109 lines
2.6 KiB
PHP
Executable File
109 lines
2.6 KiB
PHP
Executable File
<?php
|
|
|
|
//load classes
|
|
session_start();
|
|
require_once 'config.php';
|
|
|
|
//clean sent values
|
|
cleanPost($_POST);
|
|
cleanPost($_GET);
|
|
cleanPost($_REQUEST);
|
|
|
|
/* Reserved Variables and Default Values */
|
|
|
|
//general
|
|
$sPage = (isset($_GET['p']) && $_GET['p']!='')?$_GET['p']:'w';
|
|
$sPostToken = isset($_POST['post_token'])?$_POST['post_token']:'';
|
|
|
|
//logon
|
|
$sLogin = (isset($_POST['login']) && $_POST['login']!='Nickname')?$_POST['login']:'';
|
|
$sPass = (isset($_POST['pass']) && $_POST['pass']!='Password')?$_POST['pass']:'';
|
|
$bRegister = (isset($_POST['register']) && $_POST['register']==1);
|
|
|
|
//writing pad
|
|
$sThought = isset($_POST['thoughts'])?$_POST['thoughts']:'';
|
|
$iThoughtId = (isset($_POST['thought_id']) && $_POST['thought_id']!='')?$_POST['thought_id']:0; //update or insert
|
|
$bFinishedWriting = isset($_POST['finished']);
|
|
|
|
//calendar
|
|
$iDay = isset($_GET['d'])?$_GET['d']:date(MyThoughts::URL_DATE_FORMAT); //d = yyyymmdd
|
|
$iCalYear = isset($_GET[Calendar::CAL_YEAR])?$_GET[Calendar::CAL_YEAR]:0; //cy = yyyy
|
|
$iCalMonth = isset($_GET[Calendar::CAL_MONTH])?$_GET[Calendar::CAL_MONTH]:0; //cm = m
|
|
|
|
$oMyThougths = new MyThoughts();
|
|
$bValidPost = ($sPostToken!='' && $oMyThougths->checkPostToken($sPostToken));
|
|
|
|
if($bValidPost)
|
|
{
|
|
if($bRegister)
|
|
{
|
|
$oMyThougths->register($sLogin, $sPass);
|
|
$sPage = 'r';
|
|
}
|
|
elseif($sLogin!='' && $sPass!='')
|
|
{
|
|
$oMyThougths->logMeIn($sLogin, $sPass);
|
|
}
|
|
}
|
|
|
|
//if loggued in
|
|
if(!$oMyThougths->isLogguedIn())
|
|
{
|
|
$oMyThougths->logonPage($sLogin);
|
|
}
|
|
else
|
|
{
|
|
$oMyThougths->activateMenu();
|
|
$oMyThougths->setCalendarDate();
|
|
switch($sPage)
|
|
{
|
|
case 'w': //write a thought
|
|
if($bValidPost && $sThought!='' && $sThought!='Talk to me.')
|
|
{
|
|
if($iThoughtId==0)
|
|
{
|
|
$iThoughtId = $oMyThougths->addThought($sThought);
|
|
}
|
|
else
|
|
{
|
|
$oMyThougths->updateThought($iThoughtId, $sThought);
|
|
}
|
|
}
|
|
if($bFinishedWriting)
|
|
{
|
|
$oMyThougths->readingPage();
|
|
}
|
|
else
|
|
{
|
|
$oMyThougths->writingPage($iThoughtId);
|
|
}
|
|
break;
|
|
case 'r': //read a thought (per day)
|
|
if($iDay<=0 || !$oMyThougths->readingPage(strtotime($iDay)))
|
|
{
|
|
$oMyThougths->writingPage();
|
|
}
|
|
break;
|
|
case 's': // go to settings page
|
|
if($bValidPost)
|
|
{
|
|
$asSettings = array_intersect_key($_POST, array_flip($oMyThougths->getSettingsList()));
|
|
$oMyThougths->setSettings($asSettings);
|
|
$oMyThougths->writingPage();
|
|
}
|
|
else
|
|
{
|
|
$oMyThougths->settingsPage();
|
|
}
|
|
break;
|
|
case 'q': //quit
|
|
$oMyThougths->logMeOut();
|
|
}
|
|
|
|
if($iCalYear!=0 && $iCalMonth!=0)
|
|
{
|
|
$oMyThougths->setCalendarDate($iCalYear, $iCalMonth);
|
|
}
|
|
}
|
|
echo $oMyThougths->getPage();
|
|
?>
|