function mycategoryorder_set_plugin_meta($links, $file) { $plugin = plugin_basename(__FILE__); // create link if ($file == $plugin) { return array_merge($links, array('<a href="' . mycategoryorder_getTarget() . '">' . __('Order Categories', 'mycategoryorder') . '</a>', '<a href="http://wordpress.org/tags/my-category-order?forum_id=10#postform">' . __('Support Forum') . '</a>', '<a href="http://geekyweekly.com/gifts-and-donations">' . __('Donate') . '</a>')); } return $links; }
function mycategoryorder() { global $wpdb; $parentID = 0; $wpdb->show_errors(); $query1 = $wpdb->query("SHOW COLUMNS FROM {$wpdb->terms} LIKE 'term_order'"); if ($query1 == 0) { $wpdb->query("ALTER TABLE {$wpdb->terms} ADD `term_order` INT( 4 ) NULL DEFAULT '0'"); } if (isset($_POST['btnSubCats'])) { $parentID = $_POST['cats']; } elseif (isset($_POST['hdnParentID'])) { $parentID = $_POST['hdnParentID']; } if (isset($_POST['btnReturnParent'])) { $parentsParent = $wpdb->get_row("SELECT parent FROM {$wpdb->term_taxonomy} WHERE term_id = " . $_POST['hdnParentID'], ARRAY_N); $parentID = $parentsParent[0]; } if (isset($_GET['hideNote'])) { update_option('mycategoryorder_hideNote', '1'); } $success = ""; if (isset($_POST['btnOrderCats'])) { $success = mycategoryorder_updateOrder(); } $subCatStr = mycategoryorder_getSubCats($parentID); ?> <div class='wrap'> <form name="frmMyCatOrder" method="post" action=""> <h2><?php _e('My Category Order', 'mycategoryorder'); ?> </h2> <?php echo $success; if (get_option("mycategoryorder_hideNote") != "1") { ?> <div class="updated"> <strong><p><?php _e('If you like my plugin please consider donating. Every little bit helps me provide support and continue development.', 'mycategoryorder'); ?> <a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mycategoryorder'); ?> </a> <small><a href="<?php echo mycategoryorder_getTarget(); ?> &hideNote=true"><?php _e('No thanks, hide this', 'mycategoryorder'); ?> </a></small></p></strong> </div> <?php } ?> <p><?php _e('Choose a category from the drop down to order subcategories in that category or order the categories on this level by dragging and dropping them into the desired order.', 'mycategoryorder'); ?> </p> <?php if ($subCatStr != "") { ?> <h3><?php _e('Order Subcategories', 'mycategoryorder'); ?> </h3> <select id="cats" name="cats"> <?php echo $subCatStr; ?> </select> <input type="submit" name="btnSubCats" class="button" id="btnSubCats" value="<?php _e('Order Subcategories', 'mycategoryorder'); ?> " /> <?php } ?> <h3><?php _e('Order Categories', 'mycategoryorder'); ?> </h3> <ul id="myCategoryOrderList"> <?php $results = mycategoryorder_catQuery($parentID); foreach ($results as $row) { echo "<li id='id_{$row->term_id}' class='lineitem'>" . __($row->name) . "</li>"; } ?> </ul> <input type="submit" name="btnOrderCats" id="btnOrderCats" class="button-primary" value="<?php _e('Click to Order Categories', 'mycategoryorder'); ?> " onclick="javascript:orderCats(); return true;" /> <?php echo mycategoryorder_getParentLink($parentID); ?> <strong id="updateText"></strong> <br /><br /> <p> <a href="http://geekyweekly.com/mycategoryorder"><?php _e('Plugin Homepage', 'mycategoryorder'); ?> </a> | <a href="http://geekyweekly.com/gifts-and-donations"><?php _e('Donate', 'mycategoryorder'); ?> </a> | <a href="http://wordpress.org/tags/my-category-order?forum_id=10"><?php _e('Support Forum', 'mycategoryorder'); ?> </a> </p> <input type="hidden" id="hdnMyCategoryOrder" name="hdnMyCategoryOrder" /> <input type="hidden" id="hdnParentID" name="hdnParentID" value="<?php echo $parentID; ?> " /> </form> </div> <style type="text/css"> #myCategoryOrderList { width: 90%; border:1px solid #B2B2B2; margin:10px 10px 10px 0px; padding:5px 10px 5px 10px; list-style:none; background-color:#fff; -moz-border-radius:3px; -webkit-border-radius:3px; } li.lineitem { border:1px solid #B2B2B2; -moz-border-radius:3px; -webkit-border-radius:3px; background-color:#F1F1F1; color:#000; cursor:move; font-size:13px; margin-top:5px; margin-bottom:5px; padding: 2px 5px 2px 5px; height:1.5em; line-height:1.5em; } .sortable-placeholder{ border:1px dashed #B2B2B2; margin-top:5px; margin-bottom:5px; padding: 2px 5px 2px 5px; height:1.5em; line-height:1.5em; } </style> <script type="text/javascript"> // <![CDATA[ function mycategoryrderaddloadevent(){ jQuery("#myCategoryOrderList").sortable({ placeholder: "sortable-placeholder", revert: false, tolerance: "pointer" }); }; addLoadEvent(mycategoryrderaddloadevent); function orderCats() { jQuery("#updateText").html("<?php _e('Updating Category Order...', 'mycategoryorder'); ?> "); jQuery("#hdnMyCategoryOrder").val(jQuery("#myCategoryOrderList").sortable("toArray")); } // ]]> </script> <?php }
function mycategoryorder() { global $wpdb; $mode = ""; $mode = $_GET['mode']; $parentID = 0; $success = ""; if (isset($_GET['parentID'])) { $parentID = $_GET['parentID']; } $wpdb->show_errors(); $query1 = $wpdb->query("SHOW COLUMNS FROM {$wpdb->terms} LIKE 'term_order'"); if ($query1 == 0) { $wpdb->query("ALTER TABLE {$wpdb->terms} ADD `term_order` INT( 4 ) NULL DEFAULT '0'"); } if ($mode == "act_OrderCategories") { $idString = $_GET['idString']; $catIDs = explode(",", $idString); $result = count($catIDs); for ($i = 0; $i < $result; $i++) { $wpdb->query("UPDATE {$wpdb->terms} SET term_order = '{$i}' WHERE term_id ='{$catIDs[$i]}'"); } $success = '<div id="message" class="updated fade"><p>' . __('Categories updated successfully.', 'mycategoryorder') . '</p></div>'; } $subCatStr = ""; $results = $wpdb->get_results("SELECT t.term_id, t.name FROM {$wpdb->term_taxonomy} tt, {$wpdb->terms} t, {$wpdb->term_taxonomy} tt2 WHERE tt.parent = {$parentID} AND tt.taxonomy = 'category' AND t.term_id = tt.term_id AND tt2.parent = tt.term_id GROUP BY t.term_id, t.name HAVING COUNT(*) > 0 ORDER BY t.term_order ASC"); foreach ($results as $row) { $subCatStr = $subCatStr . "<option value='{$row->term_id}'>{$row->name}</option>"; } ?> <div class='wrap'> <?php echo $success; ?> <?php mycategoryorder_check_taxonomy_file(); ?> <h2><?php _e('My Category Order', 'mycategoryorder'); ?> </h2> <p><?php _e('Choose a category from the drop down to order subcategories in that category or order the categories on this level by dragging and dropping them into the desired order.', 'mycategoryorder'); ?> </p> <?php if ($parentID != 0) { $parentsParent = $wpdb->get_row("SELECT parent FROM {$wpdb->term_taxonomy} WHERE term_id = {$parentID} ", ARRAY_N); echo "<a href='" . mycategoryorder_getTarget() . "?page=mycategoryorder&parentID={$parentsParent['0']}'>" . __('Return to parent category', 'mycategoryorder') . "</a>"; } if ($subCatStr != "") { ?> <h3><?php _e('Order Subcategories', 'mycategoryorder'); ?> </h3> <select id="cats" name="cats"> <?php echo $subCatStr; ?> </select> <input type="button" name="edit" Value="<?php _e('Order Subcategories', 'mycategoryorder'); ?> " onClick="javascript:goEdit();"> <?php } $results = $wpdb->get_results("SELECT * FROM {$wpdb->terms} t inner join {$wpdb->term_taxonomy} tt on t.term_id = tt.term_id WHERE taxonomy = 'category' and parent = {$parentID} ORDER BY term_order ASC"); ?> <h3><?php _e('Order Categories', 'mycategoryorder'); ?> </h3> <ul id="order" style="width: 500px; margin:10px 10px 10px 0px; padding:10px; border:1px solid #B2B2B2; list-style:none;"> <?php foreach ($results as $row) { echo "<li id='{$row->term_id}' class='lineitem'>{$row->name}</li>"; } ?> </ul> <input type="button" id="orderButton" Value="<?php _e('Click to Order Categories', 'mycategoryorder'); ?> " onclick="javascript:orderCats();"> <strong id="updateText"></strong> </div> <style> li.lineitem { margin: 3px 0px; padding: 2px 5px 2px 5px; background-color: #F1F1F1; border:1px solid #B2B2B2; cursor: move; width: 490px; } </style> <script language="JavaScript"> function mycategoryrderaddloadevent(){ jQuery("#order").sortable({ placeholder: "ui-selected", revert: false, tolerance: "pointer" }); }; addLoadEvent(mycategoryrderaddloadevent); function orderCats() { jQuery("#orderButton").css("display", "none"); jQuery("#updateText").html("<?php _e('Updating Category Order...', 'mycategoryorder'); ?> "); idList = jQuery("#order").sortable("toArray"); location.href = '<?php echo mycategoryorder_getTarget(); ?> ?page=mycategoryorder&mode=act_OrderCategories&parentID=<?php echo $parentID; ?> &idString='+idList; } function goEdit () { if(jQuery("#cats").val() != "") location.href="<?php echo mycategoryorder_getTarget(); ?> ?page=mycategoryorder&parentID="+jQuery("#cats").val(); } </script> <?php }