public function prepare_items()
 {
     global $wpdb;
     // number of items per page
     $per_page = 20;
     // define column headers
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     $data = \Podlove\Cache\TemplateCache::get_instance()->cache_for('podlove_analytics_downloads_table', function () {
         global $wpdb;
         // retrieve data
         $subSQL = function ($start = null, $end = null) {
             $strToMysqlDate = function ($s) {
                 return date('Y-m-d', strtotime($s));
             };
             if ($start && $end) {
                 $timerange = " AND di2.accessed_at BETWEEN '{$strToMysqlDate($start)}' AND '{$strToMysqlDate($end)}'";
             } elseif ($start) {
                 $timerange = " AND DATE(di2.accessed_at) = '{$strToMysqlDate($start)}'";
             } else {
                 $timerange = "";
             }
             return "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tCOUNT(di2.id) downloads\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . Model\MediaFile::table_name() . " mf2\n\t\t\t\t\t\tLEFT JOIN " . Model\DownloadIntentClean::table_name() . " di2 ON di2.media_file_id = mf2.id\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tmf2.episode_id = e.id\n\t\t\t\t\t\t{$timerange}\n\t\t\t\t";
         };
         $sql = "\n\t\t\t\tSELECT\n\t\t\t\t\te.id,\n\t\t\t\t\tp.post_title title,\n\t\t\t\t\tp.post_date post_date,\n\t\t\t\t\tCOUNT(di.id) downloads,\n\t\t\t\t\t(" . $subSQL('28 days ago', 'now') . ") downloadsMonth,\n\t\t\t\t\t(" . $subSQL('7 days ago', 'now') . ") downloadsWeek,\n\t\t\t\t\t(" . $subSQL('1 day ago') . ") downloadsYesterday,\n\t\t\t\t\t(" . $subSQL('now') . ") downloadsToday\n\t\t\t\tFROM\n\t\t\t\t\t" . Model\Episode::table_name() . " e\n\t\t\t\t\tJOIN " . $wpdb->posts . " p ON e.post_id = p.ID\n\t\t\t\t\tJOIN " . Model\MediaFile::table_name() . " mf ON e.id = mf.episode_id\n\t\t\t\t\tLEFT JOIN " . Model\DownloadIntentClean::table_name() . " di ON di.media_file_id = mf.id\n\t\t\t\tWHERE\n\t\t\t\t\tp.post_status IN ('publish', 'private')\n\t\t\t\tGROUP BY\n\t\t\t\t\te.id\n\t\t\t";
         return $wpdb->get_results($sql, ARRAY_A);
     }, HOUR_IN_SECONDS);
     $valid_order_keys = array('post_date', 'downloads', 'downloadsMonth', 'downloadsWeek', 'downloadsYesterday', 'downloadsToday');
     // look for order options
     if (isset($_GET['orderby']) && in_array($_GET['orderby'], $valid_order_keys)) {
         $orderby = $_GET['orderby'];
     } else {
         $orderby = 'post_date';
     }
     // look how to sort
     if (isset($_GET['order'])) {
         $order = strtoupper($_GET['order']) == 'ASC' ? SORT_ASC : SORT_DESC;
     } else {
         $order = SORT_DESC;
     }
     array_multisort(\array_column($data, $orderby), $order, $data);
     // get current page
     $current_page = $this->get_pagenum();
     // get total items
     $total_items = count($data);
     // extrage page for current page only
     $data = array_slice($data, ($current_page - 1) * $per_page, $per_page);
     // add items to table
     $this->items = $data;
     // register pagination options & calculations
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
/**
 * Get Podlove episode template object.
 * 
 * @param  int|WP_Post $post          Optional. Post ID or post object. Defaults to global $post.
 * @return \Podlove\Template\Episode
 */
function get_episode($id = null)
{
    $post = get_post($id);
    if (!$post) {
        return null;
    }
    $episode = Model\Episode::find_one_by_property('post_id', $post->ID);
    if (!$episode) {
        return null;
    }
    return new Template\Episode($episode);
}
Esempio n. 3
0
    /**
     * Meta Box Template
     */
    public static function post_type_meta_box_callback($post)
    {
        $post_id = $post->ID;
        $podcast = Model\Podcast::get_instance();
        $episode = Model\Episode::find_or_create_by_post_id($post_id);
        wp_nonce_field(\Podlove\PLUGIN_FILE, 'podlove_noncename');
        ?>
		<input type="hidden" name="show-media-file-base-uri" value="<?php 
        echo $podcast->media_file_base_uri;
        ?>
" />
		<table class="form-table">
			<?php 
        $form_args = array('context' => '_podlove_meta', 'submit_button' => false, 'form' => false);
        \Podlove\Form\build_for($episode, $form_args, function ($form) use($podcast) {
            $wrapper = new \Podlove\Form\Input\TableWrapper($form);
            $episode = $form->object;
            $wrapper->checkbox('active', array('label' => __('Post Episode to Show', 'podlove'), 'description' => '', 'default' => true));
            $wrapper->string('slug', array('label' => __('Episode Media File Slug', 'podlove'), 'description' => '', 'html' => array('class' => 'regular-text')));
            // TODO: validate and parse
            $wrapper->string('duration', array('label' => __('Duration', 'podlove'), 'description' => '', 'html' => array('class' => 'regular-text')));
            $wrapper->string('subtitle', array('label' => __('Subtitle', 'podlove'), 'description' => '', 'html' => array('class' => 'large-text')));
            $wrapper->text('summary', array('label' => __('Summary', 'podlove'), 'description' => '', 'html' => array('class' => 'large-text', 'rows' => max(2, count(explode("\n", $episode->summary))))));
            if ($podcast->supports_cover_art === 'manual') {
                $wrapper->string('cover_art', array('label' => __('Episode Cover Art URL', 'podlove'), 'description' => __('JPEG or PNG. At least 1400 x 1400 pixels.', 'podlove'), 'html' => array('class' => 'regular-text')));
            }
            $wrapper->text('chapters', array('label' => __('Chapter Marks', 'podlove'), 'description' => __('One timepoint (hh:mm:ss[.mmm]) and the chapter title per line.', 'podlove'), 'html' => array('class' => 'large-text code', 'placeholder' => '00:00:00.000 Intro', 'rows' => max(2, count(explode("\n", $episode->chapters))))));
            $wrapper->checkbox('enable', array('label' => __('Enable?', 'podlove'), 'description' => __('Allow this episode to appear in podcast directories.', 'podlove'), 'default' => true));
            // TODO: button to update
            // TODO: pretty display
            // TODO: don't display link
            // TODO: display last modified from header
            $wrapper->multiselect('episode_assets', Podcast_Post_Meta_Box::episode_assets_form($episode));
        });
        ?>
		</table>
		<?php 
    }
    /**
     * Meta Box Template
     */
    public static function post_type_meta_box_callback($post)
    {
        $post_id = $post->ID;
        $podcast = Model\Podcast::get();
        $episode = Model\Episode::find_or_create_by_post_id($post_id);
        wp_nonce_field(\Podlove\PLUGIN_FILE, 'podlove_noncename');
        ?>

		<?php 
        do_action('podlove_episode_meta_box_start');
        ?>

		<input type="hidden" name="show-media-file-base-uri" value="<?php 
        echo $podcast->media_file_base_uri;
        ?>
" />
		<div class="podlove-div-wrapper-form">
			<?php 
        $form_args = array('context' => '_podlove_meta', 'submit_button' => false, 'form' => false, 'is_table' => false);
        $form_data = self::get_form_data($episode);
        \Podlove\Form\build_for($episode, $form_args, function ($form) use($podcast, $form_data) {
            $wrapper = new \Podlove\Form\Input\DivWrapper($form);
            $episode = $form->object;
            foreach ($form_data as $entry) {
                $wrapper->{$entry['type']}($entry['key'], $entry['options']);
            }
        });
        ?>
		</div>

		<?php 
        do_action('podlove_episode_meta_box_end');
        ?>

		<?php 
    }
Esempio n. 5
0
function uninstall_for_current_blog()
{
    global $wpdb;
    Model\Feed::destroy();
    Model\FileType::destroy();
    Model\EpisodeAsset::destroy();
    Model\MediaFile::destroy();
    Model\Episode::destroy();
    Model\Template::destroy();
    Model\DownloadIntent::destroy();
    Model\DownloadIntentClean::destroy();
    Model\UserAgent::destroy();
    Model\GeoArea::destroy();
    Model\GeoAreaName::destroy();
    do_action('podlove_uninstall_plugin');
    // trash all episodes
    $query = new \WP_Query(['post_type' => 'podcast']);
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            wp_trash_post(get_the_ID());
        }
    }
    wp_reset_postdata();
    // delete everything from wp_options
    $wpdb->query('DELETE FROM `' . $wpdb->options . '` WHERE option_name LIKE "%podlove%"');
}
Esempio n. 6
0
function uninstall_for_current_blog()
{
    Model\Feed::destroy();
    Model\FileType::destroy();
    Model\EpisodeAsset::destroy();
    Model\MediaFile::destroy();
    Model\Show::destroy();
    Model\Episode::destroy();
    Model\Release::destroy();
}