!', '', $exec2, 1);
preg_match_all('{
Image found using scaledImageFit ';
}
$full_imgs_srcs = array_filter($full_imgs_srcs);
echo '
' . count($full_imgs_srcs) . ' images found to add to the post ';
//status type fix if images found on exec2
if ($type == 'status' && count($full_imgs_srcs) > 0) {
$type = 'photo';
echo '<-- Adjusting type to Photo instead';
}
// ini
$ret['vid_url'] = '';
$ret['vid_id'] = '';
if ($type == 'link') {
preg_match('{l.php\?u=(.*?)&}s', $item, $linkMatches);
$foundLink = $linkMatches[1];
$link = urldecode($foundLink);
print_r('
Found Link:' . $link);
// get link title h3 class=
preg_match('!
([^<]*?) !s', $item, $linkTMatches);
$title = $linkTitle = isset($linkTMatches[1]) ? $linkTMatches[1] : '';
//second try format
Toyota hits the gas on hybrids as EV sales cool. But what does that mean for the planet? | CNN
if (wp_automatic_trim($title) == '') {
preg_match('!
([^<]*?) !s', $item, $linkTMatches);
$title = $linkTitle = $linkTMatches[1];
}
//
سب سے زیادہ جعلی لائسنس کے جعلی امتحانات شاہد خاقان کے زمانے میں پاس کئے گئے،دھماکہ خیز انکشافات
if (wp_automatic_trim($title) == '') {
preg_match('!
([^<]*?) !s', $item, $linkTMatches);
$title = $linkTitle = $linkTMatches[1];
}
echo '
Link title:' . $linkTitle;
// no title for auto generation
if (in_array('OPT_GENERATE_NO_LINK', $camp_opt)) {
$title = '';
}
// get image url
if (isset($all_imgs[0]) && wp_automatic_trim($all_imgs[0]) != '') {
$imgsrc = $link_img = wp_automatic_str_replace('&', '&', $all_imgs[0]);
}
if (stristr($link_img, 'url=') && !stristr($link_img, 'fbcdn.net')) {
$link_img_prts = explode('url=', $link_img);
$link_img = $link_img_prts[1];
$link_img_prts = explode('&', $link_img);
$link_img = urldecode($link_img_prts[0]);
$imgsrc = $link_img;
} else {
// get the image from the loaded page
preg_match('{
' . $link_img . ' ';
} else {
$content .= '
';
}
}
// add link to the content
$content .= '
' . $linkTitle . '
';
// description is no more existing getting it _6m7 _3bt9
preg_match('{_6m7 _3bt9">(.*?)
}s', $exec2, $description_matches);
if (isset($description_matches[1]) && wp_automatic_trim($description_matches[1]) != '') {
$txtContent .= $description_matches[1];
if (!in_array('OPT_FB_TXT_SKIP', $camp_opt)) {
$content .= $description_matches[1];
}
}
} elseif ($type == 'video') {
$style = '';
if (in_array('OPT_FB_VID_IMG_HIDE', $camp_opt)) {
$style = ' style="display:none" ';
}
if (stristr($item, 'youtube.com%2Fwatch')) {
preg_match('{l.php\?u=(.*?)&}s', $item, $linkMatches);
$foundLink = $linkMatches[1];
$link = urldecode($foundLink);
print_r('Video img:' . $link_img;
$imgsrc = $link_img;
if (count($full_imgs_srcs) > 1 && !stristr($exec2, '_3chq')) {
// mixed post multiple images
foreach ($full_imgs_srcs as $imgsrc) {
$content = $content . '
';
}
} else {
$content = '
' . $content;
}
if (stristr($item, '"videoID"')) {
//"videoID":"194028178836794"
preg_match('{videoID":"(.*?)"}s', $item, $id_match);
} elseif (stristr($item, 'photo_id":"')) {
// vid id photo_id":"
preg_match('{photo_id":"(.*?)"}s', $item, $id_match);
} else {
// maybe multiple videos/mixed post? source=media_collage&id=348362152651078&r
preg_match('{source=.*?&id=(\d*?)&}', $item, $id_match);
}
$vid_id = $id_match[1];
$id_match = array($id_match[1]);
echo '
Video ID:' . $vid_id;
// vid url
$vidurl = "https://www.facebook.com/video.php?v=$vid_id";
echo '
Video URL:' . $vidurl;
$ret['vid_url'] = $vidurl;
$ret['vid_id'] = $vid_id;
// embed code
$vidAuto = '';
if (in_array('OPT_FB_VID_AUTO', $camp_opt)) {
$vidAuto = ' autoplay= "true" ';
$autoplay = 'true';
} else {
$autoplay = 'false';
}
$vid_mute = in_array('OPT_FB_VID_MUTE', $camp_opt) ? ' mute=1 ' : '';
$js_mute = !in_array('OPT_FB_VID_MUTE', $camp_opt) ? "window.fbAsyncInit = function() {FB.init({appId : '',xfbml : true,version : 'v2.5'});var my_video_player;FB.Event.subscribe('xfbml.ready', function(msg) {if (msg.type === 'video') {my_video_player = msg.instance; my_video_player.unmute();}});};" : '';
$ret['vid_embed'] = '
';
if ((defined('PARENT_THEME') && (PARENT_THEME == 'truemag' || PARENT_THEME == 'newstube')) || class_exists('Cactus_video')) {
} else {
if (!in_array('OPT_FB_VID_SKIP', $camp_opt)) {
foreach ($id_match as $vid_id_single) {
$content .= '[fb_vid ' . $vid_mute . $vidAuto . ' id="' . $vid_id_single . '"]';
}
}
}
}
} elseif ($type == 'note') {
// title
preg_match('!
([^<]+?)
!s', $item, $title_matches);
$title = $title_matches[1];
// get image url
' . $content;
}
} elseif (isset($all_imgs[0])) {
preg_match('{
}', $all_imgs[0], $imgMatch);
if (isset($imgMatch[1]) && wp_automatic_trim($imgMatch[1]) != '') {
$imgsrc = $link_img = wp_automatic_str_replace('&', '&', $imgMatch[1]);
$content = '
' . $content;
}
}
// description
preg_match('!
([^<]+)
!s', $item, $content_matches);
$content = $content . $content_matches[1];
} elseif ($type == 'event') {
// missing image, event description
// event title
if ($cg_fb_from == 'events') {
//
Decor ideas discussion
preg_match('!
(.*?) !s', $exec2, $title_matches);
} else {
//event from the timeline post
preg_match('!
([^<]+?) !s', $item, $title_matches);
if (empty($title_matches[1])) {
//{"__typename":"Event","name":"
preg_match('!"__typename":"Event","name":"(.*?)"!s', $exec2, $title_matches);
if (!empty($title_matches[1])) {
$title_matches[1] = wp_automatic_fix_json_part($title_matches[1]);
}
}
}
$title = $title_matches[1];
if (stristr($exec2, 'profile_picture_for_sticky_bar":{"uri":"')) {
//ntCoverPhotoRenderer","cover_photo":{"photo":{"image":{"uri":"https:\/
//preg_match ( '!CoverPhotoRenderer","cover_photo":{"photo":{"image":{"uri":"(.*?)"!s', $exec2, $scaled_matches );
//cover_photo":{"photo":{"viewer_image":{"height":960,"width":953},"accessibility_caption":"May be a cartoon of standing","image":{"height":960,"uri":"https:\/\/sc
preg_match('!CoverPhotoRenderer","cover_photo":{"photo":{"viewer_image.*?"uri":"(.*?)"!s', $exec2, $scaled_matches);
if (empty($scaled_matches[1])) {
preg_match('!image":{"height":\d*,"uri":"(.*?)"!s', $exec2, $scaled_matches);
}
} elseif (stristr($exec2, '
' . $content;
}
} elseif ($type == 'offer') {
// offer title
preg_match('!
([^<]+?) !s', $item, $title_matches);
$title = $title_matches[1];
if (wp_automatic_trim($content) == '') {
$content = $title;
}
preg_match('{
' . $content;
}
} elseif ($type == 'photo') {
if (count($full_imgs_srcs) > 0) {
// full sized images found
foreach ($full_imgs_srcs as $single_img_src) {
if (in_array('OPT_FB_IMG_LNK_DISABLE', $camp_opt)) {
$content .= '
';
} else {
$content .= '
';
}
}
} else {
// small sized images
$content = $content . implode('', $all_imgs);
}
preg_match('{src="(.*?)"}', $content, $src_matches);
if (isset($src_matches[1]) && wp_automatic_trim($src_matches[1]) != '') {
$imgsrc = wp_automatic_str_replace('&', '&', $src_matches[1]);
}
}
// check if title exits or generate it
if (wp_automatic_trim($title) == '' && in_array('OPT_GENERATE_FB_TITLE', $camp_opt)) {
echo '
No title generating...';
if (!function_exists('wp_staticize_emoji')) {
} else {
}
// line breaks for title generation stop at line breaks
$tempContent = wp_automatic_str_replace('
', "\n", $txtContent);
$tempContent = wp_automatic_str_replace('See Translation', '', $tempContent);
$tempContent = wp_automatic_str_replace(' ', "\n", $tempContent);
$tempContent = wp_automatic_str_replace(' ', "\n", $tempContent);
$tempContent = wp_automatic_str_replace(' ', "\n", $tempContent);
$tempContent = wp_automatic_str_replace(' ', "\n", $tempContent);
$tempContent = $this->removeEmoji(strip_tags(strip_shortcodes($tempContent)));
$tempContent = preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '', $tempContent);
// Chars count
$charsCount = $camp_general['cg_fb_title_count'];
if (!is_numeric($charsCount)) {
$charsCount = 80;
}
if (function_exists('mb_substr')) {
$newTitle = mb_substr($tempContent, 0, $charsCount);
if (in_array('OPT_GENERATE_FB_RETURN', $camp_opt) && stristr($newTitle, "\n")) {
$suggestedTitle = preg_replace("{\n.*}", '', $newTitle);
if (wp_automatic_trim($suggestedTitle) != '') {
$newTitle = wp_automatic_trim($suggestedTitle);
if (in_array('OPT_FB_STRIP_TITLE', $camp_opt)) {
$before_title_removal = $content;
$content = wp_automatic_str_replace($suggestedTitle . " ", '', $content);
if ($content == $before_title_removal) {
$content = wp_automatic_str_replace('
' . $suggestedTitle . "
", '', $content);
}
if ($content == $before_title_removal) {
$content = wp_automatic_str_replace($suggestedTitle, '', $content);
}
}
}
}
} else {
$newTitle = substr($tempContent, 0, $charsCount);
echo '
mb_str is not installed !!!';
}
if (wp_automatic_trim($newTitle) == '') {
echo '<- Empty title';
} else {
$title = $newTitle;
if (!in_array('OPT_GENERATE_FB_DOT', $camp_opt) && $title != $tempContent) {
$title .= '...';
}
echo ':' . $title;
}
}
if (wp_automatic_trim($title) == '' && in_array('OPT_GENERATE_FB_TITLE_DEFAULT', $camp_opt)) {
$title = $camp_general['cg_fb_title_default'];
echo '<-- Using default title:' . $title;
}
if (wp_automatic_trim($title) == '' && in_array('OPT_FB_TITLE_SKIP', $camp_opt)) {
echo '<-- No title skiping.';
continue;
}
// remove referral suffix
if (stristr($content, 'com/l.php')) {
// extract links
preg_match_all('{"http://l\.facebook\.com/l\.php\?u=(.*?)"}', $content, $matches);
$founds = $matches[0];
$links = $matches[1];
$i = 0;
foreach ($founds as $found) {
$found = wp_automatic_str_replace('"', '', $found);
$link = $links[$i];
$link_parts = explode('&h', $link);
$link = $link_parts[0];
$content = wp_automatic_str_replace($found, urldecode($link), $content);
$i++;
}
}
// replace thumbnails by full image for external links
if (stristr($content, 'safe_image.php')) {
if (!stristr($content, 'fbstaging')) {
preg_match_all('{https://[^:]*?safe_image\.php.*?url=(.*?)"}', $content, $matches);
$found_imgs = $matches[0];
$found_imgs_links = $matches[1];
$i = 0;
foreach ($found_imgs as $found_img) {
$found_imgs_links[$i] = preg_replace('{&.*}', '', $found_imgs_links[$i]);
$found_img_link = urldecode($found_imgs_links[$i]);
$content = wp_automatic_str_replace($found_img, $found_img_link . "\"", $content);
$imgsrc = $found_img_link;
}
} else {
$content = wp_automatic_str_replace('&w=130', '&w=650', $content);
$content = wp_automatic_str_replace('&h=130', '&h=650', $content);
$imgsrc = wp_automatic_str_replace('&w=130', '&w=650', $imgsrc);
$imgsrc = wp_automatic_str_replace('&h=130', '&h=650', $imgsrc);
}
}
// small images check s130x130
if (0 && stristr($content, '130x130') || 0 && $type == 'photo') {
echo '
Small images found extracting full images..';
preg_match_all('{"https://[^"]*?\w130x130/(.*?)\..*?"}', $content, $matches);
$small_imgs_srcs = wp_automatic_str_replace('"', '', $matches[0]);
$small_imgs_ids = $matches[1];
// remove _o or _n
$small_imgs_ids = preg_replace('{_\D}', '', $small_imgs_ids);
// remove start of the id
$small_imgs_ids = preg_replace('{^\d*?_}', '', $small_imgs_ids);
// get oritinal page
$x = 'error';
curl_setopt($this->ch, CURLOPT_HTTPGET, 1);
curl_setopt($this->ch, CURLOPT_URL, wp_automatic_trim(html_entity_decode($url)));
$exec = $this->curl_exec_follow($this->ch);
$x = curl_error($this->ch);
if (stristr($exec, '
}s', $exec, $all_scalled_imgs_matches);
$plain_imas_html = implode(' ', $all_scalled_imgs_matches[0]);
// get ids without date at start \d{8}_(\d*?_\d*?)_
preg_match_all('{\d{4,8}_(\d*?_\d*?)_}', $plain_imas_html, $all_ids_imgs_matches);
$all_ids_imgs = array_unique($all_ids_imgs_matches[1]);
$small_imgs_ids = $all_ids_imgs;
$firstImage = '';
@$firstImage = $all_ids_imgs[0];
$i = 0;
foreach ($small_imgs_ids as $small_imgs_id) {
unset($large_imgs_matches);
// searching full image
preg_match('{src="(https://[^"]*?' . $small_imgs_id . '.*?)"}', $exec, $large_imgs_matches);
// ajaxify images
unset($large_imgs_matches_ajax);
preg_match('{src=(https%3A%2F%2F[^&]*?' . $small_imgs_id . '.*?)&}', $exec, $large_imgs_matches_ajax);
if (wp_automatic_trim($large_imgs_matches[1]) != '') {
$replace_img = $large_imgs_matches[1];
// check if there is a larger ajaxify image or not
if (isset($large_imgs_matches_ajax[1]) && wp_automatic_trim($large_imgs_matches_ajax[1]) != '') {
$replace_img = urldecode($large_imgs_matches_ajax[1]);
}
// if first image and image in the original content differs: case: added x photos to album
if ($i == 0 && (!stristr($content, $small_imgs_id) || !stristr($content, 'w130x130'))) {
echo '
Removing first image first';
$content = preg_replace('{
}', '', $content);
}
// echo ' Replacing '.$small_imgs_srcs[$i] . ' with '.$replace_img;
if (stristr($content, $small_imgs_id)) {
$content = wp_automatic_str_replace($small_imgs_srcs[$i], $replace_img, $content);
} else {
$content = wp_automatic_str_replace('', ' ', $content);
}
}
$i++;
}
if ($type == 'video') {
echo ' Extracting vid image';
preg_match('{background-image: url\((.*?)\)}', $exec, $vid_img_match);
$vid_img = $vid_img_match[1];
if (wp_automatic_trim($vid_img) != '') {
$content = wp_automatic_str_replace($item->picture, $vid_img, $content);
echo '-> success';
} else {
echo '-> failed';
}
}
} else {
echo ' Can not find image id at soure loaded page small img id:' . $small_imgs_ids[0];
}
}
// fix links of facebook short /
// $content = wp_automatic_str_replace('href="/', 'href="https://facebook.com/', $content);
$content = preg_replace('{href="/(\w)}', 'href="https://facebook.com/$1', $content);
// change img class
$content = wp_automatic_str_replace('class="img"', 'class="wp_automatic_fb_img"', $content);
// skip if no image
if (in_array('OPT_FB_IMG_SKIP', $camp_opt)) {
if (!stristr($content, ' link_execlude($camp->camp_id, $url);
continue;
}
}
if ($isEvent == true) {
$ret['original_title'] = $title;
$ret['original_link'] = $url;
$ret['matched_content'] = $content;
$ret['original_date'] = $wpdate;
$ret['image_src'] = $imgsrc;
$ret['post_id'] = $item_id;
// lat and long
$lat = '';
$long = '';
if (stristr($exec2, '"latitude"')) {
// ,"latitude":-7.4464878707658e-12,"longitude":9.0949470177293e-13,
preg_match('{"latitude":(.*?),"longitude":(.*?),}', $exec2, $loc_matches);
if (isset($loc_matches[1]) && isset($loc_matches[2])) {
$lat = $loc_matches[1];
$long = $loc_matches[2];
}
}
$ret['place_latitude'] = $lat;
$ret['place_longitude'] = $long;
$ret['place_map'] = isset($loc_matches[1]) ? '' : '';
$ret['event_description'] = $txtContent;
// start, end time content="2018-06-16T07:00:00-07:00 to 2018-08-16T11:00:00-07:00">
$start_time = '';
$end_time = '';
$ret['start_time_timestamp'] = '';
$ret['end_time_timestamp'] = '';
$ret['start_time'] = '';
$ret['end_time'] = '';
// "utc_start_timestamp":1604865600,"utc_end_timestamp":null}
//,"start_timestamp":1622181600,"end_timestamp":1622577600},
preg_match('!"start_timestamp":(.*?),"end_timestamp":(\d*)}!', $exec2, $date_matches);
if (isset($date_matches[1]) && wp_automatic_trim($date_matches[1]) != '') {
$start_timestamp_no_timezoned = $date_matches[1]; //1604865600
$start_date_no_timezoned = gmdate('Y-m-d H:i:s', $start_timestamp_no_timezoned); // 2020-11-08 20:00:00
$start_date_timezoned = $start_date_no_timezoned; //ini 2020-11-08 20:00:00
/*
//getting timezone "tz_display_name":"EST"
preg_match ( '!"tz_display_name":"(.*?)"!', $exec2, $tz_matches );
if(isset($tz_matches[1]) && wp_automatic_trim($tz_matches[1]) != '' ){
//found timezone EST
$found_timezone = wp_automatic_str_replace('UTC' , 'GMT', $tz_matches[1]);
$start_date_timezoned = $start_date_timezoned . ' ' . $found_timezone ; //2020-11-08 20:00:00 EST
}
*/
//getting correct UTC/GMT timestamp
$start_date_utc = strtotime($start_date_timezoned); //1604883600
$ret['start_time'] = get_date_from_gmt(gmdate('Y-m-d H:i:s', $start_date_utc)); // blog timezoned date
$ret['start_time_timestamp'] = strtotime($ret['start_time']);
//end date if exists
if (isset($date_matches[2]) && is_numeric($date_matches[2]) && $date_matches[2] != 0) {
$end_timestamp_no_timezoned = $date_matches[2];
$end_date_no_timezoned = gmdate('Y-m-d H:i:s', $end_timestamp_no_timezoned); // 2020-11-08 20:00:00
$end_date_timezoned = $end_date_no_timezoned; //ini 2020-11-08 20:00:00
/*
if(isset($tz_matches[1]) && wp_automatic_trim($tz_matches[1]) != '' ){
//found timezone EST
$end_date_timezoned = $end_date_timezoned . ' ' .$found_timezone ; //2020-11-08 20:00:00 EST
}
*/
$end_date_utc = strtotime($end_date_timezoned); //1604883600
$ret['end_time'] = get_date_from_gmt(gmdate('Y-m-d H:i:s', $end_date_utc));
$ret['end_time_timestamp'] = strtotime($ret['end_time']);
}
}
// event_place":{"__typename":"Page","name":"M&K Stationery","
$place_name = '';
preg_match('!event_place":{"__typename":".*?","name":"(.*?)","!', $exec2, $place_matches);
$place_name = '';
if (isset($place_matches[1])) {
$place_name = wp_automatic_fix_json_part($place_matches[1]);
}
$ret['place_name'] = $place_name;
// "address":{"street":"(.*?)"},"city":{"contextual_name":"(.*?)",
$place_address = '';
preg_match('!"address":{"street":"(.*?)"},"city":{"contextual_name":"(.*?)",!', $exec2, $address_matches);
if (isset($address_matches[1]) && wp_automatic_trim($address_matches[1]) != '') {
$place_address = wp_automatic_fix_json_part($address_matches[1]) . ' ' . wp_automatic_fix_json_part($address_matches[2]);
} else {
//"event_place":{"__typename":"FreeformPlace","contextual_name":"5th St, Sandton, 2196, South Africa",
}
$ret['place_address'] = $place_address;
//place street "address":{"street":"Tanta-Elhelw st. behind Kassem Amein"}
preg_match('{"street":"(.*?)"}', $exec2, $street_matches);
$ret['place_street'] = (isset($street_matches[1]) && wp_automatic_trim($street_matches[1]) != '') ? wp_automatic_fix_json_part($street_matches[1]) : '';
//"city":{"contextual_name":"Tanta"
preg_match('!"city":{"contextual_name":"(.*?)"!', $exec2, $city_matches);
$ret['place_city'] = (isset($city_matches[1]) && wp_automatic_trim($city_matches[1]) != '') ? wp_automatic_fix_json_part($city_matches[1]) : '';
//"event_connected_users_going":{"count":1}
preg_match('!"event_connected_users_going":{"count":(.*?)}!', $exec2, $going_matches);
$ret['going_count'] = (isset($going_matches[1]) && wp_automatic_trim($going_matches[1]) != '') ? $going_matches[1] : '';
//"event_connected_users_interested":{"count":2}
preg_match('!"event_connected_users_interested":{"count":(.*?)}!', $exec2, $going_matches);
$ret['interested_count'] = (isset($going_matches[1]) && wp_automatic_trim($going_matches[1]) != '') ? $going_matches[1] : '';
//no more available tags
$ret['place_email'] = '';
$ret['place_phone'] = '';
$ret['place_zip'] = '';
$ret['place_country'] = '';
} else {
// "i18n_reaction_count":"1.5K",
$item_likes = 0;
preg_match('{"i18n_reaction_count":"(.*?)"}s', $exec2, $likes_count_matches);
if (isset($likes_count_matches[1])) {
$item_likes = wp_automatic_str_replace(',', '', $likes_count_matches[1]);
}
$ret['original_title'] = $title;
$ret['original_link'] = $url;
$ret['matched_content'] = $content;
$ret['original_date'] = $wpdate;
// get from info
//"actors":[{"__typename":"User","name":"Mohamed Moawad",
//"actors":[{"__typename":"Page","name":"CNN"
preg_match('!"actors":\[{"__typename":"\w*?","name":"(.*?)",!', $exec2, $from_matches);
$from_name = '';
if (isset($from_matches[1]) && wp_automatic_trim($from_matches[1]) != '') {
$from_name = wp_automatic_fix_json_part($from_matches[1]);
} else {
////og:title" content="CNN"
preg_match('!og:title" content="(.*?)"!', $exec2, $from_matches);
if (!empty($from_matches[1])) {
$from_name = $from_matches[1];
}
}
$ret['from_name'] = $from_name;
// from ID actor_id%22%3A100026923221457%
$sharer_id = $cg_fb_page_id;
if (stristr($exec2, 'sharer_id')) {
preg_match('{sharer_id=(.*?)&}s', $exec2, $from_matches);
if (isset($from_matches[1]) && wp_automatic_trim($from_matches[1]) != '') {
$sharer_id = $from_matches[1];
}
// from_name ownerName:"Gamal M. Elkomy"
preg_match('{ownerName:"(.*?)"}s', $exec2, $from_name_matches);
if (isset($from_name_matches[1]) && wp_automatic_trim($from_name_matches[1]) != '') {
$ret['from_name'] = $from_name_matches[1];
}
} else {
// closed group content_owner_id_new":"100002936112728"
preg_match('{content_owner_id_new.*?(\d+)}s', $item, $from_matches2);
if (isset($from_matches2[1]) && wp_automatic_trim($from_matches2[1]) != '') {
$sharer_id = $from_matches2[1];
}
}
$ret['from_id'] = $sharer_id;
$ret['from_url'] = 'https://facebook.com/' . $sharer_id;
$ret['from_thumbnail'] = 'https://graph.facebook.com/' . $sharer_id . '/picture?type=large';
$ret['post_id'] = $item_id;
$ret['post_id_single'] = $single_id;
$ret['image_src'] = $imgsrc;
$ret['likes_count'] = $item_likes;
// original url of the shared post
if ($type == 'link') {
$ret['external_url'] = $link;
} else {
$ret['external_url'] = '';
}
// shares
if (!is_numeric($shares_count)) {
$shares_count = 0;
}
$ret['shares_count'] = $shares_count;
// no title
if (wp_automatic_trim($title) == '') {
$ret['original_title'] = '(notitle)';
}
// embed code
$ret['post_embed'] = '
';
// hashtags >#support
// echo $ret['matched_content'];
if (stristr($ret['matched_content'], '#')) {
preg_match_all('{>#(.*?)}', $ret['matched_content'], $hash_matchs);
$hash_matchs = $hash_matchs[1];
$hash_tags = implode(',', $hash_matchs);
$ret['item_tags'] = strip_tags($hash_tags);
} else {
$ret['item_tags'] = '';
}
}
if ($cg_fb_source == 'group' && $type != 'event') {
$ret['source_link'] = 'https://www.facebook.com/groups/' . $cg_fb_page_id . '/permalink/' . $single_id;
} else {
$ret['source_link'] = $ret['original_link'];
}
// comments {"comments":[{"body..... }],"pinnedcomments
//before_count":0,"count":44,"edges":[{"node":
if (in_array('OPT_FB_COMMENT', $camp_opt)) {
$correct_comment_part = ''; // ini
if (stristr($exec2_raw, '"edges":[{"node":')) {
$all_the_comments = array();
echo ' Comments found to extract using edges context';
// edges:[{node .........,cursor:"AQHRJpdJxCiEwoRdtdydeisnvpjtTxJ9wk1_OAMIFGwB5ylEL1Wl2fidayVd8mErMcU2Sul_ftHtFzFoCRI_3cFGSg"}]
// edges:[{node .........,cursor":null}]
preg_match_all('{"edges":\[\{"node":\{"id"[^<]*,"cursor":.*?\}\]}s', $exec2_raw, $comment_part_matches);
$comment_part_matches = $comment_part_matches[0];
if (isset($comment_part_matches[0]) && wp_automatic_trim($comment_part_matches[0]) != '') {
$correct_comment_part = '{' . $comment_part_matches[0] . '}';
// $correct_comment_part = preg_replace ( '/(\s*?{\s*?|\s*?,\s*?)([\'"])?([a-zA-Z0-9_]+)([\'"])?:/', '$1"$3":', $correct_comment_part );
$comments_json = (json_decode($correct_comment_part));
if (isset($comments_json->edges)) {
$all_comments = $comments_json->edges;
foreach ($all_comments as $single_comment) {
$a_comment = array();
$single_comment = $single_comment->node;
if (stristr($single_comment->legacy_token, $single_id)) {
$commment_txt = isset($single_comment->url) ? $single_comment->url : '';
$a_comment['text'] = @$single_comment->body->text;
// image content
if (in_array('OPT_FB_COMMENT_IMG_CNT', $camp_opt)) {
if (isset($single_comment->attachments[0]->media->image->uri)) {
$imgURI = $single_comment->attachments[0]->media->image->uri;
if (wp_automatic_trim($imgURI) != '') {
$a_comment['text'] .= ' ';
}
}
}
$a_comment['time'] = $single_comment->created_time;
$a_comment['author_id'] = $single_comment->author->id;
$a_comment['author_name'] = $single_comment->author->name;
if (wp_automatic_trim($a_comment['text']) != '') {
$all_the_comments[] = $a_comment;
}
}
}
if (count($all_the_comments) > 0) {
$ret['comments'] = array_reverse($all_the_comments);
}
}
} else {
echo ' Can not extract the Json part for the comments';
}
}
} // comments option active
// fix hashtags
if (stristr($ret['matched_content'], 'hash')) {
// # emergencias
$ret['matched_content'] = preg_replace('{>#}s', '>#', $ret['matched_content']);
}
$ret['original_date_timestamp'] = strtotime($ret['original_date']);
return $ret;
} // endforeach
echo ' End of available items reached....';
if (in_array('OPT_FB_CACHE', $camp_opt)) {
echo ' Deleting cache as no more valid items found...';
delete_post_meta($camp->camp_id, 'wp_automatic_cache');
// Setting next page url
$nextPageUrl = '';
if (!isset($list_exec_raw)) {
$list_exec_raw = '';
}
if (stristr($list_exec_raw, '"see_more_cards_id\",\"href\"') || stristr($list_exec_raw, 'm_more_item\",\"href') || stristr($list_exec_raw, 'profile\\\\\\/timeline\\\\\\/stream') || (stristr($exec, 'serialized_cursor') && $cg_fb_from == 'events') || ($cg_fb_source == 'group' && stristr($list_exec_raw, "/groups/$cg_fb_page_id?bac")) || ($cg_fb_source == 'profile' && stristr($list_exec_raw, "profile/timeline/stream/?cursor"))) {
if ($cg_fb_source == 'profile' && stristr($list_exec_raw, "profile/timeline/stream/?cursor")) {
echo ' Pagination case#-1 profile';
//See more stories
preg_match('!See Mor
echo ' Pagination case#0 groups';
preg_match('{}s', $exec, $next_page_matches);
} elseif ((stristr($exec, 'serialized_cursor') && $cg_fb_from == 'events')) {
// See More Events
echo ' Pagination case#1 events';
preg_match('{}s', $exec, $next_page_matches);
} elseif (stristr($list_exec_raw, 'm_more_item\",\"href')) {
// "m_more_item\",\"href\":\"\\\/groups\
echo ' Pagination case#2 group';
preg_match('{"m_more_item.",."href.":."(.*?)"}s', $list_exec_raw, $next_page_matches);
$possible_pagination_url = wp_automatic_fix_json_part(stripslashes($next_page_matches[1]));
if (wp_automatic_trim($possible_pagination_url) != '') {
$next_page_matches[1] = $possible_pagination_url;
}
} elseif (stristr($list_exec_raw, 'see_more_cards_id\",\"href\"')) {
//_more_cards_id","href":"\/page_c
preg_match('!"(.{4}page_content_list_view.*?)"!s', $list_exec_raw, $next_page_matches);
$possible_pagination_url = wp_automatic_fix_json_part(stripslashes($next_page_matches[1]));
if (wp_automatic_trim($possible_pagination_url) != '') {
$next_page_matches[1] = $possible_pagination_url;
}
echo ' Pagination case#3 page';
} else {
echo ' Pagination case#4 profile';
//"href\":\"\\\/profile\\\/timeline\\\/stream\\\/?cursor=AQHRvsJLrnRauzCuDLYMaVWnQGpS22H16CqnVUO2rpEfWQXQdlXHgVAlEbRrzaTqGt4znEwetPnd5AKZEIxrGxaJB0zWtkwEFuEe6Jl4x0x_hTw5d_4THMtxEwdAKq6Sncy3&profile_id=837764889&replace_id=u_0_0\"
preg_match('{"href.":."(.{4}profile.{4}timeline.{4}stream.{4}\?cursor\=.*?)"}s', $list_exec_raw, $next_page_matches);
$possible_pagination_url = wp_automatic_fix_json_part(stripslashes($next_page_matches[1]));
if (wp_automatic_trim($possible_pagination_url) != '') {
$next_page_matches[1] = $possible_pagination_url;
}
}
if (isset($foundOldPost) && $foundOldPost) {
echo ' Found old posts on current list of posts, lets set the pointer to first page again';
delete_post_meta($camp->camp_id, 'nextPageUrl');
delete_post_meta($camp->camp_id, 'wp_automatic_fb_checked_years');
} elseif (isset($next_page_matches[1]) && wp_automatic_trim($next_page_matches[1]) != '') {
// show more link exists
if ($cg_fb_from == 'events' || $cg_fb_source == 'group' || $cg_fb_source == 'profile') {
$nextPageUrl = "https://mbasic.facebook.com" . $next_page_matches[1];
} else {
$nextPageUrl = "https://m.facebook.com" . $next_page_matches[1];
}
echo ' Next page:' . $nextPageUrl;
update_post_meta($camp->camp_id, 'nextPageUrl', $nextPageUrl);
} else {
// no next
echo ' No next page available';
delete_post_meta($camp->camp_id, 'nextPageUrl');
delete_post_meta($camp->camp_id, 'wp_automatic_fb_checked_years');
}
} else {
echo ' No next page available';
delete_post_meta($camp->camp_id, 'nextPageUrl');
delete_post_meta($camp->camp_id, 'wp_automatic_fb_checked_years');
}
}
}
} // trim pageid
}
public function wp_automatic_fb_email_of_failure()
{
$wp_automatic_fb_email = get_option('wp_automatic_fb_email', '');
}
}