/** * Determines which locale to use, based on the HTTP Accept-Language header. * @param zibo\library\i18n\locale\LocaleManager $manager The locale manager * @return null|zibo\library\i18n\locale\Locale the locale */ public function getLocale(LocaleManager $manager) { $request = $this->zibo->getRequest(); if (!$request) { return null; } $fallbackLanguages = array(); $acceptedLanguages = $request->getAcceptLanguage(); foreach ($acceptedLanguages as $acceptedLanguage => $null) { if (strpos($acceptedLanguage, self::SEPARATOR_TERRITORY) === false) { $locale = strtolower($acceptedLanguage); } else { list($language, $territory) = explode(self::SEPARATOR_TERRITORY, $acceptedLanguage); $language = strtolower($language); $locale = $language . '_' . strtoupper($territory); $fallbackLanguages[$language] = true; } if ($manager->hasLocale($locale)) { return $manager->getLocale($locale); } } foreach ($fallbackLanguages as $locale => $null) { if ($manager->hasLocale($locale)) { return $manager->getLocale($locale); } } return null; }
protected static function setInvertToCreatedFilter(AbstractInvertLogItemFilter $filter, Zibo $zibo, $name, $configBase) { $configInvert = $configBase . Module::CONFIG_INVERT; $invert = $zibo->getConfigValue($configInvert); if ($invert !== null) { $filter->setInvert($invert); } }
/** * Gets the dependency container * @param zibo\core\Zibo $zibo Instance of zibo * @return zibo\core\di\DependencyContainer */ public function getContainer(Zibo $zibo) { $container = new DependencyContainer(); $files = array_reverse($zibo->getFiles(self::PATH_FILE)); foreach ($files as $file) { $this->readDependencies($container, $file); } return $container; }
/** * Gets the base URL of the system * @return string */ public function getBaseUrl() { if ($this->baseUrl) { return $this->baseUrl; } $baseUrl = $this->zibo->getConfigValue(self::CONFIG_URL); if (!$baseUrl) { $baseUrl = $this->generateBaseUrl(); } return $this->baseUrl = rtrim($baseUrl, '/'); }
/** * Gets the MIME type of a file based on it's extension * @param zibo\core\Zibo $zibo Instance of Zibo * @param zibo\library\filesystem\File $file The file to get the MIME from * @return string The MIME type of the file */ public static function getMimeType(Zibo $zibo, File $file) { $extension = $file->getExtension(); if (empty($extension)) { return self::MIME_UNKNOWN; } $mime = $zibo->getConfigValue(self::CONFIG_MIME . $extension); if (!$mime) { $mime = self::MIME_UNKNOWN; } return $mime; }
public function testMainWithChainedRequests() { $routerMock = $this->getMock('zibo\\core\\router\\Router', array('getRequest', 'getRoutes', 'getAliases')); $routerMockCall = $routerMock->expects($this->once()); $routerMockCall->method('getRequest'); $routerMockCall->will($this->returnValue(new Request('', '', 'zibo\\core\\TestController', 'chainAction'))); $zibo = new Zibo($this->getBrowserMock(), $this->getConfigIOMock()); $zibo->setRouter($routerMock); $zibo->setDispatcher(new GenericDispatcher($zibo, new ObjectFactory())); $zibo->main(); $this->assertEquals(array('chain', 'index'), TestController::$actions); }
/** * Gets all the translations for the provided locale * @param string $localeCode code of the locale * @return array an associative array with translation key - value pairs * @throws zibo\ZiboException when the locale code is empty or invalid */ public function getTranslations($localeCode) { if (!String::isString($localeCode, String::NOT_EMPTY)) { throw new ZiboException('Provided locale code is empty'); } if (isset($this->translations[$localeCode])) { return $this->translations[$localeCode]; } $this->translations[$localeCode] = array(); $translationFile = Zibo::DIRECTORY_L10N . File::DIRECTORY_SEPARATOR . $localeCode . self::EXTENSION; $translationFiles = array_reverse($this->zibo->getFiles($translationFile)); $this->translations[$localeCode] = $this->getTranslationsFromFiles($translationFiles); return $this->translations[$localeCode]; }
/** * Dispatches a request to the action of a controller * @param Request $request The request to dispatch * @param Response $response The response to dispatch the request to * @return mixed The return value of the action * @throws zibo\ZiboException when the action is not invokable */ public function dispatch(Request $request, Response $response) { $controller = $this->getController($request); $actionName = $request->getActionName(); $parameters = $request->getParameters(); $callback = $this->processAction($controller, $actionName, $parameters); $this->prepareController($controller, $request, $response, $actionName, $parameters); $this->zibo->triggerEvent(self::EVENT_PRE_DISPATCH, $controller, $actionName, $parameters); $controller->preAction(); $returnValue = $callback->invokeWithArrayArguments($parameters); $controller->postAction(); $this->zibo->triggerEvent(self::EVENT_POST_DISPATCH, $controller, $actionName, $parameters); return $returnValue; }
/** * Render this taskbar view * @param boolean $return true to return the rendered view, false to send it to the client * @return mixed null when provided $return is set to true; the rendered output when the provided $return is set to false */ public function render($return = true) { $request = Zibo::getInstance()->getRequest(); if (!$request) { return; } $baseUrl = $request->getBaseUrl() . Request::QUERY_SEPARATOR; $renderedPanels = array(); $notificationPanels = $this->taskbar->getNotificationPanels(); foreach ($notificationPanels as $panel) { $renderedPanels[] = $this->renderView($panel); } $applicationsMenu = $this->taskbar->getApplicationsMenu(); $applicationsMenu->setBaseUrl($baseUrl); $settingsMenu = $this->taskbar->getSettingsMenu(); $settingsMenu->setBaseUrl($baseUrl); $settingsMenu->orderItems(); $this->set('applicationsMenu', $applicationsMenu); $this->set('settingsMenu', $settingsMenu); $this->set('notificationPanels', array_reverse($renderedPanels)); $this->set('title', $this->taskbar->getTitle()); $this->addStyle(self::STYLE_TASKBAR); $this->addJavascript(self::SCRIPT_CLICKMENU); $this->addInlineJavascript("\$('#taskbarApplications').clickMenu({start: 'left'}); \n \t\t\t\t" . "\$('#taskbarSettings').clickMenu({start: 'right'});"); return parent::render($return); }
public function tearDown() { try { Reflection::setProperty(Zibo::getInstance(), 'instance', null); } catch (ZiboException $e) { } }
/** * Gets the base URL * @return string */ protected function getBaseUrl() { if ($this->baseUrl) { return $this->baseUrl; } return $this->baseUrl = Zibo::getInstance()->getRequest()->getBaseUrl(); }
/** * Executes the callback in a different thread. All arguments to this method will be passed on to the callback. * * The callback will be invoked but the script will not wait for it to finish. * @return null */ public function run() { $pid = @pcntl_fork(); if ($pid == -1) { throw new ZiboException('Could not run the thread: unable to fork the callback'); } if ($pid) { // parent process code $this->pid = $pid; } else { // child process code pcntl_signal(SIGTERM, array($this, 'signalHandler')); try { $this->callback->invokeWithArrayArguments(func_get_args()); } catch (Exception $exception) { $message = $exception->getMessage(); if (!$message) { $message = get_class($exception); } Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $message, $exception->getTraceAsString(), 1); echo $message . "\n"; echo $exception->getTraceAsString(); } exit; } }
/** * Action to view and change the profile * @return null */ public function indexAction() { $user = SecurityManager::getInstance()->getUser(); if (!$user) { throw new UnauthorizedException(); } $form = new ProfileForm($this->request->getBasePath(), $user); $form->addHook(new AccountProfileHook()); Zibo::getInstance()->runEvent(self::EVENT_PREPARE_FORM, $form); if ($form->isSubmitted()) { try { $form->validate(); $form->processSubmit($this); if (!$this->response->getView() && !$this->response->willRedirect()) { $this->response->setRedirect($this->request->getBasePath()); } return; } catch (ValidationException $exception) { $form->setValidationException($exception); } } $translator = $this->getTranslator(); $view = new ProfileView($form); $view->setPageTitle($translator->translate(self::TRANSLATION_TITLE)); $this->response->setView($view); }
function smarty_function_image($params, &$smarty) { try { if (empty($params['src'])) { throw new Exception('No src parameter provided for the image'); } $src = $params['src']; unset($params['src']); $image = new Image($src); if (!empty($params['thumbnail'])) { if (empty($params['width'])) { throw new Exception('No width parameter provided for the thumbnailer'); } if (empty($params['height'])) { throw new Exception('No height parameter provided for the thumbnailer'); } $image->setThumbnailer($params['thumbnail'], $params['width'], $params['height']); unset($params['thumbnail']); unset($params['width']); unset($params['height']); } foreach ($params as $key => $value) { $image->setAttribute($key, $value); } $html = $image->getHtml(); } catch (Exception $exception) { Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1); $html = '<span class="red" style="color: red;">Could not load image: ' . $exception->getMessage() . '</span>'; } return $html; }
/** * Action to ask for extra information and to send the error report * @return null */ public function indexAction() { $zibo = Zibo::getInstance(); $session = Session::getInstance(); $recipient = $zibo->getConfigValue(Module::CONFIG_MAIL_RECIPIENT); $subject = $zibo->getConfigValue(Module::CONFIG_MAIL_SUBJECT); $report = $session->get(Module::SESSION_REPORT); if (!$report || !$recipient) { $this->response->setRedirect($this->request->getBaseUrl()); return; } $form = new ReportForm($this->request->getBasePath()); if ($form->isSubmitted()) { $comment = $form->getComment(); if ($comment) { $report .= "\n\nComment:\n" . $comment; } if (!$subject) { list($subject, $null) = explode("\n", $report, 2); } $mail = new Message(); $mail->setTo($recipient); $mail->setSubject($subject); $mail->setMessage($report); $mail->send(); $session->set(Module::SESSION_REPORT); $this->addInformation(self::TRANSLATION_MAIL_SENT); $this->response->setRedirect($this->request->getBaseUrl()); return; } $view = new ReportView($form, $report); $this->response->setView($view); }
/** * Loads the archive types from the Zibo configuration * @return null */ private function loadTypes(Zibo $zibo) { $this->types = array(); $types = $zibo->getConfigValue(self::CONFIG_TYPES, array()); foreach ($types as $typeName => $className) { $this->register($typeName, $className); } }
private function loadListeners(Zibo $zibo) { $config = $zibo->getConfigValue(self::CONFIG_LOG); if (isset($config[self::CONFIG_LISTENER])) { unset($config[self::CONFIG_LISTENER]); } if (isset($config[self::CONFIG_FILTER])) { unset($config[self::CONFIG_FILTER]); } $listenerFactory = new LogListenerFactory($zibo); foreach ($config as $name => $parameters) { $listener = $listenerFactory->createListener($name); if ($listener != null) { $this->log->addLogListener($listener); } } }
/** * Gets a request from the provided path for request chaining * @param string $path The path to route * @return zibo\core\Request|null A request if the path was found, null otherwise */ protected function route($path) { $router = $this->zibo->getRouter(); if (!$router) { return null; } return $router->getRequest($this->request->getBaseUrl(), $path); }
public function tearDown() { Reflection::setProperty(Zibo::getInstance(), 'instance', null); if (file_exists('application/config/modules.temp.xml')) { unlink('application/config/modules.temp.xml'); } $this->tearDownApplication(); }
protected function tearDown() { $this->tearDownApplication(); try { Reflection::setProperty(Zibo::getInstance(), 'instance', null); } catch (ZiboException $e) { } }
/** * Loads the defined modules from the Zibo Configuration * @param zibo\core\Zibo $zibo Instance of Zibo * @return array Array with the defined modules * @throws zibo\ZiboException when a module could not be created * @see Module * @see CONFIG_MODULE */ public function loadModules(Zibo $zibo) { $configModules = $zibo->getConfigValue(self::CONFIG_MODULE); if (!$configModules) { return array(); } $objectFactory = new ObjectFactory(); $modules = array(); $configModules = Config::parseConfigTree($configModules); foreach ($configModules as $configKey => $moduleClass) { try { $modules[] = $objectFactory->create($moduleClass, self::INTERFACE_MODULE); } catch (ZiboException $exception) { throw new ZiboException('Could not create ' . $moduleClass . ' from the ' . $configKey . ' configuration key', 0, $exception); } } return $modules; }
/** * Gets the temporary directory for the installation process * @param string $path The path in the temporary directory * @return zibo\library\filesystem\File */ public static function getTempDirectory($path = null) { $rootDirectory = Zibo::getInstance()->getRootPath(); $rootDirectory = $rootDirectory->getPath(); $path = 'zibo-' . substr(md5($rootDirectory), 0, 7) . ($path ? '/' . $path : ''); $temp = new File(sys_get_temp_dir(), $path); $temp->create(); return $temp; }
/** * Initialize the orm module for the request, register orm event listeners * @return null */ public function initialize() { $zibo = Zibo::getInstance(); $zibo->registerEventListener(Zibo::EVENT_CLEAR_CACHE, array($this, 'clearCache')); $zibo->registerEventListener(Installer::EVENT_PRE_INSTALL_SCRIPT, array($this, 'defineModelsForInstalledModules')); $zibo->registerEventListener(Installer::EVENT_POST_UNINSTALL_MODULE, array($this, 'deleteModelsForUninstalledModules')); $zibo->registerEventListener(Dispatcher::EVENT_PRE_DISPATCH, array($this, 'prepareController')); $zibo->registerEventListener(BaseView::EVENT_TASKBAR, array($this, 'prepareTaskbar')); }
/** * Constructs a new recaptcha * @return null */ public function __construct() { $zibo = Zibo::getInstance(); $publicKey = $zibo->getConfigValue(self::CONFIG_PUBLIC_KEY); $privateKey = $zibo->getConfigValue(self::CONFIG_PRIVATE_KEY); $this->setPublicKey($publicKey); $this->setPrivateKey($privateKey); $this->errors = array(); }
public function setUp() { $this->io = new IOMock(); $this->negotiator = new HttpNegotiator(); $browser = new GenericBrowser(new File(getcwd())); $configIO = new ConfigIOMock(); $configIO->setValues('i18n', array('locale' => array('order' => 'en,du,fr'))); $this->zibo = Zibo::getInstance($browser, $configIO); }
/** * Constructs a new recaptcha view * @param string $publicKey The public key of the recaptcha * @param string $error Error of the previous submit * @return null */ public function __construct($publicKey, $error = null, $theme = null) { if (!$theme) { $theme = Zibo::getInstance()->getConfigValue(self::CONFIG_THEME); } $this->publicKey = $publicKey; $this->error = $error; $this->theme = $theme; }
/** * Reads the routes from the data source * @return array Array with Route instances */ protected function readRoutes() { $routes = array(); $files = array_reverse(Zibo::getInstance()->getFiles(self::PATH_FILE)); foreach ($files as $file) { $fileRoutes = $this->readRoutesFromFile($file); $routes = Structure::merge($routes, $fileRoutes); } return $routes; }
/** * Hook to grab all the messages from the view which is going to be displayed * @return null */ public function preResponse() { $response = Zibo::getInstance()->getResponse(); $view = $response->getView(); if (!$view instanceof SmartyView) { return; } $messages = $view->get('_messages'); $this->set('_messages', $messages); }
/** * Constructs a new localize panel form * @return null */ public function __construct() { $request = Zibo::getInstance()->getRequest(); $factory = FieldFactory::getInstance(); parent::__construct($request->getBaseUrl() . Request::QUERY_SEPARATOR . Module::ROUTE_LOCALIZE, self::NAME); $this->removeFromClass(Form::STYLE_FORM); $localeCode = LocalizeController::getLocale(); $localeField = $factory->createField(FieldFactory::TYPE_LOCALE, self::FIELD_LOCALE, $localeCode); $this->addField($localeField); }
public function preResponse() { $response = Zibo::getInstance()->getResponse(); $view = $response->getView(); if (!$view instanceof HtmlView) { return; } $view->addStyle(self::STYLE_BBCODE); $view->addJavascript(self::SCRIPT_BBCODE); }