Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/wp-content/themes/tuleva/helpers/acf/fund-pension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
if( function_exists('acf_add_local_field_group') ):

acf_add_local_field_group(array (
'key' => 'group_fund_pension_investment_report',
'title' => 'Investment Report',
'fields' => array (
array (
'key' => 'field_fund_pension_investment_report',
'label' => 'Investment Report',
'name' => 'investment_report_file',
'type' => 'file',
'instructions' => 'Select the latest investment report PDF from media library. When set, this replaces the hardcoded report URL in the template.',
'required' => 0,
'return_format' => 'url',
'library' => 'all',
'mime_types' => 'pdf',
),
),
'location' => array (
array (
array (
'param' => 'page_template',
'operator' => '==',
'value' => 'page_fund-stocks.php',
),
),
array (
array (
'param' => 'page_template',
'operator' => '==',
'value' => 'page_fund-bonds.php',
),
),
array (
array (
'param' => 'page_template',
'operator' => '==',
'value' => 'page_fund-third.php',
),
),
),
'menu_order' => 10,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'active' => 1,
));

endif;
1 change: 1 addition & 0 deletions src/wp-content/themes/tuleva/helpers/acf/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'helpers/acf/membership.php', // Membership page
'helpers/acf/fund-other.php', // Other fund pages
'helpers/acf/fund-savings.php', // Savings fund page
'helpers/acf/fund-pension.php', // Pension fund investment report field (TUK75, TUK00, TUV100)
'helpers/acf/fund-choosing.php', // Instructions — Step 1 page fields
'helpers/acf/jobs.php' // Jobs page fields
];
Expand Down
57 changes: 34 additions & 23 deletions src/wp-content/themes/tuleva/helpers/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,37 +396,48 @@ function hyphenate_string($string) {
}

