| 1 | 5 | stefan | <?php
 | 
      
        | 2 |  |  | 
 | 
      
        | 3 | 11 | ryan | // $Id$
 | 
      
        | 4 |  |  | 
 | 
      
        | 5 | 5 | stefan | /*
 | 
      
        | 6 |  |  | 
 | 
      
        | 7 |  |  |  Website Baker Project <http://www.websitebaker.org/>
 | 
      
        | 8 |  |  |  Copyright (C) 2004-2005, Ryan Djurovich
 | 
      
        | 9 |  |  | 
 | 
      
        | 10 |  |  |  Website Baker is free software; you can redistribute it and/or modify
 | 
      
        | 11 |  |  |  it under the terms of the GNU General Public License as published by
 | 
      
        | 12 |  |  |  the Free Software Foundation; either version 2 of the License, or
 | 
      
        | 13 |  |  |  (at your option) any later version.
 | 
      
        | 14 |  |  | 
 | 
      
        | 15 |  |  |  Website Baker is distributed in the hope that it will be useful,
 | 
      
        | 16 |  |  |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
      
        | 17 |  |  |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
      
        | 18 |  |  |  GNU General Public License for more details.
 | 
      
        | 19 |  |  | 
 | 
      
        | 20 |  |  |  You should have received a copy of the GNU General Public License
 | 
      
        | 21 |  |  |  along with Website Baker; if not, write to the Free Software
 | 
      
        | 22 |  |  |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
      
        | 23 |  |  | 
 | 
      
        | 24 |  |  | */
 | 
      
        | 25 |  |  | 
 | 
      
        | 26 |  |  | /*
 | 
      
        | 27 |  |  | 
 | 
      
        | 28 |  |  | wb class
 | 
      
        | 29 |  |  | 
 | 
      
        | 30 |  |  | This class is the basis for admin and frontend classes.
 | 
      
        | 31 |  |  | 
 | 
      
        | 32 |  |  | */
 | 
      
        | 33 |  |  | 
 | 
      
        | 34 | 106 | stefan | require_once(WB_PATH.'/framework/class.database.php');
 | 
      
        | 35 |  |  | 
 | 
      
        | 36 | 5 | stefan | class wb
 | 
      
        | 37 | 95 | stefan | {
 | 
      
        | 38 | 55 | stefan | 	// General initialization function
 | 
      
        | 39 | 238 | stefan | 	// performed when frontend or backend is loaded.
 | 
      
        | 40 | 55 | stefan | 	function wb() {
 | 
      
        | 41 | 238 | stefan | 	}
 | 
      
        | 42 |  |  | 
 | 
      
        | 43 | 5 | stefan | 	// Check whether we should show a page or not (for front-end)
 | 
      
        | 44 |  |  | 	function show_page($page) {
 | 
      
        | 45 |  |  | 		// First check if the page is set to private
 | 
      
        | 46 |  |  | 		if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
 | 
      
        | 47 |  |  | 			// Check if the user is logged in
 | 
      
        | 48 |  |  | 			if($this->is_authenticated() == true) {
 | 
      
        | 49 |  |  | 				// Now check if the user has perms to view it
 | 
      
        | 50 |  |  | 				$viewing_groups = explode(',', $page['viewing_groups']);
 | 
      
        | 51 |  |  | 				$viewing_users = explode(',', $page['viewing_users']);
 | 
      
        | 52 |  |  | 				if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
 | 
      
        | 53 |  |  | 					return true;
 | 
      
        | 54 |  |  | 				} else {
 | 
      
        | 55 |  |  | 					return false;
 | 
      
        | 56 |  |  | 				}
 | 
      
        | 57 |  |  | 			} else {
 | 
      
        | 58 |  |  | 				return false;
 | 
      
        | 59 |  |  | 			}
 | 
      
        | 60 |  |  | 		} elseif($page['visibility'] == 'public') {
 | 
      
        | 61 |  |  | 			return true;
 | 
      
        | 62 |  |  | 		} else {
 | 
      
        | 63 |  |  | 			return false;
 | 
      
        | 64 |  |  | 		}
 | 
      
        | 65 |  |  | 	}
 | 
      
        | 66 |  |  | 
 | 
      
        | 67 |  |  | 	// Check if the user is already authenticated or not
 | 
      
        | 68 |  |  | 	function is_authenticated() {
 | 
      
        | 69 |  |  | 		if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
 | 
      
        | 70 |  |  | 			return true;
 | 
      
        | 71 |  |  | 		} else {
 | 
      
        | 72 |  |  | 			return false;
 | 
      
        | 73 |  |  | 		}
 | 
      
        | 74 |  |  | 	}
 | 
      
        | 75 | 238 | stefan | 	// Modified addslashes function which takes into account magic_quotes
 | 
      
        | 76 |  |  | 	function add_slashes($input) {
 | 
      
        | 77 | 38 | stefan | 		if ( get_magic_quotes_gpc() || ( !is_string($input) ) ) {
 | 
      
        | 78 |  |  | 			return $input;
 | 
      
        | 79 |  |  | 		}
 | 
      
        | 80 | 40 | stefan | 		$output = addslashes($input);
 | 
      
        | 81 | 38 | stefan | 		return $output;
 | 
      
        | 82 |  |  | 	}
 | 
      
        | 83 | 5 | stefan | 
 | 
      
        | 84 | 238 | stefan | 	// Ditto for stripslashes
 | 
      
        | 85 | 40 | stefan | 	function strip_slashes($input) {
 | 
      
        | 86 | 36 | stefan | 		if ( !get_magic_quotes_gpc() || ( !is_string($input) ) ) {
 | 
      
        | 87 |  |  | 			return $input;
 | 
      
        | 88 |  |  | 		}
 | 
      
        | 89 |  |  | 		$output = stripslashes($input);
 | 
      
        | 90 |  |  | 		return $output;
 | 
      
        | 91 |  |  | 	}
 | 
      
        | 92 |  |  | 
 | 
      
        | 93 | 238 | stefan | 	// Escape backslashes for use with mySQL LIKE strings
 | 
      
        | 94 | 38 | stefan | 	function escape_backslashes($input) {
 | 
      
        | 95 | 42 | stefan | 		return str_replace("\\","\\\\",$input);
 | 
      
        | 96 | 38 | stefan | 	}
 | 
      
        | 97 |  |  | 
 | 
      
        | 98 | 5 | stefan | 	// Get POST data
 | 
      
        | 99 |  |  | 	function get_post($field) {
 | 
      
        | 100 |  |  | 		if(isset($_POST[$field])) {
 | 
      
        | 101 |  |  | 			return $_POST[$field];
 | 
      
        | 102 |  |  | 		} else {
 | 
      
        | 103 |  |  | 			return null;
 | 
      
        | 104 |  |  | 		}
 | 
      
        | 105 |  |  | 	}
 | 
      
        | 106 |  |  | 
 | 
      
        | 107 |  |  | 	// Get GET data
 | 
      
        | 108 |  |  | 	function get_get($field) {
 | 
      
        | 109 |  |  | 		if(isset($_GET[$field])) {
 | 
      
        | 110 |  |  | 			return $_GET[$field];
 | 
      
        | 111 |  |  | 		} else {
 | 
      
        | 112 |  |  | 			return null;
 | 
      
        | 113 |  |  | 		}
 | 
      
        | 114 |  |  | 	}
 | 
      
        | 115 |  |  | 
 | 
      
        | 116 |  |  | 	// Get SESSION data
 | 
      
        | 117 |  |  | 	function get_session($field) {
 | 
      
        | 118 |  |  | 		if(isset($_SESSION[$field])) {
 | 
      
        | 119 |  |  | 			return $_SESSION[$field];
 | 
      
        | 120 |  |  | 		} else {
 | 
      
        | 121 |  |  | 			return null;
 | 
      
        | 122 |  |  | 		}
 | 
      
        | 123 |  |  | 	}
 | 
      
        | 124 |  |  | 
 | 
      
        | 125 |  |  | 	// Get SERVER data
 | 
      
        | 126 |  |  | 	function get_server($field) {
 | 
      
        | 127 |  |  | 		if(isset($_SERVER[$field])) {
 | 
      
        | 128 |  |  | 			return $_SERVER[$field];
 | 
      
        | 129 |  |  | 		} else {
 | 
      
        | 130 |  |  | 			return null;
 | 
      
        | 131 |  |  | 		}
 | 
      
        | 132 |  |  | 	}
 | 
      
        | 133 |  |  | 
 | 
      
        | 134 |  |  | 	// Get the current users id
 | 
      
        | 135 |  |  | 	function get_user_id() {
 | 
      
        | 136 |  |  | 		return $_SESSION['USER_ID'];
 | 
      
        | 137 |  |  | 	}
 | 
      
        | 138 |  |  | 
 | 
      
        | 139 |  |  | 	// Get the current users group id
 | 
      
        | 140 |  |  | 	function get_group_id() {
 | 
      
        | 141 |  |  | 		return $_SESSION['GROUP_ID'];
 | 
      
        | 142 |  |  | 	}
 | 
      
        | 143 |  |  | 
 | 
      
        | 144 |  |  | 	// Get the current users group name
 | 
      
        | 145 |  |  | 	function get_group_name() {
 | 
      
        | 146 |  |  | 		return $_SESSION['GROUP_NAME'];
 | 
      
        | 147 |  |  | 	}
 | 
      
        | 148 |  |  | 
 | 
      
        | 149 |  |  | 	// Get the current users username
 | 
      
        | 150 |  |  | 	function get_username() {
 | 
      
        | 151 |  |  | 		return $_SESSION['USERNAME'];
 | 
      
        | 152 |  |  | 	}
 | 
      
        | 153 |  |  | 
 | 
      
        | 154 |  |  | 	// Get the current users display name
 | 
      
        | 155 |  |  | 	function get_display_name() {
 | 
      
        | 156 | 106 | stefan | 		return ($_SESSION['DISPLAY_NAME']);
 | 
      
        | 157 | 5 | stefan | 	}
 | 
      
        | 158 |  |  | 
 | 
      
        | 159 |  |  | 	// Get the current users email address
 | 
      
        | 160 |  |  | 	function get_email() {
 | 
      
        | 161 |  |  | 		return $_SESSION['EMAIL'];
 | 
      
        | 162 |  |  | 	}
 | 
      
        | 163 |  |  | 
 | 
      
        | 164 |  |  | 	// Get the current users home folder
 | 
      
        | 165 |  |  | 	function get_home_folder() {
 | 
      
        | 166 |  |  | 		return $_SESSION['HOME_FOLDER'];
 | 
      
        | 167 |  |  | 	}
 | 
      
        | 168 |  |  | 
 | 
      
        | 169 |  |  | 	// Get the current users timezone
 | 
      
        | 170 |  |  | 	function get_timezone() {
 | 
      
        | 171 |  |  | 		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
 | 
      
        | 172 |  |  | 			return $_SESSION['TIMEZONE'];
 | 
      
        | 173 |  |  | 		} else {
 | 
      
        | 174 |  |  | 			return '-72000';
 | 
      
        | 175 |  |  | 		}
 | 
      
        | 176 |  |  | 	}
 | 
      
        | 177 |  |  | 
 | 
      
        | 178 |  |  | 	// Validate supplied email address
 | 
      
        | 179 |  |  | 	function validate_email($email) {
 | 
      
        | 180 |  |  | 		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
 | 
      
        | 181 |  |  | 			return true;
 | 
      
        | 182 |  |  | 		} else {
 | 
      
        | 183 |  |  | 			return false;
 | 
      
        | 184 |  |  | 		}
 | 
      
        | 185 |  |  | 	}
 | 
      
        | 186 |  |  | 
 | 
      
        | 187 |  |  | 
 | 
      
        | 188 |  |  | }
 | 
      
        | 189 |  |  | ?>
 |