| 1 |
<?php |
<?php |
| 2 |
// $Id: jgrowl.module,v 1.2.2.3 2008/10/17 23:13:47 stevemckenzie Exp $ |
// $Id: jgrowl.module,v 1.6 2008/12/12 22:10:45 stevemckenzie Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* |
* |
| 27 |
/** |
/** |
| 28 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 29 |
*/ |
*/ |
| 30 |
function jgrowl_menu($may_cache) { |
function jgrowl_menu() { |
| 31 |
$items = array(); |
$items = array(); |
| 32 |
|
|
| 33 |
if ($may_cache) { |
$items['admin/settings/jgrowl'] = array( |
| 34 |
$items[] = array( |
'title' => t('jGrowl'), |
| 35 |
'title' => t('jGrowl'), |
'page callback' => 'drupal_get_form', |
| 36 |
'path' => 'admin/settings/jgrowl', |
'page arguments' => array('jgrowl_settings_form'), |
| 37 |
'callback' => 'drupal_get_form', |
'access callback' => 'user_access', |
| 38 |
'callback arguments' => array('jgrowl_settings_form'), |
'access arguments' => array('administer jgrowl'), |
| 39 |
'access' => user_access('administer jgrowl'), |
); |
|
); |
|
|
} |
|
| 40 |
|
|
| 41 |
return $items; |
return $items; |
| 42 |
} |
} |
| 43 |
|
|
| 44 |
/** |
/** |
| 45 |
|
* Implementation of hook_theme(). |
| 46 |
|
*/ |
| 47 |
|
function jgrowl_theme() { |
| 48 |
|
return array( |
| 49 |
|
'jgrowl_message' => array( |
| 50 |
|
'arguments' => array('message' => NULL, 'options' => array()), |
| 51 |
|
), |
| 52 |
|
); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
/** |
| 56 |
* Implementation of hook_footer(). |
* Implementation of hook_footer(). |
| 57 |
*/ |
*/ |
| 58 |
function jgrowl_footer($main = 0) { |
function jgrowl_footer($main = 0) { |
| 79 |
if ($type != 'full') { |
if ($type != 'full') { |
| 80 |
$file .= '_'. $type; |
$file .= '_'. $type; |
| 81 |
} |
} |
| 82 |
drupal_add_js($path. '/jgrowl/'. $file .'.js'); |
drupal_add_js($path. '/jgrowl/'. $file .'.js', 'module', 'footer'); |
| 83 |
|
|
| 84 |
// TODO: make theme-able. |
// TODO: make theme-able. |
| 85 |
drupal_add_css($path .'/jgrowl/jquery.jgrowl.css'); |
drupal_add_css($path .'/jgrowl/jquery.jgrowl.css'); |
| 209 |
} |
} |
| 210 |
unset($_SESSION['messages'][$type]); |
unset($_SESSION['messages'][$type]); |
| 211 |
} |
} |
| 212 |
drupal_add_js("$(document).ready(function() { $js });", 'inline'); |
drupal_add_js("$(document).ready(function() { $js });", 'inline', 'footer'); |
| 213 |
} |
} |
| 214 |
} |
} |
| 215 |
|
|
| 232 |
} |
} |
| 233 |
|
|
| 234 |
switch ($type) { |
switch ($type) { |
|
// Handle items already in JS format. |
|
|
case substr($var, 0, 1) == '{' && substr($var, (strlen($var) - 1)) == '}': |
|
|
return $var; |
|
|
|
|
| 235 |
case 'boolean': |
case 'boolean': |
| 236 |
return $var ? 'true' : 'false'; // Lowercase necessary! |
return $var ? 'true' : 'false'; // Lowercase necessary! |
| 237 |
|
|
| 238 |
case 'integer': |
case 'integer': |
| 239 |
case 'double': |
case 'double': |
| 240 |
return $var; |
return $var; |
|
|
|
|
// Handle custom JS functions. |
|
|
case substr($var, 0, strlen('function')) == 'function': |
|
|
return $var; |
|
| 241 |
|
|
| 242 |
case 'resource': |
case 'resource': |
| 243 |
case 'string': |
case 'string': |
| 260 |
$output[] = jgrowl_to_js(strval($k)) .': '. jgrowl_to_js($v); |
$output[] = jgrowl_to_js(strval($k)) .': '. jgrowl_to_js($v); |
| 261 |
} |
} |
| 262 |
return '{ '. implode(', ', $output) .' }'; |
return '{ '. implode(', ', $output) .' }'; |
| 263 |
|
|
| 264 |
|
// Handle items already in JS format. |
| 265 |
|
case substr($var, 0, 1) == '{' && substr($var, (strlen($var) - 1)) == '}': |
| 266 |
|
return $var; |
| 267 |
|
|
| 268 |
|
// Handle custom JS functions. |
| 269 |
|
case substr($var, 0, strlen('function')) == 'function': |
| 270 |
|
return $var; |
| 271 |
|
|
| 272 |
default: |
default: |
| 273 |
return 'null'; |
return 'null'; |
| 274 |
} |
} |