MIT License, Copyright 2005 Owen Winkler. Version: 3.2 Author: Owen Winkler Author URI: http://www.asymptomatic.net */ /* Adhesive - Allows easy marking of sticky posts in WordPress. Copyright (c) 2005 Owen Winkler Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* INSTRUCTIONS: Please see this web page for more information: http://redalt.com/wiki/Adhesive */ if(!function_exists('adhesive_include_up')) { function adhesive_include_up($filename) { $c=0; while(!is_file($filename)) { $filename = '../' . $filename; $c++; if($c==30) { echo 'Could not find ' . basename($filename) . '.'; return ''; } } return $filename; } } // End Options--- if(!defined('ABSPATH')) { // Things to do when the file is called solo include(adhesive_include_up('wp-config.php')); $adhesive_options = get_settings('adhesive'); if($adhesive_options == '') { $adhesive_options = array( 'display_date' => false, 'date_banner' => '

Important Message!

', 'category_only' => false, ); update_option('adhesive', $adhesive_options); } if(isset($_POST['config'])) { // Things to do when the Ajax gets ya include_once(ABSPATH.'/wp-admin/admin-functions.php'); ?>
false, 'date_banner' => '

Important Message!

', 'category_only' => false, ); update_option('adhesive', $adhesive_options); } return $name == ''? $adhesive_options : $adhesive_options[$name]; } function adhesive_posts_where($where) { if(!adhesive_get_options('category_only') || is_category()) $where = ' AND 0=1 ' . $where; return $where; } function adhesive_the_posts($posts) { global $wpdb, $adhesive_metakey, $wp_query, $request, $q; if(!adhesive_get_options('category_only') || is_category()) { $qry = "SELECT {$wpdb->postmeta}.Post_ID FROM {$wpdb->postmeta} WHERE meta_key = '{$adhesive_metakey}' AND meta_value = '1'"; if($stickies = $wpdb->get_col($qry)) { $insticky = 'not (ID in (' . implode(',', $stickies) . ')),'; } else { $insticky = ''; $stickies = array(); } if($request == '') $request = $wp_query->request; $request = str_replace(' AND 0=1 ', '', $request); $wp_query->request = $request; $request = preg_replace("/ORDER BY post_{$q['orderby']}/", "ORDER BY {$insticky} post_{$q['orderby']}", $request); unset($posts); $posts = array(); if($foo = $wpdb->get_results($request)) { foreach($foo as $post) { $post->is_sticky = (in_array($post->ID, $stickies)); array_push($posts, $post); } } } return $posts; } function adhesive_admin_footer($content) { global $wpdb, $exc, $adhesive_metakey; // Are we on the right page? if(preg_match('|post.php|i', $_SERVER['REQUEST_URI'])) { if(isset($_REQUEST['post'])) { $stickiness = $wpdb->get_var("SELECT meta_value FROM {$wpdb->postmeta} WHERE Post_ID = {$_REQUEST['post']} AND meta_key = '{$adhesive_metakey}';"); $checked = ('1' == $stickiness)?' checked="checked"':''; } ?>
'; } } function adhesive_edit_post($id) { global $wpdb, $adhesive_metakey; if(!isset($id)) $id= $_REQUEST['post_ID']; if(isset($_REQUEST['adhesive_sticky'])) { $qry = "DELETE FROM {$wpdb->postmeta} WHERE Post_ID = {$id} AND meta_key = '{$adhesive_metakey}';"; $wpdb->query($qry); $qry = "INSERT INTO {$wpdb->postmeta} (Post_ID, meta_key, meta_value) VALUES ({$id}, '{$adhesive_metakey}', '1');"; $wpdb->query($qry); } else { $qry = "DELETE FROM {$wpdb->postmeta} WHERE Post_ID = {$id} AND meta_key = '{$adhesive_metakey}';"; $wpdb->query($qry); } } function adhesive_the_content($content) { global $post; return ($post->is_sticky) ? "{$content}" : $content; } function adhesive_the_date($content) { global $post, $previousday; if($post->is_sticky && !adhesive_get_options('display_date')) { $previousday=''; return adhesive_get_options('date_banner'); } return $content; } function adhesive_the_title($content) { global $post; return (preg_match('|edit.php|i', $_SERVER['REQUEST_URI']) && ($post->is_sticky)) ? "Sticky:{$content}" : $content; } /* The following functions handle the newfangled admin configuration system */ add_action('admin_head', 'adhesive_admin_head'); if(strstr($_SERVER['REQUEST_URI'], '/wp-admin/plugins.php')) { ob_start('adhesive_capture'); if(isset($_GET['pfile']) && ($_GET['page'] == adhesive_basename(__FILE__))) { // Do something! } } function adhesive_capture($content) { $content = preg_replace_callback('//', 'adhesive_add_link', $content); return $content; } function adhesive_add_link($c) { $replacement = $c[0] . '
' . __('Configure') . ''; return $replacement; } function adhesive_admin_head($unused) { if(preg_match('/(plugins.php)/i', $_SERVER['REQUEST_URI'])) { ?>

Configure Adhesive

" . __("Configuration updated.") . ""; $adhesive_options = array( 'display_date' => isset($_POST['display_date']), 'date_banner' => $_POST['date_banner'], 'category_only' => isset($_POST['category_only']), ); update_option('adhesive', $adhesive_options); } ?>
Causes Adhesive to display sticky posts only when viewing categories, and not also on the home page.
/>
Causes Adhesive to display the date instead of the date banner on sticky posts.
/>
This banner is displayed instead of the date in themes that display the date for each post.