Applications cleanup

This commit is contained in:
Romain Neutron
2012-09-28 10:07:04 +02:00
parent 76e6d4015f
commit d5325dba2b
8 changed files with 1301 additions and 1555 deletions

View File

@@ -1,58 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Controller\Admin\Collection;
use Alchemy\Phrasea\Controller\Admin\ConnectedUsers;
use Alchemy\Phrasea\Controller\Admin\Dashboard;
use Alchemy\Phrasea\Controller\Admin\Databox;
use Alchemy\Phrasea\Controller\Admin\Databoxes;
use Alchemy\Phrasea\Controller\Admin\Description;
use Alchemy\Phrasea\Controller\Admin\Fields;
use Alchemy\Phrasea\Controller\Admin\Publications;
use Alchemy\Phrasea\Controller\Admin\Root;
use Alchemy\Phrasea\Controller\Admin\Setup;
use Alchemy\Phrasea\Controller\Admin\Sphinx;
use Alchemy\Phrasea\Controller\Admin\Subdefs;
use Alchemy\Phrasea\Controller\Admin\Users;
use Alchemy\Phrasea\Controller\Admin\TaskManager;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest;
use Silex\ControllerProviderInterface;
use Silex\Application As SilexApplication;
class Admin implements ControllerProviderInterface
{
public function connect(SilexApplication $app)
{
$controllers = $app['controllers_factory'];
$controllers->mount('/', new Root());
$controllers->mount('/dashboard', new Dashboard());
$controllers->mount('/collection', new Collection());
$controllers->mount('/databox', new Databox());
$controllers->mount('/databoxes', new Databoxes());
$controllers->mount('/setup', new Setup());
$controllers->mount('/sphinx', new Sphinx());
$controllers->mount('/connected-users', new ConnectedUsers());
$controllers->mount('/publications', new Publications());
$controllers->mount('/users', new Users());
$controllers->mount('/fields', new Fields());
$controllers->mount('/subdefs', new Subdefs());
$controllers->mount('/description', new Description());
$controllers->mount('/tests/connection', new ConnectionTest());
$controllers->mount('/tests/pathurl', new PathFileTest());
return $controllers;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -15,45 +15,35 @@ use Silex\Application as SilexApplication;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Symfony\Component\HttpFoundation\Request;
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
return call_user_func(function() {
$app = new PhraseaApplication();
return call_user_func(function($environment = 'prod') {
$app->get('/', function(Request $request, SilexApplication $app) {
$registry = $app['phraseanet.registry'];
$app = new PhraseaApplication($environment);
$apiAdapter = new \API_V1_adapter($app);
$app->get('/', function(Request $request, SilexApplication $app) {
$apiAdapter = new \API_V1_adapter($app);
$result = new \API_V1_result($request, $apiAdapter);
$result = new \API_V1_result($request, $apiAdapter);
return $result->set_datas(
array(
'name' => $registry->get('GV_homeTitle'),
'type' => 'phraseanet',
'description' => $registry->get('GV_metaDescription'),
'documentation' => 'https://docs.phraseanet.com/Devel',
'versions' => array(
'1' => array(
'number' => $apiAdapter->get_version(),
'uri' => '/api/v1/',
'authenticationProtocol' => 'OAuth2',
'authenticationVersion' => 'draft#v9',
'authenticationEndPoints' => array(
'authorization_token' => '/api/oauthv2/authorize',
'access_token' => '/api/oauthv2/token'
)
)
)
)
)->get_response();
});
return $result->set_datas(array(
'name' => $app['phraseanet.registry']->get('GV_homeTitle'),
'type' => 'phraseanet',
'description' => $app['phraseanet.registry']->get('GV_metaDescription'),
'documentation' => 'https://docs.phraseanet.com/Devel',
'versions' => array(
'1' => array(
'number' => $apiAdapter->get_version(),
'uri' => '/api/v1/',
'authenticationProtocol' => 'OAuth2',
'authenticationVersion' => 'draft#v9',
'authenticationEndPoints' => array(
'authorization_token' => '/api/oauthv2/authorize',
'access_token' => '/api/oauthv2/token'
)
)
)
))->get_response();
});
return $app;
}
);
return $app;
}, isset($environment) ? $environment : null);

View File

@@ -18,451 +18,436 @@ use Symfony\Component\HttpFoundation\Response;
class Lightbox implements ControllerProviderInterface
{
public function connect(SilexApplication $app)
{
$controllers = $app['controllers_factory'];
$controllers->get('/', function (SilexApplication $app) {
\User_Adapter::updateClientInfos($app, 6);
\User_Adapter::updateClientInfos($app, 6);
$repository = $app['EM']->getRepository('\Entities\Basket');
$repository = $app['EM']->getRepository('\Entities\Basket');
$current_user = $app['phraseanet.user'];
/* @var $repository \Repositories\BasketRepository */
/* @var $repository \Repositories\BasketRepository */
$basket_collection = array_merge(
$repository->findActiveByUser($app['phraseanet.user'])
, $repository->findActiveValidationByUser($app['phraseanet.user'])
);
$basket_collection = array_merge(
$repository->findActiveByUser($app['phraseanet.user'])
, $repository->findActiveValidationByUser($current_user)
);
$template = 'lightbox/index.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/index.html.twig';
}
return new Response($app['twig']->render($template, array(
'baskets_collection' => $basket_collection,
'module_name' => 'Lightbox',
'module' => 'lightbox'
)
));
$template = 'lightbox/index.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/index.html.twig';
}
);
return new Response($app['twig']->render($template, array(
'baskets_collection' => $basket_collection,
'module_name' => 'Lightbox',
'module' => 'lightbox'
)
));
});
$controllers->get('/ajax/NOTE_FORM/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) {
if (!$app['browser']->isMobile()) {
return new Response('');
}
$basketElement = $app['EM']
->getRepository('\Entities\BasketElement')
->findUserElement($sselcont_id, $app['phraseanet.user']);
$parameters = array(
'basket_element' => $basketElement,
'module_name' => '',
);
return $app['twig']->render('lightbox/note_form.html.twig', $parameters);
if (!$app['browser']->isMobile()) {
return new Response('');
}
)->assert('sselcont_id', '\d+');
$basketElement = $app['EM']
->getRepository('\Entities\BasketElement')
->findUserElement($sselcont_id, $app['phraseanet.user']);
$parameters = array(
'basket_element' => $basketElement,
'module_name' => '',
);
return $app['twig']->render('lightbox/note_form.html.twig', $parameters);
})->assert('sselcont_id', '\d+');
$controllers->get('/ajax/LOAD_BASKET_ELEMENT/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) {
/* @var $repository \Repositories\BasketElementRepository */
$repository = $app['EM']->getRepository('\Entities\BasketElement');
/* @var $repository \Repositories\BasketElementRepository */
$repository = $app['EM']->getRepository('\Entities\BasketElement');
$BasketElement = $repository->findUserElement($sselcont_id, $app['phraseanet.user']);
$BasketElement = $repository->findUserElement($sselcont_id, $app['phraseanet.user']);
if ($app['browser']->isMobile()) {
$output = $app['twig']->render('lightbox/basket_element.html.twig', array(
'basket_element' => $BasketElement,
'module_name' => $BasketElement->getRecord($app)->get_title()
)
);
return new Response($output);
} else {
$template_options = 'lightbox/sc_options_box.html.twig';
$template_agreement = 'lightbox/agreement_box.html.twig';
$template_selector = 'lightbox/selector_box.html.twig';
$template_note = 'lightbox/sc_note.html.twig';
$template_preview = 'common/preview.html.twig';
$template_caption = 'common/caption.html.twig';
if (!$app['browser']->isNewGeneration()) {
$template_options = 'lightbox/IE6/sc_options_box.html.twig';
$template_agreement = 'lightbox/IE6/agreement_box.html.twig';
}
$Basket = $BasketElement->getBasket();
$ret = array();
$ret['number'] = $BasketElement->getRecord($app)->get_number();
$ret['title'] = $BasketElement->getRecord($app)->get_title();
$ret['preview'] = $app['twig']->render($template_preview, array('record' => $BasketElement->getRecord($app), 'not_wrapped' => true));
$ret['options_html'] = $app['twig']->render($template_options, array('basket_element' => $BasketElement));
$ret['agreement_html'] = $app['twig']->render($template_agreement, array('basket' => $Basket, 'basket_element' => $BasketElement));
$ret['selector_html'] = $app['twig']->render($template_selector, array('basket_element' => $BasketElement));
$ret['note_html'] = $app['twig']->render($template_note, array('basket_element' => $BasketElement));
$ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $BasketElement->getRecord($app)));
return $app->json($ret);
}
}
)->assert('sselcont_id', '\d+');
$controllers->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function(SilexApplication $app, $entry_id, $item_id) {
$entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id);
$item = new \Feed_Entry_Item($app['phraseanet.appbox'], $entry, $item_id);
if ($app['browser']->isMobile()) {
$output = $app['twig']->render('lightbox/feed_element.html.twig', array(
'feed_element' => $item,
'module_name' => $item->get_record()->get_title()
)
);
return new Response($output);
} else {
$template_options = 'lightbox/feed_options_box.html.twig';
$template_preview = 'common/preview.html.twig';
$template_caption = 'common/caption.html.twig';
if (!$app['browser']->isNewGeneration()) {
$template_options = 'lightbox/IE6/feed_options_box.html.twig';
}
$ret = array();
$ret['number'] = $item->get_record()->get_number();
$ret['title'] = $item->get_record()->get_title();
$ret['preview'] = $app['twig']->render($template_preview, array('record' => $item->get_record(), 'not_wrapped' => true));
$ret['options_html'] = $app['twig']->render($template_options, array('feed_element' => $item));
$ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $item->get_record()));
$ret['agreement_html'] = $ret['selector_html'] = $ret['note_html'] = '';
return $app->json($ret);
}
}
)->assert('entry_id', '\d+')->assert('item_id', '\d+');
$controllers->get('/validate/{ssel_id}/', function (SilexApplication $app, $ssel_id) {
\User_Adapter::updateClientInfos($app, 6);
$repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */
$basket_collection = $repository->findActiveValidationAndBasketByUser(
$app['phraseanet.user']
);
$basket = $repository->findUserBasket(
$app, $ssel_id
, $app['phraseanet.user']
, false
);
if ($basket->getIsRead() === false) {
$basket = $app['EM']->merge($basket);
$basket->setIsRead(true);
$app['EM']->flush();
}
if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->getIsAware() === false) {
$basket = $app['EM']->merge($basket);
$basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true);
$app['EM']->flush();
}
$template = 'lightbox/validate.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/validate.html.twig';
}
$response = new Response($app['twig']->render($template, array(
'baskets_collection' => $basket_collection,
'basket' => $basket,
'local_title' => strip_tags($basket->getName()),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
)
));
$response->setCharset('UTF-8');
return $response;
}
)->assert('ssel_id', '\d+');
$controllers->get('/compare/{ssel_id}/', function (SilexApplication $app, $ssel_id) {
\User_Adapter::updateClientInfos($app, 6);
$repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */
$basket_collection = $repository->findActiveValidationAndBasketByUser(
$app['phraseanet.user']
);
$basket = $repository->findUserBasket(
$app, $ssel_id
, $app['phraseanet.user']
, false
);
if ($basket->getIsRead() === false) {
$basket = $app['EM']->merge($basket);
$basket->setIsRead(true);
$app['EM']->flush();
}
if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'])->getIsAware() === false) {
$basket = $app['EM']->merge($basket);
$basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true);
$app['EM']->flush();
}
$template = 'lightbox/validate.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/validate.html.twig';
}
$response = new Response($app['twig']->render($template, array(
'baskets_collection' => $basket_collection,
'basket' => $basket,
'local_title' => strip_tags($basket->getName()),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
)
));
$response->setCharset('UTF-8');
return $response;
}
)->assert('ssel_id', '\d+');
$controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) {
\User_Adapter::updateClientInfos($app, 6);
$feed_entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id);
$template = 'lightbox/feed.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/feed.html.twig';
}
$content = $feed_entry->get_content();
$output = $app['twig']->render($template, array(
'feed_entry' => $feed_entry,
'first_item' => array_shift($content),
'local_title' => $feed_entry->get_title(),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
if ($app['browser']->isMobile()) {
$output = $app['twig']->render('lightbox/basket_element.html.twig', array(
'basket_element' => $BasketElement,
'module_name' => $BasketElement->getRecord($app)->get_title()
)
);
$response = new Response($output, 200);
$response->setCharset('UTF-8');
return $response;
}
)->assert('entry_id', '\d+');
return new Response($output);
} else {
$template_options = 'lightbox/sc_options_box.html.twig';
$template_agreement = 'lightbox/agreement_box.html.twig';
$template_selector = 'lightbox/selector_box.html.twig';
$template_note = 'lightbox/sc_note.html.twig';
$template_preview = 'common/preview.html.twig';
$template_caption = 'common/caption.html.twig';
$controllers->get('/ajax/LOAD_REPORT/{ssel_id}/', function(SilexApplication $app, $ssel_id) {
$template = 'lightbox/basket_content_report.html.twig';
$repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */
$basket = $repository->findUserBasket(
$app, $ssel_id
, $app['phraseanet.user']
, false
);
$response = new Response($app['twig']->render($template, array('basket' => $basket)));
$response->setCharset('UTF-8');
return $response;
}
)->assert('ssel_id', '\d+');
$controllers->post('/ajax/SET_NOTE/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) {
$output = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees'));
$request = $app['request'];
$note = $request->request->get('note');
if (is_null($note)) {
Return new Response('You must provide a note value', 400);
if (!$app['browser']->isNewGeneration()) {
$template_options = 'lightbox/IE6/sc_options_box.html.twig';
$template_agreement = 'lightbox/IE6/agreement_box.html.twig';
}
/* @var $repository \Repositories\BasketElementRepository */
$repository = $app['EM']->getRepository('\Entities\BasketElement');
$Basket = $BasketElement->getBasket();
$basket_element = $repository->findUserElement($sselcont_id, $app['phraseanet.user']);
$ret = array();
$ret['number'] = $BasketElement->getRecord($app)->get_number();
$ret['title'] = $BasketElement->getRecord($app)->get_title();
$validationDatas = $basket_element->getUserValidationDatas($app['phraseanet.user'], $app);
$validationDatas->setNote($note);
$app['EM']->merge($validationDatas);
$app['EM']->flush();
if ($app['browser']->isMobile()) {
$datas = $app['twig']->render('lightbox/sc_note.html.twig', array('basket_element' => $basket_element));
$output = array('error' => false, 'datas' => $datas);
} else {
$template = 'lightbox/sc_note.html.twig';
$datas = $app['twig']->render($template, array('basket_element' => $basket_element));
$output = array('error' => false, 'datas' => $datas);
}
return $app->json($output);
}
)->assert('sselcont_id', '\d+');
$controllers->post('/ajax/SET_ELEMENT_AGREEMENT/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) {
$request = $app['request'];
$agreement = $request->request->get('agreement');
if (is_null($agreement)) {
Return new Response('You must provide an agreement value', 400);
}
$agreement = $agreement > 0;
$releasable = false;
try {
$ret = array(
'error' => true,
'releasable' => false,
'datas' => _('Erreur lors de la mise a jour des donnes ')
);
$user = $app['phraseanet.user'];
$repository = $app['EM']->getRepository('\Entities\BasketElement');
/* @var $repository \Repositories\BasketElementRepository */
$basket_element = $repository->findUserElement(
$sselcont_id
, $user
);
/* @var $basket_element \Entities\BasketElement */
$validationDatas = $basket_element->getUserValidationDatas($user, $app);
if (!$basket_element->getBasket()
->getValidation()
->getParticipant($user, $app)->getCanAgree()) {
throw new ControllerException('You can not agree on this');
}
$validationDatas->setAgreement($agreement);
$participant = $basket_element->getBasket()
->getValidation()
->getParticipant($user, $app);
$app['EM']->merge($basket_element);
$app['EM']->flush();
$releasable = false;
if ($participant->isReleasable() === true) {
$releasable = _('Do you want to send your report ?');
}
$ret = array(
'error' => false
, 'datas' => ''
, 'releasable' => $releasable
);
} catch (ControllerException $e) {
$ret['datas'] = $e->getMessage();
}
$ret['preview'] = $app['twig']->render($template_preview, array('record' => $BasketElement->getRecord($app), 'not_wrapped' => true));
$ret['options_html'] = $app['twig']->render($template_options, array('basket_element' => $BasketElement));
$ret['agreement_html'] = $app['twig']->render($template_agreement, array('basket' => $Basket, 'basket_element' => $BasketElement));
$ret['selector_html'] = $app['twig']->render($template_selector, array('basket_element' => $BasketElement));
$ret['note_html'] = $app['twig']->render($template_note, array('basket_element' => $BasketElement));
$ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $BasketElement->getRecord($app)));
return $app->json($ret);
}
)->assert('sselcont_id', '\d+');
})->assert('sselcont_id', '\d+');
$controllers->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function(SilexApplication $app, $entry_id, $item_id) {
$entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id);
$item = new \Feed_Entry_Item($app['phraseanet.appbox'], $entry, $item_id);
if ($app['browser']->isMobile()) {
$output = $app['twig']->render('lightbox/feed_element.html.twig', array(
'feed_element' => $item,
'module_name' => $item->get_record()->get_title()
)
);
return new Response($output);
} else {
$template_options = 'lightbox/feed_options_box.html.twig';
$template_preview = 'common/preview.html.twig';
$template_caption = 'common/caption.html.twig';
if (!$app['browser']->isNewGeneration()) {
$template_options = 'lightbox/IE6/feed_options_box.html.twig';
}
$ret = array();
$ret['number'] = $item->get_record()->get_number();
$ret['title'] = $item->get_record()->get_title();
$ret['preview'] = $app['twig']->render($template_preview, array('record' => $item->get_record(), 'not_wrapped' => true));
$ret['options_html'] = $app['twig']->render($template_options, array('feed_element' => $item));
$ret['caption'] = $app['twig']->render($template_caption, array('view' => 'preview', 'record' => $item->get_record()));
$ret['agreement_html'] = $ret['selector_html'] = $ret['note_html'] = '';
return $app->json($ret);
}
})->assert('entry_id', '\d+')->assert('item_id', '\d+');
$controllers->get('/validate/{ssel_id}/', function (SilexApplication $app, $ssel_id) {
\User_Adapter::updateClientInfos($app, 6);
$repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */
$basket_collection = $repository->findActiveValidationAndBasketByUser(
$app['phraseanet.user']
);
$basket = $repository->findUserBasket(
$app, $ssel_id
, $app['phraseanet.user']
, false
);
if ($basket->getIsRead() === false) {
$basket = $app['EM']->merge($basket);
$basket->setIsRead(true);
$app['EM']->flush();
}
if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->getIsAware() === false) {
$basket = $app['EM']->merge($basket);
$basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true);
$app['EM']->flush();
}
$template = 'lightbox/validate.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/validate.html.twig';
}
$response = new Response($app['twig']->render($template, array(
'baskets_collection' => $basket_collection,
'basket' => $basket,
'local_title' => strip_tags($basket->getName()),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
)
));
$response->setCharset('UTF-8');
return $response;
})->assert('ssel_id', '\d+');
$controllers->get('/compare/{ssel_id}/', function (SilexApplication $app, $ssel_id) {
\User_Adapter::updateClientInfos($app, 6);
$repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */
$basket_collection = $repository->findActiveValidationAndBasketByUser(
$app['phraseanet.user']
);
$basket = $repository->findUserBasket(
$app, $ssel_id
, $app['phraseanet.user']
, false
);
if ($basket->getIsRead() === false) {
$basket = $app['EM']->merge($basket);
$basket->setIsRead(true);
$app['EM']->flush();
}
if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['phraseanet.user'])->getIsAware() === false) {
$basket = $app['EM']->merge($basket);
$basket->getValidation()->getParticipant($app['phraseanet.user'], $app)->setIsAware(true);
$app['EM']->flush();
}
$template = 'lightbox/validate.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/validate.html.twig';
}
$response = new Response($app['twig']->render($template, array(
'baskets_collection' => $basket_collection,
'basket' => $basket,
'local_title' => strip_tags($basket->getName()),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
)
));
$response->setCharset('UTF-8');
return $response;
})->assert('ssel_id', '\d+');
$controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) {
\User_Adapter::updateClientInfos($app, 6);
$feed_entry = \Feed_Entry_Adapter::load_from_id($app, $entry_id);
$template = 'lightbox/feed.html.twig';
if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
$template = 'lightbox/IE6/feed.html.twig';
}
$content = $feed_entry->get_content();
$output = $app['twig']->render($template, array(
'feed_entry' => $feed_entry,
'first_item' => array_shift($content),
'local_title' => $feed_entry->get_title(),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
)
);
$response = new Response($output, 200);
$response->setCharset('UTF-8');
return $response;
})->assert('entry_id', '\d+');
$controllers->get('/ajax/LOAD_REPORT/{ssel_id}/', function(SilexApplication $app, $ssel_id) {
$template = 'lightbox/basket_content_report.html.twig';
$repository = $app['EM']->getRepository('\Entities\Basket');
/* @var $repository \Repositories\BasketRepository */
$basket = $repository->findUserBasket(
$app, $ssel_id
, $app['phraseanet.user']
, false
);
$response = new Response($app['twig']->render($template, array('basket' => $basket)));
$response->setCharset('UTF-8');
return $response;
})->assert('ssel_id', '\d+');
$controllers->post('/ajax/SET_NOTE/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) {
$output = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees'));
$request = $app['request'];
$note = $request->request->get('note');
if (is_null($note)) {
Return new Response('You must provide a note value', 400);
}
/* @var $repository \Repositories\BasketElementRepository */
$repository = $app['EM']->getRepository('\Entities\BasketElement');
$basket_element = $repository->findUserElement($sselcont_id, $app['phraseanet.user']);
$validationDatas = $basket_element->getUserValidationDatas($app['phraseanet.user'], $app);
$validationDatas->setNote($note);
$app['EM']->merge($validationDatas);
$app['EM']->flush();
if ($app['browser']->isMobile()) {
$datas = $app['twig']->render('lightbox/sc_note.html.twig', array('basket_element' => $basket_element));
$output = array('error' => false, 'datas' => $datas);
} else {
$template = 'lightbox/sc_note.html.twig';
$datas = $app['twig']->render($template, array('basket_element' => $basket_element));
$output = array('error' => false, 'datas' => $datas);
}
return $app->json($output);
})->assert('sselcont_id', '\d+');
$controllers->post('/ajax/SET_ELEMENT_AGREEMENT/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) {
$request = $app['request'];
$agreement = $request->request->get('agreement');
if (is_null($agreement)) {
Return new Response('You must provide an agreement value', 400);
}
$agreement = $agreement > 0;
$releasable = false;
try {
$ret = array(
'error' => true,
'releasable' => false,
'datas' => _('Erreur lors de la mise a jour des donnes ')
);
$user = $app['phraseanet.user'];
$repository = $app['EM']->getRepository('\Entities\BasketElement');
/* @var $repository \Repositories\BasketElementRepository */
$basket_element = $repository->findUserElement(
$sselcont_id
, $user
);
/* @var $basket_element \Entities\BasketElement */
$validationDatas = $basket_element->getUserValidationDatas($user, $app);
if (!$basket_element->getBasket()
->getValidation()
->getParticipant($user, $app)->getCanAgree()) {
throw new ControllerException('You can not agree on this');
}
$validationDatas->setAgreement($agreement);
$participant = $basket_element->getBasket()
->getValidation()
->getParticipant($user, $app);
$app['EM']->merge($basket_element);
$app['EM']->flush();
$releasable = false;
if ($participant->isReleasable() === true) {
$releasable = _('Do you want to send your report ?');
}
$ret = array(
'error' => false
, 'datas' => ''
, 'releasable' => $releasable
);
} catch (ControllerException $e) {
$ret['datas'] = $e->getMessage();
}
return $app->json($ret);
})->assert('sselcont_id', '\d+');
$controllers->post('/ajax/SET_RELEASE/{ssel_id}/', function(SilexApplication $app, $ssel_id) {
$user = $app['phraseanet.user'];
$user = $app['phraseanet.user'];
$repository = $app['EM']->getRepository('\Entities\Basket');
$repository = $app['EM']->getRepository('\Entities\Basket');
$datas = array('error' => true, 'datas' => '');
$datas = array('error' => true, 'datas' => '');
try {
/* @var $repository \Repositories\BasketRepository */
$basket = $repository->findUserBasket(
$app, $ssel_id
, $user
, false
);
try {
/* @var $repository \Repositories\BasketRepository */
$basket = $repository->findUserBasket(
$app, $ssel_id
, $user
, false
);
if (!$basket->getValidation()) {
throw new ControllerException('There is no validation session attached to this basket');
}
if (!$basket->getValidation()->getParticipant($user, $app)->getCanAgree()) {
throw new ControllerException('You have not right to agree');
}
/* @var $basket \Entities\Basket */
$participant = $basket->getValidation()->getParticipant($user, $app);
$evt_mngr = $app['events-manager'];
$expires = new \DateTime('+10 days');
$url = $app['phraseanet.appbox']->get_registry()->get('GV_ServerName')
. 'lightbox/index.php?LOG=' . \random::getUrlToken(
$app, \random::TYPE_VALIDATE
, $basket->getValidation()->getInitiator($app)->get_id()
, $expires
, $basket->getId()
);
$to = $basket->getValidation()->getInitiator($app)->get_id();
$params = array(
'ssel_id' => $basket->getId(),
'from' => $app['phraseanet.user']->get_id(),
'url' => $url,
'to' => $to
);
$evt_mngr->trigger('__VALIDATION_DONE__', $params);
$participant->setIsConfirmed(true);
$app['EM']->merge($participant);
$app['EM']->flush();
$datas = array('error' => false, 'datas' => _('Envoie avec succes'));
} catch (ControllerException $e) {
$datas = array('error' => true, 'datas' => $e->getMessage());
if (!$basket->getValidation()) {
throw new ControllerException('There is no validation session attached to this basket');
}
return $app->json($datas);
if (!$basket->getValidation()->getParticipant($user, $app)->getCanAgree()) {
throw new ControllerException('You have not right to agree');
}
/* @var $basket \Entities\Basket */
$participant = $basket->getValidation()->getParticipant($user, $app);
$evt_mngr = $app['events-manager'];
$expires = new \DateTime('+10 days');
$url = $app['phraseanet.appbox']->get_registry()->get('GV_ServerName')
. 'lightbox/index.php?LOG=' . \random::getUrlToken(
$app, \random::TYPE_VALIDATE
, $basket->getValidation()->getInitiator($app)->get_id()
, $expires
, $basket->getId()
);
$to = $basket->getValidation()->getInitiator($app)->get_id();
$params = array(
'ssel_id' => $basket->getId(),
'from' => $app['phraseanet.user']->get_id(),
'url' => $url,
'to' => $to
);
$evt_mngr->trigger('__VALIDATION_DONE__', $params);
$participant->setIsConfirmed(true);
$app['EM']->merge($participant);
$app['EM']->flush();
$datas = array('error' => false, 'datas' => _('Envoie avec succes'));
} catch (ControllerException $e) {
$datas = array('error' => true, 'datas' => $e->getMessage());
}
)->assert('ssel_id', '\d+');
return $app->json($datas);
})->assert('ssel_id', '\d+');
return $controllers;
}

