get_res_index.php 19 KB

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