/** * @param string $user the supertext user name * @param string $apikey the supertext api key * @param string $currency the currency */ protected function __construct($user, $apikey, $currency = 'eur') { $this->user = $user; $this->apikey = $apikey; $this->currency = strtolower($currency); $this->library = Core::getInstance()->getLibrary(); $this->communicationLang = str_replace('_', '-', get_bloginfo('language')); }
/** * This was built by MHA by reference. No time to fix just yet, but it works. * @param string $output referenced output variable * @param string $state referenced request stated * @param string $optional referenced optional information */ public static function getOffer(&$output, &$state, &$optional) { $optional['requestCounter'] = $_POST['requestCounter']; // Call the API for prices $options = self::getTranslationOptions(); $library = Core::getInstance()->getLibrary(); $data = $library->getTranslationData($options['post_id'], $options['pattern']); $wrapper = $library->getUserWrapper(); // Call for prices $pricing = $wrapper->getQuote($options['source_lang'], $options['target_lang'], $data); //Check if there are no offers if (empty($pricing['options'])) { $output = __('There are no offers for this translation.', ' polylang-supertext'); $state = 'no_data'; return; } // generate html output $rows = ''; $checked = 'checked="checked"'; foreach ($pricing['options'] as $option) { $itemsCount = count($option['items']); $rows .= '<tr class="firstGroupRow"> <td class="qualityGroupCell" rowspan="' . ($itemsCount + 1) . '"><strong>' . $option['name'] . '</strong></td> <td class="selectionCell"> </td> <td> </td> <td> </td> <td> </td> </tr>'; foreach ($option['items'] as $groupRowNumber => $item) { $radioInputId = $option['id'] . "_" . $item['id']; $radioInputValue = $option['id'] . ":" . $item['id']; $rows .= ' <tr> <td class="selectionCell"> <input type="radio" data-currency="' . $pricing['currency'] . '" name="rad_translation_type" id="rad_translation_type_' . $radioInputId . '" value="' . $radioInputValue . '" ' . $checked . '> </td> <td> <label for="rad_translation_type_' . $radioInputId . '">' . $item['name'] . '</label> </td> <td align="right" class="ti_deadline"> <label for="rad_translation_type_' . $radioInputId . '">' . date_i18n('D, d. F H:i', strtotime($item['date'])) . '</label> </td> <td align="right" class="ti_price"> <label for="rad_translation_type_' . $radioInputId . '">' . $pricing['currency'] . ' ' . String::numberFormat($item['price'], 2) . '</label> </td> </tr> '; $checked = ''; } $rows .= '<tr class="lastGroupRow"></tr>'; } $output .= '<table border="0" cellpadding="2" cellspacing="0"> <thead> <tr> <td> </td> <td class="selectionCell"> </td> <td><strong>' . __('Duration', 'polylang-supertext') . '</strong></td> <td align="right"><strong>' . __('Translation until', 'polylang-supertext') . '</strong></td> <td align="right"><strong>' . __('Price', 'polylang-supertext') . '</strong></td> </tr> </thead> <tbody> ' . $rows . ' </tbody> </table>'; $state = 'success'; }
default: $translatedAttachment->{$translationItem->Id} = html_entity_decode($translationItem->Content, ENT_COMPAT | ENT_HTML401, 'UTF-8'); break; } } // Save the attachment wp_update_post($translatedAttachment); } } break; } } // Now finally save that post and flush cache wp_update_post($post); $response['message'] = __('translation saved successfully', 'polylang-supertext'); Core::getInstance()->getLog()->addEntry($translationPostId, $response['message']); } else { $response['message'] = __('error: can only import into draft article', 'polylang-supertext'); Core::getInstance()->getLog()->addEntry($translationPostId, $response['message']); } } else { $response['message'] = __('error: wrong language or translation post has been deleted', 'polylang-supertext'); Core::getInstance()->getLog()->addEntry($postId, $response['message']); } } else { $response['message'] = __('error: method not allowed', 'polylang-supertext'); Core::getInstance()->getLog()->addEntry($postId, $response['message']); } // Print the response header('Content-Type: application/json'); echo json_encode($response);
/** * @return string error message or informational text */ protected function getTranslationApiHtml() { // search translation feature and use first result if (!Core::getInstance()->getLibrary()->isWorking()) { return __('The Supertext plugin hasn\'t been configured correctly.', 'polylang-supertext'); } // Return info about supertext return ' <div> <span style="float:left;"><img src="' . SUPERTEXT_POLYLANG_RESOURCE_URL . '/images/icon-st.png" alt="Supertext" title="Supertext"> </span> <span style="float:left;"><h2>Supertext: ' . __('Order article translation', 'polylang-supertext') . '</h2></span> </div> <br><br><br> '; }
/** * Show supertext log information, if there are entries for the current post */ public function addLogInfoMetabox() { $postId = intval($_GET['post']); $logEntries = Core::getInstance()->getLog()->getLogEntries($postId); // Show info if valid post and there are entries if ($postId > 0 && count($logEntries) > 0) { // Reverse entries, so that the newest is on top $logEntries = array_reverse($logEntries); // Create an html element to display the entries $html = ''; foreach ($logEntries as $entry) { $datetime = ' ' . Date::getTime(Date::EU_DATE, $entry['datetime']) . ', ' . Date::getTime(Date::EU_TIME, $entry['datetime']) . ' '; $html .= '<p><strong>' . $datetime . '</strong>: ' . $entry['message'] . '</p>'; } $helper = Metabox::get('post'); // Add a new metabox to show log entries $helper->addMetabox(Log::META_LOG, __('Supertext Plugin Log', 'polylang-supertext'), 'side', 'low'); $helper->addHtml('info', Log::META_LOG, $html); } }
/** * Create references to core and library for convenience */ public function __construct() { $this->core = Core::getInstance(); $this->library = $this->core->getLibrary(); add_action('admin_init', array($this, 'control')); }