예제 #1
0
 public function test_generate_link_general()
 {
     $link = ppp_generate_link($this->_post_id, 'sharedate_1_' . $this->_post_id, false);
     $this->assertEquals('http://example.org/?p=' . $this->_post_id, $link);
 }
/**
 * Determines if the post should be shared on publish
 * @param  string $old_status The old post status
 * @param  string $new_status The new post status
 * @param  object $post       The Post Object
 * @return void               Shares the post
 */
function ppp_tw_share_on_publish($new_status, $old_status, $post)
{
    global $ppp_options;
    $from_meta = get_post_meta($post->ID, '_ppp_share_on_publish', true);
    $from_post = isset($_POST['_ppp_share_on_publish']);
    if (empty($from_meta) && empty($from_post)) {
        return;
    }
    // Determine if we're seeing the share on publish in meta or $_POST
    if ($from_meta && !$from_post) {
        $ppp_share_on_publish_text = get_post_meta($post->ID, '_ppp_share_on_publish_text', true);
        $use_media = get_post_meta($post->ID, '_ppp_share_on_publish_include_image', true);
    } else {
        $ppp_share_on_publish_text = isset($_POST['_ppp_share_on_publish_text']) ? $_POST['_ppp_share_on_publish_text'] : '';
        $use_media = isset($_POST['_ppp_share_on_publish_include_image']) ? $_POST['_ppp_share_on_publish_include_image'] : false;
    }
    $share_content = !empty($ppp_share_on_publish_text) ? $ppp_share_on_publish_text : ppp_tw_generate_share_content($post->ID, null, false);
    $share_content = apply_filters('ppp_share_content', $share_content, array('post_id' => $post->ID));
    $name = 'sharedate_0_' . $post->ID;
    $media = ppp_post_has_media($post->ID, 'tw', $use_media);
    $share_link = ppp_generate_link($post->ID, $name, true);
    $status['twitter'] = ppp_send_tweet($share_content . ' ' . $share_link, $post->ID, $media);
    if (!empty($status['twitter']->id_str)) {
        $author_id = $post->post_author;
        $author_rt = get_user_meta($author_id, '_ppp_share_on_publish', true);
        if ($author_rt) {
            $twitter_user = new PPP_Twitter_User($author_id);
            $twitter_user->retweet($status['twitter']->id_str);
        }
    }
    if (isset($ppp_options['enable_debug']) && $ppp_options['enable_debug'] == '1') {
        update_post_meta($post->ID, '_ppp-' . $name . '-status', $status);
    }
}
/**
 * Share a Facebook post on Publish
 * @param  string $old_status The old post status
 * @param  string $new_status The new post status
 * @param  object $post       The Post object
 * @return void
 */
