コード例 #1
0
ファイル: DoDownload.php プロジェクト: nlegoff/Phraseanet
 /**
  * Prepare a set of documents for download
  *
  * @param Application $app
  * @param Request     $request
  * @param Token       $token
  *
  * @return Response
  */
 public function prepareDownload(Application $app, Request $request, Token $token)
 {
     if (false === ($list = @unserialize($token->getData()))) {
         $app->abort(500, 'Invalid datas');
     }
     if (!is_array($list)) {
         $app->abort(500, 'Invalid datas');
     }
     foreach (['export_name', 'files'] as $key) {
         if (!isset($list[$key])) {
             $app->abort(500, 'Invalid datas');
         }
     }
     $records = [];
     foreach ($list['files'] as $file) {
         if (!is_array($file) || !isset($file['base_id']) || !isset($file['record_id'])) {
             continue;
         }
         $sbasId = \phrasea::sbasFromBas($app, $file['base_id']);
         try {
             $record = new \record_adapter($app, $sbasId, $file['record_id']);
         } catch (\Exception $e) {
             continue;
         }
         $records[sprintf('%s_%s', $sbasId, $file['record_id'])] = $record;
     }
     return new Response($app['twig']->render('/prod/actions/Download/prepare.html.twig', ['module_name' => $app->trans('Export'), 'module' => $app->trans('Export'), 'list' => $list, 'records' => $records, 'token' => $token, 'anonymous' => $request->query->get('anonymous', false), 'type' => $request->query->get('type', \Session_Logger::EVENT_EXPORTDOWNLOAD)]));
 }
コード例 #2
0
ファイル: MoveCollection.php プロジェクト: nlegoff/Phraseanet
 public function apply(Application $app, Request $request)
 {
     $records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
     $datas = ['success' => false, 'message' => ''];
     try {
         if (null === $request->request->get('base_id')) {
             $datas['message'] = $app->trans('Missing target collection');
             return $app->json($datas);
         }
         if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
             $datas['message'] = $app->trans("You do not have the permission to move records to %collection%", ['%collection%', \phrasea::bas_labels($request->request->get('base_id'), $app)]);
             return $app->json($datas);
         }
         try {
             $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
         } catch (\Exception_Databox_CollectionNotFound $e) {
             $datas['message'] = $app->trans('Invalid target collection');
             return $app->json($datas);
         }
         foreach ($records as $record) {
             $record->move_to_collection($collection, $app['phraseanet.appbox']);
             if ($request->request->get("chg_coll_son") == "1") {
                 foreach ($record->get_children() as $child) {
                     if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($child->get_base_id(), 'candeleterecord')) {
                         $child->move_to_collection($collection, $app['phraseanet.appbox']);
                     }
                 }
             }
         }
         $ret = ['success' => true, 'message' => $app->trans('Records have been successfuly moved')];
     } catch (\Exception $e) {
         $ret = ['success' => false, 'message' => $app->trans('An error occured')];
     }
     return $app->json($ret);
 }
コード例 #3
0
 public static function tearDownAfterClass()
 {
     $app = new Application('test');
     \phrasea::reset_sbasDatas($app['phraseanet.appbox']);
     \phrasea::reset_baseDatas($app['phraseanet.appbox']);
     parent::tearDownAfterClass();
 }
コード例 #4
0
ファイル: Share.php プロジェクト: nlegoff/Phraseanet
 /**
  *  Share a record
  *
  * @param  Application $app
  * @param  Request     $request
  * @param  integer     $base_id
  * @param  integer     $record_id
  * @return Response
  */
 public function shareRecord(Application $app, Request $request, $base_id, $record_id)
 {
     $record = new \record_adapter($app, \phrasea::sbasFromBas($app, $base_id), $record_id);
     if (!$app['acl']->get($app['authentication']->getUser())->has_access_to_subdef($record, 'preview')) {
         $app->abort(403);
     }
     return new Response($app['twig']->render('prod/Share/record.html.twig', ['record' => $record]));
 }
コード例 #5
0
 /**
  *  Share a record
  *
  * @param  integer     $base_id
  * @param  integer     $record_id
  * @return Response
  */
 public function shareRecord($base_id, $record_id)
 {
     $record = new \record_adapter($this->app, \phrasea::sbasFromBas($this->app, $base_id), $record_id);
     if (!$this->getAclForUser()->has_access_to_subdef($record, 'preview')) {
         $this->app->abort(403);
     }
     return $this->renderResponse('prod/Share/record.html.twig', ['record' => $record]);
 }
コード例 #6
0
ファイル: Share.php プロジェクト: luisbrito/Phraseanet
 public function connect(Application $app)
 {
     $controllers = $this->createAuthenticatedCollection($app);
     $firewall = $this->getFirewall($app);
     $controllers->before(function () use($firewall) {
         $firewall->requireNotGuest();
     });
     $controllers->get('/record/{base_id}/{record_id}/', 'controller.prod.share:shareRecord')->before(function (Request $request) use($app, $firewall) {
         $firewall->requireRightOnSbas(\phrasea::sbasFromBas($app, $request->attributes->get('base_id')), 'bas_chupub');
     })->bind('share_record');
     return $controllers;
 }
コード例 #7
0
ファイル: status.php プロジェクト: nlegoff/Phraseanet
 /**
  *
  * @param  int    $sbas_id
  * @return status
  */
 private function __construct(Application $app, $sbas_id)
 {
     $this->status = [];
     $path = $url = false;
     $sbas_params = phrasea::sbas_params($app);
     if (!isset($sbas_params[$sbas_id])) {
         return;
     }
     $uniqid = md5(implode('-', [$sbas_params[$sbas_id]["host"], $sbas_params[$sbas_id]["port"], $sbas_params[$sbas_id]["dbname"]]));
     $path = $this->path = $app['root.path'] . "/config/status/" . $uniqid;
     $url = $this->url = "/custom/status/" . $uniqid;
     $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
     $xmlpref = $databox->get_structure();
     $sxe = simplexml_load_string($xmlpref);
     if ($sxe !== false) {
         foreach ($sxe->statbits->bit as $sb) {
             $bit = (int) $sb["n"];
             if ($bit < 4 && $bit > 31) {
                 continue;
             }
             $this->status[$bit]["labeloff"] = (string) $sb['labelOff'];
             $this->status[$bit]["labelon"] = (string) $sb['labelOn'];
             foreach ($app['locales.available'] as $code => $language) {
                 $this->status[$bit]['labels_on'][$code] = null;
                 $this->status[$bit]['labels_off'][$code] = null;
             }
             foreach ($sb->label as $label) {
                 $this->status[$bit]['labels_' . $label['switch']][(string) $label['code']] = (string) $label;
             }
             foreach ($app['locales.available'] as $code => $language) {
                 $this->status[$bit]['labels_on_i18n'][$code] = '' !== trim($this->status[$bit]['labels_on'][$code]) ? $this->status[$bit]['labels_on'][$code] : $this->status[$bit]["labelon"];
                 $this->status[$bit]['labels_off_i18n'][$code] = '' !== trim($this->status[$bit]['labels_off'][$code]) ? $this->status[$bit]['labels_off'][$code] : $this->status[$bit]["labeloff"];
             }
             $this->status[$bit]["img_off"] = null;
             $this->status[$bit]["img_on"] = null;
             if (is_file($path . "-stat_" . $bit . "_0.gif")) {
                 $this->status[$bit]["img_off"] = $url . "-stat_" . $bit . "_0.gif?etag=" . md5_file($path . "-stat_" . $bit . "_0.gif");
                 $this->status[$bit]["path_off"] = $path . "-stat_" . $bit . "_0.gif";
             }
             if (is_file($path . "-stat_" . $bit . "_1.gif")) {
                 $this->status[$bit]["img_on"] = $url . "-stat_" . $bit . "_1.gif?etag=" . md5_file($path . "-stat_" . $bit . "_1.gif");
                 $this->status[$bit]["path_on"] = $path . "-stat_" . $bit . "_1.gif";
             }
             $this->status[$bit]["searchable"] = isset($sb['searchable']) ? (int) $sb['searchable'] : 0;
             $this->status[$bit]["printable"] = isset($sb['printable']) ? (int) $sb['printable'] : 0;
         }
     }
     ksort($this->status);
     return $this;
 }
