/**
  * Verifies that the criteria is valid and formats is correctly.
  * Expected input format: [] with children: [rule] => name, [data] => info
  *
  * @param array|string $criteria Criteria array or serialize string; see above for format. Modified by ref.
  *
  * @return boolean
  */
 protected function _verifyCriteria(&$criteria)
 {
     $criteriaFiltered = XenForo_Helper_Criteria::prepareCriteriaForSave($criteria);
     $criteria = XenForo_Helper_Php::safeSerialize($criteriaFiltered);
     if (!$criteriaFiltered) {
         $this->error(new XenForo_Phrase('please_select_criteria_that_must_be_met'), 'user_criteria');
         return false;
     } else {
         return true;
     }
 }
Exemplo n.º 2
0
 public function saveDraft($key, $message, array $extraData = array(), array $viewingUser = null, $lastUpdate = null)
 {
     $this->standardizeViewingUserReference($viewingUser);
     $message = trim($message);
     if (!$viewingUser['user_id'] || !strlen($message)) {
         return false;
     }
     if (!$lastUpdate) {
         $lastUpdate = XenForo_Application::$time;
     }
     $this->_getDb()->query("\r\n\t\t\tINSERT INTO xf_draft\r\n\t\t\t\t(draft_key, user_id, last_update, message, extra_data)\r\n\t\t\tVALUES\r\n\t\t\t\t(?, ?, ?, ?, ?)\r\n\t\t\tON DUPLICATE KEY UPDATE\r\n\t\t\t\tlast_update = VALUES(last_update),\r\n\t\t\t\tmessage = VALUES(message),\r\n\t\t\t\textra_data = VALUES(extra_data)\r\n\t\t", array($key, $viewingUser['user_id'], $lastUpdate, $message, XenForo_Helper_Php::safeSerialize($extraData)));
     return true;
 }
Exemplo n.º 3
0
 /**
  * Removes any empty answers, and ensures that at least one answer remains
  *
  * @param string Serialized $answers
  *
  * @return boolean
  */
 protected function _verifyAnswers(&$answers)
 {
     $answers = XenForo_Helper_Php::safeUnserialize($answers);
     foreach ($answers as $i => &$answer) {
         $answer = trim($answer);
         if ($answer === '') {
             unset($answers[$i]);
         }
     }
     if (empty($answers)) {
         $this->error(new XenForo_Phrase('please_provide_at_least_one_answer'), 'answers');
         return false;
     }
     $answers = XenForo_Helper_Php::safeSerialize(array_values($answers));
     return true;
 }
