예제 #1
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);
 }
 /**
  * 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);
 }
예제 #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 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);
 }
예제 #5
0
 /**
  * Handle the buttons.
  *
  * @param ControlPanelBuilder $builder
  */
 public function handle(ControlPanelBuilder $builder)
 {
     if (!($section = $builder->getControlPanelActiveSection())) {
         $builder->setButtons([]);
         return;
     }
     $builder->setButtons($section->getButtons());
 }
 /**
  * Build the navigation.
  *
  * @param ControlPanelBuilder $builder
  */
 public function build(ControlPanelBuilder $builder)
 {
     $controlPanel = $builder->getControlPanel();
     $this->input->read($builder);
     foreach ($builder->getNavigation() as $link) {
         $controlPanel->addNavigationLink($this->factory->make($link));
     }
 }
 /**
  * Handle the command.
  *
  * @param Repository $config
  */
 public function handle(Repository $config)
 {
     $links = $this->builder->getControlPanelNavigation();
     $favorites = $config->get('streams::navigation.favorites', []);
     /* @var NavigationLinkInterface $link */
     foreach ($links as $link) {
         $link->setFavorite(in_array($link->getSlug(), $favorites));
     }
 }
 /**
  * Handle the command.
  *
  * @param Request              $request
  * @param Authorizer           $authorizer
  * @param BreadcrumbCollection $breadcrumbs
  */
 public function handle(Request $request, Authorizer $authorizer, BreadcrumbCollection $breadcrumbs)
 {
     $links = $this->builder->getControlPanelNavigation();
     /**
      * If we already have an active link
      * then we don't need to do this.
      */
     if ($active = $links->active()) {
         return;
     }
     /* @var NavigationLinkInterface $link */
     foreach ($links as $link) {
         /**
          * Get the HREF for both the active
          * and loop iteration link.
          */
         $href = array_get($link->getAttributes(), 'data-href', array_get($link->getAttributes(), 'href'));
         $activeHref = '';
         if ($active && $active instanceof NavigationLinkInterface) {
             $activeHref = array_get($active->getAttributes(), 'data-href', array_get($active->getAttributes(), 'href'));
         }
         /**
          * If the request URL does not even
          * contain the HREF then skip it.
          */
         if (!str_contains($request->url(), $href)) {
             continue;
         }
         /**
          * Compare the length of the active HREF
          * and loop iteration HREF. The longer the
          * HREF the more detailed and exact it is and
          * the more likely it is the active HREF and
          * therefore the active link.
          */
         $hrefLength = strlen($href);
         $activeHrefLength = strlen($activeHref);
         if ($hrefLength > $activeHrefLength) {
             $active = $link;
         }
     }
     // No active link!
     if (!$active) {
         return;
     }
     // Active navigation link!
     $active->setActive(true);
     // Authorize the active link.
     if (!$authorizer->authorize($active->getPermission())) {
         abort(403);
     }
     // Add the bread crumb.
     if (($breadcrumb = $active->getBreadcrumb()) !== false) {
         $breadcrumbs->put($breadcrumb ?: $active->getTitle(), $active->getHref());
     }
 }
 /**
  * Handle the event.
  */
 public function handle()
 {
     if (in_array($this->request->path(), ['admin/logout'])) {
         return;
     }
     if ($this->request->segment(1) !== 'admin') {
         return;
     }
     $this->template->put('cp', $this->controlPanel->build());
 }
예제 #10
0
 /**
  * Build the buttons.
  *
  * @param ControlPanelBuilder $builder
  */
 public function build(ControlPanelBuilder $builder)
 {
     $controlPanel = $builder->getControlPanel();
     $this->input->read($builder);
     foreach ($builder->getButtons() as $button) {
         if (($button = $this->factory->make($button)) && $button->isEnabled()) {
             $controlPanel->addButton($button);
         }
     }
 }
