| 1 | <?php | 
|---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- | 
|---|
| 3 | # | 
|---|
| 4 | # This file is part of Dotclear 2. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear | 
|---|
| 7 | # Licensed under the GPL version 2.0 license. | 
|---|
| 8 | # See LICENSE file or | 
|---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html | 
|---|
| 10 | # | 
|---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- | 
|---|
| 12 |  | 
|---|
| 13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; | 
|---|
| 14 |  | 
|---|
| 15 | dcPage::check('media,media_admin'); | 
|---|
| 16 |  | 
|---|
| 17 | $tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab']; | 
|---|
| 18 |  | 
|---|
| 19 | $post_id = !empty($_GET['post_id']) ? (integer) $_GET['post_id'] : null; | 
|---|
| 20 | if ($post_id) { | 
|---|
| 21 | $post = $core->blog->getPosts(array('post_id'=>$post_id)); | 
|---|
| 22 | if ($post->isEmpty()) { | 
|---|
| 23 | $post_id = null; | 
|---|
| 24 | } | 
|---|
| 25 | $post_title = $post->post_title; | 
|---|
| 26 | unset($post); | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | $file = null; | 
|---|
| 30 | $popup = (integer) !empty($_GET['popup']); | 
|---|
| 31 | $page_url = 'media_item.php?popup='.$popup.'&post_id='.$post_id; | 
|---|
| 32 | $media_page_url = 'media.php?popup='.$popup.'&post_id='.$post_id; | 
|---|
| 33 |  | 
|---|
| 34 | $id = !empty($_REQUEST['id']) ? (integer) $_REQUEST['id'] : ''; | 
|---|
| 35 |  | 
|---|
| 36 | if ($popup) { | 
|---|
| 37 | $open_f = array('dcPage','openPopup'); | 
|---|
| 38 | $close_f = array('dcPage','closePopup'); | 
|---|
| 39 | } else { | 
|---|
| 40 | $open_f = array('dcPage','open'); | 
|---|
| 41 | $close_f = create_function('',"dcPage::helpBlock('core_media'); dcPage::close();"); | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | $core_media_writable = false; | 
|---|
| 45 | try | 
|---|
| 46 | { | 
|---|
| 47 | $core->media = new dcMedia($core); | 
|---|
| 48 |  | 
|---|
| 49 | if ($id) { | 
|---|
| 50 | $file = $core->media->getFile($id); | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | if ($file === null) { | 
|---|
| 54 | throw new Exception(__('Not a valid file')); | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | $core->media->chdir(dirname($file->relname)); | 
|---|
| 58 | $core_media_writable = $core->media->writable(); | 
|---|
| 59 |  | 
|---|
| 60 | # Prepare directories combo box | 
|---|
| 61 | $dirs_combo = array(); | 
|---|
| 62 | foreach ($core->media->getRootDirs() as $v) { | 
|---|
| 63 | if ($v->w) { | 
|---|
| 64 | $dirs_combo['/'.$v->relname] = $v->relname; | 
|---|
| 65 | } | 
|---|
| 66 | } | 
|---|
| 67 | ksort($dirs_combo); | 
|---|
| 68 | } | 
|---|
| 69 | catch (Exception $e) | 
|---|
| 70 | { | 
|---|
| 71 | $core->error->add($e->getMessage()); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | # Upload a new file | 
|---|
| 75 | if ($file && !empty($_FILES['upfile']) && $file->editable && $core_media_writable) | 
|---|
| 76 | { | 
|---|
| 77 | try { | 
|---|
| 78 | files::uploadStatus($_FILES['upfile']); | 
|---|
| 79 | $core->media->uploadFile($_FILES['upfile']['tmp_name'],$file->basename,null,false,true); | 
|---|
| 80 | http::redirect($page_url.'&id='.$id.'&fupl=1'); | 
|---|
| 81 | } catch (Exception $e) { | 
|---|
| 82 | $core->error->add($e->getMessage()); | 
|---|
| 83 | } | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | # Update file | 
|---|
| 87 | if ($file && !empty($_POST['media_file']) && $file->editable && $core_media_writable) | 
|---|
| 88 | { | 
|---|
| 89 | $newFile = clone $file; | 
|---|
| 90 |  | 
|---|
| 91 | $newFile->basename = $_POST['media_file']; | 
|---|
| 92 |  | 
|---|
| 93 | if ($_POST['media_path']) { | 
|---|
| 94 | $newFile->dir = $_POST['media_path']; | 
|---|
| 95 | $newFile->relname = $_POST['media_path'].'/'.$newFile->basename; | 
|---|
| 96 | } else { | 
|---|
| 97 | $newFile->dir = ''; | 
|---|
| 98 | $newFile->relname = $newFile->basename; | 
|---|
| 99 | } | 
|---|
| 100 | $newFile->media_title = $_POST['media_title']; | 
|---|
| 101 | $newFile->media_dt = strtotime($_POST['media_dt']); | 
|---|
| 102 | $newFile->media_dtstr = $_POST['media_dt']; | 
|---|
| 103 | $newFile->media_priv = !empty($_POST['media_private']); | 
|---|
| 104 |  | 
|---|
| 105 | try { | 
|---|
| 106 | $core->media->updateFile($file,$newFile); | 
|---|
| 107 | http::redirect($page_url.'&id='.$id.'&fupd=1&tab=media-details-tab'); | 
|---|
| 108 | } catch (Exception $e) { | 
|---|
| 109 | $core->error->add($e->getMessage()); | 
|---|
| 110 | } | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | # Update thumbnails | 
|---|
| 114 | if (!empty($_POST['thumbs']) && $file->media_type == 'image' && $file->editable && $core_media_writable) | 
|---|
| 115 | { | 
|---|
| 116 | try { | 
|---|
| 117 | $foo = null; | 
|---|
| 118 | $core->media->mediaFireRecreateEvent($file); | 
|---|
| 119 | http::redirect($page_url.'&id='.$id.'&thumbupd=1&tab=media-details-tab'); | 
|---|
| 120 | } catch (Exception $e) { | 
|---|
| 121 | $core->error->add($e->getMessage()); | 
|---|
| 122 | } | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | # Unzip file | 
|---|
| 126 | if (!empty($_POST['unzip']) && $file->type == 'application/zip' && $file->editable && $core_media_writable) | 
|---|
| 127 | { | 
|---|
| 128 | try { | 
|---|
| 129 | $unzip_dir = $core->media->inflateZipFile($file,$_POST['inflate_mode'] == 'new'); | 
|---|
| 130 | http::redirect($media_page_url.'&d='.$unzip_dir.'&unzipok=1'); | 
|---|
| 131 | } catch (Exception $e) { | 
|---|
| 132 | $core->error->add($e->getMessage()); | 
|---|
| 133 | } | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | # Function to get image title based on meta | 
|---|
| 137 | function dcGetImageTitle($file,$pattern,$dto_first=false) | 
|---|
| 138 | { | 
|---|
| 139 | $res = array(); | 
|---|
| 140 | $pattern = preg_split('/\s*;;\s*/',$pattern); | 
|---|
| 141 | $sep = ', '; | 
|---|
| 142 |  | 
|---|
| 143 | foreach ($pattern as $v) { | 
|---|
| 144 | if ($v == 'Title') { | 
|---|
| 145 | $res[] = $file->media_title; | 
|---|
| 146 | } elseif ($file->media_meta->{$v}) { | 
|---|
| 147 | $res[] = (string) $file->media_meta->{$v}; | 
|---|
| 148 | } elseif (preg_match('/^Date\((.+?)\)$/u',$v,$m)) { | 
|---|
| 149 | if ($dto_first && $file->media_meta->DateTimeOriginal) { | 
|---|
| 150 | $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal); | 
|---|
| 151 | } else { | 
|---|
| 152 | $res[] = dt::str($m[1],$file->media_dt); | 
|---|
| 153 | } | 
|---|
| 154 | } elseif (preg_match('/^DateTimeOriginal\((.+?)\)$/u',$v,$m) && $file->media_meta->DateTimeOriginal) { | 
|---|
| 155 | $res[] = dt::dt2str($m[1],(string) $file->media_meta->DateTimeOriginal); | 
|---|
| 156 | } elseif (preg_match('/^separator\((.*?)\)$/u',$v,$m)) { | 
|---|
| 157 | $sep = $m[1]; | 
|---|
| 158 | } | 
|---|
| 159 | } | 
|---|
| 160 | return implode($sep,$res); | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | /* DISPLAY Main page | 
|---|
| 164 | -------------------------------------------------------- */ | 
|---|
| 165 | $starting_scripts = | 
|---|
| 166 | '<script type="text/javascript">'."\n". | 
|---|
| 167 | "//<![CDATA["."\n". | 
|---|
| 168 | dcPage::jsVar('dotclear.msg.confirm_delete_media',__('Are you sure to delete this media?'))."\n". | 
|---|
| 169 | "//]]>". | 
|---|
| 170 | "</script>". | 
|---|
| 171 | dcPage::jsLoad('js/_media_item.js'); | 
|---|
| 172 | if ($popup) { | 
|---|
| 173 | $starting_scripts .= | 
|---|
| 174 | dcPage::jsLoad('js/jsToolBar/popup_media.js'); | 
|---|
| 175 | } | 
|---|
| 176 | call_user_func($open_f,__('Media manager'), | 
|---|
| 177 | $starting_scripts. | 
|---|
| 178 | dcPage::jsDatePicker(). | 
|---|
| 179 | dcPage::jsPageTabs($tab) | 
|---|
| 180 | ); | 
|---|
| 181 |  | 
|---|
| 182 | if ($file === null) { | 
|---|
| 183 | call_user_func($close_f); | 
|---|
| 184 | exit; | 
|---|
| 185 | } | 
|---|
| 186 |  | 
|---|
| 187 | if (!empty($_GET['fupd']) || !empty($_GET['fupl'])) { | 
|---|
| 188 | dcPage::message(__('File has been successfully updated.')); | 
|---|
| 189 | } | 
|---|
| 190 | if (!empty($_GET['thumbupd'])) { | 
|---|
| 191 | dcPage::message(__('Thumbnails have been successfully updated.')); | 
|---|
| 192 | } | 
|---|
| 193 |  | 
|---|
| 194 | echo '<h2><a href="'.html::escapeURL($media_page_url).'">'.__('Media manager').'</a>'. | 
|---|
| 195 | ' / '.$core->media->breadCrumb(html::escapeURL($media_page_url).'&d=%s'). | 
|---|
| 196 | '<span class="page-title">'.$file->basename.'</span></h2>'; | 
|---|
| 197 |  | 
|---|
| 198 | # Insertion popup | 
|---|
| 199 | if ($popup) | 
|---|
| 200 | { | 
|---|
| 201 | $media_desc = $file->media_title; | 
|---|
| 202 |  | 
|---|
| 203 | echo | 
|---|
| 204 | '<div id="media-insert" class="multi-part" title="'.__('Insert media item').'">'. | 
|---|
| 205 | '<form id="media-insert-form" action="" method="get">'; | 
|---|
| 206 |  | 
|---|
| 207 | $media_img_default_size = $core->blog->settings->system->media_img_default_size; | 
|---|
| 208 | if ($media_img_default_size == '') { | 
|---|
| 209 | $media_img_default_size = 'm'; | 
|---|
| 210 | } | 
|---|
| 211 | $media_img_default_alignment = $core->blog->settings->system->media_img_default_alignment; | 
|---|
| 212 | if ($media_img_default_alignment == '') { | 
|---|
| 213 | $media_img_default_alignment = 'none'; | 
|---|
| 214 | } | 
|---|
| 215 | $media_img_default_link = (boolean)$core->blog->settings->system->media_img_default_link; | 
|---|
| 216 |  | 
|---|
| 217 | if ($file->media_type == 'image') | 
|---|
| 218 | { | 
|---|
| 219 | $media_type = 'image'; | 
|---|
| 220 | $media_desc = dcGetImageTitle($file, | 
|---|
| 221 | $core->blog->settings->system->media_img_title_pattern, | 
|---|
| 222 | $core->blog->settings->system->media_img_use_dto_first); | 
|---|
| 223 | if ($media_desc == $file->basename) { | 
|---|
| 224 | $media_desc = ''; | 
|---|
| 225 | } | 
|---|
| 226 |  | 
|---|
| 227 | echo | 
|---|
| 228 | '<h3>'.__('Image size:').'</h3> '; | 
|---|
| 229 |  | 
|---|
| 230 | $s_checked = false; | 
|---|
| 231 | echo '<p>'; | 
|---|
| 232 | foreach (array_reverse($file->media_thumb) as $s => $v) { | 
|---|
| 233 | $s_checked = ($s == $media_img_default_size); | 
|---|
| 234 | echo '<label class="classic">'. | 
|---|
| 235 | form::radio(array('src'),html::escapeHTML($v),$s_checked).' '. | 
|---|
| 236 | $core->media->thumb_sizes[$s][2].'</label><br /> '; | 
|---|
| 237 | } | 
|---|
| 238 | $s_checked = (!isset($file->media_thumb[$media_img_default_size])); | 
|---|
| 239 | echo '<label class="classic">'. | 
|---|
| 240 | form::radio(array('src'),$file->file_url,$s_checked).' '.__('original').'</label><br /> '; | 
|---|
| 241 | echo '</p>'; | 
|---|
| 242 |  | 
|---|
| 243 |  | 
|---|
| 244 | echo '<h3>'.__('Image alignment').'</h3>'; | 
|---|
| 245 | $i_align = array( | 
|---|
| 246 | 'none' => array(__('None'),($media_img_default_alignment == 'none' ? 1 : 0)), | 
|---|
| 247 | 'left' => array(__('Left'),($media_img_default_alignment == 'left' ? 1 : 0)), | 
|---|
| 248 | 'right' => array(__('Right'),($media_img_default_alignment == 'right' ? 1 : 0)), | 
|---|
| 249 | 'center' => array(__('Center'),($media_img_default_alignment == 'center' ? 1 : 0)) | 
|---|
| 250 | ); | 
|---|
| 251 |  | 
|---|
| 252 | echo '<p>'; | 
|---|
| 253 | foreach ($i_align as $k => $v) { | 
|---|
| 254 | echo '<label class="classic">'. | 
|---|
| 255 | form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> '; | 
|---|
| 256 | } | 
|---|
| 257 | echo '</p>'; | 
|---|
| 258 |  | 
|---|
| 259 | echo | 
|---|
| 260 | '<h3>'.__('Image insertion').'</h3>'. | 
|---|
| 261 | '<p>'. | 
|---|
| 262 | '<label for="insert1" class="classic">'.form::radio(array('insertion','insert1'),'simple',!$media_img_default_link). | 
|---|
| 263 | __('As a single image').'</label><br />'. | 
|---|
| 264 | '<label for="insert2" class="classic">'.form::radio(array('insertion','insert2'),'link',$media_img_default_link). | 
|---|
| 265 | __('As a link to original image').'</label>'. | 
|---|
| 266 | '</p>'; | 
|---|
| 267 | } | 
|---|
| 268 | elseif ($file->type == 'audio/mpeg3') | 
|---|
| 269 | { | 
|---|
| 270 | $media_type = 'mp3'; | 
|---|
| 271 |  | 
|---|
| 272 | echo '<h3>'.__('MP3 disposition').'</h3>'; | 
|---|
| 273 | dcPage::message(__("Please note that you cannot insert mp3 files with visual editor."),false); | 
|---|
| 274 |  | 
|---|
| 275 | $i_align = array( | 
|---|
| 276 | 'none' => array(__('None'),($media_img_default_alignment == 'none' ? 1 : 0)), | 
|---|
| 277 | 'left' => array(__('Left'),($media_img_default_alignment == 'left' ? 1 : 0)), | 
|---|
| 278 | 'right' => array(__('Right'),($media_img_default_alignment == 'right' ? 1 : 0)), | 
|---|
| 279 | 'center' => array(__('Center'),($media_img_default_alignment == 'center' ? 1 : 0)) | 
|---|
| 280 | ); | 
|---|
| 281 |  | 
|---|
| 282 | echo '<p>'; | 
|---|
| 283 | foreach ($i_align as $k => $v) { | 
|---|
| 284 | echo '<label for="alignment" class="classic">'. | 
|---|
| 285 | form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> '; | 
|---|
| 286 | } | 
|---|
| 287 |  | 
|---|
| 288 | $public_player_style = unserialize($core->blog->settings->themes->mp3player_style); | 
|---|
| 289 | $public_player = dcMedia::mp3player($file->file_url,$core->blog->getQmarkURL().'pf=player_mp3.swf',$public_player_style); | 
|---|
| 290 | echo form::hidden('public_player',html::escapeHTML($public_player)); | 
|---|
| 291 | echo '</p>'; | 
|---|
| 292 | } | 
|---|
| 293 | elseif ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v') | 
|---|
| 294 | { | 
|---|
| 295 | $media_type = 'flv'; | 
|---|
| 296 |  | 
|---|
| 297 | dcPage::message(__("Please note that you cannot insert video files with visual editor."),false); | 
|---|
| 298 |  | 
|---|
| 299 | echo | 
|---|
| 300 | '<h3>'.__('Video size').'</h3>'. | 
|---|
| 301 | '<p><label for="video_w" class="classic">'.__('Width:').'</label> '. | 
|---|
| 302 | form::field('video_w',3,4,400).'  '. | 
|---|
| 303 | '<label for="video_h" class="classic">'.__('Height:').'</label> '. | 
|---|
| 304 | form::field('video_h',3,4,300). | 
|---|
| 305 | '</p>'; | 
|---|
| 306 |  | 
|---|
| 307 | echo '<h3>'.__('Video disposition').'</h3>'; | 
|---|
| 308 |  | 
|---|
| 309 | $i_align = array( | 
|---|
| 310 | 'none' => array(__('None'),($media_img_default_alignment == 'none' ? 1 : 0)), | 
|---|
| 311 | 'left' => array(__('Left'),($media_img_default_alignment == 'left' ? 1 : 0)), | 
|---|
| 312 | 'right' => array(__('Right'),($media_img_default_alignment == 'right' ? 1 : 0)), | 
|---|
| 313 | 'center' => array(__('Center'),($media_img_default_alignment == 'center' ? 1 : 0)) | 
|---|
| 314 | ); | 
|---|
| 315 |  | 
|---|
| 316 | echo '<p>'; | 
|---|
| 317 | foreach ($i_align as $k => $v) { | 
|---|
| 318 | echo '<label for="alignment" class="classic">'. | 
|---|
| 319 | form::radio(array('alignment'),$k,$v[1]).' '.$v[0].'</label><br /> '; | 
|---|
| 320 | } | 
|---|
| 321 |  | 
|---|
| 322 | $public_player_style = unserialize($core->blog->settings->themes->flvplayer_style); | 
|---|
| 323 | $public_player = dcMedia::flvplayer($file->file_url,$core->blog->getQmarkURL().'pf=player_flv.swf',$public_player_style); | 
|---|
| 324 | echo form::hidden('public_player',html::escapeHTML($public_player)); | 
|---|
| 325 | echo '</p>'; | 
|---|
| 326 | } | 
|---|
| 327 | else | 
|---|
| 328 | { | 
|---|
| 329 | $media_type = 'default'; | 
|---|
| 330 | echo '<p>'.__('Media item will be inserted as a link.').'</p>'; | 
|---|
| 331 | } | 
|---|
| 332 |  | 
|---|
| 333 | echo | 
|---|
| 334 | '<p><a id="media-insert-cancel" class="button" href="#">'.__('Cancel').'</a> - '. | 
|---|
| 335 | '<strong><a id="media-insert-ok" class="button" href="#">'.__('Insert').'</a></strong>'. | 
|---|
| 336 | form::hidden(array('type'),html::escapeHTML($media_type)). | 
|---|
| 337 | form::hidden(array('title'),html::escapeHTML($file->media_title)). | 
|---|
| 338 | form::hidden(array('description'),html::escapeHTML($media_desc)). | 
|---|
| 339 | form::hidden(array('url'),$file->file_url). | 
|---|
| 340 | '</p>'; | 
|---|
| 341 |  | 
|---|
| 342 | echo '</form></div>'; | 
|---|
| 343 | } | 
|---|
| 344 |  | 
|---|
| 345 | echo | 
|---|
| 346 | '<div class="multi-part" title="'.__('Media details').'" id="media-details-tab">'. | 
|---|
| 347 | '<p id="media-icon"><img src="'.$file->media_icon.'?'.time()*rand().'" alt="" /></p>'; | 
|---|
| 348 |  | 
|---|
| 349 | echo | 
|---|
| 350 | '<div id="media-details">'; | 
|---|
| 351 |  | 
|---|
| 352 | if ($file->media_image) | 
|---|
| 353 | { | 
|---|
| 354 | $thumb_size = !empty($_GET['size']) ? $_GET['size'] : 's'; | 
|---|
| 355 |  | 
|---|
| 356 | if (!isset($core->media->thumb_sizes[$thumb_size]) && $thumb_size != 'o') { | 
|---|
| 357 | $thumb_size = 's'; | 
|---|
| 358 | } | 
|---|
| 359 |  | 
|---|
| 360 | echo '<p>'.__('Available sizes:').' '; | 
|---|
| 361 | foreach (array_reverse($file->media_thumb) as $s => $v) | 
|---|
| 362 | { | 
|---|
| 363 | $strong_link = ($s == $thumb_size) ? '<strong>%s</strong>' : '%s'; | 
|---|
| 364 | printf($strong_link,'<a href="'.html::escapeURL($page_url). | 
|---|
| 365 | '&id='.$id.'&size='.$s.'&tab=media-details-tab">'.$core->media->thumb_sizes[$s][2].'</a> | '); | 
|---|
| 366 | } | 
|---|
| 367 | echo '<a href="'.html::escapeURL($page_url).'&id='.$id.'&size=o&tab=media-details-tab">'.__('original').'</a>'; | 
|---|
| 368 | echo '</p>'; | 
|---|
| 369 |  | 
|---|
| 370 | if (isset($file->media_thumb[$thumb_size])) { | 
|---|
| 371 | echo '<p><img src="'.$file->media_thumb[$thumb_size].'?'.time()*rand().'" alt="" /></p>'; | 
|---|
| 372 | } elseif ($thumb_size == 'o') { | 
|---|
| 373 | $S = getimagesize($file->file); | 
|---|
| 374 | $class = ($S[1] > 500) ? ' class="overheight"' : ''; | 
|---|
| 375 | unset($S); | 
|---|
| 376 | echo '<p id="media-original-image"'.$class.'><img src="'.$file->file_url.'?'.time()*rand().'" alt="" /></p>'; | 
|---|
| 377 | } | 
|---|
| 378 | } | 
|---|
| 379 |  | 
|---|
| 380 | if ($file->type == 'audio/mpeg3') | 
|---|
| 381 | { | 
|---|
| 382 | echo dcMedia::mp3player($file->file_url,'index.php?pf=player_mp3.swf'); | 
|---|
| 383 | } | 
|---|
| 384 |  | 
|---|
| 385 | if ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v') | 
|---|
| 386 | { | 
|---|
| 387 | echo dcMedia::flvplayer($file->file_url,'index.php?pf=player_flv.swf'); | 
|---|
| 388 | } | 
|---|
| 389 |  | 
|---|
| 390 | echo | 
|---|
| 391 | '<h3>'.__('Media details').'</h3>'. | 
|---|
| 392 | '<ul>'. | 
|---|
| 393 | '<li><strong>'.__('File owner:').'</strong> '.$file->media_user.'</li>'. | 
|---|
| 394 | '<li><strong>'.__('File type:').'</strong> '.$file->type.'</li>'. | 
|---|
| 395 | '<li><strong>'.__('File size:').'</strong> '.files::size($file->size).'</li>'. | 
|---|
| 396 | '<li><strong>'.__('File URL:').'</strong> <a href="'.$file->file_url.'">'.$file->file_url.'</a></li>'. | 
|---|
| 397 | '</ul>'; | 
|---|
| 398 |  | 
|---|
| 399 | if (empty($_GET['find_posts'])) | 
|---|
| 400 | { | 
|---|
| 401 | echo | 
|---|
| 402 | '<p><strong><a href="'.html::escapeHTML($page_url).'&id='.$id.'&find_posts=1&tab=media-details-tab">'. | 
|---|
| 403 | __('Show entries containing this media').'</a></strong></p>'; | 
|---|
| 404 | } | 
|---|
| 405 | else | 
|---|
| 406 | { | 
|---|
| 407 | echo '<h3>'.__('Entries containing this media').'</h3>'; | 
|---|
| 408 | $params = array( | 
|---|
| 409 | 'post_type' => '', | 
|---|
| 410 | 'from' => 'LEFT OUTER JOIN '.$core->prefix.'post_media PM ON P.post_id = PM.post_id ', | 
|---|
| 411 | 'sql' => 'AND ('. | 
|---|
| 412 | 'PM.media_id = '.(integer) $id.' '. | 
|---|
| 413 | "OR post_content_xhtml LIKE '%".$core->con->escape($file->relname)."%' ". | 
|---|
| 414 | "OR post_excerpt_xhtml LIKE '%".$core->con->escape($file->relname)."%' " | 
|---|
| 415 | ); | 
|---|
| 416 |  | 
|---|
| 417 | if ($file->media_image) | 
|---|
| 418 | { # We look for thumbnails too | 
|---|
| 419 | if (preg_match('#^http(s)?://#',$core->blog->settings->system->public_url)) { | 
|---|
| 420 | $media_root = $core->blog->settings->system->public_url; | 
|---|
| 421 | } else { | 
|---|
| 422 | $media_root = $core->blog->host.path::clean($core->blog->settings->system->public_url).'/'; | 
|---|
| 423 | } | 
|---|
| 424 | foreach ($file->media_thumb as $v) { | 
|---|
| 425 | $v = preg_replace('/^'.preg_quote($media_root,'/').'/','',$v); | 
|---|
| 426 | $params['sql'] .= "OR post_content_xhtml LIKE '%".$core->con->escape($v)."%' "; | 
|---|
| 427 | $params['sql'] .= "OR post_excerpt_xhtml LIKE '%".$core->con->escape($v)."%' "; | 
|---|
| 428 | } | 
|---|
| 429 | } | 
|---|
| 430 |  | 
|---|
| 431 | $params['sql'] .= ') '; | 
|---|
| 432 |  | 
|---|
| 433 | $rs = $core->blog->getPosts($params); | 
|---|
| 434 |  | 
|---|
| 435 | if ($rs->isEmpty()) | 
|---|
| 436 | { | 
|---|
| 437 | echo '<p>'.__('No entry seems contain this media.').'</p>'; | 
|---|
| 438 | } | 
|---|
| 439 | else | 
|---|
| 440 | { | 
|---|
| 441 | echo '<ul>'; | 
|---|
| 442 | while ($rs->fetch()) { | 
|---|
| 443 | $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; | 
|---|
| 444 | switch ($rs->post_status) { | 
|---|
| 445 | case 1: | 
|---|
| 446 | $img_status = sprintf($img,__('published'),'check-on.png'); | 
|---|
| 447 | break; | 
|---|
| 448 | case 0: | 
|---|
| 449 | $img_status = sprintf($img,__('unpublished'),'check-off.png'); | 
|---|
| 450 | break; | 
|---|
| 451 | case -1: | 
|---|
| 452 | $img_status = sprintf($img,__('scheduled'),'scheduled.png'); | 
|---|
| 453 | break; | 
|---|
| 454 | case -2: | 
|---|
| 455 | $img_status = sprintf($img,__('pending'),'check-wrn.png'); | 
|---|
| 456 | break; | 
|---|
| 457 | } | 
|---|
| 458 | echo '<li>'.$img_status.' '.'<a href="'.$core->getPostAdminURL($rs->post_type,$rs->post_id).'">'. | 
|---|
| 459 | $rs->post_title.'</a>'. | 
|---|
| 460 | ($rs->post_type != 'post' ? ' ('.html::escapeHTML($rs->post_type).')' : ''). | 
|---|
| 461 | ' - '.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->post_dt).'</li>'; | 
|---|
| 462 | } | 
|---|
| 463 | echo '</ul>'; | 
|---|
| 464 | } | 
|---|
| 465 | } | 
|---|
| 466 |  | 
|---|
| 467 | if ($file->type == 'image/jpeg') | 
|---|
| 468 | { | 
|---|
| 469 | echo '<h3>'.__('Image details').'</h3>'; | 
|---|
| 470 |  | 
|---|
| 471 | if (count($file->media_meta) == 0) | 
|---|
| 472 | { | 
|---|
| 473 | echo '<p>'.__('No detail').'</p>'; | 
|---|
| 474 | } | 
|---|
| 475 | else | 
|---|
| 476 | { | 
|---|
| 477 | echo '<ul>'; | 
|---|
| 478 | foreach ($file->media_meta as $k => $v) | 
|---|
| 479 | { | 
|---|
| 480 | if ((string) $v) { | 
|---|
| 481 | echo '<li><strong>'.$k.':</strong> '.html::escapeHTML($v).'</li>'; | 
|---|
| 482 | } | 
|---|
| 483 | } | 
|---|
| 484 | echo '</ul>'; | 
|---|
| 485 | } | 
|---|
| 486 | } | 
|---|
| 487 |  | 
|---|
| 488 | if ($file->editable && $core_media_writable) | 
|---|
| 489 | { | 
|---|
| 490 | if ($file->media_type == 'image') | 
|---|
| 491 | { | 
|---|
| 492 | echo | 
|---|
| 493 | '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'. | 
|---|
| 494 | '<fieldset><legend>'.__('Update thumbnails').'</legend>'. | 
|---|
| 495 | '<p>'.__('This will create or update thumbnails for this image.').'</p>'. | 
|---|
| 496 | '<p><input type="submit" name="thumbs" value="'.__('Update thumbnails').'" />'. | 
|---|
| 497 | form::hidden(array('id'),$id). | 
|---|
| 498 | $core->formNonce().'</p>'. | 
|---|
| 499 | '</fieldset></form>'; | 
|---|
| 500 | } | 
|---|
| 501 |  | 
|---|
| 502 | if ($file->type == 'application/zip') | 
|---|
| 503 | { | 
|---|
| 504 | $inflate_combo = array( | 
|---|
| 505 | __('Extract in a new directory') => 'new', | 
|---|
| 506 | __('Extract in current directory') => 'current' | 
|---|
| 507 | ); | 
|---|
| 508 |  | 
|---|
| 509 | echo | 
|---|
| 510 | '<form class="clear" id="file-unzip" action="'.html::escapeURL($page_url).'" method="post">'. | 
|---|
| 511 | '<fieldset><legend>'.__('Extract archive').'</legend>'. | 
|---|
| 512 | '<ul>'. | 
|---|
| 513 | '<li><strong>'.__('Extract in a new directory').'</strong> : '. | 
|---|
| 514 | __('This will extract archive in a new directory that should not exist yet.').'</li>'. | 
|---|
| 515 | '<li><strong>'.__('Extract in current directory').'</strong> : '. | 
|---|
| 516 | __('This will extract archive in current directory and will overwrite existing files or directory.').'</li>'. | 
|---|
| 517 | '</ul>'. | 
|---|
| 518 | '<p><label for="inflate_mode" class="classic">'.__('Extract mode:').' '. | 
|---|
| 519 | form::combo('inflate_mode',$inflate_combo,'new').'</label> '. | 
|---|
| 520 | '<input type="submit" name="unzip" value="'.__('Extract').'" />'. | 
|---|
| 521 | form::hidden(array('id'),$id). | 
|---|
| 522 | $core->formNonce().'</p>'. | 
|---|
| 523 | '</fieldset></form>'; | 
|---|
| 524 | } | 
|---|
| 525 |  | 
|---|
| 526 | echo | 
|---|
| 527 | '<form class="clear" action="'.html::escapeURL($page_url).'" method="post">'. | 
|---|
| 528 | '<fieldset><legend>'.__('Change media properties').'</legend>'. | 
|---|
| 529 | '<p><label for="media_file">'.__('File name:'). | 
|---|
| 530 | form::field('media_file',30,255,html::escapeHTML($file->basename)).'</label></p>'. | 
|---|
| 531 | '<p><label for="media_title">'.__('File title:'). | 
|---|
| 532 | form::field('media_title',30,255,html::escapeHTML($file->media_title)).'</label></p>'. | 
|---|
| 533 | '<p><label for="media_dt">'.__('File date:'). | 
|---|
| 534 | form::field('media_dt',16,16,html::escapeHTML($file->media_dtstr)).'</label></p>'. | 
|---|
| 535 | '<p><label for="media_private" class="classic">'.form::checkbox('media_private',1,$file->media_priv).' '. | 
|---|
| 536 | __('Private').'</label></p>'. | 
|---|
| 537 | '<p><label for="media_path">'.__('New directory:'). | 
|---|
| 538 | form::combo('media_path',$dirs_combo,dirname($file->relname)).'</label></p>'. | 
|---|
| 539 | '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'. | 
|---|
| 540 | form::hidden(array('id'),$id). | 
|---|
| 541 | $core->formNonce().'</p>'. | 
|---|
| 542 | '</fieldset></form>'; | 
|---|
| 543 |  | 
|---|
| 544 | echo | 
|---|
| 545 | '<form class="clear" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data">'. | 
|---|
| 546 | '<fieldset><legend>'.__('Change file').'</legend>'. | 
|---|
| 547 | '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE).'</div>'. | 
|---|
| 548 | '<p><label for="upfile">'.__('Choose a file:'). | 
|---|
| 549 | ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).') '. | 
|---|
| 550 | '<input type="file" id="upfile" name="upfile" size="35" />'. | 
|---|
| 551 | '</label></p>'. | 
|---|
| 552 | '<p><input type="submit" value="'.__('Send').'" />'. | 
|---|
| 553 | form::hidden(array('id'),$id). | 
|---|
| 554 | $core->formNonce().'</p>'. | 
|---|
| 555 | '</fieldset></form>'; | 
|---|
| 556 |  | 
|---|
| 557 | if ($file->del) { | 
|---|
| 558 | echo | 
|---|
| 559 | '<form id="delete-form" method="post" action="'.html::escapeURL($media_page_url). | 
|---|
| 560 | '&d='.rawurlencode(dirname($file->relname)). | 
|---|
| 561 | '&remove='.rawurlencode($file->basename).'">'. | 
|---|
| 562 | '<p><input name="delete" type="submit" class="delete" value="'.__('Delete this media').'" />'. | 
|---|
| 563 | form::hidden('remove',rawurlencode($file->basename)). | 
|---|
| 564 | form::hidden('rmyes',1). | 
|---|
| 565 | $core->formNonce().'</p>'. | 
|---|
| 566 | '</form>'; | 
|---|
| 567 | } | 
|---|
| 568 |  | 
|---|
| 569 |  | 
|---|
| 570 | # --BEHAVIOR-- adminMediaItemForm | 
|---|
| 571 | $core->callBehavior('adminMediaItemForm',$file); | 
|---|
| 572 | } | 
|---|
| 573 |  | 
|---|
| 574 | echo | 
|---|
| 575 | '</div>'. | 
|---|
| 576 | '</div>'; | 
|---|
| 577 |  | 
|---|
| 578 | call_user_func($close_f); | 
|---|
| 579 | ?> | 
|---|