Andreone / dokuwiki_plantuml

A plugin for Dokuwiki that generates UML graphs from text using PlantUML
http://www.dokuwiki.org/plugin:plantuml
13 stars 20 forks source link

PlantUML Remote don't work but I patch the code #18

Open gmarchand opened 10 years ago

gmarchand commented 10 years ago

Hi

i patch the code

You have to modify default.php with this conf


$conf['remote_url']='http://plantuml.com/plantuml/img/';

and modify syntax.php with

    /**
     * Render the output remotely at plantuml.no-ip.org
     */
    function _remote($data, $in, $out) {
        if (!file_exists($in)) {
            dbglog($in, 'No such plantuml input file');
            return false;
        }

        $http = new DokuHTTPClient();
        $http->timeout = 30;

        $remote_url = $this->getConf('remote_url');
        // strip trailing "/" if present
        $base_url = preg_replace('/(.+?)\/$/', '$1', $remote_url);

        $java = $this->getConf('java');
        if ($java) {
            // use url compression if java is available
            $jar = $this->getConf('jar');
            $jar = realpath($jar);
            $jar = escapeshellarg($jar);

            $command = $java;
            $command .= ' -Djava.awt.headless=true';
            $command .= ' -Dfile.encoding=UTF-8';
            $command .= " -jar $jar";
            $command .= ' -charset UTF-8';
            $command .= ' -encodeurl';
            $command .= ' ' . escapeshellarg($in);
            $command .= ' 2>&1';

            $encoded = exec($command, $output, $return_value);

            if ($return_value == 0) {
               $url = "$base_url/image/$encoded"; 
            } else {
                dbglog(join("\n", $output), "Encoding url failed: $command");
                return false;
            }
        } else {
            $uml = io_readFile($in);
            // remove @startuml and @enduml, as they are not required by the webservice 
            $uml = str_replace("@startuml\n", '', $uml);
            $uml = str_replace("\n@enduml", '', $uml);

            $uml = $this->encodep($uml);
            $url = "$base_url/$uml";
        }
        $img = $http->get($url);
        return $img ? io_saveFile($out, $img) : false;
    }

    function encodep($text) { 
         $data = utf8_encode($text); 
         $compressed = gzdeflate($data, 9); 
         return $this->encode64($compressed); 
    } 

    function encode6bit($b) { 
         if ($b < 10) { 
              return chr(48 + $b); 
         } 
         $b -= 10; 
         if ($b < 26) { 
              return chr(65 + $b); 
         } 
         $b -= 26; 
         if ($b < 26) { 
              return chr(97 + $b); 
         } 
         $b -= 26; 
         if ($b == 0) { 
              return '-'; 
         } 
         if ($b == 1) { 
              return '_'; 
         } 
         return '?'; 
    } 

    function append3bytes($b1, $b2, $b3) { 
         $c1 = $b1 >> 2; 
         $c2 = (($b1 & 0x3) << 4) | ($b2 >> 4); 
         $c3 = (($b2 & 0xF) << 2) | ($b3 >> 6); 
         $c4 = $b3 & 0x3F; 
         $r = ""; 
         $r .= $this->encode6bit($c1 & 0x3F); 
         $r .= $this->encode6bit($c2 & 0x3F); 
         $r .= $this->encode6bit($c3 & 0x3F); 
         $r .= $this->encode6bit($c4 & 0x3F); 
         return $r; 
    } 

    function encode64($c) { 
         $str = ""; 
         $len = strlen($c); 
         for ($i = 0; $i < $len; $i+=3) { 
                if ($i+2==$len) { 
                      $str .= $this->append3bytes(ord(substr($c, $i, 1)), ord(substr($c, $i+1, 1)), 0); 
                } else if ($i+1==$len) { 
                      $str .= $this->append3bytes(ord(substr($c, $i, 1)), 0, 0); 
                } else { 
                      $str .= $this->append3bytes(ord(substr($c, $i, 1)), ord(substr($c, $i+1, 1)), ord(substr($c, $i+2, 1))); 
                } 
         } 
         return $str; 
    } 
PanderMusubi commented 9 years ago

Could someone make a new release and make it available at https://www.dokuwiki.org/plugin:plantuml