/**
  * Fetch recipient data.
  *
  * @todo bugtesting and error handling
  * @return array
  */
 public function getSlice()
 {
     $authors = $this->grab();
     $return['total-entries'] = $this->getCount();
     $pages = (int) $return['total-entries'] / (int) $this->dsParamLIMIT;
     $return['total-pages'] = round($pages);
     $return['remaining-pages'] = max(0, (int) $return['total-pages'] - (int) $this->dsParamSTARTPAGE);
     $return['remaining-entries'] = max(0, (int) $return['total-entries'] - (int) $this->dsParamSTARTPAGE * (int) $this->dsParamLIMIT);
     $return['entries-per-page'] = $this->dsParamLIMIT;
     $return['start'] = ((int) $this->dsParamSTARTPAGE - 1) * (int) $this->dsParamLIMIT + 1;
     $return['current-page'] = (int) $this->dsParamSTARTPAGE;
     require TOOLKIT . '/util.validators.php';
     foreach ($authors as $author) {
         $return['records'][] = array('id' => $author->get('id'), 'name' => $author->get('first_name') . ' ' . $author->get('last_name'), 'email' => $author->get('email'), 'valid' => General::validateString($author->get('email'), $validators['email']) ? true : false);
     }
     if ($this->newsletter_id !== NULL) {
         $newsletter = EmailNewsletterManager::create($this->newsletter_id);
         if (is_a($newsletter, 'EmailNewsletter')) {
             foreach ($return['records'] as $recipient) {
                 $newsletter->_markRecipient($recipient['email'], 'idle');
             }
         }
     }
     return $return;
 }
 /**
  * Fetch generated recipient data.
  *
  * Returns parsed recipient data. This means the xslt provided by the user
  * will be ran on the raw data, returning a name and email direcly useable
  * by the email API.
  *
  * This is the preferred way of getting recipient data.
  *
  * @todo bugtesting and error handling
  * @return array
  */
 public function getSlice()
 {
     $entries = $this->grab();
     $return['total-entries'] = (string) $entries['total-entries'];
     $return['total-pages'] = (string) $entries['total-pages'];
     $return['remaining-pages'] = (string) $entries['remaining-pages'];
     $return['remaining-entries'] = (string) $entries['remaining-entries'];
     $return['entries-per-page'] = (string) $entries['limit'];
     $return['start'] = (string) $entries['start'];
     $return['current-page'] = (string) $this->dsParamSTARTPAGE;
     $field_ids = array();
     $xsltproc = new XsltProcess();
     foreach ($this->nameFields as $nameField) {
         $field_ids[] = FieldManager::fetchFieldIDFromElementName($nameField, $this->getSource());
     }
     $email_field_id = FieldManager::fetchFieldIDFromElementName($this->emailField, $this->getSource());
     require TOOLKIT . '/util.validators.php';
     foreach ((array) $entries['records'] as $entry) {
         $entry_data = $entry->getData();
         $element = new XMLElement('entry');
         $name = '';
         $email = '';
         foreach ($entry_data as $field_id => $data) {
             if (in_array($field_id, $field_ids)) {
                 $field = FieldManager::fetch($field_id);
                 $field->appendFormattedElement($element, $data);
             }
             if ($field_id == $email_field_id) {
                 $email = $data['value'];
             }
         }
         $name = trim($xsltproc->process($element->generate(), $this->nameXslt));
         if (!empty($email)) {
             $return['records'][] = array('id' => $entry->get('id'), 'email' => $email, 'name' => $name, 'valid' => General::validateString($email, $validators['email']) ? true : false);
         }
     }
     if ($this->newsletter_id !== NULL) {
         $newsletter = EmailNewsletterManager::create($this->newsletter_id);
         if (is_a($newsletter, 'EmailNewsletter')) {
             foreach ($return['records'] as $recipient) {
                 $newsletter->_markRecipient($recipient['email'], 'idle');
             }
         }
     }
     return $return;
 }
