65 public function loadBox($max = 5, $cachedelay = 3600)
67 global $user, $langs,
$conf;
68 $langs->load(
"boxes");
74 preg_match(
'/^([0-9]+) /', $this->paramdef, $reg);
81 $keyforparamurl =
"EXTERNAL_RSS_URLRSS_".$site;
82 $keyforparamtitle =
"EXTERNAL_RSS_TITLE_".$site;
88 $result = $rssparser->parser($url, $this->max, $cachedelay,
$conf->externalrss->dir_temp);
91 $description = $rssparser->getDescription();
92 $link = $rssparser->getLink();
94 $title = $langs->trans(
"BoxTitleLastRssInfos", $max,
getDolGlobalString($keyforparamtitle));
95 if ($result < 0 || !empty($rssparser->error)) {
97 $errormessage = $langs->trans(
"FailedToRefreshDataInfoNotUpToDate", ($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")));
98 if ($rssparser->error) {
99 $errormessage .=
" - ".$rssparser->error;
101 $title .=
" ".img_error($errormessage);
102 $this->info_box_head = array(
'text' => $title,
'limit' => 0);
104 $this->info_box_head = array(
107 'subtext' => $langs->trans(
"LastRefreshDate").
': '.($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")),
108 'subpicto' =>
'globe',
109 'target' =>
'_blank',
114 $items = $rssparser->getItems();
118 $nbitems = count($items);
119 for ($line = 0; $line < $max && $line < $nbitems; $line++) {
120 $item = $items[$line];
123 $href = $item[
'link'];
124 $title = urldecode($item[
'title']);
125 $date = empty($item[
'date_timestamp']) ? null : $item[
'date_timestamp'];
126 if ($rssparser->getFormat() ==
'rss') {
127 if (!$date && isset($item[
'pubdate'])) {
128 $date = $item[
'pubdate'];
130 if (!$date && isset($item[
'pubDate'])) {
131 $date = $item[
'pubDate'];
133 if (!$date && isset($item[
'dc'][
'date'])) {
134 $date = $item[
'dc'][
'date'];
139 if ($rssparser->getFormat() ==
'atom') {
140 if (!$date && isset($item[
'issued'])) {
141 $date = $item[
'issued'];
143 if (!$date && isset($item[
'modified'])) {
144 $date = $item[
'modified'];
150 if (!is_numeric($date)) {
151 $timestamp = strtotime($date);
152 if ($timestamp > 0) {
156 if (is_numeric($date)) {
161 if (!$isutf8 &&
$conf->file->character_set_client ==
'UTF-8') {
162 $title = mb_convert_encoding($title,
'UTF-8',
'ISO-8859-1');
163 } elseif ($isutf8 &&
$conf->file->character_set_client ==
'ISO-8859-1') {
164 $title = mb_convert_encoding($title,
'ISO-8859-1');
167 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
168 $title = preg_replace(
"/^\s+/",
"", $title);
171 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
173 if (!$isutf8 &&
$conf->file->character_set_client ==
'UTF-8') {
174 $description = mb_convert_encoding($description,
'UTF-8',
'ISO-8859-1');
175 } elseif ($isutf8 &&
$conf->file->character_set_client ==
'ISO-8859-1') {
176 $description = mb_convert_encoding($description,
'ISO-8859-1');
178 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
179 $description = preg_replace(
"/^\s+/",
"", $description);
180 $description = str_replace(
"\r\n",
"", $description);
181 $tooltip .=
'<br>'.$description;
183 $this->info_box_contents[$line][0] = array(
184 'td' =>
'class="left" width="16"',
188 'target' =>
'newrss',
191 $this->info_box_contents[$line][1] = array(
192 'td' =>
'class="tdoverflowmax300"',
197 'target' =>
'newrss',
200 $this->info_box_contents[$line][2] = array(
201 'td' =>
'class="right nowraponall"',