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

Last change on this file since 30403 was 30403, checked in by ddtddt, 9 years ago
File size: 4.9 KB
Line 
1<?php
2
3/*
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 */
11
12if (!defined('PHPWG_ROOT_PATH'))
13    die('Hacking attempt!');
14
15define('SPBA_DIR', basename(dirname(__FILE__)));
16define('SPBA_PATH', PHPWG_PLUGINS_PATH . SPBA_DIR . '/');
17load_language('plugin.lang', SPBA_PATH);
18
19include_once(SPBA_PATH . 'include/function.see.inc.php');
20
21global $conf;
22$showSPBU = $conf['see_photos_by_user_show'];
23
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 
67}
68/*Schow link in menu*/
69if (in_array($showSPBU, array(1, 3))) {
70    add_event_handler('blockmanager_apply', 'add_link_SPBA');
71}
72
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    }
91}
92
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');
98}
99
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')));
105}
106
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*/
134add_event_handler('get_admin_plugin_menu_links', 'SPBA_admin_menu');
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            )
143    );
144
145    return $menu;
146}
147
148?>
Note: See TracBrowser for help on using the repository browser.