Skip to content

Commit

Permalink
Merge pull request #21 from RickKukiela/master
Browse files Browse the repository at this point in the history
Craft4 / PHP8 Update
  • Loading branch information
reganlawton authored Nov 18, 2022
2 parents 4ae12a2 + c27e23a commit a4a2f81
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 142 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Simple Sharing Changelog

## 2.0.0 - 2022-11-17
### Updated
- Craft4.x Support Added (^2.0.0 is not backward compatible with Craft3.x, use 1.x branch).

## 1.0.8 - 2020-11-08

### Updated
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ Simple Sharing is a CraftCMS plugin that generates social media share links with
the Craft CP page, allowing you to quickly and easily share entries.

## Requirements
Current Version: 2.0.0\
This plugin requires Craft CMS ^4.0.0.

This plugin requires Craft CMS 3.0.0-beta.23 or later.
If you are looking for CraftCMS 3.x support, use current project [Version 1.0.8](https://github.com/wrav/SimpleSharing/tree/1.0.8)

If use are looking for CraftCMS 2.5 support use previous project [version 1.1.5](https://github.com/hut6/SimpleSharing/tree/1.1.5)
which is the latest release for CraftCMS 2.5.
If you are looking for CraftCMS 2.5 support, use previous project [version 1.1.5](https://github.com/hut6/SimpleSharing/tree/1.1.5)

## Installing

Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wrav/simplesharing",
"description": "Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.",
"type": "craft-plugin",
"version": "1.0.8",
"version": "2.0.0",
"keywords": [
"craft",
"cms",
Expand Down Expand Up @@ -31,7 +31,8 @@
}
],
"require": {
"craftcms/cms": "^3.0.0-beta.23"
"php": ">=8.0.0",
"craftcms/cms": "^4.0.0"
},
"repositories": [
{
Expand All @@ -53,5 +54,11 @@
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/wrav/SimpleSharing/master/CHANGELOG.md",
"class": "wrav\\simplesharing\\SimpleSharing"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
}
34 changes: 10 additions & 24 deletions src/SimpleSharing.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 3.x
* SimpleSharing plugin for Craft CMS 4.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand All @@ -10,6 +10,7 @@

namespace wrav\simplesharing;

use craft\base\Model;
use craft\web\View;
use wrav\simplesharing\variables\SimpleSharingVariable;
use wrav\simplesharing\models\Settings;
Expand All @@ -18,11 +19,10 @@
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\web\UrlManager;
use craft\web\twig\variables\CraftVariable;
use craft\events\RegisterUrlRulesEvent;

use yii\base\Event;
use yii\base\View as ViewAlias;

/**
* Class SimpleSharing
Expand All @@ -36,11 +36,7 @@ class SimpleSharing extends Plugin
{
// Static Properties
// =========================================================================

/**
* @var SimpleSharing
*/
public static $plugin;
public static SimpleSharing $plugin;

// Public Methods
// =========================================================================
Expand All @@ -63,22 +59,12 @@ function (Event $event) {
}
);

Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
if ($event->plugin === $this) {
}
}
);

