Subversion-Projekte lars-tiefland.laravel_shop

Revision

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