<?php
/*
Plugin Name: HistoryNote Core – Social Wall
Description: Konum tabanlı, KYC destekli, Takvim ve Duvar hibrit sosyal medya çekirdeği.
Version: 1.0
Author: Codecia
*/
// 1. GÜVENLİK VE GİRİŞ KONTROLLERİ
if (!defined(‘ABSPATH’)) exit;
// 2. ÖZEL VERİ TİPLERİ (POST TYPES) – Notlar ve Duvarlar için
function hn_register_post_types() {
// “History Note” – Tarihe Not Düş
register_post_type(‘history_note’, array(
‘labels’ => array(‘name’ => ‘History Notes’, ‘singular_name’ => ‘Note’),
‘public’ => true,
‘has_archive’ => true,
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘custom-fields’),
‘show_in_rest’ => true, // Mobil uygulamalar (API) için gerekli
));
}
add_action(‘init’, ‘hn_register_post_types’);
// 3. DUVAR KATEGORİLERİ (TAXONOMIES)
function hn_register_taxonomies() {
register_taxonomy(‘wall_type’, ‘history_note’, array(
‘labels’ => array(‘name’ => ‘Wall Types’),
‘public’ => true,
‘hierarchical’ => true,
‘show_in_rest’ => true,
));
// Varsayılan Duvarları Oluştur
if (!term_exists(‘Public Wall’, ‘wall_type’)) wp_insert_term(‘Public Wall’, ‘wall_type’);
if (!term_exists(‘University Wall’, ‘wall_type’)) wp_insert_term(‘University Wall’, ‘wall_type’);
if (!term_exists(‘News Wall’, ‘wall_type’)) wp_insert_term(‘News Wall’, ‘wall_type’);
if (!term_exists(‘Art Wall’, ‘wall_type’)) wp_insert_term(‘Art Wall’, ‘wall_type’);
}
add_action(‘init’, ‘hn_register_taxonomies’);
// 4. RADİKAL GİRİŞ EKRANI VE NOT FORMU (SHORTCODE)
// Kullanımı: Bir sayfaya [history_input] yazın.
function hn_input_form_shortcode() {
if (!is_user_logged_in()) {
return ‘<div class=”hn-login-gate”>Lütfen önce <a href=”‘.wp_login_url().'”>Giriş Yapın</a> veya KYC ile Doğrulayın.</div>’;
}
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’ && isset($_POST[‘hn_submit_note’])) {
// Notu Kaydet
$post_id = wp_insert_post(array(
‘post_title’ => sanitize_text_field($_POST[‘hn_title’]),
‘post_content’ => sanitize_textarea_field($_POST[‘hn_content’]),
‘post_status’ => ‘publish’,
‘post_type’ => ‘history_note’,
‘post_author’ => get_current_user_id(),
));
// Duvar Seçimi ve Meta Veriler
if ($post_id) {
wp_set_object_terms($post_id, intval($_POST[‘hn_wall’]), ‘wall_type’);
update_post_meta($post_id, ‘hn_location’, sanitize_text_field($_POST[‘hn_location’])); // Konum
update_post_meta($post_id, ‘hn_is_official’, ‘pending’); // KYC Doğrulama durumu
echo ‘<div class=”hn-success”>Tarihe not düşüldü!</div>’;
}
}
// HTML FORM (Radikal Basit Arayüz)
ob_start();
?>
<style>
.hn-container { max-width: 600px; margin: 0 auto; background: #000; color: #fff; padding: 20px; font-family: ‘Courier New’, monospace; min-height: 100vh; }
.hn-input { width: 100%; background: transparent; border: none; border-bottom: 2px solid #333; color: #fff; font-size: 1.5rem; padding: 10px; margin-bottom: 20px; outline: none; }
.hn-textarea { width: 100%; background: #111; border: none; color: #0f0; height: 150px; padding: 10px; font-family: monospace; }
.hn-select { background: #222; color: #fff; border: 1px solid #444; padding: 10px; width: 100%; margin-bottom: 20px; }
.hn-btn { background: #fff; color: #000; border: none; padding: 15px 30px; font-weight: bold; cursor: pointer; width: 100%; text-transform: uppercase; letter-spacing: 2px; }
.hn-date-display { font-size: 0.8rem; color: #666; text-align: right; margin-bottom: 30px; }
</style>
<div class=”hn-container”>
<div class=”hn-date-display”><?php echo date(‘Y.m.d | H:i’); ?> // NOTE TO HISTORY</div>
<form method=”post”>
<input type=”text” name=”hn_title” class=”hn-input” placeholder=”Başlık / Konu…” required>
<select name=”hn_wall” class=”hn-select”>
<option value=””>Duvar Seçiniz (Where to post?)</option>
<?php
$terms = get_terms(array(‘taxonomy’ => ‘wall_type’, ‘hide_empty’ => false));
foreach ($terms as $term) {
echo ‘<option value=”‘.$term->term_id.'”>Request to: ‘.$term->name.'</option>’;
}
?>
</select>
<textarea name=”hn_content” class=”hn-textarea” placeholder=”Tarihe ne not düşmek istersin? (Write a note to history)”></textarea>
<input type=”hidden” name=”hn_location” id=”hn_location_input” value=”Unknown”>
<br><br>
<button type=”submit” name=”hn_submit_note” class=”hn-btn”>NOTE IT</button>
</form>
</div>
<script>
// Basit Geolocation Alımı
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
document.getElementById(‘hn_location_input’).value = position.coords.latitude + ‘,’ + position.coords.longitude;
});
}
</script>
<?php
return ob_get_clean();
}
add_shortcode(‘history_input’, ‘hn_input_form_shortcode’);
// 5. DUVAR AKIŞI (WALL DISPLAY – Google Takvim Gibi Listeleme)
// Kullanımı: [history_wall type=”public”]
function hn_wall_display_shortcode($atts) {
$atts = shortcode_atts(array(‘type’ => ‘public-wall’), $atts);
$args = array(
‘post_type’ => ‘history_note’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘wall_type’,
‘field’ => ‘slug’,
‘terms’ => $atts[‘type’],
),
),
‘posts_per_page’ => 20,
);
$query = new WP_Query($args);
ob_start();
echo ‘<div class=”hn-wall-feed” style=”background:#f4f4f4; padding:20px;”>’;
echo ‘<h3>Wall: ‘.strtoupper($atts[‘type’]).'</h3>’;
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$is_official = get_post_meta(get_the_ID(), ‘hn_is_official’, true) == ‘verified’;
$official_badge = $is_official ? ‘<span style=”color:blue”>✓ Official</span>’ : ”;
echo ‘<div style=”background:#fff; margin-bottom:15px; padding:15px; border-left: 5px solid #000;”>’;
echo ‘<small>’.get_the_date(‘d M Y H:i’).’ | ‘.get_post_meta(get_the_ID(), ‘hn_location’, true).'</small>’;
echo ‘<h4>’.get_the_title().’ ‘.$official_badge.'</h4>’;
echo ‘<div>’.get_the_excerpt().'</div>’;
echo ‘</div>’;
}
} else {
echo ‘Bu duvarda henüz not yok.’;
}
echo ‘</div>’;
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode(‘history_wall’, ‘hn_wall_display_shortcode’);