PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/pages/settings.inc.php

https://github.com/xong/rexsearch
PHP | 946 lines | 834 code | 88 blank | 24 comment | 78 complexity | e08db6aec13e9a175cbd94381e3bf81b MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if(isset($_POST['sendit']))
  3. {
  4. if(!empty($_POST['a587_rexsearch']['blacklist']))
  5. $_POST['a587_rexsearch']['blacklist'] = explode(',',$_POST['a587_rexsearch']['blacklist']);
  6. else
  7. unset($_POST['a587_rexsearch']['blacklist']);
  8. if(!empty($_POST['a587_rexsearch']['include']))
  9. {
  10. $returnArray = array();
  11. foreach($_POST['a587_rexsearch']['include'] as $include)
  12. {
  13. $includeArray = explode('`.`',$include);
  14. if(!array_key_exists($includeArray[0],$returnArray))
  15. {
  16. $returnArray[$includeArray[0]] = array();
  17. }
  18. $returnArray[$includeArray[0]][] = $includeArray[1];
  19. }
  20. $_POST['a587_rexsearch']['include'] = $returnArray;
  21. }
  22. else
  23. unset($_POST['a587_rexsearch']['include']);
  24. if(!empty($_POST['a587_rexsearch']['fileextensions']))
  25. {
  26. $returnArray = array();
  27. foreach(explode(',', $_POST['a587_rexsearch']['fileextensions']) as $fileext)
  28. {
  29. $returnArray[] = trim($fileext);
  30. }
  31. $_POST['a587_rexsearch']['fileextensions'] = $returnArray;
  32. }
  33. else
  34. unset($_POST['a587_rexsearch']['fileextensions']);
  35. $suggestnewindex = '';
  36. foreach(array_keys(array_merge(array_diff_assoc($_POST['a587_rexsearch'],$REX['ADDON']['settings']['rexsearch']), array_diff_assoc($REX['ADDON']['settings']['rexsearch'],$_POST['a587_rexsearch']))) as $changed)
  37. {
  38. if(in_array($changed, array(
  39. 'indexmode',
  40. 'indexoffline',
  41. 'automaticindex',
  42. 'blacklist',
  43. 'exclude_article_ids',
  44. 'exclude_category_ids',
  45. 'include',
  46. 'fileextensions',
  47. 'indexmediapool',
  48. 'dirdepth',
  49. 'indexfolders',
  50. 'ep_outputfilter'
  51. ))) $suggestnewindex = '&suggestnewindex=1';
  52. }
  53. echo '</pre>';
  54. a587_saveSettings($_POST['a587_rexsearch']);
  55. /*$rexsearch = new rexsearch();
  56. $rexsearch->deleteCache();*/
  57. header('Location: http://'.$_SERVER['HTTP_HOST'].substr($_SERVER["PHP_SELF"],0,-9).'index.php?page=rexsearch&subpage=settings&save=1'.$suggestnewindex);
  58. }
  59. if(!empty($_GET['save']))
  60. echo rex_info($I18N->Msg('a587_settings_saved'));
  61. if(!empty($_GET['suggestnewindex']))
  62. echo rex_warning($I18N->Msg('a587_settings_saved_warning'));
  63. ?>
  64. <div class="rex-addon-output" id="a587-form">
  65. <h2 class="rex-hl2">Einstellungen</h2>
  66. <div class="rex-form">
  67. <form method="post" action="index.php?page=rexsearch&amp;subpage=settings" id="a587_settings_form">
  68. <?php
  69. echo a587_getSettingsFormSection(
  70. 'a587_modi',
  71. $I18N->Msg('a587_settings_modi_header'),
  72. array(
  73. array(
  74. 'type' => 'select',
  75. 'id' => 'a587_rexsearch_logicalmode',
  76. 'name' => 'a587_rexsearch[logicalmode]',
  77. 'label' => $I18N->Msg('a587_settings_logicalmode'),
  78. 'options' => array(
  79. array(
  80. 'value' => 'and',
  81. 'selected' => $REX['ADDON']['settings']['rexsearch']['logicalmode'] == 'and',
  82. 'name' => $I18N->Msg('a587_settings_logicalmode_and')
  83. ),
  84. array(
  85. 'value' => 'or',
  86. 'selected' => $REX['ADDON']['settings']['rexsearch']['logicalmode'] == 'or',
  87. 'name' => $I18N->Msg('a587_settings_logicalmode_or')
  88. )
  89. )
  90. ),
  91. array(
  92. 'type' => 'select',
  93. 'id' => 'a587_rexsearch_textmode',
  94. 'name' => 'a587_rexsearch[textmode]',
  95. 'label' => $I18N->Msg('a587_settings_textmode'),
  96. 'options' => array(
  97. array(
  98. 'value' => 'plain',
  99. 'selected' => $REX['ADDON']['settings']['rexsearch']['textmode'] == 'plain',
  100. 'name' => $I18N->Msg('a587_settings_textmode_plain')
  101. ),
  102. array(
  103. 'value' => 'html',
  104. 'selected' => $REX['ADDON']['settings']['rexsearch']['textmode'] == 'html',
  105. 'name' => $I18N->Msg('a587_settings_textmode_html')
  106. ),
  107. array(
  108. 'value' => 'both',
  109. 'selected' => $REX['ADDON']['settings']['rexsearch']['textmode'] == 'both',
  110. 'name' => $I18N->Msg('a587_settings_textmode_both')
  111. )
  112. )
  113. ),
  114. array(
  115. 'type' => 'select',
  116. 'id' => 'a587_rexsearch_similarwords_mode',
  117. 'name' => 'a587_rexsearch[similarwordsmode]',
  118. 'label' => $I18N->Msg('a587_settings_similarwords_label'),
  119. 'options' => array(
  120. array(
  121. 'value' => A587_SIMILARWORDS_NONE,
  122. 'selected' => $REX['ADDON']['settings']['rexsearch']['similarwordsmode'] == A587_SIMILARWORDS_NONE,
  123. 'name' => $I18N->Msg('a587_settings_similarwords_none')
  124. ),
  125. array(
  126. 'value' => A587_SIMILARWORDS_SOUNDEX,
  127. 'selected' => $REX['ADDON']['settings']['rexsearch']['similarwordsmode'] == A587_SIMILARWORDS_SOUNDEX,
  128. 'name' => $I18N->Msg('a587_settings_similarwords_soundex')
  129. ),
  130. array(
  131. 'value' => A587_SIMILARWORDS_METAPHONE,
  132. 'selected' => $REX['ADDON']['settings']['rexsearch']['similarwordsmode'] == A587_SIMILARWORDS_METAPHONE,
  133. 'name' => $I18N->Msg('a587_settings_similarwords_metaphone')
  134. ),
  135. array(
  136. 'value' => A587_SIMILARWORDS_COLOGNEPHONE,
  137. 'selected' => $REX['ADDON']['settings']['rexsearch']['similarwordsmode'] == A587_SIMILARWORDS_COLOGNEPHONE,
  138. 'name' => $I18N->Msg('a587_settings_similarwords_cologne')
  139. ),
  140. array(
  141. 'value' => A587_SIMILARWORDS_ALL,
  142. 'selected' => $REX['ADDON']['settings']['rexsearch']['similarwordsmode'] == A587_SIMILARWORDS_ALL,
  143. 'name' => $I18N->Msg('a587_settings_similarwords_all')
  144. )
  145. )
  146. ),
  147. array(
  148. 'type' => 'checkbox',
  149. 'id' => 'a587_rexsearch_similarwords_permanent',
  150. 'name' => 'a587_rexsearch[similarwords_permanent]',
  151. 'label' => $I18N->Msg('a587_settings_similarwords_permanent'),
  152. 'value' => '1',
  153. 'checked' => !empty($REX['ADDON']['settings']['rexsearch']['similarwords_permanent'])
  154. ),
  155. array(
  156. 'type' => 'select',
  157. 'id' => 'a587_rexsearch_searchmode',
  158. 'name' => 'a587_rexsearch[searchmode]',
  159. 'label' => $I18N->Msg('a587_settings_searchmode'),
  160. 'options' => array(
  161. array(
  162. 'value' => 'like',
  163. 'selected' => $REX['ADDON']['settings']['rexsearch']['searchmode'] == 'like',
  164. 'name' => $I18N->Msg('a587_settings_searchmode_like')
  165. ),
  166. array(
  167. 'value' => 'match',
  168. 'selected' => $REX['ADDON']['settings']['rexsearch']['searchmode'] == 'match',
  169. 'name' => $I18N->Msg('a587_settings_searchmode_match')
  170. )
  171. )
  172. )
  173. )
  174. );
  175. echo a587_getSettingsFormSection(
  176. 'a587_index',
  177. $I18N->Msg('a587_settings_title_indexmode'),
  178. array(
  179. array(
  180. 'type' => 'select',
  181. 'id' => 'a587_settings_indexmode',
  182. 'name' => 'a587_rexsearch[indexmode]',
  183. 'label' => $I18N->Msg('a587_settings_indexmode_label'),
  184. 'options' => array(
  185. array(
  186. 'value' => '0',
  187. 'name' => $I18N->Msg('a587_settings_indexmode_viahttp'),
  188. 'selected' => $REX['ADDON']['settings']['rexsearch']['indexmode'] == '0',
  189. ),
  190. array(
  191. 'value' => '1',
  192. 'name' => $I18N->Msg('a587_settings_indexmode_viacache'),
  193. 'selected' => $REX['ADDON']['settings']['rexsearch']['indexmode'] == '1',
  194. ),
  195. array(
  196. 'value' => '2',
  197. 'name' => $I18N->Msg('a587_settings_indexmode_viacachetpl'),
  198. 'selected' => $REX['ADDON']['settings']['rexsearch']['indexmode'] == '2',
  199. )
  200. )
  201. ),
  202. array(
  203. 'type' => 'checkbox',
  204. 'id' => 'a587_rexsearch_indexoffline',
  205. 'name' => 'a587_rexsearch[indexoffline]',
  206. 'label' => $I18N->Msg('a587_settings_indexoffline'),
  207. 'value' => '1',
  208. 'checked' => !empty($REX['ADDON']['settings']['rexsearch']['indexoffline'])
  209. ),
  210. array(
  211. 'type' => 'checkbox',
  212. 'id' => 'a587_rexsearch_automaticindex',
  213. 'name' => 'a587_rexsearch[automaticindex]',
  214. 'label' => $I18N->Msg('a587_settings_automaticindex_label'),
  215. 'value' => '1',
  216. 'checked' => !empty($REX['ADDON']['settings']['rexsearch']['automaticindex'])
  217. ),
  218. array(
  219. 'type' => 'checkbox',
  220. 'id' => 'a587_rexsearch_ep_outputfilter',
  221. 'name' => 'a587_rexsearch[ep_outputfilter]',
  222. 'label' => $I18N->Msg('a587_settings_ep_outputfilter_label'),
  223. 'value' => '1',
  224. 'checked' => !empty($REX['ADDON']['settings']['rexsearch']['ep_outputfilter'])
  225. )
  226. )
  227. );
  228. $sample = <<<EOT
  229. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  230. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
  231. EOT;
  232. $sampleoutput = '<div id="a587_sample_wrapper" style="padding:5px;clear:left;">
  233. <h5 class="rex-form-text">'.$I18N->Msg('a587_settings_highlight_sample').':</h5>
  234. <div id="a587_sample" style="margin-top:5px;padding:5px;border:1px solid #000;background:#fff;color:#000;">';
  235. $rexsearch = new rexsearch();
  236. $rexsearch->searchString = '"velit esse" accusam';
  237. $rexsearch->parseSearchString('"velit esse" accusam');
  238. if($rexsearch->highlightType == 'array')
  239. {
  240. $sampleoutput .= '<pre style="font-size:1.2em;">';
  241. $sampleoutput .= print_r($rexsearch->getHighlightedText($sample), true);
  242. $sampleoutput .= '</pre>';
  243. }
  244. else
  245. $sampleoutput .= $rexsearch->getHighlightedText($sample);
  246. $sampleoutput .= '</div></div>';
  247. echo a587_getSettingsFormSection(
  248. 'a587_highlight',
  249. $I18N->Msg('a587_settings_highlight_header'),
  250. array(
  251. array(
  252. 'type' => 'string',
  253. 'id' => 'a587_rexsearch_surroundtags_start',
  254. 'name' => 'a587_rexsearch[surroundtags][0]',
  255. 'label' => $I18N->Msg('a587_settings_surroundtags_start'),
  256. 'value' => isset($REX['ADDON']['settings']['rexsearch']['surroundtags'][0]) ? htmlspecialchars($REX['ADDON']['settings']['rexsearch']['surroundtags'][0]) : ''
  257. ),
  258. array(
  259. 'type' => 'string',
  260. 'id' => 'a587_rexsearch_surroundtags_end',
  261. 'name' => 'a587_rexsearch[surroundtags][1]',
  262. 'label' => $I18N->Msg('a587_settings_surroundtags_end'),
  263. 'value' => isset($REX['ADDON']['settings']['rexsearch']['surroundtags'][1]) ? htmlspecialchars($REX['ADDON']['settings']['rexsearch']['surroundtags'][1]) : ''
  264. ),
  265. array(
  266. 'type' => 'hidden',
  267. 'name' => 'a587_rexsearch[limit][0]',
  268. 'value' => '0'
  269. ),
  270. array(
  271. 'type' => 'string',
  272. 'id' => 'a587_rexsearch_limit',
  273. 'name' => 'a587_rexsearch[limit][1]',
  274. 'label' => $I18N->Msg('a587_settings_limit'),
  275. 'value' => isset($REX['ADDON']['settings']['rexsearch']['limit'][1]) ? intval($REX['ADDON']['settings']['rexsearch']['limit'][1]) : ''
  276. ),
  277. array(
  278. 'type' => 'string',
  279. 'id' => 'a587_rexsearch_maxteaserchars',
  280. 'name' => 'a587_rexsearch[maxteaserchars]',
  281. 'label' => $I18N->Msg('a587_settings_maxteaserchars'),
  282. 'value' => isset($REX['ADDON']['settings']['rexsearch']['maxteaserchars']) ? intval($REX['ADDON']['settings']['rexsearch']['maxteaserchars']) : ''
  283. ),
  284. array(
  285. 'type' => 'string',
  286. 'id' => 'a587_rexsearch_maxhighlightchars',
  287. 'name' => 'a587_rexsearch[maxhighlightchars]',
  288. 'label' => $I18N->Msg('a587_settings_maxhighlightchars'),
  289. 'value' => isset($REX['ADDON']['settings']['rexsearch']['maxhighlightchars']) ? intval($REX['ADDON']['settings']['rexsearch']['maxhighlightchars']) : ''
  290. ),
  291. array(
  292. 'type' => 'select',
  293. 'id' => 'a587_rexsearch_highlight',
  294. 'name' => 'a587_rexsearch[highlight]',
  295. 'label' => $I18N->Msg('a587_settings_highlight_label'),
  296. 'options' => array(
  297. array(
  298. 'value' => 'sentence',
  299. 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'sentence',
  300. 'name' => $I18N->Msg('a587_settings_highlight_sentence')
  301. ),
  302. array(
  303. 'value' => 'paragraph',
  304. 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'paragraph',
  305. 'name' => $I18N->Msg('a587_settings_highlight_paragraph')
  306. ),
  307. array(
  308. 'value' => 'surroundtext',
  309. 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'surroundtext',
  310. 'name' => $I18N->Msg('a587_settings_highlight_surroundtext')
  311. ),
  312. array(
  313. 'value' => 'surroundtextsingle',
  314. 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'surroundtextsingle',
  315. 'name' => $I18N->Msg('a587_settings_highlight_surroundtextsingle')
  316. ),
  317. array(
  318. 'value' => 'teaser',
  319. 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'teaser',
  320. 'name' => $I18N->Msg('a587_settings_highlight_teaser')
  321. ),
  322. array(
  323. 'value' => 'array',
  324. 'selected' => $REX['ADDON']['settings']['rexsearch']['highlight'] == 'array',
  325. 'name' => $I18N->Msg('a587_settings_highlight_array')
  326. ),
  327. )
  328. ),
  329. array(
  330. 'type' => 'directoutput',
  331. 'output' => '<div class="rex-form-row">'.$sampleoutput.'</div>'
  332. )
  333. )
  334. );
  335. $categories = array();
  336. foreach(a587_getCategories() as $id => $name)
  337. {
  338. $categories[] = array(
  339. 'value' => $id,
  340. 'selected' => !empty($REX['ADDON']['settings']['rexsearch']['exclude_category_ids']) AND is_array($REX['ADDON']['settings']['rexsearch']['exclude_category_ids']) AND in_array($id,$REX['ADDON']['settings']['rexsearch']['exclude_category_ids']),
  341. 'name' => $name.' ('.$id.')'
  342. );
  343. }
  344. $articles = array();
  345. foreach(a587_getArticles() as $id => $name)
  346. {
  347. $articles[] = array(
  348. 'value' => $id,
  349. 'selected' => !empty($REX['ADDON']['settings']['rexsearch']['exclude_article_ids']) AND is_array($REX['ADDON']['settings']['rexsearch']['exclude_article_ids']) AND in_array($id,$REX['ADDON']['settings']['rexsearch']['exclude_article_ids']),
  350. 'name' => $name.' ('.$id.')'
  351. );
  352. }
  353. echo a587_getSettingsFormSection(
  354. 'a587_exclude',
  355. $I18N->Msg('a587_settings_exclude'),
  356. array(
  357. array(
  358. 'type' => 'string',
  359. 'id' => 'a587_settings_exclude_blacklist',
  360. 'name' => 'a587_rexsearch[blacklist]',
  361. 'label' => $I18N->Msg('a587_settings_exclude_blacklist'),
  362. 'value' => isset($REX['ADDON']['settings']['rexsearch']['blacklist']) ? htmlspecialchars(implode(',',$REX['ADDON']['settings']['rexsearch']['blacklist'])) : ''
  363. ),
  364. array(
  365. 'type' => 'multipleselect',
  366. 'id' => 'a587_rexsearch_exclude_article_ids',
  367. 'name' => 'a587_rexsearch[exclude_article_ids][]',
  368. 'label' => $I18N->Msg('a587_settings_exclude_articles'),
  369. 'size' => 15,
  370. 'options' => $articles
  371. ),
  372. array(
  373. 'type' => 'multipleselect',
  374. 'id' => 'a587_rexsearch_exclude_category_ids',
  375. 'name' => 'a587_rexsearch[exclude_category_ids][]',
  376. 'label' => $I18N->Msg('a587_settings_exclude_categories'),
  377. 'size' => 15,
  378. 'options' => $categories
  379. )
  380. )
  381. );
  382. $options = array();
  383. $sql_tables = new rex_sql();
  384. foreach($sql_tables->showTables() as $table)
  385. {
  386. if(false === strpos($table,'587_search') AND false === strpos($table,'587_keywords'))
  387. {
  388. $sql_columns = new rex_sql();
  389. foreach($sql_tables->showColumns($table) as $column)
  390. {
  391. /*switch(strtolower(substr($column['type'],0,4)))
  392. {
  393. case 'text':
  394. case 'char':
  395. case 'varc':*/
  396. $options[] = array(
  397. 'value' => htmlspecialchars($table.'`.`'.$column['name']),
  398. 'checked' => in_array($column['name'],(!empty($REX['ADDON']['settings']['rexsearch']['include'][$table]) AND is_array($REX['ADDON']['settings']['rexsearch']['include'][$table]))?$REX['ADDON']['settings']['rexsearch']['include'][$table]:array()),
  399. 'name' => $table.' . '.$column['name'],
  400. 'id' => $table.' . '.$column['name']
  401. );
  402. //}
  403. }
  404. }
  405. }
  406. echo a587_getSettingsFormSection(
  407. 'a587_include',
  408. $I18N->Msg('a587_settings_include'),
  409. array(
  410. array(
  411. 'type' => 'multiplecheckboxes',
  412. 'id' => 'a587_rexsearch_include',
  413. 'name' => 'a587_rexsearch[include][]',
  414. //'label' => '&lt;table&gt;.&lt;column&gt;',
  415. 'label' => '',
  416. 'size' => 20,
  417. 'options' => $options
  418. )
  419. )
  420. );
  421. $options = array(
  422. array(
  423. 'value' => '',
  424. 'name' => '',
  425. 'selected' => false,
  426. 'id' => 'a587_optiondummy'
  427. )
  428. );
  429. if(!empty($REX['ADDON']['settings']['rexsearch']['indexfolders']))
  430. {
  431. foreach($REX['ADDON']['settings']['rexsearch']['indexfolders'] as $relative)
  432. {
  433. $options[] = array(
  434. 'value' => $relative,
  435. 'name' => $relative,
  436. 'selected' => true
  437. );
  438. }
  439. }
  440. foreach(range(1,30) as $depth)
  441. {
  442. $dirdepth_options[] = array(
  443. 'value' => $depth,
  444. 'name' => $depth,
  445. 'selected' => $REX['ADDON']['settings']['rexsearch']['dirdepth'] == $depth
  446. );
  447. }
  448. echo a587_getSettingsFormSection(
  449. 'a587_files',
  450. $I18N->Msg('a587_settings_fileext_header'),
  451. array(
  452. array(
  453. 'type' => 'string',
  454. 'id' => 'a587_settings_fileext_label',
  455. 'name' => 'a587_rexsearch[fileextensions]',
  456. 'label' => $I18N->Msg('a587_settings_fileext_label'),
  457. 'value' => isset($REX['ADDON']['settings']['rexsearch']['fileextensions']) ? htmlspecialchars(implode(',',$REX['ADDON']['settings']['rexsearch']['fileextensions'])) : ''
  458. ),
  459. array(
  460. 'type' => 'checkbox',
  461. 'id' => 'a587_settings_file_mediapool',
  462. 'name' => 'a587_rexsearch[indexmediapool]',
  463. 'label' => $I18N->Msg('a587_settings_file_mediapool'),
  464. 'value' => '1',
  465. 'checked' => !empty($REX['ADDON']['settings']['rexsearch']['indexmediapool'])
  466. ),
  467. array(
  468. 'type' => 'select',
  469. 'id' => 'a587_settings_file_dirdepth',
  470. 'name' => 'a587_rexsearch[dirdepth]',
  471. 'label' => $I18N->Msg('a587_settings_file_dirdepth_label'),
  472. 'options' => $dirdepth_options
  473. ),
  474. array(
  475. 'type' => 'multipleselect',
  476. 'id' => 'a587_settings_folders',
  477. 'name' => 'a587_rexsearch[indexfolders][]',
  478. 'label' => $I18N->Msg('a587_settings_folders_label'),
  479. 'size' => 10,
  480. 'options' => $options
  481. )
  482. )
  483. );
  484. ?>
  485. <div class="rex-form-row">
  486. <p class="rex-form-col-a rex-form-submit">
  487. <input type="submit" value="<?php echo $I18N->Msg('a587_settings_submitbutton'); ?>" name="sendit" class="rex-form-submit"/>
  488. </p>
  489. </div>
  490. </form>
  491. </div>
  492. </div>
  493. <script type="text/javascript">
  494. // <![CDATA[
  495. // width of the formular
  496. (function($)
  497. {
  498. $(document).ready(function()
  499. {
  500. var mainWidth = $('#a587-form').width();
  501. // set loading image for filesearch-config
  502. $('#a587_files legend').append(
  503. $('<span>')
  504. .attr('class','loading')
  505. );
  506. // accordion
  507. $.each($('#a587-form fieldset'), function(i, elem)
  508. {
  509. var legend = $('legend', elem);
  510. var wrapper = $('.rex-form-wrapper', elem);
  511. var speed = wrapper.attr('offsetHeight');
  512. wrapper.hide();
  513. $(elem)
  514. .css('border-bottom','1px solid #fff');
  515. legend
  516. .css('cursor','pointer')
  517. .css('width', (mainWidth - parseInt(legend.css('padding-right').replace(/[^0-9]+/,'')) - parseInt(legend.css('padding-left').replace(/[^0-9]+/,''))) + 'px')
  518. .css('border-bottom','1px solid #cbcbcb')
  519. .mouseover(function()
  520. {
  521. if(wrapper.css('display') == 'none')
  522. $('legend', elem).css('color','#aaa');
  523. })
  524. .mouseout(function()
  525. {
  526. legend.css('color','#32353A');
  527. })
  528. .click(function()
  529. {
  530. wrapper.slideToggle(speed);
  531. });
  532. });
  533. // display links for showing and hiding all sections
  534. $('#a587-form h2')
  535. .css('position','relative')
  536. .append(
  537. $('<div>')
  538. .css('position','absolute')
  539. .css('top','0')
  540. .css('right','0')
  541. .css('padding','5px 1em')
  542. .css('font-size','0.75em')
  543. .css('font-weight','900')
  544. .append(
  545. $('<a><?php echo $I18N->Msg('a587_settings_show_all'); ?><'+'/a>')
  546. .css('cursor','pointer')
  547. .css('padding','0 1em')
  548. .click(function()
  549. {
  550. $.each($('#a587-form fieldset'), function(i, elem)
  551. {
  552. $('.rex-form-wrapper', elem).show();
  553. })
  554. })
  555. )
  556. .append(
  557. $('<a><?php echo $I18N->Msg('a587_settings_show_none'); ?><'+'/a>')
  558. .css('cursor','pointer')
  559. .click(function()
  560. {
  561. $.each($('#a587-form fieldset'), function(i, elem)
  562. {
  563. $('.rex-form-wrapper', elem).hide();
  564. })
  565. })
  566. )
  567. );
  568. // ajax request for sample-text
  569. $('#a587_rexsearch_highlight')
  570. .change(function()
  571. {
  572. $.get('index.php?page=rexsearch&ajax=sample&type='+$('#a587_rexsearch_highlight').attr('value'),{},function(data)
  573. {
  574. $('#a587_sample').html(data);
  575. });
  576. });
  577. // categorize datebase tables
  578. var current_table = '';
  579. $('#a587_include .checkbox').each(function(i, elem)
  580. {
  581. var table = $('input', elem).attr('value').split(/`.`/)[0];
  582. $('label', elem).text($('input', elem).attr('value').split(/`.`/)[1]);
  583. if(current_table != table)
  584. {
  585. $(elem).before(
  586. $('<div>').addClass('checkbox-heading rex-form-row').text(table).click(function()
  587. {
  588. var $next = $(this).next();
  589. var $elements = $next;
  590. while($next.hasClass('checkbox'))
  591. {
  592. //$next.show();
  593. $elements = $elements.add($next);
  594. $next = $next.next();
  595. }
  596. $elements.toggle();
  597. })
  598. );
  599. current_table = table;
  600. }
  601. });
  602. var active_tables = $();
  603. $('#a587_include .checkbox input:checked').each(function(i, elem)
  604. {
  605. var $prev = $(this).closest('.checkbox').prev();
  606. while($prev.hasClass('checkbox'))
  607. $prev = $prev.prev();
  608. active_tables = active_tables.add($prev);
  609. });
  610. active_tables.click();
  611. // directory-selection
  612. function getElementByValue(elements, value) {
  613. var returnElem = false;
  614. $.each(elements, function(i, elem)
  615. {
  616. if(elem.value == value)
  617. {
  618. returnElem = elem;
  619. return false;
  620. }
  621. });
  622. return returnElem;
  623. }
  624. function setDirs()
  625. {
  626. var depth = 0,dirs = new Array(),found,indexdirs;
  627. while(document.getElementById('subdirs_'+depth))
  628. {
  629. $.each($('#subdirs_'+depth+' option'), function(i, elem)
  630. {
  631. if(elem.selected)
  632. dirs.push(elem.value);
  633. });
  634. depth++;
  635. }
  636. indexdirs = new Array();
  637. for(var k=0; k < dirs.length; k++)
  638. {
  639. found = false;
  640. for(var i=0; i < dirs.length; i++)
  641. {
  642. //if(dirs[k].substring(0,dirs[k].lastIndexOf('/')) == dirs[i])
  643. if((dirs[i].indexOf(dirs[k]) >= 0) && (i != k))
  644. {
  645. found = true;
  646. //dirs.splice(i,1);
  647. //break;
  648. }
  649. }
  650. if(!found)
  651. indexdirs.push(dirs[k]);
  652. }
  653. $('#a587_settings_folders').empty();
  654. $.each(indexdirs, function(i, elem)
  655. {
  656. $('#a587_settings_folders')
  657. .append(
  658. $('<option>')
  659. .attr('value', elem)
  660. .text(elem)
  661. );
  662. });
  663. }
  664. function traverseSubdirs(depth, options)
  665. {
  666. var found,empty,activeOptions = new Array(),elem;
  667. for(var i = 0; i < options.length; i++)
  668. {
  669. if((elem = getElementByValue($('#subdirs_'+(depth-1)+' option'), options[i])) && elem.selected)
  670. activeOptions.push(options[i]);
  671. }
  672. while(document.getElementById('subdirs_'+depth))
  673. {
  674. empty = true;
  675. $.each($('#subdirs_'+depth+' option'), function(i, elem)
  676. {
  677. found = false;
  678. for(var k = 0; k < activeOptions.length; k++)
  679. {
  680. found = found || (elem.value.indexOf(activeOptions[k]) >= 0);
  681. }
  682. if(!found)
  683. $(elem).remove();
  684. else
  685. empty = false;
  686. });
  687. if(empty)
  688. {
  689. $('#subdirs_'+depth).remove();
  690. $('#subdirselectlabel_'+depth).remove();
  691. }
  692. depth++;
  693. }
  694. }
  695. function a587_serialize(a)
  696. {
  697. var anew = new Array();
  698. for(var i = 0; i < a.length; i++)
  699. anew.push('"' + (a[i].replace(/"/g, '\\"')) + '"');
  700. return '[' + anew.join(',') + ']';
  701. }
  702. function createSubdirSection(depth,autoselect)
  703. {
  704. var parent,options,startdirstring = '',startdirs = new Array();
  705. if(depth == 0)
  706. {
  707. parent = '#a587_settings_folders';
  708. }
  709. else
  710. {
  711. parent = '#subdirs_'+(depth-1);
  712. $.each($('#subdirs_'+(depth-1)+' option'), function(i, elem)
  713. {
  714. if(elem.selected)
  715. {
  716. startdirs.push(elem.value);
  717. }
  718. });
  719. }
  720. if(depth > 0 && !startdirs.length)
  721. {
  722. var currentDepth = depth;
  723. while(document.getElementById('subdirs_'+currentDepth))
  724. {
  725. $('#subdirs_'+(currentDepth)).remove();
  726. $('#subdirselectlabel_'+(currentDepth++)).remove();
  727. }
  728. $('#a587_files .loading').remove();
  729. while(document.getElementById('subdirs_'+(--depth)))
  730. $('#subdirs_'+(depth--)).removeAttr('disabled');
  731. return false;
  732. }
  733. else
  734. {
  735. $.post('index.php?page=rexsearch&ajax=getdirs', {'startdirs':a587_serialize(startdirs)}, function(options)
  736. {
  737. if(!document.getElementById('subdirs_'+depth) && options.length > 0)
  738. {
  739. $(parent)
  740. .after(
  741. $('<select>')
  742. .attr('id','subdirs_'+depth)
  743. .attr('class','rex-form-text subdirselect')
  744. .attr('multiple','multiple')
  745. .attr('size','10')
  746. .change(function()
  747. {
  748. createSubdirSection(depth+1);
  749. traverseSubdirs(depth+1, options);
  750. setDirs();
  751. })
  752. )
  753. .after(
  754. $('<label>')
  755. .text(('<?php echo $I18N->Msg('a587_settings_folders_dirselect_label'); ?>').replace(/%DEPTH%/, depth))
  756. .attr('for','subdirs_'+depth)
  757. .attr('class','subdirselectlabel')
  758. .attr('id','subdirselectlabel_'+depth)
  759. );
  760. if(autoselect)
  761. $('#subdirs_'+depth).attr('disabled','disabled');
  762. }
  763. for(var i = 0; i < options.length; i++)
  764. {
  765. if(!getElementByValue($('#subdirs_'+depth+' option'), options[i]))
  766. {
  767. if(autoselect)
  768. {
  769. var found = false;
  770. $('#a587_settings_folders option').each(function(j, elem)
  771. {
  772. found = found || (elem.value.indexOf(options[i]) >= 0);
  773. if(found)
  774. return false;
  775. });
  776. if(found)
  777. {
  778. $('#subdirs_'+depth)
  779. .append(
  780. $('<option>')
  781. .attr('value', options[i])
  782. .attr('selected', 'selected')
  783. .text(options[i])
  784. );
  785. }
  786. else
  787. {
  788. $('#subdirs_'+depth)
  789. .append(
  790. $('<option>')
  791. .attr('value', options[i])
  792. .text(options[i])
  793. );
  794. }
  795. }
  796. else
  797. {
  798. $('#subdirs_'+depth)
  799. .append(
  800. $('<option>')
  801. .attr('value', options[i])
  802. .text(options[i])
  803. );
  804. }
  805. }
  806. }
  807. if(autoselect)
  808. {
  809. var maxDepth = 0,splitted,current,count;
  810. $('#a587_settings_folders option').each(function(i, elem)
  811. {
  812. if((elem.id != 'a587_optiondummy') && ((count = elem.value.split('/').length-2) > maxDepth))
  813. maxDepth = count;
  814. });
  815. if(maxDepth >= depth)
  816. {
  817. createSubdirSection(depth+1,true);
  818. }
  819. else
  820. {
  821. $('#a587_files .loading').remove();
  822. depth = 0;
  823. while(document.getElementById('subdirs_'+depth))
  824. $('#subdirs_'+(depth++)).removeAttr('disabled');
  825. depth--;
  826. // adapt width of legend
  827. var legend = $('#a587_files legend');
  828. legend.css('padding-right', (mainWidth - legend.attr('offsetWidth') + parseInt(legend.css('padding-right').replace(/[^0-9]+/,''))) + 'px');
  829. }
  830. }
  831. }, 'json');
  832. return true;
  833. }
  834. }
  835. var options;
  836. // beautifying the indexed folders selectbox and selecting the options in the subdir-selectboxes
  837. $('#a587_settings_folders').attr('disabled','disabled');
  838. $.each(options = $('#a587_settings_folders option'), function(i, elem)
  839. {
  840. var splitted,current,depth=0;
  841. elem.selected = false;
  842. if(options.length - 1 == i)
  843. createSubdirSection(depth,true);
  844. });
  845. $('#a587_settings_form').submit(function()
  846. {
  847. $('#a587_settings_folders').removeAttr('disabled');
  848. $.each($('#a587_settings_folders option'), function(i, elem)
  849. {
  850. if(elem.value != '')
  851. elem.selected = true;
  852. });
  853. return true;
  854. });
  855. });
  856. }(jQuery));
  857. // ]]>
  858. </script>