postActiv.php

Summary
postActiv.php
postActivCore class for abstracting the postActiv software
postActivSuperclass to handle global configuration setup and management, as well as bootstrapping various features.
addPluginConfigure and instantiate a plugin into the current configuration.
delPluginUnload a plugin
getActivePluginsGet a list of activated plugins in this process.
initInitialize, or re-initialize, postActiv global configuration and plugins.
currentSiteGet identifier of the currently active site configuration
switchSiteChange site configuration to site specified by nickname, if set up via Status_network.
findAllSitesPull all local sites from status_network table.
initPluginsFire initialization events for all instantiated plugins.
haveConfigQuick-check if configuration has been established.
configFilesReturns a list of configuration files that have been loaded for this instance of postActiv.
isApiReturns true/false if the page or endpoint being served up is an API page
setApiSets the API mode flag for this instantiation of postActiv
isAjaxReturns true/false whether the page or endpoint being served up is an AJAX document.
setAjaxSets the Ajax mode flag for this instantiation of postActiv
defaultConfigBuild default configuration array
initDefaultsEstablish default configuration based on given or default server and path.
loadSiteProfileBootstrap loading the site settings for a given profile (community, private)
_sn_to_pathHelper function to get the path the application is running in.
loadConfigFileLoad the default or specified configuration file.
fillConfigVoidsFill in some defaults if they are not specified.
verifyLoadedConfigVerify that the loaded config is good.
isHTTPSAre we running from the web with HTTPS?
NoConfigExceptionSubclass of PHP class that reports configuration errors
__constructConstruct the exception with configfiles that were misconfigured.

postActiv

Core class for abstracting the postActiv software

postActiv

the micro-blogging software

Copyright

Copyright © 2016-2017, Maiyannah Bishop

Derived from code copyright various sources

  • GNU Social © 2013-2016, Free Software Foundation, Inc
  • StatusNet © 2008-2012, StatusNet, Inc

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses/.

https://www.gnu.org/licenses/agpl.html

About

Core class for abstracting the postActiv software

Renamed from ‘GNUsocial’ to avoid trademark/IP problems.

PHP version

Tested with PHP 7

File Authors

Web

postActiv

Superclass to handle global configuration setup and management, as well as bootstrapping various features.

Summary
addPluginConfigure and instantiate a plugin into the current configuration.
delPluginUnload a plugin
getActivePluginsGet a list of activated plugins in this process.
initInitialize, or re-initialize, postActiv global configuration and plugins.
currentSiteGet identifier of the currently active site configuration
switchSiteChange site configuration to site specified by nickname, if set up via Status_network.
findAllSitesPull all local sites from status_network table.
initPluginsFire initialization events for all instantiated plugins.
haveConfigQuick-check if configuration has been established.
configFilesReturns a list of configuration files that have been loaded for this instance of postActiv.
isApiReturns true/false if the page or endpoint being served up is an API page
setApiSets the API mode flag for this instantiation of postActiv
isAjaxReturns true/false whether the page or endpoint being served up is an AJAX document.
setAjaxSets the Ajax mode flag for this instantiation of postActiv
defaultConfigBuild default configuration array
initDefaultsEstablish default configuration based on given or default server and path.
loadSiteProfileBootstrap loading the site settings for a given profile (community, private)
_sn_to_pathHelper function to get the path the application is running in.
loadConfigFileLoad the default or specified configuration file.
fillConfigVoidsFill in some defaults if they are not specified.
verifyLoadedConfigVerify that the loaded config is good.
isHTTPSAre we running from the web with HTTPS?

addPlugin

public static function addPlugin( $name,  
array $attrs = array())

Configure and instantiate a plugin into the current configuration.  Class definitions will be loaded from standard paths if necessary.  Note that initialization events won’t be fired until later.

Parameters

  • string $name class name & plugin file/subdir name
  • array $attrs key/value pairs of public attributes to set on plugin instance

Error States

  • throws ServerException if plugin can’t be found

delPlugin

public static function delPlugin($name)

Unload a plugin

getActivePlugins

public static function getActivePlugins()

Get a list of activated plugins in this process.

Returns

  • array of (string $name, array $args) pairs

init

public static function init($server = null,
$path = null,
$conffile = null)

Initialize, or re-initialize, postActiv global configuration and plugins.

If switching site configurations during script execution, be careful when working with leftover objects -- global settings affect many things and they may not behave as you expected.

Parameters

  • server - optional web server hostname for picking config
  • path - optional URL path for picking config
  • conffile - optional configuration file path

Error States

  • throws NoConfigException if config file can’t be found

currentSite

public static function currentSite()

Get identifier of the currently active site configuration

