multiple category problem

What do you think about the script.

multiple category problem

Postby Ramon » Tue Dec 16, 2008 4:31 pm

Automatically CNR gets all subcategories when showing news. Since a long time it is known that there are some problems, some have reported it was due to the use of a comma. Well today I had some problems with it myself and figured to sort it out once and for all.

What I did is change the way categories are included, no longer will they be comma seperated. From now on they will be seperated with a "|", which in this case seems to make the world a better place.

If you want to show the subcategories of the categories selected use $getchildren = true; in your include code e.g.

Code: Select all
$static['template'] = 'music';
$static['category'] = '34|42|43';
$getchildren = true;

include 'path/to/show_news.php';


As this has only been tested by me I think it's wise to first let guru FI-DD look at it. show_news.php

Code: Select all
<?php
include_once 'head.php';

foreach($_GET as $k => $v){
   $$k = (!$v ? $$k : @htmlspecialchars($v));
}

if (is_array($_CUTE)){
   foreach($_CUTE as $k => $v){
       $$k = (!$static ? (!$v ? $$k : @htmlspecialchars($v)) : '');
   }
}

foreach($_POST as $k => $v){
   $$k = (!$v ? $$k : @htmlspecialchars($v));
}

if (is_array($static)){
   foreach($vars as $k => $v){
      if ($v != 'static' and $v != 'id' and $v != 'ucat'){
          unset($$v);
       }
   }

   foreach($static as $k => $v){
       $$k = $v;
   }
}

if (!$sort[0] or !eregi('(A|DE)SC', $sort[1])){
   $sort = array('date', 'DESC');
}

if (eregi('([0-9]{2}):([0-9]{2}):([0-9]{2})', $time)){
   $m_n = array('jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12);
    $time = explode(':', $time);
    $time = mktime($time[0], $time[1], $time[2], (eregi('[a-z]', $month) ? $m_n[$month] : $month), $day, $year);
}

if (eregi('[a-z]', $category)){
   $category = category_get_id($category);
}

if ($category and !eregi('|', $category)){
   $template = ((!eregi('(rss|print).php', $_SERVER['PHP_SELF']) and !$static and $cat_template[$category]) ? $cat_template[$category] : $template);
}

if ($category){
   foreach (explode('|', $category) as $cat){
      if($getchildren == false){
          $category_tmp[] = $cat;
      }
      else {
         foreach(explode(',', category_get_children($cat)) as $subcat){
            $category_tmp[] = $subcat;
         }
      }
   }
}

if (!$number){
   $number = $sql->table_count('news');
}

if (!$template or strtolower($template) == 'default' or is_file($template)){
   include $cutepath.'/data/tpl/Default.tpl';
} else {
   include $cutepath.'/data/tpl/'.$template.'.tpl';
}

$cache_uniq = cache_touch_this();

$allow_categories   = $category_tmp;
$allow_edit_comment = false;
$allow_add_comment  = false;
$allow_comment_form = false;
$allow_full_story   = false;
$allow_active_news  = false;
$allow_comments     = false;

if (!$static and ($id or $title or $time)){
   if ($_POST['action'] == 'addcomment'){
      $allow_add_comment = true;
   } else {
      $allow_full_story   = true;
      $allow_comments     = true;
      $allow_comment_form = true;
   }
} else {
   $allow_active_news = true;
}

include $cutepath.'/inc/show.inc.php';

$PHP_SELF = $_SERVER['PHP_SELF'];

if (!cache and !global_cache){
   cache_remover();
}

if ($unset_vars = run_filters('unset', $unset_vars)){
   foreach ($unset_vars as $unset){
      unset($$unset);
   }
}

unset(
   $template,
   $category,
    $static,
   $number,
   $year,
   $month,
   $day,
   $user,
   $author,
   $skip,
   $sort,
   $cache_uniq,
   $user_query,

   $category_tmp,
   $parent,
   $catid,
   $cat,
   $no_prev,
   $no_next,
   $i,
   $prev,
   $count_tmp,
   $unset_vars
);
?>

<!-- Content management by CNR // WWW.CUTENEWRU.COM // FORUMS.CUTENEWSRU.COM -->
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

Postby Torstein » Wed Dec 17, 2008 1:02 pm

Nice! :D

I hope this proves to work for all of us!
Torstein
 
Posts: 292
Joined: Thu Aug 03, 2006 11:19 pm

Postby FI-DD » Thu Dec 18, 2008 5:59 pm

I wonder why changing it from "," to "|" should solve it? Do you have a scenario to show up the difference?
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby Ramon » Thu Dec 18, 2008 6:39 pm

Nope not anymore. I dunno why, i just remembered a post on here somewhere from someone who found out that somehow when you have loads of different categories selecting multiple ones can go wrong, and that it had something to do with the comma seperation.

The main difference in this one is however that it does'nt select all child categories by default. That's a feature i wanted to have for a long time and really comes in handy for me :)
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

Postby azn_romeo_4u » Fri Jan 30, 2009 7:01 am

Warning: eregi() [function.eregi]: REG_EMPTY in show_news.php on line 48


I get that error when I try to copy and paste into show_news.php I just noticed, the bug as well today.

I got 105 categories so far. I went to check on category 2, it had items from category 102. Checked on category 105, it had items on category 5. But the funny thing with 5 is when I add a "05" instead of "5" it doesn't add the item from 105. Yet when I try to do "02" it says no articles.

