fix write page

This commit is contained in:
francois
2018-04-09 22:01:42 +02:00
parent ab12b33532
commit 76faf824fc
13 changed files with 445 additions and 398 deletions

View File

@@ -17,6 +17,7 @@ class Auth extends PhpObject
public function __construct($oDb, $sApiKey='', $bAutoLogin=true) public function __construct($oDb, $sApiKey='', $bAutoLogin=true)
{ {
parent::__construct(__CLASS__, Settings::DEBUG);
$this->oDb = $oDb; $this->oDb = $oDb;
$this->setUserId(0); $this->setUserId(0);
$this->sApiKey = $sApiKey; $this->sApiKey = $sApiKey;
@@ -73,7 +74,7 @@ class Auth extends PhpObject
$sCookie = $_COOKIE[self::USER_COOKIE_PASS]; $sCookie = $_COOKIE[self::USER_COOKIE_PASS];
$iUserId = addslashes(strstr($sCookie, self::TOKEN_SEP, true)); $iUserId = addslashes(strstr($sCookie, self::TOKEN_SEP, true));
$sCookie = substr(strstr($sCookie, self::TOKEN_SEP), strlen(self::TOKEN_SEP)); $sCookie = substr(strstr($sCookie, self::TOKEN_SEP), strlen(self::TOKEN_SEP));
$asEmpl = $this->oDb->selectRow(MyThoughts::USER_TABLE, array(Db::getId(MyThoughts::USER_TABLE)=>$iUserId)); $asEmpl = $this->oDb->selectRow(MyThoughts::USER_TABLE, array(Db::getId(MyThoughts::USER_TABLE)=>$iUserId));
if(!empty($asEmpl)) if(!empty($asEmpl))
{ {

View File

@@ -1,342 +1,246 @@
<?php <?php
/** /**
* Main Class * Main Class
* @author franzz * @author franzz
* @version 2.0 * @version 2.0
*/ */
class MyThoughts extends PhpObject class MyThoughts extends Main
{ {
//Interface keywords //Interface keywords
const SUCCESS = 'success'; const SUCCESS = 'success';
const ERROR = 'error'; const ERROR = 'error';
const UNAUTHORIZED = 'unauthorized'; const UNAUTHORIZED = 'unauthorized';
const NOT_FOUND = 'unknown action'; const NOT_FOUND = 'unknown action';
//SQL tables //SQL tables
const USER_TABLE = 'users'; const USER_TABLE = 'users';
const THOUGHT_TABLE = 'thoughts'; const SETTINGS_TABLE = 'settings';
const SETTINGS_TABLE = 'settings';
//Mythoughts
//Mythoughts const URL_DATE_FORMAT = 'Ymd';
const URL_DATE_FORMAT = 'Ymd'; const LAYOUT_DATE_FORMAT = 'F \t\h\e jS, Y';
const LAYOUT_DATE_FORMAT = 'F \t\h\e jS, Y'; const MYSQL_DATE_FORMAT = 'Y-m-d';
const MYSQL_DATE_FORMAT = 'Y-m-d'; const LAYOUT_TIME_FORMAT = 'G:i';
const LAYOUT_TIME_FORMAT = 'G:i'; const WELCOME_MSG_FILE = 'welcome';
const WELCOME_MSG_FILE = 'welcome'; const SETTING_LAYOUT = 'layout';
const SETTING_LAYOUT = 'layout'; const LAYOUT_ONE_PAGE = '1';
const LAYOUT_ONE_PAGE = '1'; const LAYOUT_TWO_PAGES = '2';
const LAYOUT_TWO_PAGES = '2'; const SETTING_FONT = 'font';
const SETTING_FONT = 'font'; const FONT_THOUGHTS = 'thoughts';
const FONT_THOUGHTS = 'thoughts'; const FONT_ARIAL = 'Arial';
const FONT_ARIAL = 'Arial'; const FONT_VERDANA = 'Verdana';
const FONT_VERDANA = 'Verdana'; const SETTING_SIZE = 'Size';
const SETTING_SIZE = 'Size'; const SIZE_16 = '16';
const SIZE_16 = '16'; const SIZE_18 = '18';
const SIZE_18 = '18'; const SIZE_20 = '20';
const SIZE_20 = '20';
//Format
//Objects const OBJ = 'object';
private $oClassManagement; const ARRAY = 'array';
const JSON = 'json';
/**
* Database Connection /**
* @var Db * Auth Object
*/ * @var Auth
private $oDb; */
private $oAuth;
/**
* /**
* @var Auth * Main constructor [to be called from index.php]
*/ * @param ClassManagement $oClassManagement
private $oAuth; * @param string $sLang
*/
//Variables public function __construct($oClassManagement, $sProcessPage)
private $asContext; {
//... //Load classes
//$this->oClassManagement->incClass('calendar', true);
/** $asClasses = array( array('name'=>'auth', 'project'=>true),
* Main constructor [to be called from index.php] array('name'=>'thought', 'project'=>true));
* @param ClassManagement $oClassManagement
* @param string $sLang parent::__construct($oClassManagement, $sProcessPage, $asClasses);
*/
public function __construct($oClassManagement, $sProcessPage) //Init objects
{ if($this->oDb->sDbState == Db::DB_PEACHY) $this->oAuth = new Auth($this->oDb, Settings::API_KEY);
parent::__construct(__CLASS__, Settings::DEBUG); }
$this->oClassManagement = $oClassManagement;
$this->setContext($sProcessPage); protected function install()
{
//Load classes $this->oAuth = new Auth($this->oDb, Settings::API_KEY, false);
$this->oClassManagement->incClass('db');
$this->oClassManagement->incClass('auth', true); //Install DB
//$this->oClassManagement->incClass('calendar', true); $this->oDb->install();
$this->addUser('franzz');
//Init objects }
$this->oDb = new Db(Settings::DB_SERVER, Settings::DB_LOGIN, Settings::DB_PASS, Settings::DB_NAME, self::getSqlOptions() , Settings::DB_ENC);
if($this->oDb->sDbState == Db::DB_NO_DATA) $this->install(); private function setContext($sProcessPage)
else $this->oAuth = new Auth($this->oDb, Settings::API_KEY); {
} //Browser <> PHP <> MySql synchronization
date_default_timezone_set(Settings::TIMEZONE);
private function install() ini_set('default_charset', Settings::TEXT_ENC);
{ header('Content-Type: text/html; charset='.Settings::TEXT_ENC);
$this->oAuth = new Auth($this->oDb, Settings::API_KEY, false); mb_internal_encoding(Settings::TEXT_ENC);
mb_http_output(Settings::TEXT_ENC);
//Install DB mb_http_input(Settings::TEXT_ENC);
$this->oDb->install(); mb_language('uni');
$this->addUser('franzz'); mb_regex_encoding(Settings::TEXT_ENC);
}
$this->asContext['process_page'] = basename($sProcessPage);
private function setContext($sProcessPage)
{ $sServerName = array_key_exists('SERVER_NAME', $_SERVER)?$_SERVER['SERVER_NAME']:$_SERVER['PWD'];
//Browser <> PHP <> MySql synchronization $sAppPath = 'http://'.str_replace('http://', '', $sServerName.dirname($_SERVER['SCRIPT_NAME']));
date_default_timezone_set(Settings::TIMEZONE); $this->asContext['serv_name'] = $sAppPath.(mb_substr($sAppPath, -1)!='/'?'/':'');
ini_set('default_charset', Settings::TEXT_ENC); }
header('Content-Type: text/html; charset='.Settings::TEXT_ENC);
mb_internal_encoding(Settings::TEXT_ENC); public function addUncaughtError($sError)
mb_http_output(Settings::TEXT_ENC); {
mb_http_input(Settings::TEXT_ENC); $this->addError('Uncaught errors:'."\n".$sError);
mb_language('uni'); }
mb_regex_encoding(Settings::TEXT_ENC);
/* Authorizations handling */
$this->asContext['process_page'] = basename($sProcessPage);
public function isLoggedIn()
$sServerName = array_key_exists('SERVER_NAME', $_SERVER)?$_SERVER['SERVER_NAME']:$_SERVER['PWD']; {
$sAppPath = 'http://'.str_replace('http://', '', $sServerName.dirname($_SERVER['SCRIPT_NAME'])); return $this->oAuth->isLoggedIn();
$this->asContext['serv_name'] = $sAppPath.(mb_substr($sAppPath, -1)!='/'?'/':''); }
}
public function logMeIn($sToken)
public function addUncaughtError($sError) {
{ return $this->oAuth->logMeIn($sToken);
$this->addError('Uncaught errors:'."\n".$sError); }
}
public function checkApiKey($sApiKey)
/* Authorizations handling */ {
return $this->oAuth->checkApiKey($sApiKey);
public function isLoggedIn() }
{
return $this->oAuth->isLoggedIn(); /* Building main pages */
}
public function getPage()
public function logMeIn($sToken) {
{ /*$asMaskPaths = glob('masks/*.html');
return $this->oAuth->logMeIn($sToken); $asMaskNames = array_map('basename', $asMaskPaths, array_fill(1, count($asMaskPaths), '.html'));*/
}
//Constants
public function checkApiKey($sApiKey) $asPages = array('logon', 'write', 'settings', 'template');
{ foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
return $this->oAuth->checkApiKey($sApiKey); $asGlobalVars['consts']['token_sep'] = Auth::TOKEN_SEP;
} $asGlobalVars['consts']['error'] = self::ERROR;
$asGlobalVars['consts']['success'] = self::SUCCESS;
/* Building main pages */ $asGlobalVars['consts']['context'] = $this->asContext;
$asGlobalVars['vars']['id'] = $this->oAuth->getUserId();
public function getPage($bLoggedIn) $asGlobalVars['vars']['log_in'] = $this->isLoggedIn();
{
/*$asMaskPaths = glob('masks/*.html'); //Main Page
$asMaskNames = array_map('basename', $asMaskPaths, array_fill(1, count($asMaskPaths), '.html'));*/ $sPage = $this->getPageContent('index');
$sPage = str_replace('asGlobalVars', json_encode($asGlobalVars), $sPage);
//Constants return $sPage;
$asPages = array('logon', 'write', 'settings', 'template'); }
foreach($asPages as $sPage) $asGlobalVars['consts']['pages'][$sPage] = $this->getPageContent($sPage);
$asGlobalVars['consts']['token_sep'] = Auth::TOKEN_SEP; /* DB structure. See Db::__construct */
$asGlobalVars['consts']['error'] = self::ERROR;
$asGlobalVars['consts']['success'] = self::SUCCESS; protected function getSqlOptions()
$asGlobalVars['consts']['context'] = $this->asContext; {
$asGlobalVars['vars']['id'] = $this->oAuth->getUserId(); return array(
$asGlobalVars['vars']['log_in'] = $bLoggedIn; 'tables' => array(
self::USER_TABLE => array(Db::getText(self::USER_TABLE), 'nickname', 'pass', 'cookie'),
//Main Page Thought::THOUGHT_TABLE => array(Db::getId(self::USER_TABLE), Db::getText(Thought::THOUGHT_TABLE)),
$sPage = $this->getPageContent('index'); self::SETTINGS_TABLE => array(Db::getId(self::USER_TABLE), Db::getText(self::SETTINGS_TABLE), 'value')
$sPage = str_replace('asGlobalVars', json_encode($asGlobalVars), $sPage); ),
return $sPage; 'types' => array(
} Db::getText(self::USER_TABLE) => "varchar(50) NOT NULL",
'nickname' => "varchar(60) NOT NULL",
private function getPageContent($sPage) 'pass' => "varchar(256)",
{ 'cookie' => "varchar(255)",
$sPageFile = 'masks/'.$sPage.'.html'; Db::getText(Thought::THOUGHT_TABLE) => "longtext",
return file_get_contents($sPageFile); Db::getText(self::SETTINGS_TABLE) => "varchar(20) NOT NULL",
} 'value' => "varchar(20) NOT NULL"
),
/* DB structure. See Db::__construct */ 'constraints' => array(
self::USER_TABLE => "UNIQUE KEY `username` (`".Db::getText(self::USER_TABLE)."`)"
private static function getSqlOptions() ),
{ 'cascading_delete' => array(
return array self::USER_TABLE => array(self::SETTINGS_TABLE)
( )
'tables' => array );
( }
self::USER_TABLE =>array(Db::getText(self::USER_TABLE), 'nickname', 'pass', 'cookie'),
self::THOUGHT_TABLE =>array(Db::getId(self::USER_TABLE), /* My Thoughts public functions */
Db::getText(self::THOUGHT_TABLE)),
self::SETTINGS_TABLE=>array(Db::getId(self::USER_TABLE), public function register($sNickName)
Db::getText(self::SETTINGS_TABLE), {
'value') $iUserId = $this->addUser($sNickName, true);
), $bSuccess = false;
'types' => array $sDesc = '';
( switch($iUserId)
Db::getText(self::USER_TABLE)=>"varchar(50) NOT NULL", {
'nickname'=>'varchar(60) NOT NULL', case -1:
'pass'=>"varchar(256)", $sDesc = 'There is already a user using this nickname, sorry!';
'cookie'=>"varchar(255)", break;
Db::getText(self::THOUGHT_TABLE)=>"longtext", case 0:
Db::getText(self::SETTINGS_TABLE)=>"varchar(20) NOT NULL", $sDesc = 'A database error occured. Contact admin';
'value'=>"varchar(20) NOT NULL" break;
), default:
'constraints' => array $bSuccess = true;
( }
self::USER_TABLE=>"UNIQUE KEY `username` (`".Db::getText(self::USER_TABLE)."`)" return self::getJsonResult($bSuccess, $sDesc);
), }
'cascading_delete' => array
( public function getThought($iThoughtId, $sFormat=self::OBJ)
self::USER_TABLE=>array(self::SETTINGS_TABLE) {
) $oThought = new Thought($this->oDb);
);
} if($iThoughtId=='last')
{
/* My Thoughts public functions */ $oThought->setUserId($this->oAuth->getUserId());
$oThought->openLast();
public function register($sNickName) }
{ else $oThought->open($iThoughtId);
$iUserId = $this->addUser($sNickName, true);
$bSuccess = false; switch($sFormat)
$sDesc = ''; {
switch($iUserId) case self::OBJ:
{ return $oThought; break;
case -1: case self::ARRAY:
$sDesc = 'There is already a user using this nickname, sorry!'; return $oThought->get(); break;
break; case self::JSON:
case 0: return self::getJsonResult(true, '', $oThought->get()); break;
$sDesc = 'A database error occured. Contact admin'; }
break; }
default:
$bSuccess = true; public function updateThought($asOps, $iThoughtId=0, $iUserId=-1)
} {
return self::getJsonResult($bSuccess, $sDesc); $oThought = new Thought($this->oDb, $iThoughtId);
}
if($oThought->getId() == 0) {
public function updateThought($sThought, $iThoughtId=0) if($iUserId==-1) $iUserId = $this->oAuth->getUserId();
{ if($iUserId!=0) $oThought->setUserId($iUserId);
if($iThoughtId==0) else $this->addError('Adding a thought with no user id');
{ }
$iThoughtId = $this->addThought($sThought);
$sDesc = 'created'; $oThought->setOps($asOps);
} $iThoughtId = $oThought->save();
else
{ $bSuccess = ($iThoughtId>0);
$asKeys = array(Db::getId(self::USER_TABLE) => $this->oAuth->getUserId(), $sDesc = 'thought '.($bSuccess?'':'not ').'saved';
Db::getId(self::THOUGHT_TABLE)=> $iThoughtId); return self::getJsonResult($bSuccess, $sDesc, $this->getThought($iThoughtId, self::ARRAY));
$asThought = array(Db::getText(self::THOUGHT_TABLE) => self::encodeThought($sThought)); }
$iThoughtId = $this->oDb->updateRow(self::THOUGHT_TABLE, $asKeys, $asThought);
$sDesc = 'updated'; /* My Thoughts private functions */
}
$bSuccess = ($iThoughtId>0); private function addUser($sNickName, $bLogMeIn=false)
$sDesc = 'thought '.($bSuccess?'':'not ').$sDesc; {
return self::getJsonResult($bSuccess, $sDesc, $this->getThoughtInfo($iThoughtId)); $iUserId = $this->oAuth->addUser(self::getSafeNickName($sNickName), $sNickName, $bLogMeIn);
} //if($iUserId>0) $this->updateThought(file_get_contents(self::WELCOME_MSG_FILE), $iUserId);
return $iUserId;
/* My Thoughts private functions */ }
private function addUser($sNickName, $bLogMeIn=false) /* Static toolbox functions */
{
$iUserId = $this->oAuth->addUser(self::getSafeNickName($sNickName), $sNickName, $bLogMeIn); public static function getSafeNickName($sNickName)
if($iUserId>0) $this->addThought(file_get_contents(self::WELCOME_MSG_FILE), $iUserId); {
return $iUserId; return $sNickName;
} }
}
private function addThought($sThought, $iUserId=-1)
{
if($iUserId==-1) $iUserId = $this->oAuth->getUserId();
if($iUserId!=0)
{
$asThought = array( Db::getId(self::USER_TABLE) => $iUserId,
Db::getText(self::THOUGHT_TABLE) => self::encodeThought($sThought));
$ithoughtId = $this->oDb->insertRow(self::THOUGHT_TABLE, $asThought);
}
else $this->addError('Adding a thought with no user id');
return $ithoughtId;
}
private function getThoughtInfo($iThoughtId, $bThoughtContent=false)
{
$asThoughtInfo = array();
if($iThoughtId>0)
{
$asThoughtInfo = $this->oDb->selectRow(self::THOUGHT_TABLE, $iThoughtId);
if(!$bThoughtContent) unset($asThoughtInfo[Db::getText(self::THOUGHT_TABLE)]);
}
else $this->addError('getting thought info with no thought id');
return $asThoughtInfo;
}
/* Static toolbox functions */
private static function encodeThought($sthought)
{
return base64_encode(serialize(explode("\n", self::shuffleText($sthought))));
}
private static function decodeThought($sEncodedThought)
{
return self::shuffleText(implode("\n", unserialize(base64_decode($sEncodedThought))));
}
private static function shuffleText($sText)
{
$sRandomText = "let's_mess%a&bit;with~it,!just§for¨the^sake*of-it";
for($iIndex=0; $iIndex < strlen($sText); $iIndex++)
{
$sText[$iIndex] = $sRandomText[$iIndex%strlen($sRandomText)] ^ $sText[$iIndex];
}
return $sText;
}
public static function getJsonResult($bSuccess, $sDesc='', $asVars=array())
{
header('Content-type: application/json');
return json_encode(array('result'=>$bSuccess?self::SUCCESS:self::ERROR, 'desc'=>ToolBox::mb_ucwords($sDesc))+$asVars);
}
public function getSafeNickName($sNickName)
{
return $sNickName;
}
public static function getDateTimeDesc($oTime)
{
$iTimeStamp = is_numeric($oTime)?$oTime:strtotime($oTime);
$sCurTimeStamp = time();
$asWeekDays = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'satursday', 'sunday');
$asMonths = array('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december');
$sSep = '|';
$sFormat = 'Y'.$sSep.'n'.$sSep.'W'.$sSep.'N'.$sSep.'j'.$sSep.'G';
list($sYear, $sMonth, $sWeek, $sWeekDay, $sDay, $sHour) = explode($sSep, date($sFormat, $iTimeStamp));
list($sCurYear, $sCurMonth, $sCurWeek, $sCurWeekDay, $sCurDay, $sCurHour) = explode($sSep, date($sFormat, $sCurTimeStamp));
$sDesc = '';
if($iTimeStamp>$sCurTimeStamp) $sDesc = 'in the future';
elseif($sCurTimeStamp-$iTimeStamp<60) $sDesc = 'a few seconds ago';
elseif($sCurTimeStamp-$iTimeStamp<60*10) $sDesc = 'a few minutes ago';
elseif($sCurTimeStamp-$iTimeStamp<60*20) $sDesc = '15 minutes ago';
elseif($sCurTimeStamp-$iTimeStamp<60*50) $sDesc = 'half an hour ago';
elseif($sCurTimeStamp-$iTimeStamp<60*60*2) $sDesc = 'an hour ago';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24 && $sDay==$sCurDay) $sDesc = 'at '.$sHour.' o\'clock';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24) $sDesc = 'yesterday';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*7 && $sWeek==$sCurWeek) $sDesc = $asWeekDays[$sWeekDay-1];
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*7) $sDesc = 'last '.$asWeekDays[$sWeekDay-1];
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*9) $sDesc = 'a week ago';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*12) $sDesc = '10 days ago';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*16) $sDesc = '2 weeks ago';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*23) $sDesc = '3 weeks ago';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*31 && $sMonth==$sCurMonth) $sDesc = 'on '.$asMonths[$sMonth-1].', '.$sDay;
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*30*2 && $sMonth==($sCurMonth-1)) $sDesc = 'last month';
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*365 && $sYear==$sCurYear) $sDesc = 'in '.$asMonths[$sMonth-1];
elseif($sCurTimeStamp-$iTimeStamp<60*60*24*365) $sDesc = 'in '.$asMonths[$sMonth-1].' '.$sYear;
elseif($sYear==($sCurYear-1)) $sDesc = 'last year';
else $sDesc = 'in '.$sYear;
//return self::mb_ucfirst($sDesc);
return $sDesc;
}
}
?> ?>

