Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 367 | Revision 369 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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