Skip to content

Commit

Permalink
Merge pull request #11 from phpartisan/master
Browse files Browse the repository at this point in the history
some details to fit into the trunk plugin system
  • Loading branch information
Andreas Ek committed Mar 13, 2013
2 parents 07e72fb + b965c4e commit c0b2d0a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
10 changes: 7 additions & 3 deletions plugins/restapi.php
Expand Up @@ -5,10 +5,15 @@
*/
class restapi extends phplistPlugin {

var $name = "RESTAPI";
public $name = "RESTAPI";
public $description = 'Implements a REST API interface to phpList';
public $topMenuLinks = array(
'main' => array('category' => 'system'),
);

function restapi() {
$this->coderoot = dirname(__FILE__) . '/restapi/';
parent::phplistplugin();
$this->coderoot = dirname(__FILE__) . '/restapi/';
}

function adminmenu() {
Expand All @@ -18,4 +23,3 @@ function adminmenu() {
}

}
?>
25 changes: 22 additions & 3 deletions plugins/restapi_test.php
Expand Up @@ -5,10 +5,30 @@
*/
class restapi_test extends phplistPlugin {

var $name = "RESTAPI Test";
public $name = "RESTAPI Test";
public $description = 'Functionality tests for the REST API plugin for phpList';
public $topMenuLinks = array(
'main' => array('category' => 'develop'),
);
public $settings = array(
"restapi_test_login" => array (
'value' => 'admin',
'description' => 'Login name for testing',
'type' => "text",
'allowempty' => 0,
'category'=> 'develop',
),
"restapi_test_password" => array (
'value' => 'phplist',
'description' => 'Login password for testing',
'type' => "text",
'category'=> 'develop',
),
);

function restapi_test() {
$this->coderoot = dirname(__FILE__) . '/restapi_test/';
parent::phplistplugin();
$this->coderoot = dirname(__FILE__) . '/restapi_test/';
}

function adminmenu() {
Expand All @@ -18,4 +38,3 @@ function adminmenu() {
}

}
?>
26 changes: 11 additions & 15 deletions plugins/restapi_test/main.php
Expand Up @@ -12,6 +12,15 @@

$url = apiUrl( $website );

$login = getConfig('restapi_test_login');
$password = getConfig('restapi_test_password');

if (empty($login)) {
print Error(s('Please configure the login details in the settings page'));
return;
}


?>

<html>
Expand All @@ -24,21 +33,8 @@
//Get the loginname and password!
$id = $_SESSION["logindetails"]["id"];

$dbhost = $GLOBALS['database_host'];
$dbuser = $GLOBALS['database_user'];
$dbpass = $GLOBALS['database_password'];
$dbname = $GLOBALS['database_name'];
$db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "SELECT * FROM " . $GLOBALS['table_prefix'] . "admin WHERE id=:id;";
$stmt = $db->prepare($sql);
$stmt->execute( array( ':id' => $id ) );
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
$admin = $result[0];

$api = new phpList_RESTAPI_Helper( $url );
$result = $api->login( $admin->loginname, $admin->password );
$result = $api->login( $login, $password );
if ($result->status != 'success'){
echo $result->data->message;
return;
Expand Down Expand Up @@ -371,4 +367,4 @@ function apiUrl( $website ){

}

?>
?>
5 changes: 2 additions & 3 deletions plugins/restapi_test/phplist_restapi_helper.php
Expand Up @@ -461,8 +461,8 @@ private function callAPI($command, $post_params, $no_decode=false ) {
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $post_params);
curl_setopt($c, CURLOPT_COOKIEFILE, 'phpList_RESTAPI_Helper');
curl_setopt($c, CURLOPT_COOKIEJAR, 'phpList_RESTAPI_Helper');
curl_setopt($c, CURLOPT_COOKIEFILE, $GLOBALS['tmpdir'].'/phpList_RESTAPI_Helper_cookiejar.txt');
curl_setopt($c, CURLOPT_COOKIEJAR, $GLOBALS['tmpdir'].'/phpList_RESTAPI_Helper_cookiejar.txt');
curl_setopt($c, CURLOPT_HTTPHEADER, array( 'Connection: Keep-Alive', 'Keep-Alive: 60' ));

$result = curl_exec($c);
Expand All @@ -475,4 +475,3 @@ private function callAPI($command, $post_params, $no_decode=false ) {

}

?>

0 comments on commit c0b2d0a

Please sign in to comment.