Permalink
Browse files

front-end importing of tweets from admin bar

  • Loading branch information...
alexkingorg committed Apr 13, 2012
1 parent 182331c commit cd347654fe3eaae54bebaecc16bbf3942006eb37
Showing with 103 additions and 2 deletions.
  1. +45 −1 assets/social.js
  2. +58 −1 social.php
View
@@ -288,7 +288,7 @@
/**
* Manual Aggregation
*/
- var $social_comments_adminbar_item = $('#wp-admin-bar-social_find_comments');
+ var $social_comments_adminbar_item = $('#wp-admin-bar-social-find-comments');
if ($social_comments_adminbar_item.size()) {
var $social_spinner = $social_comments_adminbar_item.find('.social-aggregation-spinner');
var $social_aggregation = $('#social_aggregation');
@@ -369,6 +369,50 @@
}
});
}
+ $('#wp-admin-bar-social-add-tweet-by-url a').each(function() {
+ $form = $(this).find('form');
+ $form.data('running-import', false).keydown(function(e) {
+ e.stopPropagation();
+ }).submit(function() {
+ if (!$(this).data('running-import')) {
+ var $this = $(this),
+ $inputs = $this.find('input');
+ $this.data('running-import', true);
+ $inputs.attr('disabled', 'disabled');
+
+ var $loading = $('<div class="loading"></div>')
+ .height($this.height())
+ .width($this.width());
+ $this.hide().closest('li')
+ .find('.msg').remove().end()
+ .end()
+ .after($loading);
+
+ $.get($this.attr('action'), {
+ url: $('input[name=url]').val()
+ }, function(response) {
+ var msg = msgClass = '';
+ switch (response) {
+ case 'protected':
+ case 'invalid':
+ msg = socialAdminBarMsgs[response];
+ msgClass = ' error';
+ break;
+ default:
+ msg = socialAdminBarMsgs['success'];
+ }
+ $loading.remove();
+ $this.data('running-import', false).show()
+ .after('<p class="msg' + msgClass + '">' + msg + '</p>');
+ $inputs.removeAttr('disabled').filter(':text').val('').focus();
+ });
+ }
+ return false;
+ }).appendTo($(this).closest('li'));
+ }).click(function(e) {
+ $(this).hide().closest('li').find('form').show().find(':text').focus().select();
+ return false;
+ });
/**
* Twitter @Anywhere
View
@@ -1678,7 +1678,7 @@ public function admin_bar_menu() {
) {
$wp_admin_bar->add_menu(array(
'parent' => 'comments',
- 'id' => 'social_find_comments',
+ 'id' => 'social-find-comments',
'title' => __('Find Social Comments', 'social')
.'<span class="social-aggregation-spinner" style="display: none;">&nbsp;(
<span class="social-dot dot-active">.</span>
@@ -1687,6 +1687,16 @@ public function admin_bar_menu() {
)</span>',
'href' => esc_url(wp_nonce_url(admin_url('index.php?social_controller=aggregation&social_action=run&post_id='.$current_object->ID), 'run')),
));
+ $wp_admin_bar->add_menu(array(
+ 'parent' => 'comments',
+ 'id' => 'social-add-tweet-by-url',
+ 'title' => __('Add Tweet by URL', 'social')
+ .'<form class="social-add-tweet" style="display: none;" method="get" action="'.esc_url(wp_nonce_url(admin_url('index.php?social_controller=import&social_action=from_url&social_service=twitter&post_id='.$current_object->ID), 'from_url')).'">
+ <input type="text" size="20" name="url" value="" autocomplete="off" />
+ <input type="submit" name="social-add-tweet-button" name="social-add-tweet-button" value="'.__('Add Tweet by URL', 'social').'" />
+ </form>',
+ 'href' => esc_url(get_edit_post_link($current_object->ID)),
+ ));
}
}
@@ -1700,10 +1710,56 @@ function admin_bar_footer_css() {
#wpadminbar .social-aggregation-spinner .dot-active {
font-weight: bold;
}
+#wpadminbar #wp-admin-bar-social-add-tweet-by-url form {
+ display: block;
+ line-height: 100%;
+ margin: 0;
+ padding: 5px;
+}
+#wpadminbar #wp-admin-bar-social-add-tweet-by-url input {
+ color: #333;
+ font-size: 11px;
+ font-weight: normal;
+ line-height: 1;
+ margin-bottom: 3px;
+ padding: 3px;
+ text-shadow: none;
+ width: 90%;
+}
+#wpadminbar #wp-admin-bar-social-add-tweet-by-url input[type="submit"] {
+ margin: 0;
+}
+#wpadminbar #wp-admin-bar-social-add-tweet-by-url .loading {
+ background: url(<?php echo admin_url('images/wpspin_light.gif'); ?>) center center no-repeat;
+}
+#wpadminbar #wp-admin-bar-social-add-tweet-by-url p.msg {
+ color: #333;
+ font-size: 12px;
+ font-weight: normal;
+ margin: 0;
+ padding: 0;
+ text-align: center;
+ text-shadow: none;
+}
+#wpadminbar #wp-admin-bar-social-add-tweet-by-url p.error {
+ color: #900;
+}
</style>
<?php
}
+ function admin_bar_footer_js() {
+?>
+<script type="text/javascript">
+var socialAdminBarMsgs = {
+ 'protected': '<?php echo esc_js(__('Protected Tweet', 'social')); ?>',
+ 'invalid': '<?php echo esc_js(__('Invalid URL', 'social')); ?>',
+ 'success': '<?php echo esc_js(__('Tweet Imported!', 'social')); ?>'
+};
+</script>
+<?php
+ }
+
/**
* Runs the upgrade only if the installed version is older than the current version.
*
@@ -2065,6 +2121,7 @@ function social_wpdb_escape($str) {
add_action('admin_enqueue_scripts', array($social, 'admin_enqueue_assets'));
add_action('admin_bar_menu', array($social, 'admin_bar_menu'), 95);
add_action('wp_after_admin_bar_render', array($social, 'admin_bar_footer_css'));
+add_action('wp_after_admin_bar_render', array($social, 'admin_bar_footer_js'));
add_action('set_user_role', array($social, 'set_user_role'), 10, 2);
add_filter('social_settings_save', array('Social_Service_Facebook', 'social_settings_save'));

0 comments on commit cd34765

Please sign in to comment.