DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:recent

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
plugin:recent [2009-01-02 21:06] 70.103.232.219plugin:recent [2021-01-22 17:59] Aleksandr
Line 1: Line 1:
 +====== Changelog Plugin ======
  
 +---- plugin ----
 +description: Allows you to show the changelog in a page.
 +author     : iDo
 +email      : iDo@woow-fr.com
 +type       : syntax
 +lastupdate : 2005-08-12
 +compatible : 
 +depends    : 
 +conflicts 
 +similar    : 
 +tags       : include, changelog, listing, !maybe.broken, recent
 +----
 +
 +===== How to use =====
 +
 +Simply write ''<nowiki>{{changelog}}</nowiki>'' in the source page.
 +
 +===== How to install =====
 +
 +First, Create a folder named 'recent' in 'lib/plugins'
 +then create a file named 'syntax.php' in this folder and copy/paste this code :
 +
 +<code php>
 +<?php
 + 
 +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
 +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_recent extends DokuWiki_Syntax_Plugin {
 + 
 +    /**
 +     * return some info
 +     */
 +    function getInfo(){
 +        return array(
 +            'author' => 'iDo',
 +            'email'  => 'iDo@woow-fr.com',
 +            'date'   => '12/08/2005',
 +            'name'   => 'Recent Plugin',
 +            'desc'   => 'Affiche les recents d\'un wiki',
 +            'url'    => 'http://www.dokuwiki.org/plugin:recent',
 +        );
 +    }
 +    /**
 +     * What kind of syntax are we?
 +     */
 +    function getType(){
 +        return 'substition';
 +    }
 +    /**
 +     * Where to sort in?
 +     */
 +    function getSort(){
 +        return 105;
 +    }
 +    /**
 +     * Connect pattern to lexer
 +     */
 +    function connectTo($mode) {
 +      $this->Lexer->addSpecialPattern("{{changelog}}",$mode,'plugin_recent');
 +    }
 +    /**
 +     * Handle the match
 +     */
 +    function handle($match, $state, $pos, &$handler){
 +        return true;
 +    }    
 + 
 +    /**
 +     * Create output
 +     */
 +    function render($mode, &$renderer, $data) {
 +        if($mode == 'xhtml'){
 +            $renderer->doc .= '<div class="recents">';
 +            $renderer->doc .= $this->_Rethtml_recent();
 +            $renderer->doc .= '</div>';
 +            return true;
 +        }
 +        return false;
 +    }
 +    
 +    function _Rethtml_recent($first=0) {
 +       ob_start();
 +       html_recent($first);
 +       return ob_get_clean();
 +    }    
 +       
 +}
 +
 +//Setup VIM: ex: et ts=4 enc=utf-8 :
 +?>
 +</code>
 +
 +===== Contact =====
 +
 +This my first plugin. i hope you'll like it ;) \\
 +ido [at] woow-fr [dot] com
 +
 +===== Comments =====
 +
 +> Looks good :-), a couple of comments ;-) \\ Why create a separate file for your ''Rethtml_recent()'' function?  Define it as a function within your plugin class and call it using ''%%$this->Rethtml_recent()%%''. Note, per the [[devel:Syntax Plugins|syntax plugin guidelines]], its good policy to prefix your own functions with an underscore. I see you have reworked the ''html_recent()''((inc/html.php)) function  to output to a string.  You could future proof your plugin by using [[http://www.php.net/manual/en/ref.outcontrol.php|PHP output buffering]] functions and calling ''html_recent()'' directly. All of which would make your code go something like this ...<code php>
 +// at the top
 +require_once(DOKU_PLUGIN.'syntax.php');
 +// require_once('shorct.php'); -- remove this line
 +require_once(DOKU_INC.'inc/html.php');
 +
 +// at the bottom
 +
 +    function render($mode, &$renderer, $data) {
 +        if($mode == 'xhtml'){       
 +//          $renderer->info['cache'] = FALSE;     // is this necessary? 
 +                                                  // a new revision, will automatically mean a fresh copy in the cache
 +            $renderer->doc .= '<div class="recents">';
 +            $renderer->doc .= $this->_Rethtml_recent();
 +            $renderer->doc .= '</div>';
 +            return true;
 +        }
 +        return false;
 +    }   
 +
 +    function _Rethtml_recent($first=0) {
 +       ob_start();
 +       html_recent($first);
 +       return ob_get_clean();
 +    } </code>  I haven't tested the above, but you get the general idea. --- //[[chris@jalakai.co.uk|Christopher Smith]] 2005-08-16 11:53//
 +
 +> I will try this and update the code asap :) Ty ! //[[ido@woow-fr.com|iDo]] 2005-08-16 20:00 GMT +1//
 +
 +> That's OK ! i have updated the code ! Thanks very much ! i did not know ob_start function. It's a very very good fonction !!! //[[ido@woow-fr.com|iDo]] 2005-08-17 09:27 GMT +1//
 +
 +
 +> Current version of code breaks XHTML conformity. This is the error: // document type does not allow element "div" here; missing one of "object", "applet", "map", "iframe", "button", "ins", "del" start-tag. // div class="recents" // couldnt locate the problem yet --- //[[loco@tag-am-meer.info|Dirk Haage]]
 +
 +>> "Parfait!" Thank you.
 +
 +> I changed the _Rethtml_recent() to NOT return the heading and the introduction line. It now looks like this: <code>    function _Rethtml_recent($first=0) {
 +       ob_start();
 +       html_recent($first);
 +       $html = ob_get_clean();
 +       $html = substr($html, strpos($html, '<ul'));
 +       return $html;
 +    }
 +</code>  --- //[[mbirth@webwriters.de|Markus Birth]]//
 +
 +> Here's a quick hack to display the latest 10 changes
 +>> No hack required, just change the recent config #~.~# --- //[[keylmf@linuxmail.org|MF Low]]//
 +
 +> Change the given method to get more control about recently changed pages. So i can list new pages the way i want ;) See live demo at the bottom of this page www.umingo.de 
 +<code php>
 +function _Rethtml_recent() {
 + global $conf;
 + global $ID;
 + $startAt = 0;
 + $numberOfEntries = 10;
 +
 +        $recents = getRecents($startAt,$numberOfEntries ,'',RECENTS_SKIP_DELETED);
 +
 + //store output and return if method is finished
 +        ob_start();
 + echo "<ul>";
 + foreach($recents as $recent){
 +   $date = date("d.m.y", $recent['date']);
 +   echo "<li>";
 +   echo "<span class='date'>".$date."</span> - ";
 +   echo html_wikilink(':'.$recent['id'], useHeading('navigation')?null:$recent['id']);
 +   echo "</li>";
 +        }
 + echo "</ul>";
 +         return ob_get_clean();
 +   
 +</code>
plugin/recent.txt · Last modified: 2024-02-05 22:28 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki