Advertisement
Guest User

Réseau social (Alexandre Bali)

a guest
Feb 20th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.69 KB | None | 0 0
  1. //index.php      : lignes 006 à 075
  2. //like.php       : lignes 078 à 093
  3. //styles-res.css : lignes 096 à 127
  4.  
  5. //index.php
  6. <!doctype html>
  7. <html>
  8.     <head>
  9.         <meta charset="utf-8">
  10.         <title>LIFAchan</title>
  11.         <link rel="stylesheet" type="text/css" href="style-res.css">
  12.     </head>
  13.     <body>
  14.         <div class="menu"><center><h1>LIFAchan</h1></center></div>
  15.         <div class="contenu">
  16.             <form enctype="multipart/form-data" method="post" action="index.php">
  17.                 <div class="nouveau_post">
  18.                     <input type="text" name="author" placeholder="Entrez un nom"><br>
  19.                     <input type="file" name="post_img"><br>
  20.                     <textarea name="post_msg" style="width: 90%; height: 400px" placeholder="Entrez du texte..."><?php if (isset($_GET["id"])) { ?><a href="<?=$_GET["id"];?>">#<?=$_GET["id"];?></a><?php print "\n"; } ?><<?="";?>/textarea><br>
  21.                     <input type="submit" name="action" value="Poster">
  22.                 </div>
  23.             </form><?php
  24.             function extension($name) {
  25.                 $yeet = "";
  26.                 $i = strlen($name) - 1;
  27.                 while ($name[$i] != ".") {
  28.                     $yeet = $name[$i].$yeet;
  29.                     $i--;
  30.                 }
  31.                 return ".$yeet";
  32.             }
  33.             function show ($file = [], $name) {
  34.                 if ($file[1] == "") $author = "Anon"; else $author = $file[1];
  35.                 print "\n               <div class=\"affiche_post\" style=\"text-align : left\" id=\"$name\"><table><tr><td>$author<td width='10px'><td>".$file[2]."\n                  <tr><td>";
  36.                 if (file_exists($name.$file[0]) and $file[0] != "") print "<a href='".$name.$file[0]."' target='_blank'><img height='100px' src='".$name.$file[0]."'></a>";
  37.                 print "<td><td>";
  38.                 for ($i = 4; $i < count($file); $i++) {
  39.                     if ($file[$i][0] == ">") {
  40.                         print "\n                       <span style='color: green'>".$file[$i]."</span><br>";
  41.                     } else {
  42.                         print "\n                       ".$file[$i]."<br>";
  43.                     }
  44.                 }
  45.                 print "\n               </table><br><form method='post' action='like.php'><input type='submit' name='$name' value='Like'> (".$file[3]." likes)</form>"
  46.                     . "\n                           <a href='index.php?id=$name#$name'><button>Répondre</button></a>";
  47.                 print "</div>";
  48.             }
  49.             $dir = scandir(".",1);
  50.             if (isset($_POST["post_msg"])) {
  51.                 $str = "";
  52.                 if ($_FILES["post_img"]["name"] != "") {
  53.                     $f = file_get_contents($_FILES["post_img"]["tmp_name"]);
  54.                     unlink($_FILES["post_img"]["tmp_name"]);
  55.                     file_put_contents(count($dir).extension($_FILES["post_img"]["name"]),$f);
  56.                     $str = extension($_FILES["post_img"]["name"]);
  57.                 }
  58.                 file_put_contents(count($dir),$str
  59.                                      ."\n".$_POST["author"]
  60.                                      ."\n".date("H:i:s Y/m/d")
  61.                                      ."\n"."0"
  62.                                      ."\n".$_POST["post_msg"]);
  63.             }
  64.             $dir = scandir(".",1);
  65.             $files = [];
  66.             foreach ($dir as $index => $content) {
  67.                 if (is_numeric($content)) {
  68.                     show(str_replace(["\n","\r"],"",file($content)),$content);
  69.                 }
  70.             }
  71.             ?>
  72.  
  73.         </div>
  74.     </body>
  75. </html>
  76.  
  77. //like.php
  78. <?php
  79. foreach ($_POST as $index => $content) {
  80.     if ($content = "Like") {
  81.         $name = $index;
  82.         $f = str_replace(["\r","\n"],"",file($index));
  83.         $f[3]++;
  84.         $str = "";
  85.         for ($i = 0; $i < count($f); $i++) {
  86.             $str .= $f[$i]."\n";
  87.         }
  88.         file_put_contents($index,$str);
  89.     }
  90. }
  91. ?>
  92. Patientez un instant...
  93. <meta http-equiv="refresh" content="1; index.php#<?=$name;?>">
  94.  
  95. //style-res.css
  96. div.menu {
  97.     background-color: red;
  98.     position: fixed;
  99.     left: 0px;
  100.     top: 0px;
  101.     width: 180px;
  102.     float: left;
  103.     padding: 10px;
  104.     height: 100%;
  105. }
  106. div.contenu {
  107.     background-color: blue;
  108.     float: right;
  109.     width: 70%;
  110.     padding: 10px;
  111.     margin: 10px;
  112. }
  113. div.nouveau_post { background-color: pink }
  114. div.affiche_post { background-color: orange }
  115. div.nouveau_post, div.affiche_post {
  116.     height: auto;
  117.     width: auto;
  118.     padding: 10px;
  119.     margin: 10px;
  120.     text-align: center;
  121. }
  122. * {
  123.     font-family: Arial
  124. }
  125. td {
  126.     text-align: left
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement