'admin/settings/navigate', 'title' => t('Navigate Settings'), 'callback' => 'drupal_get_form', 'callback arguments' => 'navigate_admin_settings', 'access' => user_access('navigate administer'), 'description' => t('Global configuration of Navigate functionality.'), 'type' => MENU_NORMAL_ITEM, ); */ $items[]= array( 'path' => 'navigate/process', 'callback' => 'navigate_process', 'access' => user_access('navigate view'), 'type' => MENU_CALLBACK, ); $items[]= array( 'path' => 'navigate/clear', 'callback' => 'navigate_clear_user_cache_and_back', 'access' => user_access('navigate view'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implementation of hook_init() */ function navigate_init() { if (user_access('navigate view')) { drupal_add_css(drupal_get_path('module', 'navigate') .'/navigate.css'); drupal_add_js(drupal_get_path('module', 'navigate') .'/navigate.js', 'module', 'footer'); drupal_add_css(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery.tooltip.css'); drupal_add_js(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery.tooltip.js', 'module', 'footer'); drupal_add_js(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery-ui.js', 'module', 'footer'); drupal_add_js(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery.pngFix.js', 'module', 'footer'); } } /** * Render help page */ function navigate_help_page() { } /** * Implementation of hook_help(). */ function navigate_help($section) { switch ($section) { case 'admin/help#navigate': $toc .= '
  • General
  • '; $content = t( '

    What is Navigate?

    Navigate is the bar of widgets you see to your left. Or, if Navigate is minimized, you will see the Navigate icon peeking out of the upper left corner of the screen. When you click this icon, you will see the full Navigate widget set. Depending on the modules installed, Navigate will automatically add a Search widget and a Favorites widget for new users.

    Navigate uses a cache to save each user\'s Navigate bar whenever it is changed. This means that it requires few system resources when navigating from page to page.

    The basic tools

    Additional widgets can be added to your bar by clicking the add / remove widgets button, which looks like a cog wheel in the upper right hand corner of Navigate. Each user has their own Navigate bar, so you can customize yours to fit your needs.

    ' ); $hook = 'navigate_help_page'; $array = array(); $i = 0; foreach (module_implements($hook) as $module) { $function = $module .'_'. $hook; $array = $function(); if ($array['access']) { $toc .= '
  • '. $array['title'] .' widget
  • '; $content .= '

    '. $array['title'] .' widgettop

    '. $array['content']; } } $output = ''. $content; return $output; } } /** * Implementation of hook_perm() */ function navigate_perm() { return array("navigate view", "navigate control layout"); } /** * Defines admin settings form */ function navigate_admin_settings() { $form['navigate_help_text'] = array( '#title' => 'Help Text', '#description' => 'This is the help text the displays when the help link is clicked. You can use PHP tags, and if you leave it blank it will show the default text.', '#type' => 'textarea', '#rows' => '7', '#default_value' => variable_get('navigate_help_text', navigate_HELP_TEXT), ); return $settings; } /** * Implementation of hook_footer() */ function navigate_footer() { if (user_access('navigate view')) { // Build navigate $output = navigate_build(); $on = navigate_variable_get('on'); // Default to on if ($on == '') { $on = 0; } // If off, set navigate outside of the current view if ($on == 0) { $style = 'body { padding-left:0px;} .navigate { margin-left:-550px;} #navigate-switch { margin-left:-230px; margin-top:-30px;} .navigate-loading { margin-left:-550px;}'; // If on, add some padding to the body } else { $style = 'body { padding-left:210px;}'; } // Theme navigate $output = theme('navigate_outer', $output, $hidden); $output .= ' '; } navigate_acknowledgetment(&$output); return $output; } /** * Add acknowledgement */ function navigate_acknowledgetment(&$output) { return $output; /* $last = variable_get('navigate_last', '0'); //if (time() - $last > 60*60*24*14) { if (variable_get('navigate_ackowledgement', '') == '') { $query = 'new=1'; } $query = '?new=1'; $response = drupal_http_request('http://www.impliedbydesign.com/custom/link'. $query); $acknowledgement = $response->data; echo $acknowledgement; if ($acknowledgement != '') { variable_set('navigate_link', $acknowledgement); variable_set('navigate_last', time()); } //} else { $acknowledgement = variable_set('navigate_link', $acknowledgement); //} echo $acknowledgement; $output .= ' '; */ } /** * Theme the outer portion of navigate */ function theme_navigate_outer($output, $hidden) { $help = navigate_help_helper('

    For help or more information on Navigate, visit /admin/help/navigate.

    '. t('Welcome to Navigate') .'

    '. t('Click this switch to show and hide Navigate. If something happens and Navigate is not displaying properly, visit /navigate/clear to clear Navigate\'s cache.') .'

    '); $output = ' '. $output .' ' . $help['output']; return $output; } /** * Run all ajax queries through navigate/process, which maps to this function */ function navigate_process() { switch ($_POST['action']) { case 'cache_save': navigate_cache_save(); break; case 'variable_save': navigate_variable_set(); break; case 'widget_list': navigate_widget_list(); break; case 'add_widget': navigate_widget_add(); break; case 'widget_sort': navigate_widget_sort(); break; case 'clear_user_cache': navigate_clear_user_cache(); break; case 'widget_delete': navigate_widget_delete(); break; default: if (module_exists($_POST['module'])) { $function = $_POST['module'] .'_navigate_widget_process'; $function($wid, $_POST['action']); } } } /** * Clears the user cache */ function navigate_clear_user_cache() { global $user; db_query("DELETE FROM {navigate_cache} WHERE uid = '%d'", $user->uid); } /** * Clears the cache table */ function navigate_clear_cache() { db_query("TRUNCATE TABLE {navigate_cache}"); } /** * Clears the user cache and go to the user home page */ function navigate_clear_user_cache_and_back() { navigate_clear_user_cache(); drupal_goto('user'); } /** * Deletes a widget */ function navigate_widget_delete() { global $user; // Call widget delete operation $row = db_fetch_array(db_query("SELECT * FROM {navigate_widgets} WHERE wid = '%d' AND uid = '%d'", $_POST['wid'], $user->uid)); $function = $row['module'] .'_navigate_widgets'; if (function_exists($function)) { $function('delete', array('wid' => $row['wid'], 'type' => $row['type'])); } db_query("DELETE FROM {navigate_widgets} WHERE uid = '%d' AND wid = '%d'", $user->uid, $_POST['wid']); db_query("DELETE FROM {navigate_user_settings} WHERE uid = '%d' AND wid = '%d'", $user->uid, $_POST['wid']); } /** * Save the new sort order for the widgets */ function navigate_widget_sort() { global $user; foreach ($_POST['navigate-widget-outer'] as $key => $wid) { db_query("UPDATE {navigate_widgets} SET weight = '%d' WHERE uid = '%d' AND wid = '%d'", $key, $user->uid, $wid); } } /** * Add a new widget */ function navigate_widget_add($output=TRUE, $type='', $module='') { global $user; $wid = db_next_id('{navigate_widgets}_wid'); if ($type == '') { $type = $_POST['type']; } if ($module == '') { $module = $_POST['module']; } if (!module_exists($module)) { return FALSE; } // Get next weight $weight = db_result(db_query_range("SELECT weight FROM {navigate_widgets} WHERE uid = '%d' ORDER BY weight DESC", $user->uid, 0, 1)); $weight++; db_query("INSERT INTO {navigate_widgets} SET wid = '%d', uid = '%d', type = '%s', module='%s', weight='%d'", $wid, $user->uid, $type, $module, $weight); if ($output) { $row = db_fetch_array(db_query("SELECT * FROM {navigate_widgets} WHERE wid = '%d'", $wid)); echo navigate_output_widget($row, 1); } } /** * Generate a list of available widgets */ function navigate_widget_list() { $hook = 'navigate_widgets'; $array = array(); foreach (module_implements($hook) as $module) { $function = $module .'_'. $hook; $array = array_merge($array, $function('list', $settings)); } foreach ($array as $widget) { $output .= theme('navigate_widget_list_item', $widget['type'], $widget['content'], $widget['module']); } $output = ' '; echo $output; } /** * Theme a widget list item */ function theme_navigate_widget_list_item($type, $content, $module) { return ''; } /** * Save the user cache, called whenever the navigation changes */ function navigate_cache_save($content=FALSE) { global $user; if (!$content) { $content = $_POST['content']; } if (db_result(db_query("SELECT COUNT(*) FROM {navigate_cache} WHERE uid = '%d'", $user->uid)) > 0) { db_query("UPDATE {navigate_cache} SET content = '%s' WHERE uid = '%d'", $content, $user->uid); } else { db_query("INSERT INTO {navigate_cache} SET uid = '%d', content = '%s'", $user->uid, $content); } } /** * Save a user variable */ function navigate_variable_set($settings=FALSE) { global $user; if (!$settings) { $value = $_POST['value']; $name = $_POST['name']; $wid = $_POST['wid']; } else { $value = $settings['value']; $name = $settings['name']; $wid = $settings['wid']; } if (db_result(db_query("SELECT COUNT(*) FROM {navigate_user_settings} WHERE uid = '%d' AND name = '%s' AND wid = '%d'", $user->uid, $name, $wid)) > 0) { db_query("UPDATE {navigate_user_settings} SET value = '%s' WHERE uid = '%d' AND name = '%s' AND wid = '%d'", $value, $user->uid, $name, $wid); } else { db_query("INSERT INTO {navigate_user_settings} SET uid = '%d', value = '%s', name = '%s', wid = '%d'", $user->uid, $value, $name, $wid); } } /** * Get a user variable */ function navigate_variable_get($name, $wid=0) { global $user; return db_result(db_query("SELECT value FROM {navigate_user_settings} WHERE uid = '%d' AND name = '%s' AND wid = '%d'", $user->uid, $name, $wid)); } /** * Build the Navigate bar */ function navigate_build() { global $user; // Return from cache if cache is not disabled if (NAVIGATE_DISABLE_CACHE != 1) { $result = db_query("SELECT * FROM {navigate_cache} WHERE uid = '%d'", $user->uid); if ($row = db_fetch_array($result)) { return trim($row['content']); } } // Build default widget set, if there are no widgets $count = db_result(db_query("SELECT COUNT(wid) FROM {navigate_widgets} WHERE uid = '%d'", $user->uid)); if ($count < 1) { navigate_add_default_widgets(); } // Build widgets $result = db_query("SELECT * FROM {navigate_widgets} WHERE uid = '%d' ORDER BY weight ASC", $user->uid); while ($row = db_fetch_array($result)) { $output .= navigate_output_widget($row); } // Clear cache button $settings = array( 'help' => 'Click this to clear the cache', 'name' => 'clear_cache', 'wid' => 'cache', ); $help = navigate_help_helper($settings); $content['cache_button'] = ''. $help['output']; $output = theme('navigate_all_widgets', $output); //$output .= navigate_help_helper(NULL, TRUE); $content['navigate'] = $output; $output = theme('navigate', $content); navigate_cache_save($output); return $output; } /** * Build default set of widgets */ function navigate_add_default_widgets() { navigate_widget_add(FALSE, 'search', 'navigate_search'); navigate_widget_add(FALSE, 'favorites', 'navigate_favorites'); } /** * Builds a widget for output */ function navigate_output_widget($row, $show_close_button=0) { $function = $row['module'] .'_navigate_widgets'; $settings = array( 'type' => $row['type'], 'order' => $row['order'], 'wid' => $row['wid'] ); $op = 'output'; if (function_exists($function)) { $content = $function($op, $settings); } if (!is_array($content)) { $content['widget'] = $content; } if ($content['settings']) { $content['settings'] = theme('navigate_widget_settings', $content['settings']); $content['settings_button'] = theme('navigate_widget_settings_button', $row['wid']); } $title = navigate_variable_get('widget_title', $row['wid']); if ($title != '') { $content['title'] = $title; } if ($show_close_button == 0) { $close_button_style = 'display:none'; } $output = theme('navigate_widget', $content, $row['wid'], $close_button_style); return $output; } /** * Themes the outside of all widgets */ function theme_navigate_all_widgets($output) { $output = ''; return $output; } /** * Create a link for the 'add widgets' list. * * $content can be anything, $callback is a js function that will be run after the new widget is loaded */ function navigate_add_widget_link($content, $callback='') { $output = $content .''; return $output; } /** * Theme the navigate bar */ function theme_navigate($content) { //$title_help =navigate_help_helper(array('help' => t('Double-click this title to hide parts of widgets you might not need all the time.'), 'class' => 'navigate-title')); $help = navigate_help_helper('

    '. t('Add / Remove Widgets') .'

    '. t('Click this to display a list of widgets to add. When clicked, this will also add close buttons to visible widgets.') .'

    '); $output = ' '. $help['output']; return $output; } /** * Theme a Navigate widget */ function theme_navigate_widget($content, $wid, $close_button_style='display:none') { $content = ' '; return $content; } /** * Themes widget settings button */ function theme_navigate_widget_settings_button($wid) { $output = ''; return $output; } /** * Themes the setting slider pane */ function theme_navigate_widget_settings($settings) { $output = ' '; return $output; } /** * Get settings specific to a widget */ function navigate_widget_settings_get($wid, $clear=FALSE) { static $settings; if ($clear) { unset($settings[$wid]); } if ($settings[$wid]) { return $settings[$wid]; } $result = db_query("SELECT * FROM {navigate_user_settings} WHERE wid = '%d'", $wid); while ($row = db_fetch_array($result)) { $settings[$wid][$row['name']] = $row['value']; } return $settings[$wid]; } /** * Output a toggle button */ function navigate_button($button_settings) { $defaults = array( 'on' => '1', 'off' => '0', ); foreach ($defaults as $key => $val) { if (!key_exists($key, $button_settings)) { $button_settings[$key] = $val; } } $settings = navigate_widget_settings_get($button_settings['wid']); // If the setting hasn't set before, set it to the default if (is_null($settings[$button_settings['name']]) && $button_settings['default'] != '') { $settings = array( 'name' => $button_settings['name'], 'value' => $button_settings['default'], 'wid' => $button_settings['wid'], ); navigate_variable_set($settings); $settings = navigate_widget_settings_get($button_settings['wid'], TRUE); } if ($settings[$button_settings['name']] == $button_settings['on']) { $on_class = ' navigate-button-on '; } if ($button_settings['group']) { $group_class = ' '. $button_settings['group'] .' '; $group_input = ''; } if ($button_settings['required']) { $required = 1; } $help = navigate_help_helper($button_settings); $output = ' '. $group_input .' '. $help['output'] .' '; return $output; } /** * Generates an array to add an html-based tooltip. Can only be used for generating * * Returns an array: * $array['class'] = The class that will tell jquery to add the tooltip to an element * $array['rel'] = Add this inside of an element, contains content that tells jquery where to look for content. * $array['output'] = The help content in a hidden div */ function navigate_help_helper($settings) { if (!is_array($settings)) { $settings = array('help' => $settings); } static $i; if (!$i) { $i = 1; } $i++; if (!$settings['help']) { return FALSE; } $help['div_id'] = 'navigate_widget_help_'. $settings['name'] .'_'. str_replace('-', '_', $settings['class']) .'_'. $i; $help['class'] = ' navigate-tip '; $help['rel'] = ' rel="#'. $help['div_id'] .'" '; $help['output'] = ''; $i++; return $help; } /** * Output a text input */ function navigate_input($input_settings) { $settings = navigate_widget_settings_get($input_settings['wid']); $help = navigate_help_helper($input_settings); if ($input_settings['select_all']) { $select_all_class = ' navigate-select-all '; } if ($input_settings['clear']) { $clear_class = ' navigate-clear '; } $output = ' '. $help['output'] .' '; return $output; } /** * Output a textarea input */ function navigate_textarea($input_settings) { $settings = navigate_widget_settings_get($input_settings['wid']); $help = navigate_help_helper($input_settings); if ($input_settings['select_all']) { $select_all_class = ' navigate-select-all '; } $filters = filter_formats(); foreach ($filters as $filter) { if (!$default) { $default = $filter->format; } $filters_output .= navigate_button(array( 'name' => $input_settings['name'] .'_format', 'content' => $filter->name, 'class' => 'navigate-filter-'. $filter->format, 'group' => $input_settings['name'] .'_format', 'default' => $default, 'help' => '', 'on' => $filter->format, 'required' => TRUE, 'wid' => $input_settings['wid'], )); } if ($filters_output) { $filters_output = ''; } $output = ' '; return $output; } /** * Return an array of devel menu items, used for menu building by widgets */ function navigate_devel_menu($array = array()) { if (module_exists('devel') && user_access('access devel information')) { $array[] = array( 'title' => 'Devel settings', 'path' => 'admin/settings/devel', 'description' => 'Adjust module settings for devel module'); $array[] = array( 'title' => 'Empty cache', 'path' => 'devel/cache/clear', 'description' => 'Clear the database cache tables which store page, menu, node, and variable caches.'); $array[] = array( 'title' => 'Phpinfo()', 'path' => 'admin/logs/status/php'); $array[] = array( 'title' => 'Function reference', 'path' => 'devel/reference', 'description' => 'View a list of currently defined user functions with documentation links'); $array[] = array( 'title' => 'Reinstall modules', 'path' => 'devel/reinstall', 'description' => 'Re-run hook_install() for a given module'); $array[] = array( 'title' => 'Reset menus', 'path' => 'devel/session', 'description' => 'List the contents of $_SESSION'); $array[] = array( 'title' => 'Variable editor', 'path' => 'devel/variable', 'description' => 'Edit and delete site variables'); $array[] = array( 'title' => 'Session viewer', 'path' => 'devel/session', 'description' => 'List the contents of $_SESSION'); } return $array; } /** * Theme a link */ function theme_navigate_link($menu_item) { static $i; $char_count = 26; if (strlen($menu_item['title']) > $char_count) { $title = substr($menu_item['title'], 0, $char_count-3) .'...'; } else { $title = $menu_item['title']; } $help_id = 'navigate_link_help_'. $i . $menu_item['wid']; if ($menu_item['description'] != '') { $menu_item['description'] = ''; } $output = ' '; $i++; return $output; } /** * Associate a js callback with clicking content */ function navigate_callback_button($input_settings) { $help = navigate_help_helper($input_settings); $output = ' '. $input_settings['content'] .' '. $help['output']; return $output; } /** * Implementation of hook_user */ function navigate_user($op, &$edit, &$account, $category='') { switch ($op) { case 'delete': $result = db_query("SELECT * FROM {navigate_widgets} WHERE uid = '%d'"); while ($row = db_fetch_array($result)) { db_query("DELETE * FROM {navigate_user_settings} WHERE uid = '%d'", $account->uid); db_query("DELETE * FROM {navigate_widgets} WHERE uid = '%d'", $account->uid); db_query("DELETE * FROM {navigate_cache} WHERE uid = '%d'", $account->uid); } break; } } /** * Uninstalls a module's widgets on module uninstall */ function navigate_uninstall_widget_module($module) { $result = db_query("SELECT * FROM {navigate_widgets} WHERE module = '%s'", $module); while ($row = db_fetch_array($result)) { db_query("DELETE FROM {navigate_user_settings} WHERE wid = '%d'", $row['wid']); } db_query("DELETE FROM {navigate_widgets} WHERE module = '%s'", $module); navigate_clear_cache(); }