예제 #1
0
 /**
  * @Saving
  */
 public static function saving($event, Node $node)
 {
     $db = self::getConnection();
     $i = 2;
     $id = $node->id;
     if (!$node->slug) {
         $node->slug = $node->title;
     }
     // Ensure unique slug
     while (self::where(['slug = ?', 'parent_id= ?'], [$node->slug, $node->parent_id])->where(function ($query) use($id) {
         if ($id) {
             $query->where('id <> ?', [$id]);
         }
     })->first()) {
         $node->slug = preg_replace('/-\\d+$/', '', $node->slug) . '-' . $i++;
     }
     // Update own path
     $path = '/' . $node->slug;
     if ($node->parent_id && ($parent = Node::find($node->parent_id)) and $parent->menu == $node->menu) {
         $path = $parent->path . $path;
     } else {
         // set Parent to 0, if old parent is not found
         $node->parent_id = 0;
     }
     // Update children's paths
     if ($id && $path != $node->path) {
         $db->executeUpdate('UPDATE ' . self::getMetadata()->getTable() . ' SET path = REPLACE (' . $db->getDatabasePlatform()->getConcatExpression($db->quote('//'), 'path') . ", '//{$node->path}', '{$path}')" . ' WHERE path LIKE ' . $db->quote($node->path . '%'));
     }
     $node->path = $path;
     // Set priority
     if (!$id) {
         $node->priority = 1 + $db->createQueryBuilder()->select($db->getDatabasePlatform()->getMaxExpression('priority'))->from('@system_node')->where(['parent_id' => $node->parent_id])->execute()->fetchColumn();
     }
 }
예제 #2
0
 /**
  * Register a node type.
  *
  * @param string $type
  * @param array  $route
  */
 public function registerType($type, array $route)
 {
     if (isset($route['protected']) and $route['protected'] and !array_filter(Node::findAll(true), function ($node) use($type) {
         return $type === $node->type;
     })) {
         Node::create(['title' => $route['label'], 'slug' => App::filter($route['label'], 'slugify'), 'type' => $type, 'status' => 1, 'link' => $route['name']])->save();
     }
     $route['id'] = $type;
     $this->types[$type] = $route;
 }
예제 #3
0
 /**
  * Adds cache breaker to router.
  * Sets profiles routes
  */
 public function onAppRequest()
 {
     App::router()->setOption('userprofile.profilelink', '{slug}');
     $this->nodes = Node::query()->where("link LIKE '@userprofile/profiles/%'")->get();
     foreach ($this->nodes as $node) {
         App::routes()->add(['name' => '@userprofile/profiles/' . $node->slug, 'controller' => 'Bixie\\Userprofile\\Controller\\ProfilesController::indexAction', 'label' => $node->title, 'defaults' => ['_node' => $node->id, 'roles' => $node->get('show_roles')], 'path' => $node->path]);
         App::routes()->add(['name' => '@userprofile/profiles/' . $node->slug . '/page', 'controller' => 'Bixie\\Userprofile\\Controller\\ProfilesController::indexAction', 'label' => $node->title, 'defaults' => ['_node' => $node->id, 'roles' => $node->get('show_roles')], 'path' => $node->path . '/page/{page}']);
         App::routes()->add(['name' => '@userprofile/profiles/' . $node->slug . '/id', 'controller' => 'Bixie\\Userprofile\\Controller\\ProfilesController::detailsAction', 'label' => __('Details'), 'defaults' => ['_node' => $node->id], 'path' => $node->path . '/{slug}']);
     }
 }
예제 #4
0
 /**
  * @Request({"id": "int", "type": "string"})
  */
 public function editAction($id = 0, $type = null)
 {
     if (!$id) {
         $widget = Widget::create(['type' => $type]);
     } else {
         if (!($widget = Widget::find($id))) {
             App::abort(404, 'Widget not found.');
         }
     }
     return ['$view' => ['title' => __('Widgets'), 'name' => 'system/widget/edit.php'], '$data' => ['widget' => $widget, 'config' => ['menus' => App::menu(), 'nodes' => array_values(Node::query()->get()), 'roles' => array_values(Role::findAll()), 'types' => array_values(App::widget()->all()), 'positions' => array_values(App::position()->all())]]];
 }
