allow individual choice of mobile themes

This commit is contained in:
Zach Prezkuta 2012-09-06 17:24:34 -06:00
parent 41439804f4
commit 77529ccdf1
17 changed files with 69 additions and 24 deletions

View file

@ -1088,9 +1088,12 @@ if(! function_exists('profile_load')) {
$a->profile = $r[0];
$a->profile['mobile-theme'] = get_pconfig($profile_uid, 'system', 'mobile_theme');
$a->page['title'] = $a->profile['name'] . " @ " . $a->config['sitename'];
$_SESSION['theme'] = $a->profile['theme'];
$_SESSION['mobile-theme'] = $a->profile['mobile-theme'];
/**
* load/reload current theme info
@ -1510,6 +1513,12 @@ if(! function_exists('current_theme')) {
if($is_mobile) {
$system_theme = ((isset($a->config['system']['mobile-theme'])) ? $a->config['system']['mobile-theme'] : '');
$theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme);
if($theme_name === '---') {
// user has selected to have the mobile theme be the same as the normal one
$system_theme = '';
$theme_name = '';
}
}
if(!$is_mobile || ($system_theme === '' && $theme_name === '')) {
$system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');

View file

@ -10,14 +10,13 @@ function nuke_session() {
unset($_SESSION['administrator']);
unset($_SESSION['cid']);
unset($_SESSION['theme']);
unset($_SESSION['mobile-theme']);
unset($_SESSION['page_flags']);
unset($_SESSION['submanage']);
unset($_SESSION['my_url']);
unset($_SESSION['my_address']);
unset($_SESSION['addr']);
unset($_SESSION['return_url']);
unset($_SESSION['theme']);
unset($_SESSION['page_flags']);
}

View file

@ -145,6 +145,7 @@ class FKOAuth1 extends OAuthServer {
}
$_SESSION['uid'] = $record['uid'];
$_SESSION['theme'] = $record['theme'];
$_SESSION['mobile-theme'] = get_pconfig($record['uid'], 'system', 'mobile_theme');
$_SESSION['authenticated'] = 1;
$_SESSION['page_flags'] = $record['page-flags'];
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $record['nickname'];

View file

@ -6,6 +6,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive
$_SESSION['uid'] = $user_record['uid'];
$_SESSION['theme'] = $user_record['theme'];
$_SESSION['mobile-theme'] = get_pconfig($user_record['uid'], 'system', 'mobile_theme');
$_SESSION['authenticated'] = 1;
$_SESSION['page_flags'] = $user_record['page-flags'];
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $user_record['nickname'];

View file

@ -329,11 +329,11 @@ function admin_page_site_post(&$a){
}
set_config('system','language', $language);
set_config('system','theme', $theme);
if ( $theme_mobile === '---' ) {
del_config('system','mobile-theme');
} else {
set_config('system','mobile-theme', $theme_mobile);
}
if ( $theme_mobile === '---' ) {
del_config('system','mobile-theme');
} else {
set_config('system','mobile-theme', $theme_mobile);
}
set_config('system','maximagesize', $maximagesize);
set_config('system','max_image_length', $maximagelength);
set_config('system','jpeg_quality', $jpegimagequality);
@ -399,16 +399,18 @@ function admin_page_site(&$a) {
/* Installed themes */
$theme_choices = array();
$theme_choices_mobile = array();
$theme_choices_mobile["---"] = t("Don't apply a special theme for mobile devices.");
$theme_choices_mobile["---"] = t("No special theme for mobile devices");
$files = glob('view/theme/*');
if($files) {
foreach($files as $file) {
$f = basename($file);
$theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
$theme_choices[$f] = $theme_name;
if (file_exists($file . '/mobile')) {
$theme_choices_mobile[$f] = $theme_name;
}
if (file_exists($file . '/mobile')) {
$theme_choices_mobile[$f] = $theme_name;
}
else {
$theme_choices[$f] = $theme_name;
}
}
}

View file

@ -1,8 +1,10 @@
<?php
function community_init(&$a) {
if(! local_user())
if(! local_user()) {
unset($_SESSION['theme']);
unset($_SESSION['mobile-theme']);
}
}

View file

@ -9,8 +9,10 @@ function directory_init(&$a) {
$a->page['aside'] .= findpeople_widget();
}
else
else {
unset($_SESSION['theme']);
unset($_SESSION['mobile-theme']);
}
}

