[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/includes/ -> class.render.css.php (source)

   1  <?php
   2  
   3  
   4  class PageLinesRenderCSS {
   5  
   6      var $lessfiles;
   7      var $types;
   8      var $ctimeout;
   9      var $btimeout;
  10      var $blog_id;
  11  
  12  	function __construct() {
  13  
  14          global $blog_id;
  15          $this->url_string = '%s/?pageless=%s';
  16          $this->ctimeout = 86400;
  17          $this->btimeout = 604800;
  18          $this->types = array( 'sections', 'core', 'custom' );
  19          $this->lessfiles = $this->get_core_lessfiles();
  20          self::actions();
  21      }
  22  
  23      /**
  24       *
  25       *  Load LESS files
  26       *
  27       *  @package PageLines DMS
  28       *  @since 2.2
  29       */
  30  	function get_core_lessfiles(){
  31  
  32          $files[] = 'reset';
  33  
  34          if(pl_has_editor()){
  35              $files[] = 'pl-structure';
  36              $files[] = 'pl-editor';
  37          } 
  38  
  39          if(!pl_deprecate_v2()) {
  40  
  41              $files[] = 'pl-v2';
  42          }
  43  
  44          $bootstrap = array(
  45              'pl-wordpress',
  46              'pl-plugins',
  47              'grid',
  48              'alerts',
  49              'labels-badges',
  50              'tooltip-popover',
  51              'buttons',
  52              'typography',
  53              'dropdowns',
  54              'accordion',
  55              'carousel',
  56              'navs',
  57              'modals',
  58              'thumbnails',
  59              'component-animations',
  60              'utilities',
  61              'pl-objects',
  62              'pl-tables',
  63              'wells',
  64              'forms',
  65              'breadcrumbs',
  66              'close',
  67              'pager',
  68              'pagination',
  69              'progress-bars',
  70              'icons',
  71              'responsive'
  72          );
  73  
  74          return array_merge($files, $bootstrap);
  75      }
  76  
  77      /**
  78       *
  79       *  Dynamic mode, CSS is loaded to a file using wp_rewrite
  80       *
  81       *  @package PageLines DMS
  82       *  @since 2.2
  83       */
  84  	private function actions() {
  85  
  86  
  87          if( pl_has_editor() && EditorLessHandler::is_draft() )
  88              return;
  89  
  90          global $pagelines_template;
  91  
  92          add_filter( 'query_vars', array( &$this, 'pagelines_add_trigger' ) );
  93          add_action( 'template_redirect', array( &$this, 'pagelines_less_trigger' ) , 15);
  94          add_action( 'template_redirect', array( &$this, 'less_file_mode' ) );
  95          add_action( 'wp_enqueue_scripts', array( &$this, 'load_less_css' ) );
  96          add_action( 'pagelines_head_last', array( &$this, 'draw_inline_custom_css' ) , 25 );
  97          add_action( 'wp_head', array( &$pagelines_template, 'print_template_section_head' ), 12 );
  98          add_action( 'pl_scripts_on_ready', array( &$pagelines_template, 'print_on_ready_scripts' ), 12 );
  99          add_action( 'wp_head', array( &$this, 'do_background_image' ), 13 );
 100          add_action( 'extend_flush', array( &$this, 'flush_version' ), 1 );
 101          add_filter( 'pagelines_insert_core_less', array( &$this, 'pagelines_insert_core_less_callback' ) );
 102          add_action( 'admin_notices', array(&$this,'less_error_report') );
 103          add_action( 'wp_before_admin_bar_render', array( &$this, 'less_css_bar' ) );
 104          if ( defined( 'PL_CSS_FLUSH' ) )
 105              do_action( 'extend_flush' );
 106          do_action( 'pagelines_max_mem' );
 107      }
 108  
 109  	function less_file_mode() {
 110  
 111          global $blog_id;
 112          if ( ! get_theme_mod( 'pl_save_version' ) )
 113              return;
 114  
 115          if( defined( 'LESS_FILE_MODE' ) && false == LESS_FILE_MODE )
 116              return;
 117  
 118          if( defined( 'PL_NO_DYNAMIC_URL' ) && true == PL_NO_DYNAMIC_URL )
 119              return;
 120  
 121          $folder = $this->get_css_dir( 'path' );
 122          $url = $this->get_css_dir( 'url' );
 123  
 124          $file = sprintf( 'compiled-css-%s.css', get_theme_mod( 'pl_save_version' ) );
 125  
 126          if( file_exists( trailingslashit( $folder ) . $file ) ){
 127              define( 'DYNAMIC_FILE_URL', trailingslashit( $url ) . $file );
 128              return;
 129          }
 130  
 131          if( false == $this->check_posix() )
 132              return;
 133  
 134          $a = $this->get_compiled_core();
 135          $b = $this->get_compiled_sections();
 136          $gfonts = preg_match( '#(@import[^;]*;)#', $a['type'], $g );
 137          $out = '';
 138          if ( $gfonts ) {
 139              $a['core'] = sprintf( "%s\n%s", $g[1], $a['core'] );
 140              $a['type'] = str_replace( $g[1], '', $a['type'] );
 141          }
 142          $out .= $this->minify( $a['core'] );
 143          $out .= $this->minify( $b['sections'] );
 144          $out .= $this->minify( $a['type'] );
 145          $out .= $this->minify( $a['dynamic'] );
 146          $mem = ( function_exists('memory_get_usage') ) ? round( memory_get_usage() / 1024 / 1024, 2 ) : 0;
 147          if ( is_multisite() )
 148              $blog = sprintf( ' on blog [%s]', $blog_id );
 149          else
 150              $blog = '';
 151          $out .= sprintf( __( '%s/* CSS was compiled at %s and took %s seconds using %sMB of unicorn dust%s.*/', 'pagelines' ), "\n", date( DATE_RFC822, $a['time'] ), $a['c_time'], $mem, $blog );
 152          $this->write_css_file( $out );
 153      }
 154  
 155  	function check_posix() {
 156  
 157          if ( true == apply_filters( 'render_css_posix_', false ) )
 158              return true;
 159  
 160          if ( ! function_exists( 'posix_geteuid') || ! function_exists( 'posix_getpwuid' ) )
 161              return false;
 162  
 163          $User = posix_getpwuid( posix_geteuid() );
 164          $File = posix_getpwuid( fileowner( __FILE__ ) );
 165          if( $User['name'] !== $File['name'] )
 166              return false;
 167  
 168          return true;
 169      }
 170  
 171  	static function get_css_dir( $type = '' ) {
 172  
 173          $folder = apply_filters( 'pagelines_css_upload_dir', wp_upload_dir() );
 174  
 175          if( 'path' == $type )
 176              return trailingslashit( $folder['basedir'] ) . 'pagelines';
 177          else
 178              return trailingslashit( $folder['baseurl'] ) . 'pagelines';
 179      }
 180  
 181  	function write_css_file( $txt ){
 182  
 183  
 184  
 185          add_filter('request_filesystem_credentials', '__return_true' );
 186  
 187          $method = 'direct';
 188          $url = 'themes.php?page=pagelines';
 189  
 190          $folder = $this->get_css_dir( 'path' );
 191          $file = sprintf( 'compiled-css-%s.css', get_theme_mod( 'pl_save_version' ) );
 192  
 193          if( !is_dir( $folder ) ) {
 194              if( true !== wp_mkdir_p( $folder ) )
 195                  return false;
 196          }
 197  
 198          include_once( ABSPATH . 'wp-admin/includes/file.php' );
 199  
 200          if ( is_writable( $folder ) ){
 201              $creds = request_filesystem_credentials($url, $method, false, false, null);
 202              if ( ! WP_Filesystem($creds) )
 203                  return false;
 204          }
 205  
 206              global $wp_filesystem;
 207              if( is_object( $wp_filesystem ) )
 208                  $wp_filesystem->put_contents( trailingslashit( $folder ) . $file, $txt, FS_CHMOD_FILE);
 209              else
 210                  return false;
 211              $url = $this->get_css_dir( 'url' );
 212  
 213              define( 'DYNAMIC_FILE_URL', sprintf( '%s/%s', $url, $file ) );
 214      }
 215  
 216  	function do_background_image() {
 217  
 218          global $pagelines_ID;
 219          if ( is_archive() || is_home() )
 220              $pagelines_ID = null;
 221          $oset = array( 'post_id' => $pagelines_ID );
 222          $oid = 'page_background_image';
 223          $sel = cssgroup('page_background_image');
 224          if( !ploption('supersize_bg', $oset) && ploption( $oid . '_url', $oset )){
 225  
 226              $bg_repeat = (ploption($oid.'_repeat', $oset)) ? ploption($oid.'_repeat', $oset) : 'no-repeat';
 227              $bg_attach = (ploption($oid.'_attach', $oset)) ? ploption($oid.'_attach', $oset): 'scroll';
 228              $bg_pos_vert = (ploption($oid.'_pos_vert', $oset) || ploption($oid.'_pos_vert', $oset) == 0 ) ? (int) ploption($oid.'_pos_vert', $oset) : '0';
 229              $bg_pos_hor = (ploption($oid.'_pos_hor', $oset) || ploption($oid.'_pos_hor', $oset) == 0 ) ? (int) ploption($oid.'_pos_hor', $oset) : '50';
 230              $bg_selector = (ploption($oid.'_selector', $oset)) ? ploption($oid.'_selector', $oset) : $sel;
 231              $bg_url = ploption($oid.'_url', $oset);
 232  
 233              $css = sprintf('%s{ background-image:url(%s);', $bg_selector, $bg_url);
 234              $css .= sprintf('background-repeat: %s;', $bg_repeat);
 235              $css .= sprintf('background-attachment: %s;', $bg_attach);
 236              $css .= sprintf('background-position: %s%% %s%%;}', $bg_pos_hor, $bg_pos_vert);
 237              echo inline_css_markup( 'pagelines-page-bg', $css );
 238  
 239          }
 240      }
 241  
 242  
 243  	function less_css_bar() {
 244          foreach ( $this->types as $t ) {
 245              if ( ploption( "pl_less_error_{$t}" ) ) {
 246  
 247                  global $wp_admin_bar;
 248                  $wp_admin_bar->add_menu( array(
 249                      'parent' => false,
 250                      'id' => 'less_error',
 251                      'title' => sprintf( '<span class="label label-warning pl-admin-bar-label">%s</span>', __( 'LESS Compile error!', 'pagelines' ) ),
 252                      'href' => admin_url( PL_SETTINGS_URL ),
 253                      'meta' => false
 254                  ));
 255                  $wp_admin_bar->add_menu( array(
 256                      'parent' => 'less_error',
 257                      'id' => 'less_message',
 258                      'title' => sprintf( __( 'Error in %s Less code: %s', 'pagelines' ), $t, ploption( "pl_less_error_{$t}" ) ),
 259                      'href' => admin_url( PL_SETTINGS_URL ),
 260                      'meta' => false
 261                  ));
 262              }
 263          }
 264      }
 265  
 266  	function less_error_report() {
 267  
 268          $default = '<div class="updated fade update-nag"><div style="text-align:left"><h4>PageLines %s LESS/CSS error.</h4>%s</div></div>';
 269  
 270          foreach ( $this->types as $t ) {
 271              if ( ploption( "pl_less_error_{$t}" ) )
 272                  printf( $default, ucfirst( $t ), ploption( "pl_less_error_{$t}" ) );
 273          }
 274      }
 275  
 276      /**
 277       *
 278       * Get custom CSS
 279       *
 280       *  @package PageLines DMS
 281       *  @since 2.2
 282       */
 283  	function draw_inline_custom_css() {
 284          // always output this, even if empty - container is needed for live compile
 285          $a = $this->get_compiled_custom();
 286          return inline_css_markup( 'pagelines-custom', rtrim( $this->minify( $a['custom'] ) ) );
 287      }
 288  
 289      /**
 290       *
 291       *  Draw dynamic CSS inline.
 292       *
 293       *  @package PageLines DMS
 294       *  @since 2.2
 295       */
 296  	function draw_inline_dynamic_css() {
 297  
 298          if( has_filter( 'disable_dynamic_css' ) )
 299              return;
 300  
 301          $css = $this->get_dynamic_css();
 302          inline_css_markup('dynamic-css', $css['dynamic'] );
 303      }
 304  
 305      /**
 306       *
 307       *  Get Dynamic CSS
 308       *
 309       *  @package PageLines DMS
 310       *  @since 2.2
 311       *
 312       */
 313  	function get_dynamic_css(){
 314  
 315          $pagelines_dynamic_css = new PageLinesCSS;
 316  
 317          $pagelines_dynamic_css->typography();
 318  
 319          $typography = $pagelines_dynamic_css->css;
 320  
 321          unset( $pagelines_dynamic_css->css );
 322          $pagelines_dynamic_css->layout();
 323          $pagelines_dynamic_css->options();
 324  
 325          $out = array(
 326              'type'        =>    $typography,
 327              'dynamic'    =>    apply_filters('pl-dynamic-css', $pagelines_dynamic_css->css)
 328          );
 329          return $out;
 330      }
 331  
 332      /**
 333       *
 334       *  Enqueue the dynamic css file.
 335       *
 336       *  @package PageLines DMS
 337       *  @since 2.2
 338       */
 339  	function load_less_css() {
 340  
 341          wp_register_style( 'pagelines-less',  $this->get_dynamic_url(), false, null, 'all' );
 342          wp_enqueue_style( 'pagelines-less' );
 343      }
 344  
 345  	function get_dynamic_url() {
 346  
 347          global $blog_id;
 348          $version = get_theme_mod( "pl_save_version" );
 349  
 350          if ( ! $version )
 351              $version = '1';
 352  
 353          if ( is_multisite() )
 354              $id = $blog_id;
 355          else
 356              $id = '1';
 357  
 358          $version = sprintf( '%s_%s', $id, $version );
 359  
 360          $parent = apply_filters( 'pl_parent_css_url', PL_PARENT_URL );
 361          
 362          $url = add_query_arg( 'pageless', $version, trailingslashit( site_url() ) );
 363          
 364          if ( defined( 'DYNAMIC_FILE_URL' ) )
 365              $url = DYNAMIC_FILE_URL;
 366  
 367          if ( has_action( 'pl_force_ssl' ) )
 368              $url = str_replace( 'http://', 'https://', $url );
 369  
 370          return apply_filters( 'pl_dynamic_css_url', $url );
 371      }
 372  
 373  	function get_base_url() {
 374  
 375          if(function_exists('icl_get_home_url')) {
 376              return icl_get_home_url();
 377            }
 378  
 379          return get_home_url();
 380      }
 381  
 382  	function check_compat() {
 383  
 384          if( defined( 'LESS_FILE_MODE' ) && false == LESS_FILE_MODE && is_multisite() )
 385              return true;
 386  
 387          if ( function_exists( 'icl_get_home_url' ) )
 388              return true;
 389  
 390          if ( defined( 'PLL_INC') )
 391              return true;
 392  
 393          if ( ! VPRO )
 394              return true;
 395  
 396          if ( defined( 'PL_NO_DYNAMIC_URL' ) )
 397              return true;
 398  
 399          if ( is_multisite() && in_array( $GLOBALS['pagenow'], array( 'wp-signup.php' ) ) )
 400              return true;
 401  
 402          if( site_url() !== get_home_url() )
 403              return true;
 404  
 405          if ( 'nginx' == substr($_SERVER['SERVER_SOFTWARE'], 0, 5) )
 406              return false;
 407  
 408          global $is_apache;
 409          if ( ! $is_apache )
 410              return true;
 411      }
 412  	function check_draft() {
 413          global $pldraft;
 414  
 415          if( is_object($pldraft) )
 416              $mode = $pldraft->mode;
 417          else
 418              $mode = false;
 419  
 420          return( 'draft' == $mode ) ? true : false;
 421      }
 422      /**
 423       *
 424       *  Get compiled/cached CSS
 425       *
 426       *  @package PageLines DMS
 427       *  @since 2.2
 428       */
 429  	function get_compiled_core() {
 430  
 431          if ( ! $this->check_draft() && is_array( $a = get_transient( 'pagelines_core_css' ) ) ) {
 432              return $a;
 433          } else {
 434  
 435              $start_time = microtime(true);
 436              build_pagelines_layout();
 437  
 438              $dynamic = $this->get_dynamic_css();
 439  
 440              $core_less = $this->get_core_lesscode();
 441  
 442              $pless = new PagelinesLess();
 443  
 444              $core_less = $pless->raw_less( $core_less  );
 445  
 446              $end_time = microtime(true);
 447              $a = array(
 448                  'dynamic'    => $dynamic['dynamic'],
 449                  'type'        => $dynamic['type'],
 450                  'core'        => $core_less,
 451                  'c_time'    => round(($end_time - $start_time),5),
 452                  'time'        => time()
 453              );
 454              if ( strpos( $core_less, 'PARSE ERROR' ) === false ) {
 455                  set_transient( 'pagelines_core_css', $a, $this->ctimeout );
 456                  set_transient( 'pagelines_core_css_backup', $a, $this->btimeout );
 457                  return $a;
 458              } else {
 459                  return get_transient( 'pagelines_core_css_backup' );
 460              }
 461          }
 462      }
 463  
 464      /**
 465       *
 466       *  Get compiled/cached CSS
 467       *
 468       *  @package PageLines DMS
 469       *  @since 2.2
 470       */
 471  	function get_compiled_sections() {
 472  
 473          if ( ! $this->check_draft() && is_array( $a = get_transient( 'pagelines_sections_css' ) ) ) {
 474              return $a;
 475          } else {
 476  
 477              $start_time = microtime(true);
 478              build_pagelines_layout();
 479  
 480              $sections = $this->get_all_active_sections();
 481  
 482              $pless = new PagelinesLess();
 483              $sections =  $pless->raw_less( $sections, 'sections' );
 484              $end_time = microtime(true);
 485              $a = array(
 486                  'sections'    => $sections,
 487                  'c_time'    => round(($end_time - $start_time),5),
 488                  'time'        => time()
 489              );
 490              if ( strpos( $sections, 'PARSE ERROR' ) === false ) {
 491                  set_transient( 'pagelines_sections_css', $a, $this->ctimeout );
 492                  set_transient( 'pagelines_sections_css_backup', $a, $this->btimeout );
 493                  return $a;
 494              } else {
 495                  return get_transient( 'pagelines_sections_css_backup' );
 496              }
 497          }
 498      }
 499  
 500  
 501      /**
 502       *
 503       *  Get compiled/cached CSS
 504       *
 505       *  @package PageLines DMS
 506       *  @since 2.2
 507       */
 508  	function get_compiled_custom() {
 509  
 510          if ( ! $this->check_draft() && is_array(  $a = get_transient( 'pagelines_custom_css' ) ) ) {
 511              return $a;
 512          } else {
 513  
 514              $start_time = microtime(true);
 515              build_pagelines_layout();
 516  
 517              $custom = stripslashes( pl_setting( 'custom_less' ) );
 518  
 519              $pless = new PagelinesLess();
 520              $custom =  $pless->raw_less( $custom, 'custom' );
 521              $end_time = microtime(true);
 522              $a = array(
 523                  'custom'    => $custom,
 524                  'c_time'    => round(($end_time - $start_time),5),
 525                  'time'        => time()
 526              );
 527              if ( strpos( $custom, 'PARSE ERROR' ) === false ) {
 528                  set_transient( 'pagelines_custom_css', $a, $this->ctimeout );
 529                  set_transient( 'pagelines_custom_css_backup', $a, $this->btimeout );
 530                  return $a;
 531              } else {
 532                  return get_transient( 'pagelines_custom_css_backup' );
 533              }
 534          }
 535      }
 536  
 537      /**
 538       *
 539       *  Get Core LESS code
 540       *
 541       *  @package PageLines DMS
 542       *  @since 2.2
 543       */
 544  	function get_core_lesscode() {
 545  
 546              return $this->load_core_cssfiles( apply_filters( 'pagelines_core_less_files', $this->lessfiles ) );
 547      }
 548  
 549      /**
 550       *
 551       *  Helper for get_core_less_code()
 552       *
 553       *  @package PageLines DMS
 554       *  @since 2.2
 555       */
 556  	function load_core_cssfiles( $files ) {
 557  
 558          $code = '';
 559          foreach( $files as $less ) {
 560  
 561              $code .= PageLinesLess::load_less_file( $less );
 562          }
 563          return apply_filters( 'pagelines_insert_core_less', $code );
 564      }
 565  
 566  	function pagelines_add_trigger( $vars ) {
 567          $vars[] = 'pageless';
 568          return $vars;
 569      }
 570  
 571  	function pagelines_less_trigger() {
 572          global $blog_id;
 573          if( intval( get_query_var( 'pageless' ) ) ) {
 574              header( 'Content-type: text/css' );
 575              header( 'Expires: ' );
 576              header( 'Cache-Control: max-age=604100, public' );
 577  
 578              $a = $this->get_compiled_core();
 579              $b = $this->get_compiled_sections();
 580              $gfonts = preg_match( '#(@import[^;]*;)#', $a['type'], $g );
 581  
 582              if ( $gfonts ) {
 583                  $a['core'] = sprintf( "%s\n%s", $g[1], $a['core'] );
 584                  $a['type'] = str_replace( $g[1], '', $a['type'] );
 585              }
 586              echo $this->minify( $a['core'] );
 587              echo $this->minify( $b['sections'] );
 588              echo $this->minify( $a['type'] );
 589              echo $this->minify( $a['dynamic'] );
 590              $mem = ( function_exists('memory_get_usage') ) ? round( memory_get_usage() / 1024 / 1024, 2 ) : 0;
 591              if ( is_multisite() )
 592                  $blog = sprintf( ' on blog [%s]', $blog_id );
 593              else
 594                  $blog = '';
 595              echo sprintf( __( '%s/* CSS was compiled at %s and took %s seconds using %sMB of unicorn dust%s.*/', 'pagelines' ), "\n", date( DATE_RFC822, $a['time'] ), $a['c_time'],  $mem, $blog );
 596              die();
 597          }
 598      }
 599  
 600      /**
 601       *
 602       *  Minify
 603       *
 604       *  @package PageLines DMS
 605       *  @since 2.2
 606       */
 607  	function minify( $css ) {
 608          if( is_pl_debug() )
 609              return $css;
 610  
 611          if( ! ploption( 'pl_minify') )
 612              return $css;
 613  
 614          $data = $css;
 615  
 616          $data = preg_replace( '#/\*.*?\*/#s', '', $data );
 617          // remove new lines \\n, tabs and \\r
 618          $data = preg_replace('/(\t|\r|\n)/', '', $data);
 619          // replace multi spaces with singles
 620          $data = preg_replace('/(\s+)/', ' ', $data);
 621          //Remove empty rules
 622          $data = preg_replace('/[^}{]+{\s?}/', '', $data);
 623          // Remove whitespace around selectors and braces
 624          $data = preg_replace('/\s*{\s*/', '{', $data);
 625          // Remove whitespace at end of rule
 626          $data = preg_replace('/\s*}\s*/', '}', $data);
 627          // Just for clarity, make every rules 1 line tall
 628          $data = preg_replace('/}/', "}\n", $data);
 629          $data = str_replace( ';}', '}', $data );
 630          $data = str_replace( ', ', ',', $data );
 631          $data = str_replace( '; ', ';', $data );
 632          $data = str_replace( ': ', ':', $data );
 633          $data = preg_replace( '#\s+#', ' ', $data );
 634  
 635          if ( ! preg_last_error() )
 636              return $data;
 637          else
 638              return $css;
 639      }
 640  
 641      /**
 642       *
 643       *  Flush rewrites/cached css
 644       *
 645       *  @package PageLines DMS
 646       *  @since 2.2
 647       */
 648  	static function flush_version( $rules = true ) {
 649  
 650          $types = array( 'sections', 'core', 'custom' );
 651  
 652          $folder = trailingslashit( self::get_css_dir( 'path' ) );
 653  
 654          $file = sprintf( 'compiled-css-%s.css', get_theme_mod( 'pl_save_version' ) );
 655  
 656          if( is_file( $folder . $file ) )
 657              @unlink( $folder . $file );
 658  
 659          // Attempt to flush super-cache and w3 cache.
 660  
 661          if( function_exists( 'prune_super_cache' ) ) {
 662              global $cache_path;
 663              $GLOBALS["super_cache_enabled"] = 1;
 664              prune_super_cache( $cache_path . 'supercache/', true );
 665              prune_super_cache( $cache_path, true );
 666          }
 667          
 668  
 669          if( $rules )
 670              flush_rewrite_rules( true );
 671          set_theme_mod( 'pl_save_version', time() );
 672  
 673          $types = array( 'sections', 'core', 'custom' );
 674  
 675          foreach( $types as $t ) {
 676  
 677              $compiled = get_transient( "pagelines_{$t}_css" );
 678              $backup = get_transient( "pagelines_{$t}_css_backup" );
 679  
 680              if ( ! is_array( $backup ) && is_array( $compiled ) && strpos( $compiled[$t], 'PARSE ERROR' ) === false )
 681                  set_transient( "pagelines_{$t}_css_backup", $compiled, 604800 );
 682  
 683              delete_transient( "pagelines_{$t}_css" );
 684          }
 685      }
 686  
 687  	function pagelines_insert_core_less_callback( $code ) {
 688  
 689          global $pagelines_raw_lesscode_external;
 690          $out = '';
 691          if ( is_array( $pagelines_raw_lesscode_external ) && ! empty( $pagelines_raw_lesscode_external ) ) {
 692  
 693              foreach( $pagelines_raw_lesscode_external as $file ) {
 694  
 695                  if( is_file( $file ) )
 696                      $out .= pl_file_get_contents( $file );
 697              }
 698              return $code . $out;
 699          }
 700          return $code;
 701      }
 702  
 703  	function get_all_active_sections() {
 704  
 705          $out = '';
 706          global $load_sections;
 707          $available = $load_sections->pagelines_register_sections( true, true );
 708  
 709          $disabled = get_option( 'pagelines_sections_disabled', array() );
 710  
 711          /*
 712          * Filter out disabled sections
 713          */
 714          foreach( $disabled as $type => $data )
 715              if ( isset( $disabled[$type] ) )
 716                  foreach( $data as $class => $state )
 717                      unset( $available[$type][ $class ] );
 718  
 719          /*
 720          * We need to reorder the array so sections css is loaded in the right order.
 721          * Core, then pagelines-sections, followed by anything else.
 722          */
 723          $sections = array();
 724          $sections['parent'] = $available['parent'];
 725          $sections['child'] = array();
 726          unset( $available['parent'] );
 727          if( isset( $available['custom'] ) && is_array( $available['custom'] ) ) {
 728              $sections['child'] = $available['custom']; // load child theme sections that override.
 729              unset( $available['custom'] );    
 730          }
 731          // remove core section less if child theme has a less file
 732          foreach( $sections['child'] as $c => $cdata) {
 733              if( isset( $sections['parent'][$c] ) && is_file( $cdata['base_dir'] . '/style.less' ) )
 734                  unset( $sections['parent'][$c] );
 735          }
 736          
 737          if ( is_array( $available ) ) {
 738              foreach( $available as $type => $data ) {
 739                  if( ! empty( $data ) )
 740                      $sections[$type] = $data;
 741              }
 742          }
 743          foreach( $sections as $t ) {
 744              foreach( $t as $key => $data ) {
 745                  if ( $data['less'] && $data['loadme'] ) {
 746                      if ( is_file( $data['base_dir'] . '/style.less' ) )
 747                          $out .= pl_file_get_contents( $data['base_dir'] . '/style.less' );
 748                      elseif( is_file( $data['base_dir'] . '/color.less' ))
 749                          $out .= pl_file_get_contents( $data['base_dir'] . '/color.less' );
 750                  }
 751              }
 752          }
 753          return apply_filters('pagelines_lesscode', $out);
 754      }
 755  
 756  } //end of PageLinesRenderCSS
 757  
 758  function pagelines_insert_core_less( $file ) {
 759  
 760      global $pagelines_raw_lesscode_external;
 761  
 762      if( !is_array( $pagelines_raw_lesscode_external ) )
 763          $pagelines_raw_lesscode_external = array();
 764  
 765      $pagelines_raw_lesscode_external[] = $file;
 766  }


Generated: Fri Aug 30 18:26:24 2013 Cross-referenced by PHPXref 0.7.1