From 879d21c8fbaf8868194aeb456a77ab95b0dc43b0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 29 Aug 2010 19:26:09 +0000 Subject: [PATCH] More usage of EL, code rewrites/cleanups, SQLs improved: - More usage of EL for admin templates (deletion of emails and notification) - Unneccessary array re-initialization removed/cleaned up - SQLs improved, a "LIMIT 1" was missing - TODOs.txt updated --- DOCS/TODOs.txt | 10 ++--- inc/gen_mediadata.php | 45 ++++++++++--------- inc/language/html_mail_de.php | 2 +- inc/modules/admin/what-del_email.php | 8 ++-- inc/modules/member/what-stats.php | 16 ++----- .../de/html/admin/admin_del_email_bonus.tpl | 2 +- .../de/html/admin/admin_del_email_notify.tpl | 2 +- 7 files changed, 40 insertions(+), 45 deletions(-) diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index f0f933ba63..ecde42a1f5 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -174,11 +174,11 @@ ./inc/modules/member/what-unconfirmed.php:143: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() ./inc/modules/order.php:76: // @TODO Unused: 2,4 ./inc/monthly/monthly_bonus.php:69: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1173: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1428: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() -./inc/mysql-manager.php:1536: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1903: // @TODO Rewrite this to a filter -./inc/mysql-manager.php:1947:// @TODO Fix inconsistency between last_module and getWhat() +./inc/mysql-manager.php:1174: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1429: // @TODO Try to rewrite this to $content = SQL_FETCHARRAY() +./inc/mysql-manager.php:1537: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1904: // @TODO Rewrite this to a filter +./inc/mysql-manager.php:1948:// @TODO Fix inconsistency between last_module and getWhat() ./inc/mysql-manager.php:370: // @TODO Try to rewrite this to one or more functions ./inc/mysql-manager.php:46:// @TODO Can we cache this? ./inc/reset/reset_beg.php:51:// @TODO This should be converted in a daily beg rallye diff --git a/inc/gen_mediadata.php b/inc/gen_mediadata.php index 8922660483..cd3fdb2ec2 100644 --- a/inc/gen_mediadata.php +++ b/inc/gen_mediadata.php @@ -42,47 +42,52 @@ if (!defined('__SECURITY')) { die(); } // END - if -// Init variables -$bsent = '0'; $bclicks = '0'; $bcount = '0'; +// Init array/varriable +$bcount = '0'; +$content = array( + 'normal_send' => 0, + 'normal_clicks' => 0, + 'bonus_send' => 0, + 'bonus_clicks' => 0 +); // Check for normal mails $result_media = SQL_QUERY('SELECT - SUM(`max_rec`) AS max_rec, - SUM(`clicks`) AS clicks + SUM(`max_rec`) AS `normal_send`, + SUM(`clicks`) AS `normal_clicks` FROM `{?_MYSQL_PREFIX?}_user_stats`', __FILE__, __LINE__); -list($nsent, $nclicks) = SQL_FETCHROW($result_media); -if (empty($nsent)) $nsent = '0'; -if (empty($nclicks)) $nclicks = '0'; +$content = merge_array($content, SQL_FETCHARRAY($result_media)); // Free memory SQL_FREERESULT($result_media); -// Count mail orders -$ncount = countSumTotalData('', 'user_stats', 'id', '', true); - // Check for bonus extension if (isExtensionActive('bonus')) { // Count bonus mails $bcount = countSumTotalData('', 'bonus', 'id', '', true); // Check for bonus mails - $result_media = SQL_QUERY('SELECT SUM(mails_sent) AS bonus_sent, SUM(clicks) AS bonus_clicks -FROM `{?_MYSQL_PREFIX?}_bonus`', __FILE__, __LINE__); - list($bsent, $bclicks) = SQL_FETCHROW($result_media); - if (empty($bsent)) $bsent = '0'; - if (empty($bclicks)) $bclicks = '0'; + $result_media = SQL_QUERY('SELECT + SUM(`mails_send`) AS `bonus_send`, + SUM(`clicks`) AS `bonus_clicks` +FROM + `{?_MYSQL_PREFIX?}_bonus`', __FILE__, __LINE__); + $content = merge_array($content, SQL_FETCHARRAY($result_media)); + + // Free memory + SQL_FREERESULT($result_media); } // END - if // Load (maybe) missing file loadIncludeOnce('inc/libs/mediadata_functions.php'); // Insert info to database -updateMediadataEntry(array('total_send' , 'normal_send') , 'init', $nsent); -updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'init', $nclicks); -updateMediadataEntry(array('total_orders', 'normal_orders'), 'init', $ncount); -updateMediadataEntry(array('total_send' , 'bonus_send' ) , 'init', $bsent); -updateMediadataEntry(array('total_clicks', 'bonus_clicks') , 'init', $bclicks); +updateMediadataEntry(array('total_send' , 'normal_send') , 'init', $content['normal_send']); +updateMediadataEntry(array('total_clicks', 'normal_clicks'), 'init', $content['normal_clicks']); +updateMediadataEntry(array('total_orders', 'normal_orders'), 'init', countSumTotalData('', 'user_stats', 'id', '', true)); +updateMediadataEntry(array('total_send' , 'bonus_send' ) , 'init', $content['bonus_send']); +updateMediadataEntry(array('total_clicks', 'bonus_clicks') , 'init', $content['bonus_clicks']); updateMediadataEntry(array('total_orders', 'bonus_orders') , 'init', $bcount); // Aquire total used points diff --git a/inc/language/html_mail_de.php b/inc/language/html_mail_de.php index ca633e555d..383593a360 100644 --- a/inc/language/html_mail_de.php +++ b/inc/language/html_mail_de.php @@ -44,7 +44,7 @@ if (!defined('__SECURITY')) { // Language definitions addMessages(array( - 'ADMIN_HTML_DOWNLOAD_CLASS' => "Bitte laden Sie sich die Klasse PHPMailer herunter, um diese Funktion nutzen zu können.", + 'ADMIN_HTML_DOWNLOAD_CLASS' => "Bitte laden Sie sich die Klasse PHPMailer herunter, um diese Funktion nutzen zu können.", 'MEMBER_HTML_INTRO' => "HTML-Emfpang - Einstellung", 'MEMBER_HTML_TEXT' => "In unserem {?mt_word?} ist das Empfangen von HTML-Mails nun möglich. Gleichzeitig können Sie auch selber HTML-Mails versenden. Möchten Sie dies beides nutzen?", 'MEMBER_HTML_ORDER_INTRO' => "HTML- oder normale Text-Mails versenden?", diff --git a/inc/modules/admin/what-del_email.php b/inc/modules/admin/what-del_email.php index 819770ab74..67e953a38c 100644 --- a/inc/modules/admin/what-del_email.php +++ b/inc/modules/admin/what-del_email.php @@ -38,7 +38,7 @@ // Some security stuff... if ((!defined('__SECURITY')) || (!isAdmin())) { die(); -} +} // END - if // Add description as navigation point addMenuDescription('admin', __FILE__); @@ -164,7 +164,7 @@ LIMIT 1", loadTemplate('admin_settings_saved', false, '{--ADMIN_USER_STATS_REMOVED--}'); } elseif ((isGetRequestParameterSet('bid')) && (isExtensionActive('bonus'))) { // Load data from bonus mail - $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s", + $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp`, `mails_sent` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1", array(bigintval(getRequestParameter('bid'))), __FILE__, __LINE__); // Delete mail only once @@ -187,7 +187,6 @@ LIMIT 1", $cnt += SQL_AFFECTEDROWS(); // Prepare data for the template - $content['url'] = generateDerefererUrl($content['url']); $content['timestamp'] = generateDateTime($content['timestamp'], 0); $content['cnt'] = $cnt; @@ -202,7 +201,7 @@ LIMIT 1", SQL_FREERESULT($result); } elseif ((isGetRequestParameterSet('nid')) && (isExtensionInstalledAndNewer('bonus', '0.8.7'))) { // Load data from bonus mail - $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s", + $result = SQL_QUERY_ESC("SELECT `id`, `subject`, `url`, `timestamp` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `id`=%s LIMIT 1", array(bigintval(getRequestParameter('nid'))), __FILE__, __LINE__); // Delete mail only once @@ -222,7 +221,6 @@ LIMIT 1", $cnt += SQL_AFFECTEDROWS(); // Prepare data for the template - $content['url'] = generateDerefererUrl($content['url']); $content['timestamp'] = generateDateTime($content['timestamp'], 0); $content['cnt'] = $cnt; diff --git a/inc/modules/member/what-stats.php b/inc/modules/member/what-stats.php index 8a37457834..b10dd0a118 100644 --- a/inc/modules/member/what-stats.php +++ b/inc/modules/member/what-stats.php @@ -100,21 +100,13 @@ if (!SQL_HASZERONUMS($result)) { $OUT = ''; while ($content = SQL_FETCHARRAY($result)) { // Prepare data for the template - $content = array( - 'cat_id' => $content['cat_id'], - 'payment_id' => $content['payment_id'], - 'url' => $content['url'], - 'timestamp_ordered' => generateDateTime($content['timestamp_ordered'], 2), - 'max_rec' => $content['max_rec'], - 'timestamp_sent' => generateDateTime($content['timestamp_send'], 2), - 'clicks' => $content['clicks'], - 'subject' => $content['subject'], - 'percents' => ($content['clicks'] / $content['max_rec'] * 100), - ); + $content['timestamp_ordered'] = generateDateTime($content['timestamp_ordered'], 2); + $content['timestamp_sent'] = generateDateTime($content['timestamp_send'], 2); + $content['percents'] = ($content['clicks'] / $content['max_rec'] * 100); // Load row template and switch colors $OUT .= loadTemplate('member_stats_row', true, $content); - } // END - if + } // END - while // Load main template $main_content['stats'] = loadTemplate('member_stats_table', true, $OUT); diff --git a/templates/de/html/admin/admin_del_email_bonus.tpl b/templates/de/html/admin/admin_del_email_bonus.tpl index 01f9ac1b18..4e467eb2bc 100644 --- a/templates/de/html/admin/admin_del_email_bonus.tpl +++ b/templates/de/html/admin/admin_del_email_bonus.tpl @@ -15,7 +15,7 @@ $content[id] $content[subject] - {--ADMIN_TEST_URL--} + {--ADMIN_TEST_URL--} $content[timestamp] $content[cnt] diff --git a/templates/de/html/admin/admin_del_email_notify.tpl b/templates/de/html/admin/admin_del_email_notify.tpl index 1f40e5c244..259e258b76 100644 --- a/templates/de/html/admin/admin_del_email_notify.tpl +++ b/templates/de/html/admin/admin_del_email_notify.tpl @@ -14,7 +14,7 @@ $content[id] $content[subject] - {--ADMIN_TEST_URL--} + {--ADMIN_TEST_URL--} $content[timestamp] $content[cnt] -- 2.39.5