/**
  * Generates a JavaScript file with client-side localization constants.
  *
  * @param Request $request Incoming request.
  * @return Response Prepared JavaScript file with client side localization
  * constants.
  */
 public function indexAction(Request $request)
 {
     $locale = $request->attributes->get('locale');
     $item = $this->getCache()->getItem('translation/js/' . $locale);
     $content = $item->get(Invalidation::OLD);
     if ($item->isMiss()) {
         $item->lock();
         $messages = load_messages($locale);
         // Store JSON-encoded data to reduce count of json_encode calls.
         $content = sprintf('%s(%s);', 'Mibew.Localization.set', json_encode($messages));
         $item->set($content);
     }
     // Session is started automatically during application initialization
     // and PHP sets "Cache-Control" and "Expires" headers to forbid caching
     // and to keep the session private. In this script we actually does not
     // use session stuff, thus we can remove these headers to provide
     // caching. Notice that all headers are removed to clear "Set-Cookie"
     // header with session ID and may be some other unsafe headers that
     // must not be cached.
     header_remove();
     // The whole response body (JSON-encoded with a callback function) is
     // cached via cache backend, thus it's simpler to use Symfony's
     // Response class instead of JsonResponse.
     $response = new Response();
     $response->headers->set('Content-Type', 'text/javascript');
     // Set various cache headers
     $response->setPublic();
     $response->setMaxAge(120);
     if ($item->getCreation()) {
         // Creation field can be unavailable for some cache drivers.
         $response->setLastModified($item->getCreation());
     }
     $response->setETag(sha1($content));
     if ($response->isNotModified($request)) {
         $response->setNotModified();
         // We does not need to send content for the client. Just return 304
         // status code.
         return $response;
     }
     // Pass the whole response for the client.
     $response->setContent($content);
     return $response;
 }
 /**
  * Processes submitting of the form which is generated in
  * {@link \Mibew\Controller\TranslationExportController::showFormAction()}
  * method.
  *
  * @param Request $request Incoming request.
  * @return string Rendered page content.
  */
 public function submitFormAction(Request $request)
 {
     csrf_check_token($request);
     $target = $request->request->get('target');
     if (!preg_match("/^[\\w-]{2,5}\$/", $target)) {
         $target = get_current_locale();
     }
     $messages = load_messages($target);
     ksort($messages);
     $catalogue = new MessageCatalogue($target, array('messages' => $messages));
     $dumper = new PoFileDumper();
     $output = $dumper->format($catalogue);
     $response = new Response();
     $response->headers->set('Content-type', 'application/octet-stream');
     $response->headers->set('Content-Disposition', sprintf('attachment; filename=translation-%s.po', $target));
     $response->headers->set('Content-Length', strlen($output));
     $response->headers->set('Content-Transfer-Encoding', 'binary');
     $response->setContent($output);
     return $response;
 }
예제 #3
0
/**
 * Return localized string by its key and locale.
 *
 * Do not use this function manually because it is for internal use only and may
 * be removed soon. Use {@link getlocal()} function instead.
 *
 * @access private
 * @param string $string Localization string key.
 * @param string $locale Target locale code.
 * @return string Localized string.
 */