Пример #3
0
 /**
  * Creates a new entry for each valid file in the `$target_section`
  */
 public function commitFiles()
 {
     $entryManager = new EntryManager(Administration::instance());
     $section = $this->target_section;
     // This is the default field instances that will populated with data.
     $entries = array();
     $fields = array('upload' => $this->target_field, 'name' => null, 'section' => null);
     foreach ($section->fetchFields() as $field) {
         if (General::validateString($field->get('type'), Extension_BulkImporter::$supported_fields['name']) && is_null($fields['name'])) {
             $fields['name'] = $field;
         }
         if (General::validateString($field->get('type'), Extension_BulkImporter::$supported_fields['section']) && is_null($fields['section'])) {
             $fields['section'] = $field;
         }
     }
     foreach ($this->files as $file) {
         $path = '/';
         if ($this->preserve_subdirectories) {
             $path = dirname(substr($file->location, strlen($this->extracted_directory)));
             if ($path != '/') {
                 $path .= '/';
             }
         } else {
             if ($this->archive_is_parent) {
                 $path = '/' . $this->extracted_archive . '/';
             }
         }
         $final_destination = preg_replace("/^\\/workspace/", '', $this->target_field->get('destination')) . $path . $file->rawname;
         if (!$file->isValid($this->target_field, $final_destination)) {
             continue;
         }
         $_post = array();
         $entry = $entryManager->create();
         $entry->set('section_id', $section->get('id'));
         $entry->set('author_id', Administration::instance()->Author->get('id'));
         // Set the Name
         if (!is_null($fields['name'])) {
             $_post[$fields['name']->get('element_name')] = $file->name;
         }
         // Set the Upload Field
         if (is_null($fields['upload'])) {
             throw new Exception(__('No valid upload field found in the <code>%s</code>', array($section->get('name'))));
         }
         $_post[$this->target_field->get('element_name')] = $final_destination;
         // Cache some info, before we move file
         // https://github.com/brendo/bulkimporter/pull/7#issuecomment-1105691
         $meta = array('size' => $file->size, 'mimetype' => $file->mimetype, 'meta' => serialize($this->target_field->getMetaInfo($file->location, $file->mimetype)));
         // Move the image from it's bulk-imported location
         $path = WORKSPACE . dirname($final_destination);
         if (!file_exists($path)) {
             General::realiseDirectory($path);
             chmod($path, intval(0755, 8));
         }
         if (rename($file->location, WORKSPACE . $final_destination)) {
             chmod(WORKSPACE . $final_destination, intval(0755, 8));
         }
         $errors = array();
         //	Check all the fields that they are correct
         if (__ENTRY_FIELD_ERROR__ == $entry->checkPostData($_post, $errors)) {
             if (!empty($errors)) {
                 $file->setErrors($errors);
             }
             continue;
         }
         if (__ENTRY_OK__ == $entry->setDataFromPost($_post, $errors, false, false)) {
             //	Because we can't upload the file using the inbuilt function
             //	we have to fake the expected output
             $upload = $entry->getData($this->target_field->get('id'));
             foreach ($meta as $key => $value) {
                 if (empty($upload[$key])) {
                     $upload[$key] = $value;
                 }
             }
             $entry->setData($this->target_field->get('id'), $upload);
             /**
              * Just prior to creation of an Entry
              *
              * @delegate EntryPreCreate
              * @param string $context
              * '/publish/new/'
              * @param Section $section
              * @param Entry $entry
              * @param array $fields
              */
             Symphony::ExtensionManager()->notifyMembers('EntryPreCreate', '/publish/new/', array('section' => $section, 'entry' => &$entry, 'fields' => &$_post));
             if ($entry->commit()) {
                 $file->setUploaded();
                 $entries[$final_destination] = $entry->get('id');
                 /**
                  * Creation of an Entry. New Entry object is provided.
                  *
                  * @delegate EntryPostCreate
                  * @param string $context
                  * '/publish/new/'
                  * @param Section $section
                  * @param Entry $entry
                  * @param array $fields
                  */
                 Symphony::ExtensionManager()->notifyMembers('EntryPostCreate', '/publish/new/', array('section' => $section, 'entry' => $entry, 'fields' => $_post));
             }
         } else {
             $file->setErrors(__('Could not save entry in the <code>%s</code>', array($section->get('name'))));
         }
     }
     // Set the Section Association
     if (!empty($entries) && !is_null($this->linked_entry['linked-entry'])) {
         $entry = current($entryManager->fetch($this->linked_entry['linked-entry']));
         // Linked field, process the array of ID's to add
         $field = $entryManager->fieldManager->fetch($this->linked_entry['linked-field']);
         $result = $field->processRawFieldData($entries, $s, false, $entry->get('id'));
         // Get the current linked entries and merge with the new ones
         $existing_values = $entry->getData($this->linked_entry['linked-field']);
         if (is_array($existing_values['relation_id'])) {
             $result['relation_id'] = array_merge_recursive($result['relation_id'], $existing_values['relation_id']);
         }
         $entry->setData($this->linked_entry['linked-field'], $result);
         $entry->commit();
     }
     $this->entries = $entries;
 }
 protected function _parseNameAndEmail(&$string)
 {
     $string = trim($string);
     if (strstr($string, '<')) {
         $name = trim(strstr($string, '<', true), "\" \t\n\r\v");
         $email = trim(strstr($string, '<'), "<> \t\n\r\v");
     } else {
         $email = trim($string, " \t\n\r\v");
         $name = NULL;
     }
     if (strlen($email) == 0) {
         unset($string);
     } else {
         require TOOLKIT . '/util.validators.php';
         return array('name' => $name, 'email' => $email, 'valid' => General::validateString($email, $validators['email']) ? true : false);
     }
 }
Пример #5
0
 private static function __applyValidationRule($data)
 {
     include TOOLKIT . '/util.validators.php';
     $rule = isset($validators['email']) ? $validators['email'] : fieldMemberEmail::$validator;
     return General::validateString($data, $rule);
 }
Пример #6
0
 private function __applyValidationRules($data)
 {
     $rule = $this->get('validator');
     return $rule ? General::validateString($data, $rule) : true;
 }
Пример #7
0
 public function applyValidationRules($data)
 {
     $rule = $this->get('text_validator');
     return $rule ? General::validateString($data, $rule) : true;
 }
Пример #8
0
 /**
  * Prior to saving an Author object, the validate function ensures that
  * the values in `$this->_fields` array are correct. As of Symphony 2.3
  * Authors must have unique username AND email address. This function returns
  * boolean, with an `$errors` array provided by reference to the callee
  * function.
  *
  * @param array $errors
  * @return boolean
  */
 public function validate(&$errors)
 {
     $errors = array();
     $current_author = null;
     if (is_null($this->get('first_name'))) {
         $errors['first_name'] = __('First name is required');
     }
     if (is_null($this->get('last_name'))) {
         $errors['last_name'] = __('Last name is required');
     }
     if ($this->get('id')) {
         $current_author = Symphony::Database()->fetchRow(0, sprintf("SELECT `email`, `username`\n                FROM `tbl_authors`\n                WHERE `id` = %d", $this->get('id')));
     }
     // Check that Email is provided
     if (is_null($this->get('email'))) {
         $errors['email'] = __('E-mail address is required');
         // Check Email is valid
     } elseif (!General::validateString($this->get('email'), $validators['email'])) {
         $errors['email'] = __('E-mail address entered is invalid');
         // Check that if an existing Author changes their email address that
         // it is not already used by another Author
     } elseif ($this->get('id')) {
         if ($current_author['email'] !== $this->get('email') && Symphony::Database()->fetchVar('count', 0, sprintf("SELECT COUNT(`id`) as `count`\n                    FROM `tbl_authors`\n                    WHERE `email` = '%s'", General::sanitize($this->get('email')))) != 0) {
             $errors['email'] = __('E-mail address is already taken');
         }
         // Check that Email is not in use by another Author
     } elseif (Symphony::Database()->fetchVar('id', 0, sprintf("SELECT `id`\n            FROM `tbl_authors`\n            WHERE `email` = '%s'\n            LIMIT 1", General::sanitize($this->get('email'))))) {
         $errors['email'] = __('E-mail address is already taken');
     }
     // Check the username exists
     if (is_null($this->get('username'))) {
         $errors['username'] = __('Username is required');
         // Check that if it's an existing Author that the username is not already
         // in use by another Author if they are trying to change it.
     } elseif ($this->get('id')) {
         if ($current_author['username'] !== $this->get('username') && Symphony::Database()->fetchVar('count', 0, sprintf("SELECT COUNT(`id`) as `count`\n                    FROM `tbl_authors`\n                    WHERE `username` = '%s'", General::sanitize($this->get('username')))) != 0) {
             $errors['username'] = __('Username is already taken');
         }
         // Check that the username is unique
     } elseif (Symphony::Database()->fetchVar('id', 0, sprintf("SELECT `id`\n            FROM `tbl_authors`\n            WHERE `username` = '%s'\n            LIMIT 1", General::sanitize($this->get('username'))))) {
         $errors['username'] = __('Username is already taken');
     }
     if (is_null($this->get('password'))) {
         $errors['password'] = __('Password is required');
     }
     return empty($errors) ? true : false;
 }