View File

@@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request;
/**
*
*
* @package OAuth2 Connector
*
@@ -30,145 +29,144 @@ use Symfony\Component\HttpFoundation\Request;
*/
return call_user_func(function($environment = 'prod') {
$app = new PhraseaApplication($environment);
$app = new PhraseaApplication($environment);
$app['oauth'] = function($app) {
return new \API_OAuth2_Adapter($app);
};
$app['oauth'] = function($app) {
return new \API_OAuth2_Adapter($app);
};
/**
* AUTHORIZE ENDPOINT
*
* Authorization endpoint - used to obtain authorization from the
* resource owner via user-agent redirection.
*/
$authorize_func = function() use ($app) {
$request = $app['request'];
$oauth2_adapter = $app['oauth'];
/**
* AUTHORIZE ENDPOINT
*
* Authorization endpoint - used to obtain authorization from the
* resource owner via user-agent redirection.
*/
$authorize_func = function() use ($app) {
$request = $app['request'];
$oauth2_adapter = $app['oauth'];
//Check for auth params, send error or redirect if not valid
$params = $oauth2_adapter->getAuthorizationRequestParameters($request);
//Check for auth params, send error or redirect if not valid
$params = $oauth2_adapter->getAuthorizationRequestParameters($request);
$app_authorized = false;
$errorMessage = false;
$app_authorized = false;
$errorMessage = false;
$client = \API_OAuth2_Application::load_from_client_id($app, $params['client_id']);
$client = \API_OAuth2_Application::load_from_client_id($app, $params['client_id']);
$oauth2_adapter->setClient($client);
$oauth2_adapter->setClient($client);
$action_accept = $request->get("action_accept");
$action_login = $request->get("action_login");
$action_accept = $request->get("action_accept");
$action_login = $request->get("action_login");
$template = "api/auth/end_user_authorization.html.twig";
$template = "api/auth/end_user_authorization.html.twig";
$custom_template = sprintf(
"%sconfig/templates/web/api/auth/end_user_authorization/%s.html.twig"
, $app['phraseanet.appbox']->get_registry()->get('GV_RootPath')
, $client->get_id()
$custom_template = sprintf(
"%sconfig/templates/web/api/auth/end_user_authorization/%s.html.twig"
, $app['phraseanet.appbox']->get_registry()->get('GV_RootPath')
, $client->get_id()
);
if (file_exists($custom_template)) {
$template = sprintf(
'api/auth/end_user_authorization/%s.html.twig'
, $client->get_id()
);
}
if (!$app->isAuthenticated()) {
if ($action_login !== null) {
try {
$auth = new \Session_Authentication_Native(
$app, $request->get("login"), $request->get("password")
);
if (file_exists($custom_template)) {
$template = sprintf(
'api/auth/end_user_authorization/%s.html.twig'
, $client->get_id()
);
}
$app->openAccount($auth);
} catch (\Exception $e) {
if (!$app->isAuthenticated()) {
if ($action_login !== null) {
try {
$auth = new \Session_Authentication_Native(
$app, $request->get("login"), $request->get("password")
);
return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter)));
}
} else {
return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter)));
}
}
$app->openAccount($auth);
} catch (\Exception $e) {
//check if current client is already authorized by current user
$user_auth_clients = \API_OAuth2_Application::load_authorized_app_by_user(
$app
, $app['phraseanet.user']
);
return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter)));
}
} else {
return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter)));
}
}
foreach ($user_auth_clients as $auth_client) {
if ($client->get_client_id() == $auth_client->get_client_id()) {
$app_authorized = true;
}
}
//check if current client is already authorized by current user
$user_auth_clients = \API_OAuth2_Application::load_authorized_app_by_user(
$app
, $app['phraseanet.user']
);
$account = $oauth2_adapter->updateAccount($app['phraseanet.user']->get_id());
foreach ($user_auth_clients as $auth_client) {
if ($client->get_client_id() == $auth_client->get_client_id()) {
$app_authorized = true;
}
}
$params['account_id'] = $account->get_id();
$account = $oauth2_adapter->updateAccount($app['phraseanet.user']->get_id());
if (!$app_authorized && $action_accept === null) {
$params = array(
"auth" => $oauth2_adapter,
"errorMessage" => $errorMessage,
);
$params['account_id'] = $account->get_id();
return new Response($app['twig']->render($template, $params));
} elseif (!$app_authorized && $action_accept !== null) {
$app_authorized = (Boolean) $action_accept;
$account->set_revoked(!$app_authorized);
}
if (!$app_authorized && $action_accept === null) {
$params = array(
"auth" => $oauth2_adapter,
"errorMessage" => $errorMessage,
);
//if native app show template
if ($oauth2_adapter->isNativeApp($params['redirect_uri'])) {
$params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params);
return new Response($app['twig']->render($template, $params));
} elseif (!$app_authorized && $action_accept !== null) {
$app_authorized = (Boolean) $action_accept;
$account->set_revoked(!$app_authorized);
}
return new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params));
} else {
$oauth2_adapter->finishClientAuthorization($app_authorized, $params);
}
};
//if native app show template
if ($oauth2_adapter->isNativeApp($params['redirect_uri'])) {
$params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params);
$app->match('/authorize', $authorize_func)->method('GET|POST');
return new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params));
} else {
$oauth2_adapter->finishClientAuthorization($app_authorized, $params);
}
};
/**
* TOKEN ENDPOINT
* Token endpoint - used to exchange an authorization grant for an access token.
*/
$app->post('/token', function(\Silex\Application $app, Request $request) {
$app->match('/authorize', $authorize_func)->method('GET|POST');
$app['oauth']->grantAccessToken();
ob_flush();
flush();
/**
* TOKEN ENDPOINT
* Token endpoint - used to exchange an authorization grant for an access token.
*/
$app->post('/token', function(\Silex\Application $app, Request $request) {
return;
})->requireHttps();
$app['oauth']->grantAccessToken();
ob_flush();
flush();
/**
* Error Handler
*/
$app->error(function (\Exception $e) use ($app) {
if ($e instanceof NotFoundHttpException || $e instanceof \Exception_NotFound) {
return new Response('The requested page could not be found.', 404, array('X-Status-Code' => 404));
}
return;
})->requireHttps();
$code = 500;
$msg = 'We are sorry, but something went wrong';
$headers = array();
/**
* Error Handler
*/
$app->error(function (\Exception $e) use ($app) {
if ($e instanceof NotFoundHttpException || $e instanceof \Exception_NotFound) {
return new Response('The requested page could not be found.', 404, array('X-Status-Code' => 404));
}
if ($e instanceof HttpExceptionInterface) {
$headers = $e->getHeaders();
$msg = $e->getMessage();
$code = $e->getStatusCode();
$code = 500;
$msg = 'We are sorry, but something went wrong';
$headers = array();
if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') {
$msg = json_encode(array('msg' => $msg, 'code' => $code));
}
}
if ($e instanceof HttpExceptionInterface) {
$headers = $e->getHeaders();
$msg = $e->getMessage();
$code = $e->getStatusCode();
return new Response($msg, $code, $headers);
});
if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') {
$msg = json_encode(array('msg' => $msg, 'code' => $code));
}
}
return new Response($msg, $code, $headers);
});
return $app;
}, $environment ? : null
);
return $app;
}, isset($environment) ? $environment : null);

