Ejemplo n.º 1
0
/**
 * Returns the lists available for the current subscription service.
 * 
 * @since 1.0.0
 * @return void
 */
function opanda_get_custom_fields()
{
    require OPANDA_BIZPANDA_DIR . '/admin/includes/subscriptions.php';
    try {
        $listId = isset($_POST['opanda_list_id']) ? $_POST['opanda_list_id'] : null;
        $service = OPanda_SubscriptionServices::getCurrentService();
        $fields = $service->getCustomFields($listId);
        echo json_encode($fields);
    } catch (Exception $ex) {
        echo json_encode(array('error' => $ex->getMessage()));
    }
    exit;
}
 /**
  * Returns subscription options.
  * 
  * @since 1.0.0
  * @return mixed[]
  */
 public function getOptions()
 {
     $options = array();
     $options[] = array('type' => 'separator');
     require_once OPANDA_BIZPANDA_DIR . '/admin/includes/subscriptions.php';
     $serviceList = OPanda_SubscriptionServices::getSerivcesList();
     // fix
     $service = get_option('opanda_subscription_service', 'database');
     if ($service == 'none') {
         update_option('opanda_subscription_service', 'database');
     }
     $listItems = array();
     foreach ($serviceList as $serviceName => $serviceInfo) {
         $listItems[] = array('value' => $serviceName, 'title' => $serviceInfo['title'], 'hint' => isset($serviceInfo['description']) ? $serviceInfo['description'] : null, 'image' => isset($serviceInfo['image']) ? $serviceInfo['image'] : null, 'hover' => isset($serviceInfo['hover']) ? $serviceInfo['hover'] : null);
     }
     $options[] = array('type' => 'dropdown', 'name' => 'subscription_service', 'way' => 'ddslick', 'width' => 450, 'data' => $listItems, 'default' => 'none', 'title' => __('Mailing Service', 'bizpanda'));
     $options = apply_filters('opanda_subscription_services_options', $options, $this);
     $options[] = array('type' => 'separator');
     return $options;
 }
Ejemplo n.º 3
0
 /**
  * Handles the proxy request.
  */
 public function handleRequest()
 {
     if (!isset($_POST['opandaRequestType']) || !isset($_POST['opandaService'])) {
         throw new Opanda_HandlerInternalException('Invalid request. The "opandaRequestType" or "opandaService" are not defined.');
     }
     require_once OPANDA_BIZPANDA_DIR . '/admin/includes/subscriptions.php';
     $service = OPanda_SubscriptionServices::getCurrentService();
     if (empty($service)) {
         throw new Opanda_HandlerInternalException(sprintf('The subscription service is not set.'));
     }
     // - service name
     $serviceName = $this->options['service'];
     if ($serviceName !== $service->name) {
         throw new Opanda_HandlerInternalException(sprintf('Invalid subscription service "%s".', $serviceName));
     }
     // - request type
     $requestType = strtolower($_POST['opandaRequestType']);
     $allowed = array('check', 'subscribe');
     if (!in_array($requestType, $allowed)) {
         throw new Opanda_HandlerInternalException(sprintf('Invalid request. The action "%s" not found.', $requestType));
     }
     // - identity data
     $identityData = isset($_POST['opandaIdentityData']) ? $_POST['opandaIdentityData'] : array();
     $identityData = $this->normilizeValues($identityData);
     if (empty($identityData['email'])) {
         throw new Opanda_HandlerException('Unable to subscribe. The email is not specified.');
     }
     // - context data
     $contextData = isset($_POST['opandaContextData']) ? $_POST['opandaContextData'] : array();
     $contextData = $this->normilizeValues($contextData);
     // - list id
     $listId = isset($_POST['opandaListId']) ? $_POST['opandaListId'] : null;
     if (empty($listId)) {
         throw new Opanda_HandlerException('Unable to subscribe. The list ID is not specified.');
     }
     // - double opt-in
     $doubleOptin = isset($_POST['opandaDoubleOptin']) ? $_POST['opandaDoubleOptin'] : true;
     $doubleOptin = $this->normilizeValue($doubleOptin);
     // - confirmation
     $confirm = isset($_POST['opandaConfirm']) ? $_POST['opandaConfirm'] : true;
     $confirm = $this->normilizeValue($confirm);
     // prepares data received from custom fields to be transferred to the mailing service
     $itemId = intval($contextData['itemId']);
     $identityData = $this->prepareDataToSave($service, $itemId, $identityData);
     $serviceReadyData = $this->mapToServiceIds($service, $itemId, $identityData);
     $identityData = $this->mapToCustomLabels($service, $itemId, $identityData);
     // creating subscription service
     try {
         $result = array();
         if ('subscribe' === $requestType) {
             $result = $service->subscribe($serviceReadyData, $listId, $doubleOptin, $contextData);
             do_action('opanda_subscribe', $result && isset($result['status']) ? $result['status'] : 'error', $identityData, $contextData);
         } elseif ('check' === $requestType) {
             $result = $service->check($serviceReadyData, $listId, $contextData);
             do_action('opanda_check', $result && isset($result['status']) ? $result['status'] : 'error', $identityData, $contextData);
         }
         if (!defined('OPANDA_WORDPRESS')) {
             return $result;
         }
         // calls the hook to save the lead in the database
         if ($result && isset($result['status'])) {
             $actionData = array('identity' => $identityData, 'requestType' => $requestType, 'service' => $this->options['service'], 'list' => $listId, 'doubleOptin' => $doubleOptin, 'confirm' => $confirm, 'context' => $contextData);
             if ('subscribed' === $result['status']) {
                 do_action('opanda_subscribed', $actionData);
             } else {
                 do_action('opanda_pending', $actionData);
             }
         }
         return $result;
     } catch (Exception $ex) {
         throw new Opanda_HandlerException($ex->getMessage());
     }
 }
    public function showSubscriptionService()
    {
        $info = OPanda_SubscriptionServices::getCurrentServiceInfo();
        $serviceName = empty($info) ? 'none' : $info['name'];
        ?>
        <div class="form-group">
            <label class="col-sm-2 control-label"></label>
            <div class="control-group controls col-sm-10">

                <?php 
        if ('database' === $serviceName) {
            ?>
                    <?php 
            printf(__('The emails will be saved in the <a href="%s" target="_blank">local database</a> because you haven\'t selected a mailing service', 'signinlocker'), opanda_get_subscribers_url());
            ?>
                <?php 
        } else {
            ?>
                    <?php 
            printf(__('You selected <strong>%s</strong> as your mailing service', 'signinlocker'), $info['title']);
            ?>
                <?php 
        }
        ?>
  
                (<a href="<?php 
        echo opanda_get_settings_url('subscription');
        ?>
" target="_blank"><?php 
        _e('change', 'signinlocker');
        ?>
</a>).
            </div>
        </div>
        <?php 
    }