changeset 774:d6668b73bb01

Modularize preview HTML stuff into a function stPrintPreviewElements().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Nov 2014 15:38:33 +0200
parents 133197d0e48a
children 62a98cb255f7
files msite.inc.php pages/vote.inc.php
diffstat 2 files changed, 39 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/msite.inc.php	Thu Nov 20 14:56:44 2014 +0200
+++ b/msite.inc.php	Thu Nov 20 15:38:33 2014 +0200
@@ -726,6 +726,44 @@
 }
 
 
+function stPrintPreviewElements($compo, $entry)
+{
+  if (($pdata = stGetEntryPreviewData($compo, $entry, FALSE, TRUE)) === FALSE)
+    return 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"]).
+          "\" onClick=\"jsShowPreviewImage('".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;
+  }
+
+  return TRUE;
+}
+
+
 // Get link helper function
 function stGetMainPageLink($id, $name, $show = TRUE)
 {
--- a/pages/vote.inc.php	Thu Nov 20 14:56:44 2014 +0200
+++ b/pages/vote.inc.php	Thu Nov 20 15:38:33 2014 +0200
@@ -150,38 +150,7 @@
           "   <td class=\"ventry\">\n".
           "    <div class=\"vpreview\">";
 
-        // 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"]).
-                  "\" onClick=\"jsShowPreviewImage('".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;
-          }
-        }
+        stPrintPreviewElements($compo, $entry);
 
         echo
           "</div>\n".