2 |
2 |
/**
|
3 |
3 |
*
|
4 |
4 |
* @category framework
|
5 |
|
* @package frontend
|
|
5 |
* @package frontend
|
6 |
6 |
* @author Ryan Djurovich, WebsiteBaker Project
|
7 |
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
|
7 |
* @copyright 2009-2012, WebsiteBaker Org. e.V.
|
8 |
8 |
* @link http://www.websitebaker2.org/
|
9 |
9 |
* @license http://www.gnu.org/licenses/gpl.html
|
10 |
10 |
* @platform WebsiteBaker 2.8.x
|
... | ... | |
46 |
46 |
* @param array &$matches: an array-var whitch will return possible matches
|
47 |
47 |
* @return bool: true there is a match, otherwise false
|
48 |
48 |
*/
|
49 |
|
function is_group_match( $groups_list1 = '', $groups_list2 = '', &$matches = null )
|
|
49 |
public function is_group_match( $groups_list1 = '', $groups_list2 = '', &$matches = null )
|
50 |
50 |
{
|
51 |
51 |
if( $groups_list1 == '' ) { return false; }
|
52 |
52 |
if( $groups_list2 == '' ) { return false; }
|
... | ... | |
69 |
69 |
* @param mixed $groups_list: an array or a coma seperated list of group-ids
|
70 |
70 |
* @return bool: true if current user is member of one of this groups, otherwise false
|
71 |
71 |
*/
|
72 |
|
function ami_group_member( $groups_list = '' )
|
|
72 |
public function ami_group_member( $groups_list = '' )
|
73 |
73 |
{
|
74 |
74 |
if( $this->get_user_id() == 1 ) { return true; }
|
75 |
75 |
return $this->is_group_match( $groups_list, $this->get_groups_id() );
|
... | ... | |
81 |
81 |
false: if page-visibility is 'none' or 'deleted', or page-vis. is 'registered' or 'private' and user isn't allowed to see the page.
|
82 |
82 |
true: if page-visibility is 'public' or 'hidden', or page-vis. is 'registered' or 'private' and user _is_ allowed to see the page.
|
83 |
83 |
*/
|
84 |
|
function page_is_visible($page)
|
|
84 |
public function page_is_visible($page)
|
85 |
85 |
{
|
|
86 |
// First check if visibility is 'none', 'deleted'
|
86 |
87 |
$show_it = false; // shall we show the page?
|
87 |
|
$page_id = $page['page_id'];
|
88 |
|
$visibility = $page['visibility'];
|
89 |
|
$viewing_groups = $page['viewing_groups'];
|
90 |
|
$viewing_users = $page['viewing_users'];
|
91 |
|
|
92 |
|
// First check if visibility is 'none', 'deleted'
|
93 |
|
if($visibility == 'none')
|
94 |
|
{
|
95 |
|
return(false);
|
96 |
|
} elseif($visibility == 'deleted')
|
97 |
|
{
|
98 |
|
return(false);
|
|
88 |
switch( $page['visibility'] )
|
|
89 |
{
|
|
90 |
case 'none':
|
|
91 |
case 'deleted':
|
|
92 |
$show_it = false;
|
|
93 |
break;
|
|
94 |
case 'hidden':
|
|
95 |
case 'public':
|
|
96 |
$show_it = true;
|
|
97 |
break;
|
|
98 |
case 'private':
|
|
99 |
case 'registered':
|
|
100 |
if($this->is_authenticated() == true)
|
|
101 |
{
|
|
102 |
$show_it = ( $this->is_group_match($this->get_groups_id(), $page['viewing_groups']) ||
|
|
103 |
$this->is_group_match($this->get_user_id(), $page['viewing_users']) );
|
|
104 |
}
|
99 |
105 |
}
|
100 |
106 |
|
101 |
|
// Now check if visibility is 'hidden', 'private' or 'registered'
|
102 |
|
if($visibility == 'hidden') { // hidden: hide the menu-link, but show the page
|
103 |
|
$show_it = true;
|
104 |
|
} elseif($visibility == 'private' || $visibility == 'registered')
|
105 |
|
{
|
106 |
|
// Check if the user is logged in
|
107 |
|
if($this->is_authenticated() == true)
|
108 |
|
{
|
109 |
|
// Now check if the user has perms to view the page
|
110 |
|
$in_group = false;
|
111 |
|
foreach($this->get_groups_id() as $cur_gid)
|
112 |
|
{
|
113 |
|
if(in_array($cur_gid, explode(',', $viewing_groups)))
|
114 |
|
{
|
115 |
|
$in_group = true;
|
116 |
|
}
|
117 |
|
}
|
118 |
|
if($in_group || in_array($this->get_user_id(), explode(',', $viewing_users))) {
|
119 |
|
$show_it = true;
|
120 |
|
} else {
|
121 |
|
$show_it = false;
|
122 |
|
}
|
123 |
|
} else {
|
124 |
|
$show_it = false;
|
125 |
|
}
|
126 |
|
} elseif($visibility == 'public') {
|
127 |
|
$show_it = true;
|
128 |
|
} else {
|
129 |
|
$show_it = false;
|
130 |
|
}
|
131 |
107 |
return($show_it);
|
132 |
108 |
}
|
|
109 |
|
133 |
110 |
// Check if there is at least one active section on this page
|
134 |
|
function page_is_active($page)
|
|
111 |
public function page_is_active($page)
|
135 |
112 |
{
|
136 |
113 |
global $database;
|
137 |
|
$has_active_sections = false;
|
138 |
|
$page_id = $page['page_id'];
|
139 |
114 |
$now = time();
|
140 |
|
$sql = 'SELECT `publ_start`, `publ_end` ';
|
141 |
|
$sql .= 'FROM `'.TABLE_PREFIX.'sections` WHERE `page_id`='.(int)$page_id;
|
142 |
|
$query_sections = $database->query($sql);
|
143 |
|
if($query_sections->numRows() != 0) {
|
144 |
|
while($section = $query_sections->fetchRow()) {
|
145 |
|
if( $now<$section['publ_end'] &&
|
146 |
|
($now>$section['publ_start'] || $section['publ_start']==0) ||
|
147 |
|
$now>$section['publ_start'] && $section['publ_end']==0)
|
148 |
|
{
|
149 |
|
$has_active_sections = true;
|
150 |
|
break;
|
151 |
|
}
|
152 |
|
}
|
153 |
|
}
|
154 |
|
return($has_active_sections);
|
155 |
|
}
|
|
115 |
$sql = 'SELECT COUNT(*) FROM `'.TABLE_PREFIX.'sections` ';
|
|
116 |
$sql .= 'WHERE ('.$now.' BETWEEN `publ_start` AND `publ_end`) OR ';
|
|
117 |
$sql .= '('.$now.' > `publ_start` AND `publ_end`=0) ';
|
|
118 |
$sql .= 'AND `page_id`='.(int)$page['page_id'];
|
|
119 |
return ($database->get_one($sql) != false);
|
|
120 |
}
|
156 |
121 |
|
157 |
122 |
// Check whether we should show a page or not (for front-end)
|
158 |
|
function show_page($page)
|
|
123 |
public function show_page($page)
|
159 |
124 |
{
|
160 |
|
$retval = ($this->page_is_visible($page) && $this->page_is_active($page));
|
161 |
|
return $retval;
|
|
125 |
if( !is_array($page) )
|
|
126 |
{
|
|
127 |
$sql = 'SELECT `page_id`, `visibility`, `viewing_groups`, `viewing_users` ';
|
|
128 |
$sql .= 'FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$page;
|
|
129 |
if( ($res_pages = $database->query($sql))!= null )
|
|
130 |
{
|
|
131 |
if( !($page = $res_pages->fetchRow()) ) { return false; }
|
|
132 |
}
|
|
133 |
}
|
|
134 |
return ($this->page_is_visible($page) && $this->page_is_active($page));
|
162 |
135 |
}
|
163 |
136 |
|
164 |
137 |
// Check if the user is already authenticated or not
|
165 |
|
function is_authenticated() {
|
|
138 |
public function is_authenticated() {
|
166 |
139 |
$retval = ( isset($_SESSION['USER_ID']) AND
|
167 |
140 |
$_SESSION['USER_ID'] != "" AND
|
168 |
141 |
is_numeric($_SESSION['USER_ID']));
|
... | ... | |
201 |
174 |
return $link;
|
202 |
175 |
}
|
203 |
176 |
}
|
204 |
|
|
|
177 |
|
205 |
178 |
// Get POST data
|
206 |
179 |
function get_post($field) {
|
207 |
180 |
return (isset($_POST[$field]) ? $_POST[$field] : null);
|
... | ... | |
212 |
185 |
$result = $this->get_post($field);
|
213 |
186 |
return (is_null($result)) ? null : $this->add_slashes($result);
|
214 |
187 |
}
|
215 |
|
|
|
188 |
|
216 |
189 |
// Get GET data
|
217 |
190 |
function get_get($field) {
|
218 |
191 |
return (isset($_GET[$field]) ? $_GET[$field] : null);
|
... | ... | |
293 |
266 |
return ($retval != false);
|
294 |
267 |
}
|
295 |
268 |
|
|
269 |
/**
|
|
270 |
* wb::send_header()
|
|
271 |
* replace header('Location:... with new method
|
|
272 |
* if header send failed you get a manuell redirected link, so script don't break
|
|
273 |
* @param string $location, redirected url
|
|
274 |
* @return void
|
|
275 |
*/
|
|
276 |
public function send_header ($location) {
|
|
277 |
if(!headers_sent()) {
|
|
278 |
header('Location: '.$location);
|
|
279 |
exit(0);
|
|
280 |
} else {
|
|
281 |
// $aDebugBacktrace = debug_backtrace();
|
|
282 |
// array_walk( $aDebugBacktrace, create_function( '$a,$b', 'print "<br /><b>". basename( $a[\'file\'] ). "</b> <font color=\"red\">{$a[\'line\']}</font> <font color=\"green\">{$a[\'function\']} ()</font> -- ". dirname( $a[\'file\'] ). "/";' ) );
|
|
283 |
$msg = "<div style=\"text-align:center;\"><h2>An error has occurred</h2><p>The <strong>Redirect</strong> could not be start automatically.\n" .
|
|
284 |
"Please click <a style=\"font-weight:bold;\" " .
|
|
285 |
"href=\"".$location."\">on this link</a> to continue!</p></div>\n";
|
|
286 |
|
|
287 |
throw new AppException($msg);
|
|
288 |
}
|
|
289 |
}
|
|
290 |
|
296 |
291 |
/* ****************
|
297 |
292 |
* set one or more bit in a integer value
|
298 |
293 |
*
|
... | ... | |
437 |
432 |
|
438 |
433 |
// Validate send email
|
439 |
434 |
function mail($fromaddress, $toaddress, $subject, $message, $fromname='', $replyTo='') {
|
440 |
|
/*
|
|
435 |
/*
|
441 |
436 |
INTEGRATED OPEN SOURCE PHPMAILER CLASS FOR SMTP SUPPORT AND MORE
|
442 |
437 |
SOME SERVICE PROVIDERS DO NOT SUPPORT SENDING MAIL VIA PHP AS IT DOES NOT PROVIDE SMTP AUTHENTICATION
|
443 |
438 |
NEW WBMAILER CLASS IS ABLE TO SEND OUT MESSAGES USING SMTP WHICH RESOLVE THESE ISSUE (C. Sommer)
|
... | ... | |
445 |
440 |
NOTE:
|
446 |
441 |
To use SMTP for sending out mails, you have to specify the SMTP host of your domain
|
447 |
442 |
via the Settings panel in the backend of Website Baker
|
448 |
|
*/
|
|
443 |
*/
|
449 |
444 |
|
450 |
445 |
$fromaddress = preg_replace('/[\r\n]/', '', $fromaddress);
|
451 |
446 |
$toaddress = preg_replace('/[\r\n]/', '', $toaddress);
|
! optimize some methods
+ add method send_header, replace header('Location:... with new method
+ if header send failed you get a manuell redirected link, so script don't break