PHP Classes

File: blogapp.php

Recommend this page to a friend!
  Classes of johno dread   To michael   blogapp.php   Download  
File: blogapp.php
Role: Application script
Content type: text/plain
Description: Index file
Class: To michael
Retrieve blog posts from a text file
Author: By
Last change: $fp = fopen($msg->fp, "a+") corrected to be

$fp = fopen($msg->blogs, "a+");
Date: 14 years ago
Size: 4,819 bytes
 

Contents

Class file image Download
<?php
/**
 * @author Johno dread
 * @copyright 2009
 * @purpose
 * Works on Firefox than IE and was not tested on other browsers
 * Stores and retrieve blogs using a text file instead of a database. Each message gets appended to the existing text file in a single line.
   Each line will be formated so that the message body is preceeded by the writer's name then preceeded by the topic,
   each post is then parsed and show each topic as a link to the message body.
*/

require ("msg.php");


if(isset(
$_POST)&& (count($_POST)== 3))

$person = trim($_POST['person']);
$mesg = str_replace("\n"," ", trim($_POST['message']));

// The "[" character is reserved, so incase it is included in a post text it's replace it.
$mesg = str_replace("[" , "|", $mesg);
$topic = trim($_POST['topic']);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
    var body = '';
      $(document).ready(function()
      {
        $("#show").click(function()
        {
            $("#block").html('<form action="Blog app.php" method="post"><label id="title">Title:</label> <input id="topic" type="text" name="topic" size="40" maxlength="80" value=""><br> <label id="user">Name:</label> <input id="name" type="text" name="person" size="40" maxlength="80" value=""><br><label>Your tribute:</label> <textarea name="message" rows="3" cols="40"></textarea><br /><input id="send" type="submit" value="Send/refresh"> </form>');

          });
    });
 
</script>

<style type="text/css">

<!--
BODY.
 
{color: black; font-family: verdana; font-size: 10 pt;} -->

H1{ color: red; font-family: arial; font-size: 12 pt;}

hr{color:#D6D3D6;}

#title{width: 20%;}
#user{width: 20%; margin-right: 20px;}

#rollup{height: 300px; width: 200px; overflow-x: hidden; overflow: scroll;}

#name{ margin-left: 16px;}

#topic{ margin-left: 50px;}

#block{width:50%; }

a{text-decoration: none;}
</style>
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=10 WIDTH=100% HEIGHT=50%>
    <TR>
        <TD BGCOLOR="#F0F8FF" ALIGN=CENTER VALIGN=TOP WIDTH=150 id = "topic">
        <h3>Tributes</h3>
        <div id="rollup">
        <?php
       
       
        $msg
= new msg($blog='');
           
//print_r($msg->getTopics());
       
$topics = array_unique($msg->getTopics());
             
         
// read the array such that the lates posts appear first.
       
$topics = array_reverse($topics);
       
$i = 1;
        foreach(
$topics as $v)
        {
            echo
'<a href="Blog app.php?t='.$v.'" id='.$i.'">'.$v.'</a>';
           
$writer = $msg->getWriter($v);
            
            foreach(
$writer as $key=>$val)
            {
                echo
"<div style='font-size:8pt;text-align:right;'>By: ".$val."</div>";
                echo
"<div style='font-size:8pt;float:right;color:#B8CDE1'>".$key ."</div>";
                break;
            }
              echo
"<div style='font-size:8pt; float:left'>".$entered."</div>";
              echo
"<br /><hr>";
             
$i++;
        }
             
       
?>
</div>
        </TD>
        <TD BGCOLOR="#E5EECC" ALIGN=LEFT VALIGN=TOP WIDTH=83%>
            <H1> Tribute to Michael</H1>
                <P> Click tributes to the left to view its contents <BR>
                    OR click below to contribute.
                </P>
                    <input id="show" type="button" value="Pay tribute">
                <p id="block">
            <?php
               
if(isset($_GET[t]) && $_GET[t] !=' ')
                {
                   
$body = strip_tags(trim($msg->getBody($_GET[t])));
                    echo
$body;
                }
           
?>
</p>
        </TD>
    </TR>
</TABLE>

<?php
// Add message

if ($mesg != "" && $topic != "" && $person!="")
    {
       
$date = date('M j Y');
       
$seg = $msg->msglen($mesg);
       
$fp = fopen($msg->blogs, "a+");
       
$fw = fwrite($fp, "<b>$topic ~ </b>$person -$seg- [ $date]\n");
       
fclose($fp);
    }


// $max_store_size is the maximum file size the msg.txt file can reach, this case: 100,000 bytes = 100Kb
$max_store_size = 100000;

// check if file size is over maximum
$file_size= filesize($msg->blogs);

/* If file size is more than allowed then reads last 10 messages (last lines of msg.txt file)and stores them in $lines array
    then deletes the "old" msg.txt file and create a new msg.txt pushing the "old" messages stored in $lines array into
    the "new" msg.txt file using $msg_old.
*/
           
if ($file_size > $max_store_size)
{
   
// reads file and stores each line $lines' array elements
   
   
$lines = file($msg->fp);
   
   
$a = count($lines);
   
   
$u = $a - 10; // we will remove the ten oldest messages from storage
   
   
array_reverse($lines);
    for(
$i=0; $i<$u;$i++)
    {
           
$msg_old .= $lines[$i]."\n";
    }
   
   
$deleted = unlink($msg->blogs);
   
$fp = fopen($msg->blogs, "a+");
   
$fw = fwrite($fp, $msg_old);
   
fclose($fp);
}
?>
</body>
</html>