Viglink

Recipe for integrating Viglink to PmWiki

Please Viglink, grow and become an important company so we can monetize on your program because I like your idea very much.

Here is the source:

<?php if (!defined('PmWiki')) exit();

/** Copyright 2012 Carlos A. Bonamigo ([email protected])
    This is a recipe for PmWiki; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.  See pmwiki.php for full details.
*/

//This is my key. replace with yours in config
SDV($ViglinKey , "2338252e2cf3fc748f66ffdbfe8a1fa5");
SDV($ViglinkJsFmt , "
<script type=\"text/javascript\">
  var vglnk = { api_url: '//api.viglink.com/api',
                key: '$ViglinKey' };

  (function(d, t) {
    var s = d.createElement(t); s.type = 'text/javascript'; s.async = true;
    s.src = ('https:' == document.location.protocol ? vglnk.api_url :
             '//cdn.viglink.com/api') + '/vglnk.js';
    var r = d.getElementsByTagName(t)[0]; r.parentNode.insertBefore(s, r);
  }(document, 'script'));
</script>
");
SDV($ViglinkStylesFmt , "
  a.vglnk {
    color: green;
  }
");
SDV($PreserveTextPreFmt, "<pre class='escaped nolinks'>");
SDV($PreserveTextCodeFmt, "<code class='escaped nolinks'>");

$HTMLHeaderFmt['viglink'] = $ViglinkJsFmt;
$HTMLStylesFmt['viglink'] = $ViglinkStylesFmt;

Markup('[=','_begin',"/(\n[^\\S\n]*)?\\[([[email protected]"."])(.*?)\\2\\]/se",
    "PreserveTextAlt('$2', PSS('$3'), '$1')");

function PreserveTextAlt($sigil, $text, $lead){
global $PreserveTextPreFmt, $PreserveTextCodeFmt;
  if ($sigil=='=') return $lead.Keep($text);
  if (strpos($text, "\n")===false) 
    return $lead.$PreserveTextCodeFmt.Keep($text)."</code>";
  $text = preg_replace("/\n[^\\S\n]+$/", "\n", $text);
  if ($lead == "" || $lead == "\n") 
    return $lead.$PreserveTextPreFmt.Keep($text)."</pre>";
  return "$lead<:pre,1>".Keep($text);
}