Permalink
Browse files

Added GitHub wiki links;

Cleaned up the issues functions;
Made the issues (as well as the wiki) appear only if GitHub says they exist;
At index.php, removed the ".." in favor of dirname(__DIR__), to stop Savant from complaining.
  • Loading branch information...
boenrobot committed Aug 12, 2012
1 parent dde7bf6 commit ec6ea9bcd1c9e16c64cf06468850e548e1cbfd5d
@@ -24,6 +24,21 @@ public function getShortName()
{
return $this->shortName;
}
+
+ public function hasGitHubWiki()
+ {
+ return $this->getGithubInfo()->has_wiki;
+ }
+
+ public function getGitHubWikiLink()
+ {
+ return self::GIT_HUB_LINK . $this->shortName . '/wiki';
+ }
+
+ public function hasGitHubIssues()
+ {
+ return $this->getGithubInfo()->has_issues;
+ }
public function getGitHubNewIssueLink()
{
@@ -44,7 +59,7 @@ public function getGitHubIssueCount($state)
{
$count = 0;
- $key = $this->name."-{$state}-issues";
+ $key = $this->name . "-{$state}-issues";
$json = $this->cache->get($key);
if ($json === false) {
@@ -63,14 +78,24 @@ public function getGitHubIssueCount($state)
return $count;
}
-
- public function getGitHubClosedIssueCount()
+
+ protected function getGithubInfo()
{
- return $this->getGitHubIssueCount('closed');
- }
+ $key = $this->name . "-wiki";
+ $json = $this->cache->get($key);
- public function getGitHubOpenIssueCount()
- {
- return $this->getGitHubIssueCount('open');
+ if ($json === false) {
+ $uri = self::GIT_HUB_API . $this->shortName;
+ $json = is_file($uri) && file_get_contents($uri);
+ if ($json === false) {
+ $json = $this->cache->get($key, 'default', false);
+ } else {
+ $this->cache->save($json, $key);
+ }
+ }
+
+ return $json === false
+ ? (object) array('has_wiki' => false, 'has_issues' => false)
+ : json_decode($json);
}
}
View
@@ -42,7 +42,7 @@
$savant->setClassToTemplateMapper(new \PEAR2Web\TemplateMapper());
$savant->setTemplatePath(
array(
- __DIR__ . '/../vendor/www/pear2.php.net/PEAR2_SimpleChannelFrontend/templates/html/',
+ dirname(__DIR__) . '/vendor/www/pear2.php.net/PEAR2_SimpleChannelFrontend/templates/html/',
__DIR__ . '/templates/pear2/html',
)
);
@@ -53,7 +53,7 @@
break;
case 'rss':
$savant->addTemplatePath(
- __DIR__ . '/../vendor/www/pear2.php.net/PEAR2_SimpleChannelFrontend/templates/rss/'
+ dirname(__DIR__) . '/vendor/www/pear2.php.net/PEAR2_SimpleChannelFrontend/templates/rss/'
);
break;
}
@@ -1,14 +1,14 @@
<?php
-$openCount = $context->getGitHubOpenIssueCount();
+$openCount = $context->getGitHubIssueCount('open');
if ($openCount == 0) {
echo '<span>none open</span>';
} else {
echo '<a href="' . $context->getGitHubOpenIssuesLink() . '" class="package-bugs-open">' . $openCount . ' open</a>';
}
-$closedCount = $context->getGitHubClosedIssueCount();
+$closedCount = $context->getGitHubIssueCount('closed');
if ($closedCount > 0) {
echo ', <a href="' . $context->getGitHubClosedIssuesLink() . '" class="package-bugs-closed">' . $closedCount . ' closed</a>';
@@ -51,12 +51,23 @@
?>
</td>
</tr>
+<?php
+if ($context->hasGitHubWiki()) {
+?> <tr>
+ <th>Documentation:</th>
+ <td><a href="<?php echo $context->getGitHubWikiLink() ?>">GitHub Wiki</a></td>
+ </tr>
+<?php
+}
+
+if ($context->hasGitHubIssues()) {
+?>
<tr>
<th>Issues:</th>
<td><?php echo $savant->render($context, 'PackageBugs.tpl.php'); ?></td>
</tr>
-
<?php
+}
if ( isset($parent->parent->context->options)
&& $parent->parent->context->options['view'] === 'package'
) {

0 comments on commit ec6ea9b

Please sign in to comment.