| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2010 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 | # Getting categories | 
|---|
| 18 | try { | 
|---|
| 19 |      $categories = $core->blog->getCategories(array('post_type'=>'post')); | 
|---|
| 20 | } catch (Exception $e) { | 
|---|
| 21 |      $core->error->add($e->getMessage()); | 
|---|
| 22 | } | 
|---|
| 23 |  | 
|---|
| 24 | # Getting authors | 
|---|
| 25 | try { | 
|---|
| 26 |      $users = $core->blog->getPostsUsers(); | 
|---|
| 27 | } catch (Exception $e) { | 
|---|
| 28 |      $core->error->add($e->getMessage()); | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | # Getting dates | 
|---|
| 32 | try { | 
|---|
| 33 |      $dates = $core->blog->getDates(array('type'=>'month')); | 
|---|
| 34 | } catch (Exception $e) { | 
|---|
| 35 |      $core->error->add($e->getMessage()); | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | # Getting langs | 
|---|
| 39 | try { | 
|---|
| 40 |      $langs = $core->blog->getLangs(); | 
|---|
| 41 | } catch (Exception $e) { | 
|---|
| 42 |      $core->error->add($e->getMessage()); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | # Creating filter combo boxes | 
|---|
| 46 | if (!$core->error->flag()) | 
|---|
| 47 | { | 
|---|
| 48 |      # Filter form we'll put in html_block | 
|---|
| 49 |      $users_combo = $categories_combo = array(); | 
|---|
| 50 |      while ($users->fetch()) | 
|---|
| 51 |      { | 
|---|
| 52 |           $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, | 
|---|
| 53 |           $users->user_firstname,$users->user_displayname); | 
|---|
| 54 |            | 
|---|
| 55 |           if ($user_cn != $users->user_id) { | 
|---|
| 56 |                $user_cn .= ' ('.$users->user_id.')'; | 
|---|
| 57 |           } | 
|---|
| 58 |            | 
|---|
| 59 |           $users_combo[$user_cn] = $users->user_id;  | 
|---|
| 60 |      } | 
|---|
| 61 |       | 
|---|
| 62 |      $categories_combo[__('None')] = 'NULL'; | 
|---|
| 63 |      while ($categories->fetch()) { | 
|---|
| 64 |           $categories_combo[str_repeat('  ',$categories->level-1).'• '. | 
|---|
| 65 |                html::escapeHTML($categories->cat_title). | 
|---|
| 66 |                ' ('.$categories->nb_post.')'] = $categories->cat_id; | 
|---|
| 67 |      } | 
|---|
| 68 |       | 
|---|
| 69 |      $status_combo = array( | 
|---|
| 70 |      ); | 
|---|
| 71 |      foreach ($core->blog->getAllPostStatus() as $k => $v) { | 
|---|
| 72 |           $status_combo[$v] = (string) $k; | 
|---|
| 73 |      } | 
|---|
| 74 |       | 
|---|
| 75 |      $selected_combo = array( | 
|---|
| 76 |      __('selected') => '1', | 
|---|
| 77 |      __('not selected') => '0' | 
|---|
| 78 |      ); | 
|---|
| 79 |       | 
|---|
| 80 |      # Months array | 
|---|
| 81 |      while ($dates->fetch()) { | 
|---|
| 82 |           $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); | 
|---|
| 83 |      } | 
|---|
| 84 |       | 
|---|
| 85 |      while ($langs->fetch()) { | 
|---|
| 86 |           $lang_combo[$langs->post_lang] = $langs->post_lang; | 
|---|
| 87 |      } | 
|---|
| 88 |       | 
|---|
| 89 |      $sortby_combo = array( | 
|---|
| 90 |      __('Date') => 'post_dt', | 
|---|
| 91 |      __('Title') => 'post_title', | 
|---|
| 92 |      __('Category') => 'cat_title', | 
|---|
| 93 |      __('Author') => 'user_id', | 
|---|
| 94 |      __('Status') => 'post_status', | 
|---|
| 95 |      __('Selected') => 'post_selected' | 
|---|
| 96 |      ); | 
|---|
| 97 |       | 
|---|
| 98 |      $order_combo = array( | 
|---|
| 99 |      __('Descending') => 'desc', | 
|---|
| 100 |      __('Ascending') => 'asc' | 
|---|
| 101 |      ); | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 | # Actions combo box | 
|---|
| 105 | $combo_action = array(); | 
|---|
| 106 | if ($core->auth->check('publish,contentadmin',$core->blog->id)) | 
|---|
| 107 | { | 
|---|
| 108 |      $combo_action[__('Status')] = array( | 
|---|
| 109 |           __('Publish') => 'publish', | 
|---|
| 110 |           __('Unpublish') => 'unpublish', | 
|---|
| 111 |           __('Schedule') => 'schedule', | 
|---|
| 112 |           __('Mark as pending') => 'pending' | 
|---|
| 113 |      ); | 
|---|
| 114 | } | 
|---|
| 115 | $combo_action[__('Mark')] = array( | 
|---|
| 116 |      __('Mark as selected') => 'selected', | 
|---|
| 117 |      __('Mark as unselected') => 'unselected' | 
|---|
| 118 | ); | 
|---|
| 119 | $combo_action[__('Change')] = array(__('Change category') => 'category'); | 
|---|
| 120 | if ($core->auth->check('admin',$core->blog->id)) | 
|---|
| 121 | { | 
|---|
| 122 |      $combo_action[__('Change')] = array_merge($combo_action[__('Change')], | 
|---|
| 123 |           array(__('Change author') => 'author')); | 
|---|
| 124 | } | 
|---|
| 125 | if ($core->auth->check('delete,contentadmin',$core->blog->id)) | 
|---|
| 126 | { | 
|---|
| 127 |      $combo_action[__('Delete')] = array(__('Delete') => 'delete'); | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 | # --BEHAVIOR-- adminPostsActionsCombo | 
|---|
| 131 | $core->callBehavior('adminPostsActionsCombo',array(&$combo_action)); | 
|---|
| 132 |  | 
|---|
| 133 | /* Get posts | 
|---|
| 134 | -------------------------------------------------------- */ | 
|---|
| 135 | $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; | 
|---|
| 136 | $nb_per_page =  30; | 
|---|
| 137 |  | 
|---|
| 138 | if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { | 
|---|
| 139 |      if ($nb_per_page != $_GET['nb']) { | 
|---|
| 140 |           $show_filters = true; | 
|---|
| 141 |      } | 
|---|
| 142 |      $nb_per_page = (integer) $_GET['nb']; | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | $params = new ArrayObject(); | 
|---|
| 146 | $params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); | 
|---|
| 147 | $params['no_content'] = true; | 
|---|
| 148 |  | 
|---|
| 149 | $filterSet = new dcFilterSet('posts.php'); | 
|---|
| 150 | class monthComboFilter extends comboFilter { | 
|---|
| 151 |      public function applyFilter($params) { | 
|---|
| 152 |           $month=$this->values[0]; | 
|---|
| 153 |           $params['post_month'] = substr($month,4,2); | 
|---|
| 154 |           $params['post_year'] = substr($month,0,4); | 
|---|
| 155 |      } | 
|---|
| 156 | } | 
|---|
| 157 | $filterSet | 
|---|
| 158 |      ->addFilter(new comboFilter( | 
|---|
| 159 |           'users',__('Author'), 'user', $users_combo)) | 
|---|
| 160 |      ->addFilter(new comboFilter( | 
|---|
| 161 |           'category',__('Category'), 'cat_id', $categories_combo)) | 
|---|
| 162 |      ->addFilter(new comboFilter( | 
|---|
| 163 |           'post_status',__('Status'), 'post_status', $status_combo,array('singleval' => 1))) | 
|---|
| 164 |      ->addFilter(new comboFilter( | 
|---|
| 165 |           'post_selected',__('Selected'), 'post_selected', $selected_combo)) | 
|---|
| 166 |      ->addFilter(new comboFilter( | 
|---|
| 167 |           'lang',__('Lang'), 'post_lang', $lang_combo)) | 
|---|
| 168 |      ->addFilter(new monthComboFilter( | 
|---|
| 169 |           'month',__('Month'), 'post_month', $dt_m_combo,array('singleval' => 1))); | 
|---|
| 170 | $filterSet->setValues($_GET); | 
|---|
| 171 |  | 
|---|
| 172 | # Get posts | 
|---|
| 173 | try { | 
|---|
| 174 |      $nfparams = $params->getArrayCopy(); | 
|---|
| 175 |      $filtered = $filterSet->applyFilters($params); | 
|---|
| 176 |      $posts = $core->blog->getPosts($params); | 
|---|
| 177 |      $counter = $core->blog->getPosts($params,true); | 
|---|
| 178 |      if ($filtered) { | 
|---|
| 179 |           $totalcounter = $core->blog->getPosts($nfparams,true); | 
|---|
| 180 |           $page_title = sprintf(__('Entries / %s filtered out of %s'),$counter->f(0),$totalcounter->f(0)); | 
|---|
| 181 |      } else { | 
|---|
| 182 |           $page_title = __('Entries'); | 
|---|
| 183 |      } | 
|---|
| 184 |      $post_list = new adminPostList($core,$posts,$counter->f(0)); | 
|---|
| 185 | } catch (Exception $e) { | 
|---|
| 186 |      $core->error->add($e->getMessage()); | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | $filterSet->setColumnsForm($post_list->getColumnsForm()); | 
|---|
| 190 |  | 
|---|
| 191 | /* DISPLAY | 
|---|
| 192 | -------------------------------------------------------- */ | 
|---|
| 193 | $starting_script = dcPage::jsLoad('js/_posts_list.js'); | 
|---|
| 194 |  | 
|---|
| 195 | $starting_script .= $filterSet->header(); | 
|---|
| 196 |  | 
|---|
| 197 | dcPage::open(__('Entries'),$starting_script); | 
|---|
| 198 |  | 
|---|
| 199 | if (!$core->error->flag()) | 
|---|
| 200 | { | 
|---|
| 201 |      echo  | 
|---|
| 202 |      '<h2>'.html::escapeHTML($core->blog->name).' › '.$page_title.'</h2>'. | 
|---|
| 203 |      '<p class="top-add"><a class="button add" href="post.php">'.__('New entry').'</a></p>'; | 
|---|
| 204 |  | 
|---|
| 205 |      $filterSet->display(); | 
|---|
| 206 |  | 
|---|
| 207 |      # Show posts | 
|---|
| 208 |      $post_list->display($page,$nb_per_page, | 
|---|
| 209 |      '<form action="posts_actions.php" method="post" id="form-entries">'. | 
|---|
| 210 |       | 
|---|
| 211 |      '%s'. | 
|---|
| 212 |       | 
|---|
| 213 |      '<div class="two-cols">'. | 
|---|
| 214 |      '<p class="col checkboxes-helpers"></p>'. | 
|---|
| 215 |       | 
|---|
| 216 |      '<p class="col right"><label for="action" class="classic">'.__('Selected entries action:').'</label> '. | 
|---|
| 217 |      form::combo('action',$combo_action). | 
|---|
| 218 |      '<input type="submit" value="'.__('ok').'" /></p>'. | 
|---|
| 219 |      $filterSet->getFormFieldsAsHidden(). | 
|---|
| 220 |      $core->formNonce(). | 
|---|
| 221 |      '</div>'. | 
|---|
| 222 |      '</form>' | 
|---|
| 223 |      ); | 
|---|
| 224 | } | 
|---|
| 225 |  | 
|---|
| 226 | dcPage::helpBlock('core_posts'); | 
|---|
| 227 | dcPage::close(); | 
|---|
| 228 | ?> | 
|---|