Add page favorite

This commit is contained in:
Mathieu Sanchez 2018-12-16 16:05:08 +09:00
parent 32ec67699b
commit dbf28b5afa
12 changed files with 81 additions and 5599 deletions

View File

@ -12,7 +12,7 @@ date_default_timezone_set( 'Europe/Paris' );
setlocale( LC_TIME, "fr_FR.UTF-8" ); setlocale( LC_TIME, "fr_FR.UTF-8" );
error_reporting( E_ALL ); error_reporting( E_ALL );
require( 'src/Lib/functions.php' ); require( 'src/Lib/Functions.php' );
require( 'src/Config.php' ); require( 'src/Config.php' );
require 'src/Autoloader.php'; require 'src/Autoloader.php';

View File

@ -3,8 +3,8 @@
namespace WebProjectFitness; namespace WebProjectFitness;
class Config { class Config {
const SITE_JS_VERSION = '1.03'; const SITE_JS_VERSION = '1.04';
const SITE_CSS_VERSION = '1.03'; const SITE_CSS_VERSION = '1.04';
const TITLE_HEADER = 'Fitness'; const TITLE_HEADER = 'Fitness';
const DESCRIPTION_HEADER = 'Site for find all the fitness exercise you need'; const DESCRIPTION_HEADER = 'Site for find all the fitness exercise you need';

28
src/Lib/Functions.php Normal file
View File

@ -0,0 +1,28 @@
<?php
/**
* Redéfini la gestion des erreurs
*
* @param $errno
* @param $errstr
* @param $errfile
* @param $errline
*
* @return bool|void
*/
function errorHandler( $errno, $errstr, $errfile, $errline ) {
if ( !( error_reporting() & $errno ) ) {
// Ce code d'erreur n'est pas inclus dans error_reporting()
return;
}
// Insertion des logs
\CAUProject3Contact\Model\Logs::insert( $errno, $errstr, $errfile, $errline, date( 'Y-m-d H:i:s' ) );
ob_clean();
new \CAUProject3Contact\Controller\Site\SiteError( 500 );
/* Ne pas exécuter le gestionnaire interne de PHP */
return;
}

View File

@ -1,413 +0,0 @@
<?php
include( 'src/Lib/mail/PHPMailerAutoload.php' );
/**
* Permet de remplacer les accents et les apostrophes dans l'url
*
* @param string $str l'url à formater
* @param string $encoding
*
* @return string
*/
function formatURL( string $str, $encoding = 'utf-8' ) {
$str = str_replace( "+", "_plus_", $str );
$str = str_replace( "%", "_pourcent_", $str );
$str = str_replace( "&", "_et_", $str );
//on remplace les apotrophes et espaces par des underscore
$str = str_replace( array( "'", " ", "," ), "_", $str );
$str = str_replace( "__", "_", $str );
// transformer les caractères accentués en entités HTML
$str = htmlentities( $str, ENT_NOQUOTES, $encoding );
// remplacer les entités HTML pour avoir juste le premier caractères non accentués
// Exemple : "&ecute;" => "e", "&Ecute;" => "E", "Ã " => "a" ...
$str = preg_replace( '#&([A-za-z])(?:acute|grave|cedil|circ|orn|ring|slash|th|tilde|uml);#', '\1', $str );
// Remplacer les ligatures tel que : Œ, Æ ...
// Exemple "Å“" => "oe"
$str = preg_replace( '#&([A-za-z]{2})(?:lig);#', '\1', $str );
// Supprimer tout le reste
//$str = preg_replace('#&[^;]+;#', '', $str);
$str = str_replace( array( "#", "&", "[", "^", ";", "]" ), '', $str );
//on passe tout en minuscule
$str = strtolower( $str );
if ( substr( $str, -1 ) == '_' ) {
$str = substr( $str, 0, -1 );
}
return $str;
}
/**
* La fonction darkroom() renomme et redimensionne les photos envoyées lors de l'ajout d'un objet.
*
* @param $img String Chemin absolu de l'image d'origine.
* @param $to String Chemin absolu de l'image générée (.jpg).
* @param $width Int Largeur de l'image générée. Si 0, valeur calculée en fonction de $height.
* @param $height Int Hauteur de l'image génétée. Si 0, valeur calculée en fonction de $width.
* Si $height = 0 et $width = 0, dimensions conservées mais conversion en .jpg
*
* @return bool
*/
function darkroom( $img, $to, $width = 0, $height = 0, $quality = 100, $useGD = true ) {
$dimensions = getimagesize( $img );
$ratio = $dimensions[ 0 ] / $dimensions[ 1 ];
// Calcul des dimensions si 0 passé en paramètre
if ( $width == 0 && $height == 0 ) {
$width = $dimensions[ 0 ];
$height = $dimensions[ 1 ];
} else if ( $height == 0 ) {
$height = round( $width / $ratio );
} else if ( $width == 0 ) {
$width = round( $height * $ratio );
}
if ( $dimensions[ 0 ] > ( $width / $height ) * $dimensions[ 1 ] ) {
$dimY = $height;
$dimX = round( $height * $dimensions[ 0 ] / $dimensions[ 1 ] );
}
if ( $dimensions[ 0 ] < ( $width / $height ) * $dimensions[ 1 ] ) {
$dimX = $width;
$dimY = round( $width * $dimensions[ 1 ] / $dimensions[ 0 ] );
}
if ( $dimensions[ 0 ] == ( $width / $height ) * $dimensions[ 1 ] ) {
$dimX = $width;
$dimY = $height;
}
// Création de l'image avec la librairie GD
if ( $useGD ) {
$pattern = imagecreatetruecolor( $width, $height );
$type = mime_content_type( $img );
switch ( substr( $type, 6 ) ) {
case 'jpeg':
$image = imagecreatefromjpeg( $img );
break;
case 'gif':
$image = imagecreatefromgif( $img );
break;
case 'png':
$image = imagecreatefrompng( $img );
break;
}
imagecopyresampled( $pattern, $image, 0, 0, 0, 0, $dimX, $dimY, $dimensions[ 0 ], $dimensions[ 1 ] );
imagedestroy( $image );
imagejpeg( $pattern, $to, $quality );
return true;
}
return true;
}
/**
* Redéfini la gestion des erreurs
*
* @param $errno
* @param $errstr
* @param $errfile
* @param $errline
*
* @return bool|void
*/
function errorHandler( $errno, $errstr, $errfile, $errline ) {
if ( !( error_reporting() & $errno ) ) {
// Ce code d'erreur n'est pas inclus dans error_reporting()
return;
}
// Insertion des logs
\WebProjectFitness\Model\Logs::insert( $errno, $errstr, $errfile, $errline, date( 'Y-m-d H:i:s' ) );
ob_clean();
new \WebProjectFitness\Controller\Site\SiteError( 500 );
/* Ne pas exécuter le gestionnaire interne de PHP */
return;
}
/**
* @return array
* Fonction permettant de récupérer des informations sur le navigateur utiliser par l'utilisateur
*/
function getBrowser() {
$u_agent = $_SERVER[ 'HTTP_USER_AGENT' ];
$bname = 'Unknown';
$platform = 'Unknown';
$ub = "";
//First get the platform?
if ( preg_match( '/android/i', $u_agent ) || preg_match( '/Android/i', $u_agent ) ) {
$platform = 'android';
} else if ( preg_match( '/linux/i', $u_agent ) ) {
$platform = 'linux';
} else if ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
$platform = 'mac';
} else if ( preg_match( '/windows|win32/i', $u_agent ) ) {
$platform = 'windows';
}
if ( strstr( $u_agent, 'mobile' ) || strstr( $u_agent, 'Mobile' ) ) {
$platform .= ' mobile';
}
// Next get the name of the useragent yes seperately and for good reason
if ( preg_match( '/MSIE/i', $u_agent ) && !preg_match( '/Opera/i', $u_agent ) ) {
$bname = 'Internet Explorer';
$ub = "MSIE";
} else if ( preg_match( '/Edge/i', $u_agent ) ) {
$bname = 'Microsoft Edge';
$ub = "Edge";
} else if ( preg_match( '/Trident/i', $u_agent ) ) {
$bname = 'Internet Explorer';
$ub = "rv";
} else if ( preg_match( '/Firefox/i', $u_agent ) ) {
$bname = 'Mozilla Firefox';
$ub = "Firefox";
} else if ( preg_match( '/Chrome/i', $u_agent ) ) {
$bname = 'Google Chrome';
$ub = "Chrome";
} else if ( preg_match( '/Safari/i', $u_agent ) ) {
$bname = 'Apple Safari';
$ub = "Safari";
} else if ( preg_match( '/Opera/i', $u_agent ) ) {
$bname = 'Opera';
$ub = "Opera";
} else if ( preg_match( '/Netscape/i', $u_agent ) ) {
$bname = 'Netscape';
$ub = "Netscape";
}
// finally get the correct version number
// Added "|:"
$known = array( 'Version', $ub, 'other' );
$pattern = '#(?<browser>' . join( '|', $known ) . ')[/|: ]+(?<version>[0-9.|a-zA-Z.]*)#';
if ( !preg_match_all( $pattern, $u_agent, $matches ) ) {
// we have no matching number just continue
}
// see how many we have
$i = count( $matches[ 'browser' ] );
if ( $i != 1 ) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if ( strripos( $u_agent, "Version" ) < strripos( $u_agent, $ub ) ) {
$version = $matches[ 'version' ][ 0 ];
} else {
$version = $matches[ 'version' ][ 1 ];
}
} else {
$version = $matches[ 'version' ][ 0 ];
}
// check if we have a number
if ( $version == null || $version == "" ) {
$version = "?";
}
return array(
'userAgent' => $u_agent,
'platform' => $platform,
'version' => $version,
'pattern' => $pattern,
'name' => $bname
);
}
/**
* @param $string
* @param $limit
*
* @return int
*/
function getLimitWord( $string, $limit ) {
$i = $limit;
if ( !isset( $string ) || empty( $string ) ) {
return 0;
}
while ( $i > 0 && $string[ $i ] != ' ' ) {
$i--;
}
return $i;
}
/**
* @param array $destinataires [nom du destinataire => adresse du destinataire] On peut en ajouter autant que l'on veut
* @param string $subject Objet du mail
* @param string $body Corp du mail
* @param string|null $auteurMail L'auteur du mail Par défaut eldotravo@gmail.com
* @param array|null $files [nom du fichier => chemin du fichier] On peut en ajouter autant que l'on veut
* @param array|null $cci [nom du cci => adresse du cci] On peut en ajouter autant que l'on veut
* @param array|null $cc [nom du cc => adresse du cc] On peut en ajouter autant que l'on veut
*/
/*
function email(array $destinataires, string $subject, string $body, string $auteurMail = null, array $files = null, array $cci = null, $cc = null) {
date_default_timezone_set('Etc/UTC');
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = ""; // Host SMTP du server d'envoi du mail
$mail->SMTPAuth = true;
$mail->Username = ""; // Identifiant de connection
$mail->Password = ""; // Mot de passe de connection
$mail->SMTPSecure = 'ssl';
$mail->Port = 465; // Port
//Enable SMTP debugging (0 = off (for production use), 1 = client messages, 2 = client and server messages)
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
$mail->Sender = ""; // l'email d'envoi
if ($auteurMail == 'Marie-Paule'){
$mail->setFrom("" , ""); // Mail affiché d'envoi, nom affiché d'envoi
$mail->addReplyTo("", ""); // Mail de reply, nom de reply
}
// Ajout de tout les utilisateurs
foreach ($destinataires as $nom => $adresseMail){
if (!empty($adresseMail)) {
$mail->addAddress($adresseMail, $nom);
}
}
// Ajout de pièces jointes
if (!empty($files)){
foreach ($files as $name => $file){
if (file_exists($file)){
$mail->addAttachment($file, $name);
}
}
}
// Ajout des CCI
if (!empty($cci)){
foreach ($cci as $nom => $adresseMail){
if (!empty($adresseMail)){
$mail->addBCC($adresseMail, $nom);
}
}
}
// Ajout des CC
if (!empty($cc)){
foreach ($cc as $nom => $adresseMail){
if (!empty($adresseMail)){
$mail->addCC($adresseMail, $nom);
}
}
}
$mail->Subject = $subject;
$mail->MsgHTML($body);
//Replace the plain text body with one created manually
$mail->AltBody = '';
if (!$mail->send()) {
// echo "Mailer Error: " . $mail->ErrorInfo;
} else {
// echo "Message sent!";
}
}
*/
/**
* @param string $file
* @param int $angle
* @param string $newName
*
* @return bool
*/
function rotateImage( string $file, int $angle, string $newName ) {
// Initialisation variable pou test futur
$image = null;
$type = mime_content_type( $file );
// Création ressources en fonction de l'image
switch ( substr( $type, 6 ) ) {
case 'jpeg':
$image = imagecreatefromjpeg( $file );
break;
case 'png':
$image = imagecreatefrompng( $file );
break;
}
// Si format image non prit en charge
if ( $image == null ) {
return false;
}
// Rotation de l'image
$rotate = imagerotate( $image, $angle, 0 );
// On recrée l'image au format de base
switch ( substr( $type, 6 ) ) {
case 'jpeg':
imagejpeg( $rotate, $file );
break;
case 'png':
imagepng( $rotate, $file );
break;
}
imagedestroy( $image );
imagedestroy( $rotate );
rename( $file, $newName );
return true;
}
/**
* @param array $data
*
* @return array
* Clean toutes les strings dans array en récursif, et filtre pour n'avoir qu'un espaces entre chaque mot
*/
function cleanArray( array $data ) {
if ( !empty( $data ) ) {
foreach ( $data as $key => $donnée ) {
switch ( gettype( $donnée ) ) {
case 'string':
if ( !empty( $donnée ) ) {
$new_string = '';
foreach ( explode( ' ', trim( $donnée ) ) as $str ) {
if ( !empty( $str ) ) {
if ( $new_string != '' ) {
$new_string .= ' ';
}
$new_string .= $str;
}
}
$data[ $key ] = $new_string;
}
break;
case 'array':
if ( !empty( $donnée ) ) {
$data[ $key ] = cleanArray( $donnée );
}
break;
}
}
}
return $data;
}
/**
* @param $array
*
* @return mixed
*/
function endKey( $array ) {
end( $array );
return key( $array );
}
?>

