From 41d7cc2d4ab3b725d1cd2cbe022dd49fbfc0065a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 15 Nov 2009 19:09:00 +0000 Subject: [PATCH] detectExtraTemplatePath() cached, ext-network continued: - Function detectExtraTemplatePath() is now 'cached' by $GLOBALS usage - Extension ext-network contined, so a selection box for networks is generated --- .gitattributes | 2 + inc/functions.php | 133 +++++++++++++----- inc/language/de.php | 1 + inc/language/network_de.php | 2 + inc/libs/network_functions.php | 36 +++++ inc/modules/admin/what-list_network_types.php | 10 ++ inc/modules/admin/what-list_payouts.php | 4 +- inc/modules/admin/what-stats_mods.php | 5 +- inc/mysql-manager.php | 52 +++---- templates/de/html/select/.htaccess | 1 + .../de/html/select/select_network_box.tpl | 17 +++ 11 files changed, 190 insertions(+), 73 deletions(-) create mode 100644 templates/de/html/select/.htaccess create mode 100644 templates/de/html/select/select_network_box.tpl diff --git a/.gitattributes b/.gitattributes index 5c459e0ef7..44b342d3ad 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1588,6 +1588,8 @@ templates/de/html/register_header.tpl -text templates/de/html/removeip_level.tpl -text templates/de/html/runtime_fatal_row.tpl -text templates/de/html/runtime_fatal_table.tpl -text +templates/de/html/select/.htaccess -text +templates/de/html/select/select_network_box.tpl -text templates/de/html/show_bonus.tpl -text templates/de/html/show_bonus_footer.tpl -text templates/de/html/show_bonus_header.tpl -text diff --git a/inc/functions.php b/inc/functions.php index d077a3c7a8..521a3fa7ba 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -312,7 +312,7 @@ function loadTemplate ($template, $return = false, $content = array()) { eval($GLOBALS['template_eval'][$template]); } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) { // Only admins shall see this warning or when installation mode is active - $ret = '
{--TEMPLATE_404--}
+ $ret = '
{--TEMPLATE_404--}
(' . $template . ')

{--TEMPLATE_CONTENT--} @@ -350,44 +350,53 @@ function detectExtraTemplatePath ($template) { // Default is empty $extraPath = ''; - // Check for admin/guest/member templates - if (substr($template, 0, 6) == 'admin_') { - // Admin template found - $extraPath = 'admin/'; - } elseif (substr($template, 0, 6) == 'guest_') { - // Guest template found - $extraPath = 'guest/'; - } elseif (substr($template, 0, 7) == 'member_') { - // Member template found - $extraPath = 'member/'; - } elseif (substr($template, 0, 8) == 'install_') { - // Installation template found - $extraPath = 'install/'; - } elseif (substr($template, 0, 4) == 'ext_') { - // Extension template found - $extraPath = 'ext/'; - } elseif (substr($template, 0, 3) == 'la_') { - // 'Logical-area' template found - $extraPath = 'la/'; - } elseif (substr($template, 0, 3) == 'js_') { - // JavaScript template found - $extraPath = 'js/'; - } elseif (substr($template, 0, 5) == 'menu_') { - // Menu template found - $extraPath = 'menu/'; - } else { - // Test for extension - $test = substr($template, 0, strpos($template, '_')); + // Do we have cache? + if (!isset($GLOBALS['extra_path'][$template])) { + // Check for admin/guest/member/etc. templates + if (substr($template, 0, 6) == 'admin_') { + // Admin template found + $extraPath = 'admin/'; + } elseif (substr($template, 0, 6) == 'guest_') { + // Guest template found + $extraPath = 'guest/'; + } elseif (substr($template, 0, 7) == 'member_') { + // Member template found + $extraPath = 'member/'; + } elseif (substr($template, 0, 7) == 'select_') { + // Selection template found + $extraPath = 'select/'; + } elseif (substr($template, 0, 8) == 'install_') { + // Installation template found + $extraPath = 'install/'; + } elseif (substr($template, 0, 4) == 'ext_') { + // Extension template found + $extraPath = 'ext/'; + } elseif (substr($template, 0, 3) == 'la_') { + // 'Logical-area' template found + $extraPath = 'la/'; + } elseif (substr($template, 0, 3) == 'js_') { + // JavaScript template found + $extraPath = 'js/'; + } elseif (substr($template, 0, 5) == 'menu_') { + // Menu template found + $extraPath = 'menu/'; + } else { + // Test for extension + $test = substr($template, 0, strpos($template, '_')); - // Probe for valid extension name - if (isExtensionNameValid($test)) { - // Set extra path to extension's name - $extraPath = $test . '/'; - } // END - if - } + // Probe for valid extension name + if (isExtensionNameValid($test)) { + // Set extra path to extension's name + $extraPath = $test . '/'; + } // END - if + } + + // Store it in cache + $GLOBALS['extra_path'][$template] = $extraPath; + } // END - if // Return result - return $extraPath; + return $GLOBALS['extra_path'][$template]; } // Loads an email template and compiles it @@ -3815,6 +3824,58 @@ function sendModeMails ($mod, $modes) { loadTemplate('admin_settings_saved', false, $content); } +// Generates a 'selection box' from given array +function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionContent) { + // Start the output + $OUT = ''; + + // Prepare output + $content = array( + 'selection_box' => $OUT, + 'module' => getModule(), + 'what' => getWhat() + ); + + // Load template and return it + return loadTemplate('select_' . $name . '_box', true, $content); +} + +// Get a module from filename and access level +function getModuleFromFileName ($file, $accessLevel) { + // Default is 'invalid'; + $modCheck = 'invalid'; + + // @TODO This is still very static, rewrite it somehow + switch ($accessLevel) { + case 'admin': + $modCheck = 'admin'; + break; + + case 'sponsor': + case 'guest': + case 'member': + $modCheck = getModule(); + break; + + default: // Unsupported file name / access level + debug_report_bug('Unsupported file name=' . basename($file) . '/access level=' . $accessLevel); + break; + } + + // Return result + return $modCheck; +} + ////////////////////////////////////////////////// // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS // ////////////////////////////////////////////////// diff --git a/inc/language/de.php b/inc/language/de.php index 8873a637a1..32e8bafd62 100644 --- a/inc/language/de.php +++ b/inc/language/de.php @@ -1138,6 +1138,7 @@ addMessages(array( 'ADMIN_EXTENSIONS_REMOVED' => "Es wurden %s Erweiterungen aus Ihrem {?mt_word?} entfernt.", 'ADMIN_WARNING_SQL_PATCHES_MISSING' => "Eine essentielle Erweiterung sql_patches ist noch nicht installiert. Bitte erledigen Sie dies bald, da Ihr {?mt_word?} sonst nicht funktioniert.", 'ADMIN_EXTENSION_IS_NON_PRODUCTIVE' => "Die von Ihnen ausgewählte Erweiterung %s ist noch nicht für den produktiven Betrieb freigegeben und befindet sich somit noch in der Entwicklung. Bitte nur verwenden, wenn Sie wissen, was Sie tun.", + 'ADMIN_ENTRIES_404' => "Es wurden keine Einträge gefunden.", 'MEMBER_MAIL_BONUS_CONFIRMED_ON' => "Sie haben diese Bonusmail %s bestätigt.", 'MEMBER_MAIL_NORMAL_CONFIRMED_ON' => "Sie haben diese Klickmail %s bestätigt.", diff --git a/inc/language/network_de.php b/inc/language/network_de.php index f917795c7f..e360e4d8f6 100644 --- a/inc/language/network_de.php +++ b/inc/language/network_de.php @@ -54,6 +54,7 @@ addMessages(array( 'ADMIN_NETWORK_ADD_TITLE' => "Neues Werbenetzwerk hinzufügen - Allgemeine Daten", 'ADMIN_NETWORK_EDIT_TITLE' => "Werbenetzwerk editieren - Allgemeine Daten", 'ADMIN_NETWORK_DELETE_TITLE' => "Werbenetzwerk löschen - Allgemeine Daten", + 'ADMIN_NETWORK_SELECT_TITLE' => "Werbenetzwerk auswählen", // - Link titles 'ADMIN_NETWORK_LIST_TYPES_LINK_TITLE' => "Weiter zu den Werbearten", 'ADMIN_NETWORK_LIST_PARAMS_LINK_TITLE' => "Weiter zu den Abfrageparametern", @@ -65,6 +66,7 @@ addMessages(array( 'ADMIN_NETWORK_CHANGE' => "Daten ändern", 'ADMIN_NETWORK_DELETE' => "Löschen", 'ADMIN_NETWORK_REMOVE' => "Daten entfernen", + 'ADMIN_NETWORK_CHOOSE' => "Werbenetzwerk auswählen", // - Success nots 'ADMIN_NETWORK_UPDATED' => "Es wurden %s Einträge in den allgemeinen Daten aktualisiert.", 'ADMIN_NETWORK_REMOVED' => "Es wurden %s Einträge aus den allgemeinen Dateen gelöscht.", diff --git a/inc/libs/network_functions.php b/inc/libs/network_functions.php index e90f634022..dfa15112c7 100644 --- a/inc/libs/network_functions.php +++ b/inc/libs/network_functions.php @@ -139,6 +139,42 @@ function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) { return SQL_AFFECTEDROWS(); } +// Generates a list of networks for given script and returns it +function generateAdminNetworkList () { + // Init output + $content = ''; + + // Query for all networks + $result = SQL_QUERY("SELECT + `network_id`, `network_title` +FROM + `{?_MYSQL_PREFIX?}_network_data` +ORDER BY + `network_title` ASC", __FILE__, __LINE__); + + // Do we have entries? + if (SQL_NUMROWS($result) > 0) { + // List all entries + $rows = array(); + while ($row = SQL_FETCHARRAY($result)) { + // Is this valid, then add it + if ((is_array($row)) && (isset($row['network_id']))) $rows[] = $row; + } // END - while + + // Generate the selection box + $content = generateSelectionBoxFromArray($rows, 'network', 'network_id', 'network_title'); + } else { + // Nothing selected + $content = loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ENTRIES_404')); + } + + // Free the result + SQL_FREERESULT($result); + + // Return the list + return $content; +} + //------------------------------------------------------------------------------ // Call-back functions //------------------------------------------------------------------------------ diff --git a/inc/modules/admin/what-list_network_types.php b/inc/modules/admin/what-list_network_types.php index fc31ab8560..4e856c6a32 100644 --- a/inc/modules/admin/what-list_network_types.php +++ b/inc/modules/admin/what-list_network_types.php @@ -44,5 +44,15 @@ if ((!defined('__SECURITY')) || (!isAdmin())) { // Add description as navigation point addMenuDescription('admin', __FILE__); +// Do we have a network selected? +if (isGetRequestElementSet('network')) { + // Get its data for template + $networkData = getNetworkDataById(getRequestElement('network')); + print('
'.print_r($networkData, true).'
'); +} else { + // Generate network list for this script + outputHtml(generateAdminNetworkList()); +} + // [EOF] ?> diff --git a/inc/modules/admin/what-list_payouts.php b/inc/modules/admin/what-list_payouts.php index 63ca2e4946..df76022cf6 100644 --- a/inc/modules/admin/what-list_payouts.php +++ b/inc/modules/admin/what-list_payouts.php @@ -39,7 +39,7 @@ // Some security stuff... if ((!defined('__SECURITY')) || (!isAdmin())) { die(); -} +} // END - if // Add description as navigation point addMenuDescription('admin', __FILE__); @@ -208,8 +208,6 @@ LIMIT 1", loadTemplate('admin_settings_saved', false, getMessage('PAYOUT_FAILED_OBTAIN_TASK_ID')); } } else { - if (!isGetRequestElementSet('do')) setRequestGetElement('do', ''); - if (getRequestElement('do') == 'delete') { // Delete all requests $result = SQL_QUERY("TRUNCATE `{?_MYSQL_PREFIX?}_user_payouts`", __FILE__, __LINE__); diff --git a/inc/modules/admin/what-stats_mods.php b/inc/modules/admin/what-stats_mods.php index 7157b6e835..59101e257e 100644 --- a/inc/modules/admin/what-stats_mods.php +++ b/inc/modules/admin/what-stats_mods.php @@ -39,14 +39,11 @@ // Some security stuff... if ((!defined('__SECURITY')) || (!isAdmin())) { die(); -} +} // END - if // Add description as navigation point addMenuDescription('admin', __FILE__); -// If var is empty set it to empty -if (!isGetRequestElementSet('mod')) setRequestGetElement('mod', ''); - // Check if module was selected if ((getRequestElement('mod') == 'index') || (getRequestElement('mod') == 'login')) { // Select menu system diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index 9503fff2fa..e691d6cf7c 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -299,40 +299,27 @@ function addMenuDescription ($accessLevel, $FQFN, $return = false, $output = tru // This is an action file! $type = 'action'; $search = substr($file, 7); - switch ($accessLevel) { - case 'admin': - $modCheck = 'admin'; - break; - - case 'sponsor': - case 'guest': - case 'member': - $modCheck = getModule(); - break; - } + + // Get access level from it + $modCheck = getModuleFromFileName($file, $accessLevel); + + // Add what $AND = " AND (`what`='' OR `what` IS NULL)"; } elseif (substr($file, 0, 5) == 'what-') { // This is an admin what file! $type = 'what'; $search = substr($file, 5); - $AND = ''; - switch ($accessLevel) { - case 'admin': - $modCheck = 'admin'; - break; - - case 'guest': - case 'member': - $modCheck = getModule(); - if (!isAdmin()) { - $AND = " AND `visible`='Y' AND `locked`='N'"; - } - break; - } + $AND = " AND `visible`='Y' AND `locked`='N'"; + + // Get access level from it + $modCheck = getModuleFromFileName($file, $accessLevel); + + // Do we have admin? Then display all + if (isAdmin()) $AND = ''; $dummy = substr($search, 0, -4); $AND .= " AND `action`='".getModeAction($accessLevel, $dummy)."'"; - } elseif (($accessLevel == 'sponsor') || ($accessLevel == "engine")) { + } elseif (($accessLevel == 'sponsor') || ($accessLevel == 'engine')) { // Sponsor / engine menu $type = 'what'; $search = $file; @@ -1556,7 +1543,12 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher // Query the database $result = SQL_QUERY_ESC("SELECT `%s`, `%s`".$SPEC." FROM `{?_MYSQL_PREFIX?}_%s` ".$where." ORDER BY `%s` ASC", - array($id, $name, $table, $name), __FUNCTION__, __LINE__); + array( + $id, + $name, + $table, + $name + ), __FUNCTION__, __LINE__); // Do we have rows? if (SQL_NUMROWS($result) > 0) { @@ -1569,13 +1561,13 @@ function generateOptionList ($table, $id, $name, $default='', $special='', $wher if (!empty($add)) $add = ' ('.$add.')'; $ret .= '>' . $title . $add . ''; } // END - while - - // Free memory - SQL_FREERESULT($result); } else { // No data found $ret = ''; } + + // Free memory + SQL_FREERESULT($result); } // Return - hopefully - the requested data diff --git a/templates/de/html/select/.htaccess b/templates/de/html/select/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/templates/de/html/select/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/templates/de/html/select/select_network_box.tpl b/templates/de/html/select/select_network_box.tpl new file mode 100644 index 0000000000..2d7d80b49f --- /dev/null +++ b/templates/de/html/select/select_network_box.tpl @@ -0,0 +1,17 @@ +
+
+ + +
+
+ {--ADMIN_NETWORK_SELECT_TITLE--} +
+
+ $content[selection_box] +
+ +
+
+
-- 2.39.5