Merge branch 'master' of https://gitlab.deblan.org/deblan/lpwd-php-portfolio into pitton
Conflicts: lib/project.php project.php
This commit is contained in:
commit
ce06182532
34
README.md
34
README.md
|
@ -43,29 +43,53 @@ Un commentaire est composé de :
|
|||
|
||||
La date est générée automatiquement.
|
||||
Tous les champs sont obligatoires à l'exception du site web.
|
||||
Il faudra afficher l'avatar de l'auteur en utilisant le service [gravatar](https://fr.gravatar.com/site/implement/images/php/). *Ne pas réutiliser ce code source mais ne vous génez par pour vous en inspirer.*
|
||||
Il faudra afficher l'avatar de l'auteur en utilisant le service [gravatar](https://fr.gravatar.com/site/implement/images/php/). *Ne pas réutiliser ce code source mais ne vous génez pas pour vous en inspirer.*
|
||||
|
||||
Flux
|
||||
----
|
||||
|
||||
Réalisez un flux RSS présentant les 10 derniers projets mis en ligne.
|
||||
Vous réalisez également un flux Atom.
|
||||
|
||||
Vous devrez concevoir et réaliser des fonctions php.
|
||||
|
||||
Réécriture d'URL
|
||||
----------------
|
||||
|
||||
Documentez-vous et réalisez une réécriture des URL (`url rewriting`) afin de les rendre plus sexy.
|
||||
|
||||
Je souhaites accéder aux projets via : http://localhost/projet/`{id}`/`{slug}`
|
||||
Le slug est une chaine de caractère contenant le nom du projet sans les caractères spéciaux. Vous devez donc créer une fonction pour le générer.
|
||||
|
||||
Exemple : le slug de `Je suis une licorne, c'est classe quand même, non ?` est `je-suis-une-licorne-c-est-classe-quand-meme-non`. Si j'avais un projet avec ce titre et si son *id* était 42, alors l'adresse du projet serait : http://localhost/projet/42/je-suis-une-licorne-c-est-classe-quand-meme-non
|
||||
|
||||
Administration
|
||||
--------------
|
||||
|
||||
Pour le moment, la rédaction des articles est réalisée via phpmyadmin. Par ailleurs, il n'y a aucun modération des commentaires.
|
||||
Vous devez donc développer un backoffice (BO) pour administrer les contenus du portfolio.
|
||||
|
||||
L'accès au BO est reservé aux administrateurs. Prévoyez ainsi une authentification avec la méthode que vous préférez parmis :
|
||||
|
||||
* Base de données + formulaire __(recommandé)__ - @see [sessions] [sessions]
|
||||
* Identifiants en durs dans le code + formulaire (il manque pas grand chose pour utiliser une bdd ;)) - @see [sessions] [sessions]
|
||||
* Basic ou Digest HTTP authentication (pour les flemmards !)
|
||||
|
||||
Les commentaires doivent pouvoir être mis hors-ligne voire supprimés.
|
||||
Les articles doivent pouvoir être ajoutés, modifiés et supprimés depuis l'interface.
|
||||
|
||||
Petit plus
|
||||
----------
|
||||
|
||||
Les étudiants qui me proposeront une correction via des `pull-request`
|
||||
auront 1 point supplémentaire sur la note finale. Les intéressés devront
|
||||
créer un compte sur [Gitlab](https://gitlab.deblan.org). Je les ajouterai
|
||||
créer un compte sur [Gitlab](https://gitnet.fr). Je les ajouterai
|
||||
au dépôt et vous me transmettrez votre travail dans une branche portant
|
||||
votre nom : `nom-prenom`.
|
||||
|
||||
#### Installation du projet
|
||||
|
||||
```
|
||||
$ git clone git@gitlab.deblan.org:deblan/lpwd-php-portfolio.git
|
||||
$ git clone git@gitnet.fr:deblan/lpwd-php-portfolio.git
|
||||
$ git branch nom-prenom # à modifier
|
||||
$ git checkout nom-prenom
|
||||
$ ... modifications ...
|
||||
|
@ -73,3 +97,5 @@ $ git commit add <les fichiers modifiés>
|
|||
$ git commit -m "Explications des modifications"
|
||||
$ git push -u origin nom-prenom
|
||||
```
|
||||
|
||||
[sessions]: http://php.net/manual/fr/function.session-start.php
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @param int $limit Nombre de projets par page
|
||||
* @return array Les projets
|
||||
*/
|
||||
function getProjects($page = 1, $limit = 5)
|
||||
function getProjects($page = 1, $limit = 5, $orderBy = 'date', $orderBySens = 'ASC')
|
||||
{
|
||||
if (!is_integer($page)) {
|
||||
throw new InvalidArgumentException('The argument "page" must be an integer.');
|
||||
|
@ -21,7 +21,17 @@ function getProjects($page = 1, $limit = 5)
|
|||
|
||||
$pdo = getDatabaseConnection();
|
||||
|
||||
$query = $pdo->prepare('select id, title, illustration, description, date from project limit :from, :limit');
|
||||
$query = $pdo->prepare(
|
||||
'
|
||||
select
|
||||
id, title, illustration, description, date
|
||||
from
|
||||
project
|
||||
order by
|
||||
'.$orderBy.' '.$orderBySens.'
|
||||
limit
|
||||
:from, :limit'
|
||||
);
|
||||
|
||||
$query->bindParam(':from', $from, PDO::PARAM_INT);
|
||||
$query->bindParam(':limit', $limit, PDO::PARAM_INT);
|
||||
|
@ -37,8 +47,6 @@ function getProjects($page = 1, $limit = 5)
|
|||
* @param int $id id du projet
|
||||
* @return array|false Le projet
|
||||
*/
|
||||
|
||||
|
||||
function getProject($id)
|
||||
{
|
||||
if (!is_integer($id)) {
|
||||
|
@ -80,21 +88,29 @@ function getProjectNumberOfPages($maxPerPage)
|
|||
/**
|
||||
* Returne les commentaires d'un projet
|
||||
*
|
||||
* @param int $id L'id du projet
|
||||
* @param int $projectId L'id du projet
|
||||
* @return array Les commentaires du projet
|
||||
*/
|
||||
|
||||
function getCommentsByProject($id)
|
||||
function getCommentsByProject($projectId)
|
||||
{
|
||||
$pdo = getDatabaseConnection();
|
||||
|
||||
$query = $pdo->prepare('select id, name, website, email, date, content from comment where project_id=:id');
|
||||
$query = $pdo->prepare('select * from comment where project_id=:project_id');
|
||||
|
||||
$query->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$query->bindParam(':project_id', $projectId, PDO::PARAM_INT);
|
||||
|
||||
$query->execute();
|
||||
|
||||
return $query->fetchAll();
|
||||
$comments = $query->fetchAll();
|
||||
|
||||
foreach ($comments as $index => $comment) {
|
||||
$comment['avatar'] = getGravatar($comment['email']);
|
||||
$comment['date'] = new DateTime($comment['date']);
|
||||
|
||||
$comments[$index] = $comment;
|
||||
}
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +128,8 @@ function createComment($name, $email, $website, $content, DateTime $date, $proje
|
|||
$pdo = getDatabaseConnection();
|
||||
|
||||
$query = $pdo->prepare(
|
||||
'insert into comment(name, email, website, content, date, project_id) value(:name, :email, :website, :content, :date, :project_id)'
|
||||
'insert into comment(name, email, website, content, date, project_id)
|
||||
value(:name, :email, :website, :content, :date, :project_id)'
|
||||
);
|
||||
|
||||
$query->execute([
|
||||
|
@ -189,6 +206,16 @@ function getProjectsPager($page, $numberOfPages)
|
|||
return $pages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une url gravatar en fonction d'un email
|
||||
*
|
||||
* @param string $email
|
||||
* @param int $size
|
||||
* @return string
|
||||
*/
|
||||
function getGravatar($email, $size = 50)
|
||||
{
|
||||
$hash = md5(strtolower(trim($email)));
|
||||
|
||||
|
||||
|
||||
return 'http://www.gravatar.com/avatar/'.$hash.'?r=g&s='.$size;
|
||||
}
|
127
project.php
127
project.php
|
@ -17,14 +17,40 @@ if (false === $project) {
|
|||
die;
|
||||
}
|
||||
|
||||
// createComment(
|
||||
// 'Simon',
|
||||
// 'simon@deblan.fr',
|
||||
// 'https://www.deblan.io/',
|
||||
// 'Mon second super commentaire !',
|
||||
// new DateTime('now'),
|
||||
// $id
|
||||
// );
|
||||
if (isset($_POST['name'], $_POST['email'], $_POST['website'], $_POST['content'])) {
|
||||
$name = trim($_POST['name']);
|
||||
$email = trim($_POST['email']);
|
||||
$website = trim($_POST['website']);
|
||||
$content = trim($_POST['content']);
|
||||
|
||||
$valid = true;
|
||||
|
||||
foreach ([$name, $email, $content] as $field) {
|
||||
if (empty($field)) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
createComment(
|
||||
$name,
|
||||
$email,
|
||||
$website,
|
||||
$content,
|
||||
new DateTime('now'),
|
||||
$id
|
||||
);
|
||||
|
||||
header('Location: project.php?id='.$id);
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
$comments = getCommentsByProject($id);
|
||||
|
||||
|
@ -39,11 +65,11 @@ $comments = getCommentsByProject($id);
|
|||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
<h1>
|
||||
<?php echo $project['title'] ?>
|
||||
</h1>
|
||||
</h1>
|
||||
|
||||
<section>
|
||||
<section>
|
||||
<article>
|
||||
<figure>
|
||||
<img src="images/<?php echo $project['illustration'] ?>" alt="" width="130px" />
|
||||
|
@ -61,49 +87,58 @@ $comments = getCommentsByProject($id);
|
|||
</time>
|
||||
</p>
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Commentaires</h2>
|
||||
|
||||
<?php if (count($comments)): ?>
|
||||
<div>
|
||||
<form action="" method="POST">
|
||||
<p>
|
||||
<label for="form-name">Nom</label>
|
||||
<input name="name" required id="form-name" type="text" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="form-mail">Email</label>
|
||||
<input name="email" required id="form-mail" type="mail" />
|
||||
</p>
|
||||
<p>
|
||||
<label for="form-website">Site web</label>
|
||||
<input name="website" id="form-website" type="website" />
|
||||
</p>
|
||||
<p>
|
||||
<textarea name="content" required rows="10" cols="30"></textarea>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input type="submit" value="Go go go!" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php foreach ($comments as $comment): ?>
|
||||
<p>Posté par : <?php echo $comment['name'] ?></p>
|
||||
<p>Email : <?php echo $comment['email'] ?></p>
|
||||
<p>Site web : <?php echo $comment['website'] ?></p>
|
||||
<span>Commentaire :</span>
|
||||
<p class="comment-content"><?php echo $comment['content'] ?></p>
|
||||
<p class="date"><?php echo $comment['date'] ?></p>
|
||||
<?php endforeach ?>
|
||||
<div>
|
||||
<p>
|
||||
<img src="<?php echo $comment['avatar'] ?>" alt="" />
|
||||
|
||||
<?php if ($comment['website']): ?>
|
||||
<a href="<?php echo htmlspecialchars($comment['website']) ?>">
|
||||
<?php endif ?>
|
||||
|
||||
<?php echo htmlspecialchars($comment['name']) ?>
|
||||
|
||||
<?php if ($comment['website']): ?>
|
||||
</a>
|
||||
<?php endif ?>
|
||||
|
||||
<form method="post" action="lib/project.php">
|
||||
<label for="name">Nom :</label>
|
||||
<input type="text" name="name" id="name">
|
||||
<label for="email">Email :</label>
|
||||
<input type="text" name="email" id="email">
|
||||
<label for="website">Votre site web</label>
|
||||
<input type="text" name="website" id="website">
|
||||
<label for="content">Votre message</label>
|
||||
<input type="text" name="content" id="content">
|
||||
<input type="hidden" name="project_id" value="<?php echo $id ?>">
|
||||
<input type="submit" value="Envoyer">
|
||||
</form>
|
||||
- Posté le <?php echo $comment['date']->format('d/m/Y à H:i') ?>
|
||||
</p>
|
||||
|
||||
|
||||
<!--
|
||||
Afficher la liste des commentaires
|
||||
|
||||
Un commentaire est composé de :
|
||||
- son auteur
|
||||
- le site web de l'auteur
|
||||
- l'email de l'auteur
|
||||
- sa date de publication
|
||||
- son contenu
|
||||
|
||||
Il faudra afficher l'avatar de l'auteur en utilisant gravatar : https://fr.gravatar.com/site/implement/images/php/
|
||||
Attention : ne pas utiliser cette fonction, il faut écrire la votre !
|
||||
-->
|
||||
<p>
|
||||
<?php echo nl2br(htmlspecialchars($comment['content'])) ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue