Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 365 | Revision 367 | 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
 
365 lars 36
    function parseCMSPage( $url )
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
        }
365 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();
333 lars 113
    /* Mobile Weiche */
355 lars 114
    if ( isset( $_SERVER["HTTP_USER_AGENT"] ) )
333 lars 115
    {
355 lars 116
        if ( !isset( $_SESSION['isMobile'] ) || $_SESSION['isMobile'] == false || !isset( $GLOBALS['isMobile'] ) || $GLOBALS['isMobile'] == false )
333 lars 117
        {
88 lars 118
 
355 lars 119
            $_SESSION['isMobile'] = false;
120
            $GLOBALS['isMobile'] = false;
88 lars 121
 
333 lars 122
            if (
123
                preg_match( "/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine
88 lars 124
        |htc|iemobile|iphone|iPad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|
125
        panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus
355 lars 126
        |up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i", $_SERVER["HTTP_USER_AGENT"] )
333 lars 127
            )
128
            {
88 lars 129
 
355 lars 130
                $_SESSION['isMobile'] = true;
131
                $GLOBALS['isMobile'] = true;
333 lars 132
            }
133
 
88 lars 134
        }
135
    }
355 lars 136
    Route::get( "/cms/{slug}", function ( $slug )
137
    {
359 lars 138
        $url = $GLOBALS["INI"]["typo3"]["url"] . "/typo3/" . $slug;
365 lars 139
        $arr = parseCMSPage( $url );
355 lars 140
        $content = $arr["content"];
361 lars 141
        return view( 'service_center_content', [
364 lars 142
            "serviceContent" => $content,
143
            "nav"            => $GLOBALS["menu"],
144
            "ini"            => $GLOBALS["INI"],
145
            "langstrings"    => $GLOBALS["langstrings"],
355 lars 146
        ] );
147
    } );
349 lars 148
    Route::get( "basket.html", function ()
149
    {
150
        return view( 'basket', [
355 lars 151
            "nav"         => $GLOBALS["menu"],
152
            "ini"         => $GLOBALS["INI"],
153
            "langstrings" => $GLOBALS["langstrings"],
349 lars 154
        ] );
155
    } );
333 lars 156
    Route::get( "/directory/{id}", function ( $id )
157
    {
158
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
159
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
160
            0,
161
            2,
162
            99
163
        ] )->get();
164
        $items = Item::with( 'price' )->with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
165
            0,
166
            2
167
        ] )->get();
168
        $subdir = Directory::with( 'medium.medium' )->find( $dirId );
355 lars 169
        $subdir["subdirs"] = $dirs;
170
        $subdir["items"] = $items;
333 lars 171
        return view( 'subdir', [
355 lars 172
            "subdir"      => $subdir,
173
            "nav"         => $GLOBALS["menu"],
174
            "ini"         => $GLOBALS["INI"],
175
            "langstrings" => $GLOBALS["langstrings"],
333 lars 176
        ] );
177
    } );
178
    Route::get( "{item:slug}.html", function ( Item $item )
179
    {
180
        $item->load( 'price', 'medium.medium' );
181
        return view( 'item', [
355 lars 182
            "item"        => $item,
183
            "nav"         => $GLOBALS["menu"],
184
            "ini"         => $GLOBALS["INI"],
185
            "langstrings" => $GLOBALS["langstrings"],
333 lars 186
        ] );
187
    } );
188
    Route::get( '/', function ()
189
    {
190
        $aktion = Action::with( 'medium.medium' )->get();
191
        return view( 'startpage', [
343 lars 192
            "pagetype"    => "Startseite",
193
            "aktion"      => $aktion,
355 lars 194
            "nav"         => $GLOBALS["menu"],
195
            "ini"         => $GLOBALS["INI"],
196
            "langstrings" => $GLOBALS["langstrings"],
333 lars 197
        ] );
198
    } );