示例#1
0
 /**
  * compiles specified tpl file and execution result in Context into resultant content
  * @param string $tpl_path path of the directory containing target template file
  * @param string $tpl_filename target template file's name
  * @param string $tpl_file if specified use it as template file's full path
  * @return string Returns compiled result in case of success, NULL otherwise
  */
 public function compile($tpl_path, $tpl_filename, $tpl_file = '')
 {
     // store the starting time for debug information
     $start = microtime(true);
     // initiation
     $this->init($tpl_path, $tpl_filename, $tpl_file);
     // if target file does not exist exit
     if (!$this->file || !file_exists($this->file)) {
         $error_message = "Template not found: {$tpl_path}{$tpl_filename}" . ($tpl_file ? " ({$tpl_file})" : '');
         trigger_error($error_message, \E_USER_WARNING);
         return escape($error_message);
     }
     // for backward compatibility
     if (is_null(self::$rootTpl)) {
         self::$rootTpl = $this->file;
     }
     $latest_mtime = max(filemtime($this->file), $this->handler_mtime);
     // make compiled file
     if (!file_exists($this->compiled_file) || filemtime($this->compiled_file) < $latest_mtime) {
         $buff = $this->parse();
         if (Rhymix\Framework\Storage::write($this->compiled_file, $buff) === false) {
             $tmpfilename = tempnam(sys_get_temp_dir(), 'rx-compiled');
             if ($tmpfilename === false || Rhymix\Framework\Storage::write($tmpfilename, $buff) === false) {
                 return 'Fatal Error : Cannot create temporary file. Please check permissions.';
             }
             $this->compiled_file = $tmpfilename;
         }
     }
     Rhymix\Framework\Debug::addFilenameAlias($this->file, $this->compiled_file);
     $output = $this->_fetch($this->compiled_file);
     // delete tmpfile
     if (isset($tmpfilename)) {
         Rhymix\Framework\Storage::delete($tmpfilename);
     }
     if ($__templatehandler_root_tpl == $this->file) {
         $__templatehandler_root_tpl = null;
     }
     // store the ending time for debug information
     $GLOBALS['__template_elapsed__'] += microtime(true) - $start;
     return $output;
 }
示例#2
0
 /**
  * Returns compiled javascript file path. The path begins from XE root directory.
  * @return string Compiled JavaScript file path
  */
 function getJsPath()
 {
     if (!$this->_cache_dir) {
         return FALSE;
     }
     $dir = $this->_cache_dir . '/ruleset';
     if (!is_dir($dir) && !mkdir($dir)) {
         return FALSE;
     }
     if (!$this->_xml_path) {
         return FALSE;
     }
     // current language
     $lang_type = class_exists('Context', false) ? Context::getLangType() : 'en';
     // check the file
     $filepath = $dir . '/' . md5($this->_version . ' ' . $this->_xml_path) . ".{$lang_type}.js";
     if (is_readable($filepath) && filemtime($filepath) > filemtime($this->_xml_path)) {
         return $filepath;
     }
     $content = $this->_compile2js();
     if ($content === FALSE) {
         return FALSE;
     }
     Rhymix\Framework\Storage::write($filepath, $content);
     return $filepath;
 }
示例#3
0
 /**
  * Write $buff into the specified file
  *
  * @param string $filename Path of target file
  * @param string $buff Content to be written
  * @param string $mode a(append) / w(write)
  * @return void
  */
 public static function writeFile($filename, $buff, $mode = "w")
 {
     return Rhymix\Framework\Storage::write(self::getRealPath($filename), $buff, $mode);
 }
