torrentSearch.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /* $Id: torrentSearch.php 2893 2007-04-14 13:20:30Z b4rt $ */
  3. /*******************************************************************************
  4. LICENSE
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License (GPL)
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. To read the license please visit http://www.gnu.org/copyleft/gpl.html
  14. *******************************************************************************/
  15. // prevent direct invocation
  16. if ((!isset($cfg['user'])) || (isset($_REQUEST['cfg']))) {
  17. @ob_end_clean();
  18. @header("location: ../../index.php");
  19. exit();
  20. }
  21. /******************************************************************************/
  22. // is enabled ?
  23. if ($cfg["enable_search"] != 1) {
  24. AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: ".$cfg["user"]." tried to use search");
  25. @error("search is disabled", "index.php?iid=index", "");
  26. }
  27. // common functions
  28. require_once('inc/functions/functions.common.php');
  29. // require
  30. require_once("inc/searchEngines/SearchEngineBase.php");
  31. // init template-instance
  32. tmplInitializeInstance($cfg["theme"], "page.torrentSearch.tmpl");
  33. // Go get the if this is a search request. go get the data and produce output.
  34. $hideSeedless = tfb_getRequestVar('hideSeedless');
  35. if (!empty($hideSeedless))
  36. $_SESSION['hideSeedless'] = $hideSeedless;
  37. if (!isset($_SESSION['hideSeedless']))
  38. $_SESSION['hideSeedless'] = 'no';
  39. $hideSeedless = $_SESSION['hideSeedless'];
  40. $pg = tfb_getRequestVar('pg');
  41. $searchEngine = tfb_getRequestVar('searchEngine');
  42. if (empty($searchEngine))
  43. $searchEngine = $cfg["searchEngine"];
  44. if (!preg_match('/^[a-zA-Z0-9]+$/D', $searchEngine))
  45. error("Invalid SearchEngine", "", "");
  46. $searchterm = tfb_getRequestVar('searchterm');
  47. if (empty($searchterm))
  48. $searchterm = tfb_getRequestVar('query');
  49. $searchterm = str_replace(" ", "+",$searchterm);
  50. if (empty($searchterm)) {
  51. // no searchterm set the get latest flag.
  52. $_REQUEST["LATEST"] = "1";
  53. }
  54. $tmpl->setvar('searchterm', str_replace("+", " ",$searchterm));
  55. $tmpl->setloop('Engine_List', tmplSetSearchEngineDDL($searchEngine));
  56. $tmpl->setvar('searchEngine', $searchEngine);
  57. // Check if Search Engine works properly
  58. if (!is_file('inc/searchEngines/'.$searchEngine.'Engine.php')) {
  59. $tmpl->setvar('sEngine_error', 1);
  60. $tmpl->setvar('sEngine_msg', "Search Engine not installed.");
  61. } else {
  62. include_once('inc/searchEngines/'.$searchEngine.'Engine.php');
  63. $sEngine = new SearchEngine(serialize($cfg));
  64. if (!$sEngine->initialized) {
  65. $tmpl->setvar('sEngine_error', 1);
  66. $tmpl->setvar('sEngine_msg', $sEngine->msg);
  67. } else {
  68. // Search Engine ready to go
  69. $mainStart = true;
  70. $catLinks = '';
  71. $tmpCatLinks = '';
  72. $tmpLen = 0;
  73. $link_list = array();
  74. foreach ($sEngine->getMainCategories() as $mainId => $mainName) {
  75. array_push($link_list, array(
  76. 'searchEngine' => $searchEngine,
  77. 'mainId' => $mainId,
  78. 'mainName' => $mainName
  79. )
  80. );
  81. }
  82. $tmpl->setloop('link_list', $link_list);
  83. $mainGenre = tfb_getRequestVar('mainGenre');
  84. $subCats = $sEngine->getSubCategories($mainGenre);
  85. if ((empty($mainGenre) && array_key_exists("subGenre", $_REQUEST)) || (count($subCats) <= 0)) {
  86. $tmpl->setvar('no_genre', 1);
  87. $tmpl->setvar('performSearch', (array_key_exists("LATEST", $_REQUEST) && $_REQUEST["LATEST"] == "1")
  88. ? $sEngine->getLatest()
  89. : $sEngine->performSearch($searchterm)
  90. );
  91. } else {
  92. $mainGenreName = $sEngine->GetMainCatName($mainGenre);
  93. $tmpl->setvar('mainGenreName', $mainGenreName);
  94. $list_cats = array();
  95. foreach ($subCats as $subId => $subName) {
  96. array_push($list_cats, array(
  97. 'subId' => $subId,
  98. 'subName' => $subName
  99. )
  100. );
  101. }
  102. $tmpl->setloop('list_cats', $list_cats);
  103. }
  104. }
  105. }
  106. //
  107. $tmpl->setvar('_SEARCH', $cfg['_SEARCH']);
  108. //
  109. tmplSetTitleBar("Torrent ".$cfg['_SEARCH']);
  110. tmplSetFoot();
  111. tmplSetIidVars();
  112. // parse template
  113. $tmpl->pparse();
  114. ?>