4.5.2: Extract caption from the xml language file

Gesperrt
m.wohlers
Beiträge: 93
Registriert: Di 25. Mai 2004, 16:11
Wohnort: Bad Aibling
Kontaktdaten:

4.5.2: Extract caption from the xml language file

Beitrag von m.wohlers »

Hallo timo!

Im neuen Snapshot vom 14.01.2005 findet sich mehrmals folgender neuer Code:
# Extract caption from the xml language file
# including plugins third level
# extended multilang version
if(strstr($db->f("location"), ';')) {

$locs = explode(";", $db->f("location"));
$file = trim($locs[0]);
$xpath = trim($locs[1]);

$filepath = explode('/',$file);
$counter = count($filepath)-1;

if ($filepath[$counter] == "") {
unset($filepath[$counter]);
$counter--;
}

if(strstr($filepath[$counter], '.xml')) {
$filename = $filepath[$counter];
unset($filepath[$counter]);
$counter--;
}

$filepath[($counter+1)] = "";

$filepath = implode("/",$filepath);

if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $cfg['lang'][$belang]) == false)
{
if (!isset($filename)) { $filename = 'lang_en_US.xml'; }
if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $filename) == false)
{
die("Unable to load any XML language file");
}
}
$caption = $plugxml->valueOf( $cfgPath['xmlroot'] . $xpath );
unset($file, $filename, $filepath);
} else {
$caption = $xml->valueOf( $cfgPath['xmlroot'] . $db->f("location") );
}
Wäre es nicht sinnvoller, daß in irgendeine functions.xxx.php auszulagern? Ist ja doch immer wieder dasselbe...

Mit morgendlichen Grüßen...
Michael Wohlers
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

ja ist sinnvoll, aber zuerst muss mal getestet werden ob das wirklich so überall läuft...

momentan wird das verwendet in allen
include*subnav.php dateien
rights_area.inc.php
grouprights_area.inc.php
class.navigation.php

ich selbst habe die auslagerung in class.navigation.php zwar schon vorgenommen, bin aber noch nicht ganz fertig damit...

als bug würd ich das momentan nicht werten... eher als cleanup

wichtig ist zuerst das mal alles halbwegs vereinheitlicht ist...
sobald mal
http://www.contenido.org/forum/viewtopic.php?t=5258
und
http://www.contenido.org/forum/viewtopic.php?t=5583 (fixed -> contenido-cvs-2005-01-18.tar.bz2 )
drinnen ist gibts die weiteren änderungen... ;-)
*** make your own tools (wishlist :: thx)
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

ich geb mal einen kurzen überblick was sich mal verändern wird.

in class.navigation.php
die klasse kümmert sich selbst darum ob $xml und $plugxml inkludiert ist und benützt die globalen instanzen von $xml und $plugxml nicht mehr.

ebenso ist ein einsatz innerhalb von $db konstrukten möglich, bisher wurde die $db global heran gezogen... was zur folge hätte das $db->next_record schleifen abgebrochen würde...

die klasse ist kompatibel zur alten methode jedoch gibt es zwei neue interne funktionen...

-> getName kümmert sich um das zurückliefern des korrekten namens...
wird sowohl intern in der klasse benutzt -> $data als auch in
include*subnav*.php als auch in rights_area.inc.php und grouprights_area.inc.php

die zweite funktion dient nur dazu den $data array zu erzeugen...

im grossen und ganzen ne wesentliche vereinfachung...
*** make your own tools (wishlist :: thx)
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

erster schritt:

die änderungen in der (bezieht sich auf contenido-cvs-2005-01-18.tar)

class.navigation.php

Code: Alles auswählen

class Contenido_Navigation {

    /**
     * @var debug
     */
    var $debug = 0;

    /**
     * array storing all data
     * @var array
     */
    var $data = array();

