/** * Get Feed Information (Size (gzip) and Last Modifcation) */ public static function getInformation($feedid, $redirected = FALSE) { $feed = \Podlove\Model\Feed::find_by_id($feedid); $source = self::getSource($feedid, $redirected); $feed_header = $source['headers']; $feed_body = $source['body']; $feed_items = $feed->post_ids(); $last_modification = \Podlove\relative_time_steps(strtotime(isset($feed_header['last-modified']) ? $feed_header['last-modified'] : 0)); $size = \Podlove\format_bytes(strlen($feed_body)); if (extension_loaded('zlib')) { $size .= " (" . \Podlove\format_bytes(strlen(gzdeflate($feed_body, 9))) . ")"; } if ($redirected === FALSE) { $latest_item = "<a href=\"" . get_permalink($feed_items[0]) . "\">" . get_the_title($feed_items[0]) . "</a>"; } else { // Fetch latest item from source of redirected feed $start_item_tag = strpos($feed_body, '<item'); $end_item_tag = strpos($feed_body, '</item>'); $first_item = substr($feed_body, $start_item_tag + 7, $end_item_tag - $start_item_tag); $start_title_tag = strpos($first_item, '<title'); $end_title_tag = strpos($first_item, '</title>'); $start_link_tag = strpos($first_item, '<link'); $end_link_tag = strpos($first_item, '</link>'); $title = substr($first_item, $start_title_tag + 7, $end_title_tag - $start_title_tag - 7); $permalink = substr($first_item, $start_link_tag + 6, $end_link_tag - $start_link_tag - 7); $latest_item = "<a href=\"" . $permalink . "\">" . $title . "</a>"; } return array('size' => $size, 'last_modification' => $last_modification, 'latest_item' => $latest_item); }
/** * Apply Twig to given template * * @param string $html File path or HTML string. * @param array $vars optional variables for Twig context * @return string rendered template string */ public static function apply_to_html($html, $vars = array()) { // file loader for internal use $file_loader = new \Twig_Loader_Filesystem(); $file_loader->addPath(implode(DIRECTORY_SEPARATOR, array(\Podlove\PLUGIN_DIR, 'templates')), 'core'); // other modules can register their own template directories/namespaces $file_loader = apply_filters('podlove_twig_file_loader', $file_loader); // database loader for user templates $db_loader = new TwigLoaderPodloveDatabase(); $loaders = array($file_loader, $db_loader); $loaders = apply_filters('podlove_twig_loaders', $loaders); $loader = new \Twig_Loader_Chain($loaders); $twig = new \Twig_Environment($loader, array('autoescape' => false)); $twig->addExtension(new \Twig_Extensions_Extension_I18n()); $twig->addExtension(new \Twig_Extensions_Extension_Date()); $formatBytesFilter = new \Twig_SimpleFilter('formatBytes', function ($string) { return \Podlove\format_bytes($string, 0); }); $padLeftFilter = new \Twig_SimpleFilter('padLeft', function ($string, $padChar, $length) { while (strlen($string) < $length) { $string = $padChar . $string; } return $string; }); $twig->addFilter($formatBytesFilter); $twig->addFilter($padLeftFilter); // add functions foreach (self::$template_tags as $tag) { $func = new \Twig_SimpleFunction($tag, function () use($tag) { return $tag(); }); $twig->addFunction($func); } $context = ['option' => $vars]; // add podcast to global context $context = array_merge($context, ['podcast' => new Podcast(Model\Podcast::get())]); // Apply filters to twig templates $context = apply_filters('podlove_templates_global_context', $context); // add podcast to global context if we are in an episode if ($episode = Model\Episode::find_one_by_property('post_id', get_the_ID())) { $context = array_merge($context, array('episode' => new Episode($episode))); } try { return $twig->render($html, $context); } catch (\Twig_Error $e) { $message = $e->getRawMessage(); $line = $e->getTemplateLine(); $template = $e->getTemplateFile(); \Podlove\Log::get()->addError($message, ['type' => 'twig', 'line' => $line, 'template' => $template]); } return ""; }
/** * Provides a shortcode to display all available download links. * * Usage: * [podlove-episode-downloads] * * @param array $options * @return string */ function episode_downloads_shortcode($options) { global $post; if (is_feed()) { return ''; } $episode = Model\Episode::find_or_create_by_post_id($post->ID); $media_files = $episode->media_files(); $html = '<ul class="episode_download_list">'; foreach ($media_files as $media_file) { $episode_asset = $media_file->episode_asset(); if (!$episode_asset->downloadable) { continue; } $file_type = $episode_asset->file_type(); $download_link_url = get_bloginfo('url') . '?download_media_file=' . $media_file->id; $download_link_name = str_replace(" ", " ", $episode_asset->title); $html .= '<li class="' . $file_type->extension . '">'; $html .= sprintf('<a href="%s">%s%s</a>', apply_filters('podlove_download_link_url', $download_link_url, $media_file), apply_filters('podlove_download_link_name', $download_link_name, $media_file), '<span class="size">' . \Podlove\format_bytes($media_file->size, 0) . '</span>'); $html .= '</li>'; } $html .= '</ul>'; return apply_filters('podlove_downloads_before', '') . $html . apply_filters('podlove_downloads_after', ''); }
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 }
<td class="podlove-dashboard-number-column"> <?php echo \Podlove\format_bytes($statistics['average_media_file_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($statistics['total_media_file_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', $statistics['days_between_releases'], 'podlove'), $statistics['days_between_releases']); ?> </td>
public function inject_widget($content) { global $post; if ('podcast' !== get_post_type()) { return $content; } if (is_feed()) { return $content; } $cache = \Podlove\Cache\TemplateCache::get_instance(); $bitlove_html = $cache->cache_for('bitlove_' . get_permalink($post->ID), function () use($post) { $episode = Model\Episode::find_or_create_by_post_id($post->ID); $media_files = $episode->media_files(); $downloads = array(); $content = ''; foreach ($media_files as $media_file) { $episode_asset = $media_file->episode_asset(); if (!$episode_asset->downloadable) { continue; } $file_type = $episode_asset->file_type(); $download_link_name = str_replace(" ", " ", $episode_asset->title); $downloads[] = array('enclosure_guid' => RssExtension::get_enclosure_guid($media_file), 'name' => $download_link_name, 'size' => \Podlove\format_bytes($media_file->size, 0), 'file' => $media_file); } $content .= '<script type="text/javascript">'; $content .= ' /* <!-- */'; foreach ($downloads as $download) { $content .= <<<EOF jQuery(function(\$) { \ttorrentByEnclosure("{$download['enclosure_guid']}", function(info) { \t if (info) { \t var url = info.sources[0].torrent, \t title = "Torrent: {$download['name']}"; \t // select-style download-widget \t jQuery("#post-{$post->ID} [name='download_media_file']").append("<option value='" + url + "' data-raw-url='" + url + "'>" + title + "</option>") \t // button-stile download-widget \t jQuery("#post-{$post->ID} .episode_download_list").append("<li><a href='" + url + "'>" + title + "<span class='size'></span></a></li>") \t } \t}); }); EOF; } $content .= ' /* --> */'; $content .= '</script>'; return $content; }); return $content . $bitlove_html; }