Index: extensions/see_photos_by_user/main.inc.php
===================================================================
--- extensions/see_photos_by_user/main.inc.php	(revision 27457)
+++ extensions/see_photos_by_user/main.inc.php	(revision 30403)
@@ -1,171 +1,147 @@
 <?php
+
 /*
-Plugin Name: See photos by user
-Version: auto
-Description: See photos by user
-Plugin URI: http://piwigo.org/ext/extension_view.php?eid=723
-Author: ddtddt
-Author URI: 
-*/
+  Plugin Name: See photos by user
+  Version: auto
+  Description: See photos by user
+  Plugin URI: http://piwigo.org/ext/extension_view.php?eid=723
+  Author: ddtddt
+  Author URI:
+ */
 
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+if (!defined('PHPWG_ROOT_PATH'))
+    die('Hacking attempt!');
 
-define('SPBA_DIR' , basename(dirname(__FILE__)));
-define('SPBA_PATH' , PHPWG_PLUGINS_PATH . SPBA_DIR . '/');
+define('SPBA_DIR', basename(dirname(__FILE__)));
+define('SPBA_PATH', PHPWG_PLUGINS_PATH . SPBA_DIR . '/');
 load_language('plugin.lang', SPBA_PATH);
+
+include_once(SPBA_PATH . 'include/function.see.inc.php');
 
 global $conf;
 $showSPBU = $conf['see_photos_by_user_show'];
 
