1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Compose_Link
24: {
25: 26: 27:
28: public $args = array();
29:
30: 31: 32:
33: public function __construct($in = null)
34: {
35: $fields = array(
36: 'to', 'cc', 'bcc', 'message', 'body', 'subject'
37: );
38:
39: if (is_string($in)) {
40: if (($pos = strpos($in, '?')) !== false) {
41: parse_str(substr($in, $pos + 1), $this->args);
42: $this->args['to'] = substr($in, 0, $pos);
43: } else {
44: $this->args['to'] = $in;
45: }
46: } elseif ($in instanceof Horde_Variables) {
47: foreach ($fields as $val) {
48: if (isset($in->$val)) {
49: $this->args[$val] = $in->$val;
50: }
51: }
52: } elseif (is_array($in)) {
53: $this->args = $in;
54: }
55:
56: if (isset($this->args['to']) &&
57: (strpos($this->args['to'], 'mailto:') === 0)) {
58: $mailto = @parse_url($this->args['to']);
59: if (is_array($mailto)) {
60: $this->args['to'] = isset($mailto['path'])
61: ? $mailto['path']
62: : '';
63: if (!empty($mailto['query'])) {
64: parse_str($mailto['query'], $vals);
65: foreach ($fields as $val) {
66: if (isset($vals[$val])) {
67: $this->args[$val] = $vals[$val];
68: }
69: }
70: }
71: }
72: }
73: }
74:
75: 76: 77: 78: 79: 80: 81:
82: public function link($simplejs = false)
83: {
84: global $browser, $prefs, $registry;
85:
86: $args = $this->args;
87: $callback = $raw = false;
88: $view = $registry->getView();
89:
90: if ($view == Horde_Registry::VIEW_SMARTMOBILE) {
91: $url = new Horde_Core_Smartmobile_Url(Horde::url('smartmobile.php'));
92: $url->setAnchor('compose');
93: } elseif ($simplejs || ($view == Horde_Registry::VIEW_DYNAMIC)) {
94: $args['popup'] = 1;
95:
96: $url = ($view == Horde_Registry::VIEW_DYNAMIC)
97: ? IMP_Dynamic_Compose::url()
98: : IMP_Basic_Compose::url();
99: $raw = true;
100: $callback = array($this, 'composeLinkSimpleCallback');
101: } elseif (($view != Horde_Registry::VIEW_MINIMAL) &&
102: $prefs->getValue('compose_popup') &&
103: $browser->hasFeature('javascript')) {
104: $url = IMP_Basic_Compose::url();
105: $callback = array($this, 'composeLinkJsCallback');
106: } else {
107: $url = ($view == Horde_Registry::VIEW_MINIMAL)
108: ? IMP_Minimal_Compose::url()
109: : IMP_Basic_Compose::url();
110: }
111:
112: if (isset($args['mailbox'])) {
113: $url = IMP_Mailbox::get($args['mailbox'])->url($url, $args['buid']);
114: unset($args['buid'], $args['mailbox']);
115: } elseif (!($url instanceof Horde_Url)) {
116: $url = Horde::url($url);
117: }
118:
119: $url->setRaw($raw)->add($args);
120: if ($callback) {
121: $url->toStringCallback = $callback;
122: }
123:
124: return $url;
125: }
126:
127: 128: 129: 130: 131: 132: 133: 134:
135: public function composeLinkSimpleCallback($url)
136: {
137: return "javascript:void(window.open('" . strval($url) . "','','width=820,height=610,status=1,scrollbars=yes,resizable=yes'))";
138: }
139:
140: 141: 142: 143: 144: 145: 146:
147: public function composeLinkJsCallback($url)
148: {
149: return 'javascript:' . Horde::popupJs(strval($url), array('urlencode' => true));
150: }
151:
152: }
153: