/**
 * The main manager screen.
 */
function cpm_manager_first_run($target_page)
{
    global $comicpress_manager;
    $target_page = "?page={$target_page}";
    $is_wpmu = function_exists("get_site_option");
    ob_start();
    ?>
  <h2>ComicPress Manager First Run</h2>

  <p><strong>Thank you for using ComicPress Manager.</strong> I can attempt to create your starting comic directories for you.
    <?php 
    if (!$is_wpmu) {
        ?>
      I'll be creating them in <?php 
        echo CPM_DOCUMENT_ROOT;
        ?>
.
    <?php 
    }
    ?>
  </p>

  <form action="<?php 
    echo $target_page;
    ?>
" method="post">
    <input type="hidden" name="action" value="do-first-run" />
    <input class="button" type="submit" value="Yes, try and make my comic directories" />
  </form>

  <?php 
    if (!$is_wpmu) {
        ?>
    <form action="<?php 
        echo $target_page;
        ?>
" method="post">
      <input type="hidden" name="action" value="skip-first-run" />
      <input class="button" type="submit" value="No, I'll make them myself" />
    </form>
  <?php 
    }
    ?>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content(null, $activity_content);
}
/**
 * The main manager screen.
 */
function cpm_manager_index()
{
    global $cpm_config;
    if (cpm_get_subcomic_directory() !== false) {
        $cpm_config->messages[] = sprintf(__("<strong>Reminder:</strong> You are managing the <strong>%s</strong> comic subdirectory.", 'comicpress-manager'), get_cat_name(get_option('comicpress-manager-manage-subcomic')));
    }
    $cpm_config->need_calendars = true;
    $example_date = cpm_generate_example_date(CPM_DATE_FORMAT);
    $example_real_date = date(CPM_DATE_FORMAT);
    $zip_extension_loaded = extension_loaded('zip');
    if (cpm_option('cpm-skip-checks') != 1) {
        if (!function_exists('get_comic_path')) {
            $cpm_config->warnings[] = __('<strong>It looks like you\'re running an older version of ComicPress.</strong> Storyline, hovertext, and transcript are fully supported in <a href="http://comicpress.org/">ComicPress 2.7</a>. You can use hovertext and transcripts in earlier themes by using <tt>get_post_meta($post->ID, "hovertext", true)</tt> and <tt>get_post_meta($post->ID, "transcript", true)</tt>.', 'comicpress-manager');
        }
    }
    if (count($_POST) == 0 && isset($_GET['upload'])) {
        $cpm_config->warnings[] = sprintf(__("Your uploaded files were larger than the <strong><tt>post_max_size</tt></strong> setting, which is currently <strong><tt>%s</tt></strong>. Either upload fewer/smaller files, upload them via FTP/SFTP, or increase your server's <strong><tt>post_max_size</tt></strong>.", 'comicpress-manager'), ini_get('post_max_size'));
    }
    ob_start();
    ?>
    <p>
      <strong>
        <?php 
    _e("ComicPress Manager manages your comics and your time.", 'comicpress-manager');
    ?>
      </strong>
      <?php 
    _e("It makes uploading new comics, importing comics from a non-ComicPress setup, and batch uploading a lot of comics at once, very fast and configurable.", 'comicpress-manager');
    ?>
    </p>

    <p>
      <strong>
        <?php 
    _e("ComicPress Manager also manages yours and your Website's sanity.", 'comicpress-manager');
    ?>
      </strong>

      <?php 
    printf(__("It can check for misconfigured ComicPress setups, for incorrectly-named files (remember, it's <em>%s-single-comic-title.ext</em>) and for when you might be duplicating a post. You will also be shown which comic will appear with which blog post in the Post editor.", 'comicpress-manager'), $example_date);
    ?>
    </p>

    <p>
      <?php 
    printf(__("<strong>Single comic titles</strong> are generated from the incoming filename.  If you've named your file <strong>%s-my-new-years-day.jpg</strong> and create a new post for the file, the post title will be <strong>My New Years Day</strong>.  This default should handle the majority of cases.  If a comic file does not have a title, the date in <strong>MM/DD/YYYY</strong> format will be used.", 'comicpress-manager'), $example_real_date);
    ?>
    </p>

    <p>
      <?php 
    _e("<strong>Upload image files</strong> lets you upload multiple comics at a time, and add a default post body for each comic.", 'comicpress-manager');
    ?>
      <?php 
    if ($zip_extension_loaded) {
        ?>
        <?php 
        _e("You can <strong>upload a Zip file and create new posts</strong> from the files contained within the Zip file.", 'comicpress-manager');
        ?>
      <?php 
    } else {
        ?>
        <?php 
        _e("<strong>You can't upload a Zip file</strong> because you do not have the PHP <strong>zip</strong> extension installed.", 'comicpress-manager');
        ?>
      <?php 
    }
    ?>
    </p>

    <p>
      <?php 
    _e("Has ComicPress Manager saved you time and sanity?  <strong>Donate a few bucks to show your appreciation!</strong>", 'comicpress-manager');
    ?>
      <span style="display: block; text-align: center">
        <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHdwYJKoZIhvcNAQcEoIIHaDCCB2QCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYBt5XgClPZfdf9s2CHnk4Ka5NQv+Aoswm3efVANJKvHR3h4msnSWwDzlJuve/JD5aE0rP4SRLnWuc4qIhOeeAP+MEGbs8WNDEPtUopmSy6aphnIVduSstqRWWSYElK5Wij/H8aJtiLML3rVBtiixgFBbj2HqD2JXuEgduepEvVMnDELMAkGBSsOAwIaBQAwgfQGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIlFUk3PoXtLKAgdAjA3AjtLZz9ZnJslgJPALzIwYw8tMbNWvyJXWksgZRdfMw29INEcgMrSYoWNHY4AKpWMrSxUcx3fUlrgvPBBa1P96NcgKfJ6U0KwygOLrolH0JAzX0cC0WU3FYSyuV3BZdWyHyb38/s9AtodBFy26fxGqvwnwgWefQE5p9k66lWA4COoc3hszyFy9ZiJ+3PFtH/j8+5SVvmRUk4EUWBMopccHzLvkpN2WALLAU4RGKGfH30K1H8+t8E/+uKH1jt8p/N6p60jR+n7+GTffo3NahoIIDhzCCA4MwggLsoAMCAQICAQAwDQYJKoZIhvcNAQEFBQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMB4XDTA0MDIxMzEwMTMxNVoXDTM1MDIxMzEwMTMxNVowgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBR07d/ETMS1ycjtkpkvjXZe9k+6CieLuLsPumsJ7QC1odNz3sJiCbs2wC0nLE0uLGaEtXynIgRqIddYCHx88pb5HTXv4SZeuv0Rqq4+axW9PLAAATU8w04qqjaSXgbGLP3NmohqM6bV9kZZwZLR/klDaQGo1u9uDb9lr4Yn+rBQIDAQABo4HuMIHrMB0GA1UdDgQWBBSWn3y7xm8XvVk/UtcKG+wQ1mSUazCBuwYDVR0jBIGzMIGwgBSWn3y7xm8XvVk/UtcKG+wQ1mSUa6GBlKSBkTCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCBXzpWmoBa5e9fo6ujionW1hUhPkOBakTr3YCDjbYfvJEiv/2P+IobhOGJr85+XHhN0v4gUkEDI8r2/rNk1m0GA8HKddvTjyGw/XqXa+LSTlDYkqI8OwR8GEYj4efEtcRpRYBxV8KxAW93YDWzFGvruKnnLbDAF6VR5w/cCMn5hzGCAZowggGWAgEBMIGUMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMDkwMTA2MDAyOTQwWjAjBgkqhkiG9w0BCQQxFgQUITTqZaXyM43N5f08PBPDuRmzzdEwDQYJKoZIhvcNAQEBBQAEgYAV0szDQPbcyW/O9pZ7jUghTRdgHbCX4RyjPzR35IrI8MrqmtK94ENuD6Xf8PxkAJ3QdDr9OvkzWOHFVrb6YrAdh+XxBsMf1lD17UbwN3XZFn5HqvoWNFxNr5j3qx0DBsCh5RlGex+HAvtIoJu21uGRjbOQQsYFdlAPHxokkVP/Xw==-----END PKCS7-----
        ">
        <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="">
        <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
        </form>
      </span>
    </p>
  <?php 
    $help_content = ob_get_clean();
    ob_start();
    ?>

  <h2 style="padding-right:0;">
    <?php 
    if ($zip_extension_loaded) {
        _e("Upload Image &amp; Zip Files", 'comicpress-manager');
    } else {
        _e("Upload Image Files", 'comicpress-manager');
    }
    ?>
  </h2>
  <h3>&mdash;
    <?php 
    if (cpm_option('cpm-obfuscate-filenames-on-upload') === "none") {
        ?>
      <?php 
        _e("any existing files with the same name will be overwritten", 'comicpress-manager');
        ?>
    <?php 
    } else {
        ?>
      <?php 
        _e("uploaded filenames will be obfuscated, therefore no old files will be overwritten after uploading", 'comicpress-manager');
        ?>
    <?php 
    }
    ?>
  </h3>

  <?php 
    $target_url = add_query_arg("upload", "1");
    ?>

  <form onsubmit="$('submit').disabled=true" action="<?php 
    echo $target_url;
    ?>
" method="post" enctype="multipart/form-data">
    <input type="hidden" name="action" value="multiple-upload-file" />
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php 
    echo cpm_short_size_string_to_bytes(ini_get('upload_max_filesize'));
    ?>
" />
    <div id="multiple-file-upload">
    </div>
    <div style="text-align: center">
      [<a href="#" onclick="add_file_upload(); return false"><?php 
    _e("Add file to upload", 'comicpress-manager');
    ?>
</a>]
    </div>

    <table class="form-table">
      <tr>
        <th scope="row"><?php 
    _e("Destination for uploaded files:", 'comicpress-manager');
    ?>
</th>
        <td>
          <select name="upload-destination" id="upload-destination">
            <option value="comic"><?php 
    _e("Comics folder", 'comicpress-manager');
    ?>
</option>
            <option value="archive_comic"><?php 
    _e("Archive folder", 'comicpress-manager');
    ?>
</option>
            <option value="rss_comic"><?php 
    _e("RSS feed folder", 'comicpress-manager');
    ?>
</option>
          </select>
        </td>
      </tr>
      <?php 
    if (count($cpm_config->comic_files) > 0) {
        ?>
        <tr id="overwrite-existing-holder">
          <th scope="row"><?php 
        _e("Overwrite an existing file:", 'comicpress-manager');
        ?>
</th>
          <td>
            <select name="overwrite-existing-file-choice" id="overwrite-existing-file-choice">
              <option value=""><?php 
        _e("-- no --", 'comicpress-manager');
        ?>
</option>
              <?php 
        foreach ($cpm_config->comic_files as $file) {
            $basename = pathinfo($file, PATHINFO_BASENAME);
            ?>
                <option value="<?php 
            echo $basename;
            ?>
"
                <?php 
            echo $_GET['replace'] == $basename ? "selected" : "";
            ?>
><?php 
            echo $basename;
            ?>
</option>
              <?php 
        }
        ?>
            </select>
          </td>
        </tr>
        <tr id="rebuild-thumbnails">
          <th scope="row"><?php 
        _e("Rebuild thumbnails?", 'comicpress-manager');
        ?>
</th>
          <td>
            <label>
              <input type="checkbox" id="replace-comic-rebuild-thumbnails" name="replace-comic-rebuild-thumbnails" value="yes" checked />
              <em>(if replacing a comic in the <strong>comic</strong> folder, you can also regenerate thumbnails)</em>
            </label>
          </td>
        </tr>
      <?php 
    }
    ?>
      <tr>
        <td align="center" colspan="2">
          <input class="button" id="submit" type="submit" value="<?php 
    if (extension_loaded("zip")) {
        _e("Upload Image &amp; Zip Files", 'comicpress-manager');
    } else {
        _e("Upload Image Files", 'comicpress-manager');
    }
    ?>
" />
        </td>
      </tr>
    </table>

    <div id="upload-destination-holder">
      <table class="form-table">
        <tr>
          <th scope="row"><?php 
    _e("Generate new posts for each uploaded file:", 'comicpress-manager');
    ?>
</th>
          <td>
            <input id="multiple-new-post-checkbox" type="checkbox" name="new_post" value="yes" checked />
            <label for="multiple-new-post-checkbox"><em>(if you only want to upload a series of files to replace others, leave this unchecked)</em></label>
          </td>
        </tr>
      </table>

      <div id="multiple-new-post-holder">
        <table class="form-table" id="specify-date-holder">
          <tr>
            <th scope="row"><?php 
    _e("Date for uploaded file:", 'comicpress-manager');
    ?>
</th>
            <td>
              <div class="curtime"><input type="text" id="override-date" name="override-date" /> <?php 
    _e("<em>(click to open calendar. for single file uploads only. can accept any date format parseable by <a href=\"http://us.php.net/strtotime\" target=\"php\">strtotime()</a>)</em>", 'comicpress-manager');
    ?>
</div>
            </td>
          </tr>
        </table>

        <?php 
    cpm_post_editor(420);
    ?>

        <table class="form-table">
          <tr>
            <td align="center">
              <input class="button" id="top-submit" type="submit" value="<?php 
    if (extension_loaded("zip")) {
        _e("Upload Image &amp; Zip Files", 'comicpress-manager');
    } else {
        _e("Upload Image Files", 'comicpress-manager');
    }
    ?>
" />
            </td>
          </tr>
        </table>
      </div>
    </div>
  </form>
  <script type="text/javascript">
    Calendar.setup({
      inputField: "override-date",
      ifFormat: "%Y-%m-%d",
      button: "override-date"
    });
  </script>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content($help_content, $activity_content);
}
/**
 * The config editor dialog.
 */
