/**
  *  This method tries to return the translated value of a text key.
  *  If this key is not existing, the key is returned with the language, 
  *  in which the key should exist, as prefix and with question marks surrounding it.
  */
 public static function getTranslatedValue($key)
 {
     // if there is no language stored yet, use the default language
     $language = isset($_SESSION[Session::LANGUAGE]) ? $_SESSION[Session::LANGUAGE] : Config::DEFAULT_LANGUAGE;
     if (!self::isLoaded()) {
         self::loadTranslations();
     }
     // first, lookup whether the key is in the product-specific translations
     $prefix = "product.";
     if (substr($key, 0, strlen($prefix)) === $prefix) {
         if (array_key_exists($key, $_SESSION[Session::PRODUCT_TRANSLATIONS])) {
             return $_SESSION[Session::PRODUCT_TRANSLATIONS][$key];
         }
         return self::formatMissingKey($key, $language);
     }
     // ok, it was not... so lookup for the general key translations.
     // if the language is not in the stored keypairs, return the key with the unknown language as prefix
     if (!array_key_exists($language, $_SESSION[Session::TRANSLATIONS])) {
         return LanguageHelper::formatMissingKey($key, $language);
     }
     // if the key is not set in the stored keypairs, return the key
     if (!array_key_exists($key, $_SESSION[Session::TRANSLATIONS][$language])) {
         return LanguageHelper::formatMissingKey($key, $language);
     }
     // return the translated key
     return $_SESSION[Session::TRANSLATIONS][$language][$key];
 }
