PageRenderTime 78ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 2ms

/iGal/admin/index.php

https://github.com/shlag/FSG2010
PHP | 9779 lines | 7691 code | 1197 blank | 891 comment | 2156 complexity | fd1afe512abb4dae58fa5536711cd26c MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /********************************************************************
  3. iGalerie - script de galerie d'images
  4. Copyright (C) 2006-2007 - http://www.igalerie.org/
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. ********************************************************************/
  17. error_reporting(E_ALL);
  18. if (@extension_loaded('zlib')
  19. && !@ini_get('zlib.output_compression')) {
  20. @ob_start('ob_gzhandler');
  21. }
  22. ignore_user_abort(TRUE);
  23. if (function_exists('set_time_limit')) {
  24. @set_time_limit(30);
  25. }
  26. // On mémorise l'heure exacte du début du script.
  27. global $TIME_START;
  28. $TIME_START = explode(' ', microtime());
  29. // Debug : requętes SQL.
  30. global $_MYSQL;
  31. $_MYSQL = array();
  32. $_MYSQL['debug'] = 0;
  33. $_MYSQL['mysql_requetes'] = 0;
  34. $_MYSQL['nb_requetes'] = 0;
  35. // Paramčtres de langue.
  36. setlocale(LC_ALL, 'fr');
  37. setlocale(LC_ALL, 'fr_FR');
  38. setlocale(LC_ALL, 'french');
  39. setlocale(LC_ALL, 'fr_FR.ISO8859-1');
  40. setlocale(LC_NUMERIC, 'en');
  41. setlocale(LC_NUMERIC, 'en_US');
  42. setlocale(LC_NUMERIC, 'english');
  43. setlocale(LC_NUMERIC, 'en_US.ISO8859-1');
  44. // On annule la fonction magic_quotes_gpc.
  45. function strip_magic_quotes(&$valeur) {
  46. if (is_array($valeur)) {
  47. array_walk($valeur, 'strip_magic_quotes');
  48. } else {
  49. $valeur = stripslashes($valeur);
  50. }
  51. }
  52. if (get_magic_quotes_gpc()) {
  53. array_walk($_GET, 'strip_magic_quotes');
  54. array_walk($_POST, 'strip_magic_quotes');
  55. array_walk($_COOKIE, 'strip_magic_quotes');
  56. array_walk($_REQUEST, 'strip_magic_quotes');
  57. }
  58. // On désactive la fonction magic_quotes_runtime
  59. if (get_magic_quotes_runtime() &&
  60. function_exists('set_magic_quotes_runtime')) {
  61. set_magic_quotes_runtime(0);
  62. }
  63. // Chargement de la config.
  64. if (file_exists(dirname(__FILE__) . '/../config/conf.php')) {
  65. require_once(dirname(__FILE__) . '/../config/conf.php');
  66. } else {
  67. define('GALERIE_INSTALL', 0);
  68. }
  69. // La galerie est-elle installée ?
  70. if (!defined('GALERIE_INSTALL') || !GALERIE_INSTALL) {
  71. header('Location:../install/');
  72. exit;
  73. }
  74. require_once(dirname(__FILE__) . '/../includes/classes/class.mysql.php');
  75. require_once(dirname(__FILE__) . '/../includes/classes/class.cookie.php');
  76. require_once(dirname(__FILE__) . '/../includes/classes/class.outils.php');
  77. require_once(dirname(__FILE__) . '/../includes/classes/class.files.php');
  78. // Filtrage des paramčtres GET et REQUEST.
  79. $gets = array('img', 'alb', 'cat', 'startnum', 'obj', 'sub_obj',
  80. 'str');
  81. for ($i = 0; $i < count($gets); $i++) {
  82. verif_gets($gets[$i], '`^\d{1,12}$`');
  83. }
  84. function verif_gets($p, $re) {
  85. if (isset($_GET[$p]) && !preg_match($re, $_GET[$p])) {
  86. unset($_GET[$p]);
  87. }
  88. if (isset($_REQUEST[$p]) && !preg_match($re, $_REQUEST[$p])) {
  89. unset($_REQUEST[$p]);
  90. }
  91. }
  92. // Si une section parmis celle existantes est demandée, on la traite...
  93. if (isset($_REQUEST['section'])) {
  94. // Création de l'objet "admin", avec initialisation de paramčtres communs.
  95. $admin = new admin();
  96. switch ($_REQUEST['section']) {
  97. case 'ftp' :
  98. require_once(dirname(__FILE__) . '/../includes/classes/class.upload.php');
  99. if (isset($_REQUEST['action'])) {
  100. switch ($_REQUEST['action']) {
  101. case 'enregistrement' :
  102. $admin->ftp();
  103. break;
  104. }
  105. }
  106. break;
  107. case 'galerie' :
  108. if (!empty($_FILES)) {
  109. require_once(dirname(__FILE__) . '/../includes/classes/class.upload.php');
  110. }
  111. if (isset($_REQUEST['page'])) {
  112. switch ($_REQUEST['page']) {
  113. case 'gestion' :
  114. $admin->galerie_action();
  115. $admin->galerie();
  116. break;
  117. default :
  118. header('Location: index.php?section=galerie&page=gestion');
  119. exit;
  120. }
  121. } else {
  122. header('Location: index.php?section=galerie&page=gestion');
  123. exit;
  124. }
  125. break;
  126. case 'representant' :
  127. if (isset($_REQUEST['cat']) && isset($_REQUEST['str'])) {
  128. $admin->galerie_representant();
  129. } else {
  130. header('Location: index.php?section=galerie&page=gestion');
  131. exit;
  132. }
  133. break;
  134. case 'votes' :
  135. $admin->display_votes();
  136. break;
  137. case 'tags' :
  138. $admin->display_tags();
  139. break;
  140. case 'utilisateurs' :
  141. if (isset($_REQUEST['page'])) {
  142. switch ($_REQUEST['page']) {
  143. case 'general' :
  144. $admin->users_general();
  145. break;
  146. case 'membres' :
  147. $admin->users_membres_action();
  148. $admin->users_membres();
  149. break;
  150. case 'groupes' :
  151. $admin->users_groupes();
  152. break;
  153. case 'modif_groupe' :
  154. $admin->users_modif_groupe();
  155. break;
  156. case 'modif_user' :
  157. $admin->users_modif_user();
  158. break;
  159. case 'images' :
  160. $admin->users_images_action();
  161. $admin->users_images();
  162. break;
  163. default :
  164. header('Location: index.php?section=utilisateurs&page=general');
  165. exit;
  166. }
  167. } else {
  168. header('Location: index.php?section=utilisateurs&page=general');
  169. exit;
  170. }
  171. break;
  172. case 'commentaires' :
  173. if (isset($_REQUEST['page'])) {
  174. switch ($_REQUEST['page']) {
  175. case 'display' :
  176. $admin->comments_action();
  177. $admin->comments();
  178. break;
  179. case 'options' :
  180. $admin->comments_options();
  181. break;
  182. case 'bans' :
  183. $admin->comments_bans();
  184. break;
  185. default :
  186. header('Location: index.php?section=commentaires&page=display');
  187. exit;
  188. }
  189. } else {
  190. header('Location: index.php?section=commentaires&page=display');
  191. exit;
  192. }
  193. break;
  194. case 'options' :
  195. if (isset($_REQUEST['page'])) {
  196. switch ($_REQUEST['page']) {
  197. case 'general' :
  198. $admin->options_general();
  199. break;
  200. case 'images' :
  201. $admin->options_images();
  202. break;
  203. case 'itext_params' :
  204. $admin->options_itext();
  205. break;
  206. case 'infos_exif' :
  207. $admin->options_exif();
  208. break;
  209. case 'infos_iptc' :
  210. $admin->options_iptc();
  211. break;
  212. case 'vignettes' :
  213. $admin->options_vignettes();
  214. break;
  215. case 'textes' :
  216. $admin->options_textes();
  217. break;
  218. case 'fonctions' :
  219. $admin->options_fonctions();
  220. break;
  221. case 'perso' :
  222. $admin->options_perso();
  223. break;
  224. default :
  225. header('Location: index.php?section=options&page=general');
  226. exit;
  227. }
  228. } else {
  229. header('Location: index.php?section=options&page=general');
  230. exit;
  231. }
  232. break;
  233. case 'infos' :
  234. $admin->infos();
  235. break;
  236. case 'outils' :
  237. if (isset($_REQUEST['page'])) {
  238. switch ($_REQUEST['page']) {
  239. case 'images' :
  240. $admin->outils_images();
  241. break;
  242. default :
  243. header('Location: index.php?section=outils&page=images');
  244. exit;
  245. }
  246. } else {
  247. header('Location: index.php?section=outils&page=images');
  248. exit;
  249. }
  250. break;
  251. break;
  252. case 'config' :
  253. if (isset($_REQUEST['page'])) {
  254. switch ($_REQUEST['page']) {
  255. case 'conf' :
  256. $admin->config_conf();
  257. break;
  258. case 'infos_sys' :
  259. $admin->config_infosys();
  260. break;
  261. default :
  262. header('Location: index.php?section=config&page=conf');
  263. exit;
  264. }
  265. } else {
  266. header('Location: index.php?section=config&page=conf');
  267. exit;
  268. }
  269. break;
  270. default :
  271. header('Location: index.php?section=galerie&page=gestion');
  272. exit;
  273. }
  274. // Fermeture de la connexion.
  275. $admin->mysql->fermer();
  276. // On démmarre la classe de template.
  277. $tpl = new template($admin->template);
  278. // On appelle le template.
  279. require('template/' . $admin->config['admin_template'] . '/index.php');
  280. // ...sinon on redirige vers la section 'albums'.
  281. } else {
  282. header('Location: index.php?section=galerie&page=gestion');
  283. }
  284. /*
  285. * ========== class.admin
  286. */
  287. class admin {
  288. var $config; // Configuration générale de la galerie.
  289. var $template; // Informations brutes ŕ destination des fonctions de template.
  290. var $mysql; // Connexion MySQL.
  291. var $galerie_dir; // Chemin relatif du répertoire des albums;
  292. /*
  293. * Constructeur.
  294. */
  295. function admin() {
  296. // Connexion ŕ la base de données.
  297. $this->mysql = new connexion(MYSQL_SERV, MYSQL_USER, MYSQL_PASS, MYSQL_BASE);
  298. // Récupération des paramčtres de configuration.
  299. $mysql_requete = 'SELECT parametre,valeur FROM ' . MYSQL_PREF . 'config';
  300. $this->config = $this->mysql->select($mysql_requete, 3);
  301. if (empty($this->config)) {
  302. die ('La base de données est vide.<br />' . mysql_error());
  303. }
  304. // Si l'identifiant de session du cookie est incorrect, on renvoie vers la console de connexion.
  305. $session = new cookie(0, 'galerie_sessionid', GALERIE_PATH . '/' . basename(dirname(__FILE__)));
  306. $session_id = $session->lire('session_id');
  307. $this->config['session_id'] = $session_id;
  308. if (empty($session_id)) {
  309. header('Location: connexion.php?t=cookie');
  310. exit;
  311. }
  312. if ($session_id != $this->config['admin_session_id']) {
  313. header('Location: connexion.php?t=session');
  314. exit;
  315. }
  316. // Si l'identifiant de session a expiré, on renvoie vers la console de connexion.
  317. if (time() > $this->config['admin_session_expire']) {
  318. header('Location: connexion.php?t=expire');
  319. exit;
  320. }
  321. // On génčre un nouveau VID.
  322. $this->template['new_vid'] = outils::gen_key(32);
  323. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'config
  324. SET valeur = "' . $this->template['new_vid'] . '"
  325. WHERE parametre = "admin_vid"';
  326. if (!$this->mysql->requete($mysql_requete)) {
  327. die('Impossible de générer le VID.');
  328. exit;
  329. }
  330. // Vérification du VID dans les formulaires.
  331. if (!empty($_POST)) {
  332. if (empty($this->config['admin_vid']) || empty($_POST['igalvid'])
  333. || $_POST['igalvid'] != $this->config['admin_vid']) {
  334. $params = '';
  335. $params .= (isset($_REQUEST['section'])) ? '?section=' . $_REQUEST['section'] : '';
  336. $params .= (isset($_REQUEST['page'])) ? '&page=' . $_REQUEST['page'] : '';
  337. $params .= (isset($_REQUEST['cat'])) ? '&cat=' . $_REQUEST['cat'] : '';
  338. $params .= (isset($_REQUEST['groupe'])) ? '&groupe=' . $_REQUEST['groupe'] : '';
  339. $params .= (isset($_REQUEST['user'])) ? '&user=' . $_REQUEST['user'] : '';
  340. header('Location: index.php' . $params);
  341. exit;
  342. }
  343. }
  344. // Deconnexion.
  345. if (isset($_GET['igal_admin_deconnect'])) {
  346. $this->verifVID();
  347. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'config SET valeur = ""
  348. WHERE parametre = "admin_session_id"';
  349. $this->mysql->requete($mysql_requete);
  350. header('Location: connexion.php');
  351. exit;
  352. }
  353. // Activation/désactivation de la galerie.
  354. if (!empty($_REQUEST['gal_desactive'])) {
  355. $this->verifVID();
  356. $this->update_option('active_galerie', 0);
  357. header('Location:index.php?' . preg_replace('`&gal_desactive=\d`', '', $_SERVER['QUERY_STRING']));
  358. }
  359. if (!empty($_REQUEST['gal_active'])) {
  360. $this->verifVID();
  361. $this->update_option('active_galerie', 1);
  362. header('Location:index.php?' . preg_replace('`&gal_active=\d`', '', $_SERVER['QUERY_STRING']));
  363. }
  364. $this->config['admin_template'] = 'defaut';
  365. switch ($_REQUEST['section']) {
  366. case 'ftp' :
  367. $this->template['infos']['title'] = 'upload FTP';
  368. break;
  369. }
  370. $this->galerie_dir = dirname(dirname(__FILE__)) . '/' . GALERIE_ALBUMS . '/';
  371. // Configuration.
  372. $this->template['config'] = $this->config;
  373. $this->template['config']['galerie_url'] = GALERIE_URL;
  374. $this->config['admin_comment_ban'] = unserialize($this->config['admin_comment_ban']);
  375. $this->config['img_resize_gd'] = IMG_RESIZE_GD;
  376. $this->config['galerie_template'] = GALERIE_THEME;
  377. $this->config['galerie_style'] = GALERIE_STYLE;
  378. $this->config['galerie_url_type'] = GALERIE_URL_TYPE;
  379. $this->config['galerie_url'] = GALERIE_URL;
  380. $this->config['galerie_path'] = GALERIE_PATH;
  381. $this->config['galerie_integrated'] = GALERIE_INTEGRATED;
  382. include(dirname(__FILE__) . '/../template/' . GALERIE_THEME . '/_fonctions.php');
  383. $this->template['enabled'] = $f;
  384. }
  385. /*
  386. * Vérification de l'identifiant de session pour chaque action sur la galerie.
  387. */
  388. function verifVID() {
  389. if (empty($this->config['admin_vid']) || empty($_GET['igalvid'])
  390. || $_GET['igalvid'] != $this->config['admin_vid']) {
  391. $params = '';
  392. $params .= (isset($_REQUEST['section'])) ? '?section=' . $_REQUEST['section'] : '';
  393. $params .= (isset($_REQUEST['page'])) ? '&page=' . $_REQUEST['page'] : '';
  394. $params .= (isset($_REQUEST['cat'])) ? '&cat=' . $_REQUEST['cat'] : '';
  395. $params .= (isset($_REQUEST['groupe'])) ? '&groupe=' . $_REQUEST['groupe'] : '';
  396. $params .= (isset($_REQUEST['user'])) ? '&user=' . $_REQUEST['user'] : '';
  397. header('Location: index.php' . $params);
  398. exit;
  399. }
  400. }
  401. /*
  402. * UPDATE des options.
  403. */
  404. function update_option($option, $valeur, $r = 1) {
  405. $valeur_mysql = outils::protege_mysql($valeur, $this->mysql->lien);
  406. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'config SET valeur = "' . $valeur_mysql . '"
  407. WHERE parametre = "' . $option . '"';
  408. if ($this->mysql->requete($mysql_requete)) {
  409. if ($r) {
  410. $this->config[$option] = $valeur;
  411. }
  412. return true;
  413. }
  414. return false;
  415. }
  416. /*
  417. * Fonction d'upload FTP.
  418. */
  419. function ftp() {
  420. // Recherche et ajout ŕ la base de données de nouvelles images et albums.
  421. $upload = new upload($this->mysql, $this->config);
  422. $upload->recup_albums();
  423. // Contrôle du temps d'exécution.
  424. if ($upload->arret) {
  425. $this->template['infos']['info']['ftp_trop'] = 'Il y a trop d\'images : cliquez ŕ nouveau sur le bouton pour scanner les répertoires restants...';
  426. }
  427. // Rapport.
  428. $rapport_resume = '';
  429. $rapport_details = '';
  430. // Erreurs.
  431. if ($upload->rapport['erreurs']) {
  432. if (count($upload->rapport['erreurs']) > 1) {
  433. $upload_verbes = ' se sont';
  434. $s = 's';
  435. } else {
  436. $upload_verbes = ' s\'est';
  437. $s = '';
  438. }
  439. $rapport_resume .= '<div class="rapport_msg rapport_erreur"><div><span>' . count($upload->rapport['erreurs']) . ' erreur' . $s . $upload_verbes . ' produite' . $s . '.</span></div></div>' . "\n";
  440. }
  441. // Ajouts.
  442. if ((count($upload->rapport['alb_ajouts']) + $upload->rapport['img_ajouts']) > 0) {
  443. $e = ($upload->rapport['alb_ajouts']) ? '' : 'e';
  444. $ajout_verbes = ((count($upload->rapport['alb_ajouts']) + $upload->rapport['img_ajouts']) > 1) ? ' ont été ajouté' . $e . 's' : ' a été ajouté' . $e;
  445. $et = ($upload->rapport['alb_ajouts']) ? ' et ' : '';
  446. $as = (count($upload->rapport['alb_ajouts']) > 1) ? 's' : '';
  447. $is = ($upload->rapport['img_ajouts'] > 1) ? 's' : '';
  448. $albs = ($upload->rapport['alb_ajouts']) ? count($upload->rapport['alb_ajouts']) . ' album' . $as : '';
  449. $imgs = ($upload->rapport['img_ajouts']) ? $et . $upload->rapport['img_ajouts'] . ' image' . $is : '';
  450. $rapport_resume .= '<div class="rapport_msg rapport_succes"><div><span>' . $albs . $imgs . $ajout_verbes . ' ŕ la base de données.</span></div></div>' . "\n";
  451. } else {
  452. $rapport_resume .= '<div class="rapport_msg rapport_infos"><div><span>Aucun nouvel album et aucune nouvelle image n\'a été détecté.</span></div></div>' . "\n";
  453. }
  454. // Mises ŕ jour.
  455. if ($upload->rapport['alb_maj']) {
  456. if (count($upload->rapport['alb_maj']) > 1) {
  457. $upload_verbes = ' ont';
  458. $s = 's';
  459. } else {
  460. $upload_verbes = ' a';
  461. $s = '';
  462. }
  463. $rapport_resume .= '<div class="rapport_msg rapport_succes"><div><span>' . count($upload->rapport['alb_maj']) . ' album' . $s . $upload_verbes . ' été mis ŕ jour.</span></div></div>' . "\n";
  464. } else {
  465. $rapport_resume .= '<div class="rapport_msg rapport_infos"><div><span>Aucun album n\'a été mis ŕ jour.</span></div></div>' . "\n";
  466. }
  467. // Update Exif.
  468. if ($upload->images_update_exif) {
  469. $s = ($upload->images_update_exif > 1) ? 's' : '';
  470. $rapport_resume .= '<div class="rapport_msg rapport_succes"><div><span>Les meta-données Exif ont été ajoutées pour ' . $upload->images_update_exif . ' image' . $s . '.</span></div></div>' . "\n";
  471. }
  472. // Rejets.
  473. if ((count($upload->rapport['cat_rejets']) + count($upload->rapport['img_rejets'])) > 0) {
  474. $e = ($upload->rapport['cat_rejets']) ? '' : 'e';
  475. $ajout_verbes = ((count($upload->rapport['cat_rejets']) + count($upload->rapport['img_rejets'])) > 1) ? ' ont été rejeté' . $e . 's' : ' a été rejeté' . $e;
  476. $et = ($upload->rapport['cat_rejets']) ? ' et ' : '';
  477. $as = ($upload->rapport['cat_rejets'] > 1) ? 's' : '';
  478. $is = (count($upload->rapport['img_rejets']) > 1) ? 's' : '';
  479. $albs = ($upload->rapport['cat_rejets']) ? count($upload->rapport['cat_rejets']) . ' catégorie' . $as . ' ou album' . $as : '';
  480. $imgs = ($upload->rapport['img_rejets']) ? $et . count($upload->rapport['img_rejets']) . ' image' . $is : '';
  481. $rapport_resume .= '<div class="rapport_msg rapport_avert"><div><span>' . $albs . $imgs . $ajout_verbes . '.</span></div></div>' . "\n";
  482. }
  483. // Détails du rapport.
  484. if ($upload->rapport['erreurs']) {
  485. $rapport_details .= '<table id="ftp_details_erreur" class="ftp_details">' . "\n" . '<tr><th>Objet</th><th>Erreur</th></tr>' . "\n";
  486. foreach ($upload->rapport['erreurs'] as $v) {
  487. $rapport_details .= '<tr><td>' . wordwrap($v[0], 50, '<br />', 1) . '</td><td>' . $v[1] . '</td></tr>';
  488. }
  489. $rapport_details .= '</table><br />' . "\n";
  490. }
  491. if ($upload->rapport['alb_ajouts']) {
  492. $rapport_details .= '<table class="ftp_details">' . "\n" . '<tr><th>Album ajouté</th><th>Nb. d\'images</th><th>Poids</th></tr>' . "\n";
  493. foreach ($upload->rapport['alb_ajouts'] as $v) {
  494. $rapport_details .= '<tr><td>' . wordwrap($v[0], 50, '<br />', 1) . '</td><td>' . $v[1] . '</td><td>' . $v[2] . '</td></tr>';
  495. }
  496. $rapport_details .= '</table><br />' . "\n";
  497. }
  498. if ($upload->rapport['alb_maj']) {
  499. $rapport_details .= '<table class="ftp_details">' . "\n" . '<tr><th>Album mis ŕ jour</th><th>Nb. d\'images supp.</th><th>Poids supp.</th></tr>' . "\n";
  500. foreach ($upload->rapport['alb_maj'] as $v) {
  501. $rapport_details .= '<tr><td>' . wordwrap($v[0], 50, '<br />', 1) . '</td><td>' . $v[1] . '</td><td>' . $v[2] . '</td></tr>';
  502. }
  503. $rapport_details .= '</table><br />' . "\n";
  504. }
  505. if ($upload->rapport['cat_rejets']) {
  506. $rapport_details .= '<table class="ftp_details">' . "\n" . '<tr><th>Catégorie rejetée</th><th>Cause</th></tr>' . "\n";
  507. foreach ($upload->rapport['cat_rejets'] as $v) {
  508. $rapport_details .= '<tr><td>' . wordwrap($v[0], 50, '<br />', 1) . '</td><td>' . $v[1] . '</td></tr>';
  509. }
  510. $rapport_details .= '</table><br />' . "\n";
  511. }
  512. if ($upload->rapport['img_rejets']) {
  513. $rapport_details .= '<table class="ftp_details">' . "\n" . '<tr><th>Image rejetée</th><th>Album</th><th>Cause</th></tr>' . "\n";
  514. foreach ($upload->rapport['img_rejets'] as $v) {
  515. $rapport_details .= '<tr><td>' . wordwrap($v[0], 50, '<br />', 1) . '</td><td>' . wordwrap($v[1], 50, '<br />', 1) . '</td><td>' . $v[2] . '</td></tr>';
  516. }
  517. $rapport_details .= '</table><br />' . "\n";
  518. }
  519. // On ajoute le rapport finalisé au tableau destiné au template.
  520. $this->template['rapport'] = '<div id="ftp_rapport_resume"><span class="ftp_rapport_titre">Rapport résumé</span><br /><br />' . $rapport_resume . '</div>' . "\n";
  521. if (!empty($rapport_details)) {
  522. $this->template['rapport'] .= '<p id="ftp_rapport_details"><span class="ftp_rapport_titre">Rapport détaillé</span></p>' . "\n";
  523. $this->template['rapport'] .= $rapport_details;
  524. }
  525. // Template.
  526. $this->template['config'] = $this->config;
  527. }
  528. /*
  529. * Désactivation d'un commentaire.
  530. */
  531. function comment_action_desactive() {
  532. $mysql_requete = 'SELECT commentaire_visible FROM ' . MYSQL_PREF . 'commentaires
  533. WHERE commentaire_id = "' . $_REQUEST['desactive'] . '"';
  534. $visible = $this->mysql->select($mysql_requete, 5);
  535. if (!empty($visible)) {
  536. $this->comments_update_nb('desactive', 0, '-');
  537. $this->template['action_maj'] = 1;
  538. }
  539. }
  540. /*
  541. * Désactivation d'un commentaire.
  542. */
  543. function comment_action_active() {
  544. $mysql_requete = 'SELECT commentaire_visible FROM ' . MYSQL_PREF . 'commentaires
  545. WHERE commentaire_id = "' . $_REQUEST['active'] . '"';
  546. $visible = $this->mysql->select($mysql_requete, 5);
  547. if (empty($visible)) {
  548. $this->comments_update_nb('active', 1, '+');
  549. $this->template['action_maj'] = 1;
  550. }
  551. }
  552. /*
  553. * Suppression d'un commentaire.
  554. */
  555. function comment_action_delete($mass = 0) {
  556. static $ids_nb = 0;
  557. static $ids;
  558. $ids = $ids . ', ' . $_REQUEST['supprime'];
  559. $ids_nb++;
  560. $mysql_requete = 'SELECT ' . MYSQL_PREF . 'images.image_chemin,
  561. ' . MYSQL_PREF . 'commentaires.commentaire_visible
  562. FROM ' . MYSQL_PREF . 'commentaires INNER JOIN ' . MYSQL_PREF . 'images USING(image_id)
  563. WHERE ' . MYSQL_PREF . 'commentaires.commentaire_id = "' . $_REQUEST['supprime'] . '"';
  564. $i_co = $this->mysql->select($mysql_requete, 11);
  565. $path = $i_co['image_chemin'];
  566. // On vérifie si le commentaire existe.
  567. if ($i_co == 'vide') {
  568. return;
  569. }
  570. // On supprime le commentaire.
  571. $mysql_requete = 'DELETE FROM ' . MYSQL_PREF . 'commentaires
  572. WHERE commentaire_id = "' . $_REQUEST['supprime'] . '"';
  573. if ($this->mysql->requete($mysql_requete)) {
  574. // On UPDATE le nombre de commentaires de l'image et des catégories parentes,
  575. // mais seulement si le commentaire n'est pas désactivé !
  576. if ($i_co['commentaire_visible']) {
  577. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'images SET
  578. image_commentaires = image_commentaires - 1
  579. WHERE image_chemin = "' . $path . '"';
  580. $this->mysql->requete($mysql_requete);
  581. while ($path != '.') {
  582. $path = dirname($path);
  583. $path = ($path == '.') ? $path : $path . '/' ;
  584. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'categories SET
  585. categorie_commentaires = categorie_commentaires - 1
  586. WHERE categorie_chemin = "' . $path . '"';
  587. $this->mysql->requete($mysql_requete);
  588. }
  589. }
  590. $comment_ids = substr($ids, 2);
  591. if (strstr($comment_ids, ',')) {
  592. $this->template['infos']['action']['co_supprime'] = 'Les commentaires ' . preg_replace('`, (\d+)$`', ' et $1', $comment_ids) . ' ont été supprimés.';
  593. } else {
  594. $this->template['infos']['action']['co_supprime'] = 'Le commentaire ' . $_REQUEST['supprime'] . ' a été supprimé.';
  595. }
  596. $_REQUEST['startnum'] = 0;
  597. }
  598. }
  599. /*
  600. * Bannissement d'un auteur.
  601. */
  602. function comments_action_ban_auteur() {
  603. $mysql_requete = 'SELECT commentaire_auteur FROM ' . MYSQL_PREF . 'commentaires
  604. WHERE commentaire_id = "' . $_REQUEST['ban_auteur'] . '"';
  605. $auteur = $this->mysql->select($mysql_requete, 5);
  606. $this->config['admin_comment_ban']['auteurs'][$auteur] = 1;
  607. $this->template['action_maj'] = 1;
  608. $bans = $this->config['admin_comment_ban'];
  609. $this->update_option('admin_comment_ban', serialize($bans), 0);
  610. }
  611. /*
  612. * Unban d'un auteur.
  613. */
  614. function comments_action_unban_auteur() {
  615. $mysql_requete = 'SELECT commentaire_auteur FROM ' . MYSQL_PREF . 'commentaires
  616. WHERE commentaire_id = "' . $_REQUEST['unban_auteur'] . '"';
  617. $auteur = $this->mysql->select($mysql_requete, 5);
  618. if (isset($this->config['admin_comment_ban']['auteurs'][$auteur])) {
  619. unset($this->config['admin_comment_ban']['auteurs'][$auteur]);
  620. }
  621. $this->template['action_maj'] = 1;
  622. $bans = $this->config['admin_comment_ban'];
  623. $this->update_option('admin_comment_ban', serialize($bans), 0);
  624. }
  625. /*
  626. * Bannissement d'une IP.
  627. */
  628. function comments_action_ban_ip() {
  629. $mysql_requete = 'SELECT commentaire_ip FROM ' . MYSQL_PREF . 'commentaires
  630. WHERE commentaire_id = "' . $_REQUEST['ban_ip'] . '"';
  631. $IP = $this->mysql->select($mysql_requete, 5);
  632. $this->config['admin_comment_ban']['IP'][$IP] = 1;
  633. //$this->template['infos']['action']['co_rb_ip'] = 'L\'IP ' . $IP . ' a été bannie.';
  634. $this->template['action_maj'] = 1;
  635. $bans = $this->config['admin_comment_ban'];
  636. $this->update_option('admin_comment_ban', serialize($bans), 0);
  637. }
  638. /*
  639. * Unban d'une IP.
  640. */
  641. function comments_action_unban_ip() {
  642. $mysql_requete = 'SELECT commentaire_ip FROM ' . MYSQL_PREF . 'commentaires
  643. WHERE commentaire_id = "' . $_REQUEST['unban_ip'] . '"';
  644. $IP = $this->mysql->select($mysql_requete, 5);
  645. if (isset($this->config['admin_comment_ban']['IP'][$IP])) {
  646. unset($this->config['admin_comment_ban']['IP'][$IP]);
  647. }
  648. //$this->template['infos']['action']['co_ru_ip'] = 'Les commentaires en provenance de l\'IP ' . $IP . ' sont de nouveau autorisés.';
  649. $this->template['action_maj'] = 1;
  650. $bans = $this->config['admin_comment_ban'];
  651. $this->update_option('admin_comment_ban', serialize($bans), 0);
  652. }
  653. /*
  654. * Action sur les commentaires, les auteurs et les IP.
  655. */
  656. function comments_action() {
  657. // Traitement par lot.
  658. if (isset($_GET['mass']) && isset($_POST['co_mass_action']) && isset($_POST['comment_id'])) {
  659. foreach ($_POST['comment_id'] as $id => $e) {
  660. switch ($_POST['co_mass_action']) {
  661. case 'desactiver' :
  662. $_REQUEST['desactive'] = $id;
  663. $this->comment_action_desactive();
  664. break;
  665. case 'activer' :
  666. $_REQUEST['active'] = $id;
  667. $this->comment_action_active();
  668. break;
  669. case 'supprimer' :
  670. $_REQUEST['supprime'] = $id;
  671. $this->comment_action_delete();
  672. break;
  673. case 'ban_auteurs' :
  674. $_REQUEST['ban_auteur'] = $id;
  675. $this->comments_action_ban_auteur();
  676. break;
  677. case 'aut_auteurs' :
  678. $_REQUEST['unban_auteur'] = $id;
  679. $this->comments_action_unban_auteur();
  680. break;
  681. case 'ban_ip' :
  682. $_REQUEST['ban_ip'] = $id;
  683. $this->comments_action_ban_ip();
  684. break;
  685. case 'aut_ip' :
  686. $_REQUEST['unban_ip'] = $id;
  687. $this->comments_action_unban_ip();
  688. break;
  689. }
  690. }
  691. unset($_REQUEST['desactive']);
  692. unset($_REQUEST['active']);
  693. unset($_REQUEST['supprime']);
  694. unset($_REQUEST['ban_auteur']);
  695. unset($_REQUEST['unban_auteur']);
  696. unset($_REQUEST['ban_ip']);
  697. unset($_REQUEST['unban_ip']);
  698. }
  699. // Désactivation du commentaire.
  700. if (isset($_REQUEST['desactive']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['desactive'])) {
  701. $this->verifVID();
  702. $this->comment_action_desactive();
  703. // Activation du commentaire.
  704. } elseif (isset($_REQUEST['active']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['active'])) {
  705. $this->verifVID();
  706. $this->comment_action_active();
  707. // Suppression du commentaire.
  708. } elseif (isset($_REQUEST['supprime']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['supprime'])) {
  709. $this->verifVID();
  710. $this->comment_action_delete();
  711. // Bannissement d'un auteur.
  712. } elseif (isset($_REQUEST['ban_auteur']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['ban_auteur'])) {
  713. $this->verifVID();
  714. $this->comments_action_ban_auteur();
  715. // Unban d'un auteur.
  716. } elseif (isset($_REQUEST['unban_auteur']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['unban_auteur'])) {
  717. $this->verifVID();
  718. $this->comments_action_unban_auteur();
  719. // Bannissement d'une IP.
  720. } elseif (isset($_REQUEST['ban_ip']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['ban_ip'])) {
  721. $this->verifVID();
  722. $this->comments_action_ban_ip();
  723. // Unban d'une IP.
  724. } elseif (isset($_REQUEST['unban_ip']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['unban_ip'])) {
  725. $this->verifVID();
  726. $this->comments_action_unban_ip();
  727. }
  728. }
  729. /*
  730. * UPDATE des informations sur l'activation/désactivation d'un commentaire.
  731. */
  732. function comments_update_nb($e, $n, $i) {
  733. // On UPDATE l'état 'visible' du commentaire.
  734. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'commentaires SET
  735. commentaire_visible = "' . $n . '"
  736. WHERE commentaire_id = "' . $_REQUEST[$e] . '"';
  737. if ($this->mysql->requete($mysql_requete)) {
  738. // On UPDATE le nombre de commentaires de l'image et des catégories parentes.
  739. $mysql_requete = 'SELECT ' . MYSQL_PREF . 'images.image_chemin
  740. FROM ' . MYSQL_PREF . 'commentaires INNER JOIN ' . MYSQL_PREF . 'images USING(image_id)
  741. WHERE ' . MYSQL_PREF . 'commentaires.commentaire_id = "' . $_REQUEST[$e] . '"';
  742. $path = $this->mysql->select($mysql_requete, 5);
  743. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'images SET
  744. image_commentaires = image_commentaires ' . $i . ' 1
  745. WHERE image_chemin = "' . $path . '"';
  746. $this->mysql->requete($mysql_requete);
  747. while ($path != '.') {
  748. $path = dirname($path);
  749. $path = ($path == '.') ? $path : $path . '/' ;
  750. $mysql_requete = 'UPDATE ' . MYSQL_PREF . 'categories SET
  751. categorie_commentaires = categorie_commentaires ' . $i . ' 1
  752. WHERE categorie_chemin = "' . $path . '"';
  753. $this->mysql->requete($mysql_requete);
  754. }
  755. }
  756. }
  757. /*
  758. * Affichage des commentaires.
  759. */
  760. function comments() {
  761. $this->template['infos']['title'] = 'gestion des commentaires';
  762. // Trie des commentaires : ordre.
  763. if (isset($_REQUEST['sort']) && preg_match('`^commentaire_(auteur|date|mail|ip|web)|image_chemin$`', $_REQUEST['sort']) && $_REQUEST['sort'] != $this->config['admin_comment_ordre']) {
  764. $this->template['infos']['comment_sort'] = $_REQUEST['sort'];
  765. $this->update_option('admin_comment_ordre', $_REQUEST['sort']);
  766. } else {
  767. $this->template['infos']['comment_sort'] = $this->config['admin_comment_ordre'];
  768. }
  769. // Trie des commentaires : sens.
  770. if (isset($_REQUEST['sens']) && preg_match('`^ASC|DESC$`', $_REQUEST['sens']) && $_REQUEST['sens'] != $this->config['admin_comment_sens']) {
  771. $this->template['infos']['comment_sens'] = $_REQUEST['sens'];
  772. $this->update_option('admin_comment_sens', $_REQUEST['sens']);
  773. } else {
  774. $this->template['infos']['comment_sens'] = $this->config['admin_comment_sens'];
  775. }
  776. // Page ŕ afficher.
  777. if (isset($_REQUEST['startnum']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['startnum'])) {
  778. $startnum = $_REQUEST['startnum'];
  779. } else {
  780. $startnum = 0;
  781. }
  782. // Filtre.
  783. $filtre = $this->config['admin_comment_filtre'];
  784. if (isset($_REQUEST['filtre']) && preg_match('`^(tous|actif|inactif)$`', $_REQUEST['filtre']) && $filtre != $_REQUEST['filtre']) {
  785. $this->update_option('admin_comment_filtre', $_REQUEST['filtre']);
  786. $filtre = $_REQUEST['filtre'];
  787. $startnum = 0;
  788. }
  789. $this->template['infos']['comment_filtre'] = $filtre;
  790. switch ($filtre) {
  791. case 'actif' :
  792. $filtre = ' AND ' . MYSQL_PREF . 'commentaires.commentaire_visible = "1"';
  793. break;
  794. case 'inactif' :
  795. $filtre = ' AND ' . MYSQL_PREF . 'commentaires.commentaire_visible = "0"';
  796. break;
  797. default :
  798. $filtre = '';
  799. }
  800. // Nombre de commentaires par page.
  801. if (isset($_REQUEST['nb']) && preg_match('`^[1-9]\d{0,3}$`', $_REQUEST['nb']) && $_REQUEST['nb'] != $this->config['admin_comment_nb']) {
  802. $this->update_option('admin_comment_nb', $_REQUEST['nb']);
  803. $this->config['admin_comment_nb'] = $_REQUEST['nb'];
  804. $this->template['infos']['nb_comments'] = $_REQUEST['nb'];
  805. $startnum = 0;
  806. } else {
  807. $this->template['infos']['nb_comments'] = $this->config['admin_comment_nb'];
  808. }
  809. $this->template['infos']['startnum'] = $startnum;
  810. // Objet actuel.
  811. if (isset($_REQUEST['cat']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['cat'])) {
  812. $obj = $_REQUEST['cat'];
  813. $obj_type = 'cat';
  814. $obj_type_ext = 'categorie';
  815. } elseif (isset($_REQUEST['img']) && preg_match('`^[1-9]\d{0,9}$`', $_REQUEST['img'])) {
  816. $obj = $_REQUEST['img'];
  817. $obj_type = 'img';
  818. $obj_type_ext = 'image';
  819. } else {
  820. $obj = 1;
  821. $obj_type = 'cat';
  822. $obj_type_ext = 'categorie';
  823. }
  824. $this->template['infos']['section'] = 'section=commentaires&page=display&' . $obj_type . '=' . $obj;
  825. $this->template['infos']['obj'] = $obj;
  826. $this->template['infos']['obj_type'] = $obj_type;
  827. $mysql_requete = 'SELECT ' . $obj_type_ext . '_chemin,
  828. ' . $obj_type_ext . '_nom
  829. FROM ' . MYSQL_PREF . $obj_type_ext . 's
  830. WHERE ' . $obj_type_ext . '_id = "' . $obj . '"';
  831. $obj = $this->mysql->select($mysql_requete, 11);
  832. if (!is_array($obj)) {
  833. header('Location:index.php?section=commentaires&page=display');
  834. exit;
  835. }
  836. $obj_chemin = ($obj[$obj_type_ext . '_chemin'] == '.') ? '' : $obj[$obj_type_ext . '_chemin'];
  837. // Recherche.
  838. $this->template['infos']['recherche'] = '';
  839. $recherche = '';
  840. if (isset($_REQUEST['search'])) {
  841. if (isset($_REQUEST['s_accents'])) {
  842. $search_inputs['s_accents'] = '1';
  843. $this->template['infos']['recherche'] .= '&s_accents=on';
  844. }
  845. if (isset($_REQUEST['s_casse'])) {
  846. $search_inputs['s_casse'] = '1';
  847. $this->template['infos']['recherche'] .= '&s_casse=on';
  848. }
  849. if (isset($_REQUEST['s_tous'])) {
  850. $search_inputs['s_tous'] = '1';
  851. $this->template['infos']['recherche'] .= '&s_tous=on';
  852. }
  853. if (isset($_REQUEST['s_msg'])) {
  854. $search_inputs['s_msg'] = '1';
  855. $this->template['infos']['recherche'] .= '&s_msg=on';
  856. }
  857. if (isset($_REQUEST['s_auteur'])) {
  858. $search_inputs['s_auteur'] = '1';
  859. $this->template['infos']['recherche'] .= '&s_auteur=on';
  860. }
  861. if (isset($_REQUEST['s_ip'])) {
  862. $search_inputs['s_ip'] = '1';
  863. $this->template['infos']['recherche'] .= '&s_ip=on';
  864. }
  865. if (isset($_REQUEST['s_mail'])) {
  866. $search_inputs['s_mail'] = '1';
  867. $this->template['infos']['recherche'] .= '&s_mail=on';
  868. }
  869. if (isset($_REQUEST['s_web'])) {
  870. $search_inputs['s_web'] = '1';
  871. $this->template['infos']['recherche'] .= '&s_web=on';
  872. }
  873. // On affiche les messages des commentaires.
  874. $this->template['display']['comment_msg'] = 1;
  875. $search_inputs['search'] = outils::html_specialchars($_REQUEST['search']);
  876. $this->template['infos']['recherche'] .= '&search=' . urlencode($_REQUEST['search']);
  877. // Récupération de la requęte.
  878. $search = trim($_REQUEST['search']);
  879. $search = preg_replace('`-+`', '-', $search);
  880. $search = str_replace('- ', '', $search);
  881. $search = str_replace(' *', '', $search);
  882. $search = preg_replace('`\s+`', ' ', $search);
  883. // Méthodes Ť AND ť ou Ť OR ť.
  884. $method = (isset($_REQUEST['s_tous'])) ? 'AND' : 'OR';
  885. // Casse.
  886. $binary = (isset($_REQUEST['s_casse'])) ? 'BINARY ' : '';
  887. // Si ni la casse ni les accents comptent, on concertit tout en minuscule.
  888. if (!isset($_REQUEST['s_casse']) && !isset($_REQUEST['s_accents'])) {
  889. $search = strtolower($search);
  890. }
  891. // Paramčtres de recherche.
  892. $search = preg_split('`\s+(?!.*[^-\s]")`i', $search, -1, PREG_SPLIT_NO_EMPTY);
  893. $champs = array();
  894. $champs['message'] = '';
  895. $champs['auteur'] = '';
  896. $champs['ip'] = '';
  897. $champs['mail'] = '';
  898. $champs['web'] = '';
  899. for ($i = 0; $i < count($search); $i++) {
  900. // Suppression des guillemets.
  901. $terme = str_replace('"', '', $search[$i]);
  902. // Remplacement des espace par une suite de caractčres non-alpha-numérique.
  903. $terme = preg_replace('`[^-\w\*\?\'\s]+`', '?', $terme);
  904. // Doit-on ne pas faire de distinction pour les lettres accentuées ?
  905. $terme = (isset($_REQUEST['s_accents'])) ? $terme : outils::regexp_accents($terme);
  906. // Doit-on inclure ou exclure le terme ?
  907. $terme = ($search[$i]{0} == '-') ? substr($terme, 1) : $terme;
  908. $not = ($search[$i]{0} == '-') ? 'NOT ' : '';
  909. // Si le terme est vide, inutile d'aller plus loin.
  910. if (trim($terme) == '') {
  911. continue;
  912. }
  913. // Remplacement des espace par une suite de caractčres non-alpha-numérique.
  914. $terme = str_replace(' ', '[^[:alnum:]]', $terme);
  915. // Joker Ť * ť.
  916. $terme = str_replace('*', '[^[:space:]]*', $terme);
  917. // Joker Ť ? ť.
  918. $terme = str_replace('?', '.', $terme);
  919. // On ne recherche que des mots entiers.
  920. $terme = '([^[:alnum:]]|^)' . $terme . '([^[:alnum:]]|$)';
  921. // Champ message.
  922. if (isset($_REQUEST['s_msg'])) {
  923. $champs['message'] .= $method . ' ' . MYSQL_PREF . 'commentaires.commentaire_message ' . $not . 'REGEXP ' . $binary . '"' . outils::protege_mysql($terme, $this->mysql->lien) . '" ';
  924. }
  925. // Champ auteur.
  926. if (isset($_REQUEST['s_auteur'])) {
  927. $champs['auteur'] .= $method . ' ' . MYSQL_PREF . 'commentaires.commentaire_auteur ' . $not . 'REGEXP ' . $binary . '"' . outils::protege_mysql($terme, $this->mysql->lien) . '" ';
  928. }
  929. // Champ ip.
  930. if (isset($_REQUEST['s_ip'])) {
  931. $champs['ip'] .= $method . ' ' . MYSQL_PREF . 'commentaires.commentaire_ip ' . $not . 'REGEXP ' . $binary . '"' . outils::protege_mysql($terme, $this->mysql->lien) . '" ';
  932. }
  933. // Champ mail.
  934. if (isset($_REQUEST['s_mail'])) {
  935. $champs['mail'] .= $method . ' ' . MYSQL_PREF . 'commentaires.commentaire_mail ' . $not . 'REGEXP ' . $binary . '"' . outils::protege_mysql($terme, $this->mysql->lien) . '" ';
  936. }
  937. // Champ web.
  938. if (isset($_REQUEST['s_web'])) {
  939. $champs['web'] .= $method . ' ' . MYSQL_PREF . 'commentaires.commentaire_web ' . $not . 'REGEXP ' . $binary . '"' . outils::protege_mysql($terme, $this->mysql->lien) . '" ';
  940. }
  941. }
  942. // Champs de la table dans lesquels la recherche s'effectuera.
  943. $commentaires_champs = '';
  944. foreach ($champs as $v) {
  945. if ($v) {
  946. $commentaires_champs .= 'OR (' . preg_replace('`^(?:AND|OR) `', '', $v) . ') ';
  947. }
  948. }
  949. if ($commentaires_champs) {
  950. $commentaires_champs = '(' . preg_replace('`^OR `', '', $commentaires_champs) . ')';
  951. }
  952. // Date
  953. $commentaires_date = '';
  954. if (isset($_REQUEST['s_date']) && isset($_REQUEST['s_dnpc']) && isset($_REQUEST['s_dnpd'])
  955. && isset($_REQUEST['s_dnsc']) && isset($_REQUEST['s_dnsd'])) {
  956. $search_inputs['s_date'] = $_REQUEST['s_date'];
  957. $search_inputs['s_dnpc'] = $_REQUEST['s_dnpc'];
  958. $search_inputs['s_dnpd'] = $_REQUEST['s_dnpd'];
  959. $search_inputs['s_dnsc'] = $_REQUEST['s_dnsc'];
  960. $search_inputs['s_dnsd'] = $_REQUEST['s_dnsd'];
  961. $this->template['infos']['recherche'] .= '&s_date=on&s_dnpc=' . $_REQUEST['s_dnpc'];
  962. $this->template['infos']['recherche'] .= '&s_dnpd=' . $_REQUEST['s_dnpd'];
  963. $this->template['infos']['recherche'] .= '&s_dnsc=' . $_REQUEST['s_dnsc'];
  964. $this->template['infos']['recherche'] .= '&s_dnsd=' . $_REQUEST['s_dnsd'];
  965. $commentaires_date .= '' . MYSQL_PREF . 'commentaires.commentaire_date < ' . outils::time_date($_REQUEST['s_dnpc'], $_REQUEST['s_dnpd'])
  966. . ' AND ' . MYSQL_PREF . 'commentaires.commentaire_date > ' . outils::time_date($_REQUEST['s_dnsc'], $_REQUEST['s_dnsd']);
  967. }
  968. if ($commentaires_champs || $commentaires_date) {
  969. $and = ($commentaires_champs && $commentaires_date) ? ' AND ' : '';
  970. $recherche = ' AND (' . $commentaires_champs . $and . $commentaires_date . ')';
  971. }
  972. $this->template['comments']['search'] = $search_inputs;
  973. }
  974. // Sous-objets.
  975. $mysql_requete = 'SELECT categorie_id,categorie_nom,categorie_chemin FROM ' . MYSQL_PREF . 'categories
  976. WHERE categorie_chemin REGEXP "^' . $obj_chemin . '[^/]+/$"
  977. AND categorie_id > 1
  978. AND (categorie_commentaires > 0 OR categorie_commentaires_inactive > 0)';
  979. $sub_cat = $this->mysql->select($mysql_requete);
  980. if (is_array($sub_cat)) {
  981. for ($i = 0; $i < count($sub_cat); $i++) {
  982. $this->template['comments']['sub_item'][$i] = $sub_cat[$i];
  983. $this->template['display']['subcats'] = 1;
  984. $this->template['infos']['sub_objects'] = 'categorie';
  985. }
  986. } else {
  987. $mysql_requete = 'SELECT image_id,image_nom,image_chemin FROM ' . MYSQL_PREF . 'images
  988. WHERE image_chemin REGEXP "^' . $obj_chemin . '[^/]+$"
  989. AND image_commentaires > 0';
  990. $imgs = $this->mysql->select($mysql_requete);
  991. if (is_array($imgs)) {
  992. for ($i = 0; $i < count($imgs); $i++) {
  993. $this->template['comments']['sub_item'][$i] = $imgs[$i];
  994. $this->template['display']['subcats'] = 1;
  995. $this->template['infos']['sub_objects'] = 'image';
  996. }
  997. }
  998. }
  999. // Barre de position.
  1000. $this->template['comments']['position'] = '';
  1001. if ($obj_chemin) {
  1002. $parent = dirname($obj_chemin);
  1003. while ($parent != '.') {
  1004. $mysql_requete = 'SELECT categorie_id,categorie_chemin,categorie_nom
  1005. FROM ' . MYSQL_PREF . 'categories
  1006. WHERE categorie_chemin = "' . $parent . '/"';
  1007. $p_i = $this->mysql->select($mysql_requete, 11);
  1008. $parent = dirname($p_i['categorie_chemin']);
  1009. $this->template['comments']['position'] = '%sep<a href="index.php?section=commentaires&amp;page=display&amp;cat=' .
  1010. $p_i['categorie_id'] . htmlentities($this->template['infos']['recherche']) . '">' .
  1011. strip_tags($p_i['categorie_nom']) . '</a>' .
  1012. $this->template['comments']['position'];
  1013. }
  1014. }
  1015. $pos_actuel = ($this->template['infos']['obj'] > 1) ? '' : ' class="pos_actuel"' ;
  1016. $this->template['comments']['position'] = '<a' . $pos_actuel . ' href="index.php?section=commentaires&amp;page=display' .
  1017. htmlentities($this->template['infos']['recherche']) . '">galerie</a>' . $this->template['comments']['position'];
  1018. if ($this->template['infos']['obj'] > 1) {
  1019. $this->template['comments']['position'] .= '%sep<a href="index.php?section=commentaires&amp;page=display&amp;' . $obj_type . '=' .
  1020. $this->template['infos']['obj'] . htmlentities($this->template['infos']['recherche']) .
  1021. '" class="pos_actuel">' .
  1022. strip_tags($obj[$obj_type_ext . '_nom']) . '</a>';
  1023. }
  1024. // Récupération du nombre de commentaires de l'objet actuel.
  1025. $mysql_requete = 'SELECT COUNT(*)
  1026. FROM ' . MYSQL_PREF . 'commentaires INNER JOIN ' . MYSQL_PREF . 'images USING(image_id)
  1027. WHERE ' . MYSQL_PREF . 'images.image_chemin LIKE "' . $obj_chemin . '%"'
  1028. . $recherche . $filtre;
  1029. if ($nc = $this->mysql->select($mysql_requete, 5)) {
  1030. $this->template['infos']['nb_objets'] = $nc;
  1031. } else {
  1032. $this->template['infos']['nb_objets'] = 0;
  1033. }
  1034. // On détermine le nombre de pages et la page actuelle.
  1035. $this->template['infos']['nb_pages'] = ceil(($this->template['infos']['nb_objets']) / $this->config['admin_comment_nb']);
  1036. for ($n = 0; $n < $this->template['infos']['nb_pages']; $n++) {
  1037. $num = $n * $this->config['admin_comment_nb'];
  1038. $this->template['nav']['pages'][$n + 1]['page'] = $num;
  1039. if ($num == $startnum) {
  1040. $this->template['infos']['page_actuelle'] = $n + 1;
  1041. }
  1042. }
  1043. // On détermine les pages suivantes, précédentes, de début et de fin.
  1044. $this->template['nav']['suivante'][1] = $startnum + $this->config['admin_comment_nb'];
  1045. $this->template['nav']['precedente'][1] = $startnum - $this->config['admin_comment_nb'];
  1046. $this->template['nav']['premiere'][1] = 0;
  1047. $this->template['nav']['derniere'][1] = ($this->template['infos']['nb_pages'] * $this->config['admin_comment_nb']) - $this->config['admin_comment_nb'];
  1048. // On détermine la position de l'objet actuel.
  1049. if ($startnum == 0) {
  1050. $this->template['nav']['premiere'][0] = 1;
  1051. }
  1052. if ($this->template['nav']['precedente'][1] < 0) {
  1053. $this->template['nav']['precedente'][0] = 1;
  1054. }
  1055. if ($this->template['nav']['suivante'][1] >= ($this->template['infos']['nb_pages'] * $this->config['admin_comment_nb']) ||
  1056. $this->template['nav']['suivante'][1] >= $this->template['infos']['nb_objets']) {
  1057. $this->template['nav']['suivante'][0] = 1;
  1058. }
  1059. if ($startnum >= $this->template['nav']['derniere'][1]) {
  1060. $this->template['nav']['derniere'][0] = 1;
  1061. }
  1062. // Récupération des informations des commentaires.
  1063. $mysql_requete = 'SELECT ' . MYSQL_PREF . 'commentaires.*,
  1064. ' . MYSQL_PREF . 'categories.categorie_id,
  1065. ' . MYSQL_PREF . 'categories.categorie_nom,
  1066. ' . MYSQL_PREF . 'images.image_id,
  1067. ' . MYSQL_PREF . 'images.image_chemin,
  1068. ' . MYSQL_PREF . 'images.image_nom,
  1069. ' . MYSQL_PREF . 'images.image_hauteur,
  1070. ' . MYSQL_PREF . 'images.image_largeur,
  1071. ' . MYSQL_PREF . 'users.user_id,
  1072. ' . MYSQL_PREF . 'users.user_login,
  1073. ' . MYSQL_PREF . 'users.user_web,
  1074. ' . MYSQL_PREF . 'users.user_mail
  1075. FROM ' . MYSQL_PREF . 'categories,
  1076. ' . MYSQL_PREF . 'images,
  1077. ' . MYSQL_PREF . 'commentaires
  1078. LEFT JOIN ' . MYSQL_PREF . 'users
  1079. ON ' . MYSQL_PREF . 'commentaires.user_id = ' . MYSQL_PREF . 'users.user_id
  1080. WHERE ' . MYSQL_PREF . 'images.image_chemin LIKE "' . $obj_chemin . '%"
  1081. AND ' . MYSQL_PREF . 'commentaires.image_id = ' . MYSQL_PREF . 'images.image_id
  1082. AND ' . MYSQL_PREF . 'categories.categorie_id = ' . MYSQL_PREF . 'images.categorie_parent_id ' .
  1083. $recherche . $filtre . '
  1084. ORDER BY ' . $this->template['infos']['comment_sort'] . ' ' . $this->template['infos']['comment_sens'] . '
  1085. LIMIT ' . $startnum . ',' . $this->config['admin_comment_nb'] . '';
  1086. $comments = $this->mysql->select($mysql_requete);
  1087. if (!is_array($comments)) {
  1088. $this->template['display']['co_vide'] = 1;
  1089. $this->template['comments']['no_comments'] = 1;
  1090. if ($this->template['infos']['startnum']) {
  1091. header('Location:index.php?' . $this->template['infos']['section'] . $this->template['infos']['recherche']);
  1092. exit;
  1093. }
  1094. } else {
  1095. settype($this->template['comments'], 'array');
  1096. $this->template['comments'] = array_merge($this->template['comments'], $comments);
  1097. for ($i = 0; $i < count($comments); $i++) {
  1098. if (isset($this->config['admin_comment_ban']['auteurs'][$comments[$i]['commentaire_auteur']])) {
  1099. $this->template['comments'][$i]['ban_auteur'] = 1;
  1100. }
  1101. if (isset($this->config['admin_comment_ban']['IP'][$comments[$i]['commentaire_ip']])) {
  1102. $this->template['comments'][$i]['ban_ip'] = 1;
  1103. }
  1104. }
  1105. }
  1106. $this->template['config']['admin_comment_ban'] = $this->config['admin_comment_ban'];
  1107. // Affichage des message.
  1108. if (isset($_REQUEST['o_msg_display'])) {
  1109. if ($_REQUEST['o_msg_display'] == 'montrer' && !$this->config['admin_comment_msg_display']) {
  1110. $this->update_option('admin_comment_msg_display', 1);
  1111. $this->template['display']['comment_msg'] = 1;
  1112. } elseif ($_REQUEST['o_msg_display'] == 'cacher' && $this->config['admin_comment_msg_display']) {
  1113. $this->update_option('admin_comment_msg_display', 0);
  1114. }
  1115. $this->template['config'] = $this->config;
  1116. }
  1117. if ($this->config['admin_comment_msg_display']) {
  1118. $this->template['display']['comment_msg'] = 1;
  1119. }
  1120. }
  1121. /*
  1122. * Options commentaires.
  1123. */
  1124. function comments_options() {
  1125. $this->template['infos']['title'] = 'options des commentaires';
  1126. if (isset($_REQUEST['u'])) {
  1127. $maj = 0;
  1128. // Elements obligatoires pour poster un commentaire.
  1129. if (isset($_REQUEST['oc_fac_mail']) && empty($this->config['comment_courriel'])) {
  1130. $this->update_option('comment_courriel', 1);
  1131. $maj = 1;
  1132. } elseif (empty($_REQUEST['oc_fac_mail']) && $this->config['comment_courriel']) {
  1133. $this->update_option('comment_courriel', 0);
  1134. $maj = 1;
  1135. }
  1136. if (isset($_REQUEST['oc_fac_web']) && empty($this->config['comment_siteweb'])) {
  1137. $this->update_option('comment_siteweb', 1);
  1138. $maj = 1;
  1139. } elseif (empty($_REQUEST['oc_fac_web']) && $this->config['comment_siteweb']) {
  1140. $this->update_option('comment_siteweb', 0);
  1141. $maj = 1;
  1142. }
  1143. // Contrôles.
  1144. if (isset($_POST['oc_pro_flood']) && preg_match('`^(0|[1-9]\d{0,3})$`', $_POST['oc_pro_flood'])
  1145. && $_POST['oc_pro_flood'] != $this->config['comment_antiflood']) {
  1146. $this->update_option('comment_antiflood', $_POST['oc_pro_flood']);
  1147. $maj = 1;
  1148. }
  1149. if (isset($_REQUEST['oc_samemsg']) && empty($this->config['comment_samemsg'])) {
  1150. $this->update_option('comment_samemsg', 1);
  1151. $maj = 1;
  1152. } elseif (empty($_REQUEST['oc_samemsg']) && $this->config['comment_samemsg']) {
  1153. $this->update_option('comment_samemsg', 0);
  1154. $maj = 1;
  1155. }
  1156. if (isset($_REQUEST['oc_maxmsg']) && empty($this->config['comment_maxmsg'])) {
  1157. $this->update_option('comment_maxmsg', 1);
  1158. $maj = 1;
  1159. } elseif (empty($_REQUEST['oc_maxmsg']) && $this->config['comment_maxmsg']) {
  1160. $this->update_option('comment_maxmsg', 0);
  1161. $maj = 1;
  1162. }
  1163. if (isset($_POST['oc_maxmsg_nb']) && preg_match('`^(0|[1-9]\d{0,3})$`', $_POST['oc_maxmsg_nb'])
  1164. && $_POST['oc_maxmsg_nb'] != $this->config['comment_maxmsg_nb']) {
  1165. $this->update_option('comment_maxmsg_nb', $_POST['oc_maxmsg_nb']);
  1166. $maj = 1;
  1167. }
  1168. if (isset($_REQUEST['oc_nourl']) && empty($this->config['comment_nourl'])) {
  1169. $this->update_option('comment_nourl', 1);
  1170. $maj = 1;
  1171. } elseif (empty($_REQUEST['oc_nourl']) && $this->config['comment_nourl']) {
  1172. $this->update_option('comment_nourl', 0);
  1173. $maj = 1;
  1174. }
  1175. if (isset($_POST['oc_nourl_nb']) && preg_match('`^(0|[1-9]\d{0,3})$`', $_POST['oc_nourl_nb'])
  1176. && $_POST['oc_nourl_nb'] != $this->config['comment_maxurl']) {
  1177. $this->update_option('comment_maxurl', $_POST['oc_nourl_nb']);
  1178. $maj = 1;
  1179. }
  1180. // Modération des commentaires.
  1181. if (isset($_REQUEST['oc_mod']) && empty($this->config['admin_comment_moderer'])) {
  1182. $this->update_option('admin_comment_moderer', 1);
  1183. $maj = 1;
  1184. } elseif (empty($_REQUEST['oc_mod']) && $this->config['admin_comment_moderer']) {
  1185. $this->update_option('admin_comment_moderer', 0);
  1186. $maj = 1;
  1187. }
  1188. // Alerte par courriel.
  1189. if (!empty($_REQUEST['oc_objet']) && $_REQUEST['oc_objet'] != $this->config['admin_comment_objet']) {
  1190. $this->update_option('admin_comment_objet', $_REQUEST['oc_objet']);
  1191. $maj = 1;
  1192. }
  1193. if (isset($_REQUEST['oc_alert']) && empty($this->config['admin_comment_alert'])) {
  1194. $this->update_option('admin_comment_alert', 1);
  1195. $maj = 1;
  1196. } elseif (empty($_REQUEST['oc_alert']) && $this->config['admin_comment_alert']) {
  1197. $this->update_option('admin_comment_alert', 0);
  1198. $maj = 1;
  1199. }
  1200. // Page des commentaires.
  1201. if ($this->template['enabled']['co_page_comments']) {
  1202. if (isset($_REQUEST['oc_comments']) && empty($this->config['galerie_page_comments'])) {
  1203. $this->update_option('galerie_page_comments', 1);
  1204. $maj = 1;
  1205. } elseif (empty($_REQUEST['oc_comments']) && $this->config['galerie_page_comments']) {
  1206. $this->up

Large files files are truncated, but you can click here to view the full file