Example #1
0
    public function form($instance)
    {
        global $webcomic;
        $webcomic->domain();
        $instance = wp_parse_args((array) $instance, array('title' => __('Archive', 'webcomic'), 'label' => '', 'format' => 'ulist', 'image' => false, 'group' => false, 'term_group' => false, 'limit' => 0, 'order' => true));
        extract($instance);
        $title = htmlspecialchars($title, ENT_QUOTES);
        ?>
		<p><label><?php 
        _e('Title:', 'webcomic');
        ?>
<input type="text" name="<?php 
        echo $this->get_field_name('title');
        ?>
" value="<?php 
        echo $title;
        ?>
" class="widefat"></label></p>
		<p><label><?php 
        _e('Label:', 'webcomic');
        ?>
<input type="text" name="<?php 
        echo $this->get_field_name('label');
        ?>
" value="<?php 
        echo $label;
        ?>
" class="widefat"><small><?php 
        _e('For the first option in dropdowns.', 'webcomic');
        ?>
</small></label></p>
		<p>
			<label>
				<?php 
        _e('Format:', 'webcomic');
        ?>
				<select name="<?php 
        echo $this->get_field_name('format');
        ?>
">
					<option value="ulist"<?php 
        if ('ulist' == $format) {
            echo ' selected';
        }
        ?>
><?php 
        _e('List', 'webcomic');
        ?>
</option>
					<option value="dropdown"<?php 
        if ('dropdown' == $format) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Dropdown', 'webcomic');
        ?>
</option>
					<option value="grid"<?php 
        if ('grid' == $format) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Grid', 'webcomic');
        ?>
</option>
				</select>
			</label>
		</p>
		<p>
			<label>
				<?php 
        _e('Group By:', 'webcomic');
        ?>
				<select name="<?php 
        echo $this->get_field_name('group');
        ?>
">
					<option value=""><?php 
        _e('Nothing', 'webcomic');
        ?>
</option>
					<option value="storyline"<?php 
        if ('storyline' == $group) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Storyline', 'webcomic');
        ?>
</option>
					<option value="character"<?php 
        if ('character' == $group) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Character', 'webcomic');
        ?>
</option>
					<option value="year"<?php 
        if ('year' == $group) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Year', 'webcomic');
        ?>
</option>
					<option value="month"<?php 
        if ('month' == $group) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Month', 'webcomic');
        ?>
</option>
					<option value="day"<?php 
        if ('day' == $group) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Day', 'webcomic');
        ?>
</option>
				</select>
			</label>
		</p>
		<p>
			<label>
				<?php 
        _e('Preview:', 'webcomic');
        ?>
				<select name="<?php 
        echo $this->get_field_name('image');
        ?>
">
					<option value=""><?php 
        _e('Title', 'webcomic');
        ?>
</option>
					<option value="small"<?php 
        if ('small' == $image) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Small', 'webcomic');
        ?>
</option>
					<option value="medium"<?php 
        if ('medium' == $image) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Medium', 'webcomic');
        ?>
</option>
					<option value="large"<?php 
        if ('large' == $image) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Large', 'webcomic');
        ?>
</option>
					<option value="full"<?php 
        if ('full' == $image) {
            echo ' selected';
        }
        ?>
><?php 
        _e('Full', 'webcomic');
        ?>
</option>
				</select>
			</label>
		</p>
		<p>
			<label>
				<?php 
        _e('Collection:', 'webcomic');
        ?>
				<select name="<?php 
        echo $this->get_field_name('term_group');
        ?>
">
					<?php 
        $walker = new webcomic_Walker_AdminTermDropdown();
        $selected = $term_group ? array($term_group) : array();
        echo $walker->walk(get_terms('webcomic_collection', 'get=all'), 0, array('selected' => $selected, 'no_def' => true));
        ?>
				</select>
			</label>
		</p>
		<p><label><?php 
        _e('Number:', 'webcomic');
        ?>
<input type="text" name="<?php 
        echo $this->get_field_name('limit');
        ?>
" value="<?php 
        echo $limit;
        ?>
" size="3"><small><?php 
        _e('0 to show all webcomics.', 'webcomic');
        ?>
</small></label></p>
		<p><label><input type="checkbox" name="<?php 
        echo $this->get_field_name('order');
        ?>
" value="1"<?php 
        if (!$order) {
            echo ' checked';
        }
        ?>
> <?php 
        _e('Show webcomics in reverse order', 'webcomic');
        ?>
</label></p>
		<input type="hidden" name="<?php 
        echo $this->get_field_name('submit');
        ?>
" value="1">
		<?php 
    }
