Mercurial > hg > fapweb
changeset 891:86ebd378af95
Modularize again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Nov 2014 20:04:18 +0200 |
parents | d6548ad68134 |
children | c036db2c64a7 |
files | msite.inc.php |
diffstat | 1 files changed, 44 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/msite.inc.php Wed Nov 26 19:47:59 2014 +0200 +++ b/msite.inc.php Wed Nov 26 20:04:18 2014 +0200 @@ -906,14 +906,14 @@ } -function stGetEntryPreviewFile($entry, $previewPath, $previewURL, $type, $addPath) +function stGetEntryPreviewFile($entry, $compo, $previewPath, $previewURL, $type, $addPath) { global $fileTypeData; if (!isset($fileTypeData[$type])) return stLogError("Invalid file type: ".$type); $fileBase = sprintf("%03d.%s", $entry["id"], $fileTypeData[$type]["fext"]); - $fileName = stMakePath(FALSE, TRUE, array($previewPath, $addPath, $fileBase)); + $fileName = stMakePath(FALSE, TRUE, array($previewPath, $compo["cpath"], $addPath, $fileBase)); return array( "type" => $type, @@ -921,56 +921,44 @@ "file" => $fileName, "exists" => @file_exists($fileName), "mtime" => @filemtime($fileName), - "url" => stMakePath(TRUE, TRUE, array($previewURL, $addPath, $fileBase)), + "url" => stMakePath(TRUE, TRUE, array($previewURL, $compo["cpath"], $addPath, $fileBase)), ); } -function stPrintPreviewElements($compo, $entry) +function stGetPreviewFileData($compo, $entry, &$pdata) { - if (($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["preview_id"])) === false) + if ($compo === false || $entry === false || + ($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["preview_id"])) === false) return FALSE; $previewPath = stGetSetting("previewPath"); $previewURL = stGetSetting("previewURL"); - $previewType = $compo["preview_type"]; - $previewOK = TRUE; + $pdata = array( + "type" => $compo["preview_type"], + "valid" => TRUE, + "files" => array(), + ); - switch ($previewType) + switch ($pdata["type"]) { case EPREV_IMAGE: - $sprev = stGetEntryPreviewFile( - $entry, $previewPath, $previewURL, + $pdata["files"]["image"] = stGetEntryPreviewFile( + $entry, $compo, $previewPath, $previewURL, stGetSetting("previewImageType"), ""); - $sthumb = stGetEntryPreviewFile( - $entry, $previewPath, $previewURL, + $pdata["files"]["thumb"] = stGetEntryPreviewFile( + $entry, $compo, $previewPath, $previewURL, stGetSetting("previewThumbType"), stGetSetting("thumbnailSubDir")); - - if ($sprev["exists"] === false || - $sthumb["exists"] === false || - $sprev["mtime"] < $efile["utime"] || - $sthumb["mtime"] < $efile["utime"]) - $previewOK = FALSE; break; case EPREV_AUDIO: - $sprev = array(); foreach (stGetSetting("sampleType") as $type) { - $sres = stGetEntryPreviewFile( - $entry, $previewPath, $previewURL, + $pdata["files"][$type] = stGetEntryPreviewFile( + $entry, $compo, $previewPath, $previewURL, $type, ""); - - if ($sres["exists"] === false || - $sres["mtime"] < $efile["utime"]) - { - $previewOK = FALSE; - break; - } - - $sprev[] = $sres; } break; @@ -978,10 +966,29 @@ return FALSE; } - switch ($previewType) + foreach ($pdata["files"] as $pkey => $pfile) + { + if ($pfile["exists"] === false || + $pfile["mtime"] < $efile["utime"]) + { + $pdata["valid"] = FALSE; + break; + } + } + + return TRUE; +} + + +function stPrintPreviewElements($compo, $entry) +{ + if (!stGetPreviewFileData($compo, $entry, $pdata)) + return FALSE; + + switch ($pdata["type"]) { case EPREV_IMAGE: - if (!$previewOK) + if (!$pdata["valid"]) { echo "<img class=\"imagePreview\" src=\"".stGetSetting("previewNoImage")."\" alt=\"Preview\" />"; @@ -989,18 +996,18 @@ else { echo - "<a href=\"".ihentities($sprev["url"]). - "\" onClick=\"return jsShowPreviewImage('".ihentities($sprev["url"])."');\">". - "<img class=\"imagePreview\" src=\"".ihentities($sthumb["url"]). + "<a href=\"".ihentities($pdata["files"]["image"]["url"]). + "\" onClick=\"return jsShowPreviewImage('".ihentities($pdata["files"]["image"]["url"])."');\">". + "<img class=\"imagePreview\" src=\"".ihentities($pdata["files"]["thumb"]["url"]). "\" alt=\"Preview\" /></a>"; } break; case EPREV_AUDIO: - if ($previewOK && count($sprev) > 0) + if ($pdata["valid"] && count($pdata["files"]) > 0) { echo "<audio controls preload=\"none\" class=\"audioPreview\">"; - foreach ($sprev as $pfile) + foreach ($pdata["files"] as $pkey => $pfile) { echo "<source src=\"".ihentities($pfile["url"])."\" type=\"".$pfile["mime"]."\">"; }