2016-09-07 03:10:56 +00:00
< ? php
namespace Zotlabs\Module\Settings ;
2018-06-05 01:40:11 +00:00
use Zotlabs\Lib\Libsync ;
2018-06-01 04:05:09 +00:00
2016-09-07 03:10:56 +00:00
class Display {
/*
* DISPLAY SETTINGS
*/
function post () {
check_form_security_token_redirectOnErr ( '/settings/display' , 'settings_display' );
$themespec = explode ( ':' , \App :: $channel [ 'channel_theme' ]);
$existing_theme = $themespec [ 0 ];
$existing_schema = $themespec [ 1 ];
$theme = (( x ( $_POST , 'theme' )) ? notags ( trim ( $_POST [ 'theme' ])) : $existing_theme );
if ( ! $theme )
$theme = 'redbasic' ;
2018-02-06 02:06:25 +00:00
2016-09-07 03:10:56 +00:00
$preload_images = (( x ( $_POST , 'preload_images' )) ? intval ( $_POST [ 'preload_images' ]) : 0 );
2017-11-01 02:56:14 +00:00
$channel_menu = (( x ( $_POST , 'channel_menu' )) ? intval ( $_POST [ 'channel_menu' ]) : 0 );
2016-09-07 03:10:56 +00:00
$user_scalable = (( x ( $_POST , 'user_scalable' )) ? intval ( $_POST [ 'user_scalable' ]) : 0 );
2017-09-12 18:00:59 +00:00
$nosmile = (( x ( $_POST , 'nosmile' )) ? intval ( $_POST [ 'nosmile' ]) : 0 );
2016-09-07 03:10:56 +00:00
$channel_divmore_height = (( x ( $_POST , 'channel_divmore_height' )) ? intval ( $_POST [ 'channel_divmore_height' ]) : 400 );
if ( $channel_divmore_height < 50 )
$channel_divmore_height = 50 ;
$network_divmore_height = (( x ( $_POST , 'network_divmore_height' )) ? intval ( $_POST [ 'network_divmore_height' ]) : 400 );
if ( $network_divmore_height < 50 )
$network_divmore_height = 50 ;
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$browser_update = (( x ( $_POST , 'browser_update' )) ? intval ( $_POST [ 'browser_update' ]) : 0 );
$browser_update = $browser_update * 1000 ;
if ( $browser_update < 10000 )
$browser_update = 10000 ;
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$itemspage = (( x ( $_POST , 'itemspage' )) ? intval ( $_POST [ 'itemspage' ]) : 20 );
if ( $itemspage > 100 )
$itemspage = 100 ;
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
set_pconfig ( local_channel (), 'system' , 'preload_images' , $preload_images );
set_pconfig ( local_channel (), 'system' , 'user_scalable' , $user_scalable );
set_pconfig ( local_channel (), 'system' , 'update_interval' , $browser_update );
set_pconfig ( local_channel (), 'system' , 'itemspage' , $itemspage );
set_pconfig ( local_channel (), 'system' , 'no_smilies' , 1 - intval ( $nosmile ));
set_pconfig ( local_channel (), 'system' , 'channel_divmore_height' , $channel_divmore_height );
set_pconfig ( local_channel (), 'system' , 'network_divmore_height' , $network_divmore_height );
2017-11-01 02:56:14 +00:00
set_pconfig ( local_channel (), 'system' , 'channel_menu' , $channel_menu );
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$newschema = '' ;
2017-03-02 10:36:35 +00:00
if ( $theme ){
2016-09-07 03:10:56 +00:00
// call theme_post only if theme has not been changed
if ( ( $themeconfigfile = $this -> get_theme_config_file ( $theme )) != null ){
require_once ( $themeconfigfile );
if ( class_exists ( '\\Zotlabs\\Theme\\' . ucfirst ( $theme ) . 'Config' )) {
$clsname = '\\Zotlabs\\Theme\\' . ucfirst ( $theme ) . 'Config' ;
$theme_config = new $clsname ();
$schemas = $theme_config -> get_schemas ();
if ( array_key_exists ( $_POST [ 'schema' ], $schemas ))
$newschema = $_POST [ 'schema' ];
if ( $newschema === '---' )
2017-09-12 18:00:59 +00:00
$newschema = '' ;
2016-09-07 03:10:56 +00:00
$theme_config -> post ();
}
}
}
logger ( 'theme: ' . $theme . (( $newschema ) ? ':' . $newschema : '' ));
$_SESSION [ 'theme' ] = $theme . (( $newschema ) ? ':' . $newschema : '' );
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$r = q ( " UPDATE channel SET channel_theme = '%s' WHERE channel_id = %d " ,
dbesc ( $theme . (( $newschema ) ? ':' . $newschema : '' )),
intval ( local_channel ())
);
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
call_hooks ( 'display_settings_post' , $_POST );
2018-06-05 01:40:11 +00:00
Libsync :: build_sync_packet ();
2016-09-07 03:10:56 +00:00
goaway ( z_root () . '/settings/display' );
return ; // NOTREACHED
}
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
function get () {
$yes_no = array ( t ( 'No' ), t ( 'Yes' ));
$default_theme = get_config ( 'system' , 'theme' );
if ( ! $default_theme )
$default_theme = 'redbasic' ;
$themespec = explode ( ':' , \App :: $channel [ 'channel_theme' ]);
$existing_theme = $themespec [ 0 ];
$existing_schema = $themespec [ 1 ];
$theme = (( $existing_theme ) ? $existing_theme : $default_theme );
$allowed_themes_str = get_config ( 'system' , 'allowed_themes' );
$allowed_themes_raw = explode ( ',' , $allowed_themes_str );
$allowed_themes = array ();
if ( count ( $allowed_themes_raw ))
2017-09-12 18:00:59 +00:00
foreach ( $allowed_themes_raw as $x )
2016-09-07 03:10:56 +00:00
if ( strlen ( trim ( $x )) && is_dir ( " view/theme/ $x " ))
$allowed_themes [] = trim ( $x );
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$themes = array ();
$files = glob ( 'view/theme/*' );
if ( $allowed_themes ) {
foreach ( $allowed_themes as $th ) {
$f = $th ;
2017-02-26 20:01:20 +00:00
2017-02-27 09:13:08 +00:00
$info = get_theme_info ( $th );
$compatible = check_plugin_versions ( $info );
2018-02-06 02:06:25 +00:00
if ( ! $compatible ) {
$themes [ $f ] = sprintf ( t ( '%s - (Incompatible)' ), $f );
2017-02-26 20:01:20 +00:00
continue ;
}
2016-09-07 03:10:56 +00:00
$is_experimental = file_exists ( 'view/theme/' . $th . '/experimental' );
$unsupported = file_exists ( 'view/theme/' . $th . '/unsupported' );
$is_library = file_exists ( 'view/theme/' . $th . '/library' );
2017-02-26 20:01:20 +00:00
2017-09-12 18:00:59 +00:00
if ( ! $is_experimental or ( $is_experimental && ( get_config ( 'experimentals' , 'exp_themes' ) == 1 or get_config ( 'experimentals' , 'exp_themes' ) === false ))){
2016-09-07 03:10:56 +00:00
$theme_name = (( $is_experimental ) ? sprintf ( t ( '%s - (Experimental)' ), $f ) : $f );
if ( ! $is_library ) {
2018-02-06 02:06:25 +00:00
$themes [ $f ] = $theme_name ;
2016-09-07 03:10:56 +00:00
}
}
}
}
$theme_selected = (( array_key_exists ( 'theme' , $_SESSION ) && $_SESSION [ 'theme' ]) ? $_SESSION [ 'theme' ] : $theme );
2017-09-12 18:00:59 +00:00
if ( strpos ( $theme_selected , ':' )) {
$theme_selected = explode ( ':' , $theme_selected )[ 0 ];
}
2016-09-07 03:10:56 +00:00
$preload_images = get_pconfig ( local_channel (), 'system' , 'preload_images' );
$preload_images = (( $preload_images === false ) ? '0' : $preload_images ); // default if not set: 0
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$user_scalable = get_pconfig ( local_channel (), 'system' , 'user_scalable' );
2016-11-07 22:24:07 +00:00
$user_scalable = (( $user_scalable === false ) ? '0' : $user_scalable ); // default if not set: 0
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$browser_update = intval ( get_pconfig ( local_channel (), 'system' , 'update_interval' ));
$browser_update = (( $browser_update == 0 ) ? 80 : $browser_update / 1000 ); // default if not set: 40 seconds
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$itemspage = intval ( get_pconfig ( local_channel (), 'system' , 'itemspage' ));
$itemspage = (( $itemspage > 0 && $itemspage < 101 ) ? $itemspage : 20 ); // default if not set: 20 items
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$nosmile = get_pconfig ( local_channel (), 'system' , 'no_smilies' );
$nosmile = (( $nosmile === false ) ? '0' : $nosmile ); // default if not set: 0
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$title_tosource = get_pconfig ( local_channel (), 'system' , 'title_tosource' );
$title_tosource = (( $title_tosource === false ) ? '0' : $title_tosource ); // default if not set: 0
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$theme_config = " " ;
if (( $themeconfigfile = $this -> get_theme_config_file ( $theme )) != null ){
require_once ( $themeconfigfile );
if ( class_exists ( '\\Zotlabs\\Theme\\' . ucfirst ( $theme ) . 'Config' )) {
$clsname = '\\Zotlabs\\Theme\\' . ucfirst ( $theme ) . 'Config' ;
$thm_config = new $clsname ();
$schemas = $thm_config -> get_schemas ();
$theme_config = $thm_config -> get ();
}
}
// logger('schemas: ' . print_r($schemas,true));
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
$tpl = get_markup_template ( " settings_display.tpl " );
$o = replace_macros ( $tpl , array (
'$ptitle' => t ( 'Display Settings' ),
2017-09-12 18:00:59 +00:00
'$d_tset' => t ( 'Theme Settings' ),
'$d_ctset' => t ( 'Custom Theme Settings' ),
2016-09-07 03:10:56 +00:00
'$d_cset' => t ( 'Content Settings' ),
'$form_security_token' => get_form_security_token ( " settings_display " ),
'$submit' => t ( 'Submit' ),
'$baseurl' => z_root (),
'$uid' => local_channel (),
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
'$theme' => (( $themes ) ? array ( 'theme' , t ( 'Display Theme:' ), $theme_selected , '' , $themes , 'preview' ) : false ),
'$schema' => array ( 'schema' , t ( 'Select scheme' ), $existing_schema , '' , $schemas ),
'$preload_images' => array ( 'preload_images' , t ( " Preload images before rendering the page " ), $preload_images , t ( " The subjective page load time will be longer but the page will be ready when displayed " ), $yes_no ),
'$user_scalable' => array ( 'user_scalable' , t ( " Enable user zoom on mobile devices " ), $user_scalable , '' , $yes_no ),
'$ajaxint' => array ( 'browser_update' , t ( " Update browser every xx seconds " ), $browser_update , t ( 'Minimum of 10 seconds, no maximum' )),
'$itemspage' => array ( 'itemspage' , t ( " Maximum number of conversations to load at any time: " ), $itemspage , t ( 'Maximum of 100 items' )),
'$nosmile' => array ( 'nosmile' , t ( " Show emoticons (smilies) as images " ), 1 - intval ( $nosmile ), '' , $yes_no ),
2017-11-01 02:56:14 +00:00
'$channel_menu' => [ 'channel_menu' , t ( 'Provide channel menu in navigation bar' ), get_pconfig ( local_channel (), 'system' , 'channel_menu' , get_config ( 'system' , 'channel_menu' , 0 )), t ( 'Default: channel menu located in app menu' ), $yes_no ],
2016-09-07 03:10:56 +00:00
'$layout_editor' => t ( 'System Page Layout Editor - (advanced)' ),
'$theme_config' => $theme_config ,
'$expert' => feature_enabled ( local_channel (), 'advanced_theming' ),
'$channel_divmore_height' => array ( 'channel_divmore_height' , t ( 'Channel page max height of content (in pixels)' ), (( get_pconfig ( local_channel (), 'system' , 'channel_divmore_height' )) ? get_pconfig ( local_channel (), 'system' , 'channel_divmore_height' ) : 400 ), t ( 'click to expand content exceeding this height' )),
2018-07-16 03:34:21 +00:00
'$network_divmore_height' => array ( 'network_divmore_height' , t ( 'Network page max height of content (in pixels)' ), (( get_pconfig ( local_channel (), 'system' , 'network_divmore_height' )) ? get_pconfig ( local_channel (), 'system' , 'network_divmore_height' ) : 400 ) , t ( 'click to expand content exceeding this height' )),
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
));
2017-09-12 18:00:59 +00:00
call_hooks ( 'display_settings' , $o );
2016-09-07 03:10:56 +00:00
return $o ;
}
function get_theme_config_file ( $theme ){
$base_theme = \App :: $theme_info [ 'extends' ];
2017-09-12 18:00:59 +00:00
2016-09-07 03:10:56 +00:00
if ( file_exists ( " view/theme/ $theme /php/config.php " )){
return " view/theme/ $theme /php/config.php " ;
2017-09-12 18:00:59 +00:00
}
2016-09-07 03:10:56 +00:00
if ( file_exists ( " view/theme/ $base_theme /php/config.php " )){
return " view/theme/ $base_theme /php/config.php " ;
}
return null ;
}
2017-09-12 18:00:59 +00:00
2016-11-07 22:24:07 +00:00
}