<?php

$action = false;
$galleryBlocks = \CoasterCms\Models\Block::where('type', '=', 'gallery')->get();
if (!$galleryBlocks->isEmpty()) {
    $galleryStorage = public_path() . '/uploads/system/gallery/';
    foreach ($galleryBlocks as $galleryBlock) {
        $oldGalleryDir = $galleryStorage . $galleryBlock->id;
        $newGalleryDir = $galleryStorage . $galleryBlock->name;
        if (is_dir($oldGalleryDir)) {
            $action = true;
            \CoasterCms\Helpers\Cms\File\Directory::copy($oldGalleryDir, $newGalleryDir);
            \CoasterCms\Helpers\Cms\File\Directory::remove($oldGalleryDir);
        }
    }
}
if ($action) {
    echo "Coaster Framework: Moved gallery files so they are stored by block name\n";
}
 public function postIndex()
 {
     if (Auth::action('system.update')) {
         $settings = Request::all();
         unset($settings['_token']);
         foreach ($settings as $setting => $value) {
             $setting = str_replace($this->dot_replace, '.', $setting);
             $current_setting = Setting::where('name', '=', $setting)->where('editable', '=', 1)->first();
             if (!empty($current_setting)) {
                 if ($setting == 'site.secure_folders') {
                     $newValues = explode(',', $value);
                     foreach ($newValues as $k => $folder) {
                         $folder = trim($folder);
                         if (empty($folder)) {
                             unset($newValues[$k]);
                         } else {
                             $newValues[$k] = '/' . trim($folder, '/') . '/';
                         }
                     }
                     foreach ($newValues as $k => $folder) {
                         foreach ($newValues as $kCheck => $folderCheck) {
                             if ($k != $kCheck && strpos($folder, $folderCheck) === 0) {
                                 unset($newValues[$k]);
                             }
                         }
                     }
                     $oldValues = explode(',', $current_setting->value);
                     foreach ($oldValues as $k => $folder) {
                         $folder = trim($folder);
                         if (empty($folder)) {
                             unset($oldValues[$k]);
                         } else {
                             $oldValues[$k] = '/' . trim($folder, '/') . '/';
                         }
                     }
                     $toSecure = array_diff($newValues, $oldValues);
                     $toUnSecure = array_diff($oldValues, $newValues);
                     foreach ($toSecure as $newSecureFolder) {
                         if (is_dir(public_path() . '/uploads' . $newSecureFolder)) {
                             Directory::copy(public_path() . '/uploads' . $newSecureFolder, storage_path() . '/uploads' . $newSecureFolder);
                             Directory::remove(public_path() . '/uploads' . $newSecureFolder, true);
                         } else {
                             @mkdir(storage_path() . '/uploads' . $newSecureFolder, 0777, true);
                         }
                     }
                     foreach ($toUnSecure as $newUnSecureFolder) {
                         if (is_dir(storage_path() . '/uploads' . $newUnSecureFolder)) {
                             Directory::copy(storage_path() . '/uploads' . $newUnSecureFolder, public_path() . '/uploads' . $newUnSecureFolder);
                             Directory::remove(storage_path() . '/uploads' . $newUnSecureFolder);
                         } else {
                             @mkdir(public_path() . '/uploads' . $newUnSecureFolder, 0777, true);
                         }
                     }
                     $value = implode(',', $newValues);
                 }
                 $current_setting->value = $value;
                 $current_setting->save();
                 if (in_array($setting, ['frontend.theme', 'admin.default_template'])) {
                     Theme::templateIdUpdate();
                 }
             }
         }
         AdminLog::new_log('System settings updated');
         $this->addAlert('success', 'System Settings Updated');
     }
     return \redirect()->route('coaster.admin.system');
 }
