Some improvements
[mailer.git] / inc / modules / member / what-reflinks.php
index 64e00bf64faa9d6cf29f07e77f6e5719695da347..5f746a4933d58aea9fbce2d749920a35fceb84bd 100644 (file)
@@ -17,7 +17,7 @@
  * Needs to be in all Files and every File needs "svn propset           *
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
-       require($INC);
-} elseif (!IS_MEMBER()) {
-       redirectToUrl('modules.php?module=index');
+       die();
+} elseif (!isMember()) {
+       redirectToIndexMemberOnlyModule();
 }
 
 // Add description as navigation point
-ADD_DESCR('member', __FILE__);
+addMenuDescription('member', __FILE__);
 
 // Load current referal clicks
-$result = SQL_QUERY_ESC("SELECT ref_clicks FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
+$result = SQL_QUERY_ESC("SELECT `ref_clicks` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
        array(getUserId()), __FILE__, __LINE__);
-list($c) = SQL_FETCHROW($result);
+
+// Load it
+$content = SQL_FETCHARRAY($result);
+
+// Free result
 SQL_FREERESULT($result);
 
-OUTPUT_HTML("<div class=\"tiny\">{--YOUR_PERSONAL_REFLINK--}:<br />
-<strong><a href=\"{!URL!}/ref.php?refid=".getUserId()."\" target=\"_blank\">{!URL!}/ref.php?ref=".getUserId()."</a></strong><br />
-<br />");
+// Prepare some data
+$content['userid'] = getUserId();
 
-if (EXT_IS_ACTIVE('nickname')) {
+// @TODO Move this into a filter
+if (isExtensionActive('nickname')) {
        // Add nickname link when nickname is entered
-       $nick = NICKNAME_GET_NICK(getUserId());
+       $nick = getNickname(getUserId());
 
        if (!empty($nick)) {
                // Display nickname link
-               OUTPUT_HTML("{--NICKNAME_YOUR_REFLINK--}:<br />
-<strong><a href=\"{!URL!}/ref.php?ref=".$nick."\" target=\"_blank\">{!URL!}/ref.php?ref=".$nick."</a></strong><br />
-<br />");
+               $content['nickname_content'] = loadTemplate('member_reflink_nickname', true, $nick);
        } else {
                // Display link to nickname form
-               OUTPUT_HTML("<div class=\"guest_note\">{--NO_NICKNAME_SET--}</strong><br />
-<a class=\"tiny\" href=\"{!URL!}/modules.php?module=login&amp;what=nickname\">{--PLEASE_CLICK_NICKNAME_FORM--}</a>");
+               $content['nickname_content'] = loadTemplate('member_reflink_no_nickname', true);
        }
-}
+} // END - if
 
-// Clicks on your reflink
-OUTPUT_HTML("{--YOUR_REFCLICKS--}: <strong>".$c."</strong> {--CLICKS--}</div><br /><br />");
 $whereStatement = " WHERE `visible`='Y'";
-if (IS_ADMIN()) $whereStatement = '';
-$result = SQL_QUERY("SELECT id, url, alternate, counter, clicks FROM `{!_MYSQL_PREFIX!}_refbanner`", __FILE__, __LINE__);
+if (isAdmin()) $whereStatement = '';
+$result = SQL_QUERY("SELECT `id`, `url`, `alternate`, `counter`, `clicks` FROM `{?_MYSQL_PREFIX?}_refbanner`", __FILE__, __LINE__);
 
 if (SQL_NUMROWS($result) > 0) {
        // List available ref banners
        $OUT = ''; $SW = 2;
-       while ($content = SQL_FETCHARRAY($result)) {
-               $test = str_replace(constant('URL'), constant('PATH'), $content['url']); $size = 0;
-               if ($test == $content['url']) {
+       while ($row = SQL_FETCHARRAY($result)) {
+               $test = str_replace(getConfig('URL'), getConfig('PATH'), $row['url']); $size = 0;
+               if ($test == $row['url']) {
                        // Download banner (I hope you keep the banner on same server???)
-                       $fp = sendGetRequest($content['url']); $bannerContent = '';
-                       if ((!empty($fp)) && (is_array($fp)) && (count($fp) > 0) {
+                       $fp = sendGetRequest($row['url']); $bannerContent = '';
+                       if ((!empty($fp)) && (is_array($fp)) && (count($fp) > 0)) {
                                // Loads only found banner, when there is a 404 error this foreach() command
                                // will cause an "Invalid argument supplied for foreach()" error
                                foreach ($fp as $f) {
                                        $bannerContent .= $f;
-                               }
-                       }
+                               } // END - foreach
+                       } // END - if
                        $size = strlen($bannerContent);
                } elseif (isFileReadable($test)) {
                        $size = filesize($test);
                }
 
-               if ($size > 0) $content['alternate'] .= " (".translateComma(round($size/102.4)/10)." {--KBYTES--})";
+               // Empty alternative text?
+               if (empty($row['alternate'])) {
+                       // Then set default
+                       $row['alternate'] = '{?MAIN_TITLE?} - {?SLOGAN?}';
+               } // END - if
 
-               // Load banner data
-               // @TODO Rewritings: alt->alternate,cnt->counter,cks->clicks,uid->userid in template
-               $content = array(
-                       'sw'  => $SW,
-                       'url' => $content['url'],
-                       'alt' => $content['alternate'],
-                       'cnt' => $content['counter'],
-                       'cks' => $content['clicks'],
-                       'uid' => getUserId(),
-                       'id'  => $content['id'],
-               );
+               if ($size > 0) $row['alternate'] .= ' ('  .translateComma(round($size / 102.4) / 10) . ' {--KBYTES--})';
+
+               // Add some more data
+               $row['sw']     = $SW;
+               $row['userid'] = getUserId();
 
                // Add row
-               $OUT .= LOAD_TEMPLATE("member_reflinks_row", true, $content);
+               $OUT .= loadTemplate('member_reflinks_row', true, $row);
 
                // Switchcolors
                $SW = 3 - $SW;
-       }
-
-       define('__REFLINKS_ROWS', $OUT);
+       } // END - while
 
        // Load final template
-       LOAD_TEMPLATE("member_reflinks_table", false, getUserId());
+       $content['refbanner_content'] = loadTemplate('member_reflinks_table', true, $OUT);
 } else {
        // No refbanner found!
-       LOAD_TEMPLATE('admin_settings_saved', false, getMessage('MEMBER_NO_REFBANNER_FOUND'));
+       $content['refbanner_content'] = loadTemplate('admin_settings_saved', true, getMessage('MEMBER_NO_REFBANNER_FOUND'));
 }
 
 // Free result
 SQL_FREERESULT($result);
 
-//
+// Load main template
+loadTemplate('member_reflink', false, $content);
+
+// [EOF]
 ?>