Location: PHPKode > projects > Free Blog Creator > freeblog/base.php
<?php
require("header.php");
?>
<script language="JavaScript" type="text/javascript" src="ed/wysiwyg.js"></script>
Menu &gt; Write a new entry<br><br><br>


<?php
$sid = $_GET['sid'];
$entryym = $_GET['entryym'];

if((!$_POST["submit"]) && (!$_POST["preview"]) && ($sid)){

$year = substr($entryym, 0, 4);
$Log=@file("./log/entry/$year.cgi");
for($i=0;$i<sizeof($Log);$i++){
$line=explode("<>",$Log[$i]);
if($line[0]==$sid){
$name=$line[1];
$base=$line[2];
$status=$line[3];
$comment=$line[4];
$trackback=$line[5];
$datetime=$line[6];
$year=$line[7];
$entryym=$line[8];
$track=$line[9];
$track=str_replace("<br />","\n",$track);
$base=base64_decode($base);
break;
}
}

}
?>
<?php
if((!$_POST["submit"]) && (!$_POST["preview"]) && (!$sid)){

$Log=@file("./log/basic.cgi");
$line=explode(",",$Log[0]);
$url=$line[0];
$url2=$line[1];
$daytime=$line[2];
$blogname=$line[3];
$status=$line[4];
$comment=$line[5];
$trackback=$line[6];
$send=$line[7];
if($daytime==""){
$daytime="-7";
}
$daytime = strtotime("$daytime hours");

}
?>


<?php
if($_POST["submit"] || $_POST["preview"]){


if($_POST['name'] == '') {
$preview1 .= 'Please enter Title.<br>';
$flag = 1;
}
if($_POST['base'] == '') {
$preview1 .= 'Please enter Content.<br>';
$flag = 1;
}
//$format = '%Y-%m-%d %H:%M:%S';
$format = '%Y-%m-%d %H:%M';
$date = strptime($_POST['datetime'], $format);
if($date == false){
$preview1 .= 'Date/Time seems invalid.<br>';
$flag = 1;
}


$err = '';
if($preview1 != '') {
$err .= $preview1;
$flag = 1;
}
}
?>
<?php
if($_POST["submit"] || $_POST["preview"] || $_POST["back"]){
$sid=$_POST['sid'];
$entryym=$_POST['entryym'];
$name=$_POST["name"];
$base=$_POST["base"];
$ping=$_POST["ping"];
$track=$_POST["track"];
$status=$_POST["status"];
$datetime=$_POST["datetime"];
$comment=$_POST["comment"];
$trackback=$_POST["trackback"];
}
?>

