示例#1
0
 function widget($args, $instance)
 {
     extract($args);
     $title = $this->get_title($instance);
     $username = $this->get_username($instance);
     $gists_count = $this->get_gists_count($instance);
     echo $args['before_widget'];
     echo $args['before_title'] . $title . $args['after_title'];
     // Init the cache system.
     $cache = new WpGithubCache();
     // Set custom timeout in seconds.
     $cache->timeout = get_option('wpgithub_cache_time', 600);
     $gists = $cache->get($username . '.gists.json');
     if ($gists == NULL) {
         $github = new Github($username);
         $gists = $github->get_gists();
         $cache->set($username . '.gists.json', $gists);
     }
     if ($gists == NULL || count($gists) == 0) {
         echo $username . ' does not have any public gists.';
     } else {
         $gists = array_slice($gists, 0, $gists_count);
         echo '<ul>';
         foreach ($gists as $gist) {
             echo '<li><a target="_blank" href="' . $gist->html_url . '" title="' . $gist->description . '">' . $gist->description . '</a></li>';
         }
         echo '</ul>';
     }
     echo $args['after_widget'];
 }
示例#2
0
/**
 * Gists shortcode.
 * @param $atts
 * @return string
 */
function ghgists_shortcode($atts)
{
    $a = shortcode_atts(array('username' => get_option('wpgithub_defaultuser', 'seinoxygen'), 'limit' => '5'), $atts);
    // Init the cache system.
    $cache = new WpGithubCache();
    // Set custom timeout in seconds.
    $cache->timeout = get_option('wpgithub_cache_time', 600);
    $gists = $cache->get($a['username'] . '.gists.json');
    if ($gists == NULL) {
        $github = new Github($a['username']);
        $gists = $github->get_gists();
        $cache->set($a['username'] . '.gists.json', $gists);
    }
    if (is_array($gists)) {
        $gists = array_slice($gists, 0, $a['limit']);
    }
    $html = '<ul class="wp-github wpg-gists">';
    foreach ($gists as $gist) {
        $html .= '<li><a target="_blank" href="' . $gist->html_url . '" title="' . $gist->description . '">' . $gist->description . '</a></li>';
    }
    $html .= '</ul>';
    return $html;
}