|
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() { |
|
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->getUsedCategories($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
|
|
|
|
|
26
|
|
|
if ($isValid = $this->form_validation->run() === TRUE) { |
|
|
|
|
|
|
27
|
|
|
foreach($customCategories as $categoryK => $category) { |
|
28
|
|
|
if(!in_array($categoryK, $usedCategories)) { |
|
29
|
|
|
$this->User_Options->set($category, $this->input->post($category) ? 'enabled' : 'disabled'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->User_Options->set($category.'_text', $this->input->post($category.'_text') ?? ''); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$this->User_Options->set('default_series_category', $this->input->post('default_series_category')); |
|
36
|
|
|
|
|
37
|
|
|
$this->User_Options->set('enable_live_countdown_timer', $this->input->post('enable_live_countdown_timer')); |
|
38
|
|
|
|
|
39
|
|
|
$this->User_Options->set('list_sort_type', $this->input->post('list_sort_type')); |
|
40
|
|
|
$this->User_Options->set('list_sort_order', $this->input->post('list_sort_order')); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/*** CUSTOM CATEGORIES ***/ |
|
44
|
|
|
foreach($customCategories as $categoryK => $category) { |
|
45
|
|
|
$this->body_data[$category] = ($this->User_Options->get($category) == 'enabled' ? TRUE : FALSE); |
|
46
|
|
|
$this->body_data[$category.'_text'] = $this->User_Options->get($category.'_text'); |
|
47
|
|
|
$this->body_data[$category.'_has_series'] = (int) in_array($categoryK, $usedCategories); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/*** DEFAULT CATEGORY ***/ |
|
51
|
|
|
$this->body_data['default_series_category'] = array_intersect_key( |
|
|
|
|
|
|
52
|
|
|
array( |
|
53
|
|
|
'reading' => 'Reading', |
|
54
|
|
|
'on-hold' => 'On-Hold', |
|
55
|
|
|
'plan-to-read' => 'Plan to Read', |
|
56
|
|
|
'custom1' => 'Custom Category 1', |
|
57
|
|
|
'custom2' => 'Custom Category 2', |
|
58
|
|
|
'custom3' => 'Custom Category 3' |
|
59
|
|
|
), |
|
60
|
|
|
array_flip(array_values($this->User_Options->options['default_series_category']['valid_options'])) |
|
61
|
|
|
); |
|
62
|
|
|
$this->body_data['default_series_category_selected'] = $this->User_Options->get('default_series_category'); |
|
63
|
|
|
|
|
64
|
|
|
/*** ENABLE LIVE JS COUNTDOWN TIMER ***/ |
|
65
|
|
|
$this->body_data = array_merge($this->body_data, $this->User_Options->generate_radio_array( |
|
66
|
|
|
'enable_live_countdown_timer', |
|
67
|
|
|
$this->User_Options->get('enable_live_countdown_timer') |
|
68
|
|
|
)); |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->body_data['list_sort_type'] = array_intersect_key( |
|
|
|
|
|
|
72
|
|
|
array( |
|
73
|
|
|
'unread' => 'Unread', |
|
74
|
|
|
'alphabetical' => 'Alphabetical', |
|
75
|
|
|
'my_status' => 'My Status', |
|
76
|
|
|
'latest' => 'Latest Release' |
|
77
|
|
|
), |
|
78
|
|
|
array_flip(array_values($this->User_Options->options['list_sort_type']['valid_options'])) |
|
79
|
|
|
); |
|
80
|
|
|
$this->body_data['list_sort_type_selected'] = $this->User_Options->get('list_sort_type'); |
|
81
|
|
|
|
|
82
|
|
|
$this->body_data['list_sort_order'] = array_intersect_key( |
|
|
|
|
|
|
83
|
|
|
array( |
|
84
|
|
|
'asc' => 'ASC', |
|
85
|
|
|
'desc' => 'DESC' |
|
86
|
|
|
), |
|
87
|
|
|
array_flip(array_values($this->User_Options->options['list_sort_order']['valid_options'])) |
|
88
|
|
|
); |
|
89
|
|
|
$this->body_data['list_sort_order_selected'] = $this->User_Options->get('list_sort_order'); |
|
90
|
|
|
|
|
91
|
|
|
$this->_render_page('User/Options'); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.