public function testGet_id() { $this->feed_datas(); $log_id = $this->object->get_id(); $this->assertTrue(is_int($log_id)); $sql = 'SELECT id FROM log WHERE sit_session = :ses_id AND usrid = :usr_id AND site = :site'; $params = [':ses_id' => self::$DI['app']['session']->get('session_id'), ':usr_id' => self::$DI['app']['authentication']->getUser()->getId(), ':site' => self::$DI['app']['conf']->get(['main', 'key'])]; $stmt = $this->databox->get_connection()->prepare($sql); $stmt->execute($params); $this->assertEquals(1, $stmt->rowCount()); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals($this->object->get_id(), $row['id']); $log_id = $this->object->get_id(); $ses_id = self::$DI['app']['session']->get('session_id'); $usr_id = self::$DI['app']['authentication']->getUser()->getId(); $this->logout(self::$DI['app']); $sql = 'SELECT id FROM log WHERE sit_session = :ses_id AND usrid = :usr_id AND site = :site'; $params = [':ses_id' => $ses_id, ':usr_id' => $usr_id, ':site' => self::$DI['app']['conf']->get(['main', 'key'])]; $stmt = $this->databox->get_connection()->prepare($sql); $stmt->execute($params); $this->assertEquals(1, $stmt->rowCount()); $row = $stmt->fetch(PDO::FETCH_ASSOC); $this->assertEquals($log_id, $row['id']); }
public function displayTreeAction(Request $request) { try { \Session_Logger::updateClientInfos($this->app, 3); } catch (SessionNotFound $e) { return $this->app->redirectPath('logout'); } $params = $this->getSectionParameters($request->query->get('position', false)); return $this->render('admin/tree.html.twig', $params); }
public function connect(SilexApplication $app) { $app['controller.prod'] = $this; $controllers = $app['controllers_factory']; $controllers->before(function (Request $request) use($app) { if (!$app['authentication']->isAuthenticated() && null !== $request->query->get('nolog')) { return $app->redirectPath('login_authenticate_as_guest'); } if (null !== ($response = $app['firewall']->requireAuthentication())) { return $response; } }); $controllers->get('/', function (Application $app) { try { \Session_Logger::updateClientInfos($app, 1); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $cssPath = $app['root.path'] . '/www/skins/prod/'; $css = []; $cssfile = false; $finder = new Finder(); $iterator = $finder->directories()->depth(0)->filter(function (\SplFileInfo $fileinfo) { return ctype_xdigit($fileinfo->getBasename()); })->in($cssPath); foreach ($iterator as $dir) { $baseName = $dir->getBaseName(); $css[$baseName] = $baseName; } $cssfile = $app['settings']->getUserSetting($app['authentication']->getUser(), 'css'); if (!$cssfile && isset($css['000000'])) { $cssfile = '000000'; } $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser())); $aggregate = Aggregate::createFromUser($app, $app['authentication']->getUser()); $thjslist = ""; $queries_topics = ''; if ($app['conf']->get(['registry', 'classic', 'render-topics']) == 'popups') { $queries_topics = \queries::dropdown_topics($app['translator'], $app['locale']); } elseif ($app['conf']->get(['registry', 'classic', 'render-topics']) == 'tree') { $queries_topics = \queries::tree_topics($app['locale']); } $sbas = $bas2sbas = []; foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) { $sbas_id = $databox->get_sbas_id(); $sbas['s' + $sbas_id] = ['sbid' => $sbas_id, 'seeker' => null]; foreach ($databox->get_collections() as $coll) { $bas2sbas['b' . $coll->get_base_id()] = ['sbid' => $sbas_id, 'ckobj' => ['checked' => false], 'waschecked' => false]; } } return $app['twig']->render('prod/index.html.twig', ['module_name' => 'Production', 'WorkZone' => new Helper\WorkZone($app, $app['request']), 'module_prod' => new Helper\Prod($app, $app['request']), 'cssfile' => $cssfile, 'module' => 'prod', 'events' => $app['events-manager'], 'GV_defaultQuery_type' => $app['conf']->get(['registry', 'searchengine', 'default-query-type']), 'GV_multiAndReport' => $app['conf']->get(['registry', 'modules', 'stories']), 'GV_thesaurus' => $app['conf']->get(['registry', 'modules', 'thesaurus']), 'cgus_agreement' => \databox_cgu::askAgreement($app), 'css' => $css, 'feeds' => $feeds, 'aggregate' => $aggregate, 'GV_google_api' => $app['conf']->get(['registry', 'webservices', 'google-charts-enabled']), 'queries_topics' => $queries_topics, 'search_status' => \databox_status::getSearchStatus($app), 'queries_history' => \queries::history($app, $app['authentication']->getUser()->getId()), 'thesau_js_list' => $thjslist, 'thesau_json_sbas' => json_encode($sbas), 'thesau_json_bas2sbas' => json_encode($bas2sbas), 'thesau_languages' => $app['locales.available']]); })->bind('prod'); return $controllers; }
/** * Display dashboard informations * * @param Application $app * @param Request $request * @return JsonResponse */ public function getDashboard(Application $app, Request $request) { $dashboard = new \module_report_dashboard($app, $app['authentication']->getUser()); if ('json' !== $request->getRequestFormat()) { \Session_Logger::updateClientInfos($app, 4); $dashboard->execute(); return $app['twig']->render('report/report_layout_child.html.twig', ['ajax_dash' => true, 'dashboard' => $dashboard, 'home_title' => $app['conf']->get(['registry', 'general', 'title']), 'module' => 'report', 'module_name' => 'Report', 'anonymous' => $app['conf']->get(['registry', 'modules', 'anonymous-report']), 'g_anal' => $app['conf']->get(['registry', 'general', 'analytics']), 'ajax' => false, 'ajax_chart' => false]); } $dmin = $request->request->get('dmin'); $dmax = $request->request->get('dmax'); if ($dmin && $dmax) { $dashboard->setDate($dmin, $dmax); } $dashboard->execute(); return $app->json(['html' => $app['twig']->render('report/ajax_dashboard_content_child.html.twig', ['dashboard' => $dashboard])]); }
public function register(SilexApplication $app) { $app['phraseanet.appbox'] = $app->share(function (SilexApplication $app) { return new \appbox($app); }); $app['firewall'] = $app->share(function (SilexApplication $app) { return new Firewall($app); }); $app['events-manager'] = $app->share(function (SilexApplication $app) { $events = new \eventsmanager_broker($app); $events->start(); return $events; }); $app['phraseanet.thumb-symlinker'] = $app->share(function (SilexApplication $app) { return SymLinker::create($app); }); $app['phraseanet.thumb-symlinker-encoder'] = $app->share(function (SilexApplication $app) { return SymLinkerEncoder::create($app); }); $app['acl'] = $app->share(function (SilexApplication $app) { return new ACLProvider($app); }); $app['phraseanet.metadata-reader'] = $app->share(function (SilexApplication $app) { $reader = new PhraseanetMetadataReader(); try { $reader->setPdfToText($app['xpdf.pdftotext']); } catch (BinaryNotFoundException $e) { } return $reader; }); $app['phraseanet.metadata-setter'] = $app->share(function () { return new PhraseanetMetadataSetter(); }); $app['phraseanet.user-query'] = function (SilexApplication $app) { return new \User_Query($app); }; $app['phraseanet.logger'] = $app->protect(function ($databox) use($app) { try { return \Session_Logger::load($app, $databox); } catch (\Exception_Session_LoggerNotFound $e) { return \Session_Logger::create($app, $databox, $app['browser']); } }); $app['date-formatter'] = $app->share(function (SilexApplication $app) { return new \phraseadate($app); }); }
public function indexAction(Request $request) { try { \Session_Logger::updateClientInfos($this->app, 1); } catch (SessionNotFound $e) { return $this->app->redirectPath('logout'); } $cssPath = $this->app['root.path'] . '/www/assets/prod/skins'; $css = []; $finder = new Finder(); /** @var SplFileInfo[] $iterator */ $iterator = $finder->directories()->depth(0)->filter(function (\SplFileInfo $fileinfo) { return ctype_xdigit($fileinfo->getBasename()); })->in($cssPath); foreach ($iterator as $dir) { $baseName = $dir->getBaseName(); $css[$baseName] = $baseName; } $user = $this->getAuthenticatedUser(); $cssfile = $this->getSettings()->getUserSetting($user, 'css'); if (!$cssfile && isset($css['000000'])) { $cssfile = '000000'; } $feeds = $this->getFeedRepository()->getAllForUser($this->getAclForUser()); $aggregate = Aggregate::createFromUser($this->app, $user); $thjslist = ""; $queries_topics = ''; $conf = $this->getConf(); if ($conf->get(['registry', 'classic', 'render-topics']) == 'popups') { $queries_topics = \queries::dropdown_topics($this->app['translator'], $this->app['locale']); } elseif ($conf->get(['registry', 'classic', 'render-topics']) == 'tree') { $queries_topics = \queries::tree_topics($this->app['locale']); } $sbas = $bas2sbas = []; foreach ($this->getApplicationBox()->get_databoxes() as $databox) { $sbas_id = $databox->get_sbas_id(); $sbas['s' . $sbas_id] = ['sbid' => $sbas_id, 'seeker' => null]; foreach ($databox->get_collections() as $coll) { $bas2sbas['b' . $coll->get_base_id()] = ['sbid' => $sbas_id, 'ckobj' => ['checked' => false], 'waschecked' => false]; } } $helper = new Helper\Prod($this->app, $request); /** @var \Closure $filter */ $filter = $this->app['plugin.filter_by_authorization']; $plugins = ['workzone' => $filter('workzone'), 'actionbar' => $filter('actionbar')]; return $this->render('prod/index.html.twig', ['module_name' => 'Production', 'WorkZone' => new Helper\WorkZone($this->app, $request), 'module_prod' => $helper, 'search_datas' => $helper->get_search_datas(), 'cssfile' => $cssfile, 'module' => 'prod', 'events' => $this->app['events-manager'], 'GV_defaultQuery_type' => $conf->get(['registry', 'searchengine', 'default-query-type']), 'GV_multiAndReport' => $conf->get(['registry', 'modules', 'stories']), 'GV_thesaurus' => $conf->get(['registry', 'modules', 'thesaurus']), 'cgus_agreement' => \databox_cgu::askAgreement($this->app), 'css' => $css, 'feeds' => $feeds, 'aggregate' => $aggregate, 'GV_google_api' => $conf->get(['registry', 'webservices', 'google-charts-enabled']), 'queries_topics' => $queries_topics, 'search_status' => \databox_status::getSearchStatus($this->app), 'queries_history' => \queries::history($this->app, $user->getId()), 'thesau_js_list' => $thjslist, 'thesau_json_sbas' => json_encode($sbas), 'thesau_json_bas2sbas' => json_encode($bas2sbas), 'thesau_languages' => $this->app['locales.available'], 'plugins' => $plugins]); }
/** * Display dashboard informations * * @param Application $app * @param Request $request * @return JsonResponse */ public function getDashboard(Application $app, Request $request) { if ('json' === $request->getRequestFormat()) { \Session_Logger::updateClientInfos($app, 4); $dashboard = new \module_report_dashboard($app, $app['authentication']->getUser()); $dmin = $request->query->get('dmin'); $dmax = $request->query->get('dmax'); if ($dmin && $dmax) { $dashboard->setDate($dmin, $dmax); } $dashboard->execute(); return $app->json(['html' => $app['twig']->render('report/ajax_dashboard_content_child.html.twig', ['dashboard' => $dashboard])]); } $granted = []; foreach ($app['acl']->get($app['authentication']->getUser())->get_granted_base(['canreport']) as $collection) { if (!isset($granted[$collection->get_sbas_id()])) { $granted[$collection->get_sbas_id()] = ['id' => $collection->get_sbas_id(), 'name' => $collection->get_databox()->get_viewname(), 'collections' => []]; } $granted[$collection->get_sbas_id()]['collections'][] = ['id' => $collection->get_coll_id(), 'base_id' => $collection->get_base_id(), 'name' => $collection->get_name()]; } return $app['twig']->render('report/report_layout_child.html.twig', ['ajax_dash' => true, 'dashboard' => null, 'granted_bases' => $granted, 'home_title' => $app['conf']->get(['registry', 'general', 'title']), 'module' => 'report', 'module_name' => 'Report', 'anonymous' => $app['conf']->get(['registry', 'modules', 'anonymous-report']), 'g_anal' => $app['conf']->get(['registry', 'general', 'analytics']), 'ajax' => false, 'ajax_chart' => false]); }
public function connect(SilexApplication $app) { $app['controller.lightbox'] = $this; $controllers = $app['controllers_factory']; $controllers->before(function (Request $request) use($app) { if (!$request->query->has('LOG')) { return; } if ($app['authentication']->isAuthenticated()) { $app['authentication']->closeAccount(); } if (null === ($token = $app['repo.tokens']->findValidToken($request->query->get('LOG')))) { $app->addFlash('error', $app->trans('The URL you used is out of date, please login')); return $app->redirectPath('homepage'); } $app['authentication']->openAccount($token->getUser()); switch ($token->getType()) { case TokenManipulator::TYPE_FEED_ENTRY: return $app->redirectPath('lightbox_feed_entry', ['entry_id' => $token->getData()]); break; case TokenManipulator::TYPE_VALIDATE: case TokenManipulator::TYPE_VIEW: return $app->redirectPath('lightbox_validation', ['basket' => $token->getData()]); break; } }); $app['firewall']->addMandatoryAuthentication($controllers); $controllers->before($app['middleware.basket.converter'])->before($app['middleware.basket.user-access']); $controllers->get('/', function (SilexApplication $app) { try { \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $repository = $app['repo.baskets']; $basket_collection = array_merge($repository->findActiveByUser($app['authentication']->getUser()), $repository->findActiveValidationByUser($app['authentication']->getUser())); $template = 'lightbox/index.html.twig'; if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { $template = 'lightbox/IE6/index.html.twig'; } return new Response($app['twig']->render($template, ['baskets_collection' => $basket_collection, 'module_name' => 'Lightbox', 'module' => 'lightbox'])); })->bind('lightbox'); $controllers->get('/ajax/NOTE_FORM/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) { if (!$app['browser']->isMobile()) { return new Response(''); } $basketElement = $app['repo.basket-elements']->findUserElement($sselcont_id, $app['authentication']->getUser()); $parameters = ['basket_element' => $basketElement, 'module_name' => '']; return $app['twig']->render('lightbox/note_form.html.twig', $parameters); })->bind('lightbox_ajax_note_form')->assert('sselcont_id', '\\d+'); $controllers->get('/ajax/LOAD_BASKET_ELEMENT/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) { $repository = $app['repo.basket-elements']; $BasketElement = $repository->findUserElement($sselcont_id, $app['authentication']->getUser()); if ($app['browser']->isMobile()) { $output = $app['twig']->render('lightbox/basket_element.html.twig', ['basket_element' => $BasketElement, 'module_name' => $BasketElement->getRecord($app)->get_title()]); return new Response($output); } else { $template_options = 'lightbox/sc_options_box.html.twig'; $template_agreement = 'lightbox/agreement_box.html.twig'; $template_selector = 'lightbox/selector_box.html.twig'; $template_note = 'lightbox/sc_note.html.twig'; $template_preview = 'common/preview.html.twig'; $template_caption = 'common/caption.html.twig'; if (!$app['browser']->isNewGeneration()) { $template_options = 'lightbox/IE6/sc_options_box.html.twig'; $template_agreement = 'lightbox/IE6/agreement_box.html.twig'; } $Basket = $BasketElement->getBasket(); $ret = []; $ret['number'] = $BasketElement->getRecord($app)->get_number(); $ret['title'] = $BasketElement->getRecord($app)->get_title(); $ret['preview'] = $app['twig']->render($template_preview, ['record' => $BasketElement->getRecord($app), 'not_wrapped' => true]); $ret['options_html'] = $app['twig']->render($template_options, ['basket_element' => $BasketElement]); $ret['agreement_html'] = $app['twig']->render($template_agreement, ['basket' => $Basket, 'basket_element' => $BasketElement]); $ret['selector_html'] = $app['twig']->render($template_selector, ['basket_element' => $BasketElement]); $ret['note_html'] = $app['twig']->render($template_note, ['basket_element' => $BasketElement]); $ret['caption'] = $app['twig']->render($template_caption, ['view' => 'preview', 'record' => $BasketElement->getRecord($app)]); return $app->json($ret); } })->bind('lightbox_ajax_load_basketelement')->assert('sselcont_id', '\\d+'); $controllers->get('/ajax/LOAD_FEED_ITEM/{entry_id}/{item_id}/', function (SilexApplication $app, $entry_id, $item_id) { $entry = $app['repo.feed-entries']->find($entry_id); $item = $entry->getItem($item_id); if ($app['browser']->isMobile()) { $output = $app['twig']->render('lightbox/feed_element.html.twig', ['feed_element' => $item, 'module_name' => $item->getRecord($app)->get_title()]); return new Response($output); } else { $template_options = 'lightbox/feed_options_box.html.twig'; $template_preview = 'common/preview.html.twig'; $template_caption = 'common/caption.html.twig'; if (!$app['browser']->isNewGeneration()) { $template_options = 'lightbox/IE6/feed_options_box.html.twig'; } $ret = []; $ret['number'] = $item->getRecord($app)->get_number(); $ret['title'] = $item->getRecord($app)->get_title(); $ret['preview'] = $app['twig']->render($template_preview, ['record' => $item->getRecord($app), 'not_wrapped' => true]); $ret['options_html'] = $app['twig']->render($template_options, ['feed_element' => $item]); $ret['caption'] = $app['twig']->render($template_caption, ['view' => 'preview', 'record' => $item->getRecord($app)]); $ret['agreement_html'] = $ret['selector_html'] = $ret['note_html'] = ''; return $app->json($ret); } })->bind('lightbox_ajax_load_feeditem')->assert('entry_id', '\\d+')->assert('item_id', '\\d+'); $controllers->get('/validate/{basket}/', function (SilexApplication $app, $basket) { try { \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $repository = $app['repo.baskets']; $basket_collection = $repository->findActiveValidationAndBasketByUser($app['authentication']->getUser()); if ($basket->getIsRead() === false) { $basket = $app['EM']->merge($basket); $basket->setIsRead(true); $app['EM']->flush(); } if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['authentication']->getUser())->getIsAware() === false) { $basket = $app['EM']->merge($basket); $basket->getValidation()->getParticipant($app['authentication']->getUser())->setIsAware(true); $app['EM']->flush(); } $template = 'lightbox/validate.html.twig'; if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { $template = 'lightbox/IE6/validate.html.twig'; } $response = new Response($app['twig']->render($template, ['baskets_collection' => $basket_collection, 'basket' => $basket, 'local_title' => strip_tags($basket->getName()), 'module' => 'lightbox', 'module_name' => $app->trans('admin::monitor: module validation')])); $response->setCharset('UTF-8'); return $response; })->bind('lightbox_validation')->assert('basket', '\\d+'); $controllers->get('/compare/{basket}/', function (SilexApplication $app, Basket $basket) { try { \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $repository = $app['repo.baskets']; $basket_collection = $repository->findActiveValidationAndBasketByUser($app['authentication']->getUser()); if ($basket->getIsRead() === false) { $basket = $app['EM']->merge($basket); $basket->setIsRead(true); $app['EM']->flush(); } if ($basket->getValidation() && $basket->getValidation()->getParticipant($app['authentication']->getUser())->getIsAware() === false) { $basket = $app['EM']->merge($basket); $basket->getValidation()->getParticipant($app['authentication']->getUser())->setIsAware(true); $app['EM']->flush(); } $template = 'lightbox/validate.html.twig'; if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { $template = 'lightbox/IE6/validate.html.twig'; } $response = new Response($app['twig']->render($template, ['baskets_collection' => $basket_collection, 'basket' => $basket, 'local_title' => strip_tags($basket->getName()), 'module' => 'lightbox', 'module_name' => $app->trans('admin::monitor: module validation')])); $response->setCharset('UTF-8'); return $response; })->bind('lightbox_compare')->assert('basket', '\\d+'); $controllers->get('/feeds/entry/{entry_id}/', function (SilexApplication $app, $entry_id) { try { \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $feed_entry = $app['repo.feed-entries']->find($entry_id); $template = 'lightbox/feed.html.twig'; if (!$app['browser']->isNewGeneration() && !$app['browser']->isMobile()) { $template = 'lightbox/IE6/feed.html.twig'; } $content = $feed_entry->getItems(); $first = $content->first(); $output = $app['twig']->render($template, ['feed_entry' => $feed_entry, 'first_item' => $first, 'local_title' => $feed_entry->getTitle(), 'module' => 'lightbox', 'module_name' => $app->trans('admin::monitor: module validation')]); $response = new Response($output, 200); $response->setCharset('UTF-8'); return $response; })->bind('lightbox_feed_entry')->assert('entry_id', '\\d+'); $controllers->get('/ajax/LOAD_REPORT/{basket}/', function (SilexApplication $app, Basket $basket) { return new Response($app['twig']->render('lightbox/basket_content_report.html.twig', ['basket' => $basket])); })->bind('lightbox_ajax_report')->assert('basket', '\\d+'); $controllers->post('/ajax/SET_NOTE/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) { $output = ['error' => true, 'datas' => $app->trans('Erreur lors de l\'enregistrement des donnees')]; $request = $app['request']; $note = $request->request->get('note'); if (is_null($note)) { return new Response('You must provide a note value', 400); } $repository = $app['repo.basket-elements']; $basket_element = $repository->findUserElement($sselcont_id, $app['authentication']->getUser()); $validationDatas = $basket_element->getUserValidationDatas($app['authentication']->getUser()); $validationDatas->setNote($note); $app['EM']->merge($validationDatas); $app['EM']->flush(); if ($app['browser']->isMobile()) { $datas = $app['twig']->render('lightbox/sc_note.html.twig', ['basket_element' => $basket_element]); $output = ['error' => false, 'datas' => $datas]; } else { $template = 'lightbox/sc_note.html.twig'; $datas = $app['twig']->render($template, ['basket_element' => $basket_element]); $output = ['error' => false, 'datas' => $datas]; } return $app->json($output); })->bind('lightbox_ajax_set_note')->assert('sselcont_id', '\\d+'); $controllers->post('/ajax/SET_ELEMENT_AGREEMENT/{sselcont_id}/', function (SilexApplication $app, $sselcont_id) { $request = $app['request']; $agreement = $request->request->get('agreement'); if (is_null($agreement)) { return new Response('You must provide an agreement value', 400); } $agreement = $agreement > 0; $releasable = false; try { $ret = ['error' => true, 'releasable' => false, 'datas' => $app->trans('Erreur lors de la mise a jour des donnes')]; $repository = $app['repo.basket-elements']; $basket_element = $repository->findUserElement($sselcont_id, $app['authentication']->getUser()); /* @var $basket_element BasketElement */ $validationDatas = $basket_element->getUserValidationDatas($app['authentication']->getUser()); if (!$basket_element->getBasket()->getValidation()->getParticipant($app['authentication']->getUser())->getCanAgree()) { throw new ControllerException('You can not agree on this'); } $validationDatas->setAgreement($agreement); $participant = $basket_element->getBasket()->getValidation()->getParticipant($app['authentication']->getUser()); $app['EM']->merge($basket_element); $app['EM']->flush(); $releasable = false; if ($participant->isReleasable() === true) { $releasable = $app->trans('Do you want to send your report ?'); } $ret = ['error' => false, 'datas' => '', 'releasable' => $releasable]; } catch (ControllerException $e) { $ret['datas'] = $e->getMessage(); } return $app->json($ret); })->bind('lightbox_ajax_set_element_agreement')->assert('sselcont_id', '\\d+'); $controllers->post('/ajax/SET_RELEASE/{basket}/', function (SilexApplication $app, Basket $basket) { $datas = ['error' => true, 'datas' => '']; try { if (!$basket->getValidation()) { throw new ControllerException('There is no validation session attached to this basket'); } if (!$basket->getValidation()->getParticipant($app['authentication']->getUser())->getCanAgree()) { throw new ControllerException('You have not right to agree'); } $agreed = false; /* @var $basket Basket */ foreach ($basket->getElements() as $element) { if (null !== $element->getUserValidationDatas($app['authentication']->getUser())->getAgreement()) { $agreed = true; } } if (!$agreed) { throw new ControllerException($app->trans('You have to give your feedback at least on one document to send a report')); } /* @var $basket Basket */ $participant = $basket->getValidation()->getParticipant($app['authentication']->getUser()); $token = $app['manipulator.token']->createBasketValidationToken($basket); $url = $app->url('lightbox', ['LOG' => $token->getValue()]); $to = $basket->getValidation()->getInitiator($app)->getId(); $app['dispatcher']->dispatch(PhraseaEvents::VALIDATION_DONE, new ValidationEvent($participant, $basket, $url)); $participant->setIsConfirmed(true); $app['EM']->merge($participant); $app['EM']->flush(); $datas = ['error' => false, 'datas' => $app->trans('Envoie avec succes')]; } catch (ControllerException $e) { $datas = ['error' => true, 'datas' => $e->getMessage()]; } return $app->json($datas); })->bind('lightbox_ajax_set_release')->assert('basket', '\\d+'); return $controllers; }
public function connect(Application $app) { $app['controller.admin.root'] = $this; $controllers = $app['controllers_factory']; $app['firewall']->addMandatoryAuthentication($controllers); $controllers->before(function (Request $request) use($app) { $app['firewall']->requireAccessToModule('admin'); }); $controllers->get('/', function (Application $app, Request $request) { try { \Session_Logger::updateClientInfos($app, 3); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $section = $request->query->get('section', false); $available = ['connected', 'registrations', 'taskmanager', 'base', 'bases', 'collection', 'user', 'users']; $feature = 'connected'; $featured = false; $position = explode(':', $section); if (count($position) > 0) { if (in_array($position[0], $available)) { $feature = $position[0]; if (isset($position[1])) { $featured = $position[1]; } } } $databoxes = $off_databoxes = []; foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) { try { if (!$app['acl']->get($app['authentication']->getUser())->has_access_to_sbas($databox->get_sbas_id())) { continue; } $databox->get_connection(); } catch (\Exception $e) { $off_databoxes[] = $databox; continue; } $databoxes[] = $databox; } $params = ['feature' => $feature, 'featured' => $featured, 'databoxes' => $databoxes, 'off_databoxes' => $off_databoxes]; return $app['twig']->render('admin/index.html.twig', ['module' => 'admin', 'events' => $app['events-manager'], 'module_name' => 'Admin', 'notice' => $request->query->get("notice"), 'feature' => $feature, 'featured' => $featured, 'databoxes' => $databoxes, 'off_databoxes' => $off_databoxes, 'tree' => $app['twig']->render('admin/tree.html.twig', $params)]); })->bind('admin'); $controllers->get('/tree/', function (Application $app, Request $request) { try { \Session_Logger::updateClientInfos($app, 3); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $available = ['connected', 'registrations', 'taskmanager', 'base', 'bases', 'collection', 'user', 'users']; $feature = 'connected'; $featured = false; $position = explode(':', $request->query->get('position', false)); if (count($position) > 0) { if (in_array($position[0], $available)) { $feature = $position[0]; if (isset($position[1])) { $featured = $position[1]; } } } $databoxes = $off_databoxes = []; foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) { try { if (!$app['acl']->get($app['authentication']->getUser())->has_access_to_sbas($databox->get_sbas_id())) { continue; } $databox->get_connection(); } catch (\Exception $e) { $off_databoxes[] = $databox; continue; } $databoxes[] = $databox; } $params = ['feature' => $feature, 'featured' => $featured, 'databoxes' => $databoxes, 'off_databoxes' => $off_databoxes]; return $app['twig']->render('admin/tree.html.twig', $params); })->bind('admin_display_tree'); $controllers->get('/test-paths/', function (Application $app, Request $request) { if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { $app->abort(400, $app->trans('Bad request format, only JSON is allowed')); } if (0 !== count($tests = $request->query->get('tests', []))) { $app->abort(400, $app->trans('Missing tests parameter')); } if (null !== ($path = $request->query->get('path'))) { $app->abort(400, $app->trans('Missing path parameter')); } foreach ($tests as $test) { switch ($test) { case 'writeable': if (!is_writable($path)) { $result = false; } break; case 'readable': default: if (!is_readable($path)) { $result = true; } break; } } return $app->json(['results' => $result]); })->bind('admin_test_paths'); $controllers->get('/structure/{databox_id}/', function (Application $app, Request $request, $databox_id) { if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_sbas($databox_id, 'bas_modify_struct')) { $app->abort(403); } $databox = $app['phraseanet.appbox']->get_databox((int) $databox_id); $structure = $databox->get_structure(); $errors = \databox::get_structure_errors($app['translator'], $structure); if ($updateOk = !!$request->query->get('success', false)) { $updateOk = true; } if (false !== ($errorsStructure = $request->query->get('error', false))) { $errorsStructure = true; } return $app['twig']->render('admin/structure.html.twig', ['databox' => $databox, 'errors' => $errors, 'structure' => $structure, 'errorsStructure' => $errorsStructure, 'updateOk' => $updateOk]); })->assert('databox_id', '\\d+')->bind('database_display_stucture'); $controllers->post('/structure/{databox_id}/', function (Application $app, Request $request, $databox_id) { if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_sbas($databox_id, 'bas_modify_struct')) { $app->abort(403); } if (null === ($structure = $request->request->get('structure'))) { $app->abort(400, $app->trans('Missing "structure" parameter')); } $errors = \databox::get_structure_errors($app['translator'], $structure); $domst = new \DOMDocument('1.0', 'UTF-8'); $domst->preserveWhiteSpace = false; $domst->formatOutput = true; if (count($errors) == 0 && $domst->loadXML($structure)) { $databox = $app['phraseanet.appbox']->get_databox($databox_id); $databox->saveStructure($domst); return $app->redirectPath('database_display_stucture', ['databox_id' => $databox_id, 'success' => 1]); } else { return $app->redirectPath('database_display_stucture', ['databox_id' => $databox_id, 'success' => 0, 'error' => 'struct']); } })->assert('databox_id', '\\d+')->bind('database_submit_stucture'); $controllers->get('/statusbit/{databox_id}/', function (Application $app, Request $request, $databox_id) { if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_sbas($databox_id, 'bas_modify_struct')) { $app->abort(403); } return $app['twig']->render('admin/statusbit.html.twig', ['databox' => $app['phraseanet.appbox']->get_databox($databox_id)]); })->assert('databox_id', '\\d+')->bind('database_display_statusbit'); $controllers->get('/statusbit/{databox_id}/status/{bit}/', function (Application $app, Request $request, $databox_id, $bit) { if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_sbas($databox_id, 'bas_modify_struct')) { $app->abort(403); } $databox = $app['phraseanet.appbox']->get_databox($databox_id); $status = $databox->get_statusbits(); switch ($errorMsg = $request->query->get('error')) { case 'rights': $errorMsg = $app->trans('You do not enough rights to update status'); break; case 'too-big': $errorMsg = $app->trans('File is too big : 64k max'); break; case 'upload-error': $errorMsg = $app->trans('Status icon upload failed : upload error'); break; case 'wright-error': $errorMsg = $app->trans('Status icon upload failed : can not write on disk'); break; case 'unknow-error': $errorMsg = $app->trans('Something wrong happend'); break; } if (isset($status[$bit])) { $status = $status[$bit]; } else { $status = ["labeloff" => '', "labelon" => '', "img_off" => '', "img_on" => '', "path_off" => '', "path_on" => '', "searchable" => false, "printable" => false]; foreach ($app['locales.available'] as $code => $language) { $status['labels_on'][$code] = null; $status['labels_off'][$code] = null; } } return $app['twig']->render('admin/statusbit/edit.html.twig', ['status' => $status, 'errorMsg' => $errorMsg]); })->assert('databox_id', '\\d+')->assert('bit', '\\d+')->bind('database_display_statusbit_form'); $controllers->post('/statusbit/{databox_id}/status/{bit}/delete/', function (Application $app, Request $request, $databox_id, $bit) { if (!$request->isXmlHttpRequest() || !array_key_exists($request->getMimeType('json'), array_flip($request->getAcceptableContentTypes()))) { $app->abort(400, $app->trans('Bad request format, only JSON is allowed')); } if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_sbas($databox_id, 'bas_modify_struct')) { $app->abort(403); } $error = false; try { \databox_status::deleteStatus($app, $app['phraseanet.appbox']->get_databox($databox_id), $bit); } catch (\Exception $e) { $error = true; } return $app->json(['success' => !$error]); })->bind('admin_statusbit_delete')->assert('databox_id', '\\d+')->assert('bit', '\\d+'); $controllers->post('/statusbit/{databox_id}/status/{bit}/', function (Application $app, Request $request, $databox_id, $bit) { if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_sbas($databox_id, 'bas_modify_struct')) { $app->abort(403); } $properties = ['searchable' => $request->request->get('searchable') ? '1' : '0', 'printable' => $request->request->get('printable') ? '1' : '0', 'name' => $request->request->get('name', ''), 'labelon' => $request->request->get('label_on', ''), 'labeloff' => $request->request->get('label_off', ''), 'labels_on' => $request->request->get('labels_on', []), 'labels_off' => $request->request->get('labels_off', [])]; \databox_status::updateStatus($app, $databox_id, $bit, $properties); if (null !== $request->request->get('delete_icon_off')) { \databox_status::deleteIcon($app, $databox_id, $bit, 'off'); } if (null !== ($file = $request->files->get('image_off'))) { try { \databox_status::updateIcon($app, $databox_id, $bit, 'off', $file); } catch (AccessDeniedHttpException $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'rights']); } catch (\Exception_InvalidArgument $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'unknow-error']); } catch (\Exception_Upload_FileTooBig $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'too-big']); } catch (\Exception_Upload_Error $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'upload-error']); } catch (\Exception_Upload_CannotWriteFile $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'wright-error']); } catch (\Exception $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'unknow-error']); } } if (null !== $request->request->get('delete_icon_on')) { \databox_status::deleteIcon($app, $databox_id, $bit, 'on'); } if (null !== ($file = $request->files->get('image_on'))) { try { \databox_status::updateIcon($app, $databox_id, $bit, 'on', $file); } catch (AccessDeniedHttpException $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'rights']); } catch (\Exception_InvalidArgument $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'unknow-error']); } catch (\Exception_Upload_FileTooBig $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'too-big']); } catch (\Exception_Upload_Error $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'upload-error']); } catch (\Exception_Upload_CannotWriteFile $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'wright-error']); } catch (\Exception $e) { return $app->redirectPath('database_display_statusbit_form', ['databox_id' => $databox_id, 'bit' => $bit, 'error' => 'unknow-error']); } } return $app->redirectPath('database_display_statusbit', ['databox_id' => $databox_id, 'success' => 1]); })->assert('databox_id', '\\d+')->assert('bit', '\\d+')->bind('database_submit_statusbit'); return $controllers; }
/** * @param int $entry_id * @return Response */ public function getFeedEntryAction($entry_id) { $app = $this->app; try { \Session_Logger::updateClientInfos($app, 6); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } /** @var FeedEntry $feed_entry */ $feed_entry = $app['repo.feed-entries']->find($entry_id); $template = $this->isBrowserNewGenerationOrMobile() ? 'lightbox/feed.html.twig' : 'lightbox/IE6/feed.html.twig'; $content = $feed_entry->getItems(); $first = $content->first(); $response = $this->renderResponse($template, ['feed_entry' => $feed_entry, 'first_item' => $first, 'local_title' => $feed_entry->getTitle(), 'module' => 'lightbox', 'module_name' => $app->trans('admin::monitor: module validation')]); $response->setCharset('UTF-8'); return $response; }
/** * Gets client main page * * @param Application $app * @param Request $request * @return Response */ public function getClient(Application $app, Request $request) { try { \Session_Logger::updateClientInfos($app, 2); } catch (SessionNotFound $e) { return $app->redirectPath('logout'); } $renderTopics = ''; if ($app['conf']->get(['registry', 'classic', 'render-topics']) == 'popups') { $renderTopics = \queries::dropdown_topics($app['translator'], $app['locale']); } elseif ($app['conf']->get(['registry', 'classic', 'render-topics']) == 'tree') { $renderTopics = \queries::tree_topics($app['locale']); } return new Response($app['twig']->render('client/index.html.twig', ['last_action' => !$app['authentication']->getUser()->isGuest() && false !== $request->cookies->has('last_act') ? $request->cookies->has('last_act') : null, 'phrasea_home' => $this->getDefaultClientStartPage($app), 'render_topics' => $renderTopics, 'grid_properties' => $this->getGridProperty(), 'search_order' => SearchEngineOptions::SORT_MODE_DESC, 'storage_access' => $this->getDocumentStorageAccess($app), 'tabs_setup' => $this->getTabSetup($app), 'module' => 'client', 'menubar' => $app['twig']->render('common/menubar.html.twig', ['module' => 'client']), 'css_file' => $this->getCssFile($app), 'basket_status' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'client_basket_status', '1'), 'mod_pres' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'client_view', ''), 'start_page' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page'), 'start_page_query' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page_query', '')])); }
public function __construct($environment = self::ENV_PROD) { parent::__construct(); error_reporting(-1); $this['root.path'] = realpath(__DIR__ . '/../../..'); $this->environment = $environment; mb_internal_encoding("UTF-8"); !defined('JETON_MAKE_SUBDEF') ? define('JETON_MAKE_SUBDEF', 0x1) : ''; !defined('JETON_WRITE_META_DOC') ? define('JETON_WRITE_META_DOC', 0x2) : ''; !defined('JETON_WRITE_META_SUBDEF') ? define('JETON_WRITE_META_SUBDEF', 0x4) : ''; !defined('JETON_WRITE_META') ? define('JETON_WRITE_META', 0x6) : ''; $this['charset'] = 'UTF-8'; $this['debug'] = $this->share(function (Application $app) { return Application::ENV_PROD !== $app->getEnvironment(); }); if ($this['debug'] === true) { ini_set('log_errors', 'on'); ini_set('error_log', $this['root.path'] . '/logs/php_error.log'); } $this->register(new BasketMiddlewareProvider()); $this->register(new ACLServiceProvider()); $this->register(new AuthenticationManagerServiceProvider()); $this->register(new BorderManagerServiceProvider()); $this->register(new BrowserServiceProvider()); $this->register(new ConfigurationServiceProvider()); $this->register(new ConfigurationTesterServiceProvider()); $this->register(new ConvertersServiceProvider()); $this->register(new RegistrationServiceProvider()); $this->register(new CacheServiceProvider()); $this->register(new CacheConnectionServiceProvider()); $this->register(new ImagineServiceProvider()); $this->register(new JMSSerializerServiceProvider()); $this->register(new FFMpegServiceProvider()); $this->register(new FeedServiceProvider()); $this->register(new FilesystemServiceProvider()); $this->register(new FtpServiceProvider()); $this->register(new GeonamesServiceProvider()); $this['geonames.server-uri'] = $this->share(function (Application $app) { return $app['conf']->get(['registry', 'webservices', 'geonames-server'], 'http://geonames.alchemyasp.com/'); }); $this->register(new MediaAlchemystServiceProvider()); $this['media-alchemyst.configuration'] = $this->share(function (Application $app) { $configuration = []; foreach (['swftools.pdf2swf.binaries' => 'pdf2swf_binary', 'swftools.swfrender.binaries' => 'swf_render_binary', 'swftools.swfextract.binaries' => 'swf_extract_binary', 'unoconv.binaries' => 'unoconv_binary', 'mp4box.binaries' => 'mp4box_binary', 'gs.binaries' => 'ghostscript_binary', 'ffmpeg.ffmpeg.binaries' => 'ffmpeg_binary', 'ffmpeg.ffprobe.binaries' => 'ffprobe_binary', 'ffmpeg.ffmpeg.timeout' => 'ffmpeg_timeout', 'ffmpeg.ffprobe.timeout' => 'ffprobe_timeout', 'gs.timeout' => 'gs_timeout', 'mp4box.timeout' => 'mp4box_timeout', 'swftools.timeout' => 'swftools_timeout', 'unoconv.timeout' => 'unoconv_timeout'] as $parameter => $key) { if ($this['conf']->has(['main', 'binaries', $key])) { $configuration[$parameter] = $this['conf']->get(['main', 'binaries', $key]); } } $imagineDriver = $app['conf']->get(['registry', 'executables', 'imagine-driver']); $configuration['ffmpeg.threads'] = $app['conf']->get(['registry', 'executables', 'ffmpeg-threads']); $configuration['imagine.driver'] = $imagineDriver ?: null; return $configuration; }); $this['media-alchemyst.logger'] = $this->share(function (Application $app) { return $app['monolog']; }); $this->register(new MediaVorusServiceProvider()); $this->register(new MonologServiceProvider()); $this['monolog.name'] = 'Phraseanet logger'; $this['monolog.handler'] = $this->share(function () { return new NullHandler(); }); $this['monolog'] = $this->share($this->extend('monolog', function (Logger $monolog) { $monolog->pushProcessor(new IntrospectionProcessor()); return $monolog; })); $this->register(new MP4BoxServiceProvider()); $this->register(new NotificationDelivererServiceProvider()); $this->register(new ORMServiceProvider()); $this->register(new ManipulatorServiceProvider()); $this->register(new InstallerServiceProvider()); $this->register(new PhraseanetServiceProvider()); $this->register(new PhraseaVersionServiceProvider()); $this->register(new PHPExiftoolServiceProvider()); $this->register(new ReCaptchaServiceProvider()); $this->register(new SubdefServiceProvider()); $this->register(new ZippyServiceProvider()); $this['recaptcha.public-key'] = $this->share(function (Application $app) { if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) { return $app['conf']->get(['registry', 'webservices', 'recaptcha-public-key']); } }); $this['recaptcha.private-key'] = $this->share(function (Application $app) { if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) { return $app['conf']->get(['registry', 'webservices', 'recaptcha-private-key']); } }); $this->register(new SearchEngineServiceProvider()); $this->register(new SessionHandlerServiceProvider()); $this->register(new SessionServiceProvider(), ['session.test' => $this->getEnvironment() === static::ENV_TEST]); $this['session.storage.test'] = $this->share(function ($app) { return new MockArraySessionStorage(); }); $this['session.storage.handler'] = $this->share(function ($app) { return $this['session.storage.handler.factory']->create($app['conf']); }); $this->register(new SerializerServiceProvider()); $this->register(new ServiceControllerServiceProvider()); $this->register(new SwiftmailerServiceProvider()); $this->register(new TasksServiceProvider()); $this->register(new TemporaryFilesystemServiceProvider()); $this->register(new TokensServiceProvider()); $this->register(new TwigServiceProvider(), ['twig.options' => ['cache' => $this['root.path'] . '/tmp/cache_twig/']]); $this->register(new TranslationServiceProvider(), ['locale_fallbacks' => ['fr'], 'translator.cache-options' => ['debug' => $this['debug'], 'cache_dir' => $this['root.path'] . '/tmp/translations']]); $this['translator'] = $this->share($this->extend('translator', function (CachedTranslator $translator, $app) { $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.fr.xlf', 'fr', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.fr.xlf', 'fr', 'validators'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.en.xlf', 'en', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.en.xlf', 'en', 'validators'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.de.xlf', 'de', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.de.xlf', 'de', 'validators'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.nl.xlf', 'nl', 'messages'); $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.nl.xlf', 'nl', 'validators'); return $translator; })); $this->register(new FormServiceProvider()); $this['form.type.extensions'] = $this->share($this->extend('form.type.extensions', function ($extensions) { $extensions[] = new HelpTypeExtension(); return $extensions; })); $this->setupTwig(); $this->register(new UnoconvServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->setupUrlGenerator(); $this->register(new UnicodeServiceProvider()); $this->register(new ValidatorServiceProvider()); $this->register(new XPDFServiceProvider()); $this->register(new FileServeServiceProvider()); $this->register(new ManipulatorServiceProvider()); $this->register(new PluginServiceProvider()); $this['phraseanet.exception_handler'] = $this->share(function ($app) { $handler = PhraseaExceptionHandler::register($app['debug']); $handler->setTranslator($app['translator']); return $handler; }); $this['swiftmailer.transport'] = $this->share(function ($app) { if ($app['conf']->get(['registry', 'email', 'smtp-enabled'])) { $transport = new \Swift_Transport_EsmtpTransport($app['swiftmailer.transport.buffer'], [$app['swiftmailer.transport.authhandler']], $app['swiftmailer.transport.eventdispatcher']); $encryption = null; if (in_array($app['conf']->get(['registry', 'email', 'smtp-secure-mode']), ['ssl', 'tls'])) { $encryption = $app['conf']->get(['registry', 'email', 'smtp-secure-mode']); } $options = $app['swiftmailer.options'] = array_replace(['host' => $app['conf']->get(['registry', 'email', 'smtp-host']), 'port' => $app['conf']->get(['registry', 'email', 'smtp-port']), 'username' => $app['conf']->get(['registry', 'email', 'smtp-user']), 'password' => $app['conf']->get(['registry', 'email', 'smtp-password']), 'encryption' => $encryption, 'auth_mode' => null], $app['swiftmailer.options']); $transport->setHost($options['host']); $transport->setPort($options['port']); // tls or ssl $transport->setEncryption($options['encryption']); if ($app['conf']->get(['registry', 'email', 'smtp-auth-enabled'])) { $transport->setUsername($options['username']); $transport->setPassword($options['password']); $transport->setAuthMode($options['auth_mode']); } } else { $transport = new \Swift_Transport_MailTransport(new \Swift_Transport_SimpleMailInvoker(), $app['swiftmailer.transport.eventdispatcher']); } return $transport; }); $this['imagine.factory'] = $this->share(function (Application $app) { if ($app['conf']->get(['registry', 'executables', 'imagine-driver']) != '') { return $app['conf']->get(['registry', 'executables', 'imagine-driver']); } if (class_exists('\\Gmagick')) { return 'gmagick'; } if (class_exists('\\Imagick')) { return 'imagick'; } if (extension_loaded('gd')) { return 'gd'; } throw new \RuntimeException('No Imagine driver available'); }); $app = $this; $this['phraseanet.logger'] = $this->protect(function ($databox) use($app) { try { return \Session_Logger::load($app, $databox); } catch (\Exception_Session_LoggerNotFound $e) { return \Session_Logger::create($app, $databox, $app['browser']); } }); $this['date-formatter'] = $this->share(function (Application $app) { return new \phraseadate($app); }); $this['xpdf.pdftotext'] = $this->share($this->extend('xpdf.pdftotext', function (PdfToText $pdftotext, Application $app) { if ($app['conf']->get(['registry', 'executables', 'pdf-max-pages'])) { $pdftotext->setPageQuantity($app['conf']->get(['registry', 'executables', 'pdf-max-pages'])); } return $pdftotext; })); $this['dispatcher'] = $this->share($this->extend('dispatcher', function ($dispatcher, Application $app) { $dispatcher->addListener(KernelEvents::REQUEST, [$app, 'initSession'], 254); $dispatcher->addListener(KernelEvents::RESPONSE, [$app, 'addUTF8Charset'], -128); $dispatcher->addSubscriber(new LogoutSubscriber()); $dispatcher->addSubscriber(new PhraseaLocaleSubscriber($app)); $dispatcher->addSubscriber(new MaintenanceSubscriber($app)); $dispatcher->addSubscriber(new CookiesDisablerSubscriber($app)); return $dispatcher; })); $this['log.channels'] = ['monolog', 'task-manager.logger']; $this->register(new LocaleServiceProvider()); $this->mount('/include/minify/', new Minifier()); $this->mount('/permalink/', new Permalink()); $this->mount('/lightbox/', new Lightbox()); $app['plugins.directory'] = $app->share(function () { $dir = __DIR__ . '/../../../plugins'; if (is_dir($dir)) { return realpath($dir); } return $dir; }); }