예제 #11
0
 /**
  * Build the sections and push them to the control_panel.
  *
  * @param ControlPanelBuilder $builder
  */
 public function build(ControlPanelBuilder $builder)
 {
     $controlPanel = $builder->getControlPanel();
     $this->input->read($builder);
     foreach ($builder->getSections() as $section) {
         if (!$this->authorizer->authorize($section['permission'])) {
             continue;
         }
         $controlPanel->addSection($this->factory->make($section));
     }
 }
 /**
  * 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);
 }
예제 #13
0
 /**
  * Guess the enabled property.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as &$button) {
         if (!isset($button['enabled']) || is_bool($button['enabled'])) {
             continue;
         }
         if (is_string($button['enabled'])) {
             $button['enabled'] = str_is($button['enabled'], $this->request->path());
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * 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);
 }
예제 #15
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);
 }
예제 #16
0
 /**
  * Merge in registered properties.
  *
  * @param ControlPanelBuilder $builder
  */
 public function merge(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as &$parameters) {
         if (!($button = array_get($parameters, 'button'))) {
             continue;
         }
         if ($button && ($button = $this->buttons->get($button))) {
             $parameters = array_replace_recursive($button, $parameters);
         }
         $button = array_get($parameters, 'button', $button);
         if ($button && ($button = $this->buttons->get($button))) {
             $parameters = array_replace_recursive($button, $parameters);
         }
     }
     $builder->setButtons($buttons);
 }
예제 #17
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));
 }
