PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/postmash-filtered/postMash.php

https://gitlab.com/Gashler/sg
PHP | 345 lines | 243 code | 55 blank | 47 comment | 45 complexity | 703525aca7582a69b2268f19ab516886 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: postMash (Filter)
  4. Plugin URI: http://postmashfiltered.wordpress.com/2009/06/19/post-mash-filtered/
  5. Description: postMash > Order Posts. Allow admin panel to filter by category/date. Allow Next/Previous posts by postMash order. Based on <a href="http://joelstarnes.co.uk" >Joel Starnes</a> postMash
  6. Author: Selwyn Nogood
  7. Version: 1.2.1
  8. Author URI: http://postmashfiltered.wordpress.com
  9. */
  10. #########CONFIG OPTIONS############################################
  11. $minlevel = 7; /*[deafult=7]*/
  12. /* Minimum user level to access page order */
  13. $switchDraftToPublishFeature = true; /*[deafult=true]*/
  14. /* Allows you to set pages not to be listed */
  15. $ShowDegubInfo = false; /*[deafult=false]*/
  16. /* Show server response debug info */
  17. ###################################################################
  18. /*
  19. INSPIRATIONS/CREDITS:
  20. Joel Starnes - This plugin is a modification of Joel Starnes great postMash plugin [http://joelstarnes.co.uk/postMash/]
  21. Valerio Proietti - Mootools JS Framework [http://mootools.net/]
  22. Stefan Lange-Hegermann - Mootools AJAX timeout class extension [http://www.blackmac.de/archives/44-Mootools-AJAX-timeout.html]
  23. vladimir - Mootools Sortables class extension [http://vladimir.akilles.cl/scripts/sortables/]
  24. ShiftThis - WP Page Order Plugin [http://www.shiftthis.net/wordpress-order-pages-plugin/]
  25. Garrett Murphey - Page Link Manager [http://gmurphey.com/2006/10/05/wordpress-plugin-page-link-manager/]
  26. */
  27. /* Copyright 2008 Selwyn Nogood (email : editor@kiwianarama.co.nz)
  28. This program is free software; you can redistribute it and/or modify
  29. it under the terms of the GNU General Public License as published by
  30. the Free Software Foundation; either version 2 of the License, or
  31. (at your option) any later version.
  32. This program is distributed in the hope that it will be useful,
  33. but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. GNU General Public License for more details.
  36. You should have received a copy of the GNU General Public License
  37. along with this program; if not, write to the Free Software
  38. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  39. */
  40. // Pre-2.6 compatibility
  41. if ( !defined('WP_CONTENT_URL') )
  42. define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  43. if ( !defined('WP_CONTENT_DIR') )
  44. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  45. // Guess the location
  46. $codeWord_path = WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__));
  47. $postMash_url = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__));
  48. function postMash_getPages(){
  49. global $wpdb, $wp_version, $switchDraftToPublishFeature;
  50. //get pages from database
  51. $date = $_GET['m'];
  52. $mmonth = substr($date, -2);
  53. $yyear = substr($date, 0, 4);
  54. $query_post .= "SELECT * FROM $wpdb->posts ";
  55. if (isset($_GET['cat']) && $_GET['cat'] != '0'){
  56. $query_post .= "INNER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
  57. INNER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
  58. WHERE $wpdb->term_taxonomy.term_id = " . $_GET['cat'] ;
  59. if (isset($_GET['m']) && $_GET['m'] != '0' ) {$query_post .= " AND YEAR($wpdb->posts.post_date) = " . $yyear ." AND MONTH($wpdb->posts.post_date) = " . $mmonth ;}
  60. $query_post .= " AND $wpdb->posts.post_type = 'post' ORDER BY menu_order ";
  61. }
  62. else {
  63. $query_post .= "WHERE post_type = 'post'";
  64. if (isset($_GET['m']) && $_GET['m'] != '0') {$query_post .= " AND YEAR(post_date) = " . $yyear ." AND MONTH(post_date) = " . $mmonth ;}
  65. $query_post .= " ORDER BY menu_order " ;}
  66. $pageposts = $wpdb->get_results("$query_post");
  67. if ($pageposts == true){
  68. echo '<ul id="postMash_pages">';
  69. foreach ($pageposts as $page): //list pages, [the 'li' ID must be pm_'page ID'] ?>
  70. <li id="pm_<?php echo $page->ID; ?>"<?php if($page->post_status == "draft"){ echo ' class="remove"'; } //if page is draft, add class remove ?>>
  71. <span style="float:right;">
  72. <?php
  73. $tags = get_the_tags($page->ID);
  74. if ( !empty( $tags ) ) {
  75. $out = array();
  76. foreach ( $tags as $c )
  77. $out[] = wp_specialchars(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display'));
  78. echo join( ', ', $out );
  79. } else {
  80. _e('');
  81. } ?></span><span class="title"><?php echo $page->post_title;?></span>
  82. <span class="postMash_box">
  83. <span class="postMash_more">&raquo;</span>
  84. <span class="postMash_pageFunctions">
  85. id:<?php echo $page->ID;?>
  86. [<a href="<?php echo get_bloginfo('wpurl').'/wp-admin/post.php?action=edit&post='.$page->ID; ?>" title="Edit This Post">edit</a>]
  87. <?php if($switchDraftToPublishFeature): ?>
  88. [<a href="#" title="Draft|Publish" class="excludeLink" onclick="toggleRemove(this); return false">toggle-draft</a>]
  89. <?php endif; ?>
  90. </span>
  91. </span>
  92. </li>
  93. <?php endforeach;
  94. echo '</ul>';
  95. return true;
  96. } else {
  97. echo '<h3 style="margin-top:30px;" >Sorry, there is nothing for this month!</h3>';
  98. return false;
  99. }
  100. }
  101. function postMash_main(){
  102. global $switchDraftToPublishFeature, $ShowDegubInfo;
  103. ?>
  104. <div id="debug_list"<?php if(false==$ShowDegubInfo) echo' style="display:none;"'; ?>></div>
  105. <div id="postMash" class="wrap">
  106. <div id="postMash_checkVersion" style="float:right; font-size:.7em; margin-top:5px;">
  107. version 1.1.0
  108. </div>
  109. <h2 style="margin-bottom:0; clear:none;">postMash: Post Ordering</h2>
  110. <p style="margin-top:4px;">
  111. Just drag the posts <strong>up</strong> or <strong>down</strong> to change their order. <?php echo "The draft button will toggle the page between draft and published states."; ?>
  112. </p><p>
  113. <div class="alignleft actions">
  114. <?php // view filters
  115. if ( !is_singular() ) {
  116. global $wpdb, $wp_locale;
  117. $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC";
  118. $arc_result = $wpdb->get_results( $arc_query );
  119. $month_count = count($arc_result);
  120. if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
  121. $m = isset($_GET['m']) ? (int)$_GET['m'] : 0;
  122. ?>
  123. <form action="" method="get" enctype="multipart/form-data">
  124. <input type="hidden" name="page" value="postmash-filtered/postMash.php" />
  125. <select name='m'>
  126. <option<?php selected( $m, 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
  127. <?php
  128. foreach ($arc_result as $arc_row) {
  129. if ( $arc_row->yyear == 0 )
  130. continue;
  131. $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
  132. if ( $arc_row->yyear . $arc_row->mmonth == $m )
  133. $default = ' selected="selected"';
  134. else
  135. $default = '';
  136. echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
  137. echo $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear";
  138. echo "</option>\n";
  139. }
  140. ?>
  141. </select>
  142. <?php } ?>
  143. <?php
  144. $cat = $_GET['cat'];
  145. $dropdown_options = array('show_option_all' => __('View all categories'), 'hide_empty' => 0, 'hierarchical' => 1,
  146. 'show_count' => 0, 'orderby' => 'name', 'selected' => $cat);
  147. wp_dropdown_categories($dropdown_options);
  148. do_action('restrict_manage_posts');
  149. ?>
  150. <input type="submit" id="post-query-submit" value="<?php _e('Filter'); ?>" class="button-secondary" />
  151. </form>
  152. <?php } ?>
  153. </div>
  154. </p>
  155. <div style="clear:both; height:20px;"> </div>
  156. <?php postMash_getPages(); ?>
  157. <p class="submit">
  158. <div id="update_status" style="float:left; margin-left:40px; opacity:0;"></div>
  159. <input type="submit" id="postMash_submit" tabindex="2" style="font-weight: bold; float:right;" value="Update" name="submit"/>
  160. </p>
  161. <br style="margin-bottom: .8em;" />
  162. </div>
  163. <div class="wrap" style="width:160px; margin-bottom:0; padding:0;"><p><a href="#" id="postMashInfo_toggle">Show|Hide Further Info</a></p></div>
  164. <div class="wrap" id="postMashInfo" style="margin-top:-1px;">
  165. <h2>How to Use</h2>
  166. <p>In order to make use of postMash, you need to order your posts by "menu_order". Like this...</p>
  167. <p style="margin-bottom:0; font-weight:bold;">Code:</p>
  168. <code id="postMash_code"><span class="white">
  169. &lt;?php $readposts = get_posts(&#x27;orderby=menu_order&#x27;); ?&gt;<br />
  170. &lt;ul&gt;<br />
  171. &lt;?php foreach($readposts as $post) : setup_postdata($post); ?&gt;<br />
  172. &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;<br />
  173. &lt;?php endforeach; ?&gt;<br />
  174. &lt;/ul&gt;
  175. </span></code>
  176. <p><a href="http://postmashfiltered.wordpress.com/">Homepage </a></p>
  177. <br />
  178. </div>
  179. <?php
  180. }
  181. function postMash_head(){
  182. //stylesheet & javascript to go in page header
  183. global $postMash_url;
  184. wp_enqueue_script('postMash_mootools', $postMash_url.'/nest-mootools.v1.11.js', false, false); //code is not compatible with other releases of moo
  185. wp_deregister_script('prototype');//remove prototype since it is incompatible with mootools
  186. wp_enqueue_script('postMash', $postMash_url.'/postMash.js', array('postMash_mootools'), false);
  187. add_action('admin_head', 'postMash_add_css', 1);
  188. }
  189. function postMash_add_css(){
  190. global $postMash_url;
  191. printf('<link rel="stylesheet" type="text/css" href="%s/postMash.css" />', $postMash_url);
  192. ?>
  193. <!-- BASED ON
  194. __ __ _
  195. WordPress Plugin | \/ | | |
  196. _ __ __ _ __ _ ___| \ / | __ _ ___| |__
  197. | '_ \/ _` |/ _` |/ _ \ |\/| |/ _` / __| '_ \
  198. | |_) (_| | (_| | __/ | | | (_| \__ \ | | |
  199. | .__/\__,_|\__, |\___|_| |_|\__,_|___/_| |_|
  200. | | __/ | Author: Joel Starnes
  201. |_| |___/ URL: joelstarnes.co.uk
  202. >>postMash Admin Page
  203. -->
  204. <?php
  205. }
  206. function postMash_add_pages(){
  207. //add menu link
  208. global $minlevel, $wp_version;
  209. if($wp_version >= 2.7){
  210. $page = add_submenu_page('edit.php', 'postMash: Order Posts', 'postMash', $minlevel, __FILE__, 'postMash_main');
  211. }else{
  212. $page = add_management_page('postMash: Order Posts', 'postMash', $minlevel, __FILE__, 'postMash_main');
  213. }
  214. add_action("admin_print_scripts-$page", 'postMash_head'); //add css styles and JS code to head
  215. }
  216. add_action('admin_menu', 'postMash_add_pages'); //add admin menu under management tab
  217. /**
  218. * Modifications to allow Next/Previous Post Link by menu_order using postMash plugin.
  219. */
  220. function get_previous_post_menu($in_same_cat = false, $excluded_categories = '') {
  221. return get_adjacent_post_menu($in_same_cat, $excluded_categories);
  222. }
  223. function get_next_post_menu($in_same_cat = false, $excluded_categories = '') {
  224. return get_adjacent_post_menu($in_same_cat, $excluded_categories, false);
  225. }
  226. function previous_post_link_menu($format='&laquo; %link', $link='%title', $in_same_cat = true, $excluded_categories = '') {
  227. adjacent_post_link_menu($format, $link, $in_same_cat, $excluded_categories, false);
  228. }
  229. function next_post_link_menu($format='%link &raquo;', $link='%title', $in_same_cat = true, $excluded_categories = '') {
  230. adjacent_post_link_menu($format, $link, $in_same_cat, $excluded_categories, true);
  231. }
  232. function get_adjacent_post_menu($in_same_cat = false, $excluded_categories = '', $previous = true) {
  233. global $post, $wpdb;
  234. if( empty($post) || !is_single() || is_attachment() )
  235. return null;
  236. $current_post_date = $post->post_date;
  237. $current_menu_order = $post->menu_order;
  238. $join = '';
  239. $posts_in_ex_cats_sql = '';
  240. if ( $in_same_cat || !empty($excluded_categories) ) {
  241. $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
  242. if ( $in_same_cat ) {
  243. $cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
  244. $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
  245. }
  246. $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
  247. if ( !empty($excluded_categories) ) {
  248. $excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
  249. if ( !empty($cat_array) ) {
  250. $excluded_categories = array_diff($excluded_categories, $cat_array);
  251. $posts_in_ex_cats_sql = '';
  252. }
  253. if ( !empty($excluded_categories) ) {
  254. $posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
  255. }
  256. }
  257. }
  258. $adjacent = $previous ? 'previous' : 'next';
  259. $op = $previous ? '<' : '>';
  260. $order = $previous ? 'DESC' : 'ASC';
  261. $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
  262. $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.menu_order $op %s AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_menu_order), $in_same_cat, $excluded_categories );
  263. $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.menu_order $order LIMIT 1" );
  264. return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
  265. }
  266. function adjacent_post_link_menu($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
  267. if ( $previous && is_attachment() )
  268. $post = & get_post($GLOBALS['post']->post_parent);
  269. else
  270. $post = get_adjacent_post_menu($in_same_cat, $excluded_categories, $previous);
  271. if ( !$post )
  272. return;
  273. $title = $post->post_title;
  274. if ( empty($post->post_title) )
  275. $title = $previous ? __('Previous Post') : __('Next Post');
  276. $title = apply_filters('the_title', $title, $post);
  277. $date = mysql2date(get_option('date_format'), $post->post_date);
  278. $string = '<a href="'.get_permalink($post).'">';
  279. $link = str_replace('%title', $title, $link);
  280. $link = str_replace('%date', $date, $link);
  281. $link = $string . $link . '</a>';
  282. $format = str_replace('%link', $link, $format);
  283. $adjacent = $previous ? 'previous' : 'next';
  284. echo apply_filters( "{$adjacent}_post_link", $format, $link );
  285. }
  286. ?>