コード例 #8
0
 /**
  * Get Databases control panel
  *
  * @param Request $request
  * @return Response
  */
 public function getDatabases(Request $request)
 {
     $acl = $this->getAclForUser();
     $sbasIds = array_merge(array_keys($acl->get_granted_sbas(['bas_manage'])), array_keys($acl->get_granted_sbas(['bas_modify_struct'])));
     $sbas = [];
     foreach ($sbasIds as $sbasId) {
         $sbas[$sbasId] = ['version' => 'unknown', 'image' => '/assets/common/images/icons/db-remove.png', 'server_info' => '', 'name' => $this->app->trans('Unreachable server')];
         try {
             $databox = $this->findDataboxById($sbasId);
             /** @var \PDO $pdoConnection */
             $pdoConnection = $databox->get_connection()->getWrappedConnection();
             $sbas[$sbasId] = ['version' => $databox->get_version(), 'image' => '/assets/common/images/icons/foldph20close_0.gif', 'server_info' => $pdoConnection->getAttribute(\PDO::ATTR_SERVER_VERSION), 'name' => \phrasea::sbas_labels($sbasId, $this->app)];
         } catch (\Exception $e) {
         }
     }
     switch ($errorMsg = $request->query->get('error')) {
         case 'scheduler-started':
             $errorMsg = $this->app->trans('Veuillez arreter le planificateur avant la mise a jour');
             break;
         case 'already-started':
             $errorMsg = $this->app->trans('The upgrade is already started');
             break;
         case 'unknow':
             $errorMsg = $this->app->trans('An error occured');
             break;
         case 'bad-email':
             $errorMsg = $this->app->trans('Please fix the database before starting');
             break;
         case 'special-chars':
             $errorMsg = $this->app->trans('Database name can not contains special characters');
             break;
         case 'base-failed':
             $errorMsg = $this->app->trans('Base could not be created');
             break;
         case 'database-failed':
             $errorMsg = $this->app->trans('Database does not exists or can not be accessed');
             break;
         case 'no-empty':
             $errorMsg = $this->app->trans('Database can not be empty');
             break;
         case 'mount-failed':
             $errorMsg = $this->app->trans('Database could not be mounted');
             break;
         case 'innodb-support':
             $errorMsg = $this->app->trans('Database server does not support InnoDB storage engine');
             break;
     }
     return $this->render('admin/databases.html.twig', ['files' => new \DirectoryIterator($this->app['root.path'] . '/lib/conf.d/data_templates'), 'sbas' => $sbas, 'error_msg' => $errorMsg, 'advices' => $request->query->get('advices', []), 'reloadTree' => (bool) $request->query->get('reload-tree')]);
 }
コード例 #9
0
 /**
  * Get Databases control panel
  *
  * @param           $app     Application $app
  * @param           $request Request $request
  * @return Response
  */
 public function getDatabases(Application $app, Request $request)
 {
     $sbasIds = array_merge(array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_sbas(['bas_manage'])), array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_sbas(['bas_modify_struct'])));
     $sbas = [];
     foreach ($sbasIds as $sbasId) {
         $sbas[$sbasId] = ['version' => 'unknown', 'image' => '/skins/icons/db-remove.png', 'server_info' => '', 'name' => $app->trans('Unreachable server')];
         try {
             $databox = $app['phraseanet.appbox']->get_databox($sbasId);
             $sbas[$sbasId] = ['version' => $databox->get_version(), 'image' => '/skins/icons/foldph20close_0.gif', 'server_info' => $databox->get_connection()->getWrappedConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION), 'name' => \phrasea::sbas_labels($sbasId, $app)];
         } catch (\Exception $e) {
         }
     }
     switch ($errorMsg = $request->query->get('error')) {
         case 'scheduler-started':
             $errorMsg = $app->trans('Veuillez arreter le planificateur avant la mise a jour');
             break;
         case 'already-started':
             $errorMsg = $app->trans('The upgrade is already started');
             break;
         case 'unknow':
             $errorMsg = $app->trans('An error occured');
             break;
         case 'bad-email':
             $errorMsg = $app->trans('Please fix the database before starting');
             break;
         case 'special-chars':
             $errorMsg = $app->trans('Database name can not contains special characters');
             break;
         case 'base-failed':
             $errorMsg = $app->trans('Base could not be created');
             break;
         case 'database-failed':
             $errorMsg = $app->trans('Database does not exists or can not be accessed');
             break;
         case 'no-empty':
             $errorMsg = $app->trans('Database can not be empty');
             break;
         case 'mount-failed':
             $errorMsg = $app->trans('Database could not be mounted');
             break;
     }
     $upgrader = new \Setup_Upgrade($app);
     return $app['twig']->render('admin/databases.html.twig', ['files' => new \DirectoryIterator($app['root.path'] . '/lib/conf.d/data_templates'), 'sbas' => $sbas, 'error_msg' => $errorMsg, 'recommendations' => $upgrader->getRecommendations(), 'advices' => $request->query->get('advices', []), 'reloadTree' => (bool) $request->query->get('reload-tree')]);
 }
コード例 #10
0
 public function testInstall()
 {
     $app = new Application(Application::ENV_TEST);
     \phrasea::reset_sbasDatas($app['phraseanet.appbox']);
     \phrasea::reset_baseDatas($app['phraseanet.appbox']);
     $app->bindRoutes();
     $parser = new Parser();
     $config = $parser->parse(file_get_contents(__DIR__ . '/../../../../../config/configuration.yml'));
     $credentials = $config['main']['database'];
     $configFile = __DIR__ . '/configuration.yml';
     $compiledFile = __DIR__ . '/configuration.yml.php';
     @unlink($configFile);
     @unlink($compiledFile);
     $app['configuration.store'] = $app->share(function () use($configFile, $compiledFile) {
         return new Configuration(new Yaml(), new Compiler(), $configFile, $compiledFile, true);
     });
     $app['conf'] = $app->share(function () use($app) {
         return new PropertyAccess($app['configuration.store']);
     });
     $app['phraseanet.appbox'] = $app->share(function () use($app) {
         return new \appbox($app);
     });
     $abInfo = ['host' => $credentials['host'], 'port' => $credentials['port'], 'user' => $credentials['user'], 'password' => $credentials['password'], 'dbname' => 'ab_setup_test'];
     $abConn = $app['dbal.provider']($abInfo);
     $dbConn = $app['dbal.provider'](['host' => $credentials['host'], 'port' => $credentials['port'], 'user' => $credentials['user'], 'password' => $credentials['password'], 'dbname' => 'db_setup_test']);
     $key = $app['orm.add']($abInfo);
     $app['orm.ems.default'] = $key;
     $dataPath = __DIR__ . '/../../../../../datas/';
     $installer = new Installer($app);
     $installer->install(uniqid('admin') . '@example.com', 'sdfsdsd', $abConn, 'http://local.phrasea.test.installer/', $dataPath, $dbConn, 'en');
     $this->assertTrue($app['configuration.store']->isSetup());
     $this->assertTrue($app['phraseanet.configuration-tester']->isUpToDate());
     $databox = current($app->getDataboxes());
     $this->assertContains('<path>' . realpath($dataPath) . '/db_setup_test/subdefs</path>', $databox->get_structure());
     $conf = $app['configuration.store']->getConfig();
     $this->assertArrayHasKey('main', $conf);
     $this->assertArrayHasKey('key', $conf['main']);
     $this->assertGreaterThan(10, strlen($conf['main']['key']));
     @unlink($configFile);
     @unlink($compiledFile);
     $app['connection.pool.manager']->closeAll();
 }