function get_localized_string($string, $locale)
{
    $localized = load_messages($locale);
    if (isset($localized[$string])) {
        return $localized[$string];
    }
    // The string is not localized, save it to the database to provide an
    // ability to translate it from the UI later. At the same time we cannot
    // rely on the database during maintenance, thus we should check the
    // current system state.
    if (get_maintenance_mode() === false) {
        save_message($locale, $string, $string);
    }
    // One can change english strings from the UI. Try to use these strings.
    if ($locale != 'en') {
        return get_localized_string($string, 'en');
    }
    // The string is not localized at all. Use it "as is".
    return $string;
}
예제 #4
0
function getstring_($text, $locale)
{
    global $messages;
    if (!isset($messages[$locale])) {
        load_messages($locale);
    }
    $localized = $messages[$locale];
    if (isset($localized[$text])) {
        return $localized[$text];
    }
    if ($locale != 'en') {
        return getstring_($text, 'en');
    }
    return "!" . $text;
}
예제 #5
0
파일: translate.php 프로젝트: paulcn/mibew
    if (substr(trim($s), -1) == "." || substr(trim($s), -1) == "?") {
        $res .= ".";
    }
    return $res;
}
$operator = check_login();
csrfchecktoken();
$source = verifyparam("source", "/^[\\w-]{2,5}\$/", $default_locale);
$target = verifyparam("target", "/^[\\w-]{2,5}\$/", $current_locale);
$stringid = verifyparam("key", "/^[_\\.\\w]+\$/", "");
if (!isset($messages[$source])) {
    load_messages($source);
}
$lang1 = $messages[$source];
if (!isset($messages[$target])) {
    load_messages($target);
}
$lang2 = $messages[$target];
$errors = array();
$page = array('lang1' => $source, 'lang2' => $target, 'title1' => isset($lang1["localeid"]) ? $lang1["localeid"] : $source, 'title2' => isset($lang2["localeid"]) ? $lang2["localeid"] : $target);
if ($stringid) {
    $translation = isset($lang2[$stringid]) ? $lang2[$stringid] : "";
    if (isset($_POST['translation'])) {
        $translation = getparam('translation');
        if (!$translation) {
            $errors[] = no_field("form.field.translation");
        }
        if (count($errors) == 0) {
            save_message($target, $stringid, $translation);
            $page['saved'] = true;
            prepare_menu($operator, false);
예제 #6
0
파일: index.php 프로젝트: Puppollo/epic
        break;
    case 'profile':
        if (empty($user)) {
            header('Location:' . sprintf('%s?action=login', SITE_URL));
        }
        if (isset($_POST['style'])) {
            setcookie('style', $_POST['style'], 0, '/');
            $style = style($_POST['style']);
        }
        $response = template('../templates/profile.php', ['site_url' => SITE_URL, 'style' => $style]);
        break;
    case 'save':
        if (empty($user)) {
            header('Location:' . sprintf('%s?action=login', SITE_URL));
        }
        $message_id = empty($_POST['message_id']) ? null : (int) $_POST['message_id'];
        $message = empty($_POST['message']) ? null : $_POST['message'];
        if (!empty($message) && valid_token($_POST['token'])) {
            isset($message_id) ? update_message($connection, $message, $message_id) : insert_message($connection, $message, $user['id']);
        }
        header('Location:' . sprintf('%s?action=home&message_id=%d', SITE_URL, $message_id));
        break;
    default:
        if (empty($user)) {
            header('Location:' . sprintf('%s?action=login', SITE_URL));
        }
        $message_id = empty($_GET['message_id']) ? null : (int) $_GET['message_id'];
        $messages = load_messages($connection, $message_id);
        $response = template('../templates/home.php', ['messages' => $messages, 'token' => token(), 'style' => $style, 'site_url' => SITE_URL, 'message_id' => $message_id]);
}
echo empty($response) ? template('404.php') : $response;
예제 #7
0
파일: common.php 프로젝트: kuell/chat
function getstring_($text, $locale, $raw = false)
{
    global $messages;
    if (!isset($messages[$locale])) {
        load_messages($locale);
    }
    $localized = $messages[$locale];
    if (isset($localized[$text])) {
        return $raw ? $localized[$text] : sanitize_string($localized[$text], 'low', 'moderate');
    }
    if ($locale != 'en') {
        return getstring_($text, 'en', $raw);
    }
    return "!" . ($raw ? $text : sanitize_string($text, 'low', 'moderate'));
}
예제 #8
0
function main()
{
    if (!empty($_POST["type"])) {
        $type = $_POST["type"];
        $sender = $_SESSION["name"];
        if ($type == "message_send") {
            $ciphered_message = $_POST["cipher"];
            $real_message = $_POST["message"];
            $friend = $_POST["friend"];
            send_friend($ciphered_message, $real_message, $friend, $sender);
        } else {
            if ($type == "message_load") {
                load_messages($sender);
            } else {
                if ($type == "inbox_load") {
                    load_inbox($sender);
                } else {
                    if ($type == "outbox_load") {
                        load_outbox($sender);
                    } else {
                        if ($type == "message_read") {
                            $ciphered_message = $_POST["cipher"];
                            $real_message = $_POST["message"];
                            $friend = $_POST["friend"];
                            //             mark_message($ciphered_message, $real_message, $friend, $sender);
                        } else {
                            if ($type == "show_friends") {
                                $sender = $_SESSION["name"];
                                show_friends($sender);
                            } else {
                                if ($type == "accept_friend_request") {
                                    $friend = $_POST["friend"];
                                    //             accept_friend_request($friend, $sender);
                                } else {
                                    if ($type == "make_friend_request") {
                                        $friend = $_POST["friend"];
                                        //             make_friend_request($friend, $sender);
                                    } else {
                                        if ($type == "settings_load") {
                                            load_settings($sender);
                                        } else {
                                            if ($type == "settings_change") {
                                                $new_color = $_POST["new_color"];
                                                change_settings($sender, $new_color);
                                            } else {
                                                if ($type == "add_friend") {
                                                    $new_friend = $_POST["new_friend"];
                                                    add_friend($sender, $new_friend);
                                                } else {
                                                    //redirect("index", "Oops! Post information wasn't passed.");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}