2 rcs_id('$Id: Ploticus.php,v 1.7 2004-09-22 13:46:26 rurban Exp $');
4 Copyright 2004 $ThePhpWikiProgrammingTeam
6 This file is part of PhpWiki.
8 PhpWiki is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 PhpWiki is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * The Ploticus plugin passes all its arguments to the ploticus
25 * binary and displays the result as PNG, GIF, EPS, SVG or SWF.
26 * Ploticus is a free, GPL, non-interactive software package
27 * for producing plots, charts, and graphics from data.
28 * See http://ploticus.sourceforge.net/doc/welcome.html
30 * @Author: Reini Urban
33 * - For windows you need either a gd library with GIF support or
34 * a ploticus with PNG support. This comes only with the cygwin built.
35 * - We support only images supported by GD so far (PNG most likely).
36 * No EPS, PS, SWF, SVG or SVGZ support due to limitations in WikiPluginCached.
37 * This will be fixed soon.
40 <?plugin Ploticus device=png [ploticus options...]
41 multiline ploticus script ...
43 * or without any script: (not tested)
44 <?plugin Ploticus -prefab vbars data=myfile.dat delim=tab y=1 clickmapurl="http://mywiki.url/wiki/?pagename=@2" clickmaplabel="@3" -csmap ?>
46 * TODO: PloticusSql - create intermediate data from SQL. Similar to SqlResult, just in graphic form.
47 * For example to produce nice looking pagehit statistics or ratings statistics.
50 if (!defined("PLOTICUS_EXE"))
52 define('PLOTICUS_EXE','pl.exe');
54 define('PLOTICUS_EXE','/usr/local/bin/pl');
56 require_once "lib/WikiPluginCached.php";
58 class WikiPlugin_Ploticus
59 extends WikiPluginCached
62 * Sets plugin type to MAP if -csmap (-map or -mapdemo or -csmapdemo not supported)
63 * or HTML if the imagetype is not supported by GD (EPS, SVG, SVGZ) (not yet)
64 * or IMG_INLINE if device = png, gif or jpeg
66 function getPluginType() {
67 if (!empty($this->_args['-csmap']))
68 return PLUGIN_CACHED_MAP; // not yet tested
70 return PLUGIN_CACHED_IMG_INLINE;
75 function getDescription () {
76 return _("Ploticus image creation");
78 function managesValidators() {
81 function getVersion() {
82 return preg_replace("/[Revision: $]/", '',
85 function getDefaultArguments() {
87 'device' => 'png', // png,gif,svgz,svg,...
93 function handle_plugin_args_cruft(&$argstr, &$args) {
94 $this->source = $argstr;
97 * Sets the expire time to one day (so the image producing
98 * functions are called seldomly) or to about two minutes
99 * if a help screen is created.
101 function getExpire($dbi, $argarray, $request) {
102 if (!empty($argarray['help']))
103 return '+120'; // 2 minutes
104 return sprintf('+%d', 3*86000); // approx 3 days
108 * Sets the imagetype according to user wishes and
109 * relies on WikiPluginCached to catch illegal image
111 * (I feel unsure whether this option is reasonable in
112 * this case, because png will definitely have the
115 * @return string 'png', 'jpeg', 'gif'
117 function getImageType($dbi, $argarray, $request) {
118 return $argarray['device'];
122 * This gives an alternative text description of
125 function getAlt($dbi, $argstr, $request) {
126 return (!empty($this->_args['alt'])) ? $this->_args['alt']
127 : $this->getDescription();
131 * Returns an image containing a usage description of the plugin.
133 * TODO: -csmap pointing to the Ploticus documentation at sf.net.
134 * @return string image handle
136 function helpImage() {
137 $def = $this->defaultArguments();
138 //$other_imgtypes = $GLOBALS['PLUGIN_CACHED_IMGTYPES'];
139 //unset ($other_imgtypes[$def['imgtype']]);
141 '<?plugin Ploticus ' .
142 'device' => ' = "' . $def['device'] . "(default)|" . join('|',$GLOBALS['PLUGIN_CACHED_IMGTYPES']).'"',
143 'alt' => ' = "alternate text"',
144 '-csmap' => ' bool: clickable map?',
145 'help' => ' bool: displays this screen',
146 '...' => ' all further lines below the first plugin line ',
147 '' => ' and inside the tags are the ploticus script.',
151 foreach($helparr as $alignright => $alignleft) {
152 $length = max($length, strlen($alignright));
155 foreach($helparr as $alignright => $alignleft) {
156 $helptext .= substr(' '
157 . $alignright, -$length).$alignleft."\n";
159 return $this->text2img($helptext, 4, array(1, 0, 0),
160 array(255, 255, 255));
163 function withShellCommand($script) {
165 $pos = strpos($script, $findme);
171 function getImage($dbi, $argarray, $request) {
172 //extract($this->getArgs($argstr, $request));
173 //extract($argarray);
174 $source =& $this->source;
175 if (!empty($source)) {
176 if ($this->withShellCommand($source)) {
177 $this->_errortext .= _("shell commands not allowed in Ploticus");
181 //$cacheparams = $GLOBALS['CacheParams'];
182 $tempfiles = $this->tempnam('Ploticus');
183 $gif = $argarray['device'];
184 $args = " -stdin -$gif -o $tempfiles.$gif";
185 if (!empty($argarray['-csmap'])) {
186 $args .= " -csmap -mapfile $tempfiles.map";
187 $this->_mapfile = "$tempfiles.map";
189 $code = $this->filterThroughCmd($source, PLOTICUS_EXE . "$args");
191 // return $this->error(fmt("Couldn't start commandline '%s'", $commandLine));
192 if (! file_exists("$tempfiles.$gif") ) {
193 $this->_errortext .= fmt("Ploticus error: Outputfile '%s' not created", $tempfiles.$gif);
196 $ImageCreateFromFunc = "ImageCreateFrom$gif";
197 $img = $ImageCreateFromFunc( "$tempfiles.$gif" );
200 return $this->error(fmt("empty source"));
204 function getMap($dbi, $argarray, $request) {
205 $img = $this->getImage($dbi, $argarray, $request);
206 return array($this->_mapfile, $img);
210 // $Log: not supported by cvs2svn $
211 // Revision 1.6 2004/09/07 13:26:31 rurban
212 // new WikiPluginCached option debug=static and some more sf.net defaults for VisualWiki
214 // Revision 1.5 2004/06/28 16:35:12 rurban
215 // prevent from shell commands
217 // Revision 1.4 2004/06/19 10:06:38 rurban
218 // Moved lib/plugincache-config.php to config/*.ini
219 // use PLUGIN_CACHED_* constants instead of global $CacheParams
221 // Revision 1.3 2004/06/03 09:40:57 rurban
222 // WikiPluginCache improvements
224 // Revision 1.2 2004/06/02 19:37:07 rurban
225 // extended description
227 // Revision 1.1 2004/06/02 19:12:42 rurban
228 // new Ploticus plugin
237 // c-hanging-comment-ender-p: nil
238 // indent-tabs-mode: nil