function widget($args, $instance) { extract($args); $title = $this->get_title($instance); $username = $this->get_username($instance); $repository = $this->get_repository($instance); $issue_count = $this->get_issue_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); $issues = $cache->get($username . '.' . $repository . '.issues.json'); if ($issues == null) { $github = new Github($username, $repository); $issues = $github->get_issues(); $cache->set($username . '.' . $repository . '.issues.json', $issues); } if ($issues == null || count($issues) == 0) { echo $username . ' does not have any public issues.'; } else { $issues = array_slice($issues, 0, $issue_count); echo '<ul>'; foreach ($issues as $issue) { echo '<li><a href="' . $issue->html_url . '" title="' . $issue->title . '">' . $issue->title . '</a></li>'; } echo '</ul>'; } echo $after_widget; }
/** * Issues shortcode. * GET /repos/:owner/:repo/issues * * @param $atts * @return string */ function ghissues_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); $issues = $cache->get($a['username'] . '.' . $a['repository'] . '.issues.json'); if ($issues == NULL) { $github = new Github($a['username'], $a['repository']); $issues = $github->get_issues(); $cache->set($a['username'] . '.' . $a['repository'] . '.issues.json', $issues); } if (is_array($issues)) { $issues = array_slice($issues, 0, $a['limit']); $html = '<ul class="wp-github wpg-issues">'; foreach ($issues as $issue) { $html .= '<li><span class="wp-github-state ' . $issue->state . '">' . $issue->state . '</span><span class="wp-github-nb">#' . $issue->number . '</span><a target="_blank" href="' . $issue->html_url . '" title="' . $issue->title . '"> ' . $issue->title . '</a></li>'; } $html .= '</ul>'; } else { $html = 'error : ' . $issues; } return $html; }