Returns

  • string

switchSite

public static function switchSite($nickname)

Change site configuration to site specified by nickname, if set up via Status_network.  If not, sites other than the current will fail horribly.

May throw exception or trigger a fatal error if the given site is missing or configured incorrectly.

Parameters

  • string $nickname

findAllSites

public static function findAllSites()

Pull all local sites from status_network table.

Behavior undefined if site is not configured via Status_network.

Returns

  • array of nicknames

initPlugins

protected static function initPlugins()

Fire initialization events for all instantiated plugins.

User config may have already added some of these plugins, with maybe configured parameters.  The self::addPlugin function will ignore the new call if it has already been instantiated.

haveConfig

public static function haveConfig()

Quick-check if configuration has been established.  Useful for functions which may get used partway through initialization to back off from fancier things.

Returns

  • boolean

configFiles

public static function configFiles()

Returns a list of configuration files that have been loaded for this instance of postActiv.

isApi

public static function isApi()

Returns true/false if the page or endpoint being served up is an API page

setApi

public static function setApi($mode)

Sets the API mode flag for this instantiation of postActiv

isAjax

public static function isAjax()

Returns true/false whether the page or endpoint being served up is an AJAX document.

setAjax

public static function setAjax($mode)

Sets the Ajax mode flag for this instantiation of postActiv

defaultConfig

protected static function defaultConfig()

Build default configuration array

Returns

  • array

initDefaults

public static function initDefaults($server,
$path)

Establish default configuration based on given or default server and path.  Sets global $_server, $_path, and $config.,

loadSiteProfile

public static function loadSiteProfile($name)

Bootstrap loading the site settings for a given profile (community, private)

_sn_to_path

protected static function _sn_to_path($sn)

Helper function to get the path the application is running in.

loadConfigFile

protected static function loadConfigFile($conffile = null)

Load the default or specified configuration file.  Modifies global $config and may establish plugins.

Parameters

  • conffile - string with a path to a specific configuration file

Error States

  • throws NoConfigException if unable to find a config file.
  • throws ServerException if there is no database configuration specified.

fillConfigVoids

static function fillConfigVoids()

Fill in some defaults if they are not specified.

verifyLoadedConfig

static function verifyLoadedConfig()

Verify that the loaded config is good.  Not complete, but will throw exceptions on common configuration problems I hope.

Might make changes to the filesystem, to created dirs, but will not make database changes.

Error States

  • Throws ConfigException if the configuration doesn’t check out.

isHTTPS

static function isHTTPS()

Are we running from the web with HTTPS?

Returns

  • boolean true if we’re running with HTTPS; else false

NoConfigException

Subclass of PHP class that reports configuration errors

Properties

  • configFiles - the config file or files that were misconfigured.

__construct

function __construct($msg,
$configFiles)

Construct the exception with configfiles that were misconfigured.

public static function addPlugin( $name,  
array $attrs = array())
Configure and instantiate a plugin into the current configuration.
public static function delPlugin($name)
Unload a plugin
public static function getActivePlugins()
Get a list of activated plugins in this process.
public static function init($server = null,
$path = null,
$conffile = null)
Initialize, or re-initialize, postActiv global configuration and plugins.
public static function currentSite()
Get identifier of the currently active site configuration
public static function switchSite($nickname)
Change site configuration to site specified by nickname, if set up via Status_network.
public static function findAllSites()
Pull all local sites from status_network table.
protected static function initPlugins()
Fire initialization events for all instantiated plugins.
public static function haveConfig()
Quick-check if configuration has been established.
public static function configFiles()
Returns a list of configuration files that have been loaded for this instance of postActiv.
public static function isApi()
Returns true/false if the page or endpoint being served up is an API page
public static function setApi($mode)
Sets the API mode flag for this instantiation of postActiv
public static function isAjax()
Returns true/false whether the page or endpoint being served up is an AJAX document.
public static function setAjax($mode)
Sets the Ajax mode flag for this instantiation of postActiv
protected static function defaultConfig()
Build default configuration array
public static function initDefaults($server,
$path)
Establish default configuration based on given or default server and path.
public static function loadSiteProfile($name)
Bootstrap loading the site settings for a given profile (community, private)
protected static function _sn_to_path($sn)
Helper function to get the path the application is running in.
protected static function loadConfigFile($conffile = null)
Load the default or specified configuration file.
static function fillConfigVoids()
Fill in some defaults if they are not specified.
static function verifyLoadedConfig()
Verify that the loaded config is good.
static function isHTTPS()
Are we running from the web with HTTPS?
function __construct($msg,
$configFiles)
Construct the exception with configfiles that were misconfigured.