Compare commits

..

2 Commits

Author SHA1 Message Date
gitea-actions[bot] 3f33afd6b2 chore(version): auto-bump patch 01.08.11-dev [skip ci] 2026-06-27 19:51:30 +00:00
jmiller 8700b46e13 feat(#132): add PHPUnit test suite with unit tests
Universal: Auto Version Bump / Version Bump (push) Successful in 8s
Add phpunit.xml.dist, bootstrap, and PSR-4 autoload config. Tests:
- PreviewHelper: 14 tests for platform mockup rendering (skipped when
  PreviewHelper not yet merged from feature/156 branch)
- ServiceIconHelper: 14 tests for icon mapping and HTML rendering
- ServiceInterfaceContract: 7 reflection tests verifying interface
  methods and types, plus 15 plugin implementation checks (skipped
  outside Joomla runtime)

21 tests pass immediately, 29 skip gracefully.

Authored-by: Moko Consulting
2026-06-27 14:50:34 -05:00
66 changed files with 545 additions and 719 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
# FILE INFORMATION # FILE INFORMATION
# DEFGROUP: Gitea.Workflow # DEFGROUP: Gitea.Workflow
# INGROUP: mokocli.Automation # INGROUP: mokocli.Automation
# VERSION: 01.08.17 # VERSION: 01.08.11
# BRIEF: Auto-create feature branch when an issue is opened # BRIEF: Auto-create feature branch when an issue is opened
name: "Universal: Issue Branch" name: "Universal: Issue Branch"
+1 -15
View File
@@ -1,20 +1,6 @@
# Changelog # Changelog
## [Unreleased] ## [Unreleased]
### Added
- **Instagram carousel**: Multi-image/video posts via Meta carousel container flow (up to 10 items)
- **Instagram Reels**: Short-form video publishing via REELS media type
- **Instagram Stories**: Image and video story publishing via STORIES media type
- **Instagram alt text**: Alt text support for image containers
- **Nostr plugin**: Full NIP-01 WebSocket relay publishing with BIP-340 Schnorr signatures (pure PHP, requires ext-gmp)
- **Nostr**: Publishes kind-1 text note events to multiple relays with automatic failover
- **Nostr**: Raw WebSocket client using stream_socket_client (no external dependencies)
- **Nostr**: Public key derivation and event signing via secp256k1 elliptic curve math
- **Threads carousel**: Support up to 20-item carousel posts via Threads API multi-container flow
- **Threads polls**: Poll creation support via poll_options parameter (2-4 options)
- **Threads spoiler tags**: Content warning / spoiler flag support for Threads posts
- **Threads text-only optimization**: Simplified single-step flow for text-only posts without media
### Fixed ### Fixed
- Webservices plugin Joomla 6 compatibility — `onBeforeApiRoute` receives `BeforeApiRouteEvent` object, extract router via `$event->getRouter()` - Webservices plugin Joomla 6 compatibility — `onBeforeApiRoute` receives `BeforeApiRouteEvent` object, extract router via `$event->getRouter()`
@@ -82,7 +68,7 @@
## [01.03.00] --- 2026-06-21 ## [01.03.00] --- 2026-06-21
<!-- VERSION: 01.08.17 --> <!-- VERSION: 01.08.11 -->
All notable changes to MokoSuiteCross will be documented in this file. All notable changes to MokoSuiteCross will be documented in this file.
+1 -1
View File
@@ -1,6 +1,6 @@
# MokoSuiteCross # MokoSuiteCross
<!-- VERSION: 01.08.17 --> <!-- VERSION: 01.08.11 -->
Cross-posting Joomla content to social media, email marketing, and chat platforms for Joomla 5/6. Cross-posting Joomla content to social media, email marketing, and chat platforms for Joomla 5/6.
+15 -1
View File
@@ -15,9 +15,23 @@
"php": ">=8.1" "php": ">=8.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.7", "squizlabs/php_codesniffer": "^3.7",
"phpstan/phpstan": "^1.10", "phpstan/phpstan": "^1.10",
"joomla/coding-standards": "^4.0" "joomla/coding-standards": "dev-3.x-dev"
},
"autoload": {
"psr-4": {
"Joomla\\Component\\MokoSuiteCross\\Administrator\\": "source/packages/com_mokosuitecross/src/",
"Joomla\\Component\\MokoSuiteCross\\Site\\": "source/packages/com_mokosuitecross/site/src/",
"Joomla\\Plugin\\Content\\MokoSuiteCross\\": "source/packages/plg_content_mokosuitecross/src/",
"Joomla\\Plugin\\System\\MokoSuiteCross\\": "source/packages/plg_system_mokosuitecross/src/"
}
},
"autoload-dev": {
"psr-4": {
"MokoSuiteCross\\Tests\\": "tests/"
}
}, },
"config": { "config": {
"sort-packages": true "sort-packages": true
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>source/packages/com_mokosuitecross/src</directory>
<directory>source/packages/plg_content_mokosuitecross/src</directory>
<directory>source/packages/plg_system_mokosuitecross/src</directory>
</include>
</source>
</phpunit>
@@ -3,6 +3,6 @@
; License: GPL-3.0-or-later ; License: GPL-3.0-or-later
PKG_MOKOSUITECROSS="MokoSuiteCross" PKG_MOKOSUITECROSS="MokoSuiteCross"
PKG_MOKOSUITECROSS_DESCRIPTION="Cross-post Joomla articles to 38 platforms including Facebook, Instagram, X/Twitter, LinkedIn, Threads, Mastodon, Bluesky, Nostr, TikTok, YouTube, Pinterest, Reddit, Medium, Telegram, Discord, Slack, Teams, Mailchimp, SendGrid, Brevo, and more. Features scheduled posting, template placeholders, UTM tagging, link shortening, caption rotation, and per-article service selection." PKG_MOKOSUITECROSS_DESCRIPTION="Cross-posting Joomla content to social media, email marketing, and chat platforms. Automatically publish articles to Facebook, X/Twitter, LinkedIn, Mastodon, Bluesky, Mailchimp, Telegram, Discord, and Slack."
PKG_MOKOSUITECROSS_PHP_VERSION_ERROR="MokoSuiteCross requires PHP %s or later." PKG_MOKOSUITECROSS_PHP_VERSION_ERROR="MokoSuiteCross requires PHP %s or later."
PKG_MOKOSUITECROSS_MIGRATION_DETECTED="Perfect Publisher Pro detected! Navigate to Components → MokoSuiteCross → Dashboard to migrate your settings." PKG_MOKOSUITECROSS_MIGRATION_DETECTED="Perfect Publisher Pro detected! Navigate to Components → MokoSuiteCross → Dashboard to migrate your settings."
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="component" method="upgrade"> <extension type="component" method="upgrade">
<name>com_mokosuitecross</name> <name>com_mokosuitecross</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1 +0,0 @@
/* 01.08.12 — no schema changes */
@@ -1 +0,0 @@
/* 01.08.13 — no schema changes */
@@ -1 +0,0 @@
/* 01.08.14 — no schema changes */
@@ -1 +0,0 @@
/* 01.08.15 — no schema changes */
@@ -1 +0,0 @@
/* 01.08.16 — no schema changes */
@@ -1 +0,0 @@
/* 01.08.17 — no schema changes */
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="content" method="upgrade"> <extension type="plugin" group="content" method="upgrade">
<name>Content - MokoSuiteCross</name> <name>Content - MokoSuiteCross</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - ActivityPub (Fediverse)</name> <name>MokoSuiteCross - ActivityPub (Fediverse)</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Google Blogger</name> <name>MokoSuiteCross - Google Blogger</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Bluesky</name> <name>MokoSuiteCross - Bluesky</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Brevo (Sendinblue)</name> <name>MokoSuiteCross - Brevo (Sendinblue)</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Constant Contact</name> <name>MokoSuiteCross - Constant Contact</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - ConvertKit</name> <name>MokoSuiteCross - ConvertKit</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Dev.to</name> <name>MokoSuiteCross - Dev.to</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Discord</name> <name>MokoSuiteCross - Discord</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Facebook / Meta</name> <name>MokoSuiteCross - Facebook / Meta</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Ghost</name> <name>MokoSuiteCross - Ghost</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Google Business Profile</name> <name>MokoSuiteCross - Google Business Profile</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Google Chat</name> <name>MokoSuiteCross - Google Chat</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Hashnode</name> <name>MokoSuiteCross - Hashnode</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Instagram</name> <name>MokoSuiteCross - Instagram</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-06-23</creationDate> <creationDate>2026-06-23</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -20,7 +20,7 @@ use Joomla\Event\SubscriberInterface;
/** /**
* Instagram service plugin for MokoSuiteCross. * Instagram service plugin for MokoSuiteCross.
* *
* Uses the Meta Content Publishing API -- a 2-step flow: * Uses the Meta Content Publishing API a 2-step flow:
* 1. Create a media container via POST /{ig_user_id}/media * 1. Create a media container via POST /{ig_user_id}/media
* 2. Publish the container via POST /{ig_user_id}/media_publish * 2. Publish the container via POST /{ig_user_id}/media_publish
*/ */
@@ -50,128 +50,24 @@ class InstagramService extends CMSPlugin implements SubscriberInterface, MokoSui
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Missing access token or Instagram account ID.']]; return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Missing access token or Instagram account ID.']];
} }
if (empty($media)) { // Step 1: Create media container
$containerUrl = 'https://graph.facebook.com/v19.0/' . urlencode($accountId) . '/media';
$containerData = [
'caption' => mb_substr($message, 0, 2200),
'access_token' => $token,
];
// Attach image if provided
if (!empty($media[0])) {
$containerData['image_url'] = $media[0];
} else {
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Instagram requires at least one image or video.']]; return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Instagram requires at least one image or video.']];
} }
$caption = mb_substr($message, 0, 2200); $ch = curl_init($containerUrl);
$mediaType = $params['media_type'] ?? '';
$altText = $params['alt_text'] ?? '';
if ($mediaType === 'reels') {
return $this->publishReels($accountId, $token, $caption, $media[0]);
}
if ($mediaType === 'stories') {
return $this->publishStories($accountId, $token, $media[0]);
}
if (\count($media) > 1) {
return $this->publishCarousel($accountId, $token, $caption, $media, $altText);
}
$fields = [
'caption' => $caption,
'image_url' => $media[0],
];
if ($altText !== '') {
$fields['alt_text'] = $altText;
}
$container = $this->createContainer($accountId, $token, $fields);
if (!$container['success']) {
return ['success' => false, 'platform_post_id' => '', 'response' => $container['data'] ?? ['error' => $container['error']]];
}
return $this->publishContainer($accountId, $token, $container['id']);
}
private function publishCarousel(string $accountId, string $token, string $caption, array $media, string $altText): array
{
$media = \array_slice($media, 0, 10);
$childIds = [];
foreach ($media as $url) {
$fields = ['is_carousel_item' => 'true'];
if ($this->isVideoUrl($url)) {
$fields['video_url'] = $url;
} else {
$fields['image_url'] = $url;
if ($altText !== '') {
$fields['alt_text'] = $altText;
}
}
$child = $this->createContainer($accountId, $token, $fields);
if (!$child['success']) {
return ['success' => false, 'platform_post_id' => '', 'response' => $child['data'] ?? ['error' => $child['error']]];
}
$childIds[] = $child['id'];
}
$carousel = $this->createContainer($accountId, $token, [
'media_type' => 'CAROUSEL',
'caption' => $caption,
'children' => implode(',', $childIds),
]);
if (!$carousel['success']) {
return ['success' => false, 'platform_post_id' => '', 'response' => $carousel['data'] ?? ['error' => $carousel['error']]];
}
return $this->publishContainer($accountId, $token, $carousel['id']);
}
private function publishReels(string $accountId, string $token, string $caption, string $videoUrl): array
{
$container = $this->createContainer($accountId, $token, [
'media_type' => 'REELS',
'video_url' => $videoUrl,
'caption' => $caption,
]);
if (!$container['success']) {
return ['success' => false, 'platform_post_id' => '', 'response' => $container['data'] ?? ['error' => $container['error']]];
}
return $this->publishContainer($accountId, $token, $container['id']);
}
private function publishStories(string $accountId, string $token, string $mediaUrl): array
{
$fields = ['media_type' => 'STORIES'];
if ($this->isVideoUrl($mediaUrl)) {
$fields['video_url'] = $mediaUrl;
} else {
$fields['image_url'] = $mediaUrl;
}
$container = $this->createContainer($accountId, $token, $fields);
if (!$container['success']) {
return ['success' => false, 'platform_post_id' => '', 'response' => $container['data'] ?? ['error' => $container['error']]];
}
return $this->publishContainer($accountId, $token, $container['id']);
}
private function createContainer(string $accountId, string $token, array $fields): array
{
$url = 'https://graph.facebook.com/v19.0/' . urlencode($accountId) . '/media';
$fields['access_token'] = $token;
$ch = curl_init($url);
curl_setopt_array($ch, [ curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($fields), CURLOPT_POSTFIELDS => http_build_query($containerData),
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30, CURLOPT_TIMEOUT => 30,
]); ]);
@@ -179,34 +75,36 @@ class InstagramService extends CMSPlugin implements SubscriberInterface, MokoSui
$response = curl_exec($ch); $response = curl_exec($ch);
if ($response === false) { if ($response === false) {
$curlError = curl_error($ch);
curl_close($ch);
return ['success' => false, 'error' => 'Connection error: ' . $curlError];
}
$curlError = curl_error($ch);
curl_close($ch);
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Connection error: ' . $curlError]];
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); curl_close($ch);
$data = json_decode($response, true) ?: []; $data = json_decode($response, true) ?: [];
if ($httpCode < 200 || $httpCode >= 300 || empty($data['id'])) { if ($httpCode < 200 || $httpCode >= 300 || empty($data['id'])) {
return ['success' => false, 'error' => $data['error']['message'] ?? 'Container creation failed', 'data' => $data]; return ['success' => false, 'platform_post_id' => '', 'response' => $data];
} }
return ['success' => true, 'id' => $data['id'], 'data' => $data]; $containerId = $data['id'];
}
private function publishContainer(string $accountId, string $token, string $containerId): array // Step 2: Publish the container
{ $publishUrl = 'https://graph.facebook.com/v19.0/' . urlencode($accountId) . '/media_publish';
$url = 'https://graph.facebook.com/v19.0/' . urlencode($accountId) . '/media_publish'; $publishData = [
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query([
'creation_id' => $containerId, 'creation_id' => $containerId,
'access_token' => $token, 'access_token' => $token,
]), ];
$ch = curl_init($publishUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($publishData),
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30, CURLOPT_TIMEOUT => 30,
]); ]);
@@ -214,11 +112,14 @@ class InstagramService extends CMSPlugin implements SubscriberInterface, MokoSui
$response = curl_exec($ch); $response = curl_exec($ch);
if ($response === false) { if ($response === false) {
$curlError = curl_error($ch);
curl_close($ch);
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Connection error: ' . $curlError]];
}
$curlError = curl_error($ch);
curl_close($ch);
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Connection error: ' . $curlError]];
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); curl_close($ch);
@@ -231,11 +132,6 @@ class InstagramService extends CMSPlugin implements SubscriberInterface, MokoSui
return ['success' => false, 'platform_post_id' => '', 'response' => $data]; return ['success' => false, 'platform_post_id' => '', 'response' => $data];
} }
private function isVideoUrl(string $url): bool
{
return (bool) preg_match('/\.(mp4|mov|avi|wmv|webm)(\?|$)/i', $url);
}
public function validateCredentials(array $credentials): array public function validateCredentials(array $credentials): array
{ {
$token = $this->resolveCredential($credentials, 'access_token'); $token = $this->resolveCredential($credentials, 'access_token');
@@ -254,9 +150,13 @@ class InstagramService extends CMSPlugin implements SubscriberInterface, MokoSui
$response = curl_exec($ch); $response = curl_exec($ch);
if ($response === false) { if ($response === false) {
$curlError = curl_error($ch); $curlError = curl_error($ch);
curl_close($ch); curl_close($ch);
return ['valid' => false, 'message' => 'Connection error: ' . $curlError, 'account_name' => '']; return ['valid' => false, 'message' => 'Connection error: ' . $curlError, 'account_name' => ''];
} }
curl_close($ch); curl_close($ch);
@@ -283,6 +183,6 @@ class InstagramService extends CMSPlugin implements SubscriberInterface, MokoSui
public function getSupportedMediaTypes(): array public function getSupportedMediaTypes(): array
{ {
return ['image', 'video', 'carousel', 'reels', 'stories']; return ['image', 'video'];
} }
} }
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - LinkedIn</name> <name>MokoSuiteCross - LinkedIn</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Mailchimp</name> <name>MokoSuiteCross - Mailchimp</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Mastodon</name> <name>MokoSuiteCross - Mastodon</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Matrix / Element</name> <name>MokoSuiteCross - Matrix / Element</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Medium</name> <name>MokoSuiteCross - Medium</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - MokoSuiteCalendar Events</name> <name>MokoSuiteCross - MokoSuiteCalendar Events</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - MokoSuiteGallery</name> <name>MokoSuiteCross - MokoSuiteGallery</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,2 +1,2 @@
PLG_MOKOSUITECROSS_NOSTR="MokoSuiteCross - Nostr" PLG_MOKOSUITECROSS_NOSTR="MokoSuiteCross - Nostr"
PLG_MOKOSUITECROSS_NOSTR_DESCRIPTION="Cross-post Joomla articles to Nostr relays via NIP-01 WebSocket protocol. Requires PHP ext-gmp for secp256k1 Schnorr signing." PLG_MOKOSUITECROSS_NOSTR_DESCRIPTION="Cross-post Joomla articles to Nostr."
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Nostr</name> <name>MokoSuiteCross - Nostr</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -20,18 +20,12 @@ use Joomla\Event\SubscriberInterface;
/** /**
* Nostr service plugin for MokoSuiteCross. * Nostr service plugin for MokoSuiteCross.
* *
* Publishes kind-1 text note events to NIP-01 WebSocket relays. * Nostr uses NIP-01 WebSocket relays for event publishing.
* Uses BIP-340 Schnorr signatures over secp256k1 (requires ext-gmp). * This is a stub — full WebSocket implementation is deferred.
* * Events are signed with the private key and sent to configured relays.
* Credentials: private_key (64-char hex nsec), relays (comma-separated wss:// URLs)
*/ */
class NostrService extends CMSPlugin implements SubscriberInterface, MokoSuiteCrossServiceInterface class NostrService extends CMSPlugin implements SubscriberInterface, MokoSuiteCrossServiceInterface
{ {
private const SECP256K1_P = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F';
private const SECP256K1_N = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141';
private const SECP256K1_GX = '79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798';
private const SECP256K1_GY = '483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8';
public static function getSubscribedEvents(): array public static function getSubscribedEvents(): array
{ {
return ['onMokoSuiteCrossGetServices' => 'onMokoSuiteCrossGetServices']; return ['onMokoSuiteCrossGetServices' => 'onMokoSuiteCrossGetServices'];
@@ -49,10 +43,6 @@ class NostrService extends CMSPlugin implements SubscriberInterface, MokoSuiteCr
public function publish(string $message, array $media, array $credentials, array $params): array public function publish(string $message, array $media, array $credentials, array $params): array
{ {
if (!extension_loaded('gmp')) {
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'PHP ext-gmp is required for Nostr signing.']];
}
$privateKey = $credentials['private_key'] ?? ''; $privateKey = $credentials['private_key'] ?? '';
$relays = $credentials['relays'] ?? ''; $relays = $credentials['relays'] ?? '';
@@ -60,393 +50,48 @@ class NostrService extends CMSPlugin implements SubscriberInterface, MokoSuiteCr
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Missing private key or relay URLs.']]; return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Missing private key or relay URLs.']];
} }
$privateKey = strtolower(trim($privateKey)); // Nostr requires WebSocket connections to relays (wss://).
// Full NIP-01 event signing and relay publishing is not yet implemented.
if (!preg_match('/^[0-9a-f]{64}$/', $privateKey)) {
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Private key must be 64 hex characters.']];
}
$pubkey = $this->getPublicKey($privateKey);
$event = $this->createEvent($pubkey, $message);
$event['sig'] = $this->schnorrSign($event['id'], $privateKey);
$relayList = array_filter(array_map('trim', explode(',', $relays)));
$lastError = '';
$published = false;
foreach ($relayList as $relayUrl) {
$result = $this->publishToRelay($relayUrl, $event);
if ($result['success']) {
$published = true;
break;
}
$lastError = $result['error'];
}
if (!$published) {
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'All relays failed. Last: ' . $lastError]];
}
return [ return [
'success' => true, 'success' => false,
'platform_post_id' => $event['id'], 'platform_post_id' => '',
'response' => ['event_id' => $event['id'], 'relay' => $relayUrl ?? ''], 'response' => ['error' => 'Nostr WebSocket relay publishing is not yet implemented. This service will be available in a future release.'],
]; ];
} }
public function validateCredentials(array $credentials): array public function validateCredentials(array $credentials): array
{ {
if (!extension_loaded('gmp')) { $privateKey = $credentials['private_key'] ?? '';
return ['valid' => false, 'message' => 'PHP ext-gmp is required for Nostr.', 'account_name' => ''];
}
$privateKey = strtolower(trim($credentials['private_key'] ?? ''));
$relays = $credentials['relays'] ?? ''; $relays = $credentials['relays'] ?? '';
if (empty($privateKey)) { if (empty($privateKey)) {
return ['valid' => false, 'message' => 'Private key is required.', 'account_name' => '']; return ['valid' => false, 'message' => 'Private key is required.', 'account_name' => ''];
} }
if (!preg_match('/^[0-9a-f]{64}$/', $privateKey)) {
return ['valid' => false, 'message' => 'Private key must be 64 hex characters.', 'account_name' => ''];
}
if (empty($relays)) { if (empty($relays)) {
return ['valid' => false, 'message' => 'At least one relay URL is required.', 'account_name' => '']; return ['valid' => false, 'message' => 'At least one relay URL is required.', 'account_name' => ''];
} }
// Validate that relay URLs look like WebSocket URLs
$relayList = array_filter(array_map('trim', explode(',', $relays))); $relayList = array_filter(array_map('trim', explode(',', $relays)));
$valid = true;
foreach ($relayList as $relay) { foreach ($relayList as $relay) {
if (!str_starts_with($relay, 'wss://') && !str_starts_with($relay, 'ws://')) { if (!str_starts_with($relay, 'wss://') && !str_starts_with($relay, 'ws://')) {
$valid = false;
break;
}
}
if (!$valid) {
return ['valid' => false, 'message' => 'Relay URLs must start with wss:// or ws://.', 'account_name' => '']; return ['valid' => false, 'message' => 'Relay URLs must start with wss:// or ws://.', 'account_name' => ''];
} }
}
$pubkey = $this->getPublicKey($privateKey); return ['valid' => true, 'message' => 'Credentials configured (' . count($relayList) . ' relay(s))', 'account_name' => 'Nostr'];
$npub = substr($pubkey, 0, 16) . '...';
return ['valid' => true, 'message' => count($relayList) . ' relay(s) configured', 'account_name' => 'npub:' . $npub];
} }
public function getSupportedMediaTypes(): array public function getSupportedMediaTypes(): array
{ {
return []; return [];
} }
// -- NIP-01 event creation --
private function createEvent(string $pubkey, string $content, int $kind = 1, array $tags = []): array
{
$createdAt = time();
$serialized = json_encode([0, $pubkey, $createdAt, $kind, $tags, $content], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$id = hash('sha256', $serialized);
return [
'id' => $id,
'pubkey' => $pubkey,
'created_at' => $createdAt,
'kind' => $kind,
'tags' => $tags,
'content' => $content,
'sig' => '',
];
}
// -- WebSocket relay publishing --
private function publishToRelay(string $relayUrl, array $event): array
{
$parsed = parse_url($relayUrl);
if (!$parsed || !isset($parsed['host'])) {
return ['success' => false, 'error' => 'Invalid relay URL'];
}
$scheme = $parsed['scheme'] ?? 'wss';
$host = $parsed['host'];
$port = $parsed['port'] ?? ($scheme === 'wss' ? 443 : 80);
$path = $parsed['path'] ?? '/';
$useTls = ($scheme === 'wss');
$address = ($useTls ? 'tls://' : 'tcp://') . $host . ':' . $port;
$context = stream_context_create(['ssl' => ['verify_peer' => true, 'verify_peer_name' => true]]);
$socket = @stream_socket_client($address, $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);
if (!$socket) {
return ['success' => false, 'error' => "Connection failed: {$errstr} ({$errno})"];
}
stream_set_timeout($socket, 10);
// WebSocket upgrade handshake
$wsKey = base64_encode(random_bytes(16));
$handshake = "GET {$path} HTTP/1.1\r\n"
. "Host: {$host}\r\n"
. "Upgrade: websocket\r\n"
. "Connection: Upgrade\r\n"
. "Sec-WebSocket-Key: {$wsKey}\r\n"
. "Sec-WebSocket-Version: 13\r\n"
. "\r\n";
fwrite($socket, $handshake);
$response = '';
while (($line = fgets($socket)) !== false) {
$response .= $line;
if (trim($line) === '') {
break;
}
}
if (strpos($response, '101') === false) {
fclose($socket);
return ['success' => false, 'error' => 'WebSocket upgrade failed'];
}
// Send EVENT message
$payload = json_encode(['EVENT', $event], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$this->wsWrite($socket, $payload);
// Read OK response (with timeout)
$reply = $this->wsRead($socket);
fclose($socket);
if ($reply === null) {
return ['success' => false, 'error' => 'No response from relay'];
}
$decoded = json_decode($reply, true);
if (!is_array($decoded) || ($decoded[0] ?? '') !== 'OK') {
$msg = is_array($decoded) ? ($decoded[3] ?? $decoded[2] ?? 'Unknown error') : 'Invalid response';
return ['success' => false, 'error' => (string) $msg];
}
// ["OK", event_id, true/false, message]
$accepted = $decoded[2] ?? false;
if (!$accepted) {
return ['success' => false, 'error' => $decoded[3] ?? 'Relay rejected event'];
}
return ['success' => true, 'error' => ''];
}
private function wsWrite($socket, string $data): void
{
$len = strlen($data);
$frame = chr(0x81); // text frame, FIN bit set
$mask = random_bytes(4);
if ($len < 126) {
$frame .= chr($len | 0x80); // mask bit set
} elseif ($len < 65536) {
$frame .= chr(126 | 0x80) . pack('n', $len);
} else {
$frame .= chr(127 | 0x80) . pack('J', $len);
}
$frame .= $mask;
for ($i = 0; $i < $len; $i++) {
$frame .= $data[$i] ^ $mask[$i % 4];
}
fwrite($socket, $frame);
}
private function wsRead($socket): ?string
{
$header = fread($socket, 2);
if ($header === false || strlen($header) < 2) {
return null;
}
$len = ord($header[1]) & 0x7F;
if ($len === 126) {
$ext = fread($socket, 2);
$len = unpack('n', $ext)[1];
} elseif ($len === 127) {
$ext = fread($socket, 8);
$len = unpack('J', $ext)[1];
}
$masked = (ord($header[1]) & 0x80) !== 0;
$mask = $masked ? fread($socket, 4) : '';
$data = '';
while (strlen($data) < $len) {
$chunk = fread($socket, $len - strlen($data));
if ($chunk === false) {
break;
}
$data .= $chunk;
}
if ($masked) {
for ($i = 0; $i < strlen($data); $i++) {
$data[$i] = $data[$i] ^ $mask[$i % 4];
}
}
return $data;
}
// -- BIP-340 Schnorr signature over secp256k1 --
private function getPublicKey(string $privateKeyHex): string
{
$d = gmp_init($privateKeyHex, 16);
$G = [gmp_init(self::SECP256K1_GX, 16), gmp_init(self::SECP256K1_GY, 16)];
$point = $this->ecMultiply($G, $d);
return str_pad(gmp_strval($point[0], 16), 64, '0', STR_PAD_LEFT);
}
private function schnorrSign(string $messageHex, string $privateKeyHex): string
{
$p = gmp_init(self::SECP256K1_P, 16);
$n = gmp_init(self::SECP256K1_N, 16);
$G = [gmp_init(self::SECP256K1_GX, 16), gmp_init(self::SECP256K1_GY, 16)];
$d = gmp_init($privateKeyHex, 16);
$P = $this->ecMultiply($G, $d);
$px = str_pad(gmp_strval($P[0], 16), 64, '0', STR_PAD_LEFT);
// BIP-340: if P.y is odd, negate d
if (gmp_testbit($P[1], 0)) {
$d = gmp_sub($n, $d);
}
$dBytes = hex2bin(str_pad(gmp_strval($d, 16), 64, '0', STR_PAD_LEFT));
$auxRand = random_bytes(32);
$t = $dBytes ^ $this->taggedHash('BIP0340/aux', $auxRand);
$pxBytes = hex2bin($px);
$msgBytes = hex2bin($messageHex);
$rand = $this->taggedHash('BIP0340/nonce', $t . $pxBytes . $msgBytes);
$k0 = gmp_mod(gmp_init(bin2hex($rand), 16), $n);
if (gmp_cmp($k0, 0) === 0) {
return str_repeat('00', 64);
}
$R = $this->ecMultiply($G, $k0);
$k = gmp_testbit($R[1], 0) ? gmp_sub($n, $k0) : $k0;
$rx = str_pad(gmp_strval($R[0], 16), 64, '0', STR_PAD_LEFT);
$rxBytes = hex2bin($rx);
$eHash = $this->taggedHash('BIP0340/challenge', $rxBytes . $pxBytes . $msgBytes);
$e = gmp_mod(gmp_init(bin2hex($eHash), 16), $n);
$s = gmp_mod(gmp_add($k, gmp_mul($e, $d)), $n);
return $rx . str_pad(gmp_strval($s, 16), 64, '0', STR_PAD_LEFT);
}
private function taggedHash(string $tag, string $data): string
{
$tagHash = hash('sha256', $tag, true);
return hash('sha256', $tagHash . $tagHash . $data, true);
}
// -- secp256k1 elliptic curve arithmetic --
private function ecMultiply(array $point, \GMP $scalar): array
{
$result = null;
$addend = $point;
$n = gmp_init(self::SECP256K1_N, 16);
$scalar = gmp_mod($scalar, $n);
while (gmp_cmp($scalar, 0) > 0) {
if (gmp_testbit($scalar, 0)) {
$result = $result === null ? $addend : $this->ecAdd($result, $addend);
}
$addend = $this->ecDouble($addend);
$scalar = gmp_div_q($scalar, 2);
}
return $result;
}
private function ecAdd(array $p1, array $p2): array
{
$prime = gmp_init(self::SECP256K1_P, 16);
if (gmp_cmp($p1[0], $p2[0]) === 0 && gmp_cmp($p1[1], $p2[1]) === 0) {
return $this->ecDouble($p1);
}
$dx = gmp_mod(gmp_sub($p2[0], $p1[0]), $prime);
if (gmp_cmp($dx, 0) < 0) {
$dx = gmp_add($dx, $prime);
}
$dy = gmp_mod(gmp_sub($p2[1], $p1[1]), $prime);
if (gmp_cmp($dy, 0) < 0) {
$dy = gmp_add($dy, $prime);
}
$slope = gmp_mod(gmp_mul($dy, gmp_invert($dx, $prime)), $prime);
$x3 = gmp_mod(gmp_sub(gmp_sub(gmp_mul($slope, $slope), $p1[0]), $p2[0]), $prime);
$y3 = gmp_mod(gmp_sub(gmp_mul($slope, gmp_sub($p1[0], $x3)), $p1[1]), $prime);
if (gmp_cmp($x3, 0) < 0) {
$x3 = gmp_add($x3, $prime);
}
if (gmp_cmp($y3, 0) < 0) {
$y3 = gmp_add($y3, $prime);
}
return [$x3, $y3];
}
private function ecDouble(array $point): array
{
$prime = gmp_init(self::SECP256K1_P, 16);
// secp256k1 has a=0, so slope = 3*x^2 / (2*y)
$num = gmp_mod(gmp_mul(3, gmp_mul($point[0], $point[0])), $prime);
$denom = gmp_mod(gmp_mul(2, $point[1]), $prime);
if (gmp_cmp($denom, 0) < 0) {
$denom = gmp_add($denom, $prime);
}
$slope = gmp_mod(gmp_mul($num, gmp_invert($denom, $prime)), $prime);
$x3 = gmp_mod(gmp_sub(gmp_mul($slope, $slope), gmp_mul(2, $point[0])), $prime);
$y3 = gmp_mod(gmp_sub(gmp_mul($slope, gmp_sub($point[0], $x3)), $point[1]), $prime);
if (gmp_cmp($x3, 0) < 0) {
$x3 = gmp_add($x3, $prime);
}
if (gmp_cmp($y3, 0) < 0) {
$y3 = gmp_add($y3, $prime);
}
return [$x3, $y3];
}
} }
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Ntfy Push Notifications</name> <name>MokoSuiteCross - Ntfy Push Notifications</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Pinterest</name> <name>MokoSuiteCross - Pinterest</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Reddit</name> <name>MokoSuiteCross - Reddit</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - RSS Feed</name> <name>MokoSuiteCross - RSS Feed</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - SendGrid</name> <name>MokoSuiteCross - SendGrid</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Slack</name> <name>MokoSuiteCross - Slack</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Microsoft Teams</name> <name>MokoSuiteCross - Microsoft Teams</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Telegram</name> <name>MokoSuiteCross - Telegram</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -17,13 +17,15 @@ use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\MokoSuiteCross\Administrator\Service\MokoSuiteCrossServiceInterface; use Joomla\Component\MokoSuiteCross\Administrator\Service\MokoSuiteCrossServiceInterface;
use Joomla\Event\SubscriberInterface; use Joomla\Event\SubscriberInterface;
/**
* Threads (Meta) service plugin for MokoSuiteCross.
*
* Uses the Threads Publishing API — a 2-step flow:
* 1. Create a media container via POST /{user_id}/threads
* 2. Publish the container via POST /{user_id}/threads_publish
*/
class ThreadsService extends CMSPlugin implements SubscriberInterface, MokoSuiteCrossServiceInterface class ThreadsService extends CMSPlugin implements SubscriberInterface, MokoSuiteCrossServiceInterface
{ {
private const API_BASE = 'https://graph.threads.net/v1.0/';
private const MAX_CAROUSEL_ITEMS = 20;
private const MAX_POLL_OPTIONS = 4;
private const MIN_POLL_OPTIONS = 2;
public static function getSubscribedEvents(): array public static function getSubscribedEvents(): array
{ {
return ['onMokoSuiteCrossGetServices' => 'onMokoSuiteCrossGetServices']; return ['onMokoSuiteCrossGetServices' => 'onMokoSuiteCrossGetServices'];
@@ -48,104 +50,25 @@ class ThreadsService extends CMSPlugin implements SubscriberInterface, MokoSuite
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Missing access token or user ID.']]; return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Missing access token or user ID.']];
} }
$text = mb_substr($message, 0, 500); // Step 1: Create media container
$media = array_filter($media); $containerUrl = 'https://graph.threads.net/v1.0/' . urlencode($userId) . '/threads';
if (\count($media) > 1) {
return $this->publishCarousel($text, $media, $userId, $token, $params);
}
return $this->publishSinglePost($text, $media, $userId, $token, $params);
}
private function publishSinglePost(string $text, array $media, string $userId, string $token, array $params): array
{
$containerUrl = self::API_BASE . urlencode($userId) . '/threads';
$containerData = [ $containerData = [
'text' => $text, 'text' => mb_substr($message, 0, 500),
'access_token' => $token, 'access_token' => $token,
]; ];
// Attach image if provided
if (!empty($media[0])) { if (!empty($media[0])) {
$mediaType = $this->detectMediaType($media[0]); $containerData['media_type'] = 'IMAGE';
$containerData['media_type'] = $mediaType; $containerData['image_url'] = $media[0];
$containerData[$mediaType === 'VIDEO' ? 'video_url' : 'image_url'] = $media[0];
} else { } else {
$containerData['media_type'] = 'TEXT'; $containerData['media_type'] = 'TEXT';
} }
$this->applyPollOptions($containerData, $params); $ch = curl_init($containerUrl);
$this->applySpoilerFlag($containerData, $params);
$result = $this->apiPost($containerUrl, $containerData);
if (!$result['success']) {
return $result;
}
return $this->publishContainer($userId, $token, $result['response']['id']);
}
private function publishCarousel(string $text, array $media, string $userId, string $token, array $params): array
{
$items = \array_slice($media, 0, self::MAX_CAROUSEL_ITEMS);
$childIds = [];
foreach ($items as $url) {
$mediaType = $this->detectMediaType($url);
$childData = [
'is_carousel_item' => 'true',
'media_type' => $mediaType,
'access_token' => $token,
];
$childData[$mediaType === 'VIDEO' ? 'video_url' : 'image_url'] = $url;
$childUrl = self::API_BASE . urlencode($userId) . '/threads';
$result = $this->apiPost($childUrl, $childData);
if (!$result['success']) {
return $result;
}
$childIds[] = $result['response']['id'];
}
$carouselData = [
'media_type' => 'CAROUSEL',
'children' => implode(',', $childIds),
'text' => $text,
'access_token' => $token,
];
$this->applySpoilerFlag($carouselData, $params);
$carouselUrl = self::API_BASE . urlencode($userId) . '/threads';
$result = $this->apiPost($carouselUrl, $carouselData);
if (!$result['success']) {
return $result;
}
return $this->publishContainer($userId, $token, $result['response']['id']);
}
private function publishContainer(string $userId, string $token, string $containerId): array
{
$publishUrl = self::API_BASE . urlencode($userId) . '/threads_publish';
$publishData = [
'creation_id' => $containerId,
'access_token' => $token,
];
return $this->apiPost($publishUrl, $publishData);
}
private function apiPost(string $url, array $data): array
{
$ch = curl_init($url);
curl_setopt_array($ch, [ curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($data), CURLOPT_POSTFIELDS => http_build_query($containerData),
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30, CURLOPT_TIMEOUT => 30,
]); ]);
@@ -153,60 +76,61 @@ class ThreadsService extends CMSPlugin implements SubscriberInterface, MokoSuite
$response = curl_exec($ch); $response = curl_exec($ch);
if ($response === false) { if ($response === false) {
$curlError = curl_error($ch); $curlError = curl_error($ch);
curl_close($ch); curl_close($ch);
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Connection error: ' . $curlError]]; return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Connection error: ' . $curlError]];
}
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); curl_close($ch);
$responseData = json_decode($response, true) ?: []; $data = json_decode($response, true) ?: [];
if ($httpCode >= 200 && $httpCode < 300 && !empty($responseData['id'])) { if ($httpCode < 200 || $httpCode >= 300 || empty($data['id'])) {
return ['success' => true, 'platform_post_id' => (string) $responseData['id'], 'response' => $responseData]; return ['success' => false, 'platform_post_id' => '', 'response' => $data];
} }
return ['success' => false, 'platform_post_id' => '', 'response' => $responseData]; $containerId = $data['id'];
// Step 2: Publish the container
$publishUrl = 'https://graph.threads.net/v1.0/' . urlencode($userId) . '/threads_publish';
$publishData = [
'creation_id' => $containerId,
'access_token' => $token,
];
$ch = curl_init($publishUrl);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($publishData),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($ch);
if ($response === false) {
$curlError = curl_error($ch);
curl_close($ch);
return ['success' => false, 'platform_post_id' => '', 'response' => ['error' => 'Connection error: ' . $curlError]];
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true) ?: [];
if ($httpCode >= 200 && $httpCode < 300 && !empty($data['id'])) {
return ['success' => true, 'platform_post_id' => (string) $data['id'], 'response' => $data];
} }
private function applyPollOptions(array &$data, array $params): void return ['success' => false, 'platform_post_id' => '', 'response' => $data];
{
$options = $params['poll_options'] ?? [];
if (empty($options) || !\is_array($options)) {
return;
}
$options = \array_slice($options, 0, self::MAX_POLL_OPTIONS);
if (\count($options) < self::MIN_POLL_OPTIONS) {
return;
}
$data['poll'] = json_encode(['options' => array_values($options)]);
}
private function applySpoilerFlag(array &$data, array $params): void
{
if (!empty($params['spoiler'])) {
$data['spoiler'] = 'true';
}
}
private function detectMediaType(string $url): string
{
$path = strtolower(parse_url($url, PHP_URL_PATH) ?? '');
$videoExtensions = ['.mp4', '.mov', '.avi', '.wmv', '.webm'];
foreach ($videoExtensions as $ext) {
if (str_ends_with($path, $ext)) {
return 'VIDEO';
}
}
return 'IMAGE';
} }
public function validateCredentials(array $credentials): array public function validateCredentials(array $credentials): array
@@ -218,7 +142,7 @@ class ThreadsService extends CMSPlugin implements SubscriberInterface, MokoSuite
return ['valid' => false, 'message' => 'Access token and user ID are required.', 'account_name' => '']; return ['valid' => false, 'message' => 'Access token and user ID are required.', 'account_name' => ''];
} }
$ch = curl_init(self::API_BASE . urlencode($userId) . '?fields=username&access_token=' . urlencode($token)); $ch = curl_init('https://graph.threads.net/v1.0/' . urlencode($userId) . '?fields=username&access_token=' . urlencode($token));
curl_setopt_array($ch, [ curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10, CURLOPT_TIMEOUT => 10,
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Threads (Meta)</name> <name>MokoSuiteCross - Threads (Meta)</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - TikTok</name> <name>MokoSuiteCross - TikTok</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Tumblr</name> <name>MokoSuiteCross - Tumblr</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - X / Twitter</name> <name>MokoSuiteCross - X / Twitter</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Generic Webhook</name> <name>MokoSuiteCross - Generic Webhook</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - WhatsApp Business</name> <name>MokoSuiteCross - WhatsApp Business</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - WordPress</name> <name>MokoSuiteCross - WordPress</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokosuitecross" method="upgrade"> <extension type="plugin" group="mokosuitecross" method="upgrade">
<name>MokoSuiteCross - Youtube</name> <name>MokoSuiteCross - Youtube</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-06-23</creationDate> <creationDate>2026-06-23</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="system" method="upgrade"> <extension type="plugin" group="system" method="upgrade">
<name>System - MokoSuiteCross</name> <name>System - MokoSuiteCross</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="system" method="upgrade"> <extension type="plugin" group="system" method="upgrade">
<name>System - MokoSuiteCross Events</name> <name>System - MokoSuiteCross Events</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="system" method="upgrade"> <extension type="plugin" group="system" method="upgrade">
<name>System - MokoSuiteCross Gallery</name> <name>System - MokoSuiteCross Gallery</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade"> <extension type="plugin" group="task" method="upgrade">
<name>Task - MokoSuiteCross Queue Processor</name> <name>Task - MokoSuiteCross Queue Processor</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="webservices" method="upgrade"> <extension type="plugin" group="webservices" method="upgrade">
<name>Web Services - MokoSuiteCross</name> <name>Web Services - MokoSuiteCross</name>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
+1 -1
View File
@@ -2,7 +2,7 @@
<extension type="package" method="upgrade"> <extension type="package" method="upgrade">
<name>MokoSuiteCross</name> <name>MokoSuiteCross</name>
<packagename>mokosuitecross</packagename> <packagename>mokosuitecross</packagename>
<version>01.08.17</version> <version>01.08.11</version>
<creationDate>2026-05-28</creationDate> <creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author> <author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail> <authorEmail>hello@mokoconsulting.tech</authorEmail>
+128
View File
@@ -0,0 +1,128 @@
<?php
/**
* @package MokoSuiteCross
* @subpackage Tests
* @author Moko Consulting <hello@mokoconsulting.tech>
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
* SPDX-License-Identifier: GPL-3.0-or-later
*/
namespace MokoSuiteCross\Tests\Unit\Helper;
use Joomla\Component\MokoSuiteCross\Administrator\Helper\PreviewHelper;
use PHPUnit\Framework\Attributes\RequiresMethod;
use PHPUnit\Framework\TestCase;
#[RequiresMethod(PreviewHelper::class, 'render')]
class PreviewHelperTest extends TestCase
{
public function testRenderTwitterContainsCharCount(): void
{
$html = PreviewHelper::render('twitter', 'Test Title', 'Hello world', 'https://example.com', '', 'Author');
$this->assertStringContainsString('11/280', $html);
}
public function testRenderTwitterEscapesHtml(): void
{
$html = PreviewHelper::render('twitter', '<script>alert(1)</script>', 'text', 'https://example.com');
$this->assertStringNotContainsString('<script>', $html);
$this->assertStringContainsString('&lt;script&gt;', $html);
}
public function testRenderFacebookContainsAuthor(): void
{
$html = PreviewHelper::render('facebook', 'My Article', 'Intro text here', 'https://example.com', '', 'John Doe');
$this->assertStringContainsString('John Doe', $html);
$this->assertStringContainsString('My Article', $html);
}
public function testRenderMastodonContainsCharCount(): void
{
$html = PreviewHelper::render('mastodon', 'Title', 'Post text', 'https://example.com', '', 'Author');
$this->assertStringContainsString('9/500', $html);
}
public function testRenderBlueskyContainsCharCount(): void
{
$html = PreviewHelper::render('bluesky', 'Title', 'A bluesky post', 'https://example.com', '', 'Author');
$this->assertStringContainsString('14/300', $html);
}
public function testRenderLinkedInContainsAuthor(): void
{
$html = PreviewHelper::render('linkedin', 'Article', 'Text', 'https://example.com', '', 'Jane Smith');
$this->assertStringContainsString('Jane Smith', $html);
}
public function testRenderTelegramDoesNotShowAuthor(): void
{
$html = PreviewHelper::render('telegram', 'Article', 'Message text', 'https://example.com');
$this->assertStringContainsString('Message text', $html);
$this->assertStringContainsString('Article', $html);
}
public function testRenderWithImageIncludesImgTag(): void
{
$html = PreviewHelper::render('twitter', 'Title', 'Text', 'https://example.com', 'https://example.com/image.jpg', 'Author');
$this->assertStringContainsString('<img src="https://example.com/image.jpg"', $html);
}
public function testRenderWithoutImageOmitsImgTag(): void
{
$html = PreviewHelper::render('twitter', 'Title', 'Text', 'https://example.com', '', 'Author');
$this->assertStringNotContainsString('<img', $html);
}
public function testRenderGenericPlatform(): void
{
$html = PreviewHelper::render('pinterest', 'Title', 'Text', 'https://example.com');
$this->assertStringContainsString('PINTEREST', $html);
$this->assertStringContainsString('Title', $html);
}
public function testGetSupportedPlatformsReturnsSix(): void
{
$platforms = PreviewHelper::getSupportedPlatforms();
$this->assertCount(6, $platforms);
$this->assertContains('twitter', $platforms);
$this->assertContains('facebook', $platforms);
$this->assertContains('mastodon', $platforms);
$this->assertContains('linkedin', $platforms);
$this->assertContains('bluesky', $platforms);
$this->assertContains('telegram', $platforms);
}
public function testRenderUsesTextWhenProvided(): void
{
$html = PreviewHelper::render('facebook', 'My Title', 'Custom intro text', 'https://example.com');
$this->assertStringContainsString('Custom intro text', $html);
}
public function testRenderFallsBackToTitleWhenTextEmpty(): void
{
$html = PreviewHelper::render('facebook', 'Fallback Title', '', 'https://example.com');
$this->assertMatchesRegularExpression('/Fallback Title.*Fallback Title/s', $html);
}
public function testImageUrlIsEscaped(): void
{
$html = PreviewHelper::render('twitter', 'Title', 'Text', 'https://example.com', 'https://example.com/img?a=1&b=2', 'Author');
$this->assertStringContainsString('https://example.com/img?a=1&amp;b=2', $html);
}
}
@@ -0,0 +1,69 @@
<?php
/**
* @package MokoSuiteCross
* @subpackage Tests
* @author Moko Consulting <hello@mokoconsulting.tech>
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
* SPDX-License-Identifier: GPL-3.0-or-later
*/
namespace MokoSuiteCross\Tests\Unit\Helper;
use Joomla\Component\MokoSuiteCross\Administrator\Helper\ServiceIconHelper;
use PHPUnit\Framework\TestCase;
class ServiceIconHelperTest extends TestCase
{
/**
* @dataProvider knownServiceTypesProvider
*/
public function testGetIconReturnsKnownIcon(string $serviceType, string $expectedIcon): void
{
$this->assertSame($expectedIcon, ServiceIconHelper::getIcon($serviceType));
}
public static function knownServiceTypesProvider(): array
{
return [
'facebook' => ['facebook', 'icon-facebook'],
'twitter' => ['twitter', 'icon-twitter'],
'linkedin' => ['linkedin', 'icon-linkedin'],
'mastodon' => ['mastodon', 'icon-globe'],
'bluesky' => ['bluesky', 'icon-cloud'],
'telegram' => ['telegram', 'icon-paper-plane'],
'discord' => ['discord', 'icon-headset'],
'slack' => ['slack', 'icon-hashtag'],
'mailchimp' => ['mailchimp', 'icon-envelope'],
'medium' => ['medium', 'icon-book'],
];
}
public function testGetIconReturnsFallbackForUnknownType(): void
{
$this->assertSame('icon-share-alt', ServiceIconHelper::getIcon('unknown_platform'));
}
public function testRenderIconOutputsSpanElement(): void
{
$html = ServiceIconHelper::renderIcon('facebook');
$this->assertSame('<span class="icon-facebook" aria-hidden="true"></span>', $html);
}
public function testRenderIconWithExtraClass(): void
{
$html = ServiceIconHelper::renderIcon('twitter', 'me-1 text-info');
$this->assertSame('<span class="icon-twitter me-1 text-info" aria-hidden="true"></span>', $html);
}
public function testRenderIconEscapesExtraClass(): void
{
$html = ServiceIconHelper::renderIcon('facebook', '"><script>');
$this->assertStringNotContainsString('<script>', $html);
$this->assertStringContainsString('&quot;&gt;&lt;script&gt;', $html);
}
}
@@ -0,0 +1,128 @@
<?php
/**
* @package MokoSuiteCross
* @subpackage Tests
* @author Moko Consulting <hello@mokoconsulting.tech>
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
* SPDX-License-Identifier: GPL-3.0-or-later
*/
namespace MokoSuiteCross\Tests\Unit\Service;
use Joomla\Component\MokoSuiteCross\Administrator\Service\MokoSuiteCrossServiceInterface;
use PHPUnit\Framework\TestCase;
class ServiceInterfaceContractTest extends TestCase
{
public function testInterfaceExists(): void
{
$this->assertTrue(interface_exists(MokoSuiteCrossServiceInterface::class));
}
public function testInterfaceDefinesRequiredMethods(): void
{
$reflection = new \ReflectionClass(MokoSuiteCrossServiceInterface::class);
$expectedMethods = [
'getServiceType',
'getServiceName',
'publish',
'validateCredentials',
'getMaxLength',
'supportsMedia',
'getSupportedMediaTypes',
];
foreach ($expectedMethods as $method) {
$this->assertTrue(
$reflection->hasMethod($method),
"Interface missing method: {$method}"
);
}
}
public function testGetServiceTypeReturnsString(): void
{
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'getServiceType');
$returnType = $method->getReturnType();
$this->assertNotNull($returnType);
$this->assertSame('string', $returnType->getName());
}
public function testPublishAcceptsCorrectParameters(): void
{
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'publish');
$params = $method->getParameters();
$this->assertCount(4, $params);
$this->assertSame('message', $params[0]->getName());
$this->assertSame('media', $params[1]->getName());
$this->assertSame('credentials', $params[2]->getName());
$this->assertSame('params', $params[3]->getName());
}
public function testPublishReturnsArray(): void
{
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'publish');
$returnType = $method->getReturnType();
$this->assertNotNull($returnType);
$this->assertSame('array', $returnType->getName());
}
public function testGetMaxLengthReturnsInt(): void
{
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'getMaxLength');
$returnType = $method->getReturnType();
$this->assertNotNull($returnType);
$this->assertSame('int', $returnType->getName());
}
public function testSupportsMediaReturnsBool(): void
{
$method = new \ReflectionMethod(MokoSuiteCrossServiceInterface::class, 'supportsMedia');
$returnType = $method->getReturnType();
$this->assertNotNull($returnType);
$this->assertSame('bool', $returnType->getName());
}
/**
* @dataProvider servicePluginClassProvider
*/
public function testServicePluginImplementsInterface(string $className): void
{
if (!class_exists($className)) {
$this->markTestSkipped("Class {$className} not autoloadable (needs Joomla runtime)");
}
$this->assertTrue(
is_subclass_of($className, MokoSuiteCrossServiceInterface::class),
"{$className} does not implement MokoSuiteCrossServiceInterface"
);
}
public static function servicePluginClassProvider(): array
{
$plugins = [
'facebook', 'twitter', 'linkedin', 'mastodon', 'bluesky',
'telegram', 'discord', 'slack', 'mailchimp', 'medium',
'instagram', 'youtube', 'threads', 'pinterest', 'reddit',
];
$cases = [];
foreach ($plugins as $plugin) {
$class = ucfirst($plugin);
$cases[$plugin] = [
"Joomla\\Plugin\\MokoSuiteCross\\{$class}\\Extension\\{$class}Service",
];
}
return $cases;
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
/**
* @package MokoSuiteCross
* @subpackage Tests
* @author Moko Consulting <hello@mokoconsulting.tech>
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
* SPDX-License-Identifier: GPL-3.0-or-later
*/
require_once __DIR__ . '/../vendor/autoload.php';
if (!defined('_JEXEC')) {
define('_JEXEC', 1);
}