예제 #1
0
    $new_playlist = array();
    $new_playlist["post_title"] = $post_title;
    $new_playlist["post_type"] = "jw_playlist";
    $new_playlist["post_status"] = null;
    $new_playlist["post_parent"] = null;
    if (isset($_POST["save"])) {
        $new_playlist_id = isset($_POST[LONGTAIL_KEY . "playlist_select"]) ? $_POST[LONGTAIL_KEY . "playlist_select"] : $playlists[0]->ID;
    } else {
        $new_playlist_id = wp_insert_post($new_playlist);
        $playlists = jwplayer_get_playlists();
    }
    $current_playlist = $new_playlist_id;
} else {
    if (isset($_POST["delete"])) {
        wp_delete_post($_POST[LONGTAIL_KEY . "playlist_select"]);
        $playlists = jwplayer_get_playlists();
        $current_playlist = $playlists[0]->ID;
    }
}
if (!isset($current_playlist)) {
    if (isset($_POST[LONGTAIL_KEY . "playlist_select"])) {
        $current_playlist = $_POST[LONGTAIL_KEY . "playlist_select"];
    } else {
        if (isset($_GET["playlist"])) {
            $current_playlist = $_GET["playlist"];
        } else {
            if (!empty($playlists)) {
                $current_playlist = $playlists[0]->ID;
            } else {
                $current_playlist = -1;
            }
예제 #2
0
/**
 * This file contains the necessary methods for rendering the Playlist Manager
 * tab in the WordPress media popup.  The code is largely borrowed from the
 * WordPress Gallery with necessary modifications for managing playlists and
 * showing all uploaded media.
 * @global string $redir_tab Global reference to the tab to redirect to on
 * submit.
 * @global string $type Global reference to the type of content being managed.
 * @param undefined $errors List of any errors encountered.
 */
function media_jwplayer_insert_form($errors)
{
    global $redir_tab, $type, $jw_query, $p_items;
    $args = array('post_parent' => null, 'posts_per_page' => 10, 'paged' => $_GET['paged'] ? $_GET['paged'] : 1, 'post_status' => 'inherit', 'post_type' => 'attachment', 'orderby' => 'title ASC, ID', 'order' => 'DESC');
    $jw_query = new WP_Query($args);
    $redir_tab = 'jwplayer';
    media_upload_header();
    $post_id = intval($_REQUEST['post_id']);
    $form_action_url = admin_url("media-upload.php?type={$type}&tab=jwplayer&post_id={$post_id}");
    $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
    $playlists = jwplayer_get_playlists();
    if (isset($_POST[LONGTAIL_KEY . "playlist_create"]) || isset($_POST["save"])) {
        $post_title = $_POST[LONGTAIL_KEY . "playlist_name"];
        $new_playlist = array();
        $new_playlist["post_title"] = $post_title;
        $new_playlist["post_type"] = "jw_playlist";
        $new_playlist["post_status"] = null;
        $new_playlist["post_parent"] = null;
        $new_playlist_id = -1;
        if (isset($_POST["save"])) {
            $new_playlist_id = isset($_POST[LONGTAIL_KEY . "playlist_select"]) ? $_POST[LONGTAIL_KEY . "playlist_select"] : $playlists[0]->ID;
        } else {
            $new_playlist_id = wp_insert_post($new_playlist);
            $playlists = jwplayer_get_playlists();
        }
        $current_playlist = $new_playlist_id;
    } else {
        if (isset($_POST["delete"])) {
            wp_delete_post($_POST[LONGTAIL_KEY . "playlist_select"]);
            $playlists = jwplayer_get_playlists();
            $current_playlist = $playlists[0]->ID;
        }
    }
    if (!isset($current_playlist)) {
        if (isset($_POST[LONGTAIL_KEY . "playlist_select"])) {
            $current_playlist = $_POST[LONGTAIL_KEY . "playlist_select"];
        } else {
            if (isset($_GET["playlist"])) {
                $current_playlist = $_GET["playlist"];
            } else {
                $current_playlist = $playlists[0]->ID;
            }
        }
    }
    if (isset($_GET["p_items"])) {
        $p_items = json_decode(str_replace("\\", "", $_GET["p_items"]));
    } else {
        if (isset($_POST["playlist_items"]) && $_POST["old_playlist"] == $current_playlist) {
            $p_items = json_decode(str_replace("\\", "", $_POST["playlist_items"]));
        } else {
            $p_items = explode(",", get_post_meta($current_playlist, LONGTAIL_KEY . "playlist_items", true));
        }
    }
    update_post_meta($new_playlist_id, LONGTAIL_KEY . "playlist_items", implode(",", $p_items));
    echo '<link rel="stylesheet" href="' . WP_PLUGIN_URL . '/' . plugin_basename(dirname(dirname(__FILE__))) . '/' . 'css/playlist.css" type="text/css" media="print, projection, screen" />' . "\n";
    echo '<script type=text/javascript src="' . WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__)) . '/' . 'js/playlist.js"></script>' . "\n";
    ?>

<script type="text/javascript">

  jQuery(function($){
    var desc = false;
    var preloaded = $(".media-item.preloaded");
    if ( preloaded.length > 0 ) {
      preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
      updateMediaForm();
    }
    var playlistPreloaded = $(".playlist-item.preloaded");
    if ( playlistPreloaded.length > 0 ) {
      playlistPreloaded.each(function(){preparePlaylistItem({id:this.id.replace(/[^0-9]/g, '')},'');});
      updatePlaylistForm();
    }
    $('#playlist-items').sortable( {
			items: 'div.playlist-item',
			placeholder: 'sorthelper',
			axis: 'y',
			distance: 2,
			handle: 'div.filename',
			stop: function(e, ui) {
				// When an update has occurred, adjust the order for each item
        var item_list = document.getElementById("playlist_items");
        var p_items = new Array();
        var old_p_items =  eval('(' + item_list.value + ')');
        if (old_p_items[0] == "") {old_p_items = new Array();}
				var all = $('#playlist-items').sortable('toArray'), len = all.length;
				$.each(all, function(i, id) {
					var order = desc ? (len - i) : (1 + i);
					$('#' + id + ' .menu_order input').val(order);
          p_items.push(id.replace("playlist-item-", ""));
				});
        update_page_numbers(p_items, old_p_items);
        document.getElementById("playlist_items").value = dump(p_items);
			}
		} );
  });

  function insertPlaylist() {
    var s;
    var playlist_dropdown = document.getElementById("<?php 
    echo LONGTAIL_KEY . "playlist_select";
    ?>
");
    var player_dropdown = document.getElementById("<?php 
    echo LONGTAIL_KEY . "player_select";
    ?>
");
    s = "[jwplayer ";
    if (player_dropdown.value != "Default") {
      s += "config=\"" + player_dropdown.value + "\" ";
    }
    s += "playlistid=\"" + playlist_dropdown.value + "\"]";
    getJWWin().send_to_editor(s);
    return;
  }

  function getJWWin() {
    return window.dialogArguments || opener || parent || top;
  }

  function deletePlaylistHandler() {
    return confirm("Are you sure wish to delete the Playlist?");
  }

  function createPlaylistHandler() {
    var playlistName = document.forms[0]["<?php 
    echo LONGTAIL_KEY . "playlist_name";
    ?>
"];
    if (playlistName.value == "") {
      alert("Your playlist must have a valid name.");
      return false;
    }
    return true;
  }

  function updatePlaylist(object) {
    var item_list = document.getElementById("playlist_items");
    var p_items = eval('(' + item_list.value + ')');
    if (p_items[0] == "") {p_items = new Array();}
    var old_p_items =  eval('(' + item_list.value + ')');
    if (old_p_items[0] == "") {old_p_items = new Array();}
    var playlist_check = object.id.indexOf("playlist_") > -1;
    var attachment_id = "";
    attachment_id = playlist_check ? object.id.replace("playlist_", "") : object.id;
    attachment_id = attachment_id.replace("attachments[", "").replace("][enabled]", "");
    if (object != null && object.checked === true) {
      p_items.push(attachment_id);
      update_checks(attachment_id, playlist_check, true);
    } else {
      var i = 0;
      for (i=0; i < p_items.length; i++) {
        if (p_items[i] == attachment_id) {
          break;
        }
      }
      update_checks(attachment_id, playlist_check, false);
      p_items.splice(i, 1);
    }
    update_page_numbers(p_items, old_p_items);
    item_list.value = dump(p_items);
  }

  function update_page_numbers(p_items, old_p_items) {
    var pages = jQuery(".page-numbers");
    var j = 0;
    for (j = 0; j < pages.length; j++) {
      var page = pages[j];
      if (page.href) {
        page.href = page.href.replace(encodeURI("&p_items=" + dump(old_p_items)), "");
        page.href = page.href + encodeURI("&p_items=" + dump(p_items));
      }
    }
  }

  function update_checks(attachment_id, playlist_check, new_state) {
    if (playlist_check) {
      var targetBox = document.getElementById("attachments[" + attachment_id + "][enabled]");
      if (targetBox != null) {
        targetBox.checked = new_state;
      }
    }
    if (new_state) {
      var itemToAdd = jQuery("#media-item-" + attachment_id).clone();
      itemToAdd[0].id = itemToAdd[0].id.replace("media", "playlist");
      itemToAdd[0].className = itemToAdd[0].className.replace("media", "playlist");
      var input = itemToAdd.children(".menu_order").children(".menu_order_input")[0];
      input.id = "playlist_" + input.id
      input.name = "playlist_" + input.name;
      if (input != null) input.checked = true;
      itemToAdd.appendTo("#playlist-items");
    } else {
      jQuery("#playlist-item-" + attachment_id).empty().remove();
    }
  }

</script>

<form enctype="multipart/form-data" method="post" action="<?php 
    echo esc_attr($form_action_url);
    ?>
" class="media-upload-form validate" id="playlist-form" style="width: 626px;">
  <?php 
    wp_nonce_field('media-form');
    ?>
  <?php 
    //media_upload_form( $errors );
    ?>
  <div class="tablenav" style="width: 626px;">
    <?php 
    $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'total' => ceil($jw_query->found_posts / 10), 'current' => $_GET['paged'] ? $_GET['paged'] : 1, 'add_args' => array('playlist' => $current_playlist)));
    if ($page_links) {
        ?>
        <div class='tablenav-pages'>
          <span style="font-size: 13px;"><?php 
        _e("Available Media:");
        ?>
</span>
          <?php 
        echo $page_links;
        ?>
        </div>
      <?php 
    }
    ?>
    <div class="alignleft actions">
      <div class="hide-if-no-js">
        <?php 
    _e("Playlist:");
    ?>
        <select onchange="this.form.submit()" id="<?php 
    echo LONGTAIL_KEY . "playlist_select";
    ?>
" name="<?php 
    echo LONGTAIL_KEY . "playlist_select";
    ?>
">
          <?php 
    foreach ($playlists as $playlist) {
        ?>
            <option value="<?php 
        echo $playlist->ID;
        ?>
" <?php 
        selected($playlist->ID, $current_playlist);
        ?>
>
              <?php 
        echo $playlist->post_title;
        ?>
            </option>
          <?php 
    }
    ?>
        </select>
        <input type="submit" class="button savebutton" name="save" id="save-all" value="<?php 
    esc_attr_e('Save');
    ?>
" />
        <input type="submit" class="button savebutton" name="delete" id="delete-all" value="<?php 
    esc_attr_e('Delete');
    ?>
" onclick="return deletePlaylistHandler()" />
        <input type="hidden" name="post_id" id="post_id" value="<?php 
    echo (int) $post_id;
    ?>
" />
        <input type="hidden" name="type" value="<?php 
    echo esc_attr($GLOBALS['type']);
    ?>
" />
        <input type="hidden" name="tab" value="<?php 
    echo esc_attr($GLOBALS['tab']);
    ?>
" />
        <input type="hidden" id="playlist_items" name="playlist_items" value='<?php 
    echo json_encode($p_items);
    ?>
' />
        <input type="hidden" id="old_playlist" name="old_playlist" value="<?php 
    echo $current_playlist;
    ?>
" />
      </div>
    </div>
  </div>

  <div id="playlist-items" style="width: 300px; float: left;" class="ui-sortable">
    <?php 
    echo get_jw_playlist_items($post_id, $errors, $current_playlist);
    ?>
  </div>

  <div id="media-items" style="width: 300px; float: right;">
    <?php 
    add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
    ?>
    <?php 
    echo get_playlist_items($post_id, $errors, $current_playlist);
    ?>
  </div>

  <div class="clear"></div>

  <p class="ml-submit">
    <?php 
    _e("New Playlist:");
    ?>
    <input type="text" value="" name="<?php 
    echo LONGTAIL_KEY . "playlist_name";
    ?>
" />
    <input type="submit" class="button savebutton" style="" name="<?php 
    echo LONGTAIL_KEY . "playlist_create";
    ?>
" id="<?php 
    echo LONGTAIL_KEY . "playlist_create";
    ?>
" value="<?php 
    esc_attr_e("Create Playlist");
    ?>
" onclick="return createPlaylistHandler()" />
  </p>
  <p class="ml-submit" style="padding: 0em 0;">
    <?php 
    _e("Select Player:");
    ?>
    <select name="<?php 
    echo LONGTAIL_KEY . "player_select";
    ?>
" id="<?php 
    echo LONGTAIL_KEY . "player_select";
    ?>
">
      <option value="Default">Default</option>
      <?php 
    $configs = LongTailFramework::getConfigs();
    ?>
      <?php 
    if ($configs) {
        ?>
        <?php 
        foreach ($configs as $config) {
            ?>
          <?php 
            if ($config != "New Player") {
                ?>
            <option value="<?php 
                echo $config;
                ?>
"><?php 
                echo $config;
                ?>
</option>
          <?php 
            }
            ?>
        <?php 
        }
        ?>
      <?php 
    }
    ?>
    </select>
    <input type="button" class="button-primary" onmousedown="insertPlaylist();" name="insert-gallery" id="insert-gallery" value="<?php 
    esc_attr_e('Insert Playlist');
    ?>
" />
  </p>
</form>
<?php 
}
/**
 * This file contains the necessary methods for rendering the Playlist Manager
 * tab in the WordPress media popup.  The code is largely borrowed from the
 * WordPress Gallery with necessary modifications for managing playlists and
 * showing all uploaded media.
 * @global string $redir_tab Global reference to the tab to redirect to on
 * submit.
 * @global string $type Global reference to the type of content being managed.
 * @param mixed $errors List of any errors encountered.
 */
function media_jwplayer_insert_form($errors)
{
    global $redir_tab, $type;
    $redir_tab = 'jwplayer';
    media_upload_header();
    $post_id = intval($_REQUEST['post_id']);
    $form_action_url = admin_url("media-upload.php?type={$type}&tab=jwplayer&post_id={$post_id}");
    $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
    $playlists = jwplayer_get_playlists();
    $current_playlist = $playlists[0]->ID;
    ?>

<script type="text/javascript">

  function insertPlaylist() {
    var s;
    var playlist_dropdown = document.getElementById("<?php 
    echo LONGTAIL_KEY . "playlist_select";
    ?>
");
    var player_dropdown = document.getElementById("<?php 
    echo LONGTAIL_KEY . "player_select";
    ?>
");
    s = "[jwplayer ";
    if (player_dropdown.value != "Default") {
      s += "config=\"" + player_dropdown.value + "\" ";
    }
    s += "playlistid=\"" + playlist_dropdown.value + "\"]";
    getJWWin().send_to_editor(s);
  }

  function getJWWin() {
    return window.dialogArguments || opener || parent || top;
  }

</script>

<form enctype="multipart/form-data" method="post" action="<?php 
    echo esc_attr($form_action_url);
    ?>
" class="media-upload-form validate" id="playlist-form" style="width: 626px;">
  <?php 
    wp_nonce_field('media-form');
    ?>

  <h3 class="media-title"><?php 
    _e("Insert a playlist", 'jw-player-plugin-for-wordpress');
    ?>
</h3>
  <p><?php 
    _e("This tab allows you to insert one of your playlists into your post.  To construct a playlist please visit the Playlist Media page.", 'jw-player-plugin-for-wordpress');
    ?>
</p>
  <div id="media-items">
    <div class="media-item">
      <div class="alignleft actions" style="margin: 1em;">
        <div class="hide-if-no-js">
          <label for="<?php 
    echo LONGTAIL_KEY . "playlist_select";
    ?>
"><strong><?php 
    _e("Select Playlist:", 'jw-player-plugin-for-wordpress');
    ?>
</strong></label>
          <select id="<?php 
    echo LONGTAIL_KEY . "playlist_select";
    ?>
" name="<?php 
    echo LONGTAIL_KEY . "playlist_select";
    ?>
">
            <?php 
    foreach ($playlists as $playlist_list) {
        ?>
            <option value="<?php 
        echo $playlist_list->ID;
        ?>
" <?php 
        selected($playlist_list->ID, $current_playlist);
        ?>
>
              <?php 
        echo $playlist_list->post_title;
        ?>
            </option>
            <?php 
    }
    ?>
          </select>
          <input type="hidden" name="post_id" id="post_id" value="<?php 
    echo (int) $post_id;
    ?>
" />
          <input type="hidden" name="type" value="<?php 
    echo esc_attr($GLOBALS['type']);
    ?>
" />
          <input type="hidden" name="tab" value="<?php 
    echo esc_attr($GLOBALS['tab']);
    ?>
" />
        </div>
      </div>

      <div class="clear"></div>

      <p class="ml-submit" style="padding: 0 0; margin: 1em;">
        <label for="<?php 
    echo LONGTAIL_KEY . "player_select";
    ?>
"><strong><?php 
    _e("Select Player:", 'jw-player-plugin-for-wordpress');
    ?>
</strong></label>
        <select name="<?php 
    echo LONGTAIL_KEY . "player_select";
    ?>
" id="<?php 
    echo LONGTAIL_KEY . "player_select";
    ?>
">
          <option value="Default">Default</option>
          <?php 
    $configs = LongTailFramework::getConfigs();
    ?>
          <?php 
    if ($configs) {
        ?>
          <?php 
        foreach ($configs as $config) {
            ?>
            <?php 
            if ($config != "New Player") {
                ?>
              <option value="<?php 
                echo $config;
                ?>
"><?php 
                echo $config;
                ?>
</option>
              <?php 
            }
            ?>
            <?php 
        }
        ?>
          <?php 
    }
    ?>
        </select>
        <input type="button" class="button-primary" onmousedown="insertPlaylist();" name="insert-gallery" id="insert-gallery" value="<?php 
    esc_attr_e('Insert Playlist', 'jw-player-plugin-for-wordpress');
    ?>
" />
      </p>
    </div>
  </div>
</form>
<?php 
}