Changeset 851:0993f64c4809
- Timestamp:
- 07/31/12 13:52:11 (13 years ago)
- Branch:
- sexy
- Files:
-
- 3 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/index.php
r848 r851 294 294 if ($core->auth->check('usage,contentadmin',$core->blog->id)) 295 295 { 296 $categories_combo = array(' ' => '');297 try {298 $categories = $core->blog->getCategories(array('post_type'=>'post'));299 while ($categories->fetch()) {300 $categories_combo[] = new formSelectOption(301 str_repeat(' ',$categories->level-1).302 ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title),303 $categories->cat_id304 );305 }306 } catch (Exception $e) { }307 308 296 echo 309 297 '<div id="quick">'. … … 318 306 form::textarea('post_content',50,7). 319 307 '</p>'. 320 '<p><label for="cat_id" class="classic">'.__('Category:').' '.321 form::combo('cat_id',$categories_combo).'</label></p>'.322 308 '<p><input type="submit" value="'.__('Save').'" name="save" /> '. 323 309 ($core->auth->check('publish',$core->blog->id) -
admin/post.php
r848 r851 16 16 17 17 $post_id = ''; 18 $cat_id = '';19 18 $post_dt = ''; 20 19 $post_format = $core->auth->getOption('post_format'); … … 48 47 } 49 48 50 # Getting categories51 $categories_combo = array(' ' => '');52 try {53 $categories = $core->blog->getCategories(array('post_type'=>'post'));54 while ($categories->fetch()) {55 $categories_combo[] = new formSelectOption(56 str_repeat(' ',$categories->level-1).($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title),57 $categories->cat_id58 );59 }60 } catch (Exception $e) { }61 62 49 # Status combo 63 50 foreach ($core->blog->getAllPostStatus() as $k => $v) { … … 101 88 { 102 89 $post_id = $post->post_id; 103 $cat_id = $post->cat_id;104 90 $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 105 91 $post_format = $post->post_format; … … 153 139 $post_title = $_POST['post_title']; 154 140 155 $cat_id = (integer) $_POST['cat_id'];156 157 141 if (isset($_POST['post_status'])) { 158 142 $post_status = (integer) $_POST['post_status']; … … 188 172 189 173 $cur->post_title = $post_title; 190 $cur->cat_id = ($cat_id ? $cat_id : null);191 174 $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; 192 175 $cur->post_format = $post_format; … … 389 372 390 373 echo 391 '<p><label for="cat_id">'.__('Category:').392 form::combo('cat_id',$categories_combo,$cat_id,'maximal').393 '</label></p>'.394 395 374 '<p><label for="post_status">'.__('Entry status:'). 396 375 form::combo('post_status',$status_combo,$post_status,'','',!$can_publish). -
admin/posts.php
r796 r851 15 15 dcPage::check('usage,contentadmin'); 16 16 17 # Getting categories18 try {19 $categories = $core->blog->getCategories(array('post_type'=>'post'));20 } catch (Exception $e) {21 $core->error->add($e->getMessage());22 }23 24 17 # Getting authors 25 18 try { … … 47 40 { 48 41 # Filter form we'll put in html_block 49 $users_combo = $categories_combo =array();50 $users_combo['-'] = $categories_combo['-'] ='';42 $users_combo = array(); 43 $users_combo['-'] = ''; 51 44 while ($users->fetch()) 52 45 { … … 61 54 } 62 55 63 $categories_combo[__('None')] = 'NULL';64 while ($categories->fetch()) {65 $categories_combo[str_repeat(' ',$categories->level-1).($categories->level-1 == 0 ? '' : '• ').66 html::escapeHTML($categories->cat_title).67 ' ('.$categories->nb_post.')'] = $categories->cat_id;68 }69 70 56 $status_combo = array( 71 57 '-' => '' … … 95 81 __('Date') => 'post_dt', 96 82 __('Title') => 'post_title', 97 __('Category') => 'cat_title',98 83 __('Author') => 'user_id', 99 84 __('Status') => 'post_status', … … 122 107 __('Mark as unselected') => 'unselected' 123 108 ); 124 $combo_action[__('Change')] = array( __('Change category') => 'category');109 $combo_action[__('Change')] = array(); 125 110 if ($core->auth->check('admin',$core->blog->id)) 126 111 { … … 139 124 -------------------------------------------------------- */ 140 125 $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : ''; 141 $cat_id = !empty($_GET['cat_id']) ? $_GET['cat_id'] : '';142 126 $status = isset($_GET['status']) ? $_GET['status'] : ''; 143 127 $selected = isset($_GET['selected']) ? $_GET['selected'] : ''; … … 168 152 } else { 169 153 $user_id=''; 170 }171 172 # - Categories filter173 if ($cat_id !== '' && in_array($cat_id,$categories_combo)) {174 $params['cat_id'] = $cat_id;175 $show_filters = true;176 } else {177 $cat_id='';178 154 } 179 155 … … 263 239 '<label for="user_id">'.__('Author:'). 264 240 form::combo('user_id',$users_combo,$user_id).'</label> '. 265 '<label for="cat_id">'.__('Category:').266 form::combo('cat_id',$categories_combo,$cat_id).'</label> '.267 241 '<label for="status">'.__('Status:'). 268 242 form::combo('status',$status_combo,$status).'</label> '. … … 305 279 '<input type="submit" value="'.__('ok').'" /></p>'. 306 280 form::hidden(array('user_id'),$user_id). 307 form::hidden(array('cat_id'),$cat_id).308 281 form::hidden(array('status'),$status). 309 282 form::hidden(array('selected'),$selected). -
admin/posts_actions.php
r500 r851 32 32 $redir = 33 33 'posts.php?user_id='.$_POST['user_id']. 34 '&cat_id='.$_POST['cat_id'].35 34 '&status='.$_POST['status']. 36 35 '&selected='.$_POST['selected']. … … 117 116 118 117 } 119 elseif ($action == 'category' && isset($_POST['new_cat_id']))120 {121 try122 {123 while ($posts->fetch())124 {125 $new_cat_id = (integer) $_POST['new_cat_id'];126 $core->blog->updPostCategory($posts->post_id,$new_cat_id);127 }128 http::redirect($redir);129 }130 catch (Exception $e)131 {132 $core->error->add($e->getMessage());133 }134 }135 118 elseif ($action == 'author' && isset($_POST['new_auth_id']) 136 119 && $core->auth->check('admin',$core->blog->id)) … … 187 170 $hidden_fields .= 188 171 form::hidden(array('user_id'),$_POST['user_id']). 189 form::hidden(array('cat_id'),$_POST['cat_id']).190 172 form::hidden(array('status'),$_POST['status']). 191 173 form::hidden(array('selected'),$_POST['selected']). … … 205 187 $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); 206 188 207 if ($action == 'category') 208 { 209 echo '<h2 class="page-title">'.__('Change category for entries').'</h2>'; 210 211 # categories list 212 # Getting categories 213 $categories_combo = array(' ' => ''); 214 try { 215 $categories = $core->blog->getCategories(array('post_type'=>'post')); 216 while ($categories->fetch()) { 217 $categories_combo[] = new formSelectOption( 218 str_repeat(' ',$categories->level-1). 219 ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), 220 $categories->cat_id 221 ); 222 } 223 } catch (Exception $e) { } 224 225 echo 226 '<form action="posts_actions.php" method="post">'. 227 '<p><label for="new_cat_id" class="classic">'.__('Category:').' '. 228 form::combo('new_cat_id',$categories_combo,''). 229 '</label> '; 230 231 echo 232 $hidden_fields. 233 $core->formNonce(). 234 form::hidden(array('action'),'category'). 235 '<input type="submit" value="'.__('Save').'" /></p>'. 236 '</form>'; 237 } 238 elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 189 if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 239 190 { 240 191 echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; -
admin/search.php
r848 r851 81 81 $combo_action[__('mark as pending')] = 'pending'; 82 82 } 83 $combo_action[__('change category')] = 'category';84 if ($core->auth->check('admin',$core->blog->id)) {85 $combo_action[__('change author')] = 'author';86 }87 83 if ($core->auth->check('delete,contentadmin',$core->blog->id)) 88 84 { -
inc/admin/lib.dc.page.php
r848 r851 414 414 self::jsVar('dotclear.msg.confirm_delete_user', 415 415 __('Are you sure you want to delete selected users (%s)?')). 416 self::jsVar('dotclear.msg.confirm_delete_category',417 __('Are you sure you want to delete category "%s"?')).418 self::jsVar('dotclear.msg.confirm_reorder_categories',419 __('Are you sure you want to reorder all categories?')).420 416 self::jsVar('dotclear.msg.confirm_delete_media', 421 417 __('Are you sure you want to remove media "%s"?')). -
inc/admin/lib.pager.php
r848 r851 47 47 '<th colspan="2">'.__('Title').'</th>'. 48 48 '<th>'.__('Date').'</th>'. 49 '<th>'.__('Category').'</th>'.50 49 '<th>'.__('Author').'</th>'. 51 50 '<th>'.__('Status').'</th>'. … … 75 74 private function postLine() 76 75 { 77 if ($this->core->auth->check('categories',$this->core->blog->id)) {78 $cat_link = '<a href="category.php?id=%s">%s</a>';79 } else {80 $cat_link = '%2$s';81 }82 83 if ($this->rs->cat_title) {84 $cat_title = sprintf($cat_link,$this->rs->cat_id,85 html::escapeHTML($this->rs->cat_title));86 } else {87 $cat_title = __('None');88 }89 90 76 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 91 77 switch ($this->rs->post_status) { … … 130 116 html::escapeHTML($this->rs->post_title).'</a></td>'. 131 117 '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'. 132 '<td class="nowrap">'.$cat_title.'</td>'.133 118 '<td class="nowrap">'.$this->rs->user_id.'</td>'. 134 119 '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. -
inc/admin/prepend.php
r848 r851 238 238 'images/menu/search.png','images/menu/search-b.png', 239 239 'usage,contentadmin',null,null)); 240 $_fav['categories'] = new ArrayObject(array('categories','Categories','categories.php',241 'images/menu/categories.png','images/menu/categories-b.png',242 'categories',null,null));243 240 $_fav['media'] = new ArrayObject(array('media','Media manager','media.php', 244 241 'images/menu/media.png','images/menu/media-b.png', … … 302 299 preg_match('/media(_item)?.php(\?.*)?$/',$_SERVER['REQUEST_URI']), 303 300 $core->auth->check('media,media_admin',$core->blog->id)); 304 $_menu['Blog']->prependItem(__('Categories'),'categories.php','images/menu/categories.png',305 preg_match('/categories.php(\?.*)?$/',$_SERVER['REQUEST_URI']),306 $core->auth->check('categories',$core->blog->id));307 301 $_menu['Blog']->prependItem(__('Search'),'search.php','images/menu/search.png', 308 302 preg_match('/search.php(\?.*)?$/',$_SERVER['REQUEST_URI']), -
inc/core/class.dc.auth.php
r527 r851 76 76 'delete' => __('delete entries and comments'), 77 77 'contentadmin' => __('manage all entries and comments'), 78 'categories' => __('manage categories'),79 78 'media' => __('manage their own media items'), 80 79 'media_admin' => __('manage all media items') -
inc/core/class.dc.blog.php
r848 r851 56 56 private $post_status = array(); 57 57 58 private $categories;59 60 58 /** @var boolean Disallow entries password protection */ 61 59 public $without_password = true; … … 169 167 $this->core->callBehavior('coreBlogAfterTriggerBlog',$cur); 170 168 } 171 172 /// @name Categories management methods173 //@{174 public function categories()175 {176 if (!($this->categories instanceof dcCategories)) {177 $this->categories = new dcCategories($this->core);178 }179 180 return $this->categories;181 }182 183 /**184 Retrieves categories. <var>$params</var> is an associative array which can185 take the following parameters:186 187 - post_type: Get only entries with given type (default "post")188 - cat_url: filter on cat_url field189 - cat_id: filter on cat_id field190 - start: start with a given category191 - level: categories level to retrieve192 193 @param params <b>array</b> Parameters194 @return <b>record</b>195 */196 public function getCategories($params=array())197 {198 $c_params = array();199 if (isset($params['post_type'])) {200 $c_params['post_type'] = $params['post_type'];201 unset($params['post_type']);202 }203 $counter = $this->getCategoriesCounter($c_params);204 205 $without_empty = $this->core->auth->userID() == false; # For public display206 207 $start = isset($params['start']) ? (integer) $params['start'] : 0;208 $l = isset($params['level']) ? (integer) $params['level'] : 0;209 210 $rs = $this->categories()->getChildren($start,null,'desc');211 212 # Get each categories total posts count213 $data = array();214 $stack = array();215 $level = 0;216 $cols = $rs->columns();217 while ($rs->fetch())218 {219 $nb_post = isset($counter[$rs->cat_id]) ? (integer) $counter[$rs->cat_id] : 0;220 221 if ($rs->level > $level) {222 $nb_total = $nb_post;223 $stack[$rs->level] = (integer) $nb_post;224 } elseif ($rs->level == $level) {225 $nb_total = $nb_post;226 $stack[$rs->level] += $nb_post;227 } else {228 $nb_total = $stack[$rs->level+1] + $nb_post;229 if (isset($stack[$rs->level])) {230 $stack[$rs->level] += $nb_total;231 } else {232 $stack[$rs->level] = $nb_total;233 }234 unset($stack[$rs->level+1]);235 }236 237 if ($nb_total == 0 && $without_empty) {238 continue;239 }240 241 $level = $rs->level;242 243 $t = array();244 foreach ($cols as $c) {245 $t[$c] = $rs->f($c);246 }247 $t['nb_post'] = $nb_post;248 $t['nb_total'] = $nb_total;249 250 if ($l == 0 || ($l > 0 && $l == $rs->level)) {251 array_unshift($data,$t);252 }253 }254 255 # We need to apply filter after counting256 if (isset($params['cat_id']) && $params['cat_id'] !== '')257 {258 $found = false;259 foreach ($data as $v) {260 if ($v['cat_id'] == $params['cat_id']) {261 $found = true;262 $data = array($v);263 break;264 }265 }266 if (!$found) {267 $data = array();268 }269 }270 271 if (isset($params['cat_url']) && ($params['cat_url'] !== '')272 && !isset($params['cat_id']))273 {274 $found = false;275 foreach ($data as $v) {276 if ($v['cat_url'] == $params['cat_url']) {277 $found = true;278 $data = array($v);279 break;280 }281 }282 if (!$found) {283 $data = array();284 }285 }286 287 return staticRecord::newFromArray($data);288 }289 290 /**291 Retrieves a category by its ID.292 293 @param id <b>integer</b> Category ID294 @return <b>record</b>295 */296 public function getCategory($id)297 {298 return $this->getCategories(array('cat_id' => $id));299 }300 301 /**302 Retrieves parents of a given category.303 304 @param id <b>integer</b> Category ID305 @return <b>record</b>306 */307 public function getCategoryParents($id)308 {309 return $this->categories()->getParents($id);310 }311 312 /**313 Retrieves first parent of a given category.314 315 @param id <b>integer</b> Category ID316 @return <b>record</b>317 */318 public function getCategoryParent($id)319 {320 return $this->categories()->getParent($id);321 }322 323 /**324 Retrieves all category's first children325 326 @param id <b>integer</b> Category ID327 @return <b>record</b>328 */329 public function getCategoryFirstChildren($id)330 {331 return $this->getCategories(array('start' => $id,'level' => $id == 0 ? 1 : 2));332 }333 334 private function getCategoriesCounter($params=array())335 {336 $strReq =337 'SELECT C.cat_id, COUNT(P.post_id) AS nb_post '.338 'FROM '.$this->prefix.'category AS C '.339 'JOIN '.$this->prefix."post P ON (C.cat_id = P.cat_id AND P.blog_id = '".$this->con->escape($this->id)."' ) ".340 "WHERE C.blog_id = '".$this->con->escape($this->id)."' ";341 342 if (!$this->core->auth->userID()) {343 $strReq .= 'AND P.post_status = 1 ';344 }345 346 if (!empty($params['post_type'])) {347 $strReq .= 'AND P.post_type '.$this->con->in($params['post_type']);348 }349 350 $strReq .= 'GROUP BY C.cat_id ';351 352 $rs = $this->con->select($strReq);353 $counters = array();354 while ($rs->fetch()) {355 $counters[$rs->cat_id] = $rs->nb_post;356 }357 358 return $counters;359 }360 361 /**362 Creates a new category. Takes a cursor as input and returns the new category363 ID.364 365 @param cur <b>cursor</b> Category cursor366 @return <b>integer</b> New category ID367 */368 public function addCategory($cur,$parent=0)369 {370 if (!$this->core->auth->check('categories',$this->id)) {371 throw new Exception(__('You are not allowed to add categories'));372 }373 374 $url = array();375 if ($parent != 0)376 {377 $rs = $this->getCategory($parent);378 if ($rs->isEmpty()) {379 $url = array();380 } else {381 $url[] = $rs->cat_url;382 }383 }384 385 if ($cur->cat_url == '') {386 $url[] = text::tidyURL($cur->cat_title,false);387 } else {388 $url[] = $cur->cat_url;389 }390 391 $cur->cat_url = implode('/',$url);392 393 $this->getCategoryCursor($cur);394 $cur->blog_id = (string) $this->id;395 396 # --BEHAVIOR-- coreBeforeCategoryCreate397 $this->core->callBehavior('coreBeforeCategoryCreate',$this,$cur);398 399 $this->categories()->addNode($cur,$parent);400 401 # --BEHAVIOR-- coreAfterCategoryCreate402 $this->core->callBehavior('coreAfterCategoryCreate',$this,$cur);403 $this->triggerBlog();404 405 return $cur->cat_id;406 }407 408 /**409 Updates an existing category.410 411 @param id <b>integer</b> Category ID412 @param cur <b>cursor</b> Category cursor413 */414 public function updCategory($id,$cur)415 {416 if (!$this->core->auth->check('categories',$this->id)) {417 throw new Exception(__('You are not allowed to update categories'));418 }419 420 if ($cur->cat_url == '')421 {422 $url = array();423 $rs = $this->categories()->getParents($id);424 while ($rs->fetch()) {425 if ($rs->index() == $rs->count()-1) {426 $url[] = $rs->cat_url;427 }428 }429 430 431 $url[] = text::tidyURL($cur->cat_title,false);432 $cur->cat_url = implode('/',$url);433 }434 435 $this->getCategoryCursor($cur,$id);436 437 # --BEHAVIOR-- coreBeforeCategoryUpdate438 $this->core->callBehavior('coreBeforeCategoryUpdate',$this,$cur);439 440 $cur->update(441 'WHERE cat_id = '.(integer) $id.' '.442 "AND blog_id = '".$this->con->escape($this->id)."' ");443 444 # --BEHAVIOR-- coreAfterCategoryUpdate445 $this->core->callBehavior('coreAfterCategoryUpdate',$this,$cur);446 447 $this->triggerBlog();448 }449 450 /**451 DEPRECATED METHOD. Use dcBlog::setCategoryParent and dcBlog::moveCategory452 instead.453 454 @param id <b>integer</b> Category ID455 @param order <b>integer</b> Category position456 */457 public function updCategoryOrder($id,$order)458 {459 return;460 }461 462 /**463 Set a category parent464 465 @param id <b>integer</b> Category ID466 @param parent <b>integer</b> Parent Category ID467 */468 public function setCategoryParent($id,$parent)469 {470 $this->categories()->setNodeParent($id,$parent);471 $this->triggerBlog();472 }473 474 /**475 Set category position476 477 @param id <b>integer</b> Category ID478 @param sibling <b>integer</b> Sibling Category ID479 @param move <b>integer</b> Order (before|after)480 */481 public function setCategoryPosition($id,$sibling,$move)482 {483 $this->categories()->setNodePosition($id,$sibling,$move);484 $this->triggerBlog();485 }486 487 /**488 Deletes a category.489 490 @param id <b>integer</b> Category ID491 */492 public function delCategory($id)493 {494 if (!$this->core->auth->check('categories',$this->id)) {495 throw new Exception(__('You are not allowed to delete categories'));496 }497 498 $strReq = 'SELECT COUNT(post_id) AS nb_post '.499 'FROM '.$this->prefix.'post '.500 'WHERE cat_id = '.(integer) $id.' '.501 "AND blog_id = '".$this->con->escape($this->id)."' ";502 503 $rs = $this->con->select($strReq);504 505 if ($rs->nb_post > 0) {506 throw new Exception(__('This category is not empty.'));507 }508 509 $this->categories()->deleteNode($id,true);510 $this->triggerBlog();511 }512 513 /**514 Reset categories order and relocate them to first level515 */516 public function resetCategoriesOrder()517 {518 if (!$this->core->auth->check('categories',$this->id)) {519 throw new Exception(__('You are not allowed to reset categories order'));520 }521 522 $this->categories()->resetOrder();523 $this->triggerBlog();524 }525 526 private function checkCategory($title,$url,$id=null)527 {528 $strReq = 'SELECT cat_id '.529 'FROM '.$this->prefix.'category '.530 "WHERE cat_url = '".$this->con->escape($url)."' ".531 "AND blog_id = '".$this->con->escape($this->id)."' ";532 533 if ($id !== null) {534 $strReq .= 'AND cat_id <> '.(integer) $id.' ';535 }536 537 $rs = $this->con->select($strReq);538 539 if (!$rs->isEmpty()) {540 throw new Exception(__('Category URL must be unique.'));541 }542 }543 544 private function getCategoryCursor($cur,$id=null)545 {546 if ($cur->cat_title == '') {547 throw new Exception(__('You must provide a category title'));548 }549 550 # If we don't have any cat_url, let's do one551 if ($cur->cat_url == '') {552 $cur->cat_url = text::tidyURL($cur->cat_title,false);553 }554 555 # Still empty ?556 if ($cur->cat_url == '') {557 throw new Exception(__('You must provide a category URL'));558 } else {559 $cur->cat_url = text::tidyURL($cur->cat_url,true);560 }561 562 # Check if title or url are unique563 $this->checkCategory($cur->cat_title,$cur->cat_url,$id);564 565 if ($cur->cat_desc !== null) {566 $cur->cat_desc = $this->core->HTMLfilter($cur->cat_desc);567 }568 }569 //@}570 169 571 170 /// @name Entries management methods … … 580 179 - post_url: Get entry with given post_url field 581 180 - user_id: (integer) Get entries belonging to given user ID 582 - cat_id: (string or array) Get entries belonging to given category ID583 - cat_id_not: deprecated (use cat_id with "id ?not" instead)584 - cat_url: (string or array) Get entries belonging to given category URL585 - cat_url_not: deprecated (use cat_url with "url ?not" instead)586 181 - post_status: (integer) Get entries with given post_status 587 182 - post_selected: (boolean) Get select flaged entries … … 598 193 - sql_only : return the sql request instead of results. Only ids are selected 599 194 600 Please note that on every cat_id or cat_url, you can add ?not to exclude601 the category and ?sub to get subcategories.602 603 195 @param params <b>array</b> Parameters 604 196 @param count_only <b>boolean</b> Only counts results … … 634 226 635 227 $strReq = 636 'SELECT P.post_id, P.blog_id, P.user_id, P.cat_id,post_dt, '.228 'SELECT P.post_id, P.blog_id, P.user_id, post_dt, '. 637 229 'post_tz, post_creadt, post_upddt, post_format, post_password, '. 638 230 'post_url, post_lang, post_title, '.$content_req. 639 231 'post_type, post_meta, post_status, post_selected, post_position, '. 640 232 'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. 641 'U.user_url, '. 642 'C.cat_title, C.cat_url, C.cat_desc '; 233 'U.user_url '; 643 234 } 644 235 645 236 $strReq .= 646 237 'FROM '.$this->prefix.'post P '. 647 'INNER JOIN '.$this->prefix.'user U ON U.user_id = P.user_id '. 648 'LEFT OUTER JOIN '.$this->prefix.'category C ON P.cat_id = C.cat_id '; 238 'INNER JOIN '.$this->prefix.'user U ON U.user_id = P.user_id '; 649 239 650 240 if (!empty($params['from'])) { … … 697 287 if (!empty($params['user_id'])) { 698 288 $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 699 }700 701 if (isset($params['cat_id']) && $params['cat_id'] !== '')702 {703 if (!is_array($params['cat_id'])) {704 $params['cat_id'] = array($params['cat_id']);705 }706 if (!empty($params['cat_id_not'])) {707 array_walk($params['cat_id'],create_function('&$v,$k','$v=$v." ?not";'));708 }709 $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_id'],'cat_id').' ';710 }711 elseif (isset($params['cat_url']) && $params['cat_url'] !== '')712 {713 if (!is_array($params['cat_url'])) {714 $params['cat_url'] = array($params['cat_url']);715 }716 if (!empty($params['cat_url_not'])) {717 array_walk($params['cat_url'],create_function('&$v,$k','$v=$v." ?not";'));718 }719 $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_url'],'cat_url').' ';720 289 } 721 290 … … 808 377 @param post_id <b>integer</b> Post ID 809 378 @param dir <b>integer</b> Search direction 810 @param restrict_to_category <b>boolean</b> Restrict to post with same category811 379 @param restrict_to_lang <b>boolean</b> Restrict to post with same lang 812 380 @return record 813 381 */ 814 public function getNextPost($post, $dir,$restrict_to_category=false, $restrict_to_lang=false)382 public function getNextPost($post, $dir, $restrict_to_lang=false) 815 383 { 816 384 $dt = $post->post_dt; … … 835 403 ') '; 836 404 837 if ($restrict_to_category) {838 $params['sql'] .= $post->cat_id ? 'AND P.cat_id = '.(integer) $post->cat_id.' ' : 'AND P.cat_id IS NULL ';839 }840 841 405 if ($restrict_to_lang) { 842 406 $params['sql'] .= $post->post_lang ? 'AND P.post_lang = \''. $this->con->escape($post->post_lang) .'\' ': 'AND P.post_lang IS NULL '; … … 918 482 - month: (integer) Get dates for given month 919 483 - day: (integer) Get dates for given day 920 - cat_id: (integer) Category ID filter921 - cat_url: Category URL filter922 484 - post_lang: lang of the posts 923 485 - next: Get date following match … … 946 508 $cat_field = $catReq = $limit = ''; 947 509 948 if (isset($params['cat_id']) && $params['cat_id'] !== '') {949 $catReq = 'AND P.cat_id = '.(integer) $params['cat_id'].' ';950 $cat_field = ', C.cat_url ';951 } elseif (isset($params['cat_url']) && $params['cat_url'] !== '') {952 $catReq = "AND C.cat_url = '".$this->con->escape($params['cat_url'])."' ";953 $cat_field = ', C.cat_url ';954 }955 510 if (!empty($params['post_lang'])) { 956 511 $catReq = 'AND P.post_lang = \''. $params['post_lang'].'\' '; … … 958 513 959 514 $strReq = 'SELECT DISTINCT('.$this->con->dateFormat('post_dt',$dt_f).') AS dt '. 960 $cat_field.961 515 ',COUNT(P.post_id) AS nb_post '. 962 'FROM '.$this->prefix.'post P LEFT JOIN '.$this->prefix.'category C '. 963 'ON P.cat_id = C.cat_id '. 516 'FROM '.$this->prefix.'post P '. 964 517 "WHERE P.blog_id = '".$this->con->escape($this->id)."' ". 965 518 $catReq; … … 1017 570 } 1018 571 1019 $strReq .= 'GROUP BY dt '.$cat_field;1020 1021 572 $order = 'desc'; 1022 573 if (!empty($params['order']) && preg_match('/^(desc|asc)$/i',$params['order'])) { … … 1196 747 public function updPostSelected($id,$selected) 1197 748 { 1198 if (!$this->core->auth->check('usage,contentadmin',$this->id)) {1199 throw new Exception(__('You are not allowed to change this entry category'));1200 }1201 1202 749 $id = (integer) $id; 1203 750 $selected = (boolean) $selected; … … 1222 769 1223 770 $cur->post_selected = (integer) $selected; 1224 $cur->post_upddt = date('Y-m-d H:i:s');1225 1226 $cur->update(1227 'WHERE post_id = '.$id.' '.1228 "AND blog_id = '".$this->con->escape($this->id)."' "1229 );1230 $this->triggerBlog();1231 }1232 1233 /**1234 Updates post category. <var>$cat_id</var> can be null.1235 1236 @param id <b>integer</b> Post ID1237 @param cat_id <b>integer</b> Category ID1238 */1239 public function updPostCategory($id,$cat_id)1240 {1241 if (!$this->core->auth->check('usage,contentadmin',$this->id)) {1242 throw new Exception(__('You are not allowed to change this entry category'));1243 }1244 1245 $id = (integer) $id;1246 $cat_id = (integer) $cat_id;1247 1248 # If user is only usage, we need to check the post's owner1249 if (!$this->core->auth->check('contentadmin',$this->id))1250 {1251 $strReq = 'SELECT post_id '.1252 'FROM '.$this->prefix.'post '.1253 'WHERE post_id = '.$id.' '.1254 "AND blog_id = '".$this->con->escape($this->id)."' ".1255 "AND user_id = '".$this->con->escape($this->core->auth->userID())."' ";1256 1257 $rs = $this->con->select($strReq);1258 1259 if ($rs->isEmpty()) {1260 throw new Exception(__('You are not allowed to change this entry category'));1261 }1262 }1263 1264 $cur = $this->con->openCursor($this->prefix.'post');1265 1266 $cur->cat_id = ($cat_id ? $cat_id : null);1267 771 $cur->post_upddt = date('Y-m-d H:i:s'); 1268 772 … … 1390 894 } 1391 895 1392 private function getPostsCategoryFilter($arr,$field='cat_id')1393 {1394 $field = $field == 'cat_id' ? 'cat_id' : 'cat_url';1395 1396 $sub = array();1397 $not = array();1398 $queries = array();1399 1400 foreach ($arr as $v)1401 {1402 $v = trim($v);1403 $args = preg_split('/\s*[?]\s*/',$v,-1,PREG_SPLIT_NO_EMPTY);1404 $id = array_shift($args);1405 $args = array_flip($args);1406 1407 if (isset($args['not'])) { $not[$id] = 1; }1408 if (isset($args['sub'])) { $sub[$id] = 1; }1409 if ($field == 'cat_id') {1410 if (preg_match('/^null$/i',$id)) {1411 $queries[$id] = 'P.cat_id IS NULL';1412 }1413 else {1414 $queries[$id] = 'P.cat_id = '.(integer) $id;1415 }1416 } else {1417 $queries[$id] = "C.cat_url = '".$this->con->escape($id)."' ";1418 }1419 }1420 1421 if (!empty($sub)) {1422 $rs = $this->con->select(1423 'SELECT cat_id, cat_url, cat_lft, cat_rgt FROM '.$this->prefix.'category '.1424 "WHERE blog_id = '".$this->con->escape($this->id)."' ".1425 'AND '.$field.' '.$this->con->in(array_keys($sub))1426 );1427 1428 while ($rs->fetch()) {1429 $queries[$rs->f($field)] = '(C.cat_lft BETWEEN '.$rs->cat_lft.' AND '.$rs->cat_rgt.')';1430 }1431 }1432 1433 # Create queries1434 $sql = array(1435 0 => array(), # wanted categories1436 1 => array() # excluded categories1437 );1438 1439 foreach ($queries as $id => $q) {1440 $sql[(integer) isset($not[$id])][] = $q;1441 }1442 1443 $sql[0] = implode(' OR ',$sql[0]);1444 $sql[1] = implode(' OR ',$sql[1]);1445 1446 if ($sql[0]) {1447 $sql[0] = '('.$sql[0].')';1448 } else {1449 unset($sql[0]);1450 }1451 1452 if ($sql[1]) {1453 $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))';1454 } else {1455 unset($sql[1]);1456 }1457 1458 return implode(' AND ',$sql);1459 }1460 1461 896 private function getPostCursor($cur,$post_id=null) 1462 897 { -
inc/core/class.dc.rs.extensions.php
r848 r851 130 130 131 131 /** 132 Returns full post category URL.133 134 @param rs Invisible parameter135 @return <b>string</b>136 */137 public static function getCategoryURL($rs)138 {139 return $rs->core->blog->url.$rs->core->url->getURLFor('category',html::sanitizeURL($rs->cat_url));140 }141 142 /**143 132 Returns whether post has an excerpt. 144 133 -
inc/core/class.dc.xmlrpc.php
r848 r851 75 75 'List of most recent posts in the system'); 76 76 77 $this->addCallback('metaWeblog.getCategories',array($this,'mw_getCategories'),78 array('array','string','string','string'),79 'List of all categories defined in the weblog');80 81 77 $this->addCallback('metaWeblog.newMediaObject',array($this,'mw_newMediaObject'), 82 78 array('struct','string','string','string','struct'), … … 88 84 'List of most recent posts in the system'); 89 85 90 $this->addCallback('mt.getCategoryList',array($this,'mt_getCategoryList'),91 array('array','string','string','string'),92 'List of all categories defined in the weblog');93 94 $this->addCallback('mt.getPostCategories',array($this,'mt_getPostCategories'),95 array('array','string','string','string'),96 'List of all categories to which the post is assigned');97 98 $this->addCallback('mt.setPostCategories',array($this,'mt_setPostCategories'),99 array('boolean','string','string','string','array'),100 'Sets the categories for a post');101 102 86 $this->addCallback('mt.publishPost',array($this,'mt_publishPost'), 103 87 array('boolean','string','string','string'), … … 143 127 'Get an array of users for the blog.'); 144 128 145 $this->addCallback('wp.getCategories',array($this,'wp_getCategories'),146 array('array','integer','string','string'),147 'Get an array of available categories on a blog.');148 149 129 $this->addCallback('wp.getTags',array($this,'wp_getTags'), 150 130 array('array','integer','string','string'), 151 131 'Get list of all tags for the blog.'); 152 153 $this->addCallback('wp.newCategory',array($this,'wp_newCategory'),154 array('integer','integer','string','string','struct'),155 'Create a new category.');156 157 $this->addCallback('wp.deleteCategory',array($this,'wp_deleteCategory'),158 array('boolean','integer','string','string','integer'),159 'Delete a category with a given ID.');160 161 $this->addCallback('wp.suggestCategories',array($this,'wp_suggestCategories'),162 array('array','integer','string','string','string','integer'),163 'Get an array of categories that start with a given string.');164 132 165 133 $this->addCallback('wp.uploadFile',array($this,'wp_uploadFile'), … … 288 256 289 257 return $rs; 290 }291 292 private function getCatID($cat_url)293 {294 $rs = $this->core->blog->getCategories(array('cat_url' => $cat_url));295 296 return $rs->isEmpty() ? null : $rs->cat_id;297 258 } 298 259 … … 344 305 } 345 306 346 # Categories in an array347 if (isset($struct['categories']) && is_array($struct['categories']))348 {349 $categories = $struct['categories'];350 $cat_id = !empty($categories[0]) ? $categories[0] : null;351 352 $cur->cat_id = $this->getCatID($cat_id);353 }354 355 307 if (isset($struct['wp_slug'])) { 356 308 $cur->post_url = $struct['wp_slug']; … … 448 400 } 449 401 450 # Categories in an array451 if (isset($struct['categories']) && is_array($struct['categories']))452 {453 $categories = $struct['categories'];454 $cat_id = !empty($categories[0]) ? $categories[0] : null;455 456 $cur->cat_id = $this->getCatID($cat_id);457 }458 459 402 if (isset($struct['wp_slug'])) { 460 403 $cur->post_url = $struct['wp_slug']; … … 504 447 $res['userid'] = $post->user_id; 505 448 $res['postid'] = $post->post_id; 506 507 if ($post->cat_id) {508 $res['categories'] = array($post->cat_url);509 }510 449 511 450 if ($type == 'blogger') { … … 566 505 $tres['userid'] = $posts->user_id; 567 506 $tres['postid'] = $posts->post_id; 568 569 if ($posts->cat_id) {570 $tres['categories'] = array($posts->cat_url);571 }572 507 573 508 if ($type == 'blogger') { … … 621 556 'url' => $this->core->auth->getInfo('user_url') 622 557 ); 623 }624 625 private function getCategories($blog_id,$user,$pwd)626 {627 $this->setUser($user,$pwd);628 $this->setBlog();629 $rs = $this->core->blog->getCategories();630 631 $res = array();632 633 $l = $rs->level;634 $stack = array('',$rs->cat_url);635 636 while ($rs->fetch())637 {638 $d = $rs->level - $l;639 if ($d == 0) {640 array_pop($stack);641 $parent = end($stack);642 } elseif ($d > 0) {643 $parent = end($stack);644 } elseif ($d < 0) {645 $D = abs($d);646 for ($i=0; $i<=$D; $i++) {647 array_pop($stack);648 }649 $parent = end($stack);650 }651 652 $res[] = array(653 'categoryId' => $rs->cat_url,654 'parentId' => $parent,655 'description' => $rs->cat_title,656 'categoryName' => $rs->cat_url,657 'htmlUrl' => $this->core->blog->url.658 $this->core->url->getURLFor('category',$rs->cat_url),659 'rssUrl' => $this->core->blog->url.660 $this->core->url->getURLFor('feed','category/'.$rs->cat_url.'/rss2')661 );662 663 $stack[] = $rs->cat_url;664 $l = $rs->level;665 }666 667 return $res;668 }669 670 private function getPostCategories($post_id,$user,$pwd)671 {672 $post_id = (integer) $post_id;673 674 $post = $this->getPostRS($post_id,$user,$pwd);675 676 return array(677 array(678 'categoryName' => $post->cat_url,679 'categoryId' => (string) $post->cat_url,680 'isPrimary' => true681 )682 );683 }684 685 private function setPostCategories($post_id,$user,$pwd,$categories)686 {687 $post_id = (integer) $post_id;688 689 $post = $this->getPostRS($post_id,$user,$pwd);690 691 $cat_id = (!empty($categories[0]['categoryId'])) ? $categories[0]['categoryId'] : null;692 693 foreach($categories as $v)694 {695 if (isset($v['isPrimary']) && $v['isPrimary']) {696 $cat_id = $v['categoryId'];697 break;698 }699 }700 701 # w.bloggar sends -1 for no category.702 if ($cat_id == -1) {703 $cat_id = null;704 }705 706 if ($cat_id) {707 $cat_id = $this->getCatID($cat_id);708 }709 710 $this->core->blog->updPostCategory($post_id,(integer) $cat_id);711 712 return true;713 558 } 714 559 … … 929 774 "link" => $posts->getURL(), 930 775 "permaLink" => $posts->getURL(), 931 "categories" => array(),932 776 "excerpt" => $posts->post_excerpt_xhtml, 933 777 "text_more" => '', … … 1036 880 } 1037 881 1038 private function newCategory($user,$pwd,$struct)1039 {1040 $this->setUser($user,$pwd);1041 $this->setBlog();1042 1043 if (empty($struct['name'])) {1044 throw new Exception('You mus give a category name.');1045 }1046 1047 $cur = $this->core->con->openCursor($this->core->prefix.'category');1048 $cur->cat_title = $struct['name'];1049 1050 if (!empty($struct['slug'])) {1051 $cur->cat_url = $struct['slug'];1052 }1053 if (!empty($struct['category_description'])) {1054 $cur->cat_desc = $struct['category_description'];1055 if (html::clean($cur->cat_desc) == $cur->cat_desc) {1056 $cur->cat_desc = '<p>'.$cur->cat_desc.'</p>';1057 }1058 }1059 1060 $parent = !empty($struct['category_parent']) ? (integer) $struct['category_parent'] : 0;1061 1062 $id = $this->core->blog->addCategory($cur,$parent);1063 $rs = $this->core->blog->getCategory($id);1064 return $rs->cat_url;1065 }1066 1067 private function deleteCategory($user,$pwd,$cat_id)1068 {1069 $this->setUser($user,$pwd);1070 $this->setBlog();1071 1072 $c = $this->core->blog->getCategories(array('cat_url' => $cat_id));1073 if ($c->isEmpty()) {1074 throw new Exception(__('This category does not exist.'));1075 }1076 $cat_id = $c->cat_id;1077 unset($c);1078 1079 $this->core->blog->delCategory((integer) $cat_id);1080 return true;1081 }1082 1083 private function searchCategories($user,$pwd,$category,$limit)1084 {1085 $this->setUser($user,$pwd);1086 $this->setBlog();1087 1088 $strReq = 'SELECT cat_id, cat_title, cat_url '.1089 'FROM '.$this->core->prefix.'category '.1090 "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".1091 "AND LOWER(cat_title) LIKE LOWER('%".$this->core->con->escape($category)."%') ".1092 ($limit > 0 ? $this->core->con->limit($limit) : '');1093 1094 $rs = $this->core->con->select($strReq);1095 1096 $res = array();1097 while ($rs->fetch())1098 {1099 $res[] = array(1100 'category_id' => $rs->cat_url,1101 'category_name' => $rs->cat_url1102 );1103 }1104 return $res;1105 }1106 1107 882 /* Blogger methods 1108 883 --------------------------------------------------- */ … … 1165 940 } 1166 941 1167 public function mw_getCategories($blogid,$username,$password)1168 {1169 return $this->getCategories($blogid,$username,$password);1170 }1171 1172 942 public function mw_newMediaObject($blogid,$username,$password,$file) 1173 943 { … … 1180 950 { 1181 951 return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'mt'); 1182 }1183 1184 public function mt_getCategoryList($blogid,$username,$password)1185 {1186 return $this->getCategories($blogid,$username,$password);1187 }1188 1189 public function mt_getPostCategories($postid,$username,$password)1190 {1191 return $this->getPostCategories($postid,$username,$password);1192 }1193 1194 public function mt_setPostCategories($postid,$username,$password,$categories)1195 {1196 return $this->setPostCategories($postid,$username,$password,$categories);1197 952 } 1198 953 … … 1266 1021 } 1267 1022 1268 public function wp_getCategories($blogid,$username,$password)1269 {1270 return $this->getCategories($blogid,$username,$password);1271 }1272 1273 1023 public function wp_getTags($blogid,$username,$password) 1274 1024 { 1275 1025 return $this->getTags($username,$password); 1276 }1277 1278 public function wp_newCategory($blogid,$username,$password,$content)1279 {1280 return $this->newCategory($username,$password,$content);1281 }1282 1283 public function wp_deleteCategory($blogid,$username,$password,$categoryid)1284 {1285 return $this->deleteCategory($username,$password,$categoryid);1286 }1287 1288 public function wp_suggestCategories($blogid,$username,$password,$category,$max_results=0)1289 {1290 return $this->searchCategories($username,$password,$category,$max_results);1291 1026 } 1292 1027 -
inc/dbschema/db-schema.php
r848 r851 29 29 30 30 ->primary('pk_blog','blog_id') 31 ;32 33 $_s->category34 ->cat_id ('bigint', 0, false)35 ->blog_id ('varchar', 32, false)36 ->cat_title ('varchar', 255, false)37 ->cat_url ('varchar', 255, false)38 ->cat_desc ('text', 0, true)39 ->cat_position ('integer', 0, true, 0)40 ->cat_lft ('integer', 0, true)41 ->cat_rgt ('integer', 0, true)42 43 ->primary('pk_category','cat_id')44 45 ->unique('uk_cat_url','cat_url','blog_id')46 31 ; 47 32 … … 102 87 ->blog_id ('varchar', 32, false) 103 88 ->user_id ('varchar', 32, false) 104 ->cat_id ('bigint', 0, true)105 89 ->post_dt ('timestamp', 0, false, 'now()') 106 90 ->post_tz ('varchar', 128, false, "'UTC'") … … 192 176 /* References indexes 193 177 -------------------------------------------------------- */ 194 $_s->category->index ('idx_category_blog_id', 'btree', 'blog_id');195 $_s->category->index ('idx_category_cat_lft_blog_id', 'btree', 'blog_id', 'cat_lft');196 $_s->category->index ('idx_category_cat_rgt_blog_id', 'btree', 'blog_id', 'cat_rgt');197 178 $_s->setting->index ('idx_setting_blog_id', 'btree', 'blog_id'); 198 179 $_s->user->index ('idx_user_user_default_blog', 'btree', 'user_default_blog'); 199 180 $_s->permissions->index ('idx_permissions_blog_id', 'btree', 'blog_id'); 200 $_s->post->index ('idx_post_cat_id', 'btree', 'cat_id');201 181 $_s->post->index ('idx_post_user_id', 'btree', 'user_id'); 202 182 $_s->post->index ('idx_post_blog_id', 'btree', 'blog_id'); … … 220 200 /* Foreign keys 221 201 -------------------------------------------------------- */ 222 $_s->category->reference('fk_category_blog','blog_id','blog','blog_id','cascade','cascade');223 202 $_s->setting->reference('fk_setting_blog','blog_id','blog','blog_id','cascade','cascade'); 224 203 $_s->user->reference('fk_user_default_blog','user_default_blog','blog','blog_id','cascade','set null'); 225 204 $_s->permissions->reference('fk_permissions_blog','blog_id','blog','blog_id','cascade','cascade'); 226 205 $_s->permissions->reference('fk_permissions_user','user_id','user','user_id','cascade','cascade'); 227 $_s->post->reference('fk_post_category','cat_id','category','cat_id','cascade','set null');228 206 $_s->post->reference('fk_post_user','user_id','user','user_id','cascade','cascade'); 229 207 $_s->post->reference('fk_post_blog','blog_id','blog','blog_id','cascade','cascade'); -
inc/prepend.php
r848 r851 29 29 $__autoload['dcAuth'] = dirname(__FILE__).'/core/class.dc.auth.php'; 30 30 $__autoload['dcBlog'] = dirname(__FILE__).'/core/class.dc.blog.php'; 31 $__autoload['dcCategories'] = dirname(__FILE__).'/core/class.dc.categories.php';32 31 $__autoload['dcError'] = dirname(__FILE__).'/core/class.dc.error.php'; 33 32 $__autoload['dcMeta'] = dirname(__FILE__).'/core/class.dc.meta.php'; … … 202 201 $core->url->register('post','post','^post/(.+)$',array('dcUrlHandlers','post')); 203 202 $core->url->register('preview','preview','^preview/(.+)$',array('dcUrlHandlers','preview')); 204 $core->url->register('category','category','^category/(.+)$',array('dcUrlHandlers','category'));205 203 $core->url->register('archive','archive','^archive(/.+)?$',array('dcUrlHandlers','archive')); 206 204 -
inc/public/class.dc.template.php
r848 r851 68 68 $this->addValue('BlogMetaRobots',array($this,'BlogMetaRobots')); 69 69 70 # Categories71 $this->addBlock('Categories',array($this,'Categories'));72 $this->addBlock('CategoriesHeader',array($this,'CategoriesHeader'));73 $this->addBlock('CategoriesFooter',array($this,'CategoriesFooter'));74 $this->addBlock('CategoryIf',array($this,'CategoryIf'));75 $this->addBlock('CategoryFirstChildren',array($this,'CategoryFirstChildren'));76 $this->addBlock('CategoryParents',array($this,'CategoryParents'));77 $this->addValue('CategoryFeedURL',array($this,'CategoryFeedURL'));78 $this->addValue('CategoryURL',array($this,'CategoryURL'));79 $this->addValue('CategoryShortURL',array($this,'CategoryShortURL'));80 $this->addValue('CategoryDescription',array($this,'CategoryDescription'));81 $this->addValue('CategoryTitle',array($this,'CategoryTitle'));82 83 70 # Entries 84 71 $this->addBlock('DateFooter',array($this,'DateFooter')); … … 95 82 $this->addValue('EntryAuthorURL',array($this,'EntryAuthorURL')); 96 83 $this->addValue('EntryBasename',array($this,'EntryBasename')); 97 $this->addValue('EntryCategory',array($this,'EntryCategory'));98 $this->addBlock('EntryCategoriesBreadcrumb',array($this,'EntryCategoriesBreadcrumb'));99 $this->addValue('EntryCategoryID',array($this,'EntryCategoryID'));100 $this->addValue('EntryCategoryURL',array($this,'EntryCategoryURL'));101 $this->addValue('EntryCategoryShortURL',array($this,'EntryCategoryShortURL'));102 84 $this->addValue('EntryContent',array($this,'EntryContent')); 103 85 $this->addValue('EntryDate',array($this,'EntryDate')); … … 458 440 <!ATTLIST tpl:Archives 459 441 type (day|month|year) #IMPLIED -- Get days, months or years, default to month -- 460 category CDATA #IMPLIED -- Get dates of given category --461 442 no_context (1|0) #IMPLIED -- Override context information 462 443 order (asc|desc) #IMPLIED -- Sort asc or desc -- … … 473 454 } 474 455 475 if (isset($attr['category'])) {476 $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";477 }478 479 456 if (isset($attr['post_type'])) { 480 457 $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; … … 483 460 if (isset($attr['post_lang'])) { 484 461 $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n"; 485 }486 487 if (empty($attr['no_context']) && !isset($attr['category']))488 {489 $p .=490 'if ($_ctx->exists("categories")) { '.491 "\$params['cat_id'] = \$_ctx->categories->cat_id; ".492 "}\n";493 462 } 494 463 … … 851 820 } 852 821 853 /* Categories ----------------------------------------- */854 855 /*dtd856 <!ELEMENT tpl:Categories - - -- Categories loop -->857 */858 public function Categories($attr,$content)859 {860 $p = "if (!isset(\$params)) \$params = array();\n";861 862 if (isset($attr['url'])) {863 $p .= "\$params['cat_url'] = '".addslashes($attr['url'])."';\n";864 }865 866 if (!empty($attr['post_type'])) {867 $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n";868 }869 870 if (!empty($attr['level'])) {871 $p .= "\$params['level'] = ".(integer) $attr['level'].";\n";872 }873 874 $res = "<?php\n";875 $res .= $p;876 $res .= $this->core->callBehavior("templatePrepareParams",877 array("tag" => "Categories","method" => "blog::getCategories"),878 $attr,$content);879 $res .= '$_ctx->categories = $core->blog->getCategories($params);'."\n";880 $res .= "?>\n";881 $res .= '<?php while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; unset($params); ?>';882 883 return $res;884 }885 886 /*dtd887 <!ELEMENT tpl:CategoriesHeader - - -- First Categories result container -->888 */889 public function CategoriesHeader($attr,$content)890 {891 return892 "<?php if (\$_ctx->categories->isStart()) : ?>".893 $content.894 "<?php endif; ?>";895 }896 897 /*dtd898 <!ELEMENT tpl:CategoriesFooter - - -- Last Categories result container -->899 */900 public function CategoriesFooter($attr,$content)901 {902 return903 "<?php if (\$_ctx->categories->isEnd()) : ?>".904 $content.905 "<?php endif; ?>";906 }907 908 /*dtd909 <!ELEMENT tpl:CategoryIf - - -- tests on current entry -->910 <!ATTLIST tpl:CategoryIf911 url CDATA #IMPLIED -- category has given url912 has_entries (0|1) #IMPLIED -- post is the first post from list (value : 1) or not (value : 0)913 has_description (0|1) #IMPLIED -- category has description (value : 1) or not (value : 0)914 >915 */916 public function CategoryIf($attr,$content)917 {918 $if = new ArrayObject();919 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&';920 921 if (isset($attr['url'])) {922 $url = addslashes(trim($attr['url']));923 if (substr($url,0,1) == '!') {924 $url = substr($url,1);925 $if[] = '($_ctx->categories->cat_url != "'.$url.'")';926 } else {927 $if[] = '($_ctx->categories->cat_url == "'.$url.'")';928 }929 }930 931 if (isset($attr['has_entries'])) {932 $sign = (boolean) $attr['has_entries'] ? '>' : '==';933 $if[] = '$_ctx->categories->nb_post '.$sign.' 0';934 }935 936 if (isset($attr['has_description'])) {937 $sign = (boolean) $attr['has_description'] ? '!=' : '==';938 $if[] = '$_ctx->categories->cat_desc '.$sign.' ""';939 }940 941 $this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if);942 943 if (count($if) != 0) {944 return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>';945 } else {946 return $content;947 }948 }949 950 /*dtd951 <!ELEMENT tpl:CategoryFirstChildren - - -- Current category first children loop -->952 */953 public function CategoryFirstChildren($attr,$content)954 {955 return956 "<?php\n".957 '$_ctx->categories = $core->blog->getCategoryFirstChildren($_ctx->categories->cat_id);'."\n".958 'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';959 }960 961 /*dtd962 <!ELEMENT tpl:CategoryParents - - -- Current category parents loop -->963 */964 public function CategoryParents($attr,$content)965 {966 return967 "<?php\n".968 '$_ctx->categories = $core->blog->getCategoryParents($_ctx->categories->cat_id);'."\n".969 'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';970 }971 972 /*dtd973 <!ELEMENT tpl:CategoryFeedURL - O -- Category feed URL -->974 <!ATTLIST tpl:CategoryFeedURL975 type (rss2|atom) #IMPLIED -- feed type (default : rss2)976 >977 */978 public function CategoryFeedURL($attr)979 {980 $type = !empty($attr['type']) ? $attr['type'] : 'atom';981 982 if (!preg_match('#^(rss2|atom)$#',$type)) {983 $type = 'atom';984 }985 986 $f = $this->getFilters($attr);987 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("feed","category/".'.988 '$_ctx->categories->cat_url."/'.$type.'")').'; ?>';989 }990 991 /*dtd992 <!ELEMENT tpl:CategoryURL - O -- Category URL (complete iabsolute URL, including blog URL) -->993 */994 public function CategoryURL($attr)995 {996 $f = $this->getFilters($attr);997 return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("category",'.998 '$_ctx->categories->cat_url)').'; ?>';999 }1000 1001 /*dtd1002 <!ELEMENT tpl:CategoryShortURL - O -- Category short URL (relative URL, from /category/) -->1003 */1004 public function CategoryShortURL($attr)1005 {1006 $f = $this->getFilters($attr);1007 return '<?php echo '.sprintf($f,'$_ctx->categories->cat_url').'; ?>';1008 }1009 1010 /*dtd1011 <!ELEMENT tpl:CategoryDescription - O -- Category description -->1012 */1013 public function CategoryDescription($attr)1014 {1015 $f = $this->getFilters($attr);1016 return '<?php echo '.sprintf($f,'$_ctx->categories->cat_desc').'; ?>';1017 }1018 1019 /*dtd1020 <!ELEMENT tpl:CategoryTitle - O -- Category title -->1021 */1022 public function CategoryTitle($attr)1023 {1024 $f = $this->getFilters($attr);1025 return '<?php echo '.sprintf($f,'$_ctx->categories->cat_title').'; ?>';1026 }1027 1028 822 /* Entries -------------------------------------------- */ 1029 823 /*dtd … … 1032 826 lastn CDATA #IMPLIED -- limit number of results to specified value 1033 827 author CDATA #IMPLIED -- get entries for a given user id 1034 category CDATA #IMPLIED -- get entries for specific categories only (multiple comma-separated categories can be specified. Use "!" as prefix to exclude a category)1035 no_category CDATA #IMPLIED -- get entries without category1036 828 no_context (1|0) #IMPLIED -- Override context information 1037 829 sortby (title|selected|author|date|id) #IMPLIED -- specify entries sort criteria (default : date) (multiple comma-separated sortby can be specified. Use "?asc" or "?desc" as suffix to provide an order for each sorby) … … 1072 864 } 1073 865 1074 if (isset($attr['category'])) {1075 $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n";1076 $p .= "context::categoryPostParam(\$params);\n";1077 }1078 1079 if (isset($attr['no_category']) && $attr['no_category']) {1080 $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n";1081 $p .= "unset(\$params['cat_url']);\n";1082 }1083 1084 866 if (!empty($attr['type'])) { 1085 867 $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n"; … … 1097 879 'if ($_ctx->exists("users")) { '. 1098 880 "\$params['user_id'] = \$_ctx->users->user_id; ". 1099 "}\n";1100 }1101 1102 if (!isset($attr['category']) && (!isset($attr['no_category']) || !$attr['no_category']))1103 {1104 $p .=1105 'if ($_ctx->exists("categories")) { '.1106 "\$params['cat_id'] = \$_ctx->categories->cat_id; ".1107 881 "}\n"; 1108 882 } … … 1185 959 <!ATTLIST tpl:EntryIf 1186 960 type CDATA #IMPLIED -- post has a given type (default: "post") 1187 category CDATA #IMPLIED -- post has a given category1188 961 first (0|1) #IMPLIED -- post is the first post from list (value : 1) or not (value : 0) 1189 962 odd (0|1) #IMPLIED -- post is in an odd position (value : 1) or not (value : 0) … … 1191 964 extended (0|1) #IMPLIED -- post has an excerpt (value : 1) or not (value : 0) 1192 965 selected (0|1) #IMPLIED -- post is selected (value : 1) or not (value : 0) 1193 has_category (0|1) #IMPLIED -- post has a category (value : 1) or not (value : 0)1194 966 has_attachment (0|1) #IMPLIED -- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code) 1195 967 operator (and|or) #IMPLIED -- combination of conditions, if more than 1 specifiec (default: and) … … 1201 973 $if = new ArrayObject(); 1202 974 $extended = null; 1203 $hascategory = null;1204 975 1205 976 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; … … 1221 992 } 1222 993 1223 if (isset($attr['category'])) {1224 $category = addslashes(trim($attr['category']));1225 if (substr($category,0,1) == '!') {1226 $category = substr($category,1);1227 $if[] = '($_ctx->posts->cat_url != "'.$category.'")';1228 } else {1229 $if[] = '($_ctx->posts->cat_url == "'.$category.'")';1230 }1231 }1232 1233 994 if (isset($attr['first'])) { 1234 995 $sign = (boolean) $attr['first'] ? '=' : '!'; … … 1249 1010 $sign = (boolean) $attr['selected'] ? '' : '!'; 1250 1011 $if[] = $sign.'(boolean)$_ctx->posts->post_selected'; 1251 }1252 1253 if (isset($attr['has_category'])) {1254 $sign = (boolean) $attr['has_category'] ? '' : '!';1255 $if[] = $sign.'$_ctx->posts->cat_id';1256 1012 } 1257 1013 … … 1430 1186 1431 1187 /*dtd 1432 <!ELEMENT tpl:EntryCategory - O -- Entry category (full name) -->1433 */1434 public function EntryCategory($attr)1435 {1436 $f = $this->getFilters($attr);1437 return '<?php echo '.sprintf($f,'$_ctx->posts->cat_title').'; ?>';1438 }1439 1440 /*dtd1441 <!ELEMENT tpl:EntryCategoriesBreadcrumb - - -- Current entry parents loop (without last one) -->1442 */1443 public function EntryCategoriesBreadcrumb($attr,$content)1444 {1445 return1446 "<?php\n".1447 '$_ctx->categories = $core->blog->getCategoryParents($_ctx->posts->cat_id);'."\n".1448 'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>';1449 }1450 1451 /*dtd1452 <!ELEMENT tpl:EntryCategoryID - O -- Entry category ID -->1453 */1454 public function EntryCategoryID($attr)1455 {1456 $f = $this->getFilters($attr);1457 return '<?php echo '.sprintf($f,'$_ctx->posts->cat_id').'; ?>';1458 }1459 1460 /*dtd1461 <!ELEMENT tpl:EntryCategoryURL - O -- Entry category URL -->1462 */1463 public function EntryCategoryURL($attr)1464 {1465 $f = $this->getFilters($attr);1466 return '<?php echo '.sprintf($f,'$_ctx->posts->getCategoryURL()').'; ?>';1467 }1468 1469 /*dtd1470 <!ELEMENT tpl:EntryCategoryShortURL - O -- Entry category short URL (relative URL, from /category/) -->1471 */1472 public function EntryCategoryShortURL($attr)1473 {1474 $f = $this->getFilters($attr);1475 return '<?php echo '.sprintf($f,'$_ctx->posts->cat_url').'; ?>';1476 }1477 1478 1479 /*dtd1480 1188 <!ELEMENT tpl:EntryFeedID - O -- Entry feed ID --> 1481 1189 */ … … 1491 1199 size (sq|t|s|m|o) #IMPLIED -- Image size to extract 1492 1200 class CDATA #IMPLIED -- Class to add on image tag 1493 with_category (1|0) #IMPLIED -- Search in entry category description if present (default 0)1494 1201 > 1495 1202 */ … … 1500 1207 $with_category = !empty($attr['with_category']) ? 'true' : 'false'; 1501 1208 1502 return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."', ".$with_category.",'".addslashes($class)."'); ?>";1209 return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."','".addslashes($class)."'); ?>"; 1503 1210 } 1504 1211 … … 1529 1236 <!ELEMENT tpl:EntryNext - - -- Next entry block --> 1530 1237 <!ATTLIST tpl:EntryNext 1531 restrict_to_category (0|1) #IMPLIED -- find next post in the same category (default: 0)1532 1238 restrict_to_lang (0|1) #IMPLIED -- find next post in the same language (default: 0) 1533 1239 > … … 1877 1583 <!ELEMENT tpl:SysIf - - -- System settings tester container --> 1878 1584 <!ATTLIST tpl:SysIf 1879 categories (0|1) #IMPLIED -- test if categories are set in current context (value : 1) or not (value : 0)1880 1585 posts (0|1) #IMPLIED -- test if posts are set in current context (value : 1) or not (value : 0) 1881 1586 blog_lang CDATA #IMPLIED -- tests if blog language is the one given in parameter … … 1894 1599 1895 1600 $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 1896 1897 if (isset($attr['categories'])) {1898 $sign = (boolean) $attr['categories'] ? '!' : '=';1899 $if[] = '$_ctx->categories '.$sign.'== null';1900 }1901 1601 1902 1602 if (isset($attr['posts'])) { -
inc/public/lib.tpl.context.php
r839 r851 162 162 } 163 163 164 public static function categoryPostParam(&$p)165 {166 $not = substr($p['cat_url'],0,1) == '!';167 if ($not) {168 $p['cat_url'] = substr($p['cat_url'],1);169 }170 171 $p['cat_url'] = preg_split('/\s*,\s*/',$p['cat_url'],-1,PREG_SPLIT_NO_EMPTY);172 173 foreach ($p['cat_url'] as &$v)174 {175 if ($not) {176 $v .= ' ?not';177 }178 if ($GLOBALS['_ctx']->exists('categories') && preg_match('/#self/',$v)) {179 $v = preg_replace('/#self/',$GLOBALS['_ctx']->categories->cat_url,$v);180 } elseif ($GLOBALS['_ctx']->exists('posts') && preg_match('/#self/',$v)) {181 $v = preg_replace('/#self/',$GLOBALS['_ctx']->posts->cat_url,$v);182 }183 }184 }185 186 164 # Static methods for pagination 187 165 public static function PaginationNbPages() … … 341 319 342 320 # First post image helpers 343 public static function EntryFirstImageHelper($size,$ with_category,$class="")321 public static function EntryFirstImageHelper($size,$class="") 344 322 { 345 323 global $core, $_ctx; … … 378 356 } 379 357 380 # No src, look in category description if available381 if (!$src && $with_category && $_ctx->categories)382 {383 if (preg_match_all($pattern,$_ctx->categories->cat_desc,$m) > 0)384 {385 foreach ($m[1] as $i => $img) {386 if (($src = self::ContentFirstImageLookup($p_root,$img,$size)) !== false) {387 $src = $p_url.(dirname($img) != '/' ? dirname($img) : '').'/'.$src;388 if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) {389 $alt = $malt[1];390 }391 break;392 }393 }394 };395 }396 397 358 if ($src) { 398 359 return '<img alt="'.$alt.'" src="'.$src.'" class="'.$class.'" />'; -
inc/public/lib.urlhandlers.php
r848 r851 245 245 $_ctx->cur_lang = $args; 246 246 self::home(null); 247 }248 }249 250 public static function category($args)251 {252 $_ctx =& $GLOBALS['_ctx'];253 $core =& $GLOBALS['core'];254 255 $n = self::getPageNumber($args);256 257 if ($args == '' && !$n) {258 # No category was specified.259 self::p404();260 }261 else262 {263 $params = new ArrayObject(array(264 'cat_url' => $args,265 'post_type' => 'post'));266 267 $core->callBehavior('publicCategoryBeforeGetCategories',$params,$args);268 269 $_ctx->categories = $core->blog->getCategories($params);270 271 if ($_ctx->categories->isEmpty()) {272 # The specified category does no exist.273 self::p404();274 }275 else276 {277 if ($n) {278 $GLOBALS['_page_number'] = $n;279 }280 self::serveDocument('category.html');281 }282 247 } 283 248 } -
locales/en/resources.php
r848 r851 24 24 $__resources['help'] = array( 25 25 'core_blog_pref' => dirname(__FILE__).'/help/blog_pref.html', 26 'core_categories' => dirname(__FILE__).'/help/categories.html',27 26 'core_media' => dirname(__FILE__).'/help/media.html', 28 27 'core_post' => dirname(__FILE__).'/help/post.html', -
plugins/widgets/_default_widgets.php
r665 r851 33 33 $__widgets->langs->setting('homeonly',__('Home page only'),1,'check'); 34 34 35 $__widgets->create('categories',__('Categories list'),array('defaultWidgets','categories'));36 $__widgets->categories->setting('title',__('Title:'),__('Categories'));37 $__widgets->categories->setting('postcount',__('With entries counts'),0,'check');38 39 35 $__widgets->create('subscribe',__('Subscribe links'),array('defaultWidgets','subscribe')); 40 36 $__widgets->subscribe->setting('title',__('Title:'),__('Subscribe')); … … 55 51 $__widgets->create('lastposts',__('Last entries'),array('defaultWidgets','lastposts')); 56 52 $__widgets->lastposts->setting('title',__('Title:'),__('Last entries')); 57 $rs = $core->blog->getCategories(array('post_type'=>'post'));58 $categories = array('' => '', __('Uncategorized') => 'null');59 while ($rs->fetch()) {60 $categories[str_repeat(' ',$rs->level-1).($rs->level-1 == 0 ? '' : '• ').html::escapeHTML($rs->cat_title)] = $rs->cat_id;61 }62 $__widgets->lastposts->setting('category',__('Category:'),'','combo',$categories);63 unset($rs,$categories);64 53 if ($core->plugins->moduleExists('tags')) { 65 54 $__widgets->lastposts->setting('tag',__('Tag:'),''); … … 84 73 $__default_widgets['nav']->append($__widgets->navigation); 85 74 $__default_widgets['nav']->append($__widgets->bestof); 86 $__default_widgets['nav']->append($__widgets->categories);87 75 $__default_widgets['extra']->append($__widgets->subscribe); 88 76 -
plugins/widgets/_widgets_functions.php
r776 r851 58 58 } 59 59 60 public static function categories($w)61 {62 global $core, $_ctx;63 64 $rs = $core->blog->getCategories(array('post_type'=>'post'));65 if ($rs->isEmpty()) {66 return;67 }68 69 $res =70 '<div class="categories">'.71 ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : '');72 73 $ref_level = $level = $rs->level-1;74 while ($rs->fetch())75 {76 $class = '';77 if (($core->url->type == 'category' && $_ctx->categories instanceof record && $_ctx->categories->cat_id == $rs->cat_id)78 || ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->cat_id == $rs->cat_id)) {79 $class = ' class="category-current"';80 }81 82 if ($rs->level > $level) {83 $res .= str_repeat('<ul><li'.$class.'>',$rs->level - $level);84 } elseif ($rs->level < $level) {85 $res .= str_repeat('</li></ul>',-($rs->level - $level));86 }87 88 if ($rs->level <= $level) {89 $res .= '</li><li'.$class.'>';90 }91 92 $res .=93 '<a href="'.$core->blog->url.$core->url->getURLFor('category', $rs->cat_url).'">'.94 html::escapeHTML($rs->cat_title).'</a>'.95 ($w->postcount ? ' <span>('.$rs->nb_post.')</span>' : '');96 97 98 $level = $rs->level;99 }100 101 if ($ref_level - $level < 0) {102 $res .= str_repeat('</li></ul>',-($ref_level - $level));103 }104 $res .= '</div>';105 106 return $res;107 }108 109 60 public static function bestof($w) 110 61 { … … 292 243 $params['no_content'] = true; 293 244 294 if ($w->category)295 {296 if ($w->category == 'null') {297 $params['sql'] = ' AND P.cat_id IS NULL ';298 } elseif (is_numeric($w->category)) {299 $params['cat_id'] = (integer) $w->category;300 } else {301 $params['cat_url'] = $w->category;302 }303 }304 305 245 if ($w->tag) 306 246 {
Note: See TracChangeset
for help on using the changeset viewer.