public function getMathML($digest, $latex)
 {
     if ($digest !== null) {
         $content = $this->plugin->getStorageAndCache()->decodeDigest($digest);
         if ($content !== null) {
             if (StringTools::startsWith($content, "<")) {
                 $breakline = null;
                 $breakline = _hx_index_of($content, "\n", 0);
                 return _hx_substr($content, 0, $breakline);
             } else {
                 $iniFile = com_wiris_util_sys_IniFile::newIniFileFromString($content);
                 $mathml = $iniFile->getProperties()->get("mml");
                 if ($mathml !== null) {
                     return $mathml;
                 } else {
                     return "Error: mathml not found.";
                 }
             }
         } else {
             return "Error: formula not found.";
         }
     } else {
         if ($latex !== null) {
             return $this->latex2mathml($latex);
         } else {
             return "Error: no digest or latex has been sent.";
         }
     }
 }
 public function updateConfiguration(&$configuration)
 {
     $configuration = $configuration;
     $s = com_wiris_system_Storage::newResourceStorage("default-configuration.ini")->read();
     $defaultIniFile = com_wiris_util_sys_IniFile::newIniFileFromString($s);
     $h = $defaultIniFile->getProperties();
     $iter = $h->keys();
     while ($iter->hasNext()) {
         $key = null;
         $key = $iter->next();
         if (com_wiris_system_PropertiesTools::getProperty($configuration, $key, null) === null) {
             $configuration[$key] = $h->get($key);
         }
         unset($key);
     }
 }
 public function updateConfiguration(&$configuration)
 {
     $configuration = $configuration;
     $confDir = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$CONFIGURATION_PATH, null);
     if ($confDir !== null) {
         $confFile = $confDir . "/configuration.ini";
         $s = com_wiris_system_Storage::newStorage($confFile);
         if ($s->exists()) {
             $defaultIniFile = com_wiris_util_sys_IniFile::newIniFileFromFilename($confFile);
             $h = $defaultIniFile->getProperties();
             $iter = $h->keys();
             while ($iter->hasNext()) {
                 $key = null;
                 $key = $iter->next();
                 $configuration[$key] = $h->get($key);
                 unset($key);
             }
         }
     }
 }
