cache_id = '_internalpubli_'.$usr_id.'_'.$page; $this->page = $page; $conn = connection::getInstance(); $total = 0; $update = 0; $sql = 'SELECT count(distinct s.ssel_id) as total, MAX(s.updater) as MAJ FROM ssel s, sselcont c, bas b WHERE s.ssel_id = c.ssel_id AND c.base_id = b.base_id AND s.public="1" AND (s.pub_restrict="0" ' . 'OR (s.pub_restrict="1" AND c.base_id IN ' . ' (SELECT base_id FROM basusr WHERE usr_id = "'.$conn->escape_string($usr_id).'" AND actif = "1"))) ORDER BY s.pub_date DESC, s.ssel_id DESC'; if($rs = $conn->query($sql)) { if($row = $conn->fetch_assoc($rs)) { $total = $row['total']; $update = $row['MAJ']; } $conn->free_result($rs); } $feed_cache = cache_feed::getInstance(); if(($tmp = $feed_cache->get($this->cache_id)) !== false) { $last_update = $tmp['infos']['updated']; $update_obj = new DateTime($update); if($last_update == $update_obj->format(DATE_ATOM)) { $this->infos = $tmp['infos']; $this->items = $tmp['items']; return $this; } $feed_cache->delete($this->cache_id); } $n = 10; $this->infos['next'] = ((((int)$page + 1) * $n) < $total) ? ((int)$page + 1) : false ; $this->infos['previous'] = $page > 0 ? ((int)$page - 1 ) : false; $sql = 'SELECT DISTINCT s.ssel_id FROM ssel s, sselcont c, bas b WHERE s.ssel_id = c.ssel_id AND b.base_id = c.base_id AND s.public="1" AND (s.pub_restrict="0" ' . 'OR (s.pub_restrict="1" AND c.base_id IN ' . ' (SELECT base_id FROM basusr WHERE usr_id = "'.$conn->escape_string($usr_id).'" AND actif = "1"))) ORDER BY s.pub_date DESC, s.ssel_id DESC LIMIT '.((int)$page * $n).', '.$n; $ssel_ids = array(); if($rs = $conn->query($sql)) { while($row = $conn->fetch_assoc($rs)) { $ssel_ids[] = $row['ssel_id']; } $conn->free_result($rs); } $RN = array("\r\n", "\n", "\r"); phrasea_open_session($ses_id, $usr_id); $sql = 'SELECT c.ord, s.public, s.pub_restrict,c.sselcont_id, c.base_id, b.sbas_id, c.record_id, s.ssel_id, s.name, s.descript, ' . 's.pub_date, ' . 's.updater, ' . ' u.usr_nom, u.usr_prenom, u.usr_login, u.usr_mail ' . ', bu.mask_and ' . ', bu.mask_xor ' . ' FROM (sselcont c, ssel s, usr u, bas b) ' . ' LEFT JOIN basusr bu ON (bu.base_id = b.base_id AND bu.usr_id = "'.$conn->escape_string($usr_id).'" )' . ' WHERE s.ssel_id = c.ssel_id AND s.public="1" ' . ' AND s.ssel_id IN ('.implode(', ',$ssel_ids).')' . ' AND u.usr_id = s.usr_id AND temporaryType=0 ' . ' AND b.base_id = c.base_id' . ' ORDER BY s.pub_date DESC, s.ssel_id DESC, c.ord ASC'; $sqlMe = 'SELECT usr_login, usr_password FROM usr WHERE usr_id = "'.$conn->escape_string($usr_id).'"'; $info_usr = null; if($rsMe = $conn->query($sqlMe)) { if($rawMe = $conn->fetch_assoc($rsMe)) { $info_usr = $rawMe; } $conn->free_result($rsMe); } if($rs = $conn->query($sql)) { $date_obj = new DateTime($update); $rss_infos = user::getMyRss(); $this->infos['title'] = ''; $this->infos['link_self'] = GV_ServerName.'atom/'.$rss_infos['token']; $this->infos['link_enclosure'] = GV_ServerName; $this->infos['updated'] = $date_obj->format(DATE_ATOM); $this->infos['id'] = GV_ServerName; $this->infos['icon'] = GV_ServerName.'favicon.ico'; $this->infos['generator'] = 'Phraseanet'; $this->infos['rights'] = ''; $this->infos['subtitle'] = ''; $sselid = null; while($row = $conn->fetch_assoc($rs)) { $isItem = false; if($row['ssel_id'] != $sselid) { $isItem = true; } $sselid = $row['ssel_id']; if($isItem) { $n = count($this->items); $this->items[$n] = array(); if($info_usr !== null) { $encryptedurl = random::getUrlToken('view',$usr_id,false,$row['ssel_id']); $this->items[$n]['id'] = GV_ServerName.'lightbox/index.php?LOG='.$encryptedurl; $this->items[$n]['link'] = GV_ServerName.'lightbox/index.php?LOG='.$encryptedurl; } $date_obj_pub = new DateTime($row['pub_date']); $date_obj_upd = new DateTime($row['updater']); $this->items[$n]['published'] = $date_obj_pub->format(DATE_ATOM); $this->items[$n]['updated'] = $date_obj_upd->format(DATE_ATOM); $this->items[$n]['title'] = html_entity_decode($row['name'],ENT_COMPAT,'UTF-8'); $this->items[$n]['restricted'] = $row['pub_restrict'] == 1 ? true : false; $o = 0; $usr = $row['usr_prenom'].' '.$row['usr_nom']; if(trim($usr) == '') $usr = 'Unknown User'; $this->items[$n]['name'] = $usr; $this->items[$n]['ssel_id'] = $row['ssel_id']; $this->items[$n]['email'] = $row['usr_mail']; $this->items[$n]['content'] = $row['descript']; $this->items[$n]['unread'] = false;// $row['id'] != '' ? true : false; $isItem = false; // $imgs =''; } $statOk = true; if($row['pub_restrict'] == 1) { $statOk = false; $connsbas = connection::getInstance($row['sbas_id']); if($connsbas) { $sql = 'SELECT record_id FROM record WHERE ((status ^ '.$row['mask_xor'].') & '.$row['mask_and'].')=0 AND record_id="'.$connsbas->escape_string($row['record_id']).'"'; if($rsRec = $connsbas->query($sql)) { if($connsbas->num_rows($rsRec)>0){ $statOk = true; } $connsbas->free_result($rsRec); } } } if($statOk) { $o++; $thumbnail = answer::getThumbnail($ses_id, $row["base_id"], $row["record_id"],GV_zommPrev_rollover_clientAnswer); $sbas_id = phrasea::sbasFromBas($row['base_id']); $captionXML = phrasea_xmlcaption($ses_id, $row['base_id'], $row['record_id']); $title = answer::format_title($sbas_id, $row["record_id"], $captionXML); $exifinfos = answer::format_infos($captionXML, $sbas_id, $row["record_id"],$thumbnail['type']); $caption = answer::format_caption($row['base_id'], $row["record_id"],$captionXML); $duration = ''; $docType = $thumbnail['type']; $isVideo = $docType == 'video' ? true:false; $isAudio = $docType == 'audio' ? true:false; if($isVideo){ $duration = answer::get_duration($captionXML); } if($isAudio){ $duration = answer::get_duration($captionXML); } $ratio = $thumbnail["w"]/$thumbnail["h"]; if($thumbnail["w"] > $thumbnail["h"]) { if($thumbnail["w"] > 200) { $thumbnail["w"] = 200; } $thumbnail["h"] = round($thumbnail["w"]/$ratio); } else { if($thumbnail["h"] > 200) { $thumbnail["h"] = 200; } $thumbnail["w"] = round($thumbnail["h"]*$ratio); } $this->items[$n]['document'][] = array( 'type' => $docType, 'sbas_id' => $sbas_id, 'base_id' => $row['base_id'], 'record_id' => $row['record_id'], 'src' => GV_ServerName.$thumbnail['thumbnail'], 'title' => $title, 'subdefs' => $thumbnail, 'technical_infos' => $exifinfos, 'caption' => $caption, 'height' => $thumbnail["h"], 'width' => $thumbnail["w"], 'order' => $row['ord'], 'duration' => $duration ); // ''; } } } $datas = array('infos'=>$this->infos,'items'=>$this->items); $feed_cache->set($this->cache_id,$datas); return $this; } public function get_datas() { return array('items'=>$this->items,'infos'=>$this->infos); } public function format_html() { $RN = array("\r\n", "\n", "\r"); $session = session::getInstance(); $usrRight = user::getInstance($session->usr_id); $feed = ''; if($this->page == 0) { $feed .= '
' . '

'._('publications:: dernieres publications').'

' . '

' . _('publications:: s\'abonner aux publications').' '. '

' . '
'; } foreach($this->items as $n=>$publi) { $feed .= '
'; $sselid = $publi['ssel_id']; $neverSeen = $publi['unread'] ? _('publications:: publication non lue') : ''; $date_obj_pub = new DateTime($publi['published']); $published = phraseadate::getPrettyString($date_obj_pub); $feed .= '
' . '
' . '

' . ''.$publi['title']. ' '.$neverSeen.'

' . '' . ' '.$published.' '; if(trim($publi['email']) != '') $feed .= ''; $feed .= $publi['name']; if(trim($publi['email']) != '') $feed .= ''; $date_obj_update = new DateTime($publi['updated']); $updated = phraseadate::getPrettyString($date_obj_update); if($updated != $published && $date_obj_update->format('U') > $date_obj_pub->format('U')) { $feed .= '
'._('publications:: derniere mise a jour').' '.$updated.'

'; } $feed .= '
'; if(trim(str_replace($RN,'',$publi['content'])) != '') { $publi['content'] = str_replace($RN,'
',$publi['content']); $feed .= ''.$publi['content']; } $feed .= '
'; if(isset($publi['document'])) { foreach($publi['document'] as $doc) { $ord = $doc['order']; $layoutmode = user::getPrefs('view'); $th_size = user::getPrefs('images_size'); $bottom = 0; $right=10; $left=0; $top = 10; $preview = ''; if(GV_zommPrev_rollover_clientAnswer) { $canprev = false; if(isset($usrRight->_rights_bas[$doc["base_id"]]) && $usrRight->_rights_bas[$doc["base_id"]]['canpreview']=='1') $canprev = true; $thumbnail = answer::getThumbnail($session->ses_id, $doc["base_id"], $doc["record_id"],GV_zommPrev_rollover_clientAnswer); $preview = answer::get_preview_rollover($doc["base_id"],$doc["record_id"],$session->ses_id,$canprev,$session->usr_id,$thumbnail['preview'],$doc['type']); } $ratio = $doc["width"] / $doc["height"]; if($ratio > 1) { $cw = min(((int)$th_size-30),$doc["width"]); $ch = $cw/$ratio; $pv = floor(($th_size-$ch)/2); $ph = floor(($th_size-$cw)/2); $imgStyle = 'width:'.$cw.'px;padding:'.$pv.'px '.$ph.'px;'; } else { $ch = min(((int)$th_size-30),$doc["height"]); $cw = $ch*$ratio; $pv = floor(($th_size-$ch)/2); $ph = floor(($th_size-$cw)/2); $imgStyle = 'height:'.$ch.'px;padding:'.$pv.'px '.$ph.'px;'; } $ident = $doc["base_id"]."_".$doc["record_id"]; $feed .= "
"; $feed .= '
'; $feed .= "
"; $feed .= $doc['title'];//$data['title']; $feed .= "
\n"; $feed .= '
'; $feed .= "
\n"; if(trim($doc['duration']) != '') $feed .= '
'.$doc['duration'].'
'; $th_title = ''; if(user::getPrefs('rollover_thumbnail') == 'caption') $th_title = $doc['caption']; if(user::getPrefs('rollover_thumbnail') == 'preview' && $preview != '') $th_title = $preview; $feed .= ""; $feed .= "
"; $feed .= '
'; $feed .= ''; $feed .= ''; $feed .= '\n"; $feed .= ""; $feed .= ""; $feed .= "
'; $feed .= ""; if(user::getPrefs('rollover_thumbnail') == 'caption' && $preview != '') $feed .= "
 "; if(user::getPrefs('rollover_thumbnail') == 'preview') $feed .= '
'; $feed .= "
"; $feed .= "
"; $feed .= "
"; } } $feed .= '
'; } $feed = '
'.$feed.'
'; if($this->infos['next']) { $feed .= '
'._('Charger les publications precedentes').'
'; } return $feed; } }