Sure, here you are
<?php
/*
---------------------------------------
Troubleshooting
---------------------------------------
Kirby has a built-in troubleshooting screen
with loads of information about your setup.
It's there to help you out when things don't work
as expected. Set it to true to activate it and
go to your homepage afterwards to display it on refresh.
*/
c::set('troubleshoot', true);
/*
---------------------------------------
Debug
---------------------------------------
Set this to true to enable php errors.
Make sure to keep this disabled for your
production site, so you won't get nasty
php errors there.
*/
c::set('debug', true);
/*
---------------------------------------
Uso di <figure> per renderizzare le immagini
---------------------------------------
*/
c::set("kirbytext.image.figure", true);
//Paginazione
c::set('hnt.pagesize',5);
/*
---------------------------------------
Routes
---------------------------------------
Kirby will register a new route to http://yoursite.com/logout When you open that URL,
the action method will be called and if there's a logged in user,
the user will be logged out.
Afterwards the script will redirect the user to the login page.
*/
c::set('routes', array(
//login
array(
'pattern' => 'logout',
'action' => function() {
if($user = site()->user()) $user->logout();
go('login');
}
)
//Friendly URL -- tracks
,array(
'pattern' => 'tracks/(:any)/(:any)/(:any)',
'action' => function($artist, $title, $aid){
$results = site()->search($aid, 'articleid');
if ($results->count()>0) {
go(site()->home() . $results->first(), 301);
}
}
)
//Friendly URL -- a
,array(
'pattern' => 'a/(:any)',
'action' => function($aid){
$results = site()->search($aid, 'articleid');
if ($results->count()>0) {
go(site()->home() . $results->first(), 301);
}
}
)
//Lista articoli
,array(
'pattern' => 'tracks',
'action' => function(){
go(site()->home(), 301);
}
)
));
return[
/*
--------------------------
Session
---------------------------
*/
'session' => [
'durationNormal' => 7200, // default: 2 hours
'durationLong' => 1209600, // default: 2 weeks
'timeout' => 1800, // default: half an hour
'cookieName' => 'kirby_session',
'gcInterval' => 100 // default: cleanup every ~100 requests
],
/*
--------------------------
Smartypants
---------------------------
*/
'smartypants' => [
'space.emdash' => '—',
'space.endash' => '–'
],
/*
--------------------------
Hooks
---------------------------
*/
'hooks' => [
//Crea l'articleID e lo scrive sul file
//-------------------------------------
'page.create:after' => function ($page) {
//Se non è un articolo, esce
if($page->template() == "article")
{
//Crea l'article ID
$ID = $page->date()->toDate("Ymd") . '-' . mt_rand(0, 9999999);
//Aggiorna il file
try { $page->update(array('articleID' => $ID)); }
catch(Exception $e) { echo $e; }
}
},
//Scrive su db l'articolo una volta aggiornato
//---------------------------------------------
'page.update:after' => function ($page,$oldpage) {
if($page->template() == "article")
{
//Aggiorna l'articolo su db
articleUpdate($page);
}
elseif ($page->template() == "selezione")
{
//Aggiorna la selezione
saveSelezioneToDB($page);
}
elseif ($page->template() == "speciale")
{
//Aggiorna l'id dello speciale
updateArtSpecialID($page);
}
},
//Scrive su db l'articolo quando cambio titolo
//---------------------------------------------
'page.changeTitle:after' => function ($page,$oldpage) {
if($page->template() == "article")
{
//Articoli
articleUpdate($page);
}
elseif ($page->template() == "selezione")
{
//Liste
saveSelezioneToDB($page);
}
},
//Quando cambia il path di uno speciale,
//viene cambiato il path di tutti gli articoli che ne fanno parte
//---------------------------------------------------------------
'page.changeSlug:after' => function ($page,$oldpage) {
if($page->template() == "speciale") articleListMove($page);
},
//Scrive lo stato della pagina quando passa da invisibile a visibile
//------------------------------------------------------------------
'page.changeStatus:after' => function ($page,$oldpage) {
if($page->template() == "article")
{
//Articoli
articleUpdate($page);
}
elseif ($page->template() == "selezione")
{
//Liste
saveSelezioneToDB($page);
}
},
//Elimina un articolo dal db quando viene eliminato dal panel
//-----------------------------------------------------------
'page.delete:after' => function ($status, $page) {
if($page->template() == "article")
{
deleteArticleFromDb($page);
}
else if ($page->template() == "selezione")
{
deleteSelezioneFromDb($page);
}
},
//Impedisce il salvataggio di alcune specifiche pagine a chi non ha i permessi
//-----------------------------------------------------------
'page.update:before' => function ($page, $values, $strings) {
/*if ($page->template() == 'lungo')
{
//Exception
throw new Exception('Non hai i permessi!');
}*/
}
]
];
function articleUpdate($page)
{
$art_artist = "";
$art_title = "";
$art_articleID = trim($page->articleID());
//Dal titolo ricava artista e titolo del pezzo e lo scrive sul file
try{
$arr = explode(':',$page->title());
if ($arr[0] > "") $art_artist = trim($arr[0]);
if ($arr[1] > "") $art_title = trim($arr[1]);
}
catch(Exception $e) { echo $e;}
//Se l'articolo è precedente all'uso del panel, salvo l'articleID generato anche sul file
if ($art_articleID == "") $art_articleID = $page->uid();
//Aggiornamento del file
$page->update(array(
'artist' => $art_artist,
'articleTitle' => $art_title,
'articleID' => $art_articleID
));
//Salvataggio su db
saveArticleToDb($page);
}