| [ Index ] |
|
Code source de Dotclear 2.0-beta6 |
1 <?php 2 # ***** BEGIN LICENSE BLOCK ***** 3 # This file is part of DotClear. 4 # Copyright (c) 2005 Olivier Meunier and contributors. All rights 5 # reserved. 6 # 7 # DotClear is free software; you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation; either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # DotClear is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with DotClear; if not, write to the Free Software 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # 21 # ***** END LICENSE BLOCK ***** 22 23 require dirname(__FILE__).'/../inc/admin/prepend.php'; 24 25 dcPage::check('media,media_admin'); 26 27 $post_id = !empty($_GET['post_id']) ? (integer) $_GET['post_id'] : null; 28 if ($post_id) { 29 $post = $core->blog->getPosts(array('post_id'=>$post_id)); 30 if ($post->isEmpty()) { 31 $post_id = null; 32 } 33 $post_title = $post->post_title; 34 unset($post); 35 } 36 37 $d = isset($_REQUEST['d']) ? $_REQUEST['d'] : null; 38 $dir = null; 39 $upfile = array(); 40 41 $page = !empty($_GET['page']) ? $_GET['page'] : 1; 42 $nb_per_page = 30; 43 44 # We are on home not comming from media manager 45 if ($d === null && isset($_SESSION['media_manager_dir'])) { 46 # We get session information 47 $d = $_SESSION['media_manager_dir']; 48 } 49 50 if (!isset($_GET['page']) && isset($_SESSION['media_manager_page'])) { 51 $page = $_SESSION['media_manager_page']; 52 } 53 54 # We set session information about directory and page 55 if ($d) { 56 $_SESSION['media_manager_dir'] = $d; 57 } else { 58 unset($_SESSION['media_manager_dir']); 59 } 60 if ($page != 1) { 61 $_SESSION['media_manager_page'] = $page; 62 } else { 63 unset($_SESSION['media_manager_page']); 64 } 65 66 $type = !empty($_GET['type']) ? $_GET['type'] : ''; 67 $popup = (integer) !empty($_GET['popup']); 68 69 $page_url = 'media.php?type='.rawurlencode($type).'&popup='.$popup.'&post_id='.$post_id; 70 71 if ($popup) { 72 $open_f = array('dcPage','openPopup'); 73 $close_f = array('dcPage','closePopup'); 74 } else { 75 $open_f = array('dcPage','open'); 76 $close_f = array('dcPage','close'); 77 } 78 79 try { 80 $core->media = new dcMedia($core,$type); 81 $core->media->chdir($d); 82 $core->media->getDir(); 83 $dir =& $core->media->dir; 84 } catch (Exception $e) { 85 $core->error->add($e->getMessage()); 86 } 87 88 # New directory 89 if ($dir && !empty($_POST['newdir'])) 90 { 91 try { 92 $core->media->makeDir($_POST['newdir']); 93 http::redirect($page_url.'&d='.$d.'&mkdok=1'); 94 } catch (Exception $e) { 95 $core->error->add($e->getMessage()); 96 } 97 } 98 99 # Adding a file 100 if ($dir && !empty($_FILES['upfile'])) 101 { 102 for ($i=0; $i<count($_FILES['upfile']['name']); $i++) 103 { 104 $upfile[] = array( 105 'name' => $_FILES['upfile']['name'][$i], 106 'type' => $_FILES['upfile']['name'][$i], 107 'tmp_name' => $_FILES['upfile']['tmp_name'][$i], 108 'error' => $_FILES['upfile']['error'][$i], 109 'size' => $_FILES['upfile']['size'][$i], 110 'title' => (isset($_POST['upfiletitle'][$i]) ? $_POST['upfiletitle'][$i] : ''), 111 'private' => (isset($_POST['upfilepriv'][$i]) ? $_POST['upfilepriv'][$i] : false) 112 ); 113 } 114 115 foreach ($upfile as $f) 116 { 117 try { 118 files::uploadStatus($f); 119 $core->media->uploadFile($f['tmp_name'],$f['name'],$f['title'],$f['private']); 120 } catch (Exception $e) { 121 $core->error->add($e->getMessage()); 122 break; 123 } 124 } 125 126 if (!$core->error->flag()) { 127 http::redirect($page_url.'&d='.$d.'&upok=1'); 128 } 129 } 130 131 132 # Removing item 133 if ($dir && !empty($_POST['rmyes']) && !empty($_POST['remove'])) 134 { 135 $_POST['remove'] = rawurldecode($_POST['remove']); 136 137 try { 138 $core->media->removeItem($_POST['remove']); 139 http::redirect($page_url.'&d='.$d.'&rmfok=1'); 140 } catch (Exception $e) { 141 $core->error->add($e->getMessage()); 142 } 143 } 144 145 # Rebuild directory 146 if ($dir && $core->auth->isSuperAdmin() && !empty($_POST['rebuild'])) 147 { 148 try { 149 $core->media->rebuild($d); 150 http::redirect($page_url.'&d='.$d.'&rebuildok=1'); 151 } catch (Exception $e) { 152 $core->error->add($e->getMessage()); 153 } 154 } 155 156 157 # DSIPLAY confirm page for rmdir & rmfile 158 if ($dir && !empty($_GET['remove'])) 159 { 160 call_user_func($open_f,__('Media manager')); 161 162 echo '<h2>'.__('Media manager').' > '.__('confirm removal').'</h2>'; 163 164 echo 165 '<form action="'.html::escapeURL($page_url).'" method="post">'. 166 '<p>'.sprintf(__('Are you sure you want to remove %s?'), 167 html::escapeHTML($_GET['remove'])).'</p>'. 168 '<p><input type="submit" value="'.__('cancel').'" /> '. 169 ' <input type="submit" name="rmyes" value="'.__('yes').'" />'. 170 form::hidden('d',$d). 171 form::hidden('remove',html::escapeHTML($_GET['remove'])).'</p>'. 172 '</form>'; 173 174 call_user_func($close_f); 175 exit; 176 } 177 178 /* DISPLAY Main page 179 -------------------------------------------------------- */ 180 call_user_func($open_f,__('Media manager'),dcPage::jsLoad('js/_media.js')); 181 182 if (!empty($_GET['mkdok'])) { 183 echo '<p class="message">'.__('Directory has been successfully created.').'</p>'; 184 } 185 186 if (!empty($_GET['upok'])) { 187 echo '<p class="message">'.__('Files have been successfully uploaded.').'</p>'; 188 } 189 190 if (!empty($_GET['rmfok'])) { 191 echo '<p class="message">'.__('File has been successfully removed.').'</p>'; 192 } 193 194 if (!empty($_GET['rmdok'])) { 195 echo '<p class="message">'.__('Directory has been successfully removed.').'</p>'; 196 } 197 198 if (!empty($_GET['rebuildok'])) { 199 echo '<p class="message">'.__('Directory has been successfully rebuilt.').'</p>'; 200 } 201 202 if (!$dir) { 203 call_user_func($close_f); 204 exit; 205 } 206 207 echo '<h2><a href="'.html::escapeURL($page_url.'&d=').'">'.__('Media manager').'</a>'. 208 ' / '.$core->media->breadCrum(html::escapeURL($page_url).'&d=%s').'</h2>'; 209 210 if ($post_id) { 211 echo '<p><strong>'.sprintf(__('Choose a file to attach to entry %s by clicking on %s.'), 212 '<a href="post.php?id='.$post_id.'">'.$post_title.'</a>', 213 '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />').'</strong></p>'; 214 } 215 if ($popup) { 216 echo '<p><strong>'.sprintf(__('Choose a file to insert into entry by clicking on %s.'), 217 '<img src="images/plus.png" alt="'.__('Attach this file to entry').'" />').'</strong></p>'; 218 } 219 220 221 $items = array_values(array_merge($dir['dirs'],$dir['files'])); 222 if (count($items) == 0) 223 { 224 echo '<p><strong>'.__('No file.').'</strong></p>'; 225 } 226 else 227 { 228 $pager = new pager($page,count($items),$nb_per_page,10); 229 230 echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 231 232 echo '<div class="media-list">'; 233 for ($i=$pager->index_start, $j=0; $i<=$pager->index_end; $i++, $j++) 234 { 235 echo mediaItemLine($items[$i],$j); 236 } 237 echo '</div>'; 238 239 echo '<p class="clear">'.__('Page(s)').' : '.$pager->getLinks().'</p>'; 240 } 241 242 if (is_writable($core->media->root)) 243 { 244 echo 245 '<h3 id="add-file">'.__('Add files').dcPage::help('media','m_newfile').'</h3>'. 246 '<form class="clear" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data">'. 247 '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'. 248 '<fieldset id="add-file-f">'. 249 '<div>'. 250 '<p><label>'.__('Choose a file:'). 251 ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).')'. 252 dcPage::help('media','m_file'). 253 '<input type="file" name="upfile[]" size="35" />'. 254 '</label></p>'. 255 '<p class="form-note">'.__('Please take care to publish media that you own and that are not protected by copyright.').'</p>'. 256 '<p><label>'.__('Title:').dcPage::help('media','m_title'). 257 form::field(array('upfiletitle[]'),35,255).'</label></p>'. 258 '<p><label class="classic">'.form::checkbox(array('upfilepriv[]'),1).' '. 259 __('Private').dcPage::help('media','m_private').'</label></p>'. 260 '</div>'. 261 '<p><input type="submit" value="'.__('send').'" />'. 262 form::hidden(array('d'),$d).'</p>'. 263 '</fieldset>'. 264 '</form>'; 265 266 echo 267 '<h3 id="new-dir">'.__('New directory').dcPage::help('media','m_newdir').'</h3>'. 268 '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'. 269 '<fieldset id="new-dir-f">'. 270 '<p><label>'.__('Name:'). 271 form::field(array('newdir'),35,255).'</label></p>'. 272 '<p><input type="submit" value="'.__('save').'" />'. 273 form::hidden(array('d'),html::escapeHTML($d)).'</p>'. 274 '</fieldset>'. 275 '</form>'; 276 } 277 278 # Empty remove form (for javascript actions) 279 echo 280 '<form id="media-remove-hide" action="'.html::escapeURL($page_url).'" method="post"><div>'. 281 form::hidden('rmyes',1).form::hidden('d',html::escapeHTML($d)). 282 form::hidden('remove',''). 283 '</div></form>'; 284 285 call_user_func($close_f); 286 287 /* ----------------------------------------------------- */ 288 function mediaItemLine($f,$i) 289 { 290 global $page_url, $type, $popup, $post_id; 291 292 $fname = $f->basename; 293 294 if ($f->d) { 295 $link = html::escapeURL($page_url).'&d='.html::sanitizeURL($f->relname); 296 if ($f->parent) { 297 $fname = '..'; 298 } 299 } else { 300 $link = 301 'media_item.php?type='.rawurlencode($type). 302 '&id='.$f->media_id.'&popup='.$popup.'&post_id='.$post_id; 303 } 304 305 $class = 'media-item media-col-'.($i%2); 306 307 $res = 308 '<div class="'.$class.'"><a class="media-icon media-link" href="'.$link.'">'. 309 '<img src="'.$f->media_icon.'" alt="" /></a>'. 310 '<ul>'. 311 '<li><a class="media-link" href="'.$link.'">'.$fname.'</a></li>'; 312 313 if (!$f->d) { 314 $res .= 315 '<li>'.$f->media_title.'</li>'. 316 '<li>'. 317 $f->media_dtstr.' - '. 318 files::size($f->size).' - '. 319 '<a href="'.$f->file_url.'">'.__('open').'</a>'. 320 '</li>'; 321 } 322 323 $res .= '<li class="media-action"> '; 324 325 if ($post_id && !$f->d) { 326 $res .= '<form action="post_media.php" method="post">'. 327 '<input type="image" src="images/plus.png" alt="'.__('Attach this file to entry').'" '. 328 'title="'.__('Attach this file to entry').'" /> '. 329 form::hidden('media_id',$f->media_id). 330 form::hidden('post_id',$post_id). 331 form::hidden('attach',1). 332 '</form>'; 333 } 334 335 if ($popup && !$f->d) { 336 $res .= '<a href="'.$link.'"><img src="images/plus.png" alt="'.__('Insert this file into entry').'" '. 337 'title="'.__('Insert this file into entry').'" /></a> '; 338 } 339 340 if ($f->del) { 341 $res .= '<a class="media-remove" '. 342 'href="'.html::escapeURL($page_url).'&d='. 343 rawurlencode($GLOBALS['d']).'&remove='.rawurlencode($f->basename).'">'. 344 '<img src="images/trash.png" alt="'.__('delete').'" title="'.__('delete').'" /></a>'; 345 } 346 347 $res .= '</li>'; 348 349 if ($f->type == 'audio/mpeg3') { 350 $res .= '<li>'.$GLOBALS['core']->media->mp3player($f->file_url).'</li>'; 351 } 352 353 $res .= '</ul></div>'; 354 355 return $res; 356 } 357 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Feb 23 22:16:06 2007 | par Balluche grâce à PHPXref 0.7 |