wff_shortcode_display

The Facebook Feed wff shortcode display function.

Description

wff_shortcode_display( $atts ); 

Parameters (1)

0. $atts
The atts.

Usage

  1. if ( !function_exists( 'wff_shortcode_display' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'facebook-feed/facebook-feed-shortcode.php'; 
  3.  
  4. // The atts. 
  5. $atts = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wff_shortcode_display($atts); 
  9.  

Defined (1)

The function is defined in the following location(s).

/facebook-feed-shortcode.php  
  1. function wff_shortcode_display ($atts) { 
  2.  
  3. if(!function_exists('wff_custom_js_code')) { 
  4. add_action( 'wp_footer', 'wff_custom_js_code' ); 
  5. function wff_custom_js_code() { 
  6.  
  7. $custom_js_setting = get_option ('wff_design_settings'); 
  8. $custom_js = ($custom_js_setting['wff_custom_js_data']) ? $custom_js_setting['wff_custom_js_data'] : '' ; 
  9. $custom_js_snippet = isset($custom_js) ? $custom_js : ''; 
  10.  
  11. echo '<script type="text/javascript">'; 
  12. if( !empty($custom_js_snippet) ) echo stripslashes($custom_js_snippet); 
  13. echo '</script>'; 
  14.  
  15. // add custom styles 
  16. if(!function_exists('wff_custom_css_code')) { 
  17. add_action( 'wp_footer', 'wff_custom_css_code' ); 
  18. function wff_custom_css_code() { 
  19. $custom_css_setting = get_option ('wff_design_settings'); 
  20. $custom_css = ($custom_css_setting['wff_custom_css_data']) ? $custom_css_setting['wff_custom_css_data'] : '' ; 
  21. $custom_css_snippet = isset($custom_css) ? stripslashes($custom_css) : ''; 
  22. echo '<style type="text/css">'.$custom_css_snippet.'</style>'; 
  23. // enqueue script for character count  
  24. if(!function_exists('wff_load_custom_scripts')) { 
  25. add_action( 'wp_footer', 'wff_load_custom_scripts' ); 
  26. function wff_load_custom_scripts() { 
  27. wp_register_script( 'wff_custom_js', plugin_dir_url( __FILE__ ) . 'js/text-count.js', array('jquery'), false, true ); 
  28. wp_enqueue_script ('wff_custom_js'); 
  29. if(!function_exists('add_my_stylesheet')) { 
  30. add_action( 'wp_footer', 'add_my_stylesheet' ); 
  31. function add_my_stylesheet() { 
  32. wp_register_style( 'wff-mystyle', plugins_url('css/style.css', __FILE__) ); 
  33. wp_enqueue_style( 'wff-mystyle' ); 
  34. //default app token 
  35. $design_setting_array = get_option ('wff_design_settings'); 
  36. $general_setting_array = get_option ('wff_general_settings'); 
  37.  
  38. $all_array =array( 
  39. 'page_id' => get_option('wff_page_id') ? get_option('wff_page_id') : '',  
  40. 'wff_post_limit' => ($general_setting_array['wff_num_posts']) ? $general_setting_array['wff_num_posts'] : '',  
  41. 'cache_time' => ($general_setting_array['wff_cache_time']) ? $general_setting_array['wff_cache_time'] : '',  
  42. 'link_target' => ($general_setting_array['wff_link_target']) ? 1 : 0,  
  43.  
  44. 'author_date_format' => (get_option('wff_author_date')) ? get_option('wff_author_date') : '',  
  45. 'author_text_size' => ($design_setting_array['wff_author_text_size']) ? $design_setting_array['wff_author_text_size'] : '',  
  46. 'line_height' => ($design_setting_array['wff_line_height']) ? $design_setting_array['wff_line_height'] : '',  
  47. 'author_text_color' => ($design_setting_array['wff_author_text_color']) ? $design_setting_array['wff_author_text_color'] : '',  
  48. 'author_img_border' => ($design_setting_array['wff_img_border']) ? $design_setting_array['wff_img_border'] : '',  
  49. 'feed_seprator' => ($design_setting_array['wff_feed_seprator']) ? $design_setting_array['wff_feed_seprator'] : '',  
  50.  
  51. 'char_limit' => ($design_setting_array['wff_char_limit']) ? $design_setting_array['wff_char_limit'] : '',  
  52. 'post_text_color' => ($design_setting_array['wff_text_color']) ? $design_setting_array['wff_text_color'] : '',  
  53. 'post_background' => ($design_setting_array['wff_post_back_color']) ? $design_setting_array['wff_post_back_color'] : '',  
  54. 'post_text_weight' => ($design_setting_array['wff_text_weight']) ? $design_setting_array['wff_text_weight'] : '',  
  55. 'post_text_size' => ($design_setting_array['wff_text_size']) ? $design_setting_array['wff_text_size'] : '',  
  56. 'post_text_align' => ($design_setting_array['wff_text_align']) ? $design_setting_array['wff_text_align'] : '',  
  57.  
  58. 'page_link_text' => ($design_setting_array['wff_page_link_text']) ? $design_setting_array['wff_page_link_text'] : '',  
  59. 'read_more' => ($design_setting_array['wff_read_more_text']) ? $design_setting_array['wff_read_more_text'] : '',  
  60. 'read_less' => ($design_setting_array['wff_read_less_text']) ? $design_setting_array['wff_read_less_text'] : '',  
  61. ); 
  62.  
  63. $atts = shortcode_atts($all_array, $atts, 'facebook-feed'); 
  64.  
  65. extract($atts); 
  66.  
  67. // Get the Page ID 
  68. if( empty($page_id) )  
  69. {  
  70. $error_message = '<p style = "color:red;" > Please enter valid Facebook Page ID</p>'; //errorif a user does not enter page id 
  71. return $error_message ; 
  72.  
  73. $wff_app_token=array('1505917499687703|2133Lp1cLt6Zk0N2por8X8QJf9k',  
  74. '393872077427061|ghfVBzNUFnMdFLAGlJbWAOVOelI',  
  75. '1377619605888926|LxwTNNAeRtn9nYhYS0VDkVDs0mI'); // We will provide support for user token in future updates 
  76.  
  77. $access_token = $wff_app_token[rand(0, 2)]; 
  78.  
  79. //initialise facepress object 
  80. $wff_posts_json_url = 'https://graph.facebook.com/' . $page_id . '/posts?access_token=' . $access_token . '&limit=' . $wff_post_limit; 
  81.  
  82. if($cache_time == 'none') {  
  83.  
  84. $feeddata = wff_fetchUrl($wff_posts_json_url); 
  85. $feedjson = json_decode($feeddata); 
  86. $fbfeed = $feedjson->data;  
  87. else { 
  88. // this code runs when there is no valid transient set 
  89. if ( false === ($feeddata = get_transient('fb_feed_query'))) { 
  90. $feeddata = wff_fetchUrl($wff_posts_json_url); 
  91. $feeddata = set_transient('fb_feed_query', $feeddata, $cache_time*60); 
  92. $feeddata = get_transient('fb_feed_query'); 
  93. $feedjson = json_decode($feeddata); 
  94. $fbfeed = $feedjson->data; 
  95.  
  96. if( empty($fbfeed) )  
  97. {  
  98. $error_message = '<p style = "color:red;" >Cannot Display Feed</p><p style = "color:red;"> Pls check if the Facebook page exists or not. </p>'; // To do display message as per theerrorcode 
  99. return $error_message ; 
  100.  
  101. // Start Building HTML 
  102. $my_final_post_text = '';  
  103. $my_final_post_text_item_wrapper = ''; 
  104. $my_final_post_text_item_wrapper_complete = ''; 
  105.  
  106. foreach ($fbfeed as $singlefeed) 
  107. {  
  108. $my_final_post_text = ''; // this var will hold author data + post text + post desc.. We will wrap this var in item wrapper  
  109.  
  110. $my_author_text = build_author_html($singlefeed, $atts); 
  111.  
  112. $what_is_post_type = $singlefeed->type;  
  113.  
  114. if($what_is_post_type == 'link') 
  115. $my_post_content_text = build_my_link_html ($singlefeed, $atts); 
  116.  
  117. if ($what_is_post_type == 'photo') 
  118. $my_post_content_text = build_my_photo_html($singlefeed, $atts); 
  119. }  
  120. if($what_is_post_type == 'video') 
  121. $my_post_content_text = build_my_video_html ($singlefeed, $atts); 
  122.  
  123. if($what_is_post_type == 'status') 
  124. if (!empty($singlefeed->message)) 
  125. $my_post_content_text = build_my_status_html ($singlefeed, $atts); 
  126. // You will cehck if this post has a message. Likes and commnts etc are not to be displayed with the feed  
  127.  
  128. if ($what_is_post_type == 'event') 
  129. {  
  130. $my_post_content_text = build_my_event_html ($singlefeed, $atts, $access_token); 
  131.  
  132. //feed seprator inline style 
  133. $wff_feed_seprator_style = 'style="'; 
  134. if ( !empty($feed_seprator) && $feed_seprator != 'none' ) $wff_feed_seprator_style .= 'border-bottom:' . $feed_seprator . 'px solid '; 
  135. if ( !empty($author_text_color) ) $wff_feed_seprator_style .= $author_text_color .';'; 
  136. $wff_feed_seprator_style .= '"'; 
  137.  
  138. // the final post text  
  139. $my_final_post_text .= $my_author_text.$my_post_content_text ;  
  140.  
  141. switch ($what_is_post_type) { 
  142.  
  143. case 'link': 
  144. $my_final_post_text_item_wrapper = '<div '.$wff_feed_seprator_style.' class = "wff-fb-item wff-fb-item-link" id ='.$singlefeed->id.'>'.$my_final_post_text.'</div>'; 
  145. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper; 
  146. break; 
  147.  
  148. case 'status': 
  149. $my_final_post_text_item_wrapper = '<div '.$wff_feed_seprator_style.' class = "wff-fb-item wff-fb-item-status" id ='.$singlefeed->id.' >'.$my_final_post_text.'</div>'; 
  150. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper; 
  151. break; 
  152.  
  153. case 'event': 
  154. $my_final_post_text_item_wrapper = '<div '.$wff_feed_seprator_style.' class = "wff-fb-item wff-fb-item-event" id ='.$singlefeed->id.'>'.$my_final_post_text.'</div>'; 
  155. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper; 
  156. break;  
  157.  
  158. case 'video': 
  159. $my_final_post_text_item_wrapper = '<div '.$wff_feed_seprator_style.' class = "wff-fb-item wff-fb-item-video" id ='.$singlefeed->id.'>'.$my_final_post_text.'</div>'; 
  160. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper; 
  161. break; 
  162.  
  163. case 'photo': 
  164. $my_final_post_text_item_wrapper = '<div '.$wff_feed_seprator_style.' class = "wff-fb-item wff-fb-item-photo" id ='.$singlefeed->id.'>'.$my_final_post_text.'</div>'; 
  165. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper; 
  166. break;  
  167.  
  168. $my_final_post_text = '<div class = "wff-feed-wrapper"><div id = "wff-id">'.$my_final_post_text_item_wrapper_complete.'</div></div>'; // Add a feed wrapper to the complete feed html 
  169.  
  170. // Return the complete html 
  171. return $my_final_post_text;