]> git.donarmstrong.com Git - roundcube.git/blob - plugins/archive/archive.php
Imported Upstream version 0.7
[roundcube.git] / plugins / archive / archive.php
1 <?php
2
3 /**
4  * Archive
5  *
6  * Plugin that adds a new button to the mailbox toolbar
7  * to move messages to a (user selectable) archive folder.
8  *
9  * @version @package_version@
10  * @author Andre Rodier, Thomas Bruederli
11  */
12 class archive extends rcube_plugin
13 {
14   public $task = 'mail|settings';
15
16   function init()
17   {
18     $rcmail = rcmail::get_instance();
19
20     // There is no "Archived flags"
21     // $GLOBALS['IMAP_FLAGS']['ARCHIVED'] = 'Archive';
22     if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show')
23       && ($archive_folder = $rcmail->config->get('archive_mbox'))) {
24       $skin_path = $this->local_skin_path();
25       
26       $this->include_script('archive.js');
27       $this->add_texts('localization', true);
28       $this->add_button(
29         array(
30             'command' => 'plugin.archive',
31             'imagepas' => $skin_path.'/archive_pas.png',
32             'imageact' => $skin_path.'/archive_act.png',
33             'width' => 32,
34             'height' => 32,
35             'title' => 'buttontitle',
36             'domain' => $this->ID,
37         ),
38         'toolbar');
39       
40       // register hook to localize the archive folder
41       $this->add_hook('render_mailboxlist', array($this, 'render_mailboxlist'));
42
43       // set env variable for client
44       $rcmail->output->set_env('archive_folder', $archive_folder);
45       $rcmail->output->set_env('archive_folder_icon', $this->url($skin_path.'/foldericon.png'));
46
47       // add archive folder to the list of default mailboxes
48       if (($default_folders = $rcmail->config->get('default_imap_folders')) && !in_array($archive_folder, $default_folders)) {
49         $default_folders[] = $archive_folder;
50         $rcmail->config->set('default_imap_folders', $default_folders);
51       }  
52     }
53     else if ($rcmail->task == 'settings') {
54       $dont_override = $rcmail->config->get('dont_override', array());
55       if (!in_array('archive_mbox', $dont_override)) {
56         $this->add_hook('preferences_list', array($this, 'prefs_table'));
57         $this->add_hook('preferences_save', array($this, 'save_prefs'));
58       }
59     }
60   }
61   
62   function render_mailboxlist($p)
63   {
64     $rcmail = rcmail::get_instance();
65     $archive_folder = $rcmail->config->get('archive_mbox');
66
67     // set localized name for the configured archive folder
68     if ($archive_folder) {
69       if (isset($p['list'][$archive_folder]))
70         $p['list'][$archive_folder]['name'] = $this->gettext('archivefolder');
71       else // search in subfolders
72         $this->_mod_folder_name($p['list'], $archive_folder, $this->gettext('archivefolder'));
73     }
74
75     return $p;
76   }
77
78   function _mod_folder_name(&$list, $folder, $new_name)
79   {
80     foreach ($list as $idx => $item) {
81       if ($item['id'] == $folder) {
82         $list[$idx]['name'] = $new_name;
83         return true;
84       } else if (!empty($item['folders']))
85         if ($this->_mod_folder_name($list[$idx]['folders'], $folder, $new_name))
86         return true;
87     }
88     return false;
89   }
90
91   function prefs_table($args)
92   {
93     global $CURR_SECTION;
94
95     if ($args['section'] == 'folders') {
96       $this->add_texts('localization');
97
98       $rcmail = rcmail::get_instance();
99
100       // load folders list when needed
101       if ($CURR_SECTION)
102         $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true,
103           'maxlength' => 30, 'exceptions' => array('INBOX'), 'folder_filter' => 'mail', 'folder_rights' => 'w'));
104       else
105         $select = new html_select();
106
107       $args['blocks']['main']['options']['archive_mbox'] = array(
108           'title' => $this->gettext('archivefolder'),
109           'content' => $select->show($rcmail->config->get('archive_mbox'), array('name' => "_archive_mbox"))
110       );
111     }
112
113     return $args;
114   }
115
116   function save_prefs($args)
117   {
118     if ($args['section'] == 'folders') {
119       $args['prefs']['archive_mbox'] = get_input_value('_archive_mbox', RCUBE_INPUT_POST);
120       return $args;
121     }
122   }
123
124 }