first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
name = Custom rulesets
description = Create custom, exportable, reusable access rulesets for applications like Panels.
core = 7.x
package = Chaos tool suite
dependencies[] = ctools
; Information added by drupal.org packaging script on 2013-02-02
version = "7.x-1.2+31-dev"
core = "7.x"
project = "ctools"
datestamp = "1359766341"

View File

@@ -0,0 +1,82 @@
<?php
/**
* Schema for customizable access rulesets.
*/
function ctools_access_ruleset_schema() {
return ctools_access_ruleset_schema_1();
}
function ctools_access_ruleset_schema_1() {
$schema = array();
$schema['ctools_access_ruleset'] = array(
'description' => 'Contains exportable customized access rulesets.',
'export' => array(
'identifier' => 'ruleset',
'bulk export' => TRUE,
'primary key' => 'rsid',
'api' => array(
'owner' => 'ctools_access_ruleset',
'api' => 'ctools_rulesets',
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'rsid' => array(
'type' => 'serial',
'description' => 'A database primary key to ensure uniqueness',
'not null' => TRUE,
'no export' => TRUE,
),
'name' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'Unique ID for this ruleset. Used to identify it programmatically.',
),
'admin_title' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'Administrative title for this ruleset.',
),
'admin_description' => array(
'type' => 'text',
'size' => 'big',
'description' => 'Administrative description for this ruleset.',
'object default' => '',
),
'requiredcontexts' => array(
'type' => 'text',
'size' => 'big',
'description' => 'Any required contexts for this ruleset.',
'serialize' => TRUE,
'object default' => array(),
),
'contexts' => array(
'type' => 'text',
'size' => 'big',
'description' => 'Any embedded contexts for this ruleset.',
'serialize' => TRUE,
'object default' => array(),
),
'relationships' => array(
'type' => 'text',
'size' => 'big',
'description' => 'Any relationships for this ruleset.',
'serialize' => TRUE,
'object default' => array(),
),
'access' => array(
'type' => 'text',
'size' => 'big',
'description' => 'The actual group of access plugins for this ruleset.',
'serialize' => TRUE,
'object default' => array(),
),
),
'primary key' => array('rsid'),
);
return $schema;
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* @file
* ctools_access_ruleset module
*
* This module allows styles to be created and managed on behalf of modules
* that implement styles.
*
* The ctools_access_ruleset tool allows recolorable styles to be created via a miniature
* scripting language. Panels utilizes this to allow administrators to add
* styles directly to any panel display.
*/
/**
* Implementation of hook_permission()
*/
function ctools_access_ruleset_permission() {
return array(
'administer ctools access ruleset' => array(
'title' => t('Administer access rulesets'),
'description' => t('Add, delete and edit custom access rulesets.'),
),
);
}
/**
* Implementation of hook_ctools_plugin_directory() to let the system know
* we implement task and task_handler plugins.
*/
function ctools_access_ruleset_ctools_plugin_directory($module, $plugin) {
// Most of this module is implemented as an export ui plugin, and the
// rest is in ctools/includes/ctools_access_ruleset.inc
if ($module == 'ctools' && ($plugin == 'export_ui' || $plugin == 'access')) {
return 'plugins/' . $plugin;
}
}
/**
* Implementation of hook_panels_dashboard_blocks().
*
* Adds page information to the Panels dashboard.
*/
function ctools_access_ruleset_panels_dashboard_blocks(&$vars) {
$vars['links']['ctools_access_ruleset'] = array(
'title' => l(t('Custom ruleset'), 'admin/structure/ctools-rulesets/add'),
'description' => t('Custom rulesets are combinations of access plugins you can use for access control, selection criteria and pane visibility.'),
);
// Load all mini panels and their displays.
ctools_include('export');
$items = ctools_export_crud_load_all('ctools_access_ruleset');
$count = 0;
$rows = array();
foreach ($items as $item) {
$rows[] = array(
check_plain($item->admin_title),
array(
'data' => l(t('Edit'), "admin/structure/ctools-rulesets/list/$item->name/edit"),
'class' => 'links',
),
);
// Only show 10.
if (++$count >= 10) {
break;
}
}
if ($rows) {
$content = theme('table', array('rows' => $rows, 'attributes' => array('class' => 'panels-manage')));
}
else {
$content = '<p>' . t('There are no custom rulesets.') . '</p>';
}
$vars['blocks']['ctools_access_ruleset'] = array(
'title' => t('Manage custom rulesets'),
'link' => l(t('Go to list'), 'admin/structure/ctools-rulesets'),
'content' => $content,
'class' => 'dashboard-ruleset',
'section' => 'right',
);
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* @file
* Plugin to provide access control based on user rulesetission strings.
*/
/**
* Plugins are described by creating a $plugin array which will be used
* by the system that includes this file.
*/
$plugin = array(
'title' => '',
'description' => '',
'callback' => 'ctools_ruleset_ctools_access_check',
'settings form' => 'ctools_ruleset_ctools_access_settings',
'summary' => 'ctools_ruleset_ctools_access_summary',
// This access plugin actually just contains child plugins that are
// exportable, UI configured rulesets.
'get child' => 'ctools_ruleset_ctools_access_get_child',
'get children' => 'ctools_ruleset_ctools_access_get_children',
);
/**
* Merge the main access plugin with a loaded ruleset to form a child plugin.
*/
function ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item) {
$plugin['name'] = $parent . ':' . $item->name;
$plugin['title'] = check_plain($item->admin_title);
$plugin['description'] = check_plain($item->admin_description);
// TODO: Generalize this in CTools.
if (!empty($item->requiredcontexts)) {
$plugin['required context'] = array();
foreach ($item->requiredcontexts as $context) {
$info = ctools_get_context($context['name']);
// TODO: allow an optional setting
$plugin['required context'][] = new ctools_context_required($context['identifier'], $info['context name']);
}
}
// Store the loaded ruleset in the plugin.
$plugin['ruleset'] = $item;
return $plugin;
}
/**
* Get a single child access plugin.
*/
function ctools_ruleset_ctools_access_get_child($plugin, $parent, $child) {
ctools_include('export');
$item = ctools_export_crud_load('ctools_access_ruleset', $child);
if ($item) {
return ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item);
}
}
/**
* Get all child access plugins.
*/
function ctools_ruleset_ctools_access_get_children($plugin, $parent) {
$plugins = array();
ctools_include('export');
$items = ctools_export_crud_load_all('ctools_access_ruleset');
foreach ($items as $name => $item) {
$child = ctools_ruleset_ctools_access_merge_plugin($plugin, $parent, $item);
$plugins[$child['name']] = $child;
}
return $plugins;
}
/**
* Settings form for the 'by ruleset' access plugin
*/
function ctools_ruleset_ctools_access_settings(&$form, &$form_state, $conf) {
if (!empty($form_state['plugin']['ruleset']->admin_description)) {
$form['markup'] = array(
'#markup' => '<div class="description">' . check_plain($form_state['plugin']['ruleset']->admin_description) . '</div>',
);
}
return $form;
}
/**
* Check for access.
*/
function ctools_ruleset_ctools_access_check($conf, $context, $plugin) {
// Load up any contexts we might be using.
$contexts = ctools_context_match_required_contexts($plugin['ruleset']->requiredcontexts, $context);
$contexts = ctools_context_load_contexts($plugin['ruleset'], FALSE, $contexts);
return ctools_access($plugin['ruleset']->access, $contexts);
}
/**
* Provide a summary description based upon the checked roles.
*/
function ctools_ruleset_ctools_access_summary($conf, $context, $plugin) {
if (!empty($plugin['ruleset']->admin_description)) {
return check_plain($plugin['ruleset']->admin_description);
}
else {
return check_plain($plugin['ruleset']->admin_title);
}
}

