Guest User

Untitled

a guest
May 30th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.30 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[0]->name;
  164. if($atts['link_target']==1) {
  165. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  166. } else {
  167. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" >' . $mystorytag[0]->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[0]->name;
  195. if($atts['link_target']==1) {
  196. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  197. } else {
  198. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->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[0]->name;
  225. if($atts['link_target']==1) {
  226. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  227. } else {
  228. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" >' . $mystorytag[0]->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[0]->name;
  238. if($atts['link_target']==1) {
  239. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  240. } else {
  241. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->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[0]->name;
  312. if($atts['link_target']==1) {
  313. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  314. } else {
  315. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;">' . $mystorytag[0]->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[0]->name;
  357. if($atts['link_target']==1) {
  358. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  359. } else {
  360. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->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[0]->name;
  389. if($atts['link_target']==1) {
  390. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  391. } else {
  392. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" >' . $mystorytag[0]->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[0]->name;
  403. if($atts['link_target']==1) {
  404. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  405. } else {
  406. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->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. $event_date_print .= " - ". $event_end_date_print;
  485. }
  486.  
  487. if (isset($mysinglefeed->story))
  488. {
  489. // if story exists then use the story in the post text
  490. $my_post_text = $mysinglefeed->story;
  491.  
  492. if (array_key_exists('story_tags',$mysinglefeed ))
  493. {
  494. // now add the hyperlink to tags
  495. foreach ( $mysinglefeed->story_tags as $mystorytag)
  496. {
  497. $mystorytagname = $mystorytag[0]->name;
  498. if($atts['link_target']==1) {
  499. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  500. } else {
  501. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" >' . $mystorytag[0]->name . '</a>';
  502. }
  503. $my_post_text = str_replace($mystorytagname, $tag_link, $my_post_text);
  504. }
  505. }
  506. }
  507.  
  508. if (isset($mysinglefeed->message))
  509. {
  510. // if story exists then use the story in the post text
  511. $my_post_text = $mysinglefeed->message;
  512. $my_post_text = makeLinks($my_post_text,$atts['link_target']);
  513. 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)) {
  514. $my_post_text = make_hash_link($my_post_text,$atts['link_target']);
  515. }
  516. }
  517.  
  518. //call post text inline style
  519. $limited_style_wrapper = limited_post_text_inline_style($atts);
  520. $full_style_wrapper = full_post_text_inline_style($atts);
  521. $line_height_style = feed_line_height($atts);
  522. /*---------------------read more text---------------------------*/
  523.  
  524. $str_without_tag = strip_tags($my_post_text);
  525. $char_count = strlen($str_without_tag);
  526.  
  527. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  528. {
  529. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  530.  
  531. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); // link the urls
  532. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  533. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  534. }
  535. if (array_key_exists('story_tags',$mysinglefeed)) {
  536. // now add the hyperlink to tags
  537. foreach ( $mysinglefeed->story_tags as $mystorytag)
  538. {
  539. $mystorytagname = $mystorytag[0]->name;
  540. if($atts['link_target']==1) {
  541. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  542. } else {
  543. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" >' . $mystorytag[0]->name . '</a>';
  544. }
  545. $short_sentence = str_replace($mystorytagname, $tag_link, $short_sentence);
  546. }
  547. }
  548.  
  549. $finaltext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link">'.$atts['read_more'].'</a></span></p>';
  550. $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>';
  551. }
  552. else {
  553. $finaltext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_text.'</p>';
  554. }
  555. /*------------------------------------------------*/
  556. $post_resource_link = $mysinglefeed->link;
  557. $event_title = $event_data->name;
  558. $event_description = $event_data->description;
  559. //$event_location = $event_data->location;
  560. $finaltext .= '<div class = "wff-fb-item-event-wrapper">';
  561. $finaltext .= '<div class = "fb-text-wrapper">';
  562. $finaltext .= '<div class = "fb-post-data description-wrapper">';
  563. if($atts['link_target']==1) {
  564. $finaltext .= '<p class="wff-event-title" '.$line_height_style.'><a class="wff-link-tab" href = '.$post_resource_link. ' target = "_blank">'.$event_title.'</a></p>';
  565. } else {
  566. $finaltext .= '<p class="wff-event-title" '.$line_height_style.'><a class="wff-link-tab" href = '.$post_resource_link. ' >'.$event_title.'</a></p>';
  567. }
  568. $finaltext .= '<p class="wff-event-content" '.$line_height_style.'>'.$event_description.'</p>';// close post data div
  569. $finaltext .= '<div class = "event-date">'.$event_date_print.'</div></div>' ; // the date div
  570. if($atts['link_target']==1) {
  571. $finaltext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '.$post_resource_link. ' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  572. } else {
  573. $finaltext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '.$post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  574. }
  575. $finaltext .= '</div></div>'; // close text wrapper and event wrapper
  576.  
  577. return $finaltext ;
  578. }
  579.  
  580. function build_my_status_html ($mysinglefeed ,$atts)
  581. {
  582. // every where we will check if there is no message..
  583. //A stroy description will be used only when there is no message
  584.  
  585. if (isset($mysinglefeed->story))
  586. {
  587. // if story exists then use the story in the post text
  588.  
  589. $my_post_text = $mysinglefeed->story;
  590.  
  591. if (array_key_exists('story_tags',$mysinglefeed ))
  592. {
  593. // now add the hyperlink to tags
  594. foreach ( $mysinglefeed->story_tags as $mystorytag)
  595. {
  596. $mystorytagname = $mystorytag[0]->name;
  597. if($atts['link_target']==1) {
  598. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  599. } else {
  600. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" >' . $mystorytag[0]->name . '</a>';
  601. }
  602. $my_post_text = str_replace($mystorytagname, $tag_link, $my_post_text);
  603. }
  604. }
  605. }
  606.  
  607. if (isset($mysinglefeed->message))
  608. {
  609. // if story exists then use the story in the post text
  610. $my_post_text = $mysinglefeed->message;
  611. $my_post_text = makeLinks($my_post_text,$atts['link_target']);
  612. 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)) {
  613. $my_post_text = make_hash_link ($my_post_text,$atts['link_target']);
  614. }
  615. }
  616. // Build Post description
  617. // first hyper link the name
  618.  
  619. $name_var = (isset($mysinglefeed->name) ? $mysinglefeed->name : '');
  620. $name_url = (isset($mysinglefeed->link) ? $mysinglefeed->link : '');
  621.  
  622. $link_post_desc = (isset($mysinglefeed->description) ? $mysinglefeed->description : '');
  623. $link_post_desc = makeLinks($link_post_desc,$atts['link_target']);
  624. 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)) {
  625. $link_post_desc = make_hash_link($link_post_desc,$atts['link_target']);
  626. }
  627. if (array_key_exists('message_tags',$mysinglefeed ))
  628. {
  629. // now add the hyperlink to tags
  630. foreach ( $mysinglefeed->message_tags as $mymessagetag)
  631. {
  632. $mymessagetagname = $mymessagetag[0]->name;
  633. if($atts['link_target']==1) {
  634. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  635. } else {
  636. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->name . '</a>';
  637. }
  638. $my_post_text = str_replace($mymessagetagname, $tag_link, $my_post_text);
  639. }
  640. }
  641. $the_resource_id_array = explode("_", $mysinglefeed->id);
  642. $the_resource_id = $the_resource_id_array[1];
  643. $post_resource_link = 'https://facebook.com/'.$atts['page_id'] .'/posts/'.$the_resource_id;
  644.  
  645. //call post text inline style
  646. $limited_style_wrapper = limited_post_text_inline_style($atts);
  647. $full_style_wrapper = full_post_text_inline_style($atts);
  648. $line_height_style = feed_line_height($atts);
  649. /*---------------------read more text---------------------------*/
  650.  
  651. $str_without_tag = strip_tags($my_post_text);
  652. $char_count = strlen($str_without_tag);
  653.  
  654. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  655. {
  656. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  657.  
  658. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); // link the urls
  659. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  660. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  661. }
  662. if (array_key_exists('story_tags',$mysinglefeed ))
  663. {
  664. foreach ( $mysinglefeed->story_tags as $mystorytag)
  665. {
  666. $mystorytagname = $mystorytag[0]->name;
  667. if($atts['link_target']==1) {
  668. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" target="_blank">' . $mystorytag[0]->name . '</a>';
  669. } else {
  670. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mystorytag[0]->id . '" style="color: indigo;" >' . $mystorytag[0]->name . '</a>';
  671. }
  672. $short_sentence = str_replace($mystorytagname, $tag_link, $short_sentence);
  673. }
  674. }
  675.  
  676. if (array_key_exists('message_tags',$mysinglefeed ))
  677. {
  678. foreach( $mysinglefeed->message_tags as $mymessagetag)// now add the hyperlink to tags
  679. {
  680. $mymessagetagname = $mymessagetag[0]->name;
  681. if($atts['link_target']==1) {
  682. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  683. } else {
  684. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->name . '</a>';
  685. }
  686. $short_sentence = str_replace($mymessagetagname, $tag_link, $short_sentence);
  687. }
  688. }
  689. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link">'.$atts['read_more'].'</a></span></p>';
  690. $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>';
  691. }
  692. else{
  693. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_text.'</p>';
  694. }
  695. /*------------------------------------------------*/
  696. if(isset($mysinglefeed->description)){
  697. if($atts['link_target']==1) {
  698. $build_link_title = '<p class = "link-title" '.$line_height_style.'><a class="wff-link-tab" target="_blank" href =' .$name_url.'>'.$name_var.'</a></p>';
  699. } else {
  700. $build_link_title = '<p class = "link-title" '.$line_height_style.'><a class="wff-link-tab" href =' .$name_url.'>'.$name_var.'</a></p>';
  701. }
  702. $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>';
  703. }
  704.  
  705. if($atts['link_target']==1) {
  706. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  707. } else {
  708. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  709. }
  710. return $mytext;
  711. }
  712.  
  713. function build_my_video_html ($mysinglefeed ,$atts)
  714. {
  715. if (isset($mysinglefeed->story))
  716. {
  717. // if story exists then use the story in the post text
  718. $my_post_text = $mysinglefeed->story;
  719. }
  720. if (isset($mysinglefeed->message))
  721. {
  722. // if story exists then use the story in the post text
  723. $my_post_text = $mysinglefeed->message;
  724. $my_post_text = makeLinks($my_post_text,$atts['link_target']);
  725. 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)) {
  726. $my_post_text = make_hash_link($my_post_text,$atts['link_target']);
  727. }
  728. }
  729.  
  730. // Build Post description
  731. // first hyper link the name
  732. $name_var = (isset($mysinglefeed->name) ? $mysinglefeed->name : '');
  733. $name_url = (isset($mysinglefeed->link) ? $mysinglefeed->link : '');
  734.  
  735. $link_post_desc = (isset($mysinglefeed->description) ? $mysinglefeed->description : '');
  736. $link_post_desc = makeLinks($link_post_desc,$atts['link_target']);
  737. 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)) {
  738. $link_post_desc = make_hash_link($link_post_desc,$atts['link_target']);
  739. }
  740. if (array_key_exists('message_tags',$mysinglefeed ))
  741. {
  742. // now add the hyperlink to tags
  743. foreach ( $mysinglefeed->message_tags as $mymessagetag)
  744. {
  745. $mymessagetagname = $mymessagetag[0]->name;
  746. if($atts['link_target']==1) {
  747. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  748. } else {
  749. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->name . '</a>';
  750. }
  751. $my_post_text = str_replace($mymessagetagname, $tag_link, $my_post_text);
  752. }
  753. }
  754. $the_resource_id_array = explode("_", $mysinglefeed->id);
  755. $the_resource_id = $the_resource_id_array[1];
  756.  
  757. $post_resource_link = 'https://facebook.com/'.$atts['page_id'] .'/posts/'.$the_resource_id;
  758.  
  759. //call post text inline style
  760. $limited_style_wrapper = limited_post_text_inline_style($atts);
  761. $full_style_wrapper = full_post_text_inline_style($atts);
  762. $line_height_style = feed_line_height($atts);
  763. /*---------------------read more text---------------------------*/
  764. $str_without_tag = strip_tags($my_post_text);
  765. $char_count = strlen($str_without_tag);
  766.  
  767. if((!empty($atts['char_limit'])) && ($atts['char_limit'] < $char_count) )
  768. {
  769. $short_sentence = substr($str_without_tag, 0,$atts['char_limit']);
  770.  
  771. $short_sentence = makeLinks ($short_sentence,$atts['link_target']); // link the urls
  772. if(!preg_match('/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)#(\w*[a-zA-Z_]+\w*)/',$short_sentence)) {
  773. $short_sentence = make_hash_link ($short_sentence,$atts['link_target']);
  774. }
  775. if (array_key_exists('message_tags',$mysinglefeed ))
  776. {
  777. foreach( $mysinglefeed->message_tags as $mymessagetag)// now add the hyperlink to tags
  778. {
  779. $mymessagetagname = $mymessagetag[0]->name;
  780. if($atts['link_target']==1) {
  781. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" target="_blank">' . $mymessagetag[0]->name . '</a>';
  782. } else {
  783. $tag_link = '<a class="wff-link-tab" href="http://facebook.com/' . $mymessagetag[0]->id . '" style="color: red;" >' . $mymessagetag[0]->name . '</a>';
  784. }
  785. $short_sentence = str_replace($mymessagetagname, $tag_link, $short_sentence);
  786. }
  787. }
  788.  
  789. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$short_sentence.'...<span><a class="wff-more-link">'.$atts['read_more'].'</a></span></p>';
  790. $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>';
  791. }
  792. else{
  793. $mytext = '<p class = "wff-post-text" '.$limited_style_wrapper.'>'.$my_post_text.'</p>';
  794. }
  795. /*------------------------------------------------*/
  796. if(isset($mysinglefeed->description)){
  797. if($atts['link_target']==1) {
  798. $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>';
  799. } else {
  800. $build_link_title = '<p class = "wff-link-title" '.$line_height_style.'><a class="wff-link-tab" href =' .$name_url.'>'.$name_var.'</a></p>';
  801. }
  802. $mytext .= '<div class = "wff-shared-link-wrapper">'.$build_link_title.'<p class = "wff-post-description" '.$line_height_style.'>'.$link_post_desc.'</p></div>';
  803. }
  804.  
  805. //$mytext .= $build_post_desc_html ;
  806. if($atts['link_target']==1) {
  807. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' target = "_blank">'.$atts['page_link_text'].'</a></div>';
  808. } else {
  809. $mytext .= '<div class = "wff-view-on-facebook"><a class="wff-link-tab" href = '. $post_resource_link.' >'.$atts['page_link_text'].'</a></div>';
  810. }
  811. return $mytext;
  812. }
  813. // function: to calculate difference b/w current time and post updated time in different time units.
  814. function posted_time($time)
  815. {
  816. $time = time() - $time; // to get the time since that moment
  817.  
  818. $time_units = array (
  819. 31536000 => 'year',
  820. 2592000 => 'month',
  821. 604800 => 'week',
  822. 86400 => 'day',
  823. 3600 => 'hour',
  824. 60 => 'minute',
  825. 1 => 'second'
  826. );
  827.  
  828. foreach ($time_units as $unit => $text) {
  829. if ($time < $unit) continue;
  830. $numberOfUnits = floor($time / $unit);
  831. return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
  832. }
  833.  
  834. }
  835. function build_author_html($mysinglefeed,$atts)
  836. {
  837. // Check if we need to apply inline styles
  838. //Author
  839. $wff_author_inline_style = 'style="';
  840. 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; ';
  841. if ( !empty($atts['line_height']) && $atts['line_height'] != 'inherit' ) $wff_author_inline_style .= 'line-height:' . $atts['line_height'].'px;';
  842. if ( !empty($atts['author_text_color']) ) $wff_author_inline_style .= 'color:' .$atts['author_text_color'] . ';';
  843. $wff_author_inline_style .= '"';
  844.  
  845. //img border size and color style
  846. $wff_author_image_style = 'style="';
  847. if ( !empty($atts['author_img_border']) && $atts['author_img_border'] != 'none' ) $wff_author_image_style .= 'border:' . $atts['author_img_border'] . 'px solid ';
  848. if ( !empty($atts['author_text_color']) ) $wff_author_image_style .= $atts['author_text_color'] .';';
  849. $wff_author_image_style .= '"';
  850.  
  851. $link_to_page = 'https://facebook.com/'.$atts['page_id'];
  852.  
  853. // get update date
  854. $time = strtotime($mysinglefeed->updated_time);
  855.  
  856. //condition for date format
  857. if($atts['author_date_format']=='default'){
  858. $post_date_print = 'posted '.posted_time($time).' ago';
  859. }
  860. else{
  861. $system_date_format = $atts['author_date_format'];
  862. $post_date_print = date_i18n($system_date_format,$time);
  863. }
  864.  
  865. $authorname = '<div class = "wff-author-name"><p '.$wff_author_inline_style.' >'. $mysinglefeed->from->name . '</p><p class = "wff-date">'.$post_date_print.'</p></div>';
  866.  
  867. if($atts['show_author_image'] == 1){
  868.  
  869. $authorimage = '<div class="wff-facebook-feed-image-div"><div class = "wff-author-image"><img '.$wff_author_image_style.' src = https://graph.facebook.com/' . $mysinglefeed->from->id . '/picture?type=square></div></div>';
  870. }
  871.  
  872. $authortext = '<div class = "wff-fb-author-data" ><div class="wff-row">'.$authorimage.'
  873. <div class="wff-facebook-feed-title-div">'.$authorname.'</div>
  874. </div></div><div class="cleafix"></div>';
  875.  
  876. if($atts['link_target']==1){
  877. $authortext = '<a class="wff-link-tab" href ='. $link_to_page .' target="_blank" >'.$authortext.'</a>';
  878. } else {
  879. $authortext = '<a class="wff-link-tab" href ='. $link_to_page .'>'.$authortext.'</a>';
  880. }
  881. $authortext = '<div class = "wff-author-wrapper">'.$authortext.'</div>';
  882.  
  883. return $authortext;
  884. }
  885.  
  886. //add easy facebook feed shortcode
  887. add_shortcode('facebook-feed','wff_shortcode_display');
  888.  
  889. function wff_shortcode_display ($atts) {
  890.  
  891. if(!function_exists('wff_custom_js_code')) {
  892. add_action( 'wp_footer', 'wff_custom_js_code' );
  893. function wff_custom_js_code() {
  894.  
  895. $custom_js_setting = get_option ('wff_design_settings');
  896. $custom_js = ($custom_js_setting['wff_custom_js_data']) ? $custom_js_setting['wff_custom_js_data'] : '' ;
  897. $custom_js_snippet = isset($custom_js) ? $custom_js : '';
  898.  
  899. echo '<script type="text/javascript">';
  900. if( !empty($custom_js_snippet) ) echo stripslashes($custom_js_snippet);
  901. echo '</script>';
  902. }
  903. }
  904.  
  905. // add custom styles
  906. if(!function_exists('wff_custom_css_code')) {
  907. add_action( 'wp_footer', 'wff_custom_css_code' );
  908. function wff_custom_css_code() {
  909. $custom_css_setting = get_option ('wff_design_settings');
  910. $custom_css = ($custom_css_setting['wff_custom_css_data']) ? $custom_css_setting['wff_custom_css_data'] : '' ;
  911. $custom_css_snippet = isset($custom_css) ? stripslashes($custom_css) : '';
  912. echo '<style type="text/css">'.$custom_css_snippet.'</style>';
  913. }
  914. }
  915. // enqueue script for character count
  916. if(!function_exists('wff_load_custom_scripts')) {
  917. add_action( 'wp_footer', 'wff_load_custom_scripts' );
  918. function wff_load_custom_scripts() {
  919. wp_register_script( 'wff_custom_js', plugin_dir_url( __FILE__ ) . 'js/text-count.js',array('jquery'), false, true );
  920. wp_enqueue_script ('wff_custom_js');
  921. }
  922. }
  923. if(!function_exists('add_my_stylesheet')) {
  924. add_action( 'wp_footer', 'add_my_stylesheet' );
  925. function add_my_stylesheet() {
  926. wp_register_style( 'wff-mystyle', plugins_url('css/style.css', __FILE__) );
  927. wp_enqueue_style( 'wff-mystyle' );
  928. }
  929. }
  930. //default app token
  931. $design_setting_array = get_option ('wff_design_settings');
  932. $general_setting_array = get_option ('wff_general_settings');
  933.  
  934. $facebookpageid = get_option('wff_page_id');
  935.  
  936. $all_array =array(
  937. 'page_id' => ( !empty( $facebookpageid ) ? $facebookpageid : '' ),
  938. 'wff_post_limit' => ($general_setting_array['wff_num_posts']) ? $general_setting_array['wff_num_posts'] : '',
  939. 'cache_time' => ($general_setting_array['wff_cache_time']) ? $general_setting_array['wff_cache_time'] : '',
  940. 'link_target' => ($general_setting_array['wff_link_target']) ? 1 : 0,
  941.  
  942.  
  943. 'author_date_format' => (get_option('wff_author_date')) ? get_option('wff_author_date') : '',
  944. 'author_text_size' => ($design_setting_array['wff_author_text_size']) ? $design_setting_array['wff_author_text_size'] : '',
  945.  
  946. 'show_author_image' => ($design_setting_array['wff_show_author_image']) ? 1 : 0,
  947.  
  948. 'line_height' => ($design_setting_array['wff_line_height']) ? $design_setting_array['wff_line_height'] : '',
  949. 'author_text_color' => ($design_setting_array['wff_author_text_color']) ? $design_setting_array['wff_author_text_color'] : '',
  950. 'author_img_border' => ($design_setting_array['wff_img_border']) ? $design_setting_array['wff_img_border'] : '',
  951. 'feed_seprator' => ($design_setting_array['wff_feed_seprator']) ? $design_setting_array['wff_feed_seprator'] : '',
  952.  
  953. 'char_limit' => ($design_setting_array['wff_char_limit']) ? $design_setting_array['wff_char_limit'] : '',
  954. 'post_text_color' => ($design_setting_array['wff_text_color']) ? $design_setting_array['wff_text_color'] : '',
  955. 'post_background' => ($design_setting_array['wff_post_back_color']) ? $design_setting_array['wff_post_back_color'] : '',
  956. 'post_text_weight' => ($design_setting_array['wff_text_weight']) ? $design_setting_array['wff_text_weight'] : '',
  957. 'post_text_size' => ($design_setting_array['wff_text_size']) ? $design_setting_array['wff_text_size'] : '',
  958. 'post_text_align' => ($design_setting_array['wff_text_align']) ? $design_setting_array['wff_text_align'] : '',
  959.  
  960. 'page_link_text' => ($design_setting_array['wff_page_link_text']) ? $design_setting_array['wff_page_link_text'] : '',
  961. 'read_more' => ($design_setting_array['wff_read_more_text']) ? $design_setting_array['wff_read_more_text'] : '',
  962. 'read_less' => ($design_setting_array['wff_read_less_text']) ? $design_setting_array['wff_read_less_text'] : '',
  963. );
  964.  
  965. $atts = shortcode_atts($all_array,$atts,'facebook-feed');
  966.  
  967. extract($atts);
  968.  
  969. // Get the Page ID
  970. if( empty($page_id) )
  971. {
  972. $error_message = '<p style = "color:red;" > Please enter valid Facebook Page ID</p>'; // error if a user does not enter page id
  973. return $error_message;
  974. }
  975.  
  976. $wff_app_token=array('1505917499687703|2133Lp1cLt6Zk0N2por8X8QJf9k',
  977. '393872077427061|ghfVBzNUFnMdFLAGlJbWAOVOelI',
  978. '1377619605888926|LxwTNNAeRtn9nYhYS0VDkVDs0mI'); // We will provide support for user token in future updates
  979.  
  980. $access_token = $wff_app_token[rand(0, 2)];
  981.  
  982. //initialise facepress object
  983. $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;
  984.  
  985. if($cache_time == 'none') {
  986. try{
  987. $feeddata = wff_fetchUrl($wff_posts_json_url);
  988. $feedjson = json_decode($feeddata);
  989. $fbfeed = $feedjson->data;
  990. }
  991. catch(Exception $e)
  992. {
  993. echo $e->getMessage();
  994. die();
  995. }
  996.  
  997. }else{
  998.  
  999. try{
  1000. // this code runs when there is no valid transient set
  1001. if ( false === ($feeddata = get_transient('fb_feed_query'))) {
  1002. $feeddata = wff_fetchUrl($wff_posts_json_url);
  1003. $feeddata = set_transient('fb_feed_query', $feeddata, $cache_time*60);
  1004. $feeddata = get_transient('fb_feed_query');
  1005. }
  1006. $feedjson = json_decode($feeddata);
  1007. $fbfeed = $feedjson->data;
  1008.  
  1009. }
  1010. catch(Exception $e)
  1011. {
  1012. echo $e->getMessage();
  1013. die();
  1014. }
  1015. }
  1016.  
  1017. if( empty($fbfeed) )
  1018. {
  1019. $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
  1020. return $error_message ;
  1021. }
  1022.  
  1023. // Start Building HTML
  1024. $my_final_post_text = '';
  1025. $my_final_post_text_item_wrapper = '';
  1026. $my_final_post_text_item_wrapper_complete = '';
  1027.  
  1028. foreach ($fbfeed as $singlefeed)
  1029. {
  1030. $my_final_post_text = ''; // this var will hold author data + post text + post desc.. We will wrap this var in item wrapper
  1031.  
  1032. $my_author_text = build_author_html($singlefeed,$atts);
  1033.  
  1034. $what_is_post_type = $singlefeed->type;
  1035.  
  1036. if($what_is_post_type == 'link')
  1037. {
  1038. $my_post_content_text = build_my_link_html ($singlefeed,$atts);
  1039. }
  1040.  
  1041. if ($what_is_post_type == 'photo')
  1042. {
  1043. $my_post_content_text = build_my_photo_html($singlefeed,$atts);
  1044. }
  1045. if($what_is_post_type == 'video')
  1046. {
  1047. $my_post_content_text = build_my_video_html ($singlefeed,$atts);
  1048. }
  1049.  
  1050. if($what_is_post_type == 'status')
  1051. {
  1052. if (!empty($singlefeed->message))
  1053. {
  1054. $my_post_content_text = build_my_status_html ($singlefeed,$atts);
  1055. }
  1056. // You will cehck if this post has a message. Likes and commnts etc are not to be displayed with the feed
  1057. }
  1058.  
  1059. if ($what_is_post_type == 'event')
  1060. {
  1061. $my_post_content_text = build_my_event_html ($singlefeed,$atts,$access_token);
  1062. }
  1063.  
  1064. //feed seprator inline style
  1065. $wff_feed_seprator_style = 'style="';
  1066. if ( !empty($feed_seprator) && $feed_seprator != 'none' ) $wff_feed_seprator_style .= 'border-bottom:' . $feed_seprator . 'px solid ';
  1067. if ( !empty($author_text_color) ) $wff_feed_seprator_style .= $author_text_color .';';
  1068. $wff_feed_seprator_style .= '"';
  1069.  
  1070. // the final post text
  1071. $my_final_post_text .= $my_author_text.$my_post_content_text ;
  1072.  
  1073. switch ($what_is_post_type) {
  1074.  
  1075. case 'link':
  1076. $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>';
  1077. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1078. break;
  1079.  
  1080. case 'status':
  1081. $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>';
  1082. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1083. break;
  1084.  
  1085. case 'event':
  1086. $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>';
  1087. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1088. break;
  1089.  
  1090. case 'video':
  1091. $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>';
  1092. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1093. break;
  1094.  
  1095. case 'photo':
  1096. $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>';
  1097. $my_final_post_text_item_wrapper_complete .= $my_final_post_text_item_wrapper;
  1098. break;
  1099.  
  1100. }
  1101. }
  1102. $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
  1103.  
  1104. // Return the complete html
  1105. return $my_final_post_text;
  1106. }
  1107. ?>
Add Comment
Please, Sign In to add comment