function generate_report_link($url, $link_text = null) {
preg_match('/\/(\d{4})\/(\d{2})\//', $url, $matches);
$year = intval($matches[1]);
$month = intval($matches[2]);

$month--;
if ($month === 0) {
$month = 12;
$year--;
}
$is_absolute = (bool) filter_var($url, FILTER_VALIDATE_URL);
$path = $is_absolute ? parse_url($url, PHP_URL_PATH) : $url;
$filename = basename($path);

$year_str = strval($year);
$month_str = str_pad(strval($month), 2, '0', STR_PAD_LEFT);
if (preg_match('/(\d{4})-(\d{2})/', $filename, $matches)) {
// Report period is encoded directly in the filename (YYYY-MM), e.g.
// "... investeeringute aruanne 2026-05.pdf" — use it as the label.
$date_text = sprintf('%s.%s', $matches[2], $matches[1]);
} elseif (preg_match('/\/(\d{4})\/(\d{2})\//', $url, $matches)) {
// Legacy uploads carry no period in the filename: the report covers the month before the
// upload-folder month (a report is uploaded the month after the period it covers).
$year = intval($matches[1]);
$month = intval($matches[2]);

$month--;
if ($month === 0) {
$month = 12;
$year--;
}

$default_text = sprintf('%s.%s', $month_str, $year_str);
if ($link_text !== null) {
$link_text = sprintf('%s (%s)', $link_text, $default_text);
$month_str = str_pad(strval($month), 2, '0', STR_PAD_LEFT);
$date_text = sprintf('%s.%s', $month_str, strval($year));
} else {
$link_text = $default_text;
$date_text = null;
}

if (filter_var($url, FILTER_VALIDATE_URL)) {
$path = parse_url($url, PHP_URL_PATH);
} else {
$path = $url;
if ($date_text !== null) {
$link_text = $link_text !== null
? sprintf('%s (%s)', $link_text, $date_text)
: $date_text;
} elseif ($link_text === null) {
$link_text = __('Report', TEXT_DOMAIN);
}

// Preserve the original host for absolute URLs: the ACF-supplied media URL may be served from a
// CDN or dedicated media host. Only site-relative paths are resolved against the current site.
$href = $is_absolute ? $url : get_site_url() . $url;

$output = sprintf(
'<a href="%s%s" target="_blank">%s</a>',
get_site_url(),
$path,
$link_text
'<a href="%s" target="_blank">%s</a>',
esc_url($href),
esc_html($link_text)
);

return $output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@
<h2 class="mt-5 mb-4 h4"><?php _e('Reports', TEXT_DOMAIN) ?></h2>
<ul class="list-style-arrow text-secondary">
<li>
<?php echo generate_report_link('https://tuleva.ee/wp-content/uploads/2026/05/Tuleva-Maailma-Volakirjade-Pensionifondi-investeeringute-aruanne-aprill-2026.pdf',__('Investment reports', TEXT_DOMAIN)); ?><?php _e(' (in Estonian)', TEXT_DOMAIN) ?>
<?php
$report_url = get_field('investment_report_file') ?: 'https://tuleva.ee/wp-content/uploads/2026/05/Tuleva-Maailma-Volakirjade-Pensionifondi-investeeringute-aruanne-aprill-2026.pdf';
echo generate_report_link($report_url, __('Investment reports', TEXT_DOMAIN));
?><?php _e(' (in Estonian)', TEXT_DOMAIN) ?>
<br>
<a href="https://www.pensionikeskus.ee/ii-sammas/kohustuslikud-pensionifondid/fid/76/" target="_blank"><?php _e('Previous reports', TEXT_DOMAIN) ?></a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
<h2 class="mt-5 mb-4 h4"><?php _e('Reports', TEXT_DOMAIN) ?></h2>
<ul class="list-style-arrow mb-5 text-secondary">
<li>
<?php echo generate_report_link('https://tuleva.ee/wp-content/uploads/2026/05/Tuleva-Maailma-Aktsiate-Pensionifondi-investeeringute-aruanne-aprill-2026.pdf',__('Investment reports', TEXT_DOMAIN)); ?><?php _e(' (in Estonian)', TEXT_DOMAIN) ?>
<?php
$report_url = get_field('investment_report_file') ?: 'https://tuleva.ee/wp-content/uploads/2026/05/Tuleva-Maailma-Aktsiate-Pensionifondi-investeeringute-aruanne-aprill-2026.pdf';
echo generate_report_link($report_url, __('Investment reports', TEXT_DOMAIN));
?><?php _e(' (in Estonian)', TEXT_DOMAIN) ?>
<br>
<a href="https://www.pensionikeskus.ee/ii-sammas/kohustuslikud-pensionifondid/fid/77/" target="_blank"><?php _e('Previous reports', TEXT_DOMAIN) ?></a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
<h2 class="mt-5 mb-4 h4"><?php _e('Reports', TEXT_DOMAIN) ?></h2>
<ul class="list-style-arrow text-secondary">
<li>
<?php echo generate_report_link('https://tuleva.ee/wp-content/uploads/2026/05/Tuleva-III-Samba-Pensionifondi-investeeringute-aruanne-aprill-2026.pdf',__('Investment reports', TEXT_DOMAIN)); ?><?php _e(' (in Estonian)', TEXT_DOMAIN) ?>
<?php
$report_url = get_field('investment_report_file') ?: 'https://tuleva.ee/wp-content/uploads/2026/05/Tuleva-III-Samba-Pensionifondi-investeeringute-aruanne-aprill-2026.pdf';
echo generate_report_link($report_url, __('Investment reports', TEXT_DOMAIN));
?><?php _e(' (in Estonian)', TEXT_DOMAIN) ?>
<br>
<a href="https://www.pensionikeskus.ee/iii-sammas/vabatahtlikud-fondid/fid/81/" target="_blank"><?php _e('Previous reports', TEXT_DOMAIN) ?></a>
</li>
Expand Down