* Version: 0+3i (based on blosxom 0+4i with a lot of improvements) * Home/Docs/Licensing: http://www.zhware.net/phosxom/ * blosxom home: http://www.oreillynet.com/~rael/lang/perl/blosxom/ */ $datadir = '/home/rubys/web/intertwingly.net/blosxom/'; $plugdir = ''; $blog_id = 'zhlog'; $blog_title = 'Sam Ruby'; $blog_url = 'http://www.intertwingly.net/phosxom3.php'; $blog_descr = 'It\'s just data'; $num_entries = 10; $abslen = 255; // length of abstracts (returned when searching) $now = date("D, d-M-Y H:i:s T"); $actions = array('xml','txt','search'); $query = ''; // templates for header,story and footer $text = array ( 'html' => array( head => '"/>Phosxom

', story => '


posted at   ">#


', foot => ''), 'xml' => array( head => "\n\n\n<?=\$blog_title?>\n\n\n\nen-us\n", story => "\n<?=\$title?>\n\n\n\">/\n\n\n", foot => "\n"), ); // ---------------------------------------------- // Parse URL reqest - output disabled (header still not sent) ob_start(); $path_arr = explode('/',$_SERVER["PATH_INFO"]); array_shift($path_arr); $pt = $path_arr; // Form content type (xml,html etc.) from the last element in URL $last = (count($path_arr)) ? array_pop($path_arr) : ''; // remove trailing slash if ('' == $last && count($path_arr)) $last = array_pop($path_arr); // is the last entry some action - search, xml etc.? $content_type = 'html'; if (!in_array($last,$actions)) array_push($path_arr,$last); if ('xml' == $last) $content_type = 'xml'; elseif ('txt' == $last) $content_type = 'plain'; // working with sub-directories $is_shifted = 0; $relative_dir = ''; $title_menu = "$blog_title"; if(count($path_arr)) { $subdir = array_shift($path_arr); $is_shifted++; } while ($subdir != '' && is_dir($datadir.$relative_dir.$subdir) && is_readable($datadir.$relative_dir.$subdir)) { $relative_dir .= $subdir.'/'; $blog_title .= ' : '.$subdir; $title_menu .= " : $subdir"; $subdir = array_shift($path_arr); } if ($is_shifted) array_unshift($path_arr,$subdir); // Form year, month, day etc. and title_menu $pt_yr = $pt_mo = $pt_da = $pt_id = ''; if (count($path_arr)) list($pt_yr,$pt_mo,$pt_da) = $path_arr; if ($pt_yr) { $blog_title .= " -- Archives: $pt_yr $pt_mo $pt_da"; $title_menu .= " -- Archives: $pt_yr"; $title_menu .= ($pt_da) ? " $pt_mo $pt_da" : " $pt_mo $pt_da"; } ob_end_clean(); // send content type information header("Content-type: text/$content_type"); if ($content_type != 'plain') echo ''."\n"; // enter templates from external .html files if ('html' == $content_type) { foreach (array('head','foot','story','search') as $tmpl) { $fname =''; if (file_exists("$datadir$relative_dir$tmpl.html") && is_readable("$datadir$relative_dir$tmpl.html")) { $fname = "$datadir$relative_dir$tmpl.html"; } else if (file_exists("$datadir$tmpl.html") && is_readable("$datadir$tmpl.html")) { $fname = "$datadir$tmpl.html"; } if ($fname != '') { $fd=fopen($fname,"r"); $data = ereg_replace("(\\$[[:alnum:]]+)", "", fread($fd,filesize($fname))); fclose($fd); while (ereg("#include \"([a-z.]+)\"", $data, $includes)) { $include = $datadir.'/'.$includes[1]; $fd=fopen($include,"r"); $data = ereg_replace($includes[0], fread($fd,filesize($include)), $data); fclose($fd); } $text['html'][$tmpl] = $data; } } } $entries = files_list($datadir.$relative_dir); // plugins if ('html' == $content_type) { include $plugdir."pxm_cal.php"; include $plugdir."pxm_search.php"; include $plugdir."pxm_img.php"; } include $plugdir."pxm_rss30.php"; // header ob_start(); eval("?>".$text[$content_type][head]."$mtime) { $yr = date("Y",$mtime); $mo = date("M",$mtime); $da = date("d",$mtime); $dw = date("l",$mtime); if ($pt_yr) { if ($yr!=$pt_yr) continue; if ($yr<$pt_yr) break; } if ($pt_mo && $mo != ucfirst(strtolower($pt_mo))) continue; if ($pt_da) { if ($da!=$pt_da) continue; if ($da<$pt_da) break; } if ('html' == $content_type && "$dw, $da $mo $yr" != $currdate ) { $currdate = "$dw, $da $mo $yr"; echo '

'.$currdate."

\n"; } $cat = dirname($fname); $fn = str_replace('.txt','', basename($fname)); $arr = file($datadir.$fname); $title = rtrim(array_shift($arr)); if ('plain' == $content_type) $body = implode(' ',$arr); else $body = implode('',$arr); $ti = strftime("%H:%M %Z",$mtime); // for searching template if ('search' == $last) { $size = filesize($datadir.$fname); $abstract = strip_tags($body); if (strlen($abstract)>$abstlen) $abstract = substr($abstract,0,$abslen).'...'; $timestamp = "on ".strftime("%d %b %Y",$mtime)." at $time"; } elseif ('xml' == $content_type) { // escape HTML special chars in title and body $title = htmlentities($title,ENT_NOQUOTES,'UTF-8'); $body = htmlentities($body,ENT_NOQUOTES,'UTF-8'); } elseif ('plain' == $content_type) { $body = pxm_rss30_format($body); } eval("?>".$text[$content_type][story]."".$text[$content_type][foot]."300) { */ foreach (list_dir($maindir) as $fname) { if (substr($fname,strrpos($fname,'.')+1) == "txt") { $entries[str_replace($datadir,'',$fname)] = filemtime($fname); } } /* $fd = fopen($cache,"w"); fwrite($fd,base64_encode(serialize($entries))); fclose($fd); } $fd = fopen($cache,"r"); $entries = unserialize(base64_decode(fread($fd,filesize($cache)))); fclose($fd); reset($entries); */ arsort($entries); return $entries; } // UNIX speciffic function: // $a = `find $dir -depth -type f -print | grep ".txt$"`; // $files = explode ("\n", $a); // Will this give me more speed? function list_dir($dirname) { if ($dirname[strlen($dirname)-1] != '/') $dirname .= '/'; static $fl_list = array(); $handle=opendir($dirname); while (false != ($file = readdir($handle))) { if($file=='.'||$file=='..') continue; if (is_dir($dirname.$file)) list_dir($dirname.$file.'/'); else if (ereg("\.txt$",$file)) $fl_list[] = $dirname.$file; } closedir($handle); return $fl_list; } ?>