-// Function to search for the last modifified file
-function searchDirsRecursive ($dir, &$last_changed) {
- // Get dir as array
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=" . $dir.'<br />');
- // Does it match what we are looking for? (We skip a lot files already!)
- // RegexPattern to exclude ., .., .revision, .svn, debug.log or .cache in the filenames
- $excludePattern = '@(\.revision|debug\.log|\.cache|config\.php)$@';
- $ds = getArrayFromDirectory($dir, '', true, false, array(), '.php', $excludePattern);
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds).'<br />');
-
- // Walk through all entries
- foreach ($ds as $d) {
- // Generate proper FQFN
- $FQFN = str_replace('//', '/', getConfig('PATH') . $dir. '/'. $d);
-
- // Is it a file and readable?
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):FQFN={$FQFN}<br />");
- if (isDirectory($FQFN)) {
- // $FQFN is a directory so also crawl into this directory
- $newDir = $d;
- if (!empty($dir)) $newDir = $dir . '/'. $d;
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):DESCENT: " . $newDir.'<br />');
- searchDirsRecursive($newDir, $last_changed);
- } elseif (isFileReadable($FQFN)) {
- // $FQFN is a filename and no directory
- $time = filemtime($FQFN);
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):File: " . $d." found. (".($last_changed['time'] - $time).")<br />");
- if ($last_changed['time'] < $time) {
- // This file is newer as the file before
- //* DEBUG: */ outputHtml(__FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>) - NEWER!<br />");
- $last_changed['path_name'] = $FQFN;
- $last_changed['time'] = $time;
- } // END - if
- }
- } // END - foreach
-}
-
-// "Getter" for revision/version data
-function getActualVersion ($type = 'Revision') {
- // By default nothing is new... ;-)
- $new = false;
-
- // Is the cache entry there?
- if (isset($GLOBALS['cache_array']['revision'][$type])) {
- // Found so increase cache hit
- incrementStatsEntry('cache_hits');
-
- // Return it
- return $GLOBALS['cache_array']['revision'][$type][0];
- } else {
- // FQFN of revision file
- $FQFN = sprintf("%s/.revision", getConfig('CACHE_PATH'));
-
- // Check if 'check_revision_data' is setted (switch for manually rewrite the .revision-File)
- if ((isGetRequestElementSet('check_revision_data')) && (getRequestElement('check_revision_data') == 'yes')) {
- // Forced rebuild of .revision file
- $new = true;
- } else {
- // Check for revision file
- if (!isFileReadable($FQFN)) {
- // Not found, so we need to create it
- $new = true;
- } else {
- // Revision file found
- $ins_vers = explode("\n", 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>');
-
- // 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;
- } else {
- // Generate fake cache entry
- foreach ($mapper as $map => $idx) {
- $GLOBALS['cache_array']['revision'][$map][0] = $ins_vers[$idx];
- } // END - foreach
-
- // Return found value
- return trim($ins_vers[$mapper[$type]]);
- }
- }
- }
-
- // Has it been updated?
- if ($new === true) {
- // Write it
- writeToFile($FQFN, implode("\n", getArrayFromActualVersion()));
-
- // ... and call recursive
- return getActualVersion($type);
- } // END - if
- }
-}
-
-// 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('Revision', 'Date', 'Tag', 'Author', 'File');
-
- // Return the created array
- return $searchFor;
-}
-
-// @TODO Please describe this function
-function getArrayFromActualVersion () {
- // Init variables
- $next_dir = '';
-
- // Directory to start with search
- $last_changed = array(
- 'path_name' => '',
- 'time' => 0
- );
-
- // Init return array
- $akt_vers = array();
-
- // Init value for counting the founded keywords
- $res = '0';
-
- // Searches all Files and there date of the last modifikation and puts the newest File in $last_changed.
- searchDirsRecursive($next_dir, $last_changed); // @TODO small change to API to $last_changed = searchDirsRecursive($next_dir, $time);
-
- // Get file
- $last_file = readFromFile($last_changed['path_name']);
-
- // Get all the keywords to search for
- $searchFor = getSearchFor();
-
- // This foreach loops the $searchFor-Tags (array('Revision', 'Date', 'Tag', 'Author') --> could easaly extended in the future)
- foreach ($searchFor as $search) {
- // Searches for "$search-tag:VALUE$" or "$search-tag::VALUE$"(the stylish keywordversion ;-)) in the lates modified file
- $res += preg_match('@\$' . $search.'(:|::) (.*) \$@U', $last_file, $t);
- // This trimms the search-result and puts it in the $GLOBALS['cache_array']['revision']-return array
- if (isset($t[2])) $GLOBALS['cache_array']['revision'][$search] = trim($t[2]);
- } // END - foreach
-
- // Save the last-changed filename for debugging
- $GLOBALS['cache_array']['revision']['File'] = $last_changed['path_name'];
-
- // at least 3 keyword-Tags are needed for propper values
- if ($res && $res >= 3
- && isset($GLOBALS['cache_array']['revision']['Revision']) && $GLOBALS['cache_array']['revision']['Revision'] != ''
- && isset($GLOBALS['cache_array']['revision']['Date']) && $GLOBALS['cache_array']['revision']['Date'] != ''
- && isset($GLOBALS['cache_array']['revision']['Tag']) && $GLOBALS['cache_array']['revision']['Tag'] != '') {
- // Prepare content witch need special treadment
-
- // Prepare timestamp for date
- preg_match('@(....)-(..)-(..) (..):(..):(..)@', $GLOBALS['cache_array']['revision']['Date'], $match_d);
- $GLOBALS['cache_array']['revision']['Date'] = mktime($match_d[4], $match_d[5], $match_d[6], $match_d[2], $match_d[3], $match_d[1]);
-
- // Add author to the Tag if the author is set and is not quix0r (lead coder)
- if ((isset($GLOBALS['cache_array']['revision']['Author'])) && ($GLOBALS['cache_array']['revision']['Author'] != 'quix0r')) {
- $GLOBALS['cache_array']['revision']['Tag'] .= '-'.strtoupper($GLOBALS['cache_array']['revision']['Author']);
- } // END - if
-
- } else {
- // No valid Data from the last modificated file so read the Revision from the Server. Fallback-solution!! Should not be removed I think.
- $version = sendGetRequest('check-updates3.php');
-
- // Prepare content
- // Only sets not setted or not proper values to the Online-Server-Fallback-Solution
- if (!isset($GLOBALS['cache_array']['revision']['Revision']) || $GLOBALS['cache_array']['revision']['Revision'] == '') $GLOBALS['cache_array']['revision']['Revision'] = trim($version[10]);
- if (!isset($GLOBALS['cache_array']['revision']['Date']) || $GLOBALS['cache_array']['revision']['Date'] == '') $GLOBALS['cache_array']['revision']['Date'] = trim($version[9]);
- if (!isset($GLOBALS['cache_array']['revision']['Tag']) || $GLOBALS['cache_array']['revision']['Tag'] == '') $GLOBALS['cache_array']['revision']['Tag'] = trim($version[8]);
- if (!isset($GLOBALS['cache_array']['revision']['Author']) || $GLOBALS['cache_array']['revision']['Author'] == '') $GLOBALS['cache_array']['revision']['Author'] = 'quix0r';
- if (!isset($GLOBALS['cache_array']['revision']['File']) || $GLOBALS['cache_array']['revision']['File'] == '') $GLOBALS['cache_array']['revision']['File'] = trim($version[11]);
- }
-
- // Return prepared array
- return $GLOBALS['cache_array']['revision'];
-}
-