1: <?php
2: /**
3: * Copyright 2012-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2012-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Special prefs handling for the 'image_replacement_addrs' preference.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2012-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Prefs_Special_ImageReplacement implements Horde_Core_Prefs_Ui_Special
24: {
25: /**
26: * Safe address list.
27: *
28: * @var Horde_Mail_Rfc822_List
29: */
30: protected $_addrlist;
31:
32: /**
33: */
34: public function init(Horde_Core_Prefs_Ui $ui)
35: {
36: }
37:
38: /**
39: */
40: public function display(Horde_Core_Prefs_Ui $ui)
41: {
42: $view = new Horde_View(array(
43: 'templatePath' => IMP_TEMPLATES . '/prefs'
44: ));
45: $view->addHelper('Text');
46:
47: $view->safe_addrs = implode("\n", $this->safeAddrList()->bare_addresses);
48:
49: return $view->render('imagereplacement');
50: }
51:
52: /**
53: */
54: public function update(Horde_Core_Prefs_Ui $ui)
55: {
56: $alist = new Horde_Mail_Rfc822_List(preg_split("/[\r\n]+/", $ui->vars->safe_addrs));
57: $alist->unique();
58:
59: if ($GLOBALS['prefs']->setValue('image_replacement_addrs', json_encode($alist->bare_addresses))) {
60: $this->_addrlist = $alist;
61: return true;
62: }
63:
64: return false;
65: }
66:
67: /**
68: * @return Horde_Mail_Rfc822_List
69: */
70: public function safeAddrList()
71: {
72: if (!isset($this->_addrlist)) {
73: $alist = json_decode($GLOBALS['prefs']->getValue('image_replacement_addrs'));
74: if (empty($alist)) {
75: $alist = array();
76: }
77:
78: $this->_addrlist = new Horde_Mail_Rfc822_List($alist);
79: }
80:
81: return $this->_addrlist;
82: }
83:
84: /**
85: * @param mixed $address Address to add to the safe address list.
86: *
87: * @return boolean True if successfully added.
88: */
89: public function addSafeAddrList($address)
90: {
91: $alist = $this->safeAddrList();
92: $alist->add($address);
93: $alist->unique();
94:
95: return $GLOBALS['prefs']->setValue('image_replacement_addrs', json_encode($alist->bare_addresses));
96: }
97:
98: /**
99: * Can addresses be added to the safe list?
100: *
101: * @return boolean True if addresses can be added.
102: */
103: public function canAddToSafeAddrList()
104: {
105: return !$GLOBALS['prefs']->isLocked('image_replacement_addrs');
106: }
107:
108: }
109: