[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.8 4 * Copyright 2014 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybb.com 7 * License: http://www.mybb.com/about/license 8 * 9 */ 10 11 /** 12 * Generate a data grid/table. 13 */ 14 class DefaultTable 15 { 16 /** 17 * @var array Array of cells for the current row. 18 */ 19 private $_cells = array(); 20 21 /** 22 * @var array Array of rows for the current table. 23 */ 24 private $_rows = array(); 25 26 /** 27 * @var array Array of headers for the current table. 28 */ 29 private $_headers = array(); 30 31 /** 32 * Construct an individual cell for this table. 33 * 34 * @param string $data The HTML content for this cell. 35 * @param array $extra Array of extra information about this cell (class, id, colspan, rowspan, width) 36 */ 37 function construct_cell($data, $extra=array()) 38 { 39 $this->_cells[] = array("data" => $data, "extra" => $extra); 40 } 41 42 /** 43 * Construct a row from the earlier defined constructed cells for the table. 44 * 45 * @param array $extra Array of extra information about this row (class, id) 46 */ 47 function construct_row($extra = array()) 48 { 49 $i = 1; 50 $cells = ''; 51 52 // We construct individual cells here 53 foreach($this->_cells as $key => $cell) 54 { 55 $cells .= "\t\t\t<td"; 56 57 if(!isset($cell['extra']['class'])) 58 { 59 $cell['extra']['class'] = ''; 60 } 61 62 if($key == 0) 63 { 64 $cell['extra']['class'] .= " first"; 65 } 66 elseif(!isset($this->_cells[$key+1])) 67 { 68 $cell['extra']['class'] .= " last"; 69 } 70 if($i == 2) 71 { 72 $cell['extra']['class'] .= " alt_col"; 73 $i = 0; 74 } 75 $i++; 76 if($cell['extra']['class']) 77 { 78 $cells .= " class=\"".trim($cell['extra']['class'])."\""; 79 } 80 if(isset($cell['extra']['style'])) 81 { 82 $cells .= " style=\"".$cell['extra']['style']."\""; 83 } 84 if(isset($cell['extra']['id'])) 85 { 86 $cells .= " id=\"".$cell['extra']['id']."\""; 87 } 88 if(isset($cell['extra']['colspan']) && $cell['extra']['colspan'] > 1) 89 { 90 $cells .= " colspan=\"".$cell['extra']['colspan']."\""; 91 } 92 if(isset($cell['extra']['rowspan']) && $cell['extra']['rowspan'] > 1) 93 { 94 $cells .= " rowspan=\"".$cell['extra']['rowspan']."\""; 95 } 96 if(isset($cell['extra']['width'])) 97 { 98 $cells .= " width=\"".$cell['extra']['width']."\""; 99 } 100 $cells .= ">"; 101 $cells .= $cell['data']; 102 $cells .= "</td>\n"; 103 } 104 $data['cells'] = $cells; 105 $data['extra'] = $extra; 106 $this->_rows[] = $data; 107 108 $this->_cells = array(); 109 } 110 111 /** 112 * return the cells of a row for the table based row. 113 * 114 * @param string $row_id The id of the row you want to give it. 115 * @param boolean $return Whether or not to return or echo the resultant contents. 116 * @return string The output of the row cells (optional). 117 */ 118 function output_row_cells($row_id, $return=false) 119 { 120 $row = $this->_rows[$row_id]['cells']; 121 122 if(!$return) 123 { 124 echo $row; 125 } 126 else 127 { 128 return $row; 129 } 130 } 131 132 /** 133 * Count the number of rows in the table. Useful for displaying a 'no rows' message. 134 * 135 * @return int The number of rows in the table. 136 */ 137 function num_rows() 138 { 139 return count($this->_rows); 140 } 141 142 /** 143 * Construct a header cell for this table. 144 * 145 * @param string $data The HTML content for this header cell. 146 * @param array $extra Array of extra information for this header cell (class, style, colspan, width) 147 */ 148 function construct_header($data, $extra=array()) 149 { 150 $this->_headers[] = array("data" => $data, "extra" => $extra); 151 } 152 153 /** 154 * Output this table to the browser. 155 * 156 * @param string $heading The heading for this table. 157 * @param int $border The border width for this table. 158 * @param string $class The class for this table. 159 * @param boolean $return Whether or not to return or echo the resultant contents. 160 * @return string The output of the row cells (optional). 161 */ 162 function output($heading="", $border=1, $class="general", $return=false) 163 { 164 if($return == true) 165 { 166 return $this->construct_html($heading, $border, $class); 167 } 168 else 169 { 170 echo $this->construct_html($heading, $border, $class); 171 } 172 } 173 174 /** 175 * Fetch the built HTML for this table. 176 * 177 * @param string $heading The heading for this table. 178 * @param int $border The border width for this table. 179 * @param string $class The class for this table. 180 * @param string $table_id The id for this table. 181 * @return string The built HTML. 182 */ 183 function construct_html($heading="", $border=1, $class=null, $table_id="") 184 { 185 $table = ''; 186 if($border == 1) 187 { 188 $table .= "<div class=\"border_wrapper\">\n"; 189 if($heading != "") 190 { 191 $table .= " <div class=\"title\">".$heading."</div>\n"; 192 } 193 } 194 $table .= "<table"; 195 if(!is_null($class)) 196 { 197 if(!$class) 198 { 199 $class = "general"; 200 } 201 $table .= " class=\"".$class."\""; 202 } 203 if($table_id != "") 204 { 205 $table .= " id=\"".$table_id."\""; 206 } 207 $table .= " cellspacing=\"0\">\n"; 208 if($this->_headers) 209 { 210 $table .= "\t<thead>\n"; 211 $table .= "\t\t<tr>\n"; 212 foreach($this->_headers as $key => $data) 213 { 214 $table .= "\t\t\t<th"; 215 if(!isset($data['extra']['class'])) 216 { 217 $data['extra']['class'] = ''; 218 } 219 if($key == 0) 220 { 221 $data['extra']['class'] .= " first"; 222 } 223 elseif(!isset($this->_headers[$key+1])) 224 { 225 $data['extra']['class'] .= " last"; 226 } 227 if(!empty($data['extra']['class'])) 228 { 229 $table .= " class=\"".$data['extra']['class']."\""; 230 } 231 if(isset($data['extra']['style'])) 232 { 233 $table .= " style=\"".$data['extra']['style']."\""; 234 } 235 if(isset($data['extra']['width'])) 236 { 237 $table .= " width=\"".$data['extra']['width']."\""; 238 } 239 if(isset($data['extra']['colspan']) && $data['extra']['colspan'] > 1) 240 { 241 $table .= " colspan=\"".$data['extra']['colspan']."\""; 242 } 243 $table .= ">".$data['data']."</th>\n"; 244 } 245 $table .= "\t\t</tr>\n"; 246 $table .= "\t</thead>\n"; 247 } 248 $table .= "\t<tbody>\n"; 249 $i = 1; 250 foreach($this->_rows as $key => $table_row) 251 { 252 $table .= "\t\t<tr"; 253 if(isset($table_row['extra']['id'])) 254 { 255 $table .= " id=\"{$table_row['extra']['id']}\""; 256 } 257 258 if(!isset($table_row['extra']['class'])) 259 { 260 $table_row['extra']['class'] = ''; 261 } 262 263 if($key == 0) 264 { 265 $table_row['extra']['class'] .= " first"; 266 } 267 else if(!isset($this->_rows[$key+1])) 268 { 269 $table_row['extra']['class'] .= " last"; 270 } 271 if($i == 2 && !isset($table_row['extra']['no_alt_row'])) 272 { 273 $table_row['extra']['class'] .= " alt_row"; 274 $i = 0; 275 } 276 $i++; 277 if($table_row['extra']['class']) 278 { 279 $table .= " class=\"".trim($table_row['extra']['class'])."\""; 280 } 281 $table .= ">\n"; 282 $table .= $table_row['cells']; 283 $table .= "\t\t</tr>\n"; 284 } 285 $table .= "\t</tbody>\n"; 286 $table .= "</table>\n"; 287 // Clean up 288 $this->_cells = $this->_rows = $this->_headers = array(); 289 if($border == 1) 290 { 291 $table .= "</div>"; 292 } 293 return $table; 294 } 295 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |