| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2011 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('categories'); | 
|---|
| 16 |  | 
|---|
| 17 | # Remove a category | 
|---|
| 18 | if (!empty($_POST['del_cat'])) | 
|---|
| 19 | { | 
|---|
| 20 |      try | 
|---|
| 21 |      { | 
|---|
| 22 |           $c = $core->blog->getCategory((integer) $_POST['del_cat']); | 
|---|
| 23 |           if ($c->isEmpty()) { | 
|---|
| 24 |                throw new Exception(__('This category does not exist.')); | 
|---|
| 25 |           } | 
|---|
| 26 |           unset($c); | 
|---|
| 27 |           $core->blog->delCategory($_POST['del_cat']); | 
|---|
| 28 |           http::redirect('categories.php?del=1'); | 
|---|
| 29 |      } | 
|---|
| 30 |      catch (Exception $e) | 
|---|
| 31 |      { | 
|---|
| 32 |           $core->error->add($e->getMessage()); | 
|---|
| 33 |      } | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | # Reset order | 
|---|
| 37 | if (!empty($_POST['reset'])) | 
|---|
| 38 | { | 
|---|
| 39 |      try | 
|---|
| 40 |      { | 
|---|
| 41 |           $core->blog->resetCategoriesOrder(); | 
|---|
| 42 |           http::redirect('categories.php?reord=1'); | 
|---|
| 43 |      } | 
|---|
| 44 |      catch (Exception $e) | 
|---|
| 45 |      { | 
|---|
| 46 |           $core->error->add($e->getMessage()); | 
|---|
| 47 |      } | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | /* Display | 
|---|
| 51 | -------------------------------------------------------- */ | 
|---|
| 52 | dcPage::open(__('Categories'), | 
|---|
| 53 |      dcPage::jsToolMan()."\n". | 
|---|
| 54 |      dcPage::jsLoad('js/_categories.js') | 
|---|
| 55 | ); | 
|---|
| 56 |  | 
|---|
| 57 | if (!empty($_GET['add'])) { | 
|---|
| 58 |      echo '<p class="message">'.__('The category has been successfully created.').'</p>'; | 
|---|
| 59 | } | 
|---|
| 60 | if (!empty($_GET['del'])) { | 
|---|
| 61 |           echo '<p class="message">'.__('The category has been successfully removed.').'</p>'; | 
|---|
| 62 | } | 
|---|
| 63 | if (!empty($_GET['reord'])) { | 
|---|
| 64 |           echo '<p class="message">'.__('Categories have been successfully reordered.').'</p>'; | 
|---|
| 65 | } | 
|---|
| 66 | if (!empty($_GET['moved'])) { | 
|---|
| 67 |           echo '<p class="message">'.__('The category has been successfully moved.').'</p>'; | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Categories').'</h2>'; | 
|---|
| 71 |  | 
|---|
| 72 | $rs = $core->blog->getCategories(array('post_type'=>'post')); | 
|---|
| 73 |  | 
|---|
| 74 | echo | 
|---|
| 75 | '<div class="two-cols">'. | 
|---|
| 76 | '<div class="col">'; | 
|---|
| 77 | if ($rs->isEmpty()) | 
|---|
| 78 | { | 
|---|
| 79 |      echo '<p>'.__('No category yet.').'</p>'; | 
|---|
| 80 | } | 
|---|
| 81 | else | 
|---|
| 82 | { | 
|---|
| 83 |      echo | 
|---|
| 84 |      '<h3>'.__('Categories list').'</h3>'. | 
|---|
| 85 |      '<div id="categories">'; | 
|---|
| 86 |       | 
|---|
| 87 |      $ref_level = $level = $rs->level-1; | 
|---|
| 88 |      while ($rs->fetch()) | 
|---|
| 89 |      { | 
|---|
| 90 |           $attr = 'id="cat'.$rs->cat_id.'"'; | 
|---|
| 91 |           if ($rs->nb_total == 0) { | 
|---|
| 92 |                $attr .= ' class="deletable"'; | 
|---|
| 93 |           } | 
|---|
| 94 |            | 
|---|
| 95 |           if ($rs->level > $level) { | 
|---|
| 96 |                echo str_repeat('<ul><li '.$attr.'>',$rs->level - $level); | 
|---|
| 97 |           } elseif ($rs->level < $level) { | 
|---|
| 98 |                echo str_repeat('</li></ul>',-($rs->level - $level)); | 
|---|
| 99 |           } | 
|---|
| 100 |            | 
|---|
| 101 |           if ($rs->level <= $level) { | 
|---|
| 102 |                echo '</li><li '.$attr.'>'; | 
|---|
| 103 |           } | 
|---|
| 104 |            | 
|---|
| 105 |           echo | 
|---|
| 106 |           '<p><strong><a href="category.php?id='.$rs->cat_id.'">'.html::escapeHTML($rs->cat_title).'</a></strong>'. | 
|---|
| 107 |           ' (<a href="posts.php?cat_id='.$rs->cat_id.'">'. | 
|---|
| 108 |           sprintf(($rs->nb_post > 1 ? __('%d entries') : __('%d entry') ),$rs->nb_post).'</a>'. | 
|---|
| 109 |           ', '.__('total:').' '.$rs->nb_total.')</p>'. | 
|---|
| 110 |           '<p>'.__('URL:').' '.html::escapeHTML($rs->cat_url).'</p>'; | 
|---|
| 111 |            | 
|---|
| 112 |           $level = $rs->level; | 
|---|
| 113 |      } | 
|---|
| 114 |       | 
|---|
| 115 |      if ($ref_level - $level < 0) { | 
|---|
| 116 |           echo str_repeat('</li></ul>',-($ref_level - $level)); | 
|---|
| 117 |      } | 
|---|
| 118 |      echo '</div>'; | 
|---|
| 119 | } | 
|---|
| 120 | echo '</div>'; | 
|---|
| 121 |  | 
|---|
| 122 | echo '<div class="col">'. | 
|---|
| 123 |  | 
|---|
| 124 | '<form action="category.php" method="post">'. | 
|---|
| 125 | '<fieldset><legend>'.__('Add a new category').'</legend>'. | 
|---|
| 126 | '<p><label class="required" for="cat_title"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').' '. | 
|---|
| 127 | form::field('cat_title',30,255).'</label></p>'. | 
|---|
| 128 | '<p><label for="new_cat_parent">'.__('Parent:').' '. | 
|---|
| 129 | '<select id="new_cat_parent" name="new_cat_parent">'. | 
|---|
| 130 | '<option value="0">'.__('Top level').'</option>'; | 
|---|
| 131 | while ($rs->fetch()) { | 
|---|
| 132 |      echo '<option value="'.$rs->cat_id.'">'. | 
|---|
| 133 |           str_repeat('  ',$rs->level-1).($categories->level-1 == 0 ? '' : '• '). | 
|---|
| 134 |           html::escapeHTML($rs->cat_title).'</option>'; | 
|---|
| 135 | } | 
|---|
| 136 | echo | 
|---|
| 137 | '</select></label></p>'. | 
|---|
| 138 | '<p><input type="submit" value="'.__('Save').'" /></p>'. | 
|---|
| 139 | $core->formNonce(). | 
|---|
| 140 | '</fieldset>'. | 
|---|
| 141 | '</form>'; | 
|---|
| 142 |  | 
|---|
| 143 | if (!$rs->isEmpty()) | 
|---|
| 144 | { | 
|---|
| 145 |      $deletable = array(); | 
|---|
| 146 |      $l = $rs->level; | 
|---|
| 147 |      $full_name = array($rs->cat_title); | 
|---|
| 148 |      while ($rs->fetch()) | 
|---|
| 149 |      { | 
|---|
| 150 |           if ($rs->level < $l) { | 
|---|
| 151 |                $full_name = array(); | 
|---|
| 152 |           } elseif ($rs->level == $l) { | 
|---|
| 153 |                array_pop($full_name); | 
|---|
| 154 |           } | 
|---|
| 155 |           $full_name[] = html::escapeHTML($rs->cat_title); | 
|---|
| 156 |           if ($rs->nb_post == 0) { | 
|---|
| 157 |                $deletable[implode(' / ',$full_name)] = $rs->cat_id; | 
|---|
| 158 |           } | 
|---|
| 159 |           $l = $rs->level; | 
|---|
| 160 |      } | 
|---|
| 161 |       | 
|---|
| 162 |      if (count($deletable) > 0) | 
|---|
| 163 |      { | 
|---|
| 164 |           echo | 
|---|
| 165 |           '<form action="categories.php" method="post" id="delete-category">'. | 
|---|
| 166 |           '<fieldset><legend>'.__('Remove a category').'</legend>'. | 
|---|
| 167 |           '<p><label for="del_cat">'.__('Choose a category to remove:').' '. | 
|---|
| 168 |           form::combo('del_cat',$deletable).'</label></p> '. | 
|---|
| 169 |           '<p><input type="submit" value="'.__('ok').'" /></p>'. | 
|---|
| 170 |           $core->formNonce(). | 
|---|
| 171 |           '</fieldset>'. | 
|---|
| 172 |           '</form>'; | 
|---|
| 173 |      } | 
|---|
| 174 |       | 
|---|
| 175 |      echo | 
|---|
| 176 |      '<form action="categories.php" method="post" id="reset-order">'. | 
|---|
| 177 |      '<fieldset><legend>'.__('Reorder categories').'</legend>'. | 
|---|
| 178 |      '<p>'.__('This will relocate all categories on the top level').'</p> '. | 
|---|
| 179 |      '<p><input type="submit" value="'.__('Reorder').'" /></p>'. | 
|---|
| 180 |      form::hidden(array('reset'),1). | 
|---|
| 181 |      $core->formNonce(). | 
|---|
| 182 |      '</fieldset>'. | 
|---|
| 183 |      '</form>'; | 
|---|
| 184 | } | 
|---|
| 185 | echo '</div>'; | 
|---|
| 186 | echo '</div>'; | 
|---|
| 187 |  | 
|---|
| 188 | dcPage::helpBlock('core_categories'); | 
|---|
| 189 | dcPage::close(); | 
|---|
| 190 | ?> | 
|---|