Ejemplo n.º 1
0
function customtaxorder()
{
    global $customtaxorder_settings;
    customtaxorder_update_settings();
    $options = $customtaxorder_settings;
    $settings = '';
    $parent_ID = 0;
    if ($_GET['page'] == 'customtaxorder') {
        $args = array('public' => true, '_builtin' => false);
        $output = 'objects';
        $taxonomies = get_taxonomies($args, $output);
        foreach ($taxonomies as $taxonomy) {
            $settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
        }
        $settings .= '<input name="customtaxorder_settings[category]" type="checkbox" value="1" ' . checked('1', $options['category'], false) . ' /> <label for="customtaxorder_settings[category]">Check this box if you want to enable Automatic Sorting of all instances from this taxonomy.</label>';
        $tax_label = 'Categories';
        $tax = 'category';
    } else {
        $args = array('public' => true, '_builtin' => false);
        $output = 'objects';
        $taxonomies = get_taxonomies($args, $output);
        foreach ($taxonomies as $taxonomy) {
            $com_page = 'customtaxorder-' . $taxonomy->name;
            if ($_GET['page'] == $com_page) {
                $settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="checkbox" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> <label for="customtaxorder_settings[' . $taxonomy->name . ']">Check this box if you want to enable Automatic Sorting of all instances from this taxonomy.</label>';
                $tax_label = $taxonomy->label;
                $tax = $taxonomy->name;
            } else {
                $settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
            }
        }
        $settings .= '<input name="customtaxorder_settings[category]" type="hidden" value="' . $options['category'] . '" />';
    }
    if (isset($_POST['go-sub-posts'])) {
        $parent_ID = $_POST['sub-posts'];
    } elseif (isset($_POST['hidden-parent-id'])) {
        $parent_ID = $_POST['hidden-parent-id'];
    }
    if (isset($_POST['return-sub-posts'])) {
        $parent_term = get_term($_POST['hidden-parent-id'], $tax);
        $parent_ID = $parent_term->parent;
    }
    $message = "";
    if (isset($_POST['order-submit'])) {
        customtaxorder_update_order();
    }
    ?>
<div class='wrap'>
	<?php 
    screen_icon('customtaxorder');
    ?>
	<h2><?php 
    _e('Order ' . $tax_label, 'customtaxorder');
    ?>
</h2>
	<form name="custom-order-form" method="post" action="">
		<?php 
    $args = array('orderby' => 'term_order', 'order' => 'ASC', 'hide_empty' => false, 'parent' => $parent_ID);
    $terms = get_terms($tax, $args);
    if ($terms) {
        ?>
		<div id="poststuff" class="metabox-holder">
			<div class="widget order-widget">
				<h3 class="widget-top"><?php 
        _e($tax_label, 'customtaxorder');
        ?>
 | <small><?php 
        _e('Order the ' . $tax_label . ' by dragging and dropping them into the desired order.', 'customtaxorder');
        ?>
</small></h3>
				<div class="misc-pub-section">
					<ul id="custom-order-list">
						<?php 
        foreach ($terms as $term) {
            ?>
						<li id="id_<?php 
            echo $term->term_id;
            ?>
" class="lineitem"><?php 
            echo $term->name;
            ?>
</li>
						<?php 
        }
        ?>
					</ul>
				</div>
				<div class="misc-pub-section misc-pub-section-last">
					<?php 
        if ($parent_ID != 0) {
            ?>
						<input type="submit" class="button" style="float:left" id="return-sub-posts" name="return-sub-posts" value="<?php 
            _e('Return to Parent', 'customtaxorder');
            ?>
" />
					<?php 
        }
        ?>
					<div id="publishing-action">
						<img src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" id="custom-loading" style="display:none" alt="" />
						<input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php 
        _e('Update Order', 'customtaxorder');
        ?>
" />
					</div>
					<div class="clear"></div>
					</div>
				<input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
				<input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php 
        echo $parent_ID;
        ?>
" />
			</div>
			<?php 
        $dropdown = customtaxorder_sub_query($terms, $tax);
        if (!empty($dropdown)) {
            ?>
			<div class="widget order-widget">
				<h3 class="widget-top"><?php 
            _e('Sub-' . $tax_label, 'customtaxorder');
            ?>
 | <small><?php 
            _e('Choose a term from the drop down to order its sub-terms.', 'customtaxorder');
            ?>
</small></h3>
				<div class="misc-pub-section misc-pub-section-last">
					<select id="sub-posts" name="sub-posts">
						<?php 
            echo $dropdown;
            ?>
					</select>
					<input type="submit" name="go-sub-posts" class="button" id="go-sub-posts" value="<?php 
            _e('Order Sub-terms', 'customtaxorder');
            ?>
" />
				</div>
			</div>		
			<?php 
        }
        ?>
		</div>
		<?php 
    } else {
        ?>
		<p><?php 
        _e('No terms found', 'customtaxorder');
        ?>
</p>
		<?php 
    }
    ?>
	</form>
	<form method="post" action="options.php">
		<?php 
    settings_fields('customtaxorder_settings');
    ?>
		<table class="form-table">
			<tr valign="top"><th scope="row">Auto-Sort Queries</th>
			<td><?php 
    echo $settings;
    ?>
</td>
			</tr>
		</table>
		<input type="hidden" name="customtaxorder_settings[update]" value="Updated" />
		<p class="submit">
			<input type="submit" class="button-primary" value="<?php 
    _e('Save Settings');
    ?>
" />
		</p>
	</form>
</div>
<?php 
    if ($terms) {
        ?>
<script type="text/javascript">
// <![CDATA[
	jQuery(document).ready(function($) {
		$("#custom-loading").hide();
		$("#order-submit").click(function() {
			orderSubmit();
		});
	});
	function customtaxorderAddLoadEvent(){
		jQuery("#custom-order-list").sortable({ 
			placeholder: "sortable-placeholder", 
			revert: false,
			tolerance: "pointer" 
		});
	};
	addLoadEvent(customtaxorderAddLoadEvent);
	function orderSubmit() {
		var newOrder = jQuery("#custom-order-list").sortable("toArray");
		jQuery("#custom-loading").show();
		jQuery("#hidden-custom-order").val(newOrder);
		return true;
	}
// ]]>
</script>
<?php 
    }
}
Ejemplo n.º 2
0
function customtaxorder()
{
    global $customtaxorder_settings, $sitepress;
    customtaxorder_update_settings();
    $options = $customtaxorder_settings;
    $settings = '';
    // The input and text for the taxonomy that's shown
    $parent_ID = 0;
    // Get list of taxonomies
    $args = array('public' => true);
    $output = 'objects';
    $taxonomies = get_taxonomies($args, $output);
    // Also make the link_category available if activated.
    $linkplugin = "link-manager/link-manager.php";
    include_once ABSPATH . 'wp-admin/includes/plugin.php';
    if (is_plugin_active($linkplugin)) {
        $args = array('name' => 'link_category');
        $taxonomies2 = get_taxonomies($args, $output);
        $taxonomies = array_merge($taxonomies, $taxonomies2);
    }
    if (!empty($taxonomies)) {
        foreach ($taxonomies as $taxonomy) {
            $com_page = 'customtaxorder-' . $taxonomy->name;
            if (!isset($options[$taxonomy->name])) {
                $options[$taxonomy->name] = 0;
                // default if not set in options yet
            }
            if ($_GET['page'] == $com_page) {
                // Set your custom capability through this filter.
                $custom_cap = apply_filters('customtaxorder_custom_cap', 'manage_categories');
                // Set your finegrained capability for this taxonomy for this custom filter.
                $custom_cap_tax = apply_filters('customtaxorder_custom_cap_' . $taxonomy->name, $custom_cap);
                if (function_exists('current_user_can') && !current_user_can($custom_cap_tax)) {
                    die(__('Cheatin&#8217; uh?', 'custom-taxonomy-order-ne'));
                }
            }
        }
    }
    // Remove filter for WPML
    remove_filter('terms_clauses', array($sitepress, 'terms_clauses'), 10, 4);
    remove_filter('get_terms', array($sitepress, 'get_terms_filter'));
    ?>
	<div class='wrap customtaxorder'>
		<div id="icon-customtaxorder"></div>

	<?php 
    if ($_GET['page'] == 'customtaxorder') {
        // Main admin page with just a set of links to the taxonomy pages.
        // Set your custom capability through this filter.
        $custom_cap = apply_filters('customtaxorder_custom_cap', 'manage_categories');
        if (function_exists('current_user_can') && !current_user_can($custom_cap)) {
            die(__('Cheatin&#8217; uh?', 'custom-taxonomy-order-ne'));
        }
        ?>
		<h1>Custom Taxonomy Order NE</h1>
		<div class="order-widget">
			<p><?php 
        _e('The ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.', 'custom-taxonomy-order-ne');
        ?>
</p>
		<?php 
        if (!empty($taxonomies)) {
            echo "<h2>" . __('Taxonomies', 'custom-taxonomy-order-ne') . "</h2><ul>";
            $taxonomies = customtaxorder_sort_taxonomies($taxonomies);
            echo '<li class="lineitem"><a href="' . admin_url('admin.php?page=customtaxorder-taxonomies') . '">' . __('Taxonomies', 'custom-taxonomy-order-ne') . '</a></li>
				';
            foreach ($taxonomies as $taxonomy) {
                echo '<li class="lineitem"><a href="' . admin_url('admin.php?page=customtaxorder-' . $taxonomy->name) . '">' . $taxonomy->label . '</a></li>
				';
            }
        }
        echo '</ul></div></div><!-- #wrap -->';
        return;
    } else {
        if (!empty($taxonomies)) {
            foreach ($taxonomies as $taxonomy) {
                $com_page = 'customtaxorder-' . $taxonomy->name;
                if (!isset($options[$taxonomy->name])) {
                    $options[$taxonomy->name] = 0;
                    // default if not set in options yet
                }
                if ($_GET['page'] == $com_page) {
                    $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="0" ' . checked('0', $options[$taxonomy->name], false) . ' /> ' . __('Order by ID (default).', 'custom-taxonomy-order-ne') . '</label><br />
						';
                    $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> ' . __('Custom Order as defined above.', 'custom-taxonomy-order-ne') . '</label><br />
						';
                    $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="2" ' . checked('2', $options[$taxonomy->name], false) . ' /> ' . __('Alphabetical Order.', 'custom-taxonomy-order-ne') . '</label><br />
						';
                    $tax_label = $taxonomy->label;
                    $tax = $taxonomy->name;
                } else {
                    if (!isset($options[$taxonomy->name])) {
                        $options[$taxonomy->name] = 0;
                        // default if not set in options yet
                    }
                    $settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
                }
            }
        }
    }
    $parent_ID_order = 0;
    if (isset($_POST['go-sub-posts'])) {
        $parent_ID = $_POST['sub-posts'];
    } elseif (isset($_POST['hidden-parent-id'])) {
        $parent_term = get_term($_POST['hidden-parent-id'], $tax);
        $parent_ID = $_POST['hidden-parent-id'];
        if (is_object($parent_term) && isset($parent_term->term_order)) {
            $parent_ID_order = $parent_term->term_order;
        }
    }
    if (isset($_POST['return-sub-posts'])) {
        $parent_term = get_term($_POST['hidden-parent-id'], $tax);
        $parent_ID = $parent_term->parent;
    }
    $message = "";
    if (isset($_POST['order-submit'])) {
        customtaxorder_update_order();
    }
    ?>

	<h1><?php 
    echo __('Order ', 'custom-taxonomy-order-ne') . $tax_label;
    ?>
</h1>
	<form name="custom-order-form" method="post" action="">
		<?php 
    $args = array('orderby' => 'term_order', 'order' => 'ASC', 'hide_empty' => false, 'parent' => $parent_ID);
    $terms = get_terms($tax, $args);
    if ($terms) {
        usort($terms, 'customtax_cmp');
        ?>
			<div id="poststuff" class="metabox-holder">
				<div class="widget order-widget">
					<h2 class="widget-top"><?php 
        _e($tax_label);
        ?>
 | <small><?php 
        _e('Order the taxonomies by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne');
        ?>
</small></h2>
					<div class="misc-pub-section">
						<ul id="custom-order-list">
							<?php 
        foreach ($terms as $term) {
            ?>
							<li id="id_<?php 
            echo $term->term_id;
            ?>
" class="lineitem"><?php 
            echo $term->name;
            ?>
</li>
							<?php 
        }
        ?>
						</ul>
					</div>
					<div class="misc-pub-section misc-pub-section-last">
						<?php 
        if ($parent_ID != 0) {
            ?>
							<input type="submit" class="button" style="float:left" id="return-sub-posts" name="return-sub-posts" value="<?php 
            _e('Return to Parent', 'custom-taxonomy-order-ne');
            ?>
" />
						<?php 
        }
        ?>
						<div id="publishing-action">
							<img src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" id="custom-loading" style="display:none" alt="" />
							<input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php 
        _e('Update Order', 'custom-taxonomy-order-ne');
        ?>
" />
							<input type="submit" name="order-alpha" id="order-alpha" class="button" value="<?php 
        _e('Sort Alphabetical', 'custom-taxonomy-order-ne');
        ?>
" />
						</div>
						<div class="clear"></div>
					</div>
					<input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
					<input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php 
        echo $parent_ID;
        ?>
" />
					<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php 
        echo $parent_ID_order;
        ?>
" />
				</div>
				<?php 
        $dropdown = customtaxorder_sub_query($terms, $tax);
        if (!empty($dropdown)) {
            ?>
				<div class="widget order-widget">
					<h2 class="widget-top"><?php 
            print __('Sub-', 'custom-taxonomy-order-ne') . $tax_label;
            ?>
 | <small><?php 
            _e('Choose a term from the drop down to order its sub-terms.', 'custom-taxonomy-order-ne');
            ?>
</small></h2>
					<div class="misc-pub-section misc-pub-section-last">
						<select id="sub-posts" name="sub-posts">
							<?php 
            echo $dropdown;
            ?>
						</select>
						<input type="submit" name="go-sub-posts" class="button" id="go-sub-posts" value="<?php 
            _e('Order Sub-terms', 'custom-taxonomy-order-ne');
            ?>
" />
					</div>
				</div>
				<?php 
        }
        ?>
			</div>
		<?php 
    } else {
        ?>
			<p><?php 
        _e('No terms found', 'custom-taxonomy-order-ne');
        ?>
</p>
		<?php 
    }
    ?>
	</form>
	<form method="post" action="options.php" class="clear">
		<?php 
    settings_fields('customtaxorder_settings');
    ?>
		<div class="metabox-holder">
			<div class="order-widget">
				<h2 class="widget-top"><?php 
    _e('Settings', 'custom-taxonomy-order-ne');
    ?>
</h2>
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><?php 
    _e('Auto-Sort Queries of this Taxonomy', 'custom-taxonomy-order-ne');
    ?>
</th>
					</tr>
					<tr valign="top">
						<td><?php 
    echo $settings;
    ?>
</td>
					</tr>
				</table>
				<input type="hidden" name="customtaxorder_settings[update]" value="Updated" />
				<p class="submit">
					<input type="submit" class="button-primary" value="<?php 
    _e('Save Settings', 'custom-taxonomy-order-ne');
    ?>
" />
				</p>
			</div>
		</div>
	</form>
</div>

<?php 
}
Ejemplo n.º 3
0
function customtaxorder()
{
    global $customtaxorder_settings;
    global $custom_tax;
    customtaxorder_update_settings();
    $options = $customtaxorder_settings;
    $settings = '';
    $parent_ID = 0;
    if ($_GET['page'] == 'customtaxorder') {
        $args = array('public' => true, '_builtin' => false);
        $output = 'objects';
        $tax_label = 'Catalogue Categories';
        $tax = $custom_tax;
    }
    $message = "";
    if (isset($_POST['order-submit'])) {
        customtaxorder_update_order();
    }
    ?>
<div class="wrap">
  <div id="icon-options-general" class="icon32"><br>
  </div>
  <h2>Order</h2>
  <div class="wpc-left-liquid">
    <div class="wpc-left">
      <div class="wpc-headings">
        <h3>Order Categories</h3>
      </div>
      <div class="wpc-inner">
        <p class="description"><?php 
    _e('Drag and drop items to customise the order of categories in WP Catalogue', 'wpc');
    ?>
 </p>
        <form name="custom-order-form" method="post" action="">
          <?php 
    $args = array('orderby' => 'term_order', 'order' => 'ASC', 'hide_empty' => false, 'parent' => $parent_ID);
    $terms = get_terms($tax, $args);
    if ($terms) {
        ?>
          <ul id="orderly-sortable" class="orderly-items">
            <?php 
        foreach ($terms as $term) {
            ?>
            <li id="id_<?php 
            echo $term->term_id;
            ?>
" class="lineitem <?php 
            echo $i % 2 == 0 ? 'alternate ' : '';
            ?>
ui-state-default"><?php 
            echo $term->name;
            ?>
</li>
            <?php 
        }
        ?>
          </ul>
          <img src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" id="custom-loading" style="display:none" alt="" />
          <input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php 
        _e('Save Order', 'wpc');
        ?>
" />
          <div class="clear"></div>
          <input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
          <input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php 
        echo $parent_ID;
        ?>
" />
          <?php 
    } else {
        ?>
          <p>
            <?php 
        _e('No terms found', 'wpc');
        ?>
          </p>
          <?php 
    }
    ?>
        </form>
      </div>
      <br class="clear">
      <?php 
    if ($terms) {
        ?>
      <script type="text/javascript">

// <![CDATA[

	jQuery(document).ready(function($) {

		$("#custom-loading").hide();

		$("#order-submit").click(function() {

			orderSubmit();

		});

	});

	function customtaxorderAddLoadEvent(){

		jQuery("#orderly-sortable").sortable({ 

			placeholder: "sortable-placeholder", 

			revert: false,

			tolerance: "pointer" 

		});

	};

	addLoadEvent(customtaxorderAddLoadEvent);

	function orderSubmit() {

		var newOrder = jQuery("#orderly-sortable").sortable("toArray");

		jQuery("#custom-loading").show();

		jQuery("#hidden-custom-order").val(newOrder);

		return true;

	}

// ]]>

</script>
      <?php 
    }
    $post_type = trim($_REQUEST['post_type']);
    if (empty($post_type)) {
        $post_type = 'post';
    }
    $post_type_object = get_post_type_object($post_type);
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $message = "Custom order saved for <em>{$post_type_object->labels->name}</em>";
        $values = (array) $_POST['orderly_values'];
        if (!empty($values)) {
            global $wpdb;
            for ($i = 0; $i < count($values); $i++) {
                $post_id = (int) $values[$i];
                $sql = $wpdb->prepare("UPDATE `{$wpdb->posts}` SET `menu_order` = %d WHERE ID = %d", $i, $post_id);
                $wpdb->query($sql);
            }
        }
    }
    $loop = new WP_Query(array('post_type' => $post_type, 'order' => 'ASC', 'orderby' => 'menu_order', 'nopaging' => true));
    ?>
      <?php 
    if (!empty($message)) {
        ?>
      <div class="updated">
        <p> <strong>
          <?php 
        _e($message, ORDERLY_DOMAIN);
        ?>
          </strong> </p>
      </div>
      <?php 
    }
    ?>
      <?php 
    if ($loop->have_posts()) {
        ?>
      <div class="wpc-headings">
        <h3>Order Products</h3>
      </div>
      <div class="wpc-inner">
        <p class="description"><?php 
        _e('Drag and drop items to customise the order of products in WP Catalogue', 'wpc');
        ?>
 </p>
        <form name="orderly-order-form" method="post" action="">
          <ul class="orderly-items orderly-sortable">
            <?php 
        $i = 1;
        while ($loop->have_posts()) {
            $loop->the_post();
            ?>
            <li id="orderly-item-<?php 
            echo the_ID();
            ?>
" class="<?php 
            echo $i % 2 == 0 ? 'alternate ' : '';
            ?>
ui-state-default"> <span class="orderly-index"><?php 
            echo $i;
            ?>
.</span> <?php 
            echo the_title();
            ?>
              <input type="hidden" value="<?php 
            echo the_ID();
            ?>
" name="orderly_values[]" id="orderly_values_<?php 
            echo $i;
            ?>
"/>
            </li>
            <?php 
            $i++;
        }
        ?>
          </ul>
          <p>
            <input type="submit" name="Submit" class="button-primary" value="<?php 
        esc_attr_e("Save Order", ORDERLY_DOMAIN);
        ?>
"/>
          </p>
        </form>
        <?php 
    } else {
        ?>
        <p>
          <?php 
        $label = strtolower($post_type_object->labels->name);
        ?>
          <?php 
        _e("There doesn't seem to be any {$label} yet. Click below to add one.", ORDERLY_DOMAIN);
        ?>
        </p>
        <p> <a href="<?php 
        echo admin_url("post-new.php?post_type={$post_type}");
        ?>
" class="button-primary">
          <?php 
        _e("Add {$post_type_object->labels->singular_name}", ORDERLY_DOMAIN);
        ?>
          </a> </p>
        <?php 
    }
    ?>
      </div>
    </div>
  </div>
  <div class="wpc-right-liquid">
    <table cellpadding="0" class="widefat donation" style="margin-bottom:10px; border:solid 2px #008001;" width="50%">
      <thead>
      <th scope="col"><strong style="color:#008001;"><?php 
    _e('Help Improve This Plugin!', 'wpc');
    ?>
