EclipseGc

Untitled

Jul 3rd, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.26 KB | None | 0 0
  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. /**
  13.  * Plugins are described by creating a $plugin array which will be used
  14.  * by the system that includes this file.
  15.  */
  16. $plugin = array(
  17.   // And this is just the administrative title.
  18.   // All our callbacks are named according to the standard pattern and can be deduced.
  19.   'title' => t('Facet Block'),
  20.   'content type' => 'solr_shows_facet_blocks_content_type_content_type',
  21.   'render last' => TRUE,
  22. );
  23.  
  24. /**
  25.  * Return the block content types with the specified $subtype_id.
  26.  */
  27. function solr_shows_facet_blocks_content_type_content_type($subtype_id) {
  28.   list($module, $delta) = explode('-', $subtype_id, 2);
  29.   $module_blocks = module_invoke('facetapi', 'block_info');
  30.   if (isset($module_blocks[$delta])) {
  31.     return _solr_shows_facet_blocks_content_type_content_type($module, $delta, $module_blocks[$delta]);
  32.   }
  33. }
  34.  
  35. /**
  36.  * Return all block content types available.
  37.  *
  38.  * Modules wanting to make special adjustments the way that CTools handles their blocks
  39.  * can implement an extension to the hook_block() family, where the function name is
  40.  * of the form "$module . '_solr_shows_facet_blocks_info'".
  41.  */
  42. function solr_shows_facet_blocks_content_type_content_types() {
  43.   $types = array();
  44.   $module = 'facetapi';
  45.   $module_blocks = module_invoke($module, 'block_info');
  46.   if ($module_blocks) {
  47.     foreach ($module_blocks as $delta => $block) {
  48.       $info = _solr_shows_facet_blocks_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["facet_blocks-$delta"] = $info;
  53.       }
  54.     }
  55.   }
  56.   return $types;
  57. }
  58.  
  59. /**
  60.  * Return an info array for a specific block.
  61.  */
  62. function _solr_shows_facet_blocks_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.  
  69.   // Ask around for further information by invoking the hook_block() extension.
  70.   $function = $module . '_solr_shows_facet_blocks_info';
  71.   if (!function_exists($function)) {
  72.     $function = 'solr_shows_default_block_info';
  73.   }
  74.   $function($module, $delta, $info);
  75.  
  76.   return $info;
  77. }
  78.  
  79. /**
  80.  * Output function for the 'block' content type. Outputs a block
  81.  * based on the module and delta supplied in the configuration.
  82.  */
  83. function solr_shows_facet_blocks_content_type_render($subtype, $conf) {
  84.   list($module, $delta) = _solr_shows_facet_blocks_get_module_delta($subtype, $conf);
  85.   $module = 'facetapi';
  86.  
  87.   $info = new stdClass;
  88.   $info->module = $module;
  89.   $info->delta = $delta;
  90.   $block = module_invoke($module, 'block_view', $delta);
  91.  
  92.   // Allow modules to modify the block before it is viewed, via either
  93.   // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
  94.   drupal_alter(array('block_view', "block_view_{$module}_{$delta}"), $block, $info);
  95.   $block = (object) $block;
  96.  
  97.   if (empty($block)) {
  98.     return;
  99.   }
  100.  
  101.   $block->module = $module;
  102.   $block->delta = $delta;
  103.  
  104.   if (isset($block->subject)) {
  105.     $block->title = $block->subject;
  106.   }
  107.   else {
  108.     $block->title = NULL;
  109.   }
  110.  
  111.   if (module_exists('block') && user_access('administer blocks')) {
  112.     $block->admin_links = array(
  113.       array(
  114.         'title' => t('Configure block'),
  115.         'href' => "admin/structure/block/manage/$module/$delta/configure",
  116.         'query' => drupal_get_destination(),
  117.       ),
  118.     );
  119.   }
  120.  
  121.   return $block;
  122. }
  123.  
  124. /**
  125.  * Empty form so we can have the default override title.
  126.  */
  127. function solr_shows_facet_blocks_content_type_edit_form($form, &$form_state) {
  128.   // Does nothing!
  129.   return $form;
  130. }
  131.  
  132. /**
  133.  * Submit function to fix the subtype for really old panel panes.
  134.  */
  135. function solr_shows_facet_blocks_content_type_edit_form_submit($form, &$form_state) {
  136.   if (empty($form_state['subtype']) && isset($form_state['pane'])) {
  137.     $form_state['pane']->subtype = $form_state['conf']['module'] . '-' . $form_state['conf']['delta'];
  138.     unset($form_state['conf']['module']);
  139.     unset($form_state['conf']['delta']);
  140.   }
  141. }
  142.  
  143. /**
  144.  * Returns the administrative title for a type.
  145.  */
  146. function solr_shows_facet_blocks_content_type_admin_title($subtype, $conf) {
  147.   list($module, $delta) = _solr_shows_facet_blocks_get_module_delta($subtype, $conf);
  148.   $module = 'facetapi';
  149.   $block = module_invoke($module, 'block_info');
  150.   if (empty($block) || empty($block[$delta])) {
  151.     return t('Deleted/missing block @module-@delta', array('@module' => $module, '@delta' => $delta));
  152.   }
  153.  
  154.   // The block description reported by hook_block() is plain text, but the title
  155.   // reported by this hook should be HTML.
  156.   $title = check_plain($block[$delta]['info']);
  157.   return $title;
  158. }
  159.  
  160. /**
  161.  * Output function for the 'block' content type. Outputs a block
  162.  * based on the module and delta supplied in the configuration.
  163.  */
  164. function solr_shows_facet_blocks_content_type_admin_info($subtype, $conf) {
  165.   list($module, $delta) = _solr_shows_facet_blocks_get_module_delta($subtype, $conf);
  166.   $module = 'facetapi';
  167.   $block = (object) module_invoke($module, 'block', 'view', $delta);
  168.  
  169.   // Sanitize the block because <script> tags can hose javascript up:
  170.   if (!empty($block->content)) {
  171.     $block->content = filter_xss_admin($block->content);
  172.   }
  173.  
  174.   if (!empty($block) && !empty($block->subject)) {
  175.     $block->title = $block->subject;
  176.     return $block;
  177.   }
  178. }
  179.  
  180. function _solr_shows_facet_blocks_get_module_delta($subtype, $conf) {
  181.   if (strpos($subtype, '-')) {
  182.     return explode('-', $subtype, 2);
  183.   }
  184.   else {
  185.     return array($conf['module'], $conf['delta']);
  186.   }
  187. }
  188.  
  189. /**
  190.  * Provide default icon and categories for blocks when modules don't do this
  191.  * for us.
  192.  */
  193. function solr_shows_default_block_info($module, $delta, &$info) {
  194.   $info['icon'] = 'icon_contrib_block.png';
  195.   $info['category'] = t('Facets');
  196. }
Advertisement
Add Comment
Please, Sign In to add comment