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

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

[extensions] - see_photos_by_user - 2.8

File size: 6.2 KB
Line 
1<?php
2/*
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
8Author URI: http://temmii.com/piwigo/
9*/
10// +-----------------------------------------------------------------------+
11// | See photos by user plugin for piwigo                                  |
12// +-----------------------------------------------------------------------+
13// | Copyright(C) 2014 - 2016 ddtddt             http://temmii.com/piwigo/ |
14// +-----------------------------------------------------------------------+
15// | This program is free software; you can redistribute it and/or modify  |
16// | it under the terms of the GNU General Public License as published by  |
17// | the Free Software Foundation                                          |
18// |                                                                       |
19// | This program is distributed in the hope that it will be useful, but   |
20// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
21// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
22// | General Public License for more details.                              |
23// |                                                                       |
24// | You should have received a copy of the GNU General Public License     |
25// | along with this program; if not, write to the Free Software           |
26// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
27// | USA.                                                                  |
28// +-----------------------------------------------------------------------+
29
30if (!defined('PHPWG_ROOT_PATH'))
31    die('Hacking attempt!');
32
33define('SPBA_DIR', basename(dirname(__FILE__)));
34define('SPBA_PATH', PHPWG_PLUGINS_PATH . SPBA_DIR . '/');
35define('SPBA_ADMIN',get_root_url().'admin.php?page=plugin-'.SPBA_DIR);
36
37include_once(SPBA_PATH . 'include/function.see.inc.php');
38
39add_event_handler('loading_lang', 'see_photos_by_user_loading_lang');     
40function see_photos_by_user_loading_lang(){
41  load_language('plugin.lang', SPBA_PATH);
42  load_language('lang', PHPWG_ROOT_PATH . 'local/', array('no_fallback' => true, 'local' => true));
43}
44
45
46global $conf;
47
48/*init plugin - filter http*/
49add_event_handler('loc_end_section_init', 'section_init_SPBA');
50function section_init_SPBA(){
51  global $tokens, $conf, $template;
52  if(strpbrk('user-', $_SERVER['REQUEST_URI'])!=false){
53    $testa = explode('user-', $_SERVER['REQUEST_URI']);
54    if(!empty($testa[1])){
55        $testd = explode('-', $testa[1]);
56            if(is_numeric($testd[0])){
57                $username= see_username($testd[0]);
58                $result=see_userlist_nb_photo();
59                $userok = array();
60                while ($row = pwg_db_fetch_assoc($result)) {
61                    $userok[] = $row['id'];
62                }
63                if (in_array($testd[0], $userok)) {
64                    $me = 'user-' . $testd[0].'-'.$username;
65                    $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 . '">'.$username . '</a>';
66                } else {
67                    $me = 'user-';
68                    $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>';
69                }
70            }else{
71                $me = 'user-';
72            }
73    }else{
74        $me = 'user-';
75    }
76    if(isset($me)){
77        if (in_array($me, $tokens))
78            include(SPBA_PATH . 'pagespba.php');
79    }
80  }
81  $template->set_filename('SPBA', realpath(SPBA_PATH . 'pagespba.tpl'));
82  $template->assign_var_from_handle('CONTENT', 'SPBA'); //2.6
83}
84
85/*Schow link in menu*/
86if ($conf['see_photos_by_user_show']==1) {
87    add_event_handler('blockmanager_apply', 'add_link_SPBA');
88}
89
90function add_link_SPBA($menu_ref_arr){
91    global $conf, $user;
92    $menu = & $menu_ref_arr[0];
93    if (($block = $menu->get_block('mbSpecials')) != null) {
94        $position = (isset($conf['SPBA_position']) and is_numeric($conf['SPBA_position'])) ? $conf['SPBA_position'] : count($block->data) + 1;
95        array_splice
96                ($block->data, $position - 1, 0, array
97            ('user-' =>
98            array
99                (
100                'URL' => make_index_url(array('section' => 'user-')),
101                'TITLE' => l10n('See photos by user'),
102                'NAME' => l10n('See photos by user')
103            )
104                )
105        );
106    }
107}
108
109/*schow users menu*/
110if ($conf['see_photos_by_user_show']==2) {
111    add_event_handler('blockmanager_register_blocks', 'register_users_menubar_blocks');
112    add_event_handler('blockmanager_apply', 'users_apply');
113}
114
115function register_users_menubar_blocks($menu_ref_arr) {
116    $menu = & $menu_ref_arr[0];
117    if ($menu->get_id() != 'menubar')
118        return;
119    $menu->register_block(new RegisteredBlock('mbUsers', 'Users', ('See photos by user')));
120}
121
122function users_apply($menu_ref_arr) {
123    global $template, $conf, $user;
124    $menu = & $menu_ref_arr[0];
125
126    $userslistemenu1 = see_userlist_nb_photo();
127
128    if (pwg_db_num_rows($userslistemenu1)) {
129        while ($userslistemenu = pwg_db_fetch_assoc($userslistemenu1)) {
130            $items = array(
131                'USERSSPBYLID' => $userslistemenu['id'],
132                'USERSSPBYL' => $userslistemenu['username'],
133                'USERSSPBYLC' => $userslistemenu['PBU'],
134            );
135
136            $template->append('userslistemenu1', $items);
137        }
138    }
139    $linkusersliste = get_root_url() . 'index.php?/user-';
140    $template->assign('USERSSPBY', $linkusersliste);
141
142    if (($block = $menu->get_block('mbUsers')) != null) {
143        $template->set_template_dir(SPBA_PATH);
144        $block->template = 'menubar_users.tpl';
145    }
146}
147
148/*Add admin menu*/
149add_event_handler('get_admin_plugin_menu_links', 'SPBA_admin_menu');
150
151function SPBA_admin_menu($menu) {
152  $menu[] = array(
153    'NAME' => l10n('Photos by user'),
154    'URL' => SPBA_ADMIN,
155    );
156  return $menu;
157}
158
159?>
Note: See TracBrowser for help on using the repository browser.