* fixed #194 PHP 5.6 error * - closed #102 added "set waypoint/destination" context menu to route finder module - update "Select2" 4.0.0 -> 4.0.3 - update "Font Awesome" 4.6.1 -> 4.6.3 * - added *.js files for develop branch * - closed #195 fixed "BASE" dir for subDir installations - fixed "Home" menu link * - #195 improved js load path * - added "clear cache" function for manually cache clearing to /setup #200 #105 #158 - added cache size information to /setup - added current pathfinder "VERSION" to /setup - updated "requireJs" 2.1.20 ->2.2.0 - removed unnecessary page cache timings from static templates (page cache) * - added "document_root", "port", "protocol" and "PHP framework version" to /setup page - added new "shattered" wormhole types to "signature table", closed #182, #179 * - added new "delete old signatures" option to "signature reader" dialog, closed #95 * - added new housekeeping cronjob für cached files, closed #200 - added new cache size information to /setup page * - fixed signature groupId/typeId "overwriting" for already known signatures. closed #207 - improved system search dialog. Added trim(); before "api/signatures-> search" request * updated README.me * fixed PHP error "default object from empty value", closed #209 * reduced image file size * - added local storage (IndexedDB) - added local storage for map scroll position. closed #69 * - added "notice" panel for upcoming release information - improved layout for "release dialog" (GitHub API) - improved pagespeed (removed render blocking javascripts) - improved map scrollbar configuration - improved Chrome browser custom scrollbar layout - removed "sign up" buttons from "map panels", closed #214 * - fixed some session and cookie bugs * - added new requirement check for `max_input_vars` to /setup URL, closed #224 * - fixed isWormhole(); bug * -v1.1.1 added js build files
86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: exodus4d
|
|
* Date: 16.01.16
|
|
* Time: 03:34
|
|
*/
|
|
|
|
namespace Controller\Api;
|
|
use Model;
|
|
use Controller;
|
|
|
|
|
|
/**
|
|
* Github controller
|
|
* Class Route
|
|
* @package Controller\Api
|
|
*/
|
|
class GitHub extends Controller\Controller {
|
|
|
|
/**
|
|
* get HTTP request options for API (curl) request
|
|
* @return array
|
|
*/
|
|
protected function getRequestOptions(){
|
|
$requestOptions = [
|
|
'timeout' => 8,
|
|
'method' => 'GET',
|
|
'user_agent' => $this->getUserAgent(),
|
|
'follow_location' => false // otherwise CURLOPT_FOLLOWLOCATION will fail
|
|
];
|
|
|
|
return $requestOptions;
|
|
}
|
|
|
|
/**
|
|
* get release information from GitHub
|
|
* @param $f3
|
|
*/
|
|
public function releases($f3){
|
|
$cacheKey = 'CACHE_GITHUB_RELEASES';
|
|
$ttl = 60 * 30; // 30min
|
|
$releaseCount = 4;
|
|
|
|
if( !$f3->exists($cacheKey) ){
|
|
$apiPath = $this->getF3()->get('PATHFINDER.API.GIT_HUB') . '/repos/exodus4d/pathfinder/releases';
|
|
|
|
// build request URL
|
|
$options = $this->getRequestOptions();
|
|
$apiResponse = \Web::instance()->request($apiPath, $options );
|
|
|
|
if($apiResponse['body']){
|
|
// request succeeded -> format "Markdown" to "HTML"
|
|
// result is JSON formed
|
|
$releasesData = (array)json_decode($apiResponse['body']);
|
|
|
|
// check max release count
|
|
if(count($releasesData) > $releaseCount){
|
|
$releasesData = array_slice($releasesData, 0, $releaseCount);
|
|
}
|
|
|
|
$md = \Markdown::instance();
|
|
foreach($releasesData as &$releaseData){
|
|
if(isset($releaseData->body)){
|
|
|
|
// convert list style
|
|
$body = str_replace(' - ', '* ', $releaseData->body );
|
|
|
|
$releaseData->body = $md->convert( $body );
|
|
}
|
|
}
|
|
$f3->set($cacheKey, $releasesData, $ttl);
|
|
}else{
|
|
// request failed -> cache failed result (respect API request limit)
|
|
$f3->set($cacheKey, false, 60 * 5);
|
|
}
|
|
}
|
|
|
|
// set 503 if service unavailable or temp cached data = false
|
|
if( !$f3->get($cacheKey) ){
|
|
$f3->status(503);
|
|
}
|
|
|
|
echo json_encode($f3->get($cacheKey));
|
|
}
|
|
} |