[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/includes/ -> class.shortcodes.php (source)

   1  <?php
   2  /**
   3   * PageLines_ShortCodes
   4   *
   5   * This file defines return functions to be used as shortcodes by users and developers
   6   *
   7   * @package     PageLines Framework
   8   * @subpackage  Sections
   9   * @since       2.2
  10   *
  11   *  SHORTCODE TABLE OF CONTENTS
  12   *  1.  Bookmark
  13   *  2.  Pagename
  14   *  3.  Theme URL
  15   *  4.  Google Maps
  16   *  5.  Google Charts
  17   *  6.  Post Feed
  18   *  7.  Dynamic Box
  19   *  8.  Container
  20   *  9.  Post Edit
  21   *  10. Post Categories
  22   *  11. Post Tags
  23   *  12. Post Type
  24   *  13. Post Comments
  25   *  14. Post Authors Archive
  26   *  15. Post Author URL
  27   *  16. Post Author Display Name
  28   *  17. Post Date
  29   *  18. Pinterest Button
  30   *      Google Plus
  31   *      Linkedin Share
  32   *  19. Tweet Button
  33   *  20. Like Button
  34   *  21. Show Authors
  35   *  22. Codebox
  36   *  23. Labels
  37   *  24. Badgets
  38   *  25. Alertbox
  39   *  26. Blockquote
  40   *  27. Button
  41   *  28. Button Group
  42   *  29. Button Dropdown
  43   *  30. Split Button Dropdown
  44   *  31. Tooltip
  45   *  32. Popover
  46   *  32. Accordion
  47   *  34. Carousel
  48   *  35. Tabs
  49   *  36. Modal Popup
  50   *  37. Post Time
  51   *  38. PageLines Buttons (orig)
  52   *  39. Enqueue jQuery
  53   *  40. Enqueue Bootstrap JS
  54   */
  55  
  56  class PageLines_ShortCodes {
  57  
  58  
  59  	function __construct() {
  60  
  61          self::register_shortcodes( $this->shortcodes_core() );
  62  
  63          // Make widgets process shortcodes
  64          add_filter( 'widget_text', 'do_shortcode' );
  65  //        add_action( 'template_redirect', array( &$this, 'filters' ) );
  66          add_action('wp_footer',array( &$this, 'print_carousel_js' ), 21);
  67  
  68      }
  69  
  70  	private function shortcodes_core() {
  71  
  72          $core = array(
  73  
  74              'button'                    =>    array( 'function' => 'pagelines_button_shortcode' ),
  75              'post_time'                    =>    array( 'function' => 'pagelines_post_time_shortcode' ),
  76  
  77              'pl_button'                    =>    array( 'function' => 'pl_button_shortcode' ),
  78              'pl_buttongroup'            =>  array( 'function' => 'pl_buttongroup_shortcode' ),
  79              'pl_buttondropdown'         =>    array( 'function' => 'pl_buttondropdown_shortcode' ),
  80              'pl_splitbuttondropdown'    =>  array( 'function' => 'pl_splitbuttondropdown_shortcode' ),
  81              'pl_tooltip'                =>  array( 'function' => 'pl_tooltip_shortcode' ),
  82              'pl_popover'                =>    array( 'function' => 'pl_popover_shortcode' ),
  83              'pl_accordion'              =>    array( 'function' => 'pl_accordion_shortcode' ),
  84              'pl_accordioncontent'       =>  array( 'function' => 'pl_accordioncontent_shortcode' ),
  85              'pl_carousel'               =>    array( 'function' => 'pl_carousel_shortcode' ),
  86              'pl_carouselimage'          =>    array( 'function' => 'pl_carouselimage_shortcode' ),
  87              'pl_tabs'                   =>    array( 'function' => 'pl_tabs_shortcode' ),
  88              'pl_tabtitlesection'        =>    array( 'function' => 'pl_tabtitlesection_shortcode' ),
  89              'pl_tabtitle'               =>    array( 'function' => 'pl_tabtitle_shortcode' ),
  90              'pl_tabcontentsection'      =>    array( 'function' => 'pl_tabcontentsection_shortcode' ),
  91              'pl_tabcontent'             =>    array( 'function' => 'pl_tabcontent_shortcode' ),
  92              'pl_modal'                    =>    array( 'function' => 'pl_modal_shortcode' ),
  93              'pl_blockquote'                =>    array( 'function' => 'pl_blockquote_shortcode' ),
  94              'pl_alertbox'                =>    array( 'function' => 'pl_alertbox_shortcode' ),
  95              'show_authors'                =>    array( 'function' => 'show_multiple_authors' ),
  96              'pl_codebox'                =>    array( 'function' =>    'pl_codebox_shortcode' ),
  97              'pl_label'                    =>    array( 'function' => 'pl_label_shortcode' ),
  98              'pl_badge'                    =>    array( 'function' => 'pl_badge_shortcode' ),
  99              'googleplus'                =>    array( 'function' => 'pl_googleplus_button' ),
 100              'linkedin'                    =>    array( 'function' => 'pl_linkedinshare_button' ),
 101              'like_button'                =>    array( 'function' => 'pl_facebook_shortcode' ),
 102              'twitter_button'            =>    array( 'function' => 'pl_twitter_button' ),
 103              'pinterest'                    =>    array( 'function' => 'pl_pinterest_button' ),
 104              'post_date'                    =>    array( 'function' => 'pagelines_post_date_shortcode' ),
 105              'post_author'                =>    array( 'function' => 'pagelines_post_author_shortcode' ),
 106              'post_author_link'            =>    array( 'function' => 'pagelines_post_author_link_shortcode' ),
 107              'post_author_posts_link'    =>    array( 'function' => 'pagelines_post_author_posts_link_shortcode' ),
 108              'post_comments'                =>    array( 'function' => 'pagelines_post_comments_shortcode' ),
 109              'post_tags'                    =>    array( 'function' => 'pagelines_post_tags_shortcode' ),
 110              'post_categories'            =>    array( 'function' => 'pagelines_post_categories_shortcode' ),
 111              'post_type'                    =>    array( 'function' => 'pagelines_post_type_shortcode' ),
 112              'post_edit'                    =>    array( 'function' => 'pagelines_post_edit_shortcode' ),
 113              'container'                    =>    array( 'function' => 'dynamic_container' ),
 114              'cbox'                        =>    array( 'function' => 'dynamic_box' ),
 115              'post_feed'                    =>    array( 'function' => 'get_postfeed' ),
 116              'chart'                        =>    array( 'function' => 'chart_shortcode' ),
 117              'googlemap'                    =>    array( 'function' => 'googleMaps' ),
 118              'themeurl'                    =>    array( 'function' => 'get_themeurl' ),
 119              'link'                        =>    array( 'function' => 'create_pagelink' ),
 120              'bookmark'                    =>    array( 'function' => 'bookmark_link' ),
 121              'pl_raw'                    =>    array( 'function' => 'do_raw' ),
 122              'pl_video'                    =>    array( 'function' => 'pl_video_shortcode' )
 123              );
 124  
 125          return $core;
 126      }
 127  
 128  	function do_raw() {
 129  
 130          global $post;
 131          $str = $post->post_content;
 132  
 133          $start = '[pl_raw]';
 134          $end = '[/pl_raw]';
 135          $stpos = strpos( $str, $start );
 136          if ( $stpos === FALSE )
 137              return '';
 138          $stpos += strlen( $start );
 139          $endpos = strpos( $str, $end, $stpos );
 140          if ( $endpos === FALSE )
 141              return '';
 142          $len = $endpos - $stpos;
 143          return do_shortcode( substr( $str, $stpos, $len ) );
 144      }
 145  
 146  
 147      // 1. Return link in page based on Bookmark
 148      // USAGE : [bookmark id="21" text="Link Text"]
 149  	function bookmark_link( $atts ) {
 150  
 151           //extract page name from the shortcode attributes
 152           extract( shortcode_atts( array( 'id' => '0', 'text' => '' ), $atts ) );
 153  
 154           //convert the page name to a page ID
 155           $bookmark = get_bookmark( $id );
 156  
 157          if( isset( $text ) ) $ltext = $text;
 158          else $ltext = $bookmark->link_name;;
 159  
 160  
 161          $pagelink = "<a href=\"".$bookmark->link_url."\" target=\"".$bookmark->link_target."\">".$ltext."</a>";
 162           return $pagelink;
 163      }
 164  
 165      // 2. Function for creating a link from a page name
 166      // USAGE : [link pagename="My Example Page" linktext="Link Text"]
 167  	function create_pagelink( $atts ) {
 168  
 169           //extract page name from the shortcode attributes
 170           extract( shortcode_atts( array( 'pagename' => 'home', 'linktext' => '' ), $atts ) );
 171  
 172           //convert the page name to a page ID
 173           $page = get_page_by_title( $pagename );
 174  
 175           //use page ID to get the permalink for the page
 176           $link = get_permalink( $page );
 177  
 178           //create the link and output
 179           $pagelink = "<a href=\"".$link."\">".$linktext."</a>";
 180  
 181           return $pagelink;
 182      }
 183  
 184      // 3. Function for getting template path
 185      // USAGE: [themeurl]
 186  	function get_themeurl( $atts ){ return get_template_directory_uri();     }
 187  
 188      // 4. GOOGLE MAPS //////////////////////////////////////////////////
 189  
 190          // you can use the default width and height
 191          // The only requirement is to add the address of the map
 192          // Example:
 193          // [googlemap address="san diego, ca"]
 194          // or with options
 195          // [googlemap width="200" height="200" address="San Francisco, CA 92109"]
 196  	function googleMaps( $atts, $content = null ) {
 197  
 198           extract( shortcode_atts( array(
 199  
 200           'width'    => '480',
 201           'height'    => '480',
 202           'locale'    => 'en',
 203           'address'    => ''
 204       ), $atts ) );
 205       $src = "http://maps.google.com/maps?f=q&source=s_q&hl=".$locale."&q=".$address;
 206       return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&amp;output=embed"></iframe>';
 207      }
 208  
 209      // 5. GOOGLE CHARTS  //////////////////////////////////////////////////
 210  
 211          // Gets Google charts
 212          // USAGE
 213          //        [chart data="0,12,24,26,32,64,54,24,22,20,8,2,0,0,3" bg="F7F9FA" size="200x100" type="sparkline"]
 214          //        [chart data="41.52,37.79,20.67,0.03" bg="F7F9FA" labels="Reffering+sites|Search+Engines|Direct+traffic|Other" colors="058DC7,50B432,ED561B,EDEF00" size="488x200" title="Traffic Sources" type="pie"]
 215  
 216  	function chart_shortcode( $atts ) {
 217          extract( shortcode_atts( array(
 218              'data' => '',
 219              'colors' => '',
 220              'size' => '400x200',
 221              'bg' => 'ffffff',
 222              'title' => '',
 223              'labels' => '',
 224              'advanced' => '',
 225              'type' => 'pie'
 226          ), $atts ) );
 227  
 228                  switch ( $type ) {
 229                      case 'line' :
 230                          $charttype = 'lc'; break;
 231                      case 'xyline' :
 232                          $charttype = 'lxy'; break;
 233                      case 'sparkline' :
 234                          $charttype = 'ls'; break;
 235                      case 'meter' :
 236                          $charttype = 'gom'; break;
 237                      case 'scatter' :
 238                          $charttype = 's'; break;
 239                      case 'venn' :
 240                          $charttype = 'v'; break;
 241                      case 'pie' :
 242                          $charttype = 'p3'; break;
 243                      case 'pie2d' :
 244                          $charttype = 'p'; break;
 245                      default :
 246                          $charttype = $type;
 247                      break;
 248                  }
 249                  $string = '';
 250                  if ( $title ) $string .= '&chtt='.$title.'';
 251                  if ( $labels ) $string .= '&chl='.$labels.'';
 252                  if ( $colors ) $string .= '&chco='.$colors.'';
 253                  $string .= '&chs='.$size.'';
 254                  $string .= '&chd=t:'.$data.'';
 255                  $string .= '&chf=bg,s,'.$bg.'';
 256  
 257          return '<img title="'.$title.'" src="http://chart.apis.google.com/chart?cht='.$charttype.''.$string.$advanced.'" alt="'.$title.'" />';
 258      }
 259  
 260      // 6. GET POST FIELD BY OFFSET //////////////////////////////////////////////////
 261      // Get a post based on offset from the last post published (0 for last post)
 262      // USAGE: [postfeed field="post_title"  offset="0" customfield="true" ]
 263  	function get_postfeed( $atts ) {
 264  
 265          //extract page name from the shortcode attributes
 266          extract( shortcode_atts( array( 'field' => 'post_title', 'offset' => '0', 'customfield' => "" ), $atts ) );
 267  
 268          //returns an array of objects
 269          $thepost = get_posts( 'numberposts=1&offset='.$offset );
 270  
 271          if( $customfield == 'true' ){
 272              $postfield = get_post_meta( $thepost[0]->ID, $field, true );
 273          }else{
 274              $postfield = $thepost[0]->$field;
 275          }
 276          return $postfield;
 277      }
 278  
 279      // 7. Created a container for dynamic html layout
 280      // USAGE: [cbox width="50%" leftgutter="15px" rightgutter="0px"] html box content[/cbox]
 281  	function dynamic_box( $atts, $content = null ) {
 282  
 283           //extract page name from the shortcode attributes
 284           extract( shortcode_atts( array( 'width' => '30%', 'leftgutter' => '10px', 'rightgutter' => '0px' ), $atts ) );
 285  
 286           $cbox = '<div class="cbox" style="float:left;width:'.$width.';"><div class="cbox_pad" style="margin: 0px '.$rightgutter.' 0px '.$leftgutter.'">'.do_shortcode( $content ).'</div></div>';
 287  
 288      return $cbox;
 289      }
 290  
 291      // 8. Created a container for dynamic html layout
 292      // USAGE: [container id="mycontainer" class="myclass"] 'cboxes' see shortcode below [/container]
 293  	function dynamic_container( $atts, $content = null ) {
 294  
 295           //extract page name from the shortcode attributes
 296           extract( shortcode_atts( array( 'id' => 'container', 'class' => '' ), $atts ) );
 297  
 298           $container = '<div style="width: 100%;" class="container">'.do_shortcode( $content ).'<div class="clear"></div></div>';
 299  
 300           return $container;
 301      }
 302  
 303      /**
 304       * 9. This function produces the edit post link for logged in users
 305       *
 306       * @example <code>[post_edit]</code> is the default usage
 307       * @example <code>[post_edit link="Edit", before="<b>" after="</b>"]</code>
 308       */
 309  	function pagelines_post_edit_shortcode( $atts ) {
 310  
 311          $defaults = array(
 312              'link' => __( "<span class='editpage sc'>Edit</span>", 'pagelines' ),
 313              'before' => '[',
 314              'after' => ']'
 315          );
 316          $atts = shortcode_atts( $defaults, $atts );
 317  
 318          // Prevent automatic WP Output
 319          ob_start();
 320          edit_post_link( $atts['link'], $atts['before'], $atts['after'] ); // if logged in
 321          $edit = ob_get_clean();
 322  
 323          $output = $edit;
 324  
 325          return apply_filters( 'pagelines_post_edit_shortcode', $output, $atts );
 326  
 327      }
 328  
 329      /**
 330       * 10. This function produces the category link list
 331       *
 332       * @example <code>[post_categories]</code> is the default usage
 333       * @example <code>[post_categories sep=", "]</code>
 334       */
 335  	function pagelines_post_categories_shortcode( $atts ) {
 336  
 337          $defaults = array(
 338              'sep' => ', ',
 339              'before' => '',
 340              'after' => ''
 341          );
 342          $atts = shortcode_atts( $defaults, $atts );
 343  
 344          $cats = get_the_category_list( trim( $atts['sep'] ) . ' ' );
 345  
 346          $output = sprintf( '<span class="categories sc">%2$s%1$s%3$s</span> ', $cats, $atts['before'], $atts['after'] );
 347  
 348          return apply_filters( 'pagelines_post_categories_shortcode', $output, $atts );
 349  
 350      }
 351  
 352      /**
 353       * 11. This function produces the tag link list
 354       *
 355       * @example <code>[post_tags]</code> is the default usage
 356       * @example <code>[post_tags sep=", " before="Tags: " after="bar"]</code>
 357       */
 358  	function pagelines_post_tags_shortcode( $atts ) {
 359  
 360          $defaults = array(
 361              'sep' => ', ',
 362              'before' => __( 'Tagged With: ', 'pagelines' ),
 363              'after' => ''
 364          );
 365          $atts = shortcode_atts( $defaults, $atts );
 366  
 367          $tags = get_the_tag_list( $atts['before'], trim( $atts['sep'] ) . ' ', $atts['after'] );
 368  
 369          if ( !$tags ) return;
 370  
 371          $output = sprintf( '<span class="tags sc">%s</span> ', $tags );
 372  
 373          return apply_filters( 'pagelines_post_tags_shortcode', $output, $atts );
 374  
 375      }
 376  
 377      /**
 378       * 12. This function produces a post type link.
 379       *
 380       * @example <code>[post_type]</code> is the default usage
 381       * @example <code>[post_type before="Type: " after="bar"]</code>
 382       */
 383  	function pagelines_post_type_shortcode( $atts ) {
 384  
 385          $defaults = array(
 386              'before' => __( 'Type: ', 'pagelines' ),
 387              'after' => ''
 388          );
 389          $atts = shortcode_atts( $defaults, $atts );
 390  
 391          global $post;
 392  
 393          if ( $post->post_type == 'post' )
 394              return;
 395  
 396          $t = get_post_type_object( $post->post_type );
 397  
 398          $name = $t->labels->name;
 399  
 400          $type = sprintf( '%s%s%s', $atts['before'], $name, $atts['after'] );
 401          if( $t->has_archive )
 402              $output = sprintf( '<span class="type sc"><a href="%s">%s</a></span> ', get_post_type_archive_link( $t->name ), $type );
 403          else
 404              $output = sprintf( '<span class="type sc">%s</span> ', $type );
 405          return apply_filters( 'pagelines_post_type_shortcode', $output, $atts );
 406      }
 407  
 408      /**
 409       * 13. This function produces the comment link
 410       *
 411       * @example <code>[post_comments]</code> is the default usage
 412       * @example <code>[post_comments zero="No Comments" one="1 Comment" more="% Comments"]</code>
 413       */
 414  	function pagelines_post_comments_shortcode( $atts ) {
 415  
 416          $defaults = array(
 417              'zero' => __( 'Add Comment', 'pagelines' ),
 418              'one' => __( "<span class='num'>1</span> Comment", 'pagelines' ),
 419              'more' => __( "<span class='num'>%</span> Comments", 'pagelines' ),
 420              'hide_if_off' => 'disabled',
 421              'before' => '',
 422              'after' => ''
 423          );
 424          $atts = shortcode_atts( $defaults, $atts );
 425  
 426          if ( ( !comments_open() ) && $atts['hide_if_off'] === 'enabled' )
 427              return;
 428  
 429          // Prevent automatic WP Output
 430          ob_start();
 431          comments_number( $atts['zero'], $atts['one'], $atts['more'] );
 432          $comments = ob_get_clean();
 433  
 434          $comments = sprintf( '<a href="%s">%s</a>', $this->get_comment_link(), $comments );
 435  
 436          $output = sprintf( '<span class="post-comments sc">%2$s%1$s%3$s</span>', $comments, $atts['before'], $atts['after'] );
 437  
 438          return apply_filters( 'pagelines_post_comments_shortcode', $output, $atts );
 439      }
 440  
 441  	function get_comment_link() {
 442  
 443          $comment = '#wp-comments';
 444  
 445          if( function_exists( 'livefyre_show_comments' ) )
 446              $comment = '#lf_comment_stream';
 447  
 448          return sprintf( '%s%s', get_permalink(), $comment );
 449      }
 450  
 451      /**
 452       * 14. This function produces the author of the post (link to author archive)
 453       *
 454       * @example <code>[post_author_posts_link]</code> is the default usage
 455       * @example <code>[post_author_posts_link before="<b>" after="</b>"]</code>
 456       */
 457  	function pagelines_post_author_posts_link_shortcode( $atts ) {
 458  
 459          $defaults = array(
 460              'before' => '',
 461              'after' => ''
 462          );
 463          $atts = shortcode_atts( $defaults, $atts );
 464  
 465          // Prevent automatic WP Output
 466          ob_start();
 467          the_author_posts_link();
 468          $author = ob_get_clean();
 469  
 470          $output = sprintf( '<span class="author vcard sc">%2$s<span class="fn">%1$s</span>%3$s</span>', $author, $atts['before'], $atts['after'] );
 471  
 472          return apply_filters( 'pagelines_post_author_shortcode', $output, $atts );
 473      }
 474  
 475      /**
 476       * 15. This function produces the author of the post (link to author URL)
 477       *
 478       * @example <code>[post_author_link]</code> is the default usage
 479       * @example <code>[post_author_link before="<b>" after="</b>"]</code>
 480       */
 481  	function pagelines_post_author_link_shortcode( $atts ) {
 482  
 483          $defaults = array(
 484              'nofollow' => FALSE,
 485              'before' => '',
 486              'after' => ''
 487          );
 488          $atts = shortcode_atts( $defaults, $atts );
 489  
 490          $author = get_the_author();
 491  
 492          //    Link?
 493          if ( get_the_author_meta( 'url' ) ) {
 494  
 495              //    Build the link
 496              $author = '<a href="' . get_the_author_meta( 'url' ) . '" title="' . esc_attr( sprintf( __( 'Visit %s&#8217;s website', 'pagelines' ), $author ) ) . '" rel="external">' . $author . '</a>';
 497  
 498          }
 499  
 500          $output = sprintf( '<span class="author vcard sc">%2$s<span class="fn">%1$s</span>%3$s</span>', $author, $atts['before'], $atts['after'] );
 501  
 502          return apply_filters( 'pagelines_post_author_link_shortcode', $output, $atts );
 503  
 504      }
 505  
 506      /**
 507       * 16. This function produces the author of the post (display name)
 508       *
 509       * @example <code>[post_author]</code> is the default usage
 510       * @example <code>[post_author before="<b>" after="</b>"]</code>
 511       */
 512  	function pagelines_post_author_shortcode( $atts ) {
 513  
 514          $defaults = array(
 515              'before' => '',
 516              'after' => ''
 517          );
 518          $atts = shortcode_atts( $defaults, $atts );
 519  
 520          $output = sprintf( '<span class="author vcard sc">%2$s<span class="fn">%1$s</span>%3$s</span>',
 521                          esc_html( get_the_author() ),
 522                          $atts['before'],
 523                          $atts['after']
 524                      );
 525  
 526          return apply_filters( 'pagelines_post_author_shortcode', $output, $atts );
 527  
 528      }
 529  
 530      /**
 531       * 17. Post Date
 532       *
 533       */
 534  	function pagelines_post_date_shortcode( $atts ) {
 535  
 536          $defaults = array(
 537              'format' => get_option( 'date_format' ),
 538              'before' => '',
 539              'after' => '',
 540              'label' => ''
 541          );
 542          $atts = shortcode_atts( $defaults, $atts );
 543  
 544          $output = sprintf( '<time class="date time published updated sc" datetime="%5$s">%1$s%3$s%4$s%2$s</time> ',
 545                          $atts['before'],
 546                          $atts['after'],
 547                          $atts['label'],
 548                          get_the_time( $atts['format'] ),
 549                          get_the_time( 'c' )
 550                      );
 551  
 552          return apply_filters( 'pagelines_post_date_shortcode', $output, $atts );
 553  
 554      }
 555  
 556  
 557      /**
 558       * 18.Shortcode to display Pinterest button
 559       *
 560       * @example <code>[pinterest_button img=""]</code> is the default usage
 561       * @example <code>[pinterest_button img=""]</code>
 562       */
 563  	function pl_pinterest_button( $atts ){
 564  
 565              $defaults = array(
 566                  'url' => get_permalink(),
 567                  'img' => '',
 568                  'title' => urlencode( the_title_attribute( array( 'echo' => false ) ) ),
 569              );
 570  
 571              $atts = shortcode_atts( $defaults, $atts );
 572  
 573              $out = sprintf( '<a href="http://pinterest.com/pin/create/button/?url=%s&amp;media=%s&amp;description=%s" class="pin-it-button" count-layout="horizontal"><img style="border:0px;" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a><script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>',
 574              $atts['url'],
 575              $atts['img'],
 576              $atts['title']
 577              );
 578  
 579              return $out;
 580  
 581          }
 582  
 583      /**
 584       * 1X.Shortcode to display Google Plus 1 Button
 585       *
 586       * @example <code>[google_plus]</code> is the default usage
 587       * @example <code>[google_plus size="" count=""]</code>
 588       * @example available attributes for size include small, medium, and tall
 589       * @example avialable counts include inline, and bubble
 590       */
 591      function pl_googleplus_button ( $atts ) {
 592  
 593          $defaults = array(
 594              'size' => 'medium',
 595              'count' => 'inline',
 596              'url' => get_permalink()
 597  
 598          );
 599  
 600          $atts = shortcode_atts($defaults, $atts);
 601  
 602          ob_start();
 603  
 604          ?>
 605              <script type="text/javascript">
 606                (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
 607                })();
 608              </script><?php
 609  
 610           printf( '<div class="g-plusone" style="width:190px;" data-size="%s" data-annotation="%s" data-href="%s"></div>',
 611              $atts['size'],
 612              $atts['count'],
 613              $atts['url']
 614          );
 615  
 616          return ob_get_clean();
 617      }
 618  
 619      /**
 620       * . Shortcode to display Linkedin Share Button
 621       *
 622       * @example <code>[linkedin]</code> is the default usage
 623       * @example <code>[linkedin count="vertical"]</code>
 624       */
 625      function pl_linkedinshare_button ($atts) {
 626  
 627              $defaults = array(
 628                  'url'    => get_permalink(),
 629                  'count'    => 'horizontal'
 630              );
 631  
 632              $atts = wp_parse_args( $atts, $defaults );
 633  
 634  
 635              $out = sprintf( '<script src="//platform.linkedin.com/in.js" type="text/javascript"></script><script type="IN/Share" data-url="%s" data-counter="%s"></script>',
 636                      $atts['url'],
 637                      $atts['count']
 638                  );
 639  
 640             return $out;
 641  
 642      }
 643  
 644      /**
 645       * 19. Shortcode to display Tweet button
 646       *
 647       * @example <code>[twitter_button type=""]</code> is the default usage
 648       * @example <code>[twitter_button type="follow"]</code>
 649       */
 650  	function pl_twitter_button( $args ){
 651  
 652          $defaults = array(
 653              'type'      => '',
 654              'permalink'    => get_permalink(),
 655              'handle'    => ( ploption( 'twittername' ) ) ? ploption( 'twittername' ) : 'PageLines' ,
 656              'title'        => ''
 657              );
 658  
 659              $a = wp_parse_args( $args, $defaults );
 660  
 661              if ($a['type'] == 'follow') {
 662  
 663                  $out = sprintf( '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script><a href="https://twitter.com/%1$s" class="twitter-follow-button" data-show-count="true">Follow @%1$s</a>',
 664                      $a['handle']
 665                          );
 666  
 667              } else {
 668  
 669                  $out = sprintf( '<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script><a href="https://twitter.com/share" class="twitter-share-button" data-url="%s" data-text="%s" data-via="%s">Tweet</a>',
 670                      $a['type'],
 671                      $a['permalink'],
 672                      $a['title'],
 673                      $a['handle']
 674                      );
 675              }
 676              return $out;
 677      }
 678  
 679      /**
 680       * 20. Shortcode to display Facebook Like button
 681       *
 682       * @example <code>[like_button]</code> is the default usage
 683       * @example <code>[like_button]</code>
 684       */
 685  	function pl_facebook_shortcode( $args ){
 686  
 687              $defaults = array(
 688                  'url'    => get_permalink(),
 689                  'width'        => '80',
 690              );
 691  
 692              $a = wp_parse_args( $args, $defaults );
 693  
 694              ob_start();
 695                  // Facebook
 696                  ?>
 697                  <script>(function(d, s, id) {
 698                          var js, fjs = d.getElementsByTagName(s)[0];
 699                          if (d.getElementById(id)) return;
 700                          js = d.createElement(s); js.id = id;
 701                          js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
 702                          fjs.parentNode.insertBefore(js, fjs);
 703                          }(document, 'script', 'facebook-jssdk'));
 704                  </script><?php
 705                  printf( '<div class="fb-like" data-href="%s" data-send="false" data-layout="button_count" data-width="%s" data-show-faces="false" data-font="arial" style="vertical-align: top"></div>',
 706                      $a['url'],
 707                      $a['width']
 708                  );
 709  
 710              return ob_get_clean();
 711  
 712          }
 713  
 714      /**
 715       * 21. This function/shortcode will show all authors on a post
 716       *
 717       * @example <code>[show_authors]</code> is the default usage
 718       * @example <code>[show_authors]</code>
 719       */
 720  	function show_multiple_authors() {
 721  
 722          if( class_exists( 'CoAuthorsIterator' ) ) {
 723  
 724              $i = new CoAuthorsIterator();
 725              $return = '';
 726              $i->iterate();
 727              $return .= '<a href="'.get_author_posts_url( get_the_author_meta( 'ID' ) ).'">'.get_the_author_meta( 'display_name' ).'</a>';
 728              while( $i->iterate() ){
 729                  $return.= $i->is_last() ? ' and ' : ', ';
 730                  $return .= '<a href="'.get_author_posts_url( get_the_author_meta( 'ID' ) ).'">'.get_the_author_meta( 'display_name' ).'</a>';
 731              }
 732  
 733              return $return;
 734  
 735          } else {
 736              //fallback
 737          }
 738      }
 739  
 740      /**
 741       * 22.Bootstrap Code Shortcode
 742       *
 743       * @example <code>[pl_codebox]...[/pl_codebox]</code> is the default usage
 744       * @example <code>[pl_codebox scrollable="yes"].box{margin:0 auto;}[/pl_codebox]</code> for lots of code
 745       */
 746  
 747  	function pl_codebox_shortcode ( $atts, $content = null ) {
 748  
 749          extract( shortcode_atts( array(
 750              'scrollable' => 'no',
 751              'linenums' => 'yes',
 752              'language'    => 'html'
 753          ), $atts ) );
 754  
 755          $scrollable = ( $scrollable == 'yes' ) ? 'pre-scrollable' : '';
 756          $linenums = ( $linenums == 'yes' ) ? 'linenums' : '';
 757          $language = 'lang-'.$language;
 758  
 759          // Grab Shortcodes
 760          $pattern = array(
 761  
 762              '#([a-z]+\=[\'|"][^\'|"]*[\'|"])#m',
 763              '#(\[[^]]*])#m',
 764  
 765          );
 766          $replace = array(
 767              '<span class="sc_var">$1</span>',
 768              '<span class="sc_code">$1</span>'
 769          );
 770  
 771          $code = preg_replace( $pattern, $replace, esc_html( $content ) );
 772  
 773          $out = sprintf( '<pre class="%s prettyprint %s %s">%s</pre>',
 774                      $scrollable,
 775                      $language,
 776                      $linenums,
 777                      $code
 778                  );
 779  
 780          return $out;
 781      }
 782  
 783      /**
 784       * 23. Bootstrap Labels Shortcode
 785       *
 786       * @example <code>[pl_label type=""]My Label[/pl_label]</code> is the default usage
 787       * @example <code>[pl_label type="info"]label[/pl_label]</code>
 788       * @example Available types include info, success, warning, error
 789       */
 790  	function pl_label_shortcode( $atts, $content = null ) {
 791  
 792          $defaults = array(
 793              'type' => 'info',
 794          );
 795  
 796          $atts = shortcode_atts( $defaults, $atts );
 797  
 798          $out = sprintf( '<span class="label label-%s">%s</span>',
 799                      $atts['type'],
 800                      do_shortcode( $content )
 801                  );
 802  
 803          return $out;
 804      }
 805  
 806      /**
 807       * 24. Bootstrap Badges Shortcode
 808       *
 809       * @example <code>[pl_badge type="info"]My badge[/pl_badge]</code> is the default usage
 810       * @example <code>[pl_badge type="info"]badge[/pl_badge]</code>
 811       * @example Available types include info, success, warning, error
 812       */
 813  	function pl_badge_shortcode( $atts, $content = null ) {
 814  
 815          $defaults = array(
 816              'type' => 'info',
 817          );
 818  
 819          $atts = shortcode_atts( $defaults, $atts );
 820  
 821          $out = sprintf( '<span class="badge badge-%s">%s</span>',
 822                      $atts['type'],
 823                      do_shortcode( $content )
 824                  );
 825  
 826          return $out;
 827      }
 828  
 829  
 830      /**
 831       * 25. Bootstrap Alertbox Shortcode
 832       *
 833       * @example <code>[pl_alertbox type="info"]My alert[/pl_alertbox]</code> is the default usage
 834       * @example <code>[pl_alertbox type="info" closable="yes"]My alert[/pl_alertbox]</code> makes an alert that can be toggled away with a close button
 835       * @example <code>[pl_alertbox type="info"]<h4 class="pl-alert-heading">Heading</h4>My alert[/pl_alertbox]</code>
 836       * @example Available types include info, success, warning, error
 837       */
 838  	function pl_alertbox_shortcode( $atts, $content = null ) {
 839  
 840          $content = str_replace( '<br />', '', str_replace( '<br>', '', $content ) );
 841  
 842          $defaults = array(
 843                      'type' => 'info',
 844                      'closable' =>'no',
 845                      );
 846  
 847          $atts = shortcode_atts( $defaults, $atts );
 848  
 849          $closed = sprintf( '<div class="alert alert-%s"><a class="close" data-dismiss="alert" href="#">×</a>%s</div>',
 850                  $atts['type'],
 851                  do_shortcode( $content )
 852          );
 853  
 854          if ( $atts['closable'] === 'yes' ) {
 855  
 856              return $closed;
 857  
 858          }
 859  
 860          $out = sprintf( '<div class="alert alert-%s alert-block">%2$s</div>',
 861                      $atts['type'],
 862                      do_shortcode( $content )
 863                  );
 864  
 865          return $out;
 866      }
 867  
 868      /**
 869       * 26. Bootstrap Blockquote Shortcode
 870       *
 871       * @example <code>[pl_blockquote pull="" cite=""]My quote[/pl_blockquote]</code> is the default usage
 872       * @example <code>[pl_blockquote pull="right" cite="Someone Famous"]My quote pulled right with source[/pl_blockquote]</code>
 873       */
 874  	function pl_blockquote_shortcode( $atts, $content = null) {
 875  
 876          $defaults = array(
 877              'pull'    => '',
 878              'cite'    => ''
 879          );
 880  
 881          $atts = shortcode_atts( $defaults, $atts );
 882  
 883          $out = sprintf( '<blockquote class="pull-%1$s"><p>%3$s<small>%2$s</small></p></blockquote>',
 884                      $atts['pull'],
 885                      $atts['cite'],
 886                      do_shortcode( $content )
 887                  );
 888  
 889          return $out;
 890  
 891      }
 892  
 893      /**
 894       * 27. Bootstrap Button Shortcode
 895       *
 896       * @example <code>[pl_button type="" size="" link="" target=""]...[/pl_button]</code> is the default usage
 897       * @example <code>[pl_button type="info" size="small" link="#" target="blank"]My Button[/pl_button]</code>
 898       * @example Available types include info, success, warning, danger, inverse
 899       * @example Available sizes include large, medium, and mini
 900       */
 901  	function pl_button_shortcode( $atts, $content = null, $target = null ) {
 902  
 903          $defaults = array(
 904              'type' => 'info',
 905              'size' => 'small',
 906              'link' => '#',
 907              'target' => '_self'
 908          );
 909  
 910          $atts = shortcode_atts( $defaults, $atts );
 911  
 912          $target = ( $target == 'blank' ) ? '_blank' : '';
 913  
 914          $out = sprintf( '<a href="%1$s" target="%2$s" class="btn btn-%3$s btn-%4$s">%5$s</a>',
 915                      $atts['link'],
 916                      $atts['target'],
 917                      $atts['type'],
 918                      $atts['size'],
 919                      do_shortcode( $content )
 920                      );
 921  
 922          return $out;
 923      }
 924  
 925  
 926      /**
 927       * 28. Bootstrap Button Group Shortcode - Builds a group of buttons as a menu
 928       *
 929       * @example <code>[pl_buttongroup]<a href="#" class="btn btn-info">...[/pl_buttongroup]</code> is the default usage
 930       * @example <code>[pl_buttongroup]<a href="#" class="btn btn-info"><a href="#" class="btn btn-info"><a href="#" class="btn btn-info">[/pl_button]</code>
 931       * @example Available types include info, success, warning, danger, inverse
 932       */
 933  	function pl_buttongroup_shortcode( $atts, $content = null ) {
 934  
 935          $content = str_replace( '<br />', '', str_replace( '<br>', '', $content ) );
 936  
 937          return sprintf( '<div class="btn-group">%s</div>', do_shortcode( $content ) );
 938  
 939      }
 940  
 941  
 942      /**
 943       * 29. Bootstrap Dropdown Button Shortcode - Builds a button with contained dropdown menu
 944       *
 945       * @example <code>[pl_buttondropdown size="" type="" label=""]<li><a href="#">...</a></li>[/pl_buttondropdown]</code> is the default usage
 946       * @example <code>[pl_buttondropdown size="large" type="info" label="button"]<li><a href="#"></li><li><a href="#"></li><li><a href="#"></li>[/pl_buttondropdown]</code>
 947       * @example Available types include info, success, warning, danger, inverse
 948       */
 949  	function pl_buttondropdown_shortcode( $atts, $content = null  ) {
 950  
 951          $defaults = array(
 952              'size' => '',
 953              'type' => '',
 954              'label' => ''
 955          );
 956  
 957          $atts = shortcode_atts( $defaults, $atts );
 958  
 959          $out = sprintf( '<div class="btn-group"><button class="btn btn-%s btn-%s dropdown-toggle" data-toggle="dropdown" href="#">%s <span class="caret"></span></button><ul  class="dropdown-menu">%s</ul></div>',
 960              $atts['size'],
 961                $atts['type'],
 962              $atts['label'],
 963              do_shortcode( $content )
 964          );
 965  
 966          return $out;
 967      }
 968  
 969  
 970      /**
 971       * 30. Bootstrap Split Button Dropdown - Builds a button with split button dropdown caret
 972       *
 973       * @example <code>[pl_splitbuttondropdown size="" type="" label=""]<li><a href="#">...</a></li>[/pl_splitbuttondropdown]</code> is the default usage
 974       * @example <code>[pl_splitbuttondropdown size="large" type="info" label="button"]<li><a href="#"></li><li><a href="#"></li><li><a href="#"></li>[/pl_splitbuttondropdown]</code>
 975       * @example Available types include info, success, warning, danger, inverse
 976       */
 977  	function pl_splitbuttondropdown_shortcode( $atts, $content = null ) {
 978  
 979          $defaults = array(
 980              'size' => '',
 981              'type' => '',
 982              'label' => ''
 983          );
 984  
 985          $atts = shortcode_atts( $defaults, $atts );
 986  
 987          $out = sprintf( '<div class="btn-group"><a class="btn btn-%1$s btn-%2$s" >%3$s</a><a class="btn btn-%1$s btn-%2$s dropdown-toggle" data-toggle="dropdown"><span  class="caret"></span></a><ul class="dropdown-menu">%4$s</ul></div>',
 988                $atts['size'],
 989              $atts['type'],
 990              $atts['label'],
 991              do_shortcode( $content )
 992          );
 993  
 994          return $out;
 995      }
 996  
 997       /**
 998       * 31. Bootstrap Tooltips
 999       *
1000       * @example <code>[pl_tooltip tip=""]...[/pl_tooltip]</code> is the default usage
1001       * @example <code>This is a [pl_tooltip tip="Cool"]tooltip[/pl_tooltip] example.</code>
1002       */
1003  	function pl_tooltip_shortcode( $atts, $content = null ) {
1004  
1005          $defaults = array(
1006              'tip' => 'Tip',
1007              'position'  => 'right'
1008          );
1009  
1010          $atts = shortcode_atts( $defaults, $atts );
1011  
1012              ob_start();
1013  
1014                  ?>
1015                  <script>
1016                      jQuery(function(){
1017                          jQuery("a[rel=tooltip]").tooltip();
1018                      });
1019                  </script><?php
1020  
1021              printf( '<a href="#" rel="tooltip" title="%s" data-placement="%s">%s</a>',
1022                  $atts['tip'],
1023                  $atts['position'],
1024                  do_shortcode( $content )
1025              );
1026  
1027              return ob_get_clean();
1028  
1029      }
1030  
1031      /**
1032       * 32. Bootstrap Popovers
1033       *
1034       * @example <code>[pl_popover title="" content=""]...[/pl_popover]</code> is the default usage
1035       * @example <code>This is a [pl_popover title="Popover Title" content="Some content that you can have inside the Popover"]popover[/pl_popover] example.</code>
1036       */
1037      function pl_popover_shortcode( $atts, $content = null ) {
1038  
1039          $defaults = array(
1040              'title' => 'Popover Title',
1041              'content' => 'Content',
1042              'position'  => 'right'
1043          );
1044  
1045          $atts = shortcode_atts( $defaults, $atts );
1046  
1047          ob_start();
1048  
1049              ?>
1050              <script>
1051                      jQuery(function(){
1052                           jQuery("a[rel=popover]")
1053                            .popover({
1054                              html:true,
1055                                trigger: 'hover'
1056                            })
1057                            .click(function(e) {
1058                              e.preventDefault()
1059                            });
1060                      });
1061              </script><?php
1062  
1063          printf( '<a href="#" rel="popover" title="%s" data-content="%s" data-placement="%s">%s</a>',
1064              $atts['title'],
1065              $atts['content'],
1066              $atts['position'],
1067              do_shortcode( $content )
1068          );
1069  
1070          return ob_get_clean();
1071  
1072      }
1073  
1074  
1075      /**
1076       * 33. Bootstrap Accordion - Collapsable Content
1077       *
1078       * @example <code>[pl_accordion name="accordion"] [accordioncontent name="accordion" number="1" heading="Tile 1"]Content 1 [/accordioncontent] [accordioncontent name="accordion" number="2" heading="Title 2"]Content 2 [/accordioncontent] [/pl_accordion]</code> is the default usage
1079       */
1080  	function pl_accordion_shortcode( $atts, $content = null ) {
1081  
1082          $defaults = array(
1083  
1084              'name' => '',
1085  
1086          );
1087  
1088          $atts = shortcode_atts( $defaults, $atts );
1089  
1090          $out = sprintf( '<div id="%s" class="accordion">%s</div>',
1091          $atts['name'],
1092          do_shortcode( $content )
1093          );
1094      return $out;
1095      }
1096  
1097      //Accordion Content
1098  	function pl_accordioncontent_shortcode( $atts, $content = null, $open = null ) {
1099  
1100          $defaults = array(
1101              'name' => '',
1102              'heading' => '',
1103              'number' => '',
1104              'open' => ''
1105          );
1106  
1107          $atts = shortcode_atts( $defaults, $atts );
1108          $open = ( $atts['open'] == 'yes' ) ? 'in' : '';
1109          $out = sprintf( '<div class="accordion-group"><div class="accordion-heading"><a class="accordion-toggle" data-toggle="collapse" data-parent="#%1$s" href="#collapse%3$s">%2$s</a></div><div id="collapse%3$s" class="accordion-body collapse %4$s"><div class="accordion-inner">%5$s</div></div></div>',
1110                $atts['name'],
1111              $atts['heading'],
1112              $atts['number'],
1113              $open,
1114              do_shortcode( $content )
1115  
1116          );
1117  
1118          return $out;
1119      }
1120  
1121      /**
1122       * 34. Bootstrap Carousel
1123       *
1124       * @example <code>[pl_carousel name=""][pl_carouselimage first="yes" title="" imageurl="" ]Caption[/pl_carouselimage][pl_carouselimage title="" imageurl="" ]Caption[/pl_carouselimage][/pl_carousel]</code> is the default usage
1125       * @example <code>[pl_carousel name="PageLinesCarousel"][pl_carouselimage first="yes" title="Feature 1" imageurl="" ]Image 1 Caption[/pl_carouselimage][pl_carouselimage title="Feature 2" imageurl=""]Image 2 Caption[/pl_carouselimage][pl_carouselimage title="Feature 3" imageurl=""]Image 3 Caption[/pl_carouselimage][/pl_carousel]</code>
1126       */
1127      function pl_carousel_shortcode( $atts, $content = null ) {
1128  
1129          global $carousel_js;
1130  
1131          if ( isset($atts['speed']) && '0' === $atts['speed'] )
1132              $atts['speed'] = 'pause'; // 0 will be striped by array_filter
1133  
1134          // remove any empty array keys that have empty values to enforce defaults (eg: name="" or speed="") that would otherwise break things
1135          $atts = array_filter($atts);
1136  
1137          $defaults = array(
1138              'name'  => 'PageLines Carousel',
1139              'speed' => 5000 // default bootstrap transition time
1140          );
1141  
1142          $atts = shortcode_atts( $defaults, $atts );
1143  
1144          $carousel_id = sanitize_title_with_dashes( $atts['name'], null, 'save' ); // convert it to a valid id attribute if it isn't.
1145          $speed = absint($atts['speed']);
1146  
1147          if ( ! isset($carousel_js) )
1148              $carousel_js = array();
1149          else {
1150              if ( array_key_exists($carousel_id, $carousel_js) )
1151                  $carousel_id = $carousel_id.'-'.count($carousel_js);
1152          }
1153  
1154          // store away the values for consolidated output in the footer
1155          $carousel_js[$carousel_id] = array(
1156              'id' => $carousel_id,
1157              'speed' => $speed
1158              );
1159  
1160          return sprintf( '<div id="%2$s" class="carousel slide"><div class="carousel-inner">%1$s</div><a class="carousel-control left" href="#%2$s" data-slide="prev">&lsaquo;</a><a class="carousel-control right" href="#%2$s" data-slide="next">&rsaquo;</a></div>',
1161          do_shortcode( $content ),
1162          $carousel_id
1163          );
1164      }
1165      //Carousel Images
1166  	function pl_carouselimage_shortcode( $atts, $content = null ) {
1167  
1168          // remove any empty string attributes to use defaults
1169          $atts = array_filter($atts);
1170  
1171          extract( shortcode_atts( array(
1172              'first' => '',
1173              'title' => '',
1174              'imageurl' => sprintf( '%s/screenshot.png', PL_PARENT_URL ), // fallback "reminder" image
1175              'caption' => '',
1176          ), $atts ) );
1177  
1178          $first = ( $first == 'yes' ) ? 'active' : '';
1179          $content = ( $content <> '' ) ? "<div class='carousel-caption'><h4>$title</h4><p>$content</p></div>" : ''; // changed to work without captions
1180  
1181          return sprintf( '<div class="item %s"><img src="%s">%s</div>', // changed to work without captions
1182                  $first,
1183                  $imageurl,
1184                  do_shortcode( $content )
1185                  );
1186      }
1187  
1188  	function print_carousel_js() {
1189  
1190          global $carousel_js;
1191  
1192          if ( ! isset($carousel_js) )
1193              return;
1194          echo "<!-- carousel_js -->\n";
1195  
1196          if ( isset($carousel_js) && is_array($carousel_js) ) : ?>
1197              <script type="text/javascript">
1198              (function($) {
1199              <?php
1200  
1201                  foreach ($carousel_js as $c) {
1202                      printf("\n$('#%s').carousel({ interval: %s })",
1203                          $c['id'],
1204                          ( 'pause' == $c['speed'] ) ? 0 : $c['speed']
1205                          );
1206                  }
1207              ?>
1208  
1209          })(jQuery);
1210  </script>
1211          <?php
1212          endif;
1213      }
1214  
1215      /**
1216       * 35. Bootstrap Tabs
1217       *
1218       * @example <code>[pl_tabs][pl_tabtitlesection type=""][pl_tabtitle active="" number="1"]...[/pl_tabtitle][pl_tabtitle number="2"]...[/pl_tabtitle][/pl_tabtitlesection][pl_tabcontentsection][pl_tabcontent active="" number="1"]...[/pl_tabcontent][pl_tabcontent number=""]...[/pl_tabcontent][/pl_tabcontentsection][/pl_tabs]</code> is the default usage
1219       * @example <code>[pl_tabs][pl_tabtitlesection type="tabs"][pl_tabtitle active="yes" number="1"]Title 1[/pl_tabtitle][pl_tabtitle number="2"]Title 2[/pl_tabtitle][/pl_tabtitlesection][pl_tabcontentsection][pl_tabcontent active="yes" number="1"]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ac mi enim, at consectetur justo.[/pl_tabcontent][pl_tabcontent number="2"]Second content there.[/pl_tabcontent][/pl_tabcontentsection][/pl_tabs]</code>
1220       * @example Available types include tabs, pills
1221       */
1222  
1223      function pl_tabs_shortcode( $atts, $content = null ) {
1224  
1225          return sprintf( '<div class="tabs">%s</div>', do_shortcode( $content ) );
1226  
1227      }
1228  
1229      //Tab Titles Section
1230  		function pl_tabtitlesection_shortcode( $atts, $content = null ) {
1231  
1232              extract( shortcode_atts( array(
1233                  'type' => '',
1234              ), $atts ) );
1235  
1236              ob_start();
1237  
1238                  ?>
1239                      <script>
1240                          jQuery(function(){
1241                               jQuery('a[data-toggle="tab"]').on('shown', function (e) {
1242                                e.target // activated tab
1243                                e.relatedTarget // previous tab
1244                              })
1245                          });
1246                      </script><?php
1247  
1248              printf( '<ul class="nav nav-%s">%s</ul>',
1249              $type,
1250              do_shortcode( $content )
1251              );
1252  
1253              return ob_get_clean();
1254          }
1255  
1256      //Tab Titles
1257  		function pl_tabtitle_shortcode( $atts, $content = null ) {
1258  
1259              extract( shortcode_atts( array(
1260                  'active' => '',
1261                  'number' => ''
1262              ), $atts ) );
1263  
1264              $active = ( $active == 'yes' ) ? "class='active'" : '';
1265  
1266              $out = sprintf( '<li %s><a href="#%s" data-toggle="tab">%s</a></li>',
1267                      $active,
1268                      $number,
1269                      do_shortcode( $content )
1270                      );
1271  
1272              return $out;
1273          }
1274  
1275      //Tab Content Section
1276  		function pl_tabcontentsection_shortcode( $atts, $content = null ) {
1277  
1278              return '<div class="tab-content">'.do_shortcode( $content ).'</div>';
1279  
1280          }
1281  
1282      //Tab Content
1283  		function pl_tabcontent_shortcode( $atts, $content = null ) {
1284  
1285              extract( shortcode_atts( array(
1286                  'active' => '',
1287                  'number' => ''
1288              ), $atts ) );
1289  
1290              $active = ( $active == 'yes' ) ? "active" : '';
1291  
1292              return sprintf( '<div class="tab-pane %s" id="%s"><p>%s</p></div>',
1293                      $active,
1294                      $number,
1295                      do_shortcode( apply_filters( 'the_content',$content ) )
1296                      );
1297          }
1298  
1299      /**
1300       * 36. Bootstrap Modal Popup Window
1301       *
1302       * @example <code>[pl_modal title="" type="" colortype="" label=""]...[/pl_modal]</code>
1303       * @example <code>[pl_modal title="Title" type="label" colortype="info" label="Click Me!"]Some content here for the cool modal pop up. You can have all kinds of cool stuff in here.[/pl_modal]</code>
1304       * @example available types include button, label, and badge
1305       * @example available color types include default, success, warning, important, info, and inverse
1306       */
1307  	function pl_modal_shortcode( $atts, $content = null ) {
1308  
1309          extract( shortcode_atts( array(
1310              'title'        => '',
1311              'type'        => '',
1312              'colortype' => '',
1313              'label'     => '',
1314              'show'        => 'false',
1315              'hash'        => rand()
1316          ), $atts ) );
1317  
1318              ob_start();
1319  
1320                  ?>
1321                  <script>
1322                      jQuery(function(){
1323                          jQuery('#modal_<?php echo $hash; ?>').modal({
1324                              keyboard: true
1325                              , show: <?php echo $show; ?>
1326                          });
1327                      });
1328                  </script><?php
1329  
1330                     printf( '<div id="modal_%6$s" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><a class="close" data-dismiss="modal" aria-hidden="true">×</a><h3>%s</h3></div><div class="modal-body"><p>%4$s</p></div><div class="modal-footer"><a href="#" class="btn btn-%3$s" data-dismiss="modal" aria-hidden="true">%7$s</a></div></div><a data-toggle="modal" role="button" href="#modal_%6$s" class="%2$s %2$s-%3$s">%5$s</a>',
1331                  $title,
1332                  $type,
1333                  $colortype,
1334                  do_shortcode( $content ),
1335                  $label,
1336                  $hash,
1337                  __( 'Close', 'pagelines' )
1338                  );
1339  
1340              return ob_get_clean();
1341  
1342      }
1343  
1344      /**
1345       * 37. This function produces the time of post publication
1346       *
1347       * @example <code>[post_time]</code> is the default usage</code>
1348       * @example <code>[post_time format="g:i a" before="<b>" after="</b>"]</code>
1349       */
1350  	function pagelines_post_time_shortcode( $atts ) {
1351  
1352          $defaults = array(
1353              'format' => get_option( 'time_format' ),
1354              'before' => '',
1355              'after' => '',
1356              'label' => ''
1357          );
1358          $atts = shortcode_atts( $defaults, $atts );
1359  
1360          $output = sprintf( '<span class="time published sc" title="%5$s">%1$s%3$s%4$s%2$s</span> ',
1361                          $atts['before'],
1362                          $atts['after'],
1363                          $atts['label'],
1364                          get_the_time( $atts['format'] ),
1365                          get_the_time( 'Y-m-d\TH:i:sO' )
1366                          );
1367  
1368          return apply_filters( 'pagelines_post_time_shortcode', $output, $atts );
1369  
1370      }
1371  
1372      /**
1373       * 38. Used to create general buttons and button links
1374       *
1375       * @example <code>[button]</code> is the default usage
1376       * @example <code>[button format="edit_post" before="<b>" after="</b>"]</code>
1377       */
1378  	function pagelines_button_shortcode( $atts ) {
1379  
1380          $defaults = array(
1381              'color'    => 'grey',
1382              'size'    => 'normal',
1383              'align'    => 'right',
1384              'style'    => '',
1385              'type'    => 'button',
1386              'text'    => '&nbsp;',
1387              'pid'    => 0,
1388              'class'    => null,
1389          );
1390          $atts = shortcode_atts( $defaults, $atts );
1391  
1392          $button = sprintf( '<div class="blink"><div class="blink-pad">%s</div></div>', $text );
1393  
1394          $output = sprintf( '<div class="%s %s %s blink-wrap">%s</div>', $special, $size, $color, $button );
1395  
1396          return apply_filters( 'pagelines_button_shortcode', $output, $atts );
1397  
1398      }
1399  
1400      /**
1401       * XX. Responsive Videos
1402       *
1403       * @example <code>[pl_video]</code> is the default usage
1404       * @example <code>[pl_video type="youtube" url="urltovideo"]</code>
1405       */
1406      function pl_video_shortcode ($atts) {
1407  
1408          extract( shortcode_atts( array(
1409              'type' =>'',
1410              'id' =>'',
1411              'width' => '100%',
1412              'height' => '100%',
1413              'related' => '',
1414              ), $atts ) );
1415          if ( $related )
1416              $related = '?rel=0';
1417  
1418          switch( $type ) {
1419  
1420  
1421              case 'vimeo':
1422                  $out = sprintf( '<div class="pl-video vimeo"><iframe src="http://player.vimeo.com/video/%s" width="%s" height="%s"  frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen wmode="transparent"></iframe></div>',$id, $width, $height );
1423                  break;
1424  
1425              case 'dailymotion':
1426                  $out = sprintf( '<div class="pl-video dailymotion"><iframe src="http://www.dailymotion.com/embed/video/%s" width="%s" height="%s"  frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen wmode="transparent"></iframe></div>',$id, $width, $height );
1427                  break;
1428  
1429              default:
1430                  $out = sprintf('<div class="pl-video youtube"><iframe src="http://www.youtube.com/embed/%s%s" width="%s" height="%s" frameborder="0" allowfullscreen wmode="transparent"></iframe></div>', $id, $related, $width, $height);
1431          }
1432          return $out;
1433      }
1434  
1435  
1436  
1437  	function filters() {
1438  
1439          /**
1440           *  Prevent AUTOP inside of shortcodes (breaking shortcodes - removed)
1441           */
1442          remove_filter( 'the_content', 'wpautop' );
1443          add_filter( 'the_content', 'wpautop' , 12);
1444          remove_filter( 'the_content', 'wptexturize' );
1445          add_filter( 'the_content', 'wptexturize' , 12);
1446      }
1447  
1448  	private function register_shortcodes( $shortcodes ) {
1449  
1450          foreach ( $shortcodes as $shortcode => $data ) {
1451              add_shortcode( $shortcode, array( &$this, $data['function']) );
1452          }
1453      }
1454  //
1455  } // end of class
1456  //
1457  new PageLines_ShortCodes;


Generated: Sat Apr 6 23:00:27 2013 Cross-referenced by PHPXref 0.7.1