68 public function loadBox($max = 5, $cachedelay = 3600)
70 global $user, $langs,
$conf;
71 $langs->load(
"boxes");
77 preg_match(
'/^([0-9]+) /', $this->paramdef, $reg);
84 $keyforparamurl =
"EXTERNAL_RSS_URLRSS_".$site;
85 $keyforparamtitle =
"EXTERNAL_RSS_TITLE_".$site;
91 $result = $rssparser->parser($url, $this->max, $cachedelay,
$conf->externalrss->dir_temp);
94 $description = $rssparser->getDescription();
95 $link = $rssparser->getLink();
97 $title = $langs->trans(
"BoxTitleLastRssInfos", $max,
getDolGlobalString($keyforparamtitle));
98 if ($result < 0 || !empty($rssparser->error)) {
100 $errormessage = $langs->trans(
"FailedToRefreshDataInfoNotUpToDate", ($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")));
101 if ($rssparser->error) {
102 $errormessage .=
" - ".$rssparser->error;
104 $title .=
" ".img_error($errormessage);
105 $this->info_box_head = array(
'text' => $title,
'limit' => 0);
107 $this->info_box_head = array(
110 'subtext' => $langs->trans(
"LastRefreshDate").
': '.($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")),
111 'subpicto' =>
'globe',
112 'target' =>
'_blank',
117 $items = $rssparser->getItems();
121 $nbitems = count($items);
122 for ($line = 0; $line < $max && $line < $nbitems; $line++) {
123 $item = $items[$line];
126 $href = $item[
'link'];
127 $title = urldecode($item[
'title']);
128 $date = empty($item[
'date_timestamp']) ? null : $item[
'date_timestamp'];
129 if ($rssparser->getFormat() ==
'rss') {
130 if (!$date && isset($item[
'pubdate'])) {
131 $date = $item[
'pubdate'];
133 if (!$date && isset($item[
'pubDate'])) {
134 $date = $item[
'pubDate'];
136 if (!$date && isset($item[
'dc'][
'date'])) {
137 $date = $item[
'dc'][
'date'];
142 if ($rssparser->getFormat() ==
'atom') {
143 if (!$date && isset($item[
'issued'])) {
144 $date = $item[
'issued'];
146 if (!$date && isset($item[
'modified'])) {
147 $date = $item[
'modified'];
153 if (!is_numeric($date)) {
154 $timestamp = strtotime($date);
155 if ($timestamp > 0) {
159 if (is_numeric($date)) {
164 if (!$isutf8 &&
$conf->file->character_set_client ==
'UTF-8') {
165 $title = mb_convert_encoding($title,
'UTF-8',
'ISO-8859-1');
166 } elseif ($isutf8 &&
$conf->file->character_set_client ==
'ISO-8859-1') {
167 $title = mb_convert_encoding($title,
'ISO-8859-1');
170 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
171 $title = preg_replace(
"/^\s+/",
"", $title);
174 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
176 if (!$isutf8 &&
$conf->file->character_set_client ==
'UTF-8') {
177 $description = mb_convert_encoding($description,
'UTF-8',
'ISO-8859-1');
178 } elseif ($isutf8 &&
$conf->file->character_set_client ==
'ISO-8859-1') {
179 $description = mb_convert_encoding($description,
'ISO-8859-1');
181 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
182 $description = preg_replace(
"/^\s+/",
"", $description);
183 $description = str_replace(
"\r\n",
"", $description);
184 $tooltip .=
'<br>'.$description;
186 $this->info_box_contents[$line][0] = array(
187 'td' =>
'class="left" width="16"',
191 'target' =>
'newrss',
194 $this->info_box_contents[$line][1] = array(
195 'td' =>
'class="tdoverflowmax300"',
200 'target' =>
'newrss',
203 $this->info_box_contents[$line][2] = array(
204 'td' =>
'class="right nowraponall"',