<?php

/**
 * This file contains examples for using the MailWizzApi PHP-SDK.
 *
 * @author Serban George Cristian <*****@*****.**>
 * @link http://www.mailwizz.com/
 * @copyright 2013 http://www.mailwizz.com/
 */
// require the setup which has registered the autoloader
require_once dirname(__FILE__) . '/setup.php';
// create the lists endpoint:
$endpoint = new MailWizzApi_Endpoint_Lists();
// update list
// please see countries.php example file for a list of allowed countries/zones for list company
$response = $endpoint->update('LIST-UNIQUE-ID', array('general' => array('name' => 'My list created from the API - now updated!', 'description' => 'This is a test list, created from the API.'), 'defaults' => array('from_name' => 'John Doe', 'reply_to' => '*****@*****.**', 'subject' => 'Hello!'), 'notifications' => array('subscribe' => 'yes', 'unsubscribe' => 'yes', 'subscribe_to' => '*****@*****.**', 'unsubscribe_to' => '*****@*****.**'), 'company' => array('name' => 'John Doe INC', 'country' => 'United States', 'zone' => 'New York', 'address_1' => 'Some street address', 'address_2' => '', 'zone_name' => '', 'city' => 'New York City', 'zip_code' => '10019')));
// and get the response
echo '<pre>';
print_r($response->body);
echo '</pre>';
示例#2
0
<?php

/**
 * This file contains examples for using the MailWizzApi PHP-SDK.
 *
 * @author Serban George Cristian <*****@*****.**>
 * @link http://www.mailwizz.com/
 * @copyright 2013-2015 http://www.mailwizz.com/
 */
