63 public function loadBox($max = 5, $cachedelay = 3600)
65 global $user, $langs, $conf;
66 $langs->load(
"boxes");
72 preg_match(
'/^([0-9]+) /', $this->paramdef, $reg);
79 $keyforparamurl =
"EXTERNAL_RSS_URLRSS_".$site;
80 $keyforparamtitle =
"EXTERNAL_RSS_TITLE_".$site;
86 $result = $rssparser->parser($url, $this->max, $cachedelay, $conf->externalrss->dir_temp);
89 $description = $rssparser->getDescription();
90 $link = $rssparser->getLink();
92 $title = $langs->trans(
"BoxTitleLastRssInfos", $max,
getDolGlobalString($keyforparamtitle));
93 if ($result < 0 || !empty($rssparser->error)) {
95 $errormessage = $langs->trans(
"FailedToRefreshDataInfoNotUpToDate", ($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")));
96 if ($rssparser->error) {
97 $errormessage .=
" - ".$rssparser->error;
99 $title .=
" ".img_error($errormessage);
100 $this->info_box_head = array(
'text' => $title,
'limit' => 0);
102 $this->info_box_head = array(
105 'subtext'=>$langs->trans(
"LastRefreshDate").
': '.($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")),
112 $items = $rssparser->getItems();
116 $nbitems = count($items);
117 for ($line = 0; $line < $max && $line < $nbitems; $line++) {
118 $item = $items[$line];
121 $href = $item[
'link'];
122 $title = urldecode($item[
'title']);
123 $date = empty($item[
'date_timestamp']) ? null : $item[
'date_timestamp'];
124 if ($rssparser->getFormat() ==
'rss') {
125 if (!$date && isset($item[
'pubdate'])) {
126 $date = $item[
'pubdate'];
128 if (!$date && isset($item[
'pubDate'])) {
129 $date = $item[
'pubDate'];
131 if (!$date && isset($item[
'dc'][
'date'])) {
132 $date = $item[
'dc'][
'date'];
137 if ($rssparser->getFormat() ==
'atom') {
138 if (!$date && isset($item[
'issued'])) {
139 $date = $item[
'issued'];
141 if (!$date && isset($item[
'modified'])) {
142 $date = $item[
'modified'];
148 if (!is_numeric($date)) {
149 $timestamp = strtotime($date);
150 if ($timestamp > 0) {
154 if (is_numeric($date)) {
159 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
160 $title = mb_convert_encoding($title,
'UTF-8',
'ISO-8859-1');
161 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
162 $title = mb_convert_encoding($title,
'ISO-8859-1');
165 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
166 $title = preg_replace(
"/^\s+/",
"", $title);
169 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
171 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
172 $description = mb_convert_encoding($description,
'UTF-8',
'ISO-8859-1');
173 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
174 $description = mb_convert_encoding($description,
'ISO-8859-1');
176 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
177 $description = preg_replace(
"/^\s+/",
"", $description);
178 $description = str_replace(
"\r\n",
"", $description);
179 $tooltip .=
'<br>'.$description;
181 $this->info_box_contents[$line][0] = array(
182 'td' =>
'class="left" width="16"',
186 'target' =>
'newrss',
189 $this->info_box_contents[$line][1] = array(
190 'td' =>
'class="tdoverflowmax300"',
195 'target' =>
'newrss',
198 $this->info_box_contents[$line][2] = array(
199 'td' =>
'class="right nowraponall"',