block.inc

  1. cis7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
  2. cle7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
  3. ecd7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
  4. elmsmedia7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
  5. harmony7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
  6. icor7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
  8. mooc7 sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc

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.

Functions

Namesort descending Description
aggregator_ctools_block_info
block_ctools_block_info
blog_ctools_block_info
book_ctools_block_info
comment_ctools_block_info
ctools_block_content_type_admin_info Output function for the 'block' content type. Outputs a block based on the module and delta supplied in the configuration.
ctools_block_content_type_admin_title Returns the administrative title for a type.
ctools_block_content_type_content_type Return the block content types with the specified $subtype_id.
ctools_block_content_type_content_types Return all block content types available.
ctools_block_content_type_edit_form Empty form so we can have the default override title.
ctools_block_content_type_edit_form_submit Submit function to fix the subtype for really old panel panes.
ctools_block_content_type_render Output function for the 'block' content type. Outputs a block based on the module and delta supplied in the configuration.
ctools_default_block_info Provide default icon and categories for blocks when modules don't do this for us.
ctools_user_login_pane_render
forum_ctools_block_info
locale_ctools_block_info
menu_ctools_block_info
node_ctools_block_info
poll_ctools_block_info
profile_ctools_block_info
search_ctools_block_info
statistics_ctools_block_info
system_ctools_block_info
user_ctools_block_info
_ctools_block_content_type_content_type Return an info array for a specific block.
_ctools_block_get_module_delta
_ctools_block_load_blocks Load block info from the database.
_ctools_get_block_info Fetch the stored info for a block.

File

