- Timestamp:
- 01/12/09 01:15:51 (2 years ago)
- Files:
-
- fMessaging.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fMessaging.php
r448 r479 Hide Line Numbers 3 3 * Provides session-based messaging for page-to-page communication 4 4 * 5 * @copyright Copyright (c) 2007-200 8Will Bond5 * @copyright Copyright (c) 2007-2009 Will Bond 6 6 * @author Will Bond [wb] <will@flourishlib.com> 7 7 * @license http://flourishlib.com/license … … 10 10 * @link http://flourishlib.com/fMessaging 11 11 * 12 * @version 1.0.0b 13 * @changes 1.0.0b The initial implementation [wb, 2008-03-05] 12 * @version 1.0.0b2 13 * @changes 1.0.0b2 Changed ::show() to accept more than one message name, or * for all messages [wb, 2009-01-12] 14 * @changes 1.0.0b The initial implementation [wb, 2008-03-05] 14 15 */ 15 16 class fMessaging … … 80 81 81 82 /** 82 * Retrieves a message, removes it from the session and prints it with the CSS class specified- will not print if no content83 * Retrieves a message, removes it from the session and prints it - will not print if no content 83 84 * 84 85 * The message will be printed in a `p` tag if it does not contain 85 86 * any block level HTML, otherwise it will be printed in a `div` tag. 86 87 * 87 * @param string $name The name of the message to retrieve88 * @param mixed $name The name or array of names of the message(s) to show, or `'*'` to show all 88 89 * @param string $recipient The intended recipient 89 * @param string $css_class The CSS class to use when displaying the message - if `NULL` is passed or the parameter is ommitted, `$name` will be used instead90 * @return boolean If a messagewas shown90 * @param string $css_class Overrides using the `$name` as the CSS class when displaying the message - only used if a single `$name` is specified 91 * @return boolean If one or more messages was shown 91 92 */ 92 93 static public function show($name, $recipient, $css_class=NULL) 93 94 { 94 $css_class = ($css_class === NULL) ? $name : $css_class; 95 $message = self::retrieve($name, $recipient); 96 fHTML::show($message, $css_class); 97 return !empty($message); 95 // Find all messages if * is specified 96 if (is_string($name) && $name == '*') { 97 fSession::open(); 98 $prefix = __CLASS__ . '::' . $recipient . '::'; 99 $keys = array_keys($_SESSION); 100 $name = array(); 101 foreach ($keys as $key) { 102 if (strpos($key, $prefix) === 0) { 103 $name[] = substr($key, strlen($prefix)); 104 } 105 } 106 } 107 108 // Handle showing multiple messages 109 if (is_array($name)) { 110 $shown = FALSE; 111 $names = $name; 112 foreach ($names as $name) { 113 $shown = fHTML::show( 114 self::retrieve($name, $recipient), 115 $name 116 ) || $shown; 117 } 118 return $shown; 119 } 120 121 // Handle a single message 122 return fHTML::show( 123 self::retrieve($name, $recipient), 124 ($css_class === NULL) ? $name : $css_class 125 ); 98 126 } 99 127 … … 110 138 111 139 /** 112 * Copyright (c) 2007-200 8Will Bond <will@flourishlib.com>140 * Copyright (c) 2007-2009 Will Bond <will@flourishlib.com> 113 141 * 114 142 * Permission is hereby granted, free of charge, to any person obtaining a copy
