1<?php
2
3/**
4 * Core modules
5 * @package modules
6 * @subpackage core
7 */
8
9/**
10 * Check the folder list icon setting
11 * @subpackage core/handler
12 */
13class Hm_Handler_check_folder_icon_setting extends Hm_Handler_Module {
14    /***
15     * set a flag to use folder list icons or not
16     */
17    public function process() {
18        $this->out('hide_folder_icons', $this->user_config->get('no_folder_icons_setting', false));
19    }
20}
21
22/**
23 * Process a password update
24 * @subpackage core/handler
25 */
26class Hm_Handler_process_pw_update extends Hm_Handler_Module {
27    /***
28     * update a password in the session for a server
29     */
30    public function process() {
31        list($success, $form ) = $this->process_form(array('server_pw_id', 'password'));
32        $missing = $this->get('missing_pw_servers', array());
33        if (!$success) {
34            return;
35        }
36        if (!array_key_exists($form['server_pw_id'], $missing)) {
37            return;
38        }
39        $server = $missing[$form['server_pw_id']];
40        switch ($server['type']) {
41            case 'POP3':
42                $current = Hm_POP3_List::dump($server['id']);
43                $current['pass'] = $form['password'];
44                unset($current['nopass']);
45                Hm_POP3_List::add($current, $server['id']);
46                $pop3 = Hm_POP3_List::connect($server['id'], false);
47                if ($pop3->state == 'authed') {
48                    Hm_Msgs::add('Password Updated');
49                    $this->out('connect_status', true);
50                }
51                else {
52                    unset($current['pass']);
53                    Hm_POP3_List::add($current, $server['id']);
54                    Hm_Msgs::add('ERRUnable to authenticate to the POP3 server');
55                    $this->out('connect_status', false);
56                }
57                break;
58            case 'SMTP':
59                $current = Hm_SMTP_List::dump($server['id']);
60                $current['pass'] = $form['password'];
61                unset($current['nopass']);
62                Hm_SMTP_List::add($current, $server['id']);
63                $smtp = Hm_SMTP_List::connect($server['id'], false);
64                if ($smtp->state == 'authed') {
65                    Hm_Msgs::add('Password Updated');
66                    $this->out('connect_status', true);
67                }
68                else {
69                    unset($current['pass']);
70                    Hm_SMTP_List::add($current, $server['id']);
71                    Hm_Msgs::add('ERRUnable to authenticate to the SMTP server');
72                    $this->out('connect_status', false);
73                }
74                break;
75            case 'IMAP':
76                $current = Hm_IMAP_List::dump($server['id']);
77                $current['pass'] = $form['password'];
78                unset($current['nopass']);
79                Hm_IMAP_List::add($current, $server['id']);
80                $imap = Hm_IMAP_List::connect($server['id'], false);
81                if ($imap->get_state() == 'authenticated') {
82                    Hm_Msgs::add('Password Updated');
83                    $this->out('connect_status', true);
84                }
85                else {
86                    unset($current['pass']);
87                    Hm_IMAP_List::add($current, $server['id']);
88                    Hm_Msgs::add('ERRUnable to authenticate to the IMAP server');
89                    $this->out('connect_status', false);
90                }
91                break;
92        }
93    }
94}
95
96/**
97 * Check for missing passwords to populate a home page dialog
98 * @subpackage core/handler
99 */
100class Hm_Handler_check_missing_passwords extends Hm_Handler_Module {
101    /***
102     * pass a list of servers with missing passwords to the output modules
103     */
104    public function process() {
105        if (!$this->user_config->get('no_password_save_setting')) {
106            return;
107        }
108        $missing = array();
109        if ($this->module_is_supported('imap')) {
110            foreach (Hm_IMAP_List::dump() as $index => $vals) {
111                if (array_key_exists('nopass', $vals)) {
112                    $vals['id'] = $index;
113                    $vals['type'] = 'IMAP';
114                    $key = 'imap_'.$index;
115                    $missing[$key] = $vals;
116                }
117            }
118        }
119        if ($this->module_is_supported('pop3')) {
120            foreach (Hm_POP3_List::dump() as $index => $vals) {
121                if (array_key_exists('nopass', $vals)) {
122                    $vals['id'] = $index;
123                    $vals['type'] = 'POP3';
124                    $key = 'pop3_'.$index;
125                    $missing[$key] = $vals;
126                }
127            }
128        }
129        if ($this->module_is_supported('smtp')) {
130            foreach (Hm_SMTP_List::dump() as $index => $vals) {
131                if (array_key_exists('nopass', $vals)) {
132                    $vals['id'] = $index;
133                    $vals['type'] = 'SMTP';
134                    $key = 'smtp_'.$index;
135                    $missing[$key] = $vals;
136                }
137            }
138        }
139        if (count($missing) > 0) {
140            $this->out('missing_pw_servers', $missing);
141        }
142    }
143}
144
145/**
146 * Close the session before it's automatically closed at the end of page processing
147 * @subpackage core/handler
148 */
149class Hm_Handler_close_session_early extends Hm_Handler_Module {
150    /***
151     * Uses the close_early method of the session this->session object
152     */
153    public function process() {
154        $this->session->close_early();
155    }
156}
157
158/**
159 * Build a list of HTTP headers to output to the browser
160 * @subpackage core/handler
161 */
162class Hm_Handler_http_headers extends Hm_Handler_Module {
163    /***
164     * These are pretty restrictive, but the idea is to have a secure starting point
165     */
166    public function process() {
167        $headers = array();
168        if ($this->get('language')) {
169            $headers['Content-Language'] = substr($this->get('language'), 0, 2);
170        }
171        if ($this->request->tls) {
172            $headers['Strict-Transport-Security'] = 'max-age=31536000';
173        }
174        $img_src = "'self'";
175        if ($this->config->get('allow_external_image_sources', false)) {
176            $img_src = '*';
177        }
178        $headers['X-Frame-Options'] = 'SAMEORIGIN';
179        $headers['X-XSS-Protection'] = '1; mode=block';
180        $headers['X-Content-Type-Options'] = 'nosniff';
181        $headers['Expires'] = gmdate('D, d M Y H:i:s \G\M\T', strtotime('-1 year'));
182        $headers['Content-Security-Policy'] = "default-src 'none'; script-src 'self' 'unsafe-inline'; ".
183            "connect-src 'self'; font-src 'self'; img-src ".$img_src." data:; style-src 'self' 'unsafe-inline';";
184        if ($this->request->type == 'AJAX') {
185            $headers['Content-Type'] = 'application/json';
186        }
187        $this->out('http_headers', $headers, false);
188    }
189}
190
191/**
192 * Process input from the the mailto handler setting in the general settings section.
193 * @subpackage core/handler
194 */
195class Hm_Handler_process_mailto_handler_setting extends Hm_Handler_Module {
196    /**
197     * Can be one true or false
198     */
199    public function process() {
200        function mailto_handler_callback($val) {
201            return $val;
202        }
203        process_site_setting('mailto_handler', $this, 'mailto_handler_callback', false, true);
204    }
205}
206
207/**
208 * Process input from the the list style setting in the general settings section.
209 * @subpackage core/handler
210 */
211class Hm_Handler_process_list_style_setting extends Hm_Handler_Module {
212    /**
213     * Can be one of two values, 'email_style' or 'list_style'. The default is 'email_style'.
214     */
215    public function process() {
216        function list_style_callback($val) {
217            if (in_array($val, array('email_style', 'news_style'))) {
218                return $val;
219            }
220            return 'email_style';
221        }
222        process_site_setting('list_style', $this, 'list_style_callback');
223    }
224}
225
226/**
227 * Process input from the the start page setting in the general settings section.
228 * @subpackage core/handler
229 */
230class Hm_Handler_process_start_page_setting extends Hm_Handler_Module {
231    /**
232     * Can be one of the values in start_page_opts()
233     */
234    public function process() {
235        function start_page_callback($val) {
236            if (in_array($val, start_page_opts(), true)) {
237                return $val;
238            }
239            return false;
240        }
241        process_site_setting('start_page', $this, 'start_page_callback');
242    }
243}
244
245/**
246 * Process "hide folder list icons" setting
247 * @subpackage core/handler
248 */
249class Hm_Handler_process_hide_folder_icons extends Hm_Handler_Module {
250    /**
251     * valid values are true or false
252     */
253    public function process() {
254        function hide_folder_icons_callback($val) {
255            return $val;
256        }
257        process_site_setting('no_folder_icons', $this, 'hide_folder_icons_callback', false, true);
258    }
259}
260
261/**
262 * Process "show icons in message lists" setting for the message list page in the settings page
263 * @subpackage core/handler
264 */
265class Hm_Handler_process_show_list_icons extends Hm_Handler_Module {
266    /**
267     * valid values are true or false
268     */
269    public function process() {
270        function show_list_icons_callback($val) {
271            return $val;
272        }
273        process_site_setting('show_list_icons', $this, 'show_list_icons_callback', false, true);
274    }
275}
276
277/**
278 * Process input from the max per source setting for the Unread page in the settings page
279 * @subpackage core/handler
280 */
281class Hm_Handler_process_unread_source_max_setting extends Hm_Handler_Module {
282    /**
283     * Allowed values are greater than zero and less than MAX_PER_SOURCE
284     */
285    public function process() {
286        process_site_setting('unread_per_source', $this, 'max_source_setting_callback', DEFAULT_PER_SOURCE);
287    }
288}
289
290/**
291 * Process input from the max per source setting for the All E-mail page in the settings page
292 * @subpackage core/handler
293 */
294class Hm_Handler_process_all_email_source_max_setting extends Hm_Handler_Module {
295    /**
296     * Allowed values are greater than zero and less than MAX_PER_SOURCE
297     */
298    public function process() {
299        process_site_setting('all_email_per_source', $this, 'max_source_setting_callback', DEFAULT_PER_SOURCE);
300    }
301}
302
303/**
304 * Process input from the no pasword between logins setting
305 * @subpackage core/handler
306 */
307class Hm_Handler_process_no_password_setting extends Hm_Handler_Module {
308    /**
309     * Allowed vals are bool true/false
310     */
311    public function process() {
312        function no_password_callback($val) {
313            return $val;
314        }
315        process_site_setting('no_password_save', $this, 'no_password_callback', false, true);
316    }
317}
318
319/**
320 * Process input from the disable delete prompts setting
321 * @subpackage core/handler
322 */
323class Hm_Handler_process_delete_prompt_setting extends Hm_Handler_Module {
324    /**
325     * Allowed vals are bool true/false
326     */
327    public function process() {
328        function delete_disabled_callback($val) {
329            return $val;
330        }
331        process_site_setting('disable_delete_prompt', $this, 'delete_disabled_callback', false, true);
332    }
333}
334
335/**
336 * Process input from the max per source setting for the Everything page in the settings page
337 * @subpackage core/handler
338 */
339class Hm_Handler_process_all_source_max_setting extends Hm_Handler_Module {
340    /**
341     * Allowed values are greater than zero and less than MAX_PER_SOURCE
342     */
343    public function process() {
344        process_site_setting('all_per_source', $this, 'max_source_setting_callback', DEFAULT_PER_SOURCE);
345    }
346}
347
348/**
349 * Process input from the max per source setting for the Flagged page in the settings page
350 * @subpackage core/handler
351 */
352class Hm_Handler_process_flagged_source_max_setting extends Hm_Handler_Module {
353    /**
354     * Allowed values are greater than zero and less than MAX_PER_SOURCE
355     */
356    public function process() {
357        process_site_setting('flagged_per_source', $this,'max_source_setting_callback', DEFAULT_PER_SOURCE);
358    }
359}
360
361/**
362 * Process "since" setting for the Flagged page in the settings page
363 * @subpackage core/handler
364 */
365class Hm_Handler_process_flagged_since_setting extends Hm_Handler_Module {
366    /**
367     * valid values are defined in the process_since_argument function
368     */
369    public function process() {
370        process_site_setting('flagged_since', $this, 'since_setting_callback');
371    }
372}
373
374/**
375 * Process "since" setting for the Everything page in the settings page
376 * @subpackage core/handler
377 */
378class Hm_Handler_process_all_since_setting extends Hm_Handler_Module {
379    /**
380     * valid values are defined in the process_since_argument function
381     */
382    public function process() {
383        process_site_setting('all_since', $this, 'since_setting_callback');
384    }
385}
386
387/**
388 * Process "since" setting for the All E-mail page in the settings page
389 * @subpackage core/handler
390 */
391class Hm_Handler_process_all_email_since_setting extends Hm_Handler_Module {
392    /**
393     * valid values are defined in the process_since_argument function
394     */
395    public function process() {
396        process_site_setting('all_email_since', $this, 'since_setting_callback');
397    }
398}
399
400/**
401 * Process "since" setting for the Unread page in the settings page
402 * @subpackage core/handler
403 */
404class Hm_Handler_process_unread_since_setting extends Hm_Handler_Module {
405    /**
406     * valid values are defined in the process_since_argument function
407     */
408    public function process() {
409        process_site_setting('unread_since', $this, 'since_setting_callback');
410    }
411}
412
413/**
414 * Process language setting from the general section of the settings page
415 * @subpackage core/handler
416 */
417class Hm_Handler_process_language_setting extends Hm_Handler_Module {
418    /**
419     * compared against the list in modules/core/functions.php:interface_langs()
420     */
421    public function process() {
422        function language_setting_callback($val) {
423            if (array_key_exists($val, interface_langs())) {
424                return $val;
425            }
426            return 'en';
427        }
428        process_site_setting('language', $this, 'language_setting_callback');
429    }
430}
431
432/**
433 * Process the timezone setting from the general section of the settings page
434 * @subpackage core/handler
435 */
436class Hm_Handler_process_timezone_setting extends Hm_Handler_Module {
437    public function process() {
438        function timezone_setting_callback($val) {
439            if (in_array($val, timezone_identifiers_list(), true)) {
440                return $val;
441            }
442            return false;
443        }
444        process_site_setting('timezone', $this, 'timezone_setting_callback');
445    }
446}
447
448/**
449 * Save user settings permanently
450 * @subpackage core/handler
451 */
452class Hm_Handler_process_save_form extends Hm_Handler_Module {
453    /**
454     * save any changes since login to permanent storage
455     */
456    public function process() {
457        list($success, $form) = $this->process_form(array('password'));
458        if (!$success) {
459            return;
460        }
461        $save = false;
462        $logout = false;
463        if (array_key_exists('save_settings_permanently', $this->request->post)) {
464            $save = true;
465        }
466        elseif (array_key_exists('save_settings_permanently_then_logout', $this->request->post)) {
467            $save = true;
468            $logout = true;
469        }
470        if ($save) {
471            save_user_settings($this, $form, $logout);
472        }
473    }
474}
475
476/**
477 * Save settings from the settings page to the session
478 * @subpackage core/handler
479 */
480class Hm_Handler_save_user_settings extends Hm_Handler_Module {
481    /**
482     * save new site settings to the session
483     */
484    public function process() {
485        list($success, $form) = $this->process_form(array('save_settings'));
486        if (!$success) {
487            return;
488        }
489        if ($new_settings = $this->get('new_user_settings', array())) {
490            foreach ($new_settings as $name => $value) {
491                $this->user_config->set($name, $value);
492            }
493            Hm_Msgs::add('Settings updated');
494            $this->session->record_unsaved('Site settings updated');
495            $this->out('reload_folders', true, false);
496        }
497    }
498}
499
500/**
501 * Setup a default title
502 * @subpackage core/handler
503 */
504class Hm_Handler_title extends Hm_Handler_Module {
505    /**
506     * output a default title based on the page URL argument
507     */
508    public function process() {
509        $this->out('title', ucfirst($this->page));
510    }
511}
512
513/**
514 * Setup the current language
515 * @subpackage core/handler
516 */
517class Hm_Handler_language extends Hm_Handler_Module {
518    /**
519     * output the user configured language or English if not set
520     */
521    public function process() {
522        $this->out('language', $this->user_config->get('language_setting', 'en'));
523    }
524}
525
526/**
527 * Setup the date
528 * @subpackage core/handler
529 */
530class Hm_Handler_date extends Hm_Handler_Module {
531    /**
532     * output a simple date string
533     */
534    public function process() {
535        $this->out('date', date('G:i:s'));
536    }
537}
538
539/**
540 * Check for the "stay logged in" option
541 */
542class Hm_Handler_stay_logged_in extends Hm_Handler_Module {
543    /**
544     * If "stay logged in" is checked, set the session lifetime
545     */
546    public function process() {
547        if ($this->config->get('allow_long_session')) {
548            $this->out('allow_long_session', true);
549        }
550        $lifetime = intval($this->config->get('long_session_lifetime', 30));
551        list($success, $form) = $this->process_form(array('stay_logged_in'));
552        if ($success && $form['stay_logged_in']) {
553            $this->session->lifetime = time()+60*60*24*$lifetime;
554        }
555    }
556}
557
558/**
559 * Process a potential login attempt
560 * @subpackage core/handler
561 */
562class Hm_Handler_login extends Hm_Handler_Module {
563    /**
564     * Perform a new login if the form was submitted, otherwise check for and continue a session if it exists
565     */
566    public $validate_request = true;
567    public function process() {
568        $this->out('is_mobile', $this->request->mobile);
569        if ($this->get('create_username', false)) {
570            return;
571        }
572        list($success, $form) = $this->process_form(array('username', 'password'));
573        if ($success) {
574            $this->session->check($this->request, rtrim($form['username']), $form['password']);
575            if ($this->session->auth_failed) {
576                Hm_Msgs::add("ERRInvalid username or password");
577            }
578            $this->session->set('username', rtrim($form['username']));
579            if ($this->config->get('redirect_after_login')) {
580                $this->out('redirect_url', $this->config->get('redirect_after_login'));
581            }
582        }
583        else {
584            $this->session->check($this->request);
585        }
586        if ($this->session->is_active()) {
587            $this->out('changed_settings', $this->session->get('changed_settings', array()), false);
588            $this->out('username', $this->session->get('username'));
589        }
590        if ($this->validate_request) {
591            Hm_Request_Key::load($this->session, $this->request, $this->session->loaded);
592            $this->validate_method($this->session, $this->request);
593            $this->process_key();
594            if (!$this->config->get('disable_origin_check', false)) {
595                $this->validate_origin($this->session, $this->request, $this->config);
596            }
597        }
598    }
599}
600
601/**
602 * Setup default page data
603 * @subpackage core/handler
604 */
605class Hm_Handler_default_page_data extends Hm_Handler_Module {
606    public function process() {
607        $this->out('data_sources', array(), false);
608        $this->out('encrypt_ajax_requests', $this->config->get('encrypt_ajax_requests', false));
609        $this->out('encrypt_local_storage', $this->config->get('encrypt_local_storage', false));
610        if (!crypt_state($this->config)) {
611            $this->out('single_server_mode', true);
612        }
613    }
614}
615
616/**
617 * Load user data
618 * @subpackage core/handler
619 */
620class Hm_Handler_load_user_data extends Hm_Handler_Module {
621    /**
622     * Load data from persistant storage on login, or from the session if already logged in
623     */
624    public function process() {
625        list($success, $form) = $this->process_form(array('username', 'password'));
626        if ($this->session->is_active()) {
627            if ($success) {
628                $this->user_config->load(rtrim($form['username']), $form['password']);
629            }
630            else {
631                $user_data = $this->session->get('user_data', array());
632                if (!empty($user_data)) {
633                    $this->user_config->reload($user_data, $this->session->get('username'));
634                }
635                $pages = $this->user_config->get('saved_pages', array());
636                if (!empty($pages)) {
637                    $this->session->set('saved_pages', $pages);
638                }
639            }
640            $this->out('disable_delete_prompt', $this->user_config->get('disable_delete_prompt_setting'));
641        }
642        if ($this->session->loaded) {
643            $start_page = $this->user_config->get('start_page_setting');
644            if ($start_page && $start_page != 'none' && in_array($start_page, start_page_opts(), true)) {
645                $this->out('redirect_url', '?'.$start_page);
646            }
647        }
648        $this->out('mailto_handler', $this->user_config->get('mailto_handler_setting', false));
649        $this->out('no_password_save', $this->user_config->get('no_password_save_setting', false));
650    }
651}
652
653/**
654 * Save user data to the session
655 * @subpackage core/handler
656 */
657class Hm_Handler_save_user_data extends Hm_Handler_Module {
658    /**
659     * @todo rename to make it obvious this is session only
660     */
661    public function process() {
662        $user_data = $this->user_config->dump();
663        if (!empty($user_data)) {
664            $this->session->set('user_data', $user_data);
665        }
666    }
667}
668
669/**
670 * Process a logout
671 * @subpackage core/handler
672 */
673class Hm_Handler_logout extends Hm_Handler_Module {
674    /**
675     * Clean up everything on logout
676     */
677    public function process() {
678        if (array_key_exists('logout', $this->request->post) && !$this->session->loaded) {
679            $this->session->destroy($this->request);
680            Hm_Msgs::add('Session destroyed on logout');
681        }
682        elseif (array_key_exists('save_and_logout', $this->request->post)) {
683            list($success, $form) = $this->process_form(array('password'));
684            if ($success) {
685                $user = $this->session->get('username', false);
686                $path = $this->config->get('user_settings_dir', false);
687                $pages = $this->session->get('saved_pages', array());
688                if (!empty($pages)) {
689                    $this->user_config->set('saved_pages', $pages);
690                }
691                if ($this->session->auth($user, $form['password'])) {
692                    $pass = $form['password'];
693                }
694                else {
695                    Hm_Msgs::add('ERRIncorrect password, could not save settings to the server');
696                    $pass = false;
697                }
698                if ($user && $path && $pass) {
699                    $this->user_config->save($user, $pass);
700                    $this->session->destroy($this->request);
701                    Hm_Msgs::add('Saved user data on logout');
702                    Hm_Msgs::add('Session destroyed on logout');
703                }
704            }
705            else {
706                Hm_Msgs::add('ERRYour password is required to save your settings to the server');
707            }
708        }
709    }
710}
711
712/**
713 * Setup the message list type based on URL arguments
714 * @subpackage core/handler
715 */
716class Hm_Handler_message_list_type extends Hm_Handler_Module {
717    /**
718     * @todo clean this up somehow
719     */
720    public function process() {
721        $uid = '';
722        $list_parent = '';
723        $list_page = 1;
724        $list_meta = true;
725        $list_path = '';
726        $mailbox_list_title = array();
727        $message_list_since = DEFAULT_SINCE;
728        $per_source_limit = DEFAULT_PER_SOURCE;
729        $no_list_headers = false;
730
731        if (array_key_exists('list_path', $this->request->get)) {
732            $path = $this->request->get['list_path'];
733            list($list_path, $mailbox_list_title, $message_list_since, $per_source_limit) = get_message_list_settings($path, $this);
734        }
735        if (array_key_exists('list_parent', $this->request->get)) {
736            $list_parent = $this->request->get['list_parent'];
737        }
738        if (array_key_exists('list_page', $this->request->get)) {
739            $list_page = (int) $this->request->get['list_page'];
740            if ($list_page < 1) {
741                $list_page = 1;
742            }
743        }
744        else {
745            $list_page = 1;
746        }
747        if (array_key_exists('uid', $this->request->get) && preg_match("/\d+/", $this->request->get['uid'])) {
748            $uid = $this->request->get['uid'];
749        }
750        $list_style = $this->user_config->get('list_style_setting', false);
751        if ($this->get('is_mobile', false)) {
752            $list_style = 'news_style';
753        }
754        if ($list_style == 'news_style') {
755            $no_list_headers = true;
756            $this->out('news_list_style', true);
757        }
758        $this->out('uid', $uid);
759        $this->out('list_path', $list_path, false);
760        $this->out('list_meta', $list_meta, false);
761        $this->out('list_parent', $list_parent, false);
762        $this->out('list_page', $list_page, false);
763        $this->out('mailbox_list_title', $mailbox_list_title, false);
764        $this->out('message_list_since', $message_list_since, false);
765        $this->out('per_source_limit', $per_source_limit, false);
766        $this->out('no_message_list_headers', $no_list_headers);
767        $this->out('msg_list_icons', $this->user_config->get('show_list_icons_setting', false));
768        $this->out('message_list_fields', array(
769            array('chkbox_col', false, false),
770            array('source_col', 'source', 'Source'),
771            array('from_col', 'from', 'From'),
772            array('subject_col', 'subject', 'Subject'),
773            array('date_col', 'msg_date', 'Date'),
774            array('icon_col', false, false)), false);
775    }
776}
777
778/**
779 * Set a cookie to instruct the JS to reload the folder list
780 * @subpackage core/handler
781 */
782class Hm_Handler_reload_folder_cookie extends Hm_Handler_Module {
783    /**
784     * This cookie will be deleted by JS
785     */
786    public function process() {
787        if ($this->get('reload_folders', false)) {
788            $this->session->secure_cookie($this->request, 'hm_reload_folders', '1');
789        }
790    }
791}
792
793/**
794 * @subpackage core/handler
795 */
796class Hm_Handler_reset_search extends Hm_Handler_Module {
797    public function process() {
798        $this->session->set('search_terms', '');
799        $this->session->set('search_since', DEFAULT_SINCE);
800        $this->session->set('search_fld', DEFAULT_SEARCH_FLD);
801    }
802}
803
804/**
805 * Process search terms from a URL
806 * @subpackage core/handler
807 */
808class Hm_Handler_process_search_terms extends Hm_Handler_Module {
809    /**
810     * validate and set search tems in the session
811     */
812    public function process() {
813        if (array_key_exists('search_terms', $this->request->get) && $this->request->get['search_terms']) {
814            $this->out('run_search', 1, false);
815            $this->session->set('search_terms', validate_search_terms($this->request->get['search_terms']));
816        }
817        if (array_key_exists('search_since', $this->request->get)) {
818            $this->session->set('search_since', process_since_argument($this->request->get['search_since'], true));
819        }
820        if (array_key_exists('search_fld', $this->request->get)) {
821            $this->session->set('search_fld', validate_search_fld($this->request->get['search_fld']));
822        }
823        $this->out('search_since', $this->session->get('search_since', DEFAULT_SINCE));
824        $this->out('search_terms', $this->session->get('search_terms', ''));
825        $this->out('search_fld', $this->session->get('search_fld', DEFAULT_SEARCH_FLD));
826        if ($this->session->get('search_terms')) {
827            $this->out('run_search', 1);
828        }
829    }
830}
831
832