Merged with 3.5.1

This commit is contained in:
Romain Neutron
2011-12-15 14:25:47 +01:00
39 changed files with 1113 additions and 1087 deletions

View File

@@ -1,37 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Silex\Application;
return call_user_func(
function()
{
$app = new Application();
$app->mount('/publications', new Controller_Admin_Publications());
$app->mount('/users', new Controller_Admin_Users());
$app->mount('/fields', new Controller_Admin_Fields());
$app->mount('/tests/connection', new Controller_Utils_ConnectionTest());
$app->mount('/tests/pathurl', new Controller_Utils_PathFileTest());
$app->error(function(\Exception $e)
{
return $e->getMessage();
});
return $app;
});

View File

@@ -1,455 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
return call_user_func(
function()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$app = new Silex\Application();
$app->get('/', function () use ($session, $appbox)
{
User_Adapter::updateClientInfos((6));
$basket_collection = new basketCollection($appbox, $session->get_usr_id());
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br'));
$browser = Browser::getInstance();
$template = 'lightbox/index.twig';
if (!$browser->isNewGeneration() && !$browser->isMobile())
$template = 'lightbox/IE6/index.twig';
$output = $twig->render($template, array(
'baskets_collection' => $basket_collection,
'module_name' => 'Lightbox',
'module' => 'lightbox'
)
);
$response = new Response($output);
$response->setCharset('UTF-8');
return $response;
}
);
$app->get('/ajax/NOTE_FORM/{sselcont_id}/', function($sselcont_id) use ($session, $appbox)
{
$browser = Browser::getInstance();
if (!$browser->isMobile())
return new Response('');
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br'));
$basket_element = basket_element_adapter::getInstance($sselcont_id);
$template = '/lightbox/note_form.twig';
$output = $twig->render($template, array('basket_element' => $basket_element, 'module_name' => ''));
return new Response($output);
}
)->assert('sselcont_id', '\d+');
$app->get('/ajax/LOAD_BASKET_ELEMENT/{sselcont_id}/', function($sselcont_id)
{
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br', 'formatoctet' => 'p4string::format_octets'));
$browser = Browser::getInstance();
if ($browser->isMobile())
{
$basket_element = basket_element_adapter::getInstance($sselcont_id);
$output = $twig->render('lightbox/basket_element.twig', array(
'basket_element' => $basket_element,
'module_name' => $basket_element->get_record()->get_title()
)
);
return new Response($output);
}
else
{
$template_options = 'lightbox/sc_options_box.twig';
$template_agreement = 'lightbox/agreement_box.twig';
$template_selector = 'lightbox/selector_box.twig';
$template_note = 'lightbox/sc_note.twig';
$template_preview = 'common/preview.html';
$template_caption = 'common/caption.html';
if (!$browser->isNewGeneration())
{
$template_options = 'lightbox/IE6/sc_options_box.twig';
$template_agreement = 'lightbox/IE6/agreement_box.twig';
}
$appbox = appbox::get_instance();
$usr_id = $appbox->get_session()->get_usr_id();
$basket_element = basket_element_adapter::getInstance($sselcont_id);
$basket = basket_adapter::getInstance($appbox, $basket_element->get_ssel_id(), $usr_id);
$ret = array();
$ret['number'] = $basket_element->get_record()->get_number();
$ret['title'] = $basket_element->get_record()->get_title();
$ret['preview'] = $twig->render($template_preview, array('record' => $basket_element->get_record(), 'not_wrapped' => true));
$ret['options_html'] = $twig->render($template_options, array('basket_element' => $basket_element));
$ret['agreement_html'] = $twig->render($template_agreement, array('basket' => $basket, 'basket_element' => $basket_element));
$ret['selector_html'] = $twig->render($template_selector, array('basket_element' => $basket_element));
$ret['note_html'] = $twig->render($template_note, array('basket_element' => $basket_element));
$ret['caption'] = $twig->render($template_caption, array('view' => 'preview', 'record' => $basket_element->get_record()));
$output = p4string::jsonencode($ret);
return new Response($output, 200, array('Content-Type' => 'application/json'));
}
}
)->assert('sselcont_id', '\d+');
$app->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function($entry_id, $item_id)
{
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br', 'formatoctet' => 'p4string::format_octets'));
$appbox = appbox::get_instance();
$entry = Feed_Entry_Adapter::load_from_id($appbox, $entry_id);
$item = new Feed_Entry_Item($appbox, $entry, $item_id);
$browser = Browser::getInstance();
if ($browser->isMobile())
{
$output = $twig->render('lightbox/feed_element.twig', array(
'feed_element' => $item,
'module_name' => $item->get_record()->get_title()
)
);
return new Response($output);
}
else
{
$template_options = 'lightbox/sc_options_box.twig';
$template_preview = 'common/preview.html';
$template_caption = 'common/caption.html';
if (!$browser->isNewGeneration())
{
$template_options = 'lightbox/IE6/sc_options_box.twig';
}
$usr_id = $appbox->get_session()->get_usr_id();
$ret = array();
$ret['number'] = $item->get_record()->get_number();
$ret['title'] = $item->get_record()->get_title();
$ret['preview'] = $twig->render($template_preview, array('record' => $item->get_record(), 'not_wrapped' => true));
$ret['options_html'] = $twig->render($template_options, array('basket_element' => $item));
$ret['caption'] = $twig->render($template_caption, array('view' => 'preview', 'record' => $item->get_record()));
$ret['agreement_html'] = $ret['selector_html'] = $ret['note_html'] = '';
$output = p4string::jsonencode($ret);
return new Response($output, 200, array('Content-type' => 'application/json'));
}
}
)->assert('entry_id', '\d+')->assert('item_id', '\d+');
$app->get('/validate/{ssel_id}/', function ($ssel_id) use ($session, $appbox)
{
User_Adapter::updateClientInfos((6));
$browser = Browser::getInstance();
$basket_collection = new basketCollection($appbox, $session->get_usr_id());
$basket = basket_adapter::getInstance($appbox, $ssel_id, $session->get_usr_id());
if ($basket->is_valid())
{
$basket->get_first_element()->load_users_infos();
}
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br'));
$template = 'lightbox/validate.twig';
if (!$browser->isNewGeneration() && !$browser->isMobile())
$template = 'lightbox/IE6/validate.twig';
$response = new Response($twig->render($template, array(
'baskets_collection' => $basket_collection,
'basket' => $basket,
'local_title' => strip_tags($basket->get_name()),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
)
));
$response->setCharset('UTF-8');
return $response;
}
)->assert('ssel_id', '\d+');
$app->get('/compare/{ssel_id}/', function ($ssel_id) use ($session, $appbox)
{
User_Adapter::updateClientInfos((6));
$browser = Browser::getInstance();
$basket_collection = new basketCollection($appbox, $session->get_usr_id());
$basket = basket_adapter::getInstance($appbox, $ssel_id, $session->get_usr_id());
if ($basket->is_valid())
{
$basket->get_first_element()->load_users_infos();
}
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br'));
$template = 'lightbox/validate.twig';
if (!$browser->isNewGeneration() && !$browser->isMobile())
$template = 'lightbox/IE6/validate.twig';
$response = new Response($twig->render($template, array(
'baskets_collection' => $basket_collection,
'basket' => $basket,
'local_title' => strip_tags($basket->get_name()),
'module' => 'lightbox',
'module_name' => _('admin::monitor: module validation')
)
));
$response->setCharset('UTF-8');
return $response;
}
)->assert('ssel_id', '\d+');
$app->get('/feeds/entry/{entry_id}/', function ($entry_id) use ($session, $appbox)
{
User_Adapter::updateClientInfos((6));
$browser = Browser::getInstance();
$feed_entry = Feed_Entry_Adapter::load_from_id($appbox, $entry_id);
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br'));
$template = 'lightbox/feed.twig';
if (!$browser->isNewGeneration() && !$browser->isMobile())
$template = 'lightbox/IE6/feed.twig';
$output = $twig->render($template, array(
'feed_entry' => $feed_entry,
'first_item' => array_shift($feed_entry->get_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+');
$app->get('/ajax/LOAD_REPORT/{ssel_id}/', function($ssel_id) use ($appbox, $app)
{
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br'));
$browser = Browser::getInstance();
$template = 'lightbox/basket_content_report.twig';
$basket = basket_adapter::getInstance($appbox, $ssel_id, $appbox->get_session()->get_usr_id());
$response = new Response($twig->render($template, array('basket' => $basket)));
$response->setCharset('UTF-8');
return $response;
}
)->assert('ssel_id', '\d+');
$app->post('/ajax/SET_NOTE/{sselcont_id}/', function ($sselcont_id) use ($app)
{
$output = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees'));
try
{
$request = $app['request'];
$note = $request->get('note');
$basket_element = basket_element_adapter::getInstance($sselcont_id);
$basket_element->set_note($note);
$twig = new supertwig();
$twig->addFilter(array('nl2br' => 'nl2br'));
$browser = Browser::getInstance();
if ($browser->isMobile())
{
$datas = $twig->render('lightbox/sc_note.twig', array('basket_element' => $basket_element));
$output = array('error' => false, 'datas' => $datas);
}
else
{
$template = 'lightbox/sc_note.twig';
$datas = $twig->render($template, array('basket_element' => $basket_element));
$output = array('error' => false, 'datas' => $datas);
}
}
catch (Exception $e)
{
return new Response('Bad Request : ' . $e->getMessage() . $e->getFile() . $e->getLine(), 400);
}
$output = p4string::jsonencode($output);
return new Response($output, 200, array('Content-Type' => 'application/json'));
}
)->assert('sselcont_id', '\d+');
$app->post('/ajax/SET_ELEMENT_AGREEMENT/{sselcont_id}/', function($sselcont_id) use ($app)
{
$request = $app['request'];
$agreement = (int) $request->get('agreement');
$ret = array(
'error' => true,
'releasable' => false,
'datas' => _('Erreur lors de la mise a jour des donnes ')
);
try
{
$appbox = appbox::get_instance();
$basket_element = basket_element_adapter::getInstance($sselcont_id);
$basket_element->set_agreement($agreement);
$basket = basket_adapter::getInstance($appbox, $basket_element->get_ssel_id(), $appbox->get_session()->get_usr_id());
$ret = array(
'error' => false
, 'datas' => ''
, 'releasable' => $basket->is_releasable() ? _('Do you want to send your report ?') : false
);
}
catch (Exception $e)
{
return new Response('Bad Request', 400);
}
$output = p4string::jsonencode($ret);
return new Response($output, 200, array('Content-Type' => 'application/json'));
}
)->assert('sselcont_id', '\d+');
$app->post('/ajax/SET_RELEASE/{ssel_id}/', function($ssel_id) use ($session, $appbox)
{
$basket = basket_adapter::getInstance($appbox, $ssel_id, $appbox->get_session()->get_usr_id());
$datas = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees'));
try
{
$appbox->get_connection()->beginTransaction();
$basket->set_released();
$datas = array('error' => false, 'datas' => _('Envoie avec succes'));
$appbox->get_connection()->commit();
}
catch (Exception $e)
{
$appbox->get_connection()->rollBack();
return new Response('Bad Request', 400);
}
$output = p4string::jsonencode($datas);
$response = new Response($output, 200, array('Content-Type' => 'application/json'));
$response->setCharset('UTF-8');
return $response;
}
)->assert('ssel_id', '\d+');
$app->error(function($e)
{
$twig = new supertwig();
$registry = registry::get_instance();
$template = 'lightbox/error.twig';
if ($registry->get('GV_debug'))
{
$options = array(
'module' => 'validation',
'module_name' => _('admin::monitor: module validation'),
'error' => sprintf(
'%s in %s on line %s '
, $e->getMessage()
, $e->getFile()
, $e->getLine()
)
);
}
else
{
$options = array(
'module' => 'validation',
'module_name' => _('admin::monitor: module validation'),
'error' => ''
);
}
$output = $twig->render($template, $options);
$response = new Response($output, 404);
$response->setCharset('UTF-8');
return $response;
});
return $app;
}
);

View File

@@ -1,227 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
return call_user_func(
function()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$app = new Silex\Application();
$deliver_content = function(Session_Handler $session, record_adapter $record, $subdef, $watermark, $stamp, $app)
{
$file = $record->get_subdef($subdef);
if ($file->get_baseurl() !== '')
{
return $app->redirect($file->get_url());
}
$pathIn = $pathOut = $file->get_pathfile();
if ($watermark === true && $file->get_type() === media_subdef::TYPE_IMAGE)
{
$pathOut = recordutils_image::watermark($record->get_base_id(), $record->get_record_id());
}
elseif ($stamp === true && $file->get_type() === media_subdef::TYPE_IMAGE)
{
$pathOut = recordutils_image::stamp($record->get_base_id(), $record->get_record_id());
}
$log_id = null;
try
{
$registry = registry::get_instance();
$logger = $session->get_logger($record->get_databox());
$log_id = $logger->get_id();
$referrer = 'NO REFERRER';
if (isset($_SERVER['HTTP_REFERER']))
$referrer = $_SERVER['HTTP_REFERER'];
$record->log_view($log_id, $referrer, $registry->get('GV_sit'));
}
catch (Exception $e)
{
}
return set_export::stream_file($pathOut, $file->get_file(), $file->get_mime(), 'attachment');
};
$app->get('/datafiles/{sbas_id}/{record_id}/{subdef}/', function($sbas_id, $record_id, $subdef) use ($app, $session, $deliver_content)
{
$databox = databox::get_instance((int) $sbas_id);
$record = new record_adapter($sbas_id, $record_id);
$record->get_type();
if (!$session->is_authenticated())
throw new Exception_Session_NotAuthenticated();
$user = User_Adapter::getInstance($session->get_usr_id(), appbox::get_instance());
if (!$user->ACL()->has_access_to_subdef($record, $subdef))
throw new Exception_UnauthorizedAction();
$stamp = false;
$watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark');
if ($watermark)
{
$subdef_class = $databox
->get_subdef_structure()
->get_subdef($record->get_type(), $subdef)
->get_class();
if ($subdef_class == databox_subdefAbstract::CLASS_PREVIEW && $user->ACL()->has_preview_grant($record))
{
$watermark = false;
}
elseif ($subdef_class == databox_subdefAbstract::CLASS_DOCUMENT && $user->ACL()->has_hd_grant($record))
{
$watermark = false;
}
}
if ($watermark)
{
if (basket_element_adapter::is_in_validation_session($record, $user))
{
$watermark = false;
}
elseif (basket_element_adapter::has_been_received($record, $user))
{
$watermark = false;
}
}
return $deliver_content($session, $record, $subdef, $watermark, $stamp, $app);
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/'
, function($label, $sbas_id, $record_id, $key, $subdef)
{
$databox = databox::get_instance((int) $sbas_id);
$record = media_Permalink_Adapter::challenge_token($databox, $key, $record_id, $subdef);
if (!($record instanceof record_adapter))
throw new Exception('bad luck');
$twig = new supertwig();
$twig->addFilter(array('formatoctet' => 'p4string::format_octets'));
return $twig->render('overview.twig', array('subdef_name' => $subdef, 'module_name' => 'overview', 'module' => 'overview', 'view' => 'overview', 'record' => $record));
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
$app->get('/permalink/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/'
, function($label, $sbas_id, $record_id, $key, $subdef) use ($app, $session, $deliver_content)
{
$databox = databox::get_instance((int) $sbas_id);
$record = media_Permalink_Adapter::challenge_token($databox, $key, $record_id, $subdef);
if (!($record instanceof record_adapter))
throw new Exception('bad luck');
$watermark = $stamp = false;
if ($session->is_authenticated())
{
$user = User_Adapter::getInstance($session->get_usr_id(), appbox::get_instance());
$watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark');
if ($watermark)
{
if (basket_element_adapter::is_in_validation_session($record, $user))
{
$watermark = false;
}
elseif (basket_element_adapter::has_been_received($record, $user))
{
$watermark = false;
}
}
return $deliver_content($session, $record, $subdef, $watermark, $stamp, $app);
}
else
{
$collection = collection::get_from_base_id($record->get_base_id());
switch ($collection->get_pub_wm())
{
default:
case 'none':
$watermark = false;
break;
case 'stamp':
$stamp = true;
break;
case 'wm':
$watermark = false;
break;
}
}
return $deliver_content($session, $record, $subdef, $watermark, $stamp, $app);
}
)
->assert('sbas_id', '\d+')->assert('record_id', '\d+');
$app->error(function (\Exception $e)
{
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
{
$code = 404;
$message = 'Not Found';
}
return new Response($message, $code);
});
return $app;
}
);

View File

@@ -1,83 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Silex\Application;
use Alchemy\Phrasea\Controller\Prod as Controller;
return call_user_func(function()
{
$twig = new \supertwig();
$app = new Application();
$app['Kernel'] = bootstrap::getKernel();
$app->mount('/baskets', new Controller\Basket());
$app->mount('/records/edit', new Controller\Edit());
$app->mount('/records/movecollection', new Controller\MoveCollection());
$app->mount('/bridge/', new Controller\Bridge());
$app->mount('/feeds', new Controller\Feed());
$app->mount('/tooltip', new Controller\Tooltip());
$app->error(function (\Exception $e, $code) use ($app, $twig)
{
if ($e instanceof \Bridge_Exception)
{
$request = $app['request'];
$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())
);
if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured)
{
$params = array_merge($params, array('account' => $app['current_account']));
return new response($twig->render('/prod/actions/Bridge/notconfigured.twig', $params), 200);
}
elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected)
{
$params = array_merge($params, array('account' => $app['current_account']));
return new response($twig->render('/prod/actions/Bridge/disconnected.twig', $params), 200);
}
elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed)
{
$params = array_merge($params, array('account' => $app['current_account']));
return new response($twig->render('/prod/actions/Bridge/disconnected.twig', $params), 200);
}
elseif ($e instanceof Bridge_Exception_ApiDisabled)
{
$params = array_merge($params, array('api' => $e->get_api()));
return new response($twig->render('/prod/actions/Bridge/deactivated.twig', $params), 200);
}
return new response($twig->render('/prod/actions/Bridge/error.twig', $params), 200);
}
});
return $app;
});

