Umlaute im Backend nach Upgrade 4.4.5 R1

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Mo 28. Feb 2005, 18:25

hmm... noch seltsamer...
hab momentan auch keine weiteren ideen...
*** make your own tools (wishlist :: thx)

Beleuchtfix
Beiträge: 1082
Registriert: Di 22. Jul 2003, 10:14
Wohnort: Hessen
Kontaktdaten:

Beitrag von Beleuchtfix » Mo 28. Feb 2005, 18:33

Ich post mal das Problem bei Domaingo.
Neulich hatte ich ein anderes Problem, das ein script unter PHP4 nicht ging aber dafür unter php5. Damals war auch ein String Vergleich nach Einlesen aus einer CSV-Datei falsch. Obwohl die Variable richtig angezeigt wird ging der If Vergleich immer daneben.

Vielleicht reagieren sie jetzt.

Florian
z.Z keine Contenido Installation aktiv

Beleuchtfix
Beiträge: 1082
Registriert: Di 22. Jul 2003, 10:14
Wohnort: Hessen
Kontaktdaten:

Beitrag von Beleuchtfix » Fr 4. Mär 2005, 19:06

Domaingo hat geantwortet, dass sie php5 offiziell nicht unterstützen und deshalb sich da auch nicht zuständig fühlen.
Also inter php4 ist es ok, 5.0.2 nicht.
Gruß
Florian
z.Z keine Contenido Installation aktiv

casi1969
Beiträge: 71
Registriert: Mi 4. Aug 2004, 16:30
Wohnort: Köln
Kontaktdaten:

Beitrag von casi1969 » Mi 6. Apr 2005, 10:21

Habe das gleiche Problem im Backend:
Unter php4 alles OK, php5 bekomme ich diese Anzeigefehler bei Umlauten. Mein Provider HostEurope. Habe den noch nicht kontaktiert deswegen. Ich glaube auch eher, dass das ein Bug von Contenido ist.

In welchen Contenido Dateien könnte man denn die Umlaute maskieren, so dass sie immer richtig angezeigt werden?

Viele Grüße
Carsten

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Mi 6. Apr 2005, 11:03

könnte ja vielleicht ein bug in der class.xml.php sein...
um das debuggen zu können bräuchte ich einen ftp zugang und einen backend sysadmin account...
*** make your own tools (wishlist :: thx)

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Do 7. Apr 2005, 12:51

hab mir das gerade angesehen

der grund für das verhalten liegt darin: (seit php5.0.2)
-> Fixed bug #29711 (Changed ext/xml to default to UTF-8 output). (Rob)

als temporärer workaround reicht es in der class.xml.php

function characterData

Code: Alles auswählen

		$data = eregi_replace ( "[[:space:]]+", " ", $data );
durch

Code: Alles auswählen

		$data = eregi_replace ( "[[:space:]]+", " ", utf8_decode($data) );
zu ersetzen...

ich verschieb das mal nach bugs
*** make your own tools (wishlist :: thx)

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Mo 18. Apr 2005, 12:27

hab mich jetzt noch etwas damit herumgespielt
bezieht sich auf -> http://www.contenido.org/forum/viewtopic.php?t=8009

ich poste gleich mal die geänderte klasse

die klasse wurde getestet bei php 5.0.4, würd jetzt noch ein paar rückmeldungen von anderen php versionen benötigen...

also mit bitte um feedback:

Code: Alles auswählen

<?php

/**
 * Class XML_doc
 *
 * Simple class for extracting values
 * from a XML document. Uses a simplified
 * XPath syntax to access the elements.
 * For example: 'root/person/name' would
 * return the value of the 'name' node in
 * 'root/person' node. You have to specify
 * the root node name. Can't access node
 * attributes yet.
 *
 * @copyright four for business AG <http://www.4fb.de>
 * @author Jan Lengowski <Jan.Lengowski@4fb.de>
 * @modified Martin Horwath <horwath@dayside.net>
 * @version 0.9.7
 * @package 4fb_XML
 */
class XML_doc {

    /**
     * @var array $errors
     */
     var $errors = array();

    /**
     * @var string xml
     */
     var $xml;

    /**
     * @var parsed array
     */
    var $parsearray;

    /**
     * @var help array
     */
    var $itemname;

    /**
     * XML Parser Object
     */
    var $parser;

    /**
     * XML encoding
     */
    var $encoding;

    /**
     * Class Construcor
     */
    function XML_doc() {
      // do nothing
    } // end function


    /**
     * load()
     *
     * Load the XML file
     *
     * @param string XML document filename
     * @return boolean true if the load was successful
     */
    function load($filename) {

        if (file_exists($filename)) {
            $fp = fopen ($filename, "rb");

            if ($fp === false)
            {
                return (false);
            }

            unset($this->xml);
            $this->xml = fread ($fp, filesize ($filename));
            fclose ($fp);

            // useful if entities are found in xml file
            $this->xml = $this->_translateLiteral2NumericEntities($this->xml);

            // get source encoding from file
            if (preg_match('/<\?xml.*encoding=[\'"](.*?)[\'"].*\?>/m', $this->xml, $m)) {
                $this->encoding = strtoupper($m[1]);
            } else {
                $this->encoding = "UTF-8";
            }

            //print_r($this->xml);
            unset($this->parsearray);
            return (true);

        } else {
            //die('no XML file ('.$filename.')');
            return (false);

        }

    } // end function


    /**
     * valueOf()
     *
     * Extract one node value from the XML document.
     * Use simplified XPath syntax to specify the node.
     * F.e. 'root/test/firstnode'
     *
     * @return String Value of XML node
     */
     function valueOf($xpath) {

        if (!is_array($this->parsearray)) { // build tree once
            $this->parse(false);
        }

        $aCombination = explode("/", $xpath);

        $keynode = "";

        foreach ($aCombination as $key => $value) {
            $keynode .= "['".$value."']";
        }

        eval('$value = $this->parsearray'.$keynode.';');


        if ($value == NULL)
        {
            $aLoosePath = $this->findLoosePath($aCombination);

            if (is_array($aLoosePath))
            {
                $keynode = "";
                foreach ($aLoosePath as $key => $value) {
                    $keynode .= "['".$value."']";
                }

                eval('$value = $this->parsearray'.$keynode.';');

            }

        }

        if ($value == NULL) { return "Not found"; }

        if (is_array($value)) { return "Has children"; }

        return $value;

    } // end function

    /**
     * findLoosePath: Finds a path in the XML array which
     *                ends with the given keys
     *
     * @param aCombination  array of keys to test for
     * @return false if nothing was found, or the array with the found keys
     */
    function findLoosePath ($aCombination, $aScope = true)
    {
        if (count($aCombination) == 0)
        {
            return false;
        }

        $keynode = "";
        foreach ($aCombination as $key => $value) {
            $keynode .= "['".$value."']";
        }

        if ($aScope===true) {
            $aScope = $this->parsearray;
        }

        foreach($aScope as $aScopeKey => $aScopeValue) {

           if (!is_array ($aScope[$aScopeKey])) {
               return false;
           }

           eval('if (isset ($aScope['.$aScopeKey.']'.$keynode.') ) { $found = true; }');
           if ($found) {
               $rCombination = array_merge(Array($aScopeKey), $aCombination);
               break;
           }

           $rCombination = $this->findLoosePath($aCombination, $aScopeValue);
           if (is_array($rCombination)) {
               $rCombination = array_merge(Array($aScopeKey), $rCombination);
               break;
           }

        }

        return $rCombination;

    }


    /**
     * parse()
     *
     * Parse the xml file in an array
     *
     *
     *
     * @return array parsearray
     */

    function parse($send=true) {
        // set up a new XML parser to do all the work for us
        $this->parser = xml_parser_create($this->encoding);
        xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->encoding);
        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
        xml_set_object($this->parser, $this);
        xml_set_element_handler($this->parser, "startElement", "endElement");
        xml_set_character_data_handler($this->parser, "characterData");

        // parse the data and free the parser...
        xml_parse($this->parser, $this->xml);
        xml_parser_free($this->parser);
        if ($send) return $this->parsearray;
    } // end function

    /**
     *
     *
     *
     */
    function startElement($parser, $name, $attrs) {
        // Start a new Element.  This means we push the new element onto
        // store the name of this element
        $this->itemname[]="$name";
    } // end function

    /**
     *
     *
     *
     */
    function endElement($parser, $name) {
        // End an element.  This is done by popping the last element from
        // the stack and adding it to the previous element on the stack.
        // delete the old element from itemname
        array_pop($this->itemname);
    } // end function

    /**
     *
     *
     *
     */
    function characterData($parser, $data) {
        // Collect the data onto the end of the current chars it dont collect whitespaces.

        $data = eregi_replace ( "[[:space:]]+", " ", $data );

        if(trim($data)){
           //search for the element path
           foreach($this->itemname as $value){
                   $pos.="[$value]";
           }

           // looks stupid but is useful to take care of entities, this corrects the line break issue
           eval("if (isset(\$this->parsearray$pos)) { \$data = \$this->parsearray$pos.trim(\$data); }");

           //set the new data in the parsearray
           eval("\$this->parsearray$pos=trim(\$data);");

        }

    } // end function

    /**
     * Translate literal entities to their numeric equivalents and vice versa.
     *
     * PHP's XML parser (in V 4.1.0) has problems with entities! The only one's that are recognized
     * are &, < > and ". *ALL* others (like &nbsp; &copy; a.s.o.) cause an
     * XML_ERROR_UNDEFINED_ENTITY error. I reported this as bug at http://bugs.php.net/bug.php?id=15092
     * The work around is to translate the entities found in the XML source to their numeric equivalent
     * E.g. &nbsp; to   / &copy; to © a.s.o.
     *
     * NOTE: Entities &, < > and " are left 'as is'
     *
     * @author Sam Blum bs_php@users.sourceforge.net
     * @param string $xmlSource The XML string
     * @param bool   $reverse (default=FALSE) Translate numeric entities to literal entities.
     * @return The XML string with translated entities.
     */
    function _translateLiteral2NumericEntities($xmlSource, $reverse = FALSE) {
        static $literal2NumericEntity;

        if (empty($literal2NumericEntity)) {
            $transTbl = get_html_translation_table(HTML_ENTITIES);
            foreach ($transTbl as $char => $entity) {
                if (strpos('&"<>', $char) !== FALSE) continue;
                    $literal2NumericEntity[$entity] = '&#'.ord($char).';';
            }
        }

        if ($reverse) {
            return strtr($xmlSource, array_flip($literal2NumericEntity));
        } else {
            return strtr($xmlSource, $literal2NumericEntity);
        }
    }


} // end class XML_doc

