- Index: fValidation.php
- ===================================================================
- --- fValidation.php (revision 520)
- +++ fValidation.php (working copy)
- -68,6 +68,14 @@
- * @var array
- */
- private $email_fields = array();
- +
- + /**
- + * Fields with custom formatting
- + *
- + * @var array
- + */
- + private $custom_fields = array();
- +
- /**
- * Fields that will be included in email headers and should be checked for email injection
- -149,8 +157,30 @@
- }
- $this->email_fields = array_merge($this->email_fields, $args);
- }
- + public function addCustomFields($args)
- + {
- + foreach ($args as $name => $params) {
- + if (!self::stringlike($name)) {
- + throw new fProgrammerException(
- + 'The field specified, %s, does not appear to be a valid field name',
- + $name
- + );
- + }
- + }
- + $this->custom_fields = array_merge($this->custom_fields, $args);
- + }
- +
- -
- /**
- * Adds form fields to be checked for email injection
- *
- -269,7 +299,7 @@
- if (self::stringlike($value) && !$is_valid) {
- $messages[] = self::compose(
- - '%s: Please enter a date',
- + '<strong>%s</strong>: Please enter a date',
- fGrammar::humanize($date_field)
- );
- }
- -289,14 +319,42 @@
- $value = trim(fRequest::get($email_field));
- if (self::stringlike($value) && !preg_match(fEmail::EMAIL_REGEX, $value)) {
- $messages[] = self::compose(
- - '%s: Please enter an email address in the form name@example.com',
- + '<strong>%s</strong>: Please enter an email address in the form name@example.com',
- fGrammar::humanize($email_field)
- );
- }
- }
- }
- + /**
- + * Validates the custom fields
- + *
- + * @param array &$messages The messages to display to the user
- + * @return void
- + */
- + private function checkCustomFields(&$messages)
- + {
- + foreach ($this->custom_fields as $name => $params) {
- + $value = trim(fRequest::get($name));
- +
- + if (is_array($params)) {
- + $validation = $params['validation'];
- + $message = $params['message'];
- + } else {
- + $validation = $params;
- + }
- +
- + if (self::stringlike($value) && !preg_match($validation, $value)) {
- + $messages[] = self::compose(
- + '<strong>%s</strong>: %s',
- + fGrammar::humanize($name),
- + isset($message)?$message:"Please enter a valid value"
- + );
- + }
- + }
- + }
- +
- /**
- * Validates email header fields to ensure they don't have newline characters (which allow for email header injection)
- *
- -308,7 +366,7 @@
- foreach ($this->email_header_fields as $email_header_field) {
- if (preg_match('#\r|\n#', fRequest::get($email_header_field))) {
- $messages[] = self::compose(
- - '%s: Line breaks are not allowed',
- + '<strong>%s</strong>: Line breaks are not allowed',
- fGrammar::humanize($email_header_field)
- );
- }
- -329,7 +387,7 @@
- if (is_numeric($key) && is_string($required_field)) {
- if (!self::hasValue($required_field)) {
- $messages[] = self::compose(
- - '%s: Please enter a value',
- + '<strong>%s</strong>: Please enter a value',
- fGrammar::humanize($required_field)
- );
- }
- -346,7 +404,7 @@
- if (!$found) {
- $required_field = array_map(array('fGrammar', 'humanize'), $required_field);
- $messages[] = self::compose(
- - '%s: Please enter at least one',
- + '<strong>%s</strong>: Please enter at least one',
- join(', ', $required_field)
- );
- }
- -359,7 +417,7 @@
- foreach ($required_field as $individual_field) {
- if (!self::hasValue($individual_field)) {
- $messages[] = self::compose(
- - '%s: Please enter a value',
- + '<strong>%s</strong>: Please enter a value',
- fGrammar::humanize($individual_field)
- );
- }
- -381,7 +439,7 @@
- $value = trim(fRequest::get($url_field));
- if (self::stringlike($value) && !preg_match('#^https?://[^ ]+$#iD', $value)) {
- $messages[] = self::compose(
- - '%s: Please enter a URL in the form http://www.example.com/page',
- + '<strong>%s</strong>: Please enter a URL in the form http://www.example.com/page',
- fGrammar::humanize($url_field)
- );
- }
- -425,7 +483,9 @@
- !$this->required_fields &&
- !$this->email_fields &&
- !$this->date_fields &&
- - !$this->url_fields) {
- + !$this->url_fields &&
- + !$this->custom_fields
- + ) {
- throw new fProgrammerException(
- 'No fields have been set to be validated'
- );
- -438,6 +498,7 @@
- $this->checkEmailFields($messages);
- $this->checkEmailHeaderFields($messages);
- $this->checkURLFields($messages);
- + $this->checkCustomFields($messages);
- if ($messages) {
- if (class_exists('fText', FALSE)) {
- Index: fActiveRecord.php
- ===================================================================
- --- fActiveRecord.php (revision 520)
- +++ fActiveRecord.php (working copy)
- -1239,6 +1239,38 @@
- );
- }
- + public function populateRequest()
- + {
- + if (fORM::getActiveRecordMethod($this, 'populateRequest')) {
- + return $this->__call('populateRequest', array());
- + }
- +
- + fORM::callHookCallbacks(
- + $this,
- + 'pre::populateRequest()',
- + $this->values,
- + $this->old_values,
- + $this->related_records,
- + $this->cache
- + );
- +
- + $table = fORM::tablize($this);
- +
- + $column_info = fORMSchema::retrieve()->getColumnInfo($table);
- + foreach ($column_info as $column => $info) {
- + $method = 'get' . fGrammar::camelize($column, TRUE);
- + fRequest::set($column, $this->$method());
- + }
- +
- + fORM::callHookCallbacks(
- + $this,
- + 'post::populateRequest()',
- + $this->values,
- + $this->old_values,
- + $this->related_records,
- + $this->cache
- + );
- + }
- /**
- * Retrieves a value from the record and prepares it for output into html.
- Index: fMessaging.php
- ===================================================================
- --- fMessaging.php (revision 520)
- +++ fMessaging.php (working copy)
- -32,7 +32,20 @@
- */
- static public function check($name, $recipient)
- {
- - return fSession::get($name, NULL, __CLASS__ . '::' . $recipient . '::') !== NULL;
- + // Find all messages if * is specified
- + if (is_string($name) && $name == '*') {
- + fSession::open();
- + $prefix = __CLASS__ . '::' . $recipient . '::';
- + $keys = array_keys($_SESSION);
- + $name = array();
- + foreach ($keys as $key) {
- + if (strpos($key, $prefix) === 0) {
- + return true;
- + }
- + }
- + } else {
- + return fSession::get($name, NULL, __CLASS__ . '::' . $recipient . '::') !== NULL;
- + }
- }
