/** * Executes the execute method of an action. * * @param sfAction $actionInstance An sfAction instance * * @return string The view type */ protected function executeAction($actionInstance) { $response = $actionInstance->getResponse(); // Set X-Frame-Options by default. Can be overridden by actions $response->setHttpHeader("X-Frame-Options", "DENY"); // execute the action $viewName = parent::executeAction($actionInstance); // Add form js and stylesheets to response if ($viewName != sfView::NONE) { $response->setHttpHeader('Expires', '0'); $response->setHttpHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0, max-age=0"); $response->setHttpHeader("Cache-Control", "private", false); $actionVars = $actionInstance->getVarHolder()->getAll(); foreach ($actionVars as $var) { if ($var instanceof sfForm) { foreach ($var->getStylesheets() as $file => $media) { $response->addStylesheet($file, '', array('media' => $media)); } foreach ($var->getJavascripts() as $file) { $response->addJavascript($file); } } } } return $viewName; }
public function __construct(sfAction $actionInstance) { $this->request = $actionInstance->getRequest(); $this->module = $actionInstance->getModuleName(); $this->action = $actionInstance->getActionName(); $this->actionVars = $actionInstance->getVarHolder()->getAll(); }
public static function notifyPostExecuteActionEvent($subject, sfEventDispatcher $dispatcher, sfAction $actionInstance, $result) { $moduleName = $actionInstance->getModuleName(); $actionName = $actionInstance->getActionName(); $params = array('moduleName' => $moduleName, 'actionName' => $actionName, 'actionInstance' => $actionInstance, 'result' => $result); $dispatcher->notify(new sfEvent($subject, 'op_action.post_execute_' . $moduleName . '_' . $actionName, $params)); $dispatcher->notify(new sfEvent($subject, 'op_action.post_execute', $params)); }
/** * @see ckAbstractResultAdapter::getResult() */ public function getResult(sfAction $action) { $lastStackEntry = $action->getContext()->getActionStack()->getLastEntry(); if ($lastStackEntry->getActionInstance() !== $action) { throw new sfRenderException(); } return $lastStackEntry->getPresentation(); }
/** * constractor * * @param sfAction $action * @param string $contentType */ public function __construct(sfAction $action) { $this->action = $action; $configcache = $action->getContext()->getConfiguration()->getConfigCache(); $file = 'config/op_opensocial_mobile_rewrite_url.yml'; $configcache->registerConfigHandler($file, 'sfSimpleYamlConfigHandler'); $this->rewriteUrlConfig = (include $configcache->checkConfig($file)); }
/** * Returns true if the action must always be called in SSL. * * @param sfAction A sfAction instance * * @return Boolean true if the action must always be called in SSL, false otherwise */ protected function sslRequired(sfAction $action) { $security = $action->getSecurityConfiguration(); $actionName = $action->getActionName(); if (isset($security[$actionName]['require_ssl'])) { return $security[$actionName]['require_ssl']; } if (isset($security['all']['require_ssl'])) { return $security['all']['require_ssl']; } return false; }
/** * @see ckAbstractResultAdapter::doGetResult() */ protected function doGetResult(sfAction $action) { $result = null; $vars = $action->getVarHolder()->getAll(); if (isset($vars[$this->getResultProperty()])) { $result = $vars[$this->getResultProperty()]; } else { if (count($vars) == 1) { reset($vars); $result = current($vars); } } return $result; }
private function getUserIdFromAction(sfAction $action) { $user = $action->getContext()->getUser(); if (null === $user || (method_exists($user, 'isAuthenticated') && !$user->isAuthenticated())) { $user_id = self::ANONYMOUS; } else { $user_id = $user->getUsername(); } return $user_id ? $user_id : self::ANONYMOUS; }
public function getRequestParameter($name, $default = null) { $exts = implode('|', self::$extensions); $val = parent::getRequestParameter($name, $default); if (!$val) { return $val; } return preg_replace("/^(.*)\\.({$exts})\$/", '$1', $val); }
public function render($iframe_transport = false) { sfConfig::set('sf_web_debug', false); if ($iframe_transport) { return $this->action->renderText('<textarea data-type="application/json">' . $this->json() . '</textarea>'); } else { return $this->action->renderText($this->json()); } }
/** * Handles the view. * * @param sfFilterChain $filterChain The current filter chain * @param sfAction $actionInstance An sfAction instance * @param string $viewName The view name */ protected function handleView($filterChain, $actionInstance, $viewName) { switch ($viewName) { case sfView::HEADER_ONLY: $this->context->getResponse()->setHeaderOnly(true); return; case sfView::NONE: return; } $this->executeView($actionInstance->getModuleName(), $actionInstance->getActionName(), $viewName, $actionInstance->getVarHolder()->getAll()); }
/** * Answer whether $action is an ajax request (XMLHttpRequest). * * @param sfAction $action The action to test. * * @return bool Whether the request is ajax. */ private function isAjax(sfAction $action) { return $action->getRequest()->isXmlHttpRequest(); }
/** * Implements the default behavior to get the result of a soap action. * * @param sfAction $actionInstance A sfAction instance * * @return mixed The result of the sfAction instance */ public function defaultResultCallback($actionInstance) { $vars = $actionInstance->getVarHolder()->getAll(); // if we have one or more vars and shouldn't render if (count($vars) > 0 && !$this->doRender()) { // get the default result array key $default_key = sfConfig::get(sprintf('mod_%s_%s_result', $actionInstance->getModuleName(), $actionInstance->getActionName()), 'result'); // if there is only one var stored we return it if (count($vars) == 1) { reset($vars); return current($vars); } else { if (array_key_exists($default_key, $vars)) { return $vars[$default_key]; } } } else { if ($this->doRender()) { // return the rendered view return $this->getActionStack()->getLastEntry()->getPresentation(); } } return; }
/** * rewriteBodyForMobile * * @param sfAction $action * @param string $body * @return string */ public static function rewriteBodyForMobile(sfAction $action, $body) { $patterns = array(); $replacements = array(); $patterns[] = "/<\\?xml(.*)encoding=(?:\"|').*(?:\"|')/iU"; $replacements[] = '<?xml${1}encoding="shift-jis"'; $patterns[] = "/<meta(.*)content=\"(.*);\\s*charset=(.*)(;.*)?\"(.*)>/iU"; $replacements[] = '<meta${1}content="${2}; charset=shift-jis${4}"${5}>'; $partials = array($action->getPartial('global/partsPageTitle', array('title' => $action->application->getTitle())), $action->getPartial('application/renderFooter', array('application' => $action->application))); if ($action->getRequest()->getMobile()->isDoCoMo() && opConfig::get('font_size')) { $pattern_start_tag = '/(<td.*?>)/'; $replacement_start_tag = '$1<font size="2">'; $pattern_end_tag = '</td>'; $replacement_end_tag = '</font></td>'; $partials = preg_replace($pattern_start_tag, $replacement_start_tag, $partials); $partials = str_replace($pattern_end_tag, $replacement_end_tag, $partials); foreach ($partials as &$partial) { $partial = '<font size="2">' . $partial . '</font>'; } } $patterns[] = "/<body.*>/iU"; $replacements[] = '${0}' . $partials[0]; $patterns[] = "/<\\/body>/i"; $replacements[] = $partials[1] . '${0}'; $inviteUrl = $action->getController()->genUrl('@application_invite?id=' . $action->memberApplication->getId()); $patterns[] = "/<a(.*)href=(?:'|\")(invite:friends)(.*)(?:'|\")(.*)>/iU"; $replacements[] = '<a${1}href="' . $inviteUrl . '${3}"${4}>'; return mb_convert_encoding(preg_replace($patterns, $replacements, $body), 'SJIS-win', 'UTF-8'); }
public static function setPageEnvironment(sfAction $action, aPage $page) { // Title is pre-escaped as valid HTML $prefix = aTools::getOptionI18n('title_prefix'); $action->getResponse()->setTitle($prefix . $page->getTitle(), false); // Necessary to allow the use of // aTools::getCurrentPage() in the layout. // In Symfony 1.1+, you can't see $action->page from // the layout. aTools::setCurrentPage($page); // Borrowed from sfSimpleCMS if (sfConfig::get('app_a_use_bundled_layout', true)) { $action->setLayout(sfContext::getInstance()->getConfiguration()->getTemplateDir('a', 'layout.php') . '/layout'); } // Loading the a helper at this point guarantees not only // helper functions but also necessary JavaScript and CSS sfContext::getInstance()->getConfiguration()->loadHelpers('a'); }
/** * Returns true if the action must always be called in SSL. * * @param sfAction A sfAction instance * * @return Boolean true if the action must always be called in SSL, false otherwise */ protected function sslRequired(sfAction $action) { return $action->getSecurityValue('require_ssl'); }