svalavuo 1 месяц назад
Родитель
Сommit
d89edbbfb7
8 измененных файлов с 332 добавлено и 60 удалено
  1. 54 0
      .htaccess
  2. 3 3
      admin/upload_image.php
  3. 9 0
      includes/publication.php
  4. 5 0
      languages/en.php
  5. 5 0
      languages/fi.php
  6. 86 56
      public/index.php
  7. 169 0
      public/journal.php
  8. 1 1
      setup.sql

+ 54 - 0
.htaccess

@@ -0,0 +1,54 @@
+# Increase PHP upload limits
+php_value upload_max_filesize 20M
+php_value post_max_size 25M
+php_value memory_limit 256M
+php_value max_execution_time 300
+php_value max_input_time 300
+
+# Enable compression
+<IfModule mod_deflate.c>
+    AddOutputFilterByType DEFLATE text/plain
+    AddOutputFilterByType DEFLATE text/html
+    AddOutputFilterByType DEFLATE text/xml
+    AddOutputFilterByType DEFLATE text/css
+    AddOutputFilterByType DEFLATE application/xml
+    AddOutputFilterByType DEFLATE application/xhtml+xml
+    AddOutputFilterByType DEFLATE application/rss+xml
+    AddOutputFilterByType DEFLATE application/javascript
+    AddOutputFilterByType DEFLATE application/x-javascript
+</IfModule>
+
+# Set caching headers
+<IfModule mod_expires.c>
+    ExpiresActive On
+    ExpiresByType image/jpg "access plus 1 year"
+    ExpiresByType image/jpeg "access plus 1 year"
+    ExpiresByType image/gif "access plus 1 year"
+    ExpiresByType image/png "access plus 1 year"
+    ExpiresByType text/css "access plus 1 month"
+    ExpiresByType application/pdf "access plus 1 month"
+    ExpiresByType text/javascript "access plus 1 month"
+    ExpiresByType application/javascript "access plus 1 month"
+    ExpiresByType application/x-shockwave-flash "access plus 1 month"
+    ExpiresByType image/x-icon "access plus 1 year"
+    ExpiresDefault "access plus 2 days"
+</IfModule>
+
+# Security headers
+<IfModule mod_headers.c>
+    Header always set X-Content-Type-Options nosniff
+    Header always set X-Frame-Options DENY
+    Header always set X-XSS-Protection "1; mode=block"
+</IfModule>
+
+# Hide .htaccess file
+<Files .htaccess>
+    Order allow,deny
+    Deny from all
+</Files>
+
+# Prevent access to config files
+<Files ~ "\.(ini|log|conf)$">
+    Order allow,deny
+    Deny from all
+</Files>

+ 3 - 3
admin/upload_image.php

@@ -116,10 +116,10 @@ echo json_encode(['success' => false, 'error' => 'Invalid request']);
  * Validate uploaded image file
  */
 function validateImageFile($file) {
-    // Check file size (5MB max)
-    $maxSize = 5 * 1024 * 1024; // 5MB
+    // Check file size (20MB max)
+    $maxSize = 20 * 1024 * 1024; // 20MB
     if ($file['size'] > $maxSize) {
-        return ['valid' => false, 'error' => 'File too large. Maximum size is 5MB'];
+        return ['valid' => false, 'error' => 'File too large. Maximum size is 20MB'];
     }
     
     // Check file type

+ 9 - 0
includes/publication.php

@@ -271,7 +271,16 @@ class Publication {
         $stats['published'] = $this->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'published'")['count'];
         $stats['draft'] = $this->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'draft'")['count'];
         $stats['archived'] = $this->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'archived'")['count'];
+        $stats['static'] = $this->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'static'")['count'];
         
         return $stats;
     }
+    
+    /**
+     * Get static main page
+     */
+    public function getStaticPage() {
+        $sql = "SELECT * FROM publications WHERE status = 'static' ORDER BY created_at DESC LIMIT 1";
+        return $this->db->fetch($sql);
+    }
 }

+ 5 - 0
languages/en.php

