Compare commits

..

18 Commits

Author SHA1 Message Date
gitea-actions[bot] e31552259d chore: update development channel 01.00.06-dev-dev [skip ci] 2026-05-28 18:42:22 +00:00
gitea-actions[bot] 97915d9f30 chore(version): auto-bump 01.00.06-dev-dev [skip ci] 2026-05-28 18:42:20 +00:00
Jonathan Miller 2872ae2b97 feat: low-priority issues #19-#22
Universal: Auto Version Bump / Version Bump (push) Successful in 4s
Update Server / Update Server (push) Successful in 13s
#19 Per-article cross-posting: Content plugin injects "Cross-Posting"
    fieldset into article editor via onContentPrepareForm. Dynamic
    checkbox list of all enabled services. Skip toggle. System plugin
    reads article attribs for mokojoomcross_services (array of service
    IDs) and mokojoomcross_skip (boolean). Unchecked = post to all.

#20 Analytics dashboard: Posts-by-service breakdown table with
    success rate column (color-coded). Top cross-posted articles
    list. DashboardModel methods: getServiceBreakdown(),
    getDailyTrend(), getTopArticles().

#21 OAuth flows: OAuthHelper with authorize URL generation (Facebook,
    LinkedIn, Twitter), PKCE for Twitter, code→token exchange, token
    storage in service credentials. OauthController with authorize
    and callback actions. Reads client ID/secret from plugin params.

#22 Wiki documentation: Services guide (all 9 platforms, default vs
    custom mode), REST API reference, Message Templates guide with
    examples per platform, Troubleshooting guide.

Authored-by: Moko Consulting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-28 13:42:07 -05:00
Moko Consulting 3664f547ee feat(workflows): append stability suffix to manifest versions [skip bump]
Universal: Auto Version Bump / Version Bump (push) Has been skipped
2026-05-28 13:41:34 -05:00
gitea-actions[bot] 6521edaab9 chore: update updates.xml (development: 01.00.05-dev-dev) [skip ci] 2026-05-28 18:36:31 +00:00
gitea-actions[bot] 3f6f286ffe chore(version): auto-bump patch 01.00.05-dev [skip ci] 2026-05-28 18:36:29 +00:00
Jonathan Miller 342f6fa3b8 feat: medium-priority issues #12-#18
Universal: Auto Version Bump / Version Bump (push) Successful in 4s
Update Server / Update updates.xml (push) Failing after 14s
#12 LinkedIn: plugin config form (OAuth client ID/secret, redirect URI)
#13 Mastodon: plugin config (default instance, visibility, hashtags)
#14 Bluesky: plugin config (default PDS URL, auto link cards)
#15 Mailchimp: plugin config (sender name/email, auto-send toggle)

#17 Template management: full CRUD with TemplatesController,
    TemplateController, TemplatesModel, TemplateModel, TemplateTable.
    List view with service type badges and body preview. Edit view
    with placeholder reference panel showing all 8 placeholders.
    Filter form with search, published, service_type filters.
    Added Templates submenu item and dashboard quick link.

#18 Logs: added filter form with level and search filters.

#16 WebServices: implementation already in place from scaffold,
    routes registered for posts and services CRUD.

Admin component now has 5 submenu items: Dashboard, Post Queue,
Services, Templates, Activity Logs.

Authored-by: Moko Consulting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-28 13:36:11 -05:00
gitea-actions[bot] 2f60ede713 chore: update updates.xml (development: 01.00.04-dev-dev) [skip ci] 2026-05-28 18:29:39 +00:00
gitea-actions[bot] 8fba003d64 chore(version): auto-bump patch 01.00.04-dev [skip ci] 2026-05-28 18:29:37 +00:00
Jonathan Miller 76dfa177c4 feat: high-priority issues #6-#10 — migration + service plugins
Universal: Auto Version Bump / Version Bump (push) Successful in 5s
Update Server / Update updates.xml (push) Failing after 13s
#6 PP Pro migration rewritten to read #__autotweet_channels table
   directly, mapping channeltype names to MokoJoomCross service types.
   Credential extraction per platform (Facebook page tokens, Twitter
   OAuth, Telegram bot tokens, Discord/Slack webhooks). Falls back to
   component params extraction when channel table doesn't exist.

#7 Facebook plugin: config form with default_page_access_token and
   default_page_id. resolveToken() reads from plugin params.

#8 Discord plugin: config form with default_webhook_url and
   embed_color. resolveWebhook() reads from plugin params.

#9 Twitter plugin: implementation already complete from scaffold.

#10 Slack plugin: config form with default_webhook_url.
    resolveWebhook() reads from plugin params.

All service plugins with universal bot support now store default
credentials in their own plugin params (Extensions → Plugins)
rather than component params. This keeps sensitive tokens scoped
to the plugin that uses them.

