Subversion-Projekte lars-tiefland.laravel_shop

Revision

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