示例#1
0
<?php

// Check if the author of this post is connected to the Twitter importer,
// if so load their Twitter avatar, if not use their Gravatar
$icon_size = 35;
// In px, how big (square) should the avatar/icon be?
// I'm being a horrible person and accessing options directly to avoid re-loading all the importer code
if (class_exists('Keyring')) {
    if ($importer = get_option('keyring_twitter_importer')) {
        if ($token = $importer['token']) {
            $token = Keyring::get_token_store()->get_token(array('id' => $token, 'type' => 'access'));
            $url = $token->get_meta('picture');
            if ($url) {
                // Use Photon (if available) to resize their icon properly
                if (function_exists('jetpack_photon_url')) {
                    $url = jetpack_photon_url($url, array('resize' => "{$icon_size},{$icon_size}", 'filter' => 'grayscale'));
                }
                // Output that sucka
                echo '<a href="' . get_author_posts_url(false, get_the_author_meta('ID')) . '">';
                echo '<img src="' . esc_url($url) . '" class="format-icon" width="' . esc_attr($icon_size) . '" height="' . esc_attr($icon_size) . '" alt="" />';
                echo '</a>';
                return;
                // Avoid doing the Gravatar, below
            }
        }
    }
}
// No Twitter connection, try to use their Gravatar instead
$gravatar = get_avatar(get_the_author_meta('ID'), $icon_size);
$gravatar = str_replace("class='", "class='format-icon ", $gravatar);
echo '<a href="' . get_author_posts_url(false, get_the_author_meta('ID')) . '">';
示例#2
0
 function __construct()
 {
     $this->keyring = Keyring::init();
     parent::__construct(array('singular' => 'connection', 'plural' => 'connections', 'screen' => $this->keyring->admin_page));
     $this->items = Keyring::get_token_store()->get_tokens();
 }
示例#3
0
 function is_connected()
 {
     $c = get_called_class();
     return Keyring::get_token_store()->count(array('service' => $c::NAME));
 }
 /**
  * Early handling/validation etc of requests within the importer. This is hooked in early
  * enough to allow for redirecting the user if necessary.
  */
 function handle_request()
 {
     // Only interested in POST requests and specific GETs
     if (empty($_GET['import']) || static::SLUG != $_GET['import']) {
         return;
     }
     // Heading to a specific step of the importer
     if (!empty($_REQUEST['step']) && ctype_alpha($_REQUEST['step'])) {
         $this->step = (string) $_REQUEST['step'];
     }
     switch ($this->step) {
         case 'greet':
             if (!empty($_REQUEST[static::SLUG . '_token'])) {
                 // Coming into the greet screen with a token specified.
                 // Set it internally as our access token and then initiate the Service for it
                 $this->set_option('token', (int) $_REQUEST[static::SLUG . '_token']);
                 $this->service = call_user_func(array(static::KEYRING_SERVICE, 'init'));
                 $token = Keyring::get_token_store()->get_token(array('service' => static::SLUG, 'id' => (int) $_REQUEST[static::SLUG . '_token']));
                 $this->service->set_token($token);
             }
             if ($this->service && $this->service->get_token()) {
                 // If a token has been selected (and is available), then jump to the next setp
                 $this->step = 'options';
             } else {
                 // Otherwise reset all default/built-ins
                 $this->set_option(array('category' => null, 'tags' => null, 'author' => null, 'auto_import' => null));
             }
             break;
         case 'options':
             // Clear token and start again if a reset was requested
             if (isset($_POST['reset'])) {
                 $this->reset();
                 $this->step = 'greet';
                 break;
             }
             // If we're "refreshing", then just act like it's an auto import
             if (isset($_POST['refresh'])) {
                 $this->auto_import = true;
             }
             // Write a custom request handler in the extending class here
             // to handle processing/storing options for import. Make sure to
             // end it with $this->step = 'import' (if you're ready to continue)
             $this->handle_request_options();
             break;
     }
 }