2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 08/31/2008 *
4 * =================== Last change: 08/31/2008 *
6 * -------------------------------------------------------------------- *
7 * File : surfbar_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Functions for surfbar *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Funktionen fuer die Surfbar *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 //------------------------------------------------------------------------------
45 //------------------------------------------------------------------------------
47 // Admin has added an URL with given user id and so on
48 function doSurfbarAdminAddUrl ($url, $limit, $reload, $waiting) {
52 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Not admin.", $url, $limit, $reload));
54 } elseif (!isUrlValid($url)) {
56 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Invalid URL.", $url, $limit, $reload));
58 } elseif (ifSurfbarHasUrlUserId($url, 0)) {
59 // URL already found in surfbar!
60 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Already added.", $url, $limit, $reload));
62 } elseif (!ifSurfbarMemberAllowedMoreUrls()) {
64 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: No more URLs allowed.", $url, $limit, $reload));
66 } elseif ('' . ($limit + 0) . '' != '' . $limit . '') {
67 // Invalid limit entered
68 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Invalid limit entered.", $url, $limit, $reload));
70 } elseif ('' . ($reload + 0) . '' != '' . $reload . '') {
71 // Invalid amount entered
72 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Invalid reload entered.", $url, $limit, $reload));
74 } elseif ('' . ($waiting + 0) . '' != '' . $waiting . '') {
75 // Invalid amount entered
76 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,waiting=%s: Invalid waiting entered.", $url, $limit, $waiting));
80 // Register the new URL
81 return doSurfbarRegisterUrl($url, 0, 'ACTIVE', 'unlock', array('limit' => $limit, 'reload' => $reload, 'waiting' => $waiting));
84 // Admin unlocked an email so we can migrate the URL
85 function doSurfbarAdminMigrateUrl ($url, $userid) {
89 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Not admin, url=' . $url . ',userid=' . $userid);
91 } elseif (!isUrlValid($url)) {
93 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Invalid URL, url=' . $url . ',userid=' . $userid);
95 } elseif (ifSurfbarHasUrlUserId($url, $userid)) {
96 // URL already found in surfbar!
97 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Already added, url=' . $url . ',userid=' . $userid);
99 } elseif (!ifSurfbarMemberAllowedMoreUrls($userid)) {
101 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Maximum exceeded, url=' . $url . ',userid=' . $userid);
105 // Register the new URL
106 return doSurfbarRegisterUrl($url, $userid, 'MIGRATED', 'migrate');
109 // Admin function for unlocking URLs
110 function doSurfbarAdminUnlockUrlIds ($IDs) {
111 // Is this an admin or invalid array?
113 // Not admin or invalid ids array
114 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Not admin');
116 } elseif (!is_array($IDs)) {
118 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs type ' . gettype($IDs) . '!=array');
120 } elseif (count($IDs) == 0) {
122 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs is empty');
126 // Set to true to make AND expression valid if first URL got unlocked
129 // Update the status for all ids
130 foreach ($IDs as $id => $dummy) {
131 // Test all ids through (ignores failed)
132 $done = (($done) && (changeSurfbarUrlStatus($id, 'PENDING', 'ACTIVE')));
135 // Return total status
139 // Admin function for rejecting URLs
140 function doSurfbarAdminRejectUrlIds ($IDs) {
141 // Is this an admin or invalid array?
143 // Not admin or invalid ids array
144 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Not admin');
146 } elseif (!is_array($IDs)) {
148 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs type ' . gettype($IDs) . '!=array');
150 } elseif (count($IDs) == 0) {
152 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs is empty');
156 // Set to true to make AND expression valid if first URL got unlocked
159 // Update the status for all ids
160 foreach ($IDs as $id => $dummy) {
161 // Test all ids through (ignores failed)
162 $done = (($done) && (changeSurfbarUrlStatus($id, 'PENDING', 'REJECTED')));
165 // Return total status
169 //------------------------------------------------------------------------------
171 //------------------------------------------------------------------------------
173 // Member has added an URL
174 function doSurfbarMemberAddUrl ($url, $limit) {
175 // Do some pre-checks
178 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: isMember()=false');
180 } elseif ((!isUrlValid($url)) && (!isAdmin())) {
182 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Invalid, url=' . $url . ',limit=' . $limit);
184 } elseif (ifSurfbarHasUrlUserId($url, getMemberId())) {
185 // URL already found in surfbar!
186 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Already found, url=' . $url . ',limit=' . $limit);
188 } elseif (!ifSurfbarMemberAllowedMoreUrls(getMemberId())) {
190 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Maximum exceeded, url=' . $url . ',limit=' . $limit);
192 } elseif (''.($limit + 0).'' != ''.$limit.'') {
193 // Invalid amount entered
194 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Invalid limit, url=' . $url . ',limit=' . $limit);
198 // Register the new URL
199 return doSurfbarRegisterUrl($url, getMemberId(), 'PENDING', 'reg', array('limit' => $limit));
202 // Create list of actions depending on status for the user
203 function generateSurfbarMemberActions ($urlId, $status) {
204 // Load all actions in an array for given status
205 $actionArray = getSurfbarArrayFromStatus($status);
208 $width = round(100 / count($actionArray));
210 // "Walk" through all actions and create forms
212 foreach ($actionArray as $actionId => $action) {
213 // Add form for this action
214 $OUT .= loadTemplate('member_list_surfbar_form', TRUE, array(
216 'url_id' => bigintval($urlId),
217 'action' => strtolower($action)
221 // Load main template
222 $output = loadTemplate('member_list_surfbar_table', TRUE, $OUT);
228 // Do the member form request
229 function doSurfbarMemberByFormData ($formData, $urlArray) {
230 // By default no action is performed
236 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: isMember()=false');
238 } elseif ((!isset($formData['url_id'])) || (!isset($formData['action']))) {
239 // Important form elements are missing!
240 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Invalid form data, required field id/action not found');
242 } elseif (!isset($urlArray[$formData['url_id']])) {
243 // Id not found in cache
244 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Field url_id not found in cache');
246 } elseif (!isSurfbarMemberActionStatusValid($formData['action'], $urlArray[$formData['url_id']]['url_status'])) {
247 // Action not allowed for current URL status
248 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Action not allowed to perform. action=' . $formData['action'] . ',url_status=' . $urlArray[$formData['url_id']]['url_status'] . ',url_id=' . $formData['url_id']);
253 $action = secureString($formData['action']);
256 if ($action != $formData['action']) {
257 // Invalid data in action found
261 // Create the function name for selected action
262 $functionName = sprintf("doSurfbarMember%sAction", firstCharUpperCase($action));
264 // Is the function there?
265 if (function_exists($functionName)) {
266 // Load data and add it to globals array
267 $urlData = getSurfbarUrlData($formData['url_id']);
268 $GLOBALS['surfbar_cache'] = merge_array($GLOBALS['surfbar_cache'], $urlData[$formData['url_id']]);
271 $urlArray[$formData['url_id']]['new_status'] = getSurfbarNewStatus('new_status');
273 // Extract URL data for call-back
274 $urlData = array(merge_array($urlArray[$formData['url_id']], array($action => $formData)));
276 // Action found so execute it
277 $performed = call_user_func_array($functionName, $urlData);
279 // Log invalid request
280 reportBug(__FUNCTION__, __LINE__, 'Invalid member action! action=' . $formData['action'] . ',url_id=' . $formData['url_id'] . ',function=' . $functionName);
287 // Getter for surfbar_actions table by given id number
288 function getSurfbarActionsDataById ($columnName, $id) {
290 if (!isset($GLOBALS[__FUNCTION__][$id][$columnName])) {
291 // Default is not found
292 $GLOBALS[__FUNCTION__][$id][$columnName] = '*INVALID*';
295 $result = SQL_QUERY_ESC("SELECT `%s` FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `actions_id`=%s LIMIT 1",
299 ), __FUNCTION__, __LINE__);
301 // Is there an entry?
302 if (SQL_NUMROWS($result) == 1) {
304 list($GLOBALS[__FUNCTION__][$id][$columnName]) = SQL_FETCHROW($result);
308 SQL_FREERESULT($result);
312 return $GLOBALS[__FUNCTION__][$id][$columnName];
315 // Validate if the requested action can be performed on current URL status
316 function isSurfbarMemberActionStatusValid ($action, $status) {
317 // Search for the requested action/status combination in database
318 $result = SQL_QUERY_ESC("SELECT `actions_new_status` FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `actions_action`='%s' AND `actions_status`='%s' LIMIT 1",
322 ), __FUNCTION__, __LINE__);
324 // Is the entry there?
325 $isValid = (SQL_NUMROWS($result) == 1);
328 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'action=' . $action . ',status=' . $status . ',isValid=' . intval($isValid));
330 // Fetch the new status if found
331 if ($isValid === TRUE) {
333 list($GLOBALS['surfbar_cache']['new_status']) = SQL_FETCHROW($result);
337 SQL_FREERESULT($result);
343 //------------------------------------------------------------------------------
345 //------------------------------------------------------------------------------
347 // Retreat a booked URL
348 function doSurfbarMemberRetreatAction ($urlData) {
349 // Create the data array for next function call
351 $urlData['url_id'] => $urlData
354 // Simply change the status here
355 return changeSurfbarUrlStatus ($urlData['url_id'], $urlData['url_status'], $urlData['new_status'], $data);
358 // Book an URL now (from migration)
359 function doSurfbarMemberBooknowAction ($urlData) {
360 // Create the data array for next function call
362 $urlData['url_id'] => $urlData
365 // Simply change the status here
366 return changeSurfbarUrlStatus ($urlData['url_id'], $urlData['url_status'], $urlData['new_status'], $data);
369 // Show edit form or do the changes
370 function doSurfbarMemberEditAction ($urlData) {
371 // Is the "execute" flag there?
372 if (isset($urlData['edit']['execute'])) {
373 // Execute the changes
374 return executeSurfbarMemberAction('edit', $urlData);
378 return displaySurfbarMemberActionForm('edit', $urlData);
381 // Show delete form or do the changes
382 function doSurfbarMemberDeleteAction ($urlData) {
383 // Is the "execute" flag there?
384 if (isset($urlData['delete']['execute'])) {
385 // Execute the changes
386 return executeSurfbarMemberAction('delete', $urlData);
390 return displaySurfbarMemberActionForm('delete', $urlData);
393 // Pause active banner
394 function doSurfbarMemberPauseAction ($urlData) {
395 return changeSurfbarUrlStatus($urlData['url_id'], $urlData['url_status'], $urlData['new_status'], array($urlData['url_id'] => $urlData));
398 // Unpause stopped banner
399 function doSurfbarMemberUnpauseAction ($urlData) {
400 // Fix missing entry for template
401 $urlData['edit'] = $urlData['unpause'];
402 $urlData['edit']['url'] = $urlData['url'];
403 $urlData['edit']['limit'] = getSurfbarViewsMax();
405 // Return status change
406 return changeSurfbarUrlStatus($urlData['url_id'], $urlData['url_status'], $urlData['new_status'], array($urlData['url_id'] => $urlData));
409 // Resubmit locked URL
410 function doSurfbarMemberResubmitAction ($urlData) {
411 return changeSurfbarUrlStatus($urlData['url_id'], $urlData['url_status'], $urlData['new_status'], array($urlData['url_id'] => $urlData));
414 // Display selected "action form"
415 function displaySurfbarMemberActionForm ($action, $urlData) {
416 // Translate some data if present
417 $content = prepareSurfbarContentForTemplate($urlData);
419 // Include fields only for action 'edit'
420 if ($action == 'edit') {
421 // Default is not limited
422 $urlData['limited_yes'] = '';
423 $urlData['limited_no'] = ' checked="checked"';
424 $urlData['limited'] = 'false';
426 // Is this URL limited?
427 if (getSurfbarViewsMax() > 0) {
428 // Then rewrite form data
429 $urlData['limited_yes'] = ' checked="checked"';
430 $urlData['limited_no'] = '';
431 $urlData['limited'] = 'true';
435 // Load the form and display it
436 loadTemplate(sprintf("member_surfbar_%s_action_form", $action), FALSE, $urlData);
438 // All fine by default ... ;-)
442 // Execute choosen action
443 function executeSurfbarMemberAction ($action, $urlData) {
444 // By default nothing is executed
447 // Is limitation "no" and "limit" is > 0?
448 if ((isset($urlData[$action]['limited'])) && ($urlData[$action]['limited'] != 'Y') && ((isset($urlData[$action]['limit'])) && ($urlData[$action]['limit'] > 0)) || (!isset($urlData[$action]['limit']))) {
449 // Set it to unlimited
450 $urlData[$action]['limit'] = '0';
453 // Construct function name
454 $functionName = sprintf("executeSurfbarMember%sAction", firstCharUpperCase($action));
456 // Is that function there?
457 if (function_exists($functionName)) {
458 // Execute the function
459 if (call_user_func_array($functionName, array($urlData)) == TRUE) {
460 // Update status as well
461 $executed = changeSurfbarUrlStatus($urlData['url_id'], $urlData['url_status'], $urlData['new_status'], array($urlData['url_id'] => $urlData));
465 reportBug(__FUNCTION__, __LINE__, 'Callback function ' . $functionName . ' does not exist.');
472 // "Execute edit" function: Update changed data
473 function executeSurfbarMemberEditAction ($urlData) {
474 // Default is nothing done
477 // Has the URL or limit changed?
479 //if (($urlData['url_views_allowed'] != $urlData['edit']['limit']) || ($url1 != $url2)) {
481 SQL_QUERY_ESC("UPDATE
482 `{?_MYSQL_PREFIX?}_surfbar_urls`
485 `url_views_allowed`=%s,
493 $urlData['edit']['limit'],
494 $urlData['edit']['limit'],
496 $urlData['url_status']
497 ), __FUNCTION__, __LINE__);
507 // "Execute delete" function: Does nothing...
508 function executeSurfbarMemberDeleteAction ($urlData) {
509 // Nothing special to do (see above function for such "special actions" to perform)
513 //------------------------------------------------------------------------------
514 // Self-maintenance functions
515 //------------------------------------------------------------------------------
518 function doSurfbarSelfMaintenance () {
519 // Handle URLs which limit has depleted so we can stop them
520 doHandleSurfbarDepletedViews();
522 // Handle low-points amounts
523 doHandleSurfbarLowPoints();
526 // Handle URLs which limit has depleted
527 function doHandleSurfbarDepletedViews () {
529 $urlArray = getSurfbarUrlData(0, 'url_views_max', 'url_id', 'ASC', 'url_id', " AND `url_views_allowed` > 0 AND `url_status`='ACTIVE'");
531 // Are there some entries?
532 if (count($urlArray) > 0) {
534 foreach ($urlArray as $id => $urlData) {
538 // Rewrite array for next call
544 changeSurfbarUrlStatus($id, 'ACTIVE', 'DEPLETED', $urlData);
549 // Alert users which have URLs booked and are low on points amount
550 function doHandleSurfbarLowPoints () {
552 $userids = determineSurfbarDepletedUserids(getConfig('surfbar_warn_low_points'));
554 // "Walk" through all URLs
555 foreach ($userids['url_userid'] as $userid => $dummy) {
556 // Is the last notification far enougth away to notify again?
557 if ((time() - $userids['notified'][$userid]) >= getConfig('surfbar_low_interval')) {
560 'url_userid' => $userid,
561 'points' => $userids['points'][$userid],
562 'notified' => $userids['notified'][$userid]
566 doSurfbarNotifyMember('low_points', $content);
568 // Update last notified
569 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `surfbar_low_notified`=NOW() WHERE `userid`=%s LIMIT 1",
570 array($userid), __FUNCTION__, __LINE__);
576 //------------------------------------------------------------------------------
578 //------------------------------------------------------------------------------
581 // Looks up by an URL
582 function ifSurfbarHasUrlUserId ($url, $userid) {
583 // Now lookup that given URL by itself
584 $urlArray = getSurfbarUrlData($url, 'url', 'url_id', 'ASC', 'url_id', sprintf(" AND `url_userid`=%s", bigintval($userid)));
587 return (count($urlArray) > 0);
590 // Load URL data by given search term and column
591 function getSurfbarUrlData ($searchTerm, $column = 'url_id', $order = 'url_id', $sort = 'ASC', $group = 'url_id', $add = '') {
592 // By default nothing is found
593 $GLOBALS['last_url_data'] = array();
595 // Is the column an id number?
596 if (($column == 'url_id') || ($column == 'url_userid')) {
597 // Extra secure input
598 $searchTerm = bigintval($searchTerm);
601 // If the column is 'url_id' there can be only one entry
603 if ($column == 'url_id') {
607 // Look up the record
608 $result = SQL_QUERY_ESC("SELECT
616 UNIX_TIMESTAMP(`url_registered`) AS `url_registered`,
617 UNIX_TIMESTAMP(`url_last_locked`) AS `url_last_locked`,
624 `{?_MYSQL_PREFIX?}_surfbar_urls`
626 `%s`='%s'" . $add . "
636 ), __FUNCTION__, __LINE__);
638 // Is there at least one record?
639 if (!SQL_HASZERONUMS($result)) {
641 while ($dataRow = SQL_FETCHARRAY($result)) {
642 // Shall we group these results?
643 if ($group == 'url_id') {
644 // Add the row by id as index
645 $GLOBALS['last_url_data'][$dataRow['url_id']] = $dataRow;
648 $GLOBALS['last_url_data'][$dataRow[$group]][$dataRow['url_id']] = $dataRow;
654 SQL_FREERESULT($result);
657 return $GLOBALS['last_url_data'];
660 // Registers an URL with the surfbar. You should have called ifSurfbarHasUrlUserId() first!
661 function doSurfbarRegisterUrl ($url, $userid, $status = 'PENDING', $addMode = 'reg', $extraFields = array()) {
662 // Make sure by the user registered URLs are always pending
663 if ($addMode == 'reg') {
668 $content = merge_array($extraFields, array(
670 'url_userid' => $userid,
671 'url_status' => $status,
674 // Is limit/reload set?
675 if (!isset($content['limit'])) {
676 $content['limit'] = '0';
678 if (!isset($content['reload'])) {
679 $content['reload'] = '0';
681 if (!isset($content['waiting'])) {
682 $content['waiting'] = '0';
685 // Insert the URL into database
686 $content['insert_id'] = insertSurfbarUrlByArray($content);
689 if ($content['insert_id'] == '0') {
690 // INSERT did not insert any data!
694 // If in reg-mode we notify admin
695 if (($addMode == 'reg') || (getConfig('surfbar_notify_admin_unlock') == 'Y')) {
696 // Notify admin even when he as unlocked an email
697 doSurfbarNotifyAdmin('url_' . $addMode, $content);
701 doSurfbarNotifyMember('url_' . $addMode, $content);
703 // Return the insert id
704 return $content['insert_id'];
707 // Inserts an url by given data array and return the insert id
708 function insertSurfbarUrlByArray ($urlData) {
710 $userid = bigintval($urlData['url_userid']);
713 if (empty($userid)) {
717 // Just run the insert query for now
718 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_urls` (`url_userid`, `url`, `url_status`, `url_views_max`, `url_views_allowed`, `url_fixed_reload`, `url_fixed_waiting`) VALUES (%s, '%s', '%s', %s, %s, %s, %s)",
722 $urlData['url_status'],
727 ), __FUNCTION__, __LINE__
731 return SQL_INSERTID();
734 // Notify admin(s) with a selected message and content
735 function doSurfbarNotifyAdmin ($messageType, $content) {
736 // Prepare template name
737 $templateName = sprintf("admin_surfbar_%s", $messageType);
740 $subject = sprintf("{--ADMIN_SURFBAR_NOTIFY_%s_SUBJECT--}",
741 strtoupper($messageType)
744 // Is the subject line there?
745 if ((substr($subject, 0, 1) == '!') && (substr($subject, -1, 1) == '!')) {
746 // Set default subject if following eval() wents wrong
747 $subject = '{%message,ADMIN_SURFBAR_NOTIFY_DEFAULT_SUBJECT=' . strtoupper($messageType) . '%}';
750 // Translate some data if present
751 $content = prepareSurfbarContentForTemplate($content);
753 // Send the notification out
754 return sendAdminNotification($subject, $templateName, $content, $content['url_userid']);
757 // Notify the user about the performed action
758 function doSurfbarNotifyMember ($messageType, $content) {
759 // Skip notification if userid is zero
760 if ($content['url_userid'] == '0') {
764 // Prepare template name
765 $templateName = sprintf("member_surfbar_%s", $messageType);
768 $subject = sprintf("{--MEMBER_SURFBAR_NOTIFY_%s_SUBJECT--}",
769 strtoupper($messageType)
772 // Is the subject line there?
773 if ((substr($subject, 0, 1) == '!') && (substr($subject, -1, 1) == '!')) {
774 // Set default subject if following eval() wents wrong
775 $subject = '{--MEMBER_SURFBAR_NOTIFY_DEFAULT_SUBJECT--}';
778 // Translate some data if present
779 $content = prepareSurfbarContentForTemplate($content);
782 $mailText = loadEmailTemplate($templateName, $content, $content['url_userid']);
785 return sendEmail($content['url_userid'], $subject, $mailText);
788 // Translates some data for template usage
789 // @TODO Can't we use our new expression language instead of this ugly code?
790 function prepareSurfbarContentForTemplate ($content) {
792 if (isset($content['url_registered'])) $content['url_registered'] = generateDateTime($content['url_registered'], 2);
793 if (isset($content['url_last_locked'])) $content['url_last_locked'] = generateDateTime($content['url_last_locked'], 2);
795 // Return translated content
799 // Translates the limit
800 function translateSurfbarLimit ($limit) {
804 $return = '{--MEMBER_SURFBAR_UNLIMITED_VIEWS--}';
807 $return = '{%pipe,translateComma=' . $limit . '%}';
814 // Translate the URL status
815 function translateSurfbarUrlStatus ($status) {
816 // NULL must be handled carfefully
817 if ((is_null($status)) || (trim($status) == '')) {
818 // Is NULL, so return other language string
819 return '{--SURFBAR_URL_STATUS_NONE--}';
821 // Return regular result
822 return sprintf("{--SURFBAR_URL_STATUS_%s--}", strtoupper($status));
826 // Translates the given action into a link title for members
827 function translateMemberSurfbarActionToTitle ($action) {
829 if (!isset($GLOBALS[__FUNCTION__][$action])) {
830 // Construct default return string (unknown
831 $GLOBALS[__FUNCTION__][$action] = '{%message,MEMBER_SURFBAR_ACTION_UNKNOWN_TITLE=' . $action . '%}';
833 // ... and the id's name
834 $messageId = 'MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_TITLE';
837 if (isMessageIdValid($messageId)) {
839 $GLOBALS[__FUNCTION__][$action] = '{--' . $messageId . '--}';
844 return $GLOBALS[__FUNCTION__][$action];
847 // Translates the given action into a submit button for members
848 function translateMemberSurfbarActionToSubmit ($action) {
850 if (!isset($GLOBALS[__FUNCTION__][$action])) {
851 // Construct default return string (unknown
852 $GLOBALS[__FUNCTION__][$action] = '{%message,MEMBER_SURFBAR_ACTION_UNKNOWN_SUBMIT=' . $action . '%}';
854 // ... and the id's name
855 $messageId = 'MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_SUBMIT';
858 if (isMessageIdValid($messageId)) {
860 $GLOBALS[__FUNCTION__][$action] = '{--' . $messageId . '--}';
865 return $GLOBALS[__FUNCTION__][$action];
869 function determineSurfbarReward ($onlyMin = FALSE) {
870 // Static values are default
871 $reward = getSurfbarStaticReward();
873 // Is there static or dynamic?
874 if (getSurfbarPaymentModel() == 'DYNAMIC') {
875 // "Calculate" dynamic reward
876 if ($onlyMin === TRUE) {
877 $reward += calculateSurfbarDynamicMininumValue();
879 $reward += calculateSurfbarDynamicAddValue();
888 function determineSurfbarCosts ($onlyMin=false) {
889 // Static costs is default
890 $costs = getConfig('surfbar_static_costs');
892 // Is there static or dynamic?
893 if (getSurfbarPaymentModel() == 'DYNAMIC') {
894 // "Calculate" dynamic costs
896 $costs += calculateSurfbarDynamicMininumValue();
898 $costs += calculateSurfbarDynamicAddValue();
906 // "Calculate" dynamic add
907 function calculateSurfbarDynamicAddValue () {
908 // Get min/max values
909 $min = calculateSurfbarDynamicMininumValue();
910 $max = calculateSurfbarDynamicMaximumValue();
912 // "Calculate" dynamic part and return it
913 return mt_rand($min, $max);
916 // Determine right template name
917 function determineSurfbarTemplateName() {
918 // Default is the frameset
919 $templateName = 'surfbar_frameset';
921 // Any frame set? ;-)
923 // Use the frame as a template name part... ;-)
924 $templateName = sprintf("surfbar_frame_%s",
925 getRequestElement('frame')
930 return $templateName;
934 * Check if the "reload lock" of the current user is full, call this function
935 * before you call ifSurfbarReloadLock().
937 function isSurfbarReloadFull () {
938 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Fixed surf lock is ' . getConfig('surfbar_static_lock') . ' - ENTERED!');
942 // Cache static reload lock
943 $GLOBALS['surfbar_cache']['surf_lock'] = getConfig('surfbar_static_lock');
945 // Is there dynamic model?
946 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'surf_lock=' . $GLOBALS['surfbar_cache']['surf_lock'] . ' - BEFORE');
947 if (getSurfbarPaymentModel() == 'DYNAMIC') {
948 // "Calculate" dynamic lock
949 $GLOBALS['surfbar_cache']['surf_lock'] += calculateSurfbarDynamicAddValue();
951 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'surf_lock=' . $GLOBALS['surfbar_cache']['surf_lock'] . ' - AFTER');
954 $result = SQL_QUERY_ESC("SELECT
955 COUNT(l.`locks_id`) AS `cnt`
957 `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
959 `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
961 u.`url_id`=l.`locks_url_id`
963 l.`locks_userid`=%s AND
964 (UNIX_TIMESTAMP() - {%%pipe,getSurfbarSurfLock%%}) < UNIX_TIMESTAMP(l.`locks_last_surfed`) AND
966 ((UNIX_TIMESTAMP(l.`locks_last_surfed`) - u.`url_fixed_reload`) < 0 AND u.`url_fixed_reload` > 0) OR
967 u.`url_fixed_reload` = 0
970 array(getMemberId()), __FUNCTION__, __LINE__
974 list($GLOBALS['surfbar_cache']['user_locks']) = SQL_FETCHROW($result);
977 if (is_null($GLOBALS['surfbar_cache']['user_locks'])) {
978 // Then fix it to zero!
979 $GLOBALS['surfbar_cache']['user_locks'] = '0';
983 SQL_FREERESULT($result);
986 $total = getSurfbarTotalUrls();
988 // Are there some URLs in lock? Admins can always surf on own URLs!
989 $isFull = ((getSurfbarUserLocks() == $total) && ($total > 0));
992 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userLocks=' . getSurfbarUserLocks() . ',total=' . $total . ',isFull=' . intval($isFull) . ' - EXIT!');
996 // Get total amount of URLs of given status for current user or of ACTIVE URLs by default
997 function getSurfbarTotalUrls ($status = 'ACTIVE', $excludeUserId = NULL) {
998 // Determine depleted user account
999 $userids = determineSurfbarDepletedUserids();
1001 // If we dont get any user ids back, there are no URLs
1002 if (count($userids['url_userid']) == 0) {
1003 // No user ids found, no URLs!
1007 // Is the exlude userid set?
1008 if (isValidUserId($excludeUserId)) {
1010 $userids['url_userid'][$excludeUserId] = $excludeUserId;
1013 // Get amount from database
1014 $result = SQL_QUERY_ESC("SELECT
1015 COUNT(`url_id`) AS cnt
1017 `{?_MYSQL_PREFIX?}_surfbar_urls`
1019 (`url_userid` NOT IN (".implode(', ', $userids['url_userid']).") OR `url_userid` IS NULL) AND
1022 array($status), __FUNCTION__, __LINE__
1026 list($count) = SQL_FETCHROW($result);
1029 SQL_FREERESULT($result);
1032 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'cnt=' . $count . ' - EXIT!');
1038 // Check whether the user is allowed to book more URLs
1039 function ifSurfbarMemberAllowedMoreUrls ($userid = NULL) {
1040 // Is this admin and userid is zero or does the user has some URLs left to book?
1041 return (((is_null($userid)) && (isAdmin())) || (getSurfbarTotalUserUrls($userid, '', array('REJECTED')) < getSurfbarMaxOrder()));
1044 // Get total amount of URLs of given status for current user
1045 function getSurfbarTotalUserUrls ($userid = NULL, $status = '', $exclude = '') {
1046 // Is the user 0 and user is logged in?
1047 if ((is_null($userid)) && (isMember())) {
1048 // Then use this userid
1049 $userid = getMemberId();
1050 } elseif (is_null($userid)) {
1052 return (getSurfbarMaxOrder() + 1);
1055 // Default is all URLs
1058 // Is the status set?
1059 if (is_array($status)) {
1060 // Only URLs with these status
1061 $add = sprintf(" AND `url_status` IN('%s')", implode("','", $status));
1062 } elseif (!empty($status)) {
1063 // Only URLs with this status
1064 $add = sprintf(" AND `url_status`='%s'", $status);
1065 } elseif (is_array($exclude)) {
1066 // Exclude URLs with these status
1067 $add = sprintf(" AND `url_status` NOT IN('%s')", implode("','", $exclude));
1068 } elseif (!empty($exclude)) {
1069 // Exclude URLs with this status
1070 $add = sprintf(" AND `url_status` != '%s'", $exclude);
1073 // Get amount from database
1074 $count = countSumTotalData($userid, 'surfbar_urls', 'url_id', 'url_userid', TRUE, $add);
1080 // Generate a validation code for the given id number
1081 function generateSurfbarValidationCode ($urlId, $salt = '') {
1082 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',salt=' . $salt . ' - ENTERED!');
1083 // Init hash with invalid value
1085 // Generate random hashed string
1086 $GLOBALS['surfbar_cache']['salt'] = sha1(generatePassword(mt_rand(200, 255)));
1087 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newSalt='.getSurfbarSalt().'', FALSE);
1089 // Use this as salt!
1090 $GLOBALS['surfbar_cache']['salt'] = $salt;
1091 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'oldSalt='.getSurfbarSalt().'', FALSE);
1094 // Hash it with md5() and salt it with the random string
1095 $hashedCode = generateHash(md5($urlId . getEncryptSeparator() . getMemberId()), getSurfbarSalt());
1097 // Finally encrypt it PGP-like and return it
1098 $valHashedCode = encodeHashForCookie($hashedCode);
1100 // Return hashed value
1101 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',salt=' . $salt . ',urlId=' . $urlId . ',salt=' . $salt . ',valHashedCode=' . $valHashedCode . ' - EXIT!');
1102 return $valHashedCode;
1105 // Check validation code
1106 function isSurfbarValidationCodeValid ($urlId, $check, $salt) {
1107 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',check=' . $check . ',salt=' . $salt . ' - ENTERED!');
1109 $urlId = bigintval($urlId);
1111 // Now generate the code again
1112 $code = generateSurfbarValidationCode($urlId, $salt);
1114 // Return result of checking hashes and salts
1115 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',(code==check)=' . intval($code == $check) . ',(salt==salts_last_salt)=' . intval($salt == getSurfbarData('salts_last_salt')) . ' - EXIT!');
1116 return (($code == $check) && ($salt == getSurfbarData('salts_last_salt')));
1119 // Lockdown the userid/id combination (reload lock)
1120 function addSurfbarReloadLockById ($urlId) {
1121 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',getMemberId()=' . getMemberId() . ' - ENTERED!');
1122 // Search for an entry
1123 $countLock = countSumTotalData(getMemberId(), 'surfbar_locks', 'locks_id', 'locks_userid', TRUE, ' AND `locks_url_id`=' . bigintval($urlId));
1125 // Is there no record?
1126 if ($countLock == 0) {
1127 // Just add it to the database
1128 SQL_QUERY_ESC('INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_locks` (`locks_userid`, `locks_url_id`) VALUES (%s, %s)',
1132 ), __FUNCTION__, __LINE__);
1135 // Remove the salt from database
1136 SQL_QUERY_ESC('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_surfbar_salts` WHERE `salts_url_id`=%s AND `salts_userid`=%s LIMIT 1',
1140 ), __FUNCTION__, __LINE__);
1142 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',getMemberId()=' . getMemberId() . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS() . ' - EXIT!');
1145 // Pay points to the user and remove it from the sender if userid is given else it is a "sponsored surf"
1146 function doSurfbarPayPoints () {
1147 // Remove it from the URL owner
1148 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getSurfbarUserid().',costs='.getSurfbarCosts() . ' - ENTERED!');
1149 if (isValidUserId(getSurfbarUserid())) {
1150 // Subtract points and ignore return status
1151 subtractPoints(sprintf("surfbar_%s", getSurfbarPaymentModel()), getSurfbarUserid(), getSurfbarCosts());
1154 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getMemberId().',reward='.getSurfbarReward());
1155 // Init referral system here
1156 initReferralSystem();
1158 // Book it to the user and ignore return status
1159 addPointsThroughReferralSystem(sprintf("surfbar:%s", getSurfbarPaymentModel()), getMemberId(), getSurfbarReward());
1160 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getSurfbarUserid().',costs='.getSurfbarCosts() . ' - EXIT!');
1163 // Updates the statistics of current URL/userid
1164 function updateInsertSurfbarStatisticsRecord () {
1168 // Get allowed views
1169 $allowed = getSurfbarViewsAllowed();
1171 // Is there a limit?
1173 // Then count views_max down!
1174 $add .= ',`url_views_max`=`url_views_max`-1';
1178 SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `url_views_total`=`url_views_total`+1' . $add . ' WHERE `url_id`=%s LIMIT 1',
1179 array(getSurfbarId()), __FUNCTION__, __LINE__);
1181 // Update the stats entry
1182 SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_surfbar_stats` SET `stats_count`=`stats_count`+1 WHERE `stats_userid`=%s AND `stats_url_id`=%s LIMIT 1',
1186 ), __FUNCTION__, __LINE__);
1188 // Was that update okay?
1189 if (SQL_HASZEROAFFECTED()) {
1190 // No, then insert entry
1191 SQL_QUERY_ESC('INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_stats` (`stats_userid`, `stats_url_id`, `stats_count`) VALUES (%s,%s,1)',
1195 ), __FUNCTION__, __LINE__);
1198 // Update total/daily/weekly/monthly counter
1199 incrementConfigEntry('surfbar_total_counter');
1200 incrementConfigEntry('surfbar_daily_counter');
1201 incrementConfigEntry('surfbar_weekly_counter');
1202 incrementConfigEntry('surfbar_monthly_counter');
1204 // Update config as well
1205 updateConfiguration(array('surfbar_total_counter', 'surfbar_daily_counter', 'surfbar_weekly_counter', 'surfbar_monthly_counter'), array(1,1,1,1), '+');
1208 // Update the salt for validation and statistics
1209 function updateSurfbarSaltStatistics () {
1211 generateSurfbarValidationCode(getSurfbarId());
1213 // Make sure only valid salts can pass
1214 if (getSurfbarSalt() == 'INVALID') {
1216 reportBug(__FUNCTION__, __LINE__, 'Invalid salt provided, id=' . getSurfbarId() . ',getMemberId()=' . getMemberId());
1219 // Update statistics record
1220 updateInsertSurfbarStatisticsRecord();
1222 // Simply store the salt from cache away in database...
1224 `{?_MYSQL_PREFIX?}_surfbar_salts`
1226 `salts_last_salt`='{%pipe,getSurfbarSalt%}'
1228 `salts_url_id`={%pipe,getSurfbarId%} AND
1229 `salts_userid`={%pipe,getMemberId%}
1230 LIMIT 1", __FUNCTION__, __LINE__);
1233 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt=' . getSurfbarSalt() . ',id=' . getSurfbarId() . ',userid=' . getMemberId() . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS() . ' - UPDATE!');
1236 if (SQL_HASZEROAFFECTED()) {
1237 // Insert missing entry!
1238 SQL_QUERY("INSERT INTO
1239 `{?_MYSQL_PREFIX?}_surfbar_salts`
1245 {%pipe,getSurfbarId%},
1246 {%pipe,getMemberId%},
1247 '{%pipe,getSurfbarSalt%}'
1248 )", __FUNCTION__, __LINE__);
1252 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'affectedRows=' . SQL_AFFECTEDROWS() . ' - EXIT!');
1254 // Return if the update was okay
1255 return (!SQL_HASZEROAFFECTED());
1258 // Check if the reload lock is active for given id
1259 function ifSurfbarReloadLock ($urlId) {
1260 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $urlId . ' - ENTERED!');
1262 $result = SQL_QUERY_ESC('SELECT COUNT(`locks_id`) AS `cnt`
1264 `{?_MYSQL_PREFIX?}_surfbar_locks`
1266 `locks_userid`=%s AND
1267 `locks_url_id`=%s AND
1268 (UNIX_TIMESTAMP() - {%%pipe,getSurfbarSurfLock%%}) < UNIX_TIMESTAMP(`locks_last_surfed`)
1270 `locks_last_surfed` ASC
1272 array(getMemberId(), bigintval($urlId)), __FUNCTION__, __LINE__
1276 list($count) = SQL_FETCHROW($result);
1279 SQL_FREERESULT($result);
1282 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',count=' . $count . ',getSurfbarSurfLock()=' . getSurfbarSurfLock() . ' - EXIT!');
1283 return ($count == 1);
1286 // Determine which user hash no more points left
1287 function determineSurfbarDepletedUserids ($limit=0) {
1290 'url_userid' => array(),
1291 'points' => array(),
1292 'notified' => array(),
1295 // Is there a current user id?
1296 if ((isMember()) && ($limit == '0')) {
1297 // Then add this as well
1298 $userids['url_userid'][getMemberId()] = getMemberId();
1299 $userids['points'][getMemberId()] = getTotalPoints(getMemberId());
1300 $userids['notified'][getMemberId()] = '0';
1302 // Get all userid except logged in one
1303 $result = SQL_QUERY_ESC("SELECT
1304 u.url_userid, UNIX_TIMESTAMP(d.surfbar_low_notified) AS notified
1306 `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
1308 `{?_MYSQL_PREFIX?}_user_data` AS d
1310 u.`url_userid`=d.`userid`
1312 u.`url_userid` NOT IN (%s) AND
1313 u.`url_userid` IS NOT NULL AND
1314 u.`url_status`='ACTIVE'
1318 u.`url_userid` ASC",
1319 array(getMemberId()), __FUNCTION__, __LINE__);
1322 $result = SQL_QUERY("SELECT
1323 u.url_userid, UNIX_TIMESTAMP(d.surfbar_low_notified) AS notified
1325 `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
1327 `{?_MYSQL_PREFIX?}_user_data` AS d
1329 u.`url_userid`=d.`userid`
1331 u.`url_userid` > 0 AND
1332 u.`url_status`='ACTIVE'
1336 u.`url_userid` ASC", __FUNCTION__, __LINE__);
1340 while ($content = SQL_FETCHARRAY($result)) {
1342 $points = getTotalPoints($content['url_userid']);
1343 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ',points=' . $points);
1345 // Shall we add this to ignore?
1346 if ($points <= $limit) {
1348 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ' has depleted points amount!');
1349 $userids['url_userid'][$content['url_userid']] = $content['url_userid'];
1350 $userids['points'][$content['url_userid']] = $points;
1351 $userids['notified'][$content['url_userid']] = $content['notified'];
1356 SQL_FREERESULT($result);
1359 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UIDs::count=' . count($userids) . ' (with own userid=' . getMemberId() . ')');
1365 // Determine how many users are Online in surfbar
1366 function determineSurfbarTotalOnline () {
1367 // Count all users in surfbar modue and return the value
1368 $result = SQL_QUERY('SELECT
1371 `{?_MYSQL_PREFIX?}_surfbar_stats`
1373 (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`stats_last_surfed`)) <= {?online_timeout?}
1375 `stats_userid` ASC', __FUNCTION__, __LINE__);
1378 $count = SQL_NUMROWS($result);
1381 SQL_FREERESULT($result);
1387 // Determine waiting time for one URL
1388 function determineSurfbarWaitingTime () {
1389 // Get fixed reload lock
1390 $fixed = getSurfbarFixedWaitingTime();
1392 // Is the URL's fixed waiting time set?
1398 // Static time is default
1399 $time = getSurfbarStaticTime();
1401 // Which payment model do we have?
1402 if (getSurfbarPaymentModel() == 'DYNAMIC') {
1403 // "Calculate" dynamic time
1404 $time += calculateSurfbarDynamicAddValue();
1411 // Changes the status of an URL from given to other
1412 function changeSurfbarUrlStatus ($urlId, $prevStatus, $newStatus, $data = array()) {
1413 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',data[]=' . gettype($data) . ',newStatus=' . $newStatus . ' - ENTERED!');
1414 // Make new status always lower-case
1415 $newStatus = strtolower($newStatus);
1417 // Get URL data for status comparison if missing
1418 if ((!is_array($data)) || (count($data) == 0)) {
1419 // Fetch missing URL data
1420 $data = getSurfbarUrlData($urlId);
1424 $filterData = array(
1426 'prev_status' => $prevStatus,
1427 'new_status' => $newStatus,
1432 // Run pre filter chain
1433 $filterData = runFilterChain('pre_change_surfbar_url_status', $filterData);
1436 if (!is_null($filterData['abort'])) {
1438 return $filterData['abort'];
1441 // Update the status now
1442 // ---------- Comment out for debugging/developing member actions! ---------
1443 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `url_status`='%s' WHERE `url_id`=%s LIMIT 1",
1447 ), __FUNCTION__, __LINE__);
1448 // ---------- Comment out for debugging/developing member actions! ---------
1451 // ---------- Comment out for debugging/developing member actions! ---------
1452 if (SQL_AFFECTEDROWS() != 1) {
1453 // No, something went wrong
1456 // ---------- Comment out for debugging/developing member actions! ---------
1458 // Run post filter chain
1459 $filterData = runFilterChain('post_change_surfbar_url_status', $filterData);
1461 // Check if generic 'data' is there
1462 assert(isset($filterData['data']));
1465 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - EXIT!');
1469 // Calculate minimum value for dynamic payment model
1470 function calculateSurfbarDynamicMininumValue () {
1471 // Addon is zero by default
1475 $percent = abs(log(getConfig('surfbar_dynamic_percent') / 100 + 1));
1478 $totalUsers = getTotalConfirmedUser();
1481 $onlineUsers = determineSurfbarTotalOnline();
1484 $addon += abs(log($onlineUsers / $totalUsers + 1) * $percent * $totalUsers);
1487 $totalUrls = getSurfbarTotalUrls('ACTIVE', 0);
1489 // Get user's total URLs
1490 $userUrls = getSurfbarTotalUserUrls(0, 'ACTIVE');
1493 if ($totalUrls > 0) {
1494 $addon += abs(log($userUrls / $totalUrls + 1) * $percent * $totalUrls);
1496 $addon += abs(log($userUrls / 1 + 1) * $percent * $totalUrls);
1503 // Calculate maximum value for dynamic payment model
1504 function calculateSurfbarDynamicMaximumValue () {
1505 // Addon is zero by default
1512 $percent = abs(log(getConfig('surfbar_dynamic_percent') / 100 + 1));
1515 $totalUsers = getTotalConfirmedUser();
1518 $addon += abs($max * $percent * $totalUsers);
1521 $totalUrls = getSurfbarTotalUrls('ACTIVE', 0);
1524 $addon += abs($max * $percent * $totalUrls);
1530 // Calculate dynamic lock
1531 function calculateSurfbarDynamicLock () {
1532 // Default lock is 30 seconds
1536 $onlineUsers = determineSurfbarTotalOnline();
1539 $addon = abs(log($onlineUsers / $addon + 1));
1545 // "Getter" for lock ids array
1546 function getSurfbarLockIdsArray () {
1547 // Prepare some arrays
1552 // Get all id from locks within the timestamp
1553 $result = SQL_QUERY_ESC("SELECT
1556 UNIX_TIMESTAMP(`locks_last_surfed`) AS `last_surfed`
1558 `{?_MYSQL_PREFIX?}_surfbar_locks`
1562 `locks_id` ASC", array(getMemberId()),
1563 __FUNCTION__, __LINE__);
1566 while ($content = SQL_FETCHARRAY($result)) {
1568 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'next - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',rest='.(time() - $content['last_surfed']).'/'.getSurfbarSurfLock());
1570 // Skip entries that are too old
1571 if (($content['last_surfed'] > (time() - getSurfbarSurfLock())) && (!in_array($content['locks_url_id'], $ignored))) {
1573 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'okay - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',last='.$content['last_surfed']);
1575 // Add only if missing or bigger
1576 if ((!isset($IDs[$content['locks_url_id']])) || ($IDs[$content['locks_url_id']] > $content['last_surfed'])) {
1578 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',last='.$content['last_surfed']);
1581 $IDs[$content['locks_url_id']] = $content['last_surfed'];
1582 $USE[$content['locks_url_id']] = $content['locks_id'];
1586 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ignore - lid='.$content['locks_id'].',url='.$content['locks_url_id'].',last='.$content['last_surfed']);
1588 // Ignore these old entries!
1589 array_push($ignored, $content['locks_url_id']);
1590 unset($IDs[$content['locks_url_id']]);
1591 unset($USE[$content['locks_url_id']]);
1596 SQL_FREERESULT($result);
1602 // "Getter" for maximum random number
1603 function getSurfbarMaximumRandom ($userids, $add) {
1604 // Count max availabe entries
1605 $result = SQL_QUERY("SELECT
1608 `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
1610 `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
1612 sbu.url_id=sbs.salts_url_id
1614 `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
1616 sbu.url_id=l.locks_url_id
1618 sbu.url_userid NOT IN (" . implode(',', $userids) . ") AND
1619 (sbu.url_views_allowed=0 OR (sbu.url_views_allowed > 0 AND sbu.url_views_max > 0)) AND
1620 sbu.url_status='ACTIVE'
1623 sbu.url_id ASC", __FUNCTION__, __LINE__);
1626 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS());
1629 $maxRand = SQL_NUMROWS($result);
1632 SQL_FREERESULT($result);
1638 // Load all URLs of the current user and return it as an array
1639 function getSurfbarUserUrls () {
1641 $urlArray = array();
1644 $result = SQL_QUERY_ESC("SELECT
1649 u.`url_views_total`,
1651 u.`url_views_allowed`,
1652 UNIX_TIMESTAMP(u.`url_registered`) AS `url_registered`,
1653 UNIX_TIMESTAMP(u.`url_last_locked`) AS `url_last_locked`,
1656 `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
1658 u.`url_userid`=%s AND
1659 u.`url_status` != 'DELETED'
1662 array(getMemberId()), __FUNCTION__, __LINE__);
1664 // Are there entries?
1665 if (!SQL_HASZERONUMS($result)) {
1667 while ($row = SQL_FETCHARRAY($result)) {
1669 $urlArray[$row['url_id']] = $row;
1674 SQL_FREERESULT($result);
1680 // "Getter" for member action array for given status
1681 function getSurfbarArrayFromStatus ($status) {
1683 $returnArray = array();
1685 // Get all assigned actions
1686 $result = SQL_QUERY_ESC("SELECT `actions_action` FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `actions_status`='%s' ORDER BY `actions_id` ASC",
1687 array($status), __FUNCTION__, __LINE__);
1689 // Some entries there?
1690 if (!SQL_HASZERONUMS($result)) {
1692 // @TODO This can be somehow rewritten
1693 while ($content = SQL_FETCHARRAY($result)) {
1694 array_push($returnArray, $content['actions_action']);
1699 SQL_FREERESULT($result);
1702 return $returnArray;
1705 // Reload to configured stop page
1706 function redirectToSurfbarStopPage ($page = 'stop') {
1707 // Internal or external?
1708 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'page=' . $page . ' - ENTERED!');
1709 if ((getConfig('surfbar_pause_mode') == 'INTERNAL') || (getConfig('surfbar_pause_url') == '')) {
1710 // Reload to internal page
1711 redirectToUrl('surfbar.php?frame=' . $page);
1713 // Reload to external page
1714 redirectToConfiguredUrl('surfbar_pause_url');
1719 * Determine next id for surfbar or get data for given id, always call this
1720 * before you call other getters below this function!
1722 function determineSurfbarNextId ($urlId = NULL) {
1723 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ' - ENTERED!');
1724 // Default is no id and no random number
1729 if (is_null($urlId)) {
1730 // Get array with lock ids
1731 $USE = getSurfbarLockIdsArray();
1733 // Shall we add some URL ids to ignore?
1735 if (count($USE) > 0) {
1737 $add = " AND sbu.`url_id` NOT IN (";
1738 foreach ($USE as $url_id => $lid) {
1740 $add .= $url_id.',';
1743 // Add closing bracket
1744 $add = substr($add, 0, -1) . ')';
1747 // Determine depleted user account
1748 $userids = determineSurfbarDepletedUserids();
1750 // Get maximum randomness factor
1751 $maxRand = getSurfbarMaximumRandom($userids['url_userid'], $add);
1753 // If more than one URL can be called generate the random number!
1755 // Generate random number
1756 $randNum = mt_rand(0, ($maxRand - 1));
1759 // And query the database
1760 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'randNum='.$randNum.',maxRand='.$maxRand.',surfLock='.getSurfbarSurfLock());
1761 $result = SQL_QUERY_ESC("SELECT
1765 sbs.salts_last_salt,
1766 sbu.url_views_total,
1768 sbu.url_views_allowed,
1769 UNIX_TIMESTAMP(l.locks_last_surfed) AS last_surfed,
1770 sbu.url_fixed_reload
1772 `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
1774 `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
1776 sbu.url_id=sbs.salts_url_id
1778 `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
1780 sbu.url_id=l.locks_url_id
1782 (sbu.`url_userid` NOT IN (".implode(',', $userids['url_userid']).") OR sbu.`url_userid` IS NULL) AND
1783 sbu.url_status='ACTIVE' AND
1784 (sbu.url_views_allowed=0 OR (sbu.url_views_allowed > 0 AND sbu.url_views_max > 0))
1789 l.locks_last_surfed ASC,
1792 array($randNum), __FUNCTION__, __LINE__
1795 // Get data from specified id number
1796 $result = SQL_QUERY_ESC("SELECT
1800 sbs.salts_last_salt,
1801 sbu.url_views_total,
1803 sbu.url_views_allowed,
1804 UNIX_TIMESTAMP(l.locks_last_surfed) AS last_surfed,
1805 sbu.url_fixed_reload
1807 `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
1809 `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
1811 sbu.url_id=sbs.salts_url_id
1813 `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
1815 sbu.url_id=l.locks_url_id
1817 (sbu.url_userid != %s OR sbu.url_userid IS NULL) AND
1818 sbu.url_status='ACTIVE' AND
1820 (sbu.url_views_allowed=0 OR (sbu.url_views_allowed > 0 AND sbu.url_views_max > 0))
1822 array(getMemberId(), bigintval($urlId)), __FUNCTION__, __LINE__
1826 // Is there an id number?
1827 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS());
1828 if (SQL_NUMROWS($result) == 1) {
1830 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - BEFORE', FALSE);
1831 $GLOBALS['surfbar_cache'] = merge_array($GLOBALS['surfbar_cache'], SQL_FETCHARRAY($result));
1832 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - AFTER', FALSE);
1834 // Determine waiting time
1835 $GLOBALS['surfbar_cache']['waiting'] = determineSurfbarWaitingTime();
1837 // Is the last salt there?
1838 if (is_null($GLOBALS['surfbar_cache']['salts_last_salt'])) {
1839 // Then repair it wit the static!
1840 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_salt - FIXED!', FALSE);
1841 $GLOBALS['surfbar_cache']['salts_last_salt'] = '';
1844 // Fix missing last_surfed
1845 if ((!isset($GLOBALS['surfbar_cache']['last_surfed'])) || (is_null($GLOBALS['surfbar_cache']['last_surfed']))) {
1847 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_surfed - FIXED!', FALSE);
1848 $GLOBALS['surfbar_cache']['last_surfed'] = '0';
1851 // Get base/fixed reward and costs
1852 $GLOBALS['surfbar_cache']['reward'] = determineSurfbarReward();
1853 $GLOBALS['surfbar_cache']['costs'] = determineSurfbarCosts();
1854 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'BASE/STATIC - reward='.getSurfbarReward().'|costs='.getSurfbarCosts());
1856 // Only in dynamic model add the dynamic bonus!
1857 if (getSurfbarPaymentModel() == 'DYNAMIC') {
1858 // Calculate dynamic reward/costs and add it
1859 $GLOBALS['surfbar_cache']['reward'] += calculateSurfbarDynamicAddValue();
1860 $GLOBALS['surfbar_cache']['costs'] += calculateSurfbarDynamicAddValue();
1861 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DYNAMIC+ - reward='.getSurfbarReward().'|costs='.getSurfbarCosts());
1865 $nextId = getSurfbarId();
1869 SQL_FREERESULT($result);
1872 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',nextId=' . $nextId . ' - EXIT!');
1876 //-----------------------------------------------------------------------------
1878 //-----------------------------------------------------------------------------
1880 // "Getter" for surfbar_dynamic_percent
1881 function getSurfbarDynamicPercent () {
1883 if (!isset($GLOBALS[__FUNCTION__])) {
1885 $GLOBALS[__FUNCTION__] = getConfig('surfbar_dynamic_percent');
1889 return $GLOBALS[__FUNCTION__];
1892 // "Getter" for surfbar_static_reward
1893 function getSurfbarStaticReward () {
1895 if (!isset($GLOBALS[__FUNCTION__])) {
1897 $GLOBALS[__FUNCTION__] = getConfig('surfbar_static_reward');
1901 return $GLOBALS[__FUNCTION__];
1904 // "Getter" for surfbar_static_time
1905 function getSurfbarStaticTime () {
1907 if (!isset($GLOBALS[__FUNCTION__])) {
1909 $GLOBALS[__FUNCTION__] = getConfig('surfbar_static_time');
1913 return $GLOBALS[__FUNCTION__];
1916 // "Getter" for surfbar_max_order
1917 function getSurfbarMaxOrder () {
1919 if (!isset($GLOBALS[__FUNCTION__])) {
1921 $GLOBALS[__FUNCTION__] = getConfig('surfbar_max_order');
1925 return $GLOBALS[__FUNCTION__];
1928 // "Getter" for surfbar_payment_model
1929 function getSurfbarPaymentModel () {
1931 if (!isset($GLOBALS[__FUNCTION__])) {
1933 $GLOBALS[__FUNCTION__] = getConfig('surfbar_payment_model');
1937 return $GLOBALS[__FUNCTION__];
1940 // "Getter" for surfbar_stats_reload
1941 function getSurfbarStatsReload () {
1943 if (!isset($GLOBALS[__FUNCTION__])) {
1945 $GLOBALS[__FUNCTION__] = getConfig('surfbar_stats_reload');
1949 return $GLOBALS[__FUNCTION__];
1952 // "Getter" for surfbar_restart_time
1953 function getSurfbarRestartTime () {
1955 if (!isset($GLOBALS[__FUNCTION__])) {
1957 $GLOBALS[__FUNCTION__] = getConfig('surfbar_restart_time');
1961 return $GLOBALS[__FUNCTION__];
1964 // "Getter" for surfbar_auto_start
1965 function getSurfbarAutoStart () {
1967 if (!isset($GLOBALS[__FUNCTION__])) {
1969 $GLOBALS[__FUNCTION__] = getConfig('surfbar_auto_start');
1973 return $GLOBALS[__FUNCTION__];
1976 // Checks whether auto-start is enabled
1977 function isSurfbarAutoStartEnabled () {
1979 if (!isset($GLOBALS[__FUNCTION__])) {
1981 $GLOBALS[__FUNCTION__] = (getSurfbarAutoStart() == 'Y');
1985 return $GLOBALS[__FUNCTION__];
1988 // "Getter" for surfbar_daily_counter
1989 function getSurfbarDailyCounter () {
1991 if (!isset($GLOBALS[__FUNCTION__])) {
1993 $GLOBALS[__FUNCTION__] = getConfig('surfbar_daily_counter');
1997 return $GLOBALS[__FUNCTION__];
2000 // "Getter" for surfbar_yester_counter
2001 function getSurfbarYesterCounter () {
2003 if (!isset($GLOBALS[__FUNCTION__])) {
2005 $GLOBALS[__FUNCTION__] = getConfig('surfbar_yester_counter');
2009 return $GLOBALS[__FUNCTION__];
2012 // "Getter" for surfbar_weekly_counter
2013 function getSurfbarWeeklyCounter () {
2015 if (!isset($GLOBALS[__FUNCTION__])) {
2017 $GLOBALS[__FUNCTION__] = getConfig('surfbar_weekly_counter');
2021 return $GLOBALS[__FUNCTION__];
2024 // "Getter" for surfbar_monthly_counter
2025 function getSurfbarMonthlyCounter () {
2027 if (!isset($GLOBALS[__FUNCTION__])) {
2029 $GLOBALS[__FUNCTION__] = getConfig('surfbar_monthly_counter');
2033 return $GLOBALS[__FUNCTION__];
2036 // "Getter" for surfbar_total_counter
2037 function getSurfbarTotalCounter () {
2039 if (!isset($GLOBALS[__FUNCTION__])) {
2041 $GLOBALS[__FUNCTION__] = getConfig('surfbar_total_counter');
2045 return $GLOBALS[__FUNCTION__];
2048 //------------------------------------------------------------------------------
2049 // Template helper functions
2050 //------------------------------------------------------------------------------
2052 // Template helper to generate a selection box for surfbar actions
2053 function doTemplateSurfbarActionsActionSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
2055 $actionsAction = array(
2056 0 => array('actions_action' => 'EDIT'),
2057 1 => array('actions_action' => 'DELETE'),
2058 2 => array('actions_action' => 'PAUSE'),
2059 3 => array('actions_action' => 'UNPAUSE'),
2060 4 => array('actions_action' => 'FRAMETEST'),
2061 5 => array('actions_action' => 'RETREAT'),
2062 6 => array('actions_action' => 'RESUBMIT'),
2063 7 => array('actions_action' => 'BOOKNOW')
2066 // Handle it over to generateSelectionBoxFromArray()
2067 $content = generateSelectionBoxFromArray($actionsAction, 'actions_action', 'actions_action', '', '_surfbar', '', $default, '', FALSE, TRUE);
2069 // Return prepared content
2073 // Template helper to generate a selection box for surfbar status
2074 function doTemplateSurfbarActionsStatusSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
2077 0 => array('actions_status' => 'PENDING'),
2078 1 => array('actions_status' => 'ACTIVE'),
2079 2 => array('actions_status' => 'LOCKED'),
2080 3 => array('actions_status' => 'STOPPED'),
2081 4 => array('actions_status' => 'REJECTED'),
2082 5 => array('actions_status' => 'DELETED'),
2083 6 => array('actions_status' => 'MIGRATED'),
2084 7 => array('actions_status' => 'DEPLETED')
2087 // Handle it over to generateSelectionBoxFromArray()
2088 $content = generateSelectionBoxFromArray($status, 'actions_status', 'actions_status', '', '_surfbar', '', $default, '', FALSE, TRUE);
2090 // Return prepared content
2094 // Template helper to generate a selection box for surfbar status
2095 function doTemplateSurfbarActionsNewStatusSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
2098 0 => array('actions_new_status' => 'PENDING'),
2099 1 => array('actions_new_status' => 'ACTIVE'),
2100 2 => array('actions_new_status' => 'LOCKED'),
2101 3 => array('actions_new_status' => 'STOPPED'),
2102 4 => array('actions_new_status' => 'REJECTED'),
2103 5 => array('actions_new_status' => 'DELETED'),
2104 6 => array('actions_new_status' => 'MIGRATED'),
2105 7 => array('actions_new_status' => 'DEPLETED')
2108 // Handle it over to generateSelectionBoxFromArray()
2109 $content = generateSelectionBoxFromArray($status, 'actions_new_status', 'actions_new_status', '', '_surfbar', '', $default, '', TRUE, TRUE);
2111 // Return prepared content
2115 //------------------------------------------------------------------------------
2116 // PLEASE DO NOT ADD ANY OTHER FUNCTIONS BELOW THIS LINE IF THEY DON'T "WRAP"
2117 // THE $GLOBALS['surfbar_cache'] ARRAY!
2118 //------------------------------------------------------------------------------
2120 // Initializes the surfbar
2121 function initSurfbar () {
2123 $GLOBALS['surfbar_cache'] = array();
2126 // Private getter for data elements
2127 function getSurfbarData ($element) {
2129 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ' - ENTERED!');
2134 // Is the entry there?
2135 if (isset($GLOBALS['surfbar_cache'][$element])) {
2137 $data = $GLOBALS['surfbar_cache'][$element];
2141 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data . ' - EXIT!');
2145 // Getter for reward from cache
2146 function getSurfbarReward () {
2147 // Get data element and return its contents
2148 return getSurfbarData('reward');
2151 // Getter for costs from cache
2152 function getSurfbarCosts () {
2153 // Get data element and return its contents
2154 return getSurfbarData('costs');
2157 // Getter for URL from cache
2158 function getSurfbarUrl () {
2159 // Get data element and return its contents
2160 return getSurfbarData('url');
2163 // Getter for salt from cache
2164 function getSurfbarSalt () {
2165 // Get data element and return its contents
2166 return getSurfbarData('salt');
2169 // Getter for id from cache
2170 function getSurfbarId () {
2171 // Get data element and return its contents
2172 return getSurfbarData('url_id');
2175 // Getter for userid from cache
2176 function getSurfbarUserid () {
2177 // Get data element and return its contents
2178 return getSurfbarData('url_userid');
2181 // Getter for user reload locks
2182 function getSurfbarUserLocks () {
2183 // Get data element and return its contents
2184 return getSurfbarData('user_locks');
2187 // Getter for reload time
2188 function getSurfbarWaitingTime () {
2189 // Get data element and return its contents
2190 return getSurfbarData('waiting');
2193 // Getter for allowed views
2194 function getSurfbarViewsAllowed () {
2195 // Get data element and return its contents
2196 return getSurfbarData('url_views_allowed');
2199 // Getter for maximum views
2200 function getSurfbarViewsMax () {
2201 // Get data element and return its contents
2202 return getSurfbarData('url_views_max');
2205 // Getter for fixed reload
2206 function getSurfbarFixedReload () {
2207 // Get data element and return its contents
2208 return getSurfbarData('url_fixed_reload');
2211 // Getter for fixed waiting time
2212 function getSurfbarFixedWaitingTime () {
2213 // Get data element and return its contents
2214 return getSurfbarData('url_fixed_waiting');
2217 // Getter for surf lock
2218 function getSurfbarSurfLock () {
2219 // Get data element and return its contents
2220 return getSurfbarData('surf_lock');
2223 // Getter for new status
2224 function getSurfbarNewStatus () {
2225 // Get data element and return its contents
2226 return getSurfbarData('new_status');
2229 // Getter for last salt
2230 function getSurfbarLastSalt () {
2231 // Get data element and return its contents
2232 return getSurfbarData('salts_last_salt');