コード例 #11
0
 /**
  * Prepare a set of documents for download
  *
  * @param Application $app
  * @param Request     $request
  * @param String      $token
  *
  * @return Response
  */
 public function prepareDownload(Application $app, Request $request, $token)
 {
     $datas = $app['tokens']->helloToken($token);
     if (false === ($list = @unserialize((string) $datas['datas']))) {
         $app->abort(500, 'Invalid datas');
     }
     $records = [];
     foreach ($list['files'] as $file) {
         if (!is_array($file) || !isset($file['base_id']) || !isset($file['record_id'])) {
             continue;
         }
         $sbasId = \phrasea::sbasFromBas($app, $file['base_id']);
         try {
             $record = new \record_adapter($app, $sbasId, $file['record_id']);
         } catch (\Exception $e) {
             continue;
         }
         $records[sprintf('%s_%s', $sbasId, $file['record_id'])] = $record;
     }
     return new Response($app['twig']->render('/prod/actions/Download/prepare.html.twig', ['module_name' => $app->trans('Export'), 'module' => $app->trans('Export'), 'list' => $list, 'records' => $records, 'token' => $token, 'anonymous' => $request->query->get('anonymous', false)]));
 }
コード例 #12
0
 protected function doExecute(InputInterface $input, OutputInterface $output)
 {
     define('FREQ_THRESHOLD', 10);
     define('SUGGEST_DEBUG', 0);
     $params = phrasea::sbas_params($this->container);
     foreach ($params as $sbas_id => $p) {
         $index = sprintf("%u", crc32(str_replace(['.', '%'], '_', sprintf('%s_%s_%s_%s', $p['host'], $p['port'], $p['user'], $p['dbname']))));
         $tmp_file = $this->container['root.path'] . '/tmp/dict' . $index . '.txt';
         $databox = $this->getService('phraseanet.appbox')->get_databox($sbas_id);
         $output->writeln("process Databox " . $databox->get_label($this->container['locale']) . " / {$index}\n");
         if (!is_executable("/usr/local/bin/indexer")) {
             $output->writeln("<error>'/usr/local/bin/indexer' is not executable</error>");
             return 1;
         }
         $builder = ProcessBuilder::create(['/usr/local/bin/indexer']);
         $builder->add('metadatas' . $index)->add('--buildstops')->add($tmp_file)->add(1000000)->add('--buildfreqs');
         $builder->getProcess()->run();
         if (!file_exists($tmp_file)) {
             $output->writeln("<error> file '" . $tmp_file . "' does not exist</error>");
             return 1;
         }
         try {
             $connbas = $databox->get_connection()->connect();
         } catch (\Exception $e) {
             continue;
         }
         $sql = 'TRUNCATE suggest';
         $stmt = $connbas->prepare($sql);
         $stmt->execute();
         $stmt->closeCursor();
         $sql = $this->BuildDictionarySQL($output, file_get_contents($tmp_file));
         if (trim($sql) !== '') {
             $stmt = $connbas->prepare($sql);
             $stmt->execute();
             $stmt->closeCursor();
         }
         unlink($tmp_file);
     }
     return 0;
 }
コード例 #13
0
ファイル: question.php プロジェクト: luisbrito/Phraseanet
 public function colFilter($field, $on = false)
 {
     $ret = [];
     $sqlBuilder = $this->sqlBuilder('question');
     $var = $sqlBuilder->sqlDistinctValByField($field);
     $sql = $var['sql'];
     $params = $var['params'];
     $stmt = $sqlBuilder->getConnBas()->prepare($sql);
     $stmt->execute($params);
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     foreach ($rs as $row) {
         $value = $row['val'];
         if ($field == 'appli') {
             $caption = implode(' ', phrasea::modulesName($this->app['translator'], @unserialize($row['val'])));
         } elseif ($field == "ddate") {
             $caption = $this->app['date-formatter']->getPrettyString(new DateTime($value));
         } else {
             $caption = $row['val'];
         }
         $ret[] = ['val' => $caption, 'value' => $value];
     }
     return $ret;
 }
コード例 #14
0
ファイル: Xmlhttp.php プロジェクト: romainneutron/Phraseanet
 public function SearchTermJson(Application $app, Request $request)
 {
     if (null === ($lng = $request->get('lng'))) {
         $data = explode('_', $app['locale']);
         if (count($data) > 0) {
             $lng = $data[0];
         }
     }
     $html = '';
     $sbid = (int) $request->get('sbid');
     try {
         $databox = $app['phraseanet.appbox']->get_databox($sbid);
         $html = "" . '<LI id="TX_P.' . $sbid . '.T" class="expandable">' . "\n";
         $html .= "\t" . '<div class="hitarea expandable-hitarea"></div>' . "\n";
         $html .= "\t" . '<span>' . \phrasea::sbas_labels($sbid, $app) . '</span>' . "\n";
         if ($request->get('t')) {
             if ($request->get('field') != '') {
                 $domth = $databox->get_dom_thesaurus();
                 $dom_struct = $databox->get_dom_structure();
             } else {
                 $domth = $databox->get_dom_thesaurus();
             }
             $q = null;
             if ($request->get('field') != '') {
                 // search only in the branch(es) linked to this field
                 if ($dom_struct) {
                     $xpath = new \DOMXPath($dom_struct);
                     if ($znode = $xpath->query('/record/description/' . $request->get('field'))->item(0)) {
                         $q = '(' . $znode->getAttribute('tbranch') . ')';
                     }
                 }
             } else {
                 // search in the whole thesaurus
                 $q = '/thesaurus';
             }
             if ($q !== null && $domth) {
                 $xpath = new \DOMXPath($domth);
                 $t = $this->splitTermAndContext($request->get('t'));
                 $q2 = 'starts-with(@w, \'' . \thesaurus::xquery_escape($app['unicode']->remove_indexer_chars($t[0])) . '\')';
                 if ($t[1]) {
                     $q2 .= ' and starts-with(@k, \'' . \thesaurus::xquery_escape($app['unicode']->remove_indexer_chars($t[1])) . '\')';
                 }
                 $q2 = '//sy[' . $q2 . ' and @lng=\'' . $lng . '\']';
                 $q .= $q2;
                 $nodes = $xpath->query($q);
                 for ($i = 0; $i < $nodes->length; $i++) {
                     $nodes->item($i)->setAttribute('bold', '1');
                     for ($n = $nodes->item($i)->parentNode; $n && $n->nodeType == XML_ELEMENT_NODE && $n->nodeName == 'te'; $n = $n->parentNode) {
                         $n->setAttribute('open', '1');
                     }
                 }
                 $this->getHTMLTerm($sbid, $lng, $domth->documentElement, $html);
             }
         } else {
             $html .= "\t" . '<ul style="display: none;">loading</ul>' . "\n";
         }
         $html .= "" . '</LI>' . "\n";
     } catch (\Exception $e) {
     }
     return $app->json(['parm' => ['sbid' => $request->get('sbid'), 't' => $request->get('t'), 'field' => $request->get('field'), 'lng' => $request->get('lng'), 'debug' => $request->get('debug')], 'html' => $html]);
 }