function cpm_manager_cpm_config()
{
    global $cpm_config, $wpmu_version;
    include realpath(dirname(__FILE__)) . '/../cpm_configuration_options.php';
    $is_table = false;
    ob_start();
    ?>

  <h2 style="padding-right:0;"><?php 
    _e("Edit ComicPress Manager Config", 'comicpress-manager');
    ?>
</h2>

  <form action="" method="post" id="config-editor">
    <input type="hidden" name="action" value="update-cpm-config" />
      <?php 
    foreach ($configuration_options as $option) {
        $ok = true;
        if ($wpmu_version) {
            $ok = !isset($option['strip-wpmu']);
        }
        if ($option['type'] == "categories") {
            $ok = count($category_checkboxes = cpm_generate_additional_categories_checkboxes($option['id'], explode(",", $result))) > 0;
        }
        if ($ok) {
            ?>
          <?php 
            if (is_string($option)) {
                ?>
            <?php 
                if ($is_table) {
                    ?>
              </table></div>
              <?php 
                    $is_table = false;
                }
                ?>
            <h3><?php 
                echo $option;
                ?>
</h3>
          <?php 
            } else {
                if (!$is_table) {
                    ?>
              <div style="overflow: hidden"><table class="form-table">
              <?php 
                    $is_table = true;
                }
                ?>
            <tr>
              <th scope="row"><?php 
                echo $option['name'];
                ?>
</th>
              <td>
                <?php 
                $result = cpm_option($option['id']);
                switch ($option['type']) {
                    case "checkbox":
                        $ok = true;
                        if (isset($option['imagemagick-only'])) {
                            $ok = $cpm_config->get_scale_method() == CPM_SCALE_IMAGEMAGICK;
                        }
                        if ($ok) {
                            ?>
                        <input type="checkbox" id="<?php 
                            echo $option['id'];
                            ?>
" name="<?php 
                            echo $option['id'];
                            ?>
" value="yes" <?php 
                            echo $result == 1 ? " checked" : "";
                            ?>
 />
                      <?php 
                        }
                        break;
                    case "text":
                        ?>
                      <input type="text" size="<?php 
                        echo isset($option['size']) ? $option['size'] : 10;
                        ?>
" name="<?php 
                        echo $option['id'];
                        ?>
" value="<?php 
                        echo $result;
                        ?>
" />
                      <?php 
                        break;
                    case "textarea":
                        ?>
                      <textarea name="<?php 
                        echo $option['id'];
                        ?>
" rows="4" cols="30"><?php 
                        echo $result;
                        ?>
</textarea>
                      <?php 
                        break;
                    case "dropdown":
                        $dropdown_parts = array();
                        foreach (explode("|", $option['options']) as $dropdown_option) {
                            $parts = explode(":", $dropdown_option);
                            $key = array_shift($parts);
                            $dropdown_parts[$key] = implode(":", $parts);
                        }
                        ?>
                      <select name="<?php 
                        echo $option['id'];
                        ?>
">
                        <?php 
                        foreach ($dropdown_parts as $key => $value) {
                            ?>
                          <option value="<?php 
                            echo $key;
                            ?>
" <?php 
                            echo $result == $key ? " selected" : "";
                            ?>
><?php 
                            echo $value;
                            ?>
</option>
                        <?php 
                        }
                        ?>
                      </select>
                      <?php 
                        break;
                    case "categories":
                        echo implode("\n", $category_checkboxes);
                        break;
                }
                ?>
                <em><label for="<?php 
                echo $option['id'];
                ?>
">(<?php 
                echo $option['message'];
                ?>
)<label></em>
              </td>
            </tr>
          <?php 
            }
            ?>
        <?php 
        }
        ?>
      <?php 
    }
    ?>
      <tr>
        <td colspan="2" align="center">
          <input class="button" type="submit" value="Change Configuration" />
        </td>
      </tr>
    </table></div>
  </form>

  <div id="first-run-holder">
    <p><strong>Re-run the &quot;First Run&quot; action? This will attempt to create the default comic folders on your site.</strong></p>

    <form action="<?php 
    echo $target_page;
    ?>
