Skip to content

Commit

Permalink
Fix #8, #11: use simplexml_load_string instead of smple_xml_load_file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kcchouette committed Aug 16, 2019
1 parent 52c21ca commit 08df837
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 18 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?)

Expand Down
2 changes: 1 addition & 1 deletion admin_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>
<div class=\"form-group\">
<label class=\"form-label\" for=\"xmlBot\">{$lang[$language]['Bot_xml']}</label>
<input type=\"text\" class=\"form-input\" id=\"xmlBot\" name=\"xmlBot\" placeholder=\"{$lang[$language]['Bot_xml']}\" value=\"{$b->getXmlFile()}\" required >
<input type=\"text\" class=\"form-input\" id=\"xmlBot\" name=\"xmlBot\" placeholder=\"{$lang[$language]['Bot_xml']}\" value=\"{$b->getXmlContent()}\" required >
</div>
<div class=\"form-group\">
<label class=\"form-label\" for=\"websiteBot\">{$lang[$language]['Bot_website']}</label>
Expand Down
2 changes: 1 addition & 1 deletion class/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getName() {
return $this->name;
}

public function getXmlFile() {
public function getXmlContent() {
return $this->xml;
}

Expand Down
4 changes: 2 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
echo '<table class="table" id="filelist">';


$xml = haveXMLfile(searchBotXMLFile(getBotList(), urldecode($_GET['bot'])));
$xml = haveXMLContent(searchBotXMLContent(getBotList(), urldecode($_GET['bot'])));

if (!$xml || !$xml->packlist->pack)
echo "<thead><tr id=\"trmain\"><th>{$lang[$language]['Fail_load_XML']}</th></tr><thead>";
Expand Down
2 changes: 1 addition & 1 deletion syndication.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
echo "<link href=\"$url\" rel=\"self\"/>";

if (isset($_GET['bot'])) {
$xml = haveXMLfile(searchBotXMLFile(getBotList(), $_GET['bot']));
$xml = haveXMLContent(searchBotXMLContent(getBotList(), $_GET['bot']));
if ($xml && $xml->packlist->pack) {

echo "<updated>" . date('c', (int)$xml->sysinfo->stats->lastupdate) . "</updated>";
Expand Down
2 changes: 1 addition & 1 deletion update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
Expand Down
14 changes: 6 additions & 8 deletions xdcc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -164,7 +162,7 @@ function searchBotsList($search) {
$dom .= "<th>{$lang[$language]['File']}</th>";
$dom .= "</tr>";
foreach($bots as $bot) {
$xml = haveXMLfile(searchBotXMLFile(getBotList(), $bot->getName()));
$xml = haveXMLContent(searchBotXMLContent(getBotList(), $bot->getName()));
if (!$xml || !$xml->packlist->pack)
;
else
Expand Down

0 comments on commit 08df837

Please sign in to comment.