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,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);
}
}