Elgg: Link block title to user's blog

Elgg: Link block title to user's blog

by Mark Penny -
Number of replies: 13
I've gone in and changed "e-portfolio" to "Blog Network" in block/eportfolio/lang/en_utf8/block_eportfolio.php and gone further and made the title a link, as below.

$string['blocktitle'] = '<a href=http://housetohouse.targeteil.org/blognetwork>Blog Network</a>';

What I'd like to do is have the block title link directly to the user's blog and sign in.

Would it be possible to have the title trigger a subroutine (one that I suspect already exists in eportfolio/lms/rss.php)?

What I'd really like to have is something like this

Blog Network/My Blog

in which the first title is linked to the first page after login and the second title is linked to the user's blog.

Even cooler would be to have each title grab the appropriate name from elsewhere, that way, no matter what the installation or who the user, the correct titles would display.

I realize this is not what was intended, but for my installation a blog menu allowing each user to log in to any of the three main pages of the blog is much more likely to be used than the eportfolio option.

Tips, anyone?
Average of ratings: -
In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Penny Leach -
Very brief answer, you should be able to do something like

 
if (empty($USER->eportfolioauthed)) {
$url = $CFG->wwwroot.'/blocks/eportfolio/authredirect.php?sesskey='.sesskey().'&url='.$blogurl;
} else {
$url = $blogurl;
}


the authredirect.php script will take a url, validate sesskey and try and authenticate the user there and then redirect them. Have a look: http://moodle.cvs.sourceforge.net/*checkout*/moodle/contrib/block_elgg/eportfolio/authredirect.php

Authredirect also sets a $USER variable so you don't have to keep going through authredirect to authenticate.

Hope that helps. That's how to do the automatic login between moodle and elgg anyway. Note that this assumes an account on both sides. The block will know whether there is one on the elgg side or not - basically in the get_content method, $rss will be empty if there's no elgg account.

p
In reply to Penny Leach

Re: Elgg: Link block title to user's blog

by Luke Hudson -
Silly me, I didn't see your reply, Penny.

Oh well, how's that for service smile

- Luke
In reply to Luke Hudson

Re: Elgg: Link block title to user's blog

by Mark Penny -
Great service! Thanks very much to both of you.

By the way, Penny, where exactly should I put the code? In lang/block_eportfolio?

Well, I'll give it a try.

Thanks again to both of you.
In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Penny Leach -
you're just wanting to sets the title of the block, right? so I guess you want to edit blocks/blog_eportfolio/block_eportfolio.php ... in get_content

