-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblogadmin.html
More file actions
202 lines (185 loc) · 11.5 KB
/
blogadmin.html
File metadata and controls
202 lines (185 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Super Admin Panel</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f4f4f9; color: #333; margin: 0; padding: 20px; }
.container { max-width: 1000px; margin: auto; background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); }
h1, h2, h3 { color: #0a2463; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-bottom: 20px;}
section { margin-top: 40px; }
#login-section, #admin-section { display: none; }
input, textarea, button { width: 100%; padding: 12px; margin-bottom: 12px; border-radius: 5px; border: 1px solid #ccc; box-sizing: border-box; font-size: 1rem; }
textarea { min-height: 250px; resize: vertical; font-family: 'Courier New', Courier, monospace; }
button { background-color: #00693f; color: white; border: none; cursor: pointer; font-weight: bold; transition: background-color 0.2s; }
button:hover { background-color: #004d2b; }
#logout-btn { background-color: #d9534f; width: auto; display: inline-block; padding: 8px 15px; margin-left: 15px; }
#logout-btn:hover { background-color: #c9302c; }
.list-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #eee; }
.list-item button { width: auto; font-size: 0.8rem; padding: 5px 10px; margin: 0 5px; }
.translation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
#cancel-blog-edit { background-color: #6c757d; }
</style>
</head>
<body>
<div class="container">
<h1>Super Admin Panel</h1>
<div id="login-section">
<h2>Login</h2><input type="email" id="email" placeholder="Email" /><input type="password" id="password" placeholder="Password" /><button id="login-btn">Login</button><p id="login-error" style="color: red"></p>
</div>
<div id="admin-section">
<p>Welcome, <strong id="admin-email"></strong>! <button id="logout-btn">Logout</button></p>
<section id="blog-management">
<h2 id="blog-form-title">Create New Blog Post</h2>
<form id="blog-form">
<input type="hidden" id="blog-post-id">
<input type="text" id="blog-author" placeholder="Author Name (e.g., Sandeep Biswal G)" required>
<input type="url" id="blog-thumbnailUrl" placeholder="Thumbnail Image URL" required>
<input type="text" id="blog-slug" placeholder="URL Slug (e.g., my-first-post)" required>
<p style="font-size:0.9rem; color:#666; margin-top:-10px;">This must be unique and contain no spaces.</p>
<div class="translation-grid">
<div>
<h3>English Version</h3>
<input type="text" id="blog-title-en" placeholder="English Title" required>
<textarea id="blog-meta-description-en" placeholder="English SEO Meta Description (~155 chars)" style="min-height: 80px;"></textarea>
<textarea id="blog-content-en" placeholder="English Content (HTML allowed)"></textarea>
</div>
<div>
<h3>Odia Version</h3>
<input type="text" id="blog-title-or" placeholder="Odia Title">
<textarea id="blog-meta-description-or" placeholder="Odia SEO Meta Description" style="min-height: 80px;"></textarea>
<textarea id="blog-content-or" placeholder="Odia Content (HTML allowed)"></textarea>
</div>
</div>
<button type="submit">Save Blog Post</button>
<button type="button" id="cancel-blog-edit" style="display:none;">Cancel Edit</button>
</form>
<div id="blog-post-list-container" style="margin-top: 30px;">
<h3>Existing Posts</h3>
<div id="blog-post-list">Loading...</div>
</div>
</section>
<section id="ad-management">
<h2>Ad Management</h2>
<form id="blog-ad-form">
<h3>Ad Code for In-Between Blog Paragraphs</h3>
<textarea id="in-post-ad-code" placeholder="Paste Google AdSense code here..."></textarea>
<button type="submit">Save Ad Code</button>
</form>
</section>
<!-- Your old game management section can go here if needed -->
</div>
</div>
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-firestore.js"></script>
<script>
const firebaseConfig = { apiKey: "AIzaSyCI8CEVsIm04yshvJVAZqQcElE_G-VaduQ", authDomain: "odia-games-visitor-counter.firebaseapp.com", projectId: "odia-games-visitor-counter" };
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth(), db = firebase.firestore();
auth.onAuthStateChanged(user => {
if (user) {
document.getElementById("login-section").style.display = "none";
document.getElementById("admin-section").style.display = "block";
document.getElementById("admin-email").textContent = user.email;
loadBlogPosts();
loadAdSettings();
} else {
document.getElementById("login-section").style.display = "block";
document.getElementById("admin-section").style.display = "none";
}
});
document.getElementById("login-btn").addEventListener("click", () => auth.signInWithEmailAndPassword(document.getElementById("email").value, document.getElementById("password").value).catch(e => alert(e.message)));
document.getElementById("logout-btn").addEventListener("click", () => auth.signOut());
document.getElementById('blog-title-en').addEventListener('input', (e) => {
if (!document.getElementById('blog-post-id').value) {
const slug = e.target.value.toLowerCase().trim().replace(/\s+/g, '-').replace(/[^\w-]+/g, '');
document.getElementById('blog-slug').value = slug;
}
});
document.getElementById("blog-form").addEventListener("submit", async (e) => {
e.preventDefault();
const postId = document.getElementById('blog-post-id').value;
const postData = {
author: document.getElementById('blog-author').value,
thumbnailUrl: document.getElementById('blog-thumbnailUrl').value,
slug: document.getElementById('blog-slug').value,
title_en: document.getElementById('blog-title-en').value,
content_en: document.getElementById('blog-content-en').value,
meta_description_en: document.getElementById('blog-meta-description-en').value,
title_or: document.getElementById('blog-title-or').value,
content_or: document.getElementById('blog-content-or').value,
meta_description_or: document.getElementById('blog-meta-description-or').value,
updatedAt: firebase.firestore.FieldValue.serverTimestamp()
};
try {
if (postId) {
await db.collection('posts').doc(postId).update(postData);
alert('Post updated successfully!');
} else {
postData.createdAt = firebase.firestore.FieldValue.serverTimestamp();
await db.collection('posts').add(postData);
alert('Post created successfully!');
}
resetBlogForm();
loadBlogPosts();
} catch (error) { alert("Error: " + error.message); }
});
async function loadBlogPosts() {
const listEl = document.getElementById("blog-post-list");
listEl.innerHTML = "Loading...";
const snapshot = await db.collection('posts').orderBy('createdAt', 'desc').get();
listEl.innerHTML = "";
snapshot.forEach(doc => {
const post = doc.data();
const div = document.createElement('div');
div.className = 'list-item';
div.innerHTML = `<span>${post.title_en}</span><div><button onclick="editPost('${doc.id}')">Edit</button><button onclick="deletePost('${doc.id}')" style="background-color:#d9534f;">Delete</button></div>`;
listEl.appendChild(div);
});
}
window.editPost = async (id) => {
const doc = await db.collection('posts').doc(id).get();
if (!doc.exists) return;
const post = doc.data();
document.getElementById('blog-post-id').value = id;
document.getElementById('blog-author').value = post.author || '';
document.getElementById('blog-thumbnailUrl').value = post.thumbnailUrl || '';
document.getElementById('blog-slug').value = post.slug || '';
document.getElementById('blog-title-en').value = post.title_en || '';
document.getElementById('blog-content-en').value = post.content_en || '';
document.getElementById('blog-meta-description-en').value = post.meta_description_en || '';
document.getElementById('blog-title-or').value = post.title_or || '';
document.getElementById('blog-content-or').value = post.content_or || '';
document.getElementById('blog-meta-description-or').value = post.meta_description_or || '';
document.getElementById('blog-form-title').textContent = 'Edit Blog Post';
document.getElementById('cancel-blog-edit').style.display = 'inline-block';
window.scrollTo({ top: 0, behavior: 'smooth' });
};
window.deletePost = async (id) => {
if (confirm('Are you sure you want to delete this post?')) {
await db.collection('posts').doc(id).delete();
loadBlogPosts();
}
};
function resetBlogForm() {
document.getElementById("blog-form").reset();
document.getElementById('blog-post-id').value = '';
document.getElementById('blog-form-title').textContent = 'Create New Blog Post';
document.getElementById('cancel-blog-edit').style.display = 'none';
}
document.getElementById('cancel-blog-edit').addEventListener('click', resetBlogForm);
document.getElementById('blog-ad-form').addEventListener('submit', async (e) => {
e.preventDefault();
const adCode = document.getElementById('in-post-ad-code').value;
await db.collection('settings').doc('blogSettings').set({ inPostAdCode: adCode }, { merge: true });
alert('Ad settings saved!');
});
async function loadAdSettings() {
const doc = await db.collection('settings').doc('blogSettings').get();
if (doc.exists) {
document.getElementById('in-post-ad-code').value = doc.data().inPostAdCode || '';
}
}
</script>
</body>
</html>