コード例 #15
0
ファイル: exportElement.php プロジェクト: nlegoff/Phraseanet
 /**
  *
  * @return record_exportElement
  */
 protected function get_actions()
 {
     $this->downloadable = $downloadable = [];
     $this->orderable = $orderable = [];
     $sd = $this->get_subdefs();
     $sbas_id = phrasea::sbasFromBas($this->app, $this->base_id);
     $subdefgroups = $this->app['phraseanet.appbox']->get_databox($sbas_id)->get_subdef_structure();
     $subdefs = [];
     foreach ($subdefgroups as $subdef_type => $subdefs_obj) {
         if ($subdef_type == $this->get_type()) {
             $subdefs = $subdefs_obj;
             break;
         }
     }
     $go_dl = ['document' => false, 'preview' => false, 'thumbnail' => true];
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->get_base_id(), 'candwnldhd')) {
         $go_dl['document'] = true;
     }
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->get_base_id(), 'candwnldpreview')) {
         $go_dl['preview'] = true;
     }
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_hd_grant($this)) {
         $go_dl['document'] = true;
         $go_dl['preview'] = true;
     }
     if ($this->app['acl']->get($this->app['authentication']->getUser())->has_preview_grant($this)) {
         $go_dl['preview'] = true;
     }
     $query = $this->app['phraseanet.user-query'];
     $masters = $query->on_base_ids([$this->base_id])->who_have_right(['order_master'])->execute()->get_results();
     $go_cmd = count($masters) > 0 && $this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($this->base_id, 'cancmd');
     $orderable['document'] = false;
     $downloadable['document'] = false;
     if (isset($sd['document']) && is_file($sd['document']->get_pathfile())) {
         if ($go_dl['document'] === true) {
             if ($this->app['acl']->get($this->app['authentication']->getUser())->is_restricted_download($this->base_id)) {
                 $this->remain_hd--;
                 if ($this->remain_hd >= 0) {
                     $localizedLabel = $this->app->trans('document original');
                     $downloadable['document'] = ['class' => 'document', 'label' => $localizedLabel];
                 }
             } else {
                 $localizedLabel = $this->app->trans('document original');
                 $downloadable['document'] = ['class' => 'document', 'label' => $localizedLabel];
             }
         }
         if ($go_cmd === true) {
             $orderable['document'] = true;
         }
         $this->add_count('document', $sd['document']->get_size());
     }
     foreach ($subdefs as $subdef) {
         $name = $subdef->get_name();
         $class = $subdef->get_class();
         $subdef_label = $name;
         foreach ($subdef->get_labels() as $lang => $label) {
             if (trim($label) == '') {
                 continue;
             }
             if ($lang == $this->app['locale']) {
                 $subdef_label = $label;
                 break;
             }
             $subdef_label = $label;
         }
         $downloadable[$name] = false;
         $downloadable_settings = $subdef->is_downloadable();
         if (!$downloadable_settings || $go_dl[$class] === false) {
             continue;
         }
         if ($go_dl[$class]) {
             if (isset($sd[$name]) && $sd[$name]->is_physically_present()) {
                 if ($class == 'document') {
                     if ($this->app['acl']->get($this->app['authentication']->getUser())->is_restricted_download($this->base_id)) {
                         $this->remain_hd--;
                         if ($this->remain_hd >= 0) {
                             $downloadable[$name] = ['class' => $class, 'label' => $subdef_label];
                         }
                     } else {
                         $downloadable[$name] = ['class' => $class, 'label' => $subdef_label];
                     }
                 } else {
                     $downloadable[$name] = ['class' => $class, 'label' => $subdef_label];
                 }
                 $this->add_count($name, $sd[$name]->get_size());
             }
         }
     }
     $xml = $this->app['serializer.caption']->serialize($this->get_caption(), CaptionSerializer::SERIALIZE_XML);
     if ($xml) {
         $localizedLabel = $this->app->trans('caption XML');
         $downloadable['caption'] = ['class' => 'caption', 'label' => $localizedLabel];
         $this->add_count('caption', strlen($xml));
         $localizedLabel = $this->app->trans('caption YAML');
         $downloadable['caption-yaml'] = ['class' => 'caption', 'label' => $localizedLabel];
         $this->add_count('caption-yaml', strlen(strip_tags($xml)));
     }
     $this->downloadable = $downloadable;
     $this->orderable = $orderable;
     return $this;
 }
コード例 #16
0
ファイル: Thesaurus.php プロジェクト: nlegoff/Phraseanet
 public function loadThesaurus(Application $app, Request $request)
 {
     if (null === $request->get("bid")) {
         return new Response('Missing bid parameter', 400);
     }
     $updated = false;
     $validThesaurus = true;
     $ctlist = [];
     $name = \phrasea::sbas_labels($request->get('bid'), $app);
     try {
         $databox = $app['phraseanet.appbox']->get_databox((int) $request->get('bid'));
         $connbas = $databox->get_connection();
         $domct = $databox->get_dom_cterms();
         $domth = $databox->get_dom_thesaurus();
         $now = date("YmdHis");
         if (!$domct && $request->get('repair') == 'on') {
             $domct = new \DOMDocument();
             $domct->load(__DIR__ . "/../../../../conf.d/blank_cterms.xml");
             $domct->documentElement->setAttribute("creation_date", $now);
             $databox->saveCterms($domct);
         }
         if (!$domth && $request->get('repair') == 'on') {
             $domth = new \DOMDocument();
             $domth->load(__DIR__ . "/../../../../conf.d/blank_thesaurus.xml");
             $domth->documentElement->setAttribute("creation_date", $now);
             $databox->saveThesaurus($domth);
         }
         if ($domct && $domth) {
             $oldversion = $domth->documentElement->getAttribute("version");
             if ($this->fixThesaurus($app, $domct, $domth, $connbas) != $oldversion) {
                 $updated = true;
                 $databox->saveCterms($domct);
                 $databox->saveThesaurus($domth);
             }
             for ($ct = $domct->documentElement->firstChild; $ct; $ct = $ct->nextSibling) {
                 if ($ct->nodeName == "te") {
                     $ctlist[] = ['id' => $ct->getAttribute("id"), 'field' => $ct->getAttribute("field")];
                 }
             }
         } else {
             $validThesaurus = false;
         }
     } catch (\Exception $e) {
     }
     return $app['twig']->render('thesaurus/load-thesaurus.html.twig', ['bid' => $request->get('bid'), 'name' => $name, 'cterms' => $ctlist, 'valid_thesaurus' => $validThesaurus, 'updated' => $updated]);
 }
コード例 #17
0
ファイル: nav.php プロジェクト: romainneutron/Phraseanet
 /**
  * Return basic information about a record
  *
  * @param integer $bid base id
  * @param integer $rid record id
  * @param array   $tab config for the html table
  *
  * @return array
  */
 public function buildTabUserWhat($bid, $rid, $tab = false)
 {
     $this->initialize();
     $sbas_id = phrasea::sbasFromBas($this->app, $bid);
     try {
         $record = new record_adapter($this->app, $sbas_id, $rid);
     } catch (\Exception_Record_AdapterNotFound $e) {
         return $this->report;
     }
     $this->setDisplay($tab);
     $this->champ = ['photo', 'record_id', 'date', 'type', 'titre', 'taille'];
     $document = $record->get_subdef('document');
     $this->title = $this->app->trans('report:: Information sur l\'enregistrement numero %number%', ['%number%' => (int) $rid]);
     $x = $record->get_thumbnail();
     $this->result[] = ['photo' => "<img style='width:" . $x->get_width() . "px;height:" . $x->get_height() . "px;'\n                        src='" . $x->get_url() . "'>", 'record_id' => $record->get_record_id(), 'date' => $this->app['date-formatter']->getPrettyString($document->get_creation_date()), 'type' => $document->get_mime(), 'titre' => $record->get_title(), 'taille' => $document->get_size()];
     $this->setDisplayNav();
     $this->setReport();
     return $this->report;
 }
