* The intent is to have plugins/add-ons supply information on scripts and styles that might be
* loaded in a 'scripts.php' file in the 'setup' directory so that consistency can be maintained and
* duplicates can be avoided. Models then simply ask to have a script or style enqueued by
- * specifying the "handle" of that script using the enqueue() method.
+ * specifying the "handle" of that script using the enqueueScripts() method.
*
- * The 'scripts.php' files should be exclusively a set of calls to the add() method
+ * The 'scripts.php' files should be exclusively a set of calls to the addScript() method
*
* @category CommonApps
* @package Registry
* @version Release: 1.0
* @link <>
*/
-abstract class glmScriptType
+abstract class GlmScriptType
{
const Unknown = 0;
const Script = 1;
}
-class glmScript
+class GlmScript
{
/**
*
* @var string $handle Required handle (name) for this script
* @var string $src Required source URL of script
- * @var int $type Required type enumerated (see glmScriptType above)
+ * @var int $type Required type enumerated (see GlmScriptType above)
* @var array $deps Optional array of handles for scripts this script depends on
* @var boolean $in_footer Optional flag for enqueue before </body> tag
* @var string $media Optional media types for styles (i.e. 'all', 'print', 'screen'...)
*/
public $handle = '';
public $src = '';
- public $type = glmScriptType::Unknown;
+ public $type = GlmScriptType::Unknown;
public $deps = false;
public $in_footer = false;
public $media = 'all';
public $fullHandle = '';
/**
- * This constructor takes an array of parameters and creates a glmScript object from that.
+ * This constructor takes an array of parameters and creates a GlmScript object from that.
* Not all parameters need to be supplied, only those specified as such above. Defaults will be
* used for parameters that are not suplied.
*
$this->$key = $val;
} else {
trigger_error(
- "glmScriptRegistry invalid glmScipt object parameter: Key = $key, Value = $val",
+ "GlmScriptRegistry invalid glmScipt object parameter: Key = $key, Value = $val",
E_USER_NOTICE );
}
}
}
- $script = glmScriptRegistry::find( glmScriptType::Script, $fullHandle);
+ $script = GlmScriptRegistry::findScript( GlmScriptType::Script, $fullHandle );
if ( $script ) {
// Add the above function as 'script_loader_tag' filter
add_filter( 'script_loader_tag', 'glmScriptRegistryTagFilter', 10, 3 );
-class glmScriptRegistry
+class GlmScriptRegistry
{
- // Lists of glmScript objects
+ // Lists of GlmScript objects
private static $_scripts = array();
private static $_styles = array();
*
* @return object New script values array or false if failure
*/
- static public function add( $scriptVals )
+ static public function addScript( $scriptVals )
{
// Make sure an array has been submitted
if ( !is_array( $scriptVals ) || !count( $scriptVals ) ) {
trigger_error(
- 'glmScriptRegistry add(): No data supplied or not array!',
+ 'GlmScriptRegistry addScript(): No data supplied or not array!',
E_USER_NOTICE );
return false;
}
// Create an object with the submitted script values
- $script = new glmScript( $scriptVals );
+ $script = new GlmScript( $scriptVals );
// Check if handle not supplied
if ( trim( $script->handle ) == '' ) {
trigger_error(
- 'glmScriptRegistry add(): Required "handle" not supplied!',
+ 'GlmScriptRegistry addScript(): Required "handle" not supplied!',
E_USER_NOTICE );
return false;
}
// Check if file type is supplied
- if ( trim( $script->type ) == glmScriptType::Unknown ) {
+ if ( trim( $script->type ) == GlmScriptType::Unknown ) {
trigger_error(
- 'glmScriptRegistry add(): Required "type" not supplied or invalid!',
+ 'GlmScriptRegistry addScript(): Required "type" not supplied or invalid!',
E_USER_NOTICE );
return false;
}
// Check if src is supplied
if ( trim( $script->src ) == '' ) {
trigger_error(
- 'glmScriptRegistry add(): Required "src" not supplied!',
+ 'GlmScriptRegistry addScript(): Required "src" not supplied!',
E_USER_NOTICE );
return false;
}
// Check if plugin is supplied
if ( trim( $script->plugin ) == '' ) {
trigger_error(
- 'glmScriptRegistry add(): Required "plugin" not supplied!',
+ 'GlmScriptRegistry addScript(): Required "plugin" not supplied!',
E_USER_NOTICE );
return false;
}
// Check if version is supplied
if ( trim( $script->src ) == '' ) {
trigger_error(
- 'glmScriptRegistry add(): Required "version" not supplied!',
+ 'GlmScriptRegistry addScript(): Required "version" not supplied!',
E_USER_NOTICE );
return false;
}
// Add script to registry list
switch ( $script->type ) {
- case glmScriptType::Script:
+ case GlmScriptType::Script:
// If there's any already listed, check for duplicates
if ( count( self::$_scripts ) ) {
// Check for duplicate handle
if ( isset( self::$_scripts[$script->handle] ) ) {
trigger_error(
- 'glmScriptRegistry add(): Duplicate script "handle" submitted! (' .
+ 'GlmScriptRegistry addScript(): Duplicate script "handle" submitted! (' .
$script->handle . ')', E_USER_NOTICE );
return false;
}
foreach ( self::$_scripts as $handle=>$s ) {
if ( $script->src == $s->src ) {
trigger_error(
- 'glmScriptRegistry add(): Duplicate script "src" submitted! (' .
+ 'GlmScriptRegistry addScript(): Duplicate script "src" submitted! (' .
$s->src . ')', E_USER_NOTICE );
return false;
}
if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
trigger_error(
- "glmScriptRegistry add(): script handle added = " .
+ "GlmScriptRegistry addScript(): script handle added = " .
$script->handle, E_USER_NOTICE );
}
break;
- case glmScriptType::Style:
+ case GlmScriptType::Style:
// If there's any already listed, check for duplicates
if ( count( self::$_styles ) ) {
// Check for duplicate handle
if ( isset( self::$_styles[$script->handle] ) ) {
trigger_error(
- 'glmScriptRegistry add(): Duplicate style "handle" submitted! (' .
+ 'GlmScriptRegistry addScript(): Duplicate style "handle" submitted! (' .
$script->handle . ')', E_USER_NOTICE );
return false;
}
foreach ( self::$_scripts as $handle=>$s ) {
if ( $script->src == $s->src ) {
trigger_error(
- 'glmScriptRegistry add(): Duplicate style "src" submitted! (' .
+ 'GlmScriptRegistry addScript(): Duplicate style "src" submitted! (' .
$s->src . ')', E_USER_NOTICE );
return false;
}
if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
trigger_error(
- "glmScriptRegistry add(): style handle added = " .
+ "GlmScriptRegistry addScript(): style handle added = " .
$script->handle, E_USER_NOTICE );
}
break;
- case glmScriptType::Unknown:
+ case GlmScriptType::Unknown:
defaut:
trigger_error(
- "glmScriptRegistry Script Type Unknown: Plugin = $s->plugin, Script = $s->handle",
+ "GlmScriptRegistry Script Type Unknown: Plugin = $s->plugin, Script = $s->handle",
E_USER_NOTICE );
break;
}
/**
* Find script using fullHandle value
*
- * @param int $type Type - enumerated (see glmScriptType above)
+ * @param int $type Type - enumerated (see GlmScriptType above)
* @param string $fullHandle Full handle for script
*
- * @return glmScriptType Script object or false if not found
+ * @return GlmScriptType Script object or false if not found
*/
- static public function find( $type, $fullHandle )
+ static public function findScript( $type, $fullHandle )
{
switch ( $type ) {
- case glmScriptType::Script:
+ case GlmScriptType::Script:
// Try to find script using fullHandle field
- if ( count( glmScriptRegistry::$_scripts ) ) {
- foreach ( glmScriptRegistry::$_scripts as $script ) {
+ if ( count( GlmScriptRegistry::$_scripts ) ) {
+ foreach ( GlmScriptRegistry::$_scripts as $script ) {
if ( $script->fullHandle == $fullHandle ) {
return $script;
}
break;
- case glmScriptType::Style:
+ case GlmScriptType::Style:
// Try to find style using fullHandle field
- if ( count( glmScriptRegistry::$_styles ) ) {
- foreach ( glmScriptRegistry::$_styles as $style ) {
+ if ( count( GlmScriptRegistry::$_styles ) ) {
+ foreach ( GlmScriptRegistry::$_styles as $style ) {
if ( $style->fullHandle == $fullHandle ) {
return $style;
}
*
* @return void
*/
- static public function reset()
+ static public function resetScripts()
{
if ( count( self::$_scripts ) ) {
/**
* Selectd a script to be enqueued
*
- * @param int $type Type - enumerated (see glmScriptType above)
+ * @param int $type Type - enumerated (see GlmScriptType above)
* @param string $handle Handle of script to be enqueued
*
* @return boolean Success is true
*/
- static public function select( $type, $handle )
+ static public function selectScript( $type, $handle )
{
switch ( $type ) {
- case glmScriptType::Script:
+ case GlmScriptType::Script:
if ( isset( self::$_scripts[$handle] ) ) {
self::$_scripts[$handle]->enqueue = true;
} else {
}
break;
- case glmScriptType::Style:
+ case GlmScriptType::Style:
if ( isset( self::$_styles[$handle] ) ) {
self::$_styles[$handle]->enqueue = true;
} else {
}
break;
- case glmScriptType::Unknown:
+ case GlmScriptType::Unknown:
default:
return false;
break;
*
* @param boolean $enqueuedOnly Return only enqueued scripts and styles
*/
- static public function list( $enqueuedOnly = false)
+ static public function listScripts( $enqueuedOnly = false)
{
// If not enqueued only, return entire list
/**
* Enqueue listed scripts
*/
- static public function enqueue()
+ static public function enqueueScripts()
{
// Scripts
if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
trigger_error(
- "glmScriptRegistry enqueue(): handle = " . $handle .
+ "GlmScriptRegistry enqueueScripts(): handle = " . $handle .
', src = ' . $s->src . ', version = ' . $s->version,
E_USER_NOTICE );
}
if ( GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE ) {
trigger_error(
- "glmScriptRegistry enqueue(): handle = " . $handle,
+ "GlmScriptRegistry enqueueScripts(): handle = " . $handle,
E_USER_NOTICE );
}
}
*/
/**
- * This file registers scripts and styles with the glmScriptRegistry.
+ * This file registers scripts and styles with the GlmScriptRegistry.
*
* Scripts and Styles are added to the registry to ensure consistancy and avoid duplication.
* This process only lists them in the registry. A further step of calling the enqueue()
* it may be the same for a matching script and style (the plugin slug and type prefix the
* 'handle' provided below to make them actually unique).
*
- * int type Required type enumerated (see glmScriptType above)
+ * int type Required type enumerated (see GlmScriptType above)
* string handle Required handle (name) for this script (no spaces or punctuation)
* Handles must be unique for a particular type
* A matching script and style may have the same handle
*
* Example - Please add multi-line comment above each with script src for reference
*
- * glmScriptRegistry::add(
+ * GlmScriptRegistry::addScript(
* [
- * 'type' => glmScriptType::Script,
+ * 'type' => GlmScriptType::Script,
* 'handle' => 'RegApp',
* 'src' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL . '/js/frontRegApp.js',
* 'deps' => array(
/*
* https://unpkg.com/leaflet@1.3.3/dist/leaflet.css
*/
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
[
- 'type' => glmScriptType::Style,
+ 'type' => GlmScriptType::Style,
'handle' => 'Leaflet',
'src' => 'https://unpkg.com/leaflet@1.3.3/dist/leaflet.css',
'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
/*
* https://unpkg.com/leaflet@1.3.3/dist/leaflet.js
*/
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
[
- 'type' => glmScriptType::Script,
+ 'type' => GlmScriptType::Script,
'handle' => 'Leaflet',
'src' => 'https://unpkg.com/leaflet@1.3.3/dist/leaflet.js',
'in_footer' => true,
* {registrations}/js/Leaflet.loading/src/Control.Loading.css
* NOTE - This file is actually in glm-member-db plugin. Need to move this at some point ****
*/
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
[
- 'type' => glmScriptType::Style,
+ 'type' => GlmScriptType::Style,
'handle' => 'LeafletControlLoading',
'src' => GLM_MEMBERS_PLUGIN_URL . 'js/Leaflet.loading/src/Control.Loading.css',
'plugin' => GLM_MEMBERS_REGISTRATIONS_PLUGIN_SLUG,
* GLM_MEMBERS_REGISTRATIONS_PLUGIN_URL/js/Leaflet.loading/src/Control.Loading.js
* NOTE - This file is actually in glm-member-db plugin. Need to move this at some point ****
*/
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
[
- 'type' => glmScriptType::Script,
+ 'type' => GlmScriptType::Script,
'handle' => 'LeafletControlLoading',
'src' => GLM_MEMBERS_PLUGIN_URL . 'js/Leaflet.loading/src/Control.Loading.js',
'in_footer' => true,
/*
* Google Maps API
*/
-glmScriptRegistry::add(
+GlmScriptRegistry::addScript(
[
- 'type' => glmScriptType::Script,
+ 'type' => GlmScriptType::Script,
'handle' => 'GoogleMapsAPI',
'src' => 'https://maps.googleapis.com/maps/api/js?sensor=true&key=' .
$this->config['settings']['google_maps_api_key'],