添加了Gravatar头像引用,添加了用户组的session信息放置

This commit is contained in:
Li Jianxuan 2013-01-16 08:09:14 +00:00
parent bdcf1e824e
commit 1ff46e39b1
7 changed files with 161 additions and 11 deletions

View File

@ -292,6 +292,8 @@ class Admin_UserController extends Zend_Controller_Action
$groupsTable = "groups";
$userGroupTable = "usergroup";
$nameField = $paramName = "name";
include_once("User.php");
$u = new User($this->db);
if(empty($ac) || $ac == "index")
{

View File

@ -176,6 +176,17 @@ class AccountController extends Zend_Controller_Action
// success: store database row to auth's storage
$data = $authAdapter->getResultRowObject(null,'password');
//头像
include_once("Avatar.php");
$avatar = new Avatar();
$data->avatar = $avatar->Get($data->email,40);
//组ID
include_once("Users.php");
$usr = new Users($db);
$data->gid = $usr->getGroup($data->id);
$auth->getStorage()->write($data);
$db->query("update users set ts_last_login=now() where username=?",array($u));

View File

@ -877,12 +877,14 @@ class DataController extends Zend_Controller_Action
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_ajax.phtml');
include_once("Avatar.php");
$avatar = new Avatar();
if ($paginator)
{
foreach($paginator as $c)
{
//$author=$this->view->escape($c['author']);
$sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created,u.usertype,
$sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created,u.usertype,u.email as email,
(SELECT au.uuid FROM mdauthor au WHERE au.userid=u.id AND au.uuid='$uuid') as uuid
FROM comments cr
LEFT JOIN users u ON cr.userid=u.id
@ -918,11 +920,16 @@ class DataController extends Zend_Controller_Action
</div>";
}
}
$img = $avatar->Get($c['email'],30);
$img = '<img src="'.$img.'" />';
$author = $c['author'];
$author=($c['userid'])?"<strong>".$author."</strong>":$author;
$author = ($c['url'])?'<a href="'.$c['url'].'">'.$author.'</a>':$author;
$author = '<div class="post_name">'.$author."</div>";
$time = '<div class="post_time">发表于'.date('Y-m-d H:i:s',strtotime($c['ts_created'])).'</div>';
print "
<div class='comment-content'><span class='title'>".$author." 发表于".date('Y-m-d H:i:s',strtotime($c['ts_created']))."</span>
<div class='comment-content'><div class='title'>".$img.$author.$time."</div>
<p>".($c['content'])."</p>
$replyhtml
</div>";

View File

@ -0,0 +1,19 @@
<?php
class Avatar{
public $def_img = "http://www.gravatar.com/avatar/";
function Get( $email, $size='' ) {
$default = $this->def_img;
if(empty($size))
{
$size = 40;
}
$url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size;
return $url;
}
}

View File

@ -33,6 +33,7 @@
// add an exception so guests can log in or register
// in order to gain privilege
$this->acl->allow('guest', 'account', array('login',
'logout',
'fetchpwd',
'register',
'registercomplete'));
@ -59,6 +60,7 @@
{
$phpSessId = $request->getParam('PHPSESSID');
if (!empty($phpSessId) && session_id() != $phpSessId) {
session_destroy();
session_id($phpSessId);

View File

@ -0,0 +1,105 @@
<?php
/**
* Users 用户相关操作
*/
class Users
{
private $db;//传入PDO对象
//使用到的公共变量
public $tbl_user = "users";
public $tbl_group = "groups";
public $tbl_userToGroup = "usergroup";
function __construct($db)
{
$this->db = $db;
}
//获取用户的组ID
public function getGroup($uid=0){
if(!empty($uid) && is_numeric($uid))
{
$sql = "SELECT gid FROM ".$this->tbl_userToGroup." WHERE uid=$uid";
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row['gid'];
}else{
$select = $this->db->select();
return $select ->from($this->tbl_group)
->order('groups.id desc');
}
}
//获取组名
public function getGroupName($gid){
if(!is_numeric($gid))
{
return false;
}
$sql = "SELECT * FROM ".$this->tbl_group." WHERE id=$gid";
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row['name'];
}
//创建用户组
public function CreateGroup($name){
$groupTable = $this->tbl_group;
if(empty($name))
{
return false;
}
$data = array(
"name" => $name
);
return $this->db->insert($groupTable,$data);
}
//把用户移动到组
public function AddTo($uid,$gid){
if(!is_numeric($uid) || !is_numeric($gid))
{
return false;
}
$sql = "SELECT * FROM ".$this->tbl_userToGroup." WHERE uid=? AND gid=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($uid,$gid));
$row = $sth->fetch();
if(!empty($row['ts_created']))
{
$data = array(
"uid"=>$uid,
"gid"=>$gid
);
$whereSql = " uid=$uid AND gid=$gid ";
return $this->db->update($this->tbl_userToGroup,$data,$whereSql);
}else{
$data = array(
"uid"=>$uid,
"gid"=>$gid
);
return $this->db->insert($this->tbl_userToGroup,$data);
}
}
}

View File

@ -51,8 +51,12 @@ h2{clear:both;}
label{float:left;text-align:right;width:100px;padding-right:20px;}
#allcomments li{display:block;border:1px solid #aaa;white-space:wrap;width:100%;overflow:hidden;}
#allcomments span.title {background:#dfdfdf;display:block;padding-left:10px;line-height:20px;}
.comment-content{display:block;border:1px solid #aaa;text-indent:2em;width:98%;margin:5px 0 0 0;}
#allcomments div.title,#allcomments span.title {background:#dfdfdf;display:block;padding-left:10px;line-height:20px;}
.comment-content{display:block;border:1px solid #aaa;text-indent:2em;width:98%;margin:5px 0 0 0; overflow:hidden;}
.comment-content .title{overflow:hidden;width:100%;}
.comment-content .title img{height:30px;float:left; padding:0px;margin:0px;}
.comment-content div.title .post_name{width:80%;margin:0px;padding:0px;line-height:15px;overflow:hidden;}
.comment-content div.title .post_time{width:80%;margin:0px;padding:0px;line-height:15px;overflow:hidden;}
.attach img {height:20px;vertical-align:middle;}
.thumb {float:left;width:250px;height:200px;}