Changeset 20840

Show
Ignore:
Timestamp:
10/06/08 17:36:44 (5 years ago)
Author:
sabel
Message:

update addon

Location:
events/phpframework/sabel/trunk
Files:
1 removed
7 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/sabel/trunk/addon/acl/config/Controller.php

    r20065 r20840  
    2424    if ($this->isPublic()) return true; 
    2525     
    26     $spec   = array("(", ")", "&", "|"); 
    27     $buf    = array(); 
    28     $rule   = $this->isAllow; 
    29     $length = strlen($rule); 
    30      
    31     $prev = ""; 
    32     $next = ""; 
    33      
    34     for ($i = 0; $i < $length; $i++) { 
    35       $next = (isset($rule{$i + 1})) ? $rule{$i + 1} : ""; 
    36       $cur  = $rule{$i}; 
    37        
    38       if ($i === 0) { 
    39         if ($cur === "(") { 
    40           $buf[] = "("; 
    41         } else { 
    42           $buf[] = '"' . $cur; 
    43         } 
    44       } elseif (in_array($prev, $spec) && 
    45                 !in_array($cur, $spec)) { 
    46         $buf[] = '"' . $cur; 
    47       } elseif (in_array($next, $spec) && 
    48                 !in_array($cur, $spec)) { 
    49         $buf[] = $rule{$i} . '"'; 
    50       } else { 
    51         $buf[] = $rule{$i}; 
    52       } 
    53        
    54       $prev = $rule{$i}; 
    55     } 
    56      
    57     $rule = implode("", $buf); 
    58     $length = strlen($rule); 
    59     if ($rule{$length - 1} !== ")") { 
    60       $rule .= '"'; 
    61     } 
    62      
     26    $s = microtime(); 
     27    $rule = preg_replace('/[a-z]+/', '"$0"', $this->isAllow); 
    6328    foreach ($roles as $role) { 
    6429      $rule = str_replace('"' . $role . '"', "true", $rule); 
    6530    } 
    6631     
    67     $rule = preg_replace('/"[a-z]+"/', 'false', $rule); 
    68     $rule = str_replace(array("|", "&"), array("||", "&&"), $rule); 
     32    $rule = str_replace( 
     33      array( "|",  "&"), 
     34      array("||", "&&"), 
     35      preg_replace('/"[a-z]+"/', 'false', $rule) 
     36    ); 
     37     
    6938    eval ('$match = ' . $rule . ';'); 
    7039     
  • events/phpframework/sabel/trunk/addon/form/Addon.php

    r20065 r20840  
    1616  public function execute($bus) 
    1717  { 
    18     $bus->getProcessorList() 
    19         ->insertPrevious("action", "form", new Form_Processor("form")); 
     18     
    2019  } 
    2120} 
  • events/phpframework/sabel/trunk/addon/form/Object.php

    r20065 r20840  
    299299  } 
    300300   
     301  public function apply(array $values, array $allowCols = array()) 
     302  { 
     303    if (empty($values)) return $this; 
     304     
     305    if (empty($allowCols)) { 
     306      $allowCols = $this->getAllowColumns(); 
     307    } 
     308     
     309    $model = $this->model; 
     310    $mdlName = $model->getName(); 
     311     
     312    foreach ($values as $key => $value) { 
     313      if (strpos($key, self::NAME_SEPARATOR) === false) continue; 
     314      list ($name, $colName) = explode(self::NAME_SEPARATOR, $key); 
     315      if ($name !== $mdlName) continue; 
     316       
     317      if ($colName === "sbl_datetime" || $colName === "sbl_date") { 
     318        list ($k, ) = each($value); 
     319        if (!in_array($k, $allowCols, true)) continue; 
     320      } elseif (!in_array($colName, $allowCols, true)) { 
     321        continue; 
     322      } 
     323       
     324      if ($colName === "sbl_datetime") { 
     325        foreach ($value as $key => $date) { 
     326          if (!isset($date["second"])) $date["second"] = "00"; 
     327          if ($this->isDatetimeValuesCompleted($date)) { 
     328            $model->__set($key, $date["year"]   . "-" . 
     329                                $date["month"]  . "-" . 
     330                                $date["day"]    . " " . 
     331                                $date["hour"]   . ":" . 
     332                                $date["minute"] . ":" . 
     333                                $date["second"]); 
     334          } else { 
     335            $model->__set($key, null); 
     336          } 
     337        } 
     338      } elseif ($colName === "sbl_date") { 
     339        foreach ($value as $key => $date) { 
     340          if ($this->isDatetimeValuesCompleted($date, false)) { 
     341            $model->__set($key, "{$date["year"]}-{$date["month"]}-{$date["day"]}"); 
     342          } else { 
     343            $model->__set($key, null); 
     344          } 
     345        } 
     346      } else { 
     347        $model->__set($colName, $value); 
     348      } 
     349    } 
     350     
     351    return $this; 
     352  } 
     353   
     354  protected function isDatetimeValuesCompleted($values, $isDatetime = true) 
     355  { 
     356    $keys = array("year", "month", "day"); 
     357     
     358    if ($isDatetime) { 
     359      $keys = array_merge($keys, array("hour", "minute", "second")); 
     360    } 
     361     
     362    foreach ($keys as $key) { 
     363      if (!isset($values[$key]) || $values[$key] === "") return false; 
     364    } 
     365     
     366    return true; 
     367  } 
     368   
    301369  protected function createInputName($name) 
    302370  { 
     
    304372  } 
    305373   
    306   private function getHtmlWriter($name, $inputName, $id = null, $class = null) 
     374  protected function getHtmlWriter($name, $inputName, $id = null, $class = null) 
    307375  { 
    308376    if ($name !== "" && !in_array($name, $this->allowCols, true)) { 
  • events/phpframework/sabel/trunk/app/index/controllers/Register.php

    r20153 r20840  
    2424  { 
    2525    $this->userForm = new Form_Object("User"); 
    26     $this->form->applyPostValues($this->userForm, array("user_name", "password", "email")); 
     26    $this->userForm->apply( 
     27      $this->request->fetchPostValues(), array("user_name", "password", "email") 
     28    ); 
    2729     
    2830    $result = $this->register->preregister($this->userForm->getModel()); 
  • events/phpframework/sabel/trunk/app/index/controllers/User.php

    r20329 r20840  
    5858    if (!$this->request->isPost()) return; 
    5959     
    60     $this->form->applyPostValues($this->settingsForm, array("user_name", "email", "private_flag")); 
     60    $this->settingsForm->apply( 
     61      $this->request->fetchPostValues(), array("user_name", "email", "private_flag") 
     62    ); 
     63     
    6164    $result = $this->getLogic("user")->updateSettings($this->settingsForm->getModel()); 
    6265     
  • events/phpframework/sabel/trunk/app/logics/Register.php

    r20076 r20840  
    2121    $result = new Logics_Result(); 
    2222    $aUser->created_at = $aUser->updated_at = now(); 
    23     $aUser->password = md5($aUser->password); 
    2423     
    2524    if ($errors = $this->validateModel($aUser)) { 
     
    2827     
    2928    $actKey = md5hash(); 
     29    $aUser->password = md5($aUser->password); 
     30     
    3031    if (ENVIRONMENT === DEVELOPMENT) { 
    3132      $aUser->save(); 
  • events/phpframework/sabel/trunk/tests/unit/logics/Register.php

    r20065 r20840  
    1717    $result = $register->preregister($aUser); 
    1818    $this->isTrue($result->isFailure()); 
    19     $this->eq(2, count($result->getErrors())); 
     19    $this->eq(3, count($result->getErrors())); 
    2020    /*  ---------------------- */ 
    2121     
     
    2323    $aUser = new User(); 
    2424    $aUser->user_name = "test1"; 
     25    $aUser->password = "test"; 
    2526    $aUser->email = "abc@example.com"; 
    2627    $result = $register->preregister($aUser); 
     
    3132    $aUser = new User(); 
    3233    $aUser->user_name = "user"; 
     34    $aUser->password = "user"; 
    3335    $aUser->email = "user@example.com"; 
    3436    $result = $register->preregister($aUser); 
     
    5355    $aUser = new User(); 
    5456    $aUser->user_name = "sabel"; 
     57    $aUser->password = "sabel"; 
    5558    $aUser->email = "sabel@example.com"; 
    5659    $register->preregister($aUser);