1 markfaulkner Nov 30, 2005 05:45
3 markfaulkner Dec 16, 2005 16:56
One application of this methodology would be to have the _bloglist.php respect memberships, e.g. only show those blogs the user was a member of (assumes authentication).
I've noticed that a place that does do this is both the Write and Edit Tabs Blog listings respect membership, possibly this mechanism can be ported to the _bloglist.php skin.
Any ideas?
4 markfaulkner Jan 05, 2006 18:37
http://doc.b2evolution.net/0.9.0/xmlsrv/_blogs_xmlsrv_xmlrpc_php.html#functionbloggergetusersblogs
This seems to return information about blogs a user is a member of possibly this is a step towards a Blog List respecting a users membership in given blogs
5 markfaulkner Jan 22, 2006 20:06
Ok, I found these two bits that when combined I'd imagine create what I'm looking for:
standard blog list code used in most skins:
<?php // --------------------------- BLOG LIST INCLUDED HERE -----------------------------
$display_blog_list = 1; // forced
# this is what will start and end your blog links
$blog_list_start = '<div class="NavBar">';
$blog_list_end = '</div>';
# this is what will separate your blog links
$blog_item_start = '';
$blog_item_end = '';
# This is the class of for the selected blog link:
$blog_selected_link_class = 'NavButton2';
# This is the class of for the other blog links:
$blog_other_link_class = 'NavButton2';
# This is additionnal markup before and after the selected blog name
$blog_selected_name_before = '<span class="small">';
$blog_selected_name_after = '</span>';
# This is additionnal markup before and after the other blog names
$blog_other_name_before = '<span class="small">';
$blog_other_name_after = '</span>';
// Include the bloglist
require( get_path('skins').'/_bloglist.php');
// ---------------------------------- END OF BLOG LIST --------------------------------- ?>
From the Admin area, a list of blogs that the user is a member of:
<?php
/**
* creates a blog list with links to Create a Post
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2004 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package admin
*/
/**
* Includes:
*/
require_once (dirname(__FILE__). '/_header.php');
$admin_tab = 'edit';
$admin_pagetitle = T_('Browse blog:');
param( 'blog', 'integer', 0 );
if( ($blog == 0) && $current_User->check_perm( 'blog_ismember', 1, false, $default_to_blog ) )
{ // Default blog is a valid choice
$blog = $default_to_blog;
}
// ---------------------------------- START OF BLOG LIST ----------------------------------
for( $curr_blog_ID = blog_list_start();
$curr_blog_ID != false;
$curr_blog_ID = blog_list_next() )
{
if( ! $current_User->check_perm( 'blog_ismember', 1, false, $curr_blog_ID ) )
{ // Current user is not a member of this blog...
continue;
}
if( $blog == 0 )
{ // If no selected blog yet, select this one:
$blog = $curr_blog_ID;
}
if( $curr_blog_ID == $blog )
{ // This is the blog being displayed on this page ?>
<a href="<?php echo T_('b2edit.php') ?>?blog=<?php echo $curr_blog_ID ?>" class="CurrentBlog"><?php blog_list_iteminfo('shortname') ?></a>
<?php
}
else
{ // This is another blog ?>
<a href="<?php echo T_('b2edit.php') ?>?blog=<?php echo $curr_blog_ID ?>" class="OtherBlog"><?php blog_list_iteminfo('shortname') ?></a>
<?php
}
} // --------------------------------- END OF BLOG LIST ---------------------------------
if( $blog == 0 )
{ // No blog could be selected
?>
<div class="panelblock">
<?php printf( T_('Since you\'re a newcomer, you\'ll have to wait for an admin to authorize you to post. You can also <a %s>e-mail the admin</a> to ask for a promotion. When you\'re promoted, just reload this page and you\'ll be able to blog. :)'), 'href="mailto:'. $admin_email. '?subject=b2-promotion"' ); ?>
</div>
<?php
}
else
{ // We could select a blog:
$Blog = Blog_get_by_ID( $blog ); /* TMP: */ $blogparams = get_blogparams_by_ID( $blog );
// Check permission:
$current_User->check_perm( 'blog_ismember', 1, true, $blog );
}
?>
So what I'd like to do is take the //Check permission: $current_User->check_perm bit and incorportate that into the standard blog list code such that users when viewing blogs only view those they are a member of.
Any help with this last steup greatly appreciated.
-Mark
6 markfaulkner Jan 23, 2006 06:40
<?php // ---------------------- START permissioned blog listing code ----------------------------
?>
<ul>
<?php
param( 'blog', 'integer', 0 );
if( ($blog == 0) && $current_User->check_perm( 'blog_ismember', 1, false, $default_to_blog ) )
{ // Default blog is a valid choice
$blog = $default_to_blog;
}
// ---------------------------------- START OF BLOG LIST ----------------------------------
for( $curr_blog_ID = blog_list_start();
$curr_blog_ID != false;
$curr_blog_ID = blog_list_next() )
{
if( ! $current_User->check_perm( 'blog_ismember', 1, false, $curr_blog_ID ) )
{ // Current user is not a member of this blog...
continue;
}
if( $blog == 0 )
{ // If no selected blog yet, select this one:
$blog = $curr_blog_ID;
}
if( $curr_blog_ID == $blog )
{ // This is the blog being displayed on this page ?>
<li><a href="<?php echo T_('b2edit.php') ?>?blog=<?php echo $curr_blog_ID ?>" class="CurrentBlog"><?php blog_list_iteminfo('shortname') ?></a>
<br />
<?php
}
else
{ // This is another blog ?>
<li><a href="<?php echo T_('b2edit.php') ?>?blog=<?php echo $curr_blog_ID ?>" class="OtherBlog"><?php blog_list_iteminfo('shortname') ?></a>
<br />
<?php
}
} // --------------------------------- END OF BLOG LIST ---------------------------------
if( $blog == 0 )
{ // No blog could be selected
?>
</ul>
<div class="panelblock">
<?php printf( T_('Since you\'re a newcomer, you\'ll have to wait for an admin to authorize you to post. <br />You can also <a %s>e-mail the admin</a> to request access.'), 'href="mailto:'. $admin_email. '?subject=Blog Access"' ); ?>
</div>
<?php
}
else
{ // We could select a blog:
$Blog = Blog_get_by_ID( $blog ); /* TMP: */ $blogparams = get_blogparams_by_ID( $blog );
// Check permission:
$current_User->check_perm( 'blog_ismember', 1, true, $blog );
}
?>
<?php // ---------------------- END permissioned blog listing code ----------------------------
?>
In case anyone else is interested in this idea the above code will provide a listing of blogs that the user is a member of, this is of course only useful for blog systems that require login to access.
Note: depending on where you're using this listing you'll need to edit this bit
href="<?php echo T_('b2edit.php') ?>?
to take the user to the correct spot when they click the link.
Next onto transforming the recent posts and recent comments to only list posts and comments from Blogs the user is a member of.
Cheers
Mark
7 edb Jan 26, 2006 19:12
Have you tested this as a not-logged-in visitor? Often when showing something to only a member you have to begin with a little test
if( is_logged_in() ) {
members only stuff here
} else {
non-members see this
}
The problem with not using it is that things like $current_User->check_perm() will choke if there is no current_User out there. Dunno if you've gone there or not...
8 markfaulkner Jan 26, 2006 19:49
EdB, Thanks for the attention!
My use case with this approach does include a mandatory login.
An advanced version of this blog listing mechanism that I think would be slick and I'll try to work out when time permits would be for the Blog List logic to be able to work out if there were blogs that had public posts and if so display those blogs if not logged in or even if logged in but not a member of the blog:
Might look like this:
if( is_logged_in() ) {
BLOG LISTING OF BLOGS USER IS A MEMBER OF
&
BLOGS WITH POSTS WHICH ARE PUBLIC
} else {
BLOGS WITH POSTS WHICH ARE PUBLIC
}
What I'm trying to do of course is provide a more elegant manor in which a user experiences the Blog 'system', e.g. if there are no posts to which a user has access to within a given blog then there is no reason for that blog to be included in 'that users' blog list (authenticated or un-authenticated)
9 jolaus Apr 23, 2006 21:59
I have changed the code from my _bloglist.php and now users only see those blogs they're member of. I have modified a little bit the code to change the unordered list and now the links look like in the original bloglist format.
But I have problems with link's urls. I have read what Markfaulkner said about the
href="<?php echo T_('b2edit.php') ?>?
but I don't know how I must edit this. I'm newbie on b2evolution so I'd be very grateful is someone would explain me how can I configure the code to get links matched to their blogs.
I'm using b2evolution. niftyyellow skin and stub files. thank you
10 markfaulkner Apr 23, 2006 22:39
I changed that bit of the link in the bloglist file from:
href="<?php echo T_('b2edit.php') ?>?
to
href="<?php echo T_('index.php') ?>?
If memory serves me it was to correct for some odd behavior, hope that is enough to get you going!
11 jolaus Apr 24, 2006 16:17
Here I am again. First of all thank you Mark for your quick help.
I don't know what I'm doing wrong. I have modified the code you put above this way:
<?php// ---------------------- START permissioned blog listing code ----------------------------
?>
<ul id="bloglist">
<?php
param( 'blog', 'integer', 0 );
if( ($blog == 0) && $current_User->check_perm( 'blog_ismember', 1, false, $default_to_blog ) )
{ // Default blog is a valid choice
$blog = $default_to_blog;
}
// ---------------------------------- START OF BLOG LIST ----------------------------------
for( $curr_blog_ID = blog_list_start();
$curr_blog_ID != false;
$curr_blog_ID = blog_list_next() )
{
if( ! $current_User->check_perm( 'blog_ismember', 1, false, $curr_blog_ID ) )
{ // Current user is not a member of this blog...
continue;
}
if( $blog == 0 )
{ // If no selected blog yet, select this one:
$blog = $curr_blog_ID;
}
if( $curr_blog_ID == $blog )
{ // This is the blog being displayed on this page ?>
<li><a href="<?php echo T_('index.php') ?>?blog=<?php echo $curr_blog_ID ?>" class="BlogButtonCurr"><?php blog_list_iteminfo('shortname') ?></a></li>
<?php
}
else
{ // This is another blog ?>
<li><a href="<?php echo T_('index.php') ?>?blog=<?php echo $curr_blog_ID ?>" class="BlogButton"><?php blog_list_iteminfo('shortname') ?></a></li>
<?php
}
}
// --------------------------------- END OF BLOG LIST ---------------------------------
if( $blog == 0 )
{ // No blog could be selected
?>
</ul>
<div class="panelblock">
<?php printf( T_('Since you\'re a newcomer, you\'ll have to wait for an admin to authorize you to post. <br />You can also <a %s>e-mail the admin</a> to request access.'), 'href="mailto:'. $admin_email. '?subject=Blog Access"' ); ?>
</div>
<?php
}
else
{ // We could select a blog:
$Blog = Blog_get_by_ID( $blog ); /* TMP: */ $blogparams = get_blogparams_by_ID( $blog );
// Check permission:
$current_User->check_perm( 'blog_ismember', 1, true, $blog );
}
?>
<?php // ---------------------- END permissioned blog listing code ----------------------------
?>
Take note that i've changed it to see the links like as original. Up until now everything's ok.
But when I clic on a link it sends me to http://localhost/skins/niftyyellow/index.php?blog=5. :?: :roll: and I get a "404 Page not found error" message.
I'm using stub files so I'm thinking the problem maybe is in the blog ID. Am I right?. If so, can anybody tell me how to modify the code above?
12 markfaulkner Apr 24, 2006 17:42
I suspect you are right that it is the use of stub files that is at issue here. You could test this by setting one of the blogs 'preferred access type' to 'other blog through index.php' and see if it starts working.
If the above proves true then what is needed is to figure out how to 'call' the blogs stub file name in the URL instead of using the index.php approach.
So what I"m saying is that since this is the bit that creates the actual URL for the link:
href="<?php echo T_('index.php') ?>?blog=<?php echo $curr_blog_ID ?>"
What is needed is something like this:
href="<?php echo $curr_blog_stub ?>"
In the interest of full disclosure I'm a bit out of my comfort zone here and I'm sheerly speculating. I took a look at the source code of the blog edit skin and it appears the this bit 'URL blog name / Stub name:' where you define the blog stub name is termed 'blog_stub' combining this with the way the 'curr_blog_ID' is called in the orginal code I'm surmizing that possibly 'curr_blog_stub' will get the blogs stub name.
If that does not work you may possibly find more information about how to 'get' certain variables here: http://doc.b2evolution.net/v-0-9/elementindex.html#s where I see that the only reference to stub is $stub -> $stub
in file _class_blog.php, variable Blog::$stub but I'm not sure how to implement that for the use case here or even if this is the proper use of this.
Hopefully those things will provide some ideas.
13 jolaus Apr 25, 2006 00:18
Well, i have created a new blog with ID number 21 and in "preferred access type" I've checked "Explicit reference to the index.php", so the blog url looks like http://localhost/index.php?blog=21 but this way it doesn't work either. The link takes me to http://localhost/skins/niftyyellow/index.php?blog=21.
I've noticed that even if I'm using stub files the links point always to the right blog ID, but the file path is always the same: http://localhost/skins/niftyyellow....... I wonder why :-/
Finally I have probed with "$curr_blog_stub" variable. In this case all links goes to http://localhost./skins/niftyyellow/.
Why all these links point always to skins/niftyyellow/ directory?
14 markfaulkner Apr 25, 2006 01:10
Jolaus, I suspect the problem you are having may be in the setup of your B2Evo files on your web server. It appears to me that your links are not obtaining the proper 'Base URL' for your B2Evo implementation, e.g. I'm thinking that somewhere in the files setup of B2Evo there is a spot where you have to designate the base URL for the implementation and currently it much be the http://localhost/... thing, or something like that.
NOTE: we are moving further and further from my experience level.
Question: does a standard out of the box blog listing work or do you get malformed links as well?
15 yabba Apr 25, 2006 12:29
<li><a href="<?php echo $baseurl; ?>index.php?blog=<?php echo $curr_blog_ID ?>" class="BlogButtonCurr"><?php blog_list_iteminfo('shortname') ?></a></li>
<?php
}
else
{ // This is another blog ?>
<li><a href="<?php echo $baseurl; ?>index.php?blog=<?php echo $curr_blog_ID ?>" class="BlogButton"><?php blog_list_iteminfo('shortname') ?></a></li>
¥
*edit*
Are you using this in your skins for your blog or are you using it for the admin area?
16 jolaus Apr 25, 2006 15:16
Bingo! Links now are working perfect!! :D
I'm using this code on _bloglist.php file from my skin, niftyyellow. This way I want to show only permitted blogs to each user on the top of the blog skin. Each teacher can only post on a few number of blogs(from two to five, more or less) so with this hack I think switching among different blogs is more comfortable, instead of having to look for a blog from a bloglist with more than 50 links.
Finally, I have checked that there's still another little bug, nothing very important, anyway.
If one user logs out directly from the "Misc" zone, I get this error:
Fatal error: Call to a member function check_perm() on a non-object in http://localhost/skins/niftyyellow/_bloglist.php on line 32
I think there is two ways to solve it: first one is to modify the code above (I don't know how) ant the second one is to hide/delete the logging out option from the frontside of the blog. Maybe this last options is more simply than the first one. How can I do this?
Eskerrik asko
17 yabba Apr 25, 2006 15:28
ok, if you're using this in a blogskin, then you need to change the file to look something like this :-
<ul id="bloglist">
<?php
// ---------------------------------- START OF BLOG LIST ----------------------------------
for( $curr_blog_ID = blog_list_start();
$curr_blog_ID != false;
$curr_blog_ID = blog_list_next() )
{
if( !isset($current_User) or ! $current_User->check_perm( 'blog_ismember', 1, false, $curr_blog_ID ) )
{ // Current user is not a member of this blog...
continue;
}
if( $curr_blog_ID == $blog )
{ // This is the blog being displayed on this page ?>
<li><a href="<?php echo $baseurl; ?>index.php?blog=<?php echo $curr_blog_ID ?>" class="BlogButtonCurr"><?php blog_list_iteminfo('shortname') ?></a></li>
<?php
}
else
{ // This is another blog ?>
<li><a href="<?php echo $baseurl; ?>index.php?blog=<?php echo $curr_blog_ID ?>" class="BlogButton"><?php blog_list_iteminfo('shortname') ?></a></li>
<?php
}
}
// --------------------------------- END OF BLOG LIST ---------------------------------
?>
</ul>
If the user is logged in then they will see all the blogs that they are a member off, if they are logged out then they shouldn't see any blogs at all (and your error should evaporate).
¥
18 jolaus Apr 25, 2006 19:26
Woooowww! It works!!!!!! :D
Thank you very much, both ¥åßßå and markfaulkner. It's great to meet people like you in this forum.
Mila esker (another way to say Thank you in Basque ;) )
19 yabba Apr 26, 2006 08:40
No problem ;)
¥
I located, in a number of places, this check "bloguser_ismember"
and I've located this code from _blogs_permissions.form.php
which is where the permissions tab of a blog seems to check for membership (amoung other things) and use this to populate the permissions table of a blog for users. (might not be of any assistance here)
So the question is how do I, using bloguser_ismember, test for membership in a particular blog.
Use Case: Amoung other things I'd like for the blog listing, when a Blog is designed to be private, to only show those blogs you have membership in. I'd be using a if_login type of check to only display the blog list when logged in so this is the next step, e.g. once logged in you only see those blogs you are a member of in your blog listing.
Hopfully we are getting there.