Knowledge Base Funktion für Template Parsing ändern

In diesem Forum kann man Fragen zur Programmierung stellen, die bei der Entwicklung von Mods für phpBB 3.0.x oder dem Modifizieren des eigenen Forums auftauchen.
Forumsregeln
phpBB 3.0 hat das Ende seiner Lebenszeit überschritten
phpBB 3.0 wird nicht mehr aktiv unterstützt. Insbesondere werden - auch bei Sicherheitslücken - keine Patches mehr bereitgestellt. Der Einsatz von phpBB 3.0 erfolgt daher auf eigene Gefahr. Wir empfehlen einen Umstieg auf die neuste phpBB-Version, welches aktiv weiterentwickelt wird und für welches regelmäßig Updates zur Verfügung gestellt werden.
Antworten
Benutzeravatar
WileCoyote
Mitglied
Beiträge: 901
Registriert: 13.07.2011 07:38
Wohnort: Österreich

Knowledge Base Funktion für Template Parsing ändern

Beitrag von WileCoyote »

Ich würde mal die Hilfe eines erfahrenen Coders benötigen.
Da es im Moment keine brauchbare Alternative gibt teste ich gerade die [ABD] PhpBB3 Knowledge Base MOD.
In der Datei includes/functions_kb_plugins.php gibt es folgende Funktion zum Parsen der Plugin Templates

Code: Alles auswählen

/**
* Parse a template and return the parsed text
*
* This function should be used for ALL plugins that normally use $template->assign_display to output data with the plugin system.
*/
function kb_parse_template($filename, $template_file)
{
	global $phpbb_root_path, $template, $user;

	$tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/kb/plugins/';
	
	// If the template file does not exist
	if (!file_exists($tpl_path . $template_file))
	{
		$error = sprintf($user->lang['PLUGIN_TEMPLATE_MISSING'], $template_file);
	
		trigger_error($error);
	}
	
	$template_path = 'kb/plugins/';

	$template->set_filenames(array(
		$filename		=> $template_path . $template_file,
	));

	// return the output
	return $template->assign_display($filename);
}
Das Problem ist, dass damit keine "Template inheritance" funktioniert. Daher habe ich die Zeile:

Code: Alles auswählen

	$tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/kb/plugins/';
dadurch ersetzt

Code: Alles auswählen

    if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/kb/plugins/'))
	{
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/kb/plugins/';	   
	}
	else if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/kb/plugins/'))
    {
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/kb/plugins/';	           
    }
Das funktioniert zwar, ich habe aber das Gefühl, dass man das besser lösen könnte. Weiß jemand Rat?
Zuletzt geändert von WileCoyote am 03.02.2012 06:07, insgesamt 1-mal geändert.
Gruß WileCoyote
Benutzeravatar
Miriam
Mitglied
Beiträge: 12310
Registriert: 13.10.2004 07:18
Kontaktdaten:

Re: Knowledge Base Funktion für Template Parsing ändern

Beitrag von Miriam »

So vllt? ->

Code: Alles auswählen

