nxs_ogtgCallback

The NextScripts: Social Networks Auto-Poster nxs ogtgCallback function.

Description

nxs_ogtgCallback( $content ); 

Parameters (1)

0. $content
The content.

Usage

  1. if ( !function_exists( 'nxs_ogtgCallback' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'nextscripts-social-networks-auto-poster/NextScripts_SNAP.php'; 
  3.  
  4. // The content. 
  5. $content = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = nxs_ogtgCallback($content); 
  9.  

Defined (1)

The function is defined in the following location(s).

/NextScripts_SNAP.php  
  1. function nxs_ogtgCallback($content) { global $post, $plgn_NS_SNAutoPoster;  
  2. if (stripos($content, 'og:title')!==false) $ogOut = "\r\n"; else { 
  3. if (!isset($plgn_NS_SNAutoPoster)) $options = get_option('NS_SNAutoPoster'); else $options = $plgn_NS_SNAutoPoster->nxs_options; $ogimgs = array();  
  4. if (!empty($post) && !is_object($post) && int($post)>0) $post = get_post($post); if (empty($options['advFindOGImg'])) $options['advFindOGImg'] = 0;  
  5. $title = preg_match( '/<title>(.*)<\/title>/', $content, $title_matches );  
  6. if ($title !== false && count( $title_matches) == 2 ) $ogT ='<meta property="og:title" content="' . $title_matches[1] . '" />'."\r\n"; else { 
  7. if (is_home() || is_front_page() ) $ogT = get_bloginfo( 'name' ); else $ogT = get_the_title(); 
  8. $ogT = '<meta property="og:title" content="' . esc_attr( apply_filters( 'nxsog_title', $ogT ) ) . '" />'."\r\n";  
  9. }  
  10. $prcRes = preg_match( '/<meta name="description" content="(.*)"/', $content, $description_matches );  
  11. if ( $prcRes !== false && count( $description_matches ) == 2 ) $ogD = '<meta property="og:description" content="' . $description_matches[1] . '" />'."\r\n"; { 
  12. if (!empty($post) && is_object($post) && is_singular()) { 
  13. if(has_excerpt($post->ID))$ogD=strip_tags(nxs_snapCleanHTML($post->post_excerpt));else $ogD= str_replace(" ", ' ', str_replace("\r\n", ' ', trim(substr(strip_tags(nxs_snapCleanHTML(strip_shortcodes($post->post_content))), 0, 200))));  
  14. } else $ogD = get_bloginfo('description'); $ogD = preg_replace('/\r\n|\r|\n/m', '', $ogD);  
  15. $ogD = '<meta property="og:description" content="'.esc_attr( apply_filters( 'nxsog_desc', $ogD ) ).'" />'."\r\n";  
  16. }  
  17. $ogSN = '<meta property="og:site_name" content="'.get_bloginfo('name').'" />'."\r\n"; 
  18. $ogLoc = strtolower(esc_attr(get_locale())); if (strlen($ogLoc)==2) $ogLoc .= "_".strtoupper($ogLoc); 
  19. $ogLoc = '<meta property="og:locale" content="'.$ogLoc.'" />'."\r\n"; $iss = is_home();  
  20. $ogType = is_singular()?'article':'website'; if(empty($vidsFromPost)) $ogType = '<meta property="og:type" content="'.esc_attr(apply_filters('nxsog_type', $ogType)).'" />'."\r\n";  
  21.  
  22. if (is_home() || is_front_page()) $ogUrl = get_bloginfo( 'url' ); else $ogUrl = 'http' . (is_ssl() ? 's' : '') . "://".$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
  23. $ogUrl = '<meta property="og:url" content="'.esc_url( apply_filters( 'nxsog_url', $ogUrl ) ) . '" />' . "\r\n"; 
  24.  
  25. if (!is_home()) { /** 
  26. $vidsFromPost = nsFindVidsInPost($post); if ($vidsFromPost !== false && is_singular()) { echo '<meta property="og:video" content="http://www.youtube.com/v/'.$vidsFromPost[0].'" />'."\n";  
  27. echo '<meta property="og:video:type" content="application/x-shockwave-flash" />'."\n"; 
  28. echo '<meta property="og:video:width" content="480" />'."\n"; 
  29. echo '<meta property="og:video:height" content="360" />'."\n"; 
  30. echo '<meta property="og:image" content="http://i2.ytimg.com/vi/'.$vidsFromPost[0].'/mqdefault.jpg" />'."\n"; 
  31. echo '<meta property="og:type" content="video" />'."\n";  
  32. } */  
  33. if (is_object($post)) { $imgURL = nxs_getPostImage($post->ID, 'full', $options['ogImgDef']); if (!empty($imgURL)) $ogimgs[] = $imgURL; 
  34. $imgsFromPost = nsFindImgsInPost($post, (int)$options['advFindOGImg']==1);  
  35. if ($imgsFromPost !== false && is_singular() && is_array($ogimgs) && is_array($imgsFromPost)) $ogimgs = array_merge($ogimgs, $imgsFromPost);  
  36. }  
  37. //## Add default image to the endof the array 
  38. if ( count($ogimgs)<1 && isset($options['ogImgDef']) && $options['ogImgDef']!='') $ogimgs[] = $options['ogImgDef'];  
  39. //## Output og:image tags 
  40. $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";  
  41. $ogOut = "\r\n".$ogSN.$ogT.$ogD.$ogType.$ogUrl.$ogLoc.$ogImgsOut; 
  42. } $content = str_ireplace('<!-- ## NXSOGTAGS ## -->', $ogOut, $content);  
  43. return $content;