function wp_redirect($location, $status = 302) { global $is_IIS; $location = apply_filters('wp_redirect', $location, $status); $status = apply_filters('wp_redirect_status', $status, $location); if (!$location) { // allows the wp_redirect filter to cancel a redirect return false; } $location = wp_sanitize_redirect($location); if (!$is_IIS && php_sapi_name() != 'cgi-fcgi') { status_header($status); } // This causes problems on IIS and some FastCGI setups $uri_ext = '/' . WpBoojFindURISegment(); $uri_len = strlen($uri_ext) + 1; if (substr($location, 0, 1) == '/' && substr($location, 0, $uri_len) != $uri_ext) { $location = '/blog' . $location; } header("Location: {$location}", true, $status); }
function proxy_admin_urls() { // Update the HTTP_HOST because wordpress bases urls off of this // We're removing 7 characters, 'http://' so the site_url MUST BE ex: http://www.clarkhawaii.com/ // @todo: Make this more robust for the above reason! $options = get_option('wp-booj'); if ($options['proxy_admin_urls'] == 'on') { if (substr(get_site_url(), 0, 7) == 'http://') { $_SERVER['HTTP_HOST'] = substr(get_site_url(), 7); } else { $_SERVER['HTTP_HOST'] = get_site_url(); } // This updates the remote_addr because of the proxy this would normally get lost if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = trim($ips[0]); } elseif (isset($_SERVER['HTTP_X_REAL_IP']) && !empty($_SERVER['HTTP_X_REAL_IP'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP']; } elseif (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) { $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CLIENT_IP']; } // Update the links we may have missed with this // we catch all urls that start with "/" and put /blog/ ahead ?> <script type="text/javascript"> uri_segment = '<?php echo WpBoojFindURISegment(); ?> '; uri_len = uri_segment.length + 1; jQuery(document).ready( function() { jQuery('a').each( function(){ link = jQuery(this).attr('href'); if( link && link.length && link.substring( 0, 1 ) == '/' && link.substring( 0, uri_len ) != '/' + uri_segment ){ jQuery(this).attr('href', '/' + uri_segment + link ); } }); jQuery('form').each( function(){ action = jQuery(this).attr('action'); if( action && action.length && action.substring( 0, 1 ) == '/' && action.substring( 0, uri_len ) != '/' + uri_segment ){ jQuery(this).attr('action', '/' + uri_segment + action ); } }); }); </script> <?php } }
public static function get_top_posts($count = 5, $months_back = False) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; if (is_plugin_active('wp-postviews/wp-postviews.php')) { global $WpBooj_options; if (isset($WpBooj_options['use_WpBoojCache']) && $WpBooj_options['use_WpBoojCache'] == 'on') { $popular_cache = WpBoojCache::check($post_id = 0, $type = 'WpBoojTopPosts'); if ($popular_cache) { return $popular_cache; } } if ($months_back) { $_1_month = 2678400; $time_back = date('Y-m-d', time() - $_1_month * $months_back); $where_append = ' AND `posts`.`post_date` > "' . $time_back . '" '; } else { $where_append = ''; } global $wpdb; $sql = "SELECT\r\n posts.ID,\r\n meta.meta_value,\r\n posts.post_title,\r\n posts.post_name,\r\n posts.post_date\r\n FROM `{$wpdb->prefix}postmeta` as meta\r\n INNER JOIN `{$wpdb->prefix}posts` as posts\r\n ON `meta`.`post_id` = posts.ID\r\n WHERE `meta`.`meta_key` = 'views' " . $where_append . "\r\n ORDER BY CAST( `meta_value` AS DECIMAL ) DESC\r\n LIMIT " . $count; $posts = $wpdb->get_results($sql); $popular = array(); foreach ($posts as $key => $post) { $popular[$key]['post_id'] = $post->ID; $popular[$key]['post_views'] = $post->meta_value; $popular[$key]['post_title'] = $post->post_title; $popular[$key]['post_slug'] = $post->post_name; $popular[$key]['post_date'] = $post->post_date; $popular[$key]['url'] = '/' . WpBoojFindURISegment() . '/' . date('Y/m/', strtotime($popular[$key]['post_date'])) . $popular[$key]['post_slug']; } if (count($popular) == $count && isset($WpBooj_options['use_WpBoojCache']) && $WpBooj_options['use_WpBoojCache'] == 'on') { WpBoojCache::store($post_id = 0, $post_type = 'WpBoojTopPosts', $popular); } return $popular; } else { return 'Please install and enable the plugin "Wp Post Views"'; } }