function ajaxGetYoutubeUrl() { Configure::write('debug', 0); $this->layout = false; $userID = $this->getUserID(); App::import('Vendor', 'YouTube', array('file' => 'class.YouTube.php')); $VideoTube = new YouTube(); $title = $description = ''; if (!empty($_REQUEST['title'])) { $title = trim($_REQUEST['title']); } if (!empty($_REQUEST['description'])) { $description = trim($_REQUEST['description']); } $youTubeUrl = $VideoTube->getUploadUrl($title, $description); $albumID = intval($_REQUEST['album_id']); if (!$albumID) { $albumID = $this->Video->Album->getJunkId($userID); } $newVideo = array(); $newVideo['model'] = 'Album'; $newVideo['model_id'] = $albumID; $newVideo['user_id'] = $this->getUserID(); $newVideo['title'] = $title; $newVideo['description'] = $description; $newVideo['is_processed'] = 0; $newVideo['is_deleted'] = 1; $newVideo['is_file'] = 1; $newVideo['tags'] = $_REQUEST['tags']; if (!empty($youTubeUrl)) { $this->Video->create(); $this->Video->save($newVideo); $id = $this->Video->getLastInsertID(); $youTubeUrl['url'] .= '?nexturl=http://' . $_SERVER['HTTP_HOST'] . '/videos/youTubeUploaderBack/' . $id . '/'; $youTubeUrl['id'] = $id; exit($this->Json->encode($youTubeUrl)); } else { exit; } }