]> git.mxchange.org Git - mailer.git/blob - inc/libs/surfbar_functions.php
8cd6082367ad4998b136abddcd4e26ef568095f1
[mailer.git] / inc / libs / surfbar_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/31/2008 *
4  * ===============                              Last change: 08/31/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : surfbar_functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Functions for surfbar                            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Funktionen fuer die Surfbar                      *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
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";
37         require($INC);
38 }
39
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?
43         if (!IS_ADMIN()) {
44                 // Then leave here
45                 return false;
46         } // END - if
47
48         // Check if that URL does not exist
49         if (SURFBAR_LOOKUP_BY_URL($url, $uid)) {
50                 // Already found!
51                 return false;
52         } // END - if
53
54         // Register the new URL
55         return SURFBAR_REGISTER_URL($url, $uid, $reward, "CONFIRMED", "unlock");
56 }
57 // Looks up by an URL
58 function SURFBAR_LOOKUP_BY_URL ($url) {
59         // Now lookup that given URL by itself
60         $urlArray = SURFBAR_GET_URL_DATA($url, "url");
61
62         // Was it found?
63         return (count($urlArray) > 0);
64 }
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") {
67         global $lastUrlData;
68
69         // By default nothing is found
70         $lastUrlData = array();
71
72         // Is the column an id number?
73         if (($column == "id") || ($column == "userid")) {
74                 // Extra secure input
75                 $searchTerm = bigintval($searchTerm);
76         } // END - if
77
78         // Look up the record
79         $result = SQL_QUERY_ESC("SELECT id, userid, url, reward, views_total, status, registered, last_locked, lock_reason
80 FROM "._MYSQL_PREFIX."_surfbar_urls
81 WHERE %s='%s'
82 ORDER BY %s %s",
83                 array($column, $searchTerm, $order, $sort), __FILE__, __LINE__);
84
85         // Is there at least one record?
86         if (SQL_NUMROWS($result) > 0) {
87                 // Then load all!
88                 while ($dataRow = SQL_FETCHARRAY($result)) {
89                         // Shall we group these results?
90                         if ($group == "id") {
91                                 // Add the row by id as index
92                                 $lastUrlData[$dataRow['id']] = $dataRow;
93                         } else {
94                                 // Group entries
95                                 $lastUrlData[$dataRow[$group]][$dataRow['id']] = $dataRow;
96                         }
97                 } // END - while
98         } // END - if
99
100         // Free the result
101         SQL_FREERESULT($result);
102
103         // Return the result
104         return $lastUrlData;
105 }
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") {
108         global $_CONFIG;
109
110         // Make sure by the user registered URLs are always pending
111         if ($addMode == "reg") $status = "PENDING";
112
113         // Prepare content
114         $content = array(
115                 'url'         => $url,
116                 'frametester' => FRAMETESTER($url),
117                 'uid'         => $uid,
118                 'reward'      => $reward,
119                 'status'      => $status
120         );
121
122         // Insert the URL into database
123         $content['insert_id'] = SURFBAR_INSERT_URL_BY_ARRAY($content);
124
125         // Translate status and reward
126         $content['status'] = SURFBAR_TRANSLATE_STATUS($content['status']);
127         $content['reward'] = TRANSLATE_COMMA($content['reward']);
128
129         // If in reg-mode we notify admin
130         if (($addMode == "reg") || ($_CONFIG['surfbar_notify_admin_unlock'] == "Y")) {
131                 // Notify admin even when he as unlocked an email
132                 SURFBAR_NOTIFY_ADMIN("url_{$addMode}", $content);
133         } // END - if
134
135         // Send mail to user
136         SURFBAR_NOTIFY_USER("url_{$addMode}", $content);
137
138         // Return the insert id
139         return $content['insert_id'];
140 }
141 // Inserts an url by given data array and return the insert id
142 function SURFBAR_INSERT_URL_BY_ARRAY ($urlData) {
143         // Just run the insert query for now
144         SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_surfbar_urls (userid, url, reward, status) VALUES(%s, '%s', %s, '%s')",
145                 array(
146                         bigintval($urlData['uid']),
147                         bigintval($urlData['url']),
148                         (float)$urlData['reward'],
149                         $urlData['status']
150                 ), __FILE__, __LINE__
151         );
152
153         // Return insert id
154         return SQL_INSERTID();
155 }
156 // Notify admin(s) with a selected message and content
157 function SURFBAR_NOTIFY_ADMIN ($messageType, $content) {
158         // Prepare template name
159         $templateName = sprintf("admin_surfbar_%s", $messageType);
160
161         // Prepare subject
162         $eval = sprintf("\$subject = ADMIN_SURFBAR_NOTIFY_%s_SUBJECT;",
163                 strtoupper($messageType)
164         );
165         eval($eval);
166
167         // Send the notification out
168         SEND_ADMIN_NOTIFICATION($subject, $templateName, $content, $content['uid']);
169 }
170 // Notify the user about the performed action
171 function SURFBAR_NOTIFY_USER ($messageType, $content) {
172         // Prepare template name
173         $templateName = sprintf("member_surfbar_%s", $messageType);
174
175         // Prepare subject
176         $eval = sprintf("\$subject = MEMBER_SURFBAR_NOTIFY_%s_SUBJECT;",
177                 strtoupper($messageType)
178         );
179         eval($eval);
180
181         // Load template
182         $mailText = LOAD_EMAIL_TEMPLATE($templateName, $content);
183
184         // Send the email
185         SEND_EMAIL($content['uid'], $subject, $mailText);
186 }
187 // Translate the URL status
188 function SURFBAR_TRANSLATE_STATUS ($status) {
189         // Create constant name
190         $constantName = sprintf("SURFBAR_URL_STATUS_%s", strtoupper($status));
191
192         // Set default translated status
193         $statusTranslated = "!".$constantName."!";
194
195         // Generate eval() command
196         if (defined($constantName)) {
197                 $eval = "\$statusTranslated = ".$constantName.";";
198                 eval($eval);
199         } // END - if
200
201         // Return result
202         return $statusTranslated;
203 }
204 //
205 ?>