<?php

if (! defined('ABSPATH')) {
    exit;
} function puffergo_get_contact_channel_types()
{
    return array('WhatsApp', 'WeChat', 'LinkedIn', 'Facebook', 'Twitter', 'YouTube', 'Other');
} function puffergo_footer_channel_icon_slug($type)
{
    $map = array('LinkedIn' => 'linkedin', 'Facebook' => 'facebook', 'Twitter' => 'twitter', 'YouTube' => 'youtube', 'WhatsApp' => 'whatsapp', 'WeChat' => 'link', 'Other' => 'link', );

    return isset($map[ $type ]) ? $map[ $type ] : 'link';
} function puffergo_footer_channel_href($value, $home)
{
    $value = trim((string) $value);

    if ($value === '') {
        return $home;
    }

if (strpos($value, 'http') === 0 || strpos($value, '//') !== false) {
        return $value;
    }

if (preg_match('/^[0-9+\-\s\(\)]+$/', $value)) {
        return 'tel:' . $value;
    }

return $home . ltrim($value, '/');
} function puffergo_get_footer_context()
{
    $sections = puffergo_get_footer_sections_from_menu();
    $copyright = PufferGo_Polylang::translate((string) get_option('puffergo_site_footer_copyright', ''));
    $home = PufferGo_Polylang::home_url();
    $year = gmdate('Y');
    $brand = puffergo_get_site_brand_identity();
    $brand_name = $brand['brand_name'];
    $logo_url = $brand['logo_url'];
    $logo_alt = $brand['logo_alt'];
    $contact = $brand['contact'];
    $email = $contact['email'];
    $phone = $contact['phone'];
    $address = $contact['address'];
    $channels = array();
    $wechat_value = '';
    $raw_channels = $contact['channels'];

    if (! empty($raw_channels)) {
        foreach ($raw_channels as $ch) {
            $type = isset($ch['type']) ? sanitize_text_field($ch['type']) : '';
            $raw_value = isset($ch['value']) ? (string) $ch['value'] : '';
            $raw_value = trim($raw_value);

            if ($type === '' || $raw_value === '') {
                continue;
            }

if ('WeChat' === $type) {
                $wechat_value = sanitize_text_field($raw_value);
                continue;
            }

if ('WhatsApp' === $type) {
                $whats = $raw_value;

                if (stripos($whats, 'http://') === 0) {
                    $whats = 'https://' . substr($whats, strlen('http://'));
                } elseif (stripos($whats, 'https://') !== 0 && 0 === strpos($whats, '//')) {
                    $whats = 'https:' . $whats;
                } elseif (preg_match('/^(wa\.me|www\.wa\.me|api\.whatsapp\.com)\//i', $whats) === 1) {
                    $whats = 'https://' . $whats;
                }

if (stripos($whats, 'https://') !== 0) {
                    continue;
                } $href = esc_url_raw($whats);

                if ($href === '') {
                    continue;
                } $channels[] = array('type' => $type, 'value' => $whats, 'href' => $href, 'icon' => puffergo_footer_channel_icon_slug($type), );
                continue;
            } $value = esc_url_raw($raw_value);

            if ($value === '') {
                $value = sanitize_text_field($raw_value);
            } $channels[] = array('type' => $type, 'value' => $value, 'href' => puffergo_footer_channel_href($value, $home), 'icon' => puffergo_footer_channel_icon_slug($type), );
        }
    } $context = array('sections' => $sections, 'copyright_text' => $copyright, 'home_url' => $home, 'year' => $year, 'brand_name' => $brand_name, 'logo_id' => $brand['logo_id'], 'logo_url' => $logo_url, 'logo_alt' => $logo_alt, 'contact_email' => $email, 'contact_phone' => $phone, 'contact_address' => $address, 'contact_channels' => $channels, 'wechat_value' => $wechat_value, );

    return apply_filters('puffergo_footer_context', $context);
} function puffergo_get_footer_sections_from_menu()
{
    $tree = puffergo_get_menu_tree('puffergo_footer', 'PufferGo Footer');

    if (empty($tree)) {
        return array();
    } $sections = array();

    foreach ($tree as $section) {
        $title = isset($section->title) ? sanitize_text_field($section->title) : '';

        if ($title === '') {
            continue;
        } $children = isset($section->children) && is_array($section->children) ? $section->children : array();

        if (empty($children)) {
            continue;
        } $links = array();

        foreach ($children as $child) {
            $name = isset($child->title) ? sanitize_text_field($child->title) : '';
            $url = isset($child->url) ? esc_url_raw($child->url) : '';

            if ($name === '') {
                continue;
            } $links[] = array('name' => $name, 'url' => $url, );
        }

if (empty($links)) {
            continue;
        } $sections[] = array('title' => $title, 'links' => $links, );
    }

return $sections;
}
