Skip to content

Commit bf14726

Browse files
committed
Basic infrastructure
0 parents  commit bf14726

15 files changed

+240
-0
lines changed

New/CHOICES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1- Hangman: based on http://www.huntingground.freeserve.co.uk/main/mainfram.htm?../games/hangman/hangman1.htm
2+
2- Web application, no widget
3+
3- Use different images,

New/Mobile_Detect.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
/**
4+
* Mobile Detect
5+
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
6+
*/
7+
class Mobile_Detect
8+
{
9+
10+
protected $accept;
11+
protected $userAgent;
12+
protected $isMobile = false;
13+
protected $isAndroid = null;
14+
protected $isAndroidtablet = null;
15+
protected $isIphone = null;
16+
protected $isIpad = null;
17+
protected $isBlackberry = null;
18+
protected $isOpera = null;
19+
protected $isPalm = null;
20+
protected $isWindows = null;
21+
protected $isWindowsphone = null;
22+
protected $isGeneric = null;
23+
protected $devices = array(
24+
"android" => "android.*mobile",
25+
"androidtablet" => "android(?!.*mobile)",
26+
"blackberry" => "blackberry",
27+
"blackberrytablet" => "rim tablet os",
28+
"iphone" => "(iphone|ipod)",
29+
"ipad" => "(ipad)",
30+
"palm" => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)",
31+
"windows" => "windows ce; (iemobile|ppc|smartphone)",
32+
"windowsphone" => "windows phone os",
33+
"generic" => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap|opera mini)"
34+
);
35+
36+
public function __construct()
37+
{
38+
$this->userAgent = $_SERVER['HTTP_USER_AGENT'];
39+
$this->accept = $_SERVER['HTTP_ACCEPT'];
40+
41+
if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
42+
$this->isMobile = true;
43+
} elseif (strpos($this->accept, 'text/vnd.wap.wml') > 0 || strpos($this->accept, 'application/vnd.wap.xhtml+xml') > 0) {
44+
$this->isMobile = true;
45+
} else {
46+
foreach ($this->devices as $device => $regexp) {
47+
if ($this->isDevice($device)) {
48+
$this->isMobile = true;
49+
}
50+
}
51+
}
52+
}
53+
54+
/**
55+
* Overloads isAndroid() | isAndroidtablet() | isIphone() | isIpad() | isBlackberry() | isBlackberrytablet() | isPalm() | isWindowsphone() | isWindows() | isGeneric() through isDevice()
56+
*
57+
* @param string $name
58+
* @param array $arguments
59+
* @return bool
60+
*/
61+
public function __call($name, $arguments)
62+
{
63+
$device = substr($name, 2);
64+
if ($name == "is" . ucfirst($device) && array_key_exists(strtolower($device), $this->devices)) {
65+
return $this->isDevice($device);
66+
} else {
67+
trigger_error("Method $name not defined", E_USER_WARNING);
68+
}
69+
}
70+
71+
/**
72+
* Returns true if any type of mobile device detected, including special ones
73+
* @return bool
74+
*/
75+
public function isMobile()
76+
{
77+
return $this->isMobile;
78+
}
79+
80+
protected function isDevice($device)
81+
{
82+
$var = "is" . ucfirst($device);
83+
$return = $this->$var === null ? (bool) preg_match("/" . $this->devices[strtolower($device)] . "/i", $this->userAgent) : $this->$var;
84+
if ($device != 'generic' && $return == true) {
85+
$this->isGeneric = false;
86+
}
87+
88+
return $return;
89+
}
90+
91+
}

New/cookie_management.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/**
4+
* File containing the cookie management
5+
*
6+
* It tries to detect the device and sets a cookie.
7+
* If there is a request for a specific page, the cookie is forced
8+
*/
9+
10+
function cookie_management()
11+
{
12+
$DOMAIN = $GLOBALS['DOMAIN'];
13+
14+
#if there is a request to view the page in a particular way, I override the cookie in any case
15+
# so that I bypass the browser detection
16+
17+
#I need another variable if I set the cookie here
18+
$COOKIE_EXSISTS = FALSE;
19+
if (isset($_REQUEST['vpa']))
20+
{
21+
#vpa = view_page_as
22+
if ($_REQUEST['vpa'] == 'm')
23+
{
24+
$is_mobile = 1;
25+
}
26+
elseif ($_REQUEST['vpa'] == 'd')
27+
{
28+
$is_mobile = 0;
29+
}
30+
else
31+
{
32+
#if the request isdifferent from the previous 2 parameters I don't do anything here
33+
}
34+
35+
if (isset($is_mobile))
36+
{
37+
#I set the cookie for 1 year
38+
setcookie('m', $is_mobile, time()+60*60*24*365, '/', $DOMAIN);
39+
$COOKIE_EXSISTS = TRUE;
40+
}
41+
}
42+
43+
#I check if the cookie is set
44+
#if so I get the value
45+
if (isset($_COOKIE['m']) || $COOKIE_EXSISTS)
46+
{
47+
if ($COOKIE_EXSISTS)
48+
{
49+
#I already have the variable set
50+
}
51+
else
52+
{
53+
#if the variable comes from a previus cookie
54+
$is_mobile = $_COOKIE['m'];
55+
}
56+
}
57+
#otherwise I try to detect if the browser is a mobile
58+
#and in any case I'll set the cookie for the next time
59+
else
60+
{
61+
#I try to detect the browser
62+
require_once ("Mobile_Detect.php");
63+
$detect = new Mobile_Detect();
64+
if ($detect->isMobile())
65+
{
66+
#the request is from a mobile
67+
$is_mobile = 1;
68+
}
69+
else
70+
{
71+
#the request is from a desktop
72+
$is_mobile = 0;
73+
}
74+
#I set the cookie for 1 year
75+
setcookie('m', $is_mobile, time()+60*60*24*365, '/', $DOMAIN);
76+
}
77+
78+
return $is_mobile;
79+
}
80+
81+
?>

New/hangman.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
#Include the settings
3+
require_once 'settings.php';
4+
#include the file containing the function to detect the browser
5+
require_once 'cookie_management.php';
6+
7+
# part of browser detection
8+
$is_mobile = cookie_management();
9+
10+
# Set the cache control header
11+
header("Vary: User-Agent, Accept");
12+
13+
if ($is_mobile == 0)
14+
{
15+
header("Location: http://".$_SERVER['SERVER_NAME'].$path_parts['dirname']."/hangman_desktop.php");
16+
}
17+
else
18+
{
19+
header("Location: http://".$_SERVER['SERVER_NAME'].$path_parts['dirname']."/hangman_mobile.php");
20+
}
21+
22+
?>

New/hangman_desktop.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
?>

New/hangman_mobile.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
?>

New/htaccess

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Expire headers
2+
<ifModule mod_expires.c>
3+
ExpiresActive On
4+
ExpiresDefault "access plus 5 seconds"
5+
ExpiresByType image/x-icon "access plus 2592000 seconds"
6+
ExpiresByType image/jpeg "access plus 2592000 seconds"
7+
ExpiresByType image/png "access plus 2592000 seconds"
8+
ExpiresByType image/gif "access plus 2592000 seconds"
9+
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
10+
ExpiresByType text/css "access plus 604800 seconds"
11+
ExpiresByType text/javascript "access plus 216000 seconds"
12+
ExpiresByType application/javascript "access plus 216000 seconds"
13+
ExpiresByType application/x-javascript "access plus 216000 seconds"
14+
ExpiresByType text/html "access plus 600 seconds"
15+
ExpiresByType text/php "access plus 600 seconds"
16+
ExpiresByType application/xhtml+xml "access plus 600 seconds"
17+
</ifModule>
18+
19+
# Cache-Control Headers
20+
<ifModule mod_headers.c>
21+
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
22+
Header set Cache-Control "public"
23+
</filesMatch>
24+
<filesMatch "\.(css)$">
25+
Header set Cache-Control "public"
26+
</filesMatch>
27+
<filesMatch "\.(js)$">
28+
Header set Cache-Control "private"
29+
</filesMatch>
30+
<filesMatch "\.(x?html?|php)$">
31+
Header set Cache-Control "private, must-revalidate"
32+
</filesMatch>
33+
</ifModule>

New/img/gallows.gif

1.68 KB
Loading

New/img/man1_0.gif

2.33 KB
Loading

New/img/man1_1.gif

2.29 KB
Loading

0 commit comments

Comments
 (0)