コード例 #18
0
ファイル: Edit.php プロジェクト: luisbrito/Phraseanet
 public function apply_rights()
 {
     $ACL = $this->app->getAclForUser($this->app->getAuthenticatedUser());
     $base_ids = array_keys($ACL->get_granted_base(['canadmin']));
     $update = $create = $delete = $create_sbas = $update_sbas = [];
     foreach ($base_ids as $base_id) {
         $rights = ['access', 'actif', 'canputinalbum', 'nowatermark', 'candwnldpreview', 'candwnldhd', 'cancmd', 'canaddrecord', 'canmodifrecord', 'chgstatus', 'candeleterecord', 'imgtools', 'canadmin', 'canreport', 'canpush', 'manage', 'modify_struct'];
         foreach ($rights as $k => $right) {
             if ($right == 'access' && !$ACL->has_access_to_base($base_id) || $right != 'access' && !$ACL->has_right_on_base($base_id, $right)) {
                 unset($rights[$k]);
                 continue;
             }
             $rights[$k] = $right . '_' . $base_id;
         }
         $parm = $this->unserializedRequestData($this->app['request'], $rights, 'values');
         foreach ($parm as $p => $v) {
             if (trim($v) == '') {
                 continue;
             }
             $serial = explode('_', $p);
             $base_id = array_pop($serial);
             $p = implode('_', $serial);
             if ($p == 'access') {
                 if ($v === '1') {
                     $create_sbas[\phrasea::sbasFromBas($this->app, $base_id)] = \phrasea::sbasFromBas($this->app, $base_id);
                     $create[] = $base_id;
                 } else {
                     $delete[] = $base_id;
                 }
             } else {
                 $create_sbas[\phrasea::sbasFromBas($this->app, $base_id)] = \phrasea::sbasFromBas($this->app, $base_id);
                 $update[$base_id][$p] = $v;
             }
         }
     }
     $sbas_ids = $ACL->get_granted_sbas();
     foreach ($sbas_ids as $databox) {
         $rights = ['bas_modif_th', 'bas_manage', 'bas_modify_struct', 'bas_chupub'];
         foreach ($rights as $k => $right) {
             if (!$ACL->has_right_on_sbas($databox->get_sbas_id(), $right)) {
                 unset($rights[$k]);
                 continue;
             }
             $rights[$k] = $right . '_' . $databox->get_sbas_id();
         }
         $parm = $this->unserializedRequestData($this->app['request'], $rights, 'values');
         foreach ($parm as $p => $v) {
             if (trim($v) == '') {
                 continue;
             }
             $serial = explode('_', $p);
             $sbas_id = array_pop($serial);
             $p = implode('_', $serial);
             $update_sbas[$sbas_id][$p] = $v;
         }
     }
     foreach ($this->users as $usr_id) {
         try {
             $this->app->getApplicationBox()->get_connection()->beginTransaction();
             $user = $this->app['repo.users']->find($usr_id);
             $this->app->getAclForUser($user)->revoke_access_from_bases($delete)->give_access_to_base($create)->give_access_to_sbas($create_sbas);
             foreach ($update as $base_id => $rights) {
                 $this->app->getAclForUser($user)->update_rights_to_base($base_id, $rights);
             }
             foreach ($update_sbas as $sbas_id => $rights) {
                 $this->app->getAclForUser($user)->update_rights_to_sbas($sbas_id, $rights);
             }
             $this->app->getApplicationBox()->get_connection()->commit();
             $this->app->getAclForUser($user)->revoke_unused_sbas_rights();
             unset($user);
         } catch (\Exception $e) {
             $this->app->getApplicationBox()->get_connection()->rollBack();
         }
     }
     return $this;
 }
コード例 #19
0
ファイル: download.php プロジェクト: nlegoff/Phraseanet
 private function formatCollId($value)
 {
     return phrasea::bas_labels(phrasea::baseFromColl($this->sbas_id, $value, $this->app), $this->app);
 }
コード例 #20
0
ファイル: base.php プロジェクト: romainneutron/Phraseanet
 public function delete_data_from_cache($option = null)
 {
     $appbox = $this->get_base_type() == self::APPLICATION_BOX ? $this : $this->get_appbox();
     if ($option === appbox::CACHE_LIST_BASES) {
         $keys = [$this->get_cache_key(appbox::CACHE_LIST_BASES)];
         phrasea::reset_sbasDatas($appbox);
         phrasea::reset_baseDatas($appbox);
         phrasea::clear_sbas_params($this->app);
         $keys[] = $this->get_cache_key(appbox::CACHE_SBAS_IDS);
         return $this->get_cache()->deleteMulti($keys);
     }
     if (is_array($option)) {
         foreach ($option as $key => $value) {
             $option[$key] = $this->get_cache_key($value);
         }
         return $this->get_cache()->deleteMulti($option);
     } else {
         return $this->get_cache()->delete($this->get_cache_key($option));
     }
 }
コード例 #21
0
ファイル: connexion.php プロジェクト: luisbrito/Phraseanet
 /**
  * @desc build the result from the specified sql
  * @param  array         $champ all the field from the request displayed in a array
  * @param  string        $sql   the request from buildreq
  * @return $this->result
  */
 protected function buildResult(Application $app, $rs)
 {
     $i = 0;
     foreach ($rs as $row) {
         if ($this->enable_limit && $i > $this->nb_record) {
             break;
         }
         foreach ($this->champ as $key => $value) {
             if (!isset($row[$value])) {
                 $this->result[$i][$value] = '<i>' . $this->app->trans('report:: non-renseigne') . '</i>';
                 continue;
             }
             if ($value == 'appli') {
                 $applis = false;
                 if (($applis = @unserialize($row[$value])) !== false) {
                     if (empty($applis)) {
                         $this->result[$i][$value] = '<i>' . $this->app->trans('report:: non-renseigne') . '</i>';
                     } else {
                         $this->result[$i][$value] = implode(' ', phrasea::modulesName($this->app['translator'], $applis));
                     }
                 } else {
                     $this->result[$i][$value] = '<i>' . $this->app->trans('report:: non-renseigne') . '</i>';
                 }
             } elseif ($value == 'ddate') {
                 $this->result[$i][$value] = $this->pretty_string ? $this->app['date-formatter']->getPrettyString(new DateTime($row[$value])) : $row[$value];
             } else {
                 $this->result[$i][$value] = $row[$value];
             }
         }
         $i++;
     }
 }
