DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:garfield

garfield plugin

Compatible with DokuWiki

No compatibility info given!

plugin Will show a daily garfield comic.

Last updated on
2009-06-22
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with images, media, random

Purpose

With the Tag [GARFIELD] you can include a Garfield comic, which will change every day.

Plugin is similar to Dilbert Plugin - It only shows a Garfield comic instead of Dilbert.

Installation

Save the following code into syntax.php and copy it into folder: /lib/plugins/garfield/

<?php
/**
 * Plugin Now: Inserts a timestamp.
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Christoph Lang <calbity@gmx.de>
 */
 
// based on http://wiki.splitbrain.org/plugin:tutorial
 
// 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');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_garfield extends DokuWiki_Syntax_Plugin {
    function getInfo() {
        return array(
        'author'  => 'Christoph Lang',
        'email'   => 'calbity@gmx.de',
        'date'    => '2009-06-22',
        'name'    => 'Garfield Plugin',
        'desc'    => 'It displays a daily Garfield Comic. Based on Dilbert Plugin.',
        'url'     => 'http://www.dokuwiki.org/plugin:garfield'
        );
    }
 
    private function _listhd() {
        require_once(DOKU_INC . 'inc/HTTPClient.php');
 
        $url = 'http://feeds.hafcom.nl/garfield.xml';
 
        $ch = new DokuHTTPClient();
        $piece = $ch->get($url);
 
        $xml = simplexml_load_string($piece);
 
        $pre  = 'http://images.ucomics.com/comics/';
        $post = '.gif';
        $a = explode($pre,  (string)$xml->channel->item->description);
        $b = explode($post, $a[1]);
 
        $feed_contents .= '<a href="' . $url . '/" alt="GARFIELD">' .
        '<img src="' . $pre . $b[0] . $post . '" alt="GARFIELD"/></a>'. "\n";
 
        return $feed_contents;
    }
 
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('\[GARFIELD\]', $mode, 'plugin_garfield');
    }
 
    function getType() { return 'substition'; }
 
    function getSort() { return 667; }
 
    function handle($match, $state, $pos, &$handler) {
        return array($match, $state, $pos);
    }
 
    function render($mode, &$renderer, $data) {
 
        if ($mode == 'xhtml') {
            $renderer->doc .= $this->_listhd();
            return true;
        }
        return false;
    }
}

hey ? what is “simplexml_load_string” ? my dokuwiki is not able to find it ! flamemaniii@gmail.it

simplexml_load_string is used to load and process an xml-file (here: the rss feed with the pictures)
plugin/garfield.txt · Last modified: 2013-09-17 15:39 by 193.23.251.59