ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

file_input_markup.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
26 class file_input_markup_1_0_0{
27
38 var $Settings = false;
39 var $CachedMultyFS = false;
40 var $FileInputAlgorithms = false;
41 var $Security = false;
42 var $String = false;
43
58 function __construct()
59 {
60 try
61 {
62 $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
63 $this->FileInputAlgorithms = get_package( 'file_input::file_input_algorithms' , 'last' , __FILE__ );
64 $this->Security = get_package( 'security' , 'last' , __FILE__ );
65 $this->String = get_package( 'string' , 'last' , __FILE__ );
66 }
67 catch( Exception $e )
68 {
69 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
70 }
71 }
72
99 private function apply_upload_count( &$Settings , $Code )
100 {
101 try
102 {
103 if( $Settings->get_setting( 'single_input' , false ) )
104 {
105 $Code = str_replace( '{file_upload_limit}' , 1 , $Code );
106 $Code = str_replace( '{file_queue_limit}' , 1 , $Code );
107 }
108 else
109 {
110 $FileUploadLimit = $Settings->get_setting( 'file_upload_limit' , 1 );
111 $Code = str_replace( '{file_upload_limit}' , $FileUploadLimit , $Code );
112 $FileQueueLimit = $Settings->get_setting( 'file_queue_limit' , 1 );
113 $Code = str_replace( '{file_queue_limit}' , $FileQueueLimit , $Code );
114 }
115
116 return( $Code );
117 }
118 catch( Exception $e )
119 {
120 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
121 }
122 }
123
154 private function apply_upload_limitations( &$Settings , $Code , $Name )
155 {
156 try
157 {
158 $Type = $Settings->get_setting( 'file_types' , 'default' );
159 list( $FileExtensions , $FileDescription ) = $this->FileInputAlgorithms->get_file_filters( $Type );
160
161 $Code = str_replace( '{file_types}' , $FileExtensions , $Code );
162 $Code = str_replace( '{file_types_description}' , $FileDescription , $Code );
163 $FileSizeLimit = $Settings->get_setting( 'file_size_limit' , '512 KB' );
164 $Code = str_replace( '{file_size_limit}' , $FileSizeLimit , $Code );
165
166 $Code = $this->apply_upload_count( $Settings , $Code );
167
168 return( $Code );
169 }
170 catch( Exception $e )
171 {
172 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
173 }
174 }
175
202 private function set_event_handlers( &$Settings , $Code )
203 {
204 try
205 {
206 $UploadSuccess = $Settings->get_setting( 'upload_success_handler' , 'uploadSuccess' );
207 $Code = str_replace( '{upload_success_handler}' , $UploadSuccess , $Code );
208
209 $UploadComplete = $Settings->get_setting( 'upload_complete_handler' , 'uploadComplete' );
210 $Code = str_replace( '{upload_complete_handler}' , $UploadComplete , $Code );
211
212 return( $Code );
213 }
214 catch( Exception $e )
215 {
216 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
217 }
218 }
219
242 private function get_uploaded_file_code( &$Settings )
243 {
244 try
245 {
246 $TemplatePath = dirname( __FILE__ ).'/res/templates/file_field.tpl';
247
248 $UploadedFileCode = $this->CachedMultyFS->file_get_contents( $TemplatePath );
249
250 $UploadedFileCode = $this->String->print_record( $UploadedFileCode , $Settings->get_raw_settings() );
251
252 return( $UploadedFileCode );
253 }
254 catch( Exception $e )
255 {
256 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
257 }
258 }
259
282 function compile_file_input( &$Settings )
283 {
284 try
285 {
286 $TemplatePath = dirname( __FILE__ ).'/res/templates/file_input.tpl';
287 $Code = $this->CachedMultyFS->file_get_contents( $TemplatePath );
288
289 $Code = str_replace(
290 '{uploaded_file_code}' , $this->get_uploaded_file_code( $Settings ) , $Code
291 );
292
293 $Url = $Settings->get_setting( 'upload_url' );
294
295 $Name = $Settings->get_setting( 'name' , 'file_input' );
296 $Code = $this->apply_upload_limitations( $Settings , $Code , $Name );
297 $Code = $this->set_event_handlers( $Settings , $Code );
298
299 $Code = str_replace( array( '{name}' , '{upload_url}' ) , array( $Name , $Url ) , $Code );
300
301 return( $Code );
302 }
303 catch( Exception $e )
304 {
305 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
306 }
307 }
308 }
309 ?>