Ejemplo n.º 1
0
/**
 * Repository presentation shortcode.
 * GET /repos/:owner/:repo
 * @param $atts
 * @return string
 */
function ghclone_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);
    $clone = $cache->get($a['username'] . '.' . $a['repository'] . '.clone.json');
    if ($clone == NULL) {
        $github = new Github($a['username'], $a['repository']);
        $clone = $github->get_clone();
        //var_dump($clone);
        $cache->set($a['username'] . '.' . $a['repository'] . '.clone.json', $clone);
    }
    if (is_object($clone)) {
        $html = '<ul class="wp-github wpg-repo">';
        $html .= '<li>';
        $html .= '<span>SSH URL</span> <input readonly type="text" value="' . $clone->ssh_url . '" />';
        $html .= '</li><li>';
        $html .= '<span>Clone URL</span> <input readonly type="text" value="' . $clone->clone_url . '" />';
        $html .= '</li>';
        $html .= '</ul>';
    } else {
        $html = $clone;
    }
    return $html;
}