예제 #1
0
/**
 * Latest Release shortcode.
 *
 * @param $atts
 * @return string
 */
function ghreleaseslatest_shortcode($atts)
{
    $a = shortcode_atts(array('username' => get_option('wpgithub_defaultuser', 'seinoxygen'), 'repository' => get_option('wpgithub_defaultrepo', 'wp-github')), $atts);
    // Init the cache system.
    $cache = new WpGithubCache();
    // Set custom timeout in seconds.
    $cache->timeout = get_option('wpgithub_cache_time', 600);
    $latest_release = $cache->get($a['username'] . '.' . $a['repository'] . '.releaseslatest.json');
    if ($latest_release == NULL) {
        $github = new Github($a['username'], $a['repository']);
        $latest_release = $github->get_latest_release();
        //var_dump($releases);
        $cache->set($a['username'] . '.' . $a['repository'] . '.releaseslatest.json', $latest_release);
    }
    if (is_object($latest_release)) {
        $html = '<div class="wp-github wpg-releaselatest">';
        $html .= '<a class="wpgithub-btn" target="_blank" href="' . $latest_release->zipball_url . '" title="' . $latest_release->tag_name . '">' . __('Download', 'wp-github') . ' ' . $latest_release->tag_name . '</a>';
        $html .= ' - <a target="_blank" href="' . $latest_release->html_url . '" title="' . $latest_release->tag_name . '">' . __('Show on Github', 'wp-github') . '</a>';
        if (!empty($latest_release->body)) {
            $html .= '<div class="wpgithub-description"><p>' . __('Description', 'wp-github') . ':';
            $html .= $latest_release->body;
            $html .= '</p></div>';
        }
        $html .= '</div>';
    } else {
        if ($latest_release == '404') {
            $html = 'Release not found';
        } else {
            $html = $latest_release;
        }
    }
    return $html;
}