hesleskaug Posted February 24, 2010 Share Posted February 24, 2010 Hello! I bought a VideoCMS from basic09.com. It was mostly what I was looking for, but I want to do some tweaks. As of now I can upload video via the browser and link to some specific sites. (youtube ++ +) But I want do be able to add video and thumbnails via URL, since I have lot of my projects allready uploaded via FTP. This is how the admin looks now. If I try to upload through (ex. file http://myhost.com/videos/myvideo.flv): "URL (supported: Youtube, Dailymotion, Metacafe, Zideo, 123video) " I get the error: Something went wrong... Please fix the following errors: * This URL is not supported or malformed. But I want to add: "Upload video via URL" "Upload thumbnail via URL" Is there any easy way to do this? I am a beginnerphp coder. CODE: <?php define('IN_ADMIN', true); require_once('../config.php'); if(!logged_in('admin')) { header('Location: ' . $path . 'admin/login/'); exit(); } else { require_once('../includes/phpthumb/ThumbLib.inc.php'); $do = (isset($_GET['do']) ? $_GET['do'] : 'browse'); $seo = (isset($_GET['seo']) ? $_GET['seo'] : false); $tpl->assign('module', $do); $submit = ($_SERVER['REQUEST_METHOD'] == 'POST'); if($do == 'browse') { $res = mysql_query(" SELECT m.title AS m_title, m.seo_url AS m_seo_url, c.title AS c_title, c.seo_url AS c_seo_url FROM movies AS m LEFT JOIN categories AS c ON m.category_id = c.id ORDER BY c.title, m.title ASC"); if(mysql_num_rows($res)) { $rows = array(); while($row = mysql_fetch_assoc($res)) { $rows[] = $row; } $tpl->assign('movies', _htmlspecialchars($rows)); } } elseif($do == 'new') { $res = mysql_query("SELECT id, title FROM categories ORDER BY title ASC"); if(mysql_num_rows($res)) { $categories = array(); while($row = mysql_fetch_assoc($res)) { $categories[$row['id']] = $row['title']; } $tpl->assign('categories', _htmlspecialchars($categories)); } if($submit) { $errors = array(); $tpl->assign('value', _htmlspecialchars($_POST)); if($_POST['title'] == '' OR strlen($_POST['title']) > 150) { $errors[] = 'Invalid title.'; } if(!isset($_POST['category_id']) OR !array_key_exists($_POST['category_id'], $categories)) { $errors[] = 'Invalid category.'; } $movie_url = null; $movie_filename = null; $move = false; $save_thumb = false; if($_POST['movie_url'] == '' AND $_FILES['movie_filename']['tmp_name'] == '') { $errors[] = 'Specify a video URL or upload a file.'; } elseif($_POST['movie_url'] != '') { if($parts = parse_url($_POST['movie_url'])) { if(strstr(@$parts['host'], 'youtube') !== false) { // YouTube if(preg_match('/v=([^&]+)/', @$parts['query'], $matches)) { $movie_url = array('type' => 'youtube', 'key' => $matches[1]); } } elseif(strstr(@$parts['host'], 'dailymotion') !== false) { // Dailymotion if(preg_match('/\/video\/([^_]+)/', @$parts['path'], $matches)) { $movie_url = array('type' => 'dailymotion', 'key' => $matches[1]); } } elseif(strstr(@$parts['host'], 'metacafe') !== false) { // Metacafe if(preg_match('/\/watch\/(.+)/', @$parts['path'], $matches)) { if(substr($matches[1], -1) == '/') $matches[1] = substr($matches[1], 0, -1); $movie_url = array('type' => 'metacafe', 'key' => $matches[1]); } } elseif(strstr(@$parts['host'], 'zideo') !== false) { // Zideo if(isset($parts['query'])) { $movie_url = array('type' => 'zideo', 'key' => $parts['query']); } } elseif(strstr(@$parts['host'], '123video') !== false) { // 123video if(preg_match('/MovieID=([0-9]+)/', @$parts['query'], $matches)) { $movie_url = array('type' => '123video', 'key' => $matches[1]); } } } if(is_array($movie_url)) { $movie_url = json_encode($movie_url); } else { $errors[] = 'This URL is not supported or malformed.'; } } else { $file_name = $_FILES['movie_filename']['name']; $file_type = $_FILES['movie_filename']['type']; $file_tmp = $_FILES['movie_filename']['tmp_name']; $file_name_array = explode('.', $file_name); $index = count($file_name_array)-1; $file_extension = $file_name_array[$index]; if(!in_array($file_extension, array('flv', 'FLV'))) { $errors[] = 'Wrong extension ('.$file_extension.').'; } if(!in_array($file_type, array('video/x-flv', 'application/octet-stream'))) { $errors[] = 'Wrong MIME type ('.$file_type.').'; } if(!sizeof($errors)) { $salt = md5(rand()); $path = '../userfiles/flv'; while(file_exists($path.'/'.$salt.'.'.$file_extension)) { $salt = md5(rand()); } $movie_filename = $salt.'.'.$file_extension; $move = true; } } if($_FILES['thumbnail']['tmp_name'] != '') { $thumb_name = $_FILES['thumbnail']['name']; $thumb_type = $_FILES['thumbnail']['type']; $thumb_tmp = $_FILES['thumbnail']['tmp_name']; $thumb_name_array = explode('.', $thumb_name); $index = count($thumb_name_array)-1; $thumb_extension = $thumb_name_array[$index]; if(!in_array($thumb_extension, array('gif', 'jpg', 'jpeg', 'png', 'GIF', 'JPG', 'JPEG', 'PNG'))) { $errors[] = 'Wrong extension ('.$thumb_extension.').'; } if(!in_array($thumb_type, array('image/gif', 'image/pjpeg', 'image/x-png', 'image/jpeg', 'image/png'))) { $errors[] = 'Wrong MIME type ('.$thumb_type.').'; } if(!sizeof($errors)) { $salt = md5(rand()); $path_thumb = '../userfiles/thumbs'; while(file_exists($path.'/'.$salt.'.'.$thumb_extension)) { $salt = md5(rand()); } $thumbnail = $salt.'.'.$thumb_extension; $save_thumb = true; } } else { $thumbnail = '__DEFAULT__'; } if(!sizeof($errors)) { $seo_url = friendlyURL($_POST['title']); $res = mysql_query("SELECT id FROM movies WHERE seo_url = '".escape($seo_url)."' LIMIT 1"); $i = 2; while(mysql_num_rows($res)) { $seo_url = friendlyURL($_POST['title'].'_'.$i); $res = mysql_query("SELECT id FROM movies WHERE seo_url = '".escape($seo_url)."' LIMIT 1"); $i++; } $res = mysql_query("INSERT INTO movies (category_id, title, seo_url, movie_url, movie_filename, thumbnail, date_added) VALUES (".escape($_POST['category_id']).", '".escape($_POST['title'])."', '".escape($seo_url)."', '".escape($movie_url)."', '".escape($movie_filename)."', '".escape($thumbnail)."', NOW())"); if($res) { $tpl->assign('success', true); if($move) { move_uploaded_file($file_tmp, $path.'/'.$movie_filename); } if($save_thumb) { $thumb = PhpThumbFactory::create($thumb_tmp); $thumb ->adaptiveResize(280, 210) ->save($path_thumb.'/'.$thumbnail); } if($movie_url != null) { $movie_url_array = json_decode($movie_url, true); $tpl->assign('movie_embed', getEmbedCode($movie_url_array['type'], $movie_url_array['key'])); } else { $tpl->assign('movie_filename', $movie_filename); } } else { $errors[] = 'Inserting failed due to database failure.'; } } if(sizeof($errors)) { $tpl->assign('errors', _htmlspecialchars($errors)); } } } elseif($do == 'edit' AND $seo != false) { $res = mysql_query("SELECT * FROM movies WHERE seo_url = '".escape($seo)."' LIMIT 1"); if(mysql_num_rows($res)) { $tpl->assign('movie_exists', true); $row = mysql_fetch_assoc($res); $res = mysql_query("SELECT id, title FROM categories ORDER BY title ASC"); if(mysql_num_rows($res)) { $categories = array(); while($c_row = mysql_fetch_assoc($res)) { $categories[$c_row['id']] = $c_row['title']; } $tpl->assign('categories', _htmlspecialchars($categories)); } if($row['movie_url'] != '') { $movie_url_array = json_decode($row['movie_url'], true); $row['movie_url'] = getMovieUrl($movie_url_array['type'], $movie_url_array['key']); $tpl->assign('movie_embed', getEmbedCode($movie_url_array['type'], $movie_url_array['key'])); $tpl->assign('movie_filename', false); } else { $tpl->assign('movie_embed', false); $tpl->assign('movie_filename', $row['movie_filename']); } if($row['thumbnail'] != '__DEFAULT__') { $tpl->assign('thumbnail', $row['thumbnail']); } else { $tpl->assign('thumbnail', $no_thumbnail_img); } $selectComments = mysql_query("SELECT * FROM comments WHERE movie_id = ".escape($row['id'])." ORDER BY date_added DESC"); if(@mysql_num_rows($selectComments)) { $commentsArray = array(); while($commentsRow = mysql_fetch_assoc($selectComments)) { $commentsArray[] = $commentsRow; } $tpl->assign('commentsArray', _htmlspecialchars($commentsArray)); } if($submit && isset($_POST['editVideo'])) { $errors = array(); $_POST['movie_filename'] = $row['movie_filename']; $tpl->assign('value', _htmlspecialchars($_POST)); if($_POST['title'] == '' OR strlen($_POST['title']) > 150) { $errors[] = 'Invalid title.'; } if(!array_key_exists($_POST['category_id'], $categories)) { $errors[] = 'Invalid category.'; } $movie_url = null; $movie_filename = null; $move = false; $save_thumb = false; if($_POST['movie_url'] != '') { if($parts = parse_url($_POST['movie_url'])) { if(strstr(@$parts['host'], 'youtube') !== false) { // YouTube if(preg_match('/v=([^&]+)/', @$parts['query'], $matches)) { $movie_url = array('type' => 'youtube', 'key' => $matches[1]); } } elseif(strstr(@$parts['host'], 'dailymotion') !== false) { // Dailymotion if(preg_match('/\/video\/([^_]+)/', @$parts['path'], $matches)) { $movie_url = array('type' => 'dailymotion', 'key' => $matches[1]); } } elseif(strstr(@$parts['host'], 'metacafe') !== false) { // Metacafe if(preg_match('/\/watch\/(.+)/', @$parts['path'], $matches)) { if(substr($matches[1], -1) == '/') $matches[1] = substr($matches[1], 0, -1); $movie_url = array('type' => 'metacafe', 'key' => $matches[1]); } } elseif(strstr(@$parts['host'], 'zideo') !== false) { // Zideo if(isset($parts['query'])) { $movie_url = array('type' => 'zideo', 'key' => $parts['query']); } } elseif(strstr(@$parts['host'], '123video') !== false) { // 123video if(preg_match('/MovieID=([0-9]+)/', @$parts['query'], $matches)) { $movie_url = array('type' => '123video', 'key' => $matches[1]); } } } if(is_array($movie_url)) { $movie_url = json_encode($movie_url); } else { $errors[] = 'This URL is not supported or malformed.'; } } else { if($_FILES['movie_filename']['tmp_name'] != '') { $file_name = $_FILES['movie_filename']['name']; $file_type = $_FILES['movie_filename']['type']; $file_tmp = $_FILES['movie_filename']['tmp_name']; $file_name_array = explode('.', $file_name); $index = count($file_name_array)-1; $file_extension = $file_name_array[$index]; if(!in_array($file_extension, array('flv', 'FLV'))) { $errors[] = 'Wrong extension ('.$file_extension.').'; } if(!in_array($file_type, array('video/x-flv', 'application/octet-stream'))) { $errors[] = 'Wrong MIME type ('.$file_type.').'; } if(!sizeof($errors)) { $salt = md5(rand()); $path = '../userfiles/flv'; while(file_exists($path.'/'.$salt.'.'.$file_extension)) { $salt = md5(rand()); } $movie_filename = $salt.'.'.$file_extension; $move = true; } } else { if($row['movie_filename'] == '') { $errors[] = 'Specify a movie (url or file).'; } else { // keep current $movie_filename = $row['movie_filename']; } } } if($_FILES['thumbnail']['tmp_name'] != '') { $thumb_name = $_FILES['thumbnail']['name']; $thumb_type = $_FILES['thumbnail']['type']; $thumb_tmp = $_FILES['thumbnail']['tmp_name']; $thumb_name_array = explode('.', $thumb_name); $index = count($thumb_name_array)-1; $thumb_extension = $thumb_name_array[$index]; if(!in_array($thumb_extension, array('gif', 'jpg', 'jpeg', 'png', 'GIF', 'JPG', 'JPEG', 'PNG'))) { $errors[] = 'Wrong extension ('.$thumb_extension.').'; } if(!in_array($thumb_type, array('image/gif', 'image/pjpeg', 'image/x-png', 'image/jpeg', 'image/png'))) { $errors[] = 'Wrong MIME type ('.$thumb_type.').'; } if(!sizeof($errors)) { $salt = md5(rand()); $path_thumb = '../userfiles/thumbs'; while(file_exists($path.'/'.$salt.'.'.$thumb_extension)) { $salt = md5(rand()); } $thumbnail = $salt.'.'.$thumb_extension; $save_thumb = true; } } else { $thumbnail = $row['thumbnail']; } if(!sizeof($errors)) { $seo_url = friendlyURL($_POST['title']); $res = mysql_query("SELECT id FROM movies WHERE seo_url = '".escape($seo_url)."' AND seo_url != '".escape($row['seo_url'])."' LIMIT 1"); $i = 2; while(mysql_num_rows($res)) { $seo_url = friendlyURL($_POST['title'].'_'.$i); $res = mysql_query("SELECT id FROM movies WHERE seo_url = '".escape($seo_url)."' AND seo_url != '".escape($row['seo_url'])."' LIMIT 1"); $i++; } $res = mysql_query("UPDATE movies SET category_id = ".escape($_POST['category_id']).", title = '".escape($_POST['title'])."', seo_url = '".escape($seo_url)."', movie_url = '".escape($movie_url)."', movie_filename = '".escape($movie_filename)."', thumbnail = '".escape($thumbnail)."' WHERE id = ".escape($row['id']).""); if($res) { $tpl->assign('success', true); $newRes = mysql_query("SELECT * FROM movies WHERE id = ".escape($row['id'])." LIMIT 1"); $newRow = mysql_fetch_assoc($newRes); if($newRow['movie_url'] != '') { $movie_url_array = json_decode($newRow['movie_url'], true); $newRow['movie_url'] = getMovieUrl($movie_url_array['type'], $movie_url_array['key']); $tpl->assign('movie_embed', getEmbedCode($movie_url_array['type'], $movie_url_array['key'])); $tpl->assign('movie_filename', false); } else { $tpl->assign('movie_embed', false); $tpl->assign('movie_filename', $newRow['movie_filename']); } if($newRow['thumbnail'] != '__DEFAULT__') { $tpl->assign('thumbnail', $newRow['thumbnail']); } else { $tpl->assign('thumbnail', $no_thumbnail_img); } $tpl->assign('value', _htmlspecialchars($newRow)); if($move) { move_uploaded_file($file_tmp, $path.'/'.$movie_filename); } if($save_thumb) { $thumb = PhpThumbFactory::create($thumb_tmp); $thumb ->adaptiveResize(280, 210) ->save($path_thumb.'/'.$thumbnail); } if(($movie_filename != $row['movie_filename']) AND $row['movie_filename'] != '') { // delete old flv when new one unlink('../userfiles/flv/' . $row['movie_filename']); } if(($thumbnail != $row['thumbnail']) AND $row['thumbnail'] != '__DEFAULT__') { // delete old thumb when new one unlink('../userfiles/thumbs/' . $row['thumbnail']); } } else { $errors[] = 'Updating failed due to database failure.'; } } if(sizeof($errors)) { $tpl->assign('errors', _htmlspecialchars($errors)); } } elseif($submit && isset($_POST['doEditComment'])) { foreach($_POST['doEditComment'] as $key => $val) { if(is_numeric($key)) { $res = mysql_query("UPDATE comments SET name = '".escape($_POST['name'][$key])."', message = '".escape($_POST['message'][$key])."' WHERE id = ".escape($key).""); } } header('Location: ' . $path . 'admin/videos/edit/' . $seo . '/'); exit(); } elseif($submit && isset($_POST['doDeleteComment'])) { foreach($_POST['doDeleteComment'] as $key => $val) { if(is_numeric($key)) { $res = mysql_query("DELETE FROM comments WHERE id = ".escape($key).""); } } header('Location: ' . $path . 'admin/videos/edit/' . $seo . '/'); exit(); } else { $tpl->assign('value', _htmlspecialchars($row)); } } } elseif($do == 'delete' AND $seo != false) { $res = mysql_query("SELECT id, movie_filename, thumbnail FROM movies WHERE seo_url = '".escape($seo)."'"); if(mysql_num_rows($res)) { $row = mysql_fetch_assoc($res); mysql_query("DELETE FROM movies WHERE id = ".$row['id'].""); if($row['movie_filename'] != '') { unlink('../userfiles/flv/' . $row['movie_filename']); } if($row['thumbnail'] != '__DEFAULT__') { unlink('../userfiles/thumbs/' . $row['thumbnail']); } } header('Location: ' . $path . 'admin/videos/'); exit(); } } $tpl->display('admin/videos.tpl'); ?> Let me know if there is anything else you need. And thanks for replying! Quote Link to comment Share on other sites More sharing options...
hesleskaug Posted February 24, 2010 Author Share Posted February 24, 2010 By the way: I've asked basic09 for help, but the don't do support on these requests. "'Note: For expansions and adjustments of one of our systems, please search for a php scripter or graphic designer on your favorite webmaster forums. For reporting a bug or mistake, you can contact us.' The reason why we do not make adjustments is because we are way to busy ourselves and we cannot handle all the requests." Quote Link to comment Share on other sites More sharing options...
hesleskaug Posted February 25, 2010 Author Share Posted February 25, 2010 No one? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.