Files
citrus-cms/app/Functions/convert-map.php
T
2026-04-28 21:14:25 +03:00

112 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
function convertMapCache() {
// Converter-map verilerini al
$converterMap = j(setting("converter-map"));
// Mapping arrays oluştur ve cache'le
$cacheKey = "converter_map_data";
$mappings = Cache::remember($cacheKey, 3600, function() use ($converterMap) {
$termToRu = $termToEn = $enToRu = $ruToEn = $enToTerm = $ruToTerm = [];
if (is_array($converterMap)) {
foreach ($converterMap as $row) {
if (!empty($row['term']) && !empty($row['term_ru'])) {
$termToRu[$row['term']] = $row['term_ru'];
}
if (!empty($row['term']) && !empty($row['term_eng'])) {
$termToEn[$row['term']] = $row['term_eng'];
}
if (!empty($row['term_eng']) && !empty($row['term_ru'])) {
$enToRu[$row['term_eng']] = $row['term_ru'];
}
if (!empty($row['term_ru']) && !empty($row['term_eng'])) {
$ruToEn[$row['term_ru']] = $row['term_eng'];
}
if (!empty($row['term_eng']) && !empty($row['term'])) {
$enToTerm[$row['term_eng']] = $row['term'];
}
if (!empty($row['term_ru']) && !empty($row['term'])) {
$ruToTerm[$row['term_ru']] = $row['term'];
}
}
}
return [
'termToRu' => $termToRu,
'termToEn' => $termToEn,
'enToRu' => $enToRu,
'ruToEn' => $ruToEn,
'enToTerm' => $enToTerm,
'ruToTerm' => $ruToTerm
];
});
// Her bir mapping'i ayrı cache key'e kaydet
Cache::put('termToRu', $mappings['termToRu'], 3600);
Cache::put('termToEn', $mappings['termToEn'], 3600);
Cache::put('enToRu', $mappings['enToRu'], 3600);
Cache::put('ruToEn', $mappings['ruToEn'], 3600);
Cache::put('enToTerm', $mappings['enToTerm'], 3600);
Cache::put('ruToTerm', $mappings['ruToTerm'], 3600);
return $mappings;
}
function convertMap() {
$cacheKey = "converter_map_data";
// Önce cache'den okumayı dene
if (Cache::has($cacheKey)) {
$mappings = Cache::get($cacheKey);
// Cache'den okunan veri geçerli mi kontrol et
if (!empty($mappings) && is_array($mappings)) {
return $mappings;
}
}
// Cache yoksa veya geçersizse yeniden oluştur
$mappings = j(setting("converter-map"));
// Yeni veriyi cache'e kaydet
if (!empty($mappings) && is_array($mappings)) {
Cache::put($cacheKey, $mappings, 60);
}
return $mappings;
}
function convertRu($term) {
// Önce cache'de mapping var mı kontrol et
$converterMap = Cache::get('termToRu');
// Eğer cache'de yoksa, convertMapCache'i çağır
if (empty($converterMap)) {
convertMapCache();
$converterMap = Cache::get('termToRu');
}
if(isset($converterMap[$term])) {
return $converterMap[$term];
} else {
Log::info("convertRu not found", ['term' => $term]);
}
return $term;
}
function convertEn($term) {
// Önce cache'de mapping var mı kontrol et
$converterMap = Cache::get('termToEn');
// Eğer cache'de yoksa, convertMapCache'i çağır
if (empty($converterMap)) {
convertMapCache();
$converterMap = Cache::get('termToEn');
}
if(isset($converterMap[$term])) {
return $converterMap[$term];
}
return $term;
}
?>