public static function writeUrl(&$db, $loc, $lastMod = null, $changeFreq = null, $priority = null, $tableName = 'sitemap') { try { $loc = trim($loc); $checksum = crc32($loc); /* get the host name from url */ preg_match('@^(?:https?:\\/\\/)?((?:www\\.)?[^\\/]+)@i', $loc, $matches); $host = $matches[1]; $row = $db->select_1('select * from sitemap where loc = %s', $loc); /* new location */ if (is_null($row)) { $db->insert('sitemap', 'checksum = \'%l\'::bigint', $checksum, 'host = %s', $host, 'loc = %s', $loc, 'last_mod = %T', $lastMod, 'change_freq = %S', $changeFreq, 'priority = %l', is_null($priority) ? 'NULL' : $priority); /* update as details have changed */ } elseif ($row->t_last_mod != $lastMod || $row->s_change_freq != $changeFreq || $row->s_priority != $priority) { $db->update_1('sitemap', 'loc = %s', $loc, 'last_mod = %T', $lastMod, 'change_freq = %S', $changeFreq, 'priority = %l', is_null($priority) ? 'NULL' : $priority); } /* nulling used variables (big sitemaps need every scrap of memory!) */ $row = null; $host = null; $checksum = null; $matches = null; } catch (Exception $e) { Atsumi::error__listen($e); } }
/** * Returns further information on how to solve the the exception * @access public * @param string $contentType The context type(html|text) * @return string Information about the exception */ public function getInstructions($contentType) { // should the below (determining the method) be the responsibility of the parser? $parserData = Atsumi::app__getParserMetaData(); $parserData = end($parserData['stack']); $this->controller = $parserData['controller']; $this->method = $parserData['method']; if ($this->method == 'methodlessRequest') { $methodArr = explode('/', $parserData['args'][0]); // TODO: This should talk back to the URI parser asking it to parse a page method. $this->method = 'page_' . $methodArr[1]; $this->args = array_slice($parserData['args'], 1); } // create string of args $argString = ''; for ($i = 0; $i < count($this->args); $i++) { $argString .= ($argString == '' ? '' : ', ') . '$arg' . strval($i + 1); } switch ($contentType) { default: case 'text/plain': return sf('--Description\\nYour choosen paser has determined that the \'%s\' method of the \'%s\' controller should be called but the method or controller cannot be found. Please make sure it exists. --Example Code to create the controller and method\\n class %s extends mvc_AbstractController { // The method to be called public function page_%s { // Don\'t forget to set your view $this->setView(\'name_of_view\'); } } --Example code to load a folder containing your controller\\n /* exmaple folders: models, views, controllers. These folders should exist in the \'classes/\' folder */ Atsumi::references(array(\'myproject\' => \'models views controllers\')); ', $this->method, $this->controller, $this->controller, $this->method); break; case 'text/html': return sf('<h4>Description</h4><p>Your choosen paser has determined that the \'<strong>%s</strong>\' method of the \'<strong>%s</strong>\' controller should be called but the method or controller cannot be found. Please make sure it exists.</p> <h4>Example Code to create the controller and method</h4> <pre class="code"> class %s extends mvc_AbstractController { // The method to be called public function %s (%s) { // Don\'t forget to set your view $this->setView(\'name_of_view\'); } } </pre> <h4>Example code to load a folder containing your controller</h4> <pre class="code"> /* exmaple folders: models, views, controllers. These folders should exist in the \'classes/\' folder */ Atsumi::references(array(\'myproject\' => \'models views controllers\')); </pre> ', $this->method, $this->controller, $this->controller, $this->method, $argString); break; } }
protected function renderBody() { pfl('<body>'); pfl('<div class="header">'); pfl('<h1><a href="%s">Atsumi Examples</a></h1>', Atsumi::app__createUri('ex_IndexController', '')); pfl('<div class="details"><strong>%s</strong> <cite>%s</cite><p>%s</p></div>', $this->get_method, $this->get_controller, $this->get_info); pfl('<br clear="both" />'); pfl('</div>'); pfl('<div class="example">'); $this->renderBodyContent(); pf('</div></body>'); }
public static function processTemplateString($templateString, $data, $supressErrors = false) { if (empty($templateString) || $templateString == '' || !$templateString) { return; } extract($data, EXTR_SKIP); ob_start(); try { eval("?>" . $templateString . '<?php '); } catch (Exception $e) { Atsumi::error__listen($e); if (!$supressErrors) { throw $e; } else { Atsumi::error__recover($e); } } return ob_get_clean(); }
function renderBodyContent() { pfl('<h1>Atsumi Examples</h1>'); pfl('<p>%s</p>', 'A collection of examples to demonstrate features of Atsumi.'); pfl('<blockquote>'); foreach ($this->get_index as $section => $exampleArr) { pfl('<h2>Examples: %s</h2>', $section); pfl('<ol>'); foreach ($exampleArr as $example) { pfl('<li>%s » <a href="%s">%s</a> <cite>%s</cite></li>', $section, Atsumi::app__createUri($example['controller'], $example['path']), $example['path'], $example['controller']); if ($example['info']) { pfl('<p style="margin-top:5px;">%s</p>', $example['info']); } } pfl('</ol>'); } pfl('</blockquote>'); pfl('<br />'); pfl('<br />'); }
static function interpolate($str, $vars) { $originalStr = $str; while (preg_match('/\\$\\{(.*?)\\}/sm', $str, $m)) { list($src, $var) = $m; // retrieve variable to interpolate in context, throw an exception // if not found. if (!array_key_exists($var, $vars)) { // TODO: Add a custom exception Atsumi::error__listen(new Exception(sf('Locale interpolation failed in for var: "%s" in str: "%s"', $var, $originalStr))); $value = ''; } else { $value = $vars[$var]; } $str = str_replace($src, $value, $str); } foreach ($vars as $key => $replacement) { $str = str_replace('${' . $key . '}', $replacement, $str); } return $str; }
public function render($options = array()) { // If elementOnly is specified, only the form element itself is returned if (isset($options['elementOnly']) && $options['elementOnly']) { $out = $this->renderElement(); } else { $out = $this->preRender(); $out .= sfl('<div class="row%s%s%s row_%s"%s>', $this->style ? " " . $this->style : "", $this->cssClass ? " " . $this->cssClass : "", $this->submitted && !$this->validates ? " error" : "", $this->name, $this->cssStyle ? " style='" . $this->cssStyle . "'" : ""); try { $out .= sf('%s%s<div class="element">%s</div>', $this->renderErrors(), ($this->label != '' || $this->getRequired()) && (!array_key_exists('label', $options) || $options['label'] !== false) ? $this->renderLabel() : '', $this->renderElement()); } catch (Exception $e) { // if in debug mode display exception details if (atsumi_Debug::getActive()) { $out .= sfl('Element Exception "%s": %s #%s', $e->getMessage(), $e->getFile(), $e->getLine()); } // fire error listeners Atsumi::error__listen($e); } $out .= '</div>'; $out .= $this->postRender(); } return $out; }
<?php // Get sencha2 require_once "../atsumi/init.php"; // Add class areas to the class loader atsumi_Loader::references(array('atsumi-examples' => 'app examples mvc', 'atsumi' => 'caster mvc widgets validators cache database')); // Initalise sencha and the url parser $settings = new ex_Settings(); Atsumi::initApp($settings); Atsumi::app__setUriParser('uriparser_Gyokuro'); // Execute sencha try { Atsumi::app__go($_SERVER['REDIRECT_URL']); } catch (app_PageNotFoundException $e) { Atsumi::app__go("/404/"); } // Render the processed output Atsumi::app__render();
<?php /** * @version 0.90 * @package Atsumi.Framework * @copyright Copyright(C) 2008, James A. Forrester-Fellowes. All rights reserved. * @license GNU/GPL, see license.txt * The Atsumi Framework is open-source software. This version may have been modified pursuant to * the GNU General Public License, and as distributed it includes or is derivative of works * licensed under the GNU General Public License or other free or open source software licenses. * See copyright.txt for copyright notices and details. */ // Manually require the core components as loader is not initalised at this point require_once dirname(__FILE__) . '/classes/core/loader/Loader.php'; // Load everything else \Atsumi\Core\Loader::references(\Atsumi\Core\Loader::getAtsumiDir(), 'core'); // Start atsumi Atsumi::start();
public function getData($method = null, $controller = null) { $parserData = Atsumi::app__getParserMetaData(); $stack = $parserData['spec']; for ($i = count($stack) - 1; $i >= 0; $i--) { $entity = $stack[$i]; /* if they haven't specified a controllero or it's specified and matches then break */ if (is_null($controller) || $entity['controller'] == $controller) { break; } } // TODO: Give this it's own exceptions! if (!is_null($controller) && $entity['controller'] != $controller) { throw new Exception("Controller not found..."); } $controller = is_null($controller) ? $this : new $controller($this->app, $this->errorHandler); // TODO: This only works for page_ not other methods.... // is method is an index? if (is_integer($method)) { $method = $method = substr($entity['method'][count($entity['method']) - 1 - $method]['name'], 5); } else { if (is_null($method)) { $method = substr($entity['method'][count($entity['method']) - 1]['name'], 5); } } $methodName = sf('data_%s', $method); $pageMethod = null; // loop through methods to find the correct one... foreach ($entity['method'] as $methodData) { if ($methodData['name'] == sf('page_%s', $method)) { $pageMethod = $methodData; break; } } // TODO: Give this it's own exceptions! if (is_null($methodData)) { throw new Exception("Method not found..."); } return call_user_func_array(array($controller, $methodName), $methodData['args']); }
public function add($elementClass, $args) { if (!class_exists($elementClass)) { throw new Exception(sf("Form Element does not exist : %s", $elementClass)); } // if the user has submitted data validate the element if (empty($this->userInput) && empty($this->userFiles)) { $args['submitted'] = false; } else { $args['submitted'] = true; } //TODO: All of these special handles need to moved to the elements.... if ($elementClass == 'widget_FileElement') { $this->encoding = 'multipart/form-data'; } $element = new $elementClass($args); $element->setSubmitted($this->getSubmitted()); // validators to use on element if (array_key_exists('validators', $args)) { $element->setValidators($args['validators']); } // name $element->setName($args['name']); // default value if (array_key_exists('default', $args)) { $element->setDefault($args['default']); } // elements label if (array_key_exists('label', $args)) { $element->setLabel($args['label']); } // css style if (array_key_exists('style', $args)) { $element->setStyle($args['style']); } // css style if (array_key_exists('cssStyle', $args)) { $element->setCssStyle($args['cssStyle']); } // tabindexes if (array_key_exists('tabindex', $args)) { $element->setTabindex($args['tabindex']); } // css style if (array_key_exists('cssClass', $args)) { $element->setCssClass($args['cssClass']); } if (array_key_exists('force_default', $args)) { $element->setForceDefault($args['force_default']); } // If form not yet submitted element is prefilled with the value entered in spec.. if (!$this->submitted && array_key_exists('name', $args) && array_key_exists('value', $args)) { $this->userInput[$args['name']] = $args['value']; } try { $element->setValue($this->userInput, $this->userFiles); } catch (Exception $e) { Atsumi::error__listen($e); $element->setError($e); } $element->validate(); // save the new element to the form... $this->elements[] = $element; $this->elementMap[$element->getName()] =& $element; }