Author Topic: [Mod] Sort the plugin list alphabetical  (Read 23561 times)

0 Members and 1 Guest are viewing this topic.

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
[Mod] Sort the plugin list alphabetical
« on: September 06, 2012, 09:51:11 AM »
Hi,

I have many plugins in the ACP plugins and I need to sort them (A-Z).

I know that we need to use something like $files = array() and sort($files)
Can someone help me to do that?


if (@is_dir("plugins")) {
            
show_nav_header("PlugIns");
            
$handle = @opendir("plugins/");
            while (
$file = @readdir($handle)) {
              if (
get_file_extension($file) != "php") {
                continue;
              }
              
$plugin_file file("./plugins/".$file);
	
	
	
  
              
$plugin_file[0] = trim($plugin_file[0]);
              if (
preg_match("/PLUGIN_TITLE:(.+)/"$plugin_file[0], $regs)) {
                
show_nav_option(trim($regs[1]), "./plugins/".$file);
              }
              else {
                
show_nav_option($file"./plugins/".$file);
              }
            }
            @
closedir($handle);
          }



Thank you in advance,

Rembrandt

  • Guest
Re: [Mod] Sort the plugin list alphabetical
« Reply #1 on: September 06, 2012, 02:49:40 PM »
Hi!

search in admin/ndex.php

          
if (@is_dir("plugins")) {
            
show_nav_header("PlugIns");
            
$handle = @opendir("plugins/");
            while (
$file = @readdir($handle)) {
              if (
get_file_extension($file) != "php") {
                continue;
              }
              
$plugin_file file("./plugins/".$file);
              
$plugin_file[0] = trim($plugin_file[0]);
              if (
preg_match("/PLUGIN_TITLE:(.+)/"$plugin_file[0], $regs)) {
                
show_nav_option(trim($regs[1]), "./plugins/".$file);
              }
              else {
                
show_nav_option($file"./plugins/".$file);
              }
            }
            @
closedir($handle);
          }

and replace:

          
if (@is_dir("plugins")) {
            
show_nav_header("PlugIns");
            
$handle = @opendir("plugins/");
            while (
$file = @readdir($handle)) {
              if (
get_file_extension($file) != "php") {
                continue;
              }
              
$mysort[] = $file
            }
//while
            
@closedir($handle);
            
            
sort($mysort); // sort the array here
            
            
foreach($mysort as $file) {    
              
$plugin_file file("./plugins/".$file);
              
$plugin_file[0] = trim($plugin_file[0]);
              if (
preg_match("/PLUGIN_TITLE:(.+)/"$plugin_file[0], $regs)) {
                
show_nav_option(trim($regs[1]), "./plugins/".$file);
              }
              else {
                
show_nav_option($file"./plugins/".$file);
              }
            }
//foreach
          
}


mfg Andi
« Last Edit: September 06, 2012, 02:59:59 PM by Rembrandt »

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: [Mod] Sort the plugin list alphabetical
« Reply #2 on: September 06, 2012, 02:54:50 PM »
Thank Andy. It works perfect.

Have a nice day.

Offline Sunny C.

  • Addicted member
  • ******
  • Posts: 1.808
  • I ♥ 4I
    • View Profile
Re: [Mod] Sort the plugin list alphabetical
« Reply #3 on: September 09, 2019, 05:01:11 PM »
For PHP/*

    
if (@is_dir("plugins")) {
        
show_nav_header("PlugIns");
        
$fileList glob('./plugins/*.php');
        
sort($fileList);
        foreach (
$fileList as $filename) {
            
//Use the is_file function to make sure that it is not a directory.
            
if (is_file($filename)) {
                
$plugin_file    file($filename);
                
$plugin_file[0] = trim($plugin_file[0]);
                if (
preg_match("/PLUGIN_TITLE:(.+)/"$plugin_file[0], $regs)) {
                    
show_nav_option(trim($regs[1]), $filename);
                } else {
                    
show_nav_option($filename$filename);
                }
            }
        }
    }