<?php #ext
/*
Blog Plugin version2
Copyright 2009 Ameoto Systems. All Rights Resurved.
Written by TheTooth, hide@address.com
WhiteCrane 1.3.5 r55+
*/
//Define
define("blog", "Blog::This plugin allows you to create a simple blog page that shows a list of pages using a prefix such as 'blog_timestamp'.<br />Written by thetooth, Copyright 2009 Ameoto Systems. All Rights Resurved.");
$this->_init['sub']['blog'] = 'blog';
$this->_init['config']['blog'] = 'blog_configMenu';
$this->_init['menu']['blog'] = 'blog_menu';
// Installer
global $config;
if(!isset($config['blogMode'])){
$config['blogMode'] = true;
$config['blogSpace'] = 'blog';
$config['blogComments'] = false;
$config['blogMini'] = false;
$config['DISQUS'] = '';
if(!file_exists('./pages/'.$config['blogSpace'].'.txt') && $config['blogMode'] == true){
$fp = fopen('./pages/'.$config['blogSpace'].'.txt','w') or die($fail['filesystem'].' [009]+ Plugin');
fwrite($fp, "=====Blog Plugin Installed!=====\n<p>WhiteCrane now comes with a small blogging platform for you to use. You'll noticed we make use of DISQUS for simple and secure comments, just remember to update your settings to get things working.</p>");
fclose($fp);
unset($fp);
}
update_config();
}
//Config Menu
function blog_configMenu(){
global $config;
function isChecked($var){
global $config;
if($config[$var] == true){
return 'checked="checked"';
}
}
echo '<tr><td><p><strong>Blog:</strong></p></td><td>
<p><input name="blogMode" type="checkbox" id="checkbox" '.isChecked('blogMode').' />Enable Blog</p>
<p><input name="blogComments" type="checkbox" id="checkbox" '.isChecked('blogComments').' />Enable Comments</p>
<p><input name="blogMini" type="checkbox" id="checkbox" '.isChecked('blogMini').' />Compact View(<a href="javascript:ReverseDisplay(\'Mini-help\')">?</a>)
<p id="Mini-help" style="display:none;">Use a more lightweight list format for posts.</p></p>
<p>Name space: <br /><input type="text" name="blogSpace" class="txt" value="'.$config['blogSpace'].'" /></p>
<p>DISQUS Domain(<a href="javascript:ReverseDisplay(\'DISQUS-help\')">?</a>): <br />
<p id="DISQUS-help" style="display:none;">This is the http://<strong>your_domain</strong>.disqus.com/, without anything else.</p>
<input type="text" name="DISQUS" class="txt" value="'.$config['DISQUS'].'" /></p></td></tr>';
}
//Menu bar
function blog_menu(){
global $config;
if (!isset($_REQUEST['act']) && !isset($_REQUEST['blog']) && $config['blogMode'] == true && Page == $config['blogSpace']){
echo '<input type="submit" name="blog" value="New Entry" class="btn">';
}
}
//Main script
function blog(){
global $config, $full, $user;
function blogImage($value){
$handle = opendir("uploads");
while(false !== ($file = readdir($handle))){
if(!is_dir($file) && preg_match('/^'.$value.'/is', $file)) return $file;
}
closedir($handle);
}
if(Page == $config['blogSpace']){
// This function reads all available news
function blogEntryList(){
global $config;
$fileList = array();
// Open the actual directory
if ($handle = opendir("pages")) {
while ($file = readdir($handle)) {
if (!is_dir($file) && preg_match('/^'.$config['blogSpace'].'_.+/',$file) > 0) {
$file = preg_replace('/'.$config['blogSpace'].'_(.+?)\.txt/is', ''.$config['blogSpace'].'_$1', $file);
$fileList[] = $file;
}
}
}
rsort($fileList);
return $fileList;
}
if (!isset($_REQUEST['act']) && isset($_REQUEST['blog']) && $_REQUEST['blog'] == 'archive' && $config['blogMode'] == true){
$list = blogEntryList();
echo '<h2>Blog Archive</h2><ul>';
foreach($list as $value){
$file = "pages/".$value.".txt";
$newsData = file($file);
$newsTitle = preg_replace("/=====(.+?)=====/is", "$1", $newsData[0]);
$submitDate = $newsData[1];
unset ($newsData['0']);
unset ($newsData['1']);
echo "<li><strong>$submitDate</strong><a href=\"";
if($config['rewrite'] == 'on'){
echo "/$value";
}else{
echo Self."/index.php?page=$value";
}
echo "\">$newsTitle</a></li>";
}
echo '</ul>';
}
if(!isset($_REQUEST['act']) && !isset($_REQUEST['blog']) && $config['blogMode'] == true && Page == $config['blogSpace']){
$parser = new Parser();
$list = blogEntryList();
$maxpost = 1;
foreach($list as $value){
if($maxpost <= 10){
$file = "pages/".$value.".txt";
$newsFull = file_get_contents($file);
echo "<div class=\"blogPost\">";
if($config['blogMini'] == true){
$newsData = file($file);
$newsTitle = preg_replace("/=====(.+?)=====/is", "$1", $newsData[0]);
$submitDate = $newsData[1];
$contentIntro = preg_split("/\^\^/", strip_tags($newsFull));
$contentIntro = $contentIntro[1];
unset ($newsData['0']);
unset ($newsData['1']);
if($contentIntro == ""){
$contentIntro = "Error getting intro!!";
}
echo "<h3><a href=\"";
if($config['rewrite'] == 'on'){
echo "/$value";
}else{
echo Self."/index.php?page=$value";
}
echo "\">$newsTitle</a></h3><sub><strong>$submitDate</strong></sub>";
$Render = "<p class=\"intro\">".$parser->parse(($config['nl'] != true ? nl2br($contentIntro) : $contentIntro))."</p>";
}else{
$Render = $parser->parse(preg_replace("/=====(.+?)=====/is", "=====<a href=\"".($config['rewrite'] == true ? "/".$value : Self."/index.php?page=".$value)."\">$1</a>=====", $newsFull));
}
echo $Render."</div>";
$maxpost++;
}else{
break;
}
}
if($maxpost == 0){
echo '<p>No Entrys!!!</p>';
}
}
if(isset($_POST['blog']) && $_POST['blog'] == "Save" && !isset($_REQUEST['act']) && array_key_exists($_SESSION["logged"],$user) && $user[$_SESSION["logged"]][1] == (1||2)){
echo 'Posting, Please Wait...';
$filename = $config['blogSpace'].'_'.date('YmdHis');
$imageMode = false;
//Image Handeler
if(isset($_FILES['upload_file']) && basename($_FILES['upload_file']['name']) != ''){
if(file_exists('uploads/'.blogImage($filename)) && !is_dir('uploads/'.blogImage($filename))){
unlink('uploads/'.blogImage($filename));
}
$tempFile = $_FILES['upload_file']['tmp_name'];
$targetPath = 'uploads/';
$extensions = pathinfo($_FILES['upload_file']['name'], PATHINFO_EXTENSION);
$safeext = array('jpg', 'jpeg', 'png', 'gif');
if((($_FILES["upload_file"]["type"] == "image/gif")
|| ($_FILES["upload_file"]["type"] == "image/jpeg")
|| ($_FILES["upload_file"]["type"] == "image/pjpeg")
|| ($_FILES["upload_file"]["type"] == "image/png")
|| ($_FILES["upload_file"]["type"] == "image/bmp"))
&& ($_FILES["upload_file"]["size"] < 5242880) && in_array(strtolower($extensions), $safeext)){
$newFileName = $filename.'.'.strtolower($extensions);
$targetFile = str_replace('//','/',$targetPath).$newFileName;
if(extension_loaded('gd') && function_exists('gd_info')){
//GD Lib extras
}
move_uploaded_file($tempFile,$targetFile);
$imageMode = "<div class=\"blogImage\">[img]".Self.'/'.$targetFile."[/img]</div>\n";
}else{
echo '<p>File format not supported.</p>';
$error = 1;
}
}
if(isset($_REQUEST['image_delete']) && blogImage($_REQUEST['id']) != ''){
unlink('uploads/'.blogImage($filename));
}
$newsTitle = '====='.stripslashes(isset($_POST['newstitle']) && $_POST['newstitle'] != "" ? $_POST['newstitle'] : 'Untitled').'=====';
$submitDate = date('Y-m-d g:i:s A')." by <a href=\"".Self."/?act=Profile&id=".$_SESSION['logged']."\">".$_SESSION['logged']."</a>";
$newsIntro = '^^'.stripslashes(isset($_POST['newsintro']) && $_POST['newsintro'] != "" ? $_POST['newsintro'] : 'No Description').'^^';
$newsContent = $imageMode.stripslashes(isset($_POST['newstext']) && $_POST['newstext'] != "" ? $_POST['newstext'] : '<p>'.$newsIntro.'</p>');
$f = fopen('pages/'.$filename.'.txt',"w+");
fwrite($f,$newsTitle."\n");
fwrite($f,$submitDate."\n");
fwrite($f,$newsIntro."\n");
fwrite($f,$newsContent."\n");
fclose($f);
Reload(1, '');
}
if(isset($_REQUEST['blog']) && $_REQUEST['blog'] == "New Entry" && $config['blogMode'] == true && Page == $config['blogSpace'] &&
@array_key_exists($_SESSION["logged"], $user)){
echo '<h2>New Entry <span style="font-size:x-small"><a href="?page='.Page.'">back</a></span></h2>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="form-table"><tr><td>
<form action="'.$_SERVER['PHP_SELF'].'?page='.Page.'" method="post" enctype="multipart/form-data">
Title:<br/><input type="text" name="newstitle" size="40"/>';
if($config['blogMini'] == true){
echo '<br />Intro(Optional):<textarea name="newsintro" rows="4"></textarea>';
}
echo '<br />Post:<br /><script type="text/javascript">edToolbar(\'newstext\');</script>
<textarea id="newstext" name="newstext" rows="10"></textarea><br />Image: <input type="file" name="upload_file" />
<input type="submit" name="blog" value="Save" /></form></td></tr></table>';
}
}
//DISQUS Commenting
if(Page != $config['blogSpace'] && preg_match("/^".$config['blogSpace']."_[0-9]/", Page) && !isset($_REQUEST['act']) && $config['blogComments'] == true){
if(is_file($full) && !is_dir($full) && file_exists($full)){
echo '<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_url = "'.Self.'/?page='.Page.'";
var disqus_title = "'.title($config, Page).'";
</script>
<script type="text/javascript" src="http://disqus.com/forums/'.$config['DISQUS'].'/embed.js"></script>
<noscript><a href="http://ameoto.disqus.com/?url=ref">View the discussion thread.</a></noscript>';
}
}} ?>