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();
125 $nbitems = count($items);
126 for ($line = 0; $line < $max && $line < $nbitems; $line++) {
127 $item = $items[$line];
130 $href = $item[
'link'];
131 $title = urldecode($item[
'title']);
132 $date = empty($item[
'date_timestamp']) ? null : $item[
'date_timestamp'];
133 if ($rssparser->getFormat() ==
'rss') {
134 if (!$date && isset($item[
'pubdate'])) {
135 $date = $item[
'pubdate'];
137 if (!$date && isset($item[
'pubDate'])) {
138 $date = $item[
'pubDate'];
140 if (!$date && isset($item[
'dc'][
'date'])) {
141 $date = $item[
'dc'][
'date'];
146 if ($rssparser->getFormat() ==
'atom') {
147 if (!$date && isset($item[
'issued'])) {
148 $date = $item[
'issued'];
150 if (!$date && isset($item[
'modified'])) {
151 $date = $item[
'modified'];
157 if (is_numeric($date)) {
162 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
163 $title = utf8_encode($title);
164 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
165 $title = utf8_decode($title);
168 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
169 $title = preg_replace(
"/^\s+/",
"", $title);
170 $this->info_box_contents[
"$href"] =
"$title";
173 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
175 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
176 $description = utf8_encode($description);
177 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
178 $description = utf8_decode($description);
180 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
181 $description = preg_replace(
"/^\s+/",
"", $description);
182 $description = str_replace(
"\r\n",
"", $description);
183 $tooltip .=
'<br>'.$description;
185 $this->info_box_contents[$line][0] = array(
186 'td' =>
'class="left" width="16"',
190 'target' =>
'newrss',
193 $this->info_box_contents[$line][1] = array(
194 'td' =>
'class="tdoverflowmax300"',
199 'target' =>
'newrss',
202 $this->info_box_contents[$line][2] = array(
203 'td' =>
'class="right nowrap"',
218 public function showBox($head =
null, $contents =
null, $nooutput = 0)
220 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);