Browse Source

- adding Tracking for Downloads and fixing last bugs in tracking and Routing

- Adding Download Class correctly with dynamic download function
- create 404 Not FPund Page and integrated it correctly
- include Facebook like Button
- fixing background for devices with 320px display width
pull-requests/1/from
Marcel Völkel 7 years ago
parent
commit
a5b55567aa

+ 1
- 1
Application/Config/router.php View File

@@ -1,3 +1,3 @@
1 1
 <?php
2 2
 $router->map('GET', '/', ROOT . DS . APP . '/Data/index.php', 'homePage');
3
-$router->map('GET', '/download/[*:trailing]', ROOT . DS . APP . '/Data/download.php', 'downloadLink');
3
+$router->map('GET', '/download/[a:controllerFile]/[*:version]?', ROOT . DS . APP . '/Data/download.php', 'downloadLink');

+ 33
- 2
Application/Data/download.php View File

@@ -1,7 +1,38 @@
1 1
 <?php
2 2
 
3
+use SCF\Core\DI;
4
+use SCF\Additionals\Tracking;
5
+use SCF\Additionals\Download;
3 6
 /**
4 7
  *  Download page for Downloads
5 8
  */
6
-//TODO: Create Download Logic with Download Class in scf/Additionals/Download.php
7
-var_dump($match);
9
+
10
+/**
11
+ * Tracking Settings set for Database logging of Downloads
12
+ * Please Remind that this only counts Click on DL Button, User can Cancel the Download
13
+ * and the system will still think it was a finished download
14
+ */
15
+$tracking = new Tracking(DI::getInstance()->get('db'));
16
+$tracking->setCurrentUserIp($_SERVER['REMOTE_ADDR']);
17
+$tracking->setCurrentUserAgent($_SERVER['HTTP_USER_AGENT']);
18
+
19
+/**
20
+ * Check if controllerFile is NOT the EuropeanFontPatch for DownloadTracking
21
+ */
22
+if ($match['params']['controllerFile'] != 'EuropeanFontPatch') {
23
+    $tracking->saveTrackingInDb('download', $settings->getValue('sks_download_version'));
24
+    $dlFile = $settings->getValue('sks_download_file');
25
+} else {
26
+    $dlFile = $settings->getValue('sks_eufont_file');
27
+}
28
+
29
+/**
30
+ * Set Needed Variables for the Download Class
31
+ */
32
+$dl = new Download();
33
+$dl->setAbsolutePath($settings->getValue('sks_download_path'));
34
+$dl->setFileName($dlFile);
35
+
36
+$dl->startDownloadFile();
37
+
38
+$tpl->display('index.tpl');

+ 22
- 0
Application/scf/Additionals/Download.php View File

@@ -52,5 +52,27 @@ class Download
52 52
         $this->absolutePath = $absolutePath;
53 53
     }
54 54
 
55
+    public function startDownloadFile()
56
+    {
57
+        $tmpPath = $this->getAbsolutePath();
58
+        $tmpFile = $this->getFileName();
59
+
60
+        $fh = fopen($tmpPath . $tmpFile, "r");
61
+        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
62
+        header('Content-Description: File Transfer');
63
+        header('Content-Type: application/octed-stream');
64
+        header('Content-Length: ' . @filesize($tmpPath . $tmpFile));
65
+        header("Content-Disposition: attachment; filename=" . $tmpFile);
66
+        header("Content-Transfer-Encoding: binary");
67
+
68
+        while (true) {
69
+            echo fgets($fh, 4096);
70
+            if (feof($fh)) break;
71
+            if (connection_status() != 0) break;
72
+        }
73
+        fclose($fh);
74
+
75
+    }
76
+
55 77
 //TODO: Finishing Download Class to generate correct Downloads for Page!
56 78
 }

+ 46
- 3
Application/scf/Additionals/Tracking.php View File

@@ -15,6 +15,8 @@ class Tracking
15 15
 
16 16
     private $currentUserReferer;
17 17
 
18
+    private $trackingTarget;
19
+
18 20
     public function __construct(Database $db)
19 21
     {
20 22
         $this->_db = $db;
@@ -70,14 +72,55 @@ class Tracking
70 72
 
71 73
     public function checkUniqueUser()
72 74
     {
73
-        $this->_db->query("SELECT ip_adress, `timestamp` FROM sks_unique_user WHERE ip_adress = '{$this->getCurrentUserIp()}' ORDER BY `timestamp` ASC LIMIT 1");
75
+        $this->_db->query("SELECT ip_adress, `timestamp` FROM sks_unique_user WHERE ip_adress = '{$this->getCurrentUserIp()}' ORDER BY `timestamp` DESC LIMIT 1");
74 76
         $result = $this->_db->single();
75 77
         $trackedDate = date("Y-m-d", $result['timestamp']);
76 78
         $currentDate = date("Y-m-d", time());
79
+        //echo $trackedDate . ' - ' . $currentDate;
77 80
         if ($trackedDate == $currentDate) {
78
-            echo 'same Day visit';
81
+            //echo 'Du warst heute um ' . date("H:i:s", $result['timestamp']) . ' Uhr schon einmal hier!';
79 82
         } else {
80
-            echo 'different Dates visit';
83
+            //echo 'different Dates visit';
84
+            $this->_db->query("INSERT INTO sks_unique_user (`ip_adress`, `user_agent`, `referrer`, `timestamp`) VALUES
85
+                                      (:ip, :userAgent, :userReferer, :timeValue)");
86
+            $this->_db->bind(':ip', $this->getCurrentUserIp());
87
+            $this->_db->bind(':userAgent', $this->getCurrentUserAgent());
88
+            $this->_db->bind(':userReferer', $this->getCurrentUserReferer());
89
+            $this->_db->bind(':timeValue', time());
90
+            $this->_db->execute();
91
+        }
92
+
93
+    }
94
+
95
+    /**
96
+     * @param mixed $trackingTarget
97
+     */
98
+    public function setTrackingTarget($trackingTarget)
99
+    {
100
+        $this->trackingTarget = $trackingTarget;
101
+    }
102
+
103
+    /**
104
+     * @return mixed
105
+     */
106
+    public function getTrackingTarget()
107
+    {
108
+        return $this->trackingTarget;
109
+    }
110
+
111
+    public function saveTrackingInDb($target, $dlVersion)
112
+    {
113
+        $tmpTarget = $target;
114
+        $tmpDlVersion = $dlVersion;
115
+        $timestamp = time();
116
+        if ($tmpTarget == 'download') {
117
+            try {
118
+                $this->_db->query("INSERT INTO `sks_unique_dls` (ip_adress, timestamp, user_agent, dl_version)
119
+                              VALUES ('{$this->getCurrentUserIp()}', '{$timestamp}', '{$this->getCurrentUserAgent()}', '{$tmpDlVersion}')");
120
+                $this->_db->execute();
121
+            } catch (\PDOException $e) {
122
+                echo $e->getMessage();
123
+            }
81 124
         }
82 125
 
83 126
     }

+ 13
- 0
Application/templates/sternenkindsaga/errorpages/404.tpl View File

@@ -1,3 +1,16 @@
1 1
 {include file="header.tpl"}
2
+<div class="row row-width">
3
+    <div class="col-lg-12 sks-not-found">
4
+        <h1>Huch!</h1>
5
+        <h2>404 Not Found</h2>
6
+        <p>
7
+            Die Information die Du aufrufen wolltest, existiert nicht. Gehe bitte wieder zurück auf die <a
8
+                    href="{$settings->getValue('siteaddr')}">Startseite</a>
9
+        </p>
10
+        <div class="clearfix"></div>
11
+    </div>
12
+</div>
13
+
14
+
2 15
 
3 16
 {include file="footer.tpl"}

+ 1
- 1
Application/templates/sternenkindsaga/html/htmlHead.tpl View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 <html lang="en">
4 4
 <head>
5
-    <title>{$settings->getValue("sitename")}</title>
5
+    <title>{$settings->getValue("sitename")|replace:'{1}':$settings->getValue("sks_download_version")}</title>
6 6
     <meta charset="utf-8">
7 7
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
8 8
     <meta name="viewport" content="width=device-width, initial-scale=1">

+ 13
- 6
Application/templates/sternenkindsaga/index.tpl View File

@@ -2,31 +2,38 @@
2 2
 <div class="row row-width">
3 3
     <div class="col-sm-7 less-padding sks-bottom-spacer">
4 4
         <div class="sks-box">
5
-            <strong>{$settings->getValue('lp_teaser_text_headline')}</strong>
5
+            <strong>{$settings->getValue('lp_teaser_text_headline')}</strong><br/>
6 6
             {$settings->getValue('lp_teaser_text')|nl2br}
7 7
         </div>
8 8
 
9 9
     </div>
10 10
     <div class="row">
11
-        <div class="col-sm-5 sks-bottom-spacer">
11
+        <div class="col-sm-offset-0 col-sm-5 sks-bottom-spacer">
12 12
             <div class="sks-box">
13 13
                 {include file="misc/carousel.tpl"}
14 14
                 <b> Erwecke jetzt das Sternenkind in dir!</b>
15
-                <button class="sks-download-button" id="sks-dl-button">Download</button>
15
+                <a href="download/SternenkindSaga/{$settings->getValue('sks_download_version')}">
16
+                    <button class="sks-download-button" id="sks-dl-button">Download</button>
17
+                </a>
16 18
             </div>
17 19
         </div>
18
-        <div class="col-sm-5 sks-bottom-spacer">
20
+        <div class="col-sm-offset-0 col-sm-5 sks-bottom-spacer">
19 21
             <div class="sks-box">
20 22
                 <strong>{$settings->getValue('sks_additional_files')}</strong><br/>
21 23
                 {$settings->getValue('sks_eu_patch')}
22 24
             </div>
23 25
         </div>
24
-        <div class="col-sm-5">
26
+        <div class="col-sm-offset-7 col-sm-5">
25 27
             <div class="sks-box">
26 28
                 <strong>{$settings->getValue('sks_social_media')}</strong><br/>
29
+                <div class="fb-like"
30
+                     data-href="https://www.facebook.com/pages/Sternenkind-Saga-Release-13122014/666851820057165"
31
+                     data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"
32
+                     style="float:right; margin-top:5px;"></div>
27 33
                 {$settings->getValue('sks_forum_link')}<br/>
28 34
                 {$settings->getValue('sks_facebook_link')}<br/>
29
-                {$settings->getValue('sks_homepage_link')}<br/>
35
+                {$settings->getValue('sks_homepage_link')}
36
+
30 37
             </div>
31 38
         </div>
32 39
     </div>

+ 1
- 0
bootstrap.php View File

@@ -47,4 +47,5 @@ $settings = new System(DI::getInstance()->get('db'));
47 47
 
48 48
 $router = DI::getInstance()->get('router');
49 49
 
50
+
50 51
 $tpl = new Templates($settings,$router);

+ 1
- 1
version View File

@@ -1 +1 @@
1
-v1.1.2
1
+v1.1.2 Rev: 2

+ 25
- 4
web/Styles/css/sks-v2.css View File

@@ -50,7 +50,7 @@ a:hover {
50 50
 }
51 51
 
52 52
 .row-width {
53
-    border: 1px solid #ffffff;
53
+
54 54
     width: 95%;
55 55
     max-width: 800px;
56 56
     margin: 20px auto 10px auto;
@@ -65,9 +65,18 @@ a:hover {
65 65
     margin-bottom: -10px;
66 66
 }
67 67
 
68
+.sks-not-found {
69
+    background: url("../images/sks-background.png") repeat;
70
+    border: 2px solid #e79b1f;
71
+    width: 100%;
72
+    color: #e79b1f;
73
+    margin: 5px auto 5px auto;
74
+    box-shadow: 0 5px 10px #000000;
75
+}
76
+
68 77
 .sks-dropdown {
69 78
     background: linear-gradient(#1f1a16, #4d3c32);
70
-    border: 1px solid #e79b1f;
79
+    border: 2px solid #e79b1f;
71 80
 }
72 81
 
73 82
 .sks-dropdown li a {
@@ -82,7 +91,7 @@ a:hover {
82 91
 }
83 92
 
84 93
 .sks-margin-bottom {
85
-    margin-bottom: 25%;
94
+    margin-bottom: 100px;
86 95
 }
87 96
 
88 97
 .sks-max-width {
@@ -121,7 +130,19 @@ a:hover {
121 130
     box-shadow: 0 5px 10px #000000;
122 131
 }
123 132
 
124
-@media only screen and (min-device-width: 375px) {
133
+.sks-small-text {
134
+    font-size: 80%;
135
+    margin: 0;
136
+    padding: 0;
137
+}
138
+
139
+.sks-center-text {
140
+    text-align: center;
141
+    margin: 0;
142
+    padding: 0;
143
+}
144
+
145
+@media only screen and (min-device-width: 320px) {
125 146
     body {
126 147
         background: #cfcfcf url('../images/sks-background.png') repeat;
127 148
     }

+ 4
- 2
web/index.php View File

@@ -14,20 +14,22 @@ require_once ROOT.DS.APP."/Config/router.php";
14 14
 $tpl->assign('sksscreens', $c->getPicArray());
15 15
 $match = $router->match();
16 16
 
17
+$userReferer = (!isset($_SERVER['HTTP_REFERER']) ? 'direct' : $_SERVER['HTTP_REFERER']);
17 18
 
18 19
 $tracking = DI::getInstance()->get('tracking');
19 20
 $tracking->setCurrentUserIp($_SERVER['REMOTE_ADDR']);
20 21
 $tracking->setCurrentUserAgent($_SERVER['HTTP_USER_AGENT']);
21
-$tracking->setCurrentUserReferer($_SERVER['HTTP_REFERER']);
22
+$tracking->setCurrentUserReferer($userReferer);
22 23
 $tracking->checkUniqueUser();
23
-
24 24
 if($match === false) {
25
+    var_dump($match);
25 26
     $tpl->display('errorpages/404.tpl');
26 27
 }
27 28
 else {
28 29
     try {
29 30
         require $match['target'];
30 31
     } catch(Exception $e) {
32
+        echo '3';
31 33
         return $e->getMessage();
32 34
     }
33 35
 }

+ 1
- 1
web/lib/sks.js View File

@@ -1,5 +1,5 @@
1 1
 $(document).ready(function () {
2 2
     $(".carousel").carousel({
3
-        interval: 2000
3
+        interval: 5000
4 4
     });
5 5
 });

Loading…
Cancel
Save