64 public function loadBox($max = 5, $cachedelay = 3600)
66 global $user, $langs, $conf;
67 $langs->load(
"boxes");
73 preg_match(
'/^([0-9]+) /', $this->paramdef, $reg);
80 $keyforparamurl =
"EXTERNAL_RSS_URLRSS_".$site;
81 $keyforparamtitle =
"EXTERNAL_RSS_TITLE_".$site;
87 $result = $rssparser->parser($url, $this->max, $cachedelay, $conf->externalrss->dir_temp);
90 $description = $rssparser->getDescription();
91 $link = $rssparser->getLink();
93 $title = $langs->trans(
"BoxTitleLastRssInfos", $max,
getDolGlobalString($keyforparamtitle));
94 if ($result < 0 || !empty($rssparser->error)) {
96 $errormessage = $langs->trans(
"FailedToRefreshDataInfoNotUpToDate", ($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")));
97 if ($rssparser->error) {
98 $errormessage .=
" - ".$rssparser->error;
100 $title .=
" ".img_error($errormessage);
101 $this->info_box_head = array(
'text' => $title,
'limit' => 0);
103 $this->info_box_head = array(
106 'subtext' => $langs->trans(
"LastRefreshDate").
': '.($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")),
107 'subpicto' =>
'globe',
108 'target' =>
'_blank',
113 $items = $rssparser->getItems();
117 $nbitems = count($items);
118 for ($line = 0; $line < $max && $line < $nbitems; $line++) {
119 $item = $items[$line];
122 $href = $item[
'link'];
123 $title = urldecode($item[
'title']);
124 $date = empty($item[
'date_timestamp']) ? null : $item[
'date_timestamp'];
125 if ($rssparser->getFormat() ==
'rss') {
126 if (!$date && isset($item[
'pubdate'])) {
127 $date = $item[
'pubdate'];
129 if (!$date && isset($item[
'pubDate'])) {
130 $date = $item[
'pubDate'];
132 if (!$date && isset($item[
'dc'][
'date'])) {
133 $date = $item[
'dc'][
'date'];
138 if ($rssparser->getFormat() ==
'atom') {
139 if (!$date && isset($item[
'issued'])) {
140 $date = $item[
'issued'];
142 if (!$date && isset($item[
'modified'])) {
143 $date = $item[
'modified'];
149 if (!is_numeric($date)) {
150 $timestamp = strtotime($date);
151 if ($timestamp > 0) {
155 if (is_numeric($date)) {
160 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
161 $title = mb_convert_encoding($title,
'UTF-8',
'ISO-8859-1');
162 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
163 $title = mb_convert_encoding($title,
'ISO-8859-1');
166 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
167 $title = preg_replace(
"/^\s+/",
"", $title);
170 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
172 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
173 $description = mb_convert_encoding($description,
'UTF-8',
'ISO-8859-1');
174 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
175 $description = mb_convert_encoding($description,
'ISO-8859-1');
177 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
178 $description = preg_replace(
"/^\s+/",
"", $description);
179 $description = str_replace(
"\r\n",
"", $description);
180 $tooltip .=
'<br>'.$description;
182 $this->info_box_contents[$line][0] = array(
183 'td' =>
'class="left" width="16"',
187 'target' =>
'newrss',
190 $this->info_box_contents[$line][1] = array(
191 'td' =>
'class="tdoverflowmax300"',
196 'target' =>
'newrss',
199 $this->info_box_contents[$line][2] = array(
200 'td' =>
'class="right nowraponall"',