Mercurial > hg > fapweb
changeset 721:69a829f687a9
Preliminary work for entry previews.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 18 Nov 2014 19:19:10 +0200 |
parents | 4f334b3c884f |
children | bf33cec02dc6 |
files | msite.inc.php pages/vote.inc.php |
diffstat | 2 files changed, 113 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/msite.inc.php Thu Nov 13 09:30:40 2014 +0200 +++ b/msite.inc.php Tue Nov 18 19:19:10 2014 +0200 @@ -640,6 +640,87 @@ } +function stMakePath($isURL, $repExt, $components) +{ + return implode("/", $components); +} + + +function stGetEntryPreviewData($compo, $entry, $probePreview, $fullData) +{ + $res = array(); + $entryStore = stGetSetting("entryStore"); + $entryPreviews = stGetSetting("entryPreviews"); + $entryURL = stGetSetting("entryURL"); + $thumbDir = stGetSetting("thumbnailSubDir"); + + // Data for the actual entry file + $res["previewType"] = ($entry["preview_type"] != EPREV_NONE) ? $entry["preview_type"] : $compo["preview_type"]; + $res["entryFile"] = stMakePath(FALSE, FALSE, array($entryStore, $compo["cpath"], $entry["filename"])); + if ($fullData) + { + $res["entrySize"] = @filesize($res["entryFile"]); + } + + // Based on preview type, set some basics + switch ($res["previewType"]) + { + case EPREV_IMAGE: + $res["fileBase"] = stMakePath(FALSE, "_sshot", array($entry["filename"])); + $res["preferType"] = "PNG"; + $fileTypeList = array( + "PNG" => array(".png", ".PNG"), + "GIF" => array(".gif", ".GIF"), + "JPEG" => array(".jpg", ".JPG"), + ); + break; + + case EPREV_AUDIO: + $res["fileBase"] = stMakePath(FALSE, "_sample", array($entry["filename"])); + $res["preferType"] = "PNG"; + $fileTypeList = array( + "MP3" => array(".mp3", ".MP3"), + "OGG" => array(".ogg", ".OGG", ".oga", ".OGA"), + ); + break; + + default: + return FALSE; + } + + // Find the preview file(s) + foreach ($fileTypeList as $ftype => $fexts) + { + foreach ($fexts as $fext) + { + $filename = stMakePath(FALSE, $fext, array($entryPreviews, $compo["cpath"], $res["fileBase"])); + if ($probePreview == FALSE || file_exists($filename)) + { + $res["previewFileType"] = $ftype; + $res["previewPath"] = $filename; + $res["previewURL"] = stMakePath(TRUE, $fext, array($entryURL, $compo["cpath"], $res["fileBase"])); + + if ($res["previewType"] == EPREV_IMAGE) + { + $res["thumbPath"] = stMakePath(TRUE, $fext, array($entryPreviews, $compo["cpath"], $thumbDir, $res["fileBase"])); + $res["thumbURL"] = stMakePath(TRUE, $fext, array($entryURL, $compo["cpath"], $thumbDir, $res["fileBase"])); + } + + if ($fullData) + { + $res["previewSize"] = @filesize($res["previewPath"]); + $res["thumbSize"] = @filesize($res["thumbPath"]); + } + + return $res; + } + } + } + + return FALSE; +} + + // Get link helper function function stGetMainPageLink($id, $name, $show = TRUE) {
--- a/pages/vote.inc.php Thu Nov 13 09:30:40 2014 +0200 +++ b/pages/vote.inc.php Tue Nov 18 19:19:10 2014 +0200 @@ -152,6 +152,38 @@ " <div class=\"vpreview\">\n". " "; + // The preview type can be overriden by the entry + if (($pdata = stGetEntryPreviewData($compo, $entry, FALSE, TRUE)) !== false) + { + switch ($pdata["previewType"]) + { + case EPREV_IMAGE: + if ($pdata["previewSize"] === FALSE || $pdata["thumbSize"] === FALSE) + { + echo + "<img class=\"imagePreview\" src=\"img/nopreview_tn.png\" alt=\"Preview\"/>"; + } + else + { + echo + "<a href=\"".ihentities($pdata["previewURL"])."\">". + "<img class=\"imagePreview\" src=\"".ihentities($pdata["thumbURL"]). + "\" alt=\"Preview\"/></a>"; + } + break; + + case EPREV_AUDIO: + if ($pdata["previewSize"] !== FALSE) + { + echo + "<audio controls class=\"audioPreview\">". + "<source src=\"".ihentities($pdata["previewURL"])."\" type=\"audio/mpeg\">-". + "</audio>"; + } + break; + } + } + echo " </div>\n". " <div class=\"vinfo\">".