source: extensions/Photo_add_by/initpicture.php @ 32623

Last change on this file since 32623 was 32392, checked in by ddtddt, 4 years ago

[Photo_add_by] piwigo 11

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