/**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @return \Anomaly\Streams\Platform\Addon\FieldType\FieldType|null
  */
 public function handle(SettingRepositoryInterface $settings)
 {
     if (!($setting = $settings->get($this->key))) {
         return null;
     }
     return $setting->getFieldType('value');
 }
 /**
  * Map additional routes.
  *
  * @param Router                     $router
  * @param SettingRepositoryInterface $settings
  */
 public function map(Router $router, SettingRepositoryInterface $settings)
 {
     $tag = $settings->value('anomaly.module.posts::tag_segment', 'tag');
     $module = $settings->value('anomaly.module.posts::module_segment', 'posts');
     $category = $settings->value('anomaly.module.posts::category_segment', 'category');
     $permalink = $settings->value('anomaly.module.posts::permalink_structure', ['year', 'month', 'day', 'post']);
     $permalink = implode('}/{', $permalink);
     /**
      * Map the RSS methods.
      */
     $router->any("{$module}/rss/category/{category}.xml", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\RssController@category', 'streams::addon' => 'anomaly.module.posts']);
     $router->any("{$module}/rss/tag/{tag}.xml", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\RssController@tag', 'streams::addon' => 'anomaly.module.posts']);
     $router->any("{$module}/rss.xml", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\RssController@recent', 'streams::addon' => 'anomaly.module.posts']);
     /**
      * Map other public routes.
      * Mind the order. Routes are
      * handled first come first serve.
      */
     $router->any("{$module}/{type}", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\TypesController@index', 'streams::addon' => 'anomaly.module.posts']);
     $router->any($module, ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\PostsController@index', 'streams::addon' => 'anomaly.module.posts']);
     $router->any("{$module}/preview/{id}", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\PostsController@preview', 'streams::addon' => 'anomaly.module.posts']);
     $router->any("{$module}/{$tag}/{tag}", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\TagsController@index', 'streams::addon' => 'anomaly.module.posts']);
     $router->any("{$module}/{$category}/{category}", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\CategoriesController@index', 'streams::addon' => 'anomaly.module.posts']);
     $router->any("{$module}/{{$permalink}}", ['uses' => 'Anomaly\\PostsModule\\Http\\Controller\\PostsController@show', 'streams::addon' => 'anomaly.module.posts']);
 }
Ejemplo n.º 3
0
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @param Parser                     $parser
  * @return string
  */
 public function handle(SettingRepositoryInterface $settings, Parser $parser)
 {
     $base = $settings->get('anomaly.module.posts::module_segment', 'posts');
     $structure = $settings->get('anomaly.module.posts::permalink_structure', '{year}/{month}/{day}/{post}');
     $data = ['year' => $this->post->created_at->format('Y'), 'month' => $this->post->created_at->format('m'), 'day' => $this->post->created_at->format('d'), 'post' => $this->post->getSlug()];
     return $parser->parse($base . '/' . $structure, $data);
 }
Ejemplo n.º 4
0
 /**
  * Handle the event.
  *
  * @param ModuleWasUninstalled $event
  */
 public function handle(ModuleWasUninstalled $event)
 {
     $module = $event->getModule();
     foreach ($this->settings->findAllByNamespace($module->getNamespace()) as $setting) {
         $this->settings->delete($setting);
     }
 }
 /**
  * Handle the event.
  *
  * @param ExtensionWasUninstalled $event
  */
 public function handle(ExtensionWasUninstalled $event)
 {
     $extension = $event->getExtension();
     foreach ($this->settings->findAllByNamespace($extension->getNamespace()) as $setting) {
         $this->settings->delete($setting);
     }
 }
Ejemplo n.º 6
0
 /**
  * Handle the command.
  *
  * @param Mailer                     $mailer
  * @param SettingRepositoryInterface $settings
  * @return mixed
  */
 public function handle(Mailer $mailer, SettingRepositoryInterface $settings)
 {
     $path = $this->dispatch(new GetResetPasswordPath($this->user, $this->redirect));
     return $mailer->send('anomaly.module.users::emails/reset', ['user' => $this->user, 'path' => $path], function (Message $message) use($settings) {
         $message->subject('Reset your password')->to($this->user->getEmail(), $this->user->getDisplayName())->from($settings->value('streams::server_email', 'noreply@localhost'));
     });
 }
Ejemplo n.º 7
0
 /**
  * Return the tag links.
  *
  * @param array $attributes
  * @return string
  */
 public function tagLinks(array $attributes = [])
 {
     array_set($attributes, 'class', array_get($attributes, 'class', 'label label-default'));
     return array_map(function ($label) use($attributes) {
         return $this->html->link(implode('/', [$this->settings->value('anomaly.module.posts::module_segment', 'posts'), $this->settings->value('anomaly.module.posts::tag_segment', 'tag'), $label]), $label, $attributes);
     }, (array) $this->object->getTags());
 }
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @param Request                    $request
  * @return Github
  */
 public function handle(SettingRepositoryInterface $settings, Request $request)
 {
     /* @var EncryptedFieldTypePresenter $clientId */
     /* @var EncryptedFieldTypePresenter $clientSecret */
     $clientId = $settings->value('anomaly.extension.github_provider::client_id');
     $clientSecret = $settings->value('anomaly.extension.github_provider::client_secret');
     return new Github(['clientId' => $clientId->decrypted(), 'clientSecret' => $clientSecret->decrypted(), 'redirectUri' => $request->fullUrl()]);
 }
Ejemplo n.º 9
0
 /**
  * Return an index of tag posts.
  *
  * @param PostRepositoryInterface $posts
  * @param                         $tag
  * @return \Illuminate\View\View
  */
 public function index(PostRepositoryInterface $posts, SettingRepositoryInterface $settings, $tag)
 {
     $posts = $posts->findManyByTag($tag, $settings->value('anomaly.module.posts::posts_per_page', null));
     $this->dispatch(new AddPostsBreadcrumb());
     $this->dispatch(new AddTagBreadcrumb($tag));
     $this->dispatch(new AddTagMetaTitle($tag));
     return view('anomaly.module.posts::tags/index', compact('posts', 'tag'));
 }
 public function __construct(SettingRepositoryInterface $settings, MessageBag $bag)
 {
     $this->baseUrl = $settings->get('bloveless.module.migrator::base_url');
     $this->disk = $settings->get('bloveless.module.migrator::disk');
     if (empty($this->baseUrl) || empty($this->disk)) {
         $bag->error("The base url and disk are required for this module to function. Set them in \"Settings\"");
     }
     parent::__construct();
 }
 /**
  * Save the form.
  *
  * @param FormBuilder $builder
  * @return bool|mixed
  */
 public function save(FormBuilder $builder)
 {
     $form = $builder->getForm();
     $namespace = $form->getEntry() . '::';
     /* @var FieldType $field */
     foreach ($form->getFields() as $field) {
         $this->settings->set($namespace . $field->getField(), $form->getValue($field->getInputName()));
     }
 }
Ejemplo n.º 12
0
 /**
  * Activate a registered user.
  *
  * @param SettingRepositoryInterface $settings
  * @return \Illuminate\Http\RedirectResponse
  */
 public function activate(SettingRepositoryInterface $settings)
 {
     if (!$this->dispatch(new HandleActivateRequest())) {
         $this->messages->success('anomaly.module.users::error.activate_user');
         return $this->redirect->to($settings->value('anomaly.module.users::activated_redirect', '/'));
     }
     $this->messages->success('anomaly.module.users::success.activate_user');
     return $this->redirect->to($this->request->get('redirect', '/'));
 }
 /**
  * Activate the chosen theme.
  *
  * @param SettingRepositoryInterface $settings
  * @param Authorizer                 $authorizer
  * @param                            $namespace
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function activate(SettingRepositoryInterface $settings, Authorizer $authorizer, $namespace)
 {
     if (!$authorizer->authorize('anomaly.module.appearance::admin_theme.change')) {
         $this->messages->error('streams::message.access_denied');
         return $this->redirect->to('admin/appearance/admin');
     }
     $settings->set('streams::admin_theme', $namespace);
     return redirect('admin/appearance');
 }
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @return AccessToken
  */
 public function handle(SettingRepositoryInterface $settings)
 {
     /* @var EncryptedFieldTypePresenter $setting */
     $setting = $settings->value('anomaly.extension.github_provider::access_token');
     if (!$setting) {
         throw new \Exception('Please generate tokens for the StreamsPlatform provider first.');
     }
     return new AccessToken(['access_token' => $setting->decrypted()]);
 }
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @param Request                    $request
  * @return GenericProvider
  */
 public function handle(SettingRepositoryInterface $settings, Request $request)
 {
     /* @var EncryptedFieldTypePresenter $clientId */
     /* @var EncryptedFieldTypePresenter $clientSecret */
     /* @var UrlFieldTypePresenter $clientDomain */
     $clientId = $settings->value('anomaly.extension.streams_platform_provider::client_id');
     $clientSecret = $settings->value('anomaly.extension.streams_platform_provider::client_secret');
     $clientDomain = $settings->value('anomaly.extension.streams_platform_provider::client_domain');
     return new GenericProvider(['clientId' => $clientId->decrypted(), 'clientSecret' => $clientSecret->decrypted(), 'redirectUri' => $request->fullUrl(), 'urlAuthorize' => $clientDomain->to('api/authorize'), 'urlAccessToken' => $clientDomain->to('api/token'), 'urlResourceOwnerDetails' => $clientDomain->to('api/owner')]);
 }
Ejemplo n.º 16
0
 /**
  * Display recent posts.
  *
  * @param PostRepositoryInterface $posts
  * @return \Illuminate\View\View
  */
 public function index(PostRepositoryInterface $posts, SettingRepositoryInterface $settings)
 {
     if (!$settings->value('anomaly.module.posts::enable_index', true)) {
         abort(404);
     }
     $posts = $posts->getRecent($settings->value('anomaly.module.posts::posts_per_page', null));
     $this->dispatch(new AddPostsBreadcrumb());
     $this->dispatch(new AddPostsMetaTitle());
     return view('anomaly.module.posts::posts/index', compact('posts'));
 }
Ejemplo n.º 17
0
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @param Parser                     $parser
  * @return string
  */
 public function handle(SettingRepositoryInterface $settings, Parser $parser)
 {
     $base = $settings->value('anomaly.module.posts::module_segment', 'posts');
     if (!$this->post->isEnabled()) {
         return $base . '/preview/' . $this->post->getStrId();
     }
     $permalink = $settings->value('anomaly.module.posts::permalink_structure', ['year', 'month', 'day', 'post']);
     $permalink = implode('}/{', $permalink);
     $data = ['year' => $this->post->publish_at->format('Y'), 'month' => $this->post->publish_at->format('m'), 'day' => $this->post->publish_at->format('d'), 'post' => $this->post->getSlug()];
     return $parser->parse($base . '/' . "{{$permalink}}", $data);
 }
Ejemplo n.º 18
0
 /**
  * Return an index of category posts.
  *
  * @param CategoryRepositoryInterface $categories
  * @param PostRepositoryInterface     $posts
  * @param                             $category
  * @return \Illuminate\View\View
  */
 public function index(CategoryRepositoryInterface $categories, PostRepositoryInterface $posts, SettingRepositoryInterface $settings, $category)
 {
     if (!($category = $categories->findBySlug($category))) {
         abort(404);
     }
     $this->dispatch(new AddPostsBreadcrumb());
     $this->dispatch(new AddCategoryBreadcrumb($category));
     $this->dispatch(new AddCategoryMetaTitle($category));
     $posts = $posts->findManyByCategory($category, $settings->value('anomaly.module.posts::posts_per_page', null));
     return view('anomaly.module.posts::categories/index', compact('category', 'posts'));
 }
Ejemplo n.º 19
0
 /**
  * Return an index of type posts.
  *
  * @param TypeRepositoryInterface     $categories
  * @param PostRepositoryInterface     $posts
  * @param                             $type
  * @return \Illuminate\View\View
  */
 public function index(TypeRepositoryInterface $categories, PostRepositoryInterface $posts, SettingRepositoryInterface $settings, $type)
 {
     if (!($type = $categories->findBySlug($type))) {
         abort(404);
     }
     $this->dispatch(new AddPostsBreadcrumb());
     $this->dispatch(new AddTypeBreadcrumb($type));
     $this->dispatch(new AddTypeMetaTitle($type));
     $posts = $posts->findManyByType($type, $settings->value('anomaly.module.posts::posts_per_page', null));
     return view('anomaly.module.posts::types/index', compact('type', 'posts'));
 }
 /**
  * Run the command.
  */
 public function run()
 {
     $data = $this->dispatch(new ReadEnvironmentFile());
     if ($timezone = array_pull($data, 'APP_TIMEZONE')) {
         $this->settings->create(['key' => 'streams::timezone', 'value' => $timezone]);
     }
     if ($locale = array_pull($data, 'DEFAULT_LOCALE')) {
         $this->settings->create(['key' => 'streams::default_locale', 'value' => $locale]);
     }
     $this->dispatch(new WriteEnvironmentFile($data));
 }
Ejemplo n.º 21
0
 /**
  * Return the form fields.
  *
  * @param SettingFormBuilder $builder
  */
 public function handle(SettingFormBuilder $builder, SettingRepositoryInterface $settings)
 {
     $namespace = $builder->getFormEntry() . '::';
     /**
      * Get the fields from the config system. Sections are
      * optionally defined the same way.
      */
     if (!($fields = $this->config->get($namespace . 'settings/settings'))) {
         $fields = $fields = $this->config->get($namespace . 'settings', []);
     }
     if ($sections = $this->config->get($namespace . 'settings/sections')) {
         $builder->setSections($sections);
     }
     /**
      * Finish each field.
      */
     foreach ($fields as $slug => &$field) {
         /**
          * Force an array. This is done later
          * too in normalization but we need it now
          * because we are normalizing / guessing our
          * own parameters somewhat.
          */
         if (is_string($field)) {
             $field = ['type' => $field];
         }
         // Make sure we have a config property.
         $field['config'] = array_get($field, 'config', []);
         if (trans()->has($label = array_get($field, 'label', $namespace . 'setting.' . $slug . '.label'))) {
             $field['label'] = trans($label);
         }
         // Default the label.
         $field['label'] = trans(array_get($field, 'label', $namespace . 'setting.' . $slug . '.name'));
         // Default the warning.
         if (trans()->has($warning = array_get($field, 'warning', $namespace . 'setting.' . $slug . '.warning'))) {
             $field['warning'] = trans($warning);
         }
         // Default the placeholder.
         if (trans()->has($placeholder = array_get($field, 'placeholder', $namespace . 'setting.' . $slug . '.placeholder'))) {
             $field['placeholder'] = trans($placeholder);
         }
         // Default the instructions.
         if (trans()->has($instructions = array_get($field, 'instructions', $namespace . 'setting.' . $slug . '.instructions'))) {
             $field['instructions'] = trans($instructions);
         }
         // Get the value defaulting to the default value.
         if ($value = $settings->get($namespace . $slug)) {
             $field['value'] = $value->getValue();
         } else {
             $field['value'] = array_get($field['config'], 'default_value');
         }
     }
     $builder->setFields($fields);
 }
 /**
  * Save the form.
  *
  * @param FormBuilder|SettingFormBuilder $builder
  * @return bool|mixed
  */
 public function save(FormBuilder $builder)
 {
     $form = $builder->getForm();
     $namespace = $form->getEntry() . '::';
     /* @var FieldType $field */
     foreach ($form->getFields() as $field) {
         $key = $namespace . $field->getField();
         $value = $form->getValue($field->getInputName());
         $this->settings->set($key, $value);
     }
     $this->events->fire(new SettingsWereSaved($builder));
 }
Ejemplo n.º 23
0
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  */
 public function handle(SettingRepositoryInterface $settings)
 {
     if (!$this->builder->getOption('redirect')) {
         $this->builder->setOption('redirect', $settings->value('anomaly.module.users::reset_redirect', '/'));
     }
     if (!$this->builder->getOption('success_message')) {
         $this->builder->setOption('success_message', $settings->value('anomaly.module.users::reset_message', 'You are now logged in.'));
     }
     if (!$this->builder->getOption('container_class')) {
         $this->builder->setOption('container_class', 'form-wrapper');
     }
 }
Ejemplo n.º 24
0
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @param ThemeCollection            $themes
  * @param Repository                 $config
  */
 public function handle(SettingRepositoryInterface $settings, ThemeCollection $themes, Repository $config)
 {
     if (!($theme = $themes->current())) {
         return;
     }
     if (!($fields = $config->get($theme->getNamespace('settings/settings')))) {
         $fields = $config->get($theme->getNamespace('settings'));
     }
     if (!$fields) {
         return;
     }
     foreach (array_keys($fields) as $field) {
         $this->variables->put($field, $settings->get($theme->getNamespace($field), array_get($fields, $field . '.config.default_value')));
     }
 }
 /**
  * Handle the command.
  *
  * @param Repository                     $cache
  * @param Request                        $request
  * @param UserAuthenticator              $authenticator
  * @param SettingRepositoryInterface     $settings
  * @param ThrottleSecurityCheckExtension $extension
  * @return bool
  */
 public function handle(Repository $cache, Request $request, UserAuthenticator $authenticator, SettingRepositoryInterface $settings, ThrottleSecurityCheckExtension $extension)
 {
     $maxAttempts = $settings->value('anomaly.extension.throttle_security_check::max_attempts', 5);
     $lockoutInterval = $settings->value('anomaly.extension.throttle_security_check::lockout_interval', 1);
     $throttleInterval = $settings->value('anomaly.extension.throttle_security_check::throttle_interval', 1);
     $attempts = $cache->get($extension->getNamespace('attempts:' . $request->ip()), 1);
     $expiration = $cache->get($extension->getNamespace('expiration:' . $request->ip()));
     if ($expiration || $attempts >= $maxAttempts) {
         $cache->put($extension->getNamespace('attempts:' . $request->ip()), $attempts + 1, $throttleInterval);
         $cache->put($extension->getNamespace('expiration:' . $request->ip()), time(), $lockoutInterval);
         $authenticator->logout();
         // Just for safe measure.
         return $this->dispatch(new MakeResponse());
     }
     $cache->put($extension->getNamespace('attempts:' . $request->ip()), $attempts + 1, $throttleInterval);
     return true;
 }
Ejemplo n.º 26
0
 /**
  * Handle the form.
  *
  * @param SettingRepositoryInterface $settings
  * @param RegisterFormBuilder        $builder
  * @param UserActivator              $activator
  * @throws \Exception
  */
 public function handle(SettingRepositoryInterface $settings, RegisterFormBuilder $builder, UserActivator $activator)
 {
     if (!$builder->canSave()) {
         return;
     }
     $builder->saveForm();
     // Save the new user.
     /* @var UserInterface $user */
     $user = $builder->getFormEntry();
     $activator->start($user);
     $mode = $settings->value('anomaly.module.users::activation_mode', 'manual');
     if ($mode === 'automatic') {
         $this->dispatch(new HandleAutomaticRegistration($builder));
     } elseif ($mode === 'manual') {
         $this->dispatch(new HandleManualRegistration($builder));
     } elseif ($mode === 'email') {
         $this->dispatch(new HandleEmailRegistration($builder));
     }
 }
Ejemplo n.º 27
0
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @param AddonCollection            $addons
  * @param Repository                 $config
  */
 public function handle(SettingRepositoryInterface $settings, AddonCollection $addons, Repository $config)
 {
     /* @var Addon $addon */
     foreach ($addons->withConfig('settings') as $addon) {
         foreach ($config->get($addon->getNamespace('settings')) as $key => $setting) {
             if (isset($setting['env']) && env($setting['env']) !== null) {
                 continue;
             }
             if (!isset($setting['bind'])) {
                 continue;
             }
             if (!$settings->has($key = $addon->getNamespace($key))) {
                 continue;
             }
             $config->set($setting['bind'], $settings->value($key));
         }
     }
     foreach ($addons->withConfig('settings/settings') as $addon) {
         foreach ($config->get($addon->getNamespace('settings/settings')) as $key => $setting) {
             if (isset($setting['env']) && env($setting['env']) !== null) {
                 continue;
             }
             if (!isset($setting['bind'])) {
                 continue;
             }
             if (!$settings->has($key = $addon->getNamespace($key))) {
                 continue;
             }
             $config->set($setting['bind'], $settings->value($key));
         }
     }
     foreach ($config->get('streams::settings/settings', []) as $key => $setting) {
         if (isset($setting['env']) && env($setting['env']) !== null) {
             continue;
         }
         if (!isset($setting['bind'])) {
             continue;
         }
         if (!$settings->has($key = 'streams::' . $key)) {
             continue;
         }
         $config->set($setting['bind'], $settings->value($key));
     }
 }
Ejemplo n.º 28
0
 /**
  * Cache the post's HTTP response.
  *
  * @param PostInterface $post
  */
 public function cache(PostInterface $post)
 {
     $response = $post->getResponse();
     $response->setTtl($this->settings->get('anomaly.module.posts::ttl'));
 }
Ejemplo n.º 29
0
 /**
  * Resolve the post.
  *
  * @return PostInterface|null
  */
 public function resolve()
 {
     $permalink = $this->settings->value('anomaly.module.posts::permalink_structure', ['year', 'month', 'day', 'post']);
     return $this->posts->findBySlug($this->request->segment(array_search('post', $permalink) + 2));
 }
Ejemplo n.º 30
0
 /**
  * Handle the command.
  *
  * @param SettingRepositoryInterface $settings
  * @return mixed
  */
 public function handle(SettingRepositoryInterface $settings)
 {
     return $settings->get($this->key, $this->default);
 }