Skip to content

Commit

Permalink
Merge branch 'release/5.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jun 2, 2024
2 parents bf6368c + 742a333 commit 1d6111f
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 100 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"][email protected][/safe-email]
Safe-Email Address: [safe-email autolink="true" icon="envelope-o" subject="Feedback"][email protected][/safe-email]
```
#### Section
Expand Down Expand Up @@ -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:
```
<div id="author">{{ page.find('/my/custom/page').contentMeta.shortcodeMeta.shortcode.section.author }}</div>
```
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:
Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion classes/shortcodes/LoremShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function words($count = 1, $tags = false, $array = false)
}
}
}
$words = array_slice($words, 0, $count);
$words = array_slice($words, 0, (int) $count);

return $this->output($words, $tags, $array);
}
Expand Down
40 changes: 31 additions & 9 deletions classes/shortcodes/SafeEmailShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@ public function init()
}

// 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 = '<a href="mailto:' . $email . '">' . $email . '</a>';
$output = '<a href="mailto:' . $email_link . '">' . $email_disp . '</a>';
} else {
$output = $email;
$output = $email_disp;
}

// Handle icon option
Expand All @@ -48,4 +53,21 @@ public function init()
return $output;
});
}
}

/**
* 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;
}
}
11 changes: 11 additions & 0 deletions classes/shortcodes/SectionShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ public function init()
{
$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);
});
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions nextgen-editor/shortcodes/safe-email/safe-email.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ window.nextgenEditor.addShortcode('safe-email', {
icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 9.25a4.924 4.924 0 011.666.291.25.25 0 00.334-.236V1.75a.158.158 0 00-.1-.147.16.16 0 00-.173.034L12.2 10.164a2.407 2.407 0 01-3.4 0L.271 1.637A.159.159 0 000 1.75v10.5A1.749 1.749 0 001.75 14h12.043a.25.25 0 00.249-.226A4.992 4.992 0 0119 9.25z"/><path d="M9.726 9.236a1.094 1.094 0 001.547 0L19.748.761A.437.437 0 0019.5.019 1.62 1.62 0 0019.249 0h-17.5A1.62 1.62 0 001.5.019a.437.437 0 00-.352.3.441.441 0 00.102.442zM22.5 15.5v-1.25a3.5 3.5 0 00-7 0v1.25A1.5 1.5 0 0014 17v5.5a1.5 1.5 0 001.5 1.5h7a1.5 1.5 0 001.5-1.5V17a1.5 1.5 0 00-1.5-1.5zM19 12.75a1.5 1.5 0 011.5 1.5v1.25h-3v-1.25a1.5 1.5 0 011.5-1.5zm1 7.5a1 1 0 11-1-1 1 1 0 011 1z"/></svg>',
},
attributes: {
subject: {
type: String,
title: 'Subject',
widget: 'input-text',
default: '',
},
icon: {
type: String,
title: 'Icon',
Expand Down
17 changes: 15 additions & 2 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading

0 comments on commit 1d6111f

Please sign in to comment.