Пример #1
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;
 }
 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;
 }