/**
  * Detect the active module and setup our
  * environment with it.
  */
 public function handle()
 {
     /**
      * In order to detect we MUST have a route
      * and we MUST have a namespace in the
      * streams::addon action parameter.
      *
      * @var Route $route
      */
     $route = $this->request->route();
     /* @var Module $module */
     if ($route && ($module = $this->modules->get(array_get($route->getAction(), 'streams::addon')))) {
         $module->setActive(true);
     }
     if (!$module && $this->request->segment(1) == 'admin' && ($module = $this->modules->findBySlug($this->request->segment(2)))) {
         $module->setActive(true);
     }
     if (!$module) {
         return;
     }
     $this->container->make('view')->addNamespace('module', $module->getPath('resources/views'));
     $this->container->make('translator')->addNamespace('module', $module->getPath('resources/lang'));
     $this->asset->addPath('module', $module->getPath('resources'));
     $this->image->addPath('module', $module->getPath('resources'));
 }
Ejemplo n.º 2
1
 /**
  * Guess the HREF for a button.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $buttons = $builder->getButtons();
     if (!($section = $this->sections->active())) {
         return;
     }
     if (!($module = $this->modules->active())) {
         return;
     }
     $stream = $builder->getTableStream();
     foreach ($buttons as &$button) {
         // If we already have an HREF then skip it.
         if (isset($button['attributes']['href'])) {
             continue;
         }
         switch (array_get($button, 'button')) {
             case 'restore':
                 $button['attributes']['href'] = $this->url->to('entry/handle/restore/' . $module->getNamespace() . '/' . $stream->getNamespace() . '/' . $stream->getSlug() . '/{entry.id}');
                 break;
             default:
                 // Determine the HREF based on the button type.
                 $type = array_get($button, 'segment', array_get($button, 'button'));
                 if ($type && !str_contains($type, '\\') && !class_exists($type)) {
                     $button['attributes']['href'] = $section->getHref($type . '/{entry.id}');
                 }
                 break;
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Guess the text for a button.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $buttons = $builder->getButtons();
     if (!($module = $this->modules->active())) {
         return;
     }
     if (!($stream = $builder->getTableStream())) {
         return;
     }
     foreach ($buttons as &$button) {
         if (isset($button['permission'])) {
             continue;
         }
         /**
          * Try and guess the permission value.
          */
         switch (array_get($button, 'button')) {
             case 'edit':
                 $button['permission'] = $module->getNamespace($stream->getSlug() . '.write');
                 break;
             default:
                 break;
         }
     }
     $builder->setButtons($buttons);
 }
Ejemplo n.º 4
0
 /**
  * Guess the sections title.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If title is set then skip it.
         if (isset($section['title'])) {
             continue;
         }
         $module = $this->modules->active();
         $title = $module->getNamespace('section.' . $section['slug'] . '.title');
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         $title = $module->getNamespace('addon.section.' . $section['slug']);
         if (!isset($section['title']) && $this->translator->has($title)) {
             $section['title'] = $title;
         }
         if (!isset($section['title']) && $this->config->get('streams::system.lazy_translations')) {
             $section['title'] = ucwords($this->string->humanize($section['slug']));
         }
         if (!isset($section['title'])) {
             $section['title'] = $title;
         }
     }
     $builder->setSections($sections);
 }
 /**
  * Handle the event.
  */
 public function handle()
 {
     if (!$this->config->get('app.debug') && !$this->session->get(__CLASS__ . 'warned') && $this->request->path() == 'admin/dashboard' && $this->modules->get('anomaly.module.installer')) {
         $this->session->set(__CLASS__ . 'warned', true);
         $this->messages->error('streams::message.delete_installer');
     }
 }
Ejemplo n.º 6
0
 /**
  * Execute the console command.
  *
  * @param ModuleManager    $manager
  * @param ModuleCollection $modules
  */
 public function fire(ModuleManager $manager, ModuleCollection $modules)
 {
     /* @var Module $module */
     $module = $modules->get($this->argument('module'));
     $manager->uninstall($module);
     $this->info(trans($module->getName()) . ' uninstalled successfully!');
 }
