ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

gallery_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 gallery_markup_1_0_0{
27
38 var $CachedMultyFS = false;
39 var $GalleryAccess = false;
40 var $GalleryAlgorithms = false;
41 var $Link = false;
42 var $String = false;
43
58 function __construct()
59 {
60 try
61 {
62 $this->CachedMultyFS = get_package_object( 'cached_multy_fs' , 'last' , __FILE__ );
63 $this->GalleryAccess = get_package( 'gallery::gallery_access' , 'last' , __FILE__ );
64 $this->GalleryAlgorithms = get_package( 'gallery::gallery_algorithms' , 'last' , __FILE__ );
65 $this->Link = get_package( 'link' , 'last' , __FILE__ );
66 $this->String = get_package( 'string' , 'last' , __FILE__ );
67 }
68 catch( Exception $e )
69 {
70 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
71 }
72 }
73
100 private function create_dependent_gallery( $MasterType , $MasterId )
101 {
102 try
103 {
104 $Gallery = array(
105 'title' => "gallery for $MasterType|id=$MasterId" ,
106 'description' => "description for $MasterType|id=$MasterId"
107 );
108
109 $id = $this->GalleryAccess->create( $Gallery );
110
111 $this->Link->create_link( $MasterId , $id , $MasterType , 'gallery' );
112
113 return( $id );
114 }
115 catch( Exception $e )
116 {
117 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
118 }
119 }
120
143 function get_dependent_gallery_id( &$BlockSettings )
144 {
145 try
146 {
147 $MasterType = $BlockSettings->get_setting( 'master_type' );
148 $MasterId = $BlockSettings->get_setting( 'master_id' );
149
150 if( $this->Link->link_exists( $MasterId , false , $MasterType , 'gallery' ) )
151 {
152 $Link = $this->Link->get_links( $MasterId , false , $MasterType , 'gallery' );
153
154 return( get_field( $Link[ 0 ] , 'object2_id' ) );
155 }
156 else
157 {
158 return( $this->create_dependent_gallery( $MasterType , $MasterId ) );
159 }
160 }
161 catch( Exception $e )
162 {
163 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
164 }
165 }
166
189 function get_gallery( &$BlockSettings )
190 {
191 try
192 {
193 if( $BlockSettings->get_setting( 'master_id' , false ) === false )
194 {
195 $id = $BlockSettings->get_setting( 'id' );
196 }
197 else
198 {
199 $id = $this->get_dependent_gallery_id( $BlockSettings );
200 }
201
202 return( $this->GalleryAlgorithms->get_by_id( $id ) );
203 }
204 catch( Exception $e )
205 {
206 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
207 }
208 }
209
236 function get_galery_template_for_client( $FilePath , $GalleryId )
237 {
238 try
239 {
240 $GalleryTemplate = $this->CachedMultyFS->file_get_contents( $FilePath );
241 $GalleryTemplate = str_replace( '{gallery_id}' , $GalleryId , $GalleryTemplate );
242 $GalleryTemplate = str_replace( '{id}' , '[id]' , $GalleryTemplate );
243 $GalleryTemplate = str_replace( '{file_path}' , '[file_path]' , $GalleryTemplate );
244 $GalleryTemplate = str_replace( '{original_file_name}' , '[original_file_name]' , $GalleryTemplate );
245 $GalleryTemplate = str_replace( '{' , '[lfb]' , $GalleryTemplate );
246 $GalleryTemplate = str_replace( '}' , '[rfb]' , $GalleryTemplate );
247
248 return( $GalleryTemplate );
249 }
250 catch( Exception $e )
251 {
252 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
253 }
254 }
255
282 private function compile_gallery_parts( $Gallery , $Files )
283 {
284 try
285 {
286 $Code = '';
287 $FilePath = dirname( __FILE__ ).'/res/templates/simple_file_list.tpl';
288 $id = get_field( $Gallery , 'id' );
289 foreach( $Files as $i => $File )
290 {
291 $Code .= $this->CachedMultyFS->file_get_contents( $FilePath );
292 $Code = $this->String->print_record( $Code , $File );
293 }
294 $Code = str_replace( '{gallery_id}' , $id , $Code );
295
296 $Input = "{file_input:file_types=images;upload_url=gallery_upload.html?gallery_id[eq]{gallery_id};";
297 $Input .= "upload_success_handler=ultimix_file_input_view_after_image_upload_processor}";
298 return( array( $Code , str_replace( '{gallery_id}' , $id , $Input ) ) );
299 }
300 catch( Exception $e )
301 {
302 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
303 }
304 }
305
332 private function compile_gallery_files( $Gallery , $Files )
333 {
334 try
335 {
336 list( $Code , $Input ) = $this->compile_gallery_parts( $Gallery , $Files );
337
338 $Template = $this->get_galery_template_for_client( $FilePath , $GalleryId );
339
340 $Gallery = $this->CachedMultyFS->get_teplate( __FILE__ , 'gallery.tpl' );
341 $PlaceHolders = array( '{code}' , '{gallery_template}' , '{input}' );
342 $Gallery = str_replace( $PlaceHolders , array( $Code , $Template , $Input ) , $Gallery );
343 $Gallery = str_replace( '{gallery_id}' , $GalleryId , $Gallery );
344
345 return( $Template );
346 }
347 catch( Exception $e )
348 {
349 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
350 }
351 }
352
375 function compile_gallery( &$Settings )
376 {
377 try
378 {
379 $Gallery = $this->get_gallery( $Settings );
380
381 $Files = $this->GalleryAlgorithms->get_gallery_files( get_field( $Gallery , 'id' ) );
382
383 $Code = $this->compile_gallery_files( $Gallery , $Files );
384
385 return( $Code );
386 }
387 catch( Exception $e )
388 {
389 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
390 }
391 }
392 }
393 ?>