Blame view

js/_tiny_mce/plugins/ajaxfilemanager/ajax_editor_reset.php 2.71 KB
42868d70   andryeyev   Создал GIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  <?php
  	/**
  	 * reset the image
  	 * @author Logan Cai (cailongqun [at] yahoo [dot] com [dot] cn)
  	 * @link www.phpletter.com
  	 * @since 22/May/2007
  	 *
  	 */
  	require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "config.php");	
  	if(!isset($_POST['path']))
  	{
  		$_POST['path'] = "uploaded/Winter.jpg" .  "?" . makeQueryString(array('path'));
  		//for crop
  		$_POST['mode'] = "crop";
  		$_POST['x'] = 100;
  		$_POST['y'] = 100;
  		$imageInfo = @GetImageSize($_POST['path']);
  		$_POST['width'] = $imageInfo[0];
  		$_POST['height'] = $imageInfo[1];
  		
  	}
  	initSessionHistory($_POST['path']);
  	
  	echo "{";
  	$error = "";
  	$info = "";
  	
  	if(empty($_POST['path']))
  	{
  		$error  =  IMG_SAVE_EMPTY_PATH;
  	}elseif(!file_exists($_POST['path']))
  	{
  		$error  =  IMG_SAVE_NOT_EXISTS;
  	}else if(!isUnderRoot($_POST['path']))
  	{
  		$error = IMG_SAVE_PATH_DISALLOWED;
  	}
  	else
  	{
  		if(!empty($_POST['mode']))
  		{
  			
  			include_once(CLASS_IMAGE);
  			$image = new Image();
  			$image->loadImage($_POST['path']);
  			
  			switch($_POST['mode'])
  			{
  				case "resize":					
  					if(!$image->resize($_POST['width'], $_POST['height'], (!empty($_POST['constraint'])?true:false)))
  					{
  						$error = IMG_SAVE_RESIZE_FAILED;
  					}					
  					break;
  				case "crop":
  					if(!$image->cropToDimensions($_POST['x'], $_POST['y'], intval($_POST['x']) + intval($_POST['width']), intval($_POST['y']) + intval($_POST['height'])))
  					{
  						$error = IMG_SAVE_CROP_FAILED;
  					}
  					
  					break;
  				case "flip":
  					if(!$image->flip($_POST['flip_angle']))
  					{
  						$error = IMG_SAVE_FLIP_FAILED;
  					}
  					break;
  				case "rotate":
  					if(!$image->rotate(intval($_POST['angle'])))
  					{
  						$error = IMG_SAVE_ROTATE_FAILED;
  					}
  					break;
  				default:
  					$error = IMG_SAVE_UNKNOWN_MODE;
  			}
  			if(empty($error))
  			{
  				
  				$sessionNewPath = $session->getSessionDir() . uniqid(md5(time())) . "." . getFileExt($_POST['path']);
  				if(!@copy($_POST['path'], $sessionNewPath))
  				{
  					$error = IMG_SAVE_BACKUP_FAILED;
  				}else 
  				{
  					addSessionHistory($_POST['path'], $sessionNewPath);
  					if($image->saveImage($_POST['path']))
  					{						
  						$imageInfo = $image->getFinalImageInfo();	
  						$info .= ",width:" . $imageInfo['width'] . "\n";
  						$info .= ",height:" . $imageInfo['height'] . "\n";
  						$info .= ",size:'" . transformFileSize($imageInfo['size']) . "'\n";
  					}else 
  					{
  						$error = IMG_SAVE_FAILED;
  					}			
  				}				
  			}else 
  			{
  				//$image->DestroyImages();
  			}
  		}else 
  		{
  			$error = IMG_SAVE_UNKNOWN_MODE;
  		}
  	}
  	
  	echo "error:'" . $error . "'\n";
  	if(isset($image) && is_object($image))
  	{
  		$image->DestroyImages();
  	}
  	echo $info;
  	echo ",history:" . sizeof($_SESSION[$_POST['path']]) . "\n";
  	echo "}";
  ?>