aboutsummaryrefslogtreecommitdiffstats
path: root/en
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2014-07-17 21:37:26 +0200
committerfilip <filip.komar@gmail.com>2014-07-17 21:37:26 +0200
commit640dfe1d371f52819e46b76b120d0f9914412131 (patch)
tree936a43ebe2259ce4d63ffe64c8a6e8eefb1b0846 /en
parentc551633f1c29c15c56a3148fd8e4d8ce90d6bd23 (diff)
downloadwww-640dfe1d371f52819e46b76b120d0f9914412131.tar
www-640dfe1d371f52819e46b76b120d0f9914412131.tar.gz
www-640dfe1d371f52819e46b76b120d0f9914412131.tar.bz2
www-640dfe1d371f52819e46b76b120d0f9914412131.tar.xz
www-640dfe1d371f52819e46b76b120d0f9914412131.zip
added caching to improve report speed
Diffstat (limited to 'en')
-rw-r--r--en/about/license/license.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/en/about/license/license.php b/en/about/license/license.php
index 5745e0826..7ae6d1cd7 100644
--- a/en/about/license/license.php
+++ b/en/about/license/license.php
@@ -53,3 +53,88 @@ function read_license_from_vcs($locale) {
return $prepared_license_strings;
}
+
+function load_license_numbers($lang, $skip_rebuilding_cache = false)
+{
+ $pot_filename = 'libDrakX.pot';
+ $po_files_path = "http://gitweb.mageia.org/software/drakx/plain/perl-install/share/po/";
+ $cache_file = __DIR__ . '/../../../_nav/var/tmp/cache/license_numbers_' . $lang . '.php';
+ $rebuild_cache = false;
+ date_default_timezone_set(@date_default_timezone_get());
+ if($lang == 'en') {
+ $filename = $pot_filename;
+ $start_text = '"POT-Creation-Date:';
+ } else {
+ $filename = locale_hyphen_underscore($lang, true) . '.po'; // create pt_BR.po from pt-br and alike
+ $start_text = '"PO-Revision-Date:';
+ }
+ if(!$skip_rebuilding_cache) {
+ $po_file = $po_files_path . $filename;
+ $filehandle = @fopen($po_file, 'r'); // read $po_file
+ if($filehandle !== false) { // could open $po_fil
+ fclose($filehandle);
+ $po_time = get_po_time($po_file, $start_text);
+ } else {
+ $po_time = get_po_time($po_files_path . $pot_filename, $start_text);
+ if(!$po_time) { $po_time = 0; } // fallback
+ }
+ if(file_exists($cache_file)) {
+ include $cache_file;
+ if($cached_time < $po_time) {
+ $rebuild_cache = true;
+ }
+ } else {
+ $rebuild_cache = true;
+ }
+ if($rebuild_cache) {
+ $license_array = read_license_from_vcs($lang);
+ $license_numbers = array_pop($license_array);
+ $license_num_all = $license_numbers["all"];
+ $license_num_unt = $license_numbers["untran"];
+ $cache_content = <<<P
+<?php
+/**! Generated. Do not edit. */
+
+// Date in $po_file
+\$cached_time = $po_time;
+
+// $lang license numbers
+\$license_num_all = $license_num_all;
+\$license_num_unt = $license_num_unt;
+
+P;
+ file_put_contents($cache_file, $cache_content);
+ }
+ } else {
+ if(file_exists($cache_file)) {
+ include $cache_file;
+ } else { // fallback
+ $license_num_all = 0;
+ $license_num_unt = 0;
+ }
+ }
+
+ $return_license_numbers["all"] = $license_num_all;
+ $return_license_numbers["untran"] = $license_num_unt;
+ return $return_license_numbers;
+}
+
+function get_po_time($po_file, $start_text)
+{
+ $filehandle = @fopen($po_file, 'r'); // read $po_file
+ if($filehandle === false) { // still could not open $po_file
+ return 0; // fallback
+ }
+
+ while(($line = fgets($filehandle, 50)) !== false) { // check first 50 characters
+ $line = trim($line);
+ if(substr_count($line, $start_text) == 1) { // if $start_text is present
+ $line = trim(str_replace(array($start_text, '\n"'), '', $line));
+ $po_time = strtotime($line);
+ fclose($filehandle);
+ return $po_time;
+ }
+ }
+ fclose($filehandle);
+ return 0; // fallback
+}