<?php
-/************************************************************************
- * Mailer v0.2.1-FINAL Start: 12/15/2009 *
- * =================== Last change: 12/15/2009 *
- * *
- * -------------------------------------------------------------------- *
- * File : revision-functions.php *
- * -------------------------------------------------------------------- *
- * Short description : Revison-info related functions *
- * -------------------------------------------------------------------- *
- * Kurzbeschreibung : Revsions-Info relevante Funktionen *
- * -------------------------------------------------------------------- *
- * $Revision:: $ *
- * $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 *
- * Copyright (c) 2009, 2010 by Mailer Developer Team *
- * For more information visit: http://www.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 *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
- * MA 02110-1301 USA *
- ************************************************************************/
-
-// Some security stuff...
-if (!defined('__SECURITY')) {
- die();
-} // END - if
-
-// "Getter" for revision/version data
-function getActualVersion ($type = 'Revision') {
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . '] - ENTRY!');
- // Default is an invalid value to find bugs... :-)
- $ret = 'INVALID';
-
- // By default nothing is new... ;-)
- $new = false;
-
- // Is the cache entry there?
- if (isset($GLOBALS['cache_array']['revision'][$type][0])) {
- // Found so increase cache hit
- incrementStatsEntry('cache_hits');
-
- // Return it
- $ret = $GLOBALS['cache_array']['revision'][$type][0];
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
- } 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 ((isGetRequestParameterSet('check_revision_data')) && (getRequestParameter('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
- $ret = getActualVersion($type);
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
- }
- }
- }
-
- // Has it been updated?
- if ($new === true) {
- // Write it
- writeToFile($FQFN, implode("\n", getArrayFromActualVersion()));
-
- // ... and call recursive
- $ret = getActualVersion($type);
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
- } // END - if
- }
-
- // Return the value
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret[' . $type . ']=' . $ret);
- 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
- $ret = '';
-
- // Searches for "$search-tag:VALUE$" or "$search-tag::VALUE$"(the stylish keywordversion ;-)) in the lates modified file
- $GLOBALS['revision_res'] += preg_match('@\$' . $search . '(:|::) (.*) \$@U', $fileData, $t);
-
- // Make sure only valid and trimmed entries are used
- if (isset($t[2])) {
- $ret = trim($t[2]);
- } // END - if
-
- // Return the result
- return $ret;
-}
-
-// Extracts requested revison info for given file name by reading it's content
-// and parsing it with extractRevisionInfoFromData().
-function extractRevisionInfoFromFile ($FQFN, $search) {
- // Read the file
- $fileData = readFromFile($FQFN);
-
- // Call the extract function and return the result
- return extractRevisionInfoFromData($fileData, $search);
-}
-
-// @TODO Please describe this function
-function getArrayFromActualVersion () {
- // Init array
- $GLOBALS['cache_array']['revision'] = array();
-
- // 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
- $GLOBALS['revision_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, 'Revision');
-
- // Get file
- $last_file = readFromFile($last_changed['path_name']);
-
- // Save the last-changed filename for debugging
- $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) {
- // This extracts the requested data $search from file data $last_file
- if ($search != 'File') {
- // Skip 'File' because we have set it some lines above
- $GLOBALS['cache_array']['revision'][$search][0] = extractRevisionInfoFromData($last_file, $search);
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'search=' . $search . ',data=' . $GLOBALS['cache_array']['revision'][$search][0]);
- } // END - if
- } // END - foreach
-
- // 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] != '') {
- // Prepare content witch need special treadment
-
- // Prepare timestamp for date
- preg_match('@(....)-(..)-(..) (..):(..):(..)@', $GLOBALS['cache_array']['revision']['Date'][0], $match_d);
- $GLOBALS['cache_array']['revision']['Date'][0] = 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'][0])) && ($GLOBALS['cache_array']['revision']['Author'][0] != 'quix0r')) {
- $GLOBALS['cache_array']['revision']['Tag'][0] .= '-'.strtoupper($GLOBALS['cache_array']['revision']['Author'][0]);
- } // 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');
-
- // 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));
- } // 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';
- }
-
- // Temporary remove [0] from array
- $array = $GLOBALS['cache_array']['revision'];
- foreach ($array as $key => $value) {
- if ((is_array($value)) && (isset($value[0]))) {
- unset($array[$key][0]);
- $array[$key] = $value[0];
- } // END - if
- } // END - if
-
- // Return prepared array
- return $array;
-}
-
-// [EOF]
+// @DEPRECATED
?>