Project

General

Profile

1
<?php
2

    
3
/*
4

    
5
 Website Baker Project <http://www.websitebaker.org/>
6
 Copyright (C) 2004-2005, Ryan Djurovich
7

    
8
 Website Baker is free software; you can redistribute it and/or modify
9
 it under the terms of the GNU General Public License as published by
10
 the Free Software Foundation; either version 2 of the License, or
11
 (at your option) any later version.
12

    
13
 Website Baker is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 GNU General Public License for more details.
17

    
18
 You should have received a copy of the GNU General Public License
19
 along with Website Baker; if not, write to the Free Software
20
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21

    
22
*/
23

    
24
/*
25

    
26
wb class
27

    
28
This class is the basis for admin and frontend classes.
29

    
30
*/
31

    
32

    
33
class wb
34
{
35
	function wb() {
36
	}
37

    
38
	// Check whether we should show a page or not (for front-end)
39
	function show_page($page) {
40
		// First check if the page is set to private
41
		if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
42
			// Check if the user is logged in
43
			if($this->is_authenticated() == true) {
44
				// Now check if the user has perms to view it
45
				$viewing_groups = explode(',', $page['viewing_groups']);
46
				$viewing_users = explode(',', $page['viewing_users']);
47
				if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
48
					return true;
49
				} else {
50
					return false;
51
				}
52
			} else {
53
				return false;
54
			}
55
		} elseif($page['visibility'] == 'public') {
56
			return true;
57
		} else {
58
			return false;
59
		}
60
	}
61

    
62
	// Check if the user is already authenticated or not
63
	function is_authenticated() {
64
		if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
65
			return true;
66
		} else {
67
			return false;
68
		}
69
	}
70

    
71
	// Get POST data
72
	function get_post($field) {
73
		if(isset($_POST[$field])) {
74
			return $_POST[$field];
75
		} else {
76
			return null;
77
		}
78
	}
79

    
80
	// Get GET data
81
	function get_get($field) {
82
		if(isset($_GET[$field])) {
83
			return $_GET[$field];
84
		} else {
85
			return null;
86
		}
87
	}
88

    
89
	// Get SESSION data
90
	function get_session($field) {
91
		if(isset($_SESSION[$field])) {
92
			return $_SESSION[$field];
93
		} else {
94
			return null;
95
		}
96
	}
97

    
98
	// Get SERVER data
99
	function get_server($field) {
100
		if(isset($_SERVER[$field])) {
101
			return $_SERVER[$field];
102
		} else {
103
			return null;
104
		}
105
	}
106

    
107
	// Get the current users id
108
	function get_user_id() {
109
		return $_SESSION['USER_ID'];
110
	}
111

    
112
	// Get the current users group id
113
	function get_group_id() {
114
		return $_SESSION['GROUP_ID'];
115
	}
116

    
117
	// Get the current users group name
118
	function get_group_name() {
119
		return $_SESSION['GROUP_NAME'];
120
	}
121

    
122
	// Get the current users username
123
	function get_username() {
124
		return $_SESSION['USERNAME'];
125
	}
126

    
127
	// Get the current users display name
128
	function get_display_name() {
129
		return stripslashes($_SESSION['DISPLAY_NAME']);
130
	}
131

    
132
	// Get the current users email address
133
	function get_email() {
134
		return $_SESSION['EMAIL'];
135
	}
136

    
137
	// Get the current users home folder
138
	function get_home_folder() {
139
		return $_SESSION['HOME_FOLDER'];
140
	}
141

    
142
	// Get the current users timezone
143
	function get_timezone() {
144
		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
145
			return $_SESSION['TIMEZONE'];
146
		} else {
147
			return '-72000';
148
		}
149
	}
150

    
151
	// Validate supplied email address
152
	function validate_email($email) {
153
		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
154
			return true;
155
		} else {
156
			return false;
157
		}
158
	}
159

    
160
	
161
}
162
?>
(6-6/11)