1<?php 2/** 3 * Adds a color picker to the toolbar 4 * 5 * @package colorpicker 6 * @author Gabriel Birke <gb@birke-software.de> 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 */ 9 10if(!defined('DOKU_INC')) die(); 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(DOKU_PLUGIN.'action.php'); 13 14class action_plugin_colorpicker extends DokuWiki_Action_Plugin { 15 16 /* 17 * Register the handlers with the dokuwiki's event controller 18 */ 19 function register(Doku_Event_Handler $controller) { 20 $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'add_button'); 21 } 22 23 /** 24 * Parse the color scheme and add the button to the toolbar. 25 * 26 * The color scheme must at least contain one "colorname=color" pair. 27 */ 28 function add_button(&$event, $param) { 29 $colorscheme = $this->getConf('colorscheme'); 30 $scheme_lines = explode("\n", $colorscheme); 31 $color_list = array(); 32 foreach ($scheme_lines as $line) 33 { 34 $combo = explode('=', $line, 2); 35 if (count($combo) != 2) { 36 continue; 37 } 38 $key = trim($combo[0]); 39 $colorvalue = trim($combo[1]); 40 if ($key && $colorvalue) { 41 $color_list[$key] = $colorvalue; 42 } 43 } 44 if (!empty($color_list)) 45 { 46 $event->data[] = array( 47 'type' => 'colorpicker', 48 'title' => $this->getLang('colorpicker'), 49 'icon' => '../../plugins/colorpicker/picker.png', 50 'list' => $color_list 51 ); 52 } 53 } 54 55} 56