Subversion-Projekte lars-tiefland.laravel_shop

Revision

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