Пример #1
0
    /**
     * Display GetResponse MCE buttons
     */
    function GrJsShortcodes()
    {
        $GrOptionDbPrefix = 'GrIntegrationOptions_';
        $api_key = get_option($GrOptionDbPrefix . 'api_key');
        if (!empty($api_key)) {
            $api = new GetResponseIntegration($api_key);
            $campaigns = $api->getCampaigns();
            $webforms = $api->getWebforms();
            // check if no errors
            if (!empty($webforms) and false === (is_array($webforms) and isset($webforms['type']) and $webforms['type'] == 'error')) {
                $webforms = $this->SortByKeyValue($webforms, 'name');
            } else {
                $campaigns = null;
                $webforms = null;
            }
            $my_campaigns = json_encode($campaigns);
            $my_webforms = json_encode($webforms);
            ?>
			<script type="text/javascript">
				var my_webforms = <?php 
            echo $my_webforms;
            ?>
;
				var my_campaigns = <?php 
            echo $my_campaigns;
            ?>
;
			</script>
	<?php 
        }
    }
 /**
  * Sanitize widget form values as they are saved.
  *
  * @see WP_Widget::update()
  *
  * @param array $new_instance Values just sent to be saved.
  * @param array $old_instance Previously saved values from database.
  *
  * @return array Updated safe values to be saved.
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     $instance['select'] = !empty($new_instance['select']) ? strip_tags($new_instance['select']) : null;
     $instance['variants'] = $new_instance['variants'] !== '-' ? strip_tags($new_instance['variants']) : null;
     $instance['style'] = strip_tags($new_instance['style']);
     $instance['center'] = strip_tags($new_instance['center']);
     $instance['center_margin'] = (int) strip_tags($new_instance['center_margin']);
     $instance['version'] = in_array(strip_tags($new_instance['version']), array('old', 'new')) ? strip_tags($new_instance['version']) : 'old';
     $api_key = get_option($this->GrOptionDbPrefix . 'api_key');
     if (!empty($api_key)) {
         $api = new GetResponseIntegration($api_key, get_option($this->GrOptionDbPrefix . 'api_url'), get_option($this->GrOptionDbPrefix . 'api_domain'));
         $webform = $instance['version'] == 'old' ? $api->getWebForm($instance['select']) : $api->getForm($instance['select']);
         $web_forms = json_decode(get_option($this->GrOptionDbPrefix . 'web_forms'), true);
         if (!empty($web_foms)) {
             $web_forms = array();
         }
         $web_forms[$instance['select']] = (array) $webform;
         if (function_exists('is_customize_preview') == false || is_customize_preview() == false) {
             update_option($this->GrOptionDbPrefix . 'web_forms', json_encode($web_forms));
         }
     }
     return $instance;
 }
Пример #3
0
    /**
     * Back-end widget form.
     *
     * @see WP_Widget::form()
     *
     * @param array $instance Previously saved values from database.
     * @return string|void
     */
    public function form($instance)
    {
        $select = $instance ? esc_attr($instance['select']) : '';
        $style = $instance ? esc_attr($instance['style']) : '';
        $api_key = get_option($this->GrOptionDbPrefix . 'api_key');
        if (!empty($api_key)) {
            $api = new GetResponseIntegration($api_key);
            $campaigns = $api->getCampaigns();
            if (!empty($campaigns)) {
                $campaign_id = array();
                foreach ($campaigns as $cid => $campaign) {
                    $campaign_id[$cid] = $campaign->name;
                }
                $webforms = $api->getWebforms();
                $webforms = Gr_Integration::SortByKeyValue($webforms, 'name');
            }
        }
        ?>

		<?php 
        if ($api_key) {
            ?>
		<p>
			<?php 
            if (!empty($webforms) and false === (is_array($webforms) and isset($webforms['type']) and $webforms['type'] == 'error')) {
                ?>
			<label for="<?php 
                echo $this->get_field_id('select');
                ?>
"><?php 
                _e('Web Form:');
                ?>
</label>
			<select name="<?php 
                echo $this->get_field_name('select');
                ?>
" id="<?php 
                echo $this->get_field_id('select');
                ?>
" class="widefat">
				<?php 
                foreach ($webforms as $webform) {
                    echo '<option value="' . $webform->id . '" id="' . $webform->id . '"', $select == $webform->id ? ' selected="selected"' : '', '>', $webform->name . ' (' . $campaign_id[$webform->campaign] . ')', '</option>';
                }
                ?>
			</select>
			<?php 
            } else {
                _e('No Webforms', 'Gr_Integration');
            }
            ?>
		</p>
		<p>
			<input id="<?php 
            echo $this->get_field_id('style');
            ?>
" name="<?php 
            echo $this->get_field_name('style');
            ?>
" type="checkbox" value="1" <?php 
            checked('1', $style);
            ?>
 />
			<label for="<?php 
            echo $this->get_field_id('style');
            ?>
"><?php 
            _e('Use Wordpress CSS styles', 'Gr_Integration');
            ?>
</label>
		</p>
		<?php 
        } else {
            ?>
		<p><?php 
            _e('API key is not set.', 'Gr_Integration');
            ?>
</p>
		<?php 
        }
    }
    /**
     * Display GetResponse MCE buttons
     */
    function GrJsShortcodes()
    {
        $GrOptionDbPrefix = 'GrIntegrationOptions_';
        $api_key = get_option($GrOptionDbPrefix . 'api_key');
        $api_url = get_option($GrOptionDbPrefix . 'api_url');
        $api_domain = get_option($GrOptionDbPrefix . 'api_domain');
        $webforms = null;
        $forms = null;
        $campaingns = null;
        if (!empty($api_key)) {
            $api = new GetResponseIntegration($api_key, $api_url, $api_domain, is_ssl());
            $webforms = $api->getWebforms(array('sort' => array('name' => 'asc')));
            $forms = $api->getForms(array('sort' => array('name' => 'asc')));
            $api_key = 'true';
            $campaingns = $api->getCampaigns();
            // for 3.8 version
        } else {
            $api_key = 'false';
        }
        if (strlen($api_domain) > 0) {
            $webforms = $this->setGetResponse360domainToWebFormUrl($webforms, $api_domain);
            $forms = $this->setGetResponse360domainToWebFormUrl($forms, $api_domain);
        }
        $webforms = json_encode($webforms);
        $forms = json_encode($forms);
        $campaingns = json_encode($campaingns);
        // for 3.8 version
        ?>
		<script type="text/javascript">
			var my_webforms = <?php 
        echo $webforms;
        ?>
;
			var my_forms = <?php 
        echo $forms;
        ?>
;
			var my_campaigns = <?php 
        echo $campaingns;
        // for 3.8 version
        ?>
;
			var text_forms = '<?php 
        echo __('New Forms', 'Gr_Integration');
        ?>
';
			var text_webforms = '<?php 
        echo __('Old Web Forms', 'Gr_Integration');
        ?>
';
			var text_no_forms = '<?php 
        echo __('No Forms', 'Gr_Integration');
        ?>
';
			var text_no_webforms = '<?php 
        echo __('No Web Forms', 'Gr_Integration');
        ?>
';
			var api_key = <?php 
        echo $api_key;
        ?>
;
		</script>
		<?php 
    }