Skip to content

Commit

Permalink
gracefully handle lack of tweet data
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkingorg committed Dec 12, 2011
1 parent a886529 commit 13e8167
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
20 changes: 10 additions & 10 deletions classes/aktt.php
Expand Up @@ -25,7 +25,7 @@ class AKTT {
static function init() {
self::$enabled = class_exists('Social');
if (!self::$enabled) {
self::add_admin_notice('error', sprintf(__('Twitter Tools relies on the <a href="%s">Social plugin</a>, please install this plugin.', 'twitter-tools'), 'http://wordpress.org/extend/plugins/social/'));
self::add_admin_notice(sprintf(__('Twitter Tools relies on the <a href="%s">Social plugin</a>, please install this plugin.', 'twitter-tools'), 'http://wordpress.org/extend/plugins/social/'), 'error');
return;
}

Expand Down Expand Up @@ -77,8 +77,8 @@ static function set_default_settings() {
'0' => __('No', 'twitter-tools')
);
self::$settings = array(
'enable_admin_ui' => array(
'name' => 'enable_admin_ui',
'tweet_admin_ui' => array(
'name' => 'tweet_admin_ui',
'value' => 1,
'label' => __('Show admin screens for tweets', 'twitter-tools'),
'type' => 'radio',
Expand Down Expand Up @@ -118,11 +118,11 @@ static function set_default_settings() {
/**
* Append a message of a certain type to the admin notices.
*
* @param string $type
* @param string $msg
* @param string $type
* @return void
*/
static function add_admin_notice($type, $msg) {
static function add_admin_notice($msg, $type = 'updated') {
self::$admin_notices[] = array(
'type' => $type == 'error' ? $type : 'updated', // If it's not an error, set it to updated
'msg' => $msg
Expand Down Expand Up @@ -164,7 +164,7 @@ static function register_post_type() {
'editor',
),
'public' => (bool) self::option('tweet_visibility'),
'show_ui' => (bool) self::option('enable_admin_ui'),
'show_ui' => (bool) self::option('tweet_admin_ui'),
'rewrite' => array(
'slug' => 'tweets',
'with_front' => false
Expand Down Expand Up @@ -379,9 +379,6 @@ static function the_post($post) {
if ($raw_data = get_post_meta($post->ID, '_aktt_tweet_raw_data', true)) {
$post->tweet = new AKTT_Tweet(json_decode($raw_data));
}
else {
$post->tweet = new AKTT_Tweet(false);
}
}
return $post;
}
Expand Down Expand Up @@ -919,7 +916,7 @@ function admin_controller(){
self::import_tweets();
wp_redirect(add_query_arg(array(
'page' => self::$menu_page_slug,
'tweets_updated' => '1'),
'aktt_action' => 'tweets_updated'),
admin_url('options-general.php')
));
break;
Expand Down Expand Up @@ -951,6 +948,9 @@ function admin_controller(){
));
die();
break;
case 'tweets_updated':
self::add_admin_notice(__('Tweets are downloading...', 'twitter-tools'));
break;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion classes/aktt_tweet.php
Expand Up @@ -332,7 +332,6 @@ function link_entities() {
);
}
ksort($entities);

$str = $this->content();
$diff = 0;
foreach ($entities as $entity) {
Expand Down
2 changes: 1 addition & 1 deletion views/admin.php
Expand Up @@ -84,7 +84,7 @@

<?php
if (AKTT::$enabled) {
if ($upgrade_needed || 1) {
if ($upgrade_needed) {
?>
<div class="aktt-upgrade-needed">
<h3><?php _e('Upgrade Needed!', 'twitter-tools'); ?></h3>
Expand Down
8 changes: 6 additions & 2 deletions views/tweet.php
Expand Up @@ -7,10 +7,14 @@

echo wptexturize($content);

if (isset($tweet->tweet) && $tweet->tweet->is_reply()) {
if (isset($tweet->tweet)) {
if ($tweet->tweet->is_reply()) {
?>
<a href="<?php echo esc_url(AKTT::status_url($tweet->tweet->reply_screen_name(), $tweet->tweet->reply_id())); ?>" class="aktt_tweet_reply"><?php printf(__('in reply to %s', 'twitter-tools'), esc_html($tweet->tweet->reply_screen_name())); ?></a>
<?php
}
}
?>
<a href="<?php echo esc_url($tweet->tweet->status_url()); ?>" class="aktt_tweet_time"><?php echo sprintf(__('%s ago', 'twitter-tools'), human_time_diff(strtotime($tweet->post_date_gmt))); ?></a>
<?php
}
?>

0 comments on commit 13e8167

Please sign in to comment.