XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AbstractImageObject.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
18{
19 public const IMAGE_TAG = '<img src="%s" width="%d" height="%d" alt="%s">';
20 public 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>
21</object>';
22
23 protected $mDirArray = [];
24 protected $_mTemporaryPath = null;
25 protected $_mFilename = null;
26 protected $_mIsDeleted = false;
27
35 public function __construct()
36 {
37 $this->initVar('image_id', XOBJ_DTYPE_INT, 0, false);
38 $this->initVar('title', XOBJ_DTYPE_STRING, '', false, 191);
39 $this->initVar('uid', XOBJ_DTYPE_INT, '', false);
40 $this->initVar('dirname', XOBJ_DTYPE_STRING, '', false);
41 $this->initVar('dataname', XOBJ_DTYPE_STRING, '', false);
42 $this->initVar('data_id', XOBJ_DTYPE_INT, '', false);
43 $this->initVar('num', XOBJ_DTYPE_INT, 1, false);
44 //body of file name
45 $this->initVar('file_name', XOBJ_DTYPE_STRING, '', false, 60);
46 //extension type of file name : Lenum_FileType
47 $this->initVar('file_type', XOBJ_DTYPE_INT, '', false);
48 $this->initVar('image_width', XOBJ_DTYPE_INT, '', false);
49 $this->initVar('image_height', XOBJ_DTYPE_INT, '', false);
50 $this->initVar('posttime', XOBJ_DTYPE_INT, time(), false);
51 }
52
60 public function setupPostData(/*** int ***/ $num=1)
61 {
62 //set uploaded image file path
63 $uploaded = @$_FILES['legacy_image']['tmp_name'] ? $_FILES['legacy_image'] : null;
64 if (isset($uploaded) && file_exists($uploaded['tmp_name'][$num]) && false !== @exif_imagetype($uploaded['tmp_name'][$num])) {
65 $this->_mTemporaryPath = $uploaded['tmp_name'][$num];
66 $this->_mFilename = $uploaded['name'][$num];
67 }
68
69 //set image id
70 $idName = XCube_Root::getSingleton()->mContext->mRequest->getRequest('legacy_image_id');
71 if (! $this->get('image_id') && isset($idName[$num])) {
72 $this->set('image_id', $idName[$num]);
73 }
74
75 $this->set('num', $num);
76
77 //Should be delete ?
78 $isDeleted = XCube_Root::getSingleton()->mContext->mRequest->getRequest('legacy_image_delete');
79 if ($isDeleted[$num]) {
80 $this->_mIsDeleted = true;
81 }
82 }
83
84 public function getTemporaryPath()
85 {
86 return $this->_mTemporaryPath;
87 }
88
89 public function getFilename()
90 {
91 return $this->_mFilename;
92 }
93
101 public function getRandomFileName($prefix, $salt=null)
102 {
103 if (! isset($salt)) {
104 $root=&XCube_Root::getSingleton();
105 $salt = $root->getSiteConfig('Cube', 'Salt');
106 }
107 mt_srand(microtime() * 1_000_000);
108 $body = md5($salt . random_int(0, mt_getrandmax()));
109 return $prefix . $body;
110 }
111
119 public function isImage(/*** int ***/ $tsize=0)
120 {
121 $srcPath = $this->getFilePath($tsize);
122 if (file_exists($srcPath) && false !== @exif_imagetype($srcPath)) {
123 return true;
124 } else {
125 return false;
126 }
127 }
128
136 public function isDeleted()
137 {
138 return $this->_mIsDeleted;
139 }
140
147 public function getImageInfo($type, $tsize=0)
148 {
149 if (! $this->isImage($tsize)) {
150 return null;
151 }
152 $info = getimagesize($this->getFilePath($tsize));
153
154 switch ($type) {
155 case 'width':
156 case '0':
157 return $info[0];
158 break;
159 case 'height':
160 case '1':
161 return $info[1];
162 break;
163 case 'file_type':
164 case '2':
165 return $info[2];
166 break;
167 case 'attr':
168 case '3':
169 return $info[3];
170 break;
171 }
172 }
173
183 abstract public function makeImageTag(/*** int ***/ $tsize=1, /*** string ***/ $htmlId=null, /*** string ***/ $htmlClass=null);
184
192 abstract public function getFilePath($tsize=0);
193
201 abstract public function getFileUrl($tsize=0);
202}
makeImageTag( $tsize=1, $htmlId=null, $htmlClass=null)