Пример #1
0
 /**
  * returns the instance created by its first invoke.
  *
  * @return Social
  */
 public static function getInstance()
 {
     if (null === self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Пример #2
0
 function __construct($acct = null)
 {
     // Set our ID
     $this->id = $acct->id();
     // Set the account (Social_Service_Twitter_Account)
     $this->social_acct = $acct;
     // For convenience, set a reference to the service which has all the account methods
     $this->service =& Social::instance()->service('twitter');
 }
 public static function add_links_from_social()
 {
     $Social = new Social();
     $ids = get_post_meta(get_the_ID(), '_social_broadcasted_ids', true);
     $services = $Social->instance()->services();
     $broadcasts = array();
     $see_on_social = '';
     if (is_array($ids) and count($ids)) {
         foreach ($services as $key => $service) {
             if (isset($ids[$key]) and count($ids[$key])) {
                 $broadcasted = true;
                 foreach ($ids[$key] as $user_id => $broadcasted) {
                     $account = $service->account($user_id);
                     foreach ($broadcasted as $broadcasted_id => $data) {
                         if (false === $account) {
                             $class = 'Social_Service_' . $key . '_Account';
                             $account = new $class($data['account']);
                             if (!$account->has_user() and 'twitter' == $key) {
                                 $recovered = $service->recover_broadcasted_tweet_data($broadcasted_id, $post->ID);
                                 if (isset($recovered->user)) {
                                     $data['account']->user = $recovered->user;
                                     $account = new $class($data['account']);
                                 }
                             }
                         }
                         $broadcasted = esc_html($service->title());
                         if (isset($broadcasted_id)) {
                             if ($account->has_user() or 'twitter' !== $service->key()) {
                                 $url = $service->status_url($account->username(), $broadcasted_id);
                                 if (!empty($url)) {
                                     $broadcasts[] = esc_url($url);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $broadcasts;
 }
Пример #4
0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php 
language_attributes();
?>
>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?php 
_e('Social Broadcasts', 'social');
?>
</title>
<?php 
wp_admin_css('install', true);
wp_admin_css('buttons', true);
$social = Social::instance();
$social->admin_enqueue_assets();
?>
	<link rel="stylesheet" id="social-css" href="<?php 
echo esc_url(SOCIAL_ADMIN_CSS);
?>
" type="text/css" media="all" />
</head>
<body class="<?php 
echo esc_attr($clean);
?>
">
<h1 id="logo"><?php 
_e('Social Broadcasts', 'social');
?>
</h1>
<form id="setup" method="post" class="broadcast-interstitial" action="<?php 
Пример #5
0
 /**
  * Saves the Facebook pages.
  *
  * @wp-action social_settings_save
  * @static
  * @param  bool $is_personal
  */
 public static function social_settings_save($is_personal = false)
 {
     $service = Social::instance()->service('facebook');
     if ($service !== false) {
         $accounts = $service->accounts();
         if (count($accounts)) {
             foreach ($accounts as $account_id => $account) {
                 if (isset($_POST['social_facebook_pages_' . $account->id()])) {
                     $pages = $service->get_pages($account);
                     $account->pages(array());
                     if (count($pages)) {
                         foreach ($_POST['social_facebook_pages_' . $account->id()] as $page_id) {
                             if (isset($pages[$page_id])) {
                                 $accounts[$account_id] = $account->page($pages[$page_id]);
                             }
                         }
                     }
                 }
                 if (defined('IS_PROFILE_PAGE')) {
                     $accounts[$account_id]->universal(false);
                     $accounts[$account_id]->use_pages(false, false);
                     $accounts[$account_id]->pages(array(), false);
                 } else {
                     $accounts[$account_id]->personal(false);
                     $accounts[$account_id]->use_pages(true, false);
                     $accounts[$account_id]->pages(array(), true);
                 }
                 $accounts[$account_id] = $accounts[$account_id]->as_object();
             }
             $service->accounts($accounts)->save($is_personal);
         }
     }
 }
Пример #6
0
 /**
  * Loads the pages for the account.
  *
  * @param  Social_Service_Account  $account
  * @param  bool                    $is_profile
  * @param  bool                    $save
  * @return array
  */
 public function get_pages(Social_Service_Account $account, $is_profile = false, $save = true)
 {
     $pages = array();
     if ($account->use_pages() or $account->use_pages(true)) {
         $response = $this->request($account, $account->id() . '/accounts');
         if ($response !== false and isset($response->body()->response)) {
             if (isset($response->body()->response->data)) {
                 foreach ($response->body()->response->data as $item) {
                     if ($item->category != 'Application') {
                         $pages[$item->id] = $item;
                     }
                 }
             } else {
                 if ($response->body()->response == 'incorrect method') {
                     // Account no longer has page permissions.
                     $service = Social::instance()->service('facebook');
                     $accounts = $service->accounts();
                     foreach ($accounts as $account_id => $_account) {
                         if ($account_id == $account->id()) {
                             $_account->use_pages(false, false);
                             $_account->use_pages(true, false);
                             $_account->pages(array(), $is_profile);
                         }
                         $accounts[$account_id] = $account->as_object();
                     }
                     if ($save) {
                         $service->accounts($accounts)->save($is_profile);
                     }
                 }
             }
         }
     }
     return $pages;
 }
Пример #7
0
 /**
  * Retrieves missing Twitter content.
  *
  * @return void
  */
 public function action_retrieve_twitter_content()
 {
     $this->verify_nonce();
     $broadcasted_id = $this->request->query('broadcasted_id');
     if ($broadcasted_id === null) {
         exit;
     }
     $post_id = $this->request->query('post_id');
     if ($post_id !== null) {
         $recovered = false;
         $run = get_post_meta('_social_run_twitter_retrieval', true);
         if (empty($run) or (int) $run <= current_time('timestamp', 1)) {
             Social::log('Running Twitter retrieval on post #:post_id for broadcasted #:broadcasted_id.', array('post_id' => $post_id, 'broadcasted_id' => $broadcasted_id));
             // Do we have accounts to use?
             $service = Social::instance()->service('twitter');
             if ($service !== false) {
                 $accounts = $service->accounts();
                 if (count($accounts)) {
                     foreach ($accounts as $account) {
                         Social::log('Using account #:account_id.', array('account_id' => $account->id()));
                         // Run the request to the find Tweet
                         $response = $service->request($account, 'statuses/show/' . $broadcasted_id);
                         if ($response !== false and $response->body()->result != 'error') {
                             $recovered = $service->recovered_meta($post_id, $broadcasted_id, $response->body()->response);
                         }
                         Social::log('Response: :response', array('response' => print_r($response, true)));
                     }
                 } else {
                     Social::log('Using public API, no accounts found.');
                     $response = wp_remote_get('http://api.twitter.com/1/statuses/show/' . $broadcasted_id . '.json');
                     if (!is_wp_error($response) and !isset($response->error)) {
                         $recovered = $service->recovered_meta($post_id, $broadcasted_id, $response);
                     }
                     Social::log('Response: :response', array('response' => print_r($response, true)));
                 }
             } else {
                 Social::log('Failed, Twitter class not found.');
             }
         }
         if (!$recovered) {
             Social::log('Failed to recover the data, try again in 15 minutes.');
             // Something went wrong, retry again in 15 minutes.
             update_post_meta($post_id, '_social_run_twitter_retrieval', current_time('timestamp', 1) + 54000);
         } else {
             if (!empty($run)) {
                 Social::log('Content found, cya!');
                 delete_post_meta($post_id, '_social_run_twitter_retrieval');
             }
         }
     }
 }
Пример #8
0
 /**
  * Filter the where clause for pulling comments for feeds (to exclude meta comments).
  *
  * @param  string  $where
  * @return string
  */
 public static function comments_feed_exclusions($where)
 {
     global $wpdb;
     $meta_types = array();
     // get services
     $services = Social::instance()->services();
     // ask each service for it's "meta" comment types
     foreach ($services as $service) {
         $meta_types = array_merge($meta_types, $service->comment_types_meta());
     }
     $meta_types = array_unique($meta_types);
     if (count($meta_types)) {
         $where .= " AND comment_type NOT IN ('" . implode("', '", array_map('social_wpdb_escape', $meta_types)) . "') ";
     }
     return $where;
 }
Пример #9
0
     $results = $wpdb->get_results("\n\t\t\tSELECT ID\n\t\t\t  FROM {$wpdb->users}\n\t\t");
     if (is_array($results)) {
         foreach ($results as $result) {
             update_user_meta($result->ID, 'social_2.0_upgrade', true);
         }
     }
 }
 // Upgrade system_cron to fetch_comments
 $fetch = $wpdb->get_var("\n\t\tSELECT option_value\n\t\t  FROM {$wpdb->options}\n\t\t WHERE option_name = 'social_system_crons'\n\t");
 if (empty($fetch)) {
     $fetch = '1';
 }
 $wpdb->query("\n\t\tINSERT\n\t\t  INTO {$wpdb->options} (option_name, option_value)\n\t\tVALUES('social_fetch_comments', '{$fetch}')\n\t\t    ON DUPLICATE KEY UPDATE option_id = option_id\n    ");
 // Update all comment types
 $keys = array();
 foreach (Social::instance()->services() as $service) {
     $keys[] = $service->key();
     if ($service->key() == 'facebook') {
         $keys[] = 'facebook-like';
     }
 }
 foreach ($keys as $key) {
     $query = $wpdb->query("\n\t\t\tUPDATE {$wpdb->comments}\n\t\t\t   SET comment_type = 'social-{$key}'\n\t\t\t WHERE comment_type = '{$key}'\n\t\t");
 }
 // Make sure all commenter accounts have the commenter flag
 $results = $wpdb->get_results("\n\t\tSELECT m.user_id\n\t\t  FROM {$wpdb->users} AS u\n\t\t  JOIN {$wpdb->usermeta} AS m\n\t\t    ON m.user_id = u.ID\n\t\t WHERE m.meta_key = 'social_accounts'\n\t\t   AND u.user_email LIKE '*****@*****.**'\n    ");
 if (count($results)) {
     foreach ($results as $result) {
         update_user_meta($result->user_id, 'social_commenter', 'true');
     }
 }
Пример #10
0
 /**
  * Create blog post from tweet
  *
  * @param array $args 
  * @return bool
  */
 function create_blog_post($args = array())
 {
     extract($args);
     // Add a space if we have a prefix
     $title_prefix = empty($title_prefix) ? '' : trim($title_prefix) . ' ';
     $post_content = $this->link_entities(false);
     // Append image to post if there is one, can't set it as a featured image until after save
     if (!empty($this->featured_image_id)) {
         $size = apply_filters('aktt_featured_image_size', 'medium');
         $post_content .= "\n\n" . wp_get_attachment_image($this->featured_image_id, $size);
     }
     $gmt_time = self::twdate_to_time($this->date());
     // Build the post data
     $data = array('post_title' => $title_prefix . $this->title(), 'post_content' => $post_content, 'post_author' => $post_author, 'post_status' => $post_status, 'post_type' => 'post', 'post_date' => date('Y-m-d H:i:s', AKTT::gmt_to_wp_time($gmt_time)), 'post_date_gmt' => date('Y-m-d H:i:s', $gmt_time), 'guid' => $this->guid() . '-post');
     $data = apply_filters('aktt_tweet_create_blog_post_data', $data);
     // hook in here if you want to conditionally skip blog post creation
     if (!apply_filters('aktt_tweet_create_blog_post', true, $data, $this)) {
         return false;
     }
     $this->blog_post_id = wp_insert_post($data, true);
     if (is_wp_error($this->blog_post_id)) {
         AKTT::log('WP_Error:: ' . $this->blog_post_id->get_error_message());
         return false;
     }
     // have to set up taxonomies after the insert in case we are in a context without
     // a 'current user' - see: http://core.trac.wordpress.org/ticket/19373
     wp_set_object_terms($this->blog_post_id, intval($post_category), 'category');
     wp_set_object_terms($this->blog_post_id, array_map('trim', explode(',', $post_tags)), 'post_tag');
     // hook in here and return false to not set the format to "status",
     // or return another format to use that format instead of status
     if ($post_format = apply_filters('aktt_tweet_create_blog_post_format', 'status', $data, $this)) {
         set_post_format($this->blog_post_id, $post_format);
     }
     if (!empty($this->featured_image_id)) {
         update_post_meta($this->blog_post_id, '_thumbnail_id', $this->featured_image_id);
     }
     update_post_meta($this->blog_post_id, '_aktt_tweet_id', $this->id());
     // twitter's tweet ID
     update_post_meta($this->blog_post_id, '_aktt_tweet_post_id', $this->post_id);
     // twitter's post ID
     // Add it to the tweet's post_meta as well
     update_post_meta($this->post_id, '_aktt_tweet_blog_post_id', $this->blog_post_id);
     // Let Social know to aggregate info about this post
     $account = false;
     foreach (AKTT::$accounts as $aktt_account) {
         if ($aktt_account->social_acct->id() == $this->data->user->id_str) {
             $account = $aktt_account->social_acct;
             break;
         }
     }
     if ($account) {
         Social::instance()->add_broadcasted_id($this->blog_post_id, 'twitter', $this->id(), $this->content(), $account, null);
     }
     // Let the account know we were successful
     return true;
 }
Пример #11
0
                $service = Social::instance()->service($group);
                if ($service !== false and count($items)) {
                    $avatar_size = apply_filters('social_items_avatar_size', array('width' => 24, 'height' => 24));
                    echo Social_View::factory('comment/social_item', compact('items', 'service', 'avatar_size'));
                }
            }
            echo '</div>';
        }
        if ($last_reply_time or count($social_items)) {
            echo '<div class="cf-clearfix"></div>';
        }
        if (count($comments)) {
            ?>
				<ol class="social-commentlist">
				<?php 
            wp_list_comments(array('callback' => array(Social::instance(), 'comment'), 'walker' => new Social_Walker_Comment()), $comments);
            ?>
				</ol>
				<?php 
        }
        if (get_comment_pages_count() > 1 and get_option('page_comments')) {
            ?>
				<nav id="comment-nav-below">
					<h1 class="assistive-text"><?php 
            _e('Comment navigation', 'social');
            ?>
</h1>
					<div class="nav-previous"><?php 
            previous_comments_link(__('&larr; Older Comments', 'social'));
            ?>
</div>
Пример #12
0
 static function download_tweet($status_id, $username = null)
 {
     if (empty(AKTT::$accounts)) {
         return false;
     }
     $account_found = $tweet = false;
     if (!empty($username)) {
         AKTT::get_social_accounts();
         foreach (AKTT::$accounts as $id => $account) {
             if ($username == $account->social_acct->name()) {
                 // proper account stored as $account
                 $account_found = true;
                 break;
             }
         }
         if (!$account_found) {
             $account = AKTT::$accounts[0];
             // use any account
         }
         $response = Social::instance()->service('twitter')->request($account->social_acct, '1.1/statuses/show/' . urlencode($t->id) . '.json', array('include_entities' => 1, 'include_rts' => 1));
         $content = $response->body();
         if ($content->result == 'success') {
             $tweets = $content->response;
             if (!$tweets || !is_array($tweets) || count($tweets) != 1) {
                 $tweet = $tweet[0];
             }
         }
     }
     return $tweet;
 }
Пример #13
0
 /**
  * Hook for 'comment_form_logged_in' action.
  *
  * @return string
  */
 public function logged_in_as()
 {
     $services = Social::instance()->services();
     $accounts = array();
     foreach ($services as $key => $service) {
         if (count($service->accounts())) {
             $accounts[$key] = $service->accounts();
         }
     }
     return Social_View::factory('comment/logged_in_as', array('services' => $services, 'accounts' => $accounts, 'current_user' => $this->current_user))->render();
 }
Пример #14
0
 /**
  * Renders the log to HTML.
  *
  * @return Social_View
  */
 public function render()
 {
     return Social_View::factory('wp-admin/post/meta/log/output', array('log' => $this->_log, 'services' => Social::instance()->services()))->render();
 }
								</li>
								<li>
									<label for="social_disable_broadcasting">
										<input type="checkbox" name="social_disable_broadcasting" id="social_disable_broadcasting" value="1" <?php 
checked(Social::option('disable_broadcasting'), '1');
?>
 />
										<?php 
_e("Disable Social's broadcasting feature.", 'social');
?>
									</label>
								</li>
								<li>&nbsp;</li>
								<li>
									<?php 
$twitter_accounts = Social::instance()->service('twitter')->accounts();
$social_api_accounts = Social::option('social_api_accounts');
$selected_id = $social_api_accounts['twitter'];
?>
									<div class="twitter-api-account">
										<label>Twitter Default API Account</label>
										<select id="social_api_accounts-twitter" name="social_api_accounts[twitter]">
											<?php 
foreach ($twitter_accounts as $account) {
    $acct_id = $account->id();
    ?>
												<?php 
    if ($account->personal()) {
        continue;
    }
    ?>
Пример #16
0
 /**
  * Initializes the controller with the request and Social objects.
  *
  * @param  Social_Request  $request
  */
 public function __construct(Social_Request $request)
 {
     $this->request = $request;
     $this->social = Social::instance();
 }