Authored-by: Moko Consulting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-28 13:29:22 -05:00
gitea-actions[bot] 4edc5a4765 chore: update updates.xml (development: 01.00.03-dev-dev) [skip ci] 2026-05-28 18:19:51 +00:00
gitea-actions[bot] a67a2a3c5d chore(version): auto-bump patch 01.00.03-dev [skip ci] 2026-05-28 18:19:49 +00:00
Jonathan Miller 9bbf2a74fb feat: queue processor — scheduled task + page-load fallback (#11)
Universal: Auto Version Bump / Version Bump (push) Successful in 5s
Update Server / Update updates.xml (push) Failing after 14s
Three-pronged queue processing:

1. Joomla Scheduled Task (preferred): New plg_task_mokojoomcross plugin
   registers "MokoJoomCross - Process Queue" task type. Admin creates
   a scheduled task in System → Scheduled Tasks with desired interval.

2. Page-load fallback: System plugin onAfterRender with configurable
   throttle interval. Runs on backend, frontend, or both. Small batch
   size (5) to avoid slowing page loads.

3. Both can run simultaneously — QueueProcessor uses DB-based lock
   to prevent concurrent execution (120s safety timeout).

Shared QueueProcessor helper handles:
- Queued post dispatch to service plugins
- Failed post retry with configurable max retries + delay
- Scheduled post firing (when scheduled_at <= now)
- Log cleanup based on retention period

Dashboard shows warning banner when page-load processing is active,
recommending switch to Joomla Scheduled Tasks for production.

Config options: queue_processing (scheduler/pageload/both),
pageload_client (admin/site/both), pageload_interval (seconds).

Authored-by: Moko Consulting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-28 13:19:31 -05:00
gitea-actions[bot] 04e7720268 chore: update updates.xml (development: 01.00.02-dev-dev) [skip ci] 2026-05-28 18:11:32 +00:00
gitea-actions[bot] d4c2ff00c3 chore(version): auto-bump patch 01.00.02-dev [skip ci] 2026-05-28 18:11:31 +00:00
Jonathan Miller 559b9ca30c feat: implement critical issues #1-#5
Universal: Auto Version Bump / Version Bump (push) Successful in 3s
Update Server / Update updates.xml (push) Failing after 9s
#1 Core engine: System plugin now dispatches to service plugins via
onMokoJoomCrossGetServices event, executes publish() immediately,
handles success/failure, duplicate guard prevents re-posting, listens
to both onContentAfterSave and onContentChangeState events. Template
rendering now resolves {category}, {author}, {date}, {fulltext}.

#3 Services CRUD: Admin list template with service type icons,
default/custom mode badges, publish toggle. Service edit form template.

#4 Post Queue: Admin list template with status badges (color-coded),
article title, service, message preview, platform post ID, error
messages, retry count, timestamps.

#5 Dashboard: Enhanced with recent activity feed from logs table,
migration controller action for PP Pro import, quick links sidebar.

#2 Telegram: Already implemented in scaffold, provider.php fixed.

Also fixes: All 9 service plugin provider.php files had broken
namespace references from bash heredoc escaping.

Authored-by: Moko Consulting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-28 13:11:20 -05:00
gitea-actions[bot] 7e4cce51de chore: update updates.xml (development: 01.00.01-dev-dev) [skip ci] 2026-05-28 17:55:19 +00:00
gitea-actions[bot] a2e2a60dea chore(version): auto-bump patch 01.00.01-dev [skip ci] 2026-05-28 17:55:17 +00:00
101 changed files with 4411 additions and 2466 deletions
-251
View File
@@ -1,251 +0,0 @@
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
# SPDX-License-Identifier: GPL-3.0-or-later
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Automation
# REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
# PATH: /.gitea/workflows/branch-protection.yml
# BRIEF: Apply standardised branch protection rules to all governed repositories
#
# +========================================================================+
# | BRANCH PROTECTION SETUP |
# +========================================================================+
# | |
# | Applies protection rules for: main, dev, rc, beta, alpha |
# | |
# | main — Require PR, block rejected reviews, no force push |
# | dev — Allow push, no force push, no delete |
# | rc — Allow push, no force push, no delete |
# | beta — Allow push, no force push, no delete |
# | alpha — Allow push, no force push, no delete |
# | |
# | jmiller has override authority on all branches. |
# | |
# +========================================================================+
name: Branch Protection Setup
on:
schedule:
- cron: '0 2 * * 1' # Weekly Monday 02:00 UTC
workflow_dispatch:
inputs:
dry_run:
description: 'Preview mode (no changes)'
required: false
type: boolean
default: false
repos:
description: 'Comma-separated repo names (empty = all governed repos)'
required: false
type: string
default: ''
env:
GITEA_URL: https://git.mokoconsulting.tech
GITEA_ORG: MokoConsulting
permissions:
contents: read
jobs:
protect:
name: Apply Branch Protection Rules
runs-on: ubuntu-latest
steps:
- name: Determine target repos
id: repos
env:
GA_TOKEN: ${{ secrets.GA_TOKEN }}
run: |
API="${GITEA_URL}/api/v1"
# Platform/standards/infra repos to exclude
EXCLUDE="gitea-org-config org-profile gitea-private .mokogitea-private MokoStandards moko-platform MokoTesting"
EXCLUDE="$EXCLUDE MokoStandards-Template-Client MokoStandards-Template-Dolibarr MokoStandards-Template-Generic MokoStandards-Template-Joomla MokoDoliProjTemplate"
if [ -n "${{ inputs.repos }}" ]; then
# User-specified repos
REPOS=$(echo "${{ inputs.repos }}" | tr ',' ' ')
else
# Fetch all org repos
PAGE=1
REPOS=""
while true; do
BATCH=$(curl -sS \
-H "Authorization: token ${GA_TOKEN}" \
"${API}/orgs/${GITEA_ORG}/repos?page=${PAGE}&limit=50" \
| jq -r '.[].name // empty')
[ -z "$BATCH" ] && break
REPOS="$REPOS $BATCH"
PAGE=$((PAGE + 1))
done
# Filter out excluded repos
FILTERED=""
for REPO in $REPOS; do
SKIP=false
for EX in $EXCLUDE; do
if [ "$REPO" = "$EX" ]; then
SKIP=true
break
fi
done
if [ "$SKIP" = "false" ]; then
FILTERED="$FILTERED $REPO"
fi
done
REPOS="$FILTERED"
fi
echo "repos=$REPOS" >> "$GITHUB_OUTPUT"
COUNT=$(echo "$REPOS" | wc -w)
echo "📋 Target repos (${COUNT}): $REPOS"
- name: Apply protection rules
env:
GA_TOKEN: ${{ secrets.GA_TOKEN }}
DRY_RUN: ${{ inputs.dry_run || 'false' }}
run: |
API="${GITEA_URL}/api/v1"
REPOS="${{ steps.repos.outputs.repos }}"
SUCCESS=0
FAILED=0
SKIPPED=0
# ── Rule definitions ──────────────────────────────────────
# Only the CI bot (jmiller token) can push directly.
# All human contributors must use PRs.
# Force push disabled on all branches.
RULE_MAIN='{
"rule_name": "main",
"enable_push": true,
"enable_push_whitelist": true,
"push_whitelist_usernames": ["jmiller"],
"enable_force_push": false,
"enable_force_push_allowlist": false,
"force_push_allowlist_usernames": [],
"enable_merge_whitelist": false,
"required_approvals": 0,
"dismiss_stale_approvals": true,
"block_on_rejected_reviews": true,
"block_on_outdated_branch": false,
"priority": 1
}'
RULE_DEV='{
"rule_name": "dev",
"enable_push": true,
"enable_push_whitelist": true,
"push_whitelist_usernames": ["jmiller"],
"enable_force_push": false,
"enable_force_push_allowlist": false,
"force_push_allowlist_usernames": [],
"enable_merge_whitelist": false,
"required_approvals": 0,
"block_on_rejected_reviews": false,
"priority": 2
}'
RULE_RC='{
"rule_name": "rc",
"enable_push": true,
"enable_push_whitelist": true,
"push_whitelist_usernames": ["jmiller"],
"enable_force_push": false,
"enable_force_push_allowlist": false,
"force_push_allowlist_usernames": [],
"enable_merge_whitelist": false,
"required_approvals": 0,
"block_on_rejected_reviews": false,
"priority": 3
}'
RULE_BETA='{
"rule_name": "beta",
"enable_push": true,
"enable_push_whitelist": true,
"push_whitelist_usernames": ["jmiller"],
"enable_force_push": false,
"enable_force_push_allowlist": false,
"force_push_allowlist_usernames": [],
"enable_merge_whitelist": false,
"required_approvals": 0,
"block_on_rejected_reviews": false,
"priority": 4
}'
RULE_ALPHA='{
"rule_name": "alpha",
"enable_push": true,
"enable_push_whitelist": true,
"push_whitelist_usernames": ["jmiller"],
"enable_force_push": false,
"enable_force_push_allowlist": false,
"force_push_allowlist_usernames": [],
"enable_merge_whitelist": false,
"required_approvals": 0,
"block_on_rejected_reviews": false,
"priority": 5
}'
RULES=("$RULE_MAIN" "$RULE_DEV" "$RULE_RC" "$RULE_BETA" "$RULE_ALPHA")
RULE_NAMES=("main" "dev" "rc" "beta" "alpha")
# ── Apply rules to each repo ──────────────────────────────
for REPO in $REPOS; do
echo ""
echo "═══ ${REPO} ═══"
for i in "${!RULES[@]}"; do
RULE="${RULES[$i]}"
NAME="${RULE_NAMES[$i]}"
if [ "$DRY_RUN" = "true" ]; then
echo " [DRY RUN] Would apply rule: ${NAME}"
SKIPPED=$((SKIPPED + 1))
continue
fi
# Delete existing rule if present (idempotent recreate)
ENCODED_NAME=$(echo "$NAME" | sed 's|/|%2F|g')
curl -sS -o /dev/null -w "" \
-X DELETE \
-H "Authorization: token ${GA_TOKEN}" \
"${API}/repos/${GITEA_ORG}/${REPO}/branch_protections/${ENCODED_NAME}" 2>/dev/null || true
# Create rule
RESPONSE=$(curl -sS -w "\n%{http_code}" \
-X POST \
-H "Authorization: token ${GA_TOKEN}" \
-H "Content-Type: application/json" \
-d "$RULE" \
"${API}/repos/${GITEA_ORG}/${REPO}/branch_protections")
HTTP=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | sed '$d')
if [ "$HTTP" = "201" ]; then
echo " ✅ ${NAME}"
SUCCESS=$((SUCCESS + 1))
else
echo " ❌ ${NAME} (HTTP ${HTTP}): $(echo "$BODY" | jq -r '.message // .' 2>/dev/null | head -1)"
FAILED=$((FAILED + 1))
fi
done
done
# ── Summary ───────────────────────────────────────────────
echo ""
echo "════════════════════════════════════════"
echo " ✅ Success: ${SUCCESS}"
echo " ❌ Failed: ${FAILED}"
echo " ⏭️ Skipped: ${SKIPPED}"
echo "════════════════════════════════════════"
if [ "$FAILED" -gt 0 ]; then
echo "::warning::${FAILED} rule(s) failed to apply"
fi
+1 -1
View File
@@ -4,7 +4,7 @@
<name>MokoJoomCross</name>
<org>MokoConsulting</org>
<description>Cross-posting Joomla content to social media, email marketing, and chat platforms</description>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<license spdx="GPL-3.0-or-later">GNU General Public License v3</license>
</identity>
<governance>
+91 -66
View File
@@ -1,66 +1,91 @@
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Release
# REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
# PATH: /.mokogitea/workflows/auto-bump.yml
# VERSION: 09.02.00
# BRIEF: Auto patch-bump version on every push to dev (skips merge commits)
name: "Universal: Auto Version Bump"
on:
push:
branches:
- dev
- rc
- 'feature/**'
- 'patch/**'
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
permissions:
contents: write
jobs:
bump:
name: Version Bump
runs-on: release
if: >-
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip bump]') &&
!startsWith(github.event.head_commit.message, 'Merge pull request')
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.MOKOGITEA_TOKEN }}
fetch-depth: 1
- name: Setup moko-platform tools
run: |
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
if [ -d "/opt/moko-platform/cli" ]; then
echo "MOKO_CLI=/opt/moko-platform/cli" >> "$GITHUB_ENV"
else
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/MokoConsulting/moko-platform.git" \
/tmp/moko-platform-api
cd /tmp/moko-platform-api && composer install --no-dev --no-interaction --quiet
echo "MOKO_CLI=/tmp/moko-platform-api/cli" >> "$GITHUB_ENV"
fi
- name: Bump version
run: |
php ${MOKO_CLI}/version_auto_bump.php \
--path . --branch "${GITHUB_REF_NAME}" \
--token "${{ secrets.MOKOGITEA_TOKEN }}" \
--repo-url "https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Release
# REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
# PATH: /.mokogitea/workflows/auto-bump.yml
# VERSION: 09.02.00
# BRIEF: Auto patch-bump version on every push to dev (skips merge commits)
name: "Universal: Auto Version Bump"
on:
push:
branches:
- dev
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
permissions:
contents: write
jobs:
bump:
name: Version Bump
runs-on: release
if: >-
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip bump]') &&
!startsWith(github.event.head_commit.message, 'Merge pull request')
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.GA_TOKEN }}
fetch-depth: 1
- name: Setup moko-platform tools
run: |
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
if [ -d "/opt/moko-platform/cli" ]; then
echo "MOKO_CLI=/opt/moko-platform/cli" >> "$GITHUB_ENV"
else
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/MokoConsulting/moko-platform.git" \
/tmp/moko-platform-api
cd /tmp/moko-platform-api && composer install --no-dev --no-interaction --quiet
echo "MOKO_CLI=/tmp/moko-platform-api/cli" >> "$GITHUB_ENV"
fi
- name: Bump version
run: |
BUMP=$(php ${MOKO_CLI}/version_bump.php --path . 2>&1) || true
echo "$BUMP"
VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null) || true
[ -z "$VERSION" ] && { echo "No version found — skipping"; exit 0; }
# Propagate to platform manifests
php ${MOKO_CLI}/version_set_platform.php \
--path . --version "$VERSION" --branch dev 2>/dev/null || true
php ${MOKO_CLI}/version_check.php --path . --fix 2>/dev/null || true
# Append -dev suffix to all manifest <version> tags
find . -maxdepth 4 -name "*.xml" ! -path "./.git/*" ! -path "./build/*" \
-exec grep -l "<version>${VERSION}</version>" {} \; 2>/dev/null | while read f; do
sed -i "s|<version>${VERSION}</version>|<version>${VERSION}-dev</version>|g" "$f"
done
VERSION="${VERSION}-dev"
# Commit if anything changed
if git diff --quiet && git diff --cached --quiet; then
echo "No version changes to commit"
exit 0
fi
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
git add -A
git commit -m "chore(version): auto-bump patch ${VERSION} [skip ci]" \
--author="gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>"
git push origin dev
echo "Bumped to ${VERSION}" >> $GITHUB_STEP_SUMMARY
+492 -285
View File
@@ -1,285 +1,492 @@
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Release
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/moko-platform
# PATH: /templates/workflows/universal/auto-release.yml.template
# VERSION: 05.00.00
# BRIEF: Universal build & release detects platform from manifest.xml
#
# +========================================================================+
# | UNIVERSAL BUILD & RELEASE PIPELINE |
# +========================================================================+
# | |
# | Reads manifest.xml (joomla|dolibarr|generic) to branch logic. |
# | |
# | Platform-specific: |
# | joomla: XML manifest, updates.xml, type-prefixed packages |
# | dolibarr: mod*.class.php, update.txt, dev version reset |
# | generic: README-only, no update stream |
# | |
# +========================================================================+
name: "Universal: Build & Release"
on:
pull_request:
types: [opened, closed]
branches:
- main
workflow_dispatch:
inputs:
action:
description: 'Action to perform'
required: false
type: choice
default: release
options:
- release
- promote-rc
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
GITEA_ORG: ${{ vars.GITEA_ORG || github.repository_owner }}
GITEA_REPO: ${{ vars.GITEA_REPO || github.event.repository.name }}
permissions:
contents: write
jobs:
# ── PR Opened → Rename branch to RC and build RC release ─────────────────────
promote-rc:
name: Promote to RC
runs-on: release
if: >-
(github.event.action == 'opened' && github.event.pull_request.merged != true) ||
(github.event_name == 'workflow_dispatch' && inputs.action == 'promote-rc')
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.MOKOGITEA_TOKEN }}
fetch-depth: 1
- name: Setup moko-platform tools
env:
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
run: |
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
# Always fetch latest CLI tools — never use stale cache from previous runs
rm -rf /tmp/moko-platform-api
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/moko-platform.git" \
/tmp/moko-platform-api
cd /tmp/moko-platform-api
composer install --no-dev --no-interaction --quiet
- name: Rename branch to rc
run: |
php /tmp/moko-platform-api/cli/branch_rename.php \
--from "${{ github.event.pull_request.head.ref || 'dev' }}" --to rc \
--token "${{ secrets.MOKOGITEA_TOKEN }}" \
--api-base "${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}" \
--pr "${{ github.event.pull_request.number }}"
- name: Checkout rc and configure git
run: |
git fetch origin rc
git checkout rc
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
git remote set-url origin "https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
- name: Publish RC release
run: |
php /tmp/moko-platform-api/cli/release_publish.php \
--path . --stability rc --bump minor --branch rc \
--token "${{ secrets.MOKOGITEA_TOKEN }}" \
--skip-update-stream
- name: Summary
if: always()
run: |
echo "## Promoted to Release Candidate" >> $GITHUB_STEP_SUMMARY
echo "Branch renamed to rc, minor bump, RC release built (updates.xml managed by Gitea Pages)" >> $GITHUB_STEP_SUMMARY
# ── Merged PR → Build & Release (or promote RC to stable) ────────────────────
release:
name: Build & Release Pipeline
runs-on: release
if: >-
github.event.pull_request.merged == true ||
(github.event_name == 'workflow_dispatch' && inputs.action != 'promote-rc')
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.MOKOGITEA_TOKEN }}
fetch-depth: 0
- name: Configure git for bot pushes
run: |
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
git remote set-url origin "https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
- name: Check for merge conflict markers
run: |
CONFLICTS=$(grep -rn '<<<<<<< \|>>>>>>> \|^=======$' --include='*.php' --include='*.xml' --include='*.css' --include='*.js' --include='*.json' --include='*.md' --include='*.yml' --include='*.yaml' --include='*.ini' --include='*.txt' . 2>/dev/null | grep -v '.git/' || true)
if [ -n "$CONFLICTS" ]; then
echo "::error::Merge conflict markers found — aborting release"
echo "## Release Blocked: Conflict Markers" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "$CONFLICTS" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "No conflict markers found"
- name: Setup moko-platform tools
env:
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_MIRROR_TOKEN }}"}}'
run: |
# Ensure PHP + Composer are available
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
# Always fetch latest CLI tools — never use stale cache from previous runs
rm -rf /tmp/moko-platform-api
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/moko-platform.git" \
/tmp/moko-platform-api
cd /tmp/moko-platform-api
composer install --no-dev --no-interaction --quiet
- name: "Publish stable release"
run: |
php /tmp/moko-platform-api/cli/release_publish.php \
--path . --stability stable --bump minor --branch main \
--token "${{ secrets.MOKOGITEA_TOKEN }}" \
--skip-update-stream
# -- STEP 9: Mirror to GitHub (stable only) --------------------------------
- name: "Step 9: Mirror release to GitHub"
if: >-
steps.version.outputs.skip != 'true' &&
secrets.GH_MIRROR_TOKEN != ''
continue-on-error: true
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
GH_REPO="${{ vars.GH_MIRROR_REPO || github.repository }}"
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_mirror.php \
--version "$VERSION" --tag "$RELEASE_TAG" \
--token "${{ secrets.MOKOGITEA_TOKEN }}" --api-base "$API_BASE" \
--gh-token "${{ secrets.GH_MIRROR_TOKEN }}" --gh-repo "$GH_REPO" \
--branch main 2>&1 || true
echo "GitHub mirror updated" >> $GITHUB_STEP_SUMMARY
# -- STEP 10: Sync main branch to GitHub mirror ----------------------------
- name: "Step 10: Push main to GitHub mirror"
if: >-
steps.version.outputs.skip != 'true' &&
secrets.GH_MIRROR_TOKEN != ''
continue-on-error: true
run: |
GH_REPO="${{ vars.GH_MIRROR_REPO || github.repository }}"
GH_ORG=$(echo "$GH_REPO" | cut -d/ -f1)
GH_NAME=$(echo "$GH_REPO" | cut -d/ -f2)
git remote add github "https://x-access-token:${{ secrets.GH_MIRROR_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git" 2>/dev/null || \
git remote set-url github "https://x-access-token:${{ secrets.GH_MIRROR_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git"
git fetch origin main --depth=1
git push github origin/main:refs/heads/main --force 2>/dev/null \
&& echo "main branch pushed to GitHub mirror" \
|| echo "WARNING: GitHub mirror push failed"
- name: "Step 11: Delete rc branch and recreate dev from main"
if: steps.version.outputs.skip != 'true'
continue-on-error: true
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
# Delete rc branch (ephemeral — created by promote-rc)
curl -sf -X DELETE -H "Authorization: token ${TOKEN}" \
"${API_BASE}/branches/rc" 2>/dev/null \
&& echo "Deleted rc branch" || echo "rc branch not found"
# Delete dev branch
curl -sf -X DELETE -H "Authorization: token ${TOKEN}" \
"${API_BASE}/branches/dev" 2>/dev/null && echo "Deleted dev branch"
# Recreate dev from main (now includes version bump + changelog promotion)
curl -sf -X POST -H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
"${API_BASE}/branches" \
-d '{"new_branch_name":"dev","old_branch_name":"main"}' 2>/dev/null && echo "Recreated dev from main"
echo "Pre-release branches cleaned, dev reset from main" >> $GITHUB_STEP_SUMMARY
- name: "Step 12: Create version branch from main"
if: steps.version.outputs.skip != 'true'
continue-on-error: true
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
BRANCH_NAME="version/${VERSION}"
MAIN_SHA=$(git rev-parse HEAD)
# Delete old version branch if it exists (same version re-release)
curl -sf -X DELETE -H "Authorization: token ${TOKEN}" "${API_BASE}/branches/${BRANCH_NAME}" 2>/dev/null && echo "Deleted old ${BRANCH_NAME}"
# Create version/XX.YY.ZZ from main
curl -sf -X POST -H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" "${API_BASE}/branches" -d "{\"new_branch_name\":\"${BRANCH_NAME}\",\"old_branch_name\":\"main\"}" 2>/dev/null && echo "Created ${BRANCH_NAME} from main (${MAIN_SHA})" || echo "WARNING: ${BRANCH_NAME} creation failed"
echo "Version branch created: ${BRANCH_NAME} (${MAIN_SHA})" >> $GITHUB_STEP_SUMMARY
# -- Dolibarr post-release: Reset dev version -----------------------------
- name: "Post-release: Reset dev version"
if: steps.version.outputs.skip != 'true'
continue-on-error: true
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/version_reset_dev.php \
--token "${{ secrets.MOKOGITEA_TOKEN }}" --api-base "${API_BASE}" \
--branch dev --path . 2>&1 || true
# -- Summary --------------------------------------------------------------
- name: Pipeline Summary
if: always()
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
PLATFORM="${{ steps.platform.outputs.platform }}"
if [ "${{ steps.version.outputs.skip }}" = "true" ]; then
echo "## Release Skipped" >> $GITHUB_STEP_SUMMARY
echo "No VERSION in README.md" >> $GITHUB_STEP_SUMMARY
elif [ "${{ steps.check.outputs.already_released }}" = "true" ]; then
echo "## Already Released — ${VERSION}" >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Build & Release Complete (${PLATFORM})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Step | Result |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Platform | \`${PLATFORM}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Branch | \`${{ steps.version.outputs.branch }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Tag | \`${{ steps.version.outputs.tag }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Release | [View](${GITEA_URL}/${GITEA_ORG}/${GITEA_REPO}/releases/tag/${{ steps.version.outputs.tag }}) |" >> $GITHUB_STEP_SUMMARY
fi
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Release
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/moko-platform
# PATH: /templates/workflows/universal/auto-release.yml.template
# VERSION: 05.00.00
# BRIEF: Universal build & release detects platform from manifest.xml
#
# +========================================================================+
# | UNIVERSAL BUILD & RELEASE PIPELINE |
# +========================================================================+
# | |
# | Reads manifest.xml (joomla|dolibarr|generic) to branch logic. |
# | |
# | Platform-specific: |
# | joomla: XML manifest, updates.xml, type-prefixed packages |
# | dolibarr: mod*.class.php, update.txt, dev version reset |
# | generic: README-only, no update stream |
# | |
# +========================================================================+
name: "Universal: Build & Release"
on:
pull_request:
types: [opened, closed]
branches:
- main
workflow_dispatch:
inputs:
action:
description: 'Action to perform'
required: false
type: choice
default: release
options:
- release
- promote-rc
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
GITEA_ORG: ${{ vars.GITEA_ORG || github.repository_owner }}
GITEA_REPO: ${{ vars.GITEA_REPO || github.event.repository.name }}
permissions:
contents: write
jobs:
# ── Draft PR → Promote highest pre-release to RC ─────────────────────────────
promote-rc:
name: Promote Pre-Release to RC
runs-on: release
if: >-
(github.event.action == 'opened' && github.event.pull_request.draft == true) ||
(github.event_name == 'workflow_dispatch' && inputs.action == 'promote-rc')
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.GA_TOKEN }}
fetch-depth: 1
- name: Setup moko-platform tools
env:
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
run: |
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/moko-platform.git" \
/tmp/moko-platform-api
cd /tmp/moko-platform-api
composer install --no-dev --no-interaction --quiet
- name: Promote to release-candidate
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_promote.php \
--from auto --to release-candidate \
--token "${{ secrets.GA_TOKEN }}" \
--api-base "${API_BASE}" \
--branch "${{ github.event.pull_request.head.ref || 'dev' }}"
- name: Cascade lesser channels
continue-on-error: true
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_cascade.php \
--stability release-candidate \
--token "${{ secrets.GA_TOKEN }}" \
--api-base "${API_BASE}"
- name: Summary
if: always()
run: |
echo "## Promoted to Release Candidate" >> $GITHUB_STEP_SUMMARY
echo "Draft PR opened — promoted highest pre-release to RC" >> $GITHUB_STEP_SUMMARY
# ── Merged PR → Build & Release (or promote RC to stable) ────────────────────
release:
name: Build & Release Pipeline
runs-on: release
if: >-
github.event.pull_request.merged == true ||
(github.event_name == 'workflow_dispatch' && inputs.action != 'promote-rc')
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
token: ${{ secrets.GA_TOKEN }}
fetch-depth: 0
- name: Setup moko-platform tools
env:
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
COMPOSER_AUTH: '{"github-oauth":{"github.com":"${{ secrets.GH_TOKEN }}"}}'
run: |
# Ensure PHP + Composer are available
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/moko-platform.git" \
/tmp/moko-platform-api
cd /tmp/moko-platform-api
composer install --no-dev --no-interaction --quiet
# -- PLATFORM DETECTION ---------------------------------------------------
- name: Detect platform
id: platform
run: |
php /tmp/moko-platform-api/cli/manifest_read.php --path . --github-output
MANIFEST=$(find . -maxdepth 3 -name "*.xml" ! -path "./.git/*" -exec grep -l '<extension' {} \; 2>/dev/null | head -1 || true)
MOD_FILE=$(find . -maxdepth 4 -name "mod*.class.php" ! -path "./.git/*" -exec grep -l 'extends DolibarrModules' {} \; 2>/dev/null | head -1 || true)
echo "manifest=${MANIFEST}" >> "$GITHUB_OUTPUT"
echo "mod_file=${MOD_FILE}" >> "$GITHUB_OUTPUT"
- name: "Step 1: Read version"
id: version
run: |
VERSION=$(php /tmp/moko-platform-api/cli/version_read.php --path .)
if [ -z "$VERSION" ]; then
echo "::error::No VERSION in README.md"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
MAJOR=$(echo "$VERSION" | cut -d. -f1)
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "release_tag=stable" >> "$GITHUB_OUTPUT"
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "branch=main" >> "$GITHUB_OUTPUT"
# -- CHECK FOR RC PROMOTION ------------------------------------------------
- name: "Check for RC release"
id: rc
if: steps.version.outputs.skip != 'true'
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
RC_JSON=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
"${API_BASE}/releases/tags/release-candidate" 2>/dev/null || echo "{}")
RC_ID=$(echo "$RC_JSON" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || true)
if [ -n "$RC_ID" ] && [ "$RC_ID" != "None" ] && [ "$RC_ID" != "" ]; then
echo "promote=true" >> "$GITHUB_OUTPUT"
echo "release_id=${RC_ID}" >> "$GITHUB_OUTPUT"
echo "::notice::RC release found (id: ${RC_ID}) — will promote to stable"
else
echo "promote=false" >> "$GITHUB_OUTPUT"
echo "::notice::No RC release — full build pipeline"
fi
- name: "Step 1b: Minor bump version"
id: bump
if: >-
steps.version.outputs.skip != 'true' &&
steps.rc.outputs.promote != 'true'
run: |
MOKO_API="/tmp/moko-platform-api/cli"
php ${MOKO_API}/version_bump.php --path . --minor 2>&1 || true
VERSION=$(php ${MOKO_API}/version_read.php --path .)
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Bumped to: ${VERSION}"
- name: Check if already released
if: steps.version.outputs.skip != 'true'
id: check
run: |
TAG="${{ steps.version.outputs.release_tag }}"
BRANCH="${{ steps.version.outputs.branch }}"
TAG_EXISTS=false
BRANCH_EXISTS=false
git rev-parse "$TAG" >/dev/null 2>&1 && TAG_EXISTS=true
git ls-remote --heads origin "$BRANCH" 2>/dev/null | grep -q "$BRANCH" && BRANCH_EXISTS=true
echo "tag_exists=$TAG_EXISTS" >> "$GITHUB_OUTPUT"
echo "branch_exists=$BRANCH_EXISTS" >> "$GITHUB_OUTPUT"
# Tag and branch may persist across patch releases — never skip
echo "already_released=false" >> "$GITHUB_OUTPUT"
# -- SANITY CHECKS -------------------------------------------------------
- name: "Sanity: Pre-release validation"
if: >-
steps.version.outputs.skip != 'true' &&
steps.check.outputs.already_released != 'true'
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
php /tmp/moko-platform-api/cli/release_validate.php \
--path . --version "$VERSION" --output-summary --github-output || true
# -- STEP 2: Create or update version/XX.YY archive branch ---------------
# Always runs — every version change on main archives to version/XX.YY
- name: "Step 2: Version archive branch"
if: steps.check.outputs.already_released != 'true'
run: |
BRANCH="${{ steps.version.outputs.branch }}"
IS_MINOR="${{ steps.version.outputs.is_minor }}"
PATCH="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
PATCH_NUM=$(echo "$PATCH" | awk -F. '{print $3}')
# Check if branch exists
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
git push origin HEAD:"$BRANCH" --force
echo "Updated archive branch: ${BRANCH} (patch ${PATCH_NUM})" >> $GITHUB_STEP_SUMMARY
else
git checkout -b "$BRANCH" 2>/dev/null || git checkout "$BRANCH"
git push origin "$BRANCH" --force
echo "Created archive branch: ${BRANCH}" >> $GITHUB_STEP_SUMMARY
fi
# -- STEP 3: Set platform version ----------------------------------------
- name: "Step 3: Set platform version"
if: >-
steps.version.outputs.skip != 'true' &&
steps.check.outputs.already_released != 'true'
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
php /tmp/moko-platform-api/cli/version_set_platform.php \
--path . --version "$VERSION" --branch main
# -- STEP 4: Update version badges ----------------------------------------
- name: "Step 4: Update version badges"
if: steps.version.outputs.skip != 'true'
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
php /tmp/moko-platform-api/cli/badge_update.php --path . --version "${VERSION}" 2>/dev/null || true
php /tmp/moko-platform-api/cli/version_check.php --path . --fix 2>/dev/null || true
# Step 5 (updates.xml) moved after Step 8 to include SHA-256 checksum
- name: Commit release changes
if: >-
steps.version.outputs.skip != 'true' &&
steps.check.outputs.already_released != 'true'
run: |
if git diff --quiet && git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
# Set push URL with token for branch-protected repos
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
git add -A
git commit -m "chore(release): build ${VERSION} [skip ci]" \
--author="gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>"
git push -u origin HEAD
# -- STEP 6: Create tag ---------------------------------------------------
- name: "Step 6: Create git tag"
if: >-
steps.version.outputs.skip != 'true'
run: |
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
# Only create the major release tag if it doesn't exist yet
if ! git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
git tag "$RELEASE_TAG"
git push origin "$RELEASE_TAG"
echo "Tag created: ${RELEASE_TAG}" >> $GITHUB_STEP_SUMMARY
else
echo "Tag ${RELEASE_TAG} already exists" >> $GITHUB_STEP_SUMMARY
fi
echo "Tag: ${TAG}" >> $GITHUB_STEP_SUMMARY
# -- STEP 7a: Promote RC to stable (skip build) ----------------------------
- name: "Step 7a: Promote RC to stable"
if: >-
steps.version.outputs.skip != 'true' &&
steps.rc.outputs.promote == 'true'
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_promote.php \
--from release-candidate --to stable \
--token "${{ secrets.GA_TOKEN }}" \
--api-base "${API_BASE}" \
--path . --branch main
echo "Promoted RC → stable (${VERSION})" >> $GITHUB_STEP_SUMMARY
# -- STEP 7b: Create or update Gitea Release (full build path) -------------
- name: "Step 7b: Gitea Release"
if: >-
steps.version.outputs.skip != 'true' &&
steps.rc.outputs.promote != 'true'
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_create.php \
--path . --version "$VERSION" --tag "$RELEASE_TAG" \
--token "${{ secrets.GA_TOKEN }}" --api-base "$API_BASE" \
--repo "${GITEA_REPO}" --branch main
echo "Release created: ${VERSION}" >> $GITHUB_STEP_SUMMARY
# -- STEP 8: Build packages and upload to release ----------------------------
- name: "Step 8: Build package and upload"
id: package
if: >-
steps.version.outputs.skip != 'true' &&
steps.rc.outputs.promote != 'true'
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_package.php \
--path . --version "$VERSION" --tag "$RELEASE_TAG" \
--token "${{ secrets.GA_TOKEN }}" --api-base "$API_BASE" \
--repo "${GITEA_REPO}" --output /tmp || true
# -- STEP 5: Write update stream (after build so SHA-256 is available) -----
- name: "Step 5: Write update stream"
if: steps.version.outputs.skip != 'true'
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
SHA256="${{ steps.package.outputs.sha256_zip }}"
# Fetch latest updates.xml from main so preserve logic has all channels
GA_TOKEN="${{ secrets.GA_TOKEN }}"
API="${GITEA_URL}/api/v1/repos/${{ github.repository }}"
curl -sf -H "Authorization: token ${GA_TOKEN}" \
"${API}/contents/updates.xml?ref=main" 2>/dev/null | \
python3 -c "import sys,json,base64; print(base64.b64decode(json.load(sys.stdin)['content']).decode())" \
> updates.xml 2>/dev/null || true
SHA_FLAG=""
[ -n "$SHA256" ] && SHA_FLAG="--sha ${SHA256}"
php /tmp/moko-platform-api/cli/updates_xml_build.php \
--path . --version "${VERSION}" --stability stable \
--gitea-url "${GITEA_URL}" --org "${GITEA_ORG}" --repo "${GITEA_REPO}" \
${SHA_FLAG} --github-output
# Commit updates.xml if changed
if ! git diff --quiet updates.xml 2>/dev/null; then
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
git add updates.xml
git commit -m "chore: update stable channel ${VERSION} [skip ci]" \
--author="gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>"
git push origin HEAD 2>&1 || true
fi
# -- STEP 8b: Update release description with changelog ----------------------
- name: "Step 8b: Update release body"
if: steps.version.outputs.skip != 'true'
continue-on-error: true
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
php /tmp/moko-platform-api/cli/release_body_update.php \
--path . --version "${VERSION}" --tag "${RELEASE_TAG}" \
--token "${{ secrets.GA_TOKEN }}" \
--gitea-url "${GITEA_URL}" --org "${GITEA_ORG}" --repo "${GITEA_REPO}" \
2>&1 || true
echo "Release body updated" >> $GITHUB_STEP_SUMMARY
# -- STEP 9: Mirror to GitHub (stable only) --------------------------------
- name: "Step 9: Mirror release to GitHub"
if: >-
steps.version.outputs.skip != 'true' &&
secrets.GH_TOKEN != ''
continue-on-error: true
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
RELEASE_TAG="${{ steps.version.outputs.release_tag }}"
GH_REPO="${{ vars.GH_MIRROR_REPO || github.repository }}"
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_mirror.php \
--version "$VERSION" --tag "$RELEASE_TAG" \
--token "${{ secrets.GA_TOKEN }}" --api-base "$API_BASE" \
--gh-token "${{ secrets.GH_TOKEN }}" --gh-repo "$GH_REPO" \
--branch main 2>&1 || true
echo "GitHub mirror updated" >> $GITHUB_STEP_SUMMARY
# -- STEP 10: Sync main branch to GitHub mirror ----------------------------
- name: "Step 10: Push main to GitHub mirror"
if: >-
steps.version.outputs.skip != 'true' &&
secrets.GH_TOKEN != ''
continue-on-error: true
run: |
GH_REPO="${{ vars.GH_MIRROR_REPO || github.repository }}"
GH_ORG=$(echo "$GH_REPO" | cut -d/ -f1)
GH_NAME=$(echo "$GH_REPO" | cut -d/ -f2)
git remote add github "https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git" 2>/dev/null || \
git remote set-url github "https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${GH_ORG}/${GH_NAME}.git"
git fetch origin main --depth=1
git push github origin/main:refs/heads/main --force 2>/dev/null \
&& echo "main branch pushed to GitHub mirror" \
|| echo "WARNING: GitHub mirror push failed"
# -- Clean up lesser pre-releases (cascade) ---------------------------------
# stable → deletes all | rc → beta,alpha,dev | beta → alpha,dev | alpha → dev
- name: "Delete lesser pre-release channels"
continue-on-error: true
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/release_cascade.php \
--stability stable \
--version "${VERSION}" \
--token "${{ secrets.GA_TOKEN }}" \
--api-base "${API_BASE}" 2>/dev/null || true
- name: "Step 11: Delete and recreate dev branch from main"
if: steps.version.outputs.skip != 'true'
continue-on-error: true
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
TOKEN="${{ secrets.GA_TOKEN }}"
# Delete dev branch
curl -sf -X DELETE -H "Authorization: token ${TOKEN}" \
"${API_BASE}/branches/dev" 2>/dev/null && echo "Deleted dev branch"
# Recreate dev from main (now includes version bump + changelog promotion)
curl -sf -X POST -H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
"${API_BASE}/branches" \
-d '{"new_branch_name":"dev","old_branch_name":"main"}' 2>/dev/null && echo "Recreated dev from main"
echo "Dev branch reset from main (keeps dev ahead after release)" >> $GITHUB_STEP_SUMMARY
# -- Dolibarr post-release: Reset dev version -----------------------------
- name: "Post-release: Reset dev version"
if: steps.version.outputs.skip != 'true'
continue-on-error: true
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php /tmp/moko-platform-api/cli/version_reset_dev.php \
--token "${{ secrets.GA_TOKEN }}" --api-base "${API_BASE}" \
--branch dev --path . 2>&1 || true
# -- Summary --------------------------------------------------------------
- name: Pipeline Summary
if: always()
run: |
VERSION="${{ steps.bump.outputs.version || steps.version.outputs.version }}"
PLATFORM="${{ steps.platform.outputs.platform }}"
if [ "${{ steps.version.outputs.skip }}" = "true" ]; then
echo "## Release Skipped" >> $GITHUB_STEP_SUMMARY
echo "No VERSION in README.md" >> $GITHUB_STEP_SUMMARY
elif [ "${{ steps.check.outputs.already_released }}" = "true" ]; then
echo "## Already Released — ${VERSION}" >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Build & Release Complete (${PLATFORM})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Step | Result |" >> $GITHUB_STEP_SUMMARY
echo "|------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Platform | \`${PLATFORM}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Branch | \`${{ steps.version.outputs.branch }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Tag | \`${{ steps.version.outputs.tag }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Release | [View](${GITEA_URL}/${GITEA_ORG}/${GITEA_REPO}/releases/tag/${{ steps.version.outputs.tag }}) |" >> $GITHUB_STEP_SUMMARY
fi
-48
View File
@@ -1,48 +0,0 @@
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: MokoStandards.Universal
# REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
# PATH: /.mokogitea/workflows/branch-cleanup.yml
# VERSION: 01.00.00
# BRIEF: Delete feature branches after PR merge
name: "Branch Cleanup"
on:
pull_request:
types: [closed]
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
cleanup:
name: Delete merged branch
runs-on: ubuntu-latest
if: >-
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref != 'dev' &&
github.event.pull_request.head.ref != 'main'
steps:
- name: Delete source branch
run: |
BRANCH="${{ github.event.pull_request.head.ref }}"
API="${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}/api/v1/repos/${{ github.repository }}/branches"
ENCODED=$(php -r "echo rawurlencode('${BRANCH}');")
STATUS=$(curl -sf -o /dev/null -w "%{http_code}" -X DELETE \
-H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
"${API}/${ENCODED}" 2>/dev/null || true)
if [ "$STATUS" = "204" ]; then
echo "Deleted branch: ${BRANCH}" >> $GITHUB_STEP_SUMMARY
elif [ "$STATUS" = "404" ]; then
echo "Branch already deleted: ${BRANCH}" >> $GITHUB_STEP_SUMMARY
else
echo "::warning::Failed to delete branch ${BRANCH} (HTTP ${STATUS})"
fi
+210 -7
View File
@@ -1,10 +1,213 @@
# DISABLED — auto-release Step 11 recreates dev from main after every release.
# Cascade-dev is redundant and causes version conflicts when both main and dev
# have different version numbers in templateDetails.xml / manifest.xml.
name: "Cascade Main → Dev (DISABLED)"
on: workflow_dispatch
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Maintenance
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/moko-platform
# PATH: /templates/workflows/cascade-dev.yml.template
# VERSION: 02.00.00
# BRIEF: Forward-merge main -> all open branches after every push to main
#
# +========================================================================+
# | CASCADE MAIN -> ALL BRANCHES |
# +========================================================================+
# | |
# | Triggers on every push to main (PR merges, bot commits, etc.) |
# | |
# | 1. List all branches matching: dev, rc/*, beta/*, alpha/* |
# | 2. For each: create PR (main -> branch), auto-merge if clean |
# | 3. On conflict: leave PR open for manual resolution |
# | |
# +========================================================================+
name: "Universal: Cascade Main -> Dev"
on:
push:
branches:
- main
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
GITEA_ORG: ${{ vars.GITEA_ORG || github.repository_owner }}
GITEA_REPO: ${{ vars.GITEA_REPO || github.event.repository.name }}
permissions:
contents: write
pull-requests: write
jobs:
noop:
cascade:
name: Cascade main -> branches
runs-on: ubuntu-latest
if: >-
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip cascade]')
steps:
- run: echo "Cascade disabled — auto-release handles dev recreation"
- name: Discover target branches
id: branches
env:
GA_TOKEN: ${{ secrets.GA_TOKEN }}
run: |
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
# Fetch all branches (paginated)
PAGE=1
ALL_BRANCHES=""
while true; do
BATCH=$(curl -sS \
-H "Authorization: token ${GA_TOKEN}" \
"${API}/branches?page=${PAGE}&limit=50" \
| jq -r '.[].name // empty')
[ -z "$BATCH" ] && break
ALL_BRANCHES="$ALL_BRANCHES $BATCH"
PAGE=$((PAGE + 1))
done
# Filter to cascade targets: dev, dev/*, rc/*, beta/*, alpha/*
TARGETS=""
for BRANCH in $ALL_BRANCHES; do
case "$BRANCH" in
dev|dev/*|rc/*|beta/*|alpha/*)
TARGETS="$TARGETS $BRANCH"
;;
esac
done
TARGETS=$(echo "$TARGETS" | xargs) # trim whitespace
if [ -z "$TARGETS" ]; then
echo "targets=" >> "$GITHUB_OUTPUT"
echo " No cascade target branches found"
else
echo "targets=$TARGETS" >> "$GITHUB_OUTPUT"
COUNT=$(echo "$TARGETS" | wc -w)
echo " Found ${COUNT} target branch(es): ${TARGETS}"
fi
- name: Cascade to all target branches
if: steps.branches.outputs.targets != ''
env:
GA_TOKEN: ${{ secrets.GA_TOKEN }}
run: |
API="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
SHORT_SHA="${GITHUB_SHA:0:7}"
TARGETS="${{ steps.branches.outputs.targets }}"
SUCCESS=0
CONFLICTS=0
SKIPPED=0
FAILED=0
for BRANCH in $TARGETS; do
echo ""
echo " main -> ${BRANCH} "
# Check if branch is already up to date
ENCODED_BRANCH=$(echo "$BRANCH" | sed 's|/|%2F|g')
RESPONSE=$(curl -sS \
-H "Authorization: token ${GA_TOKEN}" \
"${API}/compare/${ENCODED_BRANCH}...main")
AHEAD=$(echo "$RESPONSE" | jq '.total_commits // 0')
if [ "$AHEAD" -eq 0 ]; then
echo " Already up to date"
SKIPPED=$((SKIPPED + 1))
continue
fi
echo " main is ${AHEAD} commit(s) ahead"
# Check for existing cascade PR
EXISTING=$(curl -sS \
-H "Authorization: token ${GA_TOKEN}" \
"${API}/pulls?state=open&head=${GITEA_ORG}:main&base=${ENCODED_BRANCH}&limit=1")
EXISTING_COUNT=$(echo "$EXISTING" | jq 'length')
PR_NUMBER=""
if [ "$EXISTING_COUNT" -gt 0 ]; then
PR_NUMBER=$(echo "$EXISTING" | jq -r '.[0].number')
echo " Reusing existing PR #${PR_NUMBER}"
else
# Create cascade PR
PR_RESPONSE=$(curl -sS -w "\n%{http_code}" \
-X POST \
-H "Authorization: token ${GA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"title\": \"chore: cascade main -> ${BRANCH} (${SHORT_SHA}) [skip ci]\",
\"body\": \"## Automatic cascade\\n\\nForward-merging \`main\` (${SHORT_SHA}) into \`${BRANCH}\`.\\n\\nIf conflicts exist, resolve manually and merge.\\n\\n> Auto-created by **Cascade Main -> Dev**.\",
\"head\": \"main\",
\"base\": \"${BRANCH}\"
}" \
"${API}/pulls")
HTTP_CODE=$(echo "$PR_RESPONSE" | tail -1)
BODY=$(echo "$PR_RESPONSE" | sed '$d')
PR_NUMBER=$(echo "$BODY" | jq -r '.number // empty')
if [ "$HTTP_CODE" != "201" ] || [ -z "$PR_NUMBER" ]; then
MSG=$(echo "$BODY" | jq -r '.message // .' 2>/dev/null | head -1)
echo " Failed to create PR (HTTP ${HTTP_CODE}): ${MSG}"
FAILED=$((FAILED + 1))
continue
fi
echo " Created PR #${PR_NUMBER}"
fi
# Try auto-merge
PR_DATA=$(curl -sS \
-H "Authorization: token ${GA_TOKEN}" \
"${API}/pulls/${PR_NUMBER}")
MERGEABLE=$(echo "$PR_DATA" | jq -r '.mergeable // false')
if [ "$MERGEABLE" != "true" ]; then
echo " Conflicts -- PR #${PR_NUMBER} left open"
CONFLICTS=$((CONFLICTS + 1))
continue
fi
MERGE_RESPONSE=$(curl -sS -w "\n%{http_code}" \
-X POST \
-H "Authorization: token ${GA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"Do\": \"merge\",
\"merge_message_field\": \"chore: cascade main -> ${BRANCH} [skip ci]\",
\"delete_branch_after_merge\": false
}" \
"${API}/pulls/${PR_NUMBER}/merge")
MERGE_HTTP=$(echo "$MERGE_RESPONSE" | tail -1)
if [ "$MERGE_HTTP" = "200" ] || [ "$MERGE_HTTP" = "204" ]; then
echo " Merged -- ${BRANCH} is in sync"
SUCCESS=$((SUCCESS + 1))
else
MERGE_BODY=$(echo "$MERGE_RESPONSE" | sed '$d')
echo " Merge failed (HTTP ${MERGE_HTTP}) -- PR #${PR_NUMBER} left open"
CONFLICTS=$((CONFLICTS + 1))
fi
done
# Summary
echo ""
echo ""
echo " Merged: ${SUCCESS}"
echo " Conflicts: ${CONFLICTS}"
echo " Up to date: ${SKIPPED}"
echo " Failed: ${FAILED}"
echo ""
if [ "$FAILED" -gt 0 ]; then
exit 1
fi
-508
View File
@@ -1,508 +0,0 @@
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.CI
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/moko-platform
# PATH: /templates/workflows/universal/pr-check.yml.template
# VERSION: 09.23.00
# BRIEF: PR gate — branch policy + code validation before merge
name: "Universal: PR Check"
on:
pull_request:
types: [opened, synchronize, reopened, edited]
permissions:
contents: read
pull-requests: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
# ── Branch Policy ──────────────────────────────────────────────────────
branch-policy:
name: Branch Policy
runs-on: ubuntu-latest
steps:
- name: Check branch merge target
run: |
HEAD="${{ github.head_ref }}"
BASE="${{ github.base_ref }}"
echo "PR: ${HEAD} → ${BASE}"
ALLOWED=true
REASON=""
case "$HEAD" in
feature/*|feat/*)
if [ "$BASE" != "dev" ]; then
ALLOWED=false
REASON="Feature branches must target 'dev', not '${BASE}'"
fi
;;
fix/*|bugfix/*)
if [ "$BASE" != "dev" ]; then
ALLOWED=false
REASON="Fix branches must target 'dev', not '${BASE}'"
fi
;;
patch/*)
if [ "$BASE" != "dev" ] && [ "$BASE" != "rc" ]; then
ALLOWED=false
REASON="Patch branches must target 'dev' or 'rc', not '${BASE}'"
fi
;;
hotfix/*)
if [ "$BASE" != "dev" ] && [ "$BASE" != "main" ]; then
ALLOWED=false
REASON="Hotfix branches can only target 'dev' or 'main', not '${BASE}'"
fi
;;
rc)
if [ "$BASE" != "main" ]; then
ALLOWED=false
REASON="RC branch can only merge into 'main', not '${BASE}'"
fi
;;
dev)
if [ "$BASE" != "main" ]; then
ALLOWED=false
REASON="Dev branch can only merge into 'main', not '${BASE}'"
fi
;;
esac
if [ "$ALLOWED" = false ]; then
echo "::error::${REASON}"
echo "## Branch Policy Violation" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${REASON}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Allowed merge paths:" >> $GITHUB_STEP_SUMMARY
echo "- \`feature/*\` → \`dev\`" >> $GITHUB_STEP_SUMMARY
echo "- \`fix/*\` → \`dev\`" >> $GITHUB_STEP_SUMMARY
echo "- \`hotfix/*\` → \`dev\` or \`main\`" >> $GITHUB_STEP_SUMMARY
echo "- \`dev\` → \`main\`" >> $GITHUB_STEP_SUMMARY
echo "- \`rc/*\` → \`main\`" >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "Branch policy: OK (${HEAD} → ${BASE})"
echo "## Branch Policy: Passed" >> $GITHUB_STEP_SUMMARY
# ── Code Validation ────────────────────────────────────────────────────
validate:
name: Validate PR
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for merge conflict markers
run: |
CONFLICTS=$(grep -rn '<<<<<<< \|>>>>>>> \|^=======$' --include='*.php' --include='*.xml' --include='*.css' --include='*.js' --include='*.json' --include='*.md' --include='*.yml' --include='*.yaml' --include='*.ini' --include='*.txt' . 2>/dev/null | grep -v '.git/' || true)
if [ -n "$CONFLICTS" ]; then
echo "::error::Merge conflict markers found in source files"
echo "## Conflict Markers Found" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "$CONFLICTS" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "No conflict markers found"
- name: Detect platform
id: platform
run: |
# Read platform from XML manifest (<platform> tag) or plain text fallback
PLATFORM=$(sed -n 's/.*<platform>\([^<]*\)<\/platform>.*/\1/p' .mokogitea/manifest.xml 2>/dev/null | head -1)
[ -z "$PLATFORM" ] && PLATFORM=$(cat .mokogitea/manifest.xml 2>/dev/null | tr -d '[:space:]')
[ -z "$PLATFORM" ] && PLATFORM="generic"
echo "platform=$PLATFORM" >> "$GITHUB_OUTPUT"
- name: Setup PHP
if: steps.platform.outputs.platform == 'joomla' || steps.platform.outputs.platform == 'dolibarr'
run: |
if ! command -v php &> /dev/null; then
sudo apt-get update -qq
sudo apt-get install -y -qq php-cli php-mbstring php-xml >/dev/null 2>&1
fi
- name: PHP syntax check
if: steps.platform.outputs.platform == 'joomla' || steps.platform.outputs.platform == 'dolibarr'
run: |
ERRORS=0
while IFS= read -r -d '' file; do
if ! php -l "$file" 2>&1 | grep -q "No syntax errors"; then
ERRORS=$((ERRORS + 1))
fi
done < <(find . -name "*.php" -not -path "./.git/*" -not -path "./vendor/*" -print0)
echo "PHP lint: ${ERRORS} error(s)"
[ "$ERRORS" -eq 0 ] || { echo "::error::PHP syntax errors found"; exit 1; }
- name: Joomla JEXEC guard check
if: steps.platform.outputs.platform == 'joomla'
run: |
ERRORS=0
while IFS= read -r -d '' file; do
# Skip vendor, node_modules, and index.html stub files
case "$file" in ./vendor/*|./node_modules/*) continue ;; esac
# Check first 10 lines for JEXEC or JPATH guard
if ! head -20 "$file" | grep -qE "defined\s*\(\s*['\"](_JEXEC|JPATH_BASE|\\\\JPATH_PLATFORM)['\"]"; then
echo "::error file=${file}::Missing JEXEC guard: ${file}"
ERRORS=$((ERRORS + 1))
fi
done < <(find . -name "*.php" -path "*/src/*" -not -path "./.git/*" -not -path "./vendor/*" -print0)
if [ "$ERRORS" -gt 0 ]; then
echo "::error::${ERRORS} PHP file(s) missing defined('_JEXEC') or die guard"
echo "## JEXEC Guard Check: Failed" >> $GITHUB_STEP_SUMMARY
echo "${ERRORS} file(s) in src/ are missing the Joomla execution guard." >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "JEXEC guard: OK"
- name: Joomla directory listing protection
if: steps.platform.outputs.platform == 'joomla'
run: |
MISSING=0
SOURCE_DIR="src"
[ ! -d "$SOURCE_DIR" ] && exit 0
while IFS= read -r dir; do
if [ ! -f "${dir}/index.html" ]; then
echo "::warning::Missing index.html in ${dir} (directory listing protection)"
MISSING=$((MISSING + 1))
fi
done < <(find "$SOURCE_DIR" -type d -not -path "./.git/*" -not -path "*/vendor/*" -not -path "*/node_modules/*")
if [ "$MISSING" -gt 0 ]; then
echo "## Directory Protection" >> $GITHUB_STEP_SUMMARY
echo "${MISSING} director(ies) missing index.html" >> $GITHUB_STEP_SUMMARY
fi
echo "Directory protection: ${MISSING} missing (advisory)"
- name: Joomla script file and asset checks
if: steps.platform.outputs.platform == 'joomla'
run: |
ERRORS=0
MANIFEST=$(find . -maxdepth 3 -name "*.xml" ! -path "./.git/*" -exec grep -l '<extension' {} \; 2>/dev/null | head -1)
[ -z "$MANIFEST" ] && exit 0
MANIFEST_DIR=$(dirname "$MANIFEST")
# Check scriptfile exists if declared
SCRIPTFILE=$(sed -n 's/.*<scriptfile>\([^<]*\)<\/scriptfile>.*/\1/p' "$MANIFEST" 2>/dev/null)
if [ -n "$SCRIPTFILE" ]; then
if [ ! -f "${MANIFEST_DIR}/${SCRIPTFILE}" ]; then
echo "::error::Manifest declares <scriptfile>${SCRIPTFILE}</scriptfile> but file not found at ${MANIFEST_DIR}/${SCRIPTFILE}"
ERRORS=$((ERRORS + 1))
else
echo "Script file: ${MANIFEST_DIR}/${SCRIPTFILE} (OK)"
fi
fi
# Require joomla.asset.json and validate it
ASSET_JSON=$(find "$MANIFEST_DIR" -name "joomla.asset.json" -not -path "./.git/*" 2>/dev/null | head -1)
if [ -z "$ASSET_JSON" ]; then
echo "::error::joomla.asset.json not found — Joomla asset system is required"
ERRORS=$((ERRORS + 1))
else
if command -v php &> /dev/null; then
php -r "json_decode(file_get_contents('$ASSET_JSON')); if(json_last_error()!==JSON_ERROR_NONE){echo json_last_error_msg();exit(1);}" 2>&1 || {
echo "::error::joomla.asset.json is not valid JSON"
ERRORS=$((ERRORS + 1))
}
fi
echo "joomla.asset.json: valid"
fi
# Validate all XML files in src/ are well-formed
XML_ERRORS=0
if command -v php &> /dev/null; then
while IFS= read -r -d '' xmlfile; do
if ! php -r "libxml_use_internal_errors(true); \$x = simplexml_load_file('$xmlfile'); if(!\$x){foreach(libxml_get_errors() as \$e) echo trim(\$e->message) . ' in $xmlfile'; exit(1);}" 2>&1; then
XML_ERRORS=$((XML_ERRORS + 1))
fi
done < <(find "$MANIFEST_DIR" -name "*.xml" -not -path "./.git/*" -print0)
fi
if [ "$XML_ERRORS" -gt 0 ]; then
echo "::error::${XML_ERRORS} XML file(s) are malformed"
ERRORS=$((ERRORS + 1))
else
echo "XML well-formedness: OK"
fi
[ "$ERRORS" -gt 0 ] && exit 1
echo "Joomla asset checks: OK"
- name: Validate platform manifest
run: |
PLATFORM="${{ steps.platform.outputs.platform }}"
case "$PLATFORM" in
joomla)
MANIFEST=$(find . -maxdepth 3 -name "*.xml" ! -path "./.git/*" -exec grep -l '<extension' {} \; 2>/dev/null | head -1)
if [ -z "$MANIFEST" ]; then
echo "::warning::No Joomla manifest found (WaaS site)"
exit 0
fi
echo "Manifest: ${MANIFEST}"
if command -v php &> /dev/null; then
php -r "libxml_use_internal_errors(true); \$x = simplexml_load_file('$MANIFEST'); if(!\$x){foreach(libxml_get_errors() as \$e) echo \$e->message; exit(1);}" || { echo "::error::Manifest XML is malformed"; exit 1; }
fi
for ELEMENT in name version description; do
grep -q "<${ELEMENT}>" "$MANIFEST" || { echo "::error::Missing <${ELEMENT}> in manifest"; exit 1; }
done
# Block legacy raw/branch update server URLs on MokoGitea
RAW_URLS=$(grep -n 'raw/branch' "$MANIFEST" | grep -i 'mokoconsulting\|mokogitea\|git\.mokoconsulting\.tech' || true)
if [ -n "$RAW_URLS" ]; then
echo "::error::Manifest contains legacy raw/branch update server URL on MokoGitea. Use the Gitea Pages URL instead (e.g. /{REPO}/updates.xml not /{REPO}/raw/branch/main/updates.xml)"
echo "$RAW_URLS"
exit 1
fi
echo "Joomla manifest valid"
;;
dolibarr)
MOD_FILE=$(find . -maxdepth 4 -name "mod*.class.php" ! -path "./.git/*" -exec grep -l 'extends DolibarrModules' {} \; 2>/dev/null | head -1)
if [ -z "$MOD_FILE" ]; then
echo "::error::No mod*.class.php found"
exit 1
fi
echo "Dolibarr module: ${MOD_FILE}"
;;
*)
echo "Generic platform — no manifest validation"
;;
esac
- name: Check update stream format
run: |
PLATFORM="${{ steps.platform.outputs.platform }}"
case "$PLATFORM" in
joomla)
if [ -f "updates.xml" ]; then
if command -v php &> /dev/null; then
php -r "libxml_use_internal_errors(true); \$x = simplexml_load_file('updates.xml'); if(!\$x){foreach(libxml_get_errors() as \$e) echo \$e->message; exit(1);}" || { echo "::error::updates.xml is malformed"; exit 1; }
fi
echo "updates.xml valid"
fi
;;
dolibarr)
[ -f "update.txt" ] && echo "update.txt present" || echo "::warning::No update.txt"
;;
esac
- name: Validate Joomla language files
if: steps.platform.outputs.platform == 'joomla'
run: |
ERRORS=0
WARNINGS=0
# Require both en-GB and en-US language directories
LANG_ROOT=$(find . -path "*/language" -type d -not -path "./.git/*" 2>/dev/null | head -1)
if [ -z "$LANG_ROOT" ]; then
echo "No language/ directory found — skipping"
exit 0
fi
if [ ! -d "$LANG_ROOT/en-GB" ]; then
echo "::error::Missing en-GB language directory (${LANG_ROOT}/en-GB)"
ERRORS=$((ERRORS + 1))
fi
if [ ! -d "$LANG_ROOT/en-US" ]; then
echo "::error::Missing en-US language directory (${LANG_ROOT}/en-US)"
ERRORS=$((ERRORS + 1))
fi
# Check that en-GB and en-US have matching .ini files
if [ -d "$LANG_ROOT/en-GB" ] && [ -d "$LANG_ROOT/en-US" ]; then
for GB_INI in "$LANG_ROOT/en-GB"/*.ini; do
[ ! -f "$GB_INI" ] && continue
US_INI="$LANG_ROOT/en-US/$(basename "$GB_INI")"
if [ ! -f "$US_INI" ]; then
echo "::error::$(basename "$GB_INI") exists in en-GB but missing from en-US"
ERRORS=$((ERRORS + 1))
fi
done
for US_INI in "$LANG_ROOT/en-US"/*.ini; do
[ ! -f "$US_INI" ] && continue
GB_INI="$LANG_ROOT/en-GB/$(basename "$US_INI")"
if [ ! -f "$GB_INI" ]; then
echo "::error::$(basename "$US_INI") exists in en-US but missing from en-GB"
ERRORS=$((ERRORS + 1))
fi
done
fi
# Find all .ini language files
INI_FILES=$(find . -path "*/language/*/*.ini" -not -path "./.git/*" 2>/dev/null)
if [ -z "$INI_FILES" ]; then
echo "No .ini language files found"
[ "$ERRORS" -gt 0 ] && exit 1
exit 0
fi
echo "Found $(echo "$INI_FILES" | wc -l) language file(s)"
for FILE in $INI_FILES; do
FNAME=$(basename "$FILE")
LINENUM=0
SEEN_KEYS=""
while IFS= read -r line || [ -n "$line" ]; do
LINENUM=$((LINENUM + 1))
# Skip empty lines and comments
[ -z "$line" ] && continue
echo "$line" | grep -qE '^\s*;' && continue
echo "$line" | grep -qE '^\s*$' && continue
# Must match KEY="VALUE" format
if ! echo "$line" | grep -qE '^[A-Z_][A-Z0-9_]*=".*"$'; then
echo "::error file=${FILE},line=${LINENUM}::Malformed line: ${line}"
ERRORS=$((ERRORS + 1))
continue
fi
# Extract key and check for duplicates
KEY=$(echo "$line" | sed 's/=.*//')
if echo "$SEEN_KEYS" | grep -qx "$KEY"; then
echo "::error file=${FILE},line=${LINENUM}::Duplicate key: ${KEY}"
ERRORS=$((ERRORS + 1))
fi
SEEN_KEYS="${SEEN_KEYS}
${KEY}"
done < "$FILE"
echo " ${FILE}: checked ${LINENUM} lines"
done
# Cross-check en-GB vs en-US key consistency
GB_DIR=$(find . -path "*/language/en-GB" -type d -not -path "./.git/*" 2>/dev/null | head -1)
US_DIR=$(find . -path "*/language/en-US" -type d -not -path "./.git/*" 2>/dev/null | head -1)
if [ -n "$GB_DIR" ] && [ -n "$US_DIR" ]; then
for GB_FILE in "$GB_DIR"/*.ini; do
[ ! -f "$GB_FILE" ] && continue
FNAME=$(basename "$GB_FILE")
US_FILE="$US_DIR/$FNAME"
[ ! -f "$US_FILE" ] && continue
GB_KEYS=$(grep -oP '^[A-Z_][A-Z0-9_]*(?==)' "$GB_FILE" 2>/dev/null | sort)
US_KEYS=$(grep -oP '^[A-Z_][A-Z0-9_]*(?==)' "$US_FILE" 2>/dev/null | sort)
# Keys in en-GB but not en-US
MISSING_US=$(comm -23 <(echo "$GB_KEYS") <(echo "$US_KEYS"))
if [ -n "$MISSING_US" ]; then
echo "::warning::Keys in en-GB/$FNAME but missing from en-US/$FNAME:"
echo "$MISSING_US" | while read -r k; do echo " - $k"; done
WARNINGS=$((WARNINGS + 1))
fi
# Keys in en-US but not en-GB
MISSING_GB=$(comm -13 <(echo "$GB_KEYS") <(echo "$US_KEYS"))
if [ -n "$MISSING_GB" ]; then
echo "::warning::Keys in en-US/$FNAME but missing from en-GB/$FNAME:"
echo "$MISSING_GB" | while read -r k; do echo " - $k"; done
WARNINGS=$((WARNINGS + 1))
fi
done
fi
{
echo "### Language File Validation"
echo "| Metric | Count |"
echo "|---|---|"
echo "| Files checked | $(echo "$INI_FILES" | wc -l) |"
echo "| Errors | ${ERRORS} |"
echo "| Warnings | ${WARNINGS} |"
} >> $GITHUB_STEP_SUMMARY
if [ "$ERRORS" -gt 0 ]; then
echo "::error::Language validation failed with ${ERRORS} error(s)"
exit 1
fi
echo "Language files: OK (${WARNINGS} warning(s))"
- name: Check changelog has unreleased entry
run: |
if [ ! -f "CHANGELOG.md" ]; then
echo "::warning::No CHANGELOG.md found"
exit 0
fi
# Check for content under [Unreleased] section
if ! grep -q "## \[Unreleased\]" CHANGELOG.md; then
echo "::error::CHANGELOG.md missing [Unreleased] section"
exit 1
fi
# Check there's at least one entry (Added/Changed/Fixed/Removed) under Unreleased
UNRELEASED_CONTENT=$(sed -n '/## \[Unreleased\]/,/## \[/p' CHANGELOG.md | grep -cE '^\s*-\s' || true)
if [ "$UNRELEASED_CONTENT" -eq 0 ]; then
echo "::error::CHANGELOG.md [Unreleased] section has no entries. Add a changelog entry describing your changes."
echo "## Changelog Check: Failed" >> $GITHUB_STEP_SUMMARY
echo "The \`[Unreleased]\` section in CHANGELOG.md has no entries." >> $GITHUB_STEP_SUMMARY
echo "Add a line like \`- Description of your change\` under a heading (\`### Added\`, \`### Changed\`, \`### Fixed\`, etc.)" >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "Changelog: ${UNRELEASED_CONTENT} entry/entries in [Unreleased]"
- name: Verify package source
run: |
SOURCE_DIR="src"
[ ! -d "$SOURCE_DIR" ] && SOURCE_DIR="htdocs"
if [ ! -d "$SOURCE_DIR" ]; then
echo "::warning::No src/ or htdocs/ directory"
exit 0
fi
FILE_COUNT=$(find "$SOURCE_DIR" -type f | wc -l)
echo "Source: ${FILE_COUNT} files"
[ "$FILE_COUNT" -gt 0 ] || { echo "::error::Source directory is empty"; exit 1; }
# ── Pre-Release RC Build ─────────────────────────────────────────────────
pre-release:
name: Build RC Package
runs-on: ubuntu-latest
needs: [branch-policy, validate]
steps:
- name: Trigger RC pre-release
env:
GA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: ${{ github.head_ref }}
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
run: |
curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO}/actions/workflows/pre-release.yml/dispatches" -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" -d "{\"ref\":\"${BRANCH}\",\"inputs\":{\"stability\":\"release-candidate\"}}"
echo "### Pre-Release" >> $GITHUB_STEP_SUMMARY
echo "Triggered RC build on branch \`${BRANCH}\`" >> $GITHUB_STEP_SUMMARY
# ── Issue Reporter ──────────────────────────────────────────────────────
report-issues:
name: Report Issues
runs-on: ubuntu-latest
needs: [branch-policy, validate]
if: >-
always() &&
needs.validate.result == 'failure'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: automation/ci-issue-reporter.sh
sparse-checkout-cone-mode: false
- name: "File issue for PR validation failure"
env:
GITEA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
run: |
chmod +x automation/ci-issue-reporter.sh
./automation/ci-issue-reporter.sh \
--gate "PR Validation" \
--workflow "PR Check" \
--severity error \
--details "PR validation failed (syntax, manifest, changelog, or source checks). See the CI run for the specific check that failed."
+12 -13
View File
@@ -50,18 +50,16 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.MOKOGITEA_TOKEN }}
token: ${{ secrets.GA_TOKEN }}
- name: Setup moko-platform tools
env:
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
run: |
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
# Always fetch latest CLI tools — never use stale cache from previous runs
rm -rf /tmp/moko-platform-api
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/moko-platform.git" \
/tmp/moko-platform-api
@@ -89,24 +87,25 @@ jobs:
VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null)
[ -z "$VERSION" ] && VERSION="00.00.01"
# Strip any existing suffix from version before applying stability
VERSION=$(echo "$VERSION" | sed 's/-\(dev\|alpha\|beta\|rc\)$//')
php ${MOKO_CLI}/version_set_platform.php \
--path . --version "$VERSION" --branch "${{ github.ref_name }}" --stability "$STABILITY" 2>/dev/null || true
--path . --version "$VERSION" --branch "${{ github.ref_name }}" 2>/dev/null || true
# Verify version consistency across all files
php ${MOKO_CLI}/version_check.php --path . --fix 2>/dev/null || true
# Update VERSION variable with suffix
# Append suffix to all manifest <version> tags
if [ -n "$SUFFIX" ]; then
find . -maxdepth 4 -name "*.xml" ! -path "./.git/*" ! -path "./build/*" \
-exec grep -l "<version>${VERSION}</version>" {} \; 2>/dev/null | while read f; do
sed -i "s|<version>${VERSION}</version>|<version>${VERSION}${SUFFIX}</version>|g" "$f"
done
VERSION="${VERSION}${SUFFIX}"
fi
# Commit version bump
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
git remote set-url origin "https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
git remote set-url origin "https://jmiller:${{ secrets.GA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
git add -A
git diff --cached --quiet || {
git commit -m "chore(version): pre-release bump to ${VERSION} [skip ci]"
@@ -141,7 +140,7 @@ jobs:
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php ${MOKO_CLI}/release_create.php \
--path . --version "$VERSION" --tag "$TAG" \
--token "${{ secrets.MOKOGITEA_TOKEN }}" --api-base "$API_BASE" \
--token "${{ secrets.GA_TOKEN }}" --api-base "$API_BASE" \
--repo "${GITEA_REPO}" --branch dev --prerelease
- name: Build package and upload
@@ -152,7 +151,7 @@ jobs:
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
php ${MOKO_CLI}/release_package.php \
--path . --version "$VERSION" --tag "$TAG" \
--token "${{ secrets.MOKOGITEA_TOKEN }}" --api-base "$API_BASE" \
--token "${{ secrets.GA_TOKEN }}" --api-base "$API_BASE" \
--repo "${GITEA_REPO}" --output /tmp || true
- name: Update updates.xml
@@ -209,7 +208,7 @@ jobs:
continue-on-error: true
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
TOKEN="${{ secrets.GA_TOKEN }}"
php ${MOKO_CLI}/release_cascade.php \
--stability "${{ steps.meta.outputs.stability }}" \
-711
View File
@@ -1,711 +0,0 @@
# ============================================================================
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
#
# This file is part of a Moko Consulting project.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Gitea.Workflow
# INGROUP: moko-platform.Validation
# REPO: https://git.mokoconsulting.tech/mokoconsulting-tech/moko-platform
# PATH: /templates/workflows/joomla/repo_health.yml.template
# VERSION: 09.23.00
# BRIEF: Enforces repository guardrails by validating scripts governance, tooling availability, and core repository health artifacts.
# ============================================================================
name: "Generic: Repo Health"
defaults:
run:
shell: bash
on:
workflow_dispatch:
inputs:
profile:
description: 'Validation profile: all, scripts, or repo'
required: true
default: all
type: choice
options:
- all
- scripts
- repo
pull_request:
push:
permissions:
contents: read
env:
# Scripts governance policy
SCRIPTS_REQUIRED_DIRS:
SCRIPTS_ALLOWED_DIRS: scripts,scripts/fix,scripts/lib,scripts/release,scripts/run,scripts/validate
# Repo health policy
REPO_REQUIRED_ARTIFACTS: README.md,LICENSE,CHANGELOG.md,CONTRIBUTING.md,CODE_OF_CONDUCT.md,.mokogitea/workflows/
REPO_OPTIONAL_FILES: SECURITY.md,GOVERNANCE.md,.editorconfig,.gitattributes,.gitignore,README.md,docs/
REPO_DISALLOWED_DIRS:
REPO_DISALLOWED_FILES: TODO.md,todo.md
# Extended checks toggles
EXTENDED_CHECKS: "true"
# File / directory variables
DOCS_INDEX: docs/docs-index.md
SCRIPT_DIR: scripts
WORKFLOWS_DIR: .mokogitea/workflows
SHELLCHECK_PATTERN: '*.sh'
SPDX_FILE_GLOBS: '*.sh,*.php,*.js,*.ts,*.css,*.xml,*.yml,*.yaml'
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
access_check:
name: Access control
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
outputs:
allowed: ${{ steps.perm.outputs.allowed }}
permission: ${{ steps.perm.outputs.permission }}
steps:
- name: Check actor permission (admin only)
id: perm
env:
TOKEN: ${{ secrets.MOKOGITEA_TOKEN || secrets.MOKOGITEA_TOKEN || github.token }}
REPO: ${{ github.repository }}
ACTOR: ${{ github.actor }}
run: |
set -euo pipefail
ALLOWED=false
PERMISSION=unknown
METHOD=""
# Hardcoded authorized users — always allowed
case "$ACTOR" in
jmiller|gitea-actions[bot])
ALLOWED=true
PERMISSION=admin
METHOD="hardcoded allowlist"
;;
*)
# Detect platform and check permissions via API
API_BASE="${GITHUB_API_URL:-${GITEA_API_URL:-https://api.github.com}}"
RESP=$(curl -sf -H "Authorization: token ${TOKEN}" \
"${API_BASE}/repos/${REPO}/collaborators/${ACTOR}/permission" 2>/dev/null || echo '{}')
PERMISSION=$(echo "$RESP" | grep -oP '"permission"\s*:\s*"\K[^"]+' || echo "unknown")
if [ "$PERMISSION" = "admin" ] || [ "$PERMISSION" = "maintain" ] || [ "$PERMISSION" = "owner" ]; then
ALLOWED=true
fi
METHOD="collaborator API"
;;
esac
echo "permission=${PERMISSION}" >> "$GITHUB_OUTPUT"
echo "allowed=${ALLOWED}" >> "$GITHUB_OUTPUT"
{
echo "## Access Authorization"
echo ""
echo "| Field | Value |"
echo "|-------|-------|"
echo "| **Actor** | \`${ACTOR}\` |"
echo "| **Repository** | \`${REPO}\` |"
echo "| **Permission** | \`${PERMISSION}\` |"
echo "| **Method** | ${METHOD} |"
echo "| **Authorized** | ${ALLOWED} |"
echo ""
if [ "$ALLOWED" = "true" ]; then
echo "${ACTOR} authorized (${METHOD})"
else
echo "${ACTOR} is NOT authorized. Requires admin or maintain role."
fi
} >> "${GITHUB_STEP_SUMMARY}"
- name: Deny execution when not permitted
if: ${{ steps.perm.outputs.allowed != 'true' }}
run: |
set -euo pipefail
printf '%s\n' 'ERROR: Access denied. Admin permission required.' >> "${GITHUB_STEP_SUMMARY}"
exit 1
scripts_governance:
name: Scripts governance
needs: access_check
if: ${{ needs.access_check.outputs.allowed == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Scripts folder checks
env:
PROFILE_RAW: ${{ github.event.inputs.profile }}
run: |
set -euo pipefail
profile="${PROFILE_RAW:-all}"
case "${profile}" in
all|scripts|repo) ;;
*)
printf '%s\n' "ERROR: Unknown profile: ${profile}" >> "${GITHUB_STEP_SUMMARY}"
exit 1
;;
esac
if [ "${profile}" = 'repo' ]; then
{
printf '%s\n' '### Scripts governance'
printf '%s\n' "Profile: ${profile}"
printf '%s\n' 'Status: SKIPPED'
printf '%s\n' 'Reason: profile excludes scripts governance'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
if [ ! -d "${SCRIPT_DIR}" ]; then
{
printf '%s\n' '### Scripts governance'
printf '%s\n' 'Status: OK (advisory)'
printf '%s\n' 'scripts/ directory not present. No scripts governance enforced.'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
if [ -n "${SCRIPTS_REQUIRED_DIRS:-}" ]; then IFS=',' read -r -a required_dirs <<< "${SCRIPTS_REQUIRED_DIRS}"; else required_dirs=(); fi
IFS=',' read -r -a allowed_dirs <<< "${SCRIPTS_ALLOWED_DIRS}"
missing_dirs=()
unapproved_dirs=()
for d in "${required_dirs[@]}"; do
req="${d%/}"
[ ! -d "${req}" ] && missing_dirs+=("${req}/")
done
while IFS= read -r d; do
allowed=false
for a in "${allowed_dirs[@]}"; do
a_norm="${a%/}"
[ "${d%/}" = "${a_norm}" ] && allowed=true
done
[ "${allowed}" = false ] && unapproved_dirs+=("${d%/}/")
done < <(find "${SCRIPT_DIR}" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sed 's#^\./##')
{
printf '%s\n' '### Scripts governance'
printf '%s\n' "Profile: ${profile}"
printf '%s\n' '| Area | Status | Notes |'
printf '%s\n' '|---|---|---|'
if [ "${#missing_dirs[@]}" -gt 0 ]; then
printf '%s\n' '| Required directories | Warning | Missing required subfolders |'
else
printf '%s\n' '| Required directories | OK | All required subfolders present |'
fi
if [ "${#unapproved_dirs[@]}" -gt 0 ]; then
printf '%s\n' '| Directory policy | Warning | Unapproved directories detected |'
else
printf '%s\n' '| Directory policy | OK | No unapproved directories |'
fi
printf '%s\n' '| Enforcement mode | Advisory | scripts folder is optional |'
printf '\n'
if [ "${#missing_dirs[@]}" -gt 0 ]; then
printf '%s\n' 'Missing required script directories:'
for m in "${missing_dirs[@]}"; do printf '%s\n' "- ${m}"; done
printf '\n'
else
printf '%s\n' 'Missing required script directories: none.'
printf '\n'
fi
if [ "${#unapproved_dirs[@]}" -gt 0 ]; then
printf '%s\n' 'Unapproved script directories detected:'
for m in "${unapproved_dirs[@]}"; do printf '%s\n' "- ${m}"; done
printf '\n'
else
printf '%s\n' 'Unapproved script directories detected: none.'
printf '\n'
fi
printf '%s\n' 'Scripts governance completed in advisory mode.'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
repo_health:
name: Repository health
needs: access_check
if: ${{ needs.access_check.outputs.allowed == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Repository health checks
env:
PROFILE_RAW: ${{ github.event.inputs.profile }}
run: |
set -euo pipefail
profile="${PROFILE_RAW:-all}"
case "${profile}" in
all|scripts|repo) ;;
*)
printf '%s\n' "ERROR: Unknown profile: ${profile}" >> "${GITHUB_STEP_SUMMARY}"
exit 1
;;
esac
if [ "${profile}" = 'scripts' ]; then
{
printf '%s\n' '### Repository health'
printf '%s\n' "Profile: ${profile}"
printf '%s\n' 'Status: SKIPPED'
printf '%s\n' 'Reason: profile excludes repository health'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
IFS=',' read -r -a required_artifacts <<< "${REPO_REQUIRED_ARTIFACTS}"
IFS=',' read -r -a optional_files <<< "${REPO_OPTIONAL_FILES}"
if [ -n "${REPO_DISALLOWED_DIRS:-}" ]; then IFS=',' read -r -a disallowed_dirs <<< "${REPO_DISALLOWED_DIRS}"; else disallowed_dirs=(); fi
IFS=',' read -r -a disallowed_files <<< "${REPO_DISALLOWED_FILES:-}"
missing_required=()
missing_optional=()
# Source directory: src/ or htdocs/ (either is valid for extension repos)
SOURCE_DIR=""
if [ -d "src" ]; then
SOURCE_DIR="src"
elif [ -d "htdocs" ]; then
SOURCE_DIR="htdocs"
elif [ -d "deploy" ] || [ -d "cli" ] || [ -d "monitoring" ]; then
# Platform/tooling repos don't need src/
SOURCE_DIR=""
else
missing_required+=("src/ or htdocs/ (source directory required)")
fi
for item in "${required_artifacts[@]}"; do
if printf '%s' "${item}" | grep -q '/$'; then
d="${item%/}"
[ ! -d "${d}" ] && missing_required+=("${item}")
else
[ ! -f "${item}" ] && missing_required+=("${item}")
fi
done
for f in "${optional_files[@]}"; do
if printf '%s' "${f}" | grep -q '/$'; then
d="${f%/}"
[ ! -d "${d}" ] && missing_optional+=("${f}")
else
[ ! -f "${f}" ] && missing_optional+=("${f}")
fi
done
for d in "${disallowed_dirs[@]}"; do
d_norm="${d%/}"
[ -d "${d_norm}" ] && missing_required+=("${d_norm}/ (disallowed)")
done
for f in "${disallowed_files[@]}"; do
[ -f "${f}" ] && missing_required+=("${f} (disallowed)")
done
git fetch origin --prune
dev_paths=()
dev_branches=()
while IFS= read -r b; do
name="${b#origin/}"
if [ "${name}" = 'dev' ]; then
dev_branches+=("${name}")
else
dev_paths+=("${name}")
fi
done < <(git branch -r --list 'origin/dev*' | sed 's/^ *//')
if [ "${#dev_paths[@]}" -eq 0 ] && [ "${#dev_branches[@]}" -eq 0 ]; then
missing_required+=("dev or dev/* branch")
fi
content_warnings=()
if [ -f 'CHANGELOG.md' ] && ! grep -Eq '^# Changelog' CHANGELOG.md; then
content_warnings+=("CHANGELOG.md missing '# Changelog' header")
fi
if [ -f 'CHANGELOG.md' ] && grep -Eq '^[# ]*Unreleased' CHANGELOG.md; then
content_warnings+=("CHANGELOG.md contains Unreleased section (review release readiness)")
fi
if [ -f 'LICENSE' ] && ! grep -qiE 'GNU GENERAL PUBLIC LICENSE|GPL' LICENSE; then
content_warnings+=("LICENSE does not look like a GPL text")
fi
if [ -f 'README.md' ] && ! grep -qiE 'moko|Moko' README.md; then
content_warnings+=("README.md missing expected brand keyword")
fi
export PROFILE_RAW="${profile}"
export MISSING_REQUIRED="$(printf '%s\n' "${missing_required[@]:-}")"
export MISSING_OPTIONAL="$(printf '%s\n' "${missing_optional[@]:-}")"
export CONTENT_WARNINGS="$(printf '%s\n' "${content_warnings[@]:-}")"
report_json=$(printf '{"profile":"%s","missing_required":%d,"missing_optional":%d,"content_warnings":%d}' "$profile" "${#missing_required[@]}" "${#missing_optional[@]}" "${#content_warnings[@]}")
{
printf '%s\n' '### Repository health'
printf '%s\n' "Profile: ${profile}"
printf '%s\n' '| Metric | Value |'
printf '%s\n' '|---|---|'
printf '%s\n' "| Missing required | ${#missing_required[@]} |"
printf '%s\n' "| Missing optional | ${#missing_optional[@]} |"
printf '%s\n' "| Content warnings | ${#content_warnings[@]} |"
printf '\n'
printf '%s\n' '### Guardrails report (JSON)'
printf '%s\n' '```json'
printf '%s\n' "${report_json}"
printf '%s\n' '```'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
if [ "${#missing_required[@]}" -gt 0 ]; then
{
printf '%s\n' '### Missing required repo artifacts'
for m in "${missing_required[@]}"; do printf '%s\n' "- ${m}"; done
printf '%s\n' 'ERROR: Guardrails failed. Missing required repository artifacts.'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
exit 1
fi
if [ "${#missing_optional[@]}" -gt 0 ]; then
{
printf '%s\n' '### Missing optional repo artifacts'
for m in "${missing_optional[@]}"; do printf '%s\n' "- ${m}"; done
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
if [ "${#content_warnings[@]}" -gt 0 ]; then
{
printf '%s\n' '### Repo content warnings'
for m in "${content_warnings[@]}"; do printf '%s\n' "- ${m}"; done
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
# -- Joomla-specific checks --
joomla_findings=()
MANIFEST="$(find . -maxdepth 2 -name '*.xml' -exec grep -l '<extension' {} \; 2>/dev/null | head -1 || true)"
if [ -z "${MANIFEST}" ]; then
joomla_findings+=("Joomla XML manifest not found (no *.xml with <extension> tag)")
else
if ! grep -qP '<version>' "${MANIFEST}"; then
joomla_findings+=("XML manifest: <version> tag missing")
fi
if ! grep -qP 'type="(component|module|plugin|library|package|template|language)"' "${MANIFEST}"; then
joomla_findings+=("XML manifest: type attribute missing or invalid")
fi
if ! grep -qP '<name>' "${MANIFEST}"; then
joomla_findings+=("XML manifest: <name> tag missing")
fi
if ! grep -qP '<author>' "${MANIFEST}"; then
joomla_findings+=("XML manifest: <author> tag missing")
fi
if ! grep -qP '<namespace' "${MANIFEST}"; then
joomla_findings+=("XML manifest: <namespace> missing (required for Joomla 5+)")
fi
fi
INI_COUNT="$(find . -name '*.ini' -type f 2>/dev/null | wc -l)"
if [ "${INI_COUNT}" -eq 0 ]; then
joomla_findings+=("No .ini language files found")
fi
if [ ! -f 'updates.xml' ]; then
joomla_findings+=("updates.xml missing in root (required for Joomla update server)")
fi
if [ -n "${SOURCE_DIR}" ]; then
INDEX_DIRS=("${SOURCE_DIR}" "${SOURCE_DIR}/admin" "${SOURCE_DIR}/site")
for dir in "${INDEX_DIRS[@]}"; do
if [ -d "${dir}" ] && [ ! -f "${dir}/index.html" ]; then
joomla_findings+=("${dir}/index.html missing (directory listing protection)")
fi
done
fi
if [ "${#joomla_findings[@]}" -gt 0 ]; then
{
printf '%s\n' '### Joomla extension checks'
printf '%s\n' '| Check | Status |'
printf '%s\n' '|---|---|'
for f in "${joomla_findings[@]}"; do
printf '%s\n' "| ${f} | Warning |"
done
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
else
{
printf '%s\n' '### Joomla extension checks'
printf '%s\n' 'All Joomla-specific checks passed.'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
extended_enabled="${EXTENDED_CHECKS:-true}"
extended_findings=()
if [ "${extended_enabled}" = 'true' ]; then
if [ -f '.github/CODEOWNERS' ] || [ -f 'CODEOWNERS' ] || [ -f 'docs/CODEOWNERS' ]; then
:
else
extended_findings+=("CODEOWNERS not found (.github/CODEOWNERS preferred)")
fi
if ls "${WORKFLOWS_DIR}"/*.yml >/dev/null 2>&1 || ls "${WORKFLOWS_DIR}"/*.yaml >/dev/null 2>&1; then
bad_refs="$(grep -RIn --include='*.yml' --include='*.yaml' -E '^[[:space:]]*uses:[[:space:]]*[^#]+@(main|master)\b' "${WORKFLOWS_DIR}" 2>/dev/null || true)"
if [ -n "${bad_refs}" ]; then
extended_findings+=("Workflows reference actions @main/@master (pin versions): see log excerpt")
{
printf '%s\n' '### Workflow pinning advisory'
printf '%s\n' 'Found uses: entries pinned to main/master:'
printf '%s\n' '```'
printf '%s\n' "${bad_refs}"
printf '%s\n' '```'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
fi
if [ -f "${DOCS_INDEX}" ]; then
missing_links=""
while IFS= read -r docline; do
for link in $(echo "$docline" | grep -oE '\]\([^)]+\)' | sed 's/\](//' | sed 's/)$//' || true); do
case "$link" in http://*|https://*|"#"*|mailto:*) continue ;; esac
linkpath="${link%%#*}"
linkpath="${linkpath%%\?*}"
[ -z "$linkpath" ] && continue
if [ "${linkpath:0:1}" = "/" ]; then
testpath="${linkpath#/}"
else
testpath="$(dirname "${DOCS_INDEX}")/${linkpath}"
fi
[ ! -e "$testpath" ] && missing_links="${missing_links}${testpath} "
done
done < "${DOCS_INDEX}"
if [ -n "${missing_links}" ]; then
extended_findings+=("docs/docs-index.md contains broken relative links")
{
printf '%s\n' '### Docs index link integrity'
printf '%s\n' 'Broken relative links:'
for bl in ${missing_links}; do
printf '%s\n' "- ${bl}"
done
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
fi
if [ -d "${SCRIPT_DIR}" ]; then
if ! command -v shellcheck >/dev/null 2>&1; then
sudo apt-get update -qq
sudo apt-get install -y shellcheck >/dev/null
fi
sc_out=''
while IFS= read -r shf; do
[ -z "${shf}" ] && continue
out_one="$(shellcheck -S warning -x "${shf}" 2>/dev/null || true)"
if [ -n "${out_one}" ]; then
sc_out="${sc_out}${out_one}\n"
fi
done < <(find "${SCRIPT_DIR}" -type f -name "${SHELLCHECK_PATTERN}" 2>/dev/null | sort)
if [ -n "${sc_out}" ]; then
extended_findings+=("ShellCheck warnings detected (advisory)")
sc_head="$(printf '%s' "${sc_out}" | head -n 200)"
{
printf '%s\n' '### ShellCheck (advisory)'
printf '%s\n' '```'
printf '%s\n' "${sc_head}"
printf '%s\n' '```'
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
fi
spdx_missing=()
IFS=',' read -r -a spdx_globs <<< "${SPDX_FILE_GLOBS}"
spdx_args=()
for g in "${spdx_globs[@]}"; do spdx_args+=("${g}"); done
while IFS= read -r f; do
[ -z "${f}" ] && continue
if ! head -n 40 "${f}" | grep -q 'SPDX-License-Identifier:'; then
spdx_missing+=("${f}")
fi
done < <(git ls-files "${spdx_args[@]}" 2>/dev/null || true)
if [ "${#spdx_missing[@]}" -gt 0 ]; then
extended_findings+=("SPDX header missing in some tracked files (advisory)")
{
printf '%s\n' '### SPDX header advisory'
printf '%s\n' 'Files missing SPDX-License-Identifier (first 40 lines scan):'
for f in "${spdx_missing[@]}"; do printf '%s\n' "- ${f}"; done
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
stale_cutoff_days=180
stale_branches="$(git for-each-ref --format='%(refname:short) %(committerdate:unix)' refs/remotes/origin 2>/dev/null | awk -v now="$(date +%s)" -v days="${stale_cutoff_days}" '{if (now-$2 > days*86400) print $1}' | head -50)"
if [ -n "${stale_branches}" ]; then
extended_findings+=("Stale remote branches detected (advisory)")
{
printf '%s\n' '### Git hygiene advisory'
printf '%s\n' "Branches with last commit older than ${stale_cutoff_days} days (sample up to 50):"
while IFS= read -r b; do [ -n "${b}" ] && printf '%s\n' "- ${b}"; done <<< "${stale_branches}"
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
fi
{
printf '%s\n' '### Guardrails coverage matrix'
printf '%s\n' '| Domain | Status | Notes |'
printf '%s\n' '|---|---|---|'
printf '%s\n' '| Access control | OK | Admin-only execution gate |'
printf '%s\n' '| Release policy | N/A | Releases handled by MokoGitea |'
printf '%s\n' '| Scripts governance | OK | Directory policy and advisory reporting |'
printf '%s\n' '| Repo required artifacts | OK | Required, optional, disallowed enforcement |'
printf '%s\n' '| Repo content heuristics | OK | Brand, license, changelog structure |'
if [ "${extended_enabled}" = 'true' ]; then
if [ "${#extended_findings[@]}" -gt 0 ]; then
printf '%s\n' '| Extended checks | Warning | See extended findings below |'
else
printf '%s\n' '| Extended checks | OK | No findings |'
fi
else
printf '%s\n' '| Extended checks | SKIPPED | EXTENDED_CHECKS disabled |'
fi
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
if [ "${extended_enabled}" = 'true' ] && [ "${#extended_findings[@]}" -gt 0 ]; then
{
printf '%s\n' '### Extended findings (advisory)'
for f in "${extended_findings[@]}"; do printf '%s\n' "- ${f}"; done
printf '\n'
} >> "${GITHUB_STEP_SUMMARY}"
fi
printf '%s\n' 'Repository health guardrails passed.' >> "${GITHUB_STEP_SUMMARY}"
site-health:
name: Site Health
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- name: Uptime check
if: env.URLS != ''
run: |
echo "$URLS" > /tmp/urls.txt
php monitoring/uptime-probe.php --urls /tmp/urls.txt --timeout 15 || echo "::warning::Some sites are down"
rm -f /tmp/urls.txt
env:
URLS: ${{ vars.MONITORED_URLS }}
- name: SSL certificate check
if: env.DOMAINS != ''
run: |
echo "$DOMAINS" > /tmp/domains.txt
php monitoring/ssl-check.php --domains /tmp/domains.txt --warn-days 30 || echo "::warning::SSL certificates expiring soon"
rm -f /tmp/domains.txt
env:
DOMAINS: ${{ vars.MONITORED_DOMAINS }}
- name: Summary
if: always()
run: |
echo "### Site Health" >> $GITHUB_STEP_SUMMARY
echo "Uptime and SSL checks completed." >> $GITHUB_STEP_SUMMARY
# ═══════════════════════════════════════════════════════════════════════
# Issue Reporter — file issues for failed gates
# ═══════════════════════════════════════════════════════════════════════
report-issues:
name: "Report Issues"
runs-on: ubuntu-latest
needs: [access_check, scripts_governance, repo_health]
if: >-
always() &&
(needs.scripts_governance.result == 'failure' ||
needs.repo_health.result == 'failure')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: automation/ci-issue-reporter.sh
sparse-checkout-cone-mode: false
- name: "File issues for failed gates"
env:
GITEA_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }}
run: |
chmod +x automation/ci-issue-reporter.sh
REPORTER="./automation/ci-issue-reporter.sh"
WF="Repo Health"
report_gate() {
local gate="$1" result="$2" details="$3"
if [ "$result" = "failure" ]; then
"$REPORTER" --gate "$gate" --details "$details" --workflow "$WF" --severity error
fi
}
report_gate "Scripts Governance" \
"${{ needs.scripts_governance.result }}" \
"Scripts directory policy violations detected. Review required and allowed directories."
report_gate "Repository Health" \
"${{ needs.repo_health.result }}" \
"Repository health checks failed — missing required artifacts, disallowed files, or content warnings. Check the CI run summary."
+27 -26
View File
@@ -73,23 +73,25 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MOKOGITEA_TOKEN }}
token: ${{ secrets.GA_TOKEN }}
fetch-depth: 0
- name: Setup moko-platform tools
env:
MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }}
MOKO_CLONE_TOKEN: ${{ secrets.GA_TOKEN }}
MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting
COMPOSER_AUTH: '{"http-basic":{"git.mokoconsulting.tech":{"username":"token","password":"${{ secrets.MOKOGITEA_TOKEN }}"}}}'
COMPOSER_AUTH: '{"http-basic":{"git.mokoconsulting.tech":{"username":"token","password":"${{ secrets.GA_TOKEN }}"}}}'
run: |
if ! command -v composer &> /dev/null; then
sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1
fi
# Always fetch latest CLI tools — never use stale cache from previous runs
rm -rf /tmp/moko-platform
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/moko-platform.git" \
/tmp/moko-platform 2>/dev/null || true
if [ -d "/tmp/moko-platform" ]; then
echo "moko-platform already available — skipping clone"
else
git clone --depth 1 --branch main --quiet \
"https://x-access-token:${MOKO_CLONE_TOKEN}@${MOKO_CLONE_HOST}/moko-platform.git" \
/tmp/moko-platform 2>/dev/null || true
fi
if [ -d "/tmp/moko-platform" ] && [ -f "/tmp/moko-platform/composer.json" ]; then
cd /tmp/moko-platform && composer install --no-dev --no-interaction --quiet 2>/dev/null || true
fi
@@ -104,18 +106,16 @@ jobs:
run: |
BRANCH="${{ github.ref_name }}"
# Configure git for bot pushes
# Auto-bump patch version
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
git remote set-url origin "https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git"
# Auto-bump patch version
php ${MOKO_CLI}/version_bump.php --path . 2>/dev/null || true
VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null || echo "0.0.0")
# Strip any existing suffix before applying stability
VERSION=$(echo "$VERSION" | sed 's/-\(dev\|alpha\|beta\|rc\)$//')
# Propagate version to all manifest files
php ${MOKO_CLI}/version_set_platform.php --path . --version "$VERSION" --branch "$BRANCH" 2>/dev/null || true
php ${MOKO_CLI}/version_check.php --path . --fix 2>/dev/null || true
# Determine stability from branch or manual input
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
@@ -139,13 +139,12 @@ jobs:
*) SUFFIX=""; TAG="stable" ;;
esac
# Propagate version with stability suffix to all manifest files
php ${MOKO_CLI}/version_set_platform.php \
--path . --version "$VERSION" --branch "$BRANCH" --stability "$STABILITY" 2>/dev/null || true
php ${MOKO_CLI}/version_check.php --path . --fix 2>/dev/null || true
# Re-read version (now includes suffix from version_set_platform)
# Append suffix to all manifest <version> tags (non-stable only)
if [ -n "$SUFFIX" ]; then
find . -maxdepth 4 -name "*.xml" ! -path "./.git/*" ! -path "./build/*" \
-exec grep -l "<version>${VERSION}</version>" {} \; 2>/dev/null | while read f; do
sed -i "s|<version>${VERSION}</version>|<version>${VERSION}${SUFFIX}</version>|g" "$f"
done
VERSION="${VERSION}${SUFFIX}"
fi
@@ -173,13 +172,13 @@ jobs:
# Create or update Gitea release
php ${MOKO_CLI}/release_create.php \
--path . --version "$VERSION" --tag "$TAG" \
--token "${{ secrets.MOKOGITEA_TOKEN }}" --api-base "$API_BASE" \
--token "${{ secrets.GA_TOKEN }}" --api-base "$API_BASE" \
--repo "${GITEA_REPO}" --branch "${{ github.ref_name }}" --prerelease
# Build package and upload
php ${MOKO_CLI}/release_package.php \
--path . --version "$VERSION" --tag "$TAG" \
--token "${{ secrets.MOKOGITEA_TOKEN }}" --api-base "$API_BASE" \
--token "${{ secrets.GA_TOKEN }}" --api-base "$API_BASE" \
--repo "${GITEA_REPO}" --output /tmp || true
- name: Update updates.xml
@@ -203,6 +202,8 @@ jobs:
${SHA_FLAG}
# Commit and push updates.xml
git config --local user.email "gitea-actions[bot]@mokoconsulting.tech"
git config --local user.name "gitea-actions[bot]"
git add updates.xml
git diff --cached --quiet || {
git commit -m "chore: update ${STABILITY} channel ${VERSION} [skip ci]"
@@ -213,9 +214,9 @@ jobs:
if: github.ref_name != 'main' && steps.platform.outputs.platform == 'joomla'
run: |
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
GITEA_TOKEN="${{ secrets.MOKOGITEA_TOKEN }}"
GA_TOKEN="${{ secrets.GA_TOKEN }}"
FILE_SHA=$(curl -sf -H "Authorization: token ${GITEA_TOKEN}" \
FILE_SHA=$(curl -sf -H "Authorization: token ${GA_TOKEN}" \
"${API_BASE}/contents/updates.xml?ref=main" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sha',''))" 2>/dev/null || true)
if [ -n "$FILE_SHA" ] && [ -f "updates.xml" ]; then
@@ -233,7 +234,7 @@ jobs:
'${API_BASE}/contents/updates.xml',
data=payload, method='PUT',
headers={
'Authorization': 'token ${GITEA_TOKEN}',
'Authorization': 'token ${GA_TOKEN}',
'Content-Type': 'application/json'
})
try:
@@ -259,7 +260,7 @@ jobs:
ACTOR="${{ github.actor }}"
API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"
PERMISSION=$(curl -sf -H "Authorization: token ${{ secrets.MOKOGITEA_TOKEN }}" \
PERMISSION=$(curl -sf -H "Authorization: token ${{ secrets.GA_TOKEN }}" \
"${API_BASE}/collaborators/${ACTOR}/permission" 2>/dev/null | \
python3 -c "import sys,json; print(json.load(sys.stdin).get('permission','read'))" 2>/dev/null || echo "read")
case "$PERMISSION" in
+35
View File
@@ -20,3 +20,38 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Perfect Publisher Pro migration tool in installer script
- Message template system with per-platform placeholders
- Post queue with scheduled posting, retry logic, and delivery tracking
- Core cross-posting engine: service plugin dispatch, duplicate guard, immediate execution
- System plugin listens to both `onContentAfterSave` and `onContentChangeState` for publish events
- Full admin templates: services list, post queue list, activity logs list, dashboard with recent activity
- Service edit form with default/custom mode toggle and credential fields
- Dashboard migration controller action for Perfect Publisher Pro import
- Template placeholders: {title}, {url}, {introtext}, {fulltext}, {image}, {category}, {author}, {date}
- Queue processing: Joomla Scheduled Task plugin (`plg_task_mokojoomcross`) — preferred method
- Queue processing: Page-load fallback via system plugin `onAfterRender` with configurable throttle
- Configurable processing method: scheduler-only (recommended), page-load only, or both
- Dashboard warning banner when page-load processing is active instead of scheduler
- Shared `QueueProcessor` helper with DB lock to prevent concurrent execution
- Failed post retry with configurable max retries and delay
- Automatic log cleanup based on configurable retention period
- PP Pro migration rewritten: reads #__autotweet_channels table with credential mapping per service type
- PP Pro migration fallback: extracts from component params when channel table missing
- Plugin-level config forms for Telegram, Facebook, Discord, Slack (default bot tokens stored in plugin params)
- Telegram plugin config: default bot token, parse mode, link preview toggle
- Facebook plugin config: default page access token, default page ID
- Discord plugin config: default webhook URL, embed color
- Slack plugin config: default webhook URL
- LinkedIn plugin config: OAuth client ID/secret, redirect URI
- Mastodon plugin config: default instance URL, visibility, hashtags
- Bluesky plugin config: default PDS URL, auto link cards
- Mailchimp plugin config: default sender name/email, auto-send toggle
- Template management: full CRUD with list/edit views, placeholder reference panel
- Templates submenu item and dashboard quick link
- Logs filter form with level and search filters
- Admin component now has 5 submenu items: Dashboard, Post Queue, Services, Templates, Logs
- Per-article cross-posting: skip toggle and service checkboxes in article editor attribs tab
- Content plugin injects dynamic "Cross-Posting" fieldset via onContentPrepareForm
- System plugin reads article attribs for mokojoomcross_services and mokojoomcross_skip
- Analytics dashboard: posts-by-service table with success rates, top articles, daily trend data
- OAuth helper: authorization URL generation, PKCE for Twitter, code exchange, token storage
- OAuth controller: authorize and callback endpoints for Facebook, LinkedIn, Twitter
- Wiki: Services guide, REST API reference, Message Templates, Troubleshooting
-161
View File
@@ -1,161 +0,0 @@
# Contributing to Moko Consulting Projects
Thank you for your interest in contributing. All Moko Consulting repositories follow this universal workflow and version policy.
## Branching Workflow
```
feature/* ──PR──> dev ──draft PR──> (renamed to rc) ──merge──> main
```
### Step by step
1. **Create a feature branch** from `dev`:
```bash
git checkout dev && git pull
git checkout -b feature/my-change
```
2. **Work and commit** on your feature branch. Push to origin.
3. **Open a PR**: `feature/my-change` → `dev`. After review and checks, merge it.
4. **When ready for release**, open a **draft PR**: `dev` → `main`.
- This automatically renames the source branch to `rc` (release candidate)
- An RC pre-release is built and uploaded
5. **Alpha and beta branches** are created by manually renaming the branch before the RC stage:
- Rename `dev` to `alpha` for early testing → alpha pre-release is built
- Rename `alpha` to `beta` for feature-complete testing → beta pre-release is built
- When the draft PR is created, the branch is renamed to `rc`
6. **Once PR checks pass** on the `rc` branch, mark the PR as ready and merge to `main`.
7. **Merging to main** triggers the stable release pipeline:
- Minor version bump (e.g., `02.09.xx` → `02.10.00`)
- Stability suffix stripped (clean version)
- Gitea release created with ZIP/tar.gz packages
- `updates.xml` updated (Joomla extensions)
- `dev` branch recreated from `main`
### Branch summary
| Branch | Purpose | Created by |
|--------|---------|-----------|
| `feature/*` | New features and fixes | Developer |
| `dev` | Integration branch | Auto-recreated after release |
| `alpha` | Alpha pre-release testing | Manual rename from `dev` |
| `beta` | Beta pre-release testing | Manual rename from `alpha` |
| `rc` | Release candidate | Auto-renamed on draft PR to main |
| `main` | Stable releases | Protected, merge only |
| `version/XX.YY.ZZ` | Archived release snapshots | Auto-created by CI |
### Protected branches
| Branch | Direct push | Merge via |
|--------|------------|-----------|
| `main` | Blocked (CI bot whitelisted) | PR merge only |
| `dev` | Blocked (CI bot whitelisted) | PR merge from feature/* |
| `rc` | Blocked (CI bot whitelisted) | Auto-created on draft PR |
| `alpha` | Blocked (CI bot whitelisted) | Manual rename |
| `beta` | Blocked (CI bot whitelisted) | Manual rename |
| `feature/*` | Open | N/A (source branch) |
## Version Policy
### Format
All versions use `XX.YY.ZZ` — three two-digit segments, zero-padded:
- **XX** — Major version (breaking changes)
- **YY** — Minor version (new features, bumped on release to main)
- **ZZ** — Patch version (auto-incremented on every push to dev/feature branches)
Rollover: patch `99` → `00` increments minor; minor `99` → `00` increments major.
### Stability suffixes
Each branch appends a suffix to indicate stability:
| Branch | Suffix | Example |
|--------|--------|---------|
| `main` | (none) | `02.09.00` |
| `dev` | `-dev` | `02.09.01-dev` |
| `feature/*` | `-dev` | `02.09.01-dev` |
| `alpha` | `-alpha` | `02.09.01-alpha` |
| `beta` | `-beta` | `02.09.01-beta` |
| `rc` | `-rc` | `02.09.01-rc` |
### Auto version bump
On every push to `dev`, `feature/*`, or `patch/*`:
1. Patch version incremented
2. Stability suffix `-dev` applied
3. All version-bearing files updated (manifests, CHANGELOG, PHP headers, etc.)
4. Commit created with `[skip ci]` to avoid loops
### Release version flow
Version bumps happen at specific release events:
| Event | Bump | Example |
|-------|------|---------|
| Feature merged to dev | Patch bump after dev release | `02.09.01-dev` → release → `02.09.02-dev` |
| Dev promoted to RC | Minor bump | `02.09.02-dev` → `02.10.00-rc` |
| RC merged to main | Minor bump | `02.10.00-rc` → `02.11.00` (stable) |
| Dev recreated from main | Patch bump | `02.11.00` → `02.11.01-dev` |
### Release stream copies
When a higher-stability release is published, copies are created for all lesser streams with the same base version:
- **RC `02.10.00-rc`** also creates: `02.10.00-dev`, `02.10.00-alpha`, `02.10.00-beta`
- **Stable `02.11.00`** also creates: `02.11.00-dev`, `02.11.00-alpha`, `02.11.00-beta`, `02.11.00-rc`
This ensures Joomla sites on ANY stability channel see the update (Joomla only shows versions higher than what's installed).
### Version files
The version tools update all files containing version stamps:
- `.mokogitea/manifest.xml` (canonical source)
- Joomla XML manifests (`<version>` tag)
- `README.md`, `CHANGELOG.md` (`VERSION:` pattern)
- `package.json`, `pyproject.toml`
- Any text file with a `VERSION: XX.YY.ZZ` label
Files synced from other repos (with a `# REPO:` header) are not touched.
## Code Standards
- **PHP**: PSR-12, tabs for indentation
- **Copyright**: all files must include the Moko Consulting copyright header
- **License**: SPDX identifier `GPL-3.0-or-later` (or as specified per repo)
- **Attribution**: use `Authored-by: Moko Consulting` in commits, not individual names
## Commit Messages
Use conventional commit format:
```
type(scope): short description
Optional body with context.
Authored-by: Moko Consulting
```
Types: `feat`, `fix`, `chore`, `docs`, `style`, `refactor`, `test`, `ci`
Special flags in commit messages:
- `[skip ci]` — skip all CI workflows
- `[skip bump]` — skip auto version bump only
## Reporting Issues
Use the repository's issue tracker with the appropriate template.
---
*Moko Consulting <hello@mokoconsulting.tech>*
+1 -1
View File
@@ -1,6 +1,6 @@
# MokoJoomCross
<!-- VERSION: 01.00.00-dev -->
<!-- VERSION: 01.00.06-dev -->
Cross-posting Joomla content to social media, email marketing, and chat platforms for Joomla 5/6.
-237
View File
@@ -1,237 +0,0 @@
#!/usr/bin/env bash
# ============================================================================
# Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# FILE INFORMATION
# DEFGROUP: Automation.CI
# INGROUP: moko-platform.Automation
# REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
# PATH: /automation/ci-issue-reporter.sh
# VERSION: 09.23.00
# BRIEF: Creates or updates a Gitea issue when a CI gate fails.
# Deduplicates by searching open issues with the "ci-auto" label
# whose title matches the gate. If a matching issue exists, a comment
# is appended instead of opening a duplicate.
# ============================================================================
set -euo pipefail
# ── Defaults ────────────────────────────────────────────────────────────────
GITEA_URL="${GITEA_URL:-https://git.mokoconsulting.tech}"
GITEA_TOKEN="${GITEA_TOKEN:-}"
REPO="${GITHUB_REPOSITORY:-}"
RUN_URL="${GITHUB_SERVER_URL:-${GITEA_URL}}/${REPO}/actions/runs/${GITHUB_RUN_ID:-0}"
LABEL_NAME="ci-auto"
LABEL_COLOR="#e11d48"
GATE=""
DETAILS=""
SEVERITY="error"
WORKFLOW=""
# ── Parse arguments ─────────────────────────────────────────────────────────
usage() {
cat <<EOF
Usage: ci-issue-reporter.sh --gate NAME --details TEXT [OPTIONS]
Required:
--gate CI gate name (e.g. "Code Quality", "Self-Health")
--details Human-readable failure description
Optional:
--severity "error" (default) or "warning"
--workflow Workflow name for the issue title
--repo owner/repo (default: \$GITHUB_REPOSITORY)
--run-url URL to the CI run (auto-detected from env)
--token Gitea API token (default: \$GITEA_TOKEN)
--url Gitea base URL (default: \$GITEA_URL)
EOF
exit 1
}
while [[ $# -gt 0 ]]; do
case "$1" in
--gate) GATE="$2"; shift 2 ;;
--details) DETAILS="$2"; shift 2 ;;
--severity) SEVERITY="$2"; shift 2 ;;
--workflow) WORKFLOW="$2"; shift 2 ;;
--repo) REPO="$2"; shift 2 ;;
--run-url) RUN_URL="$2"; shift 2 ;;
--token) GITEA_TOKEN="$2"; shift 2 ;;
--url) GITEA_URL="$2"; shift 2 ;;
-h|--help) usage ;;
*) echo "Unknown option: $1"; usage ;;
esac
done
[[ -z "$GATE" ]] && { echo "ERROR: --gate is required"; usage; }
[[ -z "$DETAILS" ]] && { echo "ERROR: --details is required"; usage; }
[[ -z "$GITEA_TOKEN" ]] && { echo "ERROR: GITEA_TOKEN not set"; exit 1; }
[[ -z "$REPO" ]] && { echo "ERROR: GITHUB_REPOSITORY not set"; exit 1; }
API="${GITEA_URL}/api/v1/repos/${REPO}"
# ── Build title ─────────────────────────────────────────────────────────────
if [[ -n "$WORKFLOW" ]]; then
TITLE="[CI] ${WORKFLOW}: ${GATE} failed"
else
TITLE="[CI] ${GATE} failed"
fi
# ── Ensure label exists ─────────────────────────────────────────────────────
ensure_label() {
local exists
exists=$(curl -sf -o /dev/null -w '%{http_code}' \
-H "Authorization: token ${GITEA_TOKEN}" \
"${API}/labels" 2>/dev/null || echo "000")
if [[ "$exists" == "200" ]]; then
# Check if label already exists
local found
found=$(curl -sf \
-H "Authorization: token ${GITEA_TOKEN}" \
"${API}/labels" 2>/dev/null \
| grep -o "\"name\":\"${LABEL_NAME}\"" || true)
if [[ -z "$found" ]]; then
curl -sf -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/labels" \
-d "{\"name\":\"${LABEL_NAME}\",\"color\":\"${LABEL_COLOR}\",\"description\":\"Auto-created by CI issue reporter\"}" \
> /dev/null 2>&1 || true
fi
fi
}
# ── Search for existing open issue ──────────────────────────────────────────
find_existing_issue() {
# URL-encode the gate name for the query
local query
query=$(printf '%s' "[CI] ${GATE}" | sed 's/ /%20/g; s/\[/%5B/g; s/\]/%5D/g')
local response
response=$(curl -sf \
-H "Authorization: token ${GITEA_TOKEN}" \
"${API}/issues?type=issues&state=open&labels=${LABEL_NAME}&q=${query}&limit=5" \
2>/dev/null || echo "[]")
# Extract the first matching issue number
echo "$response" \
| grep -oP '"number":\s*\K[0-9]+' \
| head -1
}
# ── Build issue body ────────────────────────────────────────────────────────
build_body() {
local severity_badge
if [[ "$SEVERITY" == "error" ]]; then
severity_badge="**Severity:** Error"
else
severity_badge="**Severity:** Warning"
fi
cat <<BODY
## CI Gate Failure: ${GATE}
${severity_badge}
**Workflow:** ${WORKFLOW:-unknown}
**Branch:** ${GITHUB_REF_NAME:-unknown}
**Commit:** \`${GITHUB_SHA:0:8}\`
**Run:** [View CI run](${RUN_URL})
### Details
${DETAILS}
### Resolution
Fix the issue described above and push a new commit. This issue will be closed automatically when the gate passes, or can be closed manually.
---
*Auto-created by [ci-issue-reporter](${GITEA_URL}/${REPO}/src/branch/main/automation/ci-issue-reporter.sh)*
BODY
}
# ── Build comment body (for existing issues) ────────────────────────────────
build_comment() {
cat <<COMMENT
### CI failure recurrence
**Branch:** ${GITHUB_REF_NAME:-unknown}
**Commit:** \`${GITHUB_SHA:0:8}\`
**Run:** [View CI run](${RUN_URL})
${DETAILS}
COMMENT
}
# ── Main ────────────────────────────────────────────────────────────────────
ensure_label
EXISTING=$(find_existing_issue)
if [[ -n "$EXISTING" ]]; then
# Append comment to existing issue
COMMENT_BODY=$(build_comment)
COMMENT_JSON=$(printf '%s' "$COMMENT_BODY" | python3 -c "
import sys, json
print(json.dumps({'body': sys.stdin.read()}))" 2>/dev/null)
HTTP=$(curl -sf -o /dev/null -w '%{http_code}' -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/issues/${EXISTING}/comments" \
-d "${COMMENT_JSON}" 2>/dev/null || echo "000")
if [[ "$HTTP" == "201" ]]; then
echo "Commented on existing issue #${EXISTING}"
else
echo "WARNING: Failed to comment on issue #${EXISTING} (HTTP ${HTTP})"
fi
else
# Create new issue
ISSUE_BODY=$(build_body)
ISSUE_JSON=$(python3 -c "
import sys, json
body = sys.stdin.read()
print(json.dumps({
'title': sys.argv[1],
'body': body,
'labels': []
}))" "$TITLE" <<< "$ISSUE_BODY" 2>/dev/null)
# Create the issue
RESPONSE=$(curl -sf -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/issues" \
-d "${ISSUE_JSON}" 2>/dev/null || echo "{}")
ISSUE_NUM=$(echo "$RESPONSE" | grep -oP '"number":\s*\K[0-9]+' | head -1)
if [[ -n "$ISSUE_NUM" ]]; then
# Apply label (separate call — more reliable across Gitea versions)
LABEL_ID=$(curl -sf \
-H "Authorization: token ${GITEA_TOKEN}" \
"${API}/labels" 2>/dev/null \
| grep -oP "\"id\":\s*\K[0-9]+(?=[^}]*\"name\":\s*\"${LABEL_NAME}\")" \
| head -1 || true)
if [[ -n "$LABEL_ID" ]]; then
curl -sf -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"${API}/issues/${ISSUE_NUM}/labels" \
-d "{\"labels\":[${LABEL_ID}]}" \
> /dev/null 2>&1 || true
fi
echo "Created issue #${ISSUE_NUM}: ${TITLE}"
else
echo "WARNING: Failed to create issue"
echo "Response: ${RESPONSE}"
fi
fi
+36
View File
@@ -51,4 +51,40 @@
rows="4"
/>
</fieldset>
<fieldset name="queue" label="COM_MOKOJOOMCROSS_CONFIG_QUEUE">
<field
name="queue_processing"
type="list"
label="COM_MOKOJOOMCROSS_CONFIG_QUEUE_PROCESSING"
description="COM_MOKOJOOMCROSS_CONFIG_QUEUE_PROCESSING_DESC"
default="scheduler">
<option value="scheduler">COM_MOKOJOOMCROSS_CONFIG_QUEUE_SCHEDULER</option>
<option value="pageload">COM_MOKOJOOMCROSS_CONFIG_QUEUE_PAGELOAD</option>
<option value="both">COM_MOKOJOOMCROSS_CONFIG_QUEUE_BOTH</option>
</field>
<field
name="pageload_client"
type="list"
label="COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_CLIENT"
description="COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_CLIENT_DESC"
default="both"
showon="queue_processing:pageload,both">
<option value="both">COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_BOTH</option>
<option value="admin">COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_ADMIN</option>
<option value="site">COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_SITE</option>
</field>
<field
name="pageload_interval"
type="number"
label="COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_INTERVAL"
description="COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_INTERVAL_DESC"
default="300"
min="60"
max="3600"
showon="queue_processing:pageload,both"
/>
</fieldset>
</config>
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="filter">
<field
name="search"
type="text"
label="COM_MOKOJOOMCROSS_FILTER_SEARCH"
hint="JSEARCH_FILTER"
/>
<field
name="level"
type="list"
label="COM_MOKOJOOMCROSS_FILTER_LEVEL"
onchange="this.form.submit();">
<option value="">COM_MOKOJOOMCROSS_SELECT_LEVEL</option>
<option value="info">Info</option>
<option value="warning">Warning</option>
<option value="error">Error</option>
</field>
</fields>
<fields name="list">
<field
name="fullordering"
type="list"
label="JGLOBAL_SORT_BY"
default="a.created DESC"
onchange="this.form.submit();">
<option value="">JGLOBAL_SORT_BY</option>
<option value="a.created ASC">COM_MOKOJOOMCROSS_CREATED_ASC</option>
<option value="a.created DESC">COM_MOKOJOOMCROSS_CREATED_DESC</option>
<option value="a.level ASC">COM_MOKOJOOMCROSS_LEVEL_ASC</option>
<option value="a.level DESC">COM_MOKOJOOMCROSS_LEVEL_DESC</option>
</field>
</fields>
</form>
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="filter">
<field
name="search"
type="text"
label="COM_MOKOJOOMCROSS_FILTER_SEARCH"
hint="JSEARCH_FILTER"
/>
<field
name="published"
type="status"
label="JOPTION_SELECT_PUBLISHED"
onchange="this.form.submit();">
<option value="">JOPTION_SELECT_PUBLISHED</option>
</field>
<field
name="service_type"
type="list"
label="COM_MOKOJOOMCROSS_FILTER_SERVICE_TYPE"
onchange="this.form.submit();">
<option value="">COM_MOKOJOOMCROSS_SELECT_SERVICE_TYPE</option>
<option value="default">Default</option>
<option value="facebook">Facebook</option>
<option value="twitter">X / Twitter</option>
<option value="linkedin">LinkedIn</option>
<option value="mastodon">Mastodon</option>
<option value="bluesky">Bluesky</option>
<option value="mailchimp">Mailchimp</option>
<option value="telegram">Telegram</option>
<option value="discord">Discord</option>
<option value="slack">Slack</option>
</field>
</fields>
<fields name="list">
<field
name="fullordering"
type="list"
label="JGLOBAL_SORT_BY"
default="a.ordering ASC"
onchange="this.form.submit();">
<option value="">JGLOBAL_SORT_BY</option>
<option value="a.title ASC">JGLOBAL_TITLE_ASC</option>
<option value="a.title DESC">JGLOBAL_TITLE_DESC</option>
<option value="a.ordering ASC">JGLOBAL_ORDERING_ASC</option>
</field>
</fields>
</form>
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="details">
<field
name="id"
type="hidden"
/>
<field
name="title"
type="text"
label="JGLOBAL_TITLE"
required="true"
size="40"
/>
<field
name="service_type"
type="list"
label="COM_MOKOJOOMCROSS_FIELD_SERVICE_TYPE"
description="COM_MOKOJOOMCROSS_TEMPLATE_SERVICE_TYPE_DESC"
default="default">
<option value="default">COM_MOKOJOOMCROSS_TEMPLATE_TYPE_DEFAULT</option>
<option value="facebook">Facebook</option>
<option value="twitter">X / Twitter</option>
<option value="linkedin">LinkedIn</option>
<option value="mastodon">Mastodon</option>
<option value="bluesky">Bluesky</option>
<option value="mailchimp">Mailchimp</option>
<option value="telegram">Telegram</option>
<option value="discord">Discord</option>
<option value="slack">Slack</option>
</field>
<field
name="template_body"
type="textarea"
label="COM_MOKOJOOMCROSS_TEMPLATE_BODY"
description="COM_MOKOJOOMCROSS_TEMPLATE_BODY_DESC"
rows="10"
cols="60"
required="true"
filter="raw"
/>
<field
name="published"
type="list"
label="JSTATUS"
default="1">
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
</field>
<field
name="ordering"
type="ordering"
label="JFIELD_ORDERING_LABEL"
/>
</fieldset>
</form>
@@ -58,3 +58,78 @@ COM_MOKOJOOMCROSS_CONFIG_LOG_RETENTION="Log Retention (days)"
COM_MOKOJOOMCROSS_CONFIG_LOG_RETENTION_DESC="Number of days to keep activity logs"
COM_MOKOJOOMCROSS_CONFIG_DEFAULT_TEMPLATE="Default Message Template"
COM_MOKOJOOMCROSS_CONFIG_DEFAULT_TEMPLATE_DESC="Default template for cross-posts. Placeholders: {title}, {url}, {introtext}, {image}, {category}, {author}"
; Table headings
COM_MOKOJOOMCROSS_HEADING_STATUS="Status"
COM_MOKOJOOMCROSS_HEADING_ARTICLE="Article"
COM_MOKOJOOMCROSS_HEADING_SERVICE="Service"
COM_MOKOJOOMCROSS_HEADING_MESSAGE="Message"
COM_MOKOJOOMCROSS_HEADING_POSTED_AT="Posted"
COM_MOKOJOOMCROSS_HEADING_CREATED="Created"
COM_MOKOJOOMCROSS_HEADING_LEVEL="Level"
COM_MOKOJOOMCROSS_HEADING_MODE="Mode"
; Dashboard
COM_MOKOJOOMCROSS_DASHBOARD_RECENT_ACTIVITY="Recent Activity"
COM_MOKOJOOMCROSS_DASHBOARD_NO_RECENT="No recent activity."
COM_MOKOJOOMCROSS_DASHBOARD_TOTAL_POSTS="Total Posts"
COM_MOKOJOOMCROSS_DASHBOARD_PAGELOAD_WARNING_TITLE="Page-load queue processing is active"
COM_MOKOJOOMCROSS_DASHBOARD_PAGELOAD_WARNING="You are using page-load processing for the cross-post queue. This is a fallback method and may be unreliable on low-traffic sites. For production use, switch to Joomla Scheduled Tasks: create a task of type <strong>MokoJoomCross - Process Queue</strong> in System → Scheduled Tasks, then set queue processing to <strong>Scheduler only</strong> in component options."
; Queue Processing Configuration
COM_MOKOJOOMCROSS_CONFIG_QUEUE="Queue Processing"
COM_MOKOJOOMCROSS_CONFIG_QUEUE_PROCESSING="Processing Method"
COM_MOKOJOOMCROSS_CONFIG_QUEUE_PROCESSING_DESC="How queued posts, retries, and scheduled posts are processed. Scheduler (recommended) uses Joomla's built-in Task Scheduler. Page-load piggybacks on page requests."
COM_MOKOJOOMCROSS_CONFIG_QUEUE_SCHEDULER="Scheduler only (recommended)"
COM_MOKOJOOMCROSS_CONFIG_QUEUE_PAGELOAD="Page-load only (fallback)"
COM_MOKOJOOMCROSS_CONFIG_QUEUE_BOTH="Both (scheduler + page-load)"
COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_CLIENT="Page-load Client"
COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_CLIENT_DESC="Which Joomla application triggers page-load processing."
COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_BOTH="Backend and Frontend"
COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_ADMIN="Backend only"
COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_SITE="Frontend only"
COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_INTERVAL="Page-load Interval (seconds)"
COM_MOKOJOOMCROSS_CONFIG_PAGELOAD_INTERVAL_DESC="Minimum seconds between page-load queue runs. Lower = more responsive but more DB queries per page load."
; Submenu (extended)
COM_MOKOJOOMCROSS_SUBMENU_TEMPLATES="Templates"
; Template Management
COM_MOKOJOOMCROSS_TEMPLATE_BODY="Template Body"
COM_MOKOJOOMCROSS_TEMPLATE_BODY_DESC="Message template with placeholders. Use the reference panel on the right for available placeholders."
COM_MOKOJOOMCROSS_TEMPLATE_SERVICE_TYPE_DESC="Which platform this template is for. 'Default' is the fallback when no platform-specific template exists."
COM_MOKOJOOMCROSS_TEMPLATE_TYPE_DEFAULT="Default (fallback)"
COM_MOKOJOOMCROSS_TEMPLATE_PREVIEW="Preview"
COM_MOKOJOOMCROSS_TEMPLATE_PLACEHOLDERS="Available Placeholders"
; Placeholders
COM_MOKOJOOMCROSS_PLACEHOLDER_TITLE="Article title"
COM_MOKOJOOMCROSS_PLACEHOLDER_URL="Article URL"
COM_MOKOJOOMCROSS_PLACEHOLDER_INTROTEXT="Intro text (280 chars, no HTML)"
COM_MOKOJOOMCROSS_PLACEHOLDER_FULLTEXT="Full text (500 chars, no HTML)"
COM_MOKOJOOMCROSS_PLACEHOLDER_IMAGE="Intro image URL"
COM_MOKOJOOMCROSS_PLACEHOLDER_CATEGORY="Category name"
COM_MOKOJOOMCROSS_PLACEHOLDER_AUTHOR="Author name"
COM_MOKOJOOMCROSS_PLACEHOLDER_DATE="Publish date (YYYY-MM-DD)"
; Logs
COM_MOKOJOOMCROSS_FILTER_LEVEL="Level"
COM_MOKOJOOMCROSS_SELECT_LEVEL="- Select Level -"
COM_MOKOJOOMCROSS_LEVEL_ASC="Level ascending"
COM_MOKOJOOMCROSS_LEVEL_DESC="Level descending"
; Analytics Dashboard
COM_MOKOJOOMCROSS_DASHBOARD_SERVICE_BREAKDOWN="Posts by Service"
COM_MOKOJOOMCROSS_DASHBOARD_TOP_ARTICLES="Most Cross-Posted Articles"
COM_MOKOJOOMCROSS_DASHBOARD_SUCCESS_RATE="Success Rate"
; OAuth
COM_MOKOJOOMCROSS_OAUTH_NO_SERVICE="No service specified for OAuth authorization."
COM_MOKOJOOMCROSS_OAUTH_SERVICE_NOT_FOUND="Service not found."
COM_MOKOJOOMCROSS_OAUTH_NO_CLIENT_ID="No OAuth Client ID configured for %s. Set it in Extensions → Plugins → MokoJoomCross - %s."
COM_MOKOJOOMCROSS_OAUTH_NOT_SUPPORTED="OAuth is not supported for %s."
COM_MOKOJOOMCROSS_OAUTH_PLATFORM_ERROR="Platform returned error: %s"
COM_MOKOJOOMCROSS_OAUTH_INVALID_CALLBACK="Invalid OAuth callback — missing code or state."
COM_MOKOJOOMCROSS_OAUTH_INVALID_STATE="Invalid OAuth state parameter."
COM_MOKOJOOMCROSS_OAUTH_TOKEN_ERROR="Token exchange failed: %s"
COM_MOKOJOOMCROSS_OAUTH_SUCCESS="%s connected successfully! Access token stored."
@@ -7,4 +7,5 @@ COM_MOKOJOOMCROSS_DESCRIPTION="Cross-posting Joomla content to social media, ema
COM_MOKOJOOMCROSS_SUBMENU_DASHBOARD="Dashboard"
COM_MOKOJOOMCROSS_SUBMENU_POSTS="Post Queue"
COM_MOKOJOOMCROSS_SUBMENU_SERVICES="Services"
COM_MOKOJOOMCROSS_SUBMENU_TEMPLATES="Templates"
COM_MOKOJOOMCROSS_SUBMENU_LOGS="Activity Logs"
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="component" method="upgrade">
<name>com_mokojoomcross</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -48,6 +48,7 @@
<menu link="option=com_mokojoomcross&amp;view=dashboard">COM_MOKOJOOMCROSS_SUBMENU_DASHBOARD</menu>
<menu link="option=com_mokojoomcross&amp;view=posts">COM_MOKOJOOMCROSS_SUBMENU_POSTS</menu>
<menu link="option=com_mokojoomcross&amp;view=services">COM_MOKOJOOMCROSS_SUBMENU_SERVICES</menu>
<menu link="option=com_mokojoomcross&amp;view=templates">COM_MOKOJOOMCROSS_SUBMENU_TEMPLATES</menu>
<menu link="option=com_mokojoomcross&amp;view=logs">COM_MOKOJOOMCROSS_SUBMENU_LOGS</menu>
</submenu>
<files>
@@ -0,0 +1,59 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
use Joomla\Component\MokoJoomCross\Administrator\Helper\MigrationHelper;
class DashboardController extends BaseController
{
/**
* Run Perfect Publisher Pro migration.
*
* @return void
*/
public function migrate(): void
{
// Check ACL
if (!$this->app->getIdentity()->authorise('mokojoomcross.migrate', 'com_mokojoomcross')) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=dashboard', false),
Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'),
'error'
);
return;
}
$result = MigrationHelper::migrate();
if (!empty($result['errors'])) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=dashboard', false),
Text::sprintf('COM_MOKOJOOMCROSS_MIGRATION_ERROR', implode('; ', $result['errors'])),
'error'
);
return;
}
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=dashboard', false),
Text::sprintf('COM_MOKOJOOMCROSS_MIGRATION_SUCCESS', $result['migrated'], $result['skipped']),
'success'
);
}
}
@@ -0,0 +1,175 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\Component\MokoJoomCross\Administrator\Helper\OAuthHelper;
/**
* OAuth controller for handling browser-based authorization flows.
*
* Endpoints:
* task=oauth.authorize — Initiate OAuth flow (redirect to platform)
* task=oauth.callback — Handle platform redirect with auth code
*/
class OauthController extends BaseController
{
/**
* Initiate OAuth authorization for a service.
*
* Expects: service_id (int) in request
*/
public function authorize(): void
{
$serviceId = $this->input->getInt('service_id', 0);
if (!$serviceId) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=services', false),
Text::_('COM_MOKOJOOMCROSS_OAUTH_NO_SERVICE'),
'error'
);
return;
}
$db = \Joomla\CMS\Factory::getDbo();
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__mokojoomcross_services'))
->where($db->quoteName('id') . ' = ' . $serviceId);
$db->setQuery($query);
$service = $db->loadObject();
if (!$service) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=services', false),
Text::_('COM_MOKOJOOMCROSS_OAUTH_SERVICE_NOT_FOUND'),
'error'
);
return;
}
// Get client ID from plugin params
PluginHelper::importPlugin('mokojoomcross');
$pluginParams = PluginHelper::getPlugin('mokojoomcross', $service->service_type);
$params = json_decode($pluginParams->params ?? '{}', true) ?: [];
$clientId = $params['client_id'] ?? '';
if (empty($clientId)) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=services', false),
Text::sprintf('COM_MOKOJOOMCROSS_OAUTH_NO_CLIENT_ID', ucfirst($service->service_type)),
'error'
);
return;
}
$url = OAuthHelper::getAuthorizeUrl($service->service_type, $serviceId, $clientId);
if (!$url) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=services', false),
Text::sprintf('COM_MOKOJOOMCROSS_OAUTH_NOT_SUPPORTED', ucfirst($service->service_type)),
'error'
);
return;
}
$this->app->redirect($url);
}
/**
* Handle OAuth callback from platform.
*
* Expects: code (string), state (base64 JSON with service_id)
*/
public function callback(): void
{
$code = $this->input->getString('code', '');
$state = $this->input->getString('state', '');
$error = $this->input->getString('error', '');
if ($error) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=services', false),
Text::sprintf('COM_MOKOJOOMCROSS_OAUTH_PLATFORM_ERROR', $error),
'error'
);
return;
}
if (empty($code) || empty($state)) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=services', false),
Text::_('COM_MOKOJOOMCROSS_OAUTH_INVALID_CALLBACK'),
'error'
);
return;
}
$stateData = json_decode(base64_decode($state), true);
$serviceId = (int) ($stateData['service_id'] ?? 0);
$serviceType = $stateData['type'] ?? '';
if (!$serviceId || !$serviceType) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&view=services', false),
Text::_('COM_MOKOJOOMCROSS_OAUTH_INVALID_STATE'),
'error'
);
return;
}
// Get client credentials from plugin params
PluginHelper::importPlugin('mokojoomcross');
$pluginParams = PluginHelper::getPlugin('mokojoomcross', $serviceType);
$params = json_decode($pluginParams->params ?? '{}', true) ?: [];
$clientId = $params['client_id'] ?? '';
$clientSecret = $params['client_secret'] ?? '';
$tokenData = OAuthHelper::exchangeCode($serviceType, $code, $clientId, $clientSecret);
if (!empty($tokenData['error'])) {
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&task=service.edit&id=' . $serviceId, false),
Text::sprintf('COM_MOKOJOOMCROSS_OAUTH_TOKEN_ERROR', $tokenData['error']),
'error'
);
return;
}
OAuthHelper::storeToken($serviceId, $tokenData);
$this->setRedirect(
Route::_('index.php?option=com_mokojoomcross&task=service.edit&id=' . $serviceId, false),
Text::sprintf('COM_MOKOJOOMCROSS_OAUTH_SUCCESS', ucfirst($serviceType)),
'success'
);
}
}
@@ -0,0 +1,20 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\FormController;
class TemplateController extends FormController
{
}
@@ -0,0 +1,24 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\AdminController;
class TemplatesController extends AdminController
{
public function getModel($name = 'Template', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
}
@@ -16,28 +16,42 @@ defined('_JEXEC') or die;
use Joomla\CMS\Factory;
/**
* Migration helper for importing settings from Perfect Publisher Pro.
* Migration helper for importing settings from Perfect Publisher Pro (com_autotweet).
*
* Reads Perfect Publisher Pro's component params and plugin configurations
* and maps them to MokoJoomCross service records.
* PP Pro stores channels in #__autotweet_channels with a channeltype_id FK
* to #__autotweet_channeltypes. Each channel has a JSON params column
* containing OAuth tokens, API keys, webhook URLs, etc.
*
* This helper reads those channels and creates MokoJoomCross service records.
*/
class MigrationHelper
{
/**
* Service type mapping from Perfect Publisher Pro to MokoJoomCross.
*
* @var array
* Channel type name → MokoJoomCross service type mapping.
* PP Pro channeltype names vary; we match common patterns.
*/
private const SERVICE_MAP = [
'facebook' => 'facebook',
'twitter' => 'twitter',
'linkedin' => 'linkedin',
'telegram' => 'telegram',
private const CHANNEL_MAP = [
'facebook' => 'facebook',
'fb' => 'facebook',
'twitter' => 'twitter',
'tw' => 'twitter',
'linkedin' => 'linkedin',
'li' => 'linkedin',
'telegram' => 'telegram',
'tg' => 'telegram',
'discord' => 'discord',
'slack' => 'slack',
'mastodon' => 'mastodon',
];
/**
* Run the full migration from Perfect Publisher Pro.
*
* Strategy:
* 1. Try reading #__autotweet_channels (PP Pro's channel table)
* 2. Fall back to reading component params if table doesn't exist
* 3. Create disabled MokoJoomCross service records
*
* @return array ['migrated' => int, 'skipped' => int, 'errors' => string[]]
*/
public static function migrate(): array
@@ -45,44 +59,106 @@ class MigrationHelper
$db = Factory::getDbo();
$result = ['migrated' => 0, 'skipped' => 0, 'errors' => []];
// Read Perfect Publisher Pro component params
// Check if PP Pro is installed
if (!self::isPPProInstalled($db)) {
$result['errors'][] = 'Perfect Publisher Pro (com_autotweet) is not installed.';
return $result;
}
// Try channel-based migration first (PP Pro stores configs in #__autotweet_channels)
if (self::hasChannelTable($db)) {
$result = self::migrateFromChannels($db, $result);
} else {
// Fall back to component params extraction
$result = self::migrateFromParams($db, $result);
}
// Clear migration flag from MokoJoomCross params
self::clearMigrationFlag($db);
return $result;
}
/**
* Check if PP Pro is installed.
*/
private static function isPPProInstalled($db): bool
{
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->select('COUNT(*)')
->from($db->quoteName('#__extensions'))
->where($db->quoteName('element') . ' LIKE ' . $db->quote('%perfectpublisher%'))
->where('(' . $db->quoteName('element') . ' = ' . $db->quote('com_autotweet')
. ' OR ' . $db->quoteName('element') . ' LIKE ' . $db->quote('%perfectpublisher%') . ')')
->where($db->quoteName('type') . ' = ' . $db->quote('component'));
$db->setQuery($query);
$rawParams = $db->loadResult();
if (!$rawParams) {
$result['errors'][] = 'Perfect Publisher Pro not found or has no configuration.';
return (int) $db->loadResult() > 0;
}
/**
* Check if the autotweet_channels table exists.
*/
private static function hasChannelTable($db): bool
{
$prefix = $db->getPrefix();
try {
$db->setQuery('SHOW TABLES LIKE ' . $db->quote($prefix . 'autotweet_channels'));
return !empty($db->loadResult());
} catch (\Throwable $e) {
return false;
}
}
/**
* Migrate from #__autotweet_channels table (primary method).
*/
private static function migrateFromChannels($db, array $result): array
{
// Load channels with their type names
$query = $db->getQuery(true)
->select('c.id, c.name, c.published, c.params')
->select($db->quoteName('ct.name', 'type_name'))
->from($db->quoteName('#__autotweet_channels', 'c'))
->join('LEFT', $db->quoteName('#__autotweet_channeltypes', 'ct')
. ' ON ' . $db->quoteName('ct.id') . ' = ' . $db->quoteName('c.channeltype_id'));
$db->setQuery($query);
$channels = $db->loadObjectList();
if (empty($channels)) {
$result['errors'][] = 'No channels found in Perfect Publisher Pro.';
return $result;
}
$params = json_decode($rawParams, true);
foreach ($channels as $channel) {
$typeName = strtolower(trim($channel->type_name ?? ''));
if (!is_array($params)) {
$result['errors'][] = 'Could not parse Perfect Publisher Pro configuration.';
// Match to MokoJoomCross service type
$mjcType = null;
return $result;
}
foreach (self::CHANNEL_MAP as $pattern => $serviceType) {
if (str_contains($typeName, $pattern)) {
$mjcType = $serviceType;
break;
}
}
// Iterate known service mappings and create MokoJoomCross service records
foreach (self::SERVICE_MAP as $ppKey => $mjcType) {
$credentials = self::extractCredentials($params, $ppKey);
if (empty($credentials)) {
if (!$mjcType) {
$result['skipped']++;
continue;
}
// Check if service already exists
// Check for duplicate (same type + migrated alias)
$alias = $mjcType . '-pp-' . $channel->id;
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__mokojoomcross_services'))
->where($db->quoteName('service_type') . ' = ' . $db->quote($mjcType));
->where($db->quoteName('alias') . ' = ' . $db->quote($alias));
$db->setQuery($query);
if ((int) $db->loadResult() > 0) {
@@ -90,60 +166,223 @@ class MigrationHelper
continue;
}
// Insert new service record
// Parse channel params to extract credentials
$channelParams = json_decode($channel->params ?: '{}', true) ?: [];
$credentials = self::mapChannelCredentials($mjcType, $channelParams);
if (empty($credentials)) {
$result['skipped']++;
continue;
}
// Create MokoJoomCross service record
$service = (object) [
'title' => ucfirst($mjcType) . ' (migrated from PP Pro)',
'alias' => $mjcType . '-migrated',
'title' => $channel->name ?: ucfirst($mjcType) . ' (PP Pro #' . $channel->id . ')',
'alias' => $alias,
'service_type' => $mjcType,
'credentials' => json_encode($credentials),
'params' => '{}',
'published' => 0, // Disabled until user verifies
'published' => 0, // Disabled user must verify before enabling
'ordering' => 0,
'created' => Factory::getDate()->toSql(),
'modified' => Factory::getDate()->toSql(),
'created_by' => Factory::getApplication()->getIdentity()->id ?? 0,
];
$db->insertObject('#__mokojoomcross_services', $service);
$result['migrated']++;
try {
$db->insertObject('#__mokojoomcross_services', $service);
$result['migrated']++;
} catch (\Throwable $e) {
$result['errors'][] = sprintf('Failed to create %s service: %s', $mjcType, $e->getMessage());
}
}
// Clear migration flag
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote('{}'))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$db->execute();
return $result;
}
/**
* Extract credentials for a specific service from PP Pro params.
* Map PP Pro channel params to MokoJoomCross credential format.
*
* @param array $params PP Pro component params
* @param string $serviceKey Service key in PP Pro params
*
* @return array Credential key/value pairs (empty if none found)
* PP Pro stores various keys in channel params depending on the type.
* We normalize them to MokoJoomCross's expected credential structure.
*/
private static function extractCredentials(array $params, string $serviceKey): array
private static function mapChannelCredentials(string $serviceType, array $channelParams): array
{
$credentials = [];
$creds = ['mode' => 'custom'];
// PP Pro uses various key patterns: {service}_app_id, {service}_api_key, etc.
$prefixes = [$serviceKey . '_', $serviceKey . 'api_', $serviceKey . '-'];
// Common OAuth fields PP Pro uses
$oauthFields = ['access_token', 'access_secret', 'client_id', 'client_secret',
'api_key', 'api_secret', 'app_id', 'app_secret', 'token'];
foreach ($params as $key => $value) {
foreach ($prefixes as $prefix) {
if (str_starts_with($key, $prefix) && !empty($value)) {
$cleanKey = str_replace($prefix, '', $key);
$credentials[$cleanKey] = $value;
switch ($serviceType) {
case 'facebook':
$creds['page_access_token'] = $channelParams['access_token'] ?? $channelParams['token'] ?? '';
$creds['page_id'] = $channelParams['page_id'] ?? $channelParams['pageid'] ?? '';
break;
case 'twitter':
$creds['bearer_token'] = $channelParams['bearer_token'] ?? '';
$creds['api_key'] = $channelParams['api_key'] ?? $channelParams['consumer_key'] ?? '';
$creds['api_secret'] = $channelParams['api_secret'] ?? $channelParams['consumer_secret'] ?? '';
$creds['access_token'] = $channelParams['access_token'] ?? '';
$creds['access_token_secret'] = $channelParams['access_secret'] ?? $channelParams['access_token_secret'] ?? '';
break;
case 'linkedin':
$creds['access_token'] = $channelParams['access_token'] ?? $channelParams['token'] ?? '';
$creds['organization_id'] = $channelParams['company_id'] ?? $channelParams['organization_id'] ?? '';
$creds['person_id'] = $channelParams['person_id'] ?? $channelParams['member_id'] ?? '';
break;
case 'telegram':
$creds['bot_token'] = $channelParams['bot_token'] ?? $channelParams['token'] ?? $channelParams['api_key'] ?? '';
$creds['chat_id'] = $channelParams['chat_id'] ?? $channelParams['channel_id'] ?? '';
break;
case 'discord':
$creds['webhook_url'] = $channelParams['webhook_url'] ?? $channelParams['webhook'] ?? '';
break;
case 'slack':
$creds['webhook_url'] = $channelParams['webhook_url'] ?? $channelParams['webhook'] ?? '';
break;
case 'mastodon':
$creds['instance_url'] = $channelParams['instance_url'] ?? $channelParams['server'] ?? '';
$creds['access_token'] = $channelParams['access_token'] ?? $channelParams['token'] ?? '';
break;
default:
// Generic: copy all non-empty params
foreach ($channelParams as $key => $value) {
if (!empty($value) && is_string($value)) {
$creds[$key] = $value;
}
}
}
// Remove empty credential values and the mode key for check
$check = array_filter($creds, fn($v, $k) => $k !== 'mode' && !empty($v), ARRAY_FILTER_USE_BOTH);
return empty($check) ? [] : $creds;
}
/**
* Fallback: migrate from component params when channel table doesn't exist.
*/
private static function migrateFromParams($db, array $result): array
{
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where('(' . $db->quoteName('element') . ' = ' . $db->quote('com_autotweet')
. ' OR ' . $db->quoteName('element') . ' LIKE ' . $db->quote('%perfectpublisher%') . ')')
->where($db->quoteName('type') . ' = ' . $db->quote('component'));
$db->setQuery($query);
$rawParams = $db->loadResult();
if (!$rawParams) {
$result['errors'][] = 'No PP Pro configuration found.';
return $result;
}
$params = json_decode($rawParams, true);
if (!is_array($params)) {
$result['errors'][] = 'Could not parse PP Pro configuration.';
return $result;
}
// Extract services from component params using prefix patterns
$servicePatterns = [
'facebook' => ['facebook_', 'fb_'],
'twitter' => ['twitter_', 'tw_'],
'linkedin' => ['linkedin_', 'li_'],
'telegram' => ['telegram_', 'tg_'],
];
foreach ($servicePatterns as $mjcType => $prefixes) {
$credentials = ['mode' => 'custom'];
$found = false;
foreach ($params as $key => $value) {
foreach ($prefixes as $prefix) {
if (str_starts_with($key, $prefix) && !empty($value)) {
$cleanKey = substr($key, strlen($prefix));
$credentials[$cleanKey] = $value;
$found = true;
}
}
}
if (!$found) {
$result['skipped']++;
continue;
}
// Duplicate check
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__mokojoomcross_services'))
->where($db->quoteName('service_type') . ' = ' . $db->quote($mjcType))
->where($db->quoteName('alias') . ' LIKE ' . $db->quote('%-migrated%'));
$db->setQuery($query);
if ((int) $db->loadResult() > 0) {
$result['skipped']++;
continue;
}
$service = (object) [
'title' => ucfirst($mjcType) . ' (migrated from PP Pro)',
'alias' => $mjcType . '-migrated',
'service_type' => $mjcType,
'credentials' => json_encode($credentials),
'params' => '{}',
'published' => 0,
'ordering' => 0,
'created' => Factory::getDate()->toSql(),
'modified' => Factory::getDate()->toSql(),
'created_by' => Factory::getApplication()->getIdentity()->id ?? 0,
];
try {
$db->insertObject('#__mokojoomcross_services', $service);
$result['migrated']++;
} catch (\Throwable $e) {
$result['errors'][] = sprintf('Failed to create %s: %s', $mjcType, $e->getMessage());
}
}
return $credentials;
return $result;
}
/**
* Clear the migration flag from MokoJoomCross component params.
*/
private static function clearMigrationFlag($db): void
{
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$params = json_decode($db->loadResult() ?: '{}', true) ?: [];
unset($params['migration_available'], $params['migration_source_params']);
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($params)))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$db->execute();
}
}
@@ -0,0 +1,204 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Uri\Uri;
/**
* OAuth helper for services requiring browser-based authorization.
*
* Handles the OAuth 2.0 authorization code flow:
* 1. Generate authorize URL → redirect user to platform
* 2. Platform redirects back with auth code
* 3. Exchange code for access token
* 4. Store token in service credentials
*
* Each platform has its own endpoints and scopes. The service plugin
* provides these via OAuthConfigInterface (if it supports OAuth).
*/
class OAuthHelper
{
/**
* OAuth endpoint configs per service type.
*/
private const OAUTH_CONFIGS = [
'facebook' => [
'authorize_url' => 'https://www.facebook.com/v19.0/dialog/oauth',
'token_url' => 'https://graph.facebook.com/v19.0/oauth/access_token',
'scopes' => 'pages_manage_posts,pages_read_engagement',
],
'linkedin' => [
'authorize_url' => 'https://www.linkedin.com/oauth/v2/authorization',
'token_url' => 'https://www.linkedin.com/oauth/v2/accessToken',
'scopes' => 'w_member_social',
],
'twitter' => [
'authorize_url' => 'https://twitter.com/i/oauth2/authorize',
'token_url' => 'https://api.twitter.com/2/oauth2/token',
'scopes' => 'tweet.read tweet.write users.read',
],
];
/**
* Build the authorization URL for a given service.
*
* @param string $serviceType Service type (facebook, linkedin, twitter)
* @param int $serviceId Service record ID (passed through state param)
* @param string $clientId OAuth client/app ID
*
* @return string|null Authorization URL or null if not supported
*/
public static function getAuthorizeUrl(string $serviceType, int $serviceId, string $clientId): ?string
{
$config = self::OAUTH_CONFIGS[$serviceType] ?? null;
if (!$config) {
return null;
}
$redirectUri = self::getCallbackUrl();
$state = base64_encode(json_encode(['service_id' => $serviceId, 'type' => $serviceType]));
$params = [
'client_id' => $clientId,
'redirect_uri' => $redirectUri,
'response_type' => 'code',
'scope' => $config['scopes'],
'state' => $state,
];
// Twitter uses PKCE
if ($serviceType === 'twitter') {
$verifier = bin2hex(random_bytes(32));
$challenge = rtrim(strtr(base64_encode(hash('sha256', $verifier, true)), '+/', '-_'), '=');
// Store verifier in session for token exchange
Factory::getApplication()->getSession()->set('mokojoomcross.pkce_verifier', $verifier);
$params['code_challenge'] = $challenge;
$params['code_challenge_method'] = 'S256';
}
return $config['authorize_url'] . '?' . http_build_query($params);
}
/**
* Exchange authorization code for access token.
*
* @param string $serviceType Service type
* @param string $code Authorization code from callback
* @param string $clientId OAuth client ID
* @param string $clientSecret OAuth client secret
*
* @return array ['access_token' => '...', 'expires_in' => N, ...] or ['error' => '...']
*/
public static function exchangeCode(string $serviceType, string $code, string $clientId, string $clientSecret): array
{
$config = self::OAUTH_CONFIGS[$serviceType] ?? null;
if (!$config) {
return ['error' => 'Unsupported service type for OAuth'];
}
$postData = [
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => self::getCallbackUrl(),
'client_id' => $clientId,
'client_secret' => $clientSecret,
];
// Twitter PKCE
if ($serviceType === 'twitter') {
$verifier = Factory::getApplication()->getSession()->get('mokojoomcross.pkce_verifier', '');
$postData['code_verifier'] = $verifier;
}
$ch = curl_init($config['token_url']);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($postData),
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($response, true) ?: [];
if ($httpCode >= 200 && $httpCode < 300 && !empty($data['access_token'])) {
return $data;
}
return ['error' => $data['error_description'] ?? $data['error'] ?? 'Token exchange failed'];
}
/**
* Store OAuth token in the service credentials.
*
* @param int $serviceId Service record ID
* @param array $tokenData Token response from platform
*
* @return bool
*/
public static function storeToken(int $serviceId, array $tokenData): bool
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('credentials'))
->from($db->quoteName('#__mokojoomcross_services'))
->where($db->quoteName('id') . ' = ' . $serviceId);
$db->setQuery($query);
$credentials = json_decode($db->loadResult() ?: '{}', true) ?: [];
$credentials['access_token'] = $tokenData['access_token'];
$credentials['mode'] = 'custom';
if (!empty($tokenData['refresh_token'])) {
$credentials['refresh_token'] = $tokenData['refresh_token'];
}
if (!empty($tokenData['expires_in'])) {
$credentials['token_expires'] = time() + (int) $tokenData['expires_in'];
}
$query = $db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_services'))
->set($db->quoteName('credentials') . ' = ' . $db->quote(json_encode($credentials)))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . $serviceId);
$db->setQuery($query);
$db->execute();
return true;
}
/**
* Get the OAuth callback URL for this Joomla installation.
*
* @return string
*/
public static function getCallbackUrl(): string
{
return Uri::root() . 'administrator/index.php?option=com_mokojoomcross&task=oauth.callback';
}
}
@@ -0,0 +1,371 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\MokoJoomCross\Administrator\Service\MokoJoomCrossServiceInterface;
/**
* Shared queue processor used by:
* - System plugin onAfterRender (page-load processing)
* - Task scheduler plugin (Joomla scheduled task)
*
* Handles: queued posts, failed retries, scheduled posts, and log cleanup.
* Uses a simple DB-based lock to prevent concurrent execution.
*/
class QueueProcessor
{
/**
* Process the post queue: dispatch queued posts, retry failed, fire scheduled.
*
* @param int $batchSize Max posts to process per run
*
* @return array ['processed' => int, 'succeeded' => int, 'failed' => int, 'skipped' => int]
*/
public static function processQueue(int $batchSize = 10): array
{
$result = ['processed' => 0, 'succeeded' => 0, 'failed' => 0, 'skipped' => 0];
if (!self::acquireLock()) {
$result['skipped'] = -1;
return $result;
}
try {
$db = Factory::getDbo();
$componentParams = ComponentHelper::getParams('com_mokojoomcross');
$maxRetry = (int) $componentParams->get('retry_max', 3);
$retryDelay = (int) $componentParams->get('retry_delay', 300);
$now = Factory::getDate()->toSql();
// Build service plugin map
$pluginMap = self::getServicePluginMap();
// 1. Process queued posts
$query = $db->getQuery(true)
->select('p.*, s.service_type, s.credentials, s.params AS service_params')
->from($db->quoteName('#__mokojoomcross_posts', 'p'))
->join('INNER', $db->quoteName('#__mokojoomcross_services', 's')
. ' ON ' . $db->quoteName('s.id') . ' = ' . $db->quoteName('p.service_id'))
->where($db->quoteName('p.status') . ' = ' . $db->quote('queued'))
->where('(' . $db->quoteName('p.scheduled_at') . ' IS NULL OR '
. $db->quoteName('p.scheduled_at') . ' <= ' . $db->quote($now) . ')')
->where($db->quoteName('s.published') . ' = 1')
->order($db->quoteName('p.created') . ' ASC')
->setLimit($batchSize);
$db->setQuery($query);
$queuedPosts = $db->loadObjectList() ?: [];
// 2. Process failed posts eligible for retry
$retryAfter = Factory::getDate('now - ' . $retryDelay . ' seconds')->toSql();
$query = $db->getQuery(true)
->select('p.*, s.service_type, s.credentials, s.params AS service_params')
->from($db->quoteName('#__mokojoomcross_posts', 'p'))
->join('INNER', $db->quoteName('#__mokojoomcross_services', 's')
. ' ON ' . $db->quoteName('s.id') . ' = ' . $db->quoteName('p.service_id'))
->where($db->quoteName('p.status') . ' = ' . $db->quote('failed'))
->where($db->quoteName('p.retry_count') . ' < ' . $maxRetry)
->where($db->quoteName('p.modified') . ' <= ' . $db->quote($retryAfter))
->where($db->quoteName('s.published') . ' = 1')
->order($db->quoteName('p.modified') . ' ASC')
->setLimit($batchSize);
$db->setQuery($query);
$retryPosts = $db->loadObjectList() ?: [];
$allPosts = array_merge($queuedPosts, $retryPosts);
foreach ($allPosts as $post) {
$result['processed']++;
$plugin = $pluginMap[$post->service_type] ?? null;
if (!$plugin) {
$result['skipped']++;
continue;
}
$isRetry = ($post->status === 'failed');
if ($isRetry) {
// Increment retry count
$newRetryCount = (int) $post->retry_count + 1;
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('retry_count') . ' = ' . $newRetryCount)
->where($db->quoteName('id') . ' = ' . (int) $post->id)
);
$db->execute();
}
// Mark as posting
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('posting'))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . (int) $post->id)
);
$db->execute();
$credentials = json_decode($post->credentials ?: '{}', true) ?: [];
$params = json_decode($post->service_params ?: '{}', true) ?: [];
try {
$apiResult = $plugin->publish($post->message, [], $credentials, $params);
if (!empty($apiResult['success'])) {
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('posted'))
->set($db->quoteName('platform_post_id') . ' = ' . $db->quote($apiResult['platform_post_id'] ?? ''))
->set($db->quoteName('platform_response') . ' = ' . $db->quote(json_encode($apiResult['response'] ?? [])))
->set($db->quoteName('posted_at') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . (int) $post->id)
);
$db->execute();
self::log($db, (int) $post->id, (int) $post->service_id, 'info',
sprintf('%s to %s (ID: %s)', $isRetry ? 'Retry succeeded' : 'Posted', $post->service_type, $apiResult['platform_post_id'] ?? 'n/a'));
$result['succeeded']++;
} else {
$errorMsg = $apiResult['response']['error'] ?? json_encode($apiResult['response'] ?? []);
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('failed'))
->set($db->quoteName('error_message') . ' = ' . $db->quote(mb_substr($errorMsg, 0, 1000)))
->set($db->quoteName('platform_response') . ' = ' . $db->quote(json_encode($apiResult['response'] ?? [])))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . (int) $post->id)
);
$db->execute();
self::log($db, (int) $post->id, (int) $post->service_id, 'error',
sprintf('Failed %s: %s', $post->service_type, mb_substr($errorMsg, 0, 500)));
$result['failed']++;
}
} catch (\Throwable $e) {
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('failed'))
->set($db->quoteName('error_message') . ' = ' . $db->quote(mb_substr($e->getMessage(), 0, 1000)))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . (int) $post->id)
);
$db->execute();
self::log($db, (int) $post->id, (int) $post->service_id, 'error',
sprintf('Exception %s: %s', $post->service_type, mb_substr($e->getMessage(), 0, 500)));
$result['failed']++;
}
}
// 3. Clean up old logs
self::cleanupLogs($db, $componentParams);
} finally {
self::releaseLock();
}
return $result;
}
/**
* Check if there are pending items in the queue.
*
* @return bool
*/
public static function hasPendingWork(): bool
{
$db = Factory::getDbo();
$componentParams = ComponentHelper::getParams('com_mokojoomcross');
$maxRetry = (int) $componentParams->get('retry_max', 3);
$retryDelay = (int) $componentParams->get('retry_delay', 300);
$retryAfter = Factory::getDate('now - ' . $retryDelay . ' seconds')->toSql();
$now = Factory::getDate()->toSql();
// Queued posts ready to go
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__mokojoomcross_posts'))
->where($db->quoteName('status') . ' = ' . $db->quote('queued'))
->where('(' . $db->quoteName('scheduled_at') . ' IS NULL OR '
. $db->quoteName('scheduled_at') . ' <= ' . $db->quote($now) . ')');
$db->setQuery($query);
$queued = (int) $db->loadResult();
// Failed posts eligible for retry
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__mokojoomcross_posts'))
->where($db->quoteName('status') . ' = ' . $db->quote('failed'))
->where($db->quoteName('retry_count') . ' < ' . $maxRetry)
->where($db->quoteName('modified') . ' <= ' . $db->quote($retryAfter));
$db->setQuery($query);
$retryable = (int) $db->loadResult();
return ($queued + $retryable) > 0;
}
/**
* Import mokojoomcross plugins and build a type → plugin instance map.
*
* @return array<string, MokoJoomCrossServiceInterface>
*/
private static function getServicePluginMap(): array
{
PluginHelper::importPlugin('mokojoomcross');
$servicePlugins = [];
try {
Factory::getApplication()->getDispatcher()->dispatch(
'onMokoJoomCrossGetServices',
new \Joomla\Event\Event('onMokoJoomCrossGetServices', [&$servicePlugins])
);
} catch (\Throwable $e) {
// Dispatcher may not be available in all contexts
}
$map = [];
foreach ($servicePlugins as $plugin) {
if ($plugin instanceof MokoJoomCrossServiceInterface) {
$map[$plugin->getServiceType()] = $plugin;
}
}
return $map;
}
/**
* Delete logs older than the configured retention period.
*/
private static function cleanupLogs($db, $componentParams): void
{
$retentionDays = (int) $componentParams->get('log_retention_days', 90);
if ($retentionDays <= 0) {
return;
}
$cutoff = Factory::getDate('now - ' . $retentionDays . ' days')->toSql();
$query = $db->getQuery(true)
->delete($db->quoteName('#__mokojoomcross_logs'))
->where($db->quoteName('created') . ' < ' . $db->quote($cutoff));
$db->setQuery($query);
$db->execute();
}
/**
* Simple DB-based lock to prevent concurrent queue processing.
*/
private static function acquireLock(): bool
{
$db = Factory::getDbo();
// Use component params as lock storage
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$params = json_decode($db->loadResult() ?: '{}', true) ?: [];
$lockTime = $params['_queue_lock'] ?? 0;
// Lock expires after 120 seconds (safety valve for crashed processes)
if ($lockTime > 0 && (time() - $lockTime) < 120) {
return false;
}
$params['_queue_lock'] = time();
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($params)))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$db->execute();
return true;
}
/**
* Release the processing lock.
*/
private static function releaseLock(): void
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$params = json_decode($db->loadResult() ?: '{}', true) ?: [];
unset($params['_queue_lock']);
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($params)))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$db->execute();
}
/**
* Write a log entry.
*/
private static function log($db, ?int $postId, ?int $serviceId, string $level, string $message): void
{
$log = (object) [
'post_id' => $postId,
'service_id' => $serviceId,
'level' => $level,
'message' => mb_substr($message, 0, 2000),
'context' => '{}',
'created' => Factory::getDate()->toSql(),
];
$db->insertObject('#__mokojoomcross_logs', $log);
}
}
@@ -70,4 +70,115 @@ class DashboardModel extends BaseDatabaseModel
return !empty($params['migration_available']);
}
/**
* Get recent activity log entries.
*
* @param int $limit Number of entries to return
*
* @return array
*/
public function getRecentActivity(int $limit = 10): array
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('l.*, s.title AS service_title, s.service_type')
->from($db->quoteName('#__mokojoomcross_logs', 'l'))
->join('LEFT', $db->quoteName('#__mokojoomcross_services', 's')
. ' ON ' . $db->quoteName('s.id') . ' = ' . $db->quoteName('l.service_id'))
->order($db->quoteName('l.created') . ' DESC');
$db->setQuery($query, 0, $limit);
return $db->loadObjectList() ?: [];
}
/**
* Get posts-per-service breakdown for the analytics chart.
*
* @return array [['service_type' => '...', 'posted' => N, 'failed' => N, 'queued' => N], ...]
*/
public function getServiceBreakdown(): array
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select([
$db->quoteName('s.service_type'),
$db->quoteName('s.title', 'service_title'),
'SUM(CASE WHEN ' . $db->quoteName('p.status') . ' = ' . $db->quote('posted') . ' THEN 1 ELSE 0 END) AS posted',
'SUM(CASE WHEN ' . $db->quoteName('p.status') . ' = ' . $db->quote('failed') . ' THEN 1 ELSE 0 END) AS failed',
'SUM(CASE WHEN ' . $db->quoteName('p.status') . ' = ' . $db->quote('queued') . ' THEN 1 ELSE 0 END) AS queued',
'COUNT(*) AS total',
])
->from($db->quoteName('#__mokojoomcross_posts', 'p'))
->join('INNER', $db->quoteName('#__mokojoomcross_services', 's')
. ' ON ' . $db->quoteName('s.id') . ' = ' . $db->quoteName('p.service_id'))
->group($db->quoteName(['s.id', 's.service_type', 's.title']))
->order('total DESC');
$db->setQuery($query);
return $db->loadAssocList() ?: [];
}
/**
* Get posts-per-day for the last N days (for trend chart).
*
* @param int $days Number of days to look back
*
* @return array [['day' => '2026-05-28', 'posted' => N, 'failed' => N], ...]
*/
public function getDailyTrend(int $days = 14): array
{
$db = $this->getDatabase();
$cutoff = Factory::getDate('now - ' . $days . ' days')->format('Y-m-d');
$query = $db->getQuery(true)
->select([
'DATE(' . $db->quoteName('created') . ') AS day',
'SUM(CASE WHEN ' . $db->quoteName('status') . ' = ' . $db->quote('posted') . ' THEN 1 ELSE 0 END) AS posted',
'SUM(CASE WHEN ' . $db->quoteName('status') . ' = ' . $db->quote('failed') . ' THEN 1 ELSE 0 END) AS failed',
'COUNT(*) AS total',
])
->from($db->quoteName('#__mokojoomcross_posts'))
->where('DATE(' . $db->quoteName('created') . ') >= ' . $db->quote($cutoff))
->group('DATE(' . $db->quoteName('created') . ')')
->order('day ASC');
$db->setQuery($query);
return $db->loadAssocList() ?: [];
}
/**
* Get most cross-posted articles.
*
* @param int $limit Number of articles
*
* @return array
*/
public function getTopArticles(int $limit = 5): array
{
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select([
$db->quoteName('c.id'),
$db->quoteName('c.title'),
'COUNT(*) AS post_count',
'SUM(CASE WHEN ' . $db->quoteName('p.status') . ' = ' . $db->quote('posted') . ' THEN 1 ELSE 0 END) AS success_count',
])
->from($db->quoteName('#__mokojoomcross_posts', 'p'))
->join('INNER', $db->quoteName('#__content', 'c')
. ' ON ' . $db->quoteName('c.id') . ' = ' . $db->quoteName('p.article_id'))
->group($db->quoteName(['c.id', 'c.title']))
->order('post_count DESC');
$db->setQuery($query, 0, $limit);
return $db->loadAssocList() ?: [];
}
}
@@ -0,0 +1,39 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Model;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Model\AdminModel;
class TemplateModel extends AdminModel
{
public function getForm($data = [], $loadData = true)
{
$form = $this->loadForm(
'com_mokojoomcross.template',
'template',
['control' => 'jform', 'load_data' => $loadData]
);
if (empty($form)) {
return false;
}
return $form;
}
protected function loadFormData()
{
return $this->getItem();
}
}
@@ -0,0 +1,61 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Model;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Model\ListModel;
class TemplatesModel extends ListModel
{
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'title', 'a.title',
'service_type', 'a.service_type',
'published', 'a.published',
'ordering', 'a.ordering',
];
}
parent::__construct($config);
}
protected function getListQuery()
{
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select('a.*')
->from($db->quoteName('#__mokojoomcross_templates', 'a'));
$published = $this->getState('filter.published');
if (is_numeric($published)) {
$query->where($db->quoteName('a.published') . ' = ' . (int) $published);
}
$serviceType = $this->getState('filter.service_type');
if (!empty($serviceType)) {
$query->where($db->quoteName('a.service_type') . ' = ' . $db->quote($serviceType));
}
$orderCol = $this->state->get('list.ordering', 'a.ordering');
$orderDirn = $this->state->get('list.direction', 'ASC');
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
return $query;
}
}
@@ -0,0 +1,25 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\Table;
defined('_JEXEC') or die;
use Joomla\CMS\Table\Table;
use Joomla\Database\DatabaseDriver;
class TemplateTable extends Table
{
public function __construct(DatabaseDriver $db)
{
parent::__construct('#__mokojoomcross_templates', 'id', $db);
}
}
@@ -20,11 +20,21 @@ class HtmlView extends BaseHtmlView
{
protected $stats;
protected $migrationAvailable;
protected $recentActivity;
protected $serviceBreakdown;
protected $dailyTrend;
protected $topArticles;
public function display($tpl = null): void
{
$this->stats = $this->get('Stats');
$model = $this->getModel();
$this->stats = $this->get('Stats');
$this->migrationAvailable = $this->get('MigrationAvailable');
$this->recentActivity = $model->getRecentActivity(10);
$this->serviceBreakdown = $model->getServiceBreakdown();
$this->dailyTrend = $model->getDailyTrend(14);
$this->topArticles = $model->getTopArticles(5);
$this->addToolbar();
@@ -0,0 +1,46 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\View\Template;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
class HtmlView extends BaseHtmlView
{
protected $form;
protected $item;
public function display($tpl = null): void
{
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->addToolbar();
parent::display($tpl);
}
protected function addToolbar(): void
{
$isNew = empty($this->item->id);
ToolbarHelper::title(
'MokoJoomCross — ' . ($isNew ? 'New Template' : 'Edit Template'),
'share-alt'
);
ToolbarHelper::apply('template.apply');
ToolbarHelper::save('template.save');
ToolbarHelper::cancel('template.cancel');
}
}
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
@@ -0,0 +1,45 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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 Joomla\Component\MokoJoomCross\Administrator\View\Templates;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
class HtmlView extends BaseHtmlView
{
protected $items;
protected $pagination;
protected $state;
public function display($tpl = null): void
{
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->addToolbar();
parent::display($tpl);
}
protected function addToolbar(): void
{
ToolbarHelper::title('MokoJoomCross — Message Templates', 'share-alt');
ToolbarHelper::addNew('template.add');
ToolbarHelper::editList('template.edit');
ToolbarHelper::publish('templates.publish', 'JTOOLBAR_PUBLISH', true);
ToolbarHelper::unpublish('templates.unpublish', 'JTOOLBAR_UNPUBLISH', true);
ToolbarHelper::deleteList('', 'templates.delete', 'JTOOLBAR_DELETE');
}
}
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
@@ -11,12 +11,25 @@
defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\MokoJoomCross\Administrator\View\Dashboard\HtmlView $this */
$stats = $this->stats;
$componentParams = ComponentHelper::getParams('com_mokojoomcross');
$queueProcessing = $componentParams->get('queue_processing', 'scheduler');
?>
<?php if ($queueProcessing === 'pageload' || $queueProcessing === 'both') : ?>
<div class="alert alert-warning d-flex align-items-start mb-3">
<span class="icon-exclamation-triangle me-2 mt-1" aria-hidden="true"></span>
<div>
<strong><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_PAGELOAD_WARNING_TITLE'); ?></strong><br>
<?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_PAGELOAD_WARNING'); ?>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-lg-9">
<div class="row">
@@ -64,6 +77,107 @@ $stats = $this->stats;
</a>
</div>
<?php endif; ?>
<!-- Analytics: Service Breakdown -->
<?php if (!empty($this->serviceBreakdown)) : ?>
<div class="card mt-3">
<div class="card-header">
<h5 class="card-title mb-0"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_SERVICE_BREAKDOWN'); ?></h5>
</div>
<div class="card-body">
<table class="table table-sm table-striped mb-0">
<thead>
<tr>
<th><?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_SERVICE'); ?></th>
<th class="text-center text-success"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_POSTED'); ?></th>
<th class="text-center text-danger"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_FAILED'); ?></th>
<th class="text-center text-warning"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_QUEUED'); ?></th>
<th class="text-center"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_TOTAL_POSTS'); ?></th>
<th class="text-center"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_SUCCESS_RATE'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->serviceBreakdown as $row) :
$rate = $row['total'] > 0 ? round(($row['posted'] / $row['total']) * 100) : 0;
$rateClass = $rate >= 80 ? 'text-success' : ($rate >= 50 ? 'text-warning' : 'text-danger');
?>
<tr>
<td><?php echo htmlspecialchars($row['service_title'] . ' (' . ucfirst($row['service_type']) . ')'); ?></td>
<td class="text-center"><span class="badge bg-success"><?php echo (int) $row['posted']; ?></span></td>
<td class="text-center"><span class="badge bg-danger"><?php echo (int) $row['failed']; ?></span></td>
<td class="text-center"><span class="badge bg-warning text-dark"><?php echo (int) $row['queued']; ?></span></td>
<td class="text-center"><?php echo (int) $row['total']; ?></td>
<td class="text-center <?php echo $rateClass; ?> fw-bold"><?php echo $rate; ?>%</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
<!-- Analytics: Top Articles -->
<?php if (!empty($this->topArticles)) : ?>
<div class="card mt-3">
<div class="card-header">
<h5 class="card-title mb-0"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_TOP_ARTICLES'); ?></h5>
</div>
<div class="card-body p-0">
<div class="list-group list-group-flush">
<?php foreach ($this->topArticles as $row) : ?>
<div class="list-group-item d-flex justify-content-between align-items-center">
<span><?php echo htmlspecialchars($row['title']); ?></span>
<span>
<span class="badge bg-success"><?php echo (int) $row['success_count']; ?></span>
/
<span class="badge bg-secondary"><?php echo (int) $row['post_count']; ?></span>
</span>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<?php endif; ?>
<!-- Recent Activity -->
<div class="card mt-3">
<div class="card-header">
<h5 class="card-title mb-0"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_RECENT_ACTIVITY'); ?></h5>
</div>
<div class="card-body p-0">
<?php if (empty($this->recentActivity)) : ?>
<p class="p-3 mb-0 text-muted"><?php echo Text::_('COM_MOKOJOOMCROSS_DASHBOARD_NO_RECENT'); ?></p>
<?php else : ?>
<div class="list-group list-group-flush">
<?php foreach ($this->recentActivity as $entry) :
$levelClass = match ($entry->level) {
'error' => 'text-danger',
'warning' => 'text-warning',
default => 'text-muted',
};
$levelIcon = match ($entry->level) {
'error' => 'icon-times-circle',
'warning' => 'icon-exclamation-triangle',
default => 'icon-info-circle',
};
?>
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<span class="<?php echo $levelClass; ?>">
<span class="<?php echo $levelIcon; ?>" aria-hidden="true"></span>
<?php echo htmlspecialchars(mb_substr($entry->message, 0, 120)); ?>
</span>
<small class="text-muted"><?php echo \Joomla\CMS\HTML\HTMLHelper::_('date', $entry->created, 'Y-m-d H:i'); ?></small>
</div>
<?php if ($entry->service_title) : ?>
<small class="text-muted"><?php echo htmlspecialchars($entry->service_title); ?></small>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
<div class="col-lg-3">
@@ -79,6 +193,10 @@ $stats = $this->stats;
class="list-group-item list-group-item-action">
<?php echo Text::_('COM_MOKOJOOMCROSS_SUBMENU_POSTS'); ?>
</a>
<a href="<?php echo Route::_('index.php?option=com_mokojoomcross&view=templates'); ?>"
class="list-group-item list-group-item-action">
<?php echo Text::_('COM_MOKOJOOMCROSS_SUBMENU_TEMPLATES'); ?>
</a>
<a href="<?php echo Route::_('index.php?option=com_mokojoomcross&view=logs'); ?>"
class="list-group-item list-group-item-action">
<?php echo Text::_('COM_MOKOJOOMCROSS_SUBMENU_LOGS'); ?>
@@ -0,0 +1,110 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\MokoJoomCross\Administrator\View\Logs\HtmlView $this */
HTMLHelper::_('behavior.multiselect');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$levelBadges = [
'info' => 'bg-info',
'warning' => 'bg-warning text-dark',
'error' => 'bg-danger',
];
?>
<form action="<?php echo Route::_('index.php?option=com_mokojoomcross&view=logs'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
<div class="col-md-12">
<div id="j-main-container" class="j-main-container">
<?php echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); ?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span>
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php else : ?>
<table class="table" id="logsList">
<caption class="visually-hidden"><?php echo Text::_('COM_MOKOJOOMCROSS_SUBMENU_LOGS'); ?></caption>
<thead>
<tr>
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-10">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_LEVEL'); ?>
</th>
<th scope="col">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_MESSAGE'); ?>
</th>
<th scope="col" class="w-15 d-none d-md-table-cell">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_SERVICE'); ?>
</th>
<th scope="col" class="w-10">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_MOKOJOOMCROSS_HEADING_CREATED', 'a.created', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-5 text-center d-none d-md-table-cell">
<?php echo Text::_('JGRID_HEADING_ID'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item) :
$badgeClass = $levelBadges[$item->level] ?? 'bg-secondary';
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', ''); ?>
</td>
<td>
<span class="badge <?php echo $badgeClass; ?>">
<?php echo $this->escape(ucfirst($item->level)); ?>
</span>
</td>
<td>
<?php echo $this->escape($item->message); ?>
<?php if (!empty($item->context) && $item->context !== '{}') : ?>
<br><small class="text-muted"><code><?php echo $this->escape(mb_substr($item->context, 0, 200)); ?></code></small>
<?php endif; ?>
</td>
<td class="d-none d-md-table-cell">
<?php echo $this->escape($item->service_title ?? '—'); ?>
</td>
<td>
<?php echo HTMLHelper::_('date', $item->created, 'Y-m-d H:i:s'); ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo $this->pagination->getListFooter(); ?>
<?php endif; ?>
<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<?php echo HTMLHelper::_('form.token'); ?>
</div>
</div>
</div>
</form>
@@ -0,0 +1,131 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\MokoJoomCross\Administrator\View\Posts\HtmlView $this */
HTMLHelper::_('behavior.multiselect');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$statusBadges = [
'queued' => 'bg-warning text-dark',
'posting' => 'bg-info',
'posted' => 'bg-success',
'failed' => 'bg-danger',
'scheduled' => 'bg-secondary',
];
?>
<form action="<?php echo Route::_('index.php?option=com_mokojoomcross&view=posts'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
<div class="col-md-12">
<div id="j-main-container" class="j-main-container">
<?php echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); ?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span>
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php else : ?>
<table class="table" id="postsList">
<caption class="visually-hidden"><?php echo Text::_('COM_MOKOJOOMCROSS_SUBMENU_POSTS'); ?></caption>
<thead>
<tr>
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-10">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_STATUS'); ?>
</th>
<th scope="col">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_ARTICLE'); ?>
</th>
<th scope="col" class="w-15">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_SERVICE'); ?>
</th>
<th scope="col" class="w-15 d-none d-md-table-cell">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_MESSAGE'); ?>
</th>
<th scope="col" class="w-10 d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_MOKOJOOMCROSS_HEADING_POSTED_AT', 'a.posted_at', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 d-none d-lg-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_MOKOJOOMCROSS_HEADING_CREATED', 'a.created', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-5 text-center d-none d-md-table-cell">
<?php echo Text::_('JGRID_HEADING_ID'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item) :
$badgeClass = $statusBadges[$item->status] ?? 'bg-secondary';
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->article_title ?? ''); ?>
</td>
<td>
<span class="badge <?php echo $badgeClass; ?>">
<?php echo $this->escape(ucfirst($item->status)); ?>
</span>
<?php if ($item->status === 'failed' && !empty($item->error_message)) : ?>
<br><small class="text-danger"><?php echo $this->escape(mb_substr($item->error_message, 0, 80)); ?></small>
<?php endif; ?>
<?php if ($item->retry_count > 0) : ?>
<br><small class="text-muted">Retries: <?php echo (int) $item->retry_count; ?></small>
<?php endif; ?>
</td>
<td>
<?php echo $this->escape($item->article_title ?? 'Article #' . $item->article_id); ?>
</td>
<td>
<?php echo $this->escape($item->service_title ?? ''); ?>
<br><small class="text-muted"><?php echo $this->escape($item->service_type ?? ''); ?></small>
</td>
<td class="d-none d-md-table-cell">
<small><?php echo $this->escape(mb_substr($item->message ?? '', 0, 100)); ?></small>
<?php if (!empty($item->platform_post_id)) : ?>
<br><small class="text-success">ID: <?php echo $this->escape($item->platform_post_id); ?></small>
<?php endif; ?>
</td>
<td class="d-none d-md-table-cell">
<?php echo $item->posted_at ? HTMLHelper::_('date', $item->posted_at, 'Y-m-d H:i') : '—'; ?>
</td>
<td class="d-none d-lg-table-cell">
<?php echo HTMLHelper::_('date', $item->created, 'Y-m-d H:i'); ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo $this->pagination->getListFooter(); ?>
<?php endif; ?>
<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<?php echo HTMLHelper::_('form.token'); ?>
</div>
</div>
</div>
</form>
@@ -0,0 +1,120 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\MokoJoomCross\Administrator\View\Services\HtmlView $this */
HTMLHelper::_('behavior.multiselect');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$serviceIcons = [
'facebook' => 'icon-facebook',
'twitter' => 'icon-twitter',
'linkedin' => 'icon-linkedin',
'mastodon' => 'icon-globe',
'bluesky' => 'icon-cloud',
'mailchimp' => 'icon-envelope',
'telegram' => 'icon-comment',
'discord' => 'icon-comments',
'slack' => 'icon-comments-2',
];
?>
<form action="<?php echo Route::_('index.php?option=com_mokojoomcross&view=services'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
<div class="col-md-12">
<div id="j-main-container" class="j-main-container">
<?php echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); ?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span>
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php else : ?>
<table class="table" id="servicesList">
<caption class="visually-hidden"><?php echo Text::_('COM_MOKOJOOMCROSS_SUBMENU_SERVICES'); ?></caption>
<thead>
<tr>
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.published', $listDirn, $listOrder); ?>
</th>
<th scope="col">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-15">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_MOKOJOOMCROSS_FIELD_SERVICE_TYPE', 'a.service_type', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-10 text-center d-none d-md-table-cell">
<?php echo Text::_('COM_MOKOJOOMCROSS_HEADING_MODE'); ?>
</th>
<th scope="col" class="w-5 text-center d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item) :
$credentials = json_decode($item->credentials ?: '{}', true) ?: [];
$mode = $credentials['mode'] ?? 'custom';
$icon = $serviceIcons[$item->service_type] ?? 'icon-cog';
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
<td class="text-center">
<?php echo HTMLHelper::_('jgrid.published', $item->published, $i, 'services.', true); ?>
</td>
<td>
<a href="<?php echo Route::_('index.php?option=com_mokojoomcross&task=service.edit&id=' . $item->id); ?>">
<?php echo $this->escape($item->title); ?>
</a>
</td>
<td>
<span class="<?php echo $icon; ?>" aria-hidden="true"></span>
<?php echo $this->escape(ucfirst($item->service_type)); ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php if ($mode === 'default') : ?>
<span class="badge bg-primary">Default Bot</span>
<?php else : ?>
<span class="badge bg-secondary">Custom</span>
<?php endif; ?>
</td>
<td class="text-center d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo $this->pagination->getListFooter(); ?>
<?php endif; ?>
<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<?php echo HTMLHelper::_('form.token'); ?>
</div>
</div>
</div>
</form>
@@ -0,0 +1,44 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
/** @var \Joomla\CMS\Form\Form $this->form */
HTMLHelper::_('behavior.formvalidator');
HTMLHelper::_('behavior.keepalive');
?>
<form action="<?php echo Route::_('index.php?option=com_mokojoomcross&layout=edit&id=' . (int) $this->item->id); ?>"
method="post" name="adminForm" id="adminForm" class="form-validate">
<div class="main-card">
<div class="row">
<div class="col-lg-9">
<?php echo $this->form->renderFieldset('details'); ?>
</div>
<div class="col-lg-3">
<div class="card">
<div class="card-body">
<h4><?php echo Text::_('COM_MOKOJOOMCROSS_FIELDSET_CREDENTIALS'); ?></h4>
<?php echo $this->form->renderFieldset('credentials'); ?>
</div>
</div>
</div>
</div>
</div>
<input type="hidden" name="task" value="">
<?php echo HTMLHelper::_('form.token'); ?>
</form>
@@ -0,0 +1,57 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\MokoJoomCross\Administrator\View\Template\HtmlView $this */
HTMLHelper::_('behavior.formvalidator');
HTMLHelper::_('behavior.keepalive');
?>
<form action="<?php echo Route::_('index.php?option=com_mokojoomcross&layout=edit&id=' . (int) ($this->item->id ?? 0)); ?>"
method="post" name="adminForm" id="adminForm" class="form-validate">
<div class="main-card">
<div class="row">
<div class="col-lg-8">
<?php echo $this->form->renderFieldset('details'); ?>
</div>
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0"><?php echo Text::_('COM_MOKOJOOMCROSS_TEMPLATE_PLACEHOLDERS'); ?></h5>
</div>
<div class="card-body">
<table class="table table-sm table-striped">
<tbody>
<tr><td><code>{title}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_TITLE'); ?></td></tr>
<tr><td><code>{url}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_URL'); ?></td></tr>
<tr><td><code>{introtext}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_INTROTEXT'); ?></td></tr>
<tr><td><code>{fulltext}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_FULLTEXT'); ?></td></tr>
<tr><td><code>{image}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_IMAGE'); ?></td></tr>
<tr><td><code>{category}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_CATEGORY'); ?></td></tr>
<tr><td><code>{author}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_AUTHOR'); ?></td></tr>
<tr><td><code>{date}</code></td><td><?php echo Text::_('COM_MOKOJOOMCROSS_PLACEHOLDER_DATE'); ?></td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<input type="hidden" name="task" value="">
<?php echo HTMLHelper::_('form.token'); ?>
</form>
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
@@ -0,0 +1,103 @@
<?php
/**
* @package MokoJoomCross
* @subpackage com_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
/** @var \Joomla\Component\MokoJoomCross\Administrator\View\Templates\HtmlView $this */
HTMLHelper::_('behavior.multiselect');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<form action="<?php echo Route::_('index.php?option=com_mokojoomcross&view=templates'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
<div class="col-md-12">
<div id="j-main-container" class="j-main-container">
<?php echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); ?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"></span>
<?php echo Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php else : ?>
<table class="table" id="templatesList">
<caption class="visually-hidden"><?php echo Text::_('COM_MOKOJOOMCROSS_SUBMENU_TEMPLATES'); ?></caption>
<thead>
<tr>
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.published', $listDirn, $listOrder); ?>
</th>
<th scope="col">
<?php echo HTMLHelper::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-15">
<?php echo Text::_('COM_MOKOJOOMCROSS_FIELD_SERVICE_TYPE'); ?>
</th>
<th scope="col" class="d-none d-md-table-cell">
<?php echo Text::_('COM_MOKOJOOMCROSS_TEMPLATE_PREVIEW'); ?>
</th>
<th scope="col" class="w-5 text-center d-none d-md-table-cell">
<?php echo Text::_('JGRID_HEADING_ID'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item) : ?>
<tr class="row<?php echo $i % 2; ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
</td>
<td class="text-center">
<?php echo HTMLHelper::_('jgrid.published', $item->published, $i, 'templates.', true); ?>
</td>
<td>
<a href="<?php echo Route::_('index.php?option=com_mokojoomcross&task=template.edit&id=' . $item->id); ?>">
<?php echo $this->escape($item->title); ?>
</a>
</td>
<td>
<?php if ($item->service_type === 'default') : ?>
<span class="badge bg-primary">Default</span>
<?php else : ?>
<?php echo $this->escape(ucfirst($item->service_type)); ?>
<?php endif; ?>
</td>
<td class="d-none d-md-table-cell">
<code class="small"><?php echo $this->escape(mb_substr($item->template_body, 0, 80)); ?></code>
</td>
<td class="text-center d-none d-md-table-cell">
<?php echo (int) $item->id; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo $this->pagination->getListFooter(); ?>
<?php endif; ?>
<input type="hidden" name="task" value="">
<input type="hidden" name="boxchecked" value="0">
<?php echo HTMLHelper::_('form.token'); ?>
</div>
</div>
</div>
</form>
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>
@@ -1,2 +1,8 @@
PLG_CONTENT_MOKOJOOMCROSS="Content - MokoJoomCross"
PLG_CONTENT_MOKOJOOMCROSS_DESCRIPTION="Adds cross-post status badges to articles in the admin backend."
PLG_CONTENT_MOKOJOOMCROSS_DESCRIPTION="Adds cross-post status badges and per-article service selection to the article editor."
PLG_CONTENT_MOKOJOOMCROSS_FIELDSET_CROSSPOST="Cross-Posting"
PLG_CONTENT_MOKOJOOMCROSS_SKIP="Skip Cross-Posting"
PLG_CONTENT_MOKOJOOMCROSS_SKIP_DESC="Skip all cross-posting for this article."
PLG_CONTENT_MOKOJOOMCROSS_SERVICES="Post to Services"
PLG_CONTENT_MOKOJOOMCROSS_SERVICES_DESC="Select which services to cross-post to. Leave all unchecked to post to all enabled services."
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="content" method="upgrade">
<name>Content - MokoJoomCross</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -14,30 +14,101 @@ namespace Joomla\Plugin\Content\MokoJoomCross\Extension;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;
/**
* Content plugin that adds cross-post status badges to article views.
* Content plugin that:
* 1. Adds cross-post status badges to article views in admin
* 2. Injects service selection checkboxes into the article editor (#19)
*/
class MokoJoomCrossContent extends CMSPlugin implements SubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'onContentBeforeDisplay' => 'onContentBeforeDisplay',
'onContentBeforeDisplay' => 'onContentBeforeDisplay',
'onContentPrepareForm' => 'onContentPrepareForm',
];
}
/**
* Add cross-post status indicator before article content in admin.
* Inject cross-post service selection fields into article edit form.
*
* @param string $context The context
* @param object $article The article
* @param object $params The article params
* @param int $page The page number
*
* @return string HTML to prepend to the article
* Adds a "Cross-Posting" fieldset to the article attribs tab with:
* - Checkbox list of all enabled services
* - Skip cross-posting toggle
*/
public function onContentPrepareForm(Form $form, $data): void
{
if ($form->getName() !== 'com_content.article') {
return;
}
$app = $this->getApplication();
if (!$app->isClient('administrator')) {
return;
}
$db = Factory::getDbo();
// Load enabled services for the checkbox list
$query = $db->getQuery(true)
->select('id, title, service_type')
->from($db->quoteName('#__mokojoomcross_services'))
->where($db->quoteName('published') . ' = 1')
->order($db->quoteName('ordering') . ' ASC');
$db->setQuery($query);
$services = $db->loadObjectList();
if (empty($services)) {
return;
}
// Build dynamic XML form for the attribs fieldset
$options = '';
foreach ($services as $svc) {
$label = htmlspecialchars($svc->title . ' (' . ucfirst($svc->service_type) . ')', ENT_XML1);
$options .= '<option value="' . (int) $svc->id . '">' . $label . '</option>';
}
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="attribs">
<fieldset name="mokojoomcross" label="PLG_CONTENT_MOKOJOOMCROSS_FIELDSET_CROSSPOST">
<field
name="mokojoomcross_skip"
type="radio"
label="PLG_CONTENT_MOKOJOOMCROSS_SKIP"
description="PLG_CONTENT_MOKOJOOMCROSS_SKIP_DESC"
default="0"
class="btn-group btn-group-yesno">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
name="mokojoomcross_services"
type="checkboxes"
label="PLG_CONTENT_MOKOJOOMCROSS_SERVICES"
description="PLG_CONTENT_MOKOJOOMCROSS_SERVICES_DESC"
showon="mokojoomcross_skip:0">
{$options}
</field>
</fieldset>
</fields>
</form>
XML;
$form->load($xml);
}
/**
* Add cross-post status badges before article content in admin.
*/
public function onContentBeforeDisplay(string $context, &$article, &$params, int $page = 0): string
{
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - Bluesky</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -23,4 +23,29 @@
<language tag="en-GB">language/en-GB/plg_mokojoomcross_bluesky.ini</language>
<language tag="en-GB">language/en-GB/plg_mokojoomcross_bluesky.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic" label="PLG_MOKOJOOMCROSS_BLUESKY_FIELDSET_DEFAULTS">
<field
name="default_pds_url"
type="url"
label="PLG_MOKOJOOMCROSS_BLUESKY_DEFAULT_PDS_URL"
description="PLG_MOKOJOOMCROSS_BLUESKY_DEFAULT_PDS_URL_DESC"
default="https://bsky.social"
/>
<field
name="auto_link_card"
type="radio"
label="PLG_MOKOJOOMCROSS_BLUESKY_AUTO_LINK_CARD"
description="PLG_MOKOJOOMCROSS_BLUESKY_AUTO_LINK_CARD_DESC"
default="1"
class="btn-group btn-group-yesno"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
</fields>
</config>
</extension>
@@ -1,2 +1,7 @@
PLG_MOKOJOOMCROSS_BLUESKY="MokoJoomCross - Bluesky"
PLG_MOKOJOOMCROSS_BLUESKY_DESCRIPTION="Cross-post Joomla articles to Bluesky."
PLG_MOKOJOOMCROSS_BLUESKY_FIELDSET_DEFAULTS="Bluesky Defaults"
PLG_MOKOJOOMCROSS_BLUESKY_DEFAULT_PDS_URL="Default PDS URL"
PLG_MOKOJOOMCROSS_BLUESKY_DEFAULT_PDS_URL_DESC="Default Bluesky PDS URL (e.g. https://bsky.social)."
PLG_MOKOJOOMCROSS_BLUESKY_AUTO_LINK_CARD="Auto Link Card"
PLG_MOKOJOOMCROSS_BLUESKY_AUTO_LINK_CARD_DESC="Automatically detect URLs and create link cards in posts."
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Bluesky\Extension\BlueskyService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - Discord</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -23,4 +23,24 @@
<language tag="en-GB">language/en-GB/plg_mokojoomcross_discord.ini</language>
<language tag="en-GB">language/en-GB/plg_mokojoomcross_discord.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic" label="PLG_MOKOJOOMCROSS_DISCORD_FIELDSET_DEFAULTS">
<field
name="default_webhook_url"
type="url"
label="PLG_MOKOJOOMCROSS_DISCORD_DEFAULT_WEBHOOK_URL"
description="PLG_MOKOJOOMCROSS_DISCORD_DEFAULT_WEBHOOK_URL_DESC"
/>
<field
name="embed_color"
type="color"
label="PLG_MOKOJOOMCROSS_DISCORD_EMBED_COLOR"
description="PLG_MOKOJOOMCROSS_DISCORD_EMBED_COLOR_DESC"
default="#5865F2"
/>
</fieldset>
</fields>
</config>
</extension>
@@ -1,2 +1,7 @@
PLG_MOKOJOOMCROSS_DISCORD="MokoJoomCross - Discord"
PLG_MOKOJOOMCROSS_DISCORD_DESCRIPTION="Cross-post Joomla articles to Discord."
PLG_MOKOJOOMCROSS_DISCORD_FIELDSET_DEFAULTS="Default Settings"
PLG_MOKOJOOMCROSS_DISCORD_DEFAULT_WEBHOOK_URL="Default Webhook URL"
PLG_MOKOJOOMCROSS_DISCORD_DEFAULT_WEBHOOK_URL_DESC="The default MokoWaaS Discord webhook URL used when a service is set to 'default' mode."
PLG_MOKOJOOMCROSS_DISCORD_EMBED_COLOR="Embed Color"
PLG_MOKOJOOMCROSS_DISCORD_EMBED_COLOR_DESC="Default color for Discord embed messages. Defaults to Discord blurple (#5865F2)."
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Discord\Extension\DiscordService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -113,7 +113,6 @@ class DiscordService extends CMSPlugin implements SubscriberInterface, MokoJoomC
return $credentials['webhook_url'] ?? '';
}
return \Joomla\CMS\Component\ComponentHelper::getParams('com_mokojoomcross')
->get('discord_default_webhook', '');
return $this->params->get('default_webhook_url', '');
}
}
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - Facebook / Meta</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -23,4 +23,23 @@
<language tag="en-GB">language/en-GB/plg_mokojoomcross_facebook.ini</language>
<language tag="en-GB">language/en-GB/plg_mokojoomcross_facebook.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic" label="PLG_MOKOJOOMCROSS_FACEBOOK_FIELDSET_DEFAULTS">
<field
name="default_page_access_token"
type="password"
label="PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ACCESS_TOKEN"
description="PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ACCESS_TOKEN_DESC"
/>
<field
name="default_page_id"
type="text"
label="PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ID"
description="PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ID_DESC"
/>
</fieldset>
</fields>
</config>
</extension>
@@ -1,2 +1,7 @@
PLG_MOKOJOOMCROSS_FACEBOOK="MokoJoomCross - Facebook / Meta"
PLG_MOKOJOOMCROSS_FACEBOOK_DESCRIPTION="Cross-post Joomla articles to Facebook / Meta."
PLG_MOKOJOOMCROSS_FACEBOOK_FIELDSET_DEFAULTS="Default Settings"
PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ACCESS_TOKEN="Default Page Access Token"
PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ACCESS_TOKEN_DESC="The default MokoWaaS Facebook Page Access Token used when a service is set to 'default' mode."
PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ID="Default Page ID"
PLG_MOKOJOOMCROSS_FACEBOOK_DEFAULT_PAGE_ID_DESC="The default Facebook Page ID used when a service is set to 'default' mode."
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Facebook\Extension\FacebookService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -139,7 +139,6 @@ class FacebookService extends CMSPlugin implements SubscriberInterface, MokoJoom
return $credentials['page_access_token'] ?? '';
}
return \Joomla\CMS\Component\ComponentHelper::getParams('com_mokojoomcross')
->get('facebook_default_token', '');
return $this->params->get('default_page_access_token', '');
}
}
@@ -1,2 +1,9 @@
PLG_MOKOJOOMCROSS_LINKEDIN="MokoJoomCross - LinkedIn"
PLG_MOKOJOOMCROSS_LINKEDIN_DESCRIPTION="Cross-post Joomla articles to LinkedIn."
PLG_MOKOJOOMCROSS_LINKEDIN_FIELDSET_DEFAULTS="LinkedIn Defaults"
PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_ID="Client ID"
PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_ID_DESC="LinkedIn App Client ID."
PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_SECRET="Client Secret"
PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_SECRET_DESC="LinkedIn App Client Secret."
PLG_MOKOJOOMCROSS_LINKEDIN_REDIRECT_URI="Redirect URI"
PLG_MOKOJOOMCROSS_LINKEDIN_REDIRECT_URI_DESC="OAuth callback URL for LinkedIn authentication."
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - LinkedIn</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -23,4 +23,29 @@
<language tag="en-GB">language/en-GB/plg_mokojoomcross_linkedin.ini</language>
<language tag="en-GB">language/en-GB/plg_mokojoomcross_linkedin.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic" label="PLG_MOKOJOOMCROSS_LINKEDIN_FIELDSET_DEFAULTS">
<field
name="client_id"
type="text"
label="PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_ID"
description="PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_ID_DESC"
/>
<field
name="client_secret"
type="password"
label="PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_SECRET"
description="PLG_MOKOJOOMCROSS_LINKEDIN_CLIENT_SECRET_DESC"
/>
<field
name="redirect_uri"
type="url"
label="PLG_MOKOJOOMCROSS_LINKEDIN_REDIRECT_URI"
description="PLG_MOKOJOOMCROSS_LINKEDIN_REDIRECT_URI_DESC"
/>
</fieldset>
</fields>
</config>
</extension>
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Linkedin\Extension\LinkedinService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -1,2 +1,9 @@
PLG_MOKOJOOMCROSS_MAILCHIMP="MokoJoomCross - Mailchimp"
PLG_MOKOJOOMCROSS_MAILCHIMP_DESCRIPTION="Cross-post Joomla articles to Mailchimp."
PLG_MOKOJOOMCROSS_MAILCHIMP_FIELDSET_DEFAULTS="Mailchimp Defaults"
PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_NAME="Default From Name"
PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_NAME_DESC="Default sender name for Mailchimp campaigns."
PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_EMAIL="Default From Email"
PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_EMAIL_DESC="Default sender email address for Mailchimp campaigns."
PLG_MOKOJOOMCROSS_MAILCHIMP_AUTO_SEND="Auto Send"
PLG_MOKOJOOMCROSS_MAILCHIMP_AUTO_SEND_DESC="Automatically send the campaign on creation instead of saving as draft."
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - Mailchimp</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -23,4 +23,34 @@
<language tag="en-GB">language/en-GB/plg_mokojoomcross_mailchimp.ini</language>
<language tag="en-GB">language/en-GB/plg_mokojoomcross_mailchimp.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic" label="PLG_MOKOJOOMCROSS_MAILCHIMP_FIELDSET_DEFAULTS">
<field
name="default_from_name"
type="text"
label="PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_NAME"
description="PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_NAME_DESC"
/>
<field
name="default_from_email"
type="email"
label="PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_EMAIL"
description="PLG_MOKOJOOMCROSS_MAILCHIMP_DEFAULT_FROM_EMAIL_DESC"
/>
<field
name="auto_send"
type="radio"
label="PLG_MOKOJOOMCROSS_MAILCHIMP_AUTO_SEND"
description="PLG_MOKOJOOMCROSS_MAILCHIMP_AUTO_SEND_DESC"
default="0"
class="btn-group btn-group-yesno"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
</fields>
</config>
</extension>
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Mailchimp\Extension\MailchimpService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -1,2 +1,13 @@
PLG_MOKOJOOMCROSS_MASTODON="MokoJoomCross - Mastodon"
PLG_MOKOJOOMCROSS_MASTODON_DESCRIPTION="Cross-post Joomla articles to Mastodon."
PLG_MOKOJOOMCROSS_MASTODON_FIELDSET_DEFAULTS="Mastodon Defaults"
PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_INSTANCE_URL="Default Instance URL"
PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_INSTANCE_URL_DESC="Default Mastodon instance URL (e.g. https://mastodon.social)."
PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_VISIBILITY="Default Visibility"
PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_VISIBILITY_DESC="Default post visibility for Mastodon toots."
PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_PUBLIC="Public"
PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_UNLISTED="Unlisted"
PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_PRIVATE="Private"
PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_DIRECT="Direct"
PLG_MOKOJOOMCROSS_MASTODON_APPEND_HASHTAGS="Append Hashtags"
PLG_MOKOJOOMCROSS_MASTODON_APPEND_HASHTAGS_DESC="Default hashtags to append to posts (e.g. #Joomla #MokoWaaS)."
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - Mastodon</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -23,4 +23,35 @@
<language tag="en-GB">language/en-GB/plg_mokojoomcross_mastodon.ini</language>
<language tag="en-GB">language/en-GB/plg_mokojoomcross_mastodon.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic" label="PLG_MOKOJOOMCROSS_MASTODON_FIELDSET_DEFAULTS">
<field
name="default_instance_url"
type="url"
label="PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_INSTANCE_URL"
description="PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_INSTANCE_URL_DESC"
/>
<field
name="default_visibility"
type="list"
label="PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_VISIBILITY"
description="PLG_MOKOJOOMCROSS_MASTODON_DEFAULT_VISIBILITY_DESC"
default="public"
>
<option value="public">PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_PUBLIC</option>
<option value="unlisted">PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_UNLISTED</option>
<option value="private">PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_PRIVATE</option>
<option value="direct">PLG_MOKOJOOMCROSS_MASTODON_VISIBILITY_DIRECT</option>
</field>
<field
name="append_hashtags"
type="text"
label="PLG_MOKOJOOMCROSS_MASTODON_APPEND_HASHTAGS"
description="PLG_MOKOJOOMCROSS_MASTODON_APPEND_HASHTAGS_DESC"
/>
</fieldset>
</fields>
</config>
</extension>
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Mastodon\Extension\MastodonService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -1,2 +1,5 @@
PLG_MOKOJOOMCROSS_SLACK="MokoJoomCross - Slack"
PLG_MOKOJOOMCROSS_SLACK_DESCRIPTION="Cross-post Joomla articles to Slack."
PLG_MOKOJOOMCROSS_SLACK_FIELDSET_DEFAULTS="Default Settings"
PLG_MOKOJOOMCROSS_SLACK_DEFAULT_WEBHOOK_URL="Default Webhook URL"
PLG_MOKOJOOMCROSS_SLACK_DEFAULT_WEBHOOK_URL_DESC="The default MokoWaaS Slack webhook URL used when a service is set to 'default' mode."
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Slack\Extension\SlackService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
+14 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - Slack</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -23,4 +23,17 @@
<language tag="en-GB">language/en-GB/plg_mokojoomcross_slack.ini</language>
<language tag="en-GB">language/en-GB/plg_mokojoomcross_slack.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic" label="PLG_MOKOJOOMCROSS_SLACK_FIELDSET_DEFAULTS">
<field
name="default_webhook_url"
type="url"
label="PLG_MOKOJOOMCROSS_SLACK_DEFAULT_WEBHOOK_URL"
description="PLG_MOKOJOOMCROSS_SLACK_DEFAULT_WEBHOOK_URL_DESC"
/>
</fieldset>
</fields>
</config>
</extension>
@@ -111,7 +111,6 @@ class SlackService extends CMSPlugin implements SubscriberInterface, MokoJoomCro
return $credentials['webhook_url'] ?? '';
}
return \Joomla\CMS\Component\ComponentHelper::getParams('com_mokojoomcross')
->get('slack_default_webhook', '');
return $this->params->get('default_webhook_url', '');
}
}
@@ -1,2 +1,9 @@
PLG_MOKOJOOMCROSS_TELEGRAM="MokoJoomCross - Telegram"
PLG_MOKOJOOMCROSS_TELEGRAM_DESCRIPTION="Cross-post Joomla articles to Telegram."
PLG_MOKOJOOMCROSS_TELEGRAM_DESCRIPTION="Cross-post Joomla articles to Telegram channels and groups. Supports default @MokoWaaSBot and custom bot modes."
PLG_MOKOJOOMCROSS_TELEGRAM_FIELDSET_DEFAULTS="Default Bot Settings"
PLG_MOKOJOOMCROSS_TELEGRAM_DEFAULT_BOT_TOKEN="Default Bot Token"
PLG_MOKOJOOMCROSS_TELEGRAM_DEFAULT_BOT_TOKEN_DESC="Bot API token for the default MokoWaaS bot. Services using 'default' mode will use this token. Leave empty to require custom tokens on each service."
PLG_MOKOJOOMCROSS_TELEGRAM_PARSE_MODE="Message Format"
PLG_MOKOJOOMCROSS_TELEGRAM_PARSE_MODE_DESC="How Telegram parses formatting in messages."
PLG_MOKOJOOMCROSS_TELEGRAM_DISABLE_PREVIEW="Disable Link Preview"
PLG_MOKOJOOMCROSS_TELEGRAM_DISABLE_PREVIEW_DESC="Disable automatic link preview in Telegram messages."
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Telegram\Extension\TelegramService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -181,9 +181,7 @@ class TelegramService extends CMSPlugin implements SubscriberInterface, MokoJoom
return $credentials['bot_token'] ?? '';
}
// Default mode — load from component encrypted params
$componentParams = \Joomla\CMS\Component\ComponentHelper::getParams('com_mokojoomcross');
return $componentParams->get('telegram_default_bot_token', '');
// Default mode — load from plugin params (set in Extensions → Plugins → MokoJoomCross - Telegram)
return $this->params->get('default_bot_token', '');
}
}
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - Telegram</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -17,7 +17,7 @@ use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\MokoJoomCross${CLASS_NAME}\Extension${CLASS_NAME}Service;
use Joomla\Plugin\MokoJoomCross\Twitter\Extension\TwitterService;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="mokojoomcross" method="upgrade">
<name>MokoJoomCross - X / Twitter</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="system" method="upgrade">
<name>System - MokoJoomCross</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -17,47 +17,120 @@ use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\MokoJoomCross\Administrator\Service\MokoJoomCrossServiceInterface;
use Joomla\Event\SubscriberInterface;
/**
* System plugin that triggers cross-posting when Joomla articles are published.
*
* Listens for onContentAfterSave events on com_content articles. When an article
* transitions to published state, it dispatches the post to all enabled service
* plugins in the `mokojoomcross` plugin group.
* Flow:
* 1. Article saved → onContentAfterSave fires
* 2. Check: is it a com_content article? Is it published? Is auto-post enabled?
* 3. Load enabled services from #__mokojoomcross_services
* 4. Skip services that already have a post for this article (duplicate guard)
* 5. Render message template with article placeholders
* 6. Queue post record, then immediately attempt dispatch to the service plugin
* 7. Service plugin calls the platform API and returns success/failure
* 8. Update post status and log the result
*/
class MokoJoomCross extends CMSPlugin implements SubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'onContentAfterSave' => 'onContentAfterSave',
'onContentAfterSave' => 'onContentAfterSave',
'onContentChangeState' => 'onContentChangeState',
'onAfterRender' => 'onAfterRender',
];
}
/**
* Process queued posts on page load (backend and/or frontend).
*
* Only runs if page-load processing is enabled in component config,
* and only once per throttle interval (default 5 minutes).
*/
public function onAfterRender(): void
{
$componentParams = ComponentHelper::getParams('com_mokojoomcross');
$processingMode = $componentParams->get('queue_processing', 'scheduler');
if ($processingMode !== 'pageload' && $processingMode !== 'both') {
return;
}
$app = $this->getApplication();
$pageloadClient = $componentParams->get('pageload_client', 'both');
if ($pageloadClient === 'admin' && !$app->isClient('administrator')) {
return;
}
if ($pageloadClient === 'site' && !$app->isClient('site')) {
return;
}
// Throttle: only run once per interval
$throttleSeconds = (int) $componentParams->get('pageload_interval', 300);
$lastRun = (int) $componentParams->get('_pageload_last_run', 0);
if ((time() - $lastRun) < $throttleSeconds) {
return;
}
if (!\Joomla\Component\MokoJoomCross\Administrator\Helper\QueueProcessor::hasPendingWork()) {
return;
}
$this->updateLastRunTimestamp();
// Small batch to avoid slowing page loads
\Joomla\Component\MokoJoomCross\Administrator\Helper\QueueProcessor::processQueue(5);
}
/**
* Store the last page-load run timestamp.
*/
private function updateLastRunTimestamp(): void
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$params = json_decode($db->loadResult() ?: '{}', true) ?: [];
$params['_pageload_last_run'] = time();
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote(json_encode($params)))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_mokojoomcross'));
$db->setQuery($query);
$db->execute();
}
/**
* Triggered after a content item is saved.
*
* @param string $context The context (e.g. 'com_content.article')
* @param object $article The article object
* @param bool $isNew Whether this is a new article
*
* @return void
*/
public function onContentAfterSave(string $context, $article, bool $isNew): void
{
// Only process Joomla articles
if ($context !== 'com_content.article') {
return;
}
// Only cross-post when article is published
if ((int) ($article->state ?? 0) !== 1) {
return;
}
// Check global auto-post setting
$componentParams = ComponentHelper::getParams('com_mokojoomcross');
if (!$componentParams->get('auto_post_on_publish', 1)) {
@@ -67,12 +140,39 @@ class MokoJoomCross extends CMSPlugin implements SubscriberInterface
$this->dispatchCrossPost($article);
}
/**
* Triggered when article state changes (e.g. unpublished → published via list toggle).
*/
public function onContentChangeState(string $context, array $pks, int $value): void
{
if ($context !== 'com_content.article' || $value !== 1) {
return;
}
$componentParams = ComponentHelper::getParams('com_mokojoomcross');
if (!$componentParams->get('auto_post_on_publish', 1)) {
return;
}
$db = Factory::getDbo();
foreach ($pks as $pk) {
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__content'))
->where($db->quoteName('id') . ' = ' . (int) $pk);
$db->setQuery($query);
$article = $db->loadObject();
if ($article) {
$this->dispatchCrossPost($article);
}
}
}
/**
* Dispatch article to all enabled service plugins.
*
* @param object $article The article object
*
* @return void
*/
private function dispatchCrossPost(object $article): void
{
@@ -92,43 +192,168 @@ class MokoJoomCross extends CMSPlugin implements SubscriberInterface
return;
}
// Import service plugins
// Import service plugins so they register with the dispatcher
PluginHelper::importPlugin('mokojoomcross');
// Collect registered service plugin instances
$servicePlugins = [];
$this->getApplication()->getDispatcher()->dispatch(
'onMokoJoomCrossGetServices',
new \Joomla\Event\Event('onMokoJoomCrossGetServices', [&$servicePlugins])
);
// Index by service type for lookup
$pluginMap = [];
foreach ($servicePlugins as $plugin) {
if ($plugin instanceof MokoJoomCrossServiceInterface) {
$pluginMap[$plugin->getServiceType()] = $plugin;
}
}
$componentParams = ComponentHelper::getParams('com_mokojoomcross');
$maxRetry = (int) $componentParams->get('retry_max', 3);
// Per-article selective cross-posting (#19)
// If article attribs contain mokojoomcross_services, only post to those service IDs.
// If mokojoomcross_skip is set, skip cross-posting entirely.
$attribs = json_decode($article->attribs ?? '{}', true) ?: [];
$selectedServiceIds = $attribs['mokojoomcross_services'] ?? null;
$skipCrossPost = !empty($attribs['mokojoomcross_skip']);
if ($skipCrossPost) {
return;
}
// If specific services selected, convert to array of ints for filtering
if (is_array($selectedServiceIds) && !empty($selectedServiceIds)) {
$selectedServiceIds = array_map('intval', $selectedServiceIds);
} else {
$selectedServiceIds = null; // null = post to all
}
foreach ($services as $service) {
// Queue the post
// Per-article filter: skip if article specifies services and this one isn't in the list
if ($selectedServiceIds !== null && !in_array((int) $service->id, $selectedServiceIds, true)) {
continue;
}
// Duplicate guard — skip if article already posted/queued for this service
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('#__mokojoomcross_posts'))
->where($db->quoteName('article_id') . ' = ' . (int) $article->id)
->where($db->quoteName('service_id') . ' = ' . (int) $service->id)
->where($db->quoteName('status') . ' IN (' . $db->quote('queued') . ',' . $db->quote('posted') . ',' . $db->quote('posting') . ')');
$db->setQuery($query);
if ((int) $db->loadResult() > 0) {
continue;
}
$message = $this->renderTemplate($article, $service);
// Create queue entry
$post = (object) [
'article_id' => $article->id,
'service_id' => $service->id,
'status' => 'queued',
'message' => $this->renderTemplate($article, $service),
'created' => Factory::getDate()->toSql(),
'modified' => Factory::getDate()->toSql(),
'article_id' => (int) $article->id,
'service_id' => (int) $service->id,
'status' => 'queued',
'message' => $message,
'platform_post_id' => '',
'platform_response' => '',
'error_message' => '',
'retry_count' => 0,
'created' => Factory::getDate()->toSql(),
'modified' => Factory::getDate()->toSql(),
];
$db->insertObject('#__mokojoomcross_posts', $post);
$postId = $db->insertid();
// Log the queue action
$log = (object) [
'post_id' => $db->insertid(),
'service_id' => $service->id,
'level' => 'info',
'message' => sprintf('Article "%s" queued for %s', $article->title, $service->service_type),
'context' => json_encode(['article_id' => $article->id]),
'created' => Factory::getDate()->toSql(),
];
// Attempt immediate dispatch if service plugin is available
$plugin = $pluginMap[$service->service_type] ?? null;
$db->insertObject('#__mokojoomcross_logs', $log);
if ($plugin) {
$this->executePost($db, $postId, $plugin, $message, $service);
} else {
$this->log($db, $postId, $service->id, 'warning',
sprintf('No service plugin found for type "%s" — post remains queued', $service->service_type));
}
}
}
/**
* Execute a cross-post via the service plugin.
*/
private function executePost($db, int $postId, MokoJoomCrossServiceInterface $plugin, string $message, object $service): void
{
// Mark as posting
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('posting'))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . $postId)
);
$db->execute();
$credentials = json_decode($service->credentials ?: '{}', true) ?: [];
$params = json_decode($service->params ?: '{}', true) ?: [];
try {
$result = $plugin->publish($message, [], $credentials, $params);
if (!empty($result['success'])) {
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('posted'))
->set($db->quoteName('platform_post_id') . ' = ' . $db->quote($result['platform_post_id'] ?? ''))
->set($db->quoteName('platform_response') . ' = ' . $db->quote(json_encode($result['response'] ?? [])))
->set($db->quoteName('posted_at') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . $postId)
);
$db->execute();
$this->log($db, $postId, $service->id, 'info',
sprintf('Posted to %s (platform ID: %s)', $service->service_type, $result['platform_post_id'] ?? 'n/a'));
} else {
$errorMsg = $result['response']['error'] ?? json_encode($result['response'] ?? []);
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('failed'))
->set($db->quoteName('error_message') . ' = ' . $db->quote(mb_substr($errorMsg, 0, 1000)))
->set($db->quoteName('platform_response') . ' = ' . $db->quote(json_encode($result['response'] ?? [])))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . $postId)
);
$db->execute();
$this->log($db, $postId, $service->id, 'error',
sprintf('Failed to post to %s: %s', $service->service_type, $errorMsg));
}
} catch (\Throwable $e) {
$db->setQuery(
$db->getQuery(true)
->update($db->quoteName('#__mokojoomcross_posts'))
->set($db->quoteName('status') . ' = ' . $db->quote('failed'))
->set($db->quoteName('error_message') . ' = ' . $db->quote(mb_substr($e->getMessage(), 0, 1000)))
->set($db->quoteName('modified') . ' = ' . $db->quote(Factory::getDate()->toSql()))
->where($db->quoteName('id') . ' = ' . $postId)
);
$db->execute();
$this->log($db, $postId, $service->id, 'error',
sprintf('Exception posting to %s: %s', $service->service_type, $e->getMessage()));
}
}
/**
* Render the message template for a service.
*
* @param object $article The article
* @param object $service The service record
*
* @return string Rendered message
*/
private function renderTemplate(object $article, object $service): string
{
@@ -146,21 +371,76 @@ class MokoJoomCross extends CMSPlugin implements SubscriberInterface
->setLimit(1);
$db->setQuery($query);
$template = $db->loadResult() ?: '{title}\n\n{url}';
$template = $db->loadResult() ?: "{title}\n\n{url}";
// Build article URL
$url = \Joomla\CMS\Uri\Uri::root() . 'index.php?option=com_content&view=article&id=' . $article->id;
// Build SEF article URL
$url = Uri::root() . 'index.php?option=com_content&view=article&id=' . $article->id;
if (!empty($article->catid)) {
$url .= '&catid=' . $article->catid;
}
// Resolve category name
$categoryName = '';
if (!empty($article->catid)) {
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__categories'))
->where($db->quoteName('id') . ' = ' . (int) $article->catid);
$db->setQuery($query);
$categoryName = $db->loadResult() ?: '';
}
// Resolve author name
$authorName = '';
if (!empty($article->created_by)) {
$query = $db->getQuery(true)
->select($db->quoteName('name'))
->from($db->quoteName('#__users'))
->where($db->quoteName('id') . ' = ' . (int) $article->created_by);
$db->setQuery($query);
$authorName = $db->loadResult() ?: '';
}
// Extract intro image
$introImage = '';
$images = json_decode($article->images ?? '{}');
if (!empty($images->image_intro)) {
$introImage = Uri::root() . ltrim($images->image_intro, '/');
}
// Replace placeholders
$replacements = [
'{title}' => $article->title ?? '',
'{introtext}' => strip_tags(mb_substr($article->introtext ?? '', 0, 280)),
'{fulltext}' => strip_tags(mb_substr($article->fulltext ?? '', 0, 500)),
'{url}' => $url,
'{image}' => json_decode($article->images ?? '{}')->image_intro ?? '',
'{category}' => '',
'{author}' => '',
'{image}' => $introImage,
'{category}' => $categoryName,
'{author}' => $authorName,
'{date}' => Factory::getDate($article->publish_up ?? 'now')->format('Y-m-d'),
];
return str_replace(array_keys($replacements), array_values($replacements), $template);
}
/**
* Write an entry to the activity log.
*/
private function log($db, ?int $postId, ?int $serviceId, string $level, string $message): void
{
$log = (object) [
'post_id' => $postId,
'service_id' => $serviceId,
'level' => $level,
'message' => mb_substr($message, 0, 2000),
'context' => '{}',
'created' => Factory::getDate()->toSql(),
];
$db->insertObject('#__mokojoomcross_logs', $log);
}
}
@@ -0,0 +1 @@
<\!DOCTYPE html><title></title>
@@ -0,0 +1 @@
<\!DOCTYPE html><title></title>
@@ -0,0 +1,9 @@
; Task - MokoJoomCross Queue Processor Language File
; Copyright (C) 2026 Moko Consulting. All rights reserved.
; License: GPL-3.0-or-later
PLG_TASK_MOKOJOOMCROSS="Task - MokoJoomCross Queue Processor"
PLG_TASK_MOKOJOOMCROSS_DESCRIPTION="Joomla Scheduled Task for processing the MokoJoomCross cross-post queue. Handles queued posts, retries, scheduled posts, and log cleanup."
PLG_TASK_MOKOJOOMCROSS_PROCESS_QUEUE_TITLE="MokoJoomCross - Process Queue"
PLG_TASK_MOKOJOOMCROSS_PROCESS_QUEUE_DESC="Process queued cross-posts, retry failed posts, fire scheduled posts, and clean up old logs."
@@ -0,0 +1,2 @@
PLG_TASK_MOKOJOOMCROSS="Task - MokoJoomCross Queue Processor"
PLG_TASK_MOKOJOOMCROSS_DESCRIPTION="Joomla Scheduled Task for processing the MokoJoomCross cross-post queue."
@@ -0,0 +1 @@
<\!DOCTYPE html><title></title>
@@ -0,0 +1,12 @@
<?php
/**
* @package MokoJoomCross
* @subpackage plg_task_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="task" method="upgrade">
<name>Task - MokoJoomCross Queue Processor</name>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
<authorUrl>https://mokoconsulting.tech</authorUrl>
<copyright>Copyright (C) 2026 Moko Consulting. All rights reserved.</copyright>
<license>GPL-3.0-or-later</license>
<description>PLG_TASK_MOKOJOOMCROSS_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Task\MokoJoomCross</namespace>
<files>
<filename plugin="mokojoomcross">mokojoomcross.php</filename>
<folder>src</folder>
<folder>services</folder>
<folder>language</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_task_mokojoomcross.ini</language>
<language tag="en-GB">language/en-GB/plg_task_mokojoomcross.sys.ini</language>
</languages>
</extension>
@@ -0,0 +1 @@
<\!DOCTYPE html><title></title>
@@ -0,0 +1,38 @@
<?php
/**
* @package MokoJoomCross
* @subpackage plg_task_mokojoomcross
* @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
*/
defined('_JEXEC') or die;
use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Task\MokoJoomCross\Extension\MokoJoomCrossTask;
return new class () implements ServiceProviderInterface {
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new MokoJoomCrossTask(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('task', 'mokojoomcross')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};
@@ -0,0 +1,85 @@
<?php
/**
* @package MokoJoomCross
* @subpackage plg_task_mokojoomcross
* @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 Joomla\Plugin\Task\MokoJoomCross\Extension;
defined('_JEXEC') or die;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\MokoJoomCross\Administrator\Helper\QueueProcessor;
use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent;
use Joomla\Component\Scheduler\Administrator\Task\Status as TaskStatus;
use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait;
use Joomla\Event\SubscriberInterface;
/**
* Joomla Scheduled Task plugin for MokoJoomCross queue processing.
*
* Registers with Joomla's Task Scheduler (System → Scheduled Tasks).
* Admin can create a task of type "MokoJoomCross - Process Queue"
* and configure the interval (recommended: every 5 minutes).
*
* This is the PREFERRED processing method. Page-load processing is
* a fallback for environments without cron/scheduler access.
*/
class MokoJoomCrossTask extends CMSPlugin implements SubscriberInterface
{
use TaskPluginTrait;
/**
* @var string[] The task type IDs this plugin provides
*/
protected const TASKS_MAP = [
'mokojoomcross.process_queue' => [
'langConstPrefix' => 'PLG_TASK_MOKOJOOMCROSS_PROCESS_QUEUE',
'method' => 'processQueue',
'form' => '',
],
];
public static function getSubscribedEvents(): array
{
return [
'onTaskOptionsList' => 'advertiseRoutines',
'onExecuteTask' => 'standardRoutineHandler',
'onContentPrepareForm' => 'enhanceTaskItemForm',
];
}
/**
* Process the cross-post queue.
*
* @param ExecuteTaskEvent $event The task event
*
* @return int Task status code
*/
private function processQueue(ExecuteTaskEvent $event): int
{
$result = QueueProcessor::processQueue(20);
// Log summary
$this->logTask(sprintf(
'MokoJoomCross queue: %d processed, %d succeeded, %d failed, %d skipped',
$result['processed'],
$result['succeeded'],
$result['failed'],
$result['skipped']
));
if ($result['skipped'] === -1) {
$this->logTask('Queue processing skipped — another process holds the lock');
return TaskStatus::KNOCKOUT;
}
return TaskStatus::OK;
}
}
@@ -0,0 +1 @@
<\!DOCTYPE html><title></title>
@@ -0,0 +1 @@
<\!DOCTYPE html><title></title>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="webservices" method="upgrade">
<name>Web Services - MokoJoomCross</name>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
+3 -2
View File
@@ -2,7 +2,7 @@
<extension type="package" method="upgrade">
<name>MokoJoomCross</name>
<packagename>mokojoomcross</packagename>
<version>01.00.00-dev</version>
<version>01.00.06-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<author>Moko Consulting</author>
<authorEmail>hello@mokoconsulting.tech</authorEmail>
@@ -19,6 +19,7 @@
<file type="plugin" id="mokojoomcross" group="system">plg_system_mokojoomcross.zip</file>
<file type="plugin" id="mokojoomcross" group="content">plg_content_mokojoomcross.zip</file>
<file type="plugin" id="mokojoomcross" group="webservices">plg_webservices_mokojoomcross.zip</file>
<file type="plugin" id="mokojoomcross" group="task">plg_task_mokojoomcross.zip</file>
<!-- Service Plugins (mokojoomcross group) -->
<file type="plugin" id="facebook" group="mokojoomcross">plg_mokojoomcross_facebook.zip</file>
@@ -37,6 +38,6 @@
</languages>
<updateservers>
<server type="extension" name="MokoJoomCross Updates">https://git.mokoconsulting.tech/MokoConsulting/MokoJoomCross/updates.xml</server>
<server type="extension" name="MokoJoomCross Updates">https://git.mokoconsulting.tech/MokoConsulting/MokoJoomCross/raw/branch/main/updates.xml</server>
</updateservers>
</extension>
+1
View File
@@ -63,6 +63,7 @@ class Pkg_MokoJoomCrossInstallerScript
['system', 'mokojoomcross'],
['content', 'mokojoomcross'],
['webservices', 'mokojoomcross'],
['task', 'mokojoomcross'],
];
foreach ($corePlugins as [$folder, $element]) {
+26
View File
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
SPDX-License-Identifier: GPL-3.0-or-later
VERSION: 01.00.06-dev-dev-dev
-->
<updates>
<update>
<name>Package - MokoJoomCross</name>
<description>Package - MokoJoomCross development build.</description>
<element>pkg_mokojoomcross</element>
<type>package</type>
<client>site</client>
<version>01.00.06-dev-dev-dev</version>
<creationDate>2026-05-28</creationDate>
<infourl title='Package - MokoJoomCross'>https://git.mokoconsulting.tech/MokoConsulting/MokoJoomCross/releases/tag/development</infourl>
<downloads>
<downloadurl type='full' format='zip'>https://git.mokoconsulting.tech/MokoConsulting/MokoJoomCross/releases/download/development/pkg_mokojoomcross-01.00.06-dev-dev-dev.zip</downloadurl>
</downloads>
<sha256>87314ba561f5f1587d2ea3470a3426857bffc556ba3ea66deb7da6a6118930bd</sha256>
<tags><tag>dev</tag></tags>
<maintainer>Moko Consulting</maintainer>
<maintainerurl>https://mokoconsulting.tech</maintainerurl>
<targetplatform name="joomla" version="(5|6)\..*" />
</update>
</updates>
+77
View File
@@ -0,0 +1,77 @@
# Message Templates
MokoJoomCross uses message templates to format the content sent to each platform. Templates support placeholders that are replaced with article data at post time.
## Managing Templates
Navigate to **Components → MokoJoomCross → Templates** to create and edit templates.
## Template Priority
When cross-posting, the system looks for templates in this order:
1. **Platform-specific template** — matches the service type exactly (e.g., "twitter")
2. **Default template** — fallback used when no platform-specific template exists
## Available Placeholders
| Placeholder | Description | Example |
|-------------|-------------|---------|
| `{title}` | Article title | "New Product Launch" |
| `{url}` | Full article URL | "https://example.com/article/123" |
| `{introtext}` | Intro text (280 chars, HTML stripped) | "We're excited to announce..." |
| `{fulltext}` | Full text (500 chars, HTML stripped) | Extended content |
| `{image}` | Intro image full URL | "https://example.com/images/photo.jpg" |
| `{category}` | Article category name | "News" |
| `{author}` | Author display name | "John Smith" |
| `{date}` | Publish date (YYYY-MM-DD) | "2026-05-28" |
## Example Templates
### Default (all platforms)
```
{title}
{introtext}
{url}
```
### Twitter / X (280 char limit)
```
{title}
{url}
```
### Mastodon (with hashtags)
```
{title}
{introtext}
{url}
#Joomla #{category}
```
### Mailchimp (HTML email)
```html
<h1>{title}</h1>
<p>{introtext}</p>
<p><a href="{url}">Read the full article</a></p>
```
### Telegram (HTML format)
```html
<b>{title}</b>
{introtext}
<a href="{url}">Read more</a>
```
## Per-Article Override
In the article editor, the **Cross-Posting** tab lets you:
- Skip cross-posting entirely for a specific article
- Select which services to post to (instead of all enabled services)
+57
View File
@@ -0,0 +1,57 @@
# REST API
MokoJoomCross includes a WebServices plugin that provides REST API endpoints via Joomla's API application.
## Authentication
All endpoints require a Joomla API token. Generate one in **Users → Manage → [User] → API Tokens**.
Include the token in the `Authorization` header:
```
Authorization: Bearer YOUR_API_TOKEN
```
## Base URL
```
https://yoursite.com/api/index.php/v1/mokojoomcross/
```
## Endpoints
### Posts
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/v1/mokojoomcross/posts` | List all cross-posts |
| GET | `/v1/mokojoomcross/posts/:id` | Get single post details |
| POST | `/v1/mokojoomcross/posts` | Create a cross-post entry |
| DELETE | `/v1/mokojoomcross/posts/:id` | Delete a post |
### Services
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/v1/mokojoomcross/services` | List connected services |
| GET | `/v1/mokojoomcross/services/:id` | Get service details |
## Example
```bash
# List all posts
curl -H "Authorization: Bearer YOUR_TOKEN" \
https://yoursite.com/api/index.php/v1/mokojoomcross/posts
# List services
curl -H "Authorization: Bearer YOUR_TOKEN" \
https://yoursite.com/api/index.php/v1/mokojoomcross/services
```
## Filtering
Posts support query parameters:
- `filter[status]=posted` — Filter by status (queued, posting, posted, failed, scheduled)
- `filter[service_id]=5` — Filter by service
- `page[limit]=20` — Pagination limit
- `page[offset]=0` — Pagination offset
+60
View File
@@ -0,0 +1,60 @@
# Services
MokoJoomCross supports 9 platforms. Each is a separate plugin that can be enabled or disabled independently.
## Social Media
| Platform | Plugin | Character Limit | Media | Default Bot |
|----------|--------|----------------|-------|-------------|
| **Facebook** | plg_mokojoomcross_facebook | No limit | Yes | Yes |
| **X / Twitter** | plg_mokojoomcross_twitter | 280 | Yes | No |
| **LinkedIn** | plg_mokojoomcross_linkedin | 3,000 | Yes | No |
| **Mastodon** | plg_mokojoomcross_mastodon | 500 | Yes | No |
| **Bluesky** | plg_mokojoomcross_bluesky | 300 | Yes | No |
## Email Marketing
| Platform | Plugin | Character Limit | Media | Default Bot |
|----------|--------|----------------|-------|-------------|
| **Mailchimp** | plg_mokojoomcross_mailchimp | No limit | Yes | No |
## Chat / Messaging
| Platform | Plugin | Character Limit | Media | Default Bot |
|----------|--------|----------------|-------|-------------|
| **Telegram** | plg_mokojoomcross_telegram | 4,096 | Yes | Yes (@MokoWaaSBot) |
| **Discord** | plg_mokojoomcross_discord | 2,000 | Yes | Yes (webhook) |
| **Slack** | plg_mokojoomcross_slack | 40,000 | Yes | Yes (webhook) |
## Default vs Custom Mode
Services with "Default Bot" support offer two operating modes:
- **Default Mode**: Uses a pre-configured bot/app token managed by Moko. The admin only needs to provide a destination (chat ID, page ID, etc.). The API key is stored in the plugin's configuration and never visible in the service record.
- **Custom Mode**: The admin provides their own API keys, tokens, or webhook URLs. Full control, but requires setting up your own app/bot on the platform.
Configure default tokens in **Extensions → Plugins → MokoJoomCross - [Platform]**.
## Adding a Service
1. Go to **Components → MokoJoomCross → Services**
2. Click **New**
3. Select the service type
4. Enter a title and choose credentials mode
5. For **Default mode**: enter only the destination (chat ID, channel, etc.)
6. For **Custom mode**: enter your full API credentials as JSON
7. Save and enable
## Credentials Format
Each service expects specific JSON fields. See the individual service pages:
- [[Telegram]] — bot_token, chat_id
- [[Facebook]] — page_access_token, page_id
- [[Discord]] — webhook_url
- [[Slack]] — webhook_url
- [[LinkedIn]] — access_token, organization_id
- [[Mastodon]] — instance_url, access_token
- [[Bluesky]] — handle, app_password
- [[Mailchimp]] — api_key, list_id
- [[Twitter (X)]] — bearer_token, api_key, api_secret

Some files were not shown because too many files have changed in this diff Show More