private function _startThemeManager() { $themeManager = new TThemeManager(); $themeManager->BasePath = "System.Wsat.themes"; $url = Prado::getApplication()->getAssetManager()->publishFilePath(Prado::getPathOfNamespace('System.Wsat')); $themeManager->BaseUrl = "{$url}/themes"; $themeManager->init(null); $this->setThemeManager($themeManager); }
protected function importZendNamespace() { if (is_null(Prado::getPathOfAlias('Zend'))) { $zendBase = !is_null($this->_ZF) ? $this->_ZF . '.*' : 'Application.index.*'; $path = !is_null($this->_ZF) ? $this->_ZF . '.Zend.*' : 'Application.index.Zend.*'; Prado::using($zendBase); Prado::setPathOfAlias('Zend', Prado::getPathOfNamespace($path)); } }
function flushMySQLDatabase() { $conn = $this->sqlmap->getDbConnection(); $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset', '.sql'); if (is_file($file)) { $this->runScript($conn, $file); } else { throw new Exception('unable to find script file ' . $file); } }
public function setOpFile($op_file_namespace) { $op_file = Prado::getPathOfNamespace($op_file_namespace); if (empty($op_file)) { throw new Exception("You need to fix your output folder namespace."); } if (!is_dir($op_file)) { mkdir($op_file, 0777, true); } $this->_opFile = $op_file; }
/** * Retrieves the template used for displaying external exceptions. * This method overrides the parent implementation. */ protected function getErrorTemplate($statusCode, $exception) { // use our own template for BlogException if ($exception instanceof BlogException) { // get the path of the error template file: protected/error.html $templateFile = Prado::getPathOfNamespace('Application.error', '.html'); return file_get_contents($templateFile); } else { // otherwise use the template defined by PRADO return parent::getErrorTemplate($statusCode, $exception); } }
public function getBaseDirectory() { if (is_null($this->_baseDirectory)) { $path = $this->getManager()->getAssetPath(); if ($path === null || !is_dir($path)) { $path = Prado::getPathOfNamespace($path); } if ($path === null || !is_dir($path)) { throw new TConfigurationException('invalid asset path "{0}"', $this->getManager()->getAssetPath()); } $this->_baseDirectory = realpath($path); } return $this->_baseDirectory; }
public function saveButtonClicked($sender, $param) { $dom = new TXmlDocument(); $dom->Encoding = 'utf-8'; $dom->TagName = 'parameters'; $elements = $dom->Elements; $elements[] = $this->createParameter('SiteTitle', $this->SiteTitle->Text); $elements[] = $this->createParameter('SiteSubtitle', $this->SiteSubtitle->Text); $elements[] = $this->createParameter('SiteOwner', $this->SiteOwner->Text); $elements[] = $this->createParameter('AdminEmail', $this->AdminEmail->Text); $elements[] = $this->createParameter('MultipleUser', $this->MultipleUser->Checked); $elements[] = $this->createParameter('AccountApproval', $this->AccountApproval->Checked); $elements[] = $this->createParameter('PostPerPage', $this->PostPerPage->Text); $elements[] = $this->createParameter('RecentComments', $this->RecentComments->Text); $elements[] = $this->createParameter('PostApproval', $this->PostApproval->Checked); $themeName = $this->ThemeName->SelectedItem->Text; $elements[] = $this->createParameter('ThemeName', $themeName); $dom->saveToFile(Prado::getPathOfNamespace(self::CONFIG_FILE, '.xml')); if ($themeName !== $this->Theme->Name) { $this->Response->reload(); } }
/** * Gets the editor script base URL by publishing the tarred source via TTarAssetManager. * @return string URL base path to the published editor script */ protected function getScriptDeploymentPath() { $tarfile = Prado::getPathOfNamespace('System.3rdParty.TinyMCE.tiny_mce', '.tar'); $md5sum = Prado::getPathOfNamespace('System.3rdParty.TinyMCE.tiny_mce', '.md5'); if ($tarfile === null || $md5sum === null) { throw new TConfigurationException('htmlarea_tarfile_invalid'); } $url = $this->getApplication()->getAssetManager()->publishTarFile($tarfile, $md5sum); $this->copyCustomPlugins($url); return $url; }
/** * @param string the parameter file path. It must be in namespace format * and the file extension is '.xml'. * @throws TInvalidOperationException if the module is initialized * @throws TConfigurationException if the file is invalid */ public function setParameterFile($value) { if ($this->_initialized) { throw new TInvalidOperationException('parametermodule_parameterfile_unchangeable'); } else { if (($this->_paramFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null || !is_file($this->_paramFile)) { throw new TConfigurationException('parametermodule_parameterfile_invalid', $value); } } }
/** * @param string database file path (in namespace form) * @throws TInvalidOperationException if the module is already initialized * @throws TConfigurationException if the file is not in proper namespace format */ public function setDbFile($value) { if ($this->_initialized) { throw new TInvalidOperationException('sqlitecache_dbfile_unchangeable'); } else { if (($this->_file = Prado::getPathOfNamespace($value, self::DB_FILE_EXT)) === null) { throw new TConfigurationException('sqlitecache_dbfile_invalid', $value); } } }
/** * @param string external configuration file in namespace format. The file * must be suffixed with '.xml'. * @throws TInvalidDataValueException if the file is invalid. */ public function setConfigFile($value) { if (($this->_configFile = Prado::getPathOfNamespace($value, $this->getApplication()->getConfigurationFileExt())) === null) { throw new TConfigurationException('urlmapping_configfile_invalid', $value); } }
/** * @param string root directory (in namespace form) storing pages * @throws TInvalidOperationException if the service is initialized already or basepath is invalid */ public function setBasePath($value) { if ($this->_initialized) { throw new TInvalidOperationException('pageservice_basepath_unchangeable'); } else { if (($path = Prado::getPathOfNamespace($value)) === null || !is_dir($path)) { throw new TConfigurationException('pageservice_basepath_invalid', $value); } } $this->_basePath = realpath($path); }
public function setDbFile($value) { if (($this->_dbFile = Prado::getPathOfNamespace($value, self::DB_FILE_EXT)) === null) { throw new BlogException(500, 'blogdatamodule_dbfile_invalid', $value); } }
/** * @param string external configuration file in namespace format. The file * must be suffixed with '.xml'. * @throws TInvalidDataValueException if the file is invalid. */ public function setConfigFile($value) { if (($this->_configFile = Prado::getPathOfNamespace($value, self::CONFIG_FILE_EXT)) === null) { throw new TConfigurationException('urlmapping_configfile_invalid', $value); } }
protected function getOutputFile($app_dir, $namespace) { if (is_file($namespace) && strpos($namespace, $app_dir) === 0) { return $namespace; } $file = Prado::getPathOfNamespace($namespace, ".php"); if ($file !== null && false !== ($path = realpath(dirname($file))) && is_dir($path)) { if (strpos($path, $app_dir) === 0) { return $file; } } echo '** Output file ' . $file . ' must be within directory ' . $app_dir . "\n"; return false; }
/** * Registers the stylesheet for presentation. */ protected function registerStyleSheet() { $cs = $this->getPage()->getClientScript(); $cssFile = Prado::getPathOfNamespace('System.3rdParty.TextHighlighter.highlight', '.css'); $cssKey = 'prado:TTextHighlighter:' . $cssFile; if (!$cs->isStyleSheetFileRegistered($cssKey)) { $cs->registerStyleSheetFile($cssKey, $this->publishFilePath($cssFile)); } }
/** * @param string user/role data file path (in namespace form). The file format is XML * whose content is similar to that user/role block in application configuration. * @throws TInvalidOperationException if the module is already initialized * @throws TConfigurationException if the file is not in proper namespace format */ public function setUserFile($value) { if ($this->_initialized) { throw new TInvalidOperationException('usermanager_userfile_unchangeable'); } else { if (($this->_userFile = Prado::getPathOfNamespace($value, self::USER_FILE_EXT)) === null || !is_file($this->_userFile)) { throw new TConfigurationException('usermanager_userfile_invalid', $value); } } }
public function processLogs($logs) { if (empty($logs) || $this->getApplication()->getMode() === 'Performance') { return; } if (headers_sent()) { echo ' <div style="width:100%; background-color:darkred; color:#FFF; padding:2px"> TFirePhpLogRoute.GroupLabel "<i>' . $this->getGroupLabel() . '</i>" - Routing to FirePHP impossible, because headers already sent! </div> '; $fallback = new TBrowserLogRoute(); $fallback->processLogs($logs); return; } require_once Prado::getPathOfNamespace('System.3rdParty.FirePHPCore') . '/FirePHP.class.php'; $firephp = FirePHP::getInstance(true); $firephp->setOptions(array('useNativeJsonEncode' => false)); $firephp->group($this->getGroupLabel(), array('Collapsed' => true)); $firephp->log('Time, Message'); $first = $logs[0][3]; $c = count($logs); for ($i = 0, $n = $c; $i < $n; ++$i) { $message = $logs[$i][0]; $level = $logs[$i][1]; $category = $logs[$i][2]; if ($i < $n - 1) { $delta = $logs[$i + 1][3] - $logs[$i][3]; $total = $logs[$i + 1][3] - $first; } else { $delta = '?'; $total = $logs[$i][3] - $first; } $message = sPrintF('+%0.6f: %s', $delta, preg_replace('/\\(line[^\\)]+\\)$/', '', $message)); $firephp->fb($message, $category, self::translateLogLevel($level)); } $firephp->log(sPrintF('%0.6f', $total), 'Cumulated Time'); $firephp->groupEnd(); }
/** * Sets the translation configuration. Example configuration: * <code> * $config['type'] = 'XLIFF'; //XLIFF, gettext, Database or MySQL (deprecated) * $config['source'] = 'Path.to.directory'; // for types XLIFF and gettext * $config['source'] = 'connectionId'; // for type Database * $config['source'] = 'mysql://*****:*****@host/db'; // for type MySQL (deprecated) * $config['catalogue'] = 'messages'; //default catalog * $config['autosave'] = 'true'; //save untranslated message * $config['cache'] = 'true'; //cache translated message * $config['marker'] = '@@'; // surround untranslated text with '@@' * </code> * Throws exception is source is not found. * @param TMap|array configuration options */ protected function setTranslationConfiguration($config) { if ($config['type'] == 'XLIFF' || $config['type'] == 'gettext') { if ($config['source']) { $config['source'] = Prado::getPathOfNamespace($config['source']); if (!is_dir($config['source'])) { if (@mkdir($config['source']) === false) { throw new TConfigurationException('globalization_source_path_failed', $config['source']); } chmod($config['source'], PRADO_CHMOD); //make it deletable } } else { throw new TConfigurationException("invalid source dir '{$config['source']}'"); } } if ($config['cache']) { $config['cache'] = $this->getApplication()->getRunTimePath() . '/i18n'; if (!is_dir($config['cache'])) { if (@mkdir($config['cache']) === false) { throw new TConfigurationException('globalization_cache_path_failed', $config['cache']); } chmod($config['cache'], PRADO_CHMOD); //make it deletable } } $this->_translation = $config; }
/** * @param string Namespace or path to XML document * @throws TInvalidDataValueException */ public function setDocumentPath($value) { if (!is_file($value)) { $value = Prado::getPathOfNamespace($value, self::EXT_XML_FILE); if ($value === null) { throw new TInvalidDataValueException('xmltransform_documentpath_invalid', $value); } } $this->setViewState('DocumentPath', $value, ''); }
/** * Publish the javascript */ public function onPreRender($param) { parent::onPreRender($param); if (!$this->getPage()->getIsPostBack() && isset($_GET['TActiveFileUpload_InputId']) && isset($_GET['TActiveFileUpload_TargetId']) && $_GET['TActiveFileUpload_InputId'] == $this->getClientID()) { // tricky workaround to intercept "uploaded file too big" error: real uploads happens in onFileUpload instead $this->_errorCode = UPLOAD_ERR_FORM_SIZE; $localName = str_replace('\\', '/', tempnam(Prado::getPathOfNamespace($this->getTempPath()), '')); $fileName = addslashes($this->getFileName()); $params = new TActiveFileUploadCallbackParams(); $params->localName = $localName; $params->fileName = $fileName; $params->fileSize = $this->getFileSize(); $params->fileType = $this->getFileType(); $params->errorCode = $this->getErrorCode(); echo <<<EOS <script language="Javascript"> \tOptions = new Object(); \tOptions.clientID = '{$_GET['TActiveFileUpload_InputId']}'; \tOptions.targetID = '{$_GET['TActiveFileUpload_TargetId']}'; \tOptions.fileName = '{$params->fileName}'; \tOptions.fileSize = '{$params->fileSize}'; \tOptions.fileType = '{$params->fileType}'; \tOptions.errorCode = '{$params->errorCode}'; \tOptions.callbackToken = '{$this->pushParamsAndGetToken($params)}'; \tparent.Prado.WebUI.TactiveFileUpload.onFileUpload(Options); </script> EOS; } }
/** * Applies an application configuration. * @param TApplicationConfiguration the configuration * @param boolean whether the configuration is specified within a service. */ public function applyConfiguration($config, $withinService = false) { if ($config->getIsEmpty()) { return; } // set path aliases and using namespaces foreach ($config->getAliases() as $alias => $path) { Prado::setPathOfAlias($alias, $path); } foreach ($config->getUsings() as $using) { Prado::using($using); } // set application properties if (!$withinService) { foreach ($config->getProperties() as $name => $value) { $this->setSubProperty($name, $value); } } if (empty($this->_services)) { $this->_services = array($this->getPageServiceID() => array('TPageService', array(), null)); } // load parameters foreach ($config->getParameters() as $id => $parameter) { if (is_array($parameter)) { $component = Prado::createComponent($parameter[0]); foreach ($parameter[1] as $name => $value) { $component->setSubProperty($name, $value); } $this->_parameters->add($id, $component); } else { $this->_parameters->add($id, $parameter); } } // load and init modules specified in app config $modules = array(); foreach ($config->getModules() as $id => $moduleConfig) { Prado::trace("Loading module {$id} ({$moduleConfig[0]})", 'System.TApplication'); list($moduleClass, $initProperties, $configElement) = $moduleConfig; $module = Prado::createComponent($moduleClass); if (!is_string($id)) { $id = '_module' . count($this->_modules); $initProperties['id'] = $id; } $this->setModule($id, $module); foreach ($initProperties as $name => $value) { $module->setSubProperty($name, $value); } $modules[] = array($module, $configElement); } foreach ($modules as $module) { $module[0]->init($module[1]); } // load service foreach ($config->getServices() as $serviceID => $serviceConfig) { $this->_services[$serviceID] = $serviceConfig; } // external configurations foreach ($config->getExternalConfigurations() as $filePath => $condition) { if ($condition !== true) { $condition = $this->evaluateExpression($condition); } if ($condition) { if (($path = Prado::getPathOfNamespace($filePath, self::CONFIG_FILE_EXT)) === null || !is_file($path)) { throw new TConfigurationException('application_includefile_invalid', $filePath); } $c = new TApplicationConfiguration(); $c->loadFromFile($path); $this->applyConfiguration($c, $withinService); } } }
/** * @param string the base path for all themes. It must be in the format of a namespace. * @throws TInvalidDataValueException if the base path is not a proper namespace. */ public function setBasePath($value) { if ($this->_initialized) { throw new TInvalidOperationException('thememanager_basepath_unchangeable'); } else { $this->_basePath = Prado::getPathOfNamespace($value); if ($this->_basePath === null || !is_dir($this->_basePath)) { throw new TInvalidDataValueException('thememanager_basepath_invalid', $value); } } }
/** * @param string external configuration file in namespace format. The file * extension must be '.xml'. * @throws TConfigurationException if the file is invalid. */ public function setConfigFile($value) { if (is_file($value)) { $this->_configFile = $value; } else { $file = Prado::getPathOfNamespace($value, self::CONFIG_FILE_EXT); if ($file === null || !is_file($file)) { throw new TConfigurationException('sqlmap_configfile_invalid', $value); } else { $this->_configFile = $file; } } }
/** * Saves the current UrlManager instance to cache. * @return boolean true if UrlManager instance was cached, false otherwise. */ protected function cacheUrlManager($manager) { if ($this->getEnableCache()) { $cache = $this->getApplication()->getCache(); if ($cache !== null) { $dependencies = null; if ($this->getApplication()->getMode() !== TApplicationMode::Performance) { if ($manager instanceof TUrlMapping && ($fn = $manager->getConfigFile())) { $fn = Prado::getPathOfNamespace($fn, $this->getApplication()->getConfigurationFileExt()); $dependencies = new TFileCacheDependency($fn); } } return $cache->set($this->getCacheKey(), $manager, 0, $dependencies); } } return false; }
/** * Gets the editor script base URL by publishing the tarred source via TTarAssetManager. * @return string URL base path to the published editor script */ protected function getScriptDeploymentPath() { $basedir = Prado::getPathOfNamespace('System.Web.Javascripts.source.tinymce-405'); $url = $this->getApplication()->getAssetManager()->publishFilePath($basedir); $this->copyCustomPlugins($url); return $url; }
public function applyConfiguration($config, $withinService = false) { if ($config->getIsEmpty()) { return; } foreach ($config->getAliases() as $alias => $path) { Prado::setPathOfAlias($alias, $path); } foreach ($config->getUsings() as $using) { Prado::using($using); } if (!$withinService) { foreach ($config->getProperties() as $name => $value) { $this->setSubProperty($name, $value); } } if (empty($this->_services)) { $this->_services = array($this->getPageServiceID() => array('TPageService', array(), null)); } foreach ($config->getParameters() as $id => $parameter) { if (is_array($parameter)) { $component = Prado::createComponent($parameter[0]); foreach ($parameter[1] as $name => $value) { $component->setSubProperty($name, $value); } $this->_parameters->add($id, $component); } else { $this->_parameters->add($id, $parameter); } } $modules = array(); foreach ($config->getModules() as $id => $moduleConfig) { if (!is_string($id)) { $id = '_module' . count($this->_lazyModules); } $this->_lazyModules[$id] = $moduleConfig; if ($module = $this->internalLoadModule($id)) { $modules[] = $module; } } foreach ($modules as $module) { $module[0]->init($module[1]); } foreach ($config->getServices() as $serviceID => $serviceConfig) { $this->_services[$serviceID] = $serviceConfig; } foreach ($config->getExternalConfigurations() as $filePath => $condition) { if ($condition !== true) { $condition = $this->evaluateExpression($condition); } if ($condition) { if (($path = Prado::getPathOfNamespace($filePath, $this->getConfigurationFileExt())) === null || !is_file($path)) { throw new TConfigurationException('application_includefile_invalid', $filePath); } $cn = $this->getApplicationConfigurationClass(); $c = new $cn(); $c->loadFromFile($path); $this->applyConfiguration($c, $withinService); } } }
/** * @throws TInvalidDataValueException if the {@link getTempPath TempPath} is not writable. */ public function onInit($sender) { parent::onInit($sender); if (!Prado::getApplication()->getCache()) { if (!Prado::getApplication()->getSecurityManager()) { throw new Exception('TActiveFileUpload needs either an application level cache or a security manager to work securely'); } } if (!is_writable(Prado::getPathOfNamespace($this->getTempPath()))) { throw new TInvalidDataValueException("activefileupload_temppath_invalid", $this->getTempPath()); } }
/** * Preprocesses the template string by including external templates * @param string template string * @return string expanded template string */ protected function preprocess($input) { if ($n = preg_match_all('/<%include(.*?)%>/', $input, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) { for ($i = 0; $i < $n; ++$i) { $filePath = Prado::getPathOfNamespace(trim($matches[$i][1][0]), TTemplateManager::TEMPLATE_FILE_EXT); if ($filePath !== null && is_file($filePath)) { $this->_includedFiles[] = $filePath; } else { $errorLine = count(explode("\n", substr($input, 0, $matches[$i][0][1] + 1))); $this->handleException(new TConfigurationException('template_include_invalid', trim($matches[$i][1][0])), $errorLine, $input); } } $base = 0; for ($i = 0; $i < $n; ++$i) { $ext = file_get_contents($this->_includedFiles[$i]); $length = strlen($matches[$i][0][0]); $offset = $base + $matches[$i][0][1]; $this->_includeAtLine[$i] = count(explode("\n", substr($input, 0, $offset))); $this->_includeLines[$i] = count(explode("\n", $ext)); $input = substr_replace($input, $ext, $offset, $length); $base += strlen($ext) - $length; } } return $input; }
/** * Sets the path storing all error and exception template files. * The path must be in namespace format, such as System.Exceptions (which is the default). * @param string template path in namespace format * @throws TConfigurationException if the template path is invalid */ public function setErrorTemplatePath($value) { if (($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) { $this->_templatePath = $templatePath; } else { throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); } }