View File

@@ -1,96 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Prod\Basket;
use Alchemy\Phrasea\Controller\Prod\Bridge;
use Alchemy\Phrasea\Controller\Prod\Edit;
use Alchemy\Phrasea\Controller\Prod\Feed;
use Alchemy\Phrasea\Controller\Prod\Language;
use Alchemy\Phrasea\Controller\Prod\Lazaret;
use Alchemy\Phrasea\Controller\Prod\MoveCollection;
use Alchemy\Phrasea\Controller\Prod\MustacheLoader;
use Alchemy\Phrasea\Controller\Prod\Order;
use Alchemy\Phrasea\Controller\Prod\Printer;
use Alchemy\Phrasea\Controller\Prod\Push;
use Alchemy\Phrasea\Controller\Prod\Query;
use Alchemy\Phrasea\Controller\Prod\Root;
use Alchemy\Phrasea\Controller\Prod\Story;
use Alchemy\Phrasea\Controller\Prod\Tools;
use Alchemy\Phrasea\Controller\Prod\Tooltip;
use Alchemy\Phrasea\Controller\Prod\TOU;
use Alchemy\Phrasea\Controller\Prod\Upload;
use Alchemy\Phrasea\Controller\Prod\UserPreferences;
use Alchemy\Phrasea\Controller\Prod\UsrLists;
use Alchemy\Phrasea\Controller\Prod\WorkZone;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
return call_user_func(function() {
$app = new PhraseaApplication();
$app->mount('/UserPreferences/', new UserPreferences());
$app->mount('/query/', new Query());
$app->mount('/order/', new Order());
$app->mount('/baskets', new Basket());
$app->mount('/story', new Story());
$app->mount('/WorkZone', new WorkZone());
$app->mount('/lists', new UsrLists());
$app->mount('/MustacheLoader', new MustacheLoader());
$app->mount('/records/edit', new Edit());
$app->mount('/records/movecollection', new MoveCollection());
$app->mount('/bridge/', new Bridge());
$app->mount('/push/', new Push());
$app->mount('/printer/', new Printer());
$app->mount('/TOU/', new TOU());
$app->mount('/feeds', new Feed());
$app->mount('/tooltip', new Tooltip());
$app->mount('/language', new Language());
$app->mount('/tools/', new Tools());
$app->mount('/lazaret/', new Lazaret());
$app->mount('/upload/', new Upload());
$app->mount('/', new Root());
$app->error(function (\Exception $e, $code) use ($app) {
/* @var $request \Symfony\Component\HttpFoundation\Request */
$request = $app['request'];
if ($request->getRequestFormat() == 'json') {
$datas = array(
'success' => false
, 'message' => $e->getMessage()
);
return $app->json($datas, 200, array('X-Status-Code' => 200));
}
if ($e instanceof \Exception_BadRequest) {
return new Response('Bad Request', 400, array('X-Status-Code' => 400));
}
if ($e instanceof \Exception_NotFound) {
return new Response('Not Found', 404, array('X-Status-Code' => 404));
}
if ($e instanceof \Exception_Forbidden) {
return new Response('Not Found', 403, array('X-Status-Code' => 403));
}
});
return $app;
}
);

