From: Penny Leach Date: Mon, 29 May 2006 08:16:33 +0000 (+1200) Subject: beginning of support for about and gallery X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=4ff6f3fd7cbff515e00ddcb52a2a402109e98794;p=s9y.git beginning of support for about and gallery --- diff --git a/gallery/view.php b/gallery/view.php new file mode 100644 index 0000000..647a3e1 --- /dev/null +++ b/gallery/view.php @@ -0,0 +1,39 @@ + + + view image + + + +'; + + +$file = sanitize_filename($file); + +if (file_exists(SGN_DIR_ROOT.$file)) { + $caption = ''; + $f = explode('.',$file); + if (file_exists(SGN_DIR_ROOT.str_replace($f[count($f)-1],'inc',$file))) { + $caption = implode('',file(SGN_DIR_ROOT.str_replace($f[count($f)-1],'inc',$file))); + } + echo '

'.strip_tags($caption).'

' + .'

'.$caption.'

' + .'

'; + if ($prev = has_prev_image($file)) { + echo 'prev | '; + } + echo 'dir'; + if ($next = has_next_image($file)) { + echo ' | next '; + } + echo '

'; +} +?> + + \ No newline at end of file diff --git a/include/about.inc.php b/include/about.inc.php new file mode 100644 index 0000000..c73884e --- /dev/null +++ b/include/about.inc.php @@ -0,0 +1,42 @@ +assign('content_message',' +

about

+

A long list of not very interesting facts about me, in no particular order:

