Skip to content

Commit

Permalink
Bing and Simple Content, add config for disable widgetbay
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio-Emmolo committed Oct 15, 2024
1 parent 12ad142 commit a6b28f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
8 changes: 8 additions & 0 deletions config/shortcode-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@
'#https?://.*#i', // All links
],
],

'simpleContent' => [
'enable_widgetbay' => false,
],

'bingContent' => [
'enable_widgetbay' => false,
],
];
25 changes: 4 additions & 21 deletions src/AltShortcodes/WidgetbayShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,9 @@

class WidgetbayShortcode
{
// public static function parse($content): string
// {
// return preg_replace_callback(
// '/\[widgetbay link="(.*?)".*?\]/',
// function ($matches) {
// $link = $matches[1];
// $links = explode(',', $link);
// $htmlLinks = '';
// foreach ($links as $link) {
// $htmlLinks .= self::getRandomHtmlLinkFromWidgetbay($link) . "<br />";
// }
// return $htmlLinks;
// },
// $content
// );
// }

public function register($shortcode): string
{
if (! $shortcode->link) {
if (!$shortcode->link) {
return '';
}

Expand All @@ -35,7 +18,7 @@ public function register($shortcode): string
$htmlLinks = '';

foreach ($links as $link) {
$htmlLinks .= self::getRandomHtmlLinkFromWidgetbay($link).'<br />';
$htmlLinks .= self::getRandomHtmlLinkFromWidgetbay($link) . '<br />';
}

return $htmlLinks;
Expand All @@ -54,7 +37,7 @@ protected static function getRandomHtmlLinkFromWidgetbay(string $link): string
$shopName = self::getLabelFromUrl($link);

$labels = [
"Acquista {$title} a {$price}".($originalPrice ? " invece {$originalPrice}" : '')."{$percentages}{$shopName}",
"Acquista {$title} a {$price}" . ($originalPrice ? " invece {$originalPrice}" : '') . "{$percentages}{$shopName}",
"Vedi {$title}{$shopName}",
"Scopri il prezzo di {$title}{$shopName}",
];
Expand All @@ -75,6 +58,6 @@ protected static function getLabelFromUrl(string $url)
$domain = str_replace('www.', '', $domain);
$domain = explode('.', $domain);

return $domain[0] ? ' su '.ucwords($domain[0]) : null;
return $domain[0] ? ' su ' . ucwords($domain[0]) : null;
}
}
18 changes: 14 additions & 4 deletions src/LaravelShortcodePlus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

final class LaravelShortcodePlus
{
public function __construct(protected string $content = '') {}
public function __construct(protected string $content = '')
{
}

public static function source(string $source): LaravelShortcodePlus
{
Expand Down Expand Up @@ -69,7 +71,11 @@ public function parseSimpleContent(): string
{
$compiler = new ShortcodeCompiler;
$compiler->add('button', ButtonShortcode::class);
$compiler->add('widgetbay', WidgetbayShortcode::class);

if (config('shortcode-plus.simpleContent.enable_widgetbay')) {
$compiler->add('widgetbay', WidgetbayShortcode::class);
}

$compiler->enable();

$this->content = $compiler->compile($this->content);
Expand All @@ -84,7 +90,11 @@ public function parseBingContent(): string
{
$compiler = new ShortcodeCompiler;
$compiler->add('button', ButtonShortcode::class);
// $compiler->add('widgetbay', WidgetbayShortcode::class);

if (config('shortcode-plus.bingContent.enable_widgetbay')) {
$compiler->add('widgetbay', WidgetbayShortcode::class);
}

$compiler->add('photo', PhotoShortcode::class);
$compiler->add('distico', DisticoShortcode::class);
$compiler->add('leggianche', LeggiancheShortcode::class);
Expand All @@ -105,7 +115,7 @@ public function parseBingContent(): string
/**
* Cleans the content by removing shortcodes and empty paragraphs.
*
* @param string $content The content to be cleaned.
* @param string $content The content to be cleaned.
*/
public static function cleanHtmlAndShortcodes(string $content): string
{
Expand Down

0 comments on commit a6b28f2

Please sign in to comment.