Writing a Woot! plugin
-
Hi All,
I am not a coder so this is new trerritory for me. I have been looking for a plugin to show the current woot on Woot.com. I have only found 1 and am not able to get it working. I found a plugin creator and thought about tackling writing one. While my coding is super limited, I went out and found someone who wrote a plugin for woot that does exactly what I wanted. The code comes from a docuwiki plugin. This is the code:
<?php
/**
* Woot Plugin
*
* woot.com is a fun little website which offers a single deal on
* some techie gadget daily. Sometimes the deals are great, but
* generally it’s crap. This plugin screen scraps woot and grabs
* the current product price, title, and image.
*
* @author Russ Meyerriecks <[email protected]>
*
*/
// must be run within Dokuwiki
if(!defined(‘DOKU_INC’)) die();if(!defined(‘DOKU_PLUGIN’)) define(‘DOKU_PLUGIN’,DOKU_INC.’lib/plugins/’);
require_once(DOKU_PLUGIN.’syntax.php’);class syntax_plugin_woot extends DokuWiki_Syntax_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
‘author’ => ‘Russ Meyerriecks’,
’email’ => ‘[email protected]’,
‘date’ => ‘2008-2-6’,
‘name’ => ‘Woot Plugin’,
‘desc’ => ‘Grabs the current woot.com product name, price, and image’,
‘url’ => ‘https://wiki.splitbrain.org/plugin:woot’,
);
}/**
* What kind of syntax are we?
*/
function getType(){
return ‘substition’;
}/**
* What about paragraphs?
*/
function getPType(){
return ‘block’;
}/**
* Where to sort in?
*/
function getSort(){
return 188;
}/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern(‘\{\{woot\}\}’, $mode, ‘plugin_woot’);
}/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
return array();
}/**
* Create output
*/
function render($format, &$renderer, $data) {
if($format == ‘xhtml’){
//handle various info stuff
$woot = file_get_contents(‘https://www.woot.com’);
preg_match(“/ContentPlaceHolder_TitleHeader\”>(.+)<\/h3>/”, $woot, $matches);
$title = $matches[1];preg_match(“/PriceSpan\”>(.+)<\/span>/”, $woot, $matches);
$price = $matches[1];preg_match(“/shipping\”>(.+)<\/span>/”, $woot, $matches);
$shipping = $matches[1];preg_match(“/<img id=\”ctl00_ContentPlaceHolder_SaleImage\”.+src=\”(.+)\” alt/”, $woot, $matches);
$img = $matches[1];
$renderer->doc .= $title . ‘<br>’;
$renderer->doc .= “Price : $price $shipping <br>”;
$renderer->doc .= “<img src=’$img’>“;return true;
}
return false;
}
}I tried copying and pasting and trying different snippits of the code but nothing work. Can anyone help? Even better, can someone modify and write the plugin themselves?
Thanks
- The topic ‘Writing a Woot! plugin’ is closed to new replies.