1.9 Forum hack: post permanlinks / "See this post in context"

1.9 Forum hack: post permanlinks / "See this post in context"

Steven A -
回帖数:3

In 1.9, how can I hack the post permalink into the forum?

mod/forum/user.php generates a permalink (See this post in context) with the following code:

$fulllink = "discussion#p$post->id\">".get_string("postincontext", "forum")."";
forum_print_post($post, $discussion, $forum, $cms[$forum->id], $course, false, false, false, $ratings, $fulllink);

 

How can I generate the permalink in posts in the forum (mod/forum/discuss.php)? I've tried cutting and pasting various parts of the above code in both discuss.php and lib.php, but have not been successful.  How can $fulllink be instantiated in the forum?

Any suggestions are greatly apprecaited.

回复Steven A

Re: 1.9 Forum hack: post permanlinks / "See this post in context"

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

Why not generate $fullink inside the forum_print_post function?

Also, the URL looks wrong. The %5C bit is weird. Not that the code for the permalink will be very like the code for the 'Parent post' link, just with a different post id.

Finally, not that ForumNG already has permalinks.

回复Tim Hunt

Re: 1.9 Forum hack: post permanlinks / "See this post in context"

Steven A -

Hi Tim,

The forum seems to have messed up the URL in my initial post.

Thanks for the suggestion.  It pointed me in the right direction.  I've now added $fulllink to the forum_print_post function, and also had to add it to the $commands array as well.  Now the link is showing up.  Here are the steps:

1. add $fulllink to forum_print_post in lib.php:

function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=false, $reply=false, $link=false,
$ratings=NULL, $footer="", $highlight="", $post_read=null, $dummyifcantsee=true, $istracked=null, $fulllink) {
...
$fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".get_string("postincontext", "forum")."</a>";
...
}


2. add $fulllink to the $commands array in lib.php:

if ($fulllink) {
$commands[] = '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'#p'.$post->id.'">'.
get_string('postincontext', 'forum').'</a>';
}

One question I have is how to set permissions so that only teachers can see $fulllink.  Maybe I should read some before asking, but any pointers are appreciated.

回复Steven A

Re: 1.9 Forum hack: post permanlinks / "See this post in context"

Steven A -

To answer my own question, I copied in a permission that only teachers and above have as follows:

if ($fulllink and $cm->cache->caps['mod/forum:splitdiscussions'])

This will serve my purposes just fine.