Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

admin partitions

  • Loading branch information...
commit d365709dd0bfe1e0ea50465579c5d26fa2759f16 1 parent e4c1f0c
@studentIvan authored
View
2  README.md
@@ -1,6 +1,6 @@
# Tranquility
## Content Management Framework
-## Version 0.2.1.0 [![endorse](http://api.coderwall.com/studentivan/endorse.png)](http://coderwall.com/studentivan)
+## Version 0.3.0.0 [![endorse](http://api.coderwall.com/studentivan/endorse.png)](http://coderwall.com/studentivan)
### Features
* Easy to install and use
View
1  config/config.php
@@ -120,5 +120,6 @@
'sessions' => true,
'users' => true,
'email_confirm' => true,
+ 'extends' => array('demo'),
),
);
View
14 controllers/admin/DemoPart.php
@@ -0,0 +1,14 @@
+<?php
+class DemoPart extends AdminPartition
+{
+ public function getUserInterfaceData()
+ {
+ return array(
+ 'link' => 'demo',
+ 'name' => 'Демо',
+ 'description' => 'Демо раздел админ-панели.',
+ 'count' => false,
+ 'plural' => false
+ );
+ }
+}
View
8 solutions/standard/__init__.php
@@ -14,4 +14,12 @@
require_once $__DIRADM__ . '/datamappers/Users.php';
require_once $__DIRADM__ . '/datamappers/Roles.php';
}
+
+ if (isset($config['cms']['extends']) and $config['cms']['extends']) {
+ require_once $__DIRADM__ . '/extends/AdminPartition.php';
+ foreach ($config['cms']['extends'] as $extend) {
+ $extend = ucfirst($extend) . 'Part.php';
+ require_once $__DIRADM__ . '/../../controllers/admin/' . $extend;
+ }
+ }
}
View
25 solutions/standard/controllers/Admin.php
@@ -2,6 +2,8 @@
class Admin
{
protected static $checkCsrfToken = false;
+ protected static $extends = array();
+ public static $notFoundBreak = false;
public static function control($matches)
{
@@ -10,9 +12,16 @@ public static function control($matches)
$express = isset($matches[2]) ?
preg_replace('/[^a-z]/', '', $matches[2]) : false;
Process::$context['admin_page'] = $page;
+ self::$checkCsrfToken = (isset($_GET['csrf_token']) and
+ Process::$context['csrf_token'] === $_GET['csrf_token']);
+ if (isset(Process::$context['cms']['extends']) and Process::$context['cms']['extends'])
+ {
+ foreach (Process::$context['cms']['extends'] as $extend) {
+ $extend = ucfirst($extend) . 'Part';
+ self::$extends[] = new $extend(($express ? $express : null));
+ }
+ }
if (method_exists('Admin', $page)) {
- self::$checkCsrfToken = (isset($_GET['csrf_token']) and
- Process::$context['csrf_token'] === $_GET['csrf_token']);
call_user_func(array('Admin', $page), ($express ? $express : null));
} else {
self::secure();
@@ -302,11 +311,21 @@ public static function manager($component = false)
break;
default:
- throw new NotFoundException();
+ if (!self::$notFoundBreak)
+ throw new NotFoundException();
}
}
else
{
+ Process::$context['admin_extend'] = array();
+
+ foreach (self::$extends as $extend) {
+ /**
+ * @var $extend AdminPartition
+ */
+ Process::$context['admin_extend'][] = $extend->getUserInterfaceData();
+ }
+
if (isset(Process::$context['cms']['news']) and Process::$context['cms']['news']) {
Process::$context['news_count'] = Database::count('news');
}
View
37 solutions/standard/extends/AdminPartition.php
@@ -0,0 +1,37 @@
+<?php
+abstract class AdminPartition
+{
+ public function __construct($component = null)
+ {
+ $data = $this->getUserInterfaceData();
+ if ($component and $component == $data['link'])
+ {
+ Admin::$notFoundBreak = true;
+ Process::$context['component'] = $component;
+ $page = isset($_GET['page']) ? abs($_GET['page']) : 1;
+ $action = isset($_GET['action']) ? $_GET['action'] : false;
+ $identify = isset($_GET['identify']) ? abs($_GET['identify']) : false;
+
+ Process::$context['data_action'] = $action;
+ if (method_exists($this, $action)) {
+ $this->$action($page, $identify);
+ }
+ }
+ }
+
+ public function getUserInterfaceData()
+ {
+ return array(
+ 'link' => 'admin_partition',
+ 'name' => 'Admin Partition',
+ 'description' => 'Admin partition.',
+ 'count' => 0,
+ 'plural' => array(
+ 'root' => 'админ',
+ 'first' => '',
+ 'second' => 'а',
+ 'third' => 'ов',
+ )
+ );
+ }
+}
View
12 solutions/standard/views/admin/manager.html.twig
@@ -1,6 +1,18 @@
{% if not custom_content_view %}<div data-role="content" id="manager_content">{% endif %}
{% if not component %}
<ul data-role="listview">
+ {% for custom_admin_part in admin_extend %}
+ <li>
+ <a href="/admin/manager/{{ custom_admin_part.link }}">
+ {% if not mobile %}<img src="/images/admin/{{ custom_admin_part.link }}.png" alt="" />{% endif %}
+ <h3>{{ custom_admin_part.name }}</h3>
+ <p>{{ custom_admin_part.description }}</p>
+ </a>
+ {% if custom_admin_part.count %}<span class="ui-li-count">
+ {{ (custom_admin_part.count ~ " " ~ custom_admin_part.plural.root)|plural(custom_admin_part.plural.first, custom_admin_part.plural.second, custom_admin_part.plural.third) }}
+ </span>{% endif %}
+ </li>
+ {% endfor %}
{% if cms.news %}<li>
<a href="/admin/manager/news">
{% if not mobile %}<img src="/images/admin/news.png" alt="" />{% endif %}
View
1  views/admin/components/demo.html.twig
@@ -0,0 +1 @@
+DEMO
View
BIN  webroot/images/admin/demo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.