ultimix
file_input_algorithms.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 
27 
38  var $FileInputAccess = false;
39  var $Security = false;
40 
41  var $Extensions = array();
42 
57  function __construct()
58  {
59  try
60  {
61  $this->FileInputAccess = get_package( 'file_input::file_input_access' , 'last' , __FILE__ );
62  $this->Security = get_package( 'security' , 'last' , __FILE__ );
63 
64  $this->Extensions[ 'default' ] = array( 'jpg' , 'jpeg' , 'gif' , 'bmp' , 'png' , 'tif' ,
65  'tiff' , 'doc' , 'docx' , 'ppt' , 'pptx' , 'rtf' , 'xls' , 'xslx' , 'pdf'
66  );
67 
68  $this->Extensions[ 'images' ] = array(
69  'jpg' , 'jpeg' , 'gif' , 'bmp' , 'png' , 'tiff' , 'tif'
70  );
71 
72  $this->Extensions[ 'archives' ] = array(
73  'zip' , '7zip' , 'gz' , 'gz2' , 'tar' , 'rar' , 'arc'
74  );
75 
76  $this->Extensions[ 'all' ] = array( '*' );
77  }
78  catch( Exception $e )
79  {
80  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
81  }
82  }
83 
110  function get_extensions( $Type , $AsString = false )
111  {
112  try
113  {
114  $Extensions = array();
115 
116  if( isset( $this->Extensions[ $Type ] ) === false )
117  {
118  throw( new Exception( "File type \"$Type\" is undefined" ) );
119  }
120 
121  return(
122  $AsString ? '*.'.implode( ';*.' , $this->Extensions[ $Type ] ) : $this->Extensions[ $Type ]
123  );
124  }
125  catch( Exception $e )
126  {
127  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
128  }
129  }
130 
153  function get_file_filters( $Type )
154  {
155  try
156  {
157  $FileExtensions = $this->get_extensions( $Type , true );
158 
159  if( $Type == 'default' )
160  {
161  $FileDescription = 'Supported types';
162  }
163  elseif( $Type == 'images' )
164  {
165  $FileDescription = 'Images';
166  }
167  elseif( $Type == 'archives' )
168  {
169  $FileDescription = 'Zip archives';
170  }
171  elseif( $Type == 'all' )
172  {
173  $FileDescription = 'All files';
174  }
175 
176  return( array( $FileExtensions , $FileDescription ) );
177  }
178  catch( Exception $e )
179  {
180  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
181  }
182  }
183 
206  function get_by_id( $id )
207  {
208  try
209  {
210  $id = $this->Security->get( $id , 'integer' );
211 
212  $Records = $this->FileInputAccess->unsafe_select( "id = $id" );
213 
214  if( count( $Records ) !== 1 )
215  {
216  throw( new Exception( 'An error occured while record fetching' ) );
217  }
218  else
219  {
220  return( $Records[ 0 ] );
221  }
222  }
223  catch( Exception $e )
224  {
225  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
226  }
227  }
228  }
229 ?>