2 sam2kb Jun 02, 2009 07:35

 
 

thanks... needed this hack

Can I assume this is a general hack for all skins? Since it's in the /inc folder?
Thanks!

hudson2001 wrote:
Can I assume this is a general hack for all skins? Since it's in the /inc folder?
Thanks!
yes it's a universal hack..
btw sam2kb, isn't there a total number of posts in the category in the db that we can simply gather & display ?

tilqicom wrote:
btw sam2kb, isn't there a total number of posts in the category in the db that we can simply gather & display ?
I didn't find it.

sam2kb wrote:
tilqicom wrote:
btw sam2kb, isn't there a total number of posts in the category in the db that we can simply gather & display ?
I didn't find it.
me niether :D

I know I did the first part right, so I must have put the global thing in the wrong place because I am getting this (and variations) on all my blogs:
Parse error: syntax error, unexpected $end in /home/jhudson2/domains/hudson2001.com/public_html/blogs/inc/generic/model/_genericcategorycache.class.php on line 451Where PRECISELY does that global part need to go? I've tried it in a few places and nothing is working.
I hate being stupid about CSS.

Put
global $DB;between the 
function recurse( $callbacks, $subset_ID = NULL, $cat_array = NULL, $level = 0 )
{and
// Make sure children have been revealed for specific subset:
$this->reveal_children( $subset_ID );Line 248
Here's the whole updated function
/**
 * Return recursive display of loaded categories
 *
 * @param array callback funtions (to format the display)
 * @param integer|NULL NULL for all subsets
 * @param array categories list to display
 * @param int depth of  categories list
 *
 * @return string recursive list of all loaded categories
 */
function recurse( $callbacks, $subset_ID = NULL, $cat_array = NULL, $level = 0 )
{
	global $DB;
	
	// Make sure children have been revealed for specific subset:
	$this->reveal_children( $subset_ID );
	if( is_null( $cat_array ) )
	{	// Get all parent categories:
		if( is_null( $subset_ID ) )
		{
			$cat_array = $this->root_cats;
		}
		elseif( isset( $this->subset_root_cats[$subset_ID] ) )
		{	// We have root cats for the requested subset:
			$cat_array = $this->subset_root_cats[$subset_ID];
		}
		else
		{
			$cat_array = array();
		}
	}
	$r = '';
	if( is_array( $callbacks['before_level'] ) )
	{ // object callback:
		$r .= $callbacks['before_level'][0]->{$callbacks['before_level'][1]}( $level ); // <ul>
	}
	else
	{
		$r .= $callbacks['before_level']( $level ); // <ul>
	}
	foreach( $cat_array as $cat )
	{
		if( is_array( $callbacks['line'] ) )
		{ // object callback:
			$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
			
			$SQL = 'SELECT COUNT( postcat_post_ID )
					FROM T_postcats
					INNER JOIN T_items__item ON post_ID = postcat_post_ID
					WHERE postcat_cat_ID = '.$cat->ID.'
					AND post_status = "published" AND post_datestart < NOW()';
			
			if( !is_admin_page() && $post_count = $DB->get_var($SQL) )
			{
				$r .= ' ('.$post_count.')';
			}
		}
		else
		{
			$r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
		}
		if( !empty( $cat->children ) )
		{	// Add children categories:
			$r .= $this->recurse( $callbacks, $subset_ID, $cat->children, $level+1 );
		}
		elseif( is_array( $callbacks['no_children'] ) )
		{ // object callback:
			$r .= $callbacks['no_children'][0]->{$callbacks['no_children'][1]}( $cat, $level ); // </li>
		}
		else
		{
			$r .= $callbacks['no_children']( $cat, $level ); // </li>
		}
	}
	if( is_array( $callbacks['after_level'] ) )
	{ // object callback:
		$r .= $callbacks['after_level'][0]->{$callbacks['after_level'][1]}( $level ); // </ul>
	}
	else
	{
		$r .= $callbacks['after_level']( $level ); // </ul>
	}
	return $r;
}

Ah, it makes sense now.
/smacks head
I was trying to insert the entire thing, not just the global $DB; part.
Now it works like a charm! Wheeeeeeee!
I should say...on most of my blogs. On Pixel Green it's screwed up. Thoughts? More hacks? :)

i have tried this but it is not working for me..
My install version is 2.4.5
i have replaced these lines:
		// Make sure children have been revealed for specific subset:
		$this->reveal_children( $subset_ID );
		if( is_null( $cat_array ) )
		{	// Get all parent categories:
			if( is_null( $subset_ID ) )
			{
				$cat_array = $this->root_cats;
			}
			elseif( isset( $this->subset_root_cats[$subset_ID] ) )
			{	// We have root cats for the requested subset:
				$cat_array = $this->subset_root_cats[$subset_ID];
			}
			else
			{
				$cat_array = array();
			}
		}
		$r = '';
		if( is_array( $callbacks['before_level'] ) )
		{ // object callback:
			$r .= $callbacks['before_level'][0]->{$callbacks['before_level'][1]}( $level ); // <ul>
		}
		else
		{
			$r .= $callbacks['before_level']( $level ); // <ul>
		}
		foreach( $cat_array as $cat )
		{
			if( is_array( $callbacks['line'] ) )
			{ // object callback:
				$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
			}
			else
			{
				$r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
			}
			if( !empty( $cat->children ) )
			{	// Add children categories:
				$r .= $this->recurse( $callbacks, $subset_ID, $cat->children, $level+1 );
			}
			elseif( is_array( $callbacks['no_children'] ) )
			{ // object callback:
				$r .= $callbacks['no_children'][0]->{$callbacks['no_children'][1]}( $cat, $level ); // </li>
			}
			else
			{
				$r .= $callbacks['no_children']( $cat, $level ); // </li>
			}
		}
		if( is_array( $callbacks['after_level'] ) )
		{ // object callback:
			$r .= $callbacks['after_level'][0]->{$callbacks['after_level'][1]}( $level ); // </ul>
		}
		else
		{
			$r .= $callbacks['after_level']( $level ); // </ul>
		}
		return $r;
	}with the following you gave:
/**
* Return recursive display of loaded categories
*
* @param array callback funtions (to format the display)
* @param integer|NULL NULL for all subsets
* @param array categories list to display
* @param int depth of categories list
*
* @return string recursive list of all loaded categories
*/
function recurse( $callbacks, $subset_ID = NULL, $cat_array = NULL, $level = 0 )
{
global $DB;
// Make sure children have been revealed for specific subset:
$this->reveal_children( $subset_ID );if( is_null( $cat_array ) )
{ // Get all parent categories:
if( is_null( $subset_ID ) )
{
$cat_array = $this->root_cats;
}
elseif( isset( $this->subset_root_cats[$subset_ID] ) )
{ // We have root cats for the requested subset:
$cat_array = $this->subset_root_cats[$subset_ID];
}
else
{
$cat_array = array();
}
}$r = '';
if( is_array( $callbacks['before_level'] ) )
{ // object callback:
$r .= $callbacks['before_level'][0]->{$callbacks['before_level'][1]}( $level ); // <ul>
}
else
{
$r .= $callbacks['before_level']( $level ); // <ul>
}foreach( $cat_array as $cat )
{
if( is_array( $callbacks['line'] ) )
{ // object callback:
$r .= $callbacks['line'][0]->{$callbacks['line'][1]}( $cat, $level ); // <li> Category - or - <tr><td>Category</td></tr> ...
$SQL = 'SELECT COUNT( postcat_post_ID )
FROM T_postcats
INNER JOIN T_items__item ON post_ID = postcat_post_ID
WHERE postcat_cat_ID = '.$cat->ID.'
AND post_status = "published" AND post_datestart < NOW()';
if( !is_admin_page() && $post_count = $DB->get_var($SQL) )
{
$r .= ' ('.$post_count.')';
}
}
else
{
$r .= $callbacks['line']( $cat, $level ); // <li> Category - or - <tr><td>Category</td></tr> ...
}if( !empty( $cat->children ) )
{ // Add children categories:
$r .= $this->recurse( $callbacks, $subset_ID, $cat->children, $level+1 );
}
elseif( is_array( $callbacks['no_children'] ) )
{ // object callback:
$r .= $callbacks['no_children'][0]->{$callbacks['no_children'][1]}( $cat, $level ); // </li>
}
else
{
$r .= $callbacks['no_children']( $cat, $level ); // </li>
}}
if( is_array( $callbacks['after_level'] ) )
{ // object callback:
$r .= $callbacks['after_level'][0]->{$callbacks['after_level'][1]}( $level ); // </ul>
}
else
{
$r .= $callbacks['after_level']( $level ); // </ul>
}return $r;
}

Edit this part and see if it changes the output.
Or maybe it doesn't work in 2.4.5 :-/ , let me check...
        }
        else
        {
            $r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
        }
        if( !empty( $cat->children ) )
        {    // Add children categories:        }
        else
        {
            $r .= $callbacks['line']( $cat, $level ); // <li> Category  - or - <tr><td>Category</td></tr> ...
            $r .= ' (blah)';
        }
        if( !empty( $cat->children ) )
        {    // Add children categories: 
For those who do core work, it would be nice if each category had a field for total number of posts. Back in the day cat lists always showed number of posts, but it was taken out for server efficiency - doing the query each time yah? So we can put it back by putting the querying back, but wouldn't it be nice if at create/edit/delete a little counter was updated?
Then maybe don't show cats with no posts and probably have a param that lets one turn off the posts-in-cat counter, but really getting an efficient counter back would be nice.

i have been able to get around this one.thanks.
However i have a specific problem as always...
see screenshot below:
http://i43.tinypic.com/2e5tmp5.jpg
the thing is i have 4 parent categories as you see there:
Kişiler - (People)
Konular - (Topics)
Meslekler- (Professions)
Ülkeler- (Nations)
These categories aren't meant to be selected during entering a new post, they were only covers but i have selected one of those -konular- by mistake and now it appears Konular (1) as you can see..I dont know how i can detect in which post i have selected it, and as this parent cat includes all the other sub cats, there are hundreds of posts under it and it all appears when i click it, is there anyway how i can determine which is that 1 post causing it ?

Install the [url=http://forums.b2evolution.net//viewtopic.php?t=16492]Latest posts[/url] widget and see what's in "konular" category.

no help. |: since it seems i have checked that -konular- as an extra cat but not the main cat..
edit: nevermind, i have sorted it out by going through all the posts one by one.. luckily i had a few hundred posts and found it in the half way, it was quite an arse in the pain though, thanks
Are you ready for another hack? :)
In inc/generic/model/_genericcategorycache.class.php, line 334 edit the following code
to
You must also add global $DB; to the very top of this function