View file

@ -22,6 +22,8 @@ function home_content(&$a) {
if(x($_SESSION,'theme'))
unset($_SESSION['theme']);
if(x($_SESSION,'mobile-theme'))
unset($_SESSION['mobile-theme']);
$o .= '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>';
if(file_exists('home.html'))

View file

@ -3,8 +3,11 @@
function login_content(&$a) {
if(x($_SESSION,'theme'))
unset($_SESSION['theme']);
if(x($_SESSION,'mobile-theme'))
unset($_SESSION['mobile-theme']);
if(local_user())
goaway(z_root());
return login(($a->config['register_policy'] == REGISTER_CLOSED) ? false : true);
}
}

View file

@ -63,6 +63,7 @@ function manage_post(&$a) {
unset($_SESSION['administrator']);
unset($_SESSION['cid']);
unset($_SESSION['theme']);
unset($_SESSION['mobile-theme']);
unset($_SESSION['page_flags']);
unset($_SESSION['return_url']);
if(x($_SESSION,'submanage'))

View file

@ -193,6 +193,8 @@ function register_content(&$a) {
if(x($_SESSION,'theme'))
unset($_SESSION['theme']);
if(x($_SESSION,'mobile-theme'))
unset($_SESSION['mobile-theme']);
$username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));

View file

@ -50,8 +50,10 @@ function search_init(&$a) {
$a->page['aside'] .= search_saved_searches();
}
else
else {
unset($_SESSION['theme']);
unset($_SESSION['mobile-theme']);
}

View file