    /**
     * Constructor
     */
    function Contenido_Navigation() {

        global $db, $xml, $cfg, $sess, $perm, $belang, $cfgPath;
        $db2     = new DB_Contenido;
        $plugxml = new XML_Doc;

        # Load language file
        if ($xml->load($cfg['path']['xml'] . $cfg['lang'][$belang]) == false)
        {
        	if ($xml->load($cfg['path']['xml'] . 'lang_en_US.xml') == false)
        	{
        		die("Unable to load any XML language file");
        	}
        }

        # Load main items
        $sql = "SELECT idnavm, location FROM ".$cfg["tab"]["nav_main"]." ORDER BY idnavm";

        $db->query($sql);

        # Loop result and build array
        while ( $db->next_record() ) {

        # Extract caption from the xml language file
        # including plugins third level
        # extended multilang version
        	if(strstr($db->f("location"), ';')) {

            $locs = explode(";", $db->f("location"));
            $file       = trim($locs[0]);
            $xpath      = trim($locs[1]);

            $filepath = explode('/',$file);
            $counter = count($filepath)-1;

            if ($filepath[$counter] == "") {
               unset($filepath[$counter]);
               $counter--;
            }

            if(strstr($filepath[$counter], '.xml')) {
                $filename = $filepath[$counter];
                unset($filepath[$counter]);
                $counter--;
            }

            $filepath[($counter+1)] = "";

            $filepath = implode("/",$filepath);

            if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $cfg['lang'][$belang]) == false)
            {
                if (!isset($filename)) { $filename = 'lang_en_US.xml'; }
                if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $filename) == false)
                {
                    die("Unable to load any XML language file");
                }
            }

            $main = $plugxml->valueOf( $cfgPath['xmlroot'] . $xpath );
            unset($file, $filename, $filepath);
        } else {

            $main = $xml->valueOf( $cfgPath['xmlroot'] . $db->f("location") );

        }

            # Build data array
            $this->data[$db->f('idnavm')] = array($main);

            $sql = "SELECT
                        a.location AS location,
                        b.name AS area,
                        b.relevant
                    FROM
                        ".$cfg["tab"]["nav_sub"]." AS a,
                        ".$cfg["tab"]["area"]." AS b
                    WHERE
                        a.idnavm 	= '".$db->f('idnavm')."' AND
                        a.level 	= '0' AND
                        b.idarea 	= a.idarea AND
                        a.online 	= '1' AND
                        b.online 	= '1'
                    ORDER BY
                        a.idnavs";

            $db2->query($sql);

            while ( $db2->next_record() ) {

                $area = $db2->f('area');

                if ($perm->have_perm_area_action($area) || $db2->f('relevant') == 0){

        # Extract caption from the xml language file
        # including plugins third level
        # extended multilang version
        if(strstr($db2->f("location"), ';')) {

            $locs = explode(";", $db2->f("location"));
            $file       = trim($locs[0]);
            $xpath      = trim($locs[1]);

            $filepath = explode('/',$file);
            $counter = count($filepath)-1;

            if ($filepath[$counter] == "") {
               unset($filepath[$counter]);
               $counter--;
            }

            if(strstr($filepath[$counter], '.xml')) {
                $filename = $filepath[$counter];
                unset($filepath[$counter]);
                $counter--;
            }

            $filepath[($counter+1)] = "";

            $filepath = implode("/",$filepath);

            if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $cfg['lang'][$belang]) == false)
            {
                if (!isset($filename)) { $filename = 'lang_en_US.xml'; }
                if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $filename) == false)
                {
                    die("Unable to load any XML language file");
                }
            }
            $name = $plugxml->valueOf( $cfgPath['xmlroot'] . $xpath );
            unset($file, $filename, $filepath);
        } else {
            $name = $xml->valueOf( $cfgPath['xmlroot'] . $db2->f("location") );
        }

                   $this->data[$db->f('idnavm')][] = array($name, $area);

                }

            } // end while

        } // end while

        # debugging information
        if ($this->debug) {
            echo '<pre>';
            print_r($this->data);
            echo '</pre>';
        }

    } # end function

    #
    # Method thats builds the
    # Contenido header document
    #
    function buildHeader($lang) {

        global $cfg, $sess, $client, $changelang, $auth, $cfgClient;
wird ersetzt durch

Code: Alles auswählen

class Contenido_Navigation {

	/**
	 * @var debug
	 */
	var $debug = 0;

	/**
	 * array storing all data
	 * @var array
	 */
	var $data = array();

	/**
	 * Constructor
	 */
	function Contenido_Navigation() {

		global $cfg, $belang;

        if (!class_exists('XML_doc')) {
            cInclude ("classes", 'class.xml.php');
        }

		$this->xml = new XML_Doc;
		$this->plugxml = new XML_Doc;

		# Load language file
		if ($this->xml->load($cfg['path']['xml'] . $cfg['lang'][$belang]) == false)
		{
			if ($this->xml->load($cfg['path']['xml'] . 'lang_en_US.xml') == false)
			{
				die("Unable to load any XML language file");
			}
		}

	}

	function getName($location) {

        global $cfg, $belang;

		# Extract caption from the xml language file
		# including plugins extended multilang version

		# If a ";" is found entry is from a plugin ->
		# explode location, first is xml file path,
		# second is xpath location in xml file
        if(strstr($location, ';')) {

            $locs = explode(";", $location);
            $file       = trim($locs[0]);
            $xpath      = trim($locs[1]);

            $filepath = explode('/',$file);
            $counter = count($filepath)-1;

            if ($filepath[$counter] == "") {
               unset($filepath[$counter]);
               $counter--;
            }

            if(strstr($filepath[$counter], '.xml')) {
                $filename = $filepath[$counter];
                unset($filepath[$counter]);
                $counter--;
            }

            $filepath[($counter+1)] = "";

            $filepath = implode("/",$filepath);

            if ($this->plugxml->load($cfg["path"]["plugins"] . $filepath . $cfg['lang'][$belang]) == false)
            {
                if (!isset($filename)) { $filename = 'lang_en_US.xml'; }
                if ($this->plugxml->load($cfg["path"]["plugins"] . $filepath . $filename) == false)
                {
                    die("Unable to load $filepath XML language file");
                }
            }
            $caption = $this->plugxml->valueOf( $xpath );

        } else {
            $caption = $this->xml->valueOf( $location );
        }

        return $caption;

	}


	function _buildHeaderData() {

		global $cfg, $perm, $belang;

		$db	= new DB_Contenido;
		$db2 = new DB_Contenido;

		# Load main items
		$sql = "SELECT idnavm, location FROM ".$cfg["tab"]["nav_main"]." ORDER BY idnavm";

		$db->query($sql);

		# Loop result and build array
		while ( $db->next_record() ) {

			/* Extract names from the XML document. */
			$main = $this->getName($db->f("location"));

			# Build data array
			$this->data[$db->f('idnavm')] = array($main);

			$sql = "SELECT
						a.location AS location,
						b.name AS area,
						b.relevant
					FROM
						".$cfg["tab"]["nav_sub"]." AS a,
						".$cfg["tab"]["area"]." AS b
					WHERE
						a.idnavm	= '".$db->f('idnavm')."' AND
						a.level 	= '0' AND
						b.idarea	= a.idarea AND
						a.online	= '1' AND
						b.online	= '1'
					ORDER BY
						a.idnavs";

			$db2->query($sql);

			while ( $db2->next_record() ) {

				$area = $db2->f('area');

				if ($perm->have_perm_area_action($area) || $db2->f('relevant') == 0){

				   /* Extract names from the XML document. */
				   $name = $this->getName($db2->f("location"));

				   $this->data[$db->f('idnavm')][] = array($name, $area);

				}

			} // end while

		} // end while

		# debugging information
		if ($this->debug) {
			echo '<pre>';
			print_r($this->data);
			echo '</pre>';
		}

	} # end function

	#
	# Method thats builds the
	# Contenido header document
	#
    function buildHeader($lang) {

        global $cfg, $sess, $client, $changelang, $auth, $cfgClient;

        $this->_buildHeaderData();
Zuletzt geändert von emergence am Di 18. Jan 2005, 13:39, insgesamt 1-mal geändert.
*** make your own tools (wishlist :: thx)
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

zweiter schritt:

alle include*subnav*.php

Code: Alles auswählen

    # load language file
    if ($xml->load($cfg['path']['xml'] . $cfg['lang'][$belang]) == false)
    {
      	if ($xml->load($cfg['path']['xml'] . 'lang_en_US.xml') == false)
       	{
       		die("Unable to load any XML language file");
       	}
    }
wird entfernt...

Code: Alles auswählen

$plugxml = new XML_Doc;
wird ersetzt durch

Code: Alles auswählen

$nav = new Contenido_Navigation;
und

Code: Alles auswählen

        # Extract caption from the xml language file
        # including plugins third level
        # extended multilang version
        if(strstr($db->f("location"), ';')) {

            $locs = explode(";", $db->f("location"));
            $file       = trim($locs[0]);
            $xpath      = trim($locs[1]);

            $filepath = explode('/',$file);
            $counter = count($filepath)-1;

            if ($filepath[$counter] == "") {
               unset($filepath[$counter]);
               $counter--;
            }

            if(strstr($filepath[$counter], '.xml')) {
                $filename = $filepath[$counter];
                unset($filepath[$counter]);
                $counter--;
            }

            $filepath[($counter+1)] = "";

            $filepath = implode("/",$filepath);

            if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $cfg['lang'][$belang]) == false)
            {
                if (!isset($filename)) { $filename = 'lang_en_US.xml'; }
                if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $filename) == false)
                {
                    die("Unable to load any XML language file");
                }
            }
            $caption = $plugxml->valueOf( $cfgPath['xmlroot'] . $xpath );
            unset($file, $filename, $filepath);
        } else {
            $caption = $xml->valueOf( $cfgPath['xmlroot'] . $db->f("location") );
        }
