mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
V 3.5 RC 1
This commit is contained in:
71
lib/classes/Controller/Admin/Fields.class.php
Normal file
71
lib/classes/Controller/Admin/Fields.class.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Admin_Fields implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
// $session->close_storage();
|
||||
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
|
||||
$controllers->get('/checkmulti/', function() use ($app, $appbox)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$multi = ($request->get('multi') === 'true');
|
||||
|
||||
$metadata = databox_field::load_class_from_xpath($request->get('source'));
|
||||
|
||||
$datas = array(
|
||||
'result' => ($multi === $metadata->is_multi())
|
||||
, 'is_multi' => $metadata->is_multi()
|
||||
);
|
||||
|
||||
return new Response(p4string::jsonencode($datas));
|
||||
});
|
||||
|
||||
$controllers->get('/checkreadonly/', function() use ($app, $appbox)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$readonly = ($request->get('readonly') === 'true');
|
||||
|
||||
$metadata = databox_field::load_class_from_xpath($request->get('source'));
|
||||
|
||||
$datas = array(
|
||||
'result' => ($readonly === $metadata->is_readonly())
|
||||
, 'is_readonly' => $metadata->is_readonly()
|
||||
);
|
||||
|
||||
return new Response(p4string::jsonencode($datas));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
199
lib/classes/Controller/Admin/Publications.class.php
Normal file
199
lib/classes/Controller/Admin/Publications.class.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Admin_Publications implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$controllers->get('/list/', function() use ($app, $appbox)
|
||||
{
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$feeds = Feed_Collection::load_all($appbox, $user);
|
||||
|
||||
$template = 'admin/publications/list.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('formatdate' => 'phraseadate::getDate'));
|
||||
|
||||
return $twig->render($template, array('feeds' => $feeds));
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/create/', function() use ($app, $appbox)
|
||||
{
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$request = $app['request'];
|
||||
|
||||
$feed = Feed_Adapter::create($appbox, $user, $request->get('title'), $request->get('subtitle'));
|
||||
|
||||
if($request->get('public') == '1')
|
||||
$feed->set_public (true);
|
||||
elseif ($request->get('base_id'))
|
||||
$feed->set_collection(collection::get_from_base_id($request->get('base_id')));
|
||||
|
||||
return $app->redirect('/admin/publications/list/');
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/feed/{id}/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
|
||||
$template = 'admin/publications/fiche.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(
|
||||
array(
|
||||
'formatdate' => 'phraseadate::getDate'
|
||||
)
|
||||
);
|
||||
|
||||
return $twig->render($template
|
||||
, array(
|
||||
'feed' => $feed
|
||||
, 'error' => $app['request']->get('error')
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/feed/{id}/update/', function($id) use ($app, $appbox)
|
||||
{
|
||||
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
if (!$feed->is_owner($user))
|
||||
return $app->redirect('/admin/publications/feed/' . $id . '/?error=' . _('You are not the owner of this feed, you can not edit it'));
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
try
|
||||
{
|
||||
$collection = collection::get_from_base_id($request->get('base_id'));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$collection = null;
|
||||
}
|
||||
|
||||
$feed->set_title($request->get('title'));
|
||||
$feed->set_subtitle($request->get('subtitle'));
|
||||
$feed->set_collection($collection);
|
||||
$feed->set_public($request->get('public'));
|
||||
|
||||
return $app->redirect('/admin/publications/list/');
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/feed/{id}/iconupload/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
if (!$feed->is_owner($user))
|
||||
return new Response('ERROR:you are not allowed');
|
||||
|
||||
if ($_FILES['Filedata']['error'] !== 0)
|
||||
return new Response('ERROR:error while upload');
|
||||
|
||||
$file = new system_file($_FILES['Filedata']['tmp_name']);
|
||||
if (!in_array($file->get_mime(), array('image/jpeg', 'image/jpg', 'image/gif')))
|
||||
return new Response('ERROR:bad filetype');
|
||||
|
||||
if ($file->getSize() > 200000)
|
||||
return new Response('ERROR:file too large');
|
||||
|
||||
$datas = $file->get_technical_datas();
|
||||
if (!isset($datas[system_file::TC_DATAS_WIDTH]) || !isset($datas[system_file::TC_DATAS_HEIGHT]))
|
||||
return new Response('ERROR:file is not square');
|
||||
|
||||
if ($datas[system_file::TC_DATAS_WIDTH] != $datas[system_file::TC_DATAS_HEIGHT])
|
||||
return new Response('ERROR:file is not square');
|
||||
|
||||
$feed->set_icon($file);
|
||||
unlink($file->getPathname());
|
||||
|
||||
return new Response('FILEHREF:' . $feed->get_icon_url() . '?' . mt_rand(100000, 999999));
|
||||
});
|
||||
|
||||
$controllers->post('/feed/{id}/addpublisher/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$error = '';
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
$user = User_Adapter::getInstance($request->get('usr_id'), $appbox);
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$feed->add_publisher($user);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
return $app->redirect('/admin/publications/feed/' . $id . '/');
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/feed/{id}/removepublisher/', function($id) use ($app, $appbox)
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$publisher = new Feed_Publisher_Adapter($appbox, $request->get('publisher_id'));
|
||||
$user = $publisher->get_user();
|
||||
if ($feed->is_publisher($user) === true && $feed->is_owner($user) === false)
|
||||
$publisher->delete();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
return $app->redirect('/admin/publications/feed/' . $id . '/?err=' . $error);
|
||||
});
|
||||
|
||||
$controllers->post('/feed/{id}/delete/', function($id) use ($app, $appbox)
|
||||
{
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
$feed->delete();
|
||||
|
||||
return $app->redirect('/admin/publications/list/');
|
||||
})->assert('id', '\d+');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
140
lib/classes/Controller/Admin/Subdefs.class.php
Normal file
140
lib/classes/Controller/Admin/Subdefs.class.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?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 Controller_Admin_Subdefs
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var databox
|
||||
*/
|
||||
protected $databox;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param http_request $request
|
||||
* @param databox $databox
|
||||
* @return controller_admin_subdefs
|
||||
*/
|
||||
public function __construct(http_request $request, databox &$databox)
|
||||
{
|
||||
$this->databox = $databox;
|
||||
if ($request->has_post_datas())
|
||||
{
|
||||
$parm = $request->get_parms('delete_subdef', 'add_subdef', 'subdefs');
|
||||
|
||||
$add_subdef = array('class' => null, 'name' => null, 'group' => null);
|
||||
foreach ($add_subdef as $k => $v)
|
||||
{
|
||||
if (!isset($parm['add_subdef'][$k]) || trim($parm['add_subdef'][$k]) === '')
|
||||
unset($add_subdef[$k]);
|
||||
else
|
||||
$add_subdef[$k] = $parm['add_subdef'][$k];
|
||||
}
|
||||
|
||||
if ($parm['delete_subdef'])
|
||||
{
|
||||
$delete_subef = explode('_', $parm['delete_subdef']);
|
||||
$group = $delete_subef[0];
|
||||
$name = $delete_subef[1];
|
||||
|
||||
$subdefs = $this->databox->get_subdef_structure();
|
||||
$subdefs->delete_subdef($group, $name);
|
||||
}
|
||||
elseif (count($add_subdef) === 3)
|
||||
{
|
||||
$subdefs = $this->databox->get_subdef_structure();
|
||||
|
||||
$group = $add_subdef['group'];
|
||||
$name = $add_subdef['name'];
|
||||
$class = $add_subdef['class'];
|
||||
|
||||
$subdefs->add_subdef($group, $name, $class);
|
||||
}
|
||||
else
|
||||
{
|
||||
$subdefs = $this->databox->get_subdef_structure();
|
||||
|
||||
$options = array();
|
||||
|
||||
foreach ($parm['subdefs'] as $post_sub)
|
||||
{
|
||||
$post_sub_ex = explode('_', $post_sub);
|
||||
$group = $post_sub_ex[0];
|
||||
$name = $post_sub_ex[1];
|
||||
|
||||
$parm_loc = $request->get_parms($post_sub . '_class', $post_sub . '_downloadable');
|
||||
|
||||
$class = $parm_loc[$post_sub . '_class'];
|
||||
$downloadable = $parm_loc[$post_sub . '_downloadable'];
|
||||
|
||||
$defaults = array('path', 'baseurl', 'meta', 'mediatype');
|
||||
foreach ($defaults as $def)
|
||||
{
|
||||
$parm_loc = $request->get_parms($post_sub . '_' . $def);
|
||||
|
||||
if ($def == 'meta' && !$parm_loc[$post_sub . '_' . $def])
|
||||
{
|
||||
$parm_loc[$post_sub . '_' . $def] = "no";
|
||||
}
|
||||
|
||||
$options[$def] = $parm_loc[$post_sub . '_' . $def];
|
||||
}
|
||||
|
||||
$parm_loc = $request->get_parms($post_sub . '_mediatype');
|
||||
$mediatype = $parm_loc[$post_sub . '_mediatype'];
|
||||
$parm_loc = $request->get_parms($post_sub . '_' . $mediatype);
|
||||
|
||||
if (isset($parm_loc[$post_sub . '_' . $mediatype]))
|
||||
{
|
||||
foreach ($parm_loc[$post_sub . '_' . $mediatype] as $option => $value)
|
||||
{
|
||||
if ($option == 'resolution' && $mediatype == 'image')
|
||||
$option = 'dpi';
|
||||
$options[$option] = $value;
|
||||
}
|
||||
}
|
||||
$subdefs->set_subdef($group, $name, $class, $downloadable, $options);
|
||||
}
|
||||
}
|
||||
|
||||
return phrasea::redirect('/admin/subdefs.php?p0=' . $databox->get_sbas_id());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return controller_admin_subdefs
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->display(
|
||||
'admin/subdefs.twig',
|
||||
array(
|
||||
'databox' => $this->databox,
|
||||
'subdefs' => $this->databox->get_subdef_structure()
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
367
lib/classes/Controller/Admin/Users.class.php
Normal file
367
lib/classes/Controller/Admin/Users.class.php
Normal file
@@ -0,0 +1,367 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Admin_Users implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$session = $appbox->get_session();
|
||||
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
|
||||
$controllers->post('/rights/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
$twig->addFilter(array('geoname_name_from_id' => 'geonames::name_from_id'));
|
||||
|
||||
return $twig->render($template, $rights->get_users_rights());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->get('/rights/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
$twig->addFilter(array('geoname_name_from_id' => 'geonames::name_from_id'));
|
||||
|
||||
return $twig->render($template, $rights->get_users_rights());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/delete/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
|
||||
|
||||
|
||||
$module = new module_admin_route_users_edit($request);
|
||||
$module->delete_users();
|
||||
|
||||
return $app->redirect('/admin/users/search/');
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/apply/', function() use ($app)
|
||||
{
|
||||
$datas = array('error' => true);
|
||||
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_rights();
|
||||
$rights->apply_infos();
|
||||
|
||||
$datas = array('error' => false);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$datas['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return new Response(
|
||||
p4string::jsonencode($datas)
|
||||
, 200
|
||||
, array('Content-Type' => 'application/json')
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/quotas/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers_quotas.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
|
||||
return $twig->render($template, $rights->get_quotas());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/quotas/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_quotas();
|
||||
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/time/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers_timelimit.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
|
||||
return $twig->render($template, $rights->get_time());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/time/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_time();
|
||||
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/masks/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
|
||||
$template = 'admin/editusers_masks.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_name' => 'phrasea::bas_names'));
|
||||
$twig->addFilter(array('sbas_name' => 'phrasea::sbas_names'));
|
||||
$twig->addFilter(array('sbasFromBas' => 'phrasea::sbasFromBas'));
|
||||
|
||||
return $twig->render($template, $rights->get_masks());
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/rights/masks/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$rights = new module_admin_route_users_edit($request);
|
||||
$rights->apply_masks();
|
||||
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/search/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$users = new module_admin_route_users($request);
|
||||
$template = 'admin/users.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('floor' => 'floor'));
|
||||
$twig->addFilter(array('getDate' => 'phraseadate::getDate'));
|
||||
|
||||
return $twig->render($template, $users->search($request));
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->get('/search/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$users = new module_admin_route_users($request);
|
||||
$template = 'admin/users.html';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('floor' => 'floor'));
|
||||
$twig->addFilter(array('getDate' => 'phraseadate::getDate'));
|
||||
|
||||
return $twig->render($template, $users->search($request));
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->get('/typeahead/search/', function() use ($app, $appbox)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$user_query = new User_Query($appbox);
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$like_value = $request->get('term');
|
||||
$rights = $request->get('filter_rights') ? : array();
|
||||
$have_right = $request->get('have_right') ? : array();
|
||||
$have_not_right = $request->get('have_not_right') ? : array();
|
||||
$on_base = $request->get('on_base') ? : array();
|
||||
|
||||
|
||||
$elligible_users = $user_query->on_sbas_where_i_am($user->ACL(), $rights)
|
||||
->like(User_Query::LIKE_EMAIL, $like_value)
|
||||
->like(User_Query::LIKE_FIRSTNAME, $like_value)
|
||||
->like(User_Query::LIKE_LASTNAME, $like_value)
|
||||
->like(User_Query::LIKE_LOGIN, $like_value)
|
||||
->like_match(User_Query::LIKE_MATCH_OR)
|
||||
->who_have_right($have_right)
|
||||
->who_have_not_right($have_not_right)
|
||||
->on_base_ids($on_base)
|
||||
->execute()->get_results();
|
||||
|
||||
$datas = array();
|
||||
|
||||
foreach ($elligible_users as $user)
|
||||
{
|
||||
$datas[] = array(
|
||||
'email' => $user->get_email() ? : ''
|
||||
, 'login' => $user->get_login() ? : ''
|
||||
, 'name' => $user->get_display_name() ? : ''
|
||||
, 'id' => $user->get_id()
|
||||
);
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode($datas), 200, array('Content-type' => 'application/json'));
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/create/', function() use ($app)
|
||||
{
|
||||
|
||||
$datas = array('error' => false, 'message' => '', 'data' => null);
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
$module = new module_admin_route_users($request);
|
||||
if ($request->get('template') == '1')
|
||||
{
|
||||
$user = $module->create_template();
|
||||
}
|
||||
else
|
||||
{
|
||||
$user = $module->create_newuser();
|
||||
}
|
||||
if (!($user instanceof User_Adapter))
|
||||
throw new Exception('Unknown error');
|
||||
|
||||
$datas['data'] = $user->get_id();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$datas['error'] = true;
|
||||
$datas['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode($datas));
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/export/csv/', function() use ($appbox, $app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$user_query = new User_Query($appbox);
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$like_value = $request->get('like_value');
|
||||
$like_field = $request->get('like_field');
|
||||
$on_base = $request->get('base_id') ? : null;
|
||||
$on_sbas = $request->get('sbas_id') ? : null;
|
||||
|
||||
$elligible_users = $user_query->on_bases_where_i_am($user->ACL(), array('canadmin'))
|
||||
->like($like_field, $like_value)
|
||||
->on_base_ids($on_base)
|
||||
->on_sbas_ids($on_sbas);
|
||||
|
||||
$offset = 0;
|
||||
$geoname = new geonames();
|
||||
$buffer = array();
|
||||
|
||||
$buffer[] = array(
|
||||
'ID'
|
||||
, 'Login'
|
||||
, _('admin::compte-utilisateur nom')
|
||||
, _('admin::compte-utilisateur prenom')
|
||||
, _('admin::compte-utilisateur email')
|
||||
, 'CreationDate'
|
||||
, 'ModificationDate'
|
||||
, _('admin::compte-utilisateur adresse')
|
||||
, _('admin::compte-utilisateur ville')
|
||||
, _('admin::compte-utilisateur code postal')
|
||||
, _('admin::compte-utilisateur pays')
|
||||
, _('admin::compte-utilisateur telephone')
|
||||
, _('admin::compte-utilisateur fax')
|
||||
, _('admin::compte-utilisateur poste')
|
||||
, _('admin::compte-utilisateur societe')
|
||||
, _('admin::compte-utilisateur activite')
|
||||
);
|
||||
do
|
||||
{
|
||||
$elligible_users->limit($offset, 20);
|
||||
$offset += 20;
|
||||
|
||||
$results = $elligible_users->execute()->get_results();
|
||||
|
||||
foreach ($results as $user)
|
||||
{
|
||||
$buffer[] = array(
|
||||
$user->get_id()
|
||||
, $user->get_login()
|
||||
, $user->get_lastname()
|
||||
, $user->get_firstname()
|
||||
, $user->get_email()
|
||||
, phraseadate::format_mysql($user->get_creation_date())
|
||||
, phraseadate::format_mysql($user->get_modification_date())
|
||||
, $user->get_address()
|
||||
, $user->get_city()
|
||||
, $user->get_zipcode()
|
||||
, $geoname->get_country($user->get_geonameid())
|
||||
, $user->get_tel()
|
||||
, $user->get_fax()
|
||||
, $user->get_job()
|
||||
, $user->get_company()
|
||||
, $user->get_position()
|
||||
);
|
||||
}
|
||||
}
|
||||
while (count($results) > 0);
|
||||
|
||||
$out = format::arr_to_csv($buffer);
|
||||
|
||||
$headers = array(
|
||||
'Content-type' => 'text/csv'
|
||||
, 'Content-Disposition' => 'attachment; filename=export.txt;'
|
||||
);
|
||||
$response = new Response($out, 200, $headers);
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
}
|
||||
);
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
491
lib/classes/Controller/Prod/Records/Bridge.class.php
Normal file
491
lib/classes/Controller/Prod/Records/Bridge.class.php
Normal file
@@ -0,0 +1,491 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class Controller_Prod_Records_Bridge implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
$appbox = appbox::get_instance();
|
||||
$twig = new supertwig();
|
||||
|
||||
$app['require_connection'] = $app->protect(function(Bridge_Account $account) use ($app)
|
||||
{
|
||||
$app['current_account'] = function() use ($account)
|
||||
{
|
||||
return $account;
|
||||
};
|
||||
|
||||
if (!$account->get_api()->get_connector()->is_configured())
|
||||
throw new Bridge_Exception_ApiConnectorNotConfigured();
|
||||
if (!$account->get_api()->get_connector()->is_connected())
|
||||
throw new Bridge_Exception_ApiConnectorNotConnected ();
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
$controllers->post('/manager/'
|
||||
, function() use ($app, $twig)
|
||||
{
|
||||
$route = new module_prod_route_records_bridge($app['request']);
|
||||
$appbox = appbox::get_instance();
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
$params = array(
|
||||
'user_accounts' => Bridge_Account::get_accounts_by_user($appbox, $user)
|
||||
, 'available_apis' => Bridge_Api::get_availables($appbox)
|
||||
, 'route' => $route
|
||||
);
|
||||
|
||||
return new Response($twig->render('prod/actions/Bridge/index.twig', $params)
|
||||
);
|
||||
});
|
||||
|
||||
$controllers->get('/login/{api_name}/', function($api_name) use ($app, $twig)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$connector = Bridge_Api::get_connector_by_name($appbox->get_registry(), $api_name);
|
||||
|
||||
return $app->redirect($connector->get_auth_url());
|
||||
});
|
||||
|
||||
$controllers->get('/callback/{api_name}/', function($api_name) use ($app, $twig)
|
||||
{
|
||||
$error_message = '';
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$api = Bridge_Api::get_by_api_name($appbox, $api_name);
|
||||
$connector = $api->get_connector();
|
||||
|
||||
$response = $connector->connect();
|
||||
|
||||
$user_id = $connector->get_user_id();
|
||||
|
||||
try
|
||||
{
|
||||
$account = Bridge_Account::load_account_from_distant_id($appbox, $api, $user, $user_id);
|
||||
}
|
||||
catch (Bridge_Exception_AccountNotFound $e)
|
||||
{
|
||||
$account = Bridge_Account::create($appbox, $api, $user, $user_id, $connector->get_user_name());
|
||||
}
|
||||
$settings = $account->get_settings();
|
||||
|
||||
if (isset($response['auth_token']))
|
||||
$settings->set('auth_token', $response['auth_token']);
|
||||
if (isset($response['refresh_token']))
|
||||
$settings->set('refresh_token', $response['refresh_token']);
|
||||
|
||||
$connector->set_auth_settings($settings);
|
||||
|
||||
$connector->reconnect();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
|
||||
$params = array('error_message' => $error_message);
|
||||
|
||||
return new Response($twig->render('prod/actions/Bridge/callback.twig', $params));
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/adapter/{account_id}/logout/'
|
||||
, function($account_id) use ($app, $twig)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $account_id);
|
||||
$app['require_connection']($account);
|
||||
$account->get_api()->get_connector()->disconnect();
|
||||
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-elements/' . $account->get_api()->get_connector()->get_default_element_type() . '/');
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/adapter/{account_id}/load-records/'
|
||||
, function($account_id) use ($app, $twig)
|
||||
{
|
||||
$page = max((int) $app['request']->get('page'), 0);
|
||||
$quantity = 10;
|
||||
$offset_start = max(($page - 1) * $quantity, 0);
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $account_id);
|
||||
$elements = Bridge_Element::get_elements_by_account($appbox, $account, $offset_start, $quantity);
|
||||
|
||||
$app['require_connection']($account);
|
||||
|
||||
$params = array(
|
||||
'adapter_action' => 'load-records'
|
||||
, 'account' => $account
|
||||
, 'elements' => $elements
|
||||
, 'error_message' => $app['request']->get('error')
|
||||
, 'notice_message' => $app['request']->get('notice')
|
||||
);
|
||||
|
||||
$twig->addFilter(array('prettyDate' => 'phraseadate::getPrettyString'));
|
||||
|
||||
return new Response($twig->render('prod/actions/Bridge/records_list.twig', $params));
|
||||
})
|
||||
->assert('account_id', '\d+');
|
||||
|
||||
$controllers->get('/adapter/{account_id}/load-elements/{type}/'
|
||||
, function($account_id, $type) use ($app, $twig)
|
||||
{
|
||||
$page = max((int) $app['request']->get('page'), 0);
|
||||
$quantity = 5;
|
||||
$offset_start = max(($page - 1) * $quantity, 0);
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $account_id);
|
||||
|
||||
$app['require_connection']($account);
|
||||
|
||||
$elements = $account->get_api()->list_elements($type, $offset_start, $quantity);
|
||||
|
||||
$params = array(
|
||||
'action_type' => $type
|
||||
, 'adapter_action' => 'load-elements'
|
||||
, 'account' => $account
|
||||
, 'elements' => $elements
|
||||
, 'error_message' => $app['request']->get('error')
|
||||
, 'notice_message' => $app['request']->get('notice')
|
||||
);
|
||||
|
||||
$twig->addFilter(array('prettyDate' => 'phraseadate::getPrettyString'));
|
||||
|
||||
return new Response($twig->render('prod/actions/Bridge/element_list.twig', $params));
|
||||
})
|
||||
->assert('account_id', '\d+');
|
||||
|
||||
$controllers->get('/adapter/{account_id}/load-containers/{type}/'
|
||||
, function($account_id, $type) use ($app, $twig)
|
||||
{
|
||||
|
||||
$page = max((int) $app['request']->get('page'), 0);
|
||||
$quantity = 5;
|
||||
$offset_start = max(($page - 1) * $quantity, 0);
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $account_id);
|
||||
|
||||
$app['require_connection']($account);
|
||||
$elements = $account->get_api()->list_containers($type, $offset_start, $quantity);
|
||||
|
||||
$params = array(
|
||||
'action_type' => $type
|
||||
, 'adapter_action' => 'load-containers'
|
||||
, 'account' => $account
|
||||
, 'elements' => $elements
|
||||
, 'error_message' => $app['request']->get('error')
|
||||
, 'notice_message' => $app['request']->get('notice')
|
||||
);
|
||||
|
||||
$twig->addFilter(array('prettyDate' => 'phraseadate::getPrettyString'));
|
||||
|
||||
return new Response($twig->render('prod/actions/Bridge/element_list.twig', $params));
|
||||
})
|
||||
->assert('account_id', '\d+');
|
||||
|
||||
|
||||
$controllers->get('/action/{account_id}/{action}/{element_type}/'
|
||||
, function($account_id, $action, $element_type) use ($app, $twig)
|
||||
{
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $account_id);
|
||||
|
||||
$app['require_connection']($account);
|
||||
$request = $app['request'];
|
||||
$elements = $request->get('elements_list', array());
|
||||
$elements = is_array($elements) ? $elements : explode(';', $elements);
|
||||
|
||||
$destination = $request->get('destination');
|
||||
$route_params = array();
|
||||
$class = $account->get_api()->get_connector()->get_object_class_from_type($element_type);
|
||||
|
||||
switch ($action)
|
||||
{
|
||||
case 'createcontainer':
|
||||
break;
|
||||
|
||||
case 'modify':
|
||||
if (count($elements) != 1)
|
||||
{
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-elements/' . $element_type . '/?page=&error=' . _('Vous ne pouvez pas editer plusieurs elements simultanement'));
|
||||
}
|
||||
foreach ($elements as $element_id)
|
||||
{
|
||||
if ($class === Bridge_Api_Interface::OBJECT_CLASS_ELEMENT)
|
||||
{
|
||||
$route_params = array('element' => $account->get_api()->get_element_from_id($element_id, $element_type));
|
||||
}
|
||||
if ($class === Bridge_Api_Interface::OBJECT_CLASS_CONTAINER)
|
||||
{
|
||||
$route_params = array('element' => $account->get_api()->get_container_from_id($element_id, $element_type));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'moveinto':
|
||||
|
||||
$route_params = array('containers' => $account->get_api()->list_containers($destination, 0, 0));
|
||||
break;
|
||||
|
||||
case 'deleteelement':
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception(_('Vous essayez de faire une action que je ne connais pas !'));
|
||||
break;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'account' => $account
|
||||
, 'destination' => $destination
|
||||
, 'element_type' => $element_type
|
||||
, 'action' => $action
|
||||
, 'elements' => $elements
|
||||
, 'error_message' => $app['request']->get('error')
|
||||
, 'notice_message' => $app['request']->get('notice')
|
||||
);
|
||||
|
||||
$params = array_merge($params, $route_params);
|
||||
|
||||
$template = 'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/' . $element_type . '_' . $action . ($destination ? '_' . $destination : '') . '.twig';
|
||||
$html = $twig->render($template, $params);
|
||||
|
||||
return new Response($html);
|
||||
})->assert('account_id', '\d+');
|
||||
|
||||
|
||||
$controllers->post('/action/{account_id}/{action}/{element_type}/'
|
||||
, function($account_id, $action, $element_type) use ($app, $twig)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $account_id);
|
||||
|
||||
$app['require_connection']($account);
|
||||
|
||||
$request = $app['request'];
|
||||
$elements = $request->get('elements_list', array());
|
||||
$elements = is_array($elements) ? $elements : explode(';', $elements);
|
||||
|
||||
$destination = $request->get('destination');
|
||||
|
||||
$class = $account->get_api()->get_connector()->get_object_class_from_type($element_type);
|
||||
$html = '';
|
||||
switch ($action)
|
||||
{
|
||||
case 'modify':
|
||||
if (count($elements) != 1)
|
||||
{
|
||||
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?elements_list=' . implode(';', $elements) . '&error=' . _('Vous ne pouvez pas editer plusieurs elements simultanement'));
|
||||
}
|
||||
try
|
||||
{
|
||||
foreach ($elements as $element_id)
|
||||
{
|
||||
$datas = $account->get_api()->get_connector()->get_update_datas($app['request']);
|
||||
$errors = $account->get_api()->get_connector()->check_update_constraints($datas);
|
||||
}
|
||||
|
||||
if (count($errors) > 0)
|
||||
{
|
||||
$params = array(
|
||||
'element' => $account->get_api()->get_element_from_id($element_id, $element_type)
|
||||
, 'account' => $account
|
||||
, 'destination' => $destination
|
||||
, 'element_type' => $element_type
|
||||
, 'action' => $action
|
||||
, 'elements' => $elements
|
||||
, 'error_message' => _('Request contains invalid datas')
|
||||
, 'constraint_errors' => $errors
|
||||
, 'notice_message' => $app['request']->get('notice')
|
||||
);
|
||||
|
||||
$template = 'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/' . $element_type . '_' . $action . ($destination ? '_' . $destination : '') . '.twig';
|
||||
$html = $twig->render($template, $params);
|
||||
|
||||
return new Response($html);
|
||||
}
|
||||
|
||||
foreach ($elements as $element_id)
|
||||
{
|
||||
$datas = $account->get_api()->get_connector()->get_update_datas($app['request']);
|
||||
$account->get_api()->update_element($element_type, $element_id, $datas);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?elements_list[]=' . $element_id . '&error=' . get_class($e) . ' : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/?page=&update=success#anchor');
|
||||
|
||||
break;
|
||||
case 'createcontainer':
|
||||
|
||||
try
|
||||
{
|
||||
$container_type = $request->get('f_container_type');
|
||||
|
||||
$account->get_api()->create_container($container_type, $app['request']);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . ' : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/?page=&update=success#anchor');
|
||||
|
||||
break;
|
||||
case 'moveinto':
|
||||
try
|
||||
{
|
||||
$container_id = $request->get('container_id');
|
||||
foreach ($elements as $element_id)
|
||||
{
|
||||
$account->get_api()->add_element_to_container($element_type, $element_id, $destination, $container_id);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . ' : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-containers/' . $destination . '/?page=&update=success#anchor');
|
||||
|
||||
break;
|
||||
|
||||
case 'deleteelement':
|
||||
try
|
||||
{
|
||||
foreach ($elements as $element_id)
|
||||
{
|
||||
$account->get_api()->delete_object($element_type, $element_id);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $app->redirect('/prod/bridge/action/' . $account_id . '/' . $action . '/' . $element_type . '/?error=' . get_class($e) . $e->getMessage());
|
||||
}
|
||||
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account_id . '/load-' . $class . 's/' . $element_type . '/');
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Unknown action');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return new Response($html);
|
||||
})->assert('account_id', '\d+');
|
||||
|
||||
|
||||
$controllers->get('/upload/', function() use ($app, $twig)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $request->get('account_id'));
|
||||
$app['require_connection']($account);
|
||||
|
||||
$route = new module_prod_route_records_bridge($request);
|
||||
$route->grep_records($account->get_api()->acceptable_records());
|
||||
|
||||
$params = array(
|
||||
'route' => $route
|
||||
, 'account' => $account
|
||||
, 'error_message' => $app['request']->get('error')
|
||||
, 'notice_message' => $app['request']->get('notice')
|
||||
);
|
||||
|
||||
$html = $twig->render(
|
||||
'prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/upload.twig', $params
|
||||
);
|
||||
|
||||
return new Response($html);
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/upload/'
|
||||
, function() use ($app, $twig)
|
||||
{
|
||||
$errors = array();
|
||||
$request = $app['request'];
|
||||
$appbox = appbox::get_instance();
|
||||
$account = Bridge_Account::load_account($appbox, $request->get('account_id'));
|
||||
$app['require_connection']($account);
|
||||
|
||||
$route = new module_prod_route_records_bridge($request);
|
||||
$route->grep_records($account->get_api()->acceptable_records());
|
||||
$connector = $account->get_api()->get_connector();
|
||||
|
||||
/**
|
||||
* check constraints
|
||||
*/
|
||||
$errors = array();
|
||||
foreach ($route->get_elements() as $record)
|
||||
{
|
||||
$datas = $connector->get_upload_datas($request, $record);
|
||||
$errors = array_merge($errors, $connector->check_upload_constraints($datas, $record));
|
||||
}
|
||||
|
||||
|
||||
if (count($errors) > 0)
|
||||
{
|
||||
|
||||
$params = array(
|
||||
'route' => $route
|
||||
, 'account' => $account
|
||||
, 'error_message' => _('Request contains invalid datas')
|
||||
, 'constraint_errors' => $errors
|
||||
, 'notice_message' => $app['request']->get('notice')
|
||||
);
|
||||
|
||||
$html = $twig->render('prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/upload.twig', $params);
|
||||
|
||||
return new Response($html);
|
||||
//return $app->redirect('/prod/bridge/upload/?lst='.$request->get('lst').'&account_id='.$request->get('account_id').'&errors=' . sprintf(_('%d elements en erreur. %s'), count($errors), $error_msg));
|
||||
}
|
||||
|
||||
foreach ($route->get_elements() as $record)
|
||||
{
|
||||
$datas = $connector->get_upload_datas($request, $record);
|
||||
$title = isset($datas["title"]) ? $datas["title"] : '';
|
||||
$default_type = $connector->get_default_element_type();
|
||||
Bridge_Element::create($appbox, $account, $record, $title, Bridge_Element::STATUS_PENDING, $default_type, $datas);
|
||||
}
|
||||
|
||||
return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . sprintf(_('%d elements en attente'), count($route->get_elements())));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
61
lib/classes/Controller/Prod/Records/Edit.class.php
Normal file
61
lib/classes/Controller/Prod/Records/Edit.class.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Prod_Records_Edit implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$controllers->post('/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$editing = new module_prod_route_records_edit($request);
|
||||
$editing->propose_editing();
|
||||
|
||||
$template = 'prod/actions/edit_default.twig';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('sbas_names' => 'phrasea::sbas_names'));
|
||||
|
||||
return $twig->render($template, array('edit' => $editing, 'message' => ''));
|
||||
}
|
||||
);
|
||||
|
||||
$controllers->post('/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$editing = new module_prod_route_records_edit($request);
|
||||
$editing->execute($request);
|
||||
|
||||
$template = 'prod/actions/edit_default.twig';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('sbas_names' => 'phrasea::sbas_names'));
|
||||
|
||||
return $twig->render($template, array('edit' => $editing, 'message' => ''));
|
||||
}
|
||||
);
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
334
lib/classes/Controller/Prod/Records/Feed.class.php
Normal file
334
lib/classes/Controller/Prod/Records/Feed.class.php
Normal file
@@ -0,0 +1,334 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class Controller_Prod_Records_Feed implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
$twig = new supertwig();
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
/**
|
||||
* I got a selection of docs, which publications are available forthese docs ?
|
||||
*/
|
||||
$controllers->post('/requestavailable/', function() use ($app, $appbox, $twig)
|
||||
{
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$feeds = Feed_Collection::load_all($appbox, $user);
|
||||
$request = $app['request'];
|
||||
$publishing = new module_prod_route_records_feed($request);
|
||||
|
||||
$datas = $twig->render('prod/actions/publish/publish.html', array('publishing' => $publishing, 'feeds' => $feeds));
|
||||
|
||||
return new Response($datas);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* I've selected a publication for my ocs, let's publish them
|
||||
*/
|
||||
$controllers->post('/entry/create/', function() use ($app, $appbox, $twig)
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = $app['request'];
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$feed = new Feed_Adapter($appbox, $request->get('feed_id'));
|
||||
$publisher = Feed_Publisher_Adapter::getPublisher($appbox, $feed, $user);
|
||||
|
||||
$title = $request->get('title');
|
||||
$subtitle = $request->get('subtitle');
|
||||
$author_name = $request->get('author_name');
|
||||
$author_mail = $request->get('author_mail');
|
||||
|
||||
$entry = Feed_Entry_Adapter::create($appbox, $feed, $publisher, $title, $subtitle, $author_name, $author_mail);
|
||||
$publishing = new module_prod_route_records_feed($request);
|
||||
|
||||
foreach ($publishing->get_elements() as $record)
|
||||
{
|
||||
$item = Feed_Entry_Item::create($appbox, $entry, $record);
|
||||
}
|
||||
$datas = array('error' => false, 'message' => false);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$datas = array('error' => true, 'message' => _('An error occured'), 'details' => $e->getMessage());
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode($datas), 200, array('Content-Type' => 'application/json'));
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/entry/{id}/edit/', function($id) use ($app, $appbox, $twig)
|
||||
{
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
$entry = Feed_Entry_Adapter::load_from_id($appbox, $id);
|
||||
|
||||
if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id())
|
||||
{
|
||||
throw new Exception_UnauthorizedAction();
|
||||
}
|
||||
$feeds = Feed_Collection::load_all($appbox, $user);
|
||||
|
||||
|
||||
$datas = $twig->render('prod/actions/publish/publish_edit.html', array('entry' => $entry, 'feeds' => $feeds));
|
||||
|
||||
return new Response($datas);
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/entry/{id}/update/', function($id) use ($app, $appbox, $twig)
|
||||
{
|
||||
$datas = array('error' => true, 'message' => '', 'datas' => '');
|
||||
try
|
||||
{
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
$request = $app['request'];
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
$entry = Feed_Entry_Adapter::load_from_id($appbox, $id);
|
||||
|
||||
if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id())
|
||||
{
|
||||
throw new Exception_UnauthorizedAction();
|
||||
}
|
||||
|
||||
$title = $request->get('title');
|
||||
$subtitle = $request->get('subtitle');
|
||||
$author_name = $request->get('author_name');
|
||||
$author_mail = $request->get('author_mail');
|
||||
|
||||
$entry->set_author_email($author_mail)
|
||||
->set_author_name($author_name)
|
||||
->set_title($title)
|
||||
->set_subtitle($subtitle);
|
||||
|
||||
$items = explode(';', $request->get('sorted_lst'));
|
||||
foreach ($items as $item_sort)
|
||||
{
|
||||
$item_sort_datas = explode('_', $item_sort);
|
||||
if (count($item_sort_datas) != 2)
|
||||
continue;
|
||||
|
||||
$item = new Feed_Entry_Item($appbox, $entry, $item_sort_datas[0]);
|
||||
$item->set_ord($item_sort_datas[1]);
|
||||
}
|
||||
$appbox->get_connection()->commit();
|
||||
|
||||
$twig->addFilter(
|
||||
array(
|
||||
'sbasFromBas' => 'phrasea::sbasFromBas'
|
||||
, 'getPrettyDate' => 'phraseadate::getPrettyString'
|
||||
, 'nl2br' => 'nl2br'
|
||||
)
|
||||
);
|
||||
$entry = $twig->render('prod/feeds/entry.html', array('entry' => $entry));
|
||||
|
||||
$datas = array('error' => false, 'message' => 'succes', 'datas' => $entry);
|
||||
}
|
||||
catch (Exception_Feed_EntryNotFound $e)
|
||||
{
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = _('Feed entry not found');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode($datas), 200, array('Content-Type' => 'application/json'));
|
||||
});
|
||||
|
||||
|
||||
$controllers->post('/entry/{id}/delete/', function($id) use ($app, $appbox, $twig)
|
||||
{
|
||||
$datas = array('error' => true, 'message' => '');
|
||||
try
|
||||
{
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
$request = $app['request'];
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
$entry = Feed_Entry_Adapter::load_from_id($appbox, $id);
|
||||
|
||||
if ($entry->get_publisher()->get_user()->get_id() !== $user->get_id()
|
||||
&& $entry->get_feed()->is_owner($user) === false)
|
||||
{
|
||||
throw new Exception_UnauthorizedAction(_('Action Forbidden : You are not the publisher'));
|
||||
}
|
||||
|
||||
$entry->delete();
|
||||
|
||||
$appbox->get_connection()->commit();
|
||||
$datas = array('error' => false, 'message' => 'succes');
|
||||
}
|
||||
catch (Exception_Feed_EntryNotFound $e)
|
||||
{
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = _('Feed entry not found');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$appbox->get_connection()->rollBack();
|
||||
$datas['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode($datas), 200, array('Content-Type' => 'application/json'));
|
||||
});
|
||||
|
||||
//$app->post('/entry/{id}/addelement/', function($id) use ($app, $appbox, $twig)
|
||||
// {
|
||||
//
|
||||
// });
|
||||
//
|
||||
//$app->post('/element/{id}/update/', function($id) use ($app, $appbox, $twig)
|
||||
// {
|
||||
//
|
||||
// });
|
||||
//
|
||||
//$app->post('/element/{id}/delete/', function($id) use ($app, $appbox, $twig)
|
||||
// {
|
||||
//
|
||||
// });
|
||||
//$app->get('/entry/{id}/', function($id) use ($app, $appbox, $twig)
|
||||
// {
|
||||
//
|
||||
// });
|
||||
|
||||
$controllers->get('/', function() use ($app, $appbox, $twig)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$page = (int) $request->get('page');
|
||||
$page = $page > 0 ? $page : 1;
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$feeds = Feed_Collection::load_all($appbox, $user);
|
||||
|
||||
|
||||
$twig->addFilter(
|
||||
array(
|
||||
'sbasFromBas' => 'phrasea::sbasFromBas'
|
||||
, 'getPrettyDate' => 'phraseadate::getPrettyString'
|
||||
, 'nl2br' => 'nl2br'
|
||||
)
|
||||
);
|
||||
$datas = $twig->render('prod/feeds/feeds.html'
|
||||
, array(
|
||||
'feeds' => $feeds
|
||||
, 'feed' => $feeds->get_aggregate()
|
||||
, 'page' => $page
|
||||
)
|
||||
);
|
||||
|
||||
return new Response($datas);
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/feed/{id}/', function($id) use ($app, $appbox, $twig)
|
||||
{
|
||||
|
||||
$request = $app['request'];
|
||||
$page = (int) $request->get('page');
|
||||
$page = $page > 0 ? $page : 1;
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
|
||||
$feed = Feed_Adapter::load_with_user($appbox, $user, $id);
|
||||
$feeds = Feed_Collection::load_all($appbox, $user);
|
||||
|
||||
$twig->addFilter(
|
||||
array(
|
||||
'sbasFromBas' => 'phrasea::sbasFromBas'
|
||||
, 'getPrettyDate' => 'phraseadate::getPrettyString'
|
||||
, 'nl2br' => 'nl2br'
|
||||
)
|
||||
);
|
||||
$datas = $twig->render('prod/feeds/feeds.html', array('feed' => $feed, 'feeds' => $feeds, 'page' => $page));
|
||||
|
||||
return new Response($datas);
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/subscribe/aggregated/', function() use ($app, $appbox, $twig)
|
||||
{
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$renew = ($request->get('renew') === 'true');
|
||||
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$feeds = Feed_Collection::load_all($appbox, $user);
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
|
||||
$output = p4string::jsonencode(
|
||||
array(
|
||||
'texte' => '<p>' . _('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.')
|
||||
. '</p><p>' . _('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
|
||||
<div><input type="text" readonly="readonly" class="input_select_copy" value="' . $feeds->get_aggregate()->get_user_link($registry, $user, Feed_Adapter::FORMAT_RSS, null, $renew)->get_href() . '"/></div>',
|
||||
'titre' => _('publications::votre rss personnel')
|
||||
)
|
||||
);
|
||||
|
||||
return new Response($output, 200, array('Content-Type' => 'application/json'));
|
||||
});
|
||||
|
||||
|
||||
$controllers->get('/subscribe/{id}/', function($id) use ($app, $appbox, $twig)
|
||||
{
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$renew = ($request->get('renew') === 'true');
|
||||
$user = User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||
$feed = Feed_Adapter::load_with_user($appbox, $user, $id);
|
||||
$registry = $appbox->get_registry();
|
||||
|
||||
$output = p4string::jsonencode(
|
||||
array(
|
||||
'texte' => '<p>' . _('publication::Voici votre fil RSS personnel. Il vous permettra d\'etre tenu au courrant des publications.')
|
||||
. '</p><p>' . _('publications::Ne le partagez pas, il est strictement confidentiel') . '</p>
|
||||
<div><input type="text" style="width:100%" value="' . $feed->get_user_link($registry, $user, Feed_Adapter::FORMAT_RSS, null, $renew)->get_href() . '"/></div>',
|
||||
'titre' => _('publications::votre rss personnel')
|
||||
)
|
||||
);
|
||||
|
||||
return new Response($output, 200, array('Content-Type' => 'application/json'));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
60
lib/classes/Controller/Prod/Records/MoveCollection.class.php
Normal file
60
lib/classes/Controller/Prod/Records/MoveCollection.class.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Prod_Records_MoveCollection implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$controllers->post('/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$move = new module_prod_route_records_move($request);
|
||||
$move->propose();
|
||||
|
||||
$template = 'prod/actions/collection_default.twig';
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_names' => 'phrasea::bas_names'));
|
||||
|
||||
return $twig->render($template, array('action' => $move, 'message' => ''));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
$controllers->post('/apply/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$move = new module_prod_route_records_move($request);
|
||||
$move->execute($request);
|
||||
$template = 'prod/actions/collection_submit.twig';
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('bas_names' => 'phrasea::bas_names'));
|
||||
|
||||
return $twig->render($template, array('action' => $move, 'message' => ''));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
177
lib/classes/Controller/Prod/Records/Tooltip.class.php
Normal file
177
lib/classes/Controller/Prod/Records/Tooltip.class.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class Controller_Prod_Records_Tooltip implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
$app['appbox'] = appbox::get_instance();
|
||||
$twig = new supertwig();
|
||||
|
||||
$controllers->post('/basket/{ssel_id}/'
|
||||
, function($ssel_id) use ($app)
|
||||
{
|
||||
$bask = basket_adapter::getInstance($app['appbox'], $ssel_id, $app['appbox']->get_session()->get_usr_id());
|
||||
$isReg = false;
|
||||
|
||||
return new Response('<div style="margin:5px;width:280px;"><div><span style="font-weight:bold;font-size:14px;">' .
|
||||
$bask->get_name() . '</span> </div>' .
|
||||
($isReg ? ('<div style="text-align:right;">' . _('phraseanet::collection') . ' ' . phrasea::bas_names($bask->get_base_id()) . '</div>') : '')
|
||||
. '<div style="margin:5px 0">' . nl2br($bask->get_description()) . '</div>' .
|
||||
'<div style="margin:5px 0;text-align:right;font-style:italic;">' . sprintf(_('paniers: %d elements'), count($bask->get_elements())) .
|
||||
' - ' . phraseadate::getPrettyString($bask->get_update_date()) . '</div><hr/>
|
||||
<div style="position:relative;float:left;width:270px;">' . $bask->get_excerpt() . '</div>');
|
||||
})->assert('ssel_id', '\d+');
|
||||
|
||||
|
||||
$controllers->post('/preview/{sbas_id}/{record_id}/'
|
||||
, function($sbas_id, $record_id) use ($app)
|
||||
{
|
||||
$record = new record_adapter($sbas_id, $record_id);
|
||||
|
||||
$twig = new supertwig();
|
||||
|
||||
return new Response($twig->render(
|
||||
'common/preview.html'
|
||||
, array(
|
||||
'record' => $record
|
||||
, 'not_wrapped' => true
|
||||
)
|
||||
)
|
||||
);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
|
||||
$controllers->post('/caption/{sbas_id}/{record_id}/{view}/'
|
||||
, function($sbas_id, $record_id, $view) use ($app)
|
||||
{
|
||||
$number = (int) $app['request']->get('number');
|
||||
$record = new record_adapter($sbas_id, $record_id, $number);
|
||||
|
||||
$search_engine = null;
|
||||
if (($search_engine_options = unserialize($app['request']->get('options_serial'))) !== false)
|
||||
{
|
||||
$search_engine = new searchEngine_adapter($app['appbox']->get_registry());
|
||||
$search_engine->set_options($search_engine_options);
|
||||
}
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('formatoctet' => 'p4string::format_octets'));
|
||||
|
||||
return new Response(
|
||||
$twig->render(
|
||||
'common/caption.html'
|
||||
, array(
|
||||
'record' => $record
|
||||
, 'view' => $view
|
||||
, 'highlight' => $app['request']->get('query')
|
||||
, 'searchEngine' => $search_engine
|
||||
)
|
||||
)
|
||||
);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
|
||||
$controllers->post('/tc_datas/{sbas_id}/{record_id}/'
|
||||
, function($sbas_id, $record_id) use ($app)
|
||||
{
|
||||
$record = new record_adapter($sbas_id, $record_id);
|
||||
$document = $record->get_subdef('document');
|
||||
|
||||
$twig = new supertwig();
|
||||
$twig->addFilter(array('formatoctet' => 'p4string::format_octets'));
|
||||
|
||||
return new Response(
|
||||
$twig->render(
|
||||
'common/technical_datas.twig'
|
||||
, array('record' => $record, 'document' => $document)
|
||||
)
|
||||
);
|
||||
})->assert('sbas_id', '\d+')->assert('record_id', '\d+');
|
||||
|
||||
|
||||
$controllers->post('/metas/FieldInfos/{sbas_id}/{field_id}/'
|
||||
, function($sbas_id, $field_id) use ($app)
|
||||
{
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
$field = databox_field::get_instance($databox, $field_id);
|
||||
|
||||
$twig = new supertwig();
|
||||
|
||||
return new Response(
|
||||
$twig->render(
|
||||
'common/databox_field.twig'
|
||||
, array('field' => $field)
|
||||
)
|
||||
);
|
||||
})->assert('sbas_id', '\d+')->assert('field_id', '\d+');
|
||||
|
||||
|
||||
$controllers->post('/metas/DCESInfos/{sbas_id}/{field_id}/'
|
||||
, function($sbas_id, $field_id) use ($app)
|
||||
{
|
||||
try
|
||||
{
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
$field = databox_field::get_instance($databox, $field_id);
|
||||
|
||||
$twig = new supertwig();
|
||||
|
||||
return new Response(
|
||||
$twig->render(
|
||||
'common/databox_field_DCES.twig'
|
||||
, array('field' => $field)
|
||||
)
|
||||
);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
exit($e->getMessage());
|
||||
}
|
||||
})->assert('sbas_id', '\d+')->assert('field_id', '\d+');
|
||||
|
||||
|
||||
$controllers->post('/metas/restrictionsInfos/{sbas_id}/{field_id}/'
|
||||
, function($sbas_id, $field_id) use ($app)
|
||||
{
|
||||
$databox = databox::get_instance((int) $sbas_id);
|
||||
$field = databox_field::get_instance($databox, $field_id);
|
||||
|
||||
$twig = new supertwig();
|
||||
|
||||
return new Response(
|
||||
$twig->render(
|
||||
'common/databox_field_restrictions.twig'
|
||||
, array('field' => $field)
|
||||
)
|
||||
);
|
||||
})->assert('sbas_id', '\d+')->assert('field_id', '\d+');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
166
lib/classes/Controller/RSSFeeds.class.php
Normal file
166
lib/classes/Controller/RSSFeeds.class.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_RSSFeeds implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$display_feed = function($feed, $format, $page, $user = null)
|
||||
{
|
||||
$total = $feed->get_count_total_entries();
|
||||
$perPage = 5;
|
||||
$entries = $feed->get_entries((($page - 1) * $perPage), $perPage);
|
||||
|
||||
$registry = registry::get_instance();
|
||||
|
||||
if ($format == 'rss')
|
||||
{
|
||||
$content = new Feed_XML_RSS();
|
||||
}
|
||||
if ($format == 'atom')
|
||||
{
|
||||
$content = new Feed_XML_Atom();
|
||||
}
|
||||
|
||||
if ($user instanceof User_Adapter)
|
||||
$link = $feed->get_user_link($registry, $user, $format, $page);
|
||||
else
|
||||
$link = $feed->get_homepage_link($registry, $format, $page);
|
||||
|
||||
$content->set_updated_on(new DateTime());
|
||||
$content->set_title($feed->get_title());
|
||||
$content->set_subtitle($feed->get_subtitle());
|
||||
$content->set_generator('Phraseanet');
|
||||
$content->set_link($link);
|
||||
|
||||
if ($user instanceof User_Adapter)
|
||||
{
|
||||
if ($page > 1)
|
||||
$content->set_previous_page($feed->get_user_link($registry, $user, $format, ($page - 1)));
|
||||
if ($total > ($page * $perPage))
|
||||
$content->set_next_page($feed->get_user_link($registry, $user, $format, ($page + 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($page > 1)
|
||||
$content->set_previous_page($feed->get_homepage_link($registry, $format, ($page - 1)));
|
||||
if ($total > ($page * $perPage))
|
||||
$content->set_next_page($feed->get_homepage_link($registry, $format, ($page + 1)));
|
||||
}
|
||||
foreach ($entries->get_entries() as $entry)
|
||||
$content->set_item($entry);
|
||||
|
||||
$render = $content->render();
|
||||
$response = new Response($render, 200, array('Content-Type' => $content->get_mimetype()));
|
||||
$response->setCharset('UTF-8');
|
||||
|
||||
return $response;
|
||||
};
|
||||
|
||||
|
||||
|
||||
$controllers->get('/feed/{id}/{format}/', function($id, $format) use ($app, $appbox, $display_feed)
|
||||
{
|
||||
$feed = new Feed_Adapter($appbox, $id);
|
||||
|
||||
if (!$feed->is_public())
|
||||
{
|
||||
return new Response('Forbidden', 403);
|
||||
}
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$page = (int) $request->get('page');
|
||||
$page = $page < 1 ? 1 : $page;
|
||||
|
||||
return $display_feed($feed, $format, $page);
|
||||
})->assert('id', '\d+')->assert('format', '(rss|atom)');
|
||||
|
||||
|
||||
|
||||
$controllers->get('/userfeed/{token}/{id}/{format}/', function($token, $id, $format) use ($app, $appbox, $display_feed)
|
||||
{
|
||||
try
|
||||
{
|
||||
$token = new Feed_Token($appbox, $token, $id);
|
||||
$feed = $token->get_feed();
|
||||
}
|
||||
catch (Exception_FeedNotFound $e)
|
||||
{
|
||||
return new Response('Not Found', 404);
|
||||
}
|
||||
$request = $app['request'];
|
||||
|
||||
$page = (int) $request->get('page');
|
||||
$page = $page < 1 ? 1 : $page;
|
||||
|
||||
return $display_feed($feed, $format, $page, $token->get_user());
|
||||
})->assert('id', '\d+')->assert('format', '(rss|atom)');
|
||||
|
||||
|
||||
|
||||
$controllers->get('/userfeed/aggregated/{token}/{format}/', function($token, $format) use ($app, $appbox, $display_feed)
|
||||
{
|
||||
try
|
||||
{
|
||||
$token = new Feed_TokenAggregate($appbox, $token);
|
||||
$feed = $token->get_feed();
|
||||
}
|
||||
catch (Exception_FeedNotFound $e)
|
||||
{
|
||||
return new Response('', 404);
|
||||
}
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$page = (int) $request->get('page');
|
||||
$page = $page < 1 ? 1 : $page;
|
||||
|
||||
return $display_feed($feed, $format, $page, $token->get_user());
|
||||
})->assert('id', '\d+')->assert('format', '(rss|atom)');
|
||||
|
||||
|
||||
|
||||
$controllers->get('/aggregated/{format}/', function($format) use ($app, $appbox, $display_feed)
|
||||
{
|
||||
$feeds = Feed_Collection::load_public_feeds($appbox);
|
||||
$feed = $feeds->get_aggregate();
|
||||
|
||||
$request = $app['request'];
|
||||
$page = (int) $request->get('page');
|
||||
$page = $page < 1 ? 1 : $page;
|
||||
|
||||
return $display_feed($feed, $format, $page);
|
||||
})->assert('format', '(rss|atom)');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
306
lib/classes/Controller/Setup/Installer.class.php
Normal file
306
lib/classes/Controller/Setup/Installer.class.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
require_once dirname(__FILE__) . '/../../../version.inc';
|
||||
require_once dirname(__FILE__) . '/../../phrasea.class.php';
|
||||
require_once dirname(__FILE__) . '/../../bootstrap.class.php';
|
||||
require_once dirname(__FILE__) . '/../../cache/cacheableInterface.class.php';
|
||||
require_once dirname(__FILE__) . '/../../cache/interface.class.php';
|
||||
require_once dirname(__FILE__) . '/../../cache/nocache.class.php';
|
||||
require_once dirname(__FILE__) . '/../../cache/adapter.class.php';
|
||||
require_once dirname(__FILE__) . '/../../User/Interface.class.php';
|
||||
require_once dirname(__FILE__) . '/../../User/Adapter.class.php';
|
||||
|
||||
bootstrap::register_autoloads();
|
||||
bootstrap::set_php_configuration();
|
||||
|
||||
class Controller_Setup_Installer implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$app['available_languages'] = User_Adapter::detectLanguage(new Setup_Registry());
|
||||
|
||||
$controllers->get('/', function() use ($app)
|
||||
{
|
||||
$request = $app['request'];
|
||||
$servername = $request->getScheme() . '://' . $request->getHttpHost() . '/';
|
||||
setup::write_config($servername);
|
||||
|
||||
|
||||
$php_constraint = setup::check_php_version();
|
||||
$writability_constraints = setup::check_writability(new Setup_Registry());
|
||||
$extension_constraints = setup::check_php_extension();
|
||||
$opcode_constraints = setup::check_cache_opcode();
|
||||
$php_conf_constraints = setup::check_php_configuration();
|
||||
$locales_constraints = setup::check_system_locales();
|
||||
|
||||
$constraints_coll = array(
|
||||
'php_constraint' => $php_constraint
|
||||
, 'writability_constraints' => $writability_constraints
|
||||
, 'extension_constraints' => $extension_constraints
|
||||
, 'opcode_constraints' => $opcode_constraints
|
||||
, 'php_conf_constraints' => $php_conf_constraints
|
||||
, 'locales_constraints' => $locales_constraints
|
||||
);
|
||||
$redirect = true;
|
||||
|
||||
foreach ($constraints_coll as $key => $constraints)
|
||||
{
|
||||
$unset = true;
|
||||
foreach ($constraints as $constraint)
|
||||
{
|
||||
if (!$constraint->is_ok() && $constraint->is_blocker())
|
||||
$redirect = $unset = false;
|
||||
}
|
||||
if ($unset === true)
|
||||
{
|
||||
unset($constraints_coll[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($redirect)
|
||||
{
|
||||
return $app->redirect('/setup/installer/step2/');
|
||||
}
|
||||
|
||||
|
||||
$ld_path = array(dirname(__FILE__) . '/../../../../templates/web');
|
||||
$loader = new Twig_Loader_Filesystem($ld_path);
|
||||
$twig = new Twig_Environment($loader);
|
||||
|
||||
$html = $twig->render(
|
||||
'/setup/index.twig'
|
||||
, array_merge($constraints_coll, array(
|
||||
'locale' => Session_Handler::get_locale()
|
||||
, 'available_locales' => $app['available_languages']
|
||||
, 'version_number' => GV_version
|
||||
, 'version_name' => GV_version_name
|
||||
, 'current_servername' => $request->getScheme() . '://' . $request->getHttpHost() . '/'
|
||||
))
|
||||
);
|
||||
|
||||
return new Response($html);
|
||||
});
|
||||
|
||||
$controllers->get('/step2/', function() use ($app)
|
||||
{
|
||||
phrasea::use_i18n(Session_Handler::get_locale());
|
||||
|
||||
$ld_path = array(dirname(__FILE__) . '/../../../../templates/web');
|
||||
|
||||
$loader = new Twig_Loader_Filesystem($ld_path);
|
||||
$twig = new Twig_Environment($loader);
|
||||
|
||||
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
||||
|
||||
$request = $app['request'];
|
||||
|
||||
$warnings = array();
|
||||
if ($request->getScheme() == 'http')
|
||||
{
|
||||
$warnings[] = _('It is not recommended to install Phraseanet without HTTPS support');
|
||||
}
|
||||
$html = $twig->render(
|
||||
'/setup/step2.twig'
|
||||
, array(
|
||||
'locale' => Session_Handler::get_locale()
|
||||
, 'available_locales' => $app['available_languages']
|
||||
, 'available_templates' => appbox::list_databox_templates()
|
||||
, 'version_number' => GV_version
|
||||
, 'version_name' => GV_version_name
|
||||
, 'warnings' => $warnings
|
||||
, 'current_servername' => $request->getScheme() . '://' . $request->getHttpHost() . '/'
|
||||
, 'discovered_binaries' => setup::discover_binaries()
|
||||
, 'rootpath' => dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/'
|
||||
)
|
||||
);
|
||||
|
||||
return new Response($html);
|
||||
});
|
||||
|
||||
$controllers->post('/install/', function() use ($app)
|
||||
{
|
||||
set_time_limit(360);
|
||||
phrasea::use_i18n(Session_Handler::get_locale());
|
||||
$request = $app['request'];
|
||||
|
||||
$conn = $connbas = null;
|
||||
|
||||
$hostname = $request->get('ab_hostname');
|
||||
$port = $request->get('ab_port');
|
||||
$user_ab = $request->get('ab_user');
|
||||
$password = $request->get('ab_password');
|
||||
|
||||
$appbox_name = $request->get('ab_name');
|
||||
$databox_name = $request->get('db_name');
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new connection_pdo('appbox', $hostname, $port, $user_ab, $password, $appbox_name);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $app->redirect('/setup/installer/step2/?error=' . _('Appbox is unreachable'));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ($databox_name)
|
||||
{
|
||||
$connbas = new connection_pdo('databox', $hostname, $port, $user_ab, $password, $databox_name);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return $app->redirect('/setup/installer/step2/?error=' . _('Databox is unreachable'));
|
||||
}
|
||||
setup::rollback($conn, $connbas);
|
||||
|
||||
try
|
||||
{
|
||||
$appbox = appbox::create(new Setup_Registry(), $conn, $appbox_name, true);
|
||||
|
||||
|
||||
$registry = registry::get_instance();
|
||||
setup::create_global_values($registry);
|
||||
|
||||
$appbox->set_registry($registry);
|
||||
|
||||
$registry->set('GV_base_datapath_noweb', p4string::addEndSlash($request->get('datapath_noweb')));
|
||||
$registry->set('GV_base_datapath_web', p4string::addEndSlash($request->get('datapath_web')));
|
||||
$registry->set('GV_base_dataurl', p4string::addEndSlash($request->get('mount_point_web')));
|
||||
|
||||
$registry->set('GV_cli', $request->get('binary_php'));
|
||||
$registry->set('GV_imagick', $request->get('binary_convert'));
|
||||
$registry->set('GV_pathcomposite', $request->get('binary_composite'));
|
||||
$registry->set('GV_exiftool', $request->get('binary_exiftool'));
|
||||
$registry->set('GV_swf_extract', $request->get('binary_swfextract'));
|
||||
$registry->set('GV_pdf2swf', $request->get('binary_pdf2swf'));
|
||||
$registry->set('GV_swf_render', $request->get('binary_swfrender'));
|
||||
$registry->set('GV_unoconv', $request->get('binary_unoconv'));
|
||||
$registry->set('GV_ffmpeg', $request->get('binary_ffmpeg'));
|
||||
$registry->set('GV_mp4box', $request->get('binary_MP4Box'));
|
||||
$registry->set('GV_mplayer', $request->get('binary_mplayer'));
|
||||
$registry->set('GV_pdftotext', $request->get('binary_xpdf'));
|
||||
|
||||
$user = User_Adapter::create($appbox, $request->get('email'), $request->get('password'), $request->get('email'), true);
|
||||
|
||||
if (!p4string::hasAccent($databox_name))
|
||||
{
|
||||
if ($databox_name)
|
||||
{
|
||||
|
||||
$template = new system_file(dirname(__FILE__) . '/../../../conf.d/data_templates/' . $request->get('db_template') . '.xml');
|
||||
$databox = databox::create($appbox, $connbas, $template, $registry);
|
||||
$user->ACL()
|
||||
->give_access_to_sbas(array($databox->get_sbas_id()))
|
||||
->update_rights_to_sbas(
|
||||
$databox->get_sbas_id(), array(
|
||||
'bas_manage' => 1, 'bas_modify_struct' => 1,
|
||||
'bas_modif_th' => 1, 'bas_chupub' => 1
|
||||
)
|
||||
);
|
||||
|
||||
$a = collection::create($databox, $appbox, 'test', $user);
|
||||
|
||||
$user->ACL()->give_access_to_base(array($a->get_base_id()));
|
||||
$user->ACL()->update_rights_to_base($a->get_base_id(), array(
|
||||
'canpush' => 1, 'cancmd' => 1
|
||||
, 'canputinalbum' => 1, 'candwnldhd' => 1, 'candwnldpreview' => 1, 'canadmin' => 1
|
||||
, 'actif' => 1, 'canreport' => 1, 'canaddrecord' => 1, 'canmodifrecord' => 1
|
||||
, 'candeleterecord' => 1, 'chgstatus' => 1, 'imgtools' => 1, 'manage' => 1
|
||||
, 'modify_struct' => 1, 'nowatermark' => 1
|
||||
)
|
||||
);
|
||||
|
||||
$tasks = $request->get('create_task', array());
|
||||
foreach ($tasks as $task)
|
||||
{
|
||||
switch ($task)
|
||||
{
|
||||
case 'cindexer';
|
||||
case 'subdef';
|
||||
case 'writemeta';
|
||||
$class_name = sprintf('task_period_%s', $task);
|
||||
if ($task === 'cindexer')
|
||||
{
|
||||
$credentials = $databox->get_connection()->get_credentials();
|
||||
|
||||
$host = $credentials['hostname'];
|
||||
$port = $credentials['port'];
|
||||
$user_ab = $credentials['user'];
|
||||
$password = $credentials['password'];
|
||||
|
||||
$settings = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<tasksettings>\n<binpath>"
|
||||
. str_replace('/phraseanet_indexer', '', $request->get('binary_phraseanet_indexer'))
|
||||
. "</binpath><host>" . $host . "</host><port>"
|
||||
. $port . "</port><base>"
|
||||
. $appbox_name . "</base><user>"
|
||||
. $user_ab . "</user><password>"
|
||||
. $password . "</password><socket>25200</socket>"
|
||||
. "<use_sbas>1</use_sbas><nolog>0</nolog><clng></clng>"
|
||||
. "<winsvc_run>0</winsvc_run><charset>utf8</charset></tasksettings>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$settings = null;
|
||||
}
|
||||
|
||||
task_abstract::create($appbox, $class_name, $settings);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
phrasea::start();
|
||||
|
||||
$auth = new Session_Authentication_None($user);
|
||||
|
||||
$appbox->get_session()->authenticate($auth);
|
||||
|
||||
$redirection = '/admin/?section=taskmanager¬ice=install_success';
|
||||
|
||||
return $app->redirect($redirection);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
setup::rollback($conn, $connbas);
|
||||
exit($e->getMessage() . ' ' . $e->getFile() . ' ' . $e->getLine());
|
||||
}
|
||||
|
||||
return $app->redirect('/setup/installer/step2/?error=' . sprintf(_('an error occured : %s'), $e->getMessage()));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
88
lib/classes/Controller/Setup/Upgrader.class.php
Normal file
88
lib/classes/Controller/Setup/Upgrader.class.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Setup_Upgrader implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$app['registry'] = new Setup_Registry();
|
||||
$app['available_languages'] = User_Adapter::detectLanguage($app['registry']);
|
||||
$app['twig'] = function()
|
||||
{
|
||||
return new supertwig();
|
||||
};
|
||||
|
||||
$controllers->get('/', function() use ($app)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../../bootstrap.php';
|
||||
$upgrade_status = Setup_Upgrade::get_status();
|
||||
|
||||
ini_set('display_errors', 'on');
|
||||
$html = $app['twig']->render(
|
||||
'/setup/upgrader.twig'
|
||||
, array(
|
||||
'locale' => Session_Handler::get_locale()
|
||||
, 'upgrade_status' => $upgrade_status
|
||||
, 'available_locales' => $app['available_languages']
|
||||
, 'version_number' => GV_version
|
||||
, 'version_name' => GV_version_name)
|
||||
);
|
||||
ini_set('display_errors', 'on');
|
||||
|
||||
return new Response($html);
|
||||
});
|
||||
|
||||
$controllers->get('/status/', function() use ($app)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../../bootstrap.php';
|
||||
ini_set('display_errors', 'on');
|
||||
|
||||
$datas = Setup_Upgrade::get_status();
|
||||
|
||||
return new Response(p4string::jsonencode($datas), 200, array('Content-Type: application/json'));
|
||||
});
|
||||
|
||||
$controllers->post('/execute/', function() use ($app)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../../bootstrap.php';
|
||||
ini_set('display_errors', 'on');
|
||||
set_time_limit(0);
|
||||
session_write_close();
|
||||
ignore_user_abort(true);
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
$upgrader = new Setup_Upgrade($appbox);
|
||||
$appbox->forceUpgrade($upgrader);
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
103
lib/classes/Controller/Utils/ConnectionTest.class.php
Normal file
103
lib/classes/Controller/Utils/ConnectionTest.class.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Utils_ConnectionTest implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$controllers->get('/mysql/', function() use ($app)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/../../connection/pdo.class.php';
|
||||
|
||||
$request = $app['request'];
|
||||
$hostname = $request->get('hostname', '127.0.0.1');
|
||||
$port = (int) $request->get('port', 3306);
|
||||
$user = $request->get('user');
|
||||
$password = $request->get('password');
|
||||
$dbname = $request->get('dbname');
|
||||
|
||||
$connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false;
|
||||
|
||||
try
|
||||
{
|
||||
$conn = new connection_pdo('test', $hostname, $port, $user, $password);
|
||||
$connection_ok = true;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if ($dbname && $connection_ok === true)
|
||||
{
|
||||
try
|
||||
{
|
||||
$conn = new connection_pdo('test', $hostname, $port, $user, $password, $dbname);
|
||||
$db_ok = true;
|
||||
|
||||
$sql = "SHOW TABLE STATUS";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
$empty = $stmt->rowCount() === 0;
|
||||
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row)
|
||||
{
|
||||
if ($row["Name"] === 'sitepreff')
|
||||
{
|
||||
$is_appbox = true;
|
||||
}
|
||||
if ($row["Name"] === 'pref')
|
||||
{
|
||||
$is_databox = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return new Response(p4string::jsonencode(array(
|
||||
'connection' => $connection_ok
|
||||
, 'database' => $db_ok
|
||||
, 'is_empty' => $empty
|
||||
, 'is_appbox' => $is_appbox
|
||||
, 'is_databox' => $is_databox
|
||||
)), 200, array('application/json'));
|
||||
});
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
||||
|
60
lib/classes/Controller/Utils/PathFileTest.class.php
Normal file
60
lib/classes/Controller/Utils/PathFileTest.class.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Silex\ControllerCollection;
|
||||
|
||||
class Controller_Utils_PathFileTest implements ControllerProviderInterface
|
||||
{
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$controllers = new ControllerCollection();
|
||||
|
||||
$controllers->get('/path/', function() use ($app)
|
||||
{
|
||||
$path = $app['request']->get('path');
|
||||
|
||||
return new Response(p4string::jsonencode(array(
|
||||
'exists' => file_exists($path)
|
||||
, 'file' => is_file($path)
|
||||
, 'dir' => is_dir($path)
|
||||
, 'readable' => is_readable($path)
|
||||
, 'writeable' => is_writable($path)
|
||||
, 'executable' => is_executable($path)
|
||||
)), 200, array('application/json'));
|
||||
});
|
||||
|
||||
$controllers->get('/url/', function() use ($app)
|
||||
{
|
||||
$url = $app['request']->get('url');
|
||||
|
||||
return new Response(p4string::jsonencode(array(
|
||||
'code' => http_query::getHttpCodeFromUrl($url)
|
||||
)), 200, array('application/json'));
|
||||
});
|
||||
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user