function kb_parse_template($filename, $template_file)
{
    global $phpbb_root_path, $template, $user;

    if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
    {
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/kb/plugins/';
        
        // If the template file does not exist
        if (!@file_exists($tpl_path . $template_file))
        {
            $error = sprintf($user->lang['PLUGIN_TEMPLATE_MISSING'], $template_file);
            trigger_error($error);
        }
    }
    $tpl_path = 'kb/plugins/';

    $template->set_filenames(array(
        $filename      => $tpl_path . $template_file,
    ));

    // return the output
    return $template->assign_display($filename);
} 
(Hab's nicht getestet.)
Gruss, Miriam.
Ich schmeiß' alles hin und...
... lasse es liegen
Benutzeravatar
WileCoyote
Mitglied
Beiträge: 901
Registriert: 13.07.2011 07:38
Wohnort: Österreich

Re: Knowledge Base Funktion für Template Parsing ändern

Beitrag von WileCoyote »

Eben getestet und funktioniert. Danke dir. Ich wußte doch, dass man das besser lösen kann. Muß da wohl noch viel lernen.
Gruß WileCoyote
Benutzeravatar
Miriam
Mitglied
Beiträge: 12310
Registriert: 13.10.2004 07:18
Kontaktdaten:

Re: Knowledge Base Funktion für Template Parsing ändern

Beitrag von Miriam »

Ich auch... :grin: Probiere mal den hier:

Code: Alles auswählen

function kb_parse_template($filename, $template_file)
{
    global $phpbb_root_path, $template, $user;

    if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'])
    {
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/kb/plugins/';
        
        // If the template file does not exist
        if (!@file_exists($tpl_path . $template_file))
        {
            $error = sprintf($user->lang['PLUGIN_TEMPLATE_MISSING'], $template_file);
            trigger_error($error);
        }
    }
    else
    {
        $tpl_path = 'kb/plugins/';
    }
    
    $template->set_filenames(array(
        $filename      => $tpl_path . $template_file,
    ));

    // return the output
    return $template->assign_display($filename);
}  
Bei dem anderen hat was gefehlt. *hüstel*
Gruss, Miriam.
Ich schmeiß' alles hin und...
... lasse es liegen
Benutzeravatar
WileCoyote
Mitglied
Beiträge: 901
Registriert: 13.07.2011 07:38
Wohnort: Österreich

Re: Knowledge Base Funktion für Template Parsing ändern

Beitrag von WileCoyote »

Also im Gegensatz zur vorherigen Variante funktioniert die nicht

Code: Alles auswählen

Allgemeiner Fehler
template->_tpl_load_file(): File ./styles/prosilver/template/./styles/prosilver/template/kb/plugins/request_list.html does not exist or is empty
Edit: Ich glaube, folgender Code sollte richtig sein

Code: Alles auswählen

function kb_parse_template($filename, $template_file)
{
    global $phpbb_root_path, $template, $user;
    
    //Inherited
    if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherit_path'])
    {
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/kb/plugins/';        
    }
    //not inherited
    else
    {
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/kb/plugins/';
    }
    
    // If the template file does not exist
    if (!@file_exists($tpl_path . $template_file))
    {
        $error = sprintf($user->lang['PLUGIN_TEMPLATE_MISSING'], $template_file);
    
        trigger_error($error);
    }        
    
    $template_path = 'kb/plugins/';
    
    $template->set_filenames(array(
        $filename        => $template_path . $template_file,
    ));
    
    // return the output
    return $template->assign_display($filename);
}
 
Gruß WileCoyote
Benutzeravatar
Miriam
Mitglied
Beiträge: 12310
Registriert: 13.10.2004 07:18
Kontaktdaten:

Re: Knowledge Base Funktion für Template Parsing ändern

Beitrag von Miriam »

Ich neme alles zurück und behaupte das Gegenteil :D
Mein erster Code war richtig. Deiner ist es auch.

In deinem Code ist das hier nicht nötig ->

Code: Alles auswählen

    //not inherited
    else
    {
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/kb/plugins/';
    } 
Sollte das Template nicht vererbt worden sein, bekommst du ohnehin eine Fehlermeldung. Falls die kommt, hast du generell ein Problem mit deinem Template. Von daher ist die Abfrage eigentlich sinnlos.
Somit kannst du die Abfrage komplett auf die "Vererbung" konzentrieren, und die Abfrage, ob die "vererbte" Template Datei da ist, in diese IF Abfrage bauen... Spart eine IF-Abfrage.
Und dann sieht dein Code so aus, wie der, den ich als erstes gepostet hatte. ->

Code: Alles auswählen

    //Inherited
    if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherit_path'])
    {
        $tpl_path = $phpbb_root_path . 'styles/' . $user->theme['template_inherit_path'] . '/template/kb/plugins/';        
     
        // If the template file does not exist
        if (!@file_exists($tpl_path . $template_file))
        {
            $error = sprintf($user->lang['PLUGIN_TEMPLATE_MISSING'], $template_file);
    
            trigger_error($error);
        } 
    } 
Gruss, Miriam.
Ich schmeiß' alles hin und...
... lasse es liegen
Benutzeravatar
WileCoyote
Mitglied
Beiträge: 901
Registriert: 13.07.2011 07:38
Wohnort: Österreich

Re: Knowledge Base Funktion für Template Parsing ändern

Beitrag von WileCoyote »

Hallo Miriam,
prinzipiell hast du recht. Ich habe mich letztendlich für diese Variante entschieden, weil die Abfrage für nicht vererbte Templates in der original Fassung der Datei vorhanden ist. Wahrscheinlich wollten die Autoren dadurch sicher stellen, dass das Plugin-Verzeichnis tatsächlich existiert. Sie hatten einfach die Vererbung nicht bedacht. Bevor ich mich zu der von mir geposteten Veriante entschloss, war ich zum selben Ergebnis gekommen, wie du mit deinem letzten Beitrag.
Gruß WileCoyote
Antworten

Zurück zu „[3.0.x] Mod Bastelstube“