/components/showdata/shortcodes.php

  1. <?php 
  2. /** 
  3. * Facebook Fanpage Import Showdata Shortcodes Component. 
  4. * 
  5. * This class initializes the component. 
  6. * 
  7. * @author mahype, awesome.ug <very@awesome.ug> 
  8. * @package Facebook Fanpage Import 
  9. * @version 1.0.0 
  10. * @since 1.0.0 
  11. * @license GPL 2 
  12.   
  13. Copyright 2015 Awesome UG (very@awesome.ug) 
  14.   
  15. This program is free software; you can redistribute it and/or modify 
  16. it under the terms of the GNU General Public License, version 2, as  
  17. published by the Free Software Foundation. 
  18.   
  19. This program is distributed in the hope that it will be useful,  
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  22. GNU General Public License for more details. 
  23.   
  24. You should have received a copy of the GNU General Public License 
  25. along with this program; if not, write to the Free Software 
  26. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
  27.   
  28. */ 
  29.  
  30. if ( !defined( 'ABSPATH' ) ) exit; 
  31.  
  32. class FacebookFanpageImportShowdataShortcodes{ 
  33. var $name; 
  34.  
  35. /** 
  36. * Initializes the Component. 
  37. * @since 1.0.0 
  38. */ 
  39. function __construct() { 
  40. $this->name = get_class( $this ); 
  41.  
  42. add_shortcode( 'fanpagestream', array( $this, 'show_stream' ) ); 
  43. } // end constructor 
  44.  
  45. public function show_stream( $atts ) { 
  46. global $paged, $wp_query; 
  47.  
  48. extract( shortcode_atts( array( 
  49. 'entries' => (int) get_option( 'posts_per_page' ),  
  50. ), $atts ) ); 
  51.  
  52. $args = array( 
  53. 'posts_per_page' => $entries,  
  54. 'orderby' => 'post_date',  
  55. 'post_type' => 'fanpage-entries',  
  56. 'paged' => fbfpi_get_url_var( 'page' ) 
  57. ); 
  58.  
  59. $wp_query = new WP_Query( $args ); 
  60.  
  61. $paged_old = $paged; 
  62. $paged = ( get_query_var('paged')) ? get_query_var('paged') : 1; 
  63.  
  64. $content = '<div class="fbfpi_stream">'; 
  65. if ($wp_query->have_posts()) :  
  66. while ( $wp_query->have_posts() ) : 
  67. $wp_query->the_post(); 
  68.  
  69. // setup_postdata( $post ); 
  70. $post_id = $wp_query->post->ID; 
  71.  
  72. $fanpage_id = get_post_meta( $post_id, 'fanpage_id', TRUE ); 
  73. $fanpage_name = get_post_meta( $post_id, 'fanpage_name', TRUE ); 
  74. $fanpage_link = get_post_meta( $post_id, 'fanpage_link', TRUE ); 
  75.  
  76. $id = get_post_meta( $post_id, 'post_id', TRUE ); 
  77. $entry_id = get_post_meta( $post_id, 'entry_id', TRUE ); 
  78. $message = nl2br( get_post_meta( $post_id, 'message', TRUE ) ); 
  79. $description = get_post_meta( $post_id, 'description', TRUE ); 
  80. $permalink = get_post_meta( $post_id, 'permalink', TRUE ); 
  81. $type = get_post_meta( $post_id, 'type', TRUE ); 
  82.  
  83. $link_target = skip_value( 'fbfpi_settings', 'link_target' ); 
  84.  
  85. switch ( $type ) { 
  86. case 'link': 
  87. $action = sprintf( __( '<a href="%s" target="%s">%s</a> shared a link.', 'fbfpi' ), $fanpage_link, $link_target, $fanpage_name ); 
  88. break; 
  89. case 'photo': 
  90. $action = sprintf( __( '<a href="%s" target="%s">%s</a> shared a photo.', 'fbfpi' ), $fanpage_link, $link_target, $fanpage_name ); 
  91. break; 
  92. default: 
  93. if( '' != $description ) $action = $description; 
  94. else $action = sprintf( __( '<a href="%s" target="%s">%s</a> shared a status.', 'fbfpi' ), $fanpage_link, $link_target, $fanpage_name ); 
  95. break; 
  96.  
  97. $has_attachment = get_post_meta( $post_id, 'has_attachment', TRUE ); 
  98.  
  99. /** 
  100. * Writing Entry 
  101. */ 
  102. $content.= '<div class="fbfpi_entry">'; 
  103.  
  104. if( $message ) $content.= '<p>' . $message . '</p>'; 
  105. else $content.= '<p>' . $action . '</p>'; 
  106.  
  107. // attachment Data  
  108. if( $has_attachment ): 
  109.  
  110. $picture = ''; 
  111.  
  112. $attachment_name = get_post_meta( $post_id, 'attachment_name', TRUE ); 
  113. $attachment_description = nl2br( substr( get_post_meta( $post_id, 'attachment_description', TRUE ), 0, 200 ) ); 
  114. $attachment_caption = get_post_meta( $post_id, 'attachment_caption', TRUE ); 
  115. $attachment_href = get_post_meta( $post_id, 'attachment_href', TRUE ); 
  116. $attachment_src = get_post_meta( $post_id, 'attachment_src', TRUE ); 
  117.  
  118. if( 'event' == $type ): 
  119. $start_time = get_post_meta( $post_id, 'attachment_start_time', TRUE ); 
  120. $location = get_post_meta( $post_id, 'attachment_location', TRUE ); 
  121. $attachment_caption = sprintf( __( 'Start %s %s.', 'fbfpi' ), date_i18n( get_option( 'date_format' ), strtotime( $start_time ) ), date_i18n( get_option( 'time_format' ), strtotime( $start_time ) ) ); 
  122. $attachment_caption.= '<br />' . $location; 
  123. endif; 
  124.  
  125. if( is_array( $attachment_src ) ) 
  126. $attachment_src = $attachment_src[ 0 ]; 
  127.  
  128. echo '<pre>'; 
  129. print_r( $attachment_src ); 
  130. echo '</pre>'; 
  131.  
  132. echo '<img src="' . $attachment_src . '">'; 
  133.  
  134. $attachment_suffix = strtolower( substr( $attachment_src, strlen( $attachment_src ) - 3, strlen( $attachment_src ) ) ); 
  135.  
  136. if( 'jpg' == $attachment_suffix || 'gif' == $attachment_suffix || 'png' == $attachment_suffix ): 
  137. $picture = str_replace( '_s.' . $attachment_suffix, '_n.' . $attachment_suffix, $attachment_src ); 
  138. endif; 
  139.  
  140. $content.= '<div class="fbfpi_content">'; 
  141.  
  142. // Picture 
  143. if( $picture ): 
  144. if( '' != $attachment_name || '' != $attachment_description ) 
  145. $content.= '<div class="fbfpi_content_picture fbfpi_content_picture_small">'; 
  146. else 
  147. $content.= '<div class="fbfpi_content_picture fbfpi_content_picture_fullsize">'; 
  148.  
  149. if( $permalink ) 
  150. $content.= '<a href="' . $permalink . '" class="fbfp_picture" target="' . $link_target . '"><img src="' . $picture . '" /></a>'; 
  151. else 
  152. $content.= '<img src="' . $picture . '" />'; 
  153.  
  154. $content.= '</div>'; 
  155.  
  156. endif;  
  157.  
  158. if( '' != $attachment_name || '' != $attachment_description ): 
  159. // Content 
  160. $content.= '<div class="fbfpi_content_text fbfpi_link_content_text">'; 
  161.  
  162. if( $attachment_href && '' != $attachment_name ) 
  163. $content.= '<h4><a href="' . $permalink . '" title="' . sprintf( __( 'Link to: %s', 'fbfpi' ), $attachment_name ) .'" target="' . $link_target . '">' . $attachment_name . '</a></h4>'; 
  164. elseif( '' != $attachment_name ) 
  165. $content.= '<h4>' . $attachment_name . '</h4>'; 
  166.  
  167. if( '' != $attachment_description ) 
  168. $content.= '<p>' . $attachment_description . ' ...</p>';# 
  169.  
  170. if( '' != $attachment_caption && $attachment_href && '' != $attachment_name ) 
  171. $content.= '<small><a href="' . $permalink . '" title="' . sprintf( __( 'Link to: %s', 'fbfpi' ), $attachment_name ) .'" target="' . $link_target . '">' . $attachment_caption . '</a></small>'; 
  172. elseif ( '' != $attachment_caption ) 
  173. $content.= '<small>' . $attachment_caption . '</small>'; 
  174.  
  175. $content.= '</div>'; 
  176. endif; 
  177.  
  178. $content.= '<div class="fbfpi_clear"></div>'; 
  179. $content.= '</div>'; 
  180.  
  181. endif; 
  182.  
  183. $content.= '<div class="fbfpi_clear"></div>'; 
  184. $content.= '</div>'; 
  185.  
  186. endwhile; 
  187.  
  188.  
  189. $content.= '<div id="nav-below" class="navigation">'; 
  190. $content.= '<div class="nav-previous">' . get_next_posts_link( __( '<span class="meta-nav">←</span>Older entries', 'fbfpi' ) ) . '</div>'; 
  191. $content.= '<div class="nav-next">' . get_previous_posts_link( __( 'Newer entries <span class="meta-nav">→</span>', 'fbfpi' ) ) . '</div>'; 
  192. $content.= '<div class="fbfpi_clear"></div></div>'; 
  193.  
  194. $content.= '</div>'; 
  195.  
  196. endif; 
  197. $paged = $paged_old; 
  198. wp_reset_query(); 
  199.  
  200. return $content; 
  201.  
  202. $FacebookFanpageImportShowdataShortcodes = new FacebookFanpageImportShowdataShortcodes(); 
.