Code similar To Netease 163 News Comment Building

Source: Internet
Author: User

Code similar To Netease 163 News Comment Building

// Send a message

Require ("global. func. php tutorial ");
$ Fid = isset ($ _ GET ["id"])? Intval ($ _ GET ["id"]): 0;
$ Page = isset ($ _ GET ["page"])? Intval ($ _ GET ["page"]): 1;
If ($ _ SERVER ["REQUEST_METHOD"] = "POST ")
{
If (! File_exists ("1.php "))
{
WriteFile ("1.php", $ array = array ());
}
$ Arr = require ("1.php ");
$ Post = array ();
Unset ($ _ POST ["Submit"]);
Foreach ($ _ POST as $ k => $ v)
{
$ Post [$ k] = addslashes (htmlspecialchars ($ v ));
}
$ Post ["content"] = str_replace ("n", "<br>", $ post ["content"]);
$ Post ["id"] = count ($ arr) + 1;
$ Post ["date"] = time ();
$ Post ["fid"] = $ fid;
$ Post ["ip"] = $ _ SERVER ["REMOTE_ADDR"];
$ Arr [] = $ post;

WriteFile ("1.php", $ arr );
 
Echo "<script> location. href =" index. php? Page = $ page "</script> ";
Exit;
}
?>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> post </title>
<Script>
Var arr = new Array ();

Function ckusername ()
{
If (document. form1.username. value. length <3)
{
Document. getElementById ("user_msg"). innerHTML = "<font color =" red "> <B> the user name cannot be less than 3 characters </B> </font> ";
Arr [0] = 1;
} Else
{
Document. getElementById ("user_msg"). innerHTML = "<font color =" green "> <B> √ </B> </font> ";
Arr [0] = 0;
}


}
Function ckcontent ()
{

If (document. form1.content. value. length <8 | document. form1.content. value. length> 255)
{
Document. getElementById ("content_msg"). innerHTML = "<font color =" red "> <B> content 8-characters </B> </font> ";
Arr [1] = 1;
} Else
{
Document. getElementById ("content_msg"). innerHTML = "<font color =" green "> <B> √ </B> </font> ";
Arr [1] = 0;
}
}

Function c ()
{
If (arr. length <2)
{
Return false;
}
For (x in arr)
{
If (arr [x] = 1)
{
Return false;
}
}

Form1.submit ();

}

</Script>
</Head>
<Body>
<Form name = "form1" method = "post" action = "">
<Table width = "100%" border = "0">
<Tr>
<Td> User
<Input name = "username" type = "text" id = "id" onBlur = "ckusername ()"> </td>
</Tr>
<Tr>
<Td> <div id = "user_msg"> </div>
</Td>
</Tr>
<Tr>
<Td> <textarea name = "content" cols = "100" rows = "6" id = "content" onBlur = "ckcontent () "> </textarea> </td>
</Tr>
<Tr>
<Td> <div id = "content_msg"> </div>
</Td>
</Tr>
<Tr>
<Td> <div align = "center">
<Input type = "button" name = "Submit" value = "Submit" onClick = "c ();">
</Div> </td>
</Tr>
</Table>
</Form>
</Body>

</Html>

<? Php
Ini_set ("display_errors", 0 );
Require ("global. func. php ");
?>

Show comments like 163
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.bkjia.com/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Style>
. B {
Border: 1px dotted # e3e3e3;
Word-wrap: break-word;
Word-break: break-all;
}


</Style>

<Title> PPC standby Forum (recurrence limit: 15 layers + topic) </title>
</Head>
<Body>
<? Php
Echo "<a href =" post. php? Page = 1 "> post </a> <br> ";
If (file_exists ("1.php "))
{
$ __Array = require ("1.php ");
}
Else
{
$ __Array = array ();
}
$ Page = isset ($ _ GET ["page"])? Intval ($ _ GET ["page"]): 1;
$ Pagesize = 5;
$ Offset = ($ page-1) * $ pagesize;
$ __Str = "";
Function getTotal ()
{
Global $ __array;
$ I = 0;
Foreach ($ __array as $ k => $ v)
{
If ($ v ["fid"] = 0)
{
$ I = $ I + 1;
}
}
Return $ I;
}
Function getFid0 ()
{
Global $ __array, $ __str;
 
Foreach ($ __array as $ k => $ v)
{
If ($ v ["fid"] = 0)
{
$ Fid0 [] = $ v;
}

}
Return array_reverse ($ fid0 );
}
$ Fid0 = getFid0 ();
Function show ($ fid0, $ pagesize, $ offset)
{
Global $ __str, $ page;
Foreach (array_slice ($ fid0, $ offset, $ pagesize, true) as $ k => $ v)
{

$ __Str. = "<blockquote class =" B "> <p> ";
$ __Str. = $ v ["ip"]. "User :". $ v ["username"]. "content :". $ v ["content"]. "<a id =" a1 "href =" post. php? Id = ". $ v [" id "]." & page = $ page "> reply </a> ";
ShowChild ($ v ["id"]);
$ __Str. = "</p> </blockquote> ";



}
}

