|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Hummingbird Anime Client |
|
4
|
|
|
* |
|
5
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists |
|
6
|
|
|
* |
|
7
|
|
|
* @package HummingbirdAnimeClient |
|
8
|
|
|
* @author Timothy J. Warren |
|
9
|
|
|
* @copyright Copyright (c) 2015 - 2016 |
|
10
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient |
|
11
|
|
|
* @license MIT |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Aviat\AnimeClient; |
|
15
|
|
|
|
|
16
|
|
|
use Yosymfony\Toml\Toml; |
|
17
|
|
|
|
|
18
|
|
|
define('SRC_DIR', realpath(__DIR__ . '/../../')); |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Odds and Ends class |
|
22
|
|
|
*/ |
|
23
|
|
|
class AnimeClient { |
|
24
|
|
|
|
|
25
|
|
|
use \Aviat\Ion\Di\ContainerAware; |
|
26
|
|
|
|
|
27
|
|
|
const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth'; |
|
28
|
|
|
const DEFAULT_CONTROLLER_NAMESPACE = 'Aviat\AnimeClient\Controller'; |
|
29
|
|
|
const DEFAULT_CONTROLLER = 'Aviat\AnimeClient\Controller\Anime'; |
|
30
|
|
|
const DEFAULT_CONTROLLER_METHOD = 'index'; |
|
31
|
|
|
const NOT_FOUND_METHOD = 'not_found'; |
|
32
|
|
|
const ERROR_MESSAGE_METHOD = 'error_page'; |
|
33
|
|
|
const SRC_DIR = SRC_DIR; |
|
34
|
|
|
|
|
35
|
|
|
private static $form_pages = [ |
|
36
|
|
|
'edit', |
|
37
|
|
|
'add', |
|
38
|
|
|
'update', |
|
39
|
|
|
'update_form', |
|
40
|
|
|
'login', |
|
41
|
|
|
'logout' |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* HTML selection helper function |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $a - First item to compare |
|
48
|
|
|
* @param string $b - Second item to compare |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
public static function is_selected($a, $b) |
|
52
|
|
|
{ |
|
53
|
|
|
return ($a === $b) ? 'selected' : ''; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Inverse of selected helper function |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $a - First item to compare |
|
60
|
|
|
* @param string $b - Second item to compare |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public static function is_not_selected($a, $b) |
|
64
|
|
|
{ |
|
65
|
|
|
return ($a !== $b) ? 'selected' : ''; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Determine whether to show the sub-menu |
|
70
|
|
|
* |
|
71
|
|
|
* @return bool |
|
72
|
|
|
*/ |
|
73
|
|
|
public function is_view_page() |
|
74
|
|
|
{ |
|
75
|
|
|
$url = $this->container->get('request') |
|
76
|
|
|
->url->get(); |
|
77
|
|
|
$page_segments = explode("/", $url); |
|
78
|
|
|
|
|
79
|
|
|
$intersect = array_intersect($page_segments, self::$form_pages); |
|
80
|
|
|
|
|
81
|
|
|
return empty($intersect); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Determine whether the page is a page with a form, and |
|
86
|
|
|
* not suitable for redirection |
|
87
|
|
|
* |
|
88
|
|
|
* @return boolean |
|
89
|
|
|
*/ |
|
90
|
|
|
public function is_form_page() |
|
91
|
|
|
{ |
|
92
|
|
|
return ! $this->is_view_page(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Load configuration options from .toml files |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $path - Path to load config |
|
99
|
|
|
* @return array |
|
100
|
|
|
*/ |
|
101
|
|
|
public static function load_toml($path) |
|
102
|
|
|
{ |
|
103
|
|
|
$output = []; |
|
104
|
|
|
$files = glob("{$path}/*.toml"); |
|
105
|
|
|
|
|
106
|
|
|
foreach ($files as $file) |
|
107
|
|
|
{ |
|
108
|
|
|
$key = str_replace('.toml', '', basename($file)); |
|
109
|
|
|
$toml = file_get_contents($file); |
|
110
|
|
|
$config = Toml::Parse($toml); |
|
111
|
|
|
|
|
112
|
|
|
if ($key === 'config') |
|
113
|
|
|
{ |
|
114
|
|
|
foreach($config as $name => $value) |
|
115
|
|
|
{ |
|
116
|
|
|
$output[$name] = $value; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
continue; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$output[$key] = $config; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $output; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
// End of AnimeClient.php |