Changeset 2110713
- Timestamp:
- 06/22/2019 10:26:38 PM (7 years ago)
- Location:
- tfo-graphviz/trunk
- Files:
-
- 4 added
- 1 deleted
- 6 edited
-
js/dagre-d3.min.js (added)
-
js/dagre.min.js (added)
-
js/graphlib-dot.min.js (added)
-
readme.txt (modified) (14 diffs)
-
tfo-graphviz-admin.php (modified) (11 diffs)
-
tfo-graphviz-graphlib-dot.php (added)
-
tfo-graphviz-graphviz.php (modified) (3 diffs)
-
tfo-graphviz-method.php (modified) (4 diffs)
-
tfo-graphviz-php.php (modified) (1 diff)
-
tfo-graphviz-remote.php (deleted)
-
tfo-graphviz.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tfo-graphviz/trunk/readme.txt
r2110607 r2110713 1 1 === TFO Graphviz === 2 2 Contributors: chrisy 3 Tags: graphviz, flirble, network, diagram, graph, dot, neato, twopi, circo, fdp, visualisation, visualization, layout, hierarchical, graph, digraph, svg 3 Tags: graphviz, flirble, network, diagram, graph, dot, neato, twopi, circo, fdp, visualisation, visualization, layout, hierarchical, graph, digraph, svg, graphlib 4 4 Requires at least: 4.2.0 5 5 Tested up to: 5.2.2 6 Stable tag: 1.1 76 Stable tag: 1.18 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 Generates Graphviz graphics using shortcodes. Supports almost all Graphviz features. 10 Generates Graphviz graphics using shortcodes. Supports almost all Graphviz 11 features (depending on the generation method in use.) 11 12 12 13 == Description == 13 14 14 [Graphviz](http://www.graphviz.org/) is a powerful tool for visualising network and tree structures that connect objects. 15 16 This WordPress plugin provides a shortcode mechanism to create Graphviz graphics within blogs, including image map generation and most 17 other Graphviz features. 15 [Graphviz](http://www.graphviz.org/) is a powerful tool for visualizing network and tree structures that connect objects. 16 17 This WordPress plugin provides a shortcode mechanism to create Graphviz 18 graphics within blogs, including image map generation and most other Graphviz 19 features. 18 20 19 21 … … 32 34 * `class="*`<css_class>`*"` 33 35 34 Adds an extra CSS class name (or names) to the `img` tag of the rendered graph. This is in addition to the35 `graphviz` class that is already applied.36 Adds an extra CSS class name (or names) to the `img` tag of the rendered 37 graph. This is in addition to the `graphviz` class that is already applied. 36 38 37 39 * `emitjs="yes|no"` 38 40 39 Override the global setting that controls whether JavaScript is emitted as necessary. Typically this JavaScript is 40 only produced when rendering SVG output and is intended to ensure SVG images work on most browsers. However this can 41 sometimes be undesirable and thus this option gives some control over this. 41 Override the global setting that controls whether JavaScript is emitted as 42 necessary. Typically this JavaScript is only produced when rendering SVG 43 output and is intended to ensure SVG images work on most browsers. However 44 this can sometimes be undesirable and thus this option gives some control 45 over this. 42 46 43 47 * `height="*`<image_height>`*"` 44 48 45 Adds a `height` attribute to the image tags to enable control of the image rendering. This is useful for making 46 sure the graphic fits into a certain space and works well for SVG rendered graphs. 49 Adds a `height` attribute to the image tags to enable control of the image 50 rendering. This is useful for making sure the graphic fits into a certain 51 space and works well for SVG rendered graphs. 47 52 48 53 * `href="self|`*<URL>*`"` 49 54 50 Encompasses the generated image with a link either to the image itself (with the `self` value) or to the provided URL. If the 51 option is empty (for example, `href=""`) then no link is generated. This is the default. 55 Encompasses the generated image with a link either to the image itself (with 56 the `self` value) or to the provided URL. If the option is empty (for 57 example, `href=""`) then no link is generated. This is the default. 52 58 53 59 * `id="`*<id>*`"` 54 60 55 Provides the identifier used to link the generated image to an image map. If you use the `simple` option then it also 56 provides the name of the generated DOT graph container (since Graphviz uses this to generate the image map). If not given 57 then an identifier is generated with the form `tfo_graphviz_N` where *N* is an integer that starts at one when the plugin 58 is loaded and is incremented with use. 61 Provides the identifier used to link the generated image to an image map. If 62 you use the `simple` option then it also provides the name of the generated 63 DOT graph container (since Graphviz uses this to generate the image map). If 64 not given then an identifier is generated with the form `tfo_graphviz_N` 65 where *N* is an integer that starts at one when the plugin is loaded and is 66 incremented with use. 59 67 60 68 * `imap="yes|no"` 61 69 62 Graphviz can generate image maps using any URL's given in the DOT code so that clicking on objects in the resultant image 63 will direct a web browser to a new page. The effect of this option is to both instruct Graphviz to generate a client-side 64 image map and to also insert that map into the generated HTML. It will use the `id` value as the name of the map (see the 70 Graphviz can generate image maps using any URL's given in the DOT code so 71 that clicking on objects in the resultant image will direct a web browser to 72 a new page. The effect of this option is to both instruct Graphviz to 73 generate a client-side image map and to also insert that map into the 74 generated HTML. It will use the `id` value as the name of the map (see the 65 75 `id` option for details). `imap` defaults to `no`. 66 76 67 Take note that the `id` value specified in the shortcode tag must match the name of the graph inside your DOT; the HTML for the 68 image map is generated by Graphviz using the name of the graph as the map id and name. This plugin uses the `id` specified 69 in the shortcode tag to link the image to the map and thus these values need to match. 77 Take note that the `id` value specified in the shortcode tag must match the 78 name of the graph inside your DOT; the HTML for the image map is generated 79 by Graphviz using the name of the graph as the map id and name. This plugin 80 uses the `id` specified in the shortcode tag to link the image to the map 81 and thus these values need to match. 70 82 71 83 For example, note that `mymap` is both the `id` and the graph name: … … 79 91 ` 80 92 81 If you do not give the graph any name at all the results are undefined. Some versions of Graphviz use `%3` as the ID in the map 82 but this may not be universally true. 93 If you do not give the graph any name at all the results are undefined. Some 94 versions of Graphviz use `%3` as the ID in the map but this may not be 95 universally true. 83 96 84 97 * `lang="<dot|neato|twopi|circo|fdp>"` 85 98 86 Specifies the particular Graphviz interpreter to use. The options are `dot`, `neato`, `twopi`, `circo` and `fdp`.87 The default is `dot`.99 Specifies the particular Graphviz interpreter to use. The options are `dot`, 100 `neato`, `twopi`, `circo` and `fdp`. The default is `dot`. 88 101 89 102 * `output="<png|gif|jpg|svg>"` … … 93 106 * `simple="yes|no"` 94 107 95 The `simple` option provides a very basic DOT wrapper around your code such that the following is possible: 108 The `simple` option provides a very basic DOT wrapper around your code such 109 that the following is possible: 96 110 97 111 ` … … 107 121 ` 108 122 109 See the `id` option for a description of how the name of the `digraph` is created. `simple` defaults to `no`. 123 See the `id` option for a description of how the name of the `digraph` is 124 created. `simple` defaults to `no`. 110 125 111 126 * `title="`*<title>*`"` 112 127 113 Indicates the title of the image. This is used in the `alt` and `title` attributes of the image reference. This 114 defaults to an empty string. Note that image maps may indicate a `title` string which will appear in tool-tips. 128 Indicates the title of the image. This is used in the `alt` and `title` 129 attributes of the image reference. This defaults to an empty string. Note 130 that image maps may indicate a `title` string which will appear in 131 tool-tips. 115 132 116 133 * `width="*`<image_width>`*"` 117 134 118 Adds a `width` attribute to the image tags to enable control of the image rendering. This is useful for making 119 sure the graphic fits into a certain space and works well for SVG rendered graphs. 135 Adds a `width` attribute to the image tags to enable control of the image 136 rendering. This is useful for making sure the graphic fits into a certain 137 space and works well for SVG rendered graphs. 120 138 121 139 … … 135 153 * By using a local installation and PHP bindings to the library. 136 154 137 See the FAQ for more details on these options and http://www.graphviz.org/Download.php for details on installing Graphviz on your web server. 155 See the FAQ for more details on these options and 156 http://www.graphviz.org/Download.php for details on installing Graphviz on 157 your web server. 138 158 139 159 … … 142 162 = What is Graphviz? = 143 163 144 [Graphviz](http://www.graphviz.org/) is a way of generating visualisations of structural relationships between objects. Almost any kind of diagram where something _connects_ to something else can be drawn and automatically laid out using the language DOT. 164 [Graphviz](http://www.graphviz.org/) is a way of generating visualisations of 165 [structural relationships between objects. Almost any kind of diagram where 166 [something _connects_ to something else can be drawn and automatically laid 167 [out using the language DOT. 145 168 146 169 = How do I use this plugin? = … … 150 173 = How to I write DOT? = 151 174 152 The online documentation for [Graphviz](http://www.graphviz.org/) is terse and not especially helpful, in particular the [DOT language](http://www.graphviz.org/doc/info/lang.html) page is only helpful if you happen to be able to read an approximation of [BNF](http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form). 153 154 There are however several other introductions to Graphviz and DOT, including [an excerpt on the O'Reilly LinuxDevCenter.com site](http://linuxdevcenter.com/pub/a/linux/2004/05/06/graphviz_dot.html). Another approach would be to look at the examples in the [Graphviz gallery](http://www.graphviz.org/Gallery.php). 155 156 Users should note that DOT syntax varies between Graphviz processors and also between versions of those processors. If in doubt, find an example and experiment with it. 175 The online documentation for [Graphviz](http://www.graphviz.org/) is terse and 176 not especially helpful, in particular the [DOT 177 language](http://www.graphviz.org/doc/info/lang.html) page is only helpful if 178 you happen to be able to read an approximation of 179 [BNF](http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form). 180 181 There are however several other introductions to Graphviz and DOT, including 182 [an excerpt on the O'Reilly LinuxDevCenter.com 183 site](http://linuxdevcenter.com/pub/a/linux/2004/05/06/graphviz_dot.html). 184 Another approach would be to look at the examples in the [Graphviz 185 gallery](http://www.graphviz.org/Gallery.php). 186 187 Users should note that DOT syntax varies between Graphviz processors and also 188 between versions of those processors. If in doubt, find an example and 189 experiment with it. 157 190 158 191 = Where can I see examples? = … … 160 193 * http://blog.flirble.org/2010/11/12/graphviz-demo/ 161 194 * http://blog.flirble.org/2015/11/15/adding-svg-support-tfo-graphviz/ 195 * http://blog.flirble.org/2019/06/22/gv-example-state-machine/ 196 * http://blog.flirble.org/2019/06/22/gv-example-various-graphs/ 162 197 163 198 = Can I manipulate the rendered graph using CSS in my WordPress theme? = 164 199 165 The `img` elements are tagged with '`class="graphviz"`'. Additionally, you can add `class="myclass"` to the shortcode to add additional classes to the `img` tag. 200 The `img` elements are tagged with '`class="graphviz"`'. Additionally, you can 201 add `class="myclass"` to the shortcode to add additional classes to the `img` 202 tag. 166 203 167 204 = How can I make my graph have a transparent background? 168 205 169 Add the tag `bgcolor="transparent"` to the root graph node. For example placing `graph [bgcolor="transparent"]` near the top like this: 206 Add the tag `bgcolor="transparent"` to the root graph node. For example 207 placing `graph [bgcolor="transparent"]` near the top like this: 170 208 171 209 ` … … 179 217 = Nothing is being rendered, maybe my DOT is broken? = 180 218 181 If you're using a local Graphviz renderer then errors from Graphviz should be presented where you expect the graph to appear. Note that because of how Wordpress submits content to plugins the line numbering will not always match what you expect. 182 183 The error message when using the `dot` binary will contain the command line used as well as a line-numbered copy of the DOT that was used. 219 If you're using a local Graphviz renderer then errors from Graphviz should be 220 presented where you expect the graph to appear. Note that because of how 221 Wordpress submits content to plugins the line numbering will not always match 222 what you expect. 223 224 The error message when using the `dot` binary will contain the command line 225 used as well as a line-numbered copy of the DOT that was used. 184 226 185 227 = I'm getting strange errors that make no sense, what gives? = 186 228 187 WordPress encodes HTML entities inside the shortcode block which this plugin attempts to demangle. 188 189 Unfortunately WordPress can also try to do smart character replacement, such as "..." into a UNICODE ellipsis character. The Graphviz plugin contains a mapping of many of these back to their ASCII equivalents, but it may not be complete. Let us know if you think this is breaking your DOT. It's also possible that non-ASCII7 characters do strange things too. 190 191 Adding `define("TFO_GV_DEBUG", true)` to wp_config.php will cause the plugin to create some diagnostic files in your system `tmp` directory. The file `pre-N.dot` is the contents of the DOT as given to the plugin by WordPress, `post-N.dot` is the results of the plugin attempting to demangle it. The `N` is a number that is incremented for each shortcode section interpreted. The plugin does not clean these files up. 229 WordPress encodes HTML entities inside the shortcode block which this plugin 230 attempts to demangle. 231 232 Unfortunately WordPress can also try to do smart character replacement, such 233 as "..." into a UNICODE ellipsis character. The Graphviz plugin contains a 234 mapping of many of these back to their ASCII equivalents, but it may not be 235 complete. Let us know if you think this is breaking your DOT. It's also 236 possible that non-ASCII7 characters do strange things too. 237 238 Adding `define("TFO_GV_DEBUG", true)` to wp_config.php will cause the plugin 239 to create some diagnostic files in your system `tmp` directory. The file 240 `pre-N.dot` is the contents of the DOT as given to the plugin by WordPress, 241 `post-N.dot` is the results of the plugin attempting to demangle it. The `N` 242 is a number that is incremented for each shortcode section interpreted. The 243 plugin does not clean these files up. 192 244 193 245 = How do I install the Graphviz program (not this plugin) locally? = 194 246 195 This depends on your local operating system. You will find some details at http://www.graphviz.org/Download.php but many systems also have it in their own package management system, for example this is package `graphviz` on Debian, Ubuntu and Fedora systems. 196 197 There are currently two ways to use a local installation of Graphviz. The settings page will only show options for those 198 methods that are actually available and configured correctly. 247 This depends on your local operating system. You will find some details at 248 http://www.graphviz.org/Download.php but many systems also have it in their 249 own package management system, for example this is package `graphviz` on 250 Debian, Ubuntu and Fedora systems. 251 252 There are currently two ways to use a local installation of Graphviz. The 253 settings page will only show options for those methods that are actually 254 available and configured correctly. 199 255 200 256 1. Using a local Graphviz installation and the `dot` binary. You configure the path to this binary on the admin settings page of the plugin. … … 203 259 = I've installed the PHP bindings but Graphviz doesn't work! = 204 260 205 This requires that `gv.php` is available and that the associated module is either already loaded or loadable with `dl()`. 206 207 The use of `dl()` is often disabled in `php.ini` and doesn't work on multithreaded webservers; it's entirely disabled in modern Apache2 httpd modules. 208 209 For these cases you must ensure the library is loaded with an entry like `extension=gv.so` or similar somewhere in the PHP configuration. 261 This requires that `gv.php` is available and that the associated module is 262 either already loaded or loadable with `dl()`. 263 264 The use of `dl()` is often disabled in `php.ini` and doesn't work on 265 multithreaded webservers; it's entirely disabled in modern Apache2 httpd 266 modules. 267 268 For these cases you must ensure the library is loaded with an entry like 269 `extension=gv.so` or similar somewhere in the PHP configuration. 210 270 211 271 == Screenshots == … … 267 327 == Changelog == 268 328 329 = 1.18 = 330 * The hash that is used to name the generated output for caching was not including all the options for generation; this meant that changing things like the GraphViz language from "dot" to something else or changing the image size was not re-renerating the output. 331 * Removed all references to the defunct 'remote' method. 332 * Add a mechanism for a method to produce its content inline, not just by URL. 333 * Experiment with the Graphlib-Dot JavaScript library. See https://github.com/dagrejs/graphlib-dot/wiki 334 269 335 = 1.17 = 270 336 * HTML decode the content; WP now seems to encode HTML entities between our tags. … … 325 391 * Update documentation for using the PHP gv bindings. 326 392 327 = 1.4 = 393 = 1.4 = 328 394 * Wordpress 4.0 support. 329 395 * Fix for PHP Graphviz module loading; newer PHP's don't allow dl() at all in some cases, we should therefore detect this. … … 351 417 == Upgrade Notice == 352 418 353 Upgrading from all previous versions strongly recommended; Earlier versions will not run on Wordpress 4 or on older Apache/PHP installations. 354 355 419 Upgrading from all previous versions strongly recommended; Earlier versions 420 will not run on Wordpress 4 or on older Apache/PHP installations. 421 422 -
tfo-graphviz/trunk/tfo-graphviz-admin.php
r1593695 r2110713 165 165 } 166 166 167 if (isset($new['remote_key'])) { 168 $remote_key = trim($new['remote_key']); 169 } 170 171 $this->options = compact('css', 'graphviz_path', 'method', 'maxage', 'emitjs', 'remote_key'); 167 $this->options = compact('css', 'graphviz_path', 'method', 'maxage', 'emitjs'); 172 168 update_option('tfo-graphviz', $this->options); 173 169 return !count($this->errors->get_error_codes()); … … 189 185 if ('TFO_Graphviz_Graphviz' == $method && (!$graphviz_path)) 190 186 return; 191 192 @unlink(TFO_GRAPHVIZ_CONTENT_DIR . '/test.png');193 187 194 188 $graphviz_object = $this->graphviz('digraph test { graph [bgcolor="transparent"] a1 -> a2 -> a3 -> a1; }', array( … … 205 199 $message = ''; 206 200 $r = false; 207 $url = false; 208 209 try { 210 $url = $graphviz_object->url(); 211 } catch (Exception $e) { 212 return false; 213 } 214 215 if (!empty($graphviz_object->tmp_file)) { 216 rename($graphviz_object->tmp_file . '.log', TFO_GRAPHVIZ_CONTENT_DIR . '/test.log'); 217 } 218 219 if (is_wp_error($url)) { 220 $code = $url->get_error_code(); 221 if ( false !== strpos( $code, '_exec' ) ) { 222 $message = "<div class='error'>\n"; 223 $exec = $url->get_error_data( $code ); 224 exec( $exec, $out, $r ); 225 $message .= "<h4>Command run:</h4>\n"; 226 $message .= "<div class='pre'><code>$exec</code></div>\n"; 227 $out = preg_replace( '/tex_.+?\.log/i', 228 '<strong><a href="' . 229 esc_url( content_url( TFO_GRAPHVIZ_CONTENT.'/test.log' ) ) . 230 '">test.log</a></strong>', 231 join("\n", $out)); 232 $message .= "<h4>Result:</h4>\n"; 233 $message .= "<div class='pre'><code>$out</code></div>\n"; 234 $message .= "<p>Exit code: $r</p>\n"; 235 $message .= "</div>"; 236 } else { 237 $message = '<div class="error"><p>' . $url->get_error_message() . "</p></div>\n"; 238 } 239 240 echo $message; 241 242 return $r; 243 } 244 245 if (!empty($graphviz_object->file)) { 246 // Rename the generated image, and create a unique URL for it. 247 rename($graphviz_object->file, TFO_GRAPHVIZ_CONTENT_DIR . '/test.png'); 248 $url = content_url(TFO_GRAPHVIZ_CONTENT . '/test.png') . '?' . mt_rand(); 249 } 250 251 @unlink(TFO_GRAPHVIZ_CONTENT_DIR.'/test.log'); 252 $alt = esc_attr( __( 'Test Image', 'tfo-graphviz' ) ); 253 echo "<img class='test-image' src='" . esc_url( $url ) . "' alt='$alt' />\n"; 201 202 if ($graphviz_object->emits_url()) { 203 $url = false; 204 @unlink(TFO_GRAPHVIZ_CONTENT_DIR . '/test.png'); 205 206 try { 207 $url = $graphviz_object->url(); 208 } catch (Exception $e) { 209 return false; 210 } 211 212 if (!empty($graphviz_object->tmp_file)) { 213 rename($graphviz_object->tmp_file . '.log', TFO_GRAPHVIZ_CONTENT_DIR . '/test.log'); 214 } 215 216 if (is_wp_error($url)) { 217 $code = $url->get_error_code(); 218 if ( false !== strpos( $code, '_exec' ) ) { 219 $message = "<div class='error'>\n"; 220 $exec = $url->get_error_data( $code ); 221 exec( $exec, $out, $r ); 222 $message .= "<h4>Command run:</h4>\n"; 223 $message .= "<div class='pre'><code>$exec</code></div>\n"; 224 $out = preg_replace( '/tex_.+?\.log/i', 225 '<strong><a href="' . 226 esc_url( content_url( TFO_GRAPHVIZ_CONTENT.'/test.log' ) ) . 227 '">test.log</a></strong>', 228 join("\n", $out)); 229 $message .= "<h4>Result:</h4>\n"; 230 $message .= "<div class='pre'><code>$out</code></div>\n"; 231 $message .= "<p>Exit code: $r</p>\n"; 232 $message .= "</div>"; 233 } else { 234 $message = '<div class="error"><p>' . $url->get_error_message() . "</p></div>\n"; 235 } 236 237 echo $message; 238 239 return $r; 240 } 241 242 if (!empty($graphviz_object->file)) { 243 // Rename the generated image, and create a unique URL for it. 244 rename($graphviz_object->file, TFO_GRAPHVIZ_CONTENT_DIR . '/test.png'); 245 $url = content_url(TFO_GRAPHVIZ_CONTENT . '/test.png') . '?' . mt_rand(); 246 } 247 248 @unlink(TFO_GRAPHVIZ_CONTENT_DIR.'/test.log'); 249 $alt = esc_attr( __( 'Test Image', 'tfo-graphviz' ) ); 250 echo "<img class='test-image' src='" . esc_url( $url ) . "' alt='$alt' />\n"; 251 } else if($graphviz_object->emits_inline()) { 252 echo $graphviz_object->inline(); 253 } 254 254 255 echo "<p class='test-image'>" . __( 'If you can see a graph then all is well.', 'tfo-graphviz' ) . '</p>'; 255 256 … … 323 324 $included = include_once dirname(__FILE__)."/tfo-graphviz-$method.php"; 324 325 } catch (Exception $e) { 325 $unavailable_methods[$class] = "Exception during method load: ...";326 $unavailable_methods[$class] = "Exception during method load: " + $e->getMessage(); 326 327 continue; 327 328 } 328 329 if ($included === FALSE) { // module didn't load, or indicated it was not useable 329 $unavailable_methods[$class] = "Module refused to load : ...";330 $unavailable_methods[$class] = "Module refused to load; possibly some dependencies are missing"; 330 331 continue; 331 332 } … … 335 336 336 337 } catch (Exception $e) { 337 $unavailable_methods[$class] = "Exception when testing the method: ...";338 $unavailable_methods[$class] = "Exception when testing the method: " + $e->getMessage(); 338 339 continue; 339 340 } … … 388 389 <th scope="row"><?php _e( 'Graphviz generation method', 'tfo-graphviz' ); ?></th> 389 390 <td class="syntax"> 390 <p>Only available methods will be s hown. If you have Graphviz installed locally and no options are shown, make sure the391 <p>Only available methods will be selectable. If you have Graphviz installed locally and no options are selectable, make sure the 391 392 "<code>graphviz</code> path" option below is set correctly.</p> 392 393 <ul id="tfo-graphviz-method-switch"> … … 395 396 foreach ($available_methods as $class => $method) { 396 397 ?><li><label for="tfo-graphviz-method-<?php echo $method;?>"><input type="radio" name="tfo-graphviz[method]" id="tfo-graphviz-method-<?php echo $method;?>" value='<?php echo $class;?>'<?php checked($class, $values['method']); ?> /> <?php _e($this->method_label[$method], 'tfo-graphviz'); ?></label></li><?php 398 } 399 ?></ul><p>Unavailable methods:</p><ul><?php 400 // now show the unavailable methods 401 foreach ($unavailable_methods as $class => $message) { 402 ?><li><label for="tfo-graphviz-method-<?php echo $method; ?>"><input type="radio" disabled> <?php _e($class, 'tfo-graphviz'); ?>: <?php _e($message, 'tfo-graphviz'); ?></label></li><?php 397 403 } 398 404 ?></ul> … … 413 419 </tr> 414 420 415 <tr class="tfo-graphviz-path tfo-graphviz-method tfo-graphviz-method-remote <?php if ( in_array( 'graphviz_remote_key', $errors ) ) echo ' form-invalid'; ?>">416 <th scope="row"><label for="tfo-graphviz-remote-key"><?php _e( 'Remote TFO Graphviz API key (blank or invalid keymeans "free" mode)' ); ?></label></th>417 <td><input type='text' name='tfo-graphviz[remote_key]' value='<?php echo esc_attr( $values['remote_key'] ); ?>' size='64' id='tfo-graphviz-remote-key' /><?php418 ?></td>419 </tr>420 421 421 <tr class="tfo-graphviz-maxage<?php if ( in_array( 'graphviz_maxage', $errors ) ) echo ' form-invalid'; ?>"> 422 422 <th scope="row"><label for="tfo-graphviz-maxage"><?php _e('Maximum age, in days, of generated content (enter <em>0</em> to disable expiration)'); ?></label></th> … … 427 427 <th scope="row"><label for="tfo-graphviz-emitjs"><?php _e('Emit JavaScript'); ?></label></th> 428 428 <td><input type="checkbox" name="tfo-graphviz[emitjs]" value="1"<?php echo $values['emitjs'] ? ' checked="checked"' : ''; ?> id="tfo-graphviz-emitjs"> 429 Select this to emit JavaScript when necessary; deselect to never emit JS .429 Select this to emit JavaScript when necessary; deselect to never emit JS (this may break certain output methods and options.) 430 430 </input></td> 431 431 </tr> … … 454 454 global $themecolors; 455 455 456 if ( empty( $method ))456 if (empty($method)) 457 457 $method = 'TFO_Graphviz_Graphviz'; 458 458 459 if ( empty( $css ))459 if (empty($css)) 460 460 $css = 'img.graphviz { vertical-align: middle; border: none; }'; 461 461 462 if ( empty( $graphviz_path ))462 if (empty($graphviz_path)) 463 463 $graphviz_path = trim( @exec( 'which dot' ) ); 464 464 … … 468 468 $maxage = 30; 469 469 470 if (empty($ remote_key))471 $ remote_key = '';470 if (empty($emitjs)) 471 $emitjs = true; 472 472 473 473 $activated = true; 474 474 475 $this->options = compact('method', 'css', 'graphviz_path', 'maxage', 'activated', ' remote_key');475 $this->options = compact('method', 'css', 'graphviz_path', 'maxage', 'activated', 'emitjs'); 476 476 update_option( 'tfo-graphviz', $this->options ); 477 477 } -
tfo-graphviz/trunk/tfo-graphviz-graphviz.php
r1286864 r2110713 85 85 */ 86 86 function hash_file() { 87 $hash = md5($this->dot); 87 // Concatenate all the options for execution 88 // Otherwise when they change we may not regenerate the output 89 $data = sprintf("%s\n%%%d-%s-%s-%s%%\n", 90 $this->dot, 91 $this-imap, 92 $this->lang, 93 $this->size, 94 $this->dpi); 95 96 $hash = md5($data); 88 97 return substr($hash, 0, 32); 89 98 } … … 159 168 $dot .= sprintf("%5d %s\n", $num++, $line); 160 169 } 161 return new WP_Error('graphviz_exec', __( 'Graphviz cannot generate graph', 'tfo-graphviz' ), 170 return new WP_Error('graphviz_exec', __( 'Graphviz cannot generate graph', 'tfo-graphviz' ), 162 171 "Command: $cmd\nOutput: \n$out$err\nOriginal DOT:\n".$dot); 163 172 } … … 217 226 } 218 227 219 228 function emits_url() { 229 return true; 230 } 220 231 } 221 232 -
tfo-graphviz/trunk/tfo-graphviz-method.php
r1593695 r2110713 29 29 class TFO_Graphviz_Method { 30 30 var $dot; 31 var $lang, $simple, $output, $href, $imap; 31 var $id, $lang, $simple, $output, $href; 32 var $imap, $title, $size, $dpi, $emitjs, $class; 33 32 34 var $url; 33 34 35 var $error; 35 36 … … 43 44 function __construct($dot, $atts) { 44 45 $this->dot = (string) $dot; 45 foreach (array('id', 'lang', 'simple', 'output', 'href', 'imap', 'title', 'size', 'dpi', 'emitjs', 'class') as $att) { 46 foreach (array('id', 'lang', 'simple', 'output', 'href', 47 'imap', 'title', 'size', 'dpi', 'emitjs', 'class') as $att) { 46 48 if (array_key_exists($att, $atts)) 47 49 $this->$att = $atts[$att]; … … 53 55 /** 54 56 * Returns a hash of the contents of the current source file. 55 * Requires the file already be loaded into $this->dot . 57 * Requires the file already be loaded into $this->dot and the 58 * various shortcode arguments parsed. 56 59 * 57 60 * @return string The hash. 58 61 */ 59 62 function hash_file() { 60 $hash = md5($this->dot); 63 // Concatenate all the options for execution 64 // Otherwise when they change we may not regenerate the output 65 $data = sprintf("%s\n%%%d-%s-%s-%s-%s%%\n", 66 $this->dot, 67 $this->id, 68 $this->imap, 69 $this->lang, 70 $this->size, 71 $this->dpi); 72 73 $hash = md5($data); 61 74 return substr($hash, 0, 32); 62 75 } … … 73 86 74 87 88 /** 89 * Does this method emit a URL? 90 * @return boolean 91 */ 92 function emits_url() { 93 return false; 94 } 95 96 97 /** 98 * Inline content for the method. 99 * 100 * @return The inline content generated by this method. 101 */ 102 function inline() { 103 return ""; 104 } 105 106 107 /** 108 * Does this method emit a inline content? 109 * @return boolean 110 */ 111 function emits_inline() { 112 return false; 113 } 114 75 115 } 76 116 -
tfo-graphviz/trunk/tfo-graphviz-php.php
r1286799 r2110713 186 186 } 187 187 188 188 function emits_url() { 189 return true; 190 } 189 191 } 190 192 -
tfo-graphviz/trunk/tfo-graphviz.php
r2110602 r2110713 30 30 Plugin URI: http://blog.flirble.org/projects/graphviz/ 31 31 Description: Converts inline DOT code into an image, with optional image map, using Graphviz. 32 Version: 1.1 732 Version: 1.18 33 33 Author: Chris Luke 34 34 Author URI: http://blog.flirble.org/ … … 47 47 var $methods = array( 48 48 'TFO_Graphviz_Graphviz' => 'graphviz', 49 'TFO_Graphviz_ Remote' => 'remote',49 'TFO_Graphviz_Graphlib_Dot' => 'graphlib-dot', 50 50 'TFO_Graphviz_PHP' => 'php' 51 51 ); 52 52 var $method_label = array( 53 53 'graphviz' => 'Local Graphviz installation using the <code>dot</code> Graphviz binary (recommended)', 54 ' remote' => 'Remote Graphviz server over HTTP (not implemented) (easiest)',54 'graphlib-dot' => 'Uses the Graphlib-dot JavaScript module for in-browser rendering (experimental)', 55 55 'php' => 'Local PHP bindings for Graphviz (eg, <code>libgv-php5</code> on Debian/Ubuntu) (fastest)', 56 56 ); … … 76 76 @define('TFO_GRAPHVIZ_MAXAGE', $this->options['maxage']); 77 77 @define('TFO_GRAPHVIZ_EMITJS', $this->options['emitjs']); 78 @define('TFO_GRAPHVIZ_REMOTEKEY', $this->options['remote_key']);79 78 @define('TFO_GRAPHVIZ_SHORTCODE', 'graphviz'); 80 79 … … 170 169 'href' => false, 171 170 'title' => '', 172 'remote_key' => TFO_GRAPHVIZ_REMOTEKEY,173 171 'width' => '', 174 172 'height' => '', … … 231 229 } 232 230 233 // Attempt to retrieve the rendered result 234 $url = false; 235 try { 236 $url = $gv->url(); 237 } catch (Exception $e) { 238 $e = "Graphviz generation failed"; 239 if ($this->err) $e .= ': '.$this->err; 240 else $e .= '.'; 241 return $this->_wrap_error($e); 242 } 243 244 if (!is_wp_error($url)) { 245 // Success, generate the img tags and any image map 246 $url = esc_url($url); 247 $href = $gv->href; 248 if ($href) { 249 if (strtolower($href) == 'self') $href = $url; 250 else $href = esc_url($href); 231 if ($gv->emits_url()) { 232 // Attempt to retrieve the rendered result 233 $url = false; 234 try { 235 $url = $gv->url(); 236 } catch (Exception $e) { 237 $e = "Graphviz generation failed"; 238 if ($this->err) $e .= ': '.$this->err; 239 else $e .= '.'; 240 return $this->_wrap_error($e); 251 241 } 252 $alt = esc_attr($gv->title); 253 $ret = "<img src=\"$url\" class=\"graphviz"; 254 if (!empty($atts['class'])) $ret .= " ".esc_attr($atts['class']); 255 $ret .= "\""; 256 if (!empty($alt)) $ret .= " alt=\"$alt\" title=\"$alt\""; 257 if (!empty($gv->imap)) $ret .= " usemap=\"#$gv->id\""; 258 if (!empty($atts['width'])) $ret .= " width=\"".esc_attr($atts['width'])."\""; 259 if (!empty($atts['height'])) $ret .= " height=\"".esc_attr($atts['height'])."\""; 260 $ret .= " />"; 261 if (!empty($href)) $ret = "<a href=\"".$href."\">$ret</a>"; 262 if (!empty($gv->imap)) $ret .= "\n$gv->imap"; 263 264 } else { 265 // An error, wrap any message we received in some HTML and return it 266 $ret = "<pre>"; 267 $ret .= $url->get_error_message(); 268 $d = $url->get_error_data(); 269 if ($d) { 270 $ret .= "\n"; 271 $ret .= $url->get_error_data(); 242 243 if (!is_wp_error($url)) { 244 // Success, generate the img tags and any image map 245 $url = esc_url($url); 246 $href = $gv->href; 247 if ($href) { 248 if (strtolower($href) == 'self') $href = $url; 249 else $href = esc_url($href); 250 } 251 $alt = esc_attr($gv->title); 252 $ret = "<img src=\"$url\" class=\"graphviz"; 253 if (!empty($atts['class'])) $ret .= " ".esc_attr($atts['class']); 254 $ret .= "\""; 255 if (!empty($alt)) $ret .= " alt=\"$alt\" title=\"$alt\""; 256 if (!empty($gv->imap)) $ret .= " usemap=\"#$gv->id\""; 257 if (!empty($atts['width'])) $ret .= " width=\"".esc_attr($atts['width'])."\""; 258 if (!empty($atts['height'])) $ret .= " height=\"".esc_attr($atts['height'])."\""; 259 $ret .= " />"; 260 if (!empty($href)) $ret = "<a href=\"".$href."\">$ret</a>"; 261 if (!empty($gv->imap)) $ret .= "\n$gv->imap"; 262 263 } else { 264 // An error, wrap any message we received in some HTML and return it 265 $ret = "<pre>"; 266 $ret .= $url->get_error_message(); 267 $d = $url->get_error_data(); 268 if ($d) { 269 $ret .= "\n"; 270 $ret .= $url->get_error_data(); 271 } 272 $ret .= "</pre>\n"; 273 return $this->_wrap_error($ret); 272 274 } 273 $ret .= "</pre>\n"; 274 return $this->_wrap_error($ret); 275 } else if ($gv->emits_inline()) { 276 // Go get the inline content 277 $ret = $gv->inline(); 275 278 } 276 279
Note: See TracChangeset
for help on using the changeset viewer.