Subversion-Projekte lars-tiefland.laravel_shop

Revision

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