Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 345 | Revision 355 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    use App\Models\Action;
    use App\Models\Item;
    use App\Models\Directory;
    use Illuminate\Support\Facades\Route;

    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
     */

    $sql = "
        SELECT
            *
        FROM
            i18n_de
    ";
    $langstrings = DB::select( $sql );
    foreach ( $langstrings as $langstring )
    {
        $GLOBALS[ "langstrings" ][ $langstring->page_id ][ $langstring->id ] = $langstring->string;
    }
    function getConfig()
    {
        define( '__SITE__', env( 'site' ) );
        define( '__SHOP__', env( 'shop' ) );
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );

        $cfg_file = __CFG_PATH__ . "/config.de.xml";
        if ( !file_exists( $cfg_file ) )
        {
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
        }
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
        $ini = json_decode( json_encode( $xml ), true );
        foreach ( $ini as $key => $wert )
        {
            if ( $wert == array() )
            {
                $ini[ $key ] = "";
            }
            elseif ( is_array( $wert ) )
            {
                foreach ( $wert as $key2 => $wert2 )
                {
                    if ( $wert2 == array() )
                    {
                        $ini[ $key ][ $key2 ] = "";
                    }
                }
            }
        }

        $v_file = __CFG_PATH__ . "/versand.xml";
        if ( file_exists( $v_file ) )
        {
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
            $ini[ "shipping" ] = json_decode( json_encode( $xml ), true );
            foreach ( $ini[ "shipping" ] as $key => $wert )
            {
                if ( $wert == array() )
                {
                    $ini[ "shipping" ][ $key ] = "";
                }
                elseif ( is_array( $wert ) )
                {
                    foreach ( $wert as $key2 => $wert2 )
                    {
                        if ( $wert2 == array() )
                        {
                            $ini[ "shipping" ][ $key ][ $key2 ] = "";
                        }
                    }
                }
            }
        }
        return $ini;
    }

    session_start();
    $GLOBALS[ "INI" ] = getConfig();
    $GLOBALS[ "menu" ] = array();
    $nav = new Directory();
    $GLOBALS[ "menu" ] = $nav->nav_menu();
    /* Mobile Weiche */
    if ( isset( $_SERVER[ "HTTP_USER_AGENT" ] ) )
    {
        if ( !isset( $_SESSION[ 'isMobile' ] ) || $_SESSION[ 'isMobile' ] == false || !isset( $GLOBALS[ 'isMobile' ] ) || $GLOBALS[ 'isMobile' ] == false )
        {

            $_SESSION[ 'isMobile' ] = false;
            $GLOBALS[ 'isMobile' ] = false;

            if (
                preg_match( "/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine
        |htc|iemobile|iphone|iPad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|
        panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus
        |up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i", $_SERVER[ "HTTP_USER_AGENT" ] )
            )
            {

                $_SESSION[ 'isMobile' ] = true;
                $GLOBALS[ 'isMobile' ] = true;
            }

        }
    }
    Route::get( "basket.html", function ()
    {
        return view( 'basket', [
            "nav"  => $GLOBALS[ "menu" ],
            "ini"  => $GLOBALS[ "INI" ],
            "langstrings" => $GLOBALS[ "langstrings" ],
        ] );
    } );
    Route::get( "/directory/{id}", function ( $id )
    {
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
            0,
            2,
            99
        ] )->get();
        $items = Item::with( 'price' )->with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
            0,
            2
        ] )->get();
        $subdir = Directory::with( 'medium.medium' )->find( $dirId );
        $subdir[ "subdirs" ] = $dirs;
        $subdir[ "items" ] = $items;
        return view( 'subdir', [
            "subdir" => $subdir,
            "nav"    => $GLOBALS[ "menu" ],
            "ini"    => $GLOBALS[ "INI" ],
            "langstrings" => $GLOBALS[ "langstrings" ],
        ] );
    } );
    Route::get( "{item:slug}.html", function ( Item $item )
    {
        $item->load( 'price', 'medium.medium' );
        return view( 'item', [
            "item" => $item,
            "nav"  => $GLOBALS[ "menu" ],
            "ini"  => $GLOBALS[ "INI" ],
            "langstrings" => $GLOBALS[ "langstrings" ],
        ] );
    } );
    Route::get( '/', function ()
    {
        $aktion = Action::with( 'medium.medium' )->get();
        return view( 'startpage', [
            "pagetype"    => "Startseite",
            "aktion"      => $aktion,
            "nav"         => $GLOBALS[ "menu" ],
            "ini"         => $GLOBALS[ "INI" ],
            "langstrings" => $GLOBALS[ "langstrings" ],
        ] );
    } );