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");
 
   81     preg_match(
'/^([0-9]+) /', $this->paramdef, $reg);
 
   88     $keyforparamurl = 
"EXTERNAL_RSS_URLRSS_".$site;
 
   89     $keyforparamtitle = 
"EXTERNAL_RSS_TITLE_".$site;
 
   92     $url = $conf->global->$keyforparamurl;
 
   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, $conf->global->$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[
'dc'][
'date'])) {
 
  138           $date = $item[
'dc'][
'date'];
 
  143       if ($rssparser->getFormat() == 
'atom') {  
 
  144         if (!$date && isset($item[
'issued'])) {
 
  145           $date = $item[
'issued'];
 
  147         if (!$date && isset($item[
'modified'])) {
 
  148           $date = $item[
'modified'];
 
  154       if (is_numeric($date)) {
 
  159       if (!$isutf8 && $conf->file->character_set_client == 
'UTF-8') {
 
  160         $title = utf8_encode($title);
 
  161       } elseif ($isutf8 && $conf->file->character_set_client == 
'ISO-8859-1') {
 
  162         $title = utf8_decode($title);
 
  165       $title = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/", 
"\\1'\\2", $title); 
 
  166       $title = preg_replace(
"/^\s+/", 
"", $title); 
 
  167       $this->info_box_contents[
"$href"] = 
"$title";
 
  170       $description = !empty($item[
'description']) ? $item[
'description'] : 
'';
 
  172       if (!$isutf8 && $conf->file->character_set_client == 
'UTF-8') {
 
  173         $description = utf8_encode($description);
 
  174       } elseif ($isutf8 && $conf->file->character_set_client == 
'ISO-8859-1') {
 
  175         $description = utf8_decode($description);
 
  177       $description = preg_replace(
"/([[:alnum:]])\?([[:alnum:]])/", 
"\\1'\\2", $description);
 
  178       $description = preg_replace(
"/^\s+/", 
"", $description);
 
  179       $description = str_replace(
"\r\n", 
"", $description);
 
  180       $tooltip .= 
'<br>'.$description;
 
  182       $this->info_box_contents[$line][0] = array(
 
  183         'td' => 
'class="left" width="16"',
 
  186         'tooltip' => $tooltip,
 
  187         'target' => 
'newrss',
 
  190       $this->info_box_contents[$line][1] = array(
 
  191         'td' => 
'class="tdoverflowmax300"',
 
  194         'tooltip' => $tooltip,
 
  196         'target' => 
'newrss',
 
  199       $this->info_box_contents[$line][2] = array(
 
  200         'td' => 
'class="right nowrap"',
 
  215   public function showBox($head = 
null, $contents = 
null, $nooutput = 0)
 
  217     return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
 
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
 
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
 
utf8_check($str)
Check if a string is in UTF8.
 
$conf db
API class for accounts.