-// Clears the output buffer. This function does *NOT* backup sent content.
-function clearOutputBuffer () {
- // Trigger an error on failure
- if (!ob_end_clean()) {
- // Failed!
- debug_report_bug(__FUNCTION__.": Failed to clean output buffer.");
- } // END - if
-}
-
-// Function to search for the last modifified file
-function searchDirsRecursive ($dir, &$last_changed) {
- // Get dir as array
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):dir=".$dir."<br />\n";
- // 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|\.svn|debug\.log|\.cache|config\.php)$@';
- $ds = GET_DIR_AS_ARRAY($dir, '', true, false, $excludePattern);
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):ds[]=".count($ds)."<br />\n";
-
- // Walk through all entries
- foreach ($ds as $d) {
- // Generate proper FQFN
- $FQFN = str_replace("//", "/", constant('PATH') . $dir. "/". $d);
-
- // Is it a file and readable?
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):FQFN={$FQFN}<br />\n";
- if (isDirectory($FQFN)) {
- // $FQFN is a directory so also crawl into this directory
- $newDir = $d;
- if (!empty($dir)) $newDir = $dir . "/". $d;
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):DESCENT: ".$newDir."<br />\n";
- searchDirsRecursive($newDir, $last_changed);
- } elseif (FILE_READABLE($FQFN)) {
- // $FQFN is a filename and no directory
- $time = filemtime($FQFN);
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):File: ".$d." found. (".($last_changed['time'] - $time).")<br />\n";
- if ($last_changed['time'] < $time) {
- // This file is newer as the file before
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>) - NEWER!<br />\n";
- $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;
-
- if (EXT_IS_ACTIVE('cache')) {
- // Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
- if (REQUEST_ISSET_GET('check_revision_data') && REQUEST_GET('check_revision_data') == 'yes') $new = true;
- if (!isset($GLOBALS['cache_array']['revision'][$type])
- || count($GLOBALS['cache_array']['revision']) < 3
- || !$GLOBALS['cache_instance']->loadCacheFile('revision')) $new = true;
-
- // Is the cache file outdated/invalid?
- if ($new === true){
- $GLOBALS['cache_instance']->destroyCacheFile(); // @TODO isn't it better to do $GLOBALS['cache_instance']->destroyCacheFile('revision')?
-
- // @TODO shouldn't do the unset and the reloading $GLOBALS['cache_instance']->destroyCacheFile() Or a new methode like forceCacheReload('revision')?
- unset($GLOBALS['cache_array']['revision']);
-
- // Reload load_cach-revison.php
- LOAD_INC('inc/loader/load_cache-revision.php');
- } // END - if
-
- // Return found value
- return $GLOBALS['cache_array']['revision'][$type][0];
-
- } else {
- // Old Version without ext-cache active (deprecated ?)
-
- // FQFN of revision file
- $FQFN = sprintf("%sinc/cache/.revision", constant('PATH'));
-
- // Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
- if ((REQUEST_ISSET_GET('check_revision_data')) && (REQUEST_GET('check_revision_data') == 'yes')) {
- // Has changed!
- $new = true;
- } else {
- // Check for revision file
- if (!FILE_READABLE($FQFN)) {
- // Not found, so we need to create it
- $new = true;
- } else {
- // Revision file found
- $ins_vers = explode("\n", READ_FILE($FQFN));
-
- // Get array for mapping information
- $mapper = array_flip(getSearchFor());
- //* DEBUG: */ print("<pre>".print_r($mapper, true).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 {
- // Return found value
- return trim($ins_vers[$mapper[$type]]);
- }
- }
- }
-
- // Has it been updated?
- if ($new === true) {
- WRITE_FILE($FQFN, implode("\n", getAkt_vers()));
- } // END - if
- }
-}
-
-// Repares an array we are looking for
-// The returned Array is needed twice (in getAkt_vers() 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');
-
- // Return the created array
- return $searchFor;
-}
-
-function getAkt_vers () {
- // Init variables
- $next_dir = ''; // Directory to start with search
- $last_changed = array(
- 'path_name' => "",
- 'time' => 0
- );
- $akt_vers = array(); // Init return array
- $res = 0; // Init value for counting the founded keywords
-
- // 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 = READ_FILE($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 $akt_vers-return array
- if (isset($t[2])) $akt_vers[$search] = trim($t[2]);
- } // END - foreach
-
- // Save the last-changed filename for debugging
- $akt_vers['File'] = $last_changed['path_name'];
-
- // at least 3 keyword-Tags are needed for propper values
- if ($res && $res >= 3
- && isset($akt_vers['Revision']) && $akt_vers['Revision'] != ''
- && isset($akt_vers['Date']) && $akt_vers['Date'] != ''
- && isset($akt_vers['Tag']) && $akt_vers['Tag'] != '') {
- // Prepare content witch need special treadment
-
- // Prepare timestamp for date
- preg_match('@(....)-(..)-(..) (..):(..):(..)@', $akt_vers['Date'], $match_d);
- $akt_vers['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($akt_vers['Author'])) && ($akt_vers['Author'] != "quix0r")) {
- $akt_vers['Tag'] .= '-'.strtoupper($akt_vers['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 = GET_URL("check-updates3.php");
-
- // Prepare content
- // Only sets not setted or not proper values to the Online-Server-Fallback-Solution
- if (!isset($akt_vers['Revision']) || $akt_vers['Revision'] == '') $akt_vers['Revision'] = trim($version[10]);
- if (!isset($akt_vers['Date']) || $akt_vers['Date'] == '') $akt_vers['Date'] = trim($version[9]);
- if (!isset($akt_vers['Tag']) || $akt_vers['Tag'] == '') $akt_vers['Tag'] = trim($version[8]);
- if (!isset($akt_vers['Author']) || $akt_vers['Author'] == '') $akt_vers['Author'] = "quix0r";
- }
-
- // Return prepared array
- return $akt_vers;
-}
-
-
-// Loads an include file and logs any missing files for debug purposes
-function LOAD_INC ($INC) {
- // Add the path. This is why we need a trailing slash in config.php
- $FQFN = constant('PATH') . $INC;
-
- // Is the include file there?
- if (!INCLUDE_READABLE($INC)) {
- // Not there so log it
- debug_report_bug(sprintf("Include file %s not found.", $INC));
- return false;
- } // END - if
-
- // Try to load it
- require($FQFN);
-}
-
-// Loads an include file once
-function LOAD_INC_ONCE ($INC) {
- // Is it not loaded?
- if (!isset($GLOBALS['load_once'][$INC])) {
- // Then try to load it
- LOAD_INC($INC);
-
- // And mark it as loaded
- $GLOBALS['load_once'][$INC] = "loaded";
- } // END - if
-}
-