Ignore:
Timestamp:
Jul 1, 2012, 2:29:15 AM (12 years ago)
Author:
mistic100
Message:

choose between selectbox or thumbnails grid with a local config option, thumbnail grid use 2.4 drop-downs menus, only an icon appears on toolbar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/theme_switch/trunk/theme_switch.inc.php

    r7171 r16241  
    44// | Theme switch plugin                                                   |
    55// +-----------------------------------------------------------------------+
     6// | Copyright(C) 2012      Piwigo Team                  http://piwigo.org |
    67// | Copyright(C) 2010      Pavel Budka               http://budkovi.ic.cz |
    78// +-----------------------------------------------------------------------+
     
    2021// | USA.                                                                  |
    2122// +-----------------------------------------------------------------------+
    22 if (!defined('THEME_SWITCH_PATH'))
    23 define('THEME_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
    2423
    25 include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
     24if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    2625
    27 class theme_controler {
    28 static public function _switch()
     26function theme_controler_switch()
    2927{
    3028  global $user, $template, $conf;
    31 
    32   load_language('plugin.lang', dirname(__FILE__).'/');
    33 
    34   if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
     29 
    3530  $same = $user['theme'];
    3631  if ( isset( $_GET['theme']) )
    3732  {
    38     if ( !empty($_GET['theme']) and
    39       file_exists( PHPWG_ROOT_PATH.'themes/'.$_GET['theme']) )
     33    if ( !empty($_GET['theme']) and file_exists(PHPWG_THEMES_PATH.$_GET['theme']) )
    4034    {
    41       if (is_a_guest() or is_generic())
    42         setcookie( 'pwg_theme_switch', $_GET['theme'],
    43           time()+60*60*24*30, cookie_path() );
     35      if ( is_a_guest() or is_generic() )
     36      {
     37        pwg_set_session_var('theme_switch', $_GET['theme']);
     38      }
    4439      else
    4540      {
    46         $query = 'UPDATE '.USER_INFOS_TABLE.'
    47         SET theme = \''.$_GET['theme'].'\'
    48         WHERE user_id = '.$user['id'].'
    49         ;';
     41        $query = '
     42UPDATE '.USER_INFOS_TABLE.'
     43  SET theme = "'.$_GET['theme'].'"
     44  WHERE user_id = '.$user['id'].'
     45;';
    5046        pwg_query($query);
    5147      }
     
    5349    }
    5450  }
    55   else
    56   // Users have $user['template']/$user['theme']
    57   // Guest or generic members will use their cookied $user['template']/$user['theme'] !
    58   if ((is_a_guest() or is_generic())
    59     and isset( $_COOKIE['pwg_theme_switch'] ) )
     51  else if ( (is_a_guest() or is_generic()) and pwg_get_session_var('theme_switch')!=null )
    6052  {
    61     $user['theme'] = $_COOKIE['pwg_theme_switch'];
     53    $user['theme'] = pwg_get_session_var('theme_switch');
    6254  }
    63 } // function _switch()
    64 
    65 static public function _installed_themes()
    66 // id, name, screenshot 
    67 {
    68 $themes = new themes();
    69 $themes->sort_fs_themes();
    70 $db_themes = $themes->get_db_themes();
    71 $db_theme_ids = array();
    72 foreach ($db_themes as $db_theme)
    73 {
    74   array_push($db_theme_ids, $db_theme['id']);
    7555}
    7656
    77 $active_themes = array();
    78 
    79 
    80 foreach ($themes->fs_themes as $theme_id => $fs_theme)
     57function theme_controler_init()
    8158{
    82   if (in_array($theme_id, $db_theme_ids))
    83       array_push($active_themes, $fs_theme);
     59  global $conf;
     60 
     61  if ( isset($conf['theme_switch_mode']) and $conf['theme_switch_mode'] == 'select' )
     62  {
     63    theme_controler_select();
     64  }
     65  else
     66  {
     67    theme_controler_thumb();
     68  }
    8469}
    8570
    86 return $active_themes;
    87 } // function  _installed_themes()
     71function theme_controler_thumb()
     72{
     73  global $user, $template, $conf;
     74 
     75  foreach (get_pwg_themes() as $id => $name)
     76  {
     77    $img =  PHPWG_THEMES_PATH.$id.'/screenshot.png';
     78         
     79    if (file_exists($img))
     80    {
     81      $theme = array(
     82        'id' => $id,
     83        'name' => $name,
     84        'url' => add_url_params( duplicate_index_url(), array('theme'=>$id) ),
     85        'img' => $img,
     86        );
     87       
     88      if ($id==$user['theme'])
     89      {
     90        $template->assign('theme_switch_active', $theme);
     91      }
     92     
     93      $template->append('theme_switch', $theme);
     94    }
     95  }
     96 
     97  $template->assign('THEME_SWITCH_PATH', THEME_SWITCH_PATH);
     98 
     99  $template->set_filename('theme_thumb', dirname(__FILE__) . '/thumb.tpl');
     100  $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('theme_thumb', true));
     101 
     102  $template->clear_assign('theme_thumb');
     103}
    88104
     105function theme_controler_select()
     106{
     107  global $user, $template;
    89108
    90 static public function _flags()
    91 // Lets user choose from icons
    92 // Only themes which have gif icon provided in icons plugin directory will be provided to users.
    93 // Gif file name must be the same as theme's name and must be stored in sub directory named according to template's name. 
    94 {
    95   global $user, $template, $conf, $lang;
     109  foreach (get_pwg_themes() as $id => $name)
     110  {     
     111    $template->append('theme_switch', array(
     112      'id' => $id,
     113      'name' => $name,
     114      'url' => add_url_params( duplicate_index_url(), array('theme'=>$id) ),
     115      'select' => ($id==$user['theme']) ? 'selected="selected"' :  null,
     116      ));
     117  }
    96118 
    97   $available_theme = get_pwg_themes();
    98 
    99   $url_starting = get_query_string_diff(array('theme'));
     119  $template->set_filename('theme_select', dirname(__FILE__) . '/select.tpl');
     120  $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('theme_select', true));
    100121 
    101   foreach ( theme_controler::_installed_themes() as $theme ) {
    102     $qlc_img =  $theme['screenshot']; // $conf['themes_dir'].'/'.$theme_id.'/'.'screenshot.png';
    103          
    104     if (file_exists($qlc_img)) {
    105      
    106       $qlc_url = str_replace(array('=&','?&'),array('&','?'),
    107                  add_url_params( $url_starting, array( 'theme' => $theme['id'] )));
    108       if (isset($lang['theme']))
    109         $qlc_alt = $lang['theme'].' '.ucwords( $theme['name'] );
    110       else
    111         $qlc_alt = ucwords( $theme['name'] );
    112       $qlc_title =  $qlc_alt;
    113       $qlc = array (
    114         'url' => $qlc_url,
    115         'alt' => $qlc_alt,
    116         'img' => $qlc_img,
    117         );
    118       if ( $theme['id'] !== $user['theme'])
    119         $lsw['flags'][$theme['id']] = $qlc ;
    120       else $lsw['Active'] = $qlc;
    121       }
    122   }
    123    
    124   $template->set_filename('theme_flags', dirname(__FILE__) . '/flags.tpl');
    125   $lsw['side'] = ceil(sqrt(count($available_theme)));
    126   $template->assign(array(
    127     'theme_switch'=> $lsw,
    128     'THEME_SWITCH_PATH' => THEME_SWITCH_PATH,
    129   ));
    130   $flags = $template->parse('theme_flags',true);
    131   $template->clear_assign('theme_switch');
    132   $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags);
    133 } // function _flags()
    134 
    135 
    136 static public function _select()
    137 // Lets user choose using select control
    138 // All available themes will be provided to users.
    139 {
    140   global $user, $template, $lang;
    141  
    142   $available_theme = get_pwg_themes();
    143   $url_starting = get_query_string_diff(array('theme'));
    144   $options='<li class="selector">'
    145    .$lang['theme'].
    146     '&nbsp;<select onchange="javasript:window.location=this.value">';
    147   foreach ( theme_controler::_installed_themes() as $theme )
    148   {
    149     $qlc_url = str_replace(array('=&amp;','?&amp;'),array('&amp;','?'),
    150       add_url_params( $url_starting, array( 'theme' => $theme['id']  ) ));
    151    
    152     if ( $theme['id'] == $user['theme'] )
    153       $tmp='" selected="selected">';
    154     else
    155       $tmp='">';
    156     $options=$options.'
    157     <option label="'.$theme['name'].'" value="'.$qlc_url.$tmp.$theme['name'].'</option>';
    158   }
    159   $options=$options.'
    160   </select></li>';
    161   $template->concat( 'PLUGIN_INDEX_ACTIONS',$options);
    162 } //  function _select()
    163 
    164 static public function _theme_admin($menu)
    165 // adds menu options for future configuration
    166 {
    167 //  load_language('plugin.lang', dirname(__FILE__).'/');
    168   array_push($menu, array('NAME' => 'Theme Switch',
    169     'URL' => get_admin_plugin_menu_link(THEME_SWITCH_PATH.'admin/admin.php')));
    170   return $menu;
    171 } // function _theme_admin()
    172 
    173 } // class theme_controler
    174 
    175   /* {html_head} usage function */
    176   /* See flags.tpl for example (due no catenation available) */
    177 if (!function_exists('Componant_exists')) {
    178   function Componant_exists($path, $file)
    179     { return file_exists( $path . $file); }
     122  $template->clear_assign('theme_select');
    180123}
    181124
Note: See TracChangeset for help on using the changeset viewer.