@ -54,8 +54,6 @@ class App
public $argc ;
public $module ;
public $strings ;
public $basepath ;
public $urlpath ;
public $hooks = [];
public $timezone ;
public $interactive = true ;
@ -65,11 +63,9 @@ class App
public $identities ;
public $is_mobile = false ;
public $is_tablet = false ;
public $is_friendica_app ;
public $performance = [];
public $callstack = [];
public $theme_info = [];
public $backend = true ;
public $nav_sel ;
public $category ;
// Allow themes to control internal parameters
@ -89,6 +85,31 @@ class App
*/
private $mode ;
/**
* @ var string The App basepath
*/
private $basepath ;
/**
* @ var string The App URL path
*/
private $urlpath ;
/**
* @ var bool true , if the call is from the Friendica APP , otherwise false
*/
private $isFriendicaApp ;
/**
* @ var bool true , if the call is from an backend node ( f . e . worker )
*/
private $isBackend ;
/**
* @ var string The name of the current theme
*/
private $currentTheme ;
/**
* Register a stylesheet file path to be included in the < head > tag of every page .
* Inclusion is done in App -> initHead () .
@ -100,7 +121,7 @@ class App
*/
public function registerStylesheet ( $path )
{
$url = str_replace ( $this -> get_basep ath () . DIRECTORY_SEPARATOR , '' , $path );
$url = str_replace ( $this -> getBaseP ath () . DIRECTORY_SEPARATOR , '' , $path );
$this -> stylesheets [] = trim ( $url , '/' );
}
@ -116,7 +137,7 @@ class App
*/
public function registerFooterScript ( $path )
{
$url = str_replace ( $this -> get_basep ath () . DIRECTORY_SEPARATOR , '' , $path );
$url = str_replace ( $this -> getBaseP ath () . DIRECTORY_SEPARATOR , '' , $path );
$this -> footerScripts [] = trim ( $url , '/' );
}
@ -157,26 +178,26 @@ class App
];
private $scheme ;
private $hostname ;
private $curl_code ;
private $curl_content_type ;
private $curl_headers ;
/**
* @ brief App constructor .
*
* @ param string $basepath Path to the app base folder
* @ param bool $backend true , if the call is from backend , otherwise set to true ( Default true )
*
* @ throws Exception if the Basepath is not usable
*/
public function __construct ( $basepath )
public function __construct ( $basepath , $backend = true )
{
if ( ! static :: directory_u sable( $basepath , false )) {
if ( ! static :: isDirectoryU sable( $basepath , false )) {
throw new Exception ( 'Basepath ' . $basepath . ' isn\'t usable.' );
}
BaseObject :: setApp ( $this );
$this -> basepath = rtrim ( $basepath , DIRECTORY_SEPARATOR );
$this -> checkBackend ( $backend );
$this -> checkFriendicaApp ();
$this -> performance [ 'start' ] = microtime ( true );
$this -> performance [ 'database' ] = 0 ;
@ -230,9 +251,9 @@ class App
set_include_path (
get_include_path () . PATH_SEPARATOR
. $this -> basepath . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
. $this -> basepath . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
. $this -> basepath );
. $this -> getBasePath () . DIRECTORY_SEPARATOR . 'include' . PATH_SEPARATOR
. $this -> getBasePath () . DIRECTORY_SEPARATOR . 'library' . PATH_SEPARATOR
. $this -> getBasePath () );
if (( x ( $_SERVER , 'QUERY_STRING' )) && substr ( $_SERVER [ 'QUERY_STRING' ], 0 , 9 ) === 'pagename=' ) {
$this -> query_string = substr ( $_SERVER [ 'QUERY_STRING' ], 9 );
@ -301,11 +322,8 @@ class App
$this -> is_mobile = $mobile_detect -> isMobile ();
$this -> is_tablet = $mobile_detect -> isTablet ();
// Friendica-Client
$this -> is_friendica_app = isset ( $_SERVER [ 'HTTP_USER_AGENT' ]) && $_SERVER [ 'HTTP_USER_AGENT' ] == 'Apache-HttpClient/UNAVAILABLE (java 1.4)' ;
// Register template engines
$this -> register_template_e ngine ( 'Friendica\Render\FriendicaSmartyEngine' );
$this -> registerTemplateEngine ( 'Friendica\Render\FriendicaSmartyEngine' );
}
/**
@ -334,9 +352,9 @@ class App
$this -> loadDatabase ();
$this -> getMode () -> determine ( $this -> basepath );
$this -> getMode () -> determine ( $this -> getBasePath () );
$this -> determineUrl Path ();
$this -> determineURL Path ();
Config :: load ();
@ -372,20 +390,20 @@ class App
*/
private function loadConfigFiles ()
{
$this -> loadConfigFile ( $this -> basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini.php' );
$this -> loadConfigFile ( $this -> basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.ini.php' );
$this -> loadConfigFile ( $this -> getBasePath () . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini.php' );
$this -> loadConfigFile ( $this -> getBasePath () . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'settings.ini.php' );
// Legacy .htconfig.php support
if ( file_exists ( $this -> basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php' )) {
if ( file_exists ( $this -> getBasePath () . DIRECTORY_SEPARATOR . '.htpreconfig.php' )) {
$a = $this ;
include $this -> basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php' ;
include $this -> getBasePath () . DIRECTORY_SEPARATOR . '.htpreconfig.php' ;
}
// Legacy .htconfig.php support
if ( file_exists ( $this -> basepath . DIRECTORY_SEPARATOR . '.htconfig.php' )) {
if ( file_exists ( $this -> getBasePath () . DIRECTORY_SEPARATOR . '.htconfig.php' )) {
$a = $this ;
include $this -> basepath . DIRECTORY_SEPARATOR . '.htconfig.php' ;
include $this -> getBasePath () . DIRECTORY_SEPARATOR . '.htconfig.php' ;
$this -> setConfigValue ( 'database' , 'hostname' , $db_host );
$this -> setConfigValue ( 'database' , 'username' , $db_user );
@ -413,8 +431,8 @@ class App
}
}
if ( file_exists ( $this -> basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php' )) {
$this -> loadConfigFile ( $this -> basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php' , true );
if ( file_exists ( $this -> getBasePath () . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php' )) {
$this -> loadConfigFile ( $this -> getBasePath () . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php' , true );
}
}
@ -473,8 +491,8 @@ class App
Core\Addon :: callHooks ( 'load_config' );
// Load the local addon config file to overwritten default addon config values
if ( file_exists ( $this -> basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php' )) {
$this -> loadConfigFile ( $this -> basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php' , true );
if ( file_exists ( $this -> getBasePath () . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php' )) {
$this -> loadConfigFile ( $this -> getBasePath () . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'addon.ini.php' , true );
}
}
@ -502,7 +520,7 @@ class App
/**
* Figure out if we are running at the top of a domain or in a sub - directory and adjust accordingly
*/
private function determineUrl Path ()
private function determineURL Path ()
{
$this -> urlpath = $this -> getConfigValue ( 'system' , 'urlpath' );
@ -562,7 +580,7 @@ class App
DBA :: connect ( $db_host , $db_user , $db_pass , $db_data , $charset );
unset ( $db_host , $db_user , $db_pass , $db_data , $charset );
$this -> save_t imestamp ( $stamp1 , 'network' );
$this -> saveT imestamp ( $stamp1 , 'network' );
}
/**
@ -573,7 +591,7 @@ class App
*
* @ return string
*/
public function get_basep ath ()
public function getBaseP ath ()
{
$basepath = $this -> basepath ;
@ -589,7 +607,7 @@ class App
$basepath = $_SERVER [ 'PWD' ];
}
return self :: realp ath( $basepath );
return self :: getRealP ath( $basepath );
}
/**
@ -602,7 +620,7 @@ class App
* @ param string $path The path that is about to be normalized
* @ return string normalized path - when possible
*/
public static function realp ath( $path )
public static function getRealP ath( $path )
{
$normalized = realpath ( $path );
@ -613,7 +631,7 @@ class App
}
}
public function get_s cheme ()
public function getS cheme ()
{
return $this -> scheme ;
}
@ -632,7 +650,7 @@ class App
* @ param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN
* @ return string Friendica server base URL
*/
public function get_baseurl ( $ssl = false )
public function getBaseURL ( $ssl = false )
{
$scheme = $this -> scheme ;
@ -655,7 +673,7 @@ class App
$this -> hostname = Config :: get ( 'config' , 'hostname' );
}
return $scheme . '://' . $this -> hostname . ( ! empty ( $this -> urlpath ) ? '/' . $this -> urlpath : '' );
return $scheme . '://' . $this -> hostname . ( ! empty ( $this -> getURLpath () ) ? '/' . $this -> getURLpath () : '' );
}
/**
@ -665,7 +683,7 @@ class App
*
* @ param string $url
*/
public function set_baseurl ( $url )
public function setBaseURL ( $url )
{
$parsed = @ parse_url ( $url );
$hostname = '' ;
@ -686,8 +704,8 @@ class App
$this -> urlpath = trim ( $parsed [ 'path' ], '\\/' );
}
if ( file_exists ( $this -> basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php' )) {
include $this -> basepath . DIRECTORY_SEPARATOR . '.htpreconfig.php' ;
if ( file_exists ( $this -> getBasePath () . DIRECTORY_SEPARATOR . '.htpreconfig.php' )) {
include $this -> getBasePath () . DIRECTORY_SEPARATOR . '.htpreconfig.php' ;
}
if ( Config :: get ( 'config' , 'hostname' ) != '' ) {
@ -700,7 +718,7 @@ class App
}
}
public function get_hostn ame ()
public function getHostN ame ()
{
if ( Config :: get ( 'config' , 'hostname' ) != '' ) {
$this -> hostname = Config :: get ( 'config' , 'hostname' );
@ -709,23 +727,23 @@ class App
return $this -> hostname ;
}
public function get_ path ()
public function getURL path ()
{
return $this -> urlpath ;
}
public function set_pager_t otal ( $n )
public function setPagerT otal ( $n )
{
$this -> pager [ 'total' ] = intval ( $n );
}
public function set_pager_itemsp age ( $n )
public function setPagerItemsP age ( $n )
{
$this -> pager [ 'itemspage' ] = (( intval ( $n ) > 0 ) ? intval ( $n ) : 0 );
$this -> pager [ 'start' ] = ( $this -> pager [ 'page' ] * $this -> pager [ 'itemspage' ]) - $this -> pager [ 'itemspage' ];
}
public function set_pager_p age ( $n )
public function setPagerP age ( $n )
{
$this -> pager [ 'page' ] = $n ;
$this -> pager [ 'start' ] = ( $this -> pager [ 'page' ] * $this -> pager [ 'itemspage' ]) - $this -> pager [ 'itemspage' ];
@ -791,7 +809,7 @@ class App
* being first
*/
$this -> page [ 'htmlhead' ] = replace_macros ( $tpl , [
'$baseurl' => $this -> get_baseurl (),
'$baseurl' => $this -> getBaseURL (),
'$local_user' => local_user (),
'$generator' => 'Friendica' . ' ' . FRIENDICA_VERSION ,
'$delitem' => L10n :: t ( 'Delete this item?' ),
@ -847,41 +865,11 @@ class App
$tpl = get_markup_template ( 'footer.tpl' );
$this -> page [ 'footer' ] = replace_macros ( $tpl , [
'$baseurl' => $this -> get_baseurl (),
'$baseurl' => $this -> getBaseURL (),
'$footerScripts' => $this -> footerScripts ,
]) . $this -> page [ 'footer' ];
}
public function set_curl_code ( $code )
{
$this -> curl_code = $code ;
}
public function get_curl_code ()
{
return $this -> curl_code ;
}
public function set_curl_content_type ( $content_type )
{
$this -> curl_content_type = $content_type ;
}
public function get_curl_content_type ()
{
return $this -> curl_content_type ;
}
public function set_curl_headers ( $headers )
{
$this -> curl_headers = $headers ;
}
public function get_curl_headers ()
{
return $this -> curl_headers ;
}
/**
* @ brief Removes the base url from an url . This avoids some mixed content problems .
*
@ -889,11 +877,11 @@ class App
*
* @ return string The cleaned url
*/
public function remove_baseurl ( $orig_url )
public function removeBaseURL ( $orig_url )
{
// Remove the hostname from the url if it is an internal link
$nurl = normalise_link ( $orig_url );
$base = normalise_link ( $this -> get_baseurl ());
$base = normalise_link ( $this -> getBaseURL ());
$url = str_replace ( $base . '/' , '' , $nurl );
// if it is an external link return the orignal value
@ -909,7 +897,7 @@ class App
*
* @ param string $class
*/
private function register_template_e ngine ( $class )
private function registerTemplateE ngine ( $class )
{
$v = get_class_vars ( $class );
if ( x ( $v , 'name' )) {
@ -929,7 +917,7 @@ class App
*
* @ return object Template Engine instance
*/
public function template_e ngine()
public function getTemplateE ngine()
{
$template_engine = 'smarty3' ;
if ( x ( $this -> theme , 'template_engine' )) {
@ -956,33 +944,40 @@ class App
*
* @ return string
*/
public function get_template_e ngine ()
public function getActiveTemplateE ngine ()
<