diff --git a/homebox_panels/homebox-readonly-block.tpl.php b/homebox_panels/homebox-readonly-block.tpl.php new file mode 100644 index 0000000..c9697ae --- /dev/null +++ b/homebox_panels/homebox-readonly-block.tpl.php @@ -0,0 +1,15 @@ + +
+
+

+ subject ?> +

+
content)){ print $block->content; } else { print drupal_render($block->content); } ?>
+
+
diff --git a/homebox_panels/homebox-readonly.css b/homebox_panels/homebox-readonly.css new file mode 100644 index 0000000..90437a3 --- /dev/null +++ b/homebox_panels/homebox-readonly.css @@ -0,0 +1,89 @@ +.homebox-readonly { + position: relative; +} + +/* +** Columns/regions +*/ + +.homebox-readonly .homebox-column { + margin: 2px; + padding: 5px; + min-height: 40px; +} + +.homebox-readonly .homebox-column-wrapper { + float: left; +} +.homebox-readonly .homebox-maximized { + width: 100%; +} +/* +** Portlets/boxes +*/ +.homebox-readonly .homebox-portlet { + margin: 2px 0 5px; + padding: 0; + border: 3px solid #eee; + background-color: white; +} +.homebox-readonly .homebox-portlet .homebox-portlet-inner { + border: 1px solid #c0c0c0; + overflow: hidden; +} +.homebox-readonly .portlet-content { + padding: 4px; +} +.homebox-readonly .homebox-portlet-collapsed .portlet-content { + display: none; +} +.homebox-readonly .homebox-portlet .portlet-header { + margin: 0; + padding: 2px 4px; + border-bottom: 1px solid #ddd; + background: #e4f0f8; /* matches garland */ + color: #494949; + min-height: 18px; + font-size: 1em; +} +.homebox-readonly .homebox-portlet .portlet-header .portlet-title { + display: block; + z-index: 9; /* IE is terrible */ + position: relative; /* IE is terrible */ +} +.homebox-readonly .homebox-portlet div.views-exposed-widgets { + padding: 0 7px; +} +.homebox-readonly div.view-header { + text-align: right; +} +.homebox-readonly .portlet-maximized { + clear: both; +} + +/* +** Closed box/portlet class +*/ +.homebox-readonly .homebox-portlet-closed { + display: none; +} + +/* +** Placeholder +*/ +.homebox-readonly .homebox-placeholder { + visibility: visible !important; + margin: 5px 0; + padding: 0; + /*background: #FFFFDD;*/ + border: 3px dashed #ccc; +} +.homebox-readonly .homebox-placeholder * { + visibility: hidden; +} + +.homebox-readonly .used { + background: #F0F0F0; + border-top: 1px solid #FFFFFF; + outline: 1px solid #DDDDDD; +} diff --git a/homebox_panels/homebox-readonly.js b/homebox_panels/homebox-readonly.js new file mode 100644 index 0000000..8166f48 --- /dev/null +++ b/homebox_panels/homebox-readonly.js @@ -0,0 +1,55 @@ +(function ($) { + + Drupal.homeboxReadonly = {}; + + Drupal.behaviors.homeboxReadonly = { + attach: function (context) { + var $homebox = $('.homebox-readonly:not(.homebox-processed)', context).addClass('homebox-processed'); + + if ($homebox.length > 0) { + // Find all columns + var $columns = $homebox.find('div.homebox-column'); + + // Equilize columns height + Drupal.homeboxReadonly.equalizeColumnsHeights($columns); + + // Equalize column heights after AJAX calls + $homebox.ajaxStop(function () { + Drupal.homeboxReadonly.equalizeColumnsHeights($columns); + }); + } + } + }; + + /** + * Set all column heights equal + */ + Drupal.homeboxReadonly.equalizeColumnsHeights = function (columns) { + var maxHeight = {}, row; + columns.each(function () { + row = $(this).parent('.homebox-column-wrapper').attr('class').match(/homebox-row-(\d+)/i)[1]; + $(this).height('auto'); + maxHeight[row] = maxHeight[row] ? Math.max($(this).height(), maxHeight[row]) : $(this).height(); + }).each(function () { + row = $(this).parent('.homebox-column-wrapper').attr('class').match(/homebox-row-(\d+)/i)[1]; + $(this).height(maxHeight[row]); + }); + }; + + Drupal.behaviors.homeboxReadonlyPortlet = { + attach: function (context) { + $('.homebox-portlet:not(.homebox-processed)', context).addClass('homebox-processed').each(function () { + var $portlet = $(this); + var $portletHeader = $portlet.find('.portlet-header'); + + $.each($portlet.attr('class').split(' '), function (key, a) { + if (a.substr(0, 14) === 'homebox-color-') { + $portletHeader.attr('style', 'background: #' + a.substr(14)); + $portlet.find('.homebox-portlet-inner').attr('style', 'border: 1px solid #' + a.substr(14)); + } + }); + + }); + } + }; +})(jQuery); diff --git a/homebox_panels/homebox-readonly.tpl.php b/homebox_panels/homebox-readonly.tpl.php new file mode 100644 index 0000000..865dfbf --- /dev/null +++ b/homebox_panels/homebox-readonly.tpl.php @@ -0,0 +1,24 @@ + +
+
+ +
settings['widths'][$i] ? ' style="width: ' . $page->settings['widths'][$i] . '%;"' : ''; ?>> +
+ $weight): ?> + + content): ?> + $block, 'page' => $page)); ?> + + + +
+
+ +
diff --git a/homebox_panels/homebox_panels.info b/homebox_panels/homebox_panels.info new file mode 100644 index 0000000..87d9cf5 --- /dev/null +++ b/homebox_panels/homebox_panels.info @@ -0,0 +1,6 @@ +name = Homebox panels +description = Provides panel panes containing homebox pages. +core = 7.x +package = Homebox +dependencies[] = homebox +dependencies[] = panels diff --git a/homebox_panels/homebox_panels.module b/homebox_panels/homebox_panels.module new file mode 100644 index 0000000..b9b7003 --- /dev/null +++ b/homebox_panels/homebox_panels.module @@ -0,0 +1,50 @@ + array( + 'variables' => array('regions' => NULL, 'available_blocks' => NULL, 'column_count' => NULL, 'page' => NULL), + 'template' => 'homebox-readonly', // Set template to homebox-readonly.tpl.php + ), + 'homebox_readonly_block' => array( + 'variables' => array('block' => NULL, 'page' => NULL), + 'template' => 'homebox-readonly-block', // Set template to homebox-readonly-block.tpl.php + ), + ); +} + +/** + * Preprocesses variables for homebox-readonly.tpl.php template + * + * @param $variables + * An array containing variables to used in home-box.tpl.php + * @return + * An array containing preprocessed variables (see homebox-readonly.tpl.php) + */ +function template_preprocess_homebox_readonly(&$variables) { + // Add Homebox JavaScript files + drupal_add_js(drupal_get_path('module', 'homebox_panels') . '/homebox-readonly.js', + array('type' => 'file', 'scope' => 'header', 'group' => JS_DEFAULT, 'defer' => FALSE, 'cache' => TRUE, 'preprocess' => TRUE)); + + // Add CSS for homebox + drupal_add_css(drupal_get_path('module', 'homebox') . '/homebox.css', + array('type' => 'file', 'group' => CSS_DEFAULT, 'media' => 'all', 'preprocess' => TRUE)); + drupal_add_css(drupal_get_path('module', 'homebox_panels') . '/homebox-readonly.css', + array('type' => 'file', 'group' => CSS_DEFAULT, 'media' => 'all', 'preprocess' => TRUE)); + + + $variables['classes_array'][] = 'column-count-' . $variables['column_count']; + $variables['classes_array'][] = 'homebox-' . $variables['page']->name; +} diff --git a/homebox_panels/plugins/content_types/homebox_page.inc b/homebox_panels/plugins/content_types/homebox_page.inc new file mode 100644 index 0000000..45f54bb --- /dev/null +++ b/homebox_panels/plugins/content_types/homebox_page.inc @@ -0,0 +1,183 @@ + TRUE, + 'title' => t('Homebox page'), + 'description' => t('Homebox page with widgets.'), + 'category' => t('Miscellaneous'), + 'defaults' => array( + 'homebox_page' => '', + 'readonly' => FALSE, + ), +); + +/** + * Returns an edit form for custom settings. + */ +function homebox_panels_homebox_page_content_type_edit_form($form, &$form_state) { + $conf = $form_state['conf']; + $pages = homebox_pages(); + $page_names = array(); + if (!empty($pages)) { + foreach ($pages as $page) { + $page_names[$page->name] = $page->name; + } + } + + $form['homebox_page'] = array( + '#title' => t('Homebox page'), + '#type' => 'select', + '#options' => $page_names, + '#default_value' => $conf['homebox_page'], + ); + + $form['readonly'] = array( + '#title' => t('Read only'), + '#type' => 'checkbox', + '#default_value' => $conf['readonly'], + ); + + return $form; +} + +/** + * Submit handler for the custom settings form. + */ +function homebox_panels_homebox_page_content_type_edit_form_submit($form, &$form_state) { + // Copy everything from our defaults. + foreach (array_keys($form_state['plugin']['defaults']) as $key) { + $form_state['conf'][$key] = $form_state['values'][$key]; + } +} + +/** + * Render the homebox page. + */ +function homebox_panels_homebox_page_content_type_render($subtype, $conf, $panel_args, $context) { + $page_name = $conf['homebox_page']; + $read_only = $conf['readonly']; + + $content = ''; + $page = homebox_get_page($page_name); + if ($page) { + if ($read_only) { + $content = homebox_panels_homebox_page_content_type_read_only_page($page); + } + else { + $page->settings['full'] = FALSE; + $content = homebox_build($page); + } + } + + $block = new stdClass(); + $block->module = 'homebox_panels'; + $block->title = t('Homebox page'); + $block->content = $content; + $block->delta = $page_name; + + return $block; +} + +/** + * A copy of homebox_build() with editing disabled. + */ +function homebox_panels_homebox_page_content_type_read_only_page($page) { + global $user; + + // If no default block layout is set, return a simple message + if (empty($page->settings['blocks'])) { + return ''; + } + + // Get every block placed into its region sorted by weight + $column_count = $page->settings['regions']; + $regions = array_fill(1, $column_count, array()); + + // Extract blocks from the page + $blocks = $page->settings['blocks']; + $allowed_blocks = array(); + $info = array(); + foreach ($blocks as $block) { + if (!isset($info[$block['module']])) { + $info[$block['module']] = module_invoke($block['module'], 'block_info'); + } + if (isset($info[$block['module']][$block['delta']])) { + $allowed_blocks[$block['module']][$block['delta']] = $info[$block['module']][$block['delta']]; + if (!empty($block['title'])) { + $allowed_blocks[$block['module']][$block['delta']]['info'] = $block['title']; + } + } + } + + // Get user settings, so custom blocks are placed in regions. + $user_blocks = _homebox_get_user_settings($page); + + if ($user_blocks !== FALSE) { + // Add custom blocks. + foreach ($user_blocks as $key => $block) { + if (isset($allowed_blocks[$block['module']][$block['delta']])) { + $blocks[$key] = $user_blocks[$key]; + } + } + } + + // Preparing blocks object for theming + foreach ($blocks as $key => $block_settings) { + // Adds block to its regions + if ($block_settings['status']) { + $block = homebox_prepare_block($key, $page); + if (!is_null($block)) { + $block->closable = FALSE; + $block->homebox_classes = 'homebox-portlet homebox-unclosable'; + // If user defined region is greater than real column count put block in + // the last column/region. + $regions[min($block->region, $column_count)][$block->weight][] = $block; + $allowed_blocks[$block->module][$block->delta]['used'] = TRUE; + } + } + } + + // Sort each region/column based on key value + // Also separate the regions into rows based on the region widths + $sum_width = 0; + $row = 0; + for ($i = 1; $i <= count($regions); $i++) { + ksort($regions[$i]); + $sum_width += $page->settings['widths'][$i]; + if ($sum_width > 100) { + $row++; + $sum_width = 0; + } + $page->settings['rows'][$i] = $row; + } + + // Add block links + $add_links = NULL; + $save_form = NULL; + if ($user->uid) { + foreach ($allowed_blocks as $module => $blocks) { + foreach ($blocks as $delta => $info) { + $options = array(); + if (isset($info['used'])) { + $options['attributes'] = array('class' => 'used'); + } + } + } + } + + // If custom widths aren't set, make each width a percentage of the total available. + if (!count($page->settings['widths'])) { + $num_regions = count($regions); + for ($i = 1; $i <= $num_regions; $i++) { + // We use a combination of round() and floor() to get this rounded to two decimal places + // since the $mode argument isn't introducted into round() until PHP 5.3.0. + $page->settings['widths'][$i] = round(floor((100 / $num_regions) * 100) / 100, 2); + } + } + + // Build output + $output = theme('homebox_readonly', array('regions' => $regions, 'available_blocks' => $allowed_blocks, 'column_count' => $column_count, 'page' => $page, + 'add_links' => $add_links, 'save_form' => $save_form)); + + return $output; +}