1) Исправления в связи со сменой API MySQL
[openlib.git] / www / getJSON.php
diff --git a/www/getJSON.php b/www/getJSON.php
new file mode 100644 (file)
index 0000000..e599f53
--- /dev/null
@@ -0,0 +1,99 @@
+<?php\r
+/**\r
+ * COPS (Calibre OPDS PHP Server) HTML main script\r
+ *\r
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)\r
+ * @author     Sébastien Lucas <sebastien@slucas.fr>\r
+ *\r
+ */\r
\r
+    require_once ("config.php");\r
+    require_once ("base.php");\r
+    require_once ("author.php");\r
+    require_once ("serie.php");\r
+    require_once ("tag.php");\r
+    require_once ("language.php");\r
+    require_once ("book.php");\r
+    \r
+    header ("Content-Type:application/json;charset=utf-8");\r
+    $page = getURLParam ("page", Base::PAGE_INDEX);\r
+    $query = getURLParam ("query");\r
+    $qid = getURLParam ("id");\r
+    $n = getURLParam ("n", "1");\r
+    \r
+    $currentPage = Page::getPage ($page, $qid, $query, $n);\r
+    $currentPage->InitializeContent ();\r
+    \r
+    $out = array ( "title" => $currentPage->title);\r
+    $entries = array ();\r
+    foreach ($currentPage->entryArray as $entry) {\r
+        array_push ($entries, $entry->getContentArray ());\r
+    }\r
+    if (!is_null ($currentPage->book)) {\r
+        $out ["book"] = $currentPage->book->getFullContentArray ();\r
+    }\r
+    $out ["page"] = $page;\r
+    $out ["entries"] = $entries;\r
+    $out ["isPaginated"] = 0;\r
+    if ($currentPage->isPaginated ()) {\r
+        $prevLink = $currentPage->getPrevLink ();\r
+        $nextLink = $currentPage->getNextLink ();\r
+        $out ["isPaginated"] = 1;\r
+        $out ["prevLink"] = "";\r
+        if (!is_null ($prevLink)) {\r
+            $out ["prevLink"] = $prevLink->hrefXhtml ();\r
+        }\r
+        $out ["nextLink"] = "";\r
+        if (!is_null ($nextLink)) {\r
+            $out ["nextLink"] = $nextLink->hrefXhtml ();\r
+        }\r
+        $out ["maxPage"] = $currentPage->getMaxPage ();\r
+        $out ["currentPage"] = $currentPage->n;\r
+    }\r
+    if (!is_null (getURLParam ("complete"))) { \r
+        $out ["const"] = array ("version" => VERSION, "i18n" => array (\r
+                       "coverAlt" => localize("i18n.coversection"),\r
+                       "authorsTitle" => localize("authors.title"),\r
+                       "bookwordTitle" => localize("bookword.title"),\r
+                       "tagsTitle" => localize("tags.title"),\r
+                       "seriesTitle" => localize("series.title"),\r
+                       "customizeTitle" => localize ("customize.title"),\r
+                       "aboutTitle" => localize ("about.title"),\r
+                       "previousAlt" => localize ("paging.previous.alternate"),\r
+                       "nextAlt" => localize ("paging.next.alternate"),\r
+                       "searchAlt" => localize ("search.alternate"),\r
+                       "sortAlt" => localize ("sort.alternate"),\r
+                       "homeAlt" => localize ("home.alternate"),\r
+                       "settingsAlt" => localize ("settings.alternate"),\r
+                       "permalinkAlt" => localize ("permalink.alternate"),\r
+                       "pubdateTitle" => localize("pubdate.title"),\r
+                       "languagesTitle" => localize("language.title"),\r
+                       "contentTitle" => localize("content.summary"),\r
+                       "sortorderAsc" => localize("search.sortorder.asc"),\r
+                       "sortorderDesc" => localize("search.sortorder.desc"),\r
+                       "customizeEmail" => localize("customize.email")),\r
+                   "url" => array (\r
+                       "detailUrl" => "index.php?page=".Base::PAGE_BOOK_DETAIL."&id={0}",\r
+                       "coverUrl" => "fetch.php?id={0}",\r
+                       "thumbnailUrl" => "fetch.php?height=" . $config['cops_html_thumbnail_height'] . "&id={0}"),\r
+                   "config" => array (\r
+                       "use_fancyapps" => $config ["cops_use_fancyapps"],\r
+                       "max_item_per_page" => $config['cops_max_item_per_page'],\r
+                       "html_tag_filter" => $config['cops_html_tag_filter']));\r
+   }\r
+\r
+    $out ["containsBook"] = 0;\r
+    if ($currentPage->containsBook ()) {\r
+        $out ["containsBook"] = 1;\r
+    }\r
+    \r
+    $out["abouturl"] = "index.php?page=".Base::PAGE_ABOUT;\r
+    \r
+    if ($page == Base::PAGE_ABOUT) {\r
+        $out ["fullhtml"] = file_get_contents('about.html');\r
+    }\r
+    \r
+    $out ["homeurl"] = "index.php";\r
+    \r
+    echo json_encode ($out);\r
+\r