]> git.mxchange.org Git - mailer.git/blobdiff - inc/template-functions.php
Misc cleanups
[mailer.git] / inc / template-functions.php
index 929c99a3783b2df5dbc2bd542b20030c99bb61cd..2259ffc2e5dd94c3878eb8ab88d0943c47b3ae2d 100644 (file)
@@ -278,14 +278,18 @@ function outputRawCode ($htmlCode) {
 
 // Load a template file and return it's content (only it's name; do not use ' or ")
 function loadTemplate ($template, $return = false, $content = array(), $compileCode = true) {
+       // @TODO Remove these sanity checks if all is fine
        if (!is_bool($return)) {
-               // @TODO Remove this sanity-check if all is fine
+               // $return has to be boolean
                debug_report_bug(__FUNCTION__, __LINE__, 'return[] is not bool (' . gettype($return) . ')');
        } elseif (!is_string($template)) {
                // $template has to be string
                debug_report_bug(__FUNCTION__, __LINE__, 'template[] is not string (' . gettype($template) . ')');
        }
 
+       // Init returned content
+       $ret = '';
+
        // Set current template
        $GLOBALS['current_template'] = $template;
 
@@ -297,9 +301,6 @@ function loadTemplate ($template, $return = false, $content = array(), $compileC
                // Make all template names lowercase
                $template = strtolower($template);
 
-               // Init some data
-               $ret = '';
-
                // Base directory
                $basePath = sprintf("%stemplates/%s/html/", getPath(), getLanguage());
                $extraPath = detectExtraTemplatePath($template);
@@ -322,10 +323,9 @@ function loadTemplate ($template, $return = false, $content = array(), $compileC
                        $GLOBALS['tpl_content'][$template] = readFromFile($FQFN);
 
                        // Do we have to compile the code?
-                       $ret = '';
                        if ((isInString('$', $GLOBALS['tpl_content'][$template])) || (isInString('{--', $GLOBALS['tpl_content'][$template])) || (isInString('{?', $GLOBALS['tpl_content'][$template])) || (isInString('{%', $GLOBALS['tpl_content'][$template]))) {
                                // Normal HTML output?
-                               if (isHtmlOutputMode()) {
+                               if ((isHtmlOutputMode()) && (substr($template, 0, 3) != 'js_')) {
                                        // Add surrounding HTML comments to help finding bugs faster
                                        $ret = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['tpl_content'][$template] . '<!-- Template ' . $template . ' - End //-->';
 
@@ -461,6 +461,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
        } // END - if
 
        // Load user's data
+       // @DEPRECATED Loading the user data by given userid is deprecated because it is not related to template loading
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UID=' . $userid . ',template=' . $template . ',content[]=' . gettype($content));
        if ((isValidUserId($userid)) && (is_array($content))) {
                // If nickname extension is installed, fetch nickname as well
@@ -478,7 +479,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
                }
 
                // Merge data if valid
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'content()=' . count($content) . ' - PRE!');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'content()=' . count($content) . ' - BEFORE!');
                if ((isUserDataValid()) && ($loadUserData === true)) {
                        // It is valid
                        $content = merge_array($content, getUserDataArray());
@@ -540,7 +541,10 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
                $newContent = "Compiler error for template " . $template . " !\nUncompiled content:\n" . $GLOBALS['tpl_content'][$template];
 
                // Add last error if the required function exists
-               if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
+               if (function_exists('error_get_last')) {
+                       // Add last error and some lines for better overview
+                       $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
+               } // END - if
        } // END - if
 
        // Remove content and data
@@ -573,7 +577,7 @@ function getMenuCssClasses ($data) {
 
 // Generate XHTML code for the CAPTCHA
 function generateCaptchaCode ($code, $type, $type, $userid) {
-       return '<img border="0" alt="Code ' . $code . '" src="{%url=mailid_top.php?userid=' . $userid . '&amp;' . $type . '=' . $type . '&amp;mode=img&amp;code=' . $code . '%}" />';
+       return '<img border="0" alt="Code ' . $code . '" src="{%url=mailid_top.php?userid=' . $userid . '&amp;' . $type . '=' . $type . '&amp;do=img&amp;code=' . $code . '%}" />';
 }
 
 // Compiles the given HTML/mail code
@@ -909,13 +913,13 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
        if ($asArray === true) {
                // Just put all data in an array for later use
                $OUT = array(
-                       'YEARS'   => $Y,
-                       'MONTHS'  => $M,
-                       'WEEKS'   => $W,
-                       'DAYS'    => $D,
-                       'HOURS'   => $h,
-                       'MINUTES' => $m,
-                       'SECONDS' => $s
+                       'Y' => $Y,
+                       'M' => $M,
+                       'W' => $W,
+                       'D' => $D,
+                       'h' => $h,
+                       'm' => $m,
+                       's' => $s
                );
        } else {
                // Generate table
@@ -924,31 +928,31 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                $OUT .= '<tr>';
 
                if (isInString('Y', $display) || (empty($display))) {
-                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_YEARS--}</strong></td>';
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--TIME_UNIT_YEAR--}</strong></td>';
                } // END - if
 
                if (isInString('M', $display) || (empty($display))) {
-                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MONTHS--}</strong></td>';
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--TIME_UNIT_MONTH--}</strong></td>';
                } // END - if
 
                if (isInString('W', $display) || (empty($display))) {
-                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_WEEKS--}</strong></td>';
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--TIME_UNIT_WEEK--}</strong></td>';
                } // END - if
 
                if (isInString('D', $display) || (empty($display))) {
-                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_DAYS--}</strong></td>';
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--TIME_UNIT_DAY--}</strong></td>';
                } // END - if
 
                if (isInString('h', $display) || (empty($display))) {
-                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_HOURS--}</strong></td>';
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--TIME_UNIT_HOUR--}</strong></td>';
                } // END - if
 
                if (isInString('m', $display) || (empty($display))) {
-                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_MINUTES--}</strong></td>';
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--TIME_UNIT_MINUTE--}</strong></td>';
                } // END - if
 
                if (isInString('s', $display) || (empty($display))) {
-                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--_SECONDS--}</strong></td>';
+                       $OUT .= '<td align="center" class="timebox_column bottom"><div class="tiny">{--TIME_UNIT_SECOND--}</strong></td>';
                } // END - if
 
                $OUT .= '</tr>';
