Page Menu
Home
Wolfplex
Search
Configure Global Search
Log In
Files
F408368
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
View Options
diff --git a/_includes/HackerspaceOpenStatus.php b/_includes/HackerspaceOpenStatus.php
index c5a07cb..975c2d3 100755
--- a/_includes/HackerspaceOpenStatus.php
+++ b/_includes/HackerspaceOpenStatus.php
@@ -1,79 +1,72 @@
<?php
/**
* Class to determine if the space is currently open or closed
*/
class HackerspaceOpenStatus {
private $isOpen;
public $date;
public $who;
public $comment;
/**
* Initializes a new instance of the HackerspaceOpenStatus object
*
* @param bool $isOpen true if the space is open; otherwise, false
* @param int $date The unixtime of the last modification
* @param string $who The name of the last person to have updated the status
* @param string $comment The comment associated to this operation
*/
public function __construct ($isOpen, $date = null, $who = '', $comment = '') {
$this->isOpen = $isOpen;
$this->date = ($date === null) ? time() : $date;
$this->who = $who;
$this->comment = $comment;
}
/**
* Determines if the space is currently open or closed
*
* @return bool True if the space is currently open; otherwise, false.
*/
public function IsOpen () {
return $this->isOpen;
}
}
/**
* Determines the hackerspace open status, using the wiki
*/
class MediaWikiHackerspaceOpenStatus extends HackerspaceOpenStatus {
/**
* Initializes a new instance of the HackerspaceOpenStatus object
*/
public function __construct ($api_url, $page_title, $open_content = 'yes') {
//Gets the last revision content and metadata from the wiki
$url = "$api_url?action=query&prop=revisions&titles=$page_title&rvprop=timestamp|user|comment|content&format=json";
$data = json_decode(file_get_contents($url), true);
$data = array_pop($data['query']['pages']);
$data = $data['revisions'][0];
//Fills properties
parent::__construct(
$data['*'] == $open_content,
strtotime($data['timestamp']),
self::is_ip($data['user']) ? '' : $data['user'],
$data['comment']
);
}
/**
* Determines if the expression is a valid IPv4 or IPv6
*
* @param string $expression The expression to validate
* @return bool true if the expression is a valid IP; otherwise, false.
*/
public static function is_ip ($expression) {
return
preg_match('/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/', $expression)
||
preg_match('/^(?>(?>([a-f0-9]{1,4})(?>:(?1)){7}|(?!(?:.*[a-f0-9](?>:|$)){8,})((?1)(?>:(?1)){0,6})?::(?2)?)|(?>(?>(?1)(?>:(?1)){5}:|(?!(?:.*[a-f0-9]:){6,})(?3)?::(?>((?1)(?>:(?1)){0,4}):)?)?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?4)){3}))$/iD', $expression);
;
}
}
-
-function get_hackerspace_open_status () {
- return new MediaWikiHackerspaceOpenStatus(
- 'http://www.wolfplex.org/w/api.php',
- 'Template:IsOpen/status'
- );
-}
diff --git a/space/index.php b/space/index.php
index 948bb74..99c7ff5 100755
--- a/space/index.php
+++ b/space/index.php
@@ -1,94 +1,98 @@
<?php
/**
* Wolfplex API - Space API implementation
*/
include("../_includes/CommonData.php");
include("../_includes/HackerspaceOpenStatus.php");
-$status = get_hackerspace_open_status();
+$status = new MediaWikiHackerspaceOpenStatus(
+ 'http://www.wolfplex.org/w/api.php',
+ 'Template:IsOpen/status'
+);
+
$document = [
'api' => '0.13',
'cache' => [
'schedule' => 'm.02', //Cache duration: 2 minutes
],
'space' => $HackerspaceData['name'],
'logo' => $HackerspaceData['logo']['default'],
'url' => $HackerspaceData['URL']['default'],
'location' => [
'address' => $HackerspaceData['places']['space']['address'],
'lat' => $HackerspaceData['places']['space']['coords'][0],
'lon' => $HackerspaceData['places']['space']['coords'][1],
],
'spacefed' => [
'spacenet' => false,
'spacesaml' => false,
'spacephone' => false,
],
'state' => [
'open' => $status->IsOpen(),
'lastchange' => $status->date,
'trigger_person' => $status->who,
'message' => $status->comment,
],
'contact' => [
'irc' => $HackerspaceData['URL']['IRC'],
'twitter' => $HackerspaceData['accounts']['twitter'],
'foursquare' => $HackerspaceData['accounts']['foursquare'],
'ml' => $HackerspaceData['lists']['default'],
'email' => $HackerspaceData['mail']['contact'],
'issue_mail' => base64_encode('spike@wolfplex.home.kg'),
],
'issue_report_channels' => [
'twitter',
'issue_mail',
],
'projects' => [
$HackerspaceData['URL']['projects'],
$HackerspaceData['URL']['github'],
$HackerspaceData['URL']['bitbucket'],
],
'feeds' => [
'wiki' => [
'type' => 'atom',
'url' => $HackerspaceData['URL']['wikiRecentChangesFeed'],
]
],
/*
We can add sensors information (e.g. temperature, humidity, amount of Club-Mate left, …).
See http://spaceapi.net/documentation#documentation-ref-13-root-sensors.
If we add webcam feeds:
'cam' => [
'URL1',
'URL2',
]
If we stream something:
'stream' => [
'm4' => '',
'mjpeg' => '',
'ustream' => '',
'ext_OURFORMAT' => '',
'ext_OURFORMAT2' => '', //should be prefixed with ext_
]
If we want to share events:
'events' => [
[
'name' => '', //Name or other identity of the subject (e.g. J. Random Hacker, fridge, 3D printer, …)
'type' => '', //check-in, check-out, finish-print, …
'timestamp' => time(), //unixtime
'extra' => '', //more info
],
//...
]
*/
];
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Cache-Control: max-age=120, must-revalidate');
echo json_encode($document, JSON_PRETTY_PRINT);
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jun 8, 8:51 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
46374
Default Alt Text
(5 KB)
Attached To
rAPI Wolfplex API
Event Timeline
Log In to Comment