/**
  * addRoute - prepend a route to given routing object with abstraction of
  * symfony version
  *
  * @param  sfRouting $r
  * @param  string $routeName
  * @param  string $routeUrl
  * @param  array $routeParameters
  * @return void
  */
 protected static function addRoute(sfRouting $r, $routeName, $routePattern, $routeDefaults, $routeRequirements = array(), $routeOptions = array())
 {
     if (self::$newStyleRoutes) {
         $r->prependRoute(self::ROUTE . '_' . $routeName, new sfRoute($routePattern, $routeDefaults, $routeRequirements, $routeOptions));
     } else {
         $r->prependRoute(self::ROUTE . '_' . $routeName, $routePattern, $routeDefaults, $routeRequirements);
     }
 }
 /**
  * Retrieve the singleton instance of this class.
  *
  * @return  sfRouting The sfRouting implementation instance
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new sfRouting();
     }
     return self::$instance;
 }
Ejemplo n.º 3
0
 /**
  * @see sfRouting
  */
 public function loadConfiguration()
 {
     if (!is_null($this->cache) && ($routes = $this->cache->get('symfony.routing.configuration'))) {
         $this->routes = unserialize($routes);
         $this->routesFullyLoaded = false;
     } else {
         if ($this->options['load_configuration'] && ($config = sfContext::getInstance()->getConfigCache()->checkConfig('config/routing.yml', true))) {
             $this->setRoutes(include $config);
         }
         parent::loadConfiguration();
         if (!is_null($this->cache)) {
             if (!$this->options['lazy_routes_deserialize']) {
                 $this->cache->set('symfony.routing.configuration', serialize($this->routes));
             } else {
                 $lazyMap = array();
                 foreach ($this->routes as $name => $route) {
                     if (is_string($route)) {
                         $route = $this->loadRoute($name);
                     }
                     $lazyMap[$name] = serialize($route);
                 }
                 $this->cache->set('symfony.routing.configuration', serialize($lazyMap));
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @see sfRouting
  */
 public function setDefaultParameters($parameters)
 {
     parent::setDefaultParameters($parameters);
     foreach ($this->routes as $route) {
         if (is_object($route)) {
             $route->setDefaultParameters($this->defaultParameters);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * @see sfRouting
  */
 public function loadConfiguration()
 {
     if ($this->options['load_configuration'] && ($config = sfContext::getInstance()->getConfigCache()->checkConfig('config/routing.yml', true))) {
         foreach (include $config as $name => $route) {
             $this->routes[$name] = $route;
         }
     }
     parent::loadConfiguration();
 }
 /**
  * Initialize the vars for language switch
  *
  * @access protected
  * @param  void
  * @return void
  */
 protected function initializeSwitch()
 {
     if (method_exists($this->getContext(), 'getRouting')) {
         $this->routing = $this->getContext()->getRouting();
     } else {
         $this->routing = sfRouting::getInstance();
     }
     $this->request = $this->getContext()->getRequest();
     $this->languages_available = array('en' => array('title' => 'English', 'image' => '/sfLanguageSwitch/images/flag/gb.png'));
 }
 /**
  * Executes this configuration handler.
  *
  * @param array An array of absolute filesystem path to a configuration file
  *
  * @return string Data to be written to a cache file
  *
  * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
  * @throws sfParseException If a requested configuration file is improperly formatted
  */
 public function execute($configFiles)
 {
     // parse the yaml
     $config = $this->parseYamls($configFiles);
     // connect routes
     $routes = sfRouting::getInstance();
     foreach ($config as $name => $params) {
         $routes->connect($name, $params['url'] ? $params['url'] : '/', isset($params['param']) ? $params['param'] : array(), isset($params['requirements']) ? $params['requirements'] : array());
     }
     // compile data
     $retval = sprintf("<?php\n" . "// auto-generated by sfRoutingConfigHandler\n" . "// date: %s\n\$routes = sfRouting::getInstance();\n\$routes->setRoutes(\n%s\n);\n", date('Y/m/d H:i:s'), var_export($routes->getRoutes(), 1));
     return $retval;
 }
Ejemplo n.º 8
0
 public function executeLogin()
 {
     if ($this->getRequest()->getMethod() != sfRequest::POST) {
         $r = sfRouting::getInstance();
         if ($r->getCurrentRouteName() == 'login') {
             $this->getRequest()->setAttribute('referer', $this->getRequest()->getReferer());
         } else {
             $this->getRequest()->setAttribute('referer', $r->getCurrentInternalUri());
         }
     } else {
         $this->redirect($this->getRequestParameter('referer', '@homepage'));
     }
 }
Ejemplo n.º 9
0
 /**
  * @see sfRouting
  */
 public function loadConfiguration()
 {
     if (!is_null($this->cache) && ($routes = $this->cache->get('symfony.routing.configuration'))) {
         $this->routes = unserialize($routes);
     } else {
         if ($this->options['load_configuration'] && ($config = sfContext::getInstance()->getConfigCache()->checkConfig('config/routing.yml', true))) {
             include $config;
         }
         parent::loadConfiguration();
         if (!is_null($this->cache)) {
             $this->cache->set('symfony.routing.configuration', serialize($this->routes));
         }
     }
 }
Ejemplo n.º 10
0
 public function executeList()
 {
     $type = $this->getRequestParameter('type', 'all');
     $c = $this->{'list' . $type}();
     $c->addDescendingOrderByColumn(PostPeer::CREATED_AT);
     $c->add(PostPeer::DELETED, false);
     $pager = new sfPropelPager('Post', sfConfig::get('app_post_per_page', 7));
     $pager->setCriteria($c);
     $pager->setPage($this->getRequestParameter('page', 1));
     $pager->setPeerMethod('doSelectJoinAll');
     $pager->init();
     $this->pager = $pager;
     $r = sfRouting::getInstance();
     $this->iuri = $r->getCurrentRouteName() == 'homepage' ? '@posts?page=1' : $r->getCurrentInternalUri(true);
 }
  public function execute ($filterChain)
  {
    // execute next filter
    $filterChain->execute();

    $response = $this->getContext()->getResponse();

    // execute this filter only if cache is set and no GET or POST parameters
    // execute this filter not in debug mode, only if no_script_name and for 200 response code
    if (
      (!sfConfig::get('sf_cache') || count($_GET) || count($_POST))
      ||
      (sfConfig::get('sf_debug') || !sfConfig::get('sf_no_script_name') || $response->getStatusCode() != 200)
    )
    {
      return;
    }

    // only if cache is set for the entire page
    $cacheManager = $this->getContext()->getViewCacheManager();
    $uri = sfRouting::getInstance()->getCurrentInternalUri();
    if ($cacheManager->isCacheable($uri) && $cacheManager->withLayout($uri))
    {
      // save super cache
      $request = $this->getContext()->getRequest();
      $pathInfo = $request->getPathInfo();
      $file = sfConfig::get('sf_web_dir').'/'.$this->getParameter('cache_dir', 'cache').'/'.$request->getHost().('/' == $pathInfo[strlen($pathInfo) - 1] ? $pathInfo.'index.html' : $pathInfo);
      $current_umask = umask();
      umask(0000);
      $dir = dirname($file);
      if (!is_dir($dir))
      {
        mkdir($dir, 0777, true);
      }
      file_put_contents($file, $this->getContext()->getResponse()->getContent());
      chmod($file, 0666);
      umask($current_umask);
    }
  }
 /**
  * Stops the fragment cache.
  *
  * @param string Unique fragment name
  *
  * @return boolean true, if success otherwise false
  */
 public function stop($name)
 {
     $data = ob_get_clean();
     // save content to cache
     $internalUri = sfRouting::getInstance()->getCurrentInternalUri();
     try {
         $this->set($data, $internalUri . (strpos($internalUri, '?') ? '&' : '?') . '_sf_cache_key=' . $name);
     } catch (Exception $e) {
     }
     return $data;
 }
Ejemplo n.º 13
0
<?php

// Adding polls routes if option has not been disabled in app.yml
// @see http://www.symfony-project.com/book/trunk/09-Links-and-the-Routing-System#Creating%20Rules%20Without%20routing.yml
if (sfConfig::get('app_sfPropelPollsPlugin_routes_register', true) && in_array('sfPolls', sfConfig::get('sf_enabled_modules'))) {
    $r = sfRouting::getInstance();
    # Polls list route
    $r->prependRoute('sf_propel_polls_list', '/polls', array('module' => 'sfPolls', 'action' => 'list'), array('id' => '\\d+'));
    # Poll detail (form) route
    $r->prependRoute('sf_propel_polls_detail', '/poll_detail/:id', array('module' => 'sfPolls', 'action' => 'detail'), array('id' => '\\d+'));
    # Poll results route
    $r->prependRoute('sf_propel_polls_results', '/poll_results/:id', array('module' => 'sfPolls', 'action' => 'results'), array('id' => '\\d+'));
    # Poll vote route
    $r->prependRoute('sf_propel_polls_vote', '/poll_vote', array('module' => 'sfPolls', 'action' => 'vote'), array('id' => '\\d+'));
}
Ejemplo n.º 14
0
<?php

$feedItem = new sfGeoFeedItem();
$i18n = $item['ArticleI18n'][0];
$feedItem->setTitle($i18n['name']);
$id = $item['id'];
$lang = $i18n['culture'];
$feedItem->setLink("@document_by_id_lang_slug?module=articles&id={$id}&lang={$lang}&slug=" . make_slug($i18n['name']));
$feedItem->setUniqueId(sfRouting::getInstance()->getCurrentInternalUri() . '_' . $id);
$feedItem->setAuthorName($item['creator']);
$feedItem->setPubdate(strtotime($item['creation_date']));
$data = array();
$data[] = get_paginated_value_from_list($item['categories'], 'mod_articles_categories_list');
if (isset($item['activities']) && is_string($item['activities'])) {
    $data[] = get_paginated_activities($item['activities'], true);
}
$data[] = get_paginated_value($item['article_type'], 'mod_articles_article_types_list');
$feedItem->setDescription(implode(' - ', $data));
$feed->addItem($feedItem);
Ejemplo n.º 15
0
 private static function getItemFeedLink($item, $routeName = '', $fallback_url = '')
 {
     if ($routeName) {
         if (method_exists('sfRouting', 'getInstance')) {
             $route = sfRouting::getInstance()->getRouteByName($routeName);
             $url = $route[0];
             $paramNames = $route[2];
             $defaults = $route[4];
         } else {
             $routes = sfContext::getInstance()->getRouting()->getRoutes();
             $route = $routes[substr($routeName, 1)];
             if ($route instanceof sfRoute) {
                 $url = $route->getPattern();
                 $paramNames = array_keys($route->getVariables());
                 $defaults = $route->getDefaults();
             } else {
                 $url = $route[0];
                 $paramNames = array_keys($route[2]);
                 $defaults = $route[3];
             }
         }
         // we get all parameters
         $params = array();
         foreach ($paramNames as $paramName) {
             $value = null;
             $name = ucfirst(sfInflector::camelize($paramName));
             $found = false;
             foreach (array('getFeed' . $name, 'get' . $name) as $methodName) {
                 if (method_exists($item, $methodName)) {
                     $value = $item->{$methodName}();
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 if (array_key_exists($paramName, $defaults)) {
                     $value = $defaults[$paramName];
                 } else {
                     $error = 'Cannot find a "getFeed%s()" or "get%s()" method for object "%s" to generate URL with the "%s" route';
                     $error = sprintf($error, $name, $name, get_class($item), $routeName);
                     throw new sfException($error);
                 }
             }
             $params[] = $paramName . '=' . $value;
         }
         return sfContext::getInstance()->getController()->genUrl($routeName . ($params ? '?' . implode('&', $params) : ''), true);
     }
     foreach (array('getFeedLink', 'getLink', 'getUrl') as $methodName) {
         if (method_exists($item, $methodName)) {
             return sfContext::getInstance()->getController()->genUrl($item->{$methodName}(), true);
         }
     }
     if ($fallback_url) {
         return sfContext::getInstance()->getController()->genUrl($fallback_url, true);
     } else {
         return sfContext::getInstance()->getController()->genUrl('/', true);
     }
 }
Ejemplo n.º 16
0
<?php

// auto-generated by sfRoutingConfigHandler
// date: 2015/09/01 13:56:04
$routes = sfRouting::getInstance();
$routes->setRoutes(array('homepage' => array(0 => '/', 1 => '/^[\\/]*$/', 2 => array(), 3 => array(), 4 => array('module' => 'admin', 'action' => 'index'), 5 => array(), 6 => ''), 'listmodules' => array(0 => '/listmodules', 1 => '#^/listmodules$#', 2 => array(), 3 => array(), 4 => array('module' => 'admin', 'action' => 'listmodules'), 5 => array(), 6 => ''), 'default_symfony' => array(0 => '/symfony/:action/*', 1 => '#^/symfony(?:\\/([^\\/]+))?(?:\\/(.*))?$#', 2 => array(0 => 'action'), 3 => array('action' => 1), 4 => array('module' => 'default'), 5 => array(), 6 => ''), 'default_index' => array(0 => '/:module', 1 => '#^(?:\\/([^\\/]+))?$#', 2 => array(0 => 'module'), 3 => array('module' => 1), 4 => array('action' => 'index'), 5 => array(), 6 => ''), 'default' => array(0 => '/:module/:action/*', 1 => '#^(?:\\/([^\\/]+))?(?:\\/([^\\/]+))?(?:\\/(.*))?$#', 2 => array(0 => 'module', 1 => 'action'), 3 => array('module' => 1, 'action' => 1), 4 => array(), 5 => array(), 6 => ''), 'login' => array(0 => '/login', 1 => '#^/login$#', 2 => array(), 3 => array(), 4 => array('module' => 'user', 'action' => 'login'), 5 => array(), 6 => '')));
 /**
  * Executes this filter.
  *
  * @param sfFilterChain The filter chain
  *
  * @throws <b>sfInitializeException</b> If an error occurs during view initialization.
  * @throws <b>sfViewException</b>       If an error occurs while executing the view.
  */
 public function execute($filterChain)
 {
     // get the context and controller
     $context = $this->getContext();
     $controller = $context->getController();
     // get the current action instance
     $actionEntry = $controller->getActionStack()->getLastEntry();
     $actionInstance = $actionEntry->getActionInstance();
     // get the current action information
     $moduleName = $context->getModuleName();
     $actionName = $context->getActionName();
     // get the request method
     $method = $context->getRequest()->getMethod();
     $viewName = null;
     if (sfConfig::get('sf_cache')) {
         $uri = sfRouting::getInstance()->getCurrentInternalUri();
         if (null !== $context->getResponse()->getParameter($uri . '_action', null, 'symfony/cache')) {
             // action in cache, so go to the view
             $viewName = sfView::SUCCESS;
         }
     }
     if (!$viewName) {
         if (($actionInstance->getRequestMethods() & $method) != $method) {
             // this action will skip validation/execution for this method
             // get the default view
             $viewName = $actionInstance->getDefaultView();
         } else {
             // set default validated status
             $validated = true;
             // the case of the first letter of the action is insignificant
             // get the current action validation configuration
             $validationConfigWithFirstLetterLower = $moduleName . '/' . sfConfig::get('sf_app_module_validate_dir_name') . '/' . strtolower(substr($actionName, 0, 1)) . substr($actionName, 1) . '.yml';
             $validationConfigWithFirstLetterUpper = $moduleName . '/' . sfConfig::get('sf_app_module_validate_dir_name') . '/' . ucfirst($actionName) . '.yml';
             // determine $validateFile by testing both the uppercase and lowercase
             // types of validation configurations.
             $validateFile = null;
             if (!is_null($testValidateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $validationConfigWithFirstLetterLower, true))) {
                 $validateFile = $testValidateFile;
             } else {
                 if (!is_null($testValidateFile = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name') . '/' . $validationConfigWithFirstLetterUpper, true))) {
                     $validateFile = $testValidateFile;
                 }
             }
             // load validation configuration
             // do NOT use require_once
             if (!is_null($validateFile)) {
                 // create validator manager
                 $validatorManager = new sfValidatorManager();
                 $validatorManager->initialize($context);
                 require $validateFile;
                 // process validators
                 $validated = $validatorManager->execute();
             }
             // process manual validation
             $validateToRun = 'validate' . ucfirst($actionName);
             $manualValidated = method_exists($actionInstance, $validateToRun) ? $actionInstance->{$validateToRun}() : $actionInstance->validate();
             // action is validated if:
             // - all validation methods (manual and automatic) return true
             // - or automatic validation returns false but errors have been 'removed' by manual validation
             $validated = $manualValidated && $validated || $manualValidated && !$validated && !$context->getRequest()->hasErrors();
             // register fill-in filter
             if (null !== ($parameters = $context->getRequest()->getAttribute('fillin', null, 'symfony/filter'))) {
                 $this->registerFillInFilter($filterChain, $parameters);
             }
             if ($validated) {
                 if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                     $timer = sfTimerManager::getTimer(sprintf('Action "%s/%s"', $moduleName, $actionName));
                 }
                 // execute the action
                 $actionInstance->preExecute();
                 $viewName = $actionInstance->execute();
                 if ($viewName == '') {
                     $viewName = sfView::SUCCESS;
                 }
                 $actionInstance->postExecute();
                 if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                     $timer->addTime();
                 }
             } else {
                 if (sfConfig::get('sf_logging_enabled')) {
                     $this->context->getLogger()->info('{sfFilter} action validation failed');
                 }
                 // validation failed
                 $handleErrorToRun = 'handleError' . ucfirst($actionName);
                 $viewName = method_exists($actionInstance, $handleErrorToRun) ? $actionInstance->{$handleErrorToRun}() : $actionInstance->handleError();
                 if ($viewName == '') {
                     $viewName = sfView::ERROR;
                 }
             }
         }
     }
     if ($viewName == sfView::HEADER_ONLY) {
         $context->getResponse()->setHeaderOnly(true);
         // execute next filter
         $filterChain->execute();
     } else {
         if ($viewName != sfView::NONE) {
             if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                 $timer = sfTimerManager::getTimer(sprintf('View "%s" for "%s/%s"', $viewName, $moduleName, $actionName));
             }
             // get the view instance
             $viewInstance = $controller->getView($moduleName, $actionName, $viewName);
             $viewInstance->initialize($context, $moduleName, $actionName, $viewName);
             $viewInstance->execute();
             // render the view and if data is returned, stick it in the
             // action entry which was retrieved from the execution chain
             $viewData = $viewInstance->render();
             if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
                 $timer->addTime();
             }
             if ($controller->getRenderMode() == sfView::RENDER_VAR) {
                 $actionEntry->setPresentation($viewData);
             } else {
                 // execute next filter
                 $filterChain->execute();
             }
         }
     }
 }
 protected function addNotice($terms, $from = null)
 {
     $content = $this->getContext()->getResponse()->getContent();
     $term_string = implode($terms, ', ');
     $route = $route = sfRouting::getInstance()->getCurrentInternalUri();
     $route = preg_replace('/(\\?|&)' . $this->getHighlightQs() . '=.*?(&|$)/', '$1', $route);
     $route = $this->getContext()->getController()->genUrl($route);
     $remove_string = $this->translate($this->getRemoveString(), array('%url%' => $route));
     if ($from) {
         $message = $this->translate($this->getNoticeRefererString(), array('%from%' => $from, '%keywords%' => $term_string, '%remove%' => $remove_string));
     } else {
         $message = $this->translate($this->getNoticeString(), array('%keywords%' => $term_string, '%remove%' => $remove_string));
     }
     $content = str_replace($this->getNoticeTag(), $message, $content);
     $this->getContext()->getResponse()->setContent($content);
 }
 /**
  * Executes this filter.
  *
  * @param sfFilterChain A sfFilterChain instance.
  */
 public function executeBeforeRendering()
 {
     // cache only 200 HTTP status
     if (200 != $this->response->getStatusCode()) {
         return;
     }
     $uri = sfRouting::getInstance()->getCurrentInternalUri();
     // save page in cache
     if (isset($this->cache[$uri]) && $this->cache[$uri]['page']) {
         // set some headers that deals with cache
         if ($lifetime = $this->cacheManager->getClientLifeTime($uri, 'page')) {
             $this->response->setHttpHeader('Last-Modified', $this->response->getDate(time()), false);
             $this->response->setHttpHeader('Expires', $this->response->getDate(time() + $lifetime), false);
             $this->response->addCacheControlHttpHeader('max-age', $lifetime);
         }
         // set Vary headers
         foreach ($this->cacheManager->getVary($uri, 'page') as $vary) {
             $this->response->addVaryHttpHeader($vary);
         }
         $this->setPageCache($uri);
     } else {
         if (isset($this->cache[$uri]) && $this->cache[$uri]['action']) {
             // save action in cache
             $this->setActionCache($uri);
         }
     }
     // remove PHP automatic Cache-Control and Expires headers if not overwritten by application or cache
     if ($this->response->hasHttpHeader('Last-Modified') || sfConfig::get('sf_etag')) {
         // FIXME: these headers are set by PHP sessions (see session_cache_limiter())
         $this->response->setHttpHeader('Cache-Control', null, false);
         $this->response->setHttpHeader('Expires', null, false);
         $this->response->setHttpHeader('Pragma', null, false);
     }
     // Etag support
     if (sfConfig::get('sf_etag')) {
         $etag = '"' . md5($this->response->getContent()) . '"';
         $this->response->setHttpHeader('ETag', $etag);
         if ($this->request->getHttpHeader('IF_NONE_MATCH') == $etag) {
             $this->response->setStatusCode(304);
             $this->response->setHeaderOnly(true);
             if (sfConfig::get('sf_logging_enabled')) {
                 $this->getContext()->getLogger()->info('{sfFilter} ETag matches If-None-Match (send 304)');
             }
         }
     }
     // conditional GET support
     // never in debug mode
     if ($this->response->hasHttpHeader('Last-Modified') && !sfConfig::get('sf_debug')) {
         $last_modified = $this->response->getHttpHeader('Last-Modified');
         if ($this->request->getHttpHeader('IF_MODIFIED_SINCE') == $last_modified) {
             $this->response->setStatusCode(304);
             $this->response->setHeaderOnly(true);
             if (sfConfig::get('sf_logging_enabled')) {
                 $this->getContext()->getLogger()->info('{sfFilter} Last-Modified matches If-Modified-Since (send 304)');
             }
         }
     }
 }
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
require_once $_test_dir . '/unit/sfContextMock.class.php';
class myRequest extends sfRequest
{
    function shutdown()
    {
    }
}
class fakeRequest
{
}
$t = new lime_test(54, new lime_output_color());
$context = new sfContext();
sfRouting::getInstance()->clearRoutes();
// ::newInstance()
$t->diag('::newInstance()');
$t->isa_ok(sfRequest::newInstance('myRequest'), 'myRequest', '::newInstance() takes a request class as its first parameter');
$t->isa_ok(sfRequest::newInstance('myRequest'), 'myRequest', '::newInstance() returns an instance of myRequest');
try {
    sfRequest::newInstance('fakeRequest');
    $t->fail('::newInstance() throws a sfFactoryException if the class does not extends sfRequest');
} catch (sfFactoryException $e) {
    $t->pass('::newInstance() throws a sfFactoryException if the class does not extends sfRequest');
}
// ->initialize()
$t->diag('->initialize()');
$request = sfRequest::newInstance('myRequest');
$t->is($request->getContext(), null, '->initialize() takes a sfContext object as its first argument');
$request->initialize($context, array('foo' => 'bar'));
Ejemplo n.º 21
0
 /**
  * Generates an URL from an array of parameters.
  *
  * @param mixed   An associative array of URL parameters or an internal URI as a string.
  * @param boolean Whether to generate an absolute URL
  *
  * @return string A URL to a symfony resource
  */
 public function genUrl($parameters = array(), $absolute = false)
 {
     // absolute URL or symfony URL?
     if (!is_array($parameters) && preg_match('#^[a-z]+\\://#', $parameters)) {
         return $parameters;
     }
     if (!is_array($parameters) && $parameters == '#') {
         return $parameters;
     }
     $url = '';
     if (!sfConfig::get('sf_no_script_name')) {
         $url = $this->getContext()->getRequest()->getScriptName();
     } else {
         if ($sf_relative_url_root = $this->getContext()->getRequest()->getRelativeUrlRoot()) {
             $url = $sf_relative_url_root;
         }
     }
     $route_name = '';
     $fragment = '';
     if (!is_array($parameters)) {
         // strip fragment
         if (false !== ($pos = strpos($parameters, '#'))) {
             $fragment = substr($parameters, $pos + 1);
             $parameters = substr($parameters, 0, $pos);
         }
         list($route_name, $parameters) = $this->convertUrlStringToParameters($parameters);
     }
     if (sfConfig::get('sf_url_format') == 'PATH') {
         // use PATH format
         $divider = '/';
         $equals = '/';
         $querydiv = '/';
     } else {
         // use GET format
         $divider = ini_get('arg_separator.output');
         $equals = '=';
         $querydiv = '?';
     }
     // default module
     if (!isset($parameters['module'])) {
         $parameters['module'] = sfConfig::get('sf_default_module');
     }
     // default action
     if (!isset($parameters['action'])) {
         $parameters['action'] = sfConfig::get('sf_default_action');
     }
     $r = sfRouting::getInstance();
     if ($r->hasRoutes() && ($generated_url = $r->generate($route_name, $parameters, $querydiv, $divider, $equals))) {
         $url .= $generated_url;
     } else {
         $query = http_build_query($parameters);
         if (sfConfig::get('sf_url_format') == 'PATH') {
             $query = strtr($query, ini_get('arg_separator.output') . '=', '/');
         }
         $url .= $query;
     }
     if ($absolute) {
         $request = $this->getContext()->getRequest();
         $url = 'http' . ($request->isSecure() ? 's' : '') . '://' . $request->getHost() . $url;
     }
     if ($fragment) {
         $url .= '#' . $fragment;
     }
     return $url;
 }
Ejemplo n.º 22
0
<?php

echo use_helper('I18N');
?>

<div style="margin-bottom: 15px">
  <?php 
echo format_number_choice('[0]non c\'&egrave; nessun risultato|[1] c\'&egrave; 1 risultato|(1,+Inf] ci sono %1% risultati', array('%1%' => $results), $results);
?>
  <?php 
if (deppFiltersAndSortVariablesManager::arrayHasNonzeroValue(array_values($filters))) {
    ?>
    <?php 
    echo format_number_choice('[0,1] che risponde|(1,+Inf] che rispondono', array('%1%' => $results), $results);
    ?>
    ai <b>filtri impostati</b>
    <?php 
    if (!isset($route)) {
        //$route = sfContext::getInstance()->getModuleName() . '/' . sfContext::getInstance()->getActionName();
        $route = '@' . sfRouting::getInstance()->getCurrentRouteName();
    }
    ?>
    <?php 
    echo link_to('rimuovi tutti i filtri', "{$route}" . (strpos($route, '?') ? '&' : '?') . "reset_filters=true");
    ?>
  <?php 
}
?>
</div>

Ejemplo n.º 23
0
 /**
  * Tests if the given uri is cached.
  *
  * @param string Uniform resource identifier
  * @param boolean Flag for checking the cache
  * @param boolean If have or not layout
  *
  * @param sfTestBrowser Test browser instance
  */
 public function isUriCached($uri, $boolean, $with_layout = false)
 {
     $cacheManager = $this->getContext()->getViewCacheManager();
     // check that cache is enabled
     if (!$cacheManager) {
         $this->test->ok(!$boolean, 'cache is disabled');
         return $this;
     }
     if ($uri == sfRouting::getInstance()->getCurrentInternalUri()) {
         $main = true;
         $type = $with_layout ? 'page' : 'action';
     } else {
         $main = false;
         $type = $uri;
     }
     // check layout configuration
     if ($cacheManager->withLayout($uri) && !$with_layout) {
         $this->test->fail('cache without layout');
         $this->test->skip('cache is not configured properly', 2);
     } else {
         if (!$cacheManager->withLayout($uri) && $with_layout) {
             $this->test->fail('cache with layout');
             $this->test->skip('cache is not configured properly', 2);
         } else {
             $this->test->pass('cache is configured properly');
             // check page is cached
             $ret = $this->test->is($cacheManager->has($uri), $boolean, sprintf('"%s" %s in cache', $type, $boolean ? 'is' : 'is not'));
             // check that the content is ok in cache
             if ($boolean) {
                 if (!$ret) {
                     $this->test->fail('content in cache is ok');
                 } else {
                     if ($with_layout) {
                         $response = unserialize($cacheManager->get($uri));
                         $content = $response->getContent();
                         $this->test->ok($content == $this->getResponse()->getContent(), 'content in cache is ok');
                     } else {
                         if (true === $main) {
                             $ret = unserialize($cacheManager->get($uri));
                             $content = $ret['content'];
                             $this->test->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok');
                         } else {
                             $content = $cacheManager->get($uri);
                             $this->test->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok');
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
<?php

if (sfRouting::getInstance()->getCurrentRouteName() == 'default_symfony') {
    slot('force_canonical');
    echo "\n<link rel=\"canonical\" href=\"" . url_for('@classifiche_parlamento', true) . "\" />";
    end_slot();
}
?>
<div class="row" id="tabs-container">
    <ul id="content-tabs" class="float-container tools-container">
      <li class="current">
        <h2>
          <?php 
echo "Le classifiche";
?>
  
        </h2>
      </li>
    </ul>
</div>

<div class="row">
	<div class="twelvecol">
		
		<div style="padding:5px; width:73%;"> 
		   <p class="tools-container"><a class="ico-help" href="#">come sono calcolate le classifiche</a></p>
		  		<div style="display: none;" class="help-box float-container">
		  			<div class="inner float-container">

		  				<a class="ico-close" href="#">chiudi</a><h5>come sono calcolate le classifiche ?</h5>
		  				<p>I dati sulle <strong>presenze</strong> e <strong>assenze</strong> si riferiscono alle votazioni elettroniche che si svolgono nell'Assemblea di Camera e Senato dall'inizio della legislatura. I dati dunque si riferiscono solo al totale delle presenze e assenze nelle votazioni elettroniche in Aula. Con assenza si intendono i casi di non partecipazione al voto: sia quello in cui il parlamentare è fisicamente assente (e non in missione) sia quello in cui è presente ma non vota. Purtroppo attualmente i sistemi di documentazione dei resoconti di Camera e Senato non consentono di distinguere un caso dall'altro. I regolamenti non prevedono la registrazione del motivo dell'assenza al voto del parlamentare. Non si può distinguere, pertanto, l'assenza ingiustificata da quella, ad esempio, per ragioni di salute. <br />
Ejemplo n.º 25
0
 public function getItemFeedLink($item)
 {
     if ($routeName = $this->getFeedItemsRouteName()) {
         $routing = sfRouting::getInstance();
         $route = $routing->getRouteByName($routeName);
         $url = $route[0];
         // we get all parameters
         $params = array();
         if (preg_match_all('/\\:([^\\/]+)/', $url, $matches)) {
             foreach ($matches[1] as $paramName) {
                 $value = null;
                 $name = ucfirst(sfInflector::camelize($paramName));
                 foreach (array('getFeed' . $name, 'get' . $name) as $methodName) {
                     if (method_exists($item, $methodName)) {
                         $value = $item->{$methodName}();
                     }
                 }
                 if ($value === null) {
                     $error = 'Cannot find a matching method name for "%s" parameter to generate URL for the "%s" route name';
                     $error = sprintf($error, $name, $routeName);
                     throw new sfException($error);
                 }
                 $params[] = $paramName . '=' . $value;
             }
         }
         return $this->context->getController()->genUrl($routeName . ($params ? '?' . implode('&', $params) : ''), true);
     }
     foreach (array('getFeedLink', 'getLink', 'getUrl') as $methodName) {
         if (method_exists($item, $methodName)) {
             return $this->context->getController()->genUrl($item->{$methodName}(), true);
         }
     }
     if ($this->getLink()) {
         return sfContext::getInstance()->getController()->genUrl($this->getLink(), true);
     } else {
         return $this->context->getController()->genUrl('/', true);
     }
 }
Ejemplo n.º 26
0
/**
 * Returns previously added UJS code
 *
 * @param boolean True for static code (attached in another file), false otherwise (default)
 *
 * @return string if $static=false, a JavaScript code block
 */
function get_UJS($static = false)
{
  $response = sfContext::getInstance()->getResponse();
  $response->setParameter('included', true, 'symfony/view/UJS');
  
  if ($UJS = $response->getParameter('script', false, 'symfony/view/UJS'))
  {
	  $code = sprintf("\$().ready(function(){\n%s })", $UJS);
	  if($static)
	  {
      // JavaScript code is in another file
      $key = md5(sfRouting::getInstance()->getCurrentInternalUri());
      sfContext::getInstance()->getUser()->setAttribute('UJS_'.$key, $code, 'symfony/flash');
      use_javascript(url_for('UJS/script?key='.$key).'.php');
    }
    else
    {
      // JavaScript code appears in the document
      return sprintf("<script>\n//  <![CDATA[\n%s\n//  ]]>\n</script>", $code);
    }
  }
  return '';
}
Ejemplo n.º 27
0
 protected function loadParameters()
 {
     if (get_magic_quotes_gpc()) {
         $_GET = sfToolkit::stripslashesDeep($_GET);
     }
     $this->getParameterHolder()->addByRef($_GET);
     $pathInfo = $this->getPathInfo();
     if ($pathInfo) {
         $r = sfRouting::getInstance();
         if ($r->hasRoutes()) {
             $results = $r->parse($pathInfo);
             if ($results !== null) {
                 $this->getParameterHolder()->addByRef($results);
             } else {
                 $this->setParameter('module', sfConfig::get('sf_error_404_module'));
                 $this->setParameter('action', sfConfig::get('sf_error_404_action'));
             }
         } else {
             $array = explode('/', trim($pathInfo, '/'));
             $count = count($array);
             for ($i = 0; $i < $count; $i++) {
                 if ($count > $i + 1) {
                     $this->getParameterHolder()->setByRef($array[$i], $array[++$i]);
                 }
             }
         }
     }
     if (get_magic_quotes_gpc()) {
         $_POST = sfToolkit::stripslashesDeep((array) $_POST);
     }
     $this->getParameterHolder()->addByRef($_POST);
     foreach ($this->getParameterHolder()->getAll() as $key => $value) {
         if (0 === stripos($key, '_sf_')) {
             $this->getParameterHolder()->remove($key);
             $this->setParameter($key, $value, 'symfony/request/sfWebRequest');
             unset($_GET[$key]);
         }
     }
     if (sfConfig::get('sf_logging_enabled')) {
         $this->getContext()->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true))));
     }
 }
<?php

include_partial('tabs', array('ramo' => $sf_params->get('ramo'), 'gruppi' => false));
if (sfRouting::getInstance()->getCurrentRouteName() == 'giorni_di_carica') {
    slot('force_canonical');
    if ($sf_params->get('ramo') == 'senato') {
        echo "\n<link rel=\"canonical\" href=\"" . url_for('@giorni_di_carica_senatori', true) . "\" />";
    } else {
        echo "\n<link rel=\"canonical\" href=\"" . url_for('@giorni_di_carica_deputati', true) . "\" />";
    }
    end_slot();
}
?>

<div class="row">
	<div class="twelvecol">
		
		<?php 
echo include_partial('secondLevelMenuParlamentari', array('current' => 'giorni_di_carica', 'ramo' => $sf_params->get('ramo')));
?>
	    <div class="intro-box"><p style="font-size:14px;">
	      Non manca in Italia occasione in cui non si discuta, a torto o a ragione, della necessit&agrave; del ricambio della classe politica.<br/>
	      Per quanto riguarda i <?php 
echo $ramo == 'C' ? 'deputati' : 'senatori (esclusi quelli a a vita)';
?>
 attualmente in carica abbiamo calcolato da quanto tempo ricoprono incarichi parlamentari, ovvero per quanti anni e giorni sono stati seduti sugli scranni di Montecitorio o Palazzo Madama. Il calcolo viene aggiornato quotidianamente.<br/>
	      Oltre al riepilogo complessivo ed a quello diviso per gruppi parlamentari, di seguito la lista dei primi cinquanta <?php 
echo $ramo == 'C' ? 'deputati' : 'senatori (esclusi quelli a a vita)';
?>
 "pi&ugrave; esperti" (<?php 
echo link_to('clicca qui', '@giorni_di_carica_' . ($ramo == 'C' ? 'senatori' : 'deputati')) . ' se vuoi la lista dei ' . ($ramo == 'C' ? 'senatori' : 'deputati');
 public function setDefaultParameters($parameters)
 {
     parent::setDefaultParameters($parameters);
     $this->defaultParamsDirty = true;
 }
Ejemplo n.º 30
0
 /**
  * Loads GET, PATH_INFO and POST data into the parameter list.
  *
  */
 protected function loadParameters()
 {
     // merge GET parameters
     if (get_magic_quotes_gpc()) {
         $_GET = sfToolkit::stripslashesDeep($_GET);
     }
     $this->getParameterHolder()->addByRef($_GET);
     $pathInfo = $this->getPathInfo();
     if ($pathInfo) {
         // routing map defined?
         $r = sfRouting::getInstance();
         if ($r->hasRoutes()) {
             $results = $r->parse($pathInfo);
             if ($results !== null) {
                 $this->getParameterHolder()->addByRef($results);
             } else {
                 $this->setParameter('module', sfConfig::get('sf_error_404_module'));
                 $this->setParameter('action', sfConfig::get('sf_error_404_action'));
             }
         } else {
             $array = explode('/', trim($pathInfo, '/'));
             $count = count($array);
             for ($i = 0; $i < $count; $i++) {
                 // see if there's a value associated with this parameter,
                 // if not we're done with path data
                 if ($count > $i + 1) {
                     $this->getParameterHolder()->setByRef($array[$i], $array[++$i]);
                 }
             }
         }
     }
     $this->filesInfos = $this->convertFileInformation($_FILES);
     // merge POST parameters
     if (get_magic_quotes_gpc()) {
         $_POST = sfToolkit::stripslashesDeep((array) $_POST);
     }
     $this->getParameterHolder()->addByRef($_POST);
     // move symfony parameters in a protected namespace (parameters prefixed with _sf_)
     foreach ($this->getParameterHolder()->getAll() as $key => $value) {
         if (0 === stripos($key, '_sf_')) {
             $this->getParameterHolder()->remove($key);
             $this->setParameter($key, $value, 'symfony/request/sfWebRequest');
             unset($_GET[$key]);
         }
     }
     if (sfConfig::get('sf_logging_enabled')) {
         $this->getContext()->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true))));
     }
 }