' . t('About') . ''; $output .= '

' . t('The Block module allows you to create boxes of content, which are rendered into an area, or region, of one or more pages of a website. The core Seven administration theme, for example, implements the regions "Content", "Help", "Dashboard main", and "Dashboard sidebar", and a mongodb_block_ui may appear in any one of these regions. The Blocks administration page provides a drag-and-drop interface for assigning a mongodb_block_ui to a region, and for controlling the order of mongodb_block_uis within regions. For more information, see the online handbook entry for Block module.', array('@block' => 'http://drupal.org/handbook/modules/mongodb_block/', '@blocks' => url('admin/structure/mongodb_block'))) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Positioning content') . '
'; $output .= '
' . t('When working with mongodb_block_uis, remember that all themes do not implement the same regions, or display regions in the same way. Blocks are positioned on a per-theme basis. Users with the Administer mongodb blocks permission can disable mongodb_block_uis. Disabled mongodb_block_uis are listed on the Blocks administration page, but are not displayed in any region.', array('@mongodb_block_ui' => 'http://drupal.org/handbook/modules/mongodb_block_ui/', '@mongodb_block_uis' => url('admin/structure/mongodb_block_ui'))) . '
'; $output .= '
' . t('Controlling visibility') . '
'; $output .= '
' . t('Blocks can be configured to be visible only on certain pages, only to users of certain roles, or only on pages displaying certain content types. Administrators can also allow specific mongodb_block_uis to be enabled or disabled by users when they edit their My account page. Some dynamic mongodb_block_uis, such as those generated by modules, will be displayed only on certain pages.', array('@content-type' => url('admin/structure/types'), '@user' => url('user'))) . '
'; $output .= '
' . t('Creating custom mongodb_block_uis') . '
'; $output .= '
' . t('Users with the Administer mongodb blocks permission can add custom mongodb_block_uis, which are then listed on the Blocks administration page. Once created, custom mongodb_block_uis behave just like default and module-generated mongodb_block_uis.', array('@mongodb_block_uis' => url('admin/structure/mongodb_block_ui'), '@mongodb_block_ui-add' => url('admin/structure/mongodb_block_ui/add'))) . '
'; $output .= '
'; return $output; case 'admin/structure/mongodb_block/add': return '

' . t('Use this page to create a new custom mongodb_block_ui.') . '

'; } // if ($arg[0] == 'admin' && $arg[1] == 'structure' && $arg['2'] == 'mongodb_block_ui' && (empty($arg[3]) || $arg[3] == 'list')) { // $demo_theme = !empty($arg[4]) ? $arg[4] : variable_get('theme_default', 'garland'); // $themes = list_themes(); // $output = '

' . t('This page provides a drag-and-drop interface for assigning a mongodb_block_ui to a region, and for controlling the order of mongodb_block_uis within regions. Since not all themes implement the same regions, or display regions in the same way, mongodb_block_uis are positioned on a per-theme basis. Remember that your changes will not be saved until you click the Save mongodb_block_uis button at the bottom of the page. Click the configure link next to each mongodb_block_ui to configure its specific title and visibility settings.') . '

'; // $output .= '

' . l(t('Demonstrate mongodb_block_ui regions (@theme)', array('@theme' => $themes[$demo_theme]->info['name'])), 'admin/structure/mongodb_block_ui/demo/' . $demo_theme) . '

