]> git.mxchange.org Git - mailer.git/blobdiff - inc/revision-functions.php
Code style changed, ext-user continued:
[mailer.git] / inc / revision-functions.php
index 39b9442f466de3bce5a1b781d86e0600420cce2f..e61d9788751d69dfd852a1cf351cab7a2d47c615 100644 (file)
  * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
  * $Author::                                                          $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
@@ -41,14 +40,40 @@ if (!defined('__SECURITY')) {
        die();
 } // END - if
 
+// Initializes repository data
+function initRepositoryData () {
+       // Default data values or array indexes if numerical
+       $GLOBALS['default_repository_data'] = array(
+               // Main author of this script
+               'Author'   => 'quix0r',
+               // No default value for current file name
+               'File'     => 11,
+               // No default value for revision number
+               'Revision' => 10,
+               // No default value for date
+               'Date'     => 9,
+               // Default branch
+               'Tag'      => 8
+       );
+
+       // Add Revision, Date, Tag and Author
+       $GLOBALS['repository_search_for'] = array(
+               'File',
+               'Revision',
+               'Date',
+               'Tag',
+               'Author'
+       );
+}
+
 // "Getter" for revision/version data
-function getActualVersion ($type = 'Revision') {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . '] - ENTRY!');
+function getRepositoryData ($type = 'Revision') {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . '] - ENTERED!');
        // Default is an invalid value to find bugs... :-)
        $ret = 'INVALID';
 
        // By default nothing is new... ;-)