View File

@@ -1,75 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Silex\Application;
return call_user_func(function()
{
$app = new Application();
if (!setup::is_installed())
{
return $app->redirect("/setup/")->send();
}
$app->get('/', function() use ($app)
{
$browser = Browser::getInstance();
if ($browser->isMobile())
return $app->redirect("/login/?redirect=/lightbox");
elseif ($browser->isNewGeneration())
return $app->redirect("/login/?redirect=/prod");
else
return $app->redirect("/login/?redirect=/client");
});
$app->get('robots.txt', function() use ($app)
{
require dirname(__FILE__) . "/../lib/bootstrap.php";
$appbox = appbox::get_instance();
$registry = $appbox->get_registry();
if ($registry->get('GV_allow_search_engine') === true)
{
$buffer = "User-Agent: *\n"
. "Allow: /\n";
}
else
{
$buffer = "User-Agent: *\n"
. "Disallow: /\n";
}
$response = new Response($buffer, 200, array('Content-Type: text/plain'));
$response->setCharset('UTF-8');
return $response;
});
$app->mount('/feeds/', new Controller_RSSFeeds());
/**
* Mount all aps
*/
return $app;
}
);

View File

@@ -1,80 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Silex\Application;
return call_user_func(function()
{
$app = new Silex\Application();
$app['install'] = false;
$app['upgrade'] = false;
$app->before(function($a) use ($app)
{
if (setup::is_installed())
{
$appbox = appbox::get_instance();
if (!$appbox->need_major_upgrade())
throw new Exception_Setup_PhraseaAlreadyInstalled();
$app['upgrade'] = true;
}
else
{
$app['install'] = true;
}
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->mount('/installer/', new Controller_Setup_Installer());
$app->mount('/upgrader/', new Controller_Setup_Upgrader());
$app->mount('/test', new Controller_Utils_PathFileTest());
$app->mount('/connection_test', new Controller_Utils_ConnectionTest());
$app->error(function($e) use ($app)
{
if ($e instanceof Exception_Setup_PhraseaAlreadyInstalled)
return $app->redirect('/login');
return new Response(
sprintf(
'Error %s @%s:%s'
, $e->getFile()
, $e->getLine()
, $e->getMessage()
)
, 500
);
});
return $app;
});

View File

@@ -1,169 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class module_admin_route_users
{
protected $request;
/**
*
* @var array
*/
protected $results;
/**
*
* @var array
*/
protected $query_parms;
/**
*
* @var int
*/
protected $usr_id;
public function __construct(Symfony\Component\HttpFoundation\Request $request)
{
$this->request = $request;
return $this;
}
public function search(Symfony\Component\HttpFoundation\Request $request)
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$offset_start = (int) $request->get('offset_start');
$offset_start = $offset_start < 0 ? 0 : $offset_start;
$results_quantity = (int) $request->get('per_page');
$results_quantity = ($results_quantity < 10 || $results_quantity > 50) ? 20 : $results_quantity;
$this->query_parms = array(
'inactives' => $request->get('inactives')
, 'like_field' => $request->get('like_field')
, 'like_value' => $request->get('like_value')
, 'sbas_id' => $request->get('sbas_id')
, 'base_id' => $request->get('base_id')
, 'srt' => $request->get("srt")
, 'ord' => $request->get("ord")
, 'per_page' => $results_quantity
, 'offset_start' => $offset_start
);
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
$query = new User_Query($appbox);
if (is_array($request->get('base_id')))
$query->on_base_ids($request->get('base_id'));
elseif (is_array($request->get('sbas_id')))
$query->on_sbas_ids($request->get('sbas_id'));
$this->results = $query->sort_by($request->get("srt"), $request->get("ord"))
->like($request->get('like_field'), $request->get('like_value'))
->get_inactives($request->get('inactives'))
->include_templates(true)
->on_bases_where_i_am($user->ACL(), array('canadmin'))
->limit($offset_start, $results_quantity)
->execute();
try
{
$invite_id = User_Adapter::get_usr_id_from_login('invite');
$invite = User_Adapter::getInstance($invite_id, $appbox);
}
catch (Exception $e)
{
$invite = User_Adapter::create($appbox, 'invite', 'invite', '', false);
}
try
{
$autoregister_id = User_Adapter::get_usr_id_from_login('autoregister');
$autoregister = User_Adapter::getInstance($autoregister_id, $appbox);
}
catch (Exception $e)
{
$autoregister = User_Adapter::create($appbox, 'autoregister', 'autoregister', '', false);
}
foreach ($this->query_parms as $k => $v)
{
if (is_null($v))
$this->query_parms[$k] = false;
}
return array(
'users' => $this->results,
'parm' => $this->query_parms,
'invite_user' => $invite,
'autoregister_user' => $autoregister
);
}
public function create_newuser()
{
$email = $this->request->get('value');
if(!mail::validateEmail($email))
{
throw new Exception_InvalidArgument(_('Invalid mail address'));
}
$appbox = appbox::get_instance();
$conn = $appbox->get_connection();
$sql = 'SELECT usr_id FROM usr WHERE usr_mail = :email';
$stmt = $conn->prepare($sql);
$stmt->execute(array(':email' => $email));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$count = count($row);
if (!is_array($row) || $count == 0)
{
$created_user = User_Adapter::create($appbox, $email, random::generatePassword(16), $email, false, false);
$this->usr_id = $created_user->get_id();
}
else
{
$this->usr_id = $row['usr_id'];
$created_user = User_Adapter::getInstance($this->usr_id, $appbox);
}
return $created_user;
}
public function create_template()
{
$name = $this->request->get('value');
if(trim($name) === '')
{
throw new Exception_InvalidArgument(_('Invalid template name'));
}
$appbox = appbox::get_instance();
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
$created_user = User_Adapter::create($appbox, $name, random::generatePassword(16), null, false, false);
$created_user->set_template($user);
$this->usr_id = $user->get_id();
return $created_user;
}
}

View File

@@ -1,639 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class module_admin_route_users_edit
{
protected $request;
/**
*
* @var array
*/
protected $users = array();
/**
*
* @var array
*/
protected $users_datas;
/**
*
* @var int
*/
protected $base_id;
/**
*
* @param Symfony\Component\HttpFoundation\Request $request
* @return module_admin_route_users_edit
*/
public function __construct(Symfony\Component\HttpFoundation\Request $request)
{
$this->users = explode(';', $request->get('users'));
$this->request = $request;
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$users = array();
foreach ($this->users as $usr_id)
{
$usr_id = (int) $usr_id;
if ($usr_id > 0)
$users[$usr_id] = $usr_id;
}
$this->users = $users;
return $this;
}
public function delete_users()
{
$appbox = appbox::get_instance();
foreach ($this->users as $usr_id)
{
$user = User_Adapter::getInstance($usr_id, $appbox);
$this->delete_user($user);
}
return $this;
}
protected function delete_user(User_Adapter $user)
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$list = array_keys(User_Adapter::getInstance($session->get_usr_id(), $appbox)->ACL()->get_granted_base(array('canadmin')));
$user->ACL()->revoke_access_from_bases($list);
if ($user->ACL()->is_phantom())
$user->delete();
return $this;
}
public function get_users_rights()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$list = array_keys(User_Adapter::getInstance($session->get_usr_id(), $appbox)->ACL()->get_granted_base(array('canadmin')));
$sql = "SELECT
b.sbas_id,
b.base_id,
sum(actif) as actif,
sum(canputinalbum) as canputinalbum,
sum(candwnldpreview) as candwnldpreview,
sum(candwnldhd) as candwnldhd,
sum(cancmd) as cancmd,
sum(nowatermark) as nowatermark,
sum(canaddrecord) as canaddrecord,
sum(canmodifrecord) as canmodifrecord,
sum(chgstatus) as chgstatus,
sum(candeleterecord) as candeleterecord,
sum(imgtools) as imgtools,
sum(canadmin) as canadmin,
sum(canreport) as canreport,
sum(canpush) as canpush,
sum(manage) as manage,
sum(modify_struct) as modify_struct,
sum(sbu.bas_modif_th) as bas_modif_th,
sum(sbu.bas_manage) as bas_manage,
sum(sbu.bas_modify_struct) as bas_modify_struct,
sum(sbu.bas_chupub) as bas_chupub,
sum(time_limited) as time_limited,
DATE_FORMAT(limited_from,'%Y%m%d') as limited_from,
DATE_FORMAT(limited_to,'%Y%m%d') as limited_to,
sum(restrict_dwnld) as restrict_dwnld,
sum(remain_dwnld) as remain_dwnld,
sum(month_dwnld_max) as month_dwnld_max,
mask_xor as maskxordec,
bin(mask_xor) as maskxorbin,
mask_and as maskanddec,
bin(mask_and) as maskandbin
FROM (usr u, bas b, sbas s)
LEFT JOIN (basusr bu)
ON (bu.base_id = b.base_id AND u.usr_id = bu.usr_id)
LEFT join sbasusr sbu
ON (sbu.sbas_id = b.sbas_id AND u.usr_id = sbu.usr_id)
WHERE ( (u.usr_id = " . implode(' OR u.usr_id = ', $this->users) . " )
AND b.sbas_id = s.sbas_id
AND (b.base_id = '" . implode("' OR b.base_id = '", $list) . "'))
GROUP BY b.base_id
ORDER BY s.ord, s.sbas_id, b.ord, b.base_id ";
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute();
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$sql = 'SELECT base_id, sum(1) as access FROM basusr
WHERE (usr_id = ' . implode(' OR usr_id = ', $this->users) . ')
AND (base_id = ' . implode(' OR base_id = ', $list) . ')
GROUP BY base_id';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute();
$access = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$base_ids = array();
foreach ($access as $acc)
{
$base_ids[$acc['base_id']] = $acc;
}
unset($access);
foreach ($rs as $k => $row)
{
$rs[$k]['access'] = array_key_exists($row['base_id'], $base_ids) ? $base_ids[$row['base_id']]['access'] : '0';
foreach ($row as $dk => $data)
{
if (is_null($data))
$rs[$k][$dk] = '0';
}
}
$this->users_datas = $rs;
$out = array(
'datas' => $this->users_datas,
'users' => $this->users,
'users_serial' => implode(';', $this->users),
'base_id' => $this->base_id,
'main_user' => null
);
if (count($this->users) == 1)
{
$usr_id = array_pop($this->users);
$out['main_user'] = User_Adapter::getInstance($usr_id, $appbox);
}
return $out;
}
public function get_quotas()
{
$this->base_id = (int) $this->request->get('base_id');
// $this->base_id = (int) $parm['base_id'];
$sql = "SELECT u.usr_id, restrict_dwnld, remain_dwnld, month_dwnld_max
FROM (usr u INNER JOIN basusr bu ON u.usr_id = bu.usr_id)
WHERE u.usr_id = " . implode(' OR u.usr_id = ', $this->users) . "
AND bu.base_id = :base_id";
$conn = connection::getPDOConnection();
$stmt = $conn->prepare($sql);
$stmt->execute(array(':base_id' => $this->base_id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->users_datas = $rs;
return array(
'datas' => $this->users_datas,
'users' => $this->users,
'users_serial' => implode(';', $this->users),
'base_id' => $this->base_id
);
}
public function get_masks()
{
$this->base_id = (int) $this->request->get('base_id');
$sql = "SELECT BIN(mask_and) AS mask_and, BIN(mask_xor) AS mask_xor
FROM basusr
WHERE usr_id IN (" . implode(',', $this->users) . ")
AND base_id = :base_id";
$conn = connection::getPDOConnection();
$stmt = $conn->prepare($sql);
$stmt->execute(array(':base_id' => $this->base_id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$msk_and = null;
$msk_xor = null;
$tbits_and = array();
$tbits_xor = array();
$nrows = 0;
for ($bit = 0; $bit < 64; $bit++)
$tbits_and[$bit] = $tbits_xor[$bit] = array("nset" => 0);
foreach ($rs as $row)
{
$sta_xor = strrev($row["mask_xor"]);
for ($bit = 0; $bit < strlen($sta_xor); $bit++)
$tbits_xor[$bit]["nset"] += substr($sta_xor, $bit, 1) != "0" ? 1 : 0;
$sta_and = strrev($row["mask_and"]);
for ($bit = 0; $bit < strlen($sta_and); $bit++)
$tbits_and[$bit]["nset"] += substr($sta_and, $bit, 1) != "0" ? 1 : 0;
$nrows++;
}
$tbits_left = array();
$tbits_right = array();
$sbas_id = phrasea::sbasFromBas($this->base_id);
$databox = databox::get_instance($sbas_id);
$status = $databox->get_statusbits();
foreach ($status as $bit => $datas)
{
$tbits_left[$bit]["nset"] = 0;
$tbits_left[$bit]["name"] = $datas["labeloff"];
$tbits_left[$bit]["icon"] = $datas["img_off"];
$tbits_right[$bit]["nset"] = 0;
$tbits_right[$bit]["name"] = $datas["labelon"];
$tbits_right[$bit]["icon"] = $datas["img_on"];
}
$vand_and = $vand_or = $vxor_and = $vxor_or = "0000";
for ($bit = 4; $bit < 64; $bit++)
{
if (($tbits_and[$bit]["nset"] != 0 && $tbits_and[$bit]["nset"] != $nrows) || ($tbits_xor[$bit]["nset"] != 0 && $tbits_xor[$bit]["nset"] != $nrows))
{
if (isset($tbits_left[$bit]) && isset($tbits_right[$bit]))
{
$tbits_left[$bit]["nset"] = 2;
$tbits_right[$bit]["nset"] = 2;
}
$vand_and = "1" . $vand_and;
$vand_or = "0" . $vand_or;
$vxor_and = "1" . $vxor_and;
$vxor_or = "0" . $vxor_or;
}
else
{
if (isset($tbits_left[$bit]) && isset($tbits_right[$bit]))
{
$tbits_left[$bit]["nset"] = (($tbits_and[$bit]["nset"] == $nrows && $tbits_xor[$bit]["nset"] == 0) || $tbits_and[$bit]["nset"] == 0 ) ? 1 : 0;
$tbits_right[$bit]["nset"] = (($tbits_and[$bit]["nset"] == $nrows && $tbits_xor[$bit]["nset"] == $nrows) || $tbits_and[$bit]["nset"] == 0 ) ? 1 : 0;
}
$vand_and = ($tbits_and[$bit]["nset"] == 0 ? "0" : "1") . $vand_and;
$vand_or = ($tbits_and[$bit]["nset"] == $nrows ? "1" : "0") . $vand_or;
$vxor_and = ($tbits_xor[$bit]["nset"] == 0 ? "0" : "1") . $vxor_and;
$vxor_or = ($tbits_xor[$bit]["nset"] == $nrows ? "1" : "0") . $vxor_or;
}
}
$this->users_datas = array(
'tbits_left' => $tbits_left,
'tbits_right' => $tbits_right,
'vand_and' => $vand_and,
'vand_or' => $vand_or,
'vxor_and' => $vxor_and,
'vxor_or' => $vxor_or
);
return array(
'datas' => $this->users_datas,
'users' => $this->users,
'users_serial' => implode(';', $this->users),
'base_id' => $this->base_id
);
}
public function get_time()
{
$this->base_id = (int) $this->request->get('base_id');
$sql = "SELECT u.usr_id, time_limited, limited_from, limited_to
FROM (usr u INNER JOIN basusr bu ON u.usr_id = bu.usr_id)
WHERE u.usr_id = " . implode(' OR u.usr_id = ', $this->users) . "
AND bu.base_id = :base_id";
$conn = connection::getPDOConnection();
$stmt = $conn->prepare($sql);
$stmt->execute(array(':base_id' => $this->base_id));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$time_limited = -1;
$limited_from = $limited_to = false;
foreach ($rs as $row)
{
if ($time_limited < 0)
$time_limited = $row['time_limited'];
if ($time_limited < 2 && $row['time_limited'] != $row['time_limited'])
$time_limited = 2;
if ($limited_from !== '' && trim($row['limited_from']) != '0000-00-00 00:00:00')
{
$limited_from = $limited_from === false ? $row['limited_from'] : (($limited_from == $row['limited_from']) ? $limited_from : '');
}
if ($limited_to !== '' && trim($row['limited_to']) != '0000-00-00 00:00:00')
{
$limited_to = $limited_to === false ? $row['limited_to'] : (($limited_to == $row['limited_to']) ? $limited_to : '');
}
}
if ($limited_from)
{
$date_obj_from = new DateTime($limited_from);
$limited_from = $date_obj_from->format('Y-m-d');
}
if ($limited_to)
{
$date_obj_to = new DateTime($limited_to);
$limited_to = $date_obj_to->format('Y-m-d');
}
$datas = array('time_limited' => $time_limited, 'limited_from' => $limited_from, 'limited_to' => $limited_to);
$this->users_datas = $datas;
return array(
'datas' => $this->users_datas,
'users' => $this->users,
'users_serial' => implode(';', $this->users),
'base_id' => $this->base_id
);
}
public function apply_rights()
{
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$request = http_request::getInstance();
$ACL = User_Adapter::getInstance($session->get_usr_id(), $appbox)->ACL();
$base_ids = array_keys($ACL->get_granted_base(array('canadmin')));
$update = $create = $delete = $create_sbas = $update_sbas = array();
foreach ($base_ids as $base_id)
{
$rights = array(
'access',
'actif',
'canputinalbum',
'nowatermark',
'candwnldpreview',
'candwnldhd',
'cancmd',
'canaddrecord',
'canmodifrecord',
'chgstatus',
'candeleterecord',
'imgtools',
'canadmin',
'canreport',
'canpush',
'manage',
'modify_struct'
);
foreach ($rights as $k => $right)
{
if (($right == 'access' && !$ACL->has_access_to_base($base_id))
|| ($right != 'access' && !$ACL->has_right_on_base($base_id, $right)))
{
unset($rights[$k]);
continue;
}
$rights[$k] = $right . '_' . $base_id;
}
$parm = $request->get_parms_from_serialized_datas($rights, 'values');
foreach ($parm as $p => $v)
{
if (trim($v) == '')
continue;
$serial = explode('_', $p);
$base_id = array_pop($serial);
$p = implode('_', $serial);
if ($p == 'access')
{
if ($v === '1')
{
$create_sbas[phrasea::sbasFromBas($base_id)] = phrasea::sbasFromBas($base_id);
$create[] = $base_id;
}
else
$delete[] = $base_id;
}
else
{
$create_sbas[phrasea::sbasFromBas($base_id)] = phrasea::sbasFromBas($base_id);
$update[$base_id][$p] = $v;
}
}
}
$sbas_ids = $ACL->get_granted_sbas();
foreach ($sbas_ids as $databox)
{
$rights = array(
'bas_modif_th',
'bas_manage',
'bas_modify_struct',
'bas_chupub'
);
foreach ($rights as $k => $right)
{
if (!$ACL->has_right_on_sbas($databox->get_sbas_id(), $right))
{
unset($rights[$k]);
continue;
}
$rights[$k] = $right . '_' . $databox->get_sbas_id();
}
$parm = $request->get_parms_from_serialized_datas($rights, 'values');
foreach ($parm as $p => $v)
{
if (trim($v) == '')
continue;
$serial = explode('_', $p);
$sbas_id = array_pop($serial);
$p = implode('_', $serial);
$update_sbas[$sbas_id][$p] = $v;
}
}
foreach ($this->users as $usr_id)
{
try
{
$appbox->get_connection()->beginTransaction();
$user = User_Adapter::getInstance($usr_id, $appbox);
$user->ACL()->revoke_access_from_bases($delete)
->give_access_to_base($create)
->give_access_to_sbas($create_sbas);
foreach ($update as $base_id => $rights)
{
$user->ACL()->update_rights_to_base($base_id, $rights);
}
foreach ($update_sbas as $sbas_id => $rights)
{
$user->ACL()->update_rights_to_sbas($sbas_id, $rights);
}
$appbox->get_connection()->commit();
$user->ACL()->revoke_unused_sbas_rights();
unset($user);
}
catch (Exception $e)
{
$appbox->get_connection()->rollBack();
}
}
return $this;
}
public function apply_infos()
{
if (count($this->users) != 1)
{
return $this;
}
$appbox = appbox::get_instance();
$session = $appbox->get_session();
$request = http_request::getInstance();
$infos = array(
'gender'
, 'first_name'
, 'last_name'
, 'email'
, 'address'
, 'zip'
, 'geonameid'
, 'function'
, 'company'
, 'activite'
, 'telephone'
, 'fax'
);
$parm = $request->get_parms_from_serialized_datas($infos, 'user_infos');
foreach ($this->users as $usr_id)
{
if (!mail::validateEmail($parm['email']))
throw new Exception_InvalidArgument(_('Email addess is not valid'));
$user = User_Adapter::getInstance($usr_id, $appbox);
$user->set_firstname($parm['first_name'])
->set_lastname($parm['last_name'])
->set_email($parm['email'])
->set_address($parm['address'])
->set_zip($parm['zip'])
->set_geonameid($parm['geonameid'])
->set_position($parm['function'])
->set_job($parm['activite'])
->set_company($parm['company'])
->set_tel($parm['telephone'])
->set_fax($parm['fax']);
}
return $this;
}
public function apply_quotas()
{
$this->base_id = (int) $this->request->get('base_id');
foreach ($this->users as $usr_id)
{
$user = User_Adapter::getInstance($usr_id, appbox::get_instance());
if ($this->request->get('quota'))
$user->ACL()->set_quotas_on_base($this->base_id, $this->request->get('droits'), $this->request->get('restes'));
else
$user->ACL()->remove_quotas_on_base($this->base_id);
}
return $this;
}
public function apply_masks()
{
$this->base_id = (int) $this->request->get('base_id');
$vand_and = $this->request->get('vand_and');
$vand_or = $this->request->get('vand_or');
$vxor_and = $this->request->get('vxor_and');
$vxor_or = $this->request->get('vxor_or');
if ($vand_and && $vand_or && $vxor_and && $vxor_or)
{
foreach ($this->users as $usr_id)
{
$user = User_Adapter::getInstance($usr_id, appbox::get_instance());
$user->ACL()->set_masks_on_base($this->base_id, $vand_and, $vand_or, $vxor_and, $vxor_or);
}
}
return $this;
}
public function apply_time()
{
$this->base_id = (int) $this->request->get('base_id');
$dmin = $this->request->get('dmin') ? new DateTime($this->request->get('dmin')) : null;
$dmax = $this->request->get('dmax') ? new DateTime($this->request->get('dmax')) : null;
$activate = $this->request->get('limit');
foreach ($this->users as $usr_id)
{
$user = User_Adapter::getInstance($usr_id, appbox::get_instance());
$user->ACL()->set_limits($this->base_id, $activate, $dmin, $dmax);
}
}
}

View File

@@ -1,433 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
*
* @package OAuth2 Connector
*
* @see http://oauth.net/2/
* @uses http://code.google.com/p/oauth2-php/
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
require_once dirname(__FILE__) . "/../../../../lib/bootstrap.php";
require_once dirname(__FILE__) . "/../../../../lib/classes/API/OAuth2/Autoloader.class.php";
bootstrap::register_autoloads();
API_OAuth2_Autoloader::register();
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
return call_user_func(function()
{
$app = new Silex\Application();
$app->register(new Silex\Provider\ValidatorServiceProvider(), array(
'validator.class_path' => __DIR__ . '/../../../../lib/vendor/symfony/src',
));
$app['appbox'] = function()
{
return appbox::get_instance();
};
$app['supertwig'] = $app->share(function()
{
$twig = new supertwig();
$twig->addFilter(array('prettyDate' => 'phraseadate::getPrettyString'));
return $twig;
});
$app['oauth'] = function($app)
{
return new API_OAuth2_Adapter($app['appbox']);
};
$app['user'] = function($app)
{
if ($app['appbox']->get_session()->is_authenticated())
{
$user = user_adapter::getInstance(
$app['appbox']->get_session()->get_usr_id()
, $app['appbox']
);
return $user;
}
else
{
return null;
}
};
/**
* Protected Closure
* @var Closure
* @return Symfony\Component\HttpFoundation\Response
*/
$app['response'] = $app->protect(function ($template, $variable) use ($app)
{
$response = new Response(
$app['supertwig']->render($template, $variable)
, 200
, array('Content-Type' => 'text/html')
);
$response->setCharset('UTF-8');
return $response;
});
/* * *******************************************************************
* AUTHENTIFICATION API
*/
/**
* 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'];
$twig = $app['supertwig'];
$session = $app['appbox']->get_session();
//Check for auth params, send error or redirect if not valid
$params = $oauth2_adapter->getAuthorizationRequestParameters($request);
$authenticated = $session->is_authenticated();
$app_authorized = false;
$errorMessage = false;
$client = API_OAuth2_Application::load_from_client_id($app['appbox'], $params['client_id']);
$oauth2_adapter->setClient($client);
$action_accept = $request->get("action_accept", null);
$action_login = $request->get("action_login", null);
$template = "api/auth/end_user_authorization.twig";
$custom_template = $app['appbox']->get_registry()->get('GV_RootPath') . 'config/templates/web/api/auth/end_user_authorization/' . $client->get_id() . '.twig';
if (file_exists($custom_template))
{
$template = 'api/auth/end_user_authorization/' . $client->get_id() . '.twig';
}
if (!$authenticated)
{
if ($action_login !== null)
{
try
{
$login = $request->get("login");
$password = $request->get("password");
$auth = new Session_Authentication_Native($app['appbox'], $login, $password);
$session->authenticate($auth);
}
catch (Exception $e)
{
$params = array(
"auth" => $oauth2_adapter
, "session" => $session
, "errorMessage" => true
, "user" => $app['user']
);
$html = $twig->render($template, $params);
return new Response($html, 200, array("content-type" => "text/html"));
}
}
else
{
$params = array(
"auth" => $oauth2_adapter
, "session" => $session
, "errorMessage" => $errorMessage
, "user" => $app['user']
);
$html = $twig->render($template, $params);
return new Response($html, 200, array("content-type" => "text/html"));
}
}
//check if current client is alreadu authorized by current user
$user_auth_clients = API_OAuth2_Application::load_authorized_app_by_user($app['appbox'], $app['user']);
foreach ($user_auth_clients as $auth_client)
{
if ($client->get_client_id() == $auth_client->get_client_id())
$app_authorized = true;
}
$account = $oauth2_adapter->updateAccount($session->get_usr_id());
$params['account_id'] = $account->get_id();
if (!$app_authorized && $action_accept === null)
{
$params = array(
"auth" => $oauth2_adapter
, "session" => $session
, "errorMessage" => $errorMessage
, "user" => $app['user']
);
$html = $twig->render($template, $params);
return new Response($html, 200, array("content-type" => "text/html"));
}
elseif (!$app_authorized && $action_accept !== null)
{
$app_authorized = !!$action_accept;
$account->set_revoked(!$app_authorized);
}
//if native app show template
if ($oauth2_adapter->isNativeApp($params['redirect_uri']))
{
$params = $oauth2_adapter->finishNativeClientAuthorization($app_authorized, $params);
$html = $twig->render("api/auth/native_app_access_token.twig", $params);
return new Response($html, 200, array("content-type" => "text/html"));
}
else
{
$oauth2_adapter->finishClientAuthorization($app_authorized, $params);
}
};
$route = '/authorize';
$app->get($route, $authorize_func);
$app->post($route, $authorize_func);
/**
* TOKEN ENDPOINT
* Token endpoint - used to exchange an authorization grant for an access token.
*/
$route = '/token';
$app->post($route, function() use ($app)
{
$app['oauth']->grantAccessToken();
ob_flush();
flush();
return;
});
/**
* MANAGEMENT APPS
*
*
*/
/**
* list of all authorized apps by logged user
*/
$route = '/applications';
$app->get($route, function() use ($app)
{
$apps = API_OAuth2_Application::load_app_by_user($app['appbox'], $app['user']);
return $app['response']('api/auth/applications.twig', array("apps" => $apps, 'user' => $app['user']));
});
/**
* list of apps created by user
*/
$route = "/applications/dev";
$app->get($route, function() use ($app)
{
$rs = API_OAuth2_Application::load_dev_app_by_user($app['appbox'], $app['user']);
return $app['response']('api/auth/application_dev.twig', array("apps" => $rs));
});
/**
* display a new app form
*/
$route = "/applications/dev/new";
$app->get($route, function() use ($app)
{
$var = array("violations" => null);
return $app['response']('api/auth/application_dev_new.twig', $var);
});
$route = "/applications/dev/create";
$app->post($route, function() use ($app)
{
$submit = false;
$post = new API_OAuth2_Form_DevApp($app['request']);
$violations = $app['validator']->validate($post);
if ($violations->count() == 0)
$submit = true;
$request = $app['request'];
if ($submit)
{
$application = API_OAuth2_Application::create($app['appbox'], $app['user'], $request->get('name'));
$application->set_description($request->get('description'))
->set_redirect_uri($request->get('callback'))
->set_type($request->get('type'))
->set_website($request->get('website'));
return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show");
}
$var = array(
"violations" => $violations,
"form" => $post
);
return $app['response']('api/auth/application_dev_new.twig', $var);
});
/**
* show details of app identified by its id
*/
$route = "/applications/dev/{id}/show";
$app->get($route, function($id) use ($app)
{
$client = new API_OAuth2_Application($app['appbox'], $id);
$token = $client->get_user_account($app['user'])->get_token()->get_value();
$var = array("app" => $client, "user" => $app['user'], "token" => $token);
return $app['response']('api/auth/application_dev_show.twig', $var);
});
/**
* revoke access from a user to the app
* identified by account id
*/
$route = "/applications/revoke_access/";
$app->post($route, function() use ($app)
{
$result = array("ok" => false);
try
{
$account = new API_OAuth2_Account($app['appbox'], $app['request']->get('account_id'));
$account->set_revoked((bool) $app['request']->get('revoke'));
$result['ok'] = true;
}
catch (Exception $e)
{
}
return new Response(json_encode($result), 200, array("content-type" => "application/json"));
});
$route = "/applications/{id}/generate_access_token/";
$app->post($route, function($id) use ($app)
{
$result = array("ok" => false);
try
{
$client = new API_OAuth2_Application($app['appbox'], $id);
$account = $client->get_user_account($app['user']);
$token = $account->get_token();
if ($token instanceof API_OAuth2_Token)
$token->renew();
else
$token = API_OAuth2_Token::create($app['appbox'], $account);
$result = array(
"ok" => true
, 'token' => $token->get_value()
);
}
catch (Exception $e)
{
}
return new response(json_encode($result), 200, array("content-type" => "application/json"));
});
$route = "/applications/oauth_callback";
$app->post($route, function() use ($app)
{
$app_id = $app['request']->request->get("app_id");
$app_callback = $app["request"]->request->get("callback");
$result = array("success" => false);
try
{
$client = new API_OAuth2_Application($app['appbox'], $app_id);
$client->set_redirect_uri($app_callback);
$result['success'] = true;
}
catch (Exception $e)
{
}
return new Response(json_encode($result), 200, array("content-type" => "application/json"));
});
$route = "/applications/{id}";
$app->delete($route, function($id) use ($app)
{
$result = array("success" => false);
try
{
$client = new API_OAuth2_Application($app['appbox'], $id);
$client->delete();
$result['success'] = true;
}
catch (Exception $e)
{
}
return new Response(json_encode($result), 200, array("content-type" => "application/json"));
});
/**
* *******************************************************************
*
* Route Errors
*
*/
$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);
}
$code = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
return new Response('We are sorry, but something went terribly wrong.<br />' . $e->getMessage(), $code);
});
return $app;
});

