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