[DOC-WEB] [web-doc] master: Generate images for translation status dynamically (#54)

[email protected] (Jim Winstead via GitHub) Wed, 23 Oct 2024 17:27:23 +0000
Newsgroups php.doc.web
Message-ID <[email protected]>
Author: Jim Winstead (jimwins)
Committer: GitHub (web-flow)
Pusher: jimwins
Date: 2024-10-23T10:24:10-07:00

Commit: https://github.com/php/web-doc/commit/ff776cad3a587d218b55fc29fa2de10acd59432f
Raw diff: https://github.com/php/web-doc/commit/ff776cad3a587d218b55fc29fa2de10acd59432f.diff

Generate images for translation status dynamically (#54)

Changed paths:
  A  www/img-status-all.php
  A  www/img-status-lang.php
  D  scripts/gen_picture_info.php
  D  scripts/gen_picture_info_all_lang.php
  M  .gitignore
  M  include/lib_general.inc.php
  M  www/revcheck.php


Diff:

diff --git a/.gitignore b/.gitignore
index f183e07..a156af6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,5 @@ sqlite
 git
 log
 shared
-www/images
 www/robots.txt
 www/doc
diff --git a/include/lib_general.inc.php b/include/lib_general.inc.php
index 32156bd..936f48b 100644
--- a/include/lib_general.inc.php
+++ b/include/lib_general.inc.php
@@ -103,7 +103,7 @@ function nav_tools($lang)
     $out .= '<li><a href="revcheck.php?p=misstags&amp;lang='.$lang.'">Missing revision numbers</a></li>';
     $out .= '<li><a href="revcheck.php?p=missfiles&amp;lang='.$lang.'">Untranslated files</a></li>';
     $out .= '<li><a href="revcheck.php?p=oldfiles&amp;lang='.$lang.'">Not in EN tree</a></li>';
-    $out .= '<li><a href="revcheck.php?p=graph&amp;lang='.$lang.'">Graph</a></li>';
-    $out .= '</ul></div></div>';
+    $out .= '</ul>';
+    $out .= '</div></div>';
     return $out;
 }
diff --git a/scripts/gen_picture_info_all_lang.php b/scripts/gen_picture_info_all_lang.php
deleted file mode 100644
index 03ccad6..0000000
--- a/scripts/gen_picture_info_all_lang.php
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-include '../include/jpgraph/src/jpgraph.php';
-include '../include/jpgraph/src/jpgraph_bar.php';
-
-include '../include/init.inc.php';
-include '../include/lib_revcheck.inc.php';
-
-$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
-
-$language = revcheck_available_languages($idx);
-sort($language);
-$files_EN = count_en_files($idx);
-
-foreach ($language as $lang) {
-    $tmp = get_stats($idx, $lang, 'uptodate');
-
-    $percent_tmp[] = round($tmp[0] * 100 / $files_EN);
-    $legend_tmp[] = $lang;
-}
-
-$percent = array_values($percent_tmp);
-$legend = array_values($legend_tmp);
-
-echo "Generating PHP graphic for all languages...";
-generate_image();
-echo " Done.\n";
-
-function generate_image() {
-    global $percent, $legend;
-
-    // Create the graph. These two calls are always required
-    $graph = new Graph(600,262);
-    $graph->SetScale("textlin");
-    $graph->yaxis->scale->SetGrace(20);
-
-    $graph->xaxis->SetLabelmargin(5);
-    $graph->xaxis->SetTickLabels($legend);
-
-    $graph->ygrid->SetFill(true,'#[email protected]','#[email protected]');
-
-    // Add a drop shadow
-    $graph->SetShadow();
-
-    // Adjust the margin a bit to make more room for titles
-    $graph->img->SetMargin(50,30,20,40);
-
-    // Create a bar pot
-    $bplot = new BarPlot($percent);
-
-    // Adjust fill color
-    $bplot->SetFillColor('#9999CC');
-
-    $bplot->SetShadow();
-    $bplot->value->Show();
-    $bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
-    $bplot->value->SetAngle(45);
-    $bplot->value->SetFormat('%0.0f');
-
-    // Width
-    $bplot->SetWidth(0.6);
-
-    $graph->Add($bplot);
-
-    // Setup the titles
-    $graph->title->Set("PHP documentation");
-    $graph->xaxis->title->Set("Language");
-    $graph->yaxis->title->Set("Files up to date (%)");
-
-    $graph->title->SetFont(FF_FONT1,FS_BOLD);
-    $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
-    $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
-
-    // Display the graph
-    $graph->Stroke('../www/images/revcheck/info_revcheck_php_all_lang.png');
-}
diff --git a/www/img-status-all.php b/www/img-status-all.php
new file mode 100644
index 0000000..6e2f5f8
--- /dev/null
+++ b/www/img-status-all.php
@@ -0,0 +1,67 @@
+<?php
+require_once __DIR__ . '/../include/jpgraph/src/jpgraph.php';
+require_once __DIR__ . '/../include/jpgraph/src/jpgraph_bar.php';
+
+require_once __DIR__ . '/../include/init.inc.php';
+require_once __DIR__ . '/../include/lib_revcheck.inc.php';
+
+$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
+
+$language = revcheck_available_languages($idx);
+sort($language);
+$files_EN = count_en_files($idx);
+
+foreach ($language as $lang) {
+    $tmp = get_stats($idx, $lang, 'uptodate');
+
+    $percent_tmp[] = round($tmp[0] * 100 / $files_EN);
+    $legend_tmp[] = $lang;
+}
+
+$percent = array_values($percent_tmp);
+$legend = array_values($legend_tmp);
+
+// Create the graph. These two calls are always required
+$graph = new Graph(600,262);
+$graph->SetScale("textlin");
+$graph->yaxis->scale->SetGrace(20);
+
+$graph->xaxis->SetLabelmargin(5);
+$graph->xaxis->SetTickLabels($legend);
+
+$graph->ygrid->SetFill(true,'#[email protected]','#[email protected]');
+
+// Add a drop shadow
+$graph->SetShadow();
+
+// Adjust the margin a bit to make more room for titles
+$graph->img->SetMargin(50,30,20,40);
+
+// Create a bar pot
+$bplot = new BarPlot($percent);
+
+// Adjust fill color
+$bplot->SetFillColor('#9999CC');
+
+$bplot->SetShadow();
+$bplot->value->Show();
+$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
+$bplot->value->SetAngle(45);
+$bplot->value->SetFormat('%0.0f');
+
+// Width
+$bplot->SetWidth(0.6);
+
+$graph->Add($bplot);
+
+// Setup the titles
+$graph->title->Set("PHP Translation Status");
+$graph->xaxis->title->Set("Language");
+$graph->yaxis->title->Set("Files up to date (%)");
+
+$graph->title->SetFont(FF_FONT1,FS_BOLD);
+$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
+$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
+
+// Display the graph
+$graph->Stroke();
diff --git a/scripts/gen_picture_info.php b/www/img-status-lang.php
similarity index 78%
rename from scripts/gen_picture_info.php
rename to www/img-status-lang.php
index c43a9f6..b3c6e25 100644
--- a/scripts/gen_picture_info.php
+++ b/www/img-status-lang.php
@@ -1,13 +1,12 @@
 <?php
-$time_start = microtime(true);
 
-include '../include/jpgraph/src/jpgraph.php';
-include '../include/jpgraph/src/jpgraph_pie.php';
-include '../include/jpgraph/src/jpgraph_pie3d.php';
+require_once __DIR__ . '/../include/jpgraph/src/jpgraph.php';
+require_once __DIR__ . '/../include/jpgraph/src/jpgraph_pie.php';
+require_once __DIR__ . '/../include/jpgraph/src/jpgraph_pie3d.php';
 
-include '../include/init.inc.php';
-include '../include/lib_revcheck.inc.php';
-include '../include/lib_proj_lang.inc.php';
+require_once __DIR__ . '/../include/init.inc.php';
+require_once __DIR__ . '/../include/lib_revcheck.inc.php';
+require_once __DIR__ . '/../include/lib_proj_lang.inc.php';
 
 $idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
 
@@ -16,16 +15,12 @@
 $langs = array_keys($LANGUAGES);
 foreach ($langs as $lang) {
     if (!in_array($lang, $available_langs)) {
-        echo "Documentation for $lang language does not exist.\n";
+        die("Information for $lang language does not exist.");
     } else {
         generate_image($lang, $idx);
-        echo "Generated images/revcheck/info_revcheck_php_$lang.png\n";
     }
 }
 
-$time = round(microtime(true) - $time_start, 3);
-echo "Graphs generated in {$time}s\n";
-
 function generate_image($lang, $idx) {
     global $LANGUAGES;
 
@@ -90,5 +85,5 @@ function generate_image($lang, $idx) {
     $p1->SetLegends($legend);
 
     $graph->Add($p1);
-    $graph->Stroke("../www/images/revcheck/info_revcheck_php_$lang.png");
+    $graph->Stroke();
 }
diff --git a/www/revcheck.php b/www/revcheck.php
index fd0834b..4820bac 100644
--- a/www/revcheck.php
+++ b/www/revcheck.php
@@ -428,18 +428,9 @@
  break;
 
  case 'graph':
-     $path = "images/revcheck/info_revcheck_php_$lang.png";
-     if (is_readable(__DIR__ . "/" . $path)) {
-         echo '<img src="'.$path.'" alt="info">';
-         echo gen_date($DBLANG);
-     } else {
-         echo "<p>Can't find graph.</p>";
-     }
- break;
-
  default:
      if ($lang == 'en') {
-         echo '<img src="images/revcheck/info_revcheck_php_all_lang.png" alt="Info" class="chart">';
+         echo '<img src="img-status-all.php" width="662" height="262" alt="Info" class="chart">';
          echo '<p>This is all what we can show for original manual. To get more tools, please select translation language.</p>';
          echo gen_date($DBLANG);
          $sidebar = nav_languages();
@@ -449,6 +440,8 @@
          $intro = $intro_result->fetchArray();
          echo '<h2>Intro for language</h2>';
          echo '<p>'.$intro[0].'</p>';
+         echo '<img src="img-status-lang.php?lang=', $lang, '" width="680" height="300" alt="info">';
+         echo gen_date($DBLANG);
          echo '<p>Links to available tools are placed on the right sidebar.</p>';
      }
  break;