// require the setup which has registered the autoloader
require_once dirname(__FILE__) . '/setup.php';
// create the lists endpoint:
$endpoint = new MailWizzApi_Endpoint_Lists();
/*===================================================================================*/
// GET ALL ITEMS
$response = $endpoint->getLists($pageNumber = 1, $perPage = 10);
// DISPLAY RESPONSE
echo '<pre>';
print_r($response->body);
echo '</pre>';
/*===================================================================================*/
// get a single list
$response = $endpoint->getList('LIST-UNIQUE-ID');
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
/*===================================================================================*/
// copy a list
$response = $endpoint->copy('LIST-UNIQUE-ID');
// DISPLAY RESPONSE
    /**
     * Back-end widget form.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     */
    public function form($instance)
    {
        $title = isset($instance['title']) ? $instance['title'] : null;
        //$apiUrl             = isset($instance['api_url'])               ? $instance['api_url']              : null;
        $apiUrl = 'http://app.kirim.in/api';
        $publicKey = isset($instance['public_key']) ? $instance['public_key'] : null;
        $privateKey = isset($instance['private_key']) ? $instance['private_key'] : null;
        $listUid = isset($instance['list_uid']) ? $instance['list_uid'] : null;
        $listSelectedFields = isset($instance['selected_fields']) ? $instance['selected_fields'] : array();
        $generatedForm = isset($instance['generated_form']) ? $instance['generated_form'] : '';
        $freshLists = array(array('list_uid' => null, 'name' => __('Silahkan pilih', 'mwznb')));
        $freshFields = array();
        if (!empty($apiUrl) && !empty($publicKey) && !empty($privateKey)) {
            $oldSdkConfig = MailWizzApi_Base::getConfig();
            MailWizzApi_Base::setConfig(mwznb_build_sdk_config($apiUrl, $publicKey, $privateKey));
            $endpoint = new MailWizzApi_Endpoint_Lists();
            $response = $endpoint->getLists(1, 50);
            $response = $response->body->toArray();
            if (isset($response['status']) && $response['status'] == 'success' && !empty($response['data']['records'])) {
                foreach ($response['data']['records'] as $list) {
                    $freshLists[] = array('list_uid' => $list['general']['list_uid'], 'name' => $list['general']['name']);
                }
            }
            if (!empty($listUid)) {
                $endpoint = new MailWizzApi_Endpoint_ListFields();
                $response = $endpoint->getFields($listUid);
                $response = $response->body->toArray();
                if (isset($response['status']) && $response['status'] == 'success' && !empty($response['data']['records'])) {
                    foreach ($response['data']['records'] as $field) {
                        $freshFields[] = $field;
                    }
                }
            }
            mwznb_restore_sdk_config($oldSdkConfig);
            unset($oldSdkConfig);
        }
        ?>
        <p>
            <label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><strong><?php 
        _e('Title:');
        ?>
</strong></label> 
            <input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
        </p>
        
        <p>
            <input class="widefat mwz-api-url" id="<?php 
        echo $this->get_field_id('api_url');
        ?>
" name="<?php 
        echo $this->get_field_name('api_url');
        ?>
" type="hidden" value="<?php 
        echo esc_attr($apiUrl);
        ?>
" />
        </p>

        <p>
            <label for="<?php 
        echo $this->get_field_id('public_key');
        ?>
"><strong><?php 
        _e('Public api key:');
        ?>
</strong></label> 
            <input class="widefat mwz-public-key" id="<?php 
        echo $this->get_field_id('public_key');
        ?>
" name="<?php 
        echo $this->get_field_name('public_key');
        ?>
" type="text" value="<?php 
        echo esc_attr($publicKey);
        ?>
" />
        </p>
        
        <p>
            <label for="<?php 
        echo $this->get_field_id('private_key');
        ?>
"><strong><?php 
        _e('Private api key:');
        ?>
</strong></label> 
            <input class="widefat mwz-private-key" id="<?php 
        echo $this->get_field_id('private_key');
        ?>
" name="<?php 
        echo $this->get_field_name('private_key');
        ?>
" type="text" value="<?php 
        echo esc_attr($privateKey);
        ?>
" />
        </p>
        
        <div class="widget-control-actions">
            <div class="alignleft"></div>
            <div class="alignright">
                 <input type="submit" class="button button-primary right mwz-fetch-available-lists" value="Ambil list yang tersedia">
               <span class="spinner mwz-spinner" style="display: none;"></span>
            </div>
            <br class="clear">
        </div>
        
        <div class="lists-container" style="<?php 
        echo !empty($freshFields) ? 'display:block' : 'display:none';
        ?>
; margin:0; float:left; width:100%">
            <label for="<?php 
        echo $this->get_field_id('list_uid');
        ?>
"><strong><?php 
        _e('Pilih list:');
        ?>
</strong></label>
            <select data-listuid="<?php 
        echo esc_attr($listUid);
        ?>
" data-fieldname="<?php 
        echo $this->get_field_name('selected_fields');
        ?>
" class="widefat mwz-mail-lists-dropdown" id="<?php 
        echo $this->get_field_id('list_uid');
        ?>
" name="<?php 
        echo $this->get_field_name('list_uid');
        ?>
">
            <?php 
        foreach ($freshLists as $list) {
            ?>
            <option value="<?php 
            echo $list['list_uid'];
            ?>
"<?php 
            if ($listUid == $list['list_uid']) {
                echo ' selected="selected"';
            }
            ?>
><?php 
            echo $list['name'];
            ?>
</option>
            <?php 
        }
        ?>
            </select>
            <br class="clear"/>
            <br class="clear"/>
        </div>
        
        <div class="fields-container" style="<?php 
        echo !empty($listUid) ? 'display:block' : 'display:none';
        ?>
; margin:0; float:left; width:100%">
            <label for="<?php 
        echo $this->get_field_id('selected_fields');
        ?>
"><strong><?php 
        _e('Field:');
        ?>
</strong></label>
            <div class="table-container" style="width:100%;max-height:200px; overflow-y: scroll">
                <?php 
        mwznb_generate_fields_table($freshFields, $this->get_field_name('selected_fields'), $listSelectedFields);
        ?>
            </div>
            <br class="clear">
            <div style="float: right;">
                Generate form ulang: <input name="<?php 
        echo $this->get_field_name('generate_new_form');
        ?>
" value="1" type="checkbox" checked="checked"/>
            </div>
            <br class="clear">
        </div>
        
        <div class="generated-form-container" style="<?php 
        echo !empty($listUid) ? 'display:block' : 'display:none';
        ?>
; margin:0; float:left; width:100%">
            <label for="<?php 
        echo $this->get_field_id('generated_form');
        ?>
"><strong><?php 
        _e('Generated form:');
        ?>
</strong></label> 
            <textarea name="<?php 
        echo $this->get_field_name('generated_form');
        ?>
" id="<?php 
        echo $this->get_field_id('generated_form');
        ?>
" style="width: 100%; height: 200px; resize:none; outline:none"><?php 
        echo $generatedForm;
        ?>
</textarea>
        </div>
        
        <hr />
        <?php 
    }