Guest User

Untitled

a guest
Oct 23rd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.15 KB | None | 0 0
  1. <?php
  2. // To Do..
  3. // 1. Check if Link description exists or not. In case there is no description we will not append the description wrapper
  4. // 2. Error Handling: Show a error message if we cannot fetch the feed.. Either the id is wrong or the page is private
  5. // 3. Styling issue, sometime wrong html wrapper is created. Check in Go Pro for reference.
  6. // 4.
  7. // Define variables
  8.  
  9. $page_id = "";
  10. $access_token = "";
  11.  
  12. // snippet from this url http://krasimirtsonev.com/blog/article/php--find-links-in-a-string-and-replace-them-with-actual-html-link-tags
  13. function makeLinks($str,$link_target) {
  14. $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
  15. $urls = array();
  16. $urlsToReplace = array();
  17. if(preg_match_all($reg_exUrl, $str, $urls)) {
  18. $numOfMatches = count($urls[0]);
  19. $numOfUrlsToReplace = 0;
  20. for($i=0; $i<$numOfMatches; $i++) {
  21. $alreadyAdded = false;
  22. $numOfUrlsToReplace = count($urlsToReplace);
  23. for($j=0; $j<$numOfUrlsToReplace; $j++) {
  24. if($urlsToReplace[$j] == $urls[0][$i]) {
  25. $alreadyAdded = true;
  26. }
  27. }
  28. if(!$alreadyAdded) {
  29. array_push($urlsToReplace, $urls[0][$i]);
  30. }
  31. }
  32. $numOfUrlsToReplace = count($urlsToReplace);
  33. for($i=0; $i<$numOfUrlsToReplace; $i++) {
  34. if($link_target == 1) {
  35. $str = str_replace($urlsToReplace[$i], '<a class="wff-link-tab" href="'.$urlsToReplace[$i].'" target = "_blank">'.$urlsToReplace[$i].'</a> ', $str);
  36. } else {
  37. $str = str_replace($urlsToReplace[$i], '<a class="wff-link-tab" href="'.$urlsToReplace[$i].'" >'.$urlsToReplace[$i].'</a>', $str);
  38. }
  39. }
  40. return $str;
  41. } else {
  42. return $str;
  43. }
  44. }
  45.  
  46. function make_hash_link($str,$link_target)
  47. {
  48. $reg_exUrl = "/(#\w+)/";
  49. $urls = array();
  50. $urlsToReplace = array();
  51. if(preg_match_all($reg_exUrl, $str, $urls)) {
  52. $numOfMatches = count($urls[0]);
  53. $numOfUrlsToReplace = 0;
  54. for($i=0; $i<$numOfMatches; $i++) {
  55. $alreadyAdded = false;
  56. $numOfUrlsToReplace = count($urlsToReplace);
  57. for($j=0; $j<$numOfUrlsToReplace; $j++) {
  58. if($urlsToReplace[$j] == $urls[0][$i]) {
  59. $alreadyAdded = true;
  60. }
  61. }
  62. if(!$alreadyAdded) {
  63. array_push($urlsToReplace, $urls[0][$i]);
  64. }
  65. }
  66. $numOfUrlsToReplace = count($urlsToReplace);
  67. for($i=0; $i<$numOfUrlsToReplace; $i++) {
  68. $str_without_hastag[$i] = ltrim ($urlsToReplace[$i], '#');
  69. if($link_target == 1) {
  70. $str = str_replace($urlsToReplace[$i],'<a class="wff-link-tab" href="https://www.facebook.com/hashtag/'.$str_without_hastag[$i].'" target = "_blank">'.$urlsToReplace[$i].'</a>', $str);
  71. } else {
  72. $str = str_replace($urlsToReplace[$i],'<a class="wff-link-tab" href="https://www.facebook.com/hashtag/'.$str_without_hastag[$i].'" >'.$urlsToReplace[$i].'</a>', $str);
  73. }
  74. }
  75. return $str;
  76. }
  77. else{
  78. return $str;
  79. }
  80. }
  81.  
  82. // Reference URL http://stackoverflow.com/questions/10981513/stripos-issues-in-php4
  83. if(!is_callable('stripos')){
  84. function stripos($haystack, $needle){
  85. return strpos($haystack, stristr( $haystack, $needle ));
  86. }
  87. }
  88.  
  89. function wff_fetchUrl($url)
  90. {
  91. if(is_callable('curl_init')){
  92. $ch = curl_init();
  93. curl_setopt($ch, CURLOPT_URL, $url);
  94. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  95. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  96. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  97. $feedData = curl_exec($ch);
  98. curl_close($ch);
  99. //If not then use file_get_contents
  100. } elseif ( ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE ) {
  101. $feedData = @file_get_contents($url);
  102. //Or else use the WP HTTP AP
  103. } else {
  104. if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' );
  105. $request = new WP_Http;
  106. $result = $request->request($url);
  107. $feedData = $result['body'];
  108. }
  109. return $feedData;
  110. }
  111. //inline style for post text
  112. function limited_post_text_inline_style($atts)
  113. {
  114. $style_wrapper = ' style=" ';
  115. if ( !empty($atts['post_text_size']) && $atts['post_text_size'] != 'inherit' ) $style_wrapper .= 'font-size:' . $atts['post_text_size'] . 'px;';
  116. if ( !empty($atts['line_height']) && $atts['line_height'] != 'inherit' ) $style_wrapper .= 'line-height:' . $atts['line_height'].'px;';
  117. if ( !empty($atts['post_text_align']) && $atts['post_text_align'] != 'inherit' ) $style_wrapper .= 'text-align:' . $atts['post_text_align'].';';
  118. if ( !empty($atts['post_text_weight']) && $atts['post_text_weight'] != 'inherit' ) $style_wrapper .= 'font-weight:' . $atts['post_text_weight'].';';
  119. if ( !empty($atts['post_text_color'])) $style_wrapper .= 'color:' . $atts['post_text_color'].';';
  120. if ( !empty($atts['post_background'])) $style_wrapper .= 'background:' . $atts['post_background'].';';
  121. $style_wrapper .= ' " ';
  122.  
  123. return $style_wrapper;
  124. }
  125.  
  126. function full_post_text_inline_style($atts)
  127. {
  128. $style_wrapper = ' style=" display:none; ';
  129. if ( !empty($atts['post_text_size']) && $atts['post_text_size'] != 'inherit' ) $style_wrapper .= 'font-size:' . $atts['post_text_size'] . 'px;';
  130. if ( !empty($atts['line_height']) && $atts['line_height'] != 'inherit' ) $style_wrapper .= 'line-height:' . $atts['line_height'].'px;';
  131. if ( !empty($atts['post_text_align']) && $atts['post_text_align'] != 'inherit' ) $style_wrapper .= 'text-align:' . $atts['post_text_align'].';';
  132. if ( !empty($atts['post_text_weight']) && $atts['post_text_weight'] != 'inherit' ) $style_wrapper .= 'font-weight:' . $atts['post_text_weight'].';';
  133. if ( !empty($atts['post_text_color'])) $style_wrapper .= 'color:' . $atts['post_text_color'].';';
  134. if ( !empty($atts['post_background'])) $style_wrapper .= 'background:' . $atts['post_background'].';';
  135. $style_wrapper .= ' " ';
  136.  
  137. return $style_wrapper;
  138. }
  139.  
  140. function feed_line_height($atts)
  141. {
  142. $style_wrapper = ' style=" ';
  143.  
  144. if ( !empty($atts['line_height']) && $atts['line_height'] != 'inherit' ) $style_wrapper .= 'line-height:' . $atts['line_height'].'px;';
  145.  
  146. $style_wrapper .= ' " ';
  147.  
  148. return $style_wrapper;
  149. }
  150.  
  151. function build_my_photo_html ($mysinglefeed,$atts)
  152. {
  153. if (isset($mysinglefeed->story))
  154. {
  155. // if story exists then use the story in the post text
  156. $my_post_photo_text = $mysinglefeed->story;
  157. // we also need to handle story tags
  158. if (array_key_exists('story_tags',$mysinglefeed ))
  159. {
  160. // now add the hyperlink to tags
  161. foreach ( $mysinglefeed->story_tags as $mystorytag)
  162. {
  163. $mystorytagname = $mystorytag->name;
  164. if($atts['link_target']==1) {
  165. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  166. } else {
  167. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" >' . $mystorytag->name . '</a>';
  168. }
  169. $my_post_photo_text = str_replace($mystorytagname, $tag_link, $my_post_photo_text);
  170. }
  171. }
  172. }
  173.  
  174. if (isset($mysinglefeed->message) && !empty($mysinglefeed->message))
  175. {
  176. // if story exists then use the story in the post text
  177. $my_post_photo_text = $mysinglefeed->message;
  178.  
  179. $my_post_photo_text = makeLinks ($my_post_photo_text,$atts['link_target']); // link the urls
  180.  
  181. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$my_post_photo_text)) {
  182. $my_post_photo_text = make_hash_link ($my_post_photo_text,$atts['link_target']);
  183. }
  184.  
  185. }
  186.  
  187. // If if there are message tags
  188. $resourceid = $mysinglefeed->object_id;
  189. if (array_key_exists('message_tags',$mysinglefeed ))
  190. {
  191. // now add the hyperlink to tags
  192. foreach ( $mysinglefeed->message_tags as $mymessagetag)
  193. {
  194. $mymessagetagname = $mymessagetag->name;
  195. if($atts['link_target']==1) {
  196. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  197. } else {
  198. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  199. }
  200. $my_post_photo_text = str_replace($mymessagetagname, $tag_link, $my_post_photo_text);
  201. }
  202. }
  203.  
  204. //call post text inline style
  205. $limited_style_wrapper = limited_post_text_inline_style($atts);
  206. $full_style_wrapper = full_post_text_inline_style($atts);
  207. $line_height_style = feed_line_height($atts);
  208. /*---------------------read more text---------------------------*/
  209. $str_without_tag = strip_tags($my_post_photo_text);
  210. $char_count = strlen($str_without_tag);
  211.  
  212. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  213. {
  214. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  215.  
  216. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); //link the urls
  217. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  218. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  219. }
  220. if (array_key_exists('story_tags',$mysinglefeed ))
  221. {
  222. foreach ( $mysinglefeed->story_tags as $mystorytag)
  223. {
  224. $mystorytagname = $mystorytag->name;
  225. if($atts['link_target']==1) {
  226. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  227. } else {
  228. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" >' . $mystorytag->name . '</a>';
  229. }
  230. $short_sentence = str_replace($mystorytagname, $tag_link, $short_sentence);
  231. }
  232. }
  233. if (array_key_exists('message_tags',$mysinglefeed ))
  234. {
  235. foreach( $mysinglefeed->message_tags as $mymessagetag)// now add the hyperlink to tags
  236. {
  237. $mymessagetagname = $mymessagetag->name;
  238. if($atts['link_target']==1) {
  239. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  240. } else {
  241. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  242. }
  243. $short_sentence = str_replace($mymessagetagname, $tag_link, $short_sentence);
  244. }
  245. }
  246. $build_photo_html = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link" >'.$atts['read_more'].'</a></span></p>';
  247. $build_photo_html .= '<p class="more-content" '.$full_style_wrapper.'>'.$my_post_photo_text.'...<span><a class="wff-less-link" style="display:none">'.$atts['read_less'].'</a></span></p>';
  248. }
  249. else{
  250. $build_photo_html = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_photo_text.'</p>';
  251. }
  252. /*-----------------------------------------------*/
  253.  
  254. $the_resource_id = $mysinglefeed->object_id;
  255. $post_resource_link = 'https://facebook.com/'.$the_resource_id;
  256.  
  257. // Now build The post description
  258. if (isset($mysinglefeed->name))
  259. {
  260. $name_var = $mysinglefeed->name;
  261. $name_url = $mysinglefeed->link;
  262.  
  263. if (isset($mysinglefeed->description))
  264. {
  265.  
  266. $link_post_desc = $mysinglefeed->description;
  267. $link_post_desc = makeLinks($link_post_desc,$atts['link_target']);
  268. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$link_post_desc)) {
  269. $link_post_desc = make_hash_link($link_post_desc,$atts['link_target']);
  270. }
  271. }
  272. else {
  273. $link_post_desc= "";
  274.  
  275. }
  276. }
  277. // now I will include inline style rules while building the HTML. They can be passed via shortcode attributes
  278. $build_post_desc_html = '';
  279. if(isset($mysinglefeed->description)){
  280. if($atts['link_target']==1) {
  281. $build_link_title = '<p class = "link-title" '.$line_height_style.'><a class="wff-link-tab" target="_blank" href =' .$name_url.'>'.$name_var.' </a></p>';
  282. } else {
  283. $build_link_title = '<p class = "link-title" '.$line_height_style.'><a class="wff-link-tab" href =' .$name_url.'>'.$name_var.'</a></p>';
  284. }
  285.  
  286. $build_post_desc_html = '<div class = "description-wrapper shared-link">'.$build_link_title.'<p class = "post-desc" '.$line_height_style.'>'.$link_post_desc.'</p></div>'.$build_post_desc_html;
  287. }
  288. $build_photo_html .= $build_post_desc_html;
  289.  
  290. if($atts['link_target']==1) {
  291. $build_photo_html .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  292. } else {
  293. $build_photo_html .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  294. }
  295. return $build_photo_html;
  296. }
  297.  
  298. function build_my_link_html ($mysinglefeed,$atts)
  299. {
  300. // first work on building html for link type
  301. if (isset($mysinglefeed->story))
  302. {
  303. // if story exists then use the story in the post text
  304. $my_post_text = $mysinglefeed->story;
  305.  
  306. if (array_key_exists('story_tags',$mysinglefeed ))
  307. {
  308. // now add the hyperlink to tags
  309. foreach ( $mysinglefeed->story_tags as $mystorytag)
  310. {
  311. $mystorytagname = $mystorytag->name;
  312. if($atts['link_target']==1) {
  313. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  314. } else {
  315. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;">' . $mystorytag->name . '</a>';
  316. }
  317. $my_post_text = str_replace($mystorytagname, $tag_link, $my_post_text);
  318. }
  319. }
  320. }
  321.  
  322. if (isset($mysinglefeed->message))
  323. {
  324. // if story exists then use the story in the post text
  325. $my_post_text = $mysinglefeed->message;
  326. $my_post_text = makeLinks($my_post_text,$atts['link_target']);
  327.  
  328. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$my_post_text))
  329. {
  330. $my_post_text = make_hash_link($my_post_text,$atts['link_target']);
  331. }
  332. }
  333. // Build Post description
  334. // first hyper link the name
  335.  
  336. $name_var = $mysinglefeed->name;
  337. $name_url = $mysinglefeed->link;
  338.  
  339. if(isset($mysinglefeed->description))
  340. {
  341. $link_post_desc = $mysinglefeed->description;
  342. $link_post_desc = makeLinks($link_post_desc,$atts['link_target']);
  343. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$link_post_desc)) {
  344. $link_post_desc = make_hash_link($link_post_desc,$atts['link_target']);
  345. }
  346. } else {
  347. $link_post_desc = "";
  348. }
  349.  
  350. // $resourceid = $mysinglefeed->object_id;
  351. if (array_key_exists('message_tags',$mysinglefeed ))
  352. {
  353. // now add the hyperlink to tags
  354. foreach ( $mysinglefeed->message_tags as $mymessagetag)
  355. {
  356. $mymessagetagname = $mymessagetag->name;
  357. if($atts['link_target']==1) {
  358. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  359. } else {
  360. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  361. }
  362. $my_post_text = str_replace($mymessagetagname, $tag_link, $my_post_text);
  363. }
  364. }
  365. $the_resource_id = explode('_',$mysinglefeed->id);
  366. $post_resource_link = 'https://facebook.com/'.$atts['page_id'] .'/posts/'.$the_resource_id[1];
  367.  
  368. //call post text inline style
  369. $limited_style_wrapper = limited_post_text_inline_style($atts);
  370. $full_style_wrapper = full_post_text_inline_style($atts);
  371. $line_height_style = feed_line_height($atts);
  372. /*---------------------read more text---------------------------*/
  373. $str_without_tag = strip_tags($my_post_text);
  374. $char_count = strlen($str_without_tag);
  375.  
  376. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  377. {
  378. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  379.  
  380. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); // link the urls
  381. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  382. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  383. }
  384. if (array_key_exists('story_tags',$mysinglefeed ))
  385. {
  386. foreach ( $mysinglefeed->story_tags as $mystorytag)
  387. {
  388. $mystorytagname = $mystorytag->name;
  389. if($atts['link_target']==1) {
  390. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  391. } else {
  392. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" >' . $mystorytag->name . '</a>';
  393. }
  394. $short_sentence = str_replace($mystorytagname, $tag_link, $short_sentence);
  395. }
  396. }
  397.  
  398. if (array_key_exists('message_tags',$mysinglefeed ))
  399. {
  400. foreach( $mysinglefeed->message_tags as $mymessagetag)// now add the hyperlink to tags
  401. {
  402. $mymessagetagname = $mymessagetag->name;
  403. if($atts['link_target']==1) {
  404. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  405. } else {
  406. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  407. }
  408. $short_sentence = str_replace($mymessagetagname, $tag_link, $short_sentence);
  409. }
  410. }
  411. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link">'.$atts['read_more'].'</a></span></p>';
  412. $mytext .= '<p class="more-content" '.$full_style_wrapper.'>'.$my_post_text.'...<span><a class="wff-less-link" style="display:none">'.$atts['read_less'].'</a></span></p>';
  413. }
  414. else{
  415. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_text.'</p>';
  416. }
  417. /*------------------------------------------------*/
  418. if(isset($mysinglefeed->description)){
  419. if($atts['link_target']==1) {
  420. $build_link_title = '<p class = "wff-link-title" '.$line_height_style.'><a class="wff-link-tab" target = "_blank" href =' .$name_url.'>'.$name_var.'</a></p>';
  421. } else {
  422. $build_link_title = '<p class = "wff-link-title" '.$line_height_style.'><a class="wff-link-tab" href =' .$name_url.'>'.$name_var.'</a></p>';
  423. }
  424. $build_post_desc_html = '<div class = "wff-shared-link-wrapper">'.$build_link_title.'<p class = "wff-post-description" '.$line_height_style.'>'.$link_post_desc.'</p>';
  425.  
  426. if(isset($mysinglefeed->caption)) {
  427. $build_post_desc_html .='<a class="wff-link-tab" href='.$name_url.' target="_blank" >'.$mysinglefeed->caption.'</a></div>';
  428. } else $build_post_desc_html .= '</div>';
  429.  
  430. }
  431.  
  432. $mytext .= $build_post_desc_html ;
  433. if($atts['link_target']==1) {
  434. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  435. } else {
  436. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  437. }
  438. return $mytext;
  439. }
  440.  
  441. function build_my_event_html ($mysinglefeed ,$atts,$myaccesstoken)
  442. {
  443.  
  444. $theurl = parse_url($mysinglefeed->link);
  445. $urlpart = explode('/', $theurl['path']);
  446.  
  447. $the_event_id = $urlpart[2];
  448.  
  449. //now get the event json
  450. $event_url_json = 'https://graph.facebook.com/' . $the_event_id . '?access_token=' . $myaccesstoken ;
  451.  
  452. $event_json_data = wff_fetchUrl($event_url_json);
  453. $event_data = json_decode($event_json_data) ;
  454.  
  455. //get event start date
  456. $event_start_date = $event_data->start_time;
  457. $str_format = strtotime($event_start_date);
  458.  
  459. //condition for date format
  460. if($atts['author_date_format']=='default'){
  461. $event_date_print = date('F d, Y',$str_format);
  462. }
  463. else{
  464. $system_date_format = $atts['author_date_format'];
  465. $event_date_print = date($system_date_format, $str_format);
  466. }
  467.  
  468. //We will build the date string. Check if an end time is specified
  469. if (isset($event_data->end_time))
  470. {
  471. // get event end date
  472. $event_end_date = $event_data->end_time;
  473. $str_format = strtotime($event_end_date);
  474.  
  475. if($atts['author_date_format']=='default'){
  476. $event_end_date_print = date('F d, Y',$str_format);
  477. }
  478. else{
  479. $system_date_format = $atts['author_date_format'];
  480. $event_end_date_print = date($system_date_format, $str_format);
  481.  
  482. }
  483.  
  484.  
  485. if(strtotime($event_date_print) == strtotime($event_end_date_print)){
  486.  
  487. $event_date_print = $event_date_print;
  488. }else {
  489. $event_date_print .= " - ". $event_end_date_print;
  490.  
  491. }
  492.  
  493. $event_date_print .= " - ". $event_end_date_print;
  494. }
  495.  
  496. if (isset($mysinglefeed->story))
  497. {
  498. // if story exists then use the story in the post text
  499. $my_post_text = $mysinglefeed->story;
  500.  
  501. if (array_key_exists('story_tags',$mysinglefeed ))
  502. {
  503. // now add the hyperlink to tags
  504. foreach ( $mysinglefeed->story_tags as $mystorytag)
  505. {
  506. $mystorytagname = $mystorytag->name;
  507. if($atts['link_target']==1) {
  508. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  509. } else {
  510. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" >' . $mystorytag->name . '</a>';
  511. }
  512. $my_post_text = str_replace($mystorytagname, $tag_link, $my_post_text);
  513. }
  514. }
  515. }
  516.  
  517. if (isset($mysinglefeed->message))
  518. {
  519. // if story exists then use the story in the post text
  520. $my_post_text = $mysinglefeed->message;
  521. $my_post_text = makeLinks($my_post_text,$atts['link_target']);
  522. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$my_post_text)) {
  523. $my_post_text = make_hash_link($my_post_text,$atts['link_target']);
  524. }
  525. }
  526.  
  527. //call post text inline style
  528. $limited_style_wrapper = limited_post_text_inline_style($atts);
  529. $full_style_wrapper = full_post_text_inline_style($atts);
  530. $line_height_style = feed_line_height($atts);
  531. /*---------------------read more text---------------------------*/
  532.  
  533. $str_without_tag = strip_tags($my_post_text);
  534. $char_count = strlen($str_without_tag);
  535.  
  536. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  537. {
  538. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  539.  
  540. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); // link the urls
  541. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  542. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  543. }
  544. if (array_key_exists('story_tags',$mysinglefeed)) {
  545. // now add the hyperlink to tags
  546. foreach ( $mysinglefeed->story_tags as $mystorytag)
  547. {
  548. $mystorytagname = $mystorytag->name;
  549. if($atts['link_target']==1) {
  550. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  551. } else {
  552. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" >' . $mystorytag->name . '</a>';
  553. }
  554. $short_sentence = str_replace($mystorytagname, $tag_link, $short_sentence);
  555. }
  556. }
  557.  
  558. $finaltext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link">'.$atts['read_more'].'</a></span></p>';
  559. $finaltext .= '<p class="more-content" '.$full_style_wrapper.'>'.$my_post_text.'...<span><a class="wff-less-link" style="display:none">'.$atts['read_less'].'</a></span></p>';
  560. }
  561. else {
  562. $finaltext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_text.'</p>';
  563. }
  564. /*------------------------------------------------*/
  565. $post_resource_link = $mysinglefeed->link;
  566. $event_title = $event_data->name;
  567. $event_description = $event_data->description;
  568. //$event_location = $event_data->location;
  569. $finaltext .= '<div class = "wff-fb-item-event-wrapper">';
  570. $finaltext .= '<div class = "fb-text-wrapper">';
  571. $finaltext .= '<div class = "fb-post-data description-wrapper">';
  572. if($atts['link_target']==1) {
  573. $finaltext .= '<p class="wff-event-title" '.$line_height_style.'><a class="wff-link-tab" href = '.$post_resource_link. ' target = "_blank">'.$event_title.'</a></p>';
  574. } else {
  575. $finaltext .= '<p class="wff-event-title" '.$line_height_style.'><a class="wff-link-tab" href = '.$post_resource_link. ' >'.$event_title.'</a></p>';
  576. }
  577. $finaltext .= '<p class="wff-event-content" '.$line_height_style.'>'.$event_description.'</p>';// close post data div
  578. $finaltext .= '<div class = "event-date">'.$event_date_print.'</div></div>' ; // the date div
  579. if($atts['link_target']==1) {
  580. $finaltext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '.$post_resource_link. ' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  581. } else {
  582. $finaltext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '.$post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  583. }
  584. $finaltext .= '</div></div>'; // close text wrapper and event wrapper
  585.  
  586. return $finaltext ;
  587. }
  588.  
  589. function build_my_status_html ($mysinglefeed ,$atts)
  590. {
  591. // every where we will check if there is no message..
  592. //A stroy description will be used only when there is no message
  593.  
  594. if (isset($mysinglefeed->story))
  595. {
  596. // if story exists then use the story in the post text
  597.  
  598. $my_post_text = $mysinglefeed->story;
  599.  
  600. if (array_key_exists('story_tags',$mysinglefeed ))
  601. {
  602. // now add the hyperlink to tags
  603. foreach ( $mysinglefeed->story_tags as $mystorytag)
  604. {
  605. $mystorytagname = $mystorytag->name;
  606. if($atts['link_target']==1) {
  607. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  608. } else {
  609. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" >' . $mystorytag->name . '</a>';
  610. }
  611. $my_post_text = str_replace($mystorytagname, $tag_link, $my_post_text);
  612. }
  613. }
  614. }
  615.  
  616. if (isset($mysinglefeed->message))
  617. {
  618. // if story exists then use the story in the post text
  619. $my_post_text = $mysinglefeed->message;
  620. $my_post_text = makeLinks($my_post_text,$atts['link_target']);
  621. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$my_post_text)) {
  622. $my_post_text = make_hash_link ($my_post_text,$atts['link_target']);
  623. }
  624. }
  625. // Build Post description
  626. // first hyper link the name
  627.  
  628. $name_var = (isset($mysinglefeed->name) ? $mysinglefeed->name : '');
  629. $name_url = (isset($mysinglefeed->link) ? $mysinglefeed->link : '');
  630.  
  631. $link_post_desc = (isset($mysinglefeed->description) ? $mysinglefeed->description : '');
  632. $link_post_desc = makeLinks($link_post_desc,$atts['link_target']);
  633. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$link_post_desc)) {
  634. $link_post_desc = make_hash_link($link_post_desc,$atts['link_target']);
  635. }
  636. if (array_key_exists('message_tags',$mysinglefeed ))
  637. {
  638. // now add the hyperlink to tags
  639. foreach ( $mysinglefeed->message_tags as $mymessagetag)
  640. {
  641. $mymessagetagname = $mymessagetag->name;
  642. if($atts['link_target']==1) {
  643. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  644. } else {
  645. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  646. }
  647. $my_post_text = str_replace($mymessagetagname, $tag_link, $my_post_text);
  648. }
  649. }
  650. $the_resource_id_array = explode("_", $mysinglefeed->id);
  651. $the_resource_id = $the_resource_id_array[1];
  652. $post_resource_link = 'https://facebook.com/'.$atts['page_id'] .'/posts/'.$the_resource_id;
  653.  
  654. //call post text inline style
  655. $limited_style_wrapper = limited_post_text_inline_style($atts);
  656. $full_style_wrapper = full_post_text_inline_style($atts);
  657. $line_height_style = feed_line_height($atts);
  658. /*---------------------read more text---------------------------*/
  659.  
  660. $str_without_tag = strip_tags($my_post_text);
  661. $char_count = strlen($str_without_tag);
  662.  
  663. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  664. {
  665. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  666.  
  667. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); // link the urls
  668. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  669. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  670. }
  671. if (array_key_exists('story_tags',$mysinglefeed ))
  672. {
  673. foreach ( $mysinglefeed->story_tags as $mystorytag)
  674. {
  675. $mystorytagname = $mystorytag->name;
  676. if($atts['link_target']==1) {
  677. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" target="_blank">' . $mystorytag->name . '</a>';
  678. } else {
  679. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag->id . '" style="color: indigo;" >' . $mystorytag->name . '</a>';
  680. }
  681. $short_sentence = str_replace($mystorytagname, $tag_link, $short_sentence);
  682. }
  683. }
  684.  
  685. if (array_key_exists('message_tags',$mysinglefeed ))
  686. {
  687. foreach( $mysinglefeed->message_tags as $mymessagetag)// now add the hyperlink to tags
  688. {
  689. $mymessagetagname = $mymessagetag->name;
  690. if($atts['link_target']==1) {
  691. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  692. } else {
  693. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  694. }
  695. $short_sentence = str_replace($mymessagetagname, $tag_link, $short_sentence);
  696. }
  697. }
  698. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link">'.$atts['read_more'].'</a></span></p>';
  699. $mytext .= '<p class="more-content" '.$full_style_wrapper.'>'.$my_post_text.'...<span><a class="wff-less-link" style="display:none">'.$atts['read_less'].'</a></span></p>';
  700. }
  701. else{
  702. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_text.'</p>';
  703. }
  704. /*------------------------------------------------*/
  705. if(isset($mysinglefeed->description)){
  706. if($atts['link_target']==1) {
  707. $build_link_title = '<p class = "link-title" '.$line_height_style.'><a class="wff-link-tab" target="_blank" href =' .$name_url.'>'.$name_var.'</a></p>';
  708. } else {
  709. $build_link_title = '<p class = "link-title" '.$line_height_style.'><a class="wff-link-tab" href =' .$name_url.'>'.$name_var.'</a></p>';
  710. }
  711. $build_post_desc_html = '<div class = "description-wrapper shared-link">'.$build_link_title.'<p class = "post-desc" '.$line_height_style.'>'.$link_post_desc.'</p></div>';
  712. }
  713.  
  714. if($atts['link_target']==1) {
  715. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  716. } else {
  717. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  718. }
  719. return $mytext;
  720. }
  721.  
  722. function build_my_video_html ($mysinglefeed ,$atts)
  723. {
  724. if (isset($mysinglefeed->story))
  725. {
  726. // if story exists then use the story in the post text
  727. $my_post_text = $mysinglefeed->story;
  728. }
  729. if (isset($mysinglefeed->message))
  730. {
  731. // if story exists then use the story in the post text
  732. $my_post_text = $mysinglefeed->message;
  733. $my_post_text = makeLinks($my_post_text,$atts['link_target']);
  734. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$my_post_text)) {
  735. $my_post_text = make_hash_link($my_post_text,$atts['link_target']);
  736. }
  737. }
  738.  
  739. // Build Post description
  740. // first hyper link the name
  741. $name_var = (isset($mysinglefeed->name) ? $mysinglefeed->name : '');
  742. $name_url = (isset($mysinglefeed->link) ? $mysinglefeed->link : '');
  743.  
  744. $link_post_desc = (isset($mysinglefeed->description) ? $mysinglefeed->description : '');
  745. $link_post_desc = makeLinks($link_post_desc,$atts['link_target']);
  746. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$link_post_desc)) {
  747. $link_post_desc = make_hash_link($link_post_desc,$atts['link_target']);
  748. }
  749. if (array_key_exists('message_tags',$mysinglefeed ))
  750. {
  751. // now add the hyperlink to tags
  752. foreach ( $mysinglefeed->message_tags as $mymessagetag)
  753. {
  754. $mymessagetagname = $mymessagetag->name;
  755. if($atts['link_target']==1) {
  756. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  757. } else {
  758. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  759. }
  760. $my_post_text = str_replace($mymessagetagname, $tag_link, $my_post_text);
  761. }
  762. }
  763. $the_resource_id_array = explode("_", $mysinglefeed->id);
  764. $the_resource_id = $the_resource_id_array[1];
  765.  
  766. $post_resource_link = 'https://facebook.com/'.$atts['page_id'] .'/posts/'.$the_resource_id;
  767.  
  768. //call post text inline style
  769. $limited_style_wrapper = limited_post_text_inline_style($atts);
  770. $full_style_wrapper = full_post_text_inline_style($atts);
  771. $line_height_style = feed_line_height($atts);
  772. /*---------------------read more text---------------------------*/
  773. $str_without_tag = strip_tags($my_post_text);
  774. $char_count = strlen($str_without_tag);
  775.  
  776. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  777. {
  778. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  779.  
  780. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); // link the urls
  781. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  782. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  783. }
  784. if (array_key_exists('message_tags',$mysinglefeed ))
  785. {
  786. foreach( $mysinglefeed->message_tags as $mymessagetag)// now add the hyperlink to tags
  787. {
  788. $mymessagetagname = $mymessagetag->name;
  789. if($atts['link_target']==1) {
  790. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" target="_blank">' . $mymessagetag->name . '</a>';
  791. } else {
  792. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag->id . '" style="color: red;" >' . $mymessagetag->name . '</a>';
  793. }
  794. $short_sentence = str_replace($mymessagetagname, $tag_link, $short_sentence);
  795. }
  796. }
  797.  
  798. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link">'.$atts['read_more'].'</a></span></p>';
  799. $mytext .= '<p class="more-content" '.$full_style_wrapper.'>'.$my_post_text.'...<span><a class="wff-less-link" style="display:none">'.$atts['read_less'].'</a></span></p>';
  800. }
  801. else{
  802. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_text.'</p>';
  803. }
  804. /*------------------------------------------------*/
  805. if(isset($mysinglefeed->description)){
  806. if($atts['link_target']==1) {
  807. $build_link_title = '<p class = "wff-link-title" '.$line_height_style.'><a class="wff-link-tab" target="_blank" href =' .$name_url.'>'.$name_var.'</a></p>';
  808. } else {
  809. $build_link_title = '<p class = "wff-link-title" '.$line_height_style.'><a class="wff-link-tab" href =' .$name_url.'>'.$name_var.'</a></p>';
  810. }
  811. $mytext .= '<div class = "wff-shared-link-wrapper">'.$build_link_title.'<p class = "wff-post-description" '.$line_height_style.'>'.$link_post_desc.'</p></div>';
  812. }
  813.  
  814. //$mytext .= $build_post_desc_html ;
  815. if($atts['link_target']==1) {
  816. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  817. } else {
  818. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  819. }
  820. return $mytext;
  821. }
  822. // function: to calculate difference b/w current time and post updated time in different time units.
  823. function posted_time($time)
  824. {
  825. $time = time() - $time; // to get the time since that moment
  826.  
  827. $time_units = array (
  828. 31536000 => 'year',
  829. 2592000 => 'month',
  830. 604800 => 'week',
  831. 86400 => 'day',
  832. 3600 => 'hour',
  833. 60 => 'minute',
  834. 1 => 'second'
  835. );
  836.  
  837. foreach ($time_units as $unit => $text) {
  838. if ($time < $unit) continue;
  839. $numberOfUnits = floor($time / $unit);
  840. return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
  841. }
  842.  
  843. }
  844. function build_author_html($mysinglefeed,$atts)
  845. {
  846. // Check if we need to apply inline styles
  847. //Author
  848. $wff_author_inline_style = 'style="';
  849. if ( !empty($atts['author_text_size']) && $atts['author_text_size'] != 'inherit' ) $wff_author_inline_style .= 'font-size:' . $atts['author_text_size'] . 'px; line-height:' . $atts['author_text_size'] . 'px; ';
  850. if ( !empty($atts['line_height']) && $atts['line_height'] != 'inherit' ) $wff_author_inline_style .= 'line-height:' . $atts['line_height'].'px;';
  851. if ( !empty($atts['author_text_color']) ) $wff_author_inline_style .= 'color:' .$atts['author_text_color'] . ';';
  852. $wff_author_inline_style .= '"';
  853.  
  854. //img border size and color style
  855. $wff_author_image_style = 'style="';
  856. if ( !empty($atts['author_img_border']) && $atts['author_img_border'] != 'none' ) $wff_author_image_style .= 'border:' . $atts['author_img_border'] . 'px solid ';
  857. if ( !empty($atts['author_text_color']) ) $wff_author_image_style .= $atts['author_text_color'] .';';
  858. $wff_author_image_style .= '"';
  859.  
  860. $link_to_page = 'https://facebook.com/'.$atts['page_id'];
  861.  
  862. // get update date
  863. $time = strtotime($mysinglefeed->updated_time);
  864.  
  865. //condition for date format
  866. if($atts['author_date_format']=='default'){
  867. $post_date_print = 'posted '.posted_time($time).' ago';
  868. }
  869. else{
  870. $system_date_format = $atts['author_date_format'];
  871. $post_date_print = date_i18n($system_date_format,$time);
  872. }
  873.  
  874. $authorname = '<div class = "wff-author-name"><p '.$wff_author_inline_style.' >'. $mysinglefeed->from->name . '</p><p class = "wff-date">'.$post_date_print.'</p></div>';
  875.  
  876. $authorimage = '<div class = "wff-author-image"><img '.$wff_author_image_style.' src = https://graph.facebook.com/' . $mysinglefeed->from->id . '/picture?type=square></div>';
  877.  
  878. $authortext = '<div class = "wff-fb-author-data" ><div class="wff-row">
  879. <div class="wff-facebook-feed-image-div">'.$authorimage.'</div>
  880. <div class="wff-facebook-feed-title-div">'.$authorname.'</div>
  881. </div></div><div class="cleafix"></div>';
  882.  
  883. if($atts['link_target']==1){
  884. $authortext = '<a class="wff-link-tab" href ='. $link_to_page .' target="_blank" >'.$authortext.'</a>';
  885. } else {
  886. $authortext = '<a class="wff-link-tab" href ='. $link_to_page .'>'.$authortext.'</a>';
  887. }
  888. $authortext = '<div class = "wff-author-wrapper">'.$authortext.'</div>';
  889.  
  890. return $authortext;
  891. }
  892.  
  893. //add easy facebook feed shortcode
  894. add_shortcode('facebook-feed','wff_shortcode_display');
  895.  
  896. function wff_shortcode_display ($atts) {
  897.  
  898. if(!function_exists('wff_custom_js_code')) {
  899. add_action( 'wp_footer', 'wff_custom_js_code' );
  900. function wff_custom_js_code() {
  901.  
  902. $custom_js_setting = get_option ('wff_design_settings');
  903. $custom_js = ($custom_js_setting['wff_custom_js_data']) ? $custom_js_setting['wff_custom_js_data'] : '' ;
  904. $custom_js_snippet = isset($custom_js) ? $custom_js : '';
  905.  
  906. echo '<script type="text/javascript">';
  907. if( !empty($custom_js_snippet) ) echo stripslashes($custom_js_snippet);
  908. echo '</script>';
  909. }
  910. }
  911.  
  912. // add custom styles
  913. if(!function_exists('wff_custom_css_code')) {
  914. add_action( 'wp_footer', 'wff_custom_css_code' );
  915. function wff_custom_css_code() {
  916. $custom_css_setting = get_option ('wff_design_settings');
  917. $custom_css = ($custom_css_setting['wff_custom_css_data']) ? $custom_css_setting['wff_custom_css_data'] : '' ;
  918. $custom_css_snippet = isset($custom_css) ? stripslashes($custom_css) : '';
  919. echo '<style type="text/css">'.$custom_css_snippet.'</style>';
  920. }
  921. }
  922. // enqueue script for character count
  923. if(!function_exists('wff_load_custom_scripts')) {
  924. add_action( 'wp_footer', 'wff_load_custom_scripts' );
  925. function wff_load_custom_scripts() {
  926. wp_register_script( 'wff_custom_js', plugin_dir_url( __FILE__ ) . 'js/text-count.js',array('jquery'), false, true );
  927. wp_enqueue_script ('wff_custom_js');
  928. }
  929. }
  930. if(!function_exists('add_my_stylesheet')) {
  931. add_action( 'wp_footer', 'add_my_stylesheet' );
  932. function add_my_stylesheet() {
  933. wp_register_style( 'wff-mystyle', plugins_url('css/style.css', __FILE__) );
  934. wp_enqueue_style( 'wff-mystyle' );
  935. }
  936. }
  937. //default app token
  938. $design_setting_array = get_option ('wff_design_settings');
  939. $general_setting_array = get_option ('wff_general_settings');
  940.  
  941. $facebookpageid = get_option('wff_page_id');
  942.  
  943. $all_array =array(
  944. 'page_id' => ( !empty( $facebookpageid ) ? $facebookpageid : '' ),
  945. 'wff_post_limit' => ($general_setting_array['wff_num_posts']) ? $general_setting_array['wff_num_posts'] : '',
  946. 'cache_time' => ($general_setting_array['wff_cache_time']) ? $general_setting_array['wff_cache_time'] : '',
  947. 'link_target' => ($general_setting_array['wff_link_target']) ? 1 : 0,
  948.  
  949. 'author_date_format' => (get_option('wff_author_date')) ? get_option('wff_author_date') : '',
  950. 'author_text_size' => ($design_setting_array['wff_author_text_size']) ? $design_setting_array['wff_author_text_size'] : '',
  951. 'line_height' => ($design_setting_array['wff_line_height']) ? $design_setting_array['wff_line_height'] : '',
  952. 'author_text_color' => ($design_setting_array['wff_author_text_color']) ? $design_setting_array['wff_author_text_color'] : '',
  953. 'author_img_border' => ($design_setting_array['wff_img_border']) ? $design_setting_array['wff_img_border'] : '',
  954. 'feed_seprator' => ($design_setting_array['wff_feed_seprator']) ? $design_setting_array['wff_feed_seprator'] : '',
  955.  
  956. 'char_limit' => ($design_setting_array['wff_char_limit']) ? $design_setting_array['wff_char_limit'] : '',
  957. 'post_text_color' => ($design_setting_array['wff_text_color']) ? $design_setting_array['wff_text_color'] : '',
  958. 'post_background' => ($design_setting_array['wff_post_back_color']) ? $design_setting_array['wff_post_back_color'] : '',
  959. 'post_text_weight' => ($design_setting_array['wff_text_weight']) ? $design_setting_array['wff_text_weight'] : '',
  960. 'post_text_size' => ($design_setting_array['wff_text_size']) ? $design_setting_array['wff_text_size'] : '',
  961. 'post_text_align' => ($design_setting_array['wff_text_align']) ? $design_setting_array['wff_text_align'] : '',
  962.  
  963. 'page_link_text' => ($design_setting_array['wff_page_link_text']) ? $design_setting_array['wff_page_link_text'] : '',
  964. 'read_more' => ($design_setting_array['wff_read_more_text']) ? $design_setting_array['wff_read_more_text'] : '',
  965. 'read_less' => ($design_setting_array['wff_read_less_text']) ? $design_setting_array['wff_read_less_text'] : '',
  966. );
  967.  
  968. $atts = shortcode_atts($all_array,$atts,'facebook-feed');
  969.  
  970. extract($atts);
  971.  
  972. // Get the Page ID
  973. if( empty($page_id) )
  974. {
  975. $error_message = '<p style = "color:red;" > Please enter valid Facebook Page ID</p>'; // error if a user does not enter page id
  976. return $error_message;
  977. }
  978.  
  979. $wff_app_token=array('1505917499687703|2133Lp1cLt6Zk0N2por8X8QJf9k',
  980. '393872077427061|ghfVBzNUFnMdFLAGlJbWAOVOelI',
  981. '1377619605888926|LxwTNNAeRtn9nYhYS0VDkVDs0mI'); // We will provide support for user token in future updates
  982.  
  983. $access_token = $wff_app_token[rand(0, 2)];
  984.  
  985. //initialise facepress object
  986. $wff_posts_json_url = 'https://graph.facebook.com/' . $page_id . '/posts?fields=id,from,message,message_tags,story,story_tags,link,picture,full_picture,attachments,source,updated_time,name,caption,description,type,status_type,object_id,created_time&access_token=' . $access_token . '&limit=' . $wff_post_limit;
  987.  
  988. if($cache_time == 'none') {
  989. try{
  990. $feeddata = wff_fetchUrl($wff_posts_json_url);
  991. $feedjson = json_decode($feeddata);
  992. $fbfeed = $feedjson->data;
  993. }
  994. catch(Exception $e)
  995. {
  996. echo $e->getMessage();
  997. die();
  998. }
  999.  
  1000. }else{
  1001.  
  1002. try{
  1003. // this code runs when there is no valid transient set
  1004. if ( false === ($feeddata = get_transient('fb_feed_query'))) {
  1005. $feeddata = wff_fetchUrl($wff_posts_json_url);
  1006. $feeddata = set_transient('fb_feed_query', $feeddata, $cache_time*60);
  1007. $feeddata = get_transient('fb_feed_query');
  1008. }
  1009. $feedjson = json_decode($feeddata);
  1010. $fbfeed = $feedjson->data;
  1011.  
  1012. }
  1013. catch(Exception $e)
  1014. {
  1015. echo $e->getMessage();
  1016. die();
  1017. }
  1018. }
  1019.  
  1020. if( empty($fbfeed) )
  1021. {
  1022. $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 the error code
  1023. return $error_message ;
  1024. }
  1025.  
  1026. // Start Building HTML
  1027. $my_final_post_text = '';
  1028. $my_final_post_text_item_wrapper = '';
  1029. $my_final_post_text_item_wrapper_complete = '';
  1030.  
  1031. foreach ($fbfeed as $singlefeed)
  1032. {
  1033. $my_final_post_text = ''; // this var will hold author data + post text + post desc.. We will wrap this var in item wrapper
  1034.  
  1035. $my_author_text = build_author_html($singlefeed,$atts);
  1036.  
  1037. $what_is_post_type = $singlefeed->type;
  1038.  
  1039. if($what_is_post_type == 'link')
  1040. {
  1041. $my_post_content_text = build_my_link_html ($singlefeed,$atts);
  1042. }
  1043.  
  1044. if ($what_is_post_type == 'photo')
  1045. {
  1046. $my_post_content_text = build_my_photo_html($singlefeed,$atts);
  1047. }
  1048. if($what_is_post_type == 'video')
  1049. {
  1050. $my_post_content_text = build_my_video_html ($singlefeed,$atts);
  1051. }
  1052.  
  1053. if($what_is_post_type == 'status')
  1054. {
  1055. if (!empty($singlefeed->message))
  1056. {
  1057. $my_post_content_text = build_my_status_html ($singlefeed,$atts);
  1058. }
  1059. // You will cehck if this post has a message. Likes and commnts etc are not to be displayed with the feed
  1060. }
  1061.  
  1062. if ($what_is_post_type == 'event')
  1063. {
  1064. $my_post_content_text = build_my_event_html ($singlefeed,$atts,$access_token);
  1065. }
  1066.  
  1067. //feed seprator inline style
  1068. $wff_feed_seprator_style = 'style="';
  1069. if ( !empty($feed_seprator) && $feed_seprator != 'none' ) $wff_feed_seprator_style .= 'border-bottom:' . $feed_seprator . 'px solid ';
  1070. if ( !empty($author_text_color) ) $wff_feed_seprator_style .= $author_text_color .';';
  1071. $wff_feed_seprator_style .= '"';
  1072.  
  1073. // the final post text
  1074. $my_final_post_text .= $my_author_text.$my_post_content_text ;
  1075.  
  1076. switch ($what_is_post_type) {
  1077.  
  1078. case 'link':
  1079. $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>';
  1080. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1081. break;
  1082.  
  1083. case 'status':
  1084. $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>';
  1085. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1086. break;
  1087.  
  1088. case 'event':
  1089. $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>';
  1090. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1091. break;
  1092.  
  1093. case 'video':
  1094. $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>';
  1095. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1096. break;
  1097.  
  1098. case 'photo':
  1099. $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>';
  1100. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1101. break;
  1102.  
  1103. }
  1104. }
  1105. $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
  1106.  
  1107. // Return the complete html
  1108. return $my_final_post_text;
  1109. }
  1110. ?>
Add Comment
Please, Sign In to add comment