/** * Returns the content of global concept IDs stream as text with local IDs * * @param mixed $instream - source data with global concept IDs */ function importTemplate() { global $dir; if (!$_FILES['import_template']['size']) { $res = array("error" => 'Error occurred during upload - file had zero size'); } else { $filename = $_FILES['import_template']['tmp_name']; $origfilename = $_FILES['import_template']['name']; //read tempfile $template = file_get_contents($filename); $res = convertTemplate($template, 1); if (!is_array($res)) { $res = array('template' => $res); } if (!@$res['error']) { //check if template with such name already exists /*while (file_exists($dir.$origfilename)){ $dir.$origfilename = $dir.$origfilename . "($cnt)"; }*/ $origfilename = getUniqueTemplateName($origfilename); $res2 = saveTemplate($res['template'], $origfilename); if (count(@$res['details_not_found']) > 0) { $res2['details_not_found'] = $res['details_not_found']; } $res = $res2; } } //header("Content-type: text/javascript"); header('Content-type: application/json'); print json_encode($res); //print json_format($res); }
/** * Reads given template file contents. * It prepares it for filling. * It fills it with template variables values provided. * It does special HTML formatting if needed, e.g. draw red debug template frames. * * * @param string $folder_name Template file path: full folder path. * @param string $tmpl_short_filename Template file path: file name. * @param arrat $vars Template variables values. * @return string template html contents with tags replaced with their values. */ function fill($folder_name, $tmpl_short_filename, $vars, $customer_zone = false) { //Open file, read contents, replace tags. $this->PreviousTemplateFilename = $this->CurrentTemplateFilename; if ($customer_zone) { $this->CurrentTemplateFilename = getTemplateFileAbsolutePath($this->TemplateDirPrefix . $folder_name . $tmpl_short_filename); } else { $this->CurrentTemplateFilename = $this->TemplateDirPrefix . $folder_name . "views/admin/templates/" . $tmpl_short_filename; if (!is_file($this->CurrentTemplateFilename)) { $this->CurrentTemplateFilename = $this->TemplateDirPrefix . $folder_name . $tmpl_short_filename; } if (!is_file($this->CurrentTemplateFilename)) { $this->CurrentTemplateFilename = modApiFunc('application', 'getAppIni', 'PATH_ADMIN_TPLS_VIEWS') . $folder_name . $tmpl_short_filename; } } $code_to_include = $this->getCachedCode($this->CurrentTemplateFilename); if ($code_to_include === null) { $tpl_file = new CFile($this->CurrentTemplateFilename); $code_to_include = $tpl_file->getContent(); // , ( > 128) $code_to_include = convertTemplate($code_to_include); if ($code_to_include === FALSE) { CTrace::backtrace(); _fatal("TMPL_FILLER_ERROR_CANNOT_READ_FILE", $this->CurrentTemplateFilename); } $code_to_include = '?>' . $this->removeTemplateWrapper($code_to_include); $this->saveInCache($this->CurrentTemplateFilename, $code_to_include); } $text = $this->includeTmplCode($code_to_include); $_vars = array(); foreach ($vars as $key => $value) { $_vars['{' . $key . '}'] = $value; } $text = strtr($text, $_vars); $text = $this->addCrossSiteProtectinField($text); return $text; }