/** * Initializes this Filter. * * @param sfContext $context The current application context * @param array $parameters An associative array of initialization parameters * * @return boolean true */ public function initialize($context, $parameters = array()) { $this->request = $context->getRequest(); $this->response = $context->getResponse(); $this->user = $context->getUser(); return parent::initialize($context, $parameters); }
/** * Attempts to return the theme for the current request * * This first throws a sympal.theme.set_theme_from_request event, giving * anyone the opportunity to determine the theme. If this event is not * handled, we continue with some default rules for setting themes. * * @param sfContext $context * @param array An array of valid themes, to be used for user-entered themes * * @return string The theme (defaults to the default theme) */ public function getThemeForRequest(sfContext $context, $validThemes) { $event = $context->getEventDispatcher()->notifyUntil(new sfEvent($this, 'theme.set_theme_from_request', array('context' => $context))); if ($event->isProcessed()) { return $event->getReturnValue(); } if ($this->getOption('allow_changing_theme_by_url', true)) { $user = $context->getUser(); $request = $context->getRequest(); if ($theme = $request->getParameter($this->getOption('theme_request_parameter_name', 'sf_theme'))) { // make sure the theme is valid if (in_array($theme, $validThemes)) { $user->setCurrentTheme($theme); return $theme; } else { // unset the user attribute $user->setCurrentTheme(false); } } if ($theme = $user->getCurrentTheme()) { return $theme; } } // Get the theme from module/route. False is a valid response (don't set theme) $module = $context->getModuleName(); $route = $context->getRouting()->getCurrentRouteName(); $theme = $this->getThemeFromConfig($module, $route); if ($theme || $theme === false) { return $theme; } return $this->getOption('default_theme'); }
/** * Initializes this component. * * @param sfContext $context The current application context * * @return boolean true, if initialization completes successfully, otherwise false */ public function initialize($context) { $this->context = $context; $this->varHolder = new sfParameterHolder(); $this->request = $context->getRequest(); $this->response = $context->getResponse(); $this->requestParameterHolder = $this->request->getParameterHolder(); return true; }
/** * Initializes this component. * * @param sfContext $context The current application context. * @param string $moduleName The module name. * @param string $actionName The action name. * * @return boolean true, if initialization completes successfully, otherwise false */ public function initialize($context, $moduleName, $actionName) { $this->moduleName = $moduleName; $this->actionName = $actionName; $this->context = $context; $this->dispatcher = $context->getEventDispatcher(); $this->varHolder = new sfParameterHolder(); $this->request = $context->getRequest(); $this->response = $context->getResponse(); $this->requestParameterHolder = $this->request->getParameterHolder(); }
/** * Initializes the cache manager. * * @param sfContext $context Current application context * @param sfCache $cache An sfCache instance */ public function initialize($context, sfCache $cache, $options = array()) { $this->context = $context; $this->dispatcher = $context->getEventDispatcher(); $this->controller = $context->getController(); $this->request = $context->getRequest(); $this->options = array_merge(array('cache_key_use_vary_headers' => true, 'cache_key_use_host_name' => true), $options); if (sfConfig::get('sf_web_debug')) { $this->dispatcher->connect('view.cache.filter_content', array($this, 'decorateContentWithDebug')); } // empty configuration $this->cacheConfig = array(); // cache instance $this->cache = $cache; // routing instance $this->routing = $context->getRouting(); }
/** * Initialize this User. * * @param sfContext $context A Context instance. * @param array $parameters An associative array of initialization parameters. * * @return bool true, if initialization completes successfully, otherwise * false. * * @throws <b>sfInitializationException</b> If an error occurs while initializing this User. */ public function initialize($context, $parameters = array()) { $this->context = $context; $this->parameterHolder = new sfParameterHolder(); $this->parameterHolder->add($parameters); $this->attributeHolder = new sfParameterHolder(self::ATTRIBUTE_NAMESPACE); // read attributes from storage $attributes = $context->getStorage()->read(self::ATTRIBUTE_NAMESPACE); if (is_array($attributes)) { foreach ($attributes as $namespace => $values) { $this->attributeHolder->add($values, $namespace); } } // set the user culture to sf_culture parameter if present in the request // otherwise // - use the culture defined in the user session // - use the default culture set in i18n.yml if (!($culture = $context->getRequest()->getParameter('sf_culture'))) { if (null === ($culture = $context->getStorage()->read(self::CULTURE_NAMESPACE))) { $culture = sfConfig::get('sf_i18n_default_culture', 'en'); } } $this->setCulture($culture); }
/** * Initializes this view. * * @param sfContext $context The current application context * @param string $moduleName The module name for this view * @param string $actionName The action name for this view * @param string $viewName The view name * * @return bool true, if initialization completes successfully, otherwise false */ public function initialize($context, $moduleName, $actionName, $viewName) { $this->moduleName = $moduleName; $this->actionName = $actionName; $this->viewName = $viewName; $this->context = $context; $this->dispatcher = $context->getEventDispatcher(); sfOutputEscaper::markClassesAsSafe(array('sfForm', 'sfModelGeneratorHelper')); $this->attributeHolder = $this->initializeAttributeHolder(); $this->parameterHolder = new sfParameterHolder(); $this->parameterHolder->add(sfConfig::get('mod_' . strtolower($moduleName) . '_view_param', array())); $request = $context->getRequest(); $format = $request->getRequestFormat(); if (null !== $format) { if ('html' != $format) { $this->setExtension('.' . $format . $this->getExtension()); } if ($mimeType = $request->getMimeType($format)) { $this->context->getResponse()->setContentType($mimeType); if ('html' != $format) { $this->setDecorator(false); } } } $this->dispatcher->notify(new sfEvent($this, 'view.configure_format', array('format' => $format, 'response' => $context->getResponse(), 'request' => $context->getRequest()))); // include view configuration $this->configure(); return true; }
function _a_get_assets_body($type, $assets) { $gzip = sfConfig::get('app_a_minify_gzip', false); sfConfig::set('symfony.asset.' . $type . '_included', true); $html = ''; // We need our own copy of the trivial case here because we rewrote the asset list // for stylesheets after LESS compilation, and there is no way to // reset the list in the response object if (!sfConfig::get('app_a_minify', false)) { // This branch is seen only for CSS, because javascript calls the original Symfony // functionality when minify is off foreach ($assets as $file => $options) { $html .= stylesheet_tag($file, $options); } return $html; } $sets = array(); foreach ($assets as $file => $options) { if (preg_match('/^http(s)?:/', $file) || isset($options['data-minify']) && $options['data-minify'] === 0) { // Nonlocal URL or minify was explicitly shut off. // Don't get cute with it, otherwise things // like Addthis and ckeditor don't work if ($type === 'stylesheets') { $html .= stylesheet_tag($file, $options); } else { $html .= javascript_include_tag($file, $options); } continue; } /* * * Guts borrowed from stylesheet_tag and javascript_tag. We still do a tag if it's * a conditional stylesheet * */ $absolute = false; if (isset($options['absolute']) && $options['absolute']) { unset($options['absolute']); $absolute = true; } $condition = null; if (isset($options['condition'])) { $condition = $options['condition']; unset($options['condition']); } if (!isset($options['raw_name'])) { if ($type === 'stylesheets') { $file = stylesheet_path($file, $absolute); } else { $file = javascript_path($file, $absolute); } } else { unset($options['raw_name']); } if (is_null($options)) { $options = array(); } if ($type === 'stylesheets') { $options = array_merge(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen', 'href' => $file), $options); } else { $options = array_merge(array('type' => 'text/javascript', 'src' => $file), $options); } if (null !== $condition) { $tag = tag('link', $options); $tag = comment_as_conditional($condition, $tag); $html .= $tag . "\n"; } else { unset($options['href'], $options['src']); $optionGroupKey = json_encode($options); $set[$optionGroupKey][] = $file; } // echo($file); // $html .= "<style>\n"; // $html .= file_get_contents(sfConfig::get('sf_web_dir') . '/' . $file); // $html .= "</style>\n"; } // CSS files with the same options grouped together to be loaded together foreach ($set as $optionsJson => $files) { $groupFilename = aAssets::getGroupFilename($files); $groupFilename .= $type === 'stylesheets' ? '.css' : '.js'; if ($gzip) { $groupFilename .= 'gz'; } $dir = aFiles::getUploadFolder(array('asset-cache')); if (!file_exists($dir . '/' . $groupFilename)) { $content = ''; foreach ($files as $file) { $path = null; if (sfConfig::get('app_a_stylesheet_cache_http', false)) { $url = sfContext::getRequest()->getUriPrefix() . $file; $fileContent = file_get_contents($url); } else { $path = sfConfig::get('sf_web_dir') . $file; $fileContent = file_get_contents($path); } if ($type === 'stylesheets') { $options = array(); if (!is_null($path)) { // Rewrite relative URLs in CSS files. // This trick is available only when we don't insist on // pulling our CSS files via http rather than the filesystem // dirname would resolve symbolic links, we don't want that $fdir = preg_replace('/\\/[^\\/]*$/', '', $path); $options['currentDir'] = $fdir; $options['docRoot'] = sfConfig::get('sf_web_dir'); } if (sfConfig::get('app_a_minify', false)) { $fileContent = Minify_CSS::minify($fileContent, $options); } } else { // Trailing carriage return makes behavior more consistent with // JavaScript's behavior when loading separate files. For instance, // a missing trailing semicolon should be tolerated to the same // degree it would be with separate files. The minifier is not // a lint tool and should not surprise you with breakage $fileContent = JSMin::minify($fileContent) . "\n"; } $content .= $fileContent; } if ($gzip) { _gz_file_put_contents($dir . '/' . $groupFilename . '.tmp', $content); } else { file_put_contents($dir . '/' . $groupFilename . '.tmp', $content); } @rename($dir . '/' . $groupFilename . '.tmp', $dir . '/' . $groupFilename); } $options = json_decode($optionsJson, true); // Use stylesheet_path and javascript_path so we can respect relative_root_dir if ($type === 'stylesheets') { $options['href'] = stylesheet_path(sfConfig::get('app_a_assetCacheUrl', '/uploads/asset-cache') . '/' . $groupFilename); $html .= tag('link', $options); } else { $options['src'] = javascript_path(sfConfig::get('app_a_assetCacheUrl', '/uploads/asset-cache') . '/' . $groupFilename); $html .= content_tag('script', '', $options); } } return $html; }
public function getPathAfterLoggingIn(sfContext $context) { $logger = Logger::getLogger('core.homepageservice'); $redirectToReferer = true; $request = $context->getRequest(); $referer = $request->getReferer(); $host = $request->getHost(); // get base url: ie something like: http://host:port/symfony/web/index.php $baseUrl = $request->getUriPrefix() . $request->getPathInfoPrefix(); if ($logger->isDebugEnabled()) { $logger->debug("referer: {$referer}, host: {$host}, base url: {$baseUrl}"); } if (strpos($referer, $this->loginPath)) { // Check whether referer is login page $redirectToReferer = false; if ($logger->isDebugEnabled()) { $logger->debug("referrer is the login page. Skipping redirect:" . $this->loginPath); } } elseif (strpos($referer, $this->validatePath)) { // Check whether referer is validate action $redirectToReferer = false; if ($logger->isDebugEnabled()) { $logger->debug("referrer is the validate action. Skipping redirect:" . $this->validatePath); } } else { if (false === strpos($referer, $baseUrl)) { // Check whether from same host $redirectToReferer = false; if ($logger->isDebugEnabled()) { $logger->debug("referrer does not have same base url. Skipping redirect"); } } } /* * Try to get action and module, skip redirecting to referrer and show homepage if: * 1) Action is not secure (probably a login related url we should not redirect to) * 2) Action is not accessible to current user. */ if ($redirectToReferer) { try { $moduleAndAction = str_replace($baseUrl, '', $referer); if ($logger->isDebugEnabled()) { $logger->debug('referrer module and action: ' . $moduleAndAction); } $params = $context->getRouting()->parse($moduleAndAction); if ($params && isset($params['module']) && isset($params['action'])) { $moduleName = $params['module']; $actionName = $params['action']; if ($logger->isDebugEnabled()) { $logger->debug("module: {$moduleName}, action: {$actionName}"); } if ($context->getController()->actionExists($moduleName, $actionName)) { $action = $context->getController()->getAction($moduleName, $actionName); if ($action instanceof sfAction) { if ($action->isSecure()) { $permissions = UserRoleManagerFactory::getUserRoleManager()->getScreenPermissions($moduleName, $actionName); if ($permissions instanceof ResourcePermission) { if ($permissions->canRead()) { return $referer; } } else { $logger->debug("action does not exist"); } } else { $logger->debug("action is not secure"); } } else { $logger->debug("action not an instance of sfAction"); } } else { $logger->debug("action does not exist"); } } else { $logger->debug("referrer does not match a route"); } } catch (Exception $e) { $logger->warn('Error when trying to get referrer action: ' . $e); } } return $this->getHomePagePath(); }
/** * Initialize cache manager * * @param sfContext $context * @param sfCache $taggingCache * @param array $options * * @see sfViewCacheManager::initialize() */ public function initialize($context, sfCache $taggingCache, $options = array()) { if (!$taggingCache instanceof sfTaggingCache) { throw new InvalidArgumentException(sprintf('Cache "%s" is not instanceof sfTaggingCache', get_class($taggingCache))); } if (!sfConfig::get('sf_cache')) { $taggingCache = new sfNoTaggingCache(); } $this->setTaggingCache($taggingCache); $this->cache = $this->getTaggingCache()->getCache(); $this->setEventDispatcher($context->getEventDispatcher()); $this->context = $context; $this->controller = $context->getController(); $this->request = $context->getRequest(); $this->routing = $context->getRouting(); $this->setOptions(array_merge(array('cache_key_use_vary_headers' => true, 'cache_key_use_host_name' => true), $options)); if (sfConfig::get('sf_web_debug')) { $this->getEventDispatcher()->connect('view.cache.filter_content', array($this, 'decorateContentWithDebug')); } // empty configuration $this->cacheConfig = array(); }
/** * Initializes this view. * * @param sfContext $context The current application context * @param string $moduleName The module name for this view * @param string $actionName The action name for this view * @param string $viewName The view name * * @return bool true, if initialization completes successfully, otherwise false */ public function initialize($context, $moduleName, $actionName, $viewName) { $this->moduleName = $moduleName; $this->actionName = $actionName; $this->viewName = $viewName; $this->context = $context; $this->dispatcher = $context->getEventDispatcher(); if (sfConfig::get('sf_logging_enabled')) { $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Initialize view for "%s/%s"', $moduleName, $actionName)))); } sfOutputEscaper::markClassAsSafe('sfForm'); $this->attributeHolder = $this->initializeAttributeHolder(); $this->parameterHolder = new sfParameterHolder(); $this->parameterHolder->add(sfConfig::get('mod_' . strtolower($moduleName) . '_view_param', array())); $request = $context->getRequest(); if (!is_null($format = $request->getRequestFormat())) { if ('html' != $format) { $this->setExtension('.' . $format . $this->getExtension()); } if ($mimeType = $request->getMimeType($format)) { $this->context->getResponse()->setContentType($mimeType); $this->setDecorator(false); } $this->dispatcher->notify(new sfEvent($this, 'view.configure_format', array('format' => $format, 'response' => $context->getResponse(), 'request' => $context->getRequest()))); } // include view configuration $this->configure(); return true; }
protected function doGeneratePdf(sfContext $context, $chartBuilder, $file) { // definition of chart builder class $this->setChartBuilder($chartBuilder); // creation of a context $context->getConfiguration()->loadHelpers('Partial'); $context->getRequest()->setRequestFormat('html'); $config = sfTCPDFPluginConfigHandler::loadConfig(); sfTCPDFPluginConfigHandler::includeLangFile($context->getUser()->getCulture()); $doc_title = $this->getName() . " Report"; $doc_subject = $this->getName() . " Report generated by Otokou"; $doc_keywords = "report, otokou"; //create new PDF document (document units are set by default to millimeters) $pdf = new sfTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(PDF_AUTHOR); $pdf->SetTitle($doc_title); $pdf->SetSubject($doc_subject); $pdf->SetKeywords($doc_keywords); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); //initialize document $pdf->AliasNbPages(); // report informations $pdf->AddPage(); $html = get_partial('report/general_info', array('report' => $this)); $pdf->writeHTML($html, true, false, true, false, ''); // vehicles overall performances $html = '<h1>Vehicles performances</h1>' . '<p>The values presented below are calculated overall the entire life period of the vehicle(s).</p>' . get_partial('report/vehicles_performances', array('vehicles' => $this->getVehicles())); $pdf->writeHTML($html, true, false, true, false, ''); // charts $pdf->AddPage(); $html = '<h1>Costs</h1>'; $pdf->writeHTML($html, true, false, true, false, ''); $counter = 0; $options = array(); $attributes = array('absolute' => true); $charts = $this->defineCharts($options, $attributes); $nc = count($charts); foreach ($charts as $c) { $counter++; //$html = get_partial('report/chart', array('chart' => $c)); //$pdf->writeHTML($html, true, false, true, false, ''); $html = '<h2>' . $c['title'] . '</h2><p>' . $c['comment'] . '</p>'; $pdf->writeHTML($html); $c['chart']->generate(); $pdf->Image($c['chart']->getChartFileSystemPath()); if ($counter < $nc) { $pdf->AddPage(); } } // Close and output PDF document $pdf->Output($file, 'F'); }