Пример #1
0
 public function error()
 {
     $this->console->write($this->console->colorize('Sorry, that command was not valid.', Console::BOLD_RED));
     $this->console->write();
     $this->console->write('./spider help for help');
     $this->console->send();
 }
Пример #2
0
 /**
  * Composer install method
  * 
  * @param  \Composer\Script\Event $event
  * @throws \Pop\Db\Exception
  * @return void
  */
 public static function install($event)
 {
     $console = new Console(100, '    ');
     if (!file_exists(__DIR__ . '/../../data')) {
         mkdir(__DIR__ . '/../../data');
     }
     chmod(__DIR__ . '/../../data', 0777);
     if (!file_exists(__DIR__ . '/../../app/config/application.php')) {
         $console->write();
         $console->write($console->colorize('A configuration file was not detected.', Console::BOLD_YELLOW));
         $console->write();
         $createConfig = $console->prompt('Would you like to create one and install the database? [Y/N] ', ['y', 'n']);
         if (strtolower($createConfig) == 'y') {
             $console->write();
             // Configure application database
             $dbName = '';
             $dbUser = '';
             $dbPass = '';
             $dbHost = '';
             $dbPrefix = '';
             $dbAdapters = self::getDbAdapters();
             $adapters = array_keys($dbAdapters);
             $dbChoices = [];
             $dsn = null;
             $i = 1;
             foreach ($dbAdapters as $a) {
                 $console->write($i . ': ' . $a);
                 $dbChoices[] = $i;
                 $i++;
             }
             $console->write();
             $adapter = $console->prompt('Please select one of the above database adapters: ', $dbChoices);
             $console->write();
             // If PDO
             if (strpos($adapters[$adapter - 1], 'pdo') !== false) {
                 $console->write('1: mysql');
                 $console->write('2: pgsql');
                 $console->write('3: sqlite');
                 $console->write();
                 $dsn = $console->prompt('Please select the PDO DSN: ', [1, 2, 3]);
                 $dbInterface = 'Pdo';
                 $dbType = str_replace('pdo_', '', strtolower($adapters[$adapter - 1]));
                 $console->write();
             } else {
                 $dbInterface = ucfirst(strtolower($adapters[$adapter - 1]));
                 $dbType = null;
             }
             // If SQLite
             if ($dsn == 3 || $adapters[$adapter - 1] == 'sqlite') {
                 if (!file_exists(__DIR__ . '/../../data/.htpop.sqlite')) {
                     touch(__DIR__ . '/../../data/.htpop.sqlite');
                     chmod(__DIR__ . '/../../data/.htpop.sqlite', 0777);
                 }
                 $dbName = __DIR__ . '/../../data/.htpop.sqlite';
                 $realDbName = "__DIR__ . '/../../data/.htpop.sqlite'";
                 $dbPrefix = $console->prompt('DB Table Prefix: [pop_] ');
                 $console->write();
             } else {
                 $dbCheck = 1;
                 while (null !== $dbCheck) {
                     $dbName = $console->prompt('DB Name: ');
                     $dbUser = $console->prompt('DB User: '******'DB Password: '******'DB Host: [localhost] ');
                     $dbPrefix = $console->prompt('DB Table Prefix: [pop_] ');
                     if ($dbHost == '') {
                         $dbHost = 'localhost';
                     }
                     $dbCheck = Db::check($dbInterface, ['database' => $dbName, 'username' => $dbUser, 'password' => $dbPass, 'host' => $dbHost, 'type' => $dbType]);
                     if (null !== $dbCheck) {
                         $console->write();
                         $console->write($console->colorize('Database configuration test failed. Please try again.', Console::BOLD_RED));
                     } else {
                         $realDbName = "'" . $dbName . "'";
                         $console->write();
                         $console->write($console->colorize('Database configuration test passed.', Console::BOLD_GREEN));
                     }
                     $console->write();
                 }
             }
             // Install database
             $sql = stripos($dbInterface, 'pdo') !== false ? __DIR__ . '/../data/pop.' . strtolower($dbType) . '.sql' : __DIR__ . '/../data/pop.' . strtolower($dbInterface) . '.sql';
             if ($dbPrefix == '') {
                 $dbPrefix = 'pop_';
             }
             Db::install($sql, ['database' => $dbName, 'username' => $dbUser, 'password' => $dbPass, 'host' => $dbHost, 'prefix' => $dbPrefix, 'type' => $dbType], $dbInterface);
             // Write config file
             $config = str_replace(["define('DB_PREFIX', '');", "'adapter'  => '',", "'database' => '',", "'username' => '',", "'password' => '',", "'host'     => '',", "'type'     => null"], ["define('DB_PREFIX', '" . $dbPrefix . "');", "'adapter'  => '" . strtolower($dbInterface) . "',", "'database' => " . $realDbName . ",", "'username' => '" . $dbUser . "',", "'password' => '" . $dbPass . "',", "'host'     => '" . $dbHost . "',", "'type'     => '" . $dbType . "'"], file_get_contents(__DIR__ . '/../../app/config/application.orig.php'));
             file_put_contents(__DIR__ . '/../../app/config/application.php', $config);
             $console->write($console->colorize('Application configuration completed.', Console::BOLD_GREEN));
         }
     }
     $console->write();
     $console->write('Thank you for using Pop!');
     $console->write();
 }
