diff --git a/.buildpath b/.buildpath new file mode 100644 index 0000000..b461518 --- /dev/null +++ b/.buildpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..631931a --- /dev/null +++ b/.project @@ -0,0 +1,22 @@ + + + pqjep + + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + + org.eclipse.php.core.PHPNature + + diff --git a/.settings/org.eclipse.php.core.prefs b/.settings/org.eclipse.php.core.prefs new file mode 100644 index 0000000..cbd704c --- /dev/null +++ b/.settings/org.eclipse.php.core.prefs @@ -0,0 +1,3 @@ +#Sat Jun 11 18:54:52 CEST 2011 +eclipse.preferences.version=1 +include_path=0;/pqjep diff --git a/fragments/fortune.php b/fragments/fortune.php new file mode 100644 index 0000000..905f936 --- /dev/null +++ b/fragments/fortune.php @@ -0,0 +1,27 @@ + "", "liste" => array()); +$select = false; +foreach ($selection["liste"] as $s) { + $select = $s == $c["id"]; + if ($select) break; +} +?> + +
"> + +
+ + + ★Sélectionné ); return false;">(Retirer) + + ); return false;">☆Sélectionner + + + + , 1); return false;">+/ + , -1); return false;">- + + Signaler + Raison # +
+
diff --git a/fragments/includes.php b/fragments/includes.php new file mode 100644 index 0000000..3ca9313 --- /dev/null +++ b/fragments/includes.php @@ -0,0 +1,33 @@ + + + + + + + + + diff --git a/model/db.php b/model/db.php new file mode 100644 index 0000000..92cfd02 --- /dev/null +++ b/model/db.php @@ -0,0 +1,3 @@ +prepare("SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune " + ."FROM fortune f " + ."LEFT OUTER JOIN vote v ON v.id_fortune = f.id " + ."WHERE f.id = :id " + ."GROUP BY f.id "); + $stmt->bindParam(":id", $_GET["id"]); + $stmt->execute(); + while ($row = $stmt->fetch()) { + $c["id"] = $row["id"]; + $c["fortune"] = $row["fortune"]; + $c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + } + } else { + $query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune " + ."FROM fortune f " + ."LEFT OUTER JOIN vote v ON v.id_fortune = f.id " + ."GROUP BY f.id " + ."ORDER BY RAND() " + ."LIMIT 1"; + foreach ($db->query($query) as $row) { + $c["id"] = $row["id"]; + $c["fortune"] = $row["fortune"]; + $c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + } + } +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/model/liste.php b/model/liste.php new file mode 100644 index 0000000..a4087a1 --- /dev/null +++ b/model/liste.php @@ -0,0 +1,34 @@ +query("SELECT COUNT(*) nb FROM fortune") as $row) { + $count = round($row["nb"] / 10, 0); + } + + $p = isset($_GET['p']) ? mysql_escape_string($_GET['p']) : 0; + $p *= 10; + if ($p < 0) { + $p = 0; + } + + $confessions = array(); + $query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune " + ."FROM fortune f " + ."LEFT OUTER JOIN vote v ON v.id_fortune = f.id " + ."GROUP BY f.id " + ."ORDER BY date_ajout DESC " + ."LIMIT $p, 10"; + foreach ($db->query($query) as $row) { + $conf = array(); + $conf['id'] = $row["id"]; + $conf['fortune'] = $row["fortune"]; + $conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + array_push($confessions, $conf); + } +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/model/selection.php b/model/selection.php new file mode 100644 index 0000000..8c389ff --- /dev/null +++ b/model/selection.php @@ -0,0 +1,35 @@ + "", "liste" => array()); + +try { + $db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password); + + $confessions = array(); + $query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune " + ."FROM fortune f " + ."LEFT OUTER JOIN vote v ON v.id_fortune = f.id " + ."WHERE f.id = :id " + ."GROUP BY f.id "; + + $stmt = $db->prepare($query); + + foreach ($selection["liste"] as $s) { + $stmt->bindParam(":id", $s); + $stmt->execute(); + + if ($row = $stmt->fetch()) { + $conf = array(); + $conf['id'] = $row["id"]; + $conf['fortune'] = $row["fortune"]; + $conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + array_push($confessions, $conf); + } + } + + $count = round(count($confessions) / 10); +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/model/top.php b/model/top.php new file mode 100644 index 0000000..c356385 --- /dev/null +++ b/model/top.php @@ -0,0 +1,34 @@ +query("SELECT COUNT(*) nb FROM fortune") as $row) { + $count = round($row["nb"] / 10, 0); + } + + $p = isset($_GET['p']) ? mysql_escape_string($_GET['p']) : 0; + $p *= 10; + if ($p < 0) { + $p = 0; + } + + $confessions = array(); + $query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune " + ."FROM fortune f " + ."LEFT OUTER JOIN vote v ON v.id_fortune = f.id " + ."GROUP BY f.id " + ."ORDER BY SUM(vote_p) DESC, date_ajout DESC " + ."LIMIT $p, 10"; + foreach ($db->query($query) as $row) { + $conf = array(); + $conf['id'] = $row["id"]; + $conf['fortune'] = $row["fortune"]; + $conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + array_push($confessions, $conf); + } +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/model/view_select.php b/model/view_select.php new file mode 100644 index 0000000..0c363b8 --- /dev/null +++ b/model/view_select.php @@ -0,0 +1,47 @@ + "", "liste" => array()); + + $query = "SELECT nom " + ."FROM selection " + ."WHERE id = :id"; + $stmt = $db->prepare($query); + $stmt->bindParam(":id", $ids); + $stmt->execute(); + if ($row = $stmt->fetch()) { + $selection["nom"] = $row["nom"]; + } + + $query = "SELECT f.id id, SUM(vote_p) vote_p, SUM(vote_m) vote_m, fortune " + ."FROM fortune f " + ."LEFT OUTER JOIN vote v ON v.id_fortune = f.id " + ."INNER JOIN fortune_selection fs ON f.id = fs.id_fortune " + ."WHERE fs.id_selection = :ids " + ."GROUP BY f.id " + ."ORDER BY date_ajout DESC "; + $stmt = $db->prepare($query); + $stmt->bindParam(":ids", $ids); + $stmt->execute(); + $liste = array(); + while($row = $stmt->fetch()) { + $conf = array(); + $conf['id'] = $row["id"]; + $conf['fortune'] = $row["fortune"]; + $conf["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $conf["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + array_push($liste, $conf); + } + + $selection["liste"] = $liste; +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/root/ajax/fortune.php b/root/ajax/fortune.php new file mode 100644 index 0000000..ac1f2a9 --- /dev/null +++ b/root/ajax/fortune.php @@ -0,0 +1,30 @@ +prepare($query); + $stmt->bindParam(":id", $id); + $stmt->execute(); + while ($row = $stmt->fetch()) { + $c["id"] = $row["id"]; + $c["fortune"] = $row["fortune"]; + $c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + } + + include "../../fragments/fortune.php"; +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} +?> diff --git a/root/ajax/random.php b/root/ajax/random.php new file mode 100644 index 0000000..be3f4e3 --- /dev/null +++ b/root/ajax/random.php @@ -0,0 +1,26 @@ +query($query) as $row) { + $c["id"] = $row["id"]; + $c["fortune"] = $row["fortune"]; + $c["vote_p"] = $row["vote_p"] == null ? 0 : $row["vote_p"]; + $c["vote_m"] = $row["vote_m"] == null ? 0 : $row["vote_m"]; + } + + include "../../fragments/fortune.php"; +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} +?> diff --git a/root/ajax/select.php b/root/ajax/select.php new file mode 100644 index 0000000..be14998 --- /dev/null +++ b/root/ajax/select.php @@ -0,0 +1,50 @@ + "", "liste" => array()); + + if ($action == "add") { + foreach ($selection["liste"] as $s) { + if ($s == $id) { + ?>prepare($query); + $stmt->bindParam(":id", $id); + $stmt->execute(); + + while ($row = $stmt->fetch()) { + array_push($selection["liste"], $id); + } + } else if ($action == "rem") { + foreach ($selection["liste"] as $i => $s) { + if ($s == $id) { + unset($selection["liste"][$i]); + } + } + } + + if (count($selection["liste"]) > 0) { + $_SESSION["selection"] = $selection; + ?>prepare("SELECT * " + ."FROM signalement " + ."WHERE id_fortune = :id_fortune " + ." AND ip_from = :ip_from" + ." AND HOUR(date_signalement) + 1 > HOUR(CURRENT_TIMESTAMP)"); + $check->bindParam(":id_fortune", $id_fortune); + $check->bindParam(":ip_from", $ip_from); + $check->execute(); + if ($row = $check->fetch()) { + echo "KO"; + return; + } + + $stmt = $db->prepare("INSERT INTO signalement (id_fortune, ip_from) VALUES (:id_fortune, :ip_from)"); + $stmt->bindParam(":id_fortune", $id_fortune); + $stmt->bindParam(":ip_from", $ip_from); + $stmt->execute(); + + echo "OK"; +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/root/ajax/voter.php b/root/ajax/voter.php new file mode 100644 index 0000000..86029d9 --- /dev/null +++ b/root/ajax/voter.php @@ -0,0 +1,49 @@ +prepare("SELECT * " + ."FROM vote " + ."WHERE id_fortune = :id_fortune " + ." AND ip_from = :ip_from" + ." AND HOUR(date_vote) + 1 > HOUR(CURRENT_TIMESTAMP)"); + $check->bindParam(":id_fortune", $id_fortune); + $check->bindParam(":ip_from", $ip_from); + $check->execute(); + if ($row = $check->fetch()) { + $stmt = $db->prepare("SELECT SUM(vote_p) vote_p, SUM(vote_m) vote_m " + ."FROM vote " + ."WHERE id_fortune = :id_fortune"); + $stmt->bindParam(":id_fortune", $id_fortune); + $stmt->execute(); + $row = $stmt->fetch(); ?> +Vous avez déjà voté +/- +prepare("INSERT INTO vote (id_fortune, vote_p, vote_m, ip_from) " + ."VALUES (:id_fortune, :vote_p, :vote_m, :ip_from)"); + $stmt->bindParam(":id_fortune", $id_fortune); + $stmt->bindParam(":vote_p", $vote_p); + $stmt->bindParam(":vote_m", $vote_m); + $stmt->bindParam(":ip_from", $ip_from); + $stmt->execute(); + + $stmt = $db->prepare("SELECT SUM(vote_p) vote_p, SUM(vote_m) vote_m " + ."FROM vote " + ."WHERE id_fortune = :id_fortune"); + $stmt->bindParam(":id_fortune", $id_fortune); + $stmt->execute(); + $row = $stmt->fetch(); + + ?>Merci ! +/- + + + + Pourquoi je pirate ? + + + + + +
+ + +
+

J'avoue, je suis un pirate...

+ ... mais j'ai mes raisons ! +
+ +
+ Attention, 500 caractères max. +
+ +

Important ! Consultez la FAQ. +

+
+ + +
+ + diff --git a/root/fortune.js b/root/fortune.js new file mode 100644 index 0000000..b484569 --- /dev/null +++ b/root/fortune.js @@ -0,0 +1,89 @@ +function rollthedice() { + $.ajax({ + type: "get", + url: "ajax/random.php", + data: {}, + success: function(data) { + $(".fortune").remove(); + $(".main").append(data); + } + }); +} + +function deselect(id) { + $(".fortune[data-id="+id+"] .select").html("En cours..."); + $.ajax({ + type: "get", + url: "ajax/select.php", + data: { + action: "rem", + id: id + }, + success: function(data) { + if (location.href.indexOf("selection.php") > 0) { + $(".fortune[data-id="+id+"]").slideUp(); + } else { + setTimeout(function() { + $.get("ajax/fortune.php?id=" + id, function(data) { + $(".fortune[data-id="+id+"]").replaceWith(data); + }); + }, 500); + } + $("#select_menu").html(data); + } + }); +} + +function select(id) { + $(".fortune[data-id="+id+"] .select").html("En cours..."); + $.ajax({ + type: "get", + url: "ajax/select.php", + data: { + action: "add", + id: id + }, + success: function(data) { + $(".fortune[data-id="+id+"] .select").html("★Sélectionné !"); + $("#select_menu").html(data); + } + }); +} + +function signaler(id) { + $(".fortune[data-id="+id+"] .signaler").html("En cours..."); + $.ajax({ + type: 'post', + url: 'ajax/signaler.php', + data: { + id: id + }, + success: function(data) { + if (data == "OK") { + $(".fortune[data-id="+id+"] .signaler").html("Merci !"); + } else { + $(".fortune[data-id="+id+"] .signaler").html("Vous l'avez déjà signalé, merci tout de même !"); + } + } + }); + + return false; +} + +function voter(id, vote) { + $(".fortune[data-id="+id+"] .votes").html("En cours..."); + $.ajax({ + type: 'post', + url: 'ajax/voter.php', + data: { + id: id, + vote: vote + }, + success: function(data) { + $(".fortune[data-id="+id+"] .votes").html(data); + } + }); + + return false; +} + diff --git a/root/fragments/footer.php b/root/fragments/footer.php new file mode 100644 index 0000000..bdd748f --- /dev/null +++ b/root/fragments/footer.php @@ -0,0 +1,2 @@ +

Site fait à l'arrache par @manudwarf. CC BY-SA, certains droits réservés. Si vous me copiez, je ne vous poursuivrai pas en justice, moi.

+N'oubliez pas de consulter la FAQ. diff --git a/root/fragments/fortune.php b/root/fragments/fortune.php new file mode 100644 index 0000000..0518ab2 --- /dev/null +++ b/root/fragments/fortune.php @@ -0,0 +1,10 @@ +
"> + +
+ + " onclick="voter(, 1); return false;">+/ + " onclick="voter(, -1); return false;">- + " onclick="signaler(); return false;">Signaler + Raison # +
+
diff --git a/root/fragments/header.php b/root/fragments/header.php new file mode 100644 index 0000000..99d2fe6 --- /dev/null +++ b/root/fragments/header.php @@ -0,0 +1,21 @@ +
+ + + Tweet +
+

Parce qu'on n'est pas des voleurs !

+
+ 0) {?> + + + +
+ diff --git a/root/fragments/includes.php b/root/fragments/includes.php new file mode 100644 index 0000000..3ca9313 --- /dev/null +++ b/root/fragments/includes.php @@ -0,0 +1,33 @@ + + + + + + + + + diff --git a/root/index.php b/root/index.php new file mode 100644 index 0000000..a68bfd6 --- /dev/null +++ b/root/index.php @@ -0,0 +1,34 @@ + + + + + Pourquoi je pirate ? + + + + + +
+ + +
+
+ Encore un ! +

Pourquoi je pirate ?

+ +
+ + Dis-nous pourquoi tu pirates ! +
+ + +
+ + diff --git a/root/liste.php b/root/liste.php new file mode 100644 index 0000000..7b7d529 --- /dev/null +++ b/root/liste.php @@ -0,0 +1,59 @@ + + + + + Pourquoi je pirate ? + + + + + +
+ + +
+ Dis-nous pourquoi tu pirates ! + +
+

Les dernières confessions

+
    + +
  • + + + + + +
  • + +
+ + + + + +
    + +
  • + + + + + +
  • + +
+
+
+ + +
+ + diff --git a/root/main.css b/root/main.css new file mode 100644 index 0000000..d899b4d --- /dev/null +++ b/root/main.css @@ -0,0 +1,128 @@ +body { + background-color: #444649; + color: #ddd; + /* font-family: 'Playfair Display'; */ + font-family: Arial; + margin: 0 50px; +} + +h1, h2 { + font-family: 'Playfair Display'; +} + +a, .fortune .actions { + color: #79f; + text-decoration: none; +} + +a:hover { + color: white; +} + +#container { + box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2); + margin: 0 auto; + width: 900px; +} + +#header, #footer { + background-color: #333; + padding: 1px 15px; +} + +#header ul { + list-style: none; + margin: 0; + padding: 0; +} + +#header ul li { + display: inline; + margin-right: 15px; +} + +#header h1 { + text-shadow: 1px 1px 3px black; +} + +#content { + background-color: white; + border-bottom: 2px dashed #333; + border-top: 2px dashed #333; + color: black; + min-height: 400px; + padding: 15px; +} + +#content a:hover { + color: #013; +} + +#content h1 { + font-size: 16pt; +} + +.pagination li { + display: inline; +} + +#aveu { + background-color: #234; + border: 2px solid #333; + border-radius: 5px; + box-shadow: 0 0 10px black inset; + color: white; + display: block; + font-family: 'Playfair Display'; + font-weight: bold; + margin: 0 auto; + padding: 5px 0 5px; + text-align: center; + width: 250px; +} + +#aveu:hover { + background-color: #79B; +} + +.fortune { + background-color: #eef; + border: 2px dashed black; + box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3); + font-size: 20pt; + margin: 0 20px 30px; + padding: 20px; + padding-bottom: 25px; +} + +.fortune .actions { + font-size: 10pt; + margin: 0; + text-align: right; +} + +.fortune .actions > * { + margin-left: 10px; +} + +.fortune .actions .signaler, .fortune .actions .signaler a { + color: red; +} + +.fortune .texte { + font-family: 'Playfair Display'; +} + +#footer { + font-size: 10pt; + padding-bottom: 10px; + padding-top: 10px; +} + +fieldset { + border: none; +} + +fieldset label { + margin-right: 10px; +} diff --git a/root/post.php b/root/post.php new file mode 100644 index 0000000..b45afea --- /dev/null +++ b/root/post.php @@ -0,0 +1,23 @@ +prepare("INSERT INTO fortune (fortune, ip_from) VALUES (:fortune, :ip_from)"); + $stmt->bindParam(":fortune", $fortune); + $stmt->bindParam(":ip_from", $ip_from); + $stmt->execute(); + + header('Location: http://pourquoijepirate.fr'); +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/root/save_select.php b/root/save_select.php new file mode 100644 index 0000000..293f378 --- /dev/null +++ b/root/save_select.php @@ -0,0 +1,44 @@ + "", "liste" => array()); +print_r($_SESSION); +if (count($selection["liste"]) == 0) { + header("Location: /"); + return; +} + +$nom = $_POST["nom"]; +$ip_from = $_SERVER['REMOTE_ADDR']; + +if (strlen($nom) == 0) { + header('Location: selection.php'); + return; +} + +try { + $db = new PDO("mysql:host=localhost;dbname=pqjep", $db_username, $db_password); + + $stmt = $db->prepare("INSERT INTO selection (nom, ip_from, password) VALUES (:nom, :ip_from, '')"); + $stmt->bindParam(":nom", $nom); + $stmt->bindParam(":ip_from", $ip_from); + $stmt->execute(); + + $ids = $db->lastInsertId(); + + $stmt = $db->prepare("INSERT INTO fortune_selection VALUES (:idf, :ids)"); + foreach ($selection["liste"] as $idf) { + $stmt->bindParam(":idf", $idf); + $stmt->bindParam(":ids", $ids); + $stmt->execute(); + } + + $selection["nom"] = $nom; + $selection["id"] = $ids; + unset($_SESSION["selection"]); + + header("Location: view_select.php?ids=$ids"); +} catch (PDOException $e) { + die("Erreur de base de données. D'oh."); +} diff --git a/root/selection.php b/root/selection.php new file mode 100644 index 0000000..5fe331b --- /dev/null +++ b/root/selection.php @@ -0,0 +1,45 @@ + + + + + Pourquoi je pirate ? + + + + + +
+ + +
+ Enregistrer la sélection + + + +
+

Votre sélection de confessions

+ + + + +
+
+ + +
+ + diff --git a/root/top.php b/root/top.php new file mode 100644 index 0000000..56fbdb5 --- /dev/null +++ b/root/top.php @@ -0,0 +1,59 @@ + + + + + Pourquoi je pirate ? + + + + + +
+ + +
+ Dis-nous pourquoi tu pirates ! + +
+

Les plus pires fourbonneries (quelque part entre fourbe et forban)

+
    + +
  • + + + + + +
  • + +
+ + + + + +
    + +
  • + + + + + +
  • + +
+
+
+ + +
+ + diff --git a/root/view_select.php b/root/view_select.php new file mode 100644 index 0000000..470021d --- /dev/null +++ b/root/view_select.php @@ -0,0 +1,37 @@ + + + + + Pourquoi je pirate ? + + + + + +
+ + +
+ Dis-nous pourquoi tu pirates ! + +
+

+

Cette sélection vous plaît ? Partagez-la !

+ + + + +
+
+ + +
+ + diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..3e38127 --- /dev/null +++ b/www/index.php @@ -0,0 +1,3 @@ +