Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 646 | Revision 658 | 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
    } );
355 lars 158
    Route::get( "/cms/{slug}", function ( $slug )
159
    {
359 lars 160
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 161
        $arr = parseCMSPage( $url );
355 lars 162
        $content = $arr["content"];
361 lars 163
        return view( 'service_center_content', [
368 lars 164
            "serviceContent"    => $content,
165
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
166
            "nav"               => $GLOBALS["menu"],
167
            "ini"               => $GLOBALS["INI"],
168
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 169
        ] );
170
    } );
377 lars 171
    Route::get( "/bestellen_seite_{id}.html", function ( $id )
376 lars 172
    {
405 lars 173
        return view( 'buy_' . $id, [
376 lars 174
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
175
            "nav"               => $GLOBALS["menu"],
176
            "ini"               => $GLOBALS["INI"],
177
            "langstrings"       => $GLOBALS["langstrings"],
178
        ] );
405 lars 179
    } )->where( 'id', '[1-4]{1,}[ab]{0,1}' );
391 lars 180
    Route::post( "/bestellen_seite_{id}.html", function ( $id )
181
    {
405 lars 182
        return view( 'buy_' . $id, [
391 lars 183
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
184
            "nav"               => $GLOBALS["menu"],
185
            "ini"               => $GLOBALS["INI"],
186
            "langstrings"       => $GLOBALS["langstrings"],
187
        ] );
405 lars 188
    } )->where( 'id', '[1-4]{1,}[ab]{0,1}' );
349 lars 189
    Route::get( "basket.html", function ()
190
    {
191
        return view( 'basket', [
368 lars 192
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
193
            "nav"               => $GLOBALS["menu"],
194
            "ini"               => $GLOBALS["INI"],
195
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 196
        ] );
197
    } );
333 lars 198
    Route::get( "/directory/{id}", function ( $id )
199
    {
200
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
201
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
202
            0,
203
            99
650 lars 204
        ] )->orderBy( 'kennung' )->orderBy( 'name' )->get();
643 lars 205
        $items = Item::with( 'price', 'medium.medium', 'manufacturer' )->where( "directory_id", $dirId )->where( 'status', '=', 0 )->get();
624 lars 206
        $subdir = Directory::with( 'medium.medium', 'template.template' )->find( $dirId );
355 lars 207
        $subdir["subdirs"] = $dirs;
208
        $subdir["items"] = $items;
628 lars 209
        $template = 'subdir';
634 lars 210
        $artstaemmeItems = array();
631 lars 211
        if ( is_countable( $subdir->template ) && isset( $subdir->template[0] ) )
628 lars 212
        {
213
            $template = substr( $subdir->temmplate[0]->template->template_value, strpos( "$subdir->temmplate[0]->template->template_value", "=" ) + 1 );
634 lars 214
            foreach ( $dirs as $dir )
215
            {
216
                if ( $dir->articlemaster == 1 )
217
                {
636 lars 218
                    $artstaemmeItems[$dir->id] = $dir;
646 lars 219
                    $artstaemmeItems[$dir->id]["items"] = Item::with( 'medium.medium', 'price', 'manufacturer' )->where( 'directory_id', '=', $dir->id )->where( 'status', '=', 0 )->get();;
634 lars 220
                }
221
            }
628 lars 222
        }
223
        return view( $template, [
368 lars 224
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
225
            "subdir"            => $subdir,
226
            "nav"               => $GLOBALS["menu"],
227
            "ini"               => $GLOBALS["INI"],
228
            "langstrings"       => $GLOBALS["langstrings"],
634 lars 229
            "artstaemmeItems"   => $artstaemmeItems,
333 lars 230
        ] );
231
    } );
232
    Route::get( "{item:slug}.html", function ( Item $item )
233
    {
646 lars 234
        $item->load( 'price', 'medium.medium', 'manufacturer' );
333 lars 235
        return view( 'item', [
368 lars 236
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
237
            "item"              => $item,
238
            "nav"               => $GLOBALS["menu"],
239
            "ini"               => $GLOBALS["INI"],
240
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 241
        ] );
242
    } );
243
    Route::get( '/', function ()
244
    {
405 lars 245
        $date = date( "Y-m-d" );
246
        $aktion = Action::with( 'medium.medium' )->where( 'valid_from', '<=', $date )->where( 'valid_to', '>=', $date )->get();
333 lars 247
        return view( 'startpage', [
368 lars 248
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
249
            "pagetype"          => "Startseite",
250
            "aktion"            => $aktion,
251
            "nav"               => $GLOBALS["menu"],
252
            "ini"               => $GLOBALS["INI"],
253
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 254
        ] );
255
    } );