-if (in_array($showSPBU, array(1,3)))
-{
-add_event_handler('blockmanager_apply' , 'add_link_SPBA');
+/*init plugin - filter http*/
+add_event_handler('loc_end_section_init', 'section_init_SPBA');
+
+function section_init_SPBA() {
+    /*init plugin lang*/
+    load_language('plugin.lang', SPBA_PATH);
+    load_language('lang', PHPWG_ROOT_PATH . 'local/', array('no_fallback' => true, 'local' => true));
+    
+    global $tokens, $conf, $template;
+  if(strpbrk('user-', $_SERVER['REQUEST_URI'])!=false){
+    $testa = explode('user-', $_SERVER['REQUEST_URI']);
+    if(!empty($testa[1])){
+        $testd = explode('-', $testa[1]);
+            if(is_numeric($testd[0])){
+                $username= see_username($testd[0]);
+                $result=see_userlist_nb_photo();
+                $userok = array();
+                while ($row = pwg_db_fetch_assoc($result)) {
+                    $userok[] = $row['id'];
+                }
+                if (in_array($testd[0], $userok)) {
+                    $me = 'user-' . $testd[0].'-'.$username;
+                    $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>';
+                } else {
+                    $me = 'user-';
+                    $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>';
+                }
+            }else{
+                $me = 'user-';
+            }
+    }else{
+        $me = 'user-';
+    }
+    if(isset($me)){
+        if (in_array($me, $tokens))
+            include(SPBA_PATH . 'pagespba.php');
+    }
+  }
+  
+  //$template->assign('SPBA2', 'toto');
+  $template->set_filename('SPBA', realpath(SPBA_PATH . 'pagespba.tpl'));
+  $template->assign_var_from_handle('CONTENT', 'SPBA'); //2.6
+  
 }
-function add_link_SPBA($menu_ref_arr)
- {
-  global $conf, $user;
-  $menu = & $menu_ref_arr[0];
-  if (($block = $menu->get_block('mbSpecials')) != null)
-   {
-   load_language('plugin.lang', SPBA_PATH);
-   $position = (isset($conf['SPBA_position']) and is_numeric($conf['SPBA_position'])) ? $conf['SPBA_position'] : count($block->data)+1;
-   array_splice
-	 ($block->data, $position-1, 0, array
-	  ('user-' =>
-      array
-			 (
-			 'URL' => make_index_url(array('section' => 'user-')),
-			 'TITLE' => l10n('See photos by user'),
-			 'NAME' => l10n('See photos by user')
-       )
-    )
-   );
-   }
- }
-
-add_event_handler('loc_end_section_init', 'section_init_SPBA');
-function section_init_SPBA()
-{
- global $tokens, $conf;
-$testa = explode('user-', $_SERVER['REQUEST_URI']); 
-if (!empty ($testa[1]))
-{
-$testd= explode('/', $testa[1]);
-$query = '
-SELECT UT.id, UT.username, COUNT(DISTINCT(IT.id)) AS PBU, IT.id
- FROM ' . USERS_TABLE . ' as UT
- INNER JOIN '.IMAGES_TABLE.' AS IT ON IT.added_by = UT.id
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON IT.id = ic.image_id
-  '.get_sql_condition_FandF
-  (
-    array
-      (
-        'forbidden_categories' => 'category_id',
-        'visible_categories' => 'category_id',
-        'visible_images' => 'id'
-      ),
-    'WHERE'
-  ).'
- GROUP BY IT.added_by
- HAVING PBU >'.$conf['see_photos_by_user_nbphotos'].'
- ORDER BY '.$conf['see_photos_by_user_order'].'
- LIMIT '.$conf['see_photos_by_user_limit'].';';
-
-$result = pwg_query($query);
-$userok = array();
-while ($row = pwg_db_fetch_assoc($result))
- {
-  $userok[] = $row['username'];
+/*Schow link in menu*/
+if (in_array($showSPBU, array(1, 3))) {
+    add_event_handler('blockmanager_apply', 'add_link_SPBA');
 }
 
-if (in_array($testd[0], $userok))
-{
-$me = 'user-'.$testd[0];
-}
-else
-{
- $redirect_url = get_root_url().'index.php?/categories';
- redirect($redirect_url);
-}
-}
-else
-{$me = 'user-';}
-
-if (in_array($me, $tokens))
- include(SPBA_PATH . 'pagespba.php');
+function add_link_SPBA($menu_ref_arr) {
+    global $conf, $user;
+    $menu = & $menu_ref_arr[0];
+    if (($block = $menu->get_block('mbSpecials')) != null) {
+        load_language('plugin.lang', SPBA_PATH);
+        $position = (isset($conf['SPBA_position']) and is_numeric($conf['SPBA_position'])) ? $conf['SPBA_position'] : count($block->data) + 1;
+        array_splice
+                ($block->data, $position - 1, 0, array
+            ('user-' =>
+            array
+                (
+                'URL' => make_index_url(array('section' => 'user-')),
+                'TITLE' => l10n('See photos by user'),
+                'NAME' => l10n('See photos by user')
+            )
+                )
+        );
+    }
 }
 
-if (in_array($showSPBU, array(2,3,4)))
-{
-add_event_handler('blockmanager_register_blocks', 'register_users_menubar_blocks');
-add_event_handler('blockmanager_apply', 'users_apply');
-}
-function register_users_menubar_blocks( $menu_ref_arr )
-{
-  $menu = & $menu_ref_arr[0];
-  if ($menu->get_id() != 'menubar')
-    return;
-  $menu->register_block( new RegisteredBlock( 'mbUsers','Users',('See photos by user')));
+
+/*schow users menu*/
+if (in_array($showSPBU, array(2, 3, 4))) {
+    add_event_handler('blockmanager_register_blocks', 'register_users_menubar_blocks');
+    add_event_handler('blockmanager_apply', 'users_apply');
 }
 
-function users_apply($menu_ref_arr)
-{
-global $template, $conf, $user;
-$menu = & $menu_ref_arr[0];
-load_language('plugin.lang', SPBA_PATH);
-load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true));
-
-$userslistemenu1 = pwg_query('
-SELECT UT.id, UT.username, COUNT(DISTINCT(IT.id)) AS PBU, IT.id
- FROM ' . USERS_TABLE . ' as UT
- INNER JOIN '.IMAGES_TABLE.' AS IT ON IT.added_by = UT.id
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON IT.id = ic.image_id
-  '.get_sql_condition_FandF
-  (
-    array
-      (
-        'forbidden_categories' => 'category_id',
-        'visible_categories' => 'category_id',
-        'visible_images' => 'id'
-      ),
-    'WHERE'
-  ).'
- GROUP BY IT.added_by
- HAVING PBU >'.$conf['see_photos_by_user_nbphotos'].'
- ORDER BY '.$conf['see_photos_by_user_order'].'
- LIMIT '.$conf['see_photos_by_user_limit'].';');
-
-if (pwg_db_num_rows($userslistemenu1)) {	
- while ($userslistemenu = pwg_db_fetch_assoc($userslistemenu1))
-	{
-    $items = array(
-      'USERSSPBYL' => $userslistemenu['username'],
-	  'USERSSPBYLC' => $userslistemenu['PBU'],
-		);
-		
-	$template->append('userslistemenu1', $items);
-  	}
-}
-$linkusersliste = get_root_url().'index.php?/user-';
-$template->assign('USERSSPBY', $linkusersliste);
-   
- if (($block = $menu->get_block( 'mbUsers' )) != null) {
- $template->set_template_dir(SPBA_PATH);
- $block->template = 'menubar_users.tpl';}
+function register_users_menubar_blocks($menu_ref_arr) {
+    $menu = & $menu_ref_arr[0];
+    if ($menu->get_id() != 'menubar')
+        return;
+    $menu->register_block(new RegisteredBlock('mbUsers', 'Users', ('See photos by user')));
 }
 
+function users_apply($menu_ref_arr) {
+    global $template, $conf, $user;
+    $menu = & $menu_ref_arr[0];
+
+    $userslistemenu1 = see_userlist_nb_photo();
+
+    if (pwg_db_num_rows($userslistemenu1)) {
+        while ($userslistemenu = pwg_db_fetch_assoc($userslistemenu1)) {
+            $items = array(
+                'USERSSPBYLID' => $userslistemenu['id'],
+                'USERSSPBYL' => $userslistemenu['username'],
+                'USERSSPBYLC' => $userslistemenu['PBU'],
+            );
+
+            $template->append('userslistemenu1', $items);
+        }
+    }
+    $linkusersliste = get_root_url() . 'index.php?/user-';
+    $template->assign('USERSSPBY', $linkusersliste);
+
+    if (($block = $menu->get_block('mbUsers')) != null) {
+        $template->set_template_dir(SPBA_PATH);
+        $block->template = 'menubar_users.tpl';
+    }
+}
+
+/*Add admin menu*/
 add_event_handler('get_admin_plugin_menu_links', 'SPBA_admin_menu');
-function SPBA_admin_menu($menu)
-{
-load_language('plugin.lang', SPBA_PATH);
-  array_push(
-    $menu,
-    array(
-      'NAME' => l10n('Photos by user'),
-      'URL' => get_admin_plugin_menu_link(SPBA_PATH . 'admin.php')
-      )
+
+function SPBA_admin_menu($menu) {
+    load_language('plugin.lang', SPBA_PATH);
+    array_push(
+            $menu, array(
+        'NAME' => l10n('Photos by user'),
+        'URL' => get_admin_plugin_menu_link(SPBA_PATH . 'admin.php')
+            )
     );
-  
-  return $menu;
+
+    return $menu;
 }
 
