diff --git a/includes/content.inc b/includes/content.inc index 5c5c1a3e45cd6bd89a6ce13eb1f4d2de3a1d1bd1..a7a2a857ebf3b3365966d9ea3f69578cc78198a4 100644 --- a/includes/content.inc +++ b/includes/content.inc @@ -17,7 +17,7 @@ */ function ctools_ctools_plugin_content_types() { return array( - 'cache' => TRUE, + 'cache' => FALSE, 'defaults' => 'ctools_content_defaults', ); } @@ -61,20 +61,26 @@ function ctools_content_defaults($info, &$plugin) { } // Another ease of use check: - // If a content type is set to SINGLE and *no* subtypes are defined, this rewrites - // things so that the syntax is nicer. - if (!empty($plugin['single']) && !isset($plugin['content types'])) { - $type = array( - 'title' => $plugin['title'], - 'description' => $plugin['description'], - 'icon' => $plugin['icon'], - 'category' => $plugin['category'], - ); + if (!isset($plugin['content types'])) { + // If a content type is set to SINGLE and *no* subtypes are defined, this rewrites + // things so that the syntax is nicer. + if (!empty($plugin['single'])) { + $type = array( + 'title' => $plugin['title'], + 'description' => $plugin['description'], + 'icon' => $plugin['icon'], + 'category' => $plugin['category'], + ); - if (isset($plugin['required contexts'])) { - $type['required contexts'] = $plugin['required contexts']; + if (isset($plugin['required contexts'])) { + $type['required contexts'] = $plugin['required contexts']; + } + $plugin['content types'] = array($plugin['name'] => $type); + } + // Otherwise, auto discover the function based upon pattern naming. + else if (function_exists($function_base . 'content_types')) { + $plugin['content types'] = $function_base . 'content_types'; } - $plugin['content types'] = array($plugin['name'] => $type); } } @@ -376,7 +382,7 @@ function ctools_content_configure_form_defaults(&$form, &$form_state) { // Unless we're not allowed to override the title on this content type, add this // gadget to all panes. - if (empty($plugin['no title overridex'])) { + if (empty($plugin['no title override']) && empty($subtype['no title override'])) { $form['aligner_start'] = array( '#value' => '<div class="option-text-aligner">', ); @@ -412,7 +418,10 @@ function ctools_content_configure_form_defaults(&$form, &$form_state) { * * The $form_info and $form_state need to be preconfigured with data you'll need * such as whether or not you're using ajax, or the modal. $form_info will need - * your next/submit callbacks so that you can cache your data appropriate. This + * your next/submit callbacks so that you can cache your data appropriate. + * + * @return + * If this function returns false, no form exists. */ function ctools_content_form($op, $form_info, &$form_state, $plugin, $subtype, &$conf, $step = NULL) { $form_state += array( @@ -435,6 +444,10 @@ function ctools_content_form($op, $form_info, &$form_state, $plugin, $subtype, & _ctools_content_create_add_form_info($form_info, $plugin['edit form'], $plugin, $subtype, $op); } + if (empty($form_info['order'])) { + return FALSE; + } + ctools_include('wizard'); return ctools_wizard_multistep_form($form_info, $step, $form_state); diff --git a/plugins/content_types/block/block.inc b/plugins/content_types/block/block.inc new file mode 100644 index 0000000000000000000000000000000000000000..be244625d665653772befda56d27e07e6b59aef5 --- /dev/null +++ b/plugins/content_types/block/block.inc @@ -0,0 +1,367 @@ +<?php +// $Id$ + +/** + * @file + * Provide Drupal blocks as content. + * + * Since blocks don't provide all of the features we do, we have to do a little + * extra work, including providing icons and categories for core blocks. Blocks + * from contrib modules get to provide their own stuff, or get relegated to + * the old "Miscellaneous" category. + */ + +/** + * Callback function to supply a list of content types. + */ +function ctools_block_ctools_content_types() { + return array( + // And this is just the administrative title. + // All our callbacks are named according to the standard pattern and can be deduced. + 'title' => t('Block'), + ); +} + +/** + * Return all block content types available. + * + * Modules wanting to make special adjustments the way that panels handles their blocks + * can implement an extension to the hook_block() family, where the function name is + * of the form "$module . '_ctools_block_info'". + */ +function ctools_block_content_type_content_types() { + $types = array(); + foreach (module_list() as $module) { + $module_blocks = module_invoke($module, 'block', 'list'); + if ($module_blocks) { + foreach ($module_blocks as $delta => $block) { + // strip_tags used because it goes through check_plain and that + // just looks bad. + $info = array( + 'title' => strip_tags($block['info']), + ); + + // Ask around for further information by invoking the hook_block() extension. + $function = $module . '_ctools_block_info'; + if (!function_exists($function)) { + $function = 'ctools_default_block_info'; + } + $function($module, $delta, $info); + + // this check means modules can remove their blocks; particularly useful + // if they offer the block some other way (like we do for views) + if ($info) { + $types["$module-$delta"] = $info; + } + } + } + } + return $types; +} + +/** + * Output function for the 'block' content type. Outputs a block + * based on the module and delta supplied in the configuration. + */ +function ctools_block_content_type_render($subtype, $conf) { + list($module, $delta) = explode('-', $subtype, 2); + $block = (object) module_invoke($module, 'block', 'view', $delta); + if (empty($block)) { + return; + } + + $block->title = $block->subject; + + if (user_access('administer blocks')) { + $block->admin_links = array( + array( + 'title' => t('Configure block'), + 'alt' => t("Configure this block's 'block settings' in administer >> site building >> blocks"), + 'href' => "admin/build/block/configure/$module/$delta", + 'query' => drupal_get_destination(), + ), + ); + } + + // TEMP: Disabling block visibility checking. Ultimately we may be able to + // finally just say it's not supported. + return $block; + + // This seems extra but it prevents an unnecessary query sometimes. + if (empty($conf['block_visibility']) && $block->module != 'block') { + return $block; + } + + // Test for block visibility + + $result = db_query("SELECT title, pages, visibility FROM {blocks} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta); + $block_visibility = db_fetch_object($result); + + if ($block->module == 'block') { + $block->title = $block_visibility->title; + } + + if (empty($conf['block_visibility'])) { + return $block; + } + + if ($block_visibility && $block_visibility->pages) { + if ($block_visibility->visibility < 2) { + $path = drupal_get_path_alias($_GET['q']); + $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($block_visibility->pages, '/')) .')$/'; + $page_match = !($block_visibility->visibility xor preg_match($regexp, $path)); + } + else { + $page_match = drupal_eval($block_visibility->pages); + } + } + else { + $page_match = TRUE; + } + + if ($page_match) { + return $block; + } +} + +/** + * Empty form so we can have the default override title. + */ +function ctools_block_content_type_edit_form(&$form, &$form_state) { + // Does nothing! +} + +/** + * The submit form stores the data in $conf. + */ +function ctools_block_content_type_edit_form_submit(&$form, &$form_state) { + $form_state['conf'] = $form_state['values']; +} + +/** + * Returns an edit form for a block. + */ +//function ctools_block_content_type_edit_form($id, $parents, $conf) { +// if (user_access('administer advanced pane settings')) { +// $form['block_visibility'] = array( +// '#type' => 'checkbox', +// '#title' => t('Use block visibility settings (see block config)'), +// '#default_value' => !empty($conf['block_visibility']), +// '#description' => t('If checked, the block visibility settings for this block will apply to this block.'), +// ); +// // Module-specific block configurations. +// if ($settings = module_invoke($module, 'block', 'configure', $delta)) { +// // Specifically modify a couple of core block forms. +// if ($module == 'block') { +// unset($settings['submit']); +// $settings['info']['#type'] = 'value'; +// $settings['info']['#value'] = $settings['info']['#default_value']; +// } +// panels_admin_fix_block_tree($settings); +// $form['block_settings'] = array( +// '#type' => 'fieldset', +// '#title' => t('Block settings'), +// '#description' => t('Settings in this section are global and are for all blocks of this type, anywhere in the system.'), +// '#tree' => FALSE, +// ); +// +// +// $form['block_settings'] += $settings; +// } +// } +// +// return $form; +//} + +//function panels_admin_submit_block(&$form_values) { +// if (!empty($form_values['block_settings'])) { +// module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values['block_settings']); +// } +//} +// +///** +// * Because form api cannot collapse just part of a tree, and the block settings +// * assume no tree, we have to collapse the tree ourselves. +// */ +//function panels_admin_fix_block_tree(&$form, $key = NULL) { +// if ($key) { +// if (!empty($form['#parents'])) { +// $form['#parents'] = array_merge(array('configuration', 'block_settings'), $form['#parents']); +// } +// else if (empty($form['#tree'])) { +// $form['#parents'] = array('configuration', 'block_settings', $key); +// } +// } +// +// if (isset($form['#type']) && $form['#type'] == 'textarea' && !empty($form['#rows']) && $form['#rows'] > 10) { +// $form['#rows'] = 10; +// } +// +// foreach (element_children($form) as $key) { +// panels_admin_fix_block_tree($form[$key], $key); +// } +//} + +/** + * Returns the administrative title for a type. + */ +function ctools_block_content_type_admin_title($subtype, $conf) { + list($module, $delta) = explode('-', $subtype, 2); + $block = module_invoke($module, 'block', 'list'); + if (empty($block) || empty($block[$delta])) { + return t('Deleted/missing block @module-@delta', array('@module' => $module, '@delta' => $delta)); + } + + $title = filter_xss_admin($block[$delta]['info']); + return $title; +} + +/** + * Output function for the 'block' content type. Outputs a block + * based on the module and delta supplied in the configuration. + */ +function ctools_block_content_type_admin_info($subtype, $conf) { + list($module, $delta) = explode('-', $subtype, 2); + $block = (object) module_invoke($module, 'block', 'view', $delta); + if (!empty($block)) { + $block->title = $block->subject; + return $block; + } +} + +/** + * Provide default icon and categories for blocks when modules don't do this + * for us. + */ +function ctools_default_block_info($module, $delta, &$info) { + $core_modules = array('aggregator', 'block', 'blog', 'blogapi', 'book', 'color', 'comment', 'contact', 'drupal', 'filter', 'forum', 'help', 'legacy', 'locale', 'menu', 'node', 'path', 'ping', 'poll', 'profile', 'search', 'statistics', 'taxonomy', 'throttle', 'tracker', 'upload', 'user', 'watchdog', 'system'); + + if (in_array($module, $core_modules)) { + $info['icon'] = 'icon_core_block.png'; + $info['category'] = t('Miscellaneous'); + } + else { + $info['icon'] = 'icon_contrib_block.png'; + $info['category'] = t('Miscellaneous'); + } +} + +// These are all on behalf of modules that don't implement panels but we that +// we care about. +function menu_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_block_menu.png'; + $info['category'] = t('Menus'); + if ($delta == 'primary-links' || $delta == 'secondary-links') { + $info['icon'] = 'icon_core_primarylinks.png'; + } +} + +function forum_ctools_block_info($module, $delta, &$info) { + $info['category'] = t('Activity'); + switch ($delta) { + case '0': + $info['icon'] = 'icon_core_activeforumtopics.png'; + break; + + case '1': + $info['icon'] = 'icon_core_newforumtopics.png'; + break; + + default: + // safety net + panels_default_block_info($module, $delta, $info); + } +} + +function profile_ctools_block_info($module, $delta, &$info) { + // Hide the author information block which isn't as rich as what we can + // do with context. + return NULL; + $info['icon'] = 'icon_core_authorinformation.png'; + $info['category'] = t('Core blocks'); +} + +function book_ctools_block_info($module, $delta, &$info) { + // Hide the book navigation block which isn't as rich as what we can + // do with context. + return NULL; + $info['icon'] = 'icon_core_booknavigation.png'; + $info['category'] = t('Core blocks'); +} + +function blog_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_recentblogposts.png'; + $info['category'] = t('Activity'); +} + +function poll_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_recentpoll.png'; + $info['category'] = t('Activity'); +} + +function comment_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_recentcomments.png'; + $info['category'] = t('Activity'); +} + +function search_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_searchform.png'; + $info['category'] = t('Widgets'); +} + +function node_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_syndicate.png'; + $info['category'] = t('Widgets'); +} + +function aggregator_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_syndicate.png'; + $info['category'] = t('Feeds'); +} + +function block_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_block_empty.png'; + $info['category'] = t('Miscellaneous'); +} + +function user_ctools_block_info($module, $delta, &$info) { + $info['category'] = t('Activity'); + switch ($delta) { + case '0': + $info['icon'] = 'icon_core_userlogin.png'; + $info['category'] = t('Widgets'); + break; + + case '1': + $info['icon'] = 'icon_core_navigation.png'; + $info['category'] = t('Menus'); + break; + + case '2': + $info['icon'] = 'icon_core_whosnew.png'; + break; + + case '3': + $info['icon'] = 'icon_core_whosonline.png'; + break; + + default: + // safety net + ctools_default_block_info($module, $delta, $info); + } +} + +function locale_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_languageswitcher.png'; + $info['category'] = t('Widgets'); +} + +function statistics_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_popularcontent.png'; + $info['category'] = t('Activity'); +} + +function system_ctools_block_info($module, $delta, &$info) { + $info['icon'] = 'icon_core_drupal.png'; + $info['category'] = t('Widgets'); +} diff --git a/plugins/content_types/block/icon_contrib_block.png b/plugins/content_types/block/icon_contrib_block.png new file mode 100644 index 0000000000000000000000000000000000000000..fa78ec179a83428e5b8e247890278cdf91a8cb3e Binary files /dev/null and b/plugins/content_types/block/icon_contrib_block.png differ diff --git a/plugins/content_types/block/icon_contrib_block_empty.png b/plugins/content_types/block/icon_contrib_block_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..6d0891b03d97142074cabbe5ed47175ad01c838e Binary files /dev/null and b/plugins/content_types/block/icon_contrib_block_empty.png differ diff --git a/plugins/content_types/block/icon_contrib_menu.png b/plugins/content_types/block/icon_contrib_menu.png new file mode 100644 index 0000000000000000000000000000000000000000..38cf72090abaa16000c9dceedee8196df1c5251e Binary files /dev/null and b/plugins/content_types/block/icon_contrib_menu.png differ diff --git a/plugins/content_types/block/icon_contrib_page.png b/plugins/content_types/block/icon_contrib_page.png new file mode 100644 index 0000000000000000000000000000000000000000..4a2fa51d3856f366098978742cfe13e9389b487e Binary files /dev/null and b/plugins/content_types/block/icon_contrib_page.png differ diff --git a/plugins/content_types/block/icon_core_activeforumtopics.png b/plugins/content_types/block/icon_core_activeforumtopics.png new file mode 100644 index 0000000000000000000000000000000000000000..8414a8f8829be40a052814087e24c5800dcc6e4b Binary files /dev/null and b/plugins/content_types/block/icon_core_activeforumtopics.png differ diff --git a/plugins/content_types/block/icon_core_authorinformation.png b/plugins/content_types/block/icon_core_authorinformation.png new file mode 100644 index 0000000000000000000000000000000000000000..ab248f3f1bb62536bbf23296a949bfe05cd56bc7 Binary files /dev/null and b/plugins/content_types/block/icon_core_authorinformation.png differ diff --git a/plugins/content_types/block/icon_core_block.png b/plugins/content_types/block/icon_core_block.png new file mode 100644 index 0000000000000000000000000000000000000000..b0d9628adf19efed3b30c847a7511fc093d469b9 Binary files /dev/null and b/plugins/content_types/block/icon_core_block.png differ diff --git a/plugins/content_types/block/icon_core_block_empty.png b/plugins/content_types/block/icon_core_block_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..da08c64c64f2c6f7c5c34a442d4c1e3287f17053 Binary files /dev/null and b/plugins/content_types/block/icon_core_block_empty.png differ diff --git a/plugins/content_types/block/icon_core_block_menu.png b/plugins/content_types/block/icon_core_block_menu.png new file mode 100644 index 0000000000000000000000000000000000000000..84594431b705009714e569d99bf3a2739c42b7f5 Binary files /dev/null and b/plugins/content_types/block/icon_core_block_menu.png differ diff --git a/plugins/content_types/block/icon_core_booknavigation.png b/plugins/content_types/block/icon_core_booknavigation.png new file mode 100644 index 0000000000000000000000000000000000000000..52dfca5369bfd5cabe1b46b7ab9ff54b7c8dc14c Binary files /dev/null and b/plugins/content_types/block/icon_core_booknavigation.png differ diff --git a/plugins/content_types/block/icon_core_languageswitcher.png b/plugins/content_types/block/icon_core_languageswitcher.png new file mode 100644 index 0000000000000000000000000000000000000000..dc4521fffadb3b58e0d6d8a4463e0f99ba17f4a7 Binary files /dev/null and b/plugins/content_types/block/icon_core_languageswitcher.png differ diff --git a/plugins/content_types/block/icon_core_navigation.png b/plugins/content_types/block/icon_core_navigation.png new file mode 100644 index 0000000000000000000000000000000000000000..fb4c1f84f8261e47110d3414be92f9aa910c8646 Binary files /dev/null and b/plugins/content_types/block/icon_core_navigation.png differ diff --git a/plugins/content_types/block/icon_core_newforumtopics.png b/plugins/content_types/block/icon_core_newforumtopics.png new file mode 100644 index 0000000000000000000000000000000000000000..70bbde26bbe02b474b610658a8a97f51707a4ea1 Binary files /dev/null and b/plugins/content_types/block/icon_core_newforumtopics.png differ diff --git a/plugins/content_types/block/icon_core_page.png b/plugins/content_types/block/icon_core_page.png new file mode 100644 index 0000000000000000000000000000000000000000..f0417cb6515aa7fb2856c90722b386ed99bfc501 Binary files /dev/null and b/plugins/content_types/block/icon_core_page.png differ diff --git a/plugins/content_types/block/icon_core_popularcontent.png b/plugins/content_types/block/icon_core_popularcontent.png new file mode 100644 index 0000000000000000000000000000000000000000..70bbde26bbe02b474b610658a8a97f51707a4ea1 Binary files /dev/null and b/plugins/content_types/block/icon_core_popularcontent.png differ diff --git a/plugins/content_types/block/icon_core_primarylinks.png b/plugins/content_types/block/icon_core_primarylinks.png new file mode 100644 index 0000000000000000000000000000000000000000..6dafb99ed084232acc18dfccb2b8f8327051245a Binary files /dev/null and b/plugins/content_types/block/icon_core_primarylinks.png differ diff --git a/plugins/content_types/block/icon_core_recentblogposts.png b/plugins/content_types/block/icon_core_recentblogposts.png new file mode 100644 index 0000000000000000000000000000000000000000..785207ac49e311f1716220982f79afe382c861bb Binary files /dev/null and b/plugins/content_types/block/icon_core_recentblogposts.png differ diff --git a/plugins/content_types/block/icon_core_recentcomments.png b/plugins/content_types/block/icon_core_recentcomments.png new file mode 100644 index 0000000000000000000000000000000000000000..ba96e32a31863c59c6ecab8df957c0da95437532 Binary files /dev/null and b/plugins/content_types/block/icon_core_recentcomments.png differ diff --git a/plugins/content_types/block/icon_core_recentpoll.png b/plugins/content_types/block/icon_core_recentpoll.png new file mode 100644 index 0000000000000000000000000000000000000000..c23fa23e65cc833643971cf2fe2bdbbb0a800348 Binary files /dev/null and b/plugins/content_types/block/icon_core_recentpoll.png differ diff --git a/plugins/content_types/block/icon_core_searchform.png b/plugins/content_types/block/icon_core_searchform.png new file mode 100644 index 0000000000000000000000000000000000000000..3ad1deb65c4a1cada8cdedb7619f3ed5e8ff0587 Binary files /dev/null and b/plugins/content_types/block/icon_core_searchform.png differ diff --git a/plugins/content_types/block/icon_core_syndicate.png b/plugins/content_types/block/icon_core_syndicate.png new file mode 100644 index 0000000000000000000000000000000000000000..27c54bf00c8ef49996f633cef4f998aa6445833b Binary files /dev/null and b/plugins/content_types/block/icon_core_syndicate.png differ diff --git a/plugins/content_types/block/icon_core_userlogin.png b/plugins/content_types/block/icon_core_userlogin.png new file mode 100644 index 0000000000000000000000000000000000000000..dc4521fffadb3b58e0d6d8a4463e0f99ba17f4a7 Binary files /dev/null and b/plugins/content_types/block/icon_core_userlogin.png differ diff --git a/plugins/content_types/block/icon_core_whosnew.png b/plugins/content_types/block/icon_core_whosnew.png new file mode 100644 index 0000000000000000000000000000000000000000..51303e7fae68ef81eb001d8231f486bcf02afee2 Binary files /dev/null and b/plugins/content_types/block/icon_core_whosnew.png differ diff --git a/plugins/content_types/block/icon_core_whosonline.png b/plugins/content_types/block/icon_core_whosonline.png new file mode 100644 index 0000000000000000000000000000000000000000..a5896e3a54bbe148beddc5ef31aa4f93329b60a2 Binary files /dev/null and b/plugins/content_types/block/icon_core_whosonline.png differ diff --git a/plugins/content_types/custom/custom.inc b/plugins/content_types/custom/custom.inc index c28187cb333dbe1d953b745797cc91a3003351ed..26eb6bafc19ee785cdcdfa4b89ee4654bf470ea1 100644 --- a/plugins/content_types/custom/custom.inc +++ b/plugins/content_types/custom/custom.inc @@ -1,6 +1,14 @@ <?php // $Id$ +/** + * @file + * Custom content type. + * + * This content type is nothing more than a title and a body that is entered + * by the user and run through standard filters. The information is stored + * right in the config, so each custom content is unique. + */ /** * Callback function to supply a list of content types. @@ -88,6 +96,9 @@ function ctools_custom_content_type_edit_form(&$form, &$form_state) { return $form; } +/** + * The submit form stores the data in $conf. + */ function ctools_custom_content_type_edit_form_submit(&$form, &$form_state) { $form_state['conf'] = $form_state['values']; }