From 1ff46e39b1df930089bfa47181a2f4d3b7adbc5b Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 16 Jan 2013 08:09:14 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86Gravatar=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E5=BC=95=E7=94=A8=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BB=84=E7=9A=84session=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=94=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/UserController.php | 2 + .../default/controllers/AccountController.php | 13 ++- .../default/controllers/DataController.php | 17 ++- application/models/Avatar.php | 19 ++++ .../models/CustomControllerAclManager.php | 8 +- application/models/Users.php | 105 ++++++++++++++++++ htdocs/css/watermdview.css | 8 +- 7 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 application/models/Avatar.php create mode 100644 application/models/Users.php diff --git a/application/admin/controllers/UserController.php b/application/admin/controllers/UserController.php index 769be8b6..2b8417ef 100755 --- a/application/admin/controllers/UserController.php +++ b/application/admin/controllers/UserController.php @@ -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") { diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 52c85970..b412ca22 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -174,8 +174,19 @@ class AccountController extends Zend_Controller_Action $result = $auth->authenticate($authAdapter); if ($result->isValid()) { - // success: store database row to auth's storage + // 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)); diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 394850eb..bd476f06 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -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 "; } } - $author=$c['author']; - $author=($c['userid'])?"".$author."":$author; - $author=($c['url'])?''.$author.'':$author; + + $img = $avatar->Get($c['email'],30); + $img = ''; + + $author = $c['author']; + $author = ($c['url'])?''.$author.'':$author; + $author = '
'.$author."
"; + $time = '
发表于'.date('Y-m-d H:i:s',strtotime($c['ts_created'])).'
'; print " -
".$author." 发表于".date('Y-m-d H:i:s',strtotime($c['ts_created']))." +
".$img.$author.$time."

".($c['content'])."

$replyhtml
"; diff --git a/application/models/Avatar.php b/application/models/Avatar.php new file mode 100644 index 00000000..09322792 --- /dev/null +++ b/application/models/Avatar.php @@ -0,0 +1,19 @@ +def_img; + + if(empty($size)) + { + $size = 40; + } + + $url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size; + + return $url; + } +} \ No newline at end of file diff --git a/application/models/CustomControllerAclManager.php b/application/models/CustomControllerAclManager.php index 4a957fd7..c7217920 100755 --- a/application/models/CustomControllerAclManager.php +++ b/application/models/CustomControllerAclManager.php @@ -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,10 +60,11 @@ { $phpSessId = $request->getParam('PHPSESSID'); + if (!empty($phpSessId) && session_id() != $phpSessId) { - session_destroy(); - session_id($phpSessId); - session_start(); + session_destroy(); + session_id($phpSessId); + session_start(); } // check if a user is logged in and has a valid role, // otherwise, assign them the default role (guest) diff --git a/application/models/Users.php b/application/models/Users.php new file mode 100644 index 00000000..aff7465c --- /dev/null +++ b/application/models/Users.php @@ -0,0 +1,105 @@ +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); + } + + } + +} diff --git a/htdocs/css/watermdview.css b/htdocs/css/watermdview.css index 89aaf8b8..4f6b869a 100644 --- a/htdocs/css/watermdview.css +++ b/htdocs/css/watermdview.css @@ -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;}