====== Progress bar plugin ====== ---- plugin ---- description: This plugin lets you put a progress bar on any wiki page. author : Mike Smith email : mmiikkee13@gmail.com type : syntax lastupdate : compatible : depends : conflicts : similar : tags : progress, bar, percent ---- ===== Syntax ===== Simply put in any page, where # is a number from 0 to 100 without the % sign. (Only multiples of 10 are supported, so you can only use 0%, 10%, 20%, etc.) ==== Examples ==== will make an empty progress bar. will make a 70% full one. ==== Demo ==== [[http://popcorn-os.sourceforge.net/wiki/doku.php?id=playground:progress-bars]] ===== Installation ===== Extract the following archive to lib/plugins/. *[[http://popcorn-os.sourceforge.net/wiki/lib/plugins/progressbar.tar.bz2|.tar.bz2]] Here's the source code, but you still need the images from the above archive.\\ lib/plugins/progressbar/syntax.php:\\ 'Mike Smith', 'email' => 'mmiikkee13@gmail.com', 'date' => 'whatever today is...', 'name' => 'Progress Bar', 'desc' => 'Makes progress bars on wiki pages.', 'url' => 'http://popcorn-os.sourceforge.net', ); } /** * What kind of syntax are we? */ function getType() { return 'substition'; } /** * Where to sort in? */ function getSort() { return 999; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('', $mode, 'plugin_progressbar'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler) { substr($match, 10, -1); return array(substr($match, 10, -1)); } /** * Create output */ function render($mode, &$renderer, $data) { $renderer->doc .= '' . $data[0] . '% completed'; return true; } } ===== Customization ===== You can change the images in lib/plugins/progressbar/images. I tried to make them fit in well with the default DokuWiki style, but they probably look horrible with any other style :-) ====== Discussion ====== >The 0 state (0%, empty progress bar) doesn't work in the plugin (even on your demo site). I changed the regexp in syntax.php (connectTo() function) from this "''" to this "''" (added the ? after [1-9] to make it optional) and now it works. // - GJH 2007-01-15 // >Hi, just stumbled over your cute little plugin - STRONGLY Suggest to add the width and height tag to the img tag to allow the browser to display the wiki pages without the need to wait for loading the progress bar image // - eth at gmx punkt at 2007-02-14 // > This plugin does not work in namespaces if you have doku configured to use '/' -- syntax.php line 84 needs modified to provide an absolute web path to the images, because relitive path wont work if your in /somenamespace/somepage. dirname($_SERVER['PHP_SELF']) seems to work for me. > Both bugs have been corrected in [[http://lukas.zapletalovi.com/blog:progressbar_pro_dokuwiki|this version]]. Please include it in the mainstream and notify me. Thanks. > The .tar.gz link won't install in the plugin manager. // - dinolinux [at] gmail [dot] com 2007-05-18 // > I've made a tar.bz2 version and stuck it on the server where the demo was running. Updated the link above. However I'm not developing this anymore, therefore the other enhancements here weren't added to it. ===== Image Free Version===== Since the archive no longer exists you no longer can access the images in the zip files, however, that example site is still up and running so you can rip the images off of there. But if that links dies, you'll have to copy the source code above to syntax.php inside of the folder, progressbar. Next, you'll create an images directory inside of the progressbar directory. You'll need 11 images--one for each possible percentage. Ex: progressbar/images/100.gif. However, if you don't want to do the hassle of eleven images, and you don't need the images to be disgustingly different you could simply use the variable $data[0] to indicate an image width. And use the same image for every percentage. However, 0% wouldn't be very useful, nor would it indicate the progress percent/value without viewing the alt text. Why deal with images? The following code will replace the $renderer->doc .... line in syntax.php. It produces just about the same results as the images. $renderer->doc .= ''.($data[0]<=0 ? '' : '') . ($data[0]>=100 ? '' : '') .'
  
';
Want to throw some text in there? Use this ugly solution((zero width percentage is an issue. set to 1 in that instance)): $renderer->doc .= '
'.$data[0].'% completed
   
';
Furthermore, if you opt to not use the images any more then you shouldn't really limit yourself to only 11 different percentages. The following function replaces functino connectTo($mode) inside of syntax.php. The regular expression means accept one or two characters from 0-9 or 100 /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('', $mode, 'plugin_progressbar'); } ===== Inline Version ===== This version creates a progress bar without the images. It will also be inserted inline into your text if you want one that does not wrap to a new line. It's also thinner. **Features:** * No extra images needed. (uses one transparent image that already exists in the Wiki image directory). * 100 pixels wide. * Renders inline with your text. * Thinner. * Supports any integer percent from 0-100. * Shows the percent value on mouse-over. ** How To Use: ** -Update the connectTo function inside syntax.php as per below to make it support any number from 0-100. /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('', $mode, 'plugin_progressbar'); } -Replace the render function in your syntax.php file for this plugin, with this: function render($mode, &$renderer, $data) { if($data[0]<0){$data[0]=0;} if($data[0]>100){$data[0]=100;} $sizeLeft = 100-$data[0]; $renderer->doc .= ''.($data[0]<=0 ? '' : ''.$data[0].'%') . ($data[0]>=100 ? '' : ''.$data[0].'%') .''; return true; } -Code supplied by Sherri W. (start.ofitall.com).