/** * Constructor. * Reads the configuration given in the app spec. * In particular, the attribute 'enabled' and 'path' are read. * @param mixed the configuration. */ function __construct($config) { if (isset($config['enabled']) && (string) $config['enabled'] == 'true') { $this->enabled = true; } else { $this->enabled = false; } if (empty($config['path'])) { $this->rootPath = null; } else { $this->rootPath = realpath(pradoGetContextPath((string) $config['path'], dirname(pradoGetApplication()->getSpecificationFile()))); if ($this->rootPath === false || !is_dir($this->rootPath)) { throw new Exception("Unable to locate the cache path '{$this->rootPath}'."); } } $this->savePath = $this->rootPath; }
function assess($parameters, $pageDefinition) { if (isset($parameters['Master'])) { $pageDefinition->setMasterPageName($parameters['Master']); } $app = pradoGetApplication()->getGlobalization(); if (empty($app)) { return; } if (isset($parameters['Culture'])) { $app->Culture = $parameters['Culture']; } if (isset($parameters['Charset'])) { $app->Charset = $parameters['Charset']; } if (isset($parameters['ContentType'])) { $app->ContentType = $parameters['ContentType']; } if (isset($parameters['Catalogue'])) { $app->Translation['catalogue'] = $parameters['Catalogue']; } }
/** * Save untranslated messages to the catalogue. */ public static function saveMessages() { static $onceonly = true; if (!is_null(self::$formatter)) { if ($onceonly) { $app = pradoGetApplication()->getGlobalization(); if (isset($app->Translation['autosave'])) { $catalogue = null; if (isset($app->Translation['catalogue'])) { $catalogue = $app->Translation['catalogue']; } $auto = $app->Translation['autosave']; if ($auto == 'true') { self::$formatter->getSource()->save($catalogue); } else { self::$formatter->getSource()->setCulture($app->getDefaultCulture()); self::$formatter->getSource()->save($auto); } } } $onceonly = false; } }
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('multiform/application.spec')->run();
/** * Adds an include search path. * * A namespace is a dot-connected paths. The first segment of the string * refers to a path alias that is defined in the application specification. * The rest segments represent the subdirectories in order. * For example, 'System.Web.UI' refers to the 'Web/UI' directory under the * framework directory. * * If the namespace represents a path, it will be inserted * at the front of the current include search path. * * If the namespace represents a file (without the extension), * it will be included (require_once) at the position of calling this function. * * Do not call this function before the application singleton is created. * * @param string the namespace string */ function using($namespace) { global $pradoNamespaces; if (isset($pradoNamespaces[$namespace])) { return; } $path = pradoGetApplication()->translatePathAlias($namespace); if (is_null($path)) { throw new TPathAliasNotDefinedException($namespace); } else { if (is_dir($path)) { $pradoNamespaces[$namespace] = $path; } else { if (is_file($path . PRADO_EXT_CLASS)) { $pradoNamespaces[$namespace] = $path . PRADO_EXT_CLASS; require_once $path . PRADO_EXT_CLASS; } else { throw new TNamespaceInvalidException($namespace); } } } }
public function onAuthenticationRequired($pageName) { $this->setRedirectUrl($_SERVER['REQUEST_URI']); pradoGetApplication()->transfer('User:LoginPage'); }
<?php if (!extension_loaded('sqlite')) { die('Sorry, the php sqlite module is required for this example to work.'); } require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('mytest/application.spec')->run();
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('datalist/application.spec')->run();
protected function onPreInit($param) { if (!strlen($this->masterPageName)) { $this->masterPageName = $this->getDefinition(get_class($this))->getMasterPageName(); } if (strlen($this->masterPageName)) { $this->masterPage = pradoGetApplication()->loadPage($this->masterPageName); $this->masterPage->onPreInit($param); } }
/** * Preprocesses a template string by inserting external templates (recursively). * @param string the template string to be preprocessed * @return string the processed result */ protected function preprocessTemplate($str) { if ($n = preg_match_all('/<%include(.*?)%>/', $str, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) { $base = 0; for ($i = 0; $i < $n; ++$i) { $pathAlias = trim($matches[$i][1][0]); $ext = $this->preprocessTemplate(pradoGetApplication()->getResourceLocator()->getExternalTemplate($pathAlias)); $length = strlen($matches[$i][0][0]); $offset = $base + $matches[$i][0][1]; $str = substr_replace($str, $ext, $offset, $length); $base += strlen($ext) - $length; } } return $str; }
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('I18N/application.spec')->run();
protected function getKey() { $key = ''; if (strlen($this->key)) { $key = $this->key; } else { $key = pradoGetApplication()->getApplicationID(); } return $key; }
<?php if (!extension_loaded('sqlite')) { die('Sorry, the php sqlite module is required for this example to work.'); } require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('phonebook/application.spec')->run();
/** * Gets the content of an external template. * @param string the path alias to the external template. * @return string the external template content * @throw TTemplateNotExistsException */ public function getExternalTemplate($pathAlias) { $fname = pradoGetApplication()->translatePathAlias($pathAlias, self::EXT_TEMPLATE); if (is_null($fname) || !is_file($fname)) { throw new TTemplateNotExistsException($pathAlias); } else { return file_get_contents($fname); } }
/** * Instantiates a template for a component. * Components declared in the template will be instantiated * and added as children of the component. The container-containee * relationship will also be established. * @param TComponent the owner of the template * @param array the parsing result returned by TResourceParser. */ public function instantiateTemplate($component, $template) { $application = pradoGetApplication(); if (is_string($template)) { $template = $application->getResourceParser()->parseTemplate($template); } $components = array(); foreach ($template as $key => $object) { //special directives if ((string) $object[0] === 'directive') { $directiveClass = 'T' . $object[1] . 'Directive'; $directive = new $directiveClass(); $directive->assess($object[2], $this); } else { if (count($object) > 2) { // component list($cid, $type, $id, $attributes) = $object; $child = $application->createComponent($type, $id); $childSpec = TComponent::getDefinition($type); foreach ($attributes as $name => $value) { if ($childSpec->canSetProperty($name)) { if (strlen($value) > 1 && $value[0] === '#') { if ($value[1] !== '#') { $child->bindProperty($name, substr($value, 1)); } else { $child->setPropertyInitValue($name, substr($value, 1)); } } else { $child->setPropertyInitValue($name, $value); } } else { if ($childSpec->hasEvent($name)) { $child->attachEventHandler($name, $value); } else { $child->setAttribute($name, $value); } } } if ($child instanceof TControl) { $child->initSkin($child->getPropertyInitValue("Skin")); } $child->initProperties(); $components[$key] = $child; $container = isset($components[$cid]) ? $components[$cid] : $component; $container->addParsedObject($child, $component); } else { // static text $cid = (string) $object[0]; $container = isset($components[$cid]) ? $components[$cid] : $component; $container->addParsedObject($object[1], $component); } } } }
/** * Parses and intantiates templates. * This method is invoked when <b>OnDataBinding</b> event is raised. * It parses and instantiates all assoicated templates for the * repeater control and raises related events. * This method should only used by control developers. * @param TEventParameter event parameter */ protected function onDataBinding($param) { parent::onDataBinding($param); $this->setViewState('Items', null, null); $this->removeChildren(); $this->removeBodies(); $this->items = array(); $this->itemCount = 0; $this->header = null; $this->footer = null; $showEmpty = count($this->dataSource) <= 0 && strlen($this->emptyTemplate); if (is_null($this->dataSource)) { return; } if (strlen($this->headerTemplate) && !$showEmpty) { $header = pradoGetApplication()->createComponent('TRepeaterItem', self::ID_HEADER); $header->setType(TRepeaterItem::TYPE_HEADER); $header->instantiateTemplate($this->headerTemplate); $this->header = $header; $this->addChild($header); $this->addBody($header); $p = new TRepeaterItemEventParameter(); $p->item = $header; $this->onItemCreated($p); } $count = 0; //when the datasource is empty if ($showEmpty) { $empty = pradoGetApplication()->createComponent('TRepeaterItem', self::ID_EMPTY); $empty->setType(TRepeaterItem::TYPE_EMPTY); $empty->instantiateTemplate($this->emptyTemplate); $this->addChild($empty); $this->addBody($empty); $p = new TRepeaterItemEventParameter(); $p->item = $empty; $this->onItemCreated($p); } foreach ($this->dataSource as $key => $value) { if ($this->itemCount > 0 && strlen($this->separatorTemplate)) { $separator = pradoGetApplication()->createComponent('TRepeaterItem'); $separator->setType(TRepeaterItem::TYPE_SEPARATOR); $separator->instantiateTemplate($this->separatorTemplate); $separator->setID(self::ID_SEPARATOR . "{$count}"); $this->addChild($separator); $this->addBody($separator); $p = new TRepeaterItemEventParameter(); $p->item = $separator; $this->onItemCreated($p); } $item = null; if ($count % 2 == 1 && strlen($this->alternatingItemTemplate)) { $item = pradoGetApplication()->createComponent('TRepeaterItem'); $item->instantiateTemplate($this->alternatingItemTemplate); } else { if (strlen($this->itemTemplate)) { $item = pradoGetApplication()->createComponent('TRepeaterItem'); $item->instantiateTemplate($this->itemTemplate); } } if (!is_null($item)) { $item->setID(self::ID_ITEM . "{$count}"); $item->setIndex($key); $item->setItemIndex($count); $item->setData($value); $this->addChild($item); $this->addBody($item); $this->items[$this->itemCount] = $item; $this->itemCount++; $p = new TRepeaterItemEventParameter(); $p->item = $item; $this->onItemCreated($p); } $count++; } if (strlen($this->footerTemplate) && !$showEmpty) { $footer = pradoGetApplication()->createComponent('TRepeaterItem', self::ID_FOOTER); $footer->setType(TRepeaterItem::TYPE_FOOTER); $footer->instantiateTemplate($this->footerTemplate); $this->footer = $footer; $this->addChild($footer); $this->addBody($footer); $p = new TRepeaterItemEventParameter(); $p->item = $footer; $this->onItemCreated($p); } }
/** * Sets authentication false for the user. * Default implementation will destroy all session data related to the user visit. * Derived classes may override this method to provide special treatment. */ public function logout() { $this->setAuthenticated(false); $this->setUsername(''); $session = pradoGetApplication()->getSession(); $session->destroy(); }
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('datagrid/application.spec')->run();
<?php require_once '../framework/prado.php'; pradoGetApplication('web/application.spec')->run();
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('blog/application.spec')->run();
/** * Generates the content in the data grid. * This method is invoked when <b>OnDataBinding</b> event is raised. * It builds up the data grid according to column definitions * data source. * This method should only used by control developers. * @param TEventParameter event parameter */ protected function onDataBinding($param) { parent::onDataBinding($param); $this->setViewState('Items', null, null); $this->removeBodies(); foreach ($this->items as $item) { $this->removeChild($item); } if (!is_null($this->header)) { $this->removeChild($this->header); $this->header = null; } if (!is_null($this->footer)) { $this->removeChild($this->footer); $this->footer = null; } if (!is_null($this->pager)) { $this->removeChild($this->pager); $this->pager = null; } $this->items->clear(); foreach ($this->columns as $column) { $column->dataBind(); } if (is_null($this->dataSource)) { return; } if ($this->isAllowPaging()) { $pageSize = $this->getPageSize(); $offset = $this->isAllowCustomPaging() ? 0 : $pageSize * $this->getCurrentPageIndex(); } else { $offset = 0; $pageSize = self::MAX_PAGE_SIZE; } $index = 0; $editIndex = $this->getEditItemIndex(); $selectedIndex = $this->getSelectedItemIndex(); $this->dataItemCount = 0; $dataSource = array(); foreach ($this->dataSource as $data) { $this->dataItemCount++; $dataSource[] = $data; if ($this->isAllowCustomPaging() && $this->dataItemCount > $offset + $pageSize) { break; } if ($this->dataItemCount <= $offset || $this->dataItemCount > $offset + $pageSize) { continue; } if ($index == 0 && $this->isAutoGenerateColumns()) { //foreach($this->autoColumns as $column) // $this->removeChild($column); $this->autoColumns->clear(); $columnIndex = 0; foreach ($data as $key => $value) { $column = pradoGetApplication()->createComponent('TBoundColumn', 'AutoColumn' . $columnIndex); $column->setHeaderText($key); $column->setDataField($key); $column->setSortExpression($key); $column->dataBind(); $this->autoColumns->add($column); $columnIndex++; } } $item = $this->createComponent('TDataGridItem', self::ID_ITEM . $index); if ($index == $editIndex) { $type = TDataGridItem::TYPE_EDIT_ITEM; } else { if ($index == $selectedIndex) { $type = TDataGridItem::TYPE_SELECTED_ITEM; } else { if ($index % 2) { $type = TDataGridItem::TYPE_ALTERNATING_ITEM; } else { $type = TDataGridItem::TYPE_ITEM; } } } $item->setType($type); $item->setData($data); $item->setItemIndex($index); $this->items->add($item); $this->initializeItem($item); $p = new TDataGridItemEventParameter(); $p->item = $item; $this->onItemCreated($p); $index++; } $this->setViewState('Items', $dataSource, array()); $this->header = $this->createComponent('TDataGridItem', self::ID_HEADER); $this->header->setType(TDataGridItem::TYPE_HEADER); $this->addBody($this->header); $this->initializeItem($this->header); $p = new TDataGridItemEventParameter(); $p->item = $this->header; $this->onItemCreated($p); $this->footer = $this->createComponent('TDataGridItem', self::ID_FOOTER); $this->footer->setType(TDataGridItem::TYPE_FOOTER); $this->addBody($this->footer); $this->initializeItem($this->footer); $p = new TDataGridItemEventParameter(); $p->item = $this->footer; $this->onItemCreated($p); if ($this->isAllowPaging()) { $this->pager = $this->createComponent('TDataGridItem', self::ID_PAGER); $this->pager->setType(TDataGridItem::TYPE_PAGER); $this->addBody($this->pager); $cell = $this->pager->createComponent('TTableCell'); $this->pager->addBody($cell); $p = new TDataGridItemEventParameter(); $p->item = $this->pager; $this->onItemCreated($p); $currentPage = $this->getCurrentPageIndex(); $pageCount = $this->getPageCount(); if ($currentPage >= $pageCount) { $currentPage = $pageCount - 1; } if ($currentPage < 0) { $currentPage = 0; } $this->setCurrentPageIndex($currentPage); $buttonCount = $this->getPagerButtonCount(); $fromPage = intval($currentPage / $buttonCount) * $buttonCount; $toPage = $fromPage + $buttonCount; if ($fromPage > 0) { $button = $cell->createComponent('TLinkButton'); $button->setText('...'); $button->setCommandName(self::CMD_PAGE); $button->setCommandParameter($fromPage - 1); $button->setCausesValidation(false); $cell->addBody($button); $cell->addBody(' '); } for ($i = $fromPage; $i < $toPage; ++$i) { if ($i >= $pageCount) { break; } if ($i == $currentPage) { $cell->addBody(strval($i + 1)); $cell->addBody(' '); } else { $button = $cell->createComponent('TLinkButton'); $button->setText(strval($i + 1)); $button->setCommandName(self::CMD_PAGE); $button->setCommandParameter($i); $button->setCausesValidation(false); $cell->addBody($button); $cell->addBody(' '); } } if ($toPage < $pageCount) { $button = $cell->createComponent('TLinkButton'); $button->setText('...'); $button->setCommandName(self::CMD_PAGE); $button->setCommandParameter($toPage); $button->setCausesValidation(false); $cell->addBody($button); } } }
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('PhpBeanExample/application.spec')->run();
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('helloworld/application.spec')->run();
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('hangman/application.spec')->run();
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('nav_menu/application.spec')->run();
/** * Initializes a skin for the control. If a skin name is provided then that skin will be loaded. * If not then the skin as defined by the SkinName property of the control will be loaded. * If this property has no value then the default skin for the control will be loaded. If no * default skin exists for this control then no skin will be loaded at all. */ public function initSkin($skinName = null) { $type = get_class($this); $theme = pradoGetApplication()->getTheme(); if (is_null($skinName)) { $skinName = "_default"; } if (isset($theme[$type][$skinName])) { if (isset($theme[$type][$skinName]['parent'])) { $this->initSkin($theme[$type][$skinName]['parent']); } $definition = $this->getDefinition($type); foreach ($theme[$type][$skinName]['properties'] as $name => $value) { $definition->configureProperty($this, $name, $value); } } else { if ($skinName != 0) { throw new TSkinNotFoundException($skinName, get_class($this)); } } }
/** * Creates a child component. * This is a convenient function for creating a component * and adding it as a child component. * @param string the component type * @param string the component ID, empty for implicit ID * @return TComponent the created component. */ public function createComponent($type, $id = '') { $component = pradoGetApplication()->createComponent($type, $id); $this->addChild($component); return $component; }
/** * Dispatches the error handling to a page. * The error page will be executed and the rendering result be displayed. * If the error is not handled by a page, the method will display the error * directly based on the application state (debug or not). * This method always terminates the execution of the current application. * @param string error code * @param string|Exception error message or exception */ public function handleError($code, $e = '') { static $count = 0; $debug = pradoGetApplication()->getApplicationState() === TApplication::STATE_DEBUG; if ($e instanceof Exception) { if ($debug) { $msg = get_class($e) . ': ' . $e->getMessage() . "\n" . $e->getTraceAsString(); } else { $msg = $e->getMessage(); } } else { $msg = $e; } if ($count > 0) { if ($debug) { echo "<h1>Recursive Error</h1>\n"; echo "<h2>{$code}</h2>\n"; echo "<pre>{$msg}</pre>\n"; echo "<h2>{$this->errorCode}</h2>\n"; echo "<pre>{$this->errorMessage}</pre>"; } else { echo "<h1>{$code}</h1>\n"; echo "<pre>{$msg}</pre>"; } } else { $this->errorCode = $code; $this->errorMessage = $msg; $count++; if (isset($this->errorPages[$code])) { echo pradoGetApplication()->execute($this->errorPages[$code]); } else { if (!empty($this->defaultPage)) { echo pradoGetApplication()->execute($this->defaultPage); } else { echo "<h1>{$code}</h1>\n"; echo "<pre>{$msg}</pre>"; } } } exit; }
<?php require_once "./prado-2.0.3/framework/prado.php"; $app = pradoGetApplication('svnmanager/application.spec'); $app->run();
<?php require_once dirname(__FILE__) . '/../framework/prado.php'; pradoGetApplication('lists/application.spec')->run();