PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/news/includes/shortcodes.php

https://bitbucket.org/lgorence/quickpress
PHP | 226 lines | 119 code | 39 blank | 68 comment | 12 complexity | 0c010fd25cba9641db2bd4ac8d6804f0 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Additional shortcodes for use within the theme.
  4. *
  5. * @package News
  6. * @subpackage Includes
  7. * @since 0.1.0
  8. */
  9. /**
  10. * Registers new shortcodes.
  11. *
  12. * @since 0.1.0
  13. */
  14. function news_register_shortcodes() {
  15. add_shortcode( 'slideshow', 'news_slideshow_shortcode' );
  16. add_shortcode( 'entry-popup-shortlink', 'news_entry_shortlink_popup_shortcode' );
  17. add_shortcode( 'entry-print-link', 'news_entry_print_link_shortcode' );
  18. add_shortcode( 'entry-email-link', 'news_entry_email_link_shortcode' );
  19. add_shortcode( 'entry-mixx-link', 'news_entry_mixx_link_shortcode' );
  20. add_shortcode( 'entry-delicious-link', 'news_entry_delicious_link_shortcode' );
  21. add_shortcode( 'entry-digg-link', 'news_entry_digg_link_shortcode' );
  22. add_shortcode( 'entry-facebook-link', 'news_entry_facebook_link_shortcode' );
  23. add_shortcode( 'entry-twitter-link', 'news_entry_twitter_link_shortcode' );
  24. }
  25. /**
  26. * Shortlink popup shortcode.
  27. *
  28. * @since 0.1.0
  29. */
  30. function news_entry_shortlink_popup_shortcode() {
  31. $shortlink = wp_get_shortlink( get_the_ID() );
  32. if ( empty( $shortlink ) )
  33. return '';
  34. $id = sanitize_html_class( 'shortlink-' . get_the_ID() );
  35. $title = sprintf( __( "Shortlink for '%s'", 'news' ), get_the_title() );
  36. $out = '<a class="tips shortlink hide-if-no-js" rel="#' . $id . '" title="' . esc_attr( $title ) . '">' . __( 'Shortlink', 'news' ) . '</a>';
  37. $out .= ' <div id="' . $id . '" class="tip hide">';
  38. $out .= '<input type="text" value="' . esc_url( $shortlink ) . '" onclick="this.focus(); this.select();" />';
  39. $out .= '</div>';
  40. return $out;
  41. }
  42. /**
  43. * Print link shortcode.
  44. *
  45. * @since 0.1.0
  46. */
  47. function news_entry_print_link_shortcode() {
  48. return '<a class="print-link hide-if-no-js" href="#">' . __( 'Print', 'news' ) . '</a>';
  49. }
  50. /**
  51. * Email link shortcode.
  52. *
  53. * @since 0.1.0
  54. */
  55. function news_entry_email_link_shortcode() {
  56. $subject = urlencode( esc_attr( '[' . get_bloginfo( 'name' ) . ']' . the_title_attribute( 'echo=0' ) ) );
  57. $body = urlencode( esc_attr( sprintf( __( 'Check out this post: %1$s', 'news' ), get_permalink( get_the_ID() ) ) ) );
  58. return '<a class="email-link" href="mailto:?subject=' . $subject . '&amp;body=' . $body . '">' . __( 'Email', 'news' ) . '</a>';
  59. }
  60. /**
  61. * Mixx link shortcode.
  62. *
  63. * @since 0.1.0
  64. */
  65. function news_entry_mixx_link_shortcode() {
  66. return '<a href="http://www.mixx.com" onclick="window.location=\'http://www.mixx.com/submit?page_url=\'+window.location; return false;">' . __( 'Mixx', 'news' ) . '</a>';
  67. }
  68. /**
  69. * Delicious link shortcode.
  70. *
  71. * @since 0.1.0
  72. */
  73. function news_entry_delicious_link_shortcode() {
  74. return '<a href="http://delicious.com/save" onclick="window.open(\'http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=\'+encodeURIComponent(\'' . get_permalink() . '\')+\'&amp;title=\'+encodeURIComponent(\'' . the_title_attribute( 'echo=0' ) . '\'),\'delicious\', \'toolbar=no,width=550,height=550\'); return false;">' . __( 'Delicious', 'news' ) . '</a>';
  75. }
  76. /**
  77. * Digg link shortcode.
  78. * @note This won't work from your computer (http://localhost). Must be a live site.
  79. *
  80. * @since 0.1.0
  81. */
  82. function news_entry_digg_link_shortcode() {
  83. $url = esc_url( 'http://digg.com/submit?phase=2&amp;url=' . urlencode( get_permalink( get_the_ID() ) ) . '&amp;title="' . urlencode( the_title_attribute( 'echo=0' ) ) );
  84. return '<a href="' . $url . '" title="' . __( 'Digg this entry', 'news' ) . '">Digg</a>';
  85. }
  86. /**
  87. * Facebook share link shortcode.
  88. *
  89. * @todo Figure out why this doesn't work.
  90. *
  91. * @since 0.1.0
  92. */
  93. function news_entry_facebook_link_shortcode() {
  94. $url = esc_url( 'http://facebook.com/sharer.php?u=' . urlencode( get_permalink( get_the_ID() ) ) . '&amp;t=' . urlencode( the_title_attribute( 'echo=0' ) ) );
  95. return '<a href="' . $url . '" title="' . __( 'Share this entry on Facebook', 'news' ) . '">' . __( 'Facebook', 'news' ) . '</a>';
  96. }
  97. /**
  98. * Twitter link shortcode.
  99. *
  100. * @since 0.1.0
  101. */
  102. function news_entry_twitter_link_shortcode() {
  103. $post_id = get_the_ID();
  104. $post_type = get_post_type( $post_id );
  105. if ( 'post' == $post_type || 'page' == $post_type || 'attachment' == $post_type )
  106. $shortlink = wp_get_shortlink( $post_id );
  107. else
  108. $shortlink = get_permalink( $post_id );
  109. $url = esc_url( 'http://twitter.com/home?status=' . urlencode( sprintf( __( 'Currently reading %1$s', 'news' ), $shortlink ) ) );
  110. return '<a href="' . $url . '" title="' . __( 'Share this entry on Twitter', 'news' ) . '">' . __( 'Twitter', 'news' ) . '</a>';
  111. }
  112. /**
  113. * Slideshow shortcode.
  114. *
  115. * @since 0.1.0
  116. */
  117. function news_slideshow_shortcode( $attr ) {
  118. global $post;
  119. /* Set up the defaults for the slideshow shortcode. */
  120. $defaults = array(
  121. 'order' => 'ASC',
  122. 'orderby' => 'menu_order ID',
  123. 'id' => $post->ID,
  124. 'size' => 'news-slideshow',
  125. 'include' => '',
  126. 'exclude' => '',
  127. 'numberposts' => -1,
  128. );
  129. $attr = shortcode_atts( $defaults, $attr );
  130. /* Allow users to overwrite the default args. */
  131. extract( apply_atomic( 'slideshow_shortcode_args', $attr ) );
  132. /* Arguments for get_children(). */
  133. $children = array(
  134. 'post_parent' => intval( $id ),
  135. 'post_status' => 'inherit',
  136. 'post_type' => 'attachment',
  137. 'post_mime_type' => 'image',
  138. 'order' => $order,
  139. 'orderby' => $orderby,
  140. 'exclude' => absint( $exclude ),
  141. 'include' => absint( $include ),
  142. 'numberposts' => intval( $numberposts ),
  143. );
  144. /* Get image attachments. If none, return. */
  145. $attachments = get_children( $children );
  146. if ( empty( $attachments ) )
  147. return '';
  148. /* If is feed, leave the default WP settings. We're only worried about on-site presentation. */
  149. if ( is_feed() ) {
  150. $output = "\n";
  151. foreach ( $attachments as $id => $attachment )
  152. $output .= wp_get_attachment_link( $id, $size, true ) . "\n";
  153. return $output;
  154. }
  155. $slideshow = '<div class="slideshow-set"><div class="slideshow-items">';
  156. $i = 0;
  157. foreach ( $attachments as $attachment ) {
  158. /* Open item. */
  159. $slideshow .= '<div class="slideshow-item item item-' . ++$i . '">';
  160. /* Get image. */
  161. $slideshow .= wp_get_attachment_link( $attachment->ID, $size, true, false );
  162. /* Check for caption. */
  163. if ( !empty( $attachment->post_excerpt ) )
  164. $caption = $attachment->post_excerpt;
  165. elseif ( !empty( $attachment->post_content ) )
  166. $caption = $attachment->post_content;
  167. else
  168. $caption = '';
  169. if ( !empty( $caption ) ) {
  170. $slideshow .= '<div class="slideshow-caption">';
  171. $slideshow .= '<a class="slideshow-caption-control">' . __( 'Caption', 'news' ) . '</a>';
  172. $slideshow .= '<div class="slideshow-caption-text">' . $caption . '</div>';
  173. $slideshow .= '</div>';
  174. }
  175. $slideshow .= '</div>';
  176. }
  177. $slideshow .= '</div><div class="slideshow-controls">';
  178. $slideshow .= '<div class="slideshow-pager"></div>';
  179. $slideshow .= '<div class="slideshow-nav">';
  180. $slideshow .= '<a class="slider-prev">' . __( 'Previous', 'news' ) . '</a>';
  181. $slideshow .= '<a class="slider-next">' . __( 'Next', 'news' ) . '</a>';
  182. $slideshow .= '</div>';
  183. $slideshow .= '</div>';
  184. $slideshow .= '</div><!-- End slideshow. -->';
  185. return apply_atomic( 'slideshow_shortcode', $slideshow );
  186. }
  187. ?>