This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AvocaPluginFramework.php
102 lines (79 loc) · 2.85 KB
/
AvocaPluginFramework.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/*
Plugin Name: Avoca Plugin Framework
Plugin URI: https://github.com/avocaweb/avoca-plugin-framework
Description: Serves as an extendable base enabling rapid development of modularized Wordpress plugins
Version: 0.2
Author: Adam Bosco
Author URI: http://github.com/KuroTsuto
*/
/* A singleton serving to load the framework, establish the JS api */
class AvocaPluginFramework {
const VERSION = '0.2'; //APF Version
const FORCE_DEBUG = FALSE; //Force debug mode for ALL active AvocaPlugins
private static $_instance; //THERE CAN BE ONLY ONE
private static $_directories; //Array of APF directories for quick reference
private static $_uris; //Array of APF URIs for quick reference
private static $_plugins; //Array of active Avoca Plugins
private static $_jsApiConfigs;
private static $_jsApiFactoryScriptHandle = 'avoca-jsapifactory';
public function __construct( $strFrameworkDirectory ) {
self::_setupPaths( $strFrameworkDirectory );
self::_loadFramework();
}
public static function instance() {
if( isset( self::$_instance ) )
return self::$_instance;
return self::$_instance = new AvocaPluginFramework( __DIR__ );
}
public static function addPlugin( $pluginFile ) {
}
public static function getDir( $strDirType = 'root' ) {
return self::$_directories[ $strDirType ];
}
public static function getUri( $strUriType = 'root' ) {
return self::$_uris[ $strUriType ];
}
public static function registerJsApi( $pluginInstance, $componentData ) {
$data = array(
'name' => $pluginInstance->name,
'className' => $pluginInstance->pluginClass,
'domain' => $pluginInstance->domain,
'securityKey' => $pluginInstance->securityKey,
'ajaxUrl' => admin_url('admin-ajax.php'),
'components' => $componentData
);
$configVar = $data['domain'] . 'Config';
self::$_jsApiConfigs[ $configVar ] = $data;
}
public static function enqueueScripts() {
wp_enqueue_script(
self::$_jsApiFactoryScriptHandle,
self::getUri( 'scripts' ) . '/js-api-factory.js',
array( 'jquery' ),
self::VERSION
);
wp_localize_script( self::$_jsApiFactoryScriptHandle, 'AvocaPluginJsApiConfigurations', self::$_jsApiConfigs );
}
private static function _setupPaths( $strRootDir ) {
self::$_directories = array(
'root' => $strRootDir,
'includes' => $strRootDir . '/includes',
'scripts' => $strRootDir . '/js',
'styles' => $strRootDir . '/css'
);
$strRootURI = plugins_url( '', __FILE__ );
self::$_uris = array(
'root' => $strRootURI,
'scripts' => $strRootURI . '/js',
'styles' => $strRootURI . '/css'
);
}
private static function _loadFramework() {
$includesDir = self::getDir( 'includes' );
require( $includesDir . '/AvocaPlugin.php' );
require( $includesDir . '/AvocaPluginComponent.php' );
}
}
AvocaPluginFramework::instance();
echo(AvocaPluginFramework::getDir('scripts'));