コード例 #1
0
ファイル: Item.php プロジェクト: g4mr/configs
 /**
  * Gets item from array if it exists else return default value
  * @param string $item dot notation config_file.array.item
  * @param mixed $default value if it doesn't exist
  * @return mixed
  */
 public function get($key, $default = null)
 {
     if (!is_string($key) || empty($key)) {
         return $default;
     }
     //split string into array
     $item_pieces = explode('.', $key);
     //let igorw check if array item exists
     return igorw\get_in($this->data, $item_pieces, $default);
 }
コード例 #2
0
 public static function hydrate(array $hit, $position)
 {
     $data = $hit['_source'];
     $highlight = isset($hit['highlight']) ? $hit['highlight'] : [];
     // Strip field prefix
     $private_prefix = 'private_';
     $prefix = 'caption.';
     foreach ($highlight as $key => $value) {
         unset($highlight[$key]);
         if (substr($key, 0, strlen($private_prefix)) === $private_prefix) {
             $key = substr($key, strlen($private_prefix));
         }
         if (substr($key, 0, strlen($prefix)) == $prefix) {
             $key = substr($key, strlen($prefix));
         }
         $highlight[$key] = $value;
     }
     $record = new ElasticsearchRecord();
     $record->setPosition($position);
     $record->setBaseId(igorw\get_in($data, ['base_id'], 0));
     $record->setCollectionName(igorw\get_in($data, ['collection_name'], null));
     $record->setCollectionId(igorw\get_in($data, ['collection_id'], 0));
     $createdOn = igorw\get_in($data, ['created_on']);
     $record->setCreated($createdOn ? new \DateTime($createdOn) : $createdOn);
     $record->setDataboxId(igorw\get_in($data, ['databox_id'], 0));
     $record->setIsStory(igorw\get_in($data, ['record_type']) === 'story');
     $record->setMimeType(igorw\get_in($data, ['mime'], 'application/octet-stream'));
     $record->setOriginalName(igorw\get_in($data, ['original_name'], ''));
     $record->setRecordId(igorw\get_in($data, ['record_id'], 0));
     $record->setSha256(igorw\get_in($data, ['sha256'], ''));
     $record->setType(igorw\get_in($data, ['type'], 'unknown'));
     $updatedOn = igorw\get_in($data, ['updated_on']);
     $record->setUpdated($updatedOn ? new \DateTime($updatedOn) : $updatedOn);
     $record->setUuid(igorw\get_in($data, ['uuid'], ''));
     $record->setStatusBitField(igorw\get_in($data, ['flags_bitfield'], 0));
     $record->setTitles((array) igorw\get_in($data, ['title'], []));
     $record->setCaption((array) igorw\get_in($data, ['caption'], []));
     $record->setPrivateCaption((array) igorw\get_in($data, ['private_caption'], []));
     $record->setExif((array) igorw\get_in($data, ['exif'], []));
     $record->setSubdefs((array) igorw\get_in($data, ['subdefs'], []));
     $record->setFlags((array) igorw\get_in($data, ['flags'], []));
     $record->setHighlight((array) $highlight);
     return $record;
 }
