Skip to content

Commit

Permalink
Adds in update checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Krytic committed Feb 7, 2016
1 parent 57cbff3 commit e51ca43
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
26 changes: 24 additions & 2 deletions Upload/admin/modules/wiki/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,36 @@
}
else if ($mybb->input['action'] == "version_check")
{
$updateurl = 'https://api.github.com/repos/Krytic/MyBBWiki/releases/latest';

$page->output_nav_tabs($sub_tabs, 'wiki');

$table = new Table;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Not ideal in the least but we're not passing sensitive data. See: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
curl_setopt($ch, CURLOPT_USERAGENT, 'MyBBWiki by Krytic Update Checker. https://github.com/Krytic');
curl_setopt($ch, CURLOPT_URL, $updateurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

$latest_release = json_decode($data, true);

$latest_release['tag_name2'] = str_replace('v', '', $latest_release['tag_name']); // releases are formatted v1.0.0 or v1.5.7

if(version_compare(WIKI_VERSION, $latest_release['tag_name2']) < 0 && !$latest_release['prerelease']) {
$table->construct_header($lang->sprintf($lang->wiki_new_version, $latest_release['tag_name']), array("colspan" => 2));
$table->construct_row();

$table->construct_cell($latest_release['body']);
$table->construct_cell("<a href=\"{$latest_release['html_url']}\">" . $lang->new_release_download . "</a>", array('class' => 'align_center'));
$table->construct_row();
$table->output($lang->wiki_updates_header);
}

$table->construct_cell($lang->wiki_updates, array("class" => "align_center"));
$table->construct_row();

$table->output($lang->wiki_updates_head);
}

$page->output_footer();
Expand Down
2 changes: 2 additions & 0 deletions Upload/inc/languages/english/admin/wiki.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
$l['wiki_wip'] = "<h1>WIP</h1>";
$l['wiki_description'] = "Thank you for downloading the MyBB Wiki plugin.";
$l['wiki_home'] = "Welcome to MyBB Wiki";
$l['wiki_new_version'] = "New version ({1}) available!";
$l['new_release_download'] = "Download on GitHub";
$l['wiki_welcome'] = "<h1>Wiki Admin Control Panel</h1>";
$l['wiki_total_articles'] = "<h2>{1} article{2}</h2>";
$l['wiki_total_cats'] = "<h2>{1} categor{2}</h2>";
Expand Down
2 changes: 1 addition & 1 deletion Upload/inc/plugins/wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
die('Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.');
}

define("WIKI_VERSION", "1.0");
define("WIKI_VERSION", "1.0.1"); // cheeky placement means that we're able to access this constant from anywhere.

$plugins->add_hook('global_start', 'wiki_build_link_definitions');
$plugins->add_hook('fetch_wol_activity_end', 'wiki_fetch_wol');
Expand Down

0 comments on commit e51ca43

Please sign in to comment.