Add a lot

This commit is contained in:
Mathieu Sanchez 2018-11-27 13:59:21 +09:00
parent d9e043c468
commit 561bfbf475
37 changed files with 8589 additions and 7952 deletions

View File

@ -10,12 +10,15 @@ RewriteRule ^ - [L]
# RewriteCond %{HTTP_HOST} ^eldotravo.fr$ # RewriteCond %{HTTP_HOST} ^eldotravo.fr$
# RewriteRule ^(.*)$ http://www.eldotravo.fr/$1 [R=301,L,E=END:1] # RewriteRule ^(.*)$ http://www.eldotravo.fr/$1 [R=301,L,E=END:1]
# Redirection des fichiers static pour contact.sanchez-mathieu.dev # Redirection des fichiers static pour contact.sanchez-mathieu.test
RewriteCond %{HTTP_HOST} ^contact.sanchez-mathieu.dev$ RewriteCond %{HTTP_HOST} ^contact.sanchez-mathieu.test
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI} -f RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI} -f
RewriteRule ^(.*)$ static/$1 [L,E=END:1] RewriteRule ^(.*)$ static/$1 [L,E=END:1]
# RewriteRule ^haute-garonne/toulouse/installation-entretien-climatisation /haute-garonne/toulouse/climatisation.php [L] # Redirection des fichiers static pour contact.sanchez-mathieu.fr
RewriteCond %{HTTP_HOST} ^contact.sanchez-mathieu.fr
RewriteCond %{DOCUMENT_ROOT}/static%{REQUEST_URI} -f
RewriteRule ^(.*)$ static/$1 [L,E=END:1]
# Redirection de toutes les requêtes vers Index.php # Redirection de toutes les requêtes vers Index.php
RewriteRule ^ index.php [L,E=END:1] RewriteRule ^ index.php [L,E=END:1]

View File

