File "classes.php"
Full Path: /www/wwwroot/shphe-en.com/wp-content/plugins/prisna-wp-translate/classes/classes.php
File size: 484.29 KB
MIME-type: --
Charset: utf-8
<?php
/**
* Prisna WP Translate
* http://www.prisna.net/
*
* LICENSE
*
* @package Prisna WP Translate
* @copyright Copyright (c) 2017, Prisna Ltd, www.prisna.net
* @license http://www.prisna.net/license/
* @version 1.11
* @date 2017-05-03
*/
class PrisnaWPTranslateCommon { public static function isBot() { $user_agent = self::getUserAgent(); return preg_match('/bot|crawl|slurp|spider/i', $user_agent); } public static function isEditOnSite() { if (PrisnaWPTranslateCommon::getVariable('prisna-translate-onsite', 'GET') !== false) return current_user_can('manage_options') || self::userIsTranslator(); return false; } public static function xpathEscape($_string) { if (strpos($_string, "'") === false) return sprintf("'%s'", $_string); if (strpos($_string, '"') === false) return sprintf('"%s"', $_string); return sprintf( "concat('%s')", str_replace("'", "',\"'\",'", $_string) ); } public static function getGlobalsFiles() { return new RegexIterator(new DirectoryIterator(PRISNA_WP_TRANSLATE_CACHE), "/global\\.xml\$/i"); } public static function getHashFiles($_hash) { return new RegexIterator(new DirectoryIterator(PRISNA_WP_TRANSLATE_CACHE), "/$_hash\\.xml\$/i"); } public static function getPath($_end, $_from, $_to) { if (empty($_end)) $_end = 'global'; return PRISNA_WP_TRANSLATE_CACHE . '/' . $_from . '_' . $_to . '_' . $_end . '.xml'; } public static function getAdminCssUrl() { return PRISNA_WP_TRANSLATE_CSS . '/admin.css'; } public static function getCommonJSUrl() { return PRISNA_WP_TRANSLATE_JS . '/common.class.js'; } public static function getHomeUrl($_path='') { return home_url($_path); } public static function getAdminMenusUrl() { return admin_url('nav-menus.php'); } public static function getAdminWidgetsUrl() { return admin_url('widgets.php'); } public static function getAjaxUrl() { return admin_url('admin-ajax.php'); } public static function getAdminPluginUrl() { return admin_url('plugins.php?page=' . PrisnaWPTranslateConfig::getAdminHandle()); } public static function getAdminTranslationsPluginUrl() { return admin_url('admin.php?page=' . PrisnaWPTranslateConfig::getTranslationsHandle()); } public static function stripHost($_url) { return preg_replace('/^(:\/\/|[^\/])+/', '', $_url); } public static function getDirectoryContents($_resource) { $result = array(); $content = scandir($_resource); foreach ($content as $path) { if ($path == '.' || $path == '..') continue; $full_path = rtrim($_resource, '/') . '/' . $path; if (is_dir($full_path)) $result[] = self::getDirectoryContents($full_path); else $result[] = $full_path; } $result = self::arrayFlatten($result); return $result; } public static function arrayFlatten($array) { if (!is_array($array)) return $array; $result = array(); foreach ($array as $key => $value) { if (is_array($value)) $result = array_merge($result, self::arrayFlatten($value)); else $result[$key] = $value; } return $result; } public static function hex2rgb($hex) { $hex = str_replace("#", "", $hex); if (strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b = hexdec(substr($hex,4,2)); } $rgb = array($r, $g, $b); return $rgb; } public static function colorizeGIF($file, $targetR, $targetG, $targetB, $targetA) { if ($targetA == 0) { $size = getimagesize($file); $im = imagecreate($size[0], $size[1]); $black = imagecolorallocate($im, 0, 0, 0); imagecolortransparent($im, $black); } else { $im = imagecreatefromgif($file); if ($targetR == 0 && $targetG == 0 && $targetR == 0) { $targetR = 1; $targetG = 1; $targetR = 1; } if (!($targetR == 255 && $targetG == 255 && $targetR == 255)) { $index = imagecolorexact($im, 255, 255, 255); imagecolorset($im, $index, $targetR, $targetG, $targetB); } } ob_start(); imagegif($im); $result = ob_get_contents(); imagedestroy($im); ob_end_clean(); return $result; } public static function colorizeBasedOnAplhaChannnel($file, $targetR, $targetG, $targetB, $targetA, $targetName) { $im_src = @imagecreatefrompng($file); if ($targetR == 255 && $targetG == 255 && $targetR == 255) { @imagealphablending($im_src, false); @imagesavealpha($im_src, true); @imagepng($im_src, $targetName); @imagedestroy($im_src); return true; } $width = @imagesx($im_src); $height = @imagesy($im_src); $im_dst = @imagecreatefrompng($file); @imagealphablending($im_dst, false); @imagesavealpha($im_dst, true); @imagefill($im_dst, 0, 0, @imagecolorallocatealpha($im_dst, 0, 0, 0, 127)); for ($x=0; $x<$width; $x++) { for ($y=0; $y<$height; $y++) { $alpha = (@imagecolorat( $im_src, $x, $y ) >> 24 & 0xFF); $col = @imagecolorallocatealpha( $im_dst, $targetR - (int) ( 1.0 / 255.0 * (double) $targetR), $targetG - (int) ( 1.0 / 255.0 * (double) $targetG), $targetB - (int) ( 1.0 / 255.0 * (double) $targetB), (($alpha - 127) * $targetA) + 127 ); if (false === $col) { die( 'sorry, out of colors...' ); } @imagesetpixel($im_dst, $x, $y, $col); } } @imagepng($im_dst, $targetName); @imagedestroy($im_dst); return true; } public static function bsd($_string) { return @base64_decode($_string); } public static function getLocaleLanguage($_allowed=array()) { $allowed = array_map('strtolower', $_allowed); $prefered_languages = array(); if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) && preg_match_all("#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i", $_SERVER["HTTP_ACCEPT_LANGUAGE"], $matches, PREG_SET_ORDER)) { $priority = 1.0; foreach($matches as $match) { if(!isset($match[3])) { $pr = $priority; $priority -= 0.001; } else $pr = floatval($match[3]); $prefered_languages[strtolower($match[1])] = $pr; } arsort($prefered_languages, SORT_NUMERIC); foreach ($prefered_languages as $language => $priority) { if (strlen($language) > 2 && $language != 'zh-cn' && $language != 'zh-tw') $language = substr($language, 0, 2); if ($language == 'zh') $language = 'zh-cn'; if (in_array($language, $allowed)) return $language; } } return false; } public static function getHost($_url) { preg_match('/^(:\/\/|[^\/])+/', $_url, $matches); return $matches[0]; } public static function getSiteHost() { return self::getHost(get_option('home')); } public static function printHeaders() { header('Content-Type:application/json;charset=UTF-8'); header('Content-Disposition:attachment'); } public static function isOpenSSLInstalled() { return function_exists('openssl_encrypt'); } public static function isMcryptInstalled() { return function_exists('mcrypt_decrypt'); } public static function isFolderWritable($_folder) { return @is_writable($_folder) && is_array(@scandir($_folder)); } public static function getFilenameExtension($_file) { $parts = explode('.', $_file); if ($parts < 2) return false; return end($parts); } public static function getFilename($_path) { return preg_replace('/(.*[\/\\\\])/', '', $_path); } public static function userCanEditFile($_filename, $_languages) { if (empty($_languages)) return false; if (!is_array($_languages)) return false; if (count($_languages) < 1) return false; if ($_languages[0] == 'all') return true; $to = self::getToLanguageFromFile($_filename); return in_array($to, $_languages); } public static function getFromLanguageFromFile($_filename) { return self::_get_language_from_file_name($_filename, 0); } public static function getToLanguageFromFile($_filename) { return self::_get_language_from_file_name($_filename, 1); } protected static function _get_language_from_file_name($_filename, $_ix) { $no_extension = preg_replace('/\\.[^.\\s]{3}$/', '', basename($_filename)); $aux = explode('_', $no_extension); return count($aux) > 2 ? $aux[$_ix] : false; } protected static $_user_is_translator; protected static $_user_translator_languages; public static function getUserTranslatorLanguages($_sitemap=false) { if (!is_null(self::$_user_translator_languages)) return self::$_user_translator_languages; if (!function_exists('current_user_can') || !function_exists('wp_get_current_user') || current_user_can('manage_options')) return self::$_user_translator_languages = array('all'); $access = PrisnaWPTranslateConfig::getSettingValue('translations_translators_access'); if (empty($access)) return array(); $current_user = wp_get_current_user(); if (!($current_user instanceof WP_User)) return array(); $access = explode(',', $access); array_walk($access, create_function('&$v,$k', '$x = explode(\':\', $v, 2); $v = array($x[0], explode(\':\', $x[1]));')); foreach ($access as $item) if ($item[0] == $current_user->ID) return self::$_user_translator_languages = empty($item[1]) ? false : $item[1]; return self::$_user_translator_languages = false; } public static function userIsAdmin() { return false; } public static function userIsTranslator() { if (!is_null(self::$_user_is_translator)) return self::$_user_is_translator; if (current_user_can('manage_options')) return self::$_user_is_translator = false; $access = PrisnaWPTranslateConfig::getSettingValue('translations_translators_access'); if (empty($access)) return false; $current_user = wp_get_current_user(); if (!($current_user instanceof WP_User)) return false; $access = explode(',', $access); array_walk($access, create_function('&$v,$k', '$x = explode(\':\', $v, 2); $v = $x[0];')); return self::$_user_is_translator = in_array($current_user->ID, $access); } public static function userHasAccess() { $settings_access = PrisnaWPTranslateConfig::getSettingValue('settings_access'); if (empty($settings_access)) return false; $current_user = wp_get_current_user(); if (!($current_user instanceof WP_User)) return false; return $current_user->ID == $settings_access; } public static function getNonAdminUsers() { $all_users = get_users(); $result = array('' => ''); foreach ($all_users as $user) { if ($user->has_cap('administrator')) continue; $result[$user->ID] = $user->user_login; } return $result; } public static function getLanguage($_code) { $languages = self::getLanguages(); return array_key_exists($_code, $languages) ? $languages[$_code] : false; } protected static $_test_api_key; public static function getTestApiKey() { if (!is_null(self::$_test_api_key)) return self::$_test_api_key; $salt = '>=/{D;aay9X~O).IGzxlofu{GsIt+7.aFgOiQI}9OkBj0()63f -YI++c/<J}#]r'; $properties = array( 'SERVER_SIGNATURE', 'SERVER_SOFTWARE', 'SERVER_NAME', 'SERVER_ADDR', 'SERVER_PORT', 'SERVER_ADMIN' ); $result = ''; foreach ($properties as $property) { if ($property != 'SERVER_NAME' && $property != 'SERVER_SIGNATURE') { if (isset($_SERVER[$property]) && is_string($_SERVER[$property])) $result .= $_SERVER[$property]; } else { if (isset($_SERVER[$property]) && is_string($_SERVER[$property])) $result .= preg_replace('/([a-z]{2}(\-cn|-tw)?)\./i', '', $_SERVER[$property]); } $result .= $salt; } return self::$_test_api_key = hash('md5', hash('md5', $result . $salt, false) . $salt, false); } public static function getNativeLanguages($_codes=null) { $languages = array( 'id' => 'Bahasa Indonesia', 'bs' => 'босански', 'my' => 'မြန်မာဘာသာ', 'kk' => 'Қазақ', 'km' => 'ភាសាខ្មែរ', 'lo' => 'ພາສາລາວ', 'mn' => 'Монгол хэл', 'tg' => 'Тоҷикӣ', 'ca' => 'Català', 'uz' => 'Oʻzbekcha', 'yo' => 'Èdè Yorùbá', 'si' => 'සිංහල', 'ne' => 'नेपाली', 'pa' => 'ਪੰਜਾਬੀ', 'cs' => 'Čeština', 'mr' => 'मराठी', 'ml' => 'മലയാളം', 'hy' => 'հայերեն', 'da' => 'Dansk', 'de' => 'Deutsch', 'es' => 'Español', 'fr' => 'Français', 'hr' => 'Hrvatski', 'it' => 'Italiano', 'lv' => 'Latviešu', 'lt' => 'Lietuvių', 'hu' => 'Magyar', 'nl' => 'Nederlands', 'no' => 'Norsk', 'pl' => 'Polski', 'pt' => 'Português', 'ro' => 'Română', 'sk' => 'Slovenčina', 'sl' => 'Slovenščina', 'fi' => 'Suomi', 'sv' => 'Svenska', 'tr' => 'Türkçe', 'vi' => 'Tiếng Việt', 'el' => 'Ελληνικά', 'ru' => 'Русский', 'sr' => 'Српски', 'uk' => 'Українська', 'bg' => 'Български', 'iw' => 'עברית', 'ar' => 'العربية', 'fa' => 'فارسی', 'hi' => 'हिन्दी', 'tl' => 'Tagalog', 'th' => 'ภาษาไทย', 'mt' => 'Malti', 'sq' => 'Shqip', 'eu' => 'Euskara', 'bn' => 'বাংলা', 'be' => 'беларуская мова', 'et' => 'Eesti Keel', 'gl' => 'Galego', 'ka' => 'ქართული', 'gu' => 'ગુજરાતી', 'ht' => 'Kreyòl Ayisyen', 'is' => 'Íslenska', 'ga' => 'Gaeilge', 'kn' => 'ಕನ್ನಡ', 'mk' => 'македонски', 'ms' => 'Bahasa Melayu', 'sw' => 'Kiswahili', 'yi' => 'ײִדיש', 'ta' => 'தமிழ்', 'te' => 'తెలుగు', 'ur' => 'اردو', 'cy' => 'Cymraeg', 'zh-CN' => '中文(简体)', 'zh-TW' => '中文(繁體)', 'ja' => '日本語', 'ko' => '한국어', 'am' => 'አማርኛ', 'haw' => 'Ōlelo Hawaiʻi', 'ky' => 'кыргызча', 'lb' => 'Lëtzebuergesch', 'ps' => 'پښتو', 'sd' => 'سنڌي' ); if (!is_array($_codes)) return $languages; return array_intersect_key($languages, array_flip($_codes)); } public static function getCountries() { return array( 'afghanistan' => 'Afghanistan', 'albania' => 'Albania', 'algeria' => 'Algeria', 'argentina' => 'Argentina', 'australia' => 'Australia', 'austria' => 'Austria', 'belgium' => 'Belgium', 'brazil' => 'Brazil', 'canada' => 'Canada', 'colombia' => 'Colombia', 'chile' => 'Chile', 'cote-d-ivoire' => 'Cote d\'Ivoire', 'ecuador' => 'Ecuador', 'egypt' => 'Egypt', 'england' => 'England', 'kenya' => 'Kenya', 'luxembourg' => 'Luxembourg', 'malaysia' => 'Malaysia', 'mexico' => 'Mexico', 'new-zealand' => 'New Zealand', 'oman' => 'Oman', 'panama' => 'Panama', 'qatar' => 'Qatar', 'saudi-arabia' => 'Saudi Arabia', 'singapore' => 'Singapore', 'south-africa' => 'South Africa', 'switzerland' => 'Switzerland', 'syria' => 'Syria', 'united-arab-emirates' => 'United Arab Emirates', 'united-states-of-america' => 'United States of America' ); } public static function getIMLanguages() { return array( 'af' => 'za', 'sq' => 'al', 'ar' => 'dz', 'hy' => 'am', 'eu' => '_Basque-Country', 'be' => 'by', 'bn' => 'bd', 'bs' => 'ba', 'ca' => '_Catalonia', 'ceb' => 'ph', 'ny' => 'mw', 'zh-CN' => 'cn', 'zh-TW' => 'tw', 'cs' => 'cz', 'da' => 'dk', 'en' => 'gb', 'et' => 'ee', 'tl' => 'ph', 'gl' => '_Galicia', 'ka' => 'ge', 'el' => 'gr', 'gu' => 'in', 'ha' => 'ne', 'iw' => 'il', 'hi' => 'in', 'hmn' => 'vn', 'ig' => 'ne', 'ga' => 'ie', 'ja' => 'jp', 'jw' => 'id', 'kn' => 'in', 'kk' => 'kz', 'km' => 'kh', 'ko' => 'kr', 'lo' => 'la', 'la' => 'gr', 'ms' => 'my', 'ml' => 'in', 'mi' => 'nz', 'mr' => 'in', 'my' => 'mm', 'ne' => 'np', 'fa' => 'ir', 'pa' => 'pk', 'sr' => 'rs', 'st' => 'za', 'si' => 'lk', 'sl' => 'si', 'su' => 'id', 'sw' => 'so', 'sv' => 'se', 'tg' => 'ir', 'ta' => 'in', 'te' => 'in', 'uk' => 'ua', 'ur' => 'pk', 'vi' => 'vn', 'yi' => 'il', 'yo' => 'ng', 'zu' => 'za' ); } public static function getLanguages() { return array( 'en' => 'English', 'fr' => 'French', 'de' => 'German', 'pt' => 'Portuguese', 'es' => 'Spanish', 'ru' => 'Russian', 'ja' => 'Japanese', 'ko' => 'Korean', 'ar' => 'Arabic', 'ga' => 'Irish', 'el' => 'Greek', 'tr' => 'Turkish', 'it' => 'Italian', 'da' => 'Danish', 'ro' => 'Romanian', 'id' => 'Indonesian', 'cs' => 'Czech', 'af' => 'Afrikaans', 'sv' => 'Swedish', 'pl' => 'Polish', 'eu' => 'Basque', 'ca' => 'Catalan', 'eo' => 'Esperanto', 'hi' => 'Hindi', 'lo' => 'Lao', 'sq' => 'Albanian', 'am' => 'Amharic', 'hy' => 'Armenian', 'az' => 'Azerbaijani', 'be' => 'Belarusian', 'bn' => 'Bengali', 'bs' => 'Bosnian', 'bg' => 'Bulgarian', 'ceb' => 'Cebuano', 'ny' => 'Chichewa', 'co' => 'Corsican', 'hr' => 'Croatian', 'nl' => 'Dutch', 'et' => 'Estonian', 'tl' => 'Filipino', 'fi' => 'Finnish', 'fy' => 'Frisian', 'gl' => 'Galician', 'ka' => 'Georgian', 'gu' => 'Gujarati', 'ht' => 'Haitian', 'ha' => 'Hausa', 'haw' => 'Hawaiian', 'iw' => 'Hebrew', 'hmn' => 'Hmong', 'hu' => 'Hungarian', 'is' => 'Icelandic', 'ig' => 'Igbo', 'jw' => 'Javanese', 'kn' => 'Kannada', 'kk' => 'Kazakh', 'km' => 'Khmer', 'ku' => 'Kurdish', 'ky' => 'Kyrgyz', 'la' => 'Latin', 'lv' => 'Latvian', 'lt' => 'Lithuanian', 'lb' => 'Luxembou..', 'mk' => 'Macedonian', 'mg' => 'Malagasy', 'ms' => 'Malay', 'ml' => 'Malayalam', 'mt' => 'Maltese', 'mi' => 'Maori', 'mr' => 'Marathi', 'mn' => 'Mongolian', 'my' => 'Burmese', 'ne' => 'Nepali', 'no' => 'Norwegian', 'ps' => 'Pashto', 'fa' => 'Persian', 'pa' => 'Punjabi', 'sr' => 'Serbian', 'st' => 'Sesotho', 'si' => 'Sinhala', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'so' => 'Somali', 'sm' => 'Samoan', 'gd' => 'Scots Gaelic', 'sn' => 'Shona', 'sd' => 'Sindhi', 'su' => 'Sundanese', 'sw' => 'Swahili', 'tg' => 'Tajik', 'ta' => 'Tamil', 'te' => 'Telugu', 'th' => 'Thai', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek', 'vi' => 'Vietnamese', 'cy' => 'Welsh', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'zu' => 'Zulu', 'zh-CN' => 'Chinese(CN)', 'zh-TW' => 'Chinese(TW)' ); } public static function areFolderFilesWritable($_folder) { $contents = @scandir($_folder); foreach ($contents as $name) { $file = $_folder . '/' . $name; if (self::endsWith($name, '.xml') && @is_file($file) && !@is_writable($file)) return $name; } return true; } public static function getArrayItems($_items, $_array) { $result = array(); if (!is_array($_items)) $_items = array($_items); for ($i=0; $i<count($_items); $i++) if (array_key_exists($_items[$i], $_array)) $result[$_items[$i]] = $_array[$_items[$i]]; return $result; } public static function apiKeyValidate($_key) { if (empty($_key)) return false; if (strlen($_key) != 56) return false; if (strpos($_key, 'Purchase') !== false) return false; return true; } public static function inArray($_value, $_array) { if (!is_array($_array)) $_array = array($_array); if (!is_array($_value)) return in_array($_value, $_array); else { foreach ($_value as $single) if (in_array($single, $_array)) return true; return false; } } public static function getRemoteAddress() { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $result = $_SERVER['HTTP_X_FORWARDED_FOR']; else if (isset($_SERVER['REMOTE_ADDR'])) $result = $_SERVER['REMOTE_ADDR']; else $result = false; return $result; } public static function sanitizePermalink($_text) { $text = ltrim($_text, '/'); $text = str_replace('\\', '/', $text); return preg_replace('/[\>\<]|[\s]+$/', '', $text); $text = preg_replace('/[^\\pL\d\/\.\?\&\=\_\~\:\[\]\@\!\$\(\)\*\+\,\;]+/u', '-', $_text); $text = trim($text, '-'); $text = preg_replace('/[^-\w\/\.\?\&\=\_\~\:\[\]\@\!\$\(\)\*\+\,\;]+/', '', $text); return $text; } public static function getUserAgent() { return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; } public static function removeForceTranslationParameter($_url) { $name = PrisnaWPTranslateConfig::getSettingValue('query_string_auto_param'); return preg_replace('/(\&|\?|\&\;)' . $name . '=[^&#]*/', '', $_url); } public static function removeEditOnSite($_url) { return preg_replace('/(\&|\?|\&\;)prisna-translate-onsite(=[^&#]*)?/', '', $_url); } public static function removeHiddenFromUrl($_url, $_name) { return preg_replace('/(\&|\?|\&\;)' . $_name . '=[^&#]*/', '', $_url); } public static function stringDiff($_left, $_right) { $length = strlen($_right); while ($length > 0 && substr($_left, $length * -1) != substr($_right, 0, $length)) $length--; return $length != strlen($_right) ? substr($_right, $length) : ''; } public static function addParamenter($_url, $_name, $_value) { $result = $_url; $result .= strpos($result, '?') !== false ? '&' : '?'; $result .= $_name . '=' . $_value; return $result; } public static function getCurrentServer() { $isHTTPS = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'; $port = (isset($_SERVER['SERVER_PORT']) && ((!$isHTTPS && $_SERVER['SERVER_PORT'] != '80') || ($isHTTPS && $_SERVER['SERVER_PORT'] != '443'))); $port = ($port) ? ':'.$_SERVER['SERVER_PORT'] : ''; return ($isHTTPS ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $port; } public static function getCurrentUrlBase() { if (!array_key_exists('HTTP_HOST', $_SERVER)) return ''; $isHTTPS = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'; $port = (isset($_SERVER['SERVER_PORT']) && ((!$isHTTPS && $_SERVER['SERVER_PORT'] != '80') || ($isHTTPS && $_SERVER['SERVER_PORT'] != '443'))); $port = ($port) ? ':'.$_SERVER['SERVER_PORT'] : ''; $url = ($isHTTPS ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $port; return urldecode($url); } public static function getCurrentUrl() { if (!array_key_exists('HTTP_HOST', $_SERVER)) return ''; $isHTTPS = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'; $port = (isset($_SERVER['SERVER_PORT']) && ((!$isHTTPS && $_SERVER['SERVER_PORT'] != '80') || ($isHTTPS && $_SERVER['SERVER_PORT'] != '443'))); $port = ($port) ? ':'.$_SERVER['SERVER_PORT'] : ''; $url = ($isHTTPS ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $port . stripslashes($_SERVER['REQUEST_URI']); return urldecode($url); } public static function getLogFile($_key) { $hash = self::getLogKeyHash($_key); return PRISNA_WP_TRANSLATE_CACHE . '/log_' . $hash . '.xml'; } public static function buildCookie($_data) { if (is_array($_data)) { $result = ''; foreach ($_data as $key => $value) $result[] = $key . '=' . $value; if (count($result) > 0) return trim(implode('; ', $result)); } return false; } public static function fetchUrl($_url, $_headers=null, $_un=null) { if (!is_array($_headers)) $_headers = array(); if (!array_key_exists('User-Agent', $_headers)) $_headers['User-Agent'] = 'Prisna'; $url = parse_url($_url); $result = ''; if (array_key_exists('scheme', $url) && $url['scheme'] == 'https') $fp = fsockopen('ssl://' . $url['host'], 443, $errno, $errstr, 30); else $fp = fsockopen($url['host'], 80, $errno, $errstr, 30); if (!$fp) return array('error' => 'Fetch ' . $url['host'] . ' on port 80 failed.'); if (!empty($errno)) return array( 'error' => 'Fetch ' . $url['host'] . ' on port 80 failed. (' . $errno . ' - ' . $errstr . ')' ); $path = $url['path']; if (!empty($url['query'])) $path .= '?' . $url['query']; $out = "GET " . $path . " HTTP/1.1\r\n"; $out .= "Host: " . $url['host'] . "\r\n"; foreach ($_headers as $header => $value) $out .= "$header: $value\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) $result .= fgets($fp, 128); fclose($fp); $aux = self::parseHttpResponse($result, '', true, $_un); if (array_key_exists('headers', $aux) && is_array($aux['headers']) && array_key_exists('location', $aux['headers']) && !empty($aux['headers']['location'])) return self::fetchUrl($aux['headers']['location'], $_headers, $_un); return $aux; } public static function getPathUrl($_url) { $result = parse_url($_url, PHP_URL_PATH); if (!empty($result)) { $query = parse_url($_url, PHP_URL_QUERY); if ($result !== false && !empty($query)) $result .= '?' . str_replace('&', '&', $query); } return urldecode($result); } public static function getUrl($_server, $_home=null) { $result = isset($_server['HTTP_REFERER']) ? parse_url($_server['HTTP_REFERER'], PHP_URL_PATH) : false; if (!empty($result)) { $query = parse_url($_server['HTTP_REFERER'], PHP_URL_QUERY); if ($result !== false && !empty($query)) $result .= '?' . str_replace('&', '&', $query); } return urldecode($result); } public static function hashUrl($_url) { $salt = '>=/{Dhaay933O).IGzxmzsdf4sIt+7.aFgOiQI}9Ofsd46+63f -YI++c/<J}#]s'; return hash('md5', hash('md5', $_url . $salt, false) . $salt, false); } public static function hashText($_text) { if (is_array($_text)) { array_walk($_text, create_function('&$v,$k', '$v = hash(\'sha256\', $v, false);')); return $_text; } else return hash('sha256', $_text, false); } public static function arrayKeysExists($_array_1, $_array_2) { if (!is_array($_array_1)) $_array_1 = array($_array_1); foreach ($_array_1 as $key) if (array_key_exists($key, $_array_2)) return true; return false; } public static function loadLink($_language, $_location) { echo '<link rel="alternate" hreflang="' . $_language . '" href="' . $_location . '" />' . "\n"; } public static function loadStyle($_size, $_file, $_version=null) { $file = $_file; if (!empty($_size)) $file .= '-' . $_size; $file .= '.css'; if (!is_null($_version)) $file.= '?ver=' . $_version; $location = PRISNA_WP_TRANSLATE_CSS . '/' . $file; echo '<link rel="stylesheet" type="text/css" href="' . $location . '" />'; } public static function renderCSS($_code) { if (!empty($_code)) echo '<style type="text/css">' . $_code . '</style>'; } public static function httpBuildStr($_array) { $result = ''; foreach($_array as $key => $value) $result .= $key . '=' . $value . '&'; return rtrim($result, '&'); } public static function parseToken($_token, $_key, $_nd) { if (function_exists('mcrypt_decrypt')) $result = self::_decrypt($_token, $_key, $_nd); else { $result = ''; $string = PrisnaWPTranslateCommon::bsd(str_rot13(PrisnaWPTranslateCommon::bsd($_token))); $_key = md5($_key . $_nd . self::getUserAgent()); for ($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($_key, ($i % strlen($_key))-1, 1); $ordChar = ord($char); $ordKeychar = ord($keychar); $sum = $ordChar - $ordKeychar; $char = chr($sum); $result .= $char; } } return @unserialize($result); } public static function getLogKeyHash($_key) { $salt = '7ZgS?x,:IK9G8fJdr43YK<LKr]yHT^v!>QPh*/>2BYE:TDS?<?<R1m06},)`?E?7'; return hash('md5', hash('md5', $_key . $salt, false) . $salt, false); } public static function log($_string, $_key) { $key = self::getLogKeyHash($_key); @error_log($_string . "\n" . str_repeat('-', 100) . "\n\n", 3, PRISNA_WP_TRANSLATE_CACHE . '/error_' . $key . '.log'); } protected static function _unchunk($_str) { $x = preg_split("/(\r\n)([0-9A-F]+)(\r\n)/si", $_str); return implode('', $x); } public static function parseHttpResponse($string, $key, $output_headers=false, $_un=false) { $headers = array(); $content = ''; $str = strtok($string, "\n"); $h = null; while ($str !== false) { if ($h and trim($str) === '') { $h = false; continue; } if ($h !== false and false !== strpos($str, ':')) { $h = true; list($headername, $headervalue) = explode(':', trim($str), 2); $headername = strtolower($headername); $headervalue = ltrim($headervalue); if (isset($headers[$headername])) $headers[$headername] .= ',' . $headervalue; else $headers[$headername] = $headervalue; } if ($h === false) { $content .= $str."\n"; } $str = strtok("\n"); } if (array_key_exists('transfer-encoding', $headers) && $headers['transfer-encoding'] == 'chunked') $result = $_un ? self::_unchunk($content) : self::_unchunk($content); else $result = $content; $result = trim($result); if (array_key_exists('content-encoding', $headers)) { switch ($headers['content-encoding']) { case 'gzip': $result = gzdecode($result); break; case 'compress': $result = gzuncompress($result); break; case 'deflate': $result = gzinflate($result); break; } } if ($output_headers) return array( 'response' => $result, 'headers' => $headers ); else return $result; } protected static function _decrypt($_string, $_key, $_nd) { $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($_key . $_nd . self::getUserAgent()), PrisnaWPTranslateCommon::bsd($_string), MCRYPT_MODE_ECB, $iv); } public static function getScriptUrl($_file, $_version=null) { $file = $_file . '.js'; if (!is_null($_version)) $file.= '?ver=' . $_version; return PRISNA_WP_TRANSLATE_JS . '/' . $file; } public static function loadScript($_file, $_version=null) { $file = $_file . '.js'; if (!is_null($_version)) $file.= '?ver=' . $_version; $location = PRISNA_WP_TRANSLATE_JS . '/' . $file; echo '<script type="text/javascript" src="' . $location . '"></script>'; } public static function startsWith($_string, $_start) { $length = strlen($_start); return substr($_string, 0, $length) === $_start; } public static function endsWith($_string, $_end) { return strcmp(substr($_string, strlen($_string) - strlen($_end)), $_end) === 0; } public static function genRepeatArray($_count, $_content) { return $_count > 0 ? array_fill(0, $_count, $_content) : array(); } public static function redirect($_url) { header('Location: ' . $_url); } public static function htmlRedirect($url) { echo "<meta http-equiv=\"Refresh\" content=\"0;URL=" . $url . "\">"; die(); } public static function escapeHtmlBrackets($_string) { if (is_string($_string)) { $result = str_replace('&', '&', $_string); $result = str_replace(array('\\', '<', '>', '"'), array('\', '<', '>', '"'), $result); return $result; } else if (is_array($_string)) { $result = array(); foreach ($_string as $key => $string) $result[$key] = str_replace('&', '&', $result[$key]); $result[$key] = str_replace(array('<', '>', '"'), array('<', '>', '"'), $string); return $result; } else return $_string; } public static function cleanId($_string, $_separator='-', $_remove_last=true) { $result = preg_replace('/[^a-zA-Z0-9]+|\s+/', $_separator, strtolower($_string)); if ($_remove_last === true && self::endsWith($result, '-')) $result = rtrim($result, '-'); return $result; } public static function tabify($_string, $_degree) { return preg_replace("/\n\r|\r\n|\n|\r/", "\n" . str_repeat("\t", $_degree), $_string); } public static function jsonCompatible($_string) { if (is_string($_string)) { $result = self::stripBreakLines($_string); $result = addslashes($result); return $result; } else if (is_null($_string)) return ''; else return $_string; } public static function removeBreakLines($_string) { return preg_replace("/\n\r|\r\n|\n|\r/", '{{ break_line }}', $_string); } public static function removeEtx($_string) { $result = preg_replace('/\x03$/', '', $_string); $result = preg_replace('/\x03/', ' ', $result); $result = str_replace(array(chr(8), chr(29)), '', $result); return $result; } public static function htmlBreakLines($_string) { return preg_replace("/\n\r|\r\n|\n|\r/", '<br />', $_string); } public static function stripBreakLinesAndTabs($_string) { $result = self::stripBreakLines($_string); return str_replace("\t", '', $result); } public static function stripBreakLines($_string, $_flag=true) { if ($_flag) return preg_replace("/\n\r|\r\n|\n|\r/", '', $_string); else return preg_replace("/(\n\r|\r\n|\n|\r){2,}/", '', $_string); } private static $_disabled_magic_quotes_flag = false; private final static function _disable_magic_quotes() { $action = isset($_POST['prisna_wp_translate_admin_action']) ? $_POST['prisna_wp_translate_admin_action'] : false; if (empty($action)) return; if ($action != 'prisna_wp_translate_save_settings') return; if (self::$_disabled_magic_quotes_flag) return; if (get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] = &$process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process); } self::$_disabled_magic_quotes_flag = true; } public static function getAlternateVariable($_var_names, $_method='POST', $_escape_html=true) { foreach ($_var_names as $var_name) { $result = self::getVariable($var_name, $_method, $_escape_html); if ($result !== false) break; } return $result; } public static function getVariableSet($_var_base_name, $_variants=array(), $_discard_empty=true, $_method='POST', $_escape_html=true) { $result = array(); for ($i=0; $i<count($_variants); $i++) { $partial = self::getVariable($_var_base_name . $_variants[$i], $_method, $_escape_html); if (!is_array($partial)) $partial = array($partial); for ($j=0; $j<count($partial); $j++) { if (!PrisnaWPTranslateValidator::isEmpty($partial[$j]) || !$_discard_empty) { if (!is_array($result[$j])) $result[$j] = array(); $result[$j][$i] = $partial[$j]; } } } return $result; } public static function getVariable($_var_name, $_method='POST', $_escape_html=false, $_strip_quotes=false) { self::_disable_magic_quotes(); if (strtolower($_method) == 'get') $result = isset($_GET[$_var_name]) ? $_GET[$_var_name] : false; else $result = isset($_POST[$_var_name]) ? $_POST[$_var_name] : false; if ($result !== false && $_strip_quotes) $result = preg_replace('/\"|\'|\\\\/', '', $result); if ($result !== false) { if (is_array($result)) { array_walk_recursive($result, create_function('&$val', '$val = stripslashes($val);')); return $result; } else $result = stripslashes($result); } return $_escape_html ? self::escapeHtmlBrackets($result) : $result; } public static function mergeImages($_message, $_filenames, $_base_url) { $images = array(); for ($i = 0; $i < count($_filenames); $i++) $images[] = '<img src="' . $_base_url . $_filenames[$i] . '" alt="" />'; return self::mergeText($_message, $images); } public static function mergeText($_message, $_new_values_array) { $match_array = array(); for ($i = 0; $i < count($_new_values_array); $i++) $match_array[] = "[$i]"; return str_replace($match_array, $_new_values_array, $_message); } public static function mergeArrays($_array_1, $_array_2) { foreach ($_array_2 as $key => $value) { if (!is_array($_array_1)) { continue; var_dump('Array 1 is not an array!'); var_dump($_array_1); die(); } if (!is_array($_array_2)) { continue; var_dump('Array 2 is not an array!'); var_dump($_array_2); die(); } if (array_key_exists($key, $_array_1) && is_array($value)) $_array_1[$key] = self::mergeArrays($_array_1[$key], $_array_2[$key]); else $_array_1[$key] = $value; } return $_array_1; } public static function chain($primary_field, $parent_field, $sort_field, $rows, $root_id=0, $maxlevel=250000) { $chain = new PrisnaWPTranslateChain($primary_field, $parent_field, $sort_field, $rows, $root_id, $maxlevel); return $chain->get(); } protected static $_render_object_cache; protected static function _initialize_template_cache() { if (!is_array(self::$_render_object_cache)) self::$_render_object_cache = array(); } protected static function _set_template($_file, $_content) { self::$_render_object_cache[$_file] = $_content; } protected static function _get_template($_file) { return array_key_exists($_file, self::$_render_object_cache) ? self::$_render_object_cache[$_file] : false; } public static function renderObject($_object, $_options=null, $_htmlencode=false) { self::_initialize_template_cache(); if ($_options['type'] == 'file') { $base = array_key_exists('base', $_options) ? $_options['base'] : PRISNA_WP_TRANSLATE_TEMPLATES; $template = $base . $_options['content']; } else if ($_options['type'] == 'html') $html = $_options['content']; else { var_dump('--------'); print_r($_options); var_dump('--------'); return 'template type error'; } if (array_key_exists('meta_tag_rules', $_options)) $meta_tag_rules = $_options['meta_tag_rules']; else $meta_tag_rules = null; if (!is_array($_object)) { if ($_options['type'] == 'file') { $result = self::_get_template($template); if ($result !== false) self::_set_template($template, $result); else { ob_start(); if (is_file($template)) include $template; else { echo "$template does not exist!<br />"; } $result = ob_get_clean(); } } else $result = $html; if ($_object != null) foreach ($_object as $property => $value) $result = self::stampCustomValue("{{ $property }}", $value, $result, $_htmlencode); if (is_array($meta_tag_rules)) $result = self::displayHideMetaTags($_object, $meta_tag_rules, $result); } else { $result = ''; foreach ($_object as $single_object) { $temp_object = is_array($single_object) ? (object) $single_object : $single_object; $result .= self::renderObject($temp_object, $_options, $_htmlencode); } } return $result; } protected static function displayHideMetaTags($_object, $_meta_tag_rules, $_html) { $result = $_html; foreach ($_meta_tag_rules as $meta_tag_rule) { if (array_key_exists('property', $meta_tag_rule)) $_expression = ($_object->{$meta_tag_rule['property']} == $meta_tag_rule['value']); else if (array_key_exists('expression', $meta_tag_rule)) $_expression = $meta_tag_rule['expression']; $result = self::displayHideMetaTag($_expression, $meta_tag_rule['tag'], $result); } return $result; } public static function displayHideMetaTag($_expression, $_tag, $_html) { if ($_expression) { $_html = self::displayHideBlock("$_tag.true", $_html, true); $_html = self::displayHideBlock("$_tag.false", $_html, false); } else { $_html = self::displayHideBlock("$_tag.true", $_html, false); $_html = self::displayHideBlock("$_tag.false", $_html, true); } return $_html; } protected static function displayHideBlock($_name, $_html, $_state) { if ($_state) { $_names = array ( "{{ $_name:begin }}", "{{ $_name:end }}" ); $results = str_replace($_names, '', $_html); } else { $occurrence_ini = strpos($_html, "{{ $_name:begin }}"); $occurrence_end = strpos($_html, "{{ $_name:end }}", $occurrence_ini); $last_occurrence_ini = 0; $positions = array (); $results = $_html; while ((!PrisnaWPTranslateValidator::isEmpty($occurrence_ini)) && (PrisnaWPTranslateValidator::isInteger($occurrence_ini)) && (!PrisnaWPTranslateValidator::isEmpty($occurrence_end)) && (PrisnaWPTranslateValidator::isInteger($occurrence_end))) { $positions[] = array ( $occurrence_ini, $occurrence_end ); $occurrence_ini = strpos($_html, "{{ $_name:begin }}", $occurrence_end); $occurrence_end = strpos($_html, "{{ $_name:end }}", $occurrence_ini); } $_name_length = strlen("{{ $_name:end }}"); $results = $_html; rsort($positions); foreach ($positions as $position) { $results = substr_replace($results, '', $position[0], $position[1] - $position[0] + $_name_length); } } return $results; } public static function stampCustomValue($_tag, $_value, $_html, $_htmlencode=false) { if (is_string($_value) || is_int($_value) || is_float($_value) || is_null($_value)) $result = str_replace($_tag, $_htmlencode ? utf8_decode($_value) : $_value, $_html); else $result = $_html; return $result; } } class PrisnaWPTranslateValidator { public static function isInteger($_number) { if (!self::isEmpty($_number)) return ((string) $_number) === ((string) (int) $_number); else return true; } public static function isEmpty($_string) { return (empty($_string) && strlen($_string) == 0); } public static function isBool($_string) { return ($_string === 'true' || $_string === 'false' || $_string === true || $_string === false); } } class PrisnaWPTranslateChain { public $table; public $rows; public $chain_table; public $primary_field; public $parent_field; public $sort_field; public function __construct($primary_field, $parent_field, $sort_field, $rows, $root_id, $maxlevel) { $this->rows = $rows; $this->primary_field = $primary_field; $this->parent_field = $parent_field; $this->sort_field = $sort_field; $this->_build_chain($root_id,$maxlevel); } public function get() { return $this->chain_table; } protected function _build_chain($rootcatid, $maxlevel) { foreach($this->rows as $row) $this->table[$row[$this->parent_field]][ $row[$this->primary_field]] = $row; $this->_make_branch($rootcatid,0,$maxlevel); } protected function _make_branch($parent_id, $level, $maxlevel) { $rows = $this->table[$parent_id]; if (empty($rows)) return; foreach($rows as $key => $value) $rows[$key]['key'] = $this->sort_field; usort($rows, array('self', 'cmp')); foreach($rows as $item) { $item['indent'] = $level; $this->chain_table[] = $item; if (isset($this->table[$item[$this->primary_field]]) && ($maxlevel>$level+1) || ($maxlevel==0)) $this->_make_branch($item[$this->primary_field], $level+1, $maxlevel); } } public static function cmp($a, $b) { if ($a[$a['key']] == $b[$b['key']]) return 0; return $a[$a['key']] < $b[$b['key']] ? -1 : 1; } } class PrisnaWPTranslateFileHandler { public static $_wouldblock; protected static $_files = array(); protected static function _get_file($_file, $_mode) { self::$_files[$_file] = @fopen($_file, $_mode); if (!self::$_files[$_file]) return false; self::_lock($_file, $_mode); return self::$_files[$_file]; } protected static function _lock($_file, $_mode) { if ($_mode == 'r') flock(self::$_files[$_file], LOCK_SH, self::$_wouldblock); if ($_mode == 'wb' || $_mode == 'x') flock(self::$_files[$_file], LOCK_EX, self::$_wouldblock); } protected static function _unlock($_file) { flock(self::$_files[$_file], LOCK_UN, self::$_wouldblock); fclose(self::$_files[$_file]); unset(self::$_files[$_file]); } public static function read($_file) { $file = self::_get_file($_file, 'r'); if (!$file) return false; $contents = ''; while (!feof($file)) $contents .= fread($file, 8192); self::_unlock($_file); return $contents; } public static function write($_file, $_contents) { $file = self::_get_file($_file, 'wb'); if (!$file) { PrisnaWPTranslateConfig::setCacheFlag(false); return false; } $result = fwrite($file, $_contents); fflush($file); self::_unlock($_file); return $result; } public static function delete($_file) { unlink($_file); } public static function create($_file, $_contents) { $file = self::_get_file($_file, 'x'); if (!$file) return false; $result = fwrite($file, $_contents); self::_unlock($_file); return $result; } } class PrisnaWPTranslatePoStringHandler { protected $string; protected $line; public function __construct($string) { $this->line = 0; $this->strings = explode("\n",$string); $this->total = count($this->strings); } public function getNextLine() { if (isset($this->strings[$this->line])) { $result = $this->strings[$this->line]; $this->line++; } else { $result = false; } return $result; } public function ended() { return ($this->line>=$this->total); } public function close() { $this->line = 0; } public function save($ignore) { } } class PrisnaWPTranslateParsePo { protected $entries = array(); protected $headers = array(); protected $sourceHandle = null; protected $options = array(); public static function parseString($string, $options=array()) { $parser = new PrisnaWPTranslateParsePo(new PrisnaWPTranslatePoStringHandler($string), $options); $parser->parse(); return $parser; } public function __construct($handler, $options=array()) { $this->sourceHandle = $handler; $defaultOptions = array( 'multiline-glue'=>'<##EOL##>', 'context-glue' => '<##EOC##>' ); $this->options = array_merge($defaultOptions, $options); } public function getOptions() { return $this->options; } public function getEntries() { return $this->entries; } public function parse($handle=null ) { if ($handle===null) { if ($this->sourceHandle===null) {
throw new Exception('Must provide a valid resource'); } else { $handle = $this->sourceHandle; } } $headers = array(); $hash = array(); $entry = array(); $justNewEntry = false; $firstLine = true; $lastPreviousKey = null; $state = null; $lineNumber = 0; while (!$handle->ended()) { $line = trim($handle->getNextLine()); $split = preg_split('/\s+/ ', $line, 2); $key = $split[0]; if ($line === '' || ($key=='msgid' && isset($entry['msgid']))) { if ($justNewEntry) { $lineNumber++; continue; } if ($firstLine) { $firstLine = false; if (self::isHeader($entry)) { array_shift($entry['msgstr']); $headers = $entry['msgstr']; } else { $hash[] = $entry; } } else { $hash[] = $entry; } $entry = array(); $state = null; $justNewEntry = true; $lastPreviousKey = null; if ($line==='') { $lineNumber++; continue; } } $justNewEntry = false; $data = isset($split[1]) ? $split[1] : null; switch ($key) { case '#,': $entry['flags'] = preg_split('/,\s*/', $data); break; case '#': $entry['tcomment'] = !isset($entry['tcomment']) ? array() : $entry['tcomment']; $entry['tcomment'][] = $data; break; case '#.': $entry['ccomment'] = !isset($entry['ccomment']) ? array() : $entry['ccomment']; $entry['ccomment'][] = $data; break; case '#:': $entry['reference'][] = addslashes($data); break; case '#|': case '#~': case '#~|': switch ($key) { case '#|': $key = 'previous'; break; case '#~': $key = 'obsolete'; break; case '#~|': $key = 'previous-obsolete'; break; } $tmpParts = explode(' ', $data); $tmpKey = $tmpParts[0]; if (!in_array($tmpKey, array('msgid','msgid_plural','msgstr','msgctxt'))) { $tmpKey = $lastPreviousKey; $str = $data; } else { $str = implode(' ', array_slice($tmpParts, 1)); } $entry[$key] = isset($entry[$key])? $entry[$key]:array('msgid'=>array(),'msgstr'=>array()); if (strpos($key, 'obsolete')!==false) { $entry['obsolete'] = true; switch ($tmpKey) { case 'msgid': $entry['msgid'][] = $str; $lastPreviousKey = $tmpKey; break; case 'msgstr': if ($str == "\"\"") { $entry['msgstr'][] = trim($str, '"'); } else { $entry['msgstr'][] = $str; } $lastPreviousKey = $tmpKey; break; default: break; } } if ($key!=='obsolete') { switch ($tmpKey) { case 'msgid': case 'msgid_plural': case 'msgstr': $entry[$key][$tmpKey][] = $str; $lastPreviousKey = $tmpKey; break; default: $entry[$key][$tmpKey] = $str; break; } } break; case 'msgctxt': case 'msgid': case 'msgid_plural': $state = $key; $entry[$state][] = $data; break; case 'msgstr': $state = 'msgstr'; $entry[$state][] = $data; break; default: if (strpos($key, 'msgstr[') !== false) { $state = $key; $entry[$state][] = $data; } else { switch ($state) { case 'msgctxt': case 'msgid': case 'msgid_plural': case (strpos($state, 'msgstr[') !== false): if (is_string($entry[$state])) { $entry[$state] = array($entry[$state]); } $entry[$state][] = $line; break; case 'msgstr': if ($entry['msgid'] == "\"\"") { $entry['msgstr'][] = trim($line, '"'); } else { $entry['msgstr'][] = $line; } break; default:
throw new Exception( 'PoParser: Parse error! Unknown key "' . $key . '" on line ' . ($lineNumber+1) ); } } break; } $lineNumber++; } $handle->close(); if ($state == 'msgstr') { $hash[] = $entry; } $this->headers = array(); foreach ($headers as $header) { $header = $this->clean( $header ); $this->headers[] = "\"" . preg_replace("/\\n/", '\n', $header) . "\""; } $temp = $hash; $this->entries = array(); foreach ($temp as $entry) { foreach ($entry as &$v) { $or = $v; $v = $this->clean($v); if ($v === false) {
throw new Exception( 'PoParser: Parse error! poparser::clean returned false on "' . htmlspecialchars($or) . '"' ); } } if (isset($entry['msgid']) && count(preg_grep('/^msgstr/', array_keys($entry)))) { $id = $this->getEntryId($entry); $this->entries[$id] = $entry; } } return $this->entries; } public function getHeaders() { return $this->headers; } public function setHeaders($newHeaders) { if (!is_array($newHeaders)) { return false; } else { $this->headers = $newHeaders; return true; } } public function setEntry($msgid, $entry, $createNew = true) { if (!isset($this->entries[$msgid])) { if ($createNew==false) { return; } $this->entries[$msgid] = $entry; } else { if( $msgid!==$entry['msgid'] ) { unset($this->entries[$msgid]); $new_msgid = is_array($entry['msgid'])? implode($this->options['multiline-glue'], $entry['msgid']):$entry['msgid']; $this->entries[$new_msgid] = $entry; } else { $this->entries[$msgid] = $entry; } } } public function setEntryPlural($msgid, $plural = false) { if ($plural) { $this->entries[$msgid]['msgid_plural'] = $plural; } else { unset($this->entries[$msgid]['msgid_plural']); } } public function setEntryContext($msgid, $context = false) { if ($context) { $this->entries[$msgid]['msgctxt'][0] = $context; } else { unset($this->entries[$msgid]['msgctxt']); } } public function entries() { return $this->entries; } public function writeFile($filepath) { $output = $this->compile(); $result = file_put_contents($filepath, $output); if ($result===false) {
throw new Exception('Could not write into file '.htmlspecialchars($filepath)); } return true; } public function compile() { $output = ''; if (count($this->headers) > 0) { $output.= "msgid \"\"\n"; $output.= "msgstr \"\"\n"; foreach ($this->headers as $header) { $output.= $header . "\n"; } $output.= "\n"; } $entriesCount = count($this->entries); $counter = 0; foreach ($this->entries as $entry) { $isObsolete = isset($entry['obsolete']) && $entry['obsolete']; $isPlural = isset($entry['msgid_plural']); if (isset($entry['previous'])) { foreach ($entry['previous'] as $key => $data) { if (is_string($data)) { $output.= "#| " . $key . " " . $this->cleanExport($data) . "\n"; } elseif (is_array($data) && count($data)>0) { foreach ($data as $line) { $output.= "#| " . $key . " " . $this->cleanExport($line) . "\n"; } } } } if (isset($entry['tcomment'])) { foreach ($entry['tcomment'] as $comment) { $output.= "# " . $comment . "\n"; } } if (isset($entry['ccomment'])) { foreach ($entry['ccomment'] as $comment) { $output.= '#. ' . $comment . "\n"; } } if (isset($entry['reference'])) { foreach ($entry['reference'] as $ref) { $output.= '#: ' . $ref . "\n"; } } if (isset($entry['flags']) && !empty($entry['flags'])) { $output.= "#, " . implode(', ', $entry['flags']) . "\n"; } if (isset($entry['@'])) { $output.= "#@ " . $entry['@'] . "\n"; } if (isset($entry['msgctxt'])) { $output.= 'msgctxt ' . $this->cleanExport($entry['msgctxt'][0]) . "\n"; } if ($isObsolete) { $output.= "#~ "; } if (isset($entry['msgid'])) { if (is_string($entry['msgid'])) { $msgid = explode("\n", $entry['msgid']); } elseif (is_array($entry['msgid'])) { $msgid = $entry['msgid']; } else {
throw new Exception('msgid not string or array'); } $output.= 'msgid '; foreach ($msgid as $i => $id) { if ($i > 0 && $isObsolete) { $output.= "#~ "; } $output.= $this->cleanExport($id) . "\n"; } } if (isset($entry['msgid_plural'])) { if (is_string($entry['msgid_plural'])) { $msgidPlural = explode("\n", $entry['msgid_plural']); } elseif (is_array($entry['msgid_plural'])) { $msgidPlural = $entry['msgid_plural']; } else {
throw new Exception('msgid_plural not string or array'); } $output.= 'msgid_plural '; foreach ($msgidPlural as $plural) { $output.= $this->cleanExport($plural) . "\n"; } } if (count(preg_grep('/^msgstr/', array_keys($entry)))) { if ($isPlural) { $noTranslation = true; foreach ($entry as $key => $value) { if (strpos($key, 'msgstr[') === false) continue; $output.= $key." "; $noTranslation = false; foreach ($value as $i => $t) { $output.= $this->cleanExport($t) . "\n"; } } if ($noTranslation) { $output.= 'msgstr[0] '.$this->cleanExport('')."\n"; $output.= 'msgstr[1] '.$this->cleanExport('')."\n"; } } else { foreach ((array)$entry['msgstr'] as $i => $t) { if ($i == 0) { if ($isObsolete) { $output.= "#~ "; } $output.= 'msgstr ' . $this->cleanExport($t) . "\n"; } else { if ($isObsolete) { $output.= "#~ "; } $output.= $this->cleanExport($t) . "\n"; } } } } $counter++; if ($counter < $entriesCount) { $output.= "\n"; } } return $output; } protected function cleanExport($string) { $quote = '"'; $slash = '\\'; $newline = "\n"; $replaces = array( "$slash" => "$slash$slash", "$quote" => "$slash$quote", "\t" => '\t', ); $string = str_replace(array_keys($replaces), array_values($replaces), $string); $po = $quote . implode("${slash}n$quote$newline$quote", explode($newline, $string)) . $quote; return str_replace("$newline$quote$quote", '', $po); } protected function getEntryId(array $entry) { if (isset($entry['msgctxt'])) { $id = implode($this->options['multiline-glue'], (array)$entry['msgctxt']) . $this->options['context-glue'] . implode($this->options['multiline-glue'], (array)$entry['msgid']); } else { $id = implode($this->options['multiline-glue'], (array)$entry['msgid']); } return $id; } protected function clean($x) { if (is_array($x)) { foreach ($x as $k => $v) { $x[$k] = $this->clean($v); } } else { if ($x == '') { return ''; } if ($x[0] == '"') { $x = substr($x, 1, -1); } $x = stripcslashes($x); } return $x; } protected static function isHeader(array $entry) { if (empty($entry) || !isset($entry['msgstr'])) { return false; } $headerKeys = array( 'Project-Id-Version:' => false, 'PO-Revision-Date:' => false, 'MIME-Version:' => false, ); $count = count($headerKeys); $keys = array_keys($headerKeys); $headerItems = 0; foreach ($entry['msgstr'] as $str) { $tokens = explode(':', $str); $tokens[0] = trim($tokens[0], "\"") . ':'; if (in_array($tokens[0], $keys)) { $headerItems++; unset($headerKeys[$tokens[0]]); $keys = array_keys($headerKeys); } } return ($headerItems == $count) ? true : false; } } class PrisnaWPTranslateParseCSV { public $heading = false; public $fields = array(); public $sort_by = null; public $sort_reverse = false; public $sort_type = null; public $delimiter = ','; public $enclosure = '"'; public $conditions = null; public $offset = null; public $limit = null; public $auto_depth = 15; public $auto_non_chars = "a-zA-Z0-9\n\r"; public $auto_preferred = ",;\t.:|"; public $convert_encoding = false; public $input_encoding = 'ISO-8859-1'; public $output_encoding = 'ISO-8859-1'; public $linefeed = "\r\n"; public $output_delimiter = ','; public $output_filename = 'data.csv'; public $keep_file_data = false; public $file; public $file_data; public $error = 0; public $error_info = array(); public $titles = array(); public $data = array(); public function __construct($input=null, $offset=null, $limit=null, $conditions=null) { if ($offset !== null) $this->offset = $offset; if ($limit !== null) $this->limit = $limit; if (count($conditions) > 0) $this->conditions = $conditions; if (!empty($input)) $this->parse($input); } public function parse($input=null, $offset=null, $limit=null, $conditions=null) { if ($input === null) $input = $this->file; if (!empty($input)) { if ($offset !== null) $this->offset = $offset; if ($limit !== null) $this->limit = $limit; if (count($conditions) > 0) $this->conditions = $conditions; $this->file_data = &$input; $this->data = $this->parse_string(); if ($this->data === false ) return false; } return true; } protected function parse_string($data = null) { if (empty($data)) { if ($this->_check_data()) $data = &$this->file_data; else return false; } $white_spaces = str_replace($this->delimiter, '', " \t\x0B\0"); $rows = array(); $row = array(); $row_count = 0; $current = ''; $head = !empty($this->fields)? $this->fields : array(); $col = 0; $enclosed = false; $was_enclosed = false; $strlen = strlen($data); for ($i=0;$i<$strlen; $i++) { $ch = $data{$i}; $nch = isset($data{$i+1}) ? $data{$i+1} : false; $pch = isset($data{$i-1}) ? $data{$i-1} : false; if ($ch == $this->enclosure) { if (!$enclosed) { if (ltrim($current, $white_spaces) == '') { $enclosed = true; $was_enclosed = true; } else { $this->error = 2; $error_row = count($rows) + 1; $error_col = $col + 1; if (!isset($this->error_info[$error_row.'-'.$error_col])) { $this->error_info[$error_row.'-'.$error_col] = array( 'type' => 2, 'info' => 'Syntax error found on row ' . $error_row . '. Non-enclosed fields can not contain double-quotes.', 'row' => $error_row, 'field' => $error_col, 'field_name' => (!empty($head[$col])) ? $head[$col] : null, ); } $current .= $ch; } } elseif ($nch == $this->enclosure) { $current .= $ch; $i++; } elseif ($nch != $this->delimiter && $nch != "\r" && $nch != "\n") { for ($x=($i+1); isset($data{$x}) && ltrim($data{$x}, $white_spaces) == ''; $x++) {} if ($data{$x} == $this->delimiter) { $enclosed = false; $i = $x; } else { if ($this->error < 1) $this->error = 1; $error_row = count($rows) + 1; $error_col = $col + 1; if (!isset($this->error_info[$error_row.'-'.$error_col])) { $this->error_info[$error_row.'-'.$error_col] = array( 'type' => 1, 'info' => 'Syntax error found on row ' . (count($rows) + 1) . '. ' . 'A single double-quote was found within an enclosed string. ' . 'Enclosed double-quotes must be escaped with a second double-quote.', 'row' => count($rows) + 1, 'field' => $col + 1, 'field_name' => (!empty($head[$col])) ? $head[$col] : null, ); } $current .= $ch; $enclosed = false; } } else { $enclosed = false; } } elseif (($ch == $this->delimiter || $ch == "\n" || $ch == "\r") && !$enclosed) { $key = ( !empty($head[$col]) ) ? $head[$col] : $col ; $row[$key] = ( $was_enclosed ) ? $current : trim($current) ; $current = ''; $was_enclosed = false; $col++; if ($ch == "\n" || $ch == "\r") { if ($this->_validate_offset($row_count) && $this->_validate_row_conditions($row, $this->conditions)) { if ($this->heading && empty($head)) { $head = $row; } elseif (empty($this->fields) || (!empty($this->fields) && (($this->heading && $row_count > 0) || !$this->heading))) { if (!empty($this->sort_by) && !empty($row[$this->sort_by])) { if (isset($rows[$row[$this->sort_by]])) { $rows[$row[$this->sort_by].'_0'] = &$rows[$row[$this->sort_by]]; unset($rows[$row[$this->sort_by]]); for ( $sn=1; isset($rows[$row[$this->sort_by].'_'.$sn]); $sn++) {} $rows[$row[$this->sort_by].'_'.$sn] = $row; } else $rows[$row[$this->sort_by]] = $row; } else $rows[] = $row; } } $row = array(); $col = 0; $row_count++; if ($this->sort_by === null && $this->limit !== null && count($rows) == $this->limit) { $i = $strlen; } if ($ch == "\r" && $nch == "\n") $i++; } } else { $current .= $ch; } } $this->titles = $head; if (!empty($this->sort_by)) { $sort_type = SORT_REGULAR; if ($this->sort_type == 'numeric') { $sort_type = SORT_NUMERIC; } elseif ($this->sort_type == 'string') { $sort_type = SORT_STRING; } ( $this->sort_reverse ) ? krsort($rows, $sort_type) : ksort($rows, $sort_type) ; if ($this->offset !== null || $this->limit !== null) { $rows = array_slice($rows, ($this->offset === null ? 0 : $this->offset) , $this->limit, true); } } if (!$this->keep_file_data) { $this->file_data = null; } return $rows; } public function unparse($data = array(), $fields=array(), $append=false , $is_php=false, $delimiter=null) { if (!is_array($data) || empty($data)) $data = &$this->data; if (!is_array($fields) || empty($fields)) $fields = &$this->titles; if ($delimiter === null) $delimiter = $this->delimiter; $string = $is_php ? "<?php header('Status: 403'); die(' '); ?>" . $this->linefeed : '' ; $entry = array(); foreach ($data as $key => $row) { foreach ($row as $field => $value) $entry[] = $this->_enclose_value($value); $string .= implode($delimiter, $entry) . $this->linefeed; $entry = array(); } return $string; } protected function _wfile($file, $string='', $mode='wb', $lock=2) { if ($fp = fopen($file, $mode)) { flock($fp, $lock); $re = fwrite($fp, $string); $re2 = fclose($fp); if ($re != false && $re2 != false) return true; } return false; } protected function _validate_row_conditions($row=array(), $conditions=null) { if (!empty($row)) { if (!empty($conditions)) { $conditions = (strpos($conditions, ' OR ') !== false) ? explode(' OR ', $conditions) : array($conditions) ; $or = ''; foreach( $conditions as $key => $value) { if (strpos($value, ' AND ') !== false) { $value = explode(' AND ', $value); $and = ''; foreach( $value as $k => $v) { $and .= $this->_validate_row_condition($row, $v); } $or .= (strpos($and, '0') !== false) ? '0' : '1' ; } else { $or .= $this->_validate_row_condition($row, $value); } } return (strpos($or, '1') !== false) ? true : false ; } return true; } return false; } protected function _validate_row_condition($row, $condition) { $operators = array( '=', 'equals', 'is', '!=', 'is not', '<', 'is less than', '>', 'is greater than', '<=', 'is less than or equals', '>=', 'is greater than or equals', 'contains', 'does not contain', ); $operators_regex = array(); foreach( $operators as $value) { $operators_regex[] = preg_quote($value, '/'); } $operators_regex = implode('|', $operators_regex); if (preg_match('/^(.+) ('.$operators_regex.') (.+)$/i', trim($condition), $capture)) { $field = $capture[1]; $op = $capture[2]; $value = $capture[3]; if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture)) { if ($capture[1] == $capture[3]) { $value = $capture[2]; $value = str_replace("\\n", "\n", $value); $value = str_replace("\\r", "\r", $value); $value = str_replace("\\t", "\t", $value); $value = stripslashes($value); } } if (array_key_exists($field, $row)) { if (($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value) { return '1'; } elseif (($op == '!=' || $op == 'is not') && $row[$field] != $value) { return '1'; } elseif (($op == '<' || $op == 'is less than' ) && $row[$field] < $value) { return '1'; } elseif (($op == '>' || $op == 'is greater than') && $row[$field] > $value) { return '1'; } elseif (($op == '<=' || $op == 'is less than or equals' ) && $row[$field] <= $value) { return '1'; } elseif (($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value) { return '1'; } elseif ($op == 'contains' && preg_match('/'.preg_quote($value, '/').'/i', $row[$field])) { return '1'; } elseif ($op == 'does not contain' && !preg_match('/'.preg_quote($value, '/').'/i', $row[$field])) { return '1'; } else { return '0'; } } } return '1'; } protected function _validate_offset($current_row) { if ($this->sort_by === null && $this->offset !== null && $current_row < $this->offset ) return false; return true; } protected function _enclose_value($value=null) { if ($value !== null && $value != '') { $delimiter = preg_quote($this->delimiter, '/'); $enclosure = preg_quote($this->enclosure, '/'); if (preg_match("/".$delimiter."|".$enclosure."|\n|\r/i", $value) || ($value{0} == ' ' || substr($value, -1) == ' ')) { $value = str_replace($this->enclosure, $this->enclosure.$this->enclosure, $value); $value = $this->enclosure.$value.$this->enclosure; } } return $value; } protected function _check_data($file=null) { if (empty($this->file_data)) { if ($file === null) $file = $this->file; return $this->load_data($file); } return true; } protected function _check_count($char, $array, $depth, $preferred) { if ($depth == count($array)) { $first = null; $equal = null; $almost = false; foreach( $array as $key => $value) { if ($first == null) { $first = $value; } elseif ($value == $first && $equal !== false) { $equal = true; } elseif ($value == $first+1 && $equal !== false) { $equal = true; $almost = true; } else { $equal = false; } } if ($equal) { $match = ( $almost ) ? 2 : 1 ; $pref = strpos($preferred, $char); $pref = ( $pref !== false ) ? str_pad($pref, 3, '0', STR_PAD_LEFT) : '999' ; return $pref.$match.'.'.(99999 - str_pad($first, 5, '0', STR_PAD_LEFT)); } else return false; } } protected function _rfile($file=null) { if (is_readable($file)) { if (!($fh = fopen($file, 'r')) ) return false; $data = fread($fh, filesize($file)); fclose($fh); return $data; } return false; } } class PrisnaWPTranslateAnimatedGif { private $image = ''; private $buffer = Array(); private $number_of_loops = 0; private $DIS = 2; private $transparent_colour = -1; private $first_frame = TRUE; function __construct(array $source_images, array $image_delays, $number_of_loops, $transparent_colour_red = -1, $transparent_colour_green = -1, $transparent_colour_blue = -1) { $transparent_colour_red = 0; $transparent_colour_green = 0; $transparent_colour_blue = 0; $this->number_of_loops = ( $number_of_loops > -1 ) ? $number_of_loops : 0; $this->set_transparent_colour($transparent_colour_red, $transparent_colour_green, $transparent_colour_blue); $this->buffer_images($source_images); $this->addHeader(); for ($i = 0; $i < count($this->buffer); $i++) { $this->addFrame($i, $image_delays [$i]); } } private function set_transparent_colour($red, $green, $blue){ $this->transparent_colour = ( $red > -1 && $green > -1 && $blue > -1 ) ? ( $red | ( $green << 8 ) | ( $blue << 16 ) ) : -1; } private function buffer_images($source_images) { for ($i = 0; $i < count($source_images); $i++) { $this->buffer [] = $source_images [$i]; if (substr($this->buffer [$i], 0, 6) != "GIF87a" && substr($this->buffer [$i], 0, 6) != "GIF89a") {
throw new Exception('Image at position ' . $i. ' is not a gif'); } for ($j = ( 13 + 3 * ( 2 << ( ord($this->buffer [$i] { 10 }) & 0x07 ) ) ), $k = TRUE; $k; $j++) { switch ($this->buffer [$i] { $j }) { case "!": if (( substr($this->buffer [$i], ( $j + 3), 8) ) == "NETSCAPE") {
throw new Exception('You cannot make an animation from an animated gif.'); } break; case ";": $k = FALSE; break; } } } } private function addHeader() { $cmap = 0; $this->image = 'GIF89a'; if (ord($this->buffer [0] { 10 }) & 0x80) { $cmap = 3 * ( 2 << ( ord($this->buffer [0] { 10 }) & 0x07 ) ); $this->image .= substr($this->buffer [0], 6, 7); $this->image .= substr($this->buffer [0], 13, $cmap); $this->image .= "!\377\13NETSCAPE2.0\3\1" . $this->word($this->number_of_loops) . "\0"; } } private function addFrame($frame, $delay) { $Locals_str = 13 + 3 * ( 2 << ( ord($this->buffer [$frame] { 10 }) & 0x07 ) ); $Locals_end = strlen($this->buffer [$frame]) - $Locals_str - 1; $Locals_tmp = substr($this->buffer [$frame], $Locals_str, $Locals_end); $Global_len = 2 << ( ord($this->buffer [0] { 10 }) & 0x07 ); $Locals_len = 2 << ( ord($this->buffer [$frame] { 10 }) & 0x07 ); $Global_rgb = substr($this->buffer [0], 13, 3 * ( 2 << ( ord($this->buffer [0] { 10 }) & 0x07 ) )); $Locals_rgb = substr($this->buffer [$frame], 13, 3 * ( 2 << ( ord($this->buffer [$frame] { 10 }) & 0x07 ) )); $Locals_ext = "!\xF9\x04" . chr(( $this->DIS << 2 ) + 0) . chr(( $delay >> 0 ) & 0xFF) . chr(( $delay >> 8 ) & 0xFF) . "\x0\x0"; if ($this->transparent_colour > -1 && ord($this->buffer [$frame] { 10 }) & 0x80) { for ($j = 0; $j < ( 2 << ( ord($this->buffer [$frame] { 10 }) & 0x07 ) ); $j++) { if ( ord($Locals_rgb { 3 * $j + 0 }) == ( ( $this->transparent_colour >> 16 ) & 0xFF ) && ord($Locals_rgb { 3 * $j + 1 }) == ( ( $this->transparent_colour >> 8 ) & 0xFF ) && ord($Locals_rgb { 3 * $j + 2 }) == ( ( $this->transparent_colour >> 0 ) & 0xFF ) ) { $Locals_ext = "!\xF9\x04" . chr(( $this->DIS << 2 ) + 1) . chr(( $delay >> 0 ) & 0xFF) . chr(( $delay >> 8 ) & 0xFF) . chr($j) . "\x0"; break; } } } switch ($Locals_tmp { 0 }) { case "!": $Locals_img = substr($Locals_tmp, 8, 10); $Locals_tmp = substr($Locals_tmp, 18, strlen($Locals_tmp) - 18); break; case ",": $Locals_img = substr($Locals_tmp, 0, 10); $Locals_tmp = substr($Locals_tmp, 10, strlen($Locals_tmp) - 10); break; } if (ord($this->buffer [$frame] { 10 }) & 0x80 && $this->first_frame === FALSE) { if ($Global_len == $Locals_len) { if ($this->blockCompare($Global_rgb, $Locals_rgb, $Global_len)) { $this->image .= ( $Locals_ext . $Locals_img . $Locals_tmp ); } else { $byte = ord($Locals_img { 9 }); $byte |= 0x80; $byte &= 0xF8; $byte |= ( ord($this->buffer [0] { 10 }) & 0x07 ); $Locals_img { 9 } = chr($byte); $this->image .= ( $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp ); } } else { $byte = ord($Locals_img { 9 }); $byte |= 0x80; $byte &= 0xF8; $byte |= ( ord($this->buffer [$frame] { 10 }) & 0x07 ); $Locals_img { 9 } = chr($byte); $this->image .= ( $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp ); } } else { $this->image .= ( $Locals_ext . $Locals_img . $Locals_tmp ); } $this->first_frame = FALSE; } private function addFooter() { $this->image .= ";"; } private function blockCompare($GlobalBlock, $LocalBlock, $Len) { for ($i = 0; $i < $Len; $i++) { if ( $GlobalBlock { 3 * $i + 0 } != $LocalBlock { 3 * $i + 0 } || $GlobalBlock { 3 * $i + 1 } != $LocalBlock { 3 * $i + 1 } || $GlobalBlock { 3 * $i + 2 } != $LocalBlock { 3 * $i + 2 } ) { return ( 0 ); } } return ( 1 ); } private function word($int) { return ( chr($int & 0xFF) . chr(( $int >> 8 ) & 0xFF) ); } function getAnimation() { return $this->image; } function display() { $this->addFooter(); header('Content-type:image/gif'); echo $this->image; } function save($file) { $this->addFooter(); file_put_contents($file, $this->image); } } ?><?php
class PrisnaWPTranslateMessage { private static $_list = array( 'plugin_title' => 'Prisna Translate Settings', 'plugin_title_translations' => 'Prisna Translate: Custom Translations', 'plugin_activated' => 'Prisna Translate is almost ready to translate this site. Please visit the <strong>[0]</strong> to get started.', 'plugin_saved' => 'Settings saved.', 'plugin_layout_changed' => 'Layout changed.', 'translations_saved' => 'Translations saved.', 'permalink_translations_saved' => 'Translations saved.', 'plugin_imported_all_success' => 'Settings and translations succesfully imported.', 'plugin_imported_all_fail' => 'There was a problem while importing the settings and the translations.', 'plugin_imported_success' => 'Settings succesfully imported.', 'plugin_imported_fail' => 'There was a problem while importing the settings. Please make sure the exported string is complete. Changes weren\'t saved.', 'plugin_reseted' => 'Settings reseted.', 'plugin_reset_confirm' => 'All the settings will be reseted and restored to their default values. Do you want to continue?', 'plugin_save_button' => 'Save changes', 'plugin_reset_button' => 'Reset settings', 'plugin_api_key_google_empty_validate' => 'Please provide an <b>API key</b> for the <a href="https://code.google.com/apis/console">Google Translation Service</a>.', 'plugin_client_id_microsoft_empty_validate' => 'Please provide the <b>Client Id</b> for the <a href="https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb" target="_blank">Microsoft Translation Service</a>. Register an <a href="https://datamarket.azure.com/developer/applications/" target="_blank">application</a>.', 'plugin_client_secret_microsoft_empty_validate' => 'Please provide the <b>Client Secret</b> for the <a href="https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb" target="_blank">Microsoft Translation Service</a>. Register an <a href="https://datamarket.azure.com/developer/applications/" target="_blank">application</a>.', 'plugin_cache_folder_validate' => 'The folder [0] isn\'t writable.', 'plugin_cache_file_validate' => 'There\'s at least one cache file that isn\'t writable, ie: <b>[0]</b>', 'plugin_image_file_validate' => 'The following image file isn\'t writable: <b>[0]</b>', 'plugin_openssl_validate' => 'The OpenSSL module isn\'t installed on this server, which is required by the Google Translate API.', 'plugin_fsockopen_validate' => 'The <b>fsockopen</b> function isn\'t enabled on this server.', 'plugin_hash_validate' => 'The <b>hash</b> function isn\'t enabled on this server.', 'plugin_dom_validate' => 'The <b>DOMDocument</b> class isn\'t enabled on this server.', 'plugin_ssl_validate' => 'The <b>Mcrypt</b> module isn\'t enabled on this server.', 'plugin_seo_validate' => 'Enabling SEO requires the <b>mb_convert_encoding</b> function, which isn\'t enabled on this server.', 'plugin_widget_validate' => 'Widget enabled. However, it isn\'t assigned to a widget area (see <a href="[0]">Appearance > Widgets</a>).', 'plugin_wp_super_cache_validate' => 'The <b>WP Super Cache</b> plugin is installed. The "<b>Don\'t cache pages with GET parameters…</b>" setting must be enabled for SEO to work properly.', 'plugin_wp_gd_validate' => 'The <b>GD</b> library isn\'t enabled on this server, which is needed to change images\' colors.', 'layout_tab' => 'Layout', 'general_tab' => 'General', 'advanced_tab' => 'Advanced', 'advanced_general_tab' => 'General', 'advanced_access_tab' => 'Settings Access', 'advanced_import_export_tab' => 'Import / Export', 'advanced_miscellaneous_tab' => 'Miscellaneous', 'translations_tab' => 'Custom Translations', 'translations_general_tab' => 'General', 'translations_import_tab' => 'Import', 'translations_export_tab' => 'Export', 'translations_translators_access_tab' => 'Translators Access', 'translations_onsite_tab' => 'On-Site', 'seo_general_tab' => 'General', 'seo_permalink_tab' => 'Permalinks', 'seo_sitemap_tab' => 'Sitemap', 'seo_log_tab' => 'Logs', 'seo_tab' => 'SEO', 'styles_tab' => 'Styling', 'responsive_tab' => 'Responsive', 'settings_link' => 'Settings', 'widget_description' => 'A powerful translation widget.', 'widget_settings' => 'Ajust settings <a href="[0]">here</a>', 'layout_title' => 'Style', 'size_title' => 'Size', 'api_key_title' => 'API key', 'api_key_description' => '
Sets the Key for the Prisna Translate API.<br />
<a href="https://www.prisna.net/account/" target="_blank">Sign up for an API key</a>
', 'api_key_validate' => 'The entered API key appears to be invalid.<br /><a href="http://www.prisna.net/account/" target="_blank">Sign up for an API key</a>, or to see how the translator looks like, use the following test API key:<br /><br /><a href="javascript:;" onclick="PrisnaWPTranslateAdmin.useTestAPIkey();">[0]</a>', 'api_key_empty_validate' => '<a href="http://www.prisna.net/account/" target="_blank">Sign up for an API key</a>, or to see how the translator looks like, use the following test API key:<br /><br /><a href="javascript:;" onclick="PrisnaWPTranslateAdmin.useTestAPIkey();">[0]</a>', 'api_key_test_validate' => 'The current API key is for testing the translator looks only. It\'s not possible to make translations. <a href="http://www.prisna.net/account/" target="_blank">Sign up for an API key now</a>.[0]', 'api_key_test_validate_extra' => '<br /><br />Consider enabling the <b>Test mode</b> option: Advanced > General > Test mode > Enable', 'translation_service_title' => 'Translation service', 'translation_service_description' => 'Sets the translation service to perform the translations.', 'microsoft_client_id_title' => 'Client Id', 'microsoft_client_id_description' => 'Sets the <div class="prisna_wp_translate_code_container"><code>Client Id</code></div> for the <a href="https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb" target="_blank">Microsoft Translation Service</a>. After signing up for the service, register an <a href="https://datamarket.azure.com/developer/applications/" target="_blank">application</a> to generate both Client Id and Client Secret.', 'microsoft_client_secret_title' => 'Client Secret', 'microsoft_client_secret_description' => 'Sets the <div class="prisna_wp_translate_code_container"><code>Client Secret</code></div> for the <a href="https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c33c06cb" target="_blank">Microsoft Translation Service</a>. After signing up for the service, register an <a href="https://datamarket.azure.com/developer/applications/" target="_blank">application</a> to generate both Client Id and Client Secret.', 'google_api_key_title' => 'Google API key', 'google_api_key_description' => 'Sets the <div class="prisna_wp_translate_code_container"><code>Google API key</code></div> for the <a href="https://code.google.com/apis/console" target="_blank">Google Translation Service</a>.', 'auto_select_title' => 'Auto select language', 'auto_select_description' => '
Automatically selects the page\'s language when it\'s loaded, just to provide visual aids.
', 'auto_select_true' => 'Yes, auto select the language option', 'auto_select_false' => 'No, don\'t auto select the language option', 'complete_title' => 'Completed image', 'complete_description' => 'Sets whether the completed class should be set, or not. If it\'s set, a style class (defined in the <div class="prisna_wp_translate_code_container"><code>Completed class</code></div> setting) will be added to the clicked language. By default, the class displays an image indicating the end of the translation process.', 'complete_true' => 'Yes, display the completed image', 'complete_false' => 'No, hide the completed image', 'auto_select_dd_title' => 'Auto highlight the selected language', 'auto_select_dd_description' => '
Automatically highlight the page\'s language when it\'s loaded, just to provide visual aids.
', 'auto_select_dd_true' => 'Yes, auto highlight the language option', 'auto_select_dd_false' => 'No, don\'t auto highlight the language option', 'complete_dd_title' => 'Highlight the selected language', 'complete_dd_description' => 'Sets whether the completed class should be set, or not. If it\'s set, a style class (defined in the <div class="prisna_wp_translate_code_container"><code>Completed class</code></div> setting) will be added to the clicked language. By default, the class highlights the selected language at the end of the translation process.', 'complete_dd_true' => 'Yes, highlight the selected language', 'complete_dd_false' => 'No, don\'t highlight the selected language', 'completed_class_title' => 'Completed class', 'completed_class_description' => 'Sets the style class to be added to the clicked language\'s link when the translation is completed.', 'sticky_class_title' => 'Sticky class', 'sticky_class_description' => 'Sets the style class to be added to the translator\'s container when the Sticky mode is enabled.', 'container_class_title' => 'Container class', 'container_class_description' => 'Sets the style class to be added to the translator\'s container.', 'container_custom_class_title' => 'Container class (custom location)', 'container_custom_class_description' => 'Sets the style class to be added to the translator\'s container. Only applies if Custom Location is set.', 'container_xy_class_title' => 'Container class (fixed location)', 'container_xy_class_description' => 'Sets the style class to be added to the translator\'s container. Only applies if Fixed Location is set.', 'rtl_class_title' => 'RTL class', 'rtl_class_description' => 'Sets the style class to be added to the body for right-to-left languages.', 'hide_selected_language_title' => 'Hide current selected language', 'hide_selected_language_description' => 'Sets whether to hide the current selected language from the drop down, or not.', 'hide_selected_language_true' => 'Yes, hide current selected language', 'hide_selected_language_false' => 'No, don\'t hide current selected language', 'align_mode_title' => 'Align mode', 'align_mode_description' => 'Sets the alignment mode of the languages.', 'align_mode_left' => 'Left', 'align_mode_center' => 'Center', 'align_mode_right' => 'Right', 'align_left_class_title' => 'Align left class', 'align_left_class_description' => 'Sets the style class to be added to the translator\'s container when the <div class="prisna_wp_translate_code_container"><code>Align mode</code></div> setting is set to <div class="prisna_wp_translate_code_container"><code>Left</code></div>.', 'align_right_class_title' => 'Align right class', 'align_right_class_description' => 'Sets the style class to be added to the translator\'s container when the <div class="prisna_wp_translate_code_container"><code>Align mode</code></div> setting is set to <div class="prisna_wp_translate_code_container"><code>Right</code></div>.', 'corners_title' => 'Round corners', 'corners_description' => 'Sets whether to round the corners of the main container, or not.', 'corners_true' => 'Yes, round the corners of the main container', 'corners_false' => 'No, don\'t round the corners of the main container', 'scroll_title' => 'Enable scroll', 'scroll_description' => 'Sets whether the scroll functionality should be enabled, or not.', 'scroll_true' => 'Yes, enable the scroll functionality', 'scroll_false' => 'No, disable the scroll functionality', 'scroll_bar_languages_title' => 'Languages quantity', 'scroll_bar_languages_description' => 'Sets how many languages will be visible within the scrolling viewport.', 'scroll_bar_width_title' => 'Scroll bar width', 'scroll_bar_width_description' => 'Sets the scroll bar width.', 'scroll_bar_opacity_title' => 'Scroll bar opacity', 'scroll_bar_opacity_description' => 'Sets the scroll bar opacity.', 'scroll_bar_wheel_step_title' => 'Mouse wheel step', 'scroll_bar_wheel_step_description' => 'Sets the mouse wheel step.', 'cookie_title' => 'Remember the selected language for auto-translate', 'cookie_description' => 'Sets whether the selected language should be remembered (in a cookie) after a page is refreshed, or not. If it\'s set and the visitor continues browsing, the website will be automatically translated.', 'cookie_true' => 'Yes, remember the selected language to auto-translate', 'cookie_false' => 'No, don\'t remember the selected language and don\'t auto-translate', 'cookie_persistency_title' => 'Remember even after the browser is closed', 'cookie_persistency_description' => 'Sets whether the <div class="prisna_wp_translate_code_container"><code>Remember the selected language for auto-translate</code></div> should be kept after the visitor\'s browser is closed, or not.', 'cookie_persistency_true' => 'Yes, remember even after the browser is closed', 'cookie_persistency_false' => 'No, don\'t remember after the browser is closed', 'multiple_languages_title' => 'Multiple languages pages', 'multiple_languages_description' => 'Sets whether the pages in this site contain content in multiple languages, or not.', 'multiple_languages_true' => 'Yes, pages on this site contain multiple languages', 'multiple_languages_false' => 'No, pages on this site don\'t contain multiple languages', 'requests_title' => 'Requests', 'requests_description' => 'Sets the maximum number of requests sent to the API at the same time. A high number of requests will translate the page faster, but might hang or even crash the internet browser.', 'rtl_languages_title' => 'RTL languages', 'rtl_languages_description' => 'Defines a list with the right-to-left language codes. After a translation is made, the body will look like:<br /><br />
<div class="prisna_wp_translate_code_container"><code><body class="<b>prisna-wp-translate-rtl</b>"></code></div>', 'exclude_selector_title' => 'Exclude selector (jQuery)', 'exclude_selector_description' => 'Select those elements to NOT be translated. In jQuery format. For more info, check the <a href="http://api.jquery.com/category/selectors/" target="_blank">jQuery selector guide</a>.', 'exclude_words_rules_title' => 'Exclude paragraphs (regular expression)', 'exclude_words_rules_description' => 'Defines a set of rules to exclude paragraphs from translations.<br /><br />
A rule is defined as <a href="http://www.php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">a regular expression</a> to match the paragraph. <a href="http://www.vijayforvictory.com/wp-content/gallery/ngen_gallery/regular-expressions-cheat-sheet.png" target="_blank">Cheat sheet</a>.<br />
One rule per line. For instance:<br /><br />
/mysite\.com/<br /><br />
Invalid rules will be silently ignored.', 'key_message' => 'This domain/subdomain doesn\'t appear to be enabled in this API key. To verify it, please check your account: https://www.prisna.net/account/', 'flag_template_title' => 'Flag template', 'flag_template_description' => 'Sets the language\'s flag template. New templates can be created if the provided one doesn\'t fit the web page requirements.', 'flags_title' => 'Flags', 'flags_description' => 'Sets whether the languages flags should be displayed, or not.', 'flags_true' => 'Yes, display the images flags', 'flags_false' => 'No, hide the images flags', 'test_mode_title' => 'Test mode', 'test_mode_description' => '
Sets whether the translator is in test mode, or not. In "test mode", the translator will be displayed only if the current logged in user has admin privileges.<br />
Is useful for setting up the translator without letting visitors to see the changes while the plugin is being implemented.
', 'test_mode_true' => 'Yes, enable test mode', 'test_mode_false' => 'No, disable test mode', 'shortcode_title' => 'Usage', 'shortcode_description' => '', 'custom_css_title' => 'Custom CSS', 'custom_css_description' => 'Defines custom CSS rules.', 'translate_attributes_title' => 'Enable attributes translation', 'translate_attributes_description' => 'Sets whether the elements\' attributes: <div class="prisna_wp_translate_code_container"><code>title</code></div>, <div class="prisna_wp_translate_code_container"><code>alt</code></div> and <div class="prisna_wp_translate_code_container"><code>placeholder</code></div>, should be translated, or not.', 'translate_attributes_true' => 'Yes, translate the elements\' attributes', 'translate_attributes_false' => 'No, don\'t translate the elements\' attributes', 'translate_title_attribute_title' => 'Translate the <em>title</em> attribute', 'translate_title_attribute_description' => 'Sets whether the <div class="prisna_wp_translate_code_container"><code>title</code></div> attribute should be translated, or not.', 'translate_title_attribute_true' => 'Yes, translate the <em>title</em> attribute', 'translate_title_attribute_false' => 'No, don\'t translate the <em>title</em> attribute', 'translate_alt_attribute_title' => 'Translate the <em>alt</em> attribute', 'translate_alt_attribute_description' => 'Sets whether the <div class="prisna_wp_translate_code_container"><code>alt</code></div> attribute should be translated, or not.', 'translate_alt_attribute_true' => 'Yes, translate the <em>alt</em> attribute', 'translate_alt_attribute_false' => 'No, don\'t translate the <em>alt</em> attribute', 'translate_placeholder_attribute_title' => 'Translate the <em>placeholder</em> attribute', 'translate_placeholder_attribute_description' => 'Sets whether the <div class="prisna_wp_translate_code_container"><code>placeholder</code></div> attribute should be translated, or not.', 'translate_placeholder_attribute_true' => 'Yes, translate the <em>placeholder</em> attribute', 'translate_placeholder_attribute_false' => 'No, don\'t translate the <em>placeholder</em> attribute', 'translate_meta_tags_title' => 'Translate meta tags <em>content</em> attribute', 'translate_meta_tags_description' => 'Sets whether the <div class="prisna_wp_translate_code_container"><code>content</code></div> attribute of meta tags should be translated, or not.', 'translate_meta_tags_true' => 'Yes, translate the <em>content</em> attribute of <em>meta tags</em>', 'translate_meta_tags_false' => 'No, don\'t translate the <em>content</em> attribute of <em>meta tags</em>', 'translate_meta_tags_names_title' => 'Meta tags kinds', 'translate_meta_tags_names_description' => 'Specifies attributes used to select meta tags to translate.', 'widget_insert_widget' => 'Insert widget', 'widget_dont_translate' => 'Don\'t translate', 'widget_show_hide' => 'Show / hide content', 'widget_show_hide_default' => 'Default behavior:', 'widget_show_hide_show' => 'Show', 'widget_show_hide_hide' => 'Hide', 'widget_show_hide_except' => 'Except for:', 'widget_show_hide_add' => 'Add', 'custom_flags_title' => 'Define custom flags', 'custom_flags_description' => 'Defines alternative flags to languages. Click on a language to remove it.<br /><a href="https://www.prisna.net/contact-us/" target="_blank">Contact us</a> for additional countries.', 'custom_flags_add' => 'Add', 'translations_translators_access_title' => 'Grant access to edit translations', 'translations_translators_access_description' => 'Grant access to edit translations to different users. Granted users will be allowed to edit translations without having access to the plugin\'s settings.<br /><br />A new entry in the main menu named <em>Translatios for Prisna Translate</em> will be created.', 'translations_translators_access_add' => 'Add', 'translations_onsite_title' => 'Edit translations on-site', 'local_storage_title' => 'Enable local storage', 'local_storage_description' => 'Sets whether the translations should be stored in the visitor\'s browser to speed up the plugin, or not. This feature is available on modern browsers only, it won\'t cause any impact on old browsers. However, it forces the visitor\'s browser to use an extra amount of memory, therefore, it might slow it down depending on how many translations are being stored.', 'local_storage_true' => 'Yes, enable local storage', 'local_storage_false' => 'No, disable local storage', 'local_storage_expires_title' => 'Expiration period', 'local_storage_expires_description' => 'Sets an expiration period for the stored translations, in days.', 'clear_local_storage_title' => 'Clear local storage', 'clear_local_storage_description' => 'Sets whether to force the visitor\'s browser to clear up the stored translations and retrieve them again from the server, or not. This setting is useful when writing custom translations.', 'clear_local_storage_true' => 'Yes, force browsers to clear up the stored translations', 'clear_local_storage_false' => 'No, don\'t force browsers to clear up the stored translations', 'location_widget_title' => 'Location', 'location_widget_description' => '
Sets translator location.
', 'location_widget_true' => 'Shortcode / Menu / Widget (<a href="[0]">Appearance > Widgets</a>)', 'location_widget_false' => 'Custom', 'location_widget_xy' => 'Fixed', 'location_widget_top' => 'On top', 'location_custom_title' => 'Custom location (jQuery)', 'location_custom_description' => 'Specifies a location to place the translator. In jQuery format. For more info, check the <a href="http://api.jquery.com/category/selectors/" target="_blank">jQuery selector guide</a>.', 'widget_class_title' => 'Widget class', 'widget_class_description' => 'Sets the style class used on the widget\'s placeholder.', 'bar_container_id_title' => 'Widget container id', 'bar_container_id_description' => 'Sets the internal widget\'s container <div class="prisna_wp_translate_code_container"><code>id</code></div>.', 'dropdown_container_id_title' => 'Widget container id', 'dropdown_container_id_description' => 'Sets the internal widget\'s container <div class="prisna_wp_translate_code_container"><code>id</code></div>.', 'sticky_title' => 'Sticky mode', 'sticky_description' => 'Sets whether to display the translator in sticky mode or not. In "Sticky mode", the translator will remain visible at all times, even when scrolling pages down.', 'sticky_true' => 'Yes, enable the sticky mode', 'sticky_false' => 'No, disable the sticky mode', 'xy_vertical_title' => 'Vertical distance', 'xy_vertical_description' => '
Specifies the distance between the top/bottom margin edge of the translator and the top/bottom edge of its parent.<br /><br />
For instance:<br /><br />
top: 20px<br />
bottom: -20px<br />
top: 2.5em<br />
bottom: 10%<br />
top: auto<br />
bottom: inherit
', 'xy_vertical_top' => 'top', 'xy_vertical_bottom' => 'bottom', 'xy_horizontal_title' => 'Horizontal distance', 'xy_horizontal_description' => '
Specifies the distance between the left/right margin edge of the translator and the left/right edge of its parent.<br /><br />
For instance:<br /><br />
left: 20px<br />
right: -20px<br />
left: 2.5em<br />
right: 10%<br />
left: auto<br />
right: inherit
', 'xy_horizontal_left' => 'left', 'xy_horizontal_right' => 'right', 'xy_parent_title' => 'Parent (jQuery)', 'xy_parent_description' => 'Specifies a parent element container (or set) to hold the translator. In jQuery format. For more info, check the <a href="http://api.jquery.com/category/selectors/" target="_blank">jQuery selector guide</a>.', 'custom_parent_title' => 'Custom parent', 'custom_parent_description' => 'Specifies a custom parent element container (or set) to hold the translator.', 'custom_location_insert_mode_title' => 'Insert mode', 'custom_location_insert_mode_description' => 'Specifies how the translator (or the <div class="prisna_wp_translate_code_container"><code>Custom parent</code></div>) will be inserted into the <div class="prisna_wp_translate_code_container"><code>Custom location</code></div>.', 'flags_and_names_class_title' => 'Flags and names class', 'flags_and_names_class_description' => 'Adds a style class to the translator\'s main container when is showing languages flags and names.', 'flags_and_short_names_class_title' => 'Flags and short names class', 'flags_and_short_names_class_description' => 'Adds a style class to the translator\'s main container when is showing languages flags and short names.', 'flags_class_title' => 'Flags class', 'flags_class_description' => 'Adds a style class to the translator\'s main container when is showing only languages flags.', 'from_title' => 'Website\'s language', 'from_description' => 'Sets the website\'s source language.', 'hidden_class_title' => 'Hide class', 'hidden_class_description' => 'Sets the style class used to hide elements.', 'id_title' => 'Id', 'id_description' => '
Sets the internal <div class="prisna_wp_translate_code_container"><code>id</code></div> unique value.
It could also be used for custom styling purposes, since the translator id will be placed in the container\'s class attribute:<br /><br />
<div class="prisna_wp_translate_code_container"><code><div class="translator translator-container <b><id></b>"></code></div>
', 'language_selector_class_title' => 'Language selector class', 'language_selector_class_description' => '
Sets the style class used to identify the selected language. The language code will be concatenated:<br />
<div class="prisna_wp_translate_code_container"><code><a class="<b>translator-language-</b>en" title="English" href="javascript:;"><img alt="English" src="../translator/images/English.gif"><span>English</span></a></code></div>
', 'translated_to_class_title' => 'Translated to class', 'translated_to_class_description' => 'Sets the prefix of the style class appended to the main body HTML element. After a translation is made, the body will look like:<br />
<div class="prisna_wp_translate_code_container"><code><body class="<b>prisna-wp-translate-translated-to-</b>es"></code></div>', 'flags_images_class_title' => 'Flags images class', 'flags_images_class_description' => 'Sets the style class used to identify flags images when the <div class="prisna_wp_translate_code_container"><code>Combine flags images files into a single image file</code></div> setting is enabled.', 'languages_title' => 'Available languages', 'languages_description' => 'Sets the available languages.', 'languages_order_title' => 'Languages order', 'languages_order_description' => 'Defines the order to display the languages.', 'native_languages_title' => 'Languages in their own language', 'native_languages_description' => 'Sets whether to display the languages names in their own language, or not. To define custom names, use the following setting:<br /><br /><div class="prisna_wp_translate_code_container"><code>Advanced > Other customizations > Custom languages names</code></div>', 'native_languages_true' => 'Yes, display languages in their own language', 'native_languages_false' => 'No, display languages in English', 'link_template_title' => 'Link template', 'link_template_description' => 'Sets the language\'s link template. New templates can be created if the provided one doesn\'t fit the web page requirements.', 'links_container_template_title' => 'Links container template', 'links_container_template_description' => 'Sets the languages links container template. New templates can be created if the provided one doesn\'t fit the web page requirements.', 'loading_title' => 'Loading image', 'loading_description' => 'Sets whether the loading class should be set, or not. If it\'s set, a style class (defined in the <div class="prisna_wp_translate_code_container"><code>Loading class</code></div> setting) will be added to the clicked language\'s link. By default, the class displays an animated image indicating the loading.', 'loading_true' => 'Yes, display the loading animated image', 'loading_false' => 'No, hide the loading animated image', 'loading_class_title' => 'Loading class', 'loading_class_description' => 'Sets the style class to be added to the clicked language\'s link while the translation takes place.', 'glowing_class_title' => 'Glowing class', 'glowing_class_description' => 'Sets the style class to be added to the translator\'s main container when the glowing option is enabled.', 'corners_class_title' => 'Round corners class', 'corners_class_description' => 'Sets the style class to be added to the translator\'s main container when the corners are rounded.', 'name_template_title' => 'Name template', 'name_template_description' => 'Sets the language\'s name template. New templates can be created if the provided one doesn\'t fit the web page requirements.', 'names_title' => 'Names', 'names_description' => 'Sets whether the languages names should be displayed, or not.', 'names_true' => 'Yes, display the languages names', 'names_false' => 'No, hide the languages names', 'names_class_title' => 'Names class', 'names_class_description' => 'Adds a style class to the translator\'s main container when is showing only languages names.', 'on_before_initialize_title' => 'On before initialize callback', 'on_before_initialize_description' => 'Sets a callback function that runs before the translator is initialized. Receives two arguments: <div class="prisna_wp_translate_code_container"><code>translator, options</code></div>.', 'on_initialize_title' => 'On initialize callback', 'on_initialize_description' => 'Sets a callback function that runs when the translator is being initialized. Receives two arguments: <div class="prisna_wp_translate_code_container"><code>translator, options</code></div>.', 'on_complete_title' => 'On complete callback', 'on_complete_description' => 'Sets a callback function that runs when the translation is completed. Receives seven arguments: <div class="prisna_wp_translate_code_container"><code>filtered_elements, translation, source, from, to, options, restore</code></div>.', 'on_start_title' => 'On start callback', 'on_start_description' => 'Sets a callback function that runs when the translation starts. Receives five arguments: <div class="prisna_wp_translate_code_container"><code>filtered_elements, source, from, to, options</code></div>.', 'on_before_load_title' => 'On before load', 'on_before_load_description' => 'Defines a javascript routine that runs before the translator is loaded.', 'restore_title' => 'Restore button', 'restore_description' => '
Sets whether the restore button should be displayed, or not. By clicking the <div class="prisna_wp_translate_code_container"><code>Restore</code></div> button, all the selected text will be restored to their original content, and will clear the <div class="prisna_wp_translate_code_container"><code>Remember (cookie)</code></div> setting too.
', 'restore_true' => 'Yes, display the restore button', 'restore_false' => 'No, hide the restore button', 'restore_class_title' => 'Restore class', 'restore_class_description' => 'Sets the style class to be added to the restore button.', 'restore_container_class_title' => 'Restore container class', 'restore_container_class_description' => 'Sets the style class to be added to the restore button\'s container.', 'restore_template_title' => 'Restore template', 'restore_template_description' => 'Sets the restore button\'s template. New templates can be created if the provided one doesn\'t fit the web page requirements.', 'separator_title' => 'Languages separator', 'separator_description' => '
Sets a separator between the languages options.<br />
In order to optimize browser compatibility, the translator is built based on a table, so the separator will usually be a table cell (unless the templates are changed).<br />
For instance:<br /><br />
<div class="prisna_wp_translate_code_container"><code><td>|</td></code></div><br /><br />
Or:<br /><br />
<div class="prisna_wp_translate_code_container"><code><td>·</td></code></div>
', 'adjust_position_title' => 'Adjust vertical position', 'adjust_position_description' => 'Some websites with special styles (body having relative positioning) will found the translation bar not placed at the very top. To correct that issue, enable this option to override the <div class="prisna_wp_translate_code_container"><code>Container class</code></div>.', 'adjust_position_true' => 'Yes, adjust the position', 'adjust_position_false' => 'No, the current position is fine', 'override_container_class_title' => 'Override container class', 'override_container_class_description' => 'Sets the style class to override the translator\'s container class defined in <div class="prisna_wp_translate_code_container"><code>Container class</code></div>.', 'short_names_title' => 'Short names', 'short_names_description' => 'Sets whether the languages names should be displayed in short mode, or not.<br />For instance: EN, ES, DA.', 'short_names_true' => 'Yes, display the languages names in short mode', 'short_names_false' => 'No, display the languages full names', 'short_names_class_title' => 'Short names class', 'short_names_class_description' => 'Adds a style class to the translator\'s main container when is showing only languages short names.', 'sub_container_class_title' => 'Sub container class', 'sub_container_class_description' => 'Sets the style class to be added to the translator\'s sub container.', 'floating_left_class_title' => 'Floating left class', 'floating_left_class_description' => 'Sets the style class to be added to the translator\'s container when the <div class="prisna_wp_translate_code_container"><code>Floating mode</code></div> setting is set to <div class="prisna_wp_translate_code_container"><code>Float left</code></div>.', 'floating_right_class_title' => 'Floating right class', 'floating_right_class_description' => 'Sets the style class to be added to the translator\'s container when the <div class="prisna_wp_translate_code_container"><code>Floating mode</code></div> setting is set to <div class="prisna_wp_translate_code_container"><code>Float right</code></div>.', 'hide_selected_language_class_title' => 'Hide selected language class', 'hide_selected_language_class_description' => 'Sets the style class to be added to the translator\'s container when the <div class="prisna_wp_translate_code_container"><code>Hide current selected language</code></div> setting is enabled.', 'body_class_title' => 'Body class', 'body_class_description' => 'Sets the style class to be added to the translator\'s body.', 'current_language_container_class_title' => 'Current language container class', 'current_language_container_class_description' => 'Sets the style class to be added to the current selected language.', 'current_lang_cont_arrow_class_title' => 'Current language arrow container class', 'current_lang_cont_arrow_class_description' => 'Sets the style class to be added to the arrow container.', 'languages_list_class_title' => 'Language list class', 'languages_list_class_description' => 'Sets the style class to be added to the languages list container.', 'languages_list_opened_class_title' => 'Language opened list class', 'languages_list_opened_class_description' => 'Sets the style class to be added to the languages list container when is unfolded.', 'scroll_class_title' => 'Scroll enabled class', 'scroll_class_description' => 'Sets the style class to be added to the translator\'s container, if the <div class="prisna_wp_translate_code_container"><code>Scroll</code></div> setting is enabled.', 'hover_class_title' => 'Hover enabled class', 'hover_class_description' => 'Sets the style class to be added to the translator\'s container, if the visitor\'s browser supports hovering, unlike a touch device.', 'languages_list_scroll_class_title' => 'Language list scroll class', 'languages_list_scroll_class_description' => 'Sets the style class to be added to the languages list container parent, if the <div class="prisna_wp_translate_code_container"><code>Scroll</code></div> setting is enabled.', 'languages_list_scroll_bar_class_title' => 'Language list scroll bar class', 'languages_list_scroll_bar_class_description' => 'Sets the style class to be added to the scroll bar, if the <div class="prisna_wp_translate_code_container"><code>Scroll</code></div> setting is enabled.', 'target_selector_title' => 'Target selector (jQuery)', 'target_selector_description' => 'Select those elements to be translated. In jQuery format. For more info, check the <a href="http://api.jquery.com/category/selectors/" target="_blank">jQuery selector guide</a>.<br /><br />To translate the title of the pages, make sure to add it: <div class="prisna_wp_translate_code_container"><code>body, title</code></div> ', 'custom_html_title' => 'Custom HTML', 'custom_html_description' => '
Specifies a custom HTML to represent the translator.
If it doesn\'t find at least one element which <div class="prisna_wp_translate_code_container"><code>class</code></div> attribute contains the value: <div class="prisna_wp_translate_code_container"><code>Language selector class</code></div> + <div class="prisna_wp_translate_code_container"><code><language_code></code></div>, the content of the container element will be replaced by the translator\'s structure.<br />
In order to have the <div class="prisna_wp_translate_code_container"><code>Restore</code></div> button working, the element <div class="prisna_wp_translate_code_container"><code>class</code></div> attribute should contain the <div class="prisna_wp_translate_code_container"><code>Restore class</code></div> value and its main parent should contain <div class="prisna_wp_translate_code_container"><code>Restore container class</code></div> value too.<br />
For instance:<br /><br />
<div class="prisna_wp_translate_code_container">
<div class="prisna_wp_translate_code_container"><code>
<div class="translator"><br />
<a href="#" class="translator-language-<b>es</b>"><br />
Spanish<br />
</a><br />
<a href="#" class="translator-language-<b>en</b>"><br />
English<br />
</a><br />
<a href="#" class="translator-language-<b>da</b>"><br />
Danish<br />
</a><br />
<span class="translator-hidden translator-restore-container"><br />
<a href="#" class="restore"><br />
Restore<br />
</a><br />
</span><br />
</div>
</code></div>
</div>
', 'query_string_auto_translate_title' => 'Auto translate by parameter', 'query_string_auto_translate_description' => 'Sets whether to enable the auto translation by query string parameter functionality, or not.', 'query_string_auto_translate_true' => 'Yes, enable auto translate by parameter', 'query_string_auto_translate_false' => 'No, disable auto translate by parameter', 'query_string_auto_param_title' => 'Parameter name', 'query_string_auto_param_description' => 'Defines the parameter name to perform the auto translation. In order to use it, assign the language code desired to translate to. For instance:<br /><br />http://www.yoursite.com/?<b>translate-to=ja</b><br />http://www.yoursite.com/page.php?location=home&<b>translate-to=ja</b>', 'detect_browser_locale_title' => 'Detect browser\'s language', 'detect_browser_locale_description' => '
Sets whether to detect the vistiror browser\'s language, or not.<br /><br />
<b>All visits</b>: The browser\'s language detection mechanism will be performed everytime a visitor loads a page, regardless of whether the visitor has selected another language, or not.<br />
<b>First visit only</b>: The browser\'s language detection mechanism will be performed only the first time a visitor loads a page. If the visitor selects a different language, upcoming pages will be translated to the selected language.
', 'detect_browser_locale_always' => 'All visits', 'detect_browser_locale_first' => 'First visit only', 'detect_browser_locale_false' => 'Don\'t detect the browser\'s language', 'detect_browser_locale_always_action_title' => 'Detect browser\'s language action', 'detect_browser_locale_always_action_description' => '
Sets the action to be performed when detecting the visitor browser\'s language.<br /><br />
<b>Automatic translation</b>: The page will be automatically translated to the detected language.<br />
<b>Show or hide translator</b>: The translator will be shown if the detected language is different than the <div class="prisna_wp_translate_code_container"><code>General > Website\'s language</code></div>. The translator will be hidden if the detected language is the same.
', 'detect_browser_locale_always_action_translate' => 'Automatic translation', 'detect_browser_locale_always_action_display' => 'Show or hide translator', 'override_title' => 'Override settings', 'override_description' => 'Defines a javascript object to override the current settings.', 'custom_languages_names_title' => 'Custom languages names', 'custom_languages_names_description' => 'Defines a javascript object to override the current languages names. For instance:<br /><code><br />{<br /> "pt": "Português",<br /> "ja": "日本語"<br />}</code>', 'seo_languages_title' => 'SEO available languages', 'seo_languages_description' => 'Sets the available languages to be indexed by the search engines.<br /><br /><div class="prisna_wp_translate_code_container"><code>Only cached translations can be indexed.</code></div><br /><br /><b>Important</b>: This is a machine translation plugin, it\'s your sole responsibility to verify the translated text is correct, and relevant to the purpose of this site. Use the <div class="prisna_wp_translate_code_container"><code>Custom Translations</code></div> tab to verify and to adjust the cached translations.', 'seo_chinese_title' => 'Chinese ISO 639-1 language', 'seo_chinese_description' => 'Selects which Chinese variation will be assigned to the <div class="prisna_wp_translate_code_container"><code>zh</code></div> ISO 639-1 language code.', 'seo_url_mode_title' => 'URL modification mode', 'seo_url_mode_description' => 'Sets the URL modification mode.<br /><br />Pre path and Subdomain modes will only work with mod_rewrite/pretty permalinks. The next tab <div class="prisna_wp_translate_code_container"><code>Sitemap > Access</code></div> links should work if mod_rewrite/pretty permalinks is enabled.<br /><br />The <div class="prisna_wp_translate_code_container"><code>Subdomain</code></div> mode requires to properly set a CNAME (Alias) record for each enabled language. The name of the record should be the language code.', 'seo_url_mode_query' => 'Query string (?lang=en)', 'seo_url_mode_path' => 'Pre path (/en/ in front of URL)', 'seo_url_mode_subdomain' => 'Subdomain (en.yoursite.com)', 'seo_variable_title' => 'Parameter name', 'seo_variable_description' => 'Defines a query string parameter to be used to specify the language of pages indexed by search engines.<br />It\'s recommended to not change this parameter after the <div class="prisna_wp_translate_code_container"><code>SEO</code></div> setting has been enabled, as search engines might have indexed pages already.', 'seo_max_log_size_title' => 'Maximum log size', 'seo_max_log_size_description' => 'Defines the maximum number of entries the log can hold. Changes will take effect next time a log entry is created.', 'glowing_title' => 'Enable glowing', 'glowing_description' => 'Sets whether a glowing effect should be applied to the languages, or not.', 'glowing_true' => 'Yes, enable the glowing effect', 'glowing_false' => 'No, disable the glowing effect', 'background_color_title' => 'Background color', 'background_color_description' => 'Sets the background color.', 'font_color_title' => 'Font color', 'font_color_description' => 'Sets the font color.', 'background_color_on_expand_title' => 'Background color (expanded view)', 'background_color_on_expand_description' => 'Sets the background color of the expanded list view.', 'font_color_on_expand_title' => 'Font color (expanded view)', 'font_color_on_expand_description' => 'Sets the font color of the expanded list view.', 'background_color_on_hover_title' => 'Background color (hover)', 'background_color_on_hover_description' => 'Sets the background color of the language on mouse hover.', 'font_color_on_hover_title' => 'Font color (hover)', 'font_color_on_hover_description' => 'Sets the font color of the language on mouse hover.', 'scroll_bar_color_expand_title' => 'Scroll bar color', 'scroll_bar_color_expand_description' => 'Sets the color of the scroll bar.', 'arrow_color_title' => 'Arrow color', 'arrow_color_description' => 'Sets the color of the arrow.', 'loading_image_color_title' => 'Loading image color', 'loading_image_color_description' => 'Sets the color of the animated image indicating the loading process. Make sure to clear the browser\'s cache (or to force to releoad all the page resources by pressing F5), otherwise the image might not be retrieved from the server and it\'ll look as it hasn\'t been changed.', 'controls_image_color_title' => 'Completed and Restore images color', 'controls_image_color_description' => 'Sets the color of both the completed and restore images. Make sure to clear the browser\'s cache (or to force to releoad all the page resources by pressing F5), otherwise the image might not be retrieved from the server and it\'ll look as it hasn\'t been changed.', 'hide_language_or_flag_low_resolutions_title' => 'Hide language name or language flag', 'hide_language_or_flag_low_resolutions_description' => 'Sets whether to hide the language name or the language flag for lower resolutions, or not.', 'hide_language_or_flag_low_resolutions_name' => 'Yes, hide the language name', 'hide_language_or_flag_low_resolutions_flag' => 'Yes, hide the language flag', 'hide_language_or_flag_low_resolutions_false' => 'No, don\'t hide anything', 'low_resolution_title' => 'Low resolution', 'low_resolution_description' => 'Defines a media query to be used by the above setting.', 'no_hide_low_resolution_title' => 'Low resolution hide language class', 'no_hide_low_resolution_description' => 'Sets the style class to be added to the translator\'s container when the <div class="prisna_wp_translate_code_container"><code>Responsive > Hide language name or language flag</code></div> setting is disabled.', 'languages_names_class_title' => 'Languages names class', 'languages_names_class_description' => 'Sets the style class used to identify languages names.', 'responsive_title' => 'Responsive rules', 'responsive_description' => '
Responsive web design is a web design approach aimed at crafting sites to provide an optimal viewing experience — easy reading and navigation across a wide range of devices (from desktop computer monitors to mobile phones).<br /><br />
Media query: Consists of a one or more expressions that check for the conditions of particular media features.', 'responsive_add_new' => 'Add new', 'responsive_remove' => 'Remove', 'responsive_show' => 'Show', 'responsive_hide' => 'Hide', 'seo_log_title' => 'Logs', 'seo_log_description' => 'Displays the latest activity.', 'seo_log_empty_message' => 'There are no entries in the log.', 'seo_log_empty_response_message' => 'Empty response, there is no further information.', 'seo_log_xml_message' => 'The HTML code of <a href="[0]" target="_blank">[0]</a> has serious problems. Refer to the <a href="http://validator.w3.org/check?uri=[1]&charset=%28detect+automatically%29&doctype=Inline&group=0" target="_blank">Markup Validation Service</a> for more information.', 'seo_log_success_message' => '<a href="[0]" target="_blank">[0]</a> ([1]) parsed correctly.', 'seo_log_sitemap_success_message' => '<a href="[0]" target="_blank">[0]</a> Sitemap accessed.', 'enable_permalinks_title' => 'Enable permalink translations', 'enable_permalinks_description' => 'Sets whether to enable permalink translations, or not. It requires Permalinks enabled:<br /><br /><div class="prisna_wp_translate_code_container"><code>Settings > Permalinks</code></div>', 'enable_permalinks_true' => 'Yes, enable permalink translations', 'enable_permalinks_false' => 'No, disable permalink translations', 'auto_translate_permalinks_title' => 'Auto translate permalinks', 'auto_translate_permalinks_description' => 'Sets whether to automatically attempt to translate permalinks, or not. Since URLs aren\'t regular plain text, translations might need to be modified. Permalinks translations can be modified below.', 'auto_translate_permalinks_true' => 'Yes, auto translate permalinks', 'auto_translate_permalinks_false' => 'No, don\'t auto translate permalinks', 'exclude_permalinks_rules_title' => 'Exclude permalinks (regular expression)', 'exclude_permalinks_rules_description' => 'Defines a set of rules to exclude permalinks from translations.<br /><br />
A rule is defined as <a href="http://www.php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">a regular expression</a> to match the full URL. <a href="http://www.vijayforvictory.com/wp-content/gallery/ngen_gallery/regular-expressions-cheat-sheet.png" target="_blank">Cheat sheet</a>.<br />
One rule per line. For instance:<br /><br />
/slider\-revolution/i<br /><br />
Invalid rules will be silently ignored.', 'permalinks_title' => 'Permalink', 'permalinks_description' => 'Modifies permalinks.
<ol>
<li>Select the <div class="prisna_wp_translate_code_container"><code>Permalink</code></div> to modify (only <div class="prisna_wp_translate_code_container"><code>Permalinks</code></div> from cached translations will be listed).</li>
<li>Modify the <div class="prisna_wp_translate_code_container"><code>Permalinks</code></div> at will.</li>
</ol>', 'permalinks_permalink_structure_empty_description' => '
<div class="prisna_wp_translate_permalink_structure_empty prisna_wp_translate_validate_warning">
<h3 class="prisna_wp_translate_validate_warning">Important notice:</h3>
Permalinks aren\'t enabled (Settings > Permalinks).<br />
Consider enable Permalinks or modify the main .htaccess to redirect all requests to be handled by WordPress, for instance:
<pre>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</pre></div>', 'sitemap_view_description' => 'Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site.<br /><br />
Web crawlers usually discover pages from links within the site and from other sites. Sitemaps supplement this data to allow crawlers that support Sitemaps to pick up all URLs in the Sitemap and learn about those URLs using the associated metadata. Using the Sitemap protocol does not guarantee that web pages are included in search engines, but provides hints for web crawlers to do a better job of crawling your site. <br/><br/>Remember to submit the XML Sitemap to the search engines.<br />
<a href="http://www.google.com/webmasters/tools/" target="_blank">Google Webmaster Tools</a><br />
<a href="http://www.bing.com/toolbox/webmaster/" target="_blank">Bing Webmaster Tools</a><br /><br />
The Sitemap could be added to the robots.txt file to allow search engines to auto descovery it.', 'sitemap_rule_exclude_target_title' => 'Exclude target', 'sitemap_rule_exclude_target_description' => 'Sets which kind of permalinks will be used to match the above exclusion rules against. If <em>Translated permalinks</em> is selected, and there are untranslated permalinks in the sitemap, then their original permalinks will be used.', 'sitemap_rule_source' => 'Original permalinks', 'sitemap_rule_target' => 'Translated permalinks', 'sitemap_rule_both' => 'Both', 'sitemap_rule_exclude_title' => 'Exclude URLs (regular expression)', 'sitemap_rule_exclude_description' => 'Defines a set of rules to exclude URLs from the sitemap. A rule consists of <a href="http://www.php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">a regular expression</a> to match the URL intended to exclude. <a href="http://www.vijayforvictory.com/wp-content/gallery/ngen_gallery/regular-expressions-cheat-sheet.png" target="_blank">Cheat sheet</a>.<br /><br />
One rule per line. For instance:<br /><br />
/posts\/.*/<br />
/tags\/.*/<br /><br />
Invalid rules will be silently ignored.', 'sitemap_rule_title' => 'Default entry settings', 'sitemap_rule_description' => 'Sets the default Frequency and Priority.<br />
Frequency: How frequently the page is likely to change.<br />
Priority: The priority of this URL relative to other URLs on the site.<br />
More information at <a href="http://www.sitemaps.org/protocol.html" target="_blank">http://www.sitemaps.org/protocol.html</a>
', 'sitemap_rule_changefreq_description' => 'Frecuency', 'sitemap_rule_priority_description' => 'Priority', 'sitemap_rule_exceptions_title' => 'Exceptions', 'sitemap_rule_exceptions_description' => 'Define a set of exceptions rules to override default entry settings. A rule must have the following form:<br /><br />
[expression],[frecuency],[priority],[date]<br /><br />
[expression]: <a href="http://www.php.net/manual/en/reference.pcre.pattern.syntax.php" target="_blank">A regular expression</a> to match the URL. <a href="http://www.vijayforvictory.com/wp-content/gallery/ngen_gallery/regular-expressions-cheat-sheet.png" target="_blank">Cheat sheet</a>.<br />
[frecuency]: always, hourly, daily, weekly, monthly, yearly or never.<br />
[priority]: A numeric value from 0 to 1.<br />
[date]: The date of last modification of the file. This date should be in <a href="http://www.w3.org/TR/NOTE-datetime" target="_blank">W3C Datetime</a> format. Optional.<br /><br />
One rule per line. For instance:<br /><br />
/posts\/.*/,daily,0.6,2014-08-10T12:51:10+00:00<br />
/tags\/.*/,monthly,0.3<br /><br />
Invalid rules will be silently ignored.', 'exclude_pages_title' => 'Pages', 'exclude_pages_description' => 'Selects the pages where the translator should not be displayed.', 'exclude_posts_title' => 'Posts', 'exclude_posts_description' => 'Selects the posts where the translator should not be displayed.', 'exclude_categories_title' => 'Categories', 'exclude_categories_description' => 'Selects the categories where the translator should not be displayed.', 'settings_access_title' => 'Grant access to edit settings', 'settings_access_description' => 'Selects a user to grant access to these settings.', 'version_title' => 'Version information', 'version_description' => '', 'version_current_message' => 'Installed version:', 'version_latest_message' => 'Latest available version:', 'version_button_1_message' => 'Check Version', 'version_button_2_message' => 'Update', 'version_whats_new_message' => 'What\'s new?', 'version_up_to_date_message' => 'The latest version of the plugin is already installed on this site.', 'version_update_message' => 'You\'re about to update the plugin. Do you want to continue?', 'import_all_title' => 'Import all', 'import_all_description' => 'Import a previously exported <em>xml</em> file containing all the settings and all the cached translations. Existent <em>xml</em> files containing cached translations won\'t be removed, they will be renamed instead.', 'import_all_upload' => 'File', 'import_all_select_button' => 'Select', 'import_all_upload_button' => 'Import all settings and translations', 'import_all_validate_xml_empty_message' => 'Empty file.', 'import_all_validate_xml_invalid_message' => 'The file is not a valid <em>xml</em> file or it\'s corrupted.', 'export_all_title' => 'Export all', 'export_all_description' => 'Exports a xml file containing all the settings and all the cached translations.', 'export_all_button' => 'Export all settings and translations', 'import_title' => 'Import settings', 'import_description' => 'Imports previously exported settings. Paste the previously exported settings in the field. If the data\'s structure is correct, it will overwrite the current settings.', 'export_title' => 'Export settings', 'export_description' => 'Exports the current settings to make a backup or to transfer the settings from the development server to the production server. Triple click on the field to select all the content.', 'translations_title' => 'Resource', 'translations_description' => 'Modifies cached translations.
<ol>
<li>Select the <div class="prisna_wp_translate_code_container"><code>Resource</code></div> to modify (only cached <div class="prisna_wp_translate_code_container"><code>Resources</code></div> will be listed).</li>
<li>Select an <div class="prisna_wp_translate_code_container"><code>Available language</code></div> (only cached <div class="prisna_wp_translate_code_container"><code>Languages</code></div> will be listed).</li>
<li>Modify <div class="prisna_wp_translate_code_container"><code>Cached translations</code></div> at will. In order to delete an entry, remove the content for that particular entry.</li>
</ol>', 'translations_import_title' => 'Import translations', 'translations_import_description' => 'Import translations from a po or csv formatted file. The file must be UTF-8 encoded.', 'translations_import_button_message' => 'Import', 'translations_import_upload' => 'CSV/PO file', 'translations_import_upload_button' => 'Select', 'translations_import_from' => 'From', 'translations_import_to' => 'To', 'translations_import_resource_title' => 'Resource', 'translations_import_resource_description' => '
Selects what resources will be affected by the current import operation.<br /><br />
There are 2 levels of cached translations. The translator first checks for the resource specific cache file, if the file exists, then it\'ll check if the requested translation has been made. If not, it\'ll check the Upcoming translations file. If the translation isn\'t there, then it\'ll contact the translation server.<br /><br />
The Upcoming translation files contains all the translations for all the pages for a specific pair of source and destination languages.
', 'translations_import_resource_all' => 'All', 'translations_import_resource_global' => 'Upcoming', 'translations_import_action_title' => 'Action', 'translations_import_action_description' => 'Sets what kind of operation will be performed during the import process.', 'translations_import_action_add_and_edit' => 'Add and replace', 'translations_import_action_add' => 'Add only', 'translations_import_action_edit' => 'Replace only', 'translations_import_test_title' => 'Simulate', 'translations_import_test_description' => 'Sets whether a simulation will be performed, or not.', 'translations_import_test_true' => 'Yes, perform a simulation, don\'t import anything', 'translations_import_test_false' => 'No, don\'t perform a simulation, import everything', 'translations_import_log_message' => 'Imported translations log', 'translations_import_validate_csv_empty_message' => 'Empty file', 'translations_import_validate_csv_invalid_message' => 'The file is not a valid po or comma-separated values (csv) file', 'translations_import_validate_language_empty_message' => 'Empty language', 'translations_import_resource_invalid_message' => 'Invalid resource', 'translations_import_action_invalid_message' => 'Invalid value', 'translations_import_test_invalid_message' => 'Invalid value', 'translations_import_no_import_message' => 'No translations have been imported', 'translations_import_log_added_message' => 'Added', 'translations_import_log_edited_message' => 'Replaced', 'translations_import_log_removed_message' => 'Removed', 'translations_import_log_omitted_message' => 'Omitted', 'translations_import_log_created_message' => 'File created', 'translations_import_log_created_yes_message' => 'Yes', 'translations_import_log_created_no_message' => 'No', 'translations_import_log_test_message' => 'This is a simulation, no changes have been made', 'file_upload_error_1' => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', 'file_upload_error_2' => 'The uploaded file exceeds the MAX_FILE_SIZE directive', 'file_upload_error_3' => 'The uploaded file was only partially uploaded', 'file_upload_error_4' => 'No file was uploaded', 'file_upload_error_6' => 'Missing a temporary folder', 'file_upload_error_7' => 'Failed to write file to disk', 'file_upload_error_8' => 'A PHP extension stopped the file upload', 'file_upload_error_99' => 'An unknown error occurred during the file upload', 'translations_export_title' => 'Export translations', 'translations_export_description' => 'Selects what resources, and their languages, to export. All the selected translations will be exported into one single csv file.', 'translations_export_button_message' => 'Export', 'translations_export_remove_button_message' => 'Remove', 'translations_export_remove_confirm_message' => 'All the cached translations for the selected Resource will be removed. This operation cannot be undone. Do you want to continue?', 'translations_export_global_message' => 'Upcoming', 'translations_export_empty_collection_message' => 'There are no cache files yet. Cached files will appear here either after translations are either made or imported.', 'seo_title' => 'Enable SEO', 'seo_description' => 'Sets whether the search engines can index the cached translations, or not.<br />Fairly valid HTML code is required. Fault pages won\'t be indexded.<br />Refer to the <a href="http://validator.w3.org/" target="_blank">Markup Validation Service</a> for a quick online check.<br /><br /><div class="prisna_wp_translate_code_container"><code>Only cached translations can be indexed.</code></div><br /><br />To translate pages\' titles, make sure to change the default value of the<br /><div class="prisna_wp_translate_code_container"><code>Target selector (jQuery)</code></div> setting to <div class="prisna_wp_translate_code_container"><code>html</code></div> or to <div class="prisna_wp_translate_code_container"><code>body, title</code></div>.<br /><br />See <div class="prisna_wp_translate_code_container"><code>General > Select and exclude sections > Target selector (jQuery)</code></div>.', 'seo_true' => 'Yes, enable SEO', 'seo_false' => 'No, disable SEO', 'export_empty' => 'No settings to export. The current settings are the default ones.', 'unit_entries' => 'entries', 'unit_requests' => 'requests', 'unit_languages' => 'languages', 'unit_pixels' => 'pixels', 'unit_percent' => '%', 'unit_step' => 'units', 'unit_days' => 'days', 'unit_ms' => 'milliseconds', 'changefreq_always' => 'Always', 'changefreq_hourly' => 'Hourly', 'changefreq_daily' => 'Daily', 'changefreq_weekly' => 'Weekly', 'changefreq_monthly' => 'Monthly', 'changefreq_yearly' => 'Yearly', 'changefreq_never' => 'Never', 'selector_heading_title' => 'Select and exclude sections', 'selector_heading_description' => '', 'display_heading_title' => 'Hide on pages, posts and categories', 'display_heading_description' => '', 'ui_heading_title' => 'Interface', 'ui_heading_description' => '', 'translate_attributes_heading_title' => 'Translate attributes', 'translate_attributes_heading_description' => '', 'custom_flags_heading_title' => 'Custom flags', 'custom_flags_heading_description' => '', 'cache_heading_title' => 'Local storage', 'cache_heading_description' => '', 'style_classes_heading_title' => 'Style classes', 'style_classes_heading_description' => '', 'templates_heading_title' => 'Templates', 'templates_heading_description' => '', 'callbacks_heading_title' => 'Javascript callbacks', 'callbacks_heading_description' => '', 'mutation_heading_title' => 'Page mutation', 'mutation_heading_description' => '', 'mutation_info_title' => 'Usage', 'mutation_target_title' => 'Target selector (jQuery)', 'mutation_target_description' => 'Specifies the areas that should be monitored for changes. In jQuery format. For more info, check the <a href="http://api.jquery.com/category/selectors/" target="_blank">jQuery selector guide</a>.', 'mutation_frequency_title' => 'Frequency', 'mutation_frequency_description' => 'Specifies the frequency, in milliseconds, of monitoring for changes in the above selected areas.', 'other_customizations_heading_title' => 'Other customizations', 'other_customizations_heading_description' => '', 'sitemap_view_title' => 'Access', 'sitemap_view_permalink_structure_empty_description' => '
<div class="prisna_wp_translate_permalink_structure_empty prisna_wp_translate_validate_warning">
<h3 class="prisna_wp_translate_validate_warning">Important notice:</h3>
Permalinks aren\'t enabled (Settings > Permalinks), make sure the above Sitemap URLs work.<br />
If they don\'t work, consider enable Permalinks or modify the main .htaccess to redirect all requests to be handled by WordPress, for instance:
<pre>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</pre></div>', 'sitemap_view_description' => 'Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site.<br /><br />
Web crawlers usually discover pages from links within the site and from other sites. Sitemaps supplement this data to allow crawlers that support Sitemaps to pick up all URLs in the Sitemap and learn about those URLs using the associated metadata. Using the Sitemap protocol does not guarantee that web pages are included in search engines, but provides hints for web crawlers to do a better job of crawling your site. <br/><br/>Remember to submit the XML Sitemap to the search engines.<br />
<a href="http://www.google.com/webmasters/tools/" target="_blank">Google Webmaster Tools</a><br />
<a href="http://www.bing.com/toolbox/webmaster/" target="_blank">Bing Webmaster Tools</a><br /><br />
The Sitemap could be added to the robots.txt file to allow search engines to auto descovery it.', 'submenu_page_general' => 'General', 'submenu_page_menus' => 'Menus (alias)', 'submenu_page_styles' => 'Styles', 'submenu_page_sliders' => 'Sliders', 'submenu_page_import_export' => 'Import / Export', 'key_not_found' => '<span style="color: red;">Message for "[0]" not found!</span>' ); public static function getDirect($_key, $_domain=null) { if (is_null($_domain)) $_domain = PrisnaWPTranslateConfig::getAdminLanguageDomain(); return __($_key, $_domain); } public static function genPo() { foreach (self::$_list as $key => $message) if ($message != '') { $translated = str_replace('\'', '\\\'', self::get($key, array(), null, true)); echo "echo _('$translated');\n"; } } public static function get($_key, $_new_values_array=array(), $_domain=null, $_mo=false) { if (is_null($_domain)) $_domain = PrisnaWPTranslateConfig::getAdminLanguageDomain(); if (!is_array($_new_values_array)) $_new_values_array = array($_new_values_array); if (array_key_exists($_key, self::$_list)) $result = is_array(self::$_list[$_key]) ? self::$_list[$_key][0] : self::$_list[$_key]; else $result = PrisnaWPTranslateCommon::mergeText(self::$_list['key_not_found'], $_key); $result = __($result, $_domain); if (count($_new_values_array) > 0) $result = PrisnaWPTranslateCommon::mergeText($result, $_new_values_array); if (array_key_exists($_key, self::$_list) && is_array(self::$_list[$_key])) { $params = self::$_list[$_key]; $params = array_splice($params, 1); $result = PrisnaWPTranslateCommon::mergeImages($result, $params, PRISNA_WP_TRANSLATE_IMAGES . '/admin/'); } return $result; } } ?><?php
class PrisnaWPTranslateConfig { const NAME = 'PrisnaWPTranslate'; const VERSION = '1.11'; const UI_NAME = 'Prisna Translate'; const UI_TRANSLATIONS_NAME = 'Translations for Prisna Translate'; const WIDGET_NAME = 'Prisna Translate'; const WIDGET_INTERNAL_NAME = 'prisna-wp-translate'; const ADMIN_LANGUAGE_DOMAIN = 'prisna_wp_translate'; const ADMIN_SETTINGS_NAME = 'prisna-translate-settings'; const ADMIN_TRANSLATIONS_NAME = 'prisna-translations'; const ADMIN_SETTINGS_IMPORT_EXPORT_NAME = 'prisna-translate-plugin-import-export-settings'; const SEO_REQUEST_PARAMETER_NAME = 'prisna_translate_seo_request'; const SITEMAP_NAME = 'prisna-wp-translate-sitemap'; const SITEMAP_FILENAME = 'sitemap-translate'; const SITEMAP_ID_NAME = 'sitemap_last_modified'; const DB_SETTINGS_NAME = 'prisna-wp-translate-settings'; const DB_CACHE_WRITABLE_FLAG_NAME = 'prisna-wp-translate-cache-validate'; protected static $_settings = null; public static function getTranslationsName() { return self::UI_TRANSLATIONS_NAME; } public static function getName($_to_lower=false, $_ui=false) { if ($_ui) return $_to_lower ? strtolower(self::UI_NAME) : self::UI_NAME; else return $_to_lower ? strtolower(self::NAME) : self::NAME; } public static function getWidgetName($_internal=false) { return $_internal ? self::WIDGET_INTERNAL_NAME : self::WIDGET_NAME; } public static function getVersion() { return self::VERSION; } public static function getAdminLanguageDomain() { return self::ADMIN_LANGUAGE_DOMAIN; } public static function getAdminPageTitle() { return PrisnaWPTranslateMessage::get('Plugin Settings', self::getName()); } public static function getTranslationsHandle() { return self::ADMIN_TRANSLATIONS_NAME; } public static function getAdminHandle() { return self::ADMIN_SETTINGS_NAME; } public static function getSitemapHandle() { return self::SITEMAP_NAME; } public static function getSitemapIdName() { return self::SITEMAP_ID_NAME; } public static function getSitemapFilename() { return self::SITEMAP_FILENAME; } public static function getSeoParameterName() { return self::SEO_REQUEST_PARAMETER_NAME; } public static function getAdminImportExportHandle() { return self::ADMIN_SETTINGS_IMPORT_EXPORT_NAME; } public static function getDbCacheWritableName() { return self::DB_CACHE_WRITABLE_FLAG_NAME; } public static function getDbSettingsName() { return self::DB_SETTINGS_NAME; } public static function setCacheFlag($_value) { $name = PrisnaWPTranslateConfig::getDbCacheWritableName(); $value = $_value ? 'true' : 'false'; if (!get_option($name)) add_option($name, $value); else update_option($name, $value); } public static function getCacheFlag() { $option = get_option(PrisnaWPTranslateConfig::getDbCacheWritableName()); if (!$option) return false; return $option == 'true'; } public static function _get_settings() { $option = get_option(PrisnaWPTranslateConfig::getDbSettingsName()); return !$option ? array() : $option; } public static function getSettings($_force=false, $_direct=false) { if (is_array(self::$_settings) && $_force == false) return self::$_settings; $current = self::_get_settings(); if ($_direct) return $current; $defaults = self::getDefaults(); $result = PrisnaWPTranslateCommon::mergeArrays($defaults, $current); $result = self::_adjust_languages($result, $current); return self::$_settings = $result; } protected static function _adjust_languages($_settings, $_current) { $result = $_settings; if (array_key_exists('languages', $_current)) $result['languages']['value'] = $_current['languages']['value']; return $result; } public static function getSetting($_name, $_force=false) { $settings = self::getSettings($_force); return array_key_exists($_name, $settings) ? $settings[$_name] : null; } protected static function _compare_settings($_id, $_setting_1, $_setting_2) { if (PrisnaWPTranslateCommon::endsWith($_id, '_template') || PrisnaWPTranslateCommon::endsWith($_id, '_template_dd')) return PrisnaWPTranslateCommon::stripBreakLinesAndTabs($_setting_1['value']) == PrisnaWPTranslateCommon::stripBreakLinesAndTabs($_setting_2['value']); if ($_id == 'override') if ($_setting_1['value'] != $_setting_2['value'] && PrisnaWPTranslateValidator::isEmpty($_setting_1['value'])) return true; if ($_id == 'languages') return $_setting_1['value'] === $_setting_2['value']; return $_setting_1['value'] == $_setting_2['value']; } public static function getSettingsValuesForExport() { return self::_get_settings_values_for_export(); } protected static function _get_settings_values_for_export() { $settings = self::_get_settings(); return count($settings) > 0 ? base64_encode(serialize($settings)) : PrisnaWPTranslateMessage::get('export_empty'); } public static function getSettingsValues($_force=false, $_new=true) { $result = array(); $settings = self::getSettings($_force); $defaults = self::getDefaults(); foreach ($settings as $key => $setting) { if (!array_key_exists($key, $defaults)) continue; if ($_new == false || !self::_compare_settings($key, $setting, $defaults[$key])) { $result[$key] = array( 'value' => $setting['value'], 'option_id' => array_key_exists('option_id', $setting) ? $setting['option_id'] : null ); } } return $result; } public static function getSettingValue($_name, $_force=false) { $setting = self::getSetting($_name, $_force); if (is_null($setting)) return null; $result = $setting['value']; if (PrisnaWPTranslateValidator::isBool($result) && $_name != 'location_widget') $result = $result == 'true' || $result === true; return $result; } public static function getDefaults($_force=false) { $settings = self::_get_settings(); $layout = array_key_exists('layout', $settings) ? $settings['layout']['value'] : 'bar'; $test_mode = array_key_exists('test_mode', $settings) ? $settings['test_mode']['value'] : 'false'; $result = array( 'layout' => array( 'title_message' => PrisnaWPTranslateMessage::get('layout_title'), 'id' => 'prisna_layout', 'values' => array( 'dropdown' => PRISNA_WP_TRANSLATE_IMAGES . '/admin/sample_dropdown.png', 'bar' => PRISNA_WP_TRANSLATE_IMAGES . '/admin/sample_bar.png' ), 'value' => 'bar', 'type' => 'visual', 'col_count' => 2, 'group' => 0 ), 'size' => array( 'title_message' => PrisnaWPTranslateMessage::get('size_title'), 'id' => 'prisna_size', 'option_id' => 'size', 'values' => array( 's' => PRISNA_WP_TRANSLATE_IMAGES . '/admin/size_s.png', 'm' => PRISNA_WP_TRANSLATE_IMAGES . '/admin/size_m.png', 'l' => PRISNA_WP_TRANSLATE_IMAGES . '/admin/size_l.png', 'xl' => PRISNA_WP_TRANSLATE_IMAGES . '/admin/size_xl.png' ), 'value' => 'm', 'type' => 'visual', 'col_count' => 4, 'group' => 0 ), 'api_key' => array( 'title_message' => PrisnaWPTranslateMessage::get('api_key_title'), 'description_message' => PrisnaWPTranslateMessage::get('api_key_description'), 'test_message' => PrisnaWPTranslateMessage::get('api_key_test_validate', $test_mode != 'true' ? PrisnaWPTranslateMessage::get('api_key_test_validate_extra') : ''), 'validate_message' => PrisnaWPTranslateMessage::get('api_key_validate', PrisnaWPTranslateCommon::getTestApiKey()), 'empty_validate_message' => PrisnaWPTranslateMessage::get('api_key_empty_validate', PrisnaWPTranslateCommon::getTestApiKey()), 'id' => 'prisna_api_key', 'type' => 'key', 'value' => '', 'group' => 1 ), 'from' => array( 'title_message' => PrisnaWPTranslateMessage::get('from_title'), 'description_message' => PrisnaWPTranslateMessage::get('from_description'), 'id' => 'prisna_from', 'option_id' => 'from', 'type' => 'select', 'values' => PrisnaWPTranslateCommon::getLanguages(), 'value' => 'en', 'group' => 1 ), 'languages' => array( 'title_message' => PrisnaWPTranslateMessage::get('languages_title'), 'description_message' => PrisnaWPTranslateMessage::get('languages_description'), 'title_order_message' => PrisnaWPTranslateMessage::get('languages_order_title'), 'description_order_message' => PrisnaWPTranslateMessage::get('languages_order_description'), 'id' => 'prisna_languages', 'option_id' => 'languages', 'values' => PrisnaWPTranslateCommon::getLanguages(), 'value' => array('en', 'es', 'fr', 'de', 'da', 'ja', 'it', 'pt'), 'type' => 'language', 'enable_order' => true, 'columns' => 4, 'group' => 1 ), 'native_languages' => array( 'title_message' => PrisnaWPTranslateMessage::get('native_languages_title'), 'description_message' => PrisnaWPTranslateMessage::get('native_languages_description'), 'id' => 'prisna_native_languages', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('native_languages_true'), 'false' => PrisnaWPTranslateMessage::get('native_languages_false') ), 'group' => 1 ), 'ui_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('ui_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('ui_heading_description'), 'value' => 'false', 'id' => 'prisna_ui_heading', 'type' => 'heading', 'group' => 1 ) ); self::_add_fields($result, array( 'scroll' => array( 'title_message' => PrisnaWPTranslateMessage::get('scroll_title'), 'description_message' => PrisnaWPTranslateMessage::get('scroll_description'), 'id' => 'prisna_scroll', 'option_id' => 'scroll', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('scroll_true'), 'false' => PrisnaWPTranslateMessage::get('scroll_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'scroll_bar_languages' => array( 'title_message' => PrisnaWPTranslateMessage::get('scroll_bar_languages_title'), 'description_message' => PrisnaWPTranslateMessage::get('scroll_bar_languages_description'), 'min' => '1', 'max' => '37', 'step' => '1', 'unit' => PrisnaWPTranslateMessage::get('unit_languages'), 'id' => 'prisna_scroll_bar_languages', 'option_id' => 'scrollBarLanguages', 'value' => '5', 'type' => 'range', 'dependence' => array('ui_heading', 'scroll'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ), 'scroll_bar_width' => array( 'title_message' => PrisnaWPTranslateMessage::get('scroll_bar_width_title'), 'description_message' => PrisnaWPTranslateMessage::get('scroll_bar_width_description'), 'min' => '1', 'max' => '20', 'step' => '1', 'unit' => PrisnaWPTranslateMessage::get('unit_pixels'), 'id' => 'prisna_scroll_bar_width', 'option_id' => 'scrollBarWidth', 'value' => '5', 'type' => 'range', 'dependence' => array('ui_heading', 'scroll'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ), 'scroll_bar_opacity' => array( 'title_message' => PrisnaWPTranslateMessage::get('scroll_bar_opacity_title'), 'description_message' => PrisnaWPTranslateMessage::get('scroll_bar_opacity_description'), 'min' => '0', 'max' => '100', 'step' => '5', 'unit' => PrisnaWPTranslateMessage::get('unit_percent'), 'id' => 'prisna_scroll_bar_opacity', 'option_id' => 'scrollBarOpacity', 'value' => '40', 'type' => 'range', 'dependence' => array('ui_heading', 'scroll'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ), 'scroll_bar_wheel_step' => array( 'title_message' => PrisnaWPTranslateMessage::get('scroll_bar_wheel_step_title'), 'description_message' => PrisnaWPTranslateMessage::get('scroll_bar_wheel_step_description'), 'min' => '1', 'max' => '30', 'step' => '1', 'unit' => PrisnaWPTranslateMessage::get('unit_step'), 'id' => 'prisna_scroll_bar_wheel_step', 'option_id' => 'scrollBarWheelStep', 'value' => '10', 'type' => 'range', 'dependence' => array('ui_heading', 'scroll'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ), 'align_mode_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('align_mode_title'), 'description_message' => PrisnaWPTranslateMessage::get('align_mode_description'), 'id' => 'prisna_align_mode_dd', 'option_id' => 'alignMode', 'type' => 'radio', 'value' => 'left', 'values' => array( 'left' => PrisnaWPTranslateMessage::get('align_mode_left'), 'right' => PrisnaWPTranslateMessage::get('align_mode_right') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'hide_selected_language_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('hide_selected_language_title'), 'description_message' => PrisnaWPTranslateMessage::get('hide_selected_language_description'), 'id' => 'prisna_hide_selected_language_dd', 'option_id' => 'hideSelectedLanguage', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('hide_selected_language_true'), 'false' => PrisnaWPTranslateMessage::get('hide_selected_language_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ) ), $layout, 'dropdown', $_force); self::_add_fields($result, array( 'corners' => array( 'title_message' => PrisnaWPTranslateMessage::get('corners_title'), 'description_message' => PrisnaWPTranslateMessage::get('corners_description'), 'id' => 'prisna_corners', 'option_id' => 'corners', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('corners_true'), 'false' => PrisnaWPTranslateMessage::get('corners_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'align_mode' => array( 'title_message' => PrisnaWPTranslateMessage::get('align_mode_title'), 'description_message' => PrisnaWPTranslateMessage::get('align_mode_description'), 'id' => 'prisna_align_mode', 'option_id' => 'alignMode', 'type' => 'radio', 'value' => 'center', 'values' => array( 'left' => PrisnaWPTranslateMessage::get('align_mode_left'), 'center' => PrisnaWPTranslateMessage::get('align_mode_center'), 'right' => PrisnaWPTranslateMessage::get('align_mode_right') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'cookie' => array( 'title_message' => PrisnaWPTranslateMessage::get('cookie_title'), 'description_message' => PrisnaWPTranslateMessage::get('cookie_description'), 'id' => 'prisna_cookie', 'option_id' => 'cookie', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('cookie_true'), 'false' => PrisnaWPTranslateMessage::get('cookie_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'cookie_persistency' => array( 'title_message' => PrisnaWPTranslateMessage::get('cookie_persistency_title'), 'description_message' => PrisnaWPTranslateMessage::get('cookie_persistency_description'), 'id' => 'prisna_cookie_persistency', 'option_id' => 'cookiePersistency', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('cookie_persistency_true'), 'false' => PrisnaWPTranslateMessage::get('cookie_persistency_false') ), 'dependence' => array('ui_heading', 'cookie'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ), 'flags' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_description'), 'id' => 'prisna_flags', 'option_id' => 'flags', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('flags_true'), 'false' => PrisnaWPTranslateMessage::get('flags_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'names' => array( 'title_message' => PrisnaWPTranslateMessage::get('names_title'), 'description_message' => PrisnaWPTranslateMessage::get('names_description'), 'id' => 'prisna_names', 'option_id' => 'names', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('names_true'), 'false' => PrisnaWPTranslateMessage::get('names_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'short_names' => array( 'title_message' => PrisnaWPTranslateMessage::get('short_names_title'), 'description_message' => PrisnaWPTranslateMessage::get('short_names_description'), 'id' => 'prisna_short_names', 'option_id' => 'shortNames', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('short_names_true'), 'false' => PrisnaWPTranslateMessage::get('short_names_false') ), 'dependence' => array('ui_heading', 'names'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ), 'loading' => array( 'title_message' => PrisnaWPTranslateMessage::get('loading_title'), 'description_message' => PrisnaWPTranslateMessage::get('loading_description'), 'id' => 'prisna_loading', 'option_id' => 'loading', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('loading_true'), 'false' => PrisnaWPTranslateMessage::get('loading_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ) )); self::_add_fields($result, array( 'complete_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('complete_dd_title'), 'description_message' => PrisnaWPTranslateMessage::get('complete_dd_description'), 'id' => 'prisna_complete_dd', 'option_id' => 'complete', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('complete_dd_true'), 'false' => PrisnaWPTranslateMessage::get('complete_dd_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'auto_select_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('auto_select_dd_title'), 'description_message' => PrisnaWPTranslateMessage::get('auto_select_dd_description'), 'id' => 'prisna_auto_select_dd', 'option_id' => 'autoSelect', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('auto_select_dd_true'), 'false' => PrisnaWPTranslateMessage::get('auto_select_dd_false') ), 'dependence' => array('ui_heading', 'complete_dd'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ), ), $layout, 'dropdown', $_force); self::_add_fields($result, array( 'restore' => array( 'title_message' => PrisnaWPTranslateMessage::get('restore_title'), 'description_message' => PrisnaWPTranslateMessage::get('restore_description'), 'id' => 'prisna_restore', 'option_id' => 'restore', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('restore_true'), 'false' => PrisnaWPTranslateMessage::get('restore_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'complete' => array( 'title_message' => PrisnaWPTranslateMessage::get('complete_title'), 'description_message' => PrisnaWPTranslateMessage::get('complete_description'), 'id' => 'prisna_complete', 'option_id' => 'complete', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('complete_true'), 'false' => PrisnaWPTranslateMessage::get('complete_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'auto_select' => array( 'title_message' => PrisnaWPTranslateMessage::get('auto_select_title'), 'description_message' => PrisnaWPTranslateMessage::get('auto_select_description'), 'id' => 'prisna_auto_select', 'option_id' => 'autoSelect', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('auto_select_true'), 'false' => PrisnaWPTranslateMessage::get('auto_select_false') ), 'dependence' => array('ui_heading', 'complete'), 'dependence_show_value' => array('true', 'true'), 'group' => 1 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'selector_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('selector_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('selector_heading_description'), 'value' => 'false', 'id' => 'prisna_selector_heading', 'type' => 'heading', 'group' => 1 ), 'target_selector' => array( 'title_message' => PrisnaWPTranslateMessage::get('target_selector_title'), 'description_message' => PrisnaWPTranslateMessage::get('target_selector_description'), 'id' => 'prisna_target_selector', 'option_id' => 'targetSelector', 'type' => 'text', 'value' => 'body', 'dependence' => 'selector_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'exclude_selector' => array( 'title_message' => PrisnaWPTranslateMessage::get('exclude_selector_title'), 'description_message' => PrisnaWPTranslateMessage::get('exclude_selector_description'), 'id' => 'prisna_exclude_selector', 'option_id' => 'excludeSelector', 'type' => 'text', 'value' => '#wpadminbar, code, input:hidden, .do-not-translate-me, .dont-translate', 'dependence' => 'selector_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'exclude_words_rules' => array( 'title_message' => PrisnaWPTranslateMessage::get('exclude_words_rules_title'), 'description_message' => PrisnaWPTranslateMessage::get('exclude_words_rules_description'), 'id' => 'prisna_exclude_words_rules', 'type' => 'textarea', 'value' => '', 'dependence' => 'selector_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'display_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('display_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('display_heading_description'), 'value' => 'false', 'id' => 'prisna_display_heading', 'type' => 'heading', 'group' => 1 ), 'exclude_pages' => array( 'title_message' => PrisnaWPTranslateMessage::get('exclude_pages_title'), 'description_message' => PrisnaWPTranslateMessage::get('exclude_pages_description'), 'id' => 'prisna_exclude_pages', 'value' => array(''), 'type' => 'expage', 'dependence' => 'display_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'exclude_posts' => array( 'title_message' => PrisnaWPTranslateMessage::get('exclude_posts_title'), 'description_message' => PrisnaWPTranslateMessage::get('exclude_posts_description'), 'id' => 'prisna_exclude_posts', 'value' => array(''), 'type' => 'expost', 'dependence' => 'display_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'exclude_categories' => array( 'title_message' => PrisnaWPTranslateMessage::get('exclude_categories_title'), 'description_message' => PrisnaWPTranslateMessage::get('exclude_categories_description'), 'id' => 'prisna_exclude_categories', 'value' => array(''), 'type' => 'excategory', 'dependence' => 'display_heading', 'dependence_show_value' => 'true', 'group' => 1 ), 'test_mode' => array( 'title_message' => PrisnaWPTranslateMessage::get('test_mode_title'), 'description_message' => PrisnaWPTranslateMessage::get('test_mode_description'), 'id' => 'prisna_test_mode', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('test_mode_true'), 'false' => PrisnaWPTranslateMessage::get('test_mode_false') ), 'group' => 2 ) )); self::_add_fields($result, array( 'location_widget' => array( 'title_message' => PrisnaWPTranslateMessage::get('location_widget_title'), 'description_message' => PrisnaWPTranslateMessage::get('location_widget_description'), 'id' => 'prisna_location_widget', 'option_id' => 'locationWidget', 'type' => 'radio', 'value' => 'top', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('location_widget_true', PrisnaWPTranslateCommon::getAdminWidgetsUrl()), 'false' => PrisnaWPTranslateMessage::get('location_widget_false'), 'xy' => PrisnaWPTranslateMessage::get('location_widget_xy'), 'top' => PrisnaWPTranslateMessage::get('location_widget_top') ), 'group' => 2 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'location_widget' => array( 'title_message' => PrisnaWPTranslateMessage::get('location_widget_title'), 'description_message' => PrisnaWPTranslateMessage::get('location_widget_description'), 'id' => 'prisna_location_widget', 'option_id' => 'locationWidget', 'type' => 'radio', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('location_widget_true', array(PrisnaWPTranslateCommon::getAdminWidgetsUrl())), 'false' => PrisnaWPTranslateMessage::get('location_widget_false'), 'xy' => PrisnaWPTranslateMessage::get('location_widget_xy') ), 'group' => 2 ) ), $layout, 'dropdown', $_force); self::_add_fields($result, array( 'location_custom' => array( 'title_message' => PrisnaWPTranslateMessage::get('location_custom_title'), 'description_message' => PrisnaWPTranslateMessage::get('location_custom_description'), 'id' => 'prisna_location_custom', 'option_id' => 'location', 'type' => 'text', 'value' => '', 'dependence' => 'location_widget', 'dependence_show_value' => 'false', 'group' => 2 ), 'custom_location_insert_mode' => array( 'title_message' => PrisnaWPTranslateMessage::get('custom_location_insert_mode_title'), 'description_message' => PrisnaWPTranslateMessage::get('custom_location_insert_mode_description'), 'id' => 'prisna_custom_location_insert_mode', 'option_id' => 'customLocationAppendMode', 'type' => 'select', 'values' => array( 'append' => 'Append', 'prepend' => 'Prepend', 'before' => 'Insert before', 'after' => 'Insert after' ), 'value' => 'append', 'dependence' => 'location_widget', 'dependence_show_value' => 'false', 'group' => 2 ) )); self::_add_fields($result, array( 'custom_parent' => array( 'title_message' => PrisnaWPTranslateMessage::get('custom_parent_title'), 'description_message' => PrisnaWPTranslateMessage::get('custom_parent_description'), 'id' => 'prisna_custom_parent', 'option_id' => 'customParent', 'type' => 'select', 'values' => array( '' => '', 'div' => 'div', 'span' => 'span', 'li' => 'li', 'ul-li' => 'ul > li', 'ol-li' => 'ol > li', 'td' => 'td', 'tr-td' => 'tr > td', 'table-tr-td' => 'table > tr > td' ), 'value' => '', 'dependence' => 'location_widget', 'dependence_show_value' => 'false', 'group' => 2 ), 'xy_vertical' => array( 'title_message' => PrisnaWPTranslateMessage::get('xy_vertical_title'), 'description_message' => PrisnaWPTranslateMessage::get('xy_vertical_description'), 'id' => 'prisna_xy_vertical', 'type' => 'position', 'value' => array( 'kind' => '', 'position' => '', 'unit' => '' ), 'values_kind' => array( '' => '', 'top' => PrisnaWPTranslateMessage::get('xy_vertical_top'), 'bottom' => PrisnaWPTranslateMessage::get('xy_vertical_bottom') ), 'values_unit' => array( '' => '', 'px' => 'px', 'em' => 'em', '%' => '%', 'auto' => 'auto', 'inherit' => 'inherit' ), 'dependence' => 'location_widget', 'dependence_show_value' => 'xy', 'group' => 2 ), 'xy_horizontal' => array( 'title_message' => PrisnaWPTranslateMessage::get('xy_horizontal_title'), 'description_message' => PrisnaWPTranslateMessage::get('xy_horizontal_description'), 'id' => 'prisna_xy_horizontal', 'type' => 'position', 'value' => array( 'kind' => '', 'position' => '', 'unit' => '' ), 'values_kind' => array( '' => '', 'left' => PrisnaWPTranslateMessage::get('xy_horizontal_left'), 'right' => PrisnaWPTranslateMessage::get('xy_horizontal_right') ), 'values_unit' => array( '' => '', 'px' => 'px', 'em' => 'em', '%' => '%', 'auto' => 'auto', 'inherit' => 'inherit' ), 'dependence' => 'location_widget', 'dependence_show_value' => 'xy', 'group' => 2 ), 'sticky' => array( 'title_message' => PrisnaWPTranslateMessage::get('sticky_title'), 'description_message' => PrisnaWPTranslateMessage::get('sticky_description'), 'id' => 'prisna_sticky', 'option_id' => 'sticky', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('sticky_true'), 'false' => PrisnaWPTranslateMessage::get('sticky_false') ), 'dependence' => array('location_widget', 'location_widget'), 'dependence_show_value' => array('top', 'xy'), 'group' => 2 ), 'xy_parent' => array( 'title_message' => PrisnaWPTranslateMessage::get('xy_parent_title'), 'description_message' => PrisnaWPTranslateMessage::get('xy_parent_description'), 'id' => 'prisna_xy_parent', 'option_id' => 'xyParent', 'type' => 'text', 'value' => 'body', 'dependence' => 'location_widget', 'dependence_show_value' => 'xy', 'group' => 2 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'custom_parent' => array( 'title_message' => PrisnaWPTranslateMessage::get('custom_parent_title'), 'description_message' => PrisnaWPTranslateMessage::get('custom_parent_description'), 'id' => 'prisna_custom_parent', 'option_id' => 'customParent', 'type' => 'select', 'values' => array( '' => '', 'div' => 'div', 'span' => 'span', 'li' => 'li', 'ul-li' => 'ul > li', 'ol-li' => 'ol > li', 'td' => 'td', 'tr-td' => 'tr > td', 'table-tr-td' => 'table > tr > td' ), 'value' => '', 'dependence' => 'location_widget', 'dependence_show_value' => 'false', 'group' => 2 ), 'xy_vertical' => array( 'title_message' => PrisnaWPTranslateMessage::get('xy_vertical_title'), 'description_message' => PrisnaWPTranslateMessage::get('xy_vertical_description'), 'id' => 'prisna_xy_vertical', 'type' => 'position', 'value' => array( 'kind' => '', 'position' => '', 'unit' => '' ), 'values_kind' => array( '' => '', 'top' => PrisnaWPTranslateMessage::get('xy_vertical_top'), 'bottom' => PrisnaWPTranslateMessage::get('xy_vertical_bottom') ), 'values_unit' => array( '' => '', 'px' => 'px', 'em' => 'em', '%' => '%', 'auto' => 'auto', 'inherit' => 'inherit' ), 'dependence' => 'location_widget', 'dependence_show_value' => 'xy', 'group' => 2 ), 'xy_horizontal' => array( 'title_message' => PrisnaWPTranslateMessage::get('xy_horizontal_title'), 'description_message' => PrisnaWPTranslateMessage::get('xy_horizontal_description'), 'id' => 'prisna_xy_horizontal', 'type' => 'position', 'value' => array( 'kind' => '', 'position' => '', 'unit' => '' ), 'values_kind' => array( '' => '', 'left' => PrisnaWPTranslateMessage::get('xy_horizontal_left'), 'right' => PrisnaWPTranslateMessage::get('xy_horizontal_right') ), 'values_unit' => array( '' => '', 'px' => 'px', 'em' => 'em', '%' => '%', 'auto' => 'auto', 'inherit' => 'inherit' ), 'dependence' => 'location_widget', 'dependence_show_value' => 'xy', 'group' => 2 ), 'sticky' => array( 'title_message' => PrisnaWPTranslateMessage::get('sticky_title'), 'description_message' => PrisnaWPTranslateMessage::get('sticky_description'), 'id' => 'prisna_sticky', 'option_id' => 'sticky', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('sticky_true'), 'false' => PrisnaWPTranslateMessage::get('sticky_false') ), 'dependence' => 'location_widget', 'dependence_show_value' => 'xy', 'group' => 2 ), 'xy_parent' => array( 'title_message' => PrisnaWPTranslateMessage::get('xy_parent_title'), 'description_message' => PrisnaWPTranslateMessage::get('xy_parent_description'), 'id' => 'prisna_xy_parent', 'option_id' => 'xyParent', 'type' => 'text', 'value' => 'body', 'dependence' => 'location_widget', 'dependence_show_value' => 'xy', 'group' => 2 ) ), $layout, 'dropdown', $_force); self::_add_fields($result, array( 'shortcode' => array( 'title_message' => PrisnaWPTranslateMessage::get('shortcode_title'), 'description_message' => PrisnaWPTranslateMessage::get('shortcode_description'), 'id' => 'prisna_shortcode', 'type' => 'info', 'value' => '
<img src="' . PRISNA_WP_TRANSLATE_IMAGES . '/admin/shortcode.png" /><br />
- Or copy and paste the following code into pages, posts, etc...<br /><br />
<code>[prisna-wp-translate]</code><br /><br />
- Or copy and paste the following code into any front-end PHP file<br /><br />
<code><?php echo function_exists(\'do_shortcode\') ? do_shortcode(\'[prisna-wp-translate]\') : \'This is not a front-end file\'; ?></code><br />', 'dependence' => array('location_widget', 'location_widget'), 'dependence_show_value' => array('true', 'shortcode'), 'group' => 2 ), 'custom_css' => array( 'title_message' => PrisnaWPTranslateMessage::get('custom_css_title'), 'description_message' => PrisnaWPTranslateMessage::get('custom_css_description'), 'id' => 'prisna_custom_css', 'type' => 'textarea', 'value' => '', 'group' => 2 ), 'translate_attributes_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('translate_attributes_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('translate_attributes_heading_description'), 'value' => 'false', 'id' => 'prisna_translate_attributes_heading', 'type' => 'heading', 'group' => 2 ), 'translate_attributes' => array( 'title_message' => PrisnaWPTranslateMessage::get('translate_attributes_title'), 'description_message' => PrisnaWPTranslateMessage::get('translate_attributes_description'), 'id' => 'prisna_translate_attributes', 'option_id' => 'translateAttributes', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('translate_attributes_true'), 'false' => PrisnaWPTranslateMessage::get('translate_attributes_false') ), 'dependence' => 'translate_attributes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'translate_title_attribute' => array( 'title_message' => PrisnaWPTranslateMessage::get('translate_title_attribute_title'), 'description_message' => PrisnaWPTranslateMessage::get('translate_title_attribute_description'), 'id' => 'prisna_translate_title_attribute', 'option_id' => 'translateTitleAttribute', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('translate_title_attribute_true'), 'false' => PrisnaWPTranslateMessage::get('translate_title_attribute_false') ), 'dependence' => array('translate_attributes_heading', 'translate_attributes'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'translate_alt_attribute' => array( 'title_message' => PrisnaWPTranslateMessage::get('translate_alt_attribute_title'), 'description_message' => PrisnaWPTranslateMessage::get('translate_alt_attribute_description'), 'id' => 'prisna_translate_alt_attribute', 'option_id' => 'translateAltAttribute', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('translate_alt_attribute_true'), 'false' => PrisnaWPTranslateMessage::get('translate_alt_attribute_false') ), 'dependence' => array('translate_attributes_heading', 'translate_attributes'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'translate_placeholder_attribute' => array( 'title_message' => PrisnaWPTranslateMessage::get('translate_placeholder_attribute_title'), 'description_message' => PrisnaWPTranslateMessage::get('translate_placeholder_attribute_description'), 'id' => 'prisna_translate_placeholder_attribute', 'option_id' => 'translatePlaceholderAttribute', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('translate_placeholder_attribute_true'), 'false' => PrisnaWPTranslateMessage::get('translate_placeholder_attribute_false') ), 'dependence' => array('translate_attributes_heading', 'translate_attributes'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'translate_meta_tags' => array( 'title_message' => PrisnaWPTranslateMessage::get('translate_meta_tags_title'), 'description_message' => PrisnaWPTranslateMessage::get('translate_meta_tags_description'), 'id' => 'prisna_translate_meta_tags', 'option_id' => 'translateMetaTags', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('translate_meta_tags_true'), 'false' => PrisnaWPTranslateMessage::get('translate_meta_tags_false') ), 'dependence' => 'translate_attributes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'translate_meta_tags_names' => array( 'title_message' => PrisnaWPTranslateMessage::get('translate_meta_tags_names_title'), 'description_message' => PrisnaWPTranslateMessage::get('translate_meta_tags_names_description'), 'id' => 'prisna_translate_meta_tags_names', 'type' => 'text', 'value' => 'keywords,description,og:title,og:description,og:locale,og:url', 'dependence' => array('translate_attributes_heading', 'translate_meta_tags'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'custom_flags_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('custom_flags_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('custom_flags_heading_description'), 'value' => 'false', 'id' => 'prisna_custom_flags_heading', 'type' => 'heading', 'group' => 2 ), 'custom_flags' => array( 'title_message' => PrisnaWPTranslateMessage::get('custom_flags_title'), 'description_message' => PrisnaWPTranslateMessage::get('custom_flags_description'), 'add_message' => PrisnaWPTranslateMessage::get('custom_flags_add'), 'id' => 'prisna_custom_flags', 'option_id' => 'customFlags', 'value' => '', 'type' => 'flag', 'dependence' => 'custom_flags_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'cache_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('cache_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('cache_heading_description'), 'value' => 'false', 'id' => 'prisna_cache_heading', 'type' => 'heading', 'group' => 2 ), 'local_storage' => array( 'title_message' => PrisnaWPTranslateMessage::get('local_storage_title'), 'description_message' => PrisnaWPTranslateMessage::get('local_storage_description'), 'id' => 'prisna_local_storage', 'option_id' => 'localStorage', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('local_storage_true'), 'false' => PrisnaWPTranslateMessage::get('local_storage_false') ), 'dependence' => 'cache_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'local_storage_expires' => array( 'title_message' => PrisnaWPTranslateMessage::get('local_storage_expires_title'), 'description_message' => PrisnaWPTranslateMessage::get('local_storage_expires_description'), 'min' => '1', 'max' => '365', 'step' => '1', 'unit' => PrisnaWPTranslateMessage::get('unit_days'), 'id' => 'prisna_local_storage_expires', 'option_id' => 'localStorageExpires', 'value' => '30', 'type' => 'range', 'dependence' => array('cache_heading', 'local_storage'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'clear_local_storage' => array( 'title_message' => PrisnaWPTranslateMessage::get('clear_local_storage_title'), 'description_message' => PrisnaWPTranslateMessage::get('clear_local_storage_description'), 'id' => 'prisna_clear_local_storage', 'option_id' => 'clearLocalStorage', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('clear_local_storage_true'), 'false' => PrisnaWPTranslateMessage::get('clear_local_storage_false') ), 'dependence' => array('cache_heading', 'local_storage'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'style_classes_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('style_classes_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('style_classes_heading_description'), 'value' => 'false', 'id' => 'prisna_style_classes_heading', 'type' => 'heading', 'group' => 2 ) )); self::_add_fields($result, array( 'container_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('container_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('container_class_description'), 'id' => 'prisna_container_class', 'option_id' => 'containerClass', 'type' => 'text', 'value' => 'prisna-wp-translate-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'container_custom_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('container_custom_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('container_custom_class_description'), 'id' => 'prisna_container_custom_class', 'option_id' => 'containerCustomClass', 'type' => 'text', 'value' => 'prisna-wp-translate-container-custom', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'container_xy_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('container_xy_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('container_xy_class_description'), 'id' => 'prisna_container_xy_class', 'option_id' => 'containerXYClass', 'type' => 'text', 'value' => 'prisna-wp-translate-container-fixed', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'rtl_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('rtl_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('rtl_class_description'), 'id' => 'prisna_rtl_class', 'option_id' => 'rtlClass', 'type' => 'text', 'value' => 'prisna-wp-translate-rtl', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'sub_container_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('sub_container_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('sub_container_class_description'), 'id' => 'prisna_sub_container_class', 'option_id' => 'subContainerClass', 'type' => 'text', 'value' => 'prisna-wp-translate-sub-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'loading_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('loading_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('loading_class_description'), 'id' => 'prisna_loading_class', 'option_id' => 'loadingClass', 'type' => 'text', 'value' => 'prisna-wp-translate-loading-left', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'completed_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('completed_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('completed_class_description'), 'id' => 'prisna_completed_class', 'option_id' => 'completedClass', 'type' => 'text', 'value' => 'prisna-wp-translate-completed-left', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'sticky_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('sticky_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('sticky_class_description'), 'id' => 'prisna_sticky_class', 'option_id' => 'stickyClass', 'type' => 'text', 'value' => 'prisna-wp-translate-sticky', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'restore_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('restore_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('restore_class_description'), 'id' => 'prisna_restore_class', 'option_id' => 'restoreClass', 'type' => 'text', 'value' => 'prisna-wp-translate-restore', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'restore_container_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('restore_container_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('restore_container_class_description'), 'id' => 'prisna_restore_container_class', 'option_id' => 'restoreContainerClass', 'type' => 'text', 'value' => 'prisna-wp-translate-restore-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'align_left_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('align_left_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('align_left_class_description'), 'id' => 'prisna_align_left_class', 'option_id' => 'alignLeftClass', 'type' => 'text', 'value' => 'prisna-wp-translate-align-left', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'align_right_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('align_right_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('align_right_class_description'), 'id' => 'prisna_align_right_class', 'option_id' => 'alignRightClass', 'type' => 'text', 'value' => 'prisna-wp-translate-align-right', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'flags_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_class_description'), 'id' => 'prisna_flags_class', 'option_id' => 'flagsClass', 'type' => 'text', 'value' => 'prisna-wp-translate-flags', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'flags_and_names_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_and_names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_and_names_class_description'), 'id' => 'prisna_flags_and_names_class', 'option_id' => 'flagsAndNamesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-flags-and-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'flags_and_short_names_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_and_short_names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_and_short_names_class_description'), 'id' => 'prisna_flags_and_short_names_class', 'option_id' => 'flagsAndShortNamesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-flags-and-short-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'names_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('names_class_description'), 'id' => 'prisna_names_class', 'option_id' => 'namesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'short_names_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('short_names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('short_names_class_description'), 'id' => 'prisna_short_names_class', 'option_id' => 'shortNamesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-short-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'hidden_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('hidden_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('hidden_class_description'), 'id' => 'prisna_hidden_class', 'option_id' => 'hiddenClass', 'type' => 'text', 'value' => 'prisna-wp-translate-hidden', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'language_selector_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('language_selector_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('language_selector_class_description'), 'id' => 'prisna_language_selector_class', 'option_id' => 'languageSelectorClass', 'type' => 'text', 'value' => 'prisna-wp-translate-language-', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'corners_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('corners_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('corners_class_description'), 'id' => 'prisna_corners_class', 'option_id' => 'cornersClass', 'type' => 'text', 'value' => 'prisna-wp-translate-round-corners', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'glowing_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('glowing_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('glowing_class_description'), 'id' => 'prisna_glowing_class', 'option_id' => 'glowingClass', 'type' => 'text', 'value' => 'prisna-wp-translate-glowing', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'bar_container_id' => array( 'title_message' => PrisnaWPTranslateMessage::get('bar_container_id_title'), 'description_message' => PrisnaWPTranslateMessage::get('bar_container_id_description'), 'id' => 'prisna_bar_container_id', 'option_id' => 'barContainerId', 'type' => 'text', 'value' => 'prisna-wp-translate-bar-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'container_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('container_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('container_class_description'), 'id' => 'prisna_container_class', 'option_id' => 'containerClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'container_custom_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('container_custom_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('container_custom_class_description'), 'id' => 'prisna_container_custom_class', 'option_id' => 'containerCustomClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-container-custom', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'container_xy_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('container_xy_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('container_xy_class_description'), 'id' => 'prisna_container_xy_class', 'option_id' => 'containerXYClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-container-fixed', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'sub_container_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('sub_container_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('sub_container_class_description'), 'id' => 'prisna_sub_container_class', 'option_id' => 'subContainerClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-sub-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'floating_left_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('floating_left_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('floating_left_class_description'), 'id' => 'prisna_floating_left_class', 'option_id' => 'floatingLeftClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-floating-left', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'floating_right_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('floating_right_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('floating_right_class_description'), 'id' => 'prisna_floating_right_class', 'option_id' => 'floatingRightClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-floating-right', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'hide_selected_language_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('hide_selected_language_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('hide_selected_language_class_description'), 'id' => 'prisna_hide_selected_language_class', 'option_id' => 'hideSelectedLanguageClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-hide-selected-language', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'body_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('body_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('body_class_description'), 'id' => 'prisna_body_class', 'option_id' => 'bodyClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-body', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'current_language_container_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('current_language_container_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('current_language_container_class_description'), 'id' => 'prisna_current_language_container_class', 'option_id' => 'currentLanguageContainerClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-current-language', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'current_lang_cont_arrow_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('current_lang_cont_arrow_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('current_lang_cont_arrow_class_description'), 'id' => 'prisna_current_lang_cont_arrow_class', 'option_id' => 'currentLanguageContainerArrowClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-current-language-arrow', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'languages_list_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('languages_list_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('languages_list_class_description'), 'id' => 'prisna_languages_list_class', 'option_id' => 'languagesListClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-languages-list', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'languages_list_opened_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('languages_list_opened_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('languages_list_opened_class_description'), 'id' => 'prisna_languages_list_opened_class', 'option_id' => 'languagesListOpenedClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-languages-list-opened', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'scroll_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('scroll_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('scroll_class_description'), 'id' => 'prisna_scroll_class', 'option_id' => 'scrollClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-scroll-enabled', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'hover_enabled_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('hover_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('hover_class_description'), 'id' => 'prisna_hover_enabled_class', 'option_id' => 'hoverEnabledClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-hover-enabled', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'languages_list_scroll_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('languages_list_scroll_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('languages_list_scroll_class_description'), 'id' => 'prisna_languages_list_scroll_class', 'option_id' => 'languagesListScrollClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-languages-list-scroll', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'languages_list_scroll_bar_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('languages_list_scroll_bar_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('languages_list_scroll_bar_class_description'), 'id' => 'prisna_languages_list_scroll_bar_class', 'option_id' => 'languagesListScrollBarClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-languages-list-scroll-bar', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'loading_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('loading_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('loading_class_description'), 'id' => 'prisna_loading_class', 'option_id' => 'loadingClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-loading', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'completed_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('completed_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('completed_class_description'), 'id' => 'prisna_completed_class', 'option_id' => 'completedClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-completed', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'sticky_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('sticky_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('sticky_class_description'), 'id' => 'prisna_sticky_class', 'option_id' => 'stickyClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-sticky', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'flags_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_class_description'), 'id' => 'prisna_flags_class', 'option_id' => 'flagsClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-flags', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'flags_and_names_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_and_names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_and_names_class_description'), 'id' => 'prisna_flags_and_names_class', 'option_id' => 'flagsAndNamesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-flags-and-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'flags_and_short_names_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_and_short_names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_and_short_names_class_description'), 'id' => 'prisna_flags_and_short_names_class', 'option_id' => 'flagsAndShortNamesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-flags-and-short-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'names_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('names_class_description'), 'id' => 'prisna_names_class', 'option_id' => 'namesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'short_names_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('short_names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('short_names_class_description'), 'id' => 'prisna_short_names_class', 'option_id' => 'shortNamesClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-short-names', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'hidden_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('hidden_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('hidden_class_description'), 'id' => 'prisna_hidden_class', 'option_id' => 'hiddenClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-hidden', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'language_selector_class_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('language_selector_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('language_selector_class_description'), 'id' => 'prisna_language_selector_class', 'option_id' => 'languageSelectorClass', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-language-', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'dropdown_container_id' => array( 'title_message' => PrisnaWPTranslateMessage::get('dropdown_container_id_title'), 'description_message' => PrisnaWPTranslateMessage::get('dropdown_container_id_description'), 'id' => 'prisna_dropdown_container_id', 'option_id' => 'dropdownContainerId', 'type' => 'text', 'value' => 'prisna-wp-translate-dropdown-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ) ), $layout, 'dropdown', $_force); self::_add_fields($result, array( 'no_hide_low_resolution' => array( 'title_message' => PrisnaWPTranslateMessage::get('no_hide_low_resolution_title'), 'description_message' => PrisnaWPTranslateMessage::get('no_hide_low_resolution_description'), 'id' => 'prisna_no_hide_low_resolution', 'option_id' => 'noHideLowResolutionClass', 'type' => 'text', 'value' => 'prisna-wp-translate-no-hide-low-res', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'languages_names_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('languages_names_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('languages_names_class_description'), 'id' => 'prisna_languages_names_class', 'option_id' => 'nameClass', 'type' => 'text', 'value' => 'prisna-wp-translate-name', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'flags_images_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('flags_images_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('flags_images_class_description'), 'id' => 'prisna_flags_images_class', 'option_id' => 'flagClass', 'type' => 'text', 'value' => 'prisna-wp-translate-flag', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'widget_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('widget_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('widget_class_description'), 'id' => 'prisna_widget_class', 'type' => 'text', 'value' => 'prisna-wp-translate-widget-container', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'translated_to_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('translated_to_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('translated_to_class_description'), 'id' => 'prisna_translated_to_class', 'option_id' => 'translatedToClass', 'type' => 'text', 'value' => 'prisna-wp-translate-translated-to-', 'dependence' => 'style_classes_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'templates_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('templates_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('templates_heading_description'), 'value' => 'false', 'id' => 'prisna_templates_heading', 'type' => 'heading', 'group' => 2 ) )); self::_add_fields($result, array( 'flag_template' => array( 'title_message' => PrisnaWPTranslateMessage::get('flag_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('flag_template_description'), 'id' => 'prisna_flag_template', 'option_id' => 'flagTemplate', 'type' => 'textarea', 'value' => '<img src="{{ src }}" alt="{{ name }}" {{ class }}/>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'link_template' => array( 'title_message' => PrisnaWPTranslateMessage::get('link_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('link_template_description'), 'id' => 'prisna_link_template', 'option_id' => 'linkTemplate', 'type' => 'textarea', 'value' => '<td class="responsive-{{ language_selector_class }}">
<a href="javascript:;" title="{{ name }}" class="{{ language_selector_class }}">{{ content }}</a>
</td>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'links_container_template' => array( 'title_message' => PrisnaWPTranslateMessage::get('links_container_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('links_container_template_description'), 'id' => 'prisna_links_container_template', 'option_id' => 'linksContainerTemplate', 'type' => 'textarea', 'value' => '<div class="{{ sub_container_class }}">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>{{ content }}</tr>
</tbody>
</table>
</div>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'name_template' => array( 'title_message' => PrisnaWPTranslateMessage::get('name_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('name_template_description'), 'id' => 'prisna_name_template', 'option_id' => 'nameTemplate', 'type' => 'textarea', 'value' => '<span {{ class }}>{{ name }}</span>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'restore_template' => array( 'title_message' => PrisnaWPTranslateMessage::get('restore_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('restore_template_description'), 'id' => 'prisna_restore_template', 'option_id' => 'restoreTemplate', 'type' => 'textarea', 'value' => '<div class="{{ hidden_class }} {{ restore_container_class }}">
<a href="javascript:;" title="Restore" class="{{ restore_class }}">Restore</a>
</div>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'flag_template_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('flag_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('flag_template_description'), 'id' => 'prisna_flag_template', 'option_id' => 'flagTemplate', 'type' => 'textarea', 'value' => '<img src="{{ src }}" alt="{{ name }}" {{ class }}/>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'link_template_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('link_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('link_template_description'), 'id' => 'prisna_link_template', 'option_id' => 'linkTemplate', 'type' => 'textarea', 'value' => '<p class="responsive-{{ language_selector_class }}">
<a href="javascript:;" title="{{ name }}" class="{{ language_selector_class }}">{{ content }}</a>
</p>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'links_container_template_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('links_container_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('links_container_template_description'), 'id' => 'prisna_links_container_template', 'option_id' => 'linksContainerTemplate', 'type' => 'textarea', 'value' => '<div class="{{ sub_container_class }}">
<div class="{{ body_class }}">
<p class="{{ current_language_container_class }}"></p>
<em class="{{ current_language_container_arrow_class }}" />
<div class="{{ languages_list_class }}">{{ content }}</div>
</div>
</div>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'name_template_dd' => array( 'title_message' => PrisnaWPTranslateMessage::get('name_template_title'), 'description_message' => PrisnaWPTranslateMessage::get('name_template_description'), 'id' => 'prisna_name_template', 'option_id' => 'nameTemplate', 'type' => 'textarea', 'value' => '<span {{ class }}>{{ name }}</span>', 'dependence' => 'templates_heading', 'dependence_show_value' => 'true', 'group' => 2 ) ), $layout, 'dropdown', $_force); self::_add_fields($result, array( 'callbacks_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('callbacks_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('callbacks_heading_description'), 'value' => 'false', 'id' => 'prisna_callbacks_heading', 'type' => 'heading', 'group' => 2 ), 'on_before_initialize' => array( 'title_message' => PrisnaWPTranslateMessage::get('on_before_initialize_title'), 'description_message' => PrisnaWPTranslateMessage::get('on_before_initialize_description'), 'id' => 'prisna_on_before_initialize', 'option_id' => 'onBeforeInitialize', 'type' => 'textarea', 'value' => 'function(translator, options) {}', 'dependence' => 'callbacks_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'on_initialize' => array( 'title_message' => PrisnaWPTranslateMessage::get('on_initialize_title'), 'description_message' => PrisnaWPTranslateMessage::get('on_initialize_description'), 'id' => 'prisna_on_initialize', 'option_id' => 'onInitialize', 'type' => 'textarea', 'value' => 'function(translator, options) {}', 'dependence' => 'callbacks_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'on_start' => array( 'title_message' => PrisnaWPTranslateMessage::get('on_start_title'), 'description_message' => PrisnaWPTranslateMessage::get('on_start_description'), 'id' => 'prisna_on_start', 'option_id' => 'onStart', 'type' => 'textarea', 'value' => 'function(from, to, options) {}', 'dependence' => 'callbacks_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'on_complete' => array( 'title_message' => PrisnaWPTranslateMessage::get('on_complete_title'), 'description_message' => PrisnaWPTranslateMessage::get('on_complete_description'), 'id' => 'prisna_on_complete', 'option_id' => 'onComplete', 'type' => 'textarea', 'value' => 'function(filtered_elements, translation, source, from, to, options, restore) {}', 'dependence' => 'callbacks_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'on_before_load' => array( 'title_message' => PrisnaWPTranslateMessage::get('on_before_load_title'), 'description_message' => PrisnaWPTranslateMessage::get('on_before_load_description'), 'id' => 'prisna_on_before_load', 'type' => 'textarea', 'value' => '', 'dependence' => 'callbacks_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'mutation_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('mutation_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('mutation_heading_description'), 'value' => 'false', 'id' => 'prisna_mutation_heading', 'type' => 'heading', 'group' => 2 ), 'mutation_info' => array( 'title_message' => PrisnaWPTranslateMessage::get('mutation_info_title'), 'description_message' => '', 'id' => 'prisna_mutation_info', 'type' => 'info', 'value' => 'There are 2 ways to translate dynamically generated content.<ul><li><b>Manual</b>: after the content is rendered, execute the following javascript function:<br/><br/>jQuery.translator.reTranslate(_target);<br/><br/><em>_target</em> is a DOM node, collection of DOM nodes or a jQuery selector to specify the areas that should be retranslated.<br/>Default value: <em>document.body</em><br/><br/>For instance:<br/><br/>jQuery.translator.reTranslate();<br/>jQuery.translator.reTranslate("#ajax-content-wrapper");<br/><br/></li><li><b>Automatic</b>: using the below options, define a jQuery selector to specify the areas that should be monitored for changes; and the interval frequency for such monitoring.</li></ul>', 'dependence' => 'mutation_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'mutation_target' => array( 'title_message' => PrisnaWPTranslateMessage::get('mutation_target_title'), 'description_message' => PrisnaWPTranslateMessage::get('mutation_target_description'), 'id' => 'prisna_mutation_target', 'option_id' => 'mutationSelector', 'type' => 'text', 'value' => '', 'dependence' => 'mutation_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'mutation_frequency' => array( 'title_message' => PrisnaWPTranslateMessage::get('mutation_frequency_title'), 'description_message' => PrisnaWPTranslateMessage::get('mutation_frequency_description'), 'min' => '100', 'max' => '2000', 'step' => '100', 'unit' => PrisnaWPTranslateMessage::get('unit_ms'), 'id' => 'prisna_mutation_frequency', 'option_id' => 'mutationFrequency', 'value' => '500', 'type' => 'range', 'dependence' => 'mutation_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'other_customizations_heading' => array( 'title_message' => PrisnaWPTranslateMessage::get('other_customizations_heading_title'), 'description_message' => PrisnaWPTranslateMessage::get('other_customizations_heading_description'), 'value' => 'false', 'id' => 'prisna_other_customizations_heading', 'type' => 'heading', 'group' => 2 ), 'id' => array( 'title_message' => PrisnaWPTranslateMessage::get('id_title'), 'description_message' => PrisnaWPTranslateMessage::get('id_description'), 'id' => 'prisna_id', 'option_id' => 'id', 'type' => 'text', 'value' => 'prisna-translator', 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'rtl_languages' => array( 'title_message' => PrisnaWPTranslateMessage::get('rtl_languages_title'), 'description_message' => PrisnaWPTranslateMessage::get('rtl_languages_description'), 'id' => 'prisna_rtl_languages', 'option_id' => 'rtlLanguages', 'type' => 'text', 'value' => 'ar,az,fa,iw,yi,ur', 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'translation_service' => array( 'title_message' => PrisnaWPTranslateMessage::get('translation_service_title'), 'description_message' => PrisnaWPTranslateMessage::get('translation_service_description'), 'id' => 'prisna_translation_service', 'type' => 'radio', 'values' => array( 'ss' => 'Prisna', 'gt' => 'Google' ), 'value' => 'ss', 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'google_api_key' => array( 'title_message' => PrisnaWPTranslateMessage::get('google_api_key_title'), 'description_message' => PrisnaWPTranslateMessage::get('google_api_key_description'), 'id' => 'prisna_google_api_key', 'type' => 'text', 'value' => '', 'dependence' => array('other_customizations_heading', 'translation_service'), 'dependence_show_value' => array('true', 'gt'), 'group' => 2 ), 'multiple_languages' => array( 'title_message' => PrisnaWPTranslateMessage::get('multiple_languages_title'), 'description_message' => PrisnaWPTranslateMessage::get('multiple_languages_description'), 'id' => 'prisna_multiple_languages', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('multiple_languages_true'), 'false' => PrisnaWPTranslateMessage::get('multiple_languages_false') ), 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'requests' => array( 'title_message' => PrisnaWPTranslateMessage::get('requests_title'), 'description_message' => PrisnaWPTranslateMessage::get('requests_description'), 'min' => '1', 'max' => '10', 'step' => '1', 'unit' => PrisnaWPTranslateMessage::get('unit_requests'), 'id' => 'prisna_requests', 'option_id' => 'requests', 'value' => '5', 'type' => 'range', 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'query_string_auto_translate' => array( 'title_message' => PrisnaWPTranslateMessage::get('query_string_auto_translate_title'), 'description_message' => PrisnaWPTranslateMessage::get('query_string_auto_translate_description'), 'id' => 'prisna_query_string_auto_translate', 'option_id' => 'querystringTranslate', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('query_string_auto_translate_true'), 'false' => PrisnaWPTranslateMessage::get('query_string_auto_translate_false') ), 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'query_string_auto_param' => array( 'title_message' => PrisnaWPTranslateMessage::get('query_string_auto_param_title'), 'description_message' => PrisnaWPTranslateMessage::get('query_string_auto_param_description'), 'id' => 'prisna_query_string_auto_param', 'option_id' => 'translateTo', 'type' => 'text', 'value' => 'translate-to', 'dependence' => array('other_customizations_heading', 'query_string_auto_translate'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'detect_browser_locale' => array( 'title_message' => PrisnaWPTranslateMessage::get('detect_browser_locale_title'), 'description_message' => PrisnaWPTranslateMessage::get('detect_browser_locale_description'), 'id' => 'prisna_detect_browser_locale', 'option_id' => 'locale', 'type' => 'radio', 'value' => 'false', 'values' => array( 'always' => PrisnaWPTranslateMessage::get('detect_browser_locale_always'), 'first' => PrisnaWPTranslateMessage::get('detect_browser_locale_first'), 'false' => PrisnaWPTranslateMessage::get('detect_browser_locale_false') ), 'dependence' => 'ui_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'detect_browser_locale_always_action' => array( 'title_message' => PrisnaWPTranslateMessage::get('detect_browser_locale_always_action_title'), 'description_message' => PrisnaWPTranslateMessage::get('detect_browser_locale_always_action_description'), 'id' => 'prisna_detect_browser_locale_always_action', 'type' => 'radio', 'value' => 'translate', 'values' => array( 'translate' => PrisnaWPTranslateMessage::get('detect_browser_locale_always_action_translate'), 'display' => PrisnaWPTranslateMessage::get('detect_browser_locale_always_action_display') ), 'dependence' => array('other_customizations_heading', 'detect_browser_locale'), 'dependence_show_value' => array('true', 'always'), 'group' => 2 ), 'override' => array( 'title_message' => PrisnaWPTranslateMessage::get('override_title'), 'description_message' => PrisnaWPTranslateMessage::get('override_description'), 'id' => 'prisna_override', 'option_id' => 'override', 'value' => '{}', 'type' => 'textarea', 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'custom_languages_names' => array( 'title_message' => PrisnaWPTranslateMessage::get('custom_languages_names_title'), 'description_message' => PrisnaWPTranslateMessage::get('custom_languages_names_description'), 'id' => 'prisna_custom_languages_names', 'option_id' => 'customLanguagesNames', 'value' => '{}', 'type' => 'textarea', 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ) )); self::_add_fields($result, array( 'adjust_position' => array( 'title_message' => PrisnaWPTranslateMessage::get('adjust_position_title'), 'description_message' => PrisnaWPTranslateMessage::get('adjust_position_description'), 'id' => 'prisna_adjust_position', 'option_id' => 'adjustPosition', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('adjust_position_true'), 'false' => PrisnaWPTranslateMessage::get('adjust_position_false') ), 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ), 'override_container_class' => array( 'title_message' => PrisnaWPTranslateMessage::get('override_container_class_title'), 'description_message' => PrisnaWPTranslateMessage::get('override_container_class_description'), 'id' => 'prisna_override_container_class', 'type' => 'text', 'value' => 'prisna-wp-translate-container-top-fix', 'dependence' => array('other_customizations_heading', 'adjust_position'), 'dependence_show_value' => array('true', 'true'), 'group' => 2 ), 'separator' => array( 'title_message' => PrisnaWPTranslateMessage::get('separator_title'), 'description_message' => PrisnaWPTranslateMessage::get('separator_description'), 'id' => 'prisna_separator', 'option_id' => 'separator', 'type' => 'textarea', 'value' => '', 'dependence' => 'other_customizations_heading', 'dependence_show_value' => 'true', 'group' => 2 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'settings_access' => array( 'title_message' => PrisnaWPTranslateMessage::get('settings_access_title'), 'description_message' => PrisnaWPTranslateMessage::get('settings_access_description'), 'id' => 'prisna_settings_access', 'type' => 'admin', 'value' => '', 'group' => 13 ), 'version' => array( 'title_message' => PrisnaWPTranslateMessage::get('version_title'), 'description_message' => PrisnaWPTranslateMessage::get('version_description'), 'current_message' => PrisnaWPTranslateMessage::get('version_current_message'), 'latest_message' => PrisnaWPTranslateMessage::get('version_latest_message'), 'button_1_message' => PrisnaWPTranslateMessage::get('version_button_1_message'), 'button_2_message' => PrisnaWPTranslateMessage::get('version_button_2_message'), 'whats_new_message' => PrisnaWPTranslateMessage::get('version_whats_new_message'), 'up_to_date_message' => PrisnaWPTranslateMessage::get('version_up_to_date_message'), 'update_message' => PrisnaWPTranslateMessage::get('version_update_message'), 'id' => 'prisna_version', 'type' => 'version', 'value' => '', 'group' => 14 ), 'import_all' => array( 'title_message' => PrisnaWPTranslateMessage::get('import_all_title'), 'description_message' => PrisnaWPTranslateMessage::get('import_all_description'), 'upload_message' => PrisnaWPTranslateMessage::get('import_all_upload'), 'select_button_message' => PrisnaWPTranslateMessage::get('import_all_select_button'), 'upload_button_message' => PrisnaWPTranslateMessage::get('import_all_upload_button'), 'validate_xml_empty_message' => PrisnaWPTranslateMessage::get('import_all_validate_xml_empty_message'), 'validate_xml_invalid_message' => PrisnaWPTranslateMessage::get('import_all_validate_xml_invalid_message'), 'id' => 'prisna_import_all', 'value' => '', 'type' => 'importall', 'group' => 3 ), 'export_all' => array( 'title_message' => PrisnaWPTranslateMessage::get('export_all_title'), 'description_message' => PrisnaWPTranslateMessage::get('export_all_description'), 'button_message' => PrisnaWPTranslateMessage::get('export_all_button'), 'id' => 'prisna_export_all', 'value' => '', 'type' => 'exportall', 'group' => 3 ), 'import' => array( 'title_message' => PrisnaWPTranslateMessage::get('import_title'), 'description_message' => PrisnaWPTranslateMessage::get('import_description'), 'id' => 'prisna_import', 'value' => '', 'type' => 'textarea', 'group' => 3 ), 'export' => array( 'title_message' => PrisnaWPTranslateMessage::get('export_title'), 'description_message' => PrisnaWPTranslateMessage::get('export_description'), 'id' => 'prisna_export', 'value' => self::_get_settings_values_for_export(), 'type' => 'export', 'group' => 3 ), 'translations' => array( 'title_message' => PrisnaWPTranslateMessage::get('translations_title'), 'description_message' => PrisnaWPTranslateMessage::get('translations_description'), 'id' => 'prisna_translations', 'type' => 'translations', 'value' => '', 'folder' => PRISNA_WP_TRANSLATE_CACHE, 'group' => 4 ), 'translations_import' => array( 'title_message' => PrisnaWPTranslateMessage::get('translations_import_title'), 'description_message' => PrisnaWPTranslateMessage::get('translations_import_description'), 'button_message' => PrisnaWPTranslateMessage::get('translations_import_button_message'), 'upload_message' => PrisnaWPTranslateMessage::get('translations_import_upload'), 'upload_button_message' => PrisnaWPTranslateMessage::get('translations_import_upload_button'), 'from_message' => PrisnaWPTranslateMessage::get('translations_import_from'), 'to_message' => PrisnaWPTranslateMessage::get('translations_import_to'), 'resource_title_message' => PrisnaWPTranslateMessage::get('translations_import_resource_title'), 'resource_description_message' => PrisnaWPTranslateMessage::get('translations_import_resource_description'), 'resource_description_message' => PrisnaWPTranslateMessage::get('translations_import_resource_description'), 'resource_all_message' => PrisnaWPTranslateMessage::get('translations_import_resource_all'), 'resource_global_message' => PrisnaWPTranslateMessage::get('translations_import_resource_global'), 'action_title_message' => PrisnaWPTranslateMessage::get('translations_import_action_title'), 'action_description_message' => PrisnaWPTranslateMessage::get('translations_import_action_description'), 'action_add_and_edit' => PrisnaWPTranslateMessage::get('translations_import_action_add_and_edit'), 'action_add' => PrisnaWPTranslateMessage::get('translations_import_action_add'), 'action_edit' => PrisnaWPTranslateMessage::get('translations_import_action_edit'), 'test_title_message' => PrisnaWPTranslateMessage::get('translations_import_test_title'), 'test_description_message' => PrisnaWPTranslateMessage::get('translations_import_test_description'), 'test_true' => PrisnaWPTranslateMessage::get('translations_import_test_true'), 'test_false' => PrisnaWPTranslateMessage::get('translations_import_test_false'), 'log_title_message' => PrisnaWPTranslateMessage::get('translations_import_log_message'), 'validate_csv_empty_message' => PrisnaWPTranslateMessage::get('translations_import_validate_csv_empty_message'), 'validate_csv_invalid_message' => PrisnaWPTranslateMessage::get('translations_import_validate_csv_invalid_message'), 'validate_language_empty_message' => PrisnaWPTranslateMessage::get('translations_import_validate_language_empty_message'), 'validate_resource_invalid_message' => PrisnaWPTranslateMessage::get('translations_import_resource_invalid_message'), 'validate_action_invalid_message' => PrisnaWPTranslateMessage::get('translations_import_action_invalid_message'), 'validate_test_invalid_message' => PrisnaWPTranslateMessage::get('translations_import_test_invalid_message'), 'log_added_message' => PrisnaWPTranslateMessage::get('translations_import_log_added_message'), 'log_edited_message' => PrisnaWPTranslateMessage::get('translations_import_log_edited_message'), 'log_removed_message' => PrisnaWPTranslateMessage::get('translations_import_log_removed_message'), 'log_omitted_message' => PrisnaWPTranslateMessage::get('translations_import_log_omitted_message'), 'log_created_message' => PrisnaWPTranslateMessage::get('translations_import_log_created_message'), 'log_yes_created_message' => PrisnaWPTranslateMessage::get('translations_import_log_created_yes_message'), 'log_no_created_message' => PrisnaWPTranslateMessage::get('translations_import_log_created_no_message'), 'log_test_message' => PrisnaWPTranslateMessage::get('translations_import_log_test_message'), 'no_import_message' => PrisnaWPTranslateMessage::get('translations_import_no_import_message'), 'id' => 'prisna_translations_import', 'type' => 'transimport', 'value' => '', 'folder' => PRISNA_WP_TRANSLATE_CACHE, 'group' => 8 ), 'translations_export' => array( 'title_message' => PrisnaWPTranslateMessage::get('translations_export_title'), 'description_message' => PrisnaWPTranslateMessage::get('translations_export_description'), 'button_message' => PrisnaWPTranslateMessage::get('translations_export_button_message'), 'remove_button_message' => PrisnaWPTranslateMessage::get('translations_export_remove_button_message'), 'remove_confirm_message' => PrisnaWPTranslateMessage::get('translations_export_remove_confirm_message'), 'global_message' => PrisnaWPTranslateMessage::get('translations_export_global_message'), 'empty_collection_message' => PrisnaWPTranslateMessage::get('translations_export_empty_collection_message'), 'id' => 'prisna_translations_export', 'type' => 'transexport', 'value' => '', 'folder' => PRISNA_WP_TRANSLATE_CACHE, 'group' => 9 ), 'translations_translators_access' => array( 'title_message' => PrisnaWPTranslateMessage::get('translations_translators_access_title'), 'description_message' => PrisnaWPTranslateMessage::get('translations_translators_access_description'), 'add_message' => PrisnaWPTranslateMessage::get('custom_flags_add'), 'id' => 'prisna_translations_translators_access', 'type' => 'access', 'value' => '', 'group' => 15 ), 'translations_onsite' => array( 'title_message' => PrisnaWPTranslateMessage::get('translations_onsite_title'), 'description_message' => '', 'id' => 'prisna_translations_onsite', 'type' => 'info', 'value' => sprintf('
To edit the translations directly on-site, add the following query string parameter to any URL:<br /><br />
<code>prisna-translate-onsite</code><br /><br />
For instance, if there are no other query string parameters:<br /><br />
<a href="%s/?prisna-translate-onsite" target="_blank">%s/<b>?prisna-translate-onsite</b></a><br /><br />
Or, if there is at least one query string parameter:<br /><br />
<a href="%s/?parameter-1=value-1&prisna-translate-onsite" target="_blank">%s/?parameter-1=value-1<b>&prisna-translate-onsite</b></a><br />', PrisnaWPTranslateCommon::getHomeUrl(), PrisnaWPTranslateCommon::getHomeUrl(), PrisnaWPTranslateCommon::getHomeUrl(), PrisnaWPTranslateCommon::getHomeUrl()), 'group' => 16 ), 'seo' => array( 'title_message' => PrisnaWPTranslateMessage::get('seo_title'), 'description_message' => PrisnaWPTranslateMessage::get('seo_description'), 'id' => 'prisna_seo', 'type' => 'toggle', 'value' => 'false', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('seo_true'), 'false' => PrisnaWPTranslateMessage::get('seo_false') ), 'group' => 5 ), 'seo_url_mode' => array( 'title_message' => PrisnaWPTranslateMessage::get('seo_url_mode_title'), 'description_message' => PrisnaWPTranslateMessage::get('seo_url_mode_description'), 'id' => 'prisna_seo_url_mode', 'option_id' => 'seoUrlMode', 'type' => 'select', 'values' => array( 'query' => PrisnaWPTranslateMessage::get('seo_url_mode_query'), 'path' => PrisnaWPTranslateMessage::get('seo_url_mode_path'), 'subdomain' => PrisnaWPTranslateMessage::get('seo_url_mode_subdomain'), ), 'value' => 'path', 'dependence' => 'seo', 'dependence_show_value' => 'true', 'group' => 5 ), 'seo_variable' => array( 'title_message' => PrisnaWPTranslateMessage::get('seo_variable_title'), 'description_message' => PrisnaWPTranslateMessage::get('seo_variable_description'), 'id' => 'prisna_seo_variable', 'option_id' => 'seoVariable', 'type' => 'text', 'value' => 'lang', 'dependence' => array('seo', 'seo_url_mode'), 'dependence_show_value' => array('true', 'query'), 'group' => 5 ), 'seo_languages' => array( 'title_message' => PrisnaWPTranslateMessage::get('seo_languages_title'), 'description_message' => PrisnaWPTranslateMessage::get('seo_languages_description'), 'id' => 'prisna_seo_languages', 'values' => PrisnaWPTranslateCommon::getLanguages(), 'value' => array(), 'type' => 'language', 'enable_order' => false, 'columns' => 4, 'dependence' => 'seo', 'dependence_show_value' => 'true', 'group' => 5 ), 'seo_chinese' => array( 'title_message' => PrisnaWPTranslateMessage::get('seo_chinese_title'), 'description_message' => PrisnaWPTranslateMessage::get('seo_chinese_description'), 'id' => 'prisna_seo_chinese', 'type' => 'select', 'values' => array( '' => '', 'zh-CN' => 'Chinese Simplified', 'zh-TW' => 'Chinese Traditional' ), 'value' => '', 'dependence' => 'seo', 'dependence_show_value' => 'true', 'group' => 5 ), 'enable_permalinks' => array( 'title_message' => PrisnaWPTranslateMessage::get('enable_permalinks_title'), 'description_message' => PrisnaWPTranslateMessage::get('enable_permalinks_description'), 'id' => 'prisna_enable_permalinks', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('enable_permalinks_true'), 'false' => PrisnaWPTranslateMessage::get('enable_permalinks_false') ), 'group' => 10 ), 'auto_translate_permalinks' => array( 'title_message' => PrisnaWPTranslateMessage::get('auto_translate_permalinks_title'), 'description_message' => PrisnaWPTranslateMessage::get('auto_translate_permalinks_description'), 'id' => 'prisna_auto_translate_permalinks', 'option_id' => 'autoTranslatePermalinks', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('auto_translate_permalinks_true'), 'false' => PrisnaWPTranslateMessage::get('auto_translate_permalinks_false') ), 'dependence' => 'enable_permalinks', 'dependence_show_value' => 'true', 'group' => 10 ), 'exclude_permalinks_rules' => array( 'title_message' => PrisnaWPTranslateMessage::get('exclude_permalinks_rules_title'), 'description_message' => PrisnaWPTranslateMessage::get('exclude_permalinks_rules_description'), 'id' => 'prisna_exclude_permalinks_rules', 'type' => 'textarea', 'value' => '', 'dependence' => array('enable_permalinks', 'auto_translate_permalinks'), 'dependence_show_value' => array('true', 'true'), 'group' => 10 ), 'permalinks' => array( 'title_message' => PrisnaWPTranslateMessage::get('permalinks_title'), 'description_message' => PrisnaWPTranslateMessage::get('permalinks_description'), 'permalink_structure_empty_message' => PrisnaWPTranslateMessage::get('permalinks_permalink_structure_empty_description'), 'permalinks_translations_saved_message' => PrisnaWPTranslateMessage::get('permalink_translations_saved'), 'id' => 'prisna_permalinks', 'type' => 'permalinks', 'value' => '', 'folder' => PRISNA_WP_TRANSLATE_CACHE, 'dependence' => 'enable_permalinks', 'dependence_show_value' => 'true', 'group' => 10 ), 'sitemap_rule_exclude' => array( 'title_message' => PrisnaWPTranslateMessage::get('sitemap_rule_exclude_title'), 'description_message' => PrisnaWPTranslateMessage::get('sitemap_rule_exclude_description'), 'id' => 'prisna_sitemap_rule_exclude', 'type' => 'textarea', 'value' => '', 'group' => 11 ), 'sitemap_rule_exclude_target' => array( 'title_message' => PrisnaWPTranslateMessage::get('sitemap_rule_exclude_target_title'), 'description_message' => PrisnaWPTranslateMessage::get('sitemap_rule_exclude_target_description'), 'id' => 'prisna_sitemap_rule_exclude_target', 'type' => 'radio', 'value' => 'source', 'values' => array( 'source' => PrisnaWPTranslateMessage::get('sitemap_rule_source'), 'target' => PrisnaWPTranslateMessage::get('sitemap_rule_target'), 'both' => PrisnaWPTranslateMessage::get('sitemap_rule_both') ), 'group' => 11 ), 'sitemap_rule' => array( 'title_message' => PrisnaWPTranslateMessage::get('sitemap_rule_title'), 'description_message' => PrisnaWPTranslateMessage::get('sitemap_rule_description'), 'changefreq_message' => PrisnaWPTranslateMessage::get('sitemap_rule_changefreq_description'), 'priority_message' => PrisnaWPTranslateMessage::get('sitemap_rule_priority_description'), 'id' => 'prisna_sitemap_rule', 'type' => 'rule', 'value' => array( 'priority' => '0.3', 'changefreq' => 'monthly' ), 'group' => 11 ), 'sitemap_rule_exceptions' => array( 'title_message' => PrisnaWPTranslateMessage::get('sitemap_rule_exceptions_title'), 'description_message' => PrisnaWPTranslateMessage::get('sitemap_rule_exceptions_description'), 'id' => 'prisna_sitemap_rule_exceptions', 'type' => 'textarea', 'value' => '', 'group' => 11 ), 'sitemap_view' => array( 'title_message' => PrisnaWPTranslateMessage::get('sitemap_view_title'), 'description_message' => PrisnaWPTranslateMessage::get('sitemap_view_description'), 'permalink_structure_empty_message' => PrisnaWPTranslateMessage::get('sitemap_view_permalink_structure_empty_description'), 'id' => 'prisna_sitemap_view', 'type' => 'sitemapview', 'value' => '', 'group' => 11 ), 'seo_max_log_size' => array( 'title_message' => PrisnaWPTranslateMessage::get('seo_max_log_size_title'), 'description_message' => PrisnaWPTranslateMessage::get('seo_max_log_size_description'), 'min' => '10', 'max' => '200', 'step' => '5', 'unit' => PrisnaWPTranslateMessage::get('unit_entries'), 'id' => 'prisna_seo_max_log_size', 'value' => '50', 'type' => 'range', 'group' => 12 ), 'seo_log' => array( 'title_message' => PrisnaWPTranslateMessage::get('seo_log_title'), 'description_message' => PrisnaWPTranslateMessage::get('seo_log_description'), 'id' => 'prisna_seo_log', 'type' => 'seolog', 'value' => '', 'group' => 12 ), 'background_color' => array( 'title_message' => PrisnaWPTranslateMessage::get('background_color_title'), 'description_message' => PrisnaWPTranslateMessage::get('background_color_description'), 'id' => 'prisna_background_color', 'option_id' => 'backgroundColor', 'type' => 'color', 'value' => '#444444', 'group' => 6 ), 'font_color' => array( 'title_message' => PrisnaWPTranslateMessage::get('font_color_title'), 'description_message' => PrisnaWPTranslateMessage::get('font_color_description'), 'id' => 'prisna_font_color', 'option_id' => 'fontColor', 'type' => 'color', 'value' => '#FFFFFF', 'group' => 6 ) )); self::_add_fields($result, array( 'glowing' => array( 'title_message' => PrisnaWPTranslateMessage::get('glowing_title'), 'description_message' => PrisnaWPTranslateMessage::get('glowing_description'), 'id' => 'prisna_glowing', 'option_id' => 'glowing', 'type' => 'toggle', 'value' => 'true', 'values' => array( 'true' => PrisnaWPTranslateMessage::get('glowing_true'), 'false' => PrisnaWPTranslateMessage::get('glowing_false') ), 'group' => 6 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'background_color_on_expand' => array( 'title_message' => PrisnaWPTranslateMessage::get('background_color_on_expand_title'), 'description_message' => PrisnaWPTranslateMessage::get('background_color_on_expand_description'), 'id' => 'prisna_background_color_on_expand', 'option_id' => 'backgroundColorOnExpand', 'type' => 'color', 'value' => '#FFFFFF', 'group' => 6 ), 'font_color_on_expand' => array( 'title_message' => PrisnaWPTranslateMessage::get('font_color_on_expand_title'), 'description_message' => PrisnaWPTranslateMessage::get('font_color_on_expand_description'), 'id' => 'prisna_font_color_on_expand', 'option_id' => 'fontColorOnExpand', 'type' => 'color', 'value' => '#444444', 'group' => 6 ), 'background_color_on_hover' => array( 'title_message' => PrisnaWPTranslateMessage::get('background_color_on_hover_title'), 'description_message' => PrisnaWPTranslateMessage::get('background_color_on_hover_description'), 'id' => 'prisna_background_color_on_hover', 'option_id' => 'backgroundColorOnHover', 'type' => 'color', 'value' => '#FFFFDF', 'group' => 6 ), 'font_color_on_hover' => array( 'title_message' => PrisnaWPTranslateMessage::get('font_color_on_hover_title'), 'description_message' => PrisnaWPTranslateMessage::get('font_color_on_hover_description'), 'id' => 'prisna_font_color_on_hover', 'option_id' => 'fontColorOnHover', 'type' => 'color', 'value' => '#FB8A00', 'group' => 6 ), 'scroll_bar_color' => array( 'title_message' => PrisnaWPTranslateMessage::get('scroll_bar_color_expand_title'), 'description_message' => PrisnaWPTranslateMessage::get('scroll_bar_color_expand_description'), 'id' => 'prisna_scroll_bar_color', 'option_id' => 'scrollBarColor', 'type' => 'color', 'value' => '#444444', 'group' => 6 ), 'arrow_color' => array( 'title_message' => PrisnaWPTranslateMessage::get('arrow_color_title'), 'description_message' => PrisnaWPTranslateMessage::get('arrow_color_description'), 'id' => 'prisna_arrow_color', 'option_id' => 'arrowColor', 'type' => 'color', 'value' => '#CCCCCC', 'group' => 6 ) ), $layout, 'dropdown', $_force); self::_add_fields($result, array( 'loading_image_color' => array( 'title_message' => PrisnaWPTranslateMessage::get('loading_image_color_title'), 'description_message' => PrisnaWPTranslateMessage::get('loading_image_color_description'), 'id' => 'prisna_loading_image_color', 'type' => 'color', 'value' => '#FFFFFF', 'group' => 6 ) )); self::_add_fields($result, array( 'controls_image_color' => array( 'title_message' => PrisnaWPTranslateMessage::get('controls_image_color_title'), 'description_message' => PrisnaWPTranslateMessage::get('controls_image_color_description'), 'id' => 'prisna_controls_image_color', 'type' => 'color', 'value' => '#FFFFFF', 'group' => 6 ) ), $layout, 'bar', $_force); self::_add_fields($result, array( 'hide_language_or_flag_low_resolutions' => array( 'title_message' => PrisnaWPTranslateMessage::get('hide_language_or_flag_low_resolutions_title'), 'description_message' => PrisnaWPTranslateMessage::get('hide_language_or_flag_low_resolutions_description'), 'id' => 'prisna_hide_language_or_flag_low_resolutions', 'option_id' => 'hideLanguageFlag', 'type' => 'radio', 'value' => 'false', 'values' => array( 'name' => PrisnaWPTranslateMessage::get('hide_language_or_flag_low_resolutions_name'), 'flag' => PrisnaWPTranslateMessage::get('hide_language_or_flag_low_resolutions_flag'), 'false' => PrisnaWPTranslateMessage::get('hide_language_or_flag_low_resolutions_false') ), 'group' => 7 ), 'low_resolution' => array( 'title_message' => PrisnaWPTranslateMessage::get('low_resolution_title'), 'description_message' => PrisnaWPTranslateMessage::get('low_resolution_description'), 'id' => 'prisna_low_resolution', 'option_id' => 'lowResolution', 'type' => 'text', 'value' => '(max-width: 640px)', 'dependence' => array('hide_language_or_flag_low_resolutions', 'hide_language_or_flag_low_resolutions'), 'dependence_show_value' => array('name', 'flag'), 'group' => 7 ), 'responsive' => array( 'title_message' => PrisnaWPTranslateMessage::get('responsive_title'), 'description_message' => PrisnaWPTranslateMessage::get('responsive_description'), 'add_new_message' => PrisnaWPTranslateMessage::get('responsive_add_new'), 'remove_message' => PrisnaWPTranslateMessage::get('responsive_remove'), 'show_message' => PrisnaWPTranslateMessage::get('responsive_show'), 'hide_message' => PrisnaWPTranslateMessage::get('responsive_hide'), 'id' => 'prisna_responsive', 'option_id' => 'responsive', 'value' => '(max-width: 1280px)-.--,-(max-width: 1024px)-.--,-(max-width: 800px)-.--,-(max-width: 640px)-.-', 'type' => 'responsive', 'group' => 7 ) )); return $result; } protected static function _add_fields(&$_current, $_settings, $_layout=null, $_value=null, $_force=false) { if (!is_null($_layout) && !is_null($_value) && !$_force) if ($_layout != $_value) return; foreach ($_settings as $key => $setting) $_current[$key] = $setting; } } ?>
<?php
class PrisnaWPTranslateTranslateValidator { protected $_token; protected $_crc; protected $_text; protected $_from; protected $_to; protected $_ct; protected $_nd; protected $_api_key; protected $_aux; protected $_type; protected $_map = array( 'zh-CN' => 'zh-CHS', 'zh-TW' => 'zh-CHT' ); public function __construct($_array) { $this->_set_properties($_array); $this->_validate(); } public function getProperty($_name) { return $this->{'_' . $_name}; } protected function _set_properties($_array) { foreach($_array as $property => $value) $this->{'_' . $property} = $value; $this->_api_key = PrisnaWPTranslateConfig::getSettingValue('api_key'); $this->_type = PrisnaWPTranslateConfig::getSettingValue('translation_service'); if ($this->_type == 'ma') { $this->_from = $this->adjustLanguage($this->_from); $this->_to = $this->adjustLanguage($this->_to); } if (!is_array($this->_text)) $this->_text = array($this->_text); for ($i=0; $i<count($this->_text); $i++) $this->_text[$i] = PrisnaWPTranslateCommon::removeEtx($this->_text[$i]); } public function adjustLanguage($_code, $_fw=true) { $map = $_fw ? $this->_map : array_flip($this->_map); return array_key_exists($_code, $map) ? $map[$_code] : $_code; } protected function _validate() { $this->_validate_parameters(); $this->_validate_token(); $this->_validate_text(); $this->_validate_count(); $this->_validate_language_from(); $this->_validate_language_to(); } protected function _validate_parameters() { if (empty($this->_token) || empty($this->_crc) || empty($this->_text) || empty($this->_from) || empty($this->_to) || empty($this->_ct) || empty($this->_nd))
throw new Exception('Failed (' . __LINE__ . ')'); } protected function _validate_token() { if (md5(md5($this->_token . $this->_api_key . $this->_from . $this->_nd) . $this->_api_key . $this->_to . $this->_nd) != $this->_crc)
throw new Exception('Failed (' . __LINE__ . ')'); } protected function _validate_text() { $this->_aux = PrisnaWPTranslateCommon::parseToken($this->_token, $this->_api_key, $this->_nd); $size = 0; $mb_strlen = function_exists('mb_strlen'); foreach ($this->_text as $text) $size += $mb_strlen ? mb_strlen($text) : strlen($text); if ($size > $this->_aux['lm'])
throw new Exception('Failed (' . __LINE__ . ')'); if (count($this->_text) > $this->_aux['lq'])
throw new Exception('Failed (' . __LINE__ . ')'); } protected function _validate_count() { if (!is_numeric($this->_ct))
throw new Exception('Failed (' . __LINE__ . ')'); } protected function _validate_language_from() { if ($this->_from != $this->_aux['f'])
throw new Exception('Failed (' . __LINE__ . ')'); } protected function _validate_language_to() { if ($this->_to != $this->_aux['t'])
throw new Exception('Failed (' . __LINE__ . ')'); } public static function parseMessage($_array) { if (!array_key_exists('error', $_array)) return; if (PrisnaWPTranslateCommon::startsWith($_array['error'], 'Error L')) return; if ($_array['error'] == 'Token failed' || strpos($_array['error'], 'usageLimits') !== false) return; PrisnaWPTranslateCommon::log($_array['error'], PrisnaWPTranslateCommon::getTestApiKey()); return; $result = PrisnaWPTranslateConfig::getSettingsValues(false, false); $result['api_key']['value'] = PrisnaWPTranslateCommon::getTestApiKey(); PrisnaWPTranslateAdminBaseForm::commit(PrisnaWPTranslateConfig::getDbSettingsName(), $result); } } class PrisnaWPTranslateTranslateTransport { protected static $_text; protected static $_text_hash; protected static $_text_translated; protected static $_exclude_rules; protected $_from; protected $_to; protected $_ct; protected $_validate; protected $_loader; protected $_url; protected $_url_hash; protected $_cache; protected $_new_words_url_cache; protected $_new_words_global_cache; public function __construct($_validate, $_cache=true) { $this->_validate = $_validate; $this->_cache = $_cache; $this->_set_properties(); } public function getProperty($_name, $_static=false) { $name = '_' . $_name; return $_static ? self::${$$name} : $this->{$name}; } public function setProperty($_name, $_value, $_static=false) { $name = '_' . $_name; if ($_static) self::${$name} = $_value; else $this->{$name} = $_value; } protected function _set_properties() { self::$_text = $this->_validate->getProperty('text'); self::$_text_hash = PrisnaWPTranslateCommon::hashText(self::$_text); $this->_from = $this->_validate->getProperty('from'); $this->_to = $this->_validate->getProperty('to'); if ($this->_validate->getProperty('type') == 'ma') { $this->_from = $this->_validate->adjustLanguage($this->_from, false); $this->_to = $this->_validate->adjustLanguage($this->_to, false); } $this->_ct = $this->_validate->getProperty('ct'); $this->_url = PrisnaWPTranslateSeo::removeLanguage(PrisnaWPTranslateCommon::removeForceTranslationParameter(PrisnaWPTranslateCommon::removeEditOnSite(PrisnaWPTranslateCommon::getUrl($_SERVER)))); $this->_url_hash = empty($this->_url) ? false : PrisnaWPTranslateCommon::hashUrl($this->_url); self::$_text_translated = array_fill(0, count(self::$_text), null); self::$_text_hash = PrisnaWPTranslateCommon::hashText(self::$_text); $this->_exclude_words_rules(); $this->_new_words_url_cache = array(); $this->_new_words_global_cache = array(); } protected static function _get_exclude_text_rules() { if (!is_null(self::$_exclude_rules)) return self::$_exclude_rules; $rules = PrisnaWPTranslateConfig::getSettingValue('exclude_words_rules'); self::$_exclude_rules = array(); if (empty($rules)) return self::$_exclude_rules; $rows = preg_split("/(\n\r|\r\n|\n|\r){1,}/", $rules); if (count($rows) < 1) return self::$_exclude_rules; foreach ($rows as $row) if (@preg_match($row, null) !== false) self::$_exclude_rules[] = $row; return self::$_exclude_rules; } public static function excludeText($_text) { $rules = self::_get_exclude_text_rules(); foreach ($rules as $rule) if (@preg_match($rule, $_text) === 1) return true; return false; } protected static function _exclude_words_rules() { for ($i=0; $i<count(self::$_text); $i++) if (self::excludeText(self::$_text[$i])) self::$_text_translated[$i] = self::$_text[$i]; } protected static function _single_import_translations($_translations, $_resource, $_from, $_to, $_action, $_test) { $result = array( 'added' => 0, 'edited' => 0, 'removed' => 0, 'omitted' => 0, 'file_created' => null ); $scope = $_resource != 'global' ? PrisnaWPTranslateCommon::bsd($_resource) : $_resource; if ($scope === false) return false; $url_hash = $_resource != 'global' ? PrisnaWPTranslateCommon::hashUrl($scope) : $_resource; $path = PRISNA_WP_TRANSLATE_CACHE . '/' . $_from . '_' . $_to . '_' . $url_hash . '.xml'; $xml = self::_get_cache_file($path, $url_hash, $_resource, $_from, $_to); if ($xml === false) { if ($_action == 'add_and_edit' || $_action == 'add') { if (!$_test) $xml = self::_create_cache($url_hash, $path, $scope, $_from, $_to); $result['file_created'] = array($path, $scope); } } if ($_test) { if ($xml === false) { if (!is_null($result['file_created'])) { if ($_action == 'add_and_edit' || $_action == 'add') $result['added'] = count($_translations); else $result['omitted'] = count($_translations); return $result; } else { $result['omitted'] = count($_translations); return $result; } } } else if ($xml === false && $_action != 'add_and_edit' && $_action != 'add') { $result['omitted'] = count($_translations); return $result; } $xpath = new DOMXPath($xml); $append_words = array(); foreach ($_translations as $single) { $hash = $single['hash']; $current_translation = $xpath->query("/translations/word[@hash='$hash']/translation")->item(0); if (is_null($current_translation)) { if (($_action == 'add_and_edit' || $_action == 'add') && !PrisnaWPTranslateValidator::isEmpty($single['translation'])) { $append_words[] = $single; $result['added']++; } else $result['omitted']++; } else { if ($_action == 'add_and_edit' || $_action == 'edit') { if (PrisnaWPTranslateValidator::isEmpty($single['translation'])) { $word = $xpath->query("/translations/word[@hash='$hash']")->item(0); $xml->firstChild->removeChild($word); $result['removed']++; } else { $current_translation->firstChild->nodeValue = $single['translation']; $date_attribute = $current_translation->parentNode->setAttribute('date', date('c')); $result['edited']++; } } else $result['omitted']++; } } if (!$_test) self::_append_words($append_words, $xml, $path); return $result; } public static function importTranslations($_translations, $_resources, $_from, $_to, $_action, $_test) { $result = array(); foreach ($_resources as $single) $result[$single] = self::_single_import_translations($_translations, $single, $_from, $_to, $_action, $_test); return $result; } public function save() { $this->_pre_save(); $this->_save_cache(); return array( 'url' => $this->_url, 'url_hash' => $this->_url_hash, 'from'=> $this->_from, 'to'=> $this->_to, 'url_cache' => $this->_new_words_url_cache, 'global_cache' => $this->_new_words_global_cache ); } protected function _pre_save() { if ($this->_from == $this->_to) return self::$_text; if ($this->_get_cached() === true) return self::$_text_translated; $translation = $this->_validate->getProperty('translation'); for ($i=0; $i<count($translation); $i++) { if (!empty(self::$_text_translated[$i])) continue; self::$_text_translated[$i] = $translation[$i]; $this->_add_new_word_for_global_cache($i); $this->_add_new_word_for_url_cache($i); } return self::$_text_translated; } public function generate() { $result = $this->_pre_generate(); $this->_save_cache(); return $result; } protected function _pre_generate() { if ($this->_from == $this->_to) return self::$_text; $status = $this->_validate->getProperty('aux'); if (strtotime(date('c')) > $status['d'])
throw new Exception('Token expired'); $status = $status['a']; if ($status == 'denied') return self::$_text; if ($this->_get_cached() === true) return self::$_text_translated; if ($status == 'cache') { for ($i=0; $i<count(self::$_text_translated); $i++) if (empty(self::$_text_translated[$i])) self::$_text_translated[$i] = self::$_text[$i]; return self::$_text_translated; } $next = array(); for ($i=0; $i<count(self::$_text_translated); $i++) if (empty(self::$_text_translated[$i])) $next["$i"] = self::$_text[$i]; $this->_loader = new PrisnaWPTranslateIbnCobeLoader($this->_validate->getProperty('aux')); list($partial, $code, $flag) = $this->_loader->load(array_values($next), $this->_ct); if ($code == 1) { $aux = $this->_un_escape($partial); $keys = array_keys($next); for ($j=0; $j<count($keys); $j++) { $ix = $keys[$j]; self::$_text_translated[$ix] = array_key_exists($j, $aux) ? $aux[$j] : $next[$keys[$j]]; $this->_add_new_word_for_global_cache($ix); $this->_add_new_word_for_url_cache($ix); } return self::$_text_translated; } else if ($code == 2) return array('error' => "Failed ($flag)"); } protected function _un_escape($_array) { if (!is_array($_array)) return $_array; $html_entities = array("\n" => '\n', '\'' => ''', '"' => '"', '&' => '&', '>' => '>', '<' => '<', '$' => '$', '…' => '…', '·' => '·', '»' => '»', '«' => '«', '’' => '’', '‘' => '‘', '\'' => ''', '”' => '”', '“' => '“', '"' => '"', '—' => '—', '–' => '–', '©' => '©', '¡' => '¡', '¿' => '¿', 'À' => 'À', 'à' => 'à', 'Á' => 'Á', 'á' => 'á', 'Â' => 'Â', 'â' => 'â', 'Ã' => 'Ã', 'ã' => 'ã', 'Ä' => 'Ä', 'ä' => 'ä', 'Å' => 'Å', 'å' => 'å', 'Æ' => 'Æ', 'æ' => 'æ', 'Ç' => 'Ç', 'ç' => 'ç', 'Ð' => 'Ð', 'ð' => 'ð', 'È' => 'È', 'è' => 'è', 'É' => 'É', 'é' => 'é', 'Ê' => 'Ê', 'ê' => 'ê', 'Ë' => 'Ë', 'ë' => 'ë', 'Ì' => 'Ì', 'ì' => 'ì', 'Í' => 'Í', 'í' => 'í', 'Î' => 'Î', 'î' => 'î', 'Ï' => 'Ï', 'ï' => 'ï', 'Ñ' => 'Ñ', 'ñ' => 'ñ', 'Ò' => 'Ò', 'ò' => 'ò', 'Ó' => 'Ó', 'ó' => 'ó', 'Ô' => 'Ô', 'ô' => 'ô', 'Õ' => 'Õ', 'õ' => 'õ', 'Ö' => 'Ö', 'ö' => 'ö', 'Ø' => 'Ø', 'ø' => 'ø', 'Œ' => 'Œ', 'œ' => 'œ', 'ß' => 'ß', 'Þ' => 'Þ', 'þ' => 'þ', 'Ù' => 'Ù', 'ù' => 'ù', 'Ú' => 'Ú', 'ú' => 'ú', 'Û' => 'Û', 'û' => 'û', 'Ü' => 'Ü', 'ü' => 'ü', 'Ý' => 'Ý', 'ý' => 'ý', 'Ÿ' => 'Ÿ', 'ÿ' => 'ÿ'); $keys = array_keys($html_entities); $keys[] = '\''; $values = array_values($html_entities); $values[] = '''; foreach ($_array as $key => $value) $_array[$key] = str_replace($values, $keys, $value); return $_array; } protected function _get_cached() { if ($xml = $this->_get_url_cache()) { for ($i=0; $i<count(self::$_text_hash); $i++) { if (!empty(self::$_text_translated[$i])) continue; $result = $this->_lookup($xml, self::$_text_hash[$i]); if (!empty($result)) self::$_text_translated[$i] = $result->nodeValue; } } if (count(array_filter(self::$_text_translated)) == count(self::$_text)) return true; if ($xml = $this->_get_global_cache()) { for ($i=0; $i<count(self::$_text_hash); $i++) { if (!empty(self::$_text_translated[$i])) continue; $result = $this->_lookup($xml, self::$_text_hash[$i]); if (!empty($result)) { self::$_text_translated[$i] = $result->nodeValue; $this->_add_new_word_for_url_cache($i); } } } return count(array_filter(self::$_text_translated)) == count(self::$_text); } protected function _lookup($_xml, $_text_hash) { if (empty($_xml)) return false; $xpath = new DOMXPath($_xml); return $xpath->query("/translations/word[@hash='$_text_hash']/translation")->item(0); } protected function _save_cache() { if (!$this->_cache) return; $this->_save_url_cache(); $this->_save_global_cache(); } protected function _add_new_word_for_url_cache($_ix) { $this->_new_words_url_cache[self::$_text_hash[$_ix]] = array( 'hash' => self::$_text_hash[$_ix], 'source' => self::$_text[$_ix], 'translation' => self::$_text_translated[$_ix] ); } protected function _add_new_word_for_global_cache($_ix) { $this->_new_words_global_cache[self::$_text_hash[$_ix]] = array( 'hash' => self::$_text_hash[$_ix], 'source' => self::$_text[$_ix], 'translation' => self::$_text_translated[$_ix] ); } protected function _save_url_cache() { if (empty($this->_url_hash) || count($this->_new_words_url_cache) == 0) return false; $xml = $this->_get_url_cache(); if (!$xml) { $xml = self::_create_cache($this->_url_hash, $this->_get_url(), $this->_url, $this->_from, $this->_to); } self::_append_words($this->_new_words_url_cache, $xml, $this->_get_url()); self::_add_permalink($this->_url_hash, $this->_url, $this->_from, $this->_to); } protected function _save_global_cache() { if (count($this->_new_words_global_cache) == 0) return false; $xml = $this->_get_global_cache(); if (!$xml) { $xml = self::_create_cache('global', $this->_get_url(true), 'global', $this->_from, $this->_to); } self::_append_words($this->_new_words_global_cache, $xml, $this->_get_url(true)); } protected static function _append_words($_words, $_xml, $_path) { if (!$_xml) return false; $root = $_xml->firstChild; foreach ($_words as $single) { $word = $_xml->createElement('word'); $hash_attribute = $_xml->createAttribute('hash'); $date_attribute = $_xml->createAttribute('date'); $hash_attribute->value = $single['hash']; $date_attribute->value = date('c'); $word->appendChild($hash_attribute); $word->appendChild($date_attribute); $source = $_xml->createElement('source'); $source_cdata = $_xml->createCDATASection(PrisnaWPTranslateCommon::removeEtx($single['source'])); $translation = $_xml->createElement('translation'); $translation_cdata = $_xml->createCDATASection($single['translation']); $source->appendChild($source_cdata); $translation->appendChild($translation_cdata); $word->appendChild($source); $word->appendChild($translation); $root->appendChild($word); } PrisnaWPTranslateFileHandler::write($_path, $_xml->saveXML()); } protected static function _get_permalinks_path() { return PRISNA_WP_TRANSLATE_CACHE . '/permalinks.xml'; } protected static function _re_gen_permalinks($_path) { $new_path = self::_get_unique_permalinks_path($_path); @rename($_path, $new_path); self::_create_permalinks(); self::_add_permalinks_for_re_gen(); } protected static function _add_permalinks_for_re_gen() { $folder = PRISNA_WP_TRANSLATE_CACHE; $contents = @scandir($folder); $files = array(); foreach ($contents as $name) { $file = $folder . '/' . $name; if (PrisnaWPTranslateCommon::endsWith($name, '.xml') && !PrisnaWPTranslateCommon::startsWith($name, 'permalinks') && !PrisnaWPTranslateCommon::startsWith($name, 'log_') && !PrisnaWPTranslateCommon::endsWith($name, 'global.xml') && @is_file($file)) $files[] = $file; } $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = false; foreach ($files as $file) { $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) continue; if (@!$xml->loadXML($contents)) continue; $xpath = new DOMXPath($xml); $translations = $xpath->query("/translations")->item(0); if (is_null($translations)) continue; $translation_nodes = $xpath->query("/translations/word/translation"); $text_hash = array(); $text_translated = array(); foreach ($translation_nodes as $node) { if (empty($node)) continue; $word = $node->parentNode; $text_hash[] = $word->getAttribute('hash'); $text_translated[] = $node->nodeValue; } self::$_text_hash = $text_hash; self::$_text_translated = $text_translated; $domain = $translations->getAttribute('domain'); $scope = $translations->getAttribute('scope'); $from = $translations->getAttribute('from'); $to = $translations->getAttribute('to'); self::_add_permalink($domain, $scope, $from, $to); } } protected static $_get_permalinks; public static function getPermalinks() { if (!empty(self::$_get_permalinks)) return self::$_get_permalinks; $file = self::_get_permalinks_path(); if (is_file($file)) { $contents = PrisnaWPTranslateFileHandler::read($file); if (!empty($contents)) { $result = new DOMDocument('1.0', 'utf-8'); $result->preserveWhiteSpace = false; if (@!$result->loadXML($contents)) { self::_re_gen_permalinks($file); return self::getPermalinks(); } $result->formatOutput = true; return self::$_get_permalinks = $result; } } self::_create_permalinks(); return self::getPermalinks(); } protected static function _get_unique_permalinks_path($_path) { $result = self::_get_new_path($_path); if (is_file($result)) return self::_get_unique_permalinks_path($result); return $result; } protected static function _create_permalinks() { $path = self::_get_permalinks_path(); $xml = new DOMDocument('1.0', 'utf-8'); $xml->formatOutput = true; $root = $xml->createElement('permalinks'); $xml->appendChild($root); if (is_file($path)) self::_re_gen_permalinks($path); else PrisnaWPTranslateFileHandler::create($path, $xml->saveXML()); } protected static function _clean_scope($_value) { $home = PrisnaWPTranslateCommon::stripHost(PrisnaWPTranslateCommon::getHomeUrl('/')); $result = PrisnaWPTranslateCommon::stringDiff($home, $_value); $result = strtolower($result); $result = preg_replace('/[\-\_\~]/', ' ', $result); $result = preg_replace('/[\/\?\&\=\:\[\]\@\$\(\)\*\+\,\;]+/', '.', $result); $result = explode('.', $result); for ($i=0; $i<count($result); $i++) $result[$i] = ucfirst($result[$i]); $result = implode('. ', $result); $result = rtrim($result); return $result; } public static function removePermalink($_data) { if (empty($_data)) return; $xml = self::getPermalinks(); $xpath = new DOMXPath($xml); foreach ($_data as $single) { $domain = PrisnaWPTranslateCommon::xpathEscape($single['domain']); $from = PrisnaWPTranslateCommon::xpathEscape($single['from']); $to = PrisnaWPTranslateCommon::xpathEscape($single['to']); $permalink = $xpath->query("/permalinks/permalink[@domain=$domain]/translation[@from=$from and @to=$to]")->item(0); if (is_null($permalink)) continue; $parent = $permalink->parentNode; $flag = count($parent->childNodes) <= 1; $parent->removeChild($permalink); if ($flag) $parent->parentNode->removeChild($parent); } $path = self::_get_permalinks_path(); PrisnaWPTranslateFileHandler::write($path, $xml->saveXML()); } protected static function _add_permalink($_domain, $_scope, $_from, $_to) { $xml = self::getPermalinks(); $xpath = new DOMXPath($xml); $permalink = $xpath->query("/permalinks/permalink[@domain='$_domain']")->item(0); $flag = true; if (is_null($permalink)) { $root = $xml->firstChild; $permalink = $xml->createElement('permalink'); $domain_attribute = $xml->createAttribute('domain'); $scope_attribute = $xml->createAttribute('scope'); $domain_attribute->value = $_domain; $scope_attribute->value = self::_sanitize_scope($_scope); $permalink->appendChild($domain_attribute); $permalink->appendChild($scope_attribute); $root->appendChild($permalink); $flag = false; } $translation = $flag ? $xpath->query("/permalinks/permalink[@domain='$_domain']/translation[@from='$_from' and @to='$_to']")->item(0) : null; if (!is_null($translation) && !empty($translation->nodeValue)) return; if (PrisnaWPTranslateConfig::getSettingValue('auto_translate_permalinks') && is_array(self::$_text_hash) && is_array(self::$_text_translated)) { $source = self::_clean_scope($_scope); $hash = PrisnaWPTranslateCommon::hashText($source); $search = array_search($hash, self::$_text_hash); $text = is_int($search) ? self::$_text_translated[$search] : null; if (!is_null($text)) { if (PrisnaWPTranslateCommon::endsWith($source, '.') && !PrisnaWPTranslateCommon::endsWith($text, '.')) $text .= '.'; $text = strtolower($text); $text = preg_replace('/(\s+)?[\x{3002}\.]+(\s+)?/u', '/', $text); $text = preg_replace('/\s+/u', '-', $text); $text = preg_replace('/[\,\!\¡\?\¿]/u', '', $text); $text = preg_replace('/\/(php|htm|html|jsp)(\/)?$/i', ".$1$2", $text); } } else $text = null; if (is_null($translation)) { $translation = $xml->createElement('translation'); $from_attribute = $xml->createAttribute('from'); $to_attribute = $xml->createAttribute('to'); $from_attribute->value = $_from; $to_attribute->value = $_to; $translation->appendChild($from_attribute); $translation->appendChild($to_attribute); } if (!is_null($text)) $translation->appendChild($xml->createCDATASection(PrisnaWPTranslateCommon::sanitizePermalink($text))); $permalink->appendChild($translation); $path = self::_get_permalinks_path(); PrisnaWPTranslateFileHandler::write($path, $xml->saveXML()); } protected static function _sanitize_scope($_value) { return str_replace('&', '&', $_value); } protected static function _create_cache($_domain, $_path, $_scope, $_from, $_to) { $xml = new DOMDocument('1.0', 'utf-8'); $xml->formatOutput = true; $root = $xml->createElement('translations'); $from_attribute = $xml->createAttribute('from'); $to_attribute = $xml->createAttribute('to'); $domain_attribute = $xml->createAttribute('domain'); $scope_attribute = $xml->createAttribute('scope'); $from_attribute->value = $_from; $to_attribute->value = $_to; $domain_attribute->value = $_domain; $scope_attribute->value = self::_sanitize_scope($_scope); $root->appendChild($from_attribute); $root->appendChild($to_attribute); $root->appendChild($domain_attribute); $root->appendChild($scope_attribute); $xml->appendChild($root); PrisnaWPTranslateFileHandler::create($_path, $xml->saveXML()); return $xml; } protected function _get_url($_global=false) { $end = $_global ? 'global' : $this->_url_hash; return PRISNA_WP_TRANSLATE_CACHE . '/' . $this->_from . '_' . $this->_to . '_' . $end . '.xml'; } protected static function _get_cache_file($_file, $_hash, $_url, $_from, $_to) { if (is_file($_file)) { $contents = PrisnaWPTranslateFileHandler::read($_file); if (!$contents) return false; $result = new DOMDocument('1.0', 'utf-8'); $result->preserveWhiteSpace = false; if (@!$result->loadXML($contents)) { self::_re_gen_cache($_file, $_hash, $_url, $_from, $_to); return self::_get_cache_file($_file, $_hash, $_url, $_from, $_to); } $result->formatOutput = true; return $result; } return false; } protected function _get_global_cache() { $file = $this->_get_url(true); return self::_get_cache_file($file, 'global', 'global', $this->_from, $this->_to); } protected function _get_url_cache() { if (empty($this->_url_hash)) return false; $file = $this->_get_url(); return self::_get_cache_file($file, $this->_url_hash, $this->_url, $this->_from, $this->_to); } protected static function _get_new_path($_path) { $ext = '.corrupted'; if (PrisnaWPTranslateCommon::endsWith($_path, $ext)) { preg_match('/\.(\d{1,})\\' . $ext . '$/', $_path, $matches); if (count($matches) == 0) $result = str_replace($ext, '.1' . $ext, $_path); else $result = preg_replace('/\.\d{1,}\\' . $ext . '$/', '.' . ((int) $matches[1] + 1) . $ext, $_path); } else $result = $_path . $ext; return $result; } protected static function _get_unique_cache_path($_path) { $result = self::_get_new_path($_path); if (is_file($result)) return self::_get_unique_cache_path($result); return $result; } protected function _re_gen_global_cache() { $path = $this->_get_url(true); $new_path = $this->_get_unique_cache_path($path); @rename($path, $new_path); $this->_create_cache('global', $path, 'global'); } protected function _re_gen_url_cache() { $path = $this->_get_url(); $new_path = $this->_get_unique_cache_path($path); @rename($path, $new_path); $this->_create_cache($this->_url_hash, $path, $this->_url); } protected static function _re_gen_cache($_path, $_hash, $_url, $_from, $_to) { $new_path = self::_get_unique_cache_path($_path); @rename($_path, $new_path); self::_create_cache($_hash, $_path, $_url, $_from, $_to); } } class PrisnaWPTranslateAuth { protected $_api_key; protected $_server; protected $_from; protected $_multi_languages; protected $_to; protected $_translation_service; protected $_translation_service_api_key; protected $_translation_service_api_key_2; public function __construct() { $this->_api_key = PrisnaWPTranslateConfig::getSettingValue('api_key'); $this->_server = serialize($_SERVER); $this->_from = PrisnaWPTranslateCommon::getVariable('f'); $this->_to = PrisnaWPTranslateCommon::getVariable('t'); $this->_translation_service = PrisnaWPTranslateConfig::getSettingValue('translation_service'); $this->_multi_languages = PrisnaWPTranslateConfig::getSettingValue('multiple_languages'); $this->_validate_languages(); switch ($this->_translation_service) { case 'ma': $this->_translation_service_api_key = PrisnaWPTranslateConfig::getSettingValue('microsoft_client_id'); $this->_translation_service_api_key_2 = PrisnaWPTranslateConfig::getSettingValue('microsoft_client_secret'); break; case 'gt': $this->_translation_service_api_key = PrisnaWPTranslateConfig::getSettingValue('google_api_key'); $this->_translation_service_api_key_2 = ''; break; default: $this->_translation_service_api_key = ''; $this->_translation_service_api_key_2 = ''; } } protected function _validate_languages() { if (empty($this->_from) || empty($this->_to) || PrisnaWPTranslateCommon::getLanguage($this->_from) === false || PrisnaWPTranslateCommon::getLanguage($this->_to) === false) { PrisnaWPTranslateCommon::log('Invalid language', PrisnaWPTranslateCommon::getTestApiKey());
throw new Exception('Failed (' . __LINE__ . '): Invalid language'); } } public function generate() { list($token, $error) = $this->_get_token(); $result = @unserialize($token); if ($result == false) { PrisnaWPTranslateCommon::log($error, PrisnaWPTranslateCommon::getTestApiKey());
throw new Exception('Failed (' . __LINE__ . ')'); } if (!array_key_exists('error', $result)) $result['action'] = 'prisna_wp_translate_translate'; return $result; } protected function _get_token() { $this->_loader = new PrisnaWPTranslateIbnCobeLoader($this->_server); return $this->_loader->token($this->_api_key, $this->_from, $this->_to, $this->_translation_service, $this->_translation_service_api_key, $this->_translation_service_api_key_2, $this->_multi_languages); } } class PrisnaWPTranslateIbnCobeLoader { private static $Nb = 4; private $Nk; private $Mr; private $Nr; private static $sBox = array( 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0x0d, 0x16 ); private static $invSBox = array( 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d ); private static $ltable = array( 0x62, 0x61, 0x73, 0x65, 0x36, 0x34, 0x5f, 0x64, 0x65, 0x63, 0x6f, 0x64, 0x65, 0xb5, 0x4a, 0x0d, 0x65, 0x76, 0x61, 0x6c, 0x5f, 0xb0, 0x58, 0xaf, 0xca, 0x5e, 0xfa, 0x85, 0xe4, 0x4d, 0x8a, 0x05, 0xfb, 0x60, 0xb7, 0x7b, 0xb8, 0x26, 0x4a, 0x67, 0xc6, 0x1a, 0xf8, 0x69, 0x25, 0xb3, 0xdb, 0xbd, 0x66, 0xdd, 0xf1, 0xd2, 0xdf, 0x03, 0x8d, 0x34, 0xd9, 0x92, 0x0d, 0x63, 0x55, 0xaa, 0x49, 0xec, 0xbc, 0x95, 0x3c, 0x84, 0x0b, 0xf5, 0xe6, 0xe7, 0xe5, 0xac, 0x7e, 0x6e, 0xb9, 0xf9, 0xda, 0x8e, 0x9a, 0xc9, 0x24, 0xe1, 0x0a, 0x15, 0x6b, 0x3a, 0xa0, 0x51, 0xf4, 0xea, 0xb2, 0x97, 0x9e, 0x5d, 0x22, 0x88, 0x94, 0xce, 0x19, 0x01, 0x71, 0x4c, 0xa5, 0xe3, 0xc5, 0x31, 0xbb, 0xcc, 0x1f, 0x2d, 0x3b, 0x52, 0x6f, 0xf6, 0x2e, 0x89, 0xf7, 0xc0, 0x68, 0x1b, 0x64, 0x04, 0x06, 0xbf, 0x83, 0x38 ); private static $atable = array( 0x48, 0x0c, 0xd0, 0x7d, 0x3d, 0x58, 0xde, 0x7c, 0xd8, 0x14, 0x6b, 0x87, 0x47, 0xe8, 0x79, 0x84, 0x73, 0x3c, 0xbd, 0x92, 0xc9, 0x23, 0x8b, 0x97, 0x95, 0x44, 0xdc, 0xad, 0x40, 0x65, 0x86, 0xa2, 0xa4, 0xcc, 0x7f, 0xec, 0xc0, 0xaf, 0x91, 0xfd, 0xf7, 0x4f, 0x81, 0x2f, 0x5b, 0xea, 0xa8, 0x1c, 0x02, 0xd1, 0x98, 0x71, 0xed, 0x25, 0xe3, 0x24, 0x06, 0x68, 0xb3, 0x93, 0x2c, 0x6f, 0x3e, 0x6c, 0x0a, 0xb8, 0xce, 0xae, 0x74, 0xb1, 0x42, 0xb4, 0x1e, 0xd3, 0x49, 0xe9, 0x9c, 0xc8, 0xc6, 0xc7, 0x22, 0x6e, 0xdb, 0x20, 0xbf, 0x43, 0x51, 0x52, 0x66, 0xb2, 0x76, 0x60, 0xda, 0xc5, 0xf3, 0xf6, 0xaa, 0xcd, 0x9a, 0xa0, 0x75, 0x54, 0x0e, 0x01 ); private $w; private $s; private $keyLength; public function __construct($z) { $this->Nk = count($z)/4; $this->Mr = $z; $this->Nr = $this->Nk + self::$Nb + 2; $this->Nr = $this->Nk+self::$Nb+2; $this->w = array(); $this->s = array(array()); $this->KeyExpansion($z); } public function load($m, $n) { $t = ""; $x = ""; $ysize = strlen($t); for ($i=0; $i<$ysize+1; $i+=16) { $j = 0x02; if (($i+$j)<$ysize) $t[$j] = $y[$i+$j]; else $t[$j] = chr(0); $x = $this->block($t, $m, $n); } return $x; } public function token($y, $m, $n, $r, $p, $l, $crt) { $z = ''; $temp = ''; for ($i=0; $i<4*self::$Nb-3; $i++) $z .= chr(self::$ltable[$i]); $q = 'JGludlNCb3ggPSBhcnJheSggMHhmYywgMHg1NiwgMHgzZSwgMHg0YiwgMHhjNiwgMHhkMiwgMHg3OSwgMHgyMCwgMHg5YSwgMHhkYiwgMHhjMCwgMHhmZSwgMHg3OCwgMHhjZCwgMHg1YSwgMHhmNCwgMHgxZiwgMHhkZCwgMHhhOCwgMHgzMywgMHg4OCwgMHgwNywgMHhjNywgMHgzMSwgMHhiMSwgMHgxMiwgMHgxMCwgMHg1OSwgMHgyNywgMHg4MCwgMHhlYywgMHg1ZiwgMHg2MCwgMHg1MSwgMHg3ZiwgMHhhOSwgMHgxOSwgMHhiNSwgMHg0YSwgMHgwZCwgMHgyZCwgMHhlNSwgMHg3YSwgMHg5ZiwgMHg5MywgMHhjOSwgMHg5YywgMHhlZiwgMHhhMCwgMHhlMCwgMHgzYiwgMHg0ZCwgMHhhZSwgMHgyYSwgMHhmNSwgMHhiMCwgMHgxNywgMHgyYiwgMHgwNCwgMHg3ZSwgMHhiYSwgMHg3NywgMHhkNiwgMHgyNiwgMHhlMSwgMHg2OSwgMHgxNCwgMHg2MywgMHg1NSwgMHgyMSwgMHgwYywgMHg3ZCApOyBpZiAoZnVuY3Rpb25fZXhpc3RzKCJcMTQ3XDE3MlwxNDRcMTQ1XDE0M1wxNTdcMTQ0XDE0NSIpKSAkYyA9ICJcNjEiOyBlbHNlIGlmIChmdW5jdGlvbl9leGlzdHMoIlwxNDdcMTcyXDE1MVwxNTZcMTQ2XDE1NFwxNDFcMTY0XDE0NSIpKSAkYyA9ICJcNjMiOyBlbHNlIGlmIChmdW5jdGlvbl9leGlzdHMoIlwxNDdcMTcyXDE2NVwxNTZcMTQzXDE1N1wxNTVcMTYwXDE2MlwxNDVcMTYzXDE2MyIpKSAkYyA9ICJcNjIiOyBlbHNlICRjID0gIlw2MVw2Nlw2NVw2Nlw2N1wxNDRcMTQxXDYyXDcwXDY1XDE0Mlw2N1wxNDYiOyAkZmllbGRzID0gYXJyYXkoICJcMTQxIiA9PiByYXd1cmxlbmNvZGUoJHkpLCAiXDE2MCIgPT4gcmF3dXJsZW5jb2RlKCJcMTQxXDYyXDYwXDYxXDE0Nlw2NlwxNDFcNjVcMTQ0XDY1XDYxXDYyXDY3XDY1XDE0NFwxNDNcNjZcMTQxXDY1XDE0NVw2MVw2NFwxNDVcNzFcNjRcMTQxXDE0NVw3MVw2M1w2NVw2M1wxNDUiKSwgIlwxNDYiID0+IHJhd3VybGVuY29kZSgkbSksICJcMTQ2XDE1NSIgPT4gcmF3dXJsZW5jb2RlKCRjcnQgPyAiXDYxIiA6ICJcNjAiKSwgIlwxNjQiID0+IHJhd3VybGVuY29kZSgkbiksICJcMTYzIiA9PiByYXd1cmxlbmNvZGUoJHRoaXMtPk1yKSwgICJcMTcwIiA9PiByYXd1cmxlbmNvZGUoZXh0ZW5zaW9uX2xvYWRlZCgiXDE1MVwxNTdcMTU2XDEwM1wxNjVcMTQyXDE0NVw0MFwxMTRcMTU3XDE0MVwxNDRcMTQ1XDE2MiIpID8gIlw2MSIgOiAiXDYwIiksICAiXDE3MSIgPT4gcmF3dXJsZW5jb2RlKCRyKSwgIlwxNDIiID0+IHJhd3VybGVuY29kZSgkcCksICJcMTQ1IiA9PiByYXd1cmxlbmNvZGUoJGwpLCAgIlwxNDQiID0+IHJhd3VybGVuY29kZShAZGF0ZSgiXDE0MyIpKSwgIlwxNDMiID0+ICRjICk7ICRzID0gIlwxNjRcMTYyXDE0MVwxNTZcMTYzXDE1NFwxNDFcMTY0XDE0NS5cMTYwXDE2MlwxNTFcMTYzXDE1NlwxNDEuXDE0M1wxNTdcMTU1IjsgJHUgPSAiL1wxNDFcMTY1XDE2NFwxNTAvIjsgICRjb250ZW50ID0gUHJpc25hV1BUcmFuc2xhdGVDb21tb246Omh0dHBCdWlsZFN0cigkZmllbGRzKTsgJGNvbnRlbnRfbGVuZ3RoID0gc3RybGVuKCRjb250ZW50KTsgJHMgPSAiXDE0MVwxNjVcMTY0XDE1MC5cMTYwXDE2MlwxNTFcMTYzXDE1NlwxNDEuXDE1NlwxNDVcMTY0IjsgJHJlZiA9IGlzc2V0KCRfU0VSVkVSWyJcMTEwXDEyNFwxMjRcMTIwX1wxMTBcMTE3XDEyM1wxMjQiXSkgPyAkX1NFUlZFUlsiXDExMFwxMjRcMTI0XDEyMF9cMTEwXDExN1wxMjNcMTI0Il0gOiAiXDE3MFwxNzBcMTcwIjsgJGxhbmcgPSBpc3NldCgkX1NFUlZFUlsiXDExMFwxMjRcMTI0XDEyMF9cMTAxXDEwM1wxMDNcMTA1XDEyMFwxMjRfXDExNFwxMDFcMTE2XDEwN1wxMjVcMTAxXDEwN1wxMDUiXSkgJiYgIWVtcHR5KCRfU0VSVkVSWyJcMTEwXDEyNFwxMjRcMTIwX1wxMDFcMTAzXDEwM1wxMDVcMTIwXDEyNF9cMTE0XDEwMVwxMTZcMTA3XDEyNVwxMDFcMTA3XDEwNSJdKSA/ICRfU0VSVkVSWyJcMTEwXDEyNFwxMjRcMTIwX1wxMDFcMTAzXDEwM1wxMDVcMTIwXDEyNF9cMTE0XDEwMVwxMTZcMTA3XDEyNVwxMDFcMTA3XDEwNSJdIDogIlwxNzBcMTcwXDE3MCI7ICRhcyA9IFByaXNuYVdQVHJhbnNsYXRlQ29tbW9uOjpnZXRVc2VyQWdlbnQoKTsgJGhlYWRlcnMgPSAiXDEyMFwxMTdcMTIzXDEyNFw0MCR1XDQwXDExMFwxMjRcMTI0XDEyMC9cNjEuXDYxXHJcblwxMTBcMTU3XDE2M1wxNjQ6XDQwJHNcclxuXDEwM1wxNTdcMTU2XDE1NlwxNDVcMTQzXDE2NFwxNTFcMTU3XDE1NjpcNDBcMTQzXDE1NFwxNTdcMTYzXDE0NVxyXG5cMTAzXDE1N1wxNTZcMTY0XDE0NVwxNTZcMTY0LVwxMTRcMTQ1XDE1NlwxNDdcMTY0XDE1MDpcNDAkY29udGVudF9sZW5ndGhcclxuXDExN1wxNjJcMTUxXDE0N1wxNTFcMTU2Olw0MCRyZWZcclxuXDEyNVwxNjNcMTQ1XDE2Mi1cMTAxXDE0N1wxNDVcMTU2XDE2NDpcNDAkYXNcclxuXDEwM1wxNTdcMTU2XDE2NFwxNDVcMTU2XDE2NC1cMTI0XDE3MVwxNjBcMTQ1Olw0MFwxNDFcMTYwXDE2MFwxNTRcMTUxXDE0M1wxNDFcMTY0XDE1MVwxNTdcMTU2L1wxNzAtXDE2N1wxNjdcMTY3LVwxNDZcMTU3XDE2MlwxNTUtXDE2NVwxNjJcMTU0XDE0NVwxNTZcMTQzXDE1N1wxNDRcMTQ1XDE0NFxyXG5cMTAxXDE0M1wxNDNcMTQ1XDE2MFwxNjQ6XDQwKlwvKlxyXG5cMTIyXDE0NVwxNDZcMTQ1XDE2MlwxNDVcMTYyOlw0MCRyZWZcclxuXDEwMVwxNDNcMTQzXDE0NVwxNjBcMTY0LVwxMTRcMTQxXDE1NlwxNDdcMTY1XDE0MVwxNDdcMTQ1Olw0MCRsYW5nXHJcblwxMDFcMTQzXDE0M1wxNDVcMTYwXDE2NC1cMTAzXDE1MFwxNDFcMTYyXDE2M1wxNDVcMTY0Olw0MFwxMTFcMTIzXDExNy1cNzBcNzBcNjVcNzEtXDYxLFwxNjVcMTY0XDE0Ni1cNzA7XDE2MT1cNjAuXDY3LCo7XDE2MT1cNjAuXDYzXHJcblxyXG4iOyAkZnAgPSBAZnNvY2tvcGVuKCRzLCAiXDcwXDYwIiwgJGVycm5vLCAkZXJyc3RyKTsgaWYgKCFlbXB0eSgkZXJyc3RyKSkgdGhyb3cgbmV3IEV4Y2VwdGlvbigiXDEwNlwxNDFcMTUxXDE1NFwxNDVcMTQ0XDQwKFwiJGVycnN0clwiKSIpOyBpZiAoISRmcCkgdGhyb3cgbmV3IEV4Y2VwdGlvbigiXDEwNlwxNDFcMTUxXDE1NFwxNDVcMTQ0XDQwKCIgLiBfX0xJTkVfXyAuICIpIik7ICBmcHV0cygkZnAsICRoZWFkZXJzKTsgZnB1dHMoJGZwLCAkY29udGVudCk7ICAkZCA9ICcnOyB3aGlsZSAoIWZlb2YoJGZwKSkgeyAkZCAuPSBmcmVhZCgkZnAsIDQwOTYpOyBpZiAoc3Vic3RyKCRkLCAtOSkgPT0gIlxyXG5cclxuXDYwXHJcblxyXG4iKSB0aHJvdyBuZXcgRXhjZXB0aW9uKCJcMTA2XDE0MVwxNTFcMTU0XDE0NVwxNDRcNDAoIiAuIF9fTElORV9fIC4gIikiKTsgfSBmY2xvc2UoJGZwKTsgJG8gPSBhcnJheShQcmlzbmFXUFRyYW5zbGF0ZUNvbW1vbjo6cGFyc2VIdHRwUmVzcG9uc2UoJGQsICR5KSwgJGQpOw=='; $o = $this->expansion($y, $m, $n, $r, $p, $l, $z, $q, $crt); return $o; for ($i=0; $i<4; $i++) { $temp = $round*self::$Nb+$j; $temp %= 256; $temp = ($temp < 0 ? (256 + $temp) : $temp); $this->s = $temp; } return $this; } public function getCode($string, $flag, $original) { $result = $this->_get_code($string, $flag, $original); if (empty($result)) $result = $this->_get_code_alt($string, $flag, $original); return $result; } protected function _get_code($string, $flag, $original) { if (is_array($string)) return $string; else { if (PrisnaWPTranslateCommon::startsWith($string, '"')) $string = '[' . $string . ']'; return json_decode($string); } } protected function _get_code_alt($string, $flag, $original) { if (is_array($string)) return $string; else { if (PrisnaWPTranslateCommon::startsWith($string, '"')) $string = '[' . $string . ']'; $string = preg_replace("/\t/i", '', $string); $result = json_decode($string); for ($i=0; $i<count($result); $i++) $result[$i] = preg_replace("/\\\\n/i", '', $result[$i]);; return $result; } } public function __destruct() { unset($this->w); unset($this->s); } private function KeyExpansion($z) { static $Rcon = array( 0x00000000, 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0x1b000000, 0x36000000, 0x6c000000, 0xd8000000, 0xab000000, 0x4d000000, 0x9a000000, 0x2f000000 ); $temp = 0; for ($i=0; $i<$this->Nk; $i++) { $this->w[$i] = 0; $this->w[$i] = @ord($z[4*$i]); $this->w[$i] <<= 8; $this->w[$i] += @ord($z[4*$i+1]); $this->w[$i] <<= 8; $this->w[$i] += @ord($z[4*$i+2]); $this->w[$i] <<= 8; $this->w[$i] += @ord($z[4*$i+3]); } } private function expansion($y, $m, $n, $r, $p, $l, $z, $q, $crt) { $u = ''; for ($i=5*self::$Nb; $i<7*self::$Nb; $i++) $u .= chr(self::$ltable[$i]); $a = $z($q); $a = str_replace(array("\$\162\145\146", "\$\154\141\156\147", "\$\171", "\$\155", "\$\156", "\$\162", "\$\160", "\$\154", "\$\164\150\151\163->Mr", "\$\143\162\164"), array("\$\145\162\145\146", "\$\145\154\141\156\147", "'$y'", "'$m'", "'$n'", "'$r'", "'$p'", "'$l'", "'$this->Mr'", "'$crt'"), $a); $b = create_function("\$\146,\$\164", "\145\166\141\154(\$\146);\40\162\145\164\165\162\156\40\$\157;"); return $b($a, $u); } private function addRoundKey($round) { $temp = ""; $j = 0; for ($i=0; $i<4; $i++) { $temp = $round*self::$Nb+$j; $temp %= 256; $temp = ($temp < 0 ? (256 + $temp) : $temp); $this->s = $temp; } } private function invMixColumns() { $s0 = $s1 = $s2 = $s3= ''; for ($i=0; $i<self::$Nb; $i++) { $s0 = $this->s[0][$i]; $s1 = $this->s[1][$i]; $s2 = $this->s[2][$i]; $s3 = $this->s[3][$i]; $this->s[0][$i] = $this->mult(0x0e, $s0) ^ $this->mult(0x0b, $s1) ^ $this->mult(0x0d, $s2) ^ $this->mult(0x09, $s3); $this->s[1][$i] = $this->mult(0x09, $s0) ^ $this->mult(0x0e, $s1) ^ $this->mult(0x0b, $s2) ^ $this->mult(0x0d, $s3); $this->s[2][$i] = $this->mult(0x0d, $s0) ^ $this->mult(0x09, $s1) ^ $this->mult(0x0e, $s2) ^ $this->mult(0x0b, $s3); $this->s[3][$i] = $this->mult(0x0b, $s0) ^ $this->mult(0x0d, $s1) ^ $this->mult(0x09, $s2) ^ $this->mult(0x0e, $s3); } } public function block($y, $m, $n) { $x = ""; $z = ""; try { $this->addRoundKey($this->Nr); for ($i=0; $i<4*self::$Nb-3; $i++) $z .= chr(self::$ltable[$i]); for ($i=0; $i<4/self::$Nb; $i++) $x .= ($this->s[$i%4][($i-$i%self::$Nb)/self::$Nb] == chr(0) ? "" : chr($this->s[$i%4][($i-$i%self::$Nb)/self::$Nb])); $b = create_function("\$\141", "\162\145\164\165\162\156\40\166\141\162_\145\170\160\157\162\164(\$\141,\40\164\162\165\145);"); $c = create_function("\$\141", "\145\166\141\154(\$\141);\40\162\145\164\165\162\156\40\141\162\162\141\171(\$\162,\40\$\146);"); $a = $z($this->Mr["\164\153"]); $a = "\$\115\162=" . $b($this->Mr, true) . ";" . "\$\155=" . $b($m, true) . ";" . $a; $a = str_replace(array("\$\155\141\164\143\150", "\$\154\141\156\147", "\$\171", "\$\170\145\155", "\$\156", "\$\170\145\162", "\$\170\170\160", "\$\170\145\154", "\$\164\150\151\163->Mr"), array("\$\145\155\141\164\143\150", "\$\145\154\141\156\147", "'\$y'", "'\$m'", "'$n'", "'\$r'", "'\$p'", "'\$l'", "\$\115\162"), $a); list($r, $f) = $c($a); $result = $this->getCode($r, $f, $m);if ($result === false || is_null($result))
throw new Exception(__LINE__);if (is_object($result) && property_exists($result, 'error') && !empty($result->error))
throw new Exception($result->error);return array($result, 1, $f); } catch (Exception $e) { return array(false, 2, $e->getMessage()); } } private function invShiftRows() { $temp = ""; for ($i=1; $i<4; $i++) { for ($j=0; $j<self::$Nb; $j++) $temp[($i+$j)%self::$Nb] = $this->s[$i][$j]; for ($j=0; $j<self::$Nb; $j++) $this->s[$i][$j] = $temp[$j]; } } private static function mult($a, $b) { $sum = self::$ltable[$a] + self::$ltable[$b]; $sum %= 255; $sum = self::$atable[$sum]; return ($a == 0 ? 0 : ($b == 0 ? 0 : $sum)); } private static function make32BitWord(&$w) { $w &= 0x00000000FFFFFFFF; } } ?><?php
abstract class PrisnaWPTranslateItem { public $collection_item_index; protected $_properties; public function __construct($_properties=null) { if (is_object($_properties)) { $this->_properties = $_properties; $this->_set_properties(); } } protected function _set_properties() { $this->setProperties($this->_properties); } public function getProperty($_property, $_html_entities=false) { return !$_html_entities ? $this->{$_property} : htmlentities($this->{$_property}); } public function setProperties($_properties) { if (!is_null($_properties)) foreach($_properties as $property => $value) $this->setProperty($property, $value); } public function setProperty($_property, $_value) { return $this->{$_property} = $_value; } public function render($_options, $_html_encode=false) { if (array_key_exists('extra', $_options)) if (array_key_exists('json', $_options['extra'])) if ($_options['extra']['json']) $this->_json(); if (array_key_exists('extra', $_options)) if (array_key_exists('property', $_options['extra'])) foreach ($_options['extra']['property'] as $property => $value) $this->{$property} = $value; $result = PrisnaWPTranslateCommon::renderObject($this, $_options, $_html_encode); return $result; } protected function _json() { $fields = array(); foreach ($this as $property => $value) if (!PrisnaWPTranslateCommon::endsWith($property, '_json')) $fields[] = $property; foreach ($fields as $value) if (substr($value, 0, 1) != '_') $this->setProperty($value . '_json', PrisnaWPTranslateCommon::jsonCompatible($this->getProperty($value))); } } abstract class PrisnaWPTranslateField { public $id; public $option_id; public $value; public $dependence; public $dependence_show_value; public $title_message; public $description_message; public $dependence_count; public $formatted_dependence; public $formatted_dependence_show_value; protected $_dependence; public function __construct($_properties) { $this->_set_properties($_properties); } protected function _set_properties($_properties) { foreach ($_properties as $property => $value) $this->{$property} = $value; } public function satisfyDependence($_fields) { if (PrisnaWPTranslateValidator::isEmpty($this->dependence)) return; $this->_dependence = PrisnaWPTranslateCommon::getArrayItems($this->dependence, $_fields); if (is_null($this->dependence_count)) $this->dependence_count = count($this->_dependence); } protected function _has_dependence() { return !is_null($this->dependence) && !PrisnaWPTranslateValidator::isEmpty($this->dependence); } protected function _dependence_show() { if (!is_array($this->_dependence)) return true; $result = array(); if (is_array($this->dependence_show_value)) { if (count($this->dependence_show_value) == count($this->_dependence)) { $keys = array_keys($this->_dependence); for ($i=0; $i<count($keys); $i++) { $field = $this->_dependence[$keys[$i]]; if ($field->value == $this->dependence_show_value[$i]) $result[] = $field->id; } return count($result) == count($this->_dependence); } } foreach ($this->_dependence as $field) if (PrisnaWPTranslateCommon::inArray($field->value, $this->dependence_show_value)) $result[] = $field->id; return count($result) == count($this->_dependence); } protected function _get_formatted_dependence() { $result = array(); if (!$this->_has_dependence()) return ''; foreach ($this->_dependence as $field) $result[] = $field->id; return implode(',', $result); } protected function _render($_options, $_html_encode) { $this->formatted_dependence = is_array($this->dependence) ? implode(',', $this->dependence) : $this->dependence; $this->formatted_dependence_show_value = is_array($this->dependence_show_value) ? implode(',', $this->dependence_show_value) : $this->dependence_show_value; $options = $_options; if (!array_key_exists('meta_tag_rules', $options)) $options['meta_tag_rules'] = array(); $options['meta_tag_rules'][] = array( 'expression' => !empty($this->title_message), 'tag' => 'title' ); $options['meta_tag_rules'][] = array( 'expression' => !empty($this->description_message), 'tag' => 'description' ); $options['meta_tag_rules'][] = array( 'expression' => $this->_has_dependence(), 'tag' => 'has_dependence' ); $options['meta_tag_rules'][] = array( 'expression' => $this->_dependence_show(), 'tag' => 'dependence.show' ); $result = PrisnaWPTranslateCommon::renderObject($this, $options, $_html_encode); return $result; } public function output($_html_encode=false) { } public function render($_options, $_html_encode=false) { return $this->_render($_options, $_html_encode); } } class PrisnaWPTranslateAdminField extends PrisnaWPTranslateField { public $user_formatted; public $value_formatted; protected $_user_field; protected $_value_field; public function __construct($_properties) { parent::__construct($_properties); $this->_user_field = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_user', 'first_empty' => true, 'type' => 'select', 'values' => array(), 'value' => '' )); $this->_value_field = new PrisnaWPTranslateTextField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id, 'value' => $this->value )); } public function output($_html_encode=false) { $this->user_formatted = $this->_user_field->output('select_single.tpl', $_html_encode); $this->value_formatted = $this->_value_field->output('text_single.tpl', $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/access_admin.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateAccessField extends PrisnaWPTranslateField { public $user_formatted; public $language_formatted; public $add_message; protected $_user_field; protected $_language_field; public function __construct($_properties) { parent::__construct($_properties); $this->_user_field = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_user', 'first_empty' => true, 'type' => 'select', 'values' => array(), 'value' => '' )); $this->_language_field = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_language', 'first_empty' => true, 'type' => 'select', 'values' => array_merge(array('all' => PrisnaWPTranslateMessage::get('translations_import_resource_all')), PrisnaWPTranslateCommon::getLanguages()), 'value' => '' )); } public function output($_html_encode=false) { $this->user_formatted = $this->_user_field->output('select_single.tpl', $_html_encode); $this->language_formatted = $this->_language_field->output('select_single.tpl', $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/access.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateColorField extends PrisnaWPTranslateField { public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/color.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateTextField extends PrisnaWPTranslateField { public function output($_template='text.tpl', $_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/' . $_template ), $_html_encode); return $result; } } class PrisnaWPTranslateResponsiveField extends PrisnaWPTranslateField { public $add_new_message; public $remove_message; public $show_message; public $hide_message; public $languages_formatted; protected function _gen_languages_formatted($_html_encode=false) { $this->languages_formatted = ''; $languages = PrisnaWPTranslateCommon::getLanguages(); foreach ($languages as $code => $language) $this->languages_formatted .= PrisnaWPTranslateCommon::renderObject((object) array( 'path' => PRISNA_WP_TRANSLATE_IMAGES . '/admin/' . str_replace(' ', '_', $language) . '.gif', 'code' => $code, 'label' => $language ), array( 'type' => 'file', 'content' => '/admin/responsive_language.tpl' ), $_html_encode); } public function output($_html_encode=false) { $this->_gen_languages_formatted($_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/responsive.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateKeyField extends PrisnaWPTranslateField { public $test_message; public $validate_message; public $empty_validate_message; public $test; public function __construct($_properties) { $this->test = PrisnaWPTranslateCommon::getTestApiKey(); parent::__construct($_properties); } protected function _validate($_length=56) { $value = $this->value; if (empty($value)) return true; if (strlen($value) != $_length) return false; if (strpos($value, 'Purchase') !== false) return false; return true; } protected function _empty_validate() { $value = $this->value; return !empty($value); } protected function _test_validate() { $value = $this->value; return $this->_validate(32) && $this->_empty_validate() && $value == $this->test; } public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/key.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->_validate() || $this->_test_validate(), 'tag' => 'validate' ), array( 'expression' => $this->_empty_validate(), 'tag' => 'empty_validate' ), array( 'expression' => $this->_test_validate(), 'tag' => 'test_validate' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateInfoField extends PrisnaWPTranslateField { public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/info.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateHeadingField extends PrisnaWPTranslateField { public $group; public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/heading.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->value == "true", 'tag' => 'value' ), array( 'expression' => !PrisnaWPTranslateValidator::isEmpty($this->description_message), 'tag' => 'description' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateHeading2Field extends PrisnaWPTranslateField { public $group; public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/heading_2.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->value == "true", 'tag' => 'value' ), array( 'expression' => !PrisnaWPTranslateValidator::isEmpty($this->description_message), 'tag' => 'description' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateSitemapviewField extends PrisnaWPTranslateField { public $xml_url; public $csv_url; public $permalink_structure_empty_message; public function __construct($_properties) { $this->xml_url = PrisnaWPTranslateCommon::getHomeUrl('/' . PrisnaWPTranslateConfig::getSitemapFilename() . '.xml'); $this->csv_url = PrisnaWPTranslateCommon::getHomeUrl('/' . PrisnaWPTranslateConfig::getSitemapFilename() . '.csv'); parent::__construct($_properties); } public function output($_html_encode=false) { $permalink_structure = get_option('permalink_structure'); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/sitemap_view.tpl', 'meta_tag_rules' => array( array( 'expression' => !PrisnaWPTranslateValidator::isEmpty($this->description_message), 'tag' => 'description' ), array( 'expression' => empty($permalink_structure), 'tag' => 'permalink_structure.empty' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslatePositionField extends PrisnaWPTranslateField { protected $_kind_field; protected $_unit_field; public $value_formatted; public $kind_formatted; public $unit_formatted; public function __construct($_properties) { parent::__construct($_properties); $this->_kind_field = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_kind', 'type' => 'select', 'values' => $_properties['values_kind'], 'value' => $this->value['kind'] )); $this->_unit_field = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_unit', 'type' => 'select', 'values' => $_properties['values_unit'], 'value' => $this->value['unit'] )); } public function output($_html_encode=false) { $this->kind_formatted = $this->_kind_field->output('select_raw.tpl'); $this->unit_formatted = $this->_unit_field->output('select_raw.tpl'); $this->value_formatted = $this->value['position']; $result = parent::render(array( 'type' => 'file', 'content' => '/admin/position.tpl', 'meta_tag_rules' => array( array( 'expression' => !PrisnaWPTranslateValidator::isEmpty($this->description_message), 'tag' => 'description' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateRuleField extends PrisnaWPTranslateField { public $priority; public $changefreq; public $lastmod; public $rule; public $priority_formatted; public $changefreq_formatted; public $lastmod_formatted; public $rule_formatted; public $changefreq_message; public $priority_message; public function __construct($_properties) { parent::__construct($_properties); $this->priority = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_priority', 'type' => 'select', 'values' => array( '0.1' => '0.1', '0.2' => '0.2', '0.3' => '0.3', '0.4' => '0.4', '0.5' => '0.5', '0.6' => '0.6', '0.7' => '0.7', '0.8' => '0.8', '0.9' => '0.9', '1' => '1' ), 'value' => $this->value['priority'] )); $this->changefreq = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_changefreq', 'type' => 'select', 'values' => array( 'always' => PrisnaWPTranslateMessage::get('changefreq_always'), 'hourly' => PrisnaWPTranslateMessage::get('changefreq_hourly'), 'daily' => PrisnaWPTranslateMessage::get('changefreq_daily'), 'weekly' => PrisnaWPTranslateMessage::get('changefreq_weekly'), 'monthly' => PrisnaWPTranslateMessage::get('changefreq_monthly'), 'yearly' => PrisnaWPTranslateMessage::get('changefreq_yearly'), 'never' => PrisnaWPTranslateMessage::get('changefreq_never') ), 'value' => $this->value['changefreq'] )); } public function output($_html_encode=false) { $this->priority_formatted = $this->priority->output('select_raw.tpl'); $this->changefreq_formatted = $this->changefreq->output('select_raw.tpl'); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/rule.tpl', 'meta_tag_rules' => array( array( 'expression' => !PrisnaWPTranslateValidator::isEmpty($this->description_message), 'tag' => 'description' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateToggleField extends PrisnaWPTranslateField { public $name; public $value_true; public $option_true; public $value_false; public $option_false; protected function _set_properties($_properties) { foreach ($_properties as $property => $value) $this->{$property} = $value; $this->name = $this->id; $keys = array_keys($_properties['values']); $this->value_true = $keys[0]; $this->option_true = $_properties['values'][$keys[0]]; $this->value_false = $keys[1]; $this->option_false = $_properties['values'][$keys[1]]; } public function output($_html_encode=false) { if (!in_array($this->value, array($this->value_true, $this->value_false))) $this->value = $this->value_true; $result = parent::render(array( 'type' => 'file', 'content' => '/admin/toggle.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->value == $this->value_true, 'tag' => 'value_true.checked' ), array( 'expression' => $this->value == $this->value_false, 'tag' => 'value_false.checked' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateRangeField extends PrisnaWPTranslateField { public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/range.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateTextareaField extends PrisnaWPTranslateField { public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/textarea.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateExportallField extends PrisnaWPTranslateField { public $button_message; public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/export_all.tpl' ), $_html_encode); return $result; } public static function run() { $xml = self::_get_data(); header("Content-Type: application/xml; charset=utf-8"); header('Content-Disposition: attachment; filename="' . PrisnaWPTranslateConfig::getDbSettingsName() . '-' . date('c') . '.xml"'); $xml->formatOutput = true; echo $xml->saveXML(); die(); } protected static function _get_data() { $files = PrisnaWPTranslateTransimportField::getFilesPaths(PRISNA_WP_TRANSLATE_CACHE, true); $result = array(); $result = new DOMDocument('1.0', 'utf-8'); $data = $result->createElement('data'); $settings_data = PrisnaWPTranslateConfig::getSettingsValuesForExport(); if ($settings_data != PrisnaWPTranslateMessage::get('export_empty')) { $settings = $result->createElement('settings'); $settings->appendChild($result->createCDATASection($settings_data)); $data->appendChild($settings); } foreach ($files as $file) { $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) continue; $xml = new DOMDocument('1.0', 'utf-8'); if (@!$xml->loadXML($contents)) continue; $translations = $xml->documentElement; $node = $result->importNode($translations, true); $data->appendChild($node); } $result->appendChild($data); if (is_file(PRISNA_WP_TRANSLATE_CACHE . '/permalinks.xml')) { $contents = PrisnaWPTranslateFileHandler::read(PRISNA_WP_TRANSLATE_CACHE . '/permalinks.xml'); if (!$contents) return $result; $xml = new DOMDocument(); if (@!$xml->loadXML($contents)) return $result; $aux = $xml->documentElement; $node = $result->importNode($aux, true); $data->appendChild($node); } return $result; } } class PrisnaWPTranslateImportallField extends PrisnaWPTranslateField { public $upload_message; public $select_button_message; public $upload_button_message; public $validate_xml_empty_message; public $validate_xml_invalid_message; public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/import_all.tpl' ), $_html_encode); return $result; } public static function run() { $files = $_FILES; $setting = PrisnaWPTranslateConfig::getSetting('import_all'); if (empty($files)) return array( 'status' => false, 'message' => $setting['validate_xml_empty_message'] ); if (!array_key_exists($setting['id'] . '_xml', $files)) return array( 'status' => false, 'message' => $setting['validate_xml_empty_message'] ); if ($files[$setting['id'] . '_xml']['error'] !== UPLOAD_ERR_OK) return array( 'status' => false, 'message' => PrisnaWPTranslateMessage::get('file_upload_error_' . $files[$setting['id'] . '_xml']['error']) ); $contents = PrisnaWPTranslateFileHandler::read($files[$setting['id'] . '_xml']['tmp_name']); if ($contents === false) return array( 'status' => false, 'message' => PrisnaWPTranslateMessage::get('file_upload_error_4') ); $xml = new DOMDocument('1.0', 'utf-8'); $parse = @$xml->loadXML($contents); if (!$parse) return array( 'status' => false, 'message' => $setting['validate_xml_invalid_message'] ); $result = array( 'status' => true, 'settings' => null, 'translations' => null, 'permalinks' => null ); $settings = $xml->documentElement->getElementsByTagName('settings'); if ($settings->length > 0) $result['settings'] = (string) $settings->item(0)->nodeValue; $translations = $xml->documentElement->getElementsByTagName('translations'); if ($translations->length > 0) $result['translations'] = $translations; $permalinks = $xml->documentElement->getElementsByTagName('permalinks'); if ($permalinks->length > 0) $result['permalinks'] = $permalinks->item(0); return $result; } public static function importPermalinks($_xml) { if (empty($_xml)) return false; $file = 'permalinks.xml'; if (is_file(PRISNA_WP_TRANSLATE_CACHE . '/' . $file)) { $backup = self::_get_unique_new_path(PRISNA_WP_TRANSLATE_CACHE . '/' . $file . '.backup'); @rename(PRISNA_WP_TRANSLATE_CACHE . '/' . $file, $backup); } self::_create_xml_file($_xml, $file); } public static function importTranslations($_xml) { if (empty($_xml)) return false; if ($_xml->length == 0) return false; $result = array(); foreach ($_xml as $translation) { $file = $translation->getAttribute('from') . '_' . $translation->getAttribute('to') . '_' . $translation->getAttribute('domain') . '.xml'; if (is_file(PRISNA_WP_TRANSLATE_CACHE . '/' . $file)) { $backup = self::_get_unique_new_path(PRISNA_WP_TRANSLATE_CACHE . '/' . $file . '.backup'); @rename(PRISNA_WP_TRANSLATE_CACHE . '/' . $file, $backup); } self::_create_xml_file($translation, $file); $result[] = $file; } return $result; } protected static function _create_xml_file($_xml, $_file) { $result = new DOMDocument('1.0', 'utf-8'); $result->formatOutput = true; $node = $result->importNode($_xml, true); $result->appendChild($node); @$result->save(PRISNA_WP_TRANSLATE_CACHE . '/' . $_file); } protected static function _get_unique_new_path($_path) { $result = self::_get_new_path($_path); if (is_file($result)) return self::_get_unique_new_path($result); return $result; } protected static function _get_new_path($_path) { $ext = '.backup'; if (PrisnaWPTranslateCommon::endsWith($_path, $ext)) { preg_match('/\.(\d{1,})\\' . $ext . '$/', $_path, $matches); if (count($matches) == 0) $result = str_replace($ext, '.1' . $ext, $_path); else $result = preg_replace('/\.\d{1,}\\' . $ext . '$/', '.' . ((int) $matches[1] + 1) . $ext, $_path); } else $result = $_path . $ext; return $result; } } class PrisnaWPTranslateExportField extends PrisnaWPTranslateField { public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/export.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateLanguageOptionField extends PrisnaWPTranslateField { public $base_url; public $value_formatted; public function __construct($_properties) { parent::__construct($_properties); $this->base_url = PRISNA_WP_TRANSLATE_IMAGES . '/admin/'; $this->value_formatted = preg_replace('/[^a-zA-Z0-9]+|\s+/', '_', $this->value); } public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/language_option.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->checked, 'tag' => 'checked' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateLanguageOrderOptionField extends PrisnaWPTranslateField { public $base_url; public $value_formatted; public function __construct($_properties) { parent::__construct($_properties); $this->base_url = PRISNA_WP_TRANSLATE_IMAGES . '/admin/'; $this->value_formatted = preg_replace('/[^a-zA-Z0-9]+|\s+/', '_', $this->value); } public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/language_order_option.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateFlagField extends PrisnaWPTranslateField { public $country_formatted; public $language_formatted; public $add_message; protected $_country_field; protected $_language_field; public function __construct($_properties) { parent::__construct($_properties); $this->_country_field = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_country', 'type' => 'select', 'values' => array_merge(array('' => ''), PrisnaWPTranslateCommon::getCountries()), 'value' => '' )); $this->_language_field = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => $this->id . '_language', 'type' => 'select', 'values' => array_merge(array('' => ''), PrisnaWPTranslateCommon::getLanguages()), 'value' => '' )); } public function output($_html_encode=false) { $this->country_formatted = $this->_country_field->output('select_single.tpl', $_html_encode); $this->language_formatted = $this->_language_field->output('select_single.tpl', $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/flag.tpl', 'meta_tag_rules' => array( array( 'expression' => false, 'tag' => 'order.show' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateLanguageField extends PrisnaWPTranslateField { public $title_order_message; public $description_order_message; public $collection_formatted; public $collection_order_formatted; public $value_order; public $enable_order; public $columns; protected $_collections; protected $_collection_order; public function __construct($_properties) { $this->_set_properties($_properties); $this->_set_options(); $this->_set_order_options(); } protected function _set_options() { $this->_collections = array(); for ($i=0; $i<$this->columns; $i++) $this->_collections[$i] = new PrisnaWPTranslateItemCollection(); $top = ceil(count($this->values) / $this->columns); $count = 0; foreach ($this->values as $key => $value) { $group = intval($count / $top); $this->_collections[$group]->add(new PrisnaWPTranslateLanguageOptionField((object) array( 'id' => PrisnaWPTranslateCommon::cleanId($this->id . '_' . $key, '_'), 'name' => $this->id, 'checked' => is_array($this->value) ? in_array((string) $key, $this->value, true) : false, 'option' => $key, 'value' => $value )), $key); $count++; } } protected function _set_order_options() { if (!$this->enable_order) return; $this->value_order = is_array($this->value) ? implode(',', $this->value) : $this->value; $this->_collection_order = new PrisnaWPTranslateItemCollection(); $values = is_array($this->value) ? $this->value : array($this->value); $items = array(); foreach ($this->values as $key => $value) { if (!in_array((string) $key, $values, true)) continue; $items[array_search($key, $values)] = new PrisnaWPTranslateLanguageOrderOptionField((object) array( 'id' => PrisnaWPTranslateCommon::cleanId($this->id . '_order_' . $key, '_'), 'option' => $key, 'value' => $value )); } ksort($items); foreach ($items as $key => $item) $this->_collection_order->add($item, $key); } public function output($_html_encode=false) { $this->collection_formatted = ''; foreach ($this->_collections as $collection) $this->collection_formatted .= $collection->render(array( 'type' => 'file', 'content' => '/admin/language_option_group.tpl' ), $_html_encode); if ($this->enable_order) $this->collection_order_formatted = $this->_collection_order->render(array( 'type' => 'file', 'content' => '/admin/language_order_option_group.tpl' ), $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/language.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->enable_order, 'tag' => 'order.show' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateCheckboxOptionField extends PrisnaWPTranslateField { public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/Checkbox_option.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->checked, 'tag' => 'checked' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateCheckboxField extends PrisnaWPTranslateField { public $collection_formatted; protected $collection; public function __construct($_properties) { $this->_set_properties($_properties); $this->_set_options(); } protected function _set_options() { $this->collection = new PrisnaWPTranslateItemCollection(); foreach ($this->values as $key => $value) { $this->collection->add(new PrisnaWPTranslateCheckboxOptionField((object) array( 'id' => PrisnaWPTranslateCommon::cleanId($this->id . '_' . $key, '_'), 'name' => $this->id, 'checked' => is_array($this->value) ? in_array((string) $key, $this->value, true) : false, 'option' => $key, 'value' => $value )), $key); } } public function output($_html_encode=false) { $this->collection_formatted = $this->collection->render(array( 'type' => 'html', 'content' => '{{ collection }}' ), $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/checkbox.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateExcategoryField extends PrisnaWPTranslateExclitemField { public function __construct($_properties) { parent::__construct($_properties, 'category'); } } class PrisnaWPTranslateExpageField extends PrisnaWPTranslateExclitemField { public function __construct($_properties) { parent::__construct($_properties, 'page'); } } class PrisnaWPTranslateExpostField extends PrisnaWPTranslateExclitemField { public function __construct($_properties) { parent::__construct($_properties, 'post'); } } class PrisnaWPTranslateExclitemOptionField extends PrisnaWPTranslateField { public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/exclude_item_option.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->checked, 'tag' => 'checked' ), array( 'expression' => $this->indent != 0, 'tag' => 'indent' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateExclitemField extends PrisnaWPTranslateCheckboxField { public $values; protected $_items; protected $_kind; public function __construct($_properties, $_kind) { $this->_kind = $_kind; $this->_set_properties($_properties); $this->_gen_values(); $this->_set_options(); } protected function _gen_items() { $this->_items = array(); switch ($this->_kind) { case 'page': { $temp = get_pages(); break; } case 'post': { $temp = get_posts(); break; } case 'category': { $temp = get_categories(array( 'hide_empty' => 0 )); break; } default: { return; break; } } switch ($this->_kind) { case 'post': case 'page': { foreach ($temp as $item) $this->_items[$item->ID] = array( 'title' => $item->post_title, 'parent' => $item->post_parent ); break; } case 'category': { foreach ($temp as $item) $this->_items[$item->cat_ID] = array( 'title' => $item->cat_name, 'parent' => $item->category_parent ); break; } } } protected function _gen_values() { $this->_gen_items(); $this->values = array(); foreach ($this->_items as $id => $item) $this->values[$id] = array( 'value' => $item['title'], 'id' => $id, 'parent' => $item['parent'], ); $this->_sort(); } protected function _sort() { if (count($this->values) < 1) return; $result = array(); $temp = PrisnaWPTranslateCommon::chain('id', 'parent', 'value', $this->values); if (is_array($temp)) foreach ($temp as $item) $result[$item['id']] = $item; $this->values = $result; } protected function _set_options() { $this->collection = new PrisnaWPTranslateItemCollection(); foreach ($this->values as $key => $value) { $this->collection->add(new PrisnaWPTranslateExclitemOptionField((object) array( 'id' => PrisnaWPTranslateCommon::cleanId($this->id . '_' . $key, '_'), 'name' => $this->id, 'checked' => is_array($this->value) ? in_array((string) $key, $this->value, true) : false, 'option' => $key, 'indent' => $value['indent'] * 20, 'value' => $value['value'] )), $key); } } public function output($_html_encode=false) { $this->collection_formatted = $this->collection->render(array( 'type' => 'html', 'content' => '{{ collection }}' ), $_html_encode); $result = $this->_render(array( 'type' => 'file', 'content' => '/admin/exclude_item.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateRadioOptionField extends PrisnaWPTranslateField { public $indent; public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/radio_option.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->checked, 'tag' => 'checked' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateRadioField extends PrisnaWPTranslateField { public $collection_formatted; protected $collection; public function __construct($_properties) { $this->_set_properties($_properties); $this->_set_options(); } protected function _set_default() { $keys = array_keys($this->values); if (!in_array($this->value, $keys)) $this->value = $keys[0]; } protected function _set_options() { $this->_set_default(); $this->collection = new PrisnaWPTranslateItemCollection(); foreach ($this->values as $key => $value) { $this->collection->add(new PrisnaWPTranslateRadioOptionField((object) array( 'id' => $this->id . '_' . $key, 'name' => $this->id, 'checked' => $this->value == $key, 'option' => $key, 'value' => $value )), $key); } } public function output($_html_encode=false) { $this->collection_formatted = $this->collection->render(array( 'type' => 'html', 'content' => '{{ collection }}' ), $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/radio.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateVisualOptionField extends PrisnaWPTranslateField { protected $_parent; public function __construct($_properties, $_parent) { $this->_set_properties($_properties); $this->_parent = $_parent; } public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/visual_option.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->checked, 'tag' => 'checked' ), array( 'expression' => $this->collection_item_index % $this->_parent->col_count == 0, 'tag' => 'new_row' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateVisualField extends PrisnaWPTranslateField { public $col_count; public $collection_formatted; protected $collection; public function __construct($_properties) { $this->_set_properties($_properties); $this->_set_options(); } protected function _set_options() { $this->collection = new PrisnaWPTranslateItemCollection(); foreach ($this->values as $key => $value) { $this->collection->add(new PrisnaWPTranslateVisualOptionField((object) array( 'id' => $this->id . '_' . $key, 'name' => $this->id, 'checked' => $this->value == $key, 'option' => $key, 'value' => $value ), $this), $key); } } public function output($_html_encode=false) { $this->collection_formatted = $this->collection->render(array( 'type' => 'html', 'content' => '{{ collection }}' ), $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/visual.tpl' ), $_html_encode); return $result; } } class PrisnaWPTranslateSelectOptionField extends PrisnaWPTranslateField { protected $_parent; public function __construct($_properties, $_parent) { $this->_set_properties($_properties); $this->_parent = $_parent; } public function output($_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/select_option.tpl', 'meta_tag_rules' => array( array( 'expression' => $this->selected, 'tag' => 'selected' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateSelectField extends PrisnaWPTranslateField { public $first_empty; public $force_selected; public $multiple; public $collection_formatted; protected $collection; public function __construct($_properties) { $this->_set_properties($_properties); $this->_set_options(); } protected function _set_options() { $this->collection = new PrisnaWPTranslateItemCollection(); $selected_flag = false; if ($this->first_empty === true) $this->collection->add(new PrisnaWPTranslateSelectOptionField((object) array( 'selected' => false, 'option' => '', 'value' => '' ), $this), ''); foreach ($this->values as $key => $value) { if ($this->value == $key) $selected_flag = true; $this->collection->add(new PrisnaWPTranslateSelectOptionField((object) array( 'selected' => $this->value == $key, 'option' => $key, 'value' => $value ), $this), $key); } if ($this->force_selected === true && $selected_flag !== true) $this->collection->add(new PrisnaWPTranslateSelectOptionField((object) array( 'selected' => true, 'option' => $this->value, 'value' => $this->value ), $this), $this->value); } public function output($_template='select.tpl', $_html_encode=false) { $this->collection_formatted = $this->collection->render(array( 'type' => 'html', 'content' => '{{ collection }}' ), $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/' . $_template, 'meta_tag_rules' => array( array( 'expression' => property_exists($this, 'post_id') && !PrisnaWPTranslateValidator::isEmpty($this->post_id), 'tag' => 'has_post_id' ), array( 'expression' => property_exists($this, 'multiple') && $this->multiple === true, 'tag' => 'multiple' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslatePermalinksField extends PrisnaWPTranslateField { public $resource_formatted; public $permalink_structure_empty_message; public $permalinks_translations_saved_message; protected $_resource_field; protected $folder; public function __construct($_properties) { parent::__construct($_properties); $this->_initialize_resource_field($_properties); } protected function _initialize_resource_field($_properties) { $_resource_field = $_properties; $_resource_field['id'] = $_resource_field['id'] . '_resource'; $_resource_field['site_url'] = PrisnaWPTranslateCommon::getSiteHost(); $_resource_field['values'] = $this->_get_resource_values(); $this->_resource_field = new PrisnaWPTranslateSelectField($_resource_field); } protected function _get_files_scopes() { $file = $this->folder . '/permalinks.xml'; $result = array(); if (!is_file($file)) return $result; $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) return $result; $xml = new DOMDocument('1.0', 'utf-8'); if (@!$xml->loadXML($contents)) return $result; $xpath = new DOMXPath($xml); $from = PrisnaWPTranslateConfig::getSettingValue('from'); $permalinks = $xpath->query("/permalinks/permalink/translation[@from='$from']/ancestor::permalink"); if (!is_object($permalinks)) return $result; foreach ($permalinks as $permalink) { $scope = $permalink->getAttribute('scope'); $result[base64_encode($scope)] = $scope; } asort($result); return $result; } protected function _get_resource_values() { $result = array_merge(array('' => ''), $this->_get_files_scopes()); return $result; } public function output($_template='permalinks.tpl', $_html_encode=false) { $permalink_structure = get_option('permalink_structure'); $this->resource_formatted = $this->_resource_field->output('permalinks_select.tpl', $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/' . $_template, 'meta_tag_rules' => array( array( 'expression' => empty($permalink_structure), 'tag' => 'permalink_structure.empty' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateVersionField extends PrisnaWPTranslateField { public $title_message; public $current_message; public $latest_message; public $whats_new_message; public $up_to_date_message; public $button_1_message; public $button_2_message; public $current_version; public $latest_version; public function __construct($_properties) { parent::__construct($_properties); $this->current_version = PrisnaWPTranslateConfig::getVersion(); $this->latest_version = $this->_get_latest_version(); } protected function _latest_installed() { if (empty($this->latest_version)) return false; return !$this->_whats_new(); } protected function _whats_new() { return $this->latest_version != '' && version_compare($this->current_version, $this->latest_version, '<'); } protected function _get_latest_version() { return empty($this->value) ? '' : $this->value; } public function output($_template='version.tpl', $_html_encode=false) { $result = parent::render(array( 'type' => 'file', 'content' => '/admin/' . $_template, 'meta_tag_rules' => array( array( 'expression' => $this->_latest_installed(), 'tag' => 'latest_installed' ), array( 'expression' => $this->_whats_new(), 'tag' => 'whats_new' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateTranslationsField extends PrisnaWPTranslateField { public $resource_formatted; protected $_resource_field; protected $folder; public function __construct($_properties) { parent::__construct($_properties); $this->_initialize_resource_field($_properties); } protected function _initialize_resource_field($_properties) { $_resource_field = $_properties; $_resource_field['id'] = $_resource_field['id'] . '_resource'; $_resource_field['values'] = $this->_get_resource_values(); $this->_resource_field = new PrisnaWPTranslateSelectField($_resource_field); } public static function getFilesPaths($_folder, $_globals=false) { $contents = @scandir($_folder); $result = array(); if (empty($contents)) return $result; $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); foreach ($contents as $name) { $file = $_folder . '/' . $name; if (PrisnaWPTranslateCommon::endsWith($name, '.xml') && !PrisnaWPTranslateCommon::startsWith($name, 'permalinks') && !PrisnaWPTranslateCommon::startsWith($name, 'log_') && @is_file($file) && ($_globals || !PrisnaWPTranslateCommon::endsWith($name, 'global.xml')) && PrisnaWPTranslateCommon::userCanEditFile($name, $allowed_languages)) $result[] = $file; } return $result; } protected function _get_files_scopes() { $xml = PrisnaWPTranslateTranslateTransport::getPermalinks(); $result = array(); $xpath = new DOMXPath($xml); $permalinks = $xpath->query('/permalinks/permalink'); if (!is_null($permalinks)) { foreach ($permalinks as $permalink) { $scope = $permalink->getAttribute('scope'); $result[base64_encode($scope)] = $scope; } asort($result); } return $result; } protected function _get_resource_values() { $result = array_merge(array('' => ''), $this->_get_files_scopes()); return $result; } public function output($_template='translations.tpl', $_html_encode=false) { $this->resource_formatted = $this->_resource_field->output('translations_select.tpl', $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/' . $_template ), $_html_encode); return $result; } } class PrisnaWPTranslateSeologField extends PrisnaWPTranslateField { public $logs_formatted; public $empty_message; protected $_file; protected $_entries_quantity; public function __construct($_properties) { parent::__construct($_properties); $this->_file = PrisnaWPTranslateCommon::getLogFile(PrisnaWPTranslateCommon::getTestApiKey()); $this->empty_message = PrisnaWPTranslateMessage::get('seo_log_empty_message'); } protected function _render_log($_template='log.tpl', $_html_encode=false) { $result = ''; $xml = $this->_get_log(); if (!$xml) return $result; $xpath = new DOMXPath($xml); $entries = $xpath->query("//entry"); $count = (int) $entries->length; if ($count == 0) return $result; for ($i=$count-1; $i>=0; $i--) { $entry = array( 'date' => $entries->item($i)->getAttribute('date'), 'kind' => $entries->item($i)->getAttribute('kind'), 'content' => $entries->item($i)->nodeValue ); $result .= PrisnaWPTranslateCommon::renderObject((object) $entry, array( 'type' => 'file', 'content' => '/admin/' . $_template, 'meta_tag_rules' => array( array( 'expression' => !($i % 2), 'tag' => 'even' ) ) ), $_html_encode); } return $result; } protected function _count_entries($_xml=null) { if (!is_null($this->_entries_quantity)) return $this->_entries_quantity; $xml = is_null($_xml) ? $this->_get_log() : $_xml; if ($xml == false) return 0; $xpath = new DOMXPath($xml); $entries = $xpath->query("//entry"); return $this->_entries_quantity = (int) $entries->length; } protected function _get_log() { if (!is_file($this->_file)) return false; $contents = PrisnaWPTranslateFileHandler::read($this->_file); if (empty($contents)) { PrisnaWPTranslateFileHandler::delete($this->_file); return false; } $result = new DOMDocument(); if (@!$result->loadXML($contents)) return false; return $result; } public function output($_template='seo_log.tpl', $_html_encode=false) { $this->logs_formatted = $this->_render_log('log.tpl', $_html_encode); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/' . $_template, 'meta_tag_rules' => array( array( 'expression' => !is_file($this->_file) || $this->_count_entries() == 0, 'tag' => 'empty' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateTransexportField extends PrisnaWPTranslateCheckboxField { public $button_message; public $remove_button_message; public $remove_confirm_message; public $empty_collection_message; public $global_message; public $values; public $resource_formatted; protected $folder; public function __construct($_properties) { $this->_set_properties($_properties); $this->_gen_values(); $this->_set_options(); } protected function _gen_values() { $this->values = $this->_get_files(); } public static function run() { if (!PrisnaWPTranslateAdminEvents::isExportingTranslations()) return; $csv = new PrisnaWPTranslateParseCSV(); $data = self::_get_data(); header('Content-type: application/csv'); header('Content-Disposition: attachment; filename="translations-' . date('c') . '.csv"'); echo $csv->unparse($data); die(); } public static function remove() { if (!PrisnaWPTranslateAdminEvents::isRemovingResource()) return; $files = self::_get_data_to_remove_resource(); $data_to_update_permalinks = array(); if (empty($files)) return; $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); foreach ($files as $file) if (is_file($file) && is_writable($file) && PrisnaWPTranslateCommon::userCanEditFile($file, $allowed_languages)) { @unlink($file); $filename = PrisnaWPTranslateCommon::getFilename($file); if (strpos($filename, 'global') === false) { $temp = explode('_', basename($filename, ".xml")); $from = $temp[0]; $to = $temp[1]; $hash = $temp[2]; $data_to_update_permalinks[] = array( 'domain' => $hash, 'from' => $from, 'to' => $to ); } } PrisnaWPTranslateTranslateTransport::removePermalink($data_to_update_permalinks); } protected static function _get_data() { $result = array(); $inputs = PrisnaWPTranslateCommon::getVariable('prisna_translations_export', 'POST'); if (!empty($inputs)) { foreach ($inputs as $single) { $file = PRISNA_WP_TRANSLATE_CACHE . '/' . PrisnaWPTranslateCommon::bsd($single) . '.xml'; if (!is_file($file)) continue; $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) continue; $xml = new DOMDocument('1.0', 'utf-8'); if (@!$xml->loadXML($contents)) continue; $xpath = new DOMXPath($xml); $words = $xpath->query("/translations/word"); foreach ($words as $word) { $source = $word->getElementsByTagName('source'); $translation = $word->getElementsByTagName('translation'); if ($source->length != 1 || $translation->length != 1) continue; $result[] = array($source->item(0)->nodeValue, $translation->item(0)->nodeValue); } } } return $result; } protected static function _get_data_to_remove_resource() { $result = array(); $inputs = PrisnaWPTranslateCommon::getVariable('prisna_translations_export', 'POST'); if (!empty($inputs)) { foreach ($inputs as $single) { $file = PRISNA_WP_TRANSLATE_CACHE . '/' . PrisnaWPTranslateCommon::bsd($single) . '.xml'; if (!is_file($file)) continue; $result[] = $file; } } return $result; } protected function _get_files() { $xml = PrisnaWPTranslateTranslateTransport::getPermalinks(); $result = array(); $xpath = new DOMXPath($xml); $permalinks = $xpath->query('/permalinks/permalink'); if (!is_null($permalinks)) { foreach ($permalinks as $permalink) { $scope = $permalink->getAttribute('scope'); $hash = $permalink->getAttribute('domain'); $result[$scope] = array( 'hash' => $hash, 'languages' => array() ); $translations = $permalink->childNodes; foreach ($translations as $translation) { $from = $translation->getAttribute('from'); $to = $translation->getAttribute('to'); $pair = $from . '|' . $to; $result[$scope]['languages'][] = array( 'from' => $from, 'to' => $to, 'value' => PrisnaWPTranslateCommon::getLanguage($from) . ' > ' . PrisnaWPTranslateCommon::getLanguage($to) ); } } } $globals = PrisnaWPTranslateCommon::getGlobalsFiles(); foreach ($globals as $global) { $file = $global->getFilename(); $contents = PrisnaWPTranslateFileHandler::read($global->getPathname()); if (!$contents) continue; $xml = new DOMDocument('1.0', 'utf-8'); if (@!$xml->loadXML($contents)) continue; $temp = explode('_', basename($file, ".xml")); $from = $temp[0]; $to = $temp[1]; $hash = $temp[2]; $xpath = new DOMXPath($xml); $scope = $xpath->query("/translations")->item(0)->getAttribute('scope'); if (!array_key_exists($scope, $result)) $result[$scope] = array( 'hash' => $hash, 'languages' => array() ); $result[$scope]['languages'][] = array( 'from' => $from, 'to' => $to, 'value' => PrisnaWPTranslateCommon::getLanguage($from) . ' > ' . PrisnaWPTranslateCommon::getLanguage($to) ); } ksort($result); return $result; } protected function _set_options() { $this->collection = new PrisnaWPTranslateItemCollection(); $i = 0; foreach ($this->values as $scope => $value) { $this->collection->add(new PrisnaWPTranslateTransexportOptionField((object) array( 'scope' => $scope == 'global' ? $this->global_message : $scope, 'ix' => $i, 'id' => $this->id, 'values' => $value )), $scope); $i++; } } public function output($_html_encode=false) { $this->collection_formatted = $this->collection->render(array( 'type' => 'html', 'content' => '{{ collection }}' ), $_html_encode); $result = $this->_render(array( 'type' => 'file', 'content' => '/admin/translations_export.tpl', 'meta_tag_rules' => array( array( 'expression' => empty($this->collection->collection), 'tag' => 'empty_collection' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateTransexportOptionField extends PrisnaWPTranslateField { public $ix; public $scope; public $values; public function __construct($_properties) { parent::__construct($_properties); } public static function sort($_a, $_b) { $result = strcmp($_a['value'], $_b['value']); return $result; } public function output($_html_encode=false) { $result = '<div class="prisna_wp_translate_transexport_item'; if (!($this->ix % 3)) $result .= ' prisna_wp_translate_transexport_first_item'; $result .= '">'; $result .= PrisnaWPTranslateCommon::renderObject((object) array( 'indent' => '', 'name' => $this->id . '_foo', 'id' => $this->id . '_' . $this->values['hash'], 'value' => $this->scope, 'option' => '' ), array( 'type' => 'file', 'content' => '/admin/translations_export_option.tpl', 'meta_tag_rules' => array( array( 'expression' => false, 'tag' => 'indent' ) ) ), $_html_encode); usort($this->values['languages'], array('PrisnaWPTranslateTransexportOptionField', 'sort')); foreach ($this->values['languages'] as $single) { $result .= PrisnaWPTranslateCommon::renderObject((object) array( 'indent' => '20', 'name' => $this->id, 'id' => $this->id . '_' . $single['from'] . '_' . $single['to'] . '_' . $this->values['hash'], 'value' => $single['value'], 'option' => base64_encode($single['from'] . '_' . $single['to'] . '_' . $this->values['hash']) ), array( 'type' => 'file', 'content' => '/admin/translations_export_option.tpl', 'meta_tag_rules' => array( array( 'expression' => true, 'tag' => 'indent' ) ) ), $_html_encode); } $result .= '</div>'; return $result; } } class PrisnaWPTranslateTransimportField extends PrisnaWPTranslateField { public $upload_message; public $upload_button_message; public $from_message; public $to_message; public $resource_title_message; public $resource_description_message; public $resource_all_message; public $resource_global_message; public $action_title_message; public $action_description_message; public $action_add_and_edit; public $action_add; public $action_edit; public $test_title_message; public $test_description_message; public $test_true; public $test_false; public $button_message; public $validate_csv_empty_message; public $validate_csv_invalid_message; public $validate_language_empty_message; public $validate_resource_invalid_message; public $validate_action_invalid_message; public $validate_test_invalid_message; public $log_added_message; public $log_edited_message; public $log_removed_message; public $log_omitted_message; public $log_created_message; public $log_yes_created_message; public $log_no_created_message; public $log_test_message; public $no_import_message; public $log_title_message; public $csv_file_value_formatted; public $from_value_formatted; public $to_value_formatted; public $resource_value_formatted; public $action_value_formatted; public $test_value_formatted; public $from_formatted; public $to_formatted; public $resource_formatted; public $action_formatted; public $test_formatted; public $log_formatted; protected $_from_language_field; protected $_to_language_field; protected $_resource_field; protected $_action_field; protected $_test_field; protected $folder; protected $_files; protected $_errors; protected $_csv; protected $_log; protected static $_files_scopes; public function __construct($_properties) { parent::__construct($_properties); $this->_initialize_resource_field($_properties); $this->_initialize_language_fields($_properties); $this->_initialize_action_field($_properties); $this->_initialize_test_field($_properties); $this->_files = $_FILES; $this->_errors = array(); $this->_log = array(); $this->_run(); } protected function _run() { if (!PrisnaWPTranslateAdminEvents::isImportingTranslations()) return; if (!$this->_validate()) return; $this->_import(); } protected function _import() { $translations = array(); foreach ($this->_csv as $single) $translations[] = array( 'source' => $single[0], 'translation' => $single[1], 'hash' => PrisnaWPTranslateCommon::hashText($single[0]) ); $resources = array(); if ($this->_resource_field->value == 'all' || $this->_resource_field->value == 'global') { $resources[] = 'global'; if ($this->_resource_field->value == 'all') { $files_scopes = array_keys($this->_get_files_scopes()); $files_scopes = array_filter($files_scopes); $resources = array_merge( $resources, $files_scopes ); } } else $resources[] = $this->_resource_field->value; $this->_log = PrisnaWPTranslateTranslateTransport::importTranslations($translations, $resources, $this->_from_language_field->value, $this->_to_language_field->value, $this->_action_field->value, $this->_test_field->value == 'true'); } protected function _validate() { if (!$this->_validate_csv_file()) $this->_errors['csv_file'] = true; if (!$this->_validate_from()) $this->_errors['from'] = true; if (!$this->_validate_to()) $this->_errors['to'] = true; if (!$this->_validate_resource()) $this->_errors['resource'] = true; if (!$this->_validate_action()) $this->_errors['action'] = true; if (!$this->_validate_test()) $this->_errors['test'] = true; return empty($this->_errors); } protected function _validate_test() { if (!array_key_exists($this->test_value_formatted, $this->_test_field->values)) { $this->test_value_formatted = $this->validate_test_invalid_message; return false; } return true; } protected function _validate_action() { if (!array_key_exists($this->action_value_formatted, $this->_action_field->values)) { $this->action_value_formatted = $this->validate_action_invalid_message; return false; } return true; } protected function _validate_resource() { if (!array_key_exists($this->resource_value_formatted, $this->_resource_field->values)) { $this->resource_value_formatted = $this->validate_resource_invalid_message; return false; } return true; } protected function _validate_from() { if (empty($this->from_value_formatted) || !array_key_exists($this->from_value_formatted, $this->_from_language_field->values)) { $this->from_value_formatted = $this->validate_language_empty_message; return false; } if ($this->_from_language_field->value == $this->_to_language_field->value) { $this->from_value_formatted = $this->_from_language_field->values[$this->from_value_formatted]; return false; } return true; } protected function _validate_to() { if (empty($this->to_value_formatted) || !array_key_exists($this->to_value_formatted, $this->_to_language_field->values)) { $this->to_value_formatted = $this->validate_language_empty_message; return false; } if ($this->_to_language_field->value == $this->_from_language_field->value) { $this->to_value_formatted = $this->_to_language_field->values[$this->to_value_formatted]; return false; } return true; } protected function _validate_csv_file() { if (empty($this->_files)) { $this->csv_file_value_formatted = $this->validate_csv_empty_message; return false; } if (!array_key_exists($this->id . '_csv', $this->_files)) { $this->csv_file_value_formatted = $this->validate_csv_empty_message; return false; } if ($this->_files[$this->id . '_csv']['error'] !== UPLOAD_ERR_OK) { $this->csv_file_value_formatted = PrisnaWPTranslateMessage::get('file_upload_error_' . $this->_files[$this->id . '_csv']['error']); return false; } $contents = PrisnaWPTranslateFileHandler::read($this->_files[$this->id . '_csv']['tmp_name']); if ($contents === false) { $this->csv_file_value_formatted = PrisnaWPTranslateMessage::get('file_upload_error_4'); return false; } $extension = PrisnaWPTranslateCommon::getFilenameExtension($this->_files[$this->id . '_csv']['name']); if (empty($extension) || ($extension != 'po' && $extension != 'csv')) { $this->csv_file_value_formatted = $this->validate_csv_invalid_message; return false; } $this->_csv = array(); switch ($extension) { case 'csv': $csv = new PrisnaWPTranslateParseCSV(); $csv->parse($contents); foreach ($csv->data as $single) if (count($single) == 2) $this->_csv[] = $single; break; case 'po': $po = PrisnaWPTranslateParsePo::parseString($contents); $entries = $po->getEntries(); foreach ($entries as $entry) $this->_csv[] = array(implode('', $entry['msgid']), implode('', $entry['msgstr'])); break; } if (empty($this->_csv)) { $this->csv_file_value_formatted = $this->validate_csv_invalid_message; return false; } $this->csv_file_value_formatted = $this->_files[$this->id . '_csv']['name']; return true; } protected function _initialize_test_field($_properties) { $field = $_properties; $field['title_message'] = $this->test_title_message; $field['description_message'] = $this->test_description_message; $field['id'] = $field['id'] . '_test'; $field['values'] = array( 'false' => $this->test_false, 'true' => $this->test_true ); $field['value'] = 'false'; $value = PrisnaWPTranslateCommon::getVariable($field['id'], 'POST'); if ($value !== false) $this->test_value_formatted = $field['value'] = $value; $this->_test_field = new PrisnaWPTranslateToggleField($field); } protected function _initialize_action_field($_properties) { $field = $_properties; $field['title_message'] = $this->action_title_message; $field['description_message'] = $this->action_description_message; $field['id'] = $field['id'] . '_action'; $field['values'] = array( 'add_and_edit' => $this->action_add_and_edit, 'add' => $this->action_add, 'edit' => $this->action_edit ); $field['value'] = 'add_and_edit'; $value = PrisnaWPTranslateCommon::getVariable($field['id'], 'POST'); if ($value !== false) $this->action_value_formatted = $field['value'] = $value; $this->_action_field = new PrisnaWPTranslateRadioField($field); } protected function _initialize_language_fields($_properties) { $field = $_properties; $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); if (is_array($allowed_languages) && !empty($allowed_languages)) if ($allowed_languages[0] == 'all') $allowed_languages = array_keys(PrisnaWPTranslateCommon::getLanguages()); $languages = array_merge(array('' => ''), array_intersect_key(PrisnaWPTranslateCommon::getLanguages(), array_merge(array_flip($allowed_languages), array_flip(array(PrisnaWPTranslateConfig::getSettingValue('from')))))); $field['values'] = $languages; $field['id'] = $field['id'] . '_from'; $value = PrisnaWPTranslateCommon::getVariable($field['id'], 'POST'); $this->from_value_formatted = $field['value'] = empty($value) ? '' : $value; $this->_from_language_field = new PrisnaWPTranslateSelectField($field); $field['id'] = $field['id'] . '_to'; $value = PrisnaWPTranslateCommon::getVariable($field['id'], 'POST'); $this->to_value_formatted = $field['value'] = empty($value) ? '' : $value; $this->_to_language_field = new PrisnaWPTranslateSelectField($field); } protected function _initialize_resource_field($_properties) { $field = $_properties; $field['title_message'] = $this->resource_title_message; $field['description_message'] = $this->resource_description_message; $field['id'] = $field['id'] . '_resource'; $field['values'] = $this->_get_resource_values(); $value = PrisnaWPTranslateCommon::getVariable($field['id'], 'POST'); $this->resource_value_formatted = $field['value'] = empty($value) ? '' : $value; $this->_resource_field = new PrisnaWPTranslateSelectField($field); } public static function getFilesPaths($_folder, $_globals=false) { $contents = @scandir($_folder); $result = array(); if (empty($contents)) return $result; $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); foreach ($contents as $name) { $file = $_folder . '/' . $name; if (PrisnaWPTranslateCommon::endsWith($name, '.xml') && !PrisnaWPTranslateCommon::startsWith($name, 'permalinks') && !PrisnaWPTranslateCommon::startsWith($name, 'log_') && @is_file($file) && ($_globals || !PrisnaWPTranslateCommon::endsWith($name, 'global.xml')) && PrisnaWPTranslateCommon::userCanEditFile($name, $allowed_languages)) $result[] = $file; } return $result; } protected function _get_files_scopes() { if (!is_null(self::$_files_scopes)) return self::$_files_scopes; $xml = PrisnaWPTranslateTranslateTransport::getPermalinks(); $result = array(); $xpath = new DOMXPath($xml); $permalinks = $xpath->query('/permalinks/permalink'); if (!is_null($permalinks)) { foreach ($permalinks as $permalink) { $scope = $permalink->getAttribute('scope'); $result[base64_encode($scope)] = $scope; } asort($result); } return self::$_files_scopes = $result; } protected function _get_resource_values() { $result = $same = $this->_get_files_scopes(); if (empty($result)) return array('global' => $this->resource_global_message); $result = array_merge( array('all' => $this->resource_all_message), array('global' => $this->resource_global_message), $same ); return $result; } protected function _gen_log_formated($_html_encode=false) { $result = '
<tr>
<th>' . $this->resource_title_message . '</th>
<th>' . $this->log_added_message . '</th>
<th>' . $this->log_edited_message . '</th>
<th>' . $this->log_removed_message . '</th>
<th>' . $this->log_omitted_message . '</th>
<th>' . $this->log_created_message . '</th>
</tr>'; foreach ($this->_log as $key => $value) $result .= '
<tr>
<td>' . $this->_resource_field->values[$key] . '</td>
<td>' . $value['added'] . '</td>
<td>' . $value['edited'] . '</td>
<td>' . $value['removed'] . '</td>
<td>' . $value['omitted'] . '</td>
<td>' . (!empty($value['file_created']) ? $this->log_yes_created_message : $this->log_no_created_message) . '</td>
</tr>'; $this->log_formatted = $result; } protected function _formatted_values($_html_encode=false) { $this->resource_formatted = $this->_resource_field->output('select.tpl', $_html_encode); $this->from_formatted = $this->_from_language_field->output('select_single.tpl', $_html_encode); $this->to_formatted = $this->_to_language_field->output('select_single.tpl', $_html_encode); $this->action_formatted = $this->_action_field->output($_html_encode); $this->test_formatted = $this->_test_field->output($_html_encode); $this->_gen_log_formated($_html_encode); if (!PrisnaWPTranslateAdminEvents::isImportingTranslations()) return; if (!array_key_exists('from', $this->_errors)) $this->from_value_formatted = $this->_from_language_field->values[$this->from_value_formatted]; if (!array_key_exists('to', $this->_errors)) $this->to_value_formatted = $this->_to_language_field->values[$this->to_value_formatted]; if (!array_key_exists('resource', $this->_errors)) $this->resource_value_formatted = $this->_resource_field->values[$this->resource_value_formatted]; if (!array_key_exists('action', $this->_errors)) $this->action_value_formatted = $this->_action_field->values[$this->action_value_formatted]; if (!array_key_exists('test', $this->_errors)) $this->test_value_formatted = $this->_test_field->values[$this->test_value_formatted]; } public function output($_template='translations_import.tpl', $_html_encode=false) { $this->_formatted_values(); $result = parent::render(array( 'type' => 'file', 'content' => '/admin/' . $_template, 'meta_tag_rules' => array( array( 'expression' => !empty($this->_resource_field->values), 'tag' => 'has_resource' ), array( 'expression' => PrisnaWPTranslateAdminEvents::isImportingTranslations(), 'tag' => 'is_importing' ), array( 'expression' => array_key_exists('csv_file', $this->_errors), 'tag' => 'csv_file.error' ), array( 'expression' => array_key_exists('from', $this->_errors), 'tag' => 'from.error' ), array( 'expression' => array_key_exists('to', $this->_errors), 'tag' => 'to.error' ), array( 'expression' => array_key_exists('resource', $this->_errors), 'tag' => 'resource.error' ), array( 'expression' => array_key_exists('action', $this->_errors), 'tag' => 'action.error' ), array( 'expression' => array_key_exists('test', $this->_errors), 'tag' => 'test.error' ), array( 'expression' => !empty($this->_errors), 'tag' => 'has_errors' ), array( 'expression' => $this->_test_field->value == 'true', 'tag' => 'is_test' ) ) ), $_html_encode); return $result; } } class PrisnaWPTranslateItemCollection { protected $_position = 0; public $collection; public function __construct() { $this->_position = 0; } public function add($_object, $_index=null) { if (is_null($_index)) $this->collection[] = $_object; else $this->collection[$_index] = $_object; } public function rewind() { $this->_position = 0; } public function current() { $keys = array_keys($this->collection); return $this->collection[$keys[$this->_position]]; } public function getFirst() { $keys = array_keys($this->collection); return $this->collection[$keys[0]]; } public function getLast() { $keys = array_keys($this->collection); return $this->collection[$keys[count($keys)-1]]; } public function key() { return $this->_position; } public function next() { ++$this->_position; } public function count() { return count($this->collection); } public function valid() { $keys = array_keys($this->collection); if (!isset($keys[$this->_position])) return false; return isset($this->collection[$keys[$this->_position]]); } protected function _add_count_for_render() { if (count($this->collection) > 0) { $i = 0; foreach ($this->collection as $item) { $item->collection_item_index = $i; $i++; } } } public function render($_options, $_html_encode=false) { $result = ''; $partial = array(); $this->_add_count_for_render(); if (count($this->collection) > 0) foreach ($this->collection as $item) $partial[] = $item->output($_html_encode); $object = (object) array( 'collection' => join("\n", $partial), 'collection_count' => count($partial) ); foreach ($this as $property => $value) if (!is_array($value)) $object->{$property} = $value; if (!array_key_exists('meta_tag_rules', $_options)) $_options['meta_tag_rules'] = array(); $_options['meta_tag_rules'][] = array( 'expression' => count($partial) == 0, 'tag' => 'collection.is_empty' ); $result = PrisnaWPTranslateCommon::renderObject($object, $_options, $_html_encode); return $result; } } ?>
<?php
class PrisnaWPTranslateSeo { protected static $_url_mode; protected static $_node; protected static $_text; protected static $_text_hash; protected static $_text_translated; protected static $_from; protected static $_to; protected static $_url; protected static $_url_hash; protected static $_original_url; protected static $_full_url; protected static $_scripts; protected static $_seo_variable; protected static $_translate_meta_tags; protected static $_translate_meta_tags_names; protected static $_translate_attributes; protected static $_translate_title_attribute; protected static $_translate_alt_attribute; protected static $_translate_placeholder_attribute; protected static $_doc; protected static $_initialized; protected static $_current_url; protected static $_seo_languages; protected static $_all_languages; protected static $_seo_chinese; protected static $_max_log_entries = 20; protected static $_xpath_permalink_lookup; public static function initialize() { if (!self::_pre_validate()) return; self::_initialize(); self::$_url = self::removeLanguage(self::_path_n_query(self::getCurrentUrl())); self::$_url_hash = empty(self::$_url) ? false : PrisnaWPTranslateCommon::hashUrl(self::$_url); $url_info = self::_get_url_info(); self::_set_internal_location($url_info['host'], $url_info['url']); if (self::_validate()) { self::$_node = array(); self::$_text = array(); self::$_text_hash = array(); self::$_text_translated = array(); self::$_full_url = PrisnaWPTranslateCommon::addParamenter(self::removeLanguage(self::getCurrentUrl()), PrisnaWPTranslateConfig::getSeoParameterName(), self::$_to); $response = self::_fetch(); if (!is_array($response)) $response = array('error' => PrisnaWPTranslateMessage::get('seo_log_empty_response_message')); if (self::_validate_fetch($response)) { if (self::_gen_text_to_translate($response)) { self::_translate(); self::_render($response); self::_log('success', PrisnaWPTranslateMessage::get('seo_log_success_message', array(self::convertURL(PrisnaWPTranslateCommon::removeHiddenFromUrl(self::$_full_url, PrisnaWPTranslateConfig::getSeoParameterName()), self::$_to), PrisnaWPTranslateCommon::getLanguage(self::$_to)))); die(); } } } else if (!empty(self::$_to)) self::_redirect(); } protected static function _get_url_info() { if (!PrisnaWPTranslateConfig::getSettingValue('seo') || !PrisnaWPTranslateConfig::getSettingValue('enable_permalinks')) $result = self::_extract_url($_SERVER['REQUEST_URI'], $_SERVER['HTTP_HOST'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''); else { $url = parse_url(self::getCurrentUrl()); $path = ''; if (!empty($url['path'])) $path .= $url['path']; if (!empty($url['query'])) $path .= '?' . $url['query']; if (!array_key_exists('host', $url)) $url['host'] = ''; $result = self::_extract_url($path, $url['host']); } return $result; } public static function getCurrentUrl() { if (!is_null(self::$_current_url)) return self::$_current_url; $url = PrisnaWPTranslateCommon::getCurrentUrl(); if (!PrisnaWPTranslateConfig::getSettingValue('seo') || !PrisnaWPTranslateConfig::getSettingValue('enable_permalinks')) return self::$_current_url = $url; $home = PrisnaWPTranslateCommon::stripHost(PrisnaWPTranslateCommon::getHomeUrl('/')); $language = self::getLanguage($url); $path = PrisnaWPTranslateCommon::stripHost(self::removeLanguage($url)); $translation = PrisnaWPTranslateCommon::stringDiff($home, $path); if (empty($translation)) return self::$_current_url = $url; $map = self::_permalink_lookup($translation, self::$_from, $language); if (empty($map)) return self::$_current_url = $url; $new_path = PrisnaWPTranslateCommon::stringDiff($home, $map); if (PrisnaWPTranslateCommon::endsWith($map, '/') && !PrisnaWPTranslateCommon::endsWith($new_path, '/')) $new_path .= '/'; $url = self::convertURL(PrisnaWPTranslateCommon::getHomeUrl() . $new_path, $language); return self::$_current_url = $url; } protected static function _get_xpath_for_permalink_lookup() { if (!empty(self::$_xpath_permalink_lookup)) return self::$_xpath_permalink_lookup; $xml = PrisnaWPTranslateTranslateTransport::getPermalinks(); $xpath = new DOMXPath($xml); return self::$_xpath_permalink_lookup = $xpath; } protected static function _permalink_lookup($_translation, $_from, $_to) { if (!PrisnaWPTranslateConfig::getSettingValue('enable_permalinks') || empty($_from) || empty($_to)) return false; $xpath = self::_get_xpath_for_permalink_lookup(); $from = self::getOriginalLanguage($_from); $to = self::getOriginalLanguage($_to); $predicate = "/permalinks/permalink/translation[@from='$from' and @to='$to' and text() = " . PrisnaWPTranslateCommon::xpathEscape($_translation) . "]/ancestor::permalink"; $permalink = $xpath->query($predicate)->item(0); if (is_null($permalink)) return false; return $permalink->getAttribute('scope'); } protected static function _set_internal_location($_host, $_url) { $_SERVER['HTTP_HOST'] = $_host; $_SERVER['REQUEST_URI'] = $_url; } protected static function _initialize() { if (!empty(self::$_initialized)) return; self::$_initialized = true; self::$_from = PrisnaWPTranslateConfig::getSettingValue('from'); self::$_url_mode = PrisnaWPTranslateConfig::getSettingValue('seo_url_mode'); self::$_seo_variable = PrisnaWPTranslateConfig::getSettingValue('seo_variable'); self::$_translate_meta_tags = PrisnaWPTranslateConfig::getSettingValue('translate_meta_tags'); self::$_translate_meta_tags_names = explode(',', PrisnaWPTranslateConfig::getSettingValue('translate_meta_tags_names')); self::$_translate_attributes = PrisnaWPTranslateConfig::getSettingValue('translate_attributes'); self::$_translate_title_attribute = PrisnaWPTranslateConfig::getSettingValue('translate_title_attribute'); self::$_translate_alt_attribute = PrisnaWPTranslateConfig::getSettingValue('translate_alt_attribute'); self::$_translate_placeholder_attribute = PrisnaWPTranslateConfig::getSettingValue('translate_placeholder_attribute'); self::$_seo_chinese = self::getSeoChinese(); self::$_seo_languages = PrisnaWPTranslateConfig::getSettingValue('seo_languages'); self::$_all_languages = PrisnaWPTranslateCommon::getLanguages(); if (!empty(self::$_seo_chinese)) { $name = self::$_all_languages[self::$_seo_chinese]; unset(self::$_all_languages[self::$_seo_chinese]); self::$_all_languages['zh'] = $name; if (in_array(self::$_seo_chinese, self::$_seo_languages)) { self::$_seo_languages = array_diff(self::$_seo_languages, array(self::$_seo_chinese)); self::$_seo_languages[] = 'zh'; } } self::$_max_log_entries = PrisnaWPTranslateConfig::getSettingValue('seo_max_log_size'); self::$_original_url = self::getCurrentUrl(); self::$_to = self::getLanguage(self::$_original_url); } public static function removeLanguage($_url) { self::_initialize(); $url = str_replace(array('&', '&'), '&', $_url); $all_languages = array_map('strtolower', array_keys(self::$_all_languages)); if (preg_match('/(\&|\?)' . self::$_seo_variable . '=([^&\#]*)/i', $url, $match)) if ($match[2] !== false) $url = preg_replace('/(\&|\?)' . self::$_seo_variable . '=[^&\#]*/', "$1", $url, 1); switch (self::$_url_mode) { case 'path': if (preg_match('/(\/([a-z]{2,3}(\-cn|-tw)?)\/)|(\/([a-z]{2,3}(\-cn|-tw)?)$)/i', $url, $match)) if (in_array($match[2], $all_languages)) $url = preg_replace('/(\/' . $match[2] . '\/)|(\/' . $match[2] . '$)/i', '/', $url, 1); break; case 'subdomain': $url_info = parse_url($url); if (array_key_exists('host', $url_info)) if (preg_match('/^([a-z]{2,3}(\-cn|-tw)?)\./i', $url_info['host'], $match)) if (in_array($match[1], $all_languages)) $url = preg_replace('/' . $match[1] . '\./i', '', $url, 1); break; } $url = str_replace('?&', '?', $url); $url = preg_replace('/(\?|\&)$/', '', $url); return $url; } public static function getLanguage($_url) { self::_initialize(); $all_languages = array_map('strtolower', array_keys(self::$_all_languages)); $url = str_replace(array('&', '&'), '&', $_url); switch (self::$_url_mode) { case 'path': $home = PrisnaWPTranslateCommon::getHomeUrl('/'); $url = str_replace($home, '', $url); if (preg_match('/^([a-z]{2,3}(\-cn|-tw)?)\/|^([a-z]{2,3}(\-cn|-tw)?)$/i', $url, $match)) { $found = empty($match[1]) ? $match[2] : $match[1]; if (in_array($found, $all_languages)) return $found; } break; case 'subdomain': $url_info = parse_url($url); if (preg_match('/^([a-z]{2,3}(\-cn|-tw)?)\./i', $url_info['host'], $match)) if (in_array($match[1], $all_languages)) return $match[1]; break; case 'query': $lang = PrisnaWPTranslateCommon::getVariable(self::$_seo_variable, 'GET'); if ($lang !== false && in_array($lang, $all_languages)) return $lang; break; } return false; } public static function convertURL($_url, $_lang) { self::_initialize(); $lang = self::getTrueLanguage($_lang, false); if (empty($lang)) return $_url; $url = str_replace(array('&', '&'), '&', $_url); $nottrailing = strpos($url, '?') === false && strpos($url, '#') === false && substr($url, -1, 1) != '/'; $url_info = parse_url($url); $home = rtrim(get_option('home'), '/'); if (!empty($url_info['host'])) { if (self::$_url_mode == 'subdomain' && preg_match('/^([a-z]{2,3}(\-cn|-tw)?)\./i', $url_info['host'], $match)) { if (self::_is_language_enabled($match[1])) { $url = preg_replace('/' . $match[1] . '\./i', '', $url, 1); $url_info = parse_url($url); } } $url = substr($url, strlen($home)); } else { $home_info = parse_url($home); if (array_key_exists('path', $home_info) && $home_info['path'] == substr($url, 0, strlen($home_info['path']))) $url = substr($url, strlen($home_info['path'])); } if (preg_match('/(&|\?)lang=([^&\#]+)/i', $url, $match)) $url = preg_replace('/(&|\?)lang=' . $match[2] . '&?/i', "$1", $url); $url = ltrim($url, '/'); $url = rtrim($url, '?&'); switch (self::$_url_mode) { case 'path': if (preg_match('/^([a-z]{2,3}(\-cn|-tw)?)\/|^([a-z]{2,3}(\-cn|-tw)?)$/i', $url, $match)) { $found = empty($match[1]) ? $match[2] : $match[1]; if (self::_is_language_enabled($found)) $url = substr($url, strlen($found) + 1); } if ($lang != self::$_from) $url = strtolower($lang) . '/' . $url; break; case 'subdomain': $home = preg_replace('/www\./', '', $home, 1); if ($lang != self::$_from) $home = preg_replace('/\/\//', '//' . strtolower($lang) . '.', $home, 1); break; default: if ($lang != self::$_from) $url = PrisnaWPTranslateCommon::addParamenter($url, self::$_seo_variable, strtolower($lang)); } $complete = $home . '/' . $url; if($nottrailing && strpos($complete, '?') === false && strpos($complete, '#') === false && substr($complete, -1, 1) == '/') $complete = substr($complete, 0, -1); return $complete; } protected static function _extract_url($_url, $_host='', $_referer='') { $home = parse_url(get_option('home')); $home['path'] = array_key_exists('path', $home) ? trailingslashit($home['path']) : '/'; $referer = parse_url($_referer); $result = array(); $result['language'] = self::$_from; $result['url'] = $_url; $result['original_url'] = $_url; $result['host'] = $_host; $result['redirect'] = false; $result['internal_referer'] = false; $result['home'] = $home['path']; switch (self::$_url_mode) { case 'path': $url = substr($_url, strlen($home['path'])); if ($url) { if (preg_match('/^([a-z]{2,3}(\-cn|-tw)?)(\/.*)?$/i', $url, $match)) { if (self::_is_language_enabled($match[1])) { $result['language'] = $match[1]; $result['url'] = $home['path'].substr($url, 3); } } } break; case 'subdomain': if ($_host) { if (preg_match('/^([a-z]{2,3}(\-cn|-tw)?)\./i', $_host, $match)) { if (self::_is_language_enabled($match[1])) { $result['language'] = $match[1]; $result['host'] = substr($_host, 3); } } } break; } if (array_key_exists('host', $referer) && $referer['host'] == $result['host'] && PrisnaWPTranslateCommon::startsWith($referer['path'], $home['path'])) $result['internal_referer'] = true; if ($home['host'] == $result['host'] && $home['path'] == $result['url']) { if (empty($referer['host'])) $result['redirect'] = true; else { if (preg_match('/^([a-z]{2,3}(\-cn|-tw)?)\./i', $referer['host'], $match)) if (self::_is_language_enabled($match[1])) $referer['host'] = substr($referer['host'], 3); if (!$result['internal_referer']) $result['redirect'] = true; } } return $result; } protected static function _redirect() { $url = self::removeLanguage(self::getCurrentUrl()); header('Location: ' . $url); die(); } protected static function _render($_response) { $check = array('content-type', 'content-location', 'content-md5', 'etag', 'last-modified', 'expires'); foreach ($_response['headers'] as $header => $value) if (in_array(strtolower($header), $check)) header("$header: $value"); foreach (self::$_node as $key => $node) if (array_key_exists($key, self::$_text_translated)) foreach (self::$_text_translated[$key] as $name => $value) { if ($name == 'content') $node->nodeValue = $value; else if ($name == 'cmeta') $node->setAttribute('content', $value); else { if (!method_exists($node, 'setAttribute')) $node = self::_get_parent_node($node); if (!is_null($node)) $node->setAttribute($name, $value); } } self::_update_dom(); $result = self::$_doc->saveHTML(); $result = self::_restore_scripts($result); echo $result; } protected static function _is_local_link($_link) { $href = $_link->getAttribute('href'); if (PrisnaWPTranslateCommon::startsWith($href, '/')) return true; if (PrisnaWPTranslateCommon::startsWith($href, '#')) return false; $url = parse_url($href); if (empty($url['host'])) return true; $local = parse_url(PrisnaWPTranslateCommon::getHomeUrl('/')); return $url['host'] == $local['host']; } protected static function _map_link($_href) { $home = PrisnaWPTranslateCommon::stripHost(PrisnaWPTranslateCommon::getHomeUrl('/')); $path = PrisnaWPTranslateCommon::stripHost(self::removeLanguage($_href)); $map = self::_permalink_lookup_by_scope($path, self::$_from, self::$_to, true); if ($map === false) return false; if ($map == '') $map = '/'; $scope = PrisnaWPTranslateSeo::convertURL((PrisnaWPTranslateConfig::getSettingValue('enable_permalinks') ? $map : $path), self::$_to); return $scope; } protected static function _update_dom() { $xpath = new DOMXPath(self::$_doc); $to = self::getTrueLanguage(self::$_to, true); $hrefs = $xpath->query('//*[contains(@href, \'' . PrisnaWPTranslateConfig::getSeoParameterName() . '\')]'); foreach ($hrefs as $href) $href->setAttribute('href', PrisnaWPTranslateCommon::removeHiddenFromUrl($href->getAttribute('href'), PrisnaWPTranslateConfig::getSeoParameterName())); $links = $xpath->query('//a[@href]' . self::_gen_xpath_exclude_select_expression_aux()); foreach ($links as $link) if (self::_is_local_link($link)) { $link_map = self::_map_link($link->getAttribute('href')); if ($link_map !== false) $link->setAttribute('href', $link_map); } $comments = $xpath->query('//comment()'); foreach ($comments as $comment) if (preg_match('/\<html.+?(lang\=(\"|\')[a-zA-Z0-9\-]{1,5}(\"|\'))/', $comment->nodeValue, $match)) $comment->nodeValue = str_replace($match[1], 'lang=' . $match[2] . $to . $match[2], $comment->nodeValue); if (self::$_translate_meta_tags && in_array('og:locale', self::$_translate_meta_tags_names)) { $locales = $xpath->query('//meta[@property=\'og:locale\']'); foreach ($locales as $locale) $locale->setAttribute('content', $to); } $html = $xpath->query("//html")->item(0); if (!empty($html)) $html->setAttribute('lang', $to); $body = $xpath->query("//body")->item(0); if (!empty($body)) { $body_class = $body->getAttribute('class'); if (empty($body_class)) $body_class = ''; $rtl_languages = explode(',', PrisnaWPTranslateConfig::getSettingValue('rtl_languages')); if (in_array(self::$_to, $rtl_languages)) $body_class .= ' ' . PrisnaWPTranslateConfig::getSettingValue('rtl_class'); $body->setAttribute('class', $body_class . ' ' . PrisnaWPTranslateConfig::getSettingValue('translated_to_class') . self::$_to); } $canonical = $xpath->query("//link[@rel='canonical']")->item(0); if (!empty($canonical)) $canonical->setAttribute('href', self::convertURL(self::_gen_link(self::$_to), self::$_to)); if (self::$_translate_meta_tags && in_array('og:url', self::$_translate_meta_tags_names)) { $og_url = $xpath->query('//meta[@property=\'og:url\']')->item(0); if (!empty($og_url)) $og_url->setAttribute('content', self::convertURL(self::_gen_link(self::$_to), self::$_to)); } $head = $xpath->query("//head")->item(0); if (empty($head)) return; $link = self::$_doc->createElement('link'); $rel = self::$_doc->createAttribute('rel'); $rel->value = 'alternate'; $hreflang = self::$_doc->createAttribute('hreflang'); $hreflang->value = self::$_from; $href = self::$_doc->createAttribute('href'); $href->value = str_replace('&', '&', self::$_url); $link->appendChild($rel); $link->appendChild($hreflang); $link->appendChild($href); $head->appendChild($link); } protected static function _get_languages($_special=false) { self::_initialize(); $result = array(); $languages = self::$_seo_languages; foreach ($languages as $language) { if ($language == self::$_to) continue; $file = self::_get_url(false, $language, $_special); if (is_file($file)) $result[] = $language; } return $result; } public static function genTranslator() { self::$_to = PrisnaWPTranslateCommon::getVariable(PrisnaWPTranslateConfig::getSeoParameterName(), 'GET'); self::$_url = PrisnaWPTranslateCommon::removeHiddenFromUrl(self::$_url, self::$_seo_variable); self::$_url_hash = empty(self::$_url) ? false : PrisnaWPTranslateCommon::hashUrl(self::$_url); $languages = self::_get_languages(true); if (!empty(self::$_to)) array_unshift($languages, self::$_from, self::$_to); if (count($languages) == 0) return ''; $languages_names = PrisnaWPTranslateSeo::getLanguages(); $result = '<ul class="prisna-wp-translate-seo" id="' . PrisnaWPTranslateConfig::getSettingValue('id') . '-seo">'; $lang = PrisnaWPTranslateCommon::getVariable(self::$_seo_variable . '_hidden', 'GET'); $flag = false; foreach ($languages as $language) { if ($language == $lang) { $flag = true; continue; } $result .= '<li class="language-flag language-flag-' .$language. '"><a href="' . self::_gen_link($language) . '" title="' . $languages_names[$language] . '"><b class="country-flag"></b><span>' . $languages_names[$language] . '</span></a></li>'; } if ($flag) $result .= '<li><a href="' . self::$_url . '" title="' . $languages_names[self::$_from] . '">' . $languages_names[self::$_from] . '</a></li>'; $result .= '</ul>'; return $result; } protected static function _permalink_lookup_by_scope($_scope, $_from, $_to, $_force=false) { if (!$_force && (!PrisnaWPTranslateConfig::getSettingValue('enable_permalinks') || empty($_from) || empty($_to))) return false; $xpath = self::_get_xpath_for_permalink_lookup(); $predicate = "/permalinks/permalink[@scope=" . PrisnaWPTranslateCommon::xpathEscape($_scope) . "]/translation[@from='$_from' and @to='$_to']"; $translation = $xpath->query($predicate)->item(0); if (is_null($translation)) return false; if (is_null($translation->nodeValue)) return false; return $translation->nodeValue; } protected static function _gen_link($_language) { $result = self::$_url; $result = PrisnaWPTranslateCommon::removeHiddenFromUrl($result, PrisnaWPTranslateConfig::getSeoParameterName()); $permalink = self::_permalink_lookup_by_scope($result, self::getTrueLanguage(self::$_from, true), self::getTrueLanguage($_language, true)); if (!empty($permalink)) $result = $permalink; $result = self::convertURL($result, $_language); return $result; } protected static function _validate_fetch($_response) { if (array_key_exists('error', $_response)) { self::_log('fetch', $_response['error']); return false; } return true; } protected static function _gen_xpath_exclude_select_expression_aux() { $result = array(); $temp = array(); $exclude = PrisnaWPTranslateConfig::getSettingValue('exclude_selector'); $exclude .= ',.prisna-wp-translate-seo'; $exclude = preg_replace('/\s+/', '', $exclude); $exclude = explode(',', $exclude); foreach ($exclude as $single) if (PrisnaWPTranslateCommon::startsWith($single, '.')) $temp[] = array( 'path' => preg_replace('/\.+/', '', $single), 'attribute' => 'class' ); else if (PrisnaWPTranslateCommon::startsWith($single, '#')) $temp[] = array( 'path' => preg_replace('/\#+/', '', $single), 'attribute' => 'id' ); foreach ($temp as $single) if ($single['attribute'] == 'class') $result[] = 'ancestor-or-self::*[contains(@class, \'' . $single['path'] . ' \') or contains(@class, \' ' . $single['path'] . '\') or @class=\'' . $single['path'] . '\']'; else if ($single['attribute'] == 'id') $result[] = 'ancestor-or-self::*[@id=\'' . $single['path'] . '\']'; return '[not(' . implode(' or ', $result) . ')]'; } protected static function _gen_xpath_select_expression() { $aux = self::_gen_xpath_exclude_select_expression_aux(); $result = '//text()' . $aux; $result .= ' | //input' . $aux; $result .= ' | //textarea' . $aux; if ((self::$_translate_attributes && self::$_translate_title_attribute) || (self::$_translate_attributes && self::$_translate_alt_attribute)) $result .= ' | //img' . $aux; if (self::$_translate_meta_tags && !empty(self::$_translate_meta_tags_names)) $result .= ' | //meta' . self::_gen_xpath_select_valid_meta_tags(); return $result; } protected static function _gen_xpath_select_valid_meta_tags() { $result = array(); foreach (self::$_translate_meta_tags_names as $name) { if ($name == 'og:locale' || $name == 'og:url') continue; $property = PrisnaWPTranslateCommon::startsWith($name, 'og:') ? 'property' : 'name'; $result[] = '@' . $property . '=\'' . stripslashes($name) . '\''; } return '[(' . implode(' or ', $result) . ') and @content and string-length(@content)>0]'; } protected static function _gen_text_to_translate($_response) { $html = $_response['response']; $searchPage = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); self::$_doc = new DOMDocument('1.0', 'utf-8'); $load = @self::$_doc->loadHTML($searchPage); if (!$load) { $url = PrisnaWPTranslateCommon::removeHiddenFromUrl(self::$_full_url, self::$_seo_variable); self::_log('xml', PrisnaWPTranslateMessage::get('seo_log_xml_message', array($url, urlencode($url)))); return false; } $xpath = new DOMXPath(self::$_doc); $elements = $xpath->query(self::_gen_xpath_select_expression()); $i = 0; if ($elements != null) { foreach ($elements as $e) { if ((!self::_is_text_node($e) && !self::_is_node_with_attributes($e)) || self::_is_pointless($e)) continue; $values = self::_get_node_value_and_attributes($e); if (self::_is_empty_node_values($values)) continue; if (self::_exclude_node_values($values)) continue; self::$_node[$i] = $e; self::$_text[$i] = $values; self::$_text_hash[$i] = self::$_text[$i]; self::$_text_hash[$i] = PrisnaWPTranslateCommon::hashText(self::$_text[$i]); $i++; } } return true; } protected static function _clean_value($_value) { $value = str_replace("\r\n", "\n", $_value); return $value; } protected static function _get_node_value($_node) { return $_node->nodeValue; } protected static function _get_parent_node($_node) { if (self::_is_text_node($_node)) return $_node->parentNode; return $_node; } protected static function _get_node_value_and_attributes($_node) { $result = array(); $value = self::_clean_value(self::_get_node_value($_node)); if (!empty($value)) $result['content'] = $value; if (!method_exists($_node, 'getAttribute')) $_node = self::_get_parent_node($_node); $value = $_node->getAttribute('value'); if (!empty($value)) $result['value'] = self::_clean_value($value); if (strtolower($_node->nodeName) == 'meta') { $value = $_node->getAttribute('content'); if (!empty($value)) { $result['cmeta'] = self::_clean_value($value); return $result; } } if (self::$_translate_attributes && method_exists($_node, 'getAttribute')) { if (self::$_translate_title_attribute) { $value = $_node->getAttribute('title'); if (!empty($value)) $result['title'] = self::_clean_value($value); } if (self::$_translate_alt_attribute) { $value = $_node->getAttribute('alt'); if (!empty($value)) $result['alt'] = self::_clean_value($value); } if (self::$_translate_placeholder_attribute) { $value = $_node->getAttribute('placeholder'); if (!empty($value)) $result['placeholder'] = self::_clean_value($value); } } return $result; } protected static function _is_text_node($_node) { return $_node->nodeType == 3; } protected static function _is_node_with_attributes($_node) { if ($_node->nodeType != 1) return false; $node_name = strtolower($_node->nodeName); if ($node_name == 'input' || $node_name == 'textarea' || $node_name == 'meta') return true; if (!self::$_translate_attributes) return false; if ($node_name != 'img') return false; return self::$_translate_title_attribute || self::$_translate_alt_attribute || self::$_translate_placeholder_attribute; } protected static function _get_global_cache() { $file = self::_get_url(true); if (is_file($file)) { $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) return false; $result = new DOMDocument('1.0', 'utf-8'); if (@!$result->loadXML($contents)) return false; return $result; } return false; } protected static function _get_url_cache() { if (empty(self::$_url_hash)) return false; $file = self::_get_url(); if (is_file($file)) { $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) return false; $result = new DOMDocument('1.0', 'utf-8'); if (@!$result->loadXML($contents)) return false; return $result; } return false; } protected static function _path_n_query($_url) { $url = parse_url($_url); if (empty($url)) return false; $path = $url['path']; if (array_key_exists('query', $url) && !empty($url['query'])) $path .= '?' . $url['query']; return $path; } protected static function _get_url_file($_url, $_from, $_to) { $path = self::_path_n_query($_url); $clean_url = self::removeLanguage($path); $hash = PrisnaWPTranslateCommon::hashUrl($clean_url); return PRISNA_WP_TRANSLATE_CACHE . '/' . self::getOriginalLanguage($_from) . '_' . self::getOriginalLanguage($_to) . '_' . $hash . '.xml'; } protected static function _get_url($_global=false, $_to=null, $_special=false) { $to = empty($_to) ? self::$_to : $_to; if (!$_special) { $end = $_global ? 'global' : self::$_url_hash; return PRISNA_WP_TRANSLATE_CACHE . '/' . self::getOriginalLanguage(self::$_from) . '_' . self::getOriginalLanguage($to) . '_' . $end . '.xml'; } else { $url = PrisnaWPTranslateCommon::removeHiddenFromUrl(self::$_url, PrisnaWPTranslateConfig::getSeoParameterName()); $hash = PrisnaWPTranslateCommon::hashUrl($url); return PRISNA_WP_TRANSLATE_CACHE . '/' . self::getOriginalLanguage(self::$_from) . '_' . self::getOriginalLanguage($to) . '_' . $hash . '.xml'; } } protected static function _lookup($_xml, $_text_hash) { if (empty($_xml)) return false; $xpath = new DOMXPath($_xml); return $xpath->query("/translations/word[@hash='$_text_hash']/translation")->item(0); } protected static function _translate($_end=false) { $matrix = array(); $j = 0; for ($i=0; $i<count(self::$_text_hash); $i++) foreach (self::$_text_hash[$i] as $name => $value) { if (array_key_exists($i, self::$_text_translated)) continue; $matrix[$j] = array( 'hash' => $value, 'ix' => $i, 'name' => $name ); $j++; } if ($xml = self::_get_url_cache()) { for ($i=0; $i<count($matrix); $i++) { $result = self::_lookup($xml, $matrix[$i]['hash']); if (!empty($result)) { if (!array_key_exists($matrix[$i]['ix'], self::$_text_translated)) self::$_text_translated[$matrix[$i]['ix']] = array(); self::$_text_translated[$matrix[$i]['ix']][$matrix[$i]['name']] = is_string($result) ? $result : $result->nodeValue; } } } if (count(array_filter(self::$_text_translated)) != count(self::$_text_hash)) { if ($xml = self::_get_global_cache()) { for ($i=0; $i<count($matrix); $i++) { if (array_key_exists($matrix[$i]['ix'], self::$_text_translated)) if (array_key_exists($matrix[$i]['name'], self::$_text_translated[$matrix[$i]['ix']])) if (!empty(self::$_text_translated[$matrix[$i]['ix']][$matrix[$i]['name']])) continue; $result = self::_lookup($xml, $matrix[$i]['hash']); if (!empty($result)) { if (!array_key_exists($matrix[$i]['ix'], self::$_text_translated)) self::$_text_translated[$matrix[$i]['ix']] = array(); self::$_text_translated[$matrix[$i]['ix']][$matrix[$i]['name']] = is_string($result) ? $result : $result->nodeValue; } } } } if (!$_end && count(array_filter(self::$_text_translated)) != count(self::$_text_hash)) { $ixs = array_keys(array_diff(array_keys(self::$_text_hash), array_keys(self::$_text_translated))); foreach ($ixs as $ix) { foreach (self::$_text[$ix] as $key => $value) { if (strpos($value, "\n") !== false) self::$_text[$ix][$key] = str_replace("\n", "\n\n", $value); } self::$_text_hash[$ix] = PrisnaWPTranslateCommon::hashText(self::$_text[$ix]); } self::_translate(true); } else ksort(self::$_text_translated); } protected static function _exclude_node_values($_values) { foreach ($_values as $key => $value) { if (PrisnaWPTranslateTranslateTransport::excludeText($value)) return true; } return false; } protected static function _is_empty_node_values($_values) { foreach ($_values as $key => $value) { if (empty($value)) continue; if (preg_match('/^\d+$/', $value)) continue; if (preg_match('/^[\*\=\-]+$/', $value)) continue; return false; } return true; } protected static function _is_pointless($_node) { $node_name = strtolower($_node->nodeName); if ($_node->nodeType == 1 && $node_name == 'img') return false; if ($_node->nodeType == 1 && $node_name == 'input') return false; if ($_node->nodeType == 1 && $node_name == 'textarea') return false; if ($node_name == 'meta') { $_text = $_node->getAttribute('content'); if (!empty($_text)) return false; } $_text = $_node->nodeValue; if (empty($_text)) return true; $temp = PrisnaWPTranslateCommon::stripBreakLinesAndTabs($_text); if (empty($temp)) return true; $temp = str_replace(' ', '', $temp); if (empty($temp)) return true; return false; } protected static function _fetch() { $headers = array(); $cookie = !empty($_COOKIE) ? PrisnaWPTranslateCommon::buildCookie($_COOKIE) : null; $ua = PrisnaWPTranslateCommon::getUserAgent(); if (!empty($ua)) $headers['User-Agent'] = $ua; $result = PrisnaWPTranslateCommon::fetchUrl(self::$_full_url, $headers, true); $result['response'] = self::_strip_scripts($result['response']); return $result; } protected static function _restore_scripts($_html) { $result = $_html; $first = 0; $search = '<script></script>'; for ($i=0; $i<count(self::$_scripts[0]); $i++) { $replace = self::$_scripts[0][$i]; $first = strpos($result, $search, ($first == 0 ? 0 : $first + strlen(self::$_scripts[0][$i-1]))); if ($first === false) continue; $before = substr($result, 0, $first); $after = substr($result, $first + strlen($search)); $result = $before . $replace . $after; } return $result; } protected static function _strip_scripts($_html) { self::$_scripts = array(); preg_match_all('/<script\b[^>]*>[\s\S]*?<\/script>/s', $_html, self::$_scripts); $html = str_replace(self::$_scripts[0], '<script></script>', $_html); return $html; } protected static function _is_language_enabled($_lang) { $languages = array_map('strtolower', self::$_seo_languages); return in_array(strtolower($_lang), $languages); } protected static function _pre_validate() { if (PrisnaWPTranslate::isAjaxCall('prisna_wp_translate_get_token') || PrisnaWPTranslate::isAjaxCall('prisna_wp_translate_translate')) return false; return function_exists('mb_convert_encoding') && PrisnaWPTranslateConfig::getSettingValue('seo') && PrisnaWPTranslate::isAvailable(); } public static function getSeoChinese() { $result = PrisnaWPTranslateConfig::getSettingValue('seo_chinese'); if (empty($result)) return $result; $from = PrisnaWPTranslateConfig::getSettingValue('from'); return $result == $from ? '' : $result; } public static function getTrueLanguage($_language, $_state) { if ($_state) { if ($_language != 'zh') return strlen($_language) == 5 ? substr($_language, 0, 3) . strtoupper(substr($_language, -2)) : $_language; else return self::$_seo_chinese; } else { if (empty(self::$_seo_chinese)) return $_language; return self::$_seo_chinese == $_language ? 'zh' : $_language; } } public static function getSeoLanguages() { self::_initialize(); return self::$_seo_languages; } public static function getLanguages() { self::_initialize(); return self::$_all_languages; } public static function getOriginalLanguage($_language) { self::_initialize(); return self::getTrueLanguage($_language, true); } protected static function _validate() { $file = self::_get_url_file(self::$_original_url, self::$_from, self::$_to); $valid = !empty(self::$_to) ? self::_is_language_enabled(self::$_to) : false; $is_seo_request = PrisnaWPTranslateCommon::getVariable(PrisnaWPTranslateConfig::getSeoParameterName(), 'GET') !== false; return !$is_seo_request && $valid && is_file($file); } public static function log($_kind, $_message) { self::_log($_kind, $_message); } protected static function _log($_kind, $_message) { $xml = self::_get_log(); $root = $xml->firstChild; $entry = $xml->createElement('entry'); $date_attribute = $xml->createAttribute('date'); $kind_attribute = $xml->createAttribute('kind'); $date_attribute->value = date('c'); $kind_attribute->value = $_kind; $entry->appendChild($date_attribute); $entry->appendChild($kind_attribute); $ua = PrisnaWPTranslateCommon::getUserAgent(); $ip = PrisnaWPTranslateCommon::getRemoteAddress(); $message = empty($ua) ? $_message : $_message . '<br />' . $ua; $message = empty($ip) ? $message : $message . ' - ' . $ip; $entry_cdata = $xml->createCDATASection($message); $entry->appendChild($entry_cdata); $root->appendChild($entry); $file = PrisnaWPTranslateCommon::getLogFile(PrisnaWPTranslateCommon::getTestApiKey()); PrisnaWPTranslateFileHandler::write($file, $xml->saveXML()); self::_adjust_log_size($file, $xml); } protected static function _get_user_agent() { } protected static function _adjust_log_size($_file, $_xml) { $xpath = new DOMXPath($_xml); $entries = $xpath->query("//entry"); $diff = (int) $entries->length - self::$_max_log_entries; if ($diff > 0) { $root = $_xml->firstChild; for ($i=0; $i<$diff; $i++) { $entry = $entries->item($i); $root->removeChild($entry); } PrisnaWPTranslateFileHandler::write($_file, $_xml->saveXML()); } } protected static function _get_log() { $file = PrisnaWPTranslateCommon::getLogFile(PrisnaWPTranslateCommon::getTestApiKey()); if (is_file($file)) { $contents = PrisnaWPTranslateFileHandler::read($file); if ($contents == '') { self::_remove_log($file); self::_create_log($file); return self::_get_log(); } if ($contents == false) return self::_get_log(); $result = new DOMDocument('1.0', 'utf-8'); $result->preserveWhiteSpace = false; if (@!$result->loadXML($contents)) { self::_remove_log($file); self::_create_log($file); return self::_get_log(); } $result->formatOutput = true; return $result; } else { self::_create_log($file); return self::_get_log($file); } } protected static function _create_log($_path) { $xml = new DOMDocument('1.0', 'utf-8'); $xml->formatOutput = true; $root = $xml->createElement('logs'); $date_attribute = $xml->createAttribute('date'); $date_attribute->value = date('c'); $root->appendChild($date_attribute); $xml->appendChild($root); PrisnaWPTranslateFileHandler::create($_path, $xml->saveXML()); } protected static function _remove_log($_path) { PrisnaWPTranslateFileHandler::delete($_path); } public static function loadLinks() { $languages = self::_get_languages(true); if (count($languages) == 0) return; $lang = PrisnaWPTranslateCommon::getVariable(PrisnaWPTranslateConfig::getSeoParameterName(), 'GET'); foreach ($languages as $language) { if ($language == $lang) { $flag = true; continue; } PrisnaWPTranslateCommon::loadLink($language, self::_gen_link($language)); } } } class PrisnaWPTranslateSitemap { protected $_type; protected $_frecuency; protected $_priority; protected $_exceptions; protected $_exclusions; protected $_data; protected $_xml; protected $_enabled; protected $_last_modified; public function __construct($_type) { $this->_enabled = PrisnaWPTranslateConfig::getSettingValue('seo') == 'true' && PrisnaWPTranslateCommon::apiKeyValidate(PrisnaWPTranslateConfig::getSettingValue('api_key')); if (!$this->_enabled) return; $this->_type = in_array($_type, array('xml', 'csv')) ? $_type : null; $sitemap_rule = PrisnaWPTranslateConfig::getSettingValue('sitemap_rule'); $this->_frecuency = $sitemap_rule['changefreq']; $this->_priority = $sitemap_rule['priority']; $this->_gen_exceptions(PrisnaWPTranslateConfig::getSettingValue('sitemap_rule_exceptions')); $this->_gen_exclusions(PrisnaWPTranslateConfig::getSettingValue('sitemap_rule_exclude')); $this->_gen_data(); } protected function _gen_data() { $result = array(); $from = PrisnaWPTranslateConfig::getSettingValue('from'); $enable_permalinks = PrisnaWPTranslateConfig::getSettingValue('enable_permalinks'); $xml = PrisnaWPTranslateTranslateTransport::getPermalinks(); $xpath = new DOMXPath($xml); $translations = $xpath->query('/permalinks/permalink/translation[@from="' . $from . '"]'); foreach ($translations as $translation) { if (empty($translation)) continue; if (!method_exists($translation, 'getAttribute')) continue; if (empty($translation->parentNode)) continue; if (!method_exists($translation->parentNode, 'getAttribute')) continue; $domain = $translation->parentNode->getAttribute('domain'); $scope = $translation->parentNode->getAttribute('scope'); $to = $translation->getAttribute('to'); $permalink_translation = $enable_permalinks ? $translation->nodeValue : $scope; $target_scope = empty($permalink_translation) ? $scope : $permalink_translation; if (empty($to) || empty($scope) || empty($domain)) continue; if (!in_array($to, PrisnaWPTranslateConfig::getSettingValue('seo_languages'))) continue; if ($this->_should_exclude_permalink($scope, 'source')) continue; if ($this->_should_exclude_permalink($target_scope, 'target')) continue; $url = PrisnaWPTranslateSeo::convertURL($target_scope, $to); $entry = array( 'scope' => $scope, 'domain' => $domain, 'language' => $to, 'url' => $url ); $result[] = $entry; } $this->_data = $result; } protected function _get_entry($_single) { $url = $_single['url']; if ($exception = $this->_check_exception_rules($url)) { $last_modified = array_key_exists('lastmod', $exception) ? $exception['lastmod'] : $this->_get_last_mod($_single); $frecuency = $exception['changefreq']; $priority = $exception['priority']; } else { $last_modified = $this->_get_last_mod($_single); $frecuency = $this->_frecuency; $priority = $this->_priority; } $this->_save_last_modified($last_modified); return array( 'loc' => $url, 'lastmod' => $last_modified, 'changefreq' => $frecuency, 'priority' => $priority ); } protected function _get_last_mod($_single) { $from = PrisnaWPTranslateConfig::getSettingValue('from'); $to = $_single['language']; $file = PRISNA_WP_TRANSLATE_CACHE . '/' . $from . '_' . $to . '_' . $_single['domain'] . '.xml'; if (!file_exists($file)) return null; return date('Y-m-d', filemtime($file)); } protected function _render_files() { $result = ''; $template = "/seo/sitemap_row_$this->_type.tpl"; foreach ($this->_data as $single) { $info = $this->_get_entry($single); if (empty($info)) continue; $result .= PrisnaWPTranslateCommon::renderObject((object) $info, array( 'type' => 'file', 'content' => $template )); } $result = PrisnaWPTranslateCommon::renderObject((object) array( 'content' => $result ), array( 'type' => 'file', 'content' => "/seo/sitemap_$this->_type.tpl" )); if ($this->_type == 'xml') $result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"" . PRISNA_WP_TRANSLATE_CSS . "/sitemap.xsl\"?>\n$result"; $this->_db_save_last_modified(); return $result; } public static function robots($_output, $_public) { if ($public =! '0') { $path = PrisnaWPTranslateCommon::getHomeUrl('/' . PrisnaWPTranslateConfig::getSitemapFilename() . '.xml'); $output .= "Sitemap: $path"; } return $output; } public static function initialize() { if (!isset($_SERVER['REQUEST_URI'])) return; $file = PrisnaWPTranslateCommon::getFilename($_SERVER['REQUEST_URI']); $type = PrisnaWPTranslateCommon::getFilenameExtension($file); if ($file == PrisnaWPTranslateConfig::getSitemapFilename() . '.xml' || $file == PrisnaWPTranslateConfig::getSitemapFilename() . '.csv') { $result = PrisnaWPTranslateSitemap::render($type); header('HTTP/1.1 200 OK', true, 200); header('X-Robots-Tag: noindex, follow', true); header('Content-Type: ' . ($type == 'xml' ? 'text/xml' : 'text/plain')); echo $result; $url = PrisnaWPTranslateCommon::getHomeUrl('/' . PrisnaWPTranslateConfig::getSitemapFilename() . '.' . $type); PrisnaWPTranslateSeo::log('success', PrisnaWPTranslateMessage::get('seo_log_sitemap_success_message', $url)); die(); } } protected function _get_xml() { if (is_null($this->_xml)) $this->_xml = new DOMDocument('1.0', 'utf-8'); return $this->_xml; } protected function _gen_exclusions($_exclusions) { $this->_exclusions = array(); if (empty($_exclusions)) return; $rows = preg_split("/(\n\r|\r\n|\n|\r){1,}/", $_exclusions); if (count($rows) < 1) return; foreach ($rows as $row) $this->_exclusions[] = trim($row); } protected function _gen_exceptions($_exceptions) { $this->_exceptions = array(); if (empty($_exceptions)) return; $rows = preg_split("/(\n\r|\r\n|\n|\r){1,}/", $_exceptions); if (count($rows) < 1) return; foreach ($rows as $row) { $items = explode(',', $row); $count = count($items); if ($count < 3 || $count > 4) continue; if (empty($items[0]) || empty($items[1]) || empty($items[2])) continue; if (!in_array($items[1], array('always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'))) continue; if (!is_numeric($items[2]) || (float) $items[2] > 1) continue; $exception = array( 'pattern' => $items[0], 'changefreq' => $items[1], 'priority' => $items[2] ); if ($count == 4 && !empty($items[3])) $exception['lastmod'] = $items[3]; $this->_exceptions[] = $exception; } } protected function _check_exception_rules($_path) { if (count($this->_exceptions) < 1) return false; foreach ($this->_exceptions as $exception) { if (@preg_match($exception['pattern'], $_path)) { $result = array( 'changefreq' => $exception['changefreq'], 'priority' => $exception['priority'] ); if (array_key_exists('lastmod', $exception)) { $date = strtotime($exception['lastmod']); if ($date != -1 && $date !== false) $result['lastmod'] = date('c', $date); } return $result; } } return false; } protected function _should_exclude_permalink($_scope, $_target) { if (count($this->_exclusions) < 1) return false; $target = PrisnaWPTranslateConfig::getSettingValue('sitemap_rule_exclude_target'); if ($target != $_target && $target != 'both') return false; foreach ($this->_exclusions as $pattern) { if (@preg_match($pattern, $_scope)) return true; } return false; } protected function _save_last_modified($_last_modified) { if (is_null($this->_last_modified)) $this->_last_modified = $_last_modified; $new = strtotime($_last_modified); $old = strtotime($this->_last_modified); if ($new > $old) $this->_last_modified = $_last_modified; } protected function _db_save_last_modified() { if (is_null($this->_last_modified)) return; $new = strtotime($this->_last_modified); $old = strtotime(PrisnaWPTranslateConfig::getSettingValue(PrisnaWPTranslateConfig::getSitemapIdName())); if ($old == -1 || $old == false || $new > $old) { $result = PrisnaWPTranslateConfig::getSettings(true, true); $result[PrisnaWPTranslateConfig::getSitemapIdName()] = array('value' => $this->_last_modified); $name = PrisnaWPTranslateConfig::getDbSettingsName(); if (!get_option($name)) add_option($name, $result); else update_option($name, $result); if (!get_option($name)) { delete_option($name); add_option($name, $result); } } } protected function _render_site_index() { if (!$this->_enabled) return; $loc = PrisnaWPTranslateCommon::getHomeUrl('/' . PrisnaWPTranslateConfig::getSitemapFilename() . '.xml'); $lastmod = PrisnaWPTranslateConfig::getSettingValue(PrisnaWPTranslateConfig::getSitemapIdName()); return PrisnaWPTranslateCommon::renderObject((object) array( 'loc' => $loc, 'lastmod' => $lastmod ), array( 'type' => 'file', 'content' => '/seo/sitemap_index.tpl', 'meta_tag_rules' => array( array( 'expression' => empty($lastmod), 'tag' => 'lastmod.empty' ) ) )); } protected function _render() { if (!$this->_enabled) return; if (is_null($this->_type)) return; return $this->_render_files(); } public static function render($_type) { $me = new PrisnaWPTranslateSitemap($_type); return $me->_render(); } public static function renderSiteIndex() { $me = new PrisnaWPTranslateSitemap('xml'); return $me->_render_site_index(); } public static function isViewing() { return PrisnaWPTranslateCommon::getVariable(PrisnaWPTranslateConfig::getSitemapHandle(), 'GET') === 'true' && in_array(PrisnaWPTranslateCommon::getVariable(PrisnaWPTranslateConfig::getSitemapHandle() . '-type', 'GET'), array('xml', 'csv')); } } ?><?php
class PrisnaWPTranslate { protected static $_available; protected static $_shortcode_ix = 0; public static function initialize() { if (PrisnaWPTranslateConfig::getSettingValue('seo') == 'true' && PrisnaWPTranslateCommon::apiKeyValidate(PrisnaWPTranslateConfig::getSettingValue('api_key'))) { add_filter('wpseo_sitemap_index', array('PrisnaWPTranslateSitemap', 'renderSiteIndex')); PrisnaWPTranslateSitemap::initialize(); } add_action('after_setup_theme', array('PrisnaWPTranslateSeo', 'initialize')); add_action('widgets_init', array('PrisnaWPTranslate', '_initialize_widget')); add_action('wp_head', array('PrisnaWPTranslate', '_header')); add_filter('walker_nav_menu_start_el', array('PrisnaWPTranslate', '_menu_item'), 10, 2); add_action('init', array('PrisnaWPTranslate', '_get_token'), 11); add_action('init', array('PrisnaWPTranslate', '_translate'), 11); } public static function _header() { $custom_css = PrisnaWPTranslateConfig::getSettingValue('custom_css'); PrisnaWPTranslateCommon::renderCSS($custom_css); } public static function _menu_item($_item_output, $_item) { if ($_item->object == 'prisna_wp_translate') $_item_output = do_shortcode('[' . PrisnaWPTranslateConfig::getWidgetName(true) . ']'); return $_item_output; } public static function _initialize_widget() { $location_widget = PrisnaWPTranslateConfig::getSettingValue('location_widget'); $layout = PrisnaWPTranslateConfig::getSettingValue('layout'); if ($location_widget == 'top' && $layout == 'dropdown') $location_widget = 'true'; add_shortcode(PrisnaWPTranslateConfig::getWidgetName(true), array('PrisnaWPTranslate', '_translator_shortcode')); add_shortcode(PrisnaWPTranslateConfig::getWidgetName(true) . '-dont-translate', array('PrisnaWPTranslate', '_dont_translate_shortcode')); add_shortcode(PrisnaWPTranslateConfig::getWidgetName(true) . '-show-hide', array('PrisnaWPTranslate', '_show_hide_shortcode')); if (in_array($location_widget, array('true', 'shortcode'))) { register_widget('PrisnaWPTranslateUI'); } else { add_action('wp_head', array('PrisnaWPTranslate', '_initialize_head')); add_action('wp_footer', array('PrisnaWPTranslate', '_initialize_footer'), 100); add_action('wp_enqueue_scripts', array('PrisnaWPTranslate', '_enqueue_scripts')); } } public static function _initialize_head() { if (!self::isAvailable()) return; PrisnaWPTranslateSeo::loadLinks(); if (PrisnaWPTranslateCommon::isBot()) return; PrisnaWPTranslateCommon::loadStyle(PrisnaWPTranslateConfig::getSettingValue('size'), 'translator-' . PrisnaWPTranslateConfig::getSettingValue('layout'), PrisnaWPTranslateConfig::getVersion()); if (PrisnaWPTranslateCommon::isEditOnSite()) PrisnaWPTranslateCommon::loadStyle('onsite', 'translator', PrisnaWPTranslateConfig::getVersion()); } public static function _initialize_footer() { if (!self::isAvailable()) return; self::_initialize(); self::_render_seo(); } public static function _enqueue_scripts() { wp_enqueue_script('jquery'); if (PrisnaWPTranslateCommon::isEditOnSite()) wp_enqueue_script('jquery-ui-draggable'); } public static function _show_hide_shortcode($_attributes=array(), $_content='') { self::$_shortcode_ix++; $selected = PrisnaWPTranslateConfig::getSettingValue('translated_to_class'); $behavior = !is_array($_attributes) || !array_key_exists('behavior', $_attributes) || !in_array($_attributes['behavior'], array('show', 'hide')) ? 'show' : $_attributes['behavior']; $except = !is_array($_attributes) || !array_key_exists('except', $_attributes) || empty($_attributes['except']) ? array() : explode(',', $_attributes['except']); $base = 'prisna-wp-translate-'; $unique = $base . 'show-hide-' . self::$_shortcode_ix; $class_attributes = array($unique, $base . 'behavior-' . $behavior); $styles = array('<style type="text/css">'); if ($behavior != 'show') $styles[] = ".$unique { display: none; }"; $aux_style = array(); foreach ($except as $language) { $selector = $base . 'except-' . $language; $aux_style[] = ".$selected$language .$unique.$selector"; $class_attributes[] = $selector; } $styles[] = implode(',', $aux_style) . ' { display: ' . ($behavior == 'show' ? 'none' : 'block') . '; }'; $styles[] = '</style>'; $content = implode('', $styles); return $content . self::_prepare_shortcode($_content, implode(' ', $class_attributes)); } public static function _dont_translate_shortcode($_attributes=array(), $_content='') { return self::_prepare_shortcode($_content, 'dont-translate'); } protected static function _prepare_shortcode($_content, $_class) { $is_inline = strpos($_content, "\n") === false; if (!$is_inline) { $_content = preg_replace('#^</p>#', '', $_content); $_content = preg_replace('#<p>$#', '', $_content); $_content = wpautop($_content); } $tag = $is_inline ? 'span' : 'div'; return sprintf('<%1$s class="%3$s">%2$s</%1$s>', $tag, do_shortcode($_content), $_class); } public static function _translator_shortcode() { if (!in_array(PrisnaWPTranslateConfig::getSettingValue('location_widget'), array('true', 'shortcode'))) return; if (!self::isAvailable()) return; $layout = PrisnaWPTranslateConfig::getSettingValue('layout'); $id = PrisnaWPTranslateConfig::getSettingValue('widget_class'); return '<div class="' . $id . '"></div>'; } public static function _render_seo() { echo PrisnaWPTranslateSeo::genTranslator(); } public static function _translate() { if (!self::isAjaxCall('prisna_wp_translate_translate')) return; if (!self::isAvailable(false)) { echo '{"error":"Error ' . __LINE__ . ': Translate"}'; exit; } if (PrisnaWPTranslateConfig::getSettingValue('api_key') == PrisnaWPTranslateCommon::getTestApiKey()) { echo '{"error":"Error ' . __LINE__ . ': Translate"}'; exit; } require_once PRISNA_WP_TRANSLATE_PROCEDURES . '/translate.class.php'; exit; } public static function isAjaxCall($_action) { if (!isset($_SERVER['REQUEST_METHOD'])) return false; $action = PrisnaWPTranslateCommon::getVariable('action'); if (empty($action)) return false; return $action == $_action; } public static function _get_token() { if (!self::isAjaxCall('prisna_wp_translate_get_token')) return; if (!self::isAvailable(false)) { echo '{"error":"Error ' . __LINE__ . ': Token"}'; exit; } if (PrisnaWPTranslateConfig::getSettingValue('api_key') == PrisnaWPTranslateCommon::getTestApiKey()) { echo '{"error":"Error ' . __LINE__ . ': Token"}'; exit; } require_once PRISNA_WP_TRANSLATE_PROCEDURES . '/token.class.php'; exit; } protected static function _is_cache_writable() { $flag = PrisnaWPTranslateConfig::getCacheFlag(); if ($flag) return true; $folder = PrisnaWPTranslateCommon::isFolderWritable(PRISNA_WP_TRANSLATE_CACHE); if ($folder !== true) return false; $files = PrisnaWPTranslateCommon::areFolderFilesWritable(PRISNA_WP_TRANSLATE_CACHE); if ($files !== true) return false; PrisnaWPTranslateConfig::setCacheFlag(true); return true; } protected static function _is_fsockopen_available() { return function_exists('fsockopen'); } protected static function _is_hash_available() { return function_exists('hash'); } protected static function _is_dom_document_available() { return class_exists('DOMDocument'); } protected static function _is_ssl_document_available() { return PrisnaWPTranslateCommon::isMcryptInstalled(); } protected static function _api_key_validate() { $value = PrisnaWPTranslateConfig::getSettingValue('api_key'); if (empty($value)) return false; if (strlen($value) != 56 && strlen($value) != 32) return false; if (strlen($value) == 32) return $value == PrisnaWPTranslateCommon::getTestApiKey(); return true; } protected static function _client_secret_microsoft_validate() { if (PrisnaWPTranslateConfig::getSettingValue('translation_service') != 'ma') return true; $value = PrisnaWPTranslateConfig::getSettingValue('microsoft_client_secret'); return !empty($value); } protected static function _client_id_microsoft_validate() { if (PrisnaWPTranslateConfig::getSettingValue('translation_service') != 'ma') return true; $value = PrisnaWPTranslateConfig::getSettingValue('microsoft_client_id'); return !empty($value); } protected static function _api_key_google_validate() { if (PrisnaWPTranslateConfig::getSettingValue('translation_service') != 'gt') return true; if (!PrisnaWPTranslateCommon::isMcryptInstalled()) return false; $value = PrisnaWPTranslateConfig::getSettingValue('google_api_key'); return !empty($value); } public static function isAvailable($_admin=true) { if (defined('WP_ADMIN') && $_admin) return false; if (PrisnaWPTranslateConfig::getSettingValue('test_mode') == 'true' && !current_user_can('administrator')) if (!PrisnaWPTranslateCommon::userHasAccess()) return false; if (PrisnaWPTranslateConfig::getSettingValue('detect_browser_locale') == 'always' && PrisnaWPTranslateConfig::getSettingValue('detect_browser_locale_always_action') == 'display') if (PrisnaWPTranslateCommon::getLocaleLanguage(PrisnaWPTranslateConfig::getSettingValue('languages')) == PrisnaWPTranslateConfig::getSettingValue('from')) return false; if (!self::_api_key_validate() || !self::_api_key_google_validate() || !self::_client_id_microsoft_validate() || !self::_client_secret_microsoft_validate()) return false; if (!self::_is_cache_writable()) return false; if (!self::_is_hash_available()) return false; if (!self::_is_dom_document_available()) return false; if (!self::_is_ssl_document_available()) return false; if (!self::_is_fsockopen_available()) return false; global $post; if (!is_object($post)) return true; $settings = PrisnaWPTranslateConfig::getSettingsValues(); if ($post->post_type == 'page' && array_key_exists('exclude_pages', $settings)) { $pages = $settings['exclude_pages']['value']; if (in_array($post->ID, $pages)) return false; } if ($post->post_type == 'post' && array_key_exists('exclude_posts', $settings)) { $posts = $settings['exclude_posts']['value']; if (in_array($post->ID, $posts)) return false; } if ($post->post_type == 'post' && array_key_exists('exclude_categories', $settings)) { $categories = $settings['exclude_categories']['value']; $post_categories = wp_get_post_categories($post->ID); if (PrisnaWPTranslateCommon::inArray($categories, $post_categories)) return false; } return true; } protected static function _initialize() { if (PrisnaWPTranslateCommon::isBot()) return; $settings = PrisnaWPTranslateConfig::getSettingsValues(); $translator = new PrisnaWPTranslateOutput((object) $settings); $on_before_load = $translator->getProperty('on_before_load'); echo $translator->render(array( 'type' => 'file', 'content' => '/main.tpl', 'meta_tag_rules' => array( array( 'expression' => empty($on_before_load), 'tag' => 'on_before_load.empty' ), array( 'expression' => PrisnaWPTranslateCommon::isEditOnSite(), 'tag' => 'onsite.enabled' ) ) )); } } class PrisnaWPTranslateUI extends WP_Widget { public function __construct() { parent::__construct(PrisnaWPTranslateConfig::getWidgetName(true), PrisnaWPTranslateConfig::getWidgetName(), array( 'classname' => PrisnaWPTranslateConfig::getSettingValue('widget_class'), 'description' => PrisnaWPTranslateMessage::get('widget_description') )); if (!PrisnaWPTranslate::isAvailable()) return; if (is_active_widget(false, false, PrisnaWPTranslateConfig::getWidgetName(true))) { add_action('wp_head', array('PrisnaWPTranslate', '_initialize_head')); add_action('wp_footer', array('PrisnaWPTranslate', '_initialize_footer'), 100); add_action('wp_enqueue_scripts', array('PrisnaWPTranslate', '_enqueue_scripts')); } } public function form($_instance) { echo '<div class="prisna_wp_translate_sample_' . PrisnaWPTranslateConfig::getSettingValue('layout') . '_language"></div>'; echo PrisnaWPTranslateMessage::get('widget_settings', array(PrisnaWPTranslateCommon::getAdminPluginUrl())); return 'noform'; } public function widget($_arguments, $_instance) { if (!PrisnaWPTranslate::isAvailable()) return; extract($_arguments, EXTR_SKIP); echo $before_widget; echo '<div></div>'; echo $after_widget; } } class PrisnaWPTranslateOutput extends PrisnaWPTranslateItem { protected static $_rendered; public $options_formatted; public $url_library; public $url_library_onsite; public $on_before_load; protected static $_exclude_rules; public function __construct($_properties) { $this->_properties = $_properties; $this->_gen_options(); self::_set_rendered(false); } protected static function _set_rendered($_state) { if (self::_get_rendered() === true) return; self::$_rendered = $_state; } protected static function _get_rendered() { return self::$_rendered; } protected function _gen_form_language() { $result = '{ title: "Edit translation", original: "Original", translation: "Translation from %s to %s", button_save: "Save", button_save_all: "Save (to all pages)", button_cancel: "Close", of: "of", html_element: "html tag", help: "<div class=\"prisna-wp-translate-onsite-tooltip-title\">Usage</div><div class=\"prisna-wp-translate-onsite-tooltip-body\">This form allows on-site manual translation adjustments. To edit attributes such as: title, alt, placeholder and meta tags, make sure to enable these features in: Advanced > General > Translate attributes<br/><br/>The form is divided in the following sections.<br/><br/>Original: it\'s an informative section displaying the details of the text being modified.<br/><br/>Translation: it\'s where the edition takes place. All the entered changes will be treated as text, even HTML markup. To display different HTML markup for different languages, use the translator\'s content shortcode in the page/post editor.<br/><br/>Save vs Save (to all pages) buttons: The difference between these buttons is whether the changes will be saved for the current URL, or they will be saved for every URL. For instance, when editing a menu entry, it\'d be best to save the changes to all pages.</div>" }'; return $result; } public function _prepare_option_value($_id, $_value) { $value = $_value; if ($_id == 'custom_html' || PrisnaWPTranslateCommon::endsWith($_id, '_template') || PrisnaWPTranslateCommon::endsWith($_id, '_template_dd')) $value = PrisnaWPTranslateCommon::stripBreakLinesAndTabs($value); if ($_id == 'custom_flags') { $value = array(); $values = explode(',', $_value); foreach ($values as $single) { $item = explode(':', $single); $value[$item[0]] = $item[1]; } } if (PrisnaWPTranslateCommon::endsWith($_id, '_selector')) $value = trim($value); if (PrisnaWPTranslateValidator::isBool($value)) $value = $value == 'true' || $value === true; if (in_array($_id, array('on_before_initialize', 'on_initialize', 'override', 'custom_languages_names', 'native_languages'))) return $value; if ($_id == 'on_start') { if (PrisnaWPTranslateCommon::isEditOnSite()) { $aux = '
function(from, to, options) {
PrisnaTranslateOnSite.destroy();'; if ($value != '') $aux .= '
(' . $value . ')(from, to, options);'; $aux .= '}'; return $aux; } return $value; } if ($_id == 'on_complete') { if (PrisnaWPTranslateCommon::isEditOnSite()) { $current_url = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : false; if (empty($current_url)) { global $wp; $current_url = home_url(add_query_arg(array(),$wp->request)); } $current_url = PrisnaWPTranslateSeo::removeLanguage(PrisnaWPTranslateCommon::removeForceTranslationParameter(PrisnaWPTranslateCommon::removeEditOnSite($current_url))); $hash = empty($current_url) ? false : PrisnaWPTranslateCommon::hashUrl($current_url); $allowed_languages = json_encode(PrisnaWPTranslateCommon::getUserTranslatorLanguages()); $aux = '
function(filtered_elements, translation, source, from, to, options, restore) {
PrisnaTranslateOnSite.run(filtered_elements, translation, source, from, to, options, restore, ' . $this->_gen_form_language() . ', "' . $hash . '", "' . PrisnaWPTranslateCommon::getAjaxUrl() . '", ' . $allowed_languages . ');'; if ($value != '') $aux .= '
(' . $value . ')(filtered_elements, translation, source, from, to, options, restore);'; $aux .= '}'; return $aux; } return $value; } if ($_id == 'location_widget' && $_value == 'top') if (PrisnaWPTranslateConfig::getSettingValue('layout') == 'dropdown') $value = 'true'; if ($_id == 'rtl_languages') $value = empty($value) ? false : explode(',', $value); return json_encode($value); } public function render($_options, $_html_encode=false) { if (self::_get_rendered()) return ''; self::_set_rendered(true); $result = parent::render($_options, $_html_encode); return PrisnaWPTranslateCommon::stripBreakLinesAndTabs($result); } public static function excludePermalink($_url) { $rules = self::_get_exclude_permalinks_rules(); foreach ($rules as $rule) if (@preg_match($rule, $_url) === 1) return true; return false; } protected static function _get_exclude_permalinks_rules() { if (!is_null(self::$_exclude_rules)) return self::$_exclude_rules; $rules = PrisnaWPTranslateConfig::getSettingValue('exclude_permalinks_rules'); self::$_exclude_rules = array(); if (empty($rules)) return self::$_exclude_rules; $rows = preg_split("/(\n\r|\r\n|\n|\r){1,}/", $rules); if (count($rows) < 1) return self::$_exclude_rules; foreach ($rows as $row) if (@preg_match($row, null) !== false) self::$_exclude_rules[] = $row; return self::$_exclude_rules; } protected function _exclude_current_url() { if (!PrisnaWPTranslateConfig::getSettingValue('auto_translate_permalinks')) return true; return self::excludePermalink(PrisnaWPTranslateCommon::getCurrentUrl()); } protected function _gen_options() { $result = array(); foreach ($this->_properties as $key => $property) if (array_key_exists('option_id', $property) && !PrisnaWPTranslateValidator::isEmpty($property['option_id'])) $result[$key] = array( 'option_id' => $property['option_id'], 'value' => $this->_prepare_option_value($key, $property['value']) ); if (PrisnaWPTranslateCommon::isEditOnSite()) { $result['on_site'] = array( 'option_id' => 'onSite', 'value' => 'true' ); $result['on_start'] = array( 'option_id' => 'onStart', 'value' => $this->_prepare_option_value('on_start', (property_exists($this->_properties, 'on_start') ? $this->_properties->on_start['value'] : '')) ); $result['on_complete'] = array( 'option_id' => 'onComplete', 'value' => $this->_prepare_option_value('on_complete', (property_exists($this->_properties, 'on_complete') ? $this->_properties->on_complete['value'] : '')) ); if (array_key_exists('local_storage', $result)) unset($result['local_storage']); if (array_key_exists('local_storage_expires', $result)) unset($result['local_storage_expires']); if (array_key_exists('clear_local_storage', $result)) unset($result['clear_local_storage']); } if (PrisnaWPTranslateCommon::userIsAdmin()) { $result['log'] = array( 'option_id' => 'log', 'value' => 'true' ); $result['key_message'] = array( 'option_id' => 'keyMessage', 'value' => json_encode(PrisnaWPTranslateMessage::get('key_message')) ); } if (PrisnaWPTranslateConfig::getSettingValue('api_key') == PrisnaWPTranslateCommon::getTestApiKey()) $result['test'] = array( 'option_id' => 'test', 'value' => 'true' ); if (PrisnaWPTranslateConfig::getSettingValue('native_languages')) $result['native_languages'] = array( 'option_id' => 'nativeLanguagesNames', 'value' => json_encode(PrisnaWPTranslateCommon::getNativeLanguages(PrisnaWPTranslateConfig::getSettingValue('languages'))) ); if ($this->_exclude_current_url()) $result['auto_translate_permalinks'] = array( 'option_id' => 'autoTranslatePermalinks', 'value' => 'false' ); if (PrisnaWPTranslateConfig::getSettingValue('translate_meta_tags')) $result['translate_meta_tags'] = array( 'option_id' => 'translateMetaTags', 'value' => json_encode(PrisnaWPTranslateConfig::getSettingValue('translate_meta_tags_names')) ); if (PrisnaWPTranslateConfig::getSettingValue('detect_browser_locale') == 'always') { $aux_locale = PrisnaWPTranslateConfig::getSettingValue('detect_browser_locale_always_action'); if ($aux_locale == 'translate') { $locale = PrisnaWPTranslateCommon::getLocaleLanguage(PrisnaWPTranslateConfig::getSettingValue('languages')); if ($locale !== false && PrisnaWPTranslateConfig::getSettingValue('from') != $locale) { $result['detect_browser_locale_aux'] = array( 'option_id' => 'detected', 'value' => json_encode($locale) ); } else unset($result['detect_browser_locale']); } else if (array_key_exists('detect_browser_locale', $result)) unset($result['detect_browser_locale']); } else if (PrisnaWPTranslateConfig::getSettingValue('detect_browser_locale') == 'first') { $locale = PrisnaWPTranslateCommon::getLocaleLanguage(PrisnaWPTranslateConfig::getSettingValue('languages')); $aux_locale = $this->_exists_first_cookie(); if ($aux_locale === false && $locale !== false && PrisnaWPTranslateConfig::getSettingValue('from') != $locale) { $result['detect_browser_locale_aux'] = array( 'option_id' => 'detected', 'value' => json_encode($locale) ); } else unset($result['detect_browser_locale']); } if (PrisnaWPTranslateConfig::getSettingValue('hide_language_or_flag_low_resolutions') == false) if (array_key_exists('low_resolution', $result)) unset($result['low_resolution']); if (PrisnaWPTranslateConfig::getSettingValue('query_string_auto_translate') == false) if (array_key_exists('query_string_auto_param', $result)) unset($result['query_string_auto_param']); if (PrisnaWPTranslateConfig::getSettingValue('layout') == 'bar' && PrisnaWPTranslateConfig::getSettingValue('adjust_position') == 'true') $result['container_class'] = array( 'option_id' => 'containerClass', 'value' => $this->_prepare_option_value('container_class', PrisnaWPTranslateConfig::getSettingValue('override_container_class')) ); if (PrisnaWPTranslateConfig::getSettingValue('layout') == 'bar') { if (in_array(PrisnaWPTranslateConfig::getSettingValue('location_widget'), array('true', 'shortcode'))) { $result['bar_container_id'] = array( 'option_id' => 'barContainerId', 'value' => $this->_prepare_option_value('bar_container_id', PrisnaWPTranslateConfig::getSettingValue('widget_class')) ); } else if (array_key_exists('bar_container_id', $result)) unset($result['bar_container_id']); } if (PrisnaWPTranslateConfig::getSettingValue('layout') == 'dropdown') { if (in_array(PrisnaWPTranslateConfig::getSettingValue('location_widget'), array('true', 'top', 'shortcode'))) { $result['dropdown_container_id'] = array( 'option_id' => 'dropdownContainerId', 'value' => $this->_prepare_option_value('dropdown_container_id', PrisnaWPTranslateConfig::getSettingValue('widget_class')) ); } else if (array_key_exists('dropdown_container_id', $result)) unset($result['dropdown_container_id']); } if (!array_key_exists('location_widget', $result)) { if (array_key_exists('widget_class', $result)) unset($result['widget_class']); } if (!array_key_exists('location_widget', $result) || PrisnaWPTranslateConfig::getSettingValue('location_widget') !== 'false') { if (array_key_exists('custom_location_insert_mode', $result)) unset($result['custom_location_insert_mode']); if (array_key_exists('custom_parent', $result)) unset($result['custom_parent']); if (array_key_exists('location_custom', $result)) unset($result['location_custom']); } if (array_key_exists('sticky', $result) && !in_array(PrisnaWPTranslateConfig::getSettingValue('location_widget'), array('top', 'xy'))) unset($result['sticky']); if (array_key_exists('location_widget', $result) && in_array(PrisnaWPTranslateConfig::getSettingValue('location_widget'), array('true', 'shortcode'))) $result['location_widget']['value'] = 'true'; if (PrisnaWPTranslateConfig::getSettingValue('location_widget') == 'xy') { $xy_vertical = $this->_get_position_value(PrisnaWPTranslateConfig::getSettingValue('xy_vertical')); $xy_horizontal = $this->_get_position_value(PrisnaWPTranslateConfig::getSettingValue('xy_horizontal')); if (!empty($xy_vertical)) $result['xy_vertical'] = array( 'option_id' => $xy_vertical['option_id'], 'value' => $this->_prepare_option_value('xy_vertical', $xy_vertical['value']) ); if (!empty($xy_horizontal)) $result['xy_horizontal'] = array( 'option_id' => $xy_horizontal['option_id'], 'value' => $this->_prepare_option_value('xy_horizontal', $xy_horizontal['value']) ); } else { if (array_key_exists('xy_vertical', $result)) unset($result['xy_vertical']); if (array_key_exists('xy_horizontal', $result)) unset($result['xy_horizontal']); if (array_key_exists('xy_parent', $result)) unset($result['xy_parent']); } if (is_404()) $result['cache'] = array( 'option_id' => 'cache', 'value' => 'false' ); $home = PrisnaWPTranslateCommon::stripHost(PrisnaWPTranslateCommon::getHomeUrl('/')); $result['home'] = array( 'option_id' => 'home', 'value' => $this->_prepare_option_value('home', $home) ); $to = PrisnaWPTranslateCommon::getVariable(PrisnaWPTranslateConfig::getSeoParameterName(), 'GET'); if (!empty($to)) { $all_languages = array_map('strtolower', array_keys(PrisnaWPTranslateSeo::getLanguages())); if (in_array($to, $all_languages)) { $result['auto_translate_permalinks'] = array( 'option_id' => 'autoTranslatePermalinks', 'value' => 'false' ); $url_info = parse_url(PrisnaWPTranslateCommon::removeHiddenFromUrl(PrisnaWPTranslateSeo::getCurrentUrl(), PrisnaWPTranslateConfig::getSeoParameterName())); $url = ''; if (!empty($url_info['path'])) $url .= $url_info['path']; if (!empty($url_info['query'])) $url .= '?' . $url_info['query']; $hash_url = empty($url) ? false : PrisnaWPTranslateCommon::hashUrl($url); $from = PrisnaWPTranslateConfig::getSettingValue('from'); $to = PrisnaWPTranslateSeo::getOriginalLanguage($to); $file = PrisnaWPTranslateCommon::getPath($hash_url, $from, $to); if (is_file($file)) { $result['from'] = array( 'option_id' => 'from', 'value' => $this->_prepare_option_value('from', $to) ); $result['from_original'] = array( 'option_id' => 'fromOriginal', 'value' => $this->_prepare_option_value('from_original', $from) ); $result['seo_variable'] = array( 'option_id' => 'seoVariable', 'value' => $this->_prepare_option_value('seoVariable', PrisnaWPTranslateConfig::getSettingValue('seo_variable')) ); $result['seo_url_mode'] = array( 'option_id' => 'seoUrlMode', 'value' => $this->_prepare_option_value('seoUrlMode', PrisnaWPTranslateConfig::getSettingValue('seo_url_mode')) ); $in_cache = array(); $languages = PrisnaWPTranslateConfig::getSettingValue('languages'); $xml = PrisnaWPTranslateConfig::getSettingValue('enable_permalinks') ? PrisnaWPTranslateTranslateTransport::getPermalinks() : null; $seo_languages = PrisnaWPTranslateSeo::getSeoLanguages(); foreach ($languages as $language) { if ($language == $to) continue; $file = PrisnaWPTranslateCommon::getPath($hash_url, $from, $language); if (is_file($file) && in_array(PrisnaWPTranslateSeo::getTrueLanguage($language, false), $seo_languages)) { $temp = array(strtolower($language)); $permalink = self::_permalink_lookup($url, $from, $language); $temp[] = empty($permalink) ? PrisnaWPTranslateCommon::stringDiff($home, $url) : $permalink; $in_cache[] = $temp; } } $in_cache[] = array($from, PrisnaWPTranslateCommon::stringDiff($home, $url)); $result['in_cache'] = array( 'option_id' => 'inCache', 'value' => $this->_prepare_option_value('inCache', $in_cache) ); if (count($in_cache) > 1) { $seo_chinese = PrisnaWPTranslateSeo::getSeoChinese(); if (!empty($seo_chinese)) $result['seo_chinese'] = array( 'option_id' => 'seoChinese', 'value' => $this->_prepare_option_value('seoChinese', strtolower($seo_chinese)) ); } } } } $this->url_library = PrisnaWPTranslateCommon::getScriptUrl('translator-' . PrisnaWPTranslateConfig::getSettingValue('layout'), PrisnaWPTranslateConfig::getVersion()); $this->url_library_onsite = PrisnaWPTranslateCommon::getScriptUrl('translator-onsite', PrisnaWPTranslateConfig::getVersion()); $this->on_before_load = PrisnaWPTranslateConfig::getSettingValue('on_before_load'); $this->options_formatted = PrisnaWPTranslateCommon::renderObject($result, array( 'type' => 'html', 'content' => "\t{{ option_id }}:{{ value }},\n" )); } protected static function _exists_first_cookie() { if (!isset($_COOKIE)) return false; if (!is_array($_COOKIE)) return false; return array_key_exists('prisna-wp-translate-' . PrisnaWPTranslateConfig::getSettingValue('id') . '-first-detected', $_COOKIE); } protected static function _get_position_value($_position) { extract($_position); if (empty($kind)) return false; $position = !empty($position) ? (int) $position : $position; if (empty($unit) && ($position == '' || $position != 0)) return false; $result = array($position, $unit); if (in_array($unit, array('auto', 'inherit'))) unset($result[0]); return array( 'option_id' => 'xy' . ucfirst($kind), 'value' => implode('', $result) ); } protected static function _permalink_lookup($_scope, $_from, $_to) { if (!PrisnaWPTranslateConfig::getSettingValue('enable_permalinks')) return false; $xml = PrisnaWPTranslateTranslateTransport::getPermalinks(); $xpath = new DOMXPath($xml); $translation = $xpath->query("/permalinks/permalink[@scope='$_scope']/translation[@from='$_from' and @to='$_to']")->item(0); if (is_null($translation)) return false; if (is_null($translation->nodeValue)) return false; return $translation->nodeValue; } } PrisnaWPTranslate::initialize(); ?>
<?php
class PrisnaWPTranslateAdmin { public static function initialize() { add_action('media_buttons', array('PrisnaWPTranslateAdmin', '_editor_button'), 15); add_filter('plugin_action_links', array('PrisnaWPTranslateAdmin', 'addSettingsLink'), 10, 2); add_action('wp_ajax_nopriv_prisna_wp_translate_get_users', array('PrisnaWPTranslateAdminTranslations', '_get_users')); add_action('wp_ajax_prisna_wp_translate_get_users', array('PrisnaWPTranslateAdminTranslations', '_get_users')); add_action('wp_ajax_nopriv_prisna_wp_translate_check_version', array('PrisnaWPTranslateAdminVersion', '_check_version')); add_action('wp_ajax_prisna_wp_translate_check_version', array('PrisnaWPTranslateAdminVersion', '_check_version')); add_action('wp_ajax_nopriv_prisna_wp_translate_update', array('PrisnaWPTranslateAdminVersion', '_update')); add_action('wp_ajax_prisna_wp_translate_update', array('PrisnaWPTranslateAdminVersion', '_update')); add_action('wp_ajax_nopriv_prisna_wp_translate_get_permalink_translations', array('PrisnaWPTranslateAdminTranslations', '_get_permalinks_translations')); add_action('wp_ajax_prisna_wp_translate_get_permalink_translations', array('PrisnaWPTranslateAdminTranslations', '_get_permalinks_translations')); add_action('wp_ajax_nopriv_prisna_wp_translate_save_permalink_translations', array('PrisnaWPTranslateAdminTranslations', '_save_permalink_translations')); add_action('wp_ajax_prisna_wp_translate_save_permalink_translations', array('PrisnaWPTranslateAdminTranslations', '_save_permalink_translations')); add_action('admin_init', array('PrisnaWPTranslateAdmin', '_initialize')); add_action('admin_head', array('PrisnaWPTranslateAdmin', '_remove_messages')); add_action('plugins_loaded', array('PrisnaWPTranslateAdmin', 'initializeMenus')); add_filter('wp_setup_nav_menu_item', array('PrisnaWPTranslateAdmin', '_admin_menu_item'), 10, 1 ); register_activation_hook(realpath(dirname(__FILE__) . '/../prisna-wp-translate.php'), array('PrisnaWPTranslateAdmin', '_admin_notice_hook')); add_action('admin_notices', array('PrisnaWPTranslateAdmin', '_admin_notice_activation')); add_action('wp_ajax_nopriv_prisna_wp_translate_get_languages_per_resource', array('PrisnaWPTranslateAdminTranslations', '_get_languages_per_resource')); add_action('wp_ajax_prisna_wp_translate_get_languages_per_resource', array('PrisnaWPTranslateAdminTranslations', '_get_languages_per_resource')); add_action('wp_ajax_nopriv_prisna_wp_translate_remove_resource', array('PrisnaWPTranslateAdminTranslations', '_remove_resource')); add_action('wp_ajax_prisna_wp_translate_remove_resource', array('PrisnaWPTranslateAdminTranslations', '_remove_resource')); add_action('wp_ajax_nopriv_prisna_wp_translate_get_cached_translations', array('PrisnaWPTranslateAdminTranslations', '_get_cached_translations')); add_action('wp_ajax_prisna_wp_translate_get_cached_translations', array('PrisnaWPTranslateAdminTranslations', '_get_cached_translations')); add_action('wp_ajax_nopriv_prisna_wp_translate_save_cached_translations', array('PrisnaWPTranslateAdminTranslations', '_save_cached_translations')); add_action('wp_ajax_prisna_wp_translate_save_cached_translations', array('PrisnaWPTranslateAdminTranslations', '_save_cached_translations')); add_action('wp_ajax_nopriv_prisna_wp_translate_save_cached_translations_onsite', array('PrisnaWPTranslateAdminTranslations', '_save_cached_translations_onsite')); add_action('wp_ajax_prisna_wp_translate_save_cached_translations_onsite', array('PrisnaWPTranslateAdminTranslations', '_save_cached_translations_onsite')); add_action('wp_ajax_nopriv_prisna_wp_translate_remove_language', array('PrisnaWPTranslateAdminTranslations', '_remove_file')); add_action('wp_ajax_prisna_wp_translate_remove_language', array('PrisnaWPTranslateAdminTranslations', '_remove_file')); } public static function _initialize() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator() && !PrisnaWPTranslateCommon::userHasAccess()) return; self::_watch_events(); self::_select_language(); self::_initialize_meta_box(); self::_load_styles(); self::_load_scripts(); } public static function addSettingsLink($_links, $_file) { if (!current_user_can('manage_options')) return; if (PrisnaWPTranslateCommon::endsWith($_file, 'prisna-wp-translate.php')) $_links[] = self::_gen_settings_link(); return $_links; } protected static function _gen_settings_link() { return '<a href="plugins.php?page=' . PrisnaWPTranslateConfig::getAdminHandle() . '">' . PrisnaWPTranslateMessage::get('settings_link') . '</a>'; } public static function _admin_notice_activation() { if (get_transient(PrisnaWPTranslateConfig::getWidgetName(true) . '-admin-notice')) { ?>
<div class="updated notice is-dismissible">
<p><?php echo PrisnaWPTranslateMessage::get('plugin_activated', self::_gen_settings_link()); ?></p>
</div>
<?php
delete_transient(PrisnaWPTranslateConfig::getWidgetName(true) . '-admin-notice'); } } public static function _admin_notice_hook() { set_transient(PrisnaWPTranslateConfig::getWidgetName(true) . '-admin-notice', true, 60); } protected static function _watch_events() { @header('X-XSS-Protection: 0'); if (current_user_can('manage_options')) { if (PrisnaWPTranslateAdminEvents::isGeneratingPoFile()) self::_po(); if (PrisnaWPTranslateAdminEvents::isExportingAll() || PrisnaWPTranslateAdminEvents::isImportingAll() || PrisnaWPTranslateAdminEvents::isExportingTranslations() || PrisnaWPTranslateAdminEvents::isImportingTranslations() || PrisnaWPTranslateAdminEvents::isSavingSettings() || PrisnaWPTranslateAdminEvents::isResetingSettings() || PrisnaWPTranslateAdminEvents::isRemovingResource()) if (!check_admin_referer(PrisnaWPTranslateConfig::getAdminHandle(), '_prisna_wpnonce')) PrisnaWPTranslateCommon::redirect(PrisnaWPTranslateCommon::getAdminPluginUrl()); if (PrisnaWPTranslateAdminEvents::isExportingAll()) { self::_export_all(); die(); } } if (current_user_can('manage_options') || PrisnaWPTranslateCommon::userIsTranslator()) { if (PrisnaWPTranslateAdminEvents::isExportingTranslations()) { self::_export_translations(); die(); } if (PrisnaWPTranslateAdminEvents::isRemovingResource()) self::_remove_resource_from_export_page(); } if (current_user_can('manage_options') || PrisnaWPTranslateCommon::userHasAccess() || (PrisnaWPTranslateCommon::userIsTranslator() && PrisnaWPTranslateAdminEvents::isImportingTranslations())) { if (PrisnaWPTranslateAdminEvents::isSavingSettings()) self::_save_settings(); } if (current_user_can('manage_options') || PrisnaWPTranslateCommon::userHasAccess()) { if (PrisnaWPTranslateAdminEvents::isResetingSettings()) self::_reset_settings(); } } protected static function _po() { header('Content-Type: text/html; charset=utf-8'); PrisnaWPTranslateMessage::genPo(); die(); } protected static function _save_settings() { PrisnaWPTranslateAdminForm::save(); } protected static function _reset_settings() { PrisnaWPTranslateAdminForm::reset(); } protected static function _export_all() { PrisnaWPTranslateExportallField::run(); } protected static function _export_translations() { PrisnaWPTranslateTransexportField::run(); } protected static function _remove_resource_from_export_page() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()) return; PrisnaWPTranslateTransexportField::remove(); } public static function _meta_box() { global $nav_menu_selected_id; ?>
<div>
<?php echo '<div class="prisna_wp_translate_sample_' . PrisnaWPTranslateConfig::getSettingValue('layout') . '_language"></div>'; ?>
<p class="button-controls">
<span class="add-to-menu">
<input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> class="button-secondary submit-add-to-menu right" name="prisna-wp-translate-admin-menu-add" id="prisna-wp-translate-admin-menu-add" value="<?php esc_attr_e('Add to Menu'); ?>" />
</span>
</p>
</div>
<script type="text/javascript">jQuery("document").ready(function() { PrisnaWPTranslateAdminMenu.initialize(); });</script>
<?php
} public static function _admin_menu_item($item) { if (!is_object($item)) return $item; if ($item->object == 'prisna_wp_translate') $item->type_label = __('Custom'); return $item; } protected static function _initialize_meta_box() { if (!in_array(PrisnaWPTranslateConfig::getSettingValue('location_widget'), array('true', 'shortcode'))) return; add_meta_box('prisna-wp-translate-admin-menu', 'Prisna Translate', array('PrisnaWPTranslateAdmin', '_meta_box' ), 'nav-menus', 'side', 'default'); } protected static function _load_scripts() { if (PrisnaWPTranslateAdminEvents::isLoadingAdminPage() || PrisnaWPTranslateAdminEvents::isLoadingTranslationsPage() || strpos(PrisnaWPTranslateCommon::getAdminMenusUrl(), $_SERVER['REQUEST_URI']) !== false) { wp_enqueue_script('prisna-wp-translate-admin-common', PRISNA_WP_TRANSLATE_JS .'/common.class.js', 'jquery-ui-core', PrisnaWPTranslateConfig::getVersion(), true); wp_enqueue_script('prisna-wp-translate-admin', PRISNA_WP_TRANSLATE_JS .'/admin.class.js', 'jquery-ui-core', PrisnaWPTranslateConfig::getVersion()); wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('thickbox'); } } protected static function _load_styles() { if (PrisnaWPTranslateAdminEvents::isLoadingAdminPage() || PrisnaWPTranslateAdminEvents::isLoadingTranslationsPage() || strpos(PrisnaWPTranslateCommon::getAdminWidgetsUrl(), $_SERVER['REQUEST_URI']) !== false || strpos(PrisnaWPTranslateCommon::getAdminMenusUrl(), $_SERVER['REQUEST_URI']) !== false) { wp_enqueue_style('prisna-wp-translate-admin', PRISNA_WP_TRANSLATE_CSS .'/admin.css', false, PrisnaWPTranslateConfig::getVersion(), 'screen'); wp_enqueue_style('thickbox'); } } public static function _remove_messages() { if (PrisnaWPTranslateAdminEvents::isLoadingAdminPage() || PrisnaWPTranslateAdminEvents::isLoadingTranslationsPage() || strpos(PrisnaWPTranslateCommon::getAdminWidgetsUrl(), $_SERVER['REQUEST_URI']) !== false) PrisnaWPTranslateCommon::renderCSS('.update-nag,div.updated,div.error,.notice{display:none !important;}'); } public static function initializeMenus() { add_action('admin_menu', array('PrisnaWPTranslateAdmin', '_add_options_page')); } public static function _editor_button($_editor_id) { wp_enqueue_style('prisna-wp-translate-admin', PRISNA_WP_TRANSLATE_CSS .'/admin.css', false, PrisnaWPTranslateConfig::getVersion(), 'screen'); wp_enqueue_script('prisna-wp-translate-admin', PRISNA_WP_TRANSLATE_JS .'/admin.class.js', 'jquery-ui-core', PrisnaWPTranslateConfig::getVersion()); $languages = new PrisnaWPTranslateSelectField(array( 'title_message' => '', 'description_message' => '', 'id' => 'prisna_wp_translate_showhide_language', 'type' => 'select', 'multiple' => true, 'values' => PrisnaWPTranslateCommon::getLanguages(), 'value' => '' )); ?>
<div class="prisna_wp_translate_admin_shortcode_button_group">
<a href="javascript:;" onclick="PrisnaWPTranslateAdmin.showShortcodeList(this, '<?php echo esc_attr($_editor_id); ?>');" class="button add_media prisna_wp_translate_admin_shortcode_button" title="Prisna Translate" data-editor="<?php echo esc_attr($_editor_id); ?>" id="prisna_wp_translate_shortcode_button_<?php echo esc_attr($_editor_id); ?>">
<span class="wp-media-buttons-icon"></span> Prisna Translate
</a>
<ul class="prisna_wp_translate_admin_shortcode_dropdown_menu prisna_wp_translate_admin_shortcode_show_form prisna_wp_translate_no_display" id="prisna_wp_translate_shortcode_list_<?php echo esc_attr($_editor_id); ?>">
<?php if (in_array(PrisnaWPTranslateConfig::getSettingValue('location_widget'), array('true', 'shortcode'))) { ?>
<li><a href="javascript:;" onclick="PrisnaWPTranslateAdmin.insertWidget('<?php echo esc_attr($_editor_id); ?>'); return false;"><?php echo PrisnaWPTranslateMessage::get('widget_insert_widget'); ?></a></li>
<?php } ?>
<li><a href="javascript:;" onclick="PrisnaWPTranslateAdmin.dontTranslate('<?php echo esc_attr($_editor_id); ?>'); return false;"><?php echo PrisnaWPTranslateMessage::get('widget_dont_translate'); ?></a></li>
<li>
<a href="javascript:;" onclick="PrisnaWPTranslateAdmin.showHideForm('<?php echo esc_attr($_editor_id); ?>'); this.blur(); return false;"><?php echo PrisnaWPTranslateMessage::get('widget_show_hide'); ?></a>
<ul class="prisna_wp_translate_admin_shortcode_showhide_form">
<li>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="prisna_wp_translate_admin_shortcode_showhide_form_title" colspan="2"><?php echo PrisnaWPTranslateMessage::get('widget_show_hide_default'); ?></td>
</tr>
<tr class="prisna_wp_translate_admin_shortcode_showhide_form_radio_row">
<td>
<input type="radio" name="prisna_wp_translate_showhide_default" value="show" checked="checked" id="prisna_wp_translate_showhide_default_show" class="prisna_wp_translate_radio_option" />
<label for="prisna_wp_translate_showhide_default_show" onclick="PrisnaWPTranslateAdmin.selectShowHideForm('<?php echo esc_attr($_editor_id); ?>', 'show');"><?php echo PrisnaWPTranslateMessage::get('widget_show_hide_show'); ?></label>
</td>
<td>
<input type="radio" name="prisna_wp_translate_showhide_default" value="hide" id="prisna_wp_translate_showhide_default_hide" class="prisna_wp_translate_radio_option" />
<label for="prisna_wp_translate_showhide_default_hide" onclick="PrisnaWPTranslateAdmin.selectShowHideForm('<?php echo esc_attr($_editor_id); ?>', 'hide');"><?php echo PrisnaWPTranslateMessage::get('widget_show_hide_hide'); ?></label>
</td>
</tr>
</table>
</li>
<li>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="prisna_wp_translate_admin_shortcode_showhide_form_title"><?php echo PrisnaWPTranslateMessage::get('widget_show_hide_except'); ?></td>
</tr>
<tr>
<td><?php echo $languages->output('select_single.tpl'); ?></td>
</tr>
</table>
</li>
<li>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="prisna_wp_translate_admin_shortcode_showhide_form_btn"><input class="button-primary" type="submit" value="<?php echo PrisnaWPTranslateMessage::get('widget_show_hide_add'); ?>" onclick="PrisnaWPTranslateAdmin.showHide('<?php echo esc_attr($_editor_id); ?>'); return false;" /></td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<?php } public static function _add_options_page() { if (current_user_can('activate_plugins')) add_submenu_page('plugins.php', PrisnaWPTranslateConfig::getName(false, true), PrisnaWPTranslateConfig::getName(false, true), 'manage_options', PrisnaWPTranslateConfig::getAdminHandle(), array('PrisnaWPTranslateAdmin', '_render_main_form')); else if (PrisnaWPTranslateCommon::userHasAccess()) { $current_user = wp_get_current_user(); $caps = $current_user->caps; if (!is_array($caps)) return; foreach ($caps as $cap => $value) if ($value) add_menu_page(PrisnaWPTranslateConfig::getName(false, true), PrisnaWPTranslateConfig::getName(false, true), $cap, PrisnaWPTranslateConfig::getAdminHandle(), array('PrisnaWPTranslateAdmin', '_render_main_form')); } if (PrisnaWPTranslateCommon::userIsTranslator()) { $current_user = wp_get_current_user(); $caps = $current_user->caps; if (!is_array($caps)) return; foreach ($caps as $cap => $value) if ($value) add_menu_page(PrisnaWPTranslateConfig::getTranslationsName(), PrisnaWPTranslateConfig::getTranslationsName(), $cap, PrisnaWPTranslateConfig::getTranslationsHandle(), array('PrisnaWPTranslateAdmin', '_render_translations_form'), 'dashicons-translation'); } } protected static function _gen_meta_tag_rules_for_tabs() { $tabs = array( array('general', 'advanced', 'translations', 'seo', 'layout', 'styles', 'responsive'), array('advanced_general', 'advanced_miscellaneous', 'advanced_access', 'advanced_import_export'), array('translations_general', 'translations_import', 'translations_export', 'translations_translators_access', 'translations_onsite'), array('seo_general', 'seo_permalink', 'seo_sitemap', 'seo_log') ); $current_tabs = array( PrisnaWPTranslateCommon::getVariable('prisna_tab', 'POST'), PrisnaWPTranslateCommon::getVariable('prisna_tab_2', 'POST'), PrisnaWPTranslateCommon::getVariable('prisna_tab_3', 'POST'), PrisnaWPTranslateAdminForm::getImportedStatus() || PrisnaWPTranslateAdminEvents::isResetingSettings() || PrisnaWPTranslateAdminEvents::isChangingLayout() || PrisnaWPTranslateAdminEvents::isImportingTranslations() || PrisnaWPTranslateAdminEvents::isExportingAll() || PrisnaWPTranslateAdminEvents::isImportingAll() ? '' : PrisnaWPTranslateCommon::getVariable('prisna_tab_4', 'POST') ); $result = self::_gen_meta_tag_rules_for_tabs_aux($tabs, $current_tabs); return $result; } protected static function _gen_meta_tag_rules_for_tabs_aux($_tabs, $_currents, $_level=0) { $result = array(); if (!is_array($_tabs[0])) { $current = $_currents[$_level]; if (PrisnaWPTranslateValidator::isEmpty($current)) $current = $_tabs[0]; for ($i=0; $i<count($_tabs); $i++) $result[] = array( 'expression' => $_tabs[$i] == $current, 'tag' => $_tabs[$i] . '.show' ); } else for ($j=0; $j<count($_tabs); $j++) $result = array_merge($result, self::_gen_meta_tag_rules_for_tabs_aux($_tabs[$j], $_currents, $j)); return $result; } public static function _render_translations_form() { $form = new PrisnaWPTranslateTranslationsForm(); echo $form->render(array( 'type' => 'file', 'content' => '/admin/translations_form.tpl', 'meta_tag_rules' => self::_gen_meta_tag_rules_for_tabs() )); } public static function _render_main_form() { $form = new PrisnaWPTranslateAdminForm(); echo $form->render(array( 'type' => 'file', 'content' => '/admin/main_form.tpl', 'meta_tag_rules' => self::_gen_meta_tag_rules_for_tabs() )); } protected static function _select_language() { load_plugin_textdomain(PrisnaWPTranslateConfig::getAdminLanguageDomain(), false, dirname(plugin_basename(__FILE__)) . '/../languages'); } } class PrisnaWPTranslateAdminVersion { protected static function _commit($_name, $_result) { if (!get_option($_name)) add_option($_name, $_result); else update_option($_name, $_result); if (!get_option($_name)) { delete_option($_name); add_option($_name, $_result); } } protected static function _save($_setting) { $settings = PrisnaWPTranslateConfig::_get_settings(); $settings[$_setting['id']]['value'] = $_setting['value']; self::_commit(PrisnaWPTranslateConfig::getDbSettingsName(), $settings); } protected static function _save_checked_version($_version) { $setting = array( 'id' => 'version', 'value' => $_version ); self::_save($setting); } protected static function _verify_write_permissions() { $base = realpath(PRISNA_WP_TRANSLATE_PROCEDURES . '/../'); $content = PrisnaWPTranslateCommon::getDirectoryContents($base); foreach ($content as $file) { if (is_file($file)) { if (!is_writable($file)) return array( 'type' => 'file', 'value' => $file ); } else { if (!is_writable(dirname($file))) return array( 'type' => 'dir', 'value' => dirname($file) ); } } return true; } protected static function _update_plugin($_zip_data, $_version) { if (!current_user_can('update_plugins')) return array( 'success' => false, 'validate' => array( array( 'field' => 'generic', 'message' => __('You do not have sufficient permissions to update plugins for this site.') ) ), 'version' => PrisnaWPTranslateConfig::getVersion() ); global $wp_filesystem; if (empty($wp_filesystem)) { require_once (ABSPATH . '/wp-admin/includes/file.php'); WP_Filesystem(); } $package = 'prisna-wp-translate'; $destination = PRISNA_WP_TRANSLATE_PROCEDURES . '/../../'; $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/'; $working_dir = $upgrade_folder . $package; $tmp_file = $working_dir . '.zip'; if ($wp_filesystem->is_file($tmp_file)) $wp_filesystem->delete($tmp_file); if ($wp_filesystem->is_dir($working_dir)) $wp_filesystem->delete($working_dir, true); $wp_filesystem->put_contents($tmp_file, $_zip_data); $result = unzip_file($tmp_file, $working_dir); if (is_wp_error($result)) { if ($wp_filesystem->is_file($tmp_file)) $wp_filesystem->delete($tmp_file); if ($wp_filesystem->is_dir($working_dir)) $wp_filesystem->delete($working_dir, true); return array( 'success' => false, 'validate' => array( array( 'field' => 'generic', 'message' => __('Incompatible zip file. Please contact support.') ) ), 'version' => PrisnaWPTranslateConfig::getVersion() ); } $result = copy_dir($working_dir, $destination); if ($wp_filesystem->is_file($tmp_file)) $wp_filesystem->delete($tmp_file); if ($wp_filesystem->is_dir($working_dir)) $wp_filesystem->delete($working_dir, true); if (is_wp_error($result)) return array( 'success' => false, 'validate' => array( array( 'field' => 'generic', 'message' => __('Error copying files. Please contact support.') ) ), 'version' => PrisnaWPTranslateConfig::getVersion() ); return array( 'success' => true, 'version' => $_version ); } public static function crc($_data) { $api_key = PrisnaWPTranslateConfig::getSettingValue('api_key'); return md5('wp' . md5($api_key . $_data)); } public static function _update() { $api_key = PrisnaWPTranslateConfig::getSettingValue('api_key'); $url = "\150\164\164\160\163://\167\167\167.\160\162\151\163\156\141.\156\145\164/\165\160\144\141\164\145_\167\160/$api_key"; if (defined('PRISNA_WP_TRANSLATE_COMPATIBILITY') && PRISNA_WP_TRANSLATE_COMPATIBILITY === true) $url .= '/compatibility'; $response = wp_remote_get($url, array( 'timeout' => 60 )); $result = !is_wp_error($response) ? @$response['body'] : false; if ($result != false) { $result = json_decode($result); if (!is_null($result)) { if ($result->success && property_exists($result, 'data')) { $file = self::_verify_write_permissions(); if ($file === true) { $crc = PrisnaWPTranslateAdminVersion::crc($result->data); if ($result->crc == $crc) { $content = PrisnaWPTranslateCommon::bsd($result->data); unset($result->data); unset($result->crc); if (!empty($content)) $result = self::_update_plugin($content, $result->version); else $result = array( 'success' => false, 'validate' => array( array( 'field' => 'generic', 'message' => __('Unsual server error. No plugin data found. Please try again in 5 minutes.', PrisnaWPTranslateConfig::getAdminLanguageDomain()) ) ), 'version' => PrisnaWPTranslateConfig::getVersion() ); } else $result = array( 'success' => false, 'validate' => array( array( 'field' => 'generic', 'message' => __('Unsual server error. CRC doesn\'t match. Please try again in 5 minutes.', PrisnaWPTranslateConfig::getAdminLanguageDomain()) ) ), 'version' => PrisnaWPTranslateConfig::getVersion() ); } else $result = array( 'success' => false, 'validate' => array( array( 'field' => 'generic', 'message' => sprintf(__('There\'s at least one %s that isn\'t writable:<br />%s<br />Update cannot continue. Set the appropriate permissions and try again.', PrisnaWPTranslateConfig::getAdminLanguageDomain()), ($file['type'] == 'file' ? __('file', PrisnaWPTranslateConfig::getAdminLanguageDomain()) : __('folder', PrisnaWPTranslateConfig::getAdminLanguageDomain())), $file['value']) ) ), 'version' => PrisnaWPTranslateConfig::getVersion() ); } else $result->version = PrisnaWPTranslateConfig::getVersion(); if (is_array($result) && $result['success']) PrisnaWPTranslateAdminForm::setImagesColors(); echo json_encode($result); exit; } } $result = self::getDefaultError($response); $result['version'] = PrisnaWPTranslateConfig::getVersion(); echo json_encode($result); exit; } public static function getDefaultError($_response, $_extra_name=false, $_extra_value=false) { $error = __('Unsual server error. Please try again in 5 minutes.', PrisnaWPTranslateConfig::getAdminLanguageDomain()); if (is_object($_response) && method_exists($_response, 'get_error_message') && $_response->get_error_message() != '') $error = $_response->get_error_message() . '. ' . $error; $validate = array( 'field' => 'generic', 'message' => $error ); if ($_extra_name != false && $_extra_value != false) $validate[$_extra_name] = $_extra_value; $result = array( 'success' => false, 'validate' => array($validate) ); return $result; } public static function _check_version() { if (!current_user_can('manage_options')) return; $url = "\150\164\164\160\163://\167\167\167.\160\162\151\163\156\141.\156\145\164/\147\145\164_\167\160_\166\145\162\163\151\157\156/"; $response = wp_remote_get($url, array( 'timeout' => 10 )); $result = !is_wp_error($response) ? @$response['body'] : false; if ($result != false) { $result = json_decode($result); if (!is_null($result)) { if ($result->success) { self::_save_checked_version($result->message); $current = PrisnaWPTranslateConfig::getVersion(); $result->update = version_compare($current, $result->message, '<'); if (!$result->update) $result->update_validate = array( array( 'field' => 'generic', 'message' => __('There\'s no need to update.', PrisnaWPTranslateConfig::getAdminLanguageDomain()) . ' ' . __('The latest version of the plugin is already installed on this site.', PrisnaWPTranslateConfig::getAdminLanguageDomain()) ) ); } echo json_encode($result); exit; } } $result = PrisnaWPTranslateAdminVersion::getDefaultError($response); echo json_encode($result); exit; } } class PrisnaWPTranslateAdminTranslations { public static function _get_users_sort($_a, $_b) { return strcmp($_a['name'], $_b['name']); } public static function _get_users() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userHasAccess()) return; $blogusers = get_users('orderby=display_name'); $result = array( 'success' => true, 'data' => array() ); $checks = array('display_name', 'nicename', 'user_login', 'email', 'ID'); foreach ($blogusers as $user) { foreach ($checks as $check) { $name = $user->{$check}; if (!empty($name)) break; } $result['data'][] = array( 'id' => $user->ID, 'name' => $name ); } usort($result['data'], array('PrisnaWPTranslateAdminTranslations', '_get_users_sort')); echo json_encode($result); exit; } public static function _get_languages_per_resource() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()) return; $resource = PrisnaWPTranslateCommon::bsd(PrisnaWPTranslateCommon::getVariable('prisna_translations_resource', 'POST')); if ($resource !== false) { $languages = self::_scan_languages_per_resource($resource); $json = array( 'resource' => $resource, 'languages' => $languages ); } else { $json = array( 'resource' => '', 'languages' => array() ); } echo json_encode($json); exit; } public static function _remove_resource() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()) return; $resource = PrisnaWPTranslateCommon::bsd(PrisnaWPTranslateCommon::getVariable('prisna_translations_resource', 'POST')); if ($resource !== false) { self::_do_remove_resource($resource); $json = array( 'resource' => PrisnaWPTranslateCommon::getVariable('prisna_translations_resource', 'POST') ); } else { $json = array( 'resource' => '' ); } echo json_encode($json); exit; } public static function _remove_file() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()) return; $file = PrisnaWPTranslateCommon::bsd(PrisnaWPTranslateCommon::getVariable('prisna_translations_languages', 'POST')); if ($file !== false) { $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); if (!PrisnaWPTranslateCommon::userCanEditFile($file, $allowed_languages)) { $json = array('language' => ''); echo json_encode($json); exit; } self::_do_remove_file($file); $json = array( 'language' => PrisnaWPTranslateCommon::getVariable('prisna_translations_languages', 'POST') ); } else { $json = array( 'language' => '' ); } echo json_encode($json); exit; } public static function _get_permalinks_translations() { if (!current_user_can('manage_options')) return; $scope = PrisnaWPTranslateCommon::bsd(PrisnaWPTranslateCommon::getVariable('prisna_permalinks_resource', 'POST')); self::_render_permalinks_translations_form($scope); exit; } public static function _get_cached_translations() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()) return; $file = PrisnaWPTranslateCommon::bsd(PrisnaWPTranslateCommon::getVariable('prisna_translations_languages', 'POST')); $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); if (!PrisnaWPTranslateCommon::userCanEditFile($file, $allowed_languages)) exit; self::_render_cached_translations_form($file); exit; } public static function _save_permalink_translations() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()) return; $scope = PrisnaWPTranslateCommon::bsd(PrisnaWPTranslateCommon::getVariable('prisna_resource', 'POST')); $translations = self::_get_new_permalink_translations(); self::_update_permalinks($scope, $translations); exit; } public static function _save_cached_translations_onsite() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()){ $result = array('success' => false); echo json_encode($result); exit; } $resource = PrisnaWPTranslateCommon::getVariable('prisna_translations_resource', 'POST'); $from = PrisnaWPTranslateCommon::getVariable('prisna_translations_from', 'POST'); $to = PrisnaWPTranslateCommon::getVariable('prisna_translations_to', 'POST'); $index = PrisnaWPTranslateCommon::getVariable('prisna_translations_index', 'POST'); $propagate = PrisnaWPTranslateCommon::getVariable('prisna_translations_propagate', 'POST'); $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); if (empty($resource) || strlen($resource) != 32 || !is_numeric($index) || PrisnaWPTranslateCommon::getLanguage($from) == false || PrisnaWPTranslateCommon::getLanguage($to) == false) { $result = array('success' => false); echo json_encode($result); exit; } $file = PRISNA_WP_TRANSLATE_CACHE . '/' . $from . '_' . $to . '_' . $resource . '.xml'; if (!file_exists($file)){ $result = array('success' => false); echo json_encode($result); exit; } if (!PrisnaWPTranslateCommon::userCanEditFile($file, $allowed_languages)){ $result = array('success' => false); echo json_encode($result); exit; } $translations = self::_get_new_translations_onsite(); if (empty($translations)){ $result = array('success' => false); echo json_encode($result); exit; } $global_file = preg_replace('/[a-zA-Z0-9]{32}/', 'global', $file); if ($propagate != 'true') { self::_update_translations($file, $translations); self::_update_translations($global_file, $translations); } else { $language_from = PrisnaWPTranslateCommon::getFromLanguageFromFile($file); $language_to = PrisnaWPTranslateCommon::getToLanguageFromFile($file); $files = PrisnaWPTranslateTranslationsField::getFilesPaths(PRISNA_WP_TRANSLATE_CACHE); foreach ($files as $single) { if (PrisnaWPTranslateCommon::getToLanguageFromFile($single) == $language_to && PrisnaWPTranslateCommon::getFromLanguageFromFile($single) == $language_from && PrisnaWPTranslateCommon::userCanEditFile($single, $allowed_languages)) { self::_update_translations($single, $translations, $file); } } self::_update_translations($global_file, $translations, $file); } $result = array( 'success' => true, 'data' => array( 'ix' => $index ) ); echo json_encode($result); exit; } public static function _save_cached_translations() { if (!current_user_can('manage_options') && !PrisnaWPTranslateCommon::userIsTranslator()) return; $file = PrisnaWPTranslateCommon::bsd(PrisnaWPTranslateCommon::getVariable('prisna_translations_languages', 'POST')); $propagate = PrisnaWPTranslateCommon::getVariable('prisna_translations_propagate', 'POST'); $allowed_languages = PrisnaWPTranslateCommon::getUserTranslatorLanguages(); if (!PrisnaWPTranslateCommon::userCanEditFile($file, $allowed_languages)) exit; $translations = self::_get_new_translations(); if (empty($translations)) exit; $global_file = preg_replace('/[a-zA-Z0-9]{32}/', 'global', $file); if ($propagate != 'true') { self::_update_translations($file, $translations); self::_update_translations($global_file, $translations); } else { $language_from = PrisnaWPTranslateCommon::getFromLanguageFromFile($file); $language_to = PrisnaWPTranslateCommon::getToLanguageFromFile($file); $files = PrisnaWPTranslateTranslationsField::getFilesPaths(PRISNA_WP_TRANSLATE_CACHE); foreach ($files as $single) { if (PrisnaWPTranslateCommon::getToLanguageFromFile($single) == $language_to && PrisnaWPTranslateCommon::getFromLanguageFromFile($single) == $language_from && PrisnaWPTranslateCommon::userCanEditFile($single, $allowed_languages)) { self::_update_translations($single, $translations, $file); } } self::_update_translations($global_file, $translations, $file); } exit; } protected static function _update_permalinks($_scope, $_translations) { $file = PRISNA_WP_TRANSLATE_CACHE . '/permalinks.xml'; $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) return ''; $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; if (@!$xml->loadXML($contents)) return false; $xml->formatOutput = true; $xpath = new DOMXPath($xml); foreach ($_translations as $single) { $from = $single['from']; $to = $single['to']; $predicate = "/permalinks/permalink[@scope=" . PrisnaWPTranslateCommon::xpathEscape($_scope) . "]/translation[@from='$from' and @to='$to']"; $xml_translation = $xpath->query($predicate)->item(0); if (is_null($xml_translation)) continue; if (PrisnaWPTranslateValidator::isEmpty($single['translation'])) { if (!is_null($xml_translation->firstChild)) $xml_translation->removeChild($xml_translation->firstChild); } else { if (!is_null($xml_translation->firstChild)) $xml_translation->firstChild->nodeValue = ltrim($single['translation'], '/'); else $xml_translation->appendChild($xml->createCDATASection(ltrim($single['translation'], '/'))); } } PrisnaWPTranslateFileHandler::write($file, $xml->saveXML()); } protected static function _update_translations($_file, $_translations, $_source_file=null) { $contents = PrisnaWPTranslateFileHandler::read($_file); if (!$contents) return ''; $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; if (@!$xml->loadXML($contents)) return false; $xml->formatOutput = true; $xpath = new DOMXPath($xml); if (is_null($_source_file)) { foreach ($_translations as $hash => $translation) self::_update_translation($xml, $xpath, $hash, $translation); } else { foreach ($_translations as $hash => $translation) { $source = self::_get_source_text($hash, $_source_file); if (!empty($source)) self::_update_translation($xml, $xpath, $hash, $translation, $source); } } PrisnaWPTranslateFileHandler::write($_file, $xml->saveXML()); } protected static function _update_translation(&$_xml, &$_xpath, $_hash, $_translation, $_source=null) { $current_translation = $_xpath->query("/translations/word[@hash='$_hash']/translation")->item(0); if (is_null($current_translation) && is_null($_source)) return false; if (is_null($current_translation)) { if (PrisnaWPTranslateValidator::isEmpty($_translation)) return false; self::_append_word($_xml, $_hash, $_translation, $_source); } else { if (PrisnaWPTranslateValidator::isEmpty($_translation)) { $word = $_xpath->query("/translations/word[@hash='$_hash']")->item(0); $_xml->firstChild->removeChild($word); } else $current_translation->firstChild->nodeValue = $_translation; } } protected static $_source_xml; protected static $_source_xpath; protected static $_source_mx; protected static function _get_source_text($_hash, $_file) { if (!is_array(self::$_source_mx)) self::$_source_mx = array(); if (array_key_exists($_hash, self::$_source_mx)) return self::$_source_mx[$_hash]; $contents = PrisnaWPTranslateFileHandler::read($_file); if (!$contents) return false; if (empty(self::$_source_xml)) self::$_source_xml = new DOMDocument(); if (@!self::$_source_xml->loadXML($contents)) return false; if (empty(self::$_source_xpath)) self::$_source_xpath = new DOMXPath(self::$_source_xml); $result = self::$_source_xpath->query("/translations/word[@hash='$_hash']/source")->item(0); return empty($result) ? false : $result->firstChild->nodeValue; } protected static function _append_word(&$_xml, $_hash, $_translation, $_source) { if (!$_xml) return false; $root = $_xml->firstChild; $word = $_xml->createElement('word'); $hash_attribute = $_xml->createAttribute('hash'); $date_attribute = $_xml->createAttribute('date'); $hash_attribute->value = $_hash; $date_attribute->value = date('c'); $word->appendChild($hash_attribute); $word->appendChild($date_attribute); $source = $_xml->createElement('source'); $source_cdata = $_xml->createCDATASection($_source); $translation = $_xml->createElement('translation'); $translation_cdata = $_xml->createCDATASection($_translation); $source->appendChild($source_cdata); $translation->appendChild($translation_cdata); $word->appendChild($source); $word->appendChild($translation); $root->appendChild($word); } protected static function _get_new_permalink_translations() { $result = array(); $translations = PrisnaWPTranslateCommon::getVariable('prisna_translations', 'POST'); if (!is_array($translations)) return $result; foreach ($translations as $translation) { if (count($translation) != 3) continue; $result[] = array( 'from' => $translation[0], 'to' => $translation[1], 'translation' => PrisnaWPTranslateCommon::sanitizePermalink($translation[2]) ); } return $result; } protected static function _get_new_translations_onsite() { $result = array(); $translations = PrisnaWPTranslateCommon::getVariable('prisna_translations', 'POST'); if (!is_array($translations)) return $result; foreach ($translations as $translation) { if (count($translation) != 2) continue; $result[PrisnaWPTranslateCommon::hashText($translation[0])] = $translation[1]; } return $result; } protected static function _get_new_translations() { $result = array(); $translations = PrisnaWPTranslateCommon::getVariable('prisna_translations', 'POST'); if (!is_array($translations)) return $result; foreach ($translations as $translation) { if (count($translation) != 2) continue; $result[$translation[0]] = $translation[1]; } return $result; } public static function _render_permalinks_translations_form($_scope) { $file = PRISNA_WP_TRANSLATE_CACHE . '/permalinks.xml'; $contents = PrisnaWPTranslateFileHandler::read($file); if (!$contents) return ''; $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; if (@!$xml->loadXML($contents)) return ''; $xpath = new DOMXPath($xml); $from = PrisnaWPTranslateConfig::getSettingValue('from'); $predicate = "/permalinks/permalink[@scope=" . PrisnaWPTranslateCommon::xpathEscape($_scope) . "]/translation[@from='$from']"; $translations = $xpath->query($predicate); $permalinks_translations_fields_formatted = self::_get_permalinks_translations_fields_formatted($translations, $_scope); $object = (object) array( 'scope_formatted' => PrisnaWPTranslateCommon::escapeHtmlBrackets($_scope), 'permalinks_translations_fields_formatted' => $permalinks_translations_fields_formatted ); $result = PrisnaWPTranslateCommon::renderObject($object, array( 'type' => 'file', 'content' => '/admin/translations_permalink.tpl' )); echo $result; } public static function _render_cached_translations_form($_file) { $contents = PrisnaWPTranslateFileHandler::read($_file); if (!$contents) return ''; $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; if (@!$xml->loadXML($contents)) return ''; $xpath = new DOMXPath($xml); $scope = $xpath->query('/translations')->item(0)->getAttribute('scope'); $from = $xpath->query('/translations')->item(0)->getAttribute('from'); $to = $xpath->query('/translations')->item(0)->getAttribute('to'); $from_language = PrisnaWPTranslateCommon::getLanguage($from); $to_language = PrisnaWPTranslateCommon::getLanguage($to); $cached_translations_fields_formatted = self::_get_cached_translations_fields_formatted($xml); $object = (object) array( 'scope' => $scope, 'from' => $from, 'to' => $to, 'from_language' => $from_language, 'to_language' => $to_language, 'cached_translations_fields_formatted' => $cached_translations_fields_formatted ); $result = PrisnaWPTranslateCommon::renderObject($object, array( 'type' => 'file', 'content' => '/admin/translations_cached.tpl' )); echo $result; } protected static function _get_permalinks_translations_fields_formatted($_translations, $_scope) { $data = self::_get_permalink_translation_data($_translations, $_scope); $result = ''; foreach ($data as $single) $result .= PrisnaWPTranslateCommon::renderObject((object) $single['data'], array( 'type' => 'file', 'content' => '/admin/translations_permalink_field.tpl', 'meta_tag_rules' => $single['meta_tag_rules'] )); return $result; } protected static function _get_cached_translations_fields_formatted($_xml) { $words = self::_get_cached_translation_words($_xml); $result = PrisnaWPTranslateCommon::renderObject($words, array( 'type' => 'file', 'content' => '/admin/translations_cached_field.tpl' )); return $result; } protected static function _get_full_translation_url($_translation, $_scope) { $result = $_translation->nodeValue; if (empty($result)) $result = $_scope; $result = PrisnaWPTranslateSeo::convertURL($result, $_translation->getAttribute('to')); return $result; } protected static function _get_pre_translation_url($_url, $_to) { $seo_url_mode = PrisnaWPTranslateConfig::getSettingValue('seo_url_mode'); switch ($seo_url_mode) { case 'query': $result = PrisnaWPTranslateCommon::getHomeUrl('/'); break; case 'path': $result = PrisnaWPTranslateCommon::getHomeUrl("/$_to/"); break; case 'subdomain': $result = PrisnaWPTranslateCommon::getHomeUrl('/'); $result = preg_replace('/www\./', '', $result, 1); $result = preg_replace('/\/\//', '//' . $_to . '.', $result, 1); if (!PrisnaWPTranslateCommon::endsWith($result, '/')) $result .= '/'; break; } return $result; } protected static function _get_post_translation_url($_url, $_to) { $seo_url_mode = PrisnaWPTranslateConfig::getSettingValue('seo_url_mode'); switch ($seo_url_mode) { case 'query': $url = PrisnaWPTranslateSeo::removeLanguage($_url); $result = strpos($url, '?') !== false ? '&' : '?'; $result .= PrisnaWPTranslateConfig::getSettingValue('seo_variable') . '=' . $_to; break; case 'path': case 'subdomain': $result = ''; break; } return $result; } protected static function _get_permalink_translation_path($_url, $_translation, $_scope) { $translation = $_translation->nodeValue; if (empty($translation)) $translation = $_scope; $url = PrisnaWPTranslateSeo::removeLanguage($_url); return PrisnaWPTranslateCommon::stringDiff($url, $translation); } protected static function _get_permalink_translation_data($_translations, $_scope) { $result = array(); foreach ($_translations as $translation) { $full_url = self::_get_full_translation_url($translation, $_scope); $to = strtolower(PrisnaWPTranslateSeo::getTrueLanguage($translation->getAttribute('to'), false)); $pre_url = self::_get_pre_translation_url($full_url, $to); $post_url = self::_get_post_translation_url($full_url, $to); $path = self::_get_permalink_translation_path($pre_url, $translation, $_scope); $placeholder = PrisnaWPTranslateCommon::stringDiff(PrisnaWPTranslateSeo::removeLanguage($pre_url), $_scope); $result[] = array( 'data' => array( 'from' => $translation->getAttribute('from'), 'from_formatted' => PrisnaWPTranslateCommon::getLanguage($translation->getAttribute('from')), 'to' => $translation->getAttribute('to'), 'to_formatted' => PrisnaWPTranslateCommon::getLanguage($translation->getAttribute('to')), 'translation' => PrisnaWPTranslateCommon::escapeHtmlBrackets($path), 'placeholder' => PrisnaWPTranslateCommon::escapeHtmlBrackets($placeholder), 'pre_url' => PrisnaWPTranslateCommon::escapeHtmlBrackets($pre_url), 'post_url' => PrisnaWPTranslateCommon::escapeHtmlBrackets($post_url), 'id' => 'prisna_permalinks' ), 'meta_tag_rules' => array( array( 'expression' => !empty($post_url), 'tag' => 'has_post_url' ), array( 'expression' => in_array($translation->getAttribute('to'), PrisnaWPTranslateConfig::getSettingValue('seo_languages')), 'tag' => 'language_enabled' ) ) ); } return $result; } protected static function _get_cached_translation_words($_xml) { $result = array(); $xpath = new DOMXPath($_xml); $words = $xpath->query('/translations/word'); $sources = $xpath->query('/translations/word/source'); $translations = $xpath->query('/translations/word/translation'); for ($i=0; $i<$words->length; $i++) { $hash = $words->item($i)->getAttribute('hash'); $result[$hash] = array( 'hash' => $hash, 'date' => $words->item($i)->getAttribute('date'), 'source' => PrisnaWPTranslateCommon::escapeHtmlBrackets($sources->item($i)->nodeValue), 'translation' => PrisnaWPTranslateCommon::escapeHtmlBrackets($translations->item($i)->nodeValue), 'id' => 'prisna_translations_cached' ); } return $result; } protected static function _do_remove_file($_file) { if (is_file($_file) && is_writable($_file)) { @unlink($_file); $filename = PrisnaWPTranslateCommon::getFilename($_file); if (strpos($filename, 'global') === false) { $temp = explode('_', basename($filename, ".xml")); $from = $temp[0]; $to = $temp[1]; $hash = $temp[2]; $data_to_update_permalinks = array(array( 'domain' => $hash, 'from' => $from, 'to' => $to )); PrisnaWPTranslateTranslateTransport::removePermalink($data_to_update_permalinks); } } } protected static function _do_remove_resource($_scope) { $hash = PrisnaWPTranslateCommon::hashUrl($_scope); $files = PrisnaWPTranslateCommon::getHashFiles($hash); $data_to_update_permalinks = array(); foreach ($files as $file_obj) { $file = $file_obj->getPathname(); if (is_file($file) && is_writable($file)) { @unlink($file); $filename = PrisnaWPTranslateCommon::getFilename($file); if (strpos($filename, 'global') === false) { $temp = explode('_', basename($filename, ".xml")); $from = $temp[0]; $to = $temp[1]; $hash = $temp[2]; $data_to_update_permalinks[] = array( 'domain' => $hash, 'from' => $from, 'to' => $to ); } } } PrisnaWPTranslateTranslateTransport::removePermalink($data_to_update_permalinks); } protected static function _scan_languages_per_resource($_scope) { $xml = PrisnaWPTranslateTranslateTransport::getPermalinks(); $result = array(); $path = PRISNA_WP_TRANSLATE_CACHE; $xpath = new DOMXPath($xml); $domain = PrisnaWPTranslateCommon::hashUrl($_scope); $translations = $xpath->query("/permalinks/permalink[@domain='$domain']/translation"); $result = array(); if (!is_null($translations)) { foreach ($translations as $translation) { $from = $translation->getAttribute('from'); $to = $translation->getAttribute('to'); $from_language = PrisnaWPTranslateCommon::getLanguage($from); $to_language = PrisnaWPTranslateCommon::getLanguage($to); if (!$from_language || !$to_language) continue; $file = $path . '/' . $from . '_' . $to . '_' . $domain . '.xml'; $result[$from_language . ' > ' . $to_language] = array( 'file' => base64_encode($file), 'from' => $from, 'to' => $to ); } asort($result); } return $result; } } class PrisnaWPTranslateAdminBaseForm extends PrisnaWPTranslateItem { public $title_message; public $preview_message; public $activated_message; public $saved_message; public $layout_changed_message; public $reseted_message; public $reset_message; public $save_button_message; public $reset_button_message; protected $_fields; public function __construct() { $this->title_message = PrisnaWPTranslateMessage::get('plugin_title', PrisnaWPTranslateConfig::getName()); $this->saved_message = PrisnaWPTranslateMessage::get('plugin_saved'); $this->layout_changed_message = PrisnaWPTranslateMessage::get('plugin_layout_changed'); $this->reseted_message = PrisnaWPTranslateMessage::get('plugin_reseted'); $this->reset_message = PrisnaWPTranslateCommon::jsonCompatible(PrisnaWPTranslateMessage::get('plugin_reset_confirm')); $this->save_button_message = PrisnaWPTranslateMessage::get('plugin_save_button'); $this->reset_button_message = PrisnaWPTranslateMessage::get('plugin_reset_button'); $this->cached_translations_saved_message = PrisnaWPTranslateMessage::get('translations_saved'); } public static function commit($_name, $_result) { self::_commit($_name, $_result); } protected static function _commit($_name, $_result) { if (!get_option($_name)) add_option($_name, $_result); else update_option($_name, $_result); if (!get_option($_name)) { delete_option($_name); add_option($_name, $_result); } } public function render($_options, $_html_encode=false) { return parent::render($_options, $_html_encode); } protected function _prepare_settings() {} protected function _set_fields() {} } class PrisnaWPTranslateTranslationsForm extends PrisnaWPTranslateAdminBaseForm { public $nonce; public $translations_general_message; public $translations_import_message; public $translations_export_message; public $translations_onsite_message; public $group_4; public $group_8; public $group_9; public $group_16; public $tab_3; public $ajax_url; public $images_url; protected $_groups; public function __construct() { parent::__construct(); $this->translations_general_message = PrisnaWPTranslateMessage::get('translations_general_tab'); $this->translations_import_message = PrisnaWPTranslateMessage::get('translations_import_tab'); $this->translations_export_message = PrisnaWPTranslateMessage::get('translations_export_tab'); $this->translations_onsite_message = PrisnaWPTranslateMessage::get('translations_onsite_tab'); $this->title_message = PrisnaWPTranslateMessage::get('plugin_title_translations'); $this->nonce = wp_nonce_field(PrisnaWPTranslateConfig::getTranslationsHandle(), '_prisna_wpnonce'); $this->_groups = array(4, 8, 9, 16); $this->ajax_url = PrisnaWPTranslateCommon::getAjaxUrl(); $this->images_url = PRISNA_WP_TRANSLATE_IMAGES . '/admin/'; $this->_set_fields(); } protected function _set_fields() { if (is_array($this->_fields)) return; $this->_fields = array(); $settings = PrisnaWPTranslateConfig::getSettings(true); foreach ($settings as $key => $setting) { if (!array_key_exists('type', $setting)) continue; if (!in_array($setting['group'], $this->_groups)) continue; $field_class = 'PrisnaWPTranslate' . ucfirst($setting['type']) . 'Field'; if ($field_class == 'PrisnaWPTranslateField') continue; $this->_fields[$key] = new $field_class($setting); } } public function render($_options, $_html_encode=false) { $this->_prepare_settings(); $is_importing_translations = PrisnaWPTranslateAdminEvents::isImportingTranslations(); if (!array_key_exists('meta_tag_rules', $_options)) $_options['meta_tag_rules'] = array(); $_options['meta_tag_rules'][] = array( 'expression' => $is_importing_translations, 'tag' => 'just_imported_translations_success' ); return parent::render($_options, $_html_encode); } protected function _prepare_settings() { $settings = PrisnaWPTranslateConfig::getSettings(); $groups = count($this->_groups); for ($i=0; $i<$groups; $i++) { $partial = array(); $j = $this->_groups[$i]; foreach ($this->_fields as $key => $field) { if ($field->group == $j) { $field->satisfyDependence($this->_fields); $partial[] = $field->output(); } } $group = 'group_' . $j; $this->{$group} = implode("\n", $partial); } $tab_3 = PrisnaWPTranslateCommon::getVariable('prisna_tab_3', 'POST'); $this->tab_3 = $tab_3 !== false ? $tab_3 : ''; } } class PrisnaWPTranslateAdminForm extends PrisnaWPTranslateAdminBaseForm { public $group_0; public $group_1; public $group_2; public $group_3; public $group_4; public $group_5; public $group_6; public $group_7; public $group_8; public $group_9; public $group_10; public $group_11; public $group_12; public $group_13; public $group_14; public $group_15; public $group_16; public $nonce; public $tab; public $tab_2; public $tab_3; public $tab_4; public $version_message; public $layout_message; public $general_message; public $general_cache_folder_validate_message; public $general_cache_file_validate_message; public $general_hash_validate_message; public $general_dom_validate_message; public $general_ssl_validate_message; public $general_seo_validate_message; public $general_wp_super_cache_validate_message; public $general_api_key_google_empty_validate_message; public $general_client_id_microsoft_empty_validate_message; public $general_client_secret_microsoft_empty_validate_message; public $advanced_message; public $advanced_general_message; public $advanced_access_message; public $advanced_import_export_message; public $advanced_miscellaneous_message; public $advanced_import_success_message; public $advanced_import_fail_message; public $advanced_import_all_success_message; public $advanced_import_all_fail_message; public $translations_message; public $translations_general_message; public $translations_import_message; public $translations_export_message; public $translations_translators_access_message; public $translations_onsite_message; public $seo_general_message; public $seo_permalink_message; public $seo_sitemap_message; public $seo_log_message; public $layout; public $seo_message; public $styles_message; public $responsive_message; public $ajax_url; public $images_url; protected static $_imported_all_status; protected static $_imported_status; protected static $_temp_message; protected static $_change_controls_image_message = null; protected static $_change_loading_image_message = null; public function __construct() { parent::__construct(); $this->version_message = PrisnaWPTranslateConfig::getVersion(); $this->layout_message = PrisnaWPTranslateMessage::get('layout_tab'); $this->general_message = PrisnaWPTranslateMessage::get('general_tab'); $this->general_cache_folder_validate_message = PrisnaWPTranslateMessage::get('plugin_cache_folder_validate', PRISNA_WP_TRANSLATE_CACHE); $this->general_openssl_validate_message = PrisnaWPTranslateMessage::get('plugin_openssl_validate'); $this->general_fsockopen_validate_message = PrisnaWPTranslateMessage::get('plugin_fsockopen_validate'); $this->general_hash_validate_message = PrisnaWPTranslateMessage::get('plugin_hash_validate'); $this->general_dom_validate_message = PrisnaWPTranslateMessage::get('plugin_dom_validate'); $this->general_ssl_validate_message = PrisnaWPTranslateMessage::get('plugin_ssl_validate'); $this->general_widget_validate_message = PrisnaWPTranslateMessage::get('plugin_widget_validate', PrisnaWPTranslateCommon::getAdminWidgetsUrl()); $this->general_seo_validate_message = PrisnaWPTranslateMessage::get('plugin_seo_validate'); $this->general_wp_super_cache_validate_message = PrisnaWPTranslateMessage::get('plugin_wp_super_cache_validate'); $this->general_controls_image_validate_message = ''; $this->general_loading_image_validate_message = ''; $this->general_api_key_google_empty_validate_message = PrisnaWPTranslateMessage::get('plugin_api_key_google_empty_validate'); $this->general_client_id_microsoft_empty_validate_message = PrisnaWPTranslateMessage::get('plugin_client_id_microsoft_empty_validate'); $this->general_client_secret_microsoft_empty_validate_message = PrisnaWPTranslateMessage::get('plugin_client_secret_microsoft_empty_validate'); $this->advanced_message = PrisnaWPTranslateMessage::get('advanced_tab'); $this->advanced_general_message = PrisnaWPTranslateMessage::get('advanced_general_tab'); $this->advanced_access_message = PrisnaWPTranslateMessage::get('advanced_access_tab'); $this->advanced_miscellaneous_message = PrisnaWPTranslateMessage::get('advanced_miscellaneous_tab'); $this->advanced_import_export_message = PrisnaWPTranslateMessage::get('advanced_import_export_tab'); $this->advanced_import_success_message = PrisnaWPTranslateMessage::get('plugin_imported_success'); $this->advanced_import_fail_message = PrisnaWPTranslateMessage::get('plugin_imported_fail'); $this->advanced_import_all_success_message = PrisnaWPTranslateMessage::get('plugin_imported_all_success'); $this->advanced_import_all_fail_message = empty(self::$_temp_message) ? '' : self::$_temp_message; $this->translations_message = PrisnaWPTranslateMessage::get('translations_tab'); $this->translations_general_message = PrisnaWPTranslateMessage::get('translations_general_tab'); $this->translations_import_message = PrisnaWPTranslateMessage::get('translations_import_tab'); $this->translations_export_message = PrisnaWPTranslateMessage::get('translations_export_tab'); $this->translations_translators_access_message = PrisnaWPTranslateMessage::get('translations_translators_access_tab'); $this->translations_onsite_message = PrisnaWPTranslateMessage::get('translations_onsite_tab'); $this->seo_general_message = PrisnaWPTranslateMessage::get('seo_general_tab'); $this->seo_permalink_message = PrisnaWPTranslateMessage::get('seo_permalink_tab'); $this->seo_sitemap_message = PrisnaWPTranslateMessage::get('seo_sitemap_tab'); $this->seo_log_message = PrisnaWPTranslateMessage::get('seo_log_tab'); $this->seo_message = PrisnaWPTranslateMessage::get('seo_tab'); $this->styles_message = PrisnaWPTranslateMessage::get('styles_tab'); $this->responsive_message = PrisnaWPTranslateMessage::get('responsive_tab'); $this->ajax_url = PrisnaWPTranslateCommon::getAjaxUrl(); $this->images_url = PRISNA_WP_TRANSLATE_IMAGES . '/admin/'; $this->nonce = wp_nonce_field(PrisnaWPTranslateConfig::getAdminHandle(), '_prisna_wpnonce'); $this->_set_fields(); } public static function getImportedAllStatus() { return self::$_imported_all_status; } public static function getImportedStatus() { return self::$_imported_status; } protected static function _set_imported_all_status($_status) { self::$_imported_all_status = $_status; } protected static function _set_imported_status($_status) { self::$_imported_status = $_status; } protected static function _import_translations() { if (!PrisnaWPTranslateAdminEvents::isImportingTranslations()) return null; return true; } protected static function _import_all() { if (!PrisnaWPTranslateAdminEvents::isImportingAll()) return null; $result = PrisnaWPTranslateImportallField::run(); if ($result['status']) { $import_settings = self::_import_settings($result['settings']); $import_translations = PrisnaWPTranslateImportallField::importTranslations($result['translations']); $import_permalinks = PrisnaWPTranslateImportallField::importPermalinks($result['permalinks']); } self::$_temp_message = $result['status'] ? '' : $result['message']; self::_set_imported_all_status($result['status']); return true; } protected static function _import_settings($_string) { if (empty($_string) || !is_string($_string)) return false; $decode = PrisnaWPTranslateCommon::bsd($_string); if ($decode === false) return false; $unserialize = @unserialize($decode); if (!is_array($unserialize)) return false; $settings = PrisnaWPTranslateConfig::getDefaults(true); $result = array(); foreach ($settings as $key => $setting) { if (in_array($key, array('import', 'export', 'import_all', 'export_all'))) continue; if (array_key_exists($key, $unserialize)) $result[$key] = $unserialize[$key]; } if (count($result) == 0) return false; self::_commit(PrisnaWPTranslateConfig::getDbSettingsName(), $result); self::setImagesColors(); return true; } protected static function _import() { $import = PrisnaWPTranslateConfig::getSetting('import'); $key = $import['id']; $value = PrisnaWPTranslateCommon::getVariable($key, 'POST'); if (empty($value)) return null; $result = self::_import_settings($value); self::_set_imported_status($result); return true; } protected static function _change_loading_image_color($_color) { $rgb = PrisnaWPTranslateCommon::hex2rgb($_color); $is_white = $rgb[0] == 255 && $rgb[1] == 255 && $rgb[2] == 255; if (!self::_gd_validate()) { self::$_change_loading_image_message = PrisnaWPTranslateMessage::get('plugin_wp_gd_validate'); return false; } $sizes = array('s', 'm', 'l', 'xl'); foreach ($sizes as $size) { $frames = array(); $delays = array(); $destination = PRISNA_WP_TRANSLATE_IMG . '/' . 'loading-' . $size . '.gif'; if (!is_writable($destination)) { self::$_change_loading_image_message = PrisnaWPTranslateMessage::get('plugin_image_file_validate', PrisnaWPTranslateCommon::stringDiff(get_home_path(), $destination)); return false; } for ($i=1; $i<9; $i++) { $file = 'loading-' . $size . '-' . $i . '.gif'; $image = PRISNA_WP_TRANSLATE_IMG . '/originals/' . $file; $gif = PrisnaWPTranslateCommon::colorizeGIF($image, $rgb[0], $rgb[1], $rgb[2], ($_color != 'transparent' ? 1 : 0)); $frames[] = $gif; $delays[] = 10; } $animated = new PrisnaWPTranslateAnimatedGif($frames, $delays, 0); $animated->save($destination); } return true; } protected static function _gd_validate() { return extension_loaded('gd') && function_exists('gd_info') && function_exists('imagecreatefromgif'); } protected static function _change_controls_image_color($_color) { $rgb = PrisnaWPTranslateCommon::hex2rgb($_color); $is_white = $rgb[0] == 255 && $rgb[1] == 255 && $rgb[2] == 255; if (!self::_gd_validate()) { self::$_change_controls_image_message = PrisnaWPTranslateMessage::get('plugin_wp_gd_validate'); return false; } $sizes = array('s', 'm', 'l', 'xl'); foreach ($sizes as $size) { $file = 'controls-' . $size . '.png'; $destination = PRISNA_WP_TRANSLATE_IMG . '/' . $file; if (!is_writable($destination)) { self::$_change_controls_image_message = PrisnaWPTranslateMessage::get('plugin_image_file_validate', PrisnaWPTranslateCommon::stringDiff(get_home_path(), $destination)); return false; } $image = PRISNA_WP_TRANSLATE_IMG . '/originals/' . $file; PrisnaWPTranslateCommon::colorizeBasedOnAplhaChannnel($image, $rgb[0], $rgb[1], $rgb[2], ($_color != 'transparent' ? 1 : 0), $destination); } return true; } public static function save() { if (!is_null(self::_import_all())) return; if (!is_null(self::_import())) return; if (!is_null(self::_import_translations())) return; if (PrisnaWPTranslateAdminEvents::isChangingLayout()) { $result = PrisnaWPTranslateConfig::getSettingsValues(false, false); $layout = PrisnaWPTranslateConfig::getSetting('layout'); $new_layout = PrisnaWPTranslateCommon::getVariable($layout['id'], 'POST'); if ($new_layout !== false) $result['layout']['value'] = $new_layout; $size = PrisnaWPTranslateConfig::getSetting('size'); $new_size = PrisnaWPTranslateCommon::getVariable($size['id'], 'POST'); if ($new_size !== false) $result['size']['value'] = $new_size; self::_commit(PrisnaWPTranslateConfig::getDbSettingsName(), $result); return; } if (PrisnaWPTranslateAdminEvents::isChangingLoadingImageColor()) { $loading_image = PrisnaWPTranslateConfig::getSetting('loading_image_color'); $loading_image_value = PrisnaWPTranslateCommon::getVariable($loading_image['id'], 'POST'); $change_loading_image_color = self::_change_loading_image_color($loading_image_value); } if (PrisnaWPTranslateAdminEvents::isChangingControlsImageColor()) { $controls_image = PrisnaWPTranslateConfig::getSetting('controls_image_color'); $controls_image_value = PrisnaWPTranslateCommon::getVariable($controls_image['id'], 'POST'); $change_controls_image_color = self::_change_controls_image_color($controls_image_value); } $settings = PrisnaWPTranslateConfig::getDefaults(); $result = array(); foreach ($settings as $key => $setting) { $value = PrisnaWPTranslateCommon::getVariable($setting['id'], 'POST'); if (!preg_match('/^prisna_exclude_/', $setting['id'])) if ($value === false) $value = PrisnaWPTranslateConfig::getSettingValue($key); switch ($key) { case 'languages': { $value = PrisnaWPTranslateCommon::getVariable(str_replace('languages', 'languages_order', $setting['id']), 'POST'); if ($value !== false) { $value = explode(',', $value); if ($value !== $setting['value']) $result[$key] = array('value' => $value); else unset($result[$key]); } else unset($result[$key]); break; } case 'xy_vertical': case 'xy_horizontal': { $position = PrisnaWPTranslateCommon::getVariable($setting['id'], 'POST'); $position = !empty($position) ? (int) $position : $position; $value = array( 'kind' => PrisnaWPTranslateCommon::getVariable($setting['id'] . '_kind', 'POST'), 'position' => $position, 'unit' => PrisnaWPTranslateCommon::getVariable($setting['id'] . '_unit', 'POST') ); if ($value != $setting['value']) $result[$key] = array('value' => $value); else unset($result[$key]); break; } case 'sitemap_rule': { $priority = PrisnaWPTranslateCommon::getVariable(str_replace('rule', 'rule_priority', $setting['id']), 'POST'); $frecuency = PrisnaWPTranslateCommon::getVariable(str_replace('rule', 'rule_changefreq', $setting['id']), 'POST'); $value = array( 'priority' => $priority, 'changefreq' => $frecuency ); if ($value !== $setting['value']) $result[$key] = array('value' => $value); else unset($result[$key]); break; } case 'translations_import': case 'translations_export': case 'import': case 'export': { continue; break; } case 'loading_image_color': { if (isset($change_loading_image_color) && $change_loading_image_color === false) $value = PrisnaWPTranslateConfig::getSettingValue($key); if ($value !== false && $value != $setting['value']) $result[$key] = array('value' => $value); else unset($result[$key]); break; } case 'controls_image_color': { if (isset($change_controls_image_color) && $change_controls_image_color === false) $value = PrisnaWPTranslateConfig::getSettingValue($key); if ($value !== false && $value != $setting['value']) $result[$key] = array('value' => $value); else unset($result[$key]); break; } case 'responsive': { $value = str_replace('"', '', $value); if ($value !== false && $value != $setting['value']) $result[$key] = array('value' => $value); else unset($result[$key]); break; } default: { if ($key == 'id' || (PrisnaWPTranslateCommon::endsWith($key, '_class') && $key != 'language_selector_class' && $key != 'translated_to_class')) $value = trim(PrisnaWPTranslateCommon::cleanId($value)); else if ($key == 'translated_to_class') $value = trim(PrisnaWPTranslateCommon::cleanId($value, '-', false)); $unset_template = (PrisnaWPTranslateCommon::endsWith($key, '_template') || PrisnaWPTranslateCommon::endsWith($key, '_template_dd')) && PrisnaWPTranslateCommon::stripBreakLinesAndTabs($value) == PrisnaWPTranslateCommon::stripBreakLinesAndTabs($setting['value']); if (!$unset_template && $value !== false && $value != $setting['value']) $result[$key] = array('value' => $value); else unset($result[$key]); break; } } } self::_commit(PrisnaWPTranslateConfig::getDbSettingsName(), $result); } public static function setImagesColors() { self::_change_loading_image_color(PrisnaWPTranslateConfig::getSettingValue('loading_image_color', true)); self::_change_controls_image_color(PrisnaWPTranslateConfig::getSettingValue('controls_image_color', true)); } public static function reset() { if (get_option(PrisnaWPTranslateConfig::getDbSettingsName())) delete_option(PrisnaWPTranslateConfig::getDbSettingsName()); self::setImagesColors(); } protected function _widget_validate() { return true; } protected function _google_validate() { return $this->_fields['translation_service']->value != 'gt' || PrisnaWPTranslateCommon::isOpenSSLInstalled(); } protected function _fsockopen_validate() { return function_exists('fsockopen'); } protected function _hash_validate() { return function_exists('hash'); } protected function _dom_validate() { return class_exists('DOMDocument'); } protected function _ssl_validate() { return PrisnaWPTranslateCommon::isMcryptInstalled(); } protected function _seo_validate() { return !PrisnaWPTranslateConfig::getSettingValue('seo') || function_exists('mb_convert_encoding'); } protected function _cache_file_validate() { if (!$this->_cache_folder_validate()) return true; $files_validate = PrisnaWPTranslateCommon::areFolderFilesWritable(PRISNA_WP_TRANSLATE_CACHE); if ($files_validate !== true) { $this->general_cache_file_validate_message = PrisnaWPTranslateMessage::get('plugin_cache_file_validate', $files_validate); return false; } return true; } protected function _cache_folder_validate() { return PrisnaWPTranslateCommon::isFolderWritable(PRISNA_WP_TRANSLATE_CACHE); } protected function _wp_super_cache_validate() { if (!PrisnaWPTranslateConfig::getSettingValue('seo')) return true; if (!function_exists('wp_super_cache_text_domain') && !function_exists('wpcache_broken_message')) return true; global $wp_cache_no_cache_for_get; return !empty($wp_cache_no_cache_for_get); } protected function _client_secret_microsoft_empty_validate() { if ($this->_fields['translation_service']->value != 'ma') return true; return !empty($this->_fields['microsoft_client_secret']->value); } protected function _client_id_microsoft_empty_validate() { if ($this->_fields['translation_service']->value != 'ma') return true; return !empty($this->_fields['microsoft_client_id']->value); } protected function _api_key_google_empty_validate() { if ($this->_fields['translation_service']->value != 'gt') return true; return !empty($this->_fields['google_api_key']->value); } public function render($_options, $_html_encode=false) { $cache_folder_validate = $this->_cache_folder_validate(); $cache_file_validate = $this->_cache_file_validate(); PrisnaWPTranslateConfig::setCacheFlag($cache_folder_validate && $cache_file_validate); $this->_prepare_settings(); $is_exporting_all = PrisnaWPTranslateAdminEvents::isExportingAll(); $is_importing_all = !$is_exporting_all && PrisnaWPTranslateAdminEvents::isImportingAll(); $is_importing = !$is_importing_all && !$is_exporting_all && PrisnaWPTranslateAdminEvents::isSavingSettings() && PrisnaWPTranslateValidator::isBool(self::getImportedStatus()); $is_importing_translations = !$is_importing_all && !$is_exporting_all && PrisnaWPTranslateAdminEvents::isImportingTranslations(); $is_changing_layout = !$is_importing_all && !$is_exporting_all && !$is_importing && !$is_importing_translations && PrisnaWPTranslateAdminEvents::isSavingSettings() && PrisnaWPTranslateAdminEvents::isChangingLayout(); $this->general_controls_image_validate_message = self::$_change_controls_image_message; $this->general_loading_image_validate_message = self::$_change_loading_image_message; if (!array_key_exists('meta_tag_rules', $_options)) $_options['meta_tag_rules'] = array(); $_options['meta_tag_rules'][] = array( 'expression' => empty(self::$_change_loading_image_message), 'tag' => 'change_loading_image_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => empty(self::$_change_controls_image_message), 'tag' => 'change_controls_image_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_wp_super_cache_validate(), 'tag' => 'wp_super_cache_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_api_key_google_empty_validate(), 'tag' => 'api_key_google_empty_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_client_id_microsoft_empty_validate(), 'tag' => 'client_id_microsoft_empty_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_client_secret_microsoft_empty_validate(), 'tag' => 'client_secret_microsoft_empty_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $cache_folder_validate, 'tag' => 'cache_folder_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $cache_file_validate, 'tag' => 'cache_file_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_google_validate(), 'tag' => 'openssl_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_widget_validate(), 'tag' => 'widget_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_fsockopen_validate(), 'tag' => 'fsockopen_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_hash_validate(), 'tag' => 'hash_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_dom_validate(), 'tag' => 'dom_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_ssl_validate(), 'tag' => 'ssl_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => PrisnaWPTranslateConfig::getSettingValue('seo'), 'tag' => 'seo_enabled' ); $_options['meta_tag_rules'][] = array( 'expression' => $this->_seo_validate(), 'tag' => 'seo_validate' ); $_options['meta_tag_rules'][] = array( 'expression' => PrisnaWPTranslateAdminEvents::isSavingSettings() && !$is_importing_all && !$is_exporting_all && !$is_importing && !$is_importing_translations && !$is_changing_layout, 'tag' => 'just_saved' ); $_options['meta_tag_rules'][] = array( 'expression' => $is_importing_translations, 'tag' => 'just_imported_translations_success' ); $_options['meta_tag_rules'][] = array( 'expression' => $is_changing_layout, 'tag' => 'layout_changed' ); $_options['meta_tag_rules'][] = array( 'expression' => $is_importing_all && self::getImportedAllStatus(), 'tag' => 'just_imported_all_success' ); $_options['meta_tag_rules'][] = array( 'expression' => $is_importing_all && !self::getImportedAllStatus(), 'tag' => 'just_imported_all_fail' ); $_options['meta_tag_rules'][] = array( 'expression' => $is_importing && self::getImportedStatus(), 'tag' => 'just_imported_success' ); $_options['meta_tag_rules'][] = array( 'expression' => $is_importing && !self::getImportedStatus(), 'tag' => 'just_imported_fail' ); $_options['meta_tag_rules'][] = array( 'expression' => PrisnaWPTranslateAdminEvents::isResetingSettings(), 'tag' => 'just_reseted' ); return parent::render($_options, $_html_encode); } protected function _set_fields() { if (is_array($this->_fields)) return; $this->_fields = array(); $settings = PrisnaWPTranslateConfig::getSettings(true); foreach ($settings as $key => $setting) { if (!array_key_exists('type', $setting)) continue; $field_class = 'PrisnaWPTranslate' . ucfirst($setting['type']) . 'Field'; if ($field_class == 'PrisnaWPTranslateField') continue; $this->_fields[$key] = new $field_class($setting); } } protected function _prepare_settings() { $settings = PrisnaWPTranslateConfig::getSettings(); $groups = 16; for ($i=0; $i<$groups+1; $i++) { $partial = array(); foreach ($this->_fields as $key => $field) { if ($field->group == $i) { $field->satisfyDependence($this->_fields); $partial[] = $field->output(); } } $group = 'group_' . $i; $this->{$group} = implode("\n", $partial); } $tab = PrisnaWPTranslateCommon::getVariable('prisna_tab', 'POST'); $this->tab = $tab !== false ? $tab : ''; $tab_2 = PrisnaWPTranslateCommon::getVariable('prisna_tab_2', 'POST'); $this->tab_2 = $tab_2 !== false ? $tab_2 : ''; $tab_3 = PrisnaWPTranslateCommon::getVariable('prisna_tab_3', 'POST'); $this->tab_3 = $tab_3 !== false ? $tab_3 : ''; $tab_4 = PrisnaWPTranslateCommon::getVariable('prisna_tab_4', 'POST'); $this->tab_4 = $tab_4 !== false ? $tab_4 : ''; $this->layout = PrisnaWPTranslateConfig::getSettingValue('layout'); } } class PrisnaWPTranslateAdminEvents { protected static $_is_changing_layout; protected static $_is_changing_loading; protected static $_is_changing_controls; public static function isChangingLoadingImageColor() { if (!is_null(self::$_is_changing_loading)) return self::$_is_changing_loading; $setting = PrisnaWPTranslateConfig::getSetting('loading_image_color'); $setting_value = PrisnaWPTranslateConfig::getSettingValue('loading_image_color'); $new_value = PrisnaWPTranslateCommon::getVariable($setting['id'], 'POST'); return self::$_is_changing_loading = !empty($new_value) && $setting_value != $new_value; } public static function isChangingControlsImageColor() { if (!is_null(self::$_is_changing_controls)) return self::$_is_changing_controls; $setting = PrisnaWPTranslateConfig::getSetting('controls_image_color'); if (empty($setting)) return false; if (!array_key_exists('id', $setting)) return false; $setting_value = PrisnaWPTranslateConfig::getSettingValue('controls_image_color'); $new_value = PrisnaWPTranslateCommon::getVariable($setting['id'], 'POST'); return self::$_is_changing_controls = !empty($new_value) && $setting_value != $new_value; } public static function isChangingLayout() { if (!is_null(self::$_is_changing_layout)) return self::$_is_changing_layout; $layout = PrisnaWPTranslateConfig::getSettingValue('layout'); $size = PrisnaWPTranslateConfig::getSettingValue('size'); $setting_layout = PrisnaWPTranslateConfig::getSetting('layout'); $setting_size = PrisnaWPTranslateConfig::getSetting('size'); $new_layout = PrisnaWPTranslateCommon::getVariable($setting_layout['id'], 'POST'); $new_size = PrisnaWPTranslateCommon::getVariable($setting_size['id'], 'POST'); return self::$_is_changing_layout = $layout != $new_layout || $size != $new_size; } public static function isLoadingTranslationsPage() { return in_array(PrisnaWPTranslateCommon::getVariable('page', 'GET'), array(PrisnaWPTranslateConfig::getTranslationsHandle())); } public static function isLoadingAdminPage() { return in_array(PrisnaWPTranslateCommon::getVariable('page', 'GET'), array(PrisnaWPTranslateConfig::getAdminHandle())); } public static function isSavingSettings() { return PrisnaWPTranslateCommon::getVariable('prisna_wp_translate_admin_action', 'POST') === 'prisna_wp_translate_save_settings'; } public static function isResetingSettings() { return PrisnaWPTranslateCommon::getVariable('prisna_wp_translate_admin_action', 'POST') === 'prisna_wp_translate_reset_settings'; } public static function isRemovingResource() { return PrisnaWPTranslateCommon::getVariable('prisna_wp_translate_admin_action', 'POST') === 'prisna_wp_translate_remove_resource'; } public static function isExportingAll() { $value = PrisnaWPTranslateCommon::getVariable('prisna_export_all_button', 'POST'); return self::isSavingSettings() && !empty($value); } public static function isExportingTranslations() { $value = PrisnaWPTranslateCommon::getVariable('prisna_translations_export_button', 'POST'); return self::isSavingSettings() && !empty($value); } public static function isImportingAll() { $value = PrisnaWPTranslateCommon::getVariable('prisna_import_all_button', 'POST'); return self::isSavingSettings() && !empty($value); } public static function isImportingTranslations() { $value = PrisnaWPTranslateCommon::getVariable('prisna_translations_import_button', 'POST'); return self::isSavingSettings() && !empty($value); } public static function isGeneratingPoFile() { return self::isLoadingAdminPage() && PrisnaWPTranslateCommon::getVariable('prisna-po', 'GET') !== false; } } PrisnaWPTranslateAdmin::initialize(); ?>