mirror of
https://github.com/Mibew/mibew-operator-status-plugin.git
synced 2025-04-22 03:27:23 +03:00
Compare commits
No commits in common. "master" and "v0.2.0" have entirely different histories.
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,6 +1,2 @@
|
|||||||
# Do not index node.js modules that are used for building
|
*.zip
|
||||||
node_modules
|
*.gz
|
||||||
package-lock.json
|
|
||||||
|
|
||||||
# Do not index releases
|
|
||||||
release
|
|
@ -23,13 +23,11 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mibew\Mibew\Plugin\OperatorStatus\Controller;
|
namespace Everyx\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
|
||||||
@ -42,74 +40,27 @@ class OperatorStatusController extends AbstractController
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response Rendered page content
|
* @return Response Rendered page content
|
||||||
*/
|
*/
|
||||||
public function isOperatorOnlineAction(Request $request)
|
public function indexAction(Request $request)
|
||||||
{
|
{
|
||||||
$is_online = false;
|
$is_online = "true";
|
||||||
|
|
||||||
$opcode = $request->attributes->get('opcode');
|
$opcode = $request->attributes->get('opcode');
|
||||||
$online_operators = get_online_operators();
|
$online_operators = get_online_operators();
|
||||||
|
|
||||||
|
if ( count($online_operators) == 0 ) {
|
||||||
|
$is_online = "false";
|
||||||
|
} else if ( !empty($opcode) ) {
|
||||||
|
$is_online = "false";
|
||||||
foreach ($online_operators as $item) {
|
foreach ($online_operators as $item) {
|
||||||
if ($opcode == $item['code']) {
|
if ($item['code'] == $opcode) {
|
||||||
$is_online = true;
|
$is_online = "true";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$callback = $request->query->get('callback');
|
|
||||||
return $this->prepareResponse($is_online, $callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$response = new Response($is_online);
|
||||||
* 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', '*');
|
$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 Mibew\Mibew\Plugin\OperatorStatus;
|
namespace Everyx\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.4.0';
|
return '0.2.0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
45
README.md
45
README.md
@ -1,39 +1,14 @@
|
|||||||
# 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.
|
||||||
|
|
||||||
# Usage
|
# Useage
|
||||||
|
|
||||||
1. Get any operators online status:
|
Request `<MIBEW-BASE-URL>/opstatus/<OPERATOR-CODE>`, your will get `true` when operator
|
||||||
|
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. You can download it from the [official site](https://mibew.org/plugins#mibew-operator-status) or build the plugin from sources.
|
1. Get the archive with the plugin sources from [release page](https://github.com/everyx/mibew-operator-status-plugin/releases):
|
||||||
|
|
||||||
2. Untar/unzip the plugin's archive.
|
2. Untar/unzip the plugin's archive.
|
||||||
|
|
||||||
@ -58,16 +33,6 @@ 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
Executable file
22
build.sh
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/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
|
15
composer.json
Normal file
15
composer.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"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
44
gulpfile.js
@ -1,44 +0,0 @@
|
|||||||
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
12
package.json
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"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,14 +1,4 @@
|
|||||||
mibew_operator_status_has_online_operators:
|
everyx_operator_status:
|
||||||
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: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::isOperatorOnlineAction
|
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction
|
||||||
|
Loading…
Reference in New Issue
Block a user