Completed
Push — fix_581 ( c3cd65 )
by Fabio
70:20 queued 60:30
created
framework/Web/UI/ActiveControls/TActiveFileUpload.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 class TActiveFileUpload extends TFileUpload implements IActiveControl, ICallbackEventHandler, INamingContainer
44 44
 {
45 45
 
46
-	const SCRIPT_PATH = 'prado/activefileupload';
46
+	const SCRIPT_PATH='prado/activefileupload';
47 47
 
48 48
 	/**
49 49
 	 * @var THiddenField a flag to tell which component is doing the callback.
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * TActiveControlAdapter. If you override this class, be sure to set the
73 73
 	 * adapter appropriately by, for example, by calling this constructor.
74 74
 	 */
75
-	public function __construct(){
75
+	public function __construct() {
76 76
 		parent::__construct();
77 77
 		$this->setAdapter(new TActiveControlAdapter($this));
78 78
 	}
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	protected function getAssetUrl($file='')
86 86
 	{
87
-		$base = $this->getPage()->getClientScript()->getPradoScriptAssetUrl();
87
+		$base=$this->getPage()->getClientScript()->getPradoScriptAssetUrl();
88 88
 		return $base.'/'.self::SCRIPT_PATH.'/'.$file;
89 89
 	}
90 90
 
@@ -97,18 +97,18 @@  discard block
 block discarded – undo
97 97
 	 */
98 98
 	public function onFileUpload($param)
99 99
 	{
100
-		if ($this->_flag->getValue() && $this->getPage()->getIsPostBack() && $param == $this->_target->getUniqueID()){
100
+		if($this->_flag->getValue() && $this->getPage()->getIsPostBack() && $param==$this->_target->getUniqueID()) {
101 101
 			// save the file so that it will persist past the end of this return.
102
-			$localName = str_replace('\\', '/', tempnam(Prado::getPathOfNamespace($this->getTempPath()),''));
102
+			$localName=str_replace('\\', '/', tempnam(Prado::getPathOfNamespace($this->getTempPath()), ''));
103 103
 			parent::saveAs($localName);
104
-			$this->_localName = $localName;
104
+			$this->_localName=$localName;
105 105
 
106
-			$params = new TActiveFileUploadCallbackParams;
107
-			$params->localName = $localName;
108
-			$params->fileName = addslashes($this->getFileName());
109
-			$params->fileSize = $this->getFileSize();
110
-			$params->fileType = $this->getFileType();
111
-			$params->errorCode = $this->getErrorCode();
106
+			$params=new TActiveFileUploadCallbackParams;
107
+			$params->localName=$localName;
108
+			$params->fileName=addslashes($this->getFileName());
109
+			$params->fileSize=$this->getFileSize();
110
+			$params->fileType=$this->getFileType();
111
+			$params->errorCode=$this->getErrorCode();
112 112
 
113 113
 			// return some javascript to display a completion status.
114 114
 			echo <<<EOS
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 * @return string the path where the uploaded file will be stored temporarily, in namespace format
134 134
 	 * default "Application.runtime.*"
135 135
 	 */
136
-	public function getTempPath(){
136
+	public function getTempPath() {
137 137
 		return $this->getViewState('TempPath', 'Application.runtime.*');
138 138
 	}
139 139
 
@@ -141,15 +141,15 @@  discard block
 block discarded – undo
141 141
 	 * @param string the path where the uploaded file will be stored temporarily in namespace format
142 142
 	 * default "Application.runtime.*"
143 143
 	 */
144
-	public function setTempPath($value){
145
-		$this->setViewState('TempPath',$value,'Application.runtime.*');
144
+	public function setTempPath($value) {
145
+		$this->setViewState('TempPath', $value, 'Application.runtime.*');
146 146
 	}
147 147
 
148 148
 	/**
149 149
 	 * @return boolean a value indicating whether an automatic callback to the server will occur whenever the user modifies the text in the TTextBox control and then tabs out of the component. Defaults to true.
150 150
 	 * Note: When set to false, you will need to trigger the callback yourself.
151 151
 	 */
152
-	public function getAutoPostBack(){
152
+	public function getAutoPostBack() {
153 153
 		return $this->getViewState('AutoPostBack', true);
154 154
 	}
155 155
 
@@ -157,28 +157,28 @@  discard block
 block discarded – undo
157 157
 	 * @param boolean a value indicating whether an automatic callback to the server will occur whenever the user modifies the text in the TTextBox control and then tabs out of the component. Defaults to true.
158 158
 	 * Note: When set to false, you will need to trigger the callback yourself.
159 159
 	 */
160
-	public function setAutoPostBack($value){
161
-		$this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),true);
160
+	public function setAutoPostBack($value) {
161
+		$this->setViewState('AutoPostBack', TPropertyValue::ensureBoolean($value), true);
162 162
 	}
163 163
 
164 164
 	/**
165 165
 	 * @return string A chuck of javascript that will need to be called if {{@link getAutoPostBack AutoPostBack} is set to false}
166 166
 	 */
167
-	public function getCallbackJavascript(){
167
+	public function getCallbackJavascript() {
168 168
 		return "Prado.WebUI.TActiveFileUpload.fileChanged(\"{$this->getClientID()}\")";
169 169
 	}
170 170
 
171 171
 	/**
172 172
 	 * @throws TInvalidDataValueException if the {@link getTempPath TempPath} is not writable.
173 173
 	 */
174
-	public function onInit($sender){
174
+	public function onInit($sender) {
175 175
 		parent::onInit($sender);
176 176
 
177
-		if (!Prado::getApplication()->getCache())
178
-		  if (!Prado::getApplication()->getSecurityManager())
177
+		if(!Prado::getApplication()->getCache())
178
+		  if(!Prado::getApplication()->getSecurityManager())
179 179
 			throw new Exception('TActiveFileUpload needs either an application level cache or a security manager to work securely');
180 180
 
181
-		if (!is_writable(Prado::getPathOfNamespace($this->getTempPath()))){
181
+		if(!is_writable(Prado::getPathOfNamespace($this->getTempPath()))) {
182 182
 			throw new TInvalidDataValueException("activefileupload_temppath_invalid", $this->getTempPath());
183 183
 		}
184 184
 	}
@@ -190,17 +190,17 @@  discard block
 block discarded – undo
190 190
 	 * This method is mainly used by framework and control developers.
191 191
 	 * @param TCallbackEventParameter the event parameter
192 192
 	 */
193
- 	public function raiseCallbackEvent($param){
194
- 		$cp = $param->getCallbackParameter();
195
-		if ($key = $cp->targetID == $this->_target->getUniqueID()){
193
+ 	public function raiseCallbackEvent($param) {
194
+ 		$cp=$param->getCallbackParameter();
195
+		if($key=$cp->targetID==$this->_target->getUniqueID()) {
196 196
 
197
-			$params = $this->popParamsByToken($cp->callbackToken);
197
+			$params=$this->popParamsByToken($cp->callbackToken);
198 198
 
199
-			$_FILES[$key]['name'] = stripslashes($params->fileName);
200
-			$_FILES[$key]['size'] = intval($params->fileSize);
201
-			$_FILES[$key]['type'] = $params->fileType;
202
-			$_FILES[$key]['error'] = intval($params->errorCode);
203
-			$_FILES[$key]['tmp_name'] = $params->localName;
199
+			$_FILES[$key]['name']=stripslashes($params->fileName);
200
+			$_FILES[$key]['size']=intval($params->fileSize);
201
+			$_FILES[$key]['type']=$params->fileType;
202
+			$_FILES[$key]['error']=intval($params->errorCode);
203
+			$_FILES[$key]['tmp_name']=$params->localName;
204 204
 			$this->loadPostData($key, null);
205 205
 
206 206
 			$this->raiseEvent('OnFileUpload', $this, $param);
@@ -219,17 +219,17 @@  discard block
 block discarded – undo
219 219
 
220 220
 	protected function pushParamsAndGetToken(TActiveFileUploadCallbackParams $params)
221 221
 	{
222
-		if ($cache = Prado::getApplication()->getCache())
222
+		if($cache=Prado::getApplication()->getCache())
223 223
 			{
224 224
 				// this is the most secure method, file info can't be forged from client side, no matter what
225
-				$token = md5('TActiveFileUpload::Params::'.$this->ClientID.'::'+rand(1000*1000,9999*1000));
226
-				$cache->set($token, serialize($params), 5*60); // expire in 5 minutes - the callback should arrive back in seconds, actually
225
+				$token=md5('TActiveFileUpload::Params::'.$this->ClientID.'::'+rand(1000 * 1000, 9999 * 1000));
226
+				$cache->set($token, serialize($params), 5 * 60); // expire in 5 minutes - the callback should arrive back in seconds, actually
227 227
 			}
228 228
 		else
229
-		if ($mgr = Prado::getApplication()->getSecurityManager())
229
+		if($mgr=Prado::getApplication()->getSecurityManager())
230 230
 			{
231 231
 				// this is a less secure method, file info can be still forged from client side, but only if attacker knows the secret application key
232
-				$token = urlencode(base64_encode($mgr->encrypt(serialize($params))));
232
+				$token=urlencode(base64_encode($mgr->encrypt(serialize($params))));
233 233
 			}
234 234
 		else
235 235
 			throw new Exception('TActiveFileUpload needs either an application level cache or a security manager to work securely');
@@ -239,18 +239,18 @@  discard block
 block discarded – undo
239 239
 
240 240
 	protected function popParamsByToken($token)
241 241
 	{
242
-		if ($cache = Prado::getApplication()->getCache())
242
+		if($cache=Prado::getApplication()->getCache())
243 243
 			{
244
-				$v = $cache->get($token);
244
+				$v=$cache->get($token);
245 245
 				assert($v!='');
246 246
 				$cache->delete($token); // remove it from cache so it can't be used again and won't take up space either
247
-				$params = unserialize($v);
247
+				$params=unserialize($v);
248 248
 			}
249 249
 		else
250
-		if ($mgr = Prado::getApplication()->getSecurityManager())
250
+		if($mgr=Prado::getApplication()->getSecurityManager())
251 251
 			{
252
-				$v = $mgr->decrypt(base64_decode(urldecode($token)));
253
-				$params = unserialize($v);
252
+				$v=$mgr->decrypt(base64_decode(urldecode($token)));
253
+				$params=unserialize($v);
254 254
 			}
255 255
 		else
256 256
 			throw new Exception('TActiveFileUpload needs either an application level cache or a security manager to work securely');
@@ -267,19 +267,19 @@  discard block
 block discarded – undo
267 267
 	{
268 268
 		parent::onPreRender($param);
269 269
 
270
-		if(!$this->getPage()->getIsPostBack() && isset($_GET['TActiveFileUpload_InputId']) && isset($_GET['TActiveFileUpload_TargetId']) && $_GET['TActiveFileUpload_InputId'] == $this->getClientID())
270
+		if(!$this->getPage()->getIsPostBack() && isset($_GET['TActiveFileUpload_InputId']) && isset($_GET['TActiveFileUpload_TargetId']) && $_GET['TActiveFileUpload_InputId']==$this->getClientID())
271 271
 		{
272 272
 			// tricky workaround to intercept "uploaded file too big" error: real uploads happens in onFileUpload instead
273
-			$this->_errorCode = UPLOAD_ERR_FORM_SIZE;
274
-			$localName = str_replace('\\', '/', tempnam(Prado::getPathOfNamespace($this->getTempPath()),''));
275
-			$fileName = addslashes($this->getFileName());
273
+			$this->_errorCode=UPLOAD_ERR_FORM_SIZE;
274
+			$localName=str_replace('\\', '/', tempnam(Prado::getPathOfNamespace($this->getTempPath()), ''));
275
+			$fileName=addslashes($this->getFileName());
276 276
 
277
-			$params = new TActiveFileUploadCallbackParams;
278
-			$params->localName = $localName;
279
-			$params->fileName = $fileName;
280
-			$params->fileSize = $this->getFileSize();
281
-			$params->fileType = $this->getFileType();
282
-			$params->errorCode = $this->getErrorCode();
277
+			$params=new TActiveFileUploadCallbackParams;
278
+			$params->localName=$localName;
279
+			$params->fileName=$fileName;
280
+			$params->fileSize=$this->getFileSize();
281
+			$params->fileType=$this->getFileType();
282
+			$params->errorCode=$this->getErrorCode();
283 283
 
284 284
 			echo <<<EOS
285 285
 <script language="Javascript">
@@ -297,30 +297,30 @@  discard block
 block discarded – undo
297 297
 		}
298 298
 	}
299 299
 
300
-	public function createChildControls(){
301
-		$this->_flag = Prado::createComponent('THiddenField');
300
+	public function createChildControls() {
301
+		$this->_flag=Prado::createComponent('THiddenField');
302 302
 		$this->_flag->setID('Flag');
303 303
 		$this->getControls()->add($this->_flag);
304 304
 
305
-		$this->_busy = Prado::createComponent('TImage');
305
+		$this->_busy=Prado::createComponent('TImage');
306 306
 		$this->_busy->setID('Busy');
307 307
 		$this->_busy->setImageUrl($this->getAssetUrl('ActiveFileUploadIndicator.gif'));
308 308
 		$this->_busy->setStyle("display:none");
309 309
 		$this->getControls()->add($this->_busy);
310 310
 
311
-		$this->_success = Prado::createComponent('TImage');
311
+		$this->_success=Prado::createComponent('TImage');
312 312
 		$this->_success->setID('Success');
313 313
 		$this->_success->setImageUrl($this->getAssetUrl('ActiveFileUploadComplete.png'));
314 314
 		$this->_success->setStyle("display:none");
315 315
 		$this->getControls()->add($this->_success);
316 316
 
317
-		$this->_error = Prado::createComponent('TImage');
317
+		$this->_error=Prado::createComponent('TImage');
318 318
 		$this->_error->setID('Error');
319 319
 		$this->_error->setImageUrl($this->getAssetUrl('ActiveFileUploadError.png'));
320 320
 		$this->_error->setStyle("display:none");
321 321
 		$this->getControls()->add($this->_error);
322 322
 
323
-		$this->_target = Prado::createComponent('TInlineFrame');
323
+		$this->_target=Prado::createComponent('TInlineFrame');
324 324
 		$this->_target->setID('Target');
325 325
 		$this->_target->setFrameUrl($this->getAssetUrl('ActiveFileUploadBlank.html'));
326 326
 		$this->_target->setStyle("width:0px; height:0px;");
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 	/**
333 333
 	 * Removes localfile on ending of the callback.
334 334
 	 */
335
-	public function onUnload($param){
336
-		if ($this->getPage()->getIsCallback() &&
335
+	public function onUnload($param) {
336
+		if($this->getPage()->getIsCallback() &&
337 337
 			$this->getHasFile() &&
338
-			file_exists($this->getLocalName())){
338
+			file_exists($this->getLocalName())) {
339 339
 				unlink($this->getLocalName());
340 340
 		}
341 341
 		parent::onUnload($param);
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	/**
345 345
 	 * @return TBaseActiveCallbackControl standard callback control options.
346 346
 	 */
347
-	public function getActiveControl(){
347
+	public function getActiveControl() {
348 348
 		return $this->getAdapter()->getBaseActiveControl();
349 349
 	}
350 350
 
@@ -360,18 +360,18 @@  discard block
 block discarded – undo
360 360
 	 * Adds ID attribute, and renders the javascript for active component.
361 361
 	 * @param THtmlWriter the writer used for the rendering purpose
362 362
 	 */
363
-	public function addAttributesToRender($writer){
363
+	public function addAttributesToRender($writer) {
364 364
 		parent::addAttributesToRender($writer);
365
-		$writer->addAttribute('id',$this->getClientID());
365
+		$writer->addAttribute('id', $this->getClientID());
366 366
 
367 367
 		$this->getPage()->getClientScript()->registerPradoScript('activefileupload');
368
-		$this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(),$this->getClientOptions());
368
+		$this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getClientOptions());
369 369
 	}
370 370
 
371 371
 	/**
372 372
 	 * @return string corresponding javascript class name for this control.
373 373
 	 */
374
-	protected function getClientClassName(){
374
+	protected function getClientClassName() {
375 375
 		return 'Prado.WebUI.TActiveFileUpload';
376 376
 	}
377 377
 
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
 	 * 					completeID => complete client ID,
386 386
 	 * 					errorID => error client ID)
387 387
 	 */
388
-	protected function getClientOptions(){
389
-		$options['ID'] = $this->getClientID();
390
-		$options['EventTarget'] = $this->getUniqueID();
391
-
392
-		$options['inputID'] = $this->getClientID();
393
-		$options['flagID'] = $this->_flag->getClientID();
394
-		$options['targetID'] = $this->_target->getUniqueID();
395
-		$options['formID'] = $this->getPage()->getForm()->getClientID();
396
-		$options['indicatorID'] = $this->_busy->getClientID();
397
-		$options['completeID'] = $this->_success->getClientID();
398
-		$options['errorID'] = $this->_error->getClientID();
399
-		$options['autoPostBack'] = $this->getAutoPostBack();
388
+	protected function getClientOptions() {
389
+		$options['ID']=$this->getClientID();
390
+		$options['EventTarget']=$this->getUniqueID();
391
+
392
+		$options['inputID']=$this->getClientID();
393
+		$options['flagID']=$this->_flag->getClientID();
394
+		$options['targetID']=$this->_target->getUniqueID();
395
+		$options['formID']=$this->getPage()->getForm()->getClientID();
396
+		$options['indicatorID']=$this->_busy->getClientID();
397
+		$options['completeID']=$this->_success->getClientID();
398
+		$options['errorID']=$this->_error->getClientID();
399
+		$options['autoPostBack']=$this->getAutoPostBack();
400 400
 		return $options;
401 401
 	}
402 402
 
@@ -407,12 +407,12 @@  discard block
 block discarded – undo
407 407
 	 * If true, you will not be able to save the uploaded file again.
408 408
 	 * @return boolean true if the file saving is successful
409 409
 	 */
410
-	public function saveAs($fileName,$deleteTempFile=true){
411
-		if (($this->getErrorCode()===UPLOAD_ERR_OK) && (file_exists($this->getLocalName()))){
412
-			if ($deleteTempFile)
413
-				return rename($this->getLocalName(),$fileName);
410
+	public function saveAs($fileName, $deleteTempFile=true) {
411
+		if(($this->getErrorCode()===UPLOAD_ERR_OK) && (file_exists($this->getLocalName()))) {
412
+			if($deleteTempFile)
413
+				return rename($this->getLocalName(), $fileName);
414 414
 			else
415
-				return copy($this->getLocalName(),$fileName);
415
+				return copy($this->getLocalName(), $fileName);
416 416
 		} else
417 417
 			return false;
418 418
 	}
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 	 * @return TImage the image displayed when an upload
422 422
 	 * 		completes successfully.
423 423
 	 */
424
-	public function getSuccessImage(){
424
+	public function getSuccessImage() {
425 425
 		$this->ensureChildControls();
426 426
 		return $this->_success;
427 427
 	}
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 	 * @return TImage the image displayed when an upload
431 431
 	 * 		does not complete successfully.
432 432
 	 */
433
-	public function getErrorImage(){
433
+	public function getErrorImage() {
434 434
 		$this->ensureChildControls();
435 435
 		return $this->_error;
436 436
 	}
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	 * @return TImage the image displayed when an upload
440 440
 	 * 		is in progress.
441 441
 	 */
442
-	public function getBusyImage(){
442
+	public function getBusyImage() {
443 443
 		$this->ensureChildControls();
444 444
 		return $this->_busy;
445 445
 	}
Please login to merge, or discard this patch.