HowTo: Use a special sitemap, for admins/panel user with many links, e.g. for former WordPress-user

Comments:

  • I hope it may be useful for former WordPress-user, who like to view all uploaded medias at one place.
  • The source code of the following is based on Kirby version 2.x.

View as guest

View as admins/panel user

(!click two times in this picture to grow it here!)

HowTo

Remark:

The following is like a cookbook!
You may want to change some parts of the following, to fit your needs. Feel free!
Hint: For the first try, don’t change anything and follow this description β€œstep for step”!

Step 1:

  • Add a new directory in your /content directory.
  • Name it β€œ99-websitemap” (later you can change the number β€œ99”, if you need or want, or delete β€œ99-” to have an β€œinvisible” webpage; don’t name it β€œsitemap”, which you may need for the file β€œsitemap.xml”; later change the name in the main menu by using the panel)
  • In this directory add an empty file with the name β€œwebsitemap.txt”

Step 2:

  • Add a new file with the name β€œwebsitemap.php” in the directory β€œ/site/templates”
  • This new file should look like:

<?php snippet('header') ?>
<?php $showchanges = 8; // show only changes in the last $showchanges days ?>
<?php $referencetime = date('U') - $showchanges*24*60*60; ?>
  <main class="main" role="main">
    <div class="text">
      <h1><?php echo html($page->title()) ?><?php if($user = $site->user()): // user is logged in ?><?php if($user->hasPanelAccess()): ?><a href="<?php echo $site->url() ?>/panel/#/pages/show/<?php echo $page->uri() ?>/p:1" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="Edit site data (in new window / tab)" class="admineditlink"><sup class="fa fa-cog admincolor1"></sup></a><?php endif ?><?php endif ?></h1>
      <?php echo kirbytext($page->text()) ?>

<?php if($user = $site->user()): // user is logged in ?>
      <p class="internally1"><strong>Attention!</strong><br>Because you are logged in, you will see <strong>additional</strong> entries, informations (e.g. for all pages with changes in the last <?php echo $showchanges ?> days the last modification date is indicated!) and links, which "normal" site visitors <strong>cannot see</strong>!<br>If you want, you can <strong>log out</strong> and then go to this sitemap <strong>as a guest</strong> again!<br><em>The Webmaster</em></p>
<?php endif ?>
      <div class="websitemenu">
<?php snippet('treemenu_extended', array('showchanges' => $showchanges)); ?>

<?php if($user = $site->user()): // user is logged in ?>
<?php if($site->hasFiles()): ?>
        <span class="internally1">This website has <?php echo $site->hasFiles(); ?> global site <?php ecco(($site->hasFiles() == 1), 'file', 'files') ?>:</span><?php if($user->hasPanelAccess()): ?><a href="<?php echo $site->url() ?>/panel/#/files/index/" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="View all global site files (in a new window / tab)" class="admineditlink2"><sup class="fa fa-cog admincolor2"></sup></a><?php endif ?>

        <ul class="depth-1 internally3 sitefiles">
<?php foreach($site->files() as $file): ?>
          <li><a href="<?php echo $file->url() ?>" target="<?php echo c::get('HeinerEF.ShowTarget', '_blank'); ?>">
              <?php echo $file->filename() ?></a>
                <?php if($user->hasPanelAccess()): ?><a href="<?php echo $site->url() ?>/panel/#/files/show/<?php echo $site->uri() ?>/<?php echo $file->filename() ?>" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="View this file (in a new window / tab)" class="admineditlink3"><sup class="fa fa-cog admincolor3"></sup></a><?php endif ?>
<?php if($file->type() == 'image'): ?>
:<?php echo thumb($file, array('width' => 200, 'height' => 150)); ?>
<?php else: ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php endif ?>
<?php if($file->modified() >= $referencetime): ?><span class="mini">(<?php echo $file->niceSize() ?>, last updated: <?php echo $file->modified('d.m.Y H:i') ?>)</span><?php endif ?>

          </li>
<?php endforeach ?>
        </ul>
<?php endif ?>
<?php endif ?>
      </div>
    </div>
  </main>
<?php snippet('footer') ?>

Step 3:

  • Add a new file with the name β€œtreemenu_extended.php” in the directory β€œ/site/snippets”
  • This new file should look like:

<?php $templateignore = array('blog', 'events'); // children of $templateignore are ignored in the _public_ sitemap ?>
<?php if(!isset($subpages)): $subpages = $site->pages(); endif; ?>
<?php $referencetime = date('U') - $showchanges*24*60*60; ?>
<?php if(!isset($level)): $level=1; ?>
      <ul class="depth-1">
<?php else: ?>
<?php $level+1; ?>
      <ul class="depth-<?php echo $level; ?>">
<?php endif ?>
<?php if($user = $site->user()): // user is logged in ?>
<?php $thesubpages = $subpages; ?>
<?php else: ?>
<?php $thesubpages = $subpages->visible(); ?>
<?php endif ?>
<?php foreach($thesubpages as $p): ?>
        <li class="depth-<?php echo $p->depth() ?>">
          <a<?php echo ($p->isActive()) ? ' class="active"' : '' ?> href="<?php echo $p->url() ?>" title="<?php echo $p->title()->html() ?>"><?php echo $p->title()->html() ?></a>
