5f746a4933d58aea9fbce2d749920a35fceb84bd
[mailer.git] / inc / modules / member / what-reflinks.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/19/2003 *
4  * ===============                              Last change: 09/10/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-reflinks.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Referal links                                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Referal-Links                                    *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } elseif (!isMember()) {
43         redirectToIndexMemberOnlyModule();
44 }
45
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
48
49 // Load current referal clicks
50 $result = SQL_QUERY_ESC("SELECT `ref_clicks` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
51         array(getUserId()), __FILE__, __LINE__);
52
53 // Load it
54 $content = SQL_FETCHARRAY($result);
55
56 // Free result
57 SQL_FREERESULT($result);
58
59 // Prepare some data
60 $content['userid'] = getUserId();
61
62 // @TODO Move this into a filter
63 if (isExtensionActive('nickname')) {
64         // Add nickname link when nickname is entered
65         $nick = getNickname(getUserId());
66
67         if (!empty($nick)) {
68                 // Display nickname link
69                 $content['nickname_content'] = loadTemplate('member_reflink_nickname', true, $nick);
70         } else {
71                 // Display link to nickname form
72                 $content['nickname_content'] = loadTemplate('member_reflink_no_nickname', true);
73         }
74 } // END - if
75
76 $whereStatement = " WHERE `visible`='Y'";
77 if (isAdmin()) $whereStatement = '';
78 $result = SQL_QUERY("SELECT `id`, `url`, `alternate`, `counter`, `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner`", __FILE__, __LINE__);
79
80 if (SQL_NUMROWS($result) > 0) {
81         // List available ref banners
82         $OUT = ''; $SW = 2;
83         while ($row = SQL_FETCHARRAY($result)) {
84                 $test = str_replace(getConfig('URL'), getConfig('PATH'), $row['url']); $size = 0;
85                 if ($test == $row['url']) {
86                         // Download banner (I hope you keep the banner on same server???)
87                         $fp = sendGetRequest($row['url']); $bannerContent = '';
88                         if ((!empty($fp)) && (is_array($fp)) && (count($fp) > 0)) {
89                                 // Loads only found banner, when there is a 404 error this foreach() command
90                                 // will cause an "Invalid argument supplied for foreach()" error
91                                 foreach ($fp as $f) {
92                                         $bannerContent .= $f;
93                                 } // END - foreach
94                         } // END - if
95                         $size = strlen($bannerContent);
96                 } elseif (isFileReadable($test)) {
97                         $size = filesize($test);
98                 }
99
100                 // Empty alternative text?
101                 if (empty($row['alternate'])) {
102                         // Then set default
103                         $row['alternate'] = '{?MAIN_TITLE?} - {?SLOGAN?}';
104                 } // END - if
105
106                 if ($size > 0) $row['alternate'] .= ' ('  .translateComma(round($size / 102.4) / 10) . ' {--KBYTES--})';
107
108                 // Add some more data
109                 $row['sw']     = $SW;
110                 $row['userid'] = getUserId();
111
112                 // Add row
113                 $OUT .= loadTemplate('member_reflinks_row', true, $row);
114
115                 // Switchcolors
116                 $SW = 3 - $SW;
117         } // END - while
118
119         // Load final template
120         $content['refbanner_content'] = loadTemplate('member_reflinks_table', true, $OUT);
121 } else {
122         // No refbanner found!
123         $content['refbanner_content'] = loadTemplate('admin_settings_saved', true, getMessage('MEMBER_NO_REFBANNER_FOUND'));
124 }
125
126 // Free result
127 SQL_FREERESULT($result);
128
129 // Load main template
130 loadTemplate('member_reflink', false, $content);
131
132 // [EOF]
133 ?>