function ppp_fb_share_on_publish($new_status, $old_status, $post)
{
    global $ppp_options;
    $from_meta = get_post_meta($post->ID, '_ppp_fb_share_on_publish', true);
    $from_post = isset($_POST['_ppp_fb_share_on_publish']);
    if (empty($from_meta) && empty($from_post)) {
        return;
    }
    // Determine if we're seeing the share on publish in meta or $_POST
    if ($from_meta && !$from_post) {
        $ppp_share_on_publish_title = get_post_meta($post->ID, '_ppp_fb_share_on_publish_title', true);
    } else {
        $ppp_share_on_publish_title = isset($_POST['_ppp_fb_share_on_publish_title']) ? $_POST['_ppp_fb_share_on_publish_title'] : '';
    }
    $thumbnail = ppp_post_has_media($post->ID, 'fb', true);
    $name = 'sharedate_0_' . $post->ID . '_fb';
    $default_title = isset($ppp_options['default_text']) ? $ppp_options['default_text'] : '';
    // If an override was found, use it, otherwise try the default text content
    $share_title = isset($ppp_share_on_publish_title) && !empty($ppp_share_on_publish_title) ? $ppp_share_on_publish_title : $default_title;
    // If the content is still empty, just use the post title
    $share_title = isset($share_title) && !empty($share_title) ? $share_title : get_the_title($post->ID);
    $share_title = apply_filters('ppp_share_content', $share_title, array('post_id' => $post->ID));
    $share_link = ppp_generate_link($post->ID, $name, true);
    $status['facebook'] = ppp_fb_share($share_link, $share_title, $thumbnail);
    if (isset($ppp_options['enable_debug']) && $ppp_options['enable_debug'] == '1') {
        update_post_meta($post->ID, '_ppp-' . $name . '-status', $status);
    }
}
예제 #4
0
/**
* Display the Social tab
* @return void
*/
function ppp_display_social()
{
    do_action('ppp_social_settings_pre_form');
    $ppp_share_settings = get_option('ppp_share_settings');
    ?>
	<div class="wrap">
		<div id="icon-options-general" class="icon32"></div><h1><?php 
    _e('Post Promoter Pro - Social Settings', 'ppp-txt');
    ?>
</h1>
		<form method="post" action="options.php">
			<?php 
    wp_nonce_field('ppp-share-settings');
    ?>
			<h3><?php 
    _e('Social Media Accounts', 'ppp-txt');
    ?>
</h3>
			<?php 
    require_once PPP_PATH . 'includes/admin/class-accounts-table.php';
    $accounts_table = new PPP_Accounts_Table();
    $accounts_table->prepare_items();
    $accounts_table->display();
    ?>
			<table class="form-table">
				<?php 
    $analytics_option = isset($ppp_share_settings['analytics']) ? $ppp_share_settings['analytics'] : 0;
    ?>
				<tr valign="top">
					<th scope="row" valign="top">
						<?php 
    _e('Analytics', 'ppp-txt');
    ?>
</span>
					</th>
					<td id="ppp-analytics-options">
						<p>
							<input id="ppp_no_tracking"
							       name="ppp_share_settings[analytics]"
							       type="radio"
							       value="none"
							       <?php 
    checked('none', $analytics_option, true);
    ?>
							/>&nbsp<label for="ppp_no_tracking"><?php 
    _e('None', 'ppp-txt');
    ?>
</label>
						</p>
						<br />
						<p>
							<input id="ppp_unique_links"
							       name="ppp_share_settings[analytics]"
							       type="radio"
							       value="unique_links"
							       <?php 
    checked('unique_links', $analytics_option, true);
    ?>
							/>&nbsp<label for="ppp_unique_links"><?php 
    _e('Simple Tracking', 'ppp-txt');
    ?>
</label><br />
							<small><?php 
    _e('Appends a query string to shared links for analytics.', 'ppp-txt');
    ?>
</small>
						</p>
						<br />
						<p>
							<input id="ppp_ga_tags"
							       name="ppp_share_settings[analytics]"
							       type="radio"
							       value="google_analytics"
							       <?php 
    checked('google_analytics', $analytics_option, true);
    ?>
							/>&nbsp<label for="ppp_ga_tags"><?php 
    _e('Google Analytics Tags', 'ppp-txt');
    ?>
</label><br />
							<small><?php 
    _e('Results can be seen in the Acquisition Menu under "Campaigns"', 'ppp-txt');
    ?>
</small>
						</p>
						<?php 
    do_action('ppp-settings-analytics-radio');
    ?>
						<p id="ppp-link-example">
						<hr />
						<small><?php 
    _e('Here is an example of what your link will look like', 'ppp-txt');
    ?>
: <br />
							<?php 
    $post = wp_get_recent_posts(array('numberposts' => 1));
    ?>
							<?php 
    if (count($post) > 0) {
        ?>
								<code><?php 
        echo ppp_generate_link($post[0]['ID'], 'sharedate_1_' . $post[0]['ID'], false);
        ?>
</code></small>
							<?php 
    } else {
        ?>
								<em><?php 
        _e('No posts available to generate link from.', 'ppp-txt');
        ?>
</em>
							<?php 
    }
    ?>
						</p>
					</td>
				</tr>

				<?php 
    $tw_sop = !empty($ppp_share_settings['twitter']['share_on_publish']) ? true : false;
    $fb_sop = !empty($ppp_share_settings['facebook']['share_on_publish']) ? true : false;
    $li_sop = !empty($ppp_share_settings['linkedin']['share_on_publish']) ? true : false;
    ?>
				<tr valign="top">
					<th scope="row" valign="top">
						<?php 
    _e('Share on Publish Defaults', 'ppp-txt');
    ?>
</span><br />
						<small><em><?php 
    _e('Enabled sharing on pubish by default', 'ppp-txt');
    ?>
</em></small>
					</th>
					<td id="ppp-share-on-publish-wrapper">
						<?php 
    if (ppp_twitter_enabled()) {
        ?>
						<p>
							<input type="checkbox" id="twitter-share-on-publish" value="1" <?php 
        checked(true, $tw_sop, true);
        ?>
 name="ppp_share_settings[twitter][share_on_publish]" />
							<label for="twitter-share-on-publish"><?php 
        _e('Twitter', 'ppp-txt');
        ?>
</label>
						</p>
						<?php 
    }
    ?>

						<?php 
    if (ppp_facebook_enabled()) {
        ?>
						<p>
							<input type="checkbox" id="facebook-share-on-publish" value="1" <?php 
        checked(true, $fb_sop, true);
        ?>
 name="ppp_share_settings[facebook][share_on_publish]" />
							<label for="facebook-share-on-publish"><?php 
        _e('Facebook', 'ppp-txt');
        ?>
</label>
						</p>
						<?php 
    }
    ?>

						<?php 
    if (ppp_linkedin_enabled()) {
        ?>
						<p>
							<input type="checkbox" id="linkedin-share-on-publish" value="1" <?php 
        checked(true, $li_sop, true);
        ?>
 name="ppp_share_settings[linkedin][share_on_publish]" />
							<label for="linkedin-share-on-publish"><?php 
        _e('LinkedIn', 'ppp-txt');
        ?>
</label>
						</p>
						<?php 
    }
    ?>
					</td>
				</tr>

				<?php 
    $twitter_cards_enabled = ppp_tw_cards_enabled();
    ?>
				<tr valign="top">
					<th scope="row" valign="top">
						<?php 
    _e('Twitter Settings', 'ppp-txt');
    ?>
</span>
					</th>
					<td id="ppp-twitter-cards-wrapper">
						<p>
							<input id="ppp-twitter-cards"
							       name="ppp_share_settings[twitter][cards_enabled]"
							       type="checkbox"
							       value="1"
							       <?php 
    checked(true, $twitter_cards_enabled, true);
    ?>
							/>&nbsp<label for="ppp-twitter-cards"><?php 
    _e('Enable Twitter Cards', 'ppp-txt');
    ?>
</label>
						</p>
					</td>
				</tr>

				<?php 
    $shortener = isset($ppp_share_settings['shortener']) ? $ppp_share_settings['shortener'] : false;
    ?>
				<tr valign="top">
					<th scope="row" valign="top">
						<?php 
    _e('URL Shortener', 'ppp-txt');
    ?>
</span>
					</th>
					<td id="ppp-shortener-options">
						<p>
							<select name="ppp_share_settings[shortener]">
								<option value="-1"><?php 
    _e('Select a Service', 'ppp-txt');
    ?>
</option>
								<?php 
    do_action('ppp_url_shorteners', $shortener);
    ?>
							</select>
						</p>
						<?php 
    if ($shortener) {
        ?>
							<?php 
        do_action('ppp_shortener_settings-' . $shortener);
        ?>
						<?php 
    }
    ?>
					</td>
				</tr>

				<?php 
    settings_fields('ppp-share-settings');
    ?>

				<input type="hidden" name="action" value="update" />
				<input type="hidden" name="page_options" value="ppp_share_settings,ppp_social_settings" />


			</table>

			<input type="submit" class="button-primary" value="<?php 
    _e('Save Changes', 'ppp-txt');
    ?>
" />

		</form>
	</div>
	<?php 
}