" method="post">
      <input type="hidden" name="action" value="do-first-run" />
      <input class="button" type="submit" value="Yes, try and make my comic directories" />
    </form>
  </div>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content(null, $activity_content);
}
/**
 * The generate thumbnails dialog.
 */
function cpm_manager_thumbnails()
{
    global $cpm_config;
    $help_content = __("<p><strong>Generate thumbnails</strong> lets you regenerate thumbnails for comic files.  This is useful if an import is not functioning because it is taking too long, or if you've changed your size or quality settings for thumbnails.</p>", 'comicpress-manager');
    ob_start();
    ?>
  
  <h2 style="padding-right:0;"><?php 
    _e("Generate Thumbnails", 'comicpress-manager');
    ?>
</h2>

  <?php 
    $ok_to_generate_thumbs = false;
    $is_generating = array();
    if ($cpm_config->get_scale_method() != CPM_SCALE_NONE) {
        foreach ($cpm_config->thumbs_folder_writable as $type => $value) {
            if ($value) {
                if ($cpm_config->separate_thumbs_folder_defined[$type] !== false) {
                    if (cpm_option("cpm-{$type}-generate-thumbnails") == 1) {
                        $ok_to_generate_thumbs = true;
                        $is_generating[] = sprintf(__('<strong>%1$s thumbnails</strong> that are <strong>%2$s</strong> pixels wide', 'comicpress-manager'), $type, $cpm_config->properties["{$type}_comic_width"]);
                    }
                }
            }
        }
    }
    if ($ok_to_generate_thumbs) {
        if (count($cpm_config->comic_files) > 0) {
            ?>
        <form onsubmit="$('submit').disabled=true" action="" method="post">
          <input type="hidden" name="action" value="generate-thumbnails" />

          <p><?php 
            printf(__("You'll be generating %s.", 'comicpress-manager'), implode(__(" and ", 'comicpress-manager'), $is_generating));
            ?>
</p>

          <?php 
            _e("Thumbnails to regenerate (<em>to select multiple comics, [Ctrl]-click on Windows &amp; Linux, [Command]-click on Mac OS X</em>):", 'comicpress-manager');
            ?>
          <br />
          <select style="height: auto; width: 445px" id="select-comics-dropdown" name="comics[]" size="<?php 
            echo min(count($cpm_config->comic_files), 30);
            ?>
" multiple>
            <?php 
            foreach ($cpm_config->comic_files as $file) {
                $filename = pathinfo($file, PATHINFO_BASENAME);
                $any_thumbs = false;
                foreach (array('rss', 'archive') as $type) {
                    $thumb_file = str_replace($cpm_config->properties['comic_folder'], $cpm_config->properties["{$type}_comic_folder"], $file);
                    if (file_exists($thumb_file)) {
                        $any_thumbs = true;
                        break;
                    }
                }
                ?>
<option value="<?php 
                echo $filename;
                ?>
"><?php 
                echo $filename . ($any_thumbs ? " (*)" : "");
                ?>
</option>
            <?php 
            }
            ?>
          </select>
          <div style="text-align: center">
            <input class="button" type="submit" id="submit" value="<?php 
            _e("Generate Thumbnails for Selected Comics", 'comicpress-manager');
            ?>
" />
          </div>
        </form>
      <?php 
        } else {
            ?>
        <p><?php 
            _e("You haven't uploaded any comics yet.", 'comicpress-manager');
            ?>
</p>
      <?php 
        }
    } else {
        ?>
      <p>
        <?php 
        _e("<strong>You either aren't able to generate any thumbnails for your comics, or you have disabled thumbnail generation.</strong> This may be caused by a configuration error. Have you set up your RSS and archive directories and <a href=\"?page=" . plugin_basename(realpath(dirname(__FILE__) . '/../comicpress_manager_admin.php')) . "-config\">configured your ComicPress theme to use them</a>? Do you have either the GD library or Imagemagick installed?", 'comicpress-manager');
        ?>
      </p>
    <?php 
    }
    ?>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content($help_content, $activity_content);
}
/**
 * The delete dialog.
 */
function cpm_manager_delete()
{
    global $cpm_config;
    $help_content = __("<p><strong>Delete a comic file and the associated post, if found</strong> lets you delete a comic file and the post that goes with it.  Any thumbnails associated with the comic file will also be deleted.</p>", 'comicpress-manager');
    ob_start();
    ?>
  
  <h2 style="padding-right:0;"><?php 
    _e("Delete A Comic File &amp; Post (if found)", 'comicpress-manager');
    ?>
</h2>

  <?php 
    if (count($cpm_config->comic_files) > 0) {
        ?>
    <form onsubmit="$('submit').disabled=true" action="" method="post" onsubmit="return confirm('<?php 
        _e("Are you sure?", 'comicpress-manager');
        ?>
')">
      <input type="hidden" name="action" value="delete-comic-and-post" />

      <?php 
        _e("Comic to delete:", 'comicpress-manager');
        ?>
<br />
        <select style="width: 445px" id="delete-comic-dropdown" name="comic" align="absmiddle" onchange="change_image_preview()">
          <?php 
        foreach ($cpm_config->comic_files as $file) {
            ?>
            <option value="<?php 
            echo cpm_build_comic_uri($file, CPM_DOCUMENT_ROOT);
            ?>
"><?php 
            echo pathinfo($file, PATHINFO_BASENAME);
            ?>
</option>
          <?php 
        }
        ?>
        </select><br />
      <div id="image-preview" style="text-align: center"></div>
      <p>
        <?php 
        _e("<strong>NOTE:</strong> If more than one possible post is found, neither the posts nor the comic file will be deleted.  ComicPress Manager cannot safely resolve such a conflict.", 'comicpress-manager');
        ?>
      </p>
      <div style="text-align: center">
        <input class="button" type="submit" id="submit" value="<?php 
        _e("Delete comic and post", 'comicpress-manager');
        ?>
" />
      </div>
    </form>
  <?php 
    } else {
        ?>
    <p><?php 
        _e("You haven't uploaded any comics yet.", 'comicpress-manager');
        ?>
</p>
  <?php 
    }
    ?>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content($help_content, $activity_content);
}
/**
 * The import dialog.
 */
