Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 349 | Revision 356 | 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
 
340 lars 19
    $sql = "
20
        SELECT
21
            *
22
        FROM
23
            i18n_de
24
    ";
25
    $langstrings = DB::select( $sql );
26
    foreach ( $langstrings as $langstring )
27
    {
355 lars 28
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 29
    }
355 lars 30
    function getCMSPage( $url )
31
    {
32
        $ch = curl_init( $url );
33
        curl_setopt_array( $ch, array(
34
            CURLOPT_RETURNTRANSFER => true,
35
        );
36
        $erg = curl_exec( $ch );
37
        $code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
38
        return $erg;
39
    }
40
 
41
    function parseCMSPage( $content )
42
    {
43
        $doc = new DomDocument;
44
        $doc->validateOnParse = true;
45
        $doc->loadHtml( $erg );
46
        $menu = $doc->getElementById( "menu" )->nodeValue;
47
        $content = $doc->getElementById( "content" )->nodeValue;
48
        return array( "menu" => $menu, "content" => $content, );
49
    }
50
 
333 lars 51
    function getConfig()
52
    {
53
        define( '__SITE__', env( 'site' ) );
54
        define( '__SHOP__', env( 'shop' ) );
55
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 56
 
333 lars 57
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
58
        if ( !file_exists( $cfg_file ) )
59
        {
60
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
61
        }
62
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
63
        $ini = json_decode( json_encode( $xml ), true );
64
        foreach ( $ini as $key => $wert )
65
        {
66
            if ( $wert == array() )
67
            {
355 lars 68
                $ini[$key] = "";
333 lars 69
            }
70
            elseif ( is_array( $wert ) )
71
            {
72
                foreach ( $wert as $key2 => $wert2 )
73
                {
74
                    if ( $wert2 == array() )
75
                    {
355 lars 76
                        $ini[$key][$key2] = "";
333 lars 77
                    }
176 lars 78
                }
79
            }
80
        }
81
 
333 lars 82
        $v_file = __CFG_PATH__ . "/versand.xml";
83
        if ( file_exists( $v_file ) )
84
        {
85
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 86
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
87
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 88
            {
89
                if ( $wert == array() )
90
                {
355 lars 91
                    $ini["shipping"][$key] = "";
333 lars 92
                }
93
                elseif ( is_array( $wert ) )
94
                {
95
                    foreach ( $wert as $key2 => $wert2 )
96
                    {
97
                        if ( $wert2 == array() )
98
                        {
355 lars 99
                            $ini["shipping"][$key][$key2] = "";
333 lars 100
                        }
176 lars 101
                    }
102
                }
103
            }
104
        }
333 lars 105
        return $ini;
177 lars 106
    }
107
 
333 lars 108
    session_start();
355 lars 109
    $GLOBALS["INI"] = getConfig();
110
    $GLOBALS["menu"] = array();
333 lars 111
    $nav = new Directory();
355 lars 112
    $GLOBALS["menu"] = $nav->nav_menu();
333 lars 113
    /* Mobile Weiche */
355 lars 114
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 115
    {
355 lars 116
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] == false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] == false )
333 lars 117
        {
88 lars 118
 
355 lars 119
            $_SESSION['isMobile'] = false;
120
            $GLOBALS['isMobile'] = false;
88 lars 121
 
333 lars 122
            if (
123
                preg_match( "/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine
88 lars 124
        |htc|iemobile|iphone|iPad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|
125
        panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus
355 lars 126
        |up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i", $_SERVER["HTTP_USER_AGENT"] )
333 lars 127
            )
128
            {
88 lars 129
 
355 lars 130
                $_SESSION['isMobile'] = true;
131
                $GLOBALS['isMobile'] = true;
333 lars 132
            }
133
 
88 lars 134
        }
135
    }
355 lars 136
    Route::get( "/cms/{slug}", function ( $slug )
137
    {
138
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/" . $slug;
139
        $res = getCMSPage( $url );
140
        $arr = parseCMSPage( $res );
141
        $content = $arr["content"];
142
        return view( 'subdir', [
143
            "content"      => $content,
144
            "nav"         => $GLOBALS["menu"],
145
            "ini"         => $GLOBALS["INI"],
146
            "langstrings" => $GLOBALS["langstrings"],
147
        ] );
148
    } );
349 lars 149
    Route::get( "basket.html", function ()
150
    {
151
        return view( 'basket', [
355 lars 152
            "nav"         => $GLOBALS["menu"],
153
            "ini"         => $GLOBALS["INI"],
154
            "langstrings" => $GLOBALS["langstrings"],
349 lars 155
        ] );
156
    } );
333 lars 157
    Route::get( "/directory/{id}", function ( $id )
158
    {
159
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
160
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
161
            0,
162
            2,
163
            99
164
        ] )->get();
165
        $items = Item::with( 'price' )->with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
166
            0,
167
            2
168
        ] )->get();
169
        $subdir = Directory::with( 'medium.medium' )->find( $dirId );
355 lars 170
        $subdir["subdirs"] = $dirs;
171
        $subdir["items"] = $items;
333 lars 172
        return view( 'subdir', [
355 lars 173
            "subdir"      => $subdir,
174
            "nav"         => $GLOBALS["menu"],
175
            "ini"         => $GLOBALS["INI"],
176
            "langstrings" => $GLOBALS["langstrings"],
333 lars 177
        ] );
178
    } );
179
    Route::get( "{item:slug}.html", function ( Item $item )
180
    {
181
        $item->load( 'price', 'medium.medium' );
182
        return view( 'item', [
355 lars 183
            "item"        => $item,
184
            "nav"         => $GLOBALS["menu"],
185
            "ini"         => $GLOBALS["INI"],
186
            "langstrings" => $GLOBALS["langstrings"],
333 lars 187
        ] );
188
    } );
189
    Route::get( '/', function ()
190
    {
191
        $aktion = Action::with( 'medium.medium' )->get();
192
        return view( 'startpage', [
343 lars 193
            "pagetype"    => "Startseite",
194
            "aktion"      => $aktion,
355 lars 195
            "nav"         => $GLOBALS["menu"],
196
            "ini"         => $GLOBALS["INI"],
197
            "langstrings" => $GLOBALS["langstrings"],
333 lars 198
        ] );
199
    } );