/*
Theme Name: Twenty Twenty-Five
Theme URI: https://wordpress.org/themes/twentytwentyfive/
Author: the WordPress team
Author URI: https://wordpress.org
Description: Twenty Twenty-Five emphasizes simplicity and adaptability. It offers flexible design options, supported by a variety of patterns for different page types, such as services and landing pages, making it ideal for building personal blogs, professional portfolios, online magazines, or business websites. Its templates cater to various blog styles, from text-focused to image-heavy layouts. Additionally, it supports international typography and diverse color palettes, ensuring accessibility and customization for users worldwide.
Requires at least: 6.7
Tested up to: 7.0
Requires PHP: 7.2
Version: 1.5
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentytwentyfive
Tags: one-column, custom-colors, custom-menu, custom-logo, editor-style, featured-images, full-site-editing, block-patterns, rtl-language-support, sticky-post, threaded-comments, translation-ready, wide-blocks, block-styles, style-variations, accessibility-ready, blog, portfolio, news
*/

/*
 * IMPORTANT: This file is only served on the frontend when `SCRIPT_DEBUG` is enabled;
 * in most instances, the `style.min.css` file will be served. It is not recommended that you
 * use the Theme File Editor to modify this stylesheet. Instead, add the necessary style
 * overrides via "Additional CSS" in the Site Editor.
 */

/*
 * Link styles
 * https://github.com/WordPress/gutenberg/issues/42319
 */
a {
	text-decoration-thickness: 1px !important;
	text-underline-offset: .1em;
}

/* Focus styles */
:where(.wp-site-blocks *:focus) {
	outline-width: 2px;
	outline-style: solid;
}

/* Increase the bottom margin on submenus, so that the outline is visible. */
.wp-block-navigation .wp-block-navigation-submenu .wp-block-navigation-item:not(:last-child) {
	margin-bottom: 3px;
}

/* Increase the outline offset on the parent menu items, so that the outline does not touch the text. */
.wp-block-navigation .wp-block-navigation-item .wp-block-navigation-item__content {
	outline-offset: 4px;
}

/* Remove outline offset from the submenus, otherwise the outline is visible outside the submenu container. */
.wp-block-navigation .wp-block-navigation-item ul.wp-block-navigation__submenu-container .wp-block-navigation-item__content {
	outline-offset: 0;
}

/*
 * Progressive enhancement to reduce widows and orphans
 * https://github.com/WordPress/gutenberg/issues/55190
 */
h1, h2, h3, h4, h5, h6, blockquote, caption, figcaption, p {
	text-wrap: pretty;
}

/*
 * Change the position of the more block on the front, by making it a block level element.
 * https://github.com/WordPress/gutenberg/issues/65934
*/
.more-link {
	display: block;
}

/*
 * Prevents unnecessary scrollbars while handling long lines of preformatted text.
 * https://core.trac.wordpress.org/ticket/63875
 */
:where(pre) {
	overflow-x: auto;
}
<?php
/**
 * =====================================================
 * TEKDER KONYA - functions.php Eklentisi
 * =====================================================
 * Bu kodun TAMAMINI WordPress temanızın
 * functions.php dosyasının EN SONUNA yapıştırın.
 *
 * Gereksinimler:
 *   - CPT UI eklentisi (Projeler içerik türü)
 *   - Advanced Custom Fields / ACF (Özel alanlar)
 *   - The Events Calendar (Etkinlikler)
 * =====================================================
 */

/* ====================================================
   1) HABERLER KISAYOLU
   Kullanım: [tekder_haberler limit="3" kategori="haberler"]
   ==================================================== */
function tekder_haberler_shortcode( $atts ) {
    $atts = shortcode_atts([
        'limit'     => 3,
        'kategori'  => 'haberler',
    ], $atts);

    $args = [
        'post_type'      => 'post',
        'posts_per_page' => intval( $atts['limit'] ),
        'post_status'    => 'publish',
        'orderby'        => 'date',
        'order'          => 'DESC',
    ];

    if ( ! empty( $atts['kategori'] ) ) {
        $args['category_name'] = sanitize_text_field( $atts['kategori'] );
    }

    $query = new WP_Query( $args );
    if ( ! $query->have_posts() ) return '<p style="color:#4a6fa5;font-size:14px;">Henüz haber eklenmemiş.</p>';

    // Kategori etiket renkleri
    $etiket_renkleri = [
        'haberler'  => 'Haber',
        'duyuru'    => 'Duyuru',
        'basin'     => 'Basın',
        'egitim'    => 'Eğitim',
        'etkinlik'  => 'Etkinlik',
        'proje'     => 'Proje',
    ];

    $html  = '<div class="tk-news-grid">';
    while ( $query->have_posts() ) {
        $query->the_post();

        // Kategorileri al
        $cats     = get_the_category();
        $cat_name = ! empty( $cats ) ? $cats[0]->name : 'Haber';
        $cat_slug = ! empty( $cats ) ? $cats[0]->slug : '';
        $etiket   = isset( $etiket_renkleri[ $cat_slug ] ) ? $etiket_renkleri[ $cat_slug ] : $cat_name;

        $tarih   = get_the_date( 'j M Y' );
        $baslik  = get_the_title();
        $ozet    = wp_trim_words( get_the_excerpt(), 18, '...' );
        $link    = get_permalink();

        $html .= '
        <div class="tk-news-card" onclick="window.location=\'' . esc_url( $link ) . '\'" style="cursor:pointer;">
            <span class="tk-news-tag">' . esc_html( $etiket ) . '</span>
            <h4>' . esc_html( $baslik ) . '</h4>
            <p>' . esc_html( $ozet ) . '</p>
            <div class="tk-news-foot">
                <span class="tk-news-date">' . esc_html( $tarih ) . '</span>
                <span class="tk-news-read">Devamı ›</span>
            </div>
        </div>';
    }
    wp_reset_postdata();
    $html .= '</div>';

    return $html;
}
add_shortcode( 'tekder_haberler', 'tekder_haberler_shortcode' );