コード例 #22
0
ファイル: PDF.php プロジェクト: luisbrito/Phraseanet
 protected function print_preview($withtdm, $write_caption)
 {
     if ($withtdm === true) {
         $this->print_thumbnailGrid($this->pdf, $this->records, true);
     }
     foreach ($this->records as $krec => $rec) {
         /* @var $rec record_adapter */
         $this->pdf->AddPage();
         if ($withtdm === "CALCPAGES") {
             $rec->setNumber($this->pdf->PageNo());
         }
         $lmargin = $this->pdf->GetX();
         $himg = 0;
         $y = 0;
         $miniConv = NULL;
         $LEFT__TEXT = "";
         $LEFT__IMG = NULL;
         $RIGHT_TEXT = "";
         $RIGHT_IMG = NULL;
         $LEFT__IMG = $this->app['root.path'] . "/config/minilogos/logopdf_" . $rec->get_sbas_id() . ".jpg";
         if (!is_file($LEFT__IMG)) {
             $databox = $rec->get_databox();
             $str = $databox->get_sxml_structure();
             $vn = (string) $str->pdfPrintLogo;
             if ($vn * 1 == 1) {
                 $LEFT__TEXT = $databox->get_label($this->app['locale']);
             }
         }
         $collection = \collection::get_from_base_id($this->app, $rec->get_base_id());
         $vn = "";
         if (false !== ($str = simplexml_load_string($collection->get_prefs()))) {
             $vn = (string) $str->pdfPrintappear;
         }
         if ($vn == "" || $vn == "1") {
             $RIGHT_TEXT = \phrasea::bas_labels($rec->get_base_id(), $this->app);
         } elseif ($vn == "2") {
             $RIGHT_IMG = $this->app['root.path'] . "/config/minilogos/" . $rec->get_base_id();
         }
         $xtmp = $this->pdf->GetX();
         $ytmp = $this->pdf->GetY();
         $this->pdf->SetFont(PhraseaPDF::FONT, '', 12);
         $this->pdf->SetFillColor(220, 220, 220);
         $y = $this->pdf->GetY();
         $this->pdf->MultiCell(95, 7, $LEFT__TEXT, "LTB", "L", 1);
         $y2 = $this->pdf->GetY();
         $h = $y2 - $y;
         $this->pdf->SetY($y);
         $this->pdf->SetX(105);
         $this->pdf->Cell(95, $h, $RIGHT_TEXT, "TBR", 1, "R", 1);
         if ($LEFT__TEXT == "" && is_file($LEFT__IMG)) {
             if ($size = @getimagesize($LEFT__IMG)) {
                 $wmm = (int) $size[0] * 25.4 / 72;
                 $hmm = (int) $size[1] * 25.4 / 72;
                 if ($hmm > 6) {
                     $coeff = $hmm / 6;
                     $wmm = (int) $wmm / $coeff;
                     $hmm = (int) $hmm / $coeff;
                 }
                 $this->pdf->Image($LEFT__IMG, $xtmp + 0.5, $ytmp + 0.5, $wmm, $hmm);
             }
         }
         if ($RIGHT_IMG != NULL && is_file($RIGHT_IMG)) {
             if ($size = @getimagesize($RIGHT_IMG)) {
                 if ($size[2] == '1') {
                     if (!isset($miniConv[$RIGHT_IMG])) {
                         $tmp_filename = tempnam('minilogos/', 'gif4fpdf');
                         $img = imagecreatefromgif($RIGHT_IMG);
                         imageinterlace($img, 0);
                         imagepng($img, $tmp_filename);
                         rename($tmp_filename, $tmp_filename . '.png');
                         $miniConv[$RIGHT_IMG] = $tmp_filename . '.png';
                         $RIGHT_IMG = $tmp_filename . '.png';
                     } else {
                         $RIGHT_IMG = $miniConv[$RIGHT_IMG];
                     }
                     $wmm = (int) $size[0] * 25.4 / 72;
                     $hmm = (int) $size[1] * 25.4 / 72;
                     if ($hmm > 6) {
                         $coeff = $hmm / 6;
                         $wmm = (int) $wmm / $coeff;
                         $hmm = (int) $hmm / $coeff;
                     }
                     $tt = 0;
                     if ($hmm < 6) {
                         $tt = (6 - $hmm) / 2;
                     }
                     $this->pdf->Image($RIGHT_IMG, 200 - 0.5 - $wmm, $ytmp + 0.5 + $tt);
                 } else {
                     $wmm = (int) $size[0] * 25.4 / 72;
                     $hmm = (int) $size[1] * 25.4 / 72;
                     if ($hmm > 6) {
                         $coeff = $hmm / 6;
                         $wmm = (int) $wmm / $coeff;
                         $hmm = (int) $hmm / $coeff;
                     }
                     $this->pdf->Image($RIGHT_IMG, 200 - 0.5 - $wmm, $ytmp + 0.5);
                 }
             }
         }
         $y = $this->pdf->GetY() + 5;
         $subdef = $rec->get_subdef('preview');
         if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
             $subdef = $rec->get_thumbnail();
         }
         $f = $subdef->get_pathfile();
         if (!$this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($rec->get_base_id(), "nowatermark") && $subdef->get_type() == \media_subdef::TYPE_IMAGE) {
             $f = \recordutils_image::watermark($this->app, $subdef);
         }
         // original height / original width x new width = new height
         $wimg = $himg = 150;
         // preview dans un carre de 150 mm
         // 1px = 3.77952 mm
         $finalWidth = round($subdef->get_width() / 3.779528, 2);
         $finalHeight = round($subdef->get_height() / 3.779528, 2);
         $aspectH = $finalWidth / $finalHeight;
         $aspectW = $finalHeight / $finalWidth;
         if ($finalWidth > 0 && $finalHeight > 0) {
             if ($finalWidth > $finalHeight && $finalWidth > $wimg) {
                 $finalWidth = $wimg;
                 $finalHeight = $wimg * $aspectW;
             } else {
                 if ($finalHeight > $finalWidth && $finalHeight > $himg) {
                     $finalHeight = $himg;
                     $finalWidth = $himg * $aspectH;
                 } else {
                     if ($finalHeight == $finalWidth & $finalWidth > $wimg) {
                         $finalHeight = $wimg;
                         $finalWidth = $himg;
                     }
                 }
             }
         }
         $this->pdf->Image($f, (210 - $finalWidth) / 2, $y, $finalWidth, $finalHeight);
         if ($miniConv != NULL) {
             foreach ($miniConv as $oneF) {
                 unlink($oneF);
             }
         }
         $this->pdf->SetXY($lmargin, $y += $finalHeight + 5);
         $nf = 0;
         if ($write_caption) {
             foreach ($rec->get_caption()->get_fields() as $field) {
                 /* @var $field caption_field */
                 if ($nf > 0) {
                     $this->pdf->Write(6, "\n");
                 }
                 $this->pdf->SetFont(PhraseaPDF::FONT, 'B', 12);
                 $this->pdf->Write(5, $field->get_name() . " : ");
                 $this->pdf->SetFont(PhraseaPDF::FONT, '', 12);
                 $t = str_replace(["&lt;", "&gt;", "&amp;"], ["<", ">", "&"], strip_tags($field->get_serialized_values()));
                 $this->pdf->Write(5, $t);
                 $nf++;
             }
         }
     }
     return;
 }
コード例 #23
0
ファイル: collection.php プロジェクト: nlegoff/Phraseanet
 public static function getLogo($base_id, Application $app, $printname = false)
 {
     $base_id_key = $base_id . '_' . ($printname ? '1' : '0');
     if (!isset(self::$_logos[$base_id_key])) {
         if (is_file($app['root.path'] . '/config/minilogos/' . $base_id)) {
             $name = phrasea::bas_labels($base_id, $app);
             self::$_logos[$base_id_key] = '<img title="' . $name . '" src="/custom/minilogos/' . $base_id . '" />';
         } elseif ($printname) {
             self::$_logos[$base_id_key] = phrasea::bas_labels($base_id, $app);
         }
     }
     return isset(self::$_logos[$base_id_key]) ? self::$_logos[$base_id_key] : '';
 }
コード例 #24
0
ファイル: phrasea.php プロジェクト: luisbrito/Phraseanet
 public static function bas_labels($base_id, Application $app)
 {
     if (!self::$_bas_labels) {
         try {
             self::$_bas_labels = $app->getApplicationBox()->get_data_from_cache(self::CACHE_BAS_LABELS);
         } catch (\Exception $e) {
             foreach ($app->getDataboxes() as $databox) {
                 foreach ($databox->get_collections() as $collection) {
                     self::$_bas_labels[$collection->get_base_id()] = ['fr' => $collection->get_label('fr'), 'en' => $collection->get_label('en'), 'de' => $collection->get_label('de'), 'nl' => $collection->get_label('nl')];
                 }
             }
             $app->getApplicationBox()->set_data_to_cache(self::$_bas_labels, self::CACHE_BAS_LABELS);
         }
     }
     if (isset(self::$_bas_labels[$base_id]) && isset(self::$_bas_labels[$base_id][$app['locale']])) {
         return self::$_bas_labels[$base_id][$app['locale']];
     }
     return 'Unknown collection';
 }