View File

@ -1,49 +0,0 @@
<?php
/**
* PHPMailer SPL autoloader.
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* PHPMailer SPL autoloader.
*
* @param string $classname The name of the class to load
*/
function PHPMailerAutoload( $classname ) {
//Can't use __DIR__ as it's only in PHP 5.3+
$filename = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class.' . strtolower( $classname ) . '.php';
if ( is_readable( $filename ) ) {
require $filename;
}
}
if ( version_compare( PHP_VERSION, '5.1.2', '>=' ) ) {
//SPL autoloading was introduced in PHP 5.1.2
if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
spl_autoload_register( 'PHPMailerAutoload', true, true );
} else {
spl_autoload_register( 'PHPMailerAutoload' );
}
} else {
/**
* Fall back to traditional autoload for old PHP versions
*
* @param string $classname The name of the class to load
*/
function __autoload( $classname ) {
PHPMailerAutoload( $classname );
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//FR" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body class="body" style="background-color: whitesmoke !important;padding: 40px 0;line-height: 22px;width: 100%;">
<div class="contain"
style="background-color: white;font-family: Arial, Helvetica, sans-serif; font-size: 16px;margin: auto;padding: 20px;max-width: 500px;width: 90%">
</div>
<div style="margin:20px auto;max-width: 500px;text-align: center;width: 90%;">
</div>
</body>
</html>

View File

@ -1,5 +1,5 @@
<div class="row" style="margin-bottom: 0"> <div class="row" style="margin-bottom: 0; display: flex;">
<div class="col l3 m4 s6 green lighten-1 white-text" style="height: 750px;"> <div class="col l3 m4 s6 green lighten-1 white-text" style="min-height: 750px;">
<div class="row"> <div class="row">
<div class="col s12 center-align"> <div class="col s12 center-align">
<h5 id="exercise-title">Selected part of the body</h5> <h5 id="exercise-title">Selected part of the body</h5>

View File

@ -44,11 +44,11 @@
<body class="grey lighten-4"> <body class="grey lighten-4">
<ul id="user" class="dropdown-content"> <ul id="user" class="dropdown-content">
<li><a id="change-name">Change Your Name</a></li> <li id="change-name"><a>Change Your Name</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a>Your Exercises</a></li> <li id="your-exercise"><a>Your Exercises</a></li>
<li class="divider"></li> <!-- <li class="divider"></li>-->
<li><a>Your Training</a></li> <!-- <li><a>Your Training</a></li>-->
</ul> </ul>
<div class="navbar-fixed"> <div class="navbar-fixed">

View File

@ -63,3 +63,7 @@
height: 30px; height: 30px;
cursor: pointer; cursor: pointer;
} }
.center-align:last-child {
margin-bottom: 30px;
}

