Development

Changeset 4972

You must first sign up to be able to contribute.

Changeset 4972

Show
Ignore:
Timestamp:
09/04/07 09:59:17 (6 years ago)
Author:
mahono
Message:

* new feature: children can be secured now using new parameters 'is_secure' and 'credentials', see README
* small BC break in area class: renamed 'config' setting of actions into 'params' (but this does probably not break your code as it is internal stuff)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSimplePageControllerPlugin/README

    r4078 r4972  
    33== Abstract == 
    44 
    5 This plugin adds enables to work with pages and page areas. You can define areas in your layout template and fill them with arbitrary actions and components. 
     5This plugin enables to work with pages and page areas. You can define areas in your layout template and fill them with arbitrary actions and components. 
    66You can turn an action into a page. Be aware that any "page action" is no longer an action (in the symfony way) but a container for child actions/components/partials. 
     7Each child can be secured using credentials, see below for an example. 
    78 
    89 
     
    6263children: 
    6364  main: # area name 
    64     c1: # child name 
     65    c11: # child name 
    6566      module: user 
    66       action: login # this adds an action by getPresentationFor() to the area 
    67       params: # you can set optional config values here for each action 
     67      action: login      # this adds an action by getPresentationFor() to the area 
     68      params:            # you can set optional config values here for each action 
    6869        p1: true 
     70    c12: 
     71      module: admin 
     72      component: contextlinks 
     73      is_secure: on            # this child is only displayed if user is authenticated 
     74      credentials: admin       # and only if user has admin credential 
    6975 
    7076  sidebar: # area name 
    71     c1: # child name 
     77    c21: # child name 
    7278      module: gadget 
    73       component: login_about # this adds a component by get_component() to the area 
     79      component: login_about   # this adds a component by get_component() to the area 
     80    c22: 
     81      module: tellafriend 
     82      component: box 
     83      is_secure: on            # this child is only displayed if user is authenticated 
    7484}}} 
    7585 
  • plugins/sfSimplePageControllerPlugin/lib/sfSimplePageArea.php

    r4318 r4972  
    3939   * 
    4040   */ 
    41   public function addAction($label, $moduleName, $actionName, $viewName = null, $config = array()) 
     41  public function addAction($label, $moduleName, $actionName, $viewName = null, $params = array()) 
    4242  { 
    4343    $this->label($label); 
     
    4848      'action' => $actionName, 
    4949      'view'   => $viewName, 
    50       'config' => $config 
     50      'params' => $params 
    5151    ); 
    5252 
    5353    // set config so that we can access it later in the action 
    54     if (!empty($config)) 
     54    if (!empty($params)) 
    5555    { 
    56       sfConfig::set('sf_simplepage_child_' . $this->areaName . '_' . $label, $config); 
     56      sfConfig::set('sf_simplepage_child_' . $this->areaName . '_' . $label, $params); 
    5757    } 
    5858 
     
    6565   * Same parameters like include_component() and get_component() 
    6666   */ 
    67   public function addComponent($label, $moduleName, $componentName, $vars = array()
     67  public function addComponent($label, $moduleName, $componentName, $vars = array(), $params = array()
    6868  { 
    6969    $this->label($label); 
     
    7373      'module'    => $moduleName, 
    7474      'component' => $componentName, 
    75       'vars'      => $vars 
     75      'vars'      => $vars, 
     76      'params'    => $params 
    7677    ); 
     78 
     79    // set config so that we can access it later in the action 
     80    if (!empty($params)) 
     81    { 
     82      sfConfig::set('sf_simplepage_child_' . $this->areaName . '_' . $label, $params); 
     83    } 
    7784 
    7885    $this->hasComponent = true; 
     
    9198      'type'     => self::PARTIAL, 
    9299      'template' => $templateName, 
    93       'vars'     => $vars 
     100      'vars'     => $vars, 
     101      'params'   => $params 
    94102    ); 
     103 
     104    // set config so that we can access it later in the action 
     105    if (!empty($params)) 
     106    { 
     107      sfConfig::set('sf_simplepage_child_' . $this->areaName . '_' . $label, $params); 
     108    } 
    95109 
    96110    $this->hasPartial = true; 
     
    103117  public function render() 
    104118  { 
    105     if ($this->hasAction) 
    106     { 
    107       $context = sfContext::getInstance(); 
    108       $controller = $context->getController(); 
    109     } 
     119    $context = sfContext::getInstance(); 
     120    $controller = $context->getController(); 
     121    $user = $context->getUser(); 
    110122 
    111123    if ($this->hasComponent || $this->hasPartial) 
     
    120132    foreach ($this->contents as $label => $part) 
    121133    { 
     134      if ($part['params']['is_secure'] && !$user->isAuthenticated()) 
     135      { 
     136        continue; 
     137      } 
     138 
     139      if ($part['params']['credentials'] && !$user->hasCredential($part['params']['credentials'])) 
     140      { 
     141        continue; 
     142      } 
     143 
    122144      sfConfig::set('sf_simplepage_current_child', $label); 
    123145 
  • plugins/sfSimplePageControllerPlugin/lib/sfSimplePageConfigHandler.php

    r4318 r4972  
    7070        } 
    7171 
     72        // check if there are security settings in 'root level' 
     73        // and put them into 'params' 
     74        if (isset($conf['is_secure'])) 
     75        { 
     76          $conf['params']['is_secure'] = $conf['is_secure']; 
     77        } 
     78 
     79        if (isset($conf['credentials'])) 
     80        { 
     81          $conf['params']['credentials'] = $conf['credentials']; 
     82        } 
     83 
     84        // reset security settings if not set yet 
     85        if (!isset($conf['params']['is_secure'])) 
     86        { 
     87          $conf['params']['is_secure'] = false; 
     88        } 
     89 
     90        if (!isset($conf['params']['credentials'])) 
     91        { 
     92          $conf['params']['credentials'] = false; 
     93        } 
     94 
    7295        // template vars 
    7396        if (empty($conf['vars'])) 
     
    85108        { 
    86109          $code[] = "\$area->addComponent('{$childId}', '{$conf['module']}', '{$conf['component']}', " . 
    87             var_export($conf['vars'], true) . ');'; 
     110            var_export($conf['vars'], true) . ', ' . var_export($conf['params'], true) . ');'; 
    88111        } 
    89112        elseif (!empty($conf['partial'])) 
     
    93116            $conf['partial'] = $conf['module'] . '/' . $conf['partial']; 
    94117          } 
    95           $code[] = "\$area->addPartial('{$childId}', '{$conf['partial']}', " .  var_export($conf['vars'], true) . ');'; 
     118          $code[] = "\$area->addPartial('{$childId}', '{$conf['partial']}', " . 
     119            var_export($conf['vars'], true) . ', ' . var_export($conf['params'], true) . ');'; 
    96120        } 
    97121        else