/** * Builds a page with form for upload translation file. * * @param Request $request Incoming request. * @return string Rendered page content. */ public function showFormAction(Request $request) { $operator = $this->getOperator(); $target = $request->request->get('target'); if (!preg_match("/^[\\w-]{2,5}\$/", $target)) { $target = get_current_locale(); } $override = (bool) $request->request->get('override', false); $page = array('errors' => $request->attributes->get('errors', array())); // Load list of all available locales. $locales_list = array(); $all_locales = get_available_locales(); foreach ($all_locales as $loc) { $locales_list[] = array('id' => $loc, 'name' => $this->getLocaleName($loc)); } $page['stored'] = $request->query->has('stored'); $page['localesList'] = $locales_list; $page['formtarget'] = $target; $page['formoverride'] = $override; $page['title'] = getlocal('Translations import'); $page['menuid'] = 'translation'; $page = array_merge($page, prepare_menu($operator)); $page['tabs'] = $this->buildTabs($request); return $this->render('translation_import', $page); }
/** * Generates list of all localization constants in the system. * * @param Request $request Incoming request. * @return string Rendered page content. */ public function indexAction(Request $request) { $operator = $this->getOperator(); $target = $request->query->get('target'); if (!preg_match("/^[\\w-]{2,5}\$/", $target)) { $target = get_current_locale(); } $page = array('localeName' => $this->getLocaleName($target), 'errors' => array()); // Load list of all available locales. $locales_list = array(); $all_locales = get_available_locales(); foreach ($all_locales as $loc) { $locales_list[] = array('id' => $loc, 'name' => $this->getLocaleName($loc)); } // Prepare localization constants to display. $strings = $this->loadStrings($target); foreach ($strings as $key => $item) { $strings[$key] = array('id' => $item['translationid'], 'source' => htmlentities($item['source']), 'translation' => empty($item['translation']) ? "<font color=\"#c13030\"><b>absent</b></font>" : htmlspecialchars($item['translation'])); } // Sort localization constants in the specified order. $order = $request->query->get('sort'); if (!in_array($order, array('source', 'translation'))) { $order = 'source'; } if ($order == 'source') { usort($strings, function ($a, $b) { return strcmp($a['source'], $b['source']); }); } elseif ($order == 'translation') { usort($strings, function ($a, $b) { return strcmp($a['translation'], $b['translation']); }); } $pagination = setup_pagination($strings, 100); $page['pagination'] = $pagination['info']; $page['pagination.items'] = $pagination['items']; $page['formtarget'] = $target; $page['availableLocales'] = $locales_list; $page['availableOrders'] = array(array('id' => 'source', 'name' => getlocal('Source string')), array('id' => 'translation', 'name' => getlocal('Translation'))); $page['formsort'] = $order; $page['title'] = getlocal('Translations'); $page['menuid'] = 'translation'; $page = array_merge($page, prepare_menu($operator)); $page['tabs'] = $this->buildTabs($request); return $this->render('translations', $page); }
/** * Generates "about" page. * * @param Request $request * @return string Rendered page content */ public function indexAction(Request $request) { $page = array_merge( array( 'localizations' => get_available_locales(), 'phpVersion' => phpversion(), 'extensions' => $this->getExtensionsInfo(), 'version' => MIBEW_VERSION, 'title' => getlocal('About'), 'menuid' => 'about', ), prepare_menu($this->getOperator()) ); $this->getAssetManager()->attachJs('js/compiled/about.js'); $this->getAssetManager()->attachJs( 'https://mibew.org/api/updates', AssetManagerInterface::ABSOLUTE_URL ); return $this->render('about', $page); }
function get_locale_links() { // Get list of available locales $locale_links = array(); $all_locales = get_available_locales(); if (count($all_locales) < 2) { return null; } // Attache locale names foreach ($all_locales as $k) { $locale_info = get_locale_info($k); $locale_links[$k] = $locale_info ? $locale_info['name'] : $k; } return $locale_links; }
/** * Processes submitting of the form which is generated in * {@link \Mibew\Controller\Settings\CommonController::showFormAction()} * method. * * @param Request $request Incoming request. * @return string Rendered page content. * @throws BadRequestException If one or more parameters of the request have * wrong format. */ public function submitFormAction(Request $request) { csrf_check_token($request); $errors = array(); $params = array(); $params['email'] = $request->request->get('email'); $params['title'] = $request->request->get('title'); $params['logo'] = $request->request->get('logo'); $params['hosturl'] = $request->request->get('hosturl'); $params['usernamepattern'] = $request->request->get('usernamepattern'); $params['chattitle'] = $request->request->get('chattitle'); $params['geolink'] = $request->request->get('geolink'); $params['geolinkparams'] = $request->request->get('geolinkparams'); $params['cron_key'] = $request->request->get('cronkey'); $send_key = $request->request->get('sendmessagekey'); if (!preg_match("/^c?enter\$/", $send_key)) { throw new BadRequestException('Wrong format of "sendmessagekey" field.'); } $params['sendmessagekey'] = $send_key; $params['left_messages_locale'] = $request->request->get('leftmessageslocale'); if (!in_array($params['left_messages_locale'], get_available_locales())) { $params['left_messages_locale'] = get_home_locale(); } if ($params['email'] && !MailUtils::isValidAddress($params['email'])) { $errors[] = getlocal('Enter a valid email address'); } if ($params['geolinkparams']) { foreach (explode(',', $params['geolinkparams']) as $one_param) { $wrong_param = !preg_match("/^\\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\\d{1,4}\$/", $one_param); if ($wrong_param) { $errors[] = "Wrong link parameter: \"{$one_param}\", " . "should be one of 'toolbar, scrollbars, location, " . "status, menubar, width, height or resizable'"; } } } if (preg_match("/^[0-9A-Za-z]*\$/", $params['cron_key']) == 0) { $errors[] = getlocal('Use only Latin letters(upper and lower case) and numbers in cron key.'); } // Load styles configs $chat_style = $request->request->get('chat_style', ChatStyle::getDefaultStyle()); $chat_style_list = ChatStyle::getAvailableStyles(); if (!in_array($chat_style, $chat_style_list)) { $chat_style = $chat_style_list[0]; } $page_style = $request->request->get('page_style', PageStyle::getDefaultStyle()); $page_style_list = PageStyle::getAvailableStyles(); if (!in_array($page_style, $page_style_list)) { $page_style = $page_style_list[0]; } if (Settings::get('enabletracking')) { $invitation_style = $request->request->get('invitation_style', InvitationStyle::getDefaultStyle()); $invitation_style_list = InvitationStyle::getAvailableStyles(); if (!in_array($invitation_style, $invitation_style_list)) { $invitation_style = $invitation_style_list[0]; } } if (count($errors) != 0) { $request->attributes->set('errors', $errors); // The form should be rebuild. Invoke appropriate action. return $this->showFormAction($request); } // Update system settings foreach ($params as $key => $value) { Settings::set($key, $value); } // Update styles params ChatStyle::setDefaultStyle($chat_style); PageStyle::setDefaultStyle($page_style); if (Settings::get('enabletracking')) { InvitationStyle::setDefaultStyle($invitation_style); } // Redirect the user to the same page using GET method $redirect_to = $this->generateUrl('settings_common', array('stored' => true)); return $this->redirect($redirect_to); }
/** * Extracts locale code from the request. * * @param Request $request * @return string|boolean Locale code or boolean false if the code cannot be * extracted. */ protected function extractLocale(Request $request) { $lang = $request->isMethod('POST') ? $request->request->get('lang') : $request->query->get('lang'); $all_locales = get_available_locales(); $correct_locale = !empty($lang) && preg_match("/^[\w-]{2,5}$/", $lang) && in_array($lang, $all_locales); if (!$correct_locale) { return false; } return $lang; }
function get_locale_links($href) { global $current_locale; $localeLinks = array(); $allLocales = get_available_locales(); if (count($allLocales) < 2) { return null; } foreach ($allLocales as $k) { $localeLinks[$k] = getlocal_($k, "names"); } return $localeLinks; }
$updatequery = "insert into {$mysqlprefix}chatresponses (vcvalue,locale,groupid) values "; for ($i = 0; $i < count($result); $i++) { if ($i > 0) { $updatequery .= ", "; } $updatequery .= "('" . mysql_real_escape_string($result[$i]['vcvalue'], $link) . "','{$locale}', NULL)"; } perform_query($updatequery, $link); $result = select_multi_assoc($query, $link); } } mysql_close($link); return $result; } # locales $all_locales = get_available_locales(); $locales_with_label = array(); foreach ($all_locales as $id) { $locales_with_label[] = array('id' => $id, 'name' => getlocal_($id, "names")); } $page['locales'] = $locales_with_label; $lang = verifyparam("lang", "/^[\\w-]{2,5}\$/", ""); if (!$lang || !in_array($lang, $all_locales)) { $lang = in_array($current_locale, $all_locales) ? $current_locale : $all_locales[0]; } # groups $groupid = ""; if ($settings['enablegroups'] == '1') { $groupid = verifyparam("group", "/^\\d{0,8}\$/", ""); if ($groupid) { $group = group_by_id($groupid);
/** * Builds locale edit page. * * @param Request $request Incoming request. * @return string Rendered page content. * @throws NotFoundException If the locale with specified code is not found * in the system. */ public function showEditFormAction(Request $request) { $page = array('errors' => $request->attributes->get('errors', array())); $locale = $request->attributes->get('locale'); // Check if locale exists and enabled. if (!in_array($locale, get_available_locales())) { throw new NotFoundException(); } $info = get_locale_info($locale); $page['formtimelocale'] = $info['time_locale']; $page['formdateformatfull'] = $info['date_format']['full']; $page['formdateformatdate'] = $info['date_format']['date']; $page['formdateformattime'] = $info['date_format']['time']; // Override fields from the request if it's needed. This case will take // place when a save handler fails and passes the request to this // action. if ($request->isMethod('POST')) { $page['formtimelocale'] = $request->request->get('timelocale'); $page['formdateformatfull'] = $request->request->get('dateformatfull'); $page['formdateformatdate'] = $request->request->get('dateformatdate'); $page['formdateformattime'] = $request->request->get('dateformattime'); } $page['stored'] = $request->query->has('stored'); $page['title'] = getlocal('Locale details'); $page['menuid'] = 'translation'; $page['formaction'] = $request->getBaseUrl() . $request->getPathInfo(); $page = array_merge($page, prepare_menu($this->getOperator())); $page['tabs'] = $this->buildTabs($request); return $this->render('locale_edit', $page); }
* * Alternatively, the contents of this file may be used under the terms of * the GNU General Public License Version 2 or later (the "GPL"), in which case * the provisions of the GPL are applicable instead of those above. If you wish * to allow use of your version of this file only under the terms of the GPL, and * not to allow others to use your version of this file under the terms of the * EPL, indicate your decision by deleting the provisions above and replace them * with the notice and other provisions required by the GPL. * * Contributors: * Evgeny Gryaznov - initial API and implementation */ require_once '../libs/common.php'; require_once '../libs/operator.php'; require_once '../libs/settings.php'; $operator = check_login(); $default_extensions = array('mysql', 'gd', 'iconv'); $errors = array(); $page = array('localizations' => get_available_locales(), 'phpVersion' => phpversion(), 'version' => $version); foreach ($default_extensions as $ext) { if (!extension_loaded($ext)) { $page['phpVersion'] .= " {$ext}/absent"; } else { $ver = phpversion($ext); $page['phpVersion'] .= $ver ? " {$ext}/{$ver}" : " {$ext}"; } } prepare_menu($operator); setup_settings_tabs(3); start_html_output(); require '../view/updates.php';
function get_image_locales_map($localesdir) { $imageLocales = array(); $allLocales = get_available_locales(); foreach ($allLocales as $curr) { $imagesDir = "{$localesdir}/{$curr}/button"; if ($handle = @opendir($imagesDir)) { while (false !== ($file = readdir($handle))) { if (preg_match("/^(\\w+)_on.gif\$/", $file, $matches) && is_file("{$imagesDir}/" . $matches[1] . "_off.gif")) { $image = $matches[1]; if (!isset($imageLocales[$image])) { $imageLocales[$image] = array(); } $imageLocales[$image][] = $curr; } } closedir($handle); } } return $imageLocales; }
/** * Maps locales onto existing images. * * @param string $locales_dir Base directory of locales. * * @return array The keys of the resulting array are images names and the * values are arrays of locales which contains the image. */ protected function getImageLocalesMap($locales_dir) { $image_locales = array(); $all_locales = get_available_locales(); foreach ($all_locales as $curr) { $images_dir = "{$locales_dir}/{$curr}/button"; if ($handle = @opendir($images_dir)) { while (false !== ($file = readdir($handle))) { $both_files_exist = preg_match("/^(\\w+)_on\\.(gif|png)\$/", $file, $matches) && is_file("{$images_dir}/" . $matches[1] . "_off." . $matches[2]); if ($both_files_exist) { $image = $matches[1]; if (!isset($image_locales[$image])) { $image_locales[$image] = array(); } $image_locales[$image][] = $curr; } } closedir($handle); } } return $image_locales; }
/** * Generates "about" page. * * @param Request $request * @return string Rendered page content */ public function indexAction(Request $request) { $page = array_merge(array('localizations' => get_available_locales(), 'phpVersion' => phpversion(), 'extensions' => $this->getExtensionsInfo(), 'version' => MIBEW_VERSION, 'title' => getlocal('About'), 'menuid' => 'about', 'availableUpdates' => $this->getAvailableUpdates()), prepare_menu($this->getOperator())); return $this->render('about', $page); }
/** * Disables a locale. * * @param Request $request Incoming request. * @return \Symfony\Component\HttpFoundation\Response A response object. * @throws NotFoundException If the locale which should be disabled is not * found. */ public function disableAction(Request $request) { csrf_check_token($request); $locale = $request->attributes->get('locale'); $errors = array(); // Check if locale exists. if (!in_array($locale, discover_locales())) { throw new NotFoundException(); } // Disable locale if we can do so. $available_locales = get_available_locales(); if (in_array($locale, $available_locales)) { if (count($available_locales) > 1) { disable_locale($locale); } else { $errors[] = getlocal('Cannot disable all locales.'); } } if (count($errors) != 0) { // Something went wrong. Re-render locales list. $request->attributes->set('errors', $errors); return $this->indexAction($request); } return $this->redirect($this->generateUrl('locales')); }