/**
  * Fetch all podcasts for Publisher blogs, ordered
  */
 public static function podcasts($sortby = "title", $sort = 'ASC')
 {
     $podcast_blog_ids = Network::podcast_blog_ids();
     if (empty($podcast_blog_ids)) {
         return [];
     }
     foreach ($podcast_blog_ids as $blog_id) {
         $podcasts[$blog_id] = Podcast::get($blog_id);
     }
     uasort($podcasts, function ($a, $b) use($sortby, $sort) {
         return strnatcmp($a->{$sortby}, $b->{$sortby});
     });
     if ($sort == 'DESC') {
         krsort($podcasts);
     }
     return $podcasts;
 }
    public static function right_now()
    {
        $podcasts = \Podlove\Modules\Networks\Model\Network::podcast_blog_ids();
        $number_of_podcasts = count($podcasts);
        if (!$number_of_podcasts) {
            echo __('No podcasts exist yet.', 'podlove');
            return;
        }
        $episodes_total = 0;
        $episodes_total_per_status = array('publish' => 0, 'private' => 0, 'future' => 0, 'draft' => 0);
        $episodes_total_length = 0;
        $episode_total_average_length = 0;
        $media_file_total_average_size = 0;
        $media_file_total_size = 0;
        $days_between_episodes = 0;
        foreach ($podcasts as $podcast) {
            switch_to_blog($podcast);
            $statistics = \Podlove\Settings\Dashboard\Statistics::prepare_statistics();
            $episodes_total += $statistics['total_number_of_episodes'];
            array_walk($statistics['episodes'], function ($posts, $type) use(&$episodes_total_per_status) {
                switch ($type) {
                    case 'publish':
                        $episodes_total_per_status['publish'] += $posts;
                        break;
                    case 'publish':
                        $episodes_total_per_status['private'] += $posts;
                        break;
                    case 'future':
                        $episodes_total_per_status['future'] += $posts;
                        break;
                    case 'draft':
                        $episodes_total_per_status['draft'] += $posts;
                        break;
                }
            });
            $episodes_total_length += $statistics['total_episode_length'];
            $episode_total_average_length += $statistics['average_episode_length'];
            $days_between_episodes += $statistics['days_between_releases'];
            $media_file_total_average_size += $statistics['average_media_file_size'];
            $media_file_total_size += $statistics['total_media_file_size'];
            restore_current_blog();
        }
        // Devide stats by number of Podcasts
        $episode_total_average_length /= $number_of_podcasts;
        $days_between_episodes /= $number_of_podcasts;
        $media_file_total_average_size /= $number_of_podcasts;
        ?>
		<div class="podlove-dashboard-statistics-wrapper">
			<h4>Episodes</h4>
			<table cellspacing="0" cellpadding="0" class="podlove-dashboard-statistics">
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo $episodes_total_per_status['publish'];
        ?>
					</td>
					<td>
						<span style="color: #2c6e36;"><?php 
        echo __('Published', 'podlove');
        ?>
</span>
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo $episodes_total_per_status['private'];
        ?>
					</td>
					<td>
						<span style="color: #b43f56;"><?php 
        echo __('Private', 'podlove');
        ?>
</span>
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo $episodes_total_per_status['future'];
        ?>
					</td>
					<td>
						<span style="color: #a8a8a8;"><?php 
        echo __('To be published', 'podlove');
        ?>
</span>
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo $episodes_total_per_status['draft'];
        ?>
					</td>
					<td>
						<span style="color: #c0844c;"><?php 
        echo __('Drafts', 'podlove');
        ?>
</span>
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column podlove-dashboard-total-number">
						<?php 
        echo $episodes_total;
        ?>
					</td>
					<td class="podlove-dashboard-total-number">
						<?php 
        echo __('Total', 'podlove');
        ?>
					</td>
				</tr>
			</table>
		</div>
		<div class="podlove-dashboard-statistics-wrapper">
			<h4><?php 
        echo __('Statistics', 'podlove');
        ?>
</h4>
			<table cellspacing="0" cellpadding="0" class="podlove-dashboard-statistics">
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo gmdate("H:i:s", $episode_total_average_length);
        ?>
					</td>
					<td>
						<?php 
        echo __('is the average length of an episode', 'podlove');
        ?>
.
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        $days = round($episodes_total_length / 3600 / 24, 1);
        echo sprintf(_n('%s day', '%s days', $days, 'podlove'), $days);
        ?>
					</td>
					<td>
						<?php 
        echo __('is the total playback time of all episodes', 'podlove');
        ?>
.
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo \Podlove\format_bytes($media_file_total_average_size, 1);
        ?>
					</td>
					<td>
						<?php 
        echo __('is the average media file size', 'podlove');
        ?>
.
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo \Podlove\format_bytes($media_file_total_size, 1);
        ?>
					</td>
					<td>
						<?php 
        echo __('is the total media file size', 'podlove');
        ?>
.
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo sprintf(_n('%s day', '%s days', round($days_between_episodes), 'podlove'), round($days_between_episodes));
        ?>
					</td>
					<td>
						<?php 
        echo __('is the average interval until a new episode is released', 'podlove');
        ?>
.
					</td>
				</tr>
				<tr>
					<td class="podlove-dashboard-number-column">
						<?php 
        echo sprintf(_n('%s podcast', '%s podcasts', $number_of_podcasts, 'podlove'), $number_of_podcasts);
        ?>
					</td>
					<td>
						<?php 
        echo __('exist in your WordPress installation', 'podlove');
        ?>
.
					</td>
				</tr>
				<?php 
        do_action('podlove_dashboard_statistics_network');
        ?>
			</table>
		</div>
		<p>
			<?php 
        echo sprintf(__('You are using %s', 'podlove'), '<strong>Podlove Publisher ' . \Podlove\get_plugin_header('Version') . '</strong>');
        ?>
.
		</p>
		<?php 
    }
    public static function dashboard_network_statistics_row($genders)
    {
        $podcasts = \Podlove\Modules\Networks\Model\Network::podcast_blog_ids();
        $podcasts_with_contributors_active = 0;
        $relative_gender_numbers = array('male' => 0, 'female' => 0, 'none' => 0);
        foreach ($podcasts as $podcast) {
            switch_to_blog($podcast);
            if (\Podlove\Modules\Base::is_active('contributors')) {
                $global_gender_numbers = self::fetch_contributors_for_dashboard_statistics();
                if ($global_gender_numbers['global']['total'] > 0) {
                    foreach ($global_gender_numbers['global']['by_gender'] as $gender => $number_of_contributions) {
                        $relative_gender_numbers[$gender] += $number_of_contributions / $global_gender_numbers['global']['total'] * 100;
                    }
                }
                $podcasts_with_contributors_active++;
            }
            restore_current_blog();
        }
        ?>
		<tr>
			<td class="podlove-dashboard-number-column">
				<?php 
        echo __('Genders', 'podlove');
        ?>
			</td>
			<td>
				<?php 
        echo implode(', ', array_map(function ($percent, $gender) use($podcasts_with_contributors_active) {
            return round($percent / $podcasts_with_contributors_active) . "% " . ($gender == 'none' ? 'not attributed' : $gender);
        }, $relative_gender_numbers, array_keys($relative_gender_numbers)));
        ?>
			</td>
		</tr>
		<?php 
    }
 private static function podcast_ids()
 {
     return Model\PodcastList::with_network_scope(function () {
         return Model\Network::podcast_blog_ids();
     });
 }