Update paling Baru
This commit is contained in:
parent
e342e6bc0e
commit
70b6d84e70
@ -249,6 +249,8 @@ class AdminController extends Controller {
|
||||
'twitter_url' => get_setting('twitter_url'),
|
||||
'instagram_url' => get_setting('instagram_url'),
|
||||
'github_url' => get_setting('github_url'),
|
||||
'telegram_url' => get_setting('telegram_url'),
|
||||
'whatsapp_url' => get_setting('whatsapp_url'),
|
||||
];
|
||||
$this->view('admin/settings', ['settings' => $settings]);
|
||||
}
|
||||
@ -259,7 +261,7 @@ class AdminController extends Controller {
|
||||
|
||||
$fields = [
|
||||
'site_name', 'meta_description', 'meta_keywords', 'head_js', 'body_js',
|
||||
'facebook_url', 'twitter_url', 'instagram_url', 'github_url'
|
||||
'facebook_url', 'twitter_url', 'instagram_url', 'github_url', 'telegram_url', 'whatsapp_url'
|
||||
];
|
||||
foreach ($fields as $field) {
|
||||
if (isset($_POST[$field])) {
|
||||
|
||||
@ -3,21 +3,24 @@
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use PDO;
|
||||
|
||||
class BlogController extends Controller {
|
||||
|
||||
public function index() {
|
||||
$db = db_pdo();
|
||||
$posts = $db->query("SELECT * FROM posts WHERE status = 'published' ORDER BY created_at DESC")->fetchAll();
|
||||
$this->view('blog/index', ['posts' => $posts]);
|
||||
$stmt = $db->prepare("SELECT * FROM posts ORDER BY created_at DESC");
|
||||
$stmt->execute();
|
||||
$blogPosts = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$this->view('blog/index', ['blogPosts' => $blogPosts]);
|
||||
}
|
||||
|
||||
public function detail($params) {
|
||||
$slug = $params['slug'];
|
||||
$db = db_pdo();
|
||||
$stmt = $db->prepare("SELECT * FROM posts WHERE slug = ? AND status = 'published'");
|
||||
$stmt = $db->prepare("SELECT * FROM posts WHERE slug = ?");
|
||||
$stmt->execute([$slug]);
|
||||
$post = $stmt->fetch();
|
||||
$post = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$post) {
|
||||
$this->view('404');
|
||||
|
||||
@ -7,7 +7,7 @@ class Controller {
|
||||
extract($data);
|
||||
$viewFile = __DIR__ . "/../../views/{$name}.php";
|
||||
if (file_exists($viewFile)) {
|
||||
require_once $viewFile;
|
||||
require $viewFile;
|
||||
} else {
|
||||
echo "View {$name} not found";
|
||||
}
|
||||
@ -22,4 +22,4 @@ class Controller {
|
||||
header("Location: {$url}");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
assets/images/pexels/34396237.jpg
Normal file
BIN
assets/images/pexels/34396237.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
BIN
assets/images/pexels/6901037.jpg
Normal file
BIN
assets/images/pexels/6901037.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
BIN
assets/pasted-20260225-204334-673d6021.jpg
Normal file
BIN
assets/pasted-20260225-204334-673d6021.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 381 KiB |
BIN
assets/pasted-20260225-205030-7ab9dc17.jpg
Normal file
BIN
assets/pasted-20260225-205030-7ab9dc17.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 384 KiB |
@ -0,0 +1,4 @@
|
||||
-- Add Telegram and WhatsApp Social Media Settings
|
||||
INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES
|
||||
('telegram_url', ''),
|
||||
('whatsapp_url', '');
|
||||
5
debug_blog.log
Normal file
5
debug_blog.log
Normal file
@ -0,0 +1,5 @@
|
||||
Count: 3
|
||||
Count: 3
|
||||
Count: 3
|
||||
Count: 3
|
||||
Count: 3
|
||||
46
fill_blog.php
Normal file
46
fill_blog.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
require_once __DIR__ . '/ai/LocalAIApi.php';
|
||||
|
||||
$prompt = "Generate 3 professional blog posts for an APK/Android app store website.
|
||||
Return ONLY a JSON array of objects. Each object must have:
|
||||
- 'title': A catchy title.
|
||||
- 'slug': A URL-friendly slug.
|
||||
- 'content': Detailed HTML content (using <p>, <h2>, <ul>, etc.) at least 300 words.
|
||||
Topics:
|
||||
1. Top 5 Productivity Apps for 2026.
|
||||
2. How to Safely Install APKs on Your Android Device.
|
||||
3. The Future of Mobile Gaming: Trends in 2026.
|
||||
|
||||
Language: Indonesian.";
|
||||
|
||||
$response = LocalAIApi::createResponse([
|
||||
'input' => [
|
||||
['role' => 'system', 'content' => 'You are a professional tech blogger and SEO expert.'],
|
||||
['role' => 'user', 'content' => $prompt],
|
||||
],
|
||||
]);
|
||||
|
||||
if (!empty($response['success'])) {
|
||||
$posts = LocalAIApi::decodeJsonFromResponse($response);
|
||||
if (is_array($posts)) {
|
||||
$db = db();
|
||||
foreach ($posts as $post) {
|
||||
try {
|
||||
$stmt = $db->prepare("INSERT INTO posts (title, slug, content, status) VALUES (?, ?, ?, 'published')");
|
||||
$stmt->execute([$post['title'], $post['slug'], $post['content']]);
|
||||
echo "Inserted: " . $post['title'] . "\n";
|
||||
} catch (Exception $e) {
|
||||
echo "Error inserting " . $post['title'] . ": " . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "Failed to decode JSON from AI response.\n";
|
||||
// Attempt to extract text if JSON decoding fails directly
|
||||
$text = LocalAIApi::extractText($response);
|
||||
echo "Raw AI Text: " . substr($text, 0, 500) . "...\n";
|
||||
}
|
||||
} else {
|
||||
echo "AI Request failed: " . ($response['error'] ?? 'Unknown error') . "\n";
|
||||
}
|
||||
|
||||
54
update_blog_images.php
Normal file
54
update_blog_images.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
// Helper functions from guidelines
|
||||
function pexels_key() {
|
||||
$k = getenv('PEXELS_KEY');
|
||||
return $k && strlen($k) > 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18';
|
||||
}
|
||||
|
||||
function pexels_get($url) {
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ],
|
||||
CURLOPT_TIMEOUT => 15,
|
||||
]);
|
||||
$resp = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
function download_to($srcUrl, $destPath) {
|
||||
$data = file_get_contents($srcUrl);
|
||||
if ($data === false) return false;
|
||||
if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true);
|
||||
return file_put_contents($destPath, $data) !== false;
|
||||
}
|
||||
|
||||
$db = db();
|
||||
$posts = $db->query("SELECT id, title FROM posts WHERE image_path IS NULL OR image_path = ''")->fetchAll();
|
||||
|
||||
foreach ($posts as $post) {
|
||||
$q = urlencode($post['title'] . " android tech");
|
||||
$url = 'https://api.pexels.com/v1/search?query=' . $q . '&orientation=landscape&per_page=1&page=1';
|
||||
$data = pexels_get($url);
|
||||
if ($data && !empty($data['photos'])) {
|
||||
$photo = $data['photos'][0];
|
||||
$src = $photo['src']['large'] ?? $photo['src']['original'];
|
||||
$filename = 'assets/images/pexels/' . $photo['id'] . '.jpg';
|
||||
$target = __DIR__ . '/' . $filename;
|
||||
if (download_to($src, $target)) {
|
||||
$db->prepare("UPDATE posts SET image_path = ? WHERE id = ?")->execute([$filename, $post['id']]);
|
||||
echo "Added image to: " . $post['title'] . "\n";
|
||||
} else {
|
||||
echo "Failed to download image for: " . $post['title'] . "\n";
|
||||
}
|
||||
} else {
|
||||
echo "No image found for: " . $post['title'] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,6 +60,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label fw-semibold">Telegram URL</label>
|
||||
<input type="url" name="telegram_url" class="form-control" value="<?php echo htmlspecialchars($settings['telegram_url'] ?? ''); ?>" placeholder="https://t.me/yourchannel">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label fw-semibold">WhatsApp URL</label>
|
||||
<input type="url" name="whatsapp_url" class="form-control" value="<?php echo htmlspecialchars($settings['whatsapp_url'] ?? ''); ?>" placeholder="https://wa.me/yournumber">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
<h5 class="fw-bold mb-3"><i class="fas fa-search me-2"></i>SEO Settings</h5>
|
||||
|
||||
@ -118,4 +129,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include 'footer.php'; ?>
|
||||
<?php include 'footer.php'; ?>
|
||||
@ -1,5 +1,6 @@
|
||||
<?php include dirname(__DIR__) . '/header.php'; ?>
|
||||
|
||||
|
||||
<section class="py-5 bg-light">
|
||||
<div class="container">
|
||||
<div class="row mb-5">
|
||||
@ -10,11 +11,11 @@
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
<?php foreach ($posts as $post): ?>
|
||||
<?php foreach ($blogPosts as $item): ?>
|
||||
<div class="col-md-6 col-lg-4">
|
||||
<article class="card h-100 border-0 shadow-sm overflow-hidden hover-lift transition-all">
|
||||
<?php if ($post['image_path']): ?>
|
||||
<img src="/<?php echo $post['image_path']; ?>" class="card-img-top" alt="<?php echo htmlspecialchars($post['title']); ?>" style="height: 200px; object-fit: cover;">
|
||||
<?php if ($item['image_path']): ?>
|
||||
<img src="/<?php echo $item['image_path']; ?>" class="card-img-top" alt="<?php echo htmlspecialchars($item['title']); ?>" style="height: 200px; object-fit: cover;">
|
||||
<?php else: ?>
|
||||
<div class="bg-primary bg-opacity-10 d-flex align-items-center justify-content-center" style="height: 200px;">
|
||||
<i class="fas fa-newspaper fa-3x text-primary opacity-25"></i>
|
||||
@ -22,17 +23,17 @@
|
||||
<?php endif; ?>
|
||||
<div class="card-body p-4">
|
||||
<div class="text-muted small mb-2">
|
||||
<i class="far fa-calendar-alt me-1"></i> <?php echo date('M d, Y', strtotime($post['created_at'])); ?>
|
||||
<i class="far fa-calendar-alt me-1"></i> <?php echo date('M d, Y', strtotime($item['created_at'])); ?>
|
||||
</div>
|
||||
<h2 class="h5 card-title fw-bold mb-3">
|
||||
<a href="/blog/<?php echo $post['slug']; ?>" class="text-dark text-decoration-none stretched-link">
|
||||
<?php echo htmlspecialchars($post['title']); ?>
|
||||
<a href="/blog/<?php echo $item['slug']; ?>" class="text-dark text-decoration-none stretched-link">
|
||||
<?php echo htmlspecialchars($item['title']); ?>
|
||||
</a>
|
||||
</h2>
|
||||
<p class="card-text text-muted mb-0">
|
||||
<?php
|
||||
$excerpt = strip_tags($post['content']);
|
||||
echo mb_strimwidth($excerpt, 0, 120, '...');
|
||||
$excerpt = strip_tags($item['content']);
|
||||
echo strlen($excerpt) > 120 ? substr($excerpt, 0, 120) . '...' : $excerpt;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
@ -40,7 +41,7 @@
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if (empty($posts)): ?>
|
||||
<?php if (empty($blogPosts)): ?>
|
||||
<div class="col-12 text-center py-5">
|
||||
<div class="mb-3">
|
||||
<i class="fas fa-folder-open fa-3x text-muted opacity-25"></i>
|
||||
@ -53,4 +54,4 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php include dirname(__DIR__) . '/footer.php'; ?>
|
||||
<?php include dirname(__DIR__) . '/footer.php'; ?>
|
||||
@ -60,6 +60,12 @@
|
||||
<?php if ($gh = get_setting('github_url')): ?>
|
||||
<a href="<?php echo $gh; ?>" target="_blank" class="text-muted"><i class="bi bi-github"></i></a>
|
||||
<?php endif; ?>
|
||||
<?php if ($tg = get_setting('telegram_url')): ?>
|
||||
<a href="<?php echo $tg; ?>" target="_blank" class="text-muted"><i class="bi bi-telegram"></i></a>
|
||||
<?php endif; ?>
|
||||
<?php if ($wa = get_setting('whatsapp_url')): ?>
|
||||
<a href="<?php echo $wa; ?>" target="_blank" class="text-muted"><i class="bi bi-whatsapp"></i></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -69,4 +75,4 @@
|
||||
<script src="/assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
<?php echo get_setting('body_js'); ?>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user