| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 # MantisBT - A PHP based bugtracking system 3 4 # MantisBT is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # MantisBT is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Collapse API 19 * 20 * @package CoreAPI 21 * @subpackage CollapseAPI 22 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 23 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net 24 * @link http://www.mantisbt.org 25 * 26 * @uses authentication_api.php 27 * @uses config_api.php 28 * @uses constant_inc.php 29 * @uses current_user_api.php 30 * @uses gpc_api.php 31 * @uses tokens_api.php 32 * @uses utility_api.php 33 */ 34 35 require_api( 'authentication_api.php' ); 36 require_api( 'config_api.php' ); 37 require_api( 'constant_inc.php' ); 38 require_api( 'current_user_api.php' ); 39 require_api( 'gpc_api.php' ); 40 require_api( 'tokens_api.php' ); 41 require_api( 'utility_api.php' ); 42 43 /** 44 * 45 * @global string $g_current_collapse_section 46 */ 47 $g_current_collapse_section = null; 48 49 /** 50 * 51 * @global bool $g_open_collapse_section 52 */ 53 $g_open_collapse_section = false; 54 55 /** 56 * 57 * @global string $g_collapse_cache_token 58 */ 59 $g_collapse_cache_token = null; 60 61 /** 62 * Marks the beginning of a collapse block's open phase. 63 * This will be visible if the block is expanded, or if 64 * javascript is disabled. 65 * @param string Collapse block name 66 * @param string Collapse block section 67 */ 68 function collapse_open( $p_name, $p_section = '' ) { 69 global $g_current_collapse_section, $g_open_collapse_section; 70 71 $t_block = ( is_blank( $p_section ) ? $p_name : $p_section . '_' . $p_name ); 72 $t_display = collapse_display( $t_block ); 73 74 # make sure no other collapse section is started 75 if( $g_current_collapse_section !== null ) { 76 trigger_error( ERROR_GENERIC, ERROR ); 77 } 78 79 $g_open_collapse_section = true; 80 $g_current_collapse_section = $t_block; 81 82 $t_div_id = $t_block . '_open'; 83 echo "\n<div id=\"", $t_div_id, '"', ( $t_display ? ' class="collapse-open"' : ' class="collapse-closed"' ), '>'; 84 } 85 86 /** 87 * Marks the end of a collapse block's open phase and the beginning 88 * of the block's closed phase. Thi will only be visible if the 89 * block have been collapsed and javascript is enabled. 90 * @param string Collapse block name 91 * @param string Collapse block section 92 */ 93 function collapse_closed( $p_name, $p_section = '' ) { 94 global $g_current_collapse_section, $g_open_collapse_section; 95 96 $t_block = ( is_blank( $p_section ) ? $p_name : $p_section . '_' . $p_name ); 97 $t_display = !collapse_display( $t_block ); 98 99 # Make sure a section is opened, and it is the same section. 100 if( $t_block !== $g_current_collapse_section ) { 101 trigger_error( ERROR_GENERIC, ERROR ); 102 } 103 104 echo '</div>'; 105 106 $g_open_collapse_section = false; 107 108 ob_start(); 109 110 $t_div_id = $t_block . '_closed'; 111 echo "\n<div id=\"", $t_div_id, '"', ( $t_display ? ' class="collapse-open"' : ' class="collapse-closed"' ), '>'; 112 } 113 114 /** 115 * Marks the location where a +/- icon is placed in output 116 * for the user to toggle the collapse block status. 117 * This should appear in both the open and closed phase of a block. 118 * @param string Collapse block name 119 * @param string Collapse block section 120 */ 121 function collapse_icon( $p_name, $p_section = '' ) { 122 if( OFF == config_get( 'use_javascript' ) ) { 123 return; 124 } 125 126 $t_block = ( is_blank( $p_section ) ? $p_name : $p_section . '_' . $p_name ); 127 128 global $g_open_collapse_section; 129 130 if( $g_open_collapse_section === true ) { 131 $t_icon = 'minus.png'; 132 $t_alt = '-'; 133 $t_id = $p_name . '_open_link'; 134 } else { 135 $t_icon = 'plus.png'; 136 $t_alt = '+'; 137 $t_id = $p_name. '_closed_link'; 138 } 139 140 echo '<a id="', $t_id, '" href="" class="collapse-link"><img src="images/', $t_icon, '" alt="', $t_alt, '" /></a> '; 141 } 142 143 /** 144 * Marks the end of a collaps block's closed phase. 145 * Closed phase output is discarded if javascript is disabled. 146 * @param string Collapse block name 147 * @param string Collapse block section 148 */ 149 function collapse_end( $p_name, $p_section = '' ) { 150 global $g_current_collapse_section, $g_open_collapse_section; 151 152 $t_block = ( is_blank( $p_section ) ? $p_name : $p_section . '_' . $p_name ); 153 $t_display = collapse_display( $t_block ); 154 155 # Make sure a section is opened, and it is the same section. 156 if( $t_block !== $g_current_collapse_section ) { 157 ob_end_clean(); 158 trigger_error( ERROR_GENERIC, ERROR ); 159 } 160 161 echo '</div>'; 162 163 $g_open_collapse_section = false; 164 165 if( ON == config_get( 'use_javascript' ) ) { 166 ob_end_flush(); 167 } else { 168 ob_end_clean(); 169 } 170 171 $g_current_collapse_section = null; 172 } 173 174 /** 175 * Determine if a block should be displayed open by default. 176 * @param string Collapse block 177 * @return bool 178 */ 179 function collapse_display( $p_block ) { 180 global $g_collapse_cache_token; 181 182 if( !isset( $g_collapse_cache_token[$p_block] ) || OFF == config_get( 'use_javascript' ) ) { 183 return true; 184 } 185 186 return( true == $g_collapse_cache_token[$p_block] ); 187 } 188 189 /** 190 * Cache collapse API data from the database for the current user. 191 * If the collapse cookie has been set, grab the changes and resave 192 * the token, or touch it otherwise. 193 */ 194 function collapse_cache_token() { 195 global $g_collapse_cache_token; 196 197 if( !auth_is_user_authenticated() || current_user_is_anonymous() ) { 198 $g_collapse_cache_token = array(); 199 return; 200 } 201 202 if( isset( $g_collapse_cache_token ) ) { 203 return; 204 } 205 206 $t_user_id = auth_get_current_user_id(); 207 $t_token = token_get_value( TOKEN_COLLAPSE ); 208 209 if( !is_null( $t_token ) ) { 210 $t_data = unserialize( $t_token ); 211 } else { 212 $t_data = array(); 213 } 214 215 $g_collapse_cache_token = $t_data; 216 217 $t_cookie = gpc_get_cookie( 'MANTIS_collapse_settings', '' ); 218 219 if( false !== $t_cookie && !is_blank( $t_cookie ) ) { 220 $t_update = false; 221 $t_data = explode( '|', $t_cookie ); 222 223 foreach( $t_data as $t_pair ) { 224 $t_pair = explode( ',', $t_pair ); 225 226 if( false !== $t_pair && count( $t_pair ) == 2 ) { 227 $g_collapse_cache_token[$t_pair[0]] = ( true == $t_pair[1] ); 228 $t_update = true; 229 } 230 } 231 232 if( $t_update ) { 233 $t_token = serialize( $g_collapse_cache_token ); 234 token_set( TOKEN_COLLAPSE, $t_token, TOKEN_EXPIRY_COLLAPSE ); 235 } else { 236 token_touch( TOKEN_COLLAPSE ); 237 } 238 239 gpc_clear_cookie( 'MANTIS_collapse_settings' ); 240 } 241 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |