Hallo, Gast! (Registrieren)

Letzte Ankündigung: MyBB 1.8.38 veröffentlicht (30.04.24)


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
Wie ist ein Plugin aufgebaut?
#9
Da das Einstellungen anlegen im Admin CP etwas umständlich ist, sich dafür aber Einstellungsgruppen sehr leicht samt allen Unterpunkten löschen lassen, hab ichs jetzt so gelöst, daß das Plugin die Einstellungen nicht selbst entfernt. In activate() werden die Gruppen und Einstellungen anlegt, sofern sie noch nicht existieren.

Damit kann man das Plugin auch einfach mal deaktivieren / deinstallieren, und wieder neu installieren, ohne gleich die Einstellungen zu verlieren / auf Standardwerte zurückzusetzen.

Was hier noch fehlt: Sollte sich die Beschreibung einer Einstellung mal ändern, wird die nicht geupdated sofern die Einstellung schon existiert. Aber bei grundlegenden Funktionsänderungen ist es wahrscheinlich eh besser, der Einstellung einen neuen Namen zu geben.

Michael, falls das zu sehr ins Detail / Offtopic für diesen Thread geht - lösche meine Antworten hier einfach wieder.

PHP-Code:
function subforum_bulb_activate()
{
    
/**
     *    Called whenever a plugin is activated via the Admin CP. This should essentially make a plugin
     *    "visible" by adding templates/template changes, language changes etc.
     */

    // Apparently MyBB does not offer a plugin API for creating settings.
    // So we have to meddle with the DB directly. Yay.
    
global $db;

    
// Check if the settings group exists.
    
$query $db->query("SELECT gid FROM ".TABLE_PREFIX."settinggroups WHERE name='subforumbulb'");

    if(
$db->num_rows($query))
    {
        
// It exists, get the gid.
        
$gid $db->fetch_array($query);
        
$gid $gid['gid'];
    }

    else
    {
        
// It does not exist, create it and get the gid.
        
print "group does not exist<br>";
        
$db->insert_query("settinggroups",
                          array(
"gid" => "NULL",
                                
"name" => "subforumbulb",
                                
"title" => "Subforum Bulb",
                                
"description" => "Custom settings for the Subforum Bulb plugin.",
                                
"disporder" => "100",
                                
"isdefault" => "no"));
        
$gid $db->insert_id();
    }

    
// Check if the classic option exists.
    
$query $db->query("SELECT sid FROM ".TABLE_PREFIX."settings WHERE gid=$gid AND name='subforum_bulb_classic'");

    if(
$db->num_rows($query) == 0)
    {
        
// It does not exist, create it.
        
$db->insert_query("settings",
                          array(
"sid" => "NULL",
                                
"name" => "subforum_bulb_classic",
                                
"title" => "Classic Bulbs",
                                
"description" => "When set to YES, Subforum Bulb will stick to the original icons (Default).<br /><br />In this mode all the plugin does is prevent a parent forum to be marked as read when there are actually no new posts (MyBB bugfix).<br /><br />When set to NO, it will make use of new combined icons that show the status of the parent forum and the dominant subforum.",
                                
"optionscode" => "yesno",
                                
"value" => 1,
                                
"disporder" => 1,
                                
"gid" => $gid));
    }

    
// Check if the sorting options exists.
    
$query $db->query("SELECT sid FROM ".TABLE_PREFIX."settings WHERE gid=$gid AND name='subforum_bulb_sort'");

    if(
$db->num_rows($query) == 0)
    {
        
// It does not exist, create it.
        
$db->insert_query("settings",
                          array(
"sid" => "NULL",
                                
"name" => "subforum_bulb_sort",
                                
"title" => "Mini Subforum Sorting",
                                
"description" => "When set to NO, do nothing (Default).<br /><br />When set to YES, it will change the order of the subforums in the mini subforum list (subforum 1, subforum 2, and 3 more) so that it will show more important subforums first (unread &gt; read &gt; locked).",
                                
"optionscode" => "yesno",
                                
"value" => 0,
                                
"disporder" => 2,
                                
"gid" => $gid));
    }

    
// Rebuild the settings file.
    
rebuild_settings();

Zitieren


Nachrichten in diesem Thema
Wie ist ein Plugin aufgebaut? - von Michael - 13.10.2005, 16:32
RE: Wie ist ein Plugin aufgebaut? - von Jan - 01.05.2007, 13:22
RE: Wie ist ein Plugin aufgebaut? - von Michael - 01.05.2007, 13:39
RE: Wie ist ein Plugin aufgebaut? - von Jan - 01.05.2007, 13:46
RE: Wie ist ein Plugin aufgebaut? - von StefanT - 14.11.2008, 18:14
RE: Wie ist ein Plugin aufgebaut? - von Michael - 16.11.2008, 01:24
RE: Wie ist ein Plugin aufgebaut? - von frostschutz - 16.11.2008, 01:41
RE: Wie ist ein Plugin aufgebaut? - von Michael - 16.11.2008, 21:03