[Scummvm-git-logs] scummvm-web master -> a5722c8ca0e388b4ba8fd4b18a275e16917e196c

Mataniko mataniko at gmail.com
Thu May 9 06:40:37 CEST 2019


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm-web' repo located at https://github.com/scummvm/scummvm-web .

Summary:
00e5f875b6 TEMPLATES: Move recommended downloads to its own component
a5722c8ca0 WEB: Move the Recommended Download logic to the DownloadsModel


Commit: 00e5f875b65011bfe6ad586de617c0803b0ecaa7
    https://github.com/scummvm/scummvm-web/commit/00e5f875b65011bfe6ad586de617c0803b0ecaa7
Author: Matan Bareket (mataniko at gmail.com)
Date: 2019-05-08T23:57:26-04:00

Commit Message:
TEMPLATES: Move recommended downloads to its own component

Changed paths:
  A templates/components/recommended_download.tpl
    templates/pages/downloads.tpl


diff --git a/templates/components/recommended_download.tpl b/templates/components/recommended_download.tpl
new file mode 100644
index 0000000..04910e9
--- /dev/null
+++ b/templates/components/recommended_download.tpl
@@ -0,0 +1,13 @@
+<div id="recommended-download" class="{($recommendedDownload) ? 'visible':'hidden'}">
+  <div class="subhead">{#downloadsBadge#}</div>
+  <div class="subhead-content">
+    <div id="downloadContainer">
+      <a id="downloadButton" href={$recommendedDownload.url}>
+        <img src="images/scummvm.png" alt="Download ScummVM icon">
+        <div class="downloadText">Download ScummVM</div>
+        <div id="downloadDetails">Version {$recommendedDownload.ver} • {$recommendedDownload.os} • {$recommendedDownload.desc}</div>
+      </a>
+    </div>
+  </div>
+</div>
+<br>
diff --git a/templates/pages/downloads.tpl b/templates/pages/downloads.tpl
index 55e6010..dedb861 100644
--- a/templates/pages/downloads.tpl
+++ b/templates/pages/downloads.tpl
@@ -21,27 +21,14 @@
 	</div>
 {/capture}
 
-{capture "recommendedDownload"}
-		<div id="recommended-download" class="{($recommendedDownload) ? 'visible':'hidden'}">
-			<div class="subhead">{#downloadsBadge#}</div>
-			<div class="subhead-content">
-				<div id="downloadContainer">
-					<a id="downloadButton" href={$recommendedDownload.url}>
-						<img src="images/scummvm.png" alt="Download ScummVM icon">
-						<div class="downloadText">Download ScummVM</div>
-						<div id="downloadDetails">Version {$recommendedDownload.ver} • {$recommendedDownload.os} • {$recommendedDownload.desc}</div>
-					</a>
-				</div>
-			</div>
-		</div>
-		<br>
-{/capture}
-
 {foreach from=$downloads item=dsection name=downloads_loop}
 
   {capture "content"}
     {if $smarty.foreach.downloads_loop.first}
-      {$smarty.capture.recommendedDownload}
+      {include
+        file="components/recommended_download.tpl"
+        recommendedDownload=$recommendedDownload
+      }
     {/if}
 
     {foreach from=$dsection->getSubSections() item=dsubsection}


Commit: a5722c8ca0e388b4ba8fd4b18a275e16917e196c
    https://github.com/scummvm/scummvm-web/commit/a5722c8ca0e388b4ba8fd4b18a275e16917e196c
Author: Matan Bareket (mataniko at gmail.com)
Date: 2019-05-09T00:28:27-04:00

Commit Message:
WEB: Move the Recommended Download logic to the DownloadsModel

Changed paths:
    include/Models/DownloadsModel.php
    include/Pages/DownloadsPage.php


diff --git a/include/Models/DownloadsModel.php b/include/Models/DownloadsModel.php
index 9e00737..74aeb8f 100644
--- a/include/Models/DownloadsModel.php
+++ b/include/Models/DownloadsModel.php
@@ -3,6 +3,7 @@ namespace ScummVM\Models;
 
 use ScummVM\Objects\DownloadsSection;
 use ScummVM\XMLParser;
+use DeviceDetector\Parser\OperatingSystem AS OsParser;
 
 /**
  * The DownloadsModel will produce DownloadsSection objects.
@@ -56,4 +57,60 @@ abstract class DownloadsModel
         }
         return $sections;
     }
+
+    /* Get the recommended download */
+    public function getRecommendedDownload()
+    {
+        if (!isset($_SERVER['HTTP_USER_AGENT'])) {
+            return false;
+        }
+
+        $downloads = self::getAllDownloads();
+
+        $osParser = new OsParser();
+        $osParser->setUserAgent($_SERVER['HTTP_USER_AGENT']);
+        $os = $osParser->parse();
+
+        foreach ($downloads as $dsection) {
+            foreach ($dsection->getSubSections() as $dsubsection) {
+                $version = array_values(
+                    array_filter(
+                        $dsubsection->getItems(), function ($item) use ($os) {
+                            if ($item->getUserAgent() != "") {
+                                return preg_match("/({$item->getUserAgent()})/i", $os['name']);
+                            }
+                        }
+                    )
+                );
+
+                if ($version) {
+                    $curItem = $version[0];
+                    $url = str_replace('{$release}', RELEASE, $curItem->getURL());
+                    sscanf($url, "/frs/scummvm/%s", $versionStr);
+                    $version = substr($versionStr, 0, strpos($versionStr, "/"));
+                    $name = strip_tags($curItem->getName());
+                    $data = $curItem->getExtraInfo();
+                    if (is_array($data)) {
+                        $extra_text = $data['size'] . " ";
+                        if ($data['ext'] == '.exe') {
+                            $extra_text = $extra_text . 'Win32 ';
+                        }
+
+                        $extra_text .= $data['ext'] . " " . $data['msg'];
+                    } else {
+                        $extra_text = $data;
+                    }
+
+                    return array(
+                    'os' => $name,
+                    'ver' => $version,
+                    'desc' => $extra_text,
+                    'url' => $url,
+                    );
+                }
+            }
+        }
+
+        return false;
+    }
 }
diff --git a/include/Pages/DownloadsPage.php b/include/Pages/DownloadsPage.php
index bf932a6..7c2ec37 100644
--- a/include/Pages/DownloadsPage.php
+++ b/include/Pages/DownloadsPage.php
@@ -3,12 +3,9 @@ namespace ScummVM\Pages;
 
 use ScummVM\Controller;
 use ScummVM\Models\DownloadsModel;
-use DeviceDetector\Parser\OperatingSystem AS OsParser;
 
 class DownloadsPage extends Controller
 {
-
-
     /* Constructor. */
     public function __construct()
     {
@@ -16,65 +13,12 @@ class DownloadsPage extends Controller
         $this->template = 'pages/downloads.tpl';
     }
 
-    private function getRecommendedDownload($downloads)
-    {
-        if (!isset($_SERVER['HTTP_USER_AGENT'])) {
-            return false;
-        }
-
-        $osParser = new OsParser();
-        $osParser->setUserAgent($_SERVER['HTTP_USER_AGENT']);
-        $os = $osParser->parse();
-
-        foreach ($downloads as $dsection) {
-            foreach ($dsection->getSubSections() as $dsubsection) {
-                $version = array_values(
-                    array_filter(
-                        $dsubsection->getItems(), function ($item) use ($os) {
-                            if ($item->getUserAgent() != "") {
-                                return preg_match("/({$item->getUserAgent()})/i", $os['name']);
-                            }
-                        }
-                    )
-                );
-
-                if ($version) {
-                    $curItem = $version[0];
-                    $url = str_replace('{$release}', RELEASE, $curItem->getURL());
-                    sscanf($url, "/frs/scummvm/%s", $versionStr);
-                    $version = substr($versionStr, 0, strpos($versionStr, "/"));
-                    $name = strip_tags($curItem->getName());
-                    $data = $curItem->getExtraInfo();
-                    if (is_array($data)) {
-                        $extra_text = $data['size'] . " ";
-                        if ($data['ext'] == '.exe') {
-                            $extra_text = $extra_text . 'Win32 ';
-                        }
-
-                        $extra_text .= $data['ext'] . " " . $data['msg'];
-                    } else {
-                        $extra_text = $data;
-                    }
-
-                    return array(
-                    'os' => $name,
-                    'ver' => $version,
-                    'desc' => $extra_text,
-                    'url' => $url,
-                    );
-                }
-            }
-        }
-
-        return false;
-    }
-
     /* Display the index page. */
     public function index()
     {
         $downloads = DownloadsModel::getAllDownloads();
         $sections = DownloadsModel::getAllSections();
-        $recommendedDownload = $this->getRecommendedDownload($downloads);
+        $recommendedDownload = DownloadsModel::getRecommendedDownload();
         return $this->renderPage(
             array(
                 'title' => $this->getConfigVars('downloadsTitle'),





More information about the Scummvm-git-logs mailing list