/** * Before dispatching the requested controller/action * check to see if teh request is an AJAX request (via XMLHTTPREQUEST or $_GET['ajax'] * * If it is an ajax request, remove the layout * * If it is not, setup the FlashMessenger */ public function preDispatch() { $this->_initView(); //if its an AJAX request stop here - can be simulated via ?ajax GET parameter sent in the request if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax'])) { Zend_Controller_Action_HelperBroker::removeHelper('Layout'); } /* if (!$this->getRequest()->isXmlHttpRequest()) { $messages = array(); $messages['error'] = $this->_helper->FlashMessenger->setNamespace('error')->getMessages(); $messages['success'] = $this->_helper->FlashMessenger->setNamespace('success')->getMessages(); $this->view->messages = $messages; } */ //Sets the base url to the javascripts of the application $authNamespace = new Zend_Session_Namespace('Zend_Auth'); $timeout = $authNamespace->timeout; $time_render = time(); $script = ' var base_url = "' . $this->view->baseUrl() . '", timeout = "' . $timeout . '", time_render = "' . $time_render . '"; '; $this->view->headScript()->prependScript($script, $type = 'text/javascript', $attrs = array()); $this->view->inlineScript()->appendFile($this->view->baseUrl() . '/js/contadorsessao.js', 'text/javascript'); }
/** * Return the presentation file */ protected function getPresentationAction() { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); if (!($pres = $this->getD2EM()->getRepository('\\Entities\\MeetingItem')->find($this->getParam('id', null)))) { $this->addMessage('The requested presentation does not exist or does not have an associated file attached to it.', OSS_Message::ERROR); $this->redirect('meeting/read'); } $fn = "IXP_Members_Meeting_{$pres->getMeeting()->getDate()->format('Y-m-d')}_({$pres->getId()})."; // What kind of file do we have? if (preg_match('/pdf$/i', $pres->getFilename())) { header('Content-type: application/pdf'); $fn .= 'pdf'; } else { if (preg_match('/ppt$/i', $pres->getFilename())) { header('Content-type: application/vnd.ms-powerpoint'); $fn .= 'ppt'; } else { if (preg_match('/pps$/i', $pres->getFilename())) { header('Content-type: application/vnd.ms-powerpoint'); $fn .= 'pps'; } else { if (preg_match('/pptx$/i', $pres->getFilename())) { header('Content-type: application/vnd.ms-powerpoint'); $fn .= 'pptx'; } else { header('Content-type: application/octet-stream'); $fn .= substr($pres->getFilename(), strrpos($pres->getFilename(), '.')); } } } } header('Content-Disposition: attachment; filename="' . $fn . '"'); echo @file_get_contents(self::getMeetingsDirectory() . DIRECTORY_SEPARATOR . $pres->getMeeting()->getId() . DIRECTORY_SEPARATOR . $pres->getPresentation()); }
/** * The default error handler action */ public function errorAction() { $this->getLogger()->debug("\n"); $this->getLogger()->debug('ErrorController::errorAction()'); $log = "\n\n************************************************************************\n" . "****************************** EXCEPTIONS *******************************\n" . "************************************************************************\n\n"; $exceptions = $this->getResponse()->getException(); if (is_array($exceptions)) { foreach ($exceptions as $e) { $log .= "--------------------------- EXCEPTION --------------------------\n\n" . "Message: " . $e->getMessage() . "\nLine: " . $e->getLine() . "\nFile: " . $e->getFile(); $log .= "\n\nTrace:\n\n" . $e->getTraceAsString() . "\n\n" . print_r(OSS_Debug::compact_debug_backtrace(), true) . "\n\n"; } } $log .= "------------------------\n\n" . "HTTP_HOST : {$_SERVER['HTTP_HOST']}\n" . "HTTP_USER_AGENT: {$_SERVER['HTTP_USER_AGENT']}\n" . (isset($_SERVER['HTTP_COOKIE']) ? "HTTP_COOKIE: {$_SERVER['HTTP_COOKIE']}\n" : "") . "REMOTE_PORT: {$_SERVER['REMOTE_PORT']}\n" . "REQUEST_METHOD: {$_SERVER['REQUEST_METHOD']}\n" . "REQUEST_URI: {$_SERVER['REQUEST_URI']}\n\n"; $this->getResponse()->setBody('OK: 0'); if (isset($this->view)) { if ($errors = $this->_getParam('error_handler', false)) { $this->getResponse()->clearBody(); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found'); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $this->view->display('error/error-404.phtml'); $this->getLogger()->debug($log); break; default: $this->getLogger()->err($log); $this->view->exceptions = $exceptions; break; } } } return true; }
/** * The trait's initialisation method. * * This function is called from the Action's contructor and it passes those * same variables used for construction to the traits' init methods. * * @param object $request See Parent class constructor * @param object $response See Parent class constructor * @param object $invokeArgs See Parent class constructor */ public function OSS_Controller_Action_Trait_Smarty_Init($request, $response, $invokeArgs) { $this->view = $this->createView(); if ($this->traitIsInitialised('OSS_Controller_Action_Trait_Namespace')) { $this->view->session = $this->getSessionNamespace(); } $this->view->options = $this->_options; $this->view->addHelperPath('OSS/View/Helper', 'OSS_View_Helper'); $this->view->module = $this->getRequest()->getModuleName(); $this->view->controller = $this->getRequest()->getControllerName(); $this->view->action = $this->getRequest()->getActionName(); $this->view->basepath = Zend_Controller_Front::getInstance()->getBaseUrl(); $this->view->getEngine()->loadFilter("pre", 'whitespace_control'); if (substr($request->getActionName(), 0, 4) == 'ajax' || substr($request->getActionName(), 0, 3) == 'cli') { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); } else { $this->view->doctype('HTML5'); $this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8'); } if ($this->traitIsInitialised('OSS_Controller_Action_Trait_Auth')) { $this->view->auth = $this->getAuth(); $this->view->hasIdentity = $this->getAuth()->hasIdentity(); $this->view->identity = $this->getIdentity(); if ($this->getAuth()->hasIdentity() && method_exists($this, 'getUser')) { $this->view->user = $this->getUser(); } } $this->traitSetInitialised('OSS_Controller_Action_Trait_Smarty'); }
public function preDispatch() { // there's no HTML output from this controller - just images Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); header('Content-Type: image/png'); header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); }
/** * Предиспетчер * * @return void */ public function preDispatch() { $this->_jsdir = DOCUMENT_PATH . '/js/'; $this->_cssdir = DOCUMENT_PATH . '/css/'; $this->_cache = $this->_boot->getPluginResource('Cachemanager')->getCacheManager()->getCache('files'); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); }
public function setUp() { $front = Zend_Controller_Front::getInstance(); $front->resetInstance(); $front->setControllerDirectory(array('default' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files', 'admin' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Admin')); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $this->_dispatcher = new Zend_Controller_Dispatcher_Standard(); }
public function testLoadingAndRemovingHelpersStatically() { $helper = new Zend_Controller_Action_Helper_Redirector(); Zend_Controller_Action_HelperBroker::addHelper($helper); $this->assertTrue(Zend_Controller_Action_HelperBroker::hasHelper('redirector')); Zend_Controller_Action_HelperBroker::removeHelper('redirector'); $this->assertFalse(Zend_Controller_Action_HelperBroker::hasHelper('redirector')); }
public function dispatch($url = null) { // removing this helper solves issues with multiple redirects in one test // a fresh instance of helper is registered anyway Zend_Controller_Action_HelperBroker::removeHelper('redirector'); // Zend_Controller_Action_HelperBroker::removeHelper('flashMessenger'); parent::dispatch($url); }
/** * See {@link PHPUnit_Framework_TestCase::tearDown()} for details. */ protected function tearDown() { foreach ($this->helpersToRemove as $name) { /* @var $name string */ Zend_Controller_Action_HelperBroker::removeHelper($name); } parent::tearDown(); }
public function euroixExportAction() { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $customers = $this->getD2EM()->getRepository('\\Entities\\Customer')->getCurrentActive(false, $this->getParam('trafficing', true) ? true : false, $this->getParam('externalonly', true) ? true : false, is_int($this->getParam('ixp', false)) ? $this->getParam('ixp', false) : false); $this->getResponse()->setHeader('Content-Type', 'text/plain'); foreach ($customers as $c) { echo sprintf("%s;%s;%s;%s\n", str_replace(';', '-', $c->getName()), $c->getAutsys(), $c->getCorpwww(), $c->isIPvXEnabled(6) ? 'Yes' : 'No'); } }
public function preDispatch() { $this->assertUserPriv(\Entities\User::AUTH_SUPERUSER); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); // typically a module uses its own views/ folder - but we're sharing these // templates with the main / default module for the CLI actions so we'll // point it there instead $this->getView()->setScriptPath(APPLICATION_PATH . '/views'); }
/** * (non-PHPdoc) * @see Zend_Controller_Action::preDispatch() */ public function preDispatch() { $this->view->addHelperPath('App' . DS . 'View' . DS . 'Helper', 'App_View_Helper'); $this->_helper->addPath('App' . DS . 'Controller' . DS . 'Action' . DS . 'Helper', 'App_Controller_Action_Helper_'); //if its an AJAX request stop here if ($this->isAjaxRequest()) { Zend_Controller_Action_HelperBroker::removeHelper('Layout'); } }
/** * Run the response_contexts filter. * * @return void */ protected function _defineResponseContexts() { Zend_Controller_Action_HelperBroker::removeHelper('contextSwitch'); Zend_Controller_Action_HelperBroker::addHelper(new Omeka_Controller_Action_Helper_ContextSwitch()); $contexts = Zend_Controller_Action_HelperBroker::getStaticHelper('contextSwitch'); $contexts->setContextParam('output'); $contextArray = Omeka_Application_Resource_Helpers::getDefaultResponseContexts(); $contextArray = $this->pluginBroker->applyFilters('response_contexts', $contextArray); $contexts->addContexts($contextArray); }
public function routeStartup(Zend_Controller_Request_Abstract $request) { $request->setParam('View', Showcase_View_Smarty::factory('view.xml')); $request->getParam('View')->cache_handler_func = 'zend_cache_handler'; $request->getParam('View')->caching = 0; $viewRenderer = new Showcase_Controller_Action_Helper_ViewRenderer(); $viewRenderer->setViewSuffix('tpl')->setView($request->getParam('View'))->setViewBasePathSpec(Package::buildPath(SITE_DIR, 'views')); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); }
/** * Удаление валюты по идентификатору */ public function deleteAction() { $currencyId = $this->_request->getParam('currencyId'); $provider = $this->_getExchangeRatesProvider(); $currencyMapper = new Application_Model_CurrencyMapper(); $currencyMapper->delete($currencyId); $result = $provider->updateQuotations(); echo Zend_Json::encode($result); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @return void */ public function setUp() { Zend_Layout_LayoutTest_Override::$_mvcInstance = null; Zend_Controller_Front::getInstance()->resetInstance(); if (Zend_Controller_Action_HelperBroker::hasHelper('Layout')) { Zend_Controller_Action_HelperBroker::removeHelper('Layout'); } if (Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); } }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @return void */ public function setUp() { Zend_Controller_Front::getInstance()->resetInstance(); if (Zend_Controller_Action_HelperBroker::hasHelper('Layout')) { Zend_Controller_Action_HelperBroker::removeHelper('Layout'); } if (Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); } Zend_View_Helper_LayoutTest_Layout::resetMvcInstance(); }
public function preDispatch() { if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax'])) { Zend_Controller_Action_HelperBroker::removeHelper('Layout'); } if (!$this->getRequest()->isXmlHttpRequest()) { $messages = array(); $messages['error'] = $this->_helper->FlashMessenger->setNamespace('error')->getMessages(); $messages['success'] = $this->_helper->FlashMessenger->setNamespace('success')->getMessages(); $this->view->messages = $messages; } }
/** * The trait's initialisation method. * * This function is called from the Action's contructor and it passes those * same variables used for construction to the traits' init methods. * * @param object $request See Parent class constructor * @param object $response See Parent class constructor * @param object $invokeArgs See Parent class constructor */ public function OSS_Controller_Action_Trait_Cli_Init($request, $response, $invokeArgs) { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); if (php_sapi_name() != 'cli') { $this->getLogger()->warn('Non CLI access to a CLI controller from ' . $_SERVER['REMOTE_ADDR'] . ' to ' . $_SERVER['REQUEST_URI']); die('Unauthorised access!'); } // Used in connection with a CLI Tool script. See for example: // https://github.com/inex/IXP-Manager/blob/master/bin/ixptool.php $this->_verbose = $this->getFrontController()->getParam('verbose', false); $this->_debug = $this->getFrontController()->getParam('debug', false); $this->traitSetInitialised('OSS_Controller_Action_Trait_Cli'); }
/** * Set up redirector * * Creates request, response, and action controller objects; sets action * controller in redirector, and sets exit to false. * * Also resets the front controller instance. */ public function setUp() { $front = Zend_Controller_Front::getInstance(); $front->resetInstance(); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $this->redirector = new Zend_Controller_Action_Helper_Redirector(); $this->request = new Zend_Controller_Request_Http(); $this->response = new Zend_Controller_Response_Http(); $this->controller = new Zend_Controller_Action_Helper_Redirector_TestController($this->request, $this->response, array()); // do this so setting headers does not throw exceptions $this->response->headersSentThrowsException = false; $this->redirector->setExit(false)->setActionController($this->controller); }
public function preDispatch() { if ($this->_request->isXmlHttpRequest() || isset($_GET['ajax'])) { Zend_Controller_Action_HelperBroker::removeHelper('Layout'); } if (!$this->getRequest()->isXmlHttpRequest()) { $messages = array(); $messages['error'] = $this->_helper->FlashMessenger->setNamespace('error')->getMessages(); $messages['success'] = $this->_helper->FlashMessenger->setNamespace('success')->getMessages(); $this->view->messages = $messages; } $script = 'var base_url = "' . $this->view->baseUrl() . '";'; $this->view->headScript()->prependScript($script, $type = 'text/javascript', $attrs = array()); }
/** * The default error handler action */ public function errorAction() { $this->getLogger()->debug("\n"); $this->getLogger()->debug('ErrorController::errorAction()'); $this->getLogger()->warn('ERROR'); $except = $this->getResponse()->getException(); $this->getLogger()->debug($except[0]->getMessage() . ' ' . _('on line') . ' ' . $except[0]->getLine() . ' ' . _('of file') . ' ' . $except[0]->getFile()); $this->getLogger()->debug($except[0]->getTraceAsString()); $this->getLogger()->debug("HTTP_HOST : {$_SERVER['HTTP_HOST']}"); $this->getLogger()->debug("HTTP_USER_AGENT: {$_SERVER['HTTP_USER_AGENT']}"); $this->getLogger()->debug("HTTP_COOKIE: {$_SERVER['HTTP_COOKIE']}"); $this->getLogger()->debug("REMOTE_PORT: {$_SERVER['REMOTE_PORT']}"); $this->getLogger()->debug("REQUEST_METHOD: {$_SERVER['REQUEST_METHOD']}"); $this->getLogger()->debug("REQUEST_URI: {$_SERVER['REQUEST_URI']}"); $this->getLogger()->debug("\n"); $this->getResponse()->setBody('OK: 0'); if (isset($this->view)) { $errors = $this->_getParam('error_handler'); $this->getResponse()->clearBody(); //ob_clean(); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found'); $this->addMessage(_('The requested URL or page does not exist.'), ViMbAdmin_Message::ERROR); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $this->view->display('error/error-404.phtml'); break; default: // application error if (isset($errors->exception)) { $exception = $errors->exception; } elseif (Zend_Registry::isRegistered('exception')) { $exception = Zend_Registry::get('exception'); } $this->getLogger()->crit(_('Uncaught Exception causing fatal error') . ': ' . $exception->getMessage()); break; } } // conditionally display exceptions if ($this->getInvokeArg('displayExceptions')) { $this->view->exception = $exception; } else { $this->view->exception = false; } $this->view->request = $errors->request; return true; }
/** * A simple HTML snippet for display on other websites */ public function simpleAction() { $this->view->limit = $limit = (int) $this->getParam('limit', 0); $q = $this->getD2EM()->createQuery('SELECT m, mi FROM \\Entities\\Meeting m LEFT JOIN m.MeetingItems mi ORDER BY m.date DESC, mi.other_content ASC'); if ($limit && $limit > 0) { $q->setMaxResults($limit); } $this->view->entries = $q->execute(); $this->view->simple = true; Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); if ($this->getParam('nostyle', false)) { $this->view->display('meeting/simple2.phtml'); } else { $this->view->display('meeting/simple.phtml'); } }
public function errorAction() { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $errorHandler = $this->getParam('error_handler'); $this->log(); if ($errorHandler && isset($errorHandler['exception'])) { $e = $errorHandler['exception']; $this->getResponse()->clearBody(); $this->getResponse()->clearHeaders(); $this->getResponse()->setHttpResponseCode($e && $e->getCode() ? $e->getCode() : 400); $this->getResponse()->setRawHeader("HTTP/1.1 {$e->getCode()} {$e->getMessage()}"); } else { $this->getResponse()->clearBody(); $this->getResponse()->clearHeaders(); $this->getResponse()->setHttpResponseCode(404); $this->getResponse()->setRawHeader("HTTP/1.1 404 Not Found"); } }
/** * Обработка ошибок приложения * * @return null */ public function errorAction() { $errors = $this->_getParam('error_handler'); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: if ($this->getInvokeArg('displayExceptions') == true) { Zend_Controller_Action_HelperBroker::removeHelper("viewRenderer"); Zend_Debug::dump("ERROR: " . $errors->exception->getMessage() . PHP_EOL . $errors->exception->getTraceAsString()); } break; default: /** * Ошибка приложения (505) */ if ($this->getInvokeArg('displayExceptions') == true) { Zend_Controller_Action_HelperBroker::removeHelper("viewRenderer"); Zend_Debug::dump("ERROR: " . $errors->exception->getMessage() . PHP_EOL . $errors->exception->getTraceAsString()); } break; } }
/** * Загрузка файлов * Метод переписан для поддержки IE8- и загрузку через iframe * * @return void */ public function uploadAction() { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); if (isset($this->_params['type'])) { $filetype = $this->_params['type']; foreach ($_FILES as $filename => $data) { break; } // Определяем имя элемента загружаемого файла // Получаем конфигурацию формы $config = Phorm_Config::xml('forms/control/media.xml', 'upload'); if (isset($config['elements'][$filetype]) && isset($filename)) { // Выделяем из конфигурации формы нужный тип элемента и инициализируем форму с нужным именем элемента $form = new Phorm_Form(null, null, array('elements' => array($filename => $config['elements'][$filetype]))); // Получаем объект элемента из формы $element = $form->getElement($filename); // Валидируем элемент if ($element->isValid($filename)) { // Получаем информацию о файле $fileinfo = $element->getTransferAdapter()->getFileInfo($filename); // Добавляем тип медиа-файла $fileinfo[$filename]['mediatype'] = $filetype; // Сохраняем файл в медиа-библиотеке if ($MediaInfo = $this->Media->saveUploadedFile($fileinfo[$filename])) { // Возвращаем информацию о файле как об объекте медиа-библиотеки exit(Zend_Json::encode(array($MediaInfo))); } else { // Ошибки сохранения exit(Zend_Json::encode(array(array('errors' => array_values($this->Media->_errors))))); } } else { // Ошибки валидации exit(Zend_Json::encode(array(array('errors' => array_values($form->getMessages()))))); } } else { // Ошибка в запросе типа элемента exit(Zend_Json::encode(array(array('errors' => array(array($this->_translate->_('Неверный тип запроса'))))))); } } else { // Ошибка - не указан тип элемента exit(Zend_Json::encode(array(array('errors' => array(array($this->_translate->_('Не задан тип'))))))); } }
/** * Reset MVC instance * * Unregisters plugins and helpers, and destroys MVC layout instance. * * @return void */ public static function resetMvcInstance() { if (null !== self::$_mvcInstance) { $layout = self::$_mvcInstance; $pluginClass = $layout->getPluginClass(); $front = Zend_Controller_Front::getInstance(); if ($front->hasPlugin($pluginClass)) { $front->unregisterPlugin($pluginClass); } if (Zend_Controller_Action_HelperBroker::hasHelper('layout')) { Zend_Controller_Action_HelperBroker::removeHelper('layout'); } unset($layout); self::$_mvcInstance = null; } }
public function preDispatch() { $this->assertUserPriv(\Entities\User::AUTH_SUPERUSER); Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); }
public function assertFlashMessenger($messenger) { Zend_Controller_Action_HelperBroker::removeHelper('FlashMessenger'); $mockFlashMessenger = \Mockery::mock('Zend_Controller_Action_Helper_FlashMessenger[getName, addMessage]')->shouldReceive('addMessage')->with($messenger)->once()->shouldReceive('getName')->andReturn('FlashMessenger')->mock(); Zend_Controller_Action_HelperBroker::addHelper($mockFlashMessenger); }