View source
<?php
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
define('XBBCODE_RE_QUOTE', '"|\'|&(quot|#039);|');
define('XBBCODE_RE_ATTR', '(?:\\s+(?<key>\\w+)=(?<aq>' . XBBCODE_RE_QUOTE . ')(?<value>[^"]*?)\\g{aq}(?=\\s|\\]|$))');
define('XBBCODE_RE_TAG', '/\\[(?<closing>\\/)?(?<name>\\w+)(?:=(?<bq>' . XBBCODE_RE_QUOTE . ')(?<option>.*?)\\g{bq}(?=\\s|\\])|(?<attrs>' . XBBCODE_RE_ATTR . '+))?\\]/i');
function xbbcode_xbbcode_info() {
module_load_include('inc', 'xbbcode', 'xbbcode.crud');
$custom_tags = xbbcode_custom_tag_load();
$tags = array();
foreach ($custom_tags as $name => $tag) {
$tags[$name] = array(
'description' => $tag->description,
'sample' => $tag->sample,
'markup' => !$tag->options['php'] ? $tag->markup : NULL,
'callback' => $tag->options['php'] ? '_xbbcode_custom_eval' : NULL,
'options' => $tag->options,
);
}
return $tags;
}
function _xbbcode_custom_eval($tag_data, $xbbcode_filter) {
if (module_exists('php')) {
global $tag;
$tag = $tag_data;
module_load_include('inc', 'xbbcode', 'xbbcode.crud');
$code = '<?php global $tag; ?>' . xbbcode_custom_tag_load($tag->name)->markup;
$output = php_eval($code);
unset($tag);
return $output;
}
}
function xbbcode_theme() {
return array(
'xbbcode_settings_handlers_format' => array(
'render element' => 'fieldset',
'function' => 'theme_xbbcode_settings_handlers_format',
),
);
}
function xbbcode_settings_handlers_process(&$element, FormStateInterface $form_state, &$complete_form) {
foreach ($element['#options'] as $key => $value) {
$element[$key]['#default_value'] = $element[$key]['#default_value'] == $element[$key]['#return_value'];
unset($element[$key]['#return_value']);
$element[$key] = [
'enabled' => $element[$key],
];
}
return $element;
}
function theme_xbbcode_settings_handlers_format($variables) {
$fieldset = $variables['fieldset'];
$table =& $fieldset['tags'];
$selectors =& $fieldset['extra']['tags'];
$table['#attributes']['id'] = 'xbbcode-handlers';
foreach (array_keys($table['#options']) as $tag) {
$table['#options'][$tag]['module']['data'] = drupal_render($selectors[$tag]['module']);
}
ksort($table['#options']);
$html = drupal_render($table);
foreach (Element::children($fieldset) as $element) {
$html .= drupal_render($fieldset[$element]);
}
return $html;
}