Exemplo n.º 4
0
 public function computeDigest($mml, $param)
 {
     $ss = $this->getEditorParametersList();
     $i = null;
     $renderParams = new Hash();
     $_g1 = 0;
     $_g = $ss->length;
     while ($_g1 < $_g) {
         $i1 = $_g1++;
         $key = $ss[$i1];
         $value = com_wiris_system_PropertiesTools::getProperty($param, $key, null);
         if ($value !== null) {
             $renderParams->set($key, $value);
         }
         unset($value, $key, $i1);
     }
     if ($mml !== null) {
         $renderParams->set("mml", $mml);
     }
     $s = com_wiris_util_sys_IniFile::propertiesToString($renderParams);
     return $this->plugin->getStorageAndCache()->codeDigest($s);
 }
 public function showImage($digest, $mml, $param)
 {
     if ($digest === null && $mml === null) {
         throw new HException("Missing parameters 'formula' or 'mml'.");
     }
     if ($digest !== null && $mml !== null) {
         throw new HException("Only one parameter 'formula' or 'mml' is valid.");
     }
     $atts = false;
     if ($digest === null && $mml !== null) {
         $digest = $this->computeDigest($mml, $param);
     }
     $formula = $this->plugin->getStorageAndCache()->decodeDigest($digest);
     if ($formula === null) {
         throw new HException("Formula associated to digest not found.");
     }
     if (StringTools::startsWith($formula, "<")) {
         throw new HException("Not implemented.");
     }
     $iniFile = com_wiris_util_sys_IniFile::newIniFileFromString($formula);
     $renderParams = $iniFile->getProperties();
     $i = null;
     $ss = $this->getEditorParametersList();
     if ($param !== null) {
         $_g1 = 0;
         $_g = $ss->length;
         while ($_g1 < $_g) {
             $i1 = $_g1++;
             $key = $ss[$i1];
             $value = com_wiris_system_PropertiesTools::getProperty($param, $key, null);
             if ($value !== null) {
                 $atts = true;
                 $renderParams->set($key, $value);
             }
             unset($value, $key, $i1);
         }
     }
     if ($atts) {
         if ($mml !== null) {
             $digest = $this->computeDigest($mml, com_wiris_system_PropertiesTools::toProperties($renderParams));
         } else {
             $digest = $this->computeDigest($renderParams->get("mml"), com_wiris_system_PropertiesTools::toProperties($renderParams));
         }
     }
     $store = $this->plugin->getStorageAndCache();
     $bs = null;
     $bs = $store->retreiveData($digest, $this->plugin->getConfiguration()->getProperty("wirisimageformat", "png"));
     if ($bs === null) {
         if ($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null) !== null) {
             $json = com_wiris_util_json_JSon::decode($this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMS, null));
             $decodedHash = $json;
             $keys = $decodedHash->keys();
             $notAllowedParams = _hx_explode(",", com_wiris_plugin_api_ConfigurationKeys::$EDITOR_PARAMETERS_NOTRENDER_LIST);
             while ($keys->hasNext()) {
                 $key = $keys->next();
                 if (!com_wiris_system_ArrayEx::contains($notAllowedParams, $key)) {
                     $renderParams->set($key, $decodedHash->get($key));
                 }
                 unset($key);
             }
         } else {
             $_g1 = 0;
             $_g = $ss->length;
             while ($_g1 < $_g) {
                 $i1 = $_g1++;
                 $key = $ss[$i1];
                 if (!$renderParams->exists($key)) {
                     $confKey = com_wiris_plugin_api_ConfigurationKeys::$imageConfigProperties->get($key);
                     if ($confKey !== null) {
                         $value = $this->plugin->getConfiguration()->getProperty($confKey, null);
                         if ($value !== null) {
                             $renderParams->set($key, $value);
                         }
                         unset($value);
                     }
                     unset($confKey);
                 }
                 unset($key, $i1);
             }
         }
         $prop = com_wiris_system_PropertiesTools::toProperties($renderParams);
         $iter = $renderParams->keys();
         $mml = $renderParams->get("mml");
         $b = $this->render($this->plugin->getConfiguration()->getProperty("wirisimageformat", "png"), $mml, null, $prop, null);
         $store->storeData($digest, $this->plugin->getConfiguration()->getProperty("wirisimageformat", "png"), $b->b);
         $bs = $b->b;
     }
     return $bs;
 }
 public function showImage($digest, $mml, $param, $call)
 {
     if ($digest === null && $mml === null) {
         throw new HException("Missing parameters 'formula' or 'mml'.");
     }
     if ($digest !== null && $mml !== null) {
         throw new HException("Only one parameter 'formula' or 'mml' is valid.");
     }
     $atts = false;
     if ($digest === null && $mml !== null) {
         $digest = $this->render->computeDigest($mml, $param);
     }
     $formula = $this->plugin->getStorageAndCache()->decodeDigest($digest);
     if ($formula === null) {
         throw new HException("Formula associated to digest not found.");
     }
     if (StringTools::startsWith($formula, "<")) {
         throw new HException("Not implemented.");
     }
     $iniFile = com_wiris_util_sys_IniFile::newIniFileFromString($formula);
     $renderParams = $iniFile->getProperties();
     $i = null;
     $ss = $this->render->getEditorParametersList();
     if ($param !== null) {
         $_g1 = 0;
         $_g = $ss->length;
         while ($_g1 < $_g) {
             $i1 = $_g1++;
             $key = $ss[$i1];
             $value = com_wiris_system_PropertiesTools::getProperty($param, $key, null);
             if ($value !== null) {
                 $atts = true;
                 $renderParams->set($key, $value);
             }
             unset($value, $key, $i1);
         }
     }
     if ($atts) {
         if ($mml !== null) {
             $digest = $this->render->computeDigest($mml, com_wiris_system_PropertiesTools::toProperties($renderParams));
         } else {
             $digest = $this->render->computeDigest($renderParams->get("mml"), com_wiris_system_PropertiesTools::toProperties($renderParams));
         }
     }
     $store = $this->plugin->getStorageAndCache();
     $bs = null;
     $bs = $store->retreiveData($digest, "png");
     if ($bs === null) {
         $_g1 = 0;
         $_g = $ss->length;
         while ($_g1 < $_g) {
             $i1 = $_g1++;
             $key = $ss[$i1];
             if (!$renderParams->exists($key)) {
                 $confKey = com_wiris_plugin_api_ConfigurationKeys::$imageConfigProperties->get($key);
                 if ($confKey !== null) {
                     $value = $this->plugin->getConfiguration()->getProperty($confKey, null);
                     if ($value !== null) {
                         $renderParams->set($key, $value);
                     }
                     unset($value);
                 }
                 unset($confKey);
             }
             unset($key, $i1);
         }
         $h = new com_wiris_plugin_impl_HttpImpl($this->plugin->getImageServiceURL(null), null);
         $h->setHeader("Content-Type", "application/x-www-form-urlencoded");
         $this->plugin->addReferer($h);
         $this->plugin->addProxy($h);
         $iter = $renderParams->keys();
         while ($iter->hasNext()) {
             $key = $iter->next();
             $h->setParameter($key, $renderParams->get($key));
             unset($key);
         }
         $this->digest = $digest;
         $this->call = $call;
         com_wiris_plugin_asyncimpl_HttpPostAndContinue::doPost($h, $this, "onData");
     } else {
         $call->returnBytes($bs);
     }
 }
Exemplo n.º 7
0
 static function propertiesToString($h)
 {
     $sb = new StringBuf();
     $iter = $h->keys();
     $keys = new _hx_array(array());
     while ($iter->hasNext()) {
         $keys->push($iter->next());
     }
     $i = null;
     $j = null;
     $n = $keys->length;
     $_g = 0;
     while ($_g < $n) {
         $i1 = $_g++;
         $_g1 = $i1 + 1;
         while ($_g1 < $n) {
             $j1 = $_g1++;
             $s1 = $keys[$i1];
             $s2 = $keys[$j1];
             if (com_wiris_util_sys_IniFile::compareStrings($s1, $s2) > 0) {
                 $keys[$i1] = $s2;
                 $keys[$j1] = $s1;
             }
             unset($s2, $s1, $j1);
         }
         unset($_g1);
         unset($i1);
     }
     $_g = 0;
     while ($_g < $n) {
         $i1 = $_g++;
         $key = $keys[$i1];
         $sb->add($key);
         $sb->add("=");
         $value = $h->get($key);
         $value = str_replace("\\", "\\\\", $value);
         $value = str_replace("\n", "\\n", $value);
         $value = str_replace("\r", "\\r", $value);
         $value = str_replace("\t", "\\t", $value);
         $sb->add($value);
         $sb->add("\n");
         unset($value, $key, $i1);
     }
     return $sb->b;
 }