sites/all/modules/ulmus/ctools/plugins/content_types/block/block.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Provide Drupal blocks as content.
  5. *
  6. * Since blocks don't provide all of the features we do, we have to do a little
  7. * extra work, including providing icons and categories for core blocks. Blocks
  8. * from contrib modules get to provide their own stuff, or get relegated to
  9. * the old "Miscellaneous" category.
  10. */
  11. /**
  12. * Plugins are described by creating a $plugin array which will be used
  13. * by the system that includes this file.
  14. */
  15. $plugin = array(
  16. // And this is just the administrative title.
  17. // All our callbacks are named according to the standard pattern and can be deduced.
  18. 'title' => t('Block'),
  19. 'content type' => 'ctools_block_content_type_content_type',
  20. );
  21. /**
  22. * Return the block content types with the specified $subtype_id.
  23. */
  24. function ctools_block_content_type_content_type($subtype_id) {
  25. list($module, $delta) = explode('-', $subtype_id, 2);
  26. $module_blocks = module_invoke($module, 'block_info');
  27. if (isset($module_blocks[$delta])) {
  28. return _ctools_block_content_type_content_type($module, $delta, $module_blocks[$delta]);
  29. }
  30. }
  31. /**
  32. * Return all block content types available.
  33. *
  34. * Modules wanting to make special adjustments the way that CTools handles their blocks
  35. * can implement an extension to the hook_block() family, where the function name is
  36. * of the form "$module . '_ctools_block_info'".
  37. */
  38. function ctools_block_content_type_content_types() {
  39. $types = &drupal_static(__FUNCTION__);
  40. if (isset($types)) {
  41. return $types;
  42. }
  43. $types = array();
  44. foreach (module_implements('block_info') as $module) {
  45. $module_blocks = module_invoke($module, 'block_info');
  46. if ($module_blocks) {
  47. foreach ($module_blocks as $delta => $block) {
  48. $info = _ctools_block_content_type_content_type($module, $delta, $block);
  49. // this check means modules can remove their blocks; particularly useful
  50. // if they offer the block some other way (like we do for views)
  51. if ($info) {
  52. $types["$module-$delta"] = $info;
  53. }
  54. }
  55. }
  56. }
  57. return $types;
  58. }
  59. /**
  60. * Return an info array for a specific block.
  61. */
  62. function _ctools_block_content_type_content_type($module, $delta, $block) {
  63. // strip_tags used because it goes through check_plain and that
  64. // just looks bad.
  65. $info = array(
  66. 'title' => strip_tags($block['info']),
  67. );
  68. // Ask around for further information by invoking the hook_block() extension.
  69. $function = $module . '_ctools_block_info';
  70. if (!function_exists($function)) {
  71. $function = 'ctools_default_block_info';
  72. }
  73. $function($module, $delta, $info);
  74. return $info;
  75. }
  76. /**
  77. * Load block info from the database.
  78. *
  79. * This is copied from _block_load_blocks(). It doesn't use that
  80. * function because _block_load_blocks sorts by region, and it
  81. * doesn't cache its results anyway.
  82. */
  83. function _ctools_block_load_blocks() {
  84. if (!module_exists('block')) {
  85. return array();
  86. }
  87. $blocks = &drupal_static(__FUNCTION__, NULL);
  88. if (!isset($blocks)) {
  89. global $theme_key;
  90. $query = db_select('block', 'b');
  91. $result = $query
  92. ->fields('b')
  93. ->condition('b.theme', $theme_key)
  94. ->orderBy('b.region')
  95. ->orderBy('b.weight')
  96. ->orderBy('b.module')
  97. ->addTag('block_load')
  98. ->addTag('translatable')
  99. ->execute();
  100. $block_info = $result->fetchAllAssoc('bid');
  101. // Allow modules to modify the block list.
  102. drupal_alter('block_list', $block_info);
  103. $blocks = array();
  104. foreach ($block_info as $block) {
  105. $blocks["{$block->module}_{$block->delta}"] = $block;
  106. }
  107. }
  108. return $blocks;
  109. }
  110. /**
  111. * Fetch the stored info for a block.
  112. *
  113. * The primary reason to use this is so that modules which perform alters
  114. * can have their alters make it to the block.
  115. */
  116. function _ctools_get_block_info($module, $delta) {
  117. $blocks = _ctools_block_load_blocks();
  118. $key = $module . '_' . $delta;
  119. if (isset($blocks[$key])) {
  120. return $blocks[$key];
  121. }
  122. }
  123. /**
  124. * Output function for the 'block' content type. Outputs a block
  125. * based on the module and delta supplied in the configuration.
  126. */
  127. function ctools_block_content_type_render($subtype, $conf) {
  128. list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
  129. $info = _ctools_get_block_info($module, $delta);
  130. $block = module_invoke($module, 'block_view', $delta);
  131. if (!empty($info)) {
  132. // Allow modules to modify the block before it is viewed, via either
  133. // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
  134. drupal_alter(array('block_view', "block_view_{$module}_{$delta}"), $block, $info);
  135. }
  136. $block = (object) $block;
  137. if (empty($block)) {
  138. return;
  139. }
  140. $block->module = $module;
  141. $block->delta = $delta;
  142. if (!isset($block->title)) {
  143. if ($module == 'block' && !empty($info) && isset($info->title)) {
  144. $block->title = $info->title;
  145. }
  146. else if (isset($block->subject)) {
  147. $block->title = $block->subject;
  148. }
  149. else {
  150. $block->title = NULL;
  151. }
  152. }
  153. if (module_exists('block') && user_access('administer blocks')) {
  154. $block->admin_links = array(
  155. array(
  156. 'title' => t('Configure block'),
  157. 'href' => "admin/structure/block/manage/$module/$delta/configure",
  158. 'query' => drupal_get_destination(),
  159. ),
  160. );
  161. }
  162. return $block;
  163. }
  164. /**
  165. * Empty form so we can have the default override title.
  166. */
  167. function ctools_block_content_type_edit_form($form, &$form_state) {
  168. // Does nothing!
  169. return $form;
  170. }
  171. /**
  172. * Submit function to fix the subtype for really old panel panes.
  173. */
  174. function ctools_block_content_type_edit_form_submit($form, &$form_state) {
  175. if (empty($form_state['subtype']) && isset($form_state['pane'])) {
  176. $form_state['pane']->subtype = $form_state['conf']['module'] . '-' . $form_state['conf']['delta'];
  177. unset($form_state['conf']['module']);
  178. unset($form_state['conf']['delta']);
  179. }
  180. }
  181. /**
  182. * Returns an edit form for a block.
  183. */
  184. //function ctools_block_content_type_edit_form($id, $parents, $conf) {
  185. // if (user_access('administer advanced pane settings')) {
  186. // $form['block_visibility'] = array(
  187. // '#type' => 'checkbox',
  188. // '#title' => t('Use block visibility settings (see block config)'),
  189. // '#default_value' => !empty($conf['block_visibility']),
  190. // '#description' => t('If checked, the block visibility settings for this block will apply to this block.'),
  191. // );
  192. // // Module-specific block configurations.
  193. // if ($settings = module_invoke($module, 'block', 'configure', $delta)) {
  194. // // Specifically modify a couple of core block forms.
  195. // if ($module == 'block') {
  196. // unset($settings['submit']);
  197. // $settings['info']['#type'] = 'value';
  198. // $settings['info']['#value'] = $settings['info']['#default_value'];
  199. // }
  200. // ctools_admin_fix_block_tree($settings);
  201. // $form['block_settings'] = array(
  202. // '#type' => 'fieldset',
  203. // '#title' => t('Block settings'),
  204. // '#description' => t('Settings in this section are global and are for all blocks of this type, anywhere in the system.'),
  205. // '#tree' => FALSE,
  206. // );
  207. //
  208. //
  209. // $form['block_settings'] += $settings;
  210. // }
  211. // }
  212. //
  213. // return $form;
  214. //}
  215. //function ctools_admin_submit_block(&$form_values) {
  216. // if (!empty($form_values['block_settings'])) {
  217. // module_invoke($form_values['module'], 'block', 'save', $form_values['delta'], $form_values['block_settings']);
  218. // }
  219. //}
  220. //
  221. ///**
  222. // * Because form api cannot collapse just part of a tree, and the block settings
  223. // * assume no tree, we have to collapse the tree ourselves.
  224. // */
  225. //function ctools_admin_fix_block_tree(&$form, $key = NULL) {
  226. // if ($key) {
  227. // if (!empty($form['#parents'])) {
  228. // $form['#parents'] = array_merge(array('configuration', 'block_settings'), $form['#parents']);
  229. // }
  230. // else if (empty($form['#tree'])) {
  231. // $form['#parents'] = array('configuration', 'block_settings', $key);
  232. // }
  233. // }
  234. //
  235. // if (isset($form['#type']) && $form['#type'] == 'textarea' && !empty($form['#rows']) && $form['#rows'] > 10) {
  236. // $form['#rows'] = 10;
  237. // }
  238. //
  239. // foreach (element_children($form) as $key) {
  240. // ctools_admin_fix_block_tree($form[$key], $key);
  241. // }
  242. //}
  243. /**
  244. * Returns the administrative title for a type.
  245. */
  246. function ctools_block_content_type_admin_title($subtype, $conf) {
  247. list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
  248. $block = module_invoke($module, 'block_info');
  249. if (empty($block) || empty($block[$delta])) {
  250. return t('Deleted/missing block @module-@delta', array('@module' => $module, '@delta' => $delta));
  251. }
  252. // The block description reported by hook_block() is plain text, but the title
  253. // reported by this hook should be HTML.
  254. $title = check_plain($block[$delta]['info']);
  255. return $title;
  256. }
  257. /**
  258. * Output function for the 'block' content type. Outputs a block
  259. * based on the module and delta supplied in the configuration.
  260. */
  261. function ctools_block_content_type_admin_info($subtype, $conf) {
  262. list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
  263. $block = (object) module_invoke($module, 'block_view', $delta);
  264. if (!empty($block)) {
  265. // Sanitize the block because <script> tags can hose javascript up:
  266. if (!empty($block->content)) {
  267. $block->content = filter_xss_admin(render($block->content));
  268. }
  269. if (!empty($block->subject)) {
  270. $block->title = $block->subject;
  271. }
  272. elseif (empty($block->title)) {
  273. $block->title = t('No title');
  274. }
  275. return $block;
  276. }
  277. }
  278. function _ctools_block_get_module_delta($subtype, $conf) {
  279. if (strpos($subtype, '-')) {
  280. return explode('-', $subtype, 2);
  281. }
  282. else {
  283. return array($conf['module'], $conf['delta']);
  284. }
  285. }
  286. /**
  287. * Provide default icon and categories for blocks when modules don't do this
  288. * for us.
  289. */
  290. function ctools_default_block_info($module, $delta, &$info) {
  291. $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');
  292. if (in_array($module, $core_modules)) {
  293. $info['icon'] = 'icon_core_block.png';
  294. $info['category'] = t('Miscellaneous');
  295. }
  296. else {
  297. $info['icon'] = 'icon_contrib_block.png';
  298. $info['category'] = t('Miscellaneous');
  299. }
  300. }
  301. // These are all on behalf of modules that don't implement ctools but that
  302. // we care about.
  303. function menu_ctools_block_info($module, $delta, &$info) {
  304. $info['icon'] = 'icon_core_block_menu.png';
  305. $info['category'] = t('Menus');
  306. if ($delta == 'primary-links' || $delta == 'secondary-links') {
  307. $info['icon'] = 'icon_core_primarylinks.png';
  308. }
  309. }
  310. function forum_ctools_block_info($module, $delta, &$info) {
  311. $info['category'] = t('Activity');
  312. switch ($delta) {
  313. case 'active':
  314. $info['icon'] = 'icon_core_activeforumtopics.png';
  315. break;
  316. case 'new':
  317. $info['icon'] = 'icon_core_newforumtopics.png';
  318. break;
  319. default:
  320. // safety net
  321. ctools_default_block_info($module, $delta, $info);
  322. }
  323. }
  324. function profile_ctools_block_info($module, $delta, &$info) {
  325. // Hide the author information block which isn't as rich as what we can
  326. // do with context.
  327. $info = NULL;
  328. }
  329. function book_ctools_block_info($module, $delta, &$info) {
  330. // Hide the book navigation block which isn't as rich as what we can
  331. // do with context.
  332. $info = NULL;
  333. }
  334. function blog_ctools_block_info($module, $delta, &$info) {
  335. $info['icon'] = 'icon_core_recentblogposts.png';
  336. $info['category'] = t('Activity');
  337. }
  338. function poll_ctools_block_info($module, $delta, &$info) {
  339. $info['icon'] = 'icon_core_recentpoll.png';
  340. $info['category'] = t('Activity');
  341. }
  342. function comment_ctools_block_info($module, $delta, &$info) {
  343. $info['icon'] = 'icon_core_recentcomments.png';
  344. $info['category'] = t('Activity');
  345. }
  346. function search_ctools_block_info($module, $delta, &$info) {
  347. $info['icon'] = 'icon_core_searchform.png';
  348. $info['category'] = t('Widgets');
  349. }
  350. function node_ctools_block_info($module, $delta, &$info) {
  351. $info['icon'] = 'icon_core_syndicate.png';
  352. $info['category'] = t('Widgets');
  353. }
  354. function aggregator_ctools_block_info($module, $delta, &$info) {
  355. $info['icon'] = 'icon_core_syndicate.png';
  356. $info['category'] = t('Feeds');
  357. }
  358. function block_ctools_block_info($module, $delta, &$info) {
  359. $info['icon'] = 'icon_core_block_empty.png';
  360. $info['category'] = t('Custom blocks');
  361. // The title of custom blocks from the block module is stored in the
  362. // {block} table. Look for it in the default theme as a reasonable
  363. // default value for the title.
  364. $block_info_cache = drupal_static(__FUNCTION__);
  365. if (!isset($block_info_cache)) {
  366. $block_info_cache = db_select('block', 'b')
  367. ->fields('b')
  368. ->condition('b.module', 'block')
  369. ->condition('b.theme', variable_get('theme_default', 'bartik'))
  370. ->addTag('block_load')
  371. ->addTag('translatable')
  372. ->execute()
  373. ->fetchAllAssoc('delta');
  374. }
  375. if (isset($block_info_cache[$delta])) {
  376. $info['defaults'] = array(
  377. 'override_title' => TRUE,
  378. 'override_title_text' => $block_info_cache[$delta]->title,
  379. );
  380. }
  381. }
  382. function user_ctools_block_info($module, $delta, &$info) {
  383. $info['category'] = t('Activity');
  384. switch ($delta) {
  385. case 'login':
  386. $info['icon'] = 'icon_core_userlogin.png';
  387. $info['category'] = t('Widgets');
  388. // Provide a custom render callback, because the default login block
  389. // will not render on /user, /user/login, or any other URL beginning
  390. // /user (unless it's a user-specific page such as /user/123).
  391. $info['render callback'] = 'ctools_user_login_pane_render';
  392. break;
  393. case 'new':
  394. $info['icon'] = 'icon_core_whosnew.png';
  395. break;
  396. case 'online':
  397. $info['icon'] = 'icon_core_whosonline.png';
  398. break;
  399. default:
  400. // safety net
  401. ctools_default_block_info($module, $delta, $info);
  402. }
  403. }
  404. function locale_ctools_block_info($module, $delta, &$info) {
  405. $info['icon'] = 'icon_core_languageswitcher.png';
  406. $info['category'] = t('Widgets');
  407. }
  408. function statistics_ctools_block_info($module, $delta, &$info) {
  409. $info['icon'] = 'icon_core_popularcontent.png';
  410. $info['category'] = t('Activity');
  411. }
  412. function system_ctools_block_info($module, $delta, &$info) {
  413. // Remove the main content fake block.
  414. if ($delta == 'main') {
  415. $info = NULL;
  416. return;
  417. }
  418. $menus = array('main-menu', 'management', 'navigation', 'user-menu');
  419. if (in_array($delta, $menus)) {
  420. $info['icon'] = 'icon_core_block_menu.png';
  421. $info['category'] = t('Menus');
  422. if ($delta == 'navigation') {
  423. $info['icon'] = 'icon_core_navigation.png';
  424. }
  425. return;
  426. }
  427. $info['icon'] = 'icon_core_drupal.png';
  428. if ($delta == 'help') {
  429. $info['category'] = t('Page elements');
  430. return;
  431. }
  432. $info['category'] = t('Widgets');
  433. }
  434. function ctools_user_login_pane_render($subtype, $conf, $panel_args, $contexts) {
  435. list($module, $delta) = _ctools_block_get_module_delta($subtype, $conf);
  436. // The login form is only visible to anonymous users.
  437. global $user;
  438. if ($user->uid) {
  439. return;
  440. }
  441. $info = new stdClass;
  442. $info->module = $module;
  443. $info->delta = $delta;
  444. $block = array();
  445. $block['subject'] = t('User login');
  446. // Manually set the content (rather than invoking block_view) because the
  447. // block implementation won't render on certain URLs.
  448. $block['content'] = drupal_get_form('user_login_block');
  449. // Allow modules to modify the block before it is viewed, via either
  450. // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
  451. drupal_alter(array('block_view', "block_view_{$module}_{$delta}"), $block, $info);
  452. $block = (object) $block;
  453. if (empty($block)) {
  454. return;
  455. }
  456. $block->module = $module;
  457. $block->delta = $delta;
  458. // $block->title is not set for the blocks returned by block_block() (the
  459. // Block module adds the title in block_list() instead), so we look it up
  460. // manually, unless the title is overridden and does not use the %title
  461. // placeholder.
  462. if ($module == 'block') {
  463. $block->title = $info->title;
  464. }
  465. else if (isset($block->subject)) {
  466. $block->title = $block->subject;
  467. }
  468. else {
  469. $block->title = NULL;
  470. }
  471. if (isset($block->subject)) {
  472. $block->title = $block->subject;
  473. }
  474. else {
  475. $block->title = NULL;
  476. }
  477. if (user_access('administer blocks')) {
  478. $block->admin_links = array(
  479. array(
  480. 'title' => t('Configure block'),
  481. 'href' => "admin/structure/block/manage/$module/$delta/configure",
  482. 'query' => drupal_get_destination(),
  483. ),
  484. );
  485. }
  486. return $block;
  487. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.