@@ -467,4 +467,9 @@ return [
     'filter_all' => 'All',
     'filter' => 'Filter',
     'clear' => 'Clear',
+    
+    // Journal functionality
+    'journal' => 'Journal',
+    'view_journal' => 'View Journal',
+    'journal_description' => 'Welcome to the journal. Here you can find all the latest posts and articles.',
 ];

+ 5 - 0
languages/fi.php

@@ -469,4 +469,9 @@ return [
     'filter_all' => 'Kaikki',
     'filter' => 'Suodata',
     'clear' => 'Tyhjennä',
+    
+    // Journal functionality
+    'journal' => 'Päiväkirja',
+    'view_journal' => 'Näytä päiväkirja',
+    'journal_description' => 'Tervetuloa päiväkirjaan. Tästä löydät kaikki viimeisimmät kirjoitukset ja artikkelit.',
 ];

+ 86 - 56
public/index.php

@@ -18,7 +18,10 @@ $page = max(1, (int)($_GET['page'] ?? 1));
 $limit = 10;
 $offset = ($page - 1) * $limit;
 
-// Get publications
+// Check for static main page first
+$staticPage = $publication->getStaticPage();
+
+// Get publications for journal view
 if ($search) {
     $publications = $publication->search($search, 'published');
     $totalPublications = count($publications);
@@ -50,6 +53,7 @@ $totalPages = ceil($totalPublications / $limit);
             <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
             <nav class="main-nav">
                 <a href="index.php"><?php echo t('nav_home'); ?></a>
+                <a href="journal.php"><?php echo t('journal'); ?></a>
                 <a href="categories.php"><?php echo t('nav_categories'); ?></a>
                 <a href="search.php"><?php echo t('nav_search'); ?></a>
             </nav>
@@ -91,67 +95,93 @@ $totalPages = ceil($totalPublications / $limit);
             </aside>
 
             <main class="main-content">
-                <?php if ($search): ?>
-                    <h2><?php echo t('search_results'); ?> "<?php echo htmlspecialchars($search); ?>"</h2>
-                    <p class="results-count"><?php echo t('found_count', ['count' => $totalPublications]); ?></p>
-                <?php elseif ($category): ?>
-                    <h2><?php echo t('category'); ?>: <?php echo htmlspecialchars($category); ?></h2>
-                    <p class="results-count"><?php echo $totalPublications; ?> <?php echo t('publication_count'); ?></p>
+                <?php if ($staticPage && !$search && !$category): ?>
+                    <!-- Static main page content -->
+                    <article class="static-page">
+                        <h1><?php echo htmlspecialchars($staticPage['title']); ?></h1>
+                        
+                        <?php if ($staticPage['summary']): ?>
+                            <div class="summary"><?php echo $staticPage['summary']; ?></div>
+                        <?php endif; ?>
+                        
+                        <div class="content">
+                            <?php echo $staticPage['content']; ?>
+                        </div>
+                        
+                        <div class="meta">
+                            <span class="author"><?php echo t('by_author', ['author' => htmlspecialchars($staticPage['author'])]); ?></span>
+                            <span class="date"><?php echo t('on_date', ['date' => date('F j, Y', strtotime($staticPage['created_at']))]); ?></span>
+                        </div>
+                    </article>
+                    
+                    <div class="journal-link">
+                        <a href="journal.php" class="btn"><?php echo t('view_journal'); ?></a>
+                    </div>
+                    
                 <?php else: ?>
-                    <h2><?php echo t('latest_publications'); ?></h2>
-                <?php endif; ?>
+                    <!-- Publications list (journal view) -->
+                    <?php if ($search): ?>
+                        <h2><?php echo t('search_results'); ?> "<?php echo htmlspecialchars($search); ?>"</h2>
+                        <p class="results-count"><?php echo t('found_count', ['count' => $totalPublications]); ?></p>
+                    <?php elseif ($category): ?>
+                        <h2><?php echo t('category'); ?>: <?php echo htmlspecialchars($category); ?></h2>
+                        <p class="results-count"><?php echo $totalPublications; ?> <?php echo t('publication_count'); ?></p>
+                    <?php else: ?>
+                        <h2><?php echo t('latest_publications'); ?></h2>
+                    <?php endif; ?>
 
-                <?php if (empty($publications)): ?>
-                    <p><?php echo t('no_publications_found'); ?></p>
-                <?php else: ?>
-                    <div class="publication-list">
-                        <?php foreach ($publications as $pub): ?>
-                            <article class="publication-summary">
-                                <h3>
-                                    <a href="publication.php?id=<?php echo $pub['id']; ?>">
-                                        <?php echo htmlspecialchars($pub['title']); ?>
-                                    </a>
-                                </h3>
-                                
-                                <?php if ($pub['summary']): ?>
-                                    <p class="summary"><?php echo htmlspecialchars($pub['summary']); ?></p>
-                                <?php endif; ?>
-                                
-                                <div class="meta">
-                                    <span class="author"><?php echo t('by_author', ['author' => htmlspecialchars($pub['author'])]); ?></span>
-                                    <span class="date"><?php echo t('on_date', ['date' => date('F j, Y', strtotime($pub['created_at']))]); ?></span>
-                                    <?php if ($pub['categories']): ?>
-                                        <span class="categories">
-                                            <?php foreach (explode(',', $pub['categories']) as $cat): ?>
-                                                <a href="index.php?category=<?php echo urlencode(trim($cat)); ?>" class="category-tag">
-                                                    <?php echo htmlspecialchars(trim($cat)); ?>
-                                                </a>
-                                            <?php endforeach; ?>
-                                        </span>
+                    <?php if (empty($publications)): ?>
+                        <p><?php echo t('no_publications_found'); ?></p>
+                    <?php else: ?>
+                        <div class="publication-list">
+                            <?php foreach ($publications as $pub): ?>
+                                <article class="publication-summary">
+                                    <h3>
+                                        <a href="publication.php?id=<?php echo $pub['id']; ?>">
+                                            <?php echo htmlspecialchars($pub['title']); ?>
+                                        </a>
+                                    </h3>
+                                    
+                                    <?php if ($pub['summary']): ?>
+                                        <p class="summary"><?php echo htmlspecialchars($pub['summary']); ?></p>
                                     <?php endif; ?>
-                                </div>
-                            </article>
-                        <?php endforeach; ?>
-                    </div>
+                                    
+                                    <div class="meta">
+                                        <span class="author"><?php echo t('by_author', ['author' => htmlspecialchars($pub['author'])]); ?></span>
+                                        <span class="date"><?php echo t('on_date', ['date' => date('F j, Y', strtotime($pub['created_at']))]); ?></span>
+                                        <?php if ($pub['categories']): ?>
+                                            <span class="categories">
+                                                <?php foreach (explode(',', $pub['categories']) as $cat): ?>
+                                                    <a href="index.php?category=<?php echo urlencode(trim($cat)); ?>" class="category-tag">
+                                                        <?php echo htmlspecialchars(trim($cat)); ?>
+                                                    </a>
+                                                <?php endforeach; ?>
+                                            </span>
+                                        <?php endif; ?>
+                                    </div>
+                                </article>
+                            <?php endforeach; ?>
+                        </div>
 
-                    <?php if (!$search && !$category && $totalPages > 1): ?>
-                        <div class="pagination">
-                            <?php if ($page > 1): ?>
-                                <a href="?page=<?php echo $page - 1; ?>" class="pagination-link">« Previous</a>
-                            <?php endif; ?>
-
-                            <?php for ($i = 1; $i <= $totalPages; $i++): ?>
-                                <?php if ($i == $page): ?>
-                                    <span class="pagination-current"><?php echo $i; ?></span>
-                                <?php else: ?>
-                                    <a href="?page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
+                        <?php if (!$search && !$category && $totalPages > 1): ?>
+                            <div class="pagination">
+                                <?php if ($page > 1): ?>
+                                    <a href="?page=<?php echo $page - 1; ?>" class="pagination-link">« Previous</a>
                                 <?php endif; ?>
-                            <?php endfor; ?>
 
-                            <?php if ($page < $totalPages): ?>
-                                <a href="?page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
-                            <?php endif; ?>
-                        </div>
+                                <?php for ($i = 1; $i <= $totalPages; $i++): ?>
+                                    <?php if ($i == $page): ?>
+                                        <span class="pagination-current"><?php echo $i; ?></span>
+                                    <?php else: ?>
+                                        <a href="?page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
+                                    <?php endif; ?>
+                                <?php endfor; ?>
+
+                                <?php if ($page < $totalPages): ?>
+                                    <a href="?page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
+                                <?php endif; ?>
+                            </div>
+                        <?php endif; ?>
                     <?php endif; ?>
                 <?php endif; ?>
             </main>

+ 169 - 0
public/journal.php

@@ -0,0 +1,169 @@
+<?php
+// Start session for language preference
+session_start();
+
+require_once '../includes/config.php';
+require_once '../includes/database.php';
+require_once '../includes/publication.php';
+require_once '../includes/translation.php';
+
+// Translation system is auto-initialized when translation.php is included
+
+$publication = new Publication();
+
+// Get search query
+$search = $_GET['search'] ?? '';
+$category = $_GET['category'] ?? '';
+$page = max(1, (int)($_GET['page'] ?? 1));
+$limit = 10;
+$offset = ($page - 1) * $limit;
+
+// Get publications
+if ($search) {
+    $publications = $publication->search($search, 'published');
+    $totalPublications = count($publications);
+} elseif ($category) {
+    $publications = $publication->getByCategory($category, 'published');
+    $totalPublications = count($publications);
+} else {
+    $publications = $publication->getAll('published', $limit, $offset);
+    $totalPublications = $publication->db->fetch("SELECT COUNT(*) as count FROM publications WHERE status = 'published'")['count'];
+}
+
+// Get categories for sidebar
+$categories = $publication->getCategories();
+
+// Calculate pagination
+$totalPages = ceil($totalPublications / $limit);
+?>
+<!DOCTYPE html>
+<html lang="<?php echo Translation::getCurrentLang(); ?>">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title><?php echo t('journal'); ?> - <?php echo SITE_TITLE; ?></title>
+    <link rel="stylesheet" href="../css/style.css">
+</head>
+<body>
+    <header class="site-header">
+        <div class="container">
+            <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
+            <nav class="main-nav">
+                <a href="index.php"><?php echo t('nav_home'); ?></a>
+                <a href="journal.php" class="active"><?php echo t('journal'); ?></a>
+                <a href="categories.php"><?php echo t('nav_categories'); ?></a>
+                <a href="search.php"><?php echo t('nav_search'); ?></a>
+            </nav>
+            <?php echo Translation::getLanguageSwitcher('journal.php'); ?>
+        </div>
+    </header>
+
+    <div class="container">
+        <div class="content-layout">
+            <aside class="sidebar">
+                <div class="sidebar-section">
+                    <h3><?php echo t('search'); ?></h3>
+                    <form method="get" class="search-form">
+                        <input type="text" name="search" placeholder="<?php echo t('search_placeholder'); ?>" 
+                               value="<?php echo htmlspecialchars($search); ?>">
+                        <button type="submit" class="btn btn-sm"><?php echo t('search'); ?></button>
+                    </form>
+                </div>
+
+                <div class="sidebar-section">
+                    <h3><?php echo t('categories'); ?></h3>
+                    <ul class="category-list">
+                        <li>
+                            <a href="journal.php" <?php echo empty($category) ? 'class="active"' : ''; ?>>
+                                <?php echo t('all_categories'); ?>
+                            </a>
+                        </li>
+                        <?php foreach ($categories as $cat): ?>
+                            <li>
+                                <a href="journal.php?category=<?php echo urlencode($cat['name']); ?>" 
+                                   <?php echo $category === $cat['name'] ? 'class="active"' : ''; ?>>
+                                    <?php echo htmlspecialchars($cat['name']); ?>
+                                    <span class="count">(<?php echo $cat['publication_count']; ?>)</span>
+                                </a>
+                            </li>
+                        <?php endforeach; ?>
+                    </ul>
+                </div>
+            </aside>
+
+            <main class="main-content">
+                <?php if ($search): ?>
+                    <h2><?php echo t('search_results'); ?> "<?php echo htmlspecialchars($search); ?>"</h2>
+                    <p class="results-count"><?php echo t('found_count', ['count' => $totalPublications]); ?></p>
+                <?php elseif ($category): ?>
+                    <h2><?php echo t('category'); ?>: <?php echo htmlspecialchars($category); ?></h2>
+                    <p class="results-count"><?php echo $totalPublications; ?> <?php echo t('publication_count'); ?></p>
+                <?php else: ?>
+                    <h2><?php echo t('journal'); ?></h2>
+                    <p class="journal-description"><?php echo t('journal_description'); ?></p>
+                <?php endif; ?>
+
+                <?php if (empty($publications)): ?>
+                    <p><?php echo t('no_publications_found'); ?></p>
+                <?php else: ?>
+                    <div class="publication-list">
+                        <?php foreach ($publications as $pub): ?>
+                            <article class="publication-summary">
+                                <h3>
+                                    <a href="publication.php?id=<?php echo $pub['id']; ?>">
+                                        <?php echo htmlspecialchars($pub['title']); ?>
+                                    </a>
+                                </h3>
+                                
+                                <?php if ($pub['summary']): ?>
+                                    <p class="summary"><?php echo htmlspecialchars($pub['summary']); ?></p>
+                                <?php endif; ?>
+                                
+                                <div class="meta">
+                                    <span class="author"><?php echo t('by_author', ['author' => htmlspecialchars($pub['author'])]); ?></span>
+                                    <span class="date"><?php echo t('on_date', ['date' => date('F j, Y', strtotime($pub['created_at']))]); ?></span>
+                                    <?php if ($pub['categories']): ?>
+                                        <span class="categories">
+                                            <?php foreach (explode(',', $pub['categories']) as $cat): ?>
+                                                <a href="journal.php?category=<?php echo urlencode(trim($cat)); ?>" class="category-tag">
+                                                    <?php echo htmlspecialchars(trim($cat)); ?>
+                                                </a>
+                                            <?php endforeach; ?>
+                                        </span>
+                                    <?php endif; ?>
+                                </div>
+                            </article>
+                        <?php endforeach; ?>
+                    </div>
+
+                    <?php if (!$search && !$category && $totalPages > 1): ?>
+                        <div class="pagination">
+                            <?php if ($page > 1): ?>
+                                <a href="?page=<?php echo $page - 1; ?>" class="pagination-link">« Previous</a>
+                            <?php endif; ?>
+
+                            <?php for ($i = 1; $i <= $totalPages; $i++): ?>
+                                <?php if ($i == $page): ?>
+                                    <span class="pagination-current"><?php echo $i; ?></span>
+                                <?php else: ?>
+                                    <a href="?page=<?php echo $i; ?>" class="pagination-link"><?php echo $i; ?></a>
+                                <?php endif; ?>
+                            <?php endfor; ?>
+
+                            <?php if ($page < $totalPages): ?>
+                                <a href="?page=<?php echo $page + 1; ?>" class="pagination-link">Next »</a>
+                            <?php endif; ?>
+                        </div>
+                    <?php endif; ?>
+                <?php endif; ?>
+            </main>
+        </div>
+    </div>
+
+    <footer class="site-footer">
+        <div class="container">
+            <p><a href="/admin/" style="text-decoration:none">&copy;</a> <?php echo date('Y'); ?> <?php echo SITE_TITLE; ?>. All rights reserved.</p>
+        </div>
+    </footer>
+</body>
+</html>

+ 1 - 1
setup.sql

@@ -11,7 +11,7 @@ CREATE TABLE publications (
     content TEXT NOT NULL,
     summary VARCHAR(500),
     author VARCHAR(100) NOT NULL,
-    status ENUM('draft', 'published', 'archived') DEFAULT 'draft',
+    status ENUM('draft', 'published', 'archived', 'static') DEFAULT 'draft',
     created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
     updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
     published_at TIMESTAMP NULL DEFAULT NULL,