Example #1
0
function jd_add_twitter_inner_box($post)
{
    if (current_user_can('wpt_can_tweet')) {
        $is_pro = function_exists('wpt_pro_exists') ? 'pro' : 'free';
        echo "<div class='wp-to-twitter {$is_pro}'>";
        global $wpt_donate_url;
        $tweet_status = '';
        $options = get_option('wpt_post_types');
        if (is_object($post)) {
            $type = $post->post_type;
            $status = $post->post_status;
            $post_id = $post->ID;
        }
        $jd_tweet_this = get_post_meta($post_id, '_jd_tweet_this', true);
        if (!$jd_tweet_this) {
            $jd_tweet_this = get_option('jd_tweet_default') == '1' ? 'no' : 'yes';
        }
        if (isset($_GET['action']) && $_GET['action'] == 'edit' && get_option('jd_tweet_default_edit') == '1') {
            $jd_tweet_this = 'no';
        }
        if (isset($_REQUEST['message']) && $_REQUEST['message'] != 10) {
            // don't display when draft is updated or if no message
            if (!($_REQUEST['message'] == 1 && ($status == 'publish' && $options[$type]['post-edited-update'] != 1))) {
                $log = wpt_log('wpt_status_message', $post_id);
                $class = $log != 'Tweet sent successfully.' ? 'error' : 'updated';
                if ($log != '') {
                    echo "<div class='{$class}'><p>" . wpt_log('wpt_status_message', $post_id) . "</p></div>";
                }
            }
        }
        $previous_tweets = get_post_meta($post_id, '_jd_wp_twitter', true);
        $failed_tweets = get_post_meta($post_id, '_wpt_failed');
        $tweet = esc_attr(stripcslashes(get_post_meta($post_id, '_jd_twitter', true)));
        $tweet = apply_filters('wpt_user_text', $tweet, $status);
        $jd_template = $status == 'publish' ? $options[$type]['post-edited-text'] : $options[$type]['post-published-text'];
        if ($status == 'publish' && $options[$type]['post-edited-update'] != 1) {
            $tweet_status = sprintf(__('Tweeting %s edits is disabled.', 'wp-to-twitter'), $type);
        }
        if (current_user_can('update_core') && function_exists('wpt_pro_exists')) {
            wpt_pro_compatibility();
        }
        if ($tweet_status != '') {
            echo "<p class='disabled'>{$tweet_status}</p>";
        }
        if (current_user_can('wpt_twitter_custom') || current_user_can('update_core')) {
            ?>
			<p class='jtw'>
			<label for="jtw"><?php 
            _e("Custom Twitter Post", 'wp-to-twitter', 'wp-to-twitter');
            ?>
</label><br /><textarea class="attachmentlinks" name="_jd_twitter" id="jtw" rows="2" cols="60"><?php 
            echo esc_attr($tweet);
            ?>
</textarea>
			</p>
			<?php 
            $jd_expanded = $jd_template;
            if (get_option('jd_twit_prepend') != "") {
                $jd_expanded = "<span title='" . __('Your prepended Tweet text; not part of your template.', 'wp-to-twitter') . "'>" . stripslashes(get_option('jd_twit_prepend')) . "</span> " . $jd_expanded;
            }
            if (get_option('jd_twit_append') != "") {
                $jd_expanded = $jd_expanded . " <span title='" . __('Your appended Tweet text; not part of your template.', 'wp-to-twitter') . "'>" . stripslashes(get_option('jd_twit_append')) . "</span>";
            }
            ?>
			<p class='template'><?php 
            _e('Your template:', 'wp-to-twitter');
            ?>
 <code><?php 
            echo stripcslashes($jd_expanded);
            ?>
</code></p>
			<?php 
            if (get_option('jd_keyword_format') == 2) {
                $custom_keyword = get_post_meta($post_id, '_yourls_keyword', true);
                echo "<label for='yourls_keyword'>" . __('YOURLS Custom Keyword', 'wp-to-twitter') . "</label> <input type='text' name='_yourls_keyword' id='yourls_keyword' value='{$custom_keyword}' />";
            }
        } else {
            ?>
			<input type="hidden" name='_jd_twitter' value='<?php 
            echo esc_attr($tweet);
            ?>
' />
			<?php 
        }
        if (current_user_can('wpt_twitter_switch') || current_user_can('update_core')) {
            // "no" means 'Don't Tweet' (is checked)
            $nochecked = $jd_tweet_this == 'no' ? ' checked="checked"' : '';
            $yeschecked = $jd_tweet_this == 'yes' ? ' checked="checked"' : '';
            ?>
			<p><input type="radio" name="_jd_tweet_this" value="no" id="jtn"<?php 
            echo $nochecked;
            ?>
 /> <label for="jtn"><?php 
            _e("Don't Tweet this post.", 'wp-to-twitter');
            ?>
</label> <input type="radio" name="_jd_tweet_this" value="yes" id="jty"<?php 
            echo $yeschecked;
            ?>
 /> <label for="jty"><?php 
            _e("Tweet this post.", 'wp-to-twitter');
            ?>
</label></p>
			<?php 
        } else {
            ?>
			<input type='hidden' name='_jd_tweet_this' value='<?php 
            echo $jd_tweet_this;
            ?>
' />
			<?php 
        }
        ?>
		<div class='wpt-options'>
			<?php 
        if ($is_pro == 'pro') {
            $pro_active = " class='active'";
            $free_active = '';
        } else {
            $free_active = " class='active'";
            $pro_active = '';
        }
        ?>
			<ul class='tabs'>
				<li><a href='#authors'<?php 
        echo $pro_active;
        ?>
>Tweet to</a></li>
				<li><a href='#custom'>Options</a></li>
				<li><a href='#notes'<?php 
        echo $free_active;
        ?>
>Notes</a></li>
			</ul>
			<?php 
        /* WPT PRO OPTIONS */
        if (current_user_can('edit_others_posts')) {
            echo "<div class='wptab' id='authors'>";
            if (get_option('jd_individual_twitter_users') == 1) {
                $selected = get_post_meta($post_id, '_wpt_authorized_users', true) ? get_post_meta($post_id, '_wpt_authorized_users', true) : array();
                if (function_exists('wpt_authorized_users')) {
                    echo wpt_authorized_users($selected);
                    do_action('wpt_authors_tab', $post_id, $selected);
                } else {
                    echo "<p>";
                    if (function_exists('wpt_pro_exists')) {
                        printf(__('WP Tweets PRO 1.5.2+ allows you to select Twitter accounts. <a href="%s">Log in and download now!</a>', 'wp-to-twitter'), 'http://www.joedolson.com/articles/account/');
                    } else {
                        printf(__('Upgrade to WP Tweets PRO to select Twitter accounts! <a href="%s">Upgrade now!</a>', 'wp-to-twitter'), 'http://www.joedolson.com/articles/wp-tweets-pro/');
                    }
                    echo "</p>";
                }
            }
            echo "</div>";
        }
        ?>
		<div class='wptab' id='custom'><?php 
        if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true && (current_user_can('wpt_twitter_custom') || current_user_can('update_core'))) {
            wpt_schedule_values($post_id);
            do_action('wpt_custom_tab', $post_id, 'visible');
        } else {
            printf("<p>" . __('Upgrade to WP Tweets PRO to configure options! <a href="%s">Upgrade now!</a>' . "</p>", 'wp-to-twitter'), 'http://www.joedolson.com/articles/wp-tweets-pro/');
        }
        ?>
</div>
		<?php 
        /* WPT PRO */
        if (!current_user_can('wpt_twitter_custom') && !current_user_can('update_core')) {
            ?>
			<div class='wptab' id='custom'>
			<p><?php 
            _e('Access to customizing WP to Twitter values is not allowed for your user role.', 'wp-to-twitter');
            ?>
</p>
			<?php 
            if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
                wpt_schedule_values($post_id, 'hidden');
                do_action('wpt_custom_tab', $post_id, 'hidden');
            }
            ?>
			</div>
			<?php 
        }
        if (current_user_can('wpt_twitter_custom') || current_user_can('update_core')) {
            ?>
			<div class='wptab' id='notes'>
			<p>
			<?php 
            _e("Tweets must be less than 140 characters; Twitter counts URLs as 22 or 23 characters. Template Tags: <code>#url#</code>, <code>#title#</code>, <code>#post#</code>, <code>#category#</code>, <code>#date#</code>, <code>#modified#</code>, <code>#author#</code>, <code>#account#</code>, <code>#tags#</code>, or <code>#blog#</code>.", 'wp-to-twitter');
            do_action('wpt_notes_tab', $post_id);
            ?>
 
			</p>
			</div>
			<?php 
        }
        ?>
		</div>		
		<p class="wpt-support">
		<?php 
        if (!function_exists('wpt_pro_exists')) {
            ?>
			<a target="_blank" href="<?php 
            echo admin_url('options-general.php?page=wp-to-twitter/wp-to-twitter.php');
            ?>
#get-support"><?php 
            _e('Get Support', 'wp-to-twitter', 'wp-to-twitter');
            ?>
</a> &bull; <strong><a target="__blank" href="<?php 
            echo $wpt_donate_url;
            ?>
"><?php 
            _e('Upgrade to WP Tweets Pro', 'wp-to-twitter', 'wp-to-twitter');
            ?>
</a></strong> &raquo;
		<?php 
        } else {
            ?>
			<a target="_blank" href="<?php 
            echo admin_url('admin.php?page=wp-tweets-pro');
            ?>
#get-support"><?php 
            _e('Get Support', 'wp-to-twitter', 'wp-to-twitter');
            ?>
</a> &raquo;
		<?php 
        }
        ?>
		</p>
		<?php 
        wpt_show_tweets($previous_tweets, $failed_tweets);
        ?>
		</div>
		<?php 
    } else {
        // permissions: this user isn't allowed to Tweet;
        _e('Your role does not have the ability to Post Tweets from this site.', 'wp-to-twitter');
        ?>
 <input type='hidden' name='_jd_tweet_this' value='no' /> <?php 
    }
}
Example #2
0
/**
 * Print post meta box
 */
