refactor the js detection into a checkjs class which is only enabled on demand (currently only the channel and display pages). Will probably require a bit more work to hide/disable the cover photo when js is disabled. Have not actually tested without js to discover any other potential page issues. Have only confirmed that the detection class works and redirects to set a jsdisabled cookie and reload the page with that cookie+variable set if called from the channel page.

This commit is contained in:
redmatrix 2016-04-13 16:31:06 -07:00
parent a8a0ca8291
commit 9a0b61e4af
5 changed files with 50 additions and 19 deletions

36
Zotlabs/Web/CheckJS.php Normal file
View file

@ -0,0 +1,36 @@
<?php
namespace Zotlabs\Web;
class CheckJS {
private static $jsdisabled = 0;
function __construct($test = 0) {
if(intval($_REQUEST['jsdisabled']))
$this->jsdisabled = 1;
if(intval($_COOKIE['jsdisabled']))
$this->jsdisabled = 1;
if(! $this->jsdisabled) {
$page = urlencode(\App::$query_string);
if($test) {
\App::$page['htmlhead'] .= "\r\n" . '<meta http-equiv="refresh" content="0; url=' . z_root() . '/nojs?f=&redir=' . $page . '">' . "\r\n";
}
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 self::$jsdisabled;
}
}

View file

@ -54,6 +54,7 @@ function channel_content(&$a, $update = 0, $load = false) {
if($load) if($load)
$_SESSION['loadtime'] = datetime_convert(); $_SESSION['loadtime'] = datetime_convert();
$checkjs = new Zotlabs\Web\CheckJS();
$category = $datequery = $datequery2 = ''; $category = $datequery = $datequery2 = '';
@ -209,7 +210,7 @@ function channel_content(&$a, $update = 0, $load = false) {
App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start'])); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
if($load || ($_COOKIE['jsdisabled'] == 1)) { if($load || ($checkjs->disabled())) {
if ($mid) { if ($mid) {
$r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal
AND item_wall = 1 $sql_extra limit 1", AND item_wall = 1 $sql_extra limit 1",
@ -338,13 +339,13 @@ function channel_content(&$a, $update = 0, $load = false) {
} }
if($_COOKIE['jsdisabled'] == 1) { if($checkjs->disabled()) {
$o .= conversation($a,$items,'channel',$update,'traditional'); $o .= conversation($a,$items,'channel',$update,'traditional');
} else { } else {
$o .= conversation($a,$items,'channel',$update,$page_mode); $o .= conversation($a,$items,'channel',$update,$page_mode);
} }
if((! $update) || ($_COOKIE['jsdisabled'] == 1)) { if((! $update) || ($checkjs->disabled())) {
$o .= alt_pager($a,count($items)); $o .= alt_pager($a,count($items));
if ($mid && $items[0]['title']) if ($mid && $items[0]['title'])
App::$page['title'] = $items[0]['title'] . " - " . App::$page['title']; App::$page['title'] = $items[0]['title'] . " - " . App::$page['title'];

View file

@ -5,6 +5,10 @@ function display_content(&$a, $update = 0, $load = false) {
// logger("mod-display: update = $update load = $load"); // logger("mod-display: update = $update load = $load");
$checkjs = new Zotlabs\Web\CheckJS();
if($load) if($load)
$_SESSION['loadtime'] = datetime_convert(); $_SESSION['loadtime'] = datetime_convert();
@ -168,13 +172,13 @@ function display_content(&$a, $update = 0, $load = false) {
$sql_extra = public_permissions_sql($observer_hash); $sql_extra = public_permissions_sql($observer_hash);
if(($update && $load) || ($_COOKIE['jsdisabled'] == 1)) { if(($update && $load) || ($checkjs->disabled())) {
$updateable = false; $updateable = false;
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']),intval(App::$pager['start'])); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']),intval(App::$pager['start']));
if($load || ($_COOKIE['jsdisabled'] == 1)) { if($load || ($checkjs->disabled())) {
$r = null; $r = null;
require_once('include/identity.php'); require_once('include/identity.php');
@ -290,7 +294,7 @@ function display_content(&$a, $update = 0, $load = false) {
} }
if ($_COOKIE['jsdisabled'] == 1) { if ($checkjs->disabled()) {
$o .= conversation($a, $items, 'display', $update, 'traditional'); $o .= conversation($a, $items, 'display', $update, 'traditional');
if ($items[0]['title']) if ($items[0]['title'])
App::$page['title'] = $items[0]['title'] . " - " . App::$page['title']; App::$page['title'] = $items[0]['title'] . " - " . App::$page['title'];

View file

@ -4,6 +4,7 @@ function nojs_init(&$a) {
setcookie('jsdisabled', 1, 0); setcookie('jsdisabled', 1, 0);
$p = $_GET['query']; $p = $_GET['query'];
goaway(z_root() . (($p) ? '/' . $p : '')); $hasq = strpos($p,'?');
goaway(z_root() . (($p) ? '/' . $p : '') . (($hasq) ? '' : '?f=' ) . '&jsdisabled=1');
} }

View file

@ -1,27 +1,17 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<base href="{{$baseurl}}/" /> <base href="{{$baseurl}}/" />
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable={{$user_scalable}}" /> <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, user-scalable={{$user_scalable}}" />
<noscript><meta http-equiv="refresh" content="0; url=nojs.php&redir={{$query}}"></noscript>
{{$metas}} {{$metas}}
<!--[if IE]> <!--[if IE]>
<script src="{{$baseurl}}/library/html5.js"></script> <script src="{{$baseurl}}/library/html5.js"></script>
<![endif]--> <![endif]-->
{{$head_css}} {{$head_css}}
{{$js_strings}} {{$js_strings}}
{{$head_js}} {{$head_js}}
<link rel="shortcut icon" href="{{$icon}}" /> <link rel="shortcut icon" href="{{$icon}}" />
<link rel="search" <link rel="search" href="{{$baseurl}}/opensearch" type="application/opensearchdescription+xml" title="{{$osearch}}" />
href="{{$baseurl}}/opensearch"
type="application/opensearchdescription+xml"
title="{{$osearch}}" />
<script> <script>
var updateInterval = {{$update_interval}}; var updateInterval = {{$update_interval}};
var localUser = {{if $local_channel}}{{$local_channel}}{{else}}false{{/if}}; var localUser = {{if $local_channel}}{{$local_channel}}{{else}}false{{/if}};
var zid = {{if $zid}}'{{$zid}}'{{else}}null{{/if}}; var zid = {{if $zid}}'{{$zid}}'{{else}}null{{/if}};
@ -29,7 +19,6 @@
{{if $channel_hash}}var channelHash = '{{$channel_hash}}';{{/if}} {{if $channel_hash}}var channelHash = '{{$channel_hash}}';{{/if}}
{{if $channel_id}}var channelId = '{{$channel_id}}';{{/if}}{{* Used in e.g. autocomplete *}} {{if $channel_id}}var channelId = '{{$channel_id}}';{{/if}}{{* Used in e.g. autocomplete *}}
var preloadImages = {{$preload_images}}; var preloadImages = {{$preload_images}};
</script> </script>