Exemple #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_ogtgCallback($content)
 {
     global $post, $plgn_NS_SNAutoPoster;
     if (stripos($content, 'og:title') !== false) {
         $ogOut = "\r\n";
     } else {
         if (!isset($plgn_NS_SNAutoPoster)) {
             $options = get_option('NS_SNAutoPoster');
         } else {
             $options = $plgn_NS_SNAutoPoster->nxs_options;
         }
         $ogimgs = array();
         if (!empty($post) && !is_object($post) && int($post) > 0) {
             $post = get_post($post);
         }
         if (empty($options['advFindOGImg'])) {
             $options['advFindOGImg'] = 0;
         }
         $title = preg_match('/<title>(.*)<\\/title>/', $content, $title_matches);
         if ($title !== false && count($title_matches) == 2) {
             $ogT = '<meta property="og:title" content="' . $title_matches[1] . '" />' . "\r\n";
         } else {
             if (is_home() || is_front_page()) {
                 $ogT = get_bloginfo('name');
             } else {
                 $ogT = get_the_title();
             }
             $ogT = '<meta property="og:title" content="' . esc_attr(apply_filters('nxsog_title', $ogT)) . '" />' . "\r\n";
         }
         $prcRes = preg_match('/<meta name="description" content="(.*)"/', $content, $description_matches);
         if ($prcRes !== false && count($description_matches) == 2) {
             $ogD = '<meta property="og:description" content="' . $description_matches[1] . '" />' . "\r\n";
         }
         if (!empty($post) && is_object($post) && is_singular()) {
             if (has_excerpt($post->ID)) {
                 $ogD = strip_tags(nxs_snapCleanHTML(get_the_excerpt($post->ID)));
             } else {
                 $ogD = str_replace("  ", ' ', str_replace("\r\n", ' ', trim(substr(strip_tags(nxs_snapCleanHTML(strip_shortcodes($post->post_content))), 0, 200))));
             }
         } else {
             $ogD = get_bloginfo('description');
         }
         $ogD = preg_replace('/\\r\\n|\\r|\\n/m', '', $ogD);
         $ogD = '<meta property="og:description" content="' . esc_attr(apply_filters('nxsog_desc', $ogD)) . '" />' . "\r\n";
         $ogSN = '<meta property="og:site_name" content="' . get_bloginfo('name') . '" />' . "\r\n";
         $ogLoc = strtolower(esc_attr(get_locale()));
         if (strlen($ogLoc) == 2) {
             $ogLoc .= "_" . strtoupper($ogLoc);
         }
         $ogLoc = '<meta property="og:locale" content="' . $ogLoc . '" />' . "\r\n";
         $iss = is_home();
         $ogType = is_singular() ? 'article' : 'website';
         if (empty($vidsFromPost)) {
             $ogType = '<meta property="og:type" content="' . esc_attr(apply_filters('nxsog_type', $ogType)) . '" />' . "\r\n";
         }
         if (is_home() || is_front_page()) {
             $ogUrl = get_bloginfo('url');
         } else {
             $ogUrl = 'http' . (is_ssl() ? 's' : '') . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
         }
         $ogUrl = '<meta property="og:url" content="' . esc_url(apply_filters('nxsog_url', $ogUrl)) . '" />' . "\r\n";
         if (!is_home()) {
             /*
                   $vidsFromPost = nsFindVidsInPost($post); if ($vidsFromPost !== false && is_singular()) {  echo '<meta property="og:video" content="http://www.youtube.com/v/'.$vidsFromPost[0].'" />'."\n";  
                   echo '<meta property="og:video:type" content="application/x-shockwave-flash" />'."\n";
                   echo '<meta property="og:video:width" content="480" />'."\n";
                   echo '<meta property="og:video:height" content="360" />'."\n";
                   echo '<meta property="og:image" content="http://i2.ytimg.com/vi/'.$vidsFromPost[0].'/mqdefault.jpg" />'."\n";
                   echo '<meta property="og:type" content="video" />'."\n"; 
                 } */
             if (is_object($post)) {
                 $imgURL = nxs_getPostImage($post->ID, 'full', $options['ogImgDef']);
                 if (!empty($imgURL)) {
                     $ogimgs[] = $imgURL;
                 }
                 $imgsFromPost = nsFindImgsInPost($post, (int) $options['advFindOGImg'] == 1);
                 if ($imgsFromPost !== false && is_singular() && is_array($ogimgs) && is_array($imgsFromPost)) {
                     $ogimgs = array_merge($ogimgs, $imgsFromPost);
                 }
             }
         }
         //## Add default image to the endof the array
         if (count($ogimgs) < 1 && isset($options['ogImgDef']) && $options['ogImgDef'] != '') {
             $ogimgs[] = $options['ogImgDef'];
         }
         //## Output og:image tags
         $ogImgsOut = '';
         if (!empty($ogimgs) && is_array($ogimgs)) {
             foreach ($ogimgs as $ogimage) {
                 $ogImgsOut .= '<meta property="og:image" content="' . esc_url(apply_filters('ns_ogimage', $ogimage)) . '" />' . "\r\n";
             }
         }
         $ogOut = "\r\n" . $ogSN . $ogT . $ogD . $ogType . $ogUrl . $ogLoc . $ogImgsOut;
     }
     $content = str_ireplace('<!-- ## NXSOGTAGS ## -->', $ogOut, $content);
     return $content;
 }
 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;
 }