@@ -1419,20 +1423,20 @@ function determinePageTitle () {
                } // END - if
 
                // Add title from what file
-               $mode = '';
+               $menuMode = '';
                if (getModule() == 'login') {
-                       $mode = 'member';
+                       $menuMode = 'member';
                } elseif (getModule() == 'index') {
-                       $mode = 'guest';
+                       $menuMode = 'guest';
                } elseif (getModule() == 'admin') {
-                       $mode = 'admin';
+                       $menuMode = 'admin';
                } elseif (getModule() == 'sponsor') {
-                       $mode = 'sponsor';
+                       $menuMode = 'sponsor';
                }
 
                // Add middle part (always in admin area!)
-               if ((!empty($mode)) && ((isWhatTitleEnabled()) || ($mode == 'admin'))) {
-                       $pageTitle .= ' {%config,trim=title_middle%} ' . getTitleFromMenu($mode, getWhat());
+               if ((!empty($menuMode)) && ((isWhatTitleEnabled()) || ($menuMode == 'admin'))) {
+                       $pageTitle .= ' {%config,trim=title_middle%} ' . getTitleFromMenu($menuMode, getWhat());
                } // END - if
 
                // Add title decorations? (right)
@@ -1772,6 +1776,50 @@ function translatePoolType ($type) {
        return sprintf("{--POOL_TYPE_%s--}", strtoupper($type));
 }
 
+// "Translates" given time unit
+function translateTimeUnit ($unit) {
+       // Default is unknown
+       $message = '{%message,TIME_UNIT_UNKNOWN=' . $unit . '%}';
+
+       // "Detect" it
+       switch ($unit) {
+               case 'Y': // Years
+                       $message = '{--TIME_UNIT_YEAR--}';
+                       break;
+
+               case 'M': // Months
+                       $message = '{--TIME_UNIT_MONTH--}';
+                       break;
+
+               case 'W': // Weeks
+                       $message = '{--TIME_UNIT_WEEK--}';
+                       break;
+
+               case 'D': // Days
+                       $message = '{--TIME_UNIT_DAY--}';
+                       break;
+
+               case 'h': // Hours
+                       $message = '{--TIME_UNIT_HOUR--}';
+                       break;
+
+               case 'm': // Minute
+                       $message = '{--TIME_UNIT_MINUTE--}';
+                       break;
+
+               case 's': // Seconds
+                       $message = '{--TIME_UNIT_SECOND--}';
+                       break;
+
+               default: // Unknown value detected
+                       logDebugMessage(__FUNCTION__, __LINE__, 'Unknown time unit ' . $unit . ' detected.');
+                       break;
+       } // END - switch
+
+       // Return message
+       return $message;
+}
+
 // Displays given message in admin_settings_saved template
 function displayMessage ($message, $return = false) {
        // Load the template
@@ -1783,7 +1831,7 @@ function generateGenderSelectionBox ($selectedGender = '') {
        // Start the HTML code
        $out  = '<select name="gender" size="1" class="form_select">';
 
-       // Add the options
+       // Add options
        $out .= generateOptionList('/ARRAY/', array('M', 'F', 'C'), array('{--GENDER_M--}', '{--GENDER_F--}', '{--GENDER_C--}'), $selectedGender);
 
        // Finish HTML code
@@ -1793,6 +1841,67 @@ function generateGenderSelectionBox ($selectedGender = '') {
        return $out;
 }
 
+// Generates a selection box for given default value
+function generateTimeUnitSelectionBox ($defaultUnit, $fieldName, $unitArray) {
+       // Init variables
+       $messageIds = array();
+
+       // Generate message id array
+       foreach ($unitArray as $unit) {
+               // "Translate" it
+               $messageIds[] = translateTimeUnit($unit);
+       } // END - foreach
+
+       // Start the HTML code
+       $out = '<select name="' . $fieldName . '" size="1" class="form_select">';
+
+       // Add options
+       $out .= generateOptionList('/ARRAY/', $unitArray, $messageIds, $defaultUnit);
+
+       // Finish HTML code
+       $out .= '</select>';
+
+       // Return the code
+       return $out;
+}
+
+// Function to add style tag (wether display:none/block)
+function addStyleMenuContent ($menuMode, $mainAction, $action) {
+       // Do we have foo_menu_javascript enabled?
+       if ((!isConfigEntrySet($menuMode . '_menu_javascript')) || (getConfig($menuMode . '_menu_javascript') == 'N')) {
+               // Silently abort here, not enabled
+               return '';
+       } // END - if
+
+       // Is action=mainAction?
+       if ($action == $mainAction) {
+               // Add "menu open" style
+               return ' style="display:block"';
+       } else {
+               return ' style="display:none"';
+       }
+}
+
+// Function to add onclick attribute
+function addJavaScriptMenuContent ($menuMode, $mainAction, $action, $what) {
+       // Do we have foo_menu_javascript enabled?
+       if ((!isConfigEntrySet($menuMode . '_menu_javascript')) || (getConfig($menuMode . '_menu_javascript') == 'N')) {
+               // Silently abort here, not enabled
+               return '';
+       } // END - if
+
+       // Prepare content
+       $content = array(
+               'menu_mode'   => $menuMode,
+               'main_action' => $mainAction,
+               'action'      => $action,
+               'what'        => $what
+       );
+
+       // Return template
+       return loadTemplate('js_' . $menuMode . '_menu_onclick', true, $content);
+}
+
 //-----------------------------------------------------------------------------
 //                     Template helper functions for EL code
 //-----------------------------------------------------------------------------
@@ -1819,7 +1928,7 @@ function doTemplateColorSwitch ($template, $clear = false, $return = true) {
 // Helper function for extension registration link
 function doTemplateExtensionRegistrationLink ($template, $clear, $ext_name) {
        // Default is all non-productive
-       $OUT = '<div style="cursor:help" class="notice" title="{%message,ADMIN_EXTENSION_IS_NON_PRODUCTIVE_LINK_TITLE=' . $ext_name . '%}">{--ADMIN_EXTENSION_IS_NON_PRODUCTIVE_LINK--}</div>';
+       $OUT = '<div style="cursor:help" title="{%message,ADMIN_EXTENSION_IS_NON_PRODUCTIVE_LINK_TITLE=' . $ext_name . '%}">{--ADMIN_EXTENSION_IS_NON_PRODUCTIVE_LINK--}</div>';
 
        // Is the given extension non-productive?
        if (isExtensionProductive($ext_name)) {