<?php

use Supertext\Polylang\Helper\Constant;
use Supertext\Polylang\Api\Multilang;
use Supertext\Polylang\Api\Wrapper;
use Comotive\Util\ArrayManipulation;
/** @var Page $context */
$library = $context->getCore()->getLibrary();
$options = $library->getSettingOption();
$languageMap = isset($options[Constant::SETTING_LANGUAGE_MAP]) ? ArrayManipulation::forceArray($options[Constant::SETTING_LANGUAGE_MAP]) : array();
// Laod Languages from Polylang to match with supertext api
$htmlLanguageDropdown = '';
// Create the language matcher dropdown
foreach (Multilang::getLanguages() as $language) {
    // Get anonymous wrapper to get languages
    $api = Wrapper::getInstance();
    $stMapping = $api->getLanguageMapping($language->slug);
    $languageDropdown = '';
    foreach ($stMapping as $languageCode => $languageName) {
        $selected = '';
        if (isset($languageMap[$language->slug]) && $languageMap[$language->slug] == $languageCode) {
            $selected = ' selected';
        }
        $languageDropdown .= '<option value="' . $languageCode . '"' . $selected . '>' . $languageName . '</option>';
    }
    $languageDropdown = '
    <select name="sel_st_language_' . $language->slug . '" id="sel_st_language_' . $language->slug . '">
      <option value="">' . __('Please select', 'polylang-supertext') . '...</option>
      ' . $languageDropdown . '
    </select>';
    $htmlLanguageDropdown .= '
<?php

use Supertext\Polylang\Helper\Constant;
use Comotive\Util\ArrayManipulation;
global $shortcode_tags;
$library = $context->getCore()->getLibrary();
$options = $library->getSettingOption();
$savedShortcodes = isset($options[Constant::SETTING_SHORTCODES]) ? ArrayManipulation::forceArray($options[Constant::SETTING_SHORTCODES]) : array();
?>
<div class="postbox postbox_admin">
  <div class="inside">
    <h3><?php 
_e('Translatable Shortcodes', 'polylang-supertext');
?>
</h3>
    <table id="tblShortcodes">
      <thead>
      <tr>
        <th colspan="2"><?php 
_e('Shortcode', 'polylang-supertext');
?>
</th>
        <th><?php 
_e('Attributes', 'polylang-supertext');
?>
</th>
      </tr>
      </thead>
      <tbody>
      <?php 
foreach ($shortcode_tags as $key => $function) {
<?php

use Supertext\Polylang\Helper\Constant;
use Comotive\Util\ArrayManipulation;
/** @var Page $context */
$library = $context->getCore()->getLibrary();
$options = $library->getSettingOption();
$userMap = isset($options[Constant::SETTING_USER_MAP]) ? ArrayManipulation::forceArray($options[Constant::SETTING_USER_MAP]) : array();
// Get all users
$wpUsers = get_users();
$userList = array();
$userOptions = '';
foreach ((array) $wpUsers as $wpUser) {
    $userList[] = $wpUser->display_name . '$$' . $wpUser->data->user_login . '$$' . $wpUser->data->ID;
}
natcasesort($userList);
foreach ((array) $userList as $user) {
    $user = explode('$$', $user);
    $userOptions .= '<option value=\'' . $user[2] . '\'>' . $user[0] . ' (' . $user[1] . ')</option>';
}
// Generate select template
$selectTemplate = '' . '<select name=\'selStWpUsers[]\'>' . '<option value=\'\'>' . __('Select user', 'polylang-supertext') . '...</option>' . $userOptions . '</select>';
?>

<div class="postbox postbox_admin">
  <div id="frmSupertext" class="inside frmServiceSupertextConfig">
    <h3><?php 
_e('Supertext Accounts', 'polylang-supertext');
?>
</h3>
    <p>
        $id = $node['id'];
        $icon = $node['type'] === 'field' ? 'jstree-file' : 'jstree-folder';
        $nodeHtml .= '<li id="' . $id . '" data-jstree=\'{"icon":"' . $icon . '"}\'>';
        $nodeHtml .= $node['label'];
        if (count($node['field_definitions']) > 0) {
            $nodeHtml .= getTree($node['field_definitions']);
        }
        $nodeHtml .= '</li>';
    }
    $nodeHtml .= '</ul>';
    return $nodeHtml;
}
/** @var Page $context */
$library = $context->getCore()->getLibrary();
$options = $library->getSettingOption();
$savedCustomFieldDefinitions = isset($options[Constant::SETTING_CUSTOM_FIELDS]) ? ArrayManipulation::forceArray($options[Constant::SETTING_CUSTOM_FIELDS]) : array();
$customFieldDefinitions = $context->getCustomFieldDefinitions();
$htmlTree = getTree($customFieldDefinitions);
$savedCustomFieldIds = array();
foreach ($savedCustomFieldDefinitions as $savedCustomFieldDefinition) {
    $savedCustomFieldIds[] = $savedCustomFieldDefinition['id'];
}
?>
<div class="postbox postbox_admin">
  <div class="inside">
    <h3><?php 
_e('Translatable Custom Fields', 'polylang-supertext');
?>
</h3>
    <p>
      <?php