source: extensions/Photo_add_by/initpicture.php

Last change on this file was 32916, checked in by ddtddt, 15 months ago

[Photo_add_by] check php8

File size: 4.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Photo added by plugin for Piwigo  by TEMMII                           |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2012-2023 ddtddt               http://temmii.com/piwigo/ |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22//Ajout du prefiltre
23add_event_handler('loc_begin_picture', 'pabI', 55 );
24function pabI(){
25        global $template;
26        $template->set_prefilter('picture', 'pabIT');
27}
28
29function pabIT($content){
30  global $conf, $pwg_loaded_plugins;
31        $search = '#<div id="'.$conf['Photo_add_by'].'" class="imageInfo">#';
32  if (isset($pwg_loaded_plugins['manage_properties_photos'])){
33        $replacement = '<div id="'.$conf['Photo_add_by'].'" class="imageInfo">';
34  }else{
35        $replacement = '
36  {if $PAB}
37  <div id="pab1" class="imageInfo">
38    <dt>{\'Photo added by\'|@translate}</dt>
39    <dd>{$PAB}</dd>
40  </div>
41{/if}
42<div id="'.$conf['Photo_add_by'].'" class="imageInfo">';
43  }
44  return preg_replace($search, $replacement, $content);
45 }
46
47add_event_handler('loc_begin_picture', 'pab');
48
49function pab(){
50global $conf, $page, $template,$pwg_loaded_plugins;
51load_language('plugin.lang', PAB_PATH);
52load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) );
53
54  if ( !empty($page['image_id']) ){
55    $query = 'select added_by FROM ' . IMAGES_TABLE . ' WHERE id = \''.$page['image_id'].'\';';
56        $result = pwg_query($query);
57        $row = pwg_db_fetch_assoc($result);
58        $userab=$row['added_by'];
59       
60        $query = 'select '.$conf['user_fields']['username'].' AS username FROM ' . USERS_TABLE . ' WHERE '.$conf['user_fields']['id'].' = \''.$userab.'\';';
61        $result = pwg_query($query);
62        $row = pwg_db_fetch_assoc($result);
63        $pab=$row['username'];
64       
65        $showpab = $conf['Photo_add_by_show'];
66          if($showpab == 1 and (isset($pwg_loaded_plugins['see_photos_by_user']))){
67                $query2 = 'SELECT UT.id, UT.username, COUNT(DISTINCT(IT.id)) AS PBU
68                  FROM ' . USERS_TABLE . ' as UT
69                  INNER JOIN '.IMAGES_TABLE.' AS IT ON IT.added_by = UT.id
70                  INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON IT.id = ic.image_id
71                    '.get_sql_condition_FandF
72                        (
73                        array
74           (
75                   'forbidden_categories' => 'category_id',
76                   'visible_categories' => 'category_id',
77                   'visible_images' => 'id'
78                   ),
79                   'WHERE'
80                   ).'
81                   GROUP BY IT.added_by
82           HAVING PBU >'.$conf['see_photos_by_user_nbphotos'].'
83                   ORDER BY '.$conf['see_photos_by_user_order'].'
84                   LIMIT '.$conf['see_photos_by_user_limit'].';';
85                $result2 = pwg_query($query2);
86                $userok = array();
87                while ($row2 = pwg_db_fetch_assoc($result2)){
88                  $userok[] = $row2['username'];
89                }
90                if(in_array($pab, $userok) and $showpab == 1 and (isset($pwg_loaded_plugins['see_photos_by_user']))){
91                  $urlpab = get_root_url().'index.php?/user-'.$userab.'-'.$pab;
92                  $pab2 ='<a href="'.$urlpab.'">'.$pab.'</a>';
93                }else{
94                  $pab2=$pab;
95                }
96          }else{
97            $pab2=$pab;
98          }
99        $template->assign(array('PAB' => $pab2,));
100  }
101}
102
103?>
Note: See TracBrowser for help on using the repository browser.