function cpm_manager_import()
{
    global $comicpress_manager;
    if ($comicpress_manager->get_subcomic_directory() !== false) {
        $comicpress_manager->messages[] = sprintf(__("<strong>Reminder:</strong> You are managing the <strong>%s</strong> comic subdirectory.", 'comicpress-manager'), get_cat_name(get_option('comicpress-manager-manage-subcomic')));
    }
    if ($comicpress_manager->get_cpm_option('cpm-skip-checks') != 1) {
        if (!function_exists('get_comic_path')) {
            $comicpress_manager->warnings[] = __('<strong>It looks like you\'re running an older version of ComicPress.</strong> Storyline, hovertext, and transcript are fully supported in <a href="http://comicpress.org/">ComicPress 2.7</a>. You can use hovertext and transcripts in earlier themes by using <tt>get_post_meta($post->ID, "hovertext", true)</tt> and <tt>get_post_meta($post->ID, "transcript", true)</tt>.', 'comicpress-manager');
        }
    }
    ob_start();
    ?>
    <p>
      <?php 
    _e("<strong>Create missing posts for uploaded comics</strong> is for when you upload a lot of comics to your comic folder and want to generate generic posts for all of the new comics, or for when you're migrating from another system to ComicPress.", 'comicpress-manager');
    ?>
    </p>

    <p>
      <?php 
    $link_text = __("Bulk Edit page", 'comicpress-manager');
    $link = "<a href=\"?page=" . plugin_basename(realpath(dirname(__FILE__) . '/../comicpress_manager_admin.php')) . "-status\">{$link_text}</a>";
    printf(__("<strong>Generating thumbnails on an import is a slow process.</strong>  Some Webhosts will limit the amount of time a script can run.  If your import process is failing with thumbnail generation enabled, disable thumbnail generation, perform your import, and then visit the %s to complete the thumbnail generation process.", 'comicpress-manager'), $link);
    ?>
    </p>
  <?php 
    $help_content = ob_get_clean();
    ob_start();
    ?>
  
  <h2 style="padding-right:0;"><?php 
    _e("Create Missing Posts For Uploaded Comics", 'comicpress-manager');
    ?>
</h2>
  <h3>&mdash; <?php 
    _e("acts as a batch import process", 'comicpress-manager');
    ?>
</h3>

  <div id="import-count-information">
    <?php 
    if ($comicpress_manager->import_safe_exit === true) {
        _e("<strong>You are in the middle of an import operation.</strong> To continue, click the button below:", 'comicpress-manager');
        ?>
          <form action="" method="post">
            <?php 
        foreach ($_POST as $key => $value) {
            if (is_array($value)) {
                foreach ($value as $subvalue) {
                    ?>
                  <input type="hidden" name="<?php 
                    echo $key;
                    ?>
[]" value="<?php 
                    echo $subvalue;
                    ?>
" />
                <?php 
                }
            } else {
                ?>
                <input type="hidden" name="<?php 
                echo $key;
                ?>
" value="<?php 
                echo $value;
                ?>
" />
              <?php 
            }
        }
        ?>
            <input type="submit" class="button" value="Continue Creating Posts" />
          </form>
        <?php 
    } else {
        $execution_time = ini_get("max_execution_time");
        $max_posts_imported = (int) ($execution_time / 2);
        if ($execution_time == 0) {
            _e("<strong>Congratulations, your <tt>max_execution_time</tt> is 0</strong>. You'll be able to import all of your comics in one import operation.", 'comicpress-manager');
        } else {
            if ($max_posts_imported == 0) {
                _e("<strong>Something is very wrong with your configuration!.</strong>", 'comicpress-manager');
            } else {
                printf(__("<strong>Your <tt>max_execution_time</tt> is %s</strong>. You'll be able to safely import %s comics in one import operation.", 'comicpress-manager'), $execution_time, $max_posts_imported);
            }
        }
    }
    ?>
  </div>

  <table class="form-table">
    <tr>
      <th scope="row">
        <?php 
    _e("Count the number of missing posts", 'comicpress-manager');
    ?>
      </th>
      <td>
        <a href="#" onclick="return false" id="count-missing-posts-clicker"><?php 
    _e("Click here to count", 'comicpress-manager');
    ?>
</a> (<?php 
    _e("may take a while", 'comicpress-manager');
    ?>
): <span id="missing-posts-display"></span>
      </td>
    </tr>
  </table>

  <div id="create-missing-posts-holder">
    <form onsubmit="$('submit').disabled=true" action="" method="post" style="margin-top: 10px">
      <input type="hidden" name="action" value="create-missing-posts" />

      <?php 
    cpm_post_editor(435, true);
    ?>

      <table class="form-table">
        <tr>
          <td align="center">
            <input class="button" type="submit" id="submit" value="<?php 
    _e("Create posts", 'comicpress-manager');
    ?>
" />
          </td>
        </tr>
      </table>
    </form>
  </div>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content($help_content, $activity_content);
}
/**
 * The change dates dialog.
 */
function cpm_manager_dates()
{
    global $cpm_config;
    $cpm_config->need_calendars = true;
    if (cpm_get_subcomic_directory() !== false) {
        $cpm_config->messages[] = __("<strong>Subdirectory support enabled.</strong> Change Dates may not work as expected.", 'comicpress-manager');
    }
    $comic_format_date_string = date(CPM_DATE_FORMAT);
    $dates_output_format = "Y-m-d";
    $start_date = date($dates_output_format);
    $end_date = substr(pathinfo(end($cpm_config->comic_files), PATHINFO_BASENAME), 0, strlen($comic_format_date_string));
    $end_date = date($dates_output_format, strtotime($end_date));
    if (isset($_POST['start-date']) && !empty($_POST['start-date'])) {
        $target_start_date = strtotime($_POST['start-date']);
        if ($target_start_date != -1 && $target_start_date !== false) {
            $start_date = date($dates_output_format, $target_start_date);
        } else {
            $cpm_config->warnings[] = $_POST['start-date'] . " is an invalid date.  Resetting to {$start_date}";
        }
        $target_end_date = strtotime($_POST['end-date']);
        if ($target_end_date != -1 && $target_end_date !== false) {
            $end_date = date($dates_output_format, $target_end_date);
        } else {
            $cpm_config->warnings[] = $_POST['end-date'] . " is an invalid date.  Resetting to {$end_date}";
        }
    }
    if (strtotime($end_date) < strtotime($start_date)) {
        list($start_date, $end_date) = array($end_date, $start_date);
    }
    $visible_comic_files = array();
    $visible_comic_files_md5 = array();
    $start_date_timestamp = strtotime($start_date);
    $end_date_timestamp = strtotime($end_date);
    foreach ($cpm_config->comic_files as $file) {
        $filename = pathinfo($file, PATHINFO_BASENAME);
        $result = cpm_breakdown_comic_filename($filename);
        $result_date_timestamp = strtotime($result['date']);
        if ($result_date_timestamp >= $start_date_timestamp && $result_date_timestamp <= $end_date_timestamp) {
            $visible_comic_files[] = $file;
            $visible_comic_files_md5[] = "\"" . md5($file) . "\"";
        }
    }
    $help_content = __("<p><strong>Change post &amp; comic dates</strong> lets you change the comic file names and post dates for any and every comic published. You will only be able to move a comic file and its associated post if there is no comic or post that exists on the destination date, as ComicPress Manager cannot automatically resolve such conflicts.</p>", 'comicpress-manager');
    $help_content .= __("<p><strong>This is a potentialy dangerous and resource-intensive operation.</strong> Back up your database and comics/archive/RSS folders before performing large move operations.  Additionally, if you experience script timeouts while moving large numbers of posts, you may have to move posts & comic files by hand rather than through ComicPress Manager.</p>", 'comicpress-manager');
    ob_start();
    ?>
  
  <h2 style="padding-right:0;"><?php 
    _e("Change Post &amp; Comic Dates", 'comicpress-manager');
    ?>
</h2>
  <h3>&mdash; <?php 
    _e("date changes will affect comics that are associated or not associated with posts", 'comicpress-manager');
    ?>
</h3>

  <?php 
    if (count($cpm_config->comic_files) > 0) {
        ?>
    <form action="" method="post">
      <?php 
        printf(__('Show comics between %1$s and %2$s', 'comicpress-manager'), "<input type=\"text\" id=\"start-date\" name=\"start-date\" size=\"12\" value=\"{$start_date}\" />", "<input type=\"text\" id=\"end-date\" name=\"end-date\" size=\"12\" value=\"{$end_date}\" />");
        ?>

      <input type="submit" value="<?php 
        _e("Filter", 'comicpress-manager');
        ?>
" />
    </form>

    <script type="text/javascript">
      var comic_files_keys = [ <?php 
        echo implode(", ", $visible_comic_files_md5);
        ?>
 ];

      var days_between_posts_message = "<?php 
        _e("How many days between posts?  Separate multiple intervals with commas (Ex: MWF is 2,2,3):", 'comicpress-manager');
        ?>
";
      var valid_interval_message = "<?php 
        _e("is a valid interval", 'comicpress-manager');
        ?>
";
    </script>
    <?php 
        cpm_include_javascript("comicpress_dates.js");
        ?>

    <form onsubmit="$('submit').disabled=true" action="" method="post">
      <input type="hidden" name="action" value="change-dates" />
      <input type="hidden" name="start-date" value="<?php 
        echo $start_date;
        ?>
" />
      <input type="hidden" name="end-date" value="<?php 
        echo $end_date;
        ?>
" />

      <?php 
        $field_to_setup = array();
        foreach ($visible_comic_files as $file) {
            $filename = pathinfo($file, PATHINFO_BASENAME);
            $result = cpm_breakdown_comic_filename($filename);
            $key = md5($file);
            $fields_to_setup[] = "'dates[{$key}]'";
            ?>
        <div id="holder-<?php 
            echo $key;
            ?>
" style="border-bottom: solid #666 1px; padding-bottom: 3px; margin-bottom: 3px">
          <table cellspacing="0">
            <tr>
              <td width="300" class="form-title"><?php 
            echo $filename;
            ?>
</td>
              <td><input size="12" onchange="$('holder-<?php 
            echo $key;
            ?>
').style.backgroundColor=(this.value != '<?php 
            echo $result['date'];
            ?>
' ? '#ddd' : '')" type="text" name="dates[<?php 
            echo $key;
            ?>
]" id="dates[<?php 
            echo $key;
            ?>
]" value="<?php 
            echo $result['date'];
            ?>
" />
              [<a title="<?php 
            printf(__("Reset date to %s", 'comicpress-manager'), $result['date']);
            ?>
" href="#" onclick="$('holder-<?php 
            echo $key;
            ?>
').style.backgroundColor=''; $('dates[<?php 
            echo $key;
            ?>
]').value = '<?php 
            echo $result['date'];
            ?>
'; return false">R</a> | <a title="<?php 
            _e("Re-schedule posts from this date at a daily interval", 'comicpress-manager');
            ?>
" href="#" onclick="reschedule_posts('<?php 
            echo $key;
            ?>
'); return false">I</a>]</td>
            </tr>
          </table>
        </div>
      <?php 
        }
        ?>
      <script type="text/javascript">
        var fields_to_setup = [ 'start-date', 'end-date', <?php 
        echo implode(", ", $fields_to_setup);
        ?>
 ];

        for (var i = 0, len = fields_to_setup.length; i < len; ++i) {
          var format = (i < 2) ? "%Y-%m-%d" : "<?php 
        echo preg_replace('/([a-zA-Z])/', '%\\1', CPM_DATE_FORMAT);
        ?>
";
          Calendar.setup({
            inputField: fields_to_setup[i],
            ifFormat: format,
            button: fields_to_setup[i]
          });
        }
      </script>
      <div style="text-align: center">
        <input class="button" type="submit" id="submit" value="<?php 
        _e("Change Dates", 'comicpress-manager');
        ?>
" />
      </div>
    </form>
  <?php 
    } else {
        ?>
    <p><?php 
        _e("You haven't uploaded any comics yet.", 'comicpress-manager');
        ?>
</p>
  <?php 
    }
    ?>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content($help_content, $activity_content);
}
/**
 * The generate status dialog.
 */
