Ignore:
Timestamp:
10/04/10 20:58:57 (9 years ago)
Author:
pab
Message:

theme switch compatible with piwigo 2.1.* (with CZ, UK localization)

File:
1 edited

Legend:

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

    r7072 r7093  
    44// | Theme switch plugin                                                   | 
    55// +-----------------------------------------------------------------------+ 
    6 // | Copyright(C) 2008      Pavel Budka                http://pbudka.co.cc | 
     6// | Copyright(C) 2010      Pavel Budka               http://budkovi.ic.cz | 
    77// +-----------------------------------------------------------------------+ 
    88// | This program is free software; you can redistribute it and/or modify  | 
     
    2222if (!defined('THEME_SWITCH_PATH')) 
    2323define('THEME_SWITCH_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); 
     24 
    2425class theme_controler { 
    2526static public function _switch() 
    2627{ 
    27   global $user, $template, $conf, $lang; 
     28  global $user, $template, $conf; 
     29 
     30  load_language('plugin.lang', dirname(__FILE__).'/'); 
     31 
    2832  if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } 
    29   $same = $user['template'].'/'.$user['theme']; 
    30   if ( isset( $_GET['theme']) and isset( $_GET['template']) ) 
     33  $same = $user['theme']; 
     34  if ( isset( $_GET['theme']) )  
    3135  { 
    32     if ( !empty($_GET['theme']) and !empty($_GET['template']) and 
    33       file_exists( PHPWG_ROOT_PATH.'template/'.$_GET['template'].'/theme/'.$_GET['theme']) ) 
     36    if ( !empty($_GET['theme']) and 
     37      file_exists( PHPWG_ROOT_PATH.'themes/'.$_GET['theme']) ) 
    3438    { 
    3539      if (is_a_guest() or is_generic()) 
    36       { 
    3740        setcookie( 'pwg_theme_switch', $_GET['theme'], 
    3841          time()+60*60*24*30, cookie_path() ); 
    39         setcookie( 'pwg_template_switch', $_GET['template'], 
    40           time()+60*60*24*30, cookie_path() ); 
    41       } 
    4242      else 
    4343      { 
    4444        $query = 'UPDATE '.USER_INFOS_TABLE.' 
    45         SET template = \''.$_GET['template'].'/'.$_GET['theme'].'\' 
     45        SET theme = \''.$_GET['theme'].'\' 
    4646        WHERE user_id = '.$user['id'].' 
    4747        ;'; 
     
    4949      } 
    5050      $user['theme'] = $_GET['theme']; 
    51       $user['template'] = $_GET['template']; 
    5251    } 
    5352  } 
     
    5655  // Guest or generic members will use their cookied $user['template']/$user['theme'] ! 
    5756  if ((is_a_guest() or is_generic()) 
    58     and isset( $_COOKIE['pwg_theme_switch'] ) 
    59     and isset( $_COOKIE['pwg_template_switch'] ) ) 
     57    and isset( $_COOKIE['pwg_theme_switch'] ) ) 
    6058  { 
    61     $user['template'] = $_COOKIE['pwg_template_switch']; 
    6259    $user['theme'] = $_COOKIE['pwg_theme_switch']; 
    6360  } 
    64 } 
     61} // function _switch() 
    6562 
    6663static public function _flags() 
     
    6966// Gif file name must be the same as theme's name and must be stored in sub directory named according to template's name.   
    7067{ 
    71   global $user, $template, $lang; 
     68  global $user, $template, $conf, $lang; 
    7269   
    7370  $available_theme = get_pwg_themes(); 
    7471 
    75   $url_starting = get_query_string_diff(array('template', 'theme')); 
     72  $url_starting = get_query_string_diff(array('theme')); 
    7673 
    77   foreach ( $available_theme as $code ) { 
    78     $qlc_img =  'plugins/theme_switch/icons/' . $code . '.gif'; 
     74  foreach ( $available_theme as $theme_id => $theme ) { 
     75    $qlc_img =  $conf['themes_dir'].'/'.$theme_id.'/'.'screenshot.png'; 
    7976          
    80     if (file_exists(PHPWG_ROOT_PATH.$qlc_img)) { 
    81       list($temp, $theme) = split('/',$code); 
     77    if (file_exists($qlc_img)) { 
     78       
    8279      $qlc_url = str_replace(array('=&','?&'),array('&','?'), 
    83                  add_url_params( $url_starting, array( 'template' => $temp, 'theme' => $theme  ) )); 
     80                 add_url_params( $url_starting, array( 'theme' => $theme_id ))); 
    8481      if (isset($lang['theme'])) 
    85         $qlc_alt = $lang['theme'].': '.ucwords( $code ); 
     82        $qlc_alt = $lang['theme'].': '.ucwords( $theme ); 
    8683      else 
    87         $qlc_alt = ucwords( $code ); 
     84        $qlc_alt = ucwords( $theme ); 
    8885      $qlc_title =  $qlc_alt; 
    8986      $qlc = array (  
     
    9289        'img' => $qlc_img, 
    9390        ); 
    94       if ( $code !== $user['template'].'/'.$user['theme']) 
    95         $lsw['flags'][$code] = $qlc ; 
     91      if ( $theme_id !== $user['theme']) 
     92        $lsw['flags'][$theme_id] = $qlc ; 
    9693      else $lsw['Active'] = $qlc; 
    9794      } 
    98   } 
     95  }  
    9996     
    10097  $template->set_filename('theme_flags', dirname(__FILE__) . '/flags.tpl'); 
     
    107104  $template->clear_assign('theme_switch'); 
    108105  $template->concat( 'PLUGIN_INDEX_ACTIONS', $flags); 
    109 } 
     106} // function _flags() 
    110107 
    111108static public function _select() 
     
    116113   
    117114  $available_theme = get_pwg_themes(); 
    118   $url_starting = get_query_string_diff(array('lang')); 
     115  $url_starting = get_query_string_diff(array('theme')); 
    119116  $options='<li><span class="property"> 
    120117   <label for="template">'.$lang['theme'].'</label> 
    121118  </span> 
    122119  <select name="template" onchange="javasript:window.location=this.value">'; 
    123   foreach ( $available_theme as $code ) 
     120  foreach ( $available_theme as $theme_id => $theme ) 
    124121  { 
    125     list($temp, $theme) = split('/',$code); 
    126122    $qlc_url = str_replace(array('=&amp;','?&amp;'),array('&amp;','?'), 
    127       add_url_params( $url_starting, array( 'template' => $temp, 'theme' => $theme  ) )); 
     123      add_url_params( $url_starting, array( 'theme' => $theme_id  ) )); 
    128124     
    129     if ( $code == $user['template'].'/'.$user['theme'] ) 
     125    if ( $theme_id == $user['theme'] ) 
    130126      $tmp='" selected="selected">'; 
    131127    else 
    132128      $tmp='">'; 
    133129    $options=$options.' 
    134     <option label="'.$code.'" value="'.$qlc_url.$tmp.$code.'</option>'; 
     130    <option label="'.$theme.'" value="'.$qlc_url.$tmp.$theme.'</option>'; 
    135131  } 
    136132  $options=$options.' 
    137133  </select></li>'; 
    138134  $template->concat( 'PLUGIN_INDEX_ACTIONS',$options); 
    139 } 
    140 } 
     135} //  function _select()  
     136 
     137static public function _theme_admin($menu) 
     138// adds menu options for future configuration  
     139{ 
     140//  load_language('plugin.lang', dirname(__FILE__).'/'); 
     141  array_push($menu, array('NAME' => 'Theme Switch', 
     142    'URL' => get_admin_plugin_menu_link(THEME_SWITCH_PATH.'admin/admin.php'))); 
     143  return $menu; 
     144} // function _theme_admin() 
     145 
     146} // class theme_controler 
     147 
    141148  /* {html_head} usage function */ 
    142149  /* See flags.tpl for example (due no catenation available) */ 
     
    145152    { return file_exists( $path . $file); } 
    146153} 
     154 
    147155?> 
Note: See TracChangeset for help on using the changeset viewer.