From 08df83788edd1ca156f874a44ffd0f84e8086ea2 Mon Sep 17 00:00:00 2001 From: Kcchouette Date: Sat, 17 Aug 2019 00:24:17 +0200 Subject: [PATCH] Fix #8, #11: use simplexml_load_string instead of smple_xml_load_file --- README.md | 11 ++++++++++- TODO.md | 3 +-- admin_action.php | 2 +- class/Bot.php | 2 +- config.php | 4 ++-- index.php | 2 +- syndication.php | 2 +- update.php | 2 +- xdcc.php | 14 ++++++-------- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 22d1e78..932d9d9 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,17 @@ This project uses: 2. Change others values you want from `config.php` 3. Connect to the admin page: `admin.php` 4. Add your bot (the `name` of your bot must be UNIQUE!) - 5. Finish :) + 5. Indicate the location of the XML-generated file (it can be an URL, or a file path - eg `/home/user/bot.xml` or `../bot.xml`) + 6. Finish :) +## Problems? + +Try to see if: + + 1. There is no error in the PHP folder (per default `/var/log/php_errors.log`) + 2. When you save your bot, the file `json/data.json` is modified with the values you've set + +Thanks in advance! ## Thanks diff --git a/TODO.md b/TODO.md index a0d9e5d..1493a86 100644 --- a/TODO.md +++ b/TODO.md @@ -2,8 +2,7 @@ ## For v0.3 - - [ ] Download the XML file (from URL)? into cache (use the `lastupdate` tag; an epoch time) - - [ ] Upload the XML file into cache (serialize it? download it?) + - [ ] Save the XML content into cache (use the `lastupdate` tag; an epoch time) - [ ] Possibility of reordering bots/bookmarks in the ADMIN page - [ ] Cache can be refreshed (automatic check?) diff --git a/admin_action.php b/admin_action.php index 5c165ba..585a118 100644 --- a/admin_action.php +++ b/admin_action.php @@ -53,7 +53,7 @@
- getXmlFile()}\" required > + getXmlContent()}\" required >
diff --git a/class/Bot.php b/class/Bot.php index f83ab7a..0f68818 100644 --- a/class/Bot.php +++ b/class/Bot.php @@ -19,7 +19,7 @@ public function getName() { return $this->name; } - public function getXmlFile() { + public function getXmlContent() { return $this->xml; } diff --git a/config.php b/config.php index 31211c2..4d054f7 100644 --- a/config.php +++ b/config.php @@ -124,7 +124,7 @@ "Home_but" => "Home", "website" => "website", "IRC" => "IRC", - "Fail_load_XML" => "Failed to load XML file, or the XML file is empty", + "Fail_load_XML" => "Failed to load XML content, or the XML content is empty", "Export_csv" => "Export the number of download per file", "Transfered_daily" => "Transfered Daily", "Transfered_weekly" => "Transfered Weekly", @@ -190,7 +190,7 @@ "Home_but" => "Accueil", "website" => "site internet", "IRC" => "IRC", - "Fail_load_XML" => "Échec du chargement du fichier XML ou le fichier XML est vide", + "Fail_load_XML" => "Échec du chargement du contenu XML ou le contenu XML est vide", "Export_csv" => "Exporter le nombre de téléchargement par fichier", "Transfered_daily" => "Transferé par jour", "Transfered_weekly" => "Transféré par semaine", diff --git a/index.php b/index.php index 958d13a..3272b97 100644 --- a/index.php +++ b/index.php @@ -145,7 +145,7 @@ echo ''; - $xml = haveXMLfile(searchBotXMLFile(getBotList(), urldecode($_GET['bot']))); + $xml = haveXMLContent(searchBotXMLContent(getBotList(), urldecode($_GET['bot']))); if (!$xml || !$xml->packlist->pack) echo ""; diff --git a/syndication.php b/syndication.php index 5da3d59..7a9e789 100644 --- a/syndication.php +++ b/syndication.php @@ -21,7 +21,7 @@ echo ""; if (isset($_GET['bot'])) { - $xml = haveXMLfile(searchBotXMLFile(getBotList(), $_GET['bot'])); + $xml = haveXMLContent(searchBotXMLContent(getBotList(), $_GET['bot'])); if ($xml && $xml->packlist->pack) { echo "" . date('c', (int)$xml->sysinfo->stats->lastupdate) . ""; diff --git a/update.php b/update.php index ef957b2..afe435f 100644 --- a/update.php +++ b/update.php @@ -85,7 +85,7 @@ } // OTHER else if (isset($_POST['export_ddl'])) { - $xml = haveXMLfile(searchBotXMLFile(getBotList(), htmlspecialchars($_POST['export_ddl'], ENT_COMPAT))); + $xml = haveXMLContent(searchBotXMLContent(getBotList(), htmlspecialchars($_POST['export_ddl'], ENT_COMPAT))); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="' . htmlspecialchars($_POST['export_ddl'], ENT_COMPAT) . '.csv"'); diff --git a/xdcc.php b/xdcc.php index 9cd8f17..dd40420 100644 --- a/xdcc.php +++ b/xdcc.php @@ -7,11 +7,9 @@ require_once 'class/Bot.php'; -function haveXMLfile($xmlFile) { - if (file_exists($xmlFile)) - return simplexml_load_file($xmlFile); - else - return false; +function haveXMLContent($xmlFile) { + $filecontent = file_get_contents($xmlFile); + return simplexml_load_string($filecontent); } // return bookmark or bot object @@ -127,10 +125,10 @@ function removeBot($bname) { saveBotList($bots); } -function searchBotXMLFile($b, $n) { +function searchBotXMLContent($b, $n) { for($i = 0; $i < count($b); $i++) { if($b[$i]->getName() == $n) { - return $b[$i]->getXmlFile(); + return $b[$i]->getXmlContent(); } } } @@ -164,7 +162,7 @@ function searchBotsList($search) { $dom .= ""; $dom .= ""; foreach($bots as $bot) { - $xml = haveXMLfile(searchBotXMLFile(getBotList(), $bot->getName())); + $xml = haveXMLContent(searchBotXMLContent(getBotList(), $bot->getName())); if (!$xml || !$xml->packlist->pack) ; else
{$lang[$language]['Fail_load_XML']}
{$lang[$language]['File']}