/** * Gather various meta information for the upcoming offer */ public function __construct() { $this->postId = $_GET['postId']; $this->post = get_post($this->postId); $this->sourceLang = Multilang::getPostLanguage($this->post->ID); $this->targetLang = $_GET['targetLang']; }
require_once '../../../../../../wp-load.php'; use Supertext\Polylang\Core; use Supertext\Polylang\Api\Wrapper; use Supertext\Polylang\Api\Multilang; // Get json request body $response = array('message' => 'unknown error'); $requestBody = file_get_contents('php://input'); $json = json_decode($requestBody); $refData = explode('-', $json->ReferenceData, 2); $postId = $refData[0]; $secureToken = $refData[1]; // check md5 Secure String if (md5(Wrapper::REFERENCE_HASH . $postId) == $secureToken) { // Yes a valid confirmation -> load post object $targetLang = substr($json->TargetLang, 0, 2); $translationPostId = intval(Multilang::getPostInLanguage($postId, $targetLang)); // Only if valid, countinue if ($translationPostId > 0) { // Get the translation post object $post = get_post($translationPostId); // check if correct language if ($post->post_status == 'draft') { // Load attachments to merge later $attachments = get_children(array('post_parent' => $post->ID, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC')); // Create file links $attachmentFiles = array(); foreach ($attachments as $attachment) { $fileLink = get_post_meta($attachment->ID, '_wp_attached_file', true); $attachmentFiles[$fileLink] = $attachment; } // Save all translations
<?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 .= '
/** * Saves user and language settings to options */ protected function saveUserAndLanguageSettings() { // Saving the user mappings $userMap = array(); foreach ($_POST['selStWpUsers'] as $key => $id) { if (intval($id) > 0) { $userMap[] = array('wpUser' => intval($_POST['selStWpUsers'][$key]), 'stUser' => $_POST['fieldStUser'][$key], 'stApi' => $_POST['fieldStApi'][$key]); } } // Crappily create the language array $languageMap = array(); foreach ($_POST as $postField => $stLanguage) { if (substr($postField, 0, strlen('sel_st_language_')) == 'sel_st_language_') { $language = substr($postField, strlen('sel_st_language_')); $languageMap[$language] = $stLanguage; } } // Put into the options $this->library->saveSetting(Constant::SETTING_USER_MAP, $userMap); $this->library->saveSetting(Constant::SETTING_LANGUAGE_MAP, $languageMap); // Set the plugin to working mode, if both arrays are saved if (count($userMap) > 0 && count($languageMap) == count(Multilang::getLanguages())) { $this->library->saveSetting(Constant::SETTING_WORKING, 1); } else { $this->library->saveSetting(Constant::SETTING_WORKING, 0); } }