コード例 #25
0
ファイル: ArchiveJob.php プロジェクト: luisbrito/Phraseanet
 /**
  * {@inheritdoc}
  */
 protected function doJob(JobData $data)
 {
     $app = $data->getApplication();
     $task = $data->getTask();
     $settings = simplexml_load_string($task->getSettings());
     $baseId = (string) $settings->base_id;
     $sbasId = \phrasea::sbasFromBas($app, $baseId);
     if (!$sbasId) {
         throw new RuntimeException('Invalid collection base_id.');
     }
     $databox = $app->findDataboxById($sbasId);
     $TColls = [];
     $collection = null;
     foreach ($databox->get_collections() as $coll) {
         $TColls['c' . $coll->get_coll_id()] = $coll->get_coll_id();
         if ($baseId == $coll->get_base_id()) {
             $collection = $coll;
         }
     }
     $server_coll_id = $collection->get_coll_id();
     // mask(s) of accepted files
     $tmask = [];
     $tmaskgrp = [];
     $cold = min(max((int) $settings->cold, self::MINCOLD), self::MAXCOLD);
     $stat0 = $stat1 = "0";
     if (false !== ($sxBasePrefs = simplexml_load_string($collection->get_prefs()))) {
         if ($sxBasePrefs->status) {
             $stat0 = (string) $sxBasePrefs->status;
         }
     }
     if ($settings->status) {
         $stat1 = (string) $settings->status;
     }
     if (!$stat0) {
         $stat0 = '0';
     }
     if (!$stat1) {
         $stat1 = '0';
     }
     // check the data-repository exists
     $pathhd = (string) $settings->path;
     if ($pathhd) {
         $app['filesystem']->mkdir($pathhd, 0750);
     }
     // load masks
     if ($settings->files && $settings->files->file) {
         foreach ($settings->files->file as $ft) {
             $tmask[] = ["mask" => (string) $ft["mask"], "caption" => (string) $ft["caption"], "accept" => (string) $ft["accept"]];
         }
     }
     if ($settings->files && $settings->files->grouping) {
         foreach ($settings->files->grouping as $ft) {
             $tmaskgrp[] = ["mask" => (string) $ft["mask"], "caption" => (string) $ft["caption"], "representation" => (string) $ft["representation"], "accept" => (string) $ft["accept"]];
         }
     }
     if (count($tmask) == 0) {
         // no mask defined : accept all kind of files
         $tmask[] = ["mask" => ".*", "caption" => "", "accept" => ""];
     }
     while ($this->isStarted()) {
         $path_in = (string) $settings->hotfolder;
         if (!@is_dir($path_in)) {
             throw new RuntimeException(sprintf('Error : missing hotfolder \'%s\', stopping.', $path_in));
         }
         // copy settings to task, so it's easier to get later
         $moveArchived = \p4field::isyes($settings->move_archived);
         $moveError = \p4field::isyes($settings->move_error);
         clearstatcache();
         if (false === $app['filesystem']->exists($path_in . "/.phrasea.xml")) {
             throw new RuntimeException(sprintf('NO .phrasea.xml AT ROOT \'%s\' !', $path_in));
         }
         $path_archived = $path_error = null;
         if ($moveArchived) {
             $path_archived = $path_in . '_archived';
             $app['filesystem']->mkdir($path_archived, 0755);
         }
         if ($moveError) {
             $path_error = $path_in . '_error';
             $app['filesystem']->mkdir($path_error, 0755);
         }
         $dom = new \DOMDocument();
         $dom->formatOutput = true;
         $root = $dom->appendChild($dom->createElement('root'));
         $nnew = $this->listFilesPhase1($app, $dom, $root, $path_in, $server_coll_id, 0, $TColls);
         if ($app['debug']) {
             $this->log('debug', "=========== listFilesPhase1 ========== (returned " . $nnew . ")\n" . $dom->saveXML());
         }
         if (!$this->isStarted()) {
             return;
         }
         // wait for files to be cold
         $this->pause($cold);
         if (!$this->isStarted()) {
             return;
         }
         $this->listFilesPhase2($app, $dom, $root, $path_in, 0);
         if ($app['debug']) {
             $this->log('debug', "=========== listFilesPhase2 ========== : \n" . $dom->saveXML());
         }
         if (!$this->isStarted()) {
             return;
         }
         $this->makePairs($dom, $root, $path_in, $path_archived, $path_error, false, 0, $tmask, $tmaskgrp);
         if ($app['debug']) {
             $this->log('debug', "=========== makePairs ========== : \n" . $dom->saveXML());
         }
         $r = $this->removeBadGroups($app, $dom, $root, $path_in, $path_archived, $path_error, 0, $moveError);
         if ($app['debug']) {
             $this->log('debug', "=========== removeBadGroups ========== (returned " . ((bool) $r ? 'true' : 'false') . ") : \n" . $dom->saveXML());
         }
         $this->archive($app, $databox, $dom, $root, $path_in, $path_archived, $path_error, 0, $moveError, $moveArchived, $stat0, $stat1);
         if ($app['debug']) {
             $this->log('debug', "=========== archive ========== : \n" . $dom->saveXML());
         }
         if (!$this->isStarted()) {
             return;
         }
         $this->bubbleResults($dom, $root, $path_in, 0, \p4field::isyes($settings->copy_spe));
         if ($app['debug']) {
             $this->log('debug', "=========== bubbleResults ========== : \n" . $dom->saveXML());
         }
         $moved = $this->moveFiles($app, $dom, $root, $path_in, $path_archived, $path_error, 0, $moveArchived, $moveError);
         if ($app['debug']) {
             $this->log('debug', "=========== moveFiles ========== (returned " . ($moved ? 'true' : 'false') . ") : \n" . $dom->saveXML());
         }
     }
 }
コード例 #26
0
ファイル: databox.php プロジェクト: romainneutron/Phraseanet
 /**
  *
  * @param  Application $app
  * @param  string      $host
  * @param  int         $port
  * @param  string      $user
  * @param  string      $password
  * @param  string      $dbname
  * @param  registry    $registry
  * @return databox
  */
 public static function mount(Application $app, $host, $port, $user, $password, $dbname)
 {
     $conn = $app['dbal.provider']->get(['host' => $host, 'port' => $port, 'user' => $user, 'password' => $password, 'dbname' => $dbname]);
     $conn->connect();
     $conn = $app['phraseanet.appbox']->get_connection();
     $sql = 'SELECT MAX(ord) as ord FROM sbas';
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     if ($row) {
         $ord = $row['ord'] + 1;
     }
     $sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd)
           VALUES (null, :ord, :host, :port, :dbname, "MYSQL", :user, :password)';
     $stmt = $conn->prepare($sql);
     $stmt->execute([':ord' => $ord, ':host' => $host, ':port' => $port, ':dbname' => $dbname, ':user' => $user, ':password' => $password]);
     $stmt->closeCursor();
     $sbas_id = (int) $conn->lastInsertId();
     $app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
     $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
     $databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
     $app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_SBAS_IDS);
     phrasea::reset_sbasDatas($app['phraseanet.appbox']);
     cache_databox::update($app, $databox->get_sbas_id(), 'structure');
     return $databox;
 }
コード例 #27
0
ファイル: sqlfilter.php プロジェクト: luisbrito/Phraseanet
 private function recordFilter(module_report $report)
 {
     $this->filter['record'] = false;
     $dl_coll_filter = $params = [];
     $n = 0;
     if ($report->getUserId() != '') {
         $tab = explode(",", $report->getListCollId());
         foreach ($tab as $val) {
             $dl_coll_filter[] = "record.coll_id = :record_fil" . $n;
             $params[":record_fil" . $n] = phrasea::collFromBas($this->app, $val);
             $n++;
         }
         if (count($dl_coll_filter) > 0) {
             $this->filter['record'] = array('sql' => implode(' OR ', $dl_coll_filter), 'params' => $params);
         }
     }
     return;
 }
コード例 #28
0
ファイル: 320alpha4b.php プロジェクト: luisbrito/Phraseanet
 /**
  * {@inheritdoc}
  */
 public function apply(base $appbox, Application $app)
 {
     try {
         $sql = 'ALTER TABLE `ssel` ADD `migrated` INT NOT NULL DEFAULT "0"';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute();
         $stmt->closeCursor();
     } catch (\Exception $e) {
     }
     $sql = 'SELECT ssel_id, usr_id, name, descript, pub_date, updater, pub_restrict, homelink
             FROM ssel
             WHERE (public = "1" OR homelink="1")
               AND migrated = 0';
     $stmt = $appbox->get_connection()->prepare($sql);
     $stmt->execute();
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $date_ref = new DateTime();
     $n = 0;
     $app['orm.em']->getEventManager()->removeEventSubscriber(new TimestampableListener());
     foreach ($rs as $row) {
         if (null === ($user = $this->loadUser($app['orm.em'], $row['usr_id']))) {
             continue;
         }
         $feed = $this->get_feed($app, $appbox, $user, $row['pub_restrict'], $row['homelink']);
         if (!$feed instanceof Feed) {
             continue;
         }
         $publishers = $feed->getPublishers();
         $entry = new FeedEntry();
         $entry->setAuthorEmail((string) $user->getEmail());
         $entry->setAuthorName((string) $user->getDisplayName());
         $entry->setFeed($feed);
         $entry->setPublisher($publishers->first());
         $entry->setTitle($row['name']);
         $entry->setSubtitle($row['descript']);
         $feed->addEntry($entry);
         $date_create = new DateTime($row['pub_date']);
         if ($date_create < $date_ref) {
             $date_ref = $date_create;
         }
         $entry->setCreatedOn($date_create);
         if ($row['updater'] != '0000-00-00 00:00:00') {
             $date_update = new DateTime($row['updater']);
             $entry->setUpdatedOn($date_update);
         }
         $sql = 'SELECT sselcont_id, ssel_id, base_id, record_id
                 FROM sselcont
                 WHERE ssel_id = :ssel_id
                 ORDER BY ord ASC';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute([':ssel_id' => $row['ssel_id']]);
         $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         foreach ($rs as $row) {
             try {
                 $record = new record_adapter($app, phrasea::sbasFromBas($app, $row['base_id']), $row['record_id']);
                 $item = new FeedItem();
                 $item->setEntry($entry);
                 $entry->addItem($item);
                 $item->setRecordId($record->get_record_id());
                 $item->setSbasId($record->get_sbas_id());
                 $app['orm.em']->persist($item);
             } catch (NotFoundHttpException $e) {
             }
         }
         $app['orm.em']->persist($entry);
         $sql = 'UPDATE ssel SET deleted = "1", migrated="1"
                 WHERE ssel_id = :ssel_id';
         $stmt = $appbox->get_connection()->prepare($sql);
         $stmt->execute([':ssel_id' => $row['ssel_id']]);
         $stmt->closeCursor();
         $app['orm.em']->persist($feed);
         $n++;
         if ($n % 1000 == 0) {
             $app['orm.em']->flush();
             $app['orm.em']->clear();
         }
     }
     $this->set_feed_dates($date_ref);
     $app['orm.em']->flush();
     $app['orm.em']->clear();
     $app['orm.em']->getEventManager()->removeEventSubscriber(new TimestampableListener());
     return true;
 }
