Out of Office Message Board on my Intrant Home Page

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Zero20two
Forum Newbie
Posts: 9
Joined: Wed Feb 13, 2008 11:51 am

Out of Office Message Board on my Intrant Home Page

Post by Zero20two »

I am a new php programmer. I am running Sharepoint services for my Intranet but I am designing a new Intranet site. The main function is a message board on our home page that people can post on. Here are the needed fields and functions:

Name
Message
Date Added
Date the message expires - Auto delete itself.

When someone adds a message, it needs to look nice and not take up much space. Is there something already out there or can someone point ,me in the right direction? I have looked at bulliten boards and message boards but that is not helpful. Thanks!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Out of Office Message Board on my Intrant Home Page

Post by Jonah Bron »

UT (un-tested)

Code: Select all

<?php
$xml = new DOMDocument();
$xml->load('posts.xml');
$xml->formatOutput = true;
if (isset($_POST['post'])){
$info['name'] = $_POST['name'];
$info['text'] = $_POST['text'];
$info['title'] = $_POST['title'];
$info['date'] = date('l, d F, y H:i:s');
$info['exp']['date'] = $_POST['d'] .' '. $_POST['m'] .', '. $_POST['y'];
$info['exp']['stamp'] = strtotime($info['exp']['date']);
$new_post = $xml->createElement('post', $info['text']);
$name_attr = $xml->createAttribute('poster');
$title_attr = $xml->createAttribute('title');
$date_attr = $xml->createAttribute('date');
$exp_d_attr = $xml->createAttribute('exp-d');
$exp_s_attr = $xml->createAttribute('exp-s');
$name_attr->appendChild($xml->createTextNode($info['name']));
$title_attr->appendChild($xml->createTextNode($info['title']));
$date_attr->appendChild($xml->createTextNode($info['date']));
$exp_d_attr->appendChild($xml->createTextNode($info['exp']['date']));
$exp_s_attr->appendChild($xml->createTextNode($info['exp']['stamp']));
$new_post->appendChild($name_attr);
$new_post->appendChild($title_attr);
$new_post->appendChild($date_attr);
$new_post->appendChild($exp_d_attr);
$new_post->appendChild($exp_s_attr);
$xml->save('posts.xml');
}
$xml->load('posts.xml');
$posts = array();
foreach ($xml->documentElement->getElementsByTagName('post') as $x_post){
$post = array();
$post['poster'] = $x_post->getAttribute('poster');
$post['text'] = $x_post->nodeValue;
$post['title'] = $x_post->getAttribute('title');
$post['date'] = $x_post->getAttribute('date');
$post['exp-d'] = $x_post->getAttribute('exp-d');
$post['exp-s'] = $x_post->getAttribute('exp-s');
if ($post['exp-s'] < time()){
$xml->documentElement->removeChild($x_post);
}else{
$posts[count($posts)] = $post;
}
}
$xml->save('posts.xml');
?>

Code: Select all

<html>
<head>
<title>Posts</title>
</head>
<body>
<form action="this_page.php" method="post">
<input type="hidden" name="post" value="" />
<input type="text" name="name" value="your name" /><br />
<input type="text" name="title" value="Title" /><br />
<textarea name="text">Your post here</textarea><br />
<input type="text" name="d" value="day" /><br />
<input type="text" name="m" value="month" /><br />
<input type="text" name="y" value="2008" /><br />
<input type="submit" value="Post" />
</form>

Code: Select all

<?php
$posts = array_reverse($posts);
foreach ($posts as $post){
echo '<div><strong>'. $post['title'] .'</strong> by '. $post['poster'] .' on '. $post['date'] .', expires '. $post['exp-d'] .'
<p>'. $post['text'] .'</p></div>
';
}
?>

Code: Select all

</body>
</html>
Zero20two
Forum Newbie
Posts: 9
Joined: Wed Feb 13, 2008 11:51 am

Re: Out of Office Message Board on my Intrant Home Page

Post by Zero20two »

This is a great start! I am very new to xml though. Does all of this code go into the same page? Where does the post.xml come from? Can you give me a little more guidance? Thank you!
Zero20two
Forum Newbie
Posts: 9
Joined: Wed Feb 13, 2008 11:51 am

Re: Out of Office Message Board on my Intrant Home Page

Post by Zero20two »

I created an xml doc called posts.xml and placed the <?xml version="1.0"?> tag in it.
Now I get an error:
Warning: DOMDocument::load() [function.DOMDocument-load]: Start tag expected, '<' not found in file:///C%3A/Program%20Files/Apache%20Software%20Foundation/Apache2.2/htdocs/posts.xml, line: 2 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\addannounce.php on line 3

Any ideas?
Post Reply