]> git.mxchange.org Git - mailer.git/blobdiff - inc/template-functions.php
Noisy debug line commented out
[mailer.git] / inc / template-functions.php
index 8ec37cc2bdf207d25482bae1fd8df9c175a06ebd..59e5aadb9fe4b3dcced24ef4df74112d454ddaae 100644 (file)
@@ -110,23 +110,32 @@ function outputHtml ($htmlCode, $newLine = true) {
                                        outputRawCode($htmlCode);
 
                                        // That's why you don't need any \n at the end of your HTML code... :-)
-                                       if ($newLine === true) print("\n");
+                                       if ($newLine === true) {
+                                               print("\n");
+                                       } // END - if
                                } else {
                                        // Render mode for old or lame servers...
                                        $GLOBALS['output'] .= $htmlCode;
 
                                        // That's why you don't need any \n at the end of your HTML code... :-)
-                                       if ($newLine === true) $GLOBALS['output'] .= "\n";
+                                       if ($newLine === true) {
+                                               $GLOBALS['output'] .= "\n";
+                                       } // END - if
                                }
                                break;
 
                        case 'direct':
                                // If we are switching from render to direct output rendered code
-                               if ((!empty($GLOBALS['output'])) && (getPhpCaching() != 'on')) { outputRawCode($GLOBALS['output']); $GLOBALS['output'] = ''; }
+                               if ((!empty($GLOBALS['output'])) && (getPhpCaching() != 'on')) {
+                                       outputRawCode($GLOBALS['output']);
+                                       $GLOBALS['output'] = '';
+                               } // END - if
 
                                // The same as above... ^
                                outputRawCode($htmlCode);
-                               if ($newLine === true) print("\n");
+                               if ($newLine === true) {
+                                       print("\n");
+                               } // END - if
                                break;
 
                        default:
@@ -316,14 +325,14 @@ function loadTemplate ($template, $return = false, $content = array(), $compileC
                        $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 //-->';
 
                                        // Prepare eval() command
                                        $GLOBALS['template_eval'][$template] = '$ret = "' . getColorSwitchCode($template) . compileCode(escapeQuotes($ret), false, true, true, $compileCode) . '";';
                                } elseif (substr($template, 0, 3) == 'js_') {
-                                       // JavaScripts don't like entities and timings
+                                       // JavaScripts don't like entities, dollar signs and timings
                                        $GLOBALS['template_eval'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['tpl_content'][$template]), false, true, true, $compileCode) . '");';
                                } else {
                                        // Prepare eval() command, other output doesn't like entities, maybe
@@ -564,7 +573,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
@@ -900,13 +909,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
@@ -915,31 +924,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>';
@@ -1410,20 +1419,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)
@@ -1763,6 +1772,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
@@ -1774,7 +1827,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
@@ -1784,6 +1837,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 (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 (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
 //-----------------------------------------------------------------------------
@@ -1810,7 +1924,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)) {