Share Pastebin
Guest
Public paste!

Stefano

By: a guest | Mar 2nd, 2009 | Syntax: None | Size: 6.54 KB | Hits: 105 | Expires: Never
Copy text to clipboard
  1. Index: fValidation.php
  2. ===================================================================
  3. --- fValidation.php     (revision 520)
  4. +++ fValidation.php     (working copy)
  5.  -68,6 +68,14 @@
  6.          * @var array
  7.          */
  8.         private $email_fields = array();
  9. +
  10. +       /**
  11. +        * Fields with custom formatting
  12. +        *
  13. +        * @var array
  14. +        */
  15. +       private $custom_fields = array();
  16. +
  17.        
  18.         /**
  19.          * Fields that will be included in email headers and should be checked for email injection
  20.  -149,8 +157,30 @@
  21.                 }
  22.                 $this->email_fields = array_merge($this->email_fields, $args);
  23.         }
  24.  
  25. +       public function addCustomFields($args)
  26. +       {
  27. +               foreach ($args as $name => $params) {
  28. +                       if (!self::stringlike($name)) {
  29. +                               throw new fProgrammerException(
  30. +                                       'The field specified, %s, does not appear to be a valid field name',
  31. +                                       $name
  32. +                               );
  33. +                       }
  34. +               }
  35. +               $this->custom_fields = array_merge($this->custom_fields, $args);
  36. +       }
  37. +
  38.        
  39. -      
  40.         /**
  41.          * Adds form fields to be checked for email injection
  42.          *
  43.  -269,7 +299,7 @@
  44.                        
  45.                         if (self::stringlike($value) && !$is_valid) {
  46.                                 $messages[] = self::compose(
  47. -                                       '%s: Please enter a date',
  48. +                                       '<strong>%s</strong>: Please enter a date',
  49.                                         fGrammar::humanize($date_field)
  50.                                 );
  51.                         }
  52.  -289,14 +319,42 @@
  53.                         $value = trim(fRequest::get($email_field));
  54.                         if (self::stringlike($value) && !preg_match(fEmail::EMAIL_REGEX, $value)) {
  55.                                 $messages[] = self::compose(
  56. -                                       '%s: Please enter an email address in the form name@example.com',
  57. +                                       '<strong>%s</strong>: Please enter an email address in the form name@example.com',
  58.                                         fGrammar::humanize($email_field)
  59.                                 );
  60.                         }
  61.                 }
  62.         }
  63.        
  64. +       /**
  65. +        * Validates the custom fields
  66. +        *
  67. +        * @param  array &$messages  The messages to display to the user
  68. +        * @return void
  69. +        */
  70. +       private function checkCustomFields(&$messages)
  71. +       {
  72. +               foreach ($this->custom_fields as $name => $params) {
  73. +                       $value = trim(fRequest::get($name));
  74. +                      
  75. +                       if (is_array($params)) {
  76. +                               $validation = $params['validation'];
  77. +                               $message = $params['message'];
  78. +                       } else {
  79. +                               $validation = $params;
  80. +                       }
  81. +                      
  82. +                       if (self::stringlike($value) && !preg_match($validation, $value)) {
  83. +                               $messages[] = self::compose(
  84. +                                       '<strong>%s</strong>: %s',
  85. +                                       fGrammar::humanize($name),
  86. +                                       isset($message)?$message:"Please enter a valid value"
  87. +                               );
  88. +                       }
  89. +               }
  90. +       }
  91.        
  92. +      
  93.         /**
  94.          * Validates email header fields to ensure they don't have newline characters (which allow for email header injection)
  95.          *
  96.  -308,7 +366,7 @@
  97.                 foreach ($this->email_header_fields as $email_header_field) {
  98.                         if (preg_match('#\r|\n#', fRequest::get($email_header_field))) {
  99.                                 $messages[] = self::compose(
  100. -                                       '%s: Line breaks are not allowed',
  101. +                                       '<strong>%s</strong>: Line breaks are not allowed',
  102.                                         fGrammar::humanize($email_header_field)
  103.                                 );
  104.                         }
  105.  -329,7 +387,7 @@
  106.                         if (is_numeric($key) && is_string($required_field)) {
  107.                                 if (!self::hasValue($required_field)) {
  108.                                         $messages[] = self::compose(
  109. -                                               '%s: Please enter a value',
  110. +                                               '<strong>%s</strong>: Please enter a value',
  111.                                                 fGrammar::humanize($required_field)
  112.                                         );
  113.                                 }
  114.  -346,7 +404,7 @@
  115.                                 if (!$found) {
  116.                                         $required_field = array_map(array('fGrammar', 'humanize'), $required_field);
  117.                                         $messages[] = self::compose(
  118. -                                               '%s: Please enter at least one',
  119. +                                               '<strong>%s</strong>: Please enter at least one',
  120.                                                 join(', ', $required_field)
  121.                                         );
  122.                                 }
  123.  -359,7 +417,7 @@
  124.                                 foreach ($required_field as $individual_field) {
  125.                                         if (!self::hasValue($individual_field)) {
  126.                                                 $messages[] = self::compose(
  127. -                                                       '%s: Please enter a value',
  128. +                                                       '<strong>%s</strong>: Please enter a value',
  129.                                                         fGrammar::humanize($individual_field)
  130.                                                 );
  131.                                         }
  132.  -381,7 +439,7 @@
  133.                         $value = trim(fRequest::get($url_field));
  134.                         if (self::stringlike($value) && !preg_match('#^https?://[^ ]+$#iD', $value)) {
  135.                                 $messages[] = self::compose(
  136. -                                       '%s: Please enter a URL in the form http://www.example.com/page',
  137. +                                       '<strong>%s</strong>: Please enter a URL in the form http://www.example.com/page',
  138.                                         fGrammar::humanize($url_field)
  139.                                 );
  140.                         }
  141.  -425,7 +483,9 @@
  142.                           !$this->required_fields &&
  143.                           !$this->email_fields &&
  144.                           !$this->date_fields &&
  145. -                         !$this->url_fields) {
  146. +                         !$this->url_fields &&
  147. +                               !$this->custom_fields
  148. +                       ) {
  149.                         throw new fProgrammerException(
  150.                                 'No fields have been set to be validated'
  151.                         );
  152.  -438,6 +498,7 @@
  153.                 $this->checkEmailFields($messages);
  154.                 $this->checkEmailHeaderFields($messages);
  155.                 $this->checkURLFields($messages);
  156. +               $this->checkCustomFields($messages);
  157.                
  158.                 if ($messages) {
  159.                         if (class_exists('fText', FALSE)) {
  160. Index: fActiveRecord.php
  161. ===================================================================
  162. --- fActiveRecord.php   (revision 520)
  163. +++ fActiveRecord.php   (working copy)
  164.  -1239,6 +1239,38 @@
  165.                 );
  166.         }
  167.        
  168. +       public function populateRequest()
  169. +       {
  170. +               if (fORM::getActiveRecordMethod($this, 'populateRequest')) {
  171. +                       return $this->__call('populateRequest', array());
  172. +               }
  173. +              
  174. +               fORM::callHookCallbacks(
  175. +                       $this,
  176. +                       'pre::populateRequest()',
  177. +                       $this->values,
  178. +                       $this->old_values,
  179. +                       $this->related_records,
  180. +                       $this->cache
  181. +               );
  182. +              
  183. +               $table = fORM::tablize($this);
  184. +              
  185. +               $column_info = fORMSchema::retrieve()->getColumnInfo($table);
  186. +               foreach ($column_info as $column => $info) {
  187. +                       $method = 'get' . fGrammar::camelize($column, TRUE);
  188. +                       fRequest::set($column, $this->$method());
  189. +               }
  190. +              
  191. +               fORM::callHookCallbacks(
  192. +                       $this,
  193. +                       'post::populateRequest()',
  194. +                       $this->values,
  195. +                       $this->old_values,
  196. +                       $this->related_records,
  197. +                       $this->cache
  198. +               );
  199. +       }
  200.        
  201.         /**
  202.          * Retrieves a value from the record and prepares it for output into html.
  203. Index: fMessaging.php
  204. ===================================================================
  205. --- fMessaging.php      (revision 520)
  206. +++ fMessaging.php      (working copy)
  207.  -32,7 +32,20 @@
  208.          */
  209.         static public function check($name, $recipient)
  210.         {
  211. -               return fSession::get($name, NULL, __CLASS__ . '::' . $recipient . '::') !== NULL;
  212. +               // Find all messages if * is specified
  213. +               if (is_string($name) && $name == '*') {
  214. +                       fSession::open();
  215. +                       $prefix = __CLASS__ . '::' . $recipient . '::';
  216. +                       $keys   = array_keys($_SESSION);
  217. +                       $name   = array();
  218. +                       foreach ($keys as $key) {
  219. +                               if (strpos($key, $prefix) === 0) {
  220. +                                       return true;
  221. +                               }
  222. +                       }
  223. +               } else {
  224. +                       return fSession::get($name, NULL, __CLASS__ . '::' . $recipient . '::') !== NULL;
  225. +               }
  226.         }