function cpm_manager_status()
{
    global $cpm_config;
    $cpm_config->need_calendars = true;
    if (cpm_get_subcomic_directory() !== false) {
        $cpm_config->messages[] = sprintf(__("<strong>Reminder:</strong> You are managing the <strong>%s</strong> comic subdirectory.", 'comicpress-manager'), get_cat_name(get_option('comicpress-manager-manage-subcomic')));
    }
    if (cpm_option('cpm-skip-checks') != 1) {
        if (!function_exists('get_comic_path')) {
            $cpm_config->warnings[] = __('<strong>It looks like you\'re running an older version of ComicPress.</strong> Storyline, hovertext, and transcript are fully supported in <a href="http://comicpress.org/">ComicPress 2.7</a>. You can use hovertext and transcripts in earlier themes by using <tt>get_post_meta($post->ID, "hovertext", true)</tt> and <tt>get_post_meta($post->ID, "transcript", true)</tt>.', 'comicpress-manager');
        }
    }
    ob_start();
    ?>
  
  <h2 style="padding-right:0;"><?php 
    _e("Bulk Edit", 'comicpress-manager');
    ?>
</h2>
  <p><strong>ComicPress-related information, such as transcripts and Storyline categories for posts, and thumbnail regeneration, can be bulk edited here.</strong> To edit post-specific information, such as title and publishing date, use <strong><a href="edit.php">Edit Posts</a></strong>.

  <?php 
    $data_by_date = array();
    $dates_per_page = 15;
    foreach ($cpm_config->comic_files as $comic_filepath) {
        $comic_file = pathinfo($comic_filepath, PATHINFO_BASENAME);
        if (($result = cpm_breakdown_comic_filename($comic_file)) !== false) {
            $timestamp = strtotime($result['date']);
            $comic_date = date("Y-m-d", $timestamp);
            if (!isset($data_by_date[$comic_date])) {
                $data_by_date[$comic_date] = array();
            }
            $comic_info = array('type' => 'comic', 'timestamp' => $timestamp, 'comic_file' => $comic_file, 'file_title' => $result['converted_title'], 'comic_uri' => cpm_build_comic_uri($comic_filepath, CPM_DOCUMENT_ROOT));
            if (count($thumbnails_found = cpm_find_thumbnails_by_filename($comic_filepath)) > 0) {
                foreach ($thumbnails_found as $thumb_type => $thumb_filename) {
                    $comic_info["thumbnails_found_{$thumb_type}"] = cpm_build_comic_uri(CPM_DOCUMENT_ROOT . $thumb_filename, CPM_DOCUMENT_ROOT);
                }
            }
            $icon_file_to_use = $comic_filepath;
            foreach (array('rss', 'archive', 'mini') as $type) {
                if (isset($thumbnails_found[$type])) {
                    $icon_file_to_use = CPM_DOCUMENT_ROOT . $thumbnails_found[$type];
                }
            }
            $comic_info['icon_uri'] = cpm_build_comic_uri($icon_file_to_use, CPM_DOCUMENT_ROOT);
            $data_by_date[$comic_date][] = $comic_info;
        }
    }
    foreach (cpm_query_posts() as $comic_post) {
        $ok = true;
        if (cpm_get_subcomic_directory() !== false) {
            $ok = in_array(get_option('comicpress-manager-manage-subcomic'), wp_get_post_categories($comic_post->ID));
        }
        if ($ok) {
            $timestamp = strtotime($comic_post->post_date);
            $post_date = date("Y-m-d", $timestamp);
            if (!isset($data_by_date[$post_date])) {
                $data_by_date[$post_date] = array();
            }
            $post_info = array('type' => 'post', 'timestamp' => $timestamp, 'post_id' => $comic_post->ID, 'post_title' => $comic_post->post_title, 'post_object' => (array) $comic_post);
            $data_by_date[$post_date][] = $post_info;
        }
    }
    krsort($data_by_date);
    $all_months = array();
    foreach (array_keys($data_by_date) as $date) {
        list($year, $month, $day) = explode("-", $date);
        $key = "{$year}-{$month}";
        if (!isset($all_months[$key])) {
            $all_months[$key] = date("F Y", strtotime($date));
        }
    }
    krsort($all_months);
    if (isset($_POST['dates'])) {
        if ($_POST['dates'] != -1) {
            $new_data_by_date = array();
            foreach ($data_by_date as $date => $data) {
                if (strpos($date, $_POST['dates']) === 0) {
                    $new_data_by_date[$date] = $data;
                }
            }
            $data_by_date = $new_data_by_date;
        }
    }
    if (!isset($_GET['paged'])) {
        $_GET['paged'] = 1;
    }
    $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('&laquo;'), 'next_text' => __('&raquo;'), 'total' => ceil(count($data_by_date) / $dates_per_page), 'current' => $_GET['paged']));
    $total_data_by_date = count($data_by_date);
    $data_by_date = array_slice($data_by_date, ($_GET['paged'] - 1) * $dates_per_page, $dates_per_page);
    extract(cpm_normalize_storyline_structure());
    $comic_categories = array();
    foreach ($category_tree as $node) {
        $comic_categories[] = end(explode("/", $node));
    }
    $thumbnail_writes = cpm_get_thumbnails_to_generate();
    if ($total_data_by_date > 0) {
        $displaying_num_content = sprintf(__("Displaying %d-%d of %d", 'comicpress-manager'), ($_GET['paged'] - 1) * $dates_per_page + 1, min($total_data_by_date, ($_GET['paged'] - 1) * $dates_per_page + $dates_per_page), $total_data_by_date);
    } else {
        $displaying_num_content = __('No items to display', 'comicpress-manager');
    }
    ?>

  <style type="text/css">
    .storyline-checklist {
      overflow-y: scroll;
      border: solid #ddd 1px;
      height: 12em
    }

    #wpbody-content .bulk-edit-row-post .inline-edit-col-right {
      width: 42%
    }
  </style>
  <div id="table-holder">
    <form id="bulk-form" action="" method="post">
      <input type="hidden" name="action" value="batch-processing" />
      <div class="tablenav">
        <div class="alignleft actions">
          <select id="bulk-action" name="bulk-action">
            <option selected value="-1">Bulk Actions</option>
            <option value="individual">Submit Individual Changes</option>
            <option value="edit">Edit Selected</option>
            <option value="delete">Delete Selected</option>
            <option value="import">Create Posts for Selected Files</option>
            <option value="regen-thumbs">Regenerate Thumbs</option>
          </select>
          <input id="doaction" class="button-secondary action" type="submit" value="Apply" />
          <select id="dates" name="dates">
            <option selected value="-1">Show all dates</option>
            <?php 
    foreach ($all_months as $key => $date) {
        ?>
              <option value="<?php 
        echo $key;
        ?>
"<?php 
        echo $key == $_POST['dates'] ? " selected" : "";
        ?>
><?php 
        echo $date;
        ?>
</option>
            <?php 
    }
    ?>
          </select>
          <input id="dofilter" class="button-secondary action" type="submit" value="Filter" />
        </div>
        <div class="tablenav-pages">
          <span class="displaying-num"><?php 
    echo $displaying_num_content;
    ?>
