Index: trunk/extensions/SemanticResultFormats/Ploticus/SRF_Ploticus.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | class SRFPloticus extends SMWResultPrinter { |
24 | 24 | protected $m_ploticusparams = ''; |
25 | 25 | protected $m_imageformat = 'png'; |
26 | | - protected $m_alttext = 'Ploticus chart'; |
| 26 | + protected $m_titletext = ''; |
27 | 27 | protected $m_showcsv = false; |
28 | 28 | protected $m_ploticusmode = 'prefab'; |
29 | 29 | protected $m_debug = false; |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | protected $m_tblheight = ''; |
38 | 38 | protected $m_width = ''; |
39 | 39 | protected $m_height = ''; |
40 | | - protected $mShowHeaders = false; // override and make it false by default coz of current known overflow problem with Ploticus |
| 40 | + protected $mShowHeaders = false; // make false by default coz of current known buffer overflow with legends in Ploticus 2.40 |
41 | 41 | |
42 | 42 | protected function readParameters($params, $outputmode) { |
43 | 43 | SMWResultPrinter::readParameters($params, $outputmode); |
— | — | @@ -46,8 +46,8 @@ |
47 | 47 | if (array_key_exists('imageformat', $this->m_params)) { |
48 | 48 | $this->m_imageformat = strtolower(trim($params['imageformat'])); |
49 | 49 | } |
50 | | - if (array_key_exists('alttext', $this->m_params)) { |
51 | | - $this->m_alttext = trim($params['alttext']); |
| 50 | + if (array_key_exists('titletext', $this->m_params)) { |
| 51 | + $this->m_titletext = trim($params['titletext']); |
52 | 52 | } |
53 | 53 | if (array_key_exists('showcsv', $this->m_params)) { |
54 | 54 | $tmpcmp = strtolower(trim($params['showcsv'])); |
— | — | @@ -110,22 +110,23 @@ |
111 | 111 | $this->outputmode = SMW_OUTPUT_HTML; |
112 | 112 | |
113 | 113 | // check parameters |
114 | | - $validformats = array('svg', 'svgz','swf', 'png', 'gif', 'jpeg', 'drawdump', 'drawdumpa', 'eps', 'ps', 'csv'); |
| 114 | + $validformats = array('svg', 'svgz','swf', 'png', 'gif', 'jpeg', 'drawdump', 'drawdumpa', 'eps', 'ps'); |
115 | 115 | if (!in_array($this->m_imageformat, $validformats)) |
116 | 116 | return ('<p classid="srfperror">ERROR: '. $this->m_imageformat. ' is not a supported imageformat.<br/>Valid imageformats are: ' . |
117 | 117 | implode(', ', $validformats) . '</p>'); |
118 | 118 | |
119 | | - if($this->m_imageformat != 'csv' && empty($this->m_ploticusparams)) |
| 119 | + if (empty($this->m_ploticusparams)) |
120 | 120 | return ('<p classid="srfperror">ERROR: <em>ploticusparams</em> required.</p>'); |
121 | 121 | |
122 | | - if($this->m_imageformat != 'csv' && empty($srfgPloticusPath)) |
| 122 | + if (empty($srfgPloticusPath)) |
123 | 123 | return ('<p classid="srfperror">ERROR: Set $srfgPloticusPath in LocalSettings.php (e.g. $srfgPloticusPath=/usr/bin/pl).</p>'); |
124 | 124 | |
125 | 125 | if (!file_exists($srfgPloticusPath)) |
126 | 126 | return ('<p classid=""srfperror">ERROR: Could not find ploticus in <em>' . $srfgPloticusPath . '</em></p>'); |
127 | 127 | |
128 | | - if($this->m_ploticusmode !== 'script' && $this->m_ploticusmode !== 'prefab') |
129 | | - return ('<p classid="srfperror">ERROR: Unknown mode specified (' . $this->m_ploticusmode. '). Only "prefab" (default) and "script" mode supported.</p>'); |
| 128 | + if ($this->m_ploticusmode !== 'script' && $this->m_ploticusmode !== 'prefab') |
| 129 | + return ('<p classid="srfperror">ERROR: Unknown mode specified (' . $this->m_ploticusmode . |
| 130 | + '). Only "prefab" (default) and "script" mode supported.</p>'); |
130 | 131 | |
131 | 132 | // remove potentially dangerous keywords (prefab mode) or ploticus directives (script mode) |
132 | 133 | // this is an extended check, JUST IN CASE, even though we're invoking ploticus with the noshell security parameter |
— | — | @@ -154,8 +155,9 @@ |
155 | 156 | $tmpFile = tempnam($ploticusDir, 'srf-'); |
156 | 157 | if (($fhandle = fopen($tmpFile, 'w')) === false ) |
157 | 158 | return ('<p class="srfperror">ERROR: Cannot create data file - ' . $tmpFile . '. Check permissions.</p>'); |
158 | | - // create the header row if asked - kludgy but works |
| 159 | + |
159 | 160 | if ($this->mShowHeaders) { |
| 161 | + // create the header row |
160 | 162 | $header_row = array(); |
161 | 163 | foreach ($res->getPrintRequests() as $pr) { |
162 | 164 | $headertext = $pr->getLabel(); |
— | — | @@ -184,8 +186,8 @@ |
185 | 187 | // we create a hash based on params |
186 | 188 | // this is a great way to see if the params and/or the query result has changed |
187 | 189 | $hashname = hash('md5', $wgArticle->mTitle . $smwgIQRunningNumber . implode(',',$this->m_params)); |
188 | | - if ($this->m_imageformat != 'csv' && $this->m_liveupdating) { |
189 | | - // only include contents of result csv in hash when liveupdating is on and imageformat != csv |
| 190 | + if ($this->m_liveupdating) { |
| 191 | + // only include contents of result csv in hash when liveupdating is on |
190 | 192 | // in this way, doing file_exists check against hash filename will fail when query result has changed |
191 | 193 | $hashname .= hash_file('md5',$tmpFile); |
192 | 194 | } |
— | — | @@ -198,10 +200,7 @@ |
199 | 201 | @rename($tmpFile, $dataFile); |
200 | 202 | $dataURL = $wgUploadPath . '/ploticus/' . $hashname . '.csv'; |
201 | 203 | $srficonPath = $wgScriptPath . '/extensions/SemanticResultFormats/Ploticus/icons/'; |
202 | | - |
203 | | - if ($this->m_imageformat == 'csv') |
204 | | - return ('<a href="' . $dataURL . '" title="CSV file"><img src="'. $srficonPath . 'csv_16.png" alt="CSV file"></a>'); |
205 | | - |
| 204 | + |
206 | 205 | $graphFile = $ploticusDir . $hashname . '.' . $this->m_imageformat; |
207 | 206 | $graphURL = $wgUploadPath . '/ploticus/' . $hashname . '.' . $this->m_imageformat; |
208 | 207 | $errorFile = $ploticusDir . $hashname . '.err'; |
— | — | @@ -211,9 +210,9 @@ |
212 | 211 | $scriptFile = $ploticusDir . $hashname . '.plo'; |
213 | 212 | $scriptURL = $wgUploadPath . '/ploticus/' . $hashname . '.plo'; |
214 | 213 | |
215 | | - // get time graph was last generated. Also check to see if the |
216 | | - // generated plot has expired per the updatefrequency and needs to be redrawn |
217 | 214 | if (($this->m_updatefrequency > 0) && file_exists($graphFile)) { |
| 215 | + // get time graph was last generated. Also check to see if the |
| 216 | + // generated plot has expired per the updatefrequency and needs to be redrawn |
218 | 217 | $graphLastGenerated = filemtime($graphFile); |
219 | 218 | $expireTime = $graphLastGenerated + $this->m_updatefrequency; |
220 | 219 | if ( $expireTime < time()) { |
— | — | @@ -302,15 +301,15 @@ |
303 | 302 | case 'svg': |
304 | 303 | case 'svgz': |
305 | 304 | // note that if clickmaps are specified, Ploticus will use + instead of _ |
306 | | - // for embedded spaces in target URLs which won't work in SMW. |
| 305 | + // for embedded spaces in target URLs in the SVG XML Xlink elements which won't work in SMW. |
307 | 306 | // A patch has been submitted to Steve Grubb (Ploticus creator) |
308 | | - // that introduces the encodeclickmapurls parameter to fix this. |
| 307 | + // that introduces the encodeclickmapurls parameter to fix this. |
| 308 | + // The patch is also available in the add-ons directory. |
309 | 309 | $rtnstr .= '<object data="' . $graphURL . '"' . |
310 | 310 | (empty($this->m_width)? ' ' : ' width="'. $this->m_width . '" ') . |
311 | 311 | (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') . |
312 | 312 | 'type="image/svg+xml"><param name="src" value="' . $graphURL . |
313 | | - '"> alt : <a href="'. $graphURL . '">'. $this->m_alttext . ' - ' . |
314 | | - 'Requires SVG capable browser</a></object>'; |
| 313 | + '"> alt : <a href="'. $graphURL . '">Requires SVG capable browser</a></object>'; |
315 | 314 | break; |
316 | 315 | case 'swf': |
317 | 316 | $rtnstr .= '<object type="application/x-shockwave-flash" data="' . $graphURL . '"' . |
— | — | @@ -318,22 +317,23 @@ |
319 | 318 | (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') . |
320 | 319 | '<param name="movie" value="' . $graphURL . |
321 | 320 | '"><param name="loop" value="false"><param name="SCALE" value="noborder"> alt : <a href="'. $graphURL . |
322 | | - '">' . $this->m_alttext . ' - ' . 'Requires Adobe Flash plugin</a></object>'; |
| 321 | + '">Requires Adobe Flash plugin</a></object>'; |
323 | 322 | break; |
324 | 323 | case 'png': |
325 | 324 | case 'gif': |
326 | 325 | case 'jpeg': |
327 | | - // we are using clickmaps, create HTML snippet to enable client-side imagemaps |
328 | 326 | if (strpos($sanitized_ploticusparams, 'clickmap')) { |
| 327 | + // we are using clickmaps, create HTML snippet to enable client-side imagemaps |
329 | 328 | $mapData = file_get_contents($mapFile); |
330 | 329 | // we replace + with _ since ploticus uses + to represent spaces which mediawiki does not understand |
331 | 330 | // this is only required if you're using an unpatched copy of Ploticus (see SVG note above) |
332 | | - // we're still leaving the str_replace in if SRF-Ploticus cannot get the encodeclickmapurls patch. |
| 331 | + // regardless, we're still leaving the str_replace in place just in case the |
| 332 | + // Ploticus encodeclickmapurls patch wasn't applied. |
333 | 333 | $mapData = str_replace("+","_",$mapData); |
334 | 334 | $rtnstr .= '<map name="'. $orighash . '">'. $mapData . |
335 | 335 | '</map><img src="' . $graphURL . '" border="0" usemap="#' . $orighash . '">'; |
336 | 336 | } else { |
337 | | - $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->m_alttext .'">'; |
| 337 | + $rtnstr .= '<img src="' . $graphURL . '" alt="' . $this->m_titletext .'" title="' . $this->m_titletext . '">'; |
338 | 338 | } |
339 | 339 | break; |
340 | 340 | case 'eps': |
— | — | @@ -341,8 +341,7 @@ |
342 | 342 | $rtnstr .= '<object type="application/postscript" data="' . $graphURL . '"' . |
343 | 343 | (empty($this->m_width)? ' ' : ' width="'. $this->m_width . '" ') . |
344 | 344 | (empty($this->m_height)? ' ' : ' height="'. $this->m_height . '" ') . |
345 | | - ' alt : <a href="'. $graphURL . '">' . $this->m_alttext . ' - ' . |
346 | | - 'Requires PDF-capable browser</a></object>'; |
| 345 | + ' alt : <a href="'. $graphURL . '">Requires PDF-capable browser</a></object>'; |
347 | 346 | } |
348 | 347 | $rtnstr .= '</td></tr>'; |
349 | 348 | } |
— | — | @@ -371,10 +370,9 @@ |
372 | 371 | } |
373 | 372 | |
374 | 373 | // INFOROW - col 2 |
375 | | - // we don't display anything here for now - perhaps we can show query name in the future |
376 | | - $rtnstr .= '</td><td class="srfptitle" width="33%" colspan="1" align="center">'; |
| 374 | + // show titletext |
| 375 | + $rtnstr .= '</td><td class="srfptitle" width="33%" colspan="1" align="center">' . $this->m_titletext; |
377 | 376 | |
378 | | - |
379 | 377 | // INFOROW - TIMESTAMP - col 3 |
380 | 378 | // if showtimestamp is on, add plot generation timestamp |
381 | 379 | $rtnstr .= '</td><td class="srfptimestamp" width="33%" colspan="1" align="right">'; |
Index: trunk/extensions/SemanticResultFormats/Ploticus/README |
— | — | @@ -68,28 +68,15 @@ |
69 | 69 | can and should be used in script mode. Otherwise, the ploticus script parser will fail. |
70 | 70 | |
71 | 71 | * imageformat (enum/optional) |
72 | | - - png (default), gif, jpeg, svg, svgz, swf, eps, ps, drawdump, drawdumpa (drawdump append) and csv. |
| 72 | + - png (default), gif, jpeg, svg, svgz, swf, eps, ps, drawdump and drawdumpa (drawdump append). |
73 | 73 | Availability of format depends on how ploticus is built. When using svgz, make sure Apache |
74 | 74 | is configured properly, i.e. you have the svgz mime-type and svgz encoding. |
75 | 75 | AddType image/svg+xml svg svgz |
76 | 76 | AddEncoding gzip svgz |
77 | 77 | |
78 | | - The csv format is a special case. It only generates the CSV result and sets showcsv=true (see below), and |
79 | | - Ploticus is NOT actually invoked. |
80 | | - |
81 | | - This is useful in cases when the result set is very large and you want the ability to download the CSV file |
82 | | - without bumping up against SMW and PHP memory limits. |
83 | | - |
84 | | - FYI, while the stock CSV result printer creates the file in memory, SRF-Ploticus streams the result directly to the filesystem. |
85 | | - As a result, the resulting CSV file can be much bigger. |
86 | | - |
87 | | - As an added benefit, the CSV file is also persistent across sessions. That is, the generated URL for the CSV file is available |
88 | | - without running the query, within bounds of the $srfgPloticusCacheAgeHours LocalSettings.php parameter. |
89 | | - |
90 | | - * alttext (string/optional) |
91 | | - - alternate text displayed on mouseover for raster formats (PNG/JPEG/GIF). Ignored when client-side imagemap is generated. |
92 | | - On vector formats (SVG/SVGZ/EPS/PS), alttext is prepended to the warning message if the browser is not capable of displaying |
93 | | - the plot. |
| 78 | + * titletext (string/optional) |
| 79 | + - text displayed underneath the chart. Its also displayed on mouseover for raster formats (PNG/JPEG/GIF) and |
| 80 | + when imagemaps are not used. |
94 | 81 | |
95 | 82 | * showcsv (bool/optional) |
96 | 83 | - 0 (default). When 1, displays link to CSV file used to generate plot. Beware that the CSV |