<?php
if (!$flag){
if($_POST["submit"]){

$name = strip_tags($name);

if ($status == 2){

$Log=@file("./log/basic.cgi");
$line=explode(",",$Log[0]);
$sName=$line[3];
$send=$line[7];

$httphost= str_replace(basename(__FILE__),"",'http://'.$_SERVER["HTTP_HOST"].$_SERVER[PHP_SELF])."";


if ($ping){
$client_url = $httphost."?id=".$sid;
$title = $name;
$excerpt = $base;
$blog_name = $sName;
$blog_name = htmlspecialchars($blog_name);
$blog_name = stripslashes($blog_name);
$title = htmlspecialchars($title);
$title = stripslashes($title);
$client_url = htmlspecialchars($client_url);
$client_url = stripslashes($client_url);
 
$excerpt = str_replace( "<br>",  "\r\n", $excerpt); 
$excerpt = str_replace( "<br />",  "\r\n", $excerpt);

$excerpt = strip_tags($excerpt);
$excerpt = htmlspecialchars($excerpt);
$excerpt = stripslashes($excerpt);

if (strlen($excerpt) > 255) {
$excerpt = substr($excerpt,0,255);
}
$title=mb_convert_encoding($title, "UTF-8", "auto");
$excerpt=mb_convert_encoding($excerpt, "UTF-8", "auto");
$blog_name=mb_convert_encoding($blog_name, "UTF-8", "auto");

$post = "title=".urlencode($title)."&url=".$client_url."&excerpt=".urlencode($excerpt)."&blog_name=".urlencode($blog_name)."&charset=utf-8";

$ping = preg_replace("/[\n\r]$/","", $ping);
$ping_urls = explode("\n", $ping);

for($i=0; $i<5; $i++){
$pattern = '#(^|[^\"\'=\]])(http|HTTP|ftp)(s|S)?://((([^\s<>\.]+)\.)+[^\s<>\.]+)#sm';
if (preg_match($pattern,$ping_urls[$i])) {

$ping = parse_url($ping_urls[$i]);
$head  = "POST ".$ping_urls[$i]." HTTP/1.0\r\n";
$head .= "Host: ".$ping['host']."\r\n";
$head .= "User-Agent:blog-trackback\r\n";
$head .= "Content-Type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: ".strlen($post)."\r\n";
$head .= "\r\n";
$head .= $post."\r\n";
if (!$ping["port"]) {
$ping["port"] = 80;
}
$fp = fsockopen($ping["host"], $ping["port"], $errno, $errstr, 10);
if ($fp) {
fputs ($fp, $head);
$res = "";
while(!feof($fp)) {
$res = $res . fgets($fp, 4096);
}
fclose($fp);

list($head, $body) = split("\r\n\r\n", $res, 2 );
if( strstr( $body, "<error>0</error>") != FALSE ){
$track .= "Success&nbsp;:&nbsp;".$ping_urls[$i]."<br />";
}
elseif( strstr( $body, "<error>1</error>") != FALSE ){
$track .= "Failure&nbsp;:&nbsp;".$ping_urls[$i]."<br />";
}
else{
$track .= "Unknown&nbsp;:&nbsp;".$ping_urls[$i]."<br />";
}

}
}
}
}
}

$base = ereg_replace("(https?|ftp)(://[[:alnum:]\+\$\;\?\.%,!#~*/:@&=_-]+)", "<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>" , $base);
$base=base64_encode($base);


switch (true) 
{

case ($sid!=NULL):

$year = substr($entryym, 0, 4);
$lines=array("$sid","$name","$base","$status","$comment","$trackback","$datetime","$year","$entryym","$track","1");
$lines=implode("<>",$lines);
$lines=$lines."\n";

$Log=file("./log/entry/$year.cgi");
for($i=0;$i<sizeof($Log);$i++){
$line=explode("<>",$Log[$i]);
if($line[0]==$sid){

array_splice($Log,$i,1,$lines);

}
}
$fp=fopen("./log/entry/$year.cgi","w");
flock($fp, LOCK_EX);
foreach($Log as $line)fputs($fp,$line);	
fclose($fp); 

$type=1;

break;


case ($sid==NULL):

$year= date("Y");
$entryym= date("Ym");
$ID=1;
$Log=@file("./log/entry/$year.cgi");
for($i=0;$i<sizeof($Log);$i++){
$line=explode("<>",$Log[$i]);
if($line[0]>=$ID)
$ID=$line[0]+1;
}
$ID=$ID.$year;
$lines=array("$ID","$name","$base","$status","$comment","$trackback","$datetime","$year","$entryym","$track","1");
$lines=implode("<>",$lines);
$lines=$lines."\n";


$fp=fopen("./log/entry/$year.cgi","a");
fputs($fp,$lines);	
fclose($fp);
chmod("./log/entry/$year.cgi",0666);

$sid=$ID;
$type=3;

break;

}


$base=base64_decode($base);



if ($status == 2){

$sline = explode("<br />",$send);
for($s = 0; $s < count($sline); $s++) {
$pattern = '#(^|[^\"\'=\]])(http|HTTP|ftp)(s|S)?://((([^\s<>\.]+)\.)+[^\s<>\.]+)#sm';
if (preg_match($pattern,$sline[$s])) {
$server = "$sline[$s]";

$arr = parse_url($server);
$host = $arr["host"];
$path = $arr["path"];

$bname = "$sName";
$index = $httphost;
$html = $httphost."?id=".$sid;

  if (!$sock = @fsockopen($host , 80 , $errNo , $errStr , 3)){
    print "Failure to open socket [update notification]\n"; exit(1);
  }

$str = "";
$str .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
$str .= "<methodCall>\r\n";
$str .= "<methodName>weblogUpdates.ping</methodName>\r\n";
$str .= "<params>\r\n";
$str .= "<param>\r\n";
$str .= "<value>$bname</value>\r\n";
$str .= "</param>\r\n";
$str .= "<param>\r\n";
$str .= "<value>$index</value>\r\n";
$str .= "</param>\r\n";
$str .= "<param>\r\n";
$str .= "<value>$html</value>\r\n";
$str .= "</param>\r\n";
$str .= "</params>\r\n";
$str .= "</methodCall>\r\n";

  $head .= "POST " . $path . " HTTP/1.1\r\n";
  $head .= "Host: $host\r\n";
  $head .= "Content-type: text/xml\r\n";
  $head .= "Content-length: " . strlen($str) . "\r\n";
  $head .= "\r\n";
  $head .= "$str\r\n";

$head=mb_convert_encoding($head, "UTF-8", "auto");

  fputs($sock , $head);

$res = "";
while(!feof($sock)) {
$res = $res . fgets($sock);
}
fclose($sock);

list($head, $body) = split("\r\n\r\n", $res, 2 );

if( strstr( $body, "<boolean>0</boolean>") != FALSE ){
$err="Success update notification<br>";
}
else{
$err="Failure update notification<br>";
}
print $err;
}
}

}

$track=str_replace("<br />","\n",$track);


if($type==1){
print "Updated<br><br>";
}
if($type==3){
print "Saved<br><br>";
}



}
}
?>




