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'];
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[
'pubDate'])) {
136 $date = $item[
'pubDate'];
138 if (!$date && isset($item[
'dc'][
'date'])) {
139 $date = $item[
'dc'][
'date'];
144 if ($rssparser->getFormat() ==
'atom') {
145 if (!$date && isset($item[
'issued'])) {
146 $date = $item[
'issued'];
148 if (!$date && isset($item[
'modified'])) {
149 $date = $item[
'modified'];
155 if (!is_numeric($date)) {
156 $timestamp = strtotime($date);
157 if ($timestamp > 0) {
161 if (is_numeric($date)) {
166 if (!$isutf8 &&
$conf->file->character_set_client ==
'UTF-8') {
167 $title = mb_convert_encoding($title,
'UTF-8',
'ISO-8859-1');
168 } elseif ($isutf8 &&
$conf->file->character_set_client ==
'ISO-8859-1') {
169 $title = mb_convert_encoding($title,
'ISO-8859-1');
172 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
173 $title = preg_replace(
"/^\s+/",
"", $title);
176 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
178 if (!$isutf8 &&
$conf->file->character_set_client ==
'UTF-8') {
179 $description = mb_convert_encoding($description,
'UTF-8',
'ISO-8859-1');
180 } elseif ($isutf8 &&
$conf->file->character_set_client ==
'ISO-8859-1') {
181 $description = mb_convert_encoding($description,
'ISO-8859-1');
183 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
184 $description = preg_replace(
"/^\s+/",
"", $description);
185 $description = str_replace(
"\r\n",
"", $description);
186 $tooltip .=
'<br>'.$description;
189 $this->info_box_contents[$line][0] = array(
190 'td' =>
'class="left" width="16"',
193 'tooltip' => $tooltip,
194 'target' =>
'newrss',
197 $this->info_box_contents[$line][1] = array(
198 'td' =>
'class="tdoverflowmax300"',
201 'tooltip' => $tooltip,
203 'target' =>
'newrss',
206 $this->info_box_contents[$line][2] = array(
207 'td' =>
'class="right nowraponall"',