/* ====================================================
   2) ETKİNLİKLER KISAYOLU
   The Events Calendar eklentisi kurulu olmalı.
   Kullanım: [tekder_etkinlikler limit="3"]
   ==================================================== */
function tekder_etkinlikler_shortcode( $atts ) {
    $atts = shortcode_atts([
        'limit' => 3,
    ], $atts );

    // The Events Calendar aktif mi?
    if ( ! class_exists( 'Tribe__Events__Main' ) ) {
        return '<p style="color:#e74c3c;font-size:13px;">⚠️ "The Events Calendar" eklentisi aktif değil.</p>';
    }

    $args = [
        'post_type'      => 'tribe_events',
        'posts_per_page' => intval( $atts['limit'] ),
        'post_status'    => 'publish',
        'orderby'        => 'meta_value',
        'meta_key'       => '_EventStartDate',
        'order'          => 'ASC',
        'meta_query'     => [[
            'key'     => '_EventStartDate',
            'value'   => current_time( 'mysql' ),
            'compare' => '>=',
            'type'    => 'DATETIME',
        ]],
    ];

    $query = new WP_Query( $args );
    if ( ! $query->have_posts() ) return '<p style="color:#4a6fa5;font-size:14px;">Yaklaşan etkinlik bulunmuyor.</p>';

    $ay_tr = [
        'Jan' => 'Oca', 'Feb' => 'Şub', 'Mar' => 'Mar',
        'Apr' => 'Nis', 'May' => 'May', 'Jun' => 'Haz',
        'Jul' => 'Tem', 'Aug' => 'Ağu', 'Sep' => 'Eyl',
        'Oct' => 'Eki', 'Nov' => 'Kas', 'Dec' => 'Ara',
    ];

    $html = '<div class="tk-ev-grid">';
    while ( $query->have_posts() ) {
        $query->the_post();
        $id      = get_the_ID();
        $baslik  = get_the_title();
        $link    = get_permalink();
        $ozet    = wp_trim_words( get_the_excerpt(), 16, '...' );

        // Tarih
        $start   = get_post_meta( $id, '_EventStartDate', true );
        $gun     = date( 'd', strtotime( $start ) );
        $ay_en   = date( 'M', strtotime( $start ) );
        $ay      = isset( $ay_tr[ $ay_en ] ) ? $ay_tr[ $ay_en ] : $ay_en;
        $saat_b  = date( 'H:i', strtotime( $start ) );

        // Bitiş saati
        $end     = get_post_meta( $id, '_EventEndDate', true );
        $saat_e  = $end ? date( 'H:i', strtotime( $end ) ) : '';

        // Konum
        $venue_id = get_post_meta( $id, '_EventVenueID', true );
        $konum    = $venue_id ? get_the_title( $venue_id ) : 'Konum belirtilmedi';

        $saat_str = $saat_b . ( $saat_e ? ' — ' . $saat_e : '' );

        $html .= '
        <div class="tk-ev-card" onclick="window.location=\'' . esc_url( $link ) . '\'" style="cursor:pointer;">
            <div class="tk-ev-top">
                <div class="tk-ev-badge">
                    <strong>' . esc_html( $gun ) . '</strong>
                    <span>' . esc_html( $ay ) . '</span>
                </div>
                <h3>' . esc_html( $baslik ) . '</h3>
            </div>
            <div class="tk-ev-bot">
                <div class="tk-ev-meta">📍 ' . esc_html( $konum ) . '</div>
                <div class="tk-ev-meta">🕑 ' . esc_html( $saat_str ) . '</div>
                <p>' . esc_html( $ozet ) . '</p>
            </div>
        </div>';
    }
    wp_reset_postdata();
    $html .= '</div>';

    return $html;
}
add_shortcode( 'tekder_etkinlikler', 'tekder_etkinlikler_shortcode' );


/* ====================================================
   3) PROJELER KISAYOLU
   CPT UI + ACF gerekli.
   Kullanım: [tekder_projeler limit="3" durum="Devam Ediyor"]
   ==================================================== */
function tekder_projeler_shortcode( $atts ) {
    $atts = shortcode_atts([
        'limit' => 3,
        'durum' => '',
    ], $atts );

    $args = [
        'post_type'      => 'projeler',
        'posts_per_page' => intval( $atts['limit'] ),
        'post_status'    => 'publish',
        'orderby'        => 'date',
        'order'          => 'DESC',
    ];

    // Durum filtresi (ACF alanı: proje_durumu)
    if ( ! empty( $atts['durum'] ) ) {
        $args['meta_query'] = [[
            'key'     => 'proje_durumu',
            'value'   => sanitize_text_field( $atts['durum'] ),
            'compare' => '=',
        ]];
    }

    $query = new WP_Query( $args );
    if ( ! $query->have_posts() ) return '<p style="color:#4a6fa5;font-size:14px;">Henüz proje eklenmemiş.</p>';

    $html = '<div class="tk-proj-grid">';
    while ( $query->have_posts() ) {
        $query->the_post();

        $baslik = get_the_title();
        $ozet   = wp_trim_words( get_the_excerpt(), 18, '...' );
        $link   = get_permalink();

        // ACF alanları
        $yuzde  = function_exists( 'get_field' ) ? intval( get_field( 'tamamlanma_yuzdesi' ) ) : 0;
        $durum  = function_exists( 'get_field' ) ? get_field( 'proje_durumu' )  : 'Devam Ediyor';
        $ikon   = function_exists( 'get_field' ) ? get_field( 'proje_ikonu' )   : '💡';

        if ( empty( $durum ) ) $durum = 'Devam Ediyor';
        if ( empty( $ikon )  ) $ikon  = '💡';
        if ( $yuzde < 0  )     $yuzde = 0;
        if ( $yuzde > 100 )    $yuzde = 100;

        $html .= '
        <div class="tk-proj-card" onclick="window.location=\'' . esc_url( $link ) . '\'" style="cursor:pointer;">
            <div class="tk-proj-icon">' . esc_html( $ikon ) . '</div>
            <h4>' . esc_html( $baslik ) . '</h4>
            <p>' . esc_html( $ozet ) . '</p>
            <div class="tk-proj-bar-wrap">
                <div class="tk-proj-bar" style="width:' . $yuzde . '%"></div>
            </div>
            <div class="tk-proj-bar-label">
                <span>' . esc_html( $durum ) . '</span>
                <span>' . $yuzde . '%</span>
            </div>
        </div>';
    }
    wp_reset_postdata();
    $html .= '</div>';

    return $html;
}
add_shortcode( 'tekder_projeler', 'tekder_projeler_shortcode' );


/* ====================================================
   4) YÖNETİCİ PANELİ — Hızlı İstatistik Kutusu
   Admin panelinin ana ekranında özet gösterir.
   ==================================================== */
function tekder_dashboard_widget() {
    $haber_sayisi    = wp_count_posts( 'post' )->publish;
    $proje_sayisi    = wp_count_posts( 'projeler' )->publish ?? 0;
    $etkinlik_sayisi = class_exists( 'Tribe__Events__Main' )
                       ? wp_count_posts( 'tribe_events' )->publish
                       : '—';

    echo '<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:12px;padding:8px 0;">';

    $items = [
        [ 'label' => 'Haber',     'sayi' => $haber_sayisi,    'renk' => '#1a3a6b', 'link' => admin_url('edit.php') ],
        [ 'label' => 'Etkinlik',  'sayi' => $etkinlik_sayisi, 'renk' => '#1e50a0', 'link' => admin_url('edit.php?post_type=tribe_events') ],
        [ 'label' => 'Proje',     'sayi' => $proje_sayisi,    'renk' => '#2563c4', 'link' => admin_url('edit.php?post_type=projeler') ],
    ];

    foreach ( $items as $item ) {
        echo '<a href="' . esc_url( $item['link'] ) . '" style="text-decoration:none;background:#f0f4f9;border-radius:10px;padding:14px;text-align:center;border-top:3px solid ' . esc_attr( $item['renk'] ) . ';">';
        echo '<div style="font-size:26px;font-weight:700;color:' . esc_attr( $item['renk'] ) . ';line-height:1;">' . esc_html( $item['sayi'] ) . '</div>';
        echo '<div style="font-size:12px;color:#4a6fa5;margin-top:4px;">' . esc_html( $item['label'] ) . '</div>';
        echo '</a>';
    }

    echo '</div>';
    echo '<p style="font-size:12px;color:#93afd4;margin:8px 0 0;text-align:center;">Teknik Elemanlar Derneği Konya</p>';
}

function tekder_dashboard_widget_kaydet() {
    wp_add_dashboard_widget(
        'tekder_ozet',
        '📊 Tekder Konya — İçerik Özeti',
        'tekder_dashboard_widget'
    );
}
add_action( 'wp_dashboard_setup', 'tekder_dashboard_widget_kaydet' );

/* ====================================================
   SON
   ===================================================== */
add_filter( 'widget_text', 'do_shortcode' );
add_filter( 'the_content', 'do_shortcode' );
add_shortcode( 'tekder_test', function() {
    return '<p style="color:green;font-weight:bold;">✅ Shortcode çalışıyor!</p>';
});