id = $identifier; } else { $this->email = $identifier; } } } /** * Checks if provided string is a valid email address. * Used FILTER_VALIDATE_EMAIL filter for most part. * Additional regular expression check is used to make sure * that email structure is acceptable. * 1 or more characters before @ sign * 1 or more characters after @ sign * dot after 1 or more characters after @ sign * 2 or more characters after last dot * * @param sting $email Email address * * @return bool */ public static function isEmailAddressValid($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/', $email); } /** * Check if password is at least 6 characters long. * * @param string $password A trimmed password string. * * @return bool */ public static function isPasswordValid($password) { if (empty($password)) { return false; } if (is_callable('mb_strlen')) { $length = mb_strlen($password); } else { $length = strlen($password); } if ($length >= 6) { return true; } return false; } public function load($loader = NULL) { global $Dippler; if (!is_object($loader)) { $loader = $Dippler->backoffice->loadUser($this->idXML()); } if ($loader) { $this->type = "user"; $this->id = $loader->id[0][0]; $this->email = $loader->email[0][0]; $this->level = $loader->level[0][0]; $this->username = $loader->username[0][0]; $this->firstname = $loader->firstname[0][0]; $this->lastname = $loader->lastname[0][0]; $this->fullname = $this->firstname ." ". $this->lastname; } } public function changePassword($new_password) { global $Dippler; $this->new_password = $new_password; return $Dippler->backoffice->changePassword($this->dataXML()); } public function changeEmail() { global $Dippler; return $Dippler->backoffice->changeEmail($this->dataXML()); } public function approve() { global $Dippler; return $Dippler->backoffice->approveUser($this->dataXML()); } public function unapprove() { global $Dippler; return $Dippler->backoffice->unApproveUser($this->dataXML()); } public function changeRole() { global $Dippler; return $Dippler->backoffice->changeUserRole($this->dataXML()); } /** * Permanently removes a user from the system. * Administrator privileges are required. * * @return bool */ public function deleteUser() { global $Dippler; if ($Dippler->is_admin()) { return $Dippler->backoffice->deleteUser($this->dataXML()); } return false; } public function getURL() { return WWW_ROOT."profile/view/".$this->id; } public function getAvatarURL($size=20) { $default = WWW_ROOT."views/graphics/user.png"; return "http://www.gravatar.com/avatar/".md5(strtolower(trim($this->email)))."?d=".urlencode($default)."&s={$size}"; } /** * Returns edit URL. Uses cancel action to clear input_values * cache from session, just in case something is stuck there. * * @return string */ public function getEditURL() { return WWW_ROOT."actions/cancel.php?href=profile/view/{$this->id}/edit"; } public function getType() { return $this->type; } public function getId() { return $this->id; } public function getEmail() { return $this->email; } public function getLevel() { return $this->level; } public function getUsername() { return $this->username; } public function getFirstname() { return $this->firstname; } public function getLastname() { return $this->lastname; } public function getFullname() { return $this->fullname; } function idXML() { $data = ""; $data .= ""; if ($this->id) { $data .= "{$this->id}"; } else { $data .= "{$this->email}"; } $data .= ""; return $data; } function dataXML() { $data = ""; $data .= ""; $data .= "{$this->id}"; $data .= "email}]]>"; $data .= "{$this->level}"; if (isset($this->new_password) && $this->new_password) { $data .= "new_password}]]>"; } $data .= ""; return $data; } } ?>