Помогни ни да направим Uroci.net по - богат! Добави урок

Добавяне на новини и коментари към тях

PHP » PHP
House   трудност:    видян: 14074

В този мой втори урок ще ви покажа как да направите система за добавяне на новини и коментари към тях. Към коментарите има и smileys.

Като за начало направете 1 обща папка,в моя случай се казва phpwebnews. В нея направете още 2 папки-admin и smileys.В папката smielys се знае какво да сложите(накрая на урока ще ви дам линк към всички файлове).В главната папка слагате файловете ;addcomment.php;showsmileys.php;
webnews.badwords.inc.php;webnews.config.inc.php;webnews.php и webnews.smileys.inc.php


addcomment.php

Код
<?php 
////////////////////////////////////////////////////////////////////// 
// PHPWebNews - sebflipper Copyright 2002 // 
// http://www.sebflipper.com // 
// Main Script File // 
// // 
// Please DO NOT edit this file unless you know what you are doing // 
// // 
// By using this script you agree to the Licence // 
// // 
////////////////////////////////////////////////////////////////////// 


// Beginning php 

// Loading Config file 
require dirname(__FILE__)."/webnews.config.inc.php"; 
// include ("webnews.config.inc.php"); 

// Turns off error messages 
error_reporting (E_ERROR | E_PARSE); 

// Connecting to server database 
$db = mysql_connect("$server", "$db_user", "$db_pass"); 
mysql_select_db("$database",$db); 


// If they have sent the comments form 
if ($save_comment==true) { 
// Stripping any bad stuff 
$name = htmlspecialchars($name); 
$email = htmlspecialchars($email); 
$comment = htmlspecialchars($comment); 

$name=trim($name); 
$email=trim($email); 
$comment=trim($comment); 

// Making sure the form is not blank 
if ($name==FALSE || $email==FALSE || $comment==FALSE || $id_for==FALSE) 
{ 
echo "<html><meta http-equiv='refresh' content='0;URL=javascript:history.back()'><body><script>alert('Please fill out the required fields')</script></body></html>"; 
exit; 
} 

// Making sure that details are the correct size 
if(strlen($name)<2 || strlen($name) >25) 
{ 
echo "<html><meta http-equiv='refresh' content='0;URL=javascript:history.back()'><body><script>alert('Please correct your name')</script></body></html>"; 
exit; 
} 

if(strlen($email)<2 || strlen($email) >80) 
{ 
echo "<html><meta http-equiv='refresh' content='0;URL=javascript:history.back()'><body><script>alert('Please correct your email address')</script></body></html>"; 
exit; 
} 

if(strlen($comment)<2 || strlen($comment) >1000) 
{ 
echo "<html><meta http-equiv='refresh' content='0;URL=javascript:history.back()'><body><script>alert('Please correct your comment (1000 char max)')</script></body></html>"; 
exit; 
} 

// Checking if they have a cookie to stop spaming! 
if ($phpwebnews[spam]==true) 
{ 
echo "<html><meta http-equiv='refresh' content='0;URL=javascript:history.back()'><body><script>alert('You can only send 1 comment every $spam_time_english')</script></body></html>"; 
exit; 
} 

// Error checking ok 
// Setting cookie to stop users spaming 
setcookie("phpwebnews[spam]",spam,time()+$spam_time_out); 

// Get date and time 
$timeadjust = ($hourdiff * 60 * 60); // Changing the $hourdiff into sec's for UNIX time stamp 
$melbdate = (mktime() + $timeadjust);; 

// Save to database 
mysql_select_db("$database",$db); 
$sql = "INSERT $mysql_pre$mysql_comments SET id_for='$id_for',name='$name',date='$melbdate',email='$email',comments='$comment'"; 


$result = mysql_query($sql) or die(mysql_error()); ; 


// Echoing sent 
echo "<html><meta http-equiv='refresh' content='0;URL=$mainurl'><body><script>alert('Thank you, your comment has been saved')</script></body></html>"; 
exit; 
} 
?>

showsmileys.php

Код
<?php 
////////////////////////////////////////////////////////////////////// 
// PHPWebNews - sebflipper Copyright 2002 // 
// http://www.sebflipper.com // 
// Main Script File // 
// // 
// Please DO NOT edit this file unless you know what you are doing // 
// // 
// By using this script you agree to the Licence // 
// // 
////////////////////////////////////////////////////////////////////// 


// Beginning php 

// Loading Config file 
require dirname(__FILE__)."/webnews.config.inc.php"; 
?> 
<html> 
<head> 
<title>Smileys!</title> 
<script language="JavaScript"> 
<!-- 
function MM_findObj(n, d) { //v4.0 
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
if(!x && document.getElementById) x=document.getElementById(n); return x; 
} 

function MM_setTextOfTextfield(objName,x,newText) { //v3.0 
var obj = MM_findObj(objName); if (obj) obj.value = newText; 
} 

function x() { return; } 

