| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/Social.tar |
Image.php 0000666 00000017435 15114625553 0006324 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Social;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
/**
* Handles the Open Graph and Twitter Image.
*
* @since 4.0.0
*/
class Image {
/**
* The type of image ("facebook" or "twitter").
*
* @since 4.1.6.2
*
* @var string
*/
protected $type;
/**
* The post object.
*
* @since 4.1.6.2
*
* @var \WP_Post
*/
private $post;
/**
* The default thumbnail size.
*
* @since 4.0.0
*
* @var string
*/
protected $thumbnailSize;
/**
* Whether or not to use the cached images.
*
* @since 4.1.6
*
* @var boolean
*/
public $useCache = true;
/**
* Returns the Facebook or Twitter image.
*
* @since 4.0.0
*
* @param string $type The type ("Facebook" or "Twitter").
* @param string $imageSource The image source.
* @param \WP_Post|null $post The post object.
* @return string|array The image data.
*/
public function getImage( $type, $imageSource, $post = null ) {
$this->type = $type;
$this->post = $post;
$this->thumbnailSize = apply_filters( 'aioseo_thumbnail_size', 'fullsize' );
$hash = md5( wp_json_encode( [ $type, $imageSource, $post ] ) );
static $images = [];
if ( isset( $images[ $hash ] ) ) {
return $images[ $hash ];
}
if ( 'auto' === $imageSource && aioseo()->helpers->getPostPageBuilderName( $post->ID ) ) {
$imageSource = 'default';
}
if ( is_a( $this->post, 'WP_Post' ) ) {
switch ( $imageSource ) {
case 'featured':
$image = $this->getFeaturedImage();
break;
case 'attach':
$image = $this->getFirstAttachedImage();
break;
case 'content':
$image = $this->getFirstImageInContent();
break;
case 'author':
$image = $this->getAuthorAvatar();
break;
case 'auto':
$image = $this->getFirstAvailableImage();
break;
case 'custom':
$image = $this->getCustomFieldImage();
break;
case 'custom_image':
$metaData = aioseo()->meta->metaData->getMetaData( $post );
if ( empty( $metaData ) ) {
break;
}
$image = 'facebook' === strtolower( $this->type )
? $metaData->og_image_custom_url
: $metaData->twitter_image_custom_url;
break;
case 'default':
default:
$image = aioseo()->options->social->{$this->type}->general->defaultImagePosts;
}
}
if ( empty( $image ) ) {
$image = aioseo()->options->social->{$this->type}->general->defaultImagePosts;
}
if ( is_array( $image ) ) {
$images[ $hash ] = $image;
return $images[ $hash ];
}
$imageWithoutDimensions = aioseo()->helpers->removeImageDimensions( $image );
$attachmentId = aioseo()->helpers->attachmentUrlToPostId( $imageWithoutDimensions );
$images[ $hash ] = $attachmentId ? wp_get_attachment_image_src( $attachmentId, $this->thumbnailSize ) : $image;
return $images[ $hash ];
}
/**
* Returns the Featured Image for the post.
*
* @since 4.0.0
*
* @return array The image data.
*/
private function getFeaturedImage() {
$cachedImage = $this->getCachedImage();
if ( $cachedImage ) {
return $cachedImage;
}
$imageId = get_post_thumbnail_id( $this->post->ID );
return $imageId ? wp_get_attachment_image_src( $imageId, $this->thumbnailSize ) : '';
}
/**
* Returns the first attached image.
*
* @since 4.0.0
*
* @return string The image data.
*/
private function getFirstAttachedImage() {
$cachedImage = $this->getCachedImage();
if ( $cachedImage ) {
return $cachedImage;
}
if ( 'attachment' === get_post_type( $this->post->ID ) ) {
return wp_get_attachment_image_src( $this->post->ID, $this->thumbnailSize );
}
$attachments = get_children(
[
'post_parent' => $this->post->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
]
);
return $attachments && count( $attachments ) ? wp_get_attachment_image_src( array_values( $attachments )[0]->ID, $this->thumbnailSize ) : '';
}
/**
* Returns the first image found in the post content.
*
* @since 4.0.0
*
* @return string The image URL.
*/
private function getFirstImageInContent() {
$cachedImage = $this->getCachedImage();
if ( $cachedImage ) {
return $cachedImage;
}
$postContent = aioseo()->helpers->getPostContent( $this->post );
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', (string) $postContent, $matches ); // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
// Ignore cover block background image - WP >= 5.7.
if ( ! empty( $matches[0] ) && apply_filters( 'aioseo_social_image_ignore_cover_block', true, $this->post, $matches ) ) {
foreach ( $matches[0] as $key => $match ) {
if ( false !== stripos( $match, 'wp-block-cover__image-background' ) ) {
unset( $matches[1][ $key ] );
}
}
}
return ! empty( $matches[1] ) ? current( $matches[1] ) : '';
}
/**
* Returns the author avatar.
*
* @since 4.0.0
*
* @return string The image URL.
*/
private function getAuthorAvatar() {
$avatar = get_avatar( $this->post->post_author, 300 );
preg_match( "/src='(.*?)'/i", (string) $avatar, $matches );
return ! empty( $matches[1] ) ? $matches[1] : '';
}
/**
* Returns the first available image.
*
* @since 4.0.0
*
* @return string The image URL.
*/
private function getFirstAvailableImage() {
// Disable the cache.
$this->useCache = false;
$image = $this->getCustomFieldImage();
if ( ! $image ) {
$image = $this->getFeaturedImage();
}
if ( ! $image ) {
$image = $this->getFirstAttachedImage();
}
if ( ! $image ) {
$image = $this->getFirstImageInContent();
}
if ( ! $image && 'twitter' === strtolower( $this->type ) ) {
$image = aioseo()->options->social->twitter->homePage->image;
}
// Enable the cache.
$this->useCache = true;
return $image ? $image : aioseo()->options->social->facebook->homePage->image;
}
/**
* Returns the image from a custom field.
*
* @since 4.0.0
*
* @return string The image URL.
*/
private function getCustomFieldImage() {
$cachedImage = $this->getCachedImage();
if ( $cachedImage ) {
return $cachedImage;
}
$prefix = 'facebook' === strtolower( $this->type ) ? 'og_' : 'twitter_';
$aioseoPost = Models\Post::getPost( $this->post->ID );
$customFields = ! empty( $aioseoPost->{ $prefix . 'image_custom_fields' } )
? $aioseoPost->{ $prefix . 'image_custom_fields' }
: aioseo()->options->social->{$this->type}->general->customFieldImagePosts;
if ( ! $customFields ) {
return '';
}
$customFields = explode( ',', $customFields );
foreach ( $customFields as $customField ) {
$image = get_post_meta( $this->post->ID, $customField, true );
if ( ! empty( $image ) ) {
$image = is_array( $image ) ? $image[0] : $image;
return is_numeric( $image )
? wp_get_attachment_image_src( $image, $this->thumbnailSize )
: $image;
}
}
return '';
}
/**
* Returns the cached image if there is one.
*
* @since 4.1.6.2
*
* @param \WP_Term $object The object for which we need to get the cached image.
* @return string|array The image URL or data.
*/
protected function getCachedImage( $object = null ) {
if ( null === $object ) {
// This isn't null if we call it from the Pro class.
$object = $this->post;
}
$metaData = aioseo()->meta->metaData->getMetaData( $object );
switch ( $this->type ) {
case 'facebook':
if ( ! empty( $metaData->og_image_url ) && $this->useCache ) {
return aioseo()->meta->metaData->getCachedOgImage( $metaData );
}
break;
case 'twitter':
if ( ! empty( $metaData->twitter_image_url ) && $this->useCache ) {
return $metaData->twitter_image_url;
}
break;
default:
break;
}
return '';
}
} Social.php 0000666 00000010213 15114625553 0006477 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Social;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Handles the Social Meta.
*
* @package AIOSEO\Plugin\Common\Social
*
* @since 4.0.0
*/
class Social {
/**
* The name of the action to bust the OG cache.
*
* @since 4.2.0
*
* @var string
*/
private $bustOgCacheActionName = 'aioseo_og_cache_bust_post';
/**
* Image class instance.
*
* @since 4.2.7
*
* @var Image
*/
public $image = null;
/**
* Facebook class instance.
*
* @since 4.2.7
*
* @var Facebook
*/
public $facebook = null;
/**
* Twitter class instance.
*
* @since 4.2.7
*
* @var Twitter
*/
public $twitter = null;
/**
* Output class instance.
*
* @since 4.2.7
*
* @var Output
*/
public $output = null;
/**
* Class constructor.
*
* @since 4.0.0
*/
public function __construct() {
$this->image = new Image();
if ( wp_doing_ajax() || wp_doing_cron() ) {
return;
}
$this->facebook = new Facebook();
$this->twitter = new Twitter();
$this->output = new Output();
$this->hooks();
}
/**
* Registers our hooks.
*
* @since 4.0.0
*/
protected function hooks() {
add_action( $this->bustOgCacheActionName, [ $this, 'bustOgCachePost' ] );
// To avoid duplicate sets of meta tags.
add_filter( 'jetpack_enable_open_graph', '__return_false' );
if ( ! is_admin() ) {
add_filter( 'language_attributes', [ $this, 'addAttributes' ] );
return;
}
// Forces a refresh of the Facebook cache.
add_action( 'post_updated', [ $this, 'scheduleBustOgCachePost' ], 10, 2 );
}
/**
* Adds our attributes to the registered language attributes.
*
* @since 4.0.0
* @version 4.4.5 Adds trim function the html tag removing empty spaces.
*
* @param string $htmlTag The 'html' tag as a string.
* @return string The filtered 'html' tag as a string.
*/
public function addAttributes( $htmlTag ) {
if ( ! aioseo()->options->social->facebook->general->enable ) {
return $htmlTag;
}
$attributes = apply_filters( 'aioseo_opengraph_attributes', [ 'prefix="og: https://ogp.me/ns#"' ] );
foreach ( $attributes as $attr ) {
if ( strpos( $htmlTag, $attr ) === false ) {
$htmlTag .= " $attr ";
}
}
return trim( $htmlTag );
}
/**
* Schedule a ping to bust the OG cache.
*
* @since 4.2.0
*
* @param int $postId The post ID.
* @param \WP_Post $post The post object.
* @return void
*/
public function scheduleBustOgCachePost( $postId, $post = null ) {
if ( ! aioseo()->helpers->isSbCustomFacebookFeedActive() || ! aioseo()->helpers->isValidPost( $post ) ) {
return;
}
if ( aioseo()->actionScheduler->isScheduled( $this->bustOgCacheActionName, [ 'postId' => $postId ] ) ) {
return;
}
// Schedule the new ping.
aioseo()->actionScheduler->scheduleAsync( $this->bustOgCacheActionName, [ 'postId' => $postId ] );
}
/**
* Pings Facebook and asks them to bust the OG cache for a particular post.
*
* @since 4.2.0
*
* @see https://developers.facebook.com/docs/sharing/opengraph/using-objects#update
*
* @param int $postId The post ID.
* @return void
*/
public function bustOgCachePost( $postId ) {
$post = get_post( $postId );
$customAccessToken = apply_filters( 'aioseo_facebook_access_token', '' );
if (
! aioseo()->helpers->isValidPost( $post ) ||
( ! aioseo()->helpers->isSbCustomFacebookFeedActive() && ! $customAccessToken )
) {
return;
}
$permalink = get_permalink( $postId );
$this->bustOgCacheHelper( $permalink );
}
/**
* Helper function for bustOgCache().
*
* @since 4.2.0
*
* @param string $permalink The permalink.
* @return void
*/
protected function bustOgCacheHelper( $permalink ) {
$accessToken = aioseo()->helpers->getSbAccessToken();
$accessToken = apply_filters( 'aioseo_facebook_access_token', $accessToken );
if ( ! $accessToken ) {
return;
}
$url = sprintf(
'https://graph.facebook.com/?%s',
http_build_query(
[
'id' => $permalink,
'scrape' => true,
'access_token' => $accessToken
]
)
);
wp_remote_post( $url, [ 'blocking' => false ] );
}
} Facebook.php 0000666 00000040211 15114625553 0006777 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Social;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Traits;
/**
* Handles the Open Graph meta.
*
* @since 4.0.0
*/
class Facebook {
use Traits\SocialProfiles;
/**
* Returns the Open Graph image URL.
*
* @since 4.0.0
*
* @param int $postId The post ID (optional).
* @return string The image URL.
*/
public function getImage( $postId = null ) {
$post = aioseo()->helpers->getPost( $postId );
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$image = aioseo()->options->social->facebook->homePage->image;
if ( empty( $image ) ) {
$image = aioseo()->social->image->getImage( 'facebook', aioseo()->options->social->facebook->general->defaultImageSourcePosts, $post );
}
return $image;
}
$metaData = aioseo()->meta->metaData->getMetaData( $post );
$image = '';
if ( ! empty( $metaData ) ) {
$imageSource = ! empty( $metaData->og_image_type ) && 'default' !== $metaData->og_image_type
? $metaData->og_image_type
: aioseo()->options->social->facebook->general->defaultImageSourcePosts;
$image = aioseo()->social->image->getImage( 'facebook', $imageSource, $post );
}
// Since we could be on an archive page, let's check again for that default image.
if ( ! $image ) {
$image = aioseo()->social->image->getImage( 'facebook', 'default' );
}
if ( ! $image ) {
$image = aioseo()->helpers->getSiteLogoUrl();
}
// Allow users to control the default image per post type.
return apply_filters(
'aioseo_opengraph_default_image',
$image,
[
$post,
$this->getObjectType()
]
);
}
/**
* Returns the width of the Open Graph image.
*
* @since 4.0.0
*
* @return string The image width.
*/
public function getImageWidth() {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$width = aioseo()->options->social->facebook->homePage->imageWidth;
return $width ? $width : aioseo()->options->social->facebook->general->defaultImagePostsWidth;
}
$metaData = aioseo()->meta->metaData->getMetaData();
if ( ! empty( $metaData->og_custom_image_width ) ) {
return $metaData->og_custom_image_width;
}
$image = $this->getImage();
if ( is_array( $image ) ) {
return $image[1];
}
return aioseo()->options->social->facebook->general->defaultImagePostsWidth;
}
/**
* Returns the height of the Open Graph image.
*
* @since 4.0.0
*
* @return string The image height.
*/
public function getImageHeight() {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$height = aioseo()->options->social->facebook->homePage->imageHeight;
return $height ? $height : aioseo()->options->social->facebook->general->defaultImagePostsHeight;
}
$metaData = aioseo()->meta->metaData->getMetaData();
if ( ! empty( $metaData->og_custom_image_height ) ) {
return $metaData->og_custom_image_height;
}
$image = $this->getImage();
if ( is_array( $image ) ) {
return $image[2];
}
return aioseo()->options->social->facebook->general->defaultImagePostsHeight;
}
/**
* Returns the Open Graph video URL.
*
* @since 4.0.0
*
* @return string The video URL.
*/
public function getVideo() {
$metaData = aioseo()->meta->metaData->getMetaData();
return ! empty( $metaData->og_video ) ? $metaData->og_video : '';
}
/**
* Returns the width of the video.
*
* @since 4.0.0
*
* @return string The video width.
*/
public function getVideoWidth() {
$metaData = aioseo()->meta->metaData->getMetaData();
return ! empty( $metaData->og_video_width ) ? $metaData->og_video_width : '';
}
/**
* Returns the height of the video.
*
* @since 4.0.0
*
* @return string The video height.
*/
public function getVideoHeight() {
$metaData = aioseo()->meta->metaData->getMetaData();
return ! empty( $metaData->og_video_height ) ? $metaData->og_video_height : '';
}
/**
* Returns the site name.
*
* @since 4.0.0
*
* @return string The site name.
*/
public function getSiteName() {
$title = aioseo()->helpers->decodeHtmlEntities( aioseo()->tags->replaceTags( aioseo()->options->social->facebook->general->siteName, get_the_ID() ) );
if ( ! $title ) {
$title = aioseo()->helpers->decodeHtmlEntities( get_bloginfo( 'name' ) );
}
return wp_strip_all_tags( $title );
}
/**
* Returns the Open Graph object type.
*
* @since 4.0.0
*
* @return string The object type.
*/
public function getObjectType() {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$type = aioseo()->options->social->facebook->homePage->objectType;
return $type ? $type : 'website';
}
if ( is_post_type_archive() ) {
return 'website';
}
$post = aioseo()->helpers->getPost();
$metaData = aioseo()->meta->metaData->getMetaData( $post );
if ( ! empty( $metaData->og_object_type ) && 'default' !== $metaData->og_object_type ) {
return $metaData->og_object_type;
}
$postType = get_post_type();
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
$defaultObjectType = $dynamicOptions->social->facebook->general->postTypes->has( $postType )
? $dynamicOptions->social->facebook->general->postTypes->$postType->objectType
: '';
return ! empty( $defaultObjectType ) ? $defaultObjectType : 'article';
}
/**
* Returns the Open Graph title for the current page.
*
* @since 4.0.0
*
* @param \WP_Post|integer $post The post object or ID (optional).
* @return string The Open Graph title.
*/
public function getTitle( $post = null ) {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$title = aioseo()->meta->title->helpers->prepare( aioseo()->options->social->facebook->homePage->title );
return $title ? $title : aioseo()->meta->title->getTitle();
}
$post = aioseo()->helpers->getPost( $post );
$metaData = aioseo()->meta->metaData->getMetaData( $post );
$title = '';
if ( ! empty( $metaData->og_title ) ) {
$title = aioseo()->meta->title->helpers->prepare( $metaData->og_title );
}
if ( is_post_type_archive() ) {
$postType = get_queried_object();
if ( is_a( $postType, 'WP_Post_Type' ) ) {
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
if ( $dynamicOptions->searchAppearance->archives->has( $postType->name ) ) {
$title = aioseo()->meta->title->helpers->prepare( aioseo()->dynamicOptions->searchAppearance->archives->{ $postType->name }->title );
}
}
}
return $title
? $title
: (
$post
? aioseo()->meta->title->getPostTitle( $post )
: $title
);
}
/**
* Returns the Open Graph description.
*
* @since 4.0.0
*
* @param \WP_Post|integer $post The post object or ID (optional).
* @return string The Open Graph description.
*/
public function getDescription( $post = null ) {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$description = aioseo()->meta->description->helpers->prepare( aioseo()->options->social->facebook->homePage->description );
return $description ? $description : aioseo()->meta->description->getDescription();
}
$post = aioseo()->helpers->getPost( $post );
$metaData = aioseo()->meta->metaData->getMetaData( $post );
$description = '';
if ( ! empty( $metaData->og_description ) ) {
$description = aioseo()->meta->description->helpers->prepare( $metaData->og_description );
}
if ( is_post_type_archive() ) {
$postType = get_queried_object();
if ( is_a( $postType, 'WP_Post_Type' ) ) {
$dynamicOptions = aioseo()->dynamicOptions->noConflict();
if ( $dynamicOptions->searchAppearance->archives->has( $postType->name ) ) {
$description = aioseo()->meta->description->helpers->prepare( aioseo()->dynamicOptions->searchAppearance->archives->{ $postType->name }->metaDescription );
}
}
}
return $description
? $description
: (
$post
? aioseo()->meta->description->getPostDescription( $post )
: $description
);
}
/**
* Returns the Open Graph article section name.
*
* @since 4.0.0
*
* @return string The article section name.
*/
public function getSection() {
$metaData = aioseo()->meta->metaData->getMetaData();
return ! empty( $metaData->og_article_section ) ? $metaData->og_article_section : '';
}
/**
* Returns the Open Graph publisher URL.
*
* @since 4.0.0
*
* @return string The Open Graph publisher URL.
*/
public function getPublisher() {
if ( ! aioseo()->options->social->profiles->sameUsername->enable ) {
return aioseo()->options->social->profiles->urls->facebookPageUrl;
}
$username = aioseo()->options->social->profiles->sameUsername->username;
return ( $username && in_array( 'facebookPageUrl', aioseo()->options->social->profiles->sameUsername->included, true ) )
? 'https://facebook.com/' . $username
: '';
}
/**
* Returns the published time.
*
* @since 4.0.0
*
* @return string The published time.
*/
public function getPublishedTime() {
$post = aioseo()->helpers->getPost();
return $post ? aioseo()->helpers->dateTimeToIso8601( $post->post_date_gmt ) : '';
}
/**
* Returns the last modified time.
*
* @since 4.0.0
*
* @return string The last modified time.
*/
public function getModifiedTime() {
$post = aioseo()->helpers->getPost();
return $post ? aioseo()->helpers->dateTimeToIso8601( $post->post_modified_gmt ) : '';
}
/**
* Returns the Open Graph author.
*
* @since 4.0.0
*
* @return string The Open Graph author.
*/
public function getAuthor() {
$post = aioseo()->helpers->getPost();
if ( ! is_a( $post, 'WP_Post' ) || ! aioseo()->options->social->facebook->general->showAuthor ) {
return '';
}
$author = '';
$userProfiles = $this->getUserProfiles( $post->post_author );
if ( ! empty( $userProfiles['facebookPageUrl'] ) ) {
$author = $userProfiles['facebookPageUrl'];
}
if ( empty( $author ) ) {
$author = aioseo()->options->social->facebook->advanced->authorUrl;
}
return $author;
}
/**
* Returns the Open Graph article tags.
*
* @since 4.0.0
*
* @return array An array of unique keywords.
*/
public function getArticleTags() {
$post = aioseo()->helpers->getPost();
$metaData = aioseo()->meta->metaData->getMetaData( $post );
$tags = ! empty( $metaData->og_article_tags ) ? aioseo()->meta->keywords->extractMetaKeywords( $metaData->og_article_tags ) : [];
if (
$post &&
aioseo()->options->social->facebook->advanced->enable &&
aioseo()->options->social->facebook->advanced->generateArticleTags
) {
if ( aioseo()->options->social->facebook->advanced->useKeywordsInTags ) {
$keywords = aioseo()->meta->keywords->getKeywords();
$keywords = aioseo()->tags->parseCustomFields( $keywords );
$keywords = aioseo()->meta->keywords->keywordStringToList( $keywords );
$tags = array_merge( $tags, $keywords );
}
if ( aioseo()->options->social->facebook->advanced->useCategoriesInTags ) {
$tags = array_merge( $tags, aioseo()->helpers->getAllCategories( $post->ID ) );
}
if ( aioseo()->options->social->facebook->advanced->usePostTagsInTags ) {
$tags = array_merge( $tags, aioseo()->helpers->getAllTags( $post->ID ) );
}
}
return aioseo()->meta->keywords->getUniqueKeywords( $tags, false );
}
/**
* Retreive the locale.
*
* @since 4.1.4
*
* @return string The locale.
*/
public function getLocale() {
$locale = get_locale();
// These are the locales FB supports.
$validLocales = [
'af_ZA', // Afrikaans.
'ak_GH', // Akan.
'am_ET', // Amharic.
'ar_AR', // Arabic.
'as_IN', // Assamese.
'ay_BO', // Aymara.
'az_AZ', // Azerbaijani.
'be_BY', // Belarusian.
'bg_BG', // Bulgarian.
'bp_IN', // Bhojpuri.
'bn_IN', // Bengali.
'br_FR', // Breton.
'bs_BA', // Bosnian.
'ca_ES', // Catalan.
'cb_IQ', // Sorani Kurdish.
'ck_US', // Cherokee.
'co_FR', // Corsican.
'cs_CZ', // Czech.
'cx_PH', // Cebuano.
'cy_GB', // Welsh.
'da_DK', // Danish.
'de_DE', // German.
'el_GR', // Greek.
'en_GB', // English (UK).
'en_PI', // English (Pirate).
'en_UD', // English (Upside Down).
'en_US', // English (US).
'em_ZM',
'eo_EO', // Esperanto.
'es_ES', // Spanish (Spain).
'es_LA', // Spanish.
'es_MX', // Spanish (Mexico).
'et_EE', // Estonian.
'eu_ES', // Basque.
'fa_IR', // Persian.
'fb_LT', // Leet Speak.
'ff_NG', // Fulah.
'fi_FI', // Finnish.
'fo_FO', // Faroese.
'fr_CA', // French (Canada).
'fr_FR', // French (France).
'fy_NL', // Frisian.
'ga_IE', // Irish.
'gl_ES', // Galician.
'gn_PY', // Guarani.
'gu_IN', // Gujarati.
'gx_GR', // Classical Greek.
'ha_NG', // Hausa.
'he_IL', // Hebrew.
'hi_IN', // Hindi.
'hr_HR', // Croatian.
'hu_HU', // Hungarian.
'ht_HT', // Haitian Creole.
'hy_AM', // Armenian.
'id_ID', // Indonesian.
'ig_NG', // Igbo.
'is_IS', // Icelandic.
'it_IT', // Italian.
'ik_US',
'iu_CA',
'ja_JP', // Japanese.
'ja_KS', // Japanese (Kansai).
'jv_ID', // Javanese.
'ka_GE', // Georgian.
'kk_KZ', // Kazakh.
'km_KH', // Khmer.
'kn_IN', // Kannada.
'ko_KR', // Korean.
'ks_IN', // Kashmiri.
'ku_TR', // Kurdish (Kurmanji).
'ky_KG', // Kyrgyz.
'la_VA', // Latin.
'lg_UG', // Ganda.
'li_NL', // Limburgish.
'ln_CD', // Lingala.
'lo_LA', // Lao.
'lt_LT', // Lithuanian.
'lv_LV', // Latvian.
'mg_MG', // Malagasy.
'mi_NZ', // Maori.
'mk_MK', // Macedonian.
'ml_IN', // Malayalam.
'mn_MN', // Mongolian.
'mr_IN', // Marathi.
'ms_MY', // Malay.
'mt_MT', // Maltese.
'my_MM', // Burmese.
'nb_NO', // Norwegian (bokmal).
'nd_ZW', // Ndebele.
'ne_NP', // Nepali.
'nl_BE', // Dutch (Belgie).
'nl_NL', // Dutch.
'nn_NO', // Norwegian (nynorsk).
'nr_ZA', // Southern Ndebele.
'ns_ZA', // Northern Sotho.
'ny_MW', // Chewa.
'om_ET', // Oromo.
'or_IN', // Oriya.
'pa_IN', // Punjabi.
'pl_PL', // Polish.
'ps_AF', // Pashto.
'pt_BR', // Portuguese (Brazil).
'pt_PT', // Portuguese (Portugal).
'qc_GT', // Quiché.
'qu_PE', // Quechua.
'qr_GR',
'qz_MM', // Burmese (Zawgyi).
'rm_CH', // Romansh.
'ro_RO', // Romanian.
'ru_RU', // Russian.
'rw_RW', // Kinyarwanda.
'sa_IN', // Sanskrit.
'sc_IT', // Sardinian.
'se_NO', // Northern Sami.
'si_LK', // Sinhala.
'su_ID', // Sundanese.
'sk_SK', // Slovak.
'sl_SI', // Slovenian.
'sn_ZW', // Shona.
'so_SO', // Somali.
'sq_AL', // Albanian.
'sr_RS', // Serbian.
'ss_SZ', // Swazi.
'st_ZA', // Southern Sotho.
'sv_SE', // Swedish.
'sw_KE', // Swahili.
'sy_SY', // Syriac.
'sz_PL', // Silesian.
'ta_IN', // Tamil.
'te_IN', // Telugu.
'tg_TJ', // Tajik.
'th_TH', // Thai.
'tk_TM', // Turkmen.
'tl_PH', // Filipino.
'tl_ST', // Klingon.
'tn_BW', // Tswana.
'tr_TR', // Turkish.
'ts_ZA', // Tsonga.
'tt_RU', // Tatar.
'tz_MA', // Tamazight.
'uk_UA', // Ukrainian.
'ur_PK', // Urdu.
'uz_UZ', // Uzbek.
've_ZA', // Venda.
'vi_VN', // Vietnamese.
'wo_SN', // Wolof.
'xh_ZA', // Xhosa.
'yi_DE', // Yiddish.
'yo_NG', // Yoruba.
'zh_CN', // Simplified Chinese (China).
'zh_HK', // Traditional Chinese (Hong Kong).
'zh_TW', // Traditional Chinese (Taiwan).
'zu_ZA', // Zulu.
'zz_TR', // Zazaki.
];
// Catch some weird locales served out by WP that are not easily doubled up.
$fixLocales = [
'ca' => 'ca_ES',
'en' => 'en_US',
'el' => 'el_GR',
'et' => 'et_EE',
'ja' => 'ja_JP',
'sq' => 'sq_AL',
'uk' => 'uk_UA',
'vi' => 'vi_VN',
'zh' => 'zh_CN',
];
if ( isset( $fixLocales[ $locale ] ) ) {
$locale = $fixLocales[ $locale ];
}
// Convert locales like "es" to "es_ES", in case that works for the given locale (sometimes it does).
if ( 2 === strlen( $locale ) ) {
$locale = strtolower( $locale ) . '_' . strtoupper( $locale );
}
// Check to see if the locale is a valid FB one, if not, use en_US as a fallback.
if ( ! in_array( $locale, $validLocales, true ) ) {
$locale = strtolower( substr( $locale, 0, 2 ) ) . '_' . strtoupper( substr( $locale, 0, 2 ) );
if ( ! in_array( $locale, $validLocales, true ) ) {
$locale = 'en_US';
}
}
return apply_filters( 'aioseo_og_locale', $locale );
}
} Twitter.php 0000666 00000017724 15114625553 0006745 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Social;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Traits;
/**
* Handles the Twitter meta.
*
* @since 4.0.0
*/
class Twitter {
use Traits\SocialProfiles;
/**
* Returns the Twitter URL for the site.
*
* @since 4.0.0
*
* @return string The Twitter URL.
*/
public function getTwitterUrl() {
if ( ! aioseo()->options->social->profiles->sameUsername->enable ) {
return aioseo()->options->social->profiles->urls->twitterUrl;
}
$userName = aioseo()->options->social->profiles->sameUsername->username;
return ( $userName && in_array( 'twitterUrl', aioseo()->options->social->profiles->sameUsername->included, true ) )
? 'https://x.com/' . $userName
: '';
}
/**
* Returns the Twitter card type.
*
* @since 4.0.0
*
* @return string $card The card type.
*/
public function getCardType() {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
return aioseo()->options->social->twitter->homePage->cardType;
}
$metaData = aioseo()->meta->metaData->getMetaData();
return ! empty( $metaData->twitter_card ) && 'default' !== $metaData->twitter_card ? $metaData->twitter_card : aioseo()->options->social->twitter->general->defaultCardType;
}
/**
* Returns the Twitter creator.
*
* @since 4.0.0
*
* @return string The creator.
*/
public function getCreator() {
$post = aioseo()->helpers->getPost();
if (
! is_a( $post, 'WP_Post' ) ||
! post_type_supports( $post->post_type, 'author' ) ||
! aioseo()->options->social->twitter->general->showAuthor
) {
return '';
}
$author = '';
$userProfiles = $this->getUserProfiles( $post->post_author );
if ( ! empty( $userProfiles['twitterUrl'] ) ) {
$author = $userProfiles['twitterUrl'];
}
if ( empty( $author ) ) {
$author = aioseo()->social->twitter->getTwitterUrl();
}
$author = aioseo()->social->twitter->prepareUsername( $author );
return $author;
}
/**
* Returns the Twitter image URL.
*
* @since 4.0.0
*
* @param int $postId The post ID (optional).
* @return string The image URL.
*/
public function getImage( $postId = null ) {
$post = aioseo()->helpers->getPost( $postId );
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$image = aioseo()->options->social->twitter->homePage->image;
if ( empty( $image ) ) {
$image = aioseo()->options->social->facebook->homePage->image;
}
if ( empty( $image ) ) {
$image = aioseo()->social->image->getImage( 'twitter', aioseo()->options->social->twitter->general->defaultImageSourcePosts, $post );
}
return $image ? $image : aioseo()->social->facebook->getImage();
}
$metaData = aioseo()->meta->metaData->getMetaData( $post );
if ( ! empty( $metaData->twitter_use_og ) ) {
return aioseo()->social->facebook->getImage();
}
$image = '';
if ( ! empty( $metaData ) ) {
$imageSource = ! empty( $metaData->twitter_image_type ) && 'default' !== $metaData->twitter_image_type
? $metaData->twitter_image_type
: aioseo()->options->social->twitter->general->defaultImageSourcePosts;
$image = aioseo()->social->image->getImage( 'twitter', $imageSource, $post );
}
return $image ? $image : aioseo()->social->facebook->getImage();
}
/**
* Returns the Twitter title for the current page.
*
* @since 4.0.0
*
* @param \WP_Post|integer $post The post object or ID (optional).
* @return string The Twitter title.
*/
public function getTitle( $post = null ) {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$title = aioseo()->meta->title->helpers->prepare( aioseo()->options->social->twitter->homePage->title );
return $title ? $title : aioseo()->social->facebook->getTitle( $post );
}
$post = aioseo()->helpers->getPost( $post );
$metaData = aioseo()->meta->metaData->getMetaData( $post );
if ( ! empty( $metaData->twitter_use_og ) ) {
return aioseo()->social->facebook->getTitle( $post );
}
$title = '';
if ( ! empty( $metaData->twitter_title ) ) {
$title = aioseo()->meta->title->helpers->prepare( $metaData->twitter_title );
}
return $title ? $title : aioseo()->social->facebook->getTitle( $post );
}
/**
* Returns the Twitter description for the current page.
*
* @since 4.0.0
*
* @param \WP_Post|integer $post The post object or ID (optional).
* @return string The Twitter description.
*/
public function getDescription( $post = null ) {
if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) {
$description = aioseo()->meta->description->helpers->prepare( aioseo()->options->social->twitter->homePage->description );
return $description ? $description : aioseo()->social->facebook->getDescription( $post );
}
$post = aioseo()->helpers->getPost( $post );
$metaData = aioseo()->meta->metaData->getMetaData( $post );
if ( ! empty( $metaData->twitter_use_og ) ) {
return aioseo()->social->facebook->getDescription( $post );
}
$description = '';
if ( ! empty( $metaData->twitter_description ) ) {
$description = aioseo()->meta->description->helpers->prepare( $metaData->twitter_description );
}
return $description ? $description : aioseo()->social->facebook->getDescription( $post );
}
/**
* Prepare twitter username for public display.
*
* We do things like strip out the URL, etc and return just (at)username.
* At the moment, we'll check for 1 of 3 things... (at)username, username, and https://x.com/username.
*
* @since 4.0.0
*
* @param string $profile Twitter username.
* @param boolean $includeAt Whether or not ot include the @ sign.
* @return string Full Twitter username.
*/
public function prepareUsername( $profile, $includeAt = true ) {
if ( ! $profile ) {
return $profile;
}
$profile = (string) $profile;
if ( preg_match( '/^(\@)?[A-Za-z0-9_]+$/', (string) $profile ) ) {
if ( '@' !== $profile[0] && $includeAt ) {
$profile = '@' . $profile;
} elseif ( '@' === $profile[0] && ! $includeAt ) {
$profile = ltrim( $profile, '@' );
}
}
if ( strpos( $profile, 'twitter.com' ) || strpos( $profile, 'x.com' ) ) {
$profile = esc_url( $profile );
// Extract the twitter username from the URL.
$parsedTwitterProfile = wp_parse_url( $profile );
$path = $parsedTwitterProfile['path'];
$pathParts = explode( '/', $path );
$profile = $pathParts[1];
if ( $profile ) {
if ( '@' !== $profile[0] && $includeAt ) {
$profile = '@' . $profile;
}
if ( '@' === $profile[0] && ! $includeAt ) {
$profile = ltrim( $profile, '@' );
}
}
}
return $profile;
}
/**
* Get additional twitter data.
*
* @since 4.0.0
*
* @return array An array of additional twitter data.
*/
public function getAdditionalData() {
if ( ! aioseo()->options->social->twitter->general->additionalData ) {
return [];
}
$data = [];
$post = aioseo()->helpers->getPost();
if ( ! is_a( $post, 'WP_Post' ) ) {
return $data;
}
if ( $post->post_author && post_type_supports( $post->post_type, 'author' ) ) {
$data[] = [
'label' => __( 'Written by', 'all-in-one-seo-pack' ),
'value' => get_the_author_meta( 'display_name', $post->post_author )
];
}
if ( ! empty( $post->post_content ) ) {
$minutes = $this->getReadingTime( $post->post_content );
if ( ! empty( $minutes ) ) {
$data[] = [
'label' => __( 'Est. reading time', 'all-in-one-seo-pack' ),
// Translators: 1 - The estimated reading time.
'value' => sprintf( _n( '%1$s minute', '%1$s minutes', $minutes, 'all-in-one-seo-pack' ), $minutes )
];
}
}
return $data;
}
/**
* Returns the estimated reading time for a string.
*
* @since 4.0.0
*
* @param string $string The string to count.
* @return integer The estimated reading time as an integer.
*/
private function getReadingTime( $string ) {
$wpm = 200;
$word = str_word_count( wp_strip_all_tags( $string ) );
return round( $word / $wpm );
}
} Output.php 0000666 00000011065 15114625553 0006573 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Social;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Integrations\BuddyPress as BuddyPressIntegration;
/**
* Outputs our social meta.
*
* @since 4.0.0
*/
class Output {
/**
* Checks if the current page should have social meta.
*
* @since 4.0.0
*
* @return bool Whether or not the page should have social meta.
*/
public function isAllowed() {
if ( BuddyPressIntegration::isComponentPage() ) {
return false;
}
if (
! is_front_page() &&
! is_home() &&
! is_singular() &&
! is_post_type_archive() &&
! aioseo()->helpers->isWooCommerceShopPage()
) {
return false;
}
return true;
}
/**
* Returns the Open Graph meta.
*
* @since 4.0.0
*
* @return array The Open Graph meta.
*/
public function getFacebookMeta() {
if ( ! $this->isAllowed() || ! aioseo()->options->social->facebook->general->enable ) {
return [];
}
$meta = [
'og:locale' => aioseo()->social->facebook->getLocale(),
'og:site_name' => aioseo()->helpers->encodeOutputHtml( aioseo()->social->facebook->getSiteName() ),
'og:type' => aioseo()->social->facebook->getObjectType(),
'og:title' => aioseo()->helpers->encodeOutputHtml( aioseo()->social->facebook->getTitle() ),
'og:description' => aioseo()->helpers->encodeOutputHtml( aioseo()->social->facebook->getDescription() ),
'og:url' => esc_url( aioseo()->helpers->canonicalUrl() ),
'fb:app_id' => aioseo()->options->social->facebook->advanced->appId,
'fb:admins' => implode( ',', array_map( 'trim', explode( ',', aioseo()->options->social->facebook->advanced->adminId ) ) ),
];
$image = aioseo()->social->facebook->getImage();
if ( $image ) {
$image = is_array( $image ) ? $image[0] : $image;
$image = aioseo()->helpers->makeUrlAbsolute( $image );
$image = set_url_scheme( esc_url( $image ) );
$meta += [
'og:image' => $image,
'og:image:secure_url' => is_ssl() ? $image : '',
'og:image:width' => aioseo()->social->facebook->getImageWidth(),
'og:image:height' => aioseo()->social->facebook->getImageHeight(),
];
}
$video = aioseo()->social->facebook->getVideo();
if ( $video ) {
$video = set_url_scheme( esc_url( $video ) );
$meta += [
'og:video' => $video,
'og:video:secure_url' => is_ssl() ? $video : '',
'og:video:width' => aioseo()->social->facebook->getVideoWidth(),
'og:video:height' => aioseo()->social->facebook->getVideoHeight(),
];
}
if ( ! empty( $meta['og:type'] ) && 'article' === $meta['og:type'] ) {
$meta += [
'article:section' => aioseo()->social->facebook->getSection(),
'article:tag' => aioseo()->social->facebook->getArticleTags(),
'article:published_time' => aioseo()->social->facebook->getPublishedTime(),
'article:modified_time' => aioseo()->social->facebook->getModifiedTime(),
'article:publisher' => aioseo()->social->facebook->getPublisher(),
'article:author' => aioseo()->social->facebook->getAuthor()
];
}
return array_filter( apply_filters( 'aioseo_facebook_tags', $meta ) );
}
/**
* Returns the Twitter meta.
*
* @since 4.0.0
*
* @return array The Twitter meta.
*/
public function getTwitterMeta() {
if ( ! $this->isAllowed() || ! aioseo()->options->social->twitter->general->enable ) {
return [];
}
$meta = [
'twitter:card' => aioseo()->social->twitter->getCardType(),
'twitter:site' => aioseo()->social->twitter->prepareUsername( aioseo()->social->twitter->getTwitterUrl() ),
'twitter:title' => aioseo()->helpers->encodeOutputHtml( aioseo()->social->twitter->getTitle() ),
'twitter:description' => aioseo()->helpers->encodeOutputHtml( aioseo()->social->twitter->getDescription() ),
'twitter:creator' => aioseo()->social->twitter->getCreator()
];
$image = aioseo()->social->twitter->getImage();
if ( $image ) {
$image = is_array( $image ) ? $image[0] : $image;
$image = aioseo()->helpers->makeUrlAbsolute( $image );
// Set the twitter image meta.
$meta['twitter:image'] = $image;
}
if ( is_singular() ) {
$additionalData = apply_filters( 'aioseo_social_twitter_additional_data', aioseo()->social->twitter->getAdditionalData() );
if ( $additionalData ) {
$i = 1;
foreach ( $additionalData as $data ) {
$meta[ "twitter:label$i" ] = $data['label'];
$meta[ "twitter:data$i" ] = $data['value'];
$i++;
}
}
}
return array_filter( apply_filters( 'aioseo_twitter_tags', $meta ) );
}
}