[26635] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: See photos by user |
---|
| 4 | Version: auto |
---|
| 5 | Description: See photos by user |
---|
[26636] | 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=723 |
---|
[26635] | 7 | Author: ddtddt |
---|
| 8 | Author URI: |
---|
| 9 | */ |
---|
| 10 | |
---|
| 11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 12 | |
---|
| 13 | define('SPBA_DIR' , basename(dirname(__FILE__))); |
---|
| 14 | define('SPBA_PATH' , PHPWG_PLUGINS_PATH . SPBA_DIR . '/'); |
---|
[27391] | 15 | load_language('plugin.lang', SPBA_PATH); |
---|
[26635] | 16 | |
---|
[27428] | 17 | global $conf; |
---|
| 18 | $showSPBU = $conf['see_photos_by_user_show']; |
---|
| 19 | |
---|
[27429] | 20 | if (in_array($showSPBU, array(1,3))) |
---|
[27428] | 21 | { |
---|
[27391] | 22 | add_event_handler('blockmanager_apply' , 'add_link_SPBA'); |
---|
[27428] | 23 | } |
---|
[26635] | 24 | function add_link_SPBA($menu_ref_arr) |
---|
[26643] | 25 | { |
---|
[26635] | 26 | global $conf, $user; |
---|
| 27 | $menu = & $menu_ref_arr[0]; |
---|
| 28 | if (($block = $menu->get_block('mbSpecials')) != null) |
---|
[26643] | 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 |
---|
[27391] | 34 | ('user-' => |
---|
[26643] | 35 | array |
---|
| 36 | ( |
---|
[27391] | 37 | 'URL' => make_index_url(array('section' => 'user-')), |
---|
[26643] | 38 | 'TITLE' => l10n('See photos by user'), |
---|
| 39 | 'NAME' => l10n('See photos by user') |
---|
| 40 | ) |
---|
| 41 | ) |
---|
| 42 | ); |
---|
| 43 | } |
---|
| 44 | } |
---|
[26635] | 45 | |
---|
[27391] | 46 | add_event_handler('loc_end_section_init', 'section_init_SPBA'); |
---|
[26635] | 47 | function section_init_SPBA() |
---|
| 48 | { |
---|
[27442] | 49 | global $tokens, $conf; |
---|
[27392] | 50 | $testa = explode('user-', $_SERVER['REQUEST_URI']); |
---|
| 51 | if (!empty ($testa[1])) |
---|
| 52 | { |
---|
| 53 | $testd= explode('/', $testa[1]); |
---|
[27442] | 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']; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | if (in_array($testd[0], $userok)) |
---|
| 82 | { |
---|
[27392] | 83 | $me = 'user-'.$testd[0]; |
---|
| 84 | } |
---|
[27391] | 85 | else |
---|
[27442] | 86 | { |
---|
| 87 | $redirect_url = get_root_url().'index.php?/categories'; |
---|
| 88 | redirect($redirect_url); |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | else |
---|
[27391] | 92 | {$me = 'user-';} |
---|
| 93 | |
---|
[27429] | 94 | if (in_array($me, $tokens)) |
---|
[27391] | 95 | include(SPBA_PATH . 'pagespba.php'); |
---|
[26635] | 96 | } |
---|
| 97 | |
---|
[27429] | 98 | if (in_array($showSPBU, array(2,3,4))) |
---|
[27428] | 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'))); |
---|
| 109 | } |
---|
| 110 | |
---|
| 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';} |
---|
| 155 | } |
---|
| 156 | |
---|
[27391] | 157 | add_event_handler('get_admin_plugin_menu_links', 'SPBA_admin_menu'); |
---|
| 158 | function SPBA_admin_menu($menu) |
---|
| 159 | { |
---|
| 160 | array_push( |
---|
| 161 | $menu, |
---|
| 162 | array( |
---|
| 163 | 'NAME' => l10n('See photos by user'), |
---|
| 164 | 'URL' => get_admin_plugin_menu_link(SPBA_PATH . 'admin.php') |
---|
| 165 | //'URL' => get_root_url().'admin.php?page=plugin-See_photos_by_user' |
---|
| 166 | ) |
---|
| 167 | ); |
---|
| 168 | |
---|
| 169 | return $menu; |
---|
| 170 | } |
---|
[26635] | 171 | |
---|
| 172 | ?> |
---|