Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > d8544620e4ac7bee48ddb48c85d55709 > files > 230

ikiwiki-3.20190228-1.mga7.noarch.rpm

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asymptote (third party plugin)</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="stylesheet" href="../../style.css" type="text/css" />

<link rel="stylesheet" href="../../local.css" type="text/css" />










</head>
<body>

<div class="page">

<div class="pageheader">
<div class="header">
<span>
<span class="parentlinks">

<a href="../../index.html">ikiwiki</a>/ 

<a href="../../plugins.html">plugins</a>/ 

<a href="../contrib.html">contrib</a>/ 

</span>
<span class="title">
asymptote (third party plugin)

</span>
</span>



</div>









</div>





<div id="pagebody">

<div id="content" role="main">
<p><span class="infobox">
Plugin: asymptote<br />
Author: <a href="http://cryp.to/">Peter Simons</a><br />
Included in ikiwiki: no<br />
Enabled by default: no<br />
Included in <a href="../goodstuff.html">goodstuff</a>: no<br />
Currently enabled: no<br />
</span></p>

<p>This plugin provides the <a href="./asymptote/ikiwiki/directive/asymptote.html">asymptote</a>
<a href="../../ikiwiki/directive.html">directive</a> which allows embedding
<a href="http://asymptote.sourceforge.net/">asymptote</a> diagrams in a page.</p>

<p>Security implications: asymptote has functions for reading files and
other dangerous stuff, so enabling this plugin means that everyone who
can edit your Wiki can also read any file from your hard drive thats
accessible to the user running Ikiwiki. </p>

<p>This plugin uses the <a href="http://search.cpan.org/search?mode=dist&amp;query=Digest%3A%3ASHA">Digest::SHA</a> perl module.</p>

<p>The full source code is:</p>

<pre><code>    #! /usr/bin/perl

    package IkiWiki::Plugin::asymptote;
    use warnings;
    use strict;
    use Digest::MD5 qw(md5_hex);
    use File::Temp qw(tempdir);
    use HTML::Entities;
    use Encode;
    use IkiWiki 3.00;

    sub import {
            hook(type =&gt; "getsetup", id =&gt; "asymptote", call =&gt; \&amp;getsetup);
            hook(type =&gt; "preprocess", id =&gt; "asymptote", call =&gt; \&amp;preprocess);
    }

    sub getsetup () {
            return
                    plugin =&gt; {
                            safe =&gt; 1,
                            rebuild =&gt; undef,
                            section =&gt; "widget",
                    },
    }

    sub preprocess (@) {
            my %params = @_;

            my &#036;code = &#036;params{src};
            if (! defined &#036;code &amp;&amp; ! length &#036;code) {
                    error gettext("missing src attribute");
            }
            return create(&#036;code, \%params);
    }

    sub create (&#036;&#036;&#036;) {
            # This function calls the image generating function and returns
            # the &lt;img .. /&gt; for the generated image.
            my &#036;code = shift;
            my &#036;params = shift;

            my &#036;digest = md5_hex(Encode::encode_utf8(&#036;code));

            my &#036;imglink= &#036;params-&gt;{page} . "/&#036;digest.png";
            my &#036;imglog =  &#036;params-&gt;{page} .  "/&#036;digest.log";
            will_render(&#036;params-&gt;{page}, &#036;imglink);
            will_render(&#036;params-&gt;{page}, &#036;imglog);

            my &#036;imgurl=urlto(&#036;imglink, &#036;params-&gt;{destpage});
            my &#036;logurl=urlto(&#036;imglog, &#036;params-&gt;{destpage});

            if (-e "&#036;config{destdir}/&#036;imglink" ||
                gen_image(&#036;code, &#036;digest, &#036;params-&gt;{page})) {
                    return qq{&lt;img src="&#036;imgurl}
                            .(exists &#036;params-&gt;{alt} ? qq{" alt="} . &#036;params-&gt;{alt} : qq{})
                            .qq{" class="asymptote" /&gt;};
            }
            else {
                    error qq{&lt;a href="&#036;logurl"&gt;}.gettext("failed to generate image from code")."&lt;/a&gt;";
            }
    }

    sub gen_image (&#036;&#036;&#036;&#036;) {
            # Actually creates the image.
            my &#036;code = shift;
            my &#036;digest = shift;
            my &#036;imagedir = shift;

            my &#036;tmp = eval { create_tmp_dir(&#036;digest) };
            if (! &#036;@ &amp;&amp;
                writefile("&#036;digest.asy", &#036;tmp, &#036;code) &amp;&amp;
                writefile("&#036;imagedir/&#036;digest.png", &#036;config{destdir}, "") &amp;&amp;
                system("asy -render=2 -offscreen -f png -o &#036;config{destdir}/&#036;imagedir/&#036;digest.png &#036;tmp/&#036;digest.asy &amp;&gt;&#036;tmp/&#036;digest.log") == 0
               ) {
                    return 1;
            }
            else {
                    # store failure log
                    my &#036;log="";
                    {
                            if (open(my &#036;f, '&lt;', "&#036;tmp/&#036;digest.log")) {
                                    local &#036;/=undef;
                                    &#036;log = &lt;&#036;f&gt;;
                                    close(&#036;f);
                            }
                    }
                    writefile("&#036;digest.log", "&#036;config{destdir}/&#036;imagedir", &#036;log);

                    return 0;
            }
    }

    sub create_tmp_dir (&#036;) {
            # Create a temp directory, it will be removed when ikiwiki exits.
            my &#036;base = shift;

            my &#036;template = &#036;base.".XXXXXXXXXX";
            my &#036;tmpdir = tempdir(&#036;template, TMPDIR =&gt; 1, CLEANUP =&gt; 1);
            return &#036;tmpdir;
    }

    1
</code></pre>

</div>







</div>

<div id="footer" class="pagefooter" role="contentinfo">

<div id="pageinfo">




<div class="tags">
Tags:

<a href="../type/widget.html" rel="tag">type/widget</a>

</div>








<div class="pagedate">
Last edited <span class="date">Tue Feb 26 23:01:54 2019</span>
<!-- Created <span class="date">Tue Feb 26 23:01:54 2019</span> -->
</div>

</div>


<!-- from ikiwiki -->
</div>

</div>

</body>
</html>