]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
add hack to support arbitrary key descriptions for hotkeys
[tt-rss.git] / include / functions.php
index 89e767e2ce872f861836df406404bdcb9fbd7520..ac3a8861e0cc33c633ca60f9d330e118dc3b2e3e 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        define('EXPECTED_CONFIG_VERSION', 26);
-       define('SCHEMA_VERSION', 101);
+       define('SCHEMA_VERSION', 102);
 
        $fetch_last_error = false;
        $pluginhost = false;
 
                        global $pluginhost;
                        $pluginhost->load($plugins, $pluginhost::KIND_USER, $owner_uid);
-                       $pluginhost->load_data();
+
+                       if (get_schema_version($link) > 100) {
+                               $pluginhost->load_data();
+                       }
                }
        }
 
                $params["num_feeds"] = (int) $num_feeds;
 
                $params["collapsed_feedlist"] = (int) get_pref($link, "_COLLAPSED_FEEDLIST");
+               $params["hotkeys"] = get_hotkeys_map($link);
 
                $params["csrf_token"] = $_SESSION["csrf_token"];
+               $params["widescreen"] = (int) $_SESSION["widescreen"];
 
                return $params;
        }
 
+       function get_hotkeys_info($link) {
+               $hotkeys = array(
+                       __("Navigation") => array(
+                               "next_feed" => __("Open next feed"),
+                               "prev_feed" => __("Open previous feed"),
+                               "next_article" => __("Open next article"),
+                               "prev_article" => __("Open previous article"),
+                               "search_dialog" => __("Show search dialog")),
+                       __("Article") => array(
+                               "toggle_mark" => __("Toggle starred"),
+                               "toggle_publ" => __("Toggle published"),
+                               "toggle_unread" => __("Toggle unread"),
+                               "edit_tags" => __("Edit tags"),
+                               "dismiss_selected" => __("Dismiss selected"),
+                               "dismiss_read" => __("Dismiss read"),
+                               "open_in_new_window" => __("Open in new window"),
+                               "catchup_below" => __("Mark below as read"),
+                               "catchup_above" => __("Mark above as read"),
+                               "article_scroll_down" => __("Scroll down"),
+                               "article_scroll_up" => __("Scroll up"),
+                               "select_article_cursor" => __("Select article under cursor"),
+                               "email_article" => __("Email article"),
+                               "toggle_widescreen" => __("Toggle widescreen mode")),
+                       __("Article selection") => array(
+                               "select_all" => __("Select all articles"),
+                               "select_unread" => __("Select unread"),
+                               "select_marked" => __("Select starred"),
+                               "select_published" => __("Select published"),
+                               "select_invert" => __("Invert selection"),
+                               "select_none" => __("Deselect everything")),
+                       __("Feed") => array(
+                               "feed_refresh" => __("Refresh current feed"),
+                               "feed_unhide_read" => __("Un/hide read feeds"),
+                               "feed_subscribe" => __("Subscribe to feed"),
+                               "feed_edit" => __("Edit feed"),
+                               "feed_catchup" => __("Mark as read"),
+                               "feed_reverse" => __("Reverse headlines"),
+                               "feed_debug_update" => __("Debug feed update"),
+                               "catchup_all" => __("Mark all feeds as read"),
+                               "cat_toggle_collapse" => __("Un/collapse current category")),
+                       __("Go to") => array(
+                               "goto_all" => __("All articles"),
+                               "goto_fresh" => __("Fresh"),
+                               "goto_marked" => __("Starred"),
+                               "goto_published" => __("Published"),
+                               "goto_tagcloud" => __("Tag cloud"),
+                               "goto_prefs" => __("Preferences")),
+                       __("Other") => array(
+                               "create_label" => __("Create label"),
+                               "create_filter" => __("Create filter"),
+                               "collapse_sidebar" => __("Un/collapse sidebar"),
+                               "help_dialog" => __("Show help dialog"))
+                       );
+
+               return $hotkeys;
+       }
+
+       function get_hotkeys_map($link) {
+               $hotkeys = array(
+//                     "navigation" => array(
+                               "k" => "next_feed",
+                               "j" => "prev_feed",
+                               "n" => "next_article",
+                               "p" => "prev_article",
+                               "(38)|up" => "prev_article",
+                               "(40)|down" => "next_article",
+                               "(191)|/" => "search_dialog",
+//                     "article" => array(
+                               "s" => "toggle_mark",
+                               "S" => "toggle_publ",
+                               "u" => "toggle_unread",
+                               "T" => "edit_tags",
+                               "D" => "dismiss_selected",
+                               "X" => "dismiss_read",
+                               "o" => "open_in_new_window",
+                               "c p" => "catchup_below",
+                               "c n" => "catchup_above",
+                               "N" => "article_scroll_down",
+                               "P" => "article_scroll_up",
+                               "a W" => "toggle_widescreen",
+                               "e" => "email_article",
+//                     "article_selection" => array(
+                               "a a" => "select_all",
+                               "a u" => "select_unread",
+                               "a U" => "select_marked",
+                               "a p" => "select_published",
+                               "a i" => "select_invert",
+                               "a n" => "select_none",
+//                     "feed" => array(
+                               "f r" => "feed_refresh",
+                               "f a" => "feed_unhide_read",
+                               "f s" => "feed_subscribe",
+                               "f e" => "feed_edit",
+                               "f q" => "feed_catchup",
+                               "f x" => "feed_reverse",
+                               "f D" => "feed_debug_update",
+                               "Q" => "catchup_all",
+                               "x" => "cat_toggle_collapse",
+//                     "goto" => array(
+                               "g a" => "goto_all",
+                               "g f" => "goto_fresh",
+                               "g s" => "goto_marked",
+                               "g p" => "goto_published",
+                               "g t" => "goto_tagcloud",
+                               "g P" => "goto_prefs",
+//                     "other" => array(
+                               "(9)|tab" => "select_article_cursor", // tab
+                               "c l" => "create_label",
+                               "c f" => "create_filter",
+                               "c s" => "collapse_sidebar",
+                       );
+
+               global $pluginhost;
+               foreach ($pluginhost->get_hooks($pluginhost::HOOK_HOTKEY_MAP) as $plugin) {
+                       $hotkeys = $plugin->hook_hotkey_map($hotkeys);
+               }
+
+               $prefixes = array();
+
+               foreach (array_keys($hotkeys) as $hotkey) {
+                       $pair = explode(" ", $hotkey, 2);
+
+                       if (count($pair) > 1 && !in_array($pair[0], $prefixes)) {
+                               array_push($prefixes, $pair[0]);
+                       }
+               }
+
+               return array($prefixes, $hotkeys);
+       }
+
        function make_runtime_info($link) {
                $data = array();
 
                                $filter_query_part = filter_to_sql($link, $filter, $owner_uid);
 
                                // Try to check if SQL regexp implementation chokes on a valid regexp
-                               $result = db_query($link, "SELECT true AS true FROM ttrss_entries,
+                               $result = db_query($link, "SELECT true AS true_val FROM ttrss_entries,
                                        ttrss_user_entries, ttrss_feeds, ttrss_feed_categories
                                        WHERE $filter_query_part LIMIT 1", false);
 
-                               $test = db_fetch_result($result, 0, "true");
+                               $test = db_fetch_result($result, 0, "true_val");
 
                                if (!$test) {
                                        $filter_query_part = "false AND";
 
                $node = $doc->getElementsByTagName('body')->item(0);
 
-               return $doc->saveXML($node); //LIBXML_NOEMPTYTAG
+               // http://tt-rss.org/redmine/issues/357
+               return $doc->saveXML($node, LIBXML_NOEMPTYTAG);
        }
 
        function check_for_update($link) {
 
                                $id = 'AUDIO-' . uniqid();
 
-                               $entry .= "<audio id=\"$id\"\">
-                                       <source src=\"$url\"></source>
+                               $entry .= "<audio id=\"$id\"\" controls>
+                                       <source type=\"$ctype\" src=\"$url\"></source>
                                        </audio>";
 
                                $entry .= "<span onclick=\"player(this)\"
                                                value=\"lib/button/musicplayer.swf?song_url=$url\" />
                                        </object>";
                        }
+
+                       if ($entry) $entry .= "&nbsp;" . basename($url);
+
+                       return $entry;
+
                }
 
-               $filename = substr($url, strrpos($url, "/")+1);
+               return "";
+
+/*             $filename = substr($url, strrpos($url, "/")+1);
 
                $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
-                       $filename . " (" . $ctype . ")" . "</a>";
+                       $filename . " (" . $ctype . ")" . "</a>"; */
 
-               return $entry;
        }
 
        function format_article($link, $id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
 
                        $entries_html = array();
                        $entries = array();
+                       $entries_inline = array();
 
                        foreach ($result as $line) {
 
 
                                $filename = substr($url, strrpos($url, "/")+1);
 
-#                              $player = format_inline_player($link, $url, $ctype);
+                               $player = format_inline_player($link, $url, $ctype);
+
+                               if ($player) array_push($entries_inline, $player);
 
 #                              $entry .= " <a target=\"_blank\" href=\"" . htmlspecialchars($url) . "\">" .
 #                                      $filename . " (" . $ctype . ")" . "</a>";
                                }
                        }
 
+                       if (count($entries_inline) > 0) {
+                               $rv .= "<hr clear='both'/>";
+                               foreach ($entries_inline as $entry) { $rv .= $entry; };
+                               $rv .= "<hr clear='both'/>";
+                       }
+
                        $rv .= "<br/><div dojoType=\"dijit.form.DropDownButton\">".
                                "<span>" . __('Attachments')."</span>";
                        $rv .= "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
 
        }
 
-/*     function rewrite_urls($line) {
-               global $url_regex;
-
-               $urls = null;
-
-               $result = preg_replace("/((?<!=.)((http|https|ftp)+):\/\/[^ ,!]+)/i",
-                       "<a target=\"_blank\" href=\"\\1\">\\1</a>", $line);
-
-               return $result;
-       } */
-
        function rewrite_urls($html) {
                libxml_use_internal_errors(true);