28 include_once DOL_DOCUMENT_ROOT.
'/core/class/rssparser.class.php';
29 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
37 public $boxcode =
"lastrssinfos";
38 public $boximg =
"object_rss";
39 public $boxlabel =
"BoxLastRssInfos";
40 public $depends = array(
"externalrss");
49 public $info_box_head = array();
50 public $info_box_contents = array();
62 $this->paramdef = $param;
72 public function loadBox($max = 5, $cachedelay = 3600)
74 global $user, $langs, $conf;
75 $langs->load(
"boxes");
81 preg_match(
'/^([0-9]+) /', $this->paramdef, $reg);
88 $keyforparamurl =
"EXTERNAL_RSS_URLRSS_".$site;
89 $keyforparamtitle =
"EXTERNAL_RSS_TITLE_".$site;
92 $url = $conf->global->$keyforparamurl;
95 $result = $rssparser->parser($url, $this->max, $cachedelay, $conf->externalrss->dir_temp);
98 $description = $rssparser->getDescription();
99 $link = $rssparser->getLink();
101 $title = $langs->trans(
"BoxTitleLastRssInfos", $max, $conf->global->$keyforparamtitle);
102 if ($result < 0 || !empty($rssparser->error)) {
104 $errormessage = $langs->trans(
"FailedToRefreshDataInfoNotUpToDate", ($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")));
105 if ($rssparser->error) {
106 $errormessage .=
" - ".$rssparser->error;
108 $title .=
" ".img_error($errormessage);
109 $this->info_box_head = array(
'text' => $title,
'limit' => 0);
111 $this->info_box_head = array(
114 'subtext'=>$langs->trans(
"LastRefreshDate").
': '.($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")),
121 $items = $rssparser->getItems();
123 $nbitems = count($items);
124 for ($line = 0; $line < $max && $line < $nbitems; $line++) {
125 $item = $items[$line];
128 $href = $item[
'link'];
129 $title = urldecode($item[
'title']);
130 $date = empty($item[
'date_timestamp']) ? null : $item[
'date_timestamp'];
131 if ($rssparser->getFormat() ==
'rss') {
132 if (!$date && isset($item[
'pubdate'])) {
133 $date = $item[
'pubdate'];
135 if (!$date && isset($item[
'dc'][
'date'])) {
136 $date = $item[
'dc'][
'date'];
141 if ($rssparser->getFormat() ==
'atom') {
142 if (!$date && isset($item[
'issued'])) {
143 $date = $item[
'issued'];
145 if (!$date && isset($item[
'modified'])) {
146 $date = $item[
'modified'];
152 if (is_numeric($date)) {
157 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
158 $title = utf8_encode($title);
159 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
160 $title = utf8_decode($title);
163 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
164 $title = preg_replace(
"/^\s+/",
"", $title);
165 $this->info_box_contents[
"$href"] =
"$title";
168 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
170 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
171 $description = utf8_encode($description);
172 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
173 $description = utf8_decode($description);
175 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
176 $description = preg_replace(
"/^\s+/",
"", $description);
177 $description = str_replace(
"\r\n",
"", $description);
178 $tooltip .=
'<br>'.$description;
180 $this->info_box_contents[$line][0] = array(
181 'td' =>
'class="left" width="16"',
182 'logo' => $this->boximg,
184 'tooltip' => $tooltip,
185 'target' =>
'newrss',
188 $this->info_box_contents[$line][1] = array(
192 'tooltip' => $tooltip,
194 'target' =>
'newrss',
197 $this->info_box_contents[$line][2] = array(
198 'td' =>
'class="right nowrap"',
213 public function showBox($head =
null, $contents =
null, $nooutput = 0)
215 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);