예제 #1
0
function ozh_ta_do_page()
{
    global $ozh_ta;
    ?>
    <div class="wrap">
    <?php 
    screen_icon();
    ?>
    <h2>Ozh' Tweet Archiver</h2>
	<style>
	fieldset.ozh_ta_fs {
		border:1px solid #ddd;
		padding:2px 10px;
		padding-bottom:10px;
		margin-bottom:10px;
	}
	
	</style>
	<?php 
    if (ozh_ta_is_debug()) {
        echo "<pre style='border:1px solid;padding:5px 15px;'>";
        var_dump($ozh_ta);
        echo "</pre>";
    }
    if (wp_next_scheduled('ozh_ta_cron_import') && !ozh_ta_is_manually_archiving()) {
        ozh_ta_do_page_scheduled();
    }
    if (ozh_ta_is_configured()) {
        ozh_ta_do_page_manual();
    }
    // Option page when not doing operation
    if (!isset($_GET['action']) or $_GET['action'] != 'import_all') {
        ?>
	    <form action="options.php" method="post">
		<?php 
        settings_fields('ozh_ta');
        ?>
		<?php 
        do_settings_sections('ozh_ta');
        ?>
		<script type="text/javascript">
		(function($){
			$('.toggler').change(function(){
				var id = $(this).attr('id');
				var val = $(this).val();
				$('.toggle_'+id).hide();
				$('#toggle_'+id+'_'+val).show();
				pulse('#toggle_'+id+'_'+val );
			});
			
			var maxw = 0;
			$('select').each(function(i,e){
				var w = jQuery(this).css('width').replace('px', '');
				maxw = Math.max( maxw, w );
			}).css('width', maxw+'px');
			
			$('#link_hashtags').change(function(){
				if( $(this).val() == 'local' ) {
					pulse( $('#add_hash_as_tags').val('yes').change() );
				}
			});
			
			$('#add_hash_as_tags').change(function(){
				if( $(this).val() == 'no' && $('#link_hashtags').val() == 'local' ) {
					pulse( $('#link_hashtags').val('twitter').change() );
				}
			});
			
			function pulse( el ){
			var bg = $(el).css('backgroundColor');
			$(el).animate({backgroundColor: '#ff4'}, 500, function(){
				$(el).animate({backgroundColor: bg}, 500, function(){
					$(el).css('backgroundColor', bg);
				});
			});
			}
		
		})(jQuery);
		</script>
        <?php 
        submit_button();
        submit_button('Reset all settings', 'delete', 'delete_btn');
        ?>
        <script>
        (function($){
        $('#delete_btn').click( function() {
            if (!confirm('Really reset everything? No undo!')) {
                return false;
            }
        });
        })(jQuery);
        </script>
	    </form>
	<?php 
    }
    ?>

	</div>
    <?php 
}
예제 #2
0
/**
 * Fetch a single tweet
 *
 * This function is not used in the plugin, it's here to be used when debugging or for custom use
 *
 * @param  string $id   Tweet ID ('454752497002115072' in 'https://twitter.com/ozh/statuses/454752497002115072')
 * @return bool|object  false if not found, or tweet object (see https://dev.twitter.com/docs/platform-objects/tweets)
 */
function ozh_ta_get_single_tweet($id)
{
    global $ozh_ta;
    if (!ozh_ta_is_configured()) {
        ozh_ta_debug('Config incomplete, cannot import tweets');
        return false;
    }
    $api = 'https://api.twitter.com/1.1/statuses/show.json?id=' . $id;
    $headers = array('Authorization' => 'Bearer ' . $ozh_ta['access_token']);
    ozh_ta_debug("Polling {$api}");
    $response = wp_remote_get($api, array('headers' => $headers, 'timeout' => 10));
    $tweet = json_decode(wp_remote_retrieve_body($response));
    if (isset($tweet->errors)) {
        ozh_ta_debug("Error with tweet #{$id} : " . $tweet->errors[0]->message);
        return false;
    }
    return $tweet;
}
예제 #3
0
function ozh_ta_plugin_actions($actions)
{
    global $ozh_ta;
    $class = '';
    $text = 'Configure';
    if (!ozh_ta_is_configured()) {
        $class = 'delete';
        $text .= ' now!';
    }
    $actions['ozh_ta ' . $class] = '<a class="' . $class . '" href="' . menu_page_url('ozh_ta', false) . '">' . $text . '</a>';
    return $actions;
}