示例#4
0
 /**
  * @brief Save the file of user-defined language code
  */
 function makeCacheDefinedLangCode($site_srl = 0)
 {
     $args = new stdClass();
     // Get the language file of the current site
     if (!$site_srl) {
         $site_module_info = Context::get('site_module_info');
         $args->site_srl = (int) $site_module_info->site_srl;
     } else {
         $args->site_srl = $site_srl;
     }
     $output = executeQueryArray('module.getLang', $args);
     if (!$output->toBool() || !$output->data) {
         return;
     }
     // Set the cache directory
     $cache_path = _XE_PATH_ . 'files/cache/lang_defined/';
     FileHandler::makeDir($cache_path);
     $langMap = array();
     foreach ($output->data as $val) {
         $langMap[$val->lang_code][$val->name] = $val->value;
     }
     $lang_supported = Context::loadLangSelected();
     $defaultLang = config('locale.default_lang');
     if (!is_array($langMap[$defaultLang])) {
         $langMap[$defaultLang] = array();
     }
     foreach ($lang_supported as $langCode => $langName) {
         if (!is_array($langMap[$langCode])) {
             $langMap[$langCode] = array();
         }
         $langMap[$langCode] += $langMap[$defaultLang];
         foreach ($lang_supported as $targetLangCode => $targetLangName) {
             if ($langCode == $targetLangCode || $langCode == $defaultLang) {
                 continue;
             }
             if (!is_array($langMap[$targetLangCode])) {
                 $langMap[$targetLangCode] = array();
             }
             $langMap[$langCode] += $langMap[$targetLangCode];
         }
         $buff = array("<?php if(!defined('__XE__')) exit();");
         foreach ($langMap[$langCode] as $code => $value) {
             $buff[] = sprintf('$lang[\'%s\'] = \'%s\';', $code, addcslashes($value, "'"));
         }
         if (!Rhymix\Framework\Storage::write(sprintf('%s/%d.%s.php', $cache_path, $args->site_srl, $langCode), join(PHP_EOL, $buff))) {
             return;
         }
     }
 }
