Changeset 1572
- Timestamp:
- Oct 21, 2006, 10:16:01 PM (18 years ago)
- Location:
- branches/branch-1_6
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1_6/identification.php
r1554 r1572 72 72 } 73 73 } 74 elseif (!empty($_COOKIE[$conf['remember_me_name']])) 75 { 76 auto_login(); 77 } 74 78 75 //----------------------------------------------------- template initialization 79 76 // -
branches/branch-1_6/include/common.inc.php
r1501 r1572 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 } 213 217 214 218 215 if (is_adviser()) … … 220 217 $header_msgs[] = $lang['adviser_mode_enabled']; 221 218 } 222 223 // template instance224 $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);225 219 226 220 if (count($header_msgs) > 0) -
branches/branch-1_6/include/config_default.inc.php
r1554 r1572 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 // +-----------------------------------------------------------------------+ -
branches/branch-1_6/include/functions.inc.php
r1488 r1572 461 461 } 462 462 463 function pwg_stripslashes($value) 463 function pwg_stripslashes($value) 464 464 { 465 465 if (get_magic_quotes_gpc()) … … 470 470 } 471 471 472 function pwg_addslashes($value) 472 function pwg_addslashes($value) 473 473 { 474 474 if (!get_magic_quotes_gpc()) … … 479 479 } 480 480 481 function pwg_quotemeta($value) 481 function pwg_quotemeta($value) 482 482 { 483 483 if (get_magic_quotes_gpc()) { … … 557 557 * @return void 558 558 */ 559 function redirect( $url , $msg = '', $refre h_time = 0)559 function redirect( $url , $msg = '', $refresh_time = 0) 560 560 { 561 561 global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug; 562 562 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)) 573 576 { 574 577 $redirect_msg = l10n('redirect_msg'); … … 579 582 } 580 583 $redirect_msg = nl2br($redirect_msg); 581 $refresh = $refreh_time; 584 585 $refresh = $refresh_time; 582 586 $url_link = $url; 583 587 $title = 'redirection'; 584 588 589 $template->set_filenames( array( 'redirect' => 'redirect.tpl' ) ); 590 585 591 include( PHPWG_ROOT_PATH.'include/page_header.php' ); 586 592 … … 592 598 exit(); 593 599 } 594 595 600 /** 596 601 * returns $_SERVER['QUERY_STRING'] whitout keys given in parameters … … 694 699 { 695 700 global $conf; 696 701 697 702 $error = '<pre>'; 698 703 $error.= $header; … … 880 885 function get_themeconf($key) 881 886 { 882 global $t hemeconf;883 884 return isset($themeconf[$key]) ? $themeconf[$key] : '';887 global $template; 888 889 return $template->get_themeconf($key); 885 890 } 886 891 … … 939 944 { 940 945 global $conf; 941 946 942 947 $query = ' 943 948 SELECT param,value … … 954 959 { 955 960 $conf[ $row['param'] ] = isset($row['value']) ? $row['value'] : ''; 956 961 957 962 // If the field is true or false, the variable is transformed into a 958 963 // boolean value. -
branches/branch-1_6/include/functions_user.inc.php
r1554 r1572 105 105 } 106 106 107 108 function 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 107 155 /** 108 156 * find informations related to the user identifier … … 459 507 $status = 'normal'; 460 508 } 461 509 462 510 $insert = 463 511 array( … … 557 605 // search for an existing auto_login_key 558 606 $query = ' 559 SELECT auto_login_key 607 SELECT auto_login_key 560 608 FROM '.USERS_TABLE.' 561 609 WHERE '.$conf['user_fields']['id'].' = '.$user_id.' 562 610 ;'; 563 611 564 612 $auto_login_key = current(mysql_fetch_assoc(pwg_query($query))); 565 if (empty($auto_login_key)) 613 if (empty($auto_login_key)) 566 614 { 567 615 $auto_login_key = base64_encode(md5(uniqid(rand(), true))); … … 575 623 $cookie = array('id' => $user_id, 'key' => $auto_login_key); 576 624 setcookie($conf['remember_me_name'], 577 serialize($cookie), 625 serialize($cookie), 578 626 time()+$conf['remember_me_length'], 579 627 cookie_path() 580 628 ); 581 629 } 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 } 583 642 $_SESSION['pwg_uid'] = $user_id; 584 643 585 644 $user['id'] = $_SESSION['pwg_uid']; 586 $user['is_the_guest'] = false;587 645 } 588 646 589 647 /* 590 648 * Performs auto-connexion when cookie remember_me exists 591 * @return void649 * @return true/false 592 650 */ 593 function auto_login() { 651 function auto_login() { 594 652 global $conf; 595 653 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 = ' 600 660 SELECT auto_login_key 601 661 FROM '.USERS_TABLE.' … … 603 663 ;'; 604 664 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; 616 677 } 617 678 -
branches/branch-1_6/include/template.php
r1457 r1572 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 -
branches/branch-1_6/include/user.inc.php
r1554 r1572 3 3 // | PhpWebGallery - a PHP based picture gallery | 4 4 // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | 5 // | Copyright (C) 2003-200 5PhpWebGallery Team - http://phpwebgallery.net |5 // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | 6 6 // +-----------------------------------------------------------------------+ 7 7 // | branch : BSF (Best So Far) … … 26 26 // +-----------------------------------------------------------------------+ 27 27 28 if (isset($_COOKIE[session_name()])) 28 // by default we start with guest 29 $user['id'] = $conf['guest_id']; 30 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 } 84 85 $user['is_the_guest'] = false;86 75 } 76 $user = build_user( $user['id'], 77 ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ? 78 ); 87 79 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.