mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 22:06:43 +02:00
🎨 Code cleanup and PHPDoc
This commit is contained in:
@@ -142,7 +142,7 @@ abstract class Folder
|
||||
* @return array
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function all($path, array $params = array())
|
||||
public static function all($path, array $params = [])
|
||||
{
|
||||
if ($path === false) {
|
||||
throw new \RuntimeException("Path to {$path} doesn't exist.");
|
||||
@@ -167,7 +167,7 @@ abstract class Folder
|
||||
$iterator = new \FilesystemIterator($path);
|
||||
}
|
||||
|
||||
$results = array();
|
||||
$results = [];
|
||||
|
||||
/** @var \RecursiveDirectoryIterator $file */
|
||||
foreach ($iterator as $file) {
|
||||
|
||||
@@ -459,9 +459,9 @@ class Language
|
||||
// split $pref again by ';q='
|
||||
// and decorate the language entries by inverted position
|
||||
if (false !== ($i = strpos($pref, ';q='))) {
|
||||
$langs[substr($pref, 0, $i)] = array((float)substr($pref, $i + 3), -$k);
|
||||
$langs[substr($pref, 0, $i)] = [(float)substr($pref, $i + 3), -$k];
|
||||
} else {
|
||||
$langs[$pref] = array(1, -$k);
|
||||
$langs[$pref] = [1, -$k];
|
||||
}
|
||||
}
|
||||
arsort($langs);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
namespace Grav\Common\Markdown;
|
||||
|
||||
use Grav\Common\GravTrait;
|
||||
use Grav\Common\Page\Page;
|
||||
use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Uri;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
|
||||
@@ -11,13 +13,18 @@ use RocketTheme\Toolbox\Event\Event;
|
||||
trait ParsedownGravTrait
|
||||
{
|
||||
use GravTrait;
|
||||
|
||||
/** @var Page $page */
|
||||
protected $page;
|
||||
|
||||
/** @var Pages $pages */
|
||||
protected $pages;
|
||||
|
||||
protected $base_url;
|
||||
protected $pages_dir;
|
||||
protected $special_chars;
|
||||
protected $twig_link_regex = '/\!*\[(?:.*)\]\((\{([\{%#])\s*(.*?)\s*(?:\2|\})\})\)/';
|
||||
protected $special_protocols = ['xmpp','mailto','tel','sms'];
|
||||
protected $special_protocols = ['xmpp', 'mailto', 'tel', 'sms'];
|
||||
|
||||
public $completable_blocks = [];
|
||||
public $continuable_blocks = [];
|
||||
@@ -37,7 +44,7 @@ trait ParsedownGravTrait
|
||||
$this->BlockTypes['{'] [] = "TwigTag";
|
||||
$this->base_url = rtrim(self::getGrav()['base_url'] . self::getGrav()['pages']->base(), '/');
|
||||
$this->pages_dir = self::getGrav()['locator']->findResource('page://');
|
||||
$this->special_chars = array('>' => 'gt', '<' => 'lt', '"' => 'quot');
|
||||
$this->special_chars = ['>' => 'gt', '<' => 'lt', '"' => 'quot'];
|
||||
|
||||
if ($defaults === null) {
|
||||
$defaults = self::getGrav()['config']->get('system.pages.markdown');
|
||||
@@ -60,7 +67,7 @@ trait ParsedownGravTrait
|
||||
*/
|
||||
public function addBlockType($type, $tag, $continuable = false, $completable = false)
|
||||
{
|
||||
$this->BlockTypes[$type] []= $tag;
|
||||
$this->BlockTypes[$type] [] = $tag;
|
||||
|
||||
if ($continuable) {
|
||||
$this->continuable_blocks[] = $tag;
|
||||
@@ -79,7 +86,7 @@ trait ParsedownGravTrait
|
||||
*/
|
||||
public function addInlineType($type, $tag)
|
||||
{
|
||||
$this->InlineTypes[$type] []= $tag;
|
||||
$this->InlineTypes[$type] [] = $tag;
|
||||
$this->inlineMarkerList .= $type;
|
||||
}
|
||||
|
||||
@@ -87,11 +94,13 @@ trait ParsedownGravTrait
|
||||
* Overrides the default behavior to allow for plugin-provided blocks to be continuable
|
||||
*
|
||||
* @param $Type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBlockContinuable($Type)
|
||||
{
|
||||
$continuable = in_array($Type, $this->continuable_blocks) || method_exists($this, 'block'.$Type.'Continue');
|
||||
$continuable = in_array($Type, $this->continuable_blocks) || method_exists($this, 'block' . $Type . 'Continue');
|
||||
|
||||
return $continuable;
|
||||
}
|
||||
|
||||
@@ -99,11 +108,13 @@ trait ParsedownGravTrait
|
||||
* Overrides the default behavior to allow for plugin-provided blocks to be completable
|
||||
*
|
||||
* @param $Type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBlockCompletable($Type)
|
||||
{
|
||||
$completable = in_array($Type, $this->completable_blocks) || method_exists($this, 'block'.$Type.'Complete');
|
||||
$completable = in_array($Type, $this->completable_blocks) || method_exists($this, 'block' . $Type . 'Complete');
|
||||
|
||||
return $completable;
|
||||
}
|
||||
|
||||
@@ -111,7 +122,8 @@ trait ParsedownGravTrait
|
||||
/**
|
||||
* Make the element function publicly accessible, Medium uses this to render from Twig
|
||||
*
|
||||
* @param array $Element
|
||||
* @param array $Element
|
||||
*
|
||||
* @return string markup
|
||||
*/
|
||||
public function elementToHtml(array $Element)
|
||||
@@ -139,27 +151,28 @@ trait ParsedownGravTrait
|
||||
protected function blockTwigTag($Line)
|
||||
{
|
||||
if (preg_match('/(?:{{|{%|{#)(.*)(?:}}|%}|#})/', $Line['body'], $matches)) {
|
||||
$Block = array(
|
||||
$Block = [
|
||||
'markup' => $Line['body'],
|
||||
);
|
||||
];
|
||||
|
||||
return $Block;
|
||||
}
|
||||
}
|
||||
|
||||
protected function inlineSpecialCharacter($Excerpt)
|
||||
{
|
||||
if ($Excerpt['text'][0] === '&' && ! preg_match('/^&#?\w+;/', $Excerpt['text'])) {
|
||||
return array(
|
||||
if ($Excerpt['text'][0] === '&' && !preg_match('/^&#?\w+;/', $Excerpt['text'])) {
|
||||
return [
|
||||
'markup' => '&',
|
||||
'extent' => 1,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->special_chars[$Excerpt['text'][0]])) {
|
||||
return array(
|
||||
'markup' => '&'.$this->special_chars[$Excerpt['text'][0]].';',
|
||||
return [
|
||||
'markup' => '&' . $this->special_chars[$Excerpt['text'][0]] . ';',
|
||||
'extent' => 1,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +183,7 @@ trait ParsedownGravTrait
|
||||
$excerpt = parent::inlineImage($excerpt);
|
||||
$excerpt['element']['attributes']['src'] = $matches[1];
|
||||
$excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
|
||||
|
||||
return $excerpt;
|
||||
} else {
|
||||
$excerpt['type'] = 'image';
|
||||
@@ -177,7 +191,7 @@ trait ParsedownGravTrait
|
||||
}
|
||||
|
||||
// Some stuff we will need
|
||||
$actions = array();
|
||||
$actions = [];
|
||||
$media = null;
|
||||
|
||||
// if this is an image
|
||||
@@ -219,7 +233,7 @@ trait ParsedownGravTrait
|
||||
$actions = array_reduce(explode('&', $url['query']), function ($carry, $item) {
|
||||
$parts = explode('=', $item, 2);
|
||||
$value = isset($parts[1]) ? $parts[1] : null;
|
||||
$carry[] = [ 'method' => $parts[0], 'params' => $value ];
|
||||
$carry[] = ['method' => $parts[0], 'params' => $value];
|
||||
|
||||
return $carry;
|
||||
}, []);
|
||||
@@ -227,7 +241,8 @@ trait ParsedownGravTrait
|
||||
|
||||
// loop through actions for the image and call them
|
||||
foreach ($actions as $action) {
|
||||
$medium = call_user_func_array(array($medium, $action['method']), explode(',', urldecode($action['params'])));
|
||||
$medium = call_user_func_array([$medium, $action['method']],
|
||||
explode(',', urldecode($action['params'])));
|
||||
}
|
||||
|
||||
if (isset($url['fragment'])) {
|
||||
@@ -260,6 +275,7 @@ trait ParsedownGravTrait
|
||||
$excerpt = parent::inlineLink($excerpt);
|
||||
$excerpt['element']['attributes']['href'] = $matches[1];
|
||||
$excerpt['extent'] = $excerpt['extent'] + strlen($matches[1]) - 1;
|
||||
|
||||
return $excerpt;
|
||||
} else {
|
||||
$excerpt = parent::inlineLink($excerpt);
|
||||
@@ -302,7 +318,7 @@ trait ParsedownGravTrait
|
||||
}
|
||||
|
||||
|
||||
$url['query']= http_build_query($actions, null, '&', PHP_QUERY_RFC3986);
|
||||
$url['query'] = http_build_query($actions, null, '&', PHP_QUERY_RFC3986);
|
||||
}
|
||||
|
||||
// if no query elements left, unset query
|
||||
@@ -312,7 +328,8 @@ trait ParsedownGravTrait
|
||||
|
||||
// if there is no scheme, the file is local and we'll need to convert that URL
|
||||
if (!isset($url['scheme']) && (count($url) > 0)) {
|
||||
$excerpt['element']['attributes']['href'] = Uri::convertUrl($this->page, Uri::buildUrl($url), $type, true);
|
||||
$excerpt['element']['attributes']['href'] = Uri::convertUrl($this->page, Uri::buildUrl($url), $type,
|
||||
true);
|
||||
} elseif (in_array($url['scheme'], $this->special_protocols)) {
|
||||
return $excerpt;
|
||||
} else {
|
||||
@@ -328,6 +345,7 @@ trait ParsedownGravTrait
|
||||
{
|
||||
if (isset($this->$method) === true) {
|
||||
$func = $this->$method;
|
||||
|
||||
return call_user_func_array($func, $args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ namespace Grav\Common\Page;
|
||||
use RocketTheme\Toolbox\ArrayTraits\Constructor;
|
||||
use RocketTheme\Toolbox\ArrayTraits\NestedArrayAccess;
|
||||
|
||||
/**
|
||||
* Class Header
|
||||
* @package Grav\Common\Page
|
||||
*/
|
||||
class Header implements \ArrayAccess
|
||||
{
|
||||
use NestedArrayAccess, Constructor;
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Grav\Common\User;
|
||||
/**
|
||||
* User authentication
|
||||
*
|
||||
* @author RocketTheme
|
||||
* @author RocketTheme
|
||||
* @license MIT
|
||||
*/
|
||||
abstract class Authentication
|
||||
@@ -12,7 +12,8 @@ abstract class Authentication
|
||||
/**
|
||||
* Create password hash from plaintext password.
|
||||
*
|
||||
* @param string $password Plaintext password.
|
||||
* @param string $password Plaintext password.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
* @return string|bool
|
||||
*/
|
||||
@@ -34,8 +35,9 @@ abstract class Authentication
|
||||
/**
|
||||
* Verifies that a password matches a hash.
|
||||
*
|
||||
* @param string $password Plaintext password.
|
||||
* @param string $hash Hash to verify against.
|
||||
* @param string $password Plaintext password.
|
||||
* @param string $hash Hash to verify against.
|
||||
*
|
||||
* @return int Returns 0 if the check fails, 1 if password matches, 2 if hash needs to be updated.
|
||||
*/
|
||||
public static function verify($password, $hash)
|
||||
|
||||
@@ -10,10 +10,7 @@ use Grav\Common\Utils;
|
||||
/**
|
||||
* Group object
|
||||
*
|
||||
* @property mixed authenticated
|
||||
* @property mixed password
|
||||
* @property bool|string hashed_password
|
||||
* @author RocketTheme
|
||||
* @author RocketTheme
|
||||
* @license MIT
|
||||
*/
|
||||
class Group extends Data
|
||||
@@ -28,12 +25,15 @@ class Group extends Data
|
||||
private static function groups()
|
||||
{
|
||||
$groups = self::getGrav()['config']->get('groups');
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a group exists
|
||||
*
|
||||
* @param string $groupname
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function group_exists($groupname)
|
||||
@@ -44,6 +44,8 @@ class Group extends Data
|
||||
/**
|
||||
* Get a group by name
|
||||
*
|
||||
* @param string $groupname
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function load($groupname)
|
||||
@@ -76,7 +78,7 @@ class Group extends Data
|
||||
|
||||
self::getGrav()['config']->set("groups.$this->groupname", []);
|
||||
|
||||
foreach($fields as $field) {
|
||||
foreach ($fields as $field) {
|
||||
if ($field['type'] == 'text') {
|
||||
$value = $field['name'];
|
||||
if (isset($this->items[$value])) {
|
||||
@@ -87,8 +89,10 @@ class Group extends Data
|
||||
$value = $field['name'];
|
||||
$arrayValues = Utils::resolve($this->items, $field['name']);
|
||||
|
||||
if ($arrayValues) foreach($arrayValues as $arrayIndex => $arrayValue) {
|
||||
self::getGrav()['config']->set("groups.$this->groupname.$value.$arrayIndex", $arrayValue);
|
||||
if ($arrayValues) {
|
||||
foreach ($arrayValues as $arrayIndex => $arrayValue) {
|
||||
self::getGrav()['config']->set("groups.$this->groupname.$value.$arrayIndex", $arrayValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +108,8 @@ class Group extends Data
|
||||
/**
|
||||
* Remove a group
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $groupname
|
||||
*
|
||||
* @return bool True if the action was performed
|
||||
*/
|
||||
public static function remove($groupname)
|
||||
|
||||
@@ -10,10 +10,10 @@ use Grav\Common\Utils;
|
||||
/**
|
||||
* User object
|
||||
*
|
||||
* @property mixed authenticated
|
||||
* @property mixed password
|
||||
* @property mixed authenticated
|
||||
* @property mixed password
|
||||
* @property bool|string hashed_password
|
||||
* @author RocketTheme
|
||||
* @author RocketTheme
|
||||
* @license MIT
|
||||
*/
|
||||
class User extends Data
|
||||
@@ -26,6 +26,7 @@ class User extends Data
|
||||
* Always creates user object. To check if user exists, use $this->exists().
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public static function load($username)
|
||||
@@ -56,6 +57,7 @@ class User extends Data
|
||||
* Remove user account.
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return bool True if the action was performed
|
||||
*/
|
||||
public static function remove($username)
|
||||
@@ -73,7 +75,8 @@ class User extends Data
|
||||
*
|
||||
* If user password needs to be updated, new information will be saved.
|
||||
*
|
||||
* @param string $password Plaintext password.
|
||||
* @param string $password Plaintext password.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authenticate($password)
|
||||
@@ -90,6 +93,7 @@ class User extends Data
|
||||
$password,
|
||||
self::getGrav()['config']->get('system.security.default_hash')
|
||||
);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
// Plain-text does match, we can update the hash and proceed
|
||||
@@ -113,7 +117,7 @@ class User extends Data
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +143,8 @@ class User extends Data
|
||||
/**
|
||||
* Checks user authorization to the action.
|
||||
*
|
||||
* @param string $action
|
||||
* @param string $action
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize($action)
|
||||
@@ -156,11 +161,13 @@ class User extends Data
|
||||
|
||||
//Check group access level
|
||||
$groups = $this->get('groups');
|
||||
if ($groups) foreach((array)$groups as $group) {
|
||||
$permission = self::getGrav()['config']->get("groups.{$group}.access.{$action}");
|
||||
$return = Utils::isPositive($permission);
|
||||
if ($return === true) {
|
||||
break;
|
||||
if ($groups) {
|
||||
foreach ((array)$groups as $group) {
|
||||
$permission = self::getGrav()['config']->get("groups.{$group}.access.{$action}");
|
||||
$return = Utils::isPositive($permission);
|
||||
if ($return === true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +187,7 @@ class User extends Data
|
||||
* Ensures backwards compatibility
|
||||
*
|
||||
* @param string $action
|
||||
*
|
||||
* @deprecated use authorize()
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user