@@ -13,84 +13,84 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public function __construct($params=array('rounds'=>7, 'salt_prefix'=>'$2y$')) { |
| 15 | 15 | |
| 16 | - if(CRYPT_BLOWFISH != 1) { |
|
| 17 | - throw new Exception("bcrypt not supported in this installation. See http://php.net/crypt"); |
|
| 18 | - } |
|
| 16 | + if(CRYPT_BLOWFISH != 1) { |
|
| 17 | + throw new Exception("bcrypt not supported in this installation. See http://php.net/crypt"); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - $this->rounds = $params['rounds']; |
|
| 21 | - $this->salt_prefix = $params['salt_prefix']; |
|
| 20 | + $this->rounds = $params['rounds']; |
|
| 21 | + $this->salt_prefix = $params['salt_prefix']; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function hash($input) { |
| 25 | - $hash = crypt($input, $this->getSalt()); |
|
| 25 | + $hash = crypt($input, $this->getSalt()); |
|
| 26 | 26 | |
| 27 | - if(strlen($hash) > 13) { |
|
| 28 | - return $hash; |
|
| 29 | - } |
|
| 27 | + if(strlen($hash) > 13) { |
|
| 28 | + return $hash; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return false; |
|
| 31 | + return false; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @param $input |
| 36 | 36 | * @param $existingHash |
| 37 | 37 | * @return bool |
| 38 | - */ |
|
| 38 | + */ |
|
| 39 | 39 | public function verify($input, $existingHash) { |
| 40 | - $hash = crypt($input, $existingHash); |
|
| 41 | - return $this->hashEquals($existingHash, $hash); |
|
| 40 | + $hash = crypt($input, $existingHash); |
|
| 41 | + return $this->hashEquals($existingHash, $hash); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | - * Polyfill for hash_equals() |
|
| 46 | - * Code mainly taken from hash_equals() compat function of CodeIgniter 3 |
|
| 47 | - * |
|
| 48 | - * @param string $known_string |
|
| 49 | - * @param string $user_string |
|
| 50 | - * @return bool |
|
| 51 | - */ |
|
| 45 | + * Polyfill for hash_equals() |
|
| 46 | + * Code mainly taken from hash_equals() compat function of CodeIgniter 3 |
|
| 47 | + * |
|
| 48 | + * @param string $known_string |
|
| 49 | + * @param string $user_string |
|
| 50 | + * @return bool |
|
| 51 | + */ |
|
| 52 | 52 | private function hashEquals($known_string, $user_string) |
| 53 | 53 | { |
| 54 | - // For CI3 or PHP >= 5.6 |
|
| 55 | - if (function_exists('hash_equals')) |
|
| 56 | - { |
|
| 57 | - return hash_equals($known_string, $user_string); |
|
| 58 | - } |
|
| 54 | + // For CI3 or PHP >= 5.6 |
|
| 55 | + if (function_exists('hash_equals')) |
|
| 56 | + { |
|
| 57 | + return hash_equals($known_string, $user_string); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - // For CI2 with PHP < 5.6 |
|
| 61 | - // Code from CI3 https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/compat/hash.php |
|
| 62 | - if ( ! is_string($known_string)) |
|
| 63 | - { |
|
| 64 | - trigger_error('hash_equals(): Expected known_string to be a string, '.strtolower(gettype($known_string)).' given', E_USER_WARNING); |
|
| 65 | - return FALSE; |
|
| 66 | - } |
|
| 67 | - elseif ( ! is_string($user_string)) |
|
| 68 | - { |
|
| 69 | - trigger_error('hash_equals(): Expected user_string to be a string, '.strtolower(gettype($user_string)).' given', E_USER_WARNING); |
|
| 70 | - return FALSE; |
|
| 71 | - } |
|
| 72 | - elseif (($length = strlen($known_string)) !== strlen($user_string)) |
|
| 73 | - { |
|
| 74 | - return FALSE; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $diff = 0; |
|
| 78 | - for ($i = 0; $i < $length; $i++) |
|
| 79 | - { |
|
| 80 | - $diff |= ord($known_string[$i]) ^ ord($user_string[$i]); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return ($diff === 0); |
|
| 60 | + // For CI2 with PHP < 5.6 |
|
| 61 | + // Code from CI3 https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/compat/hash.php |
|
| 62 | + if ( ! is_string($known_string)) |
|
| 63 | + { |
|
| 64 | + trigger_error('hash_equals(): Expected known_string to be a string, '.strtolower(gettype($known_string)).' given', E_USER_WARNING); |
|
| 65 | + return FALSE; |
|
| 66 | + } |
|
| 67 | + elseif ( ! is_string($user_string)) |
|
| 68 | + { |
|
| 69 | + trigger_error('hash_equals(): Expected user_string to be a string, '.strtolower(gettype($user_string)).' given', E_USER_WARNING); |
|
| 70 | + return FALSE; |
|
| 71 | + } |
|
| 72 | + elseif (($length = strlen($known_string)) !== strlen($user_string)) |
|
| 73 | + { |
|
| 74 | + return FALSE; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $diff = 0; |
|
| 78 | + for ($i = 0; $i < $length; $i++) |
|
| 79 | + { |
|
| 80 | + $diff |= ord($known_string[$i]) ^ ord($user_string[$i]); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + return ($diff === 0); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | private function getSalt() { |
| 87 | - $salt = sprintf($this->salt_prefix.'%02d$', $this->rounds); |
|
| 87 | + $salt = sprintf($this->salt_prefix.'%02d$', $this->rounds); |
|
| 88 | 88 | |
| 89 | - $bytes = $this->getRandomBytes(16); |
|
| 89 | + $bytes = $this->getRandomBytes(16); |
|
| 90 | 90 | |
| 91 | - $salt .= $this->encodeBytes($bytes); |
|
| 91 | + $salt .= $this->encodeBytes($bytes); |
|
| 92 | 92 | |
| 93 | - return $salt; |
|
| 93 | + return $salt; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | private $randomState; |
@@ -99,78 +99,78 @@ discard block |
||
| 99 | 99 | /** |
| 100 | 100 | * @param $count |
| 101 | 101 | * @return string |
| 102 | - */ |
|
| 102 | + */ |
|
| 103 | 103 | private function getRandomBytes($count) { |
| 104 | - $bytes = ''; |
|
| 105 | - |
|
| 106 | - if(function_exists('openssl_random_pseudo_bytes') && |
|
| 107 | - (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // OpenSSL slow on Win |
|
| 108 | - $bytes = openssl_random_pseudo_bytes($count); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if($bytes === '' && @is_readable('/dev/urandom') && |
|
| 112 | - ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) { |
|
| 113 | - $bytes = fread($hRand, $count); |
|
| 114 | - fclose($hRand); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if(strlen($bytes) < $count) { |
|
| 118 | - $bytes = ''; |
|
| 119 | - |
|
| 120 | - if($this->randomState === null) { |
|
| 121 | - $this->randomState = microtime(); |
|
| 122 | - if(function_exists('getmypid')) { |
|
| 123 | - $this->randomState .= getmypid(); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - for($i = 0; $i < $count; $i += 16) { |
|
| 128 | - $this->randomState = md5(microtime() . $this->randomState); |
|
| 129 | - |
|
| 130 | - if (PHP_VERSION >= '5') { |
|
| 131 | - $bytes .= md5($this->randomState, true); |
|
| 132 | - } else { |
|
| 133 | - $bytes .= pack('H*', md5($this->randomState)); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $bytes = substr($bytes, 0, $count); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $bytes; |
|
| 104 | + $bytes = ''; |
|
| 105 | + |
|
| 106 | + if(function_exists('openssl_random_pseudo_bytes') && |
|
| 107 | + (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // OpenSSL slow on Win |
|
| 108 | + $bytes = openssl_random_pseudo_bytes($count); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if($bytes === '' && @is_readable('/dev/urandom') && |
|
| 112 | + ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) { |
|
| 113 | + $bytes = fread($hRand, $count); |
|
| 114 | + fclose($hRand); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if(strlen($bytes) < $count) { |
|
| 118 | + $bytes = ''; |
|
| 119 | + |
|
| 120 | + if($this->randomState === null) { |
|
| 121 | + $this->randomState = microtime(); |
|
| 122 | + if(function_exists('getmypid')) { |
|
| 123 | + $this->randomState .= getmypid(); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + for($i = 0; $i < $count; $i += 16) { |
|
| 128 | + $this->randomState = md5(microtime() . $this->randomState); |
|
| 129 | + |
|
| 130 | + if (PHP_VERSION >= '5') { |
|
| 131 | + $bytes .= md5($this->randomState, true); |
|
| 132 | + } else { |
|
| 133 | + $bytes .= pack('H*', md5($this->randomState)); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $bytes = substr($bytes, 0, $count); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $bytes; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | 144 | * @param $input |
| 145 | 145 | * @return string |
| 146 | - */ |
|
| 146 | + */ |
|
| 147 | 147 | private function encodeBytes($input) { |
| 148 | - // The following is code from the PHP Password Hashing Framework |
|
| 149 | - $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
| 150 | - |
|
| 151 | - $output = ''; |
|
| 152 | - $i = 0; |
|
| 153 | - do { |
|
| 154 | - $c1 = ord($input[$i++]); |
|
| 155 | - $output .= $itoa64[$c1 >> 2]; |
|
| 156 | - $c1 = ($c1 & 0x03) << 4; |
|
| 157 | - if ($i >= 16) { |
|
| 158 | - $output .= $itoa64[$c1]; |
|
| 159 | - break; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $c2 = ord($input[$i++]); |
|
| 163 | - $c1 |= $c2 >> 4; |
|
| 164 | - $output .= $itoa64[$c1]; |
|
| 165 | - $c1 = ($c2 & 0x0f) << 2; |
|
| 166 | - |
|
| 167 | - $c2 = ord($input[$i++]); |
|
| 168 | - $c1 |= $c2 >> 6; |
|
| 169 | - $output .= $itoa64[$c1]; |
|
| 170 | - $output .= $itoa64[$c2 & 0x3f]; |
|
| 171 | - } while (1); |
|
| 172 | - |
|
| 173 | - return $output; |
|
| 148 | + // The following is code from the PHP Password Hashing Framework |
|
| 149 | + $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
| 150 | + |
|
| 151 | + $output = ''; |
|
| 152 | + $i = 0; |
|
| 153 | + do { |
|
| 154 | + $c1 = ord($input[$i++]); |
|
| 155 | + $output .= $itoa64[$c1 >> 2]; |
|
| 156 | + $c1 = ($c1 & 0x03) << 4; |
|
| 157 | + if ($i >= 16) { |
|
| 158 | + $output .= $itoa64[$c1]; |
|
| 159 | + break; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $c2 = ord($input[$i++]); |
|
| 163 | + $c1 |= $c2 >> 4; |
|
| 164 | + $output .= $itoa64[$c1]; |
|
| 165 | + $c1 = ($c2 & 0x0f) << 2; |
|
| 166 | + |
|
| 167 | + $c2 = ord($input[$i++]); |
|
| 168 | + $c1 |= $c2 >> 6; |
|
| 169 | + $output .= $itoa64[$c1]; |
|
| 170 | + $output .= $itoa64[$c2 & 0x3f]; |
|
| 171 | + } while (1); |
|
| 172 | + |
|
| 173 | + return $output; |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | if ( $this->ion_auth_model->forgotten_password($identity) ) //changed |
| 134 | 134 | { |
| 135 | 135 | // Get user information |
| 136 | - $identifier = $this->ion_auth_model->identity_column; // use model identity column, so it can be overridden in a controller |
|
| 137 | - $user = $this->where($identifier, $identity)->where('active', 1)->users()->row(); // changed to get_user_by_identity from email |
|
| 136 | + $identifier = $this->ion_auth_model->identity_column; // use model identity column, so it can be overridden in a controller |
|
| 137 | + $user = $this->where($identifier, $identity)->where('active', 1)->users()->row(); // changed to get_user_by_identity from email |
|
| 138 | 138 | |
| 139 | 139 | if ($user) |
| 140 | 140 | { |
@@ -388,14 +388,14 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | $identity = $this->config->item('identity', 'ion_auth'); |
| 390 | 390 | |
| 391 | - if (substr(CI_VERSION, 0, 1) == '2') |
|
| 391 | + if (substr(CI_VERSION, 0, 1) == '2') |
|
| 392 | 392 | { |
| 393 | 393 | $this->session->unset_userdata( array($identity => '', 'id' => '', 'user_id' => '') ); |
| 394 | - } |
|
| 395 | - else |
|
| 396 | - { |
|
| 397 | - $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
|
| 398 | - } |
|
| 394 | + } |
|
| 395 | + else |
|
| 396 | + { |
|
| 397 | + $this->session->unset_userdata( array($identity, 'id', 'user_id') ); |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | 400 | // delete the remember me cookies if they exist |
| 401 | 401 | if (get_cookie($this->config->item('identity_cookie_name', 'ion_auth'))) |
@@ -437,15 +437,15 @@ discard block |
||
| 437 | 437 | { |
| 438 | 438 | $this->ion_auth_model->trigger_events('logged_in'); |
| 439 | 439 | |
| 440 | - $recheck= $this->ion_auth_model->recheck_session(); |
|
| 440 | + $recheck= $this->ion_auth_model->recheck_session(); |
|
| 441 | 441 | |
| 442 | - //auto-login the user if they are remembered |
|
| 443 | - if ( ! $recheck && get_cookie($this->config->item('identity_cookie_name', 'ion_auth')) && get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) |
|
| 442 | + //auto-login the user if they are remembered |
|
| 443 | + if ( ! $recheck && get_cookie($this->config->item('identity_cookie_name', 'ion_auth')) && get_cookie($this->config->item('remember_cookie_name', 'ion_auth'))) |
|
| 444 | 444 | { |
| 445 | 445 | $recheck = $this->ion_auth_model->login_remembered_user(); |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | - return $recheck; |
|
| 448 | + return $recheck; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -23,487 +23,487 @@ |
||
| 23 | 23 | |
| 24 | 24 | class Gravatar { |
| 25 | 25 | |
| 26 | - protected $defaults; |
|
| 27 | - |
|
| 28 | - protected $gravatar_base_url; |
|
| 29 | - protected $gravatar_secure_base_url; |
|
| 30 | - protected $gravatar_image_extension; |
|
| 31 | - protected $gravatar_image_size; |
|
| 32 | - protected $gravatar_default_image; |
|
| 33 | - protected $gravatar_force_default_image; |
|
| 34 | - protected $gravatar_rating ; |
|
| 35 | - protected $gravatar_useragent; |
|
| 26 | + protected $defaults; |
|
| 27 | + |
|
| 28 | + protected $gravatar_base_url; |
|
| 29 | + protected $gravatar_secure_base_url; |
|
| 30 | + protected $gravatar_image_extension; |
|
| 31 | + protected $gravatar_image_size; |
|
| 32 | + protected $gravatar_default_image; |
|
| 33 | + protected $gravatar_force_default_image; |
|
| 34 | + protected $gravatar_rating ; |
|
| 35 | + protected $gravatar_useragent; |
|
| 36 | 36 | |
| 37 | - protected $last_error = GRAVATAR_NO_ERROR; |
|
| 38 | - |
|
| 39 | - protected $is_https; |
|
| 40 | - protected $curl_exists; |
|
| 41 | - protected $allow_url_fopen; |
|
| 42 | - |
|
| 43 | - public function __construct($config = array()) { |
|
| 44 | - |
|
| 45 | - $this->defaults = array( |
|
| 46 | - 'gravatar_base_url' => 'http://www.gravatar.com/', |
|
| 47 | - 'gravatar_secure_base_url' => 'https://secure.gravatar.com/', |
|
| 48 | - 'gravatar_image_extension' => '.png', |
|
| 49 | - 'gravatar_image_size' => 80, |
|
| 50 | - 'gravatar_default_image' => '', |
|
| 51 | - 'gravatar_force_default_image' => false, |
|
| 52 | - 'gravatar_rating' => '', |
|
| 53 | - 'gravatar_useragent' => 'PHP Gravatar Library', |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - $this->is_https = $this->is_https(); |
|
| 57 | - $this->curl_exists = function_exists('curl_init'); |
|
| 58 | - $allow_url_fopen = @ini_get('allow_url_fopen'); |
|
| 59 | - $allow_url_fopen = $allow_url_fopen === false || in_array(strtolower($allow_url_fopen), array('on', 'true', '1')); |
|
| 60 | - $this->allow_url_fopen = $allow_url_fopen; |
|
| 61 | - |
|
| 62 | - if (!is_array($config)) { |
|
| 63 | - $config = array(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $this->defaults = array_merge($this->defaults, $config); |
|
| 67 | - $this->initialize($this->defaults); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function initialize($config = array()) { |
|
| 71 | - |
|
| 72 | - if (!is_array($config)) { |
|
| 73 | - $config = array(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - foreach ($config as $key => $value) { |
|
| 77 | - $this->{$key} = $value; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $this->gravatar_base_url = (string) $this->gravatar_base_url; |
|
| 81 | - $this->gravatar_secure_base_url = (string) $this->gravatar_secure_base_url; |
|
| 82 | - $this->gravatar_image_extension = (string) $this->gravatar_image_extension; |
|
| 83 | - |
|
| 84 | - $this->gravatar_image_size = (int) $this->gravatar_image_size; |
|
| 85 | - |
|
| 86 | - if ($this->gravatar_image_size <= 0) { |
|
| 87 | - $this->gravatar_image_size = 80; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $this->gravatar_default_image = (string) $this->gravatar_default_image; |
|
| 91 | - $this->gravatar_force_default_image = !empty($this->gravatar_force_default_image); |
|
| 92 | - $this->gravatar_rating = (string) $this->gravatar_rating; |
|
| 93 | - $this->gravatar_useragent = (string) $this->gravatar_useragent; |
|
| 94 | - |
|
| 95 | - return $this; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - public function reset() { |
|
| 99 | - |
|
| 100 | - $this->initialize($this->defaults); |
|
| 101 | - |
|
| 102 | - return $this; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function get_defaults() { |
|
| 106 | - |
|
| 107 | - return $this->defaults; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Creates a URL for requesting a Gravatar image. |
|
| 112 | - * @link http://en.gravatar.com/site/implement/images/ |
|
| 113 | - * |
|
| 114 | - * @param string $email A registered email. |
|
| 115 | - * @param int $size The requested size of the avarar in pixels (a square image). |
|
| 116 | - * @param string $default_image The fallback image option: '', '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'. |
|
| 117 | - * @param bool $force_default_image Enforces the fallback image to be shown. |
|
| 118 | - * @param string $rating The level of allowed self-rate of the avatar: '', 'g' (default), 'pg', 'r', 'x'. |
|
| 119 | - * @return string Returns the URL of the avatar to be requested. |
|
| 120 | - * |
|
| 121 | - * When optional parameters are not set, their default values are taken |
|
| 122 | - * from the configuration file application/config/gravatar.php |
|
| 123 | - */ |
|
| 124 | - public function get($email, $size = null, $default_image = null, $force_default_image = null, $rating = null) { |
|
| 125 | - |
|
| 126 | - $url = ($this->is_https ? $this->gravatar_secure_base_url : $this->gravatar_base_url).'avatar/'.$this->create_hash($email).$this->gravatar_image_extension; |
|
| 127 | - |
|
| 128 | - $query = array(); |
|
| 129 | - |
|
| 130 | - $size = (int) $size; |
|
| 37 | + protected $last_error = GRAVATAR_NO_ERROR; |
|
| 38 | + |
|
| 39 | + protected $is_https; |
|
| 40 | + protected $curl_exists; |
|
| 41 | + protected $allow_url_fopen; |
|
| 42 | + |
|
| 43 | + public function __construct($config = array()) { |
|
| 44 | + |
|
| 45 | + $this->defaults = array( |
|
| 46 | + 'gravatar_base_url' => 'http://www.gravatar.com/', |
|
| 47 | + 'gravatar_secure_base_url' => 'https://secure.gravatar.com/', |
|
| 48 | + 'gravatar_image_extension' => '.png', |
|
| 49 | + 'gravatar_image_size' => 80, |
|
| 50 | + 'gravatar_default_image' => '', |
|
| 51 | + 'gravatar_force_default_image' => false, |
|
| 52 | + 'gravatar_rating' => '', |
|
| 53 | + 'gravatar_useragent' => 'PHP Gravatar Library', |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + $this->is_https = $this->is_https(); |
|
| 57 | + $this->curl_exists = function_exists('curl_init'); |
|
| 58 | + $allow_url_fopen = @ini_get('allow_url_fopen'); |
|
| 59 | + $allow_url_fopen = $allow_url_fopen === false || in_array(strtolower($allow_url_fopen), array('on', 'true', '1')); |
|
| 60 | + $this->allow_url_fopen = $allow_url_fopen; |
|
| 61 | + |
|
| 62 | + if (!is_array($config)) { |
|
| 63 | + $config = array(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $this->defaults = array_merge($this->defaults, $config); |
|
| 67 | + $this->initialize($this->defaults); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function initialize($config = array()) { |
|
| 71 | + |
|
| 72 | + if (!is_array($config)) { |
|
| 73 | + $config = array(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + foreach ($config as $key => $value) { |
|
| 77 | + $this->{$key} = $value; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $this->gravatar_base_url = (string) $this->gravatar_base_url; |
|
| 81 | + $this->gravatar_secure_base_url = (string) $this->gravatar_secure_base_url; |
|
| 82 | + $this->gravatar_image_extension = (string) $this->gravatar_image_extension; |
|
| 83 | + |
|
| 84 | + $this->gravatar_image_size = (int) $this->gravatar_image_size; |
|
| 85 | + |
|
| 86 | + if ($this->gravatar_image_size <= 0) { |
|
| 87 | + $this->gravatar_image_size = 80; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $this->gravatar_default_image = (string) $this->gravatar_default_image; |
|
| 91 | + $this->gravatar_force_default_image = !empty($this->gravatar_force_default_image); |
|
| 92 | + $this->gravatar_rating = (string) $this->gravatar_rating; |
|
| 93 | + $this->gravatar_useragent = (string) $this->gravatar_useragent; |
|
| 94 | + |
|
| 95 | + return $this; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + public function reset() { |
|
| 99 | + |
|
| 100 | + $this->initialize($this->defaults); |
|
| 101 | + |
|
| 102 | + return $this; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function get_defaults() { |
|
| 106 | + |
|
| 107 | + return $this->defaults; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Creates a URL for requesting a Gravatar image. |
|
| 112 | + * @link http://en.gravatar.com/site/implement/images/ |
|
| 113 | + * |
|
| 114 | + * @param string $email A registered email. |
|
| 115 | + * @param int $size The requested size of the avarar in pixels (a square image). |
|
| 116 | + * @param string $default_image The fallback image option: '', '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'. |
|
| 117 | + * @param bool $force_default_image Enforces the fallback image to be shown. |
|
| 118 | + * @param string $rating The level of allowed self-rate of the avatar: '', 'g' (default), 'pg', 'r', 'x'. |
|
| 119 | + * @return string Returns the URL of the avatar to be requested. |
|
| 120 | + * |
|
| 121 | + * When optional parameters are not set, their default values are taken |
|
| 122 | + * from the configuration file application/config/gravatar.php |
|
| 123 | + */ |
|
| 124 | + public function get($email, $size = null, $default_image = null, $force_default_image = null, $rating = null) { |
|
| 125 | + |
|
| 126 | + $url = ($this->is_https ? $this->gravatar_secure_base_url : $this->gravatar_base_url).'avatar/'.$this->create_hash($email).$this->gravatar_image_extension; |
|
| 127 | + |
|
| 128 | + $query = array(); |
|
| 129 | + |
|
| 130 | + $size = (int) $size; |
|
| 131 | 131 | |
| 132 | - if ($size <= 0) { |
|
| 133 | - $size = $this->gravatar_image_size; |
|
| 134 | - } |
|
| 132 | + if ($size <= 0) { |
|
| 133 | + $size = $this->gravatar_image_size; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - if ($size > 0) { |
|
| 137 | - $query['s'] = $size; |
|
| 138 | - } |
|
| 136 | + if ($size > 0) { |
|
| 137 | + $query['s'] = $size; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if (isset($default_image)) { |
|
| 141 | - $default_image = (string) $default_image; |
|
| 142 | - } else { |
|
| 143 | - $default_image = $this->gravatar_default_image; |
|
| 144 | - } |
|
| 140 | + if (isset($default_image)) { |
|
| 141 | + $default_image = (string) $default_image; |
|
| 142 | + } else { |
|
| 143 | + $default_image = $this->gravatar_default_image; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - if ($default_image != '') { |
|
| 147 | - $query['d'] = $default_image; |
|
| 148 | - } |
|
| 146 | + if ($default_image != '') { |
|
| 147 | + $query['d'] = $default_image; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - if (isset($force_default_image)) { |
|
| 151 | - $force_default_image = !empty($force_default_image); |
|
| 152 | - } else { |
|
| 153 | - $force_default_image = $this->gravatar_force_default_image; |
|
| 154 | - } |
|
| 150 | + if (isset($force_default_image)) { |
|
| 151 | + $force_default_image = !empty($force_default_image); |
|
| 152 | + } else { |
|
| 153 | + $force_default_image = $this->gravatar_force_default_image; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - if ($force_default_image) { |
|
| 157 | - $query['f'] = 'y'; |
|
| 158 | - } |
|
| 156 | + if ($force_default_image) { |
|
| 157 | + $query['f'] = 'y'; |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - if (isset($rating)) { |
|
| 161 | - $rating = (string) $rating; |
|
| 162 | - } else { |
|
| 163 | - $rating = $this->gravatar_rating; |
|
| 164 | - } |
|
| 160 | + if (isset($rating)) { |
|
| 161 | + $rating = (string) $rating; |
|
| 162 | + } else { |
|
| 163 | + $rating = $this->gravatar_rating; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - if ($rating != '') { |
|
| 167 | - $query['r'] = $rating; |
|
| 168 | - } |
|
| 166 | + if ($rating != '') { |
|
| 167 | + $query['r'] = $rating; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - if (!empty($query)) { |
|
| 171 | - $url = $url.'?'.http_build_query($query); |
|
| 172 | - } |
|
| 170 | + if (!empty($query)) { |
|
| 171 | + $url = $url.'?'.http_build_query($query); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - return $url; |
|
| 175 | - } |
|
| 174 | + return $url; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Executes a request for Gravatar profile data and returns it as a multidimensional array. |
|
| 179 | - * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 180 | - * |
|
| 181 | - * @param string $email A registered email. |
|
| 182 | - * @return array/null Received profile data. |
|
| 183 | - */ |
|
| 184 | - public function get_profile_data($email) { |
|
| 177 | + /** |
|
| 178 | + * Executes a request for Gravatar profile data and returns it as a multidimensional array. |
|
| 179 | + * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 180 | + * |
|
| 181 | + * @param string $email A registered email. |
|
| 182 | + * @return array/null Received profile data. |
|
| 183 | + */ |
|
| 184 | + public function get_profile_data($email) { |
|
| 185 | 185 | |
| 186 | - $result = $this->execute_profile_request($email, 'php'); |
|
| 186 | + $result = $this->execute_profile_request($email, 'php'); |
|
| 187 | 187 | |
| 188 | - if ($this->last_error != GRAVATAR_NO_ERROR) { |
|
| 189 | - return null; |
|
| 190 | - } |
|
| 188 | + if ($this->last_error != GRAVATAR_NO_ERROR) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - $result = @ unserialize($result); |
|
| 192 | + $result = @ unserialize($result); |
|
| 193 | 193 | |
| 194 | - if ($result === false) { |
|
| 194 | + if ($result === false) { |
|
| 195 | 195 | |
| 196 | - $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 197 | - return null; |
|
| 198 | - } |
|
| 196 | + $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 197 | + return null; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - if (!is_array($result)) { |
|
| 200 | + if (!is_array($result)) { |
|
| 201 | 201 | |
| 202 | - $this->last_error = GRAVATAR_PROFILE_DOES_NOT_EXIST; |
|
| 203 | - return null; |
|
| 204 | - } |
|
| 202 | + $this->last_error = GRAVATAR_PROFILE_DOES_NOT_EXIST; |
|
| 203 | + return null; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - if (!isset($result['entry']) || !isset($result['entry'][0])) { |
|
| 206 | + if (!isset($result['entry']) || !isset($result['entry'][0])) { |
|
| 207 | 207 | |
| 208 | - $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 209 | - return null; |
|
| 210 | - } |
|
| 208 | + $this->last_error = GRAVATAR_INCORRECT_FORMAT; |
|
| 209 | + return null; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - return $result['entry'][0]; |
|
| 213 | - } |
|
| 212 | + return $result['entry'][0]; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Executes a request for Gravatar profile data and returns raw received response. |
|
| 217 | - * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 218 | - * |
|
| 219 | - * @param string $email A registered email. |
|
| 220 | - * @param string $format '', 'json', 'xml', 'php', 'vcf', 'qr'. |
|
| 221 | - * @return string/null Received profile raw data. |
|
| 222 | - */ |
|
| 223 | - public function execute_profile_request($email, $format = null) { |
|
| 215 | + /** |
|
| 216 | + * Executes a request for Gravatar profile data and returns raw received response. |
|
| 217 | + * @link https://en.gravatar.com/site/implement/profiles/ |
|
| 218 | + * |
|
| 219 | + * @param string $email A registered email. |
|
| 220 | + * @param string $format '', 'json', 'xml', 'php', 'vcf', 'qr'. |
|
| 221 | + * @return string/null Received profile raw data. |
|
| 222 | + */ |
|
| 223 | + public function execute_profile_request($email, $format = null) { |
|
| 224 | 224 | |
| 225 | - $this->last_error = GRAVATAR_NO_ERROR; |
|
| 225 | + $this->last_error = GRAVATAR_NO_ERROR; |
|
| 226 | 226 | |
| 227 | - if (function_exists('valid_email')) { |
|
| 227 | + if (function_exists('valid_email')) { |
|
| 228 | 228 | |
| 229 | - if (!valid_email($email)) { |
|
| 229 | + if (!valid_email($email)) { |
|
| 230 | 230 | |
| 231 | - $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 232 | - return null; |
|
| 233 | - } |
|
| 231 | + $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 232 | + return null; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - } else { |
|
| 235 | + } else { |
|
| 236 | 236 | |
| 237 | - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 237 | + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 238 | 238 | |
| 239 | - $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 240 | - return null; |
|
| 241 | - } |
|
| 242 | - } |
|
| 239 | + $this->last_error = GRAVATAR_INVALID_EMAIL; |
|
| 240 | + return null; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - $format = trim($format); |
|
| 244 | + $format = trim($format); |
|
| 245 | 245 | |
| 246 | - if ($format != '') { |
|
| 247 | - $format = '.'.ltrim($format, '.'); |
|
| 248 | - } |
|
| 246 | + if ($format != '') { |
|
| 247 | + $format = '.'.ltrim($format, '.'); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - $result = null; |
|
| 250 | + $result = null; |
|
| 251 | 251 | |
| 252 | - if ($this->curl_exists) { |
|
| 252 | + if ($this->curl_exists) { |
|
| 253 | 253 | |
| 254 | - $url = $this->gravatar_secure_base_url.$this->create_hash($email).$format; |
|
| 254 | + $url = $this->gravatar_secure_base_url.$this->create_hash($email).$format; |
|
| 255 | 255 | |
| 256 | - $ch = curl_init(); |
|
| 256 | + $ch = curl_init(); |
|
| 257 | 257 | |
| 258 | - $options = array( |
|
| 259 | - CURLOPT_USERAGENT, $this->gravatar_useragent, |
|
| 260 | - CURLOPT_RETURNTRANSFER => true, |
|
| 261 | - CURLOPT_POST => true, |
|
| 262 | - CURLOPT_POSTFIELDS => array(), |
|
| 263 | - CURLOPT_URL => $url, |
|
| 264 | - CURLOPT_TIMEOUT => 3, |
|
| 265 | - ); |
|
| 258 | + $options = array( |
|
| 259 | + CURLOPT_USERAGENT, $this->gravatar_useragent, |
|
| 260 | + CURLOPT_RETURNTRANSFER => true, |
|
| 261 | + CURLOPT_POST => true, |
|
| 262 | + CURLOPT_POSTFIELDS => array(), |
|
| 263 | + CURLOPT_URL => $url, |
|
| 264 | + CURLOPT_TIMEOUT => 3, |
|
| 265 | + ); |
|
| 266 | 266 | |
| 267 | - if (!ini_get('safe_mode') && !ini_get('open_basedir')) { |
|
| 268 | - $options[CURLOPT_FOLLOWLOCATION] = true; |
|
| 269 | - } |
|
| 267 | + if (!ini_get('safe_mode') && !ini_get('open_basedir')) { |
|
| 268 | + $options[CURLOPT_FOLLOWLOCATION] = true; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - curl_setopt_array($ch, $options); |
|
| 271 | + curl_setopt_array($ch, $options); |
|
| 272 | 272 | |
| 273 | - $result = curl_exec($ch); |
|
| 273 | + $result = curl_exec($ch); |
|
| 274 | 274 | |
| 275 | - $code = @ curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 275 | + $code = @ curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
| 276 | 276 | |
| 277 | - @ curl_close($ch); |
|
| 277 | + @ curl_close($ch); |
|
| 278 | 278 | |
| 279 | - if ($code != 200) { |
|
| 279 | + if ($code != 200) { |
|
| 280 | 280 | |
| 281 | - $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 282 | - return null; |
|
| 283 | - } |
|
| 281 | + $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 282 | + return null; |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - } elseif ($this->allow_url_fopen) { |
|
| 285 | + } elseif ($this->allow_url_fopen) { |
|
| 286 | 286 | |
| 287 | - $url = $this->gravatar_base_url.$this->create_hash($email).$format; |
|
| 287 | + $url = $this->gravatar_base_url.$this->create_hash($email).$format; |
|
| 288 | 288 | |
| 289 | - $options = array( |
|
| 290 | - 'http' => array( |
|
| 291 | - 'method' => 'GET', |
|
| 292 | - 'useragent' => $this->gravatar_useragent, |
|
| 293 | - ), |
|
| 294 | - ); |
|
| 289 | + $options = array( |
|
| 290 | + 'http' => array( |
|
| 291 | + 'method' => 'GET', |
|
| 292 | + 'useragent' => $this->gravatar_useragent, |
|
| 293 | + ), |
|
| 294 | + ); |
|
| 295 | 295 | |
| 296 | - $context = stream_context_create($options); |
|
| 296 | + $context = stream_context_create($options); |
|
| 297 | 297 | |
| 298 | - $result = @ file_get_contents($url, false, $context); |
|
| 298 | + $result = @ file_get_contents($url, false, $context); |
|
| 299 | 299 | |
| 300 | - } else { |
|
| 300 | + } else { |
|
| 301 | 301 | |
| 302 | - $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 303 | - return null; |
|
| 304 | - } |
|
| 302 | + $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 303 | + return null; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - if ($result === false) { |
|
| 306 | + if ($result === false) { |
|
| 307 | 307 | |
| 308 | - $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 309 | - return null; |
|
| 310 | - } |
|
| 308 | + $this->last_error = GRAVATAR_CANT_CONNECT; |
|
| 309 | + return null; |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - return $result; |
|
| 313 | - } |
|
| 312 | + return $result; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * Returns the error code as a result of the last profile request operation. |
|
| 317 | - * |
|
| 318 | - * @return int GRAVATAR_NO_ERROR - the last operation was successfull, |
|
| 319 | - * other returned value indicates failure. |
|
| 320 | - */ |
|
| 321 | - public function last_error() { |
|
| 315 | + /** |
|
| 316 | + * Returns the error code as a result of the last profile request operation. |
|
| 317 | + * |
|
| 318 | + * @return int GRAVATAR_NO_ERROR - the last operation was successfull, |
|
| 319 | + * other returned value indicates failure. |
|
| 320 | + */ |
|
| 321 | + public function last_error() { |
|
| 322 | 322 | |
| 323 | - return $this->last_error; |
|
| 324 | - } |
|
| 323 | + return $this->last_error; |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * Creates a hash value from a provided e-mail address. |
|
| 328 | - * @link https://en.gravatar.com/site/implement/hash/ |
|
| 329 | - * |
|
| 330 | - * @param string $email A registered email. |
|
| 331 | - * @return string/null The hash for accessing the avatar or profile data. |
|
| 332 | - */ |
|
| 333 | - public function create_hash($email) { |
|
| 334 | - |
|
| 335 | - return md5(strtolower(trim($email))); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - protected function is_https() { |
|
| 339 | - |
|
| 340 | - if (function_exists('is_https')) { |
|
| 341 | - return is_https(); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
| 345 | - return true; |
|
| 346 | - } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 347 | - return true; |
|
| 348 | - } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
| 349 | - return true; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - return false; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - //-------------------------------------------------------------------------- |
|
| 356 | - // The following original methods are kept here for backward compatibility. |
|
| 357 | - // Consider them as deprecated. |
|
| 358 | - //-------------------------------------------------------------------------- |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Set the email to be used, converting it into an md5 hash as required by gravatar.com |
|
| 363 | - * |
|
| 364 | - * @param string $email |
|
| 365 | - * |
|
| 366 | - * @return string|null Email hash or if email didn't validate then return NULL |
|
| 367 | - * |
|
| 368 | - * @deprecated |
|
| 369 | - */ |
|
| 370 | - public function set_email($email) |
|
| 371 | - { |
|
| 372 | - $email = trim(strtolower($email)); |
|
| 373 | - |
|
| 374 | - if ( ! filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) |
|
| 375 | - { |
|
| 376 | - return md5($email); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - return NULL; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * get_gravatar_url |
|
| 384 | - * |
|
| 385 | - * @see http://en.gravatar.com/site/implement/images/ for available options |
|
| 386 | - * |
|
| 387 | - * @param string $rating defaults to g |
|
| 388 | - * @param string $size defaults to 80 |
|
| 389 | - * @param string $default_image default sets can be found on the above link |
|
| 390 | - * @param boolean $secure set to TRUE if a secure url is required |
|
| 391 | - * |
|
| 392 | - * @return string gratavar url |
|
| 393 | - * |
|
| 394 | - * @deprecated |
|
| 395 | - */ |
|
| 396 | - public function get_gravatar($email, $rating = NULL, $size = NULL, $default_image = NULL, $secure = NULL) |
|
| 397 | - { |
|
| 398 | - $hash = $this->set_email($email); |
|
| 399 | - |
|
| 400 | - if ($hash === NULL) |
|
| 401 | - { |
|
| 402 | - // $hash has to be set to a value so the gravatar site can return a default image |
|
| 403 | - $hash = 'invalid_email'; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - $query_string = NULL; |
|
| 407 | - $options = array(); |
|
| 408 | - |
|
| 409 | - if ($rating !== NULL) |
|
| 410 | - { |
|
| 411 | - $options['r'] = $rating; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - if ($size !== NULL) |
|
| 415 | - { |
|
| 416 | - $options['s'] = $size; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - if ($default_image !== NULL) |
|
| 420 | - { |
|
| 421 | - $options['d'] = urlencode($default_image); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - if (count($options) > 0) |
|
| 425 | - { |
|
| 426 | - $query_string = '?'. http_build_query($options); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - if ($secure !== NULL) |
|
| 430 | - { |
|
| 431 | - $base = $this->gravatar_secure_base_url; |
|
| 432 | - } |
|
| 433 | - else |
|
| 434 | - { |
|
| 435 | - $base = $this->gravatar_base_url; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $base .'avatar/'. $hash . $query_string; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Grab the full profile data for a given email from gravatar.com in xml format |
|
| 443 | - * |
|
| 444 | - * @param string $email |
|
| 445 | - * @param string fetch_method defaults to file, 'curl' is the other option |
|
| 446 | - * |
|
| 447 | - * @return object|null $xml->entry on success, NULL on an error |
|
| 448 | - * |
|
| 449 | - * @deprecated |
|
| 450 | - */ |
|
| 451 | - public function get_profile($email, $fetch_method = 'file') |
|
| 452 | - { |
|
| 453 | - $hash = $this->set_email($email); |
|
| 454 | - |
|
| 455 | - if ($hash === NULL) |
|
| 456 | - { |
|
| 457 | - // A hash value of NULL will return no xml so the method returns NULL |
|
| 458 | - return NULL; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - libxml_use_internal_errors(TRUE); |
|
| 462 | - |
|
| 463 | - if ($fetch_method === 'file') |
|
| 464 | - { |
|
| 465 | - if (ini_get('allow_url_fopen') == FALSE) |
|
| 466 | - { |
|
| 467 | - return NULL; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $str = file_get_contents($this->gravatar_base_url . $hash .'.xml'); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - if ($fetch_method === 'curl') |
|
| 474 | - { |
|
| 475 | - if ( ! function_exists('curl_init')) |
|
| 476 | - { |
|
| 477 | - return NULL; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - $ch = curl_init(); |
|
| 481 | - $options = array( |
|
| 482 | - CURLOPT_RETURNTRANSFER => TRUE, |
|
| 483 | - CURLOPT_POST => TRUE, |
|
| 484 | - CURLOPT_URL => $this->gravatar_secure_base_url . $hash .'.xml', |
|
| 485 | - CURLOPT_TIMEOUT => 3 |
|
| 486 | - ); |
|
| 487 | - curl_setopt_array($ch, $options); |
|
| 488 | - $str = curl_exec($ch); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - $xml = simplexml_load_string($str); |
|
| 492 | - |
|
| 493 | - if ($xml === FALSE) |
|
| 494 | - { |
|
| 495 | - $errors = array(); |
|
| 496 | - foreach(libxml_get_errors() as $error) |
|
| 497 | - { |
|
| 498 | - $errors[] = $error->message.'\n'; |
|
| 499 | - } |
|
| 500 | - $error_string = implode('\n', $errors); |
|
| 501 | - throw new Exception('Failed loading XML\n'. $error_string); |
|
| 502 | - } |
|
| 503 | - else |
|
| 504 | - { |
|
| 505 | - return $xml->entry; |
|
| 506 | - } |
|
| 507 | - } |
|
| 326 | + /** |
|
| 327 | + * Creates a hash value from a provided e-mail address. |
|
| 328 | + * @link https://en.gravatar.com/site/implement/hash/ |
|
| 329 | + * |
|
| 330 | + * @param string $email A registered email. |
|
| 331 | + * @return string/null The hash for accessing the avatar or profile data. |
|
| 332 | + */ |
|
| 333 | + public function create_hash($email) { |
|
| 334 | + |
|
| 335 | + return md5(strtolower(trim($email))); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + protected function is_https() { |
|
| 339 | + |
|
| 340 | + if (function_exists('is_https')) { |
|
| 341 | + return is_https(); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { |
|
| 345 | + return true; |
|
| 346 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 347 | + return true; |
|
| 348 | + } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { |
|
| 349 | + return true; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + return false; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + //-------------------------------------------------------------------------- |
|
| 356 | + // The following original methods are kept here for backward compatibility. |
|
| 357 | + // Consider them as deprecated. |
|
| 358 | + //-------------------------------------------------------------------------- |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Set the email to be used, converting it into an md5 hash as required by gravatar.com |
|
| 363 | + * |
|
| 364 | + * @param string $email |
|
| 365 | + * |
|
| 366 | + * @return string|null Email hash or if email didn't validate then return NULL |
|
| 367 | + * |
|
| 368 | + * @deprecated |
|
| 369 | + */ |
|
| 370 | + public function set_email($email) |
|
| 371 | + { |
|
| 372 | + $email = trim(strtolower($email)); |
|
| 373 | + |
|
| 374 | + if ( ! filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) |
|
| 375 | + { |
|
| 376 | + return md5($email); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + return NULL; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * get_gravatar_url |
|
| 384 | + * |
|
| 385 | + * @see http://en.gravatar.com/site/implement/images/ for available options |
|
| 386 | + * |
|
| 387 | + * @param string $rating defaults to g |
|
| 388 | + * @param string $size defaults to 80 |
|
| 389 | + * @param string $default_image default sets can be found on the above link |
|
| 390 | + * @param boolean $secure set to TRUE if a secure url is required |
|
| 391 | + * |
|
| 392 | + * @return string gratavar url |
|
| 393 | + * |
|
| 394 | + * @deprecated |
|
| 395 | + */ |
|
| 396 | + public function get_gravatar($email, $rating = NULL, $size = NULL, $default_image = NULL, $secure = NULL) |
|
| 397 | + { |
|
| 398 | + $hash = $this->set_email($email); |
|
| 399 | + |
|
| 400 | + if ($hash === NULL) |
|
| 401 | + { |
|
| 402 | + // $hash has to be set to a value so the gravatar site can return a default image |
|
| 403 | + $hash = 'invalid_email'; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + $query_string = NULL; |
|
| 407 | + $options = array(); |
|
| 408 | + |
|
| 409 | + if ($rating !== NULL) |
|
| 410 | + { |
|
| 411 | + $options['r'] = $rating; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + if ($size !== NULL) |
|
| 415 | + { |
|
| 416 | + $options['s'] = $size; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + if ($default_image !== NULL) |
|
| 420 | + { |
|
| 421 | + $options['d'] = urlencode($default_image); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + if (count($options) > 0) |
|
| 425 | + { |
|
| 426 | + $query_string = '?'. http_build_query($options); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + if ($secure !== NULL) |
|
| 430 | + { |
|
| 431 | + $base = $this->gravatar_secure_base_url; |
|
| 432 | + } |
|
| 433 | + else |
|
| 434 | + { |
|
| 435 | + $base = $this->gravatar_base_url; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $base .'avatar/'. $hash . $query_string; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Grab the full profile data for a given email from gravatar.com in xml format |
|
| 443 | + * |
|
| 444 | + * @param string $email |
|
| 445 | + * @param string fetch_method defaults to file, 'curl' is the other option |
|
| 446 | + * |
|
| 447 | + * @return object|null $xml->entry on success, NULL on an error |
|
| 448 | + * |
|
| 449 | + * @deprecated |
|
| 450 | + */ |
|
| 451 | + public function get_profile($email, $fetch_method = 'file') |
|
| 452 | + { |
|
| 453 | + $hash = $this->set_email($email); |
|
| 454 | + |
|
| 455 | + if ($hash === NULL) |
|
| 456 | + { |
|
| 457 | + // A hash value of NULL will return no xml so the method returns NULL |
|
| 458 | + return NULL; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + libxml_use_internal_errors(TRUE); |
|
| 462 | + |
|
| 463 | + if ($fetch_method === 'file') |
|
| 464 | + { |
|
| 465 | + if (ini_get('allow_url_fopen') == FALSE) |
|
| 466 | + { |
|
| 467 | + return NULL; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $str = file_get_contents($this->gravatar_base_url . $hash .'.xml'); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + if ($fetch_method === 'curl') |
|
| 474 | + { |
|
| 475 | + if ( ! function_exists('curl_init')) |
|
| 476 | + { |
|
| 477 | + return NULL; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + $ch = curl_init(); |
|
| 481 | + $options = array( |
|
| 482 | + CURLOPT_RETURNTRANSFER => TRUE, |
|
| 483 | + CURLOPT_POST => TRUE, |
|
| 484 | + CURLOPT_URL => $this->gravatar_secure_base_url . $hash .'.xml', |
|
| 485 | + CURLOPT_TIMEOUT => 3 |
|
| 486 | + ); |
|
| 487 | + curl_setopt_array($ch, $options); |
|
| 488 | + $str = curl_exec($ch); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + $xml = simplexml_load_string($str); |
|
| 492 | + |
|
| 493 | + if ($xml === FALSE) |
|
| 494 | + { |
|
| 495 | + $errors = array(); |
|
| 496 | + foreach(libxml_get_errors() as $error) |
|
| 497 | + { |
|
| 498 | + $errors[] = $error->message.'\n'; |
|
| 499 | + } |
|
| 500 | + $error_string = implode('\n', $errors); |
|
| 501 | + throw new Exception('Failed loading XML\n'. $error_string); |
|
| 502 | + } |
|
| 503 | + else |
|
| 504 | + { |
|
| 505 | + return $xml->entry; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | 508 | |
| 509 | 509 | } |
@@ -7,23 +7,23 @@ |
||
| 7 | 7 | |
| 8 | 8 | if (!function_exists('gravatar')) { |
| 9 | 9 | |
| 10 | - // This helper function has been added here for compatibility with PyroCMS. |
|
| 11 | - function gravatar($email = '', $size = 50, $rating = 'g', $url_only = false, $default = false) { |
|
| 10 | + // This helper function has been added here for compatibility with PyroCMS. |
|
| 11 | + function gravatar($email = '', $size = 50, $rating = 'g', $url_only = false, $default = false) { |
|
| 12 | 12 | |
| 13 | - $ci = & get_instance(); |
|
| 14 | - $ci->load->library('gravatar'); |
|
| 13 | + $ci = & get_instance(); |
|
| 14 | + $ci->load->library('gravatar'); |
|
| 15 | 15 | |
| 16 | - if (@ (string) $default == '') { |
|
| 17 | - $default = null; |
|
| 18 | - } |
|
| 16 | + if (@ (string) $default == '') { |
|
| 17 | + $default = null; |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - $gravatar_url = $ci->gravatar->get($email, $size, $default, null, $rating); |
|
| 20 | + $gravatar_url = $ci->gravatar->get($email, $size, $default, null, $rating); |
|
| 21 | 21 | |
| 22 | - if ($url_only) { |
|
| 23 | - return $gravatar_url; |
|
| 24 | - } |
|
| 22 | + if ($url_only) { |
|
| 23 | + return $gravatar_url; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - return '<img src="'.$gravatar_url.'" alt="Gravatar" class="gravatar" />'; |
|
| 27 | - } |
|
| 26 | + return '<img src="'.$gravatar_url.'" alt="Gravatar" class="gravatar" />'; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (! defined('BASEPATH')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -203,14 +203,14 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $idQuery = $this->db->select('id') |
| 206 | - ->where('user_id', $userID) |
|
| 207 | - ->where('title_id', $titleID) |
|
| 208 | - ->get('tracker_chapters'); |
|
| 206 | + ->where('user_id', $userID) |
|
| 207 | + ->where('title_id', $titleID) |
|
| 208 | + ->get('tracker_chapters'); |
|
| 209 | 209 | if($idQuery->num_rows() > 0) { |
| 210 | 210 | $success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL, 'ignore_chapter' => NULL]) |
| 211 | - ->where('user_id', $userID) |
|
| 212 | - ->where('title_id', $titleID) |
|
| 213 | - ->update('tracker_chapters'); |
|
| 211 | + ->where('user_id', $userID) |
|
| 212 | + ->where('title_id', $titleID) |
|
| 213 | + ->update('tracker_chapters'); |
|
| 214 | 214 | |
| 215 | 215 | if($success) { |
| 216 | 216 | $idQueryRow = $idQuery->row(); |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | public function updateByID(int $userID, int $chapterID, string $chapter) : bool { |
| 238 | 238 | $success = (bool) $this->db->set(['current_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL]) |
| 239 | - ->where('user_id', $userID) |
|
| 240 | - ->where('id', $chapterID) |
|
| 241 | - ->update('tracker_chapters'); |
|
| 239 | + ->where('user_id', $userID) |
|
| 240 | + ->where('id', $chapterID) |
|
| 241 | + ->update('tracker_chapters'); |
|
| 242 | 242 | |
| 243 | 243 | if($success) { |
| 244 | 244 | $this->History->userUpdateTitle($chapterID, $chapter); |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | public function ignoreByID(int $userID, int $chapterID, string $chapter) : bool { |
| 250 | 250 | $success = (bool) $this->db->set(['ignore_chapter' => $chapter, 'active' => 'Y', 'last_updated' => NULL]) |
| 251 | - ->where('user_id', $userID) |
|
| 252 | - ->where('id', $chapterID) |
|
| 253 | - ->update('tracker_chapters'); |
|
| 251 | + ->where('user_id', $userID) |
|
| 252 | + ->where('id', $chapterID) |
|
| 253 | + ->update('tracker_chapters'); |
|
| 254 | 254 | |
| 255 | 255 | if($success) { |
| 256 | 256 | $this->History->userIgnoreTitle($chapterID, $chapter); |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | //This is to allow user history to function properly. |
| 264 | 264 | |
| 265 | 265 | $success = $this->db->set(['active' => 'N', 'last_updated' => NULL]) |
| 266 | - ->where('user_id', $userID) |
|
| 267 | - ->where('id', $chapterID) |
|
| 268 | - ->update('tracker_chapters'); |
|
| 266 | + ->where('user_id', $userID) |
|
| 267 | + ->where('id', $chapterID) |
|
| 268 | + ->update('tracker_chapters'); |
|
| 269 | 269 | |
| 270 | 270 | return (bool) $success; |
| 271 | 271 | } |
@@ -295,9 +295,9 @@ discard block |
||
| 295 | 295 | //TODO: OPTION, USE BACKEND MAL ID DB WHERE POSSIBLE (DEFAULT TRUE) |
| 296 | 296 | |
| 297 | 297 | $queryC = $this->db->select('mal_id') |
| 298 | - ->where('user_id', $userID) |
|
| 299 | - ->where('title_id', $titleID) |
|
| 300 | - ->get('tracker_chapters'); |
|
| 298 | + ->where('user_id', $userID) |
|
| 299 | + ->where('title_id', $titleID) |
|
| 300 | + ->get('tracker_chapters'); |
|
| 301 | 301 | |
| 302 | 302 | if($queryC->num_rows() > 0 && ($rowC = $queryC->row())) { |
| 303 | 303 | $malIDArr = [ |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | ]; |
| 307 | 307 | } else { |
| 308 | 308 | $queryT = $this->db->select('mal_id') |
| 309 | - ->where('title_id', $titleID) |
|
| 310 | - ->get('tracker_titles'); |
|
| 309 | + ->where('title_id', $titleID) |
|
| 310 | + ->get('tracker_titles'); |
|
| 311 | 311 | |
| 312 | 312 | if($queryT->num_rows() > 0 && ($rowT = $queryT->row())) { |
| 313 | 313 | $malIDArr = [ |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | public function setMalID(int $userID, int $chapterID, ?int $malID) : bool { |
| 341 | 341 | //TODO: Handle NULL? |
| 342 | 342 | $success = (bool) $this->db->set(['mal_id' => $malID, 'active' => 'Y', 'last_updated' => NULL]) |
| 343 | - ->where('user_id', $userID) |
|
| 344 | - ->where('id', $chapterID) |
|
| 345 | - ->update('tracker_chapters'); |
|
| 343 | + ->where('user_id', $userID) |
|
| 344 | + ->where('id', $chapterID) |
|
| 345 | + ->update('tracker_chapters'); |
|
| 346 | 346 | |
| 347 | 347 | if($success) { |
| 348 | 348 | //MAL id update was successful, update history |