Compare commits

..

No commits in common. "master" and "v0.1.0" have entirely different histories.

13 changed files with 95 additions and 233 deletions

6
.gitignore vendored
View File

@ -1,6 +0,0 @@
# Do not index node.js modules that are used for building
node_modules
package-lock.json
# Do not index releases
release

View File

@ -1,115 +0,0 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 everyx (lunt.luo@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Mibew\Mibew\Plugin\OperatorStatus\Controller;
use Mibew\Settings;
use Mibew\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Operator Status actions
*/
class OperatorStatusController extends AbstractController
{
/**
* Returns true or false of whether an operator is online or not.
*
* @param Request $request
* @return Response Rendered page content
*/
public function isOperatorOnlineAction(Request $request)
{
$is_online = false;
$opcode = $request->attributes->get('opcode');
$online_operators = get_online_operators();
foreach ($online_operators as $item) {
if ($opcode == $item['code']) {
$is_online = true;
break;
}
}
$callback = $request->query->get('callback');
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;
}
}

View File

@ -1,39 +1,18 @@
# Mibew Operator Status plugin
# mibew-operator-status-plugin
Plugin for Mibew, get statement based on the availability of operators.
# Usage
# Useage
1. Get any operators online status:
* 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);
```
Request `<MIBEW-BASE-URL>/opstatus?code=<OPERATOR-CODE>`, your will get `true` when operator
is online or `false` when operator is offline.
# 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 link bellow:
* [mibew-operator-status-plugin.tar.gz](archive/mibew-operator-status-plugin.tar.gz)
* [mibew-operator-status-plugin.zip](archive/mibew-operator-status-plugin.zip)
2. Untar/unzip the plugin's archive.
@ -58,16 +37,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
[MIT](LICENSE)

Binary file not shown.

Binary file not shown.

9
build.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
plugin_root_dir='Everyx'
plugin_target_dir="$plugin_root_dir/Mibew/Plugin/OperatorStatus"
mkdir -p $plugin_target_dir
cp -R src/* $plugin_target_dir
tar -czvf archive/mibew-operator-status-plugin.tar.gz $plugin_root_dir
zip -r archive/mibew-operator-status-plugin.zip $plugin_root_dir
rm -rf $plugin_root_dir

View File

@ -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;
}));
}

View File

@ -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"
}
}

View File

@ -1,14 +0,0 @@
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}
defaults:
_controller: Mibew\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::isOperatorOnlineAction

View File

@ -0,0 +1,56 @@
<?php
/*
* MIT License
*
* Copyright (c) 2016 everyx (lunt.luo@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Everyx\Mibew\Plugin\OperatorStatus\Controller;
use Mibew\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Operator Status actions
*/
class OperatorStatusController extends AbstractController
{
/**
* Returns true or false of whether an operator is online or not.
*
* @param Request $request
* @return Response Rendered page content
*/
public function indexAction(Request $request)
{
$is_online = "false";
$opcode = $request->query->get('code', false);
$online_operators = get_online_operators();
foreach ($online_operators as $item) {
if ($item['code'] == $opcode) {
$is_online = "true";
}
}
return new Response($is_online);
}
}

View File

@ -23,7 +23,7 @@
* SOFTWARE.
*/
namespace Mibew\Mibew\Plugin\OperatorStatus;
namespace Everyx\Mibew\Plugin\OperatorStatus;
/**
* Main plugin class.
@ -46,6 +46,6 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi
*/
public static function getVersion()
{
return '0.4.0';
return '0.1.0';
}
}

15
src/composer.json Normal file
View 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"
}

4
src/routing.yml Normal file
View File

@ -0,0 +1,4 @@
mibew_boilerplate_hello:
path: /opstatus
defaults:
_controller: Everyx\Mibew\Plugin\OperatorStatus\Controller\OperatorStatusController::indexAction