1: <?php
2: /**
3: * Copyright 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 2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Auto-determine attachment storage status based on IMP configuration and
16: * attachment data.
17: *
18: * @author Michael Slusarz <slusarz@horde.org>
19: * @category Horde
20: * @copyright 2014 Horde LLC
21: * @license http://www.horde.org/licenses/gpl GPL
22: * @package IMP
23: */
24: class IMP_Compose_Attachment_Storage_AutoDetermine
25: extends IMP_Compose_Attachment_Storage
26: {
27: /**
28: * The underlying storage driver.
29: *
30: * @var IMP_Compose_Attachment_Storage
31: */
32: protected $_storage;
33:
34: /**
35: */
36: public function __construct($user, $id = null)
37: {
38: global $injector;
39:
40: parent::__construct($user, $id);
41:
42: /* Default to linked storage. */
43: $factory = $injector->getInstance('IMP_Factory_ComposeAtc');
44: $this->_storage = new $factory->classLinked($this->_user, $this->_id);
45: }
46:
47: /**
48: */
49: public function __get($name)
50: {
51: switch ($name) {
52: case 'linked':
53: return ($this->_storage instanceof IMP_Compose_Attachment_Linked);
54: }
55:
56: return parent::__get($name);
57: }
58:
59: /**
60: */
61: public function read()
62: {
63: return $this->_storage->read();
64: }
65:
66: /**
67: */
68: protected function _read()
69: {
70: }
71:
72: /**
73: */
74: public function write($filename, Horde_Mime_Part $part)
75: {
76: global $conf, $injector;
77:
78: if (filesize($filename) < intval($conf['compose']['link_attach_threshol'])) {
79: $factory = $injector->getInstance('IMP_Factory_ComposeAtc');
80: $this->_storage = new $factory->classAtc($this->_user, $this->_id);
81: }
82:
83: $this->_storage->write($filename, $part);
84: }
85:
86: /**
87: */
88: protected function _write($filename, Horde_Mime_Part $part)
89: {
90: }
91:
92: /**
93: */
94: public function delete()
95: {
96: $this->_storage->delete();
97: }
98:
99: /**
100: */
101: public function exists()
102: {
103: return $this->_storage->exists();
104: }
105:
106: /**
107: */
108: public function getMetadata()
109: {
110: return $this->_storage->getMetadata();
111: }
112:
113: /**
114: */
115: public function saveMetadata($md = null)
116: {
117: return $this->_storage->saveMetadata($md);
118: }
119:
120: /**
121: */
122: public function gc()
123: {
124: $this->_storage->gc();
125: }
126:
127: }
128: