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

Last change on this file since 16241 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
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// | Theme switch plugin                                                   |
5// +-----------------------------------------------------------------------+
6// | Copyright(C) 2012      Piwigo Team                  http://piwigo.org |
7// | Copyright(C) 2010      Pavel Budka               http://budkovi.ic.cz |
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// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
25
26function theme_controler_switch()
27{
28  global $user, $template, $conf;
29 
30  $same = $user['theme'];
31  if ( isset( $_GET['theme']) ) 
32  {
33    if ( !empty($_GET['theme']) and file_exists(PHPWG_THEMES_PATH.$_GET['theme']) )
34    {
35      if ( is_a_guest() or is_generic() )
36      {
37        pwg_set_session_var('theme_switch', $_GET['theme']);
38      }
39      else
40      {
41        $query = '
42UPDATE '.USER_INFOS_TABLE.'
43  SET theme = "'.$_GET['theme'].'"
44  WHERE user_id = '.$user['id'].'
45;';
46        pwg_query($query);
47      }
48      $user['theme'] = $_GET['theme'];
49    }
50  }
51  else if ( (is_a_guest() or is_generic()) and pwg_get_session_var('theme_switch')!=null )
52  {
53    $user['theme'] = pwg_get_session_var('theme_switch');
54  }
55}
56
57function theme_controler_init()
58{
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  }
69}
70
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}
104
105function theme_controler_select()
106{
107  global $user, $template;
108
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');
123}
124
125?>
Note: See TracBrowser for help on using the repository browser.