source: extensions/CommentEditor/include/ce_functions.inc.php @ 3476

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

Add obsolete files management

  • Property svn:eol-style set to LF
File size: 5.2 KB
Line 
1<?php
2/* $Id: ce_functions.inc.php,v 1.7 2009/06/29 11:43:18 Criss Exp $ */
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5/**
6 * Include class file
7 * @param $aClassName
8 * @return unknown_type
9 */
10function ce_require_class($aClassName) {
11  require_once CE_CLASSES .strtolower($aClassName) . '.class.php';
12}
13
14function ce_clean_obsolete_files($obsolete_file_list) {
15  if (!file_exists(CE_PATH.$obsolete_file_list)) {
16    return TRUE;
17  }
18  $obsolete = file(CE_PATH.$obsolete_file_list);
19  array_push($obsolete, $obsolete_file_list);
20  return ce_clean_obsolete_list($obsolete);
21}
22
23function ce_clean_obsolete_list($file_list = array(), &$errors = array()) {
24  if (!function_exists('unlink')) {
25      // No unlink available...
26      array_push($errors, l10n('ce_no_unlink'));
27      return FALSE;
28  }
29  $success = TRUE;
30  foreach ($file_list as $file) {
31    $file = CE_PATH . $file;
32    if (file_exists($file)) {
33      // Remove obsolete file
34      $success &= unlink($file);
35    }
36  }
37  if (!$success) {
38      array_push($errors, l10n('ce_unlink_errors'));
39  }
40  return $success;
41}
42
43if (!function_exists('update_user_comment')) {
44
45/**
46 * Changed from Piwigo core function  insert_user_comment
47 */
48
49/**
50 * Tries to update a user comment in the database and returns one of :
51 * validate, moderate, reject
52 * @param array comm contains author, content, image_id
53 * @param string key secret key sent back to the browser
54 * @param array infos out array of messages
55 */
56function update_user_comment( &$comm, $key, &$infos )
57{
58  global $conf, $user;
59
60  $comm = array_merge( $comm,
61    array(
62      'ip' => $_SERVER['REMOTE_ADDR'],
63      'agent' => $_SERVER['HTTP_USER_AGENT']
64    )
65   );
66
67  $infos = array();
68  if (!$conf['comments_validation'] or is_admin())
69  {
70    $comment_action='validate'; //one of validate, moderate, reject
71  }
72  else
73  {
74    $comment_action='moderate'; //one of validate, moderate, reject
75  }
76
77  // display author field if the user status is guest or generic
78  if (!is_classic_user())
79  {
80    if ( empty($comm['author']) )
81    {
82      $comm['author'] = 'guest';
83    }
84    // if a guest try to use the name of an already existing user, he must be
85    // rejected
86    if ( $comm['author'] != 'guest' )
87    {
88      $query = '
89SELECT COUNT(*) AS user_exists
90  FROM '.USERS_TABLE.'
91  WHERE '.$conf['user_fields']['username']." = '".addslashes($comm['author'])."'";
92      $row = mysql_fetch_assoc( pwg_query( $query ) );
93      if ( $row['user_exists'] == 1 )
94      {
95        array_push($infos, l10n('comment_user_exists') );
96        $comment_action='reject';
97      }
98    }
99  }
100  else
101  {
102    if ( empty($comm['author'])) {
103        $comm['author'] = $user[$conf['user_fields']['username']];
104    }
105  }
106  if ( empty($comm['content']) )
107  { // empty comment content
108    $comment_action='reject';
109  }
110
111//  $key = explode( ':', @$key );
112//  if ( count($key)!=2
113//        or $key[0]>time()-2 // page must have been retrieved more than 2 sec ago
114//        or $key[0]<time()-3600 // 60 minutes expiration
115//        or hash_hmac(
116//              'md5', $key[0].':'.$comm['image_id'], $conf['secret_key']
117//            ) != $key[1]
118//      )
119//  {
120//    $comment_action='reject';
121//  }
122
123  if ($comment_action!='reject' and $conf['anti-flood_time']>0 )
124  { // anti-flood system
125    $reference_date = time() - $conf['anti-flood_time'];
126    $query = '
127SELECT id FROM '.COMMENTS_TABLE.'
128  WHERE date > FROM_UNIXTIME('.$reference_date.')
129    AND author = "'.addslashes($comm['author']).'"';
130    if ( mysql_num_rows( pwg_query( $query ) ) > 0 )
131    {
132      array_push( $infos, l10n('comment_anti-flood') );
133      $comment_action='reject';
134    }
135  }
136
137  // perform more spam check
138  $comment_action = trigger_event('user_comment_check',
139      $comment_action, $comm
140    );
141
142  if ( $comment_action!='reject' )
143  {
144
145    $query = 'UPDATE '.COMMENTS_TABLE;
146    $query.= ' SET author="'.addslashes($comm['author']).'"';
147    $query.= '    ,content="'.addslashes($comm['content']).'"';
148    if ('moderate' == $comment_action) {
149        $query.=',validated="false"';
150        $query.=', validation_date=NULL';
151    }
152    $query.=' WHERE (id='.$comm['comment_id'].' AND image_id='.$comm['image_id'].')';
153    pwg_query($query);
154
155    if
156      (
157        ($comment_action=='validate' and $conf['email_admin_on_comment'])
158        or
159        ($comment_action!='validate' and $conf['email_admin_on_comment_validation'])
160      )
161    {
162      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
163
164      $del_url =
165          get_absolute_root_url().'comments.php?delete='.$comm['comment_id'];
166
167      $keyargs_content = array
168      (
169        get_l10n_args('Author: %s', $comm['author']),
170        get_l10n_args('Comment: %s', $comm['content']),
171        get_l10n_args('', ''),
172        get_l10n_args('Delete: %s', $del_url)
173      );
174
175      if ($comment_action!='validate')
176      {
177        $keyargs_content[] =
178          get_l10n_args('', '');
179        $keyargs_content[] =
180          get_l10n_args('Validate: %s',
181            get_absolute_root_url().'comments.php?validate='.$comm['comment_id']);
182      }
183
184      pwg_mail_notification_admins
185      (
186        get_l10n_args('Comment by %s', $comm['author']),
187        $keyargs_content
188      );
189    }
190  }
191  return $comment_action;
192}
193
194} // function_exists
195
196?>
Note: See TracBrowser for help on using the repository browser.