public function service($serviceName, $param, $response)
 {
     $this->serviceName = $serviceName;
     $this->param = $param;
     $this->response = $response;
     $this->digest = null;
     if (com_wiris_plugin_impl_TextServiceImpl::hasCache($serviceName)) {
         $this->digest = $this->plugin->newRender()->computeDigest(null, $param);
         $store = $this->plugin->getStorageAndCache();
         $ext = com_wiris_plugin_impl_TextServiceImpl::getDigestExtension($serviceName, $param);
         $s = $store->retreiveData($this->digest, $ext);
         if ($s !== null) {
             $response->returnString(com_wiris_system_Utf8::fromBytes($s));
             return;
         }
     }
     $url = $this->plugin->getImageServiceURL($serviceName, true);
     $h = new com_wiris_plugin_impl_HttpImpl($url, $this);
     $this->plugin->addReferer($h);
     $this->plugin->addProxy($h);
     if ($param !== null) {
         $ha = com_wiris_system_PropertiesTools::fromProperties($param);
         $iter = $ha->keys();
         while ($iter->hasNext()) {
             $k = $iter->next();
             $h->setParameter($k, $ha->get($k));
             unset($k);
         }
     }
     $h->request(true);
 }
 public function getAndCheckFolder($key)
 {
     $folder = com_wiris_system_PropertiesTools::getProperty($this->config, $key, null);
     if ($folder === null || strlen(trim($folder)) === 0) {
         throw new HException("Missing configuration value: " . $key);
     }
     return $folder;
 }
 public function step1()
 {
     if ($this->param !== null && com_wiris_system_PropertiesTools::getProperty($this->param, "metrics", "false") === "true") {
         $this->render->showImage($this->digest, null, null, $this->step1_getMetrics_);
     } else {
         $this->step2();
     }
 }
 public function updateConfiguration(&$configuration)
 {
     $configuration = $configuration;
     $v = null;
     $base = null;
     $base = dirname(__FILE__);
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER, null);
     if ($v === null) {
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER] = $base . "/../../../../../../cache";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$FORMULA_FOLDER, null);
     if ($v === null) {
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$FORMULA_FOLDER] = $base . "/../../../../../../formulas";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$SHOWIMAGE_PATH, null);
     if ($v === null) {
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$SHOWIMAGE_PATH] = "integration/showimage.php?formula=";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$SHOWCASIMAGE_PATH, null);
     if ($v === null) {
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$SHOWCASIMAGE_PATH] = "integration/showcasimage.php?formula=";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$CLEAN_CACHE_PATH, null);
     if ($v === null) {
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$CLEAN_CACHE_PATH] = "cleancache.php";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$RESOURCE_PATH, null);
     if ($v === null) {
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$RESOURCE_PATH] = "resource.php";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$CONTEXT_PATH, null);
     if ($v === null) {
         $filePath = dirname(dirname($_SERVER['SCRIPT_NAME']));
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$CONTEXT_PATH] = $filePath . "/";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$CONFIGURATION_PATH, null);
     if ($v === null) {
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$CONFIGURATION_PATH] = $base . "/../../../../../..";
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$EXTERNAL_REFERER, null);
     if ($v === null) {
         $external_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$EXTERNAL_REFERER] = $external_referer;
     }
     $v = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$REFERER, null);
     if ($v === null) {
         $referer = empty($_SERVER['HTTPS']) ? "http://" : "https://";
         $referer .= $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
         if (isset($_SERVER['QUERY_STRING'])) {
             $referer .= "?" . $_SERVER['QUERY_STRING'];
         }
         $configuration[com_wiris_plugin_api_ConfigurationKeys::$REFERER] = $referer;
     }
 }
 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);
             }
         }
     }
 }
 public function updateConfiguration(&$configuration)
 {
     $configuration = $configuration;
     $confClass = com_wiris_system_PropertiesTools::getProperty($configuration, com_wiris_plugin_api_ConfigurationKeys::$CONFIGURATION_CLASS, null);
     if ($confClass !== null && _hx_index_of($confClass, "com.wiris.plugin.servlets.configuration.ParameterServletConfigurationUpdater", null) !== -1) {
         return;
     }
     if ($confClass !== null) {
         $cls = Type::resolveClass($confClass);
         if ($cls === null) {
             throw new HException("Class " . $confClass . " not found.");
         }
         $obj = Type::createInstance($cls, new _hx_array(array()));
         if ($obj === null) {
             throw new HException("Instance from " . Std::string($cls) . " cannot be created.");
         }
         $cu = $obj;
         $this->config->initialize($cu);
         $cu->updateConfiguration($configuration);
     }
 }
 static function getDigestExtension($serviceName, $param)
 {
     $lang = com_wiris_system_PropertiesTools::getProperty($param, "lang", "en");
     if ($lang !== null && strlen($lang) === 0) {
         return "en";
     }
     return $lang;
 }
 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 serviceText($serviceName, $param)
 {
     $servicesClass = Type::resolveClass("com.wiris.editor.services.PublicServices");
     $getInstance = Reflect::field($servicesClass, "getInstance");
     $publicServices = Reflect::callMethod($servicesClass, $getInstance, null);
     $serviceMethod = Reflect::field($publicServices, $serviceName);
     $args = new _hx_array(array());
     try {
         if (_hx_index_of($serviceName, "mathml2accessible", null) !== -1) {
             $mml = com_wiris_system_PropertiesTools::getProperty($param, "mml", null);
             if ($mml === null) {
                 throw new HException("Missing mml");
             } else {
                 $args->push($mml);
             }
             $lang = com_wiris_system_PropertiesTools::getProperty($param, "lang", "en");
             $args->push($lang);
             $args->push($param);
             $serviceText = Reflect::callMethod($publicServices, $serviceMethod, $args);
             return $serviceText;
         } else {
             if (_hx_index_of($serviceName, "mathml2latex", null) !== -1) {
                 $mml = com_wiris_system_PropertiesTools::getProperty($param, "mml", null);
                 if ($mml === null) {
                     throw new HException("Missing mml");
                 } else {
                     $args->push($mml);
                 }
                 $keepMathml = com_wiris_system_PropertiesTools::getProperty($param, "keepMathml", "false");
                 if (_hx_index_of($keepMathml, "true", null) !== -1) {
                     $args->push(true);
                 } else {
                     $args->push(false);
                 }
                 $args->push($param);
                 $serviceText = Reflect::callMethod($publicServices, $serviceMethod, $args);
                 return $serviceText;
             } else {
                 if (_hx_index_of($serviceName, "latex2mathml", null) !== -1) {
                     $latex = com_wiris_system_PropertiesTools::getProperty($param, "latex", null);
                     if ($latex === null) {
                         throw new HException("Missing LaTeX");
                     } else {
                         $args->push($latex);
                     }
                     $keepLatex = com_wiris_system_PropertiesTools::getProperty($param, "saveLatex", "false");
                     if (_hx_index_of($keepLatex, "false", null) !== -1) {
                         $args->push(false);
                     } else {
                         $args->push(true);
                     }
                     $args->push($param);
                     $serviceText = Reflect::callMethod($publicServices, $serviceMethod, $args);
                     return $serviceText;
                 } else {
                     throw new HException("Unknow service " . $serviceName);
                 }
             }
         }
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $e = $_ex_;
         throw new HException($e->getMessage());
     }
 }
 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 getProperty($key, $dflt)
 {
     $this->initialize0();
     return com_wiris_system_PropertiesTools::getProperty($this->props, $key, $dflt);
 }
 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);
     }
 }
