1 | <?php |
---|
2 | /** |
---|
3 | * @package Dotclear |
---|
4 | * @subpackage Backend |
---|
5 | * |
---|
6 | * @copyright Olivier Meunier & Association Dotclear |
---|
7 | * @copyright GPL-2.0-only |
---|
8 | */ |
---|
9 | |
---|
10 | require dirname(__FILE__) . '/../inc/admin/prepend.php'; |
---|
11 | |
---|
12 | dcPage::check('usage,contentadmin'); |
---|
13 | |
---|
14 | $q = !empty($_REQUEST['q']) ? $_REQUEST['q'] : (!empty($_REQUEST['qx']) ? $_REQUEST['qx'] : null); |
---|
15 | $qtype = !empty($_REQUEST['qtype']) ? $_REQUEST['qtype'] : 'p'; |
---|
16 | if ($qtype != 'c' && $qtype != 'p') { |
---|
17 | $qtype = 'p'; |
---|
18 | } |
---|
19 | |
---|
20 | $starting_scripts = ''; |
---|
21 | |
---|
22 | $page = !empty($_GET['page']) ? max(1, (integer) $_GET['page']) : 1; |
---|
23 | $nb_per_page = 30; |
---|
24 | |
---|
25 | if ($q) { |
---|
26 | $q = html::escapeHTML($q); |
---|
27 | |
---|
28 | $params = []; |
---|
29 | |
---|
30 | # Get posts |
---|
31 | if ($qtype == 'p') { |
---|
32 | $starting_scripts .= dcPage::jsLoad('js/_posts_list.js'); |
---|
33 | |
---|
34 | $params['search'] = $q; |
---|
35 | $params['limit'] = [(($page - 1) * $nb_per_page), $nb_per_page]; |
---|
36 | $params['no_content'] = true; |
---|
37 | $params['order'] = 'post_dt DESC'; |
---|
38 | |
---|
39 | try { |
---|
40 | $posts = $core->blog->getPosts($params); |
---|
41 | $counter = $core->blog->getPosts($params, true); |
---|
42 | $post_list = new adminPostList($core, $posts, $counter->f(0)); |
---|
43 | } catch (Exception $e) { |
---|
44 | $core->error->add($e->getMessage()); |
---|
45 | } |
---|
46 | } |
---|
47 | # Get comments |
---|
48 | elseif ($qtype == 'c') { |
---|
49 | $starting_scripts .= dcPage::jsLoad('js/_comments.js'); |
---|
50 | |
---|
51 | $params['search'] = $q; |
---|
52 | $params['limit'] = [(($page - 1) * $nb_per_page), $nb_per_page]; |
---|
53 | $params['no_content'] = true; |
---|
54 | $params['order'] = 'comment_dt DESC'; |
---|
55 | |
---|
56 | try { |
---|
57 | $comments = $core->blog->getComments($params); |
---|
58 | $counter = $core->blog->getComments($params, true); |
---|
59 | $comment_list = new adminCommentList($core, $comments, $counter->f(0)); |
---|
60 | } catch (Exception $e) { |
---|
61 | $core->error->add($e->getMessage()); |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | if ($qtype == 'p') { |
---|
67 | $posts_actions_page = new dcPostsActionsPage($core, $core->adminurl->get("admin.search"), ['q' => $q, 'qtype' => $qtype]); |
---|
68 | |
---|
69 | if ($posts_actions_page->process()) { |
---|
70 | return; |
---|
71 | } |
---|
72 | } else { |
---|
73 | $comments_actions_page = new dcCommentsActionsPage($core, $core->adminurl->get("admin.search"), ['q' => $q, 'qtype' => $qtype]); |
---|
74 | |
---|
75 | if ($comments_actions_page->process()) { |
---|
76 | return; |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | dcPage::open(__('Search'), $starting_scripts, |
---|
81 | dcPage::breadcrumb( |
---|
82 | [ |
---|
83 | html::escapeHTML($core->blog->name) => '', |
---|
84 | __('Search') => '' |
---|
85 | ]) |
---|
86 | ); |
---|
87 | |
---|
88 | echo |
---|
89 | '<form action="' . $core->adminurl->get("admin.search") . '" method="get" role="search">' . |
---|
90 | '<div class="fieldset"><h3>' . __('Search options') . '</h3>' . |
---|
91 | '<p><label for="q">' . __('Query:') . ' </label>' . form::field('q', 30, 255, $q) . '</p>' . |
---|
92 | '<p><label for="qtype1" class="classic">' . form::radio(['qtype', 'qtype1'], 'p', $qtype == 'p') . ' ' . __('Search in entries') . '</label> ' . |
---|
93 | '<label for="qtype2" class="classic">' . form::radio(['qtype', 'qtype2'], 'c', $qtype == 'c') . ' ' . __('Search in comments') . '</label></p>' . |
---|
94 | '<p><input type="submit" value="' . __('Search') . '" /></p>' . |
---|
95 | '</div>' . |
---|
96 | '</form>'; |
---|
97 | |
---|
98 | if ($q && !$core->error->flag()) { |
---|
99 | $redir = html::escapeHTML($_SERVER['REQUEST_URI']); |
---|
100 | |
---|
101 | # Show posts |
---|
102 | if ($qtype == 'p') { |
---|
103 | |
---|
104 | if ($counter->f(0) > 0) { |
---|
105 | printf('<h3>' . |
---|
106 | ($counter->f(0) == 1 ? __('%d entry found') : __('%d entries found')) . |
---|
107 | '</h3>', $counter->f(0)); |
---|
108 | } |
---|
109 | |
---|
110 | $post_list->display($page, $nb_per_page, |
---|
111 | '<form action="' . $core->adminurl->get("admin.search") . '" method="post" id="form-entries">' . |
---|
112 | |
---|
113 | '%s' . |
---|
114 | |
---|
115 | '<div class="two-cols">' . |
---|
116 | '<p class="col checkboxes-helpers"></p>' . |
---|
117 | |
---|
118 | '<p class="col right"><label for="action1" class="classic">' . __('Selected entries action:') . '</label> ' . |
---|
119 | form::combo(['action', 'action1'], $posts_actions_page->getCombo()) . |
---|
120 | '<input id="do-action" type="submit" value="' . __('ok') . '" /></p>' . |
---|
121 | $core->formNonce() . |
---|
122 | $posts_actions_page->getHiddenFields() . |
---|
123 | '</div>' . |
---|
124 | '</form>' |
---|
125 | ); |
---|
126 | } |
---|
127 | # Show posts |
---|
128 | elseif ($qtype == 'c') { |
---|
129 | # Actions combo box |
---|
130 | |
---|
131 | if ($counter->f(0) > 0) { |
---|
132 | printf('<h3>' . |
---|
133 | ($counter->f(0) == 1 ? __('%d comment found') : __('%d comments found')) . |
---|
134 | '</h3>', $counter->f(0)); |
---|
135 | } |
---|
136 | |
---|
137 | $comment_list->display($page, $nb_per_page, |
---|
138 | '<form action="' . $core->adminurl->get("admin.search") . '" method="post" id="form-comments">' . |
---|
139 | |
---|
140 | '%s' . |
---|
141 | |
---|
142 | '<div class="two-cols">' . |
---|
143 | '<p class="col checkboxes-helpers"></p>' . |
---|
144 | |
---|
145 | '<p class="col right"><label for="action2" class="classic">' . __('Selected comments action:') . '</label> ' . |
---|
146 | form::combo(['action', 'action2'], $comments_actions_page->getCombo()) . |
---|
147 | '<input id="do-action" type="submit" value="' . __('ok') . '" /></p>' . |
---|
148 | $core->formNonce() . |
---|
149 | $comments_actions_page->getHiddenFields() . |
---|
150 | '</div>' . |
---|
151 | '</form>' |
---|
152 | ); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | dcPage::helpBlock('core_search'); |
---|
157 | dcPage::close(); |
---|