/** * Macro definition block for Smarty. */ function smarty_block_defmacro($params, $content, &$smarty, &$repeat) { if (isset($content)) { ## create a file to store the macro if ($params['name'] == '') { $smarty->trigger_error("defmacro: unspecified attribute 'name' for the macro"); return; } $fileName = $smarty->getCurrentTemplate(); $templateNameString = str_replace(PathManager::templateDir(), '', $fileName); $templateNameString = str_replace('/', ',', $templateNameString); $templateNameString .= ',' . $params['name'] . '.tpl'; # now copy $content to file $templateNameString $fullPath = PathManager::smartyMacroTemplateDir() . $templateNameString; if (!file_exists($fullPath)) { $handle = fopen($fullPath, "w"); fwrite($handle, $content); fclose($handle); } ## ok, now register the macro $smarty->registerMacro($params['name'], $templateNameString); ##echo $templateNameString; return ''; } }
/** * Macro calling method for Smarty. */ function smarty_function_macro($params, &$smarty) { if ($params['name'] == '') { $smarty->trigger_error("macro: missing attribute 'name' for the macro"); return; } ## get macro file name $templateFilename = $smarty->getMacroTemplateFileName($params['name']); if ($templateFilename == null) { $smarty->trigger_error("macro: template file for the macro missing"); return; } // get new smarty instance to process the template: $subSmarty = Ozone::getSmartyPlain(); unset($params['name']); $subSmarty->assign('params', $params); foreach ($params as $key => $value) { $subSmarty->assign($key, $value); } ## copy the macro register $subSmarty->setMacroRegister($smarty->getMacroRegister()); #render the content $out = $subSmarty->fetch(PathManager::smartyMacroTemplateDir() . "/" . $templateFilename); return $out; }
public static function setPaths($paths) { if (is_array($paths)) { self::$paths = $paths; } return self::$paths; }
public function render($runData) { if ($runData->getModuleTemplate() == null) { return; } $this->build($runData); $template = $runData->getModuleTemplate(); $templateFile = PathManager::moduleTemplate($template); // render! $smarty = Ozone::getSmartyPlain(); $page = $runData->getPage(); $smarty->assign("page", $page); // put context into context $context = $runData->getContext(); if ($context !== null) { foreach ($context as $key => $value) { $smarty->assign($key, $value); } } // put errorMessages and messages into the smarty's context as well. $dataMessages = $runData->getMessages(); $dataErrorMessages = $runData->getErrorMessages(); if (count($dataMessages) > 0) { $smarty->assign('data_messages', $dataMessages); } if (count($dataErrorMessages) > 0) { $smarty->assign('data_errorMessages', $dataErrorMessages); } $out = $smarty->fetch($templateFile); return $out; }
public static function findModuleClass($template) { $classFilename = PathManager::moduleClass($template); if (file_exists($classFilename)) { $moduleClassPath = $classFilename; $tmp1 = explode('/', $template); $size = sizeof($tmp1); $moduleClassName = $tmp1[$size - 1]; } else { $tmppath = PathManager::moduleClassDir(); // generate list of possible classes: $template; $path44 = explode('/', $template); for ($i = sizeof($path44) - 1; $i >= 0; $i--) { $tmppath2 = ""; for ($k = 0; $k < $i; $k++) { $tmppath2 .= $path44[$k] . "/"; } $tmppath2 .= "DefaultModule.php"; $classFiles[] = $tmppath2; } foreach ($classFiles as $classFile) { if (file_exists($tmppath . $classFile)) { $moduleClassPath = $tmppath . $classFile; $moduleClassName = "DefaultModule"; break; } } } return array($moduleClassName, $moduleClassPath); }
protected function loadMessages() { $dir = PathManager::messagesDir(); $file = $dir . '/messages.xml'; $xml = simplexml_load_file($file); $this->messagesXML = $xml; }
/** * FilePath : retorna la ruta del xml o json para un contenido por ID * @param $id del elemento * @param $json : flag para retornar la extension json. xml por default * @return $path */ public static function FilePath($id, $module, $json = false) { $option = $json ? 'json' : 'xml'; $options = array('module' => $module, 'folderoption' => $option); $path = PathManager::GetContentTargetPath($options); $folder = PathManager::GetDirectoryFromId($path, $id); return Util::DirectorySeparator($folder . '/' . $id . '.' . $option); }
/** * Macro loader for Smarty. */ function smarty_function_loadmacro($params, &$smarty) { if ($params['set'] == '') { $smarty->trigger_error("macro: missing attribute 'set' for the loadmacro"); return; } $macroPath = PathManager::macroDir(); $smarty->fetch($macroPath . $params['set'] . '.tpl'); }
public function getService($className) { if (isset($this->storage["{$className}"])) { return $this->storage["{$className}"]; } else { require_once PathManager::ozonePhpServiceOnDemandDir() . $className . ".php"; $instance = new $className($this->runData); $this->storage["{$className}"] = $instance; return $instance; } }
/** * Generate a fatal error, printing the $error and sending the header * associated with the $code. By default, this function renders the * error message with the error template. If you provide an ErrorController * that responds to an action called _$code, it will use that instead. * This lets you use the default error handling while developing an app * and switch to a more polished solution later. * This method can also be handy for testing - call it without args to see * all the data associated with a request. * * @see send_header() * @param string $error * @param integer $code * @return void * */ function fatal($error = 'Fatal error.', $code = 500) { send_header($code); error_log($error); // do a mock request to see if we can handle this error with a controller $manager = new PathManager(WEB_ROOT . "/error/_{$code}"); $route = $manager->build_route(); $instance = $manager->controller_instance($route->controller); if ($instance !== FALSE && method_exists($instance, $route->action) !== FALSE) { $route->params = array('error' => $error, 'code' => $code); $action = $route->action; $instance->{$action}($route->params); } else { template('error'); sys()->data->error = $error; sys()->data->code = $code; } render($route); exit; }
private function loadList($listName) { $fileName = PathManager::listSpecFile($listName); $xml = simplexml_load_file($fileName); $optionList = $xml->option; $out = array(); foreach ($optionList as $option) { $out["{$option}" . ''] = $option->text[0] . ''; } $this->storage["{$listName}"] = $out; }
public function loadList($listName) { $fileName = PathManager::listSpecFile($listName); $xml = simplexml_load_file($fileName); $optionList = $xml->option; $out = array(); foreach ($optionList as $option) { $optionKey = $option['key']; $out["{$optionKey}"] = $option->text[0] . ''; } $this->storage["{$listName}"] = $out; $this->pleaseSelectValues["{$listName}"] = $xml->pleaseselect[0]->text[0] . ''; }
/** * Set configs for database connection * * @param array $config * @return void */ public function setConfig($config) { if (!isset($config['source_directory']) || $config['source_directory'] == '') { $sourceDir = PathManager::getDataDirectory() . '/' . $this->_driver; if (!file_exists($sourceDir)) { if (@mkdir($sourceDir) == false) { throw new Exception('Failed to create data source directory "' . $sourceDir . '". Please check permission of data directory'); } } $config['source_directory'] = $sourceDir; } if (!isset($config['source_file']) || $config['source_file'] == '') { $config['source_file'] = $this->_defaultSourceName; } $this->_config = $config; }
public function __construct() { $this->compiler_file = OZONE_ROOT . '/php/core/OzoneSmartyCompiler.php'; $this->compiler_class = 'OzoneSmartyCompiler'; $this->compile_dir = PathManager::smartyCompileDir(); $this->cache_dir = PathManager::smartyCacheDir(); $this->plugins_dir = array(PathManager::smartyPluginDir(), PathManager::smartyOzonePluginDir()); //extra dir for application extensions $this->plugins_dir[] = WIKIDOT_ROOT . '/php/smarty_plugins/'; $this->load_filter('pre', 'defmacrohelp'); $this->assign("URL_HOST", GlobalProperties::$URL_HOST); $this->assign("URL_DOMAIN", GlobalProperties::$URL_DOMAIN); $this->assign("URL_DOCS", GlobalProperties::$URL_DOCS); $this->assign("IP_HOST", GlobalProperties::$IP_HOST); $this->assign("SERVICE_NAME", GlobalProperties::$SERVICE_NAME); $this->assign("SUPPORT_EMAIL", GlobalProperties::$SUPPORT_EMAIL); }
public static function Source() { $lang = Session::Get('lang'); $dir = PathManager::GetApplicationPath() . '/content/source/' . $lang . '/'; $items = array(); $handle = opendir($dir); while (false !== ($item = readdir($handle))) { if ($item != '.' && $item != '..') { $path = $dir . $item; if (is_dir($path)) { $items[] = $path; } } } // endwhile closedir($handle); return $items; }
public static function initForm($formName) { $fileName = PathManager::formSpecFile($formName); $xml = simplexml_load_file($fileName); self::$storage["{$formName}"] = array(); $formxml = $xml->form[0]; self::$storage["{$formName}"]['xml'] = $formxml; // refactor just a bit for an easy access to fields $fields = array(); $fieldNames = array(); foreach ($formxml as $field) { $tname = $field['name']; $fieldNames[] = $tname; $fields["{$tname}"] = $field; } self::$storage["{$formName}"]['fields'] = $fields; self::$storage["{$formName}"]['fieldNames'] = $fieldNames; }
public function send() { // get the template file $templateFile = PathManager::emailTemplate($this->bodyTemplate); // get the Smarty engine $smarty = new OzoneSmarty(); $context = $this->context; if ($context !== null) { foreach ($context as $key => $value) { $smarty->assign($key, $value); } } $body = $smarty->fetch($templateFile); $this->setBody($body); if (parent::send()) { return true; } else { return false; } }
/** * Execute output html using a layout template * * @return string */ protected function renderTemplateWithLayout() { ob_start(); extract($this->_vars); $dir = PathManager::getViewTemplateDirectory(); $ext = NameManager::getTemplateExtension(); $templatePath = sprintf('%s/%s.%s', $dir, $this->_template, $ext); if (!file_exists($templatePath)) { throw new FileNotExistException($templatePath); } require_once $templatePath; $inner_contents = ob_get_contents(); ob_clean(); $dir = PathManager::getViewLayoutDirectory(); $layoutPath = sprintf('%s/%s.%s', $dir, $this->_layout, $ext); if (!file_exists($layoutPath)) { throw new FileNotExistException($layoutPath); } require_once $layoutPath; return ob_get_clean(); }
/** * Proccess Image * Generate a image the first time is requested to be served by apache later * To take advantage of this service, you should use Apache Header module width Header set Cache-Control * @return void */ public static function ProcessImage() { $id = Util::getvalue('id'); $args = Util::getvalue('params'); $ext = Util::getvalue('ext'); $options = array('id' => $id, 'width' => false, 'height' => false, 'quality' => false, 'type' => 'resize'); // Parametro Ancho if (preg_match('/w([0-9]+)/i', $args, $outputWidth)) { $options['width'] = $outputWidth[1]; } // Parametro Alto if (preg_match('/h([0-9]+)/i', $args, $outputHeight)) { $options['height'] = $outputHeight[1]; } // Parametro calidad if (preg_match('/q(100|\\d{1,2})/i', $args, $outputHeight)) { $options['quality'] = $outputHeight[1]; } // Type Crop / Resize $arr = explode('.', $args); if (strpos($arr[0], 'c') !== false) { $options['type'] = 'crop'; } // Extension del archivo solicitado $fileType = $ext ? strtolower($ext) : 'jpg'; $fileType = substr($fileType, 0, 3); $fileType = $fileType == 'jpe' ? 'jpg' : $fileType; $fileType = '.' . $fileType; // Ruta del a imagen origina en disco $sourceOpt = array('module' => 'image', 'folderoption' => 'target'); $sourceDir = PathManager::GetContentTargetPath($sourceOpt); $sourcePath = PathManager::GetDirectoryFromId($sourceDir, $id); $source = $sourcePath . '/' . $id . $fileType; $imageDir = PathManager::GetApplicationPath() . Configuration::Query('/configuration/images_bucket')->item(0)->nodeValue; if (!is_dir($imageDir)) { mkdir($imageDir, 0777); } $imagePath = PathManager::GetDirectoryFromId($imageDir, $id); $image = $imagePath . '/' . $id; // El nombre del archivo contendrá los parametros para ser servida de manera estatica if ($options['width']) { $image .= 'w' . $options['width']; } if ($options['height']) { $image .= 'h' . $options['height']; } if ($options['quality'] !== false) { $image .= 'q' . $options['quality']; } if ($options['type'] == 'crop') { $image .= 'c'; } if (!file_exists($source)) { $source = PathManager::GetApplicationPath() . '/content/not-found' . $fileType; } list($sourceWidth, $sourceHeight) = getimagesize($source); /* Si no esta definido el ancho o el alto debemos asignar limites por defecto para la generación de la imagen */ $options['width'] = $options['width'] ? $options['width'] : $sourceWidth; $options['height'] = $options['height'] ? $options['height'] : $sourceHeight; // Generar la imagen $img = new Image(); $img->load($source); $img->{$options}['type']($options['width'], $options['height']); /* Guardar la imagen en disco el próximo pedido será servido estáticamente por apache */ $quality = $options['quality'] !== false ? $options['quality'] : '80'; $img->save($image, $quality); /* Mostrar la imagen */ $img->display(); }
public function process() { global $timeStart; // initialize logging service $logger = OzoneLogger::instance(); $loggerFileOutput = new OzoneLoggerFileOutput(); $loggerFileOutput->setLogFileName(WIKIDOT_ROOT . "/logs/ozone.log"); $logger->addLoggerOutput($loggerFileOutput); $logger->setDebugLevel(GlobalProperties::$LOGGER_LEVEL); $logger->debug("AJAX module request processing started, logger initialized"); Ozone::init(); $runData = new RunData(); /* processing an AJAX request! */ $runData->setAjaxMode(true); $runData->init(); // extra return array - just for ajax handling $runData->ajaxResponseAdd("status", "OK"); Ozone::setRunData($runData); $logger->debug("RunData object created and initialized"); // handle session at the begging of procession $runData->handleSessionStart(); $template = $runData->getModuleTemplate(); $classFile = $runData->getModuleClassPath(); $className = $runData->getModuleClassName(); $logger->debug("processing template: " . $runData->getModuleTemplate() . ", class: {$className}"); require_once $classFile; $module = new $className(); // module security check if (!$module->isAllowed($runData)) { if ($classFile == $runData->getModuleClassPath()) { $runData->setModuleTemplate("errors/NotAllowed"); } else { // $module->isAllowed() should set the error template!!! if not - // default NotAllowed is used // reload the class again - we do not want the unsecure module to render! $classFile = $runData->getModuleClassPath(); $className = $runData->getModuleClassName(); $logger->debug("processing template: " . $runData->getModuleTemplate() . ", class: {$className}"); require_once $classFile; $module = new $className(); $runData->setAction(null); } } Ozone::initSmarty(); $logger->debug("OZONE initialized"); Ozone::initServices(); $logger->debug("Smarty template services loaded"); Ozone::parseMacros(); $logger->debug("Smarty macros parsed"); Ozone::updateSmartyPlain(); $logger->debug("plain version of Smarty created"); $logger->info("Ozone engines successfully initialized"); // PROCESS ACTION $actionClass = $runData->getAction(); $logger->debug("processing action {$actionClass}"); while ($actionClass != null) { require_once PathManager::actionClass($actionClass); $tmpa1 = explode('/', $actionClass); $actionClassStripped = end($tmpa1); $action = new $actionClassStripped(); // action security check $classFile = $runData->getModuleClassPath(); if (!$action->isAllowed($runData)) { if ($classFile == $runData->getModuleClassPath()) { $runData->setModuleTemplate("errors/NotAllowed"); } // $action->isAllowed() should set the error template!!! if not - // default NotAllowed is used break; } $actionEvent = $runData->getActionEvent(); if ($actionEvent != null) { $action->{$actionEvent}($runData); $logger->debug("processing action: {$actionClass}, event: {$actionEvent}"); } else { $logger->debug("processing action: {$actionClass}"); $action->perform($runData); } // this is in case action changes the action name so that // the next action can be executed. if ($runData->getNextAction() != null) { $actionClass = $runData->getNextAction(); $runData->setAction($actionClass); $runData->setActionEvent($runData->getNextActionEvent()); } else { $actionClass = null; } } // end action process // check if template has been changed by the module. if so... if ($template != $runData->getModuleTemplate) { $classFile = $runData->getModuleClassPath(); $className = $runData->getModuleClassName(); $logger->debug("processing template: " . $runData->getModuleTemplate() . ", class: {$className}"); require_once $classFile; $module = new $className(); } $module->setTemplate($template); $rendered = $module->render($runData); $rVars = $runData->getAjaxResponse(); if ($rendered != null) { // process modules... $moduleProcessor = new ModuleProcessor($runData); $out = $moduleProcessor->process($rendered); $rVars['body'] = $out; } $json = new JSONService(); $out = $json->encode($rVars); echo $out; $runData->handleSessionEnd(); }
function __construct($runData = null) { $this->macroPath = PathManager::macroDir(); }
<?php PathManager::setAppPrefix("/admin"); PathManager::loadPaths(array("", "index"), array("/login", "login"), array("/logout", "logout"), array("/posts/edit/(?P<id>\\d+)", "edit_post"), array("/posts/add", "add_post"), array("/posts/edit/(?P<id>\\d+)/generate-burn-link", "generate_burn_link"), array("/posts/(?P<id>\\d+)/comments", "view_comments"), array("pattern" => "/posts/(?P<id>\\d+)/comments/edit/(?P<comment_id>\\d+)", "action" => "edit_comment", "method" => "POST"), array("pattern" => "/posts/(?P<id>\\d+)/related", "action" => "related_posts"), array("pattern" => "/posts/(?P<id>\\d+)/related/add", "action" => "add_related_post", "method" => "POST"), array("pattern" => "/posts/(?P<id>\\d+)/related/edit/(?P<related_post_id>\\d+)", "action" => "edit_related_post", "method" => "POST"), array("pattern" => "/posts/(?P<id>\\d+)/related/delete/(?P<related_post_id>\\d+)", "action" => "delete_related_post"));
/** * Load a file that defines the library class * * @param string $className The name of the controller library to read * @param string $subdir * @return boolean */ public static function loadLibrary($className, $subdir = null) { $path = PathManager::getLibraryDirectory(); if ($subdir != '') { $path .= '/' . trim($subdir, '/'); } $res = self::load($className, $path, false, false); return $res; }
<?php PathManager::loadPaths(array("/search", "index"));
public function generateClass() { echo "generating classes for " . $this->name . "\n"; $smarty = new OzoneSmarty(); $smarty->left_delimiter = '<{'; $smarty->right_delimiter = '}>'; $smarty->assign('className', $this->getNameLowercaseFirstCapitalized()); $smarty->assign('tableName', $this->name); // put columns into context $smarty->assign('columns', $this->columns); //primary key name $smarty->assign('primaryKeyName', $this->pkColumnName); // peer name $peerName = "DB_" . $this->getNameLowercaseFirstCapitalized() . "Peer"; $smarty->assign('peerName', $peerName); //default values $defvals = array(); foreach ($this->columns as $column) { if ($column->getDefaultValue() != null) { $key = $column->getName(); $defvals["{$key}"] = $column->getDefaultValue(); } } $smarty->assign('defaultValues', $defvals); // references $smarty->assign('masterRelations', $this->masterRelations); $smarty->assign('foreignRelations', $this->foreignRelations); $templateFile = OZONE_ROOT . "/files/dbtemplates/DB_ObjectBaseTemplate.tpl"; $out = $smarty->fetch($templateFile); $cn = 'DB_' . $this->getNameLowercaseFirstCapitalized() . 'Base'; file_put_contents(PathManager::dbClass('/base/' . $cn), $out); //see if file exists! $cn = 'DB_' . $this->getNameLowercaseFirstCapitalized(); if (!file_exists(PathManager::dbClass($cn))) { $templateFile = OZONE_ROOT . "/files/dbtemplates/DB_ObjectTemplate.tpl"; $out = $smarty->fetch($templateFile); file_put_contents(PathManager::dbClass($cn), $out); } $objectName = "DB_" . $this->getNameLowercaseFirstCapitalized(); $smarty->assign('objectName', $objectName); $templateFilePeer = OZONE_ROOT . "/files/dbtemplates/DB_ObjectPeerBaseTemplate.tpl"; $out = $smarty->fetch($templateFilePeer); $cn = 'DB_' . $this->getNameLowercaseFirstCapitalized() . 'PeerBase'; file_put_contents(PathManager::dbClass('/base/' . $cn), $out); //see if file exists! $cn = 'DB_' . $this->getNameLowercaseFirstCapitalized() . 'Peer'; if (!file_exists(PathManager::dbClass($cn))) { $templateFile = OZONE_ROOT . "/files/dbtemplates/DB_ObjectPeerTemplate.tpl"; $out = $smarty->fetch($templateFile); file_put_contents(PathManager::dbClass($cn), $out); } }
/** * Wikidot - free wiki collaboration software * Copyright (c) 2008, Wikidot Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * For more information about licensing visit: * http://www.wikidot.org/license * * @category Ozone * @package Ozone_Util * @version $Id$ * @copyright Copyright (c) 2008, Wikidot Inc. * @license http://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License */ require_once PathManager::externalLibFile('JSON/JSON.php'); /** * Wrapper class for the JSON service. * */ class JSONService extends Services_JSON { }
* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * For more information about licensing visit: * http://www.wikidot.org/license * * @category Ozone * @package Ozone_Email * @version $Id$ * @copyright Copyright (c) 2008, Wikidot Inc. * @license http://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License */ require_once PathManager::externalLibFile('phpmailer/class.phpmailer.php'); /** * A wrapper class around PHPMailer to conform to the coding standards. */ class PHPMailerWrap { private $phpMailer; public function __construct() { $this->phpMailer = new PHPMailer(); } public function setAltBody($value) { $this->phpMailer->AltBody = $value; } public function getAltBody()
<?php PathManager::setAppCacheTtl(300); PathManager::loadPaths(array("/running/(?P<year>2013)", "archive"), array("/running", "index"));
<?php PathManager::setAppCacheTtl(300); PathManager::loadPaths(array("/(?P<path>[A-z0-9_-]+)", "view_static"));
<?php PathManager::loadPaths(array("(?P<url>/[a-z]{0,16})", "do_redirect"));