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;
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,
getDolGlobalString($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 = mb_convert_encoding($title,
'UTF-8',
'ISO-8859-1');
164 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
165 $title = mb_convert_encoding($title,
'ISO-8859-1');
168 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
169 $title = preg_replace(
"/^\s+/",
"", $title);
172 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
174 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
175 $description = mb_convert_encoding($description,
'UTF-8',
'ISO-8859-1');
176 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
177 $description = mb_convert_encoding($description,
'ISO-8859-1');
179 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
180 $description = preg_replace(
"/^\s+/",
"", $description);
181 $description = str_replace(
"\r\n",
"", $description);
182 $tooltip .=
'<br>'.$description;
184 $this->info_box_contents[$line][0] = array(
185 'td' =>
'class="left" width="16"',
189 'target' =>
'newrss',
192 $this->info_box_contents[$line][1] = array(
193 'td' =>
'class="tdoverflowmax300"',
198 'target' =>
'newrss',
201 $this->info_box_contents[$line][2] = array(
202 'td' =>
'class="right nowraponall"',