Browse Source

implement namespace titles filter

master
ghost 9 months ago
parent
commit
b0d36b203d
  1. 37
      src/Controller/MainController.php
  2. 38
      src/Twig/AppExtension.php
  3. 10
      templates/default/main/namespace.html.twig
  4. 2
      templates/default/main/namespace.rss.twig
  5. 10
      templates/default/main/transaction.html.twig

37
src/Controller/MainController.php

@ -104,9 +104,6 @@ class MainController extends AbstractController @@ -104,9 +104,6 @@ class MainController extends AbstractController
],
$request->get('part') > 1 ? ((int) $request->get('part') - 1) * (int) $this->getParameter('app.main.index.limit') : 0,
$this->getParameter('app.main.index.limit')
),
'title' => $this->_title(
$request->get('namespace')
)
],
$response
@ -153,40 +150,8 @@ class MainController extends AbstractController @@ -153,40 +150,8 @@ class MainController extends AbstractController
'default/main/transaction.html.twig',
[
'request' => $request,
'record' => $record,
'title' => $this->_title(
$record['namespace']
)
]
);
}
private function _title(string $namespace): ?string
{
$index = new \Kvazar\Index\Manticore();
$results = $index->get(
'_KEVA_NS_',
[
'crc32_namespace' => crc32(
$namespace
)
'record' => $record
]
);
if ($results)
{
foreach ($results as $result)
{
if ($result['key'] == '_KEVA_NS_')
{
return trim(
$result['value']
);
}
}
}
return null;
}
}

38
src/Twig/AppExtension.php

@ -24,6 +24,13 @@ class AppExtension extends AbstractExtension @@ -24,6 +24,13 @@ class AppExtension extends AbstractExtension
$this,
'formatType'
]
),
new TwigFilter(
'namespace_title',
[
$this,
'namespaceTitle'
]
)
];
}
@ -122,4 +129,35 @@ class AppExtension extends AbstractExtension @@ -122,4 +129,35 @@ class AppExtension extends AbstractExtension
return '[undefined]';
}
}
public function namespaceTitle(
string $namespace
): string
{
$index = new \Kvazar\Index\Manticore();
$results = $index->get(
'_KEVA_NS_',
[
'crc32_namespace' => crc32(
$namespace
)
]
);
if ($results)
{
foreach ($results as $result)
{
if ($result['key'] == '_KEVA_NS_')
{
return trim(
$result['value']
);
}
}
}
return $namespace;
}
}

10
templates/default/main/namespace.html.twig

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
{% extends 'default/layout.html.twig' %}
{% block title %}{% if title %}{{ title }} - {% endif %}{% if request.get('part') > 1 %}{{ 'Part' | trans | upper }} {{ request.get('part') }} - {% endif %}{{ app.name }}{% endblock %}
{% block title %}{{ request.get('namespace') | namespace_title }} - {% if request.get('part') > 1 %}{{ 'Part' | trans | upper }} {{ request.get('part') }} - {% endif %}{{ app.name }}{% endblock %}
{% block favicon %}<link rel="icon" href="{{ request.get('namespace') | jIdenticon }}" />{% endblock %}
{% block body %}
<div class="t-center px-16 pt-54">
@ -10,11 +10,9 @@ @@ -10,11 +10,9 @@
<div class="mx-a mw-560 px-16 pb-16">
<img class="br-50 shine" src="{{ request.get('namespace') | jIdenticon }}" alt="{{ request.get('namespace') }}" />
</div>
{% if title %}
<div class="mb-36 c-1">
{{ title }}
</div>
{% endif %}
<div class="mb-36 c-1">
{{ request.get('namespace') | namespace_title }}
</div>
</div>
</div>
<div class="t-center px-16 pb-36">

2
templates/default/main/namespace.rss.twig

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<atom:link href="{{ url('main_namespace',{'namespace':request.get('namespace')}) }}" rel="self" type="application/rss+xml"></atom:link>
<title>{{ app.name }}</title>
<title>{{ request.get('namespace') | namespace_title }} - {{ app.name }}</title>
<link>{{ url('main_namespace',{'namespace':request.get('namespace')}) }}</link>
{% for record in records %}
<item>

10
templates/default/main/transaction.html.twig

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
{% extends 'default/layout.html.twig' %}
{% block title %}{% if title %}{{ title }} - {% endif %}{{ app.name }}{% endblock %}
{% block title %}{{ record.key | format_type(record.type.key) }} - {{ record.namespace | namespace_title }} - {{ app.name }}{% endblock %}
{% block favicon %}<link rel="icon" href="{{ record.namespace | jIdenticon }}" />{% endblock %}
{% block body %}
<div class="t-center px-16 pt-54">
@ -12,11 +12,9 @@ @@ -12,11 +12,9 @@
<img class="br-50 shine" src="{{ record.namespace | jIdenticon }}" alt="{{ record.namespace }}" />
</a>
</div>
{% if title %}
<div class="mb-36 c-1">
{{ title }}
</div>
{% endif %}
<div class="mb-36 c-1">
{{ record.namespace | namespace_title }}
</div>
</div>
</div>
<div class="t-center px-16 pb-36">

Loading…
Cancel
Save