<?php if(($user = $site->user())): // user is logged in ?><?php if($user->hasPanelAccess()): ?><a href="<?php echo $site->url() ?>/panel/#/pages/show/<?php echo $p->uri() ?>/p:1" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="Edit site data (in a new window / tab)" class="admineditlink1"><sup class="fa fa-cog admincolor1"></sup></a><?php endif ?>
<?php if($p->modified() >= $referencetime): ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="mini">(last updated: <?php echo $p->modified('d.m.Y H:i') ?>)</span><?php endif ?>

<?php if($p->hasFiles()): ?>
          <br><span class="internally2">has <?php echo $p->hasFiles(); ?> assigned <?php ecco(($p->hasFiles() == 1), 'file', 'files') ?>:</span><?php if($user->hasPanelAccess()): ?><a href="<?php echo $site->url() ?>/panel/#/files/index/<?php echo $p->uri() ?>" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="View all files of this webpage (in a new window / tab)" class="admineditlink2"><sup class="fa fa-cog admincolor2"></sup></a><?php endif ?>

          <ul class="internally3">
<?php foreach($p->files() as $file): ?>
            <li>
              <a href="<?php echo $file->url() ?>" target="<?php echo c::get('HeinerEF.ShowTarget', '_blank'); ?>"><?php echo $file->filename() ?></a>
                <?php if($user->hasPanelAccess()): ?><a href="<?php echo $site->url() ?>/panel/#/files/show/<?php echo $p->uri() ?>/<?php echo $file->filename() ?>" target="<?php echo c::get('HeinerEF.EditTarget', '_blank'); ?>" title="View this file (in a new window / tab)" class="admineditlink3"><sup class="fa fa-cog admincolor3"></sup></a><?php endif ?>
<?php if($file->type() == 'image'): ?>
:<?php echo thumb($file, array('width' => 200, 'height' => 150)); ?>
<?php else: ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php endif ?>
<?php if($file->modified() >= $referencetime): ?><span class="mini">(<?php echo $file->niceSize() ?>, last updated: <?php echo $file->modified('d.m.Y H:i') ?>)</span><?php endif ?>

            </li>
<?php endforeach ?>
          </ul>
<?php endif ?>
<?php endif ?>
<?php if($p->hasChildren()): ?>
<?php if(($user = $site->user()) || (!(in_array($p->template(), $templateignore)))) : ?>
<?php if((in_array($p->template(), $templateignore))): ?>
   <span class="internally">
<?php endif ?>
  <?php snippet('treemenu_extended', array('subpages' => $p->children(), 'level' => $level+1, 'showchanges' => $showchanges)) ?>
<?php if((in_array($p->template(), $templateignore))): ?>
   </span>
<?php endif ?>
<?php endif ?>
<?php endif ?>
        </li>
<?php endforeach ?>
      </ul>
<?php $level-1; ?>

Step 4:

  • Within your CSS file add these lines at the end of the file:

/* ==================================================== */
@font-face {
  font-family: 'FontAwesome';
  font-weight: normal;
  font-style: normal;
  src: url(../../panel/assets/fonts/fontawesome-webfont.woff) format('woff');
}
.fa {
  display: inline-block;
  font-family: FontAwesome;
  font-feature-settings: normal;
  font-kerning: auto;
  font-language-override: normal;
  font-size: inherit;
  font-size-adjust: none;
  font-stretch: normal;
  font-style: normal;
  font-synthesis: weight style;
  font-variant: normal;
  font-weight: normal;
  line-height: 1;
  text-rendering: auto;
}
.fa-cog:before {
  content: "\f013";
}
/* The following colors are deliberately garish chosen to show the different levels significantly. Please adjust! */
.internally1 strong {
  color: #F0F;
  font-weight: 600;
}
.internally2,
.internally3 {
  font-size: 80%;
}
.admincolor1 {
  color: #00F;
}
.admincolor2 {
  color: #0F0;
}
.admincolor3 {
  color: #F00;
}


Step 5:

  • Log in at the panel and keep logged in
  • Go to your webpage β€œ/websitemap” in another browser window (being logged in).
  • Enjoy!
  • Click at a gear wheel! Then enjoy too!

Next Steps:

  • You may want to look at this webpage β€œ/websitemap” as a guest (not logged in)!
  • Modify the file β€œtreemenu_extended.php” in the directory β€œ/site/snippets” to fit your needs.
  • Modify the file β€œwebsitemap.php” in the directory β€œ/site/templates” to fit your needs.
  • Modify and extend the CSS file and extend the file β€œconfig.php” (in this post I show only the main elements, you need to test this idea).

[last edited: 2015-05-27 18:13 / German time]

Good luck!

1 Like

I have not tried it out yet but the screenshots looks nice.

In my case I would probably make it into a gallery with thumbnails.

Thanks!

Some time ago, I have build another HowTo, which you can use here too:
HowTo: Working with contextual links to the panel

Good luck!