Version 5.1 - All the GraphQL #32
@ -20,7 +20,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($items as $item): ?>
|
||||
<tr id="a-<?= $item['anime']['id'] ?>">
|
||||
<tr id="a-<?= $item['id'] ?>">
|
||||
<td class="align_left">
|
||||
<a href="<?= $item['anime']['url'] ?>">
|
||||
<?= $item['anime']['title'] ?>
|
||||
|
@ -13,7 +13,7 @@
|
||||
<h1 class="flex flex-align-end flex-wrap">
|
||||
<span class="flex-no-wrap grow-1">
|
||||
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
|
||||
<?= $config->whose_list ?>'s <?= ucfirst($url_type) ?> <?= (strpos($route_path, 'collection') !== FALSE) ? 'Collection' : 'List' ?>
|
||||
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> <?= (strpos($route_path, 'collection') !== FALSE) ? 'Collection' : 'List' ?>
|
||||
</a> [<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
|
||||
</span>
|
||||
<span class="flex-no-wrap small-font">
|
||||
|
@ -16,9 +16,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($items as $item): ?>
|
||||
<tr id="manga-<?= $item['manga']['id'] ?>">
|
||||
<tr id="manga-<?= $item['id'] ?>">
|
||||
<td class="align_left">
|
||||
<a href="https://hummingbird.me/manga/<?= $item['manga']['id'] ?>">
|
||||
<a href="<?= $item['manga']['url'] ?>">
|
||||
<?= $item['manga']['title'] ?>
|
||||
</a>
|
||||
<?= ( ! is_null($item['manga']['alternate_title'])) ? " · " . $item['manga']['alternate_title'] : "" ?>
|
||||
|
@ -7,6 +7,9 @@ namespace Aviat\AnimeClient;
|
||||
|
||||
/**
|
||||
* Wrapper for configuration values
|
||||
*
|
||||
* @property Database Config $database
|
||||
* @property Menu Config $menus
|
||||
*/
|
||||
class Config {
|
||||
|
||||
@ -39,12 +42,12 @@ class Config {
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for config values
|
||||
* Get a config value
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
public function get($key)
|
||||
{
|
||||
if (isset($this->config[$key]))
|
||||
{
|
||||
@ -53,5 +56,18 @@ class Config {
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a config value
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return Config
|
||||
*/
|
||||
public function set($key, $value)
|
||||
{
|
||||
$this->config[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
// End of config.php
|
@ -25,6 +25,12 @@ class Controller {
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Request object
|
||||
* @var object $request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Response object
|
||||
* @var object $response
|
||||
@ -90,7 +96,7 @@ class Controller {
|
||||
/**
|
||||
* Get the string output of a partial template
|
||||
*
|
||||
* @param HTMLView $view
|
||||
* @param HtmlView $view
|
||||
* @param string $template
|
||||
* @param array|object $data
|
||||
* @return string
|
||||
@ -110,7 +116,7 @@ class Controller {
|
||||
$data['route_path'] = ($route) ? $router->get_route()->path : "";
|
||||
|
||||
|
||||
$template_path = _dir($this->config->__get('view_path'), "{$template}.php");
|
||||
$template_path = _dir($this->config->get('view_path'), "{$template}.php");
|
||||
|
||||
if ( ! is_file($template_path))
|
||||
{
|
||||
@ -198,7 +204,6 @@ class Controller {
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
session_destroy();
|
||||
$this->response->redirect->seeOther($this->urlGenerator->full_url(''));
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ class Anime extends BaseController {
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
if ($this->config->show_anime_collection === FALSE)
|
||||
if ($this->config->get('show_anime_collection') === FALSE)
|
||||
{
|
||||
unset($this->nav_routes['Collection']);
|
||||
}
|
||||
@ -73,6 +73,13 @@ class Anime extends BaseController {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a portion, or all of the anime list
|
||||
*
|
||||
* @param string $type - The section of the list
|
||||
* @param string $view - List or cover view
|
||||
* @return void
|
||||
*/
|
||||
public function index($type = "watching", $view = '')
|
||||
{
|
||||
return $this->anime_list($type, $view);
|
||||
@ -116,7 +123,7 @@ class Anime extends BaseController {
|
||||
'completed' => AnimeWatchingStatus::COMPLETED
|
||||
];
|
||||
|
||||
$title = $this->config->whose_list . "'s Anime List · {$type_title_map[$type]}";
|
||||
$title = $this->config->get('whose_list') . "'s Anime List · {$type_title_map[$type]}";
|
||||
|
||||
$view_map = [
|
||||
'' => 'cover',
|
||||
|
@ -58,7 +58,7 @@ class Collection extends BaseController {
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
if ($this->config->show_anime_collection === FALSE)
|
||||
if ($this->config->get('show_anime_collection') === FALSE)
|
||||
{
|
||||
unset($this->nav_routes['Collection']);
|
||||
}
|
||||
@ -101,7 +101,7 @@ class Collection extends BaseController {
|
||||
$data = $this->collection_model->get_collection();
|
||||
|
||||
$this->outputHTML('collection/' . $view_map[$view], [
|
||||
'title' => $this->config->whose_list . "'s Anime Collection",
|
||||
'title' => $this->config->get('whose_list') . "'s Anime Collection",
|
||||
'sections' => $data,
|
||||
'genres' => $this->collection_model->get_genre_list()
|
||||
]);
|
||||
|
@ -58,6 +58,13 @@ class Manga extends Controller {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a section of the manga list
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $view
|
||||
* @return void
|
||||
*/
|
||||
public function index($status = "all", $view = "")
|
||||
{
|
||||
return $this->manga_list($status, $view);
|
||||
@ -91,7 +98,7 @@ class Manga extends Controller {
|
||||
'on_hold' => MangaModel::ON_HOLD
|
||||
];
|
||||
|
||||
$title = $this->config->whose_list . "'s Manga List · {$map[$status]}";
|
||||
$title = $this->config->get('whose_list') . "'s Manga List · {$map[$status]}";
|
||||
|
||||
$view_map = [
|
||||
'' => 'cover',
|
||||
|
@ -22,7 +22,7 @@ class Model {
|
||||
|
||||
/**
|
||||
* The container object
|
||||
* @var Container
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
@ -61,8 +61,9 @@ class Model {
|
||||
// Failsafe for weird urls
|
||||
if (strlen($ext) > 3) return $api_path;
|
||||
|
||||
$img_cache_path = $this->config->get('img_cache_path');
|
||||
$cached_image = "{$series_slug}.{$ext}";
|
||||
$cached_path = "{$this->config->img_cache_path}/{$type}/{$cached_image}";
|
||||
$cached_path = "{$img_cache_path}/{$type}/{$cached_image}";
|
||||
|
||||
// Cache the file if it doesn't already exist
|
||||
if ( ! file_exists($cached_path))
|
||||
|
@ -47,7 +47,8 @@ class Anime extends API {
|
||||
*/
|
||||
public function update($data)
|
||||
{
|
||||
$data['auth_token'] = $_SESSION['hummingbird_anime_token'];
|
||||
// @TODO use Hummingbird Auth class
|
||||
$data['auth_token'] = '';
|
||||
|
||||
$result = $this->client->post("libraries/{$data['id']}", [
|
||||
'body' => $data
|
||||
@ -168,7 +169,8 @@ class Anime extends API {
|
||||
$config['query']['status'] = $status;
|
||||
}
|
||||
|
||||
$response = $this->client->get("users/{$this->config->hummingbird_username}/library", $config);
|
||||
$username = $this->config->get('hummingbird_username');
|
||||
$response = $this->client->get("users/{$username}/library", $config);
|
||||
$output = $this->_check_cache($status, $response);
|
||||
|
||||
foreach ($output as &$row)
|
||||
@ -189,8 +191,8 @@ class Anime extends API {
|
||||
*/
|
||||
protected function _check_cache($status, $response)
|
||||
{
|
||||
$cache_file = _dir($this->config->data_cache_path, "anime-{$status}.json");
|
||||
$transformed_cache_file = _dir($this->config->data_cache_path, "anime-{$status}-transformed.json");
|
||||
$cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}.json");
|
||||
$transformed_cache_file = _dir($this->config->get('data_cache_path'), "anime-{$status}-transformed.json");
|
||||
|
||||
$cached = json_decode(file_get_contents($cache_file), TRUE);
|
||||
$api_data = json_decode($response->getBody(), TRUE);
|
||||
|
@ -31,7 +31,7 @@ class DB extends BaseModel {
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->db_config = $this->config->database;
|
||||
$this->db_config = $this->config->get('database');
|
||||
}
|
||||
}
|
||||
// End of BaseDBModel.php
|
@ -48,8 +48,9 @@ class Manga extends API {
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
|
||||
// @TODO update with auth key from auth class
|
||||
$result = $this->client->put("manga_library_entries/{$id}", [
|
||||
'cookies' => ['token' => $_SESSION['hummingbird_anime_token']],
|
||||
'cookies' => ['token' => ''],
|
||||
'json' => ['manga_library_entry' => $data]
|
||||
]);
|
||||
|
||||
@ -92,7 +93,7 @@ class Manga extends API {
|
||||
|
||||
$config = [
|
||||
'query' => [
|
||||
'user_id' => $this->config->hummingbird_username
|
||||
'user_id' => $this->config->get('hummingbird_username')
|
||||
],
|
||||
'allow_redirects' => FALSE
|
||||
];
|
||||
@ -117,8 +118,8 @@ class Manga extends API {
|
||||
$api_data = json_decode($response->getBody(), TRUE);
|
||||
if ( ! array_key_exists('manga', $api_data)) return [];
|
||||
|
||||
$cache_file = _dir($this->config->data_cache_path, 'manga.json');
|
||||
$transformed_cache_file = _dir($this->config->data_cache_path, 'manga-transformed.json');
|
||||
$cache_file = _dir($this->config->get('data_cache_path'), 'manga.json');
|
||||
$transformed_cache_file = _dir($this->config->get('data_cache_path'), 'manga-transformed.json');
|
||||
|
||||
$cached_data = json_decode(file_get_contents($cache_file), TRUE);
|
||||
|
||||
|
@ -168,10 +168,7 @@ class Router extends RoutingBase {
|
||||
*/
|
||||
public function get_controller()
|
||||
{
|
||||
$error_handler = $this->container->get('error-handler');
|
||||
$route_type = $this->__get('default_list');
|
||||
|
||||
$host = $this->request->server->get("HTTP_HOST");
|
||||
$request_uri = $this->request->server->get('PATH_INFO');
|
||||
|
||||
$path = trim($request_uri, '/');
|
||||
|
@ -38,7 +38,7 @@ class RoutingBase {
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->config = $container->get('config');
|
||||
$this->routes = $this->config->__get('routes');
|
||||
$this->routes = $this->config->get('routes');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +49,7 @@ class RoutingBase {
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
$routing_config = $this->config->routing;
|
||||
$routing_config = $this->config->get('routing');
|
||||
|
||||
if (array_key_exists($key, $routing_config))
|
||||
{
|
||||
|
@ -13,7 +13,16 @@ use BadMethodCallException;
|
||||
*/
|
||||
class Friend {
|
||||
|
||||
/**
|
||||
* Object to create a friend of
|
||||
* @var object
|
||||
*/
|
||||
private $_friend_object_;
|
||||
|
||||
/**
|
||||
* Reflection class of the object
|
||||
* @var object
|
||||
*/
|
||||
private $_reflection_friend_;
|
||||
|
||||
/**
|
||||
|
@ -13,15 +13,15 @@ class ConfigTest extends AnimeClient_TestCase {
|
||||
]);
|
||||
}
|
||||
|
||||
public function testConfig__get()
|
||||
public function testConfigGet()
|
||||
{
|
||||
$this->assertEquals($this->config->foo, $this->config->__get('foo'));
|
||||
$this->assertEquals($this->config->bar, $this->config->__get('bar'));
|
||||
$this->assertEquals(NULL, $this->config->baz);
|
||||
$this->assertEquals('bar', $this->config->get('foo'));
|
||||
$this->assertEquals('baz', $this->config->get('bar'));
|
||||
$this->assertNull($this->config->get('baz'));
|
||||
}
|
||||
|
||||
public function testGetNonExistentConfigItem()
|
||||
{
|
||||
$this->assertEquals(NULL, $this->config->foobar);
|
||||
$this->assertNull($this->config->get('foobar'));
|
||||
}
|
||||
}
|
@ -147,7 +147,7 @@ class RouterTest extends AnimeClient_TestCase {
|
||||
|
||||
|
||||
// Check route setup
|
||||
$this->assertEquals($config['routes'], $this->config->routes, "Incorrect route path");
|
||||
$this->assertEquals($config['routes'], $this->config->get('routes'), "Incorrect route path");
|
||||
$this->assertTrue(is_array($this->router->get_output_routes()));
|
||||
|
||||
// Check environment variables
|
||||
|
Loading…
Reference in New Issue
Block a user