'Navigate Settings', 'page callback' => 'drupal_get_form', 'callback arguments' => 'navigate_admin_settings', 'access arguments' => array('navigate administer'), 'description' => Global configuration of Navigate functionality.', 'type' => MENU_NORMAL_ITEM, ); */ $items['navigate/process']= array( 'page callback' => 'navigate_process', 'access arguments' => array('navigate view'), 'type' => MENU_CALLBACK, ); $items['navigate/user_autocomplete'] = array( 'title' => 'User autocomplete', 'page callback' => 'navigate_user_autocomplete', 'access callback' => 'user_access', 'access arguments' => array('navigate administer'), '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'); if (module_exists('jquery_ui')) { jquery_ui_add(array( 'ui.core', 'ui.draggable', 'ui.sortable', )); } else { 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'); drupal_add_js(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery.hotkeys.js', 'module', 'footer'); $on = navigate_variable_get('on'); // Default to on if ($on == '') { $on = 0; } drupal_add_js(array('navigateOn' => $on), 'setting'); } if (user_access('navigate administer')) { drupal_add_js('misc/autocomplete.js'); } } /** * Render help page */ function navigate_help_page() { } /** * Implementation of hook_help(). */ function navigate_help($path, $arg) { $toc = ''; switch ($path) { 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 customize", "navigate administer"); } /** * 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() { $output = ''; if (user_access('navigate view')) { // Build navigate $output = navigate_build(); // Theme navigate $output = theme('navigate_outer', $output); $output .= '
    '; } return $output; } /** * Load a widget set */ function navigate_defaults_load() { global $user; // Save current set if (navigate_variable_get('saved_set_for_loading', 0) == '') { $settings = array( 'name' => 'saved_set_for_loading', 'value' => serialize(navigate_export($user->uid)), 'wid' => 0, ); navigate_variable_set($settings); } // Replace out current if (isset($_POST['rid'])) { $export = variable_get('navigate_defaults_'. check_plain($_POST['rid']), ''); navigate_import($export, $user->uid); } if (isset($_POST['username'])) { if ($uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $_POST['username']))) { $export = navigate_export($uid); navigate_import($export, $user->uid); navigate_variable_set(array('value' => check_plain($_POST['username']), 'name' => 'username_search')); } } echo navigate_build_defaults_admin(); die(); } /** * Return to saved widget set */ function navigate_defaults_switch_back() { global $user; $export = unserialize(navigate_variable_get('saved_set_for_loading', 0)); navigate_import($export, $user->uid); navigate_variable_delete('saved_set_for_loading'); echo navigate_build_defaults_admin(); die(); } /** * Change the default widget set for all users of a certain role */ function navigate_defaults_set_all() { global $user; $export = navigate_export($user->uid); if (isset($_POST['rid']) && $_POST['rid'] != 2) { if ($rid = db_result(db_query("SELECT rid FROM {role} WHERE rid = '%d'", $_POST['rid']))) { variable_set('navigate_defaults_'. $rid, navigate_export($user->uid)); $result = db_query("SELECT uid FROM {users_roles} WHERE rid = '%d'", $_POST['rid']); while ($row = db_fetch_array($result)) { if (db_fetch_array(db_query("SELECT uid FROM {navigate_widgets} WHERE uid = '%d'", $row['uid']))) { navigate_import($export, $row['uid']); } } } } elseif (isset($_POST['rid']) && $_POST['rid'] == 2) { $result = db_query("SELECT DISTINCT(u.uid), ur.rid FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid WHERE u.uid != 0 AND ur.rid IS NULL GROUP BY u.uid"); while ($row = db_fetch_array($result)) { if (db_fetch_array(db_query("SELECT uid FROM {navigate_widgets} WHERE uid = '%d'", $row['uid']))) { navigate_import($export, $row['uid']); } } } elseif (isset($_POST['username'])) { if ($uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $_POST['username']))) { navigate_import(navigate_export($user->uid), $uid); navigate_variable_set(array('value' => check_plain($_POST['username']), 'name' => 'username_search')); } } echo navigate_build_defaults_admin(); die(); } /** * Theme the outer portion of navigate */ function theme_navigate_outer($output) { $admin_menu_class = ''; if (module_exists('admin_menu') && user_access('access administration menu')) { $admin_menu_class = ' navigate-admin-menu '; } $output = '
    ' . navigate_tooltip('navigate-switch-outer', '

    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.') .'

    ') .'
    '; return $output; } /** * Run all ajax queries through navigate/process, which maps to this function */ function navigate_process() { switch ($_POST['action']) { 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 'widget_delete': navigate_widget_delete(); break; case 'save_defaults': navigate_save_defaults(); break; case 'defaults_unset': navigate_unset_defaults(); break; case 'widgets_reload': navigate_reload_widgets(); break; case 'defaults_load': navigate_defaults_load(); break; case 'defaults_switch_back': navigate_defaults_switch_back(); break; case 'defaults_set_all': navigate_defaults_set_all(); break; case 'export_widget_set': navigate_export_widget_set(); break; case 'import_widget_set': navigate_import_widget_set(); break; default: if (module_exists($_POST['module'])) { $function = $_POST['module'] .'_navigate_widget_process'; $function($_POST['wid'], $_POST['action']); } } } /** * Load a widget set associated with a user */ function navigate_user_load_set() { global $user; if (!user_access('navigate administer')) { return; } } /** * Reload the navigate widgets */ function navigate_reload_widgets() { global $user; $output = navigate_build_all_widgets($user->uid); echo $output; die(); } /** * Save default widget set */ function navigate_save_defaults() { global $user; if (!user_access('navigate administer')) { return; } if (isset($_POST['rid'])) { if ($rid = db_result(db_query("SELECT rid FROM {role} WHERE rid = '%d'", $_POST['rid']))) { variable_set('navigate_defaults_'. $rid, navigate_export($user->uid)); } if ($_POST['rid'] == 0) { variable_set('navigate_defaults_0', navigate_export($user->uid)); } } if (isset($_POST['uid'])) { if ($uid = db_result(db_query("SELECT uid FROM {users} WHERE uid = '%d'", $_POST['uid']))) { navigate_import(navigate_export($user->uid), $uid); } } echo navigate_build_defaults_admin(); die(); } /** * Unset default widget set */ function navigate_unset_defaults() { global $user; if (!user_access('navigate administer')) { return; } variable_del('navigate_defaults_'. $_POST['rid']); echo navigate_build_defaults_admin(); die(); } /** * Deletes a widget */ function navigate_widget_delete($wid='', $uid = '') { global $user; if (!user_access('navigate administer') && $uid != $user->uid) { return FALSE; } if ($uid == '') { $uid = $user->uid; } $wid = ($wid == '') ? $_POST['wid'] : $wid; // Call widget delete operation $row = db_fetch_array(db_query("SELECT * FROM {navigate_widgets} WHERE wid = '%d' AND uid = '%d'", $wid, $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'", $uid, $wid); db_query("DELETE FROM {navigate_user_settings} WHERE uid = '%d' AND wid = '%d'", $uid, $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; 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} (uid, type, module, weight) VALUES (%d, '%s', '%s', %d)", $user->uid, $type, $module, $weight); $wid = db_last_insert_id('navigate_widgets', 'wid'); 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(); $output = ''; foreach (module_implements($hook) as $module) { $function = $module .'_'. $hook; $array = array_merge($array, $function('list')); } foreach ($array as $widget) { $output .= theme('navigate_widget_list_item', $widget); } $output = ' '; return $output; } /** * Theme a widget list item */ function theme_navigate_widget_list_item($widget) { $single = isset($widget['single']) ? '
    ' : ''; return ''; } /** * Save a user variable */ function navigate_variable_set($settings=FALSE) { global $user; if (!$settings) { $value = $_POST['value']; $name = $_POST['name']; $wid = $_POST['wid']; } else { if (!isset($settings['wid'])) { $settings['wid'] = 0; } $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} (uid, value, name, wid) VALUES (%d, '%s', '%s', %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)); } /** * Delete a user variable */ function navigate_variable_delete($name, $wid=0) { global $user; db_query("DELETE FROM {navigate_user_settings} WHERE name = '%s' AND wid = '%d' AND uid = '%d'", $name, $wid, $user->uid); } /** * Build the Navigate bar */ function navigate_build() { global $user; $output = ''; // 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 $output .= navigate_build_all_widgets($user->uid); $output = theme('navigate_all_widgets', $output); $content['navigate'] = $output; // Keyboard shortcut enable button $key_disabled = navigate_variable_get('key_disabled'); $disabled_class = ''; if ($key_disabled == 1) { $disabled_class = ' key-disabled '; } $content['key_button'] = ''. navigate_tooltip('navigate-key-button', 'Enable / disable keyboard shortcuts'); $content['help_button'] = ''; $output = theme('navigate', $content); if (user_access('navigate administer')) { $output .= ' '; } return $output; } function navigate_build_all_widgets($uid) { $output = ''; $result = db_query("SELECT * FROM {navigate_widgets} WHERE uid = '%d' ORDER BY weight ASC", $uid); while ($row = db_fetch_array($result)) { if (module_exists($row['module'])) { $output .= navigate_output_widget($row); } } return $output; } function navigate_build_defaults_admin() { // Check if a widget set is loaded $alert = ''; if (navigate_variable_get('saved_set_for_loading', 0) != '') { $alert = 'Switch back to your auto-saved set'; } // Run through roles $output = ''; $result = db_query("SELECT * FROM {role} WHERE rid <> 1"); while ($row = db_fetch_array($result)) { $default = variable_get('navigate_defaults_'. $row['rid'], ''); $load = ''. t('Load') .''; $unset = ''. t('Unset') .''; if ($default != '') { $load = ''. t('Load') .''; $unset = ''. t('Unset') .''; } $output .= ' '. $row['name'] .' '. t('Set') .' '. $load .' '. $unset .' '. t('Set all users') .' '; } $default = variable_get('navigate_defaults_0', ''); $load = ''. t('Load') .''; $unset = ''. t('Unset') .''; if ($default != '') { $load = ''. t('Load') .''; $unset = ''. t('Unset') .''; } // User search row $username_value = navigate_variable_get('username_search'); $username_class = ''; $load = ''. t('Load') .''; $set_user = ''. t('Set user') .''; if ($username_value == '') { $username_value = t('Search name / UID'); $username_class = ' navigate-username-empty '; } else { $load = ''. t('Load') .''; $set_user = ''. t('Set user') .''; } // Import / export $inputs['export'] = navigate_textarea(array( 'name' => 'set-export', 'class' => 'navigate-favorites-export', 'filters' => 'true', 'submit' => 'Export widget set', 'hide_filters' => 1, 'callback' => 'navigate_set_export', 'help' => 'Click the export button and it will load the content in this box.', 'wid' => '', )); $inputs['import'] = navigate_textarea(array( 'name' => 'set-import', 'class' => 'navigate-favorites-import', 'filters' => 'true', 'submit' => 'Import widget set', 'hide_filters' => 1, 'callback' => 'navigate_set_import', 'help' => 'Click the import button to import widget set. Note that this will replace your current set.', 'wid' => '', )); $import_export = ' '; // Combine output $output = ' '; return $output; } /** * Build default set of widgets */ function navigate_add_default_widgets() { global $user; $export = ''; // Get default widget set for user role foreach ($user->roles as $rid => $role) { $export = variable_get('navigate_defaults_'. $rid, ''); } // If no default role sets exist, then use 'unassigned roles' one if ($export == '') { $export = variable_get('navigate_defaults_0', ''); } // Run import if ($export != '') { navigate_import($export, $user->uid); return; } // If there is default set, add a search and favorites widget if ($export != '') { navigate_import($export, $user->uid); return; } navigate_widget_add(FALSE, 'navigate_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'], 'wid' => $row['wid'] ); if (isset($row['order'])) { $settings['order'] = $row['order']; } $op = 'output'; $content = ''; if (function_exists($function)) { $content = $function($op, $settings); } if (!is_array($content)) { $content['widget'] = $content; } if (isset($content['settings'])) { $content['settings'] = theme('navigate_widget_settings', $content['settings'], $row['wid']); $content['settings_button'] = theme('navigate_widget_settings_button', $row['wid']); } $title = navigate_variable_get('widget_title', $row['wid']); if ($title != '') { $content['title'] = $title; } $close_button_style = ($show_close_button == 0) ? 'display:none' : ''; $output = theme('navigate_widget', $content, $row['wid'], $close_button_style, $row['type']); return $output; } /** * Themes the outside of all widgets */ function theme_navigate_all_widgets($output) { $sortable = ''; if (user_access('navigate customize')) { $sortable = ' navigate-all-widgets-sortable '; } $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) { $launch_settings = ''; if (user_access('navigate customize')) { $launch_settings = ''. navigate_tooltip('navigate-launch-settings-all', '

    '. 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 = ' '; return $output; } /** * Theme a Navigate widget */ function theme_navigate_widget($content, $wid, $close_button_style='display:none', $type) { $content['settings_button'] = isset($content['settings_button']) ? $content['settings_button'] : ''; $content['settings'] = isset($content['settings']) ? $content['settings'] : ''; $customizable = ''; if (user_access('navigate customize')) { $customizable = ' navigate-widget-title-customizable '; } $content = ' '; return $content; } /** * Themes widget settings button */ function theme_navigate_widget_settings_button($wid) { if (user_access('navigate customize')) { $output = ''; return $output; } } /** * Themes the setting slider pane */ function theme_navigate_widget_settings($settings, $wid) { $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 (isset($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']; } if (isset($settings[$wid])) { return $settings[$wid]; } } /** * Output a toggle button */ function navigate_button($button_settings) { $defaults = array( 'on' => '1', 'off' => '0', 'help' => '', ); 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 (!isset($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); } $on_class = ''; if ($settings[$button_settings['name']] == $button_settings['on']) { $on_class = ' navigate-button-on '; } $group_class = ''; $group_input = ''; if (isset($button_settings['group'])) { $group_class = ' '. $button_settings['group'] .' '; $group_input = ''; } $required = ''; if (isset($button_settings['required'])) { $required = 1; } $callback = ''; if (isset($button_settings['callback'])) { $callback = $button_settings['callback']; } $output = ' '; return $output; } function navigate_tooltip($id, $content) { return ''; } /** * Output a text input */ function navigate_input($input_settings) { $settings = navigate_widget_settings_get($input_settings['wid']); if ($input_settings['select_all']) { $select_all_class = ' navigate-select-all '; } $clear_class = ''; if (isset($input_settings['clear'])) { $clear_class = ' navigate-clear '; } $settings[$input_settings['name']] = isset($settings[$input_settings['name']]) ? ($settings[$input_settings['name']]) : ''; $output = ' '; return $output; } /** * Output a textarea input */ function navigate_textarea($input_settings) { $filters_output = ''; $input_settings['select_all'] = isset($input_settings['select_all']) ? $input_settings['select_all'] : ''; $settings = navigate_widget_settings_get($input_settings['wid']); $select_all_class = isset($input_settings['select_all']) ? ' navigate-select-all ' : ''; $filters_output = ''; if (!isset($input_settings['hide_filters'])) { $filters = filter_formats(); foreach ($filters as $filter) { if (!isset($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 = ''; } } if (!isset($input_settings['submit'])) { $input_settings['submit'] = 'Save'; } $settings[$input_settings['name']] = isset($settings[$input_settings['name']]) ? $settings[$input_settings['name']] : ''; $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' => 'Phpinfo()', 'path' => 'admin/reports/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; if ($i == '') { $i = 1; } $char_count = 26; if (drupal_strlen($menu_item['title']) > $char_count) { $title = drupal_substr($menu_item['title'], 0, $char_count-3) .'...'; } else { $title = $menu_item['title']; } $menu_item['description'] = isset($menu_item['description']) ? ('') : ''; $help_content = ' '; $query = ''; if (strpos($menu_item['path'], '?') !== FALSE) { $path_array = explode('?', $menu_item['path']); $menu_item['path'] = $path_array[0]; $query = $path_array[1]; } $id = 'navigate_link_'. $menu_item['wid'] .'_'. $i; $output = ' '. navigate_tooltip($id, $help_content); $i++; return $output; } /** * Associate a js callback with clicking content */ function navigate_callback_button($input_settings) { $input_settings['wid'] = isset($input_settings['wid']) ? $input_settings['wid'] : ''; $output = ' '; return $output; } /** * Implementation of hook_user(). */ function navigate_user($op, &$edit, &$account, $category='') { switch ($op) { case 'delete': db_query("DELETE FROM {navigate_user_settings} WHERE uid = '%d'", $account->uid); db_query("DELETE FROM {navigate_widgets} WHERE uid = '%d'", $account->uid); break; } } /** * Uninstalls a module's widgets on module uninstall */ function navigate_uninstall_widget_module($module) { if (module_exists('navigate')) { $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); //db_query("DELETE FROM {navigate_cache} WHERE wid = '%s'", $module); } } /** * Implementation of hook_theme(). */ function navigate_theme() { return array( 'navigate_outer' => array( 'arguments' => array('output' => NULL, 'hidden' => NULL), ), 'navigate_widget_list_item' => array( 'arguments' => array('type' => NULL, 'content' => NULL, 'module' => NULL), ), 'navigate_all_widgets' => array( 'arguments' => array('output' => NULL), ), 'navigate' => array( 'arguments' => array('content' => NULL), ), 'navigate_widget' => array( 'arguments' => array('content' => NULL, 'wid' => NULL, 'close_button_style' => NULL), ), 'navigate_widget_settings_button' => array( 'arguments' => array('wid' => NULL), ), 'navigate_widget_settings' => array( 'arguments' => array('settings' => NULL), ), 'navigate_link' => array( 'arguments' => array('menu_item' => NULL), ), ); } /** * Renders an accordian-style display of content for longer widgets */ function navigate_accordian($accordian) { //static $i; //$i = isset($i) ? $i++ : 0; $output = ''; foreach ($accordian as $item) { $hide = ''; if (!isset($item['default'])) { $hide = ' style="display:none" '; } $output .= ' '; } $output = ''; return $output; } /** * Duplicate a widget */ function navigate_duplicate_widget($wid, $uid) { $result = db_query("SELECT * FROM {navigate_widgets} WHERE wid = '%d'", $wid); if ($row = db_fetch_array($result)) { db_query("INSERT INTO {navigate_widgets} (uid, type, module, weight) VALUES (%d, '%s', '%s', %d)", $uid, $row['type'], $row['module'], $row['weight']); $new_wid = db_last_insert_id('navigate_widgets', 'wid'); $function = $row['module'] .'_navigate_widgets'; if (function_exists($function)) { $function('duplicate', array('wid' => $wid, 'type' => $row['type'], 'new_wid' => $new_wid, 'uid' => $uid)); } } return $new_wid; } /** * Set value for widget */ function navigate_widget_cache_set($wid, $name, $value) { $cid = $wid .':'. $name; cache_set($cid, $value, 'cache_navigate'); } /** * Get value for widget cache */ function navigate_widget_cache_get($wid, $name) { $cid = $wid .':'. $name; $cache = cache_get($cid, 'cache_navigate'); if ($cache && isset($cache->data)) { return $cache->data; } return FALSE; } /** * Save default widget set */ function navigate_export($uid) { $export = array(); $widgets = array(); $result = db_query("SELECT * FROM {navigate_widgets} WHERE uid = '%d' ORDER BY weight ASC", $uid); while ($row = db_fetch_array($result)) { $settings = array(); $options = array(); $settings_results = db_query("SELECT * FROM {navigate_user_settings} WHERE wid = '%d'", $row['wid']); while ($setting = db_fetch_array($settings_results)) { $settings[] = array( 'name' => $setting['name'], 'value' => $setting['value'], ); } $function_name = $row['module'] .'_navigate_widgets'; if (function_exists($function_name)) { $options = $function_name('export', array('wid' => $row['wid'])); } $widget = array( 'module' => $row['module'], 'type' => $row['type'], 'weight' => $row['weight'], 'settings' => $settings, 'options' => $options, ); $widgets[] = $widget; } return $widgets; } /** * Import a widget set */ function navigate_import($export, $uid) { global $user; if (!user_access('navigate administer') && $uid != $user->uid) { return FALSE; } // Delete all current widgets for user $result = db_query("SELECT wid FROM {navigate_widgets} WHERE uid = '%d'", $uid); while ($row = db_fetch_array($result)) { navigate_widget_delete($row['wid'], $uid); } // Run import foreach ($export as $widget) { db_query("INSERT INTO {navigate_widgets} (uid, type, module, weight) VALUES (%d, '%s', '%s', %d)", $uid, $widget['type'], $widget['module'], $widget['weight']); $wid = db_last_insert_id('navigate_widgets', 'wid'); if (isset($widget['settings'])) { foreach ($widget['settings'] as $setting) { db_query("INSERT INTO {navigate_user_settings} (wid, uid, name, value) VALUES (%d, '%d', '%s', '%s')", $wid, $uid, $setting['name'], $setting['value']); } } if (isset($widget['options'])) { $function_name = $widget['module'] .'_navigate_widgets'; if (function_exists($function_name)) { $function_name('import', array('wid' => $wid, 'uid' => $uid, 'options' => $widget['options'])); } } } } /** * Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing users. */ function navigate_user_autocomplete($string = '') { $matches = array(); if ($string) { if (is_numeric($string)) { $result = db_query_range("SELECT name FROM {users} WHERE uid = '%d'", $string, 0, 10); } else { $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $string, 0, 10); } while ($user = db_fetch_object($result)) { $matches[$user->name] = check_plain($user->name); } } drupal_json($matches); } /** * Export a widget set */ function navigate_export_widget_set() { global $user; if (!user_access('navigate administer')) { return; } var_export(navigate_export($user->uid)); die(); } /** * Import a widget set */ function navigate_import_widget_set() { if (!user_access('navigate administer')) { return; } global $user; $import = eval('return '. $_POST['import'] .';'); navigate_import($import, $user->uid); die(); }