2004-10-19 22:24:10 +00:00
|
|
|
<?php
|
2005-01-31 12:21:44 +00:00
|
|
|
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2011-01-24 19:28:28 +00:00
|
|
|
* Copyright (C) 2003 Eric Seigne <erics@rycks.com>
|
2008-05-02 20:24:38 +00:00
|
|
|
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 12:43:12 +00:00
|
|
|
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
|
2025-04-16 19:09:45 +00:00
|
|
|
* Copyright (C) 2015-2025 Frédéric France <frederic.france@free.fr>
|
2025-03-09 21:42:59 +00:00
|
|
|
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
2003-07-22 16:48:53 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-07-22 16:48:53 +00:00
|
|
|
* (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
|
2019-09-23 19:55:30 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-07-22 16:48:53 +00:00
|
|
|
*/
|
|
|
|
|
|
2005-01-31 12:21:44 +00:00
|
|
|
/**
|
2011-10-24 12:11:49 +00:00
|
|
|
* \file htdocs/core/boxes/box_external_rss.php
|
2011-01-24 19:28:28 +00:00
|
|
|
* \ingroup external_rss
|
|
|
|
|
* \brief Fichier de gestion d'une box pour le module external_rss
|
|
|
|
|
*/
|
2004-10-22 22:21:26 +00:00
|
|
|
|
2012-08-23 00:04:35 +00:00
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/class/rssparser.class.php';
|
|
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
|
2005-02-27 16:45:59 +00:00
|
|
|
|
|
|
|
|
|
2012-01-26 12:49:15 +00:00
|
|
|
/**
|
|
|
|
|
* Class to manage the box to show RSS feeds
|
|
|
|
|
*/
|
2012-02-20 08:42:57 +00:00
|
|
|
class box_external_rss extends ModeleBoxes
|
|
|
|
|
{
|
2020-10-31 13:32:18 +00:00
|
|
|
public $boxcode = "lastrssinfos";
|
|
|
|
|
public $boximg = "object_rss";
|
|
|
|
|
public $boxlabel = "BoxLastRssInfos";
|
|
|
|
|
public $depends = array("externalrss");
|
2005-02-27 17:57:21 +00:00
|
|
|
|
2024-12-04 22:16:16 +00:00
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2020-10-31 13:32:18 +00:00
|
|
|
public $paramdef; // Params of box definition (not user params)
|
2011-06-17 19:14:47 +00:00
|
|
|
|
2020-10-31 13:32:18 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
* @param string $param More parameters
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($db, $param)
|
|
|
|
|
{
|
2020-04-10 08:59:32 +00:00
|
|
|
$this->db = $db;
|
|
|
|
|
$this->paramdef = $param;
|
2024-10-14 09:56:59 +00:00
|
|
|
$this->urltoaddentry = DOL_URL_ROOT.'/admin/external_rss.php';
|
2020-10-31 13:32:18 +00:00
|
|
|
}
|
2005-02-27 17:57:21 +00:00
|
|
|
|
2020-10-31 13:32:18 +00:00
|
|
|
/**
|
2011-11-23 17:28:14 +00:00
|
|
|
* Load data into info_box_contents array to show array later.
|
|
|
|
|
*
|
|
|
|
|
* @param int $max Maximum number of records to load
|
2020-10-31 13:32:18 +00:00
|
|
|
* @param int $cachedelay Delay we accept for cache file
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function loadBox($max = 5, $cachedelay = 3600)
|
|
|
|
|
{
|
|
|
|
|
global $user, $langs, $conf;
|
|
|
|
|
$langs->load("boxes");
|
2005-02-27 16:45:59 +00:00
|
|
|
|
2020-04-10 08:59:32 +00:00
|
|
|
$this->max = $max;
|
2011-06-17 19:14:47 +00:00
|
|
|
|
2006-06-18 01:34:15 +00:00
|
|
|
// On recupere numero de param de la boite
|
2021-04-07 17:38:54 +00:00
|
|
|
$reg = array();
|
2019-01-27 10:55:16 +00:00
|
|
|
preg_match('/^([0-9]+) /', $this->paramdef, $reg);
|
2020-04-10 08:59:32 +00:00
|
|
|
$site = $reg[1];
|
2005-02-27 16:45:59 +00:00
|
|
|
|
2011-08-17 13:44:13 +00:00
|
|
|
// Create dir nor required
|
|
|
|
|
// documents/externalrss is created by module activation
|
|
|
|
|
// documents/externalrss/tmp is created by rssparser
|
2011-06-17 19:14:47 +00:00
|
|
|
|
2020-04-10 08:59:32 +00:00
|
|
|
$keyforparamurl = "EXTERNAL_RSS_URLRSS_".$site;
|
|
|
|
|
$keyforparamtitle = "EXTERNAL_RSS_TITLE_".$site;
|
2017-11-10 23:28:00 +00:00
|
|
|
|
2011-08-17 13:44:13 +00:00
|
|
|
// Get RSS feed
|
2023-12-23 19:00:57 +00:00
|
|
|
$url = getDolGlobalString($keyforparamurl);
|
2011-06-17 19:14:47 +00:00
|
|
|
|
2020-10-31 13:32:18 +00:00
|
|
|
$rssparser = new RssParser($this->db);
|
2011-09-12 17:08:02 +00:00
|
|
|
$result = $rssparser->parser($url, $this->max, $cachedelay, $conf->externalrss->dir_temp);
|
2011-08-17 13:44:13 +00:00
|
|
|
|
|
|
|
|
// INFO on channel
|
2020-04-10 08:59:32 +00:00
|
|
|
$description = $rssparser->getDescription();
|
|
|
|
|
$link = $rssparser->getLink();
|
2006-08-14 22:40:29 +00:00
|
|
|
|
2023-12-23 19:00:57 +00:00
|
|
|
$title = $langs->trans("BoxTitleLastRssInfos", $max, getDolGlobalString($keyforparamtitle));
|
2021-02-23 21:03:23 +00:00
|
|
|
if ($result < 0 || !empty($rssparser->error)) {
|
2020-10-31 13:32:18 +00:00
|
|
|
// Show warning
|
|
|
|
|
$errormessage = $langs->trans("FailedToRefreshDataInfoNotUpToDate", ($rssparser->getLastFetchDate() ? dol_print_date($rssparser->getLastFetchDate(), "dayhourtext") : $langs->trans("Unknown")));
|
2021-02-23 21:03:23 +00:00
|
|
|
if ($rssparser->error) {
|
|
|
|
|
$errormessage .= " - ".$rssparser->error;
|
|
|
|
|
}
|
2020-10-31 13:32:18 +00:00
|
|
|
$title .= " ".img_error($errormessage);
|
|
|
|
|
$this->info_box_head = array('text' => $title, 'limit' => 0);
|
|
|
|
|
} else {
|
|
|
|
|
$this->info_box_head = array(
|
|
|
|
|
'text' => $title,
|
|
|
|
|
'sublink' => $link,
|
2024-08-18 16:16:08 +00:00
|
|
|
'subtext' => $langs->trans("LastRefreshDate").': '.($rssparser->getLastFetchDate() ? dol_print_date($rssparser->getLastFetchDate(), "dayhourtext") : $langs->trans("Unknown")),
|
|
|
|
|
'subpicto' => 'globe',
|
|
|
|
|
'target' => '_blank',
|
2020-10-31 13:32:18 +00:00
|
|
|
);
|
2006-06-18 01:34:15 +00:00
|
|
|
}
|
2007-08-31 22:23:42 +00:00
|
|
|
|
2011-08-17 13:44:13 +00:00
|
|
|
// INFO on items
|
2020-04-10 08:59:32 +00:00
|
|
|
$items = $rssparser->getItems();
|
2020-10-31 13:32:18 +00:00
|
|
|
//print '<pre>'.print_r($items,true).'</pre>';
|
2022-09-07 18:45:02 +00:00
|
|
|
|
|
|
|
|
// Loop on last items
|
2020-04-10 08:59:32 +00:00
|
|
|
$nbitems = count($items);
|
2021-02-23 21:03:23 +00:00
|
|
|
for ($line = 0; $line < $max && $line < $nbitems; $line++) {
|
2020-10-31 13:32:18 +00:00
|
|
|
$item = $items[$line];
|
2006-08-14 21:23:42 +00:00
|
|
|
|
2011-08-17 13:44:13 +00:00
|
|
|
// Feed common fields
|
2020-10-31 13:32:18 +00:00
|
|
|
$href = $item['link'];
|
|
|
|
|
$title = urldecode($item['title']);
|
2022-05-11 08:28:12 +00:00
|
|
|
$date = empty($item['date_timestamp']) ? null : $item['date_timestamp']; // date will be empty if conversion into timestamp failed
|
2021-02-23 21:03:23 +00:00
|
|
|
if ($rssparser->getFormat() == 'rss') { // If RSS
|
|
|
|
|
if (!$date && isset($item['pubdate'])) {
|
|
|
|
|
$date = $item['pubdate'];
|
|
|
|
|
}
|
2023-02-20 12:09:27 +00:00
|
|
|
if (!$date && isset($item['pubDate'])) {
|
|
|
|
|
$date = $item['pubDate'];
|
|
|
|
|
}
|
2021-02-23 21:03:23 +00:00
|
|
|
if (!$date && isset($item['dc']['date'])) {
|
|
|
|
|
$date = $item['dc']['date'];
|
|
|
|
|
}
|
2006-08-14 21:23:42 +00:00
|
|
|
//$item['dc']['language']
|
|
|
|
|
//$item['dc']['publisher']
|
|
|
|
|
}
|
2021-02-23 21:03:23 +00:00
|
|
|
if ($rssparser->getFormat() == 'atom') { // If Atom
|
|
|
|
|
if (!$date && isset($item['issued'])) {
|
|
|
|
|
$date = $item['issued'];
|
|
|
|
|
}
|
|
|
|
|
if (!$date && isset($item['modified'])) {
|
|
|
|
|
$date = $item['modified'];
|
|
|
|
|
}
|
2006-08-14 21:23:42 +00:00
|
|
|
//$item['issued']
|
|
|
|
|
//$item['modified']
|
|
|
|
|
//$item['atom_content']
|
|
|
|
|
}
|
2024-04-23 23:11:22 +00:00
|
|
|
if (!is_numeric($date)) {
|
|
|
|
|
$timestamp = strtotime($date);
|
|
|
|
|
if ($timestamp > 0) {
|
|
|
|
|
$date = $timestamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-23 21:03:23 +00:00
|
|
|
if (is_numeric($date)) {
|
2021-05-24 22:29:32 +00:00
|
|
|
$date = dol_print_date($date, "dayhour", 'tzuserrel');
|
2021-02-23 21:03:23 +00:00
|
|
|
}
|
2011-06-17 19:14:47 +00:00
|
|
|
|
2008-10-09 17:29:32 +00:00
|
|
|
$isutf8 = utf8_check($title);
|
2021-02-23 21:03:23 +00:00
|
|
|
if (!$isutf8 && $conf->file->character_set_client == 'UTF-8') {
|
2023-12-07 02:37:05 +00:00
|
|
|
$title = mb_convert_encoding($title, 'UTF-8', 'ISO-8859-1');
|
2021-02-23 21:03:23 +00:00
|
|
|
} elseif ($isutf8 && $conf->file->character_set_client == 'ISO-8859-1') {
|
2023-12-07 02:37:05 +00:00
|
|
|
$title = mb_convert_encoding($title, 'ISO-8859-1');
|
2021-02-23 21:03:23 +00:00
|
|
|
}
|
2020-10-31 13:32:18 +00:00
|
|
|
|
2024-01-13 18:48:20 +00:00
|
|
|
$title = preg_replace("/([[:alnum:]])\?([[:alnum:]])/", "\\1'\\2", $title); // Manage issue of quotes improperly (de)coded in utf-8
|
|
|
|
|
$title = preg_replace("/^\s+/", "", $title); // Remove leading whitespace
|
2020-10-31 13:32:18 +00:00
|
|
|
|
|
|
|
|
$tooltip = $title;
|
|
|
|
|
$description = !empty($item['description']) ? $item['description'] : '';
|
|
|
|
|
$isutf8 = utf8_check($description);
|
2021-02-23 21:03:23 +00:00
|
|
|
if (!$isutf8 && $conf->file->character_set_client == 'UTF-8') {
|
2023-12-07 02:37:05 +00:00
|
|
|
$description = mb_convert_encoding($description, 'UTF-8', 'ISO-8859-1');
|
2021-02-23 21:03:23 +00:00
|
|
|
} elseif ($isutf8 && $conf->file->character_set_client == 'ISO-8859-1') {
|
2023-12-07 02:37:05 +00:00
|
|
|
$description = mb_convert_encoding($description, 'ISO-8859-1');
|
2021-02-23 21:03:23 +00:00
|
|
|
}
|
2020-10-31 13:32:18 +00:00
|
|
|
$description = preg_replace("/([[:alnum:]])\?([[:alnum:]])/", "\\1'\\2", $description);
|
|
|
|
|
$description = preg_replace("/^\s+/", "", $description);
|
|
|
|
|
$description = str_replace("\r\n", "", $description);
|
|
|
|
|
$tooltip .= '<br>'.$description;
|
|
|
|
|
|
2025-03-09 21:42:59 +00:00
|
|
|
// Note: Escaping of value will be done by the showBox rendering method.
|
2020-10-31 13:32:18 +00:00
|
|
|
$this->info_box_contents[$line][0] = array(
|
|
|
|
|
'td' => 'class="left" width="16"',
|
2022-09-07 18:45:02 +00:00
|
|
|
'text' => img_picto('', 'rss'),
|
2020-10-31 13:32:18 +00:00
|
|
|
'url' => $href,
|
2025-03-09 21:42:59 +00:00
|
|
|
'tooltip' => $tooltip,
|
2020-10-31 13:32:18 +00:00
|
|
|
'target' => 'newrss',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->info_box_contents[$line][1] = array(
|
2022-09-07 18:45:02 +00:00
|
|
|
'td' => 'class="tdoverflowmax300"',
|
2025-03-09 21:42:59 +00:00
|
|
|
'text' => $title,
|
2020-10-31 13:32:18 +00:00
|
|
|
'url' => $href,
|
2025-03-09 21:42:59 +00:00
|
|
|
'tooltip' => $tooltip,
|
2022-09-07 18:45:02 +00:00
|
|
|
'maxlength' => 0,
|
2020-10-31 13:32:18 +00:00
|
|
|
'target' => 'newrss',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->info_box_contents[$line][2] = array(
|
2023-11-09 15:04:05 +00:00
|
|
|
'td' => 'class="right nowraponall"',
|
2025-03-09 21:42:59 +00:00
|
|
|
'text' => $date,
|
2020-10-31 13:32:18 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-02-27 16:45:59 +00:00
|
|
|
|
2011-06-17 19:14:47 +00:00
|
|
|
|
2024-09-28 10:09:35 +00:00
|
|
|
|
|
|
|
|
|
2011-11-23 17:28:14 +00:00
|
|
|
/**
|
2024-09-28 10:09:35 +00:00
|
|
|
* Method to show box. Called when the box needs to be displayed.
|
2011-11-23 17:28:14 +00:00
|
|
|
*
|
2024-09-28 10:09:35 +00:00
|
|
|
* @param ?array<array{text?:string,sublink?:string,subtext?:string,subpicto?:?string,picto?:string,nbcol?:int,limit?:int,subclass?:string,graph?:int<0,1>,target?:string}> $head Array with properties of box title
|
|
|
|
|
* @param ?array<array{tr?:string,td?:string,target?:string,text?:string,text2?:string,textnoformat?:string,tooltip?:string,logo?:string,url?:string,maxlength?:int,asis?:int<0,1>}> $contents Array with properties of box lines
|
2024-08-18 16:16:08 +00:00
|
|
|
* @param int<0,1> $nooutput No print, only return string
|
2017-06-12 12:09:00 +00:00
|
|
|
* @return string
|
2011-11-23 17:28:14 +00:00
|
|
|
*/
|
2020-10-31 13:32:18 +00:00
|
|
|
public function showBox($head = null, $contents = null, $nooutput = 0)
|
|
|
|
|
{
|
|
|
|
|
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
|
|
|
|
|
}
|
2003-07-22 16:48:53 +00:00
|
|
|
}
|