annotate plugins/rc_foldersort/rc_foldersort.php~ @ 33:d41c01c5c933

two fixes to distro
author Charlie Root
date Sun, 27 May 2018 16:53:20 -0400
parents
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 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
53
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
54 $folder_sorts = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
55 if (array_key_exists($mbox, $folder_sorts)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
56 $folder_sort = $folder_sorts[$mbox];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
57 } else if (array_key_exists('default', $folder_sorts)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
58 $folder_sort = $folder_sorts['default'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
59 } else {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
60 $folder_sort = 'date_DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
61 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
62
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
63 list($col, $order) = explode('_', $folder_sort);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
64 if ($order != 'DESC' && $order != 'ASC') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
65 $order = 'DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
66 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
67
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
68 if (!in_array($col, $cols)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
69 $col = 'date';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
70 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
71
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
72 if (is_array($content) && !array_key_exists('_sortcol', $content)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
73 $folder_sort_col_select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
74 foreach ($cols as $temp_col) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
75 $folder_sort_col_select->add(rcube_label($temp_col), $temp_col);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
76 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
77
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
78 $content['_sortcol'] = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
79 'label' => rcube_label('listsorting'),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
80 'value' => $folder_sort_col_select->show($col),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
81 );
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 if (is_array($content) && !array_key_exists('_sortcol', $options)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
85 $options['_sortcol'] = $col;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
86 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
87
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
88 if (is_array($content) && !array_key_exists('_sortord', $content)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
89 $folder_sort_order_select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
90 $folder_sort_order_select->add(rcube_label('asc'), 'ASC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
91 $folder_sort_order_select->add(rcube_label('desc'), 'DESC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
92 $content['_sortord'] = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
93 'label' => rcube_label('listorder'),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
94 'value' => $folder_sort_order_select->show($order),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
95 );
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 if (is_array($content) && !array_key_exists('_sortord', $options)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
99 $options['_sortord'] = $order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
100 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
101
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
102 $args['form']['props']['fieldsets']['settings']['content'] = $content;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
103
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
104 $args['options'] = $options;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
105
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
106 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
107 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
108
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
109 public function folder_update_hook($args)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
110 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
111 $mbox = $args['record']['name'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
112 $settings = $args['record']['settings'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
113 $sort_order = $settings['sort_column'] . '_' . $settings['sort_order'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
114 $cfg_sort = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
115 $cfg_sort[$mbox] = $sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
116 $this->sort_order = $cfg_sort;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
117
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
118 $this->rc->user->save_prefs(array('per_folder_sort' => $this->sort_order));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
119 $this->rc->output->set_env('per_folder_sort', $this->sort_order);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
120
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
121 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
122 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
123
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
124 public function preferences_list_hook($args)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
125 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
126 if ($args['section'] == 'mailbox') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
127 $cols = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
128 'from',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
129 'to',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
130 'subject',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
131 'date',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
132 'size',
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
133 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
134
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
135 $folder_sorts = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
136 if (array_key_exists('default', $folder_sorts)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
137 $folder_sort = $folder_sorts['default'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
138 } else {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
139 $folder_sort = 'date_DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
140 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
141
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
142 list($col, $order) = explode('_', $folder_sort);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
143 if ($order != 'DESC' && $order != 'ASC') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
144 $order = 'DESC';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
145 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
146
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
147 if (!in_array($col, $cols)) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
148 $col = 'date';
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
149 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
150
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
151 $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
152 foreach ($cols as $temp_col) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
153 $sort_select_col->add(rcube_label($temp_col), $temp_col);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
154 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
155
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
156 $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
157 $sort_select_order->add(rcube_label('asc'), 'ASC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
158 $sort_select_order->add(rcube_label('desc'), 'DESC');
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
159 $sort_options = array(
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
160 'title' => rcube_label('listorder'),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
161 'content' => $sort_select_col->show($col) . $sort_select_order->show($order),
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
162 );
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
163
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
164 $args['blocks']['main']['options']['listorder'] = $sort_options;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
165 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
166
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
167 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
168 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
169
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
170 public function preferences_save_hook($args)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
171 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
172 if ($args['section'] == 'mailbox') {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
173 $folder_sort_col = get_input_value('_default_sort_col', RCUBE_INPUT_POST);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
174 $folder_sort_order = get_input_value('_default_sort_order', RCUBE_INPUT_POST);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
175 $folder_sort = $folder_sort_col . '_' . $folder_sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
176 $folder_sorts = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
177 $folder_sorts['default'] = $folder_sort;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
178 $args['prefs']['per_folder_sort'] = $folder_sorts;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
179 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
180
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
181 return $args;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
182 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
183
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
184 public function sort_json_action()
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
185 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
186 $cmd = get_input_value('cmd', RCUBE_INPUT_POST);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
187 $folder = get_input_value('folder', RCUBE_INPUT_POST);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
188 $col = get_input_value('col', RCUBE_INPUT_POST);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
189 $order = get_input_value('order', RCUBE_INPUT_POST);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
190
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
191 switch ($cmd) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
192 case 'change_session': {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
193 $_SESSION['sort_col'] = $col;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
194 $_SESSION['sort_order'] = $order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
195 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
196 case 'save_order': {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
197 $sort_order = $this->sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
198 $sort_order[$folder] = $col . "_" . $order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
199 $this->sort_order = $sort_order;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
200
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
201 $this->rc->user->save_prefs(array('per_folder_sort' => $this->sort_order));
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
202 $this->rc->output->set_env('per_folder_sort', $this->sort_order);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
203 break;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
204 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
205 }
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 private function _debug($value, $key = '', $force = false)
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
209 {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
210 if ($this->debug || $force) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
211 $trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
212 $caller_trace = $trace[0];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
213 $caller_function = $trace[1]['function'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
214 $caller_line = $caller_trace['line'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
215 $caller_file = $caller_trace['file'];
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
216 $caller_file = preg_replace("|.*/|", "", $caller_file);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
217 $str = sprintf("[%s:%d - %s] ", $caller_file, $caller_line, $caller_function);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
218
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
219 $val_type = gettype($value);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
220
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
221 switch ($val_type) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
222 case "object": {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
223 $old_value = $value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
224 $value = get_class($old_value);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
225 $str .= $key . ' type = ' . $value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
226 break;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
227 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
228 default: {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
229 $old_value = $value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
230 $value = var_export($old_value, true);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
231 $str .= $key. ' = ' .$value;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
232 break;
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
233 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
234 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
235
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
236 if ($this->uname) {
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
237 $str = sprintf("[%s] %s", $this->uname, $str);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
238 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
239
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
240 write_log($this->ID, $str);
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
241 }
d41c01c5c933 two fixes to distro
Charlie Root
parents:
diff changeset
242 }
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 ?>