112
inc/thought.php Normal file
View File

@@ -0,0 +1,112 @@
<?php
class Thought extends PhpObject
{
const THOUGHT_TABLE = 'thoughts';
private $iId;
private $iUserId;
private $asOps;
private $sLed;
/**
* Database Handle
* @var Db
*/
private $oDb;
public function __construct(&$oDb, $iId=0)
{
parent::__construct(__CLASS__, Settings::DEBUG);
$this->oDb = $oDb;
$this->setId($iId);
}
public function getId()
{
return $this->iId;
}
public function setId($iId, $bOpen=true)
{
$this->iId = $iId;
if($this->iId > 0 && $bOpen) $this->open($this->iId);
}
public function setUserId($iUserId)
{
$this->iUserId = $iUserId;
}
public function setOps($asOps, $bSave=false)
{
$this->asOps = $asOps;
if($bSave) return $this->save();
}
public function openLast()
{
$iId = $this->oDb->selectValue(
self::THOUGHT_TABLE,
"MAX(".Db::getId(self::THOUGHT_TABLE).")",
array(Db::getId(MyThoughts::USER_TABLE) => $this->iUserId));
$this->open($iId);
}
public function open($iId)
{
if($iId>0)
{
$asInfo = $this->oDb->selectRow(self::THOUGHT_TABLE, $iId);
$this->iId = $asInfo[Db::getId(self::THOUGHT_TABLE)];
$this->iUserId = $asInfo[Db::getId(MyThoughts::USER_TABLE)];
$this->asOps = self::decodeThought($asInfo[Db::getText(self::THOUGHT_TABLE)]);
$this->sLed = $asInfo['led'];
}
else $this->addError('getting thought info with no thought id');
}
public function save()
{
$asThought = array(
Db::getId(MyThoughts::USER_TABLE) => $this->iUserId,
Db::getText(self::THOUGHT_TABLE) => self::encodeThought($this->asOps)
);
if($this->iId > 0) $this->oDb->updateRow(self::THOUGHT_TABLE, $this->iId, $asThought);
else $this->iId = $this->oDb->insertRow(self::THOUGHT_TABLE, $asThought);
return $this->iId;
}
public function get()
{
return array(
'id' => $this->iId,
'id_user' => $this->iUserId,
'ops' => $this->asOps,
'led' => $this->sLed
);
}
private static function encodeThought($sthought)
{
return base64_encode(serialize(explode("\n", self::shuffleText(json_encode($sthought)))));
}
private static function decodeThought($sEncodedThought)
{
return json_decode(self::shuffleText(implode("\n", unserialize(base64_decode($sEncodedThought)))), true);
}
private static function shuffleText($sText)
{
$sRandomText = "let's_mess%a&bit;with~it,!just§for¨the^sake*of-it";
for($iIndex=0; $iIndex < strlen($sText); $iIndex++)
{
$sText[$iIndex] = $sRandomText[$iIndex%strlen($sRandomText)] ^ $sText[$iIndex];
}
return $sText;
}
}