示例#5
0
 /**
  * @brief Recalculate points based on the list/comment/attachment and registration information. Granted only once a first-time login score.
  */
 function procPointAdminReCal()
 {
     @set_time_limit(0);
     // Get per-module points information
     $oModuleModel = getModel('module');
     $config = $oModuleModel->getModuleConfig('point');
     $module_config = $oModuleModel->getModulePartConfigs('point');
     // A variable to store member's points
     $member = array();
     // Get member infomation
     $output = executeQueryArray('point.getMemberCount');
     if (!$output->toBool()) {
         return $output;
     }
     if ($output->data) {
         foreach ($output->data as $key => $val) {
             if (!$val->member_srl) {
                 continue;
             }
             $member[$val->member_srl] = 0;
         }
     }
     // Get post information
     $output = executeQueryArray('point.getDocumentPoint');
     if (!$output->toBool()) {
         return $output;
     }
     if ($output->data) {
         foreach ($output->data as $key => $val) {
             if ($module_config[$val->module_srl]['insert_document']) {
                 $insert_point = $module_config[$val->module_srl]['insert_document'];
             } else {
                 $insert_point = $config->insert_document;
             }
             if (!$val->member_srl) {
                 continue;
             }
             $point = $insert_point * $val->count;
             $member[$val->member_srl] += $point;
         }
     }
     $output = null;
     // Get comments information
     $output = executeQueryArray('point.getCommentPoint');
     if (!$output->toBool()) {
         return $output;
     }
     if ($output->data) {
         foreach ($output->data as $key => $val) {
             if ($module_config[$val->module_srl]['insert_comment']) {
                 $insert_point = $module_config[$val->module_srl]['insert_comment'];
             } else {
                 $insert_point = $config->insert_comment;
             }
             if (!$val->member_srl) {
                 continue;
             }
             $point = $insert_point * $val->count;
             $member[$val->member_srl] += $point;
         }
     }
     $output = null;
     // Get the attached files' information
     $output = executeQueryArray('point.getFilePoint');
     if (!$output->toBool()) {
         return $output;
     }
     if ($output->data) {
         foreach ($output->data as $key => $val) {
             if ($module_config[$val->module_srl]['upload_file']) {
                 $insert_point = $module_config[$val->module_srl]['upload_file'];
             } else {
                 $insert_point = $config->upload_file;
             }
             if (!$val->member_srl) {
                 continue;
             }
             $point = $insert_point * $val->count;
             $member[$val->member_srl] += $point;
         }
     }
     $output = null;
     // Set all members' points to 0
     $output = executeQuery("point.initMemberPoint");
     if (!$output->toBool()) {
         return $output;
     }
     // Save the file temporarily
     $str = '';
     foreach ($member as $key => $val) {
         $val += (int) $config->signup_point;
         $str .= $key . ',' . $val . "\r\n";
     }
     Rhymix\Framework\Storage::write(\RX_BASEDIR . 'files/cache/pointRecal.txt', $str);
     $this->add('total', count($member));
     $this->add('position', 0);
     $this->setMessage(sprintf(lang('point_recal_message'), 0, $this->get('total')));
 }
 /**
  * Get javascript file list
  *
  * @param string $type Type of javascript. head, body
  * @param bool $finalize (optional)
  * @return array Returns javascript file list. Array contains file, targetie.
  */
 public function getJsFileList($type = 'head', $finalize = false)
 {
     if ($type == 'head') {
         $map =& $this->jsHeadMap;
         $mapIndex =& $this->jsHeadMapIndex;
     } else {
         $map =& $this->jsBodyMap;
         $mapIndex =& $this->jsBodyMapIndex;
     }
     $minify = self::$minify !== null ? self::$minify : (config('view.minify_scripts') ?: 'common');
     $concat = strpos(self::$concat !== null ? self::$concat : config('view.concat_scripts'), 'js') !== false;
     $this->_sortMap($map, $mapIndex);
     // Minify all scripts.
     if ($finalize) {
         foreach ($map as $indexedMap) {
             foreach ($indexedMap as $file) {
                 if (!$file->isMinified && !$file->isExternalURL && !$file->isCachedScript && ($file->isCommon && $minify !== 'none' || $minify === 'all')) {
                     $this->proc_CSS_JS($file, true);
                 }
             }
         }
     }
     // Add all files to the final result.
     $result = array();
     if ($concat && $finalize && $type === 'head' && count($concat_list = $this->_concatMap($map))) {
         foreach ($concat_list as $concat_fileset) {
             if (count($concat_fileset) === 1) {
                 $file = reset($concat_fileset);
                 $url = $file->filePath . '/' . $file->fileName;
                 if (!$file->isExternalURL && is_readable($file->fileFullPath)) {
                     $url .= '?' . date('YmdHis', filemtime($file->fileFullPath));
                 }
                 $result[] = array('file' => $url, 'targetie' => $file->targetIe);
             } else {
                 $concat_files = array();
                 $concat_max_timestamp = 0;
                 foreach ($concat_fileset as $file) {
                     $concat_files[] = $file->targetIe ? array($file->fileFullPath, $file->targetIe) : $file->fileFullPath;
                     $concat_max_timestamp = max($concat_max_timestamp, filemtime($file->fileFullPath));
                 }
                 $concat_filename = self::$assetdir . '/combined/' . sha1(serialize($concat_files)) . '.js';
                 if (!file_exists(\RX_BASEDIR . $concat_filename) || filemtime(\RX_BASEDIR . $concat_filename) < $concat_max_timestamp) {
                     Rhymix\Framework\Storage::write(\RX_BASEDIR . $concat_filename, Rhymix\Framework\Formatter::concatJS($concat_files, $concat_filename));
                 }
                 $concat_filename .= '?' . date('YmdHis', filemtime(\RX_BASEDIR . $concat_filename));
                 $result[] = array('file' => \RX_BASEURL . $concat_filename, 'targetie' => '');
             }
         }
     } else {
         foreach ($map as $indexedMap) {
             foreach ($indexedMap as $file) {
                 $url = $file->filePath . '/' . $file->fileName;
                 if (!$file->isExternalURL && is_readable($file->fileFullPath)) {
                     $url .= '?' . date('YmdHis', filemtime($file->fileFullPath));
                 }
                 $result[] = array('file' => $url, 'targetie' => $file->targetIe);
             }
         }
     }
     // Enable HTTP/2 server push for JS resources.
     if ($type === 'head' && $finalize && $this->_isServerPushEnabled()) {
         foreach ($result as $resource) {
             if ($resource['file'][0] === '/' && $resource['file'][1] !== '/') {
                 header(sprintf('Link: <%s>; rel=preload; as=script', $resource['file']), false);
             }
         }
     }
     return $result;
 }