Index: context.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context.info,v retrieving revision 1.2.2.1 diff -u -r1.2.2.1 context.info --- context.info 9 Apr 2008 01:51:52 -0000 1.2.2.1 +++ context.info 13 Jul 2008 20:49:48 -0000 @@ -1,4 +1,5 @@ -; $Id: context.info,v 1.2.2.1 2008/04/09 01:51:52 jmiccolis Exp $ +; $Id$ name = Context description = "Provide modules with a cache that lasts for a single page request." -package = Context \ No newline at end of file +package = Context +core = "6.x" Index: context.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context.module,v retrieving revision 1.2.2.1 diff -u -r1.2.2.1 context.module --- context.module 23 Mar 2008 13:14:23 -0000 1.2.2.1 +++ context.module 12 Jul 2008 23:50:49 -0000 @@ -1,5 +1,10 @@ t('context_prefix.'), + 'fields' => array( + 'prefix' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'module' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'id' => array( + 'description' => t('?'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('prefix'), + ); -function context_prefix_update_2() { - $items = array(); - $items[] = update_sql("CREATE TABLE {context_prefix} (space VARCHAR(255) NOT NULL, path VARCHAR(255) NOT NULL, id INT(10) NOT NULL, PRIMARY KEY (path))"); - $paths = variable_get('context_paths', array()); - if ($paths) { - foreach ($paths as $space => $p) { - foreach ($p as $path => $nid) { - db_query("REPLACE INTO {context_prefix} (space, path, id) VALUES('%s', '%s', %d)", $space, $path, $nid); - } - } - variable_del('context_paths'); - } - return $items; + return $schema; } -function context_prefix_update_3() { - $items = array(); - $items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN space space VARCHAR(255) NOT NULL;"); - $items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN path path VARCHAR(255) NOT NULL;"); - $items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN id id VARCHAR(255) NOT NULL;"); - return $items; +/** + * Implementation of hook_uninstall(). + */ +function context_prefix_uninstall() { + drupal_uninstall_schema('context_prefix'); } - -function context_prefix_update_4() { - $items = array(); - $items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN space module VARCHAR(255) NOT NULL;"); - $items[] = update_sql("ALTER TABLE {context_prefix} CHANGE COLUMN path prefix VARCHAR(255) NOT NULL;"); - return $items; -} \ No newline at end of file Index: context_prefix/context_prefix.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_prefix/Attic/context_prefix.module,v retrieving revision 1.1.2.4 diff -u -r1.1.2.4 context_prefix.module --- context_prefix/context_prefix.module 9 Jun 2008 16:08:59 -0000 1.1.2.4 +++ context_prefix/context_prefix.module 13 Jul 2008 20:20:00 -0000 @@ -1,36 +1,39 @@ module_exists('context_ui') ? MENU_LOCAL_TASK : MENU_NORMAL_ITEM, + 'title' => 'Context Prefixes', + 'description' => 'Displays a list of context definitions.', + 'page callback' => 'context_prefix_admin', + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'weight' => 10, + ); -define(CONTEXT_PREFIX_PATH, 0); -define(CONTEXT_PREFIX_SUBDOMAIN, 1); -define(CONTEXT_PREFIX_DOMAIN, 2); - -/** - * Implementation of hook_menu() - */ -function context_prefix_menu($may_cache) { - $items = array(); - if ($may_cache) { - $items[] = array( - 'type' => module_exists('context_ui') ? MENU_LOCAL_TASK : MENU_NORMAL_ITEM, - 'title' => t('Context Prefixes'), - 'description' => t('Displays a list of context definitions.'), - 'path' => 'admin/build/context/prefix', - 'callback' => 'context_prefix_admin', - 'access' => user_access('administer site configuration'), - 'weight' => 10, - ); - } return $items; } /** - * Implementation of hook_init() - * Checks for any valid context prefixes in request string and sets the context appropriately + * Implementation of hook_init(). + * Checks for any valid context prefixes in request string and sets the context appropriately. */ function context_prefix_init() { $location = variable_get('context_prefix_prefix_location', CONTEXT_PREFIX_PATH); - switch($location) { + switch ($location) { case CONTEXT_PREFIX_DOMAIN: context_prefix_prepare_domain(); break; @@ -86,7 +89,7 @@ function context_prefix_prepare_domain() { $host = $_SERVER['HTTP_HOST']; // We handle sub.domain.com, and nothing more (no sub1.sub2.domain.com). - $prefix = str_replace('http://','',$host); + $prefix = str_replace('http://', '', $host); $items = context_prefix_items(); if (isset($items[$prefix]) && $active = $items[$prefix] ) { context_set('context_prefix', $active->module, $active->id); @@ -155,7 +158,7 @@ /** * Returns an array of available context definitions. If provided an * optional module argument, will only provide definitions for the - * specified module. + * specified module. */ function context_prefix_items($module = NULL) { static $items; @@ -191,7 +194,7 @@ $prefix = array_shift($exploded_q); } } - // check that this prefix is valid + // check that this prefix is valid $valid = context_prefix_items(); if (isset($valid[$prefix])) { return $prefix; @@ -202,7 +205,7 @@ } /** - * Taken from i18n + * Taken from i18n. */ function _context_prefix_get_normal_path($path, $prefix) { // If bootstrap, drupal_lookup_path is not defined @@ -219,7 +222,7 @@ } /** - * Jose's very smart collision avoidance + * Jose's very smart collision avoidance. */ if (!function_exists('custom_url_rewrite')) { function custom_url_rewrite($type, $path, $original) { @@ -264,7 +267,7 @@ } } } - + if ($working_path) { $prefix[] = $working_path; } @@ -289,7 +292,7 @@ if ($path == '') { $path = variable_get('site_frontpage', 'node'); } - $path = variable_get('context_prefix_base_domain', '') . '/' . $path; // REPLACE BASE_URL with the hub domain. + $path = variable_get('context_prefix_base_domain', '') .'/'. $path; // REPLACE BASE_URL with the hub domain. break; } } @@ -345,7 +348,7 @@ // Add active class for active menu items if (stristr($key, 'active')) { $class .= " active"; - } + } // Add first and last classes to the list of links to help out themers. $extra_class = ''; @@ -399,13 +402,13 @@ $form['context_prefix_location'] = array( '#type' => 'fieldset', '#title' => t('Prefix location settings'), - ); + ); $options = array( CONTEXT_PREFIX_PATH => t('Path prefix'), CONTEXT_PREFIX_DOMAIN => t('Full domain'), // TODO: Implement these features // CONTEXT_PREFIX_SUBDOMAIN => t('Subdomain'), - ); + ); $form['context_prefix_location']['context_prefix_prefix_location'] = array( '#type' => 'select', '#title' => t('Select prefix location'), @@ -415,14 +418,14 @@ '#multiple' => FALSE, '#options' => $options, '#default_value' => variable_get('context_prefix_prefix_location', CONTEXT_PREFIX_PATH), - ); + ); $form['context_prefix_location']['context_prefix_base_domain'] = array( '#type' => 'textfield', '#title' => t('Select base domain for hub'), '#description' => t('This setting determines the base sub-domain. Enter only the part of the domain, like www'), '#required' => FALSE, '#default_value' => variable_get('context_prefix_base_domain', $base_url), - ); + ); return system_settings_form($form); } @@ -433,9 +436,9 @@ */ function context_prefix_goto($prefix, $path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) { global $base_url; - /** + /** * TODO: we need to abstract this base_url dissection into a - * handler, and in there, we'll abstract out for + * handler, and in there, we'll abstract out for * protocol handling, and handling the site's base_url like www. */ switch (variable_get('context_prefix_prefix_location', CONTEXT_PREFIX_PATH)) { Index: context_ui/context_ui.css =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_ui/context_ui.css,v retrieving revision 1.1.2.3 diff -u -r1.1.2.3 context_ui.css --- context_ui/context_ui.css 5 Jun 2008 14:20:41 -0000 1.1.2.3 +++ context_ui/context_ui.css 13 Jul 2008 20:47:12 -0000 @@ -1,3 +1,5 @@ +/* $Id$ */ + /** * Context devel block ================================================ */ Index: context_ui/context_ui.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_ui/context_ui.info,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 context_ui.info --- context_ui/context_ui.info 1 Apr 2008 15:01:46 -0000 1.1.2.2 +++ context_ui/context_ui.info 13 Jul 2008 20:49:23 -0000 @@ -1,5 +1,6 @@ -; $Id: context_ui.info,v 1.1.2.2 2008/04/01 15:01:46 yhahn Exp $ +; $Id$ name = Context UI description = "Provides a simple UI for settings up a site structure using Context." -dependencies = context -package = Context \ No newline at end of file +dependencies[] = context +package = Context +core = "6.x" Index: context_ui/context_ui.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_ui/context_ui.install,v retrieving revision 1.1.2.3 diff -u -r1.1.2.3 context_ui.install --- context_ui/context_ui.install 9 May 2008 01:32:21 -0000 1.1.2.3 +++ context_ui/context_ui.install 13 Jul 2008 20:44:55 -0000 @@ -1,35 +1,157 @@ t('context_ui.'), + 'fields' => array( + 'cid' => array( + 'description' => t('The primary identifier for a context.'), + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'system' => array( + 'description' => t('?'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'status' => array( + 'description' => t('?'), + 'type' => 'int', + 'size' => 'tiny', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'space' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'ckey' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'value' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + ), + 'unique keys' => array( + 'key1' => array('system', 'space', 'ckey', 'value'), + ), + 'primary key' => array('cid'), + ); + + $schema['context_ui_item'] = array( + 'description' => t('context_ui_item.'), + 'fields' => array( + 'type' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + ), + 'id' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'cid' => array( + 'description' => t('?'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'unique keys' => array( + 'key1' => array('id', 'type', 'cid'), + ), + /* 'primary key' => array(''), */ + ); + + $schema['context_ui_block'] = array( + 'description' => t('context_ui_block.'), + 'fields' => array( + 'module' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'delta' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + ), + 'region' => array( + 'description' => t('?'), + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ), + 'weight' => array( + 'description' => t('?'), + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0, + ), + 'cid' => array( + 'description' => t('?'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'unique keys' => array( + 'key1' => array('module', 'delta', 'region', 'cid'), + ), + /* 'primary key' => array(''), */ + ); + + return $schema; } /** - * hook_uninstall(). + * Implementation of hook_uninstall(). */ function context_ui_uninstall() { - db_query('DROP TABLE {context_ui}'); - db_query('DROP TABLE {context_ui_item}'); - db_query('DROP TABLE {context_ui_block}'); + drupal_uninstall_schema('context_ui'); } Index: context_ui/context_ui.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_ui/context_ui.js,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 context_ui.js --- context_ui/context_ui.js 1 Apr 2008 15:01:46 -0000 1.1.2.2 +++ context_ui/context_ui.js 13 Jul 2008 20:47:50 -0000 @@ -1,10 +1,12 @@ +// $Id$ + if (typeof(Drupal) == "undefined" || !Drupal.context_ui) { Drupal.context_ui = {}; } Drupal.context_ui.attach = function() { var item_tools = "
UpDownX
"; - + // multiselect handler $("input#edit-block-selector-add").click(function() { var region = $("select#edit-block-selector-regions").val(); @@ -12,7 +14,7 @@ if (selected.size() > 0) { $("div.context-ui-block-regions ul." + region + " li.dummy").remove(); selected.each(function() { - if (!$(this).attr('disabled')) { + if (!$(this).attr('disabled')) { // create new block li var block = document.createElement('li'); var value = $(this).attr('value'); @@ -26,14 +28,14 @@ $(this).remove(); // add block item to region - $("div.context-ui-block-regions ul."+ region).append(block); - + $("div.context-ui-block-regions ul."+ region).append(block); + Drupal.context_ui.regionblocks(region); } }); } }); - + // attach tool handler to existing context_ui blocks $("div.context-ui-block-regions ul li").each(function() { Drupal.context_ui.attachtools(this); @@ -56,12 +58,12 @@ // retrieve region info before item is deleted var region = $(item).parents("ul").attr("class"); - // remove block item + // remove block item item.remove(); - + // add block option - $("select#edit-block-selector-blocks").append(option); - + $("select#edit-block-selector-blocks").append(option); + Drupal.context_ui.regionblocks(region); }); // move block up @@ -96,7 +98,7 @@ } else { serialized = serialized +","+ $(this).attr('title'); - } + } }); $("input#edit-block-regions-"+ region).val(serialized); } @@ -108,7 +110,7 @@ if (Drupal.jsEnabled) { $(document).ready(function() { if ($('form#context-ui-form').size() > 0) { - Drupal.context_ui.attach(); + Drupal.context_ui.attach(); } }); }; Index: context_ui/context_ui.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_ui/context_ui.module,v retrieving revision 1.1.2.22 diff -u -r1.1.2.22 context_ui.module --- context_ui/context_ui.module 11 Jul 2008 16:06:22 -0000 1.1.2.22 +++ context_ui/context_ui.module 13 Jul 2008 20:18:21 -0000 @@ -1,10 +1,61 @@ array('form' => array()), + /* 'file' => '', */ + ); + $items['context_ui_block_ui'] = array( + 'arguments' => array('form' => array()), + 'file' => 'context_ui_admin.inc', + ); + $items['context_ui_admin'] = array( + 'arguments' => array('form' => array()), + 'file' => 'context_ui_admin.inc', + ); + + $items['context_devel'] = array( + 'arguments' => array('form' => array()), + /* 'file' => '', */ + ); + $items['context_devel_recurse'] = array( + 'arguments' => array('form' => array()), + /* 'file' => '', */ + ); + + return $items; +} + +/** + * Implementation of hook_block(). + */ +function context_ui_block($op = 'list', $delta = 0, $edit = array()) { $block = array(); if ($op == 'list') { $block['devel']['info'] = t('Context Devel'); @@ -19,7 +70,7 @@ $block['content'] = $output; } else { - $block['content'] = "

". t('No context information is set.') ."

"; + $block['content'] = '

'. t('No context information is set.') .'

'; } break; } @@ -28,7 +79,7 @@ } /** - * hook_context_items() + * hook_context_items(). */ function context_ui_context_items() { $items = array(); @@ -36,14 +87,14 @@ // Content Types $nodetypes = array(); foreach (node_get_types() as $type) { - $nodetypes[$type->type] = t($type->name); - } + $nodetypes[$type->type] = t($type->name); // @todo: this t() is wrong + } $items['node'] = array( 'title' => t('Content Types'), 'description' => t('Set this context when viewing a node page or using the add/edit form of one of these content types.'), 'options' => $nodetypes, ); - + // Views if (module_exists('views')) { $items['views'] = array( @@ -52,26 +103,20 @@ 'options' => _context_ui_get_views(), ); } - + // Menu if (module_exists('menu')) { - // grab menu cache - global $_menu; - $menus = array(); - // build options using root menus - foreach (array_reverse(menu_get_root_menus(), true) as $root_mid => $root_menu) { - // build menu options from children of each root menu - $menu = array(); - $options = menu_parent_options(0, $root_mid, 0); - unset($options[key($options)]); - foreach ($options as $mid => $title) { - $path = $_menu['items'][$mid]['path']; - $menu[$path] = $title; + // $item = array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => 'navigation', 'weight' => 0, 'link_path' => '', 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0); + // @note: NULL value seems to work here, but it is not documented that it should work + $menus = menu_parent_options(array_reverse(menu_get_menus()), NULL); + + // this is required because root menu names are displayed inside <> and will not de displayed otherwise + foreach ($menus as $key => $name) { + if (substr($menus[$key], 0, 1) == '<') { + $menus[$key] = ''. check_plain($menus[$key]) .''; } - $path = $_menu['items'][$root_mid]['path']; - $menus[$root_mid] = "". $root_menu .""; - $menus = $menus + $menu; } + $items['menu'] = array( 'title' => t('Menus'), 'description' => t('Display the selected menu items as active when this context is set.'), @@ -79,14 +124,14 @@ 'widget' => 'select', ); } - + $items['user'] = array( 'title' => t('User Pages'), 'description' => t('Set this context when a user with selected role(s) is viewed'), 'options' => user_roles(true), 'widget' => 'select', ); - + if (module_exists('nodequeue')) { $result = db_query("SELECT qid, title FROM {nodequeue_queue}"); $options = array(); @@ -97,7 +142,7 @@ 'title' => t('Nodequeue'), 'description' => t('Set this context when a node in the selected nodequeue(s) is viewed.'), 'options' => $options, - 'widget' => 'select', + 'widget' => 'select', ); } @@ -112,113 +157,97 @@ 'title' => t('Outline'), 'description' => t('Set this context when a node in the selected volumes(s) is viewed.'), 'options' => $options, - 'widget' => 'select', + 'widget' => 'select', ); } - + return $items; } -/* - * Implementation of hook_menu() +/** + * Implementation of hook_menu(). */ -function context_ui_menu($may_cache) { - $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/build/context', - 'callback' => 'context_ui_admin', - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - 'title' => t('Context'), - 'description' => t('Associate menus, views, blocks, etc. with different contexts to structure your site.') - ); - $items[] = array( - 'path' => 'admin/build/context/list', - 'title' => t('List'), - 'callback' => 'context_ui_admin', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 0, - ); - $items[] = array( - 'path' => 'admin/build/context/add', - 'callback' => 'drupal_get_form', - 'callback arguments' => array('context_ui_form', 'add'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_LOCAL_TASK, - 'title' => t('Add Context'), - 'description' => t('Add a context to your site.'), - 'weight' => 1, - ); - $items[] = array( - 'title' => t('Import'), - 'path' => 'admin/build/context/import', - 'callback' => 'context_ui_import_page', - 'access' => user_access('administer site configuration'), - 'type' => MENU_LOCAL_TASK, - 'description' => t('Import a context definition into your site.'), - 'weight' => 2, - ); - $items[] = array( - 'path' => 'admin/build/context/edit', - 'callback' => 'drupal_get_form', - 'callback arguments' => array('context_ui_form', 'edit'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_CALLBACK, - ); - $items[] = array( - 'path' => 'admin/build/context/view', - 'callback' => 'drupal_get_form', - 'callback arguments' => array('context_ui_form', 'view'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_CALLBACK, - ); - $items[] = array( - 'path' => 'admin/build/context/export', - 'callback' => 'drupal_get_form', - 'callback arguments' => array('context_ui_export'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_CALLBACK, - ); - $items[] = array( - 'path' => 'admin/build/context/delete', - 'callback' => 'drupal_get_form', - 'callback arguments' => array('context_ui_delete_confirm'), - 'access' => user_access('administer site configuration'), - 'type' => MENU_CALLBACK, - ); - return $items; - } - else { - // Rebuild context_ui "cache". - if ($_GET['q'] == 'admin/build/modules') { - include_once(drupal_get_path("module", "context_ui") ."/context_ui_admin.inc"); - context_ui_rebuild(); - } - - // Attempt to override the theme_blocks. - context_ui_block_hack(); +function context_ui_menu() { + $items['admin/build/context'] = array( + 'title' => 'Context', + 'description' => 'Associate menus, views, blocks, etc. with different contexts to structure your site.', + 'page callback' => 'context_ui_admin', + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + $items['admin/build/context/list'] = array( + 'title' => 'List', + 'page callback' => 'context_ui_admin', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 0, + ); + $items['admin/build/context/add'] = array( + 'title' => 'Add Context', + 'description' => 'Add a context to your site.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('context_ui_form', 'add'), + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 1, + ); + $items['admin/build/context/import'] = array( + 'title' => 'Import', + 'description' => 'Import a context definition into your site.', + 'page callback' => 'context_ui_import_page', + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + ); + $items['admin/build/context/edit'] = array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('context_ui_form', 'edit'), + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_CALLBACK, + ); + $items['admin/build/context/view'] = array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('context_ui_form', 'view'), + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_CALLBACK, + ); + $items['admin/build/context/export'] = array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('context_ui_export'), + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_CALLBACK, + ); + $items['admin/build/context/delete'] = array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('context_ui_delete_confirm'), + 'access callback' => 'user_access', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_CALLBACK, + ); - // Include context ui css. - drupal_add_css(drupal_get_path("module", "context_ui") ."/context_ui.css"); - } + return $items; } /** - * Implementation of hook_help() + * Implementation of hook_help(). */ -function context_ui_help($section) { - switch ($section) { +function context_ui_help($path, $arg) { + switch ($path) { case 'admin/build/context': - return "

". + return '

'. t('Contexts provide you with a way to organize your site using terms familiar to real human beings. You can create a set of sections like "News", "Projects", "Staff", and associate different technical aspects of Drupal to each section. For example, the "News" section may be a collection of Nodes, Views, Menus and Blocks.') - ."

"; + .'

'; break; } } /** - * Implementation of hook_nodeapi() + * Implementation of hook_nodeapi(). */ function context_ui_nodeapi(&$node, $op, $teaser, $page) { if ($op == 'view' && $page && arg(0) == 'node') { @@ -228,7 +257,7 @@ // Implementation of context_ui_set for nodequeue. if (module_exists('nodequeue')) { $result = db_query("SELECT qid FROM {nodequeue_nodes} WHERE nid = %d", $node->nid); - while($qid = db_fetch_object($result)) { + while ($qid = db_fetch_object($result)) { context_ui_set('nodequeue', $qid->qid); } } @@ -241,10 +270,10 @@ } /** - * Implementation of hook_form_alter() + * Implementation of hook_form_alter(). */ -function context_ui_form_alter($form_id, &$form) { - if ($form['#node'] && arg(0) != 'admin') { // Prevent this from firing on admin pages... damn form driven apis... +function context_ui_form_alter(&$form, $form_state, $form_id) { + if (isset($form['#node']) && arg(0) != 'admin') { // Prevent this from firing on admin pages... damn form driven apis... context_ui_set('node', $form['#node']->type); } else if ($form_id == 'comment_form' && $nid = $form['nid']['#value']) { @@ -254,16 +283,16 @@ } /** - * Implementation of hook_views_pre_query() + * Implementation of hook_views_pre_query(). */ -function context_ui_views_pre_query($view) { - if ($view->build_type == 'page') { - context_ui_set('views', $view->name); +function context_ui_views_pre_view($display_id, $args) { + if ($display_id->type == 'Normal') { + context_ui_set('views', $display_id->name); } } /** - * Implementation of hook_user() + * Implementation of hook_user(). */ function context_ui_user($op, &$edit, &$account, $category = NULL) { if ($op == 'view') { @@ -271,7 +300,7 @@ } } -/* +/** * Invokes hook_context_define() to collect all contexts provided in code by modules. * * @param $space @@ -287,7 +316,7 @@ $contexts = array(); foreach (module_implements('context_define') as $module) { $function = $module .'_context_define'; - $contexts = array_merge($contexts, $function()); + $contexts = array_merge($contexts, $function()); } foreach ($contexts as &$context) { $context = (object) $context; @@ -305,7 +334,7 @@ return $contexts; } -/* +/** * Invokes hook_context_items() to provides an array of item types that a context may be associated with. */ function context_ui_types($op = 'list') { @@ -327,12 +356,12 @@ } } -/* +/** * Page callback for context_ui admin landing page. */ function context_ui_admin() { - include_once(drupal_get_path("module", "context_ui") ."/context_ui_admin.inc"); - + module_load_include('inc', 'context_ui', 'context_ui_admin'); + // rebuild blocks _block_rehash(); @@ -350,7 +379,7 @@ } // Module defined contexts - $output .= "

". t('Module context definitions') ."

"; + $output .= "

". t('Module context definitions') ."

"; $contexts = context_ui_tree('system'); if ($contexts) { $output .= theme('context_ui_admin', $contexts); @@ -358,11 +387,11 @@ else { $output .= "

". t('There are currently no module defined contexts.') ."

"; } - + return $output; } -/* +/** * Generates the omnibus context definition editing form. * Note: submission and validation handlers are in context_ui_admin.inc * @@ -374,9 +403,9 @@ * @return * A Drupal form array. */ -function context_ui_form($op, $cid = NULL, $context = NULL) { - include_once(drupal_get_path("module", "context_ui") ."/context_ui_admin.inc"); - +function context_ui_form(&$form_state, $op, $cid = NULL, $context = NULL) { + module_load_include('inc', 'context_ui', 'context_ui_admin'); + drupal_add_css(drupal_get_path("module", "context_ui") ."/context_ui.css"); drupal_add_js(drupal_get_path("module", "context_ui") ."/context_ui.js"); @@ -409,11 +438,9 @@ } break; } - + // Core context definition - $form = array( - '#base' => 'context_ui_form', - ); + $form['#theme'] = 'context_ui_form'; $form['value'] = array( '#type' => 'textfield', '#title' => t('Value'), @@ -446,7 +473,7 @@ ); // Generate settings for context item associations - foreach (context_ui_types('full') as $type => $item) { + foreach (context_ui_types('full') as $type => $item) { $form['items'][$type] = array( '#title' => $item['title'], '#description' => $item['description'], @@ -467,7 +494,7 @@ // $blocks in [0] have not been assigned a region foreach ($blocks[0] as $block) { if (!isset($context->block[$block->bid])) { - $block_options[$block->module][$block->bid] = $block->label . " ($block->bid)"; + $block_options[$block->module][$block->bid] = $block->label ." ($block->bid)"; } } ksort($block_options); @@ -529,30 +556,30 @@ } if ($op == 'view') { - $form[] = array( + $form['back'] = array( '#type' => 'item', '#value' => l(t('Back'), 'admin/build/context'), ); } - + if ($op != 'view') { - $form[] = array( + $form['submit'] = array( '#type' => 'submit', - '#value' => t('Save'), + '#value' => t('Save'), ); } - + if ($op == 'edit') { - $form[] = array( + $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), - ); + ); } if ($op == 'view' || $op == 'edit' || ($op == 'add' && $context)) { if ($context) { $form['value']['#default_value'] = $context->value; - $form['key']['#default_value'] = $context->key; + $form['key']['#default_value'] = $context->ckey; $form['space']['#default_value'] = $context->space; $form['cid'] = array( '#type' => 'value', @@ -562,16 +589,16 @@ '#type' => 'value', '#value' => $context->system, ); - if ($op == 'view' || $context->system) { - $form['value']['#disabled'] = - $form['key']['#disabled'] = - $form['space']['#disabled'] = - $form['block']['selector']['blocks']['#disabled'] = + if ($op == 'view' || $context->system) { + $form['value']['#disabled'] = + $form['key']['#disabled'] = + $form['space']['#disabled'] = + $form['block']['selector']['blocks']['#disabled'] = $form['block']['selector']['regions']['#disabled'] = true; } // Set default values for each item type (except blocks) foreach (context_ui_types() as $type) { - if (is_array($context->{$type})) { + if (isset($context->{$type}) && is_array($context->{$type})) { $defaults = array(); foreach ($context->{$type} as $id) { $defaults[$id] = $id; @@ -583,7 +610,7 @@ // Blocks must be selected by region if (is_array($context->block)) { foreach ($regions as $region => $label) { - if (is_array($form['block'][$region])) { + if (isset($form['block'][$region]) && is_array($form['block'][$region])) { $defaults = array(); foreach ($form['block'][$region]['#options'] as $block => $label) { if (array_search($block, $context->block) !== false) { @@ -604,8 +631,8 @@ return $form; } -/* - * Theme function for context_ui_form() +/** + * Theme function for context_ui_form(). */ function theme_context_ui_form($form) { $output = ''; @@ -645,17 +672,17 @@ ), ); $output .= theme('table', $header, $rows, array('class' => 'context-ui-2col')); - + $output .= drupal_render($form); return $output; } -/* +/** * Provide a form to confirm deletion of a context definition. */ -function context_ui_delete_confirm($cid) { - include_once(drupal_get_path("module", "context_ui") ."/context_ui_admin.inc"); - +function context_ui_delete_confirm(&$form_state, $cid) { + module_load_include('inc', 'context_ui', 'context_ui_admin'); + $context = context_ui_context('load', $cid); if (!$context) { return drupal_goto('admin/build/context'); @@ -670,27 +697,27 @@ return $form; } -/* - * hook_submit() +/** + * hook_submit(). */ -function context_ui_delete_confirm_submit($form_id, $form) { - context_ui_context('delete', $form['cid']); +function context_ui_delete_confirm_submit($form, &$form_state) { + context_ui_context('delete', $form_state['values']['cid']); context_ui_rebuild(); - return 'admin/build/context'; + $form_state['redirect'] = 'admin/build/context'; } -/* +/** * Page callback for import form. Switches form output to context form * if import submission has occurred. */ function context_ui_import_page() { - if ($_POST['form_id'] == 'context_ui_form') { + if (!empty($_POST) && $_POST['form_id'] == 'context_ui_form') { return drupal_get_form('context_ui_form', 'add'); } return drupal_get_form('context_ui_import'); } -/* +/** * Import form. Provides simple helptext instructions and textarea for * pasting a context definition. */ @@ -712,18 +739,19 @@ '#type' => 'submit', '#value' => t('Import'), ); - + return $form; } -/* +/** * Import form submit handler. Evaluates import code and transfers to * context definition form. */ -function context_ui_import_submit($form_id, $form_values) { - include_once(drupal_get_path("module", "context_ui") ."/context_ui_admin.inc"); +function context_ui_import_submit($form, &$form_state) { + module_load_include('inc', 'context_ui', 'context_ui_admin'); + $items = array(); - if ($import = $form_values['import']) { + if ($import = $form_state['values']['import']) { ob_start(); eval($import); ob_end_clean(); @@ -736,7 +764,7 @@ $context->system = FALSE; if ($exists = context_ui_context('load', $context)) { drupal_set_message(t('A user-defined context definition with this space/key/value identifier already exists. Please remove the existing context before importing this definition.'), 'error'); - return 'admin/build/context'; + $form_state['redirect'] = 'admin/build/context'; } else { drupal_set_title(t('Add context')); @@ -747,11 +775,11 @@ } else { drupal_set_message(t('An error occurred while importing. Please check your context definition.', 'error')); - return 'admin/build/context'; + $form_state['redirect'] = 'admin/build/context'; } } -/* +/** * Provides a form with an exported context definition for use in modules. * * @param $cid @@ -760,9 +788,9 @@ * @return * A FormAPI array. */ -function context_ui_export($cid = NULL) { - include_once(drupal_get_path("module", "context_ui") ."/context_ui_admin.inc"); - +function context_ui_export(&$form_state, $cid = NULL) { + module_load_include('inc', 'context_ui', 'context_ui_admin'); + if (is_numeric($cid) && $context = context_ui_context('load', $cid)) { drupal_set_title(t('Export %title', array('%title' => $context->value))); @@ -783,7 +811,7 @@ // export $export = '$items[] = '. var_export($context, true) .';'; - + // build the form $form = array(); $form['help'] = array( @@ -814,26 +842,26 @@ * @return * True if one or more contexts were set. False if no items/contexts matched. */ - function context_ui_set($type, $id) { +function context_ui_set($type, $id) { if (!is_array($id)) { $id = array($id); } $set = false; $result = db_query(" - SELECT c.space, c.key, c.value, c.cid FROM {context_ui_item} ci + SELECT c.space, c.ckey, c.value, c.cid FROM {context_ui_item} ci JOIN {context_ui} c ON ci.cid = c.cid WHERE ci.type = '%s' AND ci.id IN (". substr(str_repeat("'%s',", count($id)), 0, -1) .") AND c.status = 1", array_merge(array($type), $id)); - if (db_num_rows($result) > 0) { - while ($context = db_fetch_object($result)) { - // If this context already has a value, don't alter it. - if (!context_exists($context->space, $context->key)) { - context_set($context->space, $context->key, $context->value); - context_ui_menu_set_location($context); - } + + while ($context = db_fetch_object($result)) { + // If this context already has a value, don't alter it. + if (!context_exists($context->space, $context->ckey)) { + context_set($context->space, $context->ckey, $context->value); + context_ui_menu_set_location($context); } $set = true; } + return $set; } @@ -883,61 +911,31 @@ * Alters the menu to reflect any active contexts. Called from context_ui_set(). */ function context_ui_menu_set_location($context) { - if ($context->cid) { - $result = db_query(" - SELECT ci.id - FROM {context_ui_item} ci - WHERE ci.type = '%s' AND ci.cid = %d", - 'menu', $context->cid); - if ($path = db_result($result)) { - // Load global menu -- unfortunately we may have to modify it manually - global $_menu; - - // Get menu item for active context - $context_menu = menu_get_item(null, $path); - $items[] = $context_menu; - - // Grab the menu tree from active context item to the root - $mid = $context_menu['pid']; - while ($mid && ($item = menu_get_item($mid))) { - $items[$mid] = $item; - $mid = $item['pid']; - } - $items = array_reverse($items, true); + // @todo this functionality is not implemented + if (!$context->cid) { + return; + } - // Graft the current active page on if it is different - $active_mid = menu_get_active_item(); - if ($active_mid != $_menu['path index'][$path] && !$items[$active_mid]) { - $active_menu = menu_get_item($active_mid); - // Due to a bug/feature? of menu_set_location() menu leaves that - // are part of the 'visible' portion of the menu tree short-circuit - // any further menu grafting. We check here, and make sure the leaf - // item is not a visible one. - if (isset($_menu['visible'][$active_mid])) { - unset($_menu['visible'][$active_mid]); - } - - // If the active menu item is a local task we need to make sure - // to include it's parent. - if ($active_menu['type'] & MENU_IS_LOCAL_TASK) { - $parent_menu = menu_get_item($active_menu['pid']); - $items[] = $parent_menu; - // Allow for two levels of local tasks. - if ($parent_menu['type'] & MENU_IS_LOCAL_TASK) { - $items[] = menu_get_item($parent_menu['pid']); - } - } - $items[] = $active_menu; - } + $result = db_query("SELECT ci.id FROM {context_ui_item} ci WHERE ci.type = 'menu' AND ci.cid = %d", $context->cid); + $menu_id = db_result($result); + if (!$menu_id) { + // No menuitem associated with context. + return; + } - // Push the new location path through - menu_set_location($items); - } +/* $mlid = substr($menu_id, stripos($menu_id, ':') +1); + if (!$mlid || !is_numeric($mlid)) { + watchdog('context_ui', 'Incorrect value in @item.', 'context_ui_item.id', WATCHDOG_ERROR); + return; } + + $result = db_query('SELECT ml.router_path FROM {menu_links} ml WHERE ml.mlid = %d', $mlid); + $path = db_result($result); + */ } /** - * TODO - Rework this, we're may just to require phptemplate and not allow for the theme to implement a + * TODO - Rework this, we're may just to require phptemplate and not allow for the theme to implement a * phptemplate_blocks function. Otherwise we may check for that namespace and use a backup otherwise. * * An egregious hack. Checks the function namespace for a theme and theme engine override of theme_blocks @@ -980,34 +978,30 @@ function context_ui_block_list($region) { global $user, $theme_key; - static $blocks, $cids; - - $defaults = array(); + static $cids = array(); + static $blocks = array(); if (!count($blocks)) { - $blocks = array(); - $cids = array(); - // generate list of active DB contexts // formerly an API function -- TODO: evaluate whether this may be useful otherwise $result = db_query("SELECT * FROM {context_ui} WHERE status = 1", 'context_ui'); while ($context = db_fetch_object($result)) { - if (context_get($context->space, $context->key) == $context->value) { + if (context_get($context->space, $context->ckey) == $context->value) { $cids[$context->cid] = $context->cid; } } $rids = array_keys($user->roles); - $placeholders = implode(',', array_fill(0, count($rids), '%d')); - $result = db_query(" + $result = db_query(db_rewrite_sql(" SELECT DISTINCT b.*, c.weight AS context_weight, c.region AS context_region, c.cid FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta LEFT JOIN {context_ui_block} c ON b.module = c.module AND b.delta = c.delta - WHERE b.theme = '%s' AND (r.rid IN ($placeholders) OR r.rid IS NULL) - ORDER BY b.region, b.weight, b.module", + WHERE b.theme = '%s' AND (r.rid IN (". db_placeholders($rids) .") OR r.rid IS NULL) + ORDER BY b.region, b.weight, b.module", 'b', 'bid'), array_merge(array($theme_key), $rids) ); + while ($block = db_fetch_object($result)) { // we determine status as a combination of DB setting + context definition $status = FALSE; @@ -1045,11 +1039,10 @@ if ($block->pages) { if ($block->visibility < 2) { $path = drupal_get_path_alias($_GET['q']); - $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block->pages, '/')) .')$/'; // Compare with the internal and path alias (if any). - $page_match = preg_match($regexp, $path); + $page_match = drupal_match_path($path, $block->pages); if ($path != $_GET['q']) { - $page_match = $page_match || preg_match($regexp, $_GET['q']); + $page_match = $page_match || drupal_match_path($_GET['q'], $block->pages); } // When $block->visibility has a value of 0, the block is displayed on // all pages except those listed in $block->pages. When set to 1, it @@ -1063,46 +1056,75 @@ else { $page_match = TRUE; } - - if ($enabled && $page_match) { - // Check the current throttle status and see if block should be displayed - // based on server load. - if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) { + $block->enabled = $enabled; + $block->page_match = $page_match; + $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block; + } + } + + } + + // Create an empty array if there were no entries + if (!isset($blocks[$region])) { + $blocks[$region] = array(); + } + + foreach ($blocks[$region] as $key => $block) { + // Render the block content if it has not been created already. + if (!isset($block->content)) { + // Erase the block from the static array - we'll put it back if it has content. + unset($blocks[$region][$key]); + if ($block->enabled && $block->page_match) { + // Check the current throttle status and see if block should be displayed + // based on server load. + if (!($block->throttle && (module_invoke('throttle', 'status') > 0))) { + // Try fetching the block from cache. Block caching is not compatible with + // node_access modules. We also preserve the submission of forms in blocks, + // by fetching from cache only if the request method is 'GET'. + if (!count(module_implements('node_grants')) && $_SERVER['REQUEST_METHOD'] == 'GET' && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) { + $array = $cache->data; + } + else { $array = module_invoke($block->module, 'block', 'view', $block->delta); - if (isset($array) && is_array($array)) { - foreach ($array as $k => $v) { - $block->$k = $v; - } + if (isset($cid)) { + cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY); } } - if (isset($block->content) && $block->content) { - // Override default block title if a custom display title is present. - if ($block->title) { - // Check plain here to allow module generated titles to keep any markup. - $block->subject = $block->title == '' ? '' : check_plain($block->title); + + if (isset($array) && is_array($array)) { + foreach ($array as $k => $v) { + $block->$k = $v; } - $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block; } } - + if (isset($block->content) && $block->content) { + // Override default block title if a custom display title is present. + if ($block->title) { + // Check plain here to allow module generated titles to keep any markup. + $block->subject = $block->title == '' ? '' : check_plain($block->title); + } + if (!isset($block->subject)) { + $block->subject = ''; + } + $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block; + } } } - // Custom sort since SQL order by won't give it to us for free - foreach ($blocks as &$region_blocks) { - uasort($region_blocks, '_context_ui_block_compare'); - } } - // Create an empty array if there were no entries - if (!isset($blocks[$region])) { - $blocks[$region] = array(); + + // Custom sort since SQL order by won't give it to us for free + foreach ($blocks as &$region_blocks) { + uasort($region_blocks, '_context_ui_block_compare'); } + return $blocks[$region]; } -/* +/** * Helper function to sort block objects by weight */ function _context_ui_block_compare($a, $b) { // Enabled blocks return ($a->weight - $b->weight); } + Index: context_ui/context_ui_admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_ui/context_ui_admin.inc,v retrieving revision 1.1.2.10 diff -u -r1.1.2.10 context_ui_admin.inc --- context_ui/context_ui_admin.inc 9 Jun 2008 22:26:35 -0000 1.1.2.10 +++ context_ui/context_ui_admin.inc 13 Jul 2008 20:36:33 -0000 @@ -1,7 +1,12 @@ array(), - 'ui' => array(), + 'ui' => array(), ); $result = db_query(" SELECT * FROM {context_ui} - ORDER BY system ASC, space ASC, `key` ASC, value ASC"); + ORDER BY system ASC, space ASC, ckey ASC, value ASC"); while ($context = db_fetch_object($result)) { - $branch = $context->system ? 'system' : 'ui'; - $tree[$branch][$context->space][$context->key][$context->value] = $context; + $branch = $context->system ? 'system' : 'ui'; + $tree[$branch][$context->space][$context->ckey][$context->value] = $context; } } switch ($op) { @@ -30,7 +35,7 @@ } } -/* +/** * Cache system contexts */ function context_ui_rebuild() { @@ -48,12 +53,12 @@ } // Insert or update system contexts - foreach ($default_contexts as $c) { + foreach ($default_contexts as $c) { // flag this context's type + status $c->system = 1; - $c->status = isset($ui[$c->space][$c->key][$c->value]) ? 0 : 1; - - if ($context = context_ui_context('load', $c)) { + $c->status = isset($ui[$c->space][$c->ckey][$c->value]) ? 0 : 1; + + if ($context = context_ui_context('load', $c)) { $c->cid = $context->cid; context_ui_context('update', $c); unset($system[$c->cid]); // remove this context from unused list @@ -62,14 +67,14 @@ context_ui_context('insert', $c); } } - + // Remove any unused contexts foreach ($system as $c => $dummy) { context_ui_context('delete', $c); } } -/* +/** * Generates the main context_ui admin page with a tiered context listing. */ function theme_context_ui_admin($context_tree) { @@ -79,7 +84,7 @@ null ); foreach ($keys as $key => $contexts) { - if (is_array($contexts)) { + if (is_array($contexts)) { $rows[] = array( "". $key ."", null @@ -102,7 +107,7 @@ $rows[] = array( "". $value ."", implode(' | ', $links), - ); + ); } } else { @@ -129,18 +134,20 @@ return theme('table', array(t('Context'), t('Actions')), $rows, array('class' => 'context-ui')); } -/* +/** * Generates the AJAX enabled block administration portion of the context_ui admin form. */ function theme_context_ui_block_ui($regions, $context = null) { + $output = ''; + $tools = "
"; foreach ($regions as $region => $label) { - $items = array(); + $items = array(); $system = _context_ui_get_blocks($region); $system_item = array(); foreach ($system as $block) { - $system_item[] = $block->label ." ($block->bid)"; + $system_item[] = $block->label ." ($block->bid)"; } $system_item = implode("
", $system_item); @@ -182,39 +189,39 @@ $items[] = array( 'data' => '', 'class' => 'dummy', - ); + ); } $output .= theme('item_list', $items, $label, 'ul', array('class' => $region)); } return $output; } -/* +/** * hook_validate() */ -function context_ui_form_validate($form_id, $form_values) { - if ($form_values['op'] == t('Save') && $form_values['value']) { +function context_ui_form_validate($form, &$form_state) { + if ($form_state['clicked_button']['#id'] == 'edit-submit' && $form_state['values']['value']) { // Check for string identifier sanity foreach (array('value', 'key', 'space') as $elem) { - if (!preg_match('!^[a-z0-9_]+$!', $form_values[$elem])) { + if (!preg_match('!^[a-z0-9_]+$!', $form_state['values'][$elem])) { form_set_error($elem, t('The context !elem can only consist of lowercase letters, underscores, and numbers.', array('!elem' => $elem))); } } - if (!$form_values['cid']) { + if (!isset($form_state['values']['cid'])) { // Check that no other user-defined context definition has taken this identifier already - $context = new StdClass(); - $context->space = $form_values['space']; - $context->key = $form_values['key']; - $context->value = $form_values['value']; + $context = new stdClass(); + $context->space = $form_state['values']['space']; + $context->ckey = $form_state['values']['key']; + $context->value = $form_state['values']['value']; $context->system = 0; if ($exists = context_ui_context('load', $context)) { - form_set_error($form_values['value'], t('A user-defined context with this space/key/value identifier already exists. Please delete the existing definition before creating a new one.')); + form_set_error($form_state['values']['value'], t('A user-defined context with this space/key/value identifier already exists. Please delete the existing definition before creating a new one.')); } } } } -/* +/** * Produces a context object from submitted form values. * * @param $form @@ -225,12 +232,12 @@ */ function context_ui_form_process($form) { $context = new stdClass(); - + // Context space/key/value definition - $context->cid = $form['cid'] ? $form['cid'] : null; - $context->system = $form['system'] ? $form['system'] : null; + $context->cid = isset($form['cid']) ? $form['cid'] : null; + $context->system = isset($form['system']) ? $form['system'] : null; $context->space = $form['space'] ? $form['space'] : null; - $context->key = $form['key'] ? $form['key'] : null; + $context->ckey = $form['key'] ? $form['key'] : null; $context->value = $form['value'] ? $form['value'] : null; $context->status = 1; // all user defined contexts have status 1 @@ -243,7 +250,7 @@ } } } - + // Blocks must be done by region $context->block = array(); global $theme_key; @@ -259,9 +266,9 @@ $block = $valid[$bid]; $modifier = $position < $midpoint ? -10 : 10; $block->weight = $position - $midpoint + $modifier; - $block->region = $region; + $block->region = $region; $block->type = 'context_ui'; - $context->block[$block->bid] = $block; + $context->block[$block->bid] = $block; } } } @@ -269,17 +276,18 @@ return $context; } -/* +/** * hook_submit() */ -function context_ui_form_submit($form_id, $form_values) { - switch (t($form_values['op'])) { +function context_ui_form_submit($form, &$form_state) { + switch (t($form_state['values']['op'])) { // Send user to delete confirmation page case 'Delete': - return 'admin/build/context/delete/'. $form_values['cid']; + $form_state['redirect'] = 'admin/build/context/delete/'. $form_state['values']['cid']; + return; // Process form values and save and/or update the context in the db case 'Save': - $context = context_ui_form_process($form_values); + $context = context_ui_form_process($form_state['values']); if (!$context->cid) { $result = context_ui_context('insert', $context); if ($result) { @@ -299,10 +307,10 @@ } // rebuild cache context_ui_rebuild(); - return 'admin/build/context'; + $form_state['redirect'] = 'admin/build/context'; } -/* +/** * Provides simple operations (load/insert/update/etc.) on a core context space/key/value definition. * * @param $op @@ -319,17 +327,17 @@ if (is_numeric($context)) { $context = db_fetch_object(db_query("SELECT * FROM {context_ui} WHERE cid = %d", $context)); } - else if (is_object($context) && $context->cid) { + else if (is_object($context) && isset($context->cid)) { $context = db_fetch_object(db_query("SELECT * FROM {context_ui} WHERE cid = %d", $context->cid)); } - else if (is_object($context) && $context->space && $context->key && $context->value) { + else if (is_object($context) && $context->space && $context->ckey && $context->value) { $args = array( $context->system, $context->space, - $context->key, + $context->ckey, $context->value ); - $context = db_fetch_object(db_query("SELECT * FROM {context_ui} WHERE system = %d AND space = '%s' AND `key` = '%s' AND value = '%s'", $args)); + $context = db_fetch_object(db_query("SELECT * FROM {context_ui} WHERE system = %d AND space = '%s' AND ckey = '%s' AND value = '%s'", $args)); } if ($context) { $context = context_ui_item('load', $context); @@ -339,21 +347,19 @@ return false; case 'insert': // check for type & existence of context definition - $existing = context_ui_context('load', $context); + $existing = context_ui_context('load', $context); if (!$existing || $existing->system != $context->system) { - $context->cid = db_next_id('{context_ui}_cid'); $values = array( - 'cid' => $context->cid, 'system' => $context->system, 'status' => $context->status, 'space' => $context->space, - '`key`' => $context->key, + 'ckey' => $context->ckey, 'value' => $context->value, ); - $keys = implode(', ', array_keys($values)); - $args = array_merge(array($keys), $values); - $result = db_query("INSERT INTO {context_ui} (%s) VALUES(%d, %d, %d, '%s', '%s', '%s')", $args); - $result = $result && context_ui_item('save', $context); + + $result = db_query("INSERT INTO {context_ui} (system, status, space, ckey, value) VALUES(%d, %d, '%s', '%s', '%s')", $values); + $context->cid = db_last_insert_id('context_ui', 'cid'); + $result = $result && context_ui_item('save', $context); $result = $result && context_ui_item_block('save', $context); return $result ? true : false; } @@ -366,12 +372,12 @@ 'system' => $context->system, 'status' => $context->status, 'space' => $context->space, - '`key`' => $context->key, + 'ckey' => $context->ckey, 'value' => $context->value, 'cid' => $context->cid, ); - $keys = implode(', ', array_keys($values)); - $result = db_query("UPDATE {context_ui} SET system = %d, status = %d, space = '%s', `key` = '%s', value = '%s'WHERE cid = %d", $values); + $keys = implode(', ', array_keys($values)); + $result = db_query("UPDATE {context_ui} SET system = %d, status = %d, space = '%s', ckey = '%s', value = '%s'WHERE cid = %d", $values); $result = $result && context_ui_item('save', $context); $result = $result && context_ui_item_block('save', $context); return $result ? true : false; @@ -388,7 +394,7 @@ } } -/* +/** * Provides simple operations (load/save) on any context-item associations. context_ui_item() will * automatically sync the database with the context object provided when saving. Any associations * that exist on the object that are absent from the database will be inserted, and any associations @@ -409,17 +415,17 @@ $result = db_query("SELECT * FROM {context_ui_item} WHERE cid = %d", $context->cid); while ($page = db_fetch_object($result)) { $context->{$page->type}[$page->id] = $page->id; - } + } return $context; case 'save': $current = (object) array('cid' => $context->cid); $current = context_ui_item('load', $current); foreach (context_ui_types() as $type) { // Delete any stale associations - if (is_array($current->{$type})) { + if (isset($current->{$type}) && is_array($current->{$type})) { foreach ($current->{$type} as $id) { $delete = false; - if (!is_array($context->{$type})) { + if (!isset($context->{$type}) || !is_array($context->{$type})) { $delete = true; } else if (array_search($id, $context->{$type}) === false) { @@ -431,17 +437,17 @@ } } // Add/update any missing associations - if (is_array($context->{$type})) { + if (isset($context->{$type}) && is_array($context->{$type})) { foreach ($context->{$type} as $id) { $update = false; - if (!is_array($current->{$type})) { + if (!isset($current->{$type}) || !is_array($current->{$type})) { $update = true; } else if (array_search($id, $current->{$type}) === false) { $update = true; } if ($update) { - $result = db_query("REPLACE INTO {context_ui_item} (cid, type, id) VALUES(%d, '%s', '%s')", $context->cid, $type, $id); + $result = db_query("REPLACE INTO {context_ui_item} (cid, type, id) VALUES(%d, '%s', '%s')", $context->cid, $type, $id); } } } @@ -453,7 +459,7 @@ return false; } -/* +/** * Provides simple operations (load/save) on any context-block associations. Parallel usage as * context_ui_item(). * @@ -508,31 +514,26 @@ } return true; break; - } + } } return false; } -/* +/** * Helper function to generate a list of database and module provided views. */ function _context_ui_get_views() { - $views = array(); - $result = db_query("SELECT name FROM {view_view}"); - while ($view = db_fetch_object($result)) { - $views[$view->name] = $view->name; - } - views_load_cache(); // the function below was not loaded without this call - $default_views = _views_get_default_views(); - $views_status = variable_get('views_defaults', array()); - foreach ($default_views as $view) { - if (!$views[$view->name] && - ($views_status[$view->name] == 'enabled' || (!$views_status[$view->name] && !$view->disabled))) { - $views[$view->name] = $view->name; + $enabled_views = array(); + + $views = views_get_all_views(); + + foreach ($views as $view) { + if (!isset($views[$view->name]->disabled) || !$views[$view->name]->disabled) { + $enabled_views[$view->name] = $view->name; } } - ksort($views); - return $views; + ksort($enabled_views); + return $enabled_views; } /** @@ -557,14 +558,14 @@ if (!$system_blocks) { // initialize regions foreach (system_region_list($theme_key) as $r => $l) { - $system_blocks[$r] = array(); + $system_blocks[$r] = array(); } // load blocks from database $result = db_query("SELECT module, delta, weight, region, status FROM {blocks} WHERE theme = '%s' ORDER BY weight, module, delta", $theme_key); while ($block = db_fetch_object($result)) { // load block info - $block_info[$block->module] = $block_info[$block->module] ? $block_info[$block->module] : module_invoke($block->module, 'block', 'list'); - $block->label = $block_info[$block->module][$block->delta]['info']; + $block_info[$block->module] = isset($block_info[$block->module]) ? $block_info[$block->module] : module_invoke($block->module, 'block', 'list'); + $block->label = $block_info[$block->module][$block->delta]['info']; $block->type = 'system'; $block->bid = $block->module .'_'. $block->delta; // add block to region @@ -577,11 +578,11 @@ // mark block as available in DB $valid[$block->module ."_". $block->delta] = true; } - } + } - // load system blocks into main block array + // load system blocks into main block array $blocks = $system_blocks; - + // load context blocks if provided if (is_object($context) && is_array($context->block)) { // iterate over context-associated blocks @@ -593,7 +594,7 @@ if (!$region || (isset($region) && $block->region == $region)) { // load block info $block_info[$block->module] = $block_info[$block->module] ? $block_info[$block->module] : module_invoke($block->module, 'block', 'list'); - $block->label = $block_info[$block->module][$block->delta]['info']; + $block->label = $block_info[$block->module][$block->delta]['info']; $block->type = 'context_ui'; $block->bid = $block->module .'_'. $block->delta; // add block to region @@ -602,12 +603,12 @@ } else { $blocks[0][$block->bid] = $block; - } + } } } } } - + foreach ($blocks as $r => &$sort_region) { if ($r !== 0) { uasort($sort_region, "_context_ui_block_compare"); Index: context_ui/tests/context_ui.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/context_ui/tests/Attic/context_ui.test,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 context_ui.test --- context_ui/tests/context_ui.test 9 Apr 2008 14:39:45 -0000 1.1.2.2 +++ context_ui/tests/context_ui.test 10 Jul 2008 23:58:13 -0000 @@ -1,5 +1,5 @@ 'Context UI Tests', ); } - + function setUp() { $this->drupalModuleEnable('context'); $this->drupalModuleEnable('context_ui'); - + parent::setUp(); } - + function tearDown() { include_once(drupal_get_path("module", "context_ui") ."/context_ui_admin.inc"); context_ui_context('delete', $this->context); - + $this->drupalModuleDisable('context'); $this->drupalModuleDisable('context_ui'); - + parent::tearDown(); } - + // Random ID is like randomNAME, but provides only lowercase letters. function randomID($number = 4, $prefix = 'simpletest_') { $chars = 'abcdefghijklmnopqrstuvwxyz_'; @@ -45,34 +45,34 @@ } return $prefix; } - + function testCreateContext() { - + // User setup - $user = $this->drupalCreateUserRolePerm(array('administer site configuration', 'access content', 'create page content')); + $user = $this->drupalCreateUserRolePerm(array('administer site configuration', 'access content', 'create page content')); $this->drupalLoginUser($user); - + // Create context $context = new stdClass(); $context->space = $this->randomID(15); - $context->key = $this->randomID(15); + $context->key = $this->randomID(15); $context->value = $this->randomID(15); $this->context = $context; - + $edit = array('space' => $context->space, 'key' => $context->key, 'value' => $context->value); $edit['items-node-page'] = 'page'; $this->drupalPostRequest('admin/build/context/add', $edit, 'Save'); $this->assertWantedRaw(t('The context %title was saved successfully.', array('%title' => $edit['value'])), 'Context saved'); - - // Create Page content + + // Create Page content $edit = array(); $edit['title'] = $this->randomName(32); $edit['body'] = $this->randomName(32); $this->drupalPostRequest('node/add/page', $edit, 'Submit'); - + // View context and test context setting node_view(node_load(array('title' => $edit['title'])), FALSE, TRUE); $this->assertIdentical(context_get($context->space, $context->key), $context->value , 'Custom context was set'); - + } } Index: tests/context.test =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/context/tests/context.test,v retrieving revision 1.1 diff -u -r1.1 context.test --- tests/context.test 11 Mar 2008 13:27:12 -0000 1.1 +++ tests/context.test 10 Jul 2008 23:56:55 -0000 @@ -1,5 +1,5 @@ assertIdentical(true, $set); + $this->assertIdentical(true, $set); // test get integrity $this->assertIdentical(array(), context_get($val)); $this->assertIdentical(true, context_exists($val)); @@ -44,12 +44,12 @@ } context_clear(); } - + // SPACE+KEY foreach ($set_types as $type => $val) { foreach ($set_types as $type2 => $val2) { // test set integrity - $set = context_set($val, $val2); + $set = context_set($val, $val2); if (in_array($type, $id_types)) { // test set integrity if ($type2 != 'bool') { @@ -69,7 +69,7 @@ } } } - context_clear(); + context_clear(); } // SPACE+KEY+VALUE, o lord