Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 331 | Revision 340 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
333 lars 3
    use App\Models\Action;
4
    use App\Models\Item;
5
    use App\Models\Directory;
6
    use Illuminate\Support\Facades\Route;
2 lars 7
 
333 lars 8
    /*
9
    |--------------------------------------------------------------------------
10
    | Web Routes
11
    |--------------------------------------------------------------------------
12
    |
13
    | Here is where you can register web routes for your application. These
14
    | routes are loaded by the RouteServiceProvider within a group which
15
    | contains the "web" middleware group. Now create something great!
16
    |
17
     */
2 lars 18
 
333 lars 19
    function getConfig()
20
    {
21
        define( '__SITE__', env( 'site' ) );
22
        define( '__SHOP__', env( 'shop' ) );
23
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 24
 
333 lars 25
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
26
        if ( !file_exists( $cfg_file ) )
27
        {
28
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
29
        }
30
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
31
        $ini = json_decode( json_encode( $xml ), true );
32
        foreach ( $ini as $key => $wert )
33
        {
34
            if ( $wert == array() )
35
            {
36
                $ini[ $key ] = "";
37
            }
38
            elseif ( is_array( $wert ) )
39
            {
40
                foreach ( $wert as $key2 => $wert2 )
41
                {
42
                    if ( $wert2 == array() )
43
                    {
44
                        $ini[ $key ][ $key2 ] = "";
45
                    }
176 lars 46
                }
47
            }
48
        }
49
 
333 lars 50
        $v_file = __CFG_PATH__ . "/versand.xml";
51
        if ( file_exists( $v_file ) )
52
        {
53
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
54
            $ini[ "shipping" ] = json_decode( json_encode( $xml ), true );
55
            foreach ( $ini[ "shipping" ] as $key => $wert )
56
            {
57
                if ( $wert == array() )
58
                {
59
                    $ini[ "shipping" ][ $key ] = "";
60
                }
61
                elseif ( is_array( $wert ) )
62
                {
63
                    foreach ( $wert as $key2 => $wert2 )
64
                    {
65
                        if ( $wert2 == array() )
66
                        {
67
                            $ini[ "shipping" ][ $key ][ $key2 ] = "";
68
                        }
176 lars 69
                    }
70
                }
71
            }
72
        }
333 lars 73
        return $ini;
177 lars 74
    }
75
 
333 lars 76
    session_start();
77
    $GLOBALS[ "INI" ] = getConfig();
78
    $GLOBALS[ "menu" ] = array();
79
    $nav = new Directory();
80
    $GLOBALS[ "menu" ] = $nav->nav_menu();
81
    /* Mobile Weiche */
82
    if ( isset( $_SERVER[ "HTTP_USER_AGENT" ] ) )
83
    {
84
        if ( !isset( $_SESSION[ 'isMobile' ] ) || $_SESSION[ 'isMobile' ] == false || !isset( $GLOBALS[ 'isMobile' ] ) || $GLOBALS[ 'isMobile' ] == false )
85
        {
88 lars 86
 
333 lars 87
            $_SESSION[ 'isMobile' ] = false;
88
            $GLOBALS[ 'isMobile' ] = false;
88 lars 89
 
333 lars 90
            if (
91
                preg_match( "/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine
88 lars 92
        |htc|iemobile|iphone|iPad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|
93
        panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus
333 lars 94
        |up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i", $_SERVER[ "HTTP_USER_AGENT" ] )
95
            )
96
            {
88 lars 97
 
333 lars 98
                $_SESSION[ 'isMobile' ] = true;
99
                $GLOBALS[ 'isMobile' ] = true;
100
            }
101
 
88 lars 102
        }
103
    }
333 lars 104
    Route::get( "/directory/{id}", function ( $id )
105
    {
106
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
107
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
108
            0,
109
            2,
110
            99
111
        ] )->get();
112
        $items = Item::with( 'price' )->with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
113
            0,
114
            2
115
        ] )->get();
116
        $subdir = Directory::with( 'medium.medium' )->find( $dirId );
117
        $subdir[ "subdirs" ] = $dirs;
118
        $subdir[ "items" ] = $items;
119
        return view( 'subdir', [
120
            "subdir" => $subdir,
121
            "nav"    => $GLOBALS[ "menu" ],
122
            "ini"    => $GLOBALS[ "INI" ]
123
        ] );
124
    } );
125
    Route::get( "{item:slug}.html", function ( Item $item )
126
    {
127
        $item->load( 'price', 'medium.medium' );
128
        return view( 'item', [
129
            "item" => $item,
130
            "nav"  => $GLOBALS[ "menu" ],
131
            "ini"  => $GLOBALS[ "INI" ]
132
        ] );
133
    } );
134
    Route::get( '/', function ()
135
    {
136
        $aktion = Action::with( 'medium.medium' )->get();
137
        return view( 'startpage', [
138
            "pagetype" => "Startseite",
139
            "aktion"   => $aktion,
140
            "nav"      => $GLOBALS[ "menu" ],
141
            "ini"      => $GLOBALS[ "INI" ]
142
        ] );
143
    } );