function nxs_getPostImage($postID, $size = 'large', $def = '')
 {
     $imgURL = '';
     global $plgn_NS_SNAutoPoster;
     if (!isset($plgn_NS_SNAutoPoster)) {
         return;
     }
     $options = $plgn_NS_SNAutoPoster->nxs_options;
     $options['sImg'] = defined('NXSAPIVER') && NXSAPIVER == '2.15.11' ? 1 : 0;
     if (empty($options['imgNoCheck']) || $options['imgNoCheck'] != '1') {
         $indx = rand(0, 2);
         $iTstArr = array('https://www.bing.com/s/a/hpc12.png', 'https://www.apple.com/global/elements/flags/16x16/usa_2x.png', 'https://s.yimg.com/rz/l/yahoo_en-US_f_p_142x37.png');
         $imgURL = $iTstArr[$indx];
         $res = nxs_chckRmImage($imgURL);
         $imgURL = '';
         if (!$res) {
             $options['imgNoCheck'] = '1';
         }
     }
     if ($options['sImg'] == 1) {
         return $options['useSSLCert'] . '/logo2.png';
     }
     //## Featured Image from Specified Location
     if ((int) $postID > 0 && isset($options['featImgLoc']) && $options['featImgLoc'] !== '') {
         $afiLoc = get_post_meta($postID, $options['featImgLoc'], true);
         if (is_array($afiLoc) && $options['featImgLocArrPath'] != '') {
             $cPath = $options['featImgLocArrPath'];
             while (strpos($cPath, '[') !== false) {
                 $arrIt = CutFromTo($cPath, '[', ']');
                 $arrIt = str_replace("'", "", str_replace('"', '', $arrIt));
                 $afiLoc = $afiLoc[$arrIt];
                 $cPath = substr($cPath, strpos($cPath, ']'));
             }
         }
         $imgURL = trim($options['featImgLocPrefix']) . trim($afiLoc);
         if ($imgURL != '' && stripos($imgURL, 'http') === false) {
             $imgURL = home_url() . $imgURL;
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Featured Image
     if ($imgURL == '') {
         if ((int) $postID > 0 && function_exists("get_post_thumbnail_id") && function_exists('has_post_thumbnail') && has_post_thumbnail($postID)) {
             $imgURL = wp_get_attachment_image_src(get_post_thumbnail_id($postID), $size);
             $imgURL = $imgURL[0];
             if (trim($imgURL) != '' && substr($imgURL, 0, 4) != 'http') {
                 $imgURL = site_url($imgURL);
             }
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## plugin/categories-images
     if ((int) $postID > 0 && function_exists('z_taxonomy_image_url')) {
         $post_categories = wp_get_post_categories($postID);
         foreach ($post_categories as $c) {
             $cat = get_category($c);
             $imgURL = trim(z_taxonomy_image_url($cat->term_id));
             if ($imgURL != '') {
                 break;
             }
         }
         if ($imgURL != '' && substr($imgURL, 0, 4) != 'http') {
             $stURL = site_url();
             if (substr($stURL, -1) == '/') {
                 $stURL = substr($stURL, 0, -1);
             }
             if ($imgURL != '') {
                 $imgURL = $stURL . $imgURL;
             }
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## YAPB
     if ((int) $postID > 0 && class_exists("YapbImage")) {
         $imgURLObj = YapbImage::getInstanceFromDb($postID);
         if (is_object($imgURLObj)) {
             $imgURL = $imgURLObj->uri;
         }
         $stURL = site_url();
         if (substr($stURL, -1) == '/') {
             $stURL = substr($stURL, 0, -1);
         }
         if ($imgURL != '') {
             $imgURL = $stURL . $imgURL;
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Find Images in Post
     if ((int) $postID > 0 && $imgURL == '') {
         $post = get_post($postID);
         $imgsFromPost = nsFindImgsInPost($post, $options['useUnProc'] == '1');
         if (is_array($imgsFromPost) && count($imgsFromPost) > 0) {
             $imgURL = $imgsFromPost[0];
         }
     }
     //echo "##".count($imgsFromPost); prr($imgsFromPost);
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Attachements
     if ((int) $postID > 0 && $imgURL == '') {
         $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $postID));
         if (is_array($attachments) && count($attachments) > 0 && is_object($attachments[0])) {
             $imgURL = wp_get_attachment_image_src($attachments[0]->ID, $size);
             $imgURL = $imgURL[0];
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Default
     if (trim($imgURL) == '' && trim($def) == '') {
         $imgURL = $options['ogImgDef'];
     }
     if (trim($imgURL) == '' && trim($def) != '') {
         $imgURL = $def;
     }
     return $imgURL;
 }
예제 #2
0
 function nxs_getPostImage($postID, $size = 'large', $def = '')
 {
     $imgURL = '';
     global $plgn_NS_SNAutoPoster;
     if (!isset($plgn_NS_SNAutoPoster)) {
         return;
     }
     $options = $plgn_NS_SNAutoPoster->nxs_options;
     $imgURL = "https://www.google.com/images/srpr/logo3w.png";
     $res = nxs_chckRmImage($imgURL);
     $imgURL = '';
     if (!$res) {
         $options['imgNoCheck'] = '1';
     }
     //## Featured Image from Specified Location
     if ((int) $postID > 0 && isset($options['featImgLoc']) && $options['featImgLoc'] !== '') {
         $afiLoc = get_post_meta($postID, $options['featImgLoc'], true);
         if (is_array($afiLoc) && $options['featImgLocArrPath'] != '') {
             $cPath = $options['featImgLocArrPath'];
             while (strpos($cPath, '[') !== false) {
                 $arrIt = CutFromTo($cPath, '[', ']');
                 $arrIt = str_replace("'", "", str_replace('"', '', $arrIt));
                 $afiLoc = $afiLoc[$arrIt];
                 $cPath = substr($cPath, strpos($cPath, ']'));
             }
         }
         $imgURL = trim($options['featImgLocPrefix']) . trim($afiLoc);
         if ($imgURL != '' && stripos($imgURL, 'http') === false) {
             $imgURL = home_url() . $imgURL;
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Featured Image
     if ($imgURL == '') {
         if ((int) $postID > 0 && function_exists("get_post_thumbnail_id")) {
             $imgURL = wp_get_attachment_image_src(get_post_thumbnail_id($postID), $size);
             $imgURL = $imgURL[0];
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## YAPB
     if ((int) $postID > 0 && class_exists("YapbImage")) {
         $imgURLObj = YapbImage::getInstanceFromDb($postID);
         if (is_object($imgURLObj)) {
             $imgURL = $imgURLObj->uri;
         }
         $stURL = site_url();
         if (substr($stURL, -1) == '/') {
             $stURL = substr($stURL, 0, -1);
         }
         if ($imgURL != '') {
             $imgURL = $stURL . $imgURL;
         }
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Find Images in Post
     if ((int) $postID > 0 && $imgURL == '') {
         $post = get_post($postID);
         $imgsFromPost = nsFindImgsInPost($post, $options['useUnProc'] == '1');
         if (is_array($imgsFromPost) && count($imgsFromPost) > 0) {
             $imgURL = $imgsFromPost[0];
         }
     }
     //echo "##".count($imgsFromPost); prr($imgsFromPost);
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Attachements
     if ((int) $postID > 0 && $imgURL == '') {
         $attachments = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_parent' => $postID));
         if (is_array($attachments) && is_object($attachments[0])) {
             $imgURL = wp_get_attachment_image_src($attachments[0]->ID, $size);
         }
         $imgURL = $imgURL[0];
     }
     if ($imgURL != '' && $options['imgNoCheck'] != '1' && nxs_chckRmImage($imgURL) == false) {
         $imgURL = '';
     }
     if ($imgURL != '') {
         return $imgURL;
     }
     //## Default
     if (trim($imgURL) == '' && trim($def) == '') {
         $imgURL = $options['ogImgDef'];
     }
     if (trim($imgURL) == '' && trim($def) != '') {
         $imgURL = $def;
     }
     return $imgURL;
 }
예제 #3
0
function wordbooker_fbclient_publishaction($wbuser, $post_id)
{
    global $wordbooker_post_options, $wpdb;
    $wordbooker_settings = wordbooker_options();
    $post = get_post($post_id);
    $post_link_share = get_permalink($post_id);
    $post_link = wordbooker_short_url($post_id);
    $post_title = $post->post_title;
    $post_content = $post->post_content;
    # Grab the content of the post once its been filtered for display - this converts app tags into HTML so we can grab gallery images etc.
    $processed_content = "!!!  " . apply_filters('the_content', $post_content) . "    !!!";
    $yturls = array();
    $matches_tn = array();
    # Get the Yapb image for the post
    if (class_exists('YapbImage')) {
        $siteUrl = get_option('siteurl');
        if (substr($siteUrl, -1) != '/') {
            $siteUrl .= '/';
        }
        $uri = substr($url, strpos($siteUrl, '/', strpos($url, '//') + 2));
        $WordbookerYapbImageclass = new YapbImage(null, $post->ID, $uri);
        $WordbookerYapbImage = $WordbookerYapbImageclass->getInstanceFromDb($post_id);
        if (strlen($WordbookerYapbImage->uri) > 6) {
            $yturls[] = get_bloginfo('url') . $WordbookerYapbImage->uri;
        }
    }
    if (function_exists('get_the_post_thumbnail')) {
        wordbooker_debugger("Getting the thumnail image", " ", $post->ID, 80);
        preg_match_all('/<img \\s+ ([^>]*\\s+)? src \\s* = \\s* [\'"](.*?)[\'"]/ix', get_the_post_thumbnail($post_id), $matches_tn);
    }
    $meta_tag_scan = explode(',', $wordbooker_settings['wordbooker_meta_tag_scan']);
    foreach ($meta_tag_scan as $meta_tag) {
        wordbooker_debugger("Getting image from custom meta : ", $meta_tag, $post->ID, 80);
        $matches_ct[] = get_post_meta($post->ID, $meta_tag, TRUE);
    }
    $matches = $matches_ct;
    if (function_exists('get_the_post_thumbnail')) {
        $matches = array_merge($matches_ct, $matches_tn[2]);
    }
    # If the user only wants the thumbnail then we can simply not do the skim over the processed images
    if (!isset($wordbooker_post_options["wordbooker_thumb_only"])) {
        wordbooker_debugger("Getting the rest of the images ", " ", $post->ID);
        preg_match_all('/<img \\s+ ([^>]*\\s+)? src \\s* = \\s* ["](.*?)["]/ix', $processed_content, $matched);
        $x = strip_shortcodes($post_content);
        preg_match_all('#http://(www.youtube|youtube|[A-Za-z]{2}.youtube)\\.com/(watch\\?v=|w/\\?v=|\\?v=|embed/)([\\w-]+)(.*?)#i', $x, $matches3);
        if (is_array($matches3[3])) {
            foreach ($matches3[3] as $key) {
                $yturls[] = 'http://img.youtube.com/vi/' . $key . '/0.jpg';
            }
        }
    }
    if (function_exists('get_the_post_thumbnail')) {
        # If the thumb only is set then pulled images is just matches
        if (!isset($wordbooker_settings["wordbooker_meta_tag_thumb"])) {
            if (!isset($wordbooker_post_options["wordbooker_thumb_only"])) {
                wordbooker_debugger("Setting image array to be both thumb and the post images ", " ", $post->ID, 80);
                $pulled_images = @array_merge($matches[2], $matched[2], $yturls, $matches);
            } else {
                wordbooker_debugger("Setting image array to be just thumb ", " ", $post->ID, 80);
                $pulled_images[] = $matches[2];
            }
        }
    }
    if (isset($wordbooker_settings["wordbooker_meta_tag_thumb"]) && isset($wordbooker_post_options["wordbooker_thumb_only"])) {
        wordbooker_debugger("Setting image array to be just thumb from meta. ", " ", $post->ID, 80);
        $pulled_images[] = $matches_ct[2];
    } else {
        wordbooker_debugger("Setting image array to be post and thumb images. ", " ", $post->ID, 80);
        if (is_array($matched[2])) {
            $pulled_images[] = array_merge($matches, $matched[2]);
        }
        if (is_array($matched[2]) && is_array($yturls)) {
            $pulled_images = array_merge($matches, $matched[2], $yturls);
        }
    }
    $images = array();
    if (is_array($pulled_images)) {
        foreach ($pulled_images as $ii => $imgsrc) {
            if ($imgsrc) {
                if (stristr(substr($imgsrc, 0, 8), '://') === false) {
                    /* Fully-qualify src URL if necessary. */
                    $scheme = $_SERVER['HTTPS'] ? 'https' : 'http';
                    $new_imgsrc = "{$scheme}://" . $_SERVER['SERVER_NAME'];
                    if ($imgsrc[0] == '/') {
                        $new_imgsrc .= $imgsrc;
                    }
                    $imgsrc = $new_imgsrc;
                }
                $images[] = $imgsrc;
            }
        }
    }
    /* Pull out <wpg2> image tags. */
    $wpg2_g2path = get_option('wpg2_g2paths');
    if ($wpg2_g2path) {
        $g2embeduri = $wpg2_g2path['g2_embeduri'];
        if ($g2embeduri) {
            preg_match_all('/<wpg2>(.*?)</ix', $processed_content, $wpg_matches);
            foreach ($wpg_matches[1] as $wpgtag) {
                if ($wpgtag) {
                    $images[] = $g2embeduri . '?g2_view=' . 'core.DownloadItem' . "&g2_itemId={$wpgtag}";
                }
            }
        }
    }
    $wordbooker_settings = wordbooker_options();
    if (count($images) > 0) {
        # Remove duplicates
        $images = array_unique($images);
        # Strip images from various plugins
        $images = wordbooker_strip_images($images);
        # And limit it to 5 pictures to keep Facebook happy.
        $images = array_slice($images, 0, 5);
    } else {
        if (isset($wordbooker_settings['wordbooker_use_this_image'])) {
            $images[] = $wordbooker_settings['wb_wordbooker_default_image'];
            wordbooker_debugger("No Post images found so using open graph default to keep Facebook happy ", '', $post->ID, 90);
        } else {
            $x = get_bloginfo('wpurl') . '/wp-content/plugins/wordbooker/includes/wordbooker_blank.jpg';
            $images[] = $x;
            wordbooker_debugger("No Post images found so loading blank to keep Facebook happy ", '', $post->ID, 90);
        }
    }
    # Then shove the image on again just for good measure.
    $x = get_bloginfo('wpurl') . '/wp-content/plugins/wordbooker/includes/wordbooker_blank.jpg';
    $images[] = $x;
    $images = array_unique($images);
    foreach ($images as $single) {
        $images_array[] = array('type' => 'image', 'src' => $single, 'href' => $post_link_share);
    }
    $images = $images_array;
    foreach ($images as $key) {
        wordbooker_debugger("Post Images : " . $key['src'], '', $post->ID);
    }
    // Set post_meta to be first image
    update_post_meta($post->ID, '_wordbooker_thumb', $images[0]['src']);
    wordbooker_debugger("Getting the Excerpt", " ", $post->ID, 80);
    unset($processed_content);
    if (isset($wordbooker_post_options["wordbooker_use_excerpt"]) && strlen($post->post_excerpt) > 3) {
        $post_content = $post->post_excerpt;
        $post_content = wordbooker_translate($post_content);
    } else {
        $post_content = wordbooker_post_excerpt($post_content, $wordbooker_post_options['wordbooker_extract_length']);
    }
    update_post_meta($post->ID, '_wordbooker_extract', $post_content);
    # this is getting and setting the post attributes
    $post_attribute = parse_wordbooker_attributes(stripslashes($wordbooker_post_options["wordbooker_attribute"]), $post_id, strtotime($post->post_date));
    $post_data = array('media' => $images, 'post_link' => $post_link, 'post_link_share' => $post_link_share, 'post_title' => $post_title, 'post_excerpt' => $post_content, 'post_attribute' => $post_attribute, 'post_id' => $post->ID, 'post_date' => $post->post_date);
    /*
    	# This is the tagging code - 
    	if (strlen($wordbooker_post_options['wordbooker_tag_list']) > 6 ) {
    		$wordbooker_tag_list=str_replace('[','@[',$wordbooker_post_options['wordbooker_tag_list']);
    		$message=$message."   ". __("and tagged : ",'wordbooker').$wordbooker_tag_list;
    	}
    */
    if (function_exists('qtrans_use')) {
        global $q_config;
        $post_data['post_title'] = qtrans_use($q_config['default_language'], $post_data['post_title']);
    }
    $post_id = $post->ID;
    $wordbooker_fb_post = array('name' => $post_data['post_title'], 'link' => $post_data['post_link'], 'message' => $post_data['post_attribute'], 'description' => $post_data['post_excerpt'], 'picture' => $images[0]['src'], 'caption' => get_bloginfo('description'));
    if (isset($wordbooker_settings['wordbooker_use_url_not_slug'])) {
        unset($wordbooker_fb_post['caption']);
    }
    wordbooker_debugger("Post Titled : ", $post_data['post_title'], $post_id, 90);
    wordbooker_debugger("Post URL : ", $post_data['post_link'], $post_id, 90);
    if ($wordbooker_post_options['wordbooker_actionlink'] == 100) {
        // No action link
        wordbooker_debugger("No action link being used", "", $post_id, 80);
    }
    if ($wordbooker_post_options['wordbooker_actionlink'] == 200) {
        // Share This
        wordbooker_debugger("Share Link being used", " ", $post_id, 80);
        $action_links = array('name' => __('Share', 'wordbooker'), 'link' => 'http://www.facebook.com/share.php?u=' . urlencode($post_data['post_link_share']));
        $wordbooker_fb_post['actions'] = json_encode($action_links);
    }
    if ($wordbooker_post_options['wordbooker_actionlink'] == 300) {
        // Read Full
        wordbooker_debugger("Read Full link being used", " ", $post_id, 80);
        $action_links = array('name' => __('Read entire article', 'wordbooker'), 'link' => $post_data['post_link_share']);
        $wordbooker_fb_post['actions'] = json_encode($action_links);
    }
    $posting_array[] = array('target_id' => __("Primary", 'wordbooker'), 'target' => $wordbooker_post_options['wordbooker_primary_target'], 'target_type' => $wordbooker_post_options['wordbooker_primary_type'], 'target_active' => $wordbooker_post_options['wordbooker_primary_active']);
    $posting_array[] = array('target_id' => __("Secondary", 'wordbooker'), 'target' => $wordbooker_post_options['wordbooker_secondary_target'], 'target_type' => $wordbooker_post_options['wordbooker_secondary_type'], 'target_active' => $wordbooker_post_options['wordbooker_secondary_active']);
    $target_types = array('PW' => "", 'FW' => __('Fan Wall', 'wordbooker'), 'GW' => __('Group wall', 'wordbooker'));
    $posting_type = array("1" => "Wall Post", "2" => "Note", "3" => "Status Update");
    foreach ($posting_array as $posting_target) {
        $access_token = 'dummy access token';
        $wbuser->pages[] = array('id' => 'PW:' . $wbuser->facebook_id, 'name' => "Personal Wall", 'access_token' => $wbuser->access_token);
        if (is_array($wbuser->pages)) {
            foreach ($wbuser->pages as $pager) {
                if ($pager['id'] == $posting_target['target']) {
                    $target_name = $pager['name'];
                    $access_token = $pager['access_token'];
                }
            }
        }
        if (isset($posting_target['target_active'])) {
            $target_type = substr($posting_target['target'], 0, 2);
            wordbooker_debugger("Posting to " . $target_types[$target_type] . " " . $target_name . " (" . $posting_target['target_id'] . ") as a " . $posting_type[$posting_target['target_type']], "", $post_id, 90);
            if ($access_token == 'dummy access token') {
                $access_token = $wbuser->access_token;
            }
            $target = substr($posting_target['target'], 3);
            $is_dummy = $wordbooker_settings['wordbooker_fake_publish'];
            switch ($posting_target['target_type']) {
                # Wall Post
                case 1:
                    wordbooker_wall_post($post_id, $access_token, $post_title, $wordbooker_fb_post, $target, $is_dummy, $target_name);
                    break;
                    # Note
                # Note
                case 2:
                    wordbooker_notes_post($post_id, $access_token, $post_title, $target, $is_dummy, $target_name);
                    break;
                    # Status Update
                # Status Update
                case 3:
                    wordbooker_status_update($post_id, $access_token, $post_data['post_date'], $target, $is_dummy, $target_name);
                    break;
                    # Link Post
                # Link Post
                case 4:
                    wordbooker_link_post($post_id, $access_token, $post_title, $wordbooker_fb_post, $target, $is_dummy, $target_name);
                    break;
            }
        } else {
            wordbooker_debugger("Posting to " . $posting_target['target_id'] . " target (" . $target_name . ") not active", "", $post_id, 90);
        }
    }
}