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 userid
     $userid = JRequest::getInt('userid', 0);
     // Set the current username
     $current = '';
     if (!empty($userid)) {
         $user = FD::user($userid);
         $current = $user->permalink;
     }
     // 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 (!SocialFieldsUserPermalinkHelper::valid($permalink, $this->params)) {
         return $ajax->reject(JText::_('PLG_FIELDS_PERMALINK_INVALID_PERMALINK'));
     }
     // Test if permalink exists
     if (SocialFieldsUserPermalinkHelper::exists($permalink, $current)) {
         return $ajax->reject(JText::_('PLG_FIELDS_PERMALINK_NOT_AVAILABLE'));
     }
     $text = JText::_('PLG_FIELDS_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($value, $user = null)
 {
     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_PERMALINK_REQUIRED'));
         return false;
     }
     if ($this->params->get('max') > 0 && JString::strlen($value) > $this->params->get('max')) {
         $this->setError(JText::_('PLG_FIELDS_PERMALINK_EXCEEDED_MAX_LENGTH'));
         return false;
     }
     // Determine the current user that is being edited
     $current = '';
     if (!empty($user)) {
         $current = $user->permalink;
     }
     if (SocialFieldsUserPermalinkHelper::exists($value, $current)) {
         $this->setError(JText::_('PLG_FIELDS_PERMALINK_NOT_AVAILABLE'));
         return false;
     }
     if (!SocialFieldsUserPermalinkHelper::valid($value, $this->params)) {
         $this->setError(JText::_('PLG_FIELDS_PERMALINK_INVALID_PERMALINK'));
         return false;
     }
     return true;
 }