View File

@@ -55,174 +55,155 @@ use Alchemy\Phrasea\Controller\Prod\UsrLists;
use Alchemy\Phrasea\Controller\Prod\WorkZone;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest;
use Silex\ControllerProviderInterface;
use Alchemy\Phrasea\Controller\Login\Authenticate as AuthenticateController;
use Silex\Application as SilexApp;
use Symfony\Component\HttpFoundation\Response;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
return call_user_func(function($environment = null) {
$app = new PhraseaApplication($environment);
// $app->enableEvents();
$app = new PhraseaApplication($environment);
$app->before(function () use ($app) {
return $app['firewall']->requireSetup($app);
});
$app->before(function () use ($app) {
return $app['firewall']->requireSetup($app);
});
$app->get('/', function(SilexApp $app) {
if ($app['browser']->isMobile()) {
return $app->redirect("/login/?redirect=lightbox");
} elseif ($app['browser']->isNewGeneration()) {
return $app->redirect("/login/?redirect=prod");
} else {
return $app->redirect("/login/?redirect=client");
}
});
$app->get('/', function(SilexApp $app) {
if ($app['browser']->isMobile()) {
return $app->redirect("/login/?redirect=lightbox");
} elseif ($app['browser']->isNewGeneration()) {
return $app->redirect("/login/?redirect=prod");
} else {
return $app->redirect("/login/?redirect=client");
}
});
$app->get('/robots.txt', function(SilexApp $app) {
$app->get('/robots.txt', function(SilexApp $app) {
if ($app['phraseanet.registry']->get('GV_allow_search_engine') === true) {
$buffer = "User-Agent: *\n" . "Allow: /\n";
} else {
$buffer = "User-Agent: *\n" . "Disallow: /\n";
}
if ($app['phraseanet.registry']->get('GV_allow_search_engine') === true) {
$buffer = "User-Agent: *\n" . "Allow: /\n";
} else {
$buffer = "User-Agent: *\n" . "Disallow: /\n";
}
return new Response($buffer, 200, array('Content-Type' => 'text/plain'));
})->bind('robots');
return new Response($buffer, 200, array('Content-Type' => 'text/plain'));
})->bind('robots');
$app->mount('/feeds/', new RSSFeeds());
$app->mount('/account/', new Account());
$app->mount('/login/', new Login());
$app->mount('/developers/', new Developers());
$app->mount('/lightbox/', new Lightbox());
$app->mount('/feeds/', new RSSFeeds());
$app->mount('/account/', new Account());
$app->mount('/login/', new Login());
$app->mount('/developers/', new Developers());
$app->mount('/lightbox/', new Lightbox());
$app->mount('/datafiles/', new Datafiles());
$app->mount('/permalink/', new Permalink());
$app->mount('/datafiles/', new Datafiles());
$app->mount('/permalink/', new Permalink());
$app->mount('/admin/', new Root());
$app->mount('/admin/dashboard', new Dashboard());
$app->mount('/admin/collection', new Collection());
$app->mount('/admin/databox', new Databox());
$app->mount('/admin/databoxes', new Databoxes());
$app->mount('/admin/setup', new Setup());
$app->mount('/admin/sphinx', new Sphinx());
$app->mount('/admin/connected-users', new ConnectedUsers());
$app->mount('/admin/publications', new Publications());
$app->mount('/admin/users', new Users());
$app->mount('/admin/fields', new Fields());
$app->mount('/admin/task-manager', new TaskManager());
$app->mount('/admin/subdefs', new Subdefs());
$app->mount('/admin/description', new Description());
$app->mount('/admin/tests/connection', new ConnectionTest());
$app->mount('/admin/tests/pathurl', new PathFileTest());
$app->mount('/admin/', new Root());
$app->mount('/admin/dashboard', new Dashboard());
$app->mount('/admin/collection', new Collection());
$app->mount('/admin/databox', new Databox());
$app->mount('/admin/databoxes', new Databoxes());
$app->mount('/admin/setup', new Setup());
$app->mount('/admin/sphinx', new Sphinx());
$app->mount('/admin/connected-users', new ConnectedUsers());
$app->mount('/admin/publications', new Publications());
$app->mount('/admin/users', new Users());
$app->mount('/admin/fields', new Fields());
$app->mount('/admin/task-manager', new TaskManager());
$app->mount('/admin/subdefs', new Subdefs());
$app->mount('/admin/description', new Description());
$app->mount('/admin/tests/connection', new ConnectionTest());
$app->mount('/admin/tests/pathurl', new PathFileTest());
$app->mount('/prod/UserPreferences/', new UserPreferences());
$app->mount('/prod/query/', new Query());
$app->mount('/prod/order/', new Order());
$app->mount('/prod/baskets', new Basket());
$app->mount('/prod/story', new Story());
$app->mount('/prod/WorkZone', new WorkZone());
$app->mount('/prod/lists', new UsrLists());
$app->mount('/prod/MustacheLoader', new MustacheLoader());
$app->mount('/prod/records/edit', new Edit());
$app->mount('/prod/records/movecollection', new MoveCollection());
$app->mount('/prod/bridge/', new Bridge());
$app->mount('/prod/push/', new Push());
$app->mount('/prod/printer/', new Printer());
$app->mount('/prod/TOU/', new TOU());
$app->mount('/prod/feeds', new Feed());
$app->mount('/prod/tooltip', new Tooltip());
$app->mount('/prod/language', new Language());
$app->mount('/prod/tools/', new Tools());
$app->mount('/prod/lazaret/', new Lazaret());
$app->mount('/prod/upload/', new Upload());
$app->mount('/prod/', new Prod());
$app->error(function(\Exception $e) use ($app) {
$request = $app['request'];
$app->mount('/prod/UserPreferences/', new UserPreferences());
$app->mount('/prod/query/', new Query());
$app->mount('/prod/order/', new Order());
$app->mount('/prod/baskets', new Basket());
$app->mount('/prod/story', new Story());
$app->mount('/prod/WorkZone', new WorkZone());
$app->mount('/prod/lists', new UsrLists());
$app->mount('/prod/MustacheLoader', new MustacheLoader());
$app->mount('/prod/records/edit', new Edit());
$app->mount('/prod/records/movecollection', new MoveCollection());
$app->mount('/prod/bridge/', new Bridge());
$app->mount('/prod/push/', new Push());
$app->mount('/prod/printer/', new Printer());
$app->mount('/prod/TOU/', new TOU());
$app->mount('/prod/feeds', new Feed());
$app->mount('/prod/tooltip', new Tooltip());
$app->mount('/prod/language', new Language());
$app->mount('/prod/tools/', new Tools());
$app->mount('/prod/lazaret/', new Lazaret());
$app->mount('/prod/upload/', new Upload());
$app->mount('/prod/', new Prod());
if ($e instanceof \Bridge_Exception) {
$params = array(
'message' => $e->getMessage()
, 'file' => $e->getFile()
, 'line' => $e->getLine()
, 'r_method' => $request->getMethod()
, 'r_action' => $request->getRequestUri()
, 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
);
$app->error(function(\Exception $e) use ($app) {
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
$params = array_merge($params, array('account' => $app['current_account']));
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
$params = array_merge($params, array('api' => $e->get_api()));
$request = $app['request'];
$response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, array('X-Status-Code' => 200));
} else {
$response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, array('X-Status-Code' => 200));
}
if ($e instanceof \Bridge_Exception) {
$response->headers->set('Phrasea-StatusCode', 200);
$params = array(
'message' => $e->getMessage()
, 'file' => $e->getFile()
, 'line' => $e->getLine()
, 'r_method' => $request->getMethod()
, 'r_action' => $request->getRequestUri()
, 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
);
return $response;
}
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
$params = array_merge($params, array('account' => $app['current_account']));
if ($request->getRequestFormat() == 'json') {
$datas = array(
'success' => false
, 'message' => $e->getMessage()
);
$response = new Response($app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
$params = array_merge($params, array('account' => $app['current_account']));
return $app->json($datas, 200, array('X-Status-Code' => 200));
}
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
$params = array_merge($params, array('account' => $app['current_account']));
if ($e instanceof \Exception_BadRequest) {
return new Response('Bad Request', 400, array('X-Status-Code' => 400));
}
if ($e instanceof \Exception_Forbidden) {
return new Response('Forbidden', 403, array('X-Status-Code' => 403));
}
$response = new Response($app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, array('X-Status-Code' => 200));
} elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
$params = array_merge($params, array('api' => $e->get_api()));
if ($e instanceof \Exception_Session_NotAuthenticated) {
$code = 403;
$message = 'Forbidden';
} elseif ($e instanceof \Exception_NotAllowed) {
$code = 403;
$message = 'Forbidden';
} elseif ($e instanceof \Exception_NotFound) {
$code = 404;
$message = 'Not Found';
} else {
throw $e;
}
$response = new Response($app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, array('X-Status-Code' => 200));
} else {
$response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, array('X-Status-Code' => 200));
}
return new Response($message, $code, array('X-Status-Code' => $code));
});
$response->headers->set('Phrasea-StatusCode', 200);
return $response;
}
$request = $app['request'];
if ($request->getRequestFormat() == 'json') {
$datas = array(
'success' => false
, 'message' => $e->getMessage()
);
return $app->json($datas, 200, array('X-Status-Code' => 200));
}
if ($e instanceof \Exception_BadRequest) {
return new Response('Bad Request', 400, array('X-Status-Code' => 400));
}
if ($e instanceof \Exception_Forbidden) {
return new Response('Forbidden', 403, array('X-Status-Code' => 403));
}
if ($e instanceof \Exception_Session_NotAuthenticated) {
$code = 403;
$message = 'Forbidden';
} elseif ($e instanceof \Exception_NotAllowed) {
$code = 403;
$message = 'Forbidden';
} elseif ($e instanceof \Exception_NotFound) {
$code = 404;
$message = 'Not Found';
} else {
throw $e;
}
return new Response($message, $code, array('X-Status-Code' => $code));
});
return $app;
}, isset($environment) ? $environment : null
);
return $app;
}, isset($environment) ? $environment : null);

