Ejemplo n.º 1
0
/**
 * Issues shortcode.
 * GET /repos/:owner/:repo/issues
 *
 * @param $atts
 * @return string
 */
function ghpulls_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);
    $pulls = $cache->get($a['username'] . '.' . $a['repository'] . '.pulls.json');
    if ($pulls == NULL) {
        $github = new Github($a['username'], $a['repository']);
        $pulls = $github->get_pulls();
        $cache->set($a['username'] . '.' . $a['repository'] . '.pulls.json', $pulls);
    }
    if (is_array($pulls)) {
        $pulls = array_slice($pulls, 0, $a['limit']);
        $html = '<ul class="wp-github wpg-pulls">';
        foreach ($pulls as $pull) {
            $html .= '<li><span class="wp-github-state ' . $pull->state . '">' . $pull->state . '</span><span class="wp-github-nb">#' . $pull->number . '</span><a target="_blank" href="' . $pull->html_url . '" title="' . $pull->title . '"> ' . $pull->title . '</a></li>';
        }
        $html .= '</ul>';
    } else {
        $html = 'error : ' . $pulls;
    }
    return $html;
}