View File

@ -243,10 +243,11 @@ let Point = ( function () {
} else { } else {
favStorage = {}; favStorage = {};
} }
let fav = favStorage[ $elem.data( "id" ) ];
main.html( ` main.html( `
<div data-id="${ $elem.data( "id" ) }" data-fav="false" class="right favorite"> <div data-id="${ $elem.data( "id" ) }" data-fav="false" class="right favorite">
<img src="/img/${ true ? "no-" : "" }favorite.png" alt=""> <img src="/img/${ fav ? "" : "no-" }favorite.png" alt="">
</div> </div>
<h2>${ data.title }</h2> <h2>${ data.title }</h2>
<div class="center-align"> <div class="center-align">
@ -343,7 +344,7 @@ $( document ).ready( () => {
$( "a[data-target=user]" ).html( userName + `<i class="material-icons right">arrow_drop_down</i>` ); $( "a[data-target=user]" ).html( userName + `<i class="material-icons right">arrow_drop_down</i>` );
} }
$( document ).on( "click", "#change-name", function () { $( document ).on( "click", "#change-name", () => {
let modal = $( "#modal" ); let modal = $( "#modal" );
modal.find( ".md-title" ).text( "Change Your Name" ); modal.find( ".md-title" ).text( "Change Your Name" );
@ -382,4 +383,41 @@ $( document ).ready( () => {
modal.addClass( "md-show" ); modal.addClass( "md-show" );
} ); } );
$( document ).on( "click", "#your-exercise", function () {
let favStorage = localStorage.getItem( "fav" );
let exercisesStorage = localStorage.getItem( "exercises" );
let main = $( "#main-container" );
main.empty();
if ( favStorage ) {
localStorage = JSON.parse( favStorage );
console.log( favStorage );
if ( exercisesStorage ) {
exercisesStorage = JSON.parse( exercisesStorage );
}
for ( let id in favStorage ) {
if ( favStorage.hasOwnProperty( id ) ) {
if ( favStorage[ id ] ) {
if ( exercisesStorage.hasOwnProperty( id ) ) {
main.append( `
<div data-id="${ id }" data-fav="false" class="right favorite">
<img src="/img/favorite.png" alt="">
</div>
<h2>${ exercisesStorage[ id ].title }</h2>
<div class="center-align">
<iframe width="560" height="315" src="${ exercisesStorage[ id ].video.replace( "https://youtu.be/", "https://www.youtube.com/embed/" ) }" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
<div class="exercise-info-container blue-grey lighten-4 left-align">${ ( exercisesStorage[ id ].description ? exercisesStorage[ id ].description : "" ) }</div>
</div>
` );
}
}
}
}
} else {
}
} );
} ); } );