View File

@@ -1,748 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package APIv1
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
/**
* Application Routage for API v1
*/
require_once dirname(__FILE__) . "/../../../../lib/classes/API/OAuth2/Autoloader.class.php";
require_once dirname(__FILE__) . "/../../../../lib/bootstrap.php";
bootstrap::register_autoloads();
API_OAuth2_Autoloader::register();
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception;
return call_user_func(function(){
$app = new Silex\Application();
$app["appbox"] = appbox::get_instance();
/**
* Associated user to related token
* @var User_Adapter
*/
$app['p4user'] = null;
/**
* @var API_OAuth2_Token
*/
$app['token'] = null;
/**
* Protected Closure
* @var Closure
* @return Symfony\Component\HttpFoundation\Response
*/
$app['response'] = $app->protect(function ($result)
{
$response = new Response(
$result->format()
, $result->get_http_code()
, array('Content-Type' => $result->get_content_type())
);
$response->setCharset('UTF-8');
return $response;
});
/**
* Api Service
* @var Closure
*/
$app['api'] = function () use ($app)
{
return new API_V1_adapter(false, $app["appbox"]);
};
$parseRoute = function ($route, Response $response)
{
$ressource = $general = $aspect = $action = null;
$exploded_route = explode('/', p4string::delFirstSlash((p4string::delEndSlash($route))));
if (sizeof($exploded_route) > 0 && $response->isOk())
{
$ressource = $exploded_route[0];
if (sizeof($exploded_route) == 2 && (int) $exploded_route[1] == 0)
{
$general = $exploded_route[1];
}
else
{
switch ($ressource)
{
case API_V1_Log::DATABOXES_RESSOURCE :
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3)
$aspect = $exploded_route[2];
break;
case API_V1_Log::RECORDS_RESSOURCE :
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 4)
{
if (!isset($exploded_route[3]))
$aspect = "record";
elseif (preg_match("/^set/", $exploded_route[3]))
$action = $exploded_route[3];
else
$aspect = $exploded_route[3];
}
break;
case API_V1_Log::BASKETS_RESSOURCE :
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3)
{
if (preg_match("/^set/", $exploded_route[2]) || preg_match("/^delete/", $exploded_route[2]))
$action = $exploded_route[2];
else
$aspect = $exploded_route[2];
}
break;
case API_V1_Log::FEEDS_RESSOURCE :
if ((int) $exploded_route[1] > 0 && sizeof($exploded_route) == 3)
$aspect = $exploded_route[2];
break;
}
}
}
return array('ressource' => $ressource, 'general' => $general, 'aspect' => $aspect, 'action' => $action);
};
/**
* oAuth verification process
*/
$app->before(function($request) use ($app)
{
$session = $app["appbox"]->get_session();
$oauth2_adapter = new API_OAuth2_Adapter($app["appbox"]);
$oauth2_adapter->verifyAccessToken();
$app['p4user'] = User_Adapter::getInstance($oauth2_adapter->get_usr_id(), $app["appbox"]);
$app['token'] = API_OAuth2_Token::load_by_oauth_token($app["appbox"], $oauth2_adapter->getToken());
if ($session->is_authenticated())
return;
if ($oauth2_adapter->has_ses_id())
{
try
{
$session->restore($app['p4user'], $oauth2_adapter->get_ses_id());
return;
}
catch (\Exception $e)
{
}
}
$auth = new Session_Authentication_None($app['p4user']);
$session->authenticate($auth);
$oauth2_adapter->remember_this_ses_id($session->get_ses_id());
return;
});
/**
* oAUth log process
*/
$app->after(function (Request $request, Response $response) use ($app, $parseRoute)
{
$account = $app['token']->get_account();
$pathInfo = $request->getPathInfo();
$route = $parseRoute($pathInfo, $response);
$log = API_V1_Log::create(
$app["appbox"],
$account,
$request->getMethod() . " " . $pathInfo,
$response->getStatusCode(),
$response->headers->get('content-type'),
$route['ressource'],
$route['general'],
$route['aspect'],
$route['action']);
});
/**
* Method Not Allowed Closure
*/
$bad_request_exception = function()
{
throw new API_V1_exception_badrequest();
};
/**
* *******************************************************************
* Route : /databoxes/list/FORMAT/
*
* Method : GET
*
* Parameters :
*
*/
$route = '/databoxes/list/';
$app->get(
$route, function() use ($app)
{
return $app['response']($app['api']->get_databoxes($app['request']));
}
);
/**
* *******************************************************************
*
* Route /databoxes/DATABOX_ID/collections/FORMAT/
*
* Method : GET
*
* Parameters ;
* DATABOX_ID : required INT
*/
$route = '/databoxes/{databox_id}/collections/';
$app->get(
$route, function($databox_id) use ($app)
{
$result = $app['api']->get_databox_collections($app['request'], $databox_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+');
$app->get('/databoxes/{any_id}/collections/', $bad_request_exception);
/**
* *******************************************************************
* Route /databoxes/DATABOX_ID/status/FORMAT/
*
* Method : GET
*
* Parameters ;
* DATABOX_ID : required INT
*
*/
$route = '/databoxes/{databox_id}/status/';
$app->get(
$route, function($databox_id) use ($app)
{
$result = $app['api']->get_databox_status($app['request'], $databox_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+');
$app->get('/databoxes/{any_id}/status/', $bad_request_exception);
/**
* Route /databoxes/DATABOX_ID/metadatas/FORMAT/
*
* Method : GET
*
* Parameters ;
* DATABOX_ID : required INT
*/
$route = '/databoxes/{databox_id}/metadatas/';
$app->get(
$route, function($databox_id) use ($app)
{
$result = $app['api']->get_databox_metadatas($app['request'], $databox_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+');
$app->get('/databoxes/{any_id}/metadatas/', $bad_request_exception);
/**
* Route /databoxes/DATABOX_ID/termsOfUse/FORMAT/
*
* Method : GET
*
* Parameters ;
* DATABOX_ID : required INT
*/
$route = '/databoxes/{databox_id}/termsOfUse/';
$app->get(
$route, function($databox_id) use ($app)
{
$result = $app['api']->get_databox_terms($app['request'], $databox_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+');
$app->get('/databoxes/{any_id}/termsOfUse/', $bad_request_exception);
/**
* Route : /records/search/FORMAT/
*
* Method : GET or POST
*
* Parameters :
* bases[] : array
* status[] : array
* fields[] : array
* record_type : boolean
* media_type : string
*
* Response :
* Array of record objects
*
*/
$route = '/records/search/';
$app->post(
$route, function() use ($app)
{
$result = $app['api']->search_records($app['request']);
return $app['response']($result);
}
);
/**
* Route : /records/DATABOX_ID/RECORD_ID/metadatas/FORMAT/
*
* Method : GET
*
* Parameters :
* DATABOX_ID : required INT
* RECORD_ID : required INT
*
*/
$route = '/records/{databox_id}/{record_id}/metadatas/';
$app->get(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->get_record_metadatas($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->get('/records/{any_id}/{anyother_id}/metadatas/', $bad_request_exception);
/**
* Route : /records/DATABOX_ID/RECORD_ID/status/FORMAT/
*
* Method : GET
*
* Parameters :
* DATABOX_ID : required INT
* RECORD_ID : required INT
*
*/
$route = '/records/{databox_id}/{record_id}/status/';
$app->get(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->get_record_status($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->get('/records/{any_id}/{anyother_id}/status/', $bad_request_exception);
/**
* Route : /records/DATABOX_ID/RECORD_ID/related/FORMAT/
*
* Method : GET
*
* Parameters :
* DATABOX_ID : required INT
* RECORD_ID : required INT
*
*/
$route = '/records/{databox_id}/{record_id}/related/';
$app->get(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->get_record_related($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->get('/records/{any_id}/{anyother_id}/related/', $bad_request_exception);
/**
* Route : /records/DATABOX_ID/RECORD_ID/embed/FORMAT/
*
* Method : GET
*
* Parameters :
* DATABOX_ID : required INT
* RECORD_ID : required INT
*
*/
$route = '/records/{databox_id}/{record_id}/embed/';
$app->get(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->get_record_embed($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->get('/records/{any_id}/{anyother_id}/embed/', $bad_request_exception);
/**
* Route : /records/DATABOX_ID/RECORD_ID/setmetadatas/FORMAT/
*
* Method : POST
*
* Parameters :
* DATABOX_ID : required INT
* RECORD_ID : required INT
*
*/
$route = '/records/{databox_id}/{record_id}/setmetadatas/';
$app->post(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->set_record_metadatas($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->post('/records/{any_id}/{anyother_id}/setmetadatas/', $bad_request_exception);
/**
* Route : /records/DATABOX_ID/RECORD_ID/setstatus/FORMAT/
*
* Method : POST
*
* Parameters :
* DATABOX_ID : required INT
* RECORD_ID : required INT
*
*/
$route = '/records/{databox_id}/{record_id}/setstatus/';
$app->post(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->set_record_status($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->post('/records/{any_id}/{anyother_id}/setstatus/', $bad_request_exception);
/**
* Route : /records/DATABOX_ID/RECORD_ID/setcollection/FORMAT/
*
* Method : POST
*
* Parameters :
* DATABOX_ID : required INT
* RECORD_ID : required INT
*
*/
$route = '/records/{databox_id}/{record_id}/setcollection/';
$app->post(
$route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->set_record_collection($app['request'], $databox_id, $record_id);
return $app['response']($result);
}
)->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->post('/records/{wrong_databox_id}/{wrong_record_id}/setcollection/', $bad_request_exception);
$route = '/records/{databox_id}/{record_id}/';
$app->get($route, function($databox_id, $record_id) use ($app)
{
$result = $app['api']->get_record($app['request'], $databox_id, $record_id);
return $app['response']($result);
})->assert('databox_id', '\d+')->assert('record_id', '\d+');
$app->get('/records/{any_id}/{anyother_id}/', $bad_request_exception);
/**
* Route : /baskets/list/FORMAT/
*
* Method : POST
*
* Parameters :
*
*/
$route = '/baskets/list/';
$app->get(
$route, function() use ($app)
{
$result = $app['api']->search_baskets($app['request']);
return $app['response']($result);
}
);
/**
* Route : /baskets/add/FORMAT/
*
* Method : POST
*
* Parameters :
*
*/
$route = '/baskets/add/';
$app->post(
$route, function() use ($app)
{
$result = $app['api']->create_basket($app['request']);
return $app['response']($result);
}
);
/**
* Route : /baskets/BASKET_ID/content/FORMAT/
*
* Method : GET
*
* Parameters :
* BASKET_ID : required INT
*
*/
$route = '/baskets/{basket_id}/content/';
$app->get(
$route, function($basket_id) use ($app)
{
$result = $app['api']->get_basket($app['request'], $basket_id);
return $app['response']($result);
}
)->assert('basket_id', '\d+');
$app->get('/baskets/{wrong_basket_id}/content/', $bad_request_exception);
/**
* Route : /baskets/BASKET_ID/settitle/FORMAT/
*
* Method : GET
*
* Parameters :
* BASKET_ID : required INT
*
*/
$route = '/baskets/{basket_id}/setname/';
$app->post(
$route, function($basket_id) use ($app)
{
$result = $app['api']->set_basket_title($app['request'], $basket_id);
return $app['response']($result);
}
)->assert('basket_id', '\d+');
$app->post('/baskets/{wrong_basket_id}/setname/', $bad_request_exception);
/**
* Route : /baskets/BASKET_ID/setdescription/FORMAT/
*
* Method : POST
*
* Parameters :
* BASKET_ID : required INT
*
*/
$route = '/baskets/{basket_id}/setdescription/';
$app->post(
$route, function($basket_id) use ($app)
{
$result = $app['api']->set_basket_description($app['request'], $basket_id);
return $app['response']($result);
}
)->assert('basket_id', '\d+');
$app->post('/baskets/{wrong_basket_id}/setdescription/', $bad_request_exception);
/**
* Route : /baskets/BASKET_ID/delete/FORMAT/
*
* Method : POST
*
* Parameters :
* BASKET_ID : required INT
*
*/
$route = '/baskets/{basket_id}/delete/';
$app->post(
$route, function($basket_id) use ($app)
{
$result = $app['api']->delete_basket($app['request'], $basket_id);
return $app['response']($result);
}
)->assert('basket_id', '\d+');
$app->post('/baskets/{wrong_basket_id}/delete/', $bad_request_exception);
/**
* Route : /feeds/list/FORMAT/
*
* Method : POST
*
* Parameters :
*
*/
// public function search_publications(\Symfony\Component\HttpFoundation\Request $app['request']);
$route = '/feeds/list/';
$app->get(
$route, function() use ($app)
{
$result = $app['api']->search_publications($app['request'], $app['p4user']);
return $app['response']($result);
}
);
/**
* Route : /feeds/PUBLICATION_ID/content/FORMAT/
*
* Method : GET
*
* Parameters :
* PUBLICATION_ID : required INT
*
*/
// public function get_publication(\Symfony\Component\HttpFoundation\Request $app['request'], $publication_id);
$route = '/feeds/{feed_id}/content/';
$app->get(
$route, function($feed_id) use ($app)
{
$result = $app['api']->get_publication($app['request'], $feed_id, $app['p4user']);
return $app['response']($result);
}
)->assert('feed_id', '\d+');
$app->get('/feeds/{wrong_feed_id}/content/', $bad_request_exception);
/**
* *******************************************************************
*
* Route Errors
*
*/
$app->error(function (\Exception $e) use ($app)
{
if ($e instanceof API_V1_exception_methodnotallowed)
$code = API_V1_result::ERROR_METHODNOTALLOWED;
elseif ($e instanceof Exception\MethodNotAllowedHttpException)
$code = API_V1_result::ERROR_METHODNOTALLOWED;
elseif ($e instanceof API_V1_exception_badrequest)
$code = API_V1_result::ERROR_BAD_REQUEST;
elseif ($e instanceof API_V1_exception_forbidden)
$code = API_V1_result::ERROR_FORBIDDEN;
elseif ($e instanceof API_V1_exception_unauthorized)
$code = API_V1_result::ERROR_UNAUTHORIZED;
elseif ($e instanceof API_V1_exception_internalservererror)
$code = API_V1_result::ERROR_INTERNALSERVERERROR;
// elseif ($e instanceof API_V1_exception_notfound)
// $code = API_V1_result::ERROR_NOTFOUND;
elseif ($e instanceof Exception_NotFound)
$code = API_V1_result::ERROR_NOTFOUND;
elseif ($e instanceof Exception\NotFoundHttpException)
$code = API_V1_result::ERROR_NOTFOUND;
else
$code = API_V1_result::ERROR_INTERNALSERVERERROR;
$result = $app['api']->get_error_message($app['request'], $code);
return $app['response']($result);
});
//// public function get_version();
////
////
//// /**
//// * Route : /records/DATABOX_ID/RECORD_ID/addtobasket/FORMAT/
//// *
//// * Method : POST
//// *
//// * Parameters :
//// * DATABOX_ID : required INT
//// * RECORD_ID : required INT
//// *
//// */
//// public function add_record_tobasket(\Symfony\Component\HttpFoundation\Request $app['request'], $databox_id, $record_id);
////
////
//// /**
//// * Route : /feeds/PUBLICATION_ID/remove/FORMAT/
//// *
//// * Method : GET
//// *
//// * Parameters :
//// * PUBLICATION_ID : required INT
//// *
//// */
//// public function remove_publications(\Symfony\Component\HttpFoundation\Request $app['request'], $publication_id);
////
////
//// /**
//// * Route : /users/search/FORMAT/
//// *
//// * Method : POST-GET
//// *
//// * Parameters :
//// *
//// */
//// public function search_users(\Symfony\Component\HttpFoundation\Request $app['request']);
////
//// /**
//// * Route : /users/USER_ID/access/FORMAT/
//// *
//// * Method : GET
//// *
//// * Parameters :
//// * USER_ID : required INT
//// *
//// */
//// public function get_user_acces(\Symfony\Component\HttpFoundation\Request $app['request'], $usr_id);
////
//// /**
//// * Route : /users/add/FORMAT/
//// *
//// * Method : POST
//// *
//// * Parameters :
//// *
//// */
//// public function add_user(\Symfony\Component\HttpFoundation\Request $app['request']);
return $app;
});