</strong></th>
          </thead>
      <tbody>
        <tr>
          <td style="border:0;"><?php 
    _e('Enjoyed this plugin? All donations are used to improve and further develop this plugin. Thanks for your contributaion.', 'wpc');
    ?>
</td>
        </tr>
        <tr>
          <td style="border:0;"><form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
              <input type="hidden" name="cmd" value="_s-xclick">
              <input type="hidden" name="hosted_button_id" value="A74K2K689DWTY">
              <input type="image" src="https://www.paypalobjects.com/en_AU/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
              <img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1">
            </form></td>
        </tr>
        <tr>
          <td style="border:0;"><?php 
    _e('you can also help by', 'wpc');
    ?>
 <a href="http://wordpress.org/plugins/wp-catalogue/"><?php 
    _e('rating this plugin on wordpress.org', 'wpc');
    ?>
</a></td>
        </tr>
      </tbody>
    </table>
    <table cellpadding="0" class="widefat" border="0">
      <thead>
      <th scope="col">Need Support</th>
          </thead>
      <tbody>
        <tr>
          <td style="border:0;"><?php 
    _e('If you are having problems with plugin please talk about them on ', 'wpc');
    ?>
<a href="http://wordpress.org/support/plugin/wp-catalogue">Support Forums</a></td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
<?php 
}
Ejemplo n.º 4
0
function customtaxorder()
{
    global $customtaxorder_settings, $sitepress;
    if (function_exists('current_user_can') && !current_user_can('manage_categories')) {
        die(__('Cheatin&#8217; uh?', 'custom-taxonomy-order-ne'));
    }
    customtaxorder_update_settings();
    $options = $customtaxorder_settings;
    $settings = '';
    // The input and text for the taxonomy that's shown
    $parent_ID = 0;
    // Remove filter for WPML
    remove_filter('terms_clauses', array($sitepress, 'terms_clauses'), 10, 4);
    remove_filter('get_terms', array($sitepress, 'get_terms_filter'));
    if ($_GET['page'] == 'customtaxorder') {
        ?>
		<h1>Custom Taxonomy Order NE</h1>
		<div class="order-widget">
			<p><?php 
        _e('The ordering of categories and custom taxonomy terms through a simple drag-and-drop interface.', 'custom-taxonomy-order-ne');
        ?>
</p>
		<?php 
        $args = array('public' => true);
        $output = 'objects';
        $taxonomies = get_taxonomies($args, $output);
        // Also make the link_category available if activated.
        $linkplugin = "link-manager/link-manager.php";
        include_once ABSPATH . 'wp-admin/includes/plugin.php';
        if (is_plugin_active($linkplugin)) {
            $args = array('name' => 'link_category');
            $taxonomies2 = get_taxonomies($args, $output);
            $taxonomies = array_merge($taxonomies, $taxonomies2);
        }
        if (!empty($taxonomies)) {
            echo "<h2>" . __('Taxonomies', 'custom-taxonomy-order-ne') . "</h2><ul>";
            foreach ($taxonomies as $taxonomy) {
                echo '<li class="lineitem"><a href="' . admin_url('admin.php?page=customtaxorder-' . $taxonomy->name) . '">' . $taxonomy->label . '</a></li>';
            }
        }
        echo "</ul></div>";
        return;
    } else {
        $args = array('public' => true);
        $output = 'objects';
        $taxonomies = get_taxonomies($args, $output);
        // Also make the link_category available if activated.
        $linkplugin = "link-manager/link-manager.php";
        include_once ABSPATH . 'wp-admin/includes/plugin.php';
        if (is_plugin_active($linkplugin)) {
            $args = array('name' => 'link_category');
            $taxonomies2 = get_taxonomies($args, $output);
            $taxonomies = array_merge($taxonomies, $taxonomies2);
        }
        if (!empty($taxonomies)) {
            foreach ($taxonomies as $taxonomy) {
                $com_page = 'customtaxorder-' . $taxonomy->name;
                if (!isset($options[$taxonomy->name])) {
                    $options[$taxonomy->name] = 0;
                    // default if not set in options yet
                }
                if ($_GET['page'] == $com_page) {
                    $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="0" ' . checked('0', $options[$taxonomy->name], false) . ' /> ' . __('Order by ID (default).', 'custom-taxonomy-order-ne') . '</label><br />';
                    $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="1" ' . checked('1', $options[$taxonomy->name], false) . ' /> ' . __('Custom Order as defined above.', 'custom-taxonomy-order-ne') . '</label><br />';
                    $settings .= '<label><input type="radio" name="customtaxorder_settings[' . $taxonomy->name . ']" value="2" ' . checked('2', $options[$taxonomy->name], false) . ' /> ' . __('Alphabetical Order.', 'custom-taxonomy-order-ne') . '</label><br />';
                    $tax_label = $taxonomy->label;
                    $tax = $taxonomy->name;
                } else {
                    if (!isset($options[$taxonomy->name])) {
                        $options[$taxonomy->name] = 0;
                        // default if not set in options yet
                    }
                    $settings .= '<input name="customtaxorder_settings[' . $taxonomy->name . ']" type="hidden" value="' . $options[$taxonomy->name] . '" />';
                }
            }
        }
    }
    $parent_ID_order = 0;
    if (isset($_POST['go-sub-posts'])) {
        $parent_ID = $_POST['sub-posts'];
    } elseif (isset($_POST['hidden-parent-id'])) {
        $parent_term = get_term($_POST['hidden-parent-id'], $tax);
        $parent_ID = $_POST['hidden-parent-id'];
        if (is_object($parent_term) && isset($parent_term->term_order)) {
            $parent_ID_order = $parent_term->term_order;
        }
    }
    if (isset($_POST['return-sub-posts'])) {
        $parent_term = get_term($_POST['hidden-parent-id'], $tax);
        $parent_ID = $parent_term->parent;
    }
    $message = "";
    if (isset($_POST['order-submit'])) {
        customtaxorder_update_order();
    }
    ?>
<div class='wrap'>
	<?php 
    screen_icon('customtaxorder');
    ?>
	<h1><?php 
    echo __('Order ', 'custom-taxonomy-order-ne') . $tax_label;
    ?>
</h1>
	<form name="custom-order-form" method="post" action="">
		<?php 
    $args = array('orderby' => 'term_order', 'order' => 'ASC', 'hide_empty' => false, 'parent' => $parent_ID);
    $terms = get_terms($tax, $args);
    if ($terms) {
        usort($terms, 'customtax_cmp');
        ?>
			<div id="poststuff" class="metabox-holder">
				<div class="widget order-widget">
					<h2 class="widget-top"><?php 
        _e($tax_label);
        ?>
 | <small><?php 
        _e('Order the taxonomies by dragging and dropping them into the desired order.', 'custom-taxonomy-order-ne');
        ?>
</small></h2>
					<div class="misc-pub-section">
						<ul id="custom-order-list">
							<?php 
        foreach ($terms as $term) {
            ?>
							<li id="id_<?php 
            echo $term->term_id;
            ?>
" class="lineitem"><?php 
            echo $term->name;
            ?>
</li>
							<?php 
        }
        ?>
						</ul>
					</div>
					<div class="misc-pub-section misc-pub-section-last">
						<?php 
        if ($parent_ID != 0) {
            ?>
							<input type="submit" class="button" style="float:left" id="return-sub-posts" name="return-sub-posts" value="<?php 
            _e('Return to Parent', 'custom-taxonomy-order-ne');
            ?>
" />
						<?php 
        }
        ?>
						<div id="publishing-action">
							<img src="<?php 
        echo esc_url(admin_url('images/wpspin_light.gif'));
        ?>
" id="custom-loading" style="display:none" alt="" />
							<input type="submit" name="order-submit" id="order-submit" class="button-primary" value="<?php 
        _e('Update Order', 'custom-taxonomy-order-ne');
        ?>
" />
							<input type="submit" name="order-alpha" id="order-alpha" class="button" value="<?php 
        _e('Sort Alphabetical', 'custom-taxonomy-order-ne');
        ?>
" />
						</div>
						<div class="clear"></div>
					</div>
					<input type="hidden" id="hidden-custom-order" name="hidden-custom-order" />
					<input type="hidden" id="hidden-parent-id" name="hidden-parent-id" value="<?php 
        echo $parent_ID;
        ?>
" />
					<input type="hidden" id="hidden-parent-id-order" name="hidden-parent-id-order" value="<?php 
        echo $parent_ID_order;
        ?>
" />
				</div>
				<?php 
        $dropdown = customtaxorder_sub_query($terms, $tax);
        if (!empty($dropdown)) {
            ?>
				<div class="widget order-widget">
					<h2 class="widget-top"><?php 
            print __('Sub-', 'custom-taxonomy-order-ne') . $tax_label;
            ?>
 | <small><?php 
            _e('Choose a term from the drop down to order its sub-terms.', 'custom-taxonomy-order-ne');
            ?>
</small></h2>
					<div class="misc-pub-section misc-pub-section-last">
						<select id="sub-posts" name="sub-posts">
							<?php 
            echo $dropdown;
            ?>
						</select>
						<input type="submit" name="go-sub-posts" class="button" id="go-sub-posts" value="<?php 
            _e('Order Sub-terms', 'custom-taxonomy-order-ne');
            ?>
" />
					</div>
				</div>
				<?php 
        }
        ?>
			</div>
		<?php 
    } else {
        ?>
			<p><?php 
        _e('No terms found', 'custom-taxonomy-order-ne');
        ?>
</p>
		<?php 
    }
    ?>
	</form>
	<form method="post" action="options.php" class="clear">
		<?php 
    settings_fields('customtaxorder_settings');
    ?>
		<div class="metabox-holder">
			<div class="order-widget">
				<h2 class="widget-top"><?php 
    _e('Settings', 'custom-taxonomy-order-ne');
    ?>
</h2>
				<table class="form-table">
					<tr valign="top">
						<th scope="row"><?php 
    _e('Auto-Sort Queries of this Taxonomy', 'custom-taxonomy-order-ne');
    ?>
</th>
					</tr>
					<tr valign="top">
						<td><?php 
    echo $settings;
    ?>
</td>
					</tr>
				</table>
				<input type="hidden" name="customtaxorder_settings[update]" value="Updated" />
				<p class="submit">
					<input type="submit" class="button-primary" value="<?php 
    _e('Save Settings', 'custom-taxonomy-order-ne');
    ?>
" />
				</p>
			</div>
		</div>
	</form>
</div>
<?php 
    if ($terms) {
        ?>
<script type="text/javascript">
// <![CDATA[

	jQuery(document).ready(function(jQuery) {
		jQuery("#custom-loading").hide();
		jQuery("#order-submit").click(function() {
			orderSubmit();
		});
		jQuery("#order-alpha").click(function(e) {
			e.preventDefault();
			jQuery("#custom-loading").show();
			orderAlpha();
			//jQuery("#order-submit").trigger("click");
			setTimeout(function(){
				jQuery("#custom-loading").hide();
			},500);
			jQuery("#order-alpha").blur();
		});
	});

	function customtaxorderAddLoadEvent(){
		jQuery("#custom-order-list").sortable({
			placeholder: "sortable-placeholder",
			revert: false,
			tolerance: "pointer"
		});
	};

	addLoadEvent(customtaxorderAddLoadEvent);

	function orderSubmit() {
		var newOrder = jQuery("#custom-order-list").sortable("toArray");
		jQuery("#custom-loading").show();
		jQuery("#hidden-custom-order").val(newOrder);
		return true;
	}

	function orderAlpha() {
		jQuery("#custom-order-list li").sort(asc_sort).appendTo('#custom-order-list');
		var newOrder = jQuery("#custom-order-list").sortable("toArray");
		jQuery("#custom-loading").show();
		jQuery("#hidden-custom-order").val(newOrder);
		return true;
	}

	// accending sort
	function asc_sort(a, b) {
		//return (jQuery(b).text()) < (jQuery(a).text()) ? 1 : -1;
		//console.log (jQuery(a).text());
		return jQuery(a).text().toUpperCase().localeCompare(jQuery(b).text().toUpperCase());
	}

// ]]>
</script>
<?php 
    }
}