protected function backup() { /* CREATE TABLE IF NOT EXISTS `xplogs` ( `id` int(11) NOT NULL, `backup_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `logs` LONGTEXT NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; ALTER TABLE `xplogs` ADD PRIMARY KEY (`id`); ALTER TABLE `xplogs` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; */ $logs = App\Files::get($this->log_file); return !!DB::table('xplogs')->insertGetId(['logs' => $logs]); }
protected function bundle($_filenames, $_ext = 'js') { $_filenames = !is_array($_filenames) ? array($_filenames) : $_filenames; $filename = 'wasabi' . md5(implode('|', $_filenames)) . $this->_getFileLastModifiedTimesIndentifier($_filenames); $ext = strtolower(trim($_ext)); $filename = $filename . '.' . $ext; $bundle_dir_base_path = $this->BASE_BUNDLES_DIR; $content = '/*' . "\n * " . implode("\n * ", $_filenames) . "\n" . ' */' . "\n"; $BUNDLES_DIR = App\Files::makeDirIfNotExists($this->BUNDLES_DIR); if (App\Files::exists($BUNDLES_DIR . '/' . $filename)) { return $bundle_dir_base_path . '/' . $filename; } foreach ($_filenames as $f) { $f = preg_replace('/\\?.+$/', '', $f); // Remove query string $content .= "\n /*----------- " . $f . " ------------*/ \n"; if ($ext === 'js') { // See: https://github.com/tedious/JShrink $content .= JShrink\Minifier::minify(App\Files::get(rtrim($f, '/'))); } } App\Files::makeFile($BUNDLES_DIR . '/' . $filename, $content); return $bundle_dir_base_path . '/' . $filename; }
protected function download($_path) { if (!App\Files::isReadable($_path)) { xplog('Unable to read file "' . $_path . '" when trying to download', __METHOD__); return ''; } $file_size = filesize($_path); $file_contents = App\Files::get($_path); $file_name = basename($_path); header("Content-length: " . $file_size); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $file_name . '"'); return $file_contents; }