]> git.wh0rd.org - tt-rss.git/blobdiff - classes/handler/public.php
syndicated feeds: force sort by last_read for published
[tt-rss.git] / classes / handler / public.php
index aff04597da9c4e01d785f29941c35363e7af51d3..d3c3fc094cba5d6bd38dbf7a64643c4fb23ea031 100644 (file)
@@ -2,7 +2,8 @@
 class Handler_Public extends Handler {
 
        private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
-               $limit, $search, $search_mode, $match_on, $view_mode = false, $format = 'atom') {
+               $limit, $offset, $search, $search_mode, $match_on,
+               $view_mode = false, $format = 'atom') {
 
                require_once "lib/MiniTemplator.class.php";
 
@@ -19,9 +20,12 @@ class Handler_Public extends Handler {
                        $date_sort_field = "date_entered";
                }
 
+               if ($feed == -2)
+                       $date_sort_field = "last_read";
+
                $qfh_ret = queryFeedHeadlines($this->link, $feed,
                        $limit, $view_mode, $is_cat, $search, $search_mode,
-                       $match_on, "$date_sort_field DESC", 0, $owner_uid);
+                       $match_on, "$date_sort_field DESC", $offset, $owner_uid);
 
                $result = $qfh_ret[0];
                $feed_title = htmlspecialchars($qfh_ret[1]);
