public function addCorsHeaders($response, $origin)
 {
     $conf = $this->getConfiguration();
     if ($conf->getProperty("wiriscorsenabled", "false") === "true") {
         $confDir = $conf->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CONFIGURATION_PATH, null);
         $corsConfFile = $confDir . "/corsservers.ini";
         $s = com_wiris_system_Storage::newStorage($corsConfFile);
         if ($s->exists()) {
             $dir = $s->read();
             $allowedHosts = _hx_explode("\n", $dir);
             if (com_wiris_system_ArrayEx::contains($allowedHosts, $origin)) {
                 $response->setHeader("Access-Control-Allow-Origin", $origin);
             }
         } else {
             $response->setHeader("Access-Control-Allow-Origin", "*");
         }
     }
 }
 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 cas($mode, $language)
 {
     $output = new StringBuf();
     $output->add("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
     $config = $this->plugin->getConfiguration();
     $availableLanguages = $this->getAvailableCASLanguages($config->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CAS_LANGUAGES, null));
     if ($language === null || !com_wiris_system_ArrayEx::contains($availableLanguages, $language)) {
         $language = $availableLanguages[0];
     }
     if ($mode !== null && $mode === "applet") {
         $codebase = str_replace("%LANG", $language, $config->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CAS_CODEBASE, null));
         $archive = str_replace("%LANG", $language, $config->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CAS_ARCHIVE, null));
         $className = str_replace("%LANG", $language, $config->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CAS_CLASS, null));
         $output->add($this->printCAS($codebase, $archive, $className));
     } else {
         $output->add($this->printCASContainer($config, $availableLanguages, $language));
     }
     return $output->b;
 }