]> git.wh0rd.org Git - tt-rss.git/commitdiff
rework version checking
authorAndrew Dolgov <fox@fakecake.org>
Tue, 23 Nov 2010 07:30:36 +0000 (10:30 +0300)
committerAndrew Dolgov <fox@fakecake.org>
Tue, 23 Nov 2010 07:30:36 +0000 (10:30 +0300)
functions.php
modules/popup-dialog.php
tt-rss.css
tt-rss.js
tt-rss.php

index 99db938ba93daafacb587367d3eb8df2c090c71e..98e4c688beb3d807480739a2077d7e9b61bc0845 100644 (file)
                        }
                }
 
-               if (CHECK_FOR_NEW_VERSION && $_SESSION["access_level"] >= 10) {
-                       
-                       if ($_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
+               if ($_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) {
                                $new_version_details = @check_for_update($link);
 
-                               $data['new_version_available'] = (int) $new_version_details != "";
+                               $data['new_version_available'] = (int) ($new_version_details != false);
 
                                $_SESSION["last_version_check"] = time();
-                       }
                }
 
                return $data;
        }
 
        function check_for_update($link) {
-               $releases_feed = "http://tt-rss.org/releases.rss";
-
-               if (!CHECK_FOR_NEW_VERSION || $_SESSION["access_level"] < 10) {
-                       return;
-               }
-
-               if (DEFAULT_UPDATE_METHOD == "1") {
-                       $rss = new SimplePie();
-                       $rss->set_useragent(SELF_USER_AGENT);
-                       $rss->set_feed_url($fetch_url);
-                       $rss->set_output_encoding('UTF-8');
-                       $rss->init();
-               } else {
-                       $rss = fetch_rss($releases_feed);
-               }
-
-               if ($rss) {
-
-                       if (DEFAULT_UPDATE_METHOD == "1") {
-                               $items = $rss->get_items();
-                       } else {
-                               $items = $rss->items;
-
-                               if (!$items || !is_array($items)) $items = $rss->entries;
-                               if (!$items || !is_array($items)) $items = $rss;
-                       }
+               if (CHECK_FOR_NEW_VERSION && $_SESSION['access_level'] >= 10) {
+                       $version_url = "http://tt-rss.org/version.php?ver=" . VERSION;
 
-                       if (!is_array($items) || count($items) == 0) {
-                               return;
-                       }                       
+                       $version_data = @fetch_file_contents($version_url);
 
-                       $latest_item = $items[0];
+                       if ($version_data) {
+                               $version_data = json_decode($version_data, true);
+                               if ($version_data && $version_data['version']) {        
 
-                       if (DEFAULT_UPDATE_METHOD == "1") {
-                               $last_title = $latest_item->get_title();
-                       } else {
-                               $last_title = $latest_item["title"];
-                       }
-
-                       $latest_version = trim(preg_replace("/(Milestone)|(completed)/", "", $last_title));
-
-                       if (DEFAULT_UPDATE_METHOD == "1") {
-                               $release_url = sanitize_rss($link, $latest_item->get_link());
-                               $content = sanitize_rss($link, $latest_item->get_description());
-                       } else {
-                               $release_url = sanitize_rss($link, $latest_item["link"]);
-                               $content = sanitize_rss($link, $latest_item["description"]);
+                                       if (version_compare(VERSION, $version_data['version']) == -1) {
+                                               return $version_data['version'];
+                                       }
+                               }
                        }
-
-                       if (version_compare(VERSION, $latest_version) == -1) {
-                               return sprintf("New version of Tiny-Tiny RSS (%s) is available:", 
-                                       $latest_version)."<div class='milestoneDetails'>$content</div>";
-                       } else {
-                               return false;
-                       }       
                }
+               return false;
        }
 
        function markArticlesById($link, $ids, $cmode) {
index 0a272d1a30c17cc43a8de975d55aa202ce7f1ec2..584f6e51df2808dd5274eb54305e60acacb3d248 100644 (file)
 
                        }
 
-                       if ($param == 2) {
-                               $msg = check_for_update($link);
-
-                               if (!$msg) {
-                                       print __("You are running the latest version of Tiny Tiny RSS. The fact that you are seeing this dialog is probably a bug.");
-                               } else {
-                                       print $msg;
-                               }
-
-                       }
-
                        if ($param == 3) {
                                print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner.");
 
                        
                        print "<div align='center'>";
 
-                       print "<button onclick=\"return closeInfoBox()\"".
+                       print "<button onclick=\"return closeInfoBox()\">".
                                __('Close this window')."</button>";
 
                        print "</div>";
                        //return;
                }
 
+               if ($id == "newVersion") {
+                       $version = check_for_update($link);
+
+                       $version_link = "<a class=\"visibleLink\" target=\"_blank\" 
+                               href=\"http://tt-rss.org\">http://tt-rss.org</a>";
+
+                       print "<div class='tagCloudContainer'>";
+
+                       print T_sprintf("New version of Tiny Tiny RSS is available (%s).<br/>Visit %s for more information.", "<b>$version</b>", $version_link);
+
+                       print "</div>";
+
+                       print "<div style='text-align : center'>";
+                       print "<button dojoType=\"dijit.form.Button\" 
+                               onclick=\"return dijit.byId('newVersionDlg').hide()\">".
+                               __('Close this window')."</button>";
+                       print "</div>";
+
+               }
+
                print "</dlg>"; 
        }
 ?>
index 539cf93f3642add4111e89a6837736af6f89c260..69b1abf9c3a59c4f3a191a46d1e894273edfaf05 100644 (file)
@@ -1096,6 +1096,7 @@ div.topLinks {
        float : right;
        color : gray;
        font-size : 12px;
+       line-height : 120%;
 }
 
 div.topLinks a {
@@ -1646,3 +1647,10 @@ a.bookmarklet {
        border : 1px solid #ecf4ff;
        padding : 2px;
 }
+
+#newVersionIcon {
+       margin-left : 5px;
+       vertical-align : middle;
+       position : relative;
+       top : -1px;
+}
index 46ea5a4bb8d22479155a7afad5ea6f9610cbea90..d88554669dec2d58cc50402d9e2b755dce74f32e 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -1107,3 +1107,24 @@ function scheduleFeedUpdate(id, is_cat) {
                exception_error("scheduleFeedUpdate", e);
        }
 }
+
+function newVersionDlg() {
+       try {
+               var query = "backend.php?op=dlg&id=newVersion";
+
+               if (dijit.byId("newVersionDlg"))
+                       dijit.byId("newVersionDlg").destroyRecursive();
+
+               dialog = new dijit.Dialog({
+                       id: "newVersionDlg",
+                       title: __("New version available!"),
+                       style: "width: 600px",
+                       href: query,
+               });
+
+               dialog.show();
+
+       } catch (e) {
+               exception_error("newVersionDlg", e);
+       }
+}
index ceeca35819f8b6fc36f1a39beccdc5f97c0438b1..f51648fef449fe725e6f7bce15e180229496fc73 100644 (file)
                        | <a href="logout.php"><?php echo __('Logout') ?></a>
        <?php } ?>
 
-       <img id="newVersionIcon" style="display:none;" onclick="javascript:explainError(2)" 
+       <img id="newVersionIcon" style="display:none;" onclick="newVersionDlg()" 
                width="13" height="13" 
                src="<?php echo theme_image($link, 'images/new_version.png') ?>"
                title="<?php echo __('New version of Tiny Tiny RSS is available!') ?>"