From: Paul P. <wa...@gl...> - 2002-09-26 20:11:40
|
One of the features which I found to be missing from phpWiki is the ability to have a page trail of the last pages which you clicked on. I worked for a while trying to understand the phpWiki plugins and I think I have it. If anyone would like to try it, feel free, and let me know if you have suggestions, comments, or questions. The basis for this is the HelloWorld.php plugin... ===Start of PageTrail.php=== <?php // -*-php-*- rcs_id('$Id: PageTrail.php,v 1.1 2002/09/24 21:56:28 ppearson Exp $'); /** * A simple PageTrail WikiPlugin. * * Usage: * <?plugin PageTrail?> * <?plugin PageTrail numberlinks=5?> */ // Constants are defined before the class. if (!defined('THE_END')) define('THE_END', "!"); class WikiPlugin_PageTrail extends WikiPlugin { // Four required functions in a WikiPlugin. function getName () { return _("PageTrail"); } function getDescription () { return _("PageTrail Plugin"); } // Establish default values for each of this plugin's arguments. function getDefaultArguments() { return array('numberlinks' => "5"); } function run($dbi, $argstr, $request) { global $Theme; extract($this->getArgs($argstr, $request)); if ($numberlinks>5 || $numberlinks<0) { $numberlinks=5;} // Get name of the current page we are on $thispage = $GLOBALS['request']->args['pagename']; $Page=array(); // Shift down the page names and store them back to cookies for ($count=$numberlinks; $count>0; $count--) { $thisvalue="PageTrail".$count; $thiscookie = @$_COOKIE["$thisvalue"]; if ($thiscookie!="") { $Page[$count+1]=$thiscookie; } else { $Page[$count+1]=""; } } $Page[1]=$thispage; // Now lets cycle through them saving them with setcookie $html = " "; for ($count=$numberlinks; $count>0; $count--) { if ($Page[$count]!="") { $Name="PageTrail" . $count; $Value = $Page[$count]; setcookie ($Name, $Value, 0, '/'); } } $html = HTML::tt(fmt('%s ==> %s ==> %s ==> %s ==> %s', WikiLink($Page[5], 'auto'), WikiLink($Page[4], 'auto'), WikiLink($Page[3], 'auto'), WikiLink($Page[2], 'auto'), WikiLink($Page[1], 'auto')),THE_END); return $html; } }; // For emacs users // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: ?> ===End of PageTrail.php=== Comments ??? Paul |
From: Wandrer <wa...@gl...> - 2002-09-26 21:56:58
|
At 05:12 PM 9/26/2002 -0700, you wrote: >Paul Pearson wrote: >>One of the features which I found to be missing from phpWiki is the >>ability to have a page trail of the last pages which you clicked on. <snip> > >Thanks Paul. I have added it to my pc wiki. Not sure how to make use of it; >maybe you can shed some light. Here's the location of PageTrail in the pcwiki: <snip> >I get a number of error messages at the top of the above page. >Cheers, >LL The errors are because the plugin is trying to send multiple cookie(s) to your computer to store the pages that you have visited. Add: <?plugin PageTrail?> to some of your pages and see how it works. When you first do that to your HomePage, you should see something like: ==> ==> ==> ==> HomePage! and then after you visit SomeOtherPage, the link should be something like: ==> ==> ==> HomePage ==> SomeOtherPage Then, after you visit TheOtherPage, the link should be something like: ==> ==> HomePage ==> SomeOtherPage ==> TheOtherPage In that way, it lists a trail of the pages you have visited that have the plugin in the page. As for the errors, do you have output buffering turned on ? Paul |
From: Reini U. <ru...@x-...> - 2002-09-27 16:13:13
|
I added a fixed version to CVS. http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpwiki/phpwiki/lib/plugin/PageTrail.php -- Reini Urban http://xarch.tu-graz.ac.at/home/rurban/ |
From: Jeff D. <da...@da...> - 2002-09-30 15:30:42
|
I haven't tried the plugin yet, but here's my one coding suggestion. You can use $request->setSessionVar() and $request->getSessionVar() to save persistent data. (Also $request->{get,set}CookieVar...) And you can save arrays (or anything else) that way. So instead of > $Page=array(); > // Shift down the page names and store them back to cookies > for ($count=$numberlinks; $count>0; $count--) { > $thisvalue="PageTrail".$count; > $thiscookie = @$_COOKIE["$thisvalue"]; > if ($thiscookie!="") { > $Page[$count+1]=$thiscookie; > } else { > $Page[$count+1]=""; > } > } > $Page[1]=$thispage; > // Now lets cycle through them saving them with setcookie > $html = " "; > for ($count=$numberlinks; $count>0; $count--) { > if ($Page[$count]!="") { > $Name="PageTrail" . $count; > $Value = $Page[$count]; > setcookie ($Name, $Value, 0, '/'); > } > } You can do something like (this is untested, of course, so guaranteed not to work): $pagetrail = $request->getSessionVar('PageTrail'); if (!is_array($pagetrail)) // FIXME: probably better validation is in order... $pagetrail = array(); array_unshift($pagetrail, $thispage); array_split($pagetrail, $numberlinks); // limit trail length $request->setSessionVar('PageTrail', $pagetrail); (Note that $pagetrail is a zero-based array, rather than a one-based array...) Besides being cleaner code, it has the advantage of not storing a whole handful of cookies in the clients browser... Cheers! |