<?=$err?>
<br>
<?php
if(!$_POST["preview"]){
?>



<form action="" method="POST" name="opinion">

<b>Title</b><br />
<input size='40' type='text' name='name' value=<?=$name?>></input><br />
<br />
<b>Content</b><br />


<script type="text/javascript" language="javascript">
<!--
document.open();
document.write("<div align=\"right\" style=\"display:none;width: 300px;\">");
document.write("<span id=\"HTMLModeinputbase\"><a href=\"javascript:void(0);\" onclick=\"viewSource('inputbase');\"><img src=\"images/switch.gif\" alt=\"Change editor\" border=\"0\"></a></span>");
document.write("<span id=\"textModeinputbase\"><a href=\"javascript:void(0);\" onclick=\"viewText('inputbase');\"><img src=\"images/switch.gif\" alt=\"Change editor\" border=\"0\"></a></span>");
document.write("</div>");
document.close();
// -->
</script>


<script type="text/javascript" language="javascript">
<!--
document.open();
document.write("<span id=\"textMoinputbase\">");
document.write("<div class=\"menubar\" style=\"display:none\">");
document.write("<span class=\"menubutton\" onclick=\"largeThis()\">");
document.write("<img src=\"images/caseupper.gif\" alt=\"Upper Case\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"xsmallThis()\">");
document.write("<img src=\"images/caselower.gif\" alt=\"Lower Case\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"boldThis()\">");
document.write("<img src=\"images/bold.gif\" alt=\"Bold\" align=\"absmiddle\" width=\"18\" height=\"18\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"italicThis()\">");
document.write("<img src=\"images/italic.gif\" alt=\"Italic\" align=\"absmiddle\" width=\"18\" height=\"18\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"sThis()\">");
document.write("<img src=\"images/strikeout.gif\" alt=\"Strikethrough\" align=\"absmiddle\" width=\"18\" height=\"18\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"uThis()\">");
document.write("<img src=\"images/underline.gif\" alt=\"Underline\" align=\"absmiddle\" width=\"18\" height=\"18\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"alignleftThis()\">");
document.write("<img src=\"images/alignleft.gif\" alt=\"Justifyleft\" align=\"absmiddle\" width=\"18\" height=\"18\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"aligncenterThis()\">");
document.write("<img src=\"images/aligncenter.gif\" alt=\"Justifycenter\" align=\"absmiddle\" width=\"18\" height=\"18\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"alignrightThis()\">");
document.write("<img src=\"images/alignright.gif\" alt=\"Justifyright\" align=\"absmiddle\" width=\"18\" height=\"18\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"blockThis()\">");
document.write("<img src=\"images/quit.gif\" alt=\"Quotation\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"leftThis()\">");
document.write("<img src=\"images/left.gif\" alt=\"&lt;\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"rightThis()\">");
document.write("<img src=\"images/right.gif\" alt=\"&gt;\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"addColor()\">");
document.write("<img src=\"images/selectcolor.gif\" alt=\"Color Code\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"addMedia()\">");
document.write("<img src=\"images/media.gif\" alt=\"Upload\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("<span class=\"menubutton\" onclick=\"ahrefThis()\">");
document.write("<img src=\"images/link.gif\" alt=\"CreateLink\" align=\"absmiddle\"/>");
document.write("</span>");
document.write("</div>");
document.write("</span>");
document.close();
// -->
</script>


<textarea 
                name="base" id="inputbase" 
                onkeyup="storeCaret(this); updPreview('base');"
                onclick="storeCaret(this);"
                onselect="storeCaret(this);" 
                tabindex="20" cols=40 rows=18><?=$base?>
</textarea>


<script language="javascript1.2">
  generate_wysiwyg('inputbase');
</script>


<br><br>
<b>Trackback</b><br />
<textarea name="ping" rows ="2" cols="30" style="ime-mode:disabled;"></textarea><br />
<b>Sent trackbacks</b><br />
<textarea name="track" rows="2" cols="30" wrap="off" READONLY><?=$track?></textarea>
<br /><br />
<b>Post type</b><br />
<select name="status">
<?php
if($status==1){
$statusSelected1="selected";
}
if(($status==2)||($status=="")){
$statusSelected2="selected";
}
?>
<option value="1" <?=$statusSelected1?>>Draft</option>
<option value="2" <?=$statusSelected2?>>Public</option>
</select>
<br />
<?php
if(!$datetime){
$datetime= date("Y-m-d H:i", $daytime);
}
?>
<b>Date/Time</b><br />
<input maxlength="20" size="20" value="<?=$datetime?>"  name="datetime"  style="ime-mode: disabled;"><br />
<br />
<b>Comments</b><br />
<select name="comment">
<?php
if(($comment==1)||($comment=="")){
$commentSelected1="selected";
}
else{
$commentSelected0="selected";
}
?>
<option value="1" <?=$commentSelected1?>>Accept</option>
<option value="0" <?=$commentSelected0?>>Not accept</option>
</select><br />
<br />
<b>Trackbacks</b><br />
<select name="trackback">
<?php
if(($trackback==1)||($trackback=="")){
$trackbackSelected1="selected";
}
else{
$trackbackSelected0="selected";
}
?>
<option value="1" <?=$trackbackSelected1?>>Accept</option>
<option value="0" <?=$trackbackSelected0?>>Not accept</option>
</select><br />
<input type="hidden" name="sid" value="<?=$sid?>"></input>
<input type="hidden" name="entryym" value="<?=$entryym?>"></input>
<br />

<br/><br/><br/>
<div align="center">
<input type="submit" name="preview" value="Confirm"><br />
<br />
<input type="submit" name="submit" value="Save">
</div>
</form>

<?php
}
?>



