public function initialize() { $zibo = Zibo::getInstance(); $this->loadListeners($zibo); $this->registerEvents($zibo); $this->logItem(self::LOG_INTRO); }
/** * 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; } }
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(); }
/** * 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); }
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 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); }
/** * 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); }
protected function tearDown() { $this->tearDownApplication(); try { Reflection::setProperty(Zibo::getInstance(), 'instance', null); } catch (ZiboException $e) { } }
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(); }
/** * Constructs a new database manager: loads the drivers and the connections from the configuration * @return null */ private function __construct() { $this->connections = array(); $this->drivers = array(); $this->defaultConnectionName = null; $zibo = Zibo::getInstance(); $this->loadDriversFromConfig($zibo); $this->loadConnectionsFromConfig($zibo); }
/** * 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 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; }
/** * 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; }
/** * 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); }
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); }
/** * 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 testExecute() { $browser = new GenericBrowser(new File(getcwd())); $this->configIOMock = new ConfigIOMock(); $zibo = Zibo::getInstance($browser, $this->configIOMock); $string = 'This is a test string.' . "\n\n" . 'We would like to have multiple lines.'; $output = System::execute('echo \'' . $string . '\''); $this->assertEquals($string, $output); Reflection::setProperty(Zibo::getInstance(), 'instance', null); }
/** * 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); }
private function setPath() { $request = Zibo::getInstance()->getRequest(); list($protocol, $website) = explode('://', $request->getBaseUrl()); list($this->domain, $path) = explode('/', $website, 2); if (strpos($this->domain, ':') !== false) { list($this->domain, $port) = explode(':', $this->domain, 2); } $this->path = '/' . $path; }
/** * 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; }
public function testRunWithChainedRequests() { $routerMock = $this->getMock('zibo\\core\\Router', array('getRequest', 'getRoutes')); $routerMockCall = $routerMock->expects($this->once()); $routerMockCall->method('getRequest'); $routerMockCall->will($this->returnValue(new Request('', '', 'zibo\\core\\TestController', 'chainAction'))); $zibo = Zibo::getInstance($this->getBrowserMock(), $this->getConfigIOMock()); $zibo->setRouter($routerMock); $zibo->run(false); $this->assertEquals(array('chain', 'index'), TestController::$actions); }
protected function setUp() { $path = new File(__DIR__ . '/../../../../'); $this->setUpApplication($path->getPath()); try { $browser = new GenericBrowser(new File(getcwd())); $configIO = new IniConfigIO(Environment::getInstance(), $browser); Zibo::getInstance($browser, $configIO); } catch (ZiboException $e) { } }
/** * Gets the file from the Zibo include paths * @param string $path Path, in the webdirectory, of the file * @return null|zibo\library\filesystem\File */ private function getFile($path) { $zibo = Zibo::getInstance(); $plainPath = new File(Zibo::DIRECTORY_WEB . File::DIRECTORY_SEPARATOR . $path); $file = $zibo->getFile($plainPath->getPath()); if ($file) { return $file; } $encodedPath = new File($plainPath->getParent()->getPath(), urlencode($plainPath->getName())); return $zibo->getFile($encodedPath->getPath()); }
/** * Service the XML-RPC server * @return null */ private function service() { $rawRequestData = file_get_contents('php://input'); if (isset($_SERVER['HTTP_HMAC'])) { Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, 'hmac send to server: ' . $_SERVER['HTTP_HMAC']); } $requestXml = $this->stripHTTPHeader($rawRequestData); $response = $this->server->service($requestXml); $this->response->setHeader('HMAC', hash_hmac('md5', $response->getXmlString(), 'test')); $this->response->setHeader('Content-Type', 'text/xml'); $this->response->setView(new ResponseView($response)); }
/** * Constructs a new log view * @param string $modelName Name of the model * @param int $id Primary key of the data * @return null */ public function __construct($modelName, $id) { parent::__construct(self::TEMPLATE); $request = Zibo::getInstance()->getRequest(); $dataUrl = $request->getBaseUrl() . '/' . Module::ROUTE_LOG_AJAX . '/' . $modelName . '/' . $id; $translator = I18n::getInstance()->getTranslator(); $labelShow = $translator->translate(self::TRANSLATION_SHOW); $labelHide = $translator->translate(self::TRANSLATION_HIDE); $this->addStyle(self::STYLE); $this->addJavascript(self::SCRIPT); $this->addInlineJavascript('ziboOrmInitializeLog("' . $labelShow . '", "' . $labelHide . '", "' . $dataUrl . '");'); }
/** * Get the mime type of a file based on it's extension * @param File $file * @return string the mime type of the file */ public static function getMimeType(File $file) { $extension = $file->getExtension(); if (empty($extension)) { return self::MIME_UNKNOWN; } $mime = Zibo::getInstance()->getConfigValue(self::CONFIG_MIME . $extension); if (!$mime) { $mime = self::MIME_UNKNOWN; } return $mime; }
/** * Constructs a new authentication status panel * @return null */ public function __construct() { parent::__construct(self::TEMPLATE); $user = SecurityManager::getInstance()->getUser(); $request = Zibo::getInstance()->getRequest(); $baseUrl = $request->getBaseUrl() . Request::QUERY_SEPARATOR; $basePath = $baseUrl . Module::ROUTE_AUTHENTICATION . Request::QUERY_SEPARATOR; $this->set('user', $user); $this->set('urlLogin', $basePath . AuthenticationController::ACTION_LOGIN); $this->set('urlLogout', $basePath . AuthenticationController::ACTION_LOGOUT); $this->set('urlProfile', $baseUrl . Module::ROUTE_PROFILE); }
/** * Add javascript and style, needed for this date field, to the view. If no HtmlView is set to the response, nothing will be done. * @return null */ public function preResponse() { $response = Zibo::getInstance()->getResponse(); $view = $response->getView(); if (!$view instanceof HtmlView) { return; } $view->addJavascript(JQueryModule::SCRIPT_JQUERY); $view->addJavascript(JQueryModule::SCRIPT_JQUERY_UI); $view->addStyle(JQueryModule::STYLE_JQUERY_UI); $view->addInlineJavascript($this->getInitializationScript()); }