Exemple #3
0
 public static function export($themeId, $withPageData)
 {
     $theme = self::find($themeId);
     if (!empty($theme)) {
         $themesDir = base_path() . '/resources/views/themes/';
         $zipFileName = $theme->theme . '.zip';
         // export blocks
         BlockUpdater::exportBlocks($theme);
         if ($withPageData) {
             // export page data
             self::_pageExportData($theme);
         }
         $zip = new Zip();
         $zip->open($themesDir . $zipFileName, Zip::CREATE);
         $zip->addDir($themesDir . $theme->theme, 'views', function ($addFrom, $addTo) use($withPageData) {
             if ($addTo == 'views/import') {
                 $addTo = '';
             }
             if (stripos($addTo, '/.svn/') !== false) {
                 $addTo = '';
             }
             if (!$withPageData && stripos($addTo, 'views/export/pages') === 0) {
                 $addTo = '';
             }
             if (stripos($addTo, 'views/export') === 0) {
                 $addTo = 'views/import' . substr($addTo, 12);
             }
             return [$addFrom, $addTo];
         });
         $zip->addDir(public_path() . '/themes/' . $theme->theme, 'public', function ($addFrom, $addTo) {
             if (stripos($addTo, '/.svn/') !== false) {
                 $addTo = '';
             }
             return [$addFrom, $addTo];
         });
         if (!empty(self::$_uploadsToAdd)) {
             foreach (self::$_uploadsToAdd as $zipPath => $dirPath) {
                 if (file_exists($dirPath) && !is_dir($dirPath)) {
                     $zip->addFile($dirPath, $zipPath);
                 }
             }
         }
         $zip->close();
         header("Content-type: application/zip");
         header("Content-Disposition: attachment; filename=" . $zipFileName);
         header('Content-Length: ' . filesize($themesDir . $zipFileName));
         header("Pragma: no-cache");
         header("Expires: 0");
         readfile($themesDir . $zipFileName);
         unlink($themesDir . $zipFileName);
         Directory::remove($themesDir . $theme->theme . '/export');
         exit;
     }
     return 'error';
 }
 unlink($nestedSortableZip);
 echo ".";
 $fancyBoxZip = public_path('coaster/jquery/fancyBox-2.1.5.zip');
 $response = $guzzleClient->request('GET', 'https://github.com/fancyapps/fancyBox/archive/v2.1.5.zip', ['sink' => $fancyBoxZip]);
 $zip = new \CoasterCms\Helpers\Cms\File\Zip();
 $zip->open($fancyBoxZip);
 $zip->extractDir('fancyBox-2.1.5/source', public_path('coaster/jquery/fancybox'));
 $zip->close();
 unlink($fancyBoxZip);
 echo ".";
 $jQueryFileUploadDir = base_path('vendor/blueimp/jquery-file-upload');
 $jQueryFileUploadPublicDir = public_path('coaster/jquery/gallery-upload');
 \CoasterCms\Helpers\Cms\File\Directory::copy($jQueryFileUploadDir . '/cors', $jQueryFileUploadPublicDir . '/cors');
 \CoasterCms\Helpers\Cms\File\Directory::copy($jQueryFileUploadDir . '/css', $jQueryFileUploadPublicDir . '/css');
 \CoasterCms\Helpers\Cms\File\Directory::copy($jQueryFileUploadDir . '/img', $jQueryFileUploadPublicDir . '/img');
 \CoasterCms\Helpers\Cms\File\Directory::copy($jQueryFileUploadDir . '/js', $jQueryFileUploadPublicDir . '/js');
 \CoasterCms\Helpers\Cms\File\File::replaceString($jQueryFileUploadDir . '/js/main.js', '        url: \'server/php/\'', '        url: window.location.href.replace(\'/edit/\', \'/update/\')');
 echo ".";
 $jQueryFileUploadExternal = $jQueryFileUploadPublicDir . '/Gallery-2.16.0.zip';
 $response = $guzzleClient->request('GET', 'https://github.com/blueimp/Gallery/archive/2.16.0.zip', ['sink' => $jQueryFileUploadExternal]);
 $zip = new \CoasterCms\Helpers\Cms\File\Zip();
 $zip->open($jQueryFileUploadExternal);
 $zip->extractFile('Gallery-2.16.0/js/jquery.blueimp-gallery.min.js', $jQueryFileUploadPublicDir . '/js/external/jquery.blueimp-gallery.min.js');
 $zip->close();
 unlink($jQueryFileUploadExternal);
 echo ".";
 $jQueryFileUploadExternal = $jQueryFileUploadPublicDir . '/JavaScript-Canvas-to-Blob-2.2.0.zip';
 $response = $guzzleClient->request('GET', 'https://github.com/blueimp/JavaScript-Canvas-to-Blob/archive/2.2.0.zip', ['sink' => $jQueryFileUploadExternal]);
 $zip = new \CoasterCms\Helpers\Cms\File\Zip();
 $zip->open($jQueryFileUploadExternal);
 $zip->extractFile('JavaScript-Canvas-to-Blob-2.2.0/js/canvas-to-blob.min.js', $jQueryFileUploadPublicDir . '/js/external/canvas-to-blob.min.js');