Files
laravel-manager-packagist/src/Modules/Sharing/SharingModule.php
T
2026-12-06 12:46:53 +00:00

87 lines
3.2 KiB
PHP

<?php
namespace IriksIT\Manager\Modules\Sharing;
use IriksIT\Manager\Modules\BaseModule;
use IriksIT\Manager\Support\Names;
use IriksIT\Manager\Support\Permission;
use IriksIT\Manager\Support\Tier;
/**
* Sharing posts on social networks: connect the owner's account of a platform (OAuth) and post a published post there with one
* button. LinkedIn comes with the package; a site adds its own platforms with `manager.sharing.platforms`
* (a class that implements `Contracts\Sharer`). Off by default.
*/
class SharingModule extends BaseModule
{
public function key(): string
{
return 'sharing';
}
public function tier(): string
{
return Tier::ADDON;
}
public function label(): string
{
return 'Sharing';
}
public function enabledByDefault(): bool
{
return false;
}
public function requires(): array
{
return ['posts'];
}
public function tables(): array
{
return ['social_connections', 'post_shares'];
}
public function permissions(): array
{
return [
new Permission('sharing.view', 'See where posts are shared', 'Sharing'),
new Permission('sharing.publish', 'Share a post on a social network', 'Sharing', needs: ['sharing.view']),
new Permission('sharing.manage', 'Connect and disconnect the accounts of the social networks', 'Sharing', needs: ['sharing.view']),
];
}
public function navigation(): array
{
return [['label' => 'Sharing', 'section' => 'Visitors', 'route' => Names::route('sharing.index'), 'permission' => 'sharing.view']];
}
/** @return array<string, array<string, mixed>> what the settings screen can change */
public function settings(): array
{
return [
'manager.sharing.live' => ['label' => 'Post for real', 'type' => 'toggle', 'group' => 'Sharing', 'help' => 'Off: a share is written down as a dry run and nothing is sent. Keep it off on a test site.', 'env' => 'MANAGER_SHARING_LIVE'],
'manager.sharing.post_url' => ['label' => 'Address of a post', 'type' => 'url', 'group' => 'Sharing', 'sensitive' => true, 'help' => 'Where a post lives on the site, with {slug} for its address, for example https://example.test/blog/{slug}', 'env' => 'MANAGER_SHARING_POST_URL'],
'manager.sharing.linkedin.client_id' => ['label' => 'LinkedIn: client id', 'type' => 'text', 'group' => 'Sharing', 'sensitive' => true, 'env' => 'MANAGER_LINKEDIN_CLIENT_ID'],
'manager.sharing.linkedin.client_secret' => ['label' => 'LinkedIn: client secret', 'type' => 'secret', 'group' => 'Sharing', 'env' => 'MANAGER_LINKEDIN_CLIENT_SECRET'],
];
}
public function actions(): array
{
return [
'sharing.connect' => ['Went to a social network to connect an account'],
'sharing.callback' => ['Connected an account of a social network'],
'sharing.disconnect' => ['Disconnected an account of a social network'],
'sharing.share' => ['Shared a post on a social network'],
];
}
public function views(): array
{
return ['sharing.index' => 'Opened the sharing screen', 'sharing.post' => 'Opened how a post is shared'];
}
}