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 .= '
'; $feed .= " | \n"; $feed .= ""; if(user::getPrefs('rollover_thumbnail') == 'caption' && $preview != '') $feed .= " "; if(user::getPrefs('rollover_thumbnail') == 'preview') $feed .= ''; $feed .= " | "; $feed .= "