classes.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,728 行 · 第 1/4 页
PHP
1,728 行
$n = '%'; } if (!$q['sentence']) { $s_array = explode(' ',$q['s']); $q['search_terms'] = $s_array; $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))'; for ( $i = 1; $i < count($s_array); $i = $i + 1) { $search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))'; } $search .= ' OR (post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\')'; $search .= ')'; } else { $search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content LIKE \''.$n.$q['s'].$n.'\'))'; } } // Category stuff if ((empty($q['cat'])) || ($q['cat'] == '0') || // Bypass cat checks if fetching specific posts ( $this->is_single || $this->is_page )) { $whichcat=''; } else { $q['cat'] = ''.urldecode($q['cat']).''; $q['cat'] = addslashes_gpc($q['cat']); if (stristr($q['cat'],'-')) { // Note: if we have a negative, we ignore all the positives. It must // always mean 'everything /except/ this one'. We should be able to do // multiple negatives but we don't :-( $eq = '!='; $andor = 'AND'; $q['cat'] = explode('-',$q['cat']); $q['cat'] = intval($q['cat'][1]); } else { $eq = '='; $andor = 'OR'; } $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) "; $cat_array = preg_split('/[,\s]+/', $q['cat']); $whichcat .= ' AND (category_id '.$eq.' '.intval($cat_array[0]); $whichcat .= get_category_children($cat_array[0], ' '.$andor.' category_id '.$eq.' '); for ($i = 1; $i < (count($cat_array)); $i = $i + 1) { $whichcat .= ' '.$andor.' category_id '.$eq.' '.intval($cat_array[$i]); $whichcat .= get_category_children($cat_array[$i], ' '.$andor.' category_id '.$eq.' '); } $whichcat .= ')'; if ($eq == '!=') { $q['cat'] = '-'.$q['cat']; // Put back the knowledge that we are excluding a category. } } // Category stuff for nice URIs global $cache_categories; if ('' != $q['category_name']) { $cat_paths = '/' . trim(urldecode($q['category_name']), '/'); $q['category_name'] = sanitize_title(basename($cat_paths)); $cat_paths = explode('/', $cat_paths); foreach($cat_paths as $pathdir) $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); $all_cat_ids = get_all_category_ids(); $q['cat'] = 0; $partial_match = 0; foreach ( $all_cat_ids as $cat_id ) { $cat = get_category($cat_id); if ( $cat->fullpath == $cat_path ) { $q['cat'] = $cat_id; break; } elseif ( $cat->category_nicename == $q['category_name'] ) { $partial_match = $cat_id; } } //if we don't match the entire hierarchy fallback on just matching the nicename if (!$q['cat'] && $partial_match) { $q['cat'] = $partial_match; } $tables = ", $wpdb->post2cat, $wpdb->categories"; $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) "; $whichcat = " AND (category_id = '" . $q['cat'] . "'"; $whichcat .= get_category_children($q['cat'], " OR category_id = "); $whichcat .= ")"; } // Author/user stuff if ((empty($q['author'])) || ($q['author'] == '0')) { $whichauthor=''; } else { $q['author'] = ''.urldecode($q['author']).''; $q['author'] = addslashes_gpc($q['author']); if (stristr($q['author'], '-')) { $eq = '!='; $andor = 'AND'; $q['author'] = explode('-', $q['author']); $q['author'] = ''.intval($q['author'][1]); } else { $eq = '='; $andor = 'OR'; } $author_array = preg_split('/[,\s]+/', $q['author']); $whichauthor .= ' AND (post_author '.$eq.' '.intval($author_array[0]); for ($i = 1; $i < (count($author_array)); $i = $i + 1) { $whichauthor .= ' '.$andor.' post_author '.$eq.' '.intval($author_array[$i]); } $whichauthor .= ')'; } // Author stuff for nice URIs if ('' != $q['author_name']) { if (stristr($q['author_name'],'/')) { $q['author_name'] = explode('/',$q['author_name']); if ($q['author_name'][count($q['author_name'])-1]) { $q['author_name'] = $q['author_name'][count($q['author_name'])-1];#no trailing slash } else { $q['author_name'] = $q['author_name'][count($q['author_name'])-2];#there was a trailling slash } } $q['author_name'] = sanitize_title($q['author_name']); $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'"); $whichauthor .= ' AND (post_author = '.intval($q['author']).')'; } $where .= $search.$whichcat.$whichauthor; if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) { $q['order']='DESC'; } // Order by if (empty($q['orderby'])) { $q['orderby']='date '.$q['order']; } else { // Used to filter values $allowed_keys = array('author', 'date', 'category', 'title', 'modified'); $q['orderby'] = urldecode($q['orderby']); $q['orderby'] = addslashes_gpc($q['orderby']); $orderby_array = explode(' ',$q['orderby']); if (!in_array($orderby_array[0],$allowed_keys)) { $orderby_array[0] = 'date'; } $q['orderby'] = $orderby_array[0].' '.$q['order']; if (count($orderby_array)>1) { for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) { // Only allow certain values for safety if (in_array($orderby_array[$i],$allowed_keys)) { $q['orderby'] .= ',post_'.$orderby_array[$i].' '.$q['order']; } } } } $now = gmdate('Y-m-d H:i:59'); //only select past-dated posts, except if a logged in user is viewing a single: then, if they //can edit the post, we let them through if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) { $where .= " AND post_date_gmt <= '$now'"; $distinct = 'DISTINCT'; } if ( $this->is_attachment ) { $where .= ' AND (post_status = "attachment")'; } elseif ($this->is_page) { $where .= ' AND (post_status = "static")'; } elseif ($this->is_single) { $where .= ' AND (post_status != "static")'; } else { $where .= ' AND (post_status = "publish"'; if (isset($user_ID) && ('' != intval($user_ID))) $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')"; else $where .= ')'; } if (! $this->is_attachment ) $where .= ' AND post_status != "attachment"'; // Apply filters on where and join prior to paging so that any // manipulations to them are reflected in the paging by day queries. $where = apply_filters('posts_where', $where); $join = apply_filters('posts_join', $join); // Paging if (empty($q['nopaging']) && ! $this->is_single && ! $this->is_page) { $page = abs(intval($q['paged'])); if (empty($page)) { $page = 1; } if (($q['what_to_show'] == 'posts')) { $q['offset'] = abs(intval($q['offset'])); if ( empty($q['offset']) ) { $pgstrt = ''; $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', '; $limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; } else { // we're ignoring $page and using 'offset' $pgstrt = $q['offset'] . ', '; $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } } elseif ($q['what_to_show'] == 'days') { $startrow = $q['posts_per_page'] * (intval($page)-1); $start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1"); $endrow = $startrow + $q['posts_per_page'] - 1; $end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1"); if ($page > 1) { $where .= " AND post_date >= '$end_date' AND post_date <= '$start_date'"; } else { $where .= " AND post_date >= '$end_date'"; } } } // Apply post-paging filters on where and join. Only plugins that // manipulate paging queries should use these hooks. $where = apply_filters('posts_where_paged', $where); $groupby = " $wpdb->posts.ID "; $groupby = apply_filters('posts_groupby', $groupby); $join = apply_filters('posts_join_paged', $join); $orderby = "post_" . $q['orderby']; $orderby = apply_filters('posts_orderby', $orderby); $request = " SELECT $distinct * FROM $wpdb->posts $join WHERE 1=1" . $where . " GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits"; $this->request = apply_filters('posts_request', $request); $this->posts = $wpdb->get_results($this->request); // Check post status to determine if post should be displayed. if ( !empty($this->posts) && $this->is_single ) { $status = get_post_status($this->posts[0]); if ( ('publish' != $status) && ('static' != $status) ) { if ( ! (isset($user_ID) && ('' != intval($user_ID))) ) { // User must be logged in to view unpublished posts. $this->posts = array(); } else { if ('draft' == $status) { // User must have edit permissions on the draft to preview. if (! current_user_can('edit_post', $this->posts[0]->ID)) { $this->posts = array(); } else { $this->is_preview = true; $this->posts[0]->post_date = current_time('mysql'); } } else { if (! current_user_can('read_post', $this->posts[0]->ID)) $this->posts = array(); } } } else { if (mysql2date('U', $this->posts[0]->post_date_gmt) > mysql2date('U', $now)) { //it's future dated $this->is_preview = true; if (!current_user_can('edit_post', $this->posts[0]->ID)) { $this->posts = array ( ); } } } } update_post_caches($this->posts); $this->posts = apply_filters('the_posts', $this->posts); $this->post_count = count($this->posts); if ($this->post_count > 0) { $this->post = $this->posts[0]; } // Save any changes made to the query vars. $this->query_vars = $q; return $this->posts; } function next_post() { $this->current_post++; $this->post = $this->posts[$this->current_post]; return $this->post; } function the_post() { global $post; $this->in_the_loop = true; $post = $this->next_post(); setup_postdata($post); if ( $this->current_post == 0 ) // loop has just started do_action('loop_start'); } function have_posts() { if ($this->current_post + 1 < $this->post_count) { return true; } elseif ($this->current_post + 1 == $this->post_count) { do_action('loop_end'); // Do some cleaning up after the loop $this->rewind_posts(); } $this->in_the_loop = false; return false; } function rewind_posts() { $this->current_post = -1; if ($this->post_count > 0) { $this->post = $this->posts[0]; } } function &query($query) { $this->parse_query($query); return $this->get_posts(); } function get_queried_object() { if (isset($this->queried_object)) { return $this->queried_object; } $this->queried_object = NULL; $this->queried_object_id = 0; if ($this->is_category) { $cat = $this->get('cat'); $category = &get_category($cat); $this->queried_object = &$category; $this->queried_object_id = $cat; } else if ($this->is_single) { $this->queried_object = $this->post; $this->queried_object_id = $this->post->ID; } else if ($this->is_page) { $this->queried_object = $this->post; $this->queried_object_id = $this->post->ID; } else if ($this->is_author) { $author_id = $this->get('author'); $author = get_userdata($author_id); $this->queried_object = $author; $this->queried_object_id = $author_id; } return $this->queried_object; } function get_queried_object_id() { $this->get_queried_object(); if (isset($this->queried_object_id)) { return $this->queried_object_id; } return 0; } function WP_Query ($query = '') { if (! empty($query)) { $this->query($query); } }}class retrospam_mgr { var $spam_words; var $comments_list; var $found_comments; function retrospam_mgr() { global $wpdb; $list = explode("\n", get_settings('moderation_keys') ); $list = array_unique( $list ); $this->spam_words = $list; $this->comment_list = $wpdb->get_results("SELECT comment_ID AS ID, comment_content AS text, comment_approved AS approved, comment_author_url AS url, comment_author_ip AS ip, comment_author_email AS email FROM $wpdb->comments ORDER BY comment_ID ASC"); } // End of class constructor function move_spam( $id_list ) { global $wpdb; $cnt = 0; $id_list = explode( ',', $id_list ); foreach ( $id_list as $comment ) { if ( $wpdb->query("update $wpdb->comments set comment_approved = '0' where comment_ID = '$comment'") ) { $cnt++; } } echo "<div class='updated'><p>$cnt comment"; if ($cnt != 1 ) echo "s"; echo " moved to the moderation queue.</p></div>\n"; } // End function move_spam function find_spam() { $in_queue = 0; foreach( $this->comment_list as $comment ) { if( $comment->approved == 1 ) { foreach( $this->spam_words as $word ) { $word = trim($word); if ( empty( $word ) ) continue; $fulltext = strtolower($comment->email.' '.$comment->url.' '.$comment->ip.' '.$comment->text); if( false !== strpos( $fulltext, strtolower($word) ) ) { $this->found_comments[] = $comment->ID; break; } } } else { $in_queue++; } } return array( 'found' => $this->found_comments, 'in_queue' => $in_queue ); } // End function find_spam function display_edit_form( $counters ) { $numfound = count($counters[found]); $numqueue = $counters[in_queue]; $body = '<p>' . sprintf(__('Suspected spam comments: <strong>%s</strong>'), $numfound) . '</p>'; if ( count($counters[found]) > 0 ) { $id_list = implode( ',', $counters[found] ); $body .= '<p><a href="options-discussion.php?action=retrospam&move=true&ids='.$id_list.'">'. __('Move suspect comments to moderation queue »') . '</a></p>'; } $head = '<div class="wrap"><h2>' . __('Check Comments Results:') . '</h2>'; $foot .= '<p><a href="options-discussion.php">' . __('« Return to Discussion Options page.') . '</a></p></div>'; return $head . $body . $foot; } // End function display_edit_form
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?