$http = netHttp::initClient('http://api.jamendo.com/get2/' . $req . '/' . $type . '/plain/?streamencoding=mp31&id=' . $id, $media_path); $http->setTimeout(5); $http->setUserAgent($_SERVER['HTTP_USER_AGENT']); $http->get($media_path); if ($http->getStatus() != 200) { throw new Exception(__('Invalid page URL')); } if ($type != 'track') { $m_title = $http->getContent(); $m_object = '<object width="200" height="300" type="application/x-shockwave-flash"' . "\n" . 'data="http://widgets.jamendo.com/fr/' . $type . '/?playertype=2008&' . $type . '_id=' . $id . '">' . "\n" . '</object>'; $m_url = $media_page; } else { $t = explode("\t", $http->getContent()); $m_title = $t[0]; $url = $t[1]; $m_object = dcMedia::mp3player($url, $core->blog->getQmarkURL() . 'pf=player_mp3.swf'); $m_url = $media_page; } } break; case 'deezer': if (preg_match('#/track/(.+?)(&|$)#', $media_path, $m)) { $idSong = $m[1]; if (preg_match('#<title>(.+?) \\| Deezer</title>#si', $content, $M)) { $m_title = $M[1]; } $m_object = '<object width="220" height="55" type="application/x-shockwave-flash"' . "\n" . ' data="http://www.deezer.com/embedded/small-widget-v2.swf?idSong=' . $idSong . '&colorBackground=0x555552&textColor1=0xFFFFFF&colorVolume=0x39D1FD&autoplay=0">' . "\n" . '</object>'; } break; } } catch (Exception $e) {
private function newMediaObject($blog_id, $user, $pwd, $file) { if (empty($file['name'])) { throw new Exception('No file name'); } if (empty($file['bits'])) { throw new Exception('No file content'); } $file_name = $file['name']; $file_bits = base64_decode($file['bits']); $this->setUser($user, $pwd); $this->setBlog(); $media = new dcMedia($this->core); $dir_name = path::clean(dirname($file_name)); $file_name = basename($file_name); $dir_name = preg_replace('!^/!', '', $dir_name); if ($dir_name != '') { $dir = explode('/', $dir_name); $cwd = './'; foreach ($dir as $v) { $v = files::tidyFileName($v); $cwd .= $v . '/'; $media->makeDir($v); $media->chdir($cwd); } } $media_id = $media->uploadBits($file_name, $file_bits); $f = $media->getFile($media_id); return array('file' => $file_name, 'url' => $f->file_url, 'type' => files::getMimeType($file_name)); }
/** * Delete an image from images folder (with its thumbnails if any) * * @param string $folder images folder * @param string $img image filename */ public static function dropImage($folder, $img) { global $core; $img = path::real(self::imagesPath($folder) . '/' . $img); if (is_writable(dirname($img))) { // Delete thumbnails if any try { $media = new dcMedia($core); $media->imageThumbRemove($img); } catch (Exception $e) { $core->error->add($e->getMessage()); } // Delete image @unlink($img); } }
if ($thumb_size != 'o' && isset($file->media_thumb[$thumb_size])) { $p = path::info($file->file); $alpha = $p['extension'] == 'png' || $p['extension'] == 'PNG'; $thumb = sprintf($alpha ? $core->media->thumb_tp_alpha : $core->media->thumb_tp, $p['dirname'], $p['base'], '%s'); $thumb_file = sprintf($thumb, $thumb_size); $T = getimagesize($thumb_file); $stats = stat($thumb_file); echo '<h3>' . __('Thumbnail details') . '</h3>' . '<ul>' . '<li><strong>' . __('Image width:') . '</strong> ' . $T[0] . ' px</li>' . '<li><strong>' . __('Image height:') . '</strong> ' . $T[1] . ' px</li>' . '<li><strong>' . __('File size:') . '</strong> ' . files::size($stats[7]) . '</li>' . '<li><strong>' . __('File URL:') . '</strong> <a href="' . $file->media_thumb[$thumb_size] . '">' . $file->media_thumb[$thumb_size] . '</a></li>' . '</ul>'; } } // Show player if relevant if ($file_type[0] == 'audio') { echo dcMedia::audioPlayer($file->type, $file->file_url, $core->adminurl->get("admin.home", array('pf' => 'player_mp3.swf')), null, $core->blog->settings->system->media_flash_fallback); } if ($file_type[0] == 'video') { echo dcMedia::videoPlayer($file->type, $file->file_url, $core->adminurl->get("admin.home", array('pf' => 'player_flv.swf')), null, $core->blog->settings->system->media_flash_fallback); } echo '<h3>' . __('Media details') . '</h3>' . '<ul>' . '<li><strong>' . __('File owner:') . '</strong> ' . $file->media_user . '</li>' . '<li><strong>' . __('File type:') . '</strong> ' . $file->type . '</li>'; if ($file->media_image) { $S = getimagesize($file->file); echo '<li><strong>' . __('Image width:') . '</strong> ' . $S[0] . ' px</li>' . '<li><strong>' . __('Image height:') . '</strong> ' . $S[1] . ' px</li>'; unset($S); } echo '<li><strong>' . __('File size:') . '</strong> ' . files::size($file->size) . '</li>' . '<li><strong>' . __('File URL:') . '</strong> <a href="' . $file->file_url . '">' . $file->file_url . '</a></li>' . '</ul>'; if (empty($_GET['find_posts'])) { echo '<p><a class="button" href="' . $core->adminurl->get('admin.media.item', array_merge($page_url_params, array("find_posts" => 1, "tab" => "media-details-tab"))) . '">' . __('Show entries containing this media') . '</a></p>'; } else { echo '<h3>' . __('Entries containing this media') . '</h3>'; $params = array('post_type' => '', 'from' => 'LEFT OUTER JOIN ' . $core->prefix . 'post_media PM ON P.post_id = PM.post_id ', 'sql' => 'AND (' . 'PM.media_id = ' . (int) $id . ' ' . "OR post_content_xhtml LIKE '%" . $core->con->escape($file->relname) . "%' " . "OR post_excerpt_xhtml LIKE '%" . $core->con->escape($file->relname) . "%' "); if ($file->media_image) { # We look for thumbnails too
function mediaItemLine($f, $i, $query, $table = false) { global $core, $page_url, $popup, $select, $post_id, $plugin_id, $page_url_params; $fname = $f->basename; $file = $query ? $f->relname : $f->basename; $class = $table ? '' : 'media-item media-col-' . $i % 2; if ($f->d) { // Folder $link = $core->adminurl->get('admin.media', array_merge($page_url_params, array('d' => html::sanitizeURL($f->relname)))); if ($f->parent) { $fname = '..'; $class .= ' media-folder-up'; } else { $class .= ' media-folder'; } } else { // Item $params = new ArrayObject(array('id' => $f->media_id, 'plugin_id' => $plugin_id, 'popup' => $popup, 'select' => $select, 'post_id' => $post_id)); $core->callBehavior('adminMediaURLParams', $params); $params = (array) $params; $link = $core->adminurl->get('admin.media.item', $params); } $maxchars = 36; if (strlen($fname) > $maxchars) { $fname = substr($fname, 0, $maxchars - 4) . '...' . ($f->d ? '' : files::getExtension($fname)); } $act = ''; if (!$f->d) { if ($select > 0) { if ($select == 1) { // Single media selection button $act .= '<a href="' . $link . '"><img src="images/plus.png" alt="' . __('Select this file') . '" ' . 'title="' . __('Select this file') . '" /></a> '; } else { // Multiple media selection checkbox $act .= form::checkbox(array('medias[]', 'media_' . rawurlencode($file)), $file); } } else { // Item if ($post_id) { // Media attachment button $act .= '<a class="attach-media" title="' . __('Attach this file to entry') . '" href="' . $core->adminurl->get("admin.post.media", array('media_id' => $f->media_id, 'post_id' => $post_id, 'attach' => 1)) . '">' . '<img src="images/plus.png" alt="' . __('Attach this file to entry') . '"/>' . '</a>'; } if ($popup) { // Media insertion button $act .= '<a href="' . $link . '"><img src="images/plus.png" alt="' . __('Insert this file into entry') . '" ' . 'title="' . __('Insert this file into entry') . '" /></a> '; } } } if ($f->del) { // Deletion button or checkbox if (!$popup && !$f->d) { if ($select < 2) { // Already set for multiple media selection $act .= form::checkbox(array('medias[]', 'media_' . rawurlencode($file)), $file); } } else { $act .= '<a class="media-remove" ' . 'href="' . html::escapeURL($page_url) . '&plugin_id=' . $plugin_id . '&d=' . rawurlencode($GLOBALS['d']) . '&q=' . rawurlencode($GLOBALS['q']) . '&remove=' . rawurlencode($file) . '">' . '<img src="images/trash.png" alt="' . __('Delete') . '" title="' . __('delete') . '" /></a>'; } } // Render markup if (!$table) { $res = '<div class="' . $class . '"><p><a class="media-icon media-link" href="' . rawurldecode($link) . '">' . '<img src="' . $f->media_icon . '" alt="" />' . ($query ? $file : $fname) . '</a></p>'; $lst = ''; if (!$f->d) { $lst .= '<li>' . $f->media_title . '</li>' . '<li>' . $f->media_dtstr . ' - ' . files::size($f->size) . ' - ' . '<a href="' . $f->file_url . '">' . __('open') . '</a>' . '</li>'; } $lst .= $act != '' ? '<li class="media-action"> ' . $act . '</li>' : ''; // Show player if relevant $file_type = explode('/', $f->type); if ($file_type[0] == 'audio') { $lst .= '<li>' . dcMedia::audioPlayer($f->type, $f->file_url, $core->adminurl->get("admin.home", array('pf' => 'player_mp3.swf')), null, $core->blog->settings->system->media_flash_fallback) . '</li>'; } $res .= $lst != '' ? '<ul>' . $lst . '</ul>' : ''; $res .= '</div>'; } else { $res = '<tr class="' . $class . '">'; $res .= '<td class="media-action">' . $act . '</td>'; $res .= '<td class="maximal" scope="row"><a class="media-flag media-link" href="' . rawurldecode($link) . '">' . '<img src="' . $f->media_icon . '" alt="" />' . ($query ? $file : $fname) . '</a>' . '<br />' . ($f->d ? '' : $f->media_title) . '</td>'; $res .= '<td class="nowrap count">' . ($f->d ? '' : $f->media_dtstr) . '</td>'; $res .= '<td class="nowrap count">' . ($f->d ? '' : files::size($f->size) . ' - ' . '<a href="' . $f->file_url . '">' . __('open') . '</a>') . '</td>'; $res .= '</tr>'; } return $res; }
echo '<a href="' . html::escapeURL($page_url) . '&id=' . $id . '&size=o">' . __('original') . '</a>'; echo '</p>'; if (isset($file->media_thumb[$thumb_size])) { echo '<p><img src="' . $file->media_thumb[$thumb_size] . '" alt="" /></p>'; } elseif ($thumb_size == 'o') { $S = getimagesize($file->file); $class = $S[1] > 500 ? ' class="overheight"' : ''; unset($S); echo '<p id="media-original-image"' . $class . '><img src="' . $file->file_url . '" alt="" /></p>'; } } if ($file->type == 'audio/mpeg3') { echo dcMedia::mp3player($file->file_url, 'index.php?pf=player_mp3.swf'); } if ($file->type == 'video/x-flv' || $file->type == 'video/mp4' || $file->type == 'video/x-m4v') { echo dcMedia::flvplayer($file->file_url, 'index.php?pf=player_flv.swf'); } echo '<h3>' . __('Media details') . '</h3>' . '<ul>' . '<li><strong>' . __('File owner:') . '</strong> ' . $file->media_user . '</li>' . '<li><strong>' . __('File type:') . '</strong> ' . $file->type . '</li>' . '<li><strong>' . __('File size:') . '</strong> ' . files::size($file->size) . '</li>' . '<li><strong>' . __('File URL:') . '</strong> <a href="' . $file->file_url . '">' . $file->file_url . '</a></li>' . '</ul>'; if (empty($_GET['find_posts'])) { echo '<p><strong><a href="' . html::escapeHTML($page_url) . '&id=' . $id . '&find_posts=1">' . __('Show entries containing this media') . '</a></strong></p>'; } else { echo '<h3>' . __('Entries containing this media') . '</h3>'; $params = array('post_type' => '', 'from' => 'LEFT OUTER JOIN ' . $core->prefix . 'post_media PM ON P.post_id = PM.post_id ', 'sql' => 'AND (' . 'PM.media_id = ' . (int) $id . ' ' . "OR post_content_xhtml LIKE '%" . $core->con->escape($file->relname) . "%' " . "OR post_excerpt_xhtml LIKE '%" . $core->con->escape($file->relname) . "%' "); if ($file->media_image) { # We look for thumbnails too $media_root = $core->blog->host . path::clean($core->blog->settings->public_url) . '/'; foreach ($file->media_thumb as $v) { $v = preg_replace('/^' . preg_quote($media_root, '/') . '/', '', $v); $params['sql'] .= "OR post_content_xhtml LIKE '%" . $core->con->escape($v) . "%' "; $params['sql'] .= "OR post_excerpt_xhtml LIKE '%" . $core->con->escape($v) . "%' "; }
function mediaItemLine($f, $i) { global $core, $page_url, $popup, $post_id; $fname = $f->basename; if ($f->d) { $link = html::escapeURL($page_url) . '&d=' . html::sanitizeURL($f->relname); if ($f->parent) { $fname = '..'; } } else { $link = 'media_item.php?id=' . $f->media_id . '&popup=' . $popup . '&post_id=' . $post_id; } $class = 'media-item media-col-' . $i % 2; $res = '<div class="' . $class . '"><a class="media-icon media-link" href="' . $link . '">' . '<img src="' . $f->media_icon . '" alt="" /></a>' . '<ul>' . '<li><a class="media-link" href="' . $link . '">' . $fname . '</a></li>'; if (!$f->d) { $res .= '<li>' . $f->media_title . '</li>' . '<li>' . $f->media_dtstr . ' - ' . files::size($f->size) . ' - ' . '<a href="' . $f->file_url . '">' . __('open') . '</a>' . '</li>'; } $res .= '<li class="media-action"> '; if ($post_id && !$f->d) { $res .= '<form action="post_media.php" method="post">' . '<input type="image" src="images/plus.png" alt="' . __('Attach this file to entry') . '" ' . 'title="' . __('Attach this file to entry') . '" /> ' . form::hidden('media_id', $f->media_id) . form::hidden('post_id', $post_id) . form::hidden('attach', 1) . $core->formNonce() . '</form>'; } if ($popup && !$f->d) { $res .= '<a href="' . $link . '"><img src="images/plus.png" alt="' . __('Insert this file into entry') . '" ' . 'title="' . __('Insert this file into entry') . '" /></a> '; } if ($f->del) { $res .= '<a class="media-remove" ' . 'href="' . html::escapeURL($page_url) . '&d=' . rawurlencode($GLOBALS['d']) . '&remove=' . rawurlencode($f->basename) . '">' . '<img src="images/trash.png" alt="' . __('delete') . '" title="' . __('delete') . '" /></a>'; } $res .= '</li>'; if ($f->type == 'audio/mpeg3') { $res .= '<li>' . dcMedia::mp3player($f->file_url, 'index.php?pf=player_mp3.swf') . '</li>'; } $res .= '</ul></div>'; return $res; }