Пример #3
0
 public function index()
 {
     $this->console->write();
     $this->console->write('    Fetching: ' . $this->console->colorize('phirecms/phirecms', Console::BOLD_CYAN) . '...', false);
     // Get latest version of phirecms
     $url = $this->urls['phirecms'] . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret;
     $curl = new Curl($url, $this->options);
     $curl->send();
     if ($curl->getCode() == 200) {
         $body = json_decode($curl->getBody(), true);
         $this->json['phirecms'] = isset($body['tag_name']) ? $body['tag_name'] : $this->current['phirecms'];
         $this->console->write();
     } else {
         $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.');
     }
     // Get latest versions of modules
     foreach ($this->modules as $module) {
         // Get version
         $this->console->write('    Fetching: ' . $this->console->colorize($module, Console::BOLD_CYAN) . '...', false);
         $url = str_replace('[{module}]', $module, $this->urls['module']) . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret;
         $curl = new Curl($url, $this->options);
         $curl->send();
         if ($curl->getCode() == 200) {
             $body = json_decode($curl->getBody(), true);
             if (isset($body['tag_name'])) {
                 $this->json['modules'][$module] = $body['tag_name'];
                 // Get file
                 if (!isset($this->current['modules'][$module]) || isset($this->current['modules'][$module]) && version_compare($this->current['modules'][$module], $this->json['modules'][$module]) < 0) {
                     $this->console->write(' Downloading...', false);
                     if (file_exists(__DIR__ . '/../../public/releases/modules/' . $module . '.zip')) {
                         unlink(__DIR__ . '/../../public/releases/modules/' . $module . '.zip');
                     }
                     $file = str_replace(['[{file}]', '[{tag_name}]'], [$module, $body['tag_name']], $this->urls['file']);
                     file_put_contents(__DIR__ . '/../../public/releases/modules/' . $module . '-' . $body['tag_name'] . '.zip', file_get_contents($file));
                     chmod(__DIR__ . '/../../public/releases/modules/' . $module . '-' . $body['tag_name'] . '.zip', 0777);
                 }
                 $this->console->write(' Complete.');
             }
         } else {
             $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.');
         }
     }
     $this->console->write();
     // Get latest versions of themes
     foreach ($this->themes as $theme) {
         // Get version
         $this->console->write('    Fetching: ' . $this->console->colorize($theme, Console::BOLD_CYAN) . '...', false);
         $url = str_replace('[{theme}]', $theme, $this->urls['theme']) . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret;
         $curl = new Curl($url, $this->options);
         $curl->send();
         if ($curl->getCode() == 200) {
             $body = json_decode($curl->getBody(), true);
             if (isset($body['tag_name'])) {
                 $this->json['themes'][$theme] = $body['tag_name'];
                 // Get file
                 if (!isset($this->current['themes'][$theme]) || isset($this->current['themes'][$theme]) && version_compare($this->current['themes'][$theme], $this->json['themes'][$theme]) < 0) {
                     $this->console->write(' Downloading...', false);
                     if (file_exists(__DIR__ . '/../../public/releases/themes/' . $theme . '.zip')) {
                         unlink(__DIR__ . '/../../public/releases/themes/' . $theme . '.zip');
                     }
                     $file = str_replace(['[{file}]', '[{tag_name}]'], [$theme, $body['tag_name']], $this->urls['file']);
                     file_put_contents(__DIR__ . '/../../public/releases/themes/' . $theme . '-' . $body['tag_name'] . '.zip', file_get_contents($file));
                     chmod(__DIR__ . '/../../public/releases/themes/' . $theme . '-' . $body['tag_name'] . '.zip', 0777);
                 }
                 $this->console->write(' Complete.');
             }
         } else {
             $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.');
         }
     }
     // Write new 'updates.json' file
     if (file_exists(__DIR__ . '/../../data/updates.json')) {
         unlink(__DIR__ . '/../../data/updates.json');
     }
     file_put_contents(__DIR__ . '/../../data/updates.json', json_encode($this->json, JSON_PRETTY_PRINT));
     $this->console->write();
     $this->console->write('    Done!');
     $this->console->write();
 }