/**
  * Updates information on the "View version x.x details" page with custom data.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.4
  *
  * @uses   FS_Api
  *
  * @param object $data
  * @param string $action
  * @param mixed  $args
  *
  * @return object
  */
 function plugins_api_filter($data, $action = '', $args = null)
 {
     $this->_logger->entrance();
     if ('plugin_information' !== $action || !isset($args->slug)) {
         return $data;
     }
     $addon = false;
     $is_addon = false;
     if ($this->_fs->get_slug() !== $args->slug) {
         $addon = $this->_fs->get_addon_by_slug($args->slug);
         if (!is_object($addon)) {
             return $data;
         }
         $is_addon = true;
     }
     $plugin_in_repo = false;
     if (!$is_addon) {
         // Try to fetch info from .org repository.
         $data = self::_fetch_plugin_info_from_repository($action, $args);
         $plugin_in_repo = false !== $data;
     }
     if (!$plugin_in_repo) {
         $data = $args;
         // Fetch as much as possible info from local files.
         $plugin_local_data = $this->_fs->get_plugin_data();
         $data->name = $plugin_local_data['Name'];
         $data->author = $plugin_local_data['Author'];
         $data->sections = array('description' => 'Upgrade ' . $plugin_local_data['Name'] . ' to latest.');
         // @todo Store extra plugin info on Freemius or parse readme.txt markup.
         /*$info = $this->_fs->get_api_site_scope()->call('/information.json');
         
         if ( !isset($info->error) ) {
         	$data = $info;
         }*/
     }
     // Get plugin's newest update.
     $new_version = $this->_fs->_fetch_latest_version($is_addon ? $addon->id : false);
     if ($is_addon) {
         $data->name = $addon->title . ' ' . __fs('addon', $this->_fs->get_slug());
         $data->slug = $addon->slug;
         $data->url = WP_FS__ADDRESS;
         $data->package = $new_version->url;
     }
     if (!$plugin_in_repo) {
         $data->last_updated = !is_null($new_version->updated) ? $new_version->updated : $new_version->created;
         $data->requires = $new_version->requires_platform_version;
         $data->tested = $new_version->tested_up_to_version;
     }
     $data->version = $new_version->version;
     $data->download_link = $new_version->url;
     return $data;
 }
 /**
  * Generate add-on plugin information.
  *
  * @author Vova Feldman (@svovaf)
  * @since  1.0.6
  *
  * @param array       $data
  * @param string      $action
  * @param object|null $args
  *
  * @return array|null
  */
 function _get_addon_info_filter($data, $action = '', $args = null)
 {
     $this->_logger->entrance();
     $parent_plugin_id = fs_request_get('parent_plugin_id', false);
     if ($this->_fs->get_id() != $parent_plugin_id || 'plugin_information' !== $action || !isset($args->slug)) {
         return $data;
     }
     // Find add-on by slug.
     $selected_addon = $this->_fs->get_addon_by_slug($args->slug);
     if (false === $selected_addon) {
         return $data;
     }
     if (!isset($selected_addon->info)) {
         // Setup some default info.
         $selected_addon->info = new stdClass();
         $selected_addon->info->selling_point_0 = 'Selling Point 1';
         $selected_addon->info->selling_point_1 = 'Selling Point 2';
         $selected_addon->info->selling_point_2 = 'Selling Point 3';
         $selected_addon->info->description = '<p>Tell your users all about your add-on</p>';
     }
     fs_enqueue_local_style('fs_addons', '/admin/add-ons.css');
     $data = $args;
     $is_free = true;
     // Load add-on pricing.
     $has_pricing = false;
     $has_features = false;
     $plans = false;
     $plans_result = $this->_fs->get_api_site_or_plugin_scope()->get("/addons/{$selected_addon->id}/plans.json");
     if (!isset($plans_result->error)) {
         $plans = $plans_result->plans;
         if (is_array($plans)) {
             for ($i = 0, $len = count($plans); $i < $len; $i++) {
                 $plans[$i] = new FS_Plugin_Plan($plans[$i]);
                 $plan = $plans[$i];
                 $pricing_result = $this->_fs->get_api_site_or_plugin_scope()->get("/addons/{$selected_addon->id}/plans/{$plan->id}/pricing.json");
                 if (!isset($pricing_result->error)) {
                     // Update plan's pricing.
                     $plan->pricing = $pricing_result->pricing;
                     if (is_array($plan->pricing) && !empty($plan->pricing)) {
                         $is_free = false;
                         foreach ($plan->pricing as &$pricing) {
                             $pricing = new FS_Pricing($pricing);
                         }
                     }
                     $has_pricing = true;
                 }
                 $features_result = $this->_fs->get_api_site_or_plugin_scope()->get("/addons/{$selected_addon->id}/plans/{$plan->id}/features.json");
                 if (!isset($features_result->error) && is_array($features_result->features) && 0 < count($features_result->features)) {
                     // Update plan's pricing.
                     $plan->features = $features_result->features;
                     $has_features = true;
                 }
             }
         }
     }
     // Fetch latest version from Freemius.
     $latest = $this->_fs->_fetch_latest_version($selected_addon->id);
     if (!$is_free) {
         // If paid add-on, then it's not on wordpress.org
         $is_wordpress_org = false;
     } else {
         // If no versions found, then assume it's a .org plugin.
         $is_wordpress_org = false === $latest;
     }
     if ($is_wordpress_org) {
         $repo_data = FS_Plugin_Updater::_fetch_plugin_info_from_repository('plugin_information', (object) array('slug' => $selected_addon->slug, 'is_ssl' => is_ssl(), 'fields' => array('banners' => true, 'reviews' => true, 'downloaded' => false, 'active_installs' => true)));
         if (!empty($repo_data)) {
             $data = $repo_data;
             $data->wp_org_missing = false;
         } else {
             // Couldn't find plugin on .org.
             $is_wordpress_org = false;
             // Plugin is missing, not on Freemius nor WP.org.
             $data->wp_org_missing = true;
         }
     }
     if (!$is_wordpress_org) {
         $data->checkout_link = $this->_fs->checkout_url();
         $data->fs_missing = false === $latest;
         if ($is_free) {
             $data->download_link = $this->_fs->_get_latest_download_local_url($selected_addon->id);
         }
     }
     if (!$is_wordpress_org) {
         // Fetch as much as possible info from local files.
         $plugin_local_data = $this->_fs->get_plugin_data();
         $data->name = $selected_addon->title;
         $data->author = $plugin_local_data['Author'];
         $view_vars = array('plugin' => $selected_addon);
         $data->sections = array('description' => fs_get_template('/plugin-info/description.php', $view_vars));
         if (!empty($selected_addon->info->banner_url)) {
             $data->banners = array('low' => $selected_addon->info->banner_url);
         }
         if (!empty($selected_addon->info->screenshots)) {
             $view_vars = array('screenshots' => $selected_addon->info->screenshots, 'plugin' => $selected_addon);
             $data->sections['screenshots'] = fs_get_template('/plugin-info/screenshots.php', $view_vars);
         }
         if (is_object($latest)) {
             $data->version = $latest->version;
             $data->last_updated = !is_null($latest->updated) ? $latest->updated : $latest->created;
             $data->requires = $latest->requires_platform_version;
             $data->tested = $latest->tested_up_to_version;
         } else {
             // Add dummy version.
             $data->version = '1.0.0';
             // Add message to developer to deploy the plugin through Freemius.
         }
     }
     if ($has_pricing) {
         // Add plans to data.
         $data->plans = $plans;
         if ($has_features) {
             $view_vars = array('plans' => $plans, 'plugin' => $selected_addon);
             $data->sections['features'] = fs_get_template('/plugin-info/features.php', $view_vars);
         }
     }
     $data->is_paid = !$is_free;
     $data->external = !$is_wordpress_org;
     return $data;
 }