Subversion-Projekte lars-tiefland.content-management

Revision

Blame | Letzte Änderung | Log anzeigen | RSS feed

<?php

    //$Id: sitemap.php 3361 2011-02-24 15:34:41Z tiefland $

    /**
     * @author Lars Tiefland <tiefland@weban.de>
     * @copyright 2008 Webagentur Niewerth
     * @package Mediaran.de
     * @version $Rev: 3361 $
     * @license propietary
     * @filesource
     * 
     */

    /**
     * 
     * @author Lars Tiefland <tiefland@weban.de>
     * @copyright 2008 Webagentur Niewerth
     * @package Mediaran.de
     */

    set_time_limit( 0 );

    function getItems( $dirId = null )
    {
        global $webs;
        $buffer = array();
        $query = "
                        SELECT
                                artikel.*
                        FROM
                                artikel
                        WHERE
                                artikel.Language= 'DE'
                ";
        if ( !is_null($dirId) )
        {
            $query .= "
                        AND
                                artikel.Father = $dirId
            ";
        }
        $query . "
                        AND
                                status = 0
                        ";
        $result = mysql_query( $query ) or die( mysql_errno() . ": " . mysql_error() .
            "<hr>" . $query );
        while ( $zeile = mysql_fetch_assoc($result) )
        {
            $zeile["code"] = md5( $_SESSION["INI"]["param_value"] . "_" . $zeile["kurzbezeichnung"] );
            $path = getPath( $zeile['Father'] );
            foreach ( $path as $elem )
            {
                $buffer[] = preg_replace( "/[\W]+/", "", $elem['ID'] . "_" . $elem['Name'] );
            }

            $zeile["itemLink"] = "http://www." . $webs["domain"] . "/index.php?item=" .
                $zeile["ID"] . "&param=" . $zeile["code"];
            $ret[] = $zeile;
        }
        return $ret;
    }

    function getPath( $root )
    {
        static $level = 0;
        $level++;

        if ( $root > 0 )
        {
            $query = "
                                select
                                        *
                                from
                                        directory
                                where
                                        ID = $root
                                and
                                        language= 'DE'
                                ";
            $result = mysql_query( $query ) or die( mysql_errno() . ": " . mysql_error() .
                "<hr>" . $query );
            $zeile = mysql_fetch_assoc( $result );

            // Bilder um Pfad und Tag erweitern
            foreach ( array("", "2") as $i )
            {
                if ( $zeile["bild_url" . $i] )
                {
                    $zeile["bild_url" . $i] = "<img src=" . $_SESSION['INI']['itemContainerKorrektur']["imagePath" .
                        $i] . $zeile["bild_url" . $i] . " >";
                }
                else
                {
                    $zeile["bild_url" . $i] = "";
                }
            }

            $path = getPath( $zeile['Father'] );

            $path[] = $zeile;

            $level--;

            if ( $level == 0 )
            {
                foreach ( $path as $p )
                {
                    if ( $p['status'] == 1 )
                    {
                        $path = array();
                    }
                }
            }

            return $path;
        }
        else
        {
            $level--;
            return array();
        }
    }

    function getSubDirs( $root )
    {
        $buffer = array();
        $query = "
                                select
                                        directory.*,
                                        Herstellerkatalog.Logo1 as Logo
                                from
                                        directory
                                left join
                                        Herstellerkatalog
                                on
                                        Herstellerkatalog.Bezeichnung = directory.Name
                                where
                                        Father = $root
                                and
                                        status=0
                                and
                                        Artikelstamm=0
                                and
                                        language= 'DE'
                                order by
                                        Kennung         
                ";
        $result = mysql_query( $query ) or die( mysql_errno() . ": " . mysql_error() .
            "<hr>" . $query );
        while ( $zeile = mysql_fetch_assoc($result) )
        {
            if ( $zeile["Logo"] )
            {
                $zeile["Logo"] = "<img src='" . $_SESSION['INI']['Hersteller']['logoPath'] .
                    $zeile["Logo"] . "' alt='" . $zeile["Name"] . "'>";
            }
            else
            {
                $zeile["Logo"] = $zeile["Name"];
            }

            // Bilder um Pfad und Tag erweitern
            foreach ( array("", "2") as $i )
            {
                if ( $zeile["bild_url" . $i] )
                {
                    $zeile["bild_url" . $i] = "<img src=" . $_SESSION['INI']['itemContainerKorrektur']["imagePath" .
                        $i] . $zeile["bild_url" . $i] . ">";
                }
                else
                {
                    $zeile["bild_url" . $i] = "";
                }
            }

            $buffer[] = $zeile;
        }
        return $buffer;
    }

    function add_items( $start=null )
    {
        global $map;
        $items = getItems( $start );
        if ( is_array($items) )
        {
            foreach ( $items as $item )
            {
                $path = getPath( $item["Father"] );
                $map->add( $item["itemLink"], 1.0 - (count($path) - 1) * 0.1 );
            }
        }
    }
    function add( $start )
    {
        global $map, $webs;
        static $count = 0;
        $subdirs = getSubdirs( $start );
        foreach ( $subdirs as $subDir )
        {
            // Pfad ermitteln
            $buffer = array();
            $path = getPath( $subDir['ID'] );
            foreach ( $path as $elem )
            {
                $buffer[] = preg_replace( "/[\W]+/", "", $elem['ID'] . "_" . $elem['Name'] );
            }

            // dirLink
            $subDir['dirLink'] = "http://www." . $webs["domain"] . "/" . implode( "/", $buffer ) .
                "/";
            $count++;
            $map->add( $subDir["dirLink"], 1.0 - (count($path) - 1) * 0.1 );
            add( $subDir["ID"] );
        }
        return $count;
    }
    require_once  "File/Sitemap.php";
    $map = new File_Sitemap();
    session_start();
    //$_SESSION["INI"]=parse_ini_file("mediaran.de.ini.php", true);
    require_once  "Online-Shop/connect2.php";
    $_SESSION["INI"]["param_value"] = file_get_contents( "control/" . $webs["domain"] .
        "_key.txt" );
    foreach ( array(783, 784, 447) as $start )
    {
        $buffer = array();
        foreach ( getPath($start) as $elem )
        {
            $buffer[] = preg_replace( "/[\W]+/", "", $elem['ID'] . "_" . $elem['Name'] );
        }

        // dirLink
        $link = "http://www." . $webs["domain"] . "/" . implode( "/", $buffer ) .
            "/";
        $map->Add( $link, 1.0 );
        $count = add( $start );
        $count++;
    }
    $map->Add( "http://www." . $webs["domain"] . "/gaestebuch/gaestebuch.htm",
        1.0 );
    $map->Add( "http://www." . $webs["domain"] . "/html/servicecenter.htm", 1.0 );
    $res = $res = $map->validate();
    if ( $res )
    {
        $map->save( "sitemap.xml.gz", true, true );
        $map->notify( "http://www." . $webs["domain"] . "/sitemap.xml.gz" );
    }
    else
    {
        echo "Ein Fehler ist beim Erstellen der Sitemap aufgreten!";
    }
?>