Skip to content

Commit

Permalink
issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgimenez committed Feb 26, 2019
1 parent e42e4ca commit c938e1f
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 12 deletions.
Binary file modified assets/images/facebook-icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/instagram-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/youtube-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions assets/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ jQuery(document).ready(function($) {
$( '#youtube-content' ).html( response );
});

var data_insta = {
action: 'csem_get_last_socials',
network: 'instagram'
}
$.get( ajax.url, data_insta, function( response ) {
$( '#instagram-content' ).html( response );
});

});
37 changes: 33 additions & 4 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,33 +272,62 @@ function csem_coletivo_customize_after_register( $wp_customize ) {
)
);
// Textarea redes
$wp_customize->add_setting( coletivo_add_settings('coletivo_ultimos_sociais_yt'),
$wp_customize->add_setting( coletivo_add_settings('coletivo_ultimos_sociais_yt_url'),
array(
'sanitize_callback' => 'sanitize_text_field',
'default' => '',
)
);
$wp_customize->add_control( coletivo_add_settings('coletivo_ultimos_sociais_yt'),
$wp_customize->add_control( coletivo_add_settings('coletivo_ultimos_sociais_yt_url'),
array(
'label' => esc_html__('URL do YouTube', 'coletivo'),
'section' => 'coletivo_ultimos_sociais_content',
'description' => '',
)
);

$wp_customize->add_setting( coletivo_add_settings('coletivo_ultimos_sociais_instagram'),
$wp_customize->add_setting( coletivo_add_settings('coletivo_ultimos_sociais_yt_id'),
array(
'sanitize_callback' => 'sanitize_text_field',
'default' => '',
)
);
$wp_customize->add_control( coletivo_add_settings('coletivo_ultimos_sociais_instagram'),
$wp_customize->add_control( coletivo_add_settings('coletivo_ultimos_sociais_yt_id'),
array(
'label' => esc_html__('ID do Canal no Youtube', 'coletivo'),
'section' => 'coletivo_ultimos_sociais_content',
'description' => 'Verique o ID pelo site: https://commentpicker.com/youtube-channel-id.php',
)
);


$wp_customize->add_setting( coletivo_add_settings('coletivo_ultimos_sociais_instagram_url'),
array(
'sanitize_callback' => 'sanitize_text_field',
'default' => '',
)
);
$wp_customize->add_control( coletivo_add_settings('coletivo_ultimos_sociais_instagram_url'),
array(
'label' => esc_html__('URL do Instagram', 'coletivo'),
'section' => 'coletivo_ultimos_sociais_content',
'description' => '',
)
);
$wp_customize->add_setting( coletivo_add_settings('coletivo_ultimos_sociais_instagram_token'),
array(
'sanitize_callback' => 'sanitize_text_field',
'default' => '',
)
);
$wp_customize->add_control( coletivo_add_settings('coletivo_ultimos_sociais_instagram_token'),
array(
'label' => esc_html__('Token de acesso Instagram', 'coletivo'),
'section' => 'coletivo_ultimos_sociais_content',
'description' => 'Gere o token pelo site: https://instagram.pixelunion.net/',
)
);

$wp_customize->add_setting( coletivo_add_settings('coletivo_ultimos_sociais_fb'),
array(
'sanitize_callback' => 'sanitize_text_field',
Expand Down
31 changes: 28 additions & 3 deletions inc/class-load-last-post-social-networks.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,39 @@ public function do_ajax() {
get_template_part( 'section-parts/each-social' );
wp_die();
}
if ( 'instagram' === $_REQUEST[ 'network' ] ) {
$this->get_instagram_feed();
get_template_part( 'section-parts/each-social' );
wp_die();
}
}
private function get_instagram_feed() {
if ( false !== get_transient( 'csem_instagram_transient' ) ) {
$this->transient = get_transient( 'csem_instagram_transient' );
$this->image = $this->transient[ 'image' ];
return;
}
$token = coletivo_get_theme_mod( 'coletivo_ultimos_sociais_instagram_token' );
if ( ! $token ) {
wp_die( 'Falta o token do instagram' );
return;
}
$instagram_api_url = 'https://api.instagram.com/v1/users/self/media/recent?access_token=' . $token;
$response = file_get_contents( $instagram_api_url );
$json = json_decode( $response );
//var_dump( $response );
$this->image = $json->data[0]->images->standard_resolution->url;
$this->transient = array( 'image' => $this->image );
set_transient( 'csem_instagram_transient', $this->transient, $this->transient_time );
}

private function get_youtube_feed() {
if ( false !== get_transient( 'csem_yt_transient' ) ) {
$this->transient = get_transient( 'csem_yt_transient' );
$this->image = $this->transient[ 'image' ];
return;
}
$channel_id = 'UClnwaE2l2FG0eKWR9Rc610A';
$channel_id = coletivo_get_theme_mod( 'coletivo_ultimos_sociais_yt_id', 'UClnwaE2l2FG0eKWR9Rc610A' );
$youtube_feed_url = 'https://www.youtube.com/feeds/videos.xml?channel_id=' . $channel_id;
$response = file_get_contents( $youtube_feed_url );
//var_dump( $response );
Expand Down Expand Up @@ -116,8 +141,8 @@ private function get_facebook_feed() {
//var_dump( $response->data[0]->images[6] );
//var_dump("https://graph.facebook.com/{$feed}/photos/uploaded/?{$authentication}&limit={$maximum}&fields=images,link");
//wp_die();
$this->image = $response->data[0]->images[6]->source;
$this->transient = array( 'image' => $this->image );
$this->image = $response->data[0]->images[6]->source
; $this->transient = array( 'image' => $this->image );
set_transient( 'csem_fb_transient', $this->transient, $this->transient_time );
}
/**
Expand Down
22 changes: 17 additions & 5 deletions section-parts/each-social.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
/**
* Conteúdo de cada uma das redes (ultimos-posts)
*/
Expand All @@ -12,16 +12,28 @@
$link = '#';
if ( 'facebook' === $_REQUEST[ 'network'] ) {
$link = coletivo_get_theme_mod( 'coletivo_ultimos_sociais_fb_url' );
$slug = str_replace( array( 'https://', 'http://', 'facebook.com', 'fb.com' ), '', $link );
$slug = str_replace( array( 'https://', 'http://', 'www.', 'facebook.com', 'fb.com', '/'), '', $link );
$slug = '@' . $slug;
}
if ( 'instagram' === $_REQUEST[ 'network'] ) {
$link = coletivo_get_theme_mod( 'coletivo_ultimos_sociais_instagram_url' );
$slug = str_replace( array( 'https://', 'http://', 'www.', 'instagram.com', '/'), '', $link );
$slug = '@' . $slug;
}
if ( 'youtube' === $_REQUEST[ 'network'] ) {
$link = coletivo_get_theme_mod( 'coletivo_ultimos_sociais_yt_url' );
$slug = str_replace( array( 'https://', 'http://', 'www.', 'youtube.com', '/user/'), '', $link );
$slug = '/' . $slug;
}

?>
<div class="each-social wow slideInUp">
<a href="<?php echo esc_url( $link );?>">
<a href="<?php echo esc_url( $link );?>" target="_blank">
<span class="icon"></span>
<img src="<?php echo esc_url( $load_last_post_social_networks->image );?>" alt="<?php _e( 'Link para a página no Facebook', 'csem-theme');?>" />
<span class="social-icon"></span>
</a>
<a href="<?php echo esc_url( $link );?>" class="slug-link">
<a href="<?php echo esc_url( $link );?>" class="slug-link" target="_blank">
<?php echo $slug;?>
</a>
</div><!-- .each-social -->
</div><!-- .each-social -->
2 changes: 2 additions & 0 deletions section-parts/section-ultimos_sociais.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
</div><!-- #facebook-content.content-socials col-md-4 -->
<div class="content-socials col-md-4" id="youtube-content">
</div><!-- #youtube-content.content-socials col-md-4 -->
<div class="content-socials col-md-4" id="instagram-content">
</div><!-- #youtube-content.content-socials col-md-4 -->

</div>
</div>
Expand Down
40 changes: 40 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ body.home .hero-content-style1 h2.hero-large-text {
*/
.section-fazer-parte {
padding-top:0 !important;
padding-bottom: 0 !important;
}
.section-fazer-parte .container {
width:100%;
Expand Down Expand Up @@ -309,3 +310,42 @@ a#featuredpage {
clear: both;
}
}

.section-ultimos-sociais {
background-color:#444444;
background-image: url( 'assets/images/social-bg.png' );
background-repeat: no-repeat;
background-position: top center;
background-attachment: fixed;
}
.section-ultimos-sociais img {
width:256px;
height: 256px;
border-radius:50%;
border:10px solid #3c3c3c;
}
.section-ultimos-sociais a.slug-link {
width: 100%;
display: inline-block;
text-align: center;
color:white !important;
padding-top:15px;
}
.section-ultimos-sociais .each-social {
text-align: center;
}
.section-ultimos-sociais .each-social span.icon {
background-size: cover;
width:48px;
height:48px;
position: absolute;
}
.section-ultimos-sociais #youtube-content .each-social span.icon {
background-image: url( 'assets/images/youtube-icon.png' );
}
.section-ultimos-sociais #facebook-content .each-social span.icon {
background-image: url( 'assets/images/facebook-icon.png' );
}
.section-ultimos-sociais #instagram-content .each-social span.icon {
background-image: url( 'assets/images/instagram-icon.png' );
}

0 comments on commit c938e1f

Please sign in to comment.