123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681 |
- <?php
- function dashboard_help($path, $arg) {
- switch ($path) {
- case 'admin/help#dashboard':
- $output = '';
- $output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('The Dashboard module provides a <a href="@dashboard">Dashboard page</a> in the administrative interface for organizing administrative tasks and navigation, and tracking information within your site. The Dashboard page contains blocks, which you can add to and arrange using the drag-and-drop interface that appears when you click on the <em>Customize dashboard</em> link. Within this interface, blocks that are not primarily used for site administration do not appear by default, but can be added via the <em>Add other blocks</em> link. For more information, see the online handbook entry for <a href="@handbook">Dashboard module</a>.', array('@handbook' => 'http://drupal.org/documentation/modules/dashboard', '@dashboard' => url('admin/dashboard'))) . '</p>';
- $output .= '<h3>' . t('Uses') . '</h3>';
- $output .= '<dl>';
- $output .= '<dt>' . t('Tracking user activity') . '</dt>';
- $output .= '<dd>' . t("By enabling blocks such as <em>Who's online</em> and <em>Who's new</em>, site users can track who is logged in and new user signups at a centralized location.") . '</dd>';
- $output .= '<dt>' . t('Tracking content activity') . '</dt>';
- $output .= '<dd>' . t('By enabling blocks such as <em>Recent blog posts</em>, <em>New forum topics</em> and <em>Recent comments</em>, site users can view newly added site content at a glance.') . '</dd>';
- $output .= '</dl>';
- return $output;
- case 'admin/dashboard/configure':
-
-
- $output = '<p>' . t('Rearrange blocks for display on the <a href="@dashboard-url">Dashboard page</a>. Blocks placed in the <em>Dashboard (inactive)</em> region are not displayed when viewing the Dashboard page, but are available within its <em>Customize dashboard</em> interface. Removing a block from active dashboard display makes it available on the main <a href="@blocks-url">blocks administration page</a>.', array('@dashboard-url' => url('admin/dashboard'), '@blocks-url' => url("admin/structure/block/list/{$GLOBALS['theme_key']}"))) . '</p>';
- return $output;
- }
- }
- function dashboard_menu() {
- $items['admin/dashboard'] = array(
- 'title' => 'Dashboard',
- 'description' => 'View and customize your dashboard.',
- 'page callback' => 'dashboard_admin',
- 'access arguments' => array('access dashboard'),
-
-
- 'weight' => -15,
- );
- $items['admin/dashboard/configure'] = array(
- 'title' => 'Configure available dashboard blocks',
- 'description' => 'Configure which blocks can be shown on the dashboard.',
- 'page callback' => 'dashboard_admin_blocks',
- 'access arguments' => array('administer blocks'),
- 'type' => MENU_VISIBLE_IN_BREADCRUMB,
- );
- $items['admin/dashboard/customize'] = array(
- 'title' => 'Customize dashboard',
- 'description' => 'Customize your dashboard.',
- 'page callback' => 'dashboard_admin',
- 'page arguments' => array(TRUE),
- 'access arguments' => array('access dashboard'),
- 'type' => MENU_VISIBLE_IN_BREADCRUMB,
- );
- $items['admin/dashboard/drawer'] = array(
- 'page callback' => 'dashboard_show_disabled',
- 'access arguments' => array('administer blocks'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/dashboard/block-content/%/%'] = array(
- 'page callback' => 'dashboard_show_block_content',
- 'page arguments' => array(3, 4),
- 'access arguments' => array('administer blocks'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/dashboard/update'] = array(
- 'page callback' => 'dashboard_update',
- 'access arguments' => array('administer blocks'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- function dashboard_permission() {
- return array(
- 'access dashboard' => array(
- 'title' => t('View the administrative dashboard'),
-
-
-
- 'description' => t('Customizing the dashboard requires the !permission-name permission.', array(
- '!permission-name' => l(t('Administer blocks'), 'admin/people/permissions', array('fragment' => 'module-block')),
- )),
- ),
- );
- }
- function dashboard_block_info_alter(&$blocks, $theme, $code_blocks) {
- $admin_theme = variable_get('admin_theme');
- if (($admin_theme && $theme == $admin_theme) || (!$admin_theme && $theme == variable_get('theme_default', 'bartik'))) {
- foreach ($blocks as $module => &$module_blocks) {
- foreach ($module_blocks as $delta => &$block) {
-
-
- if (empty($block['status']) && (empty($block['region']) || $block['region'] == BLOCK_REGION_NONE) && !empty($code_blocks[$module][$delta]['properties']['administrative'])) {
- $block['status'] = 1;
- $block['region'] = 'dashboard_inactive';
- }
- }
- }
- }
- }
- function dashboard_block_list_alter(&$blocks) {
- if (!dashboard_is_visible()) {
- foreach ($blocks as $key => $block) {
- if (in_array($block->region, dashboard_regions())) {
- unset($blocks[$key]);
- }
- }
- }
- }
- function dashboard_page_build(&$page) {
- global $theme_key;
- if (dashboard_is_visible()) {
- $block_info = array();
-
-
- $page['content']['dashboard'] = array('#theme_wrappers' => array('dashboard'));
- foreach (dashboard_regions() as $region) {
-
- if ($region == 'dashboard_inactive') {
- continue;
- }
-
-
- $page['content']['dashboard'][$region] = !empty($page[$region]) ? $page[$region] : array();
- $page['content']['dashboard'][$region]['#dashboard_region'] = $region;
-
-
- $page['content']['dashboard'][$region]['#theme_wrappers'][] = array($region, 'dashboard_region');
- unset($page[$region]);
- $blocks_found = array();
- foreach ($page['content']['dashboard'][$region] as $item) {
- if (isset($item['#theme_wrappers']) && is_array($item['#theme_wrappers']) && in_array('block', $item['#theme_wrappers'])) {
-
- if (empty($item['#block']->subject)) {
-
-
- if (!isset($block_info[$item['#block']->module])) {
- $block_info[$item['#block']->module] = module_invoke($item['#block']->module, 'block_info');
- }
- $item['#block']->subject = $block_info[$item['#block']->module][$item['#block']->delta]['info'];
- }
- $blocks_found[$item['#block']->module . '_' . $item['#block']->delta] = TRUE;
- }
- }
-
-
- $block_list = db_select('block')
- ->condition('theme', $theme_key)
- ->condition('status', 1)
- ->condition('region', $region)
- ->fields('block')
- ->execute();
- foreach ($block_list as $block) {
- if (!isset($blocks_found[$block->module . '_' . $block->delta])) {
- $block->enabled = $block->page_match = TRUE;
- $block->content = array('#markup' => '<div class="dashboard-block-empty">(empty)</div>');
- if (!isset($block_info[$block->module])) {
- $block_info[$block->module] = module_invoke($block->module, 'block_info');
- }
- $block->subject = t('@title', array('@title' => $block_info[$block->module][$block->delta]['info']));
- $block_render = array($block->module . '_' . $block->delta => $block);
- $build = _block_get_renderable_array($block_render);
- $page['content']['dashboard'][$block->region][] = $build;
- }
- }
- }
- }
- }
- function dashboard_system_info_alter(&$info, $file, $type) {
- if ($type == 'theme') {
-
-
- $dashboard_regions = dashboard_region_descriptions();
- if (isset($dashboard_regions['dashboard_inactive'])) {
- $inactive_region = $dashboard_regions['dashboard_inactive'];
- unset($dashboard_regions['dashboard_inactive']);
- $dashboard_regions['dashboard_inactive'] = $inactive_region;
- }
- $info['regions'] += $dashboard_regions;
-
-
-
- $info['overlay_regions'] = !empty($info['overlay_regions']) ? array_merge($info['overlay_regions'], dashboard_regions()) : dashboard_regions();
- }
- }
- function dashboard_theme() {
- return array(
- 'dashboard' => array(
- 'render element' => 'element',
- ),
- 'dashboard_admin' => array(
- 'render element' => 'element',
- ),
- 'dashboard_region' => array(
- 'render element' => 'element',
- ),
- 'dashboard_disabled_blocks' => array(
- 'variables' => array('blocks' => NULL),
- ),
- 'dashboard_disabled_block' => array(
- 'variables' => array('block' => NULL),
- ),
- 'dashboard_admin_display_form' => array(
-
-
- 'template' => 'block-admin-display-form',
- 'path' => drupal_get_path('module', 'block'),
- 'file' => 'block.admin.inc',
- 'render element' => 'form',
- ),
- );
- }
- function dashboard_forms() {
-
-
- $forms['dashboard_admin_display_form'] = array(
- 'callback' => 'block_admin_display_form',
- );
- return $forms;
- }
- function dashboard_admin($launch_customize = FALSE) {
- $js_settings = array(
- 'dashboard' => array(
- 'drawer' => url('admin/dashboard/drawer'),
- 'blockContent' => url('admin/dashboard/block-content'),
- 'updatePath' => url('admin/dashboard/update'),
- 'formToken' => drupal_get_token('dashboard-update'),
- 'launchCustomize' => $launch_customize,
- 'dashboard' => url('admin/dashboard'),
- 'emptyBlockText' => t('(empty)'),
- 'emptyRegionTextInactive' => t('This dashboard region is empty. Click <em>Customize dashboard</em> to add blocks to it.'),
- 'emptyRegionTextActive' => t('DRAG HERE'),
- ),
- );
- $build = array(
- '#theme' => 'dashboard_admin',
- '#message' => t('To customize the dashboard page, move blocks to the dashboard regions on the <a href="@dashboard">Dashboard administration page</a>, or enable JavaScript on this page to use the drag-and-drop interface.', array('@dashboard' => url('admin/dashboard/configure'))),
- '#access' => user_access('administer blocks'),
- '#attached' => array(
- 'js' => array(
- drupal_get_path('module', 'dashboard') . '/dashboard.js',
- array('data' => $js_settings, 'type' => 'setting'),
- ),
- 'library' => array(array('system', 'ui.sortable')),
- ),
- );
- return $build;
- }
- function dashboard_admin_blocks() {
- global $theme_key;
- drupal_theme_initialize();
- module_load_include('inc', 'block', 'block.admin');
-
-
-
-
- $blocks = block_admin_display_prepare_blocks($theme_key);
- $dashboard_regions = dashboard_region_descriptions();
- $regions_to_remove = array_diff_key(system_region_list($theme_key, REGIONS_VISIBLE), $dashboard_regions);
- foreach ($blocks as $id => $block) {
- if (isset($regions_to_remove[$block['region']])) {
- unset($blocks[$id]);
- }
- }
-
-
- return drupal_get_form('dashboard_admin_display_form', $blocks, $theme_key, $dashboard_regions);
- }
- function dashboard_form_block_admin_display_form_alter(&$form, &$form_state, $form_id) {
-
-
-
-
-
- if ($form_id != 'dashboard_admin_display_form') {
- $dashboard_regions = dashboard_region_descriptions();
- $form['block_regions']['#value'] = array_diff_key($form['block_regions']['#value'], $dashboard_regions);
- foreach (element_children($form['blocks']) as $i) {
- $block = &$form['blocks'][$i];
- if (isset($block['region']['#default_value']) && isset($dashboard_regions[$block['region']['#default_value']]) && $block['region']['#default_value'] != 'dashboard_inactive') {
- $block['#access'] = FALSE;
- }
- elseif (isset($block['region']['#options'])) {
- $block['region']['#options'] = array_diff_key($block['region']['#options'], $dashboard_regions);
- }
-
-
-
-
-
-
-
- if ($block['region']['#default_value'] == 'dashboard_inactive') {
-
- $block['region']['#default_value'] = NULL;
- }
- }
- }
- }
- function dashboard_form_dashboard_admin_display_form_alter(&$form, &$form_state) {
-
-
- foreach ($form['blocks'] as &$block) {
- if (isset($block['configure']['#href'])) {
- $block['configure']['#options']['query']['destination'] = 'admin/dashboard/configure';
- }
- if (isset($block['delete']['#href'])) {
- $block['delete']['#options']['query']['destination'] = 'admin/dashboard/configure';
- }
- }
- }
- function dashboard_form_block_admin_configure_alter(&$form, &$form_state) {
- global $theme_key;
- drupal_theme_initialize();
-
-
-
-
-
- $dashboard_regions = dashboard_region_descriptions();
- foreach (element_children($form['regions']) as $region_name) {
- $region = &$form['regions'][$region_name];
- if ($region_name != $theme_key && isset($region['#options'])) {
- $region['#options'] = array_diff_key($region['#options'], $dashboard_regions);
- }
- }
- }
- function dashboard_form_block_add_block_form_alter(&$form, &$form_state) {
- dashboard_form_block_admin_configure_alter($form, $form_state);
- }
- function template_preprocess_dashboard_admin_display_form(&$variables) {
- template_preprocess_block_admin_display_form($variables);
- if (isset($variables['block_regions'][BLOCK_REGION_NONE])) {
- $variables['block_regions'][BLOCK_REGION_NONE] = t('Other blocks');
- }
- }
- function dashboard_is_visible() {
- static $is_visible;
- if (!isset($is_visible)) {
-
-
-
- $menu_item = menu_get_item();
- $is_visible = isset($menu_item['page_callback']) && $menu_item['page_callback'] == 'dashboard_admin' && !empty($menu_item['access']);
- }
- return $is_visible;
- }
- function dashboard_region_descriptions() {
- $regions = module_invoke_all('dashboard_regions');
- drupal_alter('dashboard_regions', $regions);
- return $regions;
- }
- function dashboard_regions() {
- $regions = &drupal_static(__FUNCTION__);
- if (!isset($regions)) {
- $regions = array_keys(dashboard_region_descriptions());
- }
- return $regions;
- }
- function dashboard_dashboard_regions() {
- return array(
- 'dashboard_main' => 'Dashboard (main)',
- 'dashboard_sidebar' => 'Dashboard (sidebar)',
- 'dashboard_inactive' => 'Dashboard (inactive)',
- );
- }
- function dashboard_show_disabled() {
- global $theme_key;
-
- $blocks = _block_rehash();
-
- foreach ($blocks as $key => $block) {
- if ($block['theme'] != $theme_key || $block['region'] != 'dashboard_inactive') {
- unset($blocks[$key]);
- }
- }
-
- print theme('dashboard_disabled_blocks', array('blocks' => $blocks));
- drupal_exit();
- }
- function dashboard_show_block_content($module, $delta) {
- drupal_theme_initialize();
- global $theme_key;
- $blocks = array();
- $block_object = db_query("SELECT * FROM {block} WHERE theme = :theme AND module = :module AND delta = :delta", array(
- ":theme" => $theme_key,
- ":module" => $module,
- ":delta" => $delta,
- ))
- ->fetchObject();
- $block_object->enabled = $block_object->page_match = TRUE;
- $blocks[$module . "_" . $delta] = $block_object;
- $block_content = _block_render_blocks($blocks);
- $build = _block_get_renderable_array($block_content);
- $rendered_block = drupal_render($build);
- print $rendered_block;
- drupal_exit();
- }
- function dashboard_update() {
- drupal_theme_initialize();
- global $theme_key;
-
- if (!empty($_REQUEST['form_token']) && drupal_valid_token($_REQUEST['form_token'], 'dashboard-update')) {
- parse_str($_REQUEST['regions'], $regions);
- foreach ($regions as $region_name => $blocks) {
- if ($region_name == 'disabled_blocks') {
- $region_name = 'dashboard_inactive';
- }
- foreach ($blocks as $weight => $block_string) {
-
- preg_match('/block-([^-]+)-(.+)/', $block_string, $matches);
- $block = new stdClass();
- $block->module = $matches[1];
- $block->delta = $matches[2];
- $block->region = $region_name;
- $block->weight = $weight;
- $block->status = 1;
- db_merge('block')
- ->key(array(
- 'module' => $block->module,
- 'delta' => $block->delta,
- 'theme' => $theme_key,
- ))
- ->fields(array(
- 'status' => $block->status,
- 'weight' => $block->weight,
- 'region' => $block->region,
- 'pages' => '',
- ))
- ->execute();
- }
- }
- drupal_set_message(t('The configuration options have been saved.'), 'status', FALSE);
- }
- drupal_exit();
- }
- function theme_dashboard($variables) {
- extract($variables);
- drupal_add_css(drupal_get_path('module', 'dashboard') . '/dashboard.css');
- return '<div id="dashboard" class="clearfix">' . $element['#children'] . '</div>';
- }
- function theme_dashboard_admin($variables) {
-
-
- return '<div class="customize-dashboard js-hide">' . $variables['element']['#message'] . '</div>';
- }
- function theme_dashboard_region($variables) {
- extract($variables);
- $output = '<div id="' . $element['#dashboard_region'] . '" class="dashboard-region">';
- $output .= '<div class="region clearfix">';
- $output .= $element['#children'];
-
- $output .= '</div>';
-
- $output .= '</div>';
- return $output;
- }
- function theme_dashboard_disabled_blocks($variables) {
- extract($variables);
- $output = '<div class="canvas-content"><p>' . t('Drag and drop these blocks to the columns below. Changes are automatically saved. More options are available on the <a href="@dashboard-url">configuration page</a>.', array('@dashboard-url' => url('admin/dashboard/configure'))) . '</p>';
- $output .= '<div id="disabled-blocks"><div class="region disabled-blocks clearfix">';
- foreach ($blocks as $block) {
- $output .= theme('dashboard_disabled_block', array('block' => $block));
- }
- $output .= '<div class="clearfix"></div>';
- $output .= '<p class="dashboard-add-other-blocks">' . l(t('Add other blocks'), 'admin/dashboard/configure') . '</p>';
- $output .= '</div></div></div>';
- return $output;
- }
- function theme_dashboard_disabled_block($variables) {
- extract($variables);
- $output = "";
- if (isset($block)) {
- $output .= '<div id="block-' . $block['module'] . '-' . $block['delta']
- . '" class="disabled-block block block-' . $block['module'] . '-' . $block['delta']
- . ' module-' . $block['module'] . ' delta-' . $block['delta'] . '">'
- . '<h2>' . (!empty($block['title']) && $block['title'] != '<none>' ? check_plain($block['title']) : check_plain($block['info'])) . '</h2>'
- . '<div class="content"></div>'
- . '</div>';
- }
- return $output;
- }
|