Function showChild ($ id, $ I = 0)
{
Global $ __array, $ __str, $ page, $ offset;
 
 
If ($ I = 15) // recursive Layers
{
Return;
}
$ I ++;
Foreach ($ __array as $ k => $ v)
{
If ($ v ["fid"] = $ id)
{
$ __Str. = "<blockquote class =" B "> <p id =" a1 "> ";
$ __Str. =__ __array [$ k] ["ip"]. "User :". $ __array [$ k] ["username"]. "content :". $ __array [$ k] ["content"]. "<a href =" post. php? Id = ". $ v [" id "]." & page = $ page "> reply </a> ";
ShowChild ($ v ["id"], $ I );
$ __Str. = "</p> </blockquote> ";
}
}
}

Show ($ fid0, $ pagesize, $ offset );
$ Total = getTotal ();

Echo $ __str;
Pageft ($ total, $ pagesize, "index. php ");
Echo "<br>". $ pagenav;
?>
</Body>
</Html>

The code for the global. func. php file is as follows:

<? Php

Function writeFile ($ id, $ array)
{
$ Content = "<? Php return ". var_export ($ array, true)."?> ";
Return safe_file_put_contents ($ id, $ content );
}
/**
* Writing files
* @ Param string $ filename
* @ Param string $ contents
* @ Return boolean
*/
Function safe_file_put_contents ($ filename, & $ contents)
{
$ Fp = fopen ($ filename, "wb ");
If ($ fp)
{
Flock ($ fp, LOCK_EX );
Fwrite ($ fp, $ contents );
Flock ($ fp, LOCK_UN );
Fclose ($ fp );
Return true;
} Else
{
Return false;
}
}


/**
* Reading files
* @ Param string $ filename
* @ Return $ data | false
*/
Function safe_file_get_contents ($ filename)
{
$ Fp = fopen ($ filename, "rb ");
If ($ fp)
{
Flock ($ fp, LOCK_SH );
Clearstatcache ();
$ Filesize = filesize ($ filename );
If ($ filesize> 0)
{
$ Data = fread ($ fp, $ filesize );
} Else
{
$ Data = false;
}
Flock ($ fp, LOCK_UN );
Fclose ($ fp );
Return $ data;
} Else
{
Return false;
}
}
Function pageft ($ total, $ displaypg = 10, $ url = ''){
Global $ page, $ firstcount, $ pagenav, $ _ SERVER;

$ GLOBALS ["displaypg"] = $ displaypg;

If (! $ Page) $ page = 1;

If (! $ Url) {$ url = $ _ SERVER ["REQUEST_URI"];}

$ Parse_url = parse_url ($ url );
@ $ Url_query = $ parse_url ["query"];
If ($ url_query ){
$ Url_query = ereg_replace ("(^ | &) page = $ page", "", $ url_query );

$ Url = str_replace ($ parse_url ["query"], $ url_query, $ url );

If ($ url_query) $ url. = "& page"; else $ url. = "page ";
} Else {
$ Url. = "? Page ";
}

$ Lastpg = ceil ($ total/$ displaypg );
$ Page = min ($ lastpg, $ page );
$ Prepg = $ page-1;
$ Nextpg = ($ page = $ lastpg? 0: $ page + 1 );
If (! $ Page) $ page = 1;
$ Firstcount = ($ page-1) * $ displaypg;


$ Pagenav. = "<a href = '$ url = 1' class = 's1'> homepage </a> ";
If ($ prepg) $ pagenav. = "<a href = '$ url = $ prepg' class = 's1'> previous page </a>"; else $ pagenav. = "Previous Page ";
If ($ nextpg) $ pagenav. = "<a href = '$ url = $ nextpg' class = 's1'> next page </a>"; else $ pagenav. = "next page ";
$ Pagenav. = "<a href = '$ url = $ lastpg' class = 's1'> last page </a> ";

$ Pagenav. = "to <select name = 'topage' size = '1' onchange = 'window. location =" $ url = "+ this. value'> n ";
For ($ I = 1; $ I <= $ lastpg; $ I ++ ){
If ($ I = $ page) $ pagenav. = "<option value = '$ I' selected> $ I </option> n ";
Else $ pagenav. = "<option value = '$ I'> $ I </option> n ";
}
$ Pagenav. = "</select> page ";
}
?>

// Saved 1. php file number array format, as follows

<? Php return array (
0 =>
Array (
'Username' => 'test ',
'Content' => 'php100. com ',
'Id' => 1,
'Date' => 1253853347,
'Fid' => 0,
'IP' => '2017. 226.2.200 ',
),
1 =>
Array (
'Username' => 'aaaaaaaaad ',
'Content' => 'www .bkjia.com ',
'Id' => 2,
'Date' => 1253857672,
'Fid' => 0,
'IP' => '2017. 226.6.188 ',
),

)?>

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.