Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: {plugin request} – wow itemlinks

First attempt at providing Wowhead item links. Please post any bugs or weirdness. This requires BBPress 1.0 RC 3+ and PHP 5+ . It has no cache, so may not be suited to ultra-high volume forums.

<?php
/*
Plugin Name: Simple Wowhead Item Links
Plugin Description: Adds item sudo-html to create links to Wowhead.
Author: Tim Howgego
Author URI: http://timhowgego.com/
Version: 0.1.rc
*/

/*
Requirements:

* PHP 5 or above.
* BBPress 1.0 RC3 or above.

Install:

* Copy the file to the "my-plugins" directory.
* Active the plugin within the Admin interface.

Customising:

* Default language is English. For other languages, edit $lang (in bb_wowhead_item_search) below.
* Default will color items which are uncommon or rarer. To change this edit $commonest_color (in bb_wowhead_item_search) below.

Using:

* Users must enter the following "sudo-HTML" code within their posts: <item>Name</item> - where name is the correct name of the item to be linked to.
* Wowhead is queried each time a new link is posted. Once the link is created, it is stored as a complete link within the post. A cache should not be required given the amount of traffic on most forums.
* If Wowhead is unavailable (often due to maintenance), or some other error occurs, the link created will simply point to a Wowhead search for the item.

Thanks Drexle for some ideas.
*/

function bb_wowhead_item_search( $find ) {

// Edit Options:
$lang = 'www'; // Language: www (english), de, fr, es, ru.
$commonest_color = 2; // Only color item qualities of this number or higher. 0 colors all items. 2 does not color white and grey items. 101 (or "high") colors nothing.
// Stop Editing

$f = trim ( $find );
$s = 'http://'.$lang.'.wowhead.com/?item='.esc_attr( str_replace(' ', '+', strtolower( $f ) ) ).'&xml';
if ( function_exists("curl_init") ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $s );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 3 );
$output = curl_exec( $ch );
curl_close( $ch );
} else {
$h = fopen( $s, "r" );
while ( !feof( $h ) ) $output .= fread( $h, 8192 );
fclose( $h );
}
if ( $output and function_exists("simplexml_load_string") ) {
$xml = simplexml_load_string( $output );
$link = $xml->item->link;
$name = $xml->item->name;
if ( $link and $name ) {
$quality = $xml->item->quality[id];
$class = ( $quality and ( $quality >= $commonest_color ) ) ? ' class="q'.esc_attr( $quality ).'"' : ' class="nocolor"';
$result = '<a href="'.esc_attr( $link ).'" title="Wowhead - '.esc_attr( $name ).'."'.$class.'>'.esc_html( $name ).'</a>';
}
}
if ( $result ) return $result;
else return '<a href="http://'.$lang.'.wowhead.com/?search='.esc_attr( $f ).'" title="Wowhead - '.esc_attr( $f ).'.">'.esc_html( $f ).'</a>';
}

function bb_wowhead_item_link( $text ) {
$text = preg_replace('|(<item>)(.*?)(</item>)|e', "bb_wowhead_item_search('\2')", $text);
return $text;
}

function bb_wowhead_item_tags( $tags ) {
$tags['item'] = array();
$tags['a'] = array( 'href' => array(), 'title' => array(), 'class' => array(), 'rel' => array() );
return $tags;
}

function bb_wowhead_item_header() {
echo '<script language="JavaScript" type="text/javascript" src="http://static.wowhead.com/widgets/power.js"></script>'."n";
}

add_filter( 'bb_allowed_tags', 'bb_wowhead_item_tags' );
add_filter( 'pre_post', 'bb_wowhead_item_link' );
add_action( 'bb_head', 'bb_wowhead_item_header' ); // Comment this line out if the Wowhead javascript file already exists in the header

?>

Skip to toolbar