Exemplo n.º 1
0
 public function getInfo($name, &$err)
 {
     if (0 === strpos($name, 'http://') || 0 === strpos($name, 'https://')) {
         if (false !== ($youTubeId = YouTubeTool::getId($name))) {
             if (null !== $this->apiKey) {
                 $v = YouTubeVideo::create()->setVideoId($youTubeId)->setApiKey($this->apiKey);
                 $iframe = '<iframe src="https://www.youtube.com/embed/' . $youTubeId . '" frameborder="0" allowfullscreen></iframe>';
                 return ['type' => 'youtube', 'title' => $v->getTitle(), 'description' => nl2br($v->getDescription()), 'duration' => $v->getDuration(), 'thumbnail' => $v->getThumbnail(), 'iframe' => $iframe];
             } else {
                 $err = "YouTubeInfoHandler: YouTube api key not set";
             }
         }
     }
     return false;
 }
Exemplo n.º 2
0
function colis_get_info_by_name($name)
{
    $type = 'none';
    $ext = strtolower(FileSystemTool::getFileExtension($name));
    $ext2Type = ['jpg' => 'image', 'jpeg' => 'image', 'gif' => 'image', 'png' => 'image', 'mp4' => 'video'];
    if (array_key_exists($ext, $ext2Type)) {
        $type = $ext2Type[$ext];
    }
    $finalName = null;
    if (0 === strpos($name, 'http://') || 0 === strpos($name, 'https://')) {
        $finalName = $name;
        // handling youtube urls
        if ('video' === $type) {
            $type = 'externalVideo';
        } elseif (false !== ($youTubeId = YouTubeTool::getId($finalName))) {
            $type = 'youtube';
        }
    } else {
        // look for a file named name in a specific dir...
        $finalName = ITEMS_DIR_URL . '/' . $name;
    }
    switch ($type) {
        case 'image':
            return ['type' => $type, 'src' => $finalName];
            break;
        case 'youtube':
            $v = YouTubeVideo::create()->setVideoId($youTubeId)->setApiKey(YOUTUBE_API_KEY);
            $iframe = '<iframe src="https://www.youtube.com/embed/' . $youTubeId . '" frameborder="0" allowfullscreen></iframe>';
            return ['type' => $type, 'title' => $v->getTitle(), 'description' => nl2br($v->getDescription()), 'duration' => $v->getDuration(), 'thumbnail' => $v->getThumbnail(), 'iframe' => $iframe];
            break;
        case 'externalVideo':
            $realPath = WEB_ROOT_DIR . $finalName;
            return ['type' => $type, 'src' => $finalName];
            break;
        case 'video':
            $realPath = WEB_ROOT_DIR . $finalName;
            $duration = getVideoDuration($realPath);
            return ['type' => 'localVideo', 'src' => $finalName, 'duration' => $duration];
            break;
        default:
            return ["type" => $type];
            break;
    }
}