Recent Topics

1 Jan 28, 2006 00:34    

I've managed to work out a blog listing that checks for a users blog memberships and only lists those blogs the user is a member of.
See this item topic:
http://forums.b2evolution.net/viewtopic.php?t=6265

What I'm now struggling with is adding this bit to the code below so that the Recent Posts Listing only shows posts from Blogs the user is a member of.

$current_User->check_perm( 'blog_ismember', 1, false, $curr_blog_ID ) ) 


Documentation on this method:
http://doc.b2evolution.net/0.9.0/evocore/User.html#methodcheck_perm

Recent Posts Lising:
(this code displays all recent posts)

<div class="bSideItem"> 
   <h3><?php echo T_('Recent Posts') ?></h3> 
   <ul> 
   <?php   // Get the 10 last posts for each blog: 
   $BlogBList = & new ItemList( $blog,  '', '', '', '', '', array(), '', 'DESC', '', 10, '', '', '', '', '', '', '', 'posts' ); 
   while( $Item = $BlogBList->get_item() ) { ?> 
      <li lang="<?php $Item->lang() ?>"> 
      <a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>"><?php $Item->title( '', '', false ); ?></a> 
      </li> 
      <?php } ?> 
   <li><a href="<?php blog_list_iteminfo('blogurl', 'raw' ) ?>"><?php echo T_('More posts...') ?></a></li> 
   </ul> 
   </div>

2 Jan 28, 2006 00:40

Ok, off the top of my head, it wants to look something like this ..... if you get a fatal error or stuff then I'm afraid you'll have to wait until I wake up :P

while( $Item = $BlogBList->get_item() ) {
if (isset($current_User) and $current_User->check_perm( 'blog_ismember', 1, false, $Item->blog_ID ) )
{

....
}
}

¥

3 Jan 28, 2006 01:32

Worked like a charm for the recent posts listing.

I attempted to work that same philosophy into the Recent Comments Listing but couldn't get it to work:
Recent Comment Listing:

<div class="bSideItem">
<h3><?php echo T_('Recent Comments (from published & protected posts)') ?> </h3>
<?php

   $CommentList = & new CommentList( $blog, "'comment'", array('protected' , 'published'),'','','DESC','',10 );
   $CommentList->display_if_empty( '<div class="bComment"><p>'.T_('No comment yet...').'</p></div>' );

   while( $Comment = $CommentList->get_next() )

   {   // Loop through comments:
      ?>
<?php $Comment->author('','') ?> on  <a href="<?php $Comment->permalink(); ?>" title="permalink to comment"><?php $Comment->Item->title(); ?></a>

<br />
<?php
   }
?>        
</div>

4 Jan 28, 2006 10:56

lol, glad it worked ;)

<div class="bSideItem">
<h3><?php echo T_('Recent Comments (from published & protected posts)') ?> </h3>
<?php

$CommentList = & new CommentList( $blog, "'comment'", array('protected' , 'published'),'','','DESC','',10 );
$CommentList->display_if_empty( '<div class="bComment"><p>'.T_('No comment yet...').'</p></div>' );

while( $Comment = $CommentList->get_next() )

{ // Loop through comments:
if (isset($current_User) and $current_User->check_perm( 'blog_ismember', 1, false, $Comment->blog_ID ) )
{

?>
<?php $Comment->author('','') ?> on <a href="<?php $Comment->permalink(); ?>" title="permalink to comment"><?php $Comment->Item->title(); ?></a>

<br />
<?php
}
}
?>
</div>

¥

5 Jan 28, 2006 16:56

That produced this MySQL error:

MySQL error!

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND bloguser_user_ID = 3' at line 4(Errno=1064)

Your query:
SELECT * FROM evo_blogusers WHERE bloguser_blog_ID = AND bloguser_user_ID = 3

6 Jan 28, 2006 18:32

Lol, ahh well, you can but try :p

Try changing it to $Comment->Item->blog_ID

¥

7 Jan 28, 2006 19:52

BRILLIANT!

Thanks for the help on that!

8 Jan 28, 2006 20:01

So others interested in this idea don't have to piece together the final code from the above posts I thought I summerise the code here:

Recent Posts code that respects a Users Blog Membership, only listing posts from Blogs the user is a member of:
(the array settings for this code are to show published and protected posts)

<div class="bSideItem"> 
   <h3><?php echo T_('Recent Posts (published & protected)') ?></h3> 
   <ul> 
   <?php   // Get the 10 last posts for each blog: 
   $BlogBList = & new ItemList( $blog,  array('protected' , 'published'), '', '', '', '', array(), '', 'DESC', '', 10, '', '', '', '', '', '', '', 'posts' ); 
   while( $Item = $BlogBList->get_item() ) 
  if (isset($current_User) and $current_User->check_perm( 'blog_ismember', 1, false, $Item->blog_ID ) ) 
{ 
?> 
      <li lang="<?php $Item->lang() ?>"> 
      <a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>"><?php $Item->title( '', '', false ); ?></a> 
      </li> 
      <?php } ?> 
   <li><a href="<?php blog_list_iteminfo('blogurl', 'raw' ) ?>"><?php echo T_('More posts...') ?></a></li> 
   </ul> 
   </div> 

NOTE: for this code to work users must be a member of the Blog All blog or the 'More posts...' link will error. This link could either be removed or the code could furhter be designed to check for membership in the Blog All blog or not show this link

Recent Comments code that respects a Users Blog Membership, only listing comments from Blogs the user is a member of:
(the array settings for this code are to show comments from published and protected posts)

<div class="bSideItem"> 
<h3><?php echo T_('Recent Comments (from published & protected posts)') ?> </h3> 
<?php 

$CommentList = & new CommentList( $blog, "'comment'", array('protected' , 'published'),'','','DESC','',10 ); 
$CommentList->display_if_empty( '<div class="bComment"><p>'.T_('No comment yet...').'</p></div>' ); 

while( $Comment = $CommentList->get_next() ) 

{ // Loop through comments: 
if (isset($current_User) and $current_User->check_perm( 'blog_ismember', 1, false, $Comment->Item->blog_ID ) ) 
{ 
?> 
<?php $Comment->author('','') ?> on <a href="<?php $Comment->permalink(); ?>" title="permalink to comment"><?php $Comment->Item->title(); ?></a> 

<br /> 
<?php 
} 
} 
?> 
</div>

Heaps of thanks to the Forum for assistance on this endeavour!

10 Jan 29, 2006 11:03

Thanks, markfaulkner and ¥åßßå.

I've added it to the todo list as it is what you would expect..


Form is loading...