var jQuery = jQuery.noConflict(); function al_show() { try { if (typeof document.body.style.maxHeight === "undefined") {//if IE 6 jQuery("body","html").css({height: "100%", width: "100%"}); jQuery("html").css("overflow","hidden"); if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6 jQuery("body").append("
"); jQuery("#TB_overlay").click(al_remove); } }else{//all others if(document.getElementById("TB_overlay") === null){ jQuery("body").append(\'
\'); jQuery("#TB_overlay").click(al_remove); } } TB_WIDTH = 700; TB_HEIGHT = 500; ajaxContentW = TB_WIDTH; ajaxContentH = TB_HEIGHT; al_position(); if(frames[\'TB_iframeContent\'] === undefined){//be nice to safari jQuery("#TB_load").remove(); jQuery("#TB_window").css({display:"block"}); jQuery(document).keyup( function(e){ var key = e.keyCode; if(key == 27){al_remove();}}); } } catch(e) { //nothing here } } //helper functions below function al_remove() { jQuery("#TB_imageOff").unbind("click"); jQuery("#TB_overlay").unbind("click"); jQuery("#TB_closeWindowButton").unbind("click"); jQuery("#TB_window").fadeOut("fast",function(){jQuery(\'#TB_window,#TB_overlay,#TB_HideSelect\').remove();}); jQuery("#TB_load").remove(); if (typeof document.body.style.maxHeight == "undefined") {//if IE 6 jQuery("body","html").css({height: "auto", width: "auto"}); jQuery("html").css("overflow",""); } document.onkeydown = ""; return false; } function al_position() { jQuery("#TB_window").css({marginLeft: \'-\' + parseInt((TB_WIDTH / 2),10) + \'px\', width: 700 + \'px\'}); if ( !(jQuery.browser.msie && typeof XMLHttpRequest == \'function\')) { // take away IE6 jQuery("#TB_window").css({marginTop: \'-\' + parseInt((500 / 2),10) + \'px\'}); } } function requestAnswerLinkWindow() { if (document.getElementById("TB_window")) { return; } al_show(); al_position(); if (typeof tinyMCE != "undefined") { var inst = tinyMCE.getInstanceById("content"); if (inst) { inst.triggerSave(false, false); } } jQuery("#TB_window").css({background: "#033c66"}).append(\'\'); return false; } function addAnswerLinkTMCEButton() { if (document.getElementById("mce_editor_0_wp_help")) { jQuery("#mce_editor_0_wp_help").after(""); jQuery("#mce_editor_0_answerlink").bind("click", requestAnswerLinkWindow); } else { setTimeout("addAnswerLinkTMCEButton();", 300); } } jQuery(window).load(function() { if (!jQuery.browser.opera) { if (document.getElementById("postdivrich")) { addAnswerLinkTMCEButton(); } else { jQuery("#ed_close").after(""); jQuery("#ed_answerlink").bind("click", requestAnswerLinkWindow); } } }); '); } add_action('admin_head', 'cf_answerlink_header'); function cf_answerlink_request_handler() { if (!empty($_REQUEST['cf_action'])) { switch ($_REQUEST['cf_action']) { case 'answerlink-init': print('
'); die(); break; case 'answerlink-window': require_once(ABSPATH.WPINC.'/class-snoopy.php'); $snoop = new Snoopy; $snoop->read_timeout = 5; $snoop->submit( 'http://alink.answers.com/link/xml' , array( 'text' => stripslashes($_POST['content']) ) ); $parser = new XMLParser; $parser->parse($snoop->results); $data = $parser->document['TEXT'][0]; $content = $data['CONTENT'][0]['data']; $links = array(); if (is_array($data['LINKS'][0]['LINK'])) { foreach ($data['LINKS'][0]['LINK'] as $link) { $links[$link['ID'][0]['data']] = array( 'id' => $link['ID'][0]['data'] , 'url' => $link['URL'][0]['data'] , 'phrase' => $link['PHRASE'][0]['data'] ); } } @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); cf_answerlink_head_html(true); cf_answerlink_form($content, $links); cf_answerlink_foot_html(); die(); break; } } } add_action('init', 'cf_answerlink_request_handler', 9999); function cf_answerlink_head_html($meta = false) { if (strpos($_SERVER['HTTP_HOST'], 'wordpress.com') !== false) { $header_img = 'header.gif'; } else { $header_img = 'header-org.gif'; } print(' '); if ($meta) { ?> '); } function cf_answerlink_foot_html() { print(' '); } function cf_answerlink_nolinks() { print('

AnswerLinks powered by Answers.com

Sorry, we do not have any AnswerLinks to suggest at this time.

'); } function cf_answerlink_form($content = '', $links = array()) { if (count($links) == 0) { cf_answerlink_nolinks(); return; } print('

AnswerLinks powered by Answers.com

'); $content = apply_filters('the_content', $content); $link_js = array(); $i = 0; foreach ($links as $link) { if ($i == 0) { $first_link = $link; $i++; } $link_js[] = '["'.$link['id'].'", "'.$link['phrase'].'", "'.$link['url'].'"]'; } $link_js = ' answerlink.links = ['.implode(',', $link_js).']; '; $js = str_replace('"', '\"', 'answerlink.activeLink = "'.$first_link['id'].'"; '.str_replace("\n", ' ', $link_js).' jQuery("#" + answerlink.activeLink).addClass("active");'); print('
'); } class XMLParser { var $parser; var $filePath; var $document; var $currTag; var $tagStack; function XMLParser($path) { $this->parser = xml_parser_create(); $this->filePath = $path; $this->document = array(); $this->currTag =& $this->document; $this->tagStack = array(); } function parse($data) { xml_set_object($this->parser, $this); xml_set_character_data_handler($this->parser, 'dataHandler'); xml_set_element_handler($this->parser, 'startHandler', 'endHandler'); if(!xml_parse($this->parser, $data, feof($fp))) { cf_answerlink_head_html(); cf_answerlink_nolinks(); cf_answerlink_foot_html(); die(); /* die( sprintf( "XML error: %s at line %d" , xml_error_string(xml_get_error_code($this->parser)) , xml_get_current_line_number($this->parser) ) ); */ } xml_parser_free($this->parser); return true; } function startHandler($parser, $name, $attribs) { if(!isset($this->currTag[$name])) $this->currTag[$name] = array(); $newTag = array(); if(!empty($attribs)) $newTag['attr'] = $attribs; array_push($this->currTag[$name], $newTag); $t =& $this->currTag[$name]; $this->currTag =& $t[count($t)-1]; array_push($this->tagStack, $name); } function dataHandler($parser, $data) { $data = trim($data); if(!empty($data)) { if(isset($this->currTag['data'])) $this->currTag['data'] .= $data; else $this->currTag['data'] = $data; } } function endHandler($parser, $name) { $this->currTag =& $this->document; array_pop($this->tagStack); for($i = 0; $i < count($this->tagStack); $i++) { $t =& $this->currTag[$this->tagStack[$i]]; $this->currTag =& $t[count($t)-1]; } } } /* proper TinyMCE plugin code // PHP Code function cf_answerlink_addMCE_plugin($plugins) { $plugins[] = 'answerlink'; return $plugins; } add_filter('mce_plugins', 'cf_answerlink_addMCE_plugin'); // JS Code answerlink_mce_plugin = { getInfo: function() { return { longname : "AnswerLink TinyMCE Plugin", author : "Crowd Favorite", authorurl : "http://crowdfavorite.com", infourl : "", version : "1.0" }; } }; if (typeof(tinyMCE) !== "undefined") { tinyMCE.addPlugin("answerlink", answerlink_mce_plugin); } */ ?>