예제 #1
0
 public function renderOverview()
 {
     global $siteWebRoot, $siteTitle, $baseDir, $dateMask, $overviewTitleTemplate, $overviewRowTemplate, $useNiceUrls, $latestUpdate;
     $latestUpdate = $this->latestUpdate;
     ob_start();
     foreach ($this->gallerydata as $gallery) {
         $thumb = generateThumbnail($gallery->thumbnail, $gallery->path);
         $path = $useNiceUrls ? sprintf('%s/gallery/%s', $siteWebRoot, $gallery->safename) : sprintf('%s/?galleryID=%s', $siteWebRoot, $gallery->safename);
         // Skip non-public, empty and titleless galleries in the thumbnail view
         if (!is_null($gallery->hidden) || count($gallery->files) == 0 || is_null($gallery->title)) {
             continue;
         }
         if (!is_null($thumb)) {
             $compiledTitle = $overviewTitleTemplate;
             $compiledTitle = str_replace('GALLERYTITLE', $gallery->title, $compiledTitle);
             $compiledTitle = str_replace('GALLERYUPDATED', date($dateMask, $gallery->mtime), $compiledTitle);
             $compiledTitle = str_replace('GALLERYNUMIMAGES', count($gallery->files), $compiledTitle);
             $row = $overviewRowTemplate;
             $row = str_replace('GALLERYURL', $path, $row);
             $row = str_replace('IMGSRC', sprintf("%s%s", $siteWebRoot, $thumb), $row);
             $row = str_replace('GALLERYTITLE', $compiledTitle, $row);
             $row = str_replace('ALTTXT', '', $row);
             print $row;
         } else {
             printf("<!-- %s: %s (%s) -->", "Could not get thumbnail for gallery", $gallery->title, $gallery->path);
         }
     }
     $this->output = ob_get_clean();
 }
예제 #2
0
파일: uservoice.php 프로젝트: raykai/porter
 /**
  * Avatars are hex-encoded in the database.
  */
 public function exportHexAvatars($thumbnail = true)
 {
     $this->ex->comment("Exporting hex encoded columns...");
     $result = $this->ex->query("select UserID, Length, ContentType, Content from :_UserAvatar");
     $path = '/www/porter/userpics';
     $count = 0;
     while ($row = mysql_fetch_assoc($result)) {
         // Build path
         if (!file_exists(dirname($path))) {
             $r = mkdir(dirname($path), 0777, true);
             if (!$r) {
                 die("Could not create " . dirname($path));
             }
         }
         $photoPath = $path . '/pavatar' . $row['UserID'] . '.jpg';
         file_put_contents($photoPath, hex2bin($row['Content']));
         $this->ex->status('.');
         if ($thumbnail) {
             if ($thumbnail === true) {
                 $thumbnail = 50;
             }
             //$PicPath = str_replace('/avat', '/pavat', $photoPath);
             $thumbPath = str_replace('/pavat', '/navat', $photoPath);
             generateThumbnail($photoPath, $thumbPath, $thumbnail, $thumbnail);
         }
         $count++;
     }
     $this->ex->status("{$count} Hex Encoded.\n");
     $this->ex->comment("{$count} Hex Encoded.", false);
 }
