Recent Topics

1 Feb 12, 2008 19:10    

My b2evolution Version: 2.x


I am in the process of upgrading b2 to 2.x (from .9x). My default page "All Blog" would automatically include all blogs (except for a couple which I specified with a hack).

The new setup requires that you enter the ID of all blogs you want to aggregate in a particular blog... Our blog supports a hundred-odd blogs with more added each week, so this manual entry is not desirable.

Has anyone come up with a hack for 2.x that will automatically aggregate all blogs for a given blog (or preferably, allows you to specify what blog ID *not* to include)?

Any help or tips are appreciated.

3 Feb 15, 2008 20:06

Thanks TITSSN, however this doesn't look like it'll do the job...

I have over 100 blogs and I don't want them to show them in any specific order - only to show the newest posts from all the other blogs (with maybe the ability to *exclude* one or two blogs from the list).

Basically - just like the "old* Blog All page (which *is* my default page - not following why ppl recommend it not be - server overhead?).

I'm still looking at the codebase - but if anyone has already done, or could suggest a way to may this hack possible, that would be appreciated....

5 Feb 15, 2008 21:46

Heehee = yeah saw that post ;) I'm a little perplexed why the feature was removed or there wasn't some kind of "range" or wildcard option offered...

i.e. if I wanted to include all blogs *except* #53, specify something like:
2-52, 54+

One of the main selling points/strengths of b2 for me was this auto-aggregating feature - have to manually specify the blogs severely limits its utility.

If anyone can offer tips on where I should look - it'd be most appreciated - been looking at the ItemList classes, etc... but darn if I can find it...

6 Feb 15, 2008 21:57

I had a go at it yesterday, but I killed my blog after it crashed severely.
The Dashboard input is at /inc/collections/views/_coll_advanced.form.php lines 89-91:

$Form->begin_fieldset( T_('Aggregation').' ['.T_('Admin').']' );
	$Form->text( 'aggregate_coll_IDs', $edited_Blog->get_setting( 'aggregate_coll_IDs' ), 30, T_('Blogs to aggregate'), T_('List blog IDs separated by ,'), 255 );

It then is processed in /inc/collections/model/_blog.class.php lines 534-543:

if( param( 'aggregate_coll_IDs', 'string', NULL ) !== NULL )
{ // Aggregate list:
// fp> TODO: check perms on each aggregated blog (if changed)
// fp> TODO: better interface
	if( !preg_match( '#^([0-9]+(,[0-9]+)*)?$#', get_param( 'aggregate_coll_IDs' ) ) )
		param_error( 'aggregate_coll_IDs', T_('Invalid aggregate blog ID list!') );
	$this->set_setting( 'aggregate_coll_IDs', get_param( 'aggregate_coll_IDs' ) );

Actually I think I was close, but I really screwed it.
You want to put the 'exclusion' in an array and then take the difference from every possible blog and this 'exclusion array'.
This should then be turned into a comma separated string and it replaces 'aggregate_coll_IDs.

Or something like that.

Good luck

7 Feb 15, 2008 22:25

Well, I'm closing on it, methinks - I think the "trigger" seems to be in: /inc/items/model/_itemqueryclass.php

There are *two* where_chapter functions (starting around line 142 - in the latest b2, and the following function "where_chapter2" which seems to be a duplicate). In each there is the check for the aggregate ID's field in the blog:

if( empty( $aggregate_coll_IDs ) )

the "else" portion of this check is:

$this->WHERE_and( 'cat_blog_ID IN ('.$aggregate_coll_IDs.')' );

Just for testing, I changed mine to:

$this->WHERE_and( 'cat_blog_ID > 1' );

(as my all blogs is #1, so this should pull in all other ones) and set the "aggregate" blog ID in blog #1 to 999999, just so *something* is there and the validation on the form won't accept anything else....

Seems to work as expected, at least comparing it to the database, items__item table with the rows sorted by post_datecreated.

It would need to be refined so that the "aggregate blogs" field in the advanced blog setting tabs could accept other parameters besides a comma-separated list of positive numbers, and so forth. (though for my purposes, simply including all blogs except for #53 would satisfy me)....

8 Feb 15, 2008 22:39

Hi nate_02631,

You should be at the point where the variable is created. In /inc/items/model/_itemqueryclass.php line 156:

$aggregate_coll_IDs = $current_Blog->get_setting('aggregate_coll_IDs');

And that setting comes from the snippets I mentioned in my previous post.

Good luck

9 Feb 15, 2008 22:49

Yes, however your previous post was only dealing with the entry of the data - ideally that would need to be changed so it would accept other parameters (like wildcards, etc...) which could then be parsed right around the $aggregate_coll_IDs lines in the item model.

Obviously, *nothin* ain't happening with _coll_advanced.form.php by itself - all the action's in the item query model, though it's pretty easy to see with the snippet you posted above where to get around the comma-separated positive number validation... (though I sux at regex's) :)

I'm not sure what the best syntax might be for having more flexible specifying of blogs - wildcard (*), range (15-20), or exclusionary (-4, -9) - will have to think on that... It could then be parsed to use gt/lt operators, or "NOT IN" vs. "IN" and so forth in the DB query...

I'm guessing these types of "hacks" can't be accomplished with a plugin(?)

EDIT: P.S. only the "second" where_chapter function seems to make a difference - not sure why that is...

10 Feb 15, 2008 23:22

Forget the regex, it's checking for numbers and comma's.
This cannot be done in a plugin, there isn't a hook.

From the AM public bloglist I generated code to get every available blog:

global $Blog;
[php$BlogCache = & get_Cache( 'BlogCache' );
$avail_blogs = $BlogCache->load_public();

Then I took a string inputted in a newly created field in the Backoffice and turned it into an array:

$excluded_blog_IDs_array = explode( $excluded_blog_IDs_string );


$excluded_blog_IDs_array = array_diff( $avail_blogs, $excluded_blog_IDs_array );

This array can replace $aggregate_coll_IDs (is that a string or an array?)

But somewhere I ^()%ed up with strings and arrays ending up calling the DB for $Blog( (Array) ) with an unrecoverable error and I deleted the blog.

The code for generating a field in backoffice was someting like:

$Form->begin_fieldset( T_('Aggregation').' ['.T_('Admin').']' );
    $Form->text( 'aggregate_coll_IDs', $edited_Blog->get_setting( 'aggregate_coll_IDs' ), 30, T_('Blogs to aggregate'), T_('List blog IDs separated by ,'), 255 );
    $Form->text( '$excluded_blog_IDs_string', $edited_Blog->get_setting( '$excluded_blog_IDs_string' ), 30, T_('Blogs to exclude'), T_('List blog IDs to exclude ,'), 255 );

Good luck

11 Feb 16, 2008 13:58

Afwas wrote:

Forget the regex, it's checking for numbers and comma's. This cannot be done in a plugin, there isn't a hook.

Actually, I was referring to the whole thing in general - not just the regex...

Afwas wrote:

Good luck

Not sure why you keep wishing me "good luck" - is that your post signature or something? ;)

At any rate, I've seem to have found where the action is happening w.r.t. blog aggregation. I don't think I'd follow your methodology of with the "excluded blogs", etc... but rather allow the user to enter either a wildcard "all" with additional negative blog IDs to exclude (as Edb suggested) or enter a number list as usual. Then have the itemquery class construct the query based on that info (but yes a little work would need to be done on the validating side).

I might be able to work something up, but for the moment I'm content to do the little itemquery hack as I've done above (and add NOT blog_id = x). Thanks for your feedback!

Form is loading...

Run your own website! – This forum is powered by b2evolution CMS, a complete engine for your website.