コード例 #29
0
ファイル: ACL.php プロジェクト: nlegoff/Phraseanet
 /**
  * Apply a template on user
  *
  * @param  User  $template_user
  * @param  array $base_ids
  * @return ACL
  */
 public function apply_model(User $template_user, array $base_ids)
 {
     if (count($base_ids) == 0) {
         return $this;
     }
     $sbas_ids = [];
     foreach ($base_ids as $base_id) {
         $sbas_ids[] = phrasea::sbasFromBas($this->app, $base_id);
     }
     $sbas_ids = array_unique($sbas_ids);
     $sbas_rights = ['bas_manage', 'bas_modify_struct', 'bas_modif_th', 'bas_chupub'];
     $sbas_to_acces = [];
     $rights_to_give = [];
     foreach ($this->app['acl']->get($template_user)->get_granted_sbas() as $databox) {
         $sbas_id = $databox->get_sbas_id();
         if (!in_array($sbas_id, $sbas_ids)) {
             continue;
         }
         if (!$this->has_access_to_sbas($sbas_id)) {
             $sbas_to_acces[] = $sbas_id;
         }
         foreach ($sbas_rights as $right) {
             if ($this->app['acl']->get($template_user)->has_right_on_sbas($sbas_id, $right)) {
                 $rights_to_give[$sbas_id][$right] = '1';
             }
         }
     }
     $this->give_access_to_sbas($sbas_to_acces);
     foreach ($rights_to_give as $sbas_id => $rights) {
         $this->update_rights_to_sbas($sbas_id, $rights);
     }
     $bas_rights = ['canputinalbum', 'candwnldhd', 'candwnldpreview', 'cancmd', 'canadmin', 'actif', 'canreport', 'canpush', 'canaddrecord', 'canmodifrecord', 'candeleterecord', 'chgstatus', 'imgtools', 'manage', 'modify_struct', 'nowatermark', 'order_master'];
     $bas_to_acces = $masks_to_give = $rights_to_give = [];
     /**
      * map masks (and+xor) of template to masks to apply to user on base
      * (and_and, and_or, xor_and, xor_or)
      */
     $sbmap = ['00' => ['aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'], '01' => ['aa' => '1', 'ao' => '0', 'xa' => '1', 'xo' => '0'], '10' => ['aa' => '1', 'ao' => '1', 'xa' => '0', 'xo' => '0'], '11' => ['aa' => '1', 'ao' => '1', 'xa' => '1', 'xo' => '1']];
     foreach ($this->app['acl']->get($template_user)->get_granted_base() as $collection) {
         $base_id = $collection->get_base_id();
         if (!in_array($base_id, $base_ids)) {
             continue;
         }
         if (!$this->has_access_to_base($base_id)) {
             $bas_to_acces[] = $base_id;
         }
         foreach ($bas_rights as $right) {
             if ($this->app['acl']->get($template_user)->has_right_on_base($base_id, $right)) {
                 $rights_to_give[$base_id][$right] = '1';
             }
         }
         $mask_and = $this->app['acl']->get($template_user)->get_mask_and($base_id);
         $mask_xor = $this->app['acl']->get($template_user)->get_mask_xor($base_id);
         /**
          * apply sb is substractive
          */
         $mand = substr(str_repeat('0', 32) . decbin($mask_and), -32);
         $mxor = substr(str_repeat('0', 32) . decbin($mask_xor), -32);
         $m = ['aa' => '', 'ao' => '', 'xa' => '', 'xo' => ''];
         for ($i = 0; $i < 32; $i++) {
             $ax = $mand[$i] . $mxor[$i];
             foreach ($m as $k => $v) {
                 $m[$k] .= $sbmap[$ax][$k];
             }
         }
         $masks_to_give[$base_id] = ['aa' => $m['aa'], 'ao' => $m['ao'], 'xa' => $m['xa'], 'xo' => $m['xo']];
     }
     $this->give_access_to_base($bas_to_acces);
     foreach ($masks_to_give as $base_id => $mask) {
         $this->set_masks_on_base($base_id, $mask['aa'], $mask['ao'], $mask['xa'], $mask['xo']);
     }
     foreach ($rights_to_give as $base_id => $rights) {
         $this->update_rights_to_base($base_id, $rights);
     }
     $this->apply_template_time_limits($template_user, $base_ids);
     $this->user->setLastAppliedTemplate($template_user);
     return $this;
 }
コード例 #30
0
ファイル: adapter.php プロジェクト: romainneutron/Phraseanet
 /**
  *
  * @return Array : list of deleted files;
  */
 public function delete()
 {
     $connbas = $this->get_databox()->get_connection();
     $ftodel = [];
     foreach ($this->get_subdefs() as $subdef) {
         if (!$subdef->is_physically_present()) {
             continue;
         }
         $ftodel[] = $subdef->get_pathfile();
         $watermark = $subdef->get_path() . 'watermark_' . $subdef->get_file();
         if (file_exists($watermark)) {
             $ftodel[] = $watermark;
         }
         $stamp = $subdef->get_path() . 'stamp_' . $subdef->get_file();
         if (file_exists($stamp)) {
             $ftodel[] = $stamp;
         }
     }
     $origcoll = phrasea::collFromBas($this->app, $this->get_base_id());
     $xml = $this->app['serializer.caption']->serialize($this->get_caption(), CaptionSerializer::SERIALIZE_XML);
     $this->app['phraseanet.logger']($this->get_databox())->log($this, Session_Logger::EVENT_DELETE, $origcoll, $xml);
     $sql = "DELETE FROM record WHERE record_id = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM metadatas WHERE record_id = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM prop WHERE record_id = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM idx WHERE record_id = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM permalinks\n            WHERE subdef_id\n              IN (SELECT subdef_id FROM subdef WHERE record_id=:record_id)";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM subdef WHERE record_id = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM technical_datas WHERE record_id = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM thit WHERE record_id = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM regroup WHERE rid_parent = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $sql = "DELETE FROM regroup WHERE rid_child = :record_id";
     $stmt = $connbas->prepare($sql);
     $stmt->execute([':record_id' => $this->get_record_id()]);
     $stmt->closeCursor();
     $orderElementRepository = $this->app['EM']->getRepository('Phraseanet:OrderElement');
     /* @var $repository Alchemy\Phrasea\Model\Repositories\OrderElementRepository */
     foreach ($orderElementRepository->findBy(['recordId' => $this->get_record_id()]) as $order_element) {
         if ($order_element->getSbasId($this->app) == $this->get_sbas_id()) {
             $this->app['EM']->remove($order_element);
         }
     }
     $basketElementRepository = $this->app['EM']->getRepository('Phraseanet:BasketElement');
     /* @var $repository Alchemy\Phrasea\Model\Repositories\BasketElementRepository */
     foreach ($basketElementRepository->findElementsByRecord($this) as $basket_element) {
         $this->app['EM']->remove($basket_element);
     }
     $this->app['EM']->flush();
     $this->app['filesystem']->remove($ftodel);
     $this->delete_data_from_cache(self::CACHE_SUBDEFS);
     return array_keys($ftodel);
 }