Exemple #2
0
/**
* 语言
*/
function post_config_language($v)
{
    $id = $v['language_id'];
    $language = Module_Post_Config::language();
    $str = LanguageHelper::img('posts', $v['vid'], 'post/default/update');
    return $language[$id] . "| " . $str . " ";
}
Exemple #3
0
function node_config_language($v)
{
    global $global_field_table;
    $id = $v['language_id'];
    $str = LanguageHelper::img($global_field_table, $v['vid'], array('node/query/update', array('id' => '{id}', 'fid' => (int) $_GET['fid'])));
    return $str;
}
Exemple #4
0
/**
* 语言
*/
function video_config_language($v)
{
    $id = $v['language_id'];
    $language = Module_Video_Config::language();
    $str = LanguageHelper::img('videos', $v['vid'], 'video/default/update');
    return $language[$id] . "| " . $str . " ";
}
 /**
  * This method checks whether the given language is available.
  * If this is the case, it sets it into the cookie / session.
  * Otherwise, the default language is used.
  * @param lang new language to use
  * @return language after changing
  */
 public static function handleLanguageChange($lang)
 {
     $languages = LanguageHelper::getLanguages();
     if (in_array($lang, $languages)) {
         $_SESSION[Session::LANGUAGE] = $lang;
         setcookie(Session::LANGUAGE, $lang, time() + Config::COOKIE_LIFETIME);
     } else {
         $_SESSION[Session::LANGUAGE] = Config::DEFAULT_LANGUAGE;
         setcookie(Session::LANGUAGE, Config::DEFAULT_LANGUAGE, time() + Config::COOKIE_LIFETIME);
     }
     return $_SESSION[Session::LANGUAGE];
 }
 public function handleRequestInMain()
 {
     $this->checkAccess();
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         // get classification, its type and price from POST array
         $classification = $_POST["name-classification"];
         $type = $_POST["name-type--" . $classification];
         $namedQuery = new NamedQuery($this->QUERY_INSERT_PRODUCT);
         $namedQuery->addParam(QueryParam::TYPE_STRING, $classification);
         $namedQuery->addParam(QueryParam::TYPE_STRING, $type);
         $namedQuery->addParam(QueryParam::TYPE_STRING, $_POST["name-price"]);
         // insert those information into DB and get the product's ID
         $insertId = CRUDService::getInstance()->executeNamedQuery($namedQuery);
         // now, we can generate the new file name for the uploaded image
         $fileName = $_FILES["name-image"]["name"];
         $lastDot = strrpos($fileName, ".");
         $imgType = substr($fileName, $lastDot);
         // example : ".jpg"
         // image name is like : <productType>-<id>.<imageType>
         // for example : robot-42.png
         $imgName = strtolower($type) . "-" . $insertId . $imgType;
         // define the upload directory's relative path
         $uploadDir = "./images/products/" . $classification . "/" . strtolower($type) . "/";
         // move the uploaded file to the correct image directory
         move_uploaded_file($_FILES["name-image"]["tmp_name"], $uploadDir . $imgName);
         // now, update the database to set the image name
         $nq2 = new NamedQuery($this->QUERY_SET_IMAGE);
         $nq2->addParam(QueryParam::TYPE_STRING, $imgName);
         $nq2->addParam(QueryParam::TYPE_INTEGER, $insertId);
         CRUDService::getInstance()->executeNamedQuery($nq2);
         // keys to write : product.<id>.name.<lang> , product.<id>.description.<lang>
         $data = 'product.' . $insertId . '.name.de = "' . $_POST["name-name-de"] . '"' . PHP_EOL;
         $data .= 'product.' . $insertId . '.name.en = "' . $_POST["name-name-en"] . '"' . PHP_EOL;
         $data .= 'product.' . $insertId . '.name.fr = "' . $_POST["name-name-fr"] . '"' . PHP_EOL;
         $data .= 'product.' . $insertId . '.description.de = "' . $_POST["name-description-de"] . '"' . PHP_EOL;
         $data .= 'product.' . $insertId . '.description.en = "' . $_POST["name-description-en"] . '"' . PHP_EOL;
         $data .= 'product.' . $insertId . '.description.fr = "' . $_POST["name-description-fr"] . '"' . PHP_EOL;
         // write titles and descriptions into the products.ini file
         file_put_contents(Config::DEFAULT_PRODUCT_FILE, $data, FILE_APPEND);
         // finally, update the session with the new products.ini file content
         LanguageHelper::loadTranslations();
     }
 }
 /**
  * Returns the language list
  * 
  * @param  string  $index Optional, defaults to 'name'
  * could be name or short. 
  * @return array of languages
  */
 public static function getLanguages($index = 'name')
 {
     if (!in_array($index, array('name', 'short', 'all'))) {
         throw new InvalidArgumentException($index . ' is not a valid language offset');
     }
     if (!isset(self::$Languages)) {
         $parser = new INIConfigurationParser();
         $parser->loadFile(BUSINESS . 'conf/langs.ini');
         $parser->parse();
         $languages = $parser->getConfigs();
         if ('all' == $index) {
             self::$Languages = $languages;
         } else {
             foreach ($languages as $key => $language) {
                 self::$Languages[$key] = $language[$index];
             }
         }
     }
     return self::$Languages;
 }
 /**
  * Overwrite the abstract function from Superclass.
  * If an admin POST-ed a product change, update the database if necessary,
  * and also update the key values (language translations) for this product
  * in the products.ini file. 
  */
 public function handleRequestInMain()
 {
     $this->checkAccess();
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $id = intval($_POST["name-id"]);
         $_SESSION[Session::PRODUCT_TRANSLATIONS]["product." . $id . ".name.de"] = $_POST["name-name-de"];
         $_SESSION[Session::PRODUCT_TRANSLATIONS]["product." . $id . ".name.en"] = $_POST["name-name-en"];
         $_SESSION[Session::PRODUCT_TRANSLATIONS]["product." . $id . ".name.fr"] = $_POST["name-name-fr"];
         $_SESSION[Session::PRODUCT_TRANSLATIONS]["product." . $id . ".description.de"] = $_POST["name-description-de"];
         $_SESSION[Session::PRODUCT_TRANSLATIONS]["product." . $id . ".description.en"] = $_POST["name-description-en"];
         $_SESSION[Session::PRODUCT_TRANSLATIONS]["product." . $id . ".description.fr"] = $_POST["name-description-fr"];
         // write the edited content from session back into the product's file
         file_put_contents(Config::DEFAULT_PRODUCT_FILE, $this->productArrayToString());
         LanguageHelper::loadTranslations();
         // update the database to set the new price
         $nq = new NamedQuery($this->QUERY_SET_PRICE);
         $nq->addParam(QueryParam::TYPE_DOUBLE, doubleval($_POST["name-price"]));
         $nq->addParam(QueryParam::TYPE_INTEGER, $id);
         CRUDService::getInstance()->executeNamedQuery($nq);
         // redirect back to the delete.php page
         $this->redirect("delete.php");
     }
 }
 /**
  * Create an e-mail and check whether we are on localhost or not.
  * If localhost, we can't send an e-mail because of missing e-mail
  * provider. Otherwise, send an e-mail to the client with all 
  * information concerning the ordering.
  * @return boolean e-mail send state
  */
 private function sendMail()
 {
     $receiver = StringUtils::removeTags($_POST["name-email"]);
     $subject = LanguageHelper::getTranslatedValue(Config::EMAIL_SUBJECT);
     $message = $this->createMailBody();
     // to send an HTML e-mail, the Content-type header must be set
     $headers = "MIME-Version: 1.0 \r\n";
     $headers .= "Content-type: text/html; charset=iso-8859-1 \r\n";
     // additional headers
     $headers .= "From: 'lawnmower.ch Online Shop' <" . Config::EMAIL_SHOP_ADDRESS . "> \r\n";
     if (Config::EMAIL_USE_BCC) {
         $headers .= "Bcc: " . Config::EMAIL_SHOP_ADDRESS . "\r\n";
     }
     // if we are on localhost, always return true
     if (StringUtils::isLocalhost()) {
         return true;
     }
     // try to send the e-mail and return whether it was sent or not
     return mail($receiver, $subject, $message, $headers);
 }
 private function getValue($id, $type, $lang)
 {
     $key = "product." . $id . "." . $type . "." . $lang;
     return LanguageHelper::getTranslatedValue($key);
 }
 /**
  *  This method loads the key translations if necessary, 
  *  and replaces all text-keys with the chosen language translation.
  */
 protected function handleTranslations($template)
 {
     // if translations aren't loaded yet, do it once
     if (!isset($_SESSION[Session::TRANSLATIONS])) {
         LanguageHelper::loadTranslations();
     }
     // $matches[0] contains the results of the complete pattern
     // $matches[1] contains the results which matched the pattern inside the brackets (-> see regex pattern)
     preg_match_all(LanguageHelper::REGEX_TRANSLATION_KEYS, $template, $matches);
     foreach ($matches[1] as $match) {
         $template = str_replace("?{" . $match . "}", LanguageHelper::getTranslatedValue($match), $template);
     }
     return $template;
 }
