]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions2.php
support loading themes from themes.local
[tt-rss.git] / include / functions2.php
index 17d8acb3e3e29f92c03e28b90ad2f9973de87b31..314c128739425f88e41fa81f1b124f61b85747e9 100644 (file)
                                        else
                                                array_push($query_keywords, "($not (published = false))");
 
+                               } else {
+                                       array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
+                                                       OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
+                                       if (!$not) array_push($search_words, $k);
+                               }
+                               break;
+                       case "unread":
+                               if ($commandpair[1]) {
+                                       if ($commandpair[1] == "true")
+                                               array_push($query_keywords, "($not (unread = true))");
+                                       else
+                                               array_push($query_keywords, "($not (unread = false))");
+
                                } else {
                                        array_push($query_keywords, "(UPPER(ttrss_entries.title) $not LIKE UPPER('%$k%')
                                                        OR UPPER(ttrss_entries.content) $not LIKE UPPER('%$k%'))");
 
                        $order_by = "score DESC, date_entered DESC, updated DESC";
 
-                       if ($view_mode == "unread_first") {
-                               $order_by = "unread DESC, $order_by";
-                       }
-
                        if ($override_order) {
                                $order_by = $override_order;
                        }
                                        $cached_filename = CACHE_DIR . '/images/' . sha1($src) . '.png';
 
                                        if (file_exists($cached_filename)) {
-                                               $src = SELF_URL_PATH . '/image.php?hash=' . sha1($src);
+                                               $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src);
                                        }
 
                                        $entry->setAttribute('src', $src);
 
                                        foreach ($entries as $entry) {
 
-                                               if (preg_match("/image/", $entry["type"]) ||
-                                                               preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) {
-
-                                                               if (!$hide_images) {
-                                                                       $encsize = '';
-                                                                       if ($entry['height'] > 0)
-                                                                               $encsize .= ' height="' . intval($entry['width']) . '"';
-                                                                       if ($entry['width'] > 0)
-                                                                               $encsize .= ' width="' . intval($entry['height']) . '"';
-                                                                       $rv .= "<p><img
-                                                                       alt=\"".htmlspecialchars($entry["filename"])."\"
-                                                                       src=\"" .htmlspecialchars($entry["url"]) . "\"
-                                                                       " . $encsize . " /></p>";
-                                                               } else {
-                                                                       $rv .= "<p><a target=\"_blank\"
-                                                                       href=\"".htmlspecialchars($entry["url"])."\"
-                                                                       >" .htmlspecialchars($entry["url"]) . "</a></p>";
-                                                               }
+                                       foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin)
+                                               $retval = $plugin->hook_render_enclosure($entry, $hide_images);
 
-                                                               if ($entry['title']) {
-                                                                       $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
-                                                               }
+
+                                               if ($retval) {
+                                                       $rv .= $retval;
+                                               } else {
+
+                                                       if (preg_match("/image/", $entry["type"]) ||
+                                                                       preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) {
+
+                                                                       if (!$hide_images) {
+                                                                               $encsize = '';
+                                                                               if ($entry['height'] > 0)
+                                                                                       $encsize .= ' height="' . intval($entry['width']) . '"';
+                                                                               if ($entry['width'] > 0)
+                                                                                       $encsize .= ' width="' . intval($entry['height']) . '"';
+                                                                               $rv .= "<p><img
+                                                                               alt=\"".htmlspecialchars($entry["filename"])."\"
+                                                                               src=\"" .htmlspecialchars($entry["url"]) . "\"
+                                                                               " . $encsize . " /></p>";
+                                                                       } else {
+                                                                               $rv .= "<p><a target=\"_blank\"
+                                                                               href=\"".htmlspecialchars($entry["url"])."\"
+                                                                               >" .htmlspecialchars($entry["url"]) . "</a></p>";
+                                                                       }
+
+                                                                       if ($entry['title']) {
+                                                                               $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
+                                                                       }
+                                                       }
                                                }
                                        }
                                }
                return LABEL_BASE_INDEX - 1 + abs($feed);
        }
 
-       function theme_valid($file) {
-               if ($file == "default.css" || $file == "night.css") return true; // needed for array_filter
-               $file = "themes/" . basename($file);
+       function get_theme_path($theme) {
+               $check = "themes/$theme";
+               if (file_exists($check)) return $check;
+
+               $check = "themes.local/$theme";
+               if (file_exists($check)) return $check;
+       }
+
+       function theme_valid($theme) {
+               if ($theme == "default.css" || $theme == "night.css") return true; // needed for array_filter
+               $file = "themes/" . basename($theme);
+
+               if (!file_exists($file)) $file = "themes.local/" . basename($theme);
 
                if (file_exists($file) && is_readable($file)) {
                        $fh = fopen($file, "r");
 
                return false;
        }
+
+       function error_json($code) {
+               require_once "errors.php";
+
+               @$message = $ERRORS[$code];
+
+               return json_encode(array("error" =>
+                       array("code" => $code, "message" => $message)));
+
+       }
+
+       function abs_to_rel_path($dir) {
+               $tmp = str_replace(dirname(__DIR__), "", $dir);
+
+               if (strlen($tmp) > 0 && substr($tmp, 0, 1) == "/") $tmp = substr($tmp, 1);
+
+               return $tmp;
+       }
 ?>