forked from w3develops/w3Develops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathossn.lib.plugins.php
More file actions
116 lines (110 loc) · 3.16 KB
/
Copy pathossn.lib.plugins.php
File metadata and controls
116 lines (110 loc) · 3.16 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* Open Source Social Network
*
* @package (softlab24.com).ossn
* @author OSSN Core Team <info@softlab24.com>
* @copyright (C) SOFTLAB24 LIMITED
* @license Open Source Social Network License (OSSN LICENSE) http://www.opensource-socialnetwork.org/licence
* @link https://www.opensource-socialnetwork.org/
*/
/**
* Register a plugins by path
* This will help us to override components files easily.
*
* @param string $path A valid path;
* @return boolean
*/
function ossn_register_plugins_by_path($path) {
global $Ossn;
if(ossn_site_settings('cache') == 1) {
return false;
}
if(!is_dir($path)) {
//disable error log, will cause a huge log file
//error_log("Ossn tried to register invalid plugins by path: {$path}");
return false;
}
$path = str_replace("\\", "/", $path);
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($directory);
if($iterator) {
foreach($iterator as $file) {
if(pathinfo($file, PATHINFO_EXTENSION) == "php") {
$file = str_replace("\\", "/", $file);
$location = str_replace(dirname(__FILE__) . '/plugins/', '', $file);
$name = str_replace($path, '', $location);
$name = substr($name, 0, -4);
$name = explode('/', $name);
$plugin_type = $name[0];
unset($name[0]);
$name = implode('/', $name);
$fpath = substr($file, 0, -4);
$fpath = str_replace(array(
$name,
ossn_route()->www
), '', $fpath);
$Ossn->plugins[$plugin_type][$name] = $fpath;
}
}
}
return true;
}
/**
* View a plugin
* Plugins are registered using ossn_register_plugins_by_path()
*
* @param string $plugin A valid plugin name;
* @param array|object $vars A valid arrays or object
* @return void|mixed
*/
function ossn_plugin_view($plugin = '', $vars = array(), $type = 'default') {
global $Ossn;
$args = array(
'plugin' => $plugin
);
$plugin_type = ossn_call_hook('plugin', 'view:type', $args, $type);
if(isset($Ossn->plugins[$plugin_type][$plugin])) {
$extended_views = ossn_fetch_extend_views($plugin, $vars);
return ossn_view($Ossn->plugins[$plugin_type][$plugin] . $plugin, $vars) . $extended_views;
}
}
/**
* Unregister a plugin view
* We need this if we want to disable a plugin view.
*
* @param string $plugin A valid plugin name;
* @return void
*/
function ossn_uregister_plugin_view($plugin) {
global $Ossn;
if(isset($Ossn->plugins[$plugin])) {
unset($Ossn->plugins[$plugin]);
}
}
/**
* Generate a paths for plugins for cache
*
* @return string|false
*/
function ossn_plugins_cache_paths() {
$file = ossn_get_userdata("system/plugins_paths");
if(is_file($file) && ossn_site_settings('cache') == 1) {
$file = file_get_contents($file);
return json_decode($file, true);
}
return false;
}
/**
* If cache enabled then load paths for cache
*
* @return void;
*/
function ossn_plugin_set() {
$paths = ossn_plugins_cache_paths();
if($paths) {
global $Ossn;
$Ossn->plugins = $paths;
}
}
ossn_plugin_set();