function download() { $blocks = array_keys((array) \Larakit\Makeup\Manager::$blocks); $themes = ['default' => 'default'] + \Larakit\Page\PageTheme::getThemes(); $pages = array_keys((array) \Larakit\Makeup\Manager::$pages); $contents = ['!' => public_path('!/'), 'packages' => public_path('packages')]; $tmp_names = []; if (!is_dir(storage_path('makeup/'))) { mkdir(storage_path('makeup/'), 0777, true); } $digest = []; foreach ($pages as $page) { foreach ($themes as $theme) { $name = 'page_' . $page . '--' . $theme . '.html'; $url = url('/makeup/frame-page-' . $page . '?theme=' . $theme); $content = $this->prepare_content($url); $tmp_name = storage_path('makeup/' . $name); file_put_contents($tmp_name, $content); $contents[$name] = fopen($tmp_name, 'r'); $tmp_names[] = $tmp_name; $digest['pages'][$page][$theme] = $name; } } foreach ($blocks as $block) { foreach ($themes as $theme) { $name = 'block_' . $block . '--' . $theme . '.html'; $url = url('/makeup/frame-block-' . $block . '?theme=' . $theme); $content = $this->prepare_content($url); $tmp_name = storage_path('makeup/' . $name); file_put_contents($tmp_name, $content); $contents[$name] = fopen($tmp_name, 'r'); $tmp_names[] = $tmp_name; $digest['blocks'][$block][$theme] = $name; } } $tmp_name = storage_path('makeup/index.html'); // $tmp_names[] = $tmp_name; file_put_contents($tmp_name, \View::make('lk-makeup::!.digest', ['digest' => $digest])->__toString()); $contents['index.html'] = fopen($tmp_name, 'r'); // dd(compact('path', 'theme', 'url', 'content')); // Creates an archive.zip that contains a directory "folder" that contains // files contained in "/path/to/directory" recursively // Load Zippy $zip_path = storage_path(date('H_i_s') . '.zip'); $zippy = Zippy::load(); $zippy->create($zip_path, $contents, true); foreach ($tmp_names as $tmp_name) { unlink($tmp_name); } return \Response::download($zip_path); }
View::composer('lk-makeup::!.layouts.page', function ($view) { $view->with('theme', Request::input('theme')); $view->with('breakpoint', Request::input('breakpoint')); $view->with('path', Request::path()); }); View::composer('lk-makeup::!.layouts.block', function ($view) { $view->with('theme', Request::input('theme')); $view->with('breakpoint', Request::input('breakpoint')); $view->with('path', Request::path()); }); View::composer('lk-makeup::!.partials.dispatcher', function ($view) { $view->with('theme', Request::input('theme')); $view->with('breakpoint', Request::input('breakpoint')); $view->with('path', Request::path()); $view->with('blocks', \Larakit\Makeup\Manager::$blocks); $view->with('themes', ['default' => 'default'] + \Larakit\Page\PageTheme::getThemes()); $view->with('pages', \Larakit\Makeup\Manager::$pages); $breakpoints = []; $breakpoints[0]['text'] = 'FULLPAGE'; $prev = 0; $max = 0; $b = 0; foreach (\Larakit\Makeup\Manager::$breakpoints as $b) { if (!$max) { $max = $b; } $breakpoints[$b] = []; if ($prev) { $breakpoints[$prev]['next'] = $b; } $breakpoints[$b]['prev'] = $prev;