Esempio n. 1
0
function get_plugins($path = PLUGIN_PATH, $app = APP_NAME, $ext = '.php')
{
    static $plugins = array();
    if (isset($plugins[$app])) {
        return $plugins[$app];
    }
    if (empty_dir($path)) {
        return array();
    }
    $path = realpath($path);
    $dir = dir($path);
    if ($dir) {
        $plugin_files = array();
        while (false !== ($file = $dir->read())) {
            if ($file == "." || $file == "..") {
                continue;
            }
            if (is_dir($path . '/' . $file)) {
                $subdir = dir($path . '/' . $file);
                if ($subdir) {
                    while (($subfile = $subdir->read()) !== false) {
                        if ($subfile == "." || $subfile == "..") {
                            continue;
                        }
                        if (preg_match('/\\.php$/', $subfile)) {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    $subdir->close();
                }
            } else {
                $plugin_files[] = $file;
            }
        }
        $dir->close();
        if (count($plugin_files) > 1) {
            sort($plugin_files);
        }
        $plugins[$app] = array();
        foreach ($plugin_files as $plugin_file) {
            if (!is_readable($path . '/' . $plugin_file)) {
                continue;
            }
            $plugins[$app][] = $path . '/' . $plugin_file;
        }
        return $plugins[$app];
    } else {
        return array();
    }
}
Esempio n. 2
0
/**
+----------------------------------------------------------
* 读取插件
+----------------------------------------------------------
* @param string $path 插件目录
* @param string $app 所属项目名
+----------------------------------------------------------
* @return Array
+----------------------------------------------------------
*/
function get_plugins($path = PLUGIN_PATH, $app = APP_NAME, $ext = '.php')
{
    static $plugins = array();
    if (isset($plugins[$app])) {
        return $plugins[$app];
    }
    // 如果插件目录为空 返回空数组
    if (empty_dir($path)) {
        return array();
    }
    $path = realpath($path);
    // 缓存无效 重新读取插件文件
    /*
        $dir = glob ( $path . '/*' );
        if($dir) {
    foreach($dir as $val) {
         if(is_dir($val)){
             $subdir = glob($val.'/*'.$ext);
             if($subdir) {
                 foreach($subdir as $file)
                     $plugin_files[] = $file;
             }
         }else{
             if (strrchr($val, '.') == $ext)
                 $plugin_files[] = $val;
         }
    }
    */
    $dir = dir($path);
    if ($dir) {
        $plugin_files = array();
        while (false !== ($file = $dir->read())) {
            if ($file == "." || $file == "..") {
                continue;
            }
            if (is_dir($path . '/' . $file)) {
                $subdir = dir($path . '/' . $file);
                if ($subdir) {
                    while (($subfile = $subdir->read()) !== false) {
                        if ($subfile == "." || $subfile == "..") {
                            continue;
                        }
                        if (preg_match('/\\.php$/', $subfile)) {
                            $plugin_files[] = "{$file}/{$subfile}";
                        }
                    }
                    $subdir->close();
                }
            } else {
                $plugin_files[] = $file;
            }
        }
        $dir->close();
        //对插件文件排序
        if (count($plugin_files) > 1) {
            sort($plugin_files);
        }
        $plugins[$app] = array();
        foreach ($plugin_files as $plugin_file) {
            if (!is_readable("{$path}/{$plugin_file}")) {
                continue;
            }
            //取得插件文件的信息
            $plugin_data = get_plugin_info("{$path}/{$plugin_file}");
            if (empty($plugin_data['name'])) {
                continue;
            }
            $plugins[$app][] = $plugin_data;
        }
        return $plugins[$app];
    } else {
        return array();
    }
}