- Автор темы
- #1
Есть функция импорта медиа из YouTube, но она не рабочаяя, помагите откорегировать
и
функция из media.class.php
PHP:
private function media_import(){
// Get URL
if(isset($_GET["url"])){
$url = urldecode($_GET["url"]);
if(empty($url)) return Main::redirect(Main::ahref("media/import","",FALSE),array("danger","Please enter a valid URL."));
require(ROOT."/includes/Media.class.php");
$import = new Media();
$media = $import->import($url,"100%","500");
if(!isset($media->src)) return Main::redirect(Main::ahref("media/import","",FALSE),array("danger", "For some reason this video cannot be imported."));
// Return Error
if(isset($media->error)) return Main::redirect(Main::ahref("media/import","",FALSE),array("danger",$media->error));
Main::hook("admin_import_sidebar",array("Admin","media_import_hook"));
}
Main::set("title","Import Media");
$this->header();
include($this->t("import"));
$this->footer();
}
функция из media.class.php
PHP:
private function import_youtube(){
// Match Youtube Link
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $this->url, $match)) {
$id = $match[1];
}else{
return array("error" => "Sorry this video cannot be accessed for some reason.");
}
$json = @Main::http("http://gdata.youtube.com/feeds/api/videos/$id?v=2&alt=jsonc");
if(!$json) return array("error" => "Sorry this video cannot be accessed for some reason.");
$json = json_decode($json);
if($json->data->accessControl->embed !='allowed'){
return array("error" => "Sorry this video cannot be embedded because the author or the publisher prevented it.");
}
$this->data->title = $json->data->title;
$this->data->slug = Main::slug($this->data->title);
$this->data->id = $id;
$this->data->desc = Main::clean($json->data->description, 3, TRUE);
$this->data->thumb = "http://img.youtube.com/vi/$id/mqdefault.jpg";
$this->data->size = $this->size($this->data->thumb);
$this->data->tag = @implode(',',$json->data->tags);
$this->data->src = "//www.youtube-nocookie.com/embed/$id?showinfo=0&rel=0&iv_load_policy=3&modestbranding=1";
$this->data->import = "Youtube";
}