';
}
public function render_post_retweets($settings, $class, $item) {
echo '
';
echo '
';
}
// Render Post Element Separator
public function render_post_element_separator( $settings, $class ) {
echo '';
}
public function render_post_media($settings, $class, $item) {
if ( isset($item['extended_entities']) && null !== $item['extended_entities'] ) {
if ( $item['extended_entities']['media'] ) {
$media = $item['extended_entities']['media'];
} else if ( isset( $item['retweeted_status']['entities']['media'] ) ) {
$media = $item['retweeted_status']['entities']['media'];
} else if ( isset( $item['quoted_status']['entities']['media'] ) ) {
$media = $item['quoted_status']['entities']['media'];
} else {
$media = [];
}
}
if ( !empty($media) ) {
echo '
';
echo '
';
// && $media[0]['type'] == 'photo'
echo (isset( $media[0] )) ? '

' : '';
echo '
';
echo '
';
}
}
// Get Elements
public function get_elements( $type, $settings, $class, $item ) {
if ( 'pro-lk' == $type || 'pro-shr' == $type || 'pro-cf' == $type ) {
$type = 'title';
}
switch ( $type ) {
case 'username':
$this->render_post_username( $settings, $class, $item );
break;
case 'profile-name':
$this->render_post_user_profile_name( $settings, $class, $item );
break;
case 'twit':
$this->render_post_caption( $settings, $class, $item );
break;
case 'date':
$this->render_post_date( $settings, $class, $item );
break;
case 'likes':
$this->render_post_likes( $settings, $class, $item );
break;
case 'comment':
$this->render_post_comment( $settings, $class, $item );
break;
case 'retweets':
$this->render_post_retweets( $settings, $class, $item );
break;
case 'media':
$this->render_post_media( $settings, $class, $item );
break;
case 'profile-picture':
$this->render_post_user_profile_picture( $settings, $class, $item );
break;
// case 'read-more':
// $this->render_post_account_name( $settings, $class );
// break;
// case 'lightbox':
// $this->render_post_lightbox( $settings, $class, $item );
// break;
case 'separator':
$this->render_post_element_separator( $settings, $class );
break;
}
}
// Get Elements by Location
public function get_elements_by_location( $location, $settings, $item ) {
$locations = [];
foreach ( $settings['twitter_feed_elements'] as $data ) {
$place = $data['element_location'];
$align_vr = $data['element_align_vr'];
if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) {
$align_vr = 'middle';
}
if ( ! isset($locations[$place]) ) {
$locations[$place] = [];
}
if ( 'over' === $place ) {
if ( ! isset($locations[$place][$align_vr]) ) {
$locations[$place][$align_vr] = [];
}
array_push( $locations[$place][$align_vr], $data );
} else {
array_push( $locations[$place], $data );
}
}
if ( ! empty( $locations[$location] ) ) {
if ( 'over' === $location ) {
foreach ( $locations[$location] as $align => $thiss ) {
if ( 'middle' === $align ) {
echo '
';
}
echo '';
if ( 'middle' === $align ) {
echo '
';
}
}
} else {
echo '';
}
}
}
public function wpr_load_more_tweets_function() {
$settings = $_POST['wpr_load_more_settings'];
$credentials = base64_encode($settings['twitter_feed_consumer_key'] . ':' . $settings['twitter_feed_consumer_secret']);
add_filter('https_ssl_verify', '__return_false');
$response = wp_remote_post('https://api.twitter.com/oauth2/token', [
'method' => 'POST',
'httpversion' => '1.1',
'blocking' => true,
'headers' => [
'Authorization' => 'Basic ' . $credentials,
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
],
'body' => ['grant_type' => 'client_credentials'],
]);
$body = json_decode(wp_remote_retrieve_body($response));
if ($body) {
$token = $body->access_token;
}
add_filter('https_ssl_verify', '__return_false');
$response = [];
$items_array = [];
foreach ($settings['twitter_accounts'] as $key=>$value) {
$response[$key] = wp_remote_get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=' . $value['twitter_feed_account_name'] . '&count='. ($settings['number_of_posts'] + $_POST['next_post_index']) .'&tweet_mode=extended', [
'httpversion' => '1.1',
'blocking' => true,
'headers' => [
'Authorization' => "Bearer $token",
],
]);
if ( is_wp_error( $response[$key] ) ) {
return $response[$key];
}
if ( ! empty( $response[$key]['response'] ) && $response[$key]['response']['code'] == 200 ) {
$items_array[] = json_decode( wp_remote_retrieve_body( $response[$key] ), true );
}
}
foreach ( $items_array as $key=>$items ) :
if ($settings['twitter_feed_hashtag_name']) {
$hashtag_names = explode(',', str_replace(' ', '', $settings['twitter_feed_hashtag_name']));
foreach ($items as $key => $item) {
$match = false;
if ($item['entities']['hashtags']) {
foreach ($item['entities']['hashtags'] as $tag) {
if (in_array($tag['text'], $hashtag_names)) {
$match = true;
}
}
}
if ($match == false) {
unset($items[$key]);
}
}
}
foreach ( $items as $key=>$item) :
if ( $key >= 6 && (!defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code()) ) {
break;
}
if ($key < $_POST['next_post_index']) :
continue;
endif;
$banner_placeholder = WPR_ADDONS_ASSETS_URL . 'img/placeholder.png';
$banner = $item['user']['profile_banner_url'] ? $item['user']['profile_banner_url'] : $banner_placeholder;
?>