Kirby 3 Panel - last edited pages

Hey everyone,

in kirby 2 we had in our panel, on the home page, the field of the last edited pages.
Is this also possible in kirby 3? I haven’t found a solution yet.
Thank you for your answers :smile:

Kirby 2 Panel

Not out of the box, no.

But you could create a custom Panel section:

And in this section you would need to get the pages similar to this:

$site-index()->sortBy('modified', 'desc')->limit(5)

Hope this helps as a starting point.

1 Like

I created a (very bare bones) custom section to see how easy it is:

Maybe it helps you getting started.

7 Likes

Thank you, so much, guys :smile: That was the solution I was looking for. I have integrated the solution and it works perfectly :sunglasses:

1 Like

OK, the plugin works perfectly :smiley:
Only I would like to know how I can expand it so that the last edited pages display specifically for each user. I mean that each user will only see their own last edited pages. The pages of other users should not be displayed.
Thank you for your answers :smile:

1 Like

That will only work if you store that information somewhere. I had a plugin for Kirby 2 that stored each change in a .csv file via hooks, then you could retrieve the information from that file. My thought for Kirby 3 was storing that in a sqlite database.

(Kirby 2 stored such information in the user account file…)

Hi there,

here is a solution I created. I extended the plug-in from @thguenther and wrote a hook below it :smile: now it works

Kirby::plugin('medienbaecker/history', [
    	'sections' => [
    		'history' => [
    			'props' => [
    				'headline' => function($headline = "History") {
    					return $headline;
    				},
    				'limit' => function($limit = 10) {
    					return $limit;
    				}
    			],
    			'computed' => [
    				'latestPages' => function() {
    					$latestPages = array();
    					
    					$lasteditedpages = Db::select('lasteditedpages', '*', 'user LIKE "'.kirby()->user()->email().'" ORDER BY request_date DESC LIMIT 10');

    					foreach($lasteditedpages as $latestPage) {
    						$image = $latestPage->image();

    						$latestPages[] = [
    							'title' => $latestPage->title(),
    							'image' => $image,
    							'link' => $latestPage->link()
    						];
    					}

    					return $latestPages;
    				}
    			]
    		]
    	]
    ]);

    Kirby::plugin('mypage/historyhooks', [
    	'hooks' => [
            'page.update:after' => function ($newPage, $oldPage) {

            	$image = $newPage->image();

            	if (isset($image)) {
            		$imageUrl = $image->url();
            	}else{
            		$image = site()->image('placeholder.svg');
            		$imageUrl = $image->url();
            	}
            	

            	$lasteditedpages = Db::insert('lasteditedpages', [
    	        	'user' => kirby()->user()->email(),
    	        	'title' => $newPage->title(),
    	        	'image' => $imageUrl,
    	        	'link' => $newPage->panelUrl(),
    	        ]);        	

            }
        ]
    ]);

I have now updated the code from the hook again. Now there is also a database check.

           $image = $newPage->image();

        	if (isset($image)) {
        		$imageUrl = $image->url();
        	}else{
        		$image = site()->image('placeholder.svg');
        		$imageUrl = $image->url();
        	}

        	$select = Db::query('SELECT * FROM `lasteditedpages` WHERE user LIKE "'.kirby()->user()->email().'" ORDER BY `request_date` DESC');

        	$countArray = array();
        	$linkArray = array();

        	foreach ($select as $s) {
			  $countArray[] = $s->ID();
			  $linkArray[] = $s->link();
			}

			$count = count($countArray);

        	if ($count >= 10) {
        		
        		$delete = Db::query('DELETE FROM `lasteditedpages` WHERE user LIKE "'.kirby()->user()->email().'" ORDER BY `request_date` ASC LIMIT 1');

        	}	

        	$link = $linkArray[0];	        	
    		
    		if ($link != $newPage->panelUrl()) {
    			
    			$lasteditedpages = Db::insert('lasteditedpages', [
		        	'user' => kirby()->user()->email(),
		        	'title' => $newPage->title(),
		        	'image' => $imageUrl,
		        	'link' => $newPage->panelUrl(),
		        ]);

    		}