コード例 #3
0
ファイル: Login.php プロジェクト: romainneutron/Phraseanet
 public function doRegistration(PhraseaApplication $app, Request $request)
 {
     if (!$app['registration.manager']->isRegistrationEnabled()) {
         $app->abort(404, 'Registration is disabled');
     }
     $form = $app->form(new PhraseaRegisterForm($app, $app['registration.optional-fields'], $app['registration.fields']));
     if ('POST' === $request->getMethod()) {
         $requestData = $request->request->all();
         // Remove geocompleter field for validation this field is added client side
         // with jquery geonames plugin
         if (isset($requestData['geonameid']) && isset($requestData['geonameid-completer'])) {
             unset($requestData['geonameid-completer']);
         }
         $form->bind($requestData);
         $data = $form->getData();
         $provider = null;
         if ($data['provider-id']) {
             try {
                 $provider = $this->findProvider($app, $data['provider-id']);
             } catch (NotFoundHttpException $e) {
                 $app->addFlash('error', $app->trans('You tried to register with an unknown provider'));
                 return $app->redirectPath('login_register');
             }
             try {
                 $token = $provider->getToken();
             } catch (NotAuthenticatedException $e) {
                 $app->addFlash('error', $app->trans('You tried to register with an unknown provider'));
                 return $app->redirectPath('login_register');
             }
             $userAuthProvider = $app['EM']->getRepository('Phraseanet:UsrAuthProvider')->findWithProviderAndId($token->getProvider()->getId(), $token->getId());
             if (null !== $userAuthProvider) {
                 $this->postAuthProcess($app, $userAuthProvider->getUser());
                 if (null !== ($redirect = $request->query->get('redirect'))) {
                     $redirection = '../' . $redirect;
                 } else {
                     $redirection = $app->path('prod');
                 }
                 return $app->redirect($redirection);
             }
         }
         try {
             if ($form->isValid()) {
                 $captcha = $app['recaptcha']->bind($request);
                 if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled']) && !$captcha->isValid()) {
                     throw new FormProcessingException($app->trans('Invalid captcha answer.'));
                 }
                 if ($app['conf']->get(['registry', 'registration', 'auto-select-collections'])) {
                     $selected = null;
                 } else {
                     $selected = isset($data['collections']) ? $data['collections'] : null;
                 }
                 $inscriptions = $app['registration.manager']->getRegistrationSummary();
                 $inscOK = [];
                 foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) {
                     foreach ($databox->get_collections() as $collection) {
                         if (null !== $selected && !in_array($collection->get_base_id(), $selected)) {
                             continue;
                         }
                         if ($canRegister = igorw\get_in($inscriptions, [$databox->get_sbas_id(), 'config', 'collections', $collection->get_base_id(), 'can-register'])) {
                             $inscOK[$collection->get_base_id()] = $canRegister;
                         }
                     }
                 }
                 if (!isset($data['login'])) {
                     $data['login'] = $data['email'];
                 }
                 $user = $app['manipulator.user']->createUser($data['login'], $data['password'], $data['email'], false);
                 if (isset($data['geonameid'])) {
                     $app['manipulator.user']->setGeonameId($user, $data['geonameid']);
                 }
                 foreach (['gender' => 'setGender', 'firstname' => 'setFirstName', 'lastname' => 'setLastName', 'address' => 'setAddress', 'zipcode' => 'setZipCode', 'tel' => 'setPhone', 'fax' => 'setFax', 'job' => 'setJob', 'company' => 'setCompany', 'position' => 'setActivity'] as $property => $method) {
                     if (isset($data[$property])) {
                         call_user_func([$user, $method], $data[$property]);
                     }
                 }
                 $app['EM']->persist($user);
                 $app['EM']->flush();
                 if (null !== $provider) {
                     $this->attachProviderToUser($app['EM'], $provider, $user);
                     $app['EM']->flush();
                 }
                 $registrationsOK = [];
                 if ($app['conf']->get(['registry', 'registration', 'auto-register-enabled'])) {
                     $template_user = $app['manipulator.user']->getRepository()->findByLogin(User::USER_AUTOREGISTER);
                     $app['acl']->get($user)->apply_model($template_user, array_keys($inscOK));
                 }
                 $autoReg = $app['acl']->get($user)->get_granted_base();
                 foreach ($inscOK as $baseId => $authorization) {
                     if (false === $authorization || $app['acl']->get($user)->has_access_to_base($baseId)) {
                         continue;
                     }
                     $app['manipulator.registration']->createRegistration($user, \collection::get_from_base_id($app, $baseId));
                     $registrationsOK[$baseId] = true;
                 }
                 $params = ['registrations' => $registrationsOK, 'autoregister' => $autoReg, 'usr_id' => $user->getId()];
                 $app['events-manager']->trigger('__REGISTER_AUTOREGISTER__', $params);
                 $app['events-manager']->trigger('__REGISTER_APPROVAL__', $params);
                 $user->setMailLocked(true);
                 try {
                     $this->sendAccountUnlockEmail($app, $user);
                     $app->addFlash('info', $app->trans('login::notification: demande de confirmation par mail envoyee'));
                 } catch (InvalidArgumentException $e) {
                     // todo, log this failure
                     $app->addFlash('error', $app->trans('Unable to send your account unlock email.'));
                 }
                 return $app->redirectPath('homepage');
             }
         } catch (FormProcessingException $e) {
             $app->addFlash('error', $e->getMessage());
         }
     } elseif (null !== $request->query->get('providerId')) {
         $provider = $this->findProvider($app, $request->query->get('providerId'));
         $identity = $provider->getIdentity();
         $form->setData(array_filter(['email' => $identity->getEmail(), 'firstname' => $identity->getFirstname(), 'lastname' => $identity->getLastname(), 'company' => $identity->getCompany(), 'provider-id' => $provider->getId()]));
     }
     return $app['twig']->render('login/register-classic.html.twig', array_merge(self::getDefaultTemplateVariables($app), ['geonames_server_uri' => str_replace(sprintf('%s:', parse_url($app['geonames.server-uri'], PHP_URL_SCHEME)), '', $app['geonames.server-uri']), 'form' => $form->createView()]));
 }
