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 Alchemy\Phrasea\Application as PhraseaApplication;
use Symfony\Component\HttpFoundation\Request; 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) { $app = new PhraseaApplication($environment);
$registry = $app['phraseanet.registry'];
$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( return $result->set_datas(array(
array( 'name' => $app['phraseanet.registry']->get('GV_homeTitle'),
'name' => $registry->get('GV_homeTitle'), 'type' => 'phraseanet',
'type' => 'phraseanet', 'description' => $app['phraseanet.registry']->get('GV_metaDescription'),
'description' => $registry->get('GV_metaDescription'), 'documentation' => 'https://docs.phraseanet.com/Devel',
'documentation' => 'https://docs.phraseanet.com/Devel', 'versions' => array(
'versions' => array( '1' => array(
'1' => array( 'number' => $apiAdapter->get_version(),
'number' => $apiAdapter->get_version(), 'uri' => '/api/v1/',
'uri' => '/api/v1/', 'authenticationProtocol' => 'OAuth2',
'authenticationProtocol' => 'OAuth2', 'authenticationVersion' => 'draft#v9',
'authenticationVersion' => 'draft#v9', 'authenticationEndPoints' => array(
'authenticationEndPoints' => array( 'authorization_token' => '/api/oauthv2/authorize',
'authorization_token' => '/api/oauthv2/authorize', 'access_token' => '/api/oauthv2/token'
'access_token' => '/api/oauthv2/token' )
) )
) )
) ))->get_response();
) });
)->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 class Lightbox implements ControllerProviderInterface
{ {
public function connect(SilexApplication $app) public function connect(SilexApplication $app)
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/', function (SilexApplication $app) { $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( $template = 'lightbox/index.html.twig';
$repository->findActiveByUser($app['phraseanet.user']) if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) {
, $repository->findActiveValidationByUser($current_user) $template = 'lightbox/IE6/index.html.twig';
);
$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'
)
));
} }
);
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) { $controllers->get('/ajax/NOTE_FORM/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) {
if (!$app['browser']->isMobile()) { if (!$app['browser']->isMobile()) {
return new Response(''); 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);
} }
)->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) { $controllers->get('/ajax/LOAD_BASKET_ELEMENT/{sselcont_id}/', function(SilexApplication $app, $sselcont_id) {
/* @var $repository \Repositories\BasketElementRepository */ /* @var $repository \Repositories\BasketElementRepository */
$repository = $app['EM']->getRepository('\Entities\BasketElement'); $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()) { if ($app['browser']->isMobile()) {
$output = $app['twig']->render('lightbox/basket_element.html.twig', array( $output = $app['twig']->render('lightbox/basket_element.html.twig', array(
'basket_element' => $BasketElement, 'basket_element' => $BasketElement,
'module_name' => $BasketElement->getRecord($app)->get_title() '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')
) )
); );
$response = new Response($output, 200);
$response->setCharset('UTF-8');
return $response; return new Response($output);
} } else {
)->assert('entry_id', '\d+'); $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) { if (!$app['browser']->isNewGeneration()) {
$template_options = 'lightbox/IE6/sc_options_box.html.twig';
$template = 'lightbox/basket_content_report.html.twig'; $template_agreement = 'lightbox/IE6/agreement_box.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 */ $Basket = $BasketElement->getBasket();
$repository = $app['EM']->getRepository('\Entities\BasketElement');
$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); $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));
$validationDatas->setNote($note); $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));
$app['EM']->merge($validationDatas); $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)));
$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); 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) { $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 { try {
/* @var $repository \Repositories\BasketRepository */ /* @var $repository \Repositories\BasketRepository */
$basket = $repository->findUserBasket( $basket = $repository->findUserBasket(
$app, $ssel_id $app, $ssel_id
, $user , $user
, false , false
); );
if (!$basket->getValidation()) { if (!$basket->getValidation()) {
throw new ControllerException('There is no validation session attached to this basket'); 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());
} }
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; return $controllers;
} }

View File

