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