From 77fa1767556a116b3f00e161c88684962a7de981 Mon Sep 17 00:00:00 2001 From: bonobo Date: Wed, 24 May 2023 10:46:34 +0200 Subject: [PATCH] Subir archivos a 'lib' --- lib/exportrss.php | 111 ++++++++++++++++++++++++++++++++++++++++++++++ lib/logger.php | 53 ++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 lib/exportrss.php create mode 100644 lib/logger.php diff --git a/lib/exportrss.php b/lib/exportrss.php new file mode 100644 index 0000000..1bce766 --- /dev/null +++ b/lib/exportrss.php @@ -0,0 +1,111 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +class ExportRSS +{ + protected $data = array(); + protected $channel = array(); + protected $rawdata = array(); + + public function __construct($data, $version) + { + $feed = @file_get_contents($data); + $this->rawdata = simplexml_load_string($feed); + + // Parse the XML/RSS file + switch ($version) + { + case "1.0": + { + $this->channel = array( + "title" => $this->rawdata->channel->title, + "link" => $this->rawdata->channel->link, + "description" => $this->rawdata->channel->description, + "image" => $this->rawdata->channel->image, + "items" => $this->rawdata->channel->items, + "textinput" => $this->rowdata->channel->textinput + ); + + foreach ($this->rawdata->item as $item) + { + $row = array( + "title" => $item->title, + "link" => $item->link, + "description" => $item->description + ); + array_push($this->data, $row); + } + break; + } + case "2.0": + { + $this->channel = array( + "title" => $this->rawdata->channel->title, + "link" => $this->rawdata->channel->link, + "description" => $this->rawdata->channel->description, + "language" => $this->rawdata->channel->language, + "date" => $this->rawdata->channel->pubDate, + "builddate" => $this->rawdata->channel->lastBuildDate, + "docs" => $this->rawdata->channel->docs, + "generator" => $this->rawdata->channel->generator, + "editor" => $this->rawdata->channel->managingEditor, + "webmaster" => $this->rawdata->channel->webMaster, + ); + + foreach ($this->rawdata->channel->item as $item) + { + $row = array( + "title" => $item->title, + "link" => $item->link, + "description" => $item->description, +// "enclosure" => $this->enclosure, + "date" => $item->pubDate, + "guid" => $item->guid + ); + array_push($this->data, $row); + } + break; + } + default: + { + echo "ExportRSS::WARNING: invalid version was specified"; + break; + } + } + } + + public function get_raw_data() + { + return $this->rawdata; + } + + public function get_channel_data() + { + return $this->channel; + } + + public function get_data() + { + return $this->data; + } +} +?> diff --git a/lib/logger.php b/lib/logger.php new file mode 100644 index 0000000..565239a --- /dev/null +++ b/lib/logger.php @@ -0,0 +1,53 @@ +log_file = $path; + } + // write message to the log file + public function lwrite($message) { + // if file pointer doesn't exist, then open log file + if (!is_resource($this->fp)) { + $this->lopen(); + } + // define script name + $script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME); + // define current time and suppress E_WARNING if using the system TZ settings + // (don't forget to set the INI setting date.timezone) + $time = @date('[d/M/Y:H:i:s]'); + // write current time, script name and message to the log file + fwrite($this->fp, "$time ($script_name) $message" . PHP_EOL); + } + // close log file (it's always a good idea to close a file when you're done with it) + public function lclose() { + fclose($this->fp); + } + // open log file (private method) + private function lopen() { + // in case of Windows set default log file + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $log_file_default = 'c:/php/logfile.txt'; + } + // set default log file for Linux and other systems + else { + $log_file_default = '/tmp/logfile.txt'; + } + // define log file from lfile method or use previously set default + $lfile = $this->log_file ? $this->log_file : $log_file_default; + // open log file for writing only and place file pointer at the end of the file + // (if the file does not exist, try to create it) + $this->fp = fopen($lfile, 'a') or exit("Can't open $lfile!"); + } +} +?>