From: Rob F. <rfu...@dr...> - 2004-04-13 20:38:43
|
This is my first time working with PHP code. Obviously, I'm learning my way around. Please be kind in your comments. http://fulwell.com/wiki/index.php/FileBlog Usage is very simple: <?plugin FileBlog uldirurl=http://site.com/wiki/uploads ?> where site.com/wiki/uploads points your your wiki uploads directory. Right now the plugin is very basic (only looks for .jpg files) but it is a start and it works for me. If there is a file with the same name as an image file but with a .desc extension instead of a .jpg extension, that (text) file will be used as the description of the image file. fileblog.tmpl (goes in wiki/themes/default/templates): <div title="<?= $IMAGENAME ?>" class="wikiblog wikitext"> <div class="wikiblog-header"> <strong class="floatleft"><?= $IMAGENAME ?></strong> <strong class="floatright"><?= $DATETIME ?></strong> <br clear="all" class="clear-floats" /> </div> <div class="wikiblog-body"> <?= $CONTENT ?> </div> <div class="wikiblog-footer"> <a href="<?= $IMAGE ?>"><img src=<?= $IMAGE ?> border=0 alt=""></a> </div> </div> <hr class="no-css" /> FileBlog.php (goes in wiki/lib/plugin): <?php // -*-php-*- class WikiPlugin_FileBlog extends WikiPlugin { function getName () { return _("FileBlog"); } function getDescription () { return sprintf(_("Show file blogs for %s"),'[pagename]'); } function getVersion() { return preg_replace("/[Revision: $]/", '', "\$Revision: 0.1 $"); } // Arguments: // // uploaddir - directory where uploaded files reside // (This will be relative to your wiki location) // // uldirurl - URL which would get you a directory listing of your // upload directory (e.g. http://site.com/uploads) // // order - 'normal' - place in chronological order // - 'reverse' - place in reverse chronological order // // mode - 'all' - show all files with descriptions // 'allimages' - show all images (no descriptions) // 'author' - show only one user's files with descriptions // 'authorimages' - show only one user's images (no descriptions) // // TODO: // // - the only mode supported right now is 'all' function getDefaultArguments() { return array('uploaddir' => './uploads', 'uldirurl' => '[uldirurl]', 'order' => 'normal', 'mode' => 'all' ); } function run($dbi, $argstr, $request) { $args = $this->getArgs($argstr, $request); $html = HTML(); foreach (explode(',', $args['mode']) as $mode) { switch ($mode) { case 'all': $html->pushContent($this->showBlogs($request, $args)); break; default: return $this->error(sprintf("Bad mode ('%s')", $mode)); } } return $html; } function showBlogs (&$request, $args) { $html = HTML(); $uploaddirurl = $args['uldirurl']; $d = dir($args['uploaddir']); while (false !== ($entry = $d->read())) { if (substr($entry, -4)== ".jpg") { $filepath = $d->path . "/" . $entry; $descpath = substr_replace($filepath, ".desc", -4); if (file_exists($descpath)) { $handle = fopen($descpath, "r"); $bodytext = fread($handle, filesize($descpath)); fclose($handle); $bodytext = HTML::pre($bodytext); } else { $bodytext = HTML::pre("(No description.)"); } $imageurl = $uploaddirurl . substr(strrchr($filepath, "/"), 0 ); $filedatetime = date("l dS of F Y h:i:s A", filemtime($filepath)); $newpage = $this->GenerateFilePage($bodytext, $imageurl, $filedatetime); $html->pushContent($newpage); } } $d->close(); return $html; } function GenerateFilePage($content, $imageurl, $datetime) { global $request; $args = array(); $imagename = substr(strrchr($imageurl, "/"), 1 ); $args['IMAGENAME'] = $imagename; $args['DATETIME'] = $datetime; $args['CONTENT'] = $content; $args['IMAGE'] = $imageurl; return new Template('fileblog', $request, $args); } }; ?> |