Beispiel #1
0
 /**
  * Pre-save handling.
  */
 protected function _preSave()
 {
     if ($this->isChanged('callback_class') || $this->isChanged('callback_method')) {
         $class = $this->get('callback_class');
         $method = $this->get('callback_method');
         if (!XenForo_Helper_Php::validateCallbackPhrased($class, $method, $errorPhrase)) {
             $this->error($errorPhrase, 'callback_method');
         }
     }
 }
 protected function _preSave()
 {
     if (($this->get('action') == 'preg_replace' || $this->get('action') == 'callback') && $this->get('find')) {
         if (preg_match('/\\W[\\s\\w]*e[\\s\\w]*$/', $this->get('find'))) {
             // can't run a /e regex
             $this->error(new XenForo_Phrase('please_enter_valid_regular_expression'), 'find');
         } else {
             try {
                 preg_replace($this->get('find'), '', '');
             } catch (ErrorException $e) {
                 $this->error(new XenForo_Phrase('please_enter_valid_regular_expression'), 'find');
             }
         }
     }
     if ($this->get('action') == 'callback' && ($this->isChanged('replace') || $this->isChanged('action'))) {
         if (preg_match('/^([a-z0-9_\\\\]+)::([a-z0-9_]+)$/i', $this->get('replace'), $match)) {
             if (!XenForo_Helper_Php::validateCallbackPhrased($match[1], $match[2], $errorPhrase)) {
                 $this->error($errorPhrase, 'replace');
             }
         } else {
             $this->error(new XenForo_Phrase('please_enter_valid_callback_method'), 'replace');
         }
     }
 }
Beispiel #3
0
 /**
  * Pre-save behaviors.
  */
 protected function _preSave()
 {
     if ($this->isChanged('match_callback_class') || $this->isChanged('match_callback_method')) {
         $class = $this->get('match_callback_class');
         $method = $this->get('match_callback_method');
         if (!$class || !$method) {
             $this->set('match_callback_class', '');
             $this->set('match_callback_method', '');
         } else {
             if (!XenForo_Helper_Php::validateCallbackPhrased($class, $method, $errorPhrase)) {
                 $this->error($errorPhrase, 'match_callback_method');
             }
         }
     }
     if ($this->isUpdate() && $this->isChanged('field_type')) {
         $typeMap = $this->_getFieldModel()->getUserFieldTypeMap();
         if ($typeMap[$this->get('field_type')] != $typeMap[$this->getExisting('field_type')]) {
             $this->error(new XenForo_Phrase('you_may_not_change_field_to_different_type_after_it_has_been_created'), 'field_type');
         }
     }
     if (in_array($this->get('field_type'), array('select', 'radio', 'checkbox', 'multiselect'))) {
         if ($this->isInsert() && !$this->_fieldChoices || is_array($this->_fieldChoices) && !$this->_fieldChoices) {
             $this->error(new XenForo_Phrase('please_enter_at_least_one_choice'), 'field_choices', false);
         }
     } else {
         $this->setFieldChoices(array());
     }
     $titlePhrase = $this->getExtraData(self::DATA_TITLE);
     if ($titlePhrase !== null && strlen($titlePhrase) == 0) {
         $this->error(new XenForo_Phrase('please_enter_valid_title'), 'title');
     }
 }
 /**
  * Validates that the specified callback class and method are present and correct
  *
  * @param string $class
  * @param string $method
  *
  * @return boolean
  */
 protected function _validateCallback($class, $method)
 {
     if ($class && !XenForo_Helper_Php::validateCallbackPhrased($class, $method, $errorPhrase)) {
         $this->error($errorPhrase, 'callback_method');
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Pre-save handling.
  */
 protected function _preSave()
 {
     $titlePhrase = $this->getExtraData(self::DATA_TITLE);
     if ($titlePhrase !== null && strlen($titlePhrase) == 0) {
         $this->error(new XenForo_Phrase('please_enter_valid_title'), 'title');
     }
     $content = $this->getExtraData(self::DATA_CONTENT);
     if ($content !== null) {
         if (strlen($content) == 0) {
             $this->error(new XenForo_Phrase('please_enter_page_content'), 'content');
         } else {
             $templateWriter = XenForo_DataWriter::create('XenForo_DataWriter_Template');
             $templateWriter->set('template', $content);
             $templateErrors = $templateWriter->getErrors();
             if ($templateErrors) {
                 $this->error(reset($templateErrors), 'content');
             }
         }
     }
     if ($this->get('callback_class') || $this->get('callback_method')) {
         $class = $this->get('callback_class');
         $method = $this->get('callback_method');
         if (!XenForo_Helper_Php::validateCallbackPhrased($class, $method, $errorPhrase)) {
             $this->error($errorPhrase, 'callback_method');
         }
     }
 }
Beispiel #6
0
 /**
  * Pre-save handler.
  */
 protected function _preSave()
 {
     if ($this->isInsert() && !$this->isChanged('active')) {
         $this->set('active', 1);
     }
     $titlePhrase = $this->getExtraData(self::DATA_TITLE);
     if ($titlePhrase !== null && strlen($titlePhrase) == 0) {
         $this->error(new XenForo_Phrase('please_enter_valid_title'), 'title');
     }
     if ($this->isChanged('cron_class') || $this->isChanged('cron_method')) {
         $class = $this->get('cron_class');
         $method = $this->get('cron_method');
         if (!XenForo_Helper_Php::validateCallbackPhrased($class, $method, $errorPhrase)) {
             $this->error($errorPhrase, 'cron_method');
         }
     }
     if ($this->get('active')) {
         $runRules = unserialize($this->get('run_rules'));
         if (!is_array($runRules)) {
             $runRules = array();
         }
         $this->set('next_run', $this->_getCronModel()->calculateNextRunTime($runRules));
     } else {
         $this->set('next_run', 0x7fffffff);
         // waay in future
     }
 }
Beispiel #7
0
 protected function _preSave()
 {
     $titlePhrase = $this->getExtraData(self::DATA_TITLE);
     if ($titlePhrase !== null && strlen($titlePhrase) == 0) {
         $this->error(new XenForo_Phrase('please_enter_valid_title'), 'title');
     }
     if (strlen($this->get('option_regex'))) {
         if (preg_match('/\\W[\\s\\w]*e[\\s\\w]*$/', $this->get('option_regex'))) {
             // can't run a /e regex
             $this->error(new XenForo_Phrase('please_enter_valid_regular_expression'), 'option_regex');
         } else {
             try {
                 preg_replace($this->get('option_regex'), '', '');
             } catch (ErrorException $e) {
                 $this->error(new XenForo_Phrase('please_enter_valid_regular_expression'), 'option_regex');
             }
         }
     }
     if ($this->get('bb_code_mode') == 'replace') {
         $this->set('callback_class', '');
         $this->set('callback_method', '');
     } else {
         if ($this->get('bb_code_mode') == 'callback') {
             $this->set('replace_html', '');
             $this->set('replace_html_email', '');
             $this->set('replace_text', '');
             $class = $this->get('callback_class');
             $method = $this->get('callback_method');
             if (!XenForo_Helper_Php::validateCallbackPhrased($class, $method, $errorPhrase)) {
                 $this->error($errorPhrase, 'callback_method');
             }
         }
     }
 }