4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: Sun Zaza on September 06, 2012, 09:51:11 AM

Title: [Mod] Sort the plugin list alphabetical
Post by: Sun Zaza 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,
Title: Re: [Mod] Sort the plugin list alphabetical
Post by: Rembrandt 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
Title: Re: [Mod] Sort the plugin list alphabetical
Post by: Sun Zaza on September 06, 2012, 02:54:50 PM
Thank Andy. It works perfect.

Have a nice day.
Title: Re: [Mod] Sort the plugin list alphabetical
Post by: Sunny C. 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);
                }
            }
        }
    }