Пример #1
0
    function page()
    {
        ?>
		<div class="wrap">
			<div id="icon-options-general" class="icon32"></div>
			<h2><?php 
        echo __('Podcast Settings');
        ?>
</h2>

			<form method="post" action="options.php">
				<?php 
        settings_fields(Podcast::$pagehook);
        ?>

				<?php 
        $podcast = \Podlove\Model\Podcast::get_instance();
        $form_attributes = array('context' => 'podlove_podcast', 'form' => false);
        \Podlove\Form\build_for($podcast, $form_attributes, function ($form) {
            $wrapper = new \Podlove\Form\Input\TableWrapper($form);
            $podcast = $form->object;
            $wrapper->string('title', array('label' => __('Title', 'podlove'), 'description' => __('', 'podlove'), 'html' => array('class' => 'regular-text required')));
            $wrapper->string('subtitle', array('label' => __('Subtitle', 'podlove'), 'description' => __('The subtitle is used by iTunes.', 'podlove'), 'html' => array('class' => 'regular-text')));
            $wrapper->text('summary', array('label' => __('Summary', 'podlove'), 'description' => __('A couple of sentences describing the podcast.', 'podlove'), 'html' => array('rows' => 5, 'cols' => 40)));
            $wrapper->string('slug', array('label' => __('Mnemonic', 'podlove'), 'description' => __('The abbreviation for your podcast. Commonly the initials of the title.', 'podlove'), 'html' => array('class' => 'regular-text required')));
            $wrapper->image('cover_image', array('label' => __('Cover Art URL', 'podlove'), 'description' => __('JPEG or PNG. At least 1400 x 1400 pixels.', 'podlove'), 'html' => array('class' => 'regular-text'), 'image_width' => 300, 'image_height' => 300));
            $wrapper->string('author_name', array('label' => __('Author Name', 'podlove'), 'description' => __('Publicly displayed in Podcast directories.', 'podlove'), 'html' => array('class' => 'regular-text')));
            $wrapper->string('owner_name', array('label' => __('Owner Name', 'podlove'), 'description' => __('Used by iTunes and other Podcast directories to contact you.', 'podlove'), 'html' => array('class' => 'regular-text')));
            $wrapper->string('owner_email', array('label' => __('Owner Email', 'podlove'), 'description' => __('Used by iTunes and other Podcast directories to contact you.', 'podlove'), 'html' => array('class' => 'regular-text')));
            $wrapper->string('keywords', array('label' => __('Keywords', 'podlove'), 'description' => __('List of keywords. Separate with commas.', 'podlove'), 'html' => array('class' => 'regular-text')));
            $wrapper->select('category_1', array('label' => __('iTunes Categories', 'podlove'), 'description' => '', 'type' => 'select', 'options' => \Podlove\Itunes\categories()));
            $wrapper->select('category_2', array('label' => '', 'description' => '', 'type' => 'select', 'options' => \Podlove\Itunes\categories()));
            $wrapper->select('category_3', array('label' => '', 'description' => '<br>' . __('For placement within the older, text-based browse system, podcast feeds may list up to 3 category/subcategory pairs. (For example, "Music" counts as 1, as does "Business > Careers.") For placement within the newer browse system based on Category links, however, and for placement within the Top Podcasts and Top Episodes lists that appear in the right column of most podcast pages, only the first category listed in the feed is used.') . ' (<a href="http://www.apple.com/itunes/podcasts/specs.html#category" target="_blank">http://www.apple.com/itunes/podcasts/specs.html#category</a>)', 'options' => \Podlove\Itunes\categories()));
            $wrapper->select('language', array('label' => __('Language', 'podlove'), 'description' => __('', 'podlove'), 'default' => get_bloginfo('language'), 'options' => \Podlove\Locale\locales()));
            $wrapper->select('explicit', array('label' => __('Explicit Content?', 'podlove'), 'description' => __('', 'podlove'), 'type' => 'checkbox', 'options' => array(0 => 'no', 1 => 'yes', 2 => 'clean')));
            $wrapper->string('media_file_base_uri', array('label' => __('Media File Base URL', 'podlove'), 'description' => __('Example: http://cdn.example.com/pod/', 'podlove'), 'html' => array('class' => 'regular-text required')));
            $artwork_options = array('0' => __('None', 'podlove'), 'manual' => __('Manual Entry', 'podlove'));
            $episode_assets = Model\EpisodeAsset::all();
            foreach ($episode_assets as $episode_asset) {
                $file_type = $episode_asset->file_type();
                if ($file_type && $file_type->type === 'image') {
                    $artwork_options[$episode_asset->id] = sprintf(__('Media File: %s', 'podlove'), $episode_asset->title);
                }
            }
            $wrapper->select('supports_cover_art', array('label' => __('Episode Artwork Media File', 'podlove'), 'options' => $artwork_options));
        });
        ?>
				
			</form>
		</div>	
		<?php 
    }
    private function form_template($list, $action, $button_text = NULL)
    {
        $form_args = array('context' => 'podlove_list', 'hidden' => array('list' => $list->id, 'action' => $action));
        \Podlove\Form\build_for($list, $form_args, function ($form) {
            $wrapper = new \Podlove\Form\Input\TableWrapper($form);
            $list = $form->object;
            $wrapper->string('slug', array('label' => __('ID', 'podlove'), 'html' => array('class' => 'regular-text required'), 'description' => sprintf(__('For referencing in templates: %s', 'podlove'), '<code>{{ network.lists({id: "example"}).title }}</code>')));
            $wrapper->string('title', array('label' => __('Title', 'podlove'), 'html' => array('class' => 'regular-text required')));
            $wrapper->string('subtitle', array('label' => __('Subtitle', 'podlove'), 'html' => array('class' => 'regular-text')));
            $wrapper->text('description', array('label' => __('Summary', 'podlove'), 'description' => __('', 'podlove'), 'html' => array('rows' => 3, 'cols' => 40, 'class' => 'autogrow')));
            $wrapper->image('logo', array('label' => __('Logo', 'podlove'), 'description' => __('JPEG or PNG.', 'podlove'), 'html' => array('class' => 'regular-text'), 'image_width' => 300, 'image_height' => 300));
            $wrapper->string('url', array('label' => __('List URL', 'podlove'), 'description' => __('', 'podlove'), 'html' => array('class' => 'regular-text')));
            $wrapper->callback('podcasts', array('label' => __('Podcasts', 'podlove'), 'callback' => function () use($list) {
                $form_base_name = "podlove_list";
                ?>
					<div id="podcast_lists">
						<table class="podlove_alternating" border="0" cellspacing="0">
							<thead>
								<tr>
									<th><?php 
                echo __('Source', 'podlove');
                ?>
</th>
									<th><?php 
                echo __('Podcast/URL', 'podlove');
                ?>
</th>
									<th style="width: 60px"><?php 
                echo __('Remove', 'podlove');
                ?>
</th>
									<th style="width: 30px"></th>
								</tr>
							</thead>
							<tbody class="podcasts_table_body" style="min-height: 50px;">
								<tr class="podcasts_table_body_placeholder" style="display: none;">
									<td><em><?php 
                echo __('No Podcasts were added yet.', 'podlove');
                ?>
</em></td>
								</tr>
							</tbody>
						</table>

						<div id="add_new_podcasts_wrapper">
							<input class="button" id="add_new_podcast" value="+" type="button" />
						</div>

						<script type="text/template" id="podcast-row-template">
						<tr class="media_file_row podlove-podcast-table" data-id="{{id}}">
							<td class="podlove-podcast-column">
								<select name="<?php 
                echo $form_base_name;
                ?>
[podcasts][{{id}}][type]" class="podlove-podcast-dropdown">
									<option value="wplist" selected><?php 
                echo __('WordPress Network', 'podlove');
                ?>
</option>
								</select>
							</td>
							<td class="podlove-podcast-value"></td>
							<td>
								<span class="podcast_remove">
									<i class="clickable podlove-icon-remove"></i>
								</span>
							</td>
							<td class="move column-move"><i class="reorder-handle podlove-icon-reorder"></i></td>
						</tr>
						</script>
						<script type="text/template" id="podcast-select-type-wplist">
						<select name="<?php 
                echo $form_base_name;
                ?>
[podcasts][{{id}}][podcast]" class="podlove-podcast chosen-image">
							<option>— <?php 
                echo __('Select Podcast', 'podlove');
                ?>
 —</option>
							<?php 
                foreach (Network::podcasts() as $blog_id => $podcast) {
                    if ($podcast->title) {
                        printf("<option value='%s' data-img-src='%s'>%s</option>\n", $blog_id, $podcast->cover_art()->setWidth(45)->url(), $podcast->title);
                    }
                }
                ?>
						</select>
						</script>
					</div>

					<script type="text/javascript">

						var PODLOVE = PODLOVE || {};

						(function($) {
							var i = 0;
							var existing_podcasts = <?php 
                echo is_null($list->podcasts) ? "[]" : $list->podcasts;
                ?>
;
							var podcasts = [];

							function update_chosen() {
								$(".chosen").chosen();
								$(".chosen-image").chosenImage();
							}

							function podcast_dropdown_handler() {
								$('select.podlove-podcast-dropdown').change(function() {
									row = $(this).closest("tr");
									podcast_source = $(this).val();

									// Check for empty podcast / for new field
									if (podcast_source === '') {
										row.find(".podlove-podcast-value").html(""); // Empty podcast column and hide edit button
										row.find(".podlove-podcast-edit").hide();
										return;
									}

									if (!row.find(".podlove-podcast").length) {
										template_id = "#podcast-select-type-" + podcast_source;
										template = $( template_id ).html();
										template = template.replace(/\{\{id\}\}/g, row.data('id') );

										row.find(".podlove-podcast-value").html( template );
										update_chosen();

										i++; // continue using "i" which was already used to add the existing contributions
									}

								});
							}

							$(document).ready(function() {
								$("#podcast_lists table").podloveDataTable({
									rowTemplate: "#podcast-row-template",
									deleteHandle: ".podcast_remove",
									sortableHandle: ".reorder-handle",
									addRowHandle: "#add_new_podcast",
									data: existing_podcasts,
									dataPresets: podcasts,
									onRowLoad: function(o) {
										template_id = "#podcast-select-type-" + o.entry.type;
										template = $( template_id ).html();
										row_as_object = $(o.row)
										
										row_as_object.find(".podlove-podcast-value").html( template );
										row_as_object.find('select.podlove-podcast-dropdown option[value="' + o.entry.type + '"]').attr('selected', 'selected');

										switch ( o.entry.type ) {
											default: case 'wplist':
												row_as_object.find('select.podlove-podcast option[value="' + o.entry.podcast + '"]').attr('selected', true);
											break;
										}

										o.row = row_as_object[0].outerHTML.replace(/\{\{id\}\}/g, i);

										i++;
									},
									onRowAdd: function(o) {
										o.row = o.row.replace(/\{\{id\}\}/g, i);

										
										row = $(".podcasts_table_body tr:last .podlove-podcast-dropdown").focus();

										podcast_dropdown_handler();
										update_chosen();
										row.change();
									},
									onRowDelete: function(tr) {
										
									}
								});
							});

						}(jQuery));

					</script>
					<?php 
            }));
        });
    }