Subversion-Projekte lars-tiefland.laravel_shop

Revision

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