Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 362 | Revision 364 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
<?php
2
 
333 lars 3
    use App\Models\Action;
4
    use App\Models\Item;
5
    use App\Models\Directory;
6
    use Illuminate\Support\Facades\Route;
2 lars 7
 
333 lars 8
    /*
9
    |--------------------------------------------------------------------------
10
    | Web Routes
11
    |--------------------------------------------------------------------------
12
    |
13
    | Here is where you can register web routes for your application. These
14
    | routes are loaded by the RouteServiceProvider within a group which
15
    | contains the "web" middleware group. Now create something great!
16
    |
17
     */
2 lars 18
 
340 lars 19
    $sql = "
20
        SELECT
21
            *
22
        FROM
23
            i18n_de
24
    ";
25
    $langstrings = DB::select( $sql );
26
    foreach ( $langstrings as $langstring )
27
    {
355 lars 28
        $GLOBALS["langstrings"][$langstring->page_id][$langstring->id] = $langstring->string;
340 lars 29
    }
355 lars 30
    function getCMSPage( $url )
31
    {
32
        $ch = curl_init( $url );
33
        curl_setopt_array( $ch, array(
356 lars 34
                CURLOPT_RETURNTRANSFER => true,
35
            )
355 lars 36
        );
37
        $erg = curl_exec( $ch );
38
        $code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
39
        return $erg;
40
    }
41
 
42
    function parseCMSPage( $content )
43
    {
44
        $doc = new DomDocument;
363 lars 45
        $content = str_replace( array( "<header>", "</header>" ), "", $content );
355 lars 46
        $doc->validateOnParse = true;
357 lars 47
        $doc->loadHtml( $content );
355 lars 48
        $menu = $doc->getElementById( "menu" )->nodeValue;
49
        $content = $doc->getElementById( "content" )->nodeValue;
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();
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;
355 lars 141
        $res = getCMSPage( $url );
142
        $arr = parseCMSPage( $res );
143
        $content = $arr["content"];
361 lars 144
        return view( 'service_center_content', [
356 lars 145
            "content"     => $content,
355 lars 146
            "nav"         => $GLOBALS["menu"],
147
            "ini"         => $GLOBALS["INI"],
148
            "langstrings" => $GLOBALS["langstrings"],
149
        ] );
150
    } );
349 lars 151
    Route::get( "basket.html", function ()
152
    {
153
        return view( 'basket', [
355 lars 154
            "nav"         => $GLOBALS["menu"],
155
            "ini"         => $GLOBALS["INI"],
156
            "langstrings" => $GLOBALS["langstrings"],
349 lars 157
        ] );
158
    } );
333 lars 159
    Route::get( "/directory/{id}", function ( $id )
160
    {
161
        list( $dirId, $dirName ) = explode( "-", $id, 2 );
162
        $dirs = Directory::with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
163
            0,
164
            2,
165
            99
166
        ] )->get();
167
        $items = Item::with( 'price' )->with( 'medium.medium' )->where( "directory_id", $dirId )->whereIn( 'status', [
168
            0,
169
            2
170
        ] )->get();
171
        $subdir = Directory::with( 'medium.medium' )->find( $dirId );
355 lars 172
        $subdir["subdirs"] = $dirs;
173
        $subdir["items"] = $items;
333 lars 174
        return view( 'subdir', [
355 lars 175
            "subdir"      => $subdir,
176
            "nav"         => $GLOBALS["menu"],
177
            "ini"         => $GLOBALS["INI"],
178
            "langstrings" => $GLOBALS["langstrings"],
333 lars 179
        ] );
180
    } );
181
    Route::get( "{item:slug}.html", function ( Item $item )
182
    {
183
        $item->load( 'price', 'medium.medium' );
184
        return view( 'item', [
355 lars 185
            "item"        => $item,
186
            "nav"         => $GLOBALS["menu"],
187
            "ini"         => $GLOBALS["INI"],
188
            "langstrings" => $GLOBALS["langstrings"],
333 lars 189
        ] );
190
    } );
191
    Route::get( '/', function ()
192
    {
193
        $aktion = Action::with( 'medium.medium' )->get();
194
        return view( 'startpage', [
343 lars 195
            "pagetype"    => "Startseite",
196
            "aktion"      => $aktion,
355 lars 197
            "nav"         => $GLOBALS["menu"],
198
            "ini"         => $GLOBALS["INI"],
199
            "langstrings" => $GLOBALS["langstrings"],
333 lars 200
        ] );
201
    } );