Skip to content

Instantly share code, notes, and snippets.

@tomslominski
Created April 8, 2015 17:42
Show Gist options
  • Save tomslominski/f67d34af7bed0510eda7 to your computer and use it in GitHub Desktop.
Save tomslominski/f67d34af7bed0510eda7 to your computer and use it in GitHub Desktop.
Changing the intents in the DevBuddy Twitter plugin
/*
Changing intents in Twitter plugin
*/
if ( class_exists( 'DB_Twitter_Feed' ) ) {
function siteName_twitter_template_tag( $feed_config = NULL ) {
// Configuration validity checks are performed on instantiation
$the_feed = new DB_Twitter_Feed( $feed_config );
$url_data = array(
'tw' => $the_feed->tw,
'search' => $the_feed->search,
'intent' => $the_feed->intent
);
$the_feed->html = new siteName_Twitter_HTML( $the_feed->options, $url_data );
// We only want to talk to Twitter when our cache is on empty
if ( ! $the_feed->is_cached ) {
// Makes a request to Twitter for tweet data based on $the_feed->options
$the_feed->retrieve_feed_data();
// After attempting data retrieval, check for errors
// Feel free to change the error message
if ( $the_feed->has_errors() ) {
$the_feed->output .= '<p>We&rsquo;re unable to show tweets at this time.</p>';
// Uncomment the following code to see the details of errors
/*
$the_feed->output .= '<ul>';
foreach ( $the_feed->errors as $error ) {
$the_feed->output .= '<li>&ldquo;'.$error->message.' [error code: '.$error->code.']&rdquo;</li>';
}
$the_feed->output .= '</ul>';
$the_feed->output .= '<p>More information on errors <a href="https://dev.twitter.com/docs/error-codes-responses" target="_blank" title="Twitter API Error Codes and Responses">here</a>.</p>';
*/
// Then check for an empty timeline
// Feel free to change the notification message
} elseif( $the_feed->is_empty() ) {
$the_feed->output .= '<p>Looks like this feed is completely empty! Perhaps try a different user or search term.</p>';
// If all is well we can get to HTML renderin'
} else {
// START The Tweet list
$the_feed->output .= '<div class="tweets">';
foreach ( $the_feed->feed_data as $tweet ) {
/* Parse the tweet data and hand that data over to the HTML
class which will write the HTML code for us */
$the_feed->html->set( $the_feed->parse_tweet_data( $tweet ) );
/* Below is the default HTML layout.
The HTML class writes the actual HTML, just move the
parts around as needed.
If you do move things around, be sure to update your
stylesheet accordingly.
NOTE: The primary and secondary meta HTML parts are
merely generic div elements used as content wrappers.
*********************************************************/
// START Rendering the Tweet's HTML (outer tweet wrapper)
$the_feed->output .= $the_feed->html->open_tweet();
// START Tweet content (inner tweet wrapper)
$the_feed->output .= $the_feed->html->open_tweet_content();
// START Tweeter's display picture
$the_feed->output .= $the_feed->html->tweet_display_pic();
// END Tweeter's display picture
// START Tweet user info
$the_feed->output .= $the_feed->html->open_tweet_primary_meta();
$the_feed->output .= $the_feed->html->tweet_display_name_link();
$the_feed->output .= $the_feed->html->close_tweet_primary_meta();
// END Tweet user info
// START Actual tweet
$the_feed->output .= $the_feed->html->tweet_text();
// END Actual tweet
// START Tweet meta data
$the_feed->output .= $the_feed->html->open_tweet_secondary_meta();
$the_feed->output .= $the_feed->html->tweet_date();
$the_feed->output .= $the_feed->html->tweet_retweeted();
$the_feed->output .= $the_feed->html->tweet_intents();
$the_feed->output .= $the_feed->html->close_tweet_secondary_meta();
// END Tweet meta data
$the_feed->output .= $the_feed->html->close_tweet_content();
// END Tweet content
$the_feed->output .= $the_feed->html->close_tweet();
// END Rendering Tweet's HTML
} // END looping through tweet data
$the_feed->output .= '</div>';
// END The Tweet list
// Cache the output
$the_feed->cache_output( $the_feed->options['cache_hours'] );
}
} // END cache check
/* WP needs shortcode called content to be returned
rather than echoed, which is where the
$is_shortcode_called property comes in */
if ( $the_feed->is_shortcode_called ) {
return $the_feed->output;
} else {
echo $the_feed->output;
}
}
}
add_shortcode( 'siteName-twitter-widget', 'siteName_twitter_shortcode_function' );
function siteName_twitter_shortcode_function( $given_atts ) {
// The default options are set in the plugin settings
$default_atts =
array(
'feed_type' => NULL,
'user' => NULL,
'search_term' => NULL,
'count' => NULL,
'exclude_replies' => NULL,
'default_styling' => NULL,
'cache_hours' => NULL,
'clear_cache' => NULL,
'oauth_access_token' => NULL,
'oauth_access_token_secret' => NULL,
'consumer_key' => NULL,
'consumer_secret' => NULL
);
extract(
shortcode_atts( $default_atts, $given_atts )
);
$feed_config =
array(
'feed_type' => $feed_type,
'user' => $user,
'search_term' => $search_term,
'count' => $count,
'exclude_replies' => $exclude_replies,
'default_styling' => $default_styling,
'cache_hours' => $cache_hours,
'clear_cache' => $clear_cache,
'oauth_access_token' => $oauth_access_token,
'oauth_access_token_secret' => $oauth_access_token_secret,
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'is_shortcode_called' => TRUE
);
// Custom template tag
return siteName_twitter_template_tag( $feed_config );
}
if ( class_exists( 'DB_Twitter_HTML' ) ) {
class siteName_Twitter_HTML extends DB_Twitter_HTML {
/**
* Returns actions that end users can use to interact with the tweet: reply, retweet, and favourite
*
* @access public
* @return string
*/
public function tweet_intents() {
$output = '<div class="tweet_intents">';
// START Reply intent
$output .= '<a href="'.$this->intent.'tweet?in_reply_to='.$this->tweet['id'].'" title="Reply to this tweet" target="_blank" class="tweet_intent_reply">';
$output .= '<svg class="tweet_intent_icon tweet_intent_icon_reply"><use xlink:href="#icon-twitter-reply" /></svg>';
$output .= '</a>';
// END Reply intent
// START Retweet intent
$output .= '<a href="'.$this->intent.'retweet?tweet_id='.$this->tweet['id'].'" title="Retweet this tweet" target="_blank" class="tweet_intent_retweet">';
$output .= '<svg class="tweet_intent_icon tweet_intent_icon_retweet"><use xlink:href="#icon-twitter-retweet" /></svg>';
$output .= '</a>';
// END Retweet intent
// START Favourite intent
$output .= '<a href="'.$this->intent.'favorite?tweet_id='.$this->tweet['id'].'" title="Favourite this tweet" target="_blank" class="tweet_intent_favourite">';
$output .= '<svg class="tweet_intent_icon tweet_intent_icon_favourite"><use xlink:href="#icon-twitter-favourite" /></svg>';
$output .= '</a>';
// END Favourite intent
$output .= '</div>';
// END Tweet intents
return $output;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment