source: extensions/CommentEditor/classes/ce_comment.class.php @ 3426

Last change on this file since 3426 was 3426, checked in by Criss, 15 years ago

CommentEditor plugin creation

  • Property svn:eol-style set to LF
File size: 2.5 KB
Line 
1<?php
2/* $Id: ce_comment.class.php,v 1.3 2009/06/17 19:08:25 Criss Exp $ */
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5/**
6 * CE_Plugin class
7 */
8class 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 = '';
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[$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), array_change_key_case($userList, CASE_LOWER))) {
53            // Look in user list to have right case !
54            foreach ($user_list as $user) {
55                if (0 == strcasecmp($author, $user)) {
56                    return $user;
57                }
58            }
59        }
60        return $author;
61    }
62
63    function isKnownAuthor() {
64        if (in_array($this->infos['author'], self::getUsers())) {
65            return true;
66        }
67        return false;
68    }
69
70    function setInfo($key, $value) {
71        if (null == $key) {
72            return;
73        }
74        $this->infos[$key] = $value;
75    }
76
77    function getInfo($key = null) {
78        if (null == $key) {
79            return $this->infos;
80        }
81        return $this->infos[$key];
82    }
83
84    function isAuthor($user) {
85        if (!isset ($this->infos['author'])) {
86            return false;
87        }
88        return (0 == strcmp($this->infos['author'], $user))?true:false;
89    }
90
91    function __toString() {
92        return print_r($this->infos, true);
93    }
94}
95?>
Note: See TracBrowser for help on using the repository browser.