source: extensions/Photo_add_by/initpicture.php @ 31991

Last change on this file since 31991 was 31465, checked in by ddtddt, 8 years ago

[extensions] - Photo_add_by - 2.8

File size: 3.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Photo added by plugin for Piwigo                                      |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2012-2016 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 );
24
25function pabI()
26 {
27        global $template;
28        $template->set_prefilter('picture', 'pabIT');
29 }
30
31
32function pabIT($content, &$smarty)
33 {
34 
35 global $conf;
36 
37  $search = '#<div id="'.$conf['Photo_add_by'].'" class="imageInfo">#';
38
39  $replacement = '
40  {if $PAB}
41  <div id="pab1" class="imageInfo">
42    <dt>{\'Photo added by\'|@translate}</dt>
43    <dd>{$PAB}</dd>
44  </div>
45{/if}
46<div id="'.$conf['Photo_add_by'].'" class="imageInfo">';
47
48  return preg_replace($search, $replacement, $content);
49 }
50
51add_event_handler('loc_begin_picture', 'pab');
52
53function pab(){
54global $conf, $page, $template;
55load_language('plugin.lang', PAB_PATH);
56load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) );
57
58  if ( !empty($page['image_id']) ){
59    $query = 'select added_by FROM ' . IMAGES_TABLE . ' WHERE id = \''.$page['image_id'].'\';';
60        $result = pwg_query($query);
61        $row = pwg_db_fetch_assoc($result);
62        $userab=$row['added_by'];
63       
64        $query = 'select '.$conf['user_fields']['username'].' AS username FROM ' . USERS_TABLE . ' WHERE '.$conf['user_fields']['id'].' = \''.$userab.'\';';
65        $result = pwg_query($query);
66        $row = pwg_db_fetch_assoc($result);
67        $pab=$row['username'];
68       
69        $PASPBY = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'see_photos_by_user';"));
70        $showpab = $conf['Photo_add_by_show'];
71          if($showpab == 1 and $PASPBY['state'] == 'active'){
72                $query2 = 'SELECT UT.id, UT.username, COUNT(DISTINCT(IT.id)) AS PBU
73                  FROM ' . USERS_TABLE . ' as UT
74                  INNER JOIN '.IMAGES_TABLE.' AS IT ON IT.added_by = UT.id
75                  INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON IT.id = ic.image_id
76                    '.get_sql_condition_FandF
77                        (
78                        array
79           (
80                   'forbidden_categories' => 'category_id',
81                   'visible_categories' => 'category_id',
82                   'visible_images' => 'id'
83                   ),
84                   'WHERE'
85                   ).'
86                   GROUP BY IT.added_by
87           HAVING PBU >'.$conf['see_photos_by_user_nbphotos'].'
88                   ORDER BY '.$conf['see_photos_by_user_order'].'
89                   LIMIT '.$conf['see_photos_by_user_limit'].';';
90                $result2 = pwg_query($query2);
91                $userok = array();
92                while ($row2 = pwg_db_fetch_assoc($result2)){
93                  $userok[] = $row2['username'];
94                }
95                if(in_array($pab, $userok) and $showpab == 1 and $PASPBY['state'] == 'active'){
96                  $urlpab = get_root_url().'index.php?/user-'.$userab.'-'.$pab;
97                  $pab2 ='<a href="'.$urlpab.'">'.$pab.'</a>';
98                }else{
99                  $pab2=$pab;
100                }
101          }else{
102            $pab2=$pab;
103          }
104        $template->assign(array('PAB' => $pab2,));
105  }
106}
107
108?>
Note: See TracBrowser for help on using the repository browser.