</span>
          <?php 
    echo $page_links;
    ?>
        </div>
      </div>
      <table class="widefat fixed" id="status-table">
        <thead>
          <tr>
            <th class="check-column" width="3%">
              <input type="checkbox" name="toggle-all" class="batch-all" value="yes" />
            </th>
            <th width="12%"><?php 
    _e("Date", 'comicpress-manager');
    ?>
</th>
            <th width="34%"><?php 
    _e("Object Info", 'comicpress-manager');
    ?>
</th>
            <th width="61%"><?php 
    _e("Operations", 'comicpress-manager');
    ?>
</th>
          </tr>
        </thead>
        <tfoot>
          <tr>
            <th class="check-column">
              <input type="checkbox" name="toggle-all" class="batch-all" value="yes" />
            </th>
            <th><?php 
    _e("Date", 'comicpress-manager');
    ?>
</th>
            <th><?php 
    _e("Object Info", 'comicpress-manager');
    ?>
</th>
            <th><?php 
    _e("Operations", 'comicpress-manager');
    ?>
</th>
          </tr>
        </tfoot>
        <tbody>
          <tr style="display: none" id="bulk-edit" class="inline-edit-row inline-edit-row-post bulk-edit-row bulk-edit-row-post inline-editor">
            <td colspan="4">
              <fieldset class="inline-edit-col-left">
                <div class="inline-edit-col">
                  <h4>Bulk Edit Comic Posts</h4>
                  <div id="bulk-title-div">
                    <div id="bulk-titles" />
                  </div>
                </div>
              </fieldset>
              <fieldset class="inline-edit-col-center inline-edit-categories">
                <div class="inline-edit-col">
                  <span class="title inline-edit-categories-label">
                    Storyline
                  </span>
                  <div class="storyline-checklist">
                    <?php 
    cpm_display_storyline_checkboxes($category_tree, array(), "bulk-storyline");
    ?>
                  </div>
                </div>
              </fieldset>
              <fieldset class="inline-edit-col-right">
                <label>
                  <span class="title" style="width: auto; margin-right: 5px">&lt;img title&gt;/hovertext</span>
                  <input type="text" name="bulk-hovertext" style="width: 100%" />
                </label>
                <label>
                  <span class="title" style="width: auto; margin-right: 5px">Transcript</span>
                  <textarea name="bulk-transcript" style="height: 7em"></textarea>
                </label>
              </fieldset>
              <p class="submit inline-edit-save">
                <a id="cancel" class="button-secondary cancel alignleft" title="Cancel" href="#">Cancel</a>
                <input class="button-primary alignright" id="bulk-edit-submit" type="submit" value="Update Comic Posts" name="bulk-comic-edit" />
                <br class="clear" />
              </p>
            </td>
          </tr>
          <?php 
    $is_grey = false;
    $image_index = 0;
    foreach ($data_by_date as $date => $data) {
        $all_objects_by_type = array();
        foreach ($data as $object) {
            if (!isset($all_objects_by_type[$object['type']])) {
                $all_objects_by_type[$object['type']] = array();
            }
            $all_objects_by_type[$object['type']][] = $object;
        }
        $classes = array("data-row");
        if ($is_grey) {
            $classes[] = "grey";
        }
        $is_first_row = true;
        foreach ($data as $object) {
            ?>
              <tr class="<?php 
            echo implode(" ", $classes);
            ?>
">
                <?php 
            if ($is_first_row) {
                ?>
                  <td align="center" rowspan="<?php 
                echo count($data);
                ?>
">
                    <input id="batch-<?php 
                echo $date;
                ?>
" type="checkbox" class="batch" name="batch-<?php 
                echo $date;
                ?>
" value="yes" />
                  </td>
                  <td rowspan="<?php 
                echo count($data);
                ?>
"><?php 
                echo $date;
                ?>
</td>
                  <?php 
                $is_first_row = false;
            }
            ?>
                <td class="<?php 
            echo $object['type'];
            ?>
">
                  <?php 
            switch ($object['type']) {
                case "comic":
                    ?>
                        <div style="overflow: hidden">
                          <div><strong>
                            Comic: <?php 
                    echo empty($object['file_title']) ? $object['comic_file'] : $object['file_title'];
                    ?>
                          </strong></div>

                          <a href="<?php 
                    echo $object['comic_uri'];
                    ?>
"><img style="float: right; display: inline; margin-right: 5px; max-height: 100px" id="comic-icon-<?php 
                    echo $image_index;
                    ?>
" src="<?php 
                    echo $object['icon_uri'];
                    ?>
" /></a>

                        <?php 
                    $all_found = array();
                    foreach (array('rss', 'archive', 'mini') as $type) {
                        if (isset($object["thumbnails_found_{$type}"])) {
                            $all_found[$type] = $object["thumbnails_found_{$type}"];
                        }
                    }
                    if (count($all_found) > 0) {
                        ?>
                            [
                              <?php 
                        foreach ($all_found as $type => $uri) {
                            ?>
                                <a href="<?php 
                            echo $uri;
                            ?>
"><?php 
                            echo $type;
                            ?>
</a>
                              <?php 
                        }
                        ?>
                            ]
                          <?php 
                    } else {
                        ?>
                            [ No thumbnails found ]
                          <?php 
                    }
                    $image_index++;
                    ?>
                        </div>
                        <?php 
                    break;
                case "post":
                    if (isset($object['post_id'])) {
                        ?>
                          <strong>Post: <?php 
                        echo $object['post_title'];
                        ?>
</strong>
                          <em>(<?php 
                        echo $object['post_id'];
                        ?>
)</em><br />
                          [ <?php 
                        echo generate_view_edit_post_links($object['post_object']);
                        ?>
 ]
                        <?php 
                    }
                    break;
            }
            ?>
                </td>
                <td class="individual-operations <?php 
            echo $object['type'];
            ?>
">
                  <?php 
            switch ($object['type']) {
                case "comic":
                    ?>
                        <input type="hidden" name="file,<?php 
                    echo $date;
                    ?>
,<?php 
                    echo $object['comic_file'];
                    ?>
" value="yes" />

                        <?php 
                    if (count($all_objects_by_type['post']) == 0) {
                        ?>
                          <label><input type="checkbox" name="generate-post-<?php 
                        echo $object['comic_file'];
                        ?>
" value="yes" /> Generate a Post <em>(as a draft)</em></label><br />
                        <?php 
                    }
                    ?>

                        <?php 
                    if (count($thumbnail_writes) > 0) {
                        ?>
                          <label><input type="checkbox" name="regen-<?php 
                        echo $object['comic_file'];
                        ?>
" value="yes" /> Regenerate Thumbs</label><br />
                        <?php 
                    }
                    ?>

                        <label><input type="checkbox" class="delete-file" name="delete-file-<?php 
                    echo $object['comic_file'];
                    ?>
" value="yes" /> Delete Comic</label><br />
                        <!-- <input type="checkbox" id="do-redate-file-<?php 
                    echo $object['comic_file'];
                    ?>
" name="do-redate-file-<?php 
                    echo $object['comic_file'];
                    ?>
" /> Move to: <input class="needs-calendar" id="redate-file-<?php 
                    echo $object['comic_file'];
                    ?>
" type="text" name="redate-file-<?php 
                    echo $object['comic_file'];
                    ?>
" value="<?php 
                    echo $date;
                    ?>
" /> -->

                        <?php 
                    break;
                case "post":
                    $post_categories = array_intersect(wp_get_post_categories($object['post_id']), $comic_categories);
                    $post_category_names = array();
                    foreach ($post_categories as $category_id) {
                        $post_category_names[] = get_cat_name($category_id);
                    }
                    ?>
                        <input type="hidden" name="post,<?php 
                    echo $date;
                    ?>
,<?php 
                    echo $object['post_id'];
                    ?>
" value="yes" />
                        <label><input type="checkbox" class="delete-post" name="delete-post-<?php 
                    echo $object['post_id'];
                    ?>
" value="yes" /> Delete Post</label><br />
                        <!-- <input type="checkbox" id="do-redate-post-<?php 
                    echo $object['post_id'];
                    ?>
" name="do-redate-post-<?php 
                    echo $object['post_id'];
                    ?>
" /> Move to: <input type="text" class="needs-calendar" id="redate-post-<?php 
                    echo $object['post_id'];
                    ?>
" name="redate-post-<?php 
                    echo $object['post_if'];
                    ?>
" value="<?php 
                    echo $date;
                    ?>
" /><br /> -->

                        <?php 
                    $hovertext = get_post_meta($object['post_id'], 'hovertext', true);
                    if (!empty($hovertext)) {
                        ?>
                          <strong>&lt;img title&gt;/hovertext:</strong> <?php 
                        echo $hovertext;
                        ?>
<br />
                        <?php 
                    }
                    ?>

                         <?php 
                    $transcript = get_post_meta($object['post_id'], 'transcript', true);
                    if (!empty($transcript)) {
                        ?>
                          <strong>Transcript:</strong>
                          <div class="transcript-holder"><?php 
                        echo $transcript;
                        ?>
</div>
                        <?php 
                    }
                    ?>

                        <strong>Storyline:</strong> <span class="category-names"><?php 
                    echo implode(", ", $post_category_names);
                    ?>
</span> [ <a href="#" id="category-<?php 
                    echo $object['post_id'];
                    ?>
" class="category">Edit</a> ]
                        <div id="category-holder-<?php 
                    echo $object['post_id'];
                    ?>
" style="display: none">
                          <?php 
                    cpm_display_storyline_checkboxes($category_tree, $post_categories, $object['post_id']);
                    ?>
                        </div>

                        <?php 
                    break;
            }
            ?>
                </td>
              </tr>
            <?php 
        }
        $is_grey = !$is_grey;
    }
    ?>
        </tbody>
      </table>
      <div class="tablenav">
        <div class="alignleft actions">
          <select id="linked-bulk-action" name="linked-bulk-action">
            <option selected value="-1">Bulk Actions</option>
            <option value="individual">Submit Individual Changes</option>
            <option value="edit">Edit Selected</option>
            <option value="delete">Delete Selected</option>
            <option value="import">Create Posts for Selected Files</option>
            <option value="regen-thumbs">Regenerate Thumbs</option>
          </select>
          <input id="linked-doaction" class="button-secondary action" type="submit" value="Apply" />
        </div>
        <div class="tablenav-pages">
          <span class="displaying-num"><?php 
    echo $displaying_num_content;
    ?>
</span>
          <?php 
    echo $page_links;
    ?>
        </div>
      </div>
    </form>
    <script type="text/javascript">
      Event.observe(window, 'load', function() {
        Event.observe($('linked-bulk-action'), 'change', function() {
          $('bulk-action').selectedIndex = $('linked-bulk-action').selectedIndex;
        });

        Event.observe($('bulk-action'), 'change', function() {
          $('linked-bulk-action').selectedIndex = $('bulk-action').selectedIndex;
        });

        $$('.needs-calendar').each(function(element) {
          Calendar.setup({
            inputField: element.id,
            ifFormat: "%Y-%m-%d",
            button: element.id
          });

          Event.observe(element, 'click', function(e) {
            var element = Event.element(e);
            $("do-" + element.id).checked = true;
          });
        });

        $$('a.category').each(function(element) {
          Event.observe(element, 'click', function(e) {
            Event.stop(e);
            Element.toggle("category-holder-" + Event.element(e).id.replace(/^.*\-([0-9]+)$/, '$1'));
          });
        });
      });

      $$('.batch-all').each(function(element) {
        Event.observe(element, 'change', function(e) {
          $$('.batch').each(function(b) { b.checked = element.checked; });
          $$('.batch-all').each (function(b) { b.checked = element.checked; });
        });
      });

      $$('.individual-operations input[type=checkbox]').each(function(element) {
        Event.observe(element, 'click', function(e) {
          $('bulk-action').selectedIndex = 1;
          $('linked-bulk-action').selectedIndex = 1;
        });
      });

      var ok_to_submit = false;

      Event.observe($('bulk-form'), 'submit', function(e) {
        return ok_to_submit;
      });

      Event.observe($('bulk-edit-submit'), 'click', function(e) {
        ok_to_submit = true;
        $('bulk-form').submit();
      });

      Event.observe($('cancel'), 'click', function(e) {
        Event.stop(e);
        $('bulk-edit').hide();
        $('bulk-action').selectedIndex = 0;
      });

      Event.observe($('dofilter'), 'click', function(e) {
        Event.stop(e);
        $('bulk-action').selectedIndex = 0;
        ok_to_submit = true;
        $('bulk-form').submit();
      });

      ['doaction', 'linked-doaction'].each(function(which) {
        Event.observe($(which), 'click', function(e) {
          Event.stop(e);

          switch ($F('bulk-action')) {
            case -1:
            case "-1":
              break;
            case "edit":
              $('bulk-titles').innerHTML = "";
              var any_checked = false;
              $$('.batch').each(function(element) {
                if (element.checked) {
                  any_checked = true;
                  /\-(.*)$/.test(element.id);
                  var date = RegExp.$1;

                  var node = Builder.node("div", [
                    Builder.node("a", { id: date, className: "ntdelbutton", title: "Remove From Bulk Edit" }, [ "X" ]),
                    date
                  ]);

                  $('bulk-titles').insert(node);

                  Event.observe(node, 'click', function(evt) {
                    var node = Event.element(evt);
                    $('batch-' + node.id).checked = false;
                    Element.remove(node.parentNode);

                    var any_checked = false;
                    $$('.batch').each(function(n) {
                      if (n.checked) { any_checked = true; }
                    });

                    if (!any_checked) { $('bulk-edit').hide(); }
                  });
                }
              });

              if (any_checked) { $('bulk-edit').show(); }

              break;
            case "delete":
              if (confirm("<?php 
    _e('You are about to delete the selected posts and comic files. Are you sure?', 'comicpress-manager');
    ?>
")) {
                ok_to_submit = true;
                $('bulk-form').submit();
              }
              break;
            default:
              ok_to_submit = true;
              $('bulk-form').submit();
              break;
          }
        });
      });
    </script>
  </div>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content($help_content, $activity_content, false);
}
/**
 * The config editor dialog.
 */
function cpm_manager_config()
{
    global $cpm_config;
    extract(cpm_normalize_storyline_structure());
    ob_start();
    ?>

  <h2 style="padding-right:0;"><?php 
    _e("Edit ComicPress Config", 'comicpress-manager');
    ?>
</h2>
  <?php 
    if (!$cpm_config->can_write_config) {
        ?>
    <p>
      <?php 
        _e("<strong>You won't be able to automatically update your configuration.</strong> After submitting, you will be shown the code to paste into comicpress-config.php. If you want to enable automatic updating, check the permissions of your theme folder and comicpress-config.php file.", 'comicpress-manager');
        ?>
    </p>
  <?php 
    }
    echo cpm_manager_edit_config();
    ?>

  <?php 
    if (get_option('comicpress-enable-storyline-support') == 1) {
        ?>
    <form action="" method="post">
      <input type="hidden" name="action" value="manage-subcomic" />
      <table class="form-table" cellspacing="0">
        <tr>
          <th scope="row">Manage a subcomic</th>
          <td>
            <select name="comic">
              <?php 
        $first = true;
        $path = CPM_DOCUMENT_ROOT . '/' . $cpm_config->properties['comic_folder'];
        foreach ($category_tree as $node) {
            $category = get_category(end(explode("/", $node)));
            $selected = get_option('comicpress-manager-manage-subcomic') == $category->term_id ? " selected" : "";
            if (is_dir($path . '/' . $category->slug) || $first) {
                ?>
                    <option value="<?php 
                echo $category->term_id;
                ?>
"<?php 
                echo $selected;
                ?>
><?php 
                echo $category->name . ($first ? " (default)" : "");
                ?>
</option>
                  <?php 
            }
            $first = false;
        }
        ?>
            </select>
            <input type="submit" value="Submit" />
          </td>
        </tr>
      </table>
    </form>
  <?php 
    }
    $activity_content = ob_get_clean();
    cpm_wrap_content(null, $activity_content);
}
/**
 * The Storyline Structure editor
 */
function cpm_manager_storyline()
{
    global $comicpress_manager;
    extract($comicpress_manager->normalize_storyline_structure());
    $category_tree_javascript = array();
    $category_names = array();
    foreach ($category_tree as $node) {
        $category_tree_javascript[] = "'{$node}'";
        $parts = explode("/", $node);
        $category = get_category(end($parts));
        $category_names[] = '"' . $category->name . '"';
    }
    $help_content = __("<p><strong>Set Up Storyline Structure</strong> lets you manage your site's categories so that they can be used for storyline management. You would name them with the <strong>names of the logical divisions of your story: Chapter 1, Volume 2, etc.</strong></p>", 'comicpress-manager');
    $help_content .= __("<p>If you want to <strong>change the parent/child relationships of categories</strong>, you'll have to do that at <a href=\"categories.php\"><strong>Manage -> Categories</strong></a> for now.</p>", 'comicpress-manager');
    $help_content .= __("<p>If you <strong>added or deleted categories, or changed parent/child relationships, via Manage -> Categories</strong>, you may need to <strong>rearrange your internal story structure</strong>, otherwise your navigation will be incorrect.</p>", 'comicpress-manager');
    if (!function_exists('get_comic_path')) {
        $comicpress_manager->warnings[] = __("<strong>It looks like you're running an older version of ComicPress.</strong> Storylines are only fully supported in <a href=\"http://comicpress.org/\" target=\"_new\">ComicPress 2.7</a> or with certain theme modifications.", 'comicpress-manager');
    }
    ob_start();
    ?>
  
  <h2 style="padding-right:0;"><?php 
    _e("Set Up Storyline Structure", 'comicpress-manager');
    ?>
</h2>
  <h3>&mdash; <?php 
    _e("remember, these are all categories and their details can be edited in Posts -> Categories", 'comicpress-manager');
    ?>
</h3>

  <form action="" method="post">
    <input type="hidden" name="action" value="build-storyline-schema" />
    <input type="hidden" name="order" id="order" value="" />
    <input type="hidden" name="original-categories" value="<?php 
    echo implode(",", $category_tree);
    ?>
" />
    <div style="margin-bottom: 5px">
      <label>
        <input type="checkbox"
               id="enable-storyline-support"
               name="enable-storyline-support"
               value="yes"
               <?php 
    echo get_option('comicpress-enable-storyline-support') == 1 ? "checked" : "";
    ?>
 /> Enable Storyline Support
      </label>
    </div>

    <div id="storyline-holder"
         style="margin-bottom: 10px<?php 
    echo get_option('comicpress-enable-storyline-support') == 1 ? "" : "; display: none";
    ?>
">
      <div style="text-align: center"><?php 
    _e("Loading...", 'comicpress-manager');
    ?>
</div>
    </div>
    <input type="submit" class="button" value="<?php 
    _e("Save Structure and Modify Categories", 'comicpress-manager');
    ?>
" /> | <a href="">Cancel Changes</a>
  </form>
  <script type="text/javascript">
    var max_id = <?php 
    echo $max_id;
    ?>
;

    var tree = [ <?php 
    echo implode(", ", $category_tree_javascript);
    ?>
 ];
    var category_names = [ <?php 
    echo implode(", ", $category_names);
    ?>
 ];

    var show_top_category = <?php 
    echo get_option('comicpress-storyline-show-top-category') == 1 ? "true" : "false";
    ?>
;

    function set_order() {
      var order = [];
      $$('#storyline-holder div').each(function(node) {
        if (get_cat_path(node.id) != "") {
          order.push(get_cat_path(node.id));
        }
      });
      $('order').value = order.join(",");
    }

    function new_category(parent) {
      max_id++;
      var parts = parent.split("/");
      var target_id = parent + "/" + max_id;

      return { target_id: target_id, holder: generate_cat_editor(target_id, "", true) };
    }

    function generate_cat_editor(target_id, name, ok_to_delete) {
      var commands;
      if (target_id.split("/").length == 2) {
        var input_parameters = { type: "checkbox", name: "show-top-category", value: "yes" };
        if (show_top_category) { input_parameters['checked'] = true; };
        commands = Builder.node("div", [
          "Create: [ ",
          Builder.node("a", { href: "#", className: "child", id: "child-" + target_id }, [ "Child" ]),
          "|",
          Builder.node("label", [
            Builder.node("input", input_parameters),
            " Show This Category on Site ",
          ]),
          " ]"
        ]);
      } else {
        commands = Builder.node("div", [
          "Create: [ ",
          Builder.node("a", { href: "#", className: "sibling", id: "sibling-" + target_id }, [ "Sibling" ]),
          " | ",
          Builder.node("a", { href: "#", className: "child", id: "child-" + target_id }, [ "Child" ]),
          " ] Move: [ ",
          Builder.node("a", { href: "#", className: "up", id: "up-" + target_id }, [ "Up" ]),
          " | ",
          Builder.node("a", { href: "#", className: "down", id: "down-" + target_id }, [ "Down" ]),
          " ] ",
          Builder.node("a", { href: "#", className: "delete", id: "delete-" + target_id }, [ "Delete" ])
        ]);
      }

      return Builder.node('div', { className: "holder", id: "holder-" + target_id, style: "margin-left: " + (target_id.split("/").length - 2) * 30 + "px" }, [
        Builder.node("input", { type: "text", value: name, name: target_id, size: 40 }),
        commands
      ]);
    }

    var css_search_path = "#storyline-holder .holder";

    function do_move(id, is_down) {
      var start_parts = id.split('/');
      var end_parts;
      var start_node = $('holder-' + id);
      var end_node = $('holder-' + id);
      while (end_node) {
        end_node = is_down ? end_node.next(css_search_path) : end_node.previous(css_search_path);
        if (end_node) {
          end_parts = get_cat_path(end_node.id).split("/");
          if (end_parts.length == start_parts.length) {
            break;
          }
        }
      }

      if (end_node) {
        var ok = true;
        for (i = 0; i < start_parts.length - 1; ++i) {
          if (start_parts[i] != end_parts[i]) { ok = false; break; }
        }

        if (ok) {
          var child_node_lists = {};
          [ [ "start", start_node ], [ "end", end_node ] ].each(function(info) {
            var child_node_list = [];
            var child_node = info[1];
            while (child_node) {
              child_node_list.push(child_node)
              child_node = child_node.next(css_search_path);
              if (child_node) {
                var child_parts = get_cat_path(child_node.id).split("/");
                if (child_parts.length <= start_parts.length) {
                  break;
                }
              }
            }
            child_node_lists[info[0]] = child_node_list;
          });

          if (is_down) { child_node_lists['start'].reverse(true); }

          child_node_lists['start'].each(function(node) {
            for (i = 0, il = child_node_lists['end'].length; i < il; ++i) {
              var target_swap_node = is_down ? node.next(css_search_path) : node.previous(css_search_path);

              is_down ? Element.swapWith(node, target_swap_node) : Element.swapWith(target_swap_node, node);
            }
          });
        }
      }
    }

    function set_up_handlers(id) {
      Event.observe("child-" + id, 'click', function(e) {
        Event.stop(e);
        var new_cat = new_category(id);

        $('holder-' + id).insert({ after: new_cat.holder });
        set_up_handlers(new_cat.target_id);
        set_order();
      });

      if ($("sibling-" + id)) {
        Event.observe("sibling-" + id, 'click', function(e) {
          Event.stop(e);
          var parent_id = id.replace(/\/[^\/]+$/, '');
          var new_cat = new_category(parent_id);

          var top_node = $('holder-' + id);
          do {
            var next_node = top_node.next(css_search_path);
            if (next_node) {
              if (get_cat_path(next_node.id).length > id.length) {
                top_node = next_node;
              } else {
                next_node = null;
              }
            }
          } while (next_node);

          top_node.insert({ after: new_cat.holder });
          set_up_handlers(new_cat.target_id);
          set_order();
        });

        Event.observe("up-" + id, 'click', function(e) {
          Event.stop(e);
          do_move(id, false);
          set_order();
        });

        Event.observe("down-" + id, 'click', function(e) {
          Event.stop(e);
          do_move(id, true);
          set_order();
        });
      }

      if ($("delete-" + id)) {
        Event.observe("delete-" + id, 'click', function(e) {
          Event.stop(e);
          var top_node = $('holder-' + id);
          do {
            var next_node = top_node.next(css_search_path);
            Element.remove(top_node);

            if (next_node) {
              if (get_cat_path(next_node.id).length > id.length) {
                top_node = next_node;
              } else {
                next_node = null;
              }
            }
          } while (next_node);
        });
      }
    }

    function get_cat_path(id) { return id.replace(/^.+\-([^\-]+)$/, '$1'); }

    Event.observe(window, 'load', function() {
      $('storyline-holder').innerHTML = "";
      for (i = 0, il = tree.length; i < il; ++i) {
        $('storyline-holder').insert(generate_cat_editor(tree[i], category_names[i]));
        set_up_handlers(tree[i]);
      }
      set_order();

      Event.observe($('enable-storyline-support'), 'click', function(e) {
        $('enable-storyline-support').checked ? $('storyline-holder').show() : $('storyline-holder').hide();
      });
    });

    Element.addMethods({
      swapWith: (function() {
        if ('swapNode' in document.documentElement)
          return function(element, other) {
            return $(element).swapNode($(other));
          };
        return function(element, other) {
           element = $(element);
           other = $(other);
           var next = other.nextSibling, parent = other.parentNode;
           element.parentNode.replaceChild(other, element);
           return parent.insertBefore(element, next);
        };
      })()
    });
  </script>

  <?php 
    $activity_content = ob_get_clean();
    cpm_wrap_content($help_content, $activity_content);
}