Example #2
0
    /**
     * Displays appropriate content based on webcomic_ajax request.
     * 
     * @package webcomic
     * @since 3
     */
    public function admin_ajax()
    {
        $this->domain();
        if (empty($_REQUEST['webcomic_ajax'])) {
            return false;
        } elseif ('collection' == $_REQUEST['webcomic_ajax']) {
            global $post;
            $wc = $_REQUEST['webcomic_collection'] ? get_term($_REQUEST['webcomic_collection'], 'webcomic_collection') : false;
            $ids = $_REQUEST['post_ID'] && is_object_in_term($_REQUEST['post_ID'], 'webcomic_collection', $wc->term_id) ? true : false;
            ?>
		<td style="vertical-align:top;width:33%">
			<select name="webcomic_collection" id="webcomic_collection">
			<?php 
            if ('webcomic_post' != $_REQUEST['post_type']) {
                ?>
<option value=""><?php 
                _e('&mdash; Collections &mdash;', 'webcomic');
                ?>
</option><?php 
            }
            ?>
			<?php 
            $walker = new webcomic_Walker_AdminTermDropdown();
            echo $walker->walk(get_terms('webcomic_collection', 'get=all'), 0, array('selected' => array($wc->term_id), 'no_def' => false));
            ?>
			</select><br>
			<?php 
            if (!$wc) {
                printf(__('<p>Select a collection to make this a webcomic %s.</p>', 'webcomic'), $_REQUEST['post_type']);
            } else {
                echo '<p>' . __('Hold <code>Ctrl</code> or <code>Command</code> to select multiple storylines and characters.', 'webcomic') . '</p>';
            }
            ?>
		</td>
		<td style="width:33%">
			<?php 
            if ($wc) {
                ?>
			<label for="webcomic_storyline"><b><?php 
                _e('Storylines', 'webcomic');
                ?>
</b></label><br>
			<select name="webcomic_storyline[]" id="webcomic_storyline" size="2" style="height:10em;width:100%" multiple>
			<?php 
                $walker = new webcomic_Walker_AdminTermDropdown();
                $selected = wp_get_object_terms($_REQUEST['post_ID'], 'webcomic_storyline', array('fields' => 'ids'));
                echo $walker->walk(get_terms('webcomic_storyline', 'hide_empty=0&orderby=term_group_name&webcomic_order=1&term_group=' . $wc->term_id), 0, array('selected' => $selected, 'no_def' => $ids));
                ?>
			</select>
			<?php 
            }
            ?>
		</td>
		<td style="width:33%">
			<?php 
            if ($wc) {
                ?>
			<label for="webcomic_character"><b><?php 
                _e('Characters', 'webcomic');
                ?>
</b></label><br>
			<select name="webcomic_character[]" id="webcomic_character" size="2" style="height:10em;width:100%" multiple>
			<?php 
                $walker = new webcomic_Walker_AdminTermDropdown();
                $selected = wp_get_object_terms($_REQUEST['post_ID'], 'webcomic_character', array('fields' => 'ids'));
                echo $walker->walk(get_terms('webcomic_character', 'hide_empty=0&orderby=term_group_name&term_group=' . $wc->term_id), 0, array('selected' => $selected, 'no_def' => $ids));
                ?>
			</select>
			<?php 
            }
            ?>
			<script type="text/javascript">jQuery(document).ready(function($){$('select#webcomic_collection').change(function(){$('input[name=webcomic_ajax]').val('collection');var params=$('form').serialize();$('#webcomic_terms').load('<?php 
            echo $_SERVER['PHP_SELF'];
            ?>
',params);$('input[name=webcomic_ajax]').val('orphans');var params=$('form').serialize();$('#webcomic_orphans').load('<?php 
            echo $_SERVER['PHP_SELF'];
            ?>
',params);$('input[name=webcomic_ajax]').val(0);});});</script>
		</td>
		<?php 
            die;
        } elseif ('orphans' == $_REQUEST['webcomic_ajax'] && 'webcomic_post' == get_post_type($_REQUEST['post_ID'])) {
            $wc = $_REQUEST['webcomic_collection'] ? get_term($_REQUEST['webcomic_collection'], 'webcomic_collection') : false;
            if ($wc) {
                $abs = $this->directory('abs', $wc->slug);
                $url = $this->directory('url', $wc->slug);
                $tabs = $abs . 'thumbs/';
                $turl = $url . 'thumbs/';
                $files = glob($abs . '*.*');
                $posts = get_objects_in_term($wc->term_id, 'webcomic_collection');
                $term_meta = $this->option('term_meta');
                if (false !== ($index_key = array_search($abs . 'index.php', $files))) {
                    unset($files[$index_key]);
                }
                foreach ($term_meta as $taxonomy) {
                    foreach ($taxonomy as $term) {
                        if (!empty($term['files'])) {
                            foreach ($term['files']['full'] as $k => $v) {
                                if (false !== ($key = array_search($abs . $term['files']['full'][$k], $files))) {
                                    unset($files[$key]);
                                }
                            }
                        }
                    }
                }
                foreach ($posts as $k => $v) {
                    if ('webcomic_post' != get_post_type($v)) {
                        continue;
                    }
                    $status = get_post_status($v);
                    $post_files = $this->fetch($v, 'post', $wc->slug, true);
                    if (!empty($post_files)) {
                        foreach ($post_files['full'] as $f) {
                            $fk = array_search($abs . $f, $files);
                            unset($files[$fk]);
                        }
                    }
                }
                if ($files) {
                    ?>
			<p><?php 
                    _e('Select one or more orphaned files to bind them to this post, or upload new files below.', 'webcomic');
                    ?>
</p>
			<table id="availablethemes" cellspacing="0" cellpadding="0">
			<?php 
                    $rows = ceil(count($files) / 3);
                    $table = array();
                    for ($row = 1; $row <= $rows; $row++) {
                        for ($col = 1; $col <= 3; $col++) {
                            $table[$row][$col] = array_shift($files);
                        }
                    }
                    foreach ($table as $row => $cols) {
                        ?>
				<tr>
				<?php 
                        foreach ($cols as $col => $file) {
                            $class = array('available-theme');
                            if ($row == 1) {
                                $class[] = 'top';
                            }
                            if ($row == $rows) {
                                $class[] = 'bottom';
                            }
                            if ($col == 1) {
                                $class[] = 'left';
                            }
                            if ($col == 3) {
                                $class[] = 'right';
                            }
                            if (!$term) {
                                echo '<td class="' . join(' ', $class) . '"></td>';
                                continue;
                            }
                            ?>
					<td class="<?php 
                            echo join(' ', $class);
                            ?>
">
					<?php 
                            if ($file) {
                                ?>
						<input type="checkbox" name="webcomic_orphan[<?php 
                                echo hash('md5', $file);
                                ?>
]" id="webcomic_orphan[<?php 
                                echo hash('md5', $file);
                                ?>
]" value="<?php 
                                echo stripslashes($file);
                                ?>
">
						<label for="webcomic_orphan[<?php 
                                echo hash('md5', $file);
                                ?>
]">
						<?php 
                                $orphan = $this->retrieve($file, 'orphan', $wc->slug);
                                if ($orphan['small']) {
                                    echo $orphan['small'][0]['html'];
                                } elseif ($orphan['medium']) {
                                    echo $orphan['medium'][0]['html'];
                                } elseif ($orphan['large']) {
                                    echo $orphan['large'][0]['html'];
                                } else {
                                    echo $orphan['full'][0]['html'];
                                }
                                ?>
						</label><br>
						<a href="<?php 
                                echo $orphan['full'][0]['url'];
                                ?>
" target="_blank"><?php 
                                _e('View', 'webcomic');
                                ?>
</a>
						<?php 
                            }
                            ?>
					</td>
					<?php 
                        }
                        ?>
				</tr>
				<?php 
                    }
                    ?>
			</table>
		<?php 
                }
            }
            die;
        } elseif ('batch_post' == $_REQUEST['webcomic_ajax']) {
            ?>
		<div class="form-field">
			<label for="webcomic_post_storylines" style="float:left"><b><?php 
            _e('Storylines', 'webcomic');
            ?>
</b></label>
			<select name="webcomic_post_storylines_action" style="float:right">
				<option value="add"><?php 
            _e('Add', 'webcomic');
            ?>
</option>
				<option value="replace"><?php 
            _e('Replace', 'webcomic');
            ?>
</option>
			</select>
			<select name="webcomic_post_storylines[]" id="webcomic_post_storylines" size="2" style="height:10em;width:100%" multiple>
			<?php 
            $walker = new webcomic_Walker_AdminTermDropdown();
            echo $walker->walk(get_terms('webcomic_storyline', 'hide_empty=0&orderby=term_group_name&webcomic_order=1&term_group=' . $_REQUEST['webcomic_post_collection']), 0, array('selected' => array(), 'no_def' => true));
            ?>
			</select>
			<p><?php 
            _e('Hold <code>CTRL</code> or <code>Command</code> to select multiple storylines. Remove posts from all storylines by selecting &#8220;Replace&#8221; with no storylines selected.', 'webcomic');
            ?>
</p>
		</div>
		<div class="form-field">
			<label for="webcomic_post_characters" style="float:left"><b><?php 
            _e('Characters', 'webcomic');
            ?>
</b></label>
			<select name="webcomic_post_characters_action" style="float:right">
				<option value="add"><?php 
            _e('Add', 'webcomic');
            ?>
</option>
				<option value="replace"><?php 
            _e('Replace', 'webcomic');
            ?>
</option>
			</select>
			<select name="webcomic_post_characters[]" id="webcomic_post_characters" size="2" style="height:10em;width:100%" multiple>
			<?php 
            $walker = new webcomic_Walker_AdminTermDropdown();
            echo $walker->walk(get_terms('webcomic_character', 'hide_empty=0&orderby=term_group_name&term_group=' . $_REQUEST['webcomic_post_collection']), 0, array('selected' => array(), 'no_def' => true));
            ?>
			</select>
			<p><?php 
            _e('Hold <code>CTRL</code> or <code>Command</code> to select multiple characters. Remove posts from all characters by selecting &#8220;Replace&#8221; with no characters selected.', 'webcomic');
            ?>
</p>
		</div>
		<?php 
            die;
        } else {
            die;
        }
    }