1
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed'); |
2
|
|
|
|
3
|
|
|
class Options extends Auth_Controller { |
4
|
1 |
|
public function __construct() { |
5
|
1 |
|
parent::__construct(); |
6
|
|
|
|
7
|
|
|
$this->load->helper('form'); |
8
|
|
|
$this->load->library('form_validation'); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
public function index() : void { |
12
|
|
|
$this->header_data['title'] = 'Options'; |
13
|
|
|
$this->header_data['page'] = 'options'; |
14
|
|
|
|
15
|
|
|
$customCategories = ['custom1' => 'category_custom_1', 'custom2' => 'category_custom_2', 'custom3' => 'category_custom_3']; |
16
|
|
|
$usedCategories = $this->Tracker->category->getUsed($this->User->id); |
17
|
|
|
|
18
|
|
|
//NOTE: The checkbox validation is handled in run() |
19
|
|
|
$this->form_validation->set_rules('category_custom_1_text', 'Custom Category 1 Text', 'trim|regex_match[/^[a-zA-Z0-9-_\\s]{0,16}$/]'); |
20
|
|
|
$this->form_validation->set_rules('category_custom_2_text', 'Custom Category 2 Text', 'trim|regex_match[/^[a-zA-Z0-9-_\\s]{0,16}$/]'); |
21
|
|
|
$this->form_validation->set_rules('category_custom_3_text', 'Custom Category 3 Text', 'trim|regex_match[/^[a-zA-Z0-9-_\\s]{0,16}$/]'); |
22
|
|
|
$this->form_validation->set_rules('default_series_category', 'Default Series Category', 'required|is_valid_option_value[default_series_category]'); |
23
|
|
|
$this->form_validation->set_rules('list_sort_type', 'List Sort Type', 'required|is_valid_option_value[list_sort_type]'); |
24
|
|
|
$this->form_validation->set_rules('list_sort_order', 'List Sort Order', 'required|is_valid_option_value[list_sort_order]'); |
25
|
|
|
$this->form_validation->set_rules('theme', 'Theme', 'required|is_valid_option_value[theme]'); |
26
|
|
|
$this->form_validation->set_rules('mal_sync', 'MAL Sync', 'required|is_valid_option_value[mal_sync]'); |
27
|
|
|
|
28
|
|
|
if ($isValid = $this->form_validation->run() === TRUE) { |
|
|
|
|
29
|
|
|
foreach($customCategories as $categoryK => $category) { |
30
|
|
|
if(!in_array($categoryK, $usedCategories)) { |
31
|
|
|
$this->User_Options->set($category, $this->input->post($category) ? 'enabled' : 'disabled'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$this->User_Options->set($category.'_text', $this->input->post($category.'_text') ?? ''); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$this->User_Options->set('default_series_category', $this->input->post('default_series_category')); |
38
|
|
|
|
39
|
|
|
$this->User_Options->set('enable_live_countdown_timer', $this->input->post('enable_live_countdown_timer')); |
40
|
|
|
|
41
|
|
|
$this->User_Options->set('list_sort_type', $this->input->post('list_sort_type')); |
42
|
|
|
$this->User_Options->set('list_sort_order', $this->input->post('list_sort_order')); |
43
|
|
|
|
44
|
|
|
$this->User_Options->set('theme', $this->input->post('theme')); |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
$this->User_Options->set('enable_public_list', $this->input->post('enable_public_list')); |
48
|
|
|
|
49
|
|
|
$this->User_Options->set('mal_sync', $this->input->post('mal_sync')); |
50
|
|
|
|
51
|
|
|
//We need to force a reload to make sure the user gets the new settings. |
52
|
|
|
header("Refresh:0"); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/*** CUSTOM CATEGORIES ***/ |
56
|
|
|
foreach($customCategories as $categoryK => $category) { |
57
|
|
|
$this->body_data[$category] = ($this->User_Options->get($category) == 'enabled' ? TRUE : FALSE); |
58
|
|
|
$this->body_data[$category.'_text'] = $this->User_Options->get($category.'_text'); |
59
|
|
|
$this->body_data[$category.'_has_series'] = (int) in_array($categoryK, $usedCategories); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/*** DEFAULT CATEGORY ***/ |
63
|
|
|
$this->body_data['default_series_category'] = array_intersect_key( |
64
|
|
|
array( |
65
|
|
|
'reading' => 'Reading', |
66
|
|
|
'on-hold' => 'On-Hold', |
67
|
|
|
'plan-to-read' => 'Plan to Read', |
68
|
|
|
'custom1' => 'Custom Category 1', |
69
|
|
|
'custom2' => 'Custom Category 2', |
70
|
|
|
'custom3' => 'Custom Category 3' |
71
|
|
|
), |
72
|
|
|
array_flip(array_values($this->User_Options->options['default_series_category']['valid_options'])) |
73
|
|
|
); |
74
|
|
|
$this->body_data['default_series_category_selected'] = $this->User_Options->get('default_series_category'); |
75
|
|
|
|
76
|
|
|
/*** ENABLE LIVE JS COUNTDOWN TIMER ***/ |
77
|
|
|
$this->body_data = array_merge($this->body_data, $this->User_Options->generate_radio_array( |
78
|
|
|
'enable_live_countdown_timer', |
79
|
|
|
$this->User_Options->get('enable_live_countdown_timer') |
80
|
|
|
)); |
81
|
|
|
|
82
|
|
|
$this->body_data['list_sort_type'] = array_intersect_key( |
83
|
|
|
array( |
84
|
|
|
'unread' => 'Unread (Alphabetical)', |
85
|
|
|
'unread_latest' => 'Unread (Latest Release)', |
86
|
|
|
'alphabetical' => 'Alphabetical', |
87
|
|
|
'my_status' => 'My Status', |
88
|
|
|
'latest' => 'Latest Release' |
89
|
|
|
), |
90
|
|
|
array_flip(array_values($this->User_Options->options['list_sort_type']['valid_options'])) |
91
|
|
|
); |
92
|
|
|
$this->body_data['list_sort_type_selected'] = $this->User_Options->get('list_sort_type'); |
93
|
|
|
|
94
|
|
|
$this->body_data['list_sort_order'] = array_intersect_key( |
95
|
|
|
array( |
96
|
|
|
'asc' => 'ASC', |
97
|
|
|
'desc' => 'DESC' |
98
|
|
|
), |
99
|
|
|
array_flip(array_values($this->User_Options->options['list_sort_order']['valid_options'])) |
100
|
|
|
); |
101
|
|
|
$this->body_data['list_sort_order_selected'] = $this->User_Options->get('list_sort_order'); |
102
|
|
|
|
103
|
|
|
/** THEME **/ |
104
|
|
|
$this->body_data['theme_option'] = array_intersect_key( |
105
|
|
|
array( |
106
|
|
|
'light' => 'Light', |
107
|
|
|
'dark' => 'Dark' |
108
|
|
|
), |
109
|
|
|
array_flip(array_values($this->User_Options->options['theme']['valid_options'])) |
110
|
|
|
); |
111
|
|
|
$this->body_data['theme_option_selected'] = $this->User_Options->get('theme'); |
112
|
|
|
|
113
|
|
|
/** ENABLE PUBLIC LIST **/ |
114
|
|
|
$this->body_data = array_merge($this->body_data, $this->User_Options->generate_radio_array( |
115
|
|
|
'enable_public_list', |
116
|
|
|
$this->User_Options->get('enable_public_list') |
117
|
|
|
)); |
118
|
|
|
|
119
|
|
|
/** ENABLE MAL SYNC **/ |
120
|
|
|
$this->body_data = array_merge($this->body_data, $this->User_Options->generate_radio_array( |
121
|
|
|
'mal_sync', |
122
|
|
|
$this->User_Options->get('mal_sync') |
123
|
|
|
)); |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
$this->_render_page('User/Options'); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.