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.

6 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