Plugins + Extensions

altarvic
2013-05-13
2013-06-06
  • altarvic
    altarvic
    2013-05-13

    Hi,

    I want to use some plugins as it's shows here: http://www.adminer.org/en/plugins/
    At the same time, I want to use an extension from here: http://www.adminer.org/en/extension/
    In both examples we create adminer_object() function, but the returning results are different (AdminerPlugin vs. AdminerSoftware).

    What should I do in this case?

     
  • Jakub Vrána
    Jakub Vrána
    2013-05-13

    /* It is possible to combine customization and plugins:
    class AdminerCustomization extends AdminerPlugin {
    }
    return new AdminerCustomization($plugins);
    */

    http://www.adminer.org/en/plugins/#use

     
  • altarvic
    altarvic
    2013-05-13

    I don't need to extend AdminerPlugin class, I want to extend Adminer class

     
  • Jakub Vrána
    Jakub Vrána
    2013-05-13

    If you want to use both customization and plugins then you want to extend AdminerPlugin class.

     
  • altarvic
    altarvic
    2013-05-13

    I want plugins and extensions ("overwrite some default Adminer functionality by a custom code").

    From your examples:
    Plugins:

    function [b]adminer_object() [/b]{
        // required to run any plugin
        include_once "./plugins/plugin.php";
        
        // autoloader
        foreach (glob("plugins/*.php") as $filename) {
            include_once "./$filename";
        }
        
        $plugins = array(
            // specify enabled plugins here
            new AdminerDumpXml,
            new AdminerTinymce,
            new AdminerFileUpload("data/"),
            new AdminerSlugify,
            new AdminerTranslation,
            new AdminerForeignSystem,
        );
        
        /* It is possible to combine customization and plugins:
        class AdminerCustomization extends AdminerPlugin {
        }
        return new AdminerCustomization($plugins);
        */
        
        return new AdminerPlugin($plugins);
    }
    

    Extensions:

    function [b]adminer_object()[/b] {
        
        class AdminerSoftware extends Adminer {
            
            function name() {
                // custom name in title and heading
                return 'Software';
            }
            
            function permanentLogin() {
                // key used for permanent login
                return "2286d609676f3013d17dfd6481037303";
            }
            
            function credentials() {
                // server, username and password for connecting to database
                return array('localhost', 'ODBC', '');
            }
            
            function database() {
                // database name, will be escaped by Adminer
                return 'software';
            }
            
            function login($login, $password) {
                // validate user submitted credentials
                return ($login == 'admin' && $password == '');
            }
            
            function tableName($tableStatus) {
                // tables without comments would return empty string and will be ignored by Adminer
                return h($tableStatus["Comment"]);
            }
            
            function fieldName($field, $order = 0) {
                // only columns with comments will be displayed and only the first five in select
                return ($order <= 5 && !ereg('_(md5|sha1)$', $field["field"]) ? h($field["comment"]) : "");
            }
            
        }
        
        return new AdminerSoftware;
    }
    

    In both your examples function adminer_object() returns various results?
    I don't understand how to combine both above examples.

     
  • Jakub Vrána
    Jakub Vrána
    2013-05-13

    It's written right in the plugins example. Just uncomment AdminerCustomization definition and initialization and you are done. You can put your custom methods inside AdminerCustomization.

     
  • altarvic
    altarvic
    2013-05-14

    Got it! Thank you for your help!