Changeset 1572


Ignore:
Timestamp:
Oct 21, 2006, 10:16:01 PM (18 years ago)
Author:
rvelices
Message:

merge -r1568 from trunk to branch-1_6 (auto_login/redirect corrections)

Location:
branches/branch-1_6
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_6/identification.php

    r1554 r1572  
    7272  }
    7373}
    74 elseif (!empty($_COOKIE[$conf['remember_me_name']]))
    75 {
    76   auto_login();
    77 }
     74
    7875//----------------------------------------------------- template initialization
    7976//
  • branches/branch-1_6/include/common.inc.php

    r1501 r1572  
    133133or die ( "Could not connect to database" );
    134134
     135//
     136// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
     137// since basic gallery information is not available
     138//
     139load_conf_from_db();
     140
     141include(PHPWG_ROOT_PATH.'include/user.inc.php');
     142
     143
     144// language files
     145include_once(get_language_filepath('common.lang.php'));
     146if (defined('IN_ADMIN') and IN_ADMIN)
     147{
     148  include_once(get_language_filepath('admin.lang.php'));
     149}
     150
     151// only now we can set the localized username of the guest user (and not in
     152// include/user.inc.php)
     153if ($user['is_the_guest'])
     154{
     155  $user['username'] = $lang['guest'];
     156}
     157
     158// template instance
     159$template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme'] );
     160
     161if ($conf['gallery_locked'])
     162{
     163  $header_msgs[] = $lang['gallery_locked_message'];
     164
     165  if ( basename($_SERVER["SCRIPT_FILENAME"]) != 'identification.php'
     166      and !is_admin() )
     167  {
     168    //next line required if PATH_INFO (no ? in url) but won't work for scripts outside PWG
     169    $page['root_path'] = cookie_path();
     170    echo $lang['gallery_locked_message']
     171      .'<a href="'.get_root_url().'identification.php">.</a>';
     172    exit();
     173  }
     174}
     175
     176if ($user['is_the_guest'] and !$conf['guest_access']
     177    and !in_array( basename($_SERVER['SCRIPT_FILENAME']),
     178                      array('identification.php',
     179                            'password.php',
     180                            'register.php'
     181                        )
     182                  )
     183    )
     184{
     185  //next line required if PATH_INFO (no ? in url) but won't work for scripts outside PWG
     186  $page['root_path'] = cookie_path();
     187  redirect (get_root_url().'identification.php');
     188}
     189
    135190if ($conf['check_upgrade_feed']
    136191    and defined('PHPWG_IN_UPGRADE')
     
    150205  if (count(array_diff($existing, $applied)) > 0)
    151206  {
     207    //next line required if PATH_INFO (no ? in url) but won't work for scripts outside PWG
     208    $page['root_path'] = cookie_path();
    152209    $header_msgs[] = 'Some database upgrades are missing, '
    153       .'<a href="'.PHPWG_ROOT_PATH.'upgrade_feed.php">upgrade now</a>';
    154   }
    155 }
    156 
    157 //
    158 // Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
    159 // since basic gallery information is not available
    160 //
    161 load_conf_from_db();
    162 
    163 include(PHPWG_ROOT_PATH.'include/user.inc.php');
    164 
    165 // language files
    166 include_once(get_language_filepath('common.lang.php'));
    167 
    168 if (defined('IN_ADMIN') and IN_ADMIN)
    169 {
    170   include_once(get_language_filepath('admin.lang.php'));
    171 }
    172 
    173 if ($conf['gallery_locked'])
    174 {
    175   $header_msgs[] = $lang['gallery_locked_message']
    176     . '<a href="'.PHPWG_ROOT_PATH.'identification.php">.</a>';
    177 
    178   if ( basename($_SERVER["PHP_SELF"]) != 'identification.php'
    179       and !is_admin() )
    180   {
    181     echo( $lang['gallery_locked_message'] );
    182     exit();
    183   }
    184 }
    185 
    186 // only now we can set the localized username of the guest user (and not in
    187 // include/user.inc.php)
    188 if ($user['is_the_guest'])
    189 {
    190   $user['username'] = $lang['guest'];
    191 }
    192 
    193 // include template/theme configuration
    194 if (defined('IN_ADMIN') and IN_ADMIN)
    195 {
    196   list($user['template'], $user['theme']) =
    197     explode
    198     (
    199       '/',
    200       isset($conf['default_admin_layout']) ? $conf['default_admin_layout']
    201                                            : $user['template']
    202     );
    203 // TODO : replace $conf['admin_layout'] by $user['admin_layout']
    204 }
    205 else
    206 {
    207   list($user['template'], $user['theme']) = explode('/', $user['template']);
    208 }
    209 // TODO : replace initial $user['template'] by $user['layout']
    210 
    211 include(
    212   PHPWG_ROOT_PATH
    213   .'template/'.$user['template']
    214   .'/theme/'.$user['theme']
    215   .'/themeconf.inc.php'
    216   );
     210      .'<a href="'.get_root_url().'upgrade_feed.php">upgrade now</a>';
     211  }
     212}
     213
    217214
    218215if (is_adviser())
     
    220217  $header_msgs[] = $lang['adviser_mode_enabled'];
    221218}
    222 
    223 // template instance
    224 $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);
    225219
    226220if (count($header_msgs) > 0)
  • branches/branch-1_6/include/config_default.inc.php

    r1554 r1572  
    324324// remember_me_length : time of validity for "remember me" cookies, in
    325325// seconds.
    326 $conf['remember_me_length'] = 31536000;
     326$conf['remember_me_length'] = 5184000;
     327
     328// session_length : time of validity for normal session, in seconds.
     329$conf['session_length'] = 3600;
    327330
    328331// +-----------------------------------------------------------------------+
  • branches/branch-1_6/include/functions.inc.php

    r1488 r1572  
    461461}
    462462
    463 function pwg_stripslashes($value) 
     463function pwg_stripslashes($value)
    464464{
    465465  if (get_magic_quotes_gpc())
     
    470470}
    471471
    472 function pwg_addslashes($value) 
     472function pwg_addslashes($value)
    473473{
    474474  if (!get_magic_quotes_gpc())
     
    479479}
    480480
    481 function pwg_quotemeta($value) 
     481function pwg_quotemeta($value)
    482482{
    483483  if (get_magic_quotes_gpc()) {
     
    557557 * @return void
    558558 */
    559 function redirect( $url , $msg = '', $refreh_time = 0)
     559function redirect( $url , $msg = '', $refresh_time = 0)
    560560{
    561561  global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug;
    562562
    563   unset($template);
    564   $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);
    565   if (!isset($page['body_id']))
    566   {
    567     $page['body_id'] = 'adminPage';
    568   }
    569 
    570   // $redirect_msg, $refresh, $url_link and $title are required for creating an automated
    571   // refresh page in header.tpl
    572   if (!isset($msg) or ($msg == ''))
     563  if (!isset($lang_info))
     564  {
     565    $user = build_user( $conf['guest_id'], true);
     566    include_once(get_language_filepath('common.lang.php'));
     567    list($tmpl, $thm) = explode('/', $conf['default_template']);
     568    $template = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl, $thm);
     569  }
     570  else
     571  {
     572    $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme']);
     573  }
     574
     575  if (empty($msg))
    573576  {
    574577    $redirect_msg = l10n('redirect_msg');
     
    579582  }
    580583  $redirect_msg = nl2br($redirect_msg);
    581   $refresh = $refreh_time;
     584
     585  $refresh = $refresh_time;
    582586  $url_link = $url;
    583587  $title = 'redirection';
    584588
     589  $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) );
     590
    585591  include( PHPWG_ROOT_PATH.'include/page_header.php' );
    586592
     
    592598  exit();
    593599}
    594 
    595600/**
    596601 * returns $_SERVER['QUERY_STRING'] whitout keys given in parameters
     
    694699{
    695700  global $conf;
    696  
     701
    697702  $error = '<pre>';
    698703  $error.= $header;
     
    880885function get_themeconf($key)
    881886{
    882   global $themeconf;
    883 
    884   return isset($themeconf[$key]) ? $themeconf[$key] : '';
     887  global $template;
     888
     889  return $template->get_themeconf($key);
    885890}
    886891
     
    939944{
    940945  global $conf;
    941  
     946
    942947  $query = '
    943948SELECT param,value
     
    954959  {
    955960    $conf[ $row['param'] ] = isset($row['value']) ? $row['value'] : '';
    956    
     961
    957962    // If the field is true or false, the variable is transformed into a
    958963    // boolean value.
  • branches/branch-1_6/include/functions_user.inc.php

    r1554 r1572  
    105105}
    106106
     107
     108function build_user( $user_id, $use_cache )
     109{
     110  global $conf;
     111  $user['id'] = $user_id;
     112  $user = array_merge( $user, getuserdata($user_id, $use_cache) );
     113  if ( $user['id'] == $conf['guest_id'])
     114  {
     115    $user['is_the_guest']=true;
     116    $user['template'] = $conf['default_template'];
     117    $user['nb_image_line'] = $conf['nb_image_line'];
     118    $user['nb_line_page'] = $conf['nb_line_page'];
     119    $user['language'] = $conf['default_language'];
     120    $user['maxwidth'] = $conf['default_maxwidth'];
     121    $user['maxheight'] = $conf['default_maxheight'];
     122    $user['recent_period'] = $conf['recent_period'];
     123    $user['expand'] = $conf['auto_expand'];
     124    $user['show_nb_comments'] = $conf['show_nb_comments'];
     125    $user['enabled_high'] = $conf['newuser_default_enabled_high'];
     126  }
     127  else
     128  {
     129    $user['is_the_guest']=false;
     130  }
     131  // calculation of the number of picture to display per page
     132  $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
     133
     134  // include template/theme configuration
     135  if (defined('IN_ADMIN') and IN_ADMIN)
     136  {
     137    list($user['template'], $user['theme']) =
     138      explode
     139      (
     140        '/',
     141        isset($conf['default_admin_layout']) ? $conf['default_admin_layout']
     142                                             : $user['template']
     143      );
     144    // TODO : replace $conf['admin_layout'] by $user['admin_layout']
     145  }
     146  else
     147  {
     148    list($user['template'], $user['theme']) = explode('/', $user['template']);
     149  }
     150
     151  return $user;
     152}
     153
     154
    107155/**
    108156 * find informations related to the user identifier
     
    459507    $status = 'normal';
    460508  }
    461  
     509
    462510  $insert =
    463511    array(
     
    557605    // search for an existing auto_login_key
    558606    $query = '
    559 SELECT auto_login_key 
     607SELECT auto_login_key
    560608  FROM '.USERS_TABLE.'
    561609  WHERE '.$conf['user_fields']['id'].' = '.$user_id.'
    562610;';
    563  
     611
    564612    $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
    565     if (empty($auto_login_key)) 
     613    if (empty($auto_login_key))
    566614    {
    567615      $auto_login_key = base64_encode(md5(uniqid(rand(), true)));
     
    575623    $cookie = array('id' => $user_id, 'key' => $auto_login_key);
    576624    setcookie($conf['remember_me_name'],
    577               serialize($cookie), 
     625              serialize($cookie),
    578626              time()+$conf['remember_me_length'],
    579627              cookie_path()
    580628              );
    581629  }
    582   session_start();
     630  else
     631  { // make sure we clean any remember me ...
     632    setcookie($conf['remember_me_name'], '', 0, cookie_path());
     633  }
     634  if ( session_id()!="" )
     635  { // this can happpen when the session is expired and auto_login
     636    session_regenerate_id();
     637  }
     638  else
     639  {
     640    session_start();
     641  }
    583642  $_SESSION['pwg_uid'] = $user_id;
    584643
    585644  $user['id'] = $_SESSION['pwg_uid'];
    586   $user['is_the_guest'] = false;
    587645}
    588646
    589647/*
    590648 * Performs auto-connexion when cookie remember_me exists
    591  * @return void
     649 * @return true/false
    592650*/
    593 function auto_login() { 
     651function auto_login() {
    594652  global $conf;
    595653
    596   // must remove slash added in include/common.inc.php
    597   $cookie = unserialize(stripslashes($_COOKIE[$conf['remember_me_name']]));
    598 
    599   $query = '
     654  if ( isset( $_COOKIE[$conf['remember_me_name']] ) )
     655  {
     656    // must remove slash added in include/common.inc.php
     657    $cookie = unserialize(stripslashes($_COOKIE[$conf['remember_me_name']]));
     658
     659    $query = '
    600660SELECT auto_login_key
    601661  FROM '.USERS_TABLE.'
     
    603663;';
    604664
    605   $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
    606   if ($auto_login_key == $cookie['key'])
    607   {
    608     log_user($cookie['id'], false);
    609     redirect(make_index_url());
    610   }
    611   else
    612   {
    613     setcookie($conf['remember_me_name'], '', 0, cookie_path());
    614     redirect(make_index_url());
    615   }
     665    $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
     666    if ($auto_login_key == $cookie['key'])
     667    {
     668      log_user($cookie['id'], true);
     669      return true;
     670    }
     671    else
     672    {
     673      setcookie($conf['remember_me_name'], '', 0, cookie_path());
     674    }
     675  }
     676  return false;
    616677}
    617678
  • branches/branch-1_6/include/template.php

    r1457 r1572  
    6060  var $output = '';
    6161
     62  var $themeconf = array();
     63
    6264  /**
    6365   * Constructor. Simply sets the root dir.
    6466   *
    6567   */
    66   function Template($root = ".")
    67     {
    68       $this->set_rootdir($root);
     68  function Template($root = ".", $theme= "")
     69    {
     70      if ( $this->set_rootdir($root) )
     71      {
     72        if ( !empty( $theme ) )
     73        {
     74          include($root.'/theme/'.$theme.'/themeconf.inc.php');
     75          $this->themeconf = $themeconf;
     76        }
     77      }
    6978    }
    7079
     
    312321        die("Template->loadfile(): File $filename for handle $handle is empty");
    313322      }
    314      
     323
    315324      $this->uncompiled_code[$handle] = $str;
    316      
    317       return true;
    318     }
    319  
    320  
    321  
     325
     326      return true;
     327    }
     328
     329
     330
    322331  /**
    323332   * Compiles the given string of code, and returns the result in a string.
     
    332341      $code = preg_replace('/\{lang:([^}]+)\}/e', "l10n('$1')", $code);
    333342      // PWG specific : expand themeconf.inc.php variables
    334       $code = preg_replace('/\{themeconf:([^}]+)\}/e', "get_themeconf('$1')", $code);
     343      $code = preg_replace('/\{themeconf:([^}]+)\}/e', '$this->get_themeconf(\'$1\')', $code);
    335344      $code = preg_replace('/\{pwg_root\}/e', "get_root_url()", $code);
    336345
     
    526535    }
    527536
     537    function get_themeconf($key)
     538    {
     539      return isset($this->themeconf[$key]) ? $this->themeconf[$key] : '';
     540    }
    528541}
    529542
  • branches/branch-1_6/include/user.inc.php

    r1554 r1572  
    33// | PhpWebGallery - a PHP based picture gallery                           |
    44// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
    5 // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
     5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
     
    2626// +-----------------------------------------------------------------------+
    2727
    28 if (isset($_COOKIE[session_name()]))
     28// by default we start with guest
     29$user['id'] = $conf['guest_id'];
     30
     31if (isset($_COOKIE[session_name()]))
    2932{
    3033  session_start();
    3134  if (isset($_GET['act']) and $_GET['act'] == 'logout')
    32   {
    33     // logout
     35  { // logout
    3436    $_SESSION = array();
    3537    session_unset();
    3638    session_destroy();
    3739    setcookie(session_name(),'',0,
    38               ini_get('session.cookie_path'),
    39               ini_get('session.cookie_domain')
    40               );
     40        ini_get('session.cookie_path'),
     41        ini_get('session.cookie_domain')
     42      );
    4143    setcookie($conf['remember_me_name'], '', 0, cookie_path());
    4244    redirect(make_index_url());
    43   }
    44   elseif (empty($_SESSION['pwg_uid']))
    45   {
    46     // timeout
     45  }
     46  elseif (empty($_SESSION['pwg_uid']))
     47  { // timeout
    4748    setcookie(session_name(),'',0,
    48               ini_get('session.cookie_path'),
    49               ini_get('session.cookie_domain')
    50               );
     49        ini_get('session.cookie_path'),
     50        ini_get('session.cookie_domain')
     51      );
    5152  }
    5253  else
    5354  {
    5455    $user['id'] = $_SESSION['pwg_uid'];
    55     $user['is_the_guest'] = false;
    5656  }
    5757}
    58 elseif (!empty($_COOKIE[$conf['remember_me_name']]))
     58
     59
     60// Now check the auto-login
     61if ( $user['id']==$conf['guest_id'] )
    5962{
    6063  auto_login();
    61 }
    62 else
    63 {
    64   $user['id'] = $conf['guest_id'];
    65   $user['is_the_guest'] = true;
    6664}
    6765
    68 if ($user['is_the_guest'] and !$conf['guest_access']
    69     and (basename($_SERVER['PHP_SELF'])!='identification.php')
    70     and (basename($_SERVER['PHP_SELF'])!='password.php')
    71     and (basename($_SERVER['PHP_SELF'])!='register.php'))
    72 {
    73   redirect (get_root_url().'identification.php');
    74 }
    7566
    7667// using Apache authentication override the above user search
     
    8273    $user['id'] = get_userid($_SERVER['REMOTE_USER']);
    8374  }
    84  
    85   $user['is_the_guest'] = false;
    8675}
     76$user = build_user( $user['id'],
     77          ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
     78         );
    8779
    88 $user = array_merge(
    89   $user,
    90   getuserdata(
    91     $user['id'],
    92     ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
    93     )
    94   );
    95 
    96 // properties of user guest are found in the configuration
    97 if ($user['is_the_guest'])
    98 {
    99   $user['template'] = $conf['default_template'];
    100   $user['nb_image_line'] = $conf['nb_image_line'];
    101   $user['nb_line_page'] = $conf['nb_line_page'];
    102   $user['language'] = $conf['default_language'];
    103   $user['maxwidth'] = $conf['default_maxwidth'];
    104   $user['maxheight'] = $conf['default_maxheight'];
    105   $user['recent_period'] = $conf['recent_period'];
    106   $user['expand'] = $conf['auto_expand'];
    107   $user['show_nb_comments'] = $conf['show_nb_comments'];
    108   $user['enabled_high'] = $conf['newuser_default_enabled_high'];
    109 }
    110 
    111 // calculation of the number of picture to display per page
    112 $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
    11380?>
Note: See TracChangeset for help on using the changeset viewer.