1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Andreas Eisenreich <andi@nanuc.de> 5 */ 6 7 8if (!defined('DOKU_INC')) die(); 9 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'action.php'); 12 13class action_plugin_snippeter extends DokuWiki_Action_Plugin { 14 15 function register(Doku_Event_Handler $controller){ 16 $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'toolbarEventHandler', array ()); 17 } 18 19 function toolbarEventHandler(&$event, $param) { 20 global $conf; 21 22 //find pages based on namespace configuration 23 $snins = $this->getConf('namespace'); 24 $snipath = $conf['datadir'] . "/" . $snins; 25 $snifiles = scandir($snipath); 26 27 //Initialize menu array 28 $my_menu = array( 29 'type' => 'picker', 30 'title' => $this->getLang('choose'), 31 'icon' => '../../plugins/snippeter/images/icon.png', 32 'list' => array(), 33 'id' => 'Snippeter' 34 ); 35 36 //create menu entries 37 foreach ($snifiles as $file) { 38 if ( preg_match('/^\./', $file) ){ 39 continue; 40 } 41 $title = explode('.', $file, 2); 42 $iconstring = ''; 43 44 //Search for icon 45 $snimediadir = '../../exe/fetch.php?media='.$snins.':'; 46 47 $lines = file($snipath.'/'.$file); 48 foreach($lines as $line){ 49 if(strpos($line, "png") !== FALSE){ 50 $iconstringsafe = $line; 51 $iconstring = str_replace(':',':',$line); //FIXME 52 $iconstring = explode(":", $iconstring); 53 $iconstring = $iconstring[2]; 54 $iconstring = explode(".", $iconstring); 55 $iconstring = $iconstring[0].'.png'; 56 } 57 if ( $iconstring === '' ) { 58 $sniicon = '../../plugins/snippeter/images/icon.png'; 59 } else { 60 $sniicon = $snimediadir.$iconstring; 61 } 62 } 63 64 //Get page content 65 $content = file_get_contents($snipath.'/'.$file); 66 $content = str_replace($iconstringsafe,'',$content); 67 68 //Generate buttons per page 69 $my_menu['list'] [] = array( 70 'type' => 'format', 71 'title' => $title[0], 72 'icon' => $sniicon, 73 'open' => $content, 74 'sample' => ' ', 75 'close' => '\n', 76 77 ); 78 79 } 80 81 // find way to paste more than a single line 82 $event->data[] = $my_menu; 83 } 84 85} 86 87?> 88