/** * @brief Get the points */ function getPoint($member_srl, $from_db = false) { $member_srl = abs($member_srl); // Get from instance memory if (!$from_db && $this->pointList[$member_srl]) { return $this->pointList[$member_srl]; } // Get from file cache $path = sprintf(_XE_PATH_ . 'files/member_extra_info/point/%s', getNumberingPath($member_srl)); $cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl); if (!$from_db && file_exists($cache_filename)) { return $this->pointList[$member_srl] = trim(FileHandler::readFile($cache_filename)); } // Get from the DB $args = new stdClass(); $args->member_srl = $member_srl; $output = executeQuery('point.getPoint', $args); if (isset($output->data->member_srl)) { $point = (int) $output->data->point; $this->pointList[$member_srl] = $point; if (!is_dir($path)) { FileHandler::makeDir($path); } FileHandler::writeFile($cache_filename, $point); return $point; } return 0; }
function _getWidgetContent() { // Arrange a widget ryeolro if ($this->module_info->mcontent) { $cache_file = sprintf("%sfiles/cache/page/%d.%s.m.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getLangType()); $interval = (int) $this->module_info->page_caching_interval; if ($interval > 0) { if (!file_exists($cache_file) || filesize($cache_file) < 1) { $mtime = 0; } else { $mtime = filemtime($cache_file); } if ($mtime + $interval * 60 > time()) { $page_content = FileHandler::readFile($cache_file); $page_content = preg_replace('@<\\!--#Meta:@', '<!--Meta:', $page_content); } else { $oWidgetController =& getController('widget'); $page_content = $oWidgetController->transWidgetCode($this->module_info->mcontent); FileHandler::writeFile($cache_file, $page_content); } } else { if (file_exists($cache_file)) { FileHandler::removeFile($cache_file); } $page_content = $this->module_info->mcontent; } } else { preg_match_all('!(<img)([^\\>]*)(widget=)([^\\>]*?)(\\>)!is', $this->module_info->content, $matches); $page_content = ''; for ($i = 0, $c = count($matches[0]); $i < $c; $i++) { $page_content .= preg_replace('/ style\\=\\"([^\\"]+)\\" /i', ' style="overflow:hidden;clear:both;margin:0 0 20px 0; _margin-right:10px;" ', $matches[0][$i]) . "\n\n"; } } return $page_content; }
function _getWidgetContent() { // Arrange a widget ryeolro if ($this->module_info->mcontent) { $cache_file = sprintf("%sfiles/cache/page/%d.%s.m.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getLangType()); $interval = (int) $this->module_info->page_caching_interval; if ($interval > 0) { if (!file_exists($cache_file) || filesize($cache_file) < 1) { $mtime = 0; } else { $mtime = filemtime($cache_file); } if ($mtime + $interval * 60 > $_SERVER['REQUEST_TIME']) { $page_content = FileHandler::readFile($cache_file); $page_content = preg_replace('@<\\!--#Meta:@', '<!--Meta:', $page_content); } else { $oWidgetController = getController('widget'); $page_content = $oWidgetController->transWidgetCode($this->module_info->mcontent); FileHandler::writeFile($cache_file, $page_content); } } else { if (file_exists($cache_file)) { FileHandler::removeFile($cache_file); } $page_content = $this->module_info->mcontent; } } else { $page_content = $this->module_info->content; } return $page_content; }
function getNewsFromAgency() { //Retrieve recent news and set them into context $newest_news_url = sprintf("http://www.xeshoppingmall.com/?module=newsagency&act=getNewsagencyArticle&inst=notice&top=6&loc=%s", _XE_LOCATION_); $cache_file = sprintf("%sfiles/cache/nstore_news.%s.cache.php", _XE_PATH_, _XE_LOCATION_); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) { // Considering if data cannot be retrieved due to network problem, modify filemtime to prevent trying to reload again when refreshing textmessageistration page // Ensure to access the textmessageistration page even though news cannot be displayed FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } if (file_exists($cache_file)) { $oXml = new XmlParser(); $buff = $oXml->parse(FileHandler::readFile($cache_file)); $item = $buff->zbxe_news->item; if ($item) { if (!is_array($item)) { $item = array($item); } foreach ($item as $key => $val) { $obj = null; $obj->title = $val->body; $obj->date = $val->attrs->date; $obj->url = $val->attrs->url; $news[] = $obj; } return $news; } } }
/** * @brief 일반 요청시 출력 **/ function dispPageIndex() { // 템플릿에서 사용할 변수를 Context::set() if ($this->module_srl) { Context::set('module_srl', $this->module_srl); } // 캐시 파일 지정 $cache_file = sprintf("%sfiles/cache/page/%d.%s.cache.php", _XE_PATH_, $this->module_info->module_srl, Context::getLangType()); $interval = (int) $this->module_info->page_caching_interval; if ($interval > 0) { if (!file_exists($cache_file)) { $mtime = 0; } else { $mtime = filemtime($cache_file); } if ($mtime + $interval * 60 > time()) { $page_content = FileHandler::readFile($cache_file); } else { $oWidgetController =& getController('widget'); $page_content = $oWidgetController->transWidgetCode($this->module_info->content); FileHandler::writeFile($cache_file, $page_content); } } else { if (file_exists($cache_file)) { FileHandler::removeFile($cache_file); } $page_content = $this->module_info->content; } Context::set('module_info', $this->module_info); Context::set('page_content', $page_content); $this->setTemplateFile('content'); }
function procAuthenticationAdminConfig() { $args = Context::getRequestVars(); if (!trim(strip_tags($args->agreement))) { $agreement_file = _XE_PATH_ . 'files/authentication/agreement_' . Context::get('lang_type') . '.txt'; FileHandler::removeFile($agreement_file); $args->agreement = NULL; } // check agreement value exist if ($args->agreement) { $agreement_file = _XE_PATH_ . 'files/authentication/agreement_' . Context::get('lang_type') . '.txt'; $output = FileHandler::writeFile($agreement_file, $args->agreement); unset($args->agreement); } if (!$args->sender_no) { $args->sender_no = NULL; } if (!$args->message_content) { $args->message_content = NULL; } if (!$args->list) { $args->list = NULL; } if (!$args->cellphone_fieldname) { $args->cellphone_fieldname = NULL; } // save module configuration. $oModuleController = getController('module'); $output = $oModuleController->updateModuleConfig('authentication', $args); $this->setMessage('success_saved'); $redirectUrl = getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAuthenticationAdminConfig'); $this->setRedirectUrl($redirectUrl); }
/** * Cache a variable in the data store * * @param string $key Store the variable using this name. * @param mixed $obj The variable to store * @param int $valid_time Not used * @return void */ function put($key, $obj, $valid_time = 0) { $cache_file = $this->getCacheFileName($key); $content = array(); $content[] = '<?php'; $content[] = 'if(!defined(\'__XE__\')) { exit(); }'; $content[] = 'return \'' . addslashes(serialize($obj)) . '\';'; FileHandler::writeFile($cache_file, implode(PHP_EOL, $content)); }
/** * @brief Display messages about installation environment */ function dispInstallCheckEnv() { // Create a temporary file for mod_rewrite check. self::$rewriteCheckString = Password::createSecureSalt(32); FileHandler::writeFile(_XE_PATH_ . self::$rewriteCheckFilePath, self::$rewriteCheckString); // Check if the web server is nginx. Context::set('use_nginx', stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false); $this->setTemplateFile('check_env'); }
function getThumbnailByUrl($image_url, $width = 80, $height = 0, $thumbnail_type = '') { if (!$height) { $height = $width; } if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $config = $GLOBALS['__document_config__']; if (!$config) { $oDocumentModel = getModel('document'); $config = $oDocumentModel->getDocumentConfig(); $GLOBALS['__document_config__'] = $config; } $thumbnail_type = $config->thumbnail_type; } if (!is_dir('./files/thumbnails/magiccontent_thumbnail')) { FileHandler::makeDir('./files/thumbnails/magiccontent_thumbnail'); } $thumbnail_path = sprintf('files/thumbnails/magiccontent_thumbnail/%s', base64_encode($image_url)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return false; } else { return $thumbnail_url; } } $tmp_file = sprintf('./files/cache/tmp/%s', md5(rand(111111, 999999) . $image_url)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } if (!preg_match('/^(http|https):\\/\\//i', $image_url)) { $image_url = Context::getRequestUri() . $image_url; } FileHandler::getRemoteFile($image_url, $tmp_file); if (!file_exists($tmp_file)) { return false; } else { list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file); if (!in_array($_t, array(1, 2, 3, 6, 7, 8))) { FileHandler::writeFile($thumbnail_file, '', 'w'); return false; } $source_file = $tmp_file; } $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); FileHandler::removeFile($source_file); if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return false; }
function checkLicense($prodid, $user_id, $serial_number, $force = FALSE) { $hostinfo = array($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_NAME'], $_SERVER['HTTP_HOST']); $agency_url = sprintf("http://www.xeshoppingmall.com/?module=drmagency&act=getDrmagencyLicense&prodid=%s&hostinfo=%s&user=%s&serial=%s", $prodid, implode(',', $hostinfo), $user_id, $serial_number); $cache_file = sprintf("%sfiles/cache/license_%s.cache.php", _XE_PATH_, $prodid); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time() || $force == TRUE) { FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($agency_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } return $cache_file; }
function dispNcenterliteAdminConfig() { $oModuleModel = getModel('module'); $oNcenterliteModel = getModel('ncenterlite'); $oLayoutModel = getModel('layout'); $config = $oNcenterliteModel->getConfig(); Context::set('config', $config); $layout_list = $oLayoutModel->getLayoutList(); Context::set('layout_list', $layout_list); $mobile_layout_list = $oLayoutModel->getLayoutList(0, 'M'); Context::set('mlayout_list', $mobile_layout_list); $skin_list = $oModuleModel->getSkins($this->module_path); Context::set('skin_list', $skin_list); $mskin_list = $oModuleModel->getSkins($this->module_path, "m.skins"); Context::set('mskin_list', $mskin_list); if (!$skin_list[$config->skin]) { $config->skin = 'default'; } Context::set('colorset_list', $skin_list[$config->skin]->colorset); if (!$mskin_list[$config->mskin]) { $config->mskin = 'default'; } Context::set('mcolorset_list', $mskin_list[$config->mskin]->colorset); $security = new Security(); $security->encodeHTML('config..'); $security->encodeHTML('skin_list..title'); $security->encodeHTML('colorset_list..name', 'colorset_list..title'); $mid_list = $oModuleModel->getMidList(null, array('module_srl', 'mid', 'browser_title', 'module')); Context::set('mid_list', $mid_list); // 사용환경정보 전송 확인 $ncenterlite_module_info = $oModuleModel->getModuleInfoXml('ncenterlite'); $agreement_file = FileHandler::getRealPath(sprintf('%s%s.txt', './files/ncenterlite/ncenterlite-', $ncenterlite_module_info->version)); $agreement_ver_file = FileHandler::getRealPath(sprintf('%s%s.txt', './files/ncenterlite/ncenterlite_ver-', $ncenterlite_module_info->version)); if (file_exists($agreement_file)) { $agreement = FileHandler::readFile($agreement_file); Context::set('_ncenterlite_env_agreement', $agreement); $agreement_ver = FileHandler::readFile($agreement_ver_file); if ($agreement == 'Y') { $_ncenterlite_iframe_url = 'http://sosifam.com/index.php?mid=ncenterlite_iframe'; if (!$agreement_ver) { $_host_info = urlencode($_SERVER['HTTP_HOST']) . '-NC' . $ncenterlite_module_info->version . '-PHP' . phpversion() . '-XE' . __XE_VERSION__; } Context::set('_ncenterlite_iframe_url', $_ncenterlite_iframe_url . '&_host=' . $_host_info); Context::set('ncenterlite_module_info', $ncenterlite_module_info); } FileHandler::writeFile($agreement_ver_file, 'Y'); } else { Context::set('_ncenterlite_env_agreement', 'NULL'); } }
/** * 1. Read xml file<br /> * 2. Check the action<br /> * 3. Parsing and write a cache file<br /> * @return QueryParser object */ function &parse_xml_query($query_id, $xml_file, $cache_file) { // Read xml file $xml_obj = $this->getXmlFileContent($xml_file); // insert, update, delete, select action $action = strtolower($xml_obj->query->attrs->action); if (!$action) { return; } // Write query cache file $parser = new QueryParser($xml_obj->query); FileHandler::writeFile($cache_file, $parser->toString()); return $parser; }
function setExifCache($cache_path, $cache_file, &$exif_data) { if (!$exif_data['make']) { return false; } unset($exif_data['Thumbnail']); $cache = '<?php if(!defined("__ZBXE__")) exit();' . "\r\n"; foreach ($exif_data as $key => $val) { $cache .= "\$exif_data['" . $key . "'] = \"" . $val . "\";\r\n"; } $cache .= '?>'; if (!is_dir($cache_path)) { FileHandler::makeDir($cache_path); } FileHandler::writeFile($cache_path . $cache_file, $cache); }
/** * @brief 포인트를 구해옴 **/ function getPoint($member_srl, $from_db = false) { $member_srl = abs($member_srl); $path = sprintf('./files/member_extra_info/point/%s', getNumberingPath($member_srl)); if (!is_dir($path)) { FileHandler::makeDir($path); } $cache_filename = sprintf('%s%d.cache.txt', $path, $member_srl); if (!$from_db && file_exists($cache_filename)) { return trim(FileHandler::readFile($cache_filename)); } // DB에서 가져옴 $args->member_srl = $member_srl; $output = executeQuery('point.getPoint', $args); $point = (int) $output->data->point; FileHandler::writeFile($cache_filename, $point); return $point; }
/** * @brief 계층구조 추출 * document_category테이블을 이용해서 위키 문서의 계층 구조도를 그림 * document_category테이블에 등록되어 있지 않은 경우 depth = 0 으로 하여 신규 생성 **/ function getWikiTreeList() { header("Content-Type: text/xml; charset=UTF-8"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $oModuleModel =& getModel('module'); $mid = Context::get('mid'); $cache_file = sprintf('%sfiles/cache/wiki/%d.xml', _XE_PATH_, $this->module_srl); if ($this->grant->write_document || !file_exists($cache_file)) { FileHandler::writeFile($cache_file, $this->loadWikiTreeList($this->module_srl)); } print FileHandler::readFile($cache_file); Context::close(); exit; }
/** * @brief Display Super Admin Dashboard **/ function dispTextmessageAdminIndex() { $oTextmessageModel = getModel('textmessage'); $config = $oTextmessageModel->getConfig(); if (!$config) { Context::set('isSetupCompleted', false); } else { Context::set('isSetupCompleted', true); } Context::set('config', $config); //Retrieve recent news and set them into context $newest_news_url = sprintf("http://www.coolsms.co.kr/?module=newsagency&act=getNewsagencyArticle&inst=notice&loc=%s", _XE_LOCATION_); $cache_file = sprintf("%sfiles/cache/cool_news.%s.cache.php", _XE_PATH_, _XE_LOCATION_); if (!file_exists($cache_file) || filemtime($cache_file) + 60 * 60 < time()) { // Considering if data cannot be retrieved due to network problem, modify filemtime to prevent trying to reload again when refreshing textmessageistration page // Ensure to access the textmessage registration page even though news cannot be displayed FileHandler::writeFile($cache_file, ''); FileHandler::getRemoteFile($newest_news_url, $cache_file, null, 1, 'GET', 'text/html', array('REQUESTURL' => getFullUrl(''))); } if (file_exists($cache_file)) { $oXml = new XmlParser(); $buff = $oXml->parse(FileHandler::readFile($cache_file)); $item = $buff->zbxe_news->item; if ($item) { if (!is_array($item)) { $item = array($item); } foreach ($item as $key => $val) { $obj = new stdClass(); $obj->title = $val->body; $obj->date = $val->attrs->date; $obj->url = $val->attrs->url; $news[] = $obj; } Context::set('news', $news); } Context::set('released_version', $buff->zbxe_news->attrs->released_version); Context::set('download_link', $buff->zbxe_news->attrs->download_link); } $this->setTemplateFile('index'); }
/** * Compile XE-compatible XML lang files into PHP. * * @param string $filename * @param string $language * @return string|false */ public static function compileXMLtoPHP($filename, $language, $output_filename = null) { // Check if the cache file already exists. if ($output_filename === null) { $output_filename = RX_BASEDIR . 'files/cache/lang/' . md5($filename) . '.' . $language . '.php'; if (file_exists($output_filename) && filemtime($output_filename) > filemtime($filename)) { return $output_filename; } } // Load the XML lang file. $xml = @simplexml_load_file($filename); if ($xml === false) { \FileHandler::writeFile($output_filename, ''); return false; } // Convert XML to a PHP array. $lang = array(); self::_toArray($xml, $lang, $language); unset($xml); // Save the array as a cache file. $buff = "<?php\n"; foreach ($lang as $key => $value) { if (is_array($value)) { foreach ($value as $subkey => $subvalue) { if (is_array($subvalue)) { foreach ($subvalue as $subsubkey => $subsubvalue) { $buff .= '$lang->' . $key . "['{$subkey}']['{$subsubkey}']" . ' = ' . var_export($subsubvalue, true) . ";\n"; } } else { $buff .= '$lang->' . $key . "['{$subkey}']" . ' = ' . var_export($subvalue, true) . ";\n"; } } } else { $buff .= '$lang->' . $key . ' = ' . var_export($value, true) . ";\n"; } } \FileHandler::writeFile($output_filename, $buff); return $output_filename; }
function _createInsertAddressRuleset($fieldset_list) { $xml_file = './files/ruleset/ncart_insertAddress.xml'; $buff = '<?xml version="1.0" encoding="utf-8"?>' . '<ruleset version="1.5.0">' . '<customrules>' . '</customrules>' . '<fields>%s</fields>' . '</ruleset>'; $fields = array(); $fields[] = '<field name="member_srl" required="true" rule="number" />'; $fields[] = '<field name="opt" required="true" />'; $fields[] = '<field name="title" required="true" />'; $fields[] = '<field name="address" required="true" />'; if (count($fieldset_list)) { foreach ($fieldset_list as $fieldset) { foreach ($fieldset->fields as $field) { if ($field->required == 'Y') { switch ($field->column_type) { case 'tel': case 'kr_zip': $fields[] = sprintf('<field name="%s[]" required="true" />', $field->column_name); break; case 'email_address': $fields[] = sprintf('<field name="%s" required="true" rule="email"/>', $field->column_name); break; case 'user_id': $fields[] = sprintf('<field name="%s" required="true" rule="userid" length="3:20" />', $field->column_name); break; default: $fields[] = sprintf('<field name="%s" required="true" />', $field->column_name); break; } } } } } $xml_buff = sprintf($buff, implode('', $fields)); FileHandler::writeFile($xml_file, $xml_buff); unset($xml_buff); $validator = new Validator($xml_file); $validator->setCacheDir('files/cache'); $validator->getJsPath(); }
function getThumbnail($file_srl = null, $width = 80, $height = 0, $thumbnail_type = 'crop') { $oFileModel = getModel('file'); if (!$file_srl) { return; } if (!$height) { $height = $width; } // Define thumbnail information $thumbnail_path = sprintf('files/cache/thumbnails/%s', getNumberingPath($file_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // Return false if thumbnail file exists and its size is 0. Otherwise, return its path if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return false; } else { return $thumbnail_url; } } // Target File $source_file = NULL; $file = $oFileModel->getFile($file_srl); if ($file) { $source_file = $file->uploaded_filename; } if ($source_file) { $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); } // Return its path if a thumbnail is successfully genetated if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
/** * @brief Modules conf/info.xml wanted to read the information * It uses caching to reduce time for xml parsing .. */ function getWidgetStyleInfo($widgetStyle) { $widgetStyle_path = $this->getWidgetStylePath($widgetStyle); if (!$widgetStyle_path) { return; } $xml_file = sprintf("%sskin.xml", $widgetStyle_path); if (!file_exists($xml_file)) { return; } // If the problem by comparing the cache file and include the return variable $widgetStyle_info $cache_file = sprintf(_XE_PATH_ . 'files/cache/widgetstyles/%s.%s.cache.php', $widgetStyle, Context::getLangType()); if (file_exists($cache_file) && filemtime($cache_file) > filemtime($xml_file)) { @(include $cache_file); return $widgetStyle_info; } // If no cache file exists, parse the xml and then return the variable. $oXmlParser = new XmlParser(); $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file); $xml_obj = $tmp_xml_obj->widgetstyle; if (!$xml_obj) { return; } $buff = array(); $buff[] = '<?php if(!defined("__XE__")) exit();'; $buff[] = '$widgetStyle_info = new stdClass();'; // Title of the widget, version $buff[] = sprintf('$widgetStyle_info->widgetStyle = "%s";', $widgetStyle); $buff[] = sprintf('$widgetStyle_info->path = "%s";', $widgetStyle_path); $buff[] = sprintf('$widgetStyle_info->title = "%s";', $xml_obj->title->body); $buff[] = sprintf('$widgetStyle_info->description = "%s";', $xml_obj->description->body); $buff[] = sprintf('$widgetStyle_info->version = "%s";', $xml_obj->version->body); sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d); $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); $buff[] = sprintf('$widgetStyle_info->date = "%s";', $date); $buff[] = sprintf('$widgetStyle_info->homepage = "%s";', $xml_obj->link->body); $buff[] = sprintf('$widgetStyle_info->license = "%s";', $xml_obj->license->body); $buff[] = sprintf('$widgetStyle_info->license_link = "%s";', $xml_obj->license->attrs->link); // preview if (!$xml_obj->preview->body) { $xml_obj->preview->body = 'preview.jpg'; } $preview_file = sprintf("%s%s", $widgetStyle_path, $xml_obj->preview->body); if (file_exists($preview_file)) { $buff[] = sprintf('$widgetStyle_info->preview = "%s";', $preview_file); } // Author information if (!is_array($xml_obj->author)) { $author_list[] = $xml_obj->author; } else { $author_list = $xml_obj->author; } foreach ($author_list as $idx => $author) { $buff[] = sprintf('$widgetStyle_info->author[%d] = new stdClass();', $idx); $buff[] = sprintf('$widgetStyle_info->author[%d]->name = "%s";', $idx, $author->name->body); $buff[] = sprintf('$widgetStyle_info->author[%d]->email_address = "%s";', $idx, $author->attrs->email_address); $buff[] = sprintf('$widgetStyle_info->author[%d]->homepage = "%s";', $idx, $author->attrs->link); } // Extra vars (user defined variables to use in a template) $extra_var_groups = $xml_obj->extra_vars->group; if (!$extra_var_groups) { $extra_var_groups = $xml_obj->extra_vars; } if (!is_array($extra_var_groups)) { $extra_var_groups = array($extra_var_groups); } $extra_var_count = 0; $buff[] = sprintf('$widgetStyle_info->extra_var = new stdClass();', $extra_var_count); foreach ($extra_var_groups as $group) { $extra_vars = !is_array($group->var) ? array($group->var) : $group->var; if ($extra_vars[0]->attrs->id || $extra_vars[0]->attrs->name) { foreach ($extra_vars as $var) { $extra_var_count++; $id = $var->attrs->id ? $var->attrs->id : $var->attrs->name; $name = $var->name->body ? $var->name->body : $var->title->body; $type = $var->attrs->type ? $var->attrs->type : $var->type->body; $buff[] = sprintf('$widgetStyle_info->extra_var->%s = new stdClass();', $id); $buff[] = sprintf('$widgetStyle_info->extra_var->%s->group = "%s";', $id, $group->title->body); $buff[] = sprintf('$widgetStyle_info->extra_var->%s->name = "%s";', $id, $name); $buff[] = sprintf('$widgetStyle_info->extra_var->%s->type = "%s";', $id, $type); if ($type == 'filebox') { $buff[] = sprintf('$widgetStyle_info->extra_var->%s->filter = "%s";', $id, $var->attrs->filter); $buff[] = sprintf('$widgetStyle_info->extra_var->%s->allow_multiple = "%s";', $id, $var->attrs->allow_multiple); } $buff[] = sprintf('$widgetStyle_info->extra_var->%s->value = $vars->%s;', $id, $id); $buff[] = sprintf('$widgetStyle_info->extra_var->%s->description = "%s";', $id, str_replace('"', '\\"', $var->description->body)); if ($var->options) { $var_options = !is_array($var->options) ? array($var->options) : $var->options; foreach ($var_options as $option_item) { $buff[] = sprintf('$widgetStyle_info->extra_var->%s->options["%s"] = "%s";', $id, $option_item->value->body, $option_item->name->body); } } } } } $buff[] = sprintf('$widgetStyle_info->extra_var_count = %d;', $extra_var_count); FileHandler::writeFile($cache_file, implode(PHP_EOL, $buff)); if (file_exists($cache_file)) { @(include $cache_file); } return $widgetStyle_info; }
/** * Add products info to export folder * @author Dan Dragan (dev@xpressengine.org) * * @param array $products * * @return boolean */ public function addProductsToExportFolder($products) { $buff = ''; //table header for products csv foreach ($products[0] as $key => $value) { if (!in_array($key, array('member_srl', 'module_srl', 'regdate', 'last_update', 'primary_image', 'repo', 'associated_products', 'cache'))) { if ($key == 'product_srl') { $buff = $buff . 'id,'; } else { $buff = $buff . $key . ","; } } } $buff = $buff . "configurable_attributes\r\n"; //table values for products csv foreach ($products as $product) { // add images to temp folder foreach ($product->images as $image) { $path = sprintf('./files/attach/images/shop/%d/product-images/%d/', $image->module_srl, $image->product_srl); $filename = sprintf('%s%s', $path, $image->filename); $export_filename = sprintf('./files/attach/shop/export-import/images/%s', $image->product_srl . $image->filename); FileHandler::copyFile($filename, $export_filename); } foreach ($product as $key => $value) { if (!in_array($key, array('member_srl', 'module_srl', 'regdate', 'last_update', 'primary_image', 'primary_image_filename', 'repo', 'categories', 'attributes', 'images', 'associated_products', 'configurable_attributes', 'cache'))) { $buff = $buff . str_replace(",", ";;", $value) . ","; } if ($key == 'primary_image_filename') { if (isset($product->primary_image_filename)) { $buff = $buff . $product->product_srl . $value . ","; } else { $buff = $buff . ","; } } $product_categories = ''; if ($key == 'categories') { foreach ($value as $category) { if ($product_categories == '') { $product_categories = $category; } else { $product_categories = $product_categories . '|' . $category; } } $buff = $buff . $product_categories . ","; } $product_attributes = ''; if ($key == 'attributes') { foreach ($value as $attribute_srl => $attribute_value) { if ($product_attributes == '') { $product_attributes = $attribute_srl . '=' . $attribute_value; } else { $product_attributes = $product_attributes . '|' . $attribute_srl . '=' . $attribute_value; } } $buff = $buff . $product_attributes . ","; } $images = ''; if ($key == 'images') { foreach ($value as $image) { if ($image->filename) { if ($images == '') { $images = $product->product_srl . $image->filename; } else { $images = $images . '|' . $product->product_srl . $image->filename; } } } $buff = $buff . $images . ","; } if ($key == 'configurable_attributes') { $configurable_attributes = ''; foreach ($value as $attribute_srl => $attribute_value) { if ($configurable_attributes == '') { $configurable_attributes = $attribute_srl; } else { $configurable_attributes = $configurable_attributes . '+' . $attribute_srl; } } } } $buff = $buff . $configurable_attributes . "\r\n"; } $product_csv_filename = 'products.csv'; $product_csv_path = sprintf('./files/attach/shop/export-import/%s', $product_csv_filename); FileHandler::writeFile($product_csv_path, $buff); return TRUE; }
/** * @brief create insert item ruleset **/ function _createInsertItemRuleset($extra_vars) { $xml_file = './files/ruleset/nproduct_insertItem.xml'; $buff = '<?xml version="1.0" encoding="utf-8"?>' . '<ruleset version="1.5.0">' . '<customrules>' . '</customrules>' . '<fields>%s</fields>' . '</ruleset>'; $fields = array(); $fields[] = '<field name="module_srl" required="true" />'; $fields[] = '<field name="item_name" required="true" length="1:60" />'; $fields[] = '<field name="document_srl" required="true" rule="number" />'; $fields[] = '<field name="price" required="true" rule="number" />'; $fields[] = '<field name="description" required="true" />'; if (count($extra_vars)) { foreach ($extra_vars as $formInfo) { if ($formInfo->required == 'Y') { if ($formInfo->type == 'tel' || $formInfo->type == 'kr_zip') { $fields[] = sprintf('<field name="%s[]" required="true" />', $formInfo->column_name); } else { if ($formInfo->type == 'email_address') { $fields[] = sprintf('<field name="%s" required="true" rule="email"/>', $formInfo->column_name); } else { if ($formInfo->type == 'user_id') { $fields[] = sprintf('<field name="%s" required="true" rule="userid" length="3:20" />', $formInfo->column_name); } else { $fields[] = sprintf('<field name="%s" required="true" />', $formInfo->column_name); } } } } } } $xml_buff = sprintf($buff, implode('', $fields)); FileHandler::writeFile($xml_file, $xml_buff); unset($xml_buff); $validator = new Validator($xml_file); $validator->setCacheDir('files/cache'); $validator->getJsPath(); }
/** * @brief 레이아웃 미리 보기 **/ function dispLayoutAdminPreview() { $layout_srl = Context::get('layout_srl'); $code = Context::get('code'); $code_css = Context::get('code_css'); if (!$layout_srl || !$code) { return new Object(-1, 'msg_invalid_request'); } // 레이아웃 정보 가져오기 $oLayoutModel =& getModel('layout'); $layout_info = $oLayoutModel->getLayout($layout_srl); if (!$layout_info) { return new Object(-1, 'msg_invalid_request'); } // faceoff 레이아웃일 경우 별도 처리 if ($layout_info && $layout_info->type == 'faceoff') { $oLayoutModel->doActivateFaceOff($layout_info); } // 직접 입력된 CSS 적용 Context::addHtmlHeader("<style type=\"text/css\" charset=\"UTF-8\">" . $code_css . "</style>"); // 레이아웃 정보중 extra_vars의 이름과 값을 $layout_info에 입력 if ($layout_info->extra_var_count) { foreach ($layout_info->extra_var as $var_id => $val) { $layout_info->{$var_id} = $val->value; } } // 레이아웃 정보중 menu를 Context::set if ($layout_info->menu_count) { foreach ($layout_info->menu as $menu_id => $menu) { if (file_exists($menu->php_file)) { @(include $menu->php_file); } Context::set($menu_id, $menu); } } Context::set('layout_info', $layout_info); Context::set('content', Context::getLang('layout_preview_content')); // 코드를 임시로 저장 $edited_layout_file = sprintf('./files/cache/layout/tmp.tpl'); FileHandler::writeFile($edited_layout_file, $code); // 컴파일 $oTemplate =& TemplateHandler::getInstance(); $layout_path = $layout_info->path; $layout_file = 'layout'; $layout_tpl = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file); Context::set('layout', 'none'); // 위젯등을 변환 $oContext =& Context::getInstance(); Context::set('layout_tpl', $layout_tpl); // 임시 파일 삭제 FileHandler::removeFile($edited_layout_file); $this->setTemplateFile('layout_preview'); }
/** * Save the signature as a file * * @param int $member_srl * @param string $signature * * @return void */ function putSignature($member_srl, $signature) { $signature = trim(removeHackTag($signature)); $signature = preg_replace('/<(\\/?)(embed|object|param)/is', '<$1$2', $signature); $check_signature = trim(str_replace(array(' ', "\n", "\r"), '', strip_tags($signature, '<img><object>'))); $path = sprintf('files/member_extra_info/signature/%s/', getNumberingPath($member_srl)); $filename = sprintf('%s%d.signature.php', $path, $member_srl); if (!$check_signature) { return FileHandler::removeFile($filename); } $buff = sprintf('<?php if(!defined("__XE__")) exit();?>%s', $signature); FileHandler::makeDir($path); FileHandler::writeFile($filename, $buff); }
/** * @brief 메뉴의 xml 파일을 만들고 위치를 return **/ function makeXmlFile($menu_srl) { // xml파일 생성시 필요한 정보가 없으면 그냥 return if (!$menu_srl) { return; } // 메뉴 정보를 구함 $args->menu_srl = $menu_srl; $output = executeQuery('menu.getMenu', $args); if (!$output->toBool() || !$output->data) { return $output; } $site_srl = (int) $output->data->site_srl; if ($site_srl) { $oModuleModel =& getModel('module'); $site_info = $oModuleModel->getSiteInfo($site_srl); $domain = $site_info->domain; } // DB에서 menu_srl에 해당하는 메뉴 아이템 목록을 listorder순으로 구해옴 $args->menu_srl = $menu_srl; $args->sort_index = 'listorder'; $output = executeQuery('menu.getMenuItems', $args); if (!$output->toBool()) { return; } // 캐시 파일의 이름을 지정 $xml_file = sprintf("./files/cache/menu/%s.xml.php", $menu_srl); $php_file = sprintf("./files/cache/menu/%s.php", $menu_srl); // 구해온 데이터가 없다면 노드데이터가 없는 xml 파일만 생성 $list = $output->data; if (!$list) { $xml_buff = "<root />"; FileHandler::writeFile($xml_file, $xml_buff); FileHandler::writeFile($php_file, '<?php if(!defined("__ZBXE__")) exit(); ?>'); return $xml_file; } // 구해온 데이터가 하나라면 array로 바꾸어줌 if (!is_array($list)) { $list = array($list); } // 루프를 돌면서 tree 구성 $list_count = count($list); for ($i = 0; $i < $list_count; $i++) { $node = $list[$i]; $menu_item_srl = $node->menu_item_srl; $parent_srl = $node->parent_srl; $tree[$parent_srl][$menu_item_srl] = $node; } // 캐시 파일의 권한과 그룹 설정을 위한 공통 헤더 $header_script = '$lang_type = Context::getLangType(); ' . '$is_logged = Context::get(\'is_logged\'); ' . '$logged_info = Context::get(\'logged_info\'); ' . '$site_srl = ' . $site_srl . ';' . '$site_admin = false;' . 'if($site_srl) { ' . '$oModuleModel = &getModel(\'module\');' . '$site_module_info = $oModuleModel->getSiteInfo($site_srl); ' . 'Context::set(\'site_module_info\',$site_module_info);' . '$grant = $oModuleModel->getGrant($site_module_info, $logged_info); ' . 'if($grant->manager ==1) $site_admin = true;' . '}' . 'if($is_logged) {' . 'if($logged_info->is_admin=="Y" || $site_admin) $is_admin = true; ' . 'else $is_admin = false; ' . '$group_srls = array_keys($logged_info->group_list); ' . '} else { ' . '$is_admin = false; ' . '$group_srsl = array(); ' . '} '; // xml 캐시 파일 생성 (xml캐시는 따로 동작하기에 session 지정을 해주어야 함) $xml_buff = sprintf('<?php ' . 'define(\'__ZBXE__\', true); ' . 'require_once(\'../../../config/config.inc.php\'); ' . '$oContext = &Context::getInstance(); ' . '$oContext->init(); ' . 'header("Content-Type: text/xml; charset=UTF-8"); ' . 'header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); ' . 'header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); ' . 'header("Cache-Control: no-store, no-cache, must-revalidate"); ' . 'header("Cache-Control: post-check=0, pre-check=0", false); ' . 'header("Pragma: no-cache"); ' . '%s' . '?>' . '<root>%s</root>', $header_script, $this->getXmlTree($tree[0], $tree, $site_srl, $domain)); // php 캐시 파일 생성 $php_output = $this->getPhpCacheCode($tree[0], $tree, $site_srl, $domain); $php_buff = sprintf('<?php ' . 'if(!defined("__ZBXE__")) exit(); ' . '%s; ' . '%s; ' . '$menu->list = array(%s); ' . '?>', $header_script, $php_output['name'], $php_output['buff']); // 파일 저장 FileHandler::writeFile($xml_file, $xml_buff); FileHandler::writeFile($php_file, $php_buff); return $xml_file; }
/** * Get information by reading conf/info.xml in the module * It uses caching to reduce time for xml parsing .. * @param string $layout * @param object $info * @param string $layoutType (P : PC, M : Mobile) * @return object info of layout */ function getLayoutInfo($layout, $info = null, $layout_type = "P") { if ($info) { $layout_title = $info->title; $layout = $info->layout; $layout_srl = $info->layout_srl; $site_srl = $info->site_srl; $vars = unserialize($info->extra_vars); if ($info->module_srl) { $layout_path = preg_replace('/([a-zA-Z0-9\\_\\.]+)(\\.html)$/', '', $info->layout_path); $xml_file = sprintf('%sskin.xml', $layout_path); } } // Get a path of the requested module. Return if not exists. if (!$layout_path) { $layout_path = $this->getLayoutPath($layout, $layout_type); } if (!is_dir($layout_path)) { return; } // Read the xml file for module skin information if (!$xml_file) { $xml_file = sprintf("%sconf/info.xml", $layout_path); } if (!file_exists($xml_file)) { $layout_info = new stdClass(); $layout_info->title = $layout; $layout_info->layout = $layout; $layout_info->path = $layout_path; $layout_info->layout_title = $layout_title; if (!$layout_info->layout_type) { $layout_info->layout_type = $layout_type; } return $layout_info; } // Include the cache file if it is valid and then return $layout_info variable if (!$layout_srl) { $cache_file = $this->getLayoutCache($layout, Context::getLangType(), $layout_type); } else { $cache_file = $this->getUserLayoutCache($layout_srl, Context::getLangType()); } if (file_exists($cache_file) && filemtime($cache_file) > filemtime($xml_file)) { include $cache_file; if ($layout_info->extra_var && $vars) { foreach ($vars as $key => $value) { if (!$layout_info->extra_var->{$key} && !$layout_info->{$key}) { $layout_info->{$key} = $value; } } } if (!$layout_info->title) { $layout_info->title = $layout; } return $layout_info; } // If no cache file exists, parse the xml and then return the variable. $oXmlParser = new XmlParser(); $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file); if ($tmp_xml_obj->layout) { $xml_obj = $tmp_xml_obj->layout; } elseif ($tmp_xml_obj->skin) { $xml_obj = $tmp_xml_obj->skin; } if (!$xml_obj) { return; } $buff = array(); $buff[] = '$layout_info = new stdClass;'; $buff[] = sprintf('$layout_info->site_srl = "%s";', $site_srl); if ($xml_obj->version && $xml_obj->attrs->version == '0.2') { // Layout title, version and other information sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d); $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); $buff[] = sprintf('$layout_info->layout = "%s";', $layout); $buff[] = sprintf('$layout_info->type = "%s";', $xml_obj->attrs->type); $buff[] = sprintf('$layout_info->path = "%s";', $layout_path); $buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body); $buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->description->body); $buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->version->body); $buff[] = sprintf('$layout_info->date = "%s";', $date); $buff[] = sprintf('$layout_info->homepage = "%s";', $xml_obj->link->body); $buff[] = sprintf('$layout_info->layout_srl = $layout_srl;'); $buff[] = sprintf('$layout_info->layout_title = $layout_title;'); $buff[] = sprintf('$layout_info->license = "%s";', $xml_obj->license->body); $buff[] = sprintf('$layout_info->license_link = "%s";', $xml_obj->license->attrs->link); $buff[] = sprintf('$layout_info->layout_type = "%s";', $layout_type); // Author information if (!is_array($xml_obj->author)) { $author_list[] = $xml_obj->author; } else { $author_list = $xml_obj->author; } $buff[] = '$layout_info->author = array();'; for ($i = 0, $c = count($author_list); $i < $c; $i++) { $buff[] = sprintf('$layout_info->author[%d] = new stdClass;', $i); $buff[] = sprintf('$layout_info->author[%d]->name = "%s";', $i, $author_list[$i]->name->body); $buff[] = sprintf('$layout_info->author[%d]->email_address = "%s";', $i, $author_list[$i]->attrs->email_address); $buff[] = sprintf('$layout_info->author[%d]->homepage = "%s";', $i, $author_list[$i]->attrs->link); } // Extra vars (user defined variables to use in a template) $extra_var_groups = $xml_obj->extra_vars->group; if (!$extra_var_groups) { $extra_var_groups = $xml_obj->extra_vars; } if (!is_array($extra_var_groups)) { $extra_var_groups = array($extra_var_groups); } $buff[] = '$layout_info->extra_var = new stdClass;'; $extra_var_count = 0; foreach ($extra_var_groups as $group) { $extra_vars = $group->var; if ($extra_vars) { if (!is_array($extra_vars)) { $extra_vars = array($extra_vars); } $count = count($extra_vars); $extra_var_count += $count; for ($i = 0; $i < $count; $i++) { unset($var, $options); $var = $extra_vars[$i]; $name = $var->attrs->name; $buff[] = sprintf('$layout_info->extra_var->%s = new stdClass;', $name); $buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body); $buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body); $buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type); $buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name); $buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"', '\\"', $var->description->body)); $options = $var->options; if (!$options) { continue; } if (!is_array($options)) { $options = array($options); } $buff[] = sprintf('$layout_info->extra_var->%s->options = array();', $var->attrs->name); $options_count = count($options); $thumbnail_exist = false; for ($j = 0; $j < $options_count; $j++) { $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"] = new stdClass;', $var->attrs->name, $options[$j]->attrs->value); $thumbnail = $options[$j]->attrs->src; if ($thumbnail) { $thumbnail = $layout_path . $thumbnail; if (file_exists($thumbnail)) { $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->thumbnail = "%s";', $var->attrs->name, $options[$j]->attrs->value, $thumbnail); if (!$thumbnail_exist) { $buff[] = sprintf('$layout_info->extra_var->%s->thumbnail_exist = true;', $var->attrs->name); $thumbnail_exist = true; } } } $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->attrs->value, $options[$j]->title->body); } } } } $buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count); // Menu if ($xml_obj->menus->menu) { $menus = $xml_obj->menus->menu; if (!is_array($menus)) { $menus = array($menus); } $menu_count = count($menus); $buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count); $buff[] = '$layout_info->menu = new stdClass;'; for ($i = 0; $i < $menu_count; $i++) { $name = $menus[$i]->attrs->name; if ($menus[$i]->attrs->default == "true") { $buff[] = sprintf('$layout_info->default_menu = "%s";', $name); } $buff[] = sprintf('$layout_info->menu->%s = new stdClass;', $name); $buff[] = sprintf('$layout_info->menu->%s->name = "%s";', $name, $menus[$i]->attrs->name); $buff[] = sprintf('$layout_info->menu->%s->title = "%s";', $name, $menus[$i]->title->body); $buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";', $name, $menus[$i]->attrs->maxdepth); $buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name); $buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";', $name, $name); $buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";', $name, $name); } } } else { // Layout title, version and other information sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d); $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d); $buff[] = sprintf('$layout_info->layout = "%s";', $layout); $buff[] = sprintf('$layout_info->path = "%s";', $layout_path); $buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body); $buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->author->description->body); $buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->attrs->version); $buff[] = sprintf('$layout_info->date = "%s";', $date); $buff[] = sprintf('$layout_info->layout_srl = $layout_srl;'); $buff[] = sprintf('$layout_info->layout_title = $layout_title;'); // Author information $buff[] = sprintf('$layout_info->author[0]->name = "%s";', $xml_obj->author->name->body); $buff[] = sprintf('$layout_info->author[0]->email_address = "%s";', $xml_obj->author->attrs->email_address); $buff[] = sprintf('$layout_info->author[0]->homepage = "%s";', $xml_obj->author->attrs->link); // Extra vars (user defined variables to use in a template) $extra_var_groups = $xml_obj->extra_vars->group; if (!$extra_var_groups) { $extra_var_groups = $xml_obj->extra_vars; } if (!is_array($extra_var_groups)) { $extra_var_groups = array($extra_var_groups); } foreach ($extra_var_groups as $group) { $extra_vars = $group->var; if ($extra_vars) { if (!is_array($extra_vars)) { $extra_vars = array($extra_vars); } $extra_var_count = count($extra_vars); $buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count); for ($i = 0; $i < $extra_var_count; $i++) { unset($var, $options); $var = $extra_vars[$i]; $name = $var->attrs->name; $buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body); $buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body); $buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type); $buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name); $buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"', '\\"', $var->description->body)); $options = $var->options; if (!$options) { continue; } if (!is_array($options)) { $options = array($options); } $options_count = count($options); for ($j = 0; $j < $options_count; $j++) { $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->value->body, $options[$j]->title->body); } } } } // Menu if ($xml_obj->menus->menu) { $menus = $xml_obj->menus->menu; if (!is_array($menus)) { $menus = array($menus); } $menu_count = count($menus); $buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count); for ($i = 0; $i < $menu_count; $i++) { $name = $menus[$i]->attrs->name; if ($menus[$i]->attrs->default == "true") { $buff[] = sprintf('$layout_info->default_menu = "%s";', $name); } $buff[] = sprintf('$layout_info->menu->%s->name = "%s";', $name, $name); $buff[] = sprintf('$layout_info->menu->%s->title = "%s";', $name, $menus[$i]->title->body); $buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";', $name, $menus[$i]->maxdepth->body); $buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name); $buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";', $name, $name); $buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";', $name, $name); } } } // header_script $oModuleModel = getModel('module'); $layout_config = $oModuleModel->getModulePartConfig('layout', $layout_srl); $header_script = trim($layout_config->header_script); if ($header_script) { $buff[] = sprintf(' $layout_info->header_script = "%s"; ', str_replace(array('$', '"'), array('\\$', '\\"'), $header_script)); } FileHandler::writeFile($cache_file, '<?php if(!defined("__XE__")) exit(); ' . join(PHP_EOL, $buff)); if (FileHandler::exists($cache_file)) { include $cache_file; } if (!$layout_info->title) { $layout_info->title = $layout; } return $layout_info; }
function getThumbnail($width = 80, $height = 0, $thumbnail_type = '') { // Return false if the document doesn't exist if (!$this->document_srl) { return; } if ($this->isSecret() && !$this->isGranted()) { return; } // If not specify its height, create a square if (!$height) { $height = $width; } // Return false if neither attachement nor image files in the document if (!$this->get('uploaded_count') && !preg_match("!<img!is", $this->get('content'))) { return; } // Get thumbnai_type information from document module's configuration if (!in_array($thumbnail_type, array('crop', 'ratio'))) { $config = $GLOBALS['__document_config__']; if (!$config) { $oDocumentModel = getModel('document'); $config = $oDocumentModel->getDocumentConfig(); $GLOBALS['__document_config__'] = $config; } $thumbnail_type = $config->thumbnail_type; } // Define thumbnail information $thumbnail_path = sprintf('files/thumbnails/%s', getNumberingPath($this->document_srl, 3)); $thumbnail_file = sprintf('%s%dx%d.%s.jpg', $thumbnail_path, $width, $height, $thumbnail_type); $thumbnail_url = Context::getRequestUri() . $thumbnail_file; // Return false if thumbnail file exists and its size is 0. Otherwise, return its path if (file_exists($thumbnail_file)) { if (filesize($thumbnail_file) < 1) { return false; } else { return $thumbnail_url; } } // Target File $source_file = null; $is_tmp_file = false; // Find an iamge file among attached files if exists if ($this->hasUploadedFiles()) { $file_list = $this->getUploadedFiles(); $first_image = null; foreach ($file_list as $file) { if ($file->direct_download !== 'Y') { continue; } if ($file->cover_image === 'Y' && file_exists($file->uploaded_filename)) { $source_file = $file->uploaded_filename; break; } if ($first_image) { continue; } if (preg_match("/\\.(jpe?g|png|gif|bmp)\$/i", $file->source_filename)) { if (file_exists($file->uploaded_filename)) { $first_image = $file->uploaded_filename; } } } if (!$source_file && $first_image) { $source_file = $first_image; } } // If not exists, file an image file from the content if (!$source_file) { $content = $this->get('content'); $target_src = null; preg_match_all("!src=(\"|')([^\"' ]*?)(\"|')!is", $content, $matches, PREG_SET_ORDER); $cnt = count($matches); for ($i = 0; $i < $cnt; $i++) { $target_src = trim($matches[$i][2]); if (!preg_match("/\\.(jpg|png|jpeg|gif|bmp)\$/i", $target_src)) { continue; } if (preg_match('/\\/(common|modules|widgets|addons|layouts)\\//i', $target_src)) { continue; } else { if (!preg_match('/^(http|https):\\/\\//i', $target_src)) { $target_src = Context::getRequestUri() . $target_src; } $tmp_file = sprintf('./files/cache/tmp/%d', md5(rand(111111, 999999) . $this->document_srl)); if (!is_dir('./files/cache/tmp')) { FileHandler::makeDir('./files/cache/tmp'); } FileHandler::getRemoteFile($target_src, $tmp_file); if (!file_exists($tmp_file)) { continue; } else { list($_w, $_h, $_t, $_a) = @getimagesize($tmp_file); if ($_w < $width || $_h < $height) { continue; } $source_file = $tmp_file; $is_tmp_file = true; break; } } } } if ($source_file) { $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); } if ($is_tmp_file) { FileHandler::removeFile($source_file); } // Return its path if a thumbnail is successfully genetated if ($output) { return $thumbnail_url; } else { FileHandler::writeFile($thumbnail_file, '', 'w'); } return; }
/** * Save the category in a cache file * @param int $module_srl * @return string */ function makeCategoryFile($module_srl) { // Return if there is no information you need for creating a cache file if (!$module_srl) { return false; } // Get module information (to obtain mid) $oModuleModel = getModel('module'); $columnList = array('module_srl', 'mid', 'site_srl'); $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList); $mid = $module_info->mid; if (!is_dir('./files/cache/document_category')) { FileHandler::makeDir('./files/cache/document_category'); } // Cache file's name $xml_file = sprintf("./files/cache/document_category/%s.xml.php", $module_srl); $php_file = sprintf("./files/cache/document_category/%s.php", $module_srl); // Get a category list $args = new stdClass(); $args->module_srl = $module_srl; $args->sort_index = 'list_order'; $output = executeQueryArray('document.getCategoryList', $args); $category_list = $output->data; if (!is_array($category_list)) { $category_list = array($category_list); } $category_count = count($category_list); for ($i = 0; $i < $category_count; $i++) { $category_srl = $category_list[$i]->category_srl; if (!preg_match('/^[0-9,]+$/', $category_list[$i]->group_srls)) { $category_list[$i]->group_srls = ''; } $list[$category_srl] = $category_list[$i]; } // Create the xml file without node data if no data is obtained if (!$list) { $xml_buff = "<root />"; FileHandler::writeFile($xml_file, $xml_buff); FileHandler::writeFile($php_file, '<?php if(!defined("__XE__")) exit(); ?>'); return $xml_file; } // Change to an array if only a single data is obtained if (!is_array($list)) { $list = array($list); } // Create a tree for loop foreach ($list as $category_srl => $node) { $node->mid = $mid; $parent_srl = (int) $node->parent_srl; $tree[$parent_srl][$category_srl] = $node; } // A common header to set permissions and groups of the cache file $header_script = '$lang_type = Context::getLangType(); ' . '$is_logged = Context::get(\'is_logged\'); ' . '$logged_info = Context::get(\'logged_info\'); ' . 'if($is_logged) {' . 'if($logged_info->is_admin=="Y") $is_admin = true; ' . 'else $is_admin = false; ' . '$group_srls = array_keys($logged_info->group_list); ' . '} else { ' . '$is_admin = false; ' . '$group_srsl = array(); ' . '} ' . "\n"; // Create the xml cache file (a separate session is needed for xml cache) $xml_header_buff = ''; $xml_body_buff = $this->getXmlTree($tree[0], $tree, $module_info->site_srl, $xml_header_buff); $xml_buff = sprintf('<?php ' . 'define(\'__XE__\', true); ' . 'require_once(\'' . FileHandler::getRealPath('./config/config.inc.php') . '\'); ' . '$oContext = &Context::getInstance(); ' . '$oContext->init(); ' . 'header("Content-Type: text/xml; charset=UTF-8"); ' . 'header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); ' . 'header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); ' . 'header("Cache-Control: no-store, no-cache, must-revalidate"); ' . 'header("Cache-Control: post-check=0, pre-check=0", false); ' . 'header("Pragma: no-cache"); ' . '%s' . '%s ' . '$oContext->close();' . '?>' . '<root>%s</root>', $header_script, $xml_header_buff, $xml_body_buff); // Create php cache file $php_header_buff = '$_titles = array();'; $php_header_buff .= '$_descriptions = array();'; $php_output = $this->getPhpCacheCode($tree[0], $tree, $module_info->site_srl, $php_header_buff); $php_buff = sprintf('<?php ' . 'if(!defined("__XE__")) exit(); ' . '%s' . '%s' . '$menu = new stdClass;' . '$menu->list = array(%s); ', $header_script, $php_header_buff, $php_output['buff']); // Save File FileHandler::writeFile($xml_file, $xml_buff); FileHandler::writeFile($php_file, $php_buff); return $xml_file; }
/** * Delete if action is registerd to be encrypted by SSL. * * @param string $action act name * @return void */ public static function subtractSSLAction($action) { if (self::isExistsSSLAction($action)) { $sslActionCacheString = sprintf('$sslActions[\'%s\'] = 1;', $action); $buff = FileHandler::readFile(self::$_instance->sslActionCacheFile); $buff = str_replace($sslActionCacheString, '', $buff); FileHandler::writeFile(self::$_instance->sslActionCacheFile, $buff); } }
/** * @brief Supported languages (was procInstallAdminSaveLangSelected) **/ function saveLangSelected($selected_lang) { $langs = $selected_lang; $lang_supported = Context::loadLangSupported(); $buff = null; for ($i = 0; $i < count($langs); $i++) { $buff .= sprintf("%s,%s\n", $langs[$i], $lang_supported[$langs[$i]]); } FileHandler::writeFile(_XE_PATH_ . 'files/config/lang_selected.info', trim($buff)); //$this->setMessage('success_updated'); }