function displayResultPagination()
{
    global $pageNumber;
    global $queryId;
    global $propertyCount;
    global $pageCount;
    global $resultsPage;
    global $searchResultType;
    global $languageArr;
    global $dir;
    $resultsPage .= $searchResultType;
    $searchPagination = TemplateHelper::render('templates/resultsPagination.html', array('Paging.Search.Action' => $dir . '/searchResults.php', 'Paging.PageOf' => LanguageHelper::format($languageArr['results_Headings']['pagination']['page_Count'], array('i' => $pageNumber, 'x' => $pageCount)), 'Paging.First.Link' => $pageNumber > 1 ? 'href="' . '?pageNo=' . 1 . '"' : ' class="wbPagButtonDisable"', 'Paging.First.Text' => $languageArr['results_Headings']['pagination']['first'], 'Paging.Prev.Link' => $pageNumber > 1 ? 'href="' . '?pageNo=' . ($pageNumber - 1) . '"' : 'class="wbPagButtonDisable"', 'Paging.Prev.Text' => $languageArr['results_Headings']['pagination']['prev'], 'Paging.Next.Link' => $pageCount == $pageNumber ? 'class="wbPagButtonDisable"' : 'href="' . '?pageNo=' . ($pageNumber + 1) . '"', 'Paging.Next.Text' => $languageArr['results_Headings']['pagination']['next'], 'Paging.Last.Link' => $pageCount == $pageNumber ? 'class="wbPagButtonDisable"' : 'href="' . '?pageNo=' . $pageCount . '"', 'Paging.Last.Text' => $languageArr['results_Headings']['pagination']['last'], 'Paging.ResultCount' => $languageArr['results_Headings']['resultCount'], 'Paging.ShortHeader' => $languageArr['results_Headings']['sort']['header'], 'Paging.SortOption' => formatOptions(array('' => $languageArr['results_Headings']['sort']['options_Features'], '0' => $languageArr['results_Headings']['sort']['options_PriceAsc'], '1' => $languageArr['results_Headings']['sort']['options_PriceDesc'], '2' => $languageArr['results_Headings']['sort']['options_Location']))));
    echo $searchPagination;
}