1: <?php
2: 3: 4: 5: 6:
7:
8: if(!defined('XOOPS_ROOT_PATH'))
9: {
10: exit();
11: }
12:
13: abstract class Legacy_AbstractImageObject extends XoopsSimpleObject
14: {
15: const IMAGE_TAG = '<img src="%s" width="%d" height="%d" alt="%s" />';
16: const SWF_TAG = '<object data="%s" type="application/x-shockwave-flash" width="%d" height="%d"><param name="movie" value="%s" /><param name=loop value=false>
17: </object>';
18:
19: protected $mDirArray = array();
20: protected $_mTemporaryPath = null;
21: protected $_mFilename = null;
22: protected $_mIsDeleted = false;
23:
24: 25: 26: 27: 28: 29: 30:
31: public function __construct()
32: {
33: $this->initVar('image_id', XOBJ_DTYPE_INT, 0, false);
34: $this->initVar('title', XOBJ_DTYPE_STRING, '', false, 255);
35: $this->initVar('uid', XOBJ_DTYPE_INT, '', false);
36: $this->initVar('dirname', XOBJ_DTYPE_STRING, '', false);
37: $this->initVar('dataname', XOBJ_DTYPE_STRING, '', false);
38: $this->initVar('data_id', XOBJ_DTYPE_INT, '', false);
39: $this->initVar('num', XOBJ_DTYPE_INT, 1, false);
40:
41: $this->initVar('file_name', XOBJ_DTYPE_STRING, '', false, 60);
42:
43: $this->initVar('file_type', XOBJ_DTYPE_INT, '', false);
44: $this->initVar('image_width', XOBJ_DTYPE_INT, '', false);
45: $this->initVar('image_height', XOBJ_DTYPE_INT, '', false);
46: $this->initVar('posttime', XOBJ_DTYPE_INT, time(), false);
47: }
48:
49: 50: 51: 52: 53: 54: 55:
56: public function setupPostData( $num=1)
57: {
58:
59: $uploaded = @$_FILES['legacy_image']['tmp_name'] ? $_FILES['legacy_image'] : null;
60: if(isset($uploaded) && file_exists($uploaded['tmp_name'][$num]) && @exif_imagetype($uploaded['tmp_name'][$num])!==false){
61: $this->_mTemporaryPath = $uploaded['tmp_name'][$num];
62: $this->_mFilename = $uploaded['name'][$num];
63: }
64:
65:
66: $idName = XCube_Root::getSingleton()->mContext->mRequest->getRequest('legacy_image_id');
67: if(! $this->get('image_id') && isset($idName[$num])){
68: $this->set('image_id', $idName[$num]);
69: }
70:
71: $this->set('num', $num);
72:
73:
74: $isDeleted = XCube_Root::getSingleton()->mContext->mRequest->getRequest('legacy_image_delete');
75: if($isDeleted[$num]){
76: $this->_mIsDeleted = true;
77: }
78: }
79:
80: public function getTemporaryPath()
81: {
82: return $this->_mTemporaryPath;
83: }
84:
85: public function getFilename()
86: {
87: return $this->_mFilename;
88: }
89:
90: 91: 92: 93: 94: 95: 96:
97: public function getRandomFileName($prefix,$salt=null)
98: {
99: if (! isset($salt)) {
100: $root=&XCube_Root::getSingleton();
101: $salt = $root->getSiteConfig('Cube', 'Salt');
102: }
103: srand(microtime() *1000000);
104: $body = md5($salt . rand());
105: return $prefix . $body;
106: }
107:
108: 109: 110: 111: 112: 113: 114:
115: public function isImage( $tsize=0)
116: {
117: $srcPath = $this->getFilePath($tsize);
118: if(file_exists($srcPath) && @exif_imagetype($srcPath)!==false){
119: return true;
120: }
121: else{
122: return false;
123: }
124: }
125:
126: 127: 128: 129: 130: 131: 132:
133: public function isDeleted()
134: {
135: return $this->_mIsDeleted;
136: }
137:
138: 139: 140: 141:
142: public function getImageInfo($type, $tsize=0)
143: {
144: if(! $this->isImage($tsize)){
145: return null;
146: }
147: $info = getimagesize($this->getFilePath($tsize));
148:
149: switch($type){
150: case 'width':
151: case '0':
152: return $info[0];
153: break;
154: case 'height':
155: case '1':
156: return $info[1];
157: break;
158: case 'file_type':
159: case '2':
160: return $info[2];
161: break;
162: case 'attr':
163: case '3':
164: return $info[3];
165: break;
166: }
167: }
168:
169: 170: 171: 172: 173: 174: 175: 176: 177:
178: abstract public function makeImageTag( $tsize=1, $htmlId=null, $htmlClass=null);
179:
180: 181: 182: 183: 184: 185: 186:
187: abstract public function getFilePath($tsize=0);
188:
189: 190: 191: 192: 193: 194: 195:
196: abstract public function getFileUrl($tsize=0);
197: }
198:
199: ?>
200: