use random hash strings for Station URLs
This commit is contained in:
parent
d1faa5b4b1
commit
676c2386fd
3 changed files with 58 additions and 11 deletions
|
@ -35,12 +35,12 @@
|
|||
*
|
||||
* Redirect to a Character groups Quest Station.
|
||||
*
|
||||
* @param int $stationId ID of Character groups Quest Station
|
||||
* @param string $stationHash Hash of Character groups Quest Station
|
||||
*/
|
||||
public function cgqs($stationId)
|
||||
public function cgqs($stationHash)
|
||||
{
|
||||
// Get station
|
||||
$station = $this->Charactergroupsqueststations->getStationById($stationId);
|
||||
$station = $this->Charactergroupsqueststations->getStationByHash($stationHash);
|
||||
|
||||
// Get Character groups Quests
|
||||
$quest = $this->Charactergroupsquests->getQuestById($station['charactergroupsquest_id']);
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
$station = $this->Charactergroupsqueststations->getStationByUrl($quest['id'], $stationUrl);
|
||||
|
||||
// Generate QR-code
|
||||
$url = $this->linker->link(array('qr', 'cgqs', $station['id']), 0, true, null, true, null, true);
|
||||
$url = $this->linker->link(array('qr', 'cgqs', $station['url']), 0, true, null, true, null, true);
|
||||
$file = $this->generateQRcode($url, $size);
|
||||
if(is_null($file)) {
|
||||
return;
|
||||
|
|
|
@ -38,6 +38,12 @@
|
|||
* @var int;
|
||||
*/
|
||||
const STATUS_SOLVED = 3;
|
||||
/**
|
||||
* String length for Station URLs
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const URL_LENGTH = 10;
|
||||
|
||||
/**
|
||||
* Required models
|
||||
|
@ -86,11 +92,12 @@
|
|||
|
||||
|
||||
/**
|
||||
* Get a Station by its ID.
|
||||
* Get a Station by its URL.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param int $stationId ID of Station to get
|
||||
* @return array Station data
|
||||
* @param int $groupsquestId ID of Character groups Quest
|
||||
* @param string $stationUrl URL-title of Station to get
|
||||
* @return array Station data
|
||||
*/
|
||||
public function getStationByUrl($groupsquestId, $stationUrl)
|
||||
{
|
||||
|
@ -111,6 +118,31 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Station by its Hash.
|
||||
*
|
||||
* @throws \nre\exceptions\IdNotFoundException
|
||||
* @param string $stationUrl Hash of Station to get
|
||||
* @return array Station data
|
||||
*/
|
||||
public function getStationByHash($stationHash)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, charactergroupsquest_id, stationtype_id, title, url, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext, rightimage_id, rightav_id, wrongimage_id, wrongav_id '.
|
||||
'FROM charactergroupsqueststations '.
|
||||
'WHERE url = ?',
|
||||
's',
|
||||
$stationHash
|
||||
);
|
||||
if(empty($data)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($stationHash);
|
||||
}
|
||||
|
||||
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Stations for a Character groups Quest.
|
||||
*
|
||||
|
@ -455,7 +487,7 @@
|
|||
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
'iississddss',
|
||||
$questId, $stationtypeId, $title,
|
||||
\nre\core\Linker::createLinkParam($title), $pos,
|
||||
$this->createStationUrl(), $pos,
|
||||
$prolog, $task, $latitude, $longitude, $righttext, $wrongtext
|
||||
);
|
||||
|
||||
|
@ -482,11 +514,10 @@
|
|||
{
|
||||
$this->db->query(
|
||||
'UPDATE charactergroupsqueststations '.
|
||||
'SET stationtype_id = ?, title = ?, url = ?, prolog = ?, task = ?, latitude = ?, longitude = ?, righttext = ?, wrongtext = ? '.
|
||||
'SET stationtype_id = ?, title = ?, prolog = ?, task = ?, latitude = ?, longitude = ?, righttext = ?, wrongtext = ? '.
|
||||
'WHERE id = ?',
|
||||
'issssddssi',
|
||||
'isssddssi',
|
||||
$stationtypeId, $title,
|
||||
\nre\core\Linker::createLinkParam($title),
|
||||
$prolog, $task, $latitude, $longitude, $righttext, $wrongtext,
|
||||
$stationId
|
||||
);
|
||||
|
@ -599,6 +630,22 @@
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a URL for Stations with random characters.
|
||||
*
|
||||
* @return string A string with random characters
|
||||
*/
|
||||
private function createStationUrl()
|
||||
{
|
||||
// Length of URL
|
||||
$length = max(0, min(32, self::URL_LENGTH));
|
||||
|
||||
|
||||
// Create and return random string
|
||||
return substr(md5(microtime()), rand(0, 32-$length), $length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue