Skip to content

Commit

Permalink
phpList API
Browse files Browse the repository at this point in the history
Name conventions changed
  • Loading branch information
Andreas Ek committed Dec 29, 2012
1 parent f1ab82f commit b01ccd2
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 123 deletions.
20 changes: 10 additions & 10 deletions README.md
@@ -1,5 +1,5 @@
#PHPLIST API
REST API as a plugin to [PHPlist](https://www.phplist.com)
#phpList API
REST API as a plugin to [phpList](https://www.phplist.com)

Two plugins inside this repo: "api" and "api-test"

Expand All @@ -19,7 +19,7 @@ v. Date Description
```

##Installation
###1. Activate plugins in PHPlist
###1. Activate plugins in phpList
Change the config-parameter for plugin folder in /config/config.php.

Example of definition in config-file:
Expand All @@ -44,7 +44,7 @@ Click on left admin menu "api" for more information!
Click on "api test" to test your installation of the API plugin!

##Access
Autentication required as admin in PHPlist.
Autentication required as admin in phpList.

All requests to the API is made by method POST.

Expand All @@ -53,7 +53,7 @@ Example of API-Url:
http://www.yoursite.com/lists/admin/?page=call&pi=api
```

First login to PHPlist with *POST* method and body parameters: "login" and "password".
First login to phpList with *POST* method and body parameters: "login" and "password".


##Client
Expand All @@ -73,7 +73,7 @@ Success response from the API
"type":"List",
"data":[{
"id":"12",
"name":"A new list in PHPlist"
"name":"A new list in phpList"
}]
}
```
Expand All @@ -100,8 +100,8 @@ $url = 'http://www.yoursite.com/lists/admin/?page=call&pi=api';

//initialize cUrl for remote content
$c = curl_init();
curl_setopt( $c, CURLOPT_COOKIEFILE, 'PHPlist_API_Helper' );
curl_setopt( $c, CURLOPT_COOKIEJAR, 'PHPlist_API_Helper' );
curl_setopt( $c, CURLOPT_COOKIEFILE, 'phpList_API_Helper' );
curl_setopt( $c, CURLOPT_COOKIEJAR, 'phpList_API_Helper' );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $c, CURLOPT_POST, 1 );

Expand All @@ -112,7 +112,7 @@ $result = curl_exec( $c );
$result = json_decode( $result );
var_dump( $result->data );

//Get all lists in PHPlist via /listsGet
//Get all lists in phpList via /listsGet
curl_setopt( $c, CURLOPT_URL, 'http://www.yoursite.com/lists/admin/?page=call&pi=api' );
curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $c, CURLOPT_POST, 1 );
Expand All @@ -123,7 +123,7 @@ $result = json_decode( $result );
//Now close the cUrl when finished
curl_close( $c );

//Dump all lists in PHPlist via /listsGet
//Dump all lists in phpList via /listsGet
var_dump( $result->data );

?>
Expand Down
32 changes: 16 additions & 16 deletions plugins/api/call.php
Expand Up @@ -3,7 +3,7 @@
//No HTML-output, please!
ob_end_clean();

//Getting PHPlist globals for this plugin
//Getting phpList globals for this plugin
$plugin = $GLOBALS["plugins"][$_GET["pi"]];

include 'includes/response.php';
Expand All @@ -20,38 +20,38 @@
include 'doc/doc.php';


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

//If other than POST then assume documentation report
if ( strcmp( $_SERVER['REQUEST_METHOD'], "POST") ){

$doc = new PHPlist_API_Doc();
$doc->addClass( 'PHPlist_API_Actions' );
$doc->addClass( 'PHPlist_API_Lists' );
$doc->addClass( 'PHPlist_API_Users' );
$doc->addClass( 'PHPlist_API_Templates' );
$doc->addClass( 'PHPlist_API_Messages' );
$doc = new phpList_API_Doc();
$doc->addClass( 'phpList_API_Actions' );
$doc->addClass( 'phpList_API_Lists' );
$doc->addClass( 'phpList_API_Users' );
$doc->addClass( 'phpList_API_Templates' );
$doc->addClass( 'phpList_API_Messages' );
$doc->output();

}

//Check if command is empty!
$cmd = $_REQUEST['cmd'];
if ( empty($cmd) ){
PHPlist_API_Response::outputMessage('OK! For action, please provide Post Param Key [cmd] !');
phpList_API_Response::outputMessage('OK! For action, please provide Post Param Key [cmd] !');
}

//Now bind the commands with static functions
if ( is_callable( array( 'PHPlist_API_Lists', $cmd ) ) ) PHPlist_API_Lists::$cmd();
if ( is_callable( array( 'PHPlist_API_Actions', $cmd ) ) ) PHPlist_API_Actions::$cmd();
if ( is_callable( array( 'PHPlist_API_Users', $cmd ) ) ) PHPlist_API_Users::$cmd();
if ( is_callable( array( 'PHPlist_API_Templates', $cmd ) ) ) PHPlist_API_Templates::$cmd();
if ( is_callable( array( 'PHPlist_API_Messages', $cmd ) ) ) PHPlist_API_Messages::$cmd();
if ( is_callable( array( 'phpList_API_Lists', $cmd ) ) ) phpList_API_Lists::$cmd();
if ( is_callable( array( 'phpList_API_Actions', $cmd ) ) ) phpList_API_Actions::$cmd();
if ( is_callable( array( 'phpList_API_Users', $cmd ) ) ) phpList_API_Users::$cmd();
if ( is_callable( array( 'phpList_API_Templates', $cmd ) ) ) phpList_API_Templates::$cmd();
if ( is_callable( array( 'phpList_API_Messages', $cmd ) ) ) phpList_API_Messages::$cmd();

//If no command found, return error message!
PHPlist_API_Response::outputErrorMessage( 'No function for provided [cmd] found!' );
phpList_API_Response::outputErrorMessage( 'No function for provided [cmd] found!' );

?>
6 changes: 3 additions & 3 deletions plugins/api/doc/doc.php
@@ -1,7 +1,7 @@
<?php


class PHPlist_API_Doc{
class phpList_API_Doc{

private $classes;

Expand Down Expand Up @@ -68,7 +68,7 @@ function header(){
<!DOCTYPE html>
<html>
<head>
<title>API Plugin to PHPlist</title>
<title>API Plugin to phpList</title>
<!-- Bootstrap -->
<link href="http://netdna.bootstrapcdn.com/bootswatch/2.1.1/cerulean/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
Expand All @@ -80,7 +80,7 @@ function header(){
<header class="jumbotron subhead" id="overview">
<div class="row">
<div class="span6">
<h1>API Plugin to PHPlist</h1>
<h1>API Plugin to phpList</h1>
<p class="lead">Documentation generated <?php echo date('Y-m-d H:i:s'); ?></p>
</div>
</div>
Expand Down
16 changes: 8 additions & 8 deletions plugins/api/includes/actions.php
@@ -1,23 +1,23 @@
<?php

class PHPlist_API_Actions{
class phpList_API_Actions{

/**
* <p>Function to call for login.<p>
* <p><strong>Parameters:</strong><br/>
* [*login] {string} loginname as an admin to PHPlist<br/>
* [*login] {string} loginname as an admin to phpList<br/>
* [*password] {string} the password
* </p>
*/
static function login(){
PHPlist_API_Response::outputMessage( 'Welcome!' );
phpList_API_Response::outputMessage( 'Welcome!' );
}

/**
* <p>Processes the Message Queue in PHPlist.<br/>
* <p>Processes the Message Queue in phpList.<br/>
* Perhaps this is done via CRON or manually through the admin interface?</p>
* <p><strong>Parameters:</strong><br/>
* [*login] {string} loginname as an admin to PHPlist<br/>
* [*login] {string} loginname as an admin to phpList<br/>
* [*password] {string} the password
*
*/
Expand All @@ -26,7 +26,7 @@ static function processQueue( ){
$admin_id = $_SESSION["logindetails"]["id"];

//Get the password from db!
$db = PHPlist_API_PDO::getConnection();
$db = phpList_API_PDO::getConnection();

$sql = "SELECT * FROM " . $GLOBALS['table_prefix'] . "admin WHERE id = :id;";
$stmt = $db->prepare($sql);
Expand All @@ -37,7 +37,7 @@ static function processQueue( ){
$login = $result[0]->loginname;
$password = $result[0]->password;

$url = PHPlist_API_Common::apiUrl( $_SERVER['HTTP_HOST'] );
$url = phpList_API_Common::apiUrl( $_SERVER['HTTP_HOST'] );
$url = str_replace( 'page=call&pi=api', 'page=processqueue&login=' . $login . '&password=' . $password . '&ajax=1', $url );

//open connection
Expand All @@ -51,7 +51,7 @@ static function processQueue( ){

//ob_end_clean();

PHPlist_API_Response::outputMessage( 'Queue is processed!' );
phpList_API_Response::outputMessage( 'Queue is processed!' );

}

Expand Down
6 changes: 3 additions & 3 deletions plugins/api/includes/common.php
@@ -1,11 +1,11 @@
<?php

class PHPlist_API_Common{
class phpList_API_Common{

static function select( $type, $sql, $single=false ){
$response = new PHPlist_API_Response();
$response = new phpList_API_Response();
try {
$db = PHPlist_API_PDO::getConnection();
$db = phpList_API_PDO::getConnection();
$stmt = $db->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
Expand Down

0 comments on commit b01ccd2

Please sign in to comment.