Changeset 5123 for trunk/include


Ignore:
Timestamp:
Mar 13, 2010, 1:00:52 AM (14 years ago)
Author:
plg
Message:

feature 1502: based on Dotclear model, P@t has reorganized the way Piwigo
manages template/theme in a simpler "theme only level" architecture. It
supports multiple level inheritance.

Location:
trunk/include
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/common.inc.php

    r5021 r5123  
    159159    or (defined('PWG_HELP') and PWG_HELP))
    160160{// Admin template
    161   list($user['admin_template'], $user['admin_theme']) =
    162     explode ('/', $conf['admin_layout']);
    163   $template = new Template(PHPWG_ROOT_PATH.'admin/template/'
    164     . $user['admin_template'], $user['admin_theme'] );
     161  $template = new Template(PHPWG_ROOT_PATH.'admin/themes', $conf['admin_theme']);
    165162}
    166163else
    167164{ // Classic template
    168   $template = new Template(PHPWG_ROOT_PATH.'template/'
    169     . $user['template'], $user['theme'] );
     165  $template = new Template(PHPWG_ROOT_PATH.'themes', $user['theme'] );
    170166}
    171167
  • trunk/include/config_default.inc.php

    r5060 r5123  
    336336$conf['uniqueness_mode'] = 'md5sum';
    337337
     338// Define default theme for your gallery
     339$conf['default_theme'] = 'Sylvia';
     340
    338341// +-----------------------------------------------------------------------+
    339342// |                               metadata                                |
     
    677680// +-----------------------------------------------------------------------+
    678681
    679 $conf['admin_layout'] = 'goto/roma';
     682$conf['admin_theme'] = 'roma';
    680683
    681684// should we load the active plugins ? true=Yes, false=No
  • trunk/include/functions.inc.php

    r5102 r5123  
    612612    trigger_action('loading_lang');
    613613    load_language('local.lang', '', array('no_fallback'=>true) );
    614     list($tmpl, $thm) = explode('/', get_default_template());
    615     $template = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl, $thm);
     614    $template = new Template(PHPWG_ROOT_PATH.'themes', get_default_theme());
    616615  }
    617616  else
    618617  {
    619     $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme']);
     618    $template = new Template(PHPWG_ROOT_PATH.'themes', $user['theme']);
    620619  }
    621620
     
    711710
    712711/**
    713  * returns available template/theme
     712 * returns available themes
    714713 */
    715714function get_pwg_themes()
     
    718717  $themes = array();
    719718
    720   $template_dir = PHPWG_ROOT_PATH.'template';
    721 
    722   foreach (get_dirs($template_dir) as $template)
    723   {
    724     if ( $template != 'default' )
    725         {
    726       foreach (get_dirs($template_dir.'/'.$template.'/theme') as $theme)
    727       {
    728         array_push($themes, $template.'/'.$theme);
    729       }
    730         }
     719  $template_dir = PHPWG_ROOT_PATH.'themes';
     720
     721  foreach (get_dirs($template_dir) as $theme)
     722  {
     723    if ( $theme != 'default' )
     724          {
     725      array_push($themes, $theme);
     726          }
    731727  }
    732728
  • trunk/include/functions_mail.inc.php

    r5021 r5123  
    153153/**
    154154 * Returns an completed array template/theme
    155  * completed with get_default_template()
     155 * completed with get_default_theme()
    156156 *
    157157 * @params:
    158158 *   - args: incompleted array of template/theme
    159  *       o template: template to use [default get_default_template()]
    160  *       o theme: template to use [default get_default_template()]
     159 *       o template: template to use [default get_default_theme()]
     160 *       o theme: template to use [default get_default_theme()]
    161161 */
    162162function get_array_template_theme($args = array())
     
    168168  if (empty($args['template']) or empty($args['theme']))
    169169  {
    170     list($res['template'], $res['theme']) = explode('/', get_default_template());
     170    list($res['template'], $res['theme']) = explode('/', get_default_theme());
    171171  }
    172172
     
    190190 *   - email_format: mail format
    191191 *   - args: function params of mail function:
    192  *       o template: template to use [default get_default_template()]
    193  *       o theme: template to use [default get_default_template()]
    194  */
    195 function & get_mail_template($email_format, $args = array())
    196 {
    197   $args = get_array_template_theme($args);
    198 
    199   $mail_template = new Template(PHPWG_ROOT_PATH.'template/'.$args['template'], $args['theme']);
    200   $mail_template->set_template_dir(PHPWG_ROOT_PATH.'template/'.$args['template'].'/mail/'.$email_format);
     192 *       o template: template to use [default get_default_theme()]
     193 *       o theme: template to use [default get_default_theme()]
     194 */
     195function & get_mail_template($email_format, $theme='')
     196{
     197  if (empty($theme))
     198  {
     199    $theme = get_default_theme();
     200  }
     201
     202  $mail_template = new Template(PHPWG_ROOT_PATH.'themes', $theme, 'template/mail/'.$email_format);
     203
    201204  return $mail_template;
    202205}
     
    418421  $query = '
    419422SELECT
    420   distinct language, template
     423  distinct language, theme
    421424FROM
    422425  '.USER_GROUP_TABLE.' as ug
     
    443446    while ($row = pwg_db_fetch_assoc($result))
    444447    {
    445       $row['template_theme'] = $row['template'];
    446       list($row['template'], $row['theme']) = explode('/', $row['template_theme']);
    447448      $list[] = $row;
    448449    }
     
    462463    AND group_id = '.$group_id.'
    463464    AND language = \''.$elem['language'].'\'
    464     AND template = \''.$elem['template_theme'].'\'
     465    AND theme = \''.$elem['theme'].'\'
    465466;';
    466467
     
    482483          switch_lang_to($elem['language']);
    483484
    484           $mail_template = get_mail_template($email_format, $elem);
     485          $mail_template = get_mail_template($email_format, $elem['theme']);
    485486          $mail_template->set_filename($tpl_shortname, $tpl_shortname.'.tpl');
    486487
     
    498499              'content' => $mail_template->parse($tpl_shortname, true),
    499500              'content_format' => $email_format,
    500               'template' => $elem['template'],
    501501              'theme' => $elem['theme']
    502502            )
     
    525525 *       o content_format: format of mail content  [default value 'text/plain']
    526526 *       o email_format: global mail format  [default value $conf_mail['default_email_format']]
    527  *       o template: template to use [default get_default_template()]
    528  *       o theme: template to use [default get_default_template()]
     527 *       o theme: template to use [default get_default_theme()]
    529528 *
    530529 * @return boolean (Ok or not)
     
    585584  }
    586585
    587   $args = array_merge($args, get_array_template_theme($args));
     586  if (empty($args['theme']))
     587  {
     588    $args['theme'] = get_default_theme();
     589  }
    588590
    589591  $headers = 'From: '.$args['from']."\n";
     
    618620  {
    619621    // key compose of indexes witch allow ti cache mail data
    620     $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['template'].'-'.$args['theme'];
     622    $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme'];
    621623
    622624    if (!isset($conf_mail[$cache_key]))
    623625    {
    624       if (!isset($conf_mail[$cache_key]['template']))
     626      if (!isset($conf_mail[$cache_key]['theme']))
    625627      {
    626         $conf_mail[$cache_key]['template'] = get_mail_template($content_type);
     628        $conf_mail[$cache_key]['theme'] = get_mail_template($content_type);
    627629      }
    628630
    629       $conf_mail[$cache_key]['template']->set_filename('mail_header', 'header.tpl');
    630       $conf_mail[$cache_key]['template']->set_filename('mail_footer', 'footer.tpl');
    631 
    632       $conf_mail[$cache_key]['template']->assign(
     631      $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl');
     632      $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl');
     633
     634      $conf_mail[$cache_key]['theme']->assign(
    633635        array(
    634636          //Header
     
    653655      if ($content_type == 'text/html')
    654656      {
    655         if (is_file($conf_mail[$cache_key]['template']->get_template_dir().'/global-mail-css.tpl'))
     657        /*
     658        if (is_file($conf_mail[$cache_key]['theme']->get_template_dir().'/global-mail-css.tpl'))
    656659        {
    657           $conf_mail[$cache_key]['template']->set_filename('css', 'global-mail-css.tpl');
    658           $conf_mail[$cache_key]['template']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
     660          $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl');
     661          $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css');
    659662        }
    660 
    661         $root_abs_path = dirname(dirname(__FILE__));
    662 
    663         $file = $root_abs_path.'/template/'.$args['template'].'/theme/'.$args['theme'].'/mail-css.tpl';
     663        */
     664
     665        $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl';
    664666        if (is_file($file))
    665667        {
    666           $conf_mail[$cache_key]['template']->set_filename('css', $file);
    667           $conf_mail[$cache_key]['template']->assign_var_from_handle('MAIL_CSS', 'css');
     668          $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file));
     669          $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css');
    668670        }
    669 
     671        /*
    670672        $file = $root_abs_path.'/template-common/local-mail-css.tpl';
    671673        if (is_file($file))
     
    674676          $conf_mail[$cache_key]['template']->assign_var_from_handle('LOCAL_MAIL_CSS', 'css');
    675677        }
     678        */
    676679      }
    677680
    678681      // what are displayed on the header of each mail ?
    679682      $conf_mail[$cache_key]['header'] =
    680         $conf_mail[$cache_key]['template']->parse('mail_header', true);
     683        $conf_mail[$cache_key]['theme']->parse('mail_header', true);
    681684
    682685      // what are displayed on the footer of each mail ?
    683686      $conf_mail[$cache_key]['footer'] =
    684         $conf_mail[$cache_key]['template']->parse('mail_footer', true);
     687        $conf_mail[$cache_key]['theme']->parse('mail_footer', true);
    685688    }
    686689
     
    714717  $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n";
    715718  }
    716 
    717719
    718720  //~ // Close boundary
  • trunk/include/functions_user.inc.php

    r5060 r5123  
    246246  $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
    247247
    248   list($user['template'], $user['theme']) = explode('/', $user['template']);
     248  // Check user theme
     249  if (!file_exists(PHPWG_ROOT_PATH.'themes/'.$user['theme'].'/themeconf.inc.php'))
     250  {
     251    $user['theme'] = $conf['default_theme'];
     252  }
    249253
    250254  return $user;
     
    842846 *
    843847 */
    844 function get_default_template()
    845 {
    846   return get_default_user_value('template', PHPWG_DEFAULT_TEMPLATE);
     848function get_default_theme()
     849{
     850  return get_default_user_value('theme', PHPWG_DEFAULT_TEMPLATE);
    847851}
    848852
  • trunk/include/template.class.php

    r5101 r5123  
    5353  var $html_head_elements = array();
    5454
    55   function Template($root = ".", $theme= "")
     55  function Template($root = ".", $theme= "", $path = "template")
    5656  {
    5757    global $conf, $lang_info;
     
    7878    }
    7979
     80    $this->smarty->template_dir = array();
    8081    if ( !empty($theme) )
    8182    {
    82       include($root.'/theme/'.$theme.'/themeconf.inc.php');
    83       $this->smarty->assign('themeconf', $themeconf);
     83      $this->set_theme($root, $theme, $path);
    8484    }
    8585
    8686    $this->smarty->assign('lang_info', $lang_info);
    87 
    88     $this->set_template_dir($root);
    8987
    9088    if (!defined('IN_ADMIN') and isset($conf['extents_for_templates']))
     
    9694
    9795  /**
    98    * Sets the template root directory for this Template object.
    99    * Revised from Piwigo 2.1 to add modeling support
    100    */
     96   * Load theme's parameters.
     97   */
     98  function set_theme($root, $theme, $path)
     99  {
     100    $this->set_template_dir($root.'/'.$theme.'/'.$path);
     101
     102    include($root.'/'.$theme.'/themeconf.inc.php');
     103
     104    if (isset($themeconf['parent']))
     105    {
     106      $this->set_theme($root, $themeconf['parent'], $path);
     107    }
     108
     109    $tpl_var = array('name' => $themeconf['theme']);
     110    if (file_exists($root.'/'.$theme.'/local_head.tpl'))
     111    {
     112      $tpl_var['local_head'] = realpath($root.'/'.$theme.'/local_head.tpl');
     113    }
     114    $this->smarty->append('themes', $tpl_var);
     115    $this->smarty->append('themeconf', $themeconf, true);
     116  }
     117
    101118  function set_template_dir($dir)
    102119  {
    103     $modeling = $this->get_themeconf('modeling');
    104         if (!defined('IN_ADMIN') and ($modeling !== false))
    105         { // Modeling is active only on gallery side and never in admin
    106           // Set the normal directory
    107       $this->smarty->template_dir = array($dir);
    108           // Modeling by theme parameter
    109           $model = './template/' . $modeling;
    110       if ( $model != './template/' and is_dir($model))
    111           {
    112                 $this->smarty->template_dir[] = $model;
    113       }
    114           // Default template directory
    115           $this->smarty->template_dir[] = './template/default';
    116         }
    117     else
    118         {
    119       $this->smarty->template_dir = $dir;
    120         }
    121     $real_dir = realpath($dir);
    122     $compile_id = crc32( $real_dir===false ? $dir : $real_dir);
    123     $this->smarty->compile_id = base_convert($compile_id, 10, 36 );
     120    $this->smarty->template_dir[] = $dir;
     121
     122    if (!isset($this->smarty->compile_id))
     123    {
     124      $real_dir = realpath($dir);
     125      $compile_id = crc32( $real_dir===false ? $dir : $real_dir);
     126      $this->smarty->compile_id = base_convert($compile_id, 10, 36 );
     127    }
    124128  }
    125129
     
    197201  function set_extents($filename_array, $dir='', $overwrite=true)
    198202  {
     203    global $user;
     204
    199205    if (!is_array($filename_array))
    200206    {
     
    221227
    222228      if ((stripos(implode('',array_keys($_GET)), '/'.$param) !== false or $param == 'N/A')
    223         and (preg_match('/'.preg_quote($tpl,'/').'$/', $this->get_template_dir()) or $tpl == 'N/A')
     229        and ($tpl == $user['theme'] or $tpl == 'N/A')
    224230        and (!isset($this->extents[$handle]) or $overwrite)
    225231        and file_exists($dir . $filename))
Note: See TracChangeset for help on using the changeset viewer.