@ -35,7 +35,7 @@ if ( count( $pages ) > 1 && $pages[ count( $pages ) - 1 ] == '' ) {
if ( $pages[0] == 'api' && isset( $pages[1] ) && preg_match( '#^([a-z]+)$#', $pages[1], $api1 ) && isset( $pages[2] ) && preg_match( '#^([a-z-]+)$#', $pages[2], $api2 ) ) { if ( $pages[0] == 'api' && isset( $pages[1] ) && preg_match( '#^([a-z]+)$#', $pages[1], $api1 ) && isset( $pages[2] ) && preg_match( '#^([a-z-]+)$#', $pages[2], $api2 ) ) {
new APIRouter( $api1[0], $api2[0] ); new APIRouter( $api1[0], $api2[0] );
} else if ( preg_match( '#^test\.dev$#', $_SERVER['SERVER_NAME'] ) ) { } else if ( preg_match( '#^contact.sanchez-mathieu\.test$#', $_SERVER[ 'SERVER_NAME' ] ) || preg_match( '#^contact.sanchez-mathieu\.fr#', $_SERVER[ 'SERVER_NAME' ] ) ) {
new SiteRouter( $pages ); new SiteRouter( $pages );
} else { } else {
new Error( 404 ); new Error( 404 );

201
src/API/APIContact.php Normal file
View File

@ -0,0 +1,201 @@
<?php
namespace CAUProject3Contact\API;
use CAUProject3Contact\Model\Contact;
class APIContact extends API {
private $declaredFunctions = [
'insert' => [
'method' => 'POST',
'params' => [
'firstName' => [
'required' => true,
'type' => 'string'
],
'lastName' => [
'required' => true,
'type' => 'string'
],
'surname' => [
'required' => false,
'type' => 'string'
],
'email' => [
'required' => false,
'type' => 'string'
],
'address' => [
'required' => false,
'type' => 'string'
],
'phoneNumber' => [
'required' => false,
'type' => 'string'
],
'birthday' => [
'required' => false,
'type' => 'string'
],
]
],
'delete' => [
'method' => 'POST',
'params' => [
'id' => [
'required' => true,
'type' => 'int'
]
]
],
'get-contacts' => [
'method' => 'GET',
'params' => []
],
'update' => [
'method' => 'POST',
'params' => [
'id' => [
'required' => true,
'type' => 'int'
],
'firstName' => [
'required' => false,
'type' => 'string'
],
'lastName' => [
'required' => false,
'type' => 'string'
],
'surname' => [
'required' => false,
'type' => 'string'
],
'email' => [
'required' => false,
'type' => 'string'
],
'address' => [
'required' => false,
'type' => 'string'
],
'phoneNumber' => [
'required' => false,
'type' => 'string'
],
'birthday' => [
'required' => false,
'type' => 'string'
]
]
],
'search' => [
'method' => 'POST',
'params' => [
'query' => [
'required' => true,
'type' => 'string'
]
]
]
];
/**
* APIContact constructor.
*
* @param array $declaredFunctions
*/
public function __construct() {
parent::__construct( $this->declaredFunctions );
}
/**
* @return array
*/
public function getDeclaredFunctions() {
return $this->declaredFunctions;
}
public function insert( array $data ) {
$id = Contact::insertNewContact( $data[ "firstName" ], $data[ "lastName" ], $data[ "surname" ],
$data[ "email" ], $data[ "address" ], $data[ "phoneNumber" ], $data[ "birthday" ] );
$this->returnJson( json_encode( [
"status" => "success",
"data" => [
"id" => $id
]
] ) );
}
public function delete( array $data ) {
Contact::deleteContact( $data[ "id" ] );
}
public function getContacts() {
$this->returnJson( json_encode( [
"contacts" => Contact::getAllContact()
] ) );
}
public function update( array $data ) {
$contact = Contact::getById( $data[ "id" ] );
$newData = [];
if ( $data[ "firstName" ] !== null && $data[ "firstName" ] !== "" ) {
$newData[ "first_name" ] = $data[ "firstName" ];
}
if ( $data[ "lastName" ] !== null && $data[ "lastName" ] !== "" ) {
$newData[ "last_name" ] = $data[ "lastName" ];
}
if ( $data[ "surname" ] !== null && $data[ "surname" ] !== "" ) {
$newData[ "surname" ] = $data[ "surname" ];
}
if ( $data[ "email" ] !== null && $data[ "email" ] !== "" ) {
$newData[ "email" ] = $data[ "email" ];
}
if ( $data[ "address" ] !== null && $data[ "address" ] !== "" ) {
$newData[ "address" ] = $data[ "address" ];
}
if ( $data[ "phoneNumber" ] !== null && $data[ "phoneNumber" ] !== "" ) {
$newData[ "phone_number" ] = $data[ "phoneNumber" ];
}
if ( $data[ "birthday" ] !== null && $data[ "birthday" ] !== "" ) {
$newData[ "birthday" ] = date( "Y-m-d", strtotime( $data[ "birthday" ] ) );
}
$contact->updateContact( $newData );
$this->returnJson( json_encode( $contact ) );
}
public function search( array $data ) {
if ( count_chars( $data[ "query" ] ) >= 3 ) {
$result = Contact::search( $data[ "query" ] );
if ( $result !== null ) {
$this->returnJson( [
"status" => "success",
"code" => 200,
"result" => $result,
] );
} else {
$this->returnJson( [
"status" => "error",
"code" => 404,
"message" => "Nothing find",
] );
}
} else {
$this->returnJson( [
"status" => "error",
"code" => 400,
"message" => "Need at least 3 chars",
] );
}
}
}
?>

View File

@ -14,7 +14,8 @@ class APIError extends Controller {
* @param string $publicMessage * @param string $publicMessage
* @param string $code * @param string $code
*/ */
public function __construct( int $ErrCode = 500, string $devMessage = 'Erreur inconnue', string $publicMessage = 'Une erreur inconnue s\'est produite', string $code = '' ) { public function __construct( int $ErrCode = 500, string $devMessage = 'Erreur inconnue',
string $publicMessage = 'Une erreur inconnue s\'est produite', string $code = '' ) {
parent::__construct(); parent::__construct();
$tabCode = [ $tabCode = [

View File

@ -3,12 +3,12 @@
namespace CAUProject3Contact; namespace CAUProject3Contact;
class Config { class Config {
const SITE_JS_VERSION = '1.00'; const SITE_JS_VERSION = '0.01';
const SITE_CSS_VERSION = '1.00'; const SITE_CSS_VERSION = '0.01';
const TITLE_HEADER = 'Your contact'; const TITLE_HEADER = 'Your contact';
const DESCRIPTION_HEADER = 'Manage your contact easly'; const DESCRIPTION_HEADER = 'Manage your contact easly';
const NAMESPACE = 'CAUProject3Contact'; const NAMESPACE = 'CAUProject3Contact';
const FAVICON_PATH = '/img/favicon.png'; const FAVICON_PATH = '/img/favicon.ico';
} }

View File

@ -3,6 +3,7 @@
namespace CAUProject3Contact\Controller\Site; namespace CAUProject3Contact\Controller\Site;
use CAUProject3Contact\Controller\ControllerSite; use CAUProject3Contact\Controller\ControllerSite;
use CAUProject3Contact\Model\Contact;
class Index extends ControllerSite { class Index extends ControllerSite {
@ -12,14 +13,15 @@ class Index extends ControllerSite {
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->addHead( [ $this->addHead( [] );
$this->addFooter( [] );
$contacts = Contact::getAllContact();
$this->addData( [
"contacts" => $contacts
] ); ] );
$this->addFooter( [
] );
$this->addData( [] );
$this->view(); $this->view();
} }
} }

View File

@ -6,10 +6,18 @@ use Exception;
use PDO; use PDO;
class BDD { class BDD {
const SQL_SERVER = 'sql.sanchez-mathieu.fr'; // BDD Server
const SQL_LOGIN = 'why7n0_contact'; // BDD Login // Server BDD
const SQL_PASSWORD = 'fC3c87Gy'; // BDD Password // const SQL_SERVER = 'sql.sanchez-mathieu.fr'; // BDD Server
const SQL_DB = 'why7n0_contact'; // BDD Name // const SQL_LOGIN = 'why7n0_contact'; // BDD Login
// const SQL_PASSWORD = 'fC3c87Gy'; // BDD Password
// const SQL_DB = 'why7n0_contact'; // BDD Name
// Local BDD
const SQL_SERVER = 'localhost'; // BDD Server
const SQL_LOGIN = 'root'; // BDD Login
const SQL_PASSWORD = ''; // BDD Password
const SQL_DB = 'contact'; // BDD Name
private static $bdd; private static $bdd;

View File

@ -8,6 +8,7 @@ abstract class BDTables {
// Ex : const ABONNEMENT = 'abonnement'; // Ex : const ABONNEMENT = 'abonnement';
const LOGS = "logs"; const LOGS = "logs";
const CONTACT = "contact";
} }
?> ?>

220
src/Model/Contact.php Normal file
View File

@ -0,0 +1,220 @@
<?php
namespace CAUProject3Contact\Model;
class Contact {
public $id;
public $firstName;
public $lastName;
public $surname;
public $email;
public $address;
public $phoneNumber;
public $birthday;
// Constructors
public function __construct( int $id = null, string $firstName = null, string $lastName = null,
string $surname = null, string $email = null, string $address = null,
string $phoneNumber = null, string $birthday = null ) {
if ( $id === null || $firstName === null || $lastName === null ) {
return;
}
$this->id = $id;
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->surname = $surname;
$this->email = $email;
$this->address = $address;
$this->phoneNumber = $phoneNumber;
$this->birthday = $birthday;
}
public static function getById( int $id ) {
$req = BDD::instance()->prepare( "SELECT * FROM " . BDTables::CONTACT .
" WHERE `id` = :id" );
$req->execute( [ "id" => $id ] );
$d = $req->fetch();
return new Contact( $d[ "id" ], $d[ "first_name" ], $d[ "last_name" ], $d[ "surname" ],
$d[ "email" ], $d[ "address" ], $d[ "phone_number" ], $d[ "birthday" ] );
}
// Getters
public static function insertNewContact( string $firstName, string $lastName, string $surname = null,
string $email = null,
string $address = null, string $phoneNumber = null,
string $birthday = null ) {
$data = [
"first_name" => $firstName,
"last_name" => $lastName,
];
if ( $surname !== null && $surname !== "" ) {
$data[ "surname" ] = $surname;
}
if ( $email !== null && $email !== "" ) {
$data[ "email" ] = $email;
}
if ( $address !== null && $address !== "" ) {
$data[ "address" ] = $address;
}
if ( $phoneNumber !== null && $phoneNumber !== "" ) {
$data[ "phone_number" ] = $phoneNumber;
}
if ( $birthday !== null && $birthday !== "" ) {
$data[ "birthday" ] = date( "Y-m-d", strtotime( $birthday ) );
}
return Model::insert( BDTables::CONTACT, $data );
}
public static function deleteContact( int $id ) {
Model::delete( BDTables::CONTACT, [ "id" => $id ] );
}
public static function getAllContact(): array {
$contacts = [];
$req = BDD::instance()->prepare( "SELECT * FROM " . BDTables::CONTACT );
$req->execute();
foreach ( $req->fetchAll() as $c ) {
$contacts[] = new Contact( $c[ "id" ], $c[ "first_name" ], $c[ "last_name" ], $c[ "surname" ],
$c[ "email" ], $c[ "address" ], $c[ "phone_number" ], $c[ "birthday" ] );
}
return ( count( $contacts ) > 0 ? $contacts : null );
}
public static function search( string $query ) {
$result = [];
$words = explode( " ", cleanString( $query ) );
$q1 = $q2 = $q3 = $q4 = "SELECT * FROM `" . BDTables::CONTACT . "` WHERE ";
$lastKey = endKey( $words );
foreach ( $words as $key => $word ) {
$normal = self::getQuerySearch( $word, [ "first_name", "last_name", "surname" ] );;
$hard = self::getQuerySearch( $word, [ "email", "address", "phone_number" ] );
$q1 .= $normal;
$q2 .= $normal;
$q3 .= $hard;
$q4 .= $hard;
if ( $key != $lastKey ) {
$q1 .= " AND ";
$q2 .= " OR ";
$q3 .= " AND ";
$q4 .= " OR ";
}
}
$req1 = BDD::instance()->prepare( $q1 );
$req2 = BDD::instance()->prepare( $q2 );
$req3 = BDD::instance()->prepare( $q3 );
$req4 = BDD::instance()->prepare( $q4 );
$req1->execute();
$req2->execute();
$req3->execute();
$req4->execute();
$tmp1 = $req1->fetchAll();
$tmp2 = filterArrays( $tmp1, $req2->fetchAll() );
$tmp3 = filterArrays( $tmp1, filterArrays( $tmp2, $req3->fetchAll() ) );
$tmp4 = filterArrays( $tmp1, filterArrays( $tmp2, filterArrays( $tmp3, $req4->fetchAll() ) ) );
if ( count( $tmp1 ) > 0 || count( $tmp2 ) > 0 || count( $tmp3 ) > 0 || count( $tmp4 ) > 0 ) {
$result[ "1" ] = ( count( $tmp1 ) > 0 ? $tmp1 : null );
$result[ "2" ] = ( count( $tmp2 ) > 0 ? $tmp2 : null );
$result[ "3" ] = ( count( $tmp3 ) > 0 ? $tmp3 : null );
$result[ "4" ] = ( count( $tmp4 ) > 0 ? $tmp4 : null );
return $result;
}
return null;
}
private static function getQuerySearch( string $word, array $fields ): string {
$str = '';
$i = 0;
foreach ( $fields as $field ) {
if ( $i === 0 ) {
$str .= "(";
} else {
$str .= " OR ";
}
$str .= "`" . $field . "` LIKE '%" . $word . "%'";
$i++;
}
$str .= ')';
return $str;
}
/**
* @return string
*/
public function getFirstName(): string {
return $this->firstName;
}
/**
* @return string
*/
public function getLastName(): string {
return $this->lastName;
}
/**
* @return string
*/
public function getSurname() {
return $this->surname;
}
// Method
/**
* @return string
*/
public function getEmail() {
return $this->email;
}
// Static functions
/**
* @return string
*/
public function getAddress() {
return $this->address;
}
/**
* @return string
*/
public function getPhoneNumber() {
return $this->phoneNumber;
}
/**
* @return string
*/
public function getBirthday() {
return $this->birthday;
}
public function updateContact( array $data ) {
foreach ( $data as $key => $value ) {
$this->{$key} = $value;
}
Model::update( BDTables::CONTACT, $data, "id", $this->getId() );
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
}
?>

View File

@ -41,7 +41,8 @@ class Logs {
* @param string|null $line * @param string|null $line
* @param string|null $date * @param string|null $date
*/ */
public function __construct( int $id = null, string $level = null, string $message = null, string $file = null, string $line = null, string $date = null ) { public function __construct( int $id = null, string $level = null, string $message = null, string $file = null,
string $line = null, string $date = null ) {
if ( $id === null ) { if ( $id === null ) {
return; return;
} }

View File

@ -45,6 +45,22 @@ class Model {
$req = BDD::instance()->prepare( $reqStr ); $req = BDD::instance()->prepare( $reqStr );
$req->execute( $data ); $req->execute( $data );
} }
public static function delete( string $tableName, array $conditions ) {
$reqStr = 'DELETE FROM ' . $tableName . ' WHERE ';
$lastKey = endKey( $conditions );
foreach ( $conditions as $key => $value ) {
$reqStr .= $key . ' = :' . $key;
if ( $key != $lastKey ) {
$reqStr .= ' AND ';
}
}
$req = BDD::instance()->prepare( $reqStr );
$req->execute( $conditions );
}
} }
?> ?>

View File

@ -1,3 +1,39 @@
<div> <div class="section scrollspy">
Bonjour 2
<div class="row">
<div class="col s12 main-container">
<table class="highlight centered">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Surname</th>
<th>Email</th>
<th>Address</th>
<th>Phone Number</th>
<th>Birthday</th>
</tr>
</thead>
<tbody>
<?php
foreach ( $contacts as $contact ) {
echo "<tr>";
echo " <td>" . $contact->getFirstName() . "</td>";
echo " <td>" . $contact->getLastName() . "</td>";
echo " <td>" . ( $contact->getSurname() ? $contact->getSurname() : "" ) . "</td>";
echo " <td>" . ( $contact->getEmail() ? $contact->getEmail() : "" ) . "</td>";
echo " <td>" . ( $contact->getAddress() ? $contact->getAddress() : "" ) . "</td>";
echo " <td>" . ( $contact->getPhoneNumber() ? $contact->getPhoneNumber() : "" ) . "</td>";
echo " <td>" . ( $contact->getBirthday() ? date( "Y-m-d", strtotime( $contact->getBirthday() ) ) : "" ) . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</div> </div>
</div>
</div>
<script>
let contacts = <?= json_encode( $contacts ) ?>;
</script>

View File

@ -1,5 +1,32 @@
<script src="/js/jquery-3.2.1.min.js"></script> </div>
<script src="/js/javascript.js?v=<?= CAUProject3Contact\Config::SITE_JS_VERSION ?>"></script> </main>
<div id="modal" class="modal modal-fixed-footer">
<div class="modal-content">
<h4>Add new contact</h4>
<p>Test</p>
</div>
<div class="modal-footer">
<a class="waves-effect waves-green btn-flat">Validate</a>
<a class="waves-effect waves-red btn-flat">Cancel</a>
</div>
</div>
<footer class="page-footer blue">
<div class="footer-copyright">
<div class="container">
Made by <a class="blue-text text-lighten-3" target="_blank" href="https://www.sanchez-mathieu.fr">Mathieu
Sanchez</a>
</div>
</div>
</footer>
<script src="/js/jquery-3.3.1.min.js"></script>
<script async src="/js/materialize.min.js"></script>
<script async src="/js/javascript.js?v=<?= CAUProject3Contact\Config::SITE_JS_VERSION ?>"></script>
<link href="/css/materialize.min.css" rel="stylesheet">
<link href="/css/style.css?v=<?= CAUProject3Contact\Config::SITE_CSS_VERSION ?>" rel="stylesheet"> <link href="/css/style.css?v=<?= CAUProject3Contact\Config::SITE_CSS_VERSION ?>" rel="stylesheet">
</body> </body>

View File

@ -1,16 +1,18 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="manifest" href="/manifest.json"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- <link rel="manifest" href="/manifest.json">-->
<meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" id="status-bar" content="white-translucent"> <meta name="apple-mobile-web-app-status-bar-style" id="status-bar" content="white-translucent">
<meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="telephone=no">
<meta name="author" content="Eldotravo"> <meta name="author" content="Mathieu Sanchez">
<title><?= $this->head[ 'title' ] ?></title> <title><?= $this->head[ 'title' ] ?></title>
<meta name="description" content="<?= $this->head[ 'description' ] ?>"> <meta name="description" content="<?= $this->head[ 'description' ] ?>">
@ -18,17 +20,15 @@
<meta property="og:title" content="<?= $this->head[ 'title' ] ?>"/> <meta property="og:title" content="<?= $this->head[ 'title' ] ?>"/>
<meta property="og:description" content="<?= $this->head[ 'description' ] ?>"/> <meta property="og:description" content="<?= $this->head[ 'description' ] ?>"/>
<meta property="og:url" content="https://<?= $_SERVER[ 'SERVER_NAME' ] . $_SERVER[ 'REQUEST_URI' ] ?>"/> <meta property="og:url" content="https://<?= $_SERVER[ 'SERVER_NAME' ] . $_SERVER[ 'REQUEST_URI' ] ?>"/>
<meta property="og:image" content="https://<?= $_SERVER['SERVER_NAME'] . \CAUProject3Contact\Config::FAVICON_PATH ?>"/> <meta property="og:image"
content="https://<?= $_SERVER[ 'SERVER_NAME' ] . \CAUProject3Contact\Config::FAVICON_PATH ?>"/>
<!-- <meta property="fb:app_id" content="1000452166691027" /> --> <!-- <meta property="fb:app_id" content="1000452166691027" /> -->
<link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700%7CRoboto+Condensed:400,700%7CMaterial+Icons' <link href='https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700%7CRoboto+Condensed:400,700%7CMaterial+Icons'
rel='stylesheet' type='text/css'> rel='stylesheet' type='text/css'>
<link href="/css/theme.css?v=<?= CAUProject3Contact\Config::SITE_CSS_VERSION ?>" rel="stylesheet"> <link rel="image_src" href="<?= CAUProject3Contact\Config::FAVICON_PATH ?>"/>
<link href="/css/select2.css" rel="stylesheet"> <link rel="icon" type="image/ico" href="<?= CAUProject3Contact\Config::FAVICON_PATH ?>"/>
<link rel="image_src" href="<?php \CAUProject3Contact\Config::FAVICON_PATH ?>"/>
<link rel="icon" type="image/png" href="<?php \CAUProject3Contact\Config::FAVICON_PATH ?>"/>
<meta name="theme-color" content="#ffffff"> <meta name="theme-color" content="#ffffff">
@ -39,3 +39,28 @@
</head> </head>
<body> <body>
<nav class="blue" role="navigation">
<div class="nav-wrapper container">
<a id="logo-container" class="brand-logo">
<img src="/img/logo.png" alt="Logo of Your Contact" height="64px"/>
</a>
<ul class="right hide-on-med-and-down">
<li>
<a class="nav-search"><input type="text" placeholder="Search Contact" id="search" name="search"/></a>
</li>
<li data-position="bottom" data-tooltip="Add a new contact">
<a class="nav-add"><img class="add-contacts" src="/img/add-contacts.png" alt="Add contact"></a>
</li>
</ul>
<!-- <ul id="nav-mobile" class="sidenav">-->
<!-- <li><a href="#">Navbar Link</a></li>-->
<!-- </ul>-->
<!-- <a href="#" data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></a>-->
</div>
</nav>
<main>
<div class="container">

View File

@ -369,27 +369,18 @@ function rotateImage( string $file, int $angle, string $newName ) {
* @return array * @return array
* Clean toutes les strings dans array en récursif, et filtre pour n'avoir qu'un espaces entre chaque mot * Clean toutes les strings dans array en récursif, et filtre pour n'avoir qu'un espaces entre chaque mot
*/ */
function cleanArray( array $data ) { function cleanArray( array $data ): array {
if ( !empty( $data ) ) { if ( !empty( $data ) ) {
foreach ( $data as $key => $donnée ) { foreach ( $data as $key => $value ) {
switch ( gettype( $donnée ) ) { switch ( gettype( $value ) ) {
case 'string': case 'string':
if ( ! empty( $donnée ) ) {
$new_string = '';
foreach ( explode( ' ', trim( $donnée ) ) as $str ) {
if ( !empty( $str ) ) { if ( !empty( $str ) ) {
if ( $new_string != '' ) { $data[ $key ] = cleanString( $value );
$new_string .= ' ';
}
$new_string .= $str;
}
}
$data[ $key ] = $new_string;
} }
break; break;
case 'array': case 'array':
if ( ! empty( $donnée ) ) { if ( !empty( $value ) ) {
$data[ $key ] = cleanArray( $donnée ); $data[ $key ] = cleanArray( $value );
} }
break; break;
} }
@ -399,6 +390,19 @@ function cleanArray( array $data ) {
return $data; return $data;
} }
function cleanString( string $str ): string {
$newStr = '';
foreach ( explode( ' ', trim( $str ) ) as $word ) {
if ( !empty( $word ) && $word != '' ) {
if ( $newStr != '' ) {
$newStr .= ' ';
}
$newStr .= $word;
}
}
return $newStr;
}
/** /**
* @param $array * @param $array
* *
@ -410,4 +414,22 @@ function endKey( $array ) {
return key( $array ); return key( $array );
} }
function filterArrays( $array1, $array2 ): array {
$newArray = [];
foreach ( $array2 as $item2 ) {
$add = true;
foreach ( $array1 as $item1 ) {
if ( $item2[ "id" ] == $item1[ "id" ] ) {
$add = false;
}
}
if ( $add ) {
$newArray[] = $item2;
}
}
return $newArray;
}
?> ?>

View File

@ -964,6 +964,106 @@ class PHPMailer {
return $addresses; return $addresses;
} }
/**
* Check that a string looks like an email address.
*
* @param string $address The email address to check
* @param string $patternselect A selector for the validation pattern to use :
* * `auto` Pick best pattern automatically;
* * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
* * `pcre` Use old PCRE implementation;
* * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
* * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
* * `noregex` Don't use a regex: super fast, really dumb.
*
* @return boolean
* @static
* @access public
*/
public static function validateAddress( $address, $patternselect = 'auto' ) {
//Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
if ( strpos( $address, "\n" ) !== false or strpos( $address, "\r" ) !== false ) {
return false;
}
if ( !$patternselect or $patternselect == 'auto' ) {
//Check this constant first so it works when extension_loaded() is disabled by safe mode
//Constant was added in PHP 5.2.4
if ( defined( 'PCRE_VERSION' ) ) {
//This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
if ( version_compare( PCRE_VERSION, '8.0.3' ) >= 0 ) {
$patternselect = 'pcre8';
} else {
$patternselect = 'pcre';
}
} elseif ( function_exists( 'extension_loaded' ) and extension_loaded( 'pcre' ) ) {
//Fall back to older PCRE
$patternselect = 'pcre';
} else {
//Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
if ( version_compare( PHP_VERSION, '5.2.0' ) >= 0 ) {
$patternselect = 'php';
} else {
$patternselect = 'noregex';
}
}
}
switch ( $patternselect ) {
case 'pcre8':
/**
* Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
* @link http://squiloople.com/2009/12/20/email-address-validation/
* @copyright 2009-2010 Michael Rushton
* Feel free to use and redistribute this code. But please keep this copyright notice.
*/
return (boolean)preg_match(
'/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
'((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
'(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
'([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
'(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
'(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
'|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
'|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
'|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
$address
);
case 'pcre':
//An older regex that doesn't need a recent PCRE
return (boolean)preg_match(
'/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
'[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
'(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
'@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
'(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
'[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
'::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
'[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
'::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
'|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
$address
);
case 'html5':
/**
* This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
* @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
*/
return (boolean)preg_match(
'/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
'[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
$address
);
case 'noregex':
//No PCRE! Do something _very_ approximate!
//Check the address is 3 chars or longer and contains an @ that's not the first or last char
return ( strlen( $address ) >= 3
and strpos( $address, '@' ) >= 1
and strpos( $address, '@' ) != strlen( $address ) - 1 );
case 'php':
default:
return (boolean)filter_var( $address, FILTER_VALIDATE_EMAIL );
}
}
/** /**
* Set the From and FromName properties. * Set the From and FromName properties.
* *
@ -1536,6 +1636,176 @@ class PHPMailer {
} }
} }
/**
* Word-wrap message.
* For use with mailers that do not automatically perform wrapping
* and for quoted-printable encoded messages.
* Original written by philippe.
*
* @param string $message The message to wrap
* @param integer $length The line length to wrap to
* @param boolean $qp_mode Whether to run in Quoted-Printable mode
*
* @access public
* @return string
*/
public function wrapText( $message, $length, $qp_mode = false ) {
if ( $qp_mode ) {
$soft_break = sprintf( ' =%s', $this->LE );
} else {
$soft_break = $this->LE;
}
// If utf-8 encoding is used, we will need to make sure we don't
// split multibyte characters when we wrap
$is_utf8 = ( strtolower( $this->CharSet ) == 'utf-8' );
$lelen = strlen( $this->LE );
$crlflen = strlen( self::CRLF );
$message = $this->fixEOL( $message );
//Remove a trailing line break
if ( substr( $message, -$lelen ) == $this->LE ) {
$message = substr( $message, 0, -$lelen );
}
//Split message into lines
$lines = explode( $this->LE, $message );
//Message will be rebuilt in here
$message = '';
foreach ( $lines as $line ) {
$words = explode( ' ', $line );
$buf = '';
$firstword = true;
foreach ( $words as $word ) {
if ( $qp_mode and ( strlen( $word ) > $length ) ) {
$space_left = $length - strlen( $buf ) - $crlflen;
if ( !$firstword ) {
if ( $space_left > 20 ) {
$len = $space_left;
if ( $is_utf8 ) {
$len = $this->utf8CharBoundary( $word, $len );
} elseif ( substr( $word, $len - 1, 1 ) == '=' ) {
$len--;
} elseif ( substr( $word, $len - 2, 1 ) == '=' ) {
$len -= 2;
}
$part = substr( $word, 0, $len );
$word = substr( $word, $len );
$buf .= ' ' . $part;
$message .= $buf . sprintf( '=%s', self::CRLF );
} else {
$message .= $buf . $soft_break;
}
$buf = '';
}
while ( strlen( $word ) > 0 ) {
if ( $length <= 0 ) {
break;
}
$len = $length;
if ( $is_utf8 ) {
$len = $this->utf8CharBoundary( $word, $len );
} elseif ( substr( $word, $len - 1, 1 ) == '=' ) {
$len--;
} elseif ( substr( $word, $len - 2, 1 ) == '=' ) {
$len -= 2;
}
$part = substr( $word, 0, $len );
$word = substr( $word, $len );
if ( strlen( $word ) > 0 ) {
$message .= $part . sprintf( '=%s', self::CRLF );
} else {
$buf = $part;
}
}
} else {
$buf_o = $buf;
if ( !$firstword ) {
$buf .= ' ';
}
$buf .= $word;
if ( strlen( $buf ) > $length and $buf_o != '' ) {
$message .= $buf_o . $soft_break;
$buf = $word;
}
}
$firstword = false;
}
$message .= $buf . self::CRLF;
}
return $message;
}
/**
* Ensure consistent line endings in a string.
* Changes every end of line from CRLF, CR or LF to $this->LE.
* @access public
*
* @param string $str String to fixEOL
*
* @return string
*/
public function fixEOL( $str ) {
// Normalise to \n
$nstr = str_replace( array( "\r\n", "\r" ), "\n", $str );
// Now convert LE as needed
if ( $this->LE !== "\n" ) {
$nstr = str_replace( "\n", $this->LE, $nstr );
}
return $nstr;
}
/**
* Find the last character boundary prior to $maxLength in a utf-8
* quoted-printable encoded string.
* Original written by Colin Brown.
* @access public
*
* @param string $encodedText utf-8 QP text
* @param integer $maxLength Find the last character boundary prior to this length
*
* @return integer
*/
public function utf8CharBoundary( $encodedText, $maxLength ) {
$foundSplitPos = false;
$lookBack = 3;
while ( !$foundSplitPos ) {
$lastChunk = substr( $encodedText, $maxLength - $lookBack, $lookBack );
$encodedCharPos = strpos( $lastChunk, '=' );
if ( false !== $encodedCharPos ) {
// Found start of encoded character byte within $lookBack block.
// Check the encoded byte value (the 2 chars after the '=')
$hex = substr( $encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2 );
$dec = hexdec( $hex );
if ( $dec < 128 ) {
// Single byte character.
// If the encoded char was found at pos 0, it will fit
// otherwise reduce maxLength to start of the encoded char
if ( $encodedCharPos > 0 ) {
$maxLength = $maxLength - ( $lookBack - $encodedCharPos );
}
$foundSplitPos = true;
} elseif ( $dec >= 192 ) {
// First byte of a multi byte character
// Reduce maxLength to split at start of character
$maxLength = $maxLength - ( $lookBack - $encodedCharPos );
$foundSplitPos = true;
} elseif ( $dec < 192 ) {
// Middle byte of a multi byte character, look further back
$lookBack += 3;
}
} else {
// No encoded character found
$foundSplitPos = true;
}
}
return $maxLength;
}
/** /**
* Detect if a string contains a line longer than the maximum line length allowed. * Detect if a string contains a line longer than the maximum line length allowed.
* *
@ -1772,6 +2042,196 @@ class PHPMailer {
return implode( '', $mime ); return implode( '', $mime );
} }
/**
* Encode a header string optimally.
* Picks shortest of Q, B, quoted-printable or none.
* @access public
*
* @param string $str
* @param string $position
*
* @return string
*/
public function encodeHeader( $str, $position = 'text' ) {
$matchcount = 0;
switch ( strtolower( $position ) ) {
case 'phrase':
if ( !preg_match( '/[\200-\377]/', $str ) ) {
// Can't use addslashes as we don't know the value of magic_quotes_sybase
$encoded = addcslashes( $str, "\0..\37\177\\\"" );
if ( ( $str == $encoded ) && !preg_match( '/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str ) ) {
return ( $encoded );
} else {
return ( "\"$encoded\"" );
}
}
$matchcount = preg_match_all( '/[^\040\041\043-\133\135-\176]/', $str, $matches );
break;
/** @noinspection PhpMissingBreakStatementInspection */
case 'comment':
$matchcount = preg_match_all( '/[()"]/', $str, $matches );
// Intentional fall-through
case 'text':
default:
$matchcount += preg_match_all( '/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches );
break;
}
//There are no chars that need encoding
if ( $matchcount == 0 ) {
return ( $str );
}
$maxlen = 75 - 7 - strlen( $this->CharSet );
// Try to select the encoding which should produce the shortest output
if ( $matchcount > strlen( $str ) / 3 ) {
// More than a third of the content will need encoding, so B encoding will be most efficient
$encoding = 'B';
if ( function_exists( 'mb_strlen' ) && $this->hasMultiBytes( $str ) ) {
// Use a custom function which correctly encodes and wraps long
// multibyte strings without breaking lines within a character
$encoded = $this->base64EncodeWrapMB( $str, "\n" );
} else {
$encoded = base64_encode( $str );
$maxlen -= $maxlen % 4;
$encoded = trim( chunk_split( $encoded, $maxlen, "\n" ) );
}
} else {
$encoding = 'Q';
$encoded = $this->encodeQ( $str, $position );
$encoded = $this->wrapText( $encoded, $maxlen, true );
$encoded = str_replace( '=' . self::CRLF, "\n", trim( $encoded ) );
}
$encoded = preg_replace( '/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded );
$encoded = trim( str_replace( "\n", $this->LE, $encoded ) );
return $encoded;
}
/**
* Check if a string contains multi-byte characters.
* @access public
*
* @param string $str multi-byte text to wrap encode
*
* @return boolean
*/
public function hasMultiBytes( $str ) {
if ( function_exists( 'mb_strlen' ) ) {
return ( strlen( $str ) > mb_strlen( $str, $this->CharSet ) );
} else { // Assume no multibytes (we can't handle without mbstring functions anyway)
return false;
}
}
/**
* Encode and wrap long multibyte strings for mail headers
* without breaking lines within a character.
* Adapted from a function by paravoid
* @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
* @access public
*
* @param string $str multi-byte text to wrap encode
* @param string $linebreak string to use as linefeed/end-of-line
*
* @return string
*/
public function base64EncodeWrapMB( $str, $linebreak = null ) {
$start = '=?' . $this->CharSet . '?B?';
$end = '?=';
$encoded = '';
if ( $linebreak === null ) {
$linebreak = $this->LE;
}
$mb_length = mb_strlen( $str, $this->CharSet );
// Each line must have length <= 75, including $start and $end
$length = 75 - strlen( $start ) - strlen( $end );
// Average multi-byte ratio
$ratio = $mb_length / strlen( $str );
// Base64 has a 4:3 ratio
$avgLength = floor( $length * $ratio * .75 );
for ( $i = 0; $i < $mb_length; $i += $offset ) {
$lookBack = 0;
do {
$offset = $avgLength - $lookBack;
$chunk = mb_substr( $str, $i, $offset, $this->CharSet );
$chunk = base64_encode( $chunk );
$lookBack++;
} while ( strlen( $chunk ) > $length );
$encoded .= $chunk . $linebreak;
}
// Chomp the last linefeed
$encoded = substr( $encoded, 0, -strlen( $linebreak ) );
return $encoded;
}
/**
* Encode a string using Q encoding.
* @link http://tools.ietf.org/html/rfc2047
*
* @param string $str the text to encode
* @param string $position Where the text is going to be used, see the RFC for what that means
*
* @access public
* @return string
*/
public function encodeQ( $str, $position = 'text' ) {
// There should not be any EOL in the string
$pattern = '';
$encoded = str_replace( array( "\r", "\n" ), '', $str );
switch ( strtolower( $position ) ) {
case 'phrase':
// RFC 2047 section 5.3
$pattern = '^A-Za-z0-9!*+\/ -';
break;
/** @noinspection PhpMissingBreakStatementInspection */
case 'comment':
// RFC 2047 section 5.2
$pattern = '\(\)"';
// intentional fall-through
// for this reason we build the $pattern without including delimiters and []
case 'text':
default:
// RFC 2047 section 5.1
// Replace every high ascii, control, =, ? and _ characters
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
break;
}
$matches = array();
if ( preg_match_all( "/[{$pattern}]/", $encoded, $matches ) ) {
// If the string contains an '=', make sure it's the first thing we replace
// so as to avoid double-encoding
$eqkey = array_search( '=', $matches[ 0 ] );
if ( false !== $eqkey ) {
unset( $matches[ 0 ][ $eqkey ] );
array_unshift( $matches[ 0 ], '=' );
}
foreach ( array_unique( $matches[ 0 ] ) as $char ) {
$encoded = str_replace( $char, '=' . sprintf( '%02X', ord( $char ) ), $encoded );
}
}
// Replace every spaces to _ (more readable than =20)
return str_replace( ' ', '_', $encoded );
}
/**
* Strip newlines to prevent header injection.
* @access public
*
* @param string $str
*
* @return string
*/
public function secureHeader( $str ) {
return trim( str_replace( array( "\r", "\n" ), '', $str ) );
}
/** /**
* Check if an error occurred. * Check if an error occurred.
* @access public * @access public
@ -2595,366 +3055,6 @@ class PHPMailer {
return $result; return $result;
} }
/**
* Strip newlines to prevent header injection.
* @access public
*
* @param string $str
*
* @return string
*/
public function secureHeader( $str ) {
return trim( str_replace( array( "\r", "\n" ), '', $str ) );
}
/**
* Encode a header string optimally.
* Picks shortest of Q, B, quoted-printable or none.
* @access public
*
* @param string $str
* @param string $position
*
* @return string
*/
public function encodeHeader( $str, $position = 'text' ) {
$matchcount = 0;
switch ( strtolower( $position ) ) {
case 'phrase':
if ( ! preg_match( '/[\200-\377]/', $str ) ) {
// Can't use addslashes as we don't know the value of magic_quotes_sybase
$encoded = addcslashes( $str, "\0..\37\177\\\"" );
if ( ( $str == $encoded ) && ! preg_match( '/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str ) ) {
return ( $encoded );
} else {
return ( "\"$encoded\"" );
}
}
$matchcount = preg_match_all( '/[^\040\041\043-\133\135-\176]/', $str, $matches );
break;
/** @noinspection PhpMissingBreakStatementInspection */
case 'comment':
$matchcount = preg_match_all( '/[()"]/', $str, $matches );
// Intentional fall-through
case 'text':
default:
$matchcount += preg_match_all( '/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches );
break;
}
//There are no chars that need encoding
if ( $matchcount == 0 ) {
return ( $str );
}
$maxlen = 75 - 7 - strlen( $this->CharSet );
// Try to select the encoding which should produce the shortest output
if ( $matchcount > strlen( $str ) / 3 ) {
// More than a third of the content will need encoding, so B encoding will be most efficient
$encoding = 'B';
if ( function_exists( 'mb_strlen' ) && $this->hasMultiBytes( $str ) ) {
// Use a custom function which correctly encodes and wraps long
// multibyte strings without breaking lines within a character
$encoded = $this->base64EncodeWrapMB( $str, "\n" );
} else {
$encoded = base64_encode( $str );
$maxlen -= $maxlen % 4;
$encoded = trim( chunk_split( $encoded, $maxlen, "\n" ) );
}
} else {
$encoding = 'Q';
$encoded = $this->encodeQ( $str, $position );
$encoded = $this->wrapText( $encoded, $maxlen, true );
$encoded = str_replace( '=' . self::CRLF, "\n", trim( $encoded ) );
}
$encoded = preg_replace( '/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded );
$encoded = trim( str_replace( "\n", $this->LE, $encoded ) );
return $encoded;
}
/**
* Check if a string contains multi-byte characters.
* @access public
*
* @param string $str multi-byte text to wrap encode
*
* @return boolean
*/
public function hasMultiBytes( $str ) {
if ( function_exists( 'mb_strlen' ) ) {
return ( strlen( $str ) > mb_strlen( $str, $this->CharSet ) );
} else { // Assume no multibytes (we can't handle without mbstring functions anyway)
return false;
}
}
/**
* Encode and wrap long multibyte strings for mail headers
* without breaking lines within a character.
* Adapted from a function by paravoid
* @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
* @access public
*
* @param string $str multi-byte text to wrap encode
* @param string $linebreak string to use as linefeed/end-of-line
*
* @return string
*/
public function base64EncodeWrapMB( $str, $linebreak = null ) {
$start = '=?' . $this->CharSet . '?B?';
$end = '?=';
$encoded = '';
if ( $linebreak === null ) {
$linebreak = $this->LE;
}
$mb_length = mb_strlen( $str, $this->CharSet );
// Each line must have length <= 75, including $start and $end
$length = 75 - strlen( $start ) - strlen( $end );
// Average multi-byte ratio
$ratio = $mb_length / strlen( $str );
// Base64 has a 4:3 ratio
$avgLength = floor( $length * $ratio * .75 );
for ( $i = 0; $i < $mb_length; $i += $offset ) {
$lookBack = 0;
do {
$offset = $avgLength - $lookBack;
$chunk = mb_substr( $str, $i, $offset, $this->CharSet );
$chunk = base64_encode( $chunk );
$lookBack ++;
} while ( strlen( $chunk ) > $length );
$encoded .= $chunk . $linebreak;
}
// Chomp the last linefeed
$encoded = substr( $encoded, 0, - strlen( $linebreak ) );
return $encoded;
}
/**
* Encode a string using Q encoding.
* @link http://tools.ietf.org/html/rfc2047
*
* @param string $str the text to encode
* @param string $position Where the text is going to be used, see the RFC for what that means
*
* @access public
* @return string
*/
public function encodeQ( $str, $position = 'text' ) {
// There should not be any EOL in the string
$pattern = '';
$encoded = str_replace( array( "\r", "\n" ), '', $str );
switch ( strtolower( $position ) ) {
case 'phrase':
// RFC 2047 section 5.3
$pattern = '^A-Za-z0-9!*+\/ -';
break;
/** @noinspection PhpMissingBreakStatementInspection */
case 'comment':
// RFC 2047 section 5.2
$pattern = '\(\)"';
// intentional fall-through
// for this reason we build the $pattern without including delimiters and []
case 'text':
default:
// RFC 2047 section 5.1
// Replace every high ascii, control, =, ? and _ characters
$pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
break;
}
$matches = array();
if ( preg_match_all( "/[{$pattern}]/", $encoded, $matches ) ) {
// If the string contains an '=', make sure it's the first thing we replace
// so as to avoid double-encoding
$eqkey = array_search( '=', $matches[0] );
if ( false !== $eqkey ) {
unset( $matches[0][ $eqkey ] );
array_unshift( $matches[0], '=' );
}
foreach ( array_unique( $matches[0] ) as $char ) {
$encoded = str_replace( $char, '=' . sprintf( '%02X', ord( $char ) ), $encoded );
}
}
// Replace every spaces to _ (more readable than =20)
return str_replace( ' ', '_', $encoded );
}
/**
* Word-wrap message.
* For use with mailers that do not automatically perform wrapping
* and for quoted-printable encoded messages.
* Original written by philippe.
*
* @param string $message The message to wrap
* @param integer $length The line length to wrap to
* @param boolean $qp_mode Whether to run in Quoted-Printable mode
*
* @access public
* @return string
*/
public function wrapText( $message, $length, $qp_mode = false ) {
if ( $qp_mode ) {
$soft_break = sprintf( ' =%s', $this->LE );
} else {
$soft_break = $this->LE;
}
// If utf-8 encoding is used, we will need to make sure we don't
// split multibyte characters when we wrap
$is_utf8 = ( strtolower( $this->CharSet ) == 'utf-8' );
$lelen = strlen( $this->LE );
$crlflen = strlen( self::CRLF );
$message = $this->fixEOL( $message );
//Remove a trailing line break
if ( substr( $message, - $lelen ) == $this->LE ) {
$message = substr( $message, 0, - $lelen );
}
//Split message into lines
$lines = explode( $this->LE, $message );
//Message will be rebuilt in here
$message = '';
foreach ( $lines as $line ) {
$words = explode( ' ', $line );
$buf = '';
$firstword = true;
foreach ( $words as $word ) {
if ( $qp_mode and ( strlen( $word ) > $length ) ) {
$space_left = $length - strlen( $buf ) - $crlflen;
if ( ! $firstword ) {
if ( $space_left > 20 ) {
$len = $space_left;
if ( $is_utf8 ) {
$len = $this->utf8CharBoundary( $word, $len );
} elseif ( substr( $word, $len - 1, 1 ) == '=' ) {
$len --;
} elseif ( substr( $word, $len - 2, 1 ) == '=' ) {
$len -= 2;
}
$part = substr( $word, 0, $len );
$word = substr( $word, $len );
$buf .= ' ' . $part;
$message .= $buf . sprintf( '=%s', self::CRLF );
} else {
$message .= $buf . $soft_break;
}
$buf = '';
}
while ( strlen( $word ) > 0 ) {
if ( $length <= 0 ) {
break;
}
$len = $length;
if ( $is_utf8 ) {
$len = $this->utf8CharBoundary( $word, $len );
} elseif ( substr( $word, $len - 1, 1 ) == '=' ) {
$len --;
} elseif ( substr( $word, $len - 2, 1 ) == '=' ) {
$len -= 2;
}
$part = substr( $word, 0, $len );
$word = substr( $word, $len );
if ( strlen( $word ) > 0 ) {
$message .= $part . sprintf( '=%s', self::CRLF );
} else {
$buf = $part;
}
}
} else {
$buf_o = $buf;
if ( ! $firstword ) {
$buf .= ' ';
}
$buf .= $word;
if ( strlen( $buf ) > $length and $buf_o != '' ) {
$message .= $buf_o . $soft_break;
$buf = $word;
}
}
$firstword = false;
}
$message .= $buf . self::CRLF;
}
return $message;
}
/**
* Ensure consistent line endings in a string.
* Changes every end of line from CRLF, CR or LF to $this->LE.
* @access public
*
* @param string $str String to fixEOL
*
* @return string
*/
public function fixEOL( $str ) {
// Normalise to \n
$nstr = str_replace( array( "\r\n", "\r" ), "\n", $str );
// Now convert LE as needed
if ( $this->LE !== "\n" ) {
$nstr = str_replace( "\n", $this->LE, $nstr );
}
return $nstr;
}
/**
* Find the last character boundary prior to $maxLength in a utf-8
* quoted-printable encoded string.
* Original written by Colin Brown.
* @access public
*
* @param string $encodedText utf-8 QP text
* @param integer $maxLength Find the last character boundary prior to this length
*
* @return integer
*/
public function utf8CharBoundary( $encodedText, $maxLength ) {
$foundSplitPos = false;
$lookBack = 3;
while ( ! $foundSplitPos ) {
$lastChunk = substr( $encodedText, $maxLength - $lookBack, $lookBack );
$encodedCharPos = strpos( $lastChunk, '=' );
if ( false !== $encodedCharPos ) {
// Found start of encoded character byte within $lookBack block.
// Check the encoded byte value (the 2 chars after the '=')
$hex = substr( $encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2 );
$dec = hexdec( $hex );
if ( $dec < 128 ) {
// Single byte character.
// If the encoded char was found at pos 0, it will fit
// otherwise reduce maxLength to start of the encoded char
if ( $encodedCharPos > 0 ) {
$maxLength = $maxLength - ( $lookBack - $encodedCharPos );
}
$foundSplitPos = true;
} elseif ( $dec >= 192 ) {
// First byte of a multi byte character
// Reduce maxLength to split at start of character
$maxLength = $maxLength - ( $lookBack - $encodedCharPos );
$foundSplitPos = true;
} elseif ( $dec < 192 ) {
// Middle byte of a multi byte character, look further back
$lookBack += 3;
}
} else {
// No encoded character found
$foundSplitPos = true;
}
}
return $maxLength;
}
/** /**
* Get the array of strings for the current language. * Get the array of strings for the current language.
* @return array * @return array
@ -3537,7 +3637,8 @@ class PHPMailer {
* *
* @return boolean True on successfully adding an attachment * @return boolean True on successfully adding an attachment
*/ */
public function addEmbeddedImage( $path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline' ) { public function addEmbeddedImage( $path, $cid, $name = '', $encoding = 'base64', $type = '',
$disposition = 'inline' ) {
if ( !@is_file( $path ) ) { if ( !@is_file( $path ) ) {
$this->setError( $this->lang( 'file_access' ) . $path ); $this->setError( $this->lang( 'file_access' ) . $path );
@ -3777,106 +3878,6 @@ class PHPMailer {
return false; return false;
} }
/**
* Check that a string looks like an email address.
*
* @param string $address The email address to check
* @param string $patternselect A selector for the validation pattern to use :
* * `auto` Pick best pattern automatically;
* * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
* * `pcre` Use old PCRE implementation;
* * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
* * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
* * `noregex` Don't use a regex: super fast, really dumb.
*
* @return boolean
* @static
* @access public
*/
public static function validateAddress( $address, $patternselect = 'auto' ) {
//Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
if ( strpos( $address, "\n" ) !== false or strpos( $address, "\r" ) !== false ) {
return false;
}
if ( ! $patternselect or $patternselect == 'auto' ) {
//Check this constant first so it works when extension_loaded() is disabled by safe mode
//Constant was added in PHP 5.2.4
if ( defined( 'PCRE_VERSION' ) ) {
//This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
if ( version_compare( PCRE_VERSION, '8.0.3' ) >= 0 ) {
$patternselect = 'pcre8';
} else {
$patternselect = 'pcre';
}
} elseif ( function_exists( 'extension_loaded' ) and extension_loaded( 'pcre' ) ) {
//Fall back to older PCRE
$patternselect = 'pcre';
} else {
//Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
if ( version_compare( PHP_VERSION, '5.2.0' ) >= 0 ) {
$patternselect = 'php';
} else {
$patternselect = 'noregex';
}
}
}
switch ( $patternselect ) {
case 'pcre8':
/**
* Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
* @link http://squiloople.com/2009/12/20/email-address-validation/
* @copyright 2009-2010 Michael Rushton
* Feel free to use and redistribute this code. But please keep this copyright notice.
*/
return (boolean) preg_match(
'/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
'((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
'(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
'([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
'(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
'(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
'|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
'|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
'|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
$address
);
case 'pcre':
//An older regex that doesn't need a recent PCRE
return (boolean) preg_match(
'/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
'[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
'(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
'@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
'(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
'[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
'::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
'[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
'::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
'|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
$address
);
case 'html5':
/**
* This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
* @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
*/
return (boolean) preg_match(
'/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
'[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
$address
);
case 'noregex':
//No PCRE! Do something _very_ approximate!
//Check the address is 3 chars or longer and contains an @ that's not the first or last char
return ( strlen( $address ) >= 3
and strpos( $address, '@' ) >= 1
and strpos( $address, '@' ) != strlen( $address ) - 1 );
case 'php':
default:
return (boolean) filter_var( $address, FILTER_VALIDATE_EMAIL );
}
}
} }
/** /**

View File

@ -1,7 +1,7 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//FR" "http://www.w3.org/TR/html4/loose.dtd"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//FR" "http://www.w3.org/TR/html4/loose.dtd">
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head> </head>
<body class="body" style="background-color: whitesmoke !important;padding: 40px 0;line-height: 22px;width: 100%;"> <body class="body" style="background-color: whitesmoke !important;padding: 40px 0;line-height: 22px;width: 100%;">
<div class="contain" <div class="contain"

13
static/css/materialize.min.css vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,55 +1,37 @@
html, body, div, span, applet, object, iframe, main {
h1, h2, h3, h4, h5, h6, p, blockquote, pre, background: #F1F1F1;
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
} }
/* HTML5 display-role reset for older browsers */ .nav-add {
article, aside, details, figcaption, figure, padding-top: 12px;
footer, header, hgroup, menu, nav, section { height: 64px;
display: block;
} }
body { img.add-contacts {
line-height: 1; height: 40px;
cursor: pointer;
} }
ol, ul { .row .col.s12.main-container {
list-style: none; background: #FFF;
padding: 10px;
border-radius: 5px;
} }
blockquote, q { #search {
quotes: none; background: white;
border: none;
border-radius: 7px;
height: 40px;
width: 200px;
transition: all 0.3s;
padding-left: 10px;
} }
blockquote:before, blockquote:after, #search:hover {
q:before, q:after { width: 350px;
content: '';
content: none;
} }
table { #search:focus {
border-collapse: collapse; width: 500px;
border-spacing: 0;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
} }

BIN
static/img/add-contacts.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
static/img/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
static/img/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@ -0,0 +1,74 @@
let working = false;
let lastQuery = null;
let displayContacts = (contacts) => {
let tbody = $("table tbody");
for (let contact of contacts) {
tbody.append(`
<tr>
<td>${(contact["first_name"] ? contact["first_name"] : (contact["firstName"] ? contact["firstName"] : ""))}</td>
<td>${(contact["last_name"] ? contact["last_name"] : (contact["lastName"] ? contact["lastName"] : ""))}</td>
<td>${(contact["surname"] ? contact["surname"] : "")}</td>
<td>${(contact["email"] ? contact["email"] : "")}</td>
<td>${(contact["address"] ? contact["address"] : "")}</td>
<td>${(contact["phone_number"] ? contact["phone_number"] : (contact["phoneNumber"] ? contact["phoneNumber"] : ""))}</td>
<td>${(contact["birthday"] ? new Date(contact["birthday"]).toLocaleDateString() : "")}</td>
</tr>
`);
}
};
$(document).ready(() => {
let modal = $('.modal');
modal.modal();
let search = (query) => {
if (query.length >= 3) {
working = true;
$.ajax({
url: "/api/contact/search",
method: "POST",
data: {
query: query
},
success: function (data) {
$("table tbody").empty();
for (let i = 0; i < 4; i++) {
if (data && data.result && data.result[i.toString()] && data.result[i.toString()].length > 0) {
displayContacts(data.result[i.toString()]);
}
}
working = false;
},
error: function (e) {
working = false;
}
});
} else {
$("table tbody").empty();
displayContacts(contacts);
}
};
$(document).on("input", "#search", () => {
let query = $("#search").val();
if (!working) {
search(query);
} else {
lastQuery = query;
}
});
$(document).on("click", ".add-contacts", () => {
modal.open();
});
$("[data-tooltip]").tooltip();
});

File diff suppressed because one or more lines are too long

2
static/js/jquery-3.3.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

6
static/js/materialize.min.js vendored Normal file

File diff suppressed because one or more lines are too long