ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

file_input_access.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
16 //TODO: add field 'attached' wich is 0 by default
17 //TODO: add field 'upload_date' wich is 0 by default
18 //TODO: add method delete_unattached_files, so we'll delete unattached files wich were loaded more than 1 hour ago
19
30 class file_input_access_1_0_0{
31
42 var $NativeTable = '`umx_uploaded_file`';
43
54 var $Database = false;
55 var $DatabaseAlgorithms = false;
56 var $Security = false;
57 var $SecurityParser = false;
58
69 function __construct()
70 {
71 try
72 {
73 $this->Database = get_package( 'database' , 'last' , __FILE__ );
74 $this->DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
75 $this->Security = get_package( 'security' , 'last' , __FILE__ );
76 $this->SecurityParser = get_package( 'security::security_parser' , 'last' , __FILE__ );
77 }
78 catch( Exception $e )
79 {
80 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
81 }
82 }
83
94 var $AddLimitations = '1 = 1';
95
114 function set_add_limitations( $theAddLimitation )
115 {
116 try
117 {
118 if( $this->AddLimitations === '1 = 1' )
119 {
120 $this->AddLimitations = $theAddLimitation;
121 }
122 else
123 {
124 throw( new Exception( '"AddLimitations" was already set' ) );
125 }
126 }
127 catch( Exception $e )
128 {
129 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
130 }
131 }
132
155 function unsafe_select( $Condition )
156 {
157 try
158 {
159 $this->Database->query_as( DB_OBJECT );
160
161 return(
162 $this->Database->select( '*' , $this->NativeTable , "( $this->AddLimitations ) AND $Condition" )
163 );
164 }
165 catch( Exception $e )
166 {
167 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
168 }
169 }
170
209 function select( $Start = false , $Limit = false , $Field = false ,
210 $Order = false , $Condition = '1 = 1' )
211 {
212 try
213 {
214 $Condition = $this->DatabaseAlgorithms->select_condition(
215 $Start , $Limit , $Field , $Order , $Condition , $this->NativeTable
216 );
217
218 return( $this->unsafe_select( $Condition ) );
219 }
220 catch( Exception $e )
221 {
222 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
223 }
224 }
225
248 function delete( $id , $Options = ' 1 = 1' )
249 {
250 try
251 {
252 /* deleting file itself */
253 $Files = $this->select_list( $id );
254 if( count( $Files ) )
255 {
256 foreach( $Files as $i => $File )
257 {
258 @unlink( get_field( $File , 'file_path' ) );
259 }
260
261 /* deleting file record */
262 $id = $this->Security->get( $id , 'integer_list' );
263 $this->Database->delete( $this->NativeTable , "( $this->AddLimitations ) AND id IN ( $id )" );
264 $this->Database->commit();
265 }
266 }
267 catch( Exception $e )
268 {
269 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
270 }
271 }
272
295 function create( $Record )
296 {
297 try
298 {
299 $Record = $this->SecurityParser->parse_parameters(
300 $Record , 'file_path:string;original_file_name:string;preview_image:string,allow_not_set'
301 );
302
303 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
304
305 $id = $this->DatabaseAlgorithms->create( $this->NativeTable , $Fields , $Values );
306
307 $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
308 $EventManager->trigger_event( 'on_after_create_uploaded_file' , array( 'id' => $id ) );
309
310 return( $id );
311 }
312 catch( Exception $e )
313 {
314 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
315 }
316 }
317
340 function update( $id , $Record )
341 {
342 try
343 {
344 $id = $this->Security->get( $id , 'integer_list' );
345 $Record = $this->SecurityParser->parse_parameters(
346 $Record , 'file_path:string;original_file_name:string;preview_image:string' , 'allow_not_set'
347 );
348
349 list( $Fields , $Values ) = $this->DatabaseAlgorithms->compile_fields_values( $Record );
350
351 if( isset( $Fields[ 0 ] ) )
352 {
353 $this->Database->update(
354 $this->NativeTable , $Fields , $Values , "( $this->AddLimitations ) AND id IN ( $id )"
355 );
356 $this->Database->commit();
357 }
358 }
359 catch( Exception $e )
360 {
361 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
362 }
363 }
364
387 function select_list( $id )
388 {
389 try
390 {
391 $id = $this->Security->get( $id , 'integer_list' );
392
393 return( $this->unsafe_select( $this->NativeTable.".id IN ( $id )" ) );
394 }
395 catch( Exception $e )
396 {
397 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
398 }
399 }
400 }
401
402 ?>