Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmediacatalogue/admin/medialist.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: medialist.php 8182 2001-11-01 17:17:57Z ce $
5 //
6 // Created on: <24-Jul-2001 11:36:48 ce>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezlog.php" );
30 // include_once( "classes/ezfile.php" );
31 // include_once( "classes/ezlist.php" );
32
33 // include_once( "ezuser/classes/ezuser.php" );
34 // include_once( "ezuser/classes/ezpermission.php" );
35 // include_once( "ezuser/classes/ezobjectpermission.php" );
36
37 // // include_once( "ezmediacatalogue/classes/ezmedia.php" );
38 // include_once( "ezmediacatalogue/classes/ezmediacategory.php" );
39 // include_once( "classes/ezhttptool.php" );
40
41 $ini =& eZINI::instance( 'site.ini' );
42
43 $Language = $ini->variable( "eZMediaCatalogueMain", "Language" );
44 $SyncDir = $ini->variable( "eZMediaCatalogueMain", "SyncDir" );
45 $ImageDir = $ini->variable( "eZMediaCatalogueMain", "ImageDir" );
46
47 $t = new eZTemplate( "kernel/ezmediacatalogue/admin/" . $ini->variable( "eZMediaCatalogueMain", "TemplateDir" ),
48 "kernel/ezmediacatalogue/admin/intl/", $Language, "medialist.php" );
49
50 $t->set_file( "media_list_page_tpl", "medialist.tpl" );
51
52 $t->setAllStrings();
53
54 $user =& eZUser::currentUser();
55
56 $t->set_block( "media_list_page_tpl", "current_category_tpl", "current_category" );
57
58 // path
59 $t->set_block( "media_list_page_tpl", "path_item_tpl", "path_item" );
60
61 $t->set_block( "media_list_page_tpl", "media_list_tpl", "media_list" );
62
63 $t->set_block( "media_list_page_tpl", "write_menu_tpl", "write_menu" );
64
65 $t->set_block( "write_menu_tpl", "default_new_tpl", "default_new" );
66 $t->set_block( "write_menu_tpl", "default_delete_tpl", "default_delete" );
67
68 $t->set_block( "default_delete_tpl", "delete_categories_button_tpl", "delete_categories_button" );
69 $t->set_block( "default_delete_tpl", "delete_media_button_tpl", "delete_media_button" );
70
71 $t->set_block( "media_list_tpl", "media_tpl", "media" );
72
73 $t->set_block( "media_tpl", "read_tpl", "read" );
74 $t->set_block( "media_tpl", "write_tpl", "write" );
75
76 $t->set_block( "media_list_page_tpl", "category_list_tpl", "category_list" );
77 $t->set_block( "category_list_tpl", "category_tpl", "category" );
78
79 $t->set_block( "category_tpl", "category_write_tpl", "category_write" );
80 $t->set_block( "category_tpl", "category_read_tpl", "category_read" );
81
82 $t->set_var( "read", "" );
83 $t->set_var( "write_menu", "" );
84
85 $t->set_var( "delete_media_button" , "" );
86 $t->set_var( "delete_categories_button" , "" );
87 $t->set_var( "default_new" , "" );
88 $t->set_var( "default_delete" , "" );
89
90 $t->set_var( "site_style", $siteDesign );
91
92 $category = new eZMediaCategory( $CategoryID );
93
94 // Check if user have permission to the current category
95
96 $error = true;
97
98 if( !isset( $Offset ) )
99 $Offset = false;
100
101 if ( eZObjectPermission::hasPermission( $category->id(), "mediacatalogue_category", "r", $user )
102 || eZMediaCategory::isOwner( $user, $CategoryID ) )
103 {
104 $error = false;
105 }
106
107 if ( $CategoryID == 0 )
108 {
109 $t->set_var( "current_category_description", "" );
110 $error = false;
111 }
112
113 $t->set_var( "current_category", "" );
114
115 if ( $category->id() != 0 )
116 {
117 $t->set_var( "current_category_description", $category->description() );
118 $t->set_var( "category_id", $category->id() );
119 $t->set_var( "category_name", $category->name() );
120
121 $t->parse( "current_category", "current_category_tpl" );
122 }
123
124 // path
125 $pathArray = $category->path();
126
127 $t->set_var( "path_item", "" );
128 foreach ( $pathArray as $path )
129 {
130 $t->set_var( "category_id", $path[0] );
131
132 $t->set_var( "category_name", $path[1] );
133
134 $t->parse( "path_item", "path_item_tpl", true );
135 }
136
137
138 // ###################################################
139 function syncDir( $root, $category )
140 {
141 global $user;
142 $dir = eZPBFile::dir( $root, false );
143 while ( $entry = $dir->read() )
144 {
145 if ( $entry != "." && $entry != ".." )
146 {
147 if ( filetype( $root . $entry ) == "dir" )
148 {
149 // check if category exists if not create it:
150 $subCategoryArray =& $category->getByParent( $category );
151 $sub = false;
152 foreach ( $subCategoryArray as $subCategory )
153 {
154 if ( $subCategory->name() == $entry )
155 {
156 $sub = $subCategory;
157 }
158 //print( $subCategory->name() . "\n<br>" );
159 }
160 if ( $sub == false )
161 {
162 $sub = new eZMediaCategory( );
163 $sub->setParent( $category );
164 $sub->setName( $entry );
165 $sub->setSectionID( $SectionID );
166 $sub->store();
167 eZObjectPermission::removePermissions( $sub->id(), "mediacatalogue_category", "r" );
168 eZObjectPermission::removePermissions( $sub->id(), "mediacatalogue_category", "w" );
169 eZObjectPermission::removePermissions( $sub->id(), "mediacatalogue_category", "u" );
170 $group = new eZUserGroup( -1 );
171 eZObjectPermission::setPermission( -1, $sub->id(), "mediacatalogue_category", "r" );
172 eZObjectPermission::setPermission( 1, $sub->id(), "mediacatalogue_category", "w" );
173 eZObjectPermission::setPermission( 1, $sub->id(), "mediacatalogue_category", "u" );
174 }
175 //print( "Syncing dir " . $root . $entry . "<br>" );
176 syncDir( $root . $entry . "/", $sub );
177 }
178 else if ( filetype( $root . $entry ) == "file" )
179 {
180 $medias = $category->medias( "time", 0, -1, false, $user );
181 $mediaExists = false;
182 foreach ( $medias as $media )
183 {
184 if ( $entry == $media->name() )
185 {
186 $mediaExists = true;
187 }
188 }
189 if ( $mediaExists == false )
190 {
191 $media = new eZMedia();
192 $media->setName( $entry );
193 $media->setDescription( $Description );
194 $media->setUser( $user );
195 $author = new eZAuthor( 1 );
196 $media->setPhotographer( $author );
197 //print( "adding media: " . $root . $entry . "<br>" );
198 $file = new eZMediaFile();
199 $file->getFile( $root . $entry );
200 $media->store();
201 $media->setMedia( $file, $media->id() );
202 $media->setCategoryDefinition( $category );
203 eZMediaCategory::addMedia( $media, $category->id() );
204 $media->setOriginalFileName( $entry );
205 $media->store();
206 eZObjectPermission::removePermissions( $media->id(), "mediacatalogue_media", "r" );
207 eZObjectPermission::removePermissions( $media->id(), "mediacatalogue_media", "w" );
208 eZObjectPermission::setPermission( -1, $media->id(), "mediacatalogue_media", "r" );
209 eZObjectPermission::setPermission( 1, $media->id(), "mediacatalogue_media", "w" );
210 }
211 }
212 }
213 }
214 }
215
216
217 if ( isSet ( $MediaUpload ) )
218 {
219 $category = new eZMediaCategory( $PicCat );
220 syncDir( $SyncMediaDir, $category );
221 eZHTTPTool::header( "Location: /mediacatalogue/media/list/$PicCat/" );
222 exit();
223 }
224 else
225 {
226 $SyncMediaDir = $SyncDir;
227 }
228
229 $t->set_var( "sync_dir", $SyncMediaDir );
230
231 // ###################################################
232
233 // Print out all the categories
234 $categoryList =& $category->getByParent( $category );
235
236 $i=0;
237 foreach ( $categoryList as $categoryItem )
238 {
239 $t->set_var( "category_name", $categoryItem->name() );
240 $t->set_var( "category_id", $categoryItem->id() );
241 $t->set_var( "category_description", $categoryItem->description() );
242
243 $t->set_var( "category_read", "" );
244 $t->set_var( "category_write", "" );
245 ( $i % 2 ) ? $t->set_var( "td_class", "bgdark" ) : $t->set_var( "td_class", "bglight" );
246
247 // Check if user have read permission
248 if ( eZObjectPermission::hasPermission( $categoryItem->id(), "mediacatalogue_category", "r", $user ) ||
249 eZMediaCategory::isOwner( $user, $categoryItem->id()) )
250 {
251 $t->parse( "category_read", "category_read_tpl" );
252 }
253
254 // Check if user have write permission
255 if ( ( $user ) &&
256 ( eZObjectPermission::hasPermission( $categoryItem->id(), "mediacatalogue_category", "w", $user ) ) ||
257 ( eZMediaCategory::isOwner( $user, $categoryItem->id() ) ) )
258 {
259 $t->parse( "category_write", "category_write_tpl" );
260 $t->parse( "delete_categories_button", "delete_categories_button_tpl" );
261 $t->parse( "default_delete", "default_delete_tpl" );
262
263 if ( $CategoryID == 0 )
264 {
265 if ( eZPermission::checkPermission( $user, "eZMediaCatalogue", "WriteToRoot" ) )
266 {
267 $t->parse( "category_write", "category_write_tpl" );
268 $t->parse( "write_menu", "write_menu_tpl" );
269 }
270 }
271 else
272 {
273 $t->parse( "category_write", "category_write_tpl" );
274 $t->parse( "write_menu", "write_menu_tpl" );
275 }
276 }
277
278 $t->parse( "category", "category_tpl", true );
279 $i++;
280 }
281
282 if ( count( $categoryList ) > 0 )
283 {
284 $t->parse( "category_list", "category_list_tpl" );
285 }
286 else
287 {
288 $t->set_var( "category_list", "" );
289 }
290
291 $limit = $ini->variable( "eZMediaCatalogueMain", "ListMediaPerPage" );
292
293 // Print out all the media
294 $mediaList =& $category->media( "time", $Offset, $limit );
295
296 $i = 0;
297 $j = 0;
298 $counter = 0;
299 foreach ( $mediaList as $media )
300 {
301 $t->set_var( "media_id", $media->id() );
302 $t->set_var( "original_media_name", $media->originalFileName() );
303 $t->set_var( "media_name", $media->name() );
304 $t->set_var( "media_caption", $media->name() );
305 $t->set_var( "media_url", $media->name() );
306
307 $t->set_var( "media_description",$media->description() );
308 $t->set_var( "media_alt", $media->name() );
309 $t->set_var( "media_src", "/" . $media->mediaPath() );
310 $t->set_var( "media_file_name", $media->originalFileName() );
311
312 if ( ( $counter % 2 ) == 0 )
313 {
314 $t->set_var( "td_class", "bglight" );
315 }
316 else
317 {
318 $t->set_var( "td_class", "bgdark" );
319 }
320
321 if ( $media->fileExists( true ) )
322 {
323 $mediaPath =& $media->filePath( true );
324 $size = eZPBFile::filesize( $mediaPath );
325 }
326 else
327 {
328 $size = 0;
329 }
330
331 $size = eZPBFile::siFileSize( $size );
332
333 $t->set_var( "media_size", $size["size-string"] );
334 $t->set_var( "media_unit", $size["unit"] );
335 $t->set_var( "media_caption", $media->caption() );
336 $t->set_var( "media_uri", $media->mediaPath( false ) );
337
338 $t->set_var( "read", "" );
339 $t->set_var( "write", "" );
340
341 // Check if user have read permission
342 $can_read = false;
343 $can_write = false;
344 if ( eZObjectPermission::hasPermission( $media->id(), "mediacatalogue_media", "r", $user ) ||
345 eZMedia::isOwner( $user, $media->id() ) )
346 {
347 $can_read = true;
348 $t->parse( "read", "read_tpl" );
349 $j++;
350 }
351
352 // Check if user have write permission
353 if ( ( $user ) &&
354 ( eZObjectPermission::hasPermission( $media->id(), "mediacatalogue_media", "w", $user ) ) ||
355 ( eZMedia::isOwner( $user, $media->id() ) ) )
356 {
357 $can_write = true;
358 $t->parse( "write", "write_tpl" );
359 $t->parse( "delete_media_button", "delete_media_button_tpl" );
360 }
361
362 if ( $can_read )
363 $t->parse( "media", "media_tpl", true );
364
365 $counter++;
366 }
367
368 eZList::drawNavigator( $t, $category->mediaCount(), $limit, $Offset, "media_list_page_tpl" );
369
370 if ( isset( $can_write ) && $can_write )
371 {
372 $t->parse( "delete_media_button", "delete_media_button_tpl" );
373 $t->parse( "default_delete", "default_delete_tpl" );
374 }
375
376
377 // Print out the category/media menu
378 if ( $category->id() != 0 )
379 {
380 if ( ( $user ) &&
381 ( eZObjectPermission::hasPermission( $category->id(), "mediacatalogue_category", "w", $user ) ) )
382 {
383 $t->parse( "default_new", "default_new_tpl" );
384 $t->parse( "write_menu", "write_menu_tpl" );
385 }
386 }
387 else
388 {
389 if ( eZPermission::checkPermission( $user, "eZMediaCatalogue", "WriteToRoot" ) )
390 {
391 $t->parse( "default_new", "default_new_tpl" );
392 $t->parse( "write_menu", "write_menu_tpl" );
393 }
394 }
395
396 if ( count( $mediaList ) > 0 )
397 {
398 $t->parse( "media_list", "media_list_tpl" );
399 }
400 else
401 {
402 $t->set_var( "media_list", "" );
403 }
404
405 $t->set_var( "media_dir", $ImageDir );
406
407 $t->set_var( "main_category_id", $CategoryID );
408
409 if ( $error == false )
410 {
411 $t->pparse( "output", "media_list_page_tpl" );
412 }
413 else
414 {
415 eZHTTPTool::header( "Location: /error/403/" );
416 exit();
417 }
418
419 ?>
$CategoryID
$CategoryID
Definition: admin/articleedit.php:53
$group
$group
Definition: admin/articleedit.php:799
$author
$author
Definition: admin/articleedit.php:834
$Description
$Description
Definition: articlelistrss.php:38
eZAuthor
Definition: ezauthor.php:40
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZList\drawNavigator
static drawNavigator(&$t, $total_types, $max_types, $index, $parent=false, $variables=false)
Definition: ezlist.php:401
eZMediaCategory
Definition: ezmediacategory.php:55
eZMediaCategory\addMedia
addMedia(&$value, $categoryid=false)
Definition: ezmediacategory.php:504
eZMediaCategory\isOwner
isOwner(&$user, &$mediacategory)
Definition: ezmediacategory.php:444
eZMediaFile
Definition: ezmediafile.php:68
eZMedia
Definition: ezmedia.php:65
eZMedia\isOwner
static isOwner(&$user, &$media)
Definition: ezmedia.php:604
eZObjectPermission\hasPermission
static hasPermission( $objectID, $moduleTable, $permission, $user=false)
Definition: ezobjectpermission.php:76
eZObjectPermission\setPermission
static setPermission( $group, $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:236
eZObjectPermission\removePermissions
static removePermissions( $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:320
eZPBFile\siFileSize
static & siFileSize( $size)
Definition: ezpbfile.php:220
eZPBFile\dir
static dir( $dir, $add_sitedir=true)
Definition: ezpbfile.php:384
eZPBFile\filesize
static filesize( $filename)
Definition: ezpbfile.php:339
eZPermission\checkPermission
static checkPermission( $user, $moduleName, $permissionName)
Definition: ezpermission.php:430
eZTemplate
Definition: eztemplate.php:107
eZUserGroup
Definition: ezusergroup.php:66
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$media
if(isset( $AddMedia)) $media
Definition: ezarticle/admin/medialist.php:76
$Offset
$Offset
Definition: ezarticle/user/search.php:110
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$SectionID
$SectionID
Definition: ezfilemanager/user/filelist.php:46
$PicCat
$PicCat
Definition: ezimagecatalogue/admin/imagelist.php:48
syncDir
foreach( $pathArray as $path) syncDir( $root, $category)
Definition: ezmediacatalogue/admin/medialist.php:139
$category
$category
Definition: ezmediacatalogue/admin/medialist.php:92
$SyncDir
$SyncDir
Definition: ezmediacatalogue/admin/medialist.php:44
$ImageDir
$ImageDir
Definition: ezmediacatalogue/admin/medialist.php:45
$t
$t
Definition: ezmediacatalogue/admin/medialist.php:47
$pathArray
if( $category->id() !=0) $pathArray
Definition: ezmediacatalogue/admin/medialist.php:125
$user
$user
Definition: ezmediacatalogue/admin/medialist.php:54
$j
$j
Definition: ezmediacatalogue/admin/medialist.php:297
$i
$i
Definition: ezmediacatalogue/admin/medialist.php:236
$Language
$Language
Definition: ezmediacatalogue/admin/medialist.php:43
$ini
$ini
Definition: ezmediacatalogue/admin/medialist.php:41
$mediaList
$mediaList
Definition: ezmediacatalogue/admin/medialist.php:294
$categoryList
$categoryList
Definition: ezmediacatalogue/admin/medialist.php:234
$counter
$counter
Definition: ezmediacatalogue/admin/medialist.php:298
$limit
$limit
Definition: ezmediacatalogue/admin/medialist.php:291
$error
$error
Definition: ezmediacatalogue/admin/medialist.php:96
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
exit
exit
Definition: folder.php:81
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.