Plugin Directory

Changeset 2110713


Ignore:
Timestamp:
06/22/2019 10:26:38 PM (7 years ago)
Author:
chrisy
Message:

Experimental JS based graph vizuals

  • Dagre and graphlib-dot. Doesn't quite work, but close.
  • Fix some hashing issues.
  • Remove defunct 'remote' method
Location:
tfo-graphviz/trunk
Files:
4 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • tfo-graphviz/trunk/readme.txt

    r2110607 r2110713  
    11=== TFO Graphviz ===
    22Contributors: chrisy
    3 Tags: graphviz, flirble, network, diagram, graph, dot, neato, twopi, circo, fdp, visualisation, visualization, layout, hierarchical, graph, digraph, svg
     3Tags: graphviz, flirble, network, diagram, graph, dot, neato, twopi, circo, fdp, visualisation, visualization, layout, hierarchical, graph, digraph, svg, graphlib
    44Requires at least: 4.2.0
    55Tested up to: 5.2.2
    6 Stable tag: 1.17
     6Stable tag: 1.18
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    99
    10 Generates Graphviz graphics using shortcodes. Supports almost all Graphviz features.
     10Generates Graphviz graphics using shortcodes. Supports almost all Graphviz
     11features (depending on the generation method in use.)
    1112
    1213== Description ==
    1314
    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
     17This WordPress plugin provides a shortcode mechanism to create Graphviz
     18graphics within blogs, including image map generation and most other Graphviz
     19features.
    1820
    1921
     
    3234* `class="*`<css_class>`*"`
    3335
    34   Adds an extra CSS class name (or names) to the `img` tag of the rendered graph. This is in addition to the
    35   `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.
    3638
    3739* `emitjs="yes|no"`
    3840
    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.
    4246
    4347* `height="*`<image_height>`*"`
    4448
    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.
    4752
    4853* `href="self|`*<URL>*`"`
    4954
    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.
    5258
    5359* `id="`*<id>*`"`
    5460
    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.
    5967
    6068* `imap="yes|no"`
    6169
    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
    6575  `id` option for details). `imap` defaults to `no`.
    6676
    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.
    7082
    7183  For example, note that `mymap` is both the `id` and the graph name:
     
    7991  `
    8092
    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.
    8396
    8497* `lang="<dot|neato|twopi|circo|fdp>"`
    8598
    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`.
    88101
    89102* `output="<png|gif|jpg|svg>"`
     
    93106* `simple="yes|no"`
    94107
    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:
    96110
    97111  `
     
    107121  `
    108122
    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`.
    110125
    111126* `title="`*&lt;title&gt;*`"`
    112127
    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.
    115132
    116133* `width="*`&lt;image_width&gt;`*"`
    117134
    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.
    120138
    121139
     
    135153* By using a local installation and PHP bindings to the library.
    136154
    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.
     155See the FAQ for more details on these options and
     156http://www.graphviz.org/Download.php for details on installing Graphviz on
     157your web server.
    138158
    139159
     
    142162= What is Graphviz? =
    143163
    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.
    145168
    146169= How do I use this plugin? =
     
    150173= How to I write DOT? =
    151174
    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.
     175The online documentation for [Graphviz](http://www.graphviz.org/) is terse and
     176not especially helpful, in particular the [DOT
     177language](http://www.graphviz.org/doc/info/lang.html) page is only helpful if
     178you happen to be able to read an approximation of
     179[BNF](http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form).
     180
     181There are however several other introductions to Graphviz and DOT, including
     182[an excerpt on the O'Reilly LinuxDevCenter.com
     183site](http://linuxdevcenter.com/pub/a/linux/2004/05/06/graphviz_dot.html).
     184Another approach would be to look at the examples in the [Graphviz
     185gallery](http://www.graphviz.org/Gallery.php).
     186
     187Users should note that DOT syntax varies between Graphviz processors and also
     188between versions of those processors. If in doubt, find an example and
     189experiment with it.
    157190
    158191= Where can I see examples? =
     
    160193* http://blog.flirble.org/2010/11/12/graphviz-demo/
    161194* 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/
    162197
    163198= Can I manipulate the rendered graph using CSS in my WordPress theme? =
    164199
    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.
     200The `img` elements are tagged with '`class="graphviz"`'. Additionally, you can
     201add `class="myclass"` to the shortcode to add additional classes to the `img`
     202tag.
    166203
    167204= How can I make my graph have a transparent background?
    168205
    169 Add the tag `bgcolor="transparent"` to the root graph node. For example placing `graph [bgcolor="transparent"]` near the top like this:
     206Add the tag `bgcolor="transparent"` to the root graph node. For example
     207placing `graph [bgcolor="transparent"]` near the top like this:
    170208
    171209`
     
    179217= Nothing is being rendered, maybe my DOT is broken? =
    180218
    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.
     219If you're using a local Graphviz renderer then errors from Graphviz should be
     220presented where you expect the graph to appear. Note that because of how
     221Wordpress submits content to plugins the line numbering will not always match
     222what you expect.
     223
     224The error message when using the `dot` binary will contain the command line
     225used as well as a line-numbered copy of the DOT that was used.
    184226
    185227= I'm getting strange errors that make no sense, what gives? =
    186228
    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.
     229WordPress encodes HTML entities inside the shortcode block which this plugin
     230attempts to demangle.
     231
     232Unfortunately WordPress can also try to do smart character replacement, such
     233as "..." into a UNICODE ellipsis character. The Graphviz plugin contains a
     234mapping of many of these back to their ASCII equivalents, but it may not be
     235complete. Let us know if you think this is breaking your DOT. It's also
     236possible that non-ASCII7 characters do strange things too.
     237
     238Adding `define("TFO_GV_DEBUG", true)` to wp_config.php will cause the plugin
     239to 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`
     242is a number that is incremented for each shortcode section interpreted. The
     243plugin does not clean these files up.
    192244
    193245= How do I install the Graphviz program (not this plugin) locally? =
    194246
    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.
     247This depends on your local operating system. You will find some details at
     248http://www.graphviz.org/Download.php but many systems also have it in their
     249own package management system, for example this is package `graphviz` on
     250Debian, Ubuntu and Fedora systems.
     251
     252There are currently two ways to use a local installation of Graphviz. The
     253settings page will only show options for those methods that are actually
     254available and configured correctly.
    199255
    2002561. Using a local Graphviz installation and the `dot` binary. You configure the path to this binary on the admin settings page of the plugin.
     
    203259= I've installed the PHP bindings but Graphviz doesn't work! =
    204260
    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.
     261This requires that `gv.php` is available and that the associated module is
     262either already loaded or loadable with `dl()`.
     263
     264The use of `dl()` is often disabled in `php.ini` and doesn't work on
     265multithreaded webservers; it's entirely disabled in modern Apache2 httpd
     266modules.
     267
     268For these cases you must ensure the library is loaded with an entry like
     269`extension=gv.so` or similar somewhere in the PHP configuration.
    210270
    211271== Screenshots ==
     
    267327== Changelog ==
    268328
     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
    269335= 1.17 =
    270336* HTML decode the content; WP now seems to encode HTML entities between our tags.
     
    325391* Update documentation for using the PHP gv bindings.
    326392
    327 = 1.4 = 
     393= 1.4 =
    328394* Wordpress 4.0 support.
    329395* Fix for PHP Graphviz module loading; newer PHP's don't allow dl() at all in some cases, we should therefore detect this.
     
    351417== Upgrade Notice ==
    352418
    353 Upgrading from all previous versions strongly recommended; Earlier versions will not run on Wordpress 4 or on older Apache/PHP installations.
    354 
    355 
     419Upgrading from all previous versions strongly recommended; Earlier versions
     420will not run on Wordpress 4 or on older Apache/PHP installations.
     421
     422
  • tfo-graphviz/trunk/tfo-graphviz-admin.php

    r1593695 r2110713  
    165165        }
    166166
    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');
    172168        update_option('tfo-graphviz', $this->options);
    173169        return !count($this->errors->get_error_codes());
     
    189185        if ('TFO_Graphviz_Graphviz' == $method && (!$graphviz_path))
    190186            return;
    191 
    192         @unlink(TFO_GRAPHVIZ_CONTENT_DIR . '/test.png');
    193187
    194188        $graphviz_object = $this->graphviz('digraph test { graph [bgcolor="transparent"] a1 -> a2 -> a3 -> a1; }', array(
     
    205199        $message = '';
    206200        $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
    254255        echo "<p class='test-image'>" . __( 'If you can see a graph then all is well.', 'tfo-graphviz' ) . '</p>';
    255256
     
    323324                $included = include_once dirname(__FILE__)."/tfo-graphviz-$method.php";
    324325            } catch (Exception $e) {
    325                 $unavailable_methods[$class] = "Exception during method load: ...";
     326                $unavailable_methods[$class] = "Exception during method load: " + $e->getMessage();
    326327                continue;
    327328            }
    328329            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";
    330331                continue;
    331332            }
     
    335336
    336337            } catch (Exception $e) {
    337                 $unavailable_methods[$class] = "Exception when testing the method: ...";
     338                $unavailable_methods[$class] = "Exception when testing the method: " + $e->getMessage();
    338339                continue;
    339340            }
     
    388389            <th scope="row"><?php _e( 'Graphviz generation method', 'tfo-graphviz' ); ?></th>
    389390            <td class="syntax">
    390                 <p>Only available methods will be shown. If you have Graphviz installed locally and no options are shown, make sure the
     391                <p>Only available methods will be selectable. If you have Graphviz installed locally and no options are selectable, make sure the
    391392                "<code>graphviz</code> path" option below is set correctly.</p>
    392393                <ul id="tfo-graphviz-method-switch">
     
    395396        foreach ($available_methods as $class => $method) {
    396397            ?><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
    397403        }
    398404        ?></ul>
     
    413419        </tr>
    414420
    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' /><?php
    418         ?></td>
    419         </tr>
    420 
    421421        <tr class="tfo-graphviz-maxage<?php if ( in_array( 'graphviz_maxage', $errors ) ) echo ' form-invalid'; ?>">
    422422            <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>
     
    427427            <th scope="row"><label for="tfo-graphviz-emitjs"><?php _e('Emit JavaScript'); ?></label></th>
    428428            <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.)
    430430            </input></td>
    431431        </tr>
     
    454454        global $themecolors;
    455455
    456         if ( empty( $method ) )
     456        if (empty($method))
    457457            $method = 'TFO_Graphviz_Graphviz';
    458458
    459         if ( empty( $css ) )
     459        if (empty($css))
    460460            $css = 'img.graphviz { vertical-align: middle; border: none; }';
    461461
    462         if ( empty( $graphviz_path ) )
     462        if (empty($graphviz_path))
    463463            $graphviz_path = trim( @exec( 'which dot' ) );
    464464
     
    468468            $maxage = 30;
    469469
    470         if (empty($remote_key))
    471             $remote_key = '';
     470        if (empty($emitjs))
     471            $emitjs = true;
    472472
    473473        $activated = true;
    474474
    475         $this->options = compact('method', 'css', 'graphviz_path', 'maxage', 'activated', 'remote_key');
     475        $this->options = compact('method', 'css', 'graphviz_path', 'maxage', 'activated', 'emitjs');
    476476        update_option( 'tfo-graphviz', $this->options );
    477477    }
  • tfo-graphviz/trunk/tfo-graphviz-graphviz.php

    r1286864 r2110713  
    8585     */
    8686    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);
    8897        return substr($hash, 0, 32);
    8998    }
     
    159168                $dot .= sprintf("%5d %s\n", $num++, $line);
    160169            }
    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' ),
    162171                "Command: $cmd\nOutput: \n$out$err\nOriginal DOT:\n".$dot);
    163172        }
     
    217226    }
    218227
    219 
     228    function emits_url() {
     229        return true;
     230    }
    220231}
    221232
  • tfo-graphviz/trunk/tfo-graphviz-method.php

    r1593695 r2110713  
    2929class TFO_Graphviz_Method {
    3030    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
    3234    var $url;
    33 
    3435    var $error;
    3536
     
    4344    function __construct($dot, $atts) {
    4445        $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) {
    4648            if (array_key_exists($att, $atts))
    4749                $this->$att = $atts[$att];
     
    5355    /**
    5456     * 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.
    5659     *
    5760     * @return string The hash.
    5861     */
    5962    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);
    6174        return substr($hash, 0, 32);
    6275    }
     
    7386
    7487
     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
    75115}
    76116
  • tfo-graphviz/trunk/tfo-graphviz-php.php

    r1286799 r2110713  
    186186    }
    187187
    188 
     188    function emits_url() {
     189        return true;
     190    }
    189191}
    190192
  • tfo-graphviz/trunk/tfo-graphviz.php

    r2110602 r2110713  
    3030Plugin URI: http://blog.flirble.org/projects/graphviz/
    3131Description: Converts inline DOT code into an image, with optional image map, using Graphviz.
    32 Version: 1.17
     32Version: 1.18
    3333Author: Chris Luke
    3434Author URI: http://blog.flirble.org/
     
    4747    var $methods = array(
    4848        'TFO_Graphviz_Graphviz' => 'graphviz',
    49         'TFO_Graphviz_Remote' => 'remote',
     49        'TFO_Graphviz_Graphlib_Dot' => 'graphlib-dot',
    5050        'TFO_Graphviz_PHP' => 'php'
    5151    );
    5252    var $method_label = array(
    5353        '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)',
    5555        'php' => 'Local PHP bindings for Graphviz (eg, <code>libgv-php5</code> on Debian/Ubuntu) (fastest)',
    5656    );
     
    7676        @define('TFO_GRAPHVIZ_MAXAGE', $this->options['maxage']);
    7777        @define('TFO_GRAPHVIZ_EMITJS', $this->options['emitjs']);
    78         @define('TFO_GRAPHVIZ_REMOTEKEY', $this->options['remote_key']);
    7978        @define('TFO_GRAPHVIZ_SHORTCODE', 'graphviz');
    8079
     
    170169                'href' => false,
    171170                'title' => '',
    172                 'remote_key' => TFO_GRAPHVIZ_REMOTEKEY,
    173171                'width' => '',
    174172                'height' => '',
     
    231229        }
    232230
    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);
    251241            }
    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);
    272274            }
    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();
    275278        }
    276279
Note: See TracChangeset for help on using the changeset viewer.