From 1cd7d7fdb5d0a26f42fff8d8efc93297694cf783 Mon Sep 17 00:00:00 2001 From: Benoit Lavenier Date: Fri, 18 Aug 2023 19:43:03 +0200 Subject: [PATCH 01/23] Release 1.7.8 --- cesiumVersions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cesiumVersions.php b/cesiumVersions.php index 859623c..c6ab2ab 100644 --- a/cesiumVersions.php +++ b/cesiumVersions.php @@ -1,10 +1,10 @@ '1.7.6', - 'android' => '1.7.6', - 'debian' => '1.7.6', + 'home' => '1.7.8', + 'android' => '1.7.8', + 'debian' => '1.7.8', 'arch' => '1.6.1', 'windows' => '1.7.6', - 'web' => '1.7.6' + 'web' => '1.7.8' ]; From 7090d25cf57439ac2d2abc55ffe2d2cef2ad0ee3 Mon Sep 17 00:00:00 2001 From: Benoit Lavenier Date: Fri, 18 Aug 2023 19:44:18 +0200 Subject: [PATCH 02/23] Release 1.7.9 --- cesiumVersions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cesiumVersions.php b/cesiumVersions.php index c6ab2ab..8217ad3 100644 --- a/cesiumVersions.php +++ b/cesiumVersions.php @@ -1,10 +1,10 @@ '1.7.8', - 'android' => '1.7.8', - 'debian' => '1.7.8', + 'home' => '1.7.9', + 'android' => '1.7.9', + 'debian' => '1.7.9', 'arch' => '1.6.1', 'windows' => '1.7.6', - 'web' => '1.7.8' + 'web' => '1.7.9' ]; From e89afbcfba1fd3c478712bd8350f7bddd6e41fb2 Mon Sep 17 00:00:00 2001 From: Benoit Lavenier Date: Fri, 18 Aug 2023 20:13:48 +0200 Subject: [PATCH 03/23] Release 1.7.9 - Upgrade windows version --- cesiumVersions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cesiumVersions.php b/cesiumVersions.php index 8217ad3..aa7637f 100644 --- a/cesiumVersions.php +++ b/cesiumVersions.php @@ -5,6 +5,6 @@ 'android' => '1.7.9', 'debian' => '1.7.9', 'arch' => '1.6.1', - 'windows' => '1.7.6', + 'windows' => '1.7.9', 'web' => '1.7.9' ]; From da42569e505b26fa114d43703da4d7411cabcad4 Mon Sep 17 00:00:00 2001 From: Boris Paing Date: Thu, 19 Oct 2023 10:18:13 +0200 Subject: [PATCH 04/23] [fix] quickfix Crowdfunding --- tpl/funding-orig.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tpl/funding-orig.php b/tpl/funding-orig.php index 543d346..b939609 100644 --- a/tpl/funding-orig.php +++ b/tpl/funding-orig.php @@ -32,6 +32,7 @@ sub(new DateInterval('P1M')); @@ -85,6 +86,7 @@ echo ''; } + */ ?> @@ -114,10 +116,11 @@ + @@ -247,6 +250,7 @@ setTarget(FUNDING_TARGET); $chart = new Chart($currentCF); @@ -271,6 +275,7 @@ echo $chart->getScripts(LANG, '#chart', $rootURL . '/vendor/crowdfunding2/'); +*/ ?> From 68ba5854029321e1b394878ce5deb4e30ad5c7ae Mon Sep 17 00:00:00 2001 From: Boris Paing Date: Fri, 20 Oct 2023 11:06:53 +0200 Subject: [PATCH 05/23] [doc] ajout instructions Nginx --- doc/en/install.md | 119 +++++++++++++++++++---- doc/fr/installation.md | 211 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 286 insertions(+), 44 deletions(-) diff --git a/doc/en/install.md b/doc/en/install.md index 9cc46e7..e6cca0e 100644 --- a/doc/en/install.md +++ b/doc/en/install.md @@ -1,23 +1,114 @@ How to install Cesium website on your computer === -## How to install the web server le serveur web -To run Cesium website on your computer, you will need install a web server, and PHP ; the later converts the source code contained in *.php files into HTML the browser can understand. +## (optional) Configure multilang -Linux users will need two packages: +``` +# Root, on Debian +echo -e "ca_ES.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\nen_GB.UTF-8 UTF-8\neo UTF-8\nes_ES.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8" >> /etc/locale.gen +locale-gen +update-locale +service php*-fpm restart +``` + +## config.php + +In ̀`config.php`, edit $rootURL var according to your setup. + +```php +if ($_SERVER['SERVER_NAME'] == 'localhost') { + // Adaptez la ligne suivante à votre configuration (sans slash à la fin) + $rootURL = '/cesium_website'; +} else { + $rootURL = ''; +} +``` + +## Installer PHP + +To run Cesium website on your computer, you will need install and PHP, which converts the source code contained in *.php files into HTML the browser can understand. + + +Windows users can use [WAMP Serveur](https://www.wampserver.com/), which comes with a web server + +## How to install a web server + +To run Cesium website on your computer, you will also need a web server + +You can choose one of the following: - apache2 -- php +- nginx + +## Nginx + +Linux users will have to install the `nginx` package. For instance, Debian-like (Ubuntu, Linux Mint, etc.) users will have to run: ``` -sudo apt install apache2 php +sudo apt install nginx ``` -Windows users can use [WAMP Serveur](https://www.wampserver.com/). +Go to `/etc/nginx/sites-available/`. + +Edit the `default` file to add the bloc that follows `# Configuration for /cesium_website`. + + +```txt +server { + + listen 80; + + root /var/www/localhost; + + index index.php index.html index.htm index.nginx-debian.html; + + server_name localhost; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } -## .htaccess + # Configuration for /cesium_website + location /cesium_website { + + if (!-e $request_filename) { + + rewrite ^/cesium_website/([^/]+)/(.*)$ /cesium_website/index.php?lang=$1&page=/$2 last; + rewrite ^/cesium_website/([^/]+)$ /cesium_website/index.php?lang=fr&page=/$1 last; + } + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # Assurez-vous de vérifier et d'utiliser la version correcte de PHP + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + } +} +``` + +Note : don't forget to change `php8.1` for the version of PHP you installed. + +Restart nginx : +``` +sudo service nginx restart +``` + +## Apache + +Linux users will have to install the `apache2` package. + +For instance, Debian-like (Ubuntu, Linux Mint, etc.) users will have to run: + +``` +sudo apt install apache2 +``` + +### .htaccess Create a .htaccess in cesium_website directory, with the following text : @@ -62,17 +153,3 @@ with : Require all granted ``` - -## config.php - -In ̀`config.php`, edit $rootURL var according to your setup. - -## Configure multilang - -``` -# Root, on Debian -echo -e "ca_ES.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\nen_GB.UTF-8 UTF-8\neo UTF-8\nes_ES.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8" >> /etc/locale.gen -locale-gen -update-locale -service php*-fpm restart -``` diff --git a/doc/fr/installation.md b/doc/fr/installation.md index f3c336e..671d27d 100644 --- a/doc/fr/installation.md +++ b/doc/fr/installation.md @@ -1,23 +1,204 @@ Installer le site sur son ordinateur === -## Installer le serveur web +## (optionnel) Configurer le multilangue -Pour faire tourner ce site sur votre ordinateur, vous aurez besoin d'installer un serveur web ainsi que PHP, qui transforme le code source contenu dans les fichiers *.php en HTML que le navigateur du visiteur peut comprendre. +``` +# En root, sur Debian +echo -e "ca_ES.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\nen_GB.UTF-8 UTF-8\neo UTF-8\nes_ES.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8" >> /etc/locale.gen +locale-gen +update-locale +service php*-fpm restart +``` + +## config.php + +Dans le fichier `config.php`, modifiez la variable `$rootURL` pour qu'elle corresponde à la façon dont vous servez le site web : +```php +if ($_SERVER['SERVER_NAME'] == 'localhost') { + // Adaptez la ligne suivante à votre configuration (sans slash à la fin) + $rootURL = '/cesium_website'; +} else { + $rootURL = ''; +} +``` + +## Installer PHP + +Pour faire tourner ce site sur votre ordinateur, vous aurez besoin d'installer PHP, qui transformera le code source contenu dans les fichiers *.php en HTML que le navigateur du visiteur peut comprendre. -Sous Linux, il vous faudra installer les paquets : +Sous Linux, il vous faudra installer le paquet `php`. + +Par exemple, sous une Debian-like (Ubuntu, Linux Mint, etc.) : + +``` +sudo apt install php +``` + +Les utilisateurs de Windows peuvent utiliser [WAMP Serveur](https://www.wampserver.com/), qui vient aussi avec son serveur web. + + +## Installer un serveur web + +Pour faire tourner ce site sur votre ordinateur, vous aurez besoin d'installer un serveur web. + +Vous avez le choix entre : +- nginx - apache2 -- php + +## Nginx + +Sous Linux, il vous faudra installer le paquet `nginx`. Par exemple, sous une Debian-like (Ubuntu, Linux Mint, etc.) : ``` -sudo apt install apache2 php +sudo apt install nginx +``` + +### configurer Nginx + +Les fichiers de configuration de Nginx se trouvent dans `/etc/nginx/sites-available/`. + +#### option 1 : modifier `default` + +Vous avez probablement dans ce répertoire un fichier `default` auquel vous pouvez ajouter le bloc d'instruction qui suit le commentaire `# Configuration pour /cesium_website`. + + +```txt +server { + + listen 80; + + root /var/www/localhost; + + # Le premier fichier d'index recherché est index.php + index index.php index.html index.htm index.nginx-debian.html; + + server_name localhost; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + # Configuration pour /cesium_website + location /cesium_website { + + # Si le fichier ou le répertoire n'existe pas + if (!-e $request_filename) { + + # Réécriture d'URL + rewrite ^/cesium_website/([^/]+)/(.*)$ /cesium_website/index.php?lang=$1&page=/$2 last; + rewrite ^/cesium_website/([^/]+)$ /cesium_website/index.php?lang=fr&page=/$1 last; + } + + # Traitement des fichiers PHP + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # Assurez-vous de vérifier et d'utiliser la version correcte de PHP + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + } +} +``` + +Note : pensez à remplacer `php8.1` par la version de PHP que vous avez installée. + +Redémarrez nginx : +``` +sudo service nginx restart +``` + +#### option 1 : créer un fichier de configuration dédié + +Vous pouvez aussi créer un nouveau fichier de configuration, et un nouveau nom de serveur local. + +Commencez par créer un lien symbolique vers l'emplacement approprié : +``` +ln -s /var/www/cesium_website /home/votre_nom_d_utilisateur/projets/cesium_website +``` +en remplçant le chemin de destination par l'emplacement où vous avez téléchargé le dossier `cesium_website`. + +Auquel cas il vous faudra modifier votre fichier `/etc/hosts` : +``` +sudo nano /etc/hosts +``` + +pour y ajouter une ligne du style : +```txt +127.0.0.1 cesiumwebsite +``` + +Créez le fichier de configuration : +``` +sudo nano /etc/nginx/sites-available/cesium_website +``` + +et ajoutez-y le contenu idoine : ``` +server { -Les utilisateurs de Windows peuvent utiliser [WAMP Serveur](https://www.wampserver.com/). + listen 80; -## .htaccess + root /var/www/cesium_website; + + # Le premier fichier d'index recherché est index.php + index index.php index.html index.htm index.nginx-debian.html; + + server_name cesiumwebsite; + + location / { + # First attempt to serve request as file, then + # as directory, then fall back to displaying a 404. + try_files $uri $uri/ =404; + } + + # Configuration pour / + location / { + + # Si le fichier ou le répertoire n'existe pas + if (!-e $request_filename) { + + # Réécriture d'URL + rewrite ^/([^/]+)/(.*)$ /index.php?lang=$1&page=/$2 last; + rewrite ^/([^/]+)$ /index.php?lang=fr&page=/$1 last; + } + + # Traitement des fichiers PHP + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # Assurez-vous de vérifier et d'utiliser la version correcte de PHP + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + } +} +``` + +sans oublier de créer un lien symbolique pour rendre le site disponible : +``` +sudo ln -s /etc/nginx/sites-enabled/cesium_website /etc/nginx/sites-available/cesium_website +``` + +…et de redémarrer nginx : +``` +sudo service nginx restart +``` + +## Apache + +Sous Linux, il vous faudra installer le paquet `apache2`. + +Par exemple, sous une Debian-like (Ubuntu, Linux Mint, etc.) : + +``` +sudo apt install apache2 +``` + +### configurer le fichier `.htaccess` Le fichier `.htaccess` est celui qui gère la réécriture d'URL, qui permet d'afficher au visiteur une structure compréhensible par un être humain dans sa barre d'adresse. @@ -74,19 +255,3 @@ Redémarrez Apache : ``` systemctl restart apache2 ``` - -## config.php - -Modifiez la variable $rootURL de la même façon. - -## Configurer le multilangue - -``` -# En root, sur Debian -echo -e "ca_ES.UTF-8 UTF-8\nde_DE.UTF-8 UTF-8\nen_GB.UTF-8 UTF-8\neo UTF-8\nes_ES.UTF-8 UTF-8\nit_IT.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8" >> /etc/locale.gen -locale-gen -update-locale -service php*-fpm restart -``` - - From 8b5f0cb616eda6c3c324de36a585e84514eca86e Mon Sep 17 00:00:00 2001 From: Boris Paing Date: Fri, 20 Oct 2023 11:15:17 +0200 Subject: [PATCH 06/23] [doc] minor changes --- doc/en/install.md | 1 + doc/fr/installation.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/en/install.md b/doc/en/install.md index e6cca0e..f533a34 100644 --- a/doc/en/install.md +++ b/doc/en/install.md @@ -54,6 +54,7 @@ Go to `/etc/nginx/sites-available/`. Edit the `default` file to add the bloc that follows `# Configuration for /cesium_website`. +The `/var/www/localhost` part is assuming this is where is stored `cesium_website` (`localhost` would probably be a symbolic link). ```txt server { diff --git a/doc/fr/installation.md b/doc/fr/installation.md index 671d27d..b05d337 100644 --- a/doc/fr/installation.md +++ b/doc/fr/installation.md @@ -112,7 +112,7 @@ Redémarrez nginx : sudo service nginx restart ``` -#### option 1 : créer un fichier de configuration dédié +#### option 2 : créer un fichier de configuration dédié Vous pouvez aussi créer un nouveau fichier de configuration, et un nouveau nom de serveur local. @@ -138,7 +138,7 @@ sudo nano /etc/nginx/sites-available/cesium_website ``` et ajoutez-y le contenu idoine : -``` +```txt server { listen 80; From 4965c2ee2a64c12ba1bc0fb29233946219193c77 Mon Sep 17 00:00:00 2001 From: Boris Paing Date: Fri, 20 Oct 2023 11:19:46 +0200 Subject: [PATCH 07/23] [fix] more quickfix for support page --- tpl/funding-orig.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tpl/funding-orig.php b/tpl/funding-orig.php index b939609..6362cb4 100644 --- a/tpl/funding-orig.php +++ b/tpl/funding-orig.php @@ -4,9 +4,9 @@ $pageDescription = _(""); include('cesiumDownloads.php'); -require_once('vendor/crowdfunding2/Crowdfunding.class.php'); -require_once('vendor/crowdfunding2/Chart.class.php'); -require_once('vendor/crowdfunding2/Graph.class.php'); +// require_once('vendor/crowdfunding2/Crowdfunding.class.php'); +// require_once('vendor/crowdfunding2/Chart.class.php'); +// require_once('vendor/crowdfunding2/Graph.class.php'); include('head.php'); @@ -286,7 +286,7 @@ $('.progress-bar').animate({ - width: 'getPercentage(); ?>%' + width: 'getPercentage(); ?>%' }, 1300, ''); }); From 4feb73c4a43e431798255bd0cb82be3ed695808c Mon Sep 17 00:00:00 2001 From: Boris Paing Date: Fri, 20 Oct 2023 15:26:18 +0200 Subject: [PATCH 08/23] [fix] added some exceptions handling for crowdfunding --- vendor/crowdfunding2/.gitignore | 1 + vendor/crowdfunding2/Chart.class.php | 109 +++++------ vendor/crowdfunding2/Crowdfunding.class.php | 190 ++++++++++++-------- 3 files changed, 170 insertions(+), 130 deletions(-) diff --git a/vendor/crowdfunding2/.gitignore b/vendor/crowdfunding2/.gitignore index 6a1e286..4a4a4be 100644 --- a/vendor/crowdfunding2/.gitignore +++ b/vendor/crowdfunding2/.gitignore @@ -1,3 +1,4 @@ /img/qrcodes/ /tests/ /cache/ +/cache-cache/ diff --git a/vendor/crowdfunding2/Chart.class.php b/vendor/crowdfunding2/Chart.class.php index df41454..2b263f3 100644 --- a/vendor/crowdfunding2/Chart.class.php +++ b/vendor/crowdfunding2/Chart.class.php @@ -21,17 +21,16 @@ public function __construct ($crowdfunding) { private function addLastPointOfCumulativeGraph ($lastAmount) { - $lastDay = NULL; - - if ($this->crowdfunding->isOver()) { - - $lastDay = $this->crowdfunding->getEndDate(); - - } elseif ($this->crowdfunding->hasStartedYet()) { - - $lastDay = $this->crowdfunding->today; - } - + $lastDay = + $this->crowdfunding->isOver() ? + $this->crowdfunding->getEndDate() + :( + $this->crowdfunding->hasStartedYet() ? + $this->crowdfunding->today + : + NULL + ) + ; if (isset($lastDay)) { @@ -54,50 +53,31 @@ private function addLastPointOfCumulativeGraph ($lastAmount) { private function addSecondPointOfTarget ($target) { - $d = NULL; - - if ($this->crowdfunding->isOver()) { - - $d = $this->crowdfunding->getEndDate(); - - } else { - - if (!$this->crowdfunding->isEvergreen()) { - - $d = $this->crowdfunding->getEndDate(); - - } else { - - if ($this->crowdfunding->isEvergreen() == 'monthly') { - - // last point will be the last day of the month the campaign starts - $dateOfLastDayOfTheMonth = new DateTime($this->crowdfunding->getStartDate()->format("Y-m-t")); - - $d = $dateOfLastDayOfTheMonth; - - } else { //if ($this->crowdfunding->isEvergreen() == 'forever') { - - if ($this->crowdfunding->hasStartedYet()) { - - $d = $this->crowdfunding->now; - - } else { - - - $dateOfLastDayOfTheMonth = new DateTime($this->getStartDate()->format("Y-m-t")); - - $d = $dateOfLastDayOfTheMonth; - - } - } - - } - } - - $d->add(new DateInterval('P1D')); + $date = + $this->crowdfunding->isOver() ? + $this->crowdfunding->getEndDate() + :( + !$this->crowdfunding->isEvergreen() ? + $this->crowdfunding->getEndDate() + :( + $this->crowdfunding->isEvergreen() == 'monthly' ? + // last point will be the last day of the month the campaign starts + new DateTime($this->crowdfunding->getStartDate()->format("Y-m-t")) + :( + $this->crowdfunding->hasStartedYet() ? + $this->crowdfunding->now + : + // date of the last day of the month + new DateTime($this->getStartDate()->format("Y-m-t")) + ) + ) + ) + ; + + $date->add(new DateInterval('P1D')); $this->points['targetLine'][] = [ - 't' => $d->getTimestamp() * 1000, + 't' => $date->getTimestamp() * 1000, 'y' => $target ]; } @@ -149,8 +129,15 @@ private function setPoints () { 'y' => 0 ]; */ - - $tx = $this->crowdfunding->getDonationsList(); + + try { + + $tx = $this->crowdfunding->getDonationsList(); + + } catch (Exception $e) { + + $tx = NULL; + } if (empty($tx)) { @@ -160,7 +147,7 @@ private function setPoints () { 't' => $mt_0, 'y' => 0 ]; - + } else { $currentDay = new DateTime(); @@ -214,7 +201,6 @@ public function getAmountCollectedByDayPoints () { if (empty($this->points)) { $this->setPoints(); - } return json_encode($this->points['amountCollectedByDay']); @@ -227,10 +213,14 @@ public function getAmountCollectedByDayCumulativePoints () { if (empty($this->points)) { $this->setPoints(); - } - $points = isset($this->points['amountCollectedByDayCumulative']) ? $this->points['amountCollectedByDayCumulative'] : []; + $points = + isset($this->points['amountCollectedByDayCumulative']) ? + $this->points['amountCollectedByDayCumulative'] + : + [] + ; return json_encode($points); } @@ -241,7 +231,6 @@ public function getTargetLinePoints () { if (empty($this->points)) { $this->setPoints(); - } return json_encode($this->points['targetLine']); diff --git a/vendor/crowdfunding2/Crowdfunding.class.php b/vendor/crowdfunding2/Crowdfunding.class.php index 680d6a5..d2d7e9f 100755 --- a/vendor/crowdfunding2/Crowdfunding.class.php +++ b/vendor/crowdfunding2/Crowdfunding.class.php @@ -74,6 +74,15 @@ class Crowdfunding { private $nodes = [ // Fast ones + 'duniter971.dns1.us', + 'duniter.g1.pfouque.xyz', + 'duniter.pini.fr', + 'g1.asycn.io', + 'g1.brussels.ovh', + 'g1.cgeek.fr', + 'g1.computhings.be' + + /* 'duniter.g1.1000i100.fr', 'duniter-g1.p2p.legal', 'duniter.normandie-libre.fr', @@ -82,6 +91,7 @@ class Crowdfunding { 'duniter.vincentux.fr', 'g1.le-sou.org', 'g1.donnadieu.fr', + */ /* // Node that timeout @@ -1067,67 +1077,81 @@ public function getMonthlyAmountCollectedMean ($monthsToConsider) { return $this->monthlyAmountCollectedMean; } - private function getTransactions ($pubkey, $startDate, $endDate = NULL) { + private function cacheIt ($json, $cacheFileFullPath) { - if ($startDate > $this->now) { + if (!$this->isActivatedCache) { - return array(); + return false; + } - } else { + // Cache tx - if (!isset($endDate)) { + $cacheDir = substr($cacheFileFullPath, 0, strrpos($cacheFileFullPath, '/')); - $endDate = $this->today; - } + if (!file_exists($cacheDir)) { - $json = NULL; - $jsonUri = '/tx/history/' . $pubkey . "/times/" . $startDate->getTimestamp() . "/" . $endDate->getTimestamp(); - $txCacheDir = $this->cacheDir . 'tx/'; + mkdir($cacheDir, 0777, true); - if ($this->isOver()) { + } - $txFullPath = $txCacheDir . $pubkey . '_' . $startDate->format('Y-m-d') . '_' . $endDate->format('Y-m-d') . '.json'; + file_put_contents($cacheFileFullPath, $json); + } - } else { + private function getFromCache ($cacheFullPath) { - $txFullPath = $txCacheDir . $pubkey . '_' . $startDate->format('Y-m-d') . '.json'; + $json = NULL; - } + if (!$this->isActivatedCache) { - if ($this->isActivatedCache) { + return $json; + } - if (file_exists($txFullPath) and ((time() - filemtime($txFullPath)) < $this->cacheLongevity)) { + if (file_exists($cacheFullPath) and ((time() - filemtime($cacheFullPath)) < $this->cacheLongevity)) { - $json = file_get_contents($txFullPath); - } + $json = file_get_contents($cacheFullPath); + } + return $json; + } - if (empty($json)) { + private function getTransactions ($pubkey, $startDate, $endDate = NULL) { - $json = $this->fetchJson($jsonUri); + if ($startDate > $this->now) { - // Cache tx + return array(); - if ($this->isActivatedCache) { + } - if (!file_exists($txCacheDir)) { + if (!isset($endDate)) { - mkdir($txCacheDir, 0777, true); + $endDate = $this->today; + } - } + $txFullPath = + $this->isOver() ? + $this->cacheDir . 'tx/' . $pubkey . '_' . $startDate->format('Y-m-d') . '_' . $endDate->format('Y-m-d') . '.json' + : + $this->cacheDir . 'tx/' . $pubkey . '_' . $startDate->format('Y-m-d') . '.json' + ; - file_put_contents($txFullPath, $json); - } + $json = $this->getFromCache($txFullPath); - } + if (empty($json)) { - } else { + $jsonUri = '/tx/history/' . $pubkey . "/times/" . $startDate->getTimestamp() . "/" . $endDate->getTimestamp(); + $json = $this->fetchJson($jsonUri); + } - $json = $this->fetchJson($jsonUri); - } + $transactions = json_decode($json); + + if (empty($transactions)) { - $transactions = json_decode($json); + throw new Exception(_("Nous n'avons pas pu récupérer la liste des transactions.")); + return array(); + + } else { + $this->cacheIt($json, $txFullPath); return $transactions->history->received; } } @@ -1142,7 +1166,14 @@ public function getDonationsList () { if (empty($this->donationsList)) { - $this->fetchDonationsList(); + try { + + $this->fetchDonationsList(); + + } catch (Exception $e) { + + throw $e; + } } @@ -1152,9 +1183,16 @@ public function getDonationsList () { public function getDonors () { - if (empty($this->donorsList)) { + try { - $this->fetchDonationsList(); + if (empty($this->donorsList)) { + + $this->fetchDonationsList(); + } + + } catch (Exception $e) { + + throw $e; } return $this->donorsList; @@ -1289,48 +1327,59 @@ private function fetchDonationsList () { $this->amountCollected = 0; $this->donorsNb = 0; - $tx = $this->getTransactions($this->pubkey, - $this->startDate, - $this->endDate - ); + try { + + $tx = + $this->getTransactions( + $this->pubkey, + $this->startDate, + $this->endDate + ); + + } catch (Exception $e) { + + throw $e; + } foreach ($tx as $t) { - // Filter only incoming transactions - if ($t->issuers[0] != $this->pubkey) { + // Do not take outgoing transactions into account + if ($t->issuers[0] == $this->pubkey) { - $donorPubkey = $t->issuers[0]; + continue; + } - foreach ($t->outputs as $o) { + $donorPubkey = $t->issuers[0]; - if (strstr($o, $this->pubkey)) { + foreach ($t->outputs as $o) { - $o = explode(':', $o); + if (strstr($o, $this->pubkey)) { - $transactionAmount = $o[0] / 100; + $o = explode(':', $o); - $this->donationsList[] = new Donation( + $transactionAmount = $o[0] / 100; - $transactionAmount, - $donorPubkey, - intval($t->time), - $t->comment - ); + $this->donationsList[] = new Donation( - $this->amountCollected += $transactionAmount; + $transactionAmount, + $donorPubkey, + intval($t->time), + $t->comment + ); - if (!in_array($donorPubkey, $this->donorsList)) { + $this->amountCollected += $transactionAmount; - ++$this->donorsNb; + if (!in_array($donorPubkey, $this->donorsList)) { - $this->donorsList[] = $donorPubkey; + ++$this->donorsNb; - $this->totalDonationPerDonor[$donorPubkey] = $transactionAmount; + $this->donorsList[] = $donorPubkey; - } else { + $this->totalDonationPerDonor[$donorPubkey] = $transactionAmount; - $this->totalDonationPerDonor[$donorPubkey] += $transactionAmount; - } + } else { + + $this->totalDonationPerDonor[$donorPubkey] += $transactionAmount; } } } @@ -1361,11 +1410,11 @@ public function addNode ($node) { $node = htmlspecialchars($node); $this->nodes = array_unique( - array_merge( - (array)$node, - $this->nodes - ) - ); + array_merge( + (array)$node, + $this->nodes + ) + ); } @@ -1477,10 +1526,11 @@ protected function fetchJson_aux ($nodes, $uri, $cesiumPlus, $queryParams, $node do { - - $json = @file_get_contents("https://" . current($nodes) . $uri, - false, - $streamContext); + $json = @file_get_contents( + "https://" . current($nodes) . $uri, + false, + $streamContext + ); if (empty($json)) { From 839da1e41b2d5e9fcddad00a7974fd0668883248 Mon Sep 17 00:00:00 2001 From: Boris Paing Date: Fri, 20 Oct 2023 16:01:03 +0200 Subject: [PATCH 09/23] [fix] avatars now fetched asynchronously (via cesium plus node + lazy load) --- config.php | 1 + tpl/funding-orig.php | 179 +++++++++++--------- vendor/crowdfunding2/Crowdfunding.class.php | 15 +- vendor/crowdfunding2/Donor.class.php | 14 ++ 4 files changed, 126 insertions(+), 83 deletions(-) diff --git a/config.php b/config.php index 5dc07ba..1e6e66c 100644 --- a/config.php +++ b/config.php @@ -6,6 +6,7 @@ // Duniter : 78ZwwgpgdH5uLZLbThUQH7LKwPgjMunYfLiCfUCySkM8 // Cesium : CitdnuQgZ45tNFCagay7Wh12gwwHM8VLej1sWmfHWnQX define('FUNDING_TARGET', 20*60+230); +define('CESIUM_PLUS_NODE', 'https://g1.data.e-is.pro'); // for avatars serving $legalNotice = [ diff --git a/tpl/funding-orig.php b/tpl/funding-orig.php index 6362cb4..68f1a91 100644 --- a/tpl/funding-orig.php +++ b/tpl/funding-orig.php @@ -4,9 +4,9 @@ $pageDescription = _(""); include('cesiumDownloads.php'); -// require_once('vendor/crowdfunding2/Crowdfunding.class.php'); -// require_once('vendor/crowdfunding2/Chart.class.php'); -// require_once('vendor/crowdfunding2/Graph.class.php'); +require_once('vendor/crowdfunding2/Crowdfunding.class.php'); +require_once('vendor/crowdfunding2/Chart.class.php'); +require_once('vendor/crowdfunding2/Graph.class.php'); include('head.php'); @@ -26,13 +26,36 @@ } ?> -