@@ -195,27 +199,22 @@ class Handler_Public extends Handler {
 
        function getProfiles() {
                $login = db_escape_string($_REQUEST["login"]);
-               $password = db_escape_string($_REQUEST["password"]);
-
-               if (authenticate_user($this->link, $login, $password)) {
-                       $result = db_query($this->link, "SELECT * FROM ttrss_settings_profiles
-                               WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
-
-                       print "<select style='width: 100%' name='profile'>";
 
-                       print "<option value='0'>" . __("Default profile") . "</option>";
+               $result = db_query($this->link, "SELECT * FROM ttrss_settings_profiles,ttrss_users
+                       WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
 
-                       while ($line = db_fetch_assoc($result)) {
-                               $id = $line["id"];
-                               $title = $line["title"];
+               print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
 
-                               print "<option value='$id'>$title</option>";
-                       }
+               print "<option value='0'>" . __("Default profile") . "</option>";
 
-                       print "</select>";
+               while ($line = db_fetch_assoc($result)) {
+                       $id = $line["id"];
+                       $title = $line["title"];
 
-                       $_SESSION = array();
+                       print "<option value='$id'>$title</option>";
                }
+
+               print "</select>";
        }
 
        function pubsub() {
@@ -338,6 +337,7 @@ class Handler_Public extends Handler {
                $key = db_escape_string($_REQUEST["key"]);
                $is_cat = $_REQUEST["is_cat"] != false;
                $limit = (int)db_escape_string($_REQUEST["limit"]);
+               $offset = (int)db_escape_string($_REQUEST["offset"]);
 
                $search = db_escape_string($_REQUEST["q"]);
                $match_on = db_escape_string($_REQUEST["m"]);
@@ -364,7 +364,7 @@ class Handler_Public extends Handler {
 
                if ($owner_id) {
                        $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
-                               $search, $search_mode, $match_on, $view_mode, $format);
+                               $offset, $search, $search_mode, $match_on, $view_mode, $format);
                } else {
                        header('HTTP/1.1 403 Forbidden');
                }
@@ -391,60 +391,321 @@ class Handler_Public extends Handler {
 
                if ($_SESSION["uid"]) {
 
-                       if (!$action) {
+                       if ($action == 'share') {
 
-                               print "<table height='100%' width='100%'><tr><td colspan='2'>";
-                               print "<h1>".__("Share with Tiny Tiny RSS")."</h1>";
-                               print "</td></tr>";
+                               $title = db_escape_string(strip_tags($_REQUEST["title"]));
+                               $url = db_escape_string(strip_tags($_REQUEST["url"]));
+                               $content = db_escape_string(strip_tags($_REQUEST["content"]));
 
-                               print "<form id='share_form' name='share_form'>";
+                               create_published_article($this->link, $title, $url, $content, $_SESSION["uid"]);
 
-                               print "<input type=\"hidden\" name=\"op\" value=\"sharepopup\">";
-                               print "<input type=\"hidden\" name=\"action\" value=\"share\">";
+                               print "<script type='text/javascript'>";
+                               print "window.close();";
+                               print "</script>";
 
+                       } else {
                                $title = htmlspecialchars($_REQUEST["title"]);
                                $url = htmlspecialchars($_REQUEST["url"]);
 
-                               print "<tr><td>".__("Title:")."</td><td width='80%'><input name='title' value=\"$title\"></td></tr>";
-                               print "<tr><td>".__("URL:")."</td><td><input name='url' value=\"$url\"></td></tr>";
-                               print "<tr><td>".__("Content:")."</td><td><input name='content' value=\"\"></td></tr>";
+                               ?>
 
-                               print "<script type='text/javascript'>";
-                               print "document.forms[0].title.focus();";
-                               print "</script>";
+                               <table height='100%' width='100%'><tr><td colspan='2'>
+                               <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
+                               </td></tr>
+
+                               <form id='share_form' name='share_form'>
+
+                               <input type="hidden" name="op" value="sharepopup">
+                               <input type="hidden" name="action" value="share">
+
+                               <tr><td align='right'><?php echo __("Title:") ?></td>
+                               <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
+                               <tr><td align='right'><?php echo __("URL:") ?></td>
+                               <td><input name='url' value="<?php echo $url ?>"></td></tr>
+                               <tr><td align='right'><?php echo __("Content:") ?></td>
+                               <td><input name='content' value=""></td></tr>
+
+                               <script type='text/javascript'>document.forms[0].title.focus();</script>
+
+                               <tr><td colspan='2'>
+                                       <div style='float : right' class='insensitive-small'>
+                                       <?php echo __("Shared article will appear in the Published feed.") ?>
+                                       </div>
+                                       <button type="submit"><?php echo __('Share') ?></button>
+                                       <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
+                                       </div>
+
+                               </form>
+                               </td></tr></table>
+                               </body></html>
+                               <?php
+
+                       }
+
+               } else {
+
+                       $return = urlencode($_SERVER["REQUEST_URI"])
+                       ?>
+
+                       <form action="public.php?return=<?php echo $return ?>"
+                               method="POST" id="loginForm" name="loginForm">
+
+                       <input type="hidden" name="op" value="login">
+
+                       <table height='100%' width='100%'><tr><td colspan='2'>
+                       <h1><?php echo __("Not logged in") ?></h1></td></tr>
+
+                       <tr><td align="right"><?php echo __("Login:") ?></td>
+                       <td align="right"><input name="login"
+                               value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
+                               <tr><td align="right"><?php echo __("Password:") ?></td>
+                               <td align="right"><input type="password" name="password"
+                               value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
+                       <tr><td align="right"><?php echo __("Language:") ?></td>
+                       <td align="right">
+                       <?php
+                               print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
+                                       "style='width : 100%''");
+
+                       ?>
+                       </td></tr>
+                       <tr><td colspan='2'>
+                               <button type="submit">
+                                       <?php echo __('Log in') ?></button>
+
+                               <button onclick="return window.close()">
+                                       <?php echo __('Cancel') ?></button>
+                       </td></tr>
+                       </table>
+
+                       </form>
+                       <?php
+               }
+       }
+
+       function login() {
+
+               $_SESSION["prefs_cache"] = array();
+
+               if (!SINGLE_USER_MODE) {
+
+                       $login = db_escape_string($_POST["login"]);
+                       $password = $_POST["password"];
+                       $remember_me = $_POST["remember_me"];
+
+                       if (authenticate_user($this->link, $login, $password)) {
+                               $_POST["password"] = "";
+
+                               $_SESSION["language"] = $_POST["language"];
+                               $_SESSION["ref_schema_version"] = get_schema_version($this->link, true);
+                               $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
+
+                               if ($_POST["profile"]) {
+
+                                       $profile = db_escape_string($_POST["profile"]);
+
+                                       $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles
+                                               WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
+
+                                       if (db_num_rows($result) != 0) {
+                                               $_SESSION["profile"] = $profile;
+                                               $_SESSION["prefs_cache"] = array();
+                                       }
+                               }
+                       } else {
+                               $_SESSION["login_error_msg"] = __("Incorrect username or password");
+                       }
+
+                       if ($_REQUEST['return']) {
+                               header("Location: " . $_REQUEST['return']);
+                       } else {
+                               header("Location: " . SELF_URL_PATH);
+                       }
+               }
+       }
+
+       function subscribe() {
+               if ($_SESSION["uid"]) {
+
+                       $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
+
+                       header('Content-Type: text/html; charset=utf-8');
+                       print "<html>
+                               <head>
+                                       <title>Tiny Tiny RSS</title>
+                                       <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
+                                       <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
+                               </head>
+                               <body>
+                               <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
+                                       alt=\"Tiny Tiny RSS\"/>
+                                       <h1>".__("Subscribe to feed...")."</h1>";
+
+                       $rc = subscribe_to_feed($this->link, $feed_url);
+
+                       switch ($rc['code']) {
+                       case 0:
+                               print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
+                               break;
+                       case 1:
+                               print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
+                               break;
+                       case 2:
+                               print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
+                               break;
+                       case 3:
+                               print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
+                               break;
+                       case 4:
+                               print_notice(__("Multiple feed URLs found."));
+                               $feed_urls = $rc["feeds"];
+                               break;
+                       case 5:
+                               print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
+                               break;
+                       }
 
-                               print "<tr><td colspan='2'>
-                                       <div style='float : right' class='insensitive-small'>".
-                                       __("Shared article will appear in the Published feed.").
-                                       "</div><button type=\"submit\">".
-                                               __('Share')."</button>
-                                       <button onclick=\"return window.close()\">".
-                                               __('Cancel')."</button>
-                                       </div>";
+                       if ($feed_urls) {
+
+                               print "<form action=\"public.php\">";
+                               print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
+
+                               print "<select name=\"feed_url\">";
+
+                               foreach ($feed_urls as $url => $name) {
+                                       $url = htmlspecialchars($url);
+                                       $name = htmlspecialchars($name);
+
+                                       print "<option value=\"$url\">$name</option>";
+                               }
+
+                               print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
+                                       "\">";
 
                                print "</form>";
-                               print "</td></tr></table>";
+                       }
+
+                       $tp_uri = get_self_url_prefix() . "/prefs.php";
+                       $tt_uri = get_self_url_prefix();
 
-                               print "</body></html>";
+                       if ($rc['code'] <= 2){
+                               $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
+                                       feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
 
+                               $feed_id = db_fetch_result($result, 0, "id");
                        } else {
+                               $feed_id = 0;
+                       }
+                       print "<p>";
+
+                       if ($feed_id) {
+                               print "<form method=\"GET\" style='display: inline'
+                                       action=\"$tp_uri\">
+                                       <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
+                                       <input type=\"hidden\" name=\"method\" value=\"editFeed\">
+                                       <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
+                                       <input type=\"submit\" value=\"".__("Edit subscription options")."\">
+                                       </form>";
+                       }
 
-                               $title = db_escape_string(strip_tags($_REQUEST["title"]));
-                               $url = db_escape_string(strip_tags($_REQUEST["url"]));
-                               $content = db_escape_string(strip_tags($_REQUEST["content"]));
+                       print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
+                               <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
+                               </form></p>";
 
-                               create_published_article($this->link, $title, $url, $content, $_SESSION["uid"]);
+                       print "</body></html>";
 
-                               print "<script type='text/javascript'>";
-                               print "window.close();";
-                               print "</script>";
+               } else {
+                       render_login_form($this->link);
+               }
+       }
+
+       function subscribe2() {
+               $feed_url = db_escape_string(trim($_REQUEST["feed_url"]));
+               $cat_id = db_escape_string($_REQUEST["cat_id"]);
+               $from = db_escape_string($_REQUEST["from"]);
+
+               /* only read authentication information from POST */
+
+               $auth_login = db_escape_string(trim($_POST["auth_login"]));
+               $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
+
+               $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
+
+               switch ($rc) {
+               case 1:
+                       print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
+                       break;
+               case 2:
+                       print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
+                       break;
+               case 3:
+                       print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
+                       break;
+               case 0:
+                       print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
+                       break;
+               case 4:
+                       print_notice(__("Multiple feed URLs found."));
+
+                       $feed_urls = get_feeds_from_html($feed_url);
+                       break;
+               case 5:
+                       print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
+                       break;
+               }
+
+               if ($feed_urls) {
+                       print "<form action=\"backend.php\">";
+                       print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
+                       print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
+                       print "<input type=\"hidden\" name=\"method\" value=\"add\">";
+
+                       print "<select name=\"feed_url\">";
+
+                       foreach ($feed_urls as $url => $name) {
+                               $url = htmlspecialchars($url);
+                               $name = htmlspecialchars($name);
+                               print "<option value=\"$url\">$name</option>";
                        }
 
+                       print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
+                       print "</form>";
+               }
+
+               $tp_uri = get_self_url_prefix() . "/prefs.php";
+               $tt_uri = get_self_url_prefix();
+
+               if ($rc <= 2){
+                       $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
+                               feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
+
+                       $feed_id = db_fetch_result($result, 0, "id");
                } else {
+                       $feed_id = 0;
+               }
 
-                       print "<table><tr><td>" . __("Not logged in.") . "</td></tr></table>";
+               print "<p>";
 
+               if ($feed_id) {
+                       print "<form method=\"GET\" style='display: inline'
+                               action=\"$tp_uri\">
+                               <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
+                               <input type=\"hidden\" name=\"method\" value=\"editFeed\">
+                               <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
+                               <input type=\"submit\" value=\"".__("Edit subscription options")."\">
+                               </form>";
                }
+
+               print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
+                       <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
+                       </form></p>";
+
+               print "</body></html>";
+       }
+
+       function index() {
+               header("Content-Type: text/plain");
+               print json_encode(array("error" => array("code" => 7)));
        }
 
 }