mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
V 3.5 RC 1
This commit is contained in:
38
lib/classes/databox/Field/DCES/Contributor.class.php
Normal file
38
lib/classes/databox/Field/DCES/Contributor.class.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Contributor extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Contributor';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'An entity responsible for making contributions
|
||||
to the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#contributor';
|
||||
|
||||
}
|
39
lib/classes/databox/Field/DCES/Coverage.class.php
Normal file
39
lib/classes/databox/Field/DCES/Coverage.class.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Coverage extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Coverage';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'The spatial or temporal topic of the resource,
|
||||
the spatial applicability of the resource,
|
||||
or the jurisdiction under which the resource
|
||||
is relevant.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#coverage';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Creator.class.php
Normal file
37
lib/classes/databox/Field/DCES/Creator.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Creator extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Creator';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'An entity primarily responsible
|
||||
for making the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#creator';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Date.class.php
Normal file
37
lib/classes/databox/Field/DCES/Date.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Date extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Date';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'A point or period of time associated with an event
|
||||
in the lifecycle of the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#date';
|
||||
}
|
36
lib/classes/databox/Field/DCES/Description.class.php
Normal file
36
lib/classes/databox/Field/DCES/Description.class.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Description extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Description';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'An account of the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#description';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Format.class.php
Normal file
37
lib/classes/databox/Field/DCES/Format.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Format extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Format';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'The file format, physical medium,
|
||||
or dimensions of the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#format';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Identifier.class.php
Normal file
37
lib/classes/databox/Field/DCES/Identifier.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Identifier extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Identifier';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'An unambiguous reference to the resource
|
||||
within a given context.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#identifier';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Language.class.php
Normal file
37
lib/classes/databox/Field/DCES/Language.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Language extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Language';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'A language of the resource.
|
||||
(see [RFC4646] http://www.ietf.org/rfc/rfc4646.txt)';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#language';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Publisher.class.php
Normal file
37
lib/classes/databox/Field/DCES/Publisher.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Publisher extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Publisher';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'An entity responsible for making the resource
|
||||
available.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#publisher';
|
||||
}
|
36
lib/classes/databox/Field/DCES/Relation.class.php
Normal file
36
lib/classes/databox/Field/DCES/Relation.class.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Relation extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Relation';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'A related resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#relation';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Rights.class.php
Normal file
37
lib/classes/databox/Field/DCES/Rights.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Rights extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Rights';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'Information about rights held
|
||||
in and over the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#rights';
|
||||
}
|
37
lib/classes/databox/Field/DCES/Source.class.php
Normal file
37
lib/classes/databox/Field/DCES/Source.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Source extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Source';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'A related resource from which
|
||||
the described resource is derived.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#source';
|
||||
}
|
36
lib/classes/databox/Field/DCES/Subject.class.php
Normal file
36
lib/classes/databox/Field/DCES/Subject.class.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Subject extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Subject';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'The topic of the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#subject';
|
||||
}
|
36
lib/classes/databox/Field/DCES/Title.class.php
Normal file
36
lib/classes/databox/Field/DCES/Title.class.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Title extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Title';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'A name given to the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#title';
|
||||
}
|
36
lib/classes/databox/Field/DCES/Type.class.php
Normal file
36
lib/classes/databox/Field/DCES/Type.class.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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 Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class databox_Field_DCES_Type extends databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'Type';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition = 'The nature or genre of the resource.';
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI = 'http://dublincore.org/documents/dces/#type';
|
||||
}
|
85
lib/classes/databox/Field/DCESAbstract.class.php
Normal file
85
lib/classes/databox/Field/DCESAbstract.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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Databox DCES
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
abstract class databox_Field_DCESAbstract
|
||||
{
|
||||
|
||||
const Contributor = 'Contributor';
|
||||
const Coverage = 'Coverage';
|
||||
const Creator = 'Creator';
|
||||
const Date = 'Date';
|
||||
const Description = 'Description';
|
||||
const Format = 'Format';
|
||||
const Identifier = 'Identifier';
|
||||
const Language = 'Language';
|
||||
const Publisher = 'Publisher';
|
||||
const Relation = 'Relation';
|
||||
const Rights = 'Rights';
|
||||
const Source = 'Source';
|
||||
const Subject = 'Subject';
|
||||
const Title = 'Title';
|
||||
const Type = 'Type';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $definition;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $URI;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_label()
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_definition()
|
||||
{
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_documentation_link()
|
||||
{
|
||||
return $this->URI;
|
||||
}
|
||||
|
||||
}
|
154
lib/classes/databox/cgu.class.php
Normal file
154
lib/classes/databox/cgu.class.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_cgu
|
||||
{
|
||||
public function __construct(databox $databox, $locale)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function askAgreement()
|
||||
{
|
||||
$terms = self::getUnvalidated();
|
||||
|
||||
$out = '';
|
||||
|
||||
foreach ($terms as $name => $term)
|
||||
{
|
||||
if (trim($term['terms']) == '')
|
||||
continue;
|
||||
|
||||
$out .= '<div style="display:none;" class="cgu-dialog" title="' . str_replace('"', '"', sprintf(_('cgus:: CGUs de la base %s'), $name)) . '">';
|
||||
|
||||
$out .= '<blockquote>' . $term['terms'] . '</blockquote>';
|
||||
$out .= '<div>' . _('cgus:: Pour continuer a utiliser lapplication, vous devez accepter les conditions precedentes') . '
|
||||
<input id="terms_of_use_' . $term['sbas_id'] . '" type="button" date="' . $term['date'] . '" class="cgus-accept" value="' . _('cgus :: accepter') . '"/>
|
||||
<input id="sbas_' . $term['sbas_id'] . '" type="button" class="cgus-cancel" value="' . _('cgus :: refuser') . '"/>
|
||||
</div>';
|
||||
$out .= '</div>';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function denyCgus($sbas_id)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
if (!$session->is_authenticated())
|
||||
|
||||
return '2';
|
||||
|
||||
$ret = '1';
|
||||
|
||||
try
|
||||
{
|
||||
$sql = 'DELETE FROM sbasusr WHERE sbas_id = :sbas_id AND usr_id = :usr_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':sbas_id' => $sbas_id, ':usr_id' => $session->get_usr_id()));
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$ret = '0';
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$sql = 'DELETE FROM basusr
|
||||
WHERE base_id IN (SELECT base_id FROM bas WHERE sbas_id = :sbas_id)
|
||||
AND usr_id = :usr_id';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':sbas_id' => $sbas_id, ':usr_id' => $session->get_usr_id()));
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$ret = '0';
|
||||
}
|
||||
|
||||
$session->logout();
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private static function getUnvalidated($home=false)
|
||||
{
|
||||
$terms = array();
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
try
|
||||
{
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$cgus = $databox->get_cgus();
|
||||
|
||||
if (!isset($cgus[Session_Handler::get_locale()]))
|
||||
throw new Exception('No CGus for this locale');
|
||||
$name = $databox->get_viewname();
|
||||
|
||||
$update = $cgus[Session_Handler::get_locale()]['updated_on'];
|
||||
$value = $cgus[Session_Handler::get_locale()]['value'];
|
||||
$userValidation = true;
|
||||
|
||||
if (!$home)
|
||||
{
|
||||
$userValidation = ($user->getPrefs('terms_of_use_' . $databox->get_sbas_id()) !== $update && trim($value) !== '');
|
||||
}
|
||||
|
||||
if ($userValidation)
|
||||
$terms[$name] = array('sbas_id' => $databox->get_sbas_id(), 'terms' => $value, 'date' => $update);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $terms;
|
||||
}
|
||||
|
||||
public static function getHome()
|
||||
{
|
||||
$terms = self::getUnvalidated(true);
|
||||
|
||||
$out = '';
|
||||
|
||||
foreach ($terms as $name => $term)
|
||||
{
|
||||
if (trim($term['terms']) == '')
|
||||
continue;
|
||||
|
||||
if ($out != '')
|
||||
$out .= '<hr/>';
|
||||
|
||||
$out .= '<div><h1 style="text-align:center;">' . str_replace('"', '"', sprintf(_('cgus:: CGUs de la base %s'), $name)) . '</h1>';
|
||||
|
||||
$out .= '<blockquote>' . $term['terms'] . '</blockquote>';
|
||||
|
||||
$out .= '</div>';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
}
|
123
lib/classes/databox/descriptionStructure.class.php
Normal file
123
lib/classes/databox/descriptionStructure.class.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_descriptionStructure implements IteratorAggregate
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $elements = array();
|
||||
/**
|
||||
* Cache array for the get element by name function
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $cache_name_id = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_field
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->elements);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_field $field
|
||||
* @return databox_descriptionStructure
|
||||
*/
|
||||
public function add_element(databox_field $field)
|
||||
{
|
||||
$this->elements[$field->get_id()] = $field;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_field $field
|
||||
* @return databox_descriptionStructure
|
||||
*/
|
||||
public function remove_element(databox_field $field)
|
||||
{
|
||||
if (isset($this->elements[$field->get_id()]))
|
||||
unset($this->elements[$field->get_id()]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_elements()
|
||||
{
|
||||
return $this->elements;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <type> $name
|
||||
* @return databox_field
|
||||
*/
|
||||
public function get_element($id)
|
||||
{
|
||||
if (!isset($this->elements[$id]))
|
||||
throw new Exception_Databox_FieldNotFound ();
|
||||
|
||||
return $this->elements[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @return databox_field
|
||||
*/
|
||||
public function get_element_by_name($name)
|
||||
{
|
||||
if (isset($this->cache_name_id[$name]))
|
||||
|
||||
return $this->elements[$this->cache_name_id[$name]];
|
||||
|
||||
foreach ($this->elements as $id => $meta)
|
||||
{
|
||||
if ($meta->get_name() === $name)
|
||||
{
|
||||
$this->cache_name_id[$name] = $id;
|
||||
|
||||
return $meta;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $id
|
||||
* @return boolean
|
||||
*/
|
||||
public function isset_element($id)
|
||||
{
|
||||
return isset($this->elements[$id]);
|
||||
}
|
||||
|
||||
}
|
902
lib/classes/databox/field.class.php
Normal file
902
lib/classes/databox/field.class.php
Normal file
@@ -0,0 +1,902 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_field implements cache_cacheableInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var databox
|
||||
*/
|
||||
protected $databox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $indexable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $readonly;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $required;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $multi;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $report;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $tbranch;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $separator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $thumbtitle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $regdate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $regdesc;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var <type>
|
||||
*/
|
||||
protected $regname;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $sbas_id;
|
||||
protected static $_instance = array();
|
||||
protected $dces_element;
|
||||
|
||||
const TYPE_TEXT = "text";
|
||||
const TYPE_DATE = "date";
|
||||
const TYPE_NUMBER = "number";
|
||||
|
||||
/**
|
||||
* http://dublincore.org/documents/dces/
|
||||
*/
|
||||
const DCES_TITLE = 'Title';
|
||||
const DCES_CREATOR = 'Creator';
|
||||
const DCES_SUBJECT = 'Subject';
|
||||
const DCES_DESCRIPTION = 'Description';
|
||||
const DCES_PUBLISHER = 'Publisher';
|
||||
const DCES_CONTRIBUTOR = 'Contributor';
|
||||
const DCES_DATE = 'Date';
|
||||
const DCES_TYPE = 'Type';
|
||||
const DCES_FORMAT = 'Format';
|
||||
const DCES_IDENTIFIER = 'Identifier';
|
||||
const DCES_SOURCE = 'Source';
|
||||
const DCES_LANGUAGE = 'Language';
|
||||
const DCES_RELATION = 'Relation';
|
||||
const DCES_COVERAGE = 'Coverage';
|
||||
const DCES_RIGHTS = 'Rights';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
* @param <type> $id
|
||||
* @return databox_field
|
||||
*/
|
||||
protected function __construct(databox &$databox, $id)
|
||||
{
|
||||
$this->set_databox($databox);
|
||||
$this->sbas_id = $databox->get_sbas_id();
|
||||
|
||||
$connbas = $this->get_connection();
|
||||
|
||||
$sql = "SELECT `regdate`, `regdesc`, `regname`, `thumbtitle`, `separator`
|
||||
, `dces_element`, `tbranch`, `type`, `report`, `multi`, `required`
|
||||
, `readonly`, `indexable`, `name`, `src`
|
||||
FROM metadatas_structure WHERE id=:id";
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':id' => $id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->id = (int) $id;
|
||||
$this->source = self::load_class_from_xpath($row['src']);
|
||||
$this->name = $row['name'];
|
||||
$this->indexable = !!$row['indexable'];
|
||||
$this->readonly = !!$row['readonly'];
|
||||
$this->required = !!$row['required'];
|
||||
$this->multi = !!$row['multi'];
|
||||
$this->report = !!$row['report'];
|
||||
$this->type = $row['type'];
|
||||
$this->tbranch = $row['tbranch'];
|
||||
if ($row['dces_element'])
|
||||
{
|
||||
$dc_class = 'databox_Field_DCES_' . $row['dces_element'];
|
||||
$this->dces_element = new $dc_class();
|
||||
}
|
||||
|
||||
if (!$this->multi)
|
||||
{
|
||||
$separator = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
$separator = $row['separator'];
|
||||
|
||||
if (strpos($separator, ';') === false)
|
||||
$separator .= ';';
|
||||
}
|
||||
|
||||
$this->separator = $separator;
|
||||
$this->thumbtitle = $row['thumbtitle'];
|
||||
|
||||
$this->regdesc = !!$row['regdesc'];
|
||||
$this->regname = !!$row['regname'];
|
||||
$this->regdate = !!$row['regdate'];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
* @param int $id
|
||||
* @return databox_field
|
||||
*/
|
||||
public static function get_instance(databox &$databox, $id)
|
||||
{
|
||||
$cache_key = 'field_' . $id;
|
||||
$instance_id = $databox->get_sbas_id() . '_' . $id;
|
||||
if (!isset(self::$_instance[$instance_id]) || (self::$_instance[$instance_id] instanceof self) === false)
|
||||
{
|
||||
try
|
||||
{
|
||||
self::$_instance[$instance_id] = $databox->get_data_from_cache($cache_key);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
self::$_instance[$instance_id] = new self($databox, $id);
|
||||
$databox->set_data_to_cache(self::$_instance[$instance_id], $cache_key);
|
||||
}
|
||||
}
|
||||
|
||||
return self::$_instance[$instance_id];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
*/
|
||||
public function set_databox(databox &$databox)
|
||||
{
|
||||
$this->databox = $databox;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return connection_pdo
|
||||
*/
|
||||
public function get_connection()
|
||||
{
|
||||
return $this->databox->get_connection();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox
|
||||
*/
|
||||
public function get_databox()
|
||||
{
|
||||
return $this->databox;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
caption_field::delete_all_metadatas($this);
|
||||
|
||||
$connbas = $this->get_connection();
|
||||
$sql = 'DELETE FROM metadatas_structure WHERE id = :id';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(':id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_field
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$connbas = $this->get_connection();
|
||||
|
||||
$sql = 'UPDATE metadatas_structure SET
|
||||
`name` = :name,
|
||||
`src` = :source,
|
||||
`indexable` = :indexable,
|
||||
`readonly` = :readonly,
|
||||
`required` = :required,
|
||||
`separator` = :separator,
|
||||
`multi` = :multi,
|
||||
`report` = :report,
|
||||
`type` = :type,
|
||||
`tbranch` = :tbranch,
|
||||
`thumbtitle` = :thumbtitle
|
||||
WHERE id = :id';
|
||||
|
||||
$params = array(
|
||||
':name' => $this->name,
|
||||
':source' => $this->source->get_source(),
|
||||
':indexable' => $this->indexable ? '1' : '0',
|
||||
':readonly' => $this->readonly ? '1' : '0',
|
||||
':required' => $this->required ? '1' : '0',
|
||||
':separator' => $this->separator,
|
||||
':multi' => $this->multi ? '1' : '0',
|
||||
':report' => $this->report ? '1' : '0',
|
||||
':type' => $this->type,
|
||||
':tbranch' => $this->tbranch,
|
||||
':thumbtitle' => $this->thumbtitle,
|
||||
':id' => $this->id
|
||||
);
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
$xp_struct = $this->databox->get_xpath_structure();
|
||||
|
||||
$nodes = $xp_struct->query(
|
||||
'/record/description/*[@meta_id=' . $this->id . ']'
|
||||
);
|
||||
|
||||
if ($nodes->length == 0)
|
||||
{
|
||||
$meta = $dom_struct->createElement($this->name);
|
||||
$nodes_parent = $xp_struct->query('/record/description');
|
||||
$nodes_parent->item(0)->appendChild($meta);
|
||||
}
|
||||
else
|
||||
{
|
||||
$meta = $nodes->item(0);
|
||||
|
||||
$current_name = $meta->nodeName;
|
||||
if ($this->name != $meta->nodeName)
|
||||
{
|
||||
$old_meta = $meta;
|
||||
$meta = $dom_struct->createElement($this->name);
|
||||
$nodes_parent = $xp_struct->query('/record/description');
|
||||
$nodes_parent->item(0)->replaceChild($meta, $old_meta);
|
||||
}
|
||||
}
|
||||
$meta->setAttribute('src', $this->source->get_source());
|
||||
$meta->setAttribute('index', $this->indexable ? '1' : '0');
|
||||
$meta->setAttribute('readonly', $this->readonly ? '1' : '0');
|
||||
$meta->setAttribute('required', $this->required ? '1' : '0');
|
||||
$meta->setAttribute('multi', $this->multi ? '1' : '0');
|
||||
$meta->setAttribute('report', $this->report ? '1' : '0');
|
||||
$meta->setAttribute('type', $this->type);
|
||||
$meta->setAttribute('tbranch', $this->tbranch);
|
||||
if ($this->multi)
|
||||
{
|
||||
$meta->setAttribute('separator', $this->separator);
|
||||
}
|
||||
$meta->setAttribute('thumbtitle', $this->thumbtitle);
|
||||
$meta->setAttribute('meta_id', $this->id);
|
||||
|
||||
$this->delete_data_from_cache();
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_name($name)
|
||||
{
|
||||
$unicode_processor = new unicode();
|
||||
$name = $unicode_processor->remove_nonazAZ09($name, false, false);
|
||||
$name = $unicode_processor->remove_first_digits($name);
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $xpath
|
||||
* @return metadata_Abstract
|
||||
*/
|
||||
public static function load_class_from_xpath($xpath)
|
||||
{
|
||||
if (trim($xpath) === '')
|
||||
$classname = 'metadata_description_nosource';
|
||||
else
|
||||
$classname = 'metadata_description_' . str_replace(
|
||||
array('/rdf:RDF/rdf:Description/', ':', '-'), array('', '_', ''), $xpath
|
||||
);
|
||||
|
||||
if (!class_exists($classname))
|
||||
throw new Exception_Databox_metadataDescriptionNotFound();
|
||||
|
||||
return new $classname();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $source
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_source($source)
|
||||
{
|
||||
$this->source = self::load_class_from_xpath($source);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return metadata_Abstract
|
||||
*/
|
||||
public function get_source()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_Field_DCESAbstract
|
||||
*/
|
||||
public function get_dces_element()
|
||||
{
|
||||
return $this->dces_element;
|
||||
}
|
||||
|
||||
public function set_dces_element(databox_Field_DCESAbstract $DCES_element = null)
|
||||
{
|
||||
$sql = 'UPDATE metadatas_structure
|
||||
SET dces_element = :dces_element WHERE id = :id';
|
||||
|
||||
$connbas = $this->get_connection();
|
||||
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute(array(
|
||||
':dces_element' => $DCES_element ? $DCES_element->get_label() : null
|
||||
, ':id' => $this->id
|
||||
));
|
||||
$stmt->closeCursor();
|
||||
$this->dces_element = $DCES_element;
|
||||
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bool
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_indexable($bool)
|
||||
{
|
||||
$this->indexable = !!$bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bool
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_readonly($readonly)
|
||||
{
|
||||
$this->readonly = !!$readonly;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bool
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_required($required)
|
||||
{
|
||||
$this->required = !!$required;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bool
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_multi($multi)
|
||||
{
|
||||
$this->multi = !!$multi;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $bool
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_report($report)
|
||||
{
|
||||
$this->report = !!$report;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $type
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_type($type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $type
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_tbranch($branch)
|
||||
{
|
||||
$this->tbranch = $branch;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $type
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_separator($separator)
|
||||
{
|
||||
$this->separator = $separator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $type
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_thumbtitle($value)
|
||||
{
|
||||
$this->thumbtitle = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_regdate()
|
||||
{
|
||||
$this->set_reg_attr('date');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_regdesc()
|
||||
{
|
||||
$this->set_reg_attr('desc');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_field
|
||||
*/
|
||||
public function set_regname()
|
||||
{
|
||||
$this->set_reg_attr('name');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $attr
|
||||
* @return databox_field
|
||||
*/
|
||||
protected function set_reg_attr($attr)
|
||||
{
|
||||
try
|
||||
{
|
||||
$sql = 'UPDATE metadatas_structure SET reg' . $attr . ' = null';
|
||||
|
||||
$stmt = $this->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = 'UPDATE metadatas_structure SET reg' . $attr . '= 1 WHERE id= :id';
|
||||
|
||||
$stmt = $this->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_regname()
|
||||
{
|
||||
return $this->regname;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_regdesc()
|
||||
{
|
||||
return $this->regdesc;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_regdate()
|
||||
{
|
||||
return $this->regdate;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_thumbtitle()
|
||||
{
|
||||
return $this->thumbtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_tbranch()
|
||||
{
|
||||
return $this->tbranch;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_separator()
|
||||
{
|
||||
return $this->separator;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_indexable()
|
||||
{
|
||||
return $this->indexable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_readonly()
|
||||
{
|
||||
return $this->readonly;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_required()
|
||||
{
|
||||
return $this->required;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_multi()
|
||||
{
|
||||
return $this->multi;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_distinct()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_report()
|
||||
{
|
||||
return $this->report;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_metadata_source()
|
||||
{
|
||||
return $this->source->get_source();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_metadata_namespace()
|
||||
{
|
||||
return $this->source->get_namespace();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_metadata_tagname()
|
||||
{
|
||||
return $this->source->get_tagname();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true is the field is unknown
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_on_error()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function create(databox $databox, $name)
|
||||
{
|
||||
$sorter = 0;
|
||||
|
||||
$unicode_processor = new unicode();
|
||||
|
||||
$name = $unicode_processor->remove_nonazAZ09($name, false, false);
|
||||
$name = $unicode_processor->remove_first_digits($name);
|
||||
|
||||
$sql = 'SELECT (MAX(sorter) + 1) as sorter FROM metadatas_structure';
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
$sorter = (int) $row['sorter'];
|
||||
|
||||
$sql = "INSERT INTO metadatas_structure
|
||||
(`id`, `name`, `src`, `readonly`, `indexable`, `type`, `tbranch`,
|
||||
`thumbtitle`, `multi`, `regname`, `regdesc`, `regdate` ,
|
||||
`report`, `sorter`)
|
||||
VALUES (null, :name, '', 0, 1, 'text', '',
|
||||
null, 0, null, null, null,
|
||||
1, :sorter)";
|
||||
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':name' => $name, ':sorter' => $sorter));
|
||||
$id = $databox->get_connection()->lastInsertId();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$databox->delete_data_from_cache(databox::CACHE_META_STRUCT);
|
||||
|
||||
return self::get_instance($databox, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
$vars = array();
|
||||
foreach ($this as $key => $value)
|
||||
{
|
||||
if (in_array($key, array('databox')))
|
||||
continue;
|
||||
$vars[] = $key;
|
||||
}
|
||||
|
||||
return $vars;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
$databox = databox::get_instance($this->sbas_id);
|
||||
$this->set_databox($databox);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return string
|
||||
*/
|
||||
public function get_cache_key($option = null)
|
||||
{
|
||||
return 'field_' . $this->get_id() . ($option ? $option . '_' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data_from_cache($option = null)
|
||||
{
|
||||
return $this->databox->get_data_from_cache($this->get_cache_key($option));
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $option
|
||||
* @param int $duration
|
||||
* @return caption_field
|
||||
*/
|
||||
public function set_data_to_cache($value, $option = null, $duration = 0)
|
||||
{
|
||||
return $this->databox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the cache_cacheableInterface
|
||||
*
|
||||
* @param string $option
|
||||
* @return caption_field
|
||||
*/
|
||||
public function delete_data_from_cache($option = null)
|
||||
{
|
||||
return $this->databox->delete_data_from_cache($this->get_cache_key($option));
|
||||
}
|
||||
|
||||
}
|
95
lib/classes/databox/fieldUnknown.class.php
Normal file
95
lib/classes/databox/fieldUnknown.class.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_fieldUnknown extends databox_field
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
* @param int $id
|
||||
* @return databox_fieldUnknown
|
||||
*/
|
||||
public function __construct(databox $databox, $id)
|
||||
{
|
||||
$this->set_databox($databox);
|
||||
$this->sbas_id = $databox->get_sbas_id();
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
* @param int $id
|
||||
* @return databox_fieldUnknown
|
||||
*/
|
||||
public static function get_instance(databox &$databox, $id)
|
||||
{
|
||||
$cache_key = 'field_' . $id;
|
||||
$instance_id = $databox->get_sbas_id() . '_' . $id;
|
||||
if (!isset(self::$_instance[$instance_id]) || (self::$_instance[$instance_id] instanceof self) === false)
|
||||
{
|
||||
try
|
||||
{
|
||||
self::$_instance[$instance_id] = $databox->get_data_from_cache($cache_key);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
self::$_instance[$instance_id] = new self($databox, $id);
|
||||
$databox->set_data_to_cache(self::$_instance[$instance_id], $cache_key);
|
||||
}
|
||||
}
|
||||
|
||||
return self::$_instance[$instance_id];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_metadata_source()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_metadata_namespace()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_metadata_tagname()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return tru because the field is unknown
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_on_error()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
582
lib/classes/databox/status.class.php
Normal file
582
lib/classes/databox/status.class.php
Normal file
@@ -0,0 +1,582 @@
|
||||
<?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 databox_status
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
private static $_status = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected static $_statuses;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
private $status = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $path = '';
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $url = '';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $sbas_id
|
||||
* @return status
|
||||
*/
|
||||
private function __construct($sbas_id)
|
||||
{
|
||||
|
||||
$this->status = array();
|
||||
|
||||
$path = $url = false;
|
||||
|
||||
$sbas_params = phrasea::sbas_params();
|
||||
$registry = registry::get_instance();
|
||||
|
||||
if (!isset($sbas_params[$sbas_id]))
|
||||
|
||||
return;
|
||||
|
||||
$path = $this->path = $registry->get('GV_RootPath') . "config/status/" . urlencode($sbas_params[$sbas_id]["host"]) . "-" . urlencode($sbas_params[$sbas_id]["port"]) . "-" . urlencode($sbas_params[$sbas_id]["dbname"]);
|
||||
$url = $this->url = "/custom/status/" . urlencode($sbas_params[$sbas_id]["host"]) . "-" . urlencode($sbas_params[$sbas_id]["port"]) . "-" . urlencode($sbas_params[$sbas_id]["dbname"]);
|
||||
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
$xmlpref = $databox->get_structure();
|
||||
$sxe = simplexml_load_string($xmlpref);
|
||||
|
||||
if ($sxe)
|
||||
{
|
||||
|
||||
foreach ($sxe->statbits->bit as $sb)
|
||||
{
|
||||
$bit = (int) ($sb["n"]);
|
||||
if ($bit < 4 && $bit > 63)
|
||||
continue;
|
||||
|
||||
$this->status[$bit]["name"] = (string) ($sb);
|
||||
$this->status[$bit]["labeloff"] = (string) $sb['labelOff'];
|
||||
$this->status[$bit]["labelon"] = (string) $sb['labelOn'];
|
||||
|
||||
$this->status[$bit]["img_off"] = false;
|
||||
$this->status[$bit]["img_on"] = false;
|
||||
|
||||
if (is_file($path . "-stat_" . $bit . "_0.gif"))
|
||||
{
|
||||
$this->status[$bit]["img_off"] = $url . "-stat_" . $bit . "_0.gif";
|
||||
$this->status[$bit]["path_off"] = $path . "-stat_" . $bit . "_0.gif";
|
||||
}
|
||||
if (is_file($path . "-stat_" . $bit . "_1.gif"))
|
||||
{
|
||||
$this->status[$bit]["img_on"] = $url . "-stat_" . $bit . "_1.gif";
|
||||
$this->status[$bit]["path_on"] = $path . "-stat_" . $bit . "_1.gif";
|
||||
}
|
||||
|
||||
$this->status[$bit]["searchable"] = isset($sb['searchable']) ? (int) $sb['searchable'] : 0;
|
||||
$this->status[$bit]["printable"] = isset($sb['printable']) ? (int) $sb['printable'] : 0;
|
||||
}
|
||||
}
|
||||
ksort($this->status);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function getStatus($sbas_id)
|
||||
{
|
||||
|
||||
if (!isset(self::$_status[$sbas_id]))
|
||||
self::$_status[$sbas_id] = new databox_status($sbas_id);
|
||||
|
||||
return self::$_status[$sbas_id]->status;
|
||||
}
|
||||
|
||||
public static function getDisplayStatus()
|
||||
{
|
||||
if (self::$_statuses)
|
||||
|
||||
return self::$_statuses;
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
$sbas_ids = $user->ACL()->get_granted_sbas();
|
||||
|
||||
$statuses = array();
|
||||
|
||||
foreach ($sbas_ids as $databox)
|
||||
{
|
||||
try
|
||||
{
|
||||
$statuses[$databox->get_sbas_id()] = $databox->get_statusbits();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
self::$_statuses = $statuses;
|
||||
|
||||
return self::$_statuses;
|
||||
}
|
||||
|
||||
public static function getSearchStatus()
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
$statuses = array();
|
||||
|
||||
$sbas_ids = $user->ACL()->get_granted_sbas();
|
||||
|
||||
foreach ($sbas_ids as $databox)
|
||||
{
|
||||
try
|
||||
{
|
||||
$statuses[$databox->get_sbas_id()] = $databox->get_statusbits();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$stats = array();
|
||||
|
||||
foreach ($statuses as $sbas_id => $status)
|
||||
{
|
||||
|
||||
$see_all = false;
|
||||
|
||||
if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
|
||||
$see_all = true;
|
||||
|
||||
foreach ($status as $bit => $props)
|
||||
{
|
||||
|
||||
if ($props['searchable'] == 0 && !$see_all)
|
||||
continue;
|
||||
|
||||
$set = false;
|
||||
if (isset($stats[$bit]))
|
||||
{
|
||||
foreach ($stats[$bit] as $k => $s_desc)
|
||||
{
|
||||
if (mb_strtolower($s_desc['labelon']) == mb_strtolower($props['labelon'])
|
||||
&& mb_strtolower($s_desc['labeloff']) == mb_strtolower($props['labeloff']))
|
||||
{
|
||||
$stats[$bit][$k]['sbas'][] = $sbas_id;
|
||||
$set = true;
|
||||
}
|
||||
}
|
||||
if (!$set)
|
||||
{
|
||||
$stats[$bit][] = array(
|
||||
'sbas' => array($sbas_id),
|
||||
'labeloff' => $props['labeloff'],
|
||||
'labelon' => $props['labelon'],
|
||||
'imgoff' => $props['img_off'],
|
||||
'imgon' => $props['img_on']
|
||||
);
|
||||
$set = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$set)
|
||||
{
|
||||
$stats[$bit] = array(
|
||||
array(
|
||||
'sbas' => array($sbas_id),
|
||||
'labeloff' => $props['labeloff'],
|
||||
'labelon' => $props['labelon'],
|
||||
'imgoff' => $props['img_off'],
|
||||
'imgon' => $props['img_on']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
public static function getPath($sbas_id)
|
||||
{
|
||||
|
||||
if (!isset(self::$_status[$sbas_id]))
|
||||
self::$_status[$sbas_id] = new databox_status($sbas_id);
|
||||
|
||||
return self::$_status[$sbas_id]->path;
|
||||
}
|
||||
|
||||
public static function getUrl($sbas_id)
|
||||
{
|
||||
|
||||
if (!isset(self::$_status[$sbas_id]))
|
||||
self::$_status[$sbas_id] = new databox_status($sbas_id);
|
||||
|
||||
return self::$_status[$sbas_id]->url;
|
||||
}
|
||||
|
||||
public static function deleteStatus($sbas_id, $bit)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
|
||||
|
||||
return false;
|
||||
|
||||
$status = self::getStatus($sbas_id);
|
||||
|
||||
if (isset($status[$bit]))
|
||||
{
|
||||
$connbas = connection::getPDOConnection($sbas_id);
|
||||
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
|
||||
$doc = $databox->get_dom_structure();
|
||||
if ($doc)
|
||||
{
|
||||
$xpath = $databox->get_xpath_structure();
|
||||
$entries = $xpath->query($q = "/record/statbits/bit[@n=" . $bit . "]");
|
||||
|
||||
foreach ($entries as $sbit)
|
||||
{
|
||||
if ($p = $sbit->previousSibling)
|
||||
{
|
||||
if ($p->nodeType == XML_TEXT_NODE && $p->nodeValue == "\n\t\t")
|
||||
$p->parentNode->removeChild($p);
|
||||
}
|
||||
if ($sbit->parentNode->removeChild($sbit))
|
||||
{
|
||||
$sql = 'UPDATE record SET status = status&(~(1<<' . $bit . '))';
|
||||
$stmt = $connbas->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
}
|
||||
|
||||
$databox->saveStructure($doc);
|
||||
|
||||
if (self::$_status[$sbas_id]->status[$bit]['img_off'])
|
||||
{
|
||||
unlink(self::$_status[$sbas_id]->status[$bit]['path_off']);
|
||||
}
|
||||
if (self::$_status[$sbas_id]->status[$bit]['img_on'])
|
||||
{
|
||||
unlink(self::$_status[$sbas_id]->status[$bit]['path_on']);
|
||||
}
|
||||
|
||||
unset(self::$_status[$sbas_id]->status[$bit]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function updateStatus($sbas_id, $bit, $properties)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
|
||||
|
||||
return false;
|
||||
|
||||
$status = self::getStatus($sbas_id);
|
||||
|
||||
$databox = $appbox->get_databox((int) $sbas_id);
|
||||
|
||||
$doc = $databox->get_dom_structure($sbas_id);
|
||||
if ($doc)
|
||||
{
|
||||
$xpath = $databox->get_xpath_structure($sbas_id);
|
||||
$entries = $xpath->query("/record/statbits");
|
||||
if ($entries->length == 0)
|
||||
{
|
||||
$statbits = $doc->documentElement->appendChild($doc->createElement("statbits"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$statbits = $entries->item(0);
|
||||
}
|
||||
|
||||
if ($statbits)
|
||||
{
|
||||
$entries = $xpath->query("/record/statbits/bit[@n=" . $bit . "]");
|
||||
|
||||
if ($entries->length >= 1)
|
||||
{
|
||||
foreach ($entries as $k => $sbit)
|
||||
{
|
||||
if ($p = $sbit->previousSibling)
|
||||
{
|
||||
if ($p->nodeType == XML_TEXT_NODE && $p->nodeValue == "\n\t\t")
|
||||
$p->parentNode->removeChild($p);
|
||||
}
|
||||
$sbit->parentNode->removeChild($sbit);
|
||||
}
|
||||
}
|
||||
|
||||
$sbit = $statbits->appendChild($doc->createElement("bit"));
|
||||
|
||||
if ($n = $sbit->appendChild($doc->createAttribute("n")))
|
||||
{
|
||||
$n->value = $bit;
|
||||
$sbit->appendChild($doc->createTextNode($properties['name']));
|
||||
}
|
||||
|
||||
if ($labOn = $sbit->appendChild($doc->createAttribute("labelOn")))
|
||||
{
|
||||
$labOn->value = $properties['labelon'];
|
||||
}
|
||||
|
||||
if ($searchable = $sbit->appendChild($doc->createAttribute("searchable")))
|
||||
{
|
||||
$searchable->value = $properties['searchable'];
|
||||
}
|
||||
|
||||
if ($printable = $sbit->appendChild($doc->createAttribute("printable")))
|
||||
{
|
||||
$printable->value = $properties['printable'];
|
||||
}
|
||||
|
||||
if ($labOff = $sbit->appendChild($doc->createAttribute("labelOff")))
|
||||
{
|
||||
$labOff->value = $properties['labeloff'];
|
||||
}
|
||||
}
|
||||
|
||||
$databox->saveStructure($doc);
|
||||
|
||||
self::$_status[$sbas_id]->status[$bit]["name"] = $properties['name'];
|
||||
self::$_status[$sbas_id]->status[$bit]["labelon"] = $properties['labelon'];
|
||||
self::$_status[$sbas_id]->status[$bit]["labeloff"] = $properties['labeloff'];
|
||||
self::$_status[$sbas_id]->status[$bit]["searchable"] = (int) $properties['searchable'];
|
||||
self::$_status[$sbas_id]->status[$bit]["printable"] = (int) $properties['printable'];
|
||||
|
||||
if (!isset(self::$_status[$sbas_id]->status[$bit]['img_on']))
|
||||
self::$_status[$sbas_id]->status[$bit]['img_on'] = false;
|
||||
if (!isset(self::$_status[$sbas_id]->status[$bit]['img_off']))
|
||||
self::$_status[$sbas_id]->status[$bit]['img_off'] = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function deleteIcon($sbas_id, $bit, $switch)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
|
||||
|
||||
return false;
|
||||
|
||||
$status = self::getStatus($sbas_id);
|
||||
|
||||
$switch = in_array($switch, array('on', 'off')) ? $switch : false;
|
||||
|
||||
if (!$switch)
|
||||
|
||||
return false;
|
||||
|
||||
if ($status[$bit]['img_' . $switch])
|
||||
{
|
||||
if (isset($status[$bit]['path_' . $switch]))
|
||||
unlink($status[$bit]['path_' . $switch]);
|
||||
|
||||
$status[$bit]['img_' . $switch] = false;
|
||||
unset($status[$bit]['path_' . $switch]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function updateIcon($sbas_id, $bit, $switch, $file)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
|
||||
$registry = registry::get_instance();
|
||||
|
||||
if (!$user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
|
||||
throw new Exception_Forbidden();
|
||||
|
||||
$switch = in_array($switch, array('on', 'off')) ? $switch : false;
|
||||
|
||||
if (!$switch)
|
||||
throw new Exception_InvalidArgument();
|
||||
|
||||
$status = self::getStatus($sbas_id);
|
||||
$url = self::getUrl($sbas_id);
|
||||
$path = self::getPath($sbas_id);
|
||||
if ($file['size'] >= 65535)
|
||||
throw new Exception_Upload_FileTooBig();
|
||||
|
||||
if ($file['error'] !== UPLOAD_ERR_OK)
|
||||
throw new Exception_Upload_Error();
|
||||
|
||||
self::deleteIcon($sbas_id, $bit, $switch);
|
||||
$name = "-stat_" . $bit . "_" . ($switch == 'on' ? '1' : '0') . ".gif";
|
||||
|
||||
if (!move_uploaded_file($file["tmp_name"], $path . $name))
|
||||
throw new Exception_Upload_CannotWriteFile();
|
||||
|
||||
$custom_path = $registry->get('GV_RootPath') . 'www/custom/status/';
|
||||
|
||||
if (!is_dir($custom_path))
|
||||
system_file::mkdir($custom_path);
|
||||
|
||||
copy($path . $name, $custom_path . basename($path . $name));
|
||||
self::$_status[$sbas_id]->status[$bit]['img_' . $switch] = $url . $name;
|
||||
self::$_status[$sbas_id]->status[$bit]['path_' . $switch] = $path . $name;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function operation_and($stat1, $stat2)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
|
||||
$status = '0';
|
||||
|
||||
$sql = 'select bin(0b' . trim($stat1) . ' & 0b' . trim($stat2) . ') as result';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$status = $row['result'];
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public static function operation_and_not($stat1, $stat2)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
|
||||
$status = '0';
|
||||
|
||||
$sql = 'select bin(0b' . trim($stat1) . ' & ~0b' . trim($stat2) . ') as result';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$status = $row['result'];
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public static function operation_or($stat1, $stat2)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
|
||||
$status = '0';
|
||||
|
||||
$sql = 'select bin(0b' . trim($stat1) . ' | 0b' . trim($stat2) . ') as result';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$status = $row['result'];
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public static function dec2bin($status)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
|
||||
$status = '0';
|
||||
|
||||
$sql = 'select bin(' . ((int) $status) . ') as result';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$status = $row['result'];
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public static function hex2bin($status)
|
||||
{
|
||||
$conn = connection::getPDOConnection();
|
||||
|
||||
$status = '0';
|
||||
|
||||
$sql = 'select bin(0x' . trim($status) . ') as result';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$status = $row['result'];
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
}
|
99
lib/classes/databox/subdef/audio.class.php
Normal file
99
lib/classes/databox/subdef/audio.class.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_audio extends databox_subdefAbstract implements databox_subdefInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $available_mediatypes = array('image', 'audio');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
switch ($this->current_mediatype)
|
||||
{
|
||||
case 'audio':
|
||||
$generated = $this->generate_audio($record, $dest_dir, $registry);
|
||||
break;
|
||||
case 'image':
|
||||
default:
|
||||
$generated = $this->generate_image($record, $dest_dir, $registry);
|
||||
break;
|
||||
}
|
||||
|
||||
return $generated;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_audio(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
$outfile = $this->get_newpathfile_name($record, $dest_dir, 'mp3');
|
||||
if (file_exists($outfile))
|
||||
unlink($outfile);
|
||||
|
||||
$adapter = new binaryAdapter_audio_resample($registry);
|
||||
$resampled = $adapter->execute($record->get_hd_file(), $outfile, $this->get_options());
|
||||
|
||||
if ($resampled instanceof system_file)
|
||||
{
|
||||
return $resampled;
|
||||
}
|
||||
throw new Exception('Unable to create image from video');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_image(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
$outfile = $this->get_newpathfile_name($record, $dest_dir, 'jpg');
|
||||
if (file_exists($outfile))
|
||||
unlink($outfile);
|
||||
|
||||
$adapter = new binaryAdapter_audio_previewExtract($registry);
|
||||
$image = $adapter->execute($record->get_hd_file(), $outfile, $this->get_options());
|
||||
|
||||
$adapter = new binaryAdapter_image_resize($registry);
|
||||
$image = $adapter->execute($image, $outfile, $this->get_options());
|
||||
|
||||
if ($image instanceof system_file)
|
||||
{
|
||||
return $image;
|
||||
}
|
||||
throw new Exception('Unable to create extract image from audio');
|
||||
}
|
||||
|
||||
}
|
183
lib/classes/databox/subdef/document.class.php
Normal file
183
lib/classes/databox/subdef/document.class.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_document extends databox_subdefAbstract implements databox_subdefInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $available_mediatypes = array('image', 'flexpaper');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
switch ($this->current_mediatype)
|
||||
{
|
||||
case 'flexpaper':
|
||||
$generated = $this->generate_flexpaper($record, $dest_dir, $registry);
|
||||
break;
|
||||
case 'image':
|
||||
default:
|
||||
$generated = $this->generate_image($record, $dest_dir, $registry);
|
||||
break;
|
||||
}
|
||||
|
||||
return $generated;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_flexpaper(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
$dest_dir = $this->get_newpathfile_name($record, $dest_dir, 'swf');
|
||||
$tmp_file = $registry->get('GV_RootPath') . 'tmp/tmp_file-doc2pdf' . time() . '.pdf';
|
||||
|
||||
$swf = $exception = false;
|
||||
|
||||
try
|
||||
{
|
||||
$pdf = $this->generate_pdf_from_doc($record, $tmp_file, $registry);
|
||||
$swf = $this->generate_swf_from_pdf($pdf, $dest_dir, $registry);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
if (is_file($tmp_file))
|
||||
unlink($tmp_file);
|
||||
|
||||
if ($swf instanceof system_file)
|
||||
{
|
||||
return $swf;
|
||||
}
|
||||
throw new Exception('Unable to convert document to swf : '
|
||||
. $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $pdf
|
||||
* @param string $pathdest
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_swf_from_pdf(system_file $pdf, $pathdest, registry &$registry)
|
||||
{
|
||||
$adapter = new binaryAdapter_document_toFlexpaperSwf($registry);
|
||||
$swf = $adapter->execute($pdf, $pathdest, $this->get_options());
|
||||
|
||||
if ($swf instanceof system_file)
|
||||
{
|
||||
return $swf;
|
||||
}
|
||||
throw new Exception('Unable to convert pdf to swf');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $pathdest
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_image(record_Interface &$record, $pathdest, registry &$registry)
|
||||
{
|
||||
$pathdest = $this->get_newpathfile_name($record, $pathdest, 'jpg');
|
||||
$tmp_file = $registry->get('GV_RootPath') . 'tmp/tmp_file-doc2pdf' . time() . '.pdf';
|
||||
|
||||
$image = $exception = false;
|
||||
|
||||
try
|
||||
{
|
||||
$pdf = $this->generate_pdf_from_doc($record, $tmp_file, $registry);
|
||||
$image = $this->generate_image_from_pdf($pdf, $pathdest, $registry);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
if (is_file($tmp_file))
|
||||
unlink($tmp_file);
|
||||
|
||||
if ($image instanceof system_file)
|
||||
{
|
||||
return $image;
|
||||
}
|
||||
throw new Exception('Unable to convert document to image : '
|
||||
. $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $tmp_file
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_pdf_from_doc(record_Interface &$record, $tmp_file, registry &$registry)
|
||||
{
|
||||
$origine = $record->get_hd_file();
|
||||
|
||||
if ($origine->get_mime() == 'application/pdf')
|
||||
|
||||
return $origine;
|
||||
|
||||
$adapter = new binaryAdapter_document_toPDF($registry);
|
||||
$converted = $adapter->execute($origine, $tmp_file, $this->get_options());
|
||||
|
||||
if ($converted instanceof system_file)
|
||||
{
|
||||
return $converted;
|
||||
}
|
||||
throw new Exception('Unable to convert document');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $pdf
|
||||
* @param string $pathdest
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_image_from_pdf(system_file $pdf, $pathdest, registry &$registry)
|
||||
{
|
||||
$adapter = new binaryAdapter_image_resize($registry);
|
||||
$image = $adapter->execute($pdf, $pathdest, $this->get_options());
|
||||
|
||||
if ($image instanceof system_file)
|
||||
{
|
||||
return $image;
|
||||
}
|
||||
throw new Exception('Unable to convert pdf to image');
|
||||
}
|
||||
|
||||
}
|
122
lib/classes/databox/subdef/flash.class.php
Normal file
122
lib/classes/databox/subdef/flash.class.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_flash extends databox_subdefAbstract implements databox_subdefInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $available_mediatypes = array('image');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
switch ($this->current_mediatype)
|
||||
{
|
||||
case 'image':
|
||||
default:
|
||||
$generated = $this->generate_image($record, $dest_dir, $registry);
|
||||
break;
|
||||
}
|
||||
|
||||
return $generated;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_image(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
$pathdest = $this->get_newpathfile_name($record, $dest_dir, 'jpg');
|
||||
$tmp_file = $registry->get('GV_RootPath') . 'tmp/tmp_file-doc2pdf' . time() . '.pdf';
|
||||
|
||||
$image = $exception = false;
|
||||
|
||||
try
|
||||
{
|
||||
$pdf = $this->generate_image_from_swf($record, $tmp_file, $registry);
|
||||
$image = $this->resize_image($pdf, $pathdest, $registry);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
if (is_file($tmp_file))
|
||||
unlink($tmp_file);
|
||||
|
||||
if ($image instanceof system_file)
|
||||
{
|
||||
return $image;
|
||||
}
|
||||
throw new Exception('Unable to convert document to image : '
|
||||
. $exception->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param <type> $dest
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_image_from_swf(record_Interface &$record, $dest, registry &$registry)
|
||||
{
|
||||
@unlink($dest);
|
||||
|
||||
$adapter = new binaryAdapter_flash_toimage($registry);
|
||||
$resized = $adapter->execute($record->get_hd_file(), $dest, $this->get_options());
|
||||
|
||||
if ($resized instanceof system_file)
|
||||
{
|
||||
return $resized;
|
||||
}
|
||||
throw new Exception('Unable to create resized copy');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $pathdest
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function resize_image(system_file $origine, $pathdest, registry &$registry)
|
||||
{
|
||||
$adapter = new binaryAdapter_image_resize($registry);
|
||||
$image = $adapter->execute($origine, $pathdest, $this->get_options());
|
||||
|
||||
if ($image instanceof system_file)
|
||||
{
|
||||
return $image;
|
||||
}
|
||||
throw new Exception('Unable to convert pdf to image');
|
||||
}
|
||||
|
||||
}
|
92
lib/classes/databox/subdef/image.class.php
Normal file
92
lib/classes/databox/subdef/image.class.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_image extends databox_subdefAbstract implements databox_subdefInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $available_mediatypes = array('image');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
switch ($this->current_mediatype)
|
||||
{
|
||||
case 'image':
|
||||
default:
|
||||
$generated = $this->generate_image($record, $dest_dir, $registry);
|
||||
break;
|
||||
}
|
||||
|
||||
return $generated;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_image(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
$binary_temp = false;
|
||||
$origine = $record->get_hd_file();
|
||||
|
||||
$outfile = $this->get_newpathfile_name($record, $dest_dir, 'jpg');
|
||||
if (file_exists($outfile))
|
||||
unlink($outfile);
|
||||
|
||||
try
|
||||
{
|
||||
$tmp_file = $registry->get('GV_RootPath') . 'tmp/preview' . time() . '.jpg';
|
||||
|
||||
$adapter = new binaryAdapter_rawImage_previewExtract($registry);
|
||||
$origine = $adapter->execute($origine, $tmp_file, $this->get_options());
|
||||
$this->log('extracted a preview from the raw file');
|
||||
$binary_temp = $origine->getPathname();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->log($e->getMessage());
|
||||
}
|
||||
|
||||
$adapter = new binaryAdapter_image_resize($registry);
|
||||
$resized = $adapter->execute($origine, $outfile, $this->get_options());
|
||||
|
||||
if ($binary_temp)
|
||||
{
|
||||
unlink($binary_temp);
|
||||
}
|
||||
|
||||
if ($resized instanceof system_file)
|
||||
{
|
||||
return $resized;
|
||||
}
|
||||
throw new Exception('Unable to create resized copy');
|
||||
}
|
||||
|
||||
}
|
42
lib/classes/databox/subdef/mediatype/audio.class.php
Normal file
42
lib/classes/databox/subdef/mediatype/audio.class.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_mediatype_audio extends databox_subdef_mediatypeAbstract implements databox_subdef_mediatypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_subdef_mediatype_audio
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_subdefAbstract $subdef
|
||||
* @return array
|
||||
*/
|
||||
public function get_available_options(databox_subdefAbstract $subdef)
|
||||
{
|
||||
$options = array();
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
42
lib/classes/databox/subdef/mediatype/flexpaper.class.php
Normal file
42
lib/classes/databox/subdef/mediatype/flexpaper.class.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_mediatype_flexpaper extends databox_subdef_mediatypeAbstract implements databox_subdef_mediatypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_subdef_mediatype_flexpaper
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_subdefAbstract $subdef
|
||||
* @return array
|
||||
*/
|
||||
public function get_available_options(databox_subdefAbstract $subdef)
|
||||
{
|
||||
$options = array();
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
75
lib/classes/databox/subdef/mediatype/gif.class.php
Normal file
75
lib/classes/databox/subdef/mediatype/gif.class.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_mediatype_gif extends databox_subdef_mediatypeAbstract implements databox_subdef_mediatypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $size;
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $delay;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $size
|
||||
* @param int $delay
|
||||
* @return databox_subdef_mediatype_gif
|
||||
*/
|
||||
public function __construct($size=null, $delay=null)
|
||||
{
|
||||
$this->size = $size;
|
||||
$this->delay = $delay;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_subdefAbstract $subdef
|
||||
* @return array
|
||||
*/
|
||||
public function get_available_options(databox_subdefAbstract $subdef)
|
||||
{
|
||||
$options = array(
|
||||
'size' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => 20,
|
||||
'max' => 500,
|
||||
'value' => $this->size,
|
||||
'default' => 200
|
||||
),
|
||||
'delay' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => 1,
|
||||
'max' => 3,
|
||||
'value' => $this->delay,
|
||||
'default' => 1
|
||||
)
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
104
lib/classes/databox/subdef/mediatype/image.class.php
Normal file
104
lib/classes/databox/subdef/mediatype/image.class.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_mediatype_image extends databox_subdef_mediatypeAbstract implements databox_subdef_mediatypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $size;
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $resolution;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $strip;
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $quality;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $size
|
||||
* @param int $resolution
|
||||
* @param boolean $strip
|
||||
* @param int $quality
|
||||
* @return databox_subdef_mediatype_image
|
||||
*/
|
||||
public function __construct($size=null, $resolution=null, $strip=null, $quality=null)
|
||||
{
|
||||
|
||||
$this->size = $size;
|
||||
$this->resolution = $resolution;
|
||||
$this->strip = $strip;
|
||||
$this->quality = $quality;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_subdefAbstract $subdef
|
||||
* @return array
|
||||
*/
|
||||
public function get_available_options(databox_subdefAbstract $subdef)
|
||||
{
|
||||
|
||||
$options = array(
|
||||
'size' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => ($subdef->get_class() == 'thumbnail' ? 20 : 150),
|
||||
'max' => ($subdef->get_class() == 'thumbnail' ? 400 : 3000),
|
||||
'default' => ($subdef->get_class() == 'thumbnail' ? 200 : 800),
|
||||
'value' => $this->size
|
||||
),
|
||||
'resolution' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => 50,
|
||||
'max' => 300,
|
||||
'default' => 72,
|
||||
'value' => $this->resolution
|
||||
),
|
||||
'strip' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => ($subdef->get_class() == 'thumbnail'),
|
||||
'value' => $this->strip
|
||||
),
|
||||
'quality' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => 0,
|
||||
'max' => 100,
|
||||
'default' => 75,
|
||||
'value' => $this->quality
|
||||
)
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
132
lib/classes/databox/subdef/mediatype/video.class.php
Normal file
132
lib/classes/databox/subdef/mediatype/video.class.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_mediatype_video extends databox_subdef_mediatypeAbstract implements databox_subdef_mediatypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $fps;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $threads;
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $bitrate;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $v_codec;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $a_codec;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $size
|
||||
* @param int $fps
|
||||
* @param int $threads
|
||||
* @param int $bitrate
|
||||
* @param string $acodec
|
||||
* @param string $vcodec
|
||||
* @return databox_subdef_mediatype_video
|
||||
*/
|
||||
public function __construct($size=null, $fps=null, $threads=null, $bitrate=null, $acodec=null, $vcodec=null)
|
||||
{
|
||||
|
||||
$this->size = $size;
|
||||
$this->fps = $fps;
|
||||
$this->threads = $threads;
|
||||
$this->bitrate = $bitrate;
|
||||
$this->a_codec = $acodec;
|
||||
$this->v_codec = $vcodec;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_subdefAbstract $subdef
|
||||
* @return array
|
||||
*/
|
||||
public function get_available_options(databox_subdefAbstract $subdef)
|
||||
{
|
||||
$options = array(
|
||||
'size' => array(
|
||||
'type' => 'range',
|
||||
'step' => 16,
|
||||
'min' => 100,
|
||||
'max' => 1000,
|
||||
'value' => $this->size,
|
||||
'default' => 600
|
||||
),
|
||||
'fps' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => 1,
|
||||
'max' => 200,
|
||||
'value' => $this->fps,
|
||||
'default' => 20
|
||||
),
|
||||
'threads' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => 1,
|
||||
'max' => 16,
|
||||
'value' => $this->threads,
|
||||
'default' => 1
|
||||
),
|
||||
'bitrate' => array(
|
||||
'type' => 'range',
|
||||
'step' => 1,
|
||||
'min' => 100,
|
||||
'max' => 4000,
|
||||
'value' => $this->bitrate,
|
||||
'default' => '800'
|
||||
),
|
||||
'a_codec' => array(
|
||||
'type' => 'enum',
|
||||
'values' => array('faac', 'mp3'),
|
||||
'value' => $this->a_codec,
|
||||
'default' => 'faac'
|
||||
),
|
||||
'v_codec' => array(
|
||||
'type' => 'enum',
|
||||
'values' => array('libx264', 'flv'),
|
||||
'value' => $this->v_codec,
|
||||
'default' => 'libx264'
|
||||
)
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
38
lib/classes/databox/subdef/mediatypeAbstract.class.php
Normal file
38
lib/classes/databox/subdef/mediatypeAbstract.class.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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
|
||||
*/
|
||||
abstract class databox_subdef_mediatypeAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox_subdefAbstract $subdef
|
||||
* @return Array
|
||||
*/
|
||||
public function get_options(databox_subdefAbstract $subdef)
|
||||
{
|
||||
$options = array();
|
||||
$full_options = $this->get_available_options($subdef);
|
||||
foreach ($full_options as $opt_name => $values)
|
||||
{
|
||||
$options[$opt_name] = $values['value'];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
23
lib/classes/databox/subdef/mediatypeInterface.class.php
Normal file
23
lib/classes/databox/subdef/mediatypeInterface.class.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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 databox_subdef_mediatypeInterface
|
||||
{
|
||||
public function get_available_options(databox_subdefAbstract $subdef);
|
||||
|
||||
public function get_options(databox_subdefAbstract $subdef);
|
||||
}
|
162
lib/classes/databox/subdef/video.class.php
Normal file
162
lib/classes/databox/subdef/video.class.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdef_video extends databox_subdefAbstract implements databox_subdefInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $available_mediatypes = array('image', 'video', 'gif');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry)
|
||||
{
|
||||
switch ($this->current_mediatype)
|
||||
{
|
||||
case 'video':
|
||||
$generated = $this->generate_video($record, $dest_dir, $registry);
|
||||
break;
|
||||
case 'gif':
|
||||
$generated = $this->generate_gif($record, $dest_dir, $registry);
|
||||
break;
|
||||
case 'image':
|
||||
default:
|
||||
$generated = $this->generate_image($record, $dest_dir, $registry);
|
||||
break;
|
||||
}
|
||||
|
||||
return $generated;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_image(record_Interface $record, $dest_dir, registry $registry)
|
||||
{
|
||||
$outfile = $this->get_newpathfile_name($record, $dest_dir, 'jpg');
|
||||
if (file_exists($outfile))
|
||||
unlink($outfile);
|
||||
|
||||
$adapter = new binaryAdapter_video_toimage($registry);
|
||||
$resized = $adapter->execute($record->get_hd_file(), $outfile, $this->get_options());
|
||||
|
||||
if ($resized instanceof system_file)
|
||||
{
|
||||
return $resized;
|
||||
}
|
||||
throw new Exception('Unable to create image from video');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_video(record_Interface $record, $dest_dir, registry $registry)
|
||||
{
|
||||
$outfile = $this->get_newpathfile_name($record, $dest_dir, 'mp4');
|
||||
|
||||
$temp = $this->generate_temporary_video($record, $registry);
|
||||
$resized = $this->make_progressive($temp, $outfile, $registry);
|
||||
unlink($temp->getPathname());
|
||||
|
||||
if ($resized instanceof system_file)
|
||||
{
|
||||
return $resized;
|
||||
}
|
||||
throw new Exception('Unable to create video');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_temporary_video(record_Interface $record, registry $registry)
|
||||
{
|
||||
$outfile = $registry->get('GV_RootPath') . 'tmp/tmp_video' . time() . '.mp4';
|
||||
|
||||
$adapter = new binaryAdapter_video_resize($registry);
|
||||
$resized = $adapter->execute($record->get_hd_file(), $outfile, $this->get_options());
|
||||
|
||||
if ($resized instanceof system_file)
|
||||
{
|
||||
return $resized;
|
||||
}
|
||||
throw new Exception('Unable to create resized video');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param system_file $origine
|
||||
* @param string $path_dest
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function make_progressive(system_file $origine, $path_dest, registry $registry)
|
||||
{
|
||||
if (file_exists($path_dest))
|
||||
unlink($path_dest);
|
||||
|
||||
$adapter = new binaryAdapter_video_progressive($registry);
|
||||
$resized = $adapter->execute($origine, $path_dest, $this->get_options());
|
||||
|
||||
if ($resized instanceof system_file)
|
||||
{
|
||||
return $resized;
|
||||
}
|
||||
throw new Exception('Unable make mp4 progressive');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param <type> $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
protected function generate_gif(record_Interface $record, $dest_dir, registry $registry)
|
||||
{
|
||||
$outfile = $this->get_newpathfile_name($record, $dest_dir, 'gif');
|
||||
if (file_exists($outfile))
|
||||
unlink($outfile);
|
||||
|
||||
$adapter = new binaryAdapter_video_gif($registry);
|
||||
$resized = $adapter->execute($record->get_hd_file(), $outfile, $this->get_options());
|
||||
|
||||
if ($resized instanceof system_file)
|
||||
{
|
||||
return $resized;
|
||||
}
|
||||
throw new Exception('Unable to create resized video');
|
||||
}
|
||||
|
||||
}
|
325
lib/classes/databox/subdefAbstract.class.php
Normal file
325
lib/classes/databox/subdefAbstract.class.php
Normal file
@@ -0,0 +1,325 @@
|
||||
<?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
|
||||
*/
|
||||
abstract class databox_subdefAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $debug = true;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $baseurl;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mediatype;
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels = array();
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $write_meta;
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected $current_mediatype;
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $downloadable;
|
||||
|
||||
const CLASS_THUMBNAIL = 'thumbnail';
|
||||
|
||||
const CLASS_PREVIEW = 'preview';
|
||||
|
||||
const CLASS_DOCUMENT = 'document';
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_class()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_path()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_baseurl()
|
||||
{
|
||||
return $this->baseurl;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_mediatype()
|
||||
{
|
||||
return $this->current_mediatype;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_labels()
|
||||
{
|
||||
return $this->labels;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param SimpleXMLElement $sd
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function __construct(SimpleXMLElement $sd)
|
||||
{
|
||||
|
||||
$this->class = (string) $sd->attributes()->class;
|
||||
$this->name = (string) strtolower($sd->attributes()->name);
|
||||
$this->downloadable = p4field::isyes((string) $sd->attributes()->downloadable);
|
||||
$this->path = trim($sd->path) !== '' ? p4string::addEndSlash(trim($sd->path)) : '';
|
||||
|
||||
$this->baseurl = trim($sd->baseurl) !== '' ?
|
||||
p4string::addEndSlash(trim($sd->baseurl)) : false;
|
||||
$this->current_mediatype = (string) $sd->mediatype;
|
||||
switch ($this->current_mediatype)
|
||||
{
|
||||
case 'image':
|
||||
default:
|
||||
$size = (int) $sd->size;
|
||||
$resolution = trim($sd->dpi);
|
||||
$strip = p4field::isyes((string) $sd->strip);
|
||||
$quality = trim($sd->quality);
|
||||
$this->mediatype = new databox_subdef_mediatype_image($size, $resolution, $strip, $quality);
|
||||
break;
|
||||
case 'audio':
|
||||
$this->mediatype = new databox_subdef_mediatype_audio();
|
||||
break;
|
||||
case 'video':
|
||||
$fps = (int) $sd->fps;
|
||||
$threads = (int) $sd->threads;
|
||||
$bitrate = (int) $sd->bitrate;
|
||||
$vcodec = trim($sd->vcodec);
|
||||
$acodec = trim($sd->acodec);
|
||||
$size = (int) $sd->size;
|
||||
$this->mediatype = new databox_subdef_mediatype_video($size, $fps, $threads, $bitrate, $acodec, $vcodec);
|
||||
break;
|
||||
case 'gif':
|
||||
$delay = (int) $sd->delay;
|
||||
$size = (int) $sd->size;
|
||||
$this->mediatype = new databox_subdef_mediatype_gif($size, $delay);
|
||||
break;
|
||||
case 'flexpaper':
|
||||
$this->mediatype = new databox_subdef_mediatype_flexpaper();
|
||||
break;
|
||||
}
|
||||
|
||||
$this->write_meta = p4field::isyes((string) $sd->meta);
|
||||
|
||||
foreach ($sd->label as $label)
|
||||
{
|
||||
$lang = trim((string) $label->attributes()->lang);
|
||||
if ($lang)
|
||||
$this->labels[$lang] = (string) $label;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function is_downloadable()
|
||||
{
|
||||
return $this->downloadable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_mediatype_options()
|
||||
{
|
||||
$options = array();
|
||||
foreach ($this->available_mediatypes as $mediatype)
|
||||
{
|
||||
if ($mediatype == $this->current_mediatype)
|
||||
{
|
||||
$mediatype_obj = $this->mediatype;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
$mediatype_class = 'databox_subdef_mediatype_' . $mediatype;
|
||||
$mediatype_obj = new $mediatype_class();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$media_opt = $mediatype_obj->get_available_options($this);
|
||||
|
||||
foreach ($media_opt as $opt_name => $values)
|
||||
{
|
||||
if (is_null($values['value']) || $values['value'] == '')
|
||||
{
|
||||
$values['value'] = $values['default'];
|
||||
$media_opt[$opt_name] = $values;
|
||||
}
|
||||
}
|
||||
$options[$mediatype] = $media_opt;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells us if we have to write meta datas in the subdef
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function meta_writeable()
|
||||
{
|
||||
return $this->write_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* logs
|
||||
*
|
||||
* @param <type> $message
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function log($message)
|
||||
{
|
||||
if ($this->debug)
|
||||
{
|
||||
echo "\t --> \t" . $message . "\n";
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record $record
|
||||
* @param string $pathdest
|
||||
* @param registry $registry
|
||||
* @return media_subdef
|
||||
*/
|
||||
public function generate(record_adapter &$record, $pathdest, registry &$registry)
|
||||
{
|
||||
$dest_dir = p4string::addEndSlash(dirname($pathdest));
|
||||
if (!$pathdest)
|
||||
{
|
||||
$dest_dir = databox::dispatch($this->path);
|
||||
}
|
||||
|
||||
$baseurl = $this->baseurl ?
|
||||
$this->baseurl . substr($dest_dir, strlen($this->path)) : '';
|
||||
|
||||
try
|
||||
{
|
||||
$generated = $this->generator_switcher($record, $dest_dir, $registry);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return media_subdef::create($record, $this->get_name(), $generated, $baseurl);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param record $record
|
||||
* @param string $dest_dir
|
||||
* @param string $extension
|
||||
* @return string
|
||||
*/
|
||||
protected function get_newpathfile_name(record_adapter &$record, $dest_dir, $extension)
|
||||
{
|
||||
return $dest_dir . $record->get_record_id() . '_'
|
||||
. $this->name . '.' . $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
public function get_options()
|
||||
{
|
||||
return $this->mediatype->get_options($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract generator switcher
|
||||
*
|
||||
* @param record_Interface $record
|
||||
* @param string $dest_dir
|
||||
* @param registry $registry
|
||||
* @return system_file
|
||||
*/
|
||||
abstract protected function generator_switcher(record_Interface &$record, $dest_dir, registry &$registry);
|
||||
}
|
23
lib/classes/databox/subdefInterface.class.php
Normal file
23
lib/classes/databox/subdefInterface.class.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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 databox_subdefInterface
|
||||
{
|
||||
public function generate(record_adapter &$record, $pathdest, registry &$registry);
|
||||
|
||||
public function get_name();
|
||||
}
|
280
lib/classes/databox/subdefsStructure.class.php
Normal file
280
lib/classes/databox/subdefsStructure.class.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?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
|
||||
*/
|
||||
class databox_subdefsStructure implements IteratorAggregate
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $AvSubdefs = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return new ArrayIterator($this->AvSubdefs);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param databox $databox
|
||||
* @return Array
|
||||
*/
|
||||
public function __construct(databox &$databox)
|
||||
{
|
||||
$this->databox = $databox;
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this->AvSubdefs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
protected function load_subdefs()
|
||||
{
|
||||
|
||||
$sx_struct = $this->databox->get_sxml_structure();
|
||||
|
||||
$this->AvSubdefs = array(
|
||||
'image' => array(),
|
||||
'video' => array(),
|
||||
'audio' => array(),
|
||||
'document' => array(),
|
||||
'flash' => array()
|
||||
);
|
||||
|
||||
if (!$sx_struct)
|
||||
|
||||
return $this;
|
||||
|
||||
$subdefgroup = $sx_struct->subdefs[0];
|
||||
|
||||
|
||||
foreach ($subdefgroup as $k => $subdefs)
|
||||
{
|
||||
$subdefgroup_name = (string) $subdefs->attributes()->name;
|
||||
|
||||
if (!isset($AvSubdefs[$subdefgroup_name]))
|
||||
$AvSubdefs[$subdefgroup_name] = array();
|
||||
|
||||
foreach ($subdefs as $sd)
|
||||
{
|
||||
|
||||
$subdef_name = mb_strtolower((string) $sd->attributes()->name);
|
||||
switch ($subdefgroup_name)
|
||||
{
|
||||
case 'audio':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_audio($sd);
|
||||
break;
|
||||
|
||||
case 'image':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_image($sd);
|
||||
break;
|
||||
|
||||
case 'video':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_video($sd);
|
||||
break;
|
||||
|
||||
case 'document':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_document($sd);
|
||||
break;
|
||||
|
||||
case 'flash':
|
||||
$AvSubdefs[$subdefgroup_name][$subdef_name] =
|
||||
new databox_subdef_flash($sd);
|
||||
break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->AvSubdefs = $AvSubdefs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $subdef_type
|
||||
* @param type $subdef_name
|
||||
* @return databox_subdefAbstract
|
||||
*/
|
||||
public function get_subdef($subdef_type, $subdef_name)
|
||||
{
|
||||
if (isset($this->AvSubdefs[$subdef_type]) && isset($this->AvSubdefs[$subdef_type][$subdef_name]))
|
||||
|
||||
return $this->AvSubdefs[$subdef_type][$subdef_name];
|
||||
throw new Exception_Databox_SubdefNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function delete_subdef($group, $name)
|
||||
{
|
||||
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
$nodes = $dom_xp->query(
|
||||
'//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]/'
|
||||
. 'subdef[@name="' . $name . '"]'
|
||||
);
|
||||
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$node = $nodes->item(0);
|
||||
$parent = $node->parentNode;
|
||||
$parent->removeChild($node);
|
||||
}
|
||||
|
||||
if (isset($AvSubdefs[$group]) && isset($AvSubdefs[$group][$name]))
|
||||
unset($AvSubdefs[$group][$name]);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function add_subdef($group, $name, $class)
|
||||
{
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
|
||||
$subdef = $dom_struct->createElement('subdef');
|
||||
$subdef->setAttribute('class', $class);
|
||||
$subdef->setAttribute('name', $name);
|
||||
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
$query = '//record/subdefs/subdefgroup[@name="' . $group . '"]';
|
||||
$groups = $dom_xp->query($query);
|
||||
|
||||
if ($groups->length == 0)
|
||||
{
|
||||
$group = $dom_struct->createElement('subdefgroup');
|
||||
$group->setAttribute('name', $group);
|
||||
$dom_xp->query('/record/subdefs')->item(0)->appendChild($group);
|
||||
}
|
||||
else
|
||||
{
|
||||
$group = $groups->item(0);
|
||||
}
|
||||
|
||||
$group->appendChild($subdef);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $group
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
* @param boolean $downloadable
|
||||
* @param Array $options
|
||||
* @return databox_subdefsStructure
|
||||
*/
|
||||
public function set_subdef($group, $name, $class, $downloadable, $options)
|
||||
{
|
||||
$dom_struct = $this->databox->get_dom_structure();
|
||||
|
||||
$subdef = $dom_struct->createElement('subdef');
|
||||
$subdef->setAttribute('class', $class);
|
||||
$subdef->setAttribute('name', mb_strtolower($name));
|
||||
$subdef->setAttribute('downloadable', ($downloadable ? 'true' : 'false'));
|
||||
|
||||
foreach ($options as $option => $value)
|
||||
{
|
||||
$child = $dom_struct->createElement($option);
|
||||
$child->appendChild($dom_struct->createTextNode($value));
|
||||
$subdef->appendChild($child);
|
||||
}
|
||||
|
||||
$dom_xp = $this->databox->get_xpath_structure();
|
||||
|
||||
$nodes = $dom_xp->query('//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]');
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$dom_group = $nodes->item(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dom_group = $dom_struct->createElement('subdefgroup');
|
||||
$dom_group->setAttribute('name', $group);
|
||||
|
||||
$nodes = $dom_xp->query('//record/subdefs');
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
$nodes->item(0)->appendChild($dom_group);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception('Unable to find /record/subdefs xquery');
|
||||
}
|
||||
}
|
||||
|
||||
$nodes = $dom_xp->query(
|
||||
'//record/subdefs/'
|
||||
. 'subdefgroup[@name="' . $group . '"]/'
|
||||
. 'subdef[@name="' . $name . '"]'
|
||||
);
|
||||
|
||||
if ($nodes->length > 0)
|
||||
{
|
||||
for ($i = 0; $i < $nodes->length; $i++)
|
||||
{
|
||||
$dom_group->removeChild($nodes->item($i));
|
||||
}
|
||||
}
|
||||
|
||||
$dom_group->appendChild($subdef);
|
||||
|
||||
$this->databox->saveStructure($dom_struct);
|
||||
|
||||
$this->load_subdefs();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user