diff --git a/plugins/shortcode-core/CHANGELOG.md b/plugins/shortcode-core/CHANGELOG.md index 32c3284..49a8818 100644 --- a/plugins/shortcode-core/CHANGELOG.md +++ b/plugins/shortcode-core/CHANGELOG.md @@ -1,9 +1,18 @@ +# v5.2.0 +## 06/02/2024 + +1. [](#new) + * Added the ability to display a section from another page. See README.txt for example +1. [](#bugfix) + * Fix for `lorem` shortcode that broke when count was provided + # v5.1.3 ## 06/01/2022 1. [](#improved) * Added a new `display` CLI command to show all registered shortcodes + # v5.1.2 ## 05/10/2022 diff --git a/plugins/shortcode-core/README.md b/plugins/shortcode-core/README.md index acb41ae..a59ca4c 100644 --- a/plugins/shortcode-core/README.md +++ b/plugins/shortcode-core/README.md @@ -241,10 +241,10 @@ Do not process the shortcodes between these raw shortcode tags #### Safe-Email -Encode an email address so that it's not so easily 'scrapable' by nefarious scripts. This one has a couple of options: `autolink` toggle to turn the email into a link, and an `icon` option that lets you pick a font-awesome icon to prefix the email. Both settings are optional. +Encode an email address so that it's not so easily 'scrapable' by nefarious scripts. This one has a couple of options: `autolink` toggle to turn the email into a link, an `icon` option that lets you pick a font-awesome icon to prefix the email, and a `subject` option that let's you specify the subject line for the user's mail agent to prefill. All settings are optional. ``` -Safe-Email Address: [safe-email autolink="true" icon="envelope-o"]user@domain.com[/safe-email] +Safe-Email Address: [safe-email autolink="true" icon="envelope-o" subject="Feedback"]user@domain.com[/safe-email] ``` #### Section @@ -284,12 +284,20 @@ This we be removed from the page content and made available in Twig variables so #### Sections from other pages -You can even retrieve a section from another page utilizing the shortcodes as they are stored in the page's `contentMeta` with this syntax: +You can even retrieve a section from another page utilizing the shortcodes as they are stored in the page's `contentMeta` with this Twig syntax: ```
{{ page.find('/my/custom/page').contentMeta.shortcodeMeta.shortcode.section.author }}
``` +There may be a scenario where you define a section in another page, but want to use it in the content of a page. You can now do so with the same `[section]` shortcode by providing the page where the section is defined, and also the name of the section with no shortcode body. For example + +```markdown +[section page="/my/custom/page" name="author" /] +``` + +!! NOTE for this to work, the shortcode needs to be defined a parent page, or page that has been processed before the current page. + #### Notice A useful shortcode that performs a similar job to the [markdown-notices](https://github.com/getgrav/grav-plugin-markdown-notices) plugins, allows you to easily create simple notice blocks as seen on http://learn.getgrav.org and http://getgrav.org. To use simply use the following syntax: diff --git a/plugins/shortcode-core/blueprints.yaml b/plugins/shortcode-core/blueprints.yaml index 15426d0..3f3c4e4 100644 --- a/plugins/shortcode-core/blueprints.yaml +++ b/plugins/shortcode-core/blueprints.yaml @@ -1,7 +1,7 @@ name: Shortcode Core slug: shortcode-core type: plugin -version: 5.1.3 +version: 5.2.0 description: "This plugin provides the core functionality for shortcode plugins" icon: code author: diff --git a/plugins/shortcode-core/classes/shortcodes/LoremShortcode.php b/plugins/shortcode-core/classes/shortcodes/LoremShortcode.php index 998415d..d239565 100644 --- a/plugins/shortcode-core/classes/shortcodes/LoremShortcode.php +++ b/plugins/shortcode-core/classes/shortcodes/LoremShortcode.php @@ -145,7 +145,7 @@ class LoremShortcode extends Shortcode } } } - $words = array_slice($words, 0, $count); + $words = array_slice($words, 0, (int) $count); return $this->output($words, $tags, $array); } diff --git a/plugins/shortcode-core/classes/shortcodes/SafeEmailShortcode.php b/plugins/shortcode-core/classes/shortcodes/SafeEmailShortcode.php index 42443f3..036b6a9 100644 --- a/plugins/shortcode-core/classes/shortcodes/SafeEmailShortcode.php +++ b/plugins/shortcode-core/classes/shortcodes/SafeEmailShortcode.php @@ -14,23 +14,28 @@ class SafeEmailShortcode extends Shortcode } // Get shortcode content and parameters - $str = $sc->getContent(); + $addr_str = $sc->getContent(); $icon = $sc->getParameter('icon', false); $icon_base = "fa fa-"; $autolink = $sc->getParameter('autolink', false); + $subject = $sc->getParameter('subject', false); - // Encode email - $email = ''; - $str_len = strlen($str); - for ($i = 0; $i < $str_len; $i++) { - $email .= '&#' . ord($str[$i]). ';'; + // Add subject, if any, to the link target. + $link_str = $addr_str; + if ($subject) { + $subject = html_entity_decode($subject); + $link_str .= '?subject=' . rawurlencode($subject); } + // Encode display text and link target + $email_disp = static::encodeText($addr_str); + $email_link = static::encodeText($link_str); + // Handle autolinking if ($autolink) { - $output = '' . $email . ''; + $output = '' . $email_disp . ''; } else { - $output = $email; + $output = $email_disp; } // Handle icon option @@ -48,4 +53,21 @@ class SafeEmailShortcode extends Shortcode return $output; }); } -} \ No newline at end of file + + /** + * encodes text as numeric HTML entities + * @param string $text the text to encode + * @return string the encoded text + */ + private static function encodeText($text) + { + $encoded = ''; + $str_len = strlen($text); + + for ($i = 0; $i < $str_len; $i++) { + $encoded .= '&#' . ord($text[$i]). ';'; + } + + return $encoded; + } +} diff --git a/plugins/shortcode-core/classes/shortcodes/SectionShortcode.php b/plugins/shortcode-core/classes/shortcodes/SectionShortcode.php index f3f8cb3..847aad8 100644 --- a/plugins/shortcode-core/classes/shortcodes/SectionShortcode.php +++ b/plugins/shortcode-core/classes/shortcodes/SectionShortcode.php @@ -9,6 +9,17 @@ class SectionShortcode extends Shortcode { $this->shortcode->getHandlers()->add('section', function(ShortcodeInterface $sc) { $name = $sc->getParameter('name'); + $page = $sc->getParameter('page'); + $content = $sc->getContent(); + + if (empty($content) && isset($page)) { + if ($target = $this->grav['pages']->find($page)) { + if ($shortcodeObject = $target->contentMeta()['shortcodeMeta']['shortcode'][$sc->getName()][$name] ?? false) { + return (string) $shortcodeObject; + } + } + } + $object = new \Grav\Plugin\ShortcodeCore\ShortcodeObject($name, $sc->getContent()); $this->shortcode->addObject($sc->getName(), $object); }); diff --git a/plugins/shortcode-core/composer.lock b/plugins/shortcode-core/composer.lock index 40ab44d..4c18623 100644 --- a/plugins/shortcode-core/composer.lock +++ b/plugins/shortcode-core/composer.lock @@ -76,5 +76,5 @@ "platform-overrides": { "php": "7.1.3" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/plugins/shortcode-core/nextgen-editor/shortcodes/safe-email/safe-email.js b/plugins/shortcode-core/nextgen-editor/shortcodes/safe-email/safe-email.js index 7314813..dfe889c 100644 --- a/plugins/shortcode-core/nextgen-editor/shortcodes/safe-email/safe-email.js +++ b/plugins/shortcode-core/nextgen-editor/shortcodes/safe-email/safe-email.js @@ -8,6 +8,12 @@ window.nextgenEditor.addShortcode('safe-email', { icon: '', }, attributes: { + subject: { + type: String, + title: 'Subject', + widget: 'input-text', + default: '', + }, icon: { type: String, title: 'Icon', diff --git a/plugins/shortcode-core/vendor/autoload.php b/plugins/shortcode-core/vendor/autoload.php index d7a4ef3..28b3fcc 100644 --- a/plugins/shortcode-core/vendor/autoload.php +++ b/plugins/shortcode-core/vendor/autoload.php @@ -3,8 +3,21 @@ // autoload.php @generated by Composer if (PHP_VERSION_ID < 50600) { - echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; - exit(1); + if (!headers_sent()) { + header('HTTP/1.1 500 Internal Server Error'); + } + $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; + if (!ini_get('display_errors')) { + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { + fwrite(STDERR, $err); + } elseif (!headers_sent()) { + echo $err; + } + } + trigger_error( + $err, + E_USER_ERROR + ); } require_once __DIR__ . '/composer/autoload_real.php'; diff --git a/plugins/shortcode-core/vendor/composer/ClassLoader.php b/plugins/shortcode-core/vendor/composer/ClassLoader.php index afef3fa..7824d8f 100644 --- a/plugins/shortcode-core/vendor/composer/ClassLoader.php +++ b/plugins/shortcode-core/vendor/composer/ClassLoader.php @@ -42,35 +42,37 @@ namespace Composer\Autoload; */ class ClassLoader { - /** @var ?string */ + /** @var \Closure(string):void */ + private static $includeFile; + + /** @var string|null */ private $vendorDir; // PSR-4 /** - * @var array[] - * @psalm-var array> + * @var array> */ private $prefixLengthsPsr4 = array(); /** - * @var array[] - * @psalm-var array> + * @var array> */ private $prefixDirsPsr4 = array(); /** - * @var array[] - * @psalm-var array + * @var list */ private $fallbackDirsPsr4 = array(); // PSR-0 /** - * @var array[] - * @psalm-var array> + * List of PSR-0 prefixes + * + * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2'))) + * + * @var array>> */ private $prefixesPsr0 = array(); /** - * @var array[] - * @psalm-var array + * @var list */ private $fallbackDirsPsr0 = array(); @@ -78,8 +80,7 @@ class ClassLoader private $useIncludePath = false; /** - * @var string[] - * @psalm-var array + * @var array */ private $classMap = array(); @@ -87,29 +88,29 @@ class ClassLoader private $classMapAuthoritative = false; /** - * @var bool[] - * @psalm-var array + * @var array */ private $missingClasses = array(); - /** @var ?string */ + /** @var string|null */ private $apcuPrefix; /** - * @var self[] + * @var array */ private static $registeredLoaders = array(); /** - * @param ?string $vendorDir + * @param string|null $vendorDir */ public function __construct($vendorDir = null) { $this->vendorDir = $vendorDir; + self::initializeIncludeClosure(); } /** - * @return string[] + * @return array> */ public function getPrefixes() { @@ -121,8 +122,7 @@ class ClassLoader } /** - * @return array[] - * @psalm-return array> + * @return array> */ public function getPrefixesPsr4() { @@ -130,8 +130,7 @@ class ClassLoader } /** - * @return array[] - * @psalm-return array + * @return list */ public function getFallbackDirs() { @@ -139,8 +138,7 @@ class ClassLoader } /** - * @return array[] - * @psalm-return array + * @return list */ public function getFallbackDirsPsr4() { @@ -148,8 +146,7 @@ class ClassLoader } /** - * @return string[] Array of classname => path - * @psalm-return array + * @return array Array of classname => path */ public function getClassMap() { @@ -157,8 +154,7 @@ class ClassLoader } /** - * @param string[] $classMap Class to filename map - * @psalm-param array $classMap + * @param array $classMap Class to filename map * * @return void */ @@ -175,24 +171,25 @@ class ClassLoader * Registers a set of PSR-0 directories for a given prefix, either * appending or prepending to the ones previously set for this prefix. * - * @param string $prefix The prefix - * @param string[]|string $paths The PSR-0 root directories - * @param bool $prepend Whether to prepend the directories + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories * * @return void */ public function add($prefix, $paths, $prepend = false) { + $paths = (array) $paths; if (!$prefix) { if ($prepend) { $this->fallbackDirsPsr0 = array_merge( - (array) $paths, + $paths, $this->fallbackDirsPsr0 ); } else { $this->fallbackDirsPsr0 = array_merge( $this->fallbackDirsPsr0, - (array) $paths + $paths ); } @@ -201,19 +198,19 @@ class ClassLoader $first = $prefix[0]; if (!isset($this->prefixesPsr0[$first][$prefix])) { - $this->prefixesPsr0[$first][$prefix] = (array) $paths; + $this->prefixesPsr0[$first][$prefix] = $paths; return; } if ($prepend) { $this->prefixesPsr0[$first][$prefix] = array_merge( - (array) $paths, + $paths, $this->prefixesPsr0[$first][$prefix] ); } else { $this->prefixesPsr0[$first][$prefix] = array_merge( $this->prefixesPsr0[$first][$prefix], - (array) $paths + $paths ); } } @@ -222,9 +219,9 @@ class ClassLoader * Registers a set of PSR-4 directories for a given namespace, either * appending or prepending to the ones previously set for this namespace. * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param string[]|string $paths The PSR-4 base directories - * @param bool $prepend Whether to prepend the directories + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories * * @throws \InvalidArgumentException * @@ -232,17 +229,18 @@ class ClassLoader */ public function addPsr4($prefix, $paths, $prepend = false) { + $paths = (array) $paths; if (!$prefix) { // Register directories for the root namespace. if ($prepend) { $this->fallbackDirsPsr4 = array_merge( - (array) $paths, + $paths, $this->fallbackDirsPsr4 ); } else { $this->fallbackDirsPsr4 = array_merge( $this->fallbackDirsPsr4, - (array) $paths + $paths ); } } elseif (!isset($this->prefixDirsPsr4[$prefix])) { @@ -252,18 +250,18 @@ class ClassLoader throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; + $this->prefixDirsPsr4[$prefix] = $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( - (array) $paths, + $paths, $this->prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. $this->prefixDirsPsr4[$prefix] = array_merge( $this->prefixDirsPsr4[$prefix], - (array) $paths + $paths ); } } @@ -272,8 +270,8 @@ class ClassLoader * Registers a set of PSR-0 directories for a given prefix, * replacing any others previously set for this prefix. * - * @param string $prefix The prefix - * @param string[]|string $paths The PSR-0 base directories + * @param string $prefix The prefix + * @param list|string $paths The PSR-0 base directories * * @return void */ @@ -290,8 +288,8 @@ class ClassLoader * Registers a set of PSR-4 directories for a given namespace, * replacing any others previously set for this namespace. * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param string[]|string $paths The PSR-4 base directories + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param list|string $paths The PSR-4 base directories * * @throws \InvalidArgumentException * @@ -425,7 +423,8 @@ class ClassLoader public function loadClass($class) { if ($file = $this->findFile($class)) { - includeFile($file); + $includeFile = self::$includeFile; + $includeFile($file); return true; } @@ -476,9 +475,9 @@ class ClassLoader } /** - * Returns the currently registered loaders indexed by their corresponding vendor directories. + * Returns the currently registered loaders keyed by their corresponding vendor directories. * - * @return self[] + * @return array */ public static function getRegisteredLoaders() { @@ -555,18 +554,26 @@ class ClassLoader return false; } -} -/** - * Scope isolated include. - * - * Prevents access to $this/self from included files. - * - * @param string $file - * @return void - * @private - */ -function includeFile($file) -{ - include $file; + /** + * @return void + */ + private static function initializeIncludeClosure() + { + if (self::$includeFile !== null) { + return; + } + + /** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + * + * @param string $file + * @return void + */ + self::$includeFile = \Closure::bind(static function($file) { + include $file; + }, null, null); + } } diff --git a/plugins/shortcode-core/vendor/composer/InstalledVersions.php b/plugins/shortcode-core/vendor/composer/InstalledVersions.php index 41bc143..51e734a 100644 --- a/plugins/shortcode-core/vendor/composer/InstalledVersions.php +++ b/plugins/shortcode-core/vendor/composer/InstalledVersions.php @@ -28,7 +28,7 @@ class InstalledVersions { /** * @var mixed[]|null - * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array}|array{}|null + * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array}|array{}|null */ private static $installed; @@ -39,7 +39,7 @@ class InstalledVersions /** * @var array[] - * @psalm-var array}> + * @psalm-var array}> */ private static $installedByVendor = array(); @@ -98,7 +98,7 @@ class InstalledVersions { foreach (self::getInstalled() as $installed) { if (isset($installed['versions'][$packageName])) { - return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']); + return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false; } } @@ -119,7 +119,7 @@ class InstalledVersions */ public static function satisfies(VersionParser $parser, $packageName, $constraint) { - $constraint = $parser->parseConstraints($constraint); + $constraint = $parser->parseConstraints((string) $constraint); $provided = $parser->parseConstraints(self::getVersionRanges($packageName)); return $provided->matches($constraint); @@ -243,7 +243,7 @@ class InstalledVersions /** * @return array - * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string} + * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool} */ public static function getRootPackage() { @@ -257,7 +257,7 @@ class InstalledVersions * * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect. * @return array[] - * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array} + * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} */ public static function getRawData() { @@ -280,7 +280,7 @@ class InstalledVersions * Returns the raw data of all installed.php which are currently loaded for custom implementations * * @return array[] - * @psalm-return list}> + * @psalm-return list}> */ public static function getAllRawData() { @@ -303,7 +303,7 @@ class InstalledVersions * @param array[] $data A vendor/composer/installed.php data set * @return void * - * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array} $data + * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $data */ public static function reload($data) { @@ -313,7 +313,7 @@ class InstalledVersions /** * @return array[] - * @psalm-return list}> + * @psalm-return list}> */ private static function getInstalled() { @@ -328,7 +328,9 @@ class InstalledVersions if (isset(self::$installedByVendor[$vendorDir])) { $installed[] = self::$installedByVendor[$vendorDir]; } elseif (is_file($vendorDir.'/composer/installed.php')) { - $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php'; + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require $vendorDir.'/composer/installed.php'; + $installed[] = self::$installedByVendor[$vendorDir] = $required; if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) { self::$installed = $installed[count($installed) - 1]; } @@ -340,12 +342,17 @@ class InstalledVersions // only require the installed.php file if this file is loaded from its dumped location, // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937 if (substr(__DIR__, -8, 1) !== 'C') { - self::$installed = require __DIR__ . '/installed.php'; + /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array} $required */ + $required = require __DIR__ . '/installed.php'; + self::$installed = $required; } else { self::$installed = array(); } } - $installed[] = self::$installed; + + if (self::$installed !== array()) { + $installed[] = self::$installed; + } return $installed; } diff --git a/plugins/shortcode-core/vendor/composer/installed.json b/plugins/shortcode-core/vendor/composer/installed.json index a2b30f1..15d8528 100644 --- a/plugins/shortcode-core/vendor/composer/installed.json +++ b/plugins/shortcode-core/vendor/composer/installed.json @@ -60,6 +60,6 @@ "install-path": "../thunderer/shortcode" } ], - "dev": false, + "dev": true, "dev-package-names": [] } diff --git a/plugins/shortcode-core/vendor/composer/installed.php b/plugins/shortcode-core/vendor/composer/installed.php index 864b723..587e21b 100644 --- a/plugins/shortcode-core/vendor/composer/installed.php +++ b/plugins/shortcode-core/vendor/composer/installed.php @@ -1,31 +1,31 @@ array( + 'name' => 'getgrav/shortcode-core', 'pretty_version' => 'dev-develop', 'version' => 'dev-develop', + 'reference' => 'be1b12ecc2b9807da0a5415ef7432a6ae2ac9cee', 'type' => 'grav-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => 'd351265e0de9dfd18dcc842977d80b97c9524e81', - 'name' => 'getgrav/shortcode-core', - 'dev' => false, + 'dev' => true, ), 'versions' => array( 'getgrav/shortcode-core' => array( 'pretty_version' => 'dev-develop', 'version' => 'dev-develop', + 'reference' => 'be1b12ecc2b9807da0a5415ef7432a6ae2ac9cee', 'type' => 'grav-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => 'd351265e0de9dfd18dcc842977d80b97c9524e81', 'dev_requirement' => false, ), 'thunderer/shortcode' => array( 'pretty_version' => 'v0.7.5', 'version' => '0.7.5.0', + 'reference' => 'a4fee30613bd46efb421f8305aff0466a3268a99', 'type' => 'library', 'install_path' => __DIR__ . '/../thunderer/shortcode', 'aliases' => array(), - 'reference' => 'a4fee30613bd46efb421f8305aff0466a3268a99', 'dev_requirement' => false, ), ),