+ +'); + + + + +?> diff --git a/include/functions_installer.inc.php b/include/functions_installer.inc.php index f0553b4..6402a7a 100644 --- a/include/functions_installer.inc.php +++ b/include/functions_installer.inc.php @@ -844,7 +844,10 @@ function serendipity_installFiles($serendipity_core = '') { '{PAT_PERMALINK_AUTHORS}', '{PAT_PERMALINK_FEEDCATEGORIES}', '{PAT_PERMALINK_CATEGORIES}', - '{PAT_PERMALINK_FEEDAUTHORS}' + '{PAT_PERMALINK_FEEDAUTHORS}', + '{PAT_ABOUT}', '{PATH_ABOUT}', + '{PAT_GALLERY}','{PATH_GALLERY}', + ), array( @@ -865,7 +868,9 @@ function serendipity_installFiles($serendipity_core = '') { trim($PAT['PERMALINK_AUTHORS'], '@/i'), trim($PAT['PERMALINK_FEEDCATEGORIES'], '@/i'), trim($PAT['PERMALINK_CATEGORIES'], '@/i'), - trim($PAT['PERMALINK_FEEDAUTHORS'], '@/i') + trim($PAT['PERMALINK_FEEDAUTHORS'], '@/i'), + trim($PAT['ABOUT'], '@/i'), $serendipity['permalinkAboutPath'], + trim($PAT['GALLERY'],'@/i'), $serendipity['permalinkGalleryPath'], ), implode('', $a) @@ -883,6 +888,7 @@ function serendipity_installFiles($serendipity_core = '') { fwrite($fp, $match[1] . $content . $match[2]); } else { fwrite($fp, $content); + error_log('writing to file'); } fclose($fp); return true; diff --git a/include/functions_permalinks.inc.php b/include/functions_permalinks.inc.php index de575a8..0ccd419 100644 --- a/include/functions_permalinks.inc.php +++ b/include/functions_permalinks.inc.php @@ -216,10 +216,20 @@ function serendipity_initPermalinks() { $serendipity['permalinkSearchPath'] = 'search'; } + if (!isset($serendipity['permalinkAboutPath'])) { + $serendipity['permalinkAboutPath'] = 'about'; + } + + if (!isset($serendipity['permalinkGallery{ath'])) { + $serendipity['permalinkGalleryPath'] = 'gallery'; + } + /* URI paths * These could be defined in the language headers, except that would break * backwards URL compatibility */ + @define('PATH_ABOUT', $serendipity['permalinkAboutPath']); + @define('PATH_GALLERY', $serendipity['permalinkGalleryPath']); @define('PATH_ARCHIVES', $serendipity['permalinkArchivesPath']); @define('PATH_ARCHIVE', $serendipity['permalinkArchivePath']); @define('PATH_CATEGORIES', $serendipity['permalinkCategoriesPath']); @@ -237,6 +247,8 @@ function serendipity_initPermalinks() { * If you add new patterns, remember to add the new rules to the *.tpl files and * function serendipity_installFiles(). */ + @define('PAT_ABOUT', '@/'.PATH_ABOUT.'/?@'); + @define('PAT_GALLERY','@/'.PATH_GALLERY.'/(.*)@'); @define('PAT_FILENAME', '0-9a-z\.\_!;,\+\-'); @define('PAT_CSS', '@/(serendipity\.css|serendipity_admin\.css)@'); @define('PAT_FEED', '@/(index|atom[0-9]*|rss|b2rss|b2rdf).(rss|rdf|rss2|xml)@'); @@ -257,6 +269,8 @@ function &serendipity_permalinkPatterns($return = false) { $PAT = array(); + $PAT['ABOUT'] = '@/' . $serendipity['permalinkAboutPath']; + $PAT['GALLERY'] = '@/' . $serendipity['permalinkGalleryPath']; $PAT['UNSUBSCRIBE'] = '@/' . $serendipity['permalinkUnsubscribePath'].'/(.*)/([0-9]+)@'; $PAT['APPROVE'] = '@/' . $serendipity['permalinkApprovePath'].'/(.*)/(.*)/([0-9]+)@'; $PAT['DELETE'] = '@/' . $serendipity['permalinkDeletePath'].'/(.*)/(.*)/([0-9]+)@'; diff --git a/include/gallery.inc.php b/include/gallery.inc.php new file mode 100644 index 0000000..01ef941 --- /dev/null +++ b/include/gallery.inc.php @@ -0,0 +1,84 @@ +'.strip_tags($caption).'

' + .'

'.$caption.'

'; + + } +} else { + $content = make_directory($show); +} + +$serendipity['smarty']->assign('content_message',$content); + + +?> \ No newline at end of file diff --git a/include/genpage.inc.php b/include/genpage.inc.php index 9f9a187..1539420 100644 --- a/include/genpage.inc.php +++ b/include/genpage.inc.php @@ -91,6 +91,12 @@ if ($serendipity['smarty_raw_mode']) { case 'archives': serendipity_printArchives(); break; + case 'about': + include_once(S9Y_INCLUDE_PATH.'include/about.inc.php'); + break; + case 'gallery': + include_once(S9Y_INCLUDE_PATH.'include/gallery.inc.php'); + break; // Welcome screen or whatever default: diff --git a/include/tpl/htaccess_rewrite.tpl b/include/tpl/htaccess_rewrite.tpl index 764de68..0fb2b7b 100644 --- a/include/tpl/htaccess_rewrite.tpl +++ b/include/tpl/htaccess_rewrite.tpl @@ -25,6 +25,7 @@ RewriteRule ^{PAT_SEARCH} {indexFile}?url=/{PATH_SEARCH}/$1 [L,QSA] RewriteRule ^{PAT_CSS} {indexFile}?url=/$1 [L,QSA] RewriteRule ^index\.(html?|php.+) {indexFile}?url=index.html [L,QSA] RewriteRule ^htmlarea/(.*) htmlarea/$1 [L,QSA] +RewriteRule ^{PAT_ABOUT} {indexFile}?url=/{PAT_ABOUT}/ [L,QSA] RewriteRule (.*\.html?) {indexFile}?url=/$1 [L,QSA] diff --git a/index.php b/index.php index 4c2733b..a456d6f 100644 --- a/index.php +++ b/index.php @@ -454,6 +454,12 @@ if (preg_match(PAT_ARCHIVES, $uri, $matches) || isset($serendipity['GET']['range $css_mode = $matches[1]; include_once(S9Y_INCLUDE_PATH . 'serendipity.css.php'); exit; +} else if (preg_match(PAT_ABOUT, $uri, $matches)) { + $serendipity['GET']['action'] = 'about'; + include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php'); +} else if (preg_match(PAT_GALLERY, $uri, $matches)) { + $serendipity['GET']['action'] = 'gallery'; + include_once(S9Y_INCLUDE_PATH . 'include/genpage.inc.php'); } else if (preg_match('@/(index(\.php|\.html)?)|'. preg_quote($serendipity['indexFile']) .'@', $uri) || preg_match('@^/' . preg_quote(trim($serendipity['serendipityHTTPPath'], '/')) . '/?(\?.*)?$@', $uri)) { diff --git a/plugins/serendipity_plugin_gallery/lib.php b/plugins/serendipity_plugin_gallery/lib.php new file mode 100644 index 0000000..76d2693 --- /dev/null +++ b/plugins/serendipity_plugin_gallery/lib.php @@ -0,0 +1,293 @@ + $name) { + echo ''; + if ($expanded[$path] == 1) { + echo 'expand '."\n"; + if ($show != $path) { + echo ''.stripslashes($name).'
'."\n"; + } + else { + echo ''.stripslashes($name).'
'."\n"; + } + make_tree($path,$indent+10,$show,$expand,$expanded); + } + else { + if (has_children($path)) { + echo 'expand '."\n"; + } + else { + echo 'No children '."\n"; + } + if ($show != $path) { + echo ''.stripslashes($name).'
'."\n"; + } + else { + echo ''.stripslashes($name).'
'."\n"; + } + } + } +} + + +function has_children($path) { + global $serendipity; + $children = get_children($path); + if (!empty($children) || count($children)) { + return true; + } + return false; +} + + +function get_children($path) { + global $serendipity; + $fullpath = SGN_DIR_ROOT.$path; + $children = array(); + $dir = opendir($fullpath); + while (false !== ($file = readdir($dir))) { + if (substr($file,0,1) == '.') { // hide hidden + continue; + } + if (!is_dir($fullpath.'/'.$file)) { + continue; + } + if ($path{strlen($path) -1} != '/') { + $path = $path.'/'; + } + $children[$path.$file] = $file; + } + return $children; + +} + + +function make_search($query) { + global $serendipity; + +} + + +function make_directory($show) { + global $serendipity; + $content .='
'; + $content .='

showing images in: '.get_heading($show).':

'; + if (file_exists(SGN_DIR_ROOT.$show.'/summary.inc')) { + $content .='

»» '; + $content .= implode('',file(SGN_DIR_ROOT.$show.'/summary.inc')); + $content .='

'; + } + $files = get_images($show); + if (!is_array($files) || !count($files)) { + $content .='

»» No images!

'; + $content .='
'; + } + else { + $content .=''; + $content .=''; + $count = 1; + foreach ($files as $file) { + $thumb = get_thumb($show,$file); + $f = explode('.',$file); + $caption = ''; + if (file_exists(SGN_DIR_ROOT.$show.str_replace($f[count($f)-1],'inc',$file))) { + $caption = implode('',file(SGN_DIR_ROOT.$show.str_replace($f[count($f)-1],'inc',$file))); + } + $content .=''; + if ($count == 3) { + $content .=''; + $count = 1; + } + else { + $count++; + } + } + $content .='
'.$caption.'
'; + } + $content .='
'; + $content .='

subdirectories:

'; + + $children = get_children($show); + + if (count($children)) { + foreach ($children as $path => $child) { + $content .='

»» '.$child.''; + if (file_exists(SGN_DIR_ROOT.$path.'/summary.inc')) { + $content .='
' + .implode('',file(SGN_DIR_ROOT.$path.'/summary.inc')); + } + $content .='

'; + } + } else { + $content .='

No children

'; + } + $content .='
'; + return $content; +} + +function get_heading($str) { + global $serendipity; + $dirs = explode('/',$str); + $newstr = ''; + foreach ($dirs as $index => $dir) { + $path = ''; + for ($i = 0; $i < $index; $i++) { + $path .= $dirs[$i].'/'; + } + $newstr .= ''.$dir.'/'; + } + return $newstr; +} + + +function get_images($path) { + global $serendipity; + $fullpath = SGN_DIR_ROOT.$path; + $children = array(); + $dir = opendir($fullpath); + while (false !== ($file = readdir($dir))) { + if (substr($file,0,1) == '.') { // hide hidden + continue; + } + if (is_dir($fullpath.'/'.$file)) { + continue; + } + $f = explode('.',$file); + if ($f[count($f)-1] == 'inc') { + continue; + } + if ($f[count($f)-2] == 'thumb') { + continue; + } + if ($file{strlen($file)-1} == '~') { + // naughty emacs + continue; + } + if ($path{strlen($path) -1} != '/') { + $path = $path.'/'; + } + $children[$path.$file] = $file; + } + return $children; +} + +function get_thumb($path,$filename) { + global $serendipity; + + $f = explode('.',$filename); + $thumbname = $path.'/'.str_replace($f[count($f)-1],'thumb.'.$f[count($f)-1],$filename); + + if (file_exists(SGN_DIR_ROOT.$thumbname)) { + return $thumbname; + } + + + // set up some config variables + $width = 100; // max width of thumb + $height = 100; // max height of thumb + + $view = SGN_DIR_ROOT.$path.'/'.$filename; + + $extn = strtolower(substr($filename, -3)); + switch($extn) { + case 'jpg': + $old = @ImageCreateFromJPEG($view); + break; + + case 'png': + $old = @ImageCreateFromPNG($view); + break; + } + + + if (empty($old)) { + return false; + } else { + $old_x = ImageSX($old); + $old_y = ImageSY($old); + + // make new thumbnail + if ($old_y > $old_x) { + $new_y = $height; // max height of thumb + $new_x = ($old_x * $new_y)/$old_y; // retain aspect ratio + } + else { + $new_x = $width; // max width of thumb + $new_y = ($old_y * $new_x)/$old_x; // retain aspect ratio + } + // $new = ImageCreate($new_x, $new_y); + $new = ImageCreateTrueColor($new_x, $new_y); + @ImageCopyResized($new, $old, 0, 0, 0, 0, $new_x, $new_y, $old_x, $old_y); + } + + imageInterlace($new); + touch(SGN_DIR_ROOT.$thumbname); + $result = ImagePNG($new,SGN_DIR_ROOT.$thumbname); + return $thumbname; +} + +function sanitize_filename($file) { + global $serendipity; + $path = explode('/',$file); + $return = ''; + foreach ($path as $p) { + if ($p != '..') { + $return .= $p.'/'; + } + } + return substr($return,0,-1); + +} + + +function has_next_image($file) { + $images = get_images(substr($file,0,strrpos($file,'/'))); + $count = 0; + $ret = false; + foreach ($images as $k => $v) { + if (!empty($ret)) { + return $k; + } + if ($k == $file) { + if ($count != count($images)-1) { + $ret = true; + } + } + $count++; + } + return false; +} + +function has_prev_image($file) { + $images = get_images(substr($file,0,strrpos($file,'/'))); + $count = 0; + $ret = false; + foreach ($images as $k => $v) { + if ($k == $file) { + if (!empty($ret)) { + return $ret; + } + } + $ret = $k; + $count++; + } + return false; +} + + +?> diff --git a/plugins/serendipity_plugin_gallery/serendipity_plugin_gallery.php b/plugins/serendipity_plugin_gallery/serendipity_plugin_gallery.php new file mode 100644 index 0000000..917bbb9 --- /dev/null +++ b/plugins/serendipity_plugin_gallery/serendipity_plugin_gallery.php @@ -0,0 +1,73 @@ +add('name', PLUGIN_GALLERY); + $propbag->add('description', PLUGIN_GALLERY_BLAHBLAH); + $propbag->add('stackable', true); + $propbag->add('author', 'Penny Leach'); + $propbag->add('version', '1.0'); + $propbag->add('requirements', array( + 'serendipity' => '0.8', + 'smarty' => '2.6.7', + 'php' => '4.1.0' + )); + } + + function generate_content(&$title) + { + global $serendipity; + $title = $this->title; + + + $show = $_GET['show']; + if (!isset($show)) { + $show = (isset($_SESSION['show'])) ? $_SESSION['show'] : ''; + } + $_SESSION['show'] = $show; + $expand = $_GET['expand']; + if (!isset($_GET['expand'])) { + $expand =(isset($_SESSION['expand'])) ? $_SESSION['expand'] : ''; + } + $_SESSION['expand'] = $expand; + $expanded = $_SESSION['expanded']; + if (!isset($expanded)) { + $expanded = array(); + } + $expanded[$expand] = 1; + $collapse= $_GET['collapse']; + if (isset($collapse)) { + $expanded[$collapse] = 0; + } + $_SESSION['expanded'] = $expanded; + $op = $_GET['op']; + + make_tree('/',1,$show,$expand,$expanded); + } + +} + + +/* vim: set sts=4 ts=4 expandtab : */ +?>