Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 375 | Revision 377 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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