Ejemplo n.º 7
0
 /**
  * Guess the HREF for a button.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $sections = $builder->getControlPanelSections();
     $active = $sections->active();
     $module = $this->modules->active();
     foreach ($buttons as &$button) {
         // If we already have an HREF then skip it.
         if (isset($button['attributes']['href'])) {
             continue;
         }
         // Determine the HREF based on the button type.
         switch (array_get($button, 'button')) {
             case 'add':
             case 'new':
             case 'create':
                 $button['attributes']['href'] = $active->getHref('create');
                 break;
             case 'export':
                 if ($module) {
                     $button['attributes']['href'] = $this->url->to('entry/handle/export/' . $module->getNamespace() . '/' . array_get($button, 'namespace') . '/' . array_get($button, 'stream'));
                 }
                 break;
         }
         $type = array_get($button, 'segment', array_get($button, 'button'));
         if (!isset($button['attributes']['href']) && $type) {
             $button['attributes']['href'] = $active->getHref($type);
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Handle loading the dashboard widgets.
  *
  * @param DashboardBuilder $builder
  * @return array
  */
 public function handle(DashboardBuilder $builder)
 {
     $module = $this->modules->active();
     $builder->setWidgets(array_map(function (Extension $widget) {
         return $widget->getProvides();
     }, $this->extensions->search($module->getNamespace('widget.*'))->all()));
 }
 /**
  * Guess the action text.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $actions = $builder->getActions();
     $stream = $builder->getTableStream();
     if (!($module = $this->modules->active())) {
         return;
     }
     $section = $this->controlPanel->getControlPanelActiveSection();
     foreach ($actions as &$action) {
         /*
          * Nothing to do if set already.
          */
         if (isset($action['permission'])) {
             continue;
         }
         /*
          * Try and guess the permission.
          */
         if ($stream) {
             $action['permission'] = $module->getNamespace($stream->getSlug() . '.' . $action['slug']);
         } elseif ($section) {
             $action['permission'] = $module->getNamespace($section->getSlug() . '.' . $action['slug']);
         }
     }
     $builder->setActions($actions);
 }
 /**
  * Handle the command.
  *
  * @param ModuleCollection $modules
  * @param ThemeCollection  $themes
  */
 public function handle(ModuleCollection $modules, ThemeCollection $themes)
 {
     $theme = $themes->current();
     /*
      * Default the form view based on the request.
      */
     if (!$this->builder->getFormOption('form_view') && $this->builder->isAjax()) {
         $this->builder->setFormOption('form_view', 'streams::form/ajax');
     }
     if (!$this->builder->getFormOption('form_view') && $theme && $theme->isAdmin()) {
         $this->builder->setFormOption('form_view', 'streams::form/form');
     }
     if (!$this->builder->getFormOption('form_view') && $theme && !$theme->isAdmin()) {
         $this->builder->setFormOption('form_view', 'streams::form/standard');
     }
     if (!$this->builder->getFormOption('form_view')) {
         $this->builder->setFormOption('form_view', 'streams::form/admin/form');
     }
     /*
      * Default the form wrapper view as well.
      */
     if (!$this->builder->getFormOption('wrapper_view') && $this->builder->isAjax()) {
         $this->builder->setFormOption('wrapper_view', 'streams::ajax');
     }
     if (!$this->builder->getFormOption('wrapper_view')) {
         $this->builder->setFormOption('wrapper_view', 'streams::blank');
     }
     /*
      * If the permission is not set then
      * try and automate it.
      */
     if ($this->builder->getFormOption('permission') === null && ($module = $modules->active()) && ($stream = $this->builder->getFormStream())) {
         $this->builder->setFormOption('permission', $module->getNamespace($stream->getSlug() . '.write'));
     }
 }
