Ignore:
Timestamp:
Nov 9, 2014, 11:00:26 PM (6 years ago)
Author:
ddtddt
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/see_photos_by_user/main.inc.php

    r27457 r30403  
    11<?php
     2
    23/*
    3 Plugin Name: See photos by user
    4 Version: auto
    5 Description: See photos by user
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=723
    7 Author: ddtddt
    8 Author URI:
    9 */
     4  Plugin Name: See photos by user
     5  Version: auto
     6  Description: See photos by user
     7  Plugin URI: http://piwigo.org/ext/extension_view.php?eid=723
     8  Author: ddtddt
     9  Author URI:
     10 */
    1011
    11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     12if (!defined('PHPWG_ROOT_PATH'))
     13    die('Hacking attempt!');
    1214
    13 define('SPBA_DIR' , basename(dirname(__FILE__)));
    14 define('SPBA_PATH' , PHPWG_PLUGINS_PATH . SPBA_DIR . '/');
     15define('SPBA_DIR', basename(dirname(__FILE__)));
     16define('SPBA_PATH', PHPWG_PLUGINS_PATH . SPBA_DIR . '/');
    1517load_language('plugin.lang', SPBA_PATH);
     18
     19include_once(SPBA_PATH . 'include/function.see.inc.php');
    1620
    1721global $conf;
    1822$showSPBU = $conf['see_photos_by_user_show'];
    1923
    20 if (in_array($showSPBU, array(1,3)))
    21 {
    22 add_event_handler('blockmanager_apply' , 'add_link_SPBA');
     24/*init plugin - filter http*/
     25add_event_handler('loc_end_section_init', 'section_init_SPBA');
     26
     27function section_init_SPBA() {
     28    /*init plugin lang*/
     29    load_language('plugin.lang', SPBA_PATH);
     30    load_language('lang', PHPWG_ROOT_PATH . 'local/', array('no_fallback' => true, 'local' => true));
     31   
     32    global $tokens, $conf, $template;
     33  if(strpbrk('user-', $_SERVER['REQUEST_URI'])!=false){
     34    $testa = explode('user-', $_SERVER['REQUEST_URI']);
     35    if(!empty($testa[1])){
     36        $testd = explode('-', $testa[1]);
     37            if(is_numeric($testd[0])){
     38                $username= see_username($testd[0]);
     39                $result=see_userlist_nb_photo();
     40                $userok = array();
     41                while ($row = pwg_db_fetch_assoc($result)) {
     42                    $userok[] = $row['id'];
     43                }
     44                if (in_array($testd[0], $userok)) {
     45                    $me = 'user-' . $testd[0].'-'.$username;
     46                    $page['section_title'] = '<a href="' . get_absolute_root_url() . '">' . l10n('Home') . '</a>' . $conf['level_separator'] . '<a href="' . get_absolute_root_url() . 'index.php?/user-">' . l10n('Users').'</a>'. $conf['level_separator'] . '<a href="' . get_absolute_root_url() . 'index.php?/' . $me . '">'.$row['username'] . '</a>';
     47                } else {
     48                    $me = 'user-';
     49                    $page['section_title'] = '<a href="' . get_absolute_root_url() . '">' . l10n('Home') . '</a>' . $conf['level_separator'] . '<a href="' . get_absolute_root_url() . 'index.php?/user-">' . l10n('Users').'</a>';
     50                }
     51            }else{
     52                $me = 'user-';
     53            }
     54    }else{
     55        $me = 'user-';
     56    }
     57    if(isset($me)){
     58        if (in_array($me, $tokens))
     59            include(SPBA_PATH . 'pagespba.php');
     60    }
     61  }
     62 
     63  //$template->assign('SPBA2', 'toto');
     64  $template->set_filename('SPBA', realpath(SPBA_PATH . 'pagespba.tpl'));
     65  $template->assign_var_from_handle('CONTENT', 'SPBA'); //2.6
     66 
    2367}
    24 function add_link_SPBA($menu_ref_arr)
    25  {
    26   global $conf, $user;
    27   $menu = & $menu_ref_arr[0];
    28   if (($block = $menu->get_block('mbSpecials')) != null)
    29    {
    30    load_language('plugin.lang', SPBA_PATH);
    31    $position = (isset($conf['SPBA_position']) and is_numeric($conf['SPBA_position'])) ? $conf['SPBA_position'] : count($block->data)+1;
    32    array_splice
    33          ($block->data, $position-1, 0, array
    34           ('user-' =>
    35       array
    36                          (
    37                          'URL' => make_index_url(array('section' => 'user-')),
    38                          'TITLE' => l10n('See photos by user'),
    39                          'NAME' => l10n('See photos by user')
    40        )
    41     )
    42    );
    43    }
    44  }
    45 
    46 add_event_handler('loc_end_section_init', 'section_init_SPBA');
    47 function section_init_SPBA()
    48 {
    49  global $tokens, $conf;
    50 $testa = explode('user-', $_SERVER['REQUEST_URI']);
    51 if (!empty ($testa[1]))
    52 {
    53 $testd= explode('/', $testa[1]);
    54 $query = '
    55 SELECT UT.id, UT.username, COUNT(DISTINCT(IT.id)) AS PBU, IT.id
    56  FROM ' . USERS_TABLE . ' as UT
    57  INNER JOIN '.IMAGES_TABLE.' AS IT ON IT.added_by = UT.id
    58  INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON IT.id = ic.image_id
    59   '.get_sql_condition_FandF
    60   (
    61     array
    62       (
    63         'forbidden_categories' => 'category_id',
    64         'visible_categories' => 'category_id',
    65         'visible_images' => 'id'
    66       ),
    67     'WHERE'
    68   ).'
    69  GROUP BY IT.added_by
    70  HAVING PBU >'.$conf['see_photos_by_user_nbphotos'].'
    71  ORDER BY '.$conf['see_photos_by_user_order'].'
    72  LIMIT '.$conf['see_photos_by_user_limit'].';';
    73 
    74 $result = pwg_query($query);
    75 $userok = array();
    76 while ($row = pwg_db_fetch_assoc($result))
    77  {
    78   $userok[] = $row['username'];
     68/*Schow link in menu*/
     69if (in_array($showSPBU, array(1, 3))) {
     70    add_event_handler('blockmanager_apply', 'add_link_SPBA');
    7971}
    8072
    81 if (in_array($testd[0], $userok))
    82 {
    83 $me = 'user-'.$testd[0];
    84 }
    85 else
    86 {
    87  $redirect_url = get_root_url().'index.php?/categories';
    88  redirect($redirect_url);
    89 }
    90 }
    91 else
    92 {$me = 'user-';}
    93 
    94 if (in_array($me, $tokens))
    95  include(SPBA_PATH . 'pagespba.php');
     73function add_link_SPBA($menu_ref_arr) {
     74    global $conf, $user;
     75    $menu = & $menu_ref_arr[0];
     76    if (($block = $menu->get_block('mbSpecials')) != null) {
     77        load_language('plugin.lang', SPBA_PATH);
     78        $position = (isset($conf['SPBA_position']) and is_numeric($conf['SPBA_position'])) ? $conf['SPBA_position'] : count($block->data) + 1;
     79        array_splice
     80                ($block->data, $position - 1, 0, array
     81            ('user-' =>
     82            array
     83                (
     84                'URL' => make_index_url(array('section' => 'user-')),
     85                'TITLE' => l10n('See photos by user'),
     86                'NAME' => l10n('See photos by user')
     87            )
     88                )
     89        );
     90    }
    9691}
    9792
    98 if (in_array($showSPBU, array(2,3,4)))
    99 {
    100 add_event_handler('blockmanager_register_blocks', 'register_users_menubar_blocks');
    101 add_event_handler('blockmanager_apply', 'users_apply');
    102 }
    103 function register_users_menubar_blocks( $menu_ref_arr )
    104 {
    105   $menu = & $menu_ref_arr[0];
    106   if ($menu->get_id() != 'menubar')
    107     return;
    108   $menu->register_block( new RegisteredBlock( 'mbUsers','Users',('See photos by user')));
     93
     94/*schow users menu*/
     95if (in_array($showSPBU, array(2, 3, 4))) {
     96    add_event_handler('blockmanager_register_blocks', 'register_users_menubar_blocks');
     97    add_event_handler('blockmanager_apply', 'users_apply');
    10998}
    11099
    111 function users_apply($menu_ref_arr)
    112 {
    113 global $template, $conf, $user;
    114 $menu = & $menu_ref_arr[0];
    115 load_language('plugin.lang', SPBA_PATH);
    116 load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true));
    117 
    118 $userslistemenu1 = pwg_query('
    119 SELECT UT.id, UT.username, COUNT(DISTINCT(IT.id)) AS PBU, IT.id
    120  FROM ' . USERS_TABLE . ' as UT
    121  INNER JOIN '.IMAGES_TABLE.' AS IT ON IT.added_by = UT.id
    122  INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON IT.id = ic.image_id
    123   '.get_sql_condition_FandF
    124   (
    125     array
    126       (
    127         'forbidden_categories' => 'category_id',
    128         'visible_categories' => 'category_id',
    129         'visible_images' => 'id'
    130       ),
    131     'WHERE'
    132   ).'
    133  GROUP BY IT.added_by
    134  HAVING PBU >'.$conf['see_photos_by_user_nbphotos'].'
    135  ORDER BY '.$conf['see_photos_by_user_order'].'
    136  LIMIT '.$conf['see_photos_by_user_limit'].';');
    137 
    138 if (pwg_db_num_rows($userslistemenu1)) {       
    139  while ($userslistemenu = pwg_db_fetch_assoc($userslistemenu1))
    140         {
    141     $items = array(
    142       'USERSSPBYL' => $userslistemenu['username'],
    143           'USERSSPBYLC' => $userslistemenu['PBU'],
    144                 );
    145                
    146         $template->append('userslistemenu1', $items);
    147         }
    148 }
    149 $linkusersliste = get_root_url().'index.php?/user-';
    150 $template->assign('USERSSPBY', $linkusersliste);
    151    
    152  if (($block = $menu->get_block( 'mbUsers' )) != null) {
    153  $template->set_template_dir(SPBA_PATH);
    154  $block->template = 'menubar_users.tpl';}
     100function register_users_menubar_blocks($menu_ref_arr) {
     101    $menu = & $menu_ref_arr[0];
     102    if ($menu->get_id() != 'menubar')
     103        return;
     104    $menu->register_block(new RegisteredBlock('mbUsers', 'Users', ('See photos by user')));
    155105}
    156106
     107function users_apply($menu_ref_arr) {
     108    global $template, $conf, $user;
     109    $menu = & $menu_ref_arr[0];
     110
     111    $userslistemenu1 = see_userlist_nb_photo();
     112
     113    if (pwg_db_num_rows($userslistemenu1)) {
     114        while ($userslistemenu = pwg_db_fetch_assoc($userslistemenu1)) {
     115            $items = array(
     116                'USERSSPBYLID' => $userslistemenu['id'],
     117                'USERSSPBYL' => $userslistemenu['username'],
     118                'USERSSPBYLC' => $userslistemenu['PBU'],
     119            );
     120
     121            $template->append('userslistemenu1', $items);
     122        }
     123    }
     124    $linkusersliste = get_root_url() . 'index.php?/user-';
     125    $template->assign('USERSSPBY', $linkusersliste);
     126
     127    if (($block = $menu->get_block('mbUsers')) != null) {
     128        $template->set_template_dir(SPBA_PATH);
     129        $block->template = 'menubar_users.tpl';
     130    }
     131}
     132
     133/*Add admin menu*/
    157134add_event_handler('get_admin_plugin_menu_links', 'SPBA_admin_menu');
    158 function SPBA_admin_menu($menu)
    159 {
    160 load_language('plugin.lang', SPBA_PATH);
    161   array_push(
    162     $menu,
    163     array(
    164       'NAME' => l10n('Photos by user'),
    165       'URL' => get_admin_plugin_menu_link(SPBA_PATH . 'admin.php')
    166       )
     135
     136function SPBA_admin_menu($menu) {
     137    load_language('plugin.lang', SPBA_PATH);
     138    array_push(
     139            $menu, array(
     140        'NAME' => l10n('Photos by user'),
     141        'URL' => get_admin_plugin_menu_link(SPBA_PATH . 'admin.php')
     142            )
    167143    );
    168  
    169   return $menu;
     144
     145    return $menu;
    170146}
    171147
Note: See TracChangeset for help on using the changeset viewer.