2 /************************************************************************
3 * MXChange v0.2.1 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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Admin has added an URL with given user id
41 function SURFBAR_ADMIN_ADD_URL ($url, $uid, $reward) {
42 // Is this really an admin?
48 // Check if that URL does not exist
49 if (SURFBAR_LOOKUP_BY_URL($url, $uid)) {
54 // Register the new URL
55 return SURFBAR_REGISTER_URL($url, $uid, $reward, "CONFIRMED", "unlock");
58 function SURFBAR_LOOKUP_BY_URL ($url) {
59 // Now lookup that given URL by itself
60 $urlArray = SURFBAR_GET_URL_DATA($url, "url");
63 return (count($urlArray) > 0);
65 // Load URL data by given search term and column
66 function SURFBAR_GET_URL_DATA ($searchTerm, $column="id", $order="id", $sort="ASC", $group="id") {
69 // By default nothing is found
70 $lastUrlData = array();
72 // Is the column an id number?
73 if (($column == "id") || ($column == "userid")) {
75 $searchTerm = bigintval($searchTerm);
79 $result = SQL_QUERY_ESC("SELECT id, userid, url, reward, views_total, status, registered, last_locked, lock_reason
80 FROM "._MYSQL_PREFIX."_surfbar_urls
83 array($column, $searchTerm, $order, $sort), __FILE__, __LINE__);
85 // Is there at least one record?
86 if (SQL_NUMROWS($result) > 0) {
88 while ($dataRow = SQL_FETCHARRAY($result)) {
89 // Shall we group these results?
91 // Add the row by id as index
92 $lastUrlData[$dataRow['id']] = $dataRow;
95 $lastUrlData[$dataRow[$group]][$dataRow['id']] = $dataRow;
101 SQL_FREERESULT($result);
106 // Registers an URL with the surfbar. You should have called SURFBAR_LOOKUP_BY_URL() first!
107 function SURFBAR_REGISTER_URL ($url, $uid, $reward, $status="PENDING", $addMode="reg") {
110 // Make sure by the user registered URLs are always pending
111 if ($addMode == "reg") $status = "PENDING";
116 'frametester' => FRAMETESTER($url),
118 'reward' => TRANSLATE_COMMA($reward),
119 'status' => SURFBAR_TRANSLATE_STATUS($status)
122 // Insert the URL into database
123 $content['insert_id'] = SURFBAR_INSERT_URL_BY_ARRAY($content);
125 // If in reg-mode we notify admin
126 if (($addMode == "reg") || ($_CONFIG['surfbar_notify_admin_unlock'] == "Y")) {
127 // Notify admin even when he as unlocked an email
128 SURFBAR_NOTIFY_ADMIN("url_{$addMode}", $content);
132 SURFBAR_NOTIFY_USER("url_{$addMode}", $content);
134 // Return the insert id
135 return $content['insert_id'];
137 // Inserts an url by given data array and return the insert id
138 function SURFBAR_INSERT_URL_BY_ARRAY ($urlData) {
139 // Just run the insert query for now
140 SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_surfbar_urls (userid, url, reward, status) VALUES(%s, '%s', %s, '%s')",
142 bigintval($urlData['uid']),
143 bigintval($urlData['url']),
144 (float)$urlData['reward'],
146 ), __FILE__, __LINE__
150 return SQL_INSERTID();
152 // Notify admin(s) with a selected message and content
153 function SURFBAR_NOTIFY_ADMIN ($messageType, $content) {
154 // Prepare template name
155 $templateName = sprintf("admin_surfbar_%s", $messageType);
158 $eval = sprintf("\$subject = ADMIN_SURFBAR_NOTIFY_%s_SUBJECT;",
159 strtoupper($messageType)
163 // Send the notification out
164 SEND_ADMIN_NOTIFICATION($subject, $templateName, $content, $content['uid']);
166 // Notify the user about the performed action
167 function SURFBAR_NOTIFY_USER ($messageType, $content) {
168 // Prepare template name
169 $templateName = sprintf("member_surfbar_%s", $messageType);
172 $eval = sprintf("\$subject = MEMBER_SURFBAR_NOTIFY_%s_SUBJECT;",
173 strtoupper($messageType)
178 $mailText = LOAD_EMAIL_TEMPLATE($templateName, $content);
181 SEND_EMAIL($content['uid'], $subject, $mailText);
183 // Translate the URL status
184 function SURFBAR_TRANSLATE_STATUS ($status) {
185 // Create constant name
186 $constantName = sprintf("SURFBAR_URL_STATUS_%s", strtoupper($status));
188 // Set default translated status
189 $statusTranslated = "!".$constantName."!";
191 // Generate eval() command
192 if (defined($constantName)) {
193 $eval = "\$statusTranslated = ".$constantName.";";
198 return $statusTranslated;