[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/includes/ -> library.functions.php (source)

   1  <?php
   2  
   3  // ==============================
   4  // = PageLines Function Library =
   5  // ==============================
   6  
   7  /**
   8   *  Determines if on a foreign integration page
   9   *
  10   * @since 2.0.0
  11   */
  12  function pl_is_integration(){
  13      global $pl_integration;
  14  
  15      return (isset($pl_integration) && $pl_integration) ? true : false;
  16  }
  17  
  18  /**
  19   *  returns the integration slug if viewing an integration page
  20   *
  21   * @since 2.0.0
  22   */
  23  function pl_get_integration(){
  24      global $pl_integration;
  25  
  26      return (isset($pl_integration) && $pl_integration) ? sprintf('%s', $pl_integration) : false;
  27  }
  28  
  29  /**
  30   *  Determines if this page is showing several posts.
  31   *
  32   * @since 2.0.0
  33   */
  34  function pagelines_is_posts_page(){
  35      if(is_home() || is_search() || is_archive() || is_category() || is_tag()) return true;
  36      else return false;
  37  }
  38  
  39  
  40  /**
  41   *
  42   * @TODO document
  43   *
  44   */
  45  function pagelines_non_meta_data_page(){
  46      if(pagelines_is_posts_page() || is_404()) return true;
  47      else return false;
  48  }
  49  
  50  
  51  /**
  52   * is_pagelines_special() REVISED
  53   *
  54   * A few conditional functions that were being used were unnecessary
  55   * (is_author, is_category, & is_tag) as these are all covered by is_archive
  56   *
  57   * $special_types should be a filterable array to allow ploption to be used for extended special option values,
  58   * or anytime the passed $args['type'] would be used/compared (in admin)
  59   *
  60   * Filterable return value - could be used for example to return false for the blog home,
  61   * letting the page meta values take precedence instead of the special.  Just a thought.
  62   *
  63   */
  64  function is_pagelines_special( $args = array() ) {
  65  
  66      $special_types = apply_filters( 'pagelines_special_types', array('posts','archive','category','search','tag','author','404_page') );
  67  
  68      if ( is_404() || is_home() || is_search() || is_archive() )
  69          $special = true;
  70  
  71      elseif ( isset( $args['type'] ) && in_array( $args['type'], $special_types ) )
  72          $special = true;
  73  
  74      elseif ( pl_is_integration() )
  75          $special = true;
  76  
  77      else
  78          $special = false;
  79  
  80      return apply_filters( 'is_pagelines_special', $special, $args );
  81  }
  82  
  83  
  84  
  85  /**
  86   *
  87   * @TODO document
  88   *
  89   */
  90  function pagelines_special_pages(){
  91      return array('posts', 'search', 'archive', 'tag', 'category', '404');
  92  }
  93  
  94  
  95  /**
  96   *
  97   * @TODO document
  98   *
  99   */
 100  function pl_meta_set_url( $tab = null ){
 101  
 102      global $post;
 103  
 104      $tab = (isset($tab)) ? '#'.$tab : '';
 105  
 106      $url = (is_pagelines_special()) ? admin_url(PL_SPECIAL_OPTS_URL) : get_edit_post_link( $post->ID );
 107  
 108      return $url.$tab;
 109  }
 110  
 111  /**
 112   * PageLines Body Classes
 113   *
 114   * Sets up classes for controlling design and layout and is used on the body tag
 115   *
 116   * @package     PageLines Framework
 117   * @subpackage  Functions Library
 118   *
 119   * @since       1.1.0
 120   *
 121   * @link        http://www.pagelines.com/wiki/Pagelines_body_classes
 122   *
 123   * @uses        ploption
 124   * @uses        PL_CHILDTHEMENAME (constant)
 125   *
 126   * @return      string $body_classes - PageLines default body classes
 127   */
 128  function pagelines_body_classes(){
 129  
 130      global $pagelines_template;
 131      global $pagelines_addclasses;
 132  
 133      $special_body_class = (ploption('special_body_class')) ? ploption('special_body_class') : '';
 134  
 135      
 136      $classes = array();
 137      
 138      $classes[] = $special_body_class;
 139      // child theme name
 140      $classes[] = sanitize_html_class( strtolower( PL_CHILDTHEMENAME ) );
 141      // pro
 142      $classes[] = (pl_is_pro()) ? 'pl-pro-version' : 'pl-basic-version';
 143  
 144      
 145      if ( !pl_deprecate_v2() ) {
 146          // canvas shadow
 147          $classes[] = (ploption('canvas_shadow')) ? 'content-shadow' : '';
 148  
 149          // responsive
 150          $classes[] = (ploption('layout_handling') == 'pixels' || ploption('layout_handling') == 'percent') ? 'responsive' : 'static';
 151  
 152          // design mode
 153          $classes[] = (ploption('site_design_mode') && !pl_is_disabled('color_control')) ? ploption('site_design_mode') : 'full_width';
 154  
 155          // template type
 156          $classes[] = $pagelines_template->template_type;
 157      }
 158      else {
 159          // for backwards compatiblity, dms is:
 160          $classes[] = 'responsive';
 161          $classes[] = 'full_width';
 162      }
 163  
 164      // externally added via global variable (string)
 165      if ( isset( $pagelines_addclasses ) && $pagelines_addclasses )
 166          $classes = array_merge( $classes, (array) explode( ' ', $pagelines_addclasses ) );
 167  
 168      // ensure no duplicates or empties
 169      $classes = array_unique( array_filter( $classes ) );
 170      // filter & convert to string
 171      $body_classes = join(' ', (array) apply_filters('pagelines_body_classes', $classes) );
 172  
 173      return $body_classes;
 174  }
 175  
 176  
 177  /**
 178   *
 179   * @TODO document
 180   *
 181   */
 182  function pagelines_add_bodyclass( $class ) {
 183  
 184      global $pagelines_addclasses;
 185  
 186      if ( !isset( $pagelines_addclasses ) )
 187          $pagelines_addclasses = '';
 188  
 189      if ( isset( $class ) )
 190          $pagelines_addclasses .= sprintf( ' %s', $class );
 191  
 192  }
 193  
 194  /**
 195   *
 196   *  Sets up global post ID and $post global for handling, reference and consistency
 197   *
 198   *  @package PageLines DMS
 199   *  @subpackage Functions Library
 200   *  @since 1.0.0
 201   *
 202   */
 203  function pagelines_id_setup(){
 204      global $post;
 205      global $pagelines_ID;
 206      global $pagelines_post;
 207  
 208      if(isset($post) && is_object($post)){
 209          $pagelines_ID = $post->ID;
 210          $pagelines_post = $post;
 211      }
 212      else {
 213          $pagelines_post = '';
 214          $pagelines_ID = '';
 215      }
 216  
 217  }
 218  
 219  /**
 220   * PageLines Register Hook
 221   *
 222   * Stores for reference or use elsewhere.
 223   *
 224   * @package     PageLines Framework
 225   * @subpackage  Functions Library
 226   *
 227   * @since       1.3.3
 228   *
 229   * @link        http://www.pagelines.com/wiki/Pagelines_register_hook
 230   *
 231   * @param       $hook_name
 232   * @param       null $hook_area_id
 233   */
 234  function pagelines_register_hook( $hook_name, $hook_area_id = null){
 235  
 236      /** Do The Hook    */
 237      do_action( $hook_name, $hook_name, $hook_area_id);
 238  
 239  }
 240  
 241  /**
 242   * PageLines Template Area
 243   *
 244   * Does hooks for template areas
 245   *
 246   * @package     PageLines Framework
 247   * @subpackage  Functions Library
 248   *
 249   * @since       1.3.3
 250   *
 251   * @link        http://www.pagelines.com/wiki/Pagelines_template_area
 252   *
 253   * @param       $hook_name
 254   * @param       null $hook_area_id
 255   */
 256  function pagelines_template_area( $hook_name, $hook_area_id = null){
 257  
 258      /** Do The Hook    */
 259      do_action( $hook_name, $hook_area_id);
 260  
 261  }
 262  
 263  /**
 264   * Check Authority
 265   *
 266   * Check the authentication level for administrator status (security)
 267   *
 268   * @package     PageLines Framework
 269   * @subpackage  Functions Library
 270   * @since       1.x.x
 271   */
 272  function checkauthority(){
 273      if (!current_user_can('edit_themes'))
 274      wp_die( __( 'Sorry, but you don&#8217;t have the administrative privileges needed to do this.', 'pagelines' ) );
 275  }
 276  
 277  /**
 278   * IE Version
 279   *
 280   * Checks for IE and Returns Version
 281   *
 282   * @package     PageLines Framework
 283   * @subpackage  Functions Library
 284   * @since       1.0.0
 285   *
 286   * @return      bool|float
 287   */
 288  function ie_version() {
 289    $match=preg_match('/MSIE ([0-9]\.[0-9])/',$_SERVER['HTTP_USER_AGENT'],$reg);
 290    if($match==0)
 291      return false;
 292    else
 293      return floatval($reg[1]);
 294  }
 295  
 296  /**
 297   * PageLines ShortURL
 298   *
 299   * Gets a 'tiny' url. Returns URL if response is not 200
 300   *
 301   * @package     PageLines Framework
 302   * @subpackage  Functions Library
 303   * @since       1.5.0
 304   *
 305   * @uses        pagelines_option
 306   * @uses        pagelines_format_tweet
 307   *
 308   * @internal    uses filter 'pagelines_shorturl_provider'
 309   * @internal    uses filter 'pagelines_shorturl_cachetimeout'
 310   *
 311   * @param       $url
 312   * @param       int $timeout
 313   *
 314   * @return      string
 315   */
 316  function pagelines_shorturl( $url, $timeout = 86400 ) {
 317  
 318      global $post;
 319      if ( !pagelines_option( 'share_twitter_cache' ) )
 320          return pagelines_format_tweet( get_the_title(), $url );
 321  
 322      $provider = 'http://pln.so/api.php?action=shorturl&format=json&url=';
 323  
 324      // If cache exists send it back
 325      $cache = get_transient( 'pagelines_shorturl_cache' );
 326      if ( is_array( $cache) && array_key_exists( md5($url), $cache ) ) {
 327          return pagelines_format_tweet ( get_the_title(), $cache[md5($url)] );
 328      }
 329  
 330      // Fetch the short url from the api
 331      $response = wp_remote_get(  apply_filters( 'pagelines_shorturl_provider' , $provider ) . $url );
 332  
 333      if( is_wp_error( $response ) ) return pagelines_format_tweet( get_the_title(), $url ); // return original url if there is an error
 334  
 335      // Check the body from the api is actually a url and not a 400 error
 336      // If its OK we will cache it and return it, othwise return original url
 337  
 338      $out = ( $response['response']['code'] == 200 ) ? $response['body'] : false;
 339      if ( !is_object( $out = json_decode( $out ) ) ) return pagelines_format_tweet( get_the_title(), $url );
 340  
 341      if ( $cache == false ) {
 342          unset( $cache );
 343          $cache = array();
 344      }
 345      delete_transient( 'pagelines_shorturl_cache' );
 346      $cache = array_merge( $cache, array( md5($url) => $out->shorturl ) );
 347      set_transient( 'pagelines_shorturl_cache', $cache, apply_filters( 'pagelines_shorturl_cachetimeout', $timeout ) );
 348      return pagelines_format_tweet( get_the_title(), $out->shorturl );
 349  }
 350  
 351  
 352  /**
 353   * PageLines Format Tweet
 354   *
 355   * @param   $title
 356   * @param   $url
 357   *
 358   * @return  string
 359   */
 360  function pagelines_format_tweet( $title, $url ) {
 361  
 362      return sprintf( '%1$s - %2$s', $title, $url );
 363  }
 364  
 365  /**
 366   * PageLines Background Cascade
 367   *
 368   * Sets background cascade for use in color mixing - default: White
 369   *
 370   * @since       2.0.b6
 371   *
 372   * @uses        ploption
 373   * @internal    uses filter background_cascade
 374   *
 375   * @return      mixed|void
 376   */
 377  function pl_background_cascade(){
 378  
 379      $cascade = array(
 380          ploption('contentbg'),
 381          ploption('pagebg'),
 382          ploption('bodybg'),
 383          '#ffffff'
 384      );
 385  
 386      return apply_filters('background_cascade', $cascade);
 387  }
 388  
 389  /**
 390   * PageLines Body Background
 391   *
 392   * Body Background - default: White
 393   *
 394   * @uses        ploption
 395   * @internal    uses filter body_bg
 396   *
 397   * @since       2.0.b6
 398   *
 399   * @return      mixed|void
 400   */
 401  function pl_body_bg(){
 402  
 403      $cascade = array( ploption('bodybg'), '#ffffff' );
 404  
 405      return apply_filters('body_bg', $cascade);
 406  }
 407  
 408  
 409  /**
 410   * PageLines Strip
 411   *
 412   * Strips White Space
 413   *
 414   * @since   2.0.b13
 415   *
 416   * @param   string $t - input string
 417   * @return  mixed
 418   */
 419  function plstrip( $t ){
 420  
 421      if( is_pl_debug() )
 422          return $t;
 423  
 424      return preg_replace( '/\s+/', ' ', $t );
 425  }
 426  
 427  
 428  /**
 429   * Show Posts Nave
 430   *
 431   * Checks to see if there is more than one page for nav.
 432   *
 433   * @since 1.0.0
 434   *
 435   * @return bool
 436   * @TODO does this add a query?
 437   */
 438  function show_posts_nav() {
 439      global $wp_query;
 440      return ($wp_query->max_num_pages > 1);
 441  }
 442  
 443  
 444  /**
 445   * PageLines bbPress Forum
 446   *
 447   * Checks for a bbPress installation by pulling a global identifier from bbPress
 448   *
 449   * @since 3.x.x
 450   *
 451   * @return bool
 452   */
 453  function pagelines_bbpress_forum(){
 454      global $bbpress_forum;
 455      if($bbpress_forum ){
 456          return true;
 457      } else return false;
 458  }
 459  
 460  
 461  /**
 462   * Displays query information in footer (For testing - NOT FOR PRODUCTION)
 463   * @since 4.0.0
 464   */
 465  function show_query_analysis(){
 466      if (current_user_can('administrator')){
 467          global $wpdb;
 468          echo '<pre>';
 469          print_r($wpdb->queries);
 470          echo '</pre>';
 471      }
 472  }
 473  
 474  
 475  /**
 476   * Custom Trim Excerpt
 477   *
 478   * Returns the excerpt at a user-defined length
 479   *
 480   * @param   $text - input text
 481   * @param   $length - number of words
 482   *
 483   * @return  string - concatenated with an ellipsis
 484   */
 485  function custom_trim_excerpt($text, $length) {
 486  
 487      $text = strip_shortcodes( $text ); // optional
 488      $text = strip_tags($text);
 489  
 490      $words = explode(' ', $text, $length + 1);
 491      if ( count($words) > $length) {
 492          array_pop($words);
 493          $text = implode(' ', $words);
 494      }
 495      return ($text != '') ? $text.'&nbsp;<span class="hellip">[&hellip;]</span>' : '';
 496  }
 497  
 498  
 499  
 500  
 501  
 502  /**
 503   *
 504   * @TODO document
 505   *
 506   */
 507  function pagelines_add_page($file, $name){
 508      global $pagelines_user_pages;
 509  
 510      $pagelines_user_pages[$file] = array('name' => $name);
 511  
 512  }
 513  
 514  /**
 515   * Used for Callback calls, returns nothing
 516   *
 517   * @since 1.0.0
 518   */
 519  function pagelines_setup_menu() {
 520      echo __( 'Add links using WordPress menus in your site admin.', 'pagelines' );
 521  }
 522  
 523  /**
 524   * Setup PageLines Template
 525   *
 526   * Includes the loading template that sets up all PageLines templates
 527   *
 528   * @since   1.1.0
 529   *
 530   * @link    http://www.pagelines.com/wiki/Setup_pagelines_template
 531   *
 532   * @uses    pagelines_template_area
 533   */
 534  function setup_pagelines_template() {
 535  
 536  
 537      // if not true, then a non pagelines template is being rendered (wrap with .content)
 538      $GLOBALS['pagelines_render'] = true;
 539  
 540      get_header();
 541  
 542      if(!has_action('override_pagelines_body_output'))
 543          pagelines_template_area('pagelines_template', 'templates');
 544  
 545      get_footer();
 546  }
 547  
 548  
 549  /**
 550   * PageLines Add Page Callback
 551   *
 552   * Adds pages from the child theme.
 553   *
 554   * @since   1.1.0
 555   *
 556   * @param   $page_array
 557   * @param   $template_area
 558   *
 559   * @return  array
 560   */
 561  function pagelines_add_page_callback( $page_array, $template_area ){
 562      global $pagelines_user_pages;
 563  
 564      if( is_array($pagelines_user_pages) ){
 565          foreach($pagelines_user_pages as $file => $pageinfo){
 566              $page_array[$file] = array('name'=>$pageinfo['name']);
 567          }
 568      }
 569  
 570      return $page_array;
 571  }
 572  
 573  /**
 574   * Overrides default excerpt handling so we have more control
 575   *
 576   * @since 1.2.4
 577   */
 578  remove_filter('get_the_excerpt', 'wp_trim_excerpt');
 579  add_filter('get_the_excerpt', 'improved_trim_excerpt');
 580  
 581  /**
 582   *
 583   * @TODO document
 584   *
 585   */
 586  function improved_trim_excerpt($text) {
 587  
 588      // Group options at top :)
 589      global $ex_length, $ex_tags;
 590  
 591      if(pl_has_editor()){
 592          $allowed_tags = ( isset( $ex_tags ) && '' != $ex_tags ) ? $ex_tags : '';
 593          $excerpt_len = ( isset( $ex_length ) && '' != $ex_length ) ? $ex_length : 55;
 594      } else {
 595          $allowed_tags = (ploption('excerpt_tags')) ? ploption('excerpt_tags') : '';
 596          $excerpt_len = (ploption('excerpt_len')) ? ploption('excerpt_len') : 55;
 597      }
 598  
 599      $raw_excerpt = $text;
 600      if ( '' == $text ) {
 601          $text = get_the_content('');
 602  
 603          $text = strip_shortcodes( $text );
 604  
 605  
 606          $text = apply_filters('the_content', $text);
 607  
 608          $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); // PageLines - Strip JS
 609  
 610          $text = str_replace(']]>', ']]&gt;', $text);
 611  
 612          $text = strip_tags($text, $allowed_tags); // PageLines - allow more tags
 613  
 614  
 615          $excerpt_length = apply_filters('excerpt_length', $excerpt_len );
 616          $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
 617  
 618          $words = preg_split('/[\n\r\t ]+/', $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
 619  
 620          if ( count($words) > $excerpt_length ) {
 621              array_pop($words);
 622              $text = implode(' ', $words);
 623              $text = $text . $excerpt_more;
 624          } else
 625              $text = implode(' ', $words);
 626  
 627      }
 628      return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
 629  }
 630  
 631  /**
 632   * Generates an really short excerpt from the content or postid for tweets, facebook etc
 633   *
 634   * @param int|object $post_or_id can be the post ID, or the actual $post object itself
 635   * @param int $words the amount of words to allow
 636   * @param string $excerpt_more the text that is applied to the end of the excerpt if we algorithically snip it
 637   * @return string the snipped excerpt or the manual excerpt if it exists
 638   */
 639  function pl_short_excerpt($post_or_id, $words = 10, $excerpt_more = ' [...]') {
 640  
 641      if ( is_object( $post_or_id ) )
 642          $postObj = $post_or_id;
 643      else $postObj = get_post($post_or_id);
 644  
 645      $raw_excerpt = $text = $postObj->post_excerpt;
 646      if ( '' == $text ) {
 647          $text = $postObj->post_content;
 648  
 649          $text = strip_shortcodes( $text );
 650  
 651          $text = sanitize_text_field( $text );
 652  
 653          $text = apply_filters('the_content', $text);
 654          $text = str_replace(']]>', ']]&gt;', $text);
 655          $text = strip_tags($text);
 656          $excerpt_length = $words;
 657  
 658          $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
 659          if ( count($words) > $excerpt_length ) {
 660              array_pop($words);
 661              $text = implode(' ', $words);
 662              $text = $text . $excerpt_more;
 663          } else {
 664              $text = implode(' ', $words);
 665          }
 666      }
 667      return $text;
 668  }
 669  
 670  
 671  /**
 672   * PageLines Nav Classes
 673   *
 674   * Returns nav menu class `sf-menu` which will allow the "superfish" JavaScript to work
 675   *
 676   * @package     PageLines Framework
 677   * @subpackage  Functions Library
 678   * @since       1.1.0
 679   *
 680   * @internal    see ..\sections\nav\script.superfish.js
 681   * @internal    see ..\sections\nav\style.superfish.css
 682   *
 683   * @return      string - CSS classes
 684   */
 685  function pagelines_nav_classes(){
 686  
 687      $additional_menu_classes = '';
 688  
 689      if(ploption('enable_drop_down'))
 690          $additional_menu_classes .= ' sf-menu';
 691  
 692      return $additional_menu_classes;
 693  }
 694  
 695  /**
 696   *
 697   *  Loads Special PageLines CSS Files, Optimized
 698   *
 699   *  @package PageLines DMS
 700   *  @subpackage Functions Library
 701   *  @since 1.2.0
 702   *
 703   */
 704  function pagelines_draw_css( $css_url, $id = '', $enqueue = false){
 705      echo '<link rel="stylesheet" href="'.$css_url.'" />'."\n";
 706  }
 707  
 708  
 709  /**
 710   *
 711   *  Abstracts the Enqueue of Stylesheets, fixes bbPress issues with dropping hooks
 712   *
 713   *  @package PageLines DMS
 714   *  @since 1.3.0
 715   *
 716   */
 717  function pagelines_load_css( $css_url, $id, $hash = PL_CORE_VERSION, $enqueue = true){
 718  
 719      if(pagelines_bbpress_forum()){
 720          printf('<link rel="stylesheet" id="%s"  href="%s?ver=%s" type="text/css" />%s', $id, $css_url, $hash, "\n");
 721      } else {
 722          wp_register_style($id, $css_url, array(), $hash, 'all');
 723          wp_enqueue_style( $id );
 724      }
 725  
 726  }
 727  
 728  /**
 729   *
 730   *  Loading CSS using relative path to theme root. This allows dynamic versioning, overriding in child theme
 731   *
 732   *  @package PageLines DMS
 733   *  @since 1.4.0
 734   *
 735   */
 736  function pagelines_load_css_relative( $relative_style_url, $id){
 737  
 738      $rurl = '/' . $relative_style_url;
 739  
 740      if( is_file(get_stylesheet_directory() . $rurl ) ){
 741  
 742          $cache_ver = pl_cache_version( get_stylesheet_directory() . $rurl );
 743  
 744          pagelines_load_css( PL_CHILD_URL . $rurl , $id, $cache_ver);
 745  
 746      } elseif(is_file(get_template_directory() . $rurl) ){
 747  
 748          $cache_ver = pl_cache_version( get_template_directory() . $rurl );
 749  
 750          pagelines_load_css( PL_PARENT_URL . $rurl , $id, $cache_ver);
 751  
 752      }
 753  
 754  
 755  }
 756  
 757  /**
 758   *
 759   * Get cache version number
 760   *
 761   *
 762   */
 763  function pl_cache_version( $path, $version = PL_CORE_VERSION ){
 764      $date_modified = filemtime( $path );
 765      $cache_ver = str_replace('.', '', $version) . '-' . date('mdGis', $date_modified);
 766  
 767      return $cache_ver;
 768  }
 769  
 770  /**
 771   *
 772   *  Get Stylesheet Version
 773   *
 774   *  @package PageLines DMS
 775   *  @since 1.4.0
 776   *
 777   */
 778  function pagelines_get_style_ver( $tpath = false ){
 779  
 780      // Get cache number that accounts for edits to base.css or style.css
 781      if( is_file(get_stylesheet_directory() .'/base.css') && !$tpath ){
 782          $date_modified = filemtime( get_stylesheet_directory() .'/base.css' );
 783          $cache_ver = str_replace('.', '', PL_CHILD_VERSION) . '-' . date('mdGis', $date_modified);
 784      } elseif(is_file(get_stylesheet_directory() .'/style.css') && !$tpath ){
 785          $date_modified = filemtime( get_stylesheet_directory() .'/style.css' );
 786          $cache_ver = str_replace('.', '', PL_CORE_VERSION) .'-'.date('mdGis', $date_modified);
 787      } elseif(is_file(get_template_directory() .'/style.css')){
 788          $date_modified = filemtime( get_template_directory() .'/style.css' );
 789          $cache_ver = str_replace('.', '', PL_CORE_VERSION) .'-'.date('mdGis', $date_modified);
 790      } else {
 791          $cache_ver = PL_CORE_VERSION;
 792      }
 793  
 794  
 795      return $cache_ver;
 796  
 797  }
 798  
 799  /**
 800   * Debugging, prints nice array.
 801   * Sends to the footer in all cases.
 802   *
 803   * @since 1.5.0
 804   */
 805  function plprint( $data, $title = false, $echo = false) {
 806  
 807      if ( ! is_pl_debug() || ! current_user_can('manage_options') )
 808          return;
 809  
 810      ob_start();
 811  
 812          echo '<pre class="plprint">';
 813  
 814          if ( $title )
 815              printf('<h3>%s</h3>', $title);
 816  
 817          echo esc_html( print_r( $data, true ) );
 818  
 819          echo '</pre>';
 820  
 821      $data = ob_get_clean();
 822  
 823      if ( $echo )
 824          echo $data;
 825      elseif ( false === $echo )
 826          add_action( 'shutdown', create_function( '', sprintf('echo \'%s\';', $data) ) );
 827      else
 828          return $data;
 829  }
 830  
 831  function plcomment( $data, $title = 'DEBUG', $type = 'html' ) {
 832  
 833  
 834      if( is_pl_debug() ){
 835      $open    = ( 'html' == $type ) ? "\n<!-- " : "\n/* ";
 836      $close    = ( 'html' == $type ) ? " -->\n" : "*/\n";
 837  
 838      $pre = sprintf( '%s START %s %s', $open, $title, $close );
 839      $post = sprintf( '%s END %s %s', $open, $title, $close );
 840  
 841      return $pre . $data . $post;
 842  
 843      } else {
 844          return $data;
 845      }
 846  }
 847  
 848  /**
 849   * Creates Upload Folders for PageLines stuff
 850   *
 851   * @return true if successful
 852   **/
 853  function pagelines_make_uploads($txt = 'Load'){
 854  add_filter('request_filesystem_credentials', '__return_true' );
 855  
 856      $method = '';
 857      $url = 'themes.php?page=pagelines';
 858  
 859      if (is_writable(PAGELINES_DCSS)){
 860          $creds = request_filesystem_credentials($url, $method, false, false, null);
 861          if ( ! WP_Filesystem($creds) ) {
 862              // our credentials were no good, ask the user for them again
 863              request_filesystem_credentials($url, $method, true, false, null);
 864              return false;
 865          }
 866  
 867          global $wp_filesystem;
 868          if ( ! $wp_filesystem->put_contents( PAGELINES_DCSS, $txt, FS_CHMOD_FILE) ) {
 869              echo 'error saving file!';
 870              return false;
 871          }
 872      }
 873  
 874      return true;
 875  }
 876  /**
 877   * return array of PageLines plugins.
 878   * Since 2.0
 879   */
 880  function pagelines_register_plugins() {
 881  
 882      $pagelines_plugins = array();
 883      $plugins = get_option('active_plugins');
 884      if ( $plugins ) {
 885          foreach( $plugins as $plugin ) {
 886              $a = get_file_data( WP_PLUGIN_DIR . '/' . $plugin, $default_headers = array( 'pagelines' => 'PageLines' ) );
 887              if ( !empty( $a['pagelines'] ) ) {
 888                  $pagelines_plugins[] = str_replace( '.php', '', basename($plugin) );
 889              }
 890  
 891          }
 892      }
 893      return $pagelines_plugins;
 894  }
 895  
 896  /**
 897   *
 898   * Return sorted array based on supplied key
 899   *
 900   * @since 2.0
 901   * @return sorted array
 902   */
 903  function pagelines_array_sort( $a, $subkey, $pre = null, $dec = null ) {
 904  
 905      if ( ! is_array( $a) || ( is_array( $a ) && count( $a ) <= 1 ) )
 906          return $a;
 907  
 908      foreach( $a as $k => $v ) {
 909          $b[$k] = ( $pre ) ? strtolower( $v[$pre][$subkey] ) : strtolower( $v[$subkey] );
 910      }
 911      ( !$dec ) ? asort( $b ) : arsort($b);
 912      foreach( $b as $key => $val ) {
 913          $c[] = $a[$key];
 914      }
 915      return $c;
 916  }
 917  
 918  /**
 919   *
 920   * Polishes a Key for UI presentation
 921   *
 922   * @since 2.0
 923   * @return String
 924   */
 925  function ui_key($key){
 926  
 927      return ucwords( str_replace( '_', ' ', str_replace( 'pl_', ' ', $key) ) );
 928  }
 929  
 930  /**
 931   *
 932   * Return latest tweet as (array) or single tweet text.
 933   * Tweets are stored in the db
 934   *
 935   * @since 2.0b13
 936   * @return array
 937   */
 938  function pagelines_get_tweets( $username, $latest = null) {
 939  
 940  
 941          // Fetch the tweets from the db
 942          // Set the array into a transient for easy reuse
 943          // If we get an error store it.
 944  
 945          if ( false === ( $tweets = get_transient( 'section-twitter-' . $username ) ) ) {
 946              $params = array(
 947                  'screen_name'=>$username, // Twitter account name
 948                  'trim_user'=>true, // only basic user data (slims the result)
 949                  'include_entities'=>false, // as of Sept 2010 entities were not included in all applicable Tweets. regex still better
 950                  'include_rts' => true
 951              );
 952  
 953              /**
 954               * The exclude_replies parameter filters out replies on the server. If combined with count it only filters that number of tweets (not all tweets up to the requested count)
 955               * If we are not filtering out replies then we should specify our requested tweet count
 956               */
 957  
 958              $twitter_json_url = esc_url_raw( 'http://api.twitter.com/1/statuses/user_timeline.json?' . http_build_query( $params ), array( 'http', 'https' ) );
 959              unset( $params );
 960              $response = wp_remote_get( $twitter_json_url, array( 'User-Agent' => 'WordPress.com Twitter Widget' ) );
 961              $response_code = wp_remote_retrieve_response_code( $response );
 962              if ( 200 == $response_code ) {
 963                  $tweets = wp_remote_retrieve_body( $response );
 964                  $tweets = json_decode( $tweets, true );
 965                  $expire = 900;
 966                  if ( !is_array( $tweets ) || isset( $tweets['error'] ) ) {
 967                      $tweets = 'error';
 968                      $expire = 300;
 969                  }
 970              } else {
 971                  $tweets = 'error';
 972                  $expire = 300;
 973                  set_transient( 'section-twitter-response-code-' . $username, $response_code, $expire );
 974              }
 975  
 976              set_transient( 'section-twitter-' . $username, $tweets, $expire );
 977          }
 978  
 979          // We should have a list of tweets for $username or an error code to return.
 980  
 981          if ( 'error' != $tweets ) { // Tweets are good, return the array or a single if asked for ($latest)
 982  
 983              if ( $latest && is_array( $tweets ) && isset( $tweets[0]['text'] ) )
 984                  return  $tweets[0];
 985              elseif ( is_array( $latest ) )
 986                  return $latest;
 987          } else {
 988  
 989              // We couldnt get the tweets so lets cycle through the possible errors.
 990  
 991              $error = get_transient( 'section-twitter-response-code-' . $username );
 992              switch( $error ) {
 993  
 994                  case 401:
 995                      $text = wp_kses( sprintf( __( "Error: Please make sure the Twitter account is <a href='%s'>public</a>.", 'pagelines' ), 'http://support.twitter.com/forums/10711/entries/14016' ), array( 'a' => array( 'href' => true ) ) );
 996                  break;
 997  
 998                  case 403:
 999                      $text = __( 'Error 403: Your IP is being rate limited by Twitter.', 'pagelines' );
1000                  break;
1001  
1002                  case 404:
1003                      $text = __( 'Error 404: Your username was not found on Twitter.', 'pagelines' );
1004                  break;
1005  
1006                  case 420:
1007                      $text = __( 'Error 420: Your IP is being rate limited by Twitter.', 'pagelines' );
1008                  break;
1009  
1010                  case 502:
1011                      $text = __( 'Error 502: Twitter is being upgraded.', 'pagelines' );
1012                  break;
1013  
1014                  default:
1015                      $text = __( 'Unknown Twitter error.', 'pagelines' );
1016                  break;
1017              }
1018              return $text;
1019          }
1020  }
1021  
1022  
1023  /**
1024   *
1025   * @TODO document
1026   *
1027   */
1028  function pagelines_tweet_clickable( $tweet ) {
1029  
1030      $regex = '/http([s]?):\/\/([^\ \)$]*)/';
1031      $link_pattern = '<a href="http$1://$2" rel="nofollow" title="$2">http$1://$2</a>';
1032      $tweet = preg_replace($regex,$link_pattern,$tweet);
1033      $regex = '/@([a-zA-Z0-9_]*)/';
1034      $link_pattern = '<a href="http://twitter.com/$1" title="$1 profile on Twitter" rel="nofollow">@$1</a>';
1035      $tweet = preg_replace($regex,$link_pattern,$tweet);
1036      $regex = '/\#([a-zA-Z0-9_]*)/';
1037      $link_pattern = '<a href="https://twitter.com/search?q=%23$1&src=hash" title="Search for $1 on Twitter" rel="nofollow">#$1</a>';
1038      $tweet = preg_replace($regex,$link_pattern,$tweet);
1039  
1040      return $tweet;
1041  
1042  }
1043  
1044  
1045  /**
1046   *
1047   * @TODO document
1048   *
1049   */
1050  function pl_admin_is_page(){
1051      global $post;
1052  
1053      if( (isset($_GET['post_type']) && $_GET['post_type'] == 'page')  || (isset($post) && $post->post_type == 'page') )
1054          return true;
1055      else
1056          return false;
1057  
1058  }
1059  
1060  
1061  /**
1062   *
1063   * @TODO document
1064   *
1065   */
1066  function pl_file_get_contents( $filename ) {
1067  
1068      if ( is_file( $filename ) ) {
1069  
1070          $file = file( $filename, FILE_SKIP_EMPTY_LINES );
1071          $out = '';
1072          if( is_array( $file ) )
1073              foreach( $file as $contents )
1074                  $out .= $contents;
1075  
1076          if( $out )
1077              return $out;
1078          else
1079              return false;
1080      }
1081  }
1082  
1083  
1084  /**
1085   *
1086   * @TODO document
1087   *
1088   */
1089  function pl_detect_ie( $version = false ) {
1090  
1091      global $is_IE;
1092      if ( ! $version && $is_IE ) {
1093  
1094          return round( substr($_SERVER['HTTP_USER_AGENT'], strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') + 5, 3) );
1095      }
1096  
1097      if ( $is_IE && is_int( $version ) && stristr( $_SERVER['HTTP_USER_AGENT'], sprintf( 'msie %s', $version ) ) )
1098          return true;
1099      else
1100          return false;
1101  }
1102  
1103  /**
1104   * Search in an array, return full info.
1105   */
1106  function array_search_ext($arr, $search, $exact = true, $trav_keys = null)
1107  {
1108    if(!is_array($arr) || !$search || ($trav_keys && !is_array($trav_keys))) return false;
1109    $res_arr = array();
1110    foreach($arr as $key => $val)
1111    {
1112      $used_keys = $trav_keys ? array_merge($trav_keys, array($key)) : array($key);
1113      if(($key === $search) || (!$exact && (strpos(strtolower($key), strtolower($search)) !== false))) $res_arr[] = array('type' => "key", 'hit' => $key, 'keys' => $used_keys, 'val' => $val);
1114      if(is_array($val) && ($children_res = array_search_ext($val, $search, $exact, $used_keys))) $res_arr = array_merge($res_arr, $children_res);
1115      else if(($val === $search) || (!$exact && (strpos(strtolower($val), strtolower($search)) !== false))) $res_arr[] = array('type' => "val", 'hit' => $val, 'keys' => $used_keys, 'val' => $val);
1116    }
1117    return $res_arr ? $res_arr : false;
1118  }
1119  
1120  /**
1121   * PageLines Register Sidebar
1122   *
1123   * Registers sidebars with an optional priority.
1124   *
1125   * @param   $args
1126   * @param   null $priorty - numeric value
1127   *
1128   * @uses    plotion( 'enable_sidebar_reorder' ) - i.e.: prioritization
1129   * @uses    pagelines_sidebars class
1130   *
1131   * @link    http://www.pagelines.com/wiki/Pagelines_register_sidebar
1132   */
1133  function pagelines_register_sidebar( $args, $priorty = null ) {
1134  
1135      register_sidebar( $args );
1136  }
1137  
1138  /**
1139   * Insert into array at a position.
1140   *
1141   * @param $orig array Original array.
1142   * @param $new array Array to insert.
1143   * @param $offset int Offset
1144   * @return array
1145   */
1146  function pl_insert_into_array( $orig, $new, $offset ) {
1147  
1148      $newArray = array_slice($orig, 0, $offset, true) +
1149                  $new +
1150                  array_slice($orig, $offset, NULL, true);
1151      return $newArray;
1152  }
1153  
1154  
1155  /**
1156   * Insert into array before or after a key.
1157   *
1158   * @param $array array Original array.
1159   * @param $key str Key to find.
1160   * @param $insert_array array The array data to insert.
1161   * @param $before bool Insert before or after.
1162   * @return array
1163   */
1164  function pl_array_insert( $array, $key, $insert_array, $before = FALSE ) {
1165      $done = FALSE;
1166      foreach ($array as $array_key => $array_val) {
1167          if (!$before) {
1168              $new_array[$array_key] = $array_val;
1169          }
1170          if ($array_key == $key && !$done) {
1171              foreach ($insert_array as $insert_array_key => $insert_array_val) {
1172                  $new_array[$insert_array_key] = $insert_array_val;
1173              }
1174              $done = TRUE;
1175          }
1176          if ($before) {
1177              $new_array[$array_key] = $array_val;
1178          }
1179      }
1180      if (!$done) {
1181          $new_array = array_merge($array, $insert_array);
1182      }
1183      // Put the new array in the place of the original.
1184      return $new_array;
1185  }
1186  
1187  /**
1188   * Display a banner if suppoerted plugin is detected during template_redirect.
1189   *
1190   */
1191  function pl_check_integrations() {
1192  
1193      $integrations = array(
1194  
1195          'bbpress' => array(
1196  
1197              'function'    => 'is_bbpress',
1198              'plugin'    => 'pagelines-bbpress',
1199              'url'        => 'http://www.pagelines.com/store/plugins/pagelines-bbpress/',
1200              'name'        => 'bbPress',
1201              'class'        => 'PageLinesBBPress'
1202  
1203          ),
1204          'jigoshop' => array(
1205  
1206              'function'    => 'is_jigoshop',
1207              'plugin'    => 'pagelines-jigoshop',
1208              'url'        => 'http://www.pagelines.com/store/plugins/pagelines-jigoshop/',
1209              'name'        => 'Jigoshop',
1210              'class'        => 'PageLinesJigoShop'
1211          ),
1212      );
1213  
1214      foreach( $integrations as $i => $data ) {
1215  
1216          if( function_exists( $data['function'] ) ) {
1217  
1218              if( $data['function']() && ! class_exists( $data['class'] ) )
1219                  pl_check_integrations_banner( $data );
1220          }
1221      }
1222  }
1223  
1224  function pl_check_integrations_banner( $data ) {
1225  
1226      if( current_user_can('edit_themes') ){
1227  
1228          $banner_title = sprintf( '<h3 class="banner_title wicon">%s was detected.</h3>', $data['name'] );
1229  
1230          $text = 'Looks like your running a supported plugin but your not using our integrations whatsit.';
1231  
1232          $link_text = 'Get it from the store now!';
1233  
1234          $link = sprintf('<a href="%s">%s</a>', $data['url'], $link_text . ' &rarr;');
1235  
1236          echo sprintf('<div class="banner setup_area"><div class="banner_pad">%s <div class="banner_text subhead">%s<br/> %s</div></div></div>', $banner_title, $text, $link);
1237  
1238  
1239      }
1240  }
1241  
1242  /**
1243   * Return the raw URI
1244   *
1245   * @param $full bool Show full or just request.
1246   * @return string
1247   */
1248  function pl_get_uri( $full = true ) {
1249  
1250      if ( $full )
1251          return  $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
1252      else
1253          return  $_SERVER["REQUEST_URI"];
1254  }
1255  
1256  /**
1257   * Is framework in debug mode?
1258   *
1259   * @return bool
1260   */
1261  function is_pl_debug() {
1262  
1263      if ( defined( 'PL_DEV' ) && PL_DEV )
1264          return true;
1265      if ( pl_setting( 'enable_debug' ) )
1266          return true;
1267  }
1268  
1269  /**
1270   * Show debug info in footer ( wrapped in tags )
1271   *
1272   */
1273  function pl_debug( $text = '', $before = "\n/*", $after = '*/' ) {
1274  
1275      if ( ! is_pl_debug() )
1276          return;
1277  
1278      $out = sprintf( 'echo "%s %s %s";', $before, $text, $after );
1279      add_action( 'shutdown', create_function( '', $out ), 9999 );
1280  
1281  }
1282  
1283  /**
1284  *
1285  * @TODO do
1286  *
1287  */
1288  function inline_css_markup($id, $css, $echo = true){
1289      $mark = sprintf('%2$s<style type="text/css" id="%3$s">%2$s %1$s %2$s</style>%2$s', $css, "\n", $id);
1290  
1291      if($echo)
1292          echo $mark;
1293      else
1294          return $mark;
1295  }
1296  
1297  function pl_get_plus_link() {
1298  
1299      if( VDEV )
1300          return ADD_PLUS_DEV;
1301      else
1302          return ADD_PLUS_PRO;
1303  }


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