Last changes

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

cmb
Posts: 13538
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Last changes

Post by cmb » Thu Feb 18, 2021 12:08 am

Tata wrote:
Fri Feb 12, 2021 8:53 am
I just can't find how to set the exact page related value of the $last_update. The code above returns the same date (1970-01-01 01:00:00) for each changed page.
If the index of the page is known, say stored in $index, you can use $pd_router->find_page($index)['last_update'] to get the last update date of the page.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3279
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Last changes

Post by Tata » Thu Feb 18, 2021 2:07 pm

I tried to add into the index.php

Code: Select all

...
    $pageData = $pd_router->find_all();
    $index = $pd_router->find_page($index)['last_edit']; /***/
    uasort($pageData, function ($a, $b) {
        return $b['last_edit'] - $a['last_edit'];
    });...
and

Code: Select all

	    	foreach ($pages as $page) {
	      $html .= '<li><a href="' . "$sn?$u[$page]" . '">' . $h[$page] . ' - '.$index.'</a></li>';
The result is:
1. Start - 01.01.1970
2. Templates - 01.01.1970


In the content.htm, there is e.g.

Code: Select all

<html><head><title>Content file</title>
<?php
...
'last_edit'=>'1322055182',
...
<!--XH_ml1:Start-->
<?php
$page_data[]=array(
'url'=>'Start',
'last_edit'=>'1613328024',
...
<!--XH_ml1:Templates-->
<?php
$page_data[]=array(
'url'=>'Templates',
'last_edit'=>'1613120230',
...
So I assume that in the $html = ... shall the very exact 10-digits value be inserted from $page_data array.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

roze
Posts: 239
Joined: Tue Jun 03, 2008 7:13 am
Location: NL
Contact:

Re: Last changes

Post by roze » Sat Feb 20, 2021 6:03 pm

I've made the changes in the index file: now it looks like this

Code: Select all

Laatste wijzigingen
Colofon -
Minigids -
Inhoud Minigids -
Hymer S -
there is a strike added but no date


www.beremooiehymers.nl
Rob Zeijen,

Valkenswaard (NL)

olape
Posts: 1646
Joined: Fri Mar 13, 2015 8:47 am
Contact:

Re: Last changes

Post by olape » Sat Feb 20, 2021 6:55 pm

for the userfuncs.php

Code: Select all

/**
 * @copyright 2016 Christoph M. Becker
 * @copyright 2016 (for some additions) by svasti
 * 2018 small modifications by olape
 * @license   GPLv3
 */
/*
	{{{recently_changed()}}}, {{{recently_changed(10)}}}, {{{PLUGIN:recently_changed(10,24);}}}, {{{PLUGIN:recently_changed('',24);}}}
	oder im Template:
	<?php echo recently_changed()?>, <?php echo recently_changed(10)?>, <?php echo recently_changed(10,24)?>, <?php echo recently_changed('',24)?>
*/

function recently_changed($count = 5, $length = 28)
{
	global $pd_router, $cf;

	$pageData = $pd_router->find_all();
	uasort($pageData, function ($a, $b) {
		return $b['last_edit'] - $a['last_edit'];
	});

	$pages = array();
	$i = 0;
	foreach (array_keys($pageData) as $page) {
		if ($i < $count) {
			if (!hide($page)) {
				$timestamp = $pageData[$page]['last_edit'];
				//$date = XH_formatDate($timestamp); // date('Y-m-d', $timestamp);
				$date = date('d.m.Y', $timestamp);
				$pages[$date][] = $page;
			$i++;
			}
		} else {
			break;
		}
	}

	global $sn, $h, $u;

	$html = '<dl class="recently_changed">';
	foreach ($pages as $date => $group) {
		$html .= '<dt>' . $date . '</dt>';
		foreach ($group as $page) {
			$linktext = str_replace($cf['uri']['seperator'], ' ', $u[$page]);
			$linktext_length = utf8_strlen($linktext);
			if($linktext_length > $length) {
				$linktext = utf8_substr($linktext, -$length);
				$stringpos = utf8_strpos($linktext, ' ');
				$linktext = utf8_substr($linktext, (-$length + $stringpos));
			}
			$html .= '<dd><a href="' . "$sn?$u[$page]" . '">- ' . $linktext . '</a></dd>';
		}
	}
	$html .= '</dl>';
	return $html;
}
Result is like here. Top right, the info icon. Is called with

Code: Select all

{{{recently_changed('7', '28')}}}
https://olaf.penschke.net/

Post Reply