Fix for endless loop
[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 $content = SQL_FETCHARRAY($result);
53 SQL_FREERESULT($result);
54
55 outputHtml("<div class=\"tiny\">{--YOUR_PERSONAL_REFLINK--}:<br />
56 <strong><a href=\"{?URL?}/ref.php?refid=".getUserId()."\" target=\"_blank\">{?URL?}/ref.php?ref=".getUserId()."</a></strong><br />
57 <br />");
58
59 if (isExtensionActive('nickname')) {
60         // Add nickname link when nickname is entered
61         $nick = getNickname(getUserId());
62
63         if (!empty($nick)) {
64                 // Display nickname link
65                 outputHtml("{--NICKNAME_YOUR_REFLINK--}:<br />
66 <strong><a href=\"{?URL?}/ref.php?ref=".$nick."\" target=\"_blank\">{?URL?}/ref.php?ref=".$nick."</a></strong><br />
67 <br />");
68         } else {
69                 // Display link to nickname form
70                 outputHtml("<div class=\"guest_note\">{--NO_NICKNAME_SET--}</strong><br />
71 <a class=\"tiny\" href=\"{?URL?}/modules.php?module=login&amp;what=nickname\">{--PLEASE_CLICK_NICKNAME_FORM--}</a>");
72         }
73 }
74
75 // Clicks on your reflink
76 outputHtml("{--YOUR_REFCLICKS--}: <strong>".$content['ref_clicks']."</strong> {--CLICKS--}</div><br /><br />");
77
78 $whereStatement = " WHERE `visible`='Y'";
79 if (isAdmin()) $whereStatement = '';
80 $result = SQL_QUERY("SELECT `id`, `url`, `alternate`, `counter`, `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner`", __FILE__, __LINE__);
81
82 if (SQL_NUMROWS($result) > 0) {
83         // List available ref banners
84         $OUT = ''; $SW = 2;
85         while ($content = SQL_FETCHARRAY($result)) {
86                 $test = str_replace(getConfig('URL'), getConfig('PATH'), $content['url']); $size = 0;
87                 if ($test == $content['url']) {
88                         // Download banner (I hope you keep the banner on same server???)
89                         $fp = sendGetRequest($content['url']); $bannerContent = '';
90                         if ((!empty($fp)) && (is_array($fp)) && (count($fp) > 0)) {
91                                 // Loads only found banner, when there is a 404 error this foreach() command
92                                 // will cause an "Invalid argument supplied for foreach()" error
93                                 foreach ($fp as $f) {
94                                         $bannerContent .= $f;
95                                 } // END - foreach
96                         } // END - if
97                         $size = strlen($bannerContent);
98                 } elseif (isFileReadable($test)) {
99                         $size = filesize($test);
100                 }
101
102                 if ($size > 0) $content['alternate'] .= ' ('  .translateComma(round($size / 102.4) / 10) . ' {--KBYTES--})';
103
104                 // Add some more data
105                 $content['sw']     = $SW;
106                 $content['userid'] = getUserId();
107
108                 // Add row
109                 $OUT .= loadTemplate('member_reflinks_row', true, $content);
110
111                 // Switchcolors
112                 $SW = 3 - $SW;
113         } // END - while
114
115         // Load final template
116         loadTemplate('member_reflinks_table', false, $OUT);
117 } else {
118         // No refbanner found!
119         loadTemplate('admin_settings_saved', false, getMessage('MEMBER_NO_REFBANNER_FOUND'));
120 }
121
122 // Free result
123 SQL_FREERESULT($result);
124
125 // [EOF]
126 ?>