|
1
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed'); |
|
2
|
|
|
|
|
3
|
|
|
class PublicList extends MY_Controller { |
|
4
|
|
|
public function __construct() { |
|
5
|
|
|
parent::__construct(); |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
$this->load->library('form_validation'); |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
public function index(?string $username = NULL, string $type = 'html') { |
|
12
|
|
|
$show_404 = FALSE; |
|
13
|
|
|
|
|
14
|
|
|
$type = mb_strtolower($type); |
|
15
|
|
|
if( |
|
16
|
|
|
(!is_null($username) && $this->form_validation->valid_username($username) && ($user = $this->User->get_user_by_username($username))) |
|
17
|
|
|
&& in_array($type, ['html', 'json'/*, 'txt'*/]) |
|
18
|
|
|
&& (($this->User->id == $user->id) || ($this->User_Options->get('enable_public_list', $user->id) == 'enabled' ? TRUE : FALSE))//&& get option enabled |
|
19
|
|
|
) { |
|
20
|
|
|
$this->header_data['title'] = "{$username}'s list"; |
|
21
|
|
|
$this->header_data['page'] = "dashboard"; |
|
22
|
|
|
|
|
23
|
|
|
$trackerData = $this->Tracker->list->get($user->id); |
|
24
|
|
|
switch($type) { |
|
25
|
|
|
//case 'txt': |
|
26
|
|
|
// break; |
|
27
|
|
|
|
|
28
|
|
|
case 'html': |
|
|
|
|
|
|
29
|
|
|
$this->body_data['trackerData'] = $trackerData['series']; |
|
30
|
|
|
$this->body_data['has_inactive'] = $trackerData['has_inactive']; |
|
31
|
|
|
|
|
32
|
|
|
$this->header_data['show_header'] = FALSE; |
|
33
|
|
|
$this->footer_data['show_footer'] = FALSE; |
|
34
|
|
|
|
|
35
|
|
|
$this->body_data['category_custom_1'] = ($this->User_Options->get('category_custom_1', $user->id) == 'enabled' ? TRUE : FALSE); |
|
36
|
|
|
$this->body_data['category_custom_1_text'] = $this->User_Options->get('category_custom_1_text', $user->id); |
|
37
|
|
|
|
|
38
|
|
|
$this->body_data['category_custom_2'] = ($this->User_Options->get('category_custom_2', $user->id) == 'enabled' ? TRUE : FALSE); |
|
39
|
|
|
$this->body_data['category_custom_2_text'] = $this->User_Options->get('category_custom_2_text', $user->id); |
|
40
|
|
|
|
|
41
|
|
|
$this->body_data['category_custom_3'] = ($this->User_Options->get('category_custom_3', $user->id) == 'enabled' ? TRUE : FALSE); |
|
42
|
|
|
$this->body_data['category_custom_3_text'] = $this->User_Options->get('category_custom_3_text', $user->id); |
|
43
|
|
|
|
|
44
|
|
|
$this->_render_page('User/PublicList'); |
|
45
|
|
|
break; |
|
46
|
|
|
|
|
47
|
|
|
case 'json': |
|
48
|
|
|
$trackerData = $this->_walk_recursive_remove($trackerData, function($v, $k) { |
|
49
|
|
|
return in_array($k, ['mal_icon']); |
|
50
|
|
|
}); |
|
51
|
|
|
$this->_render_json($trackerData); |
|
52
|
|
|
break; |
|
53
|
|
|
|
|
54
|
|
|
default: |
|
55
|
|
|
//This will never happen. |
|
56
|
|
|
break; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
} else { |
|
60
|
|
|
$show_404 = TRUE; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if($show_404) show_404(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function _walk_recursive_remove (array $array, callable $callback) { |
|
67
|
|
|
foreach ($array as $k => $v) { |
|
68
|
|
|
if (is_array($v)) { |
|
69
|
|
|
$array[$k] = $this->_walk_recursive_remove($v, $callback); |
|
70
|
|
|
} else { |
|
71
|
|
|
if ($callback($v, $k)) { |
|
72
|
|
|
unset($array[$k]); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $array; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next
break.There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.