2016-07-07 18:47:48 +02:00
|
|
|
<?php
|
2019-03-20 12:52:16 +02:00
|
|
|
|
2016-07-07 18:47:48 +02:00
|
|
|
namespace Grav\Plugin\Admin;
|
|
|
|
|
|
|
|
|
|
use Grav\Common\Grav;
|
2019-03-20 12:52:16 +02:00
|
|
|
use Grav\Common\User\Interfaces\UserCollectionInterface;
|
|
|
|
|
use Grav\Common\User\Interfaces\UserInterface;
|
2016-07-07 18:47:48 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Admin utils class
|
|
|
|
|
*
|
|
|
|
|
* @license MIT
|
|
|
|
|
*/
|
|
|
|
|
class Utils
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Matches an email to a user
|
|
|
|
|
*
|
2019-03-20 12:52:16 +02:00
|
|
|
* @param string $email
|
2016-11-07 09:54:10 -07:00
|
|
|
*
|
2019-03-20 12:52:16 +02:00
|
|
|
* @return UserInterface
|
2016-07-07 18:47:48 +02:00
|
|
|
*/
|
2019-03-20 12:52:16 +02:00
|
|
|
public static function findUserByEmail(string $email)
|
2016-07-07 18:47:48 +02:00
|
|
|
{
|
2019-03-20 12:52:16 +02:00
|
|
|
$grav = Grav::instance();
|
|
|
|
|
|
|
|
|
|
/** @var UserCollectionInterface $users */
|
2019-03-27 14:52:23 +02:00
|
|
|
$users = $grav['accounts'];
|
2016-07-07 18:47:48 +02:00
|
|
|
|
2019-03-20 12:52:16 +02:00
|
|
|
return $users->find($email, ['email']);
|
2016-07-07 18:47:48 +02:00
|
|
|
}
|
2017-05-16 17:31:57 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a slug of the given string
|
|
|
|
|
*
|
|
|
|
|
* @param string $str
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2019-03-20 12:52:16 +02:00
|
|
|
public static function slug(string $str)
|
2017-05-16 17:31:57 +02:00
|
|
|
{
|
|
|
|
|
if (function_exists('transliterator_transliterate')) {
|
|
|
|
|
$str = transliterator_transliterate('Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove;', $str);
|
|
|
|
|
} else {
|
|
|
|
|
$str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$str = strtolower($str);
|
|
|
|
|
$str = preg_replace('/[-\s]+/', '-', $str);
|
|
|
|
|
$str = preg_replace('/[^a-z0-9-]/i', '', $str);
|
|
|
|
|
$str = trim($str, '-');
|
|
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
2016-07-07 18:47:48 +02:00
|
|
|
}
|