@ -236,17 +236,22 @@ function settings_post(&$a) {
check_form_security_token_redirectOnErr('/settings/display', 'settings_display');
$theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : $a->user['theme']);
$mobile_theme = ((x($_POST,'mobile_theme')) ? notags(trim($_POST['mobile_theme'])) : '');
$nosmile = ((x($_POST,'nosmile')) ? intval($_POST['nosmile']) : 0);
$browser_update = ((x($_POST,'browser_update')) ? intval($_POST['browser_update']) : 0);
$browser_update = $browser_update * 1000;
if($browser_update < 10000)
$browser_update = 40000;
$browser_update = 10000;
$itemspage_network = ((x($_POST,'itemspage_network')) ? intval($_POST['itemspage_network']) : 40);
if($itemspage_network > 100)
$itemspage_network = 40;
$itemspage_network = 100;
if($mobile_theme !== '') {
set_pconfig(local_user(),'system','mobile_theme',$mobile_theme);
}
set_pconfig(local_user(),'system','update_interval', $browser_update);
set_pconfig(local_user(),'system','itemspage_network', $itemspage_network);
set_pconfig(local_user(),'system','no_smilies',$nosmile);
@ -497,10 +502,11 @@ function settings_post(&$a) {
require_once('include/profile_update.php');
profile_change();
$_SESSION['theme'] = $theme;
//$_SESSION['theme'] = $theme;
if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
// FIXME - set to un-verified, blocked and redirect to logout
// Why? Are we verifying people or email addresses?
}
@ -704,6 +710,9 @@ function settings_content(&$a) {
$default_theme = get_config('system','theme');
if(! $default_theme)
$default_theme = 'default';
$default_mobile_theme = get_config('system','mobile-theme');
if(! $mobile_default_theme)
$mobile_default_theme = 'none';
$allowed_themes_str = get_config('system','allowed_themes');
$allowed_themes_raw = explode(',',$allowed_themes_str);
@ -715,19 +724,27 @@ function settings_content(&$a) {
$themes = array();
$mobile_themes = array("---" => t('No special theme for mobile devices'));
$files = glob('view/theme/*');
if($allowed_themes) {
foreach($allowed_themes as $th) {
$f = $th;
$is_experimental = file_exists('view/theme/' . $th . '/experimental');
$unsupported = file_exists('view/theme/' . $th . '/unsupported');
$is_mobile = file_exists('view/theme/' . $th . '/mobile');
if (!$is_experimental or ($is_experimental && (get_config('experimentals','exp_themes')==1 or get_config('experimentals','exp_themes')===false))){
$theme_name = (($is_experimental) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
$themes[$f]=$theme_name;
if($is_mobile) {
$mobile_themes[$f]=$theme_name;
}
else {
$themes[$f]=$theme_name;
}
}
}
}
$theme_selected = (!x($_SESSION,'theme')? $default_theme : $_SESSION['theme']);
$mobile_theme_selected = (!x($_SESSION,'mobile-theme')? $default_mobile_theme : $_SESSION['mobile-theme']);
$browser_update = intval(get_pconfig(local_user(), 'system','update_interval'));
$browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds
@ -753,7 +770,8 @@ function settings_content(&$a) {
'$baseurl' => $a->get_baseurl(true),
'$uid' => local_user(),
'$theme' => array('theme', t('Display Theme:'), $theme_selected, '', $themes),
'$theme' => array('theme', t('Display Theme:'), $theme_selected, '', $themes, 'preview'),
'$mobile_theme' => array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, ''),
'$ajaxint' => array('browser_update', t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds, no maximum')),
'$itemspage_network' => array('itemspage_network', t("Number of items to display per page:"), $itemspage_network, t('Maximum of 100 items')),
'$nosmile' => array('nosmile', t("Don't show emoticons"), $nosmile, ''),

View file

@ -1,7 +1,7 @@
<script>$(function(){ previewTheme($("#id_$field.0")[0]); });</script>
<div class='field select'>
<label for='id_$field.0'>$field.1</label>
<select name='$field.0' id='id_$field.0' onchange="previewTheme(this);" >
<select name='$field.0' id='id_$field.0' {{ if $field.5=='preview' }}onchange="previewTheme(this);"{{ endif }} >
{{ for $field.4 as $opt=>$val }}<option value="$opt" {{ if $opt==$field.2 }}selected="selected"{{ endif }}>$val</option>{{ endfor }}
</select>
<span class='field_help'>$field.3</span>

View file

@ -4,6 +4,7 @@
<input type='hidden' name='form_security_token' value='$form_security_token'>
{{inc field_themeselect.tpl with $field=$theme }}{{endinc}}
{{inc field_themeselect.tpl with $field=$mobile_theme }}{{endinc}}
{{inc field_input.tpl with $field=$ajaxint }}{{endinc}}
{{inc field_input.tpl with $field=$itemspage_network }}{{endinc}}
{{inc field_checkbox.tpl with $field=$nosmile}}{{endinc}}

View file

@ -1,7 +1,7 @@
<div class='field select'>
<label for='id_$field.0'>$field.1</label>
<select name='$field.0' id='id_$field.0' onchange="previewTheme(this);" >
<select name='$field.0' id='id_$field.0' {{ if $field.5=='preview' }}onchange="previewTheme(this);"{{ endif }} >
{{ for $field.4 as $opt=>$val }}<option value="$opt" {{ if $opt==$field.2 }}selected="selected"{{ endif }}>$val</option>{{ endfor }}
</select>
<span class='field_help'>$field.3</span>

View file

@ -1,7 +1,7 @@
<div class='field select'>
<label for='id_$field.0'>$field.1</label>
<select name='$field.0' id='id_$field.0' onchange="previewTheme(this);" >
<select name='$field.0' id='id_$field.0' {{ if $field.5=='preview' }}onchange="previewTheme(this);"{{ endif }} >
{{ for $field.4 as $opt=>$val }}<option value="$opt" {{ if $opt==$field.2 }}selected="selected"{{ endif }}>$val</option>{{ endfor }}
</select>
<span class='field_help'>$field.3</span>