1
difenduandada
2024-10-15 7fd2948ee35c8e147ed35ce6d8502f94a98ddd22
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
<?php
 
defined('ABSPATH') or die('abcd');
 
define('PLUGIN_PATH', 'content/plugins/');
 
$plugin_footer = [];
$plugin_header = [];
$plugin_list = get_plugin_list();
 
function get_plugin_list(){
    global $plugin_footer;
    global $plugin_header;
    $list = [];
    $dirs = scan_folder( PLUGIN_PATH );
    foreach ($dirs as $dir) {
        $info = get_plugin_info($dir);
        if($info){
            array_push($list, $info);
            if(file_exists($info['path'].'/footer.php')){
                $plugin_footer[] = ABSPATH.PLUGIN_PATH.$info['dir_name'].'/footer.php';
            }
            if(file_exists($info['path'].'/header.php')){
                $plugin_header[] = ABSPATH.PLUGIN_PATH.$info['dir_name'].'/header.php';
            }
        }
    }
    return $list;
}
 
function get_plugin_info($name){
    $plugin_dir = ABSPATH . PLUGIN_PATH . $name;
    $json_path = $plugin_dir . '/info.json';
 
    if(file_exists($json_path)){
        $array = json_decode(file_get_contents($json_path), true);
        if(isset($array['name']) && isset($array['version']) && isset($array['author']) && isset($array['description']) && isset($array['require_version']) && isset($array['tested_version']) && isset($array['type']) && isset($array['target'])){
            $array['path'] = $plugin_dir;
            $array['dir_name'] = $name;
            return $array;
        }
        return false;
    }
    return false;
}
 
function is_plugin_exist($name){
    global $plugin_list;
 
    foreach ($plugin_list as $plugin) {
        if($plugin['dir_name'] == $name){
            return true;
        }
    }
    return false;
}
 
function load_plugins($type){
    global $plugin_list;
    foreach ($plugin_list as $plugin) {
        if($plugin['target'] == $type){
            if(substr($plugin['dir_name'], 0, 1) != '_'){
                if(file_exists($plugin['path'] . '/public.php')){
                    require_once($plugin['path'] . '/public.php');
                } else if(file_exists($plugin['path'].'/main.php')) {
                    // since v1.7.8 main.php is deprecated, use public.php instead
                    // this used for backward compatibility
                    require_once($plugin['path'] . '/main.php');
                }
            }
        }
    }
}
 
function load_plugin_headers(){
    global $plugin_header;
    if(count($plugin_header)){
        foreach ($plugin_header as $hd) {
            include_once $hd;
        }
    }
}
 
function load_plugin_footers(){
    global $plugin_footer;
    if(count($plugin_footer)){
        foreach ($plugin_footer as $ft) {
            include_once $ft;
        }
    }
}
 
?>