예제 #3
0
function analyzeMediaFile(&$metaData, $filePath = NULL, $cachePath = NULL)
{
    if (!isset($metaData->fileName) || !isset($metaData->fileType)) {
        throw new Exception("meta data invalid");
    }
    $file = $filePath . DIRECTORY_SEPARATOR . $metaData->fileName;
    if (!is_file($file) || !is_readable($file)) {
        throw new Exception("file does not exist");
    }
    if (!is_dir($cachePath)) {
        throw new Exception("cache dir does not exist");
    }
    switch ($metaData->fileType) {
        case "video/quicktime":
        case "application/ogg":
        case "audio/mpeg":
        case "video/mp4":
        case "video/x-msvideo":
        case "video/ogg":
        case "video/webm":
        case "video/x-ms-asf":
        case "video/x-flv":
        case "audio/x-wav":
        case "application/octet-stream":
            if (isMediaFile($metaData, $filePath)) {
                $media = new ffmpeg_movie($file, FALSE);
                /****************************************************
                 * VIDEO
                 ****************************************************/
                if ($media->hasVideo()) {
                    $metaData->video->codec = $media->getVideoCodec();
                    $metaData->video->width = $media->getFrameWidth();
                    $metaData->video->height = $media->getFrameHeight();
                    $metaData->video->bitrate = $media->getVideoBitRate();
                    $metaData->video->framerate = $media->getFrameRate();
                    $metaData->video->duration = $media->getDuration();
                    /* Video Still */
                    $stillFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png";
                    $fc = (int) ($media->getFrameCount() / 32);
                    /* frame count is not necessarily reliable! */
                    foreach (array($fc, 100, 10, 1) as $fno) {
                        if ($fno == 0) {
                            continue;
                        }
                        $f = $media->getFrame($fno);
                        if ($f !== FALSE) {
                            imagepng($f->toGDImage(), $stillFile);
                            $metaData->video->still = basename($stillFile);
                            break;
                        }
                    }
                    /* Video Thumbnails */
                    $thumbSizes = array(90, 180, 360);
                    foreach ($thumbSizes as $tS) {
                        $thumbFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png";
                        list($thumb_width, $thumb_height) = generateThumbnail($stillFile, $thumbFile, $tS);
                        $metaData->video->thumbnail->{$tS}->file = basename($thumbFile);
                        $metaData->video->thumbnail->{$tS}->width = $thumb_width;
                        $metaData->video->thumbnail->{$tS}->height = $thumb_height;
                    }
                    /* Schedule for transcoding */
                    $transcodeSizes = array(360);
                    $metaData->transcodeStatus = 'WAITING';
                    $metaData->transcodeProgress = 0;
                    foreach ($transcodeSizes as $tS) {
                        $transcodeFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".webm";
                        list($width, $height) = scaleVideo($media->getFrameWidth(), $media->getFrameHeight(), $tS);
                        $metaData->video->transcode->{$tS}->file = basename($transcodeFile);
                        $metaData->video->transcode->{$tS}->width = $width;
                        $metaData->video->transcode->{$tS}->height = $height;
                    }
                }
                /****************************************************
                 * AUDIO
                 ****************************************************/
                if ($media->hasAudio()) {
                    $metaData->audio->codec = $media->getAudioCodec();
                    $metaData->audio->bitrate = $media->getAudioBitRate();
                    $metaData->audio->samplerate = $media->getAudioSampleRate();
                    $metaData->audio->duration = $media->getDuration();
                    $metaData->transcodeStatus = 'WAITING';
                    $metaData->transcodeProgress = 0;
                    $transcodeFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".ogg";
                    $metaData->audio->transcode->file = basename($transcodeFile);
                }
            } else {
                /* No media? */
            }
            break;
        case "image/jpeg":
        case "image/png":
        case "image/gif":
        case "image/bmp":
            list($width, $height) = getimagesize($file);
            $metaData->image->width = $width;
            $metaData->image->height = $height;
            $thumbFile = $cachePath . DIRECTORY_SEPARATOR . uniqid("ft_") . ".png";
            list($thumb_width, $thumb_height) = generateThumbnail($file, $thumbFile, 360);
            $metaData->image->thumbnail->{360}->file = basename($thumbFile);
            $metaData->image->thumbnail->{360}->width = $thumb_width;
            $metaData->image->thumbnail->{360}->height = $thumb_height;
            break;
        default:
            /* no idea about this file, let it go... */
    }
}
예제 #4
0
 /**
  * Convert database blobs into files.
  *
  * @param $sql
  * @param $blobColumn
  * @param $pathColumn
  * @param bool $thumbnail
  */
 public function exportBlobs($sql, $blobColumn, $pathColumn, $thumbnail = false)
 {
     $this->comment("Exporting blobs...");
     $result = $this->query($sql);
     $count = 0;
     while ($row = mysql_fetch_assoc($result)) {
         // vBulletin attachment hack (can't do this in MySQL)
         if (strpos($row[$pathColumn], '.attach') && strpos($row[$pathColumn], 'attachments/') !== false) {
             $pathParts = explode('/', $row[$pathColumn]);
             // 3 parts
             // Split up the userid into a path, digit by digit
             $n = strlen($pathParts[1]);
             $dirParts = array();
             for ($i = 0; $i < $n; $i++) {
                 $dirParts[] = $pathParts[1][$i];
             }
             $pathParts[1] = implode('/', $dirParts);
             // Rebuild full path
             $row[$pathColumn] = implode('/', $pathParts);
         }
         $path = $row[$pathColumn];
         // Build path
         if (!file_exists(dirname($path))) {
             $r = mkdir(dirname($path), 0777, true);
             if (!$r) {
                 die("Could not create " . dirname($path));
             }
         }
         if ($thumbnail) {
             $picPath = str_replace('/avat', '/pavat', $path);
             $fp = fopen($picPath, 'wb');
         } else {
             $fp = fopen($path, 'wb');
         }
         if (!is_resource($fp)) {
             die("Could not open {$path}.");
         }
         fwrite($fp, $row[$blobColumn]);
         fclose($fp);
         $this->status('.');
         if ($thumbnail) {
             if ($thumbnail === true) {
                 $thumbnail = 50;
             }
             $thumbPath = str_replace('/avat', '/navat', $path);
             generateThumbnail($picPath, $thumbPath, $thumbnail, $thumbnail);
         }
         $count++;
     }
     $this->status("{$count} Blobs.\n");
     $this->comment("{$count} Blobs.", false);
 }