Also I notice that this happens, on categories that have the same numbers in them. For example, 1, 11, , 121, etc etc. But it doesn't happen all the time. Even though I set it to only get from category 5, it's getting from category 105.

Anyone have any idea?
azn_romeo_4u
 
Posts: 123
Joined: Thu Sep 18, 2008 5:06 am

Postby azn_romeo_4u » Fri Jan 30, 2009 7:58 am

Okay messed around with it a little bit.

Categories 102-109 all show up in other categories that have 2-9. for example, 102 will show up in 2. 103 will show up in 3, etc etc until 109, in 9.
azn_romeo_4u
 
Posts: 123
Joined: Thu Sep 18, 2008 5:06 am

Postby nolikewise » Fri Jan 30, 2009 11:09 am

Ramon this change is perfect, it really speeds up... very big difference... thx a lot... keep on moving
nolikewise
 
Posts: 177
Joined: Mon Dec 17, 2007 8:47 am
Location: Turkiye

Postby Ramon » Sat Jan 31, 2009 5:03 pm

It was merely for testing purposes. It fixed the problem for me, if you want to try it out for yourself thats ok. But I can't guarantee that it works..

This is how my show_news.php looks like now.. I think i've done some changes after posting the above..

Code: Select all
<?php
include_once 'head.php';

foreach($_GET as $k => $v){
   $$k = (!$v ? $$k : @htmlspecialchars($v));
}

if (is_array($_CUTE)){
   foreach($_CUTE as $k => $v){
       $$k = (!$static ? (!$v ? $$k : @htmlspecialchars($v)) : '');
   }
}

foreach($_POST as $k => $v){
   $$k = (!$v ? $$k : @htmlspecialchars($v));
}

if (is_array($static)){
   foreach($vars as $k => $v){
      if ($v != 'static' and $v != 'id' and $v != 'ucat'){
          unset($$v);
       }
   }

   foreach($static as $k => $v){
       $$k = $v;
   }
}

if (!$sort[0] or !eregi('(A|DE)SC', $sort[1])){
   $sort = array('date', 'DESC');
}

if (eregi('([0-9]{2}):([0-9]{2}):([0-9]{2})', $time)){
   $m_n = array('jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6, 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12);
    $time = explode(':', $time);
    $time = mktime($time[0], $time[1], $time[2], (eregi('[a-z]', $month) ? $m_n[$month] : $month), $day, $year);
}

if (eregi('[a-z]', $category)){
   $category = category_get_id($category);
}

if ($category and @!eregi('|', $category)){
   $template = ((!eregi('(rss|print).php', $_SERVER['PHP_SELF']) and !$static and $cat_template[$category]) ? $cat_template[$category] : $template);
}

if ($category){
   foreach (explode('|', $category) as $cat){
      if($getchildren == false){
          $category_tmp[] = $cat;
      }
      else {
         foreach(explode(',', category_get_children($cat)) as $subcat){
            $category_tmp[] = $subcat;
         }
      }
   }
}

if (!$number){
   $number = $sql->table_count('news');
}

if (!$template or strtolower($template) == 'default' or is_file($template)){
   include $cutepath.'/data/tpl/Default.tpl';
} else {
   include $cutepath.'/data/tpl/'.$template.'.tpl';
}

$cache_uniq = cache_touch_this();

$allow_categories   = $category_tmp;
$allow_edit_comment = false;
$allow_add_comment  = false;
$allow_comment_form = false;
$allow_full_story   = false;
$allow_active_news  = false;
$allow_comments     = false;

if (!$static and ($id or $title or $time)){
   if ($_POST['action'] == 'addcomment'){
      $allow_add_comment = true;
   } else {
      $allow_full_story   = true;
      $allow_comments     = true;
      $allow_comment_form = true;
   }
} else {
   $allow_active_news = true;
}

include $cutepath.'/inc/show.inc.php';

$PHP_SELF = $_SERVER['PHP_SELF'];

if (!cache and !global_cache){
   cache_remover();
}

if ($unset_vars = run_filters('unset', $unset_vars)){
   foreach ($unset_vars as $unset){
      unset($$unset);
   }
}

unset(
   $template,
   $category,
    $static,
   $number,
   $year,
   $month,
   $day,
   $user,
   $author,
   $skip,
   $sort,
   $cache_uniq,
   $user_query,

   $category_tmp,
   $parent,
   $catid,
   $cat,
   $no_prev,
   $no_next,
   $i,
   $prev,
   $count_tmp,
   $unset_vars
);
?>

<!-- Copyright CNR // WWW.CUTENEWSRU.COM // For support visit FORUMS.CUTENEWSRU.COM // Please leave this note alive, thank you -->
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

Postby azn_romeo_4u » Mon Feb 02, 2009 10:08 am

I had a coder find the solution for me

1. Open the file inc/show.news.php
2. Find the line 86 which looks like:
$where[] = 'category =~ %'.$single_cat.'%';

3. Replace the line with below line.
$where[] = "category REGEXP ^$single_cat\$|^$single_cat,|,$single_cat,|,$single_cat\$";

works on my website 100% and i have 115 categories and growing.
azn_romeo_4u
 
Posts: 123
Joined: Thu Sep 18, 2008 5:06 am


Return to General feedback



Who is online

Users browsing this forum: No registered users and 0 guests

cron