Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 405 | Revision 416 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
385 lars 3
    use App\Http\Controllers\Basket;
375 lars 4
    use Illuminate\Support\Facades\DB;
365 lars 5
    use PHPHtmlParser\Dom;
333 lars 6
    use App\Models\Action;
7
    use App\Models\Item;
8
    use App\Models\Directory;
9
    use Illuminate\Support\Facades\Route;
366 lars 10
    use PHPHtmlParser\Exceptions\ChildNotFoundException;
11
    use PHPHtmlParser\Exceptions\CircularException;
12
    use PHPHtmlParser\Exceptions\CurlException;
375 lars 13
    use PHPHtmlParser\Exceptions\NotLoadedException;
366 lars 14
    use PHPHtmlParser\Exceptions\StrictException;
2 lars 15
 
333 lars 16
    /*
17
    |--------------------------------------------------------------------------
18
    | Web Routes
19
    |--------------------------------------------------------------------------
20
    |
21
    | Here is where you can register web routes for your application. These
22
    | routes are loaded by the RouteServiceProvider within a group which
23
    | contains the "web" middleware group. Now create something great!
24
    |
25
     */
2 lars 26
 
340 lars 27
    $sql = "
28
        SELECT
29
            *
30
        FROM
31
            i18n_de
32
    ";
405 lars 33
    if ( Schema::hasTable( 'i18n_de' ) )
34
    {
35
        $langstrings = DB::select( $sql );
36
    }
37
    else
38
    {
39
        $langstrings = DB::connection( "old" )->select( $sql );
40
    }
340 lars 41
    foreach ( $langstrings as $langstring )
42
    {
355 lars 43
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 44
    }
355 lars 45
 
367 lars 46
    function parseCMSPage( $url ): array
355 lars 47
    {
375 lars 48
        $menu = "";
49
        $content = "";
365 lars 50
        $dom = new Dom;
366 lars 51
        try
52
        {
53
            $dom->loadFromUrl( $url );
375 lars 54
            $menu = $dom->getElementById( 'menu' )->innerHtml;
55
            $menu = str_replace( "/typo3", "/cms", $menu );
56
            $content = $dom->getElementById( 'content' )->innerHtml;
57
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
58
            $content = str_replace( "ce-textpic", "", $content );
366 lars 59
        }
375 lars 60
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
366 lars 61
        {
62
        }
355 lars 63
        return array( "menu" => $menu, "content" => $content, );
64
    }
65
 
333 lars 66
    function getConfig()
67
    {
68
        define( '__SITE__', env( 'site' ) );
69
        define( '__SHOP__', env( 'shop' ) );
70
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 71
 
333 lars 72
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
73
        if ( !file_exists( $cfg_file ) )
74
        {
75
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
76
        }
77
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
78
        $ini = json_decode( json_encode( $xml ), true );
79
        foreach ( $ini as $key => $wert )
80
        {
81
            if ( $wert == array() )
82
            {
355 lars 83
                $ini[$key] = "";
333 lars 84
            }
85
            elseif ( is_array( $wert ) )
86
            {
87
                foreach ( $wert as $key2 => $wert2 )
88
                {
89
                    if ( $wert2 == array() )
90
                    {
355 lars 91
                        $ini[$key][$key2] = "";
333 lars 92
                    }
176 lars 93
                }
94
            }
95
        }
96
 
333 lars 97
        $v_file = __CFG_PATH__ . "/versand.xml";
98
        if ( file_exists( $v_file ) )
99
        {
100
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 101
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
102
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 103
            {
104
                if ( $wert == array() )
105
                {
355 lars 106
                    $ini["shipping"][$key] = "";
333 lars 107
                }
108
                elseif ( is_array( $wert ) )
109
                {
110
                    foreach ( $wert as $key2 => $wert2 )
111
                    {
112
                        if ( $wert2 == array() )
113
                        {
355 lars 114
                            $ini["shipping"][$key][$key2] = "";
333 lars 115
                        }
176 lars 116
                    }
117
                }
118
            }
119
        }
333 lars 120
        return $ini;
177 lars 121
    }
122
 
333 lars 123
    session_start();
355 lars 124
    $GLOBALS["INI"] = getConfig();
125
    $GLOBALS["menu"] = array();
333 lars 126
    $nav = new Directory();
355 lars 127
    $GLOBALS["menu"] = $nav->nav_menu();
368 lars 128
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
129
    $GLOBALS["serviceCenterMenu"] = $sc["menu"];
333 lars 130
    /* Mobile Weiche */
355 lars 131
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 132
    {
375 lars 133
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
333 lars 134
        {
88 lars 135
 
355 lars 136
            $_SESSION['isMobile'] = false;
137
            $GLOBALS['isMobile'] = false;
88 lars 138
 
333 lars 139
            if (
375 lars 140
                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"] )
333 lars 141
            )
142
            {
88 lars 143
 
355 lars 144
                $_SESSION['isMobile'] = true;
145
                $GLOBALS['isMobile'] = true;
333 lars 146
            }
147
 
88 lars 148
        }
149
    }
405 lars 150
    Route::get( "/addItemToBasket", function ()
385 lars 151
    {
405 lars 152
        Basket::addItem();
153
    } );
355 lars 154
    Route::get( "/cms/{slug}", function ( $slug )
155
    {
359 lars 156
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 157
        $arr = parseCMSPage( $url );
355 lars 158
        $content = $arr["content"];
361 lars 159
        return view( 'service_center_content', [
368 lars 160
            "serviceContent"    => $content,
161
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
162
            "nav"               => $GLOBALS["menu"],
163
            "ini"               => $GLOBALS["INI"],
164
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 165
        ] );
166
    } );
377 lars 167
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 168
    {
405 lars 169
        return view( 'buy_' . $id, [
376 lars 170
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
171
            "nav"               => $GLOBALS["menu"],
172
            "ini"               => $GLOBALS["INI"],
173
            "langstrings"       => $GLOBALS["langstrings"],
174
        ] );
405 lars 175
    } )->where( 'id', '[1-4]{1,}[ab]{0,1}' );
391 lars 176
    Route::post( "/bestellen_seite_{id}.html", function ( $id )
177
    {
405 lars 178
        return view( 'buy_' . $id, [
391 lars 179
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
180
            "nav"               => $GLOBALS["menu"],
181
            "ini"               => $GLOBALS["INI"],
182
            "langstrings"       => $GLOBALS["langstrings"],
183
        ] );
405 lars 184
    } )->where( 'id', '[1-4]{1,}[ab]{0,1}' );
349 lars 185
    Route::get( "basket.html", function ()
186
    {
187
        return view( 'basket', [
368 lars 188
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
189
            "nav"               => $GLOBALS["menu"],
190
            "ini"               => $GLOBALS["INI"],
191
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 192
        ] );
193
    } );
333 lars 194
    Route::get( "/directory/{id}", function ( $id )
195
    {
196
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
197
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
198
            0,
199
            99
200
        ] )->get();
201
        $items = Item::with( 'price' )->with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
202
            0,
203
            2
204
        ] )->get();
205
        $subdir = Directory::with( 'medium.medium' )->find( $dirId );
355 lars 206
        $subdir["subdirs"] = $dirs;
207
        $subdir["items"] = $items;
333 lars 208
        return view( 'subdir', [
368 lars 209
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
210
            "subdir"            => $subdir,
211
            "nav"               => $GLOBALS["menu"],
212
            "ini"               => $GLOBALS["INI"],
213
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 214
        ] );
215
    } );
216
    Route::get( "{item:slug}.html", function ( Item $item )
217
    {
218
        $item->load( 'price', 'medium.medium' );
219
        return view( 'item', [
368 lars 220
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
221
            "item"              => $item,
222
            "nav"               => $GLOBALS["menu"],
223
            "ini"               => $GLOBALS["INI"],
224
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 225
        ] );
226
    } );
227
    Route::get( '/', function ()
228
    {
405 lars 229
        $date = date( "Y-m-d" );
230
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 231
        return view( 'startpage', [
368 lars 232
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
233
            "pagetype"          => "Startseite",
234
            "aktion"            => $aktion,
235
            "nav"               => $GLOBALS["menu"],
236
            "ini"               => $GLOBALS["INI"],
237
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 238
        ] );
239
    } );