28 include_once DOL_DOCUMENT_ROOT.
'/core/class/rssparser.class.php';
29 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
37 public $boxcode =
"lastrssinfos";
38 public $boximg =
"object_rss";
39 public $boxlabel =
"BoxLastRssInfos";
40 public $depends = array(
"externalrss");
49 public $info_box_head = array();
50 public $info_box_contents = array();
62 $this->paramdef = $param;
72 public function loadBox($max = 5, $cachedelay = 3600)
74 global $user, $langs, $conf;
75 $langs->load(
"boxes");
80 preg_match(
'/^([0-9]+) /', $this->paramdef, $reg);
87 $keyforparamurl =
"EXTERNAL_RSS_URLRSS_".$site;
88 $keyforparamtitle =
"EXTERNAL_RSS_TITLE_".$site;
91 $url = $conf->global->$keyforparamurl;
94 $result = $rssparser->parser($url, $this->max, $cachedelay, $conf->externalrss->dir_temp);
97 $description = $rssparser->getDescription();
98 $link = $rssparser->getLink();
100 $title = $langs->trans(
"BoxTitleLastRssInfos", $max, $conf->global->$keyforparamtitle);
101 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) $errormessage .=
" - ".$rssparser->error;
106 $title .=
" ".img_error($errormessage);
107 $this->info_box_head = array(
'text' => $title,
'limit' => 0);
109 $this->info_box_head = array(
112 'subtext'=>$langs->trans(
"LastRefreshDate").
': '.($rssparser->getLastFetchDate() ?
dol_print_date($rssparser->getLastFetchDate(),
"dayhourtext") : $langs->trans(
"Unknown")),
119 $items = $rssparser->getItems();
121 $nbitems = count($items);
122 for ($line = 0; $line < $max && $line < $nbitems; $line++)
124 $item = $items[$line];
127 $href = $item[
'link'];
128 $title = urldecode($item[
'title']);
129 $date = $item[
'date_timestamp'];
130 if ($rssparser->getFormat() ==
'rss')
132 if (!$date && isset($item[
'pubdate'])) $date = $item[
'pubdate'];
133 if (!$date && isset($item[
'dc'][
'date'])) $date = $item[
'dc'][
'date'];
137 if ($rssparser->getFormat() ==
'atom')
139 if (!$date && isset($item[
'issued'])) $date = $item[
'issued'];
140 if (!$date && isset($item[
'modified'])) $date = $item[
'modified'];
148 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') $title = utf8_encode($title);
149 elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') $title = utf8_decode($title);
151 $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $title);
152 $title = preg_replace(
"/^\s+/",
"", $title);
153 $this->info_box_contents[
"$href"] =
"$title";
156 $description = !empty($item[
'description']) ? $item[
'description'] :
'';
158 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') $description = utf8_encode($description);
159 elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') $description = utf8_decode($description);
160 $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/",
"\\1'\\2", $description);
161 $description = preg_replace(
"/^\s+/",
"", $description);
162 $description = str_replace(
"\r\n",
"", $description);
163 $tooltip .=
'<br>'.$description;
165 $this->info_box_contents[$line][0] = array(
166 'td' =>
'class="left" width="16"',
167 'logo' => $this->boximg,
169 'tooltip' => $tooltip,
170 'target' =>
'newrss',
173 $this->info_box_contents[$line][1] = array(
177 'tooltip' => $tooltip,
179 'target' =>
'newrss',
182 $this->info_box_contents[$line][2] = array(
183 'td' =>
'class="right nowrap"',
198 public function showBox($head = null, $contents = null, $nooutput = 0)
200 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
$conf db
API class for accounts.
utf8_check($str)
Check if a string is in UTF8.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).