12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010 |
- <?php
- function overlay_help($path, $arg) {
- switch ($path) {
- case 'admin/help#overlay':
- $output = '';
- $output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('The Overlay module makes the administration pages on your site display in a JavaScript overlay of the page you were viewing when you clicked the administrative link, instead of replacing the page in your browser window. Use the close link on the overlay to return to the page you were viewing when you clicked the link. For more information, see the online handbook entry for <a href="@overlay">Overlay module</a>.', array('@overlay' => 'http://drupal.org/documentation/modules/overlay')) . '</p>';
- return $output;
- }
- }
- function overlay_menu() {
- $items['overlay-ajax/%'] = array(
- 'title' => '',
- 'page callback' => 'overlay_ajax_render_region',
- 'page arguments' => array(1),
- 'access arguments' => array('access overlay'),
- 'type' => MENU_CALLBACK,
- );
- $items['overlay/dismiss-message'] = array(
- 'title' => '',
- 'page callback' => 'overlay_user_dismiss_message',
- 'access arguments' => array('access overlay'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }
- function overlay_admin_paths() {
- $paths = array(
-
-
-
- 'overlay/dismiss-message' => TRUE,
- );
- return $paths;
- }
- function overlay_permission() {
- return array(
- 'access overlay' => array(
- 'title' => t('Access the administrative overlay'),
- 'description' => t('View administrative pages in the overlay.'),
- ),
- );
- }
- function overlay_theme() {
- return array(
- 'overlay' => array(
- 'render element' => 'page',
- 'template' => 'overlay',
- ),
- 'overlay_disable_message' => array(
- 'render element' => 'element',
- ),
- );
- }
- function overlay_form_user_profile_form_alter(&$form, &$form_state) {
- if ($form['#user_category'] == 'account') {
- $account = $form['#user'];
- if (user_access('access overlay', $account)) {
- $form['overlay_control'] = array(
- '#type' => 'fieldset',
- '#title' => t('Administrative overlay'),
- '#weight' => 4,
- '#collapsible' => TRUE,
- );
- $form['overlay_control']['overlay'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use the overlay for administrative pages.'),
- '#description' => t('Show administrative pages on top of the page you started from.'),
- '#default_value' => isset($account->data['overlay']) ? $account->data['overlay'] : 1,
- );
- }
- }
- }
- function overlay_user_presave(&$edit, $account, $category) {
- if (isset($edit['overlay'])) {
- $edit['data']['overlay'] = $edit['overlay'];
- }
- }
- function overlay_init() {
- global $user;
- $mode = overlay_get_mode();
-
-
- $use_overlay = !isset($user->data['overlay']) || $user->data['overlay'];
- if (empty($mode) && user_access('access overlay') && $use_overlay) {
- $current_path = current_path();
-
-
- if (isset($_SESSION['overlay_enable_redirect']) && $_SESSION['overlay_enable_redirect']) {
- unset($_SESSION['overlay_enable_redirect']);
- drupal_goto('<front>', array('fragment' => 'overlay=' . $current_path));
- }
- if (isset($_GET['render']) && $_GET['render'] == 'overlay') {
-
-
- if (isset($_SESSION['overlay_close_dialog'])) {
- call_user_func_array('overlay_close_dialog', $_SESSION['overlay_close_dialog']);
- unset($_SESSION['overlay_close_dialog']);
- }
-
-
- elseif (!path_is_admin($current_path)) {
-
- if (url_is_external($current_path)) {
- $current_path = '<front>';
- }
- overlay_close_dialog($current_path, array('query' => drupal_get_query_parameters(NULL, array('q', 'render'))));
- }
-
- overlay_set_mode('child');
-
- unset($_GET['render']);
- }
-
- elseif (!path_is_admin($current_path)) {
-
- overlay_set_mode('parent');
- }
- }
- }
- function overlay_exit() {
-
-
-
- if (overlay_get_mode() == 'child') {
-
-
-
-
- $original_markup = overlay_get_rendered_content();
- if (!empty($original_markup)) {
-
-
-
-
- foreach (overlay_supplemental_regions() as $region) {
- if (!isset($original_markup[$region]) || $original_markup[$region] != overlay_render_region($region)) {
- overlay_request_refresh($region);
- }
- }
- }
- }
- }
- function overlay_library() {
- $module_path = drupal_get_path('module', 'overlay');
-
- $libraries['parent'] = array(
- 'title' => 'Overlay: Parent',
- 'website' => 'http://drupal.org/documentation/modules/overlay',
- 'version' => '1.0',
- 'js' => array(
- $module_path . '/overlay-parent.js' => array(),
- ),
- 'css' => array(
- $module_path . '/overlay-parent.css' => array(),
- ),
- 'dependencies' => array(
- array('system', 'ui'),
- array('system', 'jquery.bbq'),
- ),
- );
-
- $libraries['child'] = array(
- 'title' => 'Overlay: Child',
- 'website' => 'http://drupal.org/documentation/modules/overlay',
- 'version' => '1.0',
- 'js' => array(
- $module_path . '/overlay-child.js' => array(),
- ),
- 'css' => array(
- $module_path . '/overlay-child.css' => array(),
- ),
- );
- return $libraries;
- }
- function overlay_drupal_goto_alter(&$path, &$options, &$http_response_code) {
- if (overlay_get_mode() == 'child') {
-
-
-
-
-
-
- if ($path == system_authorized_get_url() || $path == system_authorized_batch_processing_url()) {
- $_SESSION['overlay_close_dialog'] = array($path, $options);
- $path = current_path();
- $options = drupal_get_query_parameters();
- }
-
-
- if (isset($options['query'])) {
- $options['query'] += array('render' => 'overlay');
- }
- else {
- $options['query'] = array('render' => 'overlay');
- }
- }
- }
- function overlay_batch_alter(&$batch) {
- if (overlay_get_mode() == 'child') {
- if (isset($batch['url_options']['query'])) {
- $batch['url_options']['query']['render'] = 'overlay';
- }
- else {
- $batch['url_options']['query'] = array('render' => 'overlay');
- }
- }
- }
- function overlay_page_alter(&$page) {
-
-
- if ($regions_to_render = overlay_get_regions_to_render()) {
- $skipped_regions = array_diff(element_children($page), $regions_to_render);
- foreach ($skipped_regions as $skipped_region) {
- $page[$skipped_region]['#access'] = FALSE;
- }
- }
- $mode = overlay_get_mode();
- if ($mode == 'child') {
-
- array_unshift($page['#theme_wrappers'], 'overlay');
- }
- elseif ($mode == 'parent' && ($message = overlay_disable_message())) {
- $page['page_top']['disable_overlay'] = $message;
- }
- }
- function overlay_user_dismiss_message() {
- global $user;
-
-
-
-
- if (empty($user->uid) || !isset($_GET['token']) || !drupal_valid_token($_GET['token'], 'overlay')) {
- return MENU_ACCESS_DENIED;
- }
- else {
- user_save(user_load($user->uid), array('data' => array('overlay_message_dismissed' => 1)));
- drupal_set_message(t('The message has been dismissed. You can change your overlay settings at any time by visiting your profile page.'));
-
- drupal_goto('user/' . $user->uid . '/edit');
- }
- }
- function overlay_disable_message() {
- global $user;
- if (!empty($user->uid) && empty($user->data['overlay_message_dismissed']) && (!isset($user->data['overlay']) || $user->data['overlay']) && user_access('access overlay')) {
- $build = array(
- '#theme' => 'overlay_disable_message',
- '#weight' => -99,
-
- 'profile_link' => array(
- '#type' => 'link',
- '#title' => t('If you have problems accessing administrative pages on this site, disable the overlay on your profile page.'),
- '#href' => 'user/' . $user->uid . '/edit',
- '#options' => array(
- 'query' => drupal_get_destination(),
- 'fragment' => 'edit-overlay-control',
- 'attributes' => array(
- 'id' => 'overlay-profile-link',
-
- 'class' => array('overlay-exclude'),
- ),
- ),
- ),
-
-
- 'dismiss_message_link' => array(
- '#type' => 'link',
- '#title' => t('Dismiss this message.'),
- '#href' => 'overlay/dismiss-message',
- '#options' => array(
- 'query' => drupal_get_destination() + array(
-
- 'token' => drupal_get_token('overlay'),
- ),
- 'attributes' => array(
- 'id' => 'overlay-dismiss-message',
-
-
- 'class' => (overlay_get_mode() == 'parent') ? array('overlay-exclude') : array(),
- ),
- ),
- )
- );
- }
- else {
- $build = array();
- }
- return $build;
- }
- function theme_overlay_disable_message($variables) {
- $element = $variables['element'];
-
-
-
-
- foreach (array('profile_link', 'dismiss_message_link') as $key) {
- $element[$key]['#options']['attributes']['class'][] = 'element-invisible';
- if (overlay_get_mode() == 'child') {
- $element[$key]['#options']['attributes']['class'][] = 'element-focusable';
- }
- }
-
- $output = drupal_render($element['profile_link']) . ' ' . drupal_render($element['dismiss_message_link']);
-
-
- $output = '<h3 class="element-invisible">' . t('Options for the administrative overlay') . '</h3>' . $output;
-
- $output = '<div id="overlay-disable-message" class="clearfix">' . $output . '</div>';
- return $output;
- }
- function overlay_block_list_alter(&$blocks) {
-
-
-
-
-
-
- if ($regions_to_render = overlay_get_regions_to_render()) {
- foreach ($blocks as $bid => $block) {
- if (!in_array($block->region, $regions_to_render)) {
- unset($blocks[$bid]);
- }
- }
- }
- }
- function overlay_system_info_alter(&$info, $file, $type) {
- if ($type == 'theme') {
- $info['overlay_regions'][] = 'content';
- $info['overlay_regions'][] = 'help';
- }
- }
- function overlay_preprocess_html(&$variables) {
- if (overlay_get_mode() == 'child') {
-
- $variables['classes_array'][] = 'overlay';
- }
- }
- function overlay_preprocess_maintenance_page(&$variables) {
- overlay_preprocess_html($variables);
- }
- function template_preprocess_overlay(&$variables) {
- $variables['tabs'] = menu_primary_local_tasks();
- $variables['title'] = drupal_get_title();
- $variables['disable_overlay'] = overlay_disable_message();
- $variables['content_attributes_array']['class'][] = 'clearfix';
- }
- function template_process_overlay(&$variables) {
- $variables['page'] = $variables['page']['#children'];
- }
- function overlay_preprocess_page(&$variables) {
- if (overlay_get_mode() == 'child') {
- unset($variables['tabs']['#primary']);
- }
- }
- function overlay_display_empty_page($value = NULL) {
- $display_empty_page = &drupal_static(__FUNCTION__, FALSE);
- if (isset($value)) {
- $display_empty_page = $value;
- }
- return $display_empty_page;
- }
- function overlay_page_delivery_callback_alter(&$callback) {
- if (overlay_display_empty_page()) {
- $callback = 'overlay_deliver_empty_page';
- }
- }
- function overlay_deliver_empty_page() {
- $empty_page = '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head><body class="overlay"></body></html>';
- print $empty_page;
- drupal_exit();
- }
- function overlay_get_mode() {
- return overlay_set_mode(NULL);
- }
- function overlay_set_mode($mode = NULL) {
- global $base_path;
- $overlay_mode = &drupal_static(__FUNCTION__);
-
-
- if (isset($overlay_mode) || !isset($mode)) {
- return $overlay_mode;
- }
- $overlay_mode = $mode;
- switch ($overlay_mode) {
- case 'parent':
- drupal_add_library('overlay', 'parent');
-
- module_invoke_all('overlay_parent_initialize');
- break;
- case 'child':
- drupal_add_library('overlay', 'child');
-
- module_invoke_all('overlay_child_initialize');
- break;
- }
- return $overlay_mode;
- }
- function overlay_overlay_parent_initialize() {
-
- $paths = path_get_admin_paths();
- foreach ($paths as &$type) {
- $type = str_replace('<front>', variable_get('site_frontpage', 'node'), $type);
- }
- drupal_add_js(array('overlay' => array('paths' => $paths)), 'setting');
- $path_prefixes = array();
- if (module_exists('locale') && variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) {
-
- $languages = language_list('enabled');
- $languages = $languages[1];
- $path_prefixes = array();
- foreach ($languages as $language) {
- if ($language->prefix) {
- $path_prefixes[] = $language->prefix;
- }
- }
- }
- drupal_add_js(array('overlay' => array('pathPrefixes' => $path_prefixes)), 'setting');
-
- drupal_add_js(array('overlay' => array('ajaxCallback' => 'overlay-ajax')), 'setting');
- }
- function overlay_overlay_child_initialize() {
-
-
- overlay_trigger_refresh();
-
-
-
-
-
-
-
- if (!empty($_POST) || isset($_GET['token'])) {
- foreach (overlay_supplemental_regions() as $region) {
- overlay_store_rendered_content($region, overlay_render_region($region));
- }
-
-
- overlay_request_page_refresh();
- }
-
-
-
- overlay_set_regions_to_render(overlay_regions());
- }
- function overlay_close_dialog($redirect = NULL, $redirect_options = array()) {
- $settings = array(
- 'overlayChild' => array(
- 'closeOverlay' => TRUE,
- ),
- );
-
- if (isset($redirect)) {
- $settings['overlayChild']['redirect'] = url($redirect, $redirect_options);
- }
- drupal_add_js($settings, array('type' => 'setting'));
-
-
- overlay_display_empty_page(TRUE);
- }
- function overlay_regions() {
- return _overlay_region_list('overlay_regions');
- }
- function overlay_supplemental_regions() {
- return _overlay_region_list('overlay_supplemental_regions');
- }
- function _overlay_region_list($type) {
-
-
- drupal_theme_initialize();
- $themes = list_themes();
- $theme = $themes[$GLOBALS['theme']];
-
-
- return !empty($theme->info[$type]) ? $theme->info[$type] : array();
- }
- function overlay_get_regions_to_render() {
- return overlay_set_regions_to_render();
- }
- function overlay_set_regions_to_render($regions = NULL) {
- $regions_to_render = &drupal_static(__FUNCTION__, array());
- if (isset($regions)) {
- $regions_to_render = $regions;
- }
- return $regions_to_render;
- }
- function overlay_render_region($region) {
-
-
- overlay_set_regions_to_render(array($region));
-
-
-
-
-
- $system_main_content_added = &drupal_static('system_main_content_added');
- $system_main_content_added = TRUE;
- $page = array(
- '#type' => 'page',
- '#theme' => NULL,
- '#theme_wrappers' => array(),
- );
-
-
-
-
- $original_js = drupal_add_js();
- $original_css = drupal_add_css();
- $original_libraries = drupal_static('drupal_add_library');
- $js = &drupal_static('drupal_add_js');
- $css = &drupal_static('drupal_add_css');
- $libraries = &drupal_static('drupal_add_library');
- $markup = drupal_render_page($page);
- $js = $original_js;
- $css = $original_css;
- $libraries = $original_libraries;
-
-
-
- $system_main_content_added = FALSE;
-
-
- overlay_set_regions_to_render(array());
- return $markup;
- }
- function overlay_get_rendered_content() {
- return overlay_store_rendered_content();
- }
- function overlay_store_rendered_content($id = NULL, $content = NULL) {
- $rendered_content = &drupal_static(__FUNCTION__, array());
- if (isset($id)) {
- $rendered_content[$id] = $content;
- }
- return $rendered_content;
- }
- function overlay_request_refresh($region) {
- $class = drupal_region_class($region);
- $_SESSION['overlay_regions_to_refresh'][] = array($class => $region);
- }
- function overlay_request_page_refresh() {
- $_SESSION['overlay_refresh_parent'] = TRUE;
- }
- function overlay_trigger_refresh() {
- if (!empty($_SESSION['overlay_regions_to_refresh'])) {
- $settings = array(
- 'overlayChild' => array(
- 'refreshRegions' => $_SESSION['overlay_regions_to_refresh'],
- ),
- );
- drupal_add_js($settings, array('type' => 'setting'));
- unset($_SESSION['overlay_regions_to_refresh']);
- }
- if (!empty($_SESSION['overlay_refresh_parent'])) {
- drupal_add_js(array('overlayChild' => array('refreshPage' => TRUE)), array('type' => 'setting'));
- unset($_SESSION['overlay_refresh_parent']);
- }
- }
- function overlay_ajax_render_region($region) {
- print overlay_render_region($region);
- }
|