]> git.bts.cx Git - cx.git/commitdiff
Better paths for images and editor links
authorBen Sherratt <redacted>
Sat, 4 Jul 2026 19:37:58 +0000 (20:37 +0100)
committerBen Sherratt <redacted>
Sat, 4 Jul 2026 19:50:17 +0000 (20:50 +0100)
cx/lib/images.php
cx/lib/markdown.php
cx/lib/posts.php
cx/templates/admin/pages/main.php
cx/templates/public/pages/base.php
cx/templates/public/pages/list.php

index ea29f747938ca936df675143564bf0a03f37aba5..358a1ba7f5e5cea6a5466c60a96ce36848b4f178 100644 (file)
@@ -17,6 +17,11 @@ class Image {
                $this->alt_text = $dict['image_alt_text'];
                $this->url = $this->uid . '.' . $dict['image_type'];
        }
+
+       public function get_permalink_path() {
+               $permalink = '/data/images/' . $this->url;
+               return $permalink;
+       }
 }
 
 function cx_images_add_image($site_id, $alt_text, $image_path, $image_original_filename) {
index aab58d59e005f0d5006e7918cbc2cbb4cbd20b74..b79fb85a35f11874aa340118e42c621f022a1904 100644 (file)
@@ -20,14 +20,12 @@ class ExtendedParsedown extends Parsedown {
                                return;
                        }
 
-                       $permalink = '/data/images/' . $image->url;
-
                        return array(
                                'extent' => strlen($matches[0]) + 1, 
                                'element' => array(
                                        'name' => 'img',
                                        'attributes' => array(
-                                               'src' => cx_url_site($permalink),
+                                               'src' => cx_url_site($image->get_permalink_path()),
                                                'alt' => $image->alt_text,
                                        ),
                                ),
index 326d81c470585f90848e59d57b2ab2ffcbd339d8..4d122dfe642ff2fb087af6a49b9c818138b2a4fc 100644 (file)
@@ -46,8 +46,11 @@ class Post {
        }
 
        public function get_permalink_path() {
-               $post_permalink = $this->is_page ? '/' . $this->slug : '/' . date('Y', $this->date) . '/' . date('m', $this->date) . '/' . $this->slug;
-               return $post_permalink;
+               $permalink = '/' . $this->slug;
+               if ($this->is_page == false) {
+                       $permalink = '/' . date('Y', $this->date) . '/' . date('m', $this->date) . '/' . $this->slug;
+               }
+               return $permalink;
        }
 
        public function get_metadata() {
index 14ea9c40069c6d0f8e6a70a54fb972d41128bccc..f9ab483143643c2627ae0a89aa3abc360e719995 100644 (file)
@@ -4,9 +4,9 @@
 <table>
 <?php foreach (cx_posts_get(include_drafts: true) as $post): ?>
 <tr>
- <td class="fill"><a href="<?= cx_url_admin('/posts/edit?id=' . $post->id); ?>"><?= $post->title ?></a></td>
- <td class="hug"><a href="<?= cx_url_admin('/posts/edit?id=' . $post->id); ?>">Edit</a></td>
- <td class="hug"><a href="<?= cx_url_admin('/posts/delete?id=' . $post->id); ?>">Delete</a></td>
+ <td class="fill"><a href="<?= cx_url_site($post->get_permalink_path()) ?>"><?= $post->title ?></a></td>
+ <td class="hug"><a href="<?= cx_url_admin('/posts/edit?id=' . $post->id) ?>">Edit</a></td>
+ <td class="hug"><a href="<?= cx_url_admin('/posts/delete?id=' . $post->id) ?>">Delete</a></td>
 </tr>
 <?php endforeach; ?>
 </table>
@@ -15,9 +15,9 @@
 <table>
 <?php foreach (cx_pages_get(navigation_only: false, include_drafts: true) as $post): ?>
 <tr>
- <td class="fill"><a href="<?= cx_url_admin('/posts/edit?id=' . $post->id); ?>"><?= $post->title ?></a></td>
- <td class="hug"><a href="<?= cx_url_admin('/posts/edit?id=' . $post->id); ?>">Edit</a></td>
- <td class="hug"><a href="<?= cx_url_admin('/posts/delete?id=' . $post->id); ?>">Delete</a></td>
+ <td class="fill"><a href="<?= cx_url_site($post->get_permalink_path()) ?>"><?= $post->title ?></a></td>
+ <td class="hug"><a href="<?= cx_url_admin('/posts/edit?id=' . $post->id) ?>">Edit</a></td>
+ <td class="hug"><a href="<?= cx_url_admin('/posts/delete?id=' . $post->id) ?>">Delete</a></td>
 </tr>
 <?php endforeach; ?>
 </table>
@@ -26,9 +26,9 @@
 <table>
 <?php foreach (cx_images_get() as $image): ?>
 <tr>
- <td class="fill"><a href="<?= $image->url ?>"><?= $image->url ?></a></td>
- <td class="hug"><a href="<?= cx_url_admin('/images/edit?id=' . $image->id); ?>">Edit</a></td>
- <td class="hug"><a href="<?= cx_url_admin('/images/delete?id=' . $image->id); ?>">Delete</a></td>
+ <td class="fill"><a href="<?= cx_url_site($image->get_permalink_path()) ?>"><?= $image->url ?></a></td>
+ <td class="hug"><a href="<?= cx_url_admin('/images/edit?id=' . $image->id) ?>">Edit</a></td>
+ <td class="hug"><a href="<?= cx_url_admin('/images/delete?id=' . $image->id) ?>">Delete</a></td>
 </tr>
 <?php endforeach; ?>
 </table>
index 5caac0dd596660e950409972449f6427822913bd..7629caed06ba1e4648e9ca5583527208b2bfe8a1 100644 (file)
@@ -52,7 +52,7 @@
 <li><a href="<?= cx_url('/'); ?>">Home</a></li>
 
 <?php foreach (cx_pages_get() as $page): ?>
-<li><a href="<?= cx_url('/' . $page->slug); ?>"><?= $page->title ?></a></li>
+<li><a href="<?= cx_url($page->get_permalink_path()); ?>"><?= $page->title ?></a></li>
 <?php endforeach; ?>
 </ul>
 
index 0f02a71fd33b5d806743a2f8822454877b3d5ceb..3069f7202e23958880860a271ecbee08500ba90d 100644 (file)
@@ -17,7 +17,7 @@
 
        <p>
                <?php $number_of_pages = ceil(cx_posts_count() / $posts_per_page); ?>
-               <?php if($page_number + 1 < $number_of_pages): ?><a href="<?= cx_url_page($page_number, 1) ?>">Older Posts</a><?php endif; ?>
-               <?php if($page_number > 0): ?><a href="<?= cx_url_page($page_number, -1) ?>">Newer Posts</a><?php endif; ?>
+               <?php if($page_number + 1 < $number_of_pages): ?><a href="<?= cx_url_page($page_number, 1) ?>">&larr; Older Posts</a><?php endif; ?>
+               <?php if($page_number > 0): ?><a href="<?= cx_url_page($page_number, -1) ?>">Newer Posts &rarr;</a><?php endif; ?>
        </p>
 </main>