Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Implement hook_filter_info().
- */
- function wowhead_filter_info() {
- $filters['filter_wowhead'] = array(
- 'title' => t('Wowhead item filter'),
- 'description' => "Converts wowhead links to item links with tooltips",
- 'process callback' => '_wowhead_filter_process',
- );
- return $filters;
- }
- function _wowhead_filter_process($text, $format) {
- // Find all links.
- if (preg_match_all('/(http:\/\/(www\.)?wowhead\.com\/item=(\d+))/',$text, $links, PREG_SET_ORDER)) {
- foreach ($links as $match) {
- if ($new_link = _wowhead_link_item($match[0], $match[3])) {
- $text = str_replace($match[0], $new_link, $text);
- }
- }
- }
- return $text;
- }
- function _wowhead_link_item($url, $id) {
- // Find the name.
- if (!$item = cache_get("wowhead_$id")->data)
- {
- $xml = new SimpleXMLElement($url . "&xml", NULL, TRUE);
- $item = array("name" => sprintf("%s", $xml->item->name), "url" => $url, "quality" => sprintf("%d", $xml->item->quality["id"]));
- cache_set("wowhead_$id", $item);
- }
- return sprintf('<a class="q%d" href="%s">[%s]</a>', $item["quality"], $item["url"], $item["name"]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement