2017-02-15 16:13:32 -05:00
|
|
|
<?php declare(strict_types=1);
|
2015-11-16 11:40:01 -05:00
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2015-11-16 11:40:01 -05:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
2015-11-16 11:40:01 -05:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* PHP version 7
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2015-11-16 11:40:01 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2016-08-30 10:01:18 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-08-10 20:10:19 -04:00
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
2016-08-30 10:01:18 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2017-02-15 16:13:32 -05:00
|
|
|
* @version 4.0
|
2018-08-10 20:10:19 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2015-11-16 11:40:01 -05:00
|
|
|
*/
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2017-02-08 15:48:20 -05:00
|
|
|
use const Aviat\AnimeClient\{
|
2018-11-01 22:01:09 -04:00
|
|
|
ALPHA_SLUG_PATTERN,
|
|
|
|
NUM_PATTERN,
|
|
|
|
SLUG_PATTERN,
|
2017-02-08 15:48:20 -05:00
|
|
|
DEFAULT_CONTROLLER_METHOD,
|
2017-03-31 13:37:53 -04:00
|
|
|
DEFAULT_CONTROLLER
|
2017-02-08 15:48:20 -05:00
|
|
|
};
|
|
|
|
|
2017-03-30 16:16:40 -04:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Routing Config
|
|
|
|
//
|
2018-01-18 16:21:45 -05:00
|
|
|
// Maps paths to controllers and methods
|
2017-03-30 16:16:40 -04:00
|
|
|
// -------------------------------------------------------------------------
|
2018-11-01 22:01:09 -04:00
|
|
|
$routes = [
|
2020-08-05 21:46:14 -04:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// AJAX Routes
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
'cache_purge' => [
|
|
|
|
'path' => '/cache_purge',
|
|
|
|
'action' => 'clearCache',
|
|
|
|
],
|
|
|
|
'heartbeat' => [
|
|
|
|
'path' => '/heartbeat',
|
|
|
|
'action' => 'heartbeat',
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Anime List Routes
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
'anime.add.get' => [
|
|
|
|
'path' => '/anime/add',
|
|
|
|
'action' => 'addForm',
|
|
|
|
],
|
|
|
|
'anime.add.post' => [
|
|
|
|
'path' => '/anime/add',
|
|
|
|
'action' => 'add',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
2020-12-02 12:42:47 -05:00
|
|
|
'anime.random' => [
|
|
|
|
'path' => '/anime/details/random',
|
|
|
|
'action' => 'random',
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
'anime.details' => [
|
|
|
|
'path' => '/anime/details/{id}',
|
|
|
|
'action' => 'details',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'id' => SLUG_PATTERN,
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
|
|
|
'anime.delete' => [
|
|
|
|
'path' => '/anime/delete',
|
|
|
|
'action' => 'delete',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Manga Routes
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
'manga.search' => [
|
|
|
|
'path' => '/manga/search',
|
|
|
|
'action' => 'search',
|
|
|
|
],
|
|
|
|
'manga.add.get' => [
|
|
|
|
'path' => '/manga/add',
|
|
|
|
'action' => 'addForm',
|
|
|
|
],
|
|
|
|
'manga.add.post' => [
|
|
|
|
'path' => '/manga/add',
|
|
|
|
'action' => 'add',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
|
|
|
'manga.delete' => [
|
|
|
|
'path' => '/manga/delete',
|
|
|
|
'action' => 'delete',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
2020-12-02 12:42:47 -05:00
|
|
|
'manga.random' => [
|
|
|
|
'path' => '/manga/details/random',
|
|
|
|
'action' => 'random',
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
'manga.details' => [
|
|
|
|
'path' => '/manga/details/{id}',
|
|
|
|
'action' => 'details',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'id' => SLUG_PATTERN,
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Anime Collection Routes
|
|
|
|
// ---------------------------------------------------------------------
|
2017-09-14 15:32:53 -04:00
|
|
|
'anime.collection.search' => [
|
|
|
|
'path' => '/anime-collection/search',
|
2017-03-30 16:16:40 -04:00
|
|
|
'action' => 'search',
|
|
|
|
],
|
2017-09-14 15:32:53 -04:00
|
|
|
'anime.collection.add.get' => [
|
|
|
|
'path' => '/anime-collection/add',
|
2017-03-30 16:16:40 -04:00
|
|
|
'action' => 'form',
|
|
|
|
],
|
2017-09-14 15:32:53 -04:00
|
|
|
'anime.collection.edit.get' => [
|
|
|
|
'path' => '/anime-collection/edit/{id}',
|
2017-03-30 16:16:40 -04:00
|
|
|
'action' => 'form',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'id' => NUM_PATTERN,
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
2017-09-14 15:32:53 -04:00
|
|
|
'anime.collection.add.post' => [
|
|
|
|
'path' => '/anime-collection/add',
|
2017-03-30 16:16:40 -04:00
|
|
|
'action' => 'add',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
2017-09-14 15:32:53 -04:00
|
|
|
'anime.collection.edit.post' => [
|
|
|
|
'path' => '/anime-collection/edit',
|
2017-03-30 16:16:40 -04:00
|
|
|
'action' => 'edit',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
2017-09-14 15:32:53 -04:00
|
|
|
'anime.collection.view' => [
|
|
|
|
'path' => '/anime-collection/view{/view}',
|
2019-07-10 10:20:37 -04:00
|
|
|
'action' => 'view',
|
2017-03-30 16:16:40 -04:00
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'view' => ALPHA_SLUG_PATTERN,
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
2017-09-14 15:32:53 -04:00
|
|
|
'anime.collection.delete' => [
|
|
|
|
'path' => '/anime-collection/delete',
|
2017-03-30 16:16:40 -04:00
|
|
|
'action' => 'delete',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
2019-07-10 10:20:37 -04:00
|
|
|
'anime.collection.redirect' => [
|
|
|
|
'path' => '/anime-collection',
|
|
|
|
],
|
|
|
|
'anime.collection.redirect2' => [
|
|
|
|
'path' => '/anime-collection/',
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Manga Collection Routes
|
|
|
|
// ---------------------------------------------------------------------
|
2017-09-14 15:32:53 -04:00
|
|
|
'manga.collection.search' => [
|
|
|
|
'path' => '/manga-collection/search',
|
|
|
|
'action' => 'search',
|
|
|
|
],
|
|
|
|
'manga.collection.add.get' => [
|
|
|
|
'path' => '/manga-collection/add',
|
|
|
|
'action' => 'form',
|
|
|
|
],
|
|
|
|
'manga.collection.edit.get' => [
|
|
|
|
'path' => '/manga-collection/edit/{id}',
|
|
|
|
'action' => 'form',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'id' => NUM_PATTERN,
|
2017-09-14 15:32:53 -04:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'manga.collection.add.post' => [
|
|
|
|
'path' => '/manga-collection/add',
|
|
|
|
'action' => 'add',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
|
|
|
'manga.collection.edit.post' => [
|
|
|
|
'path' => '/manga-collection/edit',
|
|
|
|
'action' => 'edit',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
|
|
|
'manga.collection.view' => [
|
|
|
|
'path' => '/manga-collection/view{/view}',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'view' => ALPHA_SLUG_PATTERN,
|
2017-09-14 15:32:53 -04:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'manga.collection.delete' => [
|
|
|
|
'path' => '/manga-collection/delete',
|
|
|
|
'action' => 'delete',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Other Routes
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
'character' => [
|
|
|
|
'path' => '/character/{slug}',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'slug' => SLUG_PATTERN
|
2017-03-30 16:16:40 -04:00
|
|
|
]
|
|
|
|
],
|
2018-10-19 09:30:27 -04:00
|
|
|
'person' => [
|
2020-08-27 15:01:00 -04:00
|
|
|
'path' => '/people/{slug}',
|
2018-10-19 09:30:27 -04:00
|
|
|
'tokens' => [
|
2020-08-05 20:57:01 -04:00
|
|
|
'slug' => SLUG_PATTERN,
|
2018-10-19 09:30:27 -04:00
|
|
|
]
|
|
|
|
],
|
2018-11-01 22:01:09 -04:00
|
|
|
'default_user_info' => [
|
|
|
|
'path' => '/me',
|
|
|
|
'action' => 'me',
|
|
|
|
'controller' => 'user',
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
'user_info' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'path' => '/user/{username}',
|
|
|
|
'controller' => 'user',
|
2018-11-07 14:29:21 -05:00
|
|
|
'action' => 'about',
|
2018-10-30 11:42:32 -04:00
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'username' => '.*?'
|
2018-10-30 11:42:32 -04:00
|
|
|
]
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// Default / Shared routes
|
|
|
|
// ---------------------------------------------------------------------
|
2018-08-10 20:10:19 -04:00
|
|
|
'anilist-redirect' => [
|
|
|
|
'path' => '/anilist-redirect',
|
|
|
|
'action' => 'anilistRedirect',
|
2018-11-02 12:58:19 -04:00
|
|
|
'controller' => 'settings',
|
2018-08-10 20:10:19 -04:00
|
|
|
],
|
2018-10-09 18:10:20 -04:00
|
|
|
'anilist-callback' => [
|
2018-08-10 20:10:19 -04:00
|
|
|
'path' => '/anilist-oauth',
|
|
|
|
'action' => 'anilistCallback',
|
2018-11-02 12:58:19 -04:00
|
|
|
'controller' => 'settings',
|
2018-08-10 20:10:19 -04:00
|
|
|
],
|
2017-04-13 11:15:16 -04:00
|
|
|
'image_proxy' => [
|
|
|
|
'path' => '/public/images/{type}/{file}',
|
2018-11-01 22:01:09 -04:00
|
|
|
'action' => 'cache',
|
|
|
|
'controller' => 'images',
|
2017-04-13 11:15:16 -04:00
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'type' => SLUG_PATTERN,
|
2018-10-05 21:32:15 -04:00
|
|
|
'file' => '[a-z0-9\-]+\.[a-z]{3,4}'
|
2017-04-13 11:15:16 -04:00
|
|
|
]
|
|
|
|
],
|
2018-08-15 08:51:37 -04:00
|
|
|
'settings' => [
|
|
|
|
'path' => '/settings',
|
|
|
|
],
|
2018-08-24 14:23:01 -04:00
|
|
|
'settings-post' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'path' => '/settings/update',
|
|
|
|
'action' => 'update',
|
2018-08-24 14:23:01 -04:00
|
|
|
'verb' => 'post',
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
'login' => [
|
|
|
|
'path' => '/login',
|
|
|
|
'action' => 'login',
|
|
|
|
],
|
|
|
|
'login.post' => [
|
|
|
|
'path' => '/login',
|
|
|
|
'action' => 'loginAction',
|
|
|
|
'verb' => 'post',
|
|
|
|
],
|
|
|
|
'logout' => [
|
|
|
|
'path' => '/logout',
|
|
|
|
'action' => 'logout',
|
|
|
|
],
|
2020-12-10 15:59:37 -05:00
|
|
|
'history' => [
|
|
|
|
'controller' => 'history',
|
|
|
|
'path' => '/history/{type}',
|
|
|
|
'tokens' => [
|
|
|
|
'type' => SLUG_PATTERN
|
|
|
|
]
|
|
|
|
],
|
2018-09-20 10:41:28 -04:00
|
|
|
'increment' => [
|
|
|
|
'path' => '/{controller}/increment',
|
|
|
|
'action' => 'increment',
|
|
|
|
'verb' => 'post',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'controller' => ALPHA_SLUG_PATTERN,
|
2018-09-20 10:41:28 -04:00
|
|
|
],
|
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
'update' => [
|
|
|
|
'path' => '/{controller}/update',
|
|
|
|
'action' => 'update',
|
|
|
|
'verb' => 'post',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'controller' => ALPHA_SLUG_PATTERN,
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
|
|
|
'update.post' => [
|
|
|
|
'path' => '/{controller}/update_form',
|
|
|
|
'action' => 'formUpdate',
|
|
|
|
'verb' => 'post',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'controller' => ALPHA_SLUG_PATTERN,
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
|
|
|
'edit' => [
|
|
|
|
'path' => '/{controller}/edit/{id}/{status}',
|
|
|
|
'action' => 'edit',
|
|
|
|
'tokens' => [
|
2018-11-01 22:01:09 -04:00
|
|
|
'id' => SLUG_PATTERN,
|
2017-03-30 16:16:40 -04:00
|
|
|
'status' => '([a-zA-Z\-_]|%20)+',
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
],
|
|
|
|
'list' => [
|
2020-12-10 15:59:37 -05:00
|
|
|
'path' => '/{controller}/{status}{/view}',
|
2017-03-30 16:16:40 -04:00
|
|
|
'tokens' => [
|
2020-12-10 15:59:37 -05:00
|
|
|
'status' => ALPHA_SLUG_PATTERN,
|
2018-11-01 22:01:09 -04:00
|
|
|
'view' => ALPHA_SLUG_PATTERN,
|
2016-01-06 11:08:56 -05:00
|
|
|
],
|
2016-04-14 17:00:34 -04:00
|
|
|
],
|
2017-03-30 16:16:40 -04:00
|
|
|
'index_redirect' => [
|
|
|
|
'path' => '/',
|
|
|
|
'action' => 'redirectToDefaultRoute',
|
|
|
|
],
|
2018-11-01 22:01:09 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
$defaultMap = [
|
|
|
|
'action' => DEFAULT_CONTROLLER_METHOD,
|
|
|
|
'controller' => DEFAULT_CONTROLLER,
|
|
|
|
'params' => [],
|
|
|
|
'verb' => 'get',
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($routes as &$route)
|
|
|
|
{
|
|
|
|
foreach($defaultMap as $key => $val)
|
|
|
|
{
|
|
|
|
if ( ! array_key_exists($key, $route))
|
|
|
|
{
|
|
|
|
$route[$key] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $routes;
|