All pastes #87839 Raw Edit

Stuff

public php v1 · immutable
·published 2006-07-14 07:07 UTC
rendered paste body
<?php/*Plugin Name: AdhesivePlugin URI: http://www.asymptomatic.net/wp-hacksDescription: Allows easy marking of sticky posts in WordPress 2.0.  Licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a>, Copyright 2005 Owen Winkler.Version: 3.2Author: Owen WinklerAuthor URI: http://www.asymptomatic.net*//*Adhesive - Allows easy marking of sticky posts in WordPress.Copyright (c) 2005 Owen WinklerPermission is hereby granted, free of charge, to any personobtaining a copy of this software and associateddocumentation files (the "Software"), to deal in theSoftware without restriction, including without limitationthe 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 todo so, subject to the following conditions:The above copyright notice and this permission notice shallbe included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANYKIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THEWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULARPURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORSOR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE 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 soloinclude(adhesive_include_up('wp-config.php'));$adhesive_options = get_settings('adhesive');if($adhesive_options == '') {$adhesive_options = array('display_date' => false,'date_banner' => '<h1>Important Message!</h1>','category_only' => false,);update_option('adhesive', $adhesive_options);}if(isset($_POST['config'])) {// Things to do when the Ajax gets yainclude_once(ABSPATH.'/wp-admin/admin-functions.php');?><div style="padding:5px;"><?phpadhesive_options_form();?>		</div><?php} else {// Things to do without Ajax}die();};// Things to do when the file is included as a pluginfunction adhesive_basename($file) {return preg_replace('/^.*wp-content[\\/]plugins[\\/]/', '', $file);}// Don't change below here.add_filter('the_posts', 'adhesive_the_posts');add_filter('posts_where', 'adhesive_posts_where');add_filter('admin_footer', 'adhesive_admin_footer');add_filter('edit_post', 'adhesive_edit_post');add_filter('publish_post', 'adhesive_edit_post');add_filter('the_content', 'adhesive_the_content', 15);add_filter('the_title', 'adhesive_the_title');add_filter('admin_menu', 'adhesive_admin_menu');// Delete the following line to display the date on sticky postsadd_filter('the_date', 'adhesive_the_date', 15);$adhesive_metakey = 'sticky';function adhesive_get_options($name = '') {$adhesive_options = get_settings('adhesive');if($adhesive_options == '') {$adhesive_options = array('display_date' => false,'date_banner' => '<h1>Important Message!</h1>','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"':'';}?><div id="adhesivediv"><label class="selectit"><input type="checkbox" name="adhesive_sticky" value="true"<?php echo $checked; ?> /> Sticky</label></div><?phpecho '<script language="JavaScript" type="text/javascript"><!--var placement = document.getElementById("post_status_private");var substitution = document.getElementById("adhesivediv");var mozilla = document.getElementById&&!document.all;if(mozilla)placement.parentNode.parentNode.appendChild(substitution);else placement.parentElement.parentElement.appendChild(substitution);//--></script>';}}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) ?"<script type="text/javascript">window.document.getElementById('post-{$post->ID}').parentNode.className += ' adhesive_post';</script>{$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)) ?"<strong>Sticky:</strong>{$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('/<a href='plugins\.php\?action=deactivate&amp;plugin=.*?' . basename(__FILE__) . '.*?Deactivate</a>/', 'adhesive_add_link', $content);return $content;}function adhesive_add_link($c) {