wird ersetzt durch

Code: Alles auswählen

		/* Extract names from the XML document. */
		$caption = $nav->getName($db->f("location"));
*** make your own tools (wishlist :: thx)
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

dritter und letzter schritt

rights_area.inc.php und grouprights_area.inc.php

Code: Alles auswählen

$plugxml = new XML_Doc; 
wird ersetzt durch

Code: Alles auswählen

$nav = new Contenido_Navigation;


und

Code: Alles auswählen

				        # get areas including plugins
				        # extended multilang version
				        if(strstr($value2['location'], ';')) {
				            $locs = explode(";", $value2['location']);
				            $file       = trim($locs[0]);
				            $value2['location']      = trim($locs[1]);
				
				            $filepath = explode('/',$file);
				            $counter = count($filepath)-1;
				
				            if ($filepath[$counter] == "") {
				               unset($filepath[$counter]);
				               $counter--;
				            }
				
				            if(strstr($filepath[$counter], '.xml')) {
				                $filename = $filepath[$counter];
				                unset($filepath[$counter]);
				                $counter--;
				            }
				
				            $filepath[($counter+1)] = "";
				
				            $filepath = implode("/",$filepath);
				
				            if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $cfg['lang'][$belang]) == false)
				            {
				                if (!isset($filename)) { $filename = 'lang_en_US.xml'; }
				                if ($plugxml->load($cfg["path"]["plugins"] . $filepath . $filename) == false)
				                {
				                    die("Unable to load $filepath XML language file");
				                }
				            }
				            $main = $plugxml->valueOf( $value2['location'] );
				
				        } else {
				            $main = $xml->valueOf($cfgPath['xmlroot'] . $value2['location']);
				        }
