source: extensions/theme_switch/trunk/theme_switch.inc.php @ 20009

Last change on this file since 20009 was 16241, checked in by mistic100, 12 years ago

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 size: 4.0 KB
RevLine 
[7072]1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// | Theme switch plugin                                                   |
5// +-----------------------------------------------------------------------+
[16241]6// | Copyright(C) 2012      Piwigo Team                  http://piwigo.org |
[7093]7// | Copyright(C) 2010      Pavel Budka               http://budkovi.ic.cz |
[7072]8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[7093]23
[16241]24if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
[7171]25
[16241]26function theme_controler_switch()
[7072]27{
[7093]28  global $user, $template, $conf;
[16241]29 
[7093]30  $same = $user['theme'];
31  if ( isset( $_GET['theme']) ) 
[7072]32  {
[16241]33    if ( !empty($_GET['theme']) and file_exists(PHPWG_THEMES_PATH.$_GET['theme']) )
[7072]34    {
[16241]35      if ( is_a_guest() or is_generic() )
36      {
37        pwg_set_session_var('theme_switch', $_GET['theme']);
38      }
[7072]39      else
40      {
[16241]41        $query = '
42UPDATE '.USER_INFOS_TABLE.'
43  SET theme = "'.$_GET['theme'].'"
44  WHERE user_id = '.$user['id'].'
45;';
[7072]46        pwg_query($query);
47      }
48      $user['theme'] = $_GET['theme'];
49    }
50  }
[16241]51  else if ( (is_a_guest() or is_generic()) and pwg_get_session_var('theme_switch')!=null )
[7072]52  {
[16241]53    $user['theme'] = pwg_get_session_var('theme_switch');
[7072]54  }
[7171]55}
56
[16241]57function theme_controler_init()
[7171]58{
[16241]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  }
[7171]69}
70
[16241]71function theme_controler_thumb()
[7072]72{
[16241]73  global $user, $template, $conf;
[7072]74 
[16241]75  foreach (get_pwg_themes() as $id => $name)
76  {
77    $img =  PHPWG_THEMES_PATH.$id.'/screenshot.png';
[7072]78         
[16241]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,
[7072]86        );
[16241]87       
88      if ($id==$user['theme'])
89      {
90        $template->assign('theme_switch_active', $theme);
[7072]91      }
[16241]92     
93      $template->append('theme_switch', $theme);
94    }
[7093]95  } 
[7072]96 
[16241]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}
[7093]104
[16241]105function theme_controler_select()
[7093]106{
[16241]107  global $user, $template;
[7093]108
[16241]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  }
118 
119  $template->set_filename('theme_select', dirname(__FILE__) . '/select.tpl');
120  $template->concat('PLUGIN_INDEX_ACTIONS', $template->parse('theme_select', true));
121 
122  $template->clear_assign('theme_select');
[7072]123}
[7093]124
[16241]125?>
Note: See TracBrowser for help on using the repository browser.