?>
Zuletzt geändert von emergence am Mo 18. Apr 2005, 13:40, insgesamt 1-mal geändert.
*** make your own tools (wishlist :: thx)

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Mo 18. Apr 2005, 12:59

ach ja was ich nun genau gemacht habe:

ab php 5.0.2 ist der standard output beim xml parsen immer UTF-8
bei php 5.0.1 ist das noch ISO-8859-1
zusätzlich liest der parser angaben in welchem zeichensatz das xml verfasst wurde nicht aus...

ich hab jetzt einfach ne regex prüfung eingebaut die den zeichensatz des files ausließt... und entsprechend beim parsen das source und target encoding setzt... (der workaround ist somit eigentlich nicht mehr notwendig)

der hit an der sache ist bei php5.0.4 bricht der parse vorgang einfach ab wenn ein zeichen in einem anderen encoding gefunden wird...

getestet auf php 5.0.1, 4.3.10 -> ebenso okay
*** make your own tools (wishlist :: thx)

Beleuchtfix
Beiträge: 1082
Registriert: Di 22. Jul 2003, 10:14
Wohnort: Hessen
Kontaktdaten:

Beitrag von Beleuchtfix » Sa 23. Apr 2005, 14:41

Hallo Emergence
ich habe die geänderte Klasse unter php 4.3.10 und 5.0.3 getestet, beides erscheint mir OK.
Der Workaround war in der 4.3.10 fehlerhaft
Danke Florian

kannst du vielleicht noch ergänzen, dass es sich um die Datei contenido/classes/class.xml.php handelt, dann findet man das einfacher :wink:

timo
Beiträge: 6284
Registriert: Do 15. Mai 2003, 18:32
Wohnort: Da findet ihr mich nie!
Kontaktdaten:

Beitrag von timo » Do 19. Mai 2005, 15:28

Hi emergence,

deine Änderungen habe ich soweit übernommen -> aber noch ein paar Anmerkungen bzw Fragen:

Welches ist die Ursprungsklasse? Die der 4.4.5-r1 oder die von 4.5.x? Da gibts nämlich einige Unterschiede:

1. In der Funktion "findLoosePath" gibts im Head nach

Code: Alles auswählen

        if ($aScope===true) {
            $aScope = $this->parsearray;
        }
die Abfrage, ob $aScope auch wirklich ein Array ist:

Code: Alles auswählen

        if (!is_array ($aScope)) {
            return false;
        }
bei deiner Version aber nicht -> ich hab die Prüfung wieder aktiviert, da ich sie für sinnvoll halte

2. In der Funktion "characterData" ist ziemlich viel geändert, wo ich nicht weiß was bzw warum -> aber eins ist mir auf jeden Fall ins Auge gestochen , und zwar wenn das Array im String aufgebaut wird:

Code: Alles auswählen

$pos.="[$value]";
Sollte das nicht mit einem Anführungszeichen versehen werden, also so:

Code: Alles auswählen

$pos.="['$value']";
Denn PHP meckert u.U., wenn diese nicht verwendet werden...

Ansonsten sieht das alles recht gut aus!

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Do 19. Mai 2005, 15:44

das ist schon wieder so lange her... ;-)

ausgangspunkt war cvs_head

ad. 1
haste recht die überprüfung kann nicht schaden, verursacht aber auch kein problem...
ich glaub ich hab das zu beginn der valueOf verschoben... (da die funktion loosepath für mich nur in kombination mit valueOf einen sinn ergibt)

ad. 2
bei dem mit $pos.="[$value]"; -> ganz ehrlich keine ahnung mehr, was ich mir dabei gedacht habe...
*** 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 » Do 19. Mai 2005, 15:54

hmm also ich habe es mal eingecheckt, man könnte das ja jetzt hier schließen, oder?

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Do 19. Mai 2005, 15:57

alles was zu ist ist gut ;-)
*** make your own tools (wishlist :: thx)

Gesperrt