Finish moving get_cached_image method to Util class

This commit is contained in:
Timothy Warren 2016-07-27 14:32:37 -04:00
parent f00acbe2d6
commit a108adfa23
5 changed files with 59 additions and 55 deletions

View File

@ -1,4 +1,3 @@
<?php namespace Aviat\AnimeClient ?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -12,49 +11,7 @@
</head>
<body class="<?= $escape->attr($url_type) ?> list">
<header>
<h1 class="flex flex-align-end flex-wrap">
<span class="flex-no-wrap grow-1">
<?php if(strpos($route_path, 'collection') === FALSE): ?>
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> List
</a>
<?php if($config->get("show_{$url_type}_collection")): ?>
[<a href="<?= $urlGenerator->url('collection/view') ?>"><?= ucfirst($url_type) ?> Collection</a>]
<?php endif ?>
[<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
<?php else: ?>
<a href="<?= $urlGenerator->url('collection/view') ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> Collection
</a>
[<a href="<?= $urlGenerator->default_url('anime') ?>">Anime List</a>]
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
<?php endif ?>
</span>
<?php if ($auth->is_authenticated()): ?>
<span class="flex-no-wrap">&nbsp;</span>
<span class="flex-no-wrap small-font">
<button type="button" class="js-clear-cache user-btn">Clear API Cache</button>
</span>
<span class="flex-no-wrap">&nbsp;</span>
<?php endif ?>
<span class="flex-no-wrap small-font">
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $url->generate('logout') ?>">Logout</a>
<?php else: ?>
[<a href="<?= $url->generate('login'); ?>"><?= $config->get('whose_list') ?>'s Login</a>]
<?php endif ?>
</span>
</h1>
<nav>
<?php if ($container->get('anime-client')->is_view_page()): ?>
<?= $helper->menu($menu_name) ?>
<br />
<ul>
<li class="<?= Util::is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
<li class="<?= Util::is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
</ul>
<?php endif ?>
</nav>
<?php include 'main-menu.php' ?>
<?php if(isset($message) && is_array($message)):
extract($message);
include 'message.php';

44
app/views/main-menu.php Normal file
View File

@ -0,0 +1,44 @@
<?php namespace Aviat\AnimeClient ?>
<h1 class="flex flex-align-end flex-wrap">
<span class="flex-no-wrap grow-1">
<?php if(strpos($route_path, 'collection') === FALSE): ?>
<a href="<?= $escape->attr($urlGenerator->default_url($url_type)) ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> List
</a>
<?php if($config->get("show_{$url_type}_collection")): ?>
[<a href="<?= $urlGenerator->url('collection/view') ?>"><?= ucfirst($url_type) ?> Collection</a>]
<?php endif ?>
[<a href="<?= $urlGenerator->default_url($other_type) ?>"><?= ucfirst($other_type) ?> List</a>]
<?php else: ?>
<a href="<?= $urlGenerator->url('collection/view') ?>">
<?= $config->get('whose_list') ?>'s <?= ucfirst($url_type) ?> Collection
</a>
[<a href="<?= $urlGenerator->default_url('anime') ?>">Anime List</a>]
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
<?php endif ?>
</span>
<?php if ($auth->is_authenticated()): ?>
<span class="flex-no-wrap">&nbsp;</span>
<span class="flex-no-wrap small-font">
<button type="button" class="js-clear-cache user-btn">Clear API Cache</button>
</span>
<span class="flex-no-wrap">&nbsp;</span>
<?php endif ?>
<span class="flex-no-wrap small-font">
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $url->generate('logout') ?>">Logout</a>
<?php else: ?>
[<a href="<?= $url->generate('login'); ?>"><?= $config->get('whose_list') ?>'s Login</a>]
<?php endif ?>
</span>
</h1>
<nav>
<?php if ($container->get('util')->is_view_page()): ?>
<?= $helper->menu($menu_name) ?>
<br />
<ul>
<li class="<?= Util::is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
<li class="<?= Util::is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
</ul>
<?php endif ?>
</nav>

View File

@ -13,7 +13,7 @@
namespace Aviat\AnimeClient\Command;
use Aviat\AnimeClient\Model;
use Aviat\AnimeClient\Util;
/**
* Generates thumbnail image cache so that cover images load faster
*/
@ -21,7 +21,7 @@ class CacheImages extends BaseCommand {
protected $mangaModel;
protected $animeModel;
protected $model;
protected $util;
/*
* Convert manga images
@ -37,7 +37,7 @@ class CacheImages extends BaseCommand {
$current = 0;
foreach($manga_list as $item)
{
$this->model->get_cached_image($item['poster_image'], $item['id'], 'manga');
$this->util->get_cached_image($item['poster_image'], $item['id'], 'manga');
$current++;
echo "Cached {$current} of {$total} manga images. \n";
@ -57,7 +57,7 @@ class CacheImages extends BaseCommand {
$current = 0;
foreach($raw_list as $item)
{
$this->model->get_cached_image($item['anime']['cover_image'], $item['anime']['slug'], 'anime');
$this->util->get_cached_image($item['anime']['cover_image'], $item['anime']['slug'], 'anime');
$current++;
echo "Cached {$current} of {$total} anime images. \n";
@ -75,7 +75,7 @@ class CacheImages extends BaseCommand {
public function execute(array $args, array $options = array())
{
$this->setContainer($this->setupContainer());
$this->model = new Model($this->container);
$this->util = new Util($this->container);
$this->animeModel = $this->container->get('anime-model');
$this->mangaModel = $this->container->get('manga-model');

View File

@ -21,7 +21,6 @@ use Aviat\Ion\View\JsonView;
* Controller base, defines output methods
*
* @property Response object $response
* @property Config object $config
*/
class Controller {
@ -35,7 +34,7 @@ class Controller {
/**
* The global configuration object
* @var object $config
* @var Aviat\Ion\ConfigInterface $config
*/
protected $config;
@ -148,7 +147,7 @@ class Controller {
return;
}
$anime_client = $this->container->get('anime-client');
$util = $this->container->get('util');
$double_form_page = $server_params['HTTP_REFERER'] == $this->request->getUri();
// Don't attempt to set the redirect url if
@ -161,7 +160,7 @@ class Controller {
if (is_null($url))
{
$url = ($anime_client->is_view_page())
$url = ($util->is_view_page())
? $this->request->url->get()
: $server_params['HTTP_REFERER'];
}

View File

@ -129,6 +129,8 @@ class AnimeCollection extends Collection {
{
$anime = (object)$this->anime_model->get_anime($data['id']);
$util = $this->container->get('util');
$this->db->set([
'hummingbird_id' => $data['id'],
'slug' => $anime->slug,
@ -137,7 +139,7 @@ class AnimeCollection extends Collection {
'show_type' => $anime->show_type,
'age_rating' => $anime->age_rating,
'cover_image' => basename(
$this->get_cached_image($anime->cover_image, $anime->slug, 'anime')
$util->get_cached_image($anime->cover_image, $anime->slug, 'anime')
),
'episode_count' => $anime->episode_count,
'episode_length' => $anime->episode_length,
@ -222,6 +224,8 @@ class AnimeCollection extends Collection {
foreach ($anime as $item)
{
$util = $this->container->get('util');
$this->db->set([
'hummingbird_id' => $item->id,
'slug' => $item->slug,
@ -230,7 +234,7 @@ class AnimeCollection extends Collection {
'show_type' => $item->show_type,
'age_rating' => $item->age_rating,
'cover_image' => basename(
$this->get_cached_image($item->cover_image, $item->slug, 'anime')
$util->get_cached_image($item->cover_image, $item->slug, 'anime')
),
'episode_count' => $item->episode_count,
'episode_length' => $item->episode_length