private function form_template($episode_asset, $action, $button_text = NULL) { $raw_formats = \Podlove\Model\FileType::all(); $formats = array(); foreach ($raw_formats as $format) { $formats[$format->id] = array('title' => $format->title(), 'name' => $format->name, 'extension' => $format->extension, 'type' => $format->type); } $format_optionlist = array_map(function ($f) { return array('value' => $f['title'], 'attributes' => 'data-type="' . $f['type'] . '" data-extension="' . $f['extension'] . '" data-name="' . $f['name'] . '"'); }, $formats); $form_args = array('context' => 'podlove_episode_asset', 'hidden' => array('episode_asset' => $episode_asset->id, 'action' => $action), 'attributes' => array('id' => 'podlove_episode_assets'), 'submit_button' => false, 'form_end' => function () { echo "<p>"; submit_button(__('Save Changes'), 'primary', 'submit', false); echo " "; submit_button(__('Save Changes and Continue Editing', 'podlove'), 'secondary', 'submit_and_stay', false); echo "</p>"; }); \Podlove\Form\build_for($episode_asset, $form_args, function ($form) use($format_optionlist) { $f = new \Podlove\Form\Input\TableWrapper($form); if ($form->object->file_type_id) { $current_file_type = Model\FileType::find_by_id($form->object->file_type_id)->type; } else { $current_file_type = ''; } ?> <tr class="row_podlove_episode_asset_type"> <th scope="row" valign="top"> <label for="podlove_episode_asset_type"><?php echo __('Asset Type', 'podlove'); ?> </label> </th> <td> <select name="podlove_episode_asset_type" id="podlove_episode_asset_type"> <option><?php echo __('Please choose ...', 'podlove'); ?> </option> <?php foreach (Model\FileType::get_types() as $type) { ?> <option value="<?php echo $type; ?> " <?php selected($type, $current_file_type); ?> ><?php echo $type; ?> </option> <?php } ?> </select> <div id="option_storage" style="display:none"></div> </td> </tr> <?php $f->select('file_type_id', array('label' => __('File Format', 'podlove'), 'description' => __('', 'podlove'), 'options' => $format_optionlist)); $f->string('title', array('label' => __('Title', 'podlove'), 'description' => __('Description to identify the media file type to the user in download buttons.', 'podlove'), 'html' => array('class' => 'regular-text required podlove-check-input'))); $f->checkbox('downloadable', array('label' => __('Downloadable', 'podlove'), 'description' => sprintf('Allow downloads for users.', 'podlove'), 'default' => true)); ?> <tr> <th colspan="2"> <h3><?php echo __('Asset File Name', 'podlove'); ?> </h3> </th> </tr> <?php $f->string('suffix', array('label' => __('File Name Suffix', 'podlove'), 'description' => __('Optional. Is appended to file name after episode slug.', 'podlove'), 'html' => array('class' => 'regular-text required podlove-check-input'))); ?> <tr class="row_podlove_asset_url_preview"> <th> <?php echo __('URL Preview', 'podlove'); ?> </th> <td> <div id="url_preview" style="font-size: 1.5em"></div> <div id="url_template" style="display: none;"><?php echo Model\Podcast::get()->get_url_template(); ?> </div> </td> </tr> <?php }); // hidden fields for JavaScript ?> <input type="hidden" id="podlove_show_media_file_base_uri" value="<?php echo Model\Podcast::get()->media_file_base_uri; ?> "> <?php }
private function edit_template() { $format = \Podlove\Model\FileType::find_by_id($_REQUEST['file_type']); ?> <h3>Edit Format: <?php echo $format->name; ?> </h3> <?php $this->form_template($format, 'save'); ?> <?php }
/** * Return real file URL * * For public facing URLs, use ::get_public_file_url(). * * @return string */ public function get_file_url() { return $this->with_blog_scope(function () { $podcast = Podcast::get(); $episode = $this->episode(); $episode_asset = EpisodeAsset::find_by_id($this->episode_asset_id); $file_type = FileType::find_by_id($episode_asset->file_type_id); if (!$episode_asset || !$file_type || !$episode) { return ''; } $template = $podcast->get_url_template(); $template = apply_filters('podlove_file_url_template', $template); $template = str_replace('%media_file_base_url%', trailingslashit($podcast->media_file_base_uri), $template); $template = str_replace('%episode_slug%', \Podlove\slugify($episode->slug), $template); $template = str_replace('%suffix%', $episode_asset->suffix, $template); $template = str_replace('%format_extension%', $file_type->extension, $template); return trim($template); }); }