mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-03 11:55:52 +01:00
Improve type hints
This commit is contained in:
10
admin.php
10
admin.php
@@ -119,12 +119,11 @@ class AdminPlugin extends Plugin
|
|||||||
* - 'password1' for password format
|
* - 'password1' for password format
|
||||||
* - 'password2' for equality to password1
|
* - 'password2' for equality to password1
|
||||||
*
|
*
|
||||||
* @param object $form The form
|
|
||||||
* @param string $type The field type
|
* @param string $type The field type
|
||||||
* @param string $value The field value
|
* @param string $value The field value
|
||||||
* @param string $extra Any extra value required
|
* @param string $extra Any extra value required
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validate($type, $value, $extra = '')
|
protected function validate($type, $value, $extra = '')
|
||||||
{
|
{
|
||||||
@@ -134,22 +133,21 @@ class AdminPlugin extends Plugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'password1':
|
case 'password1':
|
||||||
if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) {
|
if (!preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/', $value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'password2':
|
case 'password2':
|
||||||
if (strcmp($value, $extra)) {
|
if (strcmp($value, $extra)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -352,6 +350,8 @@ class AdminPlugin extends Plugin
|
|||||||
return $page;
|
return $page;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (empty($this->grav['page'])) {
|
if (empty($this->grav['page'])) {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ use Grav\Common\User\User;
|
|||||||
use Grav\Common\Utils;
|
use Grav\Common\Utils;
|
||||||
use RocketTheme\Toolbox\File\File;
|
use RocketTheme\Toolbox\File\File;
|
||||||
use RocketTheme\Toolbox\File\JsonFile;
|
use RocketTheme\Toolbox\File\JsonFile;
|
||||||
use RocketTheme\Toolbox\File\LogFile;
|
|
||||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||||
use RocketTheme\Toolbox\Session\Message;
|
use RocketTheme\Toolbox\Session\Message;
|
||||||
use RocketTheme\Toolbox\Session\Session;
|
use RocketTheme\Toolbox\Session\Session;
|
||||||
@@ -71,12 +70,7 @@ class Admin
|
|||||||
public $user;
|
public $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Lang
|
* @var GPM
|
||||||
*/
|
|
||||||
protected $lang;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Grav\Common\GPM\GPM
|
|
||||||
*/
|
*/
|
||||||
protected $gpm;
|
protected $gpm;
|
||||||
|
|
||||||
@@ -458,7 +452,7 @@ class Admin
|
|||||||
$gpm = $this->gpm();
|
$gpm = $this->gpm();
|
||||||
|
|
||||||
if (!$gpm) {
|
if (!$gpm) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $local ? $gpm->getInstalledPlugins() : $gpm->getRepositoryPlugins()->filter(function (
|
return $local ? $gpm->getInstalledPlugins() : $gpm->getRepositoryPlugins()->filter(function (
|
||||||
@@ -479,7 +473,7 @@ class Admin
|
|||||||
$gpm = $this->gpm();
|
$gpm = $this->gpm();
|
||||||
|
|
||||||
if (!$gpm) {
|
if (!$gpm) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $local ? $gpm->getInstalledThemes() : $gpm->getRepositoryThemes()->filter(function ($package, $slug) use
|
return $local ? $gpm->getInstalledThemes() : $gpm->getRepositoryThemes()->filter(function ($package, $slug) use
|
||||||
@@ -496,7 +490,7 @@ class Admin
|
|||||||
*
|
*
|
||||||
* @param integer $count number of pages to pull back
|
* @param integer $count number of pages to pull back
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
public function latestPages($count = 10)
|
public function latestPages($count = 10)
|
||||||
{
|
{
|
||||||
@@ -506,7 +500,7 @@ class Admin
|
|||||||
$latest = array();
|
$latest = array();
|
||||||
|
|
||||||
if(is_null($pages->routes())){
|
if(is_null($pages->routes())){
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($pages->routes() as $url => $path) {
|
foreach ($pages->routes() as $url => $path) {
|
||||||
@@ -824,13 +818,21 @@ class Admin
|
|||||||
/**
|
/**
|
||||||
* Translate a string to the user-defined language
|
* Translate a string to the user-defined language
|
||||||
*
|
*
|
||||||
* @param $string the string to translate
|
* @param string $string the string to translate
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function translate($string)
|
public function translate($string)
|
||||||
{
|
{
|
||||||
return $this->_translate($string, [$this->grav['user']->authenticated ? $this->grav['user']->language : 'en']);
|
return $this->_translate($string, [$this->grav['user']->authenticated ? $this->grav['user']->language : 'en']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|mixed $args
|
||||||
|
* @param array|null $languages
|
||||||
|
* @param bool $array_support
|
||||||
|
* @param bool $html_out
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function _translate($args, Array $languages = null, $array_support = false, $html_out = false)
|
public function _translate($args, Array $languages = null, $array_support = false, $html_out = false)
|
||||||
{
|
{
|
||||||
if (is_array($args)) {
|
if (is_array($args)) {
|
||||||
@@ -878,6 +880,10 @@ class Admin
|
|||||||
return $lookup;
|
return $lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $php_format
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
function dateformat2Kendo($php_format)
|
function dateformat2Kendo($php_format)
|
||||||
{
|
{
|
||||||
$SYMBOLS_MATCHING = array(
|
$SYMBOLS_MATCHING = array(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use Grav\Common\GPM\Installer;
|
|||||||
use Grav\Common\Grav;
|
use Grav\Common\Grav;
|
||||||
use Grav\Common\Uri;
|
use Grav\Common\Uri;
|
||||||
use Grav\Common\Data;
|
use Grav\Common\Data;
|
||||||
use Grav\Common\Page;
|
use Grav\Common\Page\Page;
|
||||||
use Grav\Common\Page\Pages;
|
use Grav\Common\Page\Pages;
|
||||||
use Grav\Common\Page\Collection;
|
use Grav\Common\Page\Collection;
|
||||||
use Grav\Common\Plugin;
|
use Grav\Common\Plugin;
|
||||||
@@ -16,8 +16,6 @@ use Grav\Common\Theme;
|
|||||||
use Grav\Common\User\User;
|
use Grav\Common\User\User;
|
||||||
use Grav\Common\Utils;
|
use Grav\Common\Utils;
|
||||||
use Grav\Common\Backup\ZipBackup;
|
use Grav\Common\Backup\ZipBackup;
|
||||||
use Grav\Common\Markdown\Parsedown;
|
|
||||||
use Grav\Common\Markdown\ParsedownExtra;
|
|
||||||
use RocketTheme\Toolbox\File\File;
|
use RocketTheme\Toolbox\File\File;
|
||||||
use RocketTheme\Toolbox\File\JsonFile;
|
use RocketTheme\Toolbox\File\JsonFile;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
@@ -380,7 +378,7 @@ class AdminController
|
|||||||
protected function taskClearCache()
|
protected function taskClearCache()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('clear cache', ['admin.cache', 'admin.super'])) {
|
if (!$this->authorizeTask('clear cache', ['admin.cache', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get optional cleartype param
|
// get optional cleartype param
|
||||||
@@ -411,7 +409,7 @@ class AdminController
|
|||||||
{
|
{
|
||||||
$param_sep = $this->grav['config']->get('system.param_sep', ':');
|
$param_sep = $this->grav['config']->get('system.param_sep', ':');
|
||||||
if (!$this->authorizeTask('backup', ['admin.maintenance', 'admin.super'])) {
|
if (!$this->authorizeTask('backup', ['admin.maintenance', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$download = $this->grav['uri']->param('download');
|
$download = $this->grav['uri']->param('download');
|
||||||
@@ -562,7 +560,7 @@ class AdminController
|
|||||||
protected function taskListmedia()
|
protected function taskListmedia()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('list media', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('list media', ['admin.pages', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = $this->admin->page(true);
|
$page = $this->admin->page(true);
|
||||||
@@ -583,11 +581,13 @@ class AdminController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles adding a media file to a page
|
* Handles adding a media file to a page
|
||||||
|
*
|
||||||
|
* @return bool True if the action was performed.
|
||||||
*/
|
*/
|
||||||
protected function taskAddmedia()
|
protected function taskAddmedia()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('add media', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('add media', ['admin.pages', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = $this->admin->page(true);
|
$page = $this->admin->page(true);
|
||||||
@@ -597,7 +597,7 @@ class AdminController
|
|||||||
|
|
||||||
if (!isset($_FILES['file']['error']) || is_array($_FILES['file']['error'])) {
|
if (!isset($_FILES['file']['error']) || is_array($_FILES['file']['error'])) {
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_PARAMETERS')];
|
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.INVALID_PARAMETERS')];
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check $_FILES['file']['error'] value.
|
// Check $_FILES['file']['error'] value.
|
||||||
@@ -606,21 +606,21 @@ class AdminController
|
|||||||
break;
|
break;
|
||||||
case UPLOAD_ERR_NO_FILE:
|
case UPLOAD_ERR_NO_FILE:
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.NO_FILES_SENT')];
|
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.NO_FILES_SENT')];
|
||||||
return;
|
return false;
|
||||||
case UPLOAD_ERR_INI_SIZE:
|
case UPLOAD_ERR_INI_SIZE:
|
||||||
case UPLOAD_ERR_FORM_SIZE:
|
case UPLOAD_ERR_FORM_SIZE:
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT')];
|
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_FILESIZE_LIMIT')];
|
||||||
return;
|
return false;
|
||||||
default:
|
default:
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS')];
|
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNKNOWN_ERRORS')];
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$grav_limit = $config->get('system.media.upload_limit', 0);
|
$grav_limit = $config->get('system.media.upload_limit', 0);
|
||||||
// You should also check filesize here.
|
// You should also check filesize here.
|
||||||
if ($grav_limit > 0 && $_FILES['file']['size'] > $grav_limit) {
|
if ($grav_limit > 0 && $_FILES['file']['size'] > $grav_limit) {
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_GRAV_FILESIZE_LIMIT')];
|
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.EXCEEDED_GRAV_FILESIZE_LIMIT')];
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -631,19 +631,19 @@ class AdminController
|
|||||||
// If not a supported type, return
|
// If not a supported type, return
|
||||||
if (!$config->get("media.{$fileExt}")) {
|
if (!$config->get("media.{$fileExt}")) {
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNSUPPORTED_FILE_TYPE') . ': '.$fileExt];
|
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.UNSUPPORTED_FILE_TYPE') . ': '.$fileExt];
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Upload it
|
// Upload it
|
||||||
if (!move_uploaded_file($_FILES['file']['tmp_name'], sprintf('%s/%s', $page->path(), $_FILES['file']['name']))) {
|
if (!move_uploaded_file($_FILES['file']['tmp_name'], sprintf('%s/%s', $page->path(), $_FILES['file']['name']))) {
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE')];
|
$this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE')];
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_UPLOADED_SUCCESSFULLY')];
|
$this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.FILE_UPLOADED_SUCCESSFULLY')];
|
||||||
|
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -654,7 +654,7 @@ class AdminController
|
|||||||
protected function taskDelmedia()
|
protected function taskDelmedia()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('delete media', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('delete media', ['admin.pages', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = $this->admin->page(true);
|
$page = $this->admin->page(true);
|
||||||
@@ -709,6 +709,8 @@ class AdminController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the page Markdown
|
* Process the page Markdown
|
||||||
|
*
|
||||||
|
* @return bool True if the action was performed.
|
||||||
*/
|
*/
|
||||||
protected function taskProcessMarkdown()
|
protected function taskProcessMarkdown()
|
||||||
{
|
{
|
||||||
@@ -734,11 +736,13 @@ class AdminController
|
|||||||
$html = $page->content();
|
$html = $page->content();
|
||||||
|
|
||||||
$this->admin->json_response = ['status' => 'success', 'message' => $html];
|
$this->admin->json_response = ['status' => 'success', 'message' => $html];
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
|
$this->admin->json_response = ['status' => 'error', 'message' => $e->getMessage()];
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -749,7 +753,7 @@ class AdminController
|
|||||||
public function taskEnable()
|
public function taskEnable()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('enable plugin', ['admin.plugins', 'admin.super'])) {
|
if (!$this->authorizeTask('enable plugin', ['admin.plugins', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->view != 'plugins') {
|
if ($this->view != 'plugins') {
|
||||||
@@ -775,7 +779,7 @@ class AdminController
|
|||||||
public function taskDisable()
|
public function taskDisable()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('disable plugin', ['admin.plugins', 'admin.super'])) {
|
if (!$this->authorizeTask('disable plugin', ['admin.plugins', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->view != 'plugins') {
|
if ($this->view != 'plugins') {
|
||||||
@@ -801,7 +805,7 @@ class AdminController
|
|||||||
public function taskActivate()
|
public function taskActivate()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('activate theme', ['admin.themes', 'admin.super'])) {
|
if (!$this->authorizeTask('activate theme', ['admin.themes', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->view != 'themes') {
|
if ($this->view != 'themes') {
|
||||||
@@ -840,7 +844,7 @@ class AdminController
|
|||||||
{
|
{
|
||||||
$type = $this->view === 'plugins' ? 'plugins' : 'themes';
|
$type = $this->view === 'plugins' ? 'plugins' : 'themes';
|
||||||
if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
|
if (!$this->authorizeTask('install ' . $type, ['admin.' . $type, 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__ . '/gpm.php';
|
require_once __DIR__ . '/gpm.php';
|
||||||
@@ -915,7 +919,7 @@ class AdminController
|
|||||||
|
|
||||||
foreach ($permissions as $type => $p) {
|
foreach ($permissions as $type => $p) {
|
||||||
if (!$this->authorizeTask('update ' . $type , $p)) {
|
if (!$this->authorizeTask('update ' . $type , $p)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -951,7 +955,7 @@ class AdminController
|
|||||||
{
|
{
|
||||||
$type = $this->view === 'plugins' ? 'plugins' : 'themes';
|
$type = $this->view === 'plugins' ? 'plugins' : 'themes';
|
||||||
if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) {
|
if (!$this->authorizeTask('uninstall ' . $type, ['admin.' . $type, 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__ . '/gpm.php';
|
require_once __DIR__ . '/gpm.php';
|
||||||
@@ -971,6 +975,11 @@ class AdminController
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @param string $file
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
private function cleanFilesData($key, $file)
|
private function cleanFilesData($key, $file)
|
||||||
{
|
{
|
||||||
$config = $this->grav['config'];
|
$config = $this->grav['config'];
|
||||||
@@ -1031,6 +1040,11 @@ class AdminController
|
|||||||
return $cleanFiles[$key];
|
return $cleanFiles[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $needle
|
||||||
|
* @param array|string $haystack
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
private function match_in_array($needle, $haystack)
|
private function match_in_array($needle, $haystack)
|
||||||
{
|
{
|
||||||
foreach ((array)$haystack as $item) {
|
foreach ((array)$haystack as $item) {
|
||||||
@@ -1042,6 +1056,10 @@ class AdminController
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $obj
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
private function processFiles($obj)
|
private function processFiles($obj)
|
||||||
{
|
{
|
||||||
foreach ((array)$_FILES as $key => $file) {
|
foreach ((array)$_FILES as $key => $file) {
|
||||||
@@ -1062,17 +1080,17 @@ class AdminController
|
|||||||
public function taskSave()
|
public function taskSave()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reorder = false;
|
|
||||||
$data = $this->post;
|
$data = $this->post;
|
||||||
|
|
||||||
|
$config = $this->grav['config'];
|
||||||
|
|
||||||
// Special handler for pages data.
|
// Special handler for pages data.
|
||||||
if ($this->view == 'pages') {
|
if ($this->view == 'pages') {
|
||||||
/** @var Page\Pages $pages */
|
/** @var Pages $pages */
|
||||||
$pages = $this->grav['pages'];
|
$pages = $this->grav['pages'];
|
||||||
$config = $this->grav['config'];
|
|
||||||
|
|
||||||
// Find new parent page in order to build the path.
|
// Find new parent page in order to build the path.
|
||||||
$route = !isset($data['route']) ? dirname($this->admin->route) : $data['route'];
|
$route = !isset($data['route']) ? dirname($this->admin->route) : $data['route'];
|
||||||
@@ -1150,7 +1168,7 @@ class AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Always redirect if a page route was changed, to refresh it
|
// Always redirect if a page route was changed, to refresh it
|
||||||
if ($obj instanceof Page\Page) {
|
if ($obj instanceof Page) {
|
||||||
if (method_exists($obj, 'unsetRouteSlug')) {
|
if (method_exists($obj, 'unsetRouteSlug')) {
|
||||||
$obj->unsetRouteSlug();
|
$obj->unsetRouteSlug();
|
||||||
}
|
}
|
||||||
@@ -1234,7 +1252,7 @@ class AdminController
|
|||||||
protected function taskCopy()
|
protected function taskCopy()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('copy page', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('copy page', ['admin.pages', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only applies to pages.
|
// Only applies to pages.
|
||||||
@@ -1243,7 +1261,7 @@ class AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/** @var Page\Pages $pages */
|
/** @var Pages $pages */
|
||||||
$pages = $this->grav['pages'];
|
$pages = $this->grav['pages'];
|
||||||
$data = $this->post;
|
$data = $this->post;
|
||||||
|
|
||||||
@@ -1292,7 +1310,7 @@ class AdminController
|
|||||||
protected function taskReorder()
|
protected function taskReorder()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('reorder pages', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('reorder pages', ['admin.pages', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only applies to pages.
|
// Only applies to pages.
|
||||||
@@ -1313,7 +1331,7 @@ class AdminController
|
|||||||
protected function taskDelete()
|
protected function taskDelete()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('delete page', ['admin.pages', 'admin.super'])) {
|
if (!$this->authorizeTask('delete page', ['admin.pages', 'admin.super'])) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only applies to pages.
|
// Only applies to pages.
|
||||||
@@ -1390,7 +1408,7 @@ class AdminController
|
|||||||
protected function taskSaveas()
|
protected function taskSaveas()
|
||||||
{
|
{
|
||||||
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
if (!$this->authorizeTask('save', $this->dataPermissions())) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $reorder = false;
|
// $reorder = false;
|
||||||
@@ -1428,7 +1446,7 @@ class AdminController
|
|||||||
$aFile = File::instance($path);
|
$aFile = File::instance($path);
|
||||||
$aFile->save();
|
$aFile->save();
|
||||||
|
|
||||||
$aPage = new Page\Page();
|
$aPage = new Page();
|
||||||
$aPage->init(new \SplFileInfo($path), $language .'.md');
|
$aPage->init(new \SplFileInfo($path), $language .'.md');
|
||||||
$aPage->header($obj->header());
|
$aPage->header($obj->header());
|
||||||
$aPage->rawMarkdown($obj->rawMarkdown());
|
$aPage->rawMarkdown($obj->rawMarkdown());
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ class Gpm
|
|||||||
'theme' => false
|
'theme' => false
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function install($packages, $options)
|
/**
|
||||||
|
* @param Package[]|string[]|string $packages
|
||||||
|
* @param array $options
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function install($packages, array $options)
|
||||||
{
|
{
|
||||||
$options = array_merge(self::$options, $options);
|
$options = array_merge(self::$options, $options);
|
||||||
|
|
||||||
@@ -93,13 +98,24 @@ class Gpm
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function update($packages, $options)
|
/**
|
||||||
|
* @param Package[]|string[]|string $packages
|
||||||
|
* @param array $options
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function update($packages, array $options)
|
||||||
{
|
{
|
||||||
$options['overwrite'] = true;
|
$options['overwrite'] = true;
|
||||||
|
|
||||||
return static::install($packages, $options);
|
return static::install($packages, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function uninstall($packages, $options)
|
/**
|
||||||
|
* @param Package[]|string[]|string $packages
|
||||||
|
* @param array $options
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function uninstall($packages, array $options)
|
||||||
{
|
{
|
||||||
$options = array_merge(self::$options, $options);
|
$options = array_merge(self::$options, $options);
|
||||||
|
|
||||||
@@ -144,7 +160,11 @@ class Gpm
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function download($package)
|
/**
|
||||||
|
* @param Package $package
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function download(Package $package)
|
||||||
{
|
{
|
||||||
$contents = Response::get($package->zipball_url, []);
|
$contents = Response::get($package->zipball_url, []);
|
||||||
|
|
||||||
@@ -159,7 +179,12 @@ class Gpm
|
|||||||
return $cache_dir . DS . $filename . '.zip';
|
return $cache_dir . DS . $filename . '.zip';
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function _downloadSelfupgrade($package, $tmp)
|
/**
|
||||||
|
* @param array $package
|
||||||
|
* @param string $tmp
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function _downloadSelfupgrade(array $package, $tmp)
|
||||||
{
|
{
|
||||||
$output = Response::get($package['download'], []);
|
$output = Response::get($package['download'], []);
|
||||||
Folder::mkdir($tmp);
|
Folder::mkdir($tmp);
|
||||||
@@ -167,6 +192,9 @@ class Gpm
|
|||||||
return $tmp . DS . $package['name'];
|
return $tmp . DS . $package['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function selfupgrade()
|
public static function selfupgrade()
|
||||||
{
|
{
|
||||||
$upgrader = new Upgrader();
|
$upgrader = new Upgrader();
|
||||||
|
|||||||
@@ -110,6 +110,9 @@ class Popularity
|
|||||||
file_put_contents($this->daily_file, json_encode($this->daily_data));
|
file_put_contents($this->daily_file, json_encode($this->daily_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getDailyChartData()
|
public function getDailyChartData()
|
||||||
{
|
{
|
||||||
if (!$this->daily_data) {
|
if (!$this->daily_data) {
|
||||||
@@ -130,6 +133,9 @@ class Popularity
|
|||||||
return array('labels' => json_encode($labels), 'data' => json_encode($data));
|
return array('labels' => json_encode($labels), 'data' => json_encode($data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function getDailyTotal()
|
public function getDailyTotal()
|
||||||
{
|
{
|
||||||
if (!$this->daily_data) {
|
if (!$this->daily_data) {
|
||||||
@@ -143,6 +149,9 @@ class Popularity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function getWeeklyTotal()
|
public function getWeeklyTotal()
|
||||||
{
|
{
|
||||||
if (!$this->daily_data) {
|
if (!$this->daily_data) {
|
||||||
@@ -160,6 +169,9 @@ class Popularity
|
|||||||
return $total;
|
return $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function getMonthlyTotal()
|
public function getMonthlyTotal()
|
||||||
{
|
{
|
||||||
if (!$this->monthly_data) {
|
if (!$this->monthly_data) {
|
||||||
@@ -197,6 +209,9 @@ class Popularity
|
|||||||
file_put_contents($this->monthly_file, json_encode($this->monthly_data));
|
file_put_contents($this->monthly_file, json_encode($this->monthly_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getMonthyChartData()
|
protected function getMonthyChartData()
|
||||||
{
|
{
|
||||||
if (!$this->monthly_data) {
|
if (!$this->monthly_data) {
|
||||||
@@ -213,6 +228,9 @@ class Popularity
|
|||||||
return array('labels' => $labels, 'data' => $data);
|
return array('labels' => $labels, 'data' => $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
*/
|
||||||
protected function updateTotals($url)
|
protected function updateTotals($url)
|
||||||
{
|
{
|
||||||
if (!$this->totals_data) {
|
if (!$this->totals_data) {
|
||||||
@@ -229,6 +247,9 @@ class Popularity
|
|||||||
file_put_contents($this->totals_file, json_encode($this->totals_data));
|
file_put_contents($this->totals_file, json_encode($this->totals_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $ip
|
||||||
|
*/
|
||||||
protected function updateVisitors($ip)
|
protected function updateVisitors($ip)
|
||||||
{
|
{
|
||||||
if (!$this->visitors_data) {
|
if (!$this->visitors_data) {
|
||||||
@@ -246,6 +267,10 @@ class Popularity
|
|||||||
file_put_contents($this->visitors_file, json_encode($this->visitors_data));
|
file_put_contents($this->visitors_file, json_encode($this->visitors_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getData($path)
|
protected function getData($path)
|
||||||
{
|
{
|
||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user