'; // return $output; // } } /** * Implements hook_theme(). */ function mongodb_block_ui_theme() { return array( 'mongodb_block_ui_admin_display_form' => array( 'template' => 'mongodb-block-ui-admin-display-form', 'file' => 'mongodb_block_ui.admin.inc', 'render element' => 'form', ), ); } /** * Implements hook_permission(). */ function mongodb_block_ui_permission() { return array( 'administer mongodb_blocks' => array( 'title' => t('Administer mongodb blocks'), ), ); } /** * Implements hook_menu(). */ function mongodb_block_ui_menu() { $default_theme = variable_get('theme_default', 'garland'); $items['admin/structure/mongodb_block'] = array( 'title' => 'Blocks', 'description' => 'Configure what blocks content appears in your site\'s sidebars and other regions.', 'page callback' => 'mongodb_block_ui_admin_display', 'page arguments' => array($default_theme), 'access arguments' => array('administer mongodb blocks'), 'file' => 'mongodb_block_ui.admin.inc', ); $items['admin/structure/mongodb_block/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items['admin/structure/mongodb_block/manage/%/%'] = array( 'title' => 'Configure mongodb_block', 'page callback' => 'drupal_get_form', 'page arguments' => array('mongodb_block_ui_admin_configure', 4, 5), 'access arguments' => array('administer mongodb blocks'), 'file' => 'mongodb_block_ui.admin.inc', ); $items['admin/structure/mongodb_block/manage/%/%/configure'] = array( 'title' => 'Configure mongodb_blocks', 'type' => MENU_DEFAULT_LOCAL_TASK, 'context' => MENU_CONTEXT_INLINE, ); $items['admin/structure/mongodb_block/manage/%/%/delete'] = array( 'title' => 'Delete block', 'page callback' => 'drupal_get_form', 'page arguments' => array('mongodb_block_ui_custom_block_delete', 4, 5), 'access arguments' => array('administer mongodb blocks'), 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_NONE, 'file' => 'mongodb_block_ui.admin.inc', ); $items['admin/structure/mongodb_block/add'] = array( 'title' => 'Add block', 'page callback' => 'drupal_get_form', 'page arguments' => array('mongodb_block_ui_add_block_form'), 'access arguments' => array('administer mongodb blocks'), 'type' => MENU_LOCAL_ACTION, 'file' => 'mongodb_block_ui.admin.inc', ); foreach (list_themes() as $key => $theme) { $items['admin/structure/mongodb_block/list/' . $key] = array( 'title' => check_plain($theme->info['name']), 'page arguments' => array($key), 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, 'weight' => $key == $default_theme ? -10 : 0, 'access callback' => '_mongodb_block_ui_themes_access', 'access arguments' => array($theme), 'file' => 'mongodb_block_ui.admin.inc', ); if ($key != $default_theme) { $items['admin/structure/mongodb_block/list/' . $key . '/add'] = array( 'title' => 'Add block', 'page callback' => 'drupal_get_form', 'page arguments' => array('mongodb_block_ui_add_block_form'), 'access arguments' => array('administer mongodb blocks'), 'type' => MENU_LOCAL_ACTION, 'file' => 'mongodb_block_ui.admin.inc', ); } $items['admin/structure/mongodb_block/demo/' . $key] = array( 'title' => check_plain($theme->info['name']), 'page callback' => 'mongodb_block_ui_admin_demo', 'page arguments' => array($key), 'type' => MENU_CALLBACK, 'access callback' => '_mongodb_block_ui_themes_access', 'access arguments' => array($theme), 'theme callback' => '_mongodb_block_ui_custom_theme', 'theme arguments' => array($key), 'file' => 'mongodb_block_ui.admin.inc', ); } return $items; } /** * Menu item access callback - only admin or enabled themes can be accessed. */ function _mongodb_block_ui_themes_access($theme) { return user_access('administer mongodb blocks') && drupal_theme_access($theme); } /** * Theme callback for the block configuration pages. * * @param $theme * The theme whose block are being configured. If not set, the default theme * is assumed. * @return * The theme that should be used for the block configuration page, or NULL * to indicate that the default theme should be used. */ // function _mongodb_block_ui_custom_theme($theme = NULL) { // // We return exactly what was passed in, to guarantee that the page will // // always be displayed using the theme whose blocks are being configured. // return $theme; // } /** * Implements hook_block_configure(). */ function mongodb_block_ui_block_configure($delta = 0) { $custom_block = array('format' => filter_default_format()); if ($delta) { $custom_block = mongodb_block_load('mongodb_block_ui', $delta); } $form = mongodb_block_ui_custom_block_form($custom_block); return $form; } /** * Implements hook_block_view(). * * Generates the administrator-defined block for display. */ function mongodb_block_ui_block_view($delta = 0, $edit = array()) { $block = mongodb_block_load('mongodb_block_ui', $delta); $data['subject'] = check_plain($block['title']); $data['content'] = check_markup($block['body'], $block['format'], '', TRUE); return $data; } /** * Define the custom block form. */ function mongodb_block_ui_custom_block_form($edit = array()) { $edit += array( 'info' => '', 'body' => '', ); $form['info'] = array( '#type' => 'textfield', '#title' => t('Block description'), '#default_value' => $edit['info'], '#maxlength' => 64, '#description' => t('A brief description of your block. Used on the Blocks administration page.', array('@overview' => url('admin/structure/mongodb_block'))), '#required' => TRUE, '#weight' => -19, ); $form['body_field']['#weight'] = -17; $form['body_field']['body'] = array( '#type' => 'text_format', '#title' => t('Block body'), '#default_value' => $edit['body'], '#format' => isset($edit['format']) ? $edit['format'] : NULL, '#rows' => 15, '#description' => t('The content of the block as shown to the user.'), '#required' => TRUE, '#weight' => -17, '#access' => filter_access(filter_format_load($edit['format'])), ); return $form; } /** * Implements hook_form_FORM_ID_alter(). */ // function mongodb_block_ui_form_user_profile_form_alter(&$form, &$form_state) { // if ($form['#user_category'] == 'account') { // $account = $form['#user']; // $rids = array_keys($account->roles); // $result = db_query("SELECT DISTINCT b.* FROM {mongodb_block_ui} b LEFT JOIN {mongodb_block_ui_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids)); // // $mongodb_block_uis = array(); // foreach ($result as $mongodb_block_ui) { // $data = module_invoke($mongodb_block_ui->module, 'mongodb_block_ui_info'); // if ($data[$mongodb_block_ui->delta]['info']) { // $mongodb_block_uis[$mongodb_block_ui->module][$mongodb_block_ui->delta] = array( // '#type' => 'checkbox', // '#title' => check_plain($data[$mongodb_block_ui->delta]['info']), // '#default_value' => isset($account->mongodb_block_ui[$mongodb_block_ui->module][$mongodb_block_ui->delta]) ? $account->mongodb_block_ui[$mongodb_block_ui->module][$mongodb_block_ui->delta] : ($mongodb_block_ui->custom == 1), // ); // } // } // // Only display the fieldset if there are any personalizable mongodb_block_uis. // if ($mongodb_block_uis) { // $form['mongodb_block_ui'] = array( // '#type' => 'fieldset', // '#title' => t('Personalize mongodb_block_uis'), // '#description' => t('Blocks consist of content or information that complements the main content of the page. Enable or disable optional mongodb_block_uis using the checkboxes below.'), // '#weight' => 3, // '#collapsible' => TRUE, // '#tree' => TRUE, // ); // $form['mongodb_block_ui'] += $mongodb_block_uis; // } // } // } /** * Initialize blocks for enabled themes. */ // function mongodb_block_ui_themes_enabled($theme_list) { // foreach ($theme_list as $theme) { // mongodb_block_ui_theme_initialize($theme); // } // } /** * Assign an initial, default set of blocks for a theme. * * This function is called the first time a new theme is enabled. The new theme * gets a copy of the default theme's mongodb_block_uis, with the difference that if a * particular region isn't available in the new theme, the mongodb_block_ui is assigned * to the new theme's default region. * * @param $theme * The name of a theme. */ // function mongodb_block_ui_theme_initialize($theme) { // // Initialize theme's mongodb_block_uis if none already registered. // $has_mongodb_block_uis = (bool) db_query_range('SELECT 1 FROM {mongodb_block_ui} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchField(); // if (!$has_mongodb_block_uis) { // $default_theme = variable_get('theme_default', 'garland'); // $regions = system_region_list($theme); // $result = db_query("SELECT * FROM {mongodb_block_ui} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC)); // foreach ($result as $mongodb_block_ui) { // // If the region isn't supported by the theme, assign the mongodb_block_ui to the theme's default region. // if (!array_key_exists($mongodb_block_ui['region'], $regions)) { // $mongodb_block_ui['region'] = system_default_region($theme); // } // $mongodb_block_ui['theme'] = $theme; // unset($mongodb_block_ui['bid']); // drupal_write_record('mongodb_block_ui', $mongodb_block_ui); // } // } // } /** * Return all blocks in the specified region for the current user. * * @param $region * The name of a region. * * @return * An array of mongodb_block_ui objects, indexed with module_delta. * If you are displaying your mongodb_block_uis in one or two sidebars, you may check * whether this array is empty to see how many columns are going to be * displayed. * * @todo * Now that the mongodb_block_uis table has a primary key, we should use that as the * array key instead of module_delta. */ // function mongodb_block_ui_list($region) { // $mongodb_block_uis = &drupal_static(__FUNCTION__); // // if (!isset($mongodb_block_uis)) { // $mongodb_block_uis = _mongodb_block_ui_load_mongodb_block_uis(); // } // // // Create an empty array if there are no entries. // if (!isset($mongodb_block_uis[$region])) { // $mongodb_block_uis[$region] = array(); // } // else { // $mongodb_block_uis[$region] = _mongodb_block_ui_render_mongodb_block_uis($mongodb_block_uis[$region]); // } // // return $mongodb_block_uis[$region]; // } /** * Implements hook_block_info_alter(). * * Check the page, user role and user specific visibilty settings. * Remove the mongodb_block_ui if the visibility conditions are not met. */ // function mongodb_block_ui_block_info_alter(&$blocks) { // global $user, $theme_key; // // // Build an array of roles for each mongodb_block_ui. // $mongodb_block_ui_roles = array(); // $result = db_query('SELECT module, delta, rid FROM {mongodb_block_ui_role}'); // foreach ($result as $record) { // $mongodb_block_ui_roles[$record->module][$record->delta][] = $record->rid; // } // // foreach ($mongodb_block_uis as $key => $mongodb_block_ui) { // if (!isset($mongodb_block_ui->theme) || !isset($mongodb_block_ui->status) || $mongodb_block_ui->theme != $theme_key || $mongodb_block_ui->status != 1) { // // This mongodb_block_ui was added by a contrib module, leave it in the list. // continue; // } // // // If a mongodb_block_ui has no roles associated, it is displayed for every role. // // For mongodb_block_uis with roles associated, if none of the user's roles matches // // the settings from this mongodb_block_ui, remove it from the mongodb_block_ui list. // if (isset($mongodb_block_ui_roles[$mongodb_block_ui->module][$mongodb_block_ui->delta]) && !array_intersect($mongodb_block_ui_roles[$mongodb_block_ui->module][$mongodb_block_ui->delta], array_keys($user->roles))) { // // No match. // unset($mongodb_block_uis[$key]); // continue; // } // // // Use the user's mongodb_block_ui visibility setting, if necessary. // if ($mongodb_block_ui->custom != 0) { // if ($user->uid && isset($user->mongodb_block_ui[$mongodb_block_ui->module][$mongodb_block_ui->delta])) { // $enabled = $user->mongodb_block_ui[$mongodb_block_ui->module][$mongodb_block_ui->delta]; // } // else { // $enabled = ($mongodb_block_ui->custom == 1); // } // } // else { // $enabled = TRUE; // } // if (!$enabled) { // unset($mongodb_block_uis[$key]); // continue; // } // // // Match path if necessary. // if ($mongodb_block_ui->pages) { // if ($mongodb_block_ui->visibility < 2) { // $path = drupal_get_path_alias($_GET['q']); // // Compare with the internal and path alias (if any). // $page_match = drupal_match_path($path, $mongodb_block_ui->pages); // if ($path != $_GET['q']) { // $page_match = $page_match || drupal_match_path($_GET['q'], $mongodb_block_ui->pages); // } // // When $mongodb_block_ui->visibility has a value of 0, the mongodb_block_ui is displayed on // // all pages except those listed in $mongodb_block_ui->pages. When set to 1, it // // is displayed only on those pages listed in $mongodb_block_ui->pages. // $page_match = !($mongodb_block_ui->visibility xor $page_match); // } // elseif (module_exists('php')) { // $page_match = php_eval($mongodb_block_ui->pages); // } // else { // $page_match = FALSE; // } // } // else { // $page_match = TRUE; // } // if (!$page_match) { // unset($mongodb_block_uis[$key]); // } // } // } /** * Implements hook_user_role_delete(). * * Remove deleted role from blocks that use it. */ // function mongodb_block_ui_user_role_delete($role) { // db_delete('mongodb_block_ui_role') // ->condition('rid', $role->rid) // ->execute(); // } /** * Implements hook_filter_format_delete(). */ function mongodb_block_ui_filter_format_delete($format, $fallback) { $collection = mongodb_collection('block_custom'); $collection->update(array('format' => $fomat->format), array('format' => $fallback->format)); } /** * Implements hook_menu_delete(). */ function mongodb_block_ui_menu_delete($menu) { $collection = mongodb_collection('block_custom'); $collection->delete(array( 'module' => 'menu', 'delta' => $menu['menu_name'], )); // db_delete('mongodb_block_ui_role') // ->condition('module', 'menu') // ->condition('delta', $menu['menu_name']) // ->execute(); } /** * Implements hook_form_FORM_ID_alter(). */ function mongodb_block_ui_form_system_performance_settings_alter(&$form, &$form_state) { $disabled = count(module_implements('node_grants')); $form['caching']['block_cache'] = array( '#type' => 'checkbox', '#title' => t('Cache blocks'), '#default_value' => variable_get('block_cache', FALSE), '#disabled' => $disabled, '#description' => $disabled ? t('Block caching is inactive because you have enabled modules defining content access restrictions.') : NULL, '#weight' => -1, ); } /** * Implements hook_modules_uninstalled(). * * Cleanup {block} and {block_rules} tables from modules' blocks. */ // function mongodb_block_ui_modules_uninstalled($modules) { // $collection = mongodb_collection('block_custom'); // // db_delete('mongodb_block_ui') // ->condition('module', $modules, 'IN') // ->execute(); // db_delete('mongodb_block_ui_role') // ->condition('module', $modules, 'IN') // ->execute(); // } function mongodb_block_ui_mongodb_block_info_alter(&$blocks) { $collection = mongodb_collection('block'); foreach ($collection->find() as $block) { // Copy module and delta out of the _id. $block += $block['_id']; $index = $block['_id']['module'] . '_' . $block['_id']['delta']; // Add custom blocks. if ($block['_id']['module'] == 'mongodb_block_ui') { if (!isset($block['info'])) { $block['info'] = $blocks[$index]['info']; } $block['status'] = 1; $blocks[$index] = $block; } } }