repo init

This commit is contained in:
2015-12-01 23:22:23 +01:00
commit 94370ae57e
7 changed files with 339 additions and 0 deletions

76
inc/spot.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
class Spot extends Main
{
//Spot datasource
const SPOT_ID = '0Y5LrvigElWeAieBGnFol0KBEuOTkFJmm';
const SPOT_HOOK = 'https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/';
const SPOT_TYPE_XML = '/message.xml';
const SPOT_TYPE_JSON = '/message.json';
//Database
const MSG_TABLE = 'messages';
const SPOT_TABLE = 'spots';
public function __construct($oClassManagement, $sProcessPage)
{
parent::__construct($oClassManagement, $sProcessPage);
}
protected function install()
{
//Install DB
$this->oMySql->install();
}
protected function getSqlOptions()
{
return array
(
'tables' => array
(
self::MSG_TABLE => array('ref_msg_id', MySqlManager::getId(self::SPOT_TABLE), 'type', 'latitude', 'longitude', 'timestamp', 'unix_timestamp', 'content', 'battery_state'),
self::SPOT_TABLE => array('ref_spot_id', 'name', 'model')
),
'types' => array
(
'ref_msg_id' => "INT",
'type' => "VARCHAR(20)",
'latitude' => "DECIMAL(7,5)",
'longitude' => "DECIMAL(8,5)",
'timestamp' => "DATETIME",
'unix_timestamp'=> "INT",
'content' => "LONGTEXT",
'battery_state' => "VARCHAR(10)",
'ref_spot_id' => "VARCHAR(10)",
'name' => "VARCHAR(100)",
'model' => "VARCHAR(20)"
),
'constraints' => array
(
self::MSG_TABLE => "UNIQUE KEY `uni_ref_msg_id` (`ref_msg_id`)",
self::SPOT_TABLE => "UNIQUE KEY `uni_ref_spot_id` (`ref_spot_id`)",
self::MSG_TABLE => "INDEX(`ref_msg_id`)",
self::SPOT_TABLE => "INDEX(`ref_spot_id`)",
),
'cascading_delete' => array
(
self::SPOT_TABLE=>array(self::MSG_TABLE)
)
);
}
public function getSpotData()
{
//$sContent = file_get_contents(self::SPOT_HOOK.self::SPOT_ID.self::SPOT_TYPE_JSON);
$sContent = '{"response":{"feedMessageResponse":{"count":1,"feed":{"id":"0Y5LrvigElWeAieBGnFol0KBEuOTkFJmm","name":"Te Araroa","description":"Te Araroa","status":"ACTIVE","usage":0,"daysRange":7,"detailedMessageShown":false},"totalCount":1,"activityCount":0,"messages":{"message":{"@clientUnixTime":"0","id":477259564,"messengerId":"0-2489517","messengerName":"Francois","unixTime":1449002345,"messageType":"OK","latitude":48.85129,"longitude":2.40491,"modelId":"SPOT3","showCustomMsg":"N","dateTime":"2015-12-01T20:39:05+0000","messageDetail":"","batteryState":"GOOD","hidden":0,"messageContent":"Jusque là , tout va bien ! Click sur le lien en dessous pour voir où je suis :)\r\n\r\n@Clara: <3"}}}}}';
return json_decode($sContent, true);
}
public function getMainPage()
{
return parent::getMainPage(array('vars'=>array()));
}
}
?>

44
index.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
$sSpotId = '0Y5LrvigElWeAieBGnFol0KBEuOTkFJmm';
https://api.findmespot.com/spot-main-web/consumer/rest-api/2.0/public/feed/0Y5LrvigElWeAieBGnFol0KBEuOTkFJmm/message.json
/* Requests Handler */
//Start buffering
ob_start();
require_once '../objects/class_management.php';
$oClassManagement = new ClassManagement('spot');
ToolBox::cleanPost($_POST);
ToolBox::cleanPost($_GET);
ToolBox::cleanPost($_REQUEST);
ToolBox::fixGlobalVars(isset($argv)?$argv:array());
//Available variables
$sAction = isset($_REQUEST['a'])?$_REQUEST['a']:'';
$sPage = isset($_GET['p'])?$_GET['p']:'index';
//Initiate class
$oSpot = new Spot($oClassManagement, __FILE__);
$sResult = '';
if($sAction!='')
{
switch($sAction)
{
case '':
//$sResult = $oSpot->
break;
default:
$sResult = Pedidor::getJsonResult(false, Pedidor::NOT_FOUND);
}
}
else $sResult = $oSpot->getMainPage();
$sDebug = ob_get_clean();
if(Settings::DEBUG && $sDebug!='') $oSpot->addUncaughtError($sDebug);
echo $sResult;
?>

20
masks/index.html Normal file
View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link type="image/x-icon" href="images/favicon.ico" rel="shortcut icon" />
<link type="image/png" href="images/favicon_32.png" rel="icon" sizes="32x32" />
<link type="text/css" href="style/pedidor.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="script/jquery.js"></script>
<script type="text/javascript" src="script/jquery.mods.js"></script>
<script type="text/javascript" src="script/spot.js"></script>
<script type="text/javascript">
var oSpot = new Spot(asGlobalVars);
$(document).ready(oSpot.init);
</script>
<title>Find Me Spot</title>
</head>
<body>
<div id="container"></div>
</body>
</html>

