annotate plugins/rc_foldersort/rc_foldersort.php @ 43:771f6803cc4b default tip

somehow lost the correctly updated metadata so e.g. 'mail' package wasn't being imported
author Charlie Root
date Sun, 26 Jan 2025 13:13:49 -0500
parents db1e51c59ddc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
1 <?php
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
2 /*
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
3 */
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
4
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
5 class rc_foldersort extends rcube_plugin
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
6 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
7 public $task = 'mail|settings';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
8
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
9 private $rc;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
10 private $sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
11
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
12 private $uname;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
13 private $debug = false;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
14
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
15 public function init()
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
16 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
17 $this->rc = rcube::get_instance();
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
18 $this->uname = $this->rc->user->get_username();
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
19 $userprefs = $this->rc->user->get_prefs();
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
20 $this->sort_order = $userprefs['per_folder_sort'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
21 if (!is_array($this->sort_order)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
22 $this->sort_order = array();
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
23 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
24
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
25 $this->rc->output->set_env('per_folder_sort', $this->sort_order);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
26
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
27 if ($this->rc->task == 'settings') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
28 $this->add_hook('folder_form', array($this, 'folder_form_hook'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
29 $this->add_hook('folder_update', array($this, 'folder_update_hook'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
30 $this->add_hook('preferences_list', array($this, 'preferences_list_hook'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
31 $this->add_hook('preferences_save', array($this, 'preferences_save_hook'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
32 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
33
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
34 if ($this->rc->task == 'mail') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
35 $this->include_script('rc_foldersort.js');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
36 $this->register_action('plugin.rc_foldersort_json', array($this, 'sort_json_action'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
37 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
38 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
39
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
40 public function folder_form_hook($args)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
41 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
42 $content = $args['form']['props']['fieldsets']['settings']['content'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
43 $options = $args['options'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
44 $mbox = $options['name'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
45
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
46 $cols = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
47 'from',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
48 'to',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
49 'subject',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
50 'date',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
51 'size',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
52 'dates'
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
53 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
54
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
55 $folder_sorts = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
56 if (array_key_exists($mbox, $folder_sorts)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
57 $folder_sort = $folder_sorts[$mbox];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
58 } else if (array_key_exists('default', $folder_sorts)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
59 $folder_sort = $folder_sorts['default'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
60 } else {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
61 $folder_sort = 'date_DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
62 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
63
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
64 list($col, $order) = explode('_', $folder_sort);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
65 if ($order != 'DESC' && $order != 'ASC') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
66 $order = 'DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
67 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
68
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
69 if (!in_array($col, $cols)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
70 $col = 'date';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
71 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
72
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
73 if (is_array($content) && !array_key_exists('_sortcol', $content)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
74 $folder_sort_col_select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
75 foreach ($cols as $temp_col) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
76 $folder_sort_col_select->add($this->gettext($temp_col), $temp_col);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
77 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
78
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
79 $content['_sortcol'] = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
80 'label' => $this->gettext('listsorting'),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
81 'value' => $folder_sort_col_select->show($col),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
82 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
83 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
84
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
85 if (is_array($content) && !array_key_exists('_sortcol', $options)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
86 $options['_sortcol'] = $col;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
87 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
88
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
89 if (is_array($content) && !array_key_exists('_sortord', $content)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
90 $folder_sort_order_select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
91 $folder_sort_order_select->add($this->gettext('asc'), 'ASC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
92 $folder_sort_order_select->add($this->gettext('desc'), 'DESC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
93 $content['_sortord'] = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
94 'label' => $this->gettext('listorder'),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
95 'value' => $folder_sort_order_select->show($order),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
96 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
97 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
98
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
99 if (is_array($content) && !array_key_exists('_sortord', $options)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
100 $options['_sortord'] = $order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
101 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
102
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
103 $args['form']['props']['fieldsets']['settings']['content'] = $content;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
104
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
105 $args['options'] = $options;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
106
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
107 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
108 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
109
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
110 public function folder_update_hook($args)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
111 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
112 $mbox = $args['record']['name'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
113 $settings = $args['record']['settings'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
114 $sort_order = $settings['sort_column'] . '_' . $settings['sort_order'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
115 $cfg_sort = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
116 $cfg_sort[$mbox] = $sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
117 $this->sort_order = $cfg_sort;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
118
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
119 $this->rc->user->save_prefs(array('per_folder_sort' => $this->sort_order));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
120 $this->rc->output->set_env('per_folder_sort', $this->sort_order);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
121
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
122 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
123 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
124
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
125 public function preferences_list_hook($args)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
126 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
127 if ($args['section'] == 'mailbox') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
128 $cols = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
129 'from',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
130 'to',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
131 'subject',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
132 'date',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
133 'size',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
134 'dates'
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
135 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
136
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
137 $folder_sorts = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
138 if (array_key_exists('default', $folder_sorts)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
139 $folder_sort = $folder_sorts['default'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
140 } else {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
141 $folder_sort = 'date_DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
142 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
143
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
144 list($col, $order) = explode('_', $folder_sort);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
145 if ($order != 'DESC' && $order != 'ASC') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
146 $order = 'DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
147 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
148
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
149 if (!in_array($col, $cols)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
150 $col = 'date';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
151 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
152
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
153 $sort_select_col = new html_select(array('name' => '_default_sort_col', 'id' => '_default_sort_col'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
154 foreach ($cols as $temp_col) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
155 $sort_select_col->add($this->gettext($temp_col), $temp_col);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
156 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
157
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
158 $sort_select_order = new html_select(array('name' => '_default_sort_order', 'id' => '_default_sort_order'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
159 $sort_select_order->add($this->gettext('asc'), 'ASC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
160 $sort_select_order->add($this->gettext('desc'), 'DESC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
161 $sort_options = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
162 'title' => $this->gettext('listorder'),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
163 'content' => $sort_select_col->show($col) . $sort_select_order->show($order),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
164 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
165
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
166 $args['blocks']['main']['options']['listorder'] = $sort_options;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
167 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
168
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
169 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
170 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
171
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
172 public function preferences_save_hook($args)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
173 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
174 if ($args['section'] == 'mailbox') {
42
db1e51c59ddc various small fixes from upgrades to PHP and/or hangover from fix to apt-get overwrite at beginning of the year somehow
Charlie Root
parents: 33
diff changeset
175 $folder_sort_col = rcube_utils::get_input_value('_default_sort_col', rcube_utils::INPUT_POST);
db1e51c59ddc various small fixes from upgrades to PHP and/or hangover from fix to apt-get overwrite at beginning of the year somehow
Charlie Root
parents: 33
diff changeset
176 $folder_sort_order = rcube_utils::get_input_value('_default_sort_order', rcube_utils::INPUT_POST);
33
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
177 $folder_sort = $folder_sort_col . '_' . $folder_sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
178 $folder_sorts = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
179 $folder_sorts['default'] = $folder_sort;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
180 $args['prefs']['per_folder_sort'] = $folder_sorts;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
181 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
182
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
183 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
184 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
185
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
186 public function sort_json_action()
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
187 {
42
db1e51c59ddc various small fixes from upgrades to PHP and/or hangover from fix to apt-get overwrite at beginning of the year somehow
Charlie Root
parents: 33
diff changeset
188 $cmd = rcube_utils::get_input_value('cmd', rcube_utils::INPUT_POST);
db1e51c59ddc various small fixes from upgrades to PHP and/or hangover from fix to apt-get overwrite at beginning of the year somehow
Charlie Root
parents: 33
diff changeset
189 $folder = rcube_utils::get_input_value('folder', rcube_utils::INPUT_POST);
db1e51c59ddc various small fixes from upgrades to PHP and/or hangover from fix to apt-get overwrite at beginning of the year somehow
Charlie Root
parents: 33
diff changeset
190 $col = rcube_utils::get_input_value('col', rcube_utils::INPUT_POST);
db1e51c59ddc various small fixes from upgrades to PHP and/or hangover from fix to apt-get overwrite at beginning of the year somehow
Charlie Root
parents: 33
diff changeset
191 $order = rcube_utils::get_input_value('order', rcube_utils::INPUT_POST);
33
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
192
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
193 switch ($cmd) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
194 case 'change_session': {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
195 $_SESSION['sort_col'] = $col;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
196 $_SESSION['sort_order'] = $order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
197 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
198 case 'save_order': {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
199 $sort_order = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
200 $sort_order[$folder] = $col . "_" . $order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
201 $this->sort_order = $sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
202
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
203 $this->rc->user->save_prefs(array('per_folder_sort' => $this->sort_order));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
204 $this->rc->output->set_env('per_folder_sort', $this->sort_order);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
205 break;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
206 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
207 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
208 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
209
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
210 private function _debug($value, $key = '', $force = false)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
211 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
212 if ($this->debug || $force) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
213 $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
214 $caller_trace = $trace[0];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
215 $caller_function = $trace[1]['function'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
216 $caller_line = $caller_trace['line'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
217 $caller_file = $caller_trace['file'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
218 $caller_file = preg_replace("|.*/|", "", $caller_file);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
219 $str = sprintf("[%s:%d - %s] ", $caller_file, $caller_line, $caller_function);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
220
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
221 $val_type = gettype($value);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
222
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
223 switch ($val_type) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
224 case "object": {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
225 $old_value = $value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
226 $value = get_class($old_value);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
227 $str .= $key . ' type = ' . $value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
228 break;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
229 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
230 default: {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
231 $old_value = $value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
232 $value = var_export($old_value, true);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
233 $str .= $key. ' = ' .$value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
234 break;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
235 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
236 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
237
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
238 if ($this->uname) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
239 $str = sprintf("[%s] %s", $this->uname, $str);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
240 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
241
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
242 write_log($this->ID, $str);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
243 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
244 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
245
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
246 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
247 ?>