source: extensions/see_photos_by_user/main.inc.php @ 27533

Last change on this file since 27533 was 27457, checked in by ddtddt, 11 years ago

[extensions] - see_photos_by_user - menu name

File size: 4.4 KB
Line 
1<?php
2/*
3Plugin Name: See photos by user
4Version: auto
5Description: See photos by user
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=723
7Author: ddtddt
8Author URI:
9*/
10
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13define('SPBA_DIR' , basename(dirname(__FILE__)));
14define('SPBA_PATH' , PHPWG_PLUGINS_PATH . SPBA_DIR . '/');
15load_language('plugin.lang', SPBA_PATH);
16
17global $conf;
18$showSPBU = $conf['see_photos_by_user_show'];
19
20if (in_array($showSPBU, array(1,3)))
21{
22add_event_handler('blockmanager_apply' , 'add_link_SPBA');
23}
24function 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
46add_event_handler('loc_end_section_init', 'section_init_SPBA');
47function section_init_SPBA()
48{
49 global $tokens, $conf;
50$testa = explode('user-', $_SERVER['REQUEST_URI']); 
51if (!empty ($testa[1]))
52{
53$testd= explode('/', $testa[1]);
54$query = '
55SELECT 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();
76while ($row = pwg_db_fetch_assoc($result))
77 {
78  $userok[] = $row['username'];
79}
80
81if (in_array($testd[0], $userok))
82{
83$me = 'user-'.$testd[0];
84}
85else
86{
87 $redirect_url = get_root_url().'index.php?/categories';
88 redirect($redirect_url);
89}
90}
91else
92{$me = 'user-';}
93
94if (in_array($me, $tokens))
95 include(SPBA_PATH . 'pagespba.php');
96}
97
98if (in_array($showSPBU, array(2,3,4)))
99{
100add_event_handler('blockmanager_register_blocks', 'register_users_menubar_blocks');
101add_event_handler('blockmanager_apply', 'users_apply');
102}
103function 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')));
109}
110
111function users_apply($menu_ref_arr)
112{
113global $template, $conf, $user;
114$menu = & $menu_ref_arr[0];
115load_language('plugin.lang', SPBA_PATH);
116load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true));
117
118$userslistemenu1 = pwg_query('
119SELECT 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
138if (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';}
155}
156
157add_event_handler('get_admin_plugin_menu_links', 'SPBA_admin_menu');
158function SPBA_admin_menu($menu)
159{
160load_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      )
167    );
168 
169  return $menu;
170}
171
172?>
Note: See TracBrowser for help on using the repository browser.