Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gmarchand opened this issue Dec 19, 2013 · 1 comment
Open

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

gmarchand opened this issue Dec 19, 2013 · 1 comment

Comments

@gmarchand
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants