aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Web/CheckJS.php
blob: c8547b6dd191e7dd5c34f1e25027a360c6443c74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

namespace Zotlabs\Web;


class CheckJS {

	private static $jsdisabled = 0;

	function __construct($test = 0) {
		if(intval($_REQUEST['jsdisabled']))
			$this->jsdisabled = 1;
		else
			$this->jsdisabled = 0;
		if(intval($_COOKIE['jsdisabled']))
			$this->jsdisabled = 1;
		else
			$this->jsdisabled = 0;

		if(! $this->jsdisabled) {
			$page = bin2hex(\App::$query_string);

			if($test) {
				$this->jsdisabled = 1;
				if(array_key_exists('jsdisabled',$_COOKIE))
					$this->jsdisabled = $_COOKIE['jsdisabled'];

    			if(! array_key_exists('jsdisabled',$_COOKIE)) {
			        \App::$page['htmlhead'] .= "\r\n" . '<script>document.cookie="jsdisabled=0; path=/"; var jsMatch = /\&jsdisabled=0/; if (!jsMatch.exec(location.href)) { location.href = "' . z_root() . '/nojs/0?f=&redir=' . $page . '" ; }</script>' . "\r\n";
			        /* emulate JS cookie if cookies are not accepted */
			        if (array_key_exists('jsdisabled',$_GET)) {
            			$_COOKIE['jsdisabled'] = $_GET['jsdisabled'];
        			}
				}
			}
			else {
				\App::$page['htmlhead'] .= "\r\n" . '<noscript><meta http-equiv="refresh" content="0; url=' . z_root() . '/nojs?f=&redir=' . $page . '"></noscript>' . "\r\n";
			}
		}

	}

	function disabled() {
		return $this->jsdisabled;
	}


}