Skip to content

Commit

Permalink
admin partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
studentIvan committed May 16, 2012
1 parent e4c1f0c commit d365709
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@
'sessions' => true,
'users' => true,
'email_confirm' => true,
'extends' => array('demo'),
),
);
14 changes: 14 additions & 0 deletions controllers/admin/DemoPart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
class DemoPart extends AdminPartition
{
public function getUserInterfaceData()
{
return array(
'link' => 'demo',
'name' => 'Демо',
'description' => 'Демо раздел админ-панели.',
'count' => false,
'plural' => false
);
}
}
8 changes: 8 additions & 0 deletions solutions/standard/__init__.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
25 changes: 22 additions & 3 deletions solutions/standard/controllers/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class Admin
{
protected static $checkCsrfToken = false;
protected static $extends = array();
public static $notFoundBreak = false;

public static function control($matches)
{
Expand All @@ -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();
Expand Down Expand Up @@ -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');
}
Expand Down
37 changes: 37 additions & 0 deletions solutions/standard/extends/AdminPartition.php
Original file line number Diff line number Diff line change
@@ -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' => 'ов',
)
);
}
}
12 changes: 12 additions & 0 deletions solutions/standard/views/admin/manager.html.twig
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down
1 change: 1 addition & 0 deletions views/admin/components/demo.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEMO
Binary file added webroot/images/admin/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d365709

Please sign in to comment.