Changeset 1568
- Timestamp:
- Oct 20, 2006, 4:17:53 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/identification.php
r1565 r1568 73 73 } 74 74 } 75 elseif (!empty($_COOKIE[$conf['remember_me_name']])) 76 { 77 auto_login(); 78 } 75 79 76 //----------------------------------------------------- template initialization 80 77 // -
trunk/include/common.inc.php
r1502 r1568 133 133 or die ( "Could not connect to database" ); 134 134 135 // 136 // Setup gallery wide options, if this fails then we output a CRITICAL_ERROR 137 // since basic gallery information is not available 138 // 139 load_conf_from_db(); 140 141 include(PHPWG_ROOT_PATH.'include/user.inc.php'); 142 143 144 // language files 145 include_once(get_language_filepath('common.lang.php')); 146 if (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) 153 if ($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 161 if ($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 176 if ($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 135 190 if ($conf['check_upgrade_feed'] 136 191 and defined('PHPWG_IN_UPGRADE') … … 150 205 if (count(array_diff($existing, $applied)) > 0) 151 206 { 207 //next line required if PATH_INFO (no ? in url) but won't work for scripts outside PWG 208 $page['root_path'] = cookie_path(); 152 209 $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 } 217 213 218 214 if (is_adviser()) … … 220 216 $header_msgs[] = $lang['adviser_mode_enabled']; 221 217 } 222 223 // template instance224 $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);225 218 226 219 if (count($header_msgs) > 0) -
trunk/include/config_default.inc.php
r1566 r1568 324 324 // remember_me_length : time of validity for "remember me" cookies, in 325 325 // 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; 327 330 328 331 // +-----------------------------------------------------------------------+ -
trunk/include/functions.inc.php
r1567 r1568 585 585 global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug; 586 586 587 if (!isset($lang_info)) { 587 if (!isset($lang_info)) 588 { 589 $user = build_user( $conf['guest_id'], true); 588 590 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']); 589 597 } 590 598 … … 602 610 $url_link = $url; 603 611 $title = 'redirection'; 604 605 unset($template);606 if ( isset($user['template']) )607 {608 $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);609 }610 else611 {612 list($tmpl, $thm) = explode('/', $conf['default_template']);613 global $themeconf;614 include(615 PHPWG_ROOT_PATH616 .'template/'.$tmpl617 .'/theme/'.$thm618 .'/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 }624 612 625 613 $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) ); … … 922 910 function get_themeconf($key) 923 911 { 924 global $t hemeconf;925 926 return isset($themeconf[$key]) ? $themeconf[$key] : '';912 global $template; 913 914 return $template->get_themeconf($key); 927 915 } 928 916 -
trunk/include/functions_user.inc.php
r1567 r1568 105 105 } 106 106 107 function 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 107 153 /** 108 154 * find informations related to the user identifier … … 581 627 ); 582 628 } 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 } 584 641 $_SESSION['pwg_uid'] = $user_id; 585 642 586 643 $user['id'] = $_SESSION['pwg_uid']; 587 $user['is_the_guest'] = false;588 644 } 589 645 590 646 /* 591 647 * Performs auto-connexion when cookie remember_me exists 592 * @return void648 * @return true/false 593 649 */ 594 650 function auto_login() { 595 651 global $conf; 596 652 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 = ' 601 659 SELECT auto_login_key 602 660 FROM '.USERS_TABLE.' … … 604 662 ;'; 605 663 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; 617 676 } 618 677 -
trunk/include/template.php
r1456 r1568 60 60 var $output = ''; 61 61 62 var $themeconf = array(); 63 62 64 /** 63 65 * Constructor. Simply sets the root dir. 64 66 * 65 67 */ 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 } 69 78 } 70 79 … … 312 321 die("Template->loadfile(): File $filename for handle $handle is empty"); 313 322 } 314 323 315 324 $this->uncompiled_code[$handle] = $str; 316 317 return true; 318 } 319 320 321 325 326 return true; 327 } 328 329 330 322 331 /** 323 332 * Compiles the given string of code, and returns the result in a string. … … 332 341 $code = preg_replace('/\{lang:([^}]+)\}/e', "l10n('$1')", $code); 333 342 // 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); 335 344 $code = preg_replace('/\{pwg_root\}/e', "get_root_url()", $code); 336 345 … … 526 535 } 527 536 537 function get_themeconf($key) 538 { 539 return isset($this->themeconf[$key]) ? $this->themeconf[$key] : ''; 540 } 528 541 } 529 542 -
trunk/include/user.inc.php
r1524 r1568 26 26 // +-----------------------------------------------------------------------+ 27 27 28 // by default we start with guest 29 $user['id'] = $conf['guest_id']; 30 28 31 if (isset($_COOKIE[session_name()])) 29 32 { 30 33 session_start(); 31 34 if (isset($_GET['act']) and $_GET['act'] == 'logout') 32 { 33 // logout 35 { // logout 34 36 $_SESSION = array(); 35 37 session_unset(); 36 38 session_destroy(); 37 39 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 ); 41 43 setcookie($conf['remember_me_name'], '', 0, cookie_path()); 42 44 redirect(make_index_url()); 43 } 44 elseif (empty($_SESSION['pwg_uid'])) 45 { 46 // timeout 45 } 46 elseif (empty($_SESSION['pwg_uid'])) 47 { // timeout 47 48 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 ); 51 52 } 52 53 else 53 54 { 54 55 $user['id'] = $_SESSION['pwg_uid']; 55 $user['is_the_guest'] = false;56 56 } 57 57 } 58 elseif (!empty($_COOKIE[$conf['remember_me_name']])) 58 59 60 // Now check the auto-login 61 if ( $user['id']==$conf['guest_id'] ) 59 62 { 60 63 auto_login(); 61 }62 else63 {64 $user['id'] = $conf['guest_id'];65 $user['is_the_guest'] = true;66 64 } 67 65 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 }75 66 76 67 // using Apache authentication override the above user search … … 82 73 $user['id'] = get_userid($_SERVER['REMOTE_USER']); 83 74 } 75 } 76 $user = build_user( $user['id'], 77 ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ? 78 ); 84 79 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 configuration97 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 page112 $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];113 80 ?>
Note: See TracChangeset
for help on using the changeset viewer.