Ref link fixed, nickname fixed, several rewrites, TODOs.txt updated:
[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 - 2008 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif (!IS_MEMBER()) {
44         redirectToUrl('modules.php?module=index');
45 }
46
47 // Add description as navigation point
48 ADD_DESCR('member', __FILE__);
49
50 // Load current referal clicks
51 $result = SQL_QUERY_ESC("SELECT `ref_clicks` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
52         array(getUserId()), __FILE__, __LINE__);
53 $content = SQL_FETCHARRAY($result);
54 SQL_FREERESULT($result);
55
56 OUTPUT_HTML("<div class=\"tiny\">{--YOUR_PERSONAL_REFLINK--}:<br />
57 <strong><a href=\"{!URL!}/ref.php?refid=".getUserId()."\" target=\"_blank\">{!URL!}/ref.php?ref=".getUserId()."</a></strong><br />
58 <br />");
59
60 if (EXT_IS_ACTIVE('nickname')) {
61         // Add nickname link when nickname is entered
62         $nick = NICKNAME_GET_NICK(getUserId());
63
64         if (!empty($nick)) {
65                 // Display nickname link
66                 OUTPUT_HTML("{--NICKNAME_YOUR_REFLINK--}:<br />
67 <strong><a href=\"{!URL!}/ref.php?ref=".$nick."\" target=\"_blank\">{!URL!}/ref.php?ref=".$nick."</a></strong><br />
68 <br />");
69         } else {
70                 // Display link to nickname form
71                 OUTPUT_HTML("<div class=\"guest_note\">{--NO_NICKNAME_SET--}</strong><br />
72 <a class=\"tiny\" href=\"{!URL!}/modules.php?module=login&amp;what=nickname\">{--PLEASE_CLICK_NICKNAME_FORM--}</a>");
73         }
74 }
75
76 // Clicks on your reflink
77 OUTPUT_HTML("{--YOUR_REFCLICKS--}: <strong>".$content['ref_clicks']."</strong> {--CLICKS--}</div><br /><br />");
78
79 $whereStatement = " WHERE `visible`='Y'";
80 if (IS_ADMIN()) $whereStatement = '';
81 $result = SQL_QUERY("SELECT `id`, `url`, `alternate`, `counter`, `clicks` FROM `{!_MYSQL_PREFIX!}_refbanner`", __FILE__, __LINE__);
82
83 if (SQL_NUMROWS($result) > 0) {
84         // List available ref banners
85         $OUT = ''; $SW = 2;
86         while ($content = SQL_FETCHARRAY($result)) {
87                 $test = str_replace(constant('URL'), constant('PATH'), $content['url']); $size = 0;
88                 if ($test == $content['url']) {
89                         // Download banner (I hope you keep the banner on same server???)
90                         $fp = sendGetRequest($content['url']); $bannerContent = '';
91                         if ((!empty($fp)) && (is_array($fp)) && (count($fp) > 0)) {
92                                 // Loads only found banner, when there is a 404 error this foreach() command
93                                 // will cause an "Invalid argument supplied for foreach()" error
94                                 foreach ($fp as $f) {
95                                         $bannerContent .= $f;
96                                 } // END - foreach
97                         } // END - if
98                         $size = strlen($bannerContent);
99                 } elseif (isFileReadable($test)) {
100                         $size = filesize($test);
101                 }
102
103                 if ($size > 0) $content['alternate'] .= ' ('  .translateComma(round($size / 102.4) / 10) . ' {--KBYTES--})';
104
105                 // Add some more data
106                 $content['sw']     = $SW;
107                 $content['userid'] = getUserId();
108
109                 // Add row
110                 $OUT .= LOAD_TEMPLATE('member_reflinks_row', true, $content);
111
112                 // Switchcolors
113                 $SW = 3 - $SW;
114         } // END - while
115
116         define('__REFLINKS_ROWS', $OUT);
117
118         // Load final template
119         LOAD_TEMPLATE('member_reflinks_table', false, getUserId());
120 } else {
121         // No refbanner found!
122         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('MEMBER_NO_REFBANNER_FOUND'));
123 }
124
125 // Free result
126 SQL_FREERESULT($result);
127
128 // [EOF]
129 ?>