예제 #19
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'));
     }
 }
 /**
  * Normalize the navigation input.
  *
  * @param ControlPanelBuilder $builder
  */
 public function normalize(ControlPanelBuilder $builder)
 {
     $links = $builder->getNavigation();
     foreach ($links as $path => &$link) {
         /**
          * If the link is a string
          * then it must be in the
          * $path => $title format.
          */
         if (is_string($link)) {
             $link = ['href' => $path];
         }
         /**
          * Make sure we have attributes.
          */
         $link['attributes'] = array_get($link, 'attributes', []);
         /**
          * Move the HREF into attributes.
          */
         if (isset($link['href'])) {
             $link['attributes']['href'] = array_pull($link, 'href');
         }
         /**
          * Move all data-* keys
          * to attributes.
          */
         foreach ($link as $attribute => $value) {
             if (str_is('data-*', $attribute)) {
                 array_set($link, 'attributes.' . $attribute, array_pull($link, $attribute));
             }
         }
         /**
          * Make sure the HREF and data-HREF are absolute.
          */
         if (isset($link['attributes']['href']) && is_string($link['attributes']['href']) && !starts_with($link['attributes']['href'], 'http')) {
             $link['attributes']['href'] = url($link['attributes']['href']);
         }
     }
     $builder->setNavigation($links);
 }
 /**
  * Handle the command.
  *
  * @param Request              $request
  * @param Authorizer           $authorizer
  * @param BreadcrumbCollection $breadcrumbs
  */
 public function handle(Request $request, Authorizer $authorizer, BreadcrumbCollection $breadcrumbs)
 {
     $controlPanel = $this->builder->getControlPanel();
     $sections = $controlPanel->getSections();
     /*
      * If we already have an active section
      * then we don't need to do this.
      */
     if ($active = $sections->active()) {
         return;
     }
     /* @var SectionInterface $section */
     foreach ($sections as $section) {
         if (($matcher = $section->getMatcher()) && str_is($matcher, $request->path())) {
             $active = $section;
         }
         /*
          * Get the HREF for both the active
          * and loop iteration section.
          */
         $href = $section->getPermalink() ?: array_get($section->getAttributes(), 'href');
         $activeHref = '';
         if ($active && $active instanceof SectionInterface) {
             $activeHref = $active->getPermalink() ?: array_get($active->getAttributes(), 'href');
         }
         /*
          * If the request URL does not even
          * contain the HREF then skip it.
          */
         if (!str_contains($request->url(), $href)) {
             continue;
         }
         /*
          * Compare the length of the active HREF
          * and loop iteration HREF. The longer the
          * HREF the more detailed and exact it is and
          * the more likely it is the active HREF and
          * therefore the active section.
          */
         $hrefLength = strlen($href);
         $activeHrefLength = strlen($activeHref);
         if ($hrefLength > $activeHrefLength) {
             $active = $section;
         }
     }
     /**
      * If we have an active section determined
      * then mark it as such.
      *
      * @var SectionInterface $active
      * @var SectionInterface $section
      */
     if ($active) {
         if ($active->getParent()) {
             $active->setActive(true);
             $section = $sections->get($active->getParent(), $sections->first());
             $section->setHighlighted(true);
             $breadcrumbs->put($section->getBreadcrumb() ?: $section->getTitle(), $section->getHref());
         } else {
             $active->setActive(true)->setHighlighted(true);
         }
     } elseif ($active = $sections->first()) {
         $active->setActive(true)->setHighlighted(true);
     }
     // No active section!
     if (!$active) {
         return;
     }
     // Authorize the active section.
     if (!$authorizer->authorize($active->getPermission())) {
         abort(403);
     }
     // Add the bread crumb.
     if (($breadcrumb = $active->getBreadcrumb()) !== false) {
         $breadcrumbs->put($breadcrumb ?: $active->getTitle(), $active->getHref());
     }
 }
 /**
  * Evaluate the navigation.
  *
  * @param ControlPanelBuilder $builder
  */
 public function evaluate(ControlPanelBuilder $builder)
 {
     $this->evaluator->evaluate($builder->getNavigation(), compact('builder'));
 }
 /**
  * Evaluate the control panel sections.
  *
  * @param ControlPanelBuilder $builder
  */
 public function evaluate(ControlPanelBuilder $builder)
 {
     $builder->setSections($this->evaluator->evaluate($builder->getSections(), compact('builder')));
 }
 /**
  * Normalize button input.
  *
  * @param ControlPanelBuilder $builder
  */
 public function normalize(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as $key => &$button) {
         /*
          * If the button is a string but the key
          * is numeric then use the button as the
          * button type.
          */
         if (is_numeric($key) && is_string($button)) {
             $button = ['button' => $button];
         }
         /*
          * If the button AND key are strings then
          * use the key as the button and the
          * button as the text parameters.
          */
         if (!is_numeric($key) && is_string($button)) {
             $button = ['text' => $button, 'button' => $key];
         }
         /*
          * If the key is not numeric and the button
          * is an array without the button key then
          * use the key as the button's type.
          */
         if (!is_numeric($key) && is_array($button) && !isset($button['button'])) {
             $button['button'] = $key;
         }
         /*
          * Make sure some default parameters exist.
          */
         $button['attributes'] = array_get($button, 'attributes', []);
         /*
          * Move the HREF if any to the attributes.
          */
         if (isset($button['href'])) {
             array_set($button['attributes'], 'href', array_pull($button, 'href'));
         }
         /*
          * Move the target if any to the attributes.
          */
         if (isset($button['target'])) {
             array_set($button['attributes'], 'target', array_pull($button, 'target'));
         }
         /*
          * Move all data-* keys
          * to attributes.
          */
         foreach ($button as $attribute => $value) {
             if (str_is('data-*', $attribute)) {
                 array_set($button, 'attributes.' . $attribute, array_pull($button, $attribute));
             }
         }
         /*
          * Make sure the HREF is absolute.
          */
         if (isset($button['attributes']['href']) && is_string($button['attributes']['href']) && !starts_with($button['attributes']['href'], 'http')) {
             $button['attributes']['href'] = url($button['attributes']['href']);
         }
         /*
          * If we have a dropdown then
          * process those real quick.
          */
         if (isset($button['dropdown'])) {
             foreach ($button['dropdown'] as $index => &$dropdown) {
                 if (is_string($dropdown)) {
                     $dropdown = ['text' => $index, 'href' => $dropdown];
                 }
                 // Make sure we have attributes.
                 $dropdown['attributes'] = array_get($dropdown, 'attributes', []);
                 // Move the HREF if any to the attributes.
                 if (isset($dropdown['href'])) {
                     array_set($dropdown['attributes'], 'href', array_pull($dropdown, 'href'));
                 }
                 // Make sure the HREF is absolute.
                 if (isset($dropdown['attributes']['href']) && is_string($dropdown['attributes']['href']) && !starts_with($dropdown['attributes']['href'], 'http')) {
                     $dropdown['attributes']['href'] = url($dropdown['attributes']['href']);
                 }
             }
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Normalize the section input.
  *
  * @param ControlPanelBuilder $builder
  */
 public function normalize(ControlPanelBuilder $builder)
 {
     $sections = $builder->getSections();
     /*
      * Loop over each section and make sense of the input
      * provided for the given module.
      */
     foreach ($sections as $slug => &$section) {
         /*
          * If the slug is not valid and the section
          * is a string then use the section as the slug.
          */
         if (is_numeric($slug) && is_string($section)) {
             $section = ['slug' => $section];
         }
         /*
          * If the slug is a string and the title is not
          * set then use the slug as the slug.
          */
         if (is_string($slug) && !isset($section['slug'])) {
             $section['slug'] = $slug;
         }
         /*
          * Make sure we have attributes.
          */
         $section['attributes'] = array_get($section, 'attributes', []);
         /*
          * Move the HREF into attributes.
          */
         if (isset($section['href'])) {
             $section['attributes']['href'] = array_pull($section, 'href');
         }
         /*
          * Move all data-* keys
          * to attributes.
          */
         foreach ($section as $attribute => $value) {
             if (str_is('data-*', $attribute)) {
                 array_set($section, 'attributes.' . $attribute, array_pull($section, $attribute));
             }
         }
         /*
          * Move the data-href into the permalink.
          *
          * @deprecated as of v3.2
          */
         if (!isset($section['permalink']) && isset($section['attributes']['data-href'])) {
             $section['permalink'] = array_pull($section, 'attributes.data-href');
         }
         /*
          * Make sure the HREF and permalink are absolute.
          */
         if (isset($section['attributes']['href']) && is_string($section['attributes']['href']) && !starts_with($section['attributes']['href'], 'http')) {
             $section['attributes']['href'] = url($section['attributes']['href']);
         }
         if (isset($section['permalink']) && is_string($section['permalink']) && !starts_with($section['permalink'], 'http')) {
             $section['permalink'] = url($section['permalink']);
         }
         /*
          * Move child sections into main array.
          */
         if (isset($section['sections'])) {
             foreach ($section['sections'] as $key => &$child) {
                 $child['parent'] = array_get($section, 'slug');
                 $child['slug'] = array_get($child, 'slug', $key);
                 $sections[$key] = $child;
             }
         }
     }
     $builder->setSections(array_values($sections));
 }
예제 #26
0
 /**
  * Parse the control panel buttons.
  *
  * @param ControlPanelBuilder $builder
  */
 public function parse(ControlPanelBuilder $builder)
 {
     $parameters = $this->request->route()->parameters();
     $builder->setButtons($this->parser->parse($builder->getButtons(), compact('parameters')));
 }
예제 #27
0
 /**
  * Parse the control panel sections.
  *
  * @param ControlPanelBuilder $builder
  */
 public function parse(ControlPanelBuilder $builder)
 {
     $builder->setSections($this->parser->parse($builder->getSections()));
 }
예제 #28
0
 /**
  * Resolve the control panel sections.
  *
  * @param ControlPanelBuilder $builder
  */
 public function resolve(ControlPanelBuilder $builder)
 {
     $this->resolver->resolve($builder->getSections(), compact('builder'));
 }