View File

@@ -0,0 +1,29 @@
<?php
$plugin = array(
'schema' => 'ctools_access_ruleset',
'access' => 'administer ctools access ruleset',
'menu' => array(
'menu item' => 'ctools-rulesets',
'menu title' => 'Custom access rulesets',
'menu description' => 'Add, edit or delete custom access rulesets for use with Panels and other systems that utilize CTools content plugins.',
),
'title singular' => t('ruleset'),
'title singular proper' => t('Ruleset'),
'title plural' => t('rulesets'),
'title plural proper' => t('Rulesets'),
'handler' => 'ctools_access_ruleset_ui',
'use wizard' => TRUE,
'form info' => array(
'order' => array(
'basic' => t('Basic information'),
'context' => t('Contexts'),
'rules' => t('Rules'),
),
),
);

View File

@@ -0,0 +1,53 @@
<?php
class ctools_access_ruleset_ui extends ctools_export_ui {
function edit_form_context(&$form, &$form_state) {
ctools_include('context-admin');
ctools_context_admin_includes();
ctools_add_css('ruleset');
$form['right'] = array(
'#prefix' => '<div class="ctools-right-container">',
'#suffix' => '</div>',
);
$form['left'] = array(
'#prefix' => '<div class="ctools-left-container clearfix">',
'#suffix' => '</div>',
);
// Set this up and we can use CTools' Export UI's built in wizard caching,
// which already has callbacks for the context cache under this name.
$module = 'export_ui::' . $this->plugin['name'];
$name = $this->edit_cache_get_key($form_state['item'], $form_state['form type']);
ctools_context_add_context_form($module, $form, $form_state, $form['right']['contexts_table'], $form_state['item'], $name);
ctools_context_add_required_context_form($module, $form, $form_state, $form['left']['required_contexts_table'], $form_state['item'], $name);
ctools_context_add_relationship_form($module, $form, $form_state, $form['right']['relationships_table'], $form_state['item'], $name);
}
function edit_form_rules(&$form, &$form_state) {
// The 'access' UI passes everything via $form_state, unlike the 'context' UI.
// The main difference is that one is about 3 years newer than the other.
ctools_include('context');
ctools_include('context-access-admin');
$form_state['access'] = $form_state['item']->access;
$form_state['contexts'] = ctools_context_load_contexts($form_state['item']);
$form_state['module'] = 'ctools_export_ui';
$form_state['callback argument'] = $form_state['object']->plugin['name'] . ':' . $form_state['object']->edit_cache_get_key($form_state['item'], $form_state['form type']);
$form_state['no buttons'] = TRUE;
$form = ctools_access_admin_form($form, $form_state);
}
function edit_form_rules_submit(&$form, &$form_state) {
$form_state['item']->access['logic'] = $form_state['values']['logic'];
}
function edit_form_submit(&$form, &$form_state) {
parent::edit_form_submit($form, $form_state);
}
}