function insertEmoticon(addSmilie) { 
var addSmilie; var revisedMessage; 
var currentMessage = window.opener.document.sbx.shout.value; 
revisedMessage = currentMessage+addSmilie; 
window.opener.document.sbx.shout.value=revisedMessage; 
window.opener.document.sbx.shout.focus(); 
} 
//--> 
</script> 
</head> 
<body> 
<table width="100%" border="0" cellspacing="0" cellpadding="2"> 
<tr align="center" valign="bottom"> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':)');" onMouseOver="MM_setTextOfTextfield('tip','',':)')"><img src='smileys/smile.gif' alt=':)' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':(');" onMouseOver="MM_setTextOfTextfield('tip','',':(')"><img src='smileys/sad.gif' alt=':(' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(';)');" onMouseOver="MM_setTextOfTextfield('tip','',';)')"><img src='smileys/smilewinkgrin.gif' alt=';)' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon('B)');" onMouseOver="MM_setTextOfTextfield('tip','','B)')"><img src='smileys/cool.gif' alt='B)' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':D');" onMouseOver="MM_setTextOfTextfield('tip','',':D')"><img src='smileys/biggrin.gif' alt=':D' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':P');" onMouseOver="MM_setTextOfTextfield('tip','',':P')"><img src='smileys/bigrazz.gif' alt=':P' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':cry:');" onMouseOver="MM_setTextOfTextfield('tip','',':cry:')"><img src='smileys/cry.gif' alt=':cry:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':dead:');" onMouseOver="MM_setTextOfTextfield('tip','',':dead:')"><img src='smileys/dead.gif' alt=':dead:' border="0"></a></td> 
</tr> 
<tr align="center" valign="bottom"> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':laugh:');" onMouseOver="MM_setTextOfTextfield('tip','',':laugh:')"><img src='smileys/laugh.gif' alt=':laugh:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':eek:');" onMouseOver="MM_setTextOfTextfield('tip','',':eek:')"><img src='smileys/bigeek.gif' alt=':eek:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':rolleyes:');" onMouseOver="MM_setTextOfTextfield('tip','',':rolleyes:')"><img src='smileys/rolleyes.gif' alt=':rolleyes:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':mad:');" onMouseOver="MM_setTextOfTextfield('tip','',':mad:')"><img src='smileys/mad.gif' alt=':mad:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':confused:');" onMouseOver="MM_setTextOfTextfield('tip','',':confused:')"><img src='smileys/confusedw.gif' alt=':confused:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':sigh:');" onMouseOver="MM_setTextOfTextfield('tip','',':sigh:')"><img src='smileys/sighw.gif' alt=':sigh:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':yes:');" onMouseOver="MM_setTextOfTextfield('tip','',':yes:')"><img src='smileys/yes.gif' alt=':yes:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':no:');" onMouseOver="MM_setTextOfTextfield('tip','',':no:')"><img src='smileys/no.gif' alt=':no:' border="0"></a></td> 
</tr> 
<tr align="center" valign="bottom"> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':sleep:');" onMouseOver="MM_setTextOfTextfield('tip','',':sleep:')"><img src='smileys/sleepw.gif' alt=':sleep:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':upset:');" onMouseOver="MM_setTextOfTextfield('tip','',':upset:')"><img src='smileys/upsetw.gif' alt=':upset:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':shy:');" onMouseOver="MM_setTextOfTextfield('tip','',':shy:')"><img src='smileys/shy.gif' alt=':shy:' border="0"></a></td> 
<td width="12%"><a href="javascript:x();" onClick="insertEmoticon(':|');" onMouseOver="MM_setTextOfTextfield('tip','',':|')"><img src='smileys/none.gif' alt=':|' border="0"></a></td> 
<td colspan="4" align="center"> 
<input type="text" name="tip" size="15" class="editbox" READONLY value="choose a pic"> 
</td> 
</tr> 
</table> 
<?php 
// Print version - Please keep the line(s) below - NOTISE: REMOVING THE LINE(S) BELOW BRECHES THE LICENCE AGREEMENT 
echo("n<br><center><font face='Verdana, Verdana, arial, sans-serif, sans-serif' size='1'>News powered by <a href='http://www.sebflipper.com' target='_blank'>PHPWebNews</a> $webnews_ver</font></center><br>n"); 
?> 
</body> 
</html>


Страници: 1 2 3 4 »

Коментари (2)

wesels12 на 28.01 2011 в 09:27ч.
може ли да дадеш друг линк за сваляне, защото този не работи
xXRonBoyBgXx на 22.12 2015 в 16:15ч.
Не е нужно - копвай!

Регистрирайте се, за да добавите коментар


Калдейта ЕООД - © 2003-2010. Всички права запазени.
Препоръчваме: Национален Бизнес | Bomba.bg | IT Новини | Диплома.бг | TRAVEL туризъм | Реферати | AmAm.bg | Иде.ли | Курсови работи | Фото Форум | Spodeli.net | Фото-Култ | Atol.bg | Elmaz.com | MobileBulgaria.com | Казанлък.Com