[ Index ]
 

Code source de Dotclear 2.0-beta6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/admin/ -> media_item.php (source)

   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  $file = null;
  38  $type = !empty($_GET['type']) ? rawurlencode($_GET['type']) : '';
  39  $popup = (integer) !empty($_GET['popup']);
  40  $page_url = 'media_item.php?type='.rawurlencode($type).'&popup='.$popup.'&post_id='.$post_id;
  41  $media_page_url = 'media.php?type='.rawurlencode($type).'&popup='.$popup.'&post_id='.$post_id;
  42  
  43  $id = !empty($_REQUEST['id']) ? (integer) $_REQUEST['id'] : '';
  44  
  45  if ($popup) {
  46      $open_f = array('dcPage','openPopup');
  47      $close_f = array('dcPage','closePopup');
  48  } else {
  49      $open_f = array('dcPage','open');
  50      $close_f = array('dcPage','close');
  51  }
  52  
  53  try
  54  {
  55      $core->media = new dcMedia($core,$type);
  56      
  57      if ($id) {
  58          $file = $core->media->getFile($id);
  59      }
  60      
  61      if ($file === null) {
  62          throw new Exception(__('Not a valid file'));
  63      }
  64      
  65      $core->media->chdir(dirname($file->relname));
  66      
  67      # Prepare directories combo box
  68      $dirs_combo = array();
  69      foreach ($core->media->getRootDirs() as $v) {
  70          if ($v->w) {
  71              $dirs_combo['/'.$v->relname] = $v->relname;
  72          }
  73      }
  74  }
  75  catch (Exception $e)
  76  {
  77      $core->error->add($e->getMessage());
  78  }
  79  
  80  # Upload a new file
  81  if ($file && !empty($_FILES['upfile']) && $file->editable)
  82  {
  83      try {
  84          files::uploadStatus($_FILES['upfile']);
  85          $core->media->uploadFile($_FILES['upfile']['tmp_name'],$file->basename);
  86          http::redirect($page_url.'&id='.$id.'&fupl=1');
  87      } catch (Exception $e) {
  88          $core->error->add($e->getMessage());
  89      }
  90  }
  91  
  92  # Update file
  93  if ($file && !empty($_POST['media_file']) && $file->editable)
  94  {
  95      $newFile = clone $file;
  96      
  97      $newFile->basename = $_POST['media_file'];
  98      
  99      if ($_POST['media_path']) {
 100          $newFile->dir = $_POST['media_path'];
 101          $newFile->relname = $_POST['media_path'].'/'.$newFile->basename;
 102      } else {
 103          $newFile->dir = '';
 104          $newFile->relname = $newFile->basename;
 105      }
 106      $newFile->media_title = $_POST['media_title'];
 107      $newFile->media_dt = strtotime($_POST['media_dt']);
 108      $newFile->media_dtstr = $_POST['media_dt'];
 109      $newFile->media_priv = !empty($_POST['media_private']);
 110      
 111      try {
 112          $core->media->updateFile($file,$newFile);
 113          http::redirect($page_url.'&id='.$id.'&fupd=1');
 114      } catch (Exception $e) {
 115          $core->error->add($e->getMessage());
 116      }
 117  }
 118  
 119  /* DISPLAY Main page
 120  -------------------------------------------------------- */
 121  $starting_scripts = dcPage::jsLoad('js/_media_item.js');
 122  if ($popup) {
 123      $starting_scripts .= dcPage::jsLoad('js/jsToolBar/popup_media.js');
 124  }
 125  call_user_func($open_f,__('Media manager'),
 126      $starting_scripts.
 127      dcPage::jsDatePicker().
 128      dcPage::jsPageTabs()
 129  );
 130  
 131  if ($file === null) {
 132      call_user_func($close_f);
 133      exit;
 134  }
 135  
 136  if (!empty($_GET['fupd'])) {
 137      echo '<p class="message">'.__('File has been successfully updated').'</p>';
 138  }
 139  
 140  echo '<h2><a href="'.html::escapeURL($media_page_url).'">'.__('Media manager').'</a>'.
 141  ' / '.$core->media->breadCrum(html::escapeURL($media_page_url).'&amp;d=%s').
 142  $file->basename.'</h2>';
 143  
 144  # Insertion popup
 145  if ($popup && $type == 'image')
 146  {
 147      echo
 148      '<div id="media-insert" class="multi-part" title="'.__('Insert image').'">'.
 149      '<form id="media-insert-form" action="" method="get">'.
 150      '<h3>'.__('Image size:').'</h3> ';
 151      
 152      $s_checked = false;
 153      echo '<p>';
 154      foreach (array_reverse($file->media_thumb) as $s => $v) {
 155          $s_checked = ($s == 'm');
 156          echo '<label class="classic">'.
 157          form::radio(array('src'),html::escapeHTML($v),$s_checked).' '.
 158          $core->media->thumb_sizes[$s][2].'</label><br /> ';
 159      }
 160      $s_checked = (!isset($file->media_thumb['m']));
 161      echo '<label class="classic">'.
 162      form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> ';
 163      echo '</p>';
 164      
 165      
 166      echo '<h3>'.__('Image alignment').'</h3>';
 167      $i_align = array(
 168          'none' => array(__('None'),1),
 169          'left' => array(__('Left'),0),
 170          'right' => array(__('Right'),0),
 171          'center' => array(__('Center'),0)
 172      );
 173      
 174      echo '<p>';
 175      foreach ($i_align as $k => $v) {
 176          echo '<label class="classic">'.
 177          form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> ';
 178      }
 179      echo '</p>';
 180      
 181      echo
 182      '<h3>'.__('Image insertion').'</h3>'.
 183      '<p>'.
 184      '<label class="classic">'.form::radio(array('insertion'),'simple',true).
 185      __('As a single image').'</label><br />'.
 186      '<label class="classic">'.form::radio(array('insertion'),'link',false).
 187      __('As a link to original image').'</label>'.
 188      '</p>';
 189      
 190      echo
 191      '<p><a id="media-insert-cancel" href="#">'.__('Cancel').'</a> - '.
 192      '<strong><a id="media-insert-ok" href="#">'.__('Insert image').'</a></strong>'.
 193      form::hidden(array('title'),html::escapeHTML($file->media_title)).
 194      form::hidden(array('url'),$file->file_url).
 195      '</p>';
 196      
 197      echo '</form></div>';
 198      
 199      
 200  }
 201  
 202  echo
 203  '<div class="multi-part" title="'.__('Media details').'" id="media-details-tab">'.
 204  '<p id="media-icon"><img src="'.$file->media_icon.'" alt="" /></p>';
 205  
 206  echo
 207  '<div id="media-details">';
 208  
 209  if ($file->media_image)
 210  {
 211      $thumb_size = !empty($_GET['size']) ? $_GET['size'] : 's';
 212      
 213      if (!isset($core->media->thumb_sizes[$thumb_size]) && $thumb_size != 'o') {
 214          $thumb_size = 's';
 215      }
 216      
 217      echo '<p>'.__('Available sizes:').' ';
 218      foreach (array_reverse($file->media_thumb) as $s => $v)
 219      {
 220          $strong_link = ($s == $thumb_size) ? '<strong>%s</strong>' : '%s';
 221          printf($strong_link,'<a href="'.html::escapeURL($page_url).
 222          '&amp;id='.$id.'&amp;size='.$s.'">'.$core->media->thumb_sizes[$s][2].'</a> | ');
 223      }
 224      echo '<a href="'.html::escapeURL($page_url).'&amp;id='.$id.'&amp;size=o">'.__('original').'</a>';
 225      echo '</p>';
 226      
 227      if (isset($file->media_thumb[$thumb_size])) {
 228          echo '<p><img src="'.$file->media_thumb[$thumb_size].'" alt="" /></p>';
 229      } elseif ($thumb_size == 'o') {
 230          $S = getimagesize($file->file);
 231          $class = ($S[1] > 500) ? ' class="overheight"' : '';
 232          unset($S);
 233          echo '<p id="media-original-image"'.$class.'><img src="'.$file->file_url.'" alt="" /></p>';
 234      }
 235  }
 236  
 237  if ($file->type == 'audio/mpeg3')
 238  {
 239      echo $core->media->mp3player($file->file_url);
 240  }
 241  
 242  echo
 243  '<h3>'.__('Media details').'</h3>'.
 244  '<ul>'.
 245      '<li><strong>'.__('File owner:').'</strong> '.$file->media_user.'</li>'.
 246      '<li><strong>'.__('File type:').'</strong> '.$file->type.'</li>'.
 247      '<li><strong>'.__('File size:').'</strong> '.files::size($file->size).'</li>'.
 248      '<li><strong>'.__('File URL:').'</strong> <a href="'.$file->file_url.'">'.$file->file_url.'</a></li>'.
 249  '</ul>';
 250  
 251  if ($file->type == 'image/jpeg' && $meta = @simplexml_load_string($file->media_meta))
 252  {
 253      echo
 254      '<h3>'.__('Image details').'</h3>'.
 255      '<ul>';
 256      
 257      $has_meta = false;
 258      foreach ($meta as $k => $v)
 259      {
 260          if ((string) $v) {
 261              $has_meta = true;
 262              echo '<li><strong>'.$k.':</strong> '.html::escapeHTML($v).'</li>';
 263          }
 264      }
 265      
 266      echo '</ul>';
 267      
 268      if (!$has_meta) {
 269          echo '<p>'.__('No detail').'</p>';
 270      }
 271  }
 272  
 273  if ($file->editable)
 274  {
 275      echo
 276      '<h3>'.__('Change media properties').'</h3>'.
 277      '<form action="'.html::escapeURL($page_url).'" method="post">'.
 278      '<p><label>'.__('File name:').dcPage::help('media','f_name').
 279      form::field('media_file',30,255,html::escapeHTML($file->basename)).'</label></p>'.
 280      '<p><label>'.__('File title:').dcPage::help('media','f_title').
 281      form::field('media_title',30,255,html::escapeHTML($file->media_title)).'</label></p>'.
 282      '<p><label>'.__('File date:').dcPage::help('media','f_date').
 283      form::field('media_dt',16,16,html::escapeHTML($file->media_dtstr)).'</label></p>'.
 284      '<p><label class="classic">'.form::checkbox('media_private',1,$file->media_priv).' '.
 285      __('Private').dcPage::help('media','f_private').'</label></p>'.
 286      '<p><label>'.__('New directory:').dcPage::help('media','f_dir').
 287      form::combo('media_path',$dirs_combo,dirname($file->relname)).'</label></p>'.
 288      '<p><input type="submit" accesskey="s" value="'.__('save').'" />'.
 289      form::hidden(array('id'),$id).'</p>'.
 290      '</form>';
 291      
 292      echo
 293      '<h3>'.__('Change file').dcPage::help('media','f_file').'</h3>'.
 294      '<form class="clear" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data">'.
 295      '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'.
 296      '<p><label>'.__('Choose a file:').
 297      ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).') '.
 298      '<input type="file" name="upfile" size="35" />'.
 299      '</label></p>'.
 300      '<p><input type="submit" value="'.__('send').'" />'.
 301      form::hidden(array('id'),$id).'</p>'.
 302      '</form>';
 303  }
 304  
 305  echo
 306  '</div>'.
 307  '</div>';
 308  
 309  call_user_func($close_f);
 310  ?>


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7