Skip to content

Commit 36af65e

Browse files
committed
Squashed commit of the following:
commit f671ab6 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:54:50 2015 +0100 cs-fixer update commit 02b6680 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:52:44 2015 +0100 add style configs commit 662d0d0 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:52:13 2015 +0100 ignore some stuff commit 8e654c1 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:49:11 2015 +0100 apply cs-fixer commit 903fe05 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:47:57 2015 +0100 update readme commit 09a171f Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:47:49 2015 +0100 add more php versions commit 2ec3229 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:34:31 2015 +0100 add phpunit test commit 68f7dc2 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 19:05:19 2015 +0100 move tests to top level commit 1e6c3cb Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 15:09:17 2015 +0100 fix base url commit bdeea75 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 14:58:29 2015 +0100 fix path to config file commit bd248e0 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 14:49:27 2015 +0100 remove obsolete config copy commit 4d2f5db Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 14:45:05 2015 +0100 split sed in two commit 446463c Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 14:29:49 2015 +0100 add travis tests commit c26dc36 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 12:04:04 2015 +0100 update unit tests commit 795f778 Author: Michiel Dethmers <[email protected]> Date: Wed Oct 21 12:03:47 2015 +0100 phpdoc update
1 parent f581bd1 commit 36af65e

33 files changed

+1437
-955
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
plugins/restapi/output/
3+
/composer.lock
4+
/.php_cs.cache

.php_cs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
// Needed to get styleci-bridge loaded
4+
require_once __DIR__.'/vendor/autoload.php';
5+
6+
use SLLH\StyleCIBridge\ConfigBridge;
7+
8+
return ConfigBridge::create()
9+
->setUsingCache(true)
10+
;
11+
12+
$finder = Symfony\CS\Finder\DefaultFinder::create()
13+
->exclude('admin/help')
14+
->exclude('admin/info')
15+
->exclude('public_html/texts')
16+
->exclude('admin/ui')
17+
->exclude('admin/locale')
18+
->exclude('admin/PHPMailer')
19+
->in(__DIR__)
20+
;
21+
22+
return Symfony\CS\Config\Config::create()
23+
// ->level(Symfony\CS\FixerInterface::PSR0_LEVEL) /* default is symfony */
24+
// ->level(Symfony\CS\FixerInterface::NONE_LEVEL)
25+
->fixers(array('trailing_spaces', 'encoding', 'align_double_arrow', 'newline_after_open_tag', 'ordered_use', 'long_array_syntax'))
26+
->finder($finder)
27+
;

.styleci.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
preset: symfony
2+
3+
enabled:
4+
- align_double_arrow
5+
- newline_after_open_tag
6+
- ordered_use
7+
- long_array_syntax
8+
9+
disabled:
10+
- unalign_double_arrow
11+
- unalign_equals
12+
13+
finder:
14+
exclude:
15+
- "hostedplugins"
16+
- "public_html/lists/admin/plugins"
17+
- "public_html/lists/admin/PHPMailer"
18+
- "public_html/lists/admin/help"
19+
- "public_html/lists/admin/info"
20+
- "public_html/lists/admin/locale"
21+
- "public_html/lists/admin/ui"
22+
23+

.travis.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Configuration file for running the test suite. Results will be at https://travis-ci.org/phpList/phplist-plugin-restapi
2+
# whitelist
3+
language: php
4+
php:
5+
- 7.0
6+
- 5.6
7+
- 5.5
8+
- 5.4
9+
- 5.3
10+
11+
before_script:
12+
- sudo apt-get update > /dev/null
13+
- sudo apt-get install -y --force-yes apache2 libapache2-mod-php5 php5-curl php5-mysql php5-intl
14+
# Set a custom vhost
15+
- sudo sed -i -e "s,/var/www,$(pwd)/vendor/phpList/phplist3/public_html,g" /etc/apache2/sites-available/default
16+
- sudo sed -i -e "/DocumentRoot/i\ServerName phplist.dev" /etc/apache2/sites-available/default
17+
- sudo sed -i -e "/DocumentRoot/i\SetEnv ConfigFile $(pwd)/tests/travis-ci/config.php" /etc/apache2/sites-available/default
18+
- echo "127.0.0.1 phplist.dev" | sudo tee -a /etc/hosts
19+
- sudo cat /etc/apache2/sites-available/default
20+
- sudo /etc/init.d/apache2 restart
21+
- composer self-update
22+
- composer install --dev --prefer-dist
23+
- sudo cp -f tests/travis-ci/behat.yml behat.yml
24+
25+
# Set MySQL configuration and create the database.
26+
- mysql -e 'SET GLOBAL wait_timeout = 5400;'
27+
- mysql -e 'create database phplisttraviscidb;'
28+
29+
script:
30+
- vendor/bin/behat
31+
- phpunit -c tests/phpunit/phpunit.xml tests/phpunit/restapi.php
32+
after_failure:
33+
- echo "Failures detected. Outputing additional logs:"
34+
- sudo cat /var/log/apache2/error.log
35+
- sudo cat /var/log/mysql/error.log

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ License: GPLv3 or later
1212
##History
1313
```
1414
v. Date Description
15+
2015-10-21 Added Travis integration
1516
0.3 2014-05-31 Moved to phpList organisation and renamed phplist-plugin-restapi
1617
0.2.7 2013-03-13 Added order and limit to listsGet
1718
0.2.6 2013-03-13 Test script fixed with login and password.

composer.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"repositories": [
3+
{
4+
"type": "vcs",
5+
"url": "https://github.com/phpList/phplist3"
6+
}
7+
],
8+
"require": {
9+
"phpList/phplist3": "master"
10+
},
11+
"require-dev": {
12+
"behat/mink": "~1.4",
13+
"behat/mink-goutte-driver": "~1.2",
14+
"behat/mink-selenium2-driver": "~1.3",
15+
"behat/behat": "~2.4",
16+
"behat/mink-extension": "~1.3",
17+
"fabpot/goutte": "1.*@stable",
18+
"sllh/php-cs-fixer-styleci-bridge": "~1.3",
19+
"phpunit/phpunit": "3.7.*"
20+
},
21+
"minimum-stability": "dev",
22+
"prefer-stable": true,
23+
"config": {
24+
"bin-dir": "vendor/bin/"
25+
}
26+
}

plugins/restapi.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
2+
23
/**
3-
* Plugin that implements a REST API
4+
* Plugin that implements a REST API.
45
*
56
* Documentation: http://resources.phplist.com/plugin/restapi
67
*
@@ -15,23 +16,24 @@
1516
*/
1617
defined('PHPLISTINIT') || die;
1718

18-
class restapi extends phplistPlugin {
19-
20-
public $name = "RESTAPI";
19+
class restapi extends phplistPlugin
20+
{
21+
public $name = 'RESTAPI';
2122
public $description = 'Implements a REST API interface to phpList';
2223
public $topMenuLinks = array(
2324
'main' => array('category' => 'system'),
24-
);
25+
);
2526

26-
function restapi() {
27-
parent::phplistplugin();
28-
$this->coderoot = dirname(__FILE__) . '/restapi/';
27+
public function restapi()
28+
{
29+
parent::phplistplugin();
30+
$this->coderoot = dirname(__FILE__).'/restapi/';
2931
}
3032

31-
function adminmenu() {
33+
public function adminmenu()
34+
{
3235
return array(
33-
"main" => "RESTAPI"
36+
'main' => 'RESTAPI',
3437
);
3538
}
36-
3739
}

plugins/restapi/call.php

+29-19
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ob_end_clean();
99

1010
//Getting phpList globals for this plugin
11-
$plugin = $GLOBALS["plugins"][$_GET["pi"]];
11+
$plugin = $GLOBALS['plugins'][$_GET['pi']];
1212

1313
include 'includes/response.php';
1414
include 'includes/pdo.php';
@@ -24,38 +24,48 @@
2424
include 'doc/doc.php';
2525

2626
if (function_exists('api_request_log')) {
27-
api_request_log();
27+
api_request_log();
2828
}
2929

3030
//Check if this is called outside phpList auth, this should never occur!
31-
if ( empty( $plugin->coderoot ) ){
32-
Response::outputErrorMessage( 'Not authorized! Please login with [login] and [password] as admin first!' );
31+
if (empty($plugin->coderoot)) {
32+
Response::outputErrorMessage('Not authorized! Please login with [login] and [password] as admin first!');
3333
}
3434

3535
//If other than POST then assume documentation report
36-
if ( strcmp( $_SERVER['REQUEST_METHOD'], "POST") ) {
36+
if (strcmp($_SERVER['REQUEST_METHOD'], 'POST')) {
3737
$doc = new \phpListRestapiDoc();
38-
$doc->addClass( 'Actions' );
39-
$doc->addClass( 'Lists' );
40-
$doc->addClass( 'Subscribers' );
41-
$doc->addClass( 'Templates' );
42-
$doc->addClass( 'Messages' );
38+
$doc->addClass('Actions');
39+
$doc->addClass('Lists');
40+
$doc->addClass('Subscribers');
41+
$doc->addClass('Templates');
42+
$doc->addClass('Messages');
4343
$doc->output();
4444
}
4545

4646
//Check if command is empty!
4747
$cmd = $_REQUEST['cmd'];
48-
$cmd = preg_replace('/\W/','',$cmd);
49-
if ( empty($cmd) ){
50-
Response::outputMessage('OK! For action, please provide Post Param Key [cmd] !');
48+
$cmd = preg_replace('/\W/', '', $cmd);
49+
if (empty($cmd)) {
50+
Response::outputMessage('OK! For action, please provide Post Param Key [cmd] !');
5151
}
5252

5353
//Now bind the commands with static functions
54-
if ( is_callable( array( 'phpListRestapi\Lists', $cmd ) ) ) Lists::$cmd();
55-
if ( is_callable( array( 'phpListRestapi\Actions', $cmd ) ) ) Actions::$cmd();
56-
if ( is_callable( array( 'phpListRestapi\Subscribers', $cmd ) ) ) Subscribers::$cmd();
57-
if ( is_callable( array( 'phpListRestapi\Templates', $cmd ) ) ) Templates::$cmd();
58-
if ( is_callable( array( 'phpListRestapi\Messages', $cmd ) ) ) Messages::$cmd();
54+
if (is_callable(array('phpListRestapi\Lists', $cmd))) {
55+
Lists::$cmd();
56+
}
57+
if (is_callable(array('phpListRestapi\Actions', $cmd))) {
58+
Actions::$cmd();
59+
}
60+
if (is_callable(array('phpListRestapi\Subscribers', $cmd))) {
61+
Subscribers::$cmd();
62+
}
63+
if (is_callable(array('phpListRestapi\Templates', $cmd))) {
64+
Templates::$cmd();
65+
}
66+
if (is_callable(array('phpListRestapi\Messages', $cmd))) {
67+
Messages::$cmd();
68+
}
5969

6070
//If no command found, return error message!
61-
Response::outputErrorMessage( 'No function for provided [cmd] found!' );
71+
Response::outputErrorMessage('No function for provided [cmd] found!');

plugins/restapi/doc/doc.php

+25-32
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
11
<?php
22

3-
class phpListRestapiDoc {
4-
3+
class phpListRestapiDoc
4+
{
55
private $classes;
66

7-
function __construct()
7+
public function __construct()
88
{
99
}
1010

11-
function addClass( $classname ){
12-
11+
public function addClass($classname)
12+
{
1313
$this->classes[] = "phpListRestapi\\$classname";
14-
1514
}
1615

17-
function output(){
18-
16+
public function output()
17+
{
1918
$this->header();
2019

21-
foreach( $this->classes as $class ){
22-
23-
$reflect = new \ReflectionClass( $class );
20+
foreach ($this->classes as $class) {
21+
$reflect = new \ReflectionClass($class);
2422
$methods = $reflect->getMethods();
25-
foreach( $methods as $method ){
26-
23+
foreach ($methods as $method) {
2724
echo '<section>';
2825
echo '<div class="page-header">';
29-
echo '<h2>' . $method->name . '</h2>';
26+
echo '<h2>'.$method->name.'</h2>';
3027
echo '</div>';
3128
echo '<div class="row">';
3229
echo '<div class="span12">';
3330

3431
$comment = $method->getDocComment();
3532

36-
$comment = str_replace( '/**', '', $comment );
37-
$comment = str_replace( '*/', '', $comment );
38-
$comment = str_replace( '[*', '<span class="label label-warning">', $comment );
39-
$comment = str_replace( '[', '<span class="label label-success">', $comment );
40-
$comment = str_replace( ']', '</span>', $comment );
41-
$comment = str_replace( '{', '<span class="badge">', $comment );
42-
$comment = str_replace( '}', '</span>', $comment );
43-
$comment = str_replace( '*', '', $comment );
33+
$comment = str_replace('/**', '', $comment);
34+
$comment = str_replace('*/', '', $comment);
35+
$comment = str_replace('[*', '<span class="label label-warning">', $comment);
36+
$comment = str_replace('[', '<span class="label label-success">', $comment);
37+
$comment = str_replace(']', '</span>', $comment);
38+
$comment = str_replace('{', '<span class="badge">', $comment);
39+
$comment = str_replace('}', '</span>', $comment);
40+
$comment = str_replace('*', '', $comment);
4441
//$comment = str_replace( '<br><br>', '', $comment );
4542

4643
echo trim($comment);
@@ -50,18 +47,15 @@ function output(){
5047
echo '<br/>';
5148
echo '<section>';
5249
}
53-
5450
}
5551

5652
$this->footer();
5753

5854
exit;
59-
6055
}
6156

62-
63-
function header(){
64-
57+
public function header()
58+
{
6559
?>
6660

6761
<!DOCTYPE html>
@@ -80,7 +74,8 @@ function header(){
8074
<div class="row">
8175
<div class="span6">
8276
<h1>API Plugin to phpList</h1>
83-
<p class="lead">Documentation generated <?php echo date('Y-m-d H:i:s'); ?></p>
77+
<p class="lead">Documentation generated <?php echo date('Y-m-d H:i:s');
78+
?></p>
8479
</div>
8580
</div>
8681
</header>
@@ -100,8 +95,8 @@ function header(){
10095

10196
}
10297

103-
function footer(){
104-
98+
public function footer()
99+
{
105100
?>
106101
<footer id="footer">
107102
<p class="pull-right"><a href="#">Back to top</a></p>
@@ -113,6 +108,4 @@ function footer(){
113108
<?php
114109

115110
}
116-
117-
118111
}

0 commit comments

Comments
 (0)