4images Modifications / Modifikationen > Mods & Plugins (Releases & Support)

[Mod] Sort the plugin list alphabetical

(1/1)

Sun Zaza:
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:
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

Sun Zaza:
Thank Andy. It works perfect.

Have a nice day.

qBass17:
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);
                }
            }
        }
    }

Navigation

[0] Message Index

Go to full version