예제 #5
0
function processLinks($conn, $row, $href, $imgLink, $title, $time, &$imgIndex, $resizeImages, $imageGIF = false, $saveImage = true)
{
    // Alguns links começam com "//"
    if (startsWith($href, "//") === FALSE) {
        // O link é relativo e não absoluto
        if (!startsWith($href, "http") || $href[0] == "/") {
            $urlTokens[] = explode("/", $row["SITE"]);
            $href = $urlTokens[0][0] . "//" . $urlTokens[0][2] . ($href[0] == "/" ? $href : "/{$href}");
            unset($urlTokens);
        }
    }
    // Alguns endreços de imagem começam com "//". Nesses casos, acrescento a string "http:"
    if ($saveImage && $imgLink[0] == "/" && $imgLink[1] == "/") {
        $imgLink = "http:" . $imgLink;
    }
    // Link de imagem relativo
    if ($saveImage && !startsWith($imgLink, "http")) {
        $urlTokens[] = explode("/", $row["SITE"]);
        $imgLink = $urlTokens[0][0] . "//" . $urlTokens[0][2] . "/{$imgLink}";
        unset($urlTokens);
    }
    // Verifica se o link já está cadastrado no banco de dados
    $sql = "SELECT ID FROM IMAGENS WHERE LINK = :link";
    $stmtLink = $conn->prepare($sql);
    $stmtLink->bindValue(":link", $href, PDO::PARAM_STR);
    $stmtLink->execute();
    $resultLinks = $stmtLink->fetchAll(PDO::FETCH_ASSOC);
    // Se o link não estiver adastrado...
    if (empty($resultLinks)) {
        if ($saveImage) {
            // Gera o nome da imagem antes de gravar na base
            if (stristr($imgLink, ".jpg") || stristr($imgLink, ".jpeg")) {
                $formato = ".jpg";
            } else {
                if (stristr($imgLink, ".png")) {
                    $formato = ".png";
                } else {
                    if ($imageGIF && stristr($imgLink, ".gif")) {
                        $formato = ".gif";
                    } else {
                        return;
                    }
                }
            }
            $pasta = $time . "/";
            $nomeImagem = $pasta . $row["ID_SITE"] . $imgIndex++ . $formato;
        } else {
            $nomeImagem = $imgLink;
        }
        // Grava os dados do link e imagem no banco de dados. Se houver algum erro, dá rollback
        try {
            $conn->beginTransaction();
            $sql = "INSERT INTO IMAGENS (SITE_ID, LINK, ALT, CAMINHO_IMAGEM) VALUES (:site, :link, :alt, :imagem)";
            $stmtLink = $conn->prepare($sql);
            $stmtLink->bindValue(":site", $row["ID_SITE"], PDO::PARAM_INT);
            $stmtLink->bindValue(":link", $href, PDO::PARAM_STR);
            $stmtLink->bindValue(":alt", trim($title) == "" ? $row["CATEGORIA"] : $title, PDO::PARAM_STR);
            $stmtLink->bindValue(":imagem", $nomeImagem, PDO::PARAM_STR);
            $stmtLink->execute();
            if ($saveImage) {
                // Cria o arquivo com a imagem
                $fileStatus = createImage($nomeImagem, file_get_contents($imgLink));
                if ($resizeImages) {
                    // Cria o thumbnail da imagem
                    generateThumbnail($nomeImagem);
                }
                if ($fileStatus === FALSE) {
                    throw new Exception("Erro ao criar imagem");
                }
            }
            $conn->commit();
            echo $row["ID_SITE"] . " - {$href}: <span style='color:blue'>IMPORTADO</span><br />\n";
            return true;
        } catch (Exception $exc) {
            $conn->rollBack();
            echo $row["ID_SITE"] . " - {$href}: <span style='color:red'>ERRO: " . $exc->getMessage() . " - {$imgLink}</span><br />\n";
            return false;
        }
    } else {
        //echo $row["ID_SITE"] . " - $href: <span style='color:orange'>EXISTENTE</span><br />\n";
        return false;
    }
}