/** * Parse the include tags. * This is an extended version of the Spoon Library template compiler, to allow for the passing of * a relative path to an include, which will then automatically choose the theme path (if available) * or the module's path. * * @param string $content The content that may contain the include tags. * @return string The updated content, containing the parsed include tags. */ protected function parseIncludes($content) { // regex pattern // no unified restriction can be done on the allowed characters, // that differs from one OS to another // (see http://www.comentum.com/File-Systems-HFS-FAT-UFS.html) $pattern = '/\\{include:(("[^"]*?"|\'[^\']*?\')|[^:]*?)\\}/i'; // find matches if (preg_match_all($pattern, $content, $matches, PREG_SET_ORDER)) { // loop matches foreach ($matches as $match) { // search string $search = $match[0]; // inside a string if (in_array(substr($match[1], 0, 1), array('\'', '"'))) { // strip quotes $match[1] = substr($match[1], 1, -1); } $replace = '<?php $includes = array(); ob_start(); ?>' . $match[1] . '<?php $includes[] = str_replace(\'//\', \'/\', eval(\'return \\\'\' . str_replace(\'\\\'\', \'\\\\\\\'\', ob_get_clean()) .\'\\\';\')); ob_start(); ?>' . $this->variables['THEME_PATH'] . '/' . $match[1] . '<?php $includes[] = str_replace(\'//\', \'/\', eval(\'return \\\'\' . str_replace(\'\\\'\', \'\\\\\\\'\', ob_get_clean()) .\'\\\';\')); ob_start(); ?>' . $this->variables['FRONTEND_PATH'] . '/' . $match[1] . '<?php $includes[] = str_replace(\'//\', \'/\', eval(\'return \\\'\' . str_replace(\'\\\'\', \'\\\\\\\'\', ob_get_clean()) .\'\\\';\')); foreach($includes as $include) if(@file_exists($include) && is_file($include)) break; if($this->getForceCompile() || !file_exists($this->getCompileDirectory() .\'/\' . $this->getCompileName($include, \'' . dirname(realpath($this->template)) . '\'))) $this->compile(\'' . dirname(realpath($this->template)) . '\', $include); $return = @include $this->getCompileDirectory() .\'/\' . $this->getCompileName($include, \'' . dirname(realpath($this->template)) . '\'); if($return === false && $this->compile(\'' . dirname(realpath($this->template)) . '\', $include)) { $return = @include $this->getCompileDirectory() .\'/\' . $this->getCompileName($include, \'' . dirname(realpath($this->template)) . '\'); }' . "\n"; if (Model::getContainer()->getParameter('kernel.debug')) { $replace .= 'if($return === false) { ?>' . $match[0] . '<?php }' . "\n"; } $replace .= '?>'; // replace it $content = str_replace($search, $replace, $content); } } return $content; }
/** * Assign the labels */ private function parseLabels() { // grab the current module if (Model::getContainer()->has('url')) { $currentModule = Model::get('url')->getModule(); } elseif (isset($_GET['module']) && $_GET['module'] != '') { $currentModule = (string) $_GET['module']; } else { $currentModule = 'Core'; } $errors = Language::getErrors(); $labels = Language::getLabels(); $messages = Language::getMessages(); // set the begin state $realErrors = $errors['Core']; $realLabels = $labels['Core']; $realMessages = $messages['Core']; // loop all errors, label, messages and add them again, but prefixed with Core. So we can decide in the // template to use the Core-value instead of the one set by the module foreach ($errors['Core'] as $key => $value) { $realErrors['Core' . $key] = $value; } foreach ($labels['Core'] as $key => $value) { $realLabels['Core' . $key] = $value; } foreach ($messages['Core'] as $key => $value) { $realMessages['Core' . $key] = $value; } // are there errors for the current module? if (isset($errors[$currentModule])) { // loop the module-specific errors and reset them in the array with values we will use foreach ($errors[$currentModule] as $key => $value) { $realErrors[$key] = $value; } } // are there labels for the current module? if (isset($labels[$currentModule])) { // loop the module-specific labels and reset them in the array with values we will use foreach ($labels[$currentModule] as $key => $value) { $realLabels[$key] = $value; } } // are there messages for the current module? if (isset($messages[$currentModule])) { // loop the module-specific errors and reset them in the array with values we will use foreach ($messages[$currentModule] as $key => $value) { $realMessages[$key] = $value; } } // execute addslashes on the values for the locale, will be used in JS if ($this->addSlashes) { foreach ($realErrors as &$value) { $value = addslashes($value); } foreach ($realLabels as &$value) { $value = addslashes($value); } foreach ($realMessages as &$value) { $value = addslashes($value); } } // sort the arrays (just to make it look beautiful) ksort($realErrors); ksort($realLabels); ksort($realMessages); // assign errors $this->assignArray($realErrors, 'err'); // assign labels $this->assignArray($realLabels, 'lbl'); // assign messages $this->assignArray($realMessages, 'msg'); }
/** * Load the data for the given user * * @param int $userId The users id in the backend. * * @throws Exception */ public function loadUser($userId) { $userId = (int) $userId; // get database instance $db = Model::getContainer()->get('database'); // get user-data $userData = (array) $db->getRecord('SELECT u.id, u.email FROM users AS u WHERE u.id = ? LIMIT 1', array($userId)); // if there is no data we have to destroy this object, I know this isn't a realistic situation if (empty($userData)) { throw new Exception('The user (' . $userId . ') doesn\'t exist.'); } // set properties $this->setUserId($userData['id']); $this->setEmail($userData['email']); // get settings $settings = (array) $db->getPairs('SELECT us.name, us.value FROM users_settings AS us WHERE us.user_id = ?', array($userId)); // loop settings and store them in the object foreach ($settings as $key => $value) { $this->settings[$key] = unserialize($value); } }
/** * Assigns an option if we are in debug-mode */ private function parseDebug() { if (Model::getContainer()->getParameter('kernel.debug')) { $this->assign('debug', true); } }