Changeset 1568


Ignore:
Timestamp:
Oct 20, 2006, 4:17:53 AM (18 years ago)
Author:
rvelices
Message:

used in the code (generates mysql errors on session garbage collector)

  • fix auto_login (die mysql when session timed out, but user has remember)
  • when a user reconnects from identification.php, the remember cookie was not

deleted

  • fix all redirect warnings/errors (many changes - mainly in common.inc.php

and user.inc.php)

login the 60 days countdown restarts

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/identification.php

    r1565 r1568  
    7373  }
    7474}
    75 elseif (!empty($_COOKIE[$conf['remember_me_name']]))
    76 {
    77   auto_login();
    78 }
     75
    7976//----------------------------------------------------- template initialization
    8077//
  • trunk/include/common.inc.php

    r1502 r1568  
    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}
    217213
    218214if (is_adviser())
     
    220216  $header_msgs[] = $lang['adviser_mode_enabled'];
    221217}
    222 
    223 // template instance
    224 $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);
    225218
    226219if (count($header_msgs) > 0)
  • trunk/include/config_default.inc.php

    r1566 r1568  
    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// +-----------------------------------------------------------------------+
  • trunk/include/functions.inc.php

    r1567 r1568  
    585585  global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug;
    586586
    587   if (!isset($lang_info)) {
     587  if (!isset($lang_info))
     588  {
     589    $user = build_user( $conf['guest_id'], true);
    588590    include_once(get_language_filepath('common.lang.php'));
     591    list($tmpl, $thm) = explode('/', $conf['default_template']);
     592    $template = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl, $thm);
     593  }
     594  else
     595  {
     596    $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme']);
    589597  }
    590598
     
    602610  $url_link = $url;
    603611  $title = 'redirection';
    604 
    605   unset($template);
    606   if ( isset($user['template']) )
    607   {
    608     $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);
    609   }
    610   else
    611   {
    612     list($tmpl, $thm) = explode('/', $conf['default_template']);
    613     global $themeconf;
    614     include(
    615       PHPWG_ROOT_PATH
    616       .'template/'.$tmpl
    617       .'/theme/'.$thm
    618       .'/themeconf.inc.php'
    619       );
    620     $template = new Template(PHPWG_ROOT_PATH.'template/'.$tmpl);
    621     $user['is_the_guest']=true;
    622     $user['id']=$conf['guest_id'];
    623   }
    624612
    625613  $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) );
     
    922910function get_themeconf($key)
    923911{
    924   global $themeconf;
    925 
    926   return isset($themeconf[$key]) ? $themeconf[$key] : '';
     912  global $template;
     913
     914  return $template->get_themeconf($key);
    927915}
    928916
  • trunk/include/functions_user.inc.php

    r1567 r1568  
    105105}
    106106
     107function build_user( $user_id, $use_cache )
     108{
     109  global $conf;
     110  $user['id'] = $user_id;
     111  $user = array_merge( $user, getuserdata($user_id, $use_cache) );
     112  if ( $user['id'] == $conf['guest_id'])
     113  {
     114    $user['is_the_guest']=true;
     115    $user['template'] = $conf['default_template'];
     116    $user['nb_image_line'] = $conf['nb_image_line'];
     117    $user['nb_line_page'] = $conf['nb_line_page'];
     118    $user['language'] = $conf['default_language'];
     119    $user['maxwidth'] = $conf['default_maxwidth'];
     120    $user['maxheight'] = $conf['default_maxheight'];
     121    $user['recent_period'] = $conf['recent_period'];
     122    $user['expand'] = $conf['auto_expand'];
     123    $user['show_nb_comments'] = $conf['show_nb_comments'];
     124    $user['enabled_high'] = $conf['newuser_default_enabled_high'];
     125  }
     126  else
     127  {
     128    $user['is_the_guest']=false;
     129  }
     130  // calculation of the number of picture to display per page
     131  $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
     132
     133  // include template/theme configuration
     134  if (defined('IN_ADMIN') and IN_ADMIN)
     135  {
     136    list($user['template'], $user['theme']) =
     137      explode
     138      (
     139        '/',
     140        isset($conf['default_admin_layout']) ? $conf['default_admin_layout']
     141                                             : $user['template']
     142      );
     143    // TODO : replace $conf['admin_layout'] by $user['admin_layout']
     144  }
     145  else
     146  {
     147    list($user['template'], $user['theme']) = explode('/', $user['template']);
     148  }
     149
     150  return $user;
     151}
     152
    107153/**
    108154 * find informations related to the user identifier
     
    581627              );
    582628  }
    583   session_start();
     629  else
     630  { // make sure we clean any remember me ...
     631    setcookie($conf['remember_me_name'], '', 0, cookie_path());
     632  }
     633  if ( session_id()!="" )
     634  { // this can happpen when the session is expired and auto_login
     635    session_regenerate_id();
     636  }
     637  else
     638  {
     639    session_start();
     640  }
    584641  $_SESSION['pwg_uid'] = $user_id;
    585642
    586643  $user['id'] = $_SESSION['pwg_uid'];
    587   $user['is_the_guest'] = false;
    588644}
    589645
    590646/*
    591647 * Performs auto-connexion when cookie remember_me exists
    592  * @return void
     648 * @return true/false
    593649*/
    594650function auto_login() {
    595651  global $conf;
    596652
    597   // must remove slash added in include/common.inc.php
    598   $cookie = unserialize(stripslashes($_COOKIE[$conf['remember_me_name']]));
    599 
    600   $query = '
     653  if ( isset( $_COOKIE[$conf['remember_me_name']] ) )
     654  {
     655    // must remove slash added in include/common.inc.php
     656    $cookie = unserialize(stripslashes($_COOKIE[$conf['remember_me_name']]));
     657
     658    $query = '
    601659SELECT auto_login_key
    602660  FROM '.USERS_TABLE.'
     
    604662;';
    605663
    606   $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
    607   if ($auto_login_key == $cookie['key'])
    608   {
    609     log_user($cookie['id'], false);
    610     redirect(make_index_url());
    611   }
    612   else
    613   {
    614     setcookie($conf['remember_me_name'], '', 0, cookie_path());
    615     redirect(make_index_url());
    616   }
     664    $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
     665    if ($auto_login_key == $cookie['key'])
     666    {
     667      log_user($cookie['id'], true);
     668      return true;
     669    }
     670    else
     671    {
     672      setcookie($conf['remember_me_name'], '', 0, cookie_path());
     673    }
     674  }
     675  return false;
    617676}
    618677
  • trunk/include/template.php

    r1456 r1568  
    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
  • trunk/include/user.inc.php

    r1524 r1568  
    2626// +-----------------------------------------------------------------------+
    2727
     28// by default we start with guest
     29$user['id'] = $conf['guest_id'];
     30
    2831if (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  }
     75}
     76$user = build_user( $user['id'],
     77          ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
     78         );
    8479
    85   $user['is_the_guest'] = false;
    86 }
    87 
    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.