Advertisement
Azelphur

Untitled

Nov 2nd, 2011
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Implement hook_filter_info().
  4.  */
  5. function wowhead_filter_info() {
  6.   $filters['filter_wowhead'] = array(
  7.     'title' => t('Wowhead item filter'),
  8.     'description' => "Converts wowhead links to item links with tooltips",
  9.     'process callback' => '_wowhead_filter_process',
  10.   );
  11.   return $filters;
  12. }
  13.  
  14. function _wowhead_filter_process($text, $format) {
  15.   // Find all links.
  16.   if (preg_match_all('/(http:\/\/(www\.)?wowhead\.com\/item=(\d+))/',$text, $links, PREG_SET_ORDER)) {
  17.     foreach ($links as $match) {
  18.       if ($new_link = _wowhead_link_item($match[0], $match[3])) {
  19.         $text = str_replace($match[0], $new_link, $text);
  20.       }
  21.     }
  22.   }
  23.   return $text;
  24. }
  25.  
  26. function _wowhead_link_item($url, $id) {
  27.   // Find the name.
  28.   if (!$item = cache_get("wowhead_$id")->data)
  29.   {
  30.     $xml = new SimpleXMLElement($url . "&xml", NULL, TRUE);
  31.     $item = array("name" => sprintf("%s", $xml->item->name), "url" => $url, "quality" => sprintf("%d", $xml->item->quality["id"]));
  32.     cache_set("wowhead_$id", $item);
  33.   }
  34.   return sprintf('<a class="q%d" href="%s">[%s]</a>', $item["quality"], $item["url"], $item["name"]);
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement