Ignore:
Timestamp:
Jun 26, 2009, 11:52:25 AM (15 years ago)
Author:
Criss
Message:

Display edit block on picture page if request comes from this page
Add simple administration configuration management
Add and remove default configuration from databaseon plugin install / uninstall

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/CommentEditor/classes/ce_comment.class.php

    r3432 r3462  
    11<?php
    2 /* $Id: ce_comment.class.php,v 1.5 2009/06/18 14:48:19 Criss Exp $ */
     2/* $Id: ce_comment.class.php,v 1.6 2009/06/26 08:56:33 Criss Exp $ */
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
     
    77 */
    88class CE_Comment {
    9     var $id;
    10     var $infos = array();
    11     var $query;
    12     private static $s_user_list = null;
     9  var $id;
     10  var $infos = array();
     11  var $query;
     12  private static $s_user_list = null;
    1313
    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']));
     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;
    2358        }
    24         return $users;
     59      }
    2560    }
     61    return $author;
     62  }
    2663
    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;
     64  function isKnownAuthor() {
     65    if (in_array($this->infos['author'], self::getUsers())) {
     66      return true;
    3367    }
     68    return false;
     69  }
    3470
    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);
     71  function setInfo($key, $value) {
     72    if (null == $key) {
     73      return;
    4874    }
     75    $this->infos[$key] = $value;
     76  }
    4977
    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;
     78  function getInfo($key = null) {
     79    if (null == $key) {
     80      return $this->infos;
    6281    }
     82    return $this->infos[$key];
     83  }
    6384
    64     function isKnownAuthor() {
    65         if (in_array($this->infos['author'], self::getUsers())) {
    66             return true;
    67         }
    68         return false;
     85  function isAuthor($user) {
     86    if (!isset ($this->infos['author'])) {
     87      return false;
    6988    }
     89    return (0 == strcmp($this->infos['author'], $user))?true:false;
     90  }
    7091
    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     }
     92  function __toString() {
     93    return print_r($this->infos, true);
     94  }
    9595}
    9696?>
Note: See TracChangeset for help on using the changeset viewer.