public function load($template_string = false, $parse_includes = true) { $contents = ''; if ($template_string !== false) { $contents = $this->_strip_comments($template_string); $this->cache[$this->template] = $contents; $this->blocks = array(); } else { // check if template is cached if (isset($this->cache[$this->template])) { // use cached copy $contents = $this->cache[$this->template]; } else { // read and cache PerchUtil::invalidate_opcache($this->file); if (file_exists($this->file)) { # PerchUtil::debug('Opening template file: '.$this->file, 'template'); $contents = file_get_contents($this->file); $contents = $this->_strip_comments($contents); $this->cache[$this->template] = $contents; $this->blocks = array(); } } } if ($parse_includes) { if (strpos($contents, 'perch:template')) { $s = '/<perch:template[^>]*path="([^"]*)"[^>]*>/'; $count = preg_match_all($s, $contents, $matches, PREG_SET_ORDER); $out = ''; if ($count > 0) { foreach ($matches as $match) { $file = PERCH_TEMPLATE_PATH . DIRECTORY_SEPARATOR . $match[1]; if (!file_exists($file)) { $file = $this->file_path . DIRECTORY_SEPARATOR . $match[1]; } if (file_exists($file)) { $subtemplate = file_get_contents($file); $subtemplate = $this->_strip_comments($subtemplate); // rescope? if ($this->namespace != 'content' && strpos($match[0], 'rescope=')) { PerchUtil::debug('Rescoping to perch:' . $this->namespace); $subtemplate = str_replace('<perch:content ', '<perch:' . $this->namespace . ' ', $subtemplate); } $contents = str_replace($match[0], $subtemplate, $contents); PerchUtil::debug('Using sub-template: ' . str_replace(PERCH_PATH, '', $file), 'template'); } else { PerchUtil::debug('Requested sub-template not found: ' . $file, 'template-error'); } } $this->cache[$this->template] = $contents; $this->blocks = array(); } } } return $contents; }
} else { define('PERCH_RUNWAY', false); } if (!defined('PERCH_RUNWAY_ROUTED')) { define('PERCH_RUNWAY_ROUTED', false); } // Essentials used on every request - no point autoloading include PERCH_CORE . '/lib/PerchDB.class.php'; include PERCH_CORE . '/lib/PerchDB_MySQL.class.php'; include PERCH_CORE . '/lib/PerchUtil.class.php'; include PERCH_CORE . '/lib/Perch.class.php'; include PERCH_CORE . '/lib/PerchFactory.class.php'; include PERCH_CORE . '/lib/PerchBase.class.php'; include PERCH_CORE . '/lib/PerchSystem.class.php'; include PERCH_CORE . '/lib/PerchTemplate.class.php'; include PERCH_CORE . '/lib/PerchFieldType.class.php'; include PERCH_CORE . '/lib/PerchFieldTypes.class.php'; include PERCH_CORE . '/lib/PerchXMLTag.class.php'; include PERCH_CORE . '/lib/PerchResourceBuckets.class.php'; include PERCH_CORE . '/lib/PerchResourceBucket.class.php'; if (PERCH_RUNWAY) { include PERCH_CORE . '/runway/runtime.php'; } if (!defined('PERCH_SECURITY_HEADERS') || PERCH_SECURITY_HEADERS === true) { PerchUtil::set_security_headers(); } if (!PERCH_RUNWAY_ROUTED && isset($_SERVER['SCRIPT_FILENAME'])) { if ($_SERVER['SCRIPT_FILENAME'] != '') { PerchUtil::invalidate_opcache($_SERVER['SCRIPT_FILENAME']); } }
if ($Form->posted() && $Form->validate()) { $postvars = array('userGivenName', 'userFamilyName', 'userEmail', 'userUsername', 'userPassword'); $user = $Form->receive($postvars); PerchSession::set('user', $user); $postvars = array('loginpath', 'db_server', 'db_database', 'db_username', 'db_password', 'licenseKey', 'tz'); $conf = $Form->receive($postvars); if (!isset($conf['db_password'])) { $conf['db_password'] = ''; } $conf['loginpath'] = rtrim($conf['loginpath'], '/'); $config_file = file_get_contents('config.sample.php'); $config_file = preg_replace_callback('/\\$(\\w+)/', "substitute_vars", $config_file); $config_file_path = PerchUtil::file_path(realpath('../config') . '/config.php'); if (is_writable($config_file_path)) { file_put_contents($config_file_path, $config_file); PerchUtil::invalidate_opcache($config_file_path, 10000); $test_contents = file_get_contents($config_file_path); if ($test_contents == $config_file) { PerchUtil::redirect('index.php?install=1&auto=1'); } } $mode = 'configfile'; } function substitute_vars($matches) { global $user, $conf; if (isset($user[$matches[1]])) { return addslashes($user[$matches[1]]); } if (isset($conf[$matches[1]])) { return $conf[$matches[1]];