ossn.lib.plugins.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Open Source Social Network
4  *
5  * @package (Informatikon.com).ossn
6  * @author OSSN Core Team <[email protected]>
7  * @copyright 2014 iNFORMATIKON TECHNOLOGIES
8  * @license General Public Licence http://www.opensource-socialnetwork.org/licence
9  * @link http://www.opensource-socialnetwork.org/licence
10  */
11 /**
12  * Register a plugins by path
13  * This will help us to override components files easily.
14  *
15  * @param string $path A valid path;
16  * @return boolean
17  */
19  global $Ossn;
20 
21  if(ossn_site_settings('cache') == 1) {
22  return false;
23  }
24  if(!is_dir($path)) {
25  //disable error log, will cause a huge log file
26  //error_log("Ossn tried to register invalid plugins by path: {$path}");
27  return false;
28  }
29  $path = str_replace("\\", "/", $path);
30  $directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
31  $iterator = new RecursiveIteratorIterator($directory);
32  if($iterator) {
33  foreach($iterator as $file) {
34  if(pathinfo($file, PATHINFO_EXTENSION) == "php") {
35  $file = str_replace("\\", "/", $file);
36  $location = str_replace(dirname(__FILE__) . '/plugins/', '', $file);
37 
38  $name = str_replace($path, '', $location);
39  $name = substr($name, 0, -4);
40  $name = explode('/', $name);
41 
42  $plugin_type = $name[0];
43  unset($name[0]);
44 
45  $name = implode('/', $name);
46 
47  $fpath = substr($file, 0, -4);
48  $fpath = str_replace(array(
49  $name,
50  ossn_route()->www
51  ), '', $fpath);
52 
53  $Ossn->plugins[$plugin_type][$name] = $fpath;
54  }
55  }
56  }
57  return true;
58 }
59 /**
60  * View a plugin
61  * Plugins are registered using ossn_register_plugins_by_path()
62  *
63  * @param string $plugin A valid plugin name;
64  * @param array|object $vars A valid arrays or object
65  * @return void|mixed
66  */
67 function ossn_plugin_view($plugin = '', $vars = array(), $type = 'default') {
68  global $Ossn;
69  $args = array(
70  'plugin' => $plugin
71  );
72  $plugin_type = ossn_call_hook('plugin', 'view:type', $args, $type);
73  if(isset($Ossn->plugins[$plugin_type][$plugin])) {
74  $extended_views = ossn_fetch_extend_views($plugin, $vars);
75  return ossn_view($Ossn->plugins[$plugin_type][$plugin] . $plugin, $vars) . $extended_views;
76  }
77 }
78 /**
79  * Unregister a plugin view
80  * We need this if we want to disable a plugin view.
81  *
82  * @param string $plugin A valid plugin name;
83  * @return void
84  */
85 function ossn_uregister_plugin_view($plugin) {
86  global $Ossn;
87  if(isset($Ossn->plugins[$plugin])) {
88  unset($Ossn->plugins[$plugin]);
89  }
90 }
91 /**
92  * Generate a paths for plugins for cache
93  *
94  * @return string|false
95  */
97  $file = ossn_get_userdata("system/plugins_paths");
98  if(is_file($file) && ossn_site_settings('cache') == 1) {
99  $file = file_get_contents($file);
100  return json_decode($file, true);
101  }
102  return false;
103 }
104 /**
105  * If cache enabled then load paths for cache
106  *
107  * @return void;
108  */
109 function ossn_plugin_set() {
110  $paths = ossn_plugins_cache_paths();
111  if($paths) {
112  global $Ossn;
113  $Ossn->plugins = $paths;
114  }
115 }