Skip to content

Commit

Permalink
issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgimenez committed May 19, 2015
1 parent 544b30c commit 5fdd91e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 1 deletion.
10 changes: 10 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,23 @@ jQuery(document).ready(function($) {
});
});

//ajax facebook
var data = {
'action': 'facebook_brasa_social_feed'
};
$.post(odin_main.ajaxurl, data, function(response) {
$('#facebook-feed').html(response);
});

//ajax youtube
var data = {
'action': 'youtube_brasa_social_feed'
};
$.post(odin_main.ajaxurl, data, function(response) {
$('#youtube-feed').html(response);
});

//ajax twitter
var config1 = {
"id": odin_main.twitter_widget_id,
"domId": 'twitter-feed',
Expand Down
2 changes: 1 addition & 1 deletion content-facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* facebook posts content */
global $fb_post;
?>
<a class="social-feed col-md-12 animated tada" href="<?php echo esc_url($fb_post['link']);?>">
<a class="social-feed col-md-12" href="<?php echo esc_url($fb_post['link']);?>">
<div class="col-md-4 pull-left img-container">
<?php if($fb_post['type'] == 'photo'): ?>
<img src="<?php echo esc_url($fb_post['picture']);?>">
Expand Down
1 change: 1 addition & 0 deletions content-secao.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
$entre = '<div class="col-md-4 social-feed pull-right">';
$entre .= '<div id="facebook-feed"></div>';
$entre .= '<div id="twitter-feed"></div>';
$entre .= '<div id="youtube-feed"></div>';
$entre .= '</div>';
$antes = '<header class="entry-header"><h1 class="entry-title">'.get_the_title($post->ID).'</h1></header><!-- .entry-header -->';
$depois = '';
Expand Down
9 changes: 9 additions & 0 deletions content-youtube.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/* youtube posts content */
global $yt_post;
$url = 'https://youtu.be/'.$yt_post['id']['videoId'];
?>
<a class="youtube social-feed col-md-12" href="<?php echo esc_url($url);?>">
<img src="<?php echo esc_url($yt_post['snippet']['thumbnails']['medium']['url']);?>">
</a><!-- .col-md-12 -->
<div class="col-md-12" style="height:20px;clear:both"></div><!-- .col-md-12 -->
2 changes: 2 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ function is_woocommerce_activated() {
array(
'facebook_api_url' => $options['facebook_api_url'],
'facebook_auth' => $options['facebook_auth'],
'youtube_auth' => $options['youtube_auth'],
'youtube_user' => $options['youtube_user']
)
);
/**
Expand Down
24 changes: 24 additions & 0 deletions inc/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,29 @@
),
)
),
'social_yt_section' => array(
'tab' => 'social', // Sessão da aba odin_general
'title' => __( 'Opções do YouTube', 'odin' ),
'fields' => array(
array(
'id' => 'youtube_auth', // Obrigatório
'label' => __( 'Token de autorização do YouTube', 'odin' ), // Obrigatório
'type' => 'text', // Obrigatório
'default' => '', // Opcional (deve ser o id de uma imagem em mídia)
),
array(
'id' => 'youtube_user', // Obrigatório
'label' => __( 'ID do canal no YouTube', 'odin' ), // Obrigatório
'type' => 'text', // Obrigatório
'default' => '', // Opcional (deve ser o id de uma imagem em mídia)
),
array(
'id' => 'youtube_url', // Obrigatório
'label' => __( 'URL do canal no YouTube', 'odin' ), // Obrigatório
'type' => 'text', // Obrigatório
'default' => '', // Opcional (deve ser o id de uma imagem em mídia)
),
)
),
)
);
37 changes: 37 additions & 0 deletions inc/social-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
class Brasa_Social_Feed{
public function __construct($args){
$this->args = $args;

//ajax facebook
add_action( 'wp_ajax_facebook_brasa_social_feed', array($this,'do_ajax_facebook') );
add_action( 'wp_ajax_nopriv_facebook_brasa_social_feed', array($this,'do_ajax_facebook') );

//ajax youtube
add_action( 'wp_ajax_youtube_brasa_social_feed', array($this,'do_ajax_youtube') );
add_action( 'wp_ajax_nopriv_youtube_brasa_social_feed', array($this,'do_ajax_youtube') );
}

public function get_facebook_posts($limit = 2){
Expand Down Expand Up @@ -33,4 +39,35 @@ public function do_ajax_facebook(){
}
wp_die();
}

public function get_youtube_posts($limit = 2){
$request_url = add_query_arg(
array(
'channelId' => $this->args['youtube_user'],
'part' => 'snippet,id&order=date',
'maxResults' => $limit,
'key' => $this->args['youtube_auth']
),
'https://www.googleapis.com/youtube/v3/search/'
);
$request_url = esc_url_raw($request_url);
$request = wp_remote_get( $request_url );
$response = json_decode( wp_remote_retrieve_body( $request ), true );
return $response['items'];
}

public function do_ajax_youtube(){
$limit = 2;

$posts = $this->get_youtube_posts($limit);
if(!$posts || empty($posts))
wp_die();
foreach ($posts as $post) {
global $yt_post;
$yt_post = $post;
get_template_part('content','youtube');
}
wp_die();
}

}

0 comments on commit 5fdd91e

Please sign in to comment.