- -

Les développeurs remercient chaleureusement toutes les personnes qui, le mois dernier, ont financé en Ğ1 le projet Duniter :

- +

+ +

+ Si vous souhaitez soutenir le projet Duniter, c'est simple : +

+ +
+

+ Copiez la clef suivante dans votre presse-papier : + + +

+ +

+ +

+ +
+

Et maintenant collez-la dans l'annuaire Cesium afin de faire votre don 😉

+

Merci pour votre générosité ❤️

+
+
+ + +

+ sub(new DateInterval('P1M')); @@ -41,87 +64,90 @@ $lastMonthCF = new Crowdfunding(FUNDING_PUBKEY, 'relative', $lastMonthStart->format('Y-m-d'), $lastMonthEnd->format('Y-m-d')); - $donors = $lastMonthCF->getDonors(); + try { - if (empty($donors)) { + $donors = $lastMonthCF->getDonors(); - echo _('Pas encore de donateurs'); + if (empty($donors)) { - } else { - - echo ''; + } + + } catch (Exception $e) { + + echo ' +

+ ' . _("Nous n'avons pas réussi à récupérer la liste des donateurs.") . ' +

+

+ + '. _('Voir les dons dans Cesium') .' + +

'; + } + ?> - - @@ -236,21 +262,19 @@

- Ce mois-ci, nous aimerions donc atteindre la somme de DUĞ1. + Ce mois-ci, nous aimerions donc atteindre la somme de DUĞ1. Voilà où nous en sommes par rapport à cet objectif :

- + --> - --> setTarget(FUNDING_TARGET); $chart = new Chart($currentCF); @@ -275,12 +299,11 @@ echo $chart->getScripts(LANG, '#chart', $rootURL . '/vendor/crowdfunding2/'); -*/ ?> - - + + - - -