View File

@@ -49,6 +49,9 @@ elseif($sAction!='' && $bLoggedIn)
{ {
switch ($sAction) switch ($sAction)
{ {
case 'load':
$sResult = $oMyThoughts->getThought($iId, MyThoughts::JSON);
break;
case 'update': case 'update':
$sResult = $oMyThoughts->updateThought($sContent, $iId); $sResult = $oMyThoughts->updateThought($sContent, $iId);
break; break;
@@ -72,7 +75,7 @@ elseif($sAction!='' && !$bLoggedIn)
elseif($sAction=='register') $sResult = $oMyThoughts->register($sNickName); elseif($sAction=='register') $sResult = $oMyThoughts->register($sNickName);
else $sResult = MyThoughts::getJsonResult(false, MyThoughts::UNAUTHORIZED); else $sResult = MyThoughts::getJsonResult(false, MyThoughts::UNAUTHORIZED);
} }
else $sResult = $oMyThoughts->getPage($bLoggedIn); else $sResult = $oMyThoughts->getPage();
$sDebug = ob_get_clean(); $sDebug = ob_get_clean();
if(Settings::DEBUG && $sDebug!='') $oMyThoughts->addUncaughtError($sDebug); if(Settings::DEBUG && $sDebug!='') $oMyThoughts->addUncaughtError($sDebug);

View File

@@ -47,8 +47,8 @@
{insert: '\n'}, {insert: '\n'},
{insert: "In-extremist, I manage to babble some excuses about a rigorous lunch break time and leave the premises."} {insert: "In-extremist, I manage to babble some excuses about a rigorous lunch break time and leave the premises."}
]);*/ ]);*/
oQuill.setContents([{insert:self.vars('default_text')}]);
setLastContent();
setPageHeight(); setPageHeight();
//Key strokes Events //Key strokes Events
@@ -96,6 +96,21 @@
self.vars('page_height', iMaxHeight); self.vars('page_height', iMaxHeight);
} }
function setLastContent(oQuill)
{
getInfo
(
'load',
function(sDesc, asData)
{
self.vars('id', asData.id);
oQuill.setContents(asData.ops);
},
{id: 'last'}
);
}
function onChange(delta, oldDelta, source, e) function onChange(delta, oldDelta, source, e)
{ {
if(source == 'user') if(source == 'user')
@@ -170,8 +185,7 @@
function incKeyStrokes() function incKeyStrokes()
{ {
self.vars('keystrokes', self.vars('keystrokes') + 1); self.vars('keystrokes', self.vars('keystrokes') + 1);
if(self.vars('keystrokes') % 20 == 0) save();
if(self.vars('keystrokes') % 10) save();
} }
function save() function save()
@@ -183,12 +197,15 @@
getInfo getInfo
( (
'update', 'update',
function(asData) function(sDesc, asData)
{ {
self.vars('id', asData.id_thought); self.vars('id', asData.id);
oMyThoughts.onFeedback('notice', 'Saved ('+asData.led.substr(11, 5)+')'); oMyThoughts.onFeedback('notice', 'Saved ('+asData.led.substr(11, 5)+')');
}, },
{content:sContent, id:self.vars('id')}, {
id: self.vars('id'),
content: sContent
},
function(sError) function(sError)
{ {
oMyThoughts.onFeedback('error', 'Not saved! An error occured: '+sError); oMyThoughts.onFeedback('error', 'Not saved! An error occured: '+sError);

View File

@@ -78,7 +78,7 @@ function getInfo(action, fOnSuccess, vars, fOnError, sType/*, bProcessIcon*/)
else else
{ {
//if(bProcessIcon) self.resetIcon(); //if(bProcessIcon) self.resetIcon();
fOnSuccess(oData); fOnSuccess(oData.desc, oData.data);
} }
}) })
.fail(function(jqXHR, textStatus, errorThrown) .fail(function(jqXHR, textStatus, errorThrown)

View File

@@ -71,9 +71,7 @@ function MyThoughts(asGlobals)
this.onHashChange = function() this.onHashChange = function()
{ {
var asHash = self.getHash(); var asHash = self.getHash();
var sDefaultPage = self.vars('log_in')?'write':'logon'; self.switchPage(asHash);
if(asHash.hash !='' && asHash.page != '') self.switchPage(asHash); //page switching
else if(self.vars('page')=='') self.setHash(sDefaultPage); //first page
}; };
this.resetTmpFunctions = function() this.resetTmpFunctions = function()
@@ -146,40 +144,45 @@ function MyThoughts(asGlobals)
this.switchPage = function(asHash) this.switchPage = function(asHash)
{ {
var sPageName = asHash.page; var sCurrPage = self.vars('page');
var bSamePage = self.vars('page')==sPageName; var sNextPage = asHash.page;
if(self.onQuitPage(bSamePage) && !bSamePage || self.onSamePageMove(asHash)) var bLoggedIn = self.vars('log_in');
var sDefaultPage = bLoggedIn?'write':'logon';
if(asHash.hash !='' && sNextPage != '' && (bLoggedIn || sNextPage==sDefaultPage))
{ {
//Preload template if not already loaded var bSamePage = (sCurrPage==sNextPage);
if(self.onQuitPage(bSamePage) && !bSamePage || self.onSamePageMove(asHash))
//Delete tmp variables
self.vars('tmp', {});
//disable tmp functions
self.resetTmpFunctions();
//Officially a new page
var bFirstPage = self.vars('page')=='';
self.vars('page', sPageName);
//Update Page Title
var sDetail = asHash.items[0] || '';
document.title = self.consts.title+' - '+sPageName+' '+sDetail;
//Replacing DOM
var $Dom = $(self.consts.pages[sPageName]);
if(bFirstPage)
{ {
self.elem.container.html($(self.consts.pages['template'])); //Delete tmp variables
self.elem.main = self.elem.container.find('#main'); self.vars('tmp', {});
self.splash(self.elem.main, $Dom, asHash, bFirstPage); //first page
} //disable tmp functions
else self.resetTmpFunctions();
{
self.elem.main.stop().fadeTo('fast', 0, function(){self.splash(self.elem.main, $Dom, asHash, bFirstPage);}); //Switching page //Officially a new page
var bFirstPage = (sCurrPage=='');
self.vars('page', sNextPage);
//Update Page Title
var sDetail = asHash.items[0] || '';
document.title = self.consts.title+' - '+sNextPage+' '+sDetail;
//Replacing DOM
var $Dom = $(self.consts.pages[sNextPage]);
if(bFirstPage)
{
self.elem.container.html($(self.consts.pages['template']));
self.elem.main = self.elem.container.find('#main');
self.splash(self.elem.main, $Dom, asHash, bFirstPage); //first page
}
else
{
self.elem.main.stop().fadeTo('fast', 0, function(){self.splash(self.elem.main, $Dom, asHash, bFirstPage);}); //Switching page
}
} }
} }
else self.setHash(sDefaultPage); //force first page
}; };
this.splash = function($FadeInElem, $Dom, asHash, bFirstPage) this.splash = function($FadeInElem, $Dom, asHash, bFirstPage)

13
style/_variables.scss Normal file
View File

@@ -0,0 +1,13 @@
/* Colors
Very Very Bright Brown: #f7f2eb
Very Bright Brown: #ede0d0
bright brown : #e2ccb2
dark brown : #584127
blue lines : #2DCDFF
red lines : #EC3B45
*/
$col_main_1: #584127;
$col_main_2: #e2ccb2;
$col_main_3: #ede0d0;
$col_main_4: #f7f2eb;

View File

@@ -4,11 +4,9 @@
#editor_container { #editor_container {
border: 1em solid #EDE0D0;
border-radius: 0.5em;
height: calc(100% - 4em); height: calc(100% - 4em);
overflow: hidden; overflow: hidden;
position:relative; position: relative;
#editor_content { #editor_content {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +1,6 @@
/* Colors /* Variables */
Very Very Bright Brown: #f7f2eb
Very Bright Brown: #ede0d0 @import 'variables';
bright brown : #e2ccb2
dark brown : #584127
blue lines : #2DCDFF
red lines : #EC3B45
*/
/* Fonts */ /* Fonts */
@@ -228,8 +223,9 @@ a.calendar_direction {
bottom:2em; bottom:2em;
right:0; right:0;
left:0; left:0;
background:#EDE0D0;
border-radius: 0.5em; border-radius: 0.5em;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
padding: 1em;
} }
/* Read */ /* Read */

View File

@@ -1,2 +1,2 @@
Welcome To MyThoughts Online Application! Hope you'll enjoy the effort. don't hesitate to give me feebacks by sending an email to francois on the french domain lutran Welcome To MyThoughts Online App! Hope you'll enjoy the effort. don't hesitate to give me feebacks by sending an email to francois on the french domain lutran
Hit the "Write" button to start writing your thoughts. Hit the "Write" button to start writing your thoughts.