|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Command\Init; |
| 4 | + |
| 5 | +use Minicli\Command\CommandController; |
| 6 | +use Minicli\Input; |
| 7 | +use Symfony\Component\Filesystem\Filesystem; |
| 8 | + |
| 9 | +class DefaultController extends CommandController |
| 10 | +{ |
| 11 | + public function handle() |
| 12 | + { |
| 13 | + $this->getPrinter()->info('Initializing New WordPress Theme Scafffold'); |
| 14 | + $this->getPrinter()->info('Provide the projects details to begin'); |
| 15 | + |
| 16 | + $title = (new Input('What is the Theme Title?: '))->read(); |
| 17 | + $this->getPrinter()->newline(); |
| 18 | + $titleurl = (new Input('What is the Theme URI?: '))->read(); |
| 19 | + $this->getPrinter()->newline(); |
| 20 | + $description = (new Input('Theme Description?: '))->read(); |
| 21 | + $this->getPrinter()->newline(); |
| 22 | + $author = (new Input('What is the name of the Author?: '))->read(); |
| 23 | + $this->getPrinter()->newline(); |
| 24 | + $authorurl = (new Input('What is the Author URI?: '))->read(); |
| 25 | + $this->getPrinter()->newline(); |
| 26 | + $textdomain = (new Input('Text Domain (Slug)?: '))->read(); |
| 27 | + $this->getPrinter()->newline(); |
| 28 | + $tags = (new Input('Tags (seperated by comma)?: '))->read(); |
| 29 | + |
| 30 | + $this->getPrinter()->display('Details Stored Successfully'); |
| 31 | + $this->getPrinter()->display('Preparing to copy files'); |
| 32 | + |
| 33 | + $themeDir = '.'; |
| 34 | + if ($this->hasParam('themeDir')) { |
| 35 | + $themeDir = './' . $this->getParam('themeDir'); |
| 36 | + } |
| 37 | + |
| 38 | + $filesystem = new Filesystem(); |
| 39 | + $filesystem->mirror(__DIR__ . '/../../Stubs/theme-scaffold', $themeDir); |
| 40 | + $this->getPrinter()->display('Files Copied Successfully'); |
| 41 | + |
| 42 | + $cssorigin = $themeDir . '/style.css'; |
| 43 | + $details = ['title'=>$title,'themeuri'=>$titleurl,'author'=>$author,'authoruri'=>$authorurl,'description'=>$description,'text-domain'=>$textdomain,'tags'=>$tags]; |
| 44 | + $this->prepend($this->prepDetails($details),$cssorigin); |
| 45 | + $this->getPrinter()->success('Theme Scaffold initialized Successfully. Go to your WP Admin Dashboard and Install theme. Enjoy Development'); |
| 46 | + |
| 47 | + $this->getPrinter()->newline(); |
| 48 | + } |
| 49 | + |
| 50 | + public function prepend($string, $orig_filename) |
| 51 | + { |
| 52 | + $context = stream_context_create(); |
| 53 | + $orig_file = fopen($orig_filename, 'r', 1, $context); |
| 54 | + |
| 55 | + $temp_filename = tempnam(sys_get_temp_dir(), 'php_prepend_'); |
| 56 | + file_put_contents($temp_filename, $string); |
| 57 | + file_put_contents($temp_filename, $orig_file, FILE_APPEND); |
| 58 | + |
| 59 | + fclose($orig_file); |
| 60 | + unlink($orig_filename); |
| 61 | + rename($temp_filename, $orig_filename); |
| 62 | + } |
| 63 | + |
| 64 | + public function prepDetails(array $details) |
| 65 | + { |
| 66 | + $themeDetails = <<<EOD |
| 67 | + /* |
| 68 | + Theme Name: {$details['title']} |
| 69 | + Theme URI: {$details['themeuri']} |
| 70 | + Author: {$details['author']} |
| 71 | + Author URI: {$details['authoruri']} |
| 72 | + Description: Custom theme: {$details['description']} |
| 73 | + Version: 1.0.0 |
| 74 | + License: GNU General Public License v2 or later |
| 75 | + License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 76 | + Text Domain: {$details['text-domain']} |
| 77 | + Tags: {$details['tags']} |
| 78 | + |
| 79 | + This theme, like WordPress, is licensed under the GPL. |
| 80 | + Use it to make something cool, have fun, and share what you've learned with others. |
| 81 | + |
| 82 | + WP Theme Scaffold is based on Underscores http://krafthaus.co.id/, (C) 2012-2016 Automattic, Inc. |
| 83 | + Underscores is distributed under the terms of the GNU GPL v2 or later. |
| 84 | + |
| 85 | + Normalizing styles have been helped along thanks to the fine work of |
| 86 | + Nicolas Gallagher and Jonathan Neal http://necolas.github.com/normalize.css/ |
| 87 | + */ |
| 88 | + |
| 89 | + /*-------------------------------------------------------------- |
| 90 | + >>> TABLE OF CONTENTS: |
| 91 | + ---------------------------------------------------------------- |
| 92 | + # Normalize |
| 93 | + # Typography |
| 94 | + # Elements |
| 95 | + # Forms |
| 96 | + # Navigation |
| 97 | + ## Links |
| 98 | + ## Menus |
| 99 | + # Accessibility |
| 100 | + # Alignments |
| 101 | + # Clearings |
| 102 | + # Widgets |
| 103 | + # Content |
| 104 | + ## Posts and pages |
| 105 | + ## Comments |
| 106 | + # Infinite scroll |
| 107 | + # Media |
| 108 | + ## Captions |
| 109 | + ## Galleries |
| 110 | + --------------------------------------------------------------*/ |
| 111 | + |
| 112 | + /*-------------------------------------------------------------- |
| 113 | + # Normalize |
| 114 | + --------------------------------------------------------------*/ |
| 115 | +EOD; |
| 116 | + return $themeDetails; |
| 117 | + } |
| 118 | +} |
0 commit comments