Difference between revisions of "Extension:MarketResearch"

From Organic Design wiki
(XML parsing done)
m
Line 1: Line 1:
 
<?php
 
<?php
 
/**
 
/**
  * CategoryWatch extension
+
  * MarketResearch extension{{php}}{{Category:Extensions|marketResearch}}
 
  *
 
  *
* A feature that's missing from the MediaWiki Watchlist functionality is that if
+
  * Version 0.0.1 started 2008-07-12
* 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
 
  * @package MediaWiki
 
  * @subpackage Extensions
 
  * @subpackage Extensions
* @author Aran Dunkley [http://www.organicdesign.co.nz/nad User:Nad]
 
* @copyright © 2008 Aran Dunkley
 
 
  * @licence GNU General Public Licence 2.0 or later
 
  * @licence GNU General Public Licence 2.0 or later
 
  */
 
  */

Revision as of 10:30, 12 July 2008

<?php /**

* MarketResearch extensionTemplate:Php
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.
*
* Version 0.0.1 started 2008-07-12
* 
* @package MediaWiki
* @subpackage Extensions
* @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

";

}