Example #1
0
 /**
  * Validates the username.
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	JSON	A jsong encoded string.
  *
  * @author	Jason Rey <*****@*****.**>
  */
 public function isValid()
 {
     // Render the ajax lib.
     $ajax = FD::ajax();
     // Get the group id
     $groupId = JRequest::getInt('groupid', 0);
     // Set the current username
     $current = '';
     if (!empty($groupId)) {
         $group = FD::group($groupId);
         $current = $group->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 (!SocialFieldsGroupPermalinkHelper::valid($permalink, $this->params)) {
         return $ajax->reject(JText::_('PLG_FIELDS_GROUP_PERMALINK_INVALID_PERMALINK'));
     }
     // Test if permalink exists
     if (SocialFieldsGroupPermalinkHelper::exists($permalink) && $permalink != $current) {
         return $ajax->reject(JText::_('PLG_FIELDS_GROUP_PERMALINK_NOT_AVAILABLE'));
     }
     $text = JText::_('PLG_FIELDS_GROUP_PERMALINK_AVAILABLE');
     return $ajax->resolve($text);
 }
Example #2
0
 /**
  * Performs validation for the gender field.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function validate($post, $group = null)
 {
     $key = $this->inputName;
     // Get the current value
     $value = isset($post[$key]) ? $post[$key] : '';
     if (!$this->isRequired() && empty($value)) {
         return true;
     }
     // Catch for errors if this is a required field.
     if ($this->isRequired() && empty($value)) {
         $this->setError(JText::_('PLG_FIELDS_GROUP_PERMALINK_REQUIRED'));
         return false;
     }
     if ($this->params->get('max') > 0 && JString::strlen($value) > $this->params->get('max')) {
         $this->setError(JText::_('PLG_FIELDS_GROUP_PERMALINK_EXCEEDED_MAX_LENGTH'));
         return false;
     }
     // Determine the current user that is being edited
     $current = '';
     if ($group) {
         $current = $group->id;
     }
     if ($current) {
         $group = FD::group($current);
         // If the permalink is the same, just return true.
         if ($group->alias == $value) {
             return true;
         }
     }
     if (SocialFieldsGroupPermalinkHelper::exists($value)) {
         $this->setError(JText::_('PLG_FIELDS_GROUP_PERMALINK_NOT_AVAILABLE'));
         return false;
     }
     if (!SocialFieldsGroupPermalinkHelper::valid($value, $this->params)) {
         $this->setError(JText::_('PLG_FIELDS_GROUP_PERMALINK_INVALID_PERMALINK'));
         return false;
     }
     return true;
 }