예제 #5
0
 /**
  * @Route("site/page/edit", name="page/edit")
  * @Access("site: manage site", admin=true)
  * @Request({"id", "menu"})
  */
 public function editAction($id = '', $menu = '')
 {
     if (is_numeric($id)) {
         if (!$id or !($node = Node::find($id))) {
             App::abort(404, 'Node not found.');
         }
     } else {
         $node = Node::create(['type' => $id]);
         if ($menu && !App::menu($menu)) {
             App::abort(404, 'Menu not found.');
         }
         $node->menu = $menu;
     }
     if (!($type = $this->site->getType($node->type))) {
         App::abort(404, 'Type not found.');
     }
     return ['$view' => ['title' => __('Pages'), 'name' => 'system/site/admin/edit.php'], '$data' => ['node' => $node, 'type' => $type, 'roles' => array_values(Role::findAll())]];
 }
예제 #6
0
 /**
  * Registers category routes
  */
 public function onRequest()
 {
     $categories = Category::findAll(true);
     uasort($categories, function ($a, $b) {
         return strcmp(substr_count($a->path, '/'), substr_count($b->path, '/')) * -1;
     });
     $node = Node::query()->where(['link' => '@download'])->first();
     foreach ($categories as $category) {
         if ($category->status !== 1) {
             continue;
         }
         $route = ['label' => $category->title, 'defaults' => ['_node' => $node->id, 'id' => $category->id], 'path' => $node->path . $category->path];
         //category views
         App::routes()->add(array_merge(['name' => '@download/category/' . $category->id, 'controller' => 'Bixie\\Download\\Controller\\SiteController::categoryAction'], $route));
         //file view
         App::routes()->add(array_merge(['name' => '@download/category/file/' . $category->id, 'controller' => 'Bixie\\Download\\Controller\\SiteController::fileAction'], $route));
     }
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function main(App $app)
 {
     $app['node'] = function ($app) {
         if ($id = $app['request']->attributes->get('_node') and $node = Node::find($id)) {
             return $node;
         }
         return Node::create();
     };
     $app['menu'] = function ($app) {
         $menus = new MenuManager($app->config($app['theme']->name), $this->config('menus'));
         foreach ($app['theme']->get('menus', []) as $name => $label) {
             $menus->register($name, $label);
         }
         return $menus;
     };
     $app->extend('view', function ($view) use($app) {
         return $view->addHelper(new MenuHelper($app['menu']));
     });
 }
예제 #8
0
 /**
  * @param  string $menu
  * @param  array  $parameters
  * @return Node|null
  */
 public function getRoot($menu, $parameters = [])
 {
     $parameters = array_replace(['start_level' => 1, 'depth' => PHP_INT_MAX, 'mode' => 'all'], $parameters);
     $user = App::user();
     $startLevel = (int) $parameters['start_level'] ?: 1;
     $maxDepth = $startLevel + ($parameters['depth'] ?: PHP_INT_MAX);
     $nodes = Node::findByMenu($menu, true);
     $nodes[0] = new Node(['path' => '/']);
     $nodes[0]->status = 1;
     $nodes[0]->parent_id = null;
     $node = App::node();
     $path = $node->path;
     if (!isset($nodes[$node->id])) {
         foreach ($nodes as $node) {
             if ($node->getUrl('base') === $path) {
                 $path = $node->path;
                 break;
             }
         }
     }
     $path .= '/';
     $segments = explode('/', $path);
     $rootPath = count($segments) > $startLevel ? implode('/', array_slice($segments, 0, $startLevel + 1)) . '/' : '/';
     foreach ($nodes as $node) {
         $depth = substr_count($node->path, '/');
         $parent = isset($nodes[$node->parent_id]) ? $nodes[$node->parent_id] : null;
         $node->set('active', 0 === strpos($path, $node->path . '/'));
         if ($node->status !== 1 || $depth >= $maxDepth || !$node->hasAccess($user) || $node->get('menu_hide') || !($parameters['mode'] == 'all' || $node->get('active') || 0 === strpos($node->path . '/', $rootPath) || $depth == $startLevel)) {
             $node->setParent();
             continue;
         }
         $node->setParent($parent);
         if ($node->get('active') && $depth == $startLevel - 1) {
             $root = $node;
         }
     }
     if (!isset($root)) {
         return null;
     }
     $root->setParent();
     return $root;
 }
예제 #9
0
 public function onRoleDelete($event, $role)
 {
     Node::removeRole($role);
 }
예제 #10
0
 /**
  * @Route("/{id}", methods="DELETE")
  * @Request({"id"}, csrf=true)
  */
 public function deleteAction($id)
 {
     App::config('system/site')->remove('menus.' . $id);
     Node::where(['menu = :id'], [':id' => $id])->update(['menu' => 'trash', 'status' => 0]);
     return ['message' => 'success'];
 }
 /**
  * Add a path to the breadcrumbs
  * @param Node $node
  * @return $this
  */
 public function addNode(Node $node)
 {
     $this->breadcrumbs->add(['title' => $node->title, 'url' => $node->getUrl(), 'data' => $node->data]);
     return $this;
 }
 /**
  * @Route("/frontpage", methods="POST")
  * @Request({"id": "int"}, csrf=true)
  */
 public function frontpageAction($id)
 {
     if (!($node = Node::find($id)) or !($type = App::module('system/site')->getType($node->type))) {
         App::abort(404, __('Node not found.'));
     }
     if (isset($type['frontpage']) and !$type['frontpage']) {
         App::abort(400, __('Invalid node type.'));
     }
     App::config('system/site')->set('frontpage', $id);
     return ['message' => 'success'];
 }
예제 #13
0
파일: index.php 프로젝트: pagekit/pagekit
<?php

use Pagekit\Site\Event\MaintenanceListener;
use Pagekit\Site\Event\NodesListener;
use Pagekit\Site\Event\PageListener;
use Pagekit\Site\MenuHelper;
use Pagekit\Site\Model\Node;
return ['name' => 'system/site', 'main' => 'Pagekit\\Site\\SiteModule', 'autoload' => ['Pagekit\\Site\\' => 'src'], 'nodes' => ['page' => ['name' => '@page', 'label' => 'Page', 'controller' => 'Pagekit\\Site\\Controller\\PageController::indexAction']], 'routes' => ['/' => ['name' => '@site', 'controller' => 'Pagekit\\Site\\Controller\\NodeController'], '/api/site/menu' => ['name' => '@site/api/menu', 'controller' => 'Pagekit\\Site\\Controller\\MenuApiController'], '/api/site/node' => ['name' => '@site/api/node', 'controller' => 'Pagekit\\Site\\Controller\\NodeApiController'], '/api/site/page' => ['name' => '@site/api/page', 'controller' => 'Pagekit\\Site\\Controller\\PageApiController']], 'widgets' => ['widgets/menu.php', 'widgets/text.php'], 'resources' => ['system/site:' => '', 'views:system/site' => 'views'], 'permissions' => ['site: manage site' => ['title' => 'Manage site'], 'site: maintenance access' => ['title' => 'Use the site in maintenance mode']], 'menu' => ['site' => ['label' => 'Site', 'icon' => 'system/site:assets/images/icon-site.svg', 'url' => '@site/page', 'access' => 'site: manage site || system: manage widgets || system: manage storage || system: access settings', 'active' => '@site*', 'priority' => 105], 'site: pages' => ['label' => 'Pages', 'parent' => 'site', 'url' => '@site/page', 'access' => 'site: manage site', 'active' => '@site/page(/edit)?'], 'site: settings' => ['label' => 'Settings', 'parent' => 'site', 'url' => '@site/settings', 'access' => 'system: access settings', 'priority' => 30]], 'config' => ['menus' => [], 'frontpage' => 0, 'title' => '', 'description' => '', 'maintenance' => ['enabled' => false, 'logo' => '', 'msg' => ''], 'icons' => ['favicon' => false, 'appicon' => false], 'code' => ['header' => '', 'footer' => ''], 'view' => ['logo' => '']], 'events' => ['boot' => function ($event, $app) {
    $app->subscribe(new MaintenanceListener(), new NodesListener(), new PageListener());
    Node::defineProperty('theme', function () use($app) {
        $config = $app['theme']->config('_nodes.' . $this->id, []);
        $default = $app['theme']->get('node', []);
        return array_replace_recursive($default, $config);
    }, true);
}, 'request' => [function () use($app) {
    if (!$app['node']->hasAccess($app['user'])) {
        $app['kernel']->abort(403, __('Insufficient User Rights.'));
    }
}, -100], 'site' => function ($event, $app) {
    $app->on('view.head', function ($event) use($app) {
        $event->addResult($this->config('code.header'));
    }, -10);
    $app->on('view.footer', function ($event) use($app) {
        $event->addResult($this->config('code.footer'));
    }, -10);
    $app->on('view.init', function ($event, $view) use($app) {
        $view->params->set('title', $this->config('title'));
        $view->params->merge($this->config('view'));
        $view->params->merge($app['theme']->config);
        $view->params->merge($app['node']->theme);
    }, 10);