Last active
August 29, 2015 14:05
-
-
Save Gabelbombe/6197e0ea1f0696e1b7fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Header add Access-Control-Allow-Origin "*" | |
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" | |
Header add Access-Control-Allow-Methods "GET, POST, OPTIONS" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE DATABASE logger; | |
USE logger; | |
DROP TABLE IF EXISTS `pixel`; | |
CREATE TABLE `pixel` ( | |
`id` bigint(20) NOT NULL AUTO_INCREMENT, | |
`impression` varchar(127) DEFAULT NULL, | |
`product` varchar(80) DEFAULT NULL, | |
`seen` bigint(100), | |
`capt` bigint(100), | |
PRIMARY KEY (`id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php header('Access-Control-Allow-Origin: *'); | |
require '../src/Database/Logger.php'; | |
$filter = array_filter(filter_input_array(INPUT_POST, [ | |
'impr' => FILTER_VALIDATE_INT, | |
'cell' => FILTER_VALIDATE_INT, | |
'verb' => FILTER_SANITIZE_STRING, | |
'time' => FILTER_VALIDATE_INT, | |
])); | |
if (isset($filter['impr'], $filter['time'], $filter['verb'])) | |
{ | |
$log = New \Database\Logger(); | |
$row = $log->register($filter); | |
die ($row); | |
} | |
if (isset($filter['cell'], $filter['time'])) | |
{ | |
$log = New \Database\Logger(); | |
$log->update($filter); | |
die (418); | |
} | |
header("HTTP/1.0 404 Not Found"); | |
die; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src='//code.jquery.com/jquery-latest.min.js' | |
type='text/javascript'></script> | |
<script type='text/javascript'> | |
$(function () // do work | |
{ | |
var srv = '//54.201.115.206', // EC2 | |
blk = 'javascript', | |
qst = 'ref'; | |
var ck = function (name) { var re = new RegExp(name + "=([^;]+)"); var value = re.exec(document.cookie); return (value != null) ? unescape(value[1]) : null; } | |
var bu = function (base, key, value){return base + ((base.indexOf('?') > -1) ? '&' : '?') + key + '=' + value;}; | |
var qs = function (key) | |
{ | |
var match = location.search.match(new RegExp("[?&]" + key.replace(/[*+?^$.\[\]{}()|\\\/]/g, '\\$&') + '=([^&]+)(&|$)')); | |
return match && decodeURIComponent(match[1].replace(/\+/g, " ")); | |
}; | |
var cat = [ | |
'70177', // Medium Duffle Bag - Heavy Tin | |
'70163', // Original Briefcase - Heavy Tin | |
'10519', // Explorer Jacket - Cover Cloth | |
'50125', // Filson PH Boot | |
'63208' // 1st Avenue Belt | |
]; | |
var num = location.pathname.split('/').reverse() [0].split('.').reverse() [1], | |
itm = location.pathname.split('/').reverse() [0].split('.').reverse() [2], | |
lim = Math.round((new Date()).getTime() / 1000) - ck("__utma").split('.').reverse() [1]; | |
if ('uncrate' === qs(qst)) | |
{ | |
if ('-1015' === location.pathname.split('/').reverse() [1]) // strpos for black collection | |
{ | |
$('#subcontent a').each(function () | |
{ | |
if(! $(this).attr('href').match(new RegExp(blk, 'gi')) // not a js link | |
&& ! $(this).attr('href').match(new RegExp(qst, 'gi'))) // or has already been applied | |
{ | |
$(this).attr('href', bu($(this).attr('href'), qst, 'uncrate')); // bound | |
}; | |
}); | |
} | |
else if (num.match(new RegExp('^[0-9]{5}$', 'g')) || (lim <= 20 && (-1 !== $.inArray(num, cat)))) // is proid | |
{ | |
$.post(srv, {impr: num, verb: itm, time: Math.round((new Date()).getTime() / 1000)}) | |
.done(function (cell) | |
{ | |
$('#prodaddbtn').click(function () // rebind | |
{ | |
$.post(srv, {cell: cell, time: Math.round((new Date()).getTime() / 1000)}); | |
}); | |
}); | |
}; | |
}; | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Namespace Database | |
{ | |
Class Logger | |
{ | |
private $user = false, | |
$pass = false; | |
protected $conn = false; | |
public function __construct () | |
{ | |
$this->user = getenv('DBUSER'); | |
$this->pass = getenv('DBPASS'); | |
try { | |
$conn = new \PDO('mysql:host=localhost;dbname=logger', $this->user, $this->pass); | |
$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); | |
} catch(\PDOException $e) { | |
echo 'ERROR: ' . $e->getMessage(); | |
} | |
$this->conn = $conn; | |
} | |
public function register ($filter) | |
{ | |
$dbh = $this->conn; | |
$stmt = $dbh->prepare( | |
'INSERT INTO pixel SET impression = :impr, product = :verb, seen = :time' | |
); | |
$stmt->execute([ | |
':impr' => $filter['impr'], | |
':verb' => $filter['verb'], | |
':time' => $filter['time'], | |
]); | |
return $dbh->lastInsertId(); | |
} | |
public function update ($filter) | |
{ | |
$dbh = $this->conn; | |
$stmt = $dbh->prepare( | |
'UPDATE pixel SET capt = :time WHERE id = :cell' | |
); | |
$stmt->execute([ | |
':time' => $filter['time'], | |
]); | |
return true; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment