]> git.wh0rd.org - tt-rss.git/blame - plugins/updater/updater.php
split self-updater gui to updater/ plugin
[tt-rss.git] / plugins / updater / updater.php
CommitLineData
5cedb389
AD
1<?php
2class Updater extends Plugin {
3
4 private $link;
5 private $host;
6
7 function __construct($host) {
8 $this->link = $host->get_link();
9 $this->host = $host;
10
11 $host->add_hook($host::HOOK_PREFS_TAB, $this);
12 }
13
14 function get_prefs_js() {
15 return file_get_contents(dirname(__FILE__) . "/updater.js");
16 }
17
18 function hook_prefs_tab($args) {
19 if ($args != "prefPrefs") return;
20
21 if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE) && CHECK_FOR_NEW_VERSION) {
22 print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Update Tiny Tiny RSS')."\">";
23
24 if ($_SESSION["pref_last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
25 $_SESSION["version_data"] = @check_for_update($this->link);
26 $_SESSION["pref_last_version_check"] = time();
27 }
28
29 if (is_array($_SESSION["version_data"])) {
30 $version = $_SESSION["version_data"]["version"];
31 print_notice(T_sprintf("New version of Tiny Tiny RSS is available (%s).", "<b>$version</b>"));
32
33 print "<p><button dojoType=\"dijit.form.Button\" onclick=\"return updateSelf()\">".
34 __('Update Tiny Tiny RSS')."</button></p>";
35
36 } else {
37 print_notice(__("Your Tiny Tiny RSS installation is up to date."));
38 }
39
40 print "</div>"; #pane
41 }
42
43 function updateSelf() {
44 print "<form style='display : block' name='self_update_form' id='self_update_form'>";
45
46 print "<div class='error'>".__("Do not close this dialog until updating is finished. Backup your tt-rss directory before continuing.")."</div>";
47
48 print "<ul class='selfUpdateList' id='self_update_log'>";
49 print "<li>" . __("Ready to update.") . "</li>";
50 print "</ul>";
51
52 print "<div class='dlgButtons'>";
53 print "<button id=\"self_update_start_btn\" dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('updateSelfDlg').start()\" >".
54 __("Start update")."</button>";
55 print "<button id=\"self_update_stop_btn\" onclick=\"return dijit.byId('updateSelfDlg').close()\" dojoType=\"dijit.form.Button\">".
56 __("Close this window")."</button>";
57 print "</div>";
58 print "</form>";
59 }
60
61 function performUpdate() {
62 $step = (int) $_REQUEST["step"];
63 $params = json_decode($_REQUEST["params"], true);
64 $force = (bool) $_REQUEST["force"];
65
66 if (($_SESSION["access_level"] >= 10 || SINGLE_USER_MODE) && CHECK_FOR_NEW_VERSION) {
67 include "update_self.php";
68
69 print json_encode(update_self_step($this->link, $step, $params, $force));
70 }
71 }
72
73
74 }
75}
76?>