10
masks/messages.html Normal file
View File

@@ -0,0 +1,10 @@
<div id="messages">
</div>
<script type="text/javascript">
oCvtheque.pageInit = function(asHash)
{
};
//oCvtheque.onSamePageMove = function(asHash){return true;};
</script>

4
script/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

0
script/jquery.mods.js Normal file
View File

185
script/spot.js Normal file
View File

@@ -0,0 +1,185 @@
function Spot(asGlobals)
{
self = this;
this.consts = asGlobals.consts;
this.consts.hash_sep = '-';
this.consts.title = 'Find Me Spot';
this.consts.default_page = 'messages';
/* Initialization */
this.init = function()
{
//Variables & constants from php
self.vars('tmp', 'object');
self.vars('page', 'string');
self.updateVars(asGlobals.vars);
//page elem
self.elem = {};
self.elem.container = $('#container');
//on window resize
//$(window).resize(self.onResize).resize();
//Setup menu
//self.initMenu();
//Hash management
self.resetTmpFunctions();
$(window)
.bind('hashchange', self.onHashChange)
.trigger('hashchange');
};
this.updateVars = function(asVars)
{
$.each(asVars, function(sKey, oValue){self.vars(sKey, oValue)});
};
/* Variable Management */
this.vars = function(oVarName, oValue)
{
var asVarName = (typeof oVarName == 'object')?oVarName:[oVarName];
//Set, name & type / default value (init)
if(typeof oValue !== 'undefined') setElem(self.vars, copyArray(asVarName), oValue);
//Get, only name parameter
return getElem(self.vars, asVarName);
};
this.tmp = function(sVarName, oValue)
{
var asVarName = (typeof sVarName == 'object')?sVarName:[sVarName];
asVarName.unshift('tmp');
return self.vars(asVarName, oValue);
};
/* Page Switch - Trigger & Event catching */
this.onHashChange = function()
{
var asHash = self.getHash();
if(asHash.hash !='' && asHash.page != '') self.switchPage(asHash); //page switching
else if(self.vars('page')=='') self.setHash(self.consts.default_page); //first page
};
this.getHash = function()
{
var sHash = self.hash();
var asHash = sHash.split(self.consts.hash_sep);
var sPage = asHash.shift() || '';
return {hash:sHash, page:sPage, items:asHash};
};
this.setHash = function(sPage, asItems, bReboot)
{
bReboot = bReboot || false;
sPage = sPage || '';
asItems = asItems || [];
if(typeof asItems == 'string') asItems = [asItems];
if(sPage != '')
{
var sItems = (asItems.length > 0)?self.consts.hash_sep+asItems.join(self.consts.hash_sep):'';
self.hash(sPage+sItems, bReboot);
}
};
this.hash = function(hash, bReboot)
{
bReboot = bReboot || false;
if(!hash) return window.location.hash.slice(1);
else window.location.hash = '#'+hash;
if(bReboot) location.reload();
};
/* Page Switch - DOM Replacement */
this.resetTmpFunctions = function()
{
self.pageInit = function(asHash){console.log('no init for the page: '+asHash.page)};
self.onSamePageMove = function(asHash){return false};
self.onQuitPage = function(){return true};
self.onFeedback = function(sType, sMsg){feedback(sType, sMsg);};
};
this.switchPage = function(asHash)
{
var sPageName = asHash.page;
var bSamePage = self.vars('page')==sPageName;
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']));
self.elem.main = self.elem.container.find('#main');
self.splash($Dom, asHash, bFirstPage); //first page
}
else
{
self.elem.main.stop().fadeTo('fast', 0, function(){self.splash($Dom, asHash, bFirstPage);}); //Switching page
}
}
};
this.splash = function($Dom, asHash, bFirstPage)
{
//Switch main content
self.elem.main.empty().html($Dom);
//Page Bootstrap
self.pageInit(asHash, bFirstPage);
//Show main
var $FadeInElem = bFirstPage?self.elem.container:self.elem.main;
$FadeInElem.hide().fadeTo('slow', 1);
};
}
/* Common Functions */
function copyArray(asArray)
{
return asArray.slice(0); //trick to copy array
}
function getElem(aoAnchor, asPath)
{
return (typeof asPath == 'object' && asPath.length > 1)?getElem(aoAnchor[asPath.shift()], asPath):aoAnchor[(typeof asPath == 'object')?asPath.shift():asPath];
}
function setElem(aoAnchor, asPath, oValue)
{
var asTypes = {boolean:false, string:'', integer:0, int:0, array:[], object:{}};
if(typeof asPath == 'object' && asPath.length > 1)
{
var nextlevel = asPath.shift();
if(!(nextlevel in aoAnchor)) aoAnchor[nextlevel] = {}; //Creating a new level
if(typeof aoAnchor[nextlevel] !== 'object') debug('Error - setElem() : Already existing path at level "'+nextlevel+'". Cancelling setElem() action');
return setElem(aoAnchor[nextlevel], asPath, oValue);
}
else
{
var sKey = (typeof asPath == 'object')?asPath.shift():asPath;
return aoAnchor[sKey] = (!(sKey in aoAnchor) && (oValue in asTypes))?asTypes[oValue]:oValue;
}
}