1 | <?php |
---|
2 | /* $Id: ce_comment.class.php,v 1.6 2009/06/26 08:56:33 Criss Exp $ */ |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | /** |
---|
6 | * CE_Plugin class |
---|
7 | */ |
---|
8 | class CE_Comment { |
---|
9 | var $id; |
---|
10 | var $infos = array(); |
---|
11 | var $query; |
---|
12 | private static $s_user_list = null; |
---|
13 | |
---|
14 | private static function updateUsers() { |
---|
15 | $users = array(); |
---|
16 | $query = ' |
---|
17 | SELECT username |
---|
18 | FROM '. USERS_TABLE .' |
---|
19 | ORDER BY username'; |
---|
20 | $result = pwg_query( $query ); |
---|
21 | while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { |
---|
22 | $users = array_merge($users, array($row['username'] => $row['username'])); |
---|
23 | } |
---|
24 | return $users; |
---|
25 | } |
---|
26 | |
---|
27 | static function getUsers() { |
---|
28 | if (null == self::$s_user_list) { |
---|
29 | // Init user list |
---|
30 | self::$s_user_list = self::updateUsers(); |
---|
31 | } |
---|
32 | return self::$s_user_list; |
---|
33 | } |
---|
34 | |
---|
35 | function CE_Comment($comment_id) { |
---|
36 | $this->id = $comment_id; |
---|
37 | $this->query = ' |
---|
38 | SELECT com.id AS comment_id |
---|
39 | , com.image_id |
---|
40 | , com.author |
---|
41 | , com.date |
---|
42 | , com.content |
---|
43 | , com.validated |
---|
44 | FROM '.COMMENTS_TABLE.' AS com |
---|
45 | WHERE com.id = ' . $comment_id; |
---|
46 | $result = pwg_query($this->query); |
---|
47 | $this->infos = mysql_fetch_array($result, MYSQL_ASSOC); |
---|
48 | } |
---|
49 | |
---|
50 | function validateAuthor($author) { |
---|
51 | $user_list = self::getUsers(); |
---|
52 | if (array_key_exists( strtolower($author), |
---|
53 | array_change_key_case($user_list, CASE_LOWER))) { |
---|
54 | // Look in user list to have right case ! |
---|
55 | foreach ($user_list as $user) { |
---|
56 | if (0 == strcasecmp($author, $user)) { |
---|
57 | return $user; |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | return $author; |
---|
62 | } |
---|
63 | |
---|
64 | function isKnownAuthor() { |
---|
65 | if (in_array($this->infos['author'], self::getUsers())) { |
---|
66 | return true; |
---|
67 | } |
---|
68 | return false; |
---|
69 | } |
---|
70 | |
---|
71 | function setInfo($key, $value) { |
---|
72 | if (null == $key) { |
---|
73 | return; |
---|
74 | } |
---|
75 | $this->infos[$key] = $value; |
---|
76 | } |
---|
77 | |
---|
78 | function getInfo($key = null) { |
---|
79 | if (null == $key) { |
---|
80 | return $this->infos; |
---|
81 | } |
---|
82 | return $this->infos[$key]; |
---|
83 | } |
---|
84 | |
---|
85 | function isAuthor($user) { |
---|
86 | if (!isset ($this->infos['author'])) { |
---|
87 | return false; |
---|
88 | } |
---|
89 | return (0 == strcmp($this->infos['author'], $user))?true:false; |
---|
90 | } |
---|
91 | |
---|
92 | function __toString() { |
---|
93 | return print_r($this->infos, true); |
---|
94 | } |
---|
95 | } |
---|
96 | ?> |
---|