コード例 #4
0
 /**
  * Allow dot syntax access to any data
  *
  * @param  mixed        $data
  * @param  string|array $where
  * @param  bool         $strict
  * @return mixed
  */
 public function getIn($data, $where, $strict = false)
 {
     if (is_object($data)) {
         $clone = clone $data;
         $data = \Foil\arraize($clone, $this->autoescape);
     } elseif (!is_array($data)) {
         return $this->autoescape ? $this->escaper->escape($data) : $data;
     }
     $where = is_string($where) ? explode('.', $where) : (array) $where;
     $get = igorw\get_in($data, $where);
     if (!$strict || !$this->strict || !is_null($get)) {
         return $get;
     }
     $name = implode('.', $where);
     if ($this->strict === 'notice') {
         return trigger_error("{$name} is not defined.");
     }
     throw new RuntimeException("{$name} is not defined.");
 }
コード例 #5
0
 /**
  * Returns a user registration for given collection or null if no registration were requested.
  *
  * @param \collection $collection
  * @param             $userData
  *
  * @return null|array
  */
 private function getUserCollectionRegistration(\collection $collection, $userData)
 {
     if (false === $this->userHasRequestedARegistrationOnCollection($collection, $userData)) {
         return null;
     }
     $userRegistration = igorw\get_in($userData, [$collection->get_sbas_id(), $collection->get_base_id()]);
     // sets collection name
     $userRegistration['coll-name'] = $collection->get_label($this->locale);
     // sets default type
     $userRegistration['type'] = 'active';
     // gets registration entity
     $registration = $userRegistration['registration'];
     // set registration type & return user registration
     $registrationStillExists = !is_null($registration);
     $registrationNoMoreExists = !$registrationStillExists;
     $isPending = $registrationStillExists && $registration->isPending() && !$registration->isRejected();
     $isRejected = $registrationStillExists && $registration->isRejected();
     $isDone = $registrationNoMoreExists || !$isPending && !$isRejected;
     $isActive = (bool) $userRegistration['active'];
     $isTimeLimited = (bool) $userRegistration['time-limited'];
     $isNotTimeLimited = !$isTimeLimited;
     $isOnTime = (bool) $userRegistration['in-time'];
     $isOutDated = !$isOnTime;
     if (!$isActive) {
         $userRegistration['type'] = 'inactive';
         return $userRegistration;
     }
     if ($isDone) {
         $userRegistration['type'] = 'accepted';
         return $userRegistration;
     }
     if ($isRejected) {
         $userRegistration['type'] = 'rejected';
         return $userRegistration;
     }
     if ($isTimeLimited && $isOnTime && $isPending) {
         $userRegistration['type'] = 'in-time';
         return $userRegistration;
     }
     if ($isTimeLimited && $isOutDated && $isPending) {
         $userRegistration['type'] = 'out-time';
         return $userRegistration;
     }
     if ($isNotTimeLimited && $isPending) {
         $userRegistration['type'] = 'pending';
         return $userRegistration;
     }
     return $userRegistration;
 }
コード例 #6
0
 private function buildHeader($key, array $params)
 {
     $header = [];
     $header['_id'] = igorw\get_in($params, ['id']);
     $header['_type'] = igorw\get_in($params, ['type']);
     if ($index = igorw\get_in($params, ['index'])) {
         $header['_index'] = $index;
     }
     return [$key => $header];
 }
コード例 #7
0
ファイル: Indexer.php プロジェクト: luisbrito/Phraseanet
 private function setSetting($name, $value)
 {
     $index = $this->options->getIndexName();
     $params = array();
     $params['index'] = $index;
     $params['body'][$name] = $value;
     $response = $this->client->indices()->putSettings($params);
     return igorw\get_in($response, ['acknowledged']);
 }