/** * Validates the permalink. * * @author Jason Rey <*****@*****.**> * @since 1.3 * @access public * @return JSON A jsong encoded string. */ public function isValid() { // Render the ajax lib. $ajax = FD::ajax(); // Get the cluster id. $clusterId = JRequest::getInt('clusterid', 0); // Init the current alias. $current = ''; if (!empty($clusterId)) { $event = FD::event($clusterId); $current = $event->alias; } // Get the provided permalink $permalink = JRequest::getVar('permalink', ''); // Check if the field is required if (!$this->field->isRequired() && empty($permalink)) { return true; } // Check if the permalink provided is valid if (!SocialFieldsEventPermalinkHelper::valid($permalink, $this->params)) { return $ajax->reject(JText::_('FIELDS_EVENT_PERMALINK_INVALID_PERMALINK')); } // Test if permalink exists if (SocialFieldsEventPermalinkHelper::exists($permalink) && $permalink != $current) { return $ajax->reject(JText::_('FIELDS_EVENT_PERMALINK_NOT_AVAILABLE')); } $text = JText::_('FIELDS_EVENT_PERMALINK_AVAILABLE'); return $ajax->resolve($text); }
/** * Performs validation for the gender field. * * @since 1.3 * @access public * @param array $post The posted data. * @param SocialCluster $cluster The cluster object. * @return */ public function validate($post, $cluster = null) { // Get the current value $value = !empty($post[$this->inputName]) ? $post[$this->inputName] : ''; if (!$this->isRequired() && empty($value)) { return true; } // Catch for errors if this is a required field. if ($this->isRequired() && empty($value)) { $this->setError(JText::_('FIELDS_EVENT_PERMALINK_REQUIRED')); return false; } if ($this->params->get('max') > 0 && JString::strlen($value) > $this->params->get('max')) { $this->setError(JText::_('FIELDS_EVENT_PERMALINK_EXCEEDED_MAX_LENGTH')); return false; } // If the permalink is the same, just return true. if (!empty($cluster) && $cluster->alias == $value) { return true; } if (SocialFieldsEventPermalinkHelper::exists($value)) { $this->setError(JText::_('FIELDS_EVENT_PERMALINK_NOT_AVAILABLE')); return false; } if (!SocialFieldsEventPermalinkHelper::valid($value, $this->params)) { $this->setError(JText::_('FIELDS_EVENT_PERMALINK_INVALID_PERMALINK')); return false; } return true; }