you want to override $this->title if the user has an account in elgg.. so you look for
 
} else {
// print some rss!
and somewhere in that block, put the code from above, wrapped in a <a href and such, as makes sense.
In reply to Penny Leach

Re: Elgg: Link block title to user's blog

by Mark Penny -
Sounds messy. I'll try. Hope I don't hurt anybody.
In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Mark Penny -
Yeah. I'm afraid I'm too in the dark to follow your directions without more detail.

I've inserted the code as shown. Nothing bad is happening, but nothing has changed, either. Obviously, I need to plug in some text somewhere, but I have no idea where--and I have no idea how to work the wrapper you mentioned.

Sorry. I am a certified neophyte.


        if (empty($rss)) {
            // TODO proper error handling here,
            // we need return codes or the raw response or something
            // but I can't see how to get it from magpie.
            // make the join link


//Penny's code
if (empty($USER->eportfolioauthed)) {

   $url = $CFG->wwwroot.'/blocks/eportfolio/authredirect.php?sesskey='.sesskey().'&url='.$blogurl;

} else {

   $url = $blogurl;

}

            $this->content->text = '<form action="'.$CFG->wwwroot.'/blocks/eportfolio/signupredirect.php" method="post">'."\n";
            foreach($postdata as $key => $value) {
                $this->content->text .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />'."\n";
            }
            $this->content->text .= '<input type="submit" value="'.get_string('joinnow','block_eportfolio').'" />'."\n".'</form>'."\n";
        } else {
            // print some rss!
In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Penny Leach -
smile a couple of things:

1. The code needs to go in the else { block, NOT above it.

2. You need to override $this->title. Instead of using my code (which was an example, not the finished version! smile ), use Luke's, he took the time to actually look at what the variables are called, and placed clearer markers as to where it should go wink




In reply to Penny Leach

Re: Elgg: Link block title to user's blog

by Mark Penny -
Like this?

        if (empty($rss)) {
            // TODO proper error handling here,
            // we need return codes or the raw response or something
            // but I can't see how to get it from magpie.
            // make the join link



            $this->content->text = '<form action="'.$CFG->wwwroot.'/blocks/eportfolio/signupredirect.php" method="post">'."\n";
            foreach($postdata as $key => $value) {
                $this->content->text .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />'."\n";
            }
            $this->content->text .= '<input type="submit" value="'.get_string('joinnow','block_eportfolio').'" />'."\n".'</form>'."\n";
        } else {
            // print some rss!



            $this->content->text = $this->get_rss_content($rss);
            $id = $this->instance->pageid;
            if ($this->instance->pagetype == 'my-index') {
                $id = 0;
            }
            global $mods;
            if (!empty($id) && eportfolio_exportable($mods)) {
                $this->content->text .= '<p><a href="'.$CFG->wwwroot.'/blocks/eportfolio/export.php?id='.$id.'" />'.get_string('exportfiles','block_eportfolio').'</a></p>';
            }





/*insert Luke's code here*/
    $blogurl = "$CFG->block_eportfolio_baseurl/_weblog";
    if (empty($USER->eportfolioauthed)) {
        $blogurl = $CFG->wwwroot.'/blocks/eportfolio/authredirect.php?sesskey='.sesskey().'&url='.$blogurl;
    }
    $this->title = '<A href="' . $blogurl . '">' . get_string('blocktitle','block_eportfolio') . '</a>';



Nothing's happening. What I'm hoping for is something like this in the block title bar: Blog Network/My Blog, with Blog Network linked to the first page of the blog network and My Blog linked to the user's blog. I have a link for Blog Network, but it does not authenticate, because it's just an ordinary link. So far, nothing displays for My Blog.

eportfoliomenu200609122057

I'm sure I must be missing  something obvious. More clues, please. And thanks for your time.

In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Mark Penny -
My silly. When I deleted the link and left the title in lang/block_eportfolio.php, I got a title that linked to _weblog. A good first step. However, the new link doesn't authenticate, so I have to log in "manually".

eportfoliomenutitlelink200609122200
Enlarge

What I should see, if the link authenticates, is this.

eportfoliomenutitlelink200609122203
Enlarge

What's missing? A piece of code? Did I do something wrong?

Sorry to keep bothering you. Thanks for the continued help.
In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Mark Penny -
Apologies. Now it's working perfectly.

You know, I had a similar queer experience with getting eportfolio to work in the first place. All kinds of weird glitches the first run or two, then it all suddenly cleared up.

Thanks, both of you.

May I suggest that you make the weblog link part of the package? Call it Weblog or My Weblog or something.

You may not be aware of the discussion we had in the Blog forum about how disappointed many of us were that Moodle blogs do not allow comments. This little link of yours lets Elgg become Moodle's blogging system. I realize that the same basic thing was already achieved by the links in the window, but linking the title and giving the title an intuitive name like Weblog (or the name of the Elgg installation if you instruct people to go into lang/block_eportfolio and change the block title) will increase accessability and access to the Elgg installation.

In any case, thanks, Luke and Penny, for your help. I'm very pleased with the results.

One happy customer signing out. For now...
In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Paulo Matos -
Hi Mark!
Would you be kind to post here your complete modifications to e-portfolio block.
Thanks in advance.

Regards,

Paulo
In reply to Paulo Matos

Re: Elgg: Link block title to user's blog

by Mark Penny -
Hey, Paulo.

It's all here. I think you're looking for Luke's code in the post just below this reply.

This discussion all happened some time ago, so I'm pretty rusty on the details. I don't even use Elgg now, because my server won't support it. It's a pity, but these things happen.

Let me point out that the changes were made by Penny and Luke. I just requested them.

Good luck.
In reply to Mark Penny

Re: Elgg: Link block title to user's blog

by Luke Hudson -
Something like the following would probably do it:

    $blogurl = "$CFG->block_eportfolio_baseurl/_weblog";
    if (empty($USER->eportfolioauthed)) {
  $blogurl = $CFG->wwwroot.'/blocks/eportfolio/authredirect.php?sesskey='.sesskey().'&url='.$blogurl;
    }
    $this->title = '<A href="' . $blogurl . '">' . get_string('blocktitle','block_eportfolio') . '</a>';

If you place this in block_eportfolio.php, within the get_content() method, as follows:

function get_content() {

...code....

$rsserror = ob_get_contents();
ob_end_clean();
if (empty($rss)) {

....code....

} else {

...more code...

>>> insert here <<<<
$USER->valideportfolio = true;
}

...yet more code....

I think that will do it - I hope that helps.

Cheers,

 - Luke Hudson (Catalyst developer)