Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 371 | Revision 373 | 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;
369 lars 47
        $menu = str_replace( "/typo3", "/cms", $menu );
368 lars 48
        $content = $dom->getElementById( 'content' )->innerHtml;
372 lars 49
        $content = str_replace( "fileadmin/", $GLOBALS["INI"]["typo3"]["url"] . "/typo3/fileadmin/", $content );
355 lars 50
        return array( "menu" => $menu, "content" => $content, );
51
    }
52
 
333 lars 53
    function getConfig()
54
    {
55
        define( '__SITE__', env( 'site' ) );
56
        define( '__SHOP__', env( 'shop' ) );
57
        define( "__CFG_PATH__", "/etc/shop_configs/" . __SITE__ . "/" . __SHOP__ );
176 lars 58
 
333 lars 59
        $cfg_file = __CFG_PATH__ . "/config.de.xml";
60
        if ( !file_exists( $cfg_file ) )
61
        {
62
            trigger_error( "Konnte keine Konfigurationsdatei für das Shopsystem " . __SITE__ . " -> " . __SHOP__ . " finden (" . ( $cfg_file ) . ")!", E_USER_ERROR );
63
        }
64
        $xml = simplexml_load_file( $cfg_file, "SimpleXMLElement", LIBXML_NOCDATA );
65
        $ini = json_decode( json_encode( $xml ), true );
66
        foreach ( $ini as $key => $wert )
67
        {
68
            if ( $wert == array() )
69
            {
355 lars 70
                $ini[$key] = "";
333 lars 71
            }
72
            elseif ( is_array( $wert ) )
73
            {
74
                foreach ( $wert as $key2 => $wert2 )
75
                {
76
                    if ( $wert2 == array() )
77
                    {
355 lars 78
                        $ini[$key][$key2] = "";
333 lars 79
                    }
176 lars 80
                }
81
            }
82
        }
83
 
333 lars 84
        $v_file = __CFG_PATH__ . "/versand.xml";
85
        if ( file_exists( $v_file ) )
86
        {
87
            $xml = simplexml_load_file( $v_file, "SimpleXMLElement", LIBXML_NOCDATA );
355 lars 88
            $ini["shipping"] = json_decode( json_encode( $xml ), true );
89
            foreach ( $ini["shipping"] as $key => $wert )
333 lars 90
            {
91
                if ( $wert == array() )
92
                {
355 lars 93
                    $ini["shipping"][$key] = "";
333 lars 94
                }
95
                elseif ( is_array( $wert ) )
96
                {
97
                    foreach ( $wert as $key2 => $wert2 )
98
                    {
99
                        if ( $wert2 == array() )
100
                        {
355 lars 101
                            $ini["shipping"][$key][$key2] = "";
333 lars 102
                        }
176 lars 103
                    }
104
                }
105
            }
106
        }
333 lars 107
        return $ini;
177 lars 108
    }
109
 
333 lars 110
    session_start();
355 lars 111
    $GLOBALS["INI"] = getConfig();
112
    $GLOBALS["menu"] = array();
333 lars 113
    $nav = new Directory();
355 lars 114
    $GLOBALS["menu"] = $nav->nav_menu();
368 lars 115
    $sc = parseCMSPage( $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" );
116
    $GLOBALS["serviceCenterMenu"] = $sc["menu"];
333 lars 117
    /* Mobile Weiche */
355 lars 118
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 119
    {
355 lars 120
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] == false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] == false )
333 lars 121
        {
88 lars 122
 
355 lars 123
            $_SESSION['isMobile'] = false;
124
            $GLOBALS['isMobile'] = false;
88 lars 125
 
333 lars 126
            if (
127
                preg_match( "/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine
88 lars 128
        |htc|iemobile|iphone|iPad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|
129
        panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus
355 lars 130
        |up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i", $_SERVER["HTTP_USER_AGENT"] )
333 lars 131
            )
132
            {
88 lars 133
 
355 lars 134
                $_SESSION['isMobile'] = true;
135
                $GLOBALS['isMobile'] = true;
333 lars 136
            }
137
 
88 lars 138
        }
139
    }
355 lars 140
    Route::get( "/cms/{slug}", function ( $slug )
141
    {
359 lars 142
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 143
        $arr = parseCMSPage( $url );
355 lars 144
        $content = $arr["content"];
361 lars 145
        return view( 'service_center_content', [
368 lars 146
            "serviceContent"    => $content,
147
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
148
            "nav"               => $GLOBALS["menu"],
149
            "ini"               => $GLOBALS["INI"],
150
            "langstrings"       => $GLOBALS["langstrings"],
355 lars 151
        ] );
152
    } );
349 lars 153
    Route::get( "basket.html", function ()
154
    {
155
        return view( 'basket', [
368 lars 156
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
157
            "nav"               => $GLOBALS["menu"],
158
            "ini"               => $GLOBALS["INI"],
159
            "langstrings"       => $GLOBALS["langstrings"],
349 lars 160
        ] );
161
    } );
333 lars 162
    Route::get( "/directory/{id}", function ( $id )
163
    {
164
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
165
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
166
            0,
167
            2,
168
            99
169
        ] )->get();
170
        $items = Item::with( 'price' )->with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
171
            0,
172
            2
173
        ] )->get();
174
        $subdir = Directory::with( 'medium.medium' )->find( $dirId );
355 lars 175
        $subdir["subdirs"] = $dirs;
176
        $subdir["items"] = $items;
333 lars 177
        return view( 'subdir', [
368 lars 178
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
179
            "subdir"            => $subdir,
180
            "nav"               => $GLOBALS["menu"],
181
            "ini"               => $GLOBALS["INI"],
182
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 183
        ] );
184
    } );
185
    Route::get( "{item:slug}.html", function ( Item $item )
186
    {
187
        $item->load( 'price', 'medium.medium' );
188
        return view( 'item', [
368 lars 189
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
190
            "item"              => $item,
191
            "nav"               => $GLOBALS["menu"],
192
            "ini"               => $GLOBALS["INI"],
193
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 194
        ] );
195
    } );
196
    Route::get( '/', function ()
197
    {
198
        $aktion = Action::with( 'medium.medium' )->get();
199
        return view( 'startpage', [
368 lars 200
            "serviceCenterMenu" => $GLOBALS["serviceCenterMenu"],
201
            "pagetype"          => "Startseite",
202
            "aktion"            => $aktion,
203
            "nav"               => $GLOBALS["menu"],
204
            "ini"               => $GLOBALS["INI"],
205
            "langstrings"       => $GLOBALS["langstrings"],
333 lars 206
        ] );
207
    } );