Skip to content

Commit

Permalink
issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgimenez committed May 19, 2015
1 parent d78d984 commit 544b30c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
19 changes: 19 additions & 0 deletions assets/js/libs/twitter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
/*********************************************************************
* #### Twitter Post Fetcher v13.0 ####
* Coded by Jason Mayes 2015. A present to all the developers out there.
* www.jasonmayes.com
* Please keep this disclaimer with my code if you use it. Thanks. :-)
* Got feedback or questions, ask here:
* http://www.jasonmayes.com/projects/twitterApi/
* Github: https://github.com/jasonmayes/Twitter-Post-Fetcher
* Updates will be posted to this site.
*********************************************************************/
(function(w,n){"function"===typeof define&&define.amd?define([],n):"object"===typeof exports?module.exports=n():n()})(this,function(){function w(a){return a.replace(/<b[^>]*>(.*?)<\/b>/gi,function(a,g){return g}).replace(/class=".*?"|data-query-source=".*?"|dir=".*?"|rel=".*?"/gi,"")}function n(a){a=a.getElementsByTagName("a");for(var c=a.length-1;0<=c;c--)a[c].setAttribute("target","_blank")}function m(a,c){for(var g=[],f=new RegExp("(^| )"+c+"( |$)"),h=a.getElementsByTagName("*"),b=0,k=h.length;b<
k;b++)f.test(h[b].className)&&g.push(h[b]);return g}var B="",k=20,C=!0,u=[],x=!1,v=!0,q=!0,y=null,z=!0,D=!0,A=null,E=!0,F=!1,r=!0,G=!0,H={fetch:function(a){void 0===a.maxTweets&&(a.maxTweets=20);void 0===a.enableLinks&&(a.enableLinks=!0);void 0===a.showUser&&(a.showUser=!0);void 0===a.showTime&&(a.showTime=!0);void 0===a.dateFunction&&(a.dateFunction="default");void 0===a.showRetweet&&(a.showRetweet=!0);void 0===a.customCallback&&(a.customCallback=null);void 0===a.showInteraction&&(a.showInteraction=
!0);void 0===a.showImages&&(a.showImages=!1);void 0===a.linksInNewWindow&&(a.linksInNewWindow=!0);void 0===a.showPermalinks&&(a.showPermalinks=!0);if(x)u.push(a);else{x=!0;B=a.domId;k=a.maxTweets;C=a.enableLinks;q=a.showUser;v=a.showTime;D=a.showRetweet;y=a.dateFunction;A=a.customCallback;E=a.showInteraction;F=a.showImages;r=a.linksInNewWindow;G=a.showPermalinks;var c=document.createElement("script");c.type="text/javascript";c.src="https://cdn.syndication.twimg.com/widgets/timelines/"+a.id+"?&lang="+(a.lang||
"en")+"&callback=twitterFetcher.callback&suppress_response_codes=true&rnd="+Math.random();document.getElementsByTagName("head")[0].appendChild(c)}},callback:function(a){var c=document.createElement("div");c.innerHTML=a.body;"undefined"===typeof c.getElementsByClassName&&(z=!1);a=[];var g=[],f=[],h=[],b=[],p=[],t=[],e=0;if(z)for(c=c.getElementsByClassName("tweet");e<c.length;){0<c[e].getElementsByClassName("retweet-credit").length?b.push(!0):b.push(!1);if(!b[e]||b[e]&&D)a.push(c[e].getElementsByClassName("e-entry-title")[0]),
p.push(c[e].getAttribute("data-tweet-id")),g.push(c[e].getElementsByClassName("p-author")[0]),f.push(c[e].getElementsByClassName("dt-updated")[0]),t.push(c[e].getElementsByClassName("permalink")[0]),void 0!==c[e].getElementsByClassName("inline-media")[0]?h.push(c[e].getElementsByClassName("inline-media")[0]):h.push(void 0);e++}else for(c=m(c,"tweet");e<c.length;)a.push(m(c[e],"e-entry-title")[0]),p.push(c[e].getAttribute("data-tweet-id")),g.push(m(c[e],"p-author")[0]),f.push(m(c[e],"dt-updated")[0]),
t.push(c[e].getElementsByClassName("permalink")[0]),void 0!==m(c[e],"inline-media")[0]?h.push(m(c[e],"inline-media")[0]):h.push(void 0),0<m(c[e],"retweet-credit").length?b.push(!0):b.push(!1),e++;a.length>k&&(a.splice(k,a.length-k),g.splice(k,g.length-k),f.splice(k,f.length-k),b.splice(k,b.length-k),h.splice(k,h.length-k),t.splice(k,t.length-k));c=[];e=a.length;for(b=0;b<e;){if("string"!==typeof y){var d=f[b].getAttribute("datetime"),l=new Date(f[b].getAttribute("datetime").replace(/-/g,"/").replace("T",
" ").split("+")[0]),d=y(l,d);f[b].setAttribute("aria-label",d);if(a[b].innerText)if(z)f[b].innerText=d;else{var l=document.createElement("p"),I=document.createTextNode(d);l.appendChild(I);l.setAttribute("aria-label",d);f[b]=l}else f[b].textContent=d}d="";C?(r&&(n(a[b]),q&&n(g[b])),q&&(d+='<div class="user">'+w(g[b].innerHTML)+"</div>"),d+='<p class="tweet">'+w(a[b].innerHTML)+"</p>",v&&(d=G?d+('<p class="timePosted"><a href="'+t[b]+'">'+f[b].getAttribute("aria-label")+"</a></p>"):d+('<p class="timePosted">'+
f[b].getAttribute("aria-label")+"</p>"))):a[b].innerText?(q&&(d+='<p class="user">'+g[b].innerText+"</p>"),d+='<p class="tweet">'+a[b].innerText+"</p>",v&&(d+='<p class="timePosted">'+f[b].innerText+"</p>")):(q&&(d+='<p class="user">'+g[b].textContent+"</p>"),d+='<p class="tweet">'+a[b].textContent+"</p>",v&&(d+='<p class="timePosted">'+f[b].textContent+"</p>"));E&&(d+='<p class="interact"><a href="https://twitter.com/intent/tweet?in_reply_to='+p[b]+'" class="twitter_reply_icon"'+(r?' target="_blank">':
">")+'Reply</a><a href="https://twitter.com/intent/retweet?tweet_id='+p[b]+'" class="twitter_retweet_icon"'+(r?' target="_blank">':">")+'Retweet</a><a href="https://twitter.com/intent/favorite?tweet_id='+p[b]+'" class="twitter_fav_icon"'+(r?' target="_blank">':">")+"Favorite</a></p>");F&&void 0!==h[b]&&(l=h[b],void 0!==l?(l=l.innerHTML.match(/data-srcset="([A-z0-9%_\.-]+)/i)[0],l=decodeURIComponent(l).split('"')[1]):l=void 0,d+='<div class="media"><img src="'+l+'" alt="Image from tweet" /></div>');
c.push(d);b++}if(null===A){a=c.length;g=0;f=document.getElementById(B);for(h="<ul>";g<a;)h+="<li>"+c[g]+"</li>",g++;f.innerHTML=h+"</ul>"}else A(c);x=!1;0<u.length&&(H.fetch(u[0]),u.splice(0,1))}};return window.twitterFetcher=H});
jQuery(document).ready(function($) {
// fitVids.
$( '.entry-content' ).fitVids();
Expand Down Expand Up @@ -234,5 +254,16 @@ jQuery(document).ready(function($) {
$.post(odin_main.ajaxurl, data, function(response) {
$('#facebook-feed').html(response);
});

var config1 = {
"id": odin_main.twitter_widget_id,
"domId": 'twitter-feed',
"maxTweets": 2,
"enableLinks": true,
"showTime": false,
"showRetweet": false,
"showInteraction": false
};
twitterFetcher.fetch(config1);
});

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" href="<?php echo esc_url($fb_post['link']);?>">
<a class="social-feed col-md-12 animated tada" 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 @@ -56,6 +56,7 @@
case 'social':
$entre = '<div class="col-md-4 social-feed pull-right">';
$entre .= '<div id="facebook-feed"></div>';
$entre .= '<div id="twitter-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
5 changes: 4 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ function odin_enqueue_scripts() {


// Main jQuery.
$options = get_option('social');

wp_enqueue_script( 'twitter-api-js', $template_url . '/assets/js/libs/twitter.min.js', array(), null, true );
wp_enqueue_script( 'odin-main', $template_url . '/assets/js/main.js', array(), null, true );
wp_localize_script( 'odin-main', 'odin_main', array('ajaxurl' => admin_url( 'admin-ajax.php' )) );
wp_localize_script( 'odin-main', 'odin_main', array('ajaxurl' => admin_url( 'admin-ajax.php' ), 'twitter_widget_id' => $options['twitter_widget_id'] ) );


// Grunt watch livereload in the browser.
Expand Down
18 changes: 18 additions & 0 deletions inc/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@
'default' => '', // Opcional (deve ser o id de uma imagem em mídia)
),
)
),
'social_twitter_section' => array(
'tab' => 'social', // Sessão da aba odin_general
'title' => __( 'Opções do Twitter', 'odin' ),
'fields' => array(
array(
'id' => 'twitter_widget_id', // Obrigatório
'label' => __( 'ID do Widget do Twitter', 'odin' ), // Obrigatório
'type' => 'text', // Obrigatório
'default' => '', // Opcional (deve ser o id de uma imagem em mídia)
),
array(
'id' => 'twitter_url', // Obrigatório
'label' => __( 'URL da página no Twitter', 'odin' ), // Obrigatório
'type' => 'text', // Obrigatório
'default' => '', // Opcional (deve ser o id de uma imagem em mídia)
),
)
),
)
);
8 changes: 1 addition & 7 deletions inc/social-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function get_facebook_posts($limit = 2){
),
$this->args['facebook_api_url']
);
$request_url = esc_url($request_url);
$request_url = esc_url_raw($request_url);
$request = wp_remote_get( $request_url );
$response = json_decode( wp_remote_retrieve_body( $request ), true );
return $response['data'];
Expand All @@ -26,17 +26,11 @@ public function do_ajax_facebook(){

if(!$posts || empty($posts))
wp_die();
$i = 1;
foreach ($posts as $post) {
if($i > $limit)
break;

global $fb_post;
$fb_post = $post;
get_template_part('content','facebook');
$i++;
}
wp_die();
}

}

0 comments on commit 544b30c

Please sign in to comment.