Exemplo n.º 4
0
 /**
  * Verifies/sets the property value based on the type of the
  * property.
  *
  * @param string|array $value
  *
  * @return boolean
  */
 protected function _verifyPropertyValue(&$value)
 {
     switch ($this->getOption(self::OPTION_VALUE_FORMAT)) {
         case 'scalar':
             $value = strval($value);
             break;
         case 'css':
             if (!is_array($value)) {
                 $value = array();
             }
             // TODO: need to validate against allowed components
             foreach ($value as $key => &$propertyValue) {
                 if (is_string($propertyValue)) {
                     $propertyValue = trim($propertyValue);
                     if ($propertyValue === '') {
                         unset($value[$key]);
                         continue;
                     }
                     $propertyValue = str_replace("\r", '', $propertyValue);
                 } else {
                     if (is_array($propertyValue)) {
                         if (count($propertyValue) == 0) {
                             unset($value[$key]);
                             continue;
                         }
                         if ($key == 'text-decoration') {
                             asort($propertyValue);
                         }
                     }
                 }
             }
             ksort($value);
             $value = XenForo_Helper_Php::safeSerialize($value);
             break;
         default:
             throw new XenForo_Exception('Value format option not set properly.');
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * Validates an option value for pre-save.
  *
  * @param mixed $optionValue Unvalidated option
  *
  * @return string Validated option. Options are serialized; all other types a strval'd
  */
 protected function _validateOptionValuePreSave($optionValue)
 {
     switch ($this->get('data_type')) {
         case 'string':
             $optionValue = strval($optionValue);
             break;
         case 'integer':
             $optionValue = intval($optionValue);
             break;
         case 'numeric':
             $optionValue = strval($optionValue) + 0;
             break;
         case 'boolean':
             $optionValue = $optionValue ? 1 : 0;
             break;
         case 'array':
             if (!is_array($optionValue)) {
                 $unserialized = XenForo_Helper_Php::safeUnserialize($optionValue);
                 if (is_array($unserialized)) {
                     $optionValue = $unserialized;
                 } else {
                     $optionValue = array();
                 }
             }
             break;
         case 'unsigned_integer':
             $optionValue = max(0, intval($optionValue));
             break;
         case 'unsigned_numeric':
             $optionValue = max(0, strval($optionValue) + 0);
             break;
         case 'positive_integer':
             $optionValue = max(1, intval($optionValue));
             break;
     }
     $validationClass = $this->get('validation_class');
     $validationMethod = $this->get('validation_method');
     if ($validationClass && $validationMethod && $this->_validateValidationClassAndMethod($validationClass, $validationMethod)) {
         $success = (bool) call_user_func_array(array($validationClass, $validationMethod), array(&$optionValue, $this, $this->get('option_id')));
         if (!$success) {
             return false;
         }
     }
     if (is_array($optionValue)) {
         if ($this->get('data_type') != 'array') {
             $this->error(new XenForo_Phrase('only_array_data_types_may_be_represented_as_array_values'), 'data_type');
         } else {
             $subOptions = preg_split('/(\\r\\n|\\n|\\r)+/', trim($this->get('sub_options')), -1, PREG_SPLIT_NO_EMPTY);
             $newOptionValue = array();
             $allowAny = false;
             foreach ($subOptions as $subOption) {
                 if ($subOption == '*') {
                     $allowAny = true;
                 } else {
                     if (!isset($optionValue[$subOption])) {
                         $newOptionValue[$subOption] = false;
                     } else {
                         $newOptionValue[$subOption] = $optionValue[$subOption];
                         unset($optionValue[$subOption]);
                     }
                 }
             }
             if ($allowAny) {
                 // allow any keys, so bring all the remaining ones over
                 $newOptionValue += $optionValue;
             } else {
                 if (count($optionValue) > 0) {
                     $this->error(new XenForo_Phrase('following_sub_options_unknown_x', array('subOptions' => implode(', ', array_keys($optionValue)))), 'sub_options');
                 }
             }
             $optionValue = $newOptionValue;
         }
         $optionValue = XenForo_Helper_Php::safeSerialize($optionValue);
     }
     return strval($optionValue);
 }
 /**
  * Verifies the list of CSS components.
  *
  * @param array|string $components
  *
  * @return boolean
  */
 protected function _verifyCssComponents(&$components)
 {
     if (!is_array($components)) {
         $components = array();
     }
     $firstValue = reset($components);
     if (!is_bool($firstValue)) {
         $newComponents = array();
         foreach ($components as $component) {
             $newComponents[$component] = true;
         }
         $components = $newComponents;
     }
     $components = XenForo_Helper_Php::safeSerialize($components);
     return true;
 }
Exemplo n.º 7
0
 /**
  * Verifies that the criteria is valid and formats is correctly.
  * Expected input format: [] with children: [rule] => name, [data] => info
  *
  * @param array|string $criteria Criteria array or serialize string; see above for format. Modified by ref.
  *
  * @return boolean
  */
 protected function _verifyCriteria(&$criteria)
 {
     $criteriaFiltered = XenForo_Helper_Criteria::prepareCriteriaForSave($criteria);
     $criteria = XenForo_Helper_Php::safeSerialize($criteriaFiltered);
     return true;
 }
Exemplo n.º 8
0
    public function updateCustomFields()
    {
        if ($this->_updateCustomFields) {
            $userId = $this->get('user_id');
            foreach ($this->_updateCustomFields as $fieldId => $value) {
                if (is_array($value)) {
                    $value = XenForo_Helper_Php::safeSerialize($value);
                }
                $this->_db->query('
					INSERT INTO xf_user_field_value
						(user_id, field_id, field_value)
					VALUES
						(?, ?, ?)
					ON DUPLICATE KEY UPDATE
						field_value = VALUES(field_value)
				', array($userId, $fieldId, $value));
            }
        }
    }
Exemplo n.º 9
0
 /**
  * Verifies the cron run rules.
  *
  * @param string|array $runRules String may be serialized value
  *
  * @return boolean
  */
 protected function _verifyRunRules(&$runRules)
 {
     $runRulesNew = $runRules;
     if (!is_array($runRulesNew)) {
         $runRulesNew = XenForo_Helper_Php::safeUnserialize($runRulesNew);
         if (!is_array($runRulesNew)) {
             $runRulesNew = array();
         }
     }
     $runRules = XenForo_Helper_Php::safeSerialize($runRulesNew);
     return true;
 }