Extension:MarketResearch

From Organic Design wiki
Revision as of 10:29, 12 July 2008 by Nad (talk | contribs) (XML parsing done)

<?php /**

* CategoryWatch extension
*
* A feature that's missing from the MediaWiki Watchlist functionality is that if
* you watch a category page, you will only be notified when the content of the
* category page text changes. You won't be notified when pages are added to or
* removed from that category though which is probably the main information you
* were wanting.
* 
* In addition to the normal behaviour, this extension sends a message to the users
* watching category pages when membership changes listing the articles which were
* added and/or removed from the category.
*
* See http://www.mediawiki.org/Extension:CategoryWatch for installation and usage details
* See http://www.organicdesign.co.nz/Extension:CategoryWatch for development notes and disucssion
* Version 0.0.1 started 2008-07-11
* 
* @package MediaWiki
* @subpackage Extensions
* @author Aran Dunkley User:Nad
* @copyright © 2008 Aran Dunkley
* @licence GNU General Public Licence 2.0 or later
*/

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('MARKETRESEARCH_VERSION', '0.0.1, 2008-07-12');

$wgMarketResearchPartner = 'partnerid-not-set'; $wgMarketResearchURL = 'http://www.marketresearch.com/feed/search_results.asp?bquery=computers&partnerid=$1';

  1. Extension credits that show up on Special:Version

$wgExtensionCredits['parserhook'][] = array( 'name' => 'MarketResearch', 'author' => 'wikiexpert', 'url' => 'http://www.organicdesign.co.nz/Extension:MarketResearch', 'description' => 'Display market research' );


$wgExtensionFunctions[] = "wfSetupMarketResearch"; function wfSetupMarketResearch() { global $wgParser; $wgParser->setHook("marketresearch", "wfMarketResearchTag"); }

  1. The callback function for converting the input text to HTML output

function wfMarketResearchTag($input) { global $wgMarketResearchPartner, $wgMarketResearchURL; $url = str_replace('$1', $wgMarketResearchPartner, $wgMarketResearchURL); $keywords = preg_split('/[\x00-\x1f+,]+/', trim($input));

$doc = new DOMDocument(); $doc->loadXML(file_get_contents($url)); if (is_object($doc)) { foreach ($doc->getElementsByTagName('RESULT') as $result) { foreach ($result->getElementsByTagName('TITLE') as $i) $title = $i->textContent; foreach ($result->getElementsByTagName('DESCRIPTION') as $i); $desc = $i->textContent; $products = array(); foreach($result->getElementsByTagName('BUY') as $i) $products[] = $i->getAttribute('id'); if (strlen($desc) > 200) $desc = substr($desc, 0, 200).'...';

$html .= "$title
\n

$desc

\n".join(' | ', $products)."\n\n";

} } else $html = 'no valid XML returned';

return "

$html

";

}