예제 #1
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);
 }
예제 #3
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);
 }
예제 #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 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);
 }
예제 #7
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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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());
 }
예제 #11
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);
 }
예제 #12
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);
 }
예제 #13
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);
 }
예제 #14
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.
  *
  * @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'));
     }
 }
 /**
  * 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);
 }
예제 #17
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);
 }
 /**
  * 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'));
     }
 }
예제 #19
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);
 }
예제 #20
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'));
     }
 }
 /**
  * Guess some table table filter placeholders.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $filters = $builder->getFilters();
     $stream = $builder->getTableStream();
     foreach ($filters as &$filter) {
         // Skip if we already have a placeholder.
         if (isset($filter['placeholder'])) {
             continue;
         }
         // Get the placeholder off the assignment.
         if ($stream && ($assignment = $stream->getAssignment(array_get($filter, 'field')))) {
             /**
              * Always use the field name
              * as the placeholder. Placeholders
              * that are assigned otherwise usually
              * feel out of context:
              *
              * "Choose an option..." in the filter
              * would just be weird.
              */
             $filter['placeholder'] = $assignment->getFieldName();
         }
         if (!($module = $this->modules->active())) {
             continue;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.placeholder');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         $placeholder = $module->getNamespace('field.' . $filter['slug'] . '.name');
         if (!isset($filter['placeholder']) && $this->translator->has($placeholder)) {
             $filter['placeholder'] = $placeholder;
         }
         if (!array_get($filter, 'placeholder')) {
             $filter['placeholder'] = $filter['slug'];
         }
     }
     $builder->setFilters($filters);
 }
 /**
  * Handle the command.
  *
  * @param ModuleCollection $modules
  */
 public function handle(ModuleCollection $modules)
 {
     $table = $this->builder->getTable();
     /**
      * Set the default sortable option.
      */
     if ($table->getOption('sortable') === null) {
         $stream = $table->getStream();
         if ($stream && $stream->isSortable()) {
             $table->setOption('sortable', true);
         }
     }
     /**
      * Sortable tables have no pages.
      */
     if ($table->getOption('sortable') === true) {
         $table->setOption('limit', $table->getOption('limit', 99999));
     }
     /**
      * Set the default breadcrumb.
      */
     if ($table->getOption('breadcrumb') === null && ($title = $table->getOption('title'))) {
         $table->setOption('breadcrumb', $title);
     }
     /**
      * If the table ordering is currently being overridden
      * then set the values from the request on the builder
      * last so it actually has an effect.
      */
     if ($orderBy = $this->builder->getRequestValue('order_by')) {
         $table->setOption('order_by', [$orderBy => $this->builder->getRequestValue('sort', 'asc')]);
     }
     /**
      * If the permission is not set then
      * try and automate it.
      */
     if ($table->getOption('permission') === null && ($module = $modules->active()) && ($stream = $this->builder->getTableStream())) {
         $table->setOption('permission', $module->getNamespace($stream->getSlug() . '.read'));
     }
 }
예제 #23
0
 /**
  * Guess the field for a column.
  *
  * @param TableBuilder $builder
  */
 public function guess(TableBuilder $builder)
 {
     $columns = $builder->getColumns();
     $stream = $builder->getTableStream();
     $module = $this->modules->active();
     foreach ($columns as &$column) {
         /*
          * If the heading is already set then
          * we don't have anything to do.
          */
         if (isset($column['heading'])) {
             continue;
         }
         /*
          * If the heading is false, then no
          * header is desired at all.
          */
         if (isset($column['heading']) && $column['heading'] === false) {
             continue;
         }
         /*
          * No stream means we can't
          * really do much here.
          */
         if (!$stream instanceof StreamInterface) {
             continue;
         }
         if (!isset($column['field']) && is_string($column['value'])) {
             $column['field'] = $column['value'];
         }
         /*
          * If the heading matches a field
          * with dot format then reduce it.
          */
         if (isset($column['field']) && preg_match("/^entry.([a-zA-Z\\_]+)/", $column['field'], $match)) {
             $column['field'] = $match[1];
         }
         /*
          * Detect some built in columns.
          */
         if (in_array($column['field'], ['id', 'created_at', 'created_by', 'updated_at', 'updated_by'])) {
             $column['heading'] = 'streams::entry.' . $column['field'];
             continue;
         }
         /*
          * Detect entry title.
          */
         if (in_array($column['field'], ['view_link', 'edit_link']) && ($field = $stream->getTitleField())) {
             $column['heading'] = $field->getName();
             continue;
         }
         $field = $stream->getField(array_get($column, 'field'));
         /*
          * Detect the title column.
          */
         $title = $stream->getTitleField();
         if ($title && !$field && $column['field'] == 'title' && $this->translator->has($heading = $title->getName())) {
             $column['heading'] = $heading;
         }
         /*
          * Use the name from the field.
          */
         if ($field && ($heading = $field->getName())) {
             $column['heading'] = $heading;
         }
         /*
          * If no field look for
          * a name anyways.
          */
         if ($module && !$field && $this->translator->has($heading = $module->getNamespace('field.' . $column['field'] . '.name'))) {
             $column['heading'] = $heading;
         }
         /*
          * If no translatable heading yet and
          * the heading matches the value (default)
          * then humanize the heading value.
          */
         if (!isset($column['heading']) && $this->config->get('streams::system.lazy_translations')) {
             $column['heading'] = ucwords($this->string->humanize($column['field']));
         }
         /*
          * If we have a translatable heading and
          * the heading does not have a translation
          * then humanize the heading value.
          */
         if (isset($column['heading']) && str_is('*.*.*::*', $column['heading']) && !$this->translator->has($column['heading']) && $this->config->get('streams::system.lazy_translations')) {
             $column['heading'] = ucwords($this->string->humanize($column['field']));
         }
         /*
          * Last resort.
          */
         if ($module && !isset($column['heading'])) {
             $column['heading'] = $module->getNamespace('field.' . $column['field'] . '.name');
         }
     }
     $builder->setColumns($columns);
 }
 /**
  * Get the default dashboard.
  *
  * @return DashboardInterface
  */
 public function getDefault()
 {
     $module = $this->modules->active();
     return $this->extensions->search($module->getNamespace('dashboard.*'))->first();
 }