mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Merge branch '3.8'
Conflicts: composer.json composer.lock config/configuration.sample.yml lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Application/Api.php lib/Alchemy/Phrasea/Controller/Admin/Collection.php lib/Alchemy/Phrasea/Controller/Admin/Users.php lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php lib/Alchemy/Phrasea/Controller/Prod/Export.php lib/Alchemy/Phrasea/Controller/Prod/Language.php lib/Alchemy/Phrasea/Controller/Prod/Push.php lib/Alchemy/Phrasea/Controller/Prod/Tooltip.php lib/Alchemy/Phrasea/Controller/Report/Informations.php lib/Alchemy/Phrasea/Controller/Report/Root.php lib/Alchemy/Phrasea/Controller/Root/Developers.php lib/Alchemy/Phrasea/Controller/Root/Login.php lib/Alchemy/Phrasea/Controller/Root/Session.php lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php lib/Alchemy/Phrasea/Controller/Utils/ConnectionTest.php lib/Alchemy/Phrasea/Controller/Utils/PathFileTest.php lib/Alchemy/Phrasea/Core/Version.php lib/Alchemy/Phrasea/Form/Login/PhraseaAuthenticationForm.php lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php lib/Alchemy/Phrasea/SearchEngine/SphinxSearch/SphinxSearchEngine.php lib/classes/API/OAuth2/Application.php lib/classes/API/V1/adapter.php lib/classes/Feed/Adapter.php lib/classes/Feed/Aggregate.php lib/classes/Feed/Collection.php lib/classes/Feed/Entry/Adapter.php lib/classes/ZipArchiveImproved.php lib/classes/caption/Field/Value.php lib/classes/caption/record.php lib/classes/eventsmanager/notify/feed.php lib/classes/media/subdef.php lib/classes/module/report/connexion.php lib/classes/module/report/download.php lib/classes/record/adapter.php lib/classes/registry.php lib/classes/set/export.php lib/classes/setup.php lib/classes/task/abstract.php lib/classes/task/period/emptyColl.php lib/classes/uuid.php lib/conf.d/_GV_template.inc lib/conf.d/bases_structure.xml lib/conf.d/configuration.yml lib/conf.d/minifyGroupsConfig.php locale/de_DE/LC_MESSAGES/phraseanet.mo locale/de_DE/LC_MESSAGES/phraseanet.po locale/en_GB/LC_MESSAGES/phraseanet.mo locale/en_GB/LC_MESSAGES/phraseanet.po locale/fr_FR/LC_MESSAGES/phraseanet.mo locale/fr_FR/LC_MESSAGES/phraseanet.po locale/nl_NL/LC_MESSAGES/phraseanet.mo locale/nl_NL/LC_MESSAGES/phraseanet.po locale/phraseanet.pot templates/web/account/account.html.twig templates/web/account/base.html.twig templates/web/admin/databox/databox.html.twig templates/web/admin/index.html.twig templates/web/admin/setup.html.twig templates/web/admin/tree.html.twig templates/web/client/index.html.twig templates/web/common/caption.html.twig templates/web/common/caption_templates/answer.html.twig templates/web/common/caption_templates/basket_element.html.twig templates/web/common/caption_templates/internal_publi.html.twig templates/web/common/caption_templates/lazaret.html.twig templates/web/common/caption_templates/overview.html.twig templates/web/common/caption_templates/preview.html.twig templates/web/common/index_bootstrap.html.twig templates/web/common/indexfloat.html.twig templates/web/common/thumbnail.html.twig templates/web/developers/application_form.html.twig templates/web/lightbox/IE6/feed.html.twig templates/web/lightbox/IE6/validate.html.twig templates/web/lightbox/feed.html.twig templates/web/lightbox/validate.html.twig templates/web/prod/actions/Download/prepare.html.twig templates/web/prod/actions/publish/publish.html.twig templates/web/prod/index.html.twig templates/web/prod/preview/caption.html.twig templates/web/prod/results/answerlist.html.twig templates/web/thesaurus/accept.html.twig templates/web/thesaurus/export-text-dialog.html.twig templates/web/thesaurus/export-text.html.twig templates/web/thesaurus/export-topics-dialog.html.twig templates/web/thesaurus/export-topics.html.twig templates/web/thesaurus/index.html.twig templates/web/thesaurus/link-field-step1.html.twig templates/web/thesaurus/link-field-step2.html.twig templates/web/thesaurus/link-field-step3.html.twig templates/web/thesaurus/new-term.html.twig templates/web/thesaurus/properties.html.twig templates/web/thesaurus/search.html.twig templates/web/thesaurus/thesaurus.html.twig tests/Alchemy/Tests/Phrasea/Application/ApiJsonTest.php tests/Alchemy/Tests/Phrasea/Application/ApiYamlTest.php tests/Alchemy/Tests/Phrasea/Application/LightboxTest.php tests/Alchemy/Tests/Phrasea/Application/OAuth2Test.php tests/Alchemy/Tests/Phrasea/Application/OverviewTest.php tests/Alchemy/Tests/Phrasea/Authentication/PersistentCookie/ManagerTest.php tests/Alchemy/Tests/Phrasea/Cache/RedisCacheTest.php tests/Alchemy/Tests/Phrasea/Command/Compile/ConfigurationTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/FieldsTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/PublicationTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/SubdefsTest.php tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php tests/Alchemy/Tests/Phrasea/Controller/Api/ApiJSONPTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/BasketTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/BridgeTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/EditTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/FeedTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/LanguageTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/MoveCollectionTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/PrinterTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/PushTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/RootTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/StoryTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/ToolsTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/TooltipTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/UploadTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/UsrListsTest.php tests/Alchemy/Tests/Phrasea/Controller/Prod/WorkZoneTest.php tests/Alchemy/Tests/Phrasea/Controller/Root/LoginTest.php tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php tests/Alchemy/Tests/Phrasea/Controller/Utils/PathFileTestTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/FTPServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/LocaleServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/PhraseanetServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/RegistrationServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Core/Provider/TaskManagerServiceProviderTest.php tests/Alchemy/Tests/Phrasea/Http/XSendFile/NginxModeTest.php tests/Alchemy/Tests/Phrasea/Metadata/Tag/TfEditDateTest.php tests/Alchemy/Tests/Phrasea/Metadata/Tag/TfMimeTypeTest.php tests/Alchemy/Tests/Phrasea/SearchEngine/SearchEngineAbstractTest.php tests/classes/Feed/Feed_AggregateTest.php tests/classes/PhraseanetPHPUnitAbstract.php tests/db-ref.sqlite
This commit is contained in:
95
lib/classes/API/Webhook.php
Normal file
95
lib/classes/API/Webhook.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||
|
||||
class API_Webhook
|
||||
{
|
||||
const NEW_FEED_ENTRY = "new_feed_entry";
|
||||
|
||||
protected $appbox;
|
||||
protected $id;
|
||||
protected $type;
|
||||
protected $data;
|
||||
protected $created;
|
||||
|
||||
public function __construct(appbox $appbox, $id)
|
||||
{
|
||||
$this->appbox = $appbox;
|
||||
$this->id = $id;
|
||||
$sql = 'SELECT `type`, `data`, created
|
||||
FROM api_webhooks
|
||||
WHERE id = :id';
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':id' => $id));
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$row) {
|
||||
throw new RuntimeException('Webhooks not found');
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->type = $row['type'];
|
||||
$this->data = json_decode($row['data']);
|
||||
$this->created = new \DateTime($row['created']);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$sql = 'DELETE FROM api_webhooks WHERE id = :id';
|
||||
|
||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':id' => $this->id));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public static function create(appbox $appbox, $type, array $data)
|
||||
{
|
||||
$sql = 'INSERT INTO api_webhooks (id, `type`, `data`, created)
|
||||
VALUES (null, :type, :data, NOW())';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(
|
||||
'type' => $type,
|
||||
'data' => json_encode($data),
|
||||
));
|
||||
$stmt->closeCursor();
|
||||
|
||||
return new API_Webhook($appbox, $appbox->get_connection()->lastInsertId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreated()
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
722
lib/classes/Feed/Adapter.php
Normal file
722
lib/classes/Feed/Adapter.php
Normal file
@@ -0,0 +1,722 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cacheableInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var collection
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $publishers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $public;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var Feed_Publisher_Adapter
|
||||
*/
|
||||
protected $owner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $icon_url;
|
||||
|
||||
const CACHE_ENTRY_NUMBER = 'entrynumber';
|
||||
const CACHE_USER_TOKEN = 'usr_token';
|
||||
const MAX_ENTRIES = 20;
|
||||
|
||||
public function __construct(Application $app, $id)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->id = (int) $id;
|
||||
|
||||
$this->load();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function load()
|
||||
{
|
||||
try {
|
||||
$datas = $this->get_data_from_cache();
|
||||
|
||||
$this->title = $datas['title'];
|
||||
$this->subtitle = $datas['subtitle'];
|
||||
$this->collection = $datas['base_id'] ? collection::get_from_base_id($this->app, $datas['base_id']) : null;
|
||||
$this->created_on = $datas['created_on'];
|
||||
$this->updated_on = $datas['updated_on'];
|
||||
$this->public = $datas['public'];
|
||||
|
||||
return $this;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
$sql = 'SELECT id, title, subtitle, created_on, updated_on, base_id, public
|
||||
FROM feeds WHERE id = :feed_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':feed_id' => $this->id));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row)
|
||||
throw new NotFoundHttpException('Feed not found');
|
||||
|
||||
$this->title = $row['title'];
|
||||
$this->subtitle = $row['subtitle'];
|
||||
if (!is_null($row['base_id']))
|
||||
$this->collection = collection::get_from_base_id($this->app, $row['base_id']);
|
||||
$this->created_on = new DateTime($row['created_on']);
|
||||
$this->updated_on = new DateTime($row['updated_on']);
|
||||
$this->public = !!$row['public'];
|
||||
|
||||
$base_id = $this->collection instanceof collection ? $this->collection->get_base_id() : null;
|
||||
|
||||
$datas = array(
|
||||
'title' => $this->title
|
||||
, 'subtitle' => $this->subtitle
|
||||
, 'base_id' => $base_id
|
||||
, 'created_on' => $this->created_on
|
||||
, 'updated_on' => $this->updated_on
|
||||
, 'public' => $this->public
|
||||
);
|
||||
|
||||
$this->set_data_to_cache($datas);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_icon_url()
|
||||
{
|
||||
if ($this->icon_url) {
|
||||
return $this->icon_url;
|
||||
}
|
||||
|
||||
$url = '/skins/icons/rss32.gif';
|
||||
|
||||
$file = $this->app['root.path']
|
||||
. '/www/custom/feed_' . $this->get_id() . '.jpg';
|
||||
|
||||
if (file_exists($file)) {
|
||||
$url = '/custom/feed_' . $this->get_id() . '.jpg';
|
||||
}
|
||||
|
||||
$this->icon_url = $url;
|
||||
|
||||
return $this->icon_url;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $file The path to the file
|
||||
* @return Feed_Adapter
|
||||
*/
|
||||
public function set_icon($file)
|
||||
{
|
||||
if (!file_exists($file)) {
|
||||
throw new \Alchemy\Phrasea\Exception\InvalidArgumentException('File does not exists');
|
||||
}
|
||||
|
||||
$config_file = $this->app['root.path'] . '/config/feed_' . $this->get_id() . '.jpg';
|
||||
$www_file = $this->app['root.path'] . '/www/custom/feed_' . $this->get_id() . '.jpg';
|
||||
|
||||
copy($file, $config_file);
|
||||
copy($file, $www_file);
|
||||
$this->icon_url = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function set_created_on(DateTime $created_on)
|
||||
{
|
||||
$sql = 'UPDATE feeds SET created_on = :created_on
|
||||
WHERE id = :feed_id';
|
||||
$params = array(
|
||||
':created_on' => $created_on->format(DATE_ISO8601)
|
||||
, ':feed_id' => $this->get_id()
|
||||
);
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$this->created_on = $created_on;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function reset_icon()
|
||||
{
|
||||
$config_file = $this->app['root.path']
|
||||
. '/config/feed_' . $this->get_id() . '.jpg';
|
||||
$www_file = $this->app['root.path']
|
||||
. '/www/custom/feed_' . $this->get_id() . '.jpg';
|
||||
|
||||
if (is_file($config_file))
|
||||
unlink($config_file);
|
||||
if (is_file($www_file))
|
||||
unlink($www_file);
|
||||
|
||||
$this->icon_url = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_aggregated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param User_Adapter $user
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_owner(User_Adapter $user)
|
||||
{
|
||||
$this->load_publishers();
|
||||
|
||||
if (!$this->owner) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->owner->get_user()->get_id() === $user->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param User_Adapter $user
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_publisher(User_Adapter $user)
|
||||
{
|
||||
return in_array($user->get_id(), array_keys($this->get_publishers()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if a user has access to the feed
|
||||
*
|
||||
* @param User_Adapter $user
|
||||
* @return type
|
||||
*/
|
||||
public function has_access(User_Adapter $user)
|
||||
{
|
||||
if ($this->get_collection() instanceof collection) {
|
||||
return $user->ACL()->has_access_to_base($this->collection->get_base_id());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_public()
|
||||
{
|
||||
if ($this->get_collection() instanceof collection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->public;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_publishers()
|
||||
{
|
||||
return $this->load_publishers();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return collection
|
||||
*/
|
||||
public function get_collection()
|
||||
{
|
||||
return $this->collection;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param User_Adapter $user
|
||||
* @return Feed_Adapter
|
||||
*/
|
||||
public function add_publisher(User_Adapter $user)
|
||||
{
|
||||
if (in_array($user->get_id(), array_keys($this->get_publishers()))) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
Feed_Publisher_Adapter::create($this->app, $user, $this, false);
|
||||
$this->publishers = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function load_publishers()
|
||||
{
|
||||
if (is_array($this->publishers)) {
|
||||
return $this->publishers;
|
||||
}
|
||||
|
||||
$sql = 'SELECT id, usr_id, owner FROM feed_publishers
|
||||
WHERE feed_id = :feed_id';
|
||||
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':feed_id' => $this->id));
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
try {
|
||||
$publisher = new Feed_Publisher_Adapter($this->app, $row['id']);
|
||||
} catch (\Exception_Feed_PublisherNotFound $e) {
|
||||
continue;
|
||||
}
|
||||
$this->publishers[$row['usr_id']] = $publisher;
|
||||
if ($publisher->is_owner()) {
|
||||
$this->owner = $publisher;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->publishers;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param collection $collection
|
||||
* @return Feed_Adapter
|
||||
*/
|
||||
public function set_collection(collection $collection = null)
|
||||
{
|
||||
$base_id = null;
|
||||
if ($collection instanceof collection) {
|
||||
$base_id = $collection->get_base_id();
|
||||
}
|
||||
|
||||
$sql = 'UPDATE feeds SET base_id = :base_id, updated_on = NOW()
|
||||
WHERE id = :feed_id';
|
||||
$params = array(':base_id' => $base_id, ':feed_id' => $this->get_id());
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$this->collection = $collection;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $boolean
|
||||
* @return Feed_Adapter
|
||||
*/
|
||||
public function set_public($boolean)
|
||||
{
|
||||
$boolean = !!$boolean;
|
||||
$sql = 'UPDATE feeds SET public = :public, updated_on = NOW()
|
||||
WHERE id = :feed_id';
|
||||
|
||||
$params = array(
|
||||
':public' => $boolean ? '1' : '0',
|
||||
':feed_id' => $this->get_id()
|
||||
);
|
||||
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$this->public = $boolean;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
$feed_collection = new Feed_Collection($this->app, array());
|
||||
$feed_collection->delete_data_from_cache(Feed_Collection::CACHE_PUBLIC);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $title
|
||||
* @return Feed_Adapter
|
||||
*/
|
||||
public function set_title($title)
|
||||
{
|
||||
$title = trim(strip_tags($title));
|
||||
|
||||
if ($title === '')
|
||||
throw new Exception_InvalidArgument();
|
||||
|
||||
$sql = 'UPDATE feeds SET title = :title, updated_on = NOW()
|
||||
WHERE id = :feed_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':title' => $title, ':feed_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
$this->title = $title;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $subtitle
|
||||
* @return Feed_Adapter
|
||||
*/
|
||||
public function set_subtitle($subtitle)
|
||||
{
|
||||
$subtitle = strip_tags($subtitle);
|
||||
|
||||
$sql = 'UPDATE feeds SET subtitle = :subtitle, updated_on = NOW()
|
||||
WHERE id = :feed_id';
|
||||
$params = array(':subtitle' => $subtitle, ':feed_id' => $this->get_id());
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
$this->subtitle = $subtitle;
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function create(Application $app, User_Adapter $user, $title, $subtitle)
|
||||
{
|
||||
$sql = 'INSERT INTO feeds (id, title, subtitle, created_on, updated_on)
|
||||
VALUES (null, :title, :subtitle, NOW(), NOW())';
|
||||
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':title' => $title, ':subtitle' => $subtitle));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$feed_id = $app['phraseanet.appbox']->get_connection()->lastInsertId();
|
||||
|
||||
$feed = new self($app, $feed_id);
|
||||
|
||||
Feed_Publisher_Adapter::create($app, $user, $feed, true);
|
||||
|
||||
return $feed;
|
||||
}
|
||||
|
||||
public static function load_with_user(Application $app, User_Adapter $user, $id)
|
||||
{
|
||||
$feed = new self($app, $id);
|
||||
$coll = $feed->get_collection();
|
||||
if (
|
||||
$feed->is_public()
|
||||
|| $coll === null
|
||||
|| in_array($coll->get_base_id(), array_keys($user->ACL()->get_granted_base()))
|
||||
) {
|
||||
return $feed;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('Feed not found');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_count_total_entries()
|
||||
{
|
||||
try {
|
||||
return $this->get_data_from_cache(self::CACHE_ENTRY_NUMBER);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
$sql = 'SELECT count(id) as number
|
||||
FROM feed_entries WHERE feed_id = :feed_id';
|
||||
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':feed_id' => $this->get_id()));
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$number = $row ? (int) $row['number'] : 0;
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->set_data_to_cache($number, self::CACHE_ENTRY_NUMBER);
|
||||
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$this->reset_icon();
|
||||
while ($this->get_count_total_entries() > 0) {
|
||||
$entries_coll = $this->get_entries(0, 10);
|
||||
foreach ($entries_coll->get_entries() as $entry) {
|
||||
$entry->delete();
|
||||
}
|
||||
unset($entries_coll);
|
||||
$this->delete_data_from_cache(self::CACHE_ENTRY_NUMBER);
|
||||
}
|
||||
|
||||
foreach ($this->get_publishers() as $publishers)
|
||||
$publishers->delete();
|
||||
|
||||
$sql = 'DELETE FROM feed_tokens WHERE feed_id = :feed_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':feed_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = 'DELETE FROM feeds WHERE id = :feed_id';
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute(array(':feed_id' => $this->get_id()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->delete_data_from_cache();
|
||||
|
||||
$feed_coll = new Feed_Collection($this->app, array());
|
||||
$feed_coll->delete_data_from_cache(Feed_Collection::CACHE_PUBLIC);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $offset_start
|
||||
* @param int $how_many
|
||||
* @return Feed_Entry_Collection
|
||||
*/
|
||||
public function get_entries($offset_start, $how_many)
|
||||
{
|
||||
$offset_start = (int) $offset_start;
|
||||
$how_many = $how_many > self::MAX_ENTRIES ? self::MAX_ENTRIES : (int) $how_many;
|
||||
|
||||
$sql = 'SELECT id
|
||||
FROM feed_entries
|
||||
WHERE feed_id = :feed_id
|
||||
ORDER BY id DESC
|
||||
LIMIT ' . $offset_start . ', ' . $how_many;
|
||||
|
||||
$params = array(
|
||||
':feed_id' => $this->get_id()
|
||||
);
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$result = new Feed_Entry_Collection();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$entry = new Feed_Entry_Adapter($this->app, $this, $row['id']);
|
||||
$result->add_entry($entry);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registryInterface $registry
|
||||
* @param string $format
|
||||
* @param int $page
|
||||
* @return Feed_Link
|
||||
*/
|
||||
public function get_homepage_link(registryInterface $registry, $format, $page = null)
|
||||
{
|
||||
if (!$this->is_public()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch ($format) {
|
||||
case self::FORMAT_ATOM:
|
||||
return new Feed_Link(
|
||||
sprintf('%s/feeds/feed/%s/atom/%s'
|
||||
, rtrim($registry->get('GV_ServerName'), '/')
|
||||
, $this->get_id()
|
||||
, ($page ? '?page=' . $page : '')
|
||||
)
|
||||
, sprintf('%s - %s', $this->get_title(), 'Atom')
|
||||
, 'application/atom+xml'
|
||||
);
|
||||
break;
|
||||
case self::FORMAT_RSS:
|
||||
default:
|
||||
return new Feed_Link(
|
||||
sprintf('%s/feeds/feed/%s/rss/%s'
|
||||
, rtrim($registry->get('GV_ServerName'), '/')
|
||||
, $this->get_id()
|
||||
, ($page ? '?page=' . $page : '')
|
||||
)
|
||||
, sprintf('%s - %s', $this->get_title(), 'RSS')
|
||||
, 'application/rss+xml'
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param User_Adapter $user
|
||||
* @param boolean $renew
|
||||
* @return string
|
||||
*/
|
||||
protected function get_token(User_Adapter $user, $renew = false)
|
||||
{
|
||||
$cache_key = self::CACHE_USER_TOKEN . '_' . $user->get_id();
|
||||
try {
|
||||
if (!$renew) {
|
||||
return $this->get_data_from_cache($cache_key);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
$sql = 'SELECT token FROM feed_tokens
|
||||
WHERE usr_id = :usr_id AND feed_id = :feed_id
|
||||
AND aggregated IS NULL';
|
||||
|
||||
$params = array(
|
||||
':usr_id' => $user->get_id(),
|
||||
':feed_id' => $this->get_id()
|
||||
);
|
||||
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if (!$row || $renew === true) {
|
||||
$token = random::generatePassword(12, random::LETTERS_AND_NUMBERS);
|
||||
$sql = 'REPLACE INTO feed_tokens (id, token, feed_id, usr_id, aggregated)
|
||||
VALUES (null, :token, :feed_id, :usr_id, :aggregated)';
|
||||
|
||||
$params = array(
|
||||
':token' => $token
|
||||
, ':feed_id' => $this->get_id()
|
||||
, ':usr_id' => $user->get_id()
|
||||
, ':aggregated' => null
|
||||
);
|
||||
|
||||
$stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$this->delete_data_from_cache($cache_key);
|
||||
} else {
|
||||
$token = $row['token'];
|
||||
}
|
||||
|
||||
$this->set_data_to_cache($token, $cache_key);
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param registryInterface $registry
|
||||
* @param User_Adapter $user
|
||||
* @param string $format
|
||||
* @param int $page
|
||||
* @param boolean $renew_token
|
||||
* @return Feed_Link
|
||||
*/
|
||||
public function get_user_link(registryInterface $registry, User_Adapter $user, $format, $page = null, $renew_token = false)
|
||||
{
|
||||
switch ($format) {
|
||||
case self::FORMAT_ATOM:
|
||||
return new Feed_Link(
|
||||
sprintf('%s/feeds/userfeed/%s/%s/atom/'
|
||||
, rtrim($registry->get('GV_ServerName'), '/')
|
||||
, $this->get_token($user, $renew_token)
|
||||
, $this->get_id()
|
||||
, ($page ? '?page=' . $page : '')
|
||||
)
|
||||
, sprintf('%s - %s', $this->get_title(), 'Atom')
|
||||
, 'application/atom+xml'
|
||||
);
|
||||
break;
|
||||
case self::FORMAT_RSS:
|
||||
return new Feed_Link(
|
||||
sprintf('%s/feeds/userfeed/%s/%s/rss/%s'
|
||||
, rtrim($registry->get('GV_ServerName'), '/')
|
||||
, $this->get_token($user, $renew_token)
|
||||
, $this->get_id()
|
||||
, ($page ? '?page=' . $page : '')
|
||||
)
|
||||
, sprintf('%s - %s', $this->get_title(), 'RSS')
|
||||
, 'application/rss+xml'
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_cache_key($option = null)
|
||||
{
|
||||
return 'feed_adapter_' . $this->get_id() . '_' . ($option ? '_' . $option : '');
|
||||
}
|
||||
|
||||
public function get_data_from_cache($option = null)
|
||||
{
|
||||
return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option));
|
||||
}
|
||||
|
||||
public function set_data_to_cache($value, $option = null, $duration = 0)
|
||||
{
|
||||
return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration);
|
||||
}
|
||||
|
||||
public function delete_data_from_cache($option = null)
|
||||
{
|
||||
return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option));
|
||||
}
|
||||
}
|
@@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
class ThesaurusValue
|
||||
class caption_Field_ThesaurusValue
|
||||
{
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
@@ -51,7 +51,20 @@ class caption_Field_Value implements cache_cacheableInterface
|
||||
protected $record;
|
||||
protected $app;
|
||||
|
||||
protected static $localCache = [];
|
||||
/**
|
||||
* Query to ask to the search engine to bounce to the current value;
|
||||
* This property is set if the value is matched against a thesaurus value;
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $qjs;
|
||||
|
||||
/**
|
||||
* Tells whether the value is matched against a thesaurus value.
|
||||
*/
|
||||
protected $isThesaurusValue;
|
||||
|
||||
protected static $localCache = array();
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -71,6 +84,11 @@ class caption_Field_Value implements cache_cacheableInterface
|
||||
$this->retrieveValues();
|
||||
}
|
||||
|
||||
public function getQjs()
|
||||
{
|
||||
return $this->qjs;
|
||||
}
|
||||
|
||||
protected function retrieveValues()
|
||||
{
|
||||
try {
|
||||
@@ -336,7 +354,6 @@ class caption_Field_Value implements cache_cacheableInterface
|
||||
public function highlight_thesaurus()
|
||||
{
|
||||
$value = $this->getValue();
|
||||
|
||||
$databox = $this->databox_field->get_databox();
|
||||
$XPATH_thesaurus = $databox->get_xpath_thesaurus();
|
||||
|
||||
@@ -374,18 +391,33 @@ class caption_Field_Value implements cache_cacheableInterface
|
||||
if($context_noacc != "")
|
||||
$note += ($node->getAttribute("k") == $context_noacc) ? 1 : 0;
|
||||
if ($note > $bestnote) {
|
||||
$bestnote = $note;
|
||||
$bestnode = $node;
|
||||
}
|
||||
}
|
||||
if ($bestnode) {
|
||||
list($term, $context) = $this->splitTermAndContext(str_replace(["[[em]]", "[[/em]]"], ["", ""], $value));
|
||||
$qjs = $term . ($context ? '['.$context.']' : '');
|
||||
|
||||
$value = new ThesaurusValue($bestnode->getAttribute('v'), $this->databox_field, $qjs);
|
||||
if ($bestnode) {
|
||||
list($term, $context) = $this->splitTermAndContext(str_replace(array("[[em]]", "[[/em]]"), array("", ""), $value));
|
||||
// a value has been found in thesaurus, update value & set the query to bounce to the value
|
||||
$this->value = $bestnode->getAttribute('v');
|
||||
$this->qjs = $term . ($context ? '['.$context.']' : '');
|
||||
$this->isThesaurusValue = true;
|
||||
} else {
|
||||
$this->isThesaurusValue = false;
|
||||
}
|
||||
|
||||
return $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isThesaurusValue()
|
||||
{
|
||||
if (null === $this->isThesaurusValue) {
|
||||
$this->highlight_thesaurus();
|
||||
}
|
||||
|
||||
return $this->isThesaurusValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,6 +498,11 @@ class caption_Field_Value implements cache_cacheableInterface
|
||||
unset(self::$localCache[$this->get_cache_key($option)]);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public static function purge()
|
||||
{
|
||||
self::$localCache = [];
|
||||
|
@@ -197,27 +197,27 @@ class caption_field implements cache_cacheableInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_serialized_values($custom_separator = false, $highlightTheso = false)
|
||||
public function get_serialized_values($custom_separator = false, $highlight = false)
|
||||
{
|
||||
if ($this->databox_field->is_multi() === true) {
|
||||
if ($custom_separator !== false)
|
||||
$separator = $custom_separator;
|
||||
else
|
||||
$separator = $this->databox_field->get_separator();
|
||||
|
||||
return self::serialize_value($this->values, $separator, $highlightTheso);
|
||||
} else {
|
||||
foreach ($this->values as $value) {
|
||||
/* @var $value Caption_Field_Value */
|
||||
if ($highlightTheso) {
|
||||
return $value->highlight_thesaurus();
|
||||
} else {
|
||||
return $value->getValue();
|
||||
}
|
||||
}
|
||||
if (0 === count($this->values)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
if ($this->is_multi()) {
|
||||
$separator = $custom_separator !== false ? $custom_separator : $this->databox_field->get_separator();
|
||||
|
||||
return self::serialize_value($this->values, $separator, $highlight);
|
||||
}
|
||||
|
||||
$value = current($this->values);
|
||||
|
||||
/* @var $value Caption_Field_Value */
|
||||
if ($highlight) {
|
||||
return $value->highlight_thesaurus();
|
||||
}
|
||||
|
||||
return $value->getValue();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,17 +256,6 @@ class caption_field implements cache_cacheableInterface
|
||||
return $this->databox_field;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function highlight_thesaurus()
|
||||
{
|
||||
$value = $this->get_serialized_values(false, true);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $serialized_value
|
||||
|
@@ -174,55 +174,40 @@ class caption_record implements caption_interface, cache_cacheableInterface
|
||||
*/
|
||||
public function get_highlight_fields($highlight = '', Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null)
|
||||
{
|
||||
return $this->highlight_fields($highlight, $grep_fields, $searchEngine, $includeBusiness, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo move this fun in caption_field object
|
||||
* @param string $highlight
|
||||
* @param array $grep_fields
|
||||
* @param SearchEngineInterface $searchEngine
|
||||
* @return array
|
||||
*/
|
||||
protected function highlight_fields($highlight, Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false, SearchEngineOptions $options = null)
|
||||
{
|
||||
$fields = [];
|
||||
$fields = array();
|
||||
|
||||
foreach ($this->get_fields($grep_fields, $includeBusiness) as $meta_struct_id => $field) {
|
||||
|
||||
$value = preg_replace(
|
||||
"(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\w:#%/;$()~_?/\-=\\\.&]*)([^']{1}))"
|
||||
, '$1 $2 <a title="' . $this->app->trans('Open the URL in a new window') . '" class="ui-icon ui-icon-extlink" href="$2" style="display:inline;padding:2px 5px;margin:0 4px 0 2px;" target="_blank"> </a>$7'
|
||||
, $highlight ? $field->highlight_thesaurus() : $field->get_serialized_values(false, false)
|
||||
);
|
||||
|
||||
$fields[$field->get_name()] = [
|
||||
'value' => $value,
|
||||
/** @Ignore */
|
||||
'label' => $field->get_databox_field()->get_label($this->app['locale']),
|
||||
$values = array();
|
||||
foreach ($field->get_values() as $metaId => $v) {
|
||||
$values[$metaId] = array(
|
||||
'value' => $v->getValue(),
|
||||
'from_thesaurus' => $highlight ? $v->isThesaurusValue() : false,
|
||||
'qjs' => $v->getQjs(),
|
||||
);
|
||||
}
|
||||
$fields[$field->get_name()] = array(
|
||||
'values' => $values,
|
||||
'name' => $field->get_name(),
|
||||
'label' => $field->get_databox_field()->get_label($this->app['locale.I18n']),
|
||||
'separator' => $field->get_databox_field()->get_separator(),
|
||||
];
|
||||
'sbas_id' => $field->get_databox_field()->get_databox()->get_sbas_id()
|
||||
);
|
||||
}
|
||||
|
||||
if ($searchEngine instanceof SearchEngineInterface) {
|
||||
$ret = $searchEngine->excerpt($highlight, $fields, $this->record, $options);
|
||||
|
||||
// sets highlighted value from search engine, highlighted values will now
|
||||
// be surrounded by [[em]][[/em]] tags
|
||||
if ($ret) {
|
||||
$n = -1;
|
||||
|
||||
foreach ($fields as $key => $value) {
|
||||
$n++;
|
||||
|
||||
if (!isset($fields[$key])) {
|
||||
if (!isset($ret[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($fields[$key]['value'], '<a class="bounce" ') !== false) {
|
||||
continue;
|
||||
foreach ($ret[$key] as $metaId => $newValue) {
|
||||
$fields[$key]['values'][$metaId]['value'] = $newValue;
|
||||
}
|
||||
|
||||
//if(strpos($fields[$key]['value'], '<a ') === false)
|
||||
$fields[$key]['value'] = $ret[$n];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -63,8 +63,14 @@ class databox_status
|
||||
return;
|
||||
}
|
||||
|
||||
$path = $this->path = $app['root.path'] . "/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"]);
|
||||
$uniqid = md5(implode('-', array(
|
||||
$sbas_params[$sbas_id]["host"],
|
||||
$sbas_params[$sbas_id]["port"],
|
||||
$sbas_params[$sbas_id]["dbname"]
|
||||
)));
|
||||
|
||||
$path = $this->path = $app['root.path'] . "/config/status/" . $uniqid;
|
||||
$url = $this->url = "/custom/status/" . $uniqid;
|
||||
|
||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
||||
$xmlpref = $databox->get_structure();
|
||||
|
@@ -44,7 +44,6 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
|
||||
];
|
||||
|
||||
$dom_xml = new DOMDocument('1.0', 'UTF-8');
|
||||
|
||||
$dom_xml->preserveWhiteSpace = false;
|
||||
$dom_xml->formatOutput = true;
|
||||
|
||||
@@ -58,7 +57,11 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
|
||||
|
||||
$dom_xml->appendChild($root);
|
||||
|
||||
$datas = $dom_xml->saveXml();
|
||||
$data = $dom_xml->saveXml();
|
||||
|
||||
API_Webhook::create($this->app['phraseanet.appbox'], API_Webhook::NEW_FEED_ENTRY, array_merge(
|
||||
array('feed_id' => $entry->get_feed()->get_id()), $params
|
||||
));
|
||||
|
||||
$Query = new \User_Query($this->app);
|
||||
|
||||
@@ -74,11 +77,6 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
|
||||
$start = 0;
|
||||
$perLoop = 100;
|
||||
|
||||
$from = [
|
||||
'email' => $entry->getAuthorEmail(),
|
||||
'name' => $entry->getAuthorName()
|
||||
];
|
||||
|
||||
do {
|
||||
$results = $Query->limit($start, $perLoop)->execute()->get_results();
|
||||
|
||||
@@ -108,7 +106,7 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
|
||||
}
|
||||
}
|
||||
|
||||
$this->broker->notify($user_to_notif->getId(), __CLASS__, $datas, $mailed);
|
||||
$this->broker->notify($user_to_notif->getId(), __CLASS__, $data, $mailed);
|
||||
}
|
||||
$start += $perLoop;
|
||||
} while (count($results) > 0);
|
||||
@@ -118,13 +116,13 @@ class eventsmanager_notify_feed extends eventsmanager_notifyAbstract
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Array $datas
|
||||
* @param Array $data
|
||||
* @param boolean $unread
|
||||
* @return Array
|
||||
*/
|
||||
public function datas($datas, $unread)
|
||||
public function datas($data, $unread)
|
||||
{
|
||||
$sx = simplexml_load_string($datas);
|
||||
$sx = simplexml_load_string($data);
|
||||
|
||||
$entry = $this->app['repo.feed-entries']->find((int) $sx->entry_id);
|
||||
|
||||
|
@@ -200,13 +200,12 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row) {
|
||||
|
||||
$this->width = (int) $row['width'];
|
||||
$this->size = (int) $row['size'];
|
||||
$this->height = (int) $row['height'];
|
||||
$this->mime = $row['mime'];
|
||||
$this->file = $row['file'];
|
||||
$this->etag = $row['etag'];
|
||||
$this->etag = $row['etag'] !== null ? $row['etag'] : md5(time() . $row['path'] .$row['file']);
|
||||
$this->path = p4string::addEndSlash($row['path']);
|
||||
$this->is_substituted = ! ! $row['substit'];
|
||||
$this->subdef_id = (int) $row['subdef_id'];
|
||||
@@ -742,7 +741,7 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($this->mime, ['video/mp4'])) {
|
||||
if ($this->app['phraseanet.h264-factory']->isH264Enabled() && in_array($this->mime, array('video/mp4'))) {
|
||||
if (null !== $url = $this->app['phraseanet.h264']->getUrl($this->get_pathfile())) {
|
||||
$this->url = $url;
|
||||
|
||||
|
@@ -91,8 +91,9 @@ class module_report_connexion extends module_report
|
||||
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult(Application $app, $rs)
|
||||
{
|
||||
|
@@ -94,8 +94,9 @@ class module_report_download extends module_report
|
||||
|
||||
/**
|
||||
* @desc build the result from the specified sql
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @param array $champ all the field from the request displayed in a array
|
||||
* @param string $sql the request from buildreq
|
||||
* @return $this->result
|
||||
*/
|
||||
protected function buildResult(Application $app, $rs)
|
||||
{
|
||||
|
78
lib/classes/patch/384alpha2a.php
Normal file
78
lib/classes/patch/384alpha2a.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class patch_384alpha2a implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.8.4-alpha.2';
|
||||
|
||||
/** @var array */
|
||||
private $concern = array(base::APPLICATION_BOX);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$finder = new Finder();
|
||||
$fs = new Filesystem();
|
||||
foreach ($finder->files()->in($app['root.path'].'/config/status') as $file) {
|
||||
if (!$file->isFile()) {
|
||||
continue;
|
||||
}
|
||||
$fileName = $file->getFileName();
|
||||
$chunks = explode('-', $fileName);
|
||||
|
||||
if (count($chunks) < 4) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$suffix = array_pop($chunks);
|
||||
$uniqid = md5(implode('-', $chunks));
|
||||
|
||||
$fs->rename($file->getRealPath(), $app['root.path'].'/config/status/' . $uniqid . '-' . $suffix);
|
||||
|
||||
if ($fs->exists($app['root.path'] . '/www/custom/status/' . $file->getFileName())) {
|
||||
$fs->remove($app['root.path'] . '/www/custom/status/' . $file->getFileName());
|
||||
}
|
||||
}
|
||||
|
||||
$app['filesystem']->mirror($app['root.path'] . '/config/status/', $app['root.path'] . '/www/custom/status/');
|
||||
}
|
||||
}
|
68
lib/classes/patch/384alpha3a.php
Normal file
68
lib/classes/patch/384alpha3a.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
class patch_384alpha3a implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.8.4-alpha.3';
|
||||
|
||||
/** @var array */
|
||||
private $concern = array(base::APPLICATION_BOX);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$config = $app['phraseanet.configuration']->getConfig();
|
||||
|
||||
$config['api_cors'] = array(
|
||||
'enabled' => false,
|
||||
'allow_credentials' => false,
|
||||
'allow_origin' => array(),
|
||||
'allow_headers' => array(),
|
||||
'allow_methods' => array(),
|
||||
'expose_headers' => array(),
|
||||
'max_age' => 0,
|
||||
'hosts' => array(),
|
||||
);
|
||||
|
||||
$app['phraseanet.configuration']->setConfig($config);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
62
lib/classes/patch/384alpha4a.php
Normal file
62
lib/classes/patch/384alpha4a.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
class patch_384alpha4a implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.8.4-alpha.4';
|
||||
|
||||
/** @var array */
|
||||
private $concern = array(base::APPLICATION_BOX);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$config = $app['phraseanet.configuration']->getConfig();
|
||||
|
||||
$config['session'] = array(
|
||||
'idle' => 0,
|
||||
'lifetime' => 604800,
|
||||
);
|
||||
|
||||
$app['phraseanet.configuration']->setConfig($config);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
57
lib/classes/patch/384alpha5a.php
Normal file
57
lib/classes/patch/384alpha5a.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
class patch_384alpha5a implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.8.4-alpha.5';
|
||||
|
||||
/** @var array */
|
||||
private $concern = array(base::DATA_BOX);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $databox, Application $app)
|
||||
{
|
||||
$sql = "UPDATE log_docs SET `action`='mail' WHERE `action`='download' AND LOCATE('@', comment)";
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -895,12 +895,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
||||
}
|
||||
|
||||
if (count($fields_to_retrieve) > 0) {
|
||||
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine, false, $options);
|
||||
$titles = [];
|
||||
foreach ($retrieved_fields as $key => $value) {
|
||||
if (trim($value['value'] === ''))
|
||||
continue;
|
||||
$titles[] = $value['value'];
|
||||
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine);
|
||||
$titles = array();
|
||||
foreach ($retrieved_fields as $value) {
|
||||
foreach ($value['values'] as $v) {
|
||||
$titles[] = $v['value'];
|
||||
}
|
||||
}
|
||||
$title = trim(implode(' - ', $titles));
|
||||
}
|
||||
|
@@ -463,7 +463,7 @@ class record_preview extends record_adapter
|
||||
|
||||
$width = 350;
|
||||
$height = 150;
|
||||
$url = Url::factory('http://chart.apis.google.com/chart?' .
|
||||
$url = Url::factory('https://chart.googleapis.com/chart?' .
|
||||
'chs=' . $width . 'x' . $height .
|
||||
'&chd=t:' . implode(',', $views) .
|
||||
'&cht=lc' .
|
||||
@@ -544,7 +544,7 @@ class record_preview extends record_adapter
|
||||
$width = 550;
|
||||
$height = 100;
|
||||
|
||||
$url = Url::factory('http://chart.apis.google.com/chart?'
|
||||
$url = Url::factory('https://chart.googleapis.com/chart?'
|
||||
. 'cht=p3&chf=bg,s,00000000&chd=t:'
|
||||
. implode(',', $referrers)
|
||||
. '&chs=' . $width . 'x' . $height
|
||||
@@ -619,7 +619,7 @@ class record_preview extends record_adapter
|
||||
|
||||
$width = 250;
|
||||
$height = 150;
|
||||
$url = Url::factory('http://chart.apis.google.com/chart?' .
|
||||
$url = Url::factory('https://chart.googleapis.com/chart?' .
|
||||
'chs=' . $width . 'x' . $height .
|
||||
'&chd=t:' . implode(',', $dwnls) .
|
||||
'&cht=lc' .
|
||||
|
@@ -761,12 +761,7 @@ class set_export extends set_abstract
|
||||
$tmplog = [];
|
||||
$files = $list['files'];
|
||||
|
||||
$event_names = [
|
||||
'mail-export' => Session_Logger::EVENT_EXPORTMAIL,
|
||||
'download' => Session_Logger::EVENT_EXPORTDOWNLOAD
|
||||
];
|
||||
|
||||
$event_name = isset($event_names[$type]) ? $event_names[$type] : Session_Logger::EVENT_EXPORTDOWNLOAD;
|
||||
$event_name = in_array($type, array(Session_Logger::EVENT_EXPORTMAIL,Session_Logger::EVENT_EXPORTDOWNLOAD)) ? $type : Session_Logger::EVENT_EXPORTDOWNLOAD;
|
||||
|
||||
foreach ($files as $record) {
|
||||
foreach ($record["subdefs"] as $o => $obj) {
|
||||
@@ -774,8 +769,7 @@ class set_export extends set_abstract
|
||||
|
||||
$record_object = new record_adapter($app, $sbas_id, $record['record_id']);
|
||||
|
||||
$app['phraseanet.logger']($record_object->get_databox())
|
||||
->log($record_object, $event_name, $o, $comment);
|
||||
$app['phraseanet.logger']($record_object->get_databox())->log($record_object, $event_name, $o, $comment);
|
||||
|
||||
if ($o != "caption") {
|
||||
$log["rid"] = $record_object->get_record_id();
|
||||
@@ -792,6 +786,12 @@ class set_export extends set_abstract
|
||||
}
|
||||
}
|
||||
|
||||
$export_types = array(
|
||||
'download' => 0,
|
||||
'mail-export' => 2,
|
||||
'ftp' => 4
|
||||
);
|
||||
|
||||
$list_base = array_unique(array_keys($tmplog));
|
||||
|
||||
if (!$anonymous) {
|
||||
|
144
lib/classes/task/period/apiwebhooks.php
Normal file
144
lib/classes/task/period/apiwebhooks.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Guzzle\Http\Client as GuzzleClient;
|
||||
|
||||
class task_period_apiwebhooks extends task_appboxAbstract
|
||||
{
|
||||
public static function getName()
|
||||
{
|
||||
return _('Api Webhook');
|
||||
}
|
||||
|
||||
public static function help()
|
||||
{
|
||||
return _('Notify Phraseanet Oauth2 client applications using webhooks.');
|
||||
}
|
||||
|
||||
protected function retrieveContent(appbox $appbox)
|
||||
{
|
||||
$stmt = $appbox->get_connection()->prepare('SELECT id, `type`, `data` FROM api_webhooks');
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
protected function processOneContent(appbox $appbox, array $row)
|
||||
{
|
||||
$data = null;
|
||||
switch ($row['type']) {
|
||||
case \API_Webhook::NEW_FEED_ENTRY:
|
||||
$data = $this->processNewFeedEntry($row);
|
||||
}
|
||||
|
||||
if (null === $data) {
|
||||
return;
|
||||
}
|
||||
$urls = $this->getApplicationHookUrls($appbox);
|
||||
$this->sendData($urls, $data);
|
||||
}
|
||||
|
||||
protected function postProcessOneContent(appbox $appbox, array $row)
|
||||
{
|
||||
$w = new API_Webhook($appbox, $row['id']);
|
||||
$w->delete();
|
||||
}
|
||||
|
||||
protected function getApplicationHookUrls(appbox $appbox)
|
||||
{
|
||||
$stmt = $appbox->get_connection()->prepare('
|
||||
SELECT webhook_url
|
||||
FROM api_applications
|
||||
WHERE webhook_url IS NOT NULL
|
||||
');
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return array_map(function ($row) {
|
||||
return $row['webhook_url'];
|
||||
}, $rows);
|
||||
}
|
||||
|
||||
protected function sendData(array $urls, array $data)
|
||||
{
|
||||
if (count($urls) === 0) {
|
||||
return;
|
||||
}
|
||||
$client = new GuzzleClient();
|
||||
$body = json_encode($data);
|
||||
$requests = array();
|
||||
foreach ($urls as $url) {
|
||||
$requests[] = $client->createRequest('POST', $url, array(
|
||||
'Content-Type' => 'application/vnd.phraseanet.event+json'
|
||||
), $body);
|
||||
}
|
||||
$client->send($requests);
|
||||
}
|
||||
|
||||
protected function processNewFeedEntry(array $row)
|
||||
{
|
||||
$data = json_decode($row['data']);
|
||||
if (!isset($data->{"feed_id"}) || !isset($data->{"entry_id"})) {
|
||||
return;
|
||||
}
|
||||
$feed = new Feed_Adapter($this->dependencyContainer, $data->{"feed_id"});
|
||||
$entry = new \Feed_Entry_Adapter($this->dependencyContainer, $feed, $data->{"entry_id"});
|
||||
$query = new \User_Query($this->dependencyContainer);
|
||||
|
||||
$query->include_phantoms(true)
|
||||
->include_invite(false)
|
||||
->include_templates(false)
|
||||
->email_not_null(true);
|
||||
|
||||
if ($entry->get_feed()->get_collection()) {
|
||||
$query->on_base_ids(array($entry->get_feed()->get_collection()->get_base_id()));
|
||||
}
|
||||
|
||||
$start = 0;
|
||||
$perLoop = 100;
|
||||
$users = array();
|
||||
|
||||
do {
|
||||
$results = $query->limit($start, $perLoop)->execute()->get_results();
|
||||
foreach ($results as $user) {
|
||||
$users[] = array(
|
||||
'email' => $user->get_email(),
|
||||
'firstname' => $user->get_firstname() ?: null,
|
||||
'lastname' => $user->get_lastname() ?: null,
|
||||
);
|
||||
}
|
||||
$start += $perLoop;
|
||||
} while (count($results) > 0);
|
||||
|
||||
return array(
|
||||
'event' => $row['type'],
|
||||
'users_were_notified' => !!$data->{"notify_email"},
|
||||
'feed' => array(
|
||||
'id' => $feed->get_id(),
|
||||
'title' => $feed->get_title(),
|
||||
'description' => $feed->get_subtitle() ?: null,
|
||||
),
|
||||
'entry' => array(
|
||||
'id' => $entry->get_id(),
|
||||
'author' => array(
|
||||
'name' => $entry->get_author_name(),
|
||||
'email' => $entry->get_author_email()
|
||||
),
|
||||
'title' => $entry->get_title(),
|
||||
'description' => $entry->get_subtitle() ?: null,
|
||||
),
|
||||
'users' => $users
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user