Beispiel #1
0
 /**
  * Get the parser associated with this link instance.
  *
  * @return blcParser|null
  */
 function get_parser()
 {
     if (is_null($this->_parser)) {
         $this->_parser = blc_get_parser($this->parser_type);
     }
     return $this->_parser;
 }
Beispiel #2
0
 /**
  * Hook for the 'the_content' filter. Scans the current post and adds the 'broken_link' 
  * CSS class to all links that are known to be broken. Currently works only on standard
  * HTML links (i.e. the '<a href=...' kind). 
  *
  * @param string $content Post content
  * @return string Modified post content.
  */
 function hook_the_content($content)
 {
     global $post, $wpdb;
     if (empty($post)) {
         return $content;
     }
     //Retrieve info about all occurences of broken links in the current post
     $q = "\r\n\t\t\tSELECT instances.raw_url\r\n\t\t\tFROM {$wpdb->prefix}blc_instances AS instances JOIN {$wpdb->prefix}blc_links AS links \r\n\t\t\t\tON instances.link_id = links.link_id\r\n\t\t\tWHERE \r\n\t\t\t\tinstances.container_type = %s\r\n\t\t\t\tAND instances.container_id = %d\r\n\t\t\t\tAND links.broken = 1\r\n\t\t\t\tAND parser_type = 'link' \r\n\t\t";
     $q = $wpdb->prepare($q, $this->container_type, $post->ID);
     $links = $wpdb->get_results($q, ARRAY_A);
     //Return the content unmodified if there are no broken links in this post.
     if (empty($links) || !is_array($links)) {
         return $content;
     }
     //Put the broken link URLs in an array
     $broken_link_urls = array();
     foreach ($links as $link) {
         $broken_link_urls[] = $link['raw_url'];
     }
     //Iterate over all HTML links and modify the broken ones
     $parser = blc_get_parser('link');
     $content = $parser->multi_edit($content, array(&$this, 'highlight_broken_link'), $broken_link_urls);
     return $content;
 }