get_res_index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. /*
  3. 获取资源列表
  4. */
  5. require_once "../config.php";
  6. require_once "../public/_pdo.php";
  7. if (isset($_COOKIE["language"])) {
  8. $lang = $_COOKIE["language"];
  9. } else {
  10. $lang = "en";
  11. }
  12. require_once "language/db_{$lang}.php";
  13. if (isset($_GET["book"])) {
  14. $book = (int)$_GET["book"];
  15. } else {
  16. echo "no book id";
  17. exit;
  18. }
  19. if (substr($book, 0, 1) == 'p') {
  20. $book = substr($book, 1);
  21. }
  22. if (isset($_GET["album"])) {
  23. $album = $_GET["album"];
  24. } else {
  25. $album = -1;
  26. }
  27. if (isset($_GET["paragraph"])) {
  28. $paragraph = (int)$_GET["paragraph"];
  29. } else {
  30. $paragraph = -1;
  31. }
  32. function format_file_size($size)
  33. {
  34. if ($size < 102) {
  35. $str_size = $size . "B";
  36. } else if ($size < (1024 * 102)) {
  37. $str_size = sprintf("%.1f KB", $size / 1024);
  38. } else {
  39. $str_size = sprintf("%.1f MB", $size / (1024 * 1024));
  40. }
  41. return ($str_size);
  42. }
  43. PDO_Connect("" . _FILE_DB_RESRES_INDEX_);
  44. //资源名称
  45. $res_title = "";
  46. if ($album == -1) {
  47. //查书
  48. if ($paragraph == -1) {
  49. //查整本书
  50. $query = "select * from 'book' where book_id='$book' ";
  51. $Fetch = PDO_FetchAll($query);
  52. $iFetch = count($Fetch);
  53. if ($iFetch > 0) {
  54. echo "<div id='album_info_head'>";
  55. $res_title = $Fetch[0]["title"];
  56. echo "<h2>$res_title</h2>";
  57. echo "<div class='album_info'>";
  58. echo "<div class='cover'></div>";
  59. echo "<div class='infomation'>";
  60. //标题
  61. echo "<div class='title'>《" . $res_title . "》</div>";
  62. echo "<div class='type'>" . $Fetch[0]["c1"] . " " . $Fetch[0]["c2"] . "</div>";
  63. echo "</div>";
  64. echo "</div>";
  65. //相关专辑
  66. $query = "select album.id,album.title, author.name from album LEFT JOIN author ON album.author = author.id where album.book='$book' ";
  67. $Fetch_ather = PDO_FetchAll($query);
  68. $iFetchAther = count($Fetch_ather);
  69. if ($iFetchAther > 0) {
  70. echo "<ul class='search_list'>";
  71. echo "<li class='title'>相关专辑</li>";
  72. foreach ($Fetch_ather as $one_album) {
  73. $read_link = "reader.php?book=$book&album=" . $one_album["id"] . "&paragraph=$paragraph";
  74. $info_link = "index_render_res_list($book," . $one_album["id"] . ",-1)";
  75. echo "<li onclick='$info_link' >";
  76. echo "<span>{$one_album["title"]}</span>";
  77. echo "<div><span class='author_name'>" . $one_album["name"] . "</span><span class='ui-icon-carat-r ui-icon' style='display:inline-block;'></span></span>";
  78. echo "</li>";
  79. }
  80. echo "</ul>";
  81. }
  82. //相关专辑结束
  83. echo "</div>";
  84. //目录
  85. PDO_Connect(_FILE_DB_PALITEXT_);
  86. $query = "SELECT * FROM "._TABLE_PALI_TEXT_." where book = '{$book}' and ( level>'0' and level<8 ) ";
  87. $Fetch_Toc = PDO_FetchAll($query);
  88. $iFetchToc = count($Fetch_Toc);
  89. if ($iFetchToc > 0) {
  90. $aLevel = array();
  91. foreach ($Fetch_Toc as $one_title) {
  92. $level = $one_title["level"];
  93. if (isset($aLevel["{$level}"])) {
  94. $aLevel["{$level}"]++;
  95. } else {
  96. $aLevel["{$level}"] = 1;
  97. }
  98. }
  99. ksort($aLevel);
  100. //找出不是一个的最大层级
  101. foreach ($aLevel as $x => $x_value) {
  102. $maxLevel = $x;
  103. if ($x_value > 1) {
  104. break;
  105. }
  106. }
  107. echo "<ul class='search_list'>";
  108. echo "<li class='title'>章节</li>";
  109. foreach ($Fetch_Toc as $one_title) {
  110. $level = $one_title["level"];
  111. if ($maxLevel == $level) {
  112. $toc_paragraph = $one_title["paragraph"];
  113. $toc_title = $one_title["text"];
  114. $info_link = "index_render_res_list($book,-1,$toc_paragraph)";
  115. echo "<li onclick='$info_link' >";
  116. echo "<span>{$toc_title}</span>";
  117. echo "<div><span class='author_name'>2</span><span class='ui-icon-carat-r ui-icon' style='display:inline-block;'></span></span>";
  118. echo "</li>";
  119. }
  120. }
  121. echo "</ul>";
  122. }
  123. //目录结束
  124. }
  125. } else {
  126. //查书中的一个段
  127. PDO_Connect(_FILE_DB_PALITEXT_);
  128. $query = "SELECT text from "._TABLE_PALI_TEXT_." where book= '{$book}' and paragraph= '{$paragraph}' ";
  129. $res_title = PDO_FetchOne($query);
  130. echo "<div id='album_info_head'>";
  131. echo "<h2>$res_title</h2>";
  132. echo "<div class='album_info'>";
  133. echo "<div class='cover'></div>";
  134. echo "<div class='infomation'>";
  135. //书名
  136. echo "<div class='title'>《{$book_name[$book][0]}》</div>";
  137. echo "<div class='type'>{$book_name[$book][1]}</div>";
  138. echo "</div>";
  139. echo "</div>";
  140. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  141. $query = "SELECT resindex.id,resindex.title,resindex.type,resindex.album,author.name from \""._TABLE_RES_INDEX_."\" as resindex LEFT JOIN author ON resindex.author = author.id where resindex.book='$book' and resindex.paragraph=$paragraph and resindex.type<>7 group by resindex.album";
  142. $Fetch = PDO_FetchAll($query);
  143. $iFetch = count($Fetch);
  144. if ($iFetch > 0) {
  145. $res_title = $Fetch[0]["title"];
  146. //可用资源
  147. echo "<ul class='search_list'>";
  148. echo "<li class='title'>可用资源</li>";
  149. foreach ($Fetch as $one_album) {
  150. $album_type = $one_album["type"];
  151. $read_link = ""; //"../reader/?book=$book&album=".$one_album["album"]."&paragraph=$paragraph";
  152. $info_link = "index_render_res_list($book," . $one_album["album"] . ",$paragraph)";
  153. echo "<li onclick='$info_link' >";
  154. echo "<span><span class='media_type'>{$media_type_short[$album_type]}</span>{$one_album["title"]}</span>";
  155. echo "<div><span class='author_name'>{$one_album["name"]}</span><span class='ui-icon-carat-r ui-icon' style='display:inline-block;'></span></span>";
  156. echo "</li>";
  157. }
  158. echo "</ul>";
  159. }
  160. //查共享文档
  161. PDO_Connect(_FILE_DB_FILEINDEX_);
  162. $query = "SELECT * from "._TABLE_FILEINDEX_." where book=? and paragraph=? and status>0 and share>0 order by create_time";
  163. $Fetch = PDO_FetchAll($query,array($book,$paragraph));
  164. $iFetch = count($Fetch);
  165. if ($iFetch > 0) {
  166. echo "<ul class='search_list'>";
  167. echo "<li class='title'>共享文档</li>";
  168. foreach ($Fetch as $one_file) {
  169. //$read_link="reader.php?book=$book&album=".$one_para["album"]."&paragraph=$paragraph";
  170. $edit_link = "../app/project.php?op=open&doc_id={$one_file["doc_id"]}";
  171. echo "<li class='noline'><a href='$edit_link' target='_blank'>" . $one_file["title"] . "</a>-" . $one_file["user_id"] . "</li>";
  172. }
  173. echo "</ul>";
  174. }
  175. //目录
  176. PDO_Connect(_FILE_DB_PALITEXT_);
  177. $query = "SELECT * from \""._TABLE_RES_INDEX_."\" where book = ? and level>'0' and level<8 and paragraph >= ? ";
  178. $Fetch_Toc = PDO_FetchAll($query,array($book,$paragraph));
  179. $iFetchToc = count($Fetch_Toc);
  180. if ($iFetchToc > 1) {
  181. if ($Fetch_Toc[1]["level"] > $Fetch_Toc[0]["level"]) {
  182. echo "<ul class='search_list'>";
  183. echo "<li class='title'>章节</li>";
  184. for ($iToc = 1; $iToc < $iFetchToc; $iToc++) {
  185. if ($Fetch_Toc[$iToc]["level"] <= $Fetch_Toc[0]["level"]) {
  186. break;
  187. }
  188. $level = $Fetch_Toc[$iToc]["level"];
  189. $toc_paragraph = $Fetch_Toc[$iToc]["paragraph"];
  190. $toc_title = $Fetch_Toc[$iToc]["text"];
  191. $info_link = "index_render_res_list($book,-1,$toc_paragraph)";
  192. echo "<li onclick='$info_link' >";
  193. echo "<span>{$toc_title}</span>";
  194. echo "<div><span class='author_name'>2</span><span class='ui-icon-carat-r ui-icon' style='display:inline-block;'></span></span>";
  195. echo "</li>";
  196. }
  197. echo "</ul>";
  198. }
  199. }
  200. //目录结束
  201. }
  202. } else {
  203. //查专辑
  204. if ($paragraph == -1) {
  205. //查整张专辑
  206. $query = "select album.id,album.title,album.file,album.guid,album.type, author.name from album LEFT JOIN author ON album.author = author.id where album.id='$album' ";
  207. //$query = "select * from 'album' where id='$album'";
  208. $Fetch = PDO_FetchAll($query);
  209. $iFetch = count($Fetch);
  210. if ($iFetch > 0) {
  211. echo "<div id='album_info_head'>";
  212. //标题
  213. $res_title = $Fetch[0]["title"];
  214. $album_file_name = $Fetch[0]["file"];
  215. $album_guid = $Fetch[0]["guid"];
  216. $album_type = $Fetch[0]["type"];
  217. echo "<h2>$res_title</h2>";
  218. echo "<div class='album_info'>";
  219. echo "<div class='cover'></div>";
  220. echo "<div class='infomation'>";
  221. //标题
  222. echo "<div class='title'>" . $res_title . "</div>";
  223. //echo "<div class='type'>".$Fetch[0]["c1"]." ".$Fetch[0]["c2"]."</div>";
  224. echo "<div class='author'>" . $Fetch[0]["name"] . "</div>";
  225. echo "<div class='media'><span class='media_type'>" . $media_type[$Fetch[0]["type"]] . "</span></div>";
  226. echo "</div>";
  227. echo "</div>";
  228. $read_link = "reader.php?book=$book&album=$album&paragraph=$paragraph";
  229. echo "<ul class='search_list'>";
  230. echo "<li class='title'>阅读</li>";
  231. echo "<li><a class='online_read' style='color: white;' href='$read_link' target='_blank'>在线阅读</a></li>";
  232. echo "</ul>";
  233. //下载
  234. echo "<ul class='search_list'>";
  235. $query = "select album_ebook.file_name, album_ebook.file_size, file_format.format from album_ebook LEFT JOIN file_format ON album_ebook.file_format=file_format.id where album='$album'";
  236. $Fetch_ebook = PDO_FetchAll($query);
  237. if (count($Fetch_ebook) > 0) {
  238. echo "<li class='title'>下载</li>";
  239. foreach ($Fetch_ebook as $one_ebook) {
  240. $ebook_download_link = "<a href='" . $one_ebook["file_name"] . "' target='_blank'>下载</a>";
  241. echo "<li><span class='file_format'>" . $one_ebook["format"] . "</span>" . format_file_size($one_ebook["file_size"]) . "$ebook_download_link</li>";
  242. }
  243. }
  244. echo "</ul>";
  245. //相关专辑
  246. echo "<ul class='search_list'>";
  247. $query = "select album.id,album.title,album.file,album.guid,album.type, author.name from album LEFT JOIN author ON album.author = author.id where album.book='$book' and album.id != $album ";
  248. //$query = "select * from 'album' where book='$book' and id != $album";
  249. $Fetch_ather = PDO_FetchAll($query);
  250. $iFetchAther = count($Fetch_ather);
  251. if ($iFetchAther > 0) {
  252. echo "<li class='title'>相关专辑</li>";
  253. foreach ($Fetch_ather as $one_album) {
  254. $read_link = "reader.php?book=$book&album=" . $one_album["id"] . "&paragraph=$paragraph";
  255. echo "<li ><span class='media_type'>{$media_type[$one_album["type"]]}</span><a href='$read_link' target='_blank'>{$one_album["title"]}</a>{$one_album["name"]}</li>";
  256. }
  257. }
  258. echo "</ul>";
  259. //相关专辑结束
  260. echo "</div>";
  261. //目录
  262. switch ($album_type) {
  263. case 1:
  264. case 2:
  265. case 6:
  266. PDO_Connect(_FILE_DB_PALITEXT_);
  267. $query = "select * from "._TABLE_PALI_TEXT_." where book = '{$book}' and level>'0' and level<8 ";
  268. break;
  269. case 3:
  270. $db_file = '../' . $album_file_name;
  271. echo "db album:{$db_file}";
  272. PDO_Connect("$db_file");
  273. $query = "select * from 'album' where guid='$album_guid'";
  274. $Fetch_album = PDO_FetchAll($query);
  275. $this_album_id = $Fetch_album[0]["id"];
  276. $query = "select * from 'data' where level>'0' and level<8 and album=$this_album_id ";
  277. break;
  278. }
  279. $Fetch_Toc = PDO_FetchAll($query);
  280. $iFetchToc = count($Fetch_Toc);
  281. if ($iFetchToc > 0) {
  282. $aLevel = array();
  283. foreach ($Fetch_Toc as $one_title) {
  284. $level = $one_title["level"];
  285. if (isset($aLevel["{$level}"])) {
  286. $aLevel["{$level}"]++;
  287. } else {
  288. $aLevel["{$level}"] = 1;
  289. }
  290. }
  291. ksort($aLevel);
  292. //找出不是一个的最大层级
  293. foreach ($aLevel as $x => $x_value) {
  294. $maxLevel = $x;
  295. if ($x_value > 1) {
  296. break;
  297. }
  298. }
  299. echo "<ul class='search_list'>";
  300. echo "<li class='title'>章节</li>";
  301. foreach ($Fetch_Toc as $one_title) {
  302. $level = $one_title["level"];
  303. if ($maxLevel == $level) {
  304. $toc_paragraph = $one_title["paragraph"];
  305. $toc_title = $one_title["text"];
  306. $info_link = "index_render_res_list($book,$album,$toc_paragraph)";
  307. echo "<li onclick='$info_link' >";
  308. echo "<span>{$toc_title}</span>";
  309. echo "<div><span class='author_name'>2</span><span class='ui-icon-carat-r ui-icon' style='display:inline-block;'></span></span>";
  310. echo "</li>";
  311. }
  312. }
  313. echo "</ul>";
  314. }
  315. //目录结束
  316. }
  317. } else {
  318. //查专辑中的一个段
  319. $query = "select * from 'index' where album='$album' and paragraph=$paragraph";
  320. $Fetch = PDO_FetchAll($query);
  321. $iFetch = count($Fetch);
  322. if ($iFetch > 0) {
  323. //标题
  324. $res_title = $Fetch[0]["title"];
  325. echo "<h2>$res_title</h2>";
  326. echo "<div class='album_info'>";
  327. echo "<div class='cover'></div>";
  328. echo "<div class='infomation'>";
  329. //出自专辑 标题
  330. $query = "select album.id,album.title,album.type,album.file,album.guid, author.name from album LEFT JOIN author ON album.author = author.id where album.id='$album' ";
  331. $FetchAlbum = PDO_FetchAll($query);
  332. if (count($FetchAlbum) > 0) {
  333. $album_type = $FetchAlbum[0]["type"];
  334. $album_file_name = $FetchAlbum[0]["file"];
  335. $album_guid = $FetchAlbum[0]["guid"];
  336. //专辑标题
  337. $info_link = "index_render_res_list($book,$album,-1)";
  338. echo "<div onclick='$info_link' class='title'>" . $FetchAlbum[0]["title"] . "</div>";
  339. }
  340. echo "<div class='author'>" . $FetchAlbum[0]["name"] . "</div>";
  341. echo "<div class='author'><span class='media_type'>" . $media_type[$FetchAlbum[0]["type"]] . "</span></div>";
  342. echo "</div>";
  343. echo "</div>";
  344. //在线阅读
  345. $read_link = "reader.php?book=$book&album=$album&paragraph=$paragraph";
  346. echo "<ul class='search_list'>";
  347. echo "<li class='title'>阅读</li>";
  348. echo "<li><a class='online_read' style='color: white;' href='$read_link' target='_blank'>在线阅读</a></li>";
  349. echo "</ul>";
  350. //相关段落
  351. //$query = "select album.id,album.title,album.file,album.guid,album.type, author.name from album LEFT JOIN author ON album.author = author.id where album.book='$book' and album.id != $album ";
  352. $query = "select idx.id , idx.title , idx.album , idx.type , author.name FROM 'index' as idx LEFT JOIN author ON idx.author = author.id WHERE idx.book='$book' and idx.paragraph=$paragraph and idx.album!=$album and idx.type!=7";
  353. $Fetch_ather = PDO_FetchAll($query);
  354. $iFetchAther = count($Fetch_ather);
  355. if ($iFetchAther > 0) {
  356. echo "<ul class='search_list'>";
  357. echo "<li class='title'>相关资源</li>";
  358. foreach ($Fetch_ather as $one_album) {
  359. $read_link = "reader.php?book=$book&album=" . $one_album["album"] . "&paragraph=$paragraph";
  360. echo "<li class='noline'>";
  361. echo "<span><span class='media_type'>{$media_type[$one_album["type"]]}</span>";
  362. echo "<a href='$read_link' target='_blank'>{$one_album["title"]}</a></span><span>{$one_album["name"]}</span></li>";
  363. }
  364. echo "</ul>";
  365. }
  366. //目录
  367. switch ($album_type) {
  368. case 1:
  369. case 2:
  370. case 6:
  371. PDO_Connect(_FILE_DB_PALITEXT_);
  372. $query = "select * from "._TABLE_PALI_TEXT_." where book = '{$book}' and level>'0' and level<8 and paragraph>=$paragraph ";
  373. break;
  374. case 3:
  375. $db_file = "../{$album_file_name}";
  376. PDO_Connect("$db_file");
  377. $query = "select * from 'album' where guid='$album_guid'";
  378. $Fetch_album = PDO_FetchAll($query);
  379. $this_album_id = $Fetch_album[0]["id"];
  380. $query = "select * from 'data' where level>'0' and level<8 and paragraph>=$paragraph and album=$this_album_id ";
  381. break;
  382. }
  383. $Fetch_Toc = PDO_FetchAll($query);
  384. $iFetchToc = count($Fetch_Toc);
  385. if ($iFetchToc > 1) {
  386. if ($Fetch_Toc[1]["level"] > $Fetch_Toc[0]["level"]) {
  387. echo "<ul class='search_list'>";
  388. echo "<li class='title'>章节</li>";
  389. for ($iToc = 1; $iToc < $iFetchToc; $iToc++) {
  390. if ($Fetch_Toc[$iToc]["level"] <= $Fetch_Toc[0]["level"]) {
  391. break;
  392. }
  393. $level = $Fetch_Toc[$iToc]["level"];
  394. $toc_paragraph = $Fetch_Toc[$iToc]["paragraph"];
  395. $toc_title = $Fetch_Toc[$iToc]["text"];
  396. $info_link = "index_render_res_list($book,$album,$toc_paragraph)";
  397. echo "<li onclick='$info_link' >";
  398. echo "<span>{$toc_title}</span>";
  399. echo "<div><span class='author_name'>2</span><span class='ui-icon-carat-r ui-icon' style='display:inline-block;'></span></span>";
  400. echo "</li>";
  401. }
  402. echo "</ul>";
  403. }
  404. }
  405. //目录结束
  406. }
  407. }
  408. }