| [ Index ] |
PHP Cross Reference of PageLines Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * PageLinesLayout 4 * 5 * Class for managing content layout 6 * 7 * @package PageLines Framework 8 * @subpackage Layout 9 * 10 * @since 1.0 11 */ 12 class PageLinesLayout { 13 14 // BUILD THE PAGELINES OBJECT 15 16 /** 17 * 18 * @TODO document 19 * 20 */ 21 function __construct($layout_mode = null) { 22 23 $this->builder = new stdClass; 24 $this->clip = new stdClass; 25 $this->sidebar_wrap = new stdClass; 26 $this->column_wrap = new stdClass; 27 $this->dynamic_grid = new stdClass; 28 $this->margin = new stdClass; 29 $this->content = new stdClass; 30 $this->gutter = new stdClass; 31 $this->sidebar1 = new stdClass; 32 $this->sidebar2 = new stdClass; 33 $this->main_content = new stdClass; 34 $this->hidden = new stdClass; 35 36 $this->builder->width = 1400; 37 /* 38 Get the layout map from DB, or use default 39 */ 40 $this->get_layout_map(); 41 42 /* 43 If layout mode isn't set, then use the saved default mode. 44 */ 45 if( isset($layout_mode) ) 46 $this->layout_mode = $layout_mode; 47 elseif ( isset($this->layout_map['saved_layout']) && !empty($this->layout_map['saved_layout']) ) 48 $layout_mode = $this->layout_map['saved_layout']; 49 else 50 $layout_mode = ( ploption( 'layout_default' ) ) ? ploption( 'layout_default' ) : 'one-sidebar-right'; 51 52 $this->build_layout($layout_mode); 53 } 54 55 56 /** 57 * 58 * @TODO document 59 * 60 */ 61 function build_layout($layout_mode){ 62 63 /* 64 Set the current pages layout 65 */ 66 $this->layout_mode = $layout_mode; 67 68 /* 69 Get number of columns 70 */ 71 $this->set_columns(); 72 73 /* 74 Set layout dimensions 75 */ 76 $this->set_layout_data(); 77 78 /* 79 Set wrap dimensions for use on page 80 */ 81 $this->set_wrap_dimensions(); 82 83 /* 84 Set scaled dimensions and convert for use in the JS builder 85 */ 86 $this->set_builder_dimensions(); 87 88 89 } 90 91 92 /** 93 * 94 * @TODO document 95 * 96 */ 97 function set_columns(){ 98 if($this->layout_mode == 'two-sidebar-center' || $this->layout_mode == 'two-sidebar-left' || $this->layout_mode == 'two-sidebar-right') 99 $this->num_columns = 3; 100 elseif($this->layout_mode == 'one-sidebar-left' || $this->layout_mode == 'one-sidebar-right') 101 $this->num_columns = 2; 102 else 103 $this->num_columns = 1; 104 } 105 106 107 108 /** 109 * 110 * @TODO document 111 * 112 */ 113 function get_layout_map(){ 114 115 $db_layout_map = ploption('layout'); 116 117 $this->layout_map = ( $db_layout_map && is_array($db_layout_map) ) ? $db_layout_map : $this->default_layout_setup(); 118 119 120 121 } 122 123 124 125 126 /** 127 * 128 * @TODO document 129 * 130 */ 131 function default_layout_setup(){ 132 133 $this->content->width = 1100; 134 $this->content->percent = $this->get_content_percent($this->content->width); 135 136 $this->gutter->width = 20; 137 138 $def_main_two = 780; 139 $def_sb_two = 320; 140 141 $def_main_three = 620; 142 $def_sb_three = 240; 143 144 $default_map = array( 145 'saved_layout' => 'one-sidebar-right', 146 'last_edit' => 'one-sidebar-right', 147 'content_width' => $this->content->width, 148 'responsive_width' => $this->content->percent, 149 'one-sidebar-right' => array( 150 'maincolumn_width' => $def_main_two, 151 'primarysidebar_width' => $def_sb_two, 152 'gutter_width' => $this->gutter->width, 153 'content_width' => $this->content->width 154 ), 155 'one-sidebar-left' => array( 156 'maincolumn_width' => $def_main_two, 157 'primarysidebar_width' => $def_sb_two, 158 'gutter_width' => $this->gutter->width, 159 'content_width' => $this->content->width 160 ), 161 'two-sidebar-right' => array( 162 'maincolumn_width' => $def_main_three, 163 'primarysidebar_width' => $def_sb_three, 164 'gutter_width' => $this->gutter->width, 165 'content_width' => $this->content->width 166 ), 167 'two-sidebar-left' => array( 168 'maincolumn_width' => $def_main_three, 169 'primarysidebar_width' => $def_sb_three, 170 'gutter_width' => $this->gutter->width, 171 'content_width' => $this->content->width 172 ), 173 'two-sidebar-center' => array( 174 'maincolumn_width' => $def_main_three, 175 'primarysidebar_width' => $def_sb_three, 176 'gutter_width' => $this->gutter->width, 177 'content_width' => $this->content->width 178 ), 179 'fullwidth' => array( 180 'maincolumn_width' => $this->content->width, 181 'primarysidebar_width' => 0, 182 'gutter_width' => 0, 183 'content_width' => 0 184 ) 185 ); 186 187 188 return $default_map; 189 } 190 191 192 /** 193 * 194 * @TODO document 195 * 196 */ 197 function get_content_percent( $content_width ){ 198 return ( $content_width / $this->builder->width ) * 100; 199 } 200 201 202 203 /** 204 * 205 * @TODO document 206 * 207 */ 208 function set_layout_data(){ 209 210 // Text & IDs 211 $this->hidden->text = ''; 212 $this->hidden->id = 'hidden'; 213 214 $this->main_content->text = __( 'Main Column', 'pagelines' ); 215 $this->main_content->id = 'layout-main-content'; 216 217 $this->sidebar1->text = 'SB1'; 218 $this->sidebar1->id = 'layout-sidebar-1'; 219 220 $this->sidebar2->text = 'SB2'; 221 $this->sidebar2->id = 'layout-sidebar-2'; 222 223 $this->gutter->width = 30; 224 225 $this->fudgefactor = 24; 226 227 $this->hidden->width = 0; 228 229 $this->content->width = $this->layout_map['content_width']; 230 $this->content->percent = $this->get_content_percent( $this->layout_map['content_width'] ); 231 232 foreach($this->layout_map as $layoutmode => $settings){ 233 if($this->layout_mode == $layoutmode && ($layoutmode == 'one-sidebar-right' || $layoutmode == 'one-sidebar-left')){ 234 235 //Account for javascript saving of other layout type 236 $this->main_content->width = $settings['maincolumn_width']; 237 $this->sidebar1->width = $this->content->width - $settings['maincolumn_width']; 238 239 } elseif($this->layout_mode == $layoutmode && ($layoutmode == 'fullwidth')){ 240 241 //Account for javascript saving of other layout type 242 $this->main_content->width = $this->content->width; 243 $this->sidebar1->width = 0; 244 245 }elseif($this->layout_mode == $layoutmode) { 246 247 $this->main_content->width = $settings['maincolumn_width']; 248 $this->sidebar1->width = $settings['primarysidebar_width']; 249 250 } 251 } 252 253 $this->margin->width = ($this->builder->width - $this->content->width)/2 - ($this->fudgefactor - 1); 254 255 $this->sidebar2->width = $this->content->width - $this->main_content->width - $this->sidebar1->width; 256 257 $this->dynamic_grid->width = $this->content->width/12; 258 259 } 260 261 262 263 /** 264 * 265 * @TODO document 266 * 267 */ 268 function set_wrap_dimensions(){ 269 if($this->layout_mode == 'two-sidebar-center'){ 270 $this->column_wrap->width = $this->main_content->width + $this->sidebar1->width; 271 $this->sidebar_wrap->width = $this->sidebar2->width; 272 273 $this->clip->width = ($this->main_content->width - (3 * $this->gutter->width))/2 ; 274 275 }elseif($this->layout_mode == 'two-sidebar-right' || $this->layout_mode == 'two-sidebar-left'){ 276 277 $this->column_wrap->width = $this->main_content->width; 278 $this->sidebar_wrap->width = $this->sidebar1->width + $this->sidebar2->width; 279 $this->clip->width = ($this->main_content->width - (2 * $this->gutter->width))/2 ; 280 281 }elseif($this->layout_mode == 'one-sidebar-right' || $this->layout_mode == 'one-sidebar-left'){ 282 $this->column_wrap->width = $this->main_content->width; 283 $this->sidebar_wrap->width = $this->sidebar1->width; 284 285 $this->clip->width = ($this->main_content->width - (2 * $this->gutter->width))/2 ; 286 }else{ 287 $this->sidebar_wrap->width = 0; 288 $this->column_wrap->width = $this->main_content->width; 289 $this->clip->width = ($this->main_content->width - (1 * $this->gutter->width))/2 ; 290 } 291 } 292 293 294 /** 295 * 296 * @TODO document 297 * 298 */ 299 function set_builder_dimensions(){ 300 301 $this->builder->bwidth = $this->downscale($this->builder->width); 302 $this->content->bwidth = $this->downscale($this->content->width); 303 $this->gutter->bwidth = $this->downscale($this->gutter->width); 304 $this->margin->bwidth = $this->downscale($this->margin->width); 305 $this->main_content->bwidth = $this->downscale($this->main_content->width); 306 $this->sidebar1->bwidth = $this->downscale($this->sidebar1->width); 307 $this->sidebar2->bwidth = $this->downscale($this->sidebar2->width); 308 309 $this->hidden->bwidth = 0; 310 311 /* 312 Convert builder dimensions to dimensions the plugin understands 313 */ 314 $this->builder_inner_directions(); 315 } 316 317 318 /** 319 * 320 * @TODO document 321 * 322 */ 323 function builder_inner_directions(){ 324 if($this->layout_mode == 'two-sidebar-right'){ 325 326 $this->west = $this->main_content; 327 $this->center = $this->sidebar1; 328 $this->east = $this->sidebar2; 329 }elseif($this->layout_mode == 'two-sidebar-left'){ 330 331 $this->east = $this->main_content; 332 $this->west = $this->sidebar1; 333 $this->center = $this->sidebar2; 334 }elseif($this->layout_mode == 'two-sidebar-center'){ 335 336 $this->east = $this->sidebar2; 337 $this->west = $this->sidebar1; 338 $this->center = $this->main_content; 339 }elseif($this->layout_mode == 'one-sidebar-right'){ 340 $this->east = $this->sidebar1; 341 $this->west = $this->hidden; 342 $this->center = $this->main_content; 343 } 344 elseif($this->layout_mode == 'one-sidebar-left'){ 345 $this->east = $this->hidden; 346 $this->west = $this->sidebar1; 347 $this->center = $this->main_content; 348 }elseif($this->layout_mode == 'fullwidth'){ 349 $this->east = $this->hidden; 350 $this->west = $this->hidden; 351 $this->center = $this->main_content; 352 }else{ 353 echo 'There was an issue setting layout. Please reset your settings.'; 354 } 355 } 356 357 358 /** 359 * 360 * @TODO document 361 * 362 */ 363 function downscale($actual_pixels, $ratio = 2){ 364 return floor($actual_pixels / $ratio); 365 } 366 367 368 369 /** 370 * 371 * @TODO document 372 * 373 */ 374 function get_layout_inline(){ 375 376 $l = $this->calculate_dimensions($this->layout_mode); 377 $mode = '.'.$this->layout_mode.' '; 378 $css = ''; 379 $c = $this->content->width; 380 $p = $this->content->percent; 381 382 // Selectors 383 384 // Setup Page Width 385 $page_width_array = apply_filters( 'pl_page_width', array('body.fixed_width #page', 'body.fixed_width #footer', 'body.canvas .page-canvas') ); 386 $page_width_sel = join(',', $page_width_array); 387 388 // Setup Content Width 389 $content_width_array = apply_filters( 'pl_content_width', array('#site .content', '#footer .content') ); 390 $content_width_sel = join(',', $content_width_array); 391 392 393 // Options 394 $layout_handling = ploption('layout_handling'); 395 $design_mode = ploption('site_design_mode'); 396 397 $contained = ($design_mode == 'fixed_width' && !pl_is_disabled('color_control')) ? true : false; 398 399 400 // Set CSS for content and page width 401 if( $layout_handling == 'percent'){ 402 403 if($contained){ 404 $css .= sprintf($page_width_sel . '{ width: %s%%;}', $p); 405 $css .= sprintf($content_width_sel . '{ width: %s%%; }', '100'); 406 } else 407 $css .= sprintf($content_width_sel . '{ width: %s%%; }', $p); 408 409 } elseif( $layout_handling == 'pixels' ){ 410 $css .= sprintf($page_width_sel . '{ max-width:%spx; }', $c); 411 $css .= sprintf($content_width_sel . '{ width: 100%%; max-width:%spx;}', $c); 412 }else{ 413 $css .= sprintf($page_width_sel . '{ max-width:%spx; }', $c); 414 $css .= sprintf($content_width_sel . '{ width:%spx;}', $c); 415 } 416 417 // Set CSS for inner elements based on mode 418 $content_id = apply_filters('pl_content_id', '#pagelines_content'); 419 420 $main_col_id = apply_filters('pl_main_id', '#column-main'); 421 422 foreach(get_the_layouts() as $mode){ 423 424 $l = $this->calculate_dimensions($mode); 425 426 $mode_selector = '.'.$mode; 427 428 $css .= sprintf('%1$s %3$s %4$s{ %2$s }', $mode_selector, $l['main'], $content_id, $main_col_id); 429 $css .= sprintf('%1$s %3$s #sidebar1{ %2$s }', $mode_selector, $l['sb1'], $content_id); 430 $css .= sprintf('%1$s %3$s #sidebar2{ %2$s }', $mode_selector, $l['sb2'], $content_id); 431 $css .= sprintf('%1$s %3$s #column-wrap{ %2$s }', $mode_selector, $l['colwrap'], $content_id); 432 $css .= sprintf('%1$s %3$s #sidebar-wrap{ %2$s }', $mode_selector, $l['sbwrap'], $content_id); 433 434 } 435 436 return $css; 437 } 438 439 440 /** 441 * 442 * @TODO document 443 * 444 */ 445 function calculate_dimensions( $layout_mode ){ 446 447 $save_mode = $this->layout_mode; 448 449 $this->build_layout($layout_mode); 450 451 $l = array(); 452 453 /* (target / context)*100 = percent-result */ 454 455 $l['colwrap'] = $this->get_width( $this->column_wrap->width, $this->content->width ); 456 $l['sbwrap'] = $this->get_width( $this->sidebar_wrap->width, $this->content->width ); 457 458 $l['main'] = $this->get_width( $this->main_content->width, $this->column_wrap->width ); 459 460 $l['sb2'] = $this->get_width( $this->sidebar2->width, $this->sidebar_wrap->width ); 461 462 if($layout_mode == 'two-sidebar-center') 463 $l['sb1'] = $this->get_width( $this->sidebar1->width, $this->column_wrap->width ); 464 else 465 $l['sb1'] = $this->get_width( $this->sidebar1->width, $this->sidebar_wrap->width ); 466 467 468 $this->layout_mode = $save_mode; 469 $this->build_layout($save_mode); 470 471 return $l; 472 } 473 474 475 /** 476 * 477 * @TODO document 478 * 479 */ 480 function get_width($target, $context){ 481 return sprintf( 'width:%s%%;', ($context != 0 ) ? ( $target / $context ) * 100 : 0 ); 482 } 483 484 485 } 486 487 //********* END OF LAYOUT CLASS *********// 488 489 490 /** 491 * PageLines Layout Object 492 * @global object $pagelines_template 493 * @since 1.0.0 494 */ 495 function build_pagelines_layout(){ 496 497 global $pagelines_layout; 498 global $post; 499 500 $post_id = (isset($post->ID)) ? $post->ID : null; 501 502 $oset = array( 'post_id' => $post_id ); 503 504 $page_layout = (ploption( '_pagelines_layout_mode', $oset)) ? ploption( '_pagelines_layout_mode', $oset) : null; 505 506 $pagelines_layout = new PageLinesLayout( $page_layout ); 507 } 508 509 510 /** 511 * 512 * Sets Content Width for Large images when adding media 513 * 514 * @package PageLines Framework 515 * @subpackage Functions Library 516 * @since 1.2.3 517 * 518 */ 519 function pagelines_current_page_content_width() { 520 521 global $pagelines_layout; 522 global $content_width; 523 global $post; 524 525 $mode = pagelines_layout_mode(); 526 527 $c_width = $pagelines_layout->layout_map[$mode]['maincolumn_width']; 528 529 if ( !isset( $content_width ) ) $content_width = $c_width - 45; 530 531 } 532 533 /** 534 * PageLines Layout Mode 535 * 536 * Returns Current Layout Mode 537 * 538 * @package PageLines Framework 539 * @subpackage Functions Library 540 * 541 * @since 1.0.0 542 * 543 * @return mixed 544 */ 545 function pagelines_layout_mode() { 546 547 global $pagelines_layout; 548 return $pagelines_layout->layout_mode; 549 550 } 551 552 /** 553 * 554 * @TODO do 555 * 556 */ 557 function get_layout_mode(){ 558 $load_layout = new PageLinesLayout(); 559 $layoutmap = $load_layout->get_layout_map(); 560 $layout_mode = $layoutmap['layout_mode']; 561 return $layout_mode; 562 } 563 564 565 /* 566 The main content layouts available in this theme 567 */ 568 function get_the_layouts(){ 569 return array( 570 'fullwidth', 571 'one-sidebar-right', 572 'one-sidebar-left', 573 'two-sidebar-right', 574 'two-sidebar-left', 575 'two-sidebar-center' 576 ); 577 } 578 579 /** 580 * 581 * @TODO do 582 * 583 */ 584 function reset_layout_to_default(){ 585 586 $dlayout = new PageLinesLayout; 587 588 $layout_map = $dlayout->default_layout_setup(); 589 590 pagelines_update_option('layout', $layout_map); 591 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu May 23 23:52:43 2013 | Cross-referenced by PHPXref 0.7.1 |