Beispiel #14
0
 public function filter($str, $prop)
 {
     $saveMode = null;
     if ($prop !== null) {
         $saveMode = com_wiris_system_PropertiesTools::getProperty($prop, "savemode", null);
     }
     if ($saveMode === null) {
         $saveMode = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$SAVE_MODE, "xml");
     }
     $b = null;
     $b = $saveMode === "safeXml";
     $tags = null;
     if ($b) {
         $tags = com_wiris_plugin_impl_TextFilterTags::newSafeXml();
     } else {
         $tags = com_wiris_plugin_impl_TextFilterTags::newXml();
     }
     $str = $this->filterMath($tags, $str, $prop, $b);
     $str = $this->filterApplet($tags, $str, $prop, $b);
     return $str;
 }
 public function editor($language, $prop)
 {
     $output = new StringBuf();
     if ($language === null || strlen($language) === 0) {
         $language = "en";
     }
     $language = strtolower($language);
     str_replace("-", "_", $language);
     $store = com_wiris_system_Storage::newResourceStorage("lang/" . $language . "/strings.js");
     if (!$store->exists()) {
         $store = com_wiris_system_Storage::newResourceStorage("lang/" . _hx_substr($language, 0, 2) . "/strings.js");
         $language = _hx_substr($language, 0, 2);
         if (!$store->exists()) {
             $language = "en";
         }
     }
     $attributes = new StringBuf();
     $attributes->add("");
     $confVal = "";
     $i = 0;
     $config = $this->plugin->getConfiguration();
     $h = com_wiris_plugin_api_ConfigurationKeys::$imageConfigPropertiesInv;
     $it = $h->keys();
     $value = null;
     while ($it->hasNext()) {
         $value = $it->next();
         if ($config->getProperty($value, null) !== null) {
             if ($i !== 0) {
                 $attributes->add(",");
             }
             $i++;
             $confVal = $config->getProperty($value, null);
             str_replace("-", "_", $confVal);
             str_replace("-", "_", $confVal);
             $attributes->add("'");
             $attributes->add(com_wiris_plugin_api_ConfigurationKeys::$imageConfigPropertiesInv->get($value));
             $attributes->add("' : '");
             $attributes->add($confVal);
             $attributes->add("'");
         }
     }
     $script = new StringBuf();
     if ($i > 0) {
         $script->add("<script type=\"text/javascript\">window.wrs_attributes = {");
         $script->add($attributes);
         $script->add("};</script>");
     }
     $editorUrl = $this->plugin->getImageServiceURL("editor");
     $isSegure = com_wiris_system_PropertiesTools::getProperty($prop, "secure", "false") === "true";
     if (StringTools::startsWith($editorUrl, "http:") && $isSegure) {
         $editorUrl = "https:" . _hx_substr($editorUrl, 5, null);
     }
     $this->addLine($output, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
     $this->addLine($output, "<html><head>");
     $this->addLine($output, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>");
     $this->addLine($output, $script->b);
     $this->addLine($output, "<script type=\"text/javascript\" src=\"" . $editorUrl . "?lang=" . rawurlencode($language) . "\"></script>");
     $this->addLine($output, "<script type=\"text/javascript\" src=\"../core/editor.js\"></script>");
     $this->addLine($output, "<script type=\"text/javascript\" src=\"../lang/" . rawurlencode($language) . "/strings.js\"></script>");
     $this->addLine($output, "<title>WIRIS editor</title>");
     $this->addLine($output, "<style type=\"text/css\">/*<!--*/html, body, #container { height: 100%; } body { margin: 0; }");
     $this->addLine($output, "#links { text-align: right; margin-right: 20px; } #links_rtl {text-align: left; margin-left: 20px;} #controls { float: left; } #controls_rtl {float: right;}/*-->*/</style>");
     $this->addLine($output, "</head><body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">");
     $this->addLine($output, "<div id=\"container\"><div id=\"editorContainer\"></div><div id=\"controls\"></div>");
     $this->addLine($output, "<div id=\"links\"><a href=\"http://www.wiris.com/editor3/docs/manual/latex-support\" id=\"a_latex\" target=\"_blank\">LaTeX</a> | ");
     $this->addLine($output, "<a href=\"http://www.wiris.com/editor3/docs/manual\" target=\"_blank\" id=\"a_manual\">Manual</a></div></div></body>");
     return $output->b;
 }