diff --git a/Changelog b/Changelog index 920273a3c..76ef85f96 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-04-18 DariusIII + * Chg: Add MgrPosterController * Chg: Add TmuxController * Chg: Add AjaxController, update utils-admin.js * Chg: Add ReleaseNamingRegexesController diff --git a/app/Http/Controllers/Admin/MgrPosterController.php b/app/Http/Controllers/Admin/MgrPosterController.php new file mode 100644 index 000000000..bc181b210 --- /dev/null +++ b/app/Http/Controllers/Admin/MgrPosterController.php @@ -0,0 +1,113 @@ +setAdminPrefs(); + + $posters = MultigroupPoster::all('id', 'poster')->sortBy('poster'); + + $postersCheck = $posters->first(); + + $poster = $request->has('poster') && ! empty($request->input('poster')) ? $request->input('poster') : ''; + + $this->smarty->assign( + [ + 'poster' => $poster, + 'posters' => $posters, + 'check' => $postersCheck, + ] + ); + + $title = 'MultiGroup Posters List'; + $content = $this->smarty->fetch('posters-list.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } + + /** + * @param \Illuminate\Http\Request $request + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Exception + */ + public function edit(Request $request) + { + $this->setAdminPrefs(); + +// Set the current action. + $action = $request->input('action') ?? 'view'; + + switch ($action) { + case 'submit': + if ($request->input('id') === '') { + // Add a new mg poster. + $poster = MultigroupPoster::query()->create(['poster' => $request->input('poster')]); + } else { + // Update an existing mg poster. + $poster = MultigroupPoster::query()->where('id', '=', $request->input('id'))->update(['poster' => $request->input('poster')]); + } + $this->smarty->assign('poster', $poster); + return redirect('posters-list'); + break; + + case 'view': + default: + if (! empty($request->input('id'))) { + $title = 'MultiGroup Poster Edit'; + $poster = MultigroupPoster::query()->where('id', '=', $request->input('id'))->firstOrFail(); + } else { + $title = 'MultiGroup Poster Add'; + $poster = ''; + } + $this->smarty->assign('poster', $poster); + break; + } + + + $content = $this->smarty->fetch('posters-edit.tpl'); + + $this->smarty->assign( + [ + 'title' => $title, + 'content' => $content, + ] + ); + + $this->adminrender(); + } + + /** + * @param $id + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function destroy($id) + { + if ($id) { + MultigroupPoster::query()->where('id', '=', $id)->delete(); + } + + return redirect('posters-list'); + } +} diff --git a/public/oldadmin/opcachestats.php b/public/oldadmin/opcachestats.php deleted file mode 100644 index 927542cc7..000000000 --- a/public/oldadmin/opcachestats.php +++ /dev/null @@ -1,1238 +0,0 @@ -setAdminPrefs(); - -$NNURL = $page->serverurl; - -/** - * OPcache GUI. - * - * A simple but effective single-file GUI for the OPcache PHP extension. - * - * @author Andrew Collington, andy@amnuts.com - * @version 2.3.0 - * @link https://github.com/amnuts/opcache-gui - * @license MIT, http://acollington.mit-license.org/ - */ -/* - * User configuration - */ -$options = [ - 'allow_filelist' => true, // show/hide the files tab - 'allow_invalidate' => true, // give a link to invalidate files - 'allow_reset' => true, // give option to reset the whole cache - 'allow_realtime' => true, // give option to enable/disable real-time updates - 'refresh_time' => 5, // how often the data will refresh, in seconds - 'size_precision' => 2, // Digits after decimal point - 'size_space' => false, // have '1MB' or '1 MB' when showing sizes - 'charts' => true, // show gauge chart or just big numbers - 'debounce_rate' => 250, // milliseconds after key press to send keyup event when filtering -]; -/* - * Shouldn't need to alter anything else below here - */ -if (! extension_loaded('Zend OPcache')) { - die('The Zend OPcache extension does not appear to be installed'); -} -$ocEnabled = ini_get('opcache.enable'); -if (empty($ocEnabled)) { - die('The Zend OPcache extension is installed but not turned on'); -} -class OpCacheService -{ - protected $data; - protected $options; - protected $defaults = [ - 'allow_filelist' => true, - 'allow_invalidate' => true, - 'allow_reset' => true, - 'allow_realtime' => true, - 'refresh_time' => 5, - 'size_precision' => 2, - 'size_space' => false, - 'charts' => true, - 'debounce_rate' => 250, - ]; - - private function __construct($options = []) - { - $this->options = array_merge($this->defaults, $options); - $this->data = $this->compileState(); - } - - public static function init($options = []) - { - $self = new self($options); - if (! empty($_SERVER['HTTP_X_REQUESTED_WITH']) - && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' - ) { - if (isset($_GET['reset']) && $self->getOption('allow_reset')) { - echo '{ "success": "'.($self->resetCache() ? 'yes' : 'no').'" }'; - } elseif (isset($_GET['invalidate']) && $self->getOption('allow_invalidate')) { - echo '{ "success": "'.($self->resetCache($_GET['invalidate']) ? 'yes' : 'no').'" }'; - } else { - echo json_encode($self->getData((empty($_GET['section']) ? null : $_GET['section']))); - } - exit; - } elseif (isset($_GET['reset']) && $self->getOption('allow_reset')) { - $self->resetCache(); - header('Location: ?'); - exit; - } elseif (isset($_GET['invalidate']) && $self->getOption('allow_invalidate')) { - $self->resetCache($_GET['invalidate']); - header('Location: ?'); - exit; - } - - return $self; - } - - public function getOption($name = null) - { - if ($name === null) { - return $this->options; - } - - return isset($this->options[$name]) - ? $this->options[$name] - : null; - } - - public function getData($section = null, $property = null) - { - if ($section === null) { - return $this->data; - } - $section = strtolower($section); - if (isset($this->data[$section])) { - if ($property === null || ! isset($this->data[$section][$property])) { - return $this->data[$section]; - } - - return $this->data[$section][$property]; - } - - return null; - } - - public function canInvalidate() - { - return $this->getOption('allow_invalidate') && function_exists('opcache_invalidate'); - } - - public function resetCache($file = null) - { - $success = false; - if ($file === null) { - $success = opcache_reset(); - } elseif (function_exists('opcache_invalidate')) { - $success = opcache_invalidate(urldecode($file), true); - } - if ($success) { - $this->compileState(); - } - - return $success; - } - - protected function size($size) - { - $i = 0; - $val = ['b', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - while (($size / 1024) > 1) { - $size /= 1024; - $i++; - } - - return sprintf( - '%.'.$this->getOption('size_precision').'f%s%s', - $size, - ($this->getOption('size_space') ? ' ' : ''), - $val[$i] - ); - } - - protected function compileState() - { - $status = opcache_get_status(); - $config = opcache_get_configuration(); - $files = []; - if (! empty($status['scripts']) && $this->getOption('allow_filelist')) { - uasort($status['scripts'], function ($a, $b) { - return $a['hits'] < $b['hits']; - }); - foreach ($status['scripts'] as &$file) { - $file['full_path'] = str_replace('\\', '/', $file['full_path']); - $file['readable'] = [ - 'hits' => number_format($file['hits']), - 'memory_consumption' => $this->size($file['memory_consumption']), - ]; - } - $files = array_values($status['scripts']); - } - $overview = array_merge( - $status['memory_usage'], - $status['opcache_statistics'], - [ - 'used_memory_percentage' => round(100 * ( - ($status['memory_usage']['used_memory'] + $status['memory_usage']['wasted_memory']) - / $config['directives']['opcache.memory_consumption'] - )), - 'hit_rate_percentage' => round($status['opcache_statistics']['opcache_hit_rate']), - 'wasted_percentage' => round($status['memory_usage']['current_wasted_percentage'], 2), - 'readable' => [ - 'total_memory' => $this->size($config['directives']['opcache.memory_consumption']), - 'used_memory' => $this->size($status['memory_usage']['used_memory']), - 'free_memory' => $this->size($status['memory_usage']['free_memory']), - 'wasted_memory' => $this->size($status['memory_usage']['wasted_memory']), - 'num_cached_scripts' => number_format($status['opcache_statistics']['num_cached_scripts']), - 'hits' => number_format($status['opcache_statistics']['hits']), - 'misses' => number_format($status['opcache_statistics']['misses']), - 'blacklist_miss' => number_format($status['opcache_statistics']['blacklist_misses']), - 'num_cached_keys' => number_format($status['opcache_statistics']['num_cached_keys']), - 'max_cached_keys' => number_format($status['opcache_statistics']['max_cached_keys']), - 'interned' => null, - 'start_time' => date('Y-m-d H:i:s', $status['opcache_statistics']['start_time']), - 'last_restart_time' => ( - $status['opcache_statistics']['last_restart_time'] == 0 - ? 'never' - : date('Y-m-d H:i:s', $status['opcache_statistics']['last_restart_time']) - ), - ], - ] - ); - - if (! empty($status['interned_strings_usage'])) { - $overview['readable']['interned'] = [ - 'buffer_size' => $this->size($status['interned_strings_usage']['buffer_size']), - 'strings_used_memory' => $this->size($status['interned_strings_usage']['used_memory']), - 'strings_free_memory' => $this->size($status['interned_strings_usage']['free_memory']), - 'number_of_strings' => number_format($status['interned_strings_usage']['number_of_strings']), - ]; - } - $directives = []; - ksort($config['directives']); - foreach ($config['directives'] as $k => $v) { - $directives[] = ['k' => $k, 'v' => $v]; - } - $version = array_merge( - $config['version'], - [ - 'php' => phpversion(), - 'server' => $_SERVER['SERVER_SOFTWARE'], - 'host' => ( - function_exists('gethostname') - ? gethostname() - : ( - php_uname('n') - ?: ( - empty($_SERVER['SERVER_NAME']) - ? $_SERVER['HOST_NAME'] - : $_SERVER['SERVER_NAME'] - ) - ) - ), - ] - ); - - return [ - 'version' => $version, - 'overview' => $overview, - 'files' => $files, - 'directives' => $directives, - 'blacklist' => $config['blacklist'], - 'functions' => get_extension_funcs('Zend OPcache'), - ]; - } -} -$opcache = OpCacheService::init($options); -?> - - - - - - OPcache statistics on <?php echo $opcache->getData('version', 'host'); ?> - - - - - - - - -
- -
- -
-
-
-
-
-
-
-
- - - - - - getData('functions') as $func): ?> - - - -
Available functions
-
-
-
-
-
-
- getOption('allow_filelist')): ?> -
-
- -
- -
-
-
- - - - - - - \ No newline at end of file diff --git a/public/oldadmin/poster-delete.php b/public/oldadmin/poster-delete.php deleted file mode 100644 index a1bed2be4..000000000 --- a/public/oldadmin/poster-delete.php +++ /dev/null @@ -1,16 +0,0 @@ -has('id')) { - MultigroupPoster::query()->where('id', '=', request()->input('id'))->delete(); -} - -if (request()->has('from')) { - $referrer = request()->input('from'); -} else { - $referrer = request()->server('HTTP_REFERER'); -} -header('Location: '.$referrer); diff --git a/public/oldadmin/posters-edit.php b/public/oldadmin/posters-edit.php deleted file mode 100644 index 7d6ddcac8..000000000 --- a/public/oldadmin/posters-edit.php +++ /dev/null @@ -1,43 +0,0 @@ -setAdminPrefs(); -$relPosters = new ProcessReleasesMultiGroup(['Settings' => $page->pdo]); - -// Set the current action. -$action = request()->input('action') ?? 'view'; - -switch ($action) { - case 'submit': - if (request()->input('id') === '') { - // Add a new mg poster. - $poster = MultigroupPoster::query()->create(['poster' => request()->input('poster')]); - } else { - // Update an existing mg poster. - $poster = MultigroupPoster::query()->where('id', '=', request()->input('id'))->update(['poster' => request()->input('poster')]); - } - - header('Location:'.WWW_TOP.'/posters-list.php'); - break; - - case 'view': - default: - if (! empty(request()->input('id'))) { - $page->title = 'MultiGroup Poster Edit'; - $poster = MultigroupPoster::query()->where('id', '=', request()->input('id'))->firstOrFail(); - } else { - $page->title = 'MultiGroup Poster Add'; - $poster = ''; - } - $page->smarty->assign('poster', $poster); - break; -} - -$page->content = $page->smarty->fetch('posters-edit.tpl'); -$page->adminrender(); diff --git a/public/oldadmin/posters-list.php b/public/oldadmin/posters-list.php deleted file mode 100644 index e1097fd33..000000000 --- a/public/oldadmin/posters-list.php +++ /dev/null @@ -1,27 +0,0 @@ -setAdminPrefs(); - -$posters = MultigroupPoster::all('id', 'poster')->sortBy('poster'); - -$postersCheck = $posters->first(); - -$poster = request()->has('poster') && ! empty(request()->input('poster')) ? request()->input('poster') : ''; - -$page->smarty->assign( - [ - 'poster' => $poster, - 'posters' => $posters, - 'check' => $postersCheck, - ] -); - -$page->title = 'MultiGroup Posters List'; -$page->content = $page->smarty->fetch('posters-list.tpl'); -$page->adminrender(); diff --git a/resources/views/themes/admin/posters-list.tpl b/resources/views/themes/admin/posters-list.tpl index 479b005f4..5184a47e7 100644 --- a/resources/views/themes/admin/posters-list.tpl +++ b/resources/views/themes/admin/posters-list.tpl @@ -11,11 +11,11 @@ {foreach from=$posters item=$poster} - {$poster->poster} + {$poster->poster} Delete poster diff --git a/routes/web.php b/routes/web.php index e3ebd8455..2ef0bacbb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -262,5 +262,11 @@ Route::prefix('admin')->group(function () { Route::post('ajax', 'AjaxController@ajaxAction'); Route::get('tmux-edit', 'TmuxController@edit'); Route::post('tmux-edit', 'TmuxController@edit'); + Route::get('posters-list', 'MgrPosterController@index'); + Route::post('posters-list', 'MgrPosterController@index'); + Route::get('posters-edit', 'MgrPosterController@edit'); + Route::post('posters-edit', 'MgrPosterController@edit'); + Route::get('poster-delete/{id}', 'MgrPosterController@destroy'); + Route::post('poster-delete/{id}', 'MgrPosterController@destroy'); }); });