/**
  * Latest widget control
  *
  * @param integer $widget_id
  * @param array   $form_inputs
  * @return void
  */
 function widget_latest_control($widget_id, $form_inputs = array())
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $this->_config->set('widget.latest.items', Util_Request::get_integer('w3tc_widget_latest_items', 3));
         $this->_config->save();
         delete_transient($this->_widget_latest_cache_key());
     }
     include W3TC_INC_DIR . '/widget/latest_control.php';
 }
 /**
  * Configures the plugin to use the zone id provided in request
  */
 function w3tc_cdn_use_netdna_maxcdn_pull_zone()
 {
     require_once W3TC_LIB_NETDNA_DIR . '/NetDNA.php';
     $cdn_engine = Util_Request::get_string('type');
     $this->validate_cdnengine_is_netdna_maxcdn($cdn_engine);
     $authorization_key = Util_Request::get_string('authorization_key');
     $this->validate_authorization_key($authorization_key);
     $zone_id = Util_Request::get_integer('zone_id');
     $keys = explode('+', $authorization_key);
     list($alias, $consumer_key, $consumer_secret) = $keys;
     $api = new \NetDNA($alias, $consumer_key, $consumer_secret);
     $this->validate_account($api);
     try {
         $pull_zone = $api->get_zone($zone_id);
         if ($pull_zone) {
             $custom_domains = $api->get_custom_domains($pull_zone['id']);
             if (sizeof($custom_domains) > 0) {
                 $result = array('result' => 'valid', 'cnames' => array($custom_domains));
                 $test = true;
                 foreach ($custom_domains as $url) {
                     $test = $test && $this->test_cdn_url($url);
                 }
                 if ($test) {
                     $this->_config->set("cdn.enabled", true);
                 }
             } else {
                 $name = $pull_zone['name'];
                 $result = array('result' => 'valid', 'cnames' => array("{$name}.{$alias}.netdna-cdn.com"));
                 $test = $this->test_cdn_url("{$name}.{$alias}.netdna-cdn.com");
                 if ($test) {
                     $this->_config->set("cdn.enabled", true);
                 }
             }
             $this->_config->set("cdn.enabled", true);
             $this->_config->set("cdn.{$cdn_engine}.zone_id", $pull_zone['id']);
             $this->_config->set("cdn.{$cdn_engine}.domain", $result['cnames']);
             $this->_config->save();
         } else {
             $result = array('result' => 'error', 'message' => sprintf(__('The provided zone id was not connected to the provided authorization key.', 'w3-total-cache')));
         }
     } catch (\Exception $ex) {
         $result = array('result' => 'error', 'message' => $ex->getMessage());
     }
     echo json_encode($result);
     exit;
 }