Ejemplo n.º 11
0
 /**
  * Execute the console command.
  *
  * @param ModuleCollection $modules
  * @param Repository       $config
  * @param Search           $search
  * @param Kernel           $console
  */
 public function fire(ModuleCollection $modules, Repository $config, Search $search, Kernel $console)
 {
     $stream = $this->argument('stream');
     if (!$stream) {
         $this->info('Destroying index');
         $console->call('search:destroy');
     } else {
         $this->info('Deleting ' . $stream);
         $search->search('stream', $stream)->delete();
     }
     /* @var Module $module */
     foreach ($modules->withConfig('search') as $module) {
         foreach ($config->get($module->getNamespace('search')) as $model => $search) {
             /* @var EntryModel $model */
             $model = new $model();
             if (!$stream || $stream == $model->getStreamNamespace() . '.' . $model->getStreamSlug()) {
                 $this->info('Rebuilding ' . $stream);
                 $this->output->progressStart($model->count());
                 foreach ($model->all() as $entry) {
                     $entry->save();
                     $this->output->progressAdvance();
                 }
                 $this->output->progressFinish();
             }
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Handle the command.
  *
  * @param ModuleCollection $modules
  * @param Decorator        $decorator
  * @param Repository       $config
  * @param Container        $container
  * @param Request          $request
  * @param Search           $search
  * @return LengthAwarePaginator
  */
 public function handle(ModuleCollection $modules, Decorator $decorator, Repository $config, Container $container, Request $request, Search $search)
 {
     /* @var Query $query */
     $query = $search->index($this->criteria->option('index', 'default'));
     $constraint = $this->criteria->option('in');
     if (!empty($constraint) && is_string($constraint)) {
         $query = $query->search('stream', $constraint, ['required' => true]);
     }
     if (!empty($constraint) && is_array($constraint)) {
         /* @var Module $module */
         foreach ($modules->withConfig('search') as $module) {
             foreach ($config->get($module->getNamespace('search')) as $model => $definition) {
                 /* @var EntryInterface $model */
                 $model = $container->make($model);
                 $stream = $model->getStreamNamespace() . '.' . $model->getStreamSlug();
                 if (!in_array($stream, $constraint)) {
                     $query = $query->search('stream', $stream, ['required' => false, 'prohibited' => true]);
                 }
             }
         }
     }
     foreach ($this->criteria->getOperations() as $operation) {
         $query = call_user_func_array([$query, $operation['name']], $operation['arguments']);
     }
     $page = $request->get('page', 1);
     $perPage = $this->criteria->option('paginate', $this->criteria->option('limit', 15));
     $query->limit($perPage, ($page - 1) * $perPage);
     $collection = new SearchCollection(array_map(function ($result) use($decorator) {
         return $decorator->decorate(new SearchItem($result));
     }, $query->get()));
     return (new LengthAwarePaginator($collection, $query->count(), $perPage, $page))->setPath($request->path())->appends($request->all());
 }
Ejemplo n.º 13
0
 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /**
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         if (!isset($button['button'])) {
             continue;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         if ((!isset($button['text']) || !$this->translator->has($button['text'])) && $this->config->get('streams::system.lazy_translations')) {
             $button['text'] = $this->string->humanize(array_get($button, 'slug', $button['button']));
         }
     }
     $builder->setButtons($buttons);
 }
Ejemplo n.º 14
0
 /**
  * Handle the command.
  *
  * @param ModuleCollection $modules
  * @param Repository       $config
  * @return mixed|null
  */
 public function handle(ModuleCollection $modules, Repository $config)
 {
     /* @var Module $module */
     foreach ($modules->withConfig('search.' . get_class($this->entry)) as $module) {
         return $config->get($module->getNamespace('search.' . get_class($this->entry)));
     }
     return null;
 }
 /**
  * Handle the command.
  *
  * @param ModuleCollection $modules
  */
 public function handle(ModuleCollection $modules)
 {
     if ($this->builder->getDashboardOption('dashboard_view')) {
         return;
     }
     if ($module = $modules->active()) {
         $this->builder->setDashboardOption('dashboard_view', $module->getNamespace('admin/dashboard'));
     }
 }
Ejemplo n.º 16
0
 /**
  * Handle the command.
  *
  * @param ModuleCollection $modules
  * @param Repository       $config
  * @return mixed|null
  */
 public function handle(ModuleCollection $modules, Repository $config)
 {
     $default = $config->get('anomaly.module.search::' . ($key = 'search.' . get_class($this->entry)));
     /* @var Module $module */
     foreach ($modules->withConfig($key) as $module) {
         return $default ?: $config->get($module->getNamespace($key));
     }
     return $default;
 }
 /**
  * Check the authorization of module access.
  *
  * @param  Request  $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if ($request->segment(1) !== 'admin' || in_array($request->path(), ['admin/login', 'admin/logout'])) {
         return $next($request);
     }
     $module = $this->modules->active();
     if ($module && !$this->authorizer->authorize($module->getNamespace('*'))) {
         abort(403);
     }
     return $next($request);
 }
Ejemplo n.º 18
0
 /**
  * Handle the command.
  *
  * @param ModuleCollection $modules
  * @param Repository       $config
  * @return mixed|null
  */
 public function handle(ModuleCollection $modules, Repository $config)
 {
     $items = [];
     /* @var Module $module */
     foreach ($modules->withConfig('search') as $module) {
         foreach ($config->get($module->getNamespace('search')) as $model => $configuration) {
             $items[$model] = $configuration;
         }
     }
     return $items;
 }
 /**
  * Guess the sections title.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $module = $this->modules->active();
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If permission is set then skip it.
         if (isset($section['permission'])) {
             return;
         }
         $section['permission'] = $module->getNamespace($section['slug'] . '.*');
     }
     $builder->setSections($sections);
 }
Ejemplo n.º 20
0
 /**
  * Handle the event.
  */
 public function handle()
 {
     if (in_array($this->request->path(), ['admin/logout'])) {
         return;
     }
     if ($this->request->segment(1) !== 'admin') {
         return;
     }
     if (!$this->modules->active()) {
         return;
     }
     $this->template->put('cp', $this->controlPanel->build());
 }
Ejemplo n.º 21
0
 /**
  * Guess the text for the views.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     if (!($module = $this->modules->active())) {
         return;
     }
     $views = $builder->getViews();
     foreach ($views as &$view) {
         // Only automate it if not set.
         if (!isset($view['text'])) {
             $view['text'] = $module->getNamespace('view.' . $view['slug']);
         }
     }
     $builder->setViews($views);
 }
Ejemplo n.º 22
0
 /**
  * Guess the text for a button.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $buttons = $builder->getButtons();
     if (!($module = $this->modules->active())) {
         return;
     }
     foreach ($buttons as &$button) {
         // Skip if set already.
         if (!isset($button['text']) && isset($button['slug'])) {
             $button['text'] = $module->getNamespace('button.' . $button['slug']);
         }
     }
     $builder->setButtons($buttons);
 }
Ejemplo n.º 23
0
 /**
  * Guess the action text.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $actions = $builder->getActions();
     if (!($module = $this->modules->active())) {
         return;
     }
     foreach ($actions as &$action) {
         // Only if it's not already set.
         if (!isset($action['text'])) {
             $action['text'] = $module->getNamespace('button.' . $action['slug']);
         }
     }
     $builder->setActions($actions);
 }
Ejemplo n.º 24
0
 /**
  * Authorize the tree.
  *
  * @param TreeBuilder $builder
  */
 public function authorize(TreeBuilder $builder)
 {
     // Try the option first.
     $permission = $builder->getTreeOption('permission');
     /*
      * If the option is not set then
      * try and automate the permission.
      */
     if (!$permission && ($module = $this->modules->active()) && ($stream = $builder->getTreeStream())) {
         $permission = $module->getNamespace($stream->getSlug() . '.read');
     }
     if (!$this->authorizer->authorize($permission)) {
         abort(403);
     }
 }
 /**
  * Handle the command.
  *
  * @return array
  */
 public function handle()
 {
     $nav = [];
     /* @var UserInterface $user */
     $user = $this->guard->user();
     /**
      * Loop through the modules and build a navigation
      * array with the basic information available.
      *
      * Keep it generic but helpful.
      */
     foreach ($this->modules->enabled() as $module) {
         /**
          * If the group is set to false then
          * skip it - no backend navigation.
          */
         if ($module instanceof Module && $module->getNavigation() === false) {
             continue;
         }
         /**
          * If the user does not have access to anything
          * in the addon then don't add it to the navigation.
          */
         if ($this->config->get($module->getNamespace('permissions')) && !$user->hasPermission($module->getNamespace('*'))) {
             continue;
         }
         // Build the required data.
         $url = $this->getUrl($module);
         $title = $this->getTitle($module);
         $group = $this->getGroup($module);
         $active = $this->getActive($module);
         $item = compact('url', 'title', 'group', 'active');
         /**
          * If the module defined a $navigation property it
          * get's put into a dropdown of the same name.
          *
          * Otherwise just lop it onto the navigation array.
          */
         if ($group) {
             $this->addItemToGroup($nav, $item, $module);
         } else {
             $this->addItem($nav, $item, $module);
         }
     }
     // Finish up formatting.
     $this->finish($nav);
     return $nav;
 }
 /**
  * Guess the sections description.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as &$section) {
         // If description is set then skip it.
         if (isset($section['description'])) {
             continue;
         }
         $module = $this->modules->active();
         $description = $module->getNamespace('section.' . $section['slug'] . '.description');
         if ($this->translator->has($description)) {
             $section['description'] = $description;
         }
     }
     $builder->setSections($sections);
 }
Ejemplo n.º 27
0
 /**
  * Guess the sections HREF attribute.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     foreach ($sections as $index => &$section) {
         // If HREF is set then skip it.
         if (isset($section['attributes']['href'])) {
             continue;
         }
         $module = $this->modules->active();
         $href = $this->url->to('admin/' . $module->getSlug());
         if ($index !== 0 && $module->getSlug() !== $section['slug']) {
             $href .= '/' . $section['slug'];
         }
         $section['attributes']['href'] = $href;
     }
     $builder->setSections($sections);
 }
Ejemplo n.º 28
0
 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /*
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         /*
          * If the button starts with "new_" just use
          * "new" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'new_')) {
             if (!isset($button['text'])) {
                 $text = $module->getNamespace('button.' . $button['button']);
                 if ($this->translator->has($text)) {
                     $button['text'] = $text;
                 }
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
         /*
          * If the button starts with "add_" just use
          * "add" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'add_')) {
             if (!isset($button['text'])) {
                 $button['text'] = $module->getNamespace('button.' . $button['button']);
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Handle the navigation.
  *
  * @param ControlPanelBuilder $builder
  * @param ModuleCollection    $modules
  */
 public function handle(ControlPanelBuilder $builder, ModuleCollection $modules)
 {
     $navigation = [];
     /* @var Module $module */
     foreach ($modules->enabled()->accessible() as $module) {
         if ($module->getNavigation()) {
             $navigation[trans($module->getName())] = $module;
         }
     }
     ksort($navigation);
     foreach ($navigation as $key => $module) {
         if ($module->getNamespace() == 'anomaly.module.dashboard') {
             $navigation = [$key => $module] + $navigation;
             break;
         }
     }
     $builder->setNavigation(array_map(function (Module $module) {
         return ['breadcrumb' => $module->getName(), 'title' => $module->getTitle(), 'slug' => $module->getNamespace(), 'href' => 'admin/' . $module->getSlug()];
     }, $navigation));
 }
Ejemplo n.º 30
0
 /**
  * Handle the sections.
  *
  * @param ControlPanelBuilder $builder
  */
 public function handle(ControlPanelBuilder $builder)
 {
     /**
      * We have to have a module for
      * the default functionality.
      */
     if (!($module = $this->modules->active())) {
         return;
     }
     /**
      * Default to the module's sections.
      */
     $builder->setSections($sections = $module->getSections());
     /**
      * If the module has a sections handler
      * let that HANDLE the sections.
      */
     if (!$sections && class_exists($sections = get_class($module) . 'Sections')) {
         $this->resolver->resolve($sections . '@handle', compact('builder'));
     }
 }