2015-11-16 19:30:04 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Hummingbird Anime Client
|
|
|
|
*
|
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists
|
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren
|
2016-01-04 16:58:33 -05:00
|
|
|
* @copyright Copyright (c) 2015 - 2016
|
2015-11-16 19:30:04 -05:00
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient;
|
|
|
|
|
2016-02-10 17:30:45 -05:00
|
|
|
use Yosymfony\Toml\Toml;
|
|
|
|
|
2016-01-06 17:06:30 -05:00
|
|
|
define('SRC_DIR', realpath(__DIR__ . '/../../'));
|
|
|
|
|
2016-01-06 15:44:40 -05:00
|
|
|
/**
|
|
|
|
* Odds and Ends class
|
|
|
|
*/
|
2015-11-16 19:30:04 -05:00
|
|
|
class AnimeClient {
|
|
|
|
|
|
|
|
use \Aviat\Ion\Di\ContainerAware;
|
2016-01-04 10:53:03 -05:00
|
|
|
|
|
|
|
const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
|
2016-01-06 11:08:56 -05:00
|
|
|
const DEFAULT_CONTROLLER_NAMESPACE = 'Aviat\AnimeClient\Controller';
|
|
|
|
const DEFAULT_CONTROLLER = 'Aviat\AnimeClient\Controller\Anime';
|
|
|
|
const DEFAULT_CONTROLLER_METHOD = 'index';
|
|
|
|
const NOT_FOUND_METHOD = 'not_found';
|
|
|
|
const ERROR_MESSAGE_METHOD = 'error_page';
|
2016-01-06 17:06:30 -05:00
|
|
|
const SRC_DIR = SRC_DIR;
|
2016-01-04 10:53:03 -05:00
|
|
|
|
|
|
|
private static $form_pages = [
|
|
|
|
'edit',
|
|
|
|
'add',
|
|
|
|
'update',
|
|
|
|
'update_form',
|
|
|
|
'login',
|
2016-04-14 17:51:00 -04:00
|
|
|
'logout',
|
|
|
|
'details'
|
2016-01-04 10:53:03 -05:00
|
|
|
];
|
|
|
|
|
2015-11-16 19:30:04 -05:00
|
|
|
/**
|
|
|
|
* HTML selection helper function
|
|
|
|
*
|
|
|
|
* @param string $a - First item to compare
|
|
|
|
* @param string $b - Second item to compare
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function is_selected($a, $b)
|
|
|
|
{
|
|
|
|
return ($a === $b) ? 'selected' : '';
|
|
|
|
}
|
2015-11-18 10:54:06 -05:00
|
|
|
|
2015-11-16 19:30:04 -05:00
|
|
|
/**
|
|
|
|
* Inverse of selected helper function
|
|
|
|
*
|
|
|
|
* @param string $a - First item to compare
|
|
|
|
* @param string $b - Second item to compare
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function is_not_selected($a, $b)
|
|
|
|
{
|
|
|
|
return ($a !== $b) ? 'selected' : '';
|
|
|
|
}
|
2015-11-18 10:54:06 -05:00
|
|
|
|
2015-11-16 19:30:04 -05:00
|
|
|
/**
|
|
|
|
* Determine whether to show the sub-menu
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function is_view_page()
|
|
|
|
{
|
|
|
|
$url = $this->container->get('request')
|
2016-02-17 10:29:05 -05:00
|
|
|
->getUri();
|
2015-11-16 19:30:04 -05:00
|
|
|
$page_segments = explode("/", $url);
|
2015-11-18 10:54:06 -05:00
|
|
|
|
2016-01-04 10:53:03 -05:00
|
|
|
$intersect = array_intersect($page_segments, self::$form_pages);
|
2015-11-18 10:54:06 -05:00
|
|
|
|
2015-11-16 19:30:04 -05:00
|
|
|
return empty($intersect);
|
|
|
|
}
|
|
|
|
|
2016-01-04 10:53:03 -05:00
|
|
|
/**
|
|
|
|
* Determine whether the page is a page with a form, and
|
|
|
|
* not suitable for redirection
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function is_form_page()
|
|
|
|
{
|
|
|
|
return ! $this->is_view_page();
|
|
|
|
}
|
|
|
|
|
2016-02-10 17:30:45 -05:00
|
|
|
/**
|
|
|
|
* Load configuration options from .toml files
|
|
|
|
*
|
|
|
|
* @param string $path - Path to load config
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function load_toml($path)
|
|
|
|
{
|
|
|
|
$output = [];
|
|
|
|
$files = glob("{$path}/*.toml");
|
|
|
|
|
|
|
|
foreach ($files as $file)
|
|
|
|
{
|
|
|
|
$key = str_replace('.toml', '', basename($file));
|
|
|
|
$toml = file_get_contents($file);
|
|
|
|
$config = Toml::Parse($toml);
|
|
|
|
|
|
|
|
if ($key === 'config')
|
|
|
|
{
|
|
|
|
foreach($config as $name => $value)
|
|
|
|
{
|
|
|
|
$output[$name] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output[$key] = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
2015-11-16 19:30:04 -05:00
|
|
|
}
|
2016-02-10 17:30:45 -05:00
|
|
|
// End of AnimeClient.php
|