Added : Gravatar =D

This commit is contained in:
Arslan Hassan 2010-02-25 15:26:03 +00:00
parent c3a0395726
commit af010c7511
5 changed files with 237 additions and 9 deletions

View file

@ -118,7 +118,7 @@ class CBEmail
e(lang("email_msg_empty"));
else
{
$db->update(tbl($this->db_tpl),array("email_template_subject","email_template"),array($subj,$msg),
$db->update(tbl($this->db_tpl),array("email_template_subject","email_template"),array($subj,'|no_mc|'.$msg),
" email_template_id='$id'");
e(lang("email_tpl_has_updated"),"m");
}

View file

@ -0,0 +1,191 @@
<?php
/**
* Class Gravatar
*
* From Gravatar Help:
* "A gravatar is a dynamic image resource that is requested from our server. The request
* URL is presented here, broken into its segments."
* Source:
* http://site.gravatar.com/site/implement
*
* Usage:
* <code>
* $email = "youremail@yourhost.com";
* $default = "http://www.yourhost.com/default_image.jpg"; // Optional
* $gravatar = new Gravatar($email, $default);
* $gravatar->size = 80;
* $gravatar->rating = "G";
* $gravatar->border = "FF0000";
*
* echo $gravatar; // Or echo $gravatar->toHTML();
* </code>
*
* Class Page: http://www.phpclasses.org/browse/package/4227.html
*
* @author Lucas Araújo <araujo.lucas@gmail.com>
* @version 1.0
* @package Gravatar
*/
class Gravatar
{
/**
* Gravatar's url
*/
const GRAVATAR_URL = "http://www.gravatar.com/avatar.php";
/**
* Ratings available
*/
private $GRAVATAR_RATING = array("G", "PG", "R", "X");
/**
* Query string. key/value
*/
protected $properties = array(
"gravatar_id" => NULL,
"default" => NULL,
"size" => 80, // The default value
"rating" => NULL,
"border" => NULL,
);
/**
* E-mail. This will be converted to md5($email)
*/
protected $email = "";
/**
* Extra attributes to the IMG tag like ALT, CLASS, STYLE...
*/
protected $extra = "";
/**
*
*/
public function __construct($email=NULL, $default=NULL) {
$this->setEmail($email);
$this->setDefault($default);
}
/**
*
*/
public function setEmail($email) {
if ($this->isValidEmail($email)) {
$this->email = $email;
$this->properties['gravatar_id'] = md5(strtolower($this->email));
return true;
}
return false;
}
/**
*
*/
public function setDefault($default) {
$this->properties['default'] = $default;
}
/**
*
*/
public function setRating($rating) {
if (in_array($rating, $this->GRAVATAR_RATING)) {
$this->properties['rating'] = $rating;
return true;
}
return false;
}
/**
*
*/
public function setSize($size) {
$size = (int) $size;
if ($size <= 0)
$size = NULL; // Use the default size
$this->properties['size'] = $size;
}
/**
*
*/
public function setExtra($extra) {
$this->extra = $extra;
}
/**
*
*/
public function isValidEmail($email) {
//global $userquery;
return is_valid_syntax('email',$email);
// Source: http://www.zend.com/zend/spotlight/ev12apr.php
//return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}
/**
* Object property overloading
*/
public function __get($var) { return @$this->properties[$var]; }
/**
* Object property overloading
*/
public function __set($var, $value) {
switch($var) {
case "email": return $this->setEmail($value);
case "rating": return $this->setRating($value);
case "default": return $this->setDefault($value);
case "size": return $this->setSize($value);
// Cannot set gravatar_id
case "gravatar_id": return;
}
return @$this->properties[$var] = $value;
}
/**
* Object property overloading
*/
public function __isset($var) { return isset($this->properties[$var]); }
/**
* Object property overloading
*/
public function __unset($var) { return @$this->properties[$var] == NULL; }
/**
* Get source
*/
public function getSrc() {
$url = self::GRAVATAR_URL ."?";
$first = true;
foreach($this->properties as $key => $value) {
if (isset($value)) {
if (!$first)
$url .= "&";
$url .= $key."=".urlencode($value);
$first = false;
}
}
return $url;
}
/**
* toHTML
*/
public function toHTML() {
return '<img src="'. $this->getSrc() .'"'
.(!isset($this->size) ? "" : ' width="'.$this->size.'" height="'.$this->size.'"')
.$this->extra
.' />';
}
/**
* toString
*/
public function __toString() { return $this->toHTML(); }
}
?>

View file

@ -15,6 +15,7 @@ define('NO_AVATAR','no_avatar.png'); //if there is no avatar or profile pic, thi
define('AVATAR_SIZE',250);
define('AVATAR_SMALL_SIZE',40);
define('BG_SIZE',1200);
define("USE_GAVATAR",true); //Use Gavatar
class userquery extends CBCategory{
@ -1320,13 +1321,14 @@ class userquery extends CBCategory{
*/
function getUserThumb($udetails,$size='',$uid=NULL,$just_file=false)
{
$remote = false;
if(empty($udetails['userid']))
if(empty($udetails['userid']) && $uid)
$udetails = $this->get_user_details($uid);
//$thumbnail = $udetails['avatar'] ? $udetails['avatar'] : NO_AVATAR;
$thumbnail = $udetails['avatar'];
$thumb_file = USER_THUMBS_DIR.'/'.$thumbnail;
if(file_exists($thumb_file) && $thumbnail!='')
$thumb_file = USER_THUMBS_URL.'/'.$thumbnail;
elseif(!empty($udetails['avatar_url']))
@ -1334,22 +1336,54 @@ class userquery extends CBCategory{
$thumb_file = $udetails['avatar_url'];
$remote = true;
}else
$thumb_file = USER_THUMBS_URL.'/'.NO_AVATAR;
{
if(!USE_GAVATAR)
$thumb_file = USER_THUMBS_URL.'/'.NO_AVATAR;
else
{
switch($size)
{
case "small":
{
$thesize = AVATAR_SMALL_SIZE;
$default = USER_THUMBS_URL.'/'.getName(NO_AVATAR).'-small.'.getExt(NO_AVATAR);
}
break;
default:
{
$thesize = AVATAR_SIZE;
$default = USER_THUMBS_URL.'/'.NO_AVATAR;
}
}
$email = $udetails['email'];
$email = $email ? $email : $udetails['anonym_email'];
$gravatar = new Gravatar($email, $default);
$gravatar->size = $thesize;
$gravatar->rating = "G";
$gravatar->border = "FF0000";
$thumb = $gravatar->getSrc();
//echo $gravatar->toHTML();
}
}
$ext = GetExt($thumb_file);
$file = getName($thumb_file);
if(!$remote)
{
if(!empty($size))
if(!empty($size) && !$thumb)
$thumb = USER_THUMBS_URL.'/'.$file.'-'.$size.'.'.$ext;
else
elseif(!$thumb)
$thumb = USER_THUMBS_URL.'/'.$file.'.'.$ext;
}else
}elseif(!USE_GAVATAR)
$thumb = $thumb_file;
if($just_file)
return $file.'.'.$ext;
return $thumb;
}
function avatar($udetails,$size='',$uid=NULL)

View file

@ -76,6 +76,9 @@ if(file_exists(dirname(__FILE__).'/../install/isinstall.php')){
require_once('classes/cbemail.class.php');
require_once('classes/pm.class.php');
require_once('classes/cbpage.class.php');
//Adding Gravatar
require_once('classes/gravatar.class.php');
require_once 'languages.php';

View file

@ -17,7 +17,7 @@
</form>
{else}
<div class="avatar">
<div style="width:40px; height:40px; background:#EEE; margin:0px; padding:0px;"><img src="{$userquery->getUserThumb($udetails,'small')}" class="mid_user_thumb" /></div>
<div style="width:40px; height:40px; background:#EEE; margin:0px; padding:0px;"><img src="{$userquery->getUserThumb($userquery->udetails,'small')}" class="mid_user_thumb" /></div>
</div>
<div class="txt">
{lang code='howdy_user' assign='howdyuser'}