/** * If the specified URL was most recently "drilled into" with a query string, append * the query to the end of the URL. If the URL already includes a query string, the * saved state is ignored. * @param string $url */ public static function SavedState($url) { $url = Typeframe::Pagemill()->data()->parseVariables(Typeframe_Attribute_Url::ConvertShortUrlToExpression($url)); if (strpos($url, '?') === false) { // Remove trailing slash if ($url > '/' && substr($url, strlen($url) - 1, 1) == '/') { $url = substr($url, 0, strlen($url) - 1); } return $url . (!empty($_SESSION['breadcrumbs'][$url]['query']) ? '?' . $_SESSION['breadcrumbs'][$url]['query'] : (!empty($_SESSION['breadcrumbs']["{$url}/"]['query']) ? '?' . $_SESSION['breadcrumbs']["{$url}/"]['query'] : '')); } return $url; }
/** * Include (evaluate) a file in the source/scripts directory. * @param string $script The relative path to the file. */ public static function IncludeScript($script) { // TODO: Get rid of these variables. They should be declared explicitly in the controller if necessary. $pm = Typeframe::Pagemill(); $db = Typeframe::Database(); include_once TYPEF_SOURCE_DIR . '/scripts' . $script; }
<?php $db = Typeframe::Database(); $pm = Typeframe::Pagemill(); Typeframe::SetPageTemplate('/admin/applications/index.html'); foreach (Typeframe::Registry()->applications() as $a) { $app = array('name' => $a->name(), 'title' => $a->title(), 'map' => $a->map()); $pm->addLoop('applications', $app); if ($a->map() == 'hard') { $pm->addLoop('applications', 'pages', array('uri' => TYPEF_WEB_DIR . $a->base())); } else { // TODO: Figure out what to do about soft-mapped pages /* foreach (Typeframe::Registry()->getApplicationPagesByName($a->name()) as $p) { $pm->addLoop('applications', 'pages', array('uri' => $p->uri())); } */ } } $pm->sortLoop('applications', 'name');
<?php $file = isset($_REQUEST['file']) ? $_REQUEST['file'] : ''; if ($file && file_exists(TYPEF_DIR . $file) && is_file(TYPEF_DIR . $file)) { header('Content-type: text/css'); $dir = dirname($file); $md5 = md5($file) . '.css'; $dst = TYPEF_DIR . '/files/cache/lessphp/' . $md5; lessc::ccompile(TYPEF_DIR . $file, $dst); $css = SimpleCss::LoadFile($dst, TYPEF_WEB_DIR . $dir); $code = $css->toString(); preg_match_all('/url\\(\\"([\\w\\W\\s\\S]*?)"\\)/', $code, $matches); if (isset($matches[1])) { foreach ($matches[1] as $url) { $url = Typeframe_Attribute_Url::ConvertShortUrlToExpression($url); $url = Typeframe::Pagemill()->data()->parseVariables($url); $code = str_replace($matches[1], $url, $code); } } echo $code; exit; } else { http_response_code(404); Typeframe::SetPageTemplate('/404.html'); Typeframe::CurrentPage()->stop(); }
public function execute($return = false) { set_error_handler(array($this, '_errorHandler')); if ($return) { ob_start(); } $backups = array(); foreach ($this->_superglobals as $key => $value) { eval('$backups[\'' . $key . '\'] = $_' . $key . ';'); // The $_SERVER superglobal gets merged instead of replaced. if ($key == 'SERVER') { eval('$value = array_merge($_SERVER, $value);'); } eval('$_' . $key . ' = $value;'); } if (isset($this->_superglobals['GET']) || isset($this->_superglobals['POST'])) { $backups['REQUEST'] = $_REQUEST; $_REQUEST = array(); $order = array('_GET', '_POST'); foreach ($order as $var) { eval('$tmp = $' . $var . ';'); foreach ($tmp as $key => $value) { $_REQUEST[$key] = $value; } } } if (!isset($backups['SESSION']) && session_id() == '' && !headers_sent()) { session_start(); } self::$_current[] = $this; $this->_initialize(); self::_Include($this->_controller, $this->_pagemill); if (isset($this->_callbacks[$this->controllerPath()])) { foreach ($this->_callbacks[$this->controllerPath()] as $callback) { call_user_func($callback); } } Typeframe::Timestamp('Scripts and controller executed'); // TODO: Process output (Pagemill template) $selectedTemplate = null; if (is_null($this->_redirectLocation)) { if (is_null($this->_template)) { $selectedTemplate = $this->_resolveTemplate($this->_getDefaultTemplate()); } else { $selectedTemplate = $this->_resolveTemplate($this->_template); } } else { $selectedTemplate = $this->_resolveTemplate('/redirect.html'); if (!$return && !requestIsAjax()) { if ($this->_redirectHeader) { header('Location: ' . $this->_redirectLocation); } if (isset($this->_redirectResponseCode) && !requestIsAjax()) { http_response_code($this->_redirectResponseCode); } } } if ($selectedTemplate) { $pm = Typeframe::Pagemill(); $pm->writeFile($selectedTemplate, false, !isset($_SERVER['SHELL'])); } array_pop(self::$_current); if ($this->_errors) { echo "\n<!--[errors]\n"; foreach ($this->_errors as $error) { echo "{$error}\n"; } echo "[/errors]-->\n"; } foreach ($backups as $key => $value) { eval('$_' . $key . ' = $value;'); } if (!isset($backups['SESSION']) && session_id() != '') { if (TYPEF_WEB_DIR != '') { session_set_cookie_params(ini_get('session.cookie_lifetime'), TYPEF_WEB_DIR); } session_write_close(); } restore_error_handler(); if ($return) { return ob_get_clean(); } }
public function execute() { static $executed = false; if (!$executed) { $executed = true; $this->_executeApplicationCode(); Typeframe::Timestamp('Controller and triggers executed'); $selectedTemplate = $this->_template; if (!$selectedTemplate && $this->_application->name()) { $pathinfo = pathinfo($this->_controller); $selectedTemplate = substr($pathinfo['dirname'], strlen(TYPEF_SOURCE_DIR . '/controllers')) . '/' . $pathinfo['filename'] . '.html'; $finalTemplate = Typeframe::FindTemplate($selectedTemplate); if (is_null($finalTemplate)) { $selectedTemplate = null; } } else { $finalTemplate = Typeframe::FindTemplate($selectedTemplate); } // $selectedTemplate tells us if a template was selected (either explicitly or automatically). // $finalTemplate tells us if the template is valid. if ($selectedTemplate) { if ($finalTemplate) { Typeframe::Timestamp('Starting page render'); if ($this->_redirectLocation) { // If there were errors sent to the browser (i.e., output has already started), don't use meta redirect //if ( (headers_sent()) || (ob_get_length()) ) { // Typeframe::Pagemill()->setVariable("time", 0); //} if (Typeframe::Pagemill()->getVariable('time') == 0 && $_SERVER['REQUEST_METHOD'] == 'POST' && !headers_sent() && !requestIsAjax()) { $_SESSION['typef_redirect_message'] = Typeframe::Pagemill()->getVariable('message'); } } $this->_executedTemplate = $finalTemplate; if ($this->_redirectHeader) { if (!headers_sent() && !requestIsAjax()) { header('Location: ' . $this->_redirectLocation, true, $this->_redirectResponseCode); } } Typeframe::Pagemill()->writeFile($finalTemplate); // TODO: Another quick and dirty hack to make JavaScript templates work. /*$pathinfo = pathinfo($selectedTemplate); switch ($pathinfo['extension']) { case 'js': $output = str_replace('<', '<', $output); $output = str_replace('>', '>', $output); $output = str_replace('&', '&', $output); } echo $output;*/ } else { trigger_error("Template {$selectedTemplate} not found"); } } } else { trigger_error("Page controller was already executed"); } if (!$this->_redirectLocation && !requestIsAjax()) { unset($_SESSION['typef_redirect_message']); } session_write_close(); }
private static function _GetStylesheetsFromElement(SimpleXMLElement $xml, array &$stylesheets) { $els = $xml->xpath('//link[@rel="stylesheet"]|//pm:include'); foreach ($els as $e) { if ($e->getName() == 'link') { // stylesheet $converted = Typeframe::Pagemill()->data()->parseVariables(Typeframe_Attribute_Url::ConvertShortUrlToExpression((string) $e['href'])); if ($converted) { $stylesheets[] = $converted; } } else { if ($e->getName() == 'include') { // include $inc = Pagemill_SimpleXmlElement::LoadFile(Typeframe_Skin::TemplatePath($e['template'])); self::_GetStylesheetsFromElement($inc, $stylesheets); } } } }
public function output(Pagemill_Data $data, Pagemill_Stream $stream, $content = null) { if (!$this->insidePlugin()) { $content = self::Cache(); $name = $this->getAttribute('name'); $type = $this->getAttribute('type'); if ($type == 'html') { // Parse short URL attributes $urled = @$content[$name]; $urled = preg_replace('/(<[^>]*? href=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); $urled = preg_replace('/(<[^>]*? src=")~\\//', '$1' . TYPEF_WEB_DIR . '/', $urled); @($content[$name] = $urled); } if ($type == 'model') { if (!empty($content[$name])) { $model = $content[$name]; if ((string) $model != '') { $model = explode(':', $model); if (class_exists($model[0])) { $record = $model[0]::Get($model[1]); $content[$name] = $record; } } } else { $content[$name] = null; } } if ($this->getAttribute('scope') == 'global') { Typeframe::Pagemill()->set($name, @$content[$name]); } else { $data->set($name, @$content[$name]); } } //$inner = $this->inner($data); if (count($this->children()) > 0) { foreach ($this->children() as $child) { $child->process($data, $stream); } } else { $output = ''; if ($this->getAttribute('noop')) { $output = ''; } else { if ($type == 'html') { $pm = new Pagemill($data); $output = $pm->writeString('<pm:codeblock elements="*" attributes="*">@{' . $name . '}@</pm:codeblock>', true); } else { if ($type == 'image') { // Only display something if something is filled in, ie: no broken images. if (@$content[$name] && is_readable(TYPEF_DIR . '/files/public/content/' . @$content[$name])) { // Allow any other attribute to transparently pass to the image. $atts = ''; foreach ($this->attributes() as $k => $v) { switch ($k) { case 'name': case 'label': case 'type': case 'src': break; default: $atts .= " {$k}=\"{$v}\""; } } $output = '<img src="' . TYPEF_WEB_DIR . '/files/public/content/' . $content[$name] . '"' . $atts . '/>'; } else { $output = ''; } } else { if ($type == 'link') { if (!$content[$name] && @$this->getAttribute('ignoreblank') == true) { return ''; } $linktitle = @$this->getAttribute('linktitle') ? $this->getAttribute('linktitle') : 'Click Here'; $linkstyle = @$this->getAttribute('linkstyle') ? $this->getAttribute('linkstyle') : ''; $output = '<a href="' . $content[$name] . '" style="' . $linkstyle . '">' . $linktitle . '</a>'; } else { if ($type == 'checkbox' || $type == 'select') { // Checkbox and select types are primarily for configurable template logic and do not have default output. $output = ''; } else { $output = $content[$name]; } } } } } $stream->puts($output); } }
<?php // Add user data to Pagemill // TODO: This trigger isn't strictly necessary anymore, since it's easy to pass get/post/session/cookie data into templates // (and as of this writing, the kernel.php trigger does so) Typeframe::Pagemill()->setVariable('loggedin', Typeframe::User()->loggedIn()); if (Typeframe::User()->loggedIn()) { Typeframe::Pagemill()->setVariable('typef_session_username', Typeframe::User()->get('username')); Typeframe::Pagemill()->setVariable('typef_session_userid', Typeframe::User()->get('userid')); Typeframe::Pagemill()->setVariable('typef_session_usergroupid', Typeframe::User()->get('usergroupid')); }