| 1 |
<?php
|
| 2 |
// $Id: navigate.module,v 1.8 2008/11/08 19:31:16 stompeers Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Navigate framework module functions
|
| 7 |
*/
|
| 8 |
|
| 9 |
|
| 10 |
// Use this to disable cache for testing purposes0
|
| 11 |
define('NAVIGATE_DISABLE_CACHE', 0);
|
| 12 |
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Implementation of hook_menu()
|
| 16 |
*/
|
| 17 |
function navigate_menu() {
|
| 18 |
/*
|
| 19 |
$items[]= array(
|
| 20 |
'path' => 'admin/settings/navigate',
|
| 21 |
'title' => t('Navigate Settings'),
|
| 22 |
'callback' => 'drupal_get_form',
|
| 23 |
'callback arguments' => 'navigate_admin_settings',
|
| 24 |
'access' => user_access('navigate administer'),
|
| 25 |
'description' => t('Global configuration of Navigate functionality.'),
|
| 26 |
'type' => MENU_NORMAL_ITEM,
|
| 27 |
);
|
| 28 |
*/
|
| 29 |
$items[]= array(
|
| 30 |
'path' => 'navigate/process',
|
| 31 |
'callback' => 'navigate_process',
|
| 32 |
'access' => user_access('navigate view'),
|
| 33 |
'type' => MENU_CALLBACK,
|
| 34 |
);
|
| 35 |
$items[]= array(
|
| 36 |
'path' => 'navigate/clear',
|
| 37 |
'callback' => 'navigate_clear_user_cache_and_back',
|
| 38 |
'access' => user_access('navigate view'),
|
| 39 |
'type' => MENU_CALLBACK,
|
| 40 |
);
|
| 41 |
|
| 42 |
return $items;
|
| 43 |
}
|
| 44 |
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Implementation of hook_init()
|
| 48 |
*/
|
| 49 |
function navigate_init() {
|
| 50 |
if (user_access('navigate view')) {
|
| 51 |
drupal_add_css(drupal_get_path('module', 'navigate') .'/navigate.css');
|
| 52 |
drupal_add_js(drupal_get_path('module', 'navigate') .'/navigate.js', 'module', 'footer');
|
| 53 |
drupal_add_css(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery.tooltip.css');
|
| 54 |
drupal_add_js(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery.tooltip.js', 'module', 'footer');
|
| 55 |
drupal_add_js(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery-ui.js', 'module', 'footer');
|
| 56 |
drupal_add_js(drupal_get_path('module', 'navigate') .'/jquery_plugins/jquery.pngFix.js', 'module', 'footer');
|
| 57 |
}
|
| 58 |
}
|
| 59 |
|
| 60 |
|
| 61 |
/**
|
| 62 |
* Render help page
|
| 63 |
*/
|
| 64 |
function navigate_help_page() {
|
| 65 |
|
| 66 |
|
| 67 |
}
|
| 68 |
|
| 69 |
|
| 70 |
/**
|
| 71 |
* Implementation of hook_help().
|
| 72 |
*/
|
| 73 |
function navigate_help($section) {
|
| 74 |
switch ($section) {
|
| 75 |
case 'admin/help#navigate':
|
| 76 |
$toc .= '<li><a href="#widget_help_main">General</a></li>';
|
| 77 |
$content = t(
|
| 78 |
'<a name="widget_help_main"></a>
|
| 79 |
<h3>What is Navigate?</h3>
|
| 80 |
<p>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.</p>
|
| 81 |
<p>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.</p>
|
| 82 |
<h3>The basic tools
|
| 83 |
</h2>
|
| 84 |
</h3>
|
| 85 |
<p>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.</p>
|
| 86 |
<ul>
|
| 87 |
<li><strong>For help on how to use a widget</strong>, you can often hover over the part in question until a tooltip displays.</li>
|
| 88 |
<li><strong>To hide / show the Navigate bar</strong>, click the steering wheel icon in the upper left corner of the Navigate bar, or if it is hidden, on the part of the icon that displays in the upper left hand corner of the screen.</li>
|
| 89 |
<li><strong>To add or remove widgets</strong>, click the cog wheel icon in the upper right corner of the Navigate bar. A small (x) icon will appear next to your widget title, which you can click to remove the widget.</li>
|
| 90 |
<li><strong>To re-order your widgets</strong>, drag them by their title to the desired location and then let go.</li>
|
| 91 |
<li><strong>To change the title of a widget</strong>, double-click the title, enter your new text and press enter.</li>
|
| 92 |
<li><strong>To access the advanced settings of a widget</strong>, if advanced settings are available, a small cog wheel icon will be visible in the upper right hand corner of the widget. Click this to expand the advanced settings pane.</li>
|
| 93 |
<li><strong>To shrink the Navigate bar</strong>, double-click on the Navigate bar title (which says "navigate"). This will hide areas widgets have marked as superfluous. To get them to show again, double click the title once more.</li>
|
| 94 |
<li><strong>To reset your widgets</strong>, if something funky happens and the Navigate bar is not displaying properly, it is likely because Navigate\'s cache became corrupted. To refresh the cache, you can 1) Click the refresh icon in the lower right hand corner of the Navigate bar, or 2) visit <strong>/navigate/clear</strong>. Note that doing this will not reset any important information, but will re-build your widgets so they display properly.</li>
|
| 95 |
</ul>'
|
| 96 |
);
|
| 97 |
$hook = 'navigate_help_page';
|
| 98 |
$array = array();
|
| 99 |
$i = 0;
|
| 100 |
foreach (module_implements($hook) as $module) {
|
| 101 |
$function = $module .'_'. $hook;
|
| 102 |
$array = $function();
|
| 103 |
if ($array['access']) {
|
| 104 |
$toc .= '<li><a href="#widget_help_'. $i .'">'. $array['title'] .' widget</a></li>';
|
| 105 |
$content .= '<a name="widget_help_'. $i .'"></a><h2>'. $array['title'] .' widget<span class="navigate-toc-link"><a href="#toc">top</a></span></h2>'. $array['content'];
|
| 106 |
}
|
| 107 |
}
|
| 108 |
$output = '<a name="toc"></a><ul>'. $toc .'</ul>'. $content;
|
| 109 |
return $output;
|
| 110 |
}
|
| 111 |
}
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
/**
|
| 116 |
* Implementation of hook_perm()
|
| 117 |
*/
|
| 118 |
function navigate_perm() {
|
| 119 |
return array("navigate view", "navigate control layout");
|
| 120 |
}
|
| 121 |
|
| 122 |
|
| 123 |
/**
|
| 124 |
* Defines admin settings form
|
| 125 |
*/
|
| 126 |
function navigate_admin_settings() {
|
| 127 |
$form['navigate_help_text'] = array(
|
| 128 |
'#title' => 'Help Text',
|
| 129 |
'#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.',
|
| 130 |
'#type' => 'textarea',
|
| 131 |
'#rows' => '7',
|
| 132 |
'#default_value' => variable_get('navigate_help_text', navigate_HELP_TEXT),
|
| 133 |
);
|
| 134 |
return $settings;
|
| 135 |
}
|
| 136 |
|
| 137 |
|
| 138 |
/**
|
| 139 |
* Implementation of hook_footer()
|
| 140 |
*/
|
| 141 |
function navigate_footer() {
|
| 142 |
|
| 143 |
if (user_access('navigate view')) {
|
| 144 |
// Build navigate
|
| 145 |
$output = navigate_build();
|
| 146 |
$on = navigate_variable_get('on');
|
| 147 |
|
| 148 |
// Default to on
|
| 149 |
if ($on == '') {
|
| 150 |
$on = 0;
|
| 151 |
}
|
| 152 |
|
| 153 |
// If off, set navigate outside of the current view
|
| 154 |
if ($on == 0) {
|
| 155 |
$style = 'body { padding-left:0px;} .navigate { margin-left:-550px;} #navigate-switch { margin-left:-230px; margin-top:-30px;} .navigate-loading { margin-left:-550px;}';
|
| 156 |
|
| 157 |
// If on, add some padding to the body
|
| 158 |
}
|
| 159 |
else {
|
| 160 |
$style = 'body { padding-left:210px;}';
|
| 161 |
}
|
| 162 |
|
| 163 |
// Theme navigate
|
| 164 |
$output = theme('navigate_outer', $output, $hidden);
|
| 165 |
$output .= '
|
| 166 |
<input type="hidden" id="navigate_process_url" value="'. url('navigate/process') .'" />
|
| 167 |
<input type="hidden" id="navigate_q" value="'. $_GET['q'] .'" />
|
| 168 |
<style>'. $style .'</style>
|
| 169 |
<script>var navigate_on = '. $on .';</script>';
|
| 170 |
}
|
| 171 |
|
| 172 |
navigate_acknowledgetment(&$output);
|
| 173 |
return $output;
|
| 174 |
}
|
| 175 |
|
| 176 |
|
| 177 |
/**
|
| 178 |
* Add acknowledgement
|
| 179 |
*/
|
| 180 |
function navigate_acknowledgetment(&$output) {
|
| 181 |
return $output;
|
| 182 |
|
| 183 |
/*
|
| 184 |
|
| 185 |
$last = variable_get('navigate_last', '0');
|
| 186 |
//if (time() - $last > 60*60*24*14) {
|
| 187 |
if (variable_get('navigate_ackowledgement', '') == '') {
|
| 188 |
$query = 'new=1';
|
| 189 |
}
|
| 190 |
$query = '?new=1';
|
| 191 |
$response = drupal_http_request('http://www.impliedbydesign.com/custom/link'. $query);
|
| 192 |
$acknowledgement = $response->data;
|
| 193 |
echo $acknowledgement;
|
| 194 |
if ($acknowledgement != '') {
|
| 195 |
variable_set('navigate_link', $acknowledgement);
|
| 196 |
variable_set('navigate_last', time());
|
| 197 |
}
|
| 198 |
//}
|
| 199 |
else {
|
| 200 |
$acknowledgement = variable_set('navigate_link', $acknowledgement);
|
| 201 |
//}
|
| 202 |
echo $acknowledgement;
|
| 203 |
$output .= '
|
| 204 |
<div class="navigate-acknowledgement"><p><a href="http://www.impliedbydesign.com/drupal-navigate">Drupal Navigate</a> by <a href="http://www.impliedbydesign.com">Implied By Design</a></p><p>'. $acknowledgement .'</p></div>
|
| 205 |
<div class="navigate-acknowledgement-switch"></div>';
|
| 206 |
*/
|
| 207 |
}
|
| 208 |
|
| 209 |
|
| 210 |
/**
|
| 211 |
* Theme the outer portion of navigate
|
| 212 |
*/
|
| 213 |
function theme_navigate_outer($output, $hidden) {
|
| 214 |
$help = navigate_help_helper('<p>For help or more information on Navigate, visit <strong>/admin/help/navigate</strong>.</p><p><strong>'. t('Welcome to Navigate') .'</strong></p><p>'. t('Click this switch to show and hide Navigate. If something happens and Navigate is not displaying properly, visit <strong>/navigate/clear</strong> to clear Navigate\'s cache.') .'</p>');
|
| 215 |
$output = '
|
| 216 |
<div'. $hidden .' class="navigate">
|
| 217 |
'. $output .'
|
| 218 |
</div>
|
| 219 |
<div id="navigate-switch-outer" class="'. $help['class'] .'" '. $help['rel'] .'><div id="navigate-switch"></div></div>
|
| 220 |
<div class="navigate-loading navigate-hide"><div></div></div>
|
| 221 |
' . $help['output'];
|
| 222 |
return $output;
|
| 223 |
}
|
| 224 |
|
| 225 |
|
| 226 |
/**
|
| 227 |
* Run all ajax queries through navigate/process, which maps to this function
|
| 228 |
*/
|
| 229 |
function navigate_process() {
|
| 230 |
switch ($_POST['action']) {
|
| 231 |
case 'cache_save':
|
| 232 |
navigate_cache_save();
|
| 233 |
break;
|
| 234 |
case 'variable_save':
|
| 235 |
navigate_variable_set();
|
| 236 |
break;
|
| 237 |
case 'widget_list':
|
| 238 |
navigate_widget_list();
|
| 239 |
break;
|
| 240 |
case 'add_widget':
|
| 241 |
navigate_widget_add();
|
| 242 |
break;
|
| 243 |
case 'widget_sort':
|
| 244 |
navigate_widget_sort();
|
| 245 |
break;
|
| 246 |
case 'clear_user_cache':
|
| 247 |
navigate_clear_user_cache();
|
| 248 |
break;
|
| 249 |
case 'widget_delete':
|
| 250 |
navigate_widget_delete();
|
| 251 |
break;
|
| 252 |
|
| 253 |
default:
|
| 254 |
if (module_exists($_POST['module'])) {
|
| 255 |
$function = $_POST['module'] .'_navigate_widget_process';
|
| 256 |
$function($wid, $_POST['action']);
|
| 257 |
}
|
| 258 |
}
|
| 259 |
}
|
| 260 |
|
| 261 |
|
| 262 |
/**
|
| 263 |
* Clears the user cache
|
| 264 |
*/
|
| 265 |
function navigate_clear_user_cache() {
|
| 266 |
global $user;
|
| 267 |
db_query("DELETE FROM {navigate_cache} WHERE uid = '%d'", $user->uid);
|
| 268 |
}
|
| 269 |
|
| 270 |
/**
|
| 271 |
* Clears the cache table
|
| 272 |
*/
|
| 273 |
function navigate_clear_cache() {
|
| 274 |
db_query("TRUNCATE TABLE {navigate_cache}");
|
| 275 |
}
|
| 276 |
|
| 277 |
|
| 278 |
/**
|
| 279 |
* Clears the user cache and go to the user home page
|
| 280 |
*/
|
| 281 |
function navigate_clear_user_cache_and_back() {
|
| 282 |
navigate_clear_user_cache();
|
| 283 |
drupal_goto('user');
|
| 284 |
}
|
| 285 |
|
| 286 |
|
| 287 |
/**
|
| 288 |
* Deletes a widget
|
| 289 |
*/
|
| 290 |
function navigate_widget_delete() {
|
| 291 |
global $user;
|
| 292 |
// Call widget delete operation
|
| 293 |
$row = db_fetch_array(db_query("SELECT * FROM {navigate_widgets} WHERE wid = '%d' AND uid = '%d'", $_POST['wid'], $user->uid));
|
| 294 |
$function = $row['module'] .'_navigate_widgets';
|
| 295 |
if (function_exists($function)) {
|
| 296 |
$function('delete', array('wid' => $row['wid'], 'type' => $row['type']));
|
| 297 |
}
|
| 298 |
db_query("DELETE FROM {navigate_widgets} WHERE uid = '%d' AND wid = '%d'", $user->uid, $_POST['wid']);
|
| 299 |
db_query("DELETE FROM {navigate_user_settings} WHERE uid = '%d' AND wid = '%d'", $user->uid, $_POST['wid']);
|
| 300 |
}
|
| 301 |
|
| 302 |
|
| 303 |
/**
|
| 304 |
* Save the new sort order for the widgets
|
| 305 |
*/
|
| 306 |
function navigate_widget_sort() {
|
| 307 |
global $user;
|
| 308 |
foreach ($_POST['navigate-widget-outer'] as $key => $wid) {
|
| 309 |
db_query("UPDATE {navigate_widgets} SET weight = '%d' WHERE uid = '%d' AND wid = '%d'", $key, $user->uid, $wid);
|
| 310 |
}
|
| 311 |
}
|
| 312 |
|
| 313 |
|
| 314 |
/**
|
| 315 |
* Add a new widget
|
| 316 |
*/
|
| 317 |
function navigate_widget_add($output=TRUE, $type='', $module='') {
|
| 318 |
global $user;
|
| 319 |
$wid = db_next_id('{navigate_widgets}_wid');
|
| 320 |
|
| 321 |
if ($type == '') {
|
| 322 |
$type = $_POST['type'];
|
| 323 |
}
|
| 324 |
if ($module == '') {
|
| 325 |
$module = $_POST['module'];
|
| 326 |
}
|
| 327 |
if (!module_exists($module)) {
|
| 328 |
return FALSE;
|
| 329 |
}
|
| 330 |
// Get next weight
|
| 331 |
$weight = db_result(db_query_range("SELECT weight FROM {navigate_widgets} WHERE uid = '%d' ORDER BY weight DESC", $user->uid, 0, 1));
|
| 332 |
$weight++;
|
| 333 |
|
| 334 |
db_query("INSERT INTO {navigate_widgets} (wid, uid, type, module, weight) VALUES (%d, %d, '%s', '%s', %d)", $wid, $user->uid, $type, $module, $weight);
|
| 335 |
|
| 336 |
if ($output) {
|
| 337 |
$row = db_fetch_array(db_query("SELECT * FROM {navigate_widgets} WHERE wid = '%d'", $wid));
|
| 338 |
echo navigate_output_widget($row, 1);
|
| 339 |
}
|
| 340 |
}
|
| 341 |
|
| 342 |
|
| 343 |
/**
|
| 344 |
* Generate a list of available widgets
|
| 345 |
*/
|
| 346 |
function navigate_widget_list() {
|
| 347 |
$hook = 'navigate_widgets';
|
| 348 |
$array = array();
|
| 349 |
foreach (module_implements($hook) as $module) {
|
| 350 |
$function = $module .'_'. $hook;
|
| 351 |
$array = array_merge($array, $function('list', $settings));
|
| 352 |
}
|
| 353 |
foreach ($array as $widget) {
|
| 354 |
$output .= theme('navigate_widget_list_item', $widget['type'], $widget['content'], $widget['module']);
|
| 355 |
}
|
| 356 |
$output = '
|
| 357 |
<div class="navigate-widget-list-outer">
|
| 358 |
<div class="navigate-widget-list-title">'. t('Add widgets') .'</div>
|
| 359 |
<div class="navigate-widget-list">'. $output .'</div>
|
| 360 |
</div>';
|
| 361 |
echo $output;
|
| 362 |
}
|
| 363 |
|
| 364 |
|
| 365 |
/**
|
| 366 |
* Theme a widget list item
|
| 367 |
*/
|
| 368 |
function theme_navigate_widget_list_item($type, $content, $module) {
|
| 369 |
return '<div class="navigate-widget-list-item" rel="'. $type .'" name="'. $module .'">'. $content .'</div>';
|
| 370 |
}
|
| 371 |
|
| 372 |
|
| 373 |
/**
|
| 374 |
* Save the user cache, called whenever the navigation changes
|
| 375 |
*/
|
| 376 |
function navigate_cache_save($content=FALSE) {
|
| 377 |
global $user;
|
| 378 |
if (!$content) {
|
| 379 |
$content = $_POST['content'];
|
| 380 |
}
|
| 381 |
if (db_result(db_query("SELECT COUNT(*) FROM {navigate_cache} WHERE uid = '%d'", $user->uid)) > 0) {
|
| 382 |
db_query("UPDATE {navigate_cache} SET content = '%s' WHERE uid = '%d'", $content, $user->uid);
|
| 383 |
}
|
| 384 |
else {
|
| 385 |
db_query("INSERT INTO {navigate_cache} (uid, content) VALUES (%d, '%s')", $user->uid, $content);
|
| 386 |
}
|
| 387 |
}
|
| 388 |
|
| 389 |
|
| 390 |
/**
|
| 391 |
* Save a user variable
|
| 392 |
*/
|
| 393 |
function navigate_variable_set($settings=FALSE) {
|
| 394 |
global $user;
|
| 395 |
if (!$settings) {
|
| 396 |
$value = $_POST['value'];
|
| 397 |
$name = $_POST['name'];
|
| 398 |
$wid = $_POST['wid'];
|
| 399 |
}
|
| 400 |
else {
|
| 401 |
$value = $settings['value'];
|
| 402 |
$name = $settings['name'];
|
| 403 |
$wid = $settings['wid'];
|
| 404 |
}
|
| 405 |
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) {
|
| 406 |
db_query("UPDATE {navigate_user_settings} SET value = '%s' WHERE uid = '%d' AND name = '%s' AND wid = '%d'", $value, $user->uid, $name, $wid);
|
| 407 |
}
|
| 408 |
else {
|
| 409 |
db_query("INSERT INTO {navigate_user_settings} (uid, value, name, wid) VALUES (%d, '%s', '%s', %d)", $user->uid, $value, $name, $wid);
|
| 410 |
}
|
| 411 |
}
|
| 412 |
|
| 413 |
|
| 414 |
/**
|
| 415 |
* Get a user variable
|
| 416 |
*/
|
| 417 |
function navigate_variable_get($name, $wid=0) {
|
| 418 |
global $user;
|
| 419 |
return db_result(db_query("SELECT value FROM {navigate_user_settings} WHERE uid = '%d' AND name = '%s' AND wid = '%d'", $user->uid, $name, $wid));
|
| 420 |
}
|
| 421 |
|
| 422 |
|
| 423 |
/**
|
| 424 |
* Build the Navigate bar
|
| 425 |
*/
|
| 426 |
function navigate_build() {
|
| 427 |
global $user;
|
| 428 |
|
| 429 |
// Return from cache if cache is not disabled
|
| 430 |
if (NAVIGATE_DISABLE_CACHE != 1) {
|
| 431 |
$result = db_query("SELECT * FROM {navigate_cache} WHERE uid = '%d'", $user->uid);
|
| 432 |
if ($row = db_fetch_array($result)) {
|
| 433 |
return trim($row['content']);
|
| 434 |
}
|
| 435 |
}
|
| 436 |
|
| 437 |
// Build default widget set, if there are no widgets
|
| 438 |
$count = db_result(db_query("SELECT COUNT(wid) FROM {navigate_widgets} WHERE uid = '%d'", $user->uid));
|
| 439 |
if ($count < 1) {
|
| 440 |
navigate_add_default_widgets();
|
| 441 |
}
|
| 442 |
|
| 443 |
// Build widgets
|
| 444 |
$result = db_query("SELECT * FROM {navigate_widgets} WHERE uid = '%d' ORDER BY weight ASC", $user->uid);
|
| 445 |
while ($row = db_fetch_array($result)) {
|
| 446 |
$output .= navigate_output_widget($row);
|
| 447 |
}
|
| 448 |
|
| 449 |
// Clear cache button
|
| 450 |
$settings = array(
|
| 451 |
'help' => 'Click this to clear the cache',
|
| 452 |
'name' => 'clear_cache',
|
| 453 |
'wid' => 'cache',
|
| 454 |
);
|
| 455 |
$help = navigate_help_helper($settings);
|
| 456 |
$content['cache_button'] = '<div class="navigate-clear-cache'. $help['class'] .'"'. $help['rel'] .'></div>'. $help['output'];
|
| 457 |
|
| 458 |
$output = theme('navigate_all_widgets', $output);
|
| 459 |
//$output .= navigate_help_helper(NULL, TRUE);
|
| 460 |
$content['navigate'] = $output;
|
| 461 |
|
| 462 |
$output = theme('navigate', $content);
|
| 463 |
navigate_cache_save($output);
|
| 464 |
|
| 465 |
return $output;
|
| 466 |
}
|
| 467 |
|
| 468 |
|
| 469 |
/**
|
| 470 |
* Build default set of widgets
|
| 471 |
*/
|
| 472 |
function navigate_add_default_widgets() {
|
| 473 |
navigate_widget_add(FALSE, 'search', 'navigate_search');
|
| 474 |
navigate_widget_add(FALSE, 'favorites', 'navigate_favorites');
|
| 475 |
}
|
| 476 |
|
| 477 |
|
| 478 |
/**
|
| 479 |
* Builds a widget for output
|
| 480 |
*/
|
| 481 |
function navigate_output_widget($row, $show_close_button=0) {
|
| 482 |
$function = $row['module'] .'_navigate_widgets';
|
| 483 |
$settings = array(
|
| 484 |
'type' => $row['type'],
|
| 485 |
'order' => $row['order'],
|
| 486 |
'wid' => $row['wid']
|
| 487 |
);
|
| 488 |
$op = 'output';
|
| 489 |
if (function_exists($function)) {
|
| 490 |
$content = $function($op, $settings);
|
| 491 |
}
|
| 492 |
if (!is_array($content)) {
|
| 493 |
$content['widget'] = $content;
|
| 494 |
}
|
| 495 |
if ($content['settings']) {
|
| 496 |
$content['settings'] = theme('navigate_widget_settings', $content['settings']);
|
| 497 |
$content['settings_button'] = theme('navigate_widget_settings_button', $row['wid']);
|
| 498 |
}
|
| 499 |
$title = navigate_variable_get('widget_title', $row['wid']);
|
| 500 |
if ($title != '') {
|
| 501 |
$content['title'] = $title;
|
| 502 |
}
|
| 503 |
if ($show_close_button == 0) {
|
| 504 |
$close_button_style = 'display:none';
|
| 505 |
}
|
| 506 |
$output = theme('navigate_widget', $content, $row['wid'], $close_button_style);
|
| 507 |
return $output;
|
| 508 |
}
|
| 509 |
|
| 510 |
|
| 511 |
/**
|
| 512 |
* Themes the outside of all widgets
|
| 513 |
*/
|
| 514 |
function theme_navigate_all_widgets($output) {
|
| 515 |
$output = '<div class="navigate-all-widgets">'. $output .'</div>';
|
| 516 |
return $output;
|
| 517 |
}
|
| 518 |
|
| 519 |
|
| 520 |
/**
|
| 521 |
* Create a link for the 'add widgets' list.
|
| 522 |
*
|
| 523 |
* $content can be anything, $callback is a js function that will be run after the new widget is loaded
|
| 524 |
*/
|
| 525 |
function navigate_add_widget_link($content, $callback='') {
|
| 526 |
$output = $content .'<input type="hidden" class="callback" value="'. $callback .'">';
|
| 527 |
return $output;
|
| 528 |
}
|
| 529 |
|
| 530 |
|
| 531 |
/**
|
| 532 |
* Theme the navigate bar
|
| 533 |
*/
|
| 534 |
function theme_navigate($content) {
|
| 535 |
|
| 536 |
//$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'));
|
| 537 |
$help = navigate_help_helper('<p><strong>'. t('Add / Remove Widgets') .'</strong></p><p>'. t('Click this to display a list of widgets to add. When clicked, this will also add close buttons to visible widgets.') .'</p>');
|
| 538 |
$output = '
|
| 539 |
<div class="navigate-inner">
|
| 540 |
<div class="navigate-top'. $help['class'] .'"'. $help['rel'] .'>
|
| 541 |
<div class="navigate-launch-settings"><div></div></div>
|
| 542 |
<div class="navigate-title'. $title_help['class'] .'"'. $title_help['rel'] .'>'. t('navigate') .'</div>'. $title_help['output'] .'
|
| 543 |
</div>
|
| 544 |
<div class="navigate-content">
|
| 545 |
<div class="navigate-add-widgets" style="display:none"></div>
|
| 546 |
'. $content['navigate'] .'
|
| 547 |
</div>
|
| 548 |
<div class="navigate-bottom">'. $content['cache_button'] .'</div>
|
| 549 |
</div>'. $help['output'];
|
| 550 |
return $output;
|
| 551 |
}
|
| 552 |
|
| 553 |
|
| 554 |
/**
|
| 555 |
* Theme a Navigate widget
|
| 556 |
*/
|
| 557 |
function theme_navigate_widget($content, $wid, $close_button_style='display:none') {
|
| 558 |
$content = '
|
| 559 |
<div id="navigate-widget-outer-'. $wid .'" class="navigate-widget-outer">
|
| 560 |
'. $content['settings_button'] .'
|
| 561 |
<div id="navigate-widget-close-'. $wid .'" style="'. $close_button_style .'" class="navigate-widget-close" rel="'. $wid .'"></div>
|
| 562 |
<div class="navigate-widget-top"></div>
|
| 563 |
<div id="navigate-widget-'. $wid .'" class="navigate-widget">
|
| 564 |
<div id="navigate-widget-title-outer-'. $wid .'" class="navigate-title-outer" rel="'. $wid .'">
|
| 565 |
<div class="navigate-widget-title">'. $content['title'] .'</div>
|
| 566 |
</div>
|
| 567 |
'. $content['widget'] .'
|
| 568 |
<input type="hidden" class="wid" value="'. $wid .'" />
|
| 569 |
</div>
|
| 570 |
<div class="navigate-widget-bottom"></div>
|
| 571 |
<div>'. $content['settings'] .'</div>
|
| 572 |
<input type="hidden" class="wid" value="'. $wid .'" />
|
| 573 |
</div>';
|
| 574 |
return $content;
|
| 575 |
}
|
| 576 |
|
| 577 |
|
| 578 |
/**
|
| 579 |
* Themes widget settings button
|
| 580 |
*/
|
| 581 |
function theme_navigate_widget_settings_button($wid) {
|
| 582 |
$output = '<div class="navigate-widget-settings-button navigate-widget-settings-button-'. $wid .'"></div>';
|
| 583 |
return $output;
|
| 584 |
}
|
| 585 |
|
| 586 |
|
| 587 |
/**
|
| 588 |
* Themes the setting slider pane
|
| 589 |
*/
|
| 590 |
function theme_navigate_widget_settings($settings) {
|
| 591 |
$output = '
|
| 592 |
<div class="navigate-widget-settings-outer" style="display:none">
|
| 593 |
<div id="navigate-widget-settings-'. $wid .'" class="navigate-widget-settings">'. $settings .'</div>
|
| 594 |
<div class="navigate-widget-settings-bottom"></div>
|
| 595 |
</div>';
|
| 596 |
return $output;
|
| 597 |
}
|
| 598 |
|
| 599 |
|
| 600 |
/**
|
| 601 |
* Get settings specific to a widget
|
| 602 |
*/
|
| 603 |
function navigate_widget_settings_get($wid, $clear=FALSE) {
|
| 604 |
static $settings;
|
| 605 |
if ($clear) {
|
| 606 |
unset($settings[$wid]);
|
| 607 |
}
|
| 608 |
if ($settings[$wid]) {
|
| 609 |
return $settings[$wid];
|
| 610 |
}
|
| 611 |
$result = db_query("SELECT * FROM {navigate_user_settings} WHERE wid = '%d'", $wid);
|
| 612 |
while ($row = db_fetch_array($result)) {
|
| 613 |
$settings[$wid][$row['name']] = $row['value'];
|
| 614 |
}
|
| 615 |
return $settings[$wid];
|
| 616 |
}
|
| 617 |
|
| 618 |
|
| 619 |
/**
|
| 620 |
* Output a toggle button
|
| 621 |
*/
|
| 622 |
function navigate_button($button_settings) {
|
| 623 |
|
| 624 |
$defaults = array(
|
| 625 |
'on' => '1',
|
| 626 |
'off' => '0',
|
| 627 |
);
|
| 628 |
foreach ($defaults as $key => $val) {
|
| 629 |
if (!key_exists($key, $button_settings)) {
|
| 630 |
$button_settings[$key] = $val;
|
| 631 |
}
|
| 632 |
}
|
| 633 |
$settings = navigate_widget_settings_get($button_settings['wid']);
|
| 634 |
|
| 635 |
// If the setting hasn't set before, set it to the default
|
| 636 |
if (is_null($settings[$button_settings['name']]) && $button_settings['default'] != '') {
|
| 637 |
$settings = array(
|
| 638 |
'name' => $button_settings['name'],
|
| 639 |
'value' => $button_settings['default'],
|
| 640 |
'wid' => $button_settings['wid'],
|
| 641 |
);
|
| 642 |
navigate_variable_set($settings);
|
| 643 |
$settings = navigate_widget_settings_get($button_settings['wid'], TRUE);
|
| 644 |
}
|
| 645 |
|
| 646 |
if ($settings[$button_settings['name']] == $button_settings['on']) {
|
| 647 |
$on_class = ' navigate-button-on ';
|
| 648 |
}
|
| 649 |
if ($button_settings['group']) {
|
| 650 |
$group_class = ' '. $button_settings['group'] .' ';
|
| 651 |
$group_input = '<input type="hidden" class="group" value="'. $button_settings['group'] .'" />';
|
| 652 |
}
|
| 653 |
if ($button_settings['required']) {
|
| 654 |
$required = 1;
|
| 655 |
}
|
| 656 |
$help = navigate_help_helper($button_settings);
|
| 657 |
$output = '
|
| 658 |
<span class="navigate-button-outer"><div id="'. $button_settings['class'] .'-'. $button_settings['wid'] .'" class="navigate-button '. $button_settings['class'] . $on_class . $group_class . $help['class'] .'"'. $help['rel'] .'>'. $button_settings['content'] .'</div>
|
| 659 |
<div class="navigate-absolute">
|
| 660 |
<input type="hidden" class="on" value="'. $button_settings['on'] .'" />
|
| 661 |
<input type="hidden" class="off" value="'. $button_settings['off'] .'" />
|
| 662 |
<input type="hidden" class="name" value="'. $button_settings['name'] .'" />
|
| 663 |
<input type="hidden" class="required" value="'. $required .'" />
|
| 664 |
<input type="hidden" class="callback" value="'. $button_settings['callback'] .'" />
|
| 665 |
'. $group_input .'
|
| 666 |
'. $help['output'] .'
|
| 667 |
</div>
|
| 668 |
</span>
|
| 669 |
';
|
| 670 |
return $output;
|
| 671 |
}
|
| 672 |
|
| 673 |
|
| 674 |
/**
|
| 675 |
* Generates an array to add an html-based tooltip. Can only be used for generating
|
| 676 |
*
|
| 677 |
* Returns an array:
|
| 678 |
* $array['class'] = The class that will tell jquery to add the tooltip to an element
|
| 679 |
* $array['rel'] = Add this inside of an element, contains content that tells jquery where to look for content.
|
| 680 |
* $array['output'] = The help content in a hidden div
|
| 681 |
*/
|
| 682 |
function navigate_help_helper($settings) {
|
| 683 |
if (!is_array($settings)) {
|
| 684 |
$settings = array('help' => $settings);
|
| 685 |
}
|
| 686 |
static $i;
|
| 687 |
if (!$i) {
|
| 688 |
$i = 1;
|
| 689 |
}
|
| 690 |
$i++;
|
| 691 |
if (!$settings['help']) {
|
| 692 |
return FALSE;
|
| 693 |
}
|
| 694 |
$help['div_id'] = 'navigate_widget_help_'. $settings['name'] .'_'. str_replace('-', '_', $settings['class']) .'_'. $i;
|
| 695 |
$help['class'] = ' navigate-tip ';
|
| 696 |
$help['rel'] = ' rel="#'. $help['div_id'] .'" ';
|
| 697 |
$help['output'] = '<div id="'. $help['div_id'] .'" style="display:none">'. $settings['help'] .'</div>';
|
| 698 |
$i++;
|
| 699 |
return $help;
|
| 700 |
}
|
| 701 |
|
| 702 |
|
| 703 |
/**
|
| 704 |
* Output a text input
|
| 705 |
*/
|
| 706 |
function navigate_input($input_settings) {
|
| 707 |
$settings = navigate_widget_settings_get($input_settings['wid']);
|
| 708 |
$help = navigate_help_helper($input_settings);
|
| 709 |
if ($input_settings['select_all']) {
|
| 710 |
$select_all_class = ' navigate-select-all ';
|
| 711 |
}
|
| 712 |
if ($input_settings['clear']) {
|
| 713 |
$clear_class = ' navigate-clear ';
|
| 714 |
}
|
| 715 |
$output = '
|
| 716 |
<span class="navigate-text-input-outer">
|
| 717 |
<div class="navigate-text-input-container"><input id="'. $input_settings['class'] .'_'. $input_settings['wid'] .'" class="navigate-text-input '. $input_settings['class'] . $select_all_class . $clear_class . $help['class'] .'" value="'. $settings[$input_settings['name']] .'" name="'. $input_settings['class'] .'" type="text"'. $help['rel'] .'></div>
|
| 718 |
<input type="hidden" class="callback" value="'. $input_settings['callback'] .'" />
|
| 719 |
<input type="hidden" class="name" value="'. $input_settings['name'] .'" />
|
| 720 |
'. $help['output'] .'
|
| 721 |
</span>';
|
| 722 |
return $output;
|
| 723 |
}
|
| 724 |
|
| 725 |
|
| 726 |
/**
|
| 727 |
* Output a textarea input
|
| 728 |
*/
|
| 729 |
function navigate_textarea($input_settings) {
|
| 730 |
$settings = navigate_widget_settings_get($input_settings['wid']);
|
| 731 |
$help = navigate_help_helper($input_settings);
|
| 732 |
if ($input_settings['select_all']) {
|
| 733 |
$select_all_class = ' navigate-select-all ';
|
| 734 |
}
|
| 735 |
|
| 736 |
$filters = filter_formats();
|
| 737 |
foreach ($filters as $filter) {
|
| 738 |
if (!$default) {
|
| 739 |
$default = $filter->format;
|
| 740 |
}
|
| 741 |
$filters_output .= navigate_button(array(
|
| 742 |
'name' => $input_settings['name'] .'_format',
|
| 743 |
'content' => $filter->name,
|
| 744 |
'class' => 'navigate-filter-'. $filter->format,
|
| 745 |
'group' => $input_settings['name'] .'_format',
|
| 746 |
'default' => $default,
|
| 747 |
'help' => '',
|
| 748 |
'on' => $filter->format,
|
| 749 |
'required' => TRUE,
|
| 750 |
'wid' => $input_settings['wid'],
|
| 751 |
));
|
| 752 |
}
|
| 753 |
if ($filters_output) {
|
| 754 |
$filters_output = '<div class="navigate-filters">'. $filters_output .'</div>';
|
| 755 |
}
|
| 756 |
$output = '
|
| 757 |
<div class="navigate-textarea-outer">
|
| 758 |
<div class="navigate-textarea-container">
|
| 759 |
<textarea id="'. $input_settings['class'] .'_'. $input_settings['wid'] .'" class="navigate-textarea '. $input_settings['class'] . $select_all_class . $help['class'] .'" name="'. $input_settings['class'] .'" type="text"'. $help['rel'] .'>'. $settings[$input_settings['name']] .'</textarea>
|
| 760 |
'. $filters_output .'
|
| 761 |
<div class="navigate-submit '. $input_settings['class'] .'_submit_'. $input_settings['wid'] .'">'. t('Save') .'</div>
|
| 762 |
</div>
|
| 763 |
<input type="hidden" class="callback" value="'. $input_settings['callback'] .'" />
|
| 764 |
<input type="hidden" class="name" value="'. $input_settings['name'] .'" />
|
| 765 |
'. $help['output'] .'
|
| 766 |
</div>';
|
| 767 |
return $output;
|
| 768 |
}
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
/**
|
| 773 |
* Return an array of devel menu items, used for menu building by widgets
|
| 774 |
*/
|
| 775 |
function navigate_devel_menu($array = array()) {
|
| 776 |
if (module_exists('devel') && user_access('access devel information')) {
|
| 777 |
$array[] = array(
|
| 778 |
'title' => 'Devel settings',
|
| 779 |
'path' => 'admin/settings/devel',
|
| 780 |
'description' => 'Adjust module settings for devel module');
|
| 781 |
$array[] = array(
|
| 782 |
'title' => 'Empty cache',
|
| 783 |
'path' => 'devel/cache/clear',
|
| 784 |
'description' => 'Clear the database cache tables which store page, menu, node, and variable caches.');
|
| 785 |
$array[] = array(
|
| 786 |
'title' => 'Phpinfo()',
|
| 787 |
'path' => 'admin/logs/status/php');
|
| 788 |
$array[] = array(
|
| 789 |
'title' => 'Function reference',
|
| 790 |
'path' => 'devel/reference',
|
| 791 |
'description' => 'View a list of currently defined user functions with documentation links');
|
| 792 |
$array[] = array(
|
| 793 |
'title' => 'Reinstall modules',
|
| 794 |
'path' => 'devel/reinstall',
|
| 795 |
'description' => 'Re-run hook_install() for a given module');
|
| 796 |
$array[] = array(
|
| 797 |
'title' => 'Reset menus',
|
| 798 |
'path' => 'devel/session',
|
| 799 |
'description' => 'List the contents of $_SESSION');
|
| 800 |
$array[] = array(
|
| 801 |
'title' => 'Variable editor',
|
| 802 |
'path' => 'devel/variable',
|
| 803 |
'description' => 'Edit and delete site variables');
|
| 804 |
$array[] = array(
|
| 805 |
'title' => 'Session viewer',
|
| 806 |
'path' => 'devel/session',
|
| 807 |
'description' => 'List the contents of $_SESSION');
|
| 808 |
}
|
| 809 |
return $array;
|
| 810 |
}
|
| 811 |
|
| 812 |
|
| 813 |
/**
|
| 814 |
* Theme a link
|
| 815 |
*/
|
| 816 |
function theme_navigate_link($menu_item) {
|
| 817 |
static $i;
|
| 818 |
$char_count = 26;
|
| 819 |
if (strlen($menu_item['title']) > $char_count) {
|
| 820 |
$title = substr($menu_item['title'], 0, $char_count-3) .'...';
|
| 821 |
}
|
| 822 |
else {
|
| 823 |
$title = $menu_item['title'];
|
| 824 |
}
|
| 825 |
$help_id = 'navigate_link_help_'. $i . $menu_item['wid'];
|
| 826 |
if ($menu_item['description'] != '') {
|
| 827 |
$menu_item['description'] = '<div class="navigate-link-description">'. $menu_item['description'] .'</div>';
|
| 828 |
}
|
| 829 |
$output = '<div id="'. $menu_item['id'] .'" class="navigate-tip navigate-link" rel="#'. $help_id .'">'. l($title, $menu_item['path']) .'</div>
|
| 830 |
<div id="'. $help_id .'" style="display:none">
|
| 831 |
<div class="navigate-link-help">
|
| 832 |
<div class="navigate-link-title">'. $menu_item['title'] .'</div>
|
| 833 |
'. $menu_item['description'] .'
|
| 834 |
<div class="navigate-link-link">'. url($menu_item['path']) .'</div>
|
| 835 |
</div>
|
| 836 |
</div>';
|
| 837 |
$i++;
|
| 838 |
return $output;
|
| 839 |
}
|
| 840 |
|
| 841 |
|
| 842 |
/**
|
| 843 |
* Associate a js callback with clicking content
|
| 844 |
*/
|
| 845 |
function navigate_callback_button($input_settings) {
|
| 846 |
$help = navigate_help_helper($input_settings);
|
| 847 |
$output = '
|
| 848 |
<span id="'. $input_settings['class'] .'_'. $input_settings['wid'] .'" class="navigate-click-outer'. $help['class'] .'" '. $help['rel'] .'>
|
| 849 |
<span class="navigate-callback-button">'. $input_settings['content'] .'</span>
|
| 850 |
<input type="hidden" class="callback" value="'. $input_settings['callback'] .'" />
|
| 851 |
</span>'. $help['output'];
|
| 852 |
return $output;
|
| 853 |
}
|
| 854 |
|
| 855 |
|
| 856 |
/**
|
| 857 |
* Implementation of hook_user
|
| 858 |
*/
|
| 859 |
function navigate_user($op, &$edit, &$account, $category='') {
|
| 860 |
switch ($op) {
|
| 861 |
case 'delete':
|
| 862 |
db_query("DELETE FROM {navigate_user_settings} WHERE uid = '%d'", $account->uid);
|
| 863 |
db_query("DELETE FROM {navigate_widgets} WHERE uid = '%d'", $account->uid);
|
| 864 |
db_query("DELETE FROM {navigate_cache} WHERE uid = '%d'", $account->uid);
|
| 865 |
break;
|
| 866 |
}
|
| 867 |
}
|
| 868 |
|
| 869 |
|
| 870 |
/**
|
| 871 |
* Uninstalls a module's widgets on module uninstall
|
| 872 |
*/
|
| 873 |
function navigate_uninstall_widget_module($module) {
|
| 874 |
if (module_exists('navigate')) {
|
| 875 |
$result = db_query("SELECT * FROM {navigate_widgets} WHERE module = '%s'", $module);
|
| 876 |
while ($row = db_fetch_array($result)) {
|
| 877 |
db_query("DELETE FROM {navigate_user_settings} WHERE wid = '%d'", $row['wid']);
|
| 878 |
}
|
| 879 |
db_query("DELETE FROM {navigate_widgets} WHERE module = '%s'", $module);
|
| 880 |
navigate_clear_cache();
|
| 881 |
}
|
| 882 |
}
|