/** * Compiles code for the {radinclude} tag * * @param array $args array with attributes from parser * @param object $compiler compiler object * @param array $parameter array with compilation parameter * @throws rad_exception * @return string compiled code */ public function compile($args, $compiler, $parameter) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); if (!isset($_attr['module'])) { throw new rad_exception("radinclude: missing 'module' parameter"); } if (!isset($_attr['file'])) { throw new rad_exception("radinclude: missing 'file' parameter"); } $modulename = trim($_attr['module'], '"\''); //remove beginning and end quotes $filename = trim($_attr['file'], '"\''); if (!preg_match('/^[a-z][a-z0-9]{2,31}$/i', $modulename)) { throw new rad_exception("radinclude: 'module' should only use a-zA-Z0-9 characters and be from 2 to 31 long"); } if (!preg_match('/^[a-z0-9][-_.a-z0-9]*(?:\\/[a-z0-9][-_.a-z0-9]*)*\\.tpl$/i', $filename)) { throw new rad_exception("radinclude: 'file' should only consists of a-zA-Z0-9-_. and \\ symbols"); } if (!($filename = rad_themer::getFilePath(null, 'templates', $modulename, $filename))) { throw new rad_exception("Template {$filename} not found in module {$modulename}"); } $this->replaceFilename($filename, $args); //relative to module filename -> to absolute path return parent::compile($args, $compiler, $parameter); }
/** * Gets the XML-file name for module and component * @param string $module * @param string $fn * @return string - Full file name */ private function _getFN($module, $fn, $useTheme = false, $checkExists = false) { $fn .= '.xml'; if ($checkExists && $useTheme) { return rad_themer::getFilePath(null, 'set', $module, $fn); } //Use only default theme $file = COMPONENTSPATH . $module . DS . 'set' . DS . $fn; if (!$checkExists || file_exists($file)) { return $file; } return null; }
function __construct() { if ($this->request('t')) { if (rad_themer::themeExists($this->request('t'))) { rad_session::setVar('theme', $this->request('t')); } } else { rad_session::setVar('theme', $this->config('theme.default')); } if (isset($_SERVER['HTTP_REFERER'])) { $this->redirect($_SERVER['HTTP_REFERER']); } else { $this->redirect($this->makeURL('alias=' . $this->config('defaultAlias'))); } }
function _autoload($class_name) { if (trim($class_name) == '') { return false; } if (class_exists($class_name)) { return true; } $classParts = explode('_', $class_name); if (count($classParts) < 2) { return false; } switch ($classType = array_shift($classParts)) { case 'rad': $file = LIBPATH . 'class.' . implode('_', $classParts) . '.php'; break; case 'interface': $file = LIBPATH . 'interfaces' . DS . 'interface.' . implode('_', $classParts) . '.php'; break; case 'rpl': $file = LIBPATH . 'ext/' . strtolower($class_name) . '.php'; break; case 'struct': case 'model': case 'controller': case 'class': $plural = $classType == 'class' ? 'classes' : $classType . 's'; $component = array_shift($classParts); $className = implode('_', $classParts); $file = rad_themer::getFilePath(null, $plural, $component, $className . '.php'); break; default: return; } if (!empty($file)) { @(include_once $file); if (class_exists($class_name, false)) { return true; } throw new RuntimeException("Could not find the class '{$class_name}' in {$file}!", 11348); } }
errorMsg('Module name is incorrect!'); } if (empty($filename)) { errorMsg('File name is not set!'); } if (!preg_match('~^[a-zA-Z0-9][-_.a-zA-Z0-9]*(?:/[a-zA-Z0-9][-_.a-zA-Z0-9]*)*\\.(?:js|css)$~i', $filename)) { errorMsg('File name is incorrect!'); } $theme_name = rad_themer::getCurrentTheme(); $cachedFile = $config['rootPath'] . 'cache' . DS . $type . DS . $theme_name . DS . $module . DS . $filename; $cachedPath = dirname($cachedFile); if (!recursive_mkdir($cachedPath, 0777)) { errorMsg('Can not create dir! Path: {$cachedPath}'); } if (!file_exists($cachedFile) || time() - filemtime($cachedFile) >= (int) $config['cache.power.time']) { $originalFile = rad_themer::getFilePath($theme_name, 'jscss', $module, $filename); if (!$originalFile) { errorMsg('File does not exist!'); } try { rad_jscss::copyToCache($originalFile, $cachedFile); } catch (Exception $e) { errorMsg("Could not copy file {$originalFile} to {$cachedFile}"); } } if (!@readfile($cachedFile)) { errorMsg("Error reading {$cachedFile}"); } function errorMsg($msg = null) { header('HTTP/1.0 404 Not Found');
private static function checkTheme() { if (empty(self::$themeName)) { self::$themeName = rad_themer::getCurrentTheme(); } return self::$themeName; }
protected static function parseIncludes(&$includes) { self::$_includes = array(); foreach ($includes as $id) { self::$_includes[$id->inc_name] = rad_themer::getFilePath(null, 'templates', $id->m_name, $id->inc_filename); } }
public static function getLinkToImage($module, $file, $preset) { if (empty($preset)) { //TODO: maybe it'd be better to set "original" preset by default? throw new RuntimeException('"Preset" parameter is required in {url type="image"} TAG'); } $fnameOriginal = rad_themer::getFilePath(null, 'img', $module, $file); if (!$fnameOriginal) { throw new RuntimeException("File {$file} not found in module {$module} for {url type='image'}"); } $theme = rad_themer::getCurrentTheme(); $tail = "img/{$theme}/{$module}/{$preset}/{$file}"; $fnameCached = CACHEPATH . fixPath($tail); self::renewCache($fnameOriginal, $fnameCached, $preset); return SITE_URL . 'cache/' . $tail; }
/** * Assign theme folders * */ function assignThemes() { $this->setVar('theme_default', rad_config::getParam('theme.default')); $this->setVar('themes', rad_themer::getThemes()); $this->setVar('curr_theme', call_user_func(array(rad_config::getParam('loader_class'), 'getCurrentTheme'))); }
/** * Function that is called to show all variables and all the page! */ public static function show() { $o = rad_rsmarty::getSmartyObject(); //TODO: optimize memory if (count(self::$_html)) { foreach (self::$_html as $key => $value) { $o->assign($key, $value); } } $o->assign('_CURR_LANG_', rad_lang::getCurrentLanguage()); if (isset(self::$sendedParams[self::$_alias->filename])) { foreach (self::$sendedParams[self::$_alias->filename] as $pkey => $pval) { $o->assign($pkey, $pval); } } $file = rad_themer::getFilePath(null, 'templates', 'core', 'maintemplates' . DS . self::$_alias->filename . '.tpl'); rad_instances::setCurrentTemplate($file, true); $o->display($file); }
/** * Assign theme folders * */ function assignThemes() { $themes = rad_themer::getThemes(); $this->setVar('themes', $themes); if (!empty($themes)) { $table = new model_core_table('themes'); $alias_id = (int) $this->request('id'); $table->setState('where', 'theme_aliasid=' . $alias_id); $themes_rules = $table->getItems(); $this->setVar('themes_rules', $themes_rules); } }
/** * Assign theme folders */ function assignThemes() { $this->setVar('themes', rad_themer::getThemes()); }