function widget($args, $instance) { extract($args); $title = $this->get_title($instance); $username = $this->get_username($instance); $gists_count = $this->get_gists_count($instance); echo $before_widget; echo $before_title . $title . $after_title; // Init the cache system. $cache = new Cache(); // 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 href="' . $gist->html_url . '" title="' . $gist->description . '">' . $gist->description . '</a></li>'; } echo '</ul>'; } echo $after_widget; }
/** * 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; }