Пример #9
0
 function checkPostFieldData($data, &$message, $entry_id = NULL)
 {
     /*
     UPLOAD_ERR_OK
     Value: 0; There is no error, the file uploaded with success.
     
     UPLOAD_ERR_INI_SIZE
     Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
     
     UPLOAD_ERR_FORM_SIZE
     Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
     
     UPLOAD_ERR_PARTIAL
     Value: 3; The uploaded file was only partially uploaded.
     
     UPLOAD_ERR_NO_FILE
     Value: 4; No file was uploaded.
     
     UPLOAD_ERR_NO_TMP_DIR
     Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
     
     UPLOAD_ERR_CANT_WRITE
     Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
     
     UPLOAD_ERR_EXTENSION
     Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0.
     */
     //	Array
     //	(
     //	    [name] => filename.pdf
     //	    [type] => application/pdf
     //	    [tmp_name] => /tmp/php/phpYtdlCl
     //	    [error] => 0
     //	    [size] => 16214
     //	)
     $message = NULL;
     try {
         $this->S3->getBucket($this->get('bucket'));
     } catch (Exception $e) {
         $message = __('The bucket %s doesn\'t exist! Please update this section.', array($this->get('bucket')));
         return self::__INVALID_FIELDS__;
     }
     if (empty($data) || isset($data['error']) && $data['error'] == UPLOAD_ERR_NO_FILE) {
         if ($this->get('required') == 'yes') {
             $message = __("'%s' is a required field.", array($this->get('label')));
             return self::__MISSING_FIELDS__;
         }
         return self::__OK__;
     }
     ## Its not an array, so just retain the current data and return
     if (!is_array($data)) {
         return self::__OK__;
     }
     if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) {
         switch ($data['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize')));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize(Symphony::Configuration()->get('max_upload_size', 'admin'))));
                 break;
             case UPLOAD_ERR_PARTIAL:
                 $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_NO_TMP_DIR:
                 $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label')));
                 break;
         }
         return self::__ERROR_CUSTOM__;
     }
     ## Sanitize the filename
     $data['name'] = Lang::createFilename($data['name']);
     ## uniq the filename
     if ($this->get('unique_filename') == true && isset($data['name'])) {
         $this->getUniqueFilename($data['name']);
     }
     if ($this->get('validator') != NULL) {
         $rule = $this->get('validator');
         if (!General::validateString($data['name'], $rule)) {
             $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     ## check if the file exists since we can't check directly through the s3 library, the file field is unique
     $row = Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `file`='" . $data['name'] . "'");
     if (isset($row['file'])) {
         $message = __('A file with the name %1$s already exists at that bucket. Please rename the file first, or choose another.', array($data['name']));
         return self::__INVALID_FIELDS__;
     }
     return self::__OK__;
 }
Пример #10
0
 public function checkPostFieldData($data, &$message, $entry_id = null)
 {
     /**
      * For information about PHPs upload error constants see:
      * @link http://php.net/manual/en/features.file-upload.errors.php
      */
     $message = null;
     if (empty($data) || is_array($data) && isset($data['error']) && $data['error'] == UPLOAD_ERR_NO_FILE) {
         if ($this->get('required') == 'yes') {
             $message = __('‘%s’ is a required field.', array($this->get('label')));
             return self::__MISSING_FIELDS__;
         }
         return self::__OK__;
     }
     // Its not an array, so just retain the current data and return
     if (is_array($data) === false) {
         $file = $this->getFilePath(basename($data));
         if (file_exists($file) === false || !is_readable($file)) {
             $message = __('The file uploaded is no longer available. Please check that it exists, and is readable.');
             return self::__INVALID_FIELDS__;
         }
         // Ensure that the file still matches the validator and hasn't
         // changed since it was uploaded.
         if ($this->get('validator') != null) {
             $rule = $this->get('validator');
             if (General::validateString($file, $rule) === false) {
                 $message = __('File chosen in ‘%s’ does not match allowable file types for that field.', array($this->get('label')));
                 return self::__INVALID_FIELDS__;
             }
         }
         return self::__OK__;
     }
     if (is_dir(DOCROOT . $this->get('destination') . '/') === false) {
         $message = __('The destination directory, %s, does not exist.', array('<code>' . $this->get('destination') . '</code>'));
         return self::__ERROR__;
     } elseif (is_writable(DOCROOT . $this->get('destination') . '/') === false) {
         $message = __('Destination folder is not writable.') . ' ' . __('Please check permissions on %s.', array('<code>' . $this->get('destination') . '</code>'));
         return self::__ERROR__;
     }
     if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) {
         switch ($data['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 $message = __('File chosen in ‘%1$s’ exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize')));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $message = __('File chosen in ‘%1$s’ exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize($_POST['MAX_FILE_SIZE'])));
                 break;
             case UPLOAD_ERR_PARTIAL:
             case UPLOAD_ERR_NO_TMP_DIR:
                 $message = __('File chosen in ‘%s’ was only partially uploaded due to an error.', array($this->get('label')));
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $message = __('Uploading ‘%s’ failed. Could not write temporary file to disk.', array($this->get('label')));
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $message = __('Uploading ‘%s’ failed. File upload stopped by extension.', array($this->get('label')));
                 break;
         }
         return self::__ERROR_CUSTOM__;
     }
     // Sanitize the filename
     $data['name'] = Lang::createFilename($data['name']);
     if ($this->get('validator') != null) {
         $rule = $this->get('validator');
         if (!General::validateString($data['name'], $rule)) {
             $message = __('File chosen in ‘%s’ does not match allowable file types for that field.', array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     return self::__OK__;
 }
Пример #11
0
 function checkPostFieldData($data, &$message, $entry_id = NULL)
 {
     /*
     	UPLOAD_ERR_OK
     	Value: 0; There is no error, the file uploaded with success.
     
     	UPLOAD_ERR_INI_SIZE
     	Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
     
     	UPLOAD_ERR_FORM_SIZE
     	Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
     
     	UPLOAD_ERR_PARTIAL
     	Value: 3; The uploaded file was only partially uploaded.
     
     	UPLOAD_ERR_NO_FILE
     	Value: 4; No file was uploaded.
     
     	UPLOAD_ERR_NO_TMP_DIR
     	Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
     
     	UPLOAD_ERR_CANT_WRITE
     	Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
     
     	UPLOAD_ERR_EXTENSION
     	Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0.
     */
     //	Array
     //	(
     //	    [name] => filename.pdf
     //	    [type] => application/pdf
     //	    [tmp_name] => /tmp/php/phpYtdlCl
     //	    [error] => 0
     //	    [size] => 16214
     //	)
     $message = NULL;
     if (empty($data) || $data['error'] == UPLOAD_ERR_NO_FILE) {
         if ($this->get('required') == 'yes') {
             $message = __("'%s' is a required field.", $this->get('label'));
             return self::__MISSING_FIELDS__;
         }
         return self::__OK__;
     }
     ## Its not an array, so just retain the current data and return
     if (!is_array($data)) {
         return self::__OK__;
     }
     if (!is_writable(DOCROOT . $this->get('destination') . '/')) {
         $message = __('Destination folder, <code>%s</code>, is not writable. Please check permissions.', array($this->get('destination')));
         return self::__ERROR__;
     }
     if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) {
         switch ($data['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize')));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize($this->_engine->Configuration->get('max_upload_size', 'admin'))));
                 break;
             case UPLOAD_ERR_PARTIAL:
                 $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_NO_TMP_DIR:
                 $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label')));
                 break;
         }
         return self::__ERROR_CUSTOM__;
     }
     ## Sanitize the filename
     $data['name'] = Lang::createFilename($data['name']);
     if ($this->get('validator') != NULL) {
         $rule = $this->get('validator');
         if (!General::validateString($data['name'], $rule)) {
             $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/');
     $new_file = $abs_path . '/' . $data['name'];
     $existing_file = NULL;
     if ($entry_id) {
         $row = $this->Database->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `entry_id` = '{$entry_id}' LIMIT 1");
         $existing_file = $abs_path . '/' . trim($row['file'], '/');
     }
     if ($existing_file != $new_file && file_exists($new_file)) {
         $message = __('A file with the name %1$s already exists in %2$s. Please rename the file first, or choose another.', array($data['name'], $this->get('destination')));
         return self::__INVALID_FIELDS__;
     }
     return self::__OK__;
 }
Пример #12
0
 private function __applyValidationRule($data)
 {
     return General::validateString($data, '/^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}$/');
 }
Пример #13
0
 public function validate(MessageStack $errors)
 {
     if (is_null($this->first_name)) {
         $errors->append('first_name', __('First name is required'));
     }
     if (is_null($this->last_name)) {
         $errors->append('last_name', __('Last name is required'));
     }
     if (is_null($this->email)) {
         $errors->append('email', __('E-mail address is required'));
     } elseif (!General::validateString($this->email, '/^[^@]+@[^\\.@]+\\.[^@]+$/i')) {
         $errors->append('email', __('E-mail address entered is invalid'));
     }
     if (is_null($this->username)) {
         $errors->append('username', __('Username is required'));
     } elseif ($this->id) {
         $result = Symphony::Database()->query("SELECT `username` FROM `tbl_users` WHERE `id` = %d", array($this->id));
         $current_username = $result->current()->username;
         if ($current_username != $this->username && Symphony::Database()->query("SELECT `id` FROM `tbl_users` WHERE `username` = '%s'", array($this->username))->valid()) {
             $errors->append('username', __('Username is already taken'));
         }
     } elseif (Symphony::Database()->query("SELECT `id` FROM `tbl_users` WHERE `username` = '%s'", array($this->username))->valid()) {
         $errors->append('username', __('Username is already taken'));
     }
     if (is_null($this->password)) {
         $errors->append('password', __('Password is required'));
     }
     return $errors->length() == 0;
 }
 protected function _parseNameAndEmail(&$string)
 {
     $string = trim($string);
     if (strstr($string, '<')) {
         $name = trim(strstr($string, '<', true), "\" \t\n\r\v");
         $email = trim(strstr($string, '<'), "<> \t\n\r\v");
     } else {
         $email = trim($string, " \t\n\r\v");
         $name = NULL;
     }
     if (strlen($email) == 0) {
         unset($string);
     } else {
         return array('name' => $name, 'email' => $email, 'valid' => General::validateString($this->_emailValidator, $recipient['email']) ? true : false);
     }
 }
Пример #15
0
 public function validateRule($data)
 {
     $rule = $this->get('validator');
     return $rule ? General::validateString($data, $rule) : true;
 }
Пример #16
0
 private function __applyValidationRule($data)
 {
     include TOOLKIT . '/util.validators.php';
     $rule = isset($validators['email']) ? $validators['email'] : '/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i';
     return General::validateString($data, $rule);
 }
Пример #17
0
 public function validateFilename($file, &$message)
 {
     if ($this->get('validator') != null) {
         $rule = $this->get('validator');
         if (General::validateString($file, $rule) === false) {
             $message = __('File chosen in ‘%s’ does not match allowable file types for that field.', array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     } else {
         $blacklist = Symphony::Configuration()->get('upload_blacklist', 'admin');
         if (!empty($blacklist) && General::validateString($file, $blacklist)) {
             $message = __('File chosen in ‘%s’ is blacklisted for that field.', array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     return self::__OK__;
 }
 function validateFields($sid, $fields)
 {
     $errors = array();
     $fields = $this->__resolveFieldNames($sid, $fields);
     $row = $this->_db->fetchRow(0, "SELECT t1.primary_field, t2.name\n\t\t\t\t\t\t\t\t  FROM tbl_sections as t1\n\t\t\t\t\t\t\t\t  LEFT JOIN `tbl_customfields` AS t2 ON t1.primary_field = t2.id\n\t\t\t\t\t\t\t\t  WHERE t1.id = '" . $sid . "' LIMIT 1");
     $primary_field_id = $row['primary_field'];
     $primary_field_name = $row['title'];
     $required = $this->fetchEntryRequiredFields($sid);
     ##Make sure required fields are filled
     for ($i = 0; $i < count($required); $i++) {
         if (trim($fields[$required[$i]]) == "") {
             $errors[$required[$i]] = true;
         }
     }
     ##Make sure the primary field is also filled
     if (trim($fields[$primary_field_id]) == "") {
         $errors[$primary_field_id] = true;
     }
     if (!empty($errors)) {
         return $errors;
     }
     ##Validate the fields
     $fieldSchema = $this->fetchEntryFieldSchema($sid);
     foreach ($fieldSchema as $f) {
         $string = trim($fields[$f['id']]);
         if ($string != "" && $f['validator'] != NULL && !defined('__SYM_ENTRY_VALIDATION_ERROR__')) {
             if ($f['validator'] == 'custom') {
                 $rule = $f['validation_rule'];
             } elseif ($f['validator'] != NULL) {
                 include TOOLKIT . "/util.validators.php";
                 $rule = $validators[$f['validator']][1];
             }
             if ($f['type'] == 'list') {
                 $string = preg_split('/,/', $string, -1, PREG_SPLIT_NO_EMPTY);
                 $string = array_map("trim", $string);
             }
             if (!General::validateString($string, $rule)) {
                 define("__SYM_ENTRY_VALIDATION_ERROR__", $f['name']);
                 return false;
             }
         }
     }
     return NULL;
 }
Пример #19
0
 /**
  * Prior to saving an Author object, the validate function ensures that
  * the values in `$this->_fields` array are correct. The function returns
  * boolean, but an errors array is provided by reference to the callee
  * function.
  *
  * @param array $errors
  * @return boolean
  */
 public function validate(&$errors)
 {
     require_once TOOLKIT . '/util.validators.php';
     $errors = array();
     if (is_null($this->get('first_name'))) {
         $errors['first_name'] = __('First name is required');
     }
     if (is_null($this->get('last_name'))) {
         $errors['last_name'] = __('Last name is required');
     }
     if (is_null($this->get('email'))) {
         $errors['email'] = __('E-mail address is required');
     } elseif (!General::validateString($this->get('email'), $validators['email'])) {
         $errors['email'] = __('E-mail address entered is invalid');
     }
     if (is_null($this->get('username'))) {
         $errors['username'] = __('Username is required');
     } elseif ($this->get('id')) {
         $current_username = Symphony::Database()->fetchVar('username', 0, "SELECT `username` FROM `tbl_authors` WHERE `id` = " . $this->get('id'));
         if ($current_username != $this->get('username') && Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_authors` WHERE `username` = '" . $this->get('username') . "' LIMIT 1")) {
             $errors['username'] = __('Username is already taken');
         }
     } elseif (Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_authors` WHERE `username` = '" . $this->get('username') . "' LIMIT 1")) {
         $errors['username'] = __('Username is already taken');
     }
     if (is_null($this->get('password'))) {
         $errors['password'] = __('Password is required');
     }
     return empty($errors) ? true : false;
 }
Пример #20
0
 public function validateData(MessageStack $errors, Entry $entry = null, $data = null)
 {
     if ($data->error == UPLOAD_ERR_NO_FILE) {
         if ($this->required == 'yes') {
             $errors->append(null, (object) array('message' => __("'%s' is a required field.", array($this->label)), 'code' => self::ERROR_MISSING));
             return self::STATUS_ERROR;
         }
         return self::STATUS_OK;
     }
     if (!is_object($data)) {
         return self::STATUS_OK;
     }
     if (!is_writable(DOCROOT . $this->destination . '/')) {
         $errors->append(null, (object) array('message' => __("Destination folder, <code>%s</code>, is not writable. Please check permissions.", array($this->destination)), 'code' => self::ERROR_INVALID));
         return self::STATUS_ERROR;
     }
     if ($data->error != UPLOAD_ERR_NO_FILE and $data->error != UPLOAD_ERR_OK) {
         switch ($data->error) {
             case UPLOAD_ERR_INI_SIZE:
                 $size = is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize');
                 $errors->append(null, (object) array('message' => __('File chosen in \'%s\' exceeds the maximum allowed upload size of %s specified by your host.', array($this->label, $size)), 'code' => self::ERROR_INVALID));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $size = General::formatFilesize(Symphony::Configuration()->core()->symphony->{'maximum-upload-size'});
                 $errors->append(null, (object) array('message' => __('File chosen in \'%s\' exceeds the maximum allowed upload size of %s, specified by Symphony.', array($this->label, $size)), 'code' => self::ERROR_INVALID));
                 break;
             case UPLOAD_ERR_PARTIAL:
             case UPLOAD_ERR_NO_TMP_DIR:
                 $errors->append(null, (object) array('message' => __('File chosen in \'%s\' was only partially uploaded due to an error.', array($this->label)), 'code' => self::ERROR_INVALID));
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $errors->append(null, (object) array('message' => __('Uploading \'%s\' failed. Could not write temporary file to disk.', array($this->label)), 'code' => self::ERROR_INVALID));
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $errors->append(null, (object) array('message' => __('Uploading \'%s\' failed. File upload stopped by extension.', array($this->label)), 'code' => self::ERROR_INVALID));
                 break;
         }
         return self::STATUS_ERROR;
     }
     if ($this->validator != null) {
         $rule = $this->validator;
         if (!General::validateString($data->file, $rule)) {
             $errors->append(null, (object) array('message' => __('File chosen in \'%s\' does not match allowable file types for that field.', array($this->label)), 'code' => self::ERROR_INVALID));
             return self::STATUS_ERROR;
         }
     }
     $file = DOCROOT . '/' . $data->path . '/' . $data->file;
     // Make sure we don't upload over the top of a pervious file:
     if (isset($data->tmp_name) and $data->existing != $file and file_exists($file)) {
         $errors->append(null, (object) array('message' => __('A file with the name %s already exists in %s. Please rename the file first, or choose another.', array($data->name, trim($this->destination, '/'))), 'code' => self::ERROR_INVALID));
         return self::ERROR_INVALID;
     }
     return self::STATUS_OK;
 }
Пример #21
0
 public function checkPostFieldData($data, &$message, $entry_id = NULL)
 {
     $message = NULL;
     if ($this->s3->doesBucketExist($this->get('bucket')) == false) {
         $message = __('The bucket %s doesn\'t exist! Please update this section.', array($this->get('bucket')));
         return self::__INVALID_FIELDS__;
     }
     if (empty($data) || isset($data['error']) && $data['error'] == UPLOAD_ERR_NO_FILE) {
         if ($this->get('required') == 'yes') {
             $message = __("'%s' is a required field.", array($this->get('label')));
             return self::__MISSING_FIELDS__;
         }
         return self::__OK__;
     }
     ## Its not an array, so just retain the current data and return
     if (!is_array($data)) {
         return self::__OK__;
     }
     if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) {
         switch ($data['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize')));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize(Symphony::Configuration()->get('max_upload_size', 'admin'))));
                 break;
             case UPLOAD_ERR_PARTIAL:
                 $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_NO_TMP_DIR:
                 $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label')));
                 break;
         }
         return self::__ERROR_CUSTOM__;
     }
     ## Sanitize the filename
     $data['name'] = Lang::createFilename($data['name']);
     ## uniq the filename
     if ($this->get('unique_filename') == true && isset($data['name'])) {
         $this->getUniqueFilename($data['name']);
     }
     if ($this->get('validator') != NULL) {
         $rule = $this->get('validator');
         if (!General::validateString($data['name'], $rule)) {
             $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     ## check if the file exists since we can't check directly through the s3 library, the file field is unique
     $row = Symphony::Database()->fetchRow(0, sprintf("\r\n            SELECT * FROM `tbl_entries_data_%d` WHERE `file` = '%s'\r\n        ", $this->get('id'), $data['name']));
     if (isset($row['file'])) {
         $message = __('A file with the name %1$s already exists at that bucket. Please rename the file first, or choose another.', array($data['name']));
         return self::__INVALID_FIELDS__;
     }
     return self::__OK__;
 }
 public function checkPostFieldData($data, &$message, $entry_id = null)
 {
     $label = $this->get('label');
     $message = null;
     if (empty($data) or $data['error'] == UPLOAD_ERR_NO_FILE) {
         if ($this->get('required') == 'yes') {
             $message = "'{$label}' is a required field.";
             return self::__MISSING_FIELDS__;
         }
         return self::__OK__;
     }
     // Its not an array, so just retain the current data and return
     if (!is_array($data)) {
         return self::__OK__;
     }
     if (!is_writable(DOCROOT . $this->get('destination') . '/')) {
         $message = __('Destination folder, <code>%s</code>, is not writable. Please check permissions.', array($this->get('destination')));
         return self::__ERROR__;
     }
     if ($data['error'] != UPLOAD_ERR_NO_FILE and $data['error'] != UPLOAD_ERR_OK) {
         switch ($data['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 $size = is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize');
                 $message = __('File chosen in \'%s\' exceeds the maximum allowed upload size of %s specified by your host.', array($label, $size));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $size = General::formatFilesize(Symphony::Configuration()->get('max_upload_size', 'admin'));
                 $message = __('File chosen in \'%s\' exceeds the maximum allowed upload size of %s, specified by Symphony.', array($label, $size));
                 break;
             case UPLOAD_ERR_PARTIAL:
             case UPLOAD_ERR_NO_TMP_DIR:
                 $message = __('File chosen in \'%s\' was only partially uploaded due to an error.', array($label));
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $message = __('Uploading \'%s\' failed. Could not write temporary file to disk.', array($label));
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $message = __('Uploading \'%s\' failed. File upload stopped by extension.', array($label));
                 break;
         }
         return self::__ERROR_CUSTOM__;
     }
     // Sanitize the filename:
     if ($this->get('serialise') == 'yes' and is_array($data) and isset($data['name'])) {
         $data['name'] = $this->getHashedFilename($data['name']);
     }
     if ($this->get('validator') != null) {
         $rule = $this->get('validator');
         if (!General::validateString($data['name'], $rule)) {
             $message = __('File chosen in \'%s\' does not match allowable file types for that field.', array($label));
             return self::__INVALID_FIELDS__;
         }
     }
     $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/');
     $new_file = $abs_path . '/' . $data['name'];
     $existing_file = null;
     if ($entry_id) {
         $field_id = $this->get('id');
         $row = $this->Database->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tf.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_entries_data_{$field_id}` AS f\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tf.entry_id = '{$entry_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t");
         $existing_file = $abs_path . '/' . trim($row['file'], '/');
     }
     if ($existing_file != $new_file and file_exists($new_file)) {
         $message = __('A file with the name %s already exists in %s. Please rename the file first, or choose another.', array($data['name'], $this->get('destination')));
         return self::__INVALID_FIELDS__;
     }
     return self::__OK__;
 }
Пример #23
0
 function validate(&$errors)
 {
     $errors = array();
     if ($this->get('first_name') == '') {
         $errors['first_name'] = __('First name is required');
     }
     if ($this->get('last_name') == '') {
         $errors['last_name'] = __('Last name is required');
     }
     if ($this->get('email') == '') {
         $errors['email'] = __('E-mail address is required');
     } elseif (!General::validateString($this->get('email'), '/^[^@]+@[^\\.@]+\\.[^@]+$/i')) {
         $errors['email'] = __('E-mail address entered is invalid');
     }
     if ($this->get('username') == '') {
         $errors['username'] = __('Username is required');
     } elseif ($this->get('id')) {
         $current_username = $this->_Parent->Database->fetchVar('username', 0, "SELECT `username` FROM `tbl_authors` WHERE `id` = " . $this->get('id'));
         if ($current_username != $this->get('username') && $this->_Parent->Database->fetchVar('id', 0, "SELECT `id` FROM `tbl_authors` WHERE `username` = '" . $this->get('username') . "' LIMIT 1")) {
             $errors['username'] = __('Username is already taken');
         }
     } elseif ($this->_Parent->Database->fetchVar('id', 0, "SELECT `id` FROM `tbl_authors` WHERE `username` = '" . $this->get('username') . "' LIMIT 1")) {
         $errors['username'] = __('Username is already taken');
     }
     if ($this->get('password') == '') {
         $errors['password'] = __('Password is required');
     }
     return empty($errors) ? true : false;
 }
Пример #24
0
 public function checkPostFieldData($data, &$message, $entry_id = NULL)
 {
     $message = NULL;
     if ($this->get('required') == 'yes' && (strlen($data['username']) == 0 || strlen($data['password']) == 0)) {
         $message = __('Username and Password are required fields.');
         return self::__MISSING_FIELDS__;
     }
     if (!General::validateString($data['username'], '/^[\\pL\\s-_0-9]{1,}+$/iu')) {
         $message = __('Username contains invalid characters.');
         return self::__INVALID_FIELDS__;
     }
     $existing_member = $this->fetchMemberFromUsername($data['username']);
     if ($this->get('required') == 'yes' && (is_object($existing_member) && $existing_member->get('id') != $entry_id)) {
         $message = __('That username is already taken.');
         return self::__INVALID_FIELDS__;
     }
     return self::__OK__;
 }
Пример #25
0
 public function checkPostFieldData($data, &$message, $entry_id = NULL)
 {
     /*
     	UPLOAD_ERR_OK
     	Value: 0; There is no error, the file uploaded with success.
     
     	UPLOAD_ERR_INI_SIZE
     	Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
     
     	UPLOAD_ERR_FORM_SIZE
     	Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
     
     	UPLOAD_ERR_PARTIAL
     	Value: 3; The uploaded file was only partially uploaded.
     
     	UPLOAD_ERR_NO_FILE
     	Value: 4; No file was uploaded.
     
     	UPLOAD_ERR_NO_TMP_DIR
     	Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
     
     	UPLOAD_ERR_CANT_WRITE
     	Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
     
     	UPLOAD_ERR_EXTENSION
     	Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0.
     
     	Array
     	(
     		[name] => filename.pdf
     		[type] => application/pdf
     		[tmp_name] => /tmp/php/phpYtdlCl
     		[error] => 0
     		[size] => 16214
     	)
     */
     $message = NULL;
     if (empty($data) || $data['error'] == UPLOAD_ERR_NO_FILE) {
         if ($this->get('required') == 'yes') {
             $message = __("'%s' is a required field.", array($this->get('label')));
             return self::__MISSING_FIELDS__;
         }
         return self::__OK__;
     }
     // Its not an array, so just retain the current data and return
     if (!is_array($data)) {
         // Ensure the file exists in the `WORKSPACE` directory
         // @link http://symphony-cms.com/discuss/issues/view/610/
         $file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $data);
         if (!file_exists($file) || !is_readable($file)) {
             $message = __('The file uploaded is no longer available. Please check that it exists, and is readable.');
             return self::__INVALID_FIELDS__;
         }
         // Ensure that the file still matches the validator and hasn't
         // changed since it was uploaded.
         if ($this->get('validator') != NULL) {
             $rule = $this->get('validator');
             if (!General::validateString($file, $rule)) {
                 $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label')));
                 return self::__INVALID_FIELDS__;
             }
         }
         return self::__OK__;
     }
     if (!is_dir(DOCROOT . $this->get('destination') . '/')) {
         $message = __('The destination directory, <code>%s</code>, does not exist.', array($this->get('destination')));
         return self::__ERROR__;
     } elseif (!is_writable(DOCROOT . $this->get('destination') . '/')) {
         $message = __('Destination folder, <code>%s</code>, is not writable. Please check permissions.', array($this->get('destination')));
         return self::__ERROR__;
     }
     if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) {
         switch ($data['error']) {
             case UPLOAD_ERR_INI_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize')));
                 break;
             case UPLOAD_ERR_FORM_SIZE:
                 $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize($_POST['MAX_FILE_SIZE'])));
                 break;
             case UPLOAD_ERR_PARTIAL:
             case UPLOAD_ERR_NO_TMP_DIR:
                 $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_CANT_WRITE:
                 $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label')));
                 break;
             case UPLOAD_ERR_EXTENSION:
                 $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label')));
                 break;
         }
         return self::__ERROR_CUSTOM__;
     }
     // Sanitize the filename
     $data['name'] = Lang::createFilename($data['name']);
     if ($this->get('validator') != NULL) {
         $rule = $this->get('validator');
         if (!General::validateString($data['name'], $rule)) {
             $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/');
     $new_file = $abs_path . '/' . $data['name'];
     $existing_file = NULL;
     if ($entry_id) {
         $row = Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `entry_id` = '{$entry_id}' LIMIT 1");
         $existing_file = $abs_path . '/' . trim($row['file'], '/');
     }
     if (strtolower($existing_file) != strtolower($new_file) && file_exists($new_file)) {
         $message = __('A file with the name %1$s already exists in %2$s. Please rename the file first, or choose another.', array($data['name'], $this->get('destination')));
         return self::__INVALID_FIELDS__;
     }
     return self::__OK__;
 }
Пример #26
0
 public function checkPostFieldData($data, &$message, $entry_id = null)
 {
     $message = null;
     $username = trim($data);
     //	If the field is required
     if ($this->get('required') == "yes" && empty($username)) {
         $message = __('%s is a required field.', array($this->get('label')));
         return self::__MISSING_FIELDS__;
     }
     //	Check Username
     if (!empty($username)) {
         if ($this->get('validator') && !General::validateString($username, $this->get('validator'))) {
             $message = __('%s contains invalid characters.', array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
         // We need to make sure the value doesn't already exist in the Section.
         $existing = $this->fetchMemberIDBy($username);
         // If there is an existing username, and it's not the current object (editing), error.
         if (!is_null($existing) && $existing != $entry_id) {
             $message = __('%s is already taken.', array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     return self::__OK__;
 }
 /**
  * Prior to saving an Author object, the validate function ensures that
  * the values in `$this->_fields` array are correct. As of Symphony 2.3
  * Authors must have unique username AND email address. This function returns
  * boolean, with an `$errors` array provided by reference to the callee
  * function.
  *
  * @param array $errors
  * @return boolean
  */
 public function validate(&$errors)
 {
     require_once TOOLKIT . '/util.validators.php';
     $errors = array();
     $current_author = null;
     if (is_null($this->get('first_name'))) {
         $errors['first_name'] = __('First name is required');
     }
     if (is_null($this->get('last_name'))) {
         $errors['last_name'] = __('Last name is required');
     }
     if ($this->get('id')) {
         $current_author = Symphony::Database()->fetchRow(0, sprintf("\n\t\t\t\t\t\tSELECT `email`, `username`\n\t\t\t\t\t\tFROM `tbl_authors`\n\t\t\t\t\t\tWHERE `id` = %d\n\t\t\t\t\t", $this->get('id')));
     }
     // Check that Email is provided
     if (is_null($this->get('email'))) {
         $errors['email'] = __('E-mail address is required');
     } else {
         if (!General::validateString($this->get('email'), $validators['email'])) {
             $errors['email'] = __('E-mail address entered is invalid');
         } else {
             if ($this->get('id')) {
                 if ($current_author['email'] != $this->get('email') && Symphony::Database()->fetchVar('count', 0, sprintf("\n\t\t\t\t\t\t\tSELECT COUNT(`id`) as `count`\n\t\t\t\t\t\t\tFROM `tbl_authors`\n\t\t\t\t\t\t\tWHERE `email` = '%s'\n\t\t\t\t\t\t", General::sanitize($this->get('email')))) != 0) {
                     $errors['email'] = __('E-mail address is already taken');
                 }
             } else {
                 if (Symphony::Database()->fetchVar('id', 0, sprintf("\n\t\t\t\t\tSELECT `id`\n\t\t\t\t\tFROM `tbl_authors`\n\t\t\t\t\tWHERE `email` = '%s'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t", General::sanitize($this->get('email'))))) {
                     $errors['email'] = __('E-mail address is already taken');
                 }
             }
         }
     }
     // Check the username exists
     if (is_null($this->get('username'))) {
         $errors['username'] = __('Username is required');
     } else {
         if ($this->get('id')) {
             if ($current_author['username'] != $this->get('username') && Symphony::Database()->fetchVar('count', 0, sprintf("\n\t\t\t\t\t\t\tSELECT COUNT(`id`) as `count`\n\t\t\t\t\t\t\tFROM `tbl_authors`\n\t\t\t\t\t\t\tWHERE `username` = '%s'\n\t\t\t\t\t\t", General::sanitize($this->get('username')))) != 0) {
                 $errors['username'] = __('Username is already taken');
             }
         } else {
             if (Symphony::Database()->fetchVar('id', 0, sprintf("\n\t\t\t\t\tSELECT `id`\n\t\t\t\t\tFROM `tbl_authors`\n\t\t\t\t\tWHERE `username` = '%s'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t", General::sanitize($this->get('username'))))) {
                 $errors['username'] = __('Username is already taken');
             }
         }
     }
     if (is_null($this->get('password'))) {
         $errors['password'] = __('Password is required');
     }
     return empty($errors) ? true : false;
 }
 public function validateRule($data)
 {
     $rule = '/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i';
     return $rule ? General::validateString($data, $rule) : true;
 }
Пример #29
0
 public function checkPostFieldData($data, &$message, $entry_id = null)
 {
     $message = null;
     if ($this->get('required') == 'yes' && strlen(trim($data)) == 0) {
         $message = __('‘%s’ is a required field.', array($this->get('label')));
         return self::__MISSING_FIELDS__;
     }
     if ($this->get('validator')) {
         $data = preg_split('/\\,\\s*/i', $data, -1, PREG_SPLIT_NO_EMPTY);
         $data = array_map('trim', $data);
         if (empty($data)) {
             return self::__OK__;
         }
         if (!General::validateString($data, $this->get('validator'))) {
             $message = __("'%s' contains invalid data. Please check the contents.", array($this->get('label')));
             return self::__INVALID_FIELDS__;
         }
     }
     return self::__OK__;
 }
 private function __applyValidationRule($data)
 {
     return General::validateString($data, '/^\\w(?:\\.?[\\w%+-]+)*@\\w(?:[\\w-]*\\.)+?[a-z]{2,}$/i');
 }