]> git.mxchange.org Git - mailer.git/blobdiff - inc/template-functions.php
Continued:
[mailer.git] / inc / template-functions.php
index d4bd6354fa62f3d7c80f39cbfb730bdb743c35b8..159456c0bdb4b0e53e383caa3ec7951014371469 100644 (file)
@@ -11,7 +11,7 @@
  * Kurzbeschreibung  : Template-Funktionen                              *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2016 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -78,16 +78,16 @@ function initTemplateColorSwitch ($template) {
        $GLOBALS['color_switch'][$template] = 2;
 }
 
-// "Getter" for color switch code
-function getColorSwitchCode ($template) {
+// "Renders" color switch code
+function renderColorSwitchCode ($template) {
        // Prepare the code
-       $code = "{DQUOTE} . doTemplateColorSwitch('" . $template . "', FALSE, FALSE) . {DQUOTE}";
+       $code = sprintf("{DQUOTE} . doTemplateColorSwitch('%s', FALSE, FALSE) . {DQUOTE}", $template);
 
        // And return it
        return $code;
 }
 
-// Output HTML code directly or 'render' it. You addionally switch the new-line character off
+// Output HTML code directly or 'render' it. You can addionally switch the new-line character off
 function outputHtml ($htmlCode = NULL, $newLine = TRUE) {
        // Init output
        if (!isset($GLOBALS['__output'])) {
@@ -238,7 +238,7 @@ function doFinalCompilation ($code, $insertComments = TRUE, $enableCodes = TRUE)
        // Compile all out
        while (((isInString('{--', $code)) || (isInString('{DQUOTE}', $code)) || (isInString('{?', $code)) || (isInString('{%', $code) !== FALSE)) && ($totalCompilations < 7)) {
                // Init common variables
-               $content = array();
+               $content = [];
                $newContent = '';
 
                // Compile it
@@ -293,7 +293,7 @@ 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) {
+function loadTemplate ($template, $return = FALSE, $content = [], $compileCode = TRUE) {
        // @TODO Remove these sanity checks if all is fine
        if (!is_bool($return)) {
                // $return has to be boolean
@@ -351,7 +351,7 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC
 
                                        // Prepare eval() command
                                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
-                                       $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . getColorSwitchCode($template) . compileCode(escapeQuotes($code), TRUE, $compileCode) . '";';
+                                       $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . renderColorSwitchCode($template) . compileCode(escapeQuotes($code), TRUE, $compileCode) . '";';
                                } elseif (substr($template, 0, 3) == 'js_') {
                                        // JavaScripts don't like entities, dollar signs and timings
                                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
@@ -369,7 +369,7 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC
                                // Add surrounding HTML comments to help finding bugs faster
                                $templateContent = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['template_content']['html'][$template] . '<!-- Template ' . $template . ' - End //-->';
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
-                               $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . getColorSwitchCode($template) . compileRawCode(escapeQuotes($templateContent), TRUE, $compileCode) . '";';
+                               $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . renderColorSwitchCode($template) . compileRawCode(escapeQuotes($templateContent), TRUE, $compileCode) . '";';
                        } elseif (isAjaxOutputMode()) {
                                // AJAX (JSON content)
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
@@ -381,16 +381,19 @@ function loadTemplate ($template, $return = FALSE, $content = array(), $compileC
                        } // END - if
                } elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
                        // Only admins shall see this warning or when installation mode is active
-                       $templateContent = '<div class="para">
+                       $templateContent = sprintf('<div class="para">
        {--TEMPLATE_404--}
 </div>
 <div class="para">
-       (' . $template . ')
+       (%s)
 </div>
 <div class="para">
        {--TEMPLATE_CONTENT--}:
-       <pre>' . print_r($content, TRUE) . '</pre>
-</div>';
+       <pre>%s</pre>
+</div>',
+                               $template,
+                               print_r($content, TRUE)
+                       );
                } else {
                        // No file!
                        $GLOBALS['template_eval']['html'][$template] = '404';
@@ -477,7 +480,7 @@ function detectExtraTemplatePath ($prefix, $template) {
 }
 
 // Loads an email template and compiles it
-function loadEmailTemplate ($template, $content = array(), $userid = NULL, $loadUserData = TRUE) {
+function loadEmailTemplate ($template, $content = [], $userid = NULL, $loadUserData = TRUE) {
        // Make sure all template names are lowercase!
        $template = strtolower($template);
 
@@ -533,13 +536,16 @@ function loadEmailTemplate ($template, $content = array(), $userid = NULL, $load
                        $GLOBALS['template_eval']['email'][$template] = '$templateContent = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['template_content']['email'][$template])) . '");';
                } elseif (!empty($template)) {
                        // Template file not found
-                       $templateContent = '<div class="para">
-       {--TEMPLATE_404--}: ' . $template . '
+                       $templateContent = sprintf('<div class="para">
+       {--TEMPLATE_404--}: %s
 </div>
 <div class="para">
        {--TEMPLATE_CONTENT--}:
-       <pre>' . print_r($content, TRUE) . '</pre>
-</div>';
+       <pre>%s</pre>
+</div>',
+                               $template,
+                               print_r($content, TRUE)
+                       );
 
                        // Don't cache this, as there is no template to cache
                        $GLOBALS['template_eval']['email'][$template] = '404';
@@ -685,7 +691,7 @@ function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) {
        // Are some matches found?
        if ((isFilledArray($matches)) && (isFilledArray($matches[0]))) {
                // Replace all matches
-               $matchesFound = array();
+               $matchesFound = [];
                foreach ($matches[0] as $key => $match) {
                        // Fuzzy look has failed by default
                        $fuzzyFound = FALSE;
@@ -780,7 +786,7 @@ function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) {
 }
 
 //
-function addSelectionBox ($type, $default, $prefix = '', $id = NULL, $class = 'form_select') {
+function addSelectionBox ($type, $default, $prefix = '', $id = NULL, $class = 'form_select', $allSteps = FALSE) {
        $OUT = '';
 
        if ($type == 'yn') {
@@ -880,7 +886,16 @@ function addSelectionBox ($type, $default, $prefix = '', $id = NULL, $class = 'f
 
                case 'mi': // Minutes
                case 'se': // Seconds
-                       for ($idx = 0; $idx <= 59; $idx+=5) {
+                       // Default is 5 minutes/seconds step
+                       $step = 5;
+
+                       // All steps?
+                       if ($allSteps === TRUE) {
+                               // Then all steps
+                               $step = 1;
+                       } // END - if
+
+                       for ($idx = 0; $idx <= 59; $idx += $step) {
                                $padded = padLeftZero($idx, 2);
                                $OUT .= '<option value="' . $padded . '"';
                                if ($default == $padded) $OUT .= ' selected="selected"';
@@ -960,7 +975,7 @@ function generateImageOrCode ($img_code, $headerSent = TRUE) {
 }
 
 // Create selection box or array of splitted timestamp
-function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $asArray = FALSE) {
+function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $asArray = FALSE, $allSteps = FALSE) {
        // Do not continue if ONE_DAY is absend
        if (!isConfigEntrySet('ONE_DAY')) {
                // Abort here
@@ -1011,7 +1026,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
        } // END - if
 
        // Put all calculated values in array
-       $data = array(
+       $data = [
                'Y' => $year,
                'M' => $month,
                'W' => $week,
@@ -1019,7 +1034,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                'h' => $hour,
                'm' => $minute,
                's' => $second
-       );
+       ];
 
        //
        // Now we convert them in seconds...
@@ -1029,9 +1044,9 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                $OUT = $data;
        } else {
                // Init array
-               $units = array(
+               $units = [
                        // Time unit -> field name
-                       'unit_field' => array(
+                       'unit_field' => [
                                'Y' => 'ye',
                                'M' => 'mn',
                                'W' => 'we',
@@ -1039,9 +1054,9 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                                'h' => 'ho',
                                'm' => 'mi',
                                's' => 'se'
-                       ),
+                       ],
                        // Time unit -> label
-                       'unit_label' => array(
+                       'unit_label' => [
                                'Y' => 'YEAR',
                                'M' => 'MONTH',
                                'W' => 'WEEK',
@@ -1049,8 +1064,8 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                                'h' => 'HOUR',
                                'm' => 'MINUTE',
                                's' => 'SECOND'
-                       )
-               );
+                       ]
+               ];
 
                // Generate table
                $OUT  = '<div align="' . $align . '">';
@@ -1076,7 +1091,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        if (isInString($unit, $display) || (empty($display))) {
                                // Generate year selection
                                $OUT .= '<td align="center">';
-                               $OUT .= addSelectionBox($field, $data[$unit], $prefix, NULL, 'mini_select');
+                               $OUT .= addSelectionBox($field, $data[$unit], $prefix, NULL, 'mini_select', $allSteps);
                                $OUT .= '</td>';
                        } else {
                                $OUT .= '<input type="hidden" name="' . $prefix . '_' . $field . '" value="0" />';
@@ -1250,10 +1265,10 @@ function displayParsingTime () {
 
        // Prepare output
        // @TODO This can be easily moved out after the merge from EL branch to this is complete
-       $content = array(
+       $content = [
                'run_time' => $runTime,
                'sql_time' => (getConfig('sql_time') * 1000),
-       );
+       ];
 
        // Load the template
        $GLOBALS['__page_footer'] .= loadTemplate('show_timings', TRUE, $content);
@@ -1318,10 +1333,10 @@ function reportBug ($file, $line, $message = '', $sendEmail = TRUE) {
        // Send an email? (e.g. not wanted for evaluation errors)
        if (($sendEmail === TRUE) && (!isInstaller()) && (isAdminRegistered())) {
                // Prepare content
-               $content = array(
+               $content = [
                        'message'   => trim($message),
                        'backtrace' => trim(debug_get_mailable_backtrace())
-               );
+               ];
 
                // Send email to webmaster
                sendAdminNotification('{--REPORT_BUG_SUBJECT--}', 'admin_report_bug', $content);
@@ -1367,8 +1382,8 @@ function compileUriCode ($code, $simple = TRUE) {
        } // END - if
 
        // Compile these by default
-       $charsCompile = array(
-               'from' => array(
+       $charsCompile = [
+               'from' => [
                        '{DOT}',
                        '{SLASH}',
                        '{QUOT}',
@@ -1378,8 +1393,8 @@ function compileUriCode ($code, $simple = TRUE) {
                        '{OPEN_SQR}',
                        '{CLOSE_SQR}',
                        '{PER}'
-               ),
-               'to' => array(
+               ],
+               'to' => [
                        '.',
                        '/',
                        chr(39),
@@ -1389,8 +1404,8 @@ function compileUriCode ($code, $simple = TRUE) {
                        '[',
                        ']',
                        '%'
-               )
-       );
+               ]
+       ];
 
        // Compile constants
        if ($simple === FALSE) {
@@ -1811,10 +1826,7 @@ function sendModeMails ($mod, $modes) {
 }
 
 // Generates a 'selection box' from given array
-function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) {
-       // options must be an array
-       assert(is_array($options));
-
+function generateSelectionBoxFromArray (array $options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) {
        // Default is empty
        $addKey = '';
 
@@ -1872,9 +1884,9 @@ function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionCont
        $OUT .= '</select>';
 
        // Prepare output
-       $content = array(
+       $content = [
                'selection_box' => $OUT,
-       );
+       ];
 
        // Load template and return it
        if (empty($templateName)) {
@@ -1914,7 +1926,7 @@ function addPageHeaderFooter () {
        $OUT = '';
 
        // Add them all together. This is maybe to simple
-       foreach (array('__page_header', '__output', '__page_footer') as $pagePart) {
+       foreach (['__page_header', '__output', '__page_footer'] as $pagePart) {
                // Add page part if set
                if (isset($GLOBALS[$pagePart])) {
                        $OUT .= $GLOBALS[$pagePart];
@@ -2019,24 +2031,24 @@ function returnErrorMessage ($message) {
        return loadTemplate('admin_settings_unsaved', TRUE, $message);
 }
 
-// Generates a selection box for (maybe) given gender
-function generateGenderSelectionBox ($selectedGender = '', $fieldName = 'gender') {
+// Generates a selection box for (maybe) given sex
+function generateSexSelectionBox ($selectedSex = '', $fieldName = 'sex') {
        // Start the HTML code
        $out  = '<select name="' . $fieldName . '" size="1" class="form_select">';
 
        // Add options
        $out .= generateOptions(
                '/ARRAY/',
-               array(
+               [
                        'M',
                        'F',
                        'C'
-               ), array(
-                       '{--GENDER_M--}',
-                       '{--GENDER_F--}',
-                       '{--GENDER_C--}'
-               ),
-               $selectedGender
+               ], [
+                       '{--SEX_M--}',
+                       '{--SEX_F--}',
+                       '{--SEX_C--}'
+               ],
+               $selectedSex
        );
 
        // Finish HTML code
@@ -2049,7 +2061,7 @@ function generateGenderSelectionBox ($selectedGender = '', $fieldName = 'gender'
 // Generates a selection box for given default value
 function generateTimeUnitSelectionBox ($defaultUnit, $fieldName, $unitArray) {
        // Init variables
-       $messageIds = array();
+       $messageIds = [];
 
        // Generate message id array
        foreach ($unitArray as $unit) {
@@ -2149,7 +2161,7 @@ function compactContent ($uncompactedContent) {
        $compactedContent = str_replace(chr(9), '', str_replace(PHP_EOL, '', str_replace(chr(13), '', $uncompactedContent)));
 
        // Make a space after >
-       $compactedContent = str_replace(array('>', '  '), array('> ', ' '), $compactedContent);
+       $compactedContent = str_replace(['>', '  '], ['> ', ' '], $compactedContent);
 
        // Then regex all comments like <!-- //--> away
        preg_match_all('/<!--[\w\W]*?(\/\/){0,1}-->/', $compactedContent, $matches);
@@ -2262,14 +2274,14 @@ function doTemplateNoYesSelectionBox ($templateName, $clear, $formField) {
 // Helper function to add extra content for guest area (module=index and others)
 function doTemplateGuestFooterExtras ($templateName, $clear) {
        // Init filter data
-       $filterData = array(
+       $filterData = [
                // Name of used template
                'template' => $templateName,
                // Target array for gathered data
-               '__data'   => array(),
+               '__data'   => [],
                // Where the HTML output will go
                '__output' => '',
-       );
+       ];
 
        // Run the filter chain
        $filterData = runFilterChain('guest_footer_extras', $filterData);
@@ -2287,16 +2299,16 @@ function doTemplateMemberFooterExtras ($templateName, $clear) {
        } // END - if
 
        // Init filter data
-       $filterData = array(
+       $filterData = [
                // Current user's id number
                'userid'   => getMemberId(),
                // Name of used template
                'template' => $templateName,
                // Target array for gathered data
-               '__data'   => array(),
+               '__data'   => [],
                // Where the HTML output will go
                '__output' => '',
-       );
+       ];
 
        // Run the filter chain
        $filterData = runFilterChain('member_footer_extras', $filterData);
@@ -2349,10 +2361,10 @@ function doTemplateGetTermsConditionsLink ($templateName, $clear) {
 // Template helper function to create selection box for "locked points mode"
 function doTemplatePointsLockedModeSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
        // Init array
-       $lockedModes = array(
-               0 => array('mode' => 'LOCKED'),
-               1 => array('mode' => 'UNLOCKED'),
-       );
+       $lockedModes = [
+               0 => ['mode' => 'LOCKED'],
+               1 => ['mode' => 'UNLOCKED'],
+       ];
 
        // Handle it over to generateSelectionBoxFromArray()
        $content = generateSelectionBoxFromArray($lockedModes, 'points_locked_mode', 'mode', '', '', '', $default);
@@ -2364,10 +2376,10 @@ function doTemplatePointsLockedModeSelectionBox ($templateName, $clear = FALSE,
 // Template helper function to create selection box for payment method
 function doTemplatePointsPaymentMethodSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
        // Init array
-       $paymentMethods = array(
-               0 => array('method' => 'DIRECT'),
-               1 => array('method' => 'REFERRAL'),
-       );
+       $paymentMethods = [
+               0 => ['method' => 'DIRECT'],
+               1 => ['method' => 'REFERRAL'],
+       ];
 
        // Handle it over to generateSelectionBoxFromArray()
        $content = generateSelectionBoxFromArray($paymentMethods, 'points_payment_method', 'method', '', '', '', $default);
@@ -2381,7 +2393,7 @@ function doTemplateDereferrerUrl ($templateName, $clear = FALSE, $url = NULL) {
        // Is the URL not NULL and not empty?
        if ((!is_null($url)) && (!empty($url))) {
                // Set HTML with EL code
-               $url = '<a href="{%pipe,generateDereferrerUrl=' . $url . '%}" rel="external" target="_blank">{--ADMIN_TEST_URL--}</a>';
+               $url = sprintf('<a href="{%%pipe,generateDereferrerUrl=%s%%}" rel="external" target="_blank">{--ADMIN_TEST_URL--}</a>', $url);
        } // END - if
 
        // Return URL (or content) or dashes if empty
@@ -2389,7 +2401,7 @@ function doTemplateDereferrerUrl ($templateName, $clear = FALSE, $url = NULL) {
 }
 
 // Load another template and return its content
-function doTemplateLoadTemplate ($templateName, $clear = FALSE, $theTemplate, $content = array()) {
+function doTemplateLoadTemplate ($templateName, $clear = FALSE, $theTemplate, $content = []) {
        // Load "the" template
        return loadTemplate($theTemplate, TRUE, $content);
 }
@@ -2400,7 +2412,7 @@ function doTemplateMetaFavIcon ($templateName, $clear = FALSE) {
        $out = '';
 
        // Check all common extensions
-       foreach (array('ico', 'gif', 'png') as $extension) {
+       foreach (['ico', 'gif', 'png'] as $extension) {
                // Is the file there?
                if (isFileReadable(getPath() . 'favicon.' . $extension)) {
                        // Then use this and abort
@@ -2532,4 +2544,3 @@ function loadPageFooter () {
 }
 
 // [EOF]
-?>