mirror of
https://github.com/Mibew/mibew-operator-status-plugin.git
synced 2025-04-12 06:50:13 +03:00
Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
7ebb2f84ad | |||
0aa7e62a6e | |||
47f91842e4 | |||
4a0a561c0a | |||
13b30db232 | |||
84c94f427a | |||
|
0269150a5f | ||
|
e662cc5e1a | ||
a8941cf2b3 | |||
1d9daa25ec | |||
|
638cfea943 | ||
|
ecc448482e | ||
|
0375ef42d7 | ||
|
cccbdc39ce | ||
15e18503f2 | |||
240cfad12a | |||
3ddcb227db | |||
|
5284d7e5ad | ||
|
3025f9e3cc | ||
|
66ee83b0b0 | ||
682ac0c4e6 | |||
|
8e5d1f6e47 |
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
*.zip
|
# Do not index node.js modules that are used for building
|
||||||
*.gz
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
|
# Do not index releases
|
||||||
|
release
|
@ -23,11 +23,13 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Everyx\Mibew\Plugin\OperatorStatus\Controller;
|
namespace Mibew\Mibew\Plugin\OperatorStatus\Controller;
|
||||||
|
|
||||||
|
use Mibew\Settings;
|
||||||
use Mibew\Controller\AbstractController;
|
use Mibew\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operator Status actions
|
* Operator Status actions
|
||||||
@ -37,30 +39,77 @@ class OperatorStatusController extends AbstractController
|
|||||||
/**
|
/**
|
||||||
* Returns true or false of whether an operator is online or not.
|
* Returns true or false of whether an operator is online or not.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response Rendered page content
|
* @return Response Rendered page content
|
||||||
*/
|
*/
|
||||||
public function indexAction(Request $request)
|
public function isOperatorOnlineAction(Request $request)
|
||||||
{
|
{
|
||||||
$is_online = "true";
|
$is_online = false;
|
||||||
|
|
||||||
$opcode = $request->attributes->get('opcode');
|
$opcode = $request->attributes->get('opcode');
|
||||||
$online_operators = get_online_operators();
|
$online_operators = get_online_operators();
|
||||||
|
foreach ($online_operators as $item) {
|
||||||
if ( count($online_operators) == 0 ) {
|
if ($opcode == $item['code']) {
|
||||||
$is_online = "false";
|
$is_online = true;
|
||||||
} else if ( !empty($opcode) ) {
|
break;
|
||||||
$is_online = "false";
|
|
||||||
foreach ($online_operators as $item) {
|
|
||||||
if ($item['code'] == $opcode) {
|
|
||||||
$is_online = "true";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new Response($is_online);
|
$callback = $request->query->get('callback');
|
||||||
$response->headers->set('Access-Control-Allow-Origin', '*');
|
return $this->prepareResponse($is_online, $callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true or false of whether any operators is online or not.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response Rendered page content
|
||||||
|
*/
|
||||||
|
public function hasOnlineOperatorsAction(Request $request)
|
||||||
|
{
|
||||||
|
$is_online = has_online_operators();
|
||||||
|
|
||||||
|
$callback = $request->query->get('callback');
|
||||||
|
return $this->prepareResponse($is_online, $callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true or false of whether any operators in specificed group is online or not.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response Rendered page content
|
||||||
|
*/
|
||||||
|
public function isOperatorGroupOnlineAction(Request $request)
|
||||||
|
{
|
||||||
|
$is_online = false;
|
||||||
|
|
||||||
|
$group_id = $request->attributes->get('group_id');
|
||||||
|
if (Settings::get('enablegroups') == '1') {
|
||||||
|
$is_online = has_online_operators($group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$callback = $request->query->get('callback');
|
||||||
|
return $this->prepareResponse($is_online, $callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns prepared response: JSONP or plain text.
|
||||||
|
*
|
||||||
|
* @param Boolean $is_online
|
||||||
|
* @param String $callback
|
||||||
|
* @return Response Rendered page content
|
||||||
|
*/
|
||||||
|
private function prepareResponse($is_online, $callback) {
|
||||||
|
$response = NULL;
|
||||||
|
|
||||||
|
if ( empty($callback) ) {
|
||||||
|
$response = new Response( $is_online ? 'true' : 'false' );
|
||||||
|
$response->headers->set('Access-Control-Allow-Origin', '*');
|
||||||
|
} else {
|
||||||
|
$response = new JsonResponse($is_online);
|
||||||
|
$response->setCallback($callback);
|
||||||
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Everyx\Mibew\Plugin\OperatorStatus;
|
namespace Mibew\Mibew\Plugin\OperatorStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main plugin class.
|
* Main plugin class.
|
||||||
@ -46,6 +46,6 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi
|
|||||||
*/
|
*/
|
||||||
public static function getVersion()
|
public static function getVersion()
|
||||||
{
|
{
|
||||||
return '0.2.0';
|
return '0.4.0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
45
README.md
45
README.md
@ -1,14 +1,39 @@
|
|||||||
# mibew-operator-status-plugin
|
# Mibew Operator Status plugin
|
||||||
Plugin for Mibew, get statement based on the availability of operators.
|
Plugin for Mibew, get statement based on the availability of operators.
|
||||||
|
|
||||||
# Useage
|
# Usage
|
||||||
|
|
||||||
Request `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>`, your will get `true` when operator
|
1. Get any operators online status:
|
||||||
is online or `false` when operator is offline.
|
|
||||||
|
* request URL: `<MIBEW-BASE-URL>/opstatus`.
|
||||||
|
* return `true` when any operators is online and `false` when not.
|
||||||
|
|
||||||
|
2. Get any operators online status in specificed group:
|
||||||
|
|
||||||
|
* request URL: `<MIBEW-BASE-URL>/opstatus/group/<GROUP-ID>`.
|
||||||
|
* return `true` when any operators in this group is online and `false` when not.
|
||||||
|
|
||||||
|
3. Get an operator online status by operator code:
|
||||||
|
|
||||||
|
* Request URL: `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>`.
|
||||||
|
* return `true` when operator is online or `false` when not.
|
||||||
|
|
||||||
|
4. Use callback parameter:
|
||||||
|
|
||||||
|
Just insert `<script>` tag and set `src` to URL above and add `callback` parameter
|
||||||
|
|
||||||
|
* `<MIBEW-BASE-URL>/opstatus?callback=<CALLBACK_FUNCTION>`
|
||||||
|
* `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>?callback=<CALLBACK_FUNCTION>`
|
||||||
|
|
||||||
|
will return bellow and run `CALLBACK_FUNCTION` automatically.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
/**/CALLBACK_FUNCTION(status);
|
||||||
|
```
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
1. Get the archive with the plugin sources from [release page](https://github.com/everyx/mibew-operator-status-plugin/releases):
|
1. Get the archive with the plugin sources. You can download it from the [official site](https://mibew.org/plugins#mibew-operator-status) or build the plugin from sources.
|
||||||
|
|
||||||
2. Untar/unzip the plugin's archive.
|
2. Untar/unzip the plugin's archive.
|
||||||
|
|
||||||
@ -33,6 +58,16 @@ plugins:
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Build from sources
|
||||||
|
|
||||||
|
1. Obtain a copy of the repository using `git clone`, download button, or another way.
|
||||||
|
2. Install [node.js](http://nodejs.org/) and [npm](https://www.npmjs.org/).
|
||||||
|
3. Install [Gulp](http://gulpjs.com/).
|
||||||
|
4. Install npm dependencies using `npm install`.
|
||||||
|
5. Run Gulp to build the sources using `gulp default`.
|
||||||
|
|
||||||
|
Finally `.tar.gz` and `.zip` archives of the ready-to-use Plugin will be available in release directory.
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
[MIT](LICENSE)
|
[MIT](LICENSE)
|
||||||
|
22
build.sh
22
build.sh
@ -1,22 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
author='Everyx'
|
|
||||||
|
|
||||||
tmp_dir='/tmp'
|
|
||||||
working_dir=`echo $PWD`
|
|
||||||
|
|
||||||
target_dir="$tmp_dir/$author/Mibew/Plugin/OperatorStatus"
|
|
||||||
mkdir -p $target_dir
|
|
||||||
|
|
||||||
shopt -s extglob
|
|
||||||
cp -R !(*.sh) $target_dir
|
|
||||||
shopt -u extglob
|
|
||||||
|
|
||||||
version=`cat Plugin.php|grep -Po "(?<=return ')(\d.){2}\d{1}"`
|
|
||||||
|
|
||||||
cd $tmp_dir
|
|
||||||
|
|
||||||
tar -czvf $working_dir/mibew-operator-status-plugin.$version.tar.gz $author
|
|
||||||
zip -r $working_dir/mibew-operator-status-plugin.$version.zip $author
|
|
||||||
|
|
||||||
rm -rf $plugin_root_dir
|
|
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "everyx/mibew-operator-status-plugin",
|
|
||||||
"description": "An operator status plugin for Mibew 2.0.",
|
|
||||||
"license": "MIT",
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "everyx",
|
|
||||||
"email": "lunt.luo@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {"Everyx\\Mibew\\Plugin\\OperatorStatus\\": ""}
|
|
||||||
},
|
|
||||||
"target-dir": "Everyx/Mibew/Plugin/OperatorStatus"
|
|
||||||
}
|
|
44
gulpfile.js
Normal file
44
gulpfile.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
var eventStream = require('event-stream'),
|
||||||
|
gulp = require('gulp'),
|
||||||
|
chmod = require('gulp-chmod'),
|
||||||
|
zip = require('gulp-zip'),
|
||||||
|
tar = require('gulp-tar'),
|
||||||
|
gzip = require('gulp-gzip'),
|
||||||
|
rename = require('gulp-rename');
|
||||||
|
|
||||||
|
gulp.task('prepare-release', function() {
|
||||||
|
var version = require('./package.json').version;
|
||||||
|
|
||||||
|
return eventStream.merge(
|
||||||
|
getSources()
|
||||||
|
.pipe(zip('operator-status-plugin-' + version + '.zip')),
|
||||||
|
getSources()
|
||||||
|
.pipe(tar('operator-status-plugin-' + version + '.tar'))
|
||||||
|
.pipe(gzip())
|
||||||
|
)
|
||||||
|
.pipe(chmod(0644))
|
||||||
|
.pipe(gulp.dest('release'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Builds and packs plugins sources
|
||||||
|
gulp.task('default', gulp.series('prepare-release'));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns files stream with the plugin sources.
|
||||||
|
*
|
||||||
|
* @returns {Object} Stream with VinylFS files.
|
||||||
|
*/
|
||||||
|
var getSources = function() {
|
||||||
|
return gulp.src([
|
||||||
|
'Controller/*',
|
||||||
|
'LICENSE',
|
||||||
|
'Plugin.php',
|
||||||
|
'README.md',
|
||||||
|
'routing.yml'
|
||||||
|
],
|
||||||
|
{base: './'}
|
||||||
|
)
|
||||||
|
.pipe(rename(function(path) {
|
||||||
|
path.dirname = 'Mibew/Mibew/Plugin/OperatorStatus/' + path.dirname;
|
||||||
|
}));
|
||||||
|
}
|
12
package.json
Normal file
12
package.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"version": "0.4.0",
|
||||||
|
"devDependencies": {
|
||||||
|
"event-stream": "3.3.4",
|
||||||
|
"gulp": "^4.0.0",
|
||||||
|
"gulp-chmod": "~3.0.0",
|
||||||
|
"gulp-gzip": "~1.1.0",
|
||||||
|
"gulp-rename": "~1.2.2",
|
||||||
|
"gulp-tar": "~3.1.0",
|
||||||
|
"gulp-zip": "~3.0.2"
|
||||||
|
}
|
||||||
|
}
|
14
routing.yml
14
routing.yml
@ -1,4 +1,14 @@
|
|||||||
everyx_operator_status:
|
mibew_operator_status_has_online_operators:
|
||||||
|
path: /opstatus
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::hasOnlineOperatorsAction
|
||||||
|
|
||||||
|
mibew_operator_status_has_online_group_operators:
|
||||||
|
path: /opstatus/group/{group_id}
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::isOperatorGroupOnlineAction
|
||||||
|
|
||||||
|
mibew_operator_status_is_operator_online:
|
||||||
path: /opstatus/{opcode}
|
path: /opstatus/{opcode}
|
||||||
defaults:
|
defaults:
|
||||||
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction
|
_controller: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::isOperatorOnlineAction
|
||||||
|
Loading…
Reference in New Issue
Block a user