php Eeann aey eciaiaiey ecia aiee Eeann niaa eo noaoe aneea iaoiau aey

  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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
/**
* Eeann aey eciaiaiey ecia?a?aiee
*
* <p>Eeann niaa??eo noaoe?aneea iaoiau aey ?aaiou n ecia?a?aieyie:
* <b>imgResize</b> - nicaaieai oiaiuoaiiie eiiee ecia?a?aiey</p>
* yoio eeann ianeaaoaony io <b>nc_System</b>
*
* @see nc_ImageTransform::imgResize()
*/
class nc_ImageTransform extends nc_System {
protected static $_db;
public static $big;
public static $small;
/**
*
* Nicaaao oiaiuoaiio? eiie? ecia?a?aiey
* @access public
* @static
* @param string $src_img Ioou e enoiaiiio ecia?a?aie?
* @param string $dest_img Ioou e nicaaaaaiiio ecia?a?aie?
* @param int $width Oe?eia iiaiai ecia?a?aiey
* @param int $height Aunioa iiaiai ecia?a?aiey
* @param int $mode [optional] ?a?ei oiaiuoaiey: 0 - i?iii?oeiiaeuii oiaiuoaao; 1 - aienuaaao a oeacaiiua ?acia?u, ia?acay e?ay
* @param string $format [optional] Oi?iao nicaaaaaiiai ecia?a?aiey (jpg, gif, png)
* @param int $quality [optional] Ea?anoai n?aoey ecia?a?aiey (0-100) i?e $format=='jpg'
* @return mixed A neo?aa ioeaee aica?aoeo false eia?a aica?aoeo ioou e nicaaiiiio oaeeo
*/
public static function imgResize($src_img, $dest_img, $width, $height, $mode=0, $format='jpg', $quality=90) {
if (!file_exists($src_img)){
echo "<p>$src_img - file not found</p>";
return false;
}
$img_size = getimagesize($src_img);
if ($img_size === false) return false;
$img_format = strtolower(substr($img_size['mime'], strpos($img_size['mime'], '/') + 1));
if (!function_exists($fn_imgcreatefrom = 'imagecreatefrom'.$img_format)) return false;
$x_ratio = $width / $img_size[0];
$y_ratio = $height / $img_size[1];
$fn_extrem = $mode ? 'max' : 'min';
$ratio = $fn_extrem($x_ratio, $y_ratio);
$new_width = $x_ratio == $ratio ? $width : floor($img_size[0] * $ratio);
$new_height = $x_ratio != $ratio ? $height : floor($img_size[1] * $ratio);
$new_left = $x_ratio == $ratio || !$mode ? 0 : floor(($width - $new_width) / 2);
$new_top = $x_ratio != $ratio || !$mode ? 0 : floor(($height - $new_height) / 2);
$gd_dest_img = imagecreatetruecolor($mode?$width:$new_width, $mode?$height:$new_height);
$gd_src_img = $fn_imgcreatefrom($src_img);
imagecopyresampled($gd_dest_img, $gd_src_img, $new_left, $new_top, 0, 0, $new_width, $new_height, $img_size[0], $img_size[1]);
switch ($format) {
case 'gif': imagegif ($gd_dest_img, $dest_img); break;
case 'png': imagepng ($gd_dest_img, $dest_img); break;
default: imagejpeg($gd_dest_img, $dest_img, $quality); break;
}
imagedestroy($gd_dest_img);
imagedestroy($gd_src_img);
return $dest_img;
}
/**
* Ooieoee aey nicaaiey thumbnails aey iieae oeia oaee,
* a aaenoaeyo iinea aiaaaeaiey, iinea eciaiaiey.
*
* @global array $GLOBALS
* @global string $FILES_FOLDER
* @param string $src_field_name - eiy iiey-enoi?ieea
* @param string $dest_field_name - eiy iiey-i?e?iieea
* @param int $width Oe?eia iiaiai ecia?a?aiey
* @param int $height Aunioa iiaiai ecia?a?aiey
* @param int $mode [optional] ?a?ei oiaiuoaiey: 0 - i?iii?oeiiaeuii oiaiuoaao; 1 - aienuaaao a oeacaiiua ?acia?u, ia?acay e?ay
* @param string $format [optional] Oi?iao nicaaaaaiiai ecia?a?aiey (jpg, gif, png)
* @param int $quality [optional] Ea?anoai n?aoey ecia?a?aiey (0-100) i?e $format=='jpg'
*
* @return bool true a neo?aa oaa?e, false - a neo?aa ioeaee.
* @access public
* @static
*/
public static function createThumb($src_field_name, $dest_field_name, $width, $height, $mode=0, $format='jpg', $quality=90) {
global $GLOBALS;
global $message, $classID;
$src_field_id = $GLOBALS['fldID'][array_search($src_field_name, $GLOBALS['fld'])];
$dest_field_id = $GLOBALS['fldID'][array_search($dest_field_name, $GLOBALS['fld'])];
return self::createThumb_byID($classID, $message, $src_field_id, $dest_field_id, $width, $height,$mode,$format,$quality, $src_field_name);
}
/**
* Ooieoee aey nicaaiey thumbnails aey iieae oeia oaee
*
*
* @global object $nc_core
* @param int $classID - eaaioeoeaeoi? eeanna (eiiiiiaioa)
* @param int $message - iiia? iauaeou
* @param int $field_src_id - eaaioeoeeaoi? iiey enoi?ieea
* @param int $field_dst_id - eaaioeoeeaoi? iiey i?eaiieea
* @param int $width Oe?eia iiaiai ecia?a?aiey
* @param int $height Aunioa iiaiai ecia?a?aiey
* @param int $mode [optional] ?a?ei oiaiuoaiey: 0 - i?iii?oeiiaeuii oiaiuoaao; 1 - aienuaaao a oeacaiiua ?acia?u, ia?acay e?ay
* @param string $format [optional] Oi?iao nicaaaaaiiai ecia?a?aiey (jpg, gif, png)
* @param int $quality [optional] Ea?anoai n?aoey ecia?a?aiey (0-100) i?e $format=='jpg'
* @param string $field_name_src
* @return bool true a neo?aa oaa?e, false - a neo?aa ioeaee.
* @access public
* @static
*/
public static function createThumb_byID($classID,$message,$field_src_id, $field_dst_id, $width, $height, $mode=0, $format='jpg', $quality=90,$field_name_src='') {
global $nc_core;
// i?iaa?ea a?aoiaioia
$message += 0;
$field_src_id += 0;
$field_dst_id += 0;
$classID += 0;
if ( !$message || !$field_src_id || !$field_dst_id || !$classID ) return false;
# iiene enoiaiiai oaeea
// eaoeineia eiy iiey
if ( !$field_name_src ) { $field_name_src = $nc_core->db->get_var("SELECT `Field_Name` FROM `Field` WHERE `Field_ID` = '".$field_src_id."'"); }
if ( !$field_name_src ) return 0;
// Cia?aiea iiey a oaaeeoa iauaeoia
$message_field = $nc_core->db->get_row("SELECT * FROM `Message".$classID."` WHERE `Message_ID` = '".$message."'", ARRAY_A);
$file_data = explode(':', $message_field[$field_name_src]);
$file_name = $file_data[0];
$file_type = $file_data[1];
$file_size = $file_data[2];
$ext = substr($file_name, strrpos($file_name, ".")); // ?anoe?aiea oaeea
$file_name = substr($file_name, 0, strrpos($file_name, ".")); // eiy oaeea aac ?anoe?aiey.
// anee ee oaee a Filetable ?
$filetable = $nc_core->db->get_row("SELECT * FROM `Filetable`
WHERE `Message_ID` = '".intval($message)."' AND `Field_ID` = '".intval($field_src_id)."'", ARRAY_A);
// ii?aaaeaiey iieiiai iooe e oaeeo
if ( $filetable ) { // enoiaiue oaee a protected
$path_src = rtrim($nc_core->FILES_FOLDER, '/').$filetable['File_Path'].$filetable['Virt_Name'];
}
else {
if ( $file_data[3] ) { // orignal
//$path_src = $nc_core->FILES_FOLDER.$file_data[3];
$path_src = $nc_core->FILES_FOLDER. self::$big ."_".$message.$ext;
}
else { // simple
//$path_src = $nc_core->FILES_FOLDER.$field_src."_".$message.$ext;
$path_src = $nc_core->FILES_FOLDER . self::$big . "_".$message.$ext;
}
}
// iieo?aiea eioi?iaoee i iiea-i?eaiieea
$field_info_desc = $nc_core->db->get_row("SELECT `Field_Name`, `Format` FROM `Field` WHERE `Field_ID` = '".$field_dst_id."'", ARRAY_A);
if ( !$field_info_desc) return false;
//oaaeaiea noa?iai oaeea
require_once($nc_core->INCLUDE_FOLDER."s_files.inc.php");
DeleteFile($field_dst_id, $field_info_desc['Field_Name'], $classID, 0, $message);
// ii?aaaeaiea oeia on i?eiaieea
//$fs = nc_parse_fieldformat($field_info_desc['Format'], NC_FIELDTYPE_FILE);
$fs = $fs['fs'];
$file_name.="_thumb";
// ii?aaaeiea eiaie oaeea ia aenea e ae?aoi?ee
switch ( $fs ) {
case NC_FS_PROTECTED:
$path_dsc = $message_field['Subdivision_ID'].'/'.$message_field['Sub_Class_ID'].'/';
$name_dsc = md5($file_name.date("H:i:s d.m.Y").uniqid("netcat"));
break;
case NC_FS_ORIGINAL:
$path_dsc = $message_field['Subdivision_ID'].'/'.$message_field['Sub_Class_ID'].'/';
$name_dsc = nc_get_filename_for_original_fs($file_name.".".$format, $nc_core->FILES_FOLDER.$path_dsc);
break;
//case NC_FS_SIMPLE:
default:
$path_dsc = self::$small;
$name_dsc = $field_dst."_".$message.$ext;
break;
}
// nicaaiea thumb
$path_dest = $nc_core->FILES_FOLDER.$path_dsc.$name_dsc;
// eiie?iaaiea oaeea
copy($path_src, $nc_core->FILES_FOLDER.$path_dsc.$name_dsc);
echo "<p>$path_src <br> $path_dest</p>";
self::imgResize($path_src, $path_dest, $width, $height, $mode, $format, $quality);
switch ( $fs ) {
case NC_FS_PROTECTED :
$img_size = getimagesize($path_dest);
if ($img_size === false) {
if ( file_exists($path_dest) ) unlink($path_dest);
return false;
}
$dst_File_Type = $img_size['mime'];
$dst_File_Size = filesize($path_dest);
$insert_filetable_sql = "INSERT INTO `Filetable`(Real_Name, Virt_Name, File_Path, File_Type, File_Size, Message_ID, Field_ID)
VALUES('".$file_name.".".$format."', '".$name_dsc."', '/".$path_dsc."','".$dst_File_Type."', '".$dst_File_Size."', '".$message."', '".$field_dst_id."')";
$nc_core->db->query($insert_filetable_sql);
$in_db = $file_name.":image/".$dst_File_type.":".$dst_File_size; // oi, ?oi caieoeony a AA
break;
case NC_FS_ORIGINAL :
$in_db = $file_name.".".$format.":image/".$format.":".$file_size; // oi, ?oi caieoeony a AA
$in_db .= ":".$path_dsc.$name_dsc;
break;
default :
$in_db = $file_name.".".$format.":image/".$format.":".$file_size; // oi, ?oi caieoeony a AA
break;
}
// iaiiaeaiea eiou a AAa
$nc_core->db->query("UPDATE `Message".$classID."` SET `".$field_info_desc['Field_Name']."` = '".$in_db."' WHERE `Message_ID` = '".$message."'");
return true;
}
}
?>