Skip to content

Commit

Permalink
Merge pull request #97 from Erwane/raidplannerdb-source
Browse files Browse the repository at this point in the history
Raidplannerdb source
  • Loading branch information
st3ph authored Dec 12, 2019
2 parents f3a59c2 + faf134d commit 1f2af9d
Show file tree
Hide file tree
Showing 723 changed files with 10,959 additions and 6,928 deletions.
2 changes: 1 addition & 1 deletion app/Config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


Configure::write('debug', 0);
Configure::write('mushraider', array('version' => '1.7.0.3', 'date' => '2019-01-17'));
Configure::write('mushraider', array('version' => '1.7.0.4', 'date' => '2019-12-12'));

/**
* Configure the Error handler used to handle errors for your application. By default
Expand Down
6 changes: 3 additions & 3 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function beforeFilter() {
// If config isn't set, redirect to install process to create one
if(!Configure::read('Settings.installed') && strtolower($this->plugin) != 'install') {
$this->Session->setFlash(__('MushRaider is ready for install, what about you ?'), 'flash_info');
$this->redirect('/install/step/1');
$this->redirect('/install/step/1');
}

// Language
Expand Down Expand Up @@ -91,7 +91,7 @@ public function beforeFilter() {

// Log in user
if($this->Session->check('User.id')) {
$userID = $this->Session->read('User.id');
$userID = $this->Session->read('User.id');
if(!empty($userID)) {
$params = array();
$params['recursive'] = 1;
Expand Down Expand Up @@ -136,7 +136,7 @@ public function beforeRender() {
// SEO
$this->pageTitle .= !empty($this->request->params['named']['page'])?' - page '.$this->request->params['named']['page']:'';
$this->pageDescription .= !empty($this->request->params['named']['page'])?' - page '.$this->request->params['named']['page']:'';

$this->set('title_for_layout', $this->pageTitle);
$this->set('description_for_layout', $this->pageDescription);
$this->set('breadcrumb', $this->breadcrumb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
App::uses('HttpSocket', 'Network/Http');
App::uses('Configure', 'Core');

class RaidheadSource extends DataSource {
class RaidplannerDbSource extends DataSource {

public $config = array(
'baseUrl' => 'https://api.raidhead.com/',
'baseUrl' => 'https://db.raidplanner.org/',
'langs' => array('eng', 'fra')
);

Expand All @@ -36,6 +36,7 @@ public function __construct() {
private function _get($uri)
{
$client = new HttpSocket(array(
'timeout' => 5,
'request' => array(
'redirect' => 2,
),
Expand All @@ -61,7 +62,7 @@ private function _get($uri)
}

public function gets($type = 'all') {
$games = $this->_get('/games/index.json');
$games = $this->_get('/games.json');

if($type == 'list') {
$list = array();
Expand All @@ -76,10 +77,6 @@ public function gets($type = 'all') {
}

public function get($slug) {
return $this->_get('/games/get/' . $slug . '.json');
}

public function serverStatus($slug) {
return $this->_get('/server_status/get/' . $slug . '.json');
return $this->_get('/game/' . $slug . '.json');
}
}
13 changes: 8 additions & 5 deletions app/Plugin/Admin/Controller/AdminAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ private function checkUpdate() {
$mushraider['date'] = '0000-00-00';
}
$jsonUrl = 'http://medias.mushraider.com/version.json';
$HttpSocket = new HttpSocket();
$json = $HttpSocket->get($jsonUrl);
$lastVersion = json_decode($json->body);
$HttpSocket = new HttpSocket(['timeout' => 1]);
$response = $HttpSocket->get($jsonUrl);
if (empty($response->body)) {
return;
}
$lastVersion = json_decode($response->body);
// Check if version is different
// Be sure the server is newer than the current app
// Be sure the server is newer than the current app
if(($mushraider['version'] != $lastVersion->version && $mushraider['date'] < $lastVersion->date) || ($mushraider['version'] == $lastVersion->version && $mushraider['date'] < $lastVersion->date)) {
$updateMsg = __('<strong>MushRaider %s</strong> is available! <a href="http://mushraider.com/download" target="_blank">Please update now</a>', $lastVersion->version);
$this->set('updateAvailable', $updateMsg);
}
}
}
}
22 changes: 11 additions & 11 deletions app/Plugin/Admin/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function importGame() {
$slug = $this->request->query['slug'];
$this->Session->write('ajaxProgress', 10);

App::uses('RaidheadSource', 'Model/Datasource');
$RaidHead = new RaidheadSource();
$game = $RaidHead->get($slug);
App::uses('RaidplannerDbSource', 'Model/Datasource');
$source = new RaidplannerDbSource();
$game = $source->get($slug);

// Check API error
if($game['error']) {
Expand All @@ -71,7 +71,7 @@ public function importGame() {
$toSave['slug'] = $game['game']['short'];
$toSave['logo'] = $game['game']['icon_64'];
$toSave['import_slug'] = $game['game']['short'];
$toSave['import_modified'] = $game['lastupdate'];
$toSave['import_modified'] = strtotime($game['lastupdate']);
if(!$gameId = $GameModel->__add($toSave)) {
$jsonMessage['type'] = 'important';
$jsonMessage['msg'] = __('Save failed : An error occur while saving the game');
Expand Down Expand Up @@ -139,7 +139,7 @@ public function importGame() {
$ClasseModel->__add($toSaveClasses, array('game_id' => $gameId));
}
}

$this->Session->write('ajaxProgress', 100);

$jsonMessage['type'] = 'success';
Expand All @@ -155,7 +155,7 @@ public function importGame() {
public function ajaxProgress() {
$progress = 0;
if($this->Session->check('ajaxProgress')) {
$progress = $this->Session->read('ajaxProgress');
$progress = $this->Session->read('ajaxProgress');
}

return $progress;
Expand All @@ -167,11 +167,11 @@ public function checkUpdates() {
App::uses('Game', 'Model');
$GameModel = new Game();

App::uses('RaidheadSource', 'Model/Datasource');
$RaidHead = new RaidheadSource();
$apiGames = $RaidHead->gets();
App::uses('RaidplannerDbSource', 'Model/Datasource');
$source = new RaidplannerDbSource();
$apiGames = $source->gets();

$params = array();
$params = array();
$params['recursive'] = -1;
$params['fields'] = array('import_slug', 'import_modified');
$params['conditions']['import_slug !='] = null;
Expand All @@ -187,4 +187,4 @@ public function checkUpdates() {

return json_encode($jsonList);
}
}
}
18 changes: 9 additions & 9 deletions app/Plugin/Admin/Controller/GamesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function add() {
$this->Session->setFlash(__('Something goes wrong'), 'flash_error');
}
}else {
$this->Session->setFlash($imageName['error'], 'flash_error');
$this->Session->setFlash($imageName['error'], 'flash_error');
}
}

Expand All @@ -99,7 +99,7 @@ public function edit($id = null) {
$params['recursive'] = 1;
$params['contain']['Classe'] = array();
$params['contain']['Dungeon'] = array();
$params['contain']['Race'] = array();
$params['contain']['Race'] = array();
$params['conditions']['Game.id'] = $id;
if(!$game = $this->Game->find('first', $params)) {
$this->Session->setFlash(__('MushRaider is unable to find this game oO'), 'flash_error');
Expand Down Expand Up @@ -193,7 +193,7 @@ public function edit($id = null) {
$this->Session->setFlash(__('Something goes wrong'), 'flash_error');
}
}else {
$this->Session->setFlash($imageName['error'], 'flash_error');
$this->Session->setFlash($imageName['error'], 'flash_error');
}

$game['Game'] = array_merge($game['Game'], $this->request->data['Game']);
Expand All @@ -209,13 +209,13 @@ public function edit($id = null) {
$this->set('racesList', $racesList);


$this->request->data = array_merge($game, $this->request->data);
$this->request->data = array_merge($game, $this->request->data);
}

public function import() {
App::uses('RaidheadSource', 'Model/Datasource');
$RaidHead = new RaidheadSource();
$this->set('gamesList', $RaidHead->gets('list'));
App::uses('RaidplannerDbSource', 'Model/Datasource');
$source = new RaidplannerDbSource();
$this->set('gamesList', $source->gets('list'));
}

public function delete($id = null) {
Expand All @@ -232,7 +232,7 @@ public function delete($id = null) {
$this->Session->setFlash(__('Something goes wrong'), 'flash_error');
}
}

$this->redirect('/admin/games');
}
}
}
6 changes: 3 additions & 3 deletions app/Plugin/Admin/View/Games/import.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<div class="accordion-body body in collapse">
<div class="alert alert-info">
<h4><i class="fa fa-info-circle"></i> <?php echo __('What is that ?');?></h4>
<p><?php echo __('MushRaider can import games data from the RaidHead.com API');?></p>
<p><?php echo __('RaidHead.com API supports many games, the import system allows you to add a new game (and keep it up to date) in just one click !');?></p>
<p><?php echo __('MushRaider can import games data from the Raidplanner.org DB');?></p>
<p><?php echo __('Raidplanner.org DB supports many games, the import system allows you to add a new game (and keep it up to date) in just one click !');?></p>
</div>

<div class="importForm">
Expand All @@ -25,4 +25,4 @@
</div>
</div>
</div>
</div>
</div>
24 changes: 19 additions & 5 deletions lib/Cake/Cache/Cache.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @package Cake.Cache
* @since CakePHP(tm) v 1.2.0.4933
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

App::uses('Inflector', 'Utility');
Expand Down Expand Up @@ -616,4 +616,18 @@ public static function add($key, $value, $config = 'default') {
self::set(null, $config);
return $success;
}

/**
* Fetch the engine attached to a specific configuration name.
*
* @param string $config Optional string configuration name to get an engine for. Defaults to 'default'.
* @return null|CacheEngine Null if the engine has not been initialized or the engine.
*/
public static function engine($config = 'default') {
if (self::isInitialized($config)) {
return self::$_engines[$config];
}

return null;
}
}
12 changes: 6 additions & 6 deletions lib/Cake/Cache/CacheEngine.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @package Cake.Cache
* @since CakePHP(tm) v 1.2.0.4933
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

