public static function enforceRequestLimit($limit)
 {
     $response = new Response();
     try {
         $db = PDO::getConnection();
         $stmt = $db->prepare('select count(cmd) as num from ' . $GLOBALS['table_prefix'] . 'restapi_request_log where date > date_sub(now(),interval 1 minute)');
         $stmt->execute();
         $result = $stmt->fetch(PDO::FETCH_OBJ);
         if ($result->num > $limit) {
             $response->outputErrorMessage('Too many requests. Requests are limited to ' . $limit . ' per minute');
             die(0);
         }
     } catch (\Exception $e) {
         $response->setError($e->getCode(), $e->getMessage());
     }
 }
 public static function templateDelete()
 {
     $sql = 'DELETE FROM ' . $GLOBALS['table_prefix'] . 'template WHERE id=:id';
     try {
         if (!is_numeric($_REQUEST['id'])) {
             Response::outputErrorMessage('invalid call');
         }
         $db = PDO::getConnection();
         $stmt = $db->prepare($sql);
         $stmt->bindParam('id', $_REQUEST['id'], PDO::PARAM_STR);
         $stmt->execute();
         $db = null;
         Response::outputDeleted('Template', $_REQUEST['id']);
     } catch (\Exception $e) {
         Response::outputError($e);
     }
 }
 /**
  * Add a subscriber to a list.
  * 
  * <p>The subscriber then subscribes to the list.</p>
  * <p><strong>Parameters:</strong><br/>
  * [*list_id] {integer} the ID of the list.<br/>
  * [*subscriber_id] {integer} the ID of the subscriber.<br/>
  * <p><strong>Returns:</strong><br/>
  * Array of lists where the subscriber is assigned to.
  * </p>
  */
 public static function listSubscriberAdd($list_id = 0, $subscriber_id = 0)
 {
     if ($list_id == 0) {
         $list_id = sprintf('%d', $_REQUEST['list_id']);
     }
     if ($subscriber_id == 0) {
         $subscriber_id = sprintf('%d', $_REQUEST['subscriber_id']);
     }
     if (empty($subscriber_id) || empty($list_id)) {
         Response::outputErrorMessage('invalid call');
     }
     $sql = 'INSERT INTO ' . $GLOBALS['tables']['listuser'] . ' (userid, listid, entered) VALUES (:subscriber_id, :list_id, now());';
     try {
         $db = PDO::getConnection();
         $stmt = $db->prepare($sql);
         $stmt->bindParam('subscriber_id', $subscriber_id, PDO::PARAM_INT);
         $stmt->bindParam('list_id', $list_id, PDO::PARAM_INT);
         $stmt->execute();
         $db = null;
         self::listsSubscriber($subscriber_id);
     } catch (\Exception $e) {
         Response::outputError($e);
     }
     die(0);
 }
Example #4
0
if ($requireSecret) {
    $secret = getConfig('remote_processing_secret');
    if (empty($_REQUEST['secret']) || $_REQUEST['secret'] != $secret) {
        $response->outputErrorMessage('Incorrect processing secret. Check your settings.');
        die(0);
    }
}
$enforceSSL = getConfig('restapi_enforcessl');
if ($enforceSSL && empty($_SERVER['HTTPS'])) {
    $response->outputErrorMessage('Invalid API request. Request is not using SSL, which is enforced by the plugin settings.');
    die(0);
}
//Now bind the commands with static functions
if (is_callable(array('phpListRestapi\\Lists', $cmd))) {
    Lists::$cmd();
}
if (is_callable(array('phpListRestapi\\Actions', $cmd))) {
    Actions::$cmd();
}
if (is_callable(array('phpListRestapi\\Subscribers', $cmd))) {
    Subscribers::$cmd();
}
if (is_callable(array('phpListRestapi\\Templates', $cmd))) {
    Templates::$cmd();
}
if (is_callable(array('phpListRestapi\\Campaigns', $cmd))) {
    Campaigns::$cmd();
}
//If no command found, return error message!
Response::outputErrorMessage('No function for provided [cmd] found!');
 /**
  * Delete a Subscriber.
  * 
  * <p><strong>Parameters:</strong><br/>
  * [*id] {integer} the ID of the Subscriber.<br/>
  * </p>
  * <p><strong>Returns:</strong><br/>
  * The deleted Subscriber ID.
  * </p>
  */
 public static function subscriberDelete()
 {
     $sql = 'DELETE FROM ' . $GLOBALS['tables']['user'] . ' WHERE id=:id;';
     try {
         if (!is_numeric($_REQUEST['id'])) {
             Response::outputErrorMessage('invalid call');
         }
         $db = PDO::getConnection();
         $stmt = $db->prepare($sql);
         $stmt->bindParam('id', $_REQUEST['id'], PDO::PARAM_INT);
         $stmt->execute();
         $db = null;
         Response::outputDeleted('Subscriber', sprintf('%d', $_REQUEST['id']));
     } catch (\Exception $e) {
         Response::outputError($e);
     }
 }