@@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
*
* *
* @package OAuth2 Connector * @package OAuth2 Connector
* *
@@ -30,145 +29,144 @@ use Symfony\Component\HttpFoundation\Request;
*/ */
return call_user_func(function($environment = 'prod') { return call_user_func(function($environment = 'prod') {
$app = new PhraseaApplication($environment); $app = new PhraseaApplication($environment);
$app['oauth'] = function($app) { $app['oauth'] = function($app) {
return new \API_OAuth2_Adapter($app); return new \API_OAuth2_Adapter($app);
}; };
/** /**
* AUTHORIZE ENDPOINT * AUTHORIZE ENDPOINT
* *
* Authorization endpoint - used to obtain authorization from the * Authorization endpoint - used to obtain authorization from the
* resource owner via user-agent redirection. * resource owner via user-agent redirection.
*/ */
$authorize_func = function() use ($app) { $authorize_func = function() use ($app) {
$request = $app['request']; $request = $app['request'];
$oauth2_adapter = $app['oauth']; $oauth2_adapter = $app['oauth'];
//Check for auth params, send error or redirect if not valid //Check for auth params, send error or redirect if not valid
$params = $oauth2_adapter->getAuthorizationRequestParameters($request); $params = $oauth2_adapter->getAuthorizationRequestParameters($request);
$app_authorized = false; $app_authorized = false;
$errorMessage = 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_accept = $request->get("action_accept");
$action_login = $request->get("action_login"); $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( $custom_template = sprintf(
"%sconfig/templates/web/api/auth/end_user_authorization/%s.html.twig" "%sconfig/templates/web/api/auth/end_user_authorization/%s.html.twig"
, $app['phraseanet.appbox']->get_registry()->get('GV_RootPath') , $app['phraseanet.appbox']->get_registry()->get('GV_RootPath')
, $client->get_id() , $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)) { $app->openAccount($auth);
$template = sprintf( } catch (\Exception $e) {
'api/auth/end_user_authorization/%s.html.twig'
, $client->get_id()
);
}
if (!$app->isAuthenticated()) { return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter)));
if ($action_login !== null) { }
try { } else {
$auth = new \Session_Authentication_Native( return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter)));
$app, $request->get("login"), $request->get("password") }
); }
$app->openAccount($auth); //check if current client is already authorized by current user
} catch (\Exception $e) { $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))); foreach ($user_auth_clients as $auth_client) {
} if ($client->get_client_id() == $auth_client->get_client_id()) {
} else { $app_authorized = true;
return new Response($app['twig']->render($template, array("auth" => $oauth2_adapter))); }
} }
}
//check if current client is already authorized by current user $account = $oauth2_adapter->updateAccount($app['phraseanet.user']->get_id());
$user_auth_clients = \API_OAuth2_Application::load_authorized_app_by_user(
$app
, $app['phraseanet.user']
);
foreach ($user_auth_clients as $auth_client) { $params['account_id'] = $account->get_id();
if ($client->get_client_id() == $auth_client->get_client_id()) {
$app_authorized = true;
}
}
$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) { //if native app show template
$params = array( if ($oauth2_adapter->isNativeApp($params['redirect_uri'])) {
"auth" => $oauth2_adapter, $params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params);
"errorMessage" => $errorMessage,
);
return new Response($app['twig']->render($template, $params)); return new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params));
} elseif (!$app_authorized && $action_accept !== null) { } else {
$app_authorized = (Boolean) $action_accept; $oauth2_adapter->finishClientAuthorization($app_authorized, $params);
$account->set_revoked(!$app_authorized); }
} };
//if native app show template $app->match('/authorize', $authorize_func)->method('GET|POST');
if ($oauth2_adapter->isNativeApp($params['redirect_uri'])) {
$params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params);
return new Response($app['twig']->render("api/auth/native_app_access_token.html.twig", $params)); /**
} else { * TOKEN ENDPOINT
$oauth2_adapter->finishClientAuthorization($app_authorized, $params); * 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();
/** return;
* TOKEN ENDPOINT })->requireHttps();
* Token endpoint - used to exchange an authorization grant for an access token.
*/
$app->post('/token', function(\Silex\Application $app, Request $request) {
$app['oauth']->grantAccessToken(); /**
ob_flush(); * Error Handler
flush(); */
$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; $code = 500;
})->requireHttps(); $msg = 'We are sorry, but something went wrong';
$headers = array();
/** if ($e instanceof HttpExceptionInterface) {
* Error Handler $headers = $e->getHeaders();
*/ $msg = $e->getMessage();
$app->error(function (\Exception $e) use ($app) { $code = $e->getStatusCode();
if ($e instanceof NotFoundHttpException || $e instanceof \Exception_NotFound) {
return new Response('The requested page could not be found.', 404, array('X-Status-Code' => 404));
}
$code = 500; if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') {
$msg = 'We are sorry, but something went wrong'; $msg = json_encode(array('msg' => $msg, 'code' => $code));
$headers = array(); }
}
if ($e instanceof HttpExceptionInterface) { return new Response($msg, $code, $headers);
$headers = $e->getHeaders(); });
$msg = $e->getMessage();
$code = $e->getStatusCode();
if (isset($headers['content-type']) && $headers['content-type'] == 'application/json') { return $app;
$msg = json_encode(array('msg' => $msg, 'code' => $code)); }, isset($environment) ? $environment : null);
}
}
return new Response($msg, $code, $headers);
});
return $app;
}, $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\Prod\WorkZone;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest;
use Silex\ControllerProviderInterface;
use Alchemy\Phrasea\Controller\Login\Authenticate as AuthenticateController;
use Silex\Application as SilexApp; use Silex\Application as SilexApp;
use Symfony\Component\HttpFoundation\Response; 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) { return call_user_func(function($environment = null) {
$app = new PhraseaApplication($environment); $app = new PhraseaApplication($environment);
// $app->enableEvents();
$app->before(function () use ($app) { $app->before(function () use ($app) {
return $app['firewall']->requireSetup($app); return $app['firewall']->requireSetup($app);
}); });
$app->get('/', function(SilexApp $app) { $app->get('/', function(SilexApp $app) {
if ($app['browser']->isMobile()) { if ($app['browser']->isMobile()) {
return $app->redirect("/login/?redirect=lightbox"); return $app->redirect("/login/?redirect=lightbox");
} elseif ($app['browser']->isNewGeneration()) { } elseif ($app['browser']->isNewGeneration()) {
return $app->redirect("/login/?redirect=prod"); return $app->redirect("/login/?redirect=prod");
} else { } else {
return $app->redirect("/login/?redirect=client"); 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) { if ($app['phraseanet.registry']->get('GV_allow_search_engine') === true) {
$buffer = "User-Agent: *\n" . "Allow: /\n"; $buffer = "User-Agent: *\n" . "Allow: /\n";
} else { } else {
$buffer = "User-Agent: *\n" . "Disallow: /\n"; $buffer = "User-Agent: *\n" . "Disallow: /\n";
} }
return new Response($buffer, 200, array('Content-Type' => 'text/plain')); return new Response($buffer, 200, array('Content-Type' => 'text/plain'));
})->bind('robots'); })->bind('robots');
$app->mount('/feeds/', new RSSFeeds()); $app->mount('/feeds/', new RSSFeeds());
$app->mount('/account/', new Account()); $app->mount('/account/', new Account());
$app->mount('/login/', new Login()); $app->mount('/login/', new Login());
$app->mount('/developers/', new Developers()); $app->mount('/developers/', new Developers());
$app->mount('/lightbox/', new Lightbox()); $app->mount('/lightbox/', new Lightbox());
$app->mount('/datafiles/', new Datafiles());
$app->mount('/permalink/', new Permalink());
$app->mount('/datafiles/', new Datafiles()); $app->mount('/admin/', new Root());
$app->mount('/permalink/', new Permalink()); $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('/prod/UserPreferences/', new UserPreferences());
$app->mount('/admin/dashboard', new Dashboard()); $app->mount('/prod/query/', new Query());
$app->mount('/admin/collection', new Collection()); $app->mount('/prod/order/', new Order());
$app->mount('/admin/databox', new Databox()); $app->mount('/prod/baskets', new Basket());
$app->mount('/admin/databoxes', new Databoxes()); $app->mount('/prod/story', new Story());
$app->mount('/admin/setup', new Setup()); $app->mount('/prod/WorkZone', new WorkZone());
$app->mount('/admin/sphinx', new Sphinx()); $app->mount('/prod/lists', new UsrLists());
$app->mount('/admin/connected-users', new ConnectedUsers()); $app->mount('/prod/MustacheLoader', new MustacheLoader());
$app->mount('/admin/publications', new Publications()); $app->mount('/prod/records/edit', new Edit());
$app->mount('/admin/users', new Users()); $app->mount('/prod/records/movecollection', new MoveCollection());
$app->mount('/admin/fields', new Fields()); $app->mount('/prod/bridge/', new Bridge());
$app->mount('/admin/task-manager', new TaskManager()); $app->mount('/prod/push/', new Push());
$app->mount('/admin/subdefs', new Subdefs()); $app->mount('/prod/printer/', new Printer());
$app->mount('/admin/description', new Description()); $app->mount('/prod/TOU/', new TOU());
$app->mount('/admin/tests/connection', new ConnectionTest()); $app->mount('/prod/feeds', new Feed());
$app->mount('/admin/tests/pathurl', new PathFileTest()); $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()); if ($e instanceof \Bridge_Exception) {
$app->mount('/prod/query/', new Query()); $params = array(
$app->mount('/prod/order/', new Order()); 'message' => $e->getMessage()
$app->mount('/prod/baskets', new Basket()); , 'file' => $e->getFile()
$app->mount('/prod/story', new Story()); , 'line' => $e->getLine()
$app->mount('/prod/WorkZone', new WorkZone()); , 'r_method' => $request->getMethod()
$app->mount('/prod/lists', new UsrLists()); , 'r_action' => $request->getRequestUri()
$app->mount('/prod/MustacheLoader', new MustacheLoader()); , 'r_parameters' => ($request->getMethod() == 'GET' ? array() : $request->request->all())
$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) { 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( return $response;
'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())
);
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) { if ($request->getRequestFormat() == 'json') {
$params = array_merge($params, array('account' => $app['current_account'])); $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)); return $app->json($datas, 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)); if ($e instanceof \Exception_BadRequest) {
} elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) { return new Response('Bad Request', 400, array('X-Status-Code' => 400));
$params = array_merge($params, array('account' => $app['current_account'])); }
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)); if ($e instanceof \Exception_Session_NotAuthenticated) {
} elseif ($e instanceof \Bridge_Exception_ApiDisabled) { $code = 403;
$params = array_merge($params, array('api' => $e->get_api())); $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)); return new Response($message, $code, array('X-Status-Code' => $code));
} else { });
$response = new Response($app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, array('X-Status-Code' => 200));
}
$response->headers->set('Phrasea-StatusCode', 200); return $app;
}, isset($environment) ? $environment : null);
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
);

View File

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