Awesome! I’m glad my code worked as a starting point.

A little tip that might help:
You don’t need to define two separate plugins. Just add the 'hooks' part after 'sections':

Kirby::plugin('your/history', [
    	'sections' => [
    	    	# Code for the section    	
    	],
    	'hooks'=> [
    	    	# Code for the hooks
    	]
]);
1 Like

@thguenther:

Can you please show, what I have to add to the site.yml blueprint of the K3 Starterkit to show something like you show in the hardcopy of the README.md file in the dashboard of the Panel.

I have added your plugin in the project, but see nothing in the dashboard.

Thank you!

HeinerEF

@anon77445132

# site/blueprints/site.yml

title: Website
columns:
  - width: 1/2
    sections:
      pages: true
  - width: 1/2
    sections:
      history:
        headline: Deine letzten Änderungen

Thank you very much. This runs.

I had not found this within your README.md from https://github.com/medienbaecker/kirby-history

@anon77445132 This plugin is still WIP—I just wanted to provide a simple example to help OP get started. If you look at the code you’ll see it’s very bare bones. Please feel free to create a fork to extend functionality/documentation.

1 Like

My entire code for that :

  • Cool icons
  • Users, date and time modified

index.css

.k-history-section .latest-pages a {
	display: block;
	background: white;
	line-height: 1.25em;
	box-shadow: 0 2px 5px rgba(22,23,26,.05);
	margin-bottom: 2px;
        display: -webkit-flex;
	display: flex;
	-webkit-flex-flow: row wrap;
	flex-flow: row wrap;
	-webkit-justify-content: space-between;
	justify-content:space-between;
}
.k-history-section .latest-pages a span{
       font-size:14px;
       padding: .5rem .75rem;
       text-overflow: ellipsis;
       white-space: nowrap;
       overflow: hidden;
}
.k-history-section .latest-pages a span:nth-child(2){
       flex:1
}
.k-history-section .latest-pages a div:nth-child(4){
       width:10em;
       text-align:right;
}
.k-history-section .latest-pages a div{
       padding: .5rem .75rem;
       color:#777;
       font-size:12px;
       line-height:21px
}
.k-history-section .latest-pages .k-icon {
       width: 38px;
       height: 38px;
}
.k-history-section .latest-pages .k-icon svg {
       opacity: .5;
} 

index.js

panel.plugin('medienbaecker/history', {
	sections: {
		history: {
			data: function () {
				return {
					headline: null,
					latestPages: []
				}
			},
			created: function() {
				this.load().then(response => {
					this.headline = response.headline;
					this.latestPages = response.latestPages;
				});
			},
			template: `
				<section class="k-history-section">
					<header class="k-section-header">
						<h2 class="k-headline">{{ headline }}</h2>
					</header>
					<div class="latest-pages">
						
                        <a v-for="page in latestPages" :href="page.link"><span aria-hidden="true" data-back="pattern" class="k-icon k-icon-circle-filled"><svg viewBox="0 0 16 16" style="color: rgb(197, 201, 198);"><use xlink:href="#icon-circle-filled"></use></svg></span><span>{{ page.title }}</span><div>{{ page.user }}</div><div>{{ page.last }}</div></a>
        
					</div>
				</section>
			`
			}
	}
});

index.php

<?php

Kirby::plugin('medienbaecker/history', [
	'sections' => [
		'history' => [
			'props' => [
				'headline' => function($headline = "History") {
					return $headline;
				},
				'limit' => function($limit = 5) {
					return $limit;
				}
			],
			'computed' => [
				'latestPages' => function() {
					$latestPages = array();
					foreach(site()->index()->sortBy('modified', 'desc')->limit($this->limit()) as $latestPage) {
						$latestPages[] = [
							'title' => $latestPage->title()->value(),
							'link' => $latestPage->panelUrl(),
                            'last' => $latestPage->modified('d/m/y  H:i'),
                            'user' => kirby()->user()->name()->value(),
						];
					}
					return $latestPages;
				}
			]
		]
	]
]);
4 Likes