80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?php
|
|
|
|
use dokuwiki\Extension\SyntaxPlugin;
|
|
|
|
require_once(__DIR__ . '/../autoload.php');
|
|
|
|
/**
|
|
* luxtools Plugin: Calendar sync button syntax.
|
|
*
|
|
* Renders a manual calendar sync button on any wiki page.
|
|
* Only visible to admins. The actual sync is handled by the
|
|
* existing AJAX endpoint (luxtools_calendar_sync).
|
|
*
|
|
* Syntax:
|
|
* - {{calendar_sync>}}
|
|
*/
|
|
class syntax_plugin_luxtools_calendarsync extends SyntaxPlugin
|
|
{
|
|
/** @inheritdoc */
|
|
public function getType()
|
|
{
|
|
return 'substition';
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
public function getPType()
|
|
{
|
|
return 'block';
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
public function getSort()
|
|
{
|
|
return 225;
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
public function connectTo($mode)
|
|
{
|
|
$this->Lexer->addSpecialPattern('\{\{calendar_sync>\}\}', $mode, 'plugin_luxtools_calendarsync');
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
public function handle($match, $state, $pos, Doku_Handler $handler)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/** @inheritdoc */
|
|
public function render($format, Doku_Renderer $renderer, $data)
|
|
{
|
|
if ($data === false || !is_array($data)) return false;
|
|
if ($format !== 'xhtml') return false;
|
|
if (!($renderer instanceof Doku_Renderer_xhtml)) return false;
|
|
|
|
$renderer->nocache();
|
|
|
|
// Only render for authenticated users
|
|
if (empty($_SERVER['REMOTE_USER'])) {
|
|
return true;
|
|
}
|
|
|
|
$ajaxUrl = defined('DOKU_BASE') ? (string)DOKU_BASE . 'lib/exe/ajax.php' : 'lib/exe/ajax.php';
|
|
$sectok = function_exists('getSecurityToken') ? getSecurityToken() : '';
|
|
|
|
$buttonLabel = (string)$this->getLang('calendar_sync_button');
|
|
if ($buttonLabel === '') $buttonLabel = 'Sync Calendars';
|
|
|
|
$renderer->doc .= '<div class="luxtools-plugin luxtools-calendar-sync-widget">';
|
|
$renderer->doc .= '<button type="button" class="button luxtools-calendar-sync-btn"'
|
|
. ' data-luxtools-ajax-url="' . hsc($ajaxUrl) . '"'
|
|
. ' data-luxtools-sectok="' . hsc($sectok) . '"'
|
|
. '>' . hsc($buttonLabel) . '</button>';
|
|
$renderer->doc .= '<span class="luxtools-calendar-sync-status"></span>';
|
|
$renderer->doc .= '</div>';
|
|
|
|
return true;
|
|
}
|
|
}
|