Skip to content

Commit

Permalink
Merge branch 'feature/tweet-reply-31' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkingorg committed Apr 26, 2012
2 parents e7eec86 + 9b36378 commit b2beb0d
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 38 deletions.
27 changes: 23 additions & 4 deletions assets/admin.css
Expand Up @@ -667,7 +667,7 @@
padding-left: 20px;
position: relative;
}
.broadcast-interstitial li.account .broadcast-edit input {
.broadcast-interstitial li.account .broadcast-edit input[type="checkbox"] {
left: -5px;
position: absolute;
top: 7px;
Expand All @@ -680,8 +680,8 @@
padding: 6px 7px;
width: 90%;
}
.broadcast-interstitial li.account .broadcast-edit a.edit {
display: block;
.broadcast-interstitial li.account .broadcast-edit a.edit,
.broadcast-interstitial li.account .broadcast-edit a.tweet-reply-link {
font-size: 12px;
line-height: 100%;
opacity: .3;
Expand All @@ -699,6 +699,22 @@
.broadcast-interstitial li.account.facebook .broadcast-edit textarea {
height: 180px;
}
.broadcast-interstitial li.account .broadcast-edit .tweet-reply-fields {
display: none;
opacity: .3;
padding: 5px 0 0 7px;
}
.broadcast-interstitial li.account .broadcast-edit .tweet-reply-fields label {
color: #666;
font-size: 11px;
height: 15px;
position: relative;
top: 0;
}
.broadcast-interstitial li.account .broadcast-edit .tweet-reply-fields input {
padding: 5px;
width: 85%;
}
.broadcast-interstitial li.account .broadcast-edit .counter {
color: #999;
display: none;
Expand All @@ -715,9 +731,12 @@
}
.broadcast-interstitial li.account .checked .readonly,
.broadcast-interstitial li.account .checked a.edit,
.broadcast-interstitial li.account .checked a.tweet-reply-link,
.broadcast-interstitial li.account .checked textarea,
.broadcast-interstitial li.account .checked .tweet-reply-fields,
.broadcast-interstitial li.account .checked .counter,
.broadcast-interstitial li.account .broadcast-edit:hover a.edit {
.broadcast-interstitial li.account .broadcast-edit:hover a.edit,
.broadcast-interstitial li.account .broadcast-edit:hover a.tweet-reply-link {
opacity: 1;
}
.broadcast-interstitial li.account .broadcast-edit.edit .readonly,
Expand Down
12 changes: 9 additions & 3 deletions assets/admin.js
Expand Up @@ -162,9 +162,8 @@

$('.broadcast-interstitial .broadcast-edit a.edit').click(function(e) {
$(this).closest('.broadcast-edit').addClass('edit')
.find('input[type="checkbox"]').prop('checked', true).end()
.find('textarea').focus().select().end()
.find('input[type="checkbox"]').change();
.find('input[type="checkbox"]').prop('checked', true).change().end()
.find('textarea').focus().select();
e.preventDefault();
});

Expand All @@ -187,6 +186,13 @@
}
$counter.removeClass('maxlength-remaining-short').addClass(diffClass).html(diff);
}).change();

$('.broadcast-interstitial .broadcast-edit a.tweet-reply-link').click(function() {
$(this).hide().closest('.broadcast-edit')
.find('input[type="checkbox"]').prop('checked', true).change().end()
.find('.tweet-reply-fields').show().find(':input').focus();
e.preventDefault();
});

$('body.clean ul.accounts li.proto .broadcast-edit textarea').on('keyup change click focus', function() {
var val = $(this).val();
Expand Down
18 changes: 14 additions & 4 deletions lib/social/controller/broadcast.php
Expand Up @@ -30,12 +30,11 @@ public function action_options() {
$service_accounts = $this->request->post('social_accounts');
$account_content = $this->request->post('social_account_content');

$account_content_meta = array();
$account_content_meta = $account_service_meta = array();
foreach ($services as $key => $service) {
if (count($service->accounts())) {
if (isset($service_accounts[$key])) {
$accounts_selected = true;

foreach ($service_accounts[$key] as $account_id) {
$account_id = explode('|', $account_id);
if (!isset($account_content[$key][$account_id[0]]) or empty($account_content[$key][$account_id[0]])) {
Expand All @@ -52,10 +51,12 @@ public function action_options() {
}
else {
if (!isset($account_content_meta[$key])) {
$account_content_meta[$key] = array();
$account_content_meta[$key] = $account_service_meta[$key] = array();
}

$account_content_meta[$key][$account_id[0]] = $account_content[$key][$account_id[0]];
// TODO
$account_service_meta[$key][$account_id[0]] = $service->get_broadcast_extras($account_id[0], $post);
}
}
}
Expand Down Expand Up @@ -156,6 +157,7 @@ public function action_options() {

// Store the content
update_post_meta($post->ID, '_social_broadcast_content', $account_content_meta);
update_post_meta($post->ID, '_social_broadcast_meta', $account_service_meta);
update_post_meta($post->ID, '_social_broadcast_accounts', $broadcast_accounts);

if (!in_array($this->request->post('social_action'), array('Schedule', 'Update'))) {
Expand Down Expand Up @@ -399,6 +401,10 @@ public function action_run($post_id = null) {
if (empty($account_content)) {
$account_content = array();
}
$account_meta = get_post_meta($post->ID, '_social_broadcast_meta', true);
if (empty($account_meta)) {
$account_meta = array();
}

Social::log('About to start broadcasting.');
foreach ($broadcast_accounts as $key => $accounts) {
Expand Down Expand Up @@ -434,6 +440,10 @@ public function action_run($post_id = null) {
if (isset($account_content[$key][$_account->id])) {
$message = $account_content[$key][$_account->id];
}
$args = array();
if (isset($account_meta[$key][$_account->id])) {
$args = $account_meta[$key][$_account->id];
}

if (!empty($message)) {
Social::log('Broadcasting to :username, account #:id. (:service)', array(
Expand All @@ -442,7 +452,7 @@ public function action_run($post_id = null) {
'service' => $service->title(),
));

$response = $service->broadcast($account, $message, array(), $post->ID);
$response = $service->broadcast($account, $message, $args, $post->ID);
if ($response !== false) {
if ($response->limit_reached()) {
if (!isset($errored_accounts[$key])) {
Expand Down
10 changes: 10 additions & 0 deletions lib/social/service.php
Expand Up @@ -762,4 +762,14 @@ public static function comment_types_meta() {
return array();
}

/**
* Any additional parameters that should be passed with a broadcast.
*
* @static
* @return array
*/
public function get_broadcast_extras($account_id, $post, $args = array()) {
return apply_filters($this->key().'_broadcast_extras', $args, $this, $account_id, $post);
}

} // End Social_Service
68 changes: 44 additions & 24 deletions lib/social/service/facebook.php
Expand Up @@ -35,6 +35,32 @@ public function request($account, $api, array $args = array(), $method = 'GET')
return parent::request($account, $api, $args, $method);
}

/**
* Any additional parameters that should be passed with a broadcast.
*
* @static
* @return array
*/
public function get_broadcast_extras($account_id, $post, $args = array()) {
if (get_post_format($post->ID) !== 'status') {
setup_postdata($post);
$link_args = array(
'link' => get_post_permalink($post->ID),
'title' => get_the_title($post->ID),
'description' => get_the_excerpt(),
);
if (function_exists('has_post_thumbnail') and has_post_thumbnail($post->ID)) {
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
$link_args = $link_args + array(
'picture' => $image[0],
);
}
wp_reset_postdata();
$args = $args + $link_args;
}
return parent::get_broadcast_extras($account_id, $post, $args);
}

/**
* Broadcasts the message to the specified account. Returns the broadcasted ID.
*
Expand Down Expand Up @@ -83,33 +109,27 @@ public function broadcast($account, $message, array $args = array(), $post_id =
}
}
}
}

// posting with a link, do not include URL in comment.
$format = trim(str_replace('{url}', '', Social::option('comment_broadcast_format')));
$message = $this->format_comment_content($comment, $format);
$args['message'] = $message;

// prep data
if (!is_null($comment_id)) {
// prep data
$post = get_post($comment->comment_post_ID);
$type = 'comment';
}
if (!is_null($post_id)) {
$post = get_post($post_id);
$type = 'post';
}
setup_postdata($post);

$link_args = array(
'link' => get_post_permalink($post->ID),
'title' => $post->post_title,
'description' => get_the_excerpt(),
);
if (function_exists('has_post_thumbnail') and has_post_thumbnail($post->ID)) {
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
$link_args = $link_args + array(
'picture' => $image[0],
setup_postdata($post);
$link_args = array(
'link' => get_post_permalink($post->ID),
'title' => get_the_title($post->ID),
'description' => get_the_excerpt(),
);
}
wp_reset_postdata();

if ($type == 'comment' || ($type == 'post' && get_post_format($post->ID) !== 'status')) {
if (function_exists('has_post_thumbnail') and has_post_thumbnail($post->ID)) {
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
$link_args = $link_args + array(
'picture' => $image[0],
);
}
wp_reset_postdata();
$args = $args + $link_args;
}

Expand Down
32 changes: 30 additions & 2 deletions lib/social/service/twitter.php
Expand Up @@ -24,6 +24,24 @@ final class Social_Service_Twitter extends Social_Service implements Social_Inte
public function max_broadcast_length() {
return 140;
}

/**
* Any additional parameters that should be passed with a broadcast.
*
* @static
* @return array
*/
public function get_broadcast_extras($account_id, $post, $args = array()) {
if (isset($_POST['social_account_in_reply_to']) &&
isset($_POST['social_account_in_reply_to'][$this->key()]) &&
!empty($_POST['social_account_in_reply_to'][$this->key()][$account_id])) {
$id = $this->tweet_url_to_id(stripslashes($_POST['social_account_in_reply_to'][$this->key()][$account_id]));
if (!empty($id)) {
$args['in_reply_to_status_id'] = $id;
}
}
return parent::get_broadcast_extras($account_id, $post, $args);
}

/**
* Broadcasts the message to the specified account. Returns the broadcasted ID.
Expand Down Expand Up @@ -324,6 +342,17 @@ public function aggregation_row($type, $item, $username, $id) {
}
return '';
}

/**
* Parse a Twitter URL and return the tweet ID.
*
* @param string $url
* @return string
*/
public function tweet_url_to_id($url) {
$url = explode('/', $url);
return end($url);
}

/**
* Imports a Tweet by URL.
Expand All @@ -341,8 +370,7 @@ public function import_tweet_by_url($post_id, $url) {
}

$invalid = false;
$url = explode('/', $url);
$id = end($url);
$id = $this->tweet_url_to_id($url);
if (!empty($id) and !$this->is_original_broadcast($post, $id)) {
Social::log('Importing tweet. -- ID: :id -- URL: :url', array(
'id' => $id,
Expand Down
24 changes: 24 additions & 0 deletions social-twitter.php
Expand Up @@ -350,6 +350,29 @@ public static function social_item_output_title($title, $key) {

return $title;
}

/**
* Add a "reply to" field to broadcast form.
*
* @static
* @param obj $post
* @param obj $service
* @param obj $account
* @return void
*/
public static function social_broadcast_form_item_edit($post, $service, $account) {
if ($service->key() != 'twitter') {
return;
}
$field_name = str_replace('_content', '_in_reply_to', $account['field_name_content']);
?>
<a href="#" class="tweet-reply-link"><?php _e('Send as a reply', 'social'); ?></a>
<div class="tweet-reply-fields">
<label for="<?php echo esc_attr($field_name); ?>"><?php _e('URL of Tweet (to reply to)', 'social'); ?></label>
<input type="text" class="tweet-reply-field" name="<?php echo esc_attr($field_name); ?>" value="" id="<?php echo esc_attr($field_name); ?>" />
</div>
<?php
}

} // End Social_Twitter

Expand All @@ -362,5 +385,6 @@ public static function social_item_output_title($title, $key) {
add_filter('social_save_broadcasted_ids_data', array('Social_Twitter', 'social_save_broadcasted_ids_data'), 10, 5);
add_filter('social_item_output_title', array('Social_Twitter', 'social_item_output_title'), 10, 2);
add_action('wp_enqueue_scripts', array('Social_Twitter', 'enqueue_assets'));
add_action('social_broadcast_form_item_edit', array('Social_Twitter', 'social_broadcast_form_item_edit'), 10, 3);

}
2 changes: 1 addition & 1 deletion views/wp-admin/post/broadcast/options.php
Expand Up @@ -66,9 +66,9 @@
?>
<div class="broadcast-edit<?php echo ($account['edit'] ? ' edit' : ''); echo ($account['checked'] ? ' checked' : ''); ?>">
<input type="checkbox" name="<?php echo esc_attr($account['field_name_checked']); ?>" id="<?php echo esc_attr($account['field_name_checked'].$account['field_value_checked']); ?>" value="<?php echo esc_attr($account['field_value_checked']); ?>"<?php checked($account['checked'], true); ?> />
<textarea name="<?php echo esc_attr($account['field_name_content']); ?>" cols="40" rows="2" maxlength="<?php echo esc_attr($account['maxlength']); ?>"><?php echo esc_textarea($account['content']); ?></textarea>
<p class="readonly"><?php echo esc_textarea($account['content']); ?></p>
<a href="#" class="edit"><?php _e('Edit', 'social'); ?></a>
<textarea name="<?php echo esc_attr($account['field_name_content']); ?>" cols="40" rows="2" maxlength="<?php echo esc_attr($account['maxlength']); ?>"><?php echo esc_textarea($account['content']); ?></textarea>
<span class="counter"></span>
<?php do_action('social_broadcast_form_item_edit', $post, $service, $account); ?>
</div>
Expand Down

0 comments on commit b2beb0d

Please sign in to comment.