Changeset 2865
- Timestamp:
- 11/24/08 05:24:59 (7 weeks ago)
- Location:
- trunk/htdocs/system
- Files:
-
- 3 modified
-
admin/header.php (modified) (2 diffs)
-
classes/adminhandler.php (modified) (3 diffs)
-
classes/stack.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/htdocs/system/admin/header.php
r2861 r2865 20 20 <?php 21 21 Plugins::act( 'admin_header', $this ); 22 Stack::out( 'admin_header_javascript', '<script src="%s" type="text/javascript"></script>'."\r\n");23 Stack::out( 'admin_stylesheet', '<link rel="stylesheet" type="text/css" href="%s" media="%s">'."\r\n");22 Stack::out( 'admin_header_javascript', array('Stack', 'scripts') ); 23 Stack::out( 'admin_stylesheet', array('Stack', 'styles') ); 24 24 ?> 25 25 <!--[if IE 7]> … … 69 69 70 70 <?php Plugins::act('admin_info', $theme, $page); ?> 71 -
trunk/htdocs/system/classes/adminhandler.php
r2863 r2865 2202 2202 echo json_encode($output); 2203 2203 } 2204 2204 2205 2205 public function ajax_update_groups($handler_vars) 2206 2206 { … … 2399 2399 $users= Users::get_all(); 2400 2400 $members= $group->members; 2401 foreach($users as $user) { 2401 foreach($users as $user) { 2402 2402 if(in_array($user->id, $members)) { 2403 2403 $user->membership= TRUE; … … 2716 2716 */ 2717 2717 public static function setup_stacks() { 2718 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/jquery.js" );2719 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.core.js" );2720 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.slider.js" );2721 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.tabs.js" );2722 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.sortable.js" );2723 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.resizable.js" );2724 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/jquery.spinner.js" );2725 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/jquery.color.js" );2726 Stack::add( 'admin_header_javascript', Site::get_url('habari') . "/3rdparty/humanmsg/humanmsg.js" );2727 Stack::add( 'admin_header_javascript', Site::get_url('habari') . "/3rdparty/hotkeys/jquery.hotkeys.js" );2728 Stack::add( 'admin_header_javascript', Site::get_url('admin_theme') . "/js/media.js" );2729 Stack::add( 'admin_header_javascript', Site::get_url('admin_theme') . "/js/admin.js" );2718 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/jquery.js", 'jquery' ); 2719 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.core.js", 'ui.core' ); 2720 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.slider.js", 'ui.slider' ); 2721 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.tabs.js", 'ui.tabs' ); 2722 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.sortable.js", 'ui.sortable' ); 2723 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/ui.resizable.js", 'ui.resizable' ); 2724 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/jquery.spinner.js", 'jquery.spinner' ); 2725 Stack::add( 'admin_header_javascript', Site::get_url('scripts') . "/jquery.color.js", 'jquery.color' ); 2726 Stack::add( 'admin_header_javascript', Site::get_url('habari') . "/3rdparty/humanmsg/humanmsg.js", 'humanmsg' ); 2727 Stack::add( 'admin_header_javascript', Site::get_url('habari') . "/3rdparty/hotkeys/jquery.hotkeys.js", 'jquery.hotkeys' ); 2728 Stack::add( 'admin_header_javascript', Site::get_url('admin_theme') . "/js/media.js", 'media' ); 2729 Stack::add( 'admin_header_javascript', Site::get_url('admin_theme') . "/js/admin.js", 'admin' ); 2730 2730 } 2731 2731 } -
trunk/htdocs/system/classes/stack.php
r2592 r2865 7 7 * This is useful for collecting a set of unique javascript references to output 8 8 * and then insert them at a specific point on the page. 9 * 9 * 10 10 * <code> 11 * // Add jquery to the javascript stack: 11 * // Add jquery to the javascript stack: 12 12 * Stack::add( 'template_header_javascript', Site::get_url('scripts') . '/jquery.js', 'jquery' ); 13 13 * 14 14 * // Add stylesheet to theme_stylesheet stack with media type 15 15 * Stack::add( 'template_stylesheet', array( Site::get_url('theme') . '/style.css', 'screen' ), 'style' ); 16 * 16 * 17 17 * // Output the javascript stack: 18 18 * Stack::out( 'template_header_javascript', '<script src="%s" type="text/javascript"></script>' ); … … 20 20 * // Output the theme_stylesheet stack: 21 21 * Stack::out( 'template_stylesheet', '<link rel="stylesheet" type="text/css" href="%s" media="%s">' ); 22 * </code> 22 * </code> 23 23 * 24 24 * @package Habari … … 28 28 { 29 29 private static $stacks = array(); 30 30 31 31 /** 32 32 * Private constructor for Stack. 33 * Stack objects should only be created using the static 33 * Stack objects should only be created using the static 34 34 * method Static::create_stack(), or one of the methods that 35 * adds a value directly to a stack. This prevents multiple Stack 35 * adds a value directly to a stack. This prevents multiple Stack 36 36 * objects from being created with the same name. 37 * 37 * 38 38 * @param mixed $input An array or ArrayObject to create the stack from. 39 39 * @return array The created stack … … 48 48 * @param string $stack_name The name of the stack to return 49 49 * @return Stack The requested stack 50 **/ 50 **/ 51 51 public static function get_named_stack( $stack_name ) 52 52 { … … 58 58 } 59 59 } 60 60 61 61 /** 62 62 * Check for the existence of a given stack item. … … 67 67 */ 68 68 public static function has ( $stack_name, $value_name ) { 69 69 70 70 // get the stack 71 71 $stack = self::get_named_stack( $stack_name ); 72 72 73 73 if ( isset( $stack[ $value_name ] ) ) { 74 74 return true; … … 77 77 return false; 78 78 } 79 80 } 81 79 80 } 81 82 82 /** 83 83 * Get a single item from a given stack. … … 89 89 */ 90 90 public static function get_item ( $stack_name, $value_name, $default_value = null ) { 91 91 92 92 // get the stack 93 93 $stack = self::get_named_stack( $stack_name ); 94 94 95 95 if ( isset( $stack[ $value_name ] ) ) { 96 96 return $stack[ $value_name ]; … … 99 99 return $default_value; 100 100 } 101 102 } 103 101 102 } 103 104 104 /** 105 105 * Creates and retreives a named stack instance 106 106 * @param string $stack_name The name of the stack to create and return 107 107 * @return array The created stack 108 **/ 108 **/ 109 109 public static function create_stack( $stack_name ) 110 110 { … … 115 115 return self::$stacks[$stack_name]; 116 116 } 117 117 118 118 /** 119 119 * Add a value to a stack … … 121 121 * @param mixed $value The value to add 122 122 * @param string $value_name The name of the value to add 123 * @return array The stack that was added to 124 **/ 125 public static function add( $stack_name, $value, $value_name = null )123 * @return array The stack that was added to 124 **/ 125 public static function add( $stack_name, $value, $value_name = null, $after = null ) 126 126 { 127 127 $stack = self::get_named_stack( $stack_name ); 128 128 $value_name = $value_name ? $value_name : md5( serialize( $value ) ); 129 $stack[$value_name]= $value; 129 if(!is_null($after)) { 130 if(!is_array($after)) { 131 $after = array($after); 132 } 133 $newstack = array(); 134 foreach($stack as $k => $v) { 135 $newstack[$k] = $v; 136 $inserted = false; 137 if(in_array($k, $after)) { 138 unset($after[array_search($k, $after)]); 139 if(count($after) == 0) { 140 $newstack[$value_name] = $value; 141 $inserted = true; 142 } 143 } 144 } 145 if(!$inserted) { 146 $newstack[$value_name] = $value; 147 } 148 $stack = $newstack; 149 } 150 else { 151 $stack[$value_name]= $value; 152 } 130 153 self::$stacks[$stack_name]= $stack; 131 154 return $stack; 132 155 } 133 156 134 157 /** 135 158 * Remove a value to a stack 136 159 * @param string $stack_name The name of the stack 137 160 * @param string $value_name The name of the value to remove 138 * @return array The rest of the stack, post-remove 139 **/ 161 * @return array The rest of the stack, post-remove 162 **/ 140 163 public static function remove( $stack_name, $value_name ) 141 164 { … … 147 170 return $stack; 148 171 } 149 172 150 173 /** 151 174 * Returns all of the values of the stack 152 175 * @param string $stack_name The name of the stack to output 153 176 * @param mixed $format A printf-style formatting string or callback used to output each stack element 154 **/ 177 **/ 155 178 public static function get( $stack_name, $format = null) 156 179 { … … 160 183 foreach( $stack as $element ) { 161 184 if ( is_callable($format) ) { 162 $out.= call_user_func_array( $format, (array) $element ); 185 $out.= call_user_func_array( $format, (array) $element ); 163 186 } 164 187 elseif ( is_string( $format ) ) { … … 171 194 return $out; 172 195 } 173 196 174 197 /** 175 198 * Outputs all of the values of the stack 176 199 * @param string $stack_name The name of the stack to output 177 200 * @param mixed $format A printf-style formatting string or callback used to output each stack element 178 **/ 201 **/ 179 202 public static function out( $stack_name, $format = null) 180 203 { 181 204 echo self::get( $stack_name, $format ); 182 205 } 206 207 public static function scripts( $element ) 208 { 209 if(strpos($element, 'http://') === 0 && strpos($element, "\n") === FALSE) { 210 $output = sprintf( '<script src="%s" type="text/javascript"></script>'."\r\n", $element); 211 } 212 else { 213 $output = sprintf( '<script type="text/javascript">%s</script>'."\r\n", $element); 214 } 215 return $output; 216 } 217 218 public static function styles( $element, $typename ) 219 { 220 if(strpos($element, 'http://') === 0 && strpos($element, "\n") === FALSE) { 221 $output = sprintf( '<link rel="stylesheet" type="text/css" href="%s" media="%s">'."\r\n", $element, $typename); 222 } 223 else { 224 $output = sprintf( '<style type="text/stylesheet" media="%s">%s</style>'."\r\n", $typename, $element); 225 } 226 return $output; 227 } 183 228 } 184 229
