本文整理汇总了PHP中Pimcore\Tool::isValidLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP Tool::isValidLanguage方法的具体用法?PHP Tool::isValidLanguage怎么用?PHP Tool::isValidLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Tool
的用法示例。
在下文中一共展示了Tool::isValidLanguage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPreferredLanguage
/**
* Get user preferred locale.
*
* @return string|null
*/
protected function getPreferredLanguage()
{
if (!isset($_COOKIE[self::LANG_PARAM_NAME])) {
return null;
}
$lang = $_COOKIE[self::LANG_PARAM_NAME];
if (Tool::isValidLanguage($lang)) {
return $lang;
}
return null;
}
示例2: getTableName
/**
* @return string
* @throws \Exception
* @throws \Zend_Exception
*/
protected function getTableName()
{
if (empty($this->tableName)) {
// default
$this->tableName = "object_" . $this->model->getClassId();
if (!$this->model->getIgnoreLocalizedFields()) {
$language = null;
// check for a localized field and if they should be used for this list
if (property_exists("\\Pimcore\\Model\\Object\\" . ucfirst($this->model->getClassName()), "localizedfields")) {
if ($this->model->getLocale()) {
if (Tool::isValidLanguage((string) $this->model->getLocale())) {
$language = (string) $this->model->getLocale();
}
}
if (!$language && \Zend_Registry::isRegistered("Zend_Locale")) {
$locale = \Zend_Registry::get("Zend_Locale");
if (Tool::isValidLanguage((string) $locale)) {
$language = (string) $locale;
}
}
if (!$language) {
$language = Tool::getDefaultLanguage();
}
if (!$language) {
throw new \Exception("No valid language/locale set. Use \$list->setLocale() to add a language to the listing, or register a global locale");
}
$this->tableName = "object_localized_" . $this->model->getClassId() . "_" . $language;
}
}
}
return $this->tableName;
}
示例3: getLanguage
/**
* @throws \Exception
* @param null $language
* @return string
*/
public function getLanguage($language = null)
{
if ($language) {
return (string) $language;
}
// try to get the language from the registry
try {
$locale = \Zend_Registry::get("Zend_Locale");
if (Tool::isValidLanguage((string) $locale)) {
return (string) $locale;
}
throw new \Exception("Not supported language");
} catch (\Exception $e) {
return Tool::getDefaultLanguage();
}
}
示例4: initTranslation
/**
* @return null|\Pimcore\Translate|\Pimcore\Translate\Website
* @throws \Zend_Exception
*/
public function initTranslation()
{
$translate = null;
if (\Zend_Registry::isRegistered("Zend_Translate")) {
$t = \Zend_Registry::get("Zend_Translate");
// this check is necessary for the case that a document is rendered within an admin request
// example: send test newsletter
if ($t instanceof \Pimcore\Translate) {
$translate = $t;
}
}
if (!$translate) {
// setup \Zend_Translate
try {
$locale = \Zend_Registry::get("Zend_Locale");
$translate = new \Pimcore\Translate\Website($locale);
if (Tool::isValidLanguage($locale)) {
$translate->setLocale($locale);
} else {
\Logger::error("You want to use an invalid language which is not defined in the system settings: " . $locale);
// fall back to the first (default) language defined
$languages = Tool::getValidLanguages();
if ($languages[0]) {
\Logger::error("Using '" . $languages[0] . "' as a fallback, because the language '" . $locale . "' is not defined in system settings");
$translate = new \Pimcore\Translate\Website($languages[0]);
// reinit with new locale
$translate->setLocale($languages[0]);
} else {
throw new \Exception("You have not defined a language in the system settings (Website -> Frontend-Languages), please add at least one language.");
}
}
// register the translator in \Zend_Registry with the key "\Zend_Translate" to use the translate helper for \Zend_View
\Zend_Registry::set("Zend_Translate", $translate);
} catch (\Exception $e) {
\Logger::error("initialization of Pimcore_Translate failed");
\Logger::error($e);
}
}
return $translate;
}
示例5: gridGetColumnConfigAction
//.........这里部分代码省略.........
if (!empty($fieldConfig)) {
$availableFields[] = $fieldConfig;
$count++;
}
}
}
}
}
}
} else {
if (empty($types) || in_array($field->getFieldType(), $types)) {
$fieldConfig = $this->getFieldGridConfig($field, $gridType, $count, !empty($types));
if (!empty($fieldConfig)) {
$availableFields[] = $fieldConfig;
$count++;
}
}
}
}
}
} else {
$savedColumns = $gridConfig['columns'];
foreach ($savedColumns as $key => $sc) {
if (!$sc['hidden']) {
if (in_array($key, $systemColumns)) {
$colConfig = array("key" => $key, "type" => "system", "label" => $key, "position" => $sc['position']);
if (isset($sc['width'])) {
$colConfig['width'] = $sc['width'];
}
$availableFields[] = $colConfig;
} else {
$keyParts = explode("~", $key);
if (substr($key, 0, 1) == "~") {
// not needed for now
// $type = $keyParts[1];
// $field = $keyParts[2];
// $keyid = $keyParts[3];
} else {
if (count($keyParts) > 1) {
$brick = $keyParts[0];
$key = $keyParts[1];
$brickClass = Object\Objectbrick\Definition::getByKey($brick);
$fd = $brickClass->getFieldDefinition($key);
if (!empty($fd)) {
$fieldConfig = $this->getFieldGridConfig($fd, $gridType, $sc['position'], true, $brick . "~");
if (!empty($fieldConfig)) {
if (isset($sc['width'])) {
$fieldConfig['width'] = $sc['width'];
}
$availableFields[] = $fieldConfig;
}
}
} else {
$fd = $class->getFieldDefinition($key);
//if not found, look for localized fields
if (empty($fd)) {
foreach ($localizedFields as $lf) {
$fd = $lf->getFieldDefinition($key);
if (!empty($fd)) {
break;
}
}
}
if (!empty($fd)) {
$fieldConfig = $this->getFieldGridConfig($fd, $gridType, $sc['position'], true);
if (!empty($fieldConfig)) {
if (isset($sc['width'])) {
$fieldConfig['width'] = $sc['width'];
}
$availableFields[] = $fieldConfig;
}
}
}
}
}
}
}
}
usort($availableFields, function ($a, $b) {
if ($a["position"] == $b["position"]) {
return 0;
}
return $a["position"] < $b["position"] ? -1 : 1;
});
$config = \Pimcore\Config::getSystemConfig();
$frontendLanguages = Tool\Admin::reorderWebsiteLanguages(\Pimcore\Tool\Admin::getCurrentUser(), $config->general->validLanguages);
if ($frontendLanguages) {
$language = explode(',', $frontendLanguages)[0];
} else {
$language = $this->getLanguage();
}
if (!Tool::isValidLanguage($language)) {
$validLanguages = Tool::getValidLanguages();
$language = $validLanguages[0];
}
if (!empty($gridConfig) && !empty($gridConfig['language'])) {
$language = $gridConfig['language'];
}
$this->_helper->json(array("sortinfo" => $gridConfig['sortinfo'], "language" => $language, "availableFields" => $availableFields, "onlyDirectChildren" => $gridConfig['onlyDirectChildren'], "pageSize" => $gridConfig['pageSize']));
}
示例6: setLanguage
/**
* @param $language
* @param bool $useFrontendLanguages
* @return $this
* @throws \Zend_Exception
*/
public function setLanguage($language, $useFrontendLanguages = false)
{
if (\Zend_Locale::isLocale($language, true)) {
$locale = new \Zend_Locale($language);
} else {
$locale = new \Zend_Locale("en");
}
if ($useFrontendLanguages) {
// check if given language is a valid language
if (!Tool::isValidLanguage($locale)) {
return;
}
\Zend_Registry::set("Zend_Locale", $locale);
} else {
// check if given language is installed if not => skip
if (!in_array((string) $locale->getLanguage(), AdminTool::getLanguages())) {
return;
}
\Zend_Registry::set("Zend_Locale", $locale);
if (\Zend_Registry::isRegistered("Zend_Translate")) {
$t = \Zend_Registry::get("Zend_Translate");
if ((string) $locale != (string) $t->getLocale()) {
$languageFile = AdminTool::getLanguageFile($locale);
$t->addTranslation($languageFile, $locale);
$t->setLocale($locale);
}
}
}
$this->language = (string) $locale;
$this->view->language = $this->getLanguage();
return $this;
}
示例7: createEmptyTranslation
/**
* @param $locale
* @param $messageId
* @return mixed
*/
protected function createEmptyTranslation($locale, $messageId)
{
$messageIdOriginal = $messageId;
$messageId = mb_strtolower($messageId);
// don't create translation if it's just empty
if (array_key_exists($messageId, $this->_translate[$locale])) {
return;
}
$class = self::getBackend();
// no translation found create key
if (Tool::isValidLanguage($locale)) {
try {
$t = $class::getByKey($messageId);
$t->addTranslation($locale, "");
} catch (\Exception $e) {
$t = new $class();
$t->setKey($messageId);
// add all available languages
$availableLanguages = (array) Tool::getValidLanguages();
foreach ($availableLanguages as $language) {
$t->addTranslation($language, "");
}
}
$t->save();
}
// put it into the store, otherwise when there are more calls to the same key during one process
// the key would be inserted/updated several times, what would be redundant
$this->_translate[$locale][$messageId] = $messageIdOriginal;
}
示例8: wordExportAction
//.........这里部分代码省略.........
$string = str_replace("\n", "", $string);
$string = str_replace("\r", "", $string);
$string = str_replace("\t", "", $string);
$string = preg_replace('/&[a-zA-Z0-9]+;/', '', $string);
// remove html entities
$string = preg_replace('#[ ]+#', '', $string);
return $string;
};
// remove empty tags (where it matters)
$elements = $dom->find("a, li");
if ($elements) {
foreach ($elements as $el) {
$string = $clearText($el->plaintext);
if (empty($string)) {
$el->outertext = "";
}
}
}
// replace links => links get [Linktext]
$elements = $dom->find("a");
if ($elements) {
foreach ($elements as $el) {
$string = $clearText($el->plaintext);
if (!empty($string)) {
$el->outertext = "[" . $el->plaintext . "]";
} else {
$el->outertext = "";
}
}
}
$html = $dom->save();
$dom->clear();
unset($dom);
// force closing tags (simple_html_dom doesn't seem to support this anymore)
$doc = new \DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML('<?xml encoding="UTF-8"><article>' . $html . "</article>");
libxml_clear_errors();
$html = $doc->saveHTML();
$bodyStart = strpos($html, "<body>") + 6;
$bodyEnd = strpos($html, "</body>");
if ($bodyStart && $bodyEnd) {
$html = substr($html, $bodyStart, $bodyEnd - $bodyStart);
}
$output .= $html;
}
} else {
if ($element instanceof Object\Concrete) {
$hasContent = false;
if ($fd = $element->getClass()->getFieldDefinition("localizedfields")) {
$definitions = $fd->getFielddefinitions();
$locale = new \Zend_Locale(str_replace("-", "_", $source));
if (Tool::isValidLanguage((string) $locale)) {
$locale = (string) $locale;
} else {
$locale = $locale->getLanguage();
}
$output .= '
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<td colspan="2"><span style="color:#cc2929;font-weight: bold;">Localized Data</span></td>
</tr>
';
foreach ($definitions as $definition) {
// check allowed datatypes
if (!in_array($definition->getFieldtype(), array("input", "textarea", "wysiwyg"))) {
continue;
}
$content = $element->{"get" . ucfirst($definition->getName())}($locale);
if (!empty($content)) {
$output .= '
<tr>
<td><span style="color:#cc2929;">' . $definition->getTitle() . ' (' . $definition->getName() . ')<span></td>
<td>' . $content . ' </td>
</tr>
';
$hasContent = true;
}
}
$output .= '</table>';
}
if (!$hasContent) {
$output = "";
// there's no content in the object, so reset all contents and do not inclide it in the export
}
}
}
// append contents
if (!empty($output)) {
$f = fopen($exportFile, "a+");
fwrite($f, $output);
fclose($f);
}
} catch (\Exception $e) {
\Logger::error("Word Export: " . $e->getMessage());
\Logger::error($e);
}
}
$this->_helper->json(array("success" => true));
}