Ignore:
Timestamp:
Mar 19, 2016, 9:01:52 PM (9 years ago)
Author:
ddtddt
Message:

[extensions] - Photo_add_by - 2.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Photo_add_by/initpicture.php

    r30404 r31465  
    11<?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// +-----------------------------------------------------------------------+
    221
    322//Ajout du prefiltre
     
    3251add_event_handler('loc_begin_picture', 'pab');
    3352
    34 function pab()
    35 {
     53function pab(){
    3654global $conf, $page, $template;
    3755load_language('plugin.lang', PAB_PATH);
    3856load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) );
    3957
    40   if ( !empty($page['image_id']) )   
    41   {
    42  
    43   $query = '
    44 select added_by
    45   FROM ' . IMAGES_TABLE . '
    46   WHERE id = \''.$page['image_id'].'\'
    47   ;';
    48 $result = pwg_query($query);
    49 $row = pwg_db_fetch_assoc($result);
    50 $userab=$row['added_by'];
    51 
    52   $query = '
    53 select '.$conf['user_fields']['username'].' AS username
    54   FROM ' . USERS_TABLE . '
    55   WHERE '.$conf['user_fields']['id'].' = \''.$userab.'\'
    56   ;';
    57 $result = pwg_query($query);
    58 $row = pwg_db_fetch_assoc($result);
    59 $pab=$row['username'];
    60 
    61 $PASPBY = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'see_photos_by_user';"));
    62 $showpab = $conf['Photo_add_by_show'];
    63 if($showpab == 1 and $PASPBY['state'] == 'active')
    64 {
    65 $query2 = '
    66 SELECT UT.id, UT.username, COUNT(DISTINCT(IT.id)) AS PBU
    67  FROM ' . USERS_TABLE . ' as UT
    68  INNER JOIN '.IMAGES_TABLE.' AS IT ON IT.added_by = UT.id
    69  INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON IT.id = ic.image_id
    70   '.get_sql_condition_FandF
    71   (
    72     array
    73       (
    74         'forbidden_categories' => 'category_id',
    75         'visible_categories' => 'category_id',
    76         'visible_images' => 'id'
    77       ),
    78     'WHERE'
    79   ).'
    80  GROUP BY IT.added_by
    81  HAVING PBU >'.$conf['see_photos_by_user_nbphotos'].'
    82  ORDER BY '.$conf['see_photos_by_user_order'].'
    83  LIMIT '.$conf['see_photos_by_user_limit'].';';
    84 
    85 $result2 = pwg_query($query2);
    86 
    87 $userok = array();
    88 while ($row2 = pwg_db_fetch_assoc($result2))
    89  {
    90   $userok[] = $row2['username'];
    91 }
    92 if(in_array($pab, $userok) and $showpab == 1 and $PASPBY['state'] == 'active')
    93 {
    94 $urlpab = get_root_url().'index.php?/user-'.$userab.'-'.$pab;
    95 $pab2 ='<a href="'.$urlpab.'">'.$pab.'</a>';
    96 }
    97 else
    98 {
    99 $pab2=$pab;
    100 }
    101 }
    102 else
    103 {
    104 $pab2=$pab;
    105 }
    106 $template->assign(array('PAB' => $pab2,));
    107 
     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,));
    108105  }
    109106}
Note: See TracChangeset for help on using the changeset viewer.