/**
Expand Down Expand Up @@ -181,7 +181,7 @@ public function key($key) {

$prefix = '';
if (!empty($this->_groupPrefix)) {
$prefix = vsprintf($this->_groupPrefix, $this->groups());
$prefix = md5(implode('_', $this->groups()));
}

$key = preg_replace('/[\s]+/', '_', strtolower(trim(str_replace(array(DS, '/', '.'), '_', strval($key)))));
Expand Down
10 changes: 5 additions & 5 deletions lib/Cake/Cache/Engine/ApcEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
/**
* APC storage engine for cache.
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @package Cake.Cache.Engine
* @since CakePHP(tm) v 1.2.0.4933
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

/**
Expand Down
20 changes: 14 additions & 6 deletions lib/Cake/Cache/Engine/FileEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
*
* You can configure a FileEngine cache, using Cache::config()
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 1.2.0.4933
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

/**
Expand Down Expand Up @@ -267,6 +267,10 @@ protected function _clearDirectory($path, $now, $threshold) {
}

$dir = dir($path);
if ($dir === false) {
return;
}

while (($entry = $dir->read()) !== false) {
if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) {
continue;
Expand Down Expand Up @@ -348,7 +352,11 @@ protected function _setKey($key, $createKey = false) {
if (!$createKey && !$path->isFile()) {
return false;
}
if (empty($this->_File) || $this->_File->getBaseName() !== $key) {
if (
empty($this->_File) ||
$this->_File->getBaseName() !== $key ||
$this->_File->valid() === false
) {
$exists = file_exists($path->getPathname());
try {
$this->_File = $path->openFile('c+');
Expand Down
Loading

0 comments on commit 1f2af9d

Please sign in to comment.