123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace Grav\Plugin\Admin;
- use Grav\Common\Grav;
- use Grav\Common\User\User;
- class Utils
- {
-
- public static function findUserByEmail($email)
- {
- $account_dir = Grav::instance()['locator']->findResource('account://');
- $files = array_diff(scandir($account_dir, SCANDIR_SORT_ASCENDING), ['.', '..']);
- foreach ($files as $file) {
- if (strpos($file, '.yaml') !== false) {
- $user = User::load(trim(substr($file, 0, -5)));
- if ($user['email'] === $email) {
- return $user;
- }
- }
- }
-
- return User::load($email);
- }
-
- public static function slug($str)
- {
- 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;
- }
- }
|