diff --git a/.env.example b/.env.example index d1af6d2..669c58c 100644 --- a/.env.example +++ b/.env.example @@ -61,8 +61,14 @@ VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" #------------------ # FIPAMO SETTINGS #------------------ -PAGES_PATH="path/to/pages" -THEMES_PATH="path/to/themes" -SETTINGS_PATH="path/to/settings.json" -FOLKS_PATH="path/to/folks.json" -TAGS_PATH="path/to/tag.json" +FIPAMO_DIR="../content" +PAGES_PATH="${FIPAMO_DIR}/pages" +THEMES_PATH="${FIPAMO_DIR}/themes" +FIPAMO_CONFIG="${FIPAMO_DIR}/config" +SETTINGS_PATH="${FIPAMO_CONFIG}/settings.json" +FOLKS_PATH="${FIPAMO_CONFIG}/folks.json" +TAGS_PATH="${FIPAMO_CONFIG}/tags.json" +FIPAMO_INIT="${FIPAMO_DIR}/init" +FIPAMO_BACKUPS="${FIPAMO_DIR}/backups" +# MAIL +ADMIN_EMAIL = "you@admin.email" diff --git a/app/Repositories/MemberRepository.php b/app/Repositories/MemberRepository.php index 5432673..774c721 100644 --- a/app/Repositories/MemberRepository.php +++ b/app/Repositories/MemberRepository.php @@ -21,7 +21,7 @@ class MemberRepository implements MemberRepositoryInterface if (file_exists(env('FOLKS_PATH'))) { $this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true); } else { - $this->folks = json_decode(file_get_contents('../content/init/folks-template.json'), true); + $this->folks = json_decode(file_get_contents(env('FIPAMO_INIT') . '/folks-template.json'), true); } } diff --git a/app/Services/Upkeep/InitService.php b/app/Services/Upkeep/InitService.php index 157172e..962b268 100644 --- a/app/Services/Upkeep/InitService.php +++ b/app/Services/Upkeep/InitService.php @@ -52,11 +52,11 @@ class InitService //grab template files //TODO: Remove hardcoded link and set up init path in settings $newFolks = json_decode( - file_get_contents('../content/init/folks-template.json'), + file_get_contents(env('FIPAMO_INIT') . '/folks-template.json'), true ); $newSettings = json_decode( - file_get_contents('../content/init/settings-template.json'), + file_get_contents(env('FIPAMO_INIT') . '/settings-template.json'), true ); //get form values @@ -82,6 +82,7 @@ class InitService $newSettings['global']['title'] = $title; //create index file + //TODO: upate path attribute to use env variable $index = [ 'id' => 1, 'uuid' => createUUID(), @@ -103,16 +104,16 @@ class InitService ]; //once all files created, write down - mkdir('../content/config', 0755, true); - $this->docs->writeSettings($newSettings, '../content/config/settings.json'); - $this->docs->writeSettings($newFolks, '../content/config/folks.json'); - $this->docs->writeSettings([], '../content/config/tags.json'); + mkdir(env('FIPAMO_CONFIG'), 0755, true); + $this->docs->writeSettings($newSettings, env('FIPAMO_CONFIG') . '/settings.json'); + $this->docs->writeSettings($newFolks, env('FIPAMO_CONFIG') . '/folks.json'); + $this->docs->writeSettings([], env('FIPAMO_CONFIG') . '/tags.json'); $object = (object) $index; $this->docs->writePages( 'create', 'start', - '../content/pages/start/index.md', + env('PAGES_PATH') . '/start/index.md', $this->docs::objectToMD($object) ); @@ -124,11 +125,11 @@ class InitService public function restore($request) { $file = $request->file('backup-upload'); - $file->move('../content' . '/', $file->getClientOriginalName()); + $file->move(env('FIPAMO_DIR') . '/', $file->getClientOriginalName()); $zip = new \ZipArchive(); $result = []; - $tempDir = '../content/_temp'; - if ($zip->open('../content' . '/' . $file->getClientOriginalName()) === true) { + $tempDir = env('FIPAMO_DIR') . '/_temp'; + if ($zip->open(env('FIPAMO_DIR') . '/' . $file->getClientOriginalName()) === true) { $folks = json_decode($zip->getFromName('config/folks.json'), true); $found = find($folks, ['handle' => $request->restore_member_handle]); if ($found) { @@ -153,18 +154,18 @@ class InitService $newConfig['global']['externalAPI'] = 'false'; } //make dir and write new config files - if (!is_dir('../content/config/')) { - mkdir('../content/config/', 0755, true); + if (!is_dir(env('FIPAMO_CONFIG'))) { + mkdir(env('FIPAMO_CONFIG'), 0755, true); } - $this->docs->writeSettings($newConfig, '../content/config/settings.json'); - $this->docs->writeSettings($newFolks, '../content/config/folks.json'); - rename($tempDir . '/config/tags.json', '../content/config/tags.json'); + $this->docs->writeSettings($newConfig, env('FIPAMO_CONFIG') . '/settings.json'); + $this->docs->writeSettings($newFolks, env('FIPAMO_CONFIG') . '/folks.json'); + rename($tempDir . '/config/tags.json', env('FIPAMO_CONFIG') . '/tags.json'); //move saved markdown pages - rename($tempDir . '/content/pages/', '../content/pages'); + rename($tempDir . '/content/pages/', env('PAGES_PATH')); //clean up temp dir and zip file $this->docs::deleteFolder($tempDir); $zip->close(); - unlink('../content/' . $file->getClientOriginalName()); + unlink(env('FIPAMO_DIR') . $file->getClientOriginalName()); $result = [ 'type' => 'requestGood', 'message' => 'Site Restored! Redirecting', diff --git a/app/Services/Upkeep/MaintenanceService.php b/app/Services/Upkeep/MaintenanceService.php index af9f8f3..1b06d40 100644 --- a/app/Services/Upkeep/MaintenanceService.php +++ b/app/Services/Upkeep/MaintenanceService.php @@ -18,18 +18,18 @@ class MaintenanceService { //make sure back directory is there $stamp = Carbon::now()->format("YmdGis"); - if (!is_dir('../content/backups')) { - mkdir('../content/backups', 0755, true); + if (!is_dir(env('FIPAMO_BACKUPS'))) { + mkdir(env('FIPAMO_BACKUPS'), 0755, true); } //creat backup zip $zip = new \ZipArchive(); $zip->open( - '../content/backups/backup-' . $stamp . '.zip', + env('FIPAMO_BACKUPS') . '/backup-' . $stamp . '.zip', \ZipArchive::CREATE | \ZipArchive::OVERWRITE ); //gather data and path info for md pages - $pagePath = '../content/pages'; + $pagePath = env('PAGES_PATH'); $yearPaths = glob($pagePath . '/*', GLOB_ONLYDIR); foreach ($yearPaths as $years) { $year = explode('/', $years); @@ -94,22 +94,22 @@ class MaintenanceService $zip->addFile(env('FOLKS_PATH'), 'config/folks.json'); $zip->addFile(env('TAGS_PATH'), 'config/tags.json'); // create temp files for image lists - file_put_contents('../content/backups/blog_images_temp.json', json_encode($blogImages)); - file_put_contents('../content/backups/user_images_temp.json', json_encode($userImages)); - file_put_contents('../content/backups/blog_docs_temp.json', json_encode($blogDocs)); - file_put_contents('../content/backups/blog_vids_temp.json', json_encode($blogVids)); + file_put_contents(env('FIPAMO_BACKUPS') . '/blog_images_temp.json', json_encode($blogImages)); + file_put_contents(env('FIPAMO_BACKUPS') . '/user_images_temp.json', json_encode($userImages)); + file_put_contents(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json', json_encode($blogDocs)); + file_put_contents(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json', json_encode($blogVids)); //add to zip - $zip->addFile('../content/backups/blog_images_temp.json', 'assets/blog_images.json'); - $zip->addFile('../content/backups/user_images_temp.json', 'assets/user_images.json'); - $zip->addFile('../content/backups/blog_docs_temp.json', 'assets/blog_docs.json'); - $zip->addFile('../content/backups/blog_vids_temp.json', 'assets/blog_videos.json'); + $zip->addFile(env('FIPAMO_BACKUPS') . '/blog_images_temp.json', 'assets/blog_images.json'); + $zip->addFile(env('FIPAMO_BACKUPS') . '/user_images_temp.json', 'assets/user_images.json'); + $zip->addFile(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json', 'assets/blog_docs.json'); + $zip->addFile(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json', 'assets/blog_videos.json'); //save zip file $zip->close(); //clean up temp files - unlink('../content/backups/blog_images_temp.json'); - unlink('../content/backups/user_images_temp.json'); - unlink('../content/backups/blog_docs_temp.json'); - unlink('../content/backups/blog_vids_temp.json'); + unlink(env('FIPAMO_BACKUPS') . '/blog_images_temp.json'); + unlink(env('FIPAMO_BACKUPS') . '/user_images_temp.json'); + unlink(env('FIPAMO_BACKUPS') . '/blog_docs_temp.json'); + unlink(env('FIPAMO_BACKUPS') . '/blog_vids_temp.json'); //update settings file with latest back up date $this->settings->updateGlobalData('last_backup', $stamp);