wird ersetzt durch

Code: Alles auswählen

		    /* Extract names from the XML document. */
		    $main = $nav->getName($value2['location']);
das ist es...
*** make your own tools (wishlist :: thx)
timo
Beiträge: 6284
Registriert: Do 15. Mai 2003, 18:32
Wohnort: Da findet ihr mich nie!
Kontaktdaten:

Beitrag von timo »

ok, soweit habe ich das alles geändert.

Ich überlege grade, ob es Sinn macht, daß die Methode "valueOf" bei einem nichtgefundenen Element genauso verfährt wie es ursprünglich der Fall war...Grund: Sämtliche Plugins fliegen mir gerade um die Ohren bzw melden "Not Found"...

also anstatt

Code: Alles auswählen

if ($value == NULL) { return "Not found"; }
Wird dann ein Aufruf auf eine Kompatibilitätsfunktion gemacht
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

tja jetzt hab ich ein problem, ohne das ich ein plugin kenne das ihr einsetzt kann ich nicht sagen was geändert werden sollte...
vielleicht kannst du mir eines zur verfügung stellen...

ich müsste zumindestens den code sehen den ihr bei einer plugin subnav einsetzt... + die sql einträge die in con_sub_nav gemacht werden...

so kann ich mich nur an die plugins orientieren die hier im forum zur verfügung stehen ;-)

ist natürlich ne möglichkeit die alte methode wieder mit reinzubauen...

wenn du mir was zur verfügung stellst, müsstest du ebenso nen neuen snapshot erzeugen...
Zuletzt geändert von emergence am Di 18. Jan 2005, 14:16, insgesamt 1-mal geändert.
*** make your own tools (wishlist :: thx)
timo
Beiträge: 6284
Registriert: Do 15. Mai 2003, 18:32
Wohnort: Da findet ihr mich nie!
Kontaktdaten:

Beitrag von timo »

naja das liegt einfach daran, daß bei den Plugins die Einträge in der nav_sub nicht vollständig sind...meistens fehlt "navigation".

Und die ganzen Einträge bei allen Kunden nachzutragen ist ein wenig schwierig ;)
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

du meinst das hier oder
-> http://www.contenido.org/forum/viewtopi ... 8561#38561
behandeln wird das beim anderen thread weiter...
*** make your own tools (wishlist :: thx)
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

ach ja minimal was ich vergessen habe

Code: Alles auswählen

//include ($cfgPathContenido.$cfgPathTpl."all_html_line0.inc.php");
//Select the itemid´s
        # Load language file
        if ($xml->load($cfg['path']['xml'] . $cfg['lang'][$belang]) == false)
        {
        	if ($xml->load($cfg['path']['xml'] . 'lang_en_US.xml') == false)
        	{
        		die("Unable to load any XML language file");
        	}
        }
kann jeweils in rights_area.inc.php und grouprights_area.inc.php
entfernt werden...
ist nur mehr datenmüll
*** make your own tools (wishlist :: thx)
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

ich mach hier zu...

sieht wunderbar aus im snapshot...
*** make your own tools (wishlist :: thx)
Gesperrt