Event::on(
View::class,
View::EVENT_END_PAGE,
function(Event $event) {
ViewAlias::EVENT_END_PAGE,
function() {
if (Craft::$app->getRequest()->getIsCpRequest()) {
$url = Craft::$app->assetManager->getPublishedUrl('@wrav/simplesharing/assetbundles/simplesharing/dist/js/SimpleSharing.js', true);

echo "<script src='$url'></script>";
}
}
Expand All @@ -100,7 +86,7 @@ function(Event $event) {
/**
* @inheritdoc
*/
protected function createSettingsModel()
protected function createSettingsModel(): ?Model
{
return new Settings();
}
Expand All @@ -110,18 +96,18 @@ protected function createSettingsModel()
*/
protected function settingsHtml(): string
{
$sections = Craft::$app->sections->getAllSections('id');
$sections = Craft::$app->sections->getAllSections();
$optionsSections = [];

foreach ($sections as $id => $section) {
foreach ($sections as $section) {
$optionsSections[$section->id] = $section->name;
}

$optionsPlatforms = [
'facebook' => 'Facebook',
'twitter' => 'Twitter',
'linkedin' => 'LinkedIn',
// 'pinterest' => 'Pinterest',
//'pinterest' => 'Pinterest',
'mix' => 'Mix',
'tumblr' => 'Tumblr',
'reddit' => 'Reddit',
Expand Down
53 changes: 1 addition & 52 deletions src/assetbundles/simplesharing/dist/img/SimpleSharing-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 18 additions & 13 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 3.x
* SimpleSharing plugin for Craft CMS 4.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand All @@ -10,11 +10,12 @@

namespace wrav\simplesharing\controllers;

use craft\elements\Entry;
use Twig\Error\LoaderError;
use Twig\Error\SyntaxError;
use wrav\simplesharing\SimpleSharing;

use Craft;
use craft\web\Controller;
use yii\web\NotFoundHttpException;

/**
* @author reganlawton
Expand All @@ -26,32 +27,36 @@ class DefaultController extends Controller

// Protected Properties
// =========================================================================

protected $allowAnonymous = true;
protected array|bool|int $allowAnonymous = true;

// Public Methods
// =========================================================================

public function actionUrl()
/**
* @return string
* @throws NotFoundHttpException
* @throws LoaderError
* @throws SyntaxError
*/
public function actionUrl(): string
{
$data = Craft::$app->request->getQueryParams();
$allowedSections = SimpleSharing::getInstance()->getSettings()->allowedSections;
$allowedPlatforms = SimpleSharing::getInstance()->getSettings()->allowedPlatforms;

if (!$allowedSections || (is_array($allowedSections) && in_array($data['sectionId'], $allowedSections))) {
/** @var Entry|null $entry */
$entry = Craft::$app->getEntries()->getEntryById($data['id']);

if (null !== $entry && trim((string)$entry->url)) {
$entry = Craft::$app->getEntries()->getEntryById($data['id']);
if (null !== $entry && trim((string) $entry->url)) {

$btns = [];
$encodedUrl = urlencode(trim($entry->url));
$encodedUrl = urlencode(trim((string) $entry->url));

$links = [
'facebook' => '<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=' . $encodedUrl . '">Facebook</a>',
'twitter' => '<a target="_blank" href="https://twitter.com/intent/tweet?text=' . $encodedUrl . '">Twitter</a>',
'linkedin' => '<a target="_blank" href="https://www.linkedin.com/shareArticle?title=' . $encodedUrl . '&summary=&source=&url=' . $encodedUrl . '">LinkedIn</a>',
// 'pinterest' => '<a target="_blank" href="http://pinterest.com/pin/create/link/?media=aaa&url=' . $encodedUrl . '">Pinterest</a>',
'linkedin' => '<a target="_blank" href="https://www.linkedin.com/sharing/share-offsite/?url=' . $encodedUrl . '">LinkedIn</a>',
//'pinterest' => '<a target="_blank" href="http://pinterest.com/pin/create/link/?media=aaa&url=' . $encodedUrl . '">Pinterest</a>',
'mix' => '<a target="_blank" href="https://mix.com/add?url=' . $encodedUrl . '">Mix</a>',
'tumblr' => '<a target="_blank" href="https://www.tumblr.com/share/link?' . $encodedUrl . '">Tumblr</a>',
'reddit' => '<a target="_blank" href="http://www.reddit.com/submit?url=' . $encodedUrl . '">Reddit</a>',
Expand All @@ -72,6 +77,6 @@ public function actionUrl()
}
}

Craft::$app->end();
throw new NotFoundHttpException();
}
}
19 changes: 5 additions & 14 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 3.x
* SimpleSharing plugin for Craft CMS 4.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand All @@ -10,9 +10,6 @@

namespace wrav\simplesharing\models;

use wrav\simplesharing;

use Craft;
use craft\base\Model;

/**
Expand All @@ -24,14 +21,8 @@ class Settings extends Model
{
// Public Properties
// =========================================================================

/**
* @var string
*/
public $allowedSections;

/**
* @var string
*/
public $allowedPlatforms;
/** @var string[] $allowedSections */
/** @var string[] $allowedPlatforms */
public array $allowedSections = [];
public array $allowedPlatforms = [];
}
2 changes: 1 addition & 1 deletion src/templates/settings.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{#
/**
* SimpleSharing plugin for Craft CMS 3.x
* SimpleSharing plugin for Craft CMS 4.x
*
* SimpleSharing Settings.twig
*
Expand Down
2 changes: 1 addition & 1 deletion src/translations/en/simple-sharing.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SimpleSharing plugin for Craft CMS 3.x
* SimpleSharing plugin for Craft CMS 4.x
*
* Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
*
Expand Down
Loading

0 comments on commit a4a2f81

Please sign in to comment.