示例#1
0
文件: Utility.php 项目: TMBR/johnjohn
 /**
  * Create a new instance of Tribe__Events__PUE__Utility from its JSON-encoded representation.
  *
  * @param string $json
  *
  * @return Tribe__Events__PUE__Utility
  */
 public static function from_json($json)
 {
     //Since update-related information is simply a subset of the full plugin info,
     //we can parse the update JSON as if it was a plugin info string, then copy over
     //the parts that we care about.
     $pluginInfo = Tribe__Events__PUE__Plugin_Info::from_json($json);
     if ($pluginInfo != null) {
         return Tribe__Events__PUE__Utility::from_plugin_info($pluginInfo);
     } else {
         return null;
     }
 }
 /**
  * Retrieve the latest update (if any) from the configured API endpoint.
  *
  * @uses Tribe__Events__PUE__Checker::request_info()
  *
  * @return Tribe__Events__PUE__Utility An instance of Tribe__Events__PUE__Utility, or NULL when no updates are available.
  */
 public function request_update()
 {
     //For the sake of simplicity, this function just calls request_info()
     //and transforms the result accordingly.
     $pluginInfo = $this->request_info(array('pu_checking_for_updates' => '1'));
     if ($pluginInfo == null) {
         return null;
     }
     //admin display for if the update check reveals that there is a new version but the API key isn't valid.
     if (isset($pluginInfo->api_invalid)) {
         //we have json_error returned let's display a message
         $this->json_error = $pluginInfo;
         add_action('admin_notices', array(&$this, 'display_json_error'));
         return null;
     }
     if (isset($pluginInfo->new_install_key)) {
         $this->update_option($this->pue_install_key, $pluginInfo->new_install_key);
     }
     //need to correct the download url so it contains the custom user data (i.e. api and any other paramaters)
     $download_query = $this->get_download_query();
     if (!empty($download_query)) {
         $pluginInfo->download_url = esc_url_raw(add_query_arg($download_query, $pluginInfo->download_url));
     }
     // Add plugin dirname/file (this will be expected by WordPress when it builds the plugin list table)
     $pluginInfo->plugin = $this->get_plugin_file();
     return Tribe__Events__PUE__Utility::from_plugin_info($pluginInfo);
 }