-       $new = false;
+       $new = FALSE;
 
        // Is the cache entry there?
        if (isset($GLOBALS['cache_array']['revision'][$type][0])) {
@@ -60,29 +85,29 @@ function getActualVersion ($type = 'Revision') {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
        } else {
                // FQFN of revision file
-               $FQFN = sprintf("%s/.revision", getConfig('CACHE_PATH'));
+               $FQFN = sprintf("%s/.revision", getCachePath());
 
                // Check if 'check_revision_data' is setted (switch for manually rewrite the .revision-File)
-               if ((isGetRequestParameterSet('check_revision_data')) && (getRequestParameter('check_revision_data') == 'yes')) {
+               if ((isGetRequestElementSet('check_revision_data')) && (getRequestElement('check_revision_data') == 'yes')) {
                        // Forced rebuild of .revision file
-                       $new = true;
+                       $new = TRUE;
                } else {
                        // Check for revision file
                        if (!isFileReadable($FQFN)) {
                                // Not found, so we need to create it
-                               $new = true;
+                               $new = TRUE;
                        } else {
                                // Revision file found
-                               $ins_vers = explode("\n", readFromFile($FQFN));
+                               $ins_vers = explode(chr(10), readFromFile($FQFN));
 
                                // Get array for mapping information
-                               $mapper = array_flip(getSearchFor());
-                               //* DEBUG: */ print('<pre>mapper='.print_r($mapper, true).'</pre>ins_vers=<pre>'.print_r($ins_vers, true).'</pre>');
+                               $mapper = array_flip($GLOBALS['repository_search_for']);
+                               //* DEBUG: */ debugOutput('<pre>mapper='.print_r($mapper, TRUE).'</pre>ins_vers=<pre>'.print_r($ins_vers, TRUE).'</pre>');
 
                                // Is the content valid?
                                if ((!is_array($ins_vers)) || (count($ins_vers) <= 0) || (!isset($ins_vers[$mapper[$type]])) || (trim($ins_vers[$mapper[$type]]) == '') || ($ins_vers[0]) == 'new') {
                                        // File needs update!
-                                       $new = true;
+                                       $new = TRUE;
                                } else {
                                        // Generate fake cache entry
                                        foreach ($mapper as $map => $idx) {
@@ -90,38 +115,28 @@ function getActualVersion ($type = 'Revision') {
                                        } // END - foreach
 
                                        // Return found value
-                                       $ret = getActualVersion($type);
+                                       $ret = getRepositoryData($type);
                                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
                                }
                        }
                }
 
                // Has it been updated?
-               if ($new === true)  {
+               if ($new === TRUE)  {
                        // Write it
-                       writeToFile($FQFN, implode("\n", getArrayFromActualVersion()));
+                       writeToFile($FQFN, implode(chr(10), getArrayFromRepositoryData()));
 
                        // ... and call recursive
-                       $ret = getActualVersion($type);
+                       $ret = getRepositoryData($type);
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
                } // END - if
        }
 
        // Return the value
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret . ' - EXIT!');
        return $ret;
 }
 
-// Repares an array we are looking for
-// The returned Array is needed twice (in getArrayFromActualVersion() and in getActualVersion() in the old .revision-fallback) so I puted it in an extra function to not polute the global namespace
-function getSearchFor () {
-       // Add Revision, Date, Tag and Author
-       $searchFor = array('File', 'Revision', 'Date', 'Tag', 'Author');
-
-       // Return the created array
-       return $searchFor;
-}
-
 // Extracts requested revision info from given file data
 function extractRevisionInfoFromData ($fileData, $search) {
        // Default is to return empty string
@@ -149,8 +164,9 @@ function extractRevisionInfoFromFile ($FQFN, $search) {
        return extractRevisionInfoFromData($fileData, $search);
 }
 
-// @TODO Please describe this function
-function getArrayFromActualVersion () {
+// Gets an array back for current repository data.
+// @TODO This function does also set and get in 'cache_array'
+function getArrayFromRepositoryData () {
        // Init array
        $GLOBALS['cache_array']['revision'] = array();
 
@@ -179,7 +195,7 @@ function getArrayFromActualVersion () {
        $GLOBALS['cache_array']['revision']['File'][0] = $last_changed['path_name'];
 
        // This foreach loops the $searchFor-Tags (array('Revision', 'Date', 'Tag', 'Author') --> could easaly extended in the future)
-       foreach (getSearchFor() as $search) {
+       foreach ($GLOBALS['repository_search_for'] as $search) {
                // This extracts the requested data $search from file data $last_file
                if ($search != 'File') {
                        // Skip 'File' because we have set it some lines above
@@ -190,9 +206,9 @@ function getArrayFromActualVersion () {
 
        // at least 3 keyword-Tags are needed for propper values
        if ($GLOBALS['revision_res'] && $GLOBALS['revision_res'] >= 3
-       && isset($GLOBALS['cache_array']['revision']['Revision'][0]) && $GLOBALS['cache_array']['revision']['Revision'][0] != ''
-       && isset($GLOBALS['cache_array']['revision']['Date'][0]) && $GLOBALS['cache_array']['revision']['Date'][0] != ''
-       && isset($GLOBALS['cache_array']['revision']['Tag'][0]) && $GLOBALS['cache_array']['revision']['Tag'][0] != '') {
+       && isset($GLOBALS['cache_array']['revision']['Revision'][0]) && !empty($GLOBALS['cache_array']['revision']['Revision'][0])
+       && isset($GLOBALS['cache_array']['revision']['Date'][0]) && !empty($GLOBALS['cache_array']['revision']['Date'][0])
+       && isset($GLOBALS['cache_array']['revision']['Tag'][0]) && !empty($GLOBALS['cache_array']['revision']['Tag'][0])) {
                // Prepare content witch need special treadment
 
                // Prepare timestamp for date
@@ -201,7 +217,7 @@ function getArrayFromActualVersion () {
 
                // Add author to the Tag if the author is set and is not quix0r (lead coder)
                if ((isset($GLOBALS['cache_array']['revision']['Author'][0])) && ($GLOBALS['cache_array']['revision']['Author'][0] != 'quix0r')) {
-                       $GLOBALS['cache_array']['revision']['Tag'][0] .= '-'.strtoupper($GLOBALS['cache_array']['revision']['Author'][0]);
+                       $GLOBALS['cache_array']['revision']['Tag'][0] .= '-' . strtoupper($GLOBALS['cache_array']['revision']['Author'][0]);
                } // END - if
 
        } else {
@@ -211,16 +227,24 @@ function getArrayFromActualVersion () {
                // Invalid request reply?
                if (!isset($version[11])) {
                        // Cannot continue here
-                       debug_report_bug('Invalid response from check-updates3.php, count should be 10+, is ' . count($version));
+                       reportBug(__FUNCTION__, __LINE__, 'Invalid response from check-updates3.php, count should be at least 11, is ' . count($version));
                } // END - if
 
                // Prepare content
                // Only sets not setted or not proper values to the Online-Server-Fallback-Solution
-               if (!isset($GLOBALS['cache_array']['revision']['File'][0])     || $GLOBALS['cache_array']['revision']['File'][0]     == '') $GLOBALS['cache_array']['revision']['File'][0]     = trim($version[11]);
-               if (!isset($GLOBALS['cache_array']['revision']['Revision'][0]) || $GLOBALS['cache_array']['revision']['Revision'][0] == '') $GLOBALS['cache_array']['revision']['Revision'][0] = trim($version[10]);
-               if (!isset($GLOBALS['cache_array']['revision']['Date'][0])     || $GLOBALS['cache_array']['revision']['Date'][0]     == '') $GLOBALS['cache_array']['revision']['Date'][0]     = trim($version[9]);
-               if (!isset($GLOBALS['cache_array']['revision']['Tag'][0])      || $GLOBALS['cache_array']['revision']['Tag'][0]      == '') $GLOBALS['cache_array']['revision']['Tag'][0]      = trim($version[8]);
-               if (!isset($GLOBALS['cache_array']['revision']['Author'][0])   || $GLOBALS['cache_array']['revision']['Author'][0]   == '') $GLOBALS['cache_array']['revision']['Author'][0]   = 'quix0r';
+               foreach ($GLOBALS['repository_search_for'] as $entry) {
+                       // Is it not set or empty?
+                       if ((!isset($GLOBALS['cache_array']['revision'][$entry][0])) || (empty($GLOBALS['cache_array']['revision']['File'][0]))) {
+                               // Is default data entry nummerical?
+                               if (is_numeric($GLOBALS['default_repository_data'][$entry])) {
+                                       // Use entry from $version
+                                       $GLOBALS['cache_array']['revision'][$entry][0] = trim($version[$GLOBALS['default_repository_data'][$entry]]);
+                               } else {
+                                       // Non-numeric -> use it directly
+                                       $GLOBALS['cache_array']['revision'][$entry][0] = $GLOBALS['default_repository_data'][$entry];
+                               }
+                       } // END - if
+               } // END - if
        }
 
        // Temporary remove [0] from array