function wpt_add_twitter_inner_box($post)
{
    if (current_user_can('wpt_can_tweet')) {
        $is_pro = function_exists('wpt_pro_exists') ? 'pro' : 'free';
        ?>
		<div class='wp-to-twitter <?php 
        echo $is_pro;
        ?>
'>
			<?php 
        $tweet_status = '';
        $options = get_option('wpt_post_types');
        $type = $post->post_type;
        $status = $post->post_status;
        $post_id = $post->ID;
        $jd_tweet_this = get_post_meta($post_id, '_jd_tweet_this', true);
        if (!$jd_tweet_this) {
            $jd_tweet_this = get_option('jd_tweet_default') == '1' ? 'no' : 'yes';
        }
        if (isset($_GET['action']) && $_GET['action'] == 'edit' && get_option('jd_tweet_default_edit') == '1' && $status == 'publish') {
            $jd_tweet_this = 'no';
        }
        if (isset($_REQUEST['message']) && $_REQUEST['message'] != 10) {
            // don't display when draft is updated or if no message
            if (!($_REQUEST['message'] == 1 && ($status == 'publish' && $options[$type]['post-edited-update'] != 1)) && $jd_tweet_this != 'no') {
                $log = wpt_log('wpt_status_message', $post_id);
                $class = $log != __('Tweet sent successfully.', 'wp-to-twitter') ? 'error' : 'updated';
                if ($log != '') {
                    echo "<div class='{$class}'><p>{$log}</p></div>";
                }
            }
        }
        $previous_tweets = get_post_meta($post_id, '_jd_wp_twitter', true);
        $failed_tweets = get_post_meta($post_id, '_wpt_failed');
        $tweet = esc_attr(stripcslashes(get_post_meta($post_id, '_jd_twitter', true)));
        $tweet = apply_filters('wpt_user_text', $tweet, $status);
        $jd_template = $status == 'publish' ? $options[$type]['post-edited-text'] : $options[$type]['post-published-text'];
        if ($status == 'publish' && $options[$type]['post-edited-update'] != 1) {
            $tweet_status = sprintf(__('Tweeting %s edits is disabled.', 'wp-to-twitter'), $type);
        }
        if ($status == 'publish' && (current_user_can('wpt_tweet_now') || current_user_can('manage_options'))) {
            ?>
			<div class='tweet-buttons'>
				<button class='tweet button-primary'
				        data-action='tweet'><?php 
            _e('Tweet Now', 'wp-to-twitter');
            ?>
</button>
				<?php 
            if (function_exists('wpt_pro_exists') && wpt_pro_exists()) {
                ?>
					<button class='tweet schedule button-secondary' data-action='schedule'
					        disabled><?php 
                _e('Schedule', 'wp-to-twitter');
                ?>
</button>
					<button class='time button-secondary'>
						<span class="dashicons dashicons-clock"><span
								class="screen-reader-text"><?php 
                _e('Set Date/Time', 'wp-to-twitter');
                ?>
</span></span>
					</button>
					<div id="jts">
						<label for='wpt_date'><?php 
                _e('Date', 'wp-to-twitter');
                ?>
</label> 
						<input type='date'
							value=''
							class='date'
							name='wpt_datetime'
							id='wpt_date'
							data-value='<?php 
                echo date('Y-m-d', current_time('timestamp'));
                ?>
' /><br/>
						<label for='wpt_time'><?php 
                _e('Time', 'wp-to-twitter');
                ?>
</label> 
						<input type='text'
							value='<?php 
                echo date_i18n('h:s a', current_time('timestamp') + 3600);
                ?>
'
							class='time'
							name='wpt_datetime'
							id='wpt_time'/>
					</div>
				<?php 
            }
            ?>
				<div class='wpt_log' aria-live='assertive'></div>
			</div>
		<?php 
        }
        if ($tweet_status != '') {
            echo "<p class='disabled'>{$tweet_status}</p>";
        }
        if (current_user_can('wpt_twitter_custom') || current_user_can('manage_options')) {
            ?>
			<p class='jtw'>
				<label
					for="jtw"><?php 
            _e("Custom Twitter Post", 'wp-to-twitter', 'wp-to-twitter');
            ?>
</label><br/><textarea class="wpt_tweet_box" name="_jd_twitter" id="jtw" rows="2"
					cols="60"><?php 
            echo esc_attr($tweet);
            ?>
</textarea>
			</p>
			<?php 
            $jd_expanded = $jd_template;
            if (get_option('jd_twit_prepend') != "") {
                $jd_expanded = "<span title='" . __('Your prepended Tweet text; not part of your template.', 'wp-to-twitter') . "'>" . stripslashes(get_option('jd_twit_prepend')) . "</span> " . $jd_expanded;
            }
            if (get_option('jd_twit_append') != "") {
                $jd_expanded = $jd_expanded . " <span title='" . __('Your appended Tweet text; not part of your template.', 'wp-to-twitter') . "'>" . stripslashes(get_option('jd_twit_append')) . "</span>";
            }
            ?>
			<p class='template'><?php 
            _e('Your template:', 'wp-to-twitter');
            ?>
				<code><?php 
            echo stripcslashes($jd_expanded);
            ?>
</code></p>
			<?php 
            echo apply_filters('wpt_custom_retweet_fields', '', $post_id);
            if (get_option('jd_keyword_format') == 2) {
                $custom_keyword = get_post_meta($post_id, '_yourls_keyword', true);
                echo "<label for='yourls_keyword'>" . __('YOURLS Custom Keyword', 'wp-to-twitter') . "</label> <input type='text' name='_yourls_keyword' id='yourls_keyword' value='{$custom_keyword}' />";
            }
        } else {
            ?>
			<input type="hidden" name='_jd_twitter' value='<?php 
            esc_attr_e($tweet);
            ?>
'/>
		<?php 
        }
        if (current_user_can('wpt_twitter_switch') || current_user_can('manage_options')) {
            // "no" means 'Don't Tweet' (is checked)
            $nochecked = $jd_tweet_this == 'no' ? ' checked="checked"' : '';
            $yeschecked = $jd_tweet_this == 'yes' ? ' checked="checked"' : '';
            ?>
			<p class='toggle-btn-group'>
				<input type="radio" name="_jd_tweet_this" value="no" id="jtn"<?php 
            echo $nochecked;
            ?>
 /><label for="jtn"><?php 
            _e("Don't Tweet post.", 'wp-to-twitter');
            ?>
</label> 
				<input type="radio" name="_jd_tweet_this" value="yes" id="jty"<?php 
            echo $yeschecked;
            ?>
 />
				<label for="jty"><?php 
            _e("Tweet post.", 'wp-to-twitter');
            ?>
</label>
			</p>
		<?php 
        } else {
            ?>
			<input type='hidden' name='_jd_tweet_this' value='<?php 
            echo $jd_tweet_this;
            ?>
'/>
		<?php 
        }
        ?>
		<div class='wpt-options'>
			<?php 
        if ($is_pro == 'pro') {
            $pro_active = " class='active'";
            $free_active = '';
        } else {
            $free_active = " class='active'";
            $pro_active = '';
        }
        ?>
			<ul class='tabs' role="tablist">
				<?php 
        if (get_option('jd_individual_twitter_users') == 1) {
            ?>
					<li><a href='#authors'<?php 
            echo $pro_active;
            ?>
 aria-controls="authors" role="tab" id="tab_authors"><?php 
            _e('Tweet to', 'wp-to-twitter');
            ?>
</a></li>
				<?php 
        }
        ?>
				<li><a href='#custom' aria-controls="custom" role="tab" id="tab_custom"><?php 
        _e('Options', 'wp-to-twitter');
        ?>
</a></li>
				<li><a href='#notes'<?php 
        echo $free_active;
        ?>
 aria-controls="notes" role="tab" id="tab_notes"><?php 
        _e('Notes', 'wp-to-twitter');
        ?>
</a></li>
			</ul>
			<?php 
        /* WPT PRO OPTIONS */
        if (current_user_can('edit_others_posts')) {
            if (get_option('jd_individual_twitter_users') == 1) {
                echo "<div class='wptab' id='authors' aria-labelledby='tab_authors' role='tabpanel'>";
                $selected = get_post_meta($post_id, '_wpt_authorized_users', true) ? get_post_meta($post_id, '_wpt_authorized_users', true) : array();
                if (function_exists('wpt_authorized_users')) {
                    echo wpt_authorized_users($selected);
                    do_action('wpt_authors_tab', $post_id, $selected);
                } else {
                    echo "<p>";
                    if (function_exists('wpt_pro_exists')) {
                        printf(__('WP Tweets PRO allows you to select Twitter accounts. <a href="%s">Log in and download now!</a>', 'wp-to-twitter'), 'http://www.joedolson.com/account/');
                    } else {
                        printf(__('Upgrade to WP Tweets PRO to select Twitter accounts! <a href="%s">Upgrade now!</a>', 'wp-to-twitter'), 'http://www.joedolson.com/wp-tweets-pro/');
                    }
                    echo "</p>";
                }
                echo "</div>";
            }
        }
        ?>
				<div class='wptab' id='custom' aria-labelledby='tab_custom' role='tabpanel'><?php 
        if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true && (current_user_can('wpt_twitter_custom') || current_user_can('manage_options'))) {
            wpt_schedule_values($post_id);
            do_action('wpt_custom_tab', $post_id, 'visible');
        } else {
            if (function_exists('wpt_pro_exists')) {
                echo "<p>" . sprintf(__('Upgrade to WP Tweets PRO to configure options! <a href="%s">Upgrade now!</a>', 'wp-to-twitter'), 'http://www.joedolson.com/wp-tweets-pro/') . "</p>";
            }
        }
        ?>
				</div>
			<?php 
        /* WPT PRO */
        if (!current_user_can('wpt_twitter_custom') && !current_user_can('manage_options')) {
            ?>
				<div class='wptab' id='custom' aria-labelledby='tab_custom' role='tabpanel'>
					<p><?php 
            _e('Access to customizing WP to Twitter values is not allowed for your user role.', 'wp-to-twitter');
            ?>
</p>
					<?php 
            if (function_exists('wpt_pro_exists') && wpt_pro_exists() == true) {
                wpt_schedule_values($post_id, 'hidden');
                do_action('wpt_custom_tab', $post_id, 'hidden');
            }
            ?>
				</div>
			<?php 
        }
        if (current_user_can('wpt_twitter_custom') || current_user_can('manage_options')) {
            ?>
				<div class='wptab' id='notes' aria-labelledby='tab_notes' role='tabpanel'>
					<p>
						<?php 
            _e("Tweets must be less than 140 characters; Twitter counts URLs as 22 or 23 characters. Template Tags: <code>#url#</code>, <code>#title#</code>, <code>#post#</code>, <code>#category#</code>, <code>#date#</code>, <code>#modified#</code>, <code>#author#</code>, <code>#account#</code>, <code>#tags#</code>, or <code>#blog#</code>, <code>#longurl#</code>.", 'wp-to-twitter');
            do_action('wpt_notes_tab', $post_id);
            ?>
					</p>
				</div>
			<?php 
        }
        ?>
		</div>
		<p class="wpt-support">
			<?php 
        if (!function_exists('wpt_pro_exists')) {
            /* These aren't actually usages that require esc_url. But using it will give people the illusion that it does something. */
            ?>
				<a target="_blank"
				   href="<?php 
            echo esc_url(add_query_arg('tab', 'support', admin_url('options-general.php?page=wp-to-twitter/wp-to-twitter.php')));
            ?>
#get-support"><?php 
            _e('Get Support', 'wp-to-twitter', 'wp-to-twitter');
            ?>
</a> &bull;
				<strong><a target="__blank" href="https://www.joedolson.com/wp-tweets-pro/"><?php 
            _e('Go Premium', 'wp-to-twitter', 'wp-to-twitter');
            ?>
</a></strong> &raquo;
			<?php 
        } else {
            ?>
				<a target="_blank"
				   href="<?php 
            echo esc_url(add_query_arg('tab', 'support', admin_url('admin.php?page=wp-tweets-pro')));
            ?>
#get-support"><?php 
            _e('Get Support', 'wp-to-twitter', 'wp-to-twitter');
            ?>
</a> &raquo;
			<?php 
        }
        ?>
		</p>
		<?php 
        wpt_show_tweets($previous_tweets, $failed_tweets);
        ?>
		</div>
	<?php 
    } else {
        // permissions: this user isn't allowed to Tweet;
        _e('Your role does not have the ability to Post Tweets from this site.', 'wp-to-twitter');
        ?>
 <input
			type='hidden' name='_jd_tweet_this' value='no'/> <?php 
    }
}