Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 650 | Revision 671 | 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
 
624 lars 27
    if ( php_sapi_name() == "cli" )
582 lars 28
    {
29
        return;
30
    }
340 lars 31
    $sql = "
32
        SELECT
33
            *
34
        FROM
35
            i18n_de
36
    ";
405 lars 37
    if ( Schema::hasTable( 'i18n_de' ) )
38
    {
39
        $langstrings = DB::select( $sql );
40
    }
41
    else
42
    {
43
        $langstrings = DB::connection( "old" )->select( $sql );
44
    }
340 lars 45
    foreach ( $langstrings as $langstring )
46
    {
355 lars 47
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 48
    }
355 lars 49
 
367 lars 50
    function parseCMSPage( $url ): array
355 lars 51
    {
375 lars 52
        $menu = "";
53
        $content = "";
365 lars 54
        $dom = new Dom;
366 lars 55
        try
56
        {
57
            $dom->loadFromUrl( $url );
375 lars 58
            $menu = $dom->getElementById( 'menu' )->innerHtml;
59
            $menu = str_replace( "/typo3", "/cms", $menu );
60
            $content = $dom->getElementById( 'content' )->innerHtml;
61
            $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
62
            $content = str_replace( "ce-textpic", "", $content );
366 lars 63
        }
375 lars 64
        catch ( ChildNotFoundException|CircularException|CurlException|StrictException|NotLoadedException $e )
366 lars 65
        {
66
        }
355 lars 67
        return array( "menu" => $menu, "content" => $content, );
68
    }
69
 
333 lars 70
    function getConfig()
71
    {
72
        define( '__SITE__', env( 'site' ) );
73
        define( '__SHOP__', env( 'shop' ) );
74
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 75
 
333 lars 76
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
77
        if ( !file_exists( $cfg_file ) )
78
        {
79
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
80
        }
81
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
82
        $ini = json_decode( json_encode( $xml ), true );
83
        foreach ( $ini as $key => $wert )
84
        {
85
            if ( $wert == array() )
86
            {
355 lars 87
                $ini[$key] = "";
333 lars 88
            }
89
            elseif ( is_array( $wert ) )
90
            {
91
                foreach ( $wert as $key2 => $wert2 )
92
                {
93
                    if ( $wert2 == array() )
94
                    {
355 lars 95
                        $ini[$key][$key2] = "";
333 lars 96
                    }
176 lars 97
                }
98
            }
99
        }
100
 
333 lars 101
        $v_file = __CFG_PATH__ . "/versand.xml";
102
        if ( file_exists( $v_file ) )
103
        {
104
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 105
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
106
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 107
            {
108
                if ( $wert == array() )
109
                {
355 lars 110
                    $ini["shipping"][$key] = "";
333 lars 111
                }
112
                elseif ( is_array( $wert ) )
113
                {
114
                    foreach ( $wert as $key2 => $wert2 )
115
                    {
116
                        if ( $wert2 == array() )
117
                        {
355 lars 118
                            $ini["shipping"][$key][$key2] = "";
333 lars 119
                        }
176 lars 120
                    }
121
                }
122
            }
123
        }
333 lars 124
        return $ini;
177 lars 125
    }
126
 
333 lars 127
    session_start();
355 lars 128
    $GLOBALS["INI"] = getConfig();
129
    $GLOBALS["menu"] = array();
333 lars 130
    $nav = new Directory();
355 lars 131
    $GLOBALS["menu"] = $nav->nav_menu();
368 lars 132
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
133
    $GLOBALS["serviceCenterMenu"] = $sc["menu"];
333 lars 134
    /* Mobile Weiche */
355 lars 135
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 136
    {
375 lars 137
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] === false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] === false )
333 lars 138
        {
88 lars 139
 
355 lars 140
            $_SESSION['isMobile'] = false;
141
            $GLOBALS['isMobile'] = false;
88 lars 142
 
333 lars 143
            if (
375 lars 144
                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 145
            )
146
            {
88 lars 147
 
355 lars 148
                $_SESSION['isMobile'] = true;
149
                $GLOBALS['isMobile'] = true;
333 lars 150
            }
151
 
88 lars 152
        }
153
    }
405 lars 154
    Route::get( "/addItemToBasket", function ()
385 lars 155
    {
405 lars 156
        Basket::addItem();
157
    } );
658 lars 158
    Route::get( '/setSessionVars', function ()
159
    {
160
        foreach ( $_GET as $key => $value )
161
        {
162
            if ( $value == "false" )
163
            {
164
                unset( $_SESSION[$key] );
165
            }
166
            else
167
            {
168
                $_SESSION[$key] = $value;
169
            }
170
        }
171
    } );
355 lars 172
    Route::get( "/cms/{slug}", function ( $slug )
173
    {
359 lars 174
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 175
        $arr = parseCMSPage( $url );
355 lars 176
        $content = $arr["content"];
361 lars 177
        return view( 'service_center_content', [
368 lars 178
            "serviceContent"    => $content,
179
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
180
            "nav"               => $GLOBALS["menu"],
181
            "ini"               => $GLOBALS["INI"],
182
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 183
        ] );
184
    } );
377 lars 185
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 186
    {
405 lars 187
        return view( 'buy_' . $id, [
376 lars 188
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
189
            "nav"               => $GLOBALS["menu"],
190
            "ini"               => $GLOBALS["INI"],
191
            "langstrings"       => $GLOBALS["langstrings"],
192
        ] );
405 lars 193
    } )->where( 'id', '[1-4]{1,}[ab]{0,1}' );
391 lars 194
    Route::post( "/bestellen_seite_{id}.html", function ( $id )
195
    {
405 lars 196
        return view( 'buy_' . $id, [
391 lars 197
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
198
            "nav"               => $GLOBALS["menu"],
199
            "ini"               => $GLOBALS["INI"],
200
            "langstrings"       => $GLOBALS["langstrings"],
201
        ] );
405 lars 202
    } )->where( 'id', '[1-4]{1,}[ab]{0,1}' );
349 lars 203
    Route::get( "basket.html", function ()
204
    {
205
        return view( 'basket', [
368 lars 206
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
207
            "nav"               => $GLOBALS["menu"],
208
            "ini"               => $GLOBALS["INI"],
209
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 210
        ] );
211
    } );
333 lars 212
    Route::get( "/directory/{id}", function ( $id )
213
    {
214
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
215
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
216
            0,
217
            99
650 lars 218
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 219
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
624 lars 220
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
355 lars 221
        $subdir["subdirs"] = $dirs;
222
        $subdir["items"] = $items;
628 lars 223
        $template = 'subdir';
634 lars 224
        $artstaemmeItems = array();
631 lars 225
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 226
        {
227
            $template = substr( $subdir->temmplate[0]->template->template_value, strpos( "$subdir->temmplate[0]->template->template_value", "=" ) + 1 );
634 lars 228
            foreach ( $dirs as $dir )
229
            {
230
                if ( $dir->articlemaster == 1 )
231
                {
636 lars 232
                    $artstaemmeItems[$dir->id] = $dir;
646 lars 233
                    $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();;
634 lars 234
                }
235
            }
628 lars 236
        }
237
        return view( $template, [
368 lars 238
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
239
            "subdir"            => $subdir,
240
            "nav"               => $GLOBALS["menu"],
241
            "ini"               => $GLOBALS["INI"],
242
            "langstrings"       => $GLOBALS["langstrings"],
634 lars 243
            "artstaemmeItems"   => $artstaemmeItems,
333 lars 244
        ] );
245
    } );
246
    Route::get( "{item:slug}.html", function ( Item $item )
247
    {
646 lars 248
        $item->load( 'price', 'medium.medium', 'manufacturer' );
333 lars 249
        return view( 'item', [
368 lars 250
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
251
            "item"              => $item,
252
            "nav"               => $GLOBALS["menu"],
253
            "ini"               => $GLOBALS["INI"],
254
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 255
        ] );
256
    } );
257
    Route::get( '/', function ()
258
    {
405 lars 259
        $date = date( "Y-m-d" );
260
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 261
        return view( 'startpage', [
368 lars 262
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
263
            "pagetype"          => "Startseite",
264
            "aktion"            => $aktion,
265
            "nav"               => $GLOBALS["menu"],
266
            "ini"               => $GLOBALS["INI"],
267
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 268
        ] );
269
    } );