mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
V 3.5 RC 1
This commit is contained in:
113
lib/classes/record/Interface.class.php
Normal file
113
lib/classes/record/Interface.class.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
interface record_Interface
|
||||
{
|
||||
public function get_creation_date();
|
||||
|
||||
public function get_uuid();
|
||||
|
||||
public function get_modification_date();
|
||||
|
||||
public function get_number();
|
||||
|
||||
public function set_number($number);
|
||||
|
||||
public function set_type($type);
|
||||
|
||||
public function is_grouping();
|
||||
|
||||
public function get_base_id();
|
||||
|
||||
public function get_record_id();
|
||||
|
||||
public function get_databox();
|
||||
|
||||
public function get_thumbnail();
|
||||
|
||||
public function get_embedable_medias();
|
||||
|
||||
public function get_status_icons();
|
||||
|
||||
public function get_type();
|
||||
|
||||
public function get_formated_duration();
|
||||
|
||||
public function get_duration();
|
||||
|
||||
public function move_to_collection(collection &$collection, appbox &$appbox);
|
||||
|
||||
public function get_rollover_thumbnail();
|
||||
|
||||
public function get_sha256();
|
||||
|
||||
public function get_mime();
|
||||
|
||||
public function get_status();
|
||||
|
||||
public function get_subdef($name);
|
||||
|
||||
public function get_subdefs();
|
||||
|
||||
public function get_collection_logo();
|
||||
|
||||
public function get_technical_infos($data = false);
|
||||
|
||||
public function get_caption();
|
||||
|
||||
public function get_xml();
|
||||
|
||||
public function get_original_name();
|
||||
|
||||
public function get_title($highlight = false, searchEngine_adapter $searchEngine = null);
|
||||
|
||||
public function get_preview();
|
||||
|
||||
public function has_preview();
|
||||
|
||||
public function get_serialize_key();
|
||||
|
||||
public function get_sbas_id();
|
||||
|
||||
public function substitute_subdef($name, system_file $pathfile);
|
||||
|
||||
public function set_metadatas(Array $metadatas);
|
||||
|
||||
public function reindex();
|
||||
|
||||
public function rebuild_subdefs();
|
||||
|
||||
public function write_metas();
|
||||
|
||||
public function set_binary_status($status);
|
||||
|
||||
public function get_reg_name();
|
||||
|
||||
public function get_bitly_link();
|
||||
|
||||
public function get_hd_file();
|
||||
|
||||
public function delete();
|
||||
|
||||
public function generate_subdefs(databox $databox, Array $wanted_subdefs = null);
|
||||
|
||||
public function log_view($log_id, $referrer, $gv_sit);
|
||||
|
||||
public function rotate_subdefs($angle);
|
||||
|
||||
public function get_container_baskets();
|
||||
}
|
1998
lib/classes/record/adapter.class.php
Normal file
1998
lib/classes/record/adapter.class.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
class record_audio extends record
|
||||
{
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
class record_document extends record
|
||||
{
|
||||
|
||||
}
|
326
lib/classes/record/exportElement.class.php
Normal file
326
lib/classes/record/exportElement.class.php
Normal file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class record_exportElement extends record_adapter
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $downloadable;
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $orderable;
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $size;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $remain_hd;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $directory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $base_id
|
||||
* @param int $record_id
|
||||
* @param string $directory
|
||||
* @param int $remain_hd
|
||||
* @return record_exportElement
|
||||
*/
|
||||
function __construct($sbas_id, $record_id, $directory='', $remain_hd=false)
|
||||
{
|
||||
$this->directory = $directory;
|
||||
$this->remain_hd = $remain_hd;
|
||||
$this->size = array();
|
||||
parent::__construct($sbas_id, $record_id);
|
||||
|
||||
$this->get_actions($remain_hd);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return record_exportElement
|
||||
*/
|
||||
protected function get_actions()
|
||||
{
|
||||
$this->downloadable = $downloadable = array();
|
||||
$this->orderable = $orderable = array();
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$sd = $this->get_subdefs();
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($this->base_id);
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
if (isset($sd['document']) &&
|
||||
($user->ACL()->has_right_on_base($this->get_base_id(), 'candwnldhd') ||
|
||||
$user->ACL()->has_preview_grant($this))
|
||||
)
|
||||
{
|
||||
$subdefgroups = $appbox->get_databox($sbas_id)->get_subdef_structure();
|
||||
|
||||
$subdefs = array();
|
||||
|
||||
foreach ($subdefgroups as $subdef_type => $subdefs_obj)
|
||||
{
|
||||
if ($subdef_type == $this->get_type())
|
||||
{
|
||||
$subdefs = $subdefs_obj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$go_dl = array(
|
||||
'document' => false,
|
||||
'preview' => false,
|
||||
'thumbnail' => true
|
||||
);
|
||||
|
||||
if ($user->ACL()->has_right_on_base($this->get_base_id(), 'candwnldhd'))
|
||||
{
|
||||
$go_dl['document'] = true;
|
||||
}
|
||||
if ($user->ACL()->has_right_on_base($this->get_base_id(), 'candwnldpreview'))
|
||||
{
|
||||
$go_dl['preview'] = true;
|
||||
}
|
||||
if ($user->ACL()->has_hd_grant($this))
|
||||
{
|
||||
$go_dl['document'] = true;
|
||||
$go_dl['preview'] = true;
|
||||
}
|
||||
if ($user->ACL()->has_preview_grant($this))
|
||||
{
|
||||
$go_dl['preview'] = true;
|
||||
}
|
||||
|
||||
$query = new User_Query($appbox);
|
||||
|
||||
$masters = $query->on_base_ids(array($this->base_id))
|
||||
->who_have_right(array('order_master'))
|
||||
->execute()->get_results();
|
||||
|
||||
$go_cmd = (count($masters) > 0 && $user->ACL()->has_right_on_base($this->base_id, 'cancmd'));
|
||||
|
||||
$orderable['document'] = false;
|
||||
$downloadable['document'] = false;
|
||||
|
||||
if (isset($sd['document']) && is_file($sd['document']->get_pathfile()))
|
||||
{
|
||||
if ($go_dl['document'] === true)
|
||||
{
|
||||
if ($user->ACL()->is_restricted_download($this->base_id))
|
||||
{
|
||||
$this->remain_hd--;
|
||||
if ($this->remain_hd >= 0)
|
||||
$downloadable['document'] = array(
|
||||
'class' => 'document',
|
||||
'label' => _('document original')
|
||||
);
|
||||
}
|
||||
else
|
||||
$downloadable['document'] = array(
|
||||
'class' => 'document',
|
||||
'label' => _('document original')
|
||||
);
|
||||
}
|
||||
if ($go_cmd === true)
|
||||
{
|
||||
$orderable['document'] = true;
|
||||
}
|
||||
|
||||
$this->add_count('document', $sd['document']->get_size());
|
||||
}
|
||||
|
||||
|
||||
foreach ($subdefs as $subdef)
|
||||
{
|
||||
$name = $subdef->get_name();
|
||||
$class = $subdef->get_class();
|
||||
|
||||
|
||||
$subdef_label = $name;
|
||||
foreach ($subdef->get_labels() as $lang => $label)
|
||||
{
|
||||
if (trim($label) == '')
|
||||
continue;
|
||||
|
||||
if ($lang == $session->get_I18n())
|
||||
{
|
||||
$subdef_label = $label;
|
||||
break;
|
||||
}
|
||||
$subdef_label = $label;
|
||||
}
|
||||
|
||||
$downloadable[$name] = false;
|
||||
|
||||
$downloadable_settings = $subdef->is_downloadable();
|
||||
|
||||
if (!$downloadable_settings || $go_dl[$class] === false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($go_dl[$class])
|
||||
{
|
||||
if (isset($sd[$name]) && is_file($sd[$name]->get_pathfile()))
|
||||
{
|
||||
if ($class == 'document')
|
||||
{
|
||||
|
||||
if ($user->ACL()->is_restricted_download($this->base_id))
|
||||
{
|
||||
$this->remain_hd--;
|
||||
if ($this->remain_hd >= 0)
|
||||
$downloadable[$name] = array(
|
||||
'class' => $class,
|
||||
'label' => $subdef_label
|
||||
);
|
||||
}
|
||||
else
|
||||
$downloadable[$name] = array(
|
||||
'class' => $class,
|
||||
'label' => $subdef_label
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$downloadable[$name] = array(
|
||||
'class' => $class,
|
||||
'label' => $subdef_label
|
||||
);
|
||||
}
|
||||
|
||||
$this->add_count($name, $sd[$name]->get_size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$xml = $this->get_xml();
|
||||
|
||||
if ($xml)
|
||||
{
|
||||
$downloadable['caption'] = array(
|
||||
'class' => 'caption',
|
||||
'label' => _('caption XML')
|
||||
);
|
||||
$this->add_count('caption', strlen($xml));
|
||||
$downloadable['caption-yaml'] = array(
|
||||
'class' => 'caption',
|
||||
'label' => _('caption YAML')
|
||||
);
|
||||
$this->add_count('caption-yaml', strlen(strip_tags($xml)));
|
||||
}
|
||||
|
||||
$this->downloadable = $downloadable;
|
||||
$this->orderable = $orderable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $size
|
||||
* @return record_exportElement
|
||||
*/
|
||||
private function add_count($name, $size)
|
||||
{
|
||||
if (!$this->size)
|
||||
{
|
||||
$objectsize = array();
|
||||
}
|
||||
else
|
||||
$objectsize = $this->size;
|
||||
|
||||
$objectsize[$name] = $size;
|
||||
|
||||
$this->size = $objectsize;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed content
|
||||
*/
|
||||
public function get_size($name = false)
|
||||
{
|
||||
if ($name)
|
||||
|
||||
return $this->size[$name];
|
||||
else
|
||||
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_orderable()
|
||||
{
|
||||
return $this->orderable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_downloadable()
|
||||
{
|
||||
return $this->downloadable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_remain_hd()
|
||||
{
|
||||
return $this->remain_hd;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_directory()
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
|
||||
}
|
@@ -1,546 +0,0 @@
|
||||
<?php
|
||||
class record_image extends record
|
||||
{
|
||||
private function wrap($fontSize, $angle, $fontFace, $string, $width)
|
||||
{
|
||||
$ret = array();
|
||||
$testbox = imagettfbbox($fontSize, $angle, $fontFace, 'Op'); // str 'Op' used to calculate linespace
|
||||
$height = abs($testbox[1] - ($dy = $testbox[7]));
|
||||
|
||||
foreach(explode("\n", $string) as $lig)
|
||||
{
|
||||
if($lig == '')
|
||||
{
|
||||
$ret[] = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$buff = '';
|
||||
foreach(explode(' ', $lig) as $wrd)
|
||||
{
|
||||
$test = $buff . ($buff?' ':'') . $wrd;
|
||||
$testbox = imagettfbbox($fontSize, $angle, $fontFace, $test);
|
||||
if( abs($testbox[2]-$testbox[0]) > $width )
|
||||
{
|
||||
if($buff=='')
|
||||
{
|
||||
$ret[] = $test;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret[] = $buff;
|
||||
$buff = $wrd;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$buff = $test;
|
||||
}
|
||||
}
|
||||
if($buff != '')
|
||||
$ret[] = $buff;
|
||||
}
|
||||
}
|
||||
return(array('l'=>$ret, 'h'=>$height, 'dy'=>$dy));
|
||||
}
|
||||
|
||||
|
||||
public static function stamp($bas, $rec, $hd=false)
|
||||
{
|
||||
$debug = false;
|
||||
// define('STAMPLOG', '/home/gaulier/workspace/v22/tmp/stamp.log');
|
||||
// define('STAMPLOG', '/home/gaulier/Documents/exports/stamp.log');
|
||||
|
||||
// if($debug)
|
||||
// file_put_contents(STAMPLOG, "");
|
||||
|
||||
if(GV_imagick == '' )
|
||||
return false;
|
||||
|
||||
$conn = connection::getInstance();
|
||||
|
||||
$ph_session = phrasea::bases();
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($bas);
|
||||
|
||||
if(!isset($sbas_id))
|
||||
return false;
|
||||
|
||||
$connSbas = connection::getInstance($sbas_id);
|
||||
|
||||
if(!$connSbas)
|
||||
return false;
|
||||
|
||||
$sdname = 'preview';
|
||||
if($hd)
|
||||
$sdname = 'document';
|
||||
|
||||
$sql = "SELECT path, file, mime, type, xml, prefs FROM subdef s, record r, coll c WHERE r.record_id='".$connSbas->escape_string($rec)."' AND r.record_id = s.record_id AND name='".$connSbas->escape_string($sdname)."' AND c.coll_id=r.coll_id";
|
||||
|
||||
$sxprefs = $sxxml = $domprefs = FALSE;
|
||||
if($rs = $connSbas->query($sql))
|
||||
{
|
||||
if($row = $connSbas->fetch_assoc($rs))
|
||||
{
|
||||
|
||||
$domprefs = new DOMDocument();
|
||||
if( !($domprefs->loadXML($row['prefs'])) )
|
||||
$domprefs = FALSE;
|
||||
|
||||
$sxxml = simplexml_load_string($row['xml']);
|
||||
$file = array(
|
||||
'type'=>$row['type']
|
||||
,'path'=>p4string::addEndSlash($row['path'])
|
||||
,'file'=>$row['file']
|
||||
,'mime'=>$row['mime']
|
||||
);
|
||||
}
|
||||
$connSbas->free_result($rs);
|
||||
}
|
||||
|
||||
if($domprefs===FALSE || $sxxml===FALSE)
|
||||
return false;
|
||||
|
||||
$xpprefs = new DOMXPath($domprefs);
|
||||
|
||||
$pathIn = $file['path'].$file['file'];
|
||||
$pathOut = $file['path'].'stamp_'.$file['file'];
|
||||
$pathTmpStamp = GV_RootPath.'tmp/'.time().'-stamptmp_'.$file['file'];
|
||||
|
||||
if(!is_file($pathIn))
|
||||
return false;
|
||||
|
||||
if($file['type'] != 'image' || $xpprefs->query('/baseprefs/stamp')->length == 0)
|
||||
{
|
||||
return $pathIn;
|
||||
}
|
||||
|
||||
$vars = $xpprefs->query('/baseprefs/stamp/*/var');
|
||||
for($i=0; $i<$vars->length; $i++)
|
||||
{
|
||||
$varval = '';
|
||||
$n = $vars->item($i);
|
||||
switch(strtoupper($n->getAttribute('name')))
|
||||
{
|
||||
case 'DATE':
|
||||
if( !($format = $n->getAttribute('format')) )
|
||||
$format = 'Y/m/d H:i:s';
|
||||
$varval = date($format);
|
||||
@unlink($pathOut); // since date is included, invalidate cache
|
||||
break;
|
||||
case 'RECORD_ID':
|
||||
$varval = $rec;
|
||||
break;
|
||||
}
|
||||
$n->parentNode->replaceChild($domprefs->createTextNode($varval), $n);
|
||||
}
|
||||
|
||||
// ------------- CACHING !
|
||||
if(is_file($pathOut))
|
||||
return $pathOut;
|
||||
|
||||
$fields = $xpprefs->query('/baseprefs/stamp/*/field');
|
||||
for($i=0; $i<$fields->length; $i++)
|
||||
{
|
||||
$fldval = '';
|
||||
$n = $fields->item($i);
|
||||
$fieldname = $n->getAttribute('name');
|
||||
|
||||
$x = $sxxml->description->{$fieldname};
|
||||
if(is_array($x))
|
||||
{
|
||||
foreach($x as $v)
|
||||
$fldval .= ($fldval?'; ':'') . (string)$v ;
|
||||
}
|
||||
else
|
||||
{
|
||||
$fldval .= ($fldval?'; ':'') . (string)$x ;
|
||||
}
|
||||
$n->parentNode->replaceChild($domprefs->createTextNode($fldval), $n);
|
||||
}
|
||||
|
||||
$domprefs->normalizeDocument();
|
||||
|
||||
$collname = "";
|
||||
foreach($ph_session["bases"] as $base)
|
||||
{
|
||||
foreach($base["collections"] as $coll)
|
||||
{
|
||||
if($coll["base_id"]==$bas)
|
||||
{
|
||||
$collname = $coll["name"] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !($tailleimg = @getimagesize($pathIn)) )
|
||||
return false;
|
||||
|
||||
|
||||
$image_width = $tailleimg[0];
|
||||
$image_height = $tailleimg[1];
|
||||
|
||||
$text_xpos = 0;
|
||||
$text_width = $image_width;
|
||||
|
||||
$logofile = GV_RootPath . 'config/stamp/' . $bas;
|
||||
$logopos = null;
|
||||
$imlogo = null; // gd image
|
||||
$logo_phywidth = $logo_phyheight = 0; // physical size
|
||||
$logo_reswidth = $logo_resheight = 0; // resized size
|
||||
|
||||
if( is_array($logosize = @getimagesize($logofile)) )
|
||||
{
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : %s\n", __LINE__, var_export($logosize, true)), FILE_APPEND);
|
||||
$logo_reswidth = $logo_phywidth = $logosize[0];
|
||||
$logo_resheight = $logo_phyheight = $logosize[1];
|
||||
|
||||
$v = $xpprefs->query('/baseprefs/stamp/logo');
|
||||
if($v->length > 0)
|
||||
{
|
||||
$logopos = @strtoupper($v->item(0)->getAttribute('position'));
|
||||
if( ($logowidth = trim($v->item(0)->getAttribute('width'))) != '')
|
||||
{
|
||||
if(substr($logowidth, -1) == '%')
|
||||
$logo_reswidth = (int)($logowidth * $image_width / 100);
|
||||
else
|
||||
$logo_reswidth = (int)$logowidth;
|
||||
$logo_resheight = (int)($logo_phyheight * ($logo_reswidth/$logo_phywidth));
|
||||
}
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : logo_reswidth=%s logo_phywidth=%s logo_resheight=%s logo_phyheight=%s \n", __LINE__, $logo_reswidth, $logo_phywidth, $logo_resheight, $logo_phyheight), FILE_APPEND);
|
||||
|
||||
if(($logopos == 'LEFT' || $logopos == 'RIGHT') && $logo_phywidth > 0 && $logo_phyheight > 0)
|
||||
{
|
||||
switch($logosize['mime'])
|
||||
{
|
||||
case 'image/gif':
|
||||
$imlogo = @imagecreatefromgif($logofile);
|
||||
break;
|
||||
case 'image/png':
|
||||
$imlogo = @imagecreatefrompng($logofile);
|
||||
break;
|
||||
case 'image/jpeg':
|
||||
case 'image/pjpeg':
|
||||
$imlogo = @imagecreatefromjpeg($logofile);
|
||||
break;
|
||||
}
|
||||
if($imlogo)
|
||||
{
|
||||
if($logo_reswidth > $image_width/2)
|
||||
{
|
||||
// logo too large, resize please
|
||||
$logo_reswidth = (int)($image_width/2);
|
||||
$logo_resheight = (int)($logo_phyheight * ($logo_reswidth/$logo_phywidth));
|
||||
}
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : logo_reswidth=%s logo_phywidth=%s logo_resheight=%s logo_phyheight=%s \n", __LINE__, $logo_reswidth, $logo_phywidth, $logo_resheight, $logo_phyheight), FILE_APPEND);
|
||||
|
||||
$text_width -= ($text_xpos = $logo_reswidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$txth = 0;
|
||||
$txtblock = array();
|
||||
$texts = $xpprefs->query('/baseprefs/stamp/text');
|
||||
$fontsize = "100%";
|
||||
for($i=0; $i<$texts->length; $i++)
|
||||
{
|
||||
if( ($tmpfontsize = trim($texts->item($i)->getAttribute('size'))) != '' )
|
||||
{
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : %s * %s\n", __LINE__, $tmpfontsize, $image_width), FILE_APPEND);
|
||||
if(substr($tmpfontsize, -1) == '%')
|
||||
$tmpfontsize = (int)($tmpfontsize * $image_width / 4000);
|
||||
else
|
||||
$tmpfontsize = (int)$tmpfontsize;
|
||||
//if($tmpfontsize > 300)
|
||||
// $tmpfontsize = 300;
|
||||
$fontsize = $tmpfontsize;
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : %s\n", __LINE__, $fontsize), FILE_APPEND);
|
||||
}
|
||||
// if(!$hd)
|
||||
// {
|
||||
// $fontsize = $fontsize * 0.2;
|
||||
// }
|
||||
|
||||
if($fontsize < 2)
|
||||
$fontsize = 2;
|
||||
elseif($fontsize > 300)
|
||||
$fontsize = 300;
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : %s\n", __LINE__, $fontsize), FILE_APPEND);
|
||||
|
||||
$txtline = $texts->item($i)->nodeValue;
|
||||
|
||||
if($txtline != '')
|
||||
{
|
||||
$txtlines = record_image::wrap($fontsize, 0, GV_RootPath.'lib/stamper/arial.ttf', $txtline, $text_width);
|
||||
|
||||
foreach($txtlines['l'] as $txtline)
|
||||
{
|
||||
$txtblock[] = array('x'=>$text_xpos, 'dy'=>$txtlines['dy'], 'w'=>$text_width, 'h'=>$txtlines['h'], 't'=>$txtline, 's'=>$fontsize);//, 'b'=>$txtbox);
|
||||
$txth += $txtlines['h'];
|
||||
}
|
||||
}
|
||||
}
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : txtblock=%s \n", __LINE__, var_export($txtblock, true)), FILE_APPEND);
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : txth=%s \n", __LINE__, $txth), FILE_APPEND);
|
||||
|
||||
$stampheight = max($logo_resheight, $txth);
|
||||
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : stampheight=%s \n", __LINE__, $stampheight), FILE_APPEND);
|
||||
|
||||
$im = imagecreatetruecolor($image_width, $stampheight);
|
||||
|
||||
$white = imagecolorallocate($im, 255, 255, 255);
|
||||
imagefilledrectangle($im, 0,0 , $image_width, $stampheight, $white);
|
||||
imagecolordeallocate($im, $white);
|
||||
|
||||
//if($debug)
|
||||
// imagejpeg($im, '/home/gaulier/Documents/exports/stamp.1.jpg', 80);
|
||||
|
||||
if($imlogo)
|
||||
{
|
||||
if($logo_reswidth != $logo_phywidth)
|
||||
{
|
||||
imagecopyresampled($im, $imlogo,
|
||||
0, 0, // dst_x, dst_y
|
||||
0, 0, // src_x, src_y
|
||||
$logo_reswidth, // dst_w
|
||||
$logo_resheight, // dst_h
|
||||
$logo_phywidth, // src_w
|
||||
$logo_phyheight // src_h
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
imagecopy($im, $imlogo,
|
||||
0, 0, // dst_x, dst_y
|
||||
0, 0, // src_x, src_y
|
||||
$logo_phywidth, // src_w
|
||||
$logo_phyheight // src_h
|
||||
);
|
||||
}
|
||||
}
|
||||
//if($debug)
|
||||
// imagejpeg($im, '/home/gaulier/Documents/exports/stamp.2.jpg', 80);
|
||||
|
||||
if(count($txtblock) >= 0)
|
||||
{
|
||||
$black = imagecolorallocate($im, 0, 0, 0);
|
||||
$txt_ypos = 0; //$txtblock[0]['h'];
|
||||
foreach($txtblock as $block)
|
||||
{
|
||||
imagettftext($im, $block['s'], 0, $block['x'], $txt_ypos-$block['dy'], $black, GV_RootPath.'lib/stamper/arial.ttf', $block['t']);
|
||||
$txt_ypos += $block['h'];
|
||||
}
|
||||
imagecolordeallocate($im, $black);
|
||||
}
|
||||
imagejpeg($im, $pathTmpStamp, 80);
|
||||
|
||||
//if($debug)
|
||||
// imagejpeg($im, '/home/gaulier/Documents/exports/stamp.3.jpg', 80);
|
||||
|
||||
imagedestroy($im);
|
||||
|
||||
$newh = $image_height + $stampheight;
|
||||
|
||||
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : newh=%s \n", __LINE__, $newh), FILE_APPEND);
|
||||
|
||||
$cmd = GV_imagick ;
|
||||
$cmd .= ' -extent "'.$image_width.'x'.$newh.'" -draw "image SrcOver 0,'.$image_height.' '.$image_width.','.$stampheight.'
|
||||
\''.$pathTmpStamp.'\'"';
|
||||
|
||||
$cmd.= " \"".$pathIn ."\""; # <<-- le doc original
|
||||
$cmd.= " \"".$pathOut."\""; # <-- le doc stampe
|
||||
|
||||
//if($debug)
|
||||
// file_put_contents(STAMPLOG, sprintf("%d : cmd=%s \n", __LINE__, $cmd), FILE_APPEND);
|
||||
|
||||
/*
|
||||
$descriptorspec = array(0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
||||
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
||||
2 => array("pipe", "w") // stderr is a file to write to
|
||||
);
|
||||
$process = proc_open($cmd, $descriptorspec, $pipes);
|
||||
if (is_resource($process))
|
||||
{
|
||||
fclose($pipes[0]);
|
||||
$err="";
|
||||
while (!feof($pipes[1]))
|
||||
$out = fgets($pipes[1], 1024);
|
||||
fclose($pipes[1]);
|
||||
while (!feof($pipes[2]))
|
||||
$err .= fgets($pipes[2], 1024);
|
||||
fclose($pipes[2]);
|
||||
$return_value = proc_close($process);
|
||||
}
|
||||
*/
|
||||
exec($cmd);
|
||||
|
||||
unlink($pathTmpStamp);
|
||||
|
||||
if(is_file($pathOut))
|
||||
return $pathOut;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function watermark($bas,$rec,$hd=false)
|
||||
{
|
||||
$conn = connection::getInstance();
|
||||
|
||||
$ph_session = phrasea::bases();
|
||||
|
||||
$sbas_id = phrasea::sbasFromBas($bas);
|
||||
|
||||
if(!isset($sbas_id))
|
||||
return false;
|
||||
|
||||
$connSbas = connection::getInstance($sbas_id);
|
||||
|
||||
if(!$connSbas)
|
||||
return false;
|
||||
|
||||
$sql = "SELECT path, file, mime, type, xml FROM subdef s, record r WHERE r.record_id='".$connSbas->escape_string($rec)."' AND r.record_id = s.record_id AND name='preview'";
|
||||
|
||||
if($rs = $connSbas->query($sql))
|
||||
{
|
||||
if($row = $connSbas->fetch_assoc($rs))
|
||||
{
|
||||
$file = array(
|
||||
'type'=>$row['type']
|
||||
,'path'=>p4string::addEndSlash($row['path'])
|
||||
,'file'=>$row['file']
|
||||
,'mime'=>$row['mime']
|
||||
,'xml'=>$row['xml']
|
||||
);
|
||||
}
|
||||
$connSbas->free_result($rs);
|
||||
}
|
||||
|
||||
if(!isset($file))
|
||||
return false;
|
||||
|
||||
$pathIn = $file['path'].$file['file'];
|
||||
|
||||
$pathOut = $file['path'].'watermark_'.$file['file'];
|
||||
|
||||
if(!is_file($pathIn))
|
||||
return false;
|
||||
|
||||
if(is_file($pathOut))
|
||||
return $pathOut;
|
||||
|
||||
|
||||
if(trim(GV_pathcomposite) != "" && file_exists(GV_RootPath.'config/wm/'.$bas)) // si il y a un WM
|
||||
{
|
||||
$cmd = GV_pathcomposite . " ";
|
||||
$cmd .= GV_RootPath.'config/wm/'.$bas . " ";
|
||||
$cmd .= " \"".$pathIn ."\" "; # <<-- la preview original
|
||||
$cmd .= " -strip -watermark 90% -gravity center ";
|
||||
$cmd .= " \"".$pathOut."\""; # <-- la preview temporaire
|
||||
|
||||
|
||||
$descriptorspec = array(0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
||||
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
||||
2 => array("pipe", "w") // stderr is a file to write to
|
||||
);
|
||||
$process = proc_open($cmd, $descriptorspec, $pipes);
|
||||
if (is_resource($process))
|
||||
{
|
||||
fclose($pipes[0]);
|
||||
$err="";
|
||||
while (!feof($pipes[1]))
|
||||
$out = fgets($pipes[1], 1024);
|
||||
fclose($pipes[1]);
|
||||
while (!feof($pipes[2]))
|
||||
$err .= fgets($pipes[2], 1024);
|
||||
fclose($pipes[2]);
|
||||
$return_value = proc_close($process);
|
||||
}
|
||||
}
|
||||
elseif(GV_imagick!="" )
|
||||
{
|
||||
$collname = "";
|
||||
foreach($ph_session["bases"] as $base)
|
||||
{
|
||||
foreach($base["collections"] as $coll)
|
||||
{
|
||||
if($coll["base_id"]==$bas)
|
||||
{
|
||||
$collname = $coll["name"] ;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$cmd = GV_imagick ;
|
||||
$tailleimg = @getimagesize($pathIn);
|
||||
$max = ($tailleimg[0]> $tailleimg[1]?$tailleimg[0]: $tailleimg[1]);
|
||||
|
||||
$tailleText = (int)($max/30);
|
||||
|
||||
if($tailleText<8)
|
||||
$tailleText=8;
|
||||
|
||||
if($tailleText>12)
|
||||
$decalage=2;
|
||||
else
|
||||
$decalage=1;
|
||||
|
||||
$cmd .= " -fill white -draw \"line 0,0 ".$tailleimg[0].",".$tailleimg[1]."\"";
|
||||
$cmd .= " -fill black -draw \"line 1,0 ".($tailleimg[0]+1).",".($tailleimg[1])."\"";
|
||||
|
||||
$cmd .= " -fill white -draw \"line ".$tailleimg[0].",0 0,".$tailleimg[1]."\"";
|
||||
$cmd .= " -fill black -draw \"line ".($tailleimg[0]+1).",0 1,".($tailleimg[1])."\"";
|
||||
|
||||
$cmd .= " -fill white -gravity NorthWest -pointsize $tailleText -draw \"text 0,0 '$collname'\"";
|
||||
$cmd .= " -fill black -gravity NorthWest -pointsize $tailleText -draw \"text $decalage,1 '$collname'\"";
|
||||
|
||||
$cmd .= " -fill white -gravity center -pointsize $tailleText -draw \"text 0,0 '$collname'\"";
|
||||
$cmd .= " -fill black -gravity center -pointsize $tailleText -draw \"text $decalage,1 '$collname'\"";
|
||||
|
||||
$cmd .= " -fill white -gravity SouthEast -pointsize $tailleText -draw \"text 0,0 '$collname'\"";
|
||||
$cmd .= " -fill black -gravity SouthEast -pointsize $tailleText -draw \"text $decalage,1 '$collname'\"";
|
||||
|
||||
|
||||
$cmd.= " \"".$pathIn ."\""; # <<-- la preview original
|
||||
$cmd.= " \"".$pathOut."\""; # <-- la preview temporaire
|
||||
|
||||
$descriptorspec = array(0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
||||
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
||||
2 => array("pipe", "w") // stderr is a file to write to
|
||||
);
|
||||
$process = proc_open($cmd, $descriptorspec, $pipes);
|
||||
if (is_resource($process))
|
||||
{
|
||||
fclose($pipes[0]);
|
||||
$err="";
|
||||
while (!feof($pipes[1]))
|
||||
$out = fgets($pipes[1], 1024);
|
||||
fclose($pipes[1]);
|
||||
while (!feof($pipes[2]))
|
||||
$err .= fgets($pipes[2], 1024);
|
||||
fclose($pipes[2]);
|
||||
$return_value = proc_close($process);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(is_file($pathOut))
|
||||
return $pathOut;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
class record_map extends record
|
||||
{
|
||||
|
||||
}
|
85
lib/classes/record/orderElement.class.php
Normal file
85
lib/classes/record/orderElement.class.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class record_orderElement extends record_adapter
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $deny;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $order_master_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $base_id
|
||||
* @param int $record_id
|
||||
* @param boolean $deny
|
||||
* @param int $order_master_id
|
||||
*/
|
||||
public function __construct($sbas_id, $record_id, $deny, $order_master_id)
|
||||
{
|
||||
$this->deny = !!$deny;
|
||||
$this->order_master_id = $order_master_id;
|
||||
|
||||
parent::__construct($sbas_id, $record_id);
|
||||
|
||||
$this->get_subdefs();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_order_master_name()
|
||||
{
|
||||
if ($this->order_master_id)
|
||||
{
|
||||
$user = User_Adapter::getInstance($this->order_master_id, appbox::get_instance());
|
||||
|
||||
return $user->get_display_name();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_order_master_id()
|
||||
{
|
||||
return $this->order_master_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function get_deny()
|
||||
{
|
||||
return $this->deny;
|
||||
}
|
||||
|
||||
}
|
669
lib/classes/record/preview.class.php
Normal file
669
lib/classes/record/preview.class.php
Normal file
@@ -0,0 +1,669 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class record_preview extends record_adapter
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $env;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $total;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var mixed content
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var mixed content
|
||||
*/
|
||||
protected $train;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $short_history;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var media
|
||||
*/
|
||||
protected $view_popularity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var media
|
||||
*/
|
||||
protected $refferer_popularity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var media
|
||||
*/
|
||||
protected $download_popularity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $env
|
||||
* @param int $pos
|
||||
* @param mixed content $contId
|
||||
* @param boolean $reload_train
|
||||
* @return record_preview
|
||||
*/
|
||||
public function __construct($env, $pos, $contId, $reload_train, searchEngine_adapter $search_engine =null, $query='')
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$number = null;
|
||||
$this->env = $env;
|
||||
|
||||
switch ($env)
|
||||
{
|
||||
case "RESULT":
|
||||
$results = $search_engine->query_per_offset($query, (int) ($pos), 1);
|
||||
$mypreview = array();
|
||||
|
||||
if ($results->get_datas()->is_empty())
|
||||
{
|
||||
throw new Exception('Record introuvable');
|
||||
}
|
||||
foreach ($results->get_datas() as $record)
|
||||
{
|
||||
$number = $pos;
|
||||
$sbas_id = $record->get_sbas_id();
|
||||
$record_id = $record->get_record_id();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "REG":
|
||||
$contId = explode('_', $contId);
|
||||
$base_id = $contId[0];
|
||||
$sbas_id = phrasea::sbasFromBas($base_id);
|
||||
$record_id = $contId[1];
|
||||
|
||||
$this->container = new record_adapter($sbas_id, $record_id);
|
||||
if ($pos == 0)
|
||||
{
|
||||
$number = 0;
|
||||
$title = _('preview:: regroupement ');
|
||||
}
|
||||
else
|
||||
{
|
||||
// $this->container = new record_adapter($sbas_id, $record_id);
|
||||
$children = $this->container->get_children();
|
||||
foreach ($children as $child)
|
||||
{
|
||||
$sbas_id = $child->get_sbas_id();
|
||||
$record_id = $child->get_record_id();
|
||||
if ($child->get_number() == $pos)
|
||||
break;
|
||||
}
|
||||
$number = $pos;
|
||||
$this->total = $children->get_count();
|
||||
}
|
||||
|
||||
break;
|
||||
case "BASK":
|
||||
$basket = basket_adapter::getInstance($appbox, $contId, $appbox->get_session()->get_usr_id());
|
||||
|
||||
$this->container = $basket;
|
||||
$this->total = count($basket->get_elements());
|
||||
$i = 0;
|
||||
$first = true;
|
||||
|
||||
foreach ($basket->get_elements() as $element)
|
||||
{
|
||||
$i++;
|
||||
if ($first)
|
||||
{
|
||||
$sbas_id = $element->get_record()->get_sbas_id();
|
||||
$record_id = $element->get_record()->get_record_id();
|
||||
$this->name = $basket->get_name();
|
||||
$number = $element->get_order();
|
||||
}
|
||||
$first = false;
|
||||
|
||||
if ($element->get_order() == $pos)
|
||||
{
|
||||
$sbas_id = $element->get_record()->get_sbas_id();
|
||||
$record_id = $element->get_record()->get_record_id();
|
||||
$this->name = $basket->get_name();
|
||||
$number = $element->get_order();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "FEED":
|
||||
$entry = Feed_Entry_Adapter::load_from_id($appbox, $contId);
|
||||
// $basket = basket_adapter::getInstance($appbox, $contId, $appbox->get_session()->get_usr_id());
|
||||
|
||||
$this->container = $entry;
|
||||
$this->total = count($entry->get_content());
|
||||
$i = 0;
|
||||
$first = true;
|
||||
|
||||
foreach ($entry->get_content() as $element)
|
||||
{
|
||||
$i++;
|
||||
if ($first)
|
||||
{
|
||||
$sbas_id = $element->get_record()->get_sbas_id();
|
||||
$record_id = $element->get_record()->get_record_id();
|
||||
$this->name = $entry->get_title();
|
||||
$number = $element->get_ord();
|
||||
}
|
||||
$first = false;
|
||||
|
||||
if ($element->get_ord() == $pos)
|
||||
{
|
||||
$sbas_id = $element->get_record()->get_sbas_id();
|
||||
$record_id = $element->get_record()->get_record_id();
|
||||
$this->name = $entry->get_title();
|
||||
$number = $element->get_ord();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
parent::__construct($sbas_id, $record_id, $number);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_train($pos = 0, $query='', searchEngine_adapter $search_engine=null)
|
||||
{
|
||||
if ($this->train)
|
||||
return $this->train;
|
||||
|
||||
switch ($this->env)
|
||||
{
|
||||
case 'RESULT':
|
||||
$perPage = 56;
|
||||
$index = ($pos - 3) < 0 ? 0 : ($pos - 3);
|
||||
$page = (int) ceil($pos / $perPage);
|
||||
$results = $search_engine->query_per_offset($query, $index, $perPage);
|
||||
|
||||
$this->train = $results->get_datas();
|
||||
break;
|
||||
case 'BASK':
|
||||
$this->train = $this->container->get_elements();
|
||||
break;
|
||||
case 'REG':
|
||||
$this->train = $this->container->get_children();
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->train;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_from_result()
|
||||
{
|
||||
return $this->env == 'RESULT';
|
||||
}
|
||||
|
||||
public function is_from_feed()
|
||||
{
|
||||
return $this->env == 'FEED';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_from_basket()
|
||||
{
|
||||
return $this->env == 'BASK';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_from_reg()
|
||||
{
|
||||
return $this->env == 'REG';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function get_title($highlight = '', searchEngine_adapter $search_engine=null)
|
||||
{
|
||||
if ($this->title)
|
||||
return $this->title;
|
||||
$this->title = collection::getLogo($this->get_base_id()) . ' ';
|
||||
switch ($this->env)
|
||||
{
|
||||
|
||||
case "RESULT":
|
||||
$this->title .= sprintf(
|
||||
_('preview:: resultat numero %s '), '<span id="current_result_n">' . ($this->number + 1)
|
||||
. '</span>'
|
||||
);
|
||||
|
||||
$title = parent::get_title();
|
||||
if ($search_engine instanceof searchEngine_adapter)
|
||||
{
|
||||
$this->title .= array_pop($search_engine->build_excerpt($highlight, array($title), $this));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->title .= $title;
|
||||
}
|
||||
break;
|
||||
case "BASK":
|
||||
$this->title .= $this->name . ' - ' . parent::get_title()
|
||||
. ' (' . $this->get_number() . '/' . $this->total . ') ';
|
||||
break;
|
||||
case "REG":
|
||||
if ($this->get_number() == 0)
|
||||
$this->title .= _('preview:: regroupement ');
|
||||
else
|
||||
$this->title .= sprintf(
|
||||
_('preview:: Previsualisation numero %s '), $this->get_number() . '/' . $this->total
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$this->title .= parent::get_title();
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return mixed content
|
||||
*/
|
||||
public function get_container()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_short_history()
|
||||
{
|
||||
if (!is_null($this->short_history))
|
||||
return $this->short_history;
|
||||
|
||||
$tab = array();
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$registry = $appbox->get_registry();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
$report = $user->ACL()->has_right_on_base($this->get_base_id(), 'canreport');
|
||||
|
||||
$connsbas = connection::getPDOConnection($this->get_sbas_id());
|
||||
|
||||
$sql = 'SELECT d . * , l.user, l.usrid as usr_id, l.site
|
||||
FROM log_docs d, log l
|
||||
WHERE d.log_id = l.id
|
||||
AND d.record_id = :record_id ';
|
||||
$params = array(':record_id' => $this->get_record_id());
|
||||
|
||||
if (!$report)
|
||||
{
|
||||
$sql .= ' AND ((l.usrid = :usr_id AND l.site= :site) OR action="add")';
|
||||
$params[':usr_id'] = $session->get_usr_id();
|
||||
$params[':site'] = $registry->get('GV_sit');
|
||||
}
|
||||
|
||||
$sql .= 'ORDER BY d.date, usrid DESC';
|
||||
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
$hour = phraseadate::getPrettyString(new DateTime($row['date']));
|
||||
|
||||
if (!isset($tab[$hour]))
|
||||
$tab[$hour] = array();
|
||||
|
||||
$site = $row['site'];
|
||||
|
||||
if (!isset($tab[$hour][$site]))
|
||||
$tab[$hour][$site] = array();
|
||||
|
||||
$action = $row['action'];
|
||||
|
||||
if (!isset($tab[$hour][$site][$action]))
|
||||
$tab[$hour][$site][$action] = array();
|
||||
|
||||
if (!isset($tab[$hour][$site][$action][$row['usr_id']]))
|
||||
$tab[$hour][$site][$action][$row['usr_id']] =
|
||||
array('final' => array(), 'comment' => array());
|
||||
|
||||
if (!in_array($row['final'], $tab[$hour][$site][$action][$row['usr_id']]['final']))
|
||||
$tab[$hour][$site][$action][$row['usr_id']]['final'][] =
|
||||
$row['final'];
|
||||
|
||||
if (!in_array($row['comment'], $tab[$hour][$site][$action][$row['usr_id']]['comment']))
|
||||
$tab[$hour][$site][$action][$row['usr_id']]['comment'][] =
|
||||
$row['comment'];
|
||||
}
|
||||
|
||||
$this->short_history = array_reverse($tab);
|
||||
|
||||
return $this->short_history;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return media_image
|
||||
*/
|
||||
public function get_view_popularity()
|
||||
{
|
||||
if (!is_null($this->view_popularity))
|
||||
return $this->view_popularity;
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$report = $user->ACL()->has_right_on_base(
|
||||
$this->get_base_id(), 'canreport');
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
if (!$report && !$registry->get('GV_google_api'))
|
||||
{
|
||||
$this->view_popularity = false;
|
||||
|
||||
return $this->view_popularity;
|
||||
}
|
||||
|
||||
$views = $dwnls = array();
|
||||
$top = 1;
|
||||
$day = 30;
|
||||
$min = 0;
|
||||
$average = 0;
|
||||
|
||||
while ($day >= 0)
|
||||
{
|
||||
|
||||
$datetime = new DateTime('-' . $day . ' days');
|
||||
$date = date_format($datetime, 'Y-m-d');
|
||||
$views[$date] = $dwnls[$date] = 0;
|
||||
$day--;
|
||||
}
|
||||
|
||||
$sql = 'SELECT count(id) as views, DATE(date) as datee
|
||||
FROM `log_view`
|
||||
WHERE record_id = :record_id
|
||||
AND date > (NOW() - INTERVAL 1 MONTH)
|
||||
AND site_id = :site
|
||||
GROUP BY datee ORDER BY datee ASC';
|
||||
|
||||
$connsbas = connection::getPDOConnection($this->get_sbas_id());
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute(
|
||||
array(
|
||||
':record_id' => $this->get_record_id(),
|
||||
':site' => $registry->get('GV_sit')
|
||||
)
|
||||
);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if (isset($views[$row['datee']]))
|
||||
{
|
||||
$views[$row['datee']] = (int) $row['views'];
|
||||
$top = max((int) $row['views'], $top);
|
||||
$min = isset($min) ? min($row['views'], $min) : $row['views'];
|
||||
$average += $row['views'];
|
||||
}
|
||||
}
|
||||
|
||||
$topScale = round($top * 1.2);
|
||||
|
||||
$average = $average / 30;
|
||||
$max = round(($top) * 100 / ($topScale));
|
||||
$min = round($min * 100 / ($topScale));
|
||||
$average = round($average * 100 / ($topScale));
|
||||
|
||||
$width = 350;
|
||||
$height = 150;
|
||||
$url = 'http://chart.apis.google.com/chart?' .
|
||||
'chs=' . $width . 'x' . $height .
|
||||
'&chd=t:' . implode(',', $views) .
|
||||
'&cht=lc' .
|
||||
'&chf=bg,s,00000000' .
|
||||
'&chxt=x,y,r' .
|
||||
'&chds=0,' . $topScale .
|
||||
'&chls=2.0&chxtc=2,-350' .
|
||||
'&chxl=0:|' . date_format(new DateTime('-30 days'), 'd M') . '|'
|
||||
. date_format(new DateTime('-15 days'), 'd M') . '|'
|
||||
. date_format(new DateTime(), 'd M') . '|1:|0|'
|
||||
. round($top / 2, 2) . '|' . $top
|
||||
. '|2:|min|average|max' .
|
||||
'&chxp=2,' . $min . ',' . $average . ',' . $max;
|
||||
|
||||
|
||||
$this->view_popularity = new media_adapter($url, $width, $height);
|
||||
|
||||
return $this->view_popularity;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return media
|
||||
*/
|
||||
public function get_refferer_popularity()
|
||||
{
|
||||
if (!is_null($this->refferer_popularity))
|
||||
return $this->refferer_popularity;
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$report = $user->ACL()->has_right_on_base(
|
||||
$this->get_base_id(), 'canreport');
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
if (!$report && !$registry->get('GV_google_api'))
|
||||
{
|
||||
$this->refferer_popularity = false;
|
||||
|
||||
return $this->refferer_popularity;
|
||||
}
|
||||
|
||||
$connsbas = connection::getPDOConnection($this->get_sbas_id());
|
||||
|
||||
$sql = 'SELECT count( id ) AS views, referrer
|
||||
FROM `log_view`
|
||||
WHERE record_id = :record_id
|
||||
AND date > ( NOW( ) - INTERVAL 1 MONTH )
|
||||
GROUP BY referrer ORDER BY referrer ASC';
|
||||
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute(array(':record_id' => $this->get_record_id()));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$referrers = array();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($row['referrer'] == 'NO REFERRER')
|
||||
$row['referrer'] = _('report::acces direct');
|
||||
if ($row['referrer'] == $registry->get('GV_ServerName') . 'prod/')
|
||||
$row['referrer'] = _('admin::monitor: module production');
|
||||
if ($row['referrer'] == $registry->get('GV_ServerName') . 'client/')
|
||||
$row['referrer'] = _('admin::monitor: module client');
|
||||
if (strpos($row['referrer'], $registry->get('GV_ServerName') . 'login/') !== false)
|
||||
$row['referrer'] = _('report:: page d\'accueil');
|
||||
if (strpos($row['referrer'], 'http://apps.cooliris.com/') !== false)
|
||||
$row['referrer'] = _('report:: visualiseur cooliris');
|
||||
|
||||
if (strpos($row['referrer'], $registry->get('GV_ServerName') . 'document/') !== false)
|
||||
{
|
||||
if (strpos($row['referrer'], '/view/') !== false)
|
||||
$row['referrer'] = _('report::presentation page preview');
|
||||
else
|
||||
$row['referrer'] = _('report::acces direct');
|
||||
}
|
||||
if (strpos($row['referrer'], $registry->get('GV_ServerName') . 'permalink/') !== false)
|
||||
{
|
||||
if (strpos($row['referrer'], '/view/') !== false)
|
||||
$row['referrer'] = _('report::presentation page preview');
|
||||
else
|
||||
$row['referrer'] = _('report::acces direct');
|
||||
}
|
||||
if (!isset($referrers[$row['referrer']]))
|
||||
$referrers[$row['referrer']] = 0;
|
||||
$referrers[$row['referrer']] += (int) $row['views'];
|
||||
}
|
||||
|
||||
$width = 550;
|
||||
$height = 100;
|
||||
|
||||
$url = 'http://chart.apis.google.com/chart?'
|
||||
. 'cht=p3&chf=bg,s,00000000&chd=t:'
|
||||
. implode(',', $referrers)
|
||||
. '&chs=' . $width . 'x' . $height
|
||||
. '&chl='
|
||||
. urlencode(implode('|', array_keys($referrers))) . '';
|
||||
|
||||
$this->refferer_popularity = new media_adapter($url, $width, $height);
|
||||
|
||||
return $this->refferer_popularity;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return media
|
||||
*/
|
||||
public function get_download_popularity()
|
||||
{
|
||||
|
||||
if (!is_null($this->download_popularity))
|
||||
return $this->download_popularity;
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$registry = $appbox->get_registry();
|
||||
$report = $user->ACL()->has_right_on_base(
|
||||
$this->get_base_id(), 'canreport');
|
||||
|
||||
$ret = false;
|
||||
if (!$report && !$registry->get('GV_google_api'))
|
||||
{
|
||||
$this->download_popularity = false;
|
||||
|
||||
return $this->download_popularity;
|
||||
}
|
||||
|
||||
$views = $dwnls = array();
|
||||
$top = 1;
|
||||
$day = 30;
|
||||
$min = 0;
|
||||
$average = 0;
|
||||
|
||||
while ($day >= 0)
|
||||
{
|
||||
|
||||
$datetime = new DateTime('-' . $day . ' days');
|
||||
$date = date_format($datetime, 'Y-m-d');
|
||||
$views[$date] = $dwnls[$date] = 0;
|
||||
$day--;
|
||||
}
|
||||
|
||||
$sql = 'SELECT count(d.id) as dwnl, DATE(d.date) as datee
|
||||
FROM `log_docs` d, log l
|
||||
WHERE action="download"
|
||||
AND log_id=l.id
|
||||
AND record_id= :record_id
|
||||
AND d.date > (NOW() - INTERVAL 1 MONTH)
|
||||
AND site= :site
|
||||
GROUP BY datee ORDER BY datee ASC';
|
||||
|
||||
$connsbas = connection::getPDOConnection($this->get_sbas_id());
|
||||
$stmt = $connsbas->prepare($sql);
|
||||
$stmt->execute(
|
||||
array(
|
||||
':record_id' => $this->get_record_id(),
|
||||
':site' => $registry->get('GV_sit')
|
||||
)
|
||||
);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$top = 10;
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if (isset($dwnls[$row['datee']]))
|
||||
{
|
||||
$dwnls[$row['datee']] = (int) $row['dwnl'];
|
||||
$top = max(((int) $row['dwnl'] + 10), $top);
|
||||
}
|
||||
}
|
||||
|
||||
$width = 250;
|
||||
$height = 150;
|
||||
$url = 'http://chart.apis.google.com/chart?' .
|
||||
'chs=' . $width . 'x' . $height .
|
||||
'&chd=t:' . implode(',', $dwnls) .
|
||||
'&cht=lc' .
|
||||
'&chf=bg,s,00000000' .
|
||||
'&chxt=x,y' .
|
||||
'&chds=0,' . $top .
|
||||
'&chxl=0:|' . date_format(new DateTime('-30 days'), 'd M') . '|'
|
||||
. date_format(new DateTime('-15 days'), 'd M') . '|'
|
||||
. date_format(new DateTime(), 'd M') . '|1:|0|'
|
||||
. round($top / 2) . '|' . $top . '';
|
||||
|
||||
$ret = new media_adapter($url, $width, $height);
|
||||
$this->download_popularity = $ret;
|
||||
|
||||
return $this->download_popularity;
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
class record_video extends record
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user