コード例 #1
0
function sp_ev_settings_page()
{
    // activate cron hook if not active
    sp_ev_activation();
    wp_enqueue_script('jquery');
    ?>
    <form id="delete_author" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" style="display: none">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="delete_author" />
        <input type="hidden" name="host_id" />
        <input type="hidden" name="author_id" />
    </form>

    <script type="text/javascript">
        function delete_author(host_id, author_id) {
          jQuery('#delete_author [name="host_id"]').val(host_id);
          jQuery('#delete_author [name="author_id"]').val(author_id);
          var confirmtext = <?php 
    echo '"' . sprintf(__('Are you sure you want to remove %s on %s?', 'external-videos'), '"+ author_id +"', '"+ host_id +"') . '"';
    ?>
;
          if (!confirm(confirmtext)) {
              return false;
          }
          jQuery('#delete_author').submit();
        }
    </script>
 
    <div class="wrap">
        <h2><?php 
    _e('External Videos Settings', 'external-videos');
    ?>
</h2>
    <?php 
    $VIDEO_HOSTS = array('youtube' => 'YouTube', 'vimeo' => 'Vimeo', 'dotsub' => 'DotSub');
    $raw_options = get_option('sp_external_videos_options');
    $options = $raw_options == "" ? array('version' => 1, 'authors' => array(), 'rss' => false) : $raw_options;
    // clean up entered data from surplus white space
    $_POST['author_id'] = trim($_POST['author_id']);
    $_POST['secret_key'] = trim($_POST['secret_key']);
    $_POST['developer_key'] = trim($_POST['developer_key']);
    if ($_POST['external_videos'] == 'Y') {
        if ($_POST['action'] == 'add_author') {
            if (!array_key_exists($_POST['host_id'], $VIDEO_HOSTS)) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Invalid video host.', 'external-videos');
                ?>
</strong></p></div><?php 
            } elseif (sp_ev_local_author_exists($_POST['host_id'], $_POST['author_id'], $options['authors'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Author already exists.', 'external-videos');
                ?>
</strong></p></div><?php 
            } elseif (!sp_ev_remote_author_exists($_POST['host_id'], $_POST['author_id'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Invalid author.', 'external-videos');
                ?>
</strong></p></div><?php 
            } elseif (!sp_ev_authorization_exists($_POST['host_id'], $_POST['developer_key'], $_POST['secret_key'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Missing developer key.', 'external-videos');
                ?>
</strong></p></div><?php 
            } else {
                $options['authors'][] = array('host_id' => $_POST['host_id'], 'author_id' => $_POST['author_id'], 'developer_key' => $_POST['developer_key'], 'secret_key' => $_POST['secret_key']);
                update_option('sp_external_videos_options', $options);
                ?>
<div class="updated"><p><strong><?php 
                echo __('Added author.', 'external-videos');
                ?>
</strong></p></div><?php 
            }
        } elseif ($_POST['action'] == 'delete_author') {
            if (!sp_ev_local_author_exists($_POST['host_id'], $_POST['author_id'], $options['authors'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __("Can't delete an author that doesn't exist.", 'external-videos');
                ?>
</strong></p></div><?php 
            } else {
                foreach ($options['authors'] as $key => $author) {
                    if ($author['host_id'] == $_POST['host_id'] && $author['author_id'] == $_POST['author_id']) {
                        unset($options['authors'][$key]);
                    }
                }
                $options['authors'] = array_values($options['authors']);
                // also remove the author's videos from the posts table
                $del_videos = 0;
                $author_posts = new WP_Query(array('post_type' => 'external-videos', 'meta_key' => 'author_id', 'meta_value' => $_POST['author_id'], 'nopaging' => 1));
                while ($author_posts->have_posts()) {
                    $query_video = $author_posts->next_post();
                    $host = get_post_meta($query_video->ID, 'host_id', true);
                    if ($host == $_POST['host_id']) {
                        wp_delete_post($query_video->ID, false);
                        $del_videos += 1;
                    }
                }
                update_option('sp_external_videos_options', $options);
                unset($_POST['host_id'], $_POST['author_id']);
                ?>
<div class="updated"><p><strong><?php 
                printf(_n('Deleted author and his %d video.', 'Deleted author and his %d videos.', $del_videos, 'external-videos'), $del_videos);
                ?>
</strong></p></div><?php 
            }
        } elseif ($_POST['action'] == 'sp_ev_update_videos') {
            $num_videos = sp_ev_update_videos($options['authors']);
            ?>
<div class="updated"><p><strong><?php 
            printf(_n('Found %d video.', 'Found %d videos.', $num_videos, 'external-videos'), $num_videos);
            ?>
</strong></p></div><?php 
        } elseif ($_POST['action'] == 'sp_ev_delete_videos') {
            $num_videos = sp_ev_delete_videos();
            ?>
<div class="deleted"><p><strong><?php 
            printf(_n('Deleted %d video.', 'Deleted %d videos.', $num_videos, 'external-videos'), $num_videos);
            ?>
</strong></p></div><?php 
        } elseif ($_POST['action'] == 'ev_settings') {
            ?>
<div class="update"><p><strong><?php 
            if ($_POST['ev-rss'] == 'rss') {
                _e('Added video pages to RSS feed.', 'external-videos');
                $options['rss'] = true;
            } else {
                _e('Removed video pages from RSS feed.', 'external-videos');
                $options['rss'] = false;
            }
            update_option('sp_external_videos_options', $options);
            ?>
</strong></p></div><?php 
        }
    }
    ?>
    <h3><?php 
    _e('Authors', 'external-videos');
    ?>
</h3>
    <?php 
    foreach ($options['authors'] as $author) {
        echo sprintf(__('%1$s at %2$s', 'external-videos'), $author['author_id'], $VIDEO_HOSTS[$author['host_id']]) . " (<a href=\"#\" onclick=\"delete_author('" . $author['host_id'] . "', '" . $author['author_id'] . "');\">" . __('Delete') . "</a>) <br />\n";
    }
    ?>

    <h3><?php 
    _e('Add Authors', 'external-videos');
    ?>
</h3>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="add_author" />
        <p>
            <?php 
    _e('Video Host:', 'external-videos');
    ?>
            <select name="host_id">
            <?php 
    foreach ($VIDEO_HOSTS as $key => $value) {
        echo "<option value=\"{$key}\">{$value}";
    }
    ?>
            </select>
        <p>
            <?php 
    _e('Author ID:', 'external-videos');
    ?>
            <input type="text" name="author_id" value="<?php 
    echo $_POST['author_id'];
    ?>
"/>
        <p>
            <?php 
    _e('Developer Key:', 'external-videos');
    ?>
            <input type="text" name="developer_key" value="<?php 
    echo $_POST['developer_key'];
    ?>
"/>
            <?php 
    _e('(required for Vimeo, leave empty otherwise)', 'external-videos');
    ?>
        <p>
            <?php 
    _e('Secret Key:', 'external-videos');
    ?>
            <input type="text" name="secret_key" value="<?php 
    echo $_POST['secret_key'];
    ?>
"/>
            <?php 
    _e('(required for Vimeo, leave empty otherwise)', 'external-videos');
    ?>
        </p>
        <p class="submit">
            <input type="submit" name="Submit" value="<?php 
    _e('Add new author', 'external-videos');
    ?>
" />
        </p>
    </form>

    <h3><?php 
    _e('Plugin Settings', 'external-videos');
    ?>
</h3>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
      <input type="hidden" name="external_videos" value="Y" />
      <input type="hidden" name="action" value="ev_settings" />
      <p>
        <?php 
    $ev_rss = $options['rss'];
    ?>
        
        <input type="checkbox" name="ev-rss" value="rss" <?php 
    if ($ev_rss == true) {
        echo "checked";
    }
    ?>
/>
        <?php 
    _e('Add video posts to Website RSS feed', 'external-videos');
    ?>
      </p>
      <p class="submit">
          <input type="submit" name="Submit" value="<?php 
    _e('Save');
    ?>
" />
      </p>
    </form>
    
    <h3><?php 
    _e('Update Videos (newly added/deleted videos)', 'external-videos');
    ?>
</h3>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="sp_ev_update_videos" />
        <p class="submit">
            <input type="submit" name="Submit" value="<?php 
    _e('Update Videos from Channels', 'external-videos');
    ?>
" />
        </p>
    </form>
    <p><?php 
    _e('Next automatic update scheduled for:', 'external-videos');
    ?>
      <i><?php 
    echo date('Y-m-d H:i:s', wp_next_scheduled('ev_daily_event'));
    ?>
</i>
    </p><br />

    <h3><?php 
    _e('Delete All Videos', 'external-videos');
    ?>
</h3>
    <p>
      <?php 
    _e('Be careful with this option - you will lose all links you have built between blog posts and the video pages. This is really only meant as a reset option.', 'external-videos');
    ?>
    </p>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="sp_ev_delete_videos" />
        <p class="submit">
            <input type="submit" name="Submit" value="<?php 
    _e('Remove All Stored Videos From Channels', 'external-videos');
    ?>
" />
        </p>
    </form>

    </div>
    <?php 
}
コード例 #2
0
function sp_ev_settings_page()
{
    // activate cron hook if not active
    sp_ev_activation();
    wp_enqueue_script('jquery');
    ?>
    <form id="delete_author" method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" style="display: none">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="delete_author" />
        <input type="hidden" name="host_id" />
        <input type="hidden" name="author_id" />
    </form>

    <script type="text/javascript">
        function delete_author(host_id, author_id) {
          jQuery('#delete_author [name="host_id"]').val(host_id);
          jQuery('#delete_author [name="author_id"]').val(author_id);
          var confirmtext = <?php 
    echo '"' . sprintf(__('Are you sure you want to remove %s on %s?', 'external-videos'), '"+ author_id +"', '"+ host_id +"') . '"';
    ?>
;
          if (!confirm(confirmtext)) {
              return false;
          }
          jQuery('#delete_author').submit();
        }
    </script>
 
    <div class="wrap">
        <h2><?php 
    _e('External Videos Settings', 'external-videos');
    ?>
</h2>
    <?php 
    $VIDEO_HOSTS = array('youtube' => 'YouTube', 'vimeo' => 'Vimeo', 'dotsub' => 'DotSub', 'wistia' => 'Wistia');
    $raw_options = get_option('sp_external_videos_options');
    $options = $raw_options == "" ? array('version' => 1, 'authors' => array(), 'rss' => false, 'delete' => true) : $raw_options;
    // clean up entered data from surplus white space
    $_POST['author_id'] = trim(sanitize_text_field($_POST['author_id']));
    $_POST['secret_key'] = trim(sanitize_text_field($_POST['secret_key']));
    $_POST['developer_key'] = trim(sanitize_text_field($_POST['developer_key']));
    if ($_POST['external_videos'] == 'Y') {
        if ($_POST['action'] == 'add_author') {
            if (!array_key_exists($_POST['host_id'], $VIDEO_HOSTS)) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Invalid video host.', 'external-videos');
                ?>
</strong></p></div><?php 
            } elseif (sp_ev_local_author_exists($_POST['host_id'], $_POST['author_id'], $options['authors'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Author already exists.', 'external-videos');
                ?>
</strong></p></div><?php 
            } elseif (!sp_ev_authorization_exists($_POST['host_id'], $_POST['developer_key'], $_POST['secret_key'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Missing developer key.', 'external-videos');
                ?>
</strong></p></div><?php 
            } elseif (!sp_ev_remote_author_exists($_POST['host_id'], $_POST['author_id'], $_POST['developer_key'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __('Invalid author - check spelling.', 'external-videos');
                ?>
</strong></p></div><?php 
            } else {
                $options['authors'][] = array('host_id' => $_POST['host_id'], 'author_id' => $_POST['author_id'], 'developer_key' => $_POST['developer_key'], 'secret_key' => $_POST['secret_key'], 'ev_author' => $_POST['user'], 'ev_category' => $_POST['post_category'], 'ev_post_format' => $_POST['post_format'], 'ev_post_status' => $_POST['post_status']);
                update_option('sp_external_videos_options', $options);
                ?>
<div class="updated"><p><strong><?php 
                echo __('Added author.', 'external-videos');
                ?>
</strong></p></div><?php 
            }
        } elseif ($_POST['action'] == 'delete_author') {
            if (!sp_ev_local_author_exists($_POST['host_id'], $_POST['author_id'], $options['authors'])) {
                ?>
<div class="error"><p><strong><?php 
                echo __("Can't delete an author that doesn't exist.", 'external-videos');
                ?>
</strong></p></div><?php 
            } else {
                foreach ($options['authors'] as $key => $author) {
                    if ($author['host_id'] == $_POST['host_id'] && $author['author_id'] == $_POST['author_id']) {
                        unset($options['authors'][$key]);
                    }
                }
                $options['authors'] = array_values($options['authors']);
                // also remove the author's videos from the posts table
                $del_videos = 0;
                $author_posts = new WP_Query(array('post_type' => 'external-videos', 'meta_key' => 'author_id', 'meta_value' => $_POST['author_id'], 'nopaging' => 1));
                while ($author_posts->have_posts()) {
                    $query_video = $author_posts->next_post();
                    $host = get_post_meta($query_video->ID, 'host_id', true);
                    if ($host == $_POST['host_id']) {
                        $post = get_post($query_video->ID);
                        $post->post_status = 'trash';
                        wp_update_post($post);
                        $del_videos += 1;
                    }
                }
                update_option('sp_external_videos_options', $options);
                unset($_POST['host_id'], $_POST['author_id']);
                ?>
<div class="updated"><p><strong><?php 
                printf(__('Deleted author and moved its %d video to trash.', 'Deleted author and its %d videos to trash.', $del_videos, 'external-videos'), $del_videos);
                ?>
</strong></p></div><?php 
            }
        } elseif ($_POST['action'] == 'sp_ev_update_videos') {
            $num_videos = sp_ev_update_videos($options['authors'], $options['delete']);
            ?>
<div class="updated"><p><strong><?php 
            printf(__('Found %d video.', 'Found %d videos.', $num_videos, 'external-videos'), $num_videos);
            ?>
</strong></p></div><?php 
        } elseif ($_POST['action'] == 'sp_ev_delete_videos') {
            $num_videos = sp_ev_delete_videos();
            ?>
<div class="deleted"><p><strong><?php 
            printf(__('Moved %d video into trash.', 'Moved %d videos into trash.', $num_videos, 'external-videos'), $num_videos);
            ?>
</strong></p></div><?php 
        } elseif ($_POST['action'] == 'ev_settings') {
            ?>
<div class="updated"><p><strong><?php 
            if ($_POST['ev-rss'] == "rss") {
                _e('Video pages will appear in RSS feed.', 'external-videos');
                $options['rss'] = true;
            } else {
                _e('Video pages will not appear in RSS feed.', 'external-videos');
                $options['rss'] = false;
            }
            ?>
<br/><?php 
            if ($_POST['ev-delete'] == "delete") {
                _e('Externally removed videos will be trashed.', 'external-videos');
                $options['delete'] = true;
            } else {
                _e('Externally removed videos will be kept.', 'external-videos');
                $options['delete'] = false;
            }
            update_option('sp_external_videos_options', $options);
            ?>
</strong></p></div><?php 
        }
    }
    ?>
    <h3><?php 
    _e('Authors', 'external-videos');
    ?>
</h3>
    <?php 
    foreach ($options['authors'] as $author) {
        echo sprintf(__('%1$s at %2$s', 'external-videos'), $author['author_id'], $VIDEO_HOSTS[$author['host_id']]) . " (<a href=\"#\" onclick=\"delete_author('" . $author['host_id'] . "', '" . $author['author_id'] . "');\">" . __('Delete') . "</a>) <br />\n";
    }
    ?>

    <h3><?php 
    _e('Add Publishers', 'external-videos');
    ?>
</h3>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="add_author" />
        <p>
            <?php 
    _e('Video Host:', 'external-videos');
    ?>
            <select name="host_id">
            <?php 
    foreach ($VIDEO_HOSTS as $key => $value) {
        echo "<option value=\"{$key}\">{$value}";
    }
    ?>
            </select>
        <p>
            <?php 
    _e('Publisher ID:', 'external-videos');
    ?>
            <input type="text" name="author_id" value="<?php 
    echo sanitize_text_field($_POST['author_id']);
    ?>
"/>
            <?php 
    _e('(the identifier at the end of the URL; for wistia: domain prefix)', 'external-videos');
    ?>
        <p>
            <?php 
    _e('Developer Key:', 'external-videos');
    ?>
            <input type="text" name="developer_key" value="<?php 
    echo sanitize_text_field($_POST['developer_key']);
    ?>
"/>
            <?php 
    _e('(required for Vimeo/Wistia, leave empty otherwise)', 'external-videos');
    ?>
        <p>
            <?php 
    _e('Secret Key:', 'external-videos');
    ?>
            <input type="text" name="secret_key" value="<?php 
    echo sanitize_text_field($_POST['secret_key']);
    ?>
"/>
            <?php 
    _e('(required for Vimeo, leave empty otherwise)', 'external-videos');
    ?>
        </p>
        <p>
          <?php 
    _e('Default WP User', 'external-videos');
    ?>
          <?php 
    wp_dropdown_users();
    ?>
        </p>
        <p>
            <?php 
    _e('Default Post Category');
    ?>
            <?php 
    $selected_cats = array(get_cat_ID('External Videos', 'external-videos'));
    ?>
            <ul style="padding-left:20px;">
            <?php 
    wp_category_checklist(0, 0, $selected_cats, false, null, true);
    ?>
            </ul>
        </p>
        <p>
            <?php 
    _e('Default Post Format');
    ?>
            <?php 
    $post_formats = get_post_format_strings();
    unset($post_formats['video']);
    ?>
            <select name="post_format" id="ev_post_format">
              <option value="video"><?php 
    echo get_post_format_string('video');
    ?>
</option>
            <?php 
    foreach ($post_formats as $format_slug => $format_name) {
        ?>
              <option<?php 
        selected(get_option('post_format'), $format_slug);
        ?>
 value="<?php 
        echo esc_attr($format_slug);
        ?>
"><?php 
        echo esc_html($format_name);
        ?>
</option>
            <?php 
    }
    ?>
            </select>
        </p>
        <p>
          <?php 
    _e('Set Post Status', 'external-videos');
    ?>
          <select name='post_status' id='ev_post_status'>
            <option value='publish' selected><?php 
    _e('Published');
    ?>
</option>
            <option value='pending'><?php 
    _e('Pending Review');
    ?>
</option>
            <option value='draft'><?php 
    _e('Draft');
    ?>
</option>
            <option value='private'><?php 
    _e('Privately Published');
    ?>
</option>
            <option value='future'><?php 
    _e('Scheduled');
    ?>
</option>
          </select>
        </p>
        <p class="submit">
            <input type="submit" name="Submit" value="<?php 
    _e('Add new author', 'external-videos');
    ?>
" />
        </p>
    </form>

    <h3><?php 
    _e('Plugin Settings', 'external-videos');
    ?>
</h3>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
      <input type="hidden" name="external_videos" value="Y" />
      <input type="hidden" name="action" value="ev_settings" />
      <?php 
    $ev_rss = $options['rss'];
    $ev_del = $options['delete'];
    ?>
      <p>
        <input type="checkbox" name="ev-rss" value="rss" <?php 
    if ($ev_rss == true) {
        echo "checked";
    }
    ?>
/>
        <?php 
    _e('Add video posts to Website RSS feed', 'external-videos');
    ?>
      </p>
      <p>
        <input type="checkbox" name="ev-delete" value="delete" <?php 
    if ($ev_del == true) {
        echo "checked";
    }
    ?>
/>
        <?php 
    _e('Move videos locally to trash when deleted on external site', 'external-videos');
    ?>
      </p>
      <p class="submit">
          <input type="submit" name="Submit" value="<?php 
    _e('Save');
    ?>
" />
      </p>
    </form>
    
    <h3><?php 
    _e('Update Videos (newly added/deleted videos)', 'external-videos');
    ?>
</h3>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="sp_ev_update_videos" />
        <p class="submit">
            <input type="submit" name="Submit" value="<?php 
    _e('Update Videos from Channels', 'external-videos');
    ?>
" />
        </p>
    </form>
    <p><?php 
    _e('Next automatic update scheduled for:', 'external-videos');
    ?>
      <i><?php 
    echo date('Y-m-d H:i:s', wp_next_scheduled('ev_daily_event'));
    ?>
</i>
    </p><br/>

    <h3><?php 
    _e('Delete All Videos', 'external-videos');
    ?>
</h3>
    <p>
      <?php 
    _e('Be careful with this option - you will lose all links you have built between blog posts and the video pages. This is really only meant as a reset option.', 'external-videos');
    ?>
.
    </p>
    <form method="post" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
">
        <input type="hidden" name="external_videos" value="Y" />
        <input type="hidden" name="action" value="sp_ev_delete_videos" />
        <p class="submit">
            <input type="submit" name="Submit" value="<?php 
    _e('Remove All Stored Videos From Channels', 'external-videos');
    ?>
" />
        </p>
    </form>

    </div>
    <?php 
}