=')) { define('AKV_25', true); define('AKV_25s', 'true'); } else { define('AKV_25', false); define('AKV_25s', 'false'); } if (!function_exists('is_admin_page')) { function is_admin_page() { if (function_exists('is_admin')) { return is_admin(); } if (function_exists('check_admin_referer')) { return true; } else { return false; } } } if (is_admin_page() && !AKV_25) { wp_enqueue_script('jquery'); } if (!function_exists('wp_prototype_before_jquery')) { function wp_prototype_before_jquery( $js_array ) { if ( false === $jquery = array_search( 'jquery', $js_array ) ) return $js_array; if ( false === $prototype = array_search( 'prototype', $js_array ) ) return $js_array; if ( $prototype < $jquery ) return $js_array; unset($js_array[$prototype]); array_splice( $js_array, $jquery, 0, 'prototype' ); return $js_array; } add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); } function cf_answerlink_header() { print(' '); } 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, true)) { 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]; } } } ?>