<?php
if (!$flag){
if($_POST["preview"]){
?>
<form action="" method="POST" name="opinio">

<b>Title</b><br /><?=$name?><br />
<input type="hidden" name="name" value=<?=$name?>></input>

<b>Content</b><br /><?=$base?><br />
<input type="hidden" name="base" value=<?=$base?>></input>

<b>Trackback</b><br /><?=$ping?><br />
<input type="hidden" name="ping" value=<?=$ping?>></input>
<?php
if($status==1){
$stat="Draft";
}
if($status==2){
$stat="Public";
}
?>
<b>Post type</b><br /><?=$stat?><br />
<input type="hidden" name="status" value="<?=$status?>"></input>
<b>Date/Time</b><br /><?=$datetime?><br />
<input type="hidden" name="datetime" value="<?=$datetime?>"></input>

<?php
if($comment==0){
$commen="Not accept";
}
else{
$commen="Accept";
}
?>
<b>Comments</b><br /><?=$commen?><br />
<input type="hidden" name="comment" value="<?=$comment?>"></input>
<?php
if($trackback==0){
$track="Not accept";
}
else{
$track="Accept";
}
?>
<b>Trackbacks</b><br /><?=$track?><br />
<input type="hidden" name="trackback" value="<?=$trackback?>"></input>

<input type="hidden" name="sid" value="<?=$sid?>"></input>
<input type="hidden" name="entryym" value="<?=$entryym?>"></input>


<br />
<br><div align="center"><input type="submit" name="back" value="Rewrite"><br />
<br />
<input type="submit" name="submit" value="Save"></div></form>

<?php
}
}
?>



<?php
require("footer.php");
?>
Return current item: Free Blog Creator