/**
  * Prepare report data
  *
  * @param array input data
  */
 public function prepareRequest(array $input_data)
 {
     $month_day = get_option('wprc_usage_sending_month_day');
     $send = false;
     if (!$month_day) {
         // Choose one day of the month between 2 and 27.
         // We'll not send usage reports out of those days
         $month_day = str_pad(rand(2, 27), 2, '0', STR_PAD_LEFT);
         update_option('wprc_usage_sending_month_day', $month_day);
         $current_day = date_i18n('d');
         if (strcmp($current_day, $month_day) === -1) {
             // If month day < today we'll send the report later on, but this same month
             $next_report_date = date_i18n('Ym' . $month_day, current_time('timestamp'));
             set_transient('wprc_usage_reports', $next_report_date);
         } else {
             $send = true;
         }
     }
     $today = date_i18n('Ymd', current_time('timestamp'));
     $transient = get_transient('wprc_usage_reports');
     if (!$transient || strcmp($today, $transient) >= 0) {
         $next_report_date = date_i18n('Ym' . $month_day, strtotime('first day of next month', current_time('timestamp')));
         set_transient('wprc_usage_reports', $next_report_date);
         $send = true;
     }
     if ($send) {
         // get data of all plugins
         WPRC_Loader::includeExtensionDataManager();
         $all_data = WPRC_ExtensionDataManager::getAllData('extension');
         $value = array();
         $report = $this->search_key($all_data, 'activated_extensions');
         $site_info = $this->getSiteInfo(true);
         $site_url = $site_info['site_url'];
         $raw_report_data = array('reports' => $report);
         if (!is_array($report)) {
             return false;
         }
         $report = $this->formRequestStructure($raw_report_data);
         return $report;
     }
     return false;
 }
 /**
  * Prepare report data
  *
  * @param array input data
  */
 public function prepareRequest(array $input_data)
 {
     // validate input data
     if (!array_key_exists('extension_type', $input_data)) {
         throw new Exception(__('Please set extension_type', 'installer'));
         return false;
     }
     // set extension type
     $extension_type = $input_data['extension_type'];
     // check timers
     WPRC_Loader::includeExtensionTimer();
     $timers = WPRC_ExtensionTimer::checkTimers();
     // if there are no timers registered in the system
     if (count($timers) == 0) {
         return false;
     }
     // get data of all plugins
     WPRC_Loader::includeExtensionDataManager();
     $all_data = WPRC_ExtensionDataManager::getAllData('extension');
     // if there are no saved data for plugins
     if (!is_array($all_data)) {
         return false;
     }
     $report_data = array();
     $correct_work_period = WPRC_ExtensionTimer::getDefaultPeriod();
     // cycle for expired timers
     foreach ($timers as $extension => $timer_expired) {
         if ($timer_expired) {
             // prepare report data --------------------
             // get saved list of activated plugins
             if (!array_key_exists($extension, $all_data)) {
                 continue;
             }
             $extension_data = $all_data[$extension];
             if (!array_key_exists('activated_extensions', $extension_data) || count($extension_data) == 0) {
                 continue;
             }
             // check presence of extension with expired timer in the sent reports list (was extension sent?)
             if ($this->isSentReportsListItemExists($extension)) {
                 continue;
             }
             // cycle for activated plugins of each plugin with expired timer
             if (count($extension_data['activated_extensions']) > 0) {
                 foreach ($extension_data['activated_extensions'] as $activated_extension => $activated_extension_data) {
                     // check last activation dates of extensions in the saved list
                     /*if(!isset($all_data[$activated_extension]) || !isset($extension_data['activated_extensions']) || !array_key_exists('last_activation_date', $all_data[$activated_extension]))
                       {
                           continue;
                       }*/
                     if (isset($all_data[$activated_extension]) && isset($all_data[$activated_extension]['last_activation_date'])) {
                         $last_activation_date = $all_data[$activated_extension]['last_activation_date'];
                     } else {
                         if (is_array($activated_extension_data)) {
                             // include activated extensions even thougb they were not activated through extension manager
                             // since obviously they work together
                             $last_activation_date = time() - $correct_work_period;
                         } else {
                             continue;
                         }
                     }
                     // add extension to the report data
                     if (time() - $last_activation_date >= $correct_work_period) {
                         if (!isset($report_data[$extension])) {
                             $report_data[$extension] = array();
                         }
                         if (!isset($report_data[$extension]['activated_extensions'])) {
                             $report_data[$extension]['activated_extensions'] = array();
                         }
                         $report_data[$extension]['activated_extensions'][$activated_extension] = $activated_extension_data;
                     }
                 }
             }
             if (count($report_data) == 0) {
                 continue;
             }
         }
     }
     // end of timers FOREACH
     // form array for the formRequestStructure method
     $raw_report_data = array('reports' => $report_data);
     // form report structure
     $report = $this->formRequestStructure($raw_report_data);
     //file_put_contents(WPRC_PLUGIN_PATH.'/debug_correct.txt',print_r($report,true),FILE_APPEND);
     return $report;
 }