Changeset 3854
- Timestamp:
- 06/08/2006 02:22:16 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r3851 r3854 7 7 return $string; 8 8 } 9 }10 11 function get_profile($field, $user = false) {12 global $wpdb;13 if ( !$user )14 $user = $wpdb->escape($_COOKIE[USER_COOKIE]);15 return $wpdb->get_var("SELECT $field FROM $wpdb->users WHERE user_login = '$user'");16 9 } 17 10 … … 169 162 } 170 163 171 function user_pass_ok($user_login,$user_pass) {172 global $cache_userdata;173 if ( empty($cache_userdata[$user_login]) ) {174 $userdata = get_userdatabylogin($user_login);175 } else {176 $userdata = $cache_userdata[$user_login];177 }178 return (md5($user_pass) == $userdata->user_pass);179 }180 181 function get_usernumposts($userid) {182 global $wpdb;183 return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$userid' AND post_type = 'post' AND post_status = 'publish'");184 }185 186 164 function maybe_unserialize($original) { 187 165 if ( false !== $gm = @ unserialize($original) ) … … 225 203 function get_option($option) { 226 204 return get_settings($option); 227 }228 229 function get_user_option( $option, $user = 0 ) {230 global $wpdb;231 232 if ( empty($user) )233 $user = wp_get_current_user();234 else235 $user = get_userdata($user);236 237 if ( isset( $user->{$wpdb->prefix . $option} ) ) // Blog specific238 return $user->{$wpdb->prefix . $option};239 elseif ( isset( $user->{$option} ) ) // User specific and cross-blog240 return $user->{$option};241 else // Blog global242 return get_option( $option );243 205 } 244 206 … … 301 263 } 302 264 return false; 303 }304 305 function update_user_option( $user_id, $option_name, $newvalue, $global = false ) {306 global $wpdb;307 if ( !$global )308 $option_name = $wpdb->prefix . $option_name;309 return update_usermeta( $user_id, $option_name, $newvalue );310 265 } 311 266 … … 598 553 } 599 554 600 // Setup global post data.601 function setup_postdata($post) {602 global $id, $postdata, $authordata, $day, $page, $pages, $multipage, $more, $numpages, $wp_query;603 global $pagenow;604 605 $id = $post->ID;606 607 $authordata = get_userdata($post->post_author);608 609 $day = mysql2date('d.m.y', $post->post_date);610 $currentmonth = mysql2date('m', $post->post_date);611 $numpages = 1;612 $page = get_query_var('page');613 if ( !$page )614 $page = 1;615 if ( is_single() || is_page() )616 $more = 1;617 $content = $post->post_content;618 if ( preg_match('/<!--nextpage-->/', $content) ) {619 if ( $page > 1 )620 $more = 1;621 $multipage = 1;622 $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);623 $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);624 $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);625 $pages = explode('<!--nextpage-->', $content);626 $numpages = count($pages);627 } else {628 $pages[0] = $post->post_content;629 $multipage = 0;630 }631 return true;632 }633 634 // Setup global user vars. Used by set_current_user() for back compat.635 function setup_userdata($user_id = '') {636 global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity;637 638 if ( '' == $user_id )639 $user = wp_get_current_user();640 else641 $user = new WP_User($user_id);642 643 if ( 0 == $user->ID )644 return;645 646 $userdata = $user->data;647 $user_login = $user->user_login;648 $user_level = $user->user_level;649 $user_ID = $user->ID;650 $user_email = $user->user_email;651 $user_url = $user->user_url;652 $user_pass_md5 = md5($user->user_pass);653 $user_identity = $user->display_name;654 }655 656 555 function is_new_day() { 657 556 global $day, $previousday; … … 797 696 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 798 697 remove_filter($tag, $function_to_remove, $priority, $accepted_args); 799 }800 801 function get_page_uri($page_id) {802 $page = get_page($page_id);803 $uri = urldecode($page->post_name);804 805 // A page cannot be it's own parent.806 if ( $page->post_parent == $page->ID )807 return $uri;808 809 while ($page->post_parent != 0) {810 $page = get_page($page->post_parent);811 $uri = urldecode($page->post_name) . "/" . $uri;812 }813 814 return $uri;815 }816 817 function get_posts($args) {818 global $wpdb;819 820 if ( is_array($args) )821 $r = &$args;822 else823 parse_str($args, $r);824 825 $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => '',826 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' =>'');827 $r = array_merge($defaults, $r);828 extract($r);829 830 $inclusions = '';831 if ( !empty($include) ) {832 $offset = 0; //ignore offset, category, exclude, meta_key, and meta_value params if using include833 $category = '';834 $exclude = '';835 $meta_key = '';836 $meta_value = '';837 $incposts = preg_split('/[\s,]+/',$include);838 $numberposts = count($incposts); // only the number of posts included839 if ( count($incposts) ) {840 foreach ( $incposts as $incpost ) {841 if (empty($inclusions))842 $inclusions = ' AND ( ID = ' . intval($incpost) . ' ';843 else844 $inclusions .= ' OR ID = ' . intval($incpost) . ' ';845 }846 }847 }848 if (!empty($inclusions))849 $inclusions .= ')';850 851 $exclusions = '';852 if ( !empty($exclude) ) {853 $exposts = preg_split('/[\s,]+/',$exclude);854 if ( count($exposts) ) {855 foreach ( $exposts as $expost ) {856 if (empty($exclusions))857 $exclusions = ' AND ( ID <> ' . intval($expost) . ' ';858 else859 $exclusions .= ' AND ID <> ' . intval($expost) . ' ';860 }861 }862 }863 if (!empty($exclusions))864 $exclusions .= ')';865 866 $query ="SELECT DISTINCT * FROM $wpdb->posts " ;867 $query .= ( empty( $category ) ? "" : ", $wpdb->post2cat " ) ;868 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ;869 $query .= " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " ;870 $query .= ( empty( $category ) ? "" : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") " ) ;871 $query .= ( empty( $meta_key ) | empty($meta_value) ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" ) ;872 $query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . " " . $order . " LIMIT " . $offset . ',' . $numberposts ;873 874 $posts = $wpdb->get_results($query);875 876 update_post_caches($posts);877 878 return $posts;879 698 } 880 699 … … 1110 929 } 1111 930 1112 function get_usermeta( $user_id, $meta_key = '') {1113 global $wpdb;1114 $user_id = (int) $user_id;1115 1116 if ( !empty($meta_key) ) {1117 $meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);1118 $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");1119 } else {1120 $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");1121 }1122 1123 if ( empty($metas) ) {1124 if ( empty($meta_key) )1125 return array();1126 else1127 return '';1128 }1129 1130 foreach ($metas as $index => $meta) {1131 @ $value = unserialize($meta->meta_value);1132 if ( $value === FALSE )1133 $value = $meta->meta_value;1134 1135 $values[] = $value;1136 }1137 1138 if ( count($values) == 1 )1139 return $values[0];1140 else1141 return $values;1142 }1143 1144 function update_usermeta( $user_id, $meta_key, $meta_value ) {1145 global $wpdb;1146 if ( !is_numeric( $user_id ) )1147 return false;1148 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);1149 1150 if ( is_array($meta_value) || is_object($meta_value) )1151 $meta_value = serialize($meta_value);1152 $meta_value = trim( $meta_value );1153 1154 if (empty($meta_value)) {1155 return delete_usermeta($user_id, $meta_key);1156 }1157 1158 $cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");1159 if ( !$cur ) {1160 $wpdb->query("INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value )1161 VALUES1162 ( '$user_id', '$meta_key', '$meta_value' )");1163 } else if ( $cur->meta_value != $meta_value ) {1164 $wpdb->query("UPDATE $wpdb->usermeta SET meta_value = '$meta_value' WHERE user_id = '$user_id' AND meta_key = '$meta_key'");1165 } else {1166 return false;1167 }1168 1169 $user = get_userdata($user_id);1170 wp_cache_delete($user_id, 'users');1171 wp_cache_delete($user->user_login, 'userlogins');1172 1173 return true;1174 }1175 1176 function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) {1177 global $wpdb;1178 if ( !is_numeric( $user_id ) )1179 return false;1180 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);1181 1182 if ( is_array($meta_value) || is_object($meta_value) )1183 $meta_value = serialize($meta_value);1184 $meta_value = trim( $meta_value );1185 1186 if ( ! empty($meta_value) )1187 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key' AND meta_value = '$meta_value'");1188 else1189 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");1190 1191 $user = get_userdata($user_id);1192 wp_cache_delete($user_id, 'users');1193 wp_cache_delete($user->user_login, 'userlogins');1194 1195 return true;1196 }1197 1198 931 function register_activation_hook($file, $function) { 1199 932 $file = plugin_basename($file); -
trunk/wp-includes/post.php
r3851 r3854 145 145 } 146 146 147 function get_posts($args) { 148 global $wpdb; 149 150 if ( is_array($args) ) 151 $r = &$args; 152 else 153 parse_str($args, $r); 154 155 $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => '', 156 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' =>''); 157 $r = array_merge($defaults, $r); 158 extract($r); 159 160 $inclusions = ''; 161 if ( !empty($include) ) { 162 $offset = 0; //ignore offset, category, exclude, meta_key, and meta_value params if using include 163 $category = ''; 164 $exclude = ''; 165 $meta_key = ''; 166 $meta_value = ''; 167 $incposts = preg_split('/[\s,]+/',$include); 168 $numberposts = count($incposts); // only the number of posts included 169 if ( count($incposts) ) { 170 foreach ( $incposts as $incpost ) { 171 if (empty($inclusions)) 172 $inclusions = ' AND ( ID = ' . intval($incpost) . ' '; 173 else 174 $inclusions .= ' OR ID = ' . intval($incpost) . ' '; 175 } 176 } 177 } 178 if (!empty($inclusions)) 179 $inclusions .= ')'; 180 181 $exclusions = ''; 182 if ( !empty($exclude) ) { 183 $exposts = preg_split('/[\s,]+/',$exclude); 184 if ( count($exposts) ) { 185 foreach ( $exposts as $expost ) { 186 if (empty($exclusions)) 187 $exclusions = ' AND ( ID <> ' . intval($expost) . ' '; 188 else 189 $exclusions .= ' AND ID <> ' . intval($expost) . ' '; 190 } 191 } 192 } 193 if (!empty($exclusions)) 194 $exclusions .= ')'; 195 196 $query ="SELECT DISTINCT * FROM $wpdb->posts " ; 197 $query .= ( empty( $category ) ? "" : ", $wpdb->post2cat " ) ; 198 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 199 $query .= " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " ; 200 $query .= ( empty( $category ) ? "" : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") " ) ; 201 $query .= ( empty( $meta_key ) | empty($meta_value) ? "" : " AND ($wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->postmeta.meta_key = '$meta_key' AND $wpdb->postmeta.meta_value = '$meta_value' )" ) ; 202 $query .= " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . " " . $order . " LIMIT " . $offset . ',' . $numberposts ; 203 204 $posts = $wpdb->get_results($query); 205 206 update_post_caches($posts); 207 208 return $posts; 209 } 147 210 148 211 // … … 931 994 } } 932 995 return $result; 996 } 997 998 function get_page_uri($page_id) { 999 $page = get_page($page_id); 1000 $uri = urldecode($page->post_name); 1001 1002 // A page cannot be it's own parent. 1003 if ( $page->post_parent == $page->ID ) 1004 return $uri; 1005 1006 while ($page->post_parent != 0) { 1007 $page = get_page($page->post_parent); 1008 $uri = urldecode($page->post_name) . "/" . $uri; 1009 } 1010 1011 return $uri; 933 1012 } 934 1013 -
trunk/wp-includes/query.php
r3824 r3854 1038 1038 } 1039 1039 1040 // 1041 // Private helper functions 1042 // 1043 1044 // Setup global post data. 1045 function setup_postdata($post) { 1046 global $id, $postdata, $authordata, $day, $page, $pages, $multipage, $more, $numpages, $wp_query; 1047 global $pagenow; 1048 1049 $id = $post->ID; 1050 1051 $authordata = get_userdata($post->post_author); 1052 1053 $day = mysql2date('d.m.y', $post->post_date); 1054 $currentmonth = mysql2date('m', $post->post_date); 1055 $numpages = 1; 1056 $page = get_query_var('page'); 1057 if ( !$page ) 1058 $page = 1; 1059 if ( is_single() || is_page() ) 1060 $more = 1; 1061 $content = $post->post_content; 1062 if ( preg_match('/<!--nextpage-->/', $content) ) { 1063 if ( $page > 1 ) 1064 $more = 1; 1065 $multipage = 1; 1066 $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content); 1067 $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content); 1068 $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content); 1069 $pages = explode('<!--nextpage-->', $content); 1070 $numpages = count($pages); 1071 } else { 1072 $pages[0] = $post->post_content; 1073 $multipage = 0; 1074 } 1075 return true; 1076 } 1077 1040 1078 ?> -
trunk/wp-settings.php
r3851 r3854 129 129 require (ABSPATH . WPINC . '/query.php'); 130 130 require (ABSPATH . WPINC . '/theme.php'); 131 require (ABSPATH . WPINC . '/user.php'); 131 132 require (ABSPATH . WPINC . '/template-functions-general.php'); 132 133 require (ABSPATH . WPINC . '/template-functions-links.php'); 133 require (ABSPATH . WPINC . '/ template-functions-author.php');134 require (ABSPATH . WPINC . '/author-template.php'); 134 135 require (ABSPATH . WPINC . '/post.php'); 135 136 require (ABSPATH . WPINC . '/post-template.php');
Note: See TracChangeset
for help on using the changeset viewer.