View File

@@ -13,74 +13,66 @@ namespace Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Configuration;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Symfony\Component\HttpFoundation\Response;
use Alchemy\Phrasea\Controller\Setup\Installer;
use Alchemy\Phrasea\Controller\Setup\Upgrader;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
return call_user_func(function() {
return call_user_func(function($environment = null) {
$app = new PhraseaApplication();
$app = new PhraseaApplication();
$app['install'] = false;
$app['upgrade'] = false;
$app['install'] = false;
$app['upgrade'] = false;
$app->before(function($a) use ($app) {
if (\setup::is_installed()) {
if ( ! $app['phraseanet.appbox']->need_major_upgrade()) {
throw new \Exception_Setup_PhraseaAlreadyInstalled();
}
$app->before(function($a) use ($app) {
if (\setup::is_installed()) {
if (!$app['phraseanet.appbox']->need_major_upgrade()) {
throw new \Exception_Setup_PhraseaAlreadyInstalled();
}
$app['upgrade'] = true;
} elseif (\setup::needUpgradeConfigurationFile()) {
$app['upgrade'] = true;
} elseif (\setup::needUpgradeConfigurationFile()) {
if (\setup::requireGVUpgrade()) {
setup::upgradeGV($app['phraseanet.core']['Registry']);
}
if (\setup::requireGVUpgrade()) {
setup::upgradeGV($app['phraseanet.core']['Registry']);
}
$connexionInc = new \SplFileInfo(__DIR__ . '/../../../../config/connexion.inc');
$configInc = new \SplFileInfo(__DIR__ . '/../../../../config/config.inc');
$connexionInc = new \SplFileInfo(__DIR__ . '/../../../../config/connexion.inc');
$configInc = new \SplFileInfo(__DIR__ . '/../../../../config/config.inc');
echo " config at ".__FILE__."\n";
$configuration = Configuration::build();
$configuration->upgradeFromOldConf($configInc, $connexionInc);
$configuration = Configuration::build();
$configuration->upgradeFromOldConf($configInc, $connexionInc);
$app['install'] = true;
} else {
$app['install'] = true;
}
$app['install'] = true;
} else {
$app['install'] = true;
}
return;
});
return;
});
$app->get('/', function() use ($app) {
if ($app['install'] === true) {
return $app->redirect('/setup/installer/');
}if ($app['upgrade'] === true) {
return $app->redirect('/setup/upgrader/');
}
});
$app->get('/', function() use ($app) {
if ($app['install'] === true) {
return $app->redirect('/setup/installer/');
}if ($app['upgrade'] === true) {
return $app->redirect('/setup/upgrader/');
}
});
$app->mount('/installer/', new Installer());
$app->mount('/upgrader/', new Upgrader());
$app->mount('/test', new PathFileTest());
$app->mount('/connection_test', new ConnectionTest());
$app->mount('/installer/', new Installer());
$app->mount('/upgrader/', new Upgrader());
$app->mount('/test', new PathFileTest());
$app->mount('/connection_test', new ConnectionTest());
$app->error(function($e) use ($app) {
if ($e instanceof \Exception_Setup_PhraseaAlreadyInstalled) {
return $app->redirect('/login/');
}
$app->error(function($e) use ($app) {
if ($e instanceof \Exception_Setup_PhraseaAlreadyInstalled) {
return $app->redirect('/login/');
}
throw $e;
// return new Response('Internal Server Error', 500);
});
return new Response('Internal Server Error', 500, array('X-Status-Code' => 500));
});
return $app;
}
return $app;
}, isset($environment) ? $environment : null
);