/** * Repository Releases shortcode. * List releases as a li * @param $atts * @return string */ function ghreleases_shortcode($atts) { $a = shortcode_atts(array('username' => get_option('wpgithub_defaultuser', 'seinoxygen'), 'repository' => get_option('wpgithub_defaultrepo', 'wp-github'), 'limit' => '5'), $atts); // Init the cache system. $cache = new WpGithubCache(); // Set custom timeout in seconds. $cache->timeout = get_option('wpgithub_cache_time', 600); $releases = $cache->get($a['username'] . '.' . $a['repository'] . '.releases.json'); if ($releases == NULL) { $github = new Github($a['username'], $a['repository']); $data = $github->get_releases(); $cache->set($a['username'] . '.' . $a['repository'] . '.releases.json', $data); } $releases = $cache->get($a['username'] . '.' . $a['repository'] . '.releases.json'); if (is_array($releases)) { $releases = array_slice($releases, 0, $a['limit']); $html = '<ul class="wp-github wpg-releases">'; foreach ($releases as $release) { $html .= '<li><a target="_blank" href="' . $release->zipball_url . '" title="' . $release->name . '">' . __('Download', 'wp-github') . ' ' . $release->tag_name . '</a></li>'; } $html .= '</ul>'; } else { $html = 'Please refresh'; } return $html; }