V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xinyana
V2EX  ›  程序员

xiunoBBS 后台插件排序方法--启用的排前面

  •  
  •   xinyana · 2020-10-22 14:09:48 +08:00 · 627 次点击
    这是一个创建于 1279 天前的主题,其中的信息可能已经有所发展或是发生改变。

    xiunoBBS 后台插件默认是按照插件路径排序,也可以理解为按照插件作者(英文缩写)排序

    但是后台看起来就有点乱,找自己启用的插件要翻老半天

    先上排序后的效果,有没有变清爽: paixu.png

    排序方法

    这个效果功能懒得开发成插件,而且几乎为必备修改,直接改源码

    将文件/model/plugin.func.php第 53 行的plugin_init()函数修改为以下代码,同时增加函数array_sort()即可,完整代码如下:

    // 在安装、卸载插件的时候,需要先初始化
    function plugin_init() {
    	global $plugin_srcfiles, $plugin_paths, $plugins, $official_plugins;
    	$plugin_paths = glob(APP_PATH.'plugin/*', GLOB_ONLYDIR);
    	if(is_array($plugin_paths)) {
    		foreach($plugin_paths as $path) {
    			$dir = file_name($path);
    			$conffile = $path."/conf.json";
    			if(!is_file($conffile)) continue;
    			$arr = xn_json_decode(file_get_contents($conffile));
    			if(empty($arr)) continue;
    			$plugins[$dir] = $arr;
    			
    			// 额外的信息
    			$plugins[$dir]['hooks'] = array();
    			$hookpaths = glob(APP_PATH."plugin/$dir/hook/*.*"); // path
    			if(is_array($hookpaths)) {
    				foreach($hookpaths as $hookpath) {
    					$hookname = file_name($hookpath);
    					$plugins[$dir]['hooks'][$hookname] = $hookpath;
    				}
    			}
    			
    			// 本地 + 线上数据
    			$plugins[$dir] = plugin_read_by_dir($dir);
    		}
    		//插件排序,依赖于自定义函数 array_sort()
    		$plugins = array_sort($plugins,'installed','desc');
    		$plugins = array_sort($plugins,'enable','desc');
    		
    	}
    }
    
    //二维数组排序
    function array_sort($arr,$keys,$type='asc'){ 
    	$keysvalue = $new_array = array();
    	foreach ($arr as $k=>$v){
    		$keysvalue[$k] = $v[$keys];
    	}
    	if($type == 'asc'){
    		asort($keysvalue);
    	}else{
    		arsort($keysvalue);
    	}
    	reset($keysvalue);
    	foreach ($keysvalue as $k=>$v){
    		$new_array[$k] = $arr[$k];
    	}
    	return $new_array; 
    } 
    

    转发自: https://www.gezhong.vip/thread-29.htm

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3411 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:07 · PVG 20:07 · LAX 05:07 · JFK 08:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.