Browse Source

Repository*: load category names from lang files; include only current name in category

master
parent
commit
78a244bddc
  1. 2
      repo.php
  2. 36
      src/RepositoryBase.php

2
repo.php

@ -72,6 +72,8 @@ if (isset($config['cache'])) {
$data = $repo->data($_REQUEST);
$repo->updateLang($data, $_REQUEST);
if (!array_key_exists('index', $data['categories'])) {
$data['categories']['index'] = array(
'type' => 'index',

36
src/RepositoryBase.php

@ -34,6 +34,42 @@ class RepositoryBase {
return $data;
}
function updateLang (&$data, $options) {
$lang = array_key_exists('lang', $options) ? $options['lang'] : 'en';
if (!is_array($data['lang'])) {
$data['lang'] = array();
}
foreach ($data['categories'] as $id => $category) {
$name = null;
if (array_key_exists("category:{$id}", $data['lang'])) {
$name = $data['lang']["category:{$id}"];
if ($name !== '' && $name !== null) {
$data['categories'][$id]['name'] = array(
$lang => $data['lang']["category:{$id}"],
);
}
}
elseif (array_key_exists('name', $category)) {
if (array_key_exists($lang, $category['name'])) {
$name = $category['name'][$lang];
}
elseif (array_key_exists('en', $category['name'])) {
$name = $category['name']['en'];
}
elseif (sizeof($category['name'])) {
$name = $category['name'][array_keys($category['name'])[0]];
}
$data['lang']["category:{$id}"] = $name;
$data['categories'][$id]['name'] = array($lang => $name);
}
}
}
function isCategory ($data) {
if (!array_key_exists('type', $data)) {
return false;

Loading…
Cancel
Save