Ticket #986: 986-includes.diff
| File 986-includes.diff, 210.5 KB (added by Nazgul, 6 years ago) |
|---|
-
wp-includes/bookmark-template.php
77 77 $order = 'DESC'; 78 78 $orderby = substr($orderby, 1); 79 79 } 80 80 81 81 if ($category == -1) { //get_bookmarks uses '' to signify all categories 82 82 $category = ''; 83 83 } … … 159 159 } 160 160 161 161 function get_linkrating($link) { 162 return apply_filters('link_rating', $link->link_rating);162 return apply_filters('link_rating', $link->link_rating); 163 163 } 164 164 165 165 /** function get_linkcatname() … … 170 170 function get_linkcatname($id = 0) { 171 171 $id = (int) $id; 172 172 173 if ( empty($id) )174 return '';175 173 if ( empty($id) ) 174 return ''; 175 176 176 $cats = wp_get_link_cats($id); 177 177 178 178 if ( empty($cats) || ! is_array($cats) ) … … 195 195 ** count (default true) - the number of links in the db 196 196 */ 197 197 function links_popup_script($text = 'Links', $width=400, $height=400, 198 $file='links.all.php', $count = true) {199 if ($count == true) {200 $counts = $wpdb->get_var("SELECT count(*) FROM $wpdb->links");201 }198 $file='links.all.php', $count = true) { 199 if ($count == true) { 200 $counts = $wpdb->get_var("SELECT count(*) FROM $wpdb->links"); 201 } 202 202 203 $javascript = "<a href=\"#\" " .204 " onclick=\"javascript:window.open('$file?popup=1', '_blank', " .205 "'width=$width,height=$height,scrollbars=yes,status=no'); " .206 " return false\">";207 $javascript .= $text;203 $javascript = "<a href=\"#\" " . 204 " onclick=\"javascript:window.open('$file?popup=1', '_blank', " . 205 "'width=$width,height=$height,scrollbars=yes,status=no'); " . 206 " return false\">"; 207 $javascript .= $text; 208 208 209 if ($count == true) {210 $javascript .= " ($counts)";211 }209 if ($count == true) { 210 $javascript .= " ($counts)"; 211 } 212 212 213 $javascript .="</a>\n\n";214 echo $javascript;213 $javascript .="</a>\n\n"; 214 echo $javascript; 215 215 } 216 216 217 217 … … 345 345 'category_orderby' => 'name', 'category_order' => 'ASC'); 346 346 $r = array_merge($defaults, $r); 347 347 extract($r); 348 348 349 349 // TODO: The rest of it. 350 350 // If $categorize, group links by category with the category name being the 351 // title of each li, otherwise just list them with title_li as the li title. 351 // title of each li, otherwise just list them with title_li as the li title. 352 352 // If $categorize and $category or $category_name, list links for the given category 353 353 // with the category name as the title li. If not $categorize, use title_li. 354 354 // When using each category's name as a title li, use before and after args for specifying -
wp-includes/bookmark.php
19 19 20 20 // Deprecate 21 21 function get_link($bookmark_id, $output = OBJECT) { 22 return get_bookmark($bookmark_id, $output); 22 return get_bookmark($bookmark_id, $output); 23 23 } 24 24 25 25 function get_bookmarks($args = '') { … … 50 50 } 51 51 } 52 52 } 53 if (!empty($inclusions)) 53 if (!empty($inclusions)) 54 54 $inclusions .= ')'; 55 55 56 56 $exclusions = ''; … … 65 65 } 66 66 } 67 67 } 68 if (!empty($exclusions)) 68 if (!empty($exclusions)) 69 69 $exclusions .= ')'; 70 70 71 71 if ( ! empty($category_name) ) { 72 72 if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") ) 73 73 $category = $cat_id; … … 87 87 } 88 88 } 89 89 if (!empty($category_query)) { 90 $category_query .= ')'; 90 $category_query .= ')'; 91 91 $join = " LEFT JOIN $wpdb->link2cat ON ($wpdb->links.link_id = $wpdb->link2cat.link_id) "; 92 92 } 93 93 -
wp-includes/cache.php
67 67 var $secret = ''; 68 68 69 69 function acquire_lock() { 70 // Acquire a write lock. 70 // Acquire a write lock. 71 71 $this->mutex = @fopen($this->cache_dir.$this->flock_filename, 'w'); 72 72 if ( false == $this->mutex) 73 73 return false; … … 239 239 while ($index < count($stack)) { 240 240 # Get indexed directory from stack 241 241 $dir = $stack[$index]; 242 242 243 243 $dh = @ opendir($dir); 244 244 if (!$dh) 245 245 return false; 246 246 247 247 while (($file = @ readdir($dh)) !== false) { 248 248 if ($file == '.' or $file == '..') 249 249 continue; -
wp-includes/capabilities.php
211 211 } 212 212 213 213 function level_reduction($max, $item) { 214 if(preg_match('/^level_(10|[0-9])$/i', $item, $matches)) {215 $level = intval($matches[1]);216 return max($max, $level);217 } else {218 return $max;219 }214 if(preg_match('/^level_(10|[0-9])$/i', $item, $matches)) { 215 $level = intval($matches[1]); 216 return max($max, $level); 217 } else { 218 return $max; 219 } 220 220 } 221 221 222 222 function update_user_level_from_caps() { 223 global $wpdb;224 $this->user_level = array_reduce(array_keys($this->allcaps), array(&$this, 'level_reduction'), 0);225 update_usermeta($this->id, $wpdb->prefix.'user_level', $this->user_level);223 global $wpdb; 224 $this->user_level = array_reduce(array_keys($this->allcaps), array(&$this, 'level_reduction'), 0); 225 update_usermeta($this->id, $wpdb->prefix.'user_level', $this->user_level); 226 226 } 227 227 228 228 function add_cap($cap, $grant = true) { … … 288 288 $post = get_post($args[0]); 289 289 if ( 'page' == $post->post_type ) { 290 290 $args = array_merge(array('delete_page', $user_id), $args); 291 return call_user_func_array('map_meta_cap', $args); 291 return call_user_func_array('map_meta_cap', $args); 292 292 } 293 293 $post_author_data = get_userdata($post->post_author); 294 294 //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br/>"; … … 342 342 $post = get_post($args[0]); 343 343 if ( 'page' == $post->post_type ) { 344 344 $args = array_merge(array('edit_page', $user_id), $args); 345 return call_user_func_array('map_meta_cap', $args); 345 return call_user_func_array('map_meta_cap', $args); 346 346 } 347 347 $post_author_data = get_userdata($post->post_author); 348 348 //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br/>"; … … 392 392 $post = get_post($args[0]); 393 393 if ( 'page' == $post->post_type ) { 394 394 $args = array_merge(array('read_page', $user_id), $args); 395 return call_user_func_array('map_meta_cap', $args); 395 return call_user_func_array('map_meta_cap', $args); 396 396 } 397 397 398 398 if ( 'private' != $post->post_status ) { -
wp-includes/category-template.php
184 184 $output .= "\t<option value='0'>$show_option_all</option>\n"; 185 185 } 186 186 187 if ( $show_option_none) { 188 $show_option_none = apply_filters('list_cats', $show_option_none); 187 if ( $show_option_none) { 188 $show_option_none = apply_filters('list_cats', $show_option_none); 189 189 $output .= "\t<option value='-1'>$show_option_none</option>\n"; 190 190 } 191 191 … … 222 222 extract($r); 223 223 224 224 $categories = get_categories($r); 225 225 226 226 $output = ''; 227 227 if ( $title_li && 'list' == $style ) 228 228 $output = '<li class="categories">' . $r['title_li'] . '<ul>'; … … 245 245 246 246 if ( $title_li && 'list' == $style ) 247 247 $output .= '</ul></li>'; 248 248 249 249 echo apply_filters('list_cats', $output); 250 250 } 251 251 -
wp-includes/category.php
28 28 $where = 'cat_ID > 0'; 29 29 $inclusions = ''; 30 30 if ( !empty($include) ) { 31 $child_of = 0; //ignore child_of and exclude params if using include 32 $exclude = ''; 31 $child_of = 0; //ignore child_of and exclude params if using include 32 $exclude = ''; 33 33 $incategories = preg_split('/[\s,]+/',$include); 34 34 if ( count($incategories) ) { 35 35 foreach ( $incategories as $incat ) { … … 40 40 } 41 41 } 42 42 } 43 if (!empty($inclusions)) 44 $inclusions .= ')'; 43 if (!empty($inclusions)) 44 $inclusions .= ')'; 45 45 $where .= $inclusions; 46 46 47 47 $exclusions = ''; … … 57 57 } 58 58 } 59 59 } 60 if (!empty($exclusions)) 60 if (!empty($exclusions)) 61 61 $exclusions .= ')'; 62 62 $exclusions = apply_filters('list_cats_exclusions', $exclusions ); 63 63 $where .= $exclusions; … … 85 85 function stamp_cat($cat) { 86 86 global $cat_stamps; 87 87 $cat->last_update_timestamp = $cat_stamps[$cat->cat_ID]; 88 return $cat; 88 return $cat; 89 89 } 90 90 $categories = array_map('stamp_cat', $categories); 91 91 unset($cat_stamps); … … 139 139 140 140 $categories = $wpdb->get_results("SELECT cat_ID, category_nicename, category_parent FROM $wpdb->categories WHERE category_nicename = '$leaf_path'"); 141 141 142 if ( empty($categories) ) 142 if ( empty($categories) ) 143 143 return NULL; 144 144 145 145 foreach ($categories as $category) { -
wp-includes/class-IXR.php
1 1 <?php 2 /* 3 IXR - The Inutio XML-RPC Library - (c) Incutio Ltd 2002-20054 Version 1.7 (beta) - Simon Willison, 23rd May 20055 Site: http://scripts.incutio.com/xmlrpc/6 Manual: http://scripts.incutio.com/xmlrpc/manual.php7 Made available under the BSD License: http://www.opensource.org/licenses/bsd-license.php2 /* 3 IXR - The Inutio XML-RPC Library - (c) Incutio Ltd 2002-2005 4 Version 1.7 (beta) - Simon Willison, 23rd May 2005 5 Site: http://scripts.incutio.com/xmlrpc/ 6 Manual: http://scripts.incutio.com/xmlrpc/manual.php 7 Made available under the BSD License: http://www.opensource.org/licenses/bsd-license.php 8 8 */ 9 9 10 10 class IXR_Value { 11 var $data; 12 var $type; 13 function IXR_Value ($data, $type = false) { 14 $this->data = $data; 15 if (!$type) { 16 $type = $this->calculateType(); 17 } 18 $this->type = $type; 19 if ($type == 'struct') { 20 /* Turn all the values in the array in to new IXR_Value objects */ 21 foreach ($this->data as $key => $value) { 22 $this->data[$key] = new IXR_Value($value); 23 } 24 } 25 if ($type == 'array') { 26 for ($i = 0, $j = count($this->data); $i < $j; $i++) { 27 $this->data[$i] = new IXR_Value($this->data[$i]); 28 } 29 } 30 } 31 function calculateType() { 32 if ($this->data === true || $this->data === false) { 33 return 'boolean'; 34 } 35 if (is_integer($this->data)) { 36 return 'int'; 37 } 38 if (is_double($this->data)) { 39 return 'double'; 40 } 41 // Deal with IXR object types base64 and date 42 if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { 43 return 'date'; 44 } 45 if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { 46 return 'base64'; 47 } 48 // If it is a normal PHP object convert it in to a struct 49 if (is_object($this->data)) { 50 51 $this->data = get_object_vars($this->data); 52 return 'struct'; 53 } 54 if (!is_array($this->data)) { 55 return 'string'; 56 } 57 /* We have an array - is it an array or a struct ? */ 58 if ($this->isStruct($this->data)) { 59 return 'struct'; 60 } else { 61 return 'array'; 62 } 63 } 64 function getXml() { 65 /* Return XML for this value */ 66 switch ($this->type) { 67 case 'boolean': 68 return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; 69 break; 70 case 'int': 71 return '<int>'.$this->data.'</int>'; 72 break; 73 case 'double': 74 return '<double>'.$this->data.'</double>'; 75 break; 76 case 'string': 77 return '<string>'.htmlspecialchars($this->data).'</string>'; 78 break; 79 case 'array': 80 $return = '<array><data>'."\n"; 81 foreach ($this->data as $item) { 82 $return .= ' <value>'.$item->getXml()."</value>\n"; 83 } 84 $return .= '</data></array>'; 85 return $return; 86 break; 87 case 'struct': 88 $return = '<struct>'."\n"; 89 foreach ($this->data as $name => $value) { 11 var $data; 12 var $type; 13 function IXR_Value ($data, $type = false) { 14 $this->data = $data; 15 if (!$type) { 16 $type = $this->calculateType(); 17 } 18 $this->type = $type; 19 if ($type == 'struct') { 20 /* Turn all the values in the array in to new IXR_Value objects */ 21 foreach ($this->data as $key => $value) { 22 $this->data[$key] = new IXR_Value($value); 23 } 24 } 25 if ($type == 'array') { 26 for ($i = 0, $j = count($this->data); $i < $j; $i++) { 27 $this->data[$i] = new IXR_Value($this->data[$i]); 28 } 29 } 30 } 31 function calculateType() { 32 if ($this->data === true || $this->data === false) { 33 return 'boolean'; 34 } 35 if (is_integer($this->data)) { 36 return 'int'; 37 } 38 if (is_double($this->data)) { 39 return 'double'; 40 } 41 // Deal with IXR object types base64 and date 42 if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { 43 return 'date'; 44 } 45 if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { 46 return 'base64'; 47 } 48 // If it is a normal PHP object convert it in to a struct 49 if (is_object($this->data)) { 50 $this->data = get_object_vars($this->data); 51 return 'struct'; 52 } 53 if (!is_array($this->data)) { 54 return 'string'; 55 } 56 /* We have an array - is it an array or a struct ? */ 57 if ($this->isStruct($this->data)) { 58 return 'struct'; 59 } else { 60 return 'array'; 61 } 62 } 63 function getXml() { 64 /* Return XML for this value */ 65 switch ($this->type) { 66 case 'boolean': 67 return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; 68 break; 69 case 'int': 70 return '<int>'.$this->data.'</int>'; 71 break; 72 case 'double': 73 return '<double>'.$this->data.'</double>'; 74 break; 75 case 'string': 76 return '<string>'.htmlspecialchars($this->data).'</string>'; 77 break; 78 case 'array': 79 $return = '<array><data>'."\n"; 80 foreach ($this->data as $item) { 81 $return .= ' <value>'.$item->getXml()."</value>\n"; 82 } 83 $return .= '</data></array>'; 84 return $return; 85 break; 86 case 'struct': 87 $return = '<struct>'."\n"; 88 foreach ($this->data as $name => $value) { 90 89 $name = htmlspecialchars($name); 91 $return .= " <member><name>$name</name><value>";92 $return .= $value->getXml()."</value></member>\n";93 }94 $return .= '</struct>';95 return $return;96 break;97 case 'date':98 case 'base64':99 return $this->data->getXml();100 break;101 }102 return false;103 }104 function isStruct($array) {105 /* Nasty function to check if an array is a struct or not */106 $expected = 0;107 foreach ($array as $key => $value) {108 if ((string)$key != (string)$expected) {109 return true;110 }111 $expected++;112 }113 return false;114 }90 $return .= " <member><name>$name</name><value>"; 91 $return .= $value->getXml()."</value></member>\n"; 92 } 93 $return .= '</struct>'; 94 return $return; 95 break; 96 case 'date': 97 case 'base64': 98 return $this->data->getXml(); 99 break; 100 } 101 return false; 102 } 103 function isStruct($array) { 104 /* Nasty function to check if an array is a struct or not */ 105 $expected = 0; 106 foreach ($array as $key => $value) { 107 if ((string)$key != (string)$expected) { 108 return true; 109 } 110 $expected++; 111 } 112 return false; 113 } 115 114 } 116 115 117 116 118 117 class IXR_Message { 119 var $message;120 var $messageType; // methodCall / methodResponse / fault121 var $faultCode;122 var $faultString;123 var $methodName;124 var $params;125 // Current variable stacks126 var $_arraystructs = array(); // The stack used to keep track of the current array/struct127 var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array128 var $_currentStructName = array(); // A stack as well129 var $_param;130 var $_value;131 var $_currentTag;132 var $_currentTagContents;133 // The XML parser134 var $_parser;135 function IXR_Message ($message) {136 $this->message = $message;137 }138 function parse() {139 // first remove the XML declaration140 $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message);141 if (trim($this->message) == '') {142 return false;143 }144 $this->_parser = xml_parser_create();145 // Set XML parser to take the case of tags in to account146 xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);147 // Set XML parser callback functions148 xml_set_object($this->_parser, $this);149 xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');150 xml_set_character_data_handler($this->_parser, 'cdata');151 if (!xml_parse($this->_parser, $this->message)) {152 /* die(sprintf('XML error: %s at line %d',153 xml_error_string(xml_get_error_code($this->_parser)),154 xml_get_current_line_number($this->_parser))); */155 return false;156 }157 xml_parser_free($this->_parser);158 // Grab the error messages, if any159 if ($this->messageType == 'fault') {160 $this->faultCode = $this->params[0]['faultCode'];161 $this->faultString = $this->params[0]['faultString'];162 }163 return true;164 }165 function tag_open($parser, $tag, $attr) {118 var $message; 119 var $messageType; // methodCall / methodResponse / fault 120 var $faultCode; 121 var $faultString; 122 var $methodName; 123 var $params; 124 // Current variable stacks 125 var $_arraystructs = array(); // The stack used to keep track of the current array/struct 126 var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array 127 var $_currentStructName = array(); // A stack as well 128 var $_param; 129 var $_value; 130 var $_currentTag; 131 var $_currentTagContents; 132 // The XML parser 133 var $_parser; 134 function IXR_Message ($message) { 135 $this->message = $message; 136 } 137 function parse() { 138 // first remove the XML declaration 139 $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message); 140 if (trim($this->message) == '') { 141 return false; 142 } 143 $this->_parser = xml_parser_create(); 144 // Set XML parser to take the case of tags in to account 145 xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); 146 // Set XML parser callback functions 147 xml_set_object($this->_parser, $this); 148 xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); 149 xml_set_character_data_handler($this->_parser, 'cdata'); 150 if (!xml_parse($this->_parser, $this->message)) { 151 /* die(sprintf('XML error: %s at line %d', 152 xml_error_string(xml_get_error_code($this->_parser)), 153 xml_get_current_line_number($this->_parser))); */ 154 return false; 155 } 156 xml_parser_free($this->_parser); 157 // Grab the error messages, if any 158 if ($this->messageType == 'fault') { 159 $this->faultCode = $this->params[0]['faultCode']; 160 $this->faultString = $this->params[0]['faultString']; 161 } 162 return true; 163 } 164 function tag_open($parser, $tag, $attr) { 166 165 $this->_currentTagContents = ''; 167 $this->currentTag = $tag;168 switch($tag) {169 case 'methodCall':170 case 'methodResponse':171 case 'fault':172 $this->messageType = $tag;173 break;174 /* Deal with stacks of arrays and structs */175 case 'data': // data is to all intents and puposes more interesting than array176 $this->_arraystructstypes[] = 'array';177 $this->_arraystructs[] = array();178 break;179 case 'struct':180 $this->_arraystructstypes[] = 'struct';181 $this->_arraystructs[] = array();182 break;183 }184 }185 function cdata($parser, $cdata) {186 $this->_currentTagContents .= $cdata;187 }188 function tag_close($parser, $tag) {189 $valueFlag = false;190 switch($tag) {191 case 'int':192 case 'i4':193 $value = (int) trim($this->_currentTagContents);194 $valueFlag = true;195 break;196 case 'double':197 $value = (double) trim($this->_currentTagContents);198 $valueFlag = true;199 break;200 case 'string':201 $value = $this->_currentTagContents;202 $valueFlag = true;203 break;204 case 'dateTime.iso8601':205 $value = new IXR_Date(trim($this->_currentTagContents));206 // $value = $iso->getTimestamp();207 $valueFlag = true;208 break;209 case 'value':210 // "If no type is indicated, the type is string."211 if (trim($this->_currentTagContents) != '') {212 $value = (string)$this->_currentTagContents;213 $valueFlag = true;214 }215 break;216 case 'boolean':217 $value = (boolean) trim($this->_currentTagContents);218 $valueFlag = true;219 break;220 case 'base64':221 $value = base64_decode( trim( $this->_currentTagContents ) );222 $valueFlag = true;223 break;224 /* Deal with stacks of arrays and structs */225 case 'data':226 case 'struct':227 $value = array_pop($this->_arraystructs);228 array_pop($this->_arraystructstypes);229 $valueFlag = true;230 break;231 case 'member':232 array_pop($this->_currentStructName);233 break;234 case 'name':235 $this->_currentStructName[] = trim($this->_currentTagContents);236 break;237 case 'methodName':238 $this->methodName = trim($this->_currentTagContents);239 break;240 }241 if ($valueFlag) {242 if (count($this->_arraystructs) > 0) {243 // Add value to struct or array244 if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {245 // Add to struct246 $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;247 } else {248 // Add to array249 $this->_arraystructs[count($this->_arraystructs)-1][] = $value;250 }251 } else {252 // Just add as a paramater253 $this->params[] = $value;254 }255 }166 $this->currentTag = $tag; 167 switch($tag) { 168 case 'methodCall': 169 case 'methodResponse': 170 case 'fault': 171 $this->messageType = $tag; 172 break; 173 /* Deal with stacks of arrays and structs */ 174 case 'data': // data is to all intents and puposes more interesting than array 175 $this->_arraystructstypes[] = 'array'; 176 $this->_arraystructs[] = array(); 177 break; 178 case 'struct': 179 $this->_arraystructstypes[] = 'struct'; 180 $this->_arraystructs[] = array(); 181 break; 182 } 183 } 184 function cdata($parser, $cdata) { 185 $this->_currentTagContents .= $cdata; 186 } 187 function tag_close($parser, $tag) { 188 $valueFlag = false; 189 switch($tag) { 190 case 'int': 191 case 'i4': 192 $value = (int) trim($this->_currentTagContents); 193 $valueFlag = true; 194 break; 195 case 'double': 196 $value = (double) trim($this->_currentTagContents); 197 $valueFlag = true; 198 break; 199 case 'string': 200 $value = $this->_currentTagContents; 201 $valueFlag = true; 202 break; 203 case 'dateTime.iso8601': 204 $value = new IXR_Date(trim($this->_currentTagContents)); 205 // $value = $iso->getTimestamp(); 206 $valueFlag = true; 207 break; 208 case 'value': 209 // "If no type is indicated, the type is string." 210 if (trim($this->_currentTagContents) != '') { 211 $value = (string)$this->_currentTagContents; 212 $valueFlag = true; 213 } 214 break; 215 case 'boolean': 216 $value = (boolean) trim($this->_currentTagContents); 217 $valueFlag = true; 218 break; 219 case 'base64': 220 $value = base64_decode( trim( $this->_currentTagContents ) ); 221 $valueFlag = true; 222 break; 223 /* Deal with stacks of arrays and structs */ 224 case 'data': 225 case 'struct': 226 $value = array_pop($this->_arraystructs); 227 array_pop($this->_arraystructstypes); 228 $valueFlag = true; 229 break; 230 case 'member': 231 array_pop($this->_currentStructName); 232 break; 233 case 'name': 234 $this->_currentStructName[] = trim($this->_currentTagContents); 235 break; 236 case 'methodName': 237 $this->methodName = trim($this->_currentTagContents); 238 break; 239 } 240 if ($valueFlag) { 241 if (count($this->_arraystructs) > 0) { 242 // Add value to struct or array 243 if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { 244 // Add to struct 245 $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; 246 } else { 247 // Add to array 248 $this->_arraystructs[count($this->_arraystructs)-1][] = $value; 249 } 250 } else { 251 // Just add as a paramater 252 $this->params[] = $value; 253 } 254 } 256 255 $this->_currentTagContents = ''; 257 } 256 } 258 257 } 259 258 260 259 261 260 class IXR_Server { 262 var $data;263 var $callbacks = array();264 var $message;265 var $capabilities;266 function IXR_Server($callbacks = false, $data = false) {267 $this->setCapabilities();268 if ($callbacks) {269 $this->callbacks = $callbacks;270 }271 $this->setCallbacks();272 $this->serve($data);273 }274 function serve($data = false) {275 if (!$data) {276 global $HTTP_RAW_POST_DATA;277 if (!$HTTP_RAW_POST_DATA) {278 die('XML-RPC server accepts POST requests only.');279 }280 $data = $HTTP_RAW_POST_DATA;281 }282 $this->message = new IXR_Message($data);283 if (!$this->message->parse()) {284 $this->error(-32700, 'parse error. not well formed');285 }286 if ($this->message->messageType != 'methodCall') {287 $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');288 }289 $result = $this->call($this->message->methodName, $this->message->params);290 // Is the result an error?291 if (is_a($result, 'IXR_Error')) {292 $this->error($result);293 }294 // Encode the result295 $r = new IXR_Value($result);296 $resultxml = $r->getXml();297 // Create the XML298 $xml = <<<EOD261 var $data; 262 var $callbacks = array(); 263 var $message; 264 var $capabilities; 265 function IXR_Server($callbacks = false, $data = false) { 266 $this->setCapabilities(); 267 if ($callbacks) { 268 $this->callbacks = $callbacks; 269 } 270 $this->setCallbacks(); 271 $this->serve($data); 272 } 273 function serve($data = false) { 274 if (!$data) { 275 global $HTTP_RAW_POST_DATA; 276 if (!$HTTP_RAW_POST_DATA) { 277 die('XML-RPC server accepts POST requests only.'); 278 } 279 $data = $HTTP_RAW_POST_DATA; 280 } 281 $this->message = new IXR_Message($data); 282 if (!$this->message->parse()) { 283 $this->error(-32700, 'parse error. not well formed'); 284 } 285 if ($this->message->messageType != 'methodCall') { 286 $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); 287 } 288 $result = $this->call($this->message->methodName, $this->message->params); 289 // Is the result an error? 290 if (is_a($result, 'IXR_Error')) { 291 $this->error($result); 292 } 293 // Encode the result 294 $r = new IXR_Value($result); 295 $resultxml = $r->getXml(); 296 // Create the XML 297 $xml = <<<EOD 299 298 <methodResponse> 300 <params>301 <param>302 <value>303 $resultxml304 </value>305 </param>306 </params>299 <params> 300 <param> 301 <value> 302 $resultxml 303 </value> 304 </param> 305 </params> 307 306 </methodResponse> 308 307 309 308 EOD; 310 // Send it311 $this->output($xml);312 }313 function call($methodname, $args) {314 if (!$this->hasMethod($methodname)) {315 return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');316 }317 $method = $this->callbacks[$methodname];318 // Perform the callback and send the response319 if (count($args) == 1) {320 // If only one paramater just send that instead of the whole array321 $args = $args[0];322 }323 // Are we dealing with a function or a method?324 if (substr($method, 0, 5) == 'this:') {325 // It's a class method - check it exists326 $method = substr($method, 5);327 if (!method_exists($this, $method)) {328 return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');329 }330 // Call the method331 $result = $this->$method($args);332 } else {333 // It's a function - does it exist?334 if (is_array($method)) {335 if (!method_exists($method[0], $method[1])) {336 return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');337 }338 } else if (!function_exists($method)) {339 return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');340 }341 // Call the function342 $result = call_user_func($method, $args);343 }344 return $result;345 }309 // Send it 310 $this->output($xml); 311 } 312 function call($methodname, $args) { 313 if (!$this->hasMethod($methodname)) { 314 return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); 315 } 316 $method = $this->callbacks[$methodname]; 317 // Perform the callback and send the response 318 if (count($args) == 1) { 319 // If only one paramater just send that instead of the whole array 320 $args = $args[0]; 321 } 322 // Are we dealing with a function or a method? 323 if (substr($method, 0, 5) == 'this:') { 324 // It's a class method - check it exists 325 $method = substr($method, 5); 326 if (!method_exists($this, $method)) { 327 return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); 328 } 329 // Call the method 330 $result = $this->$method($args); 331 } else { 332 // It's a function - does it exist? 333 if (is_array($method)) { 334 if (!method_exists($method[0], $method[1])) { 335 return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); 336 } 337 } else if (!function_exists($method)) { 338 return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); 339 } 340 // Call the function 341 $result = call_user_func($method, $args); 342 } 343 return $result; 344 } 346 345 347 function error($error, $message = false) {348 // Accepts either an error object or an error code and message349 if ($message && !is_object($error)) {350 $error = new IXR_Error($error, $message);351 }352 $this->output($error->getXml());353 }354 function output($xml) {355 $xml = '<?xml version="1.0"?>'."\n".$xml;356 $length = strlen($xml);357 header('Connection: close');358 header('Content-Length: '.$length);359 header('Content-Type: text/xml');360 header('Date: '.date('r'));361 echo $xml;362 exit;363 }364 function hasMethod($method) {365 return in_array($method, array_keys($this->callbacks));366 }367 function setCapabilities() {368 // Initialises capabilities array369 $this->capabilities = array(370 'xmlrpc' => array(371 'specUrl' => 'http://www.xmlrpc.com/spec',372 'specVersion' => 1373 ),374 'faults_interop' => array(375 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',376 'specVersion' => 20010516377 ),378 'system.multicall' => array(379 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',380 'specVersion' => 1381 ),382 ); 383 }384 function getCapabilities($args) {385 return $this->capabilities;386 }387 function setCallbacks() {388 $this->callbacks['system.getCapabilities'] = 'this:getCapabilities';389 $this->callbacks['system.listMethods'] = 'this:listMethods';390 $this->callbacks['system.multicall'] = 'this:multiCall';391 }392 function listMethods($args) {393 // Returns a list of methods - uses array_reverse to ensure user defined394 // methods are listed before server defined methods395 return array_reverse(array_keys($this->callbacks));396 }397 function multiCall($methodcalls) {398 // See http://www.xmlrpc.com/discuss/msgReader$1208399 $return = array();400 foreach ($methodcalls as $call) {401 $method = $call['methodName'];402 $params = $call['params'];403 if ($method == 'system.multicall') {404 $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden');405 } else {406 $result = $this->call($method, $params);407 }408 if (is_a($result, 'IXR_Error')) {409 $return[] = array(410 'faultCode' => $result->code,411 'faultString' => $result->message412 );413 } else {414 $return[] = array($result);415 }416 }417 return $return;418 }346 function error($error, $message = false) { 347 // Accepts either an error object or an error code and message 348 if ($message && !is_object($error)) { 349 $error = new IXR_Error($error, $message); 350 } 351 $this->output($error->getXml()); 352 } 353 function output($xml) { 354 $xml = '<?xml version="1.0"?>'."\n".$xml; 355 $length = strlen($xml); 356 header('Connection: close'); 357 header('Content-Length: '.$length); 358 header('Content-Type: text/xml'); 359 header('Date: '.date('r')); 360 echo $xml; 361 exit; 362 } 363 function hasMethod($method) { 364 return in_array($method, array_keys($this->callbacks)); 365 } 366 function setCapabilities() { 367 // Initialises capabilities array 368 $this->capabilities = array( 369 'xmlrpc' => array( 370 'specUrl' => 'http://www.xmlrpc.com/spec', 371 'specVersion' => 1 372 ), 373 'faults_interop' => array( 374 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', 375 'specVersion' => 20010516 376 ), 377 'system.multicall' => array( 378 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', 379 'specVersion' => 1 380 ), 381 ); 382 } 383 function getCapabilities($args) { 384 return $this->capabilities; 385 } 386 function setCallbacks() { 387 $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; 388 $this->callbacks['system.listMethods'] = 'this:listMethods'; 389 $this->callbacks['system.multicall'] = 'this:multiCall'; 390 } 391 function listMethods($args) { 392 // Returns a list of methods - uses array_reverse to ensure user defined 393 // methods are listed before server defined methods 394 return array_reverse(array_keys($this->callbacks)); 395 } 396 function multiCall($methodcalls) { 397 // See http://www.xmlrpc.com/discuss/msgReader$1208 398 $return = array(); 399 foreach ($methodcalls as $call) { 400 $method = $call['methodName']; 401 $params = $call['params']; 402 if ($method == 'system.multicall') { 403 $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); 404 } else { 405 $result = $this->call($method, $params); 406 } 407 if (is_a($result, 'IXR_Error')) { 408 $return[] = array( 409 'faultCode' => $result->code, 410 'faultString' => $result->message 411 ); 412 } else { 413 $return[] = array($result); 414 } 415 } 416 return $return; 417 } 419 418 } 420 419 421 420 class IXR_Request { 422 var $method;423 var $args;424 var $xml;425 function IXR_Request($method, $args) {426 $this->method = $method;427 $this->args = $args;428 $this->xml = <<<EOD421 var $method; 422 var $args; 423 var $xml; 424 function IXR_Request($method, $args) { 425 $this->method = $method; 426 $this->args = $args; 427 $this->xml = <<<EOD 429 428 <?xml version="1.0"?> 430 429 <methodCall> 431 430 <methodName>{$this->method}</methodName> 432 431 <params> 433 432 434 433 EOD; 435 foreach ($this->args as $arg) {436 $this->xml .= '<param><value>';437 $v = new IXR_Value($arg);438 $this->xml .= $v->getXml();439 $this->xml .= "</value></param>\n";440 }441 $this->xml .= '</params></methodCall>';442 }443 function getLength() {444 return strlen($this->xml);445 }446 function getXml() {447 return $this->xml;448 }434 foreach ($this->args as $arg) { 435 $this->xml .= '<param><value>'; 436 $v = new IXR_Value($arg); 437 $this->xml .= $v->getXml(); 438 $this->xml .= "</value></param>\n"; 439 } 440 $this->xml .= '</params></methodCall>'; 441 } 442 function getLength() { 443 return strlen($this->xml); 444 } 445 function getXml() { 446 return $this->xml; 447 } 449 448 } 450 449 451 450 452 451 class IXR_Client { 453 var $server;454 var $port;455 var $path;456 var $useragent;457 var $response;458 var $message = false;459 var $debug = false;452 var $server; 453 var $port; 454 var $path; 455 var $useragent; 456 var $response; 457 var $message = false; 458 var $debug = false; 460 459 var $timeout; 461 // Storage place for an error message462 var $error = false;463 function IXR_Client($server, $path = false, $port = 80, $timeout = false) {464 if (!$path) {465 // Assume we have been given a URL instead466 $bits = parse_url($server);467 $this->server = $bits['host'];468 $this->port = isset($bits['port']) ? $bits['port'] : 80;469 $this->path = isset($bits['path']) ? $bits['path'] : '/';470 // Make absolutely sure we have a path471 if (!$this->path) {472 $this->path = '/';473 }474 } else {475 $this->server = $server;476 $this->path = $path;477 $this->port = $port;478 }479 $this->useragent = 'Incutio XML-RPC';460 // Storage place for an error message 461 var $error = false; 462 function IXR_Client($server, $path = false, $port = 80, $timeout = false) { 463 if (!$path) { 464 // Assume we have been given a URL instead 465 $bits = parse_url($server); 466 $this->server = $bits['host']; 467 $this->port = isset($bits['port']) ? $bits['port'] : 80; 468 $this->path = isset($bits['path']) ? $bits['path'] : '/'; 469 // Make absolutely sure we have a path 470 if (!$this->path) { 471 $this->path = '/'; 472 } 473 } else { 474 $this->server = $server; 475 $this->path = $path; 476 $this->port = $port; 477 } 478 $this->useragent = 'Incutio XML-RPC'; 480 479 $this->timeout = $timeout; 481 }482 function query() {483 $args = func_get_args();484 $method = array_shift($args);485 $request = new IXR_Request($method, $args);486 $length = $request->getLength();487 $xml = $request->getXml();488 $r = "\r\n";489 $request = "POST {$this->path} HTTP/1.0$r";490 $request .= "Host: {$this->server}$r";491 $request .= "Content-Type: text/xml$r";492 $request .= "User-Agent: {$this->useragent}$r";493 $request .= "Content-length: {$length}$r$r";494 $request .= $xml;495 // Now send the request496 if ($this->debug) {497 echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n";498 }499 if ($this->timeout) {500 $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);501 } else {502 $fp = @fsockopen($this->server, $this->port, $errno, $errstr);503 }504 if (!$fp) {505 $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr");506 return false;507 }508 fputs($fp, $request);509 $contents = '';510 $gotFirstLine = false;511 $gettingHeaders = true;512 while (!feof($fp)) {513 $line = fgets($fp, 4096);514 if (!$gotFirstLine) {515 // Check line for '200'516 if (strstr($line, '200') === false) {517 $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');518 return false;519 }520 $gotFirstLine = true;521 }522 if (trim($line) == '') {523 $gettingHeaders = false;524 }525 if (!$gettingHeaders) {526 $contents .= trim($line)."\n";527 }528 }529 if ($this->debug) {530 echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n";531 }532 // Now parse what we've got back533 $this->message = new IXR_Message($contents);534 if (!$this->message->parse()) {535 // XML error536 $this->error = new IXR_Error(-32700, 'parse error. not well formed');537 return false;538 }539 // Is the message a fault?540 if ($this->message->messageType == 'fault') {541 $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);542 return false;543 }544 // Message must be OK545 return true;546 }547 function getResponse() {548 // methodResponses can only have one param - return that549 return $this->message->params[0];550 }551 function isError() {552 return (is_object($this->error));553 }554 function getErrorCode() {555 return $this->error->code;556 }557 function getErrorMessage() {558 return $this->error->message;559 }480 } 481 function query() { 482 $args = func_get_args(); 483 $method = array_shift($args); 484 $request = new IXR_Request($method, $args); 485 $length = $request->getLength(); 486 $xml = $request->getXml(); 487 $r = "\r\n"; 488 $request = "POST {$this->path} HTTP/1.0$r"; 489 $request .= "Host: {$this->server}$r"; 490 $request .= "Content-Type: text/xml$r"; 491 $request .= "User-Agent: {$this->useragent}$r"; 492 $request .= "Content-length: {$length}$r$r"; 493 $request .= $xml; 494 // Now send the request 495 if ($this->debug) { 496 echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n"; 497 } 498 if ($this->timeout) { 499 $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); 500 } else { 501 $fp = @fsockopen($this->server, $this->port, $errno, $errstr); 502 } 503 if (!$fp) { 504 $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr"); 505 return false; 506 } 507 fputs($fp, $request); 508 $contents = ''; 509 $gotFirstLine = false; 510 $gettingHeaders = true; 511 while (!feof($fp)) { 512 $line = fgets($fp, 4096); 513 if (!$gotFirstLine) { 514 // Check line for '200' 515 if (strstr($line, '200') === false) { 516 $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); 517 return false; 518 } 519 $gotFirstLine = true; 520 } 521 if (trim($line) == '') { 522 $gettingHeaders = false; 523 } 524 if (!$gettingHeaders) { 525 $contents .= trim($line)."\n"; 526 } 527 } 528 if ($this->debug) { 529 echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n"; 530 } 531 // Now parse what we've got back 532 $this->message = new IXR_Message($contents); 533 if (!$this->message->parse()) { 534 // XML error 535 $this->error = new IXR_Error(-32700, 'parse error. not well formed'); 536 return false; 537 } 538 // Is the message a fault? 539 if ($this->message->messageType == 'fault') { 540 $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); 541 return false; 542 } 543 // Message must be OK 544 return true; 545 } 546 function getResponse() { 547 // methodResponses can only have one param - return that 548 return $this->message->params[0]; 549 } 550 function isError() { 551 return (is_object($this->error)); 552 } 553 function getErrorCode() { 554 return $this->error->code; 555 } 556 function getErrorMessage() { 557 return $this->error->message; 558 } 560 559 } 561 560 562 561 563 562 class IXR_Error { 564 var $code;565 var $message;566 function IXR_Error($code, $message) {567 $this->code = $code;568 $this->message = $message;569 }570 function getXml() {571 $xml = <<<EOD563 var $code; 564 var $message; 565 function IXR_Error($code, $message) { 566 $this->code = $code; 567 $this->message = $message; 568 } 569 function getXml() { 570 $xml = <<<EOD 572 571 <methodResponse> 573 <fault>574 <value>575 <struct>576 <member>577 <name>faultCode</name>578 <value><int>{$this->code}</int></value>579 </member>580 <member>581 <name>faultString</name>582 <value><string>{$this->message}</string></value>583 </member>584 </struct>585 </value>586 </fault>587 </methodResponse> 572 <fault> 573 <value> 574 <struct> 575 <member> 576 <name>faultCode</name> 577 <value><int>{$this->code}</int></value> 578 </member> 579 <member> 580 <name>faultString</name> 581 <value><string>{$this->message}</string></value> 582 </member> 583 </struct> 584 </value> 585 </fault> 586 </methodResponse> 588 587 589 588 EOD; 590 return $xml;591 }589 return $xml; 590 } 592 591 } 593 592 594 593 595 594 class IXR_Date { 596 var $year;597 var $month;598 var $day;599 var $hour;600 var $minute;601 var $second;602 function IXR_Date($time) {603 // $time can be a PHP timestamp or an ISO one604 if (is_numeric($time)) {605 $this->parseTimestamp($time);606 } else {607 $this->parseIso($time);608 }609 }610 function parseTimestamp($timestamp) {611 $this->year = date('Y', $timestamp);612 $this->month = date('m', $timestamp);613 $this->day = date('d', $timestamp);614 $this->hour = date('H', $timestamp);615 $this->minute = date('i', $timestamp);616 $this->second = date('s', $timestamp);617 }618 function parseIso($iso) {619 $this->year = substr($iso, 0, 4);620 $this->month = substr($iso, 4, 2);621 $this->day = substr($iso, 6, 2);622 $this->hour = substr($iso, 9, 2);623 $this->minute = substr($iso, 12, 2);624 $this->second = substr($iso, 15, 2);625 $this->timezone = substr($iso, 17);626 }627 function getIso() {628 return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;629 }630 function getXml() {631 return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';632 }633 function getTimestamp() {634 return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);635 }595 var $year; 596 var $month; 597 var $day; 598 var $hour; 599 var $minute; 600 var $second; 601 function IXR_Date($time) { 602 // $time can be a PHP timestamp or an ISO one 603 if (is_numeric($time)) { 604 $this->parseTimestamp($time); 605 } else { 606 $this->parseIso($time); 607 } 608 } 609 function parseTimestamp($timestamp) { 610 $this->year = date('Y', $timestamp); 611 $this->month = date('m', $timestamp); 612 $this->day = date('d', $timestamp); 613 $this->hour = date('H', $timestamp); 614 $this->minute = date('i', $timestamp); 615 $this->second = date('s', $timestamp); 616 } 617 function parseIso($iso) { 618 $this->year = substr($iso, 0, 4); 619 $this->month = substr($iso, 4, 2); 620 $this->day = substr($iso, 6, 2); 621 $this->hour = substr($iso, 9, 2); 622 $this->minute = substr($iso, 12, 2); 623 $this->second = substr($iso, 15, 2); 624 $this->timezone = substr($iso, 17); 625 } 626 function getIso() { 627 return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; 628 } 629 function getXml() { 630 return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; 631 } 632 function getTimestamp() { 633 return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); 634 } 636 635 } 637 636 638 637 639 638 class IXR_Base64 { 640 var $data;641 function IXR_Base64($data) {642 $this->data = $data;643 }644 function getXml() {645 return '<base64>'.base64_encode($this->data).'</base64>';646 }639 var $data; 640 function IXR_Base64($data) { 641 $this->data = $data; 642 } 643 function getXml() { 644 return '<base64>'.base64_encode($this->data).'</base64>'; 645 } 647 646 } 648 647 649 648 650 649 class IXR_IntrospectionServer extends IXR_Server { 651 var $signatures;652 var $help;653 function IXR_IntrospectionServer() {654 $this->setCallbacks();655 $this->setCapabilities();656 $this->capabilities['introspection'] = array(657 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',658 'specVersion' => 1659 );660 $this->addCallback(661 'system.methodSignature', 662 'this:methodSignature', 663 array('array', 'string'), 664 'Returns an array describing the return type and required parameters of a method'665 );666 $this->addCallback(667 'system.getCapabilities', 668 'this:getCapabilities', 669 array('struct'), 670 'Returns a struct describing the XML-RPC specifications supported by this server'671 );672 $this->addCallback(673 'system.listMethods', 674 'this:listMethods', 675 array('array'), 676 'Returns an array of available methods on this server'677 );678 $this->addCallback(679 'system.methodHelp', 680 'this:methodHelp', 681 array('string', 'string'), 682 'Returns a documentation string for the specified method'683 );684 }685 function addCallback($method, $callback, $args, $help) {686 $this->callbacks[$method] = $callback;687 $this->signatures[$method] = $args;688 $this->help[$method] = $help;689 }690 function call($methodname, $args) {691 // Make sure it's in an array692 if ($args && !is_array($args)) {693 $args = array($args);694 }695 // Over-rides default call method, adds signature check696 if (!$this->hasMethod($methodname)) {697 return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');698 }699 $method = $this->callbacks[$methodname];700 $signature = $this->signatures[$methodname];701 $returnType = array_shift($signature);702 // Check the number of arguments703 if (count($args) != count($signature)) {704 return new IXR_Error(-32602, 'server error. wrong number of method parameters');705 }706 // Check the argument types707 $ok = true;708 $argsbackup = $args;709 for ($i = 0, $j = count($args); $i < $j; $i++) {710 $arg = array_shift($args);711 $type = array_shift($signature);712 switch ($type) {713 case 'int':714 case 'i4':715 if (is_array($arg) || !is_int($arg)) {716 $ok = false;717 }718 break;719 case 'base64':720 case 'string':721 if (!is_string($arg)) {722 $ok = false;723 }724 break;725 case 'boolean':726 if ($arg !== false && $arg !== true) {727 $ok = false;728 }729 break;730 case 'float':731 case 'double':732 if (!is_float($arg)) {733 $ok = false;734 }735 break;736 case 'date':737 case 'dateTime.iso8601':738 if (!is_a($arg, 'IXR_Date')) {739 $ok = false;740 }741 break;742 }743 if (!$ok) {744 return new IXR_Error(-32602, 'server error. invalid method parameters');745 }746 }747 // It passed the test - run the "real" method call748 return parent::call($methodname, $argsbackup);749 }750 function methodSignature($method) {751 if (!$this->hasMethod($method)) {752 return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');753 }754 // We should be returning an array of types755 $types = $this->signatures[$method];756 $return = array();757 foreach ($types as $type) {758 switch ($type) {759 case 'string':760 $return[] = 'string';761 break;762 case 'int':763 case 'i4':764 $return[] = 42;765 break;766 case 'double':767 $return[] = 3.1415;768 break;769 case 'dateTime.iso8601':770 $return[] = new IXR_Date(time());771 break;772 case 'boolean':773 $return[] = true;774 break;775 case 'base64':776 $return[] = new IXR_Base64('base64');777 break;778 case 'array':779 $return[] = array('array');780 break;781 case 'struct':782 $return[] = array('struct' => 'struct');783 break;784 }785 }786 return $return;787 }788 function methodHelp($method) {789 return $this->help[$method];790 }650 var $signatures; 651 var $help; 652 function IXR_IntrospectionServer() { 653 $this->setCallbacks(); 654 $this->setCapabilities(); 655 $this->capabilities['introspection'] = array( 656 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', 657 'specVersion' => 1 658 ); 659 $this->addCallback( 660 'system.methodSignature', 661 'this:methodSignature', 662 array('array', 'string'), 663 'Returns an array describing the return type and required parameters of a method' 664 ); 665 $this->addCallback( 666 'system.getCapabilities', 667 'this:getCapabilities', 668 array('struct'), 669 'Returns a struct describing the XML-RPC specifications supported by this server' 670 ); 671 $this->addCallback( 672 'system.listMethods', 673 'this:listMethods', 674 array('array'), 675 'Returns an array of available methods on this server' 676 ); 677 $this->addCallback( 678 'system.methodHelp', 679 'this:methodHelp', 680 array('string', 'string'), 681 'Returns a documentation string for the specified method' 682 ); 683 } 684 function addCallback($method, $callback, $args, $help) { 685 $this->callbacks[$method] = $callback; 686 $this->signatures[$method] = $args; 687 $this->help[$method] = $help; 688 } 689 function call($methodname, $args) { 690 // Make sure it's in an array 691 if ($args && !is_array($args)) { 692 $args = array($args); 693 } 694 // Over-rides default call method, adds signature check 695 if (!$this->hasMethod($methodname)) { 696 return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); 697 } 698 $method = $this->callbacks[$methodname]; 699 $signature = $this->signatures[$methodname]; 700 $returnType = array_shift($signature); 701 // Check the number of arguments 702 if (count($args) != count($signature)) { 703 return new IXR_Error(-32602, 'server error. wrong number of method parameters'); 704 } 705 // Check the argument types 706 $ok = true; 707 $argsbackup = $args; 708 for ($i = 0, $j = count($args); $i < $j; $i++) { 709 $arg = array_shift($args); 710 $type = array_shift($signature); 711 switch ($type) { 712 case 'int': 713 case 'i4': 714 if (is_array($arg) || !is_int($arg)) { 715 $ok = false; 716 } 717 break; 718 case 'base64': 719 case 'string': 720 if (!is_string($arg)) { 721 $ok = false; 722 } 723 break; 724 case 'boolean': 725 if ($arg !== false && $arg !== true) { 726 $ok = false; 727 } 728 break; 729 case 'float': 730 case 'double': 731 if (!is_float($arg)) { 732 $ok = false; 733 } 734 break; 735 case 'date': 736 case 'dateTime.iso8601': 737 if (!is_a($arg, 'IXR_Date')) { 738 $ok = false; 739 } 740 break; 741 } 742 if (!$ok) { 743 return new IXR_Error(-32602, 'server error. invalid method parameters'); 744 } 745 } 746 // It passed the test - run the "real" method call 747 return parent::call($methodname, $argsbackup); 748 } 749 function methodSignature($method) { 750 if (!$this->hasMethod($method)) { 751 return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); 752 } 753 // We should be returning an array of types 754 $types = $this->signatures[$method]; 755 $return = array(); 756 foreach ($types as $type) { 757 switch ($type) { 758 case 'string': 759 $return[] = 'string'; 760 break; 761 case 'int': 762 case 'i4': 763 $return[] = 42; 764 break; 765 case 'double': 766 $return[] = 3.1415; 767 break; 768 case 'dateTime.iso8601': 769 $return[] = new IXR_Date(time()); 770 break; 771 case 'boolean': 772 $return[] = true; 773 break; 774 case 'base64': 775 $return[] = new IXR_Base64('base64'); 776 break; 777 case 'array': 778 $return[] = array('array'); 779 break; 780 case 'struct': 781 $return[] = array('struct' => 'struct'); 782 break; 783 } 784 } 785 return $return; 786 } 787 function methodHelp($method) { 788 return $this->help[$method]; 789 } 791 790 } 792 791 793 792 794 793 class IXR_ClientMulticall extends IXR_Client { 795 var $calls = array();796 function IXR_ClientMulticall($server, $path = false, $port = 80) {797 parent::IXR_Client($server, $path, $port);798 $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';799 }800 function addCall() {801 $args = func_get_args();802 $methodName = array_shift($args);803 $struct = array(804 'methodName' => $methodName,805 'params' => $args806 );807 $this->calls[] = $struct;808 }809 function query() {810 // Prepare multicall, then call the parent::query() method811 return parent::query('system.multicall', $this->calls);812 }794 var $calls = array(); 795 function IXR_ClientMulticall($server, $path = false, $port = 80) { 796 parent::IXR_Client($server, $path, $port); 797 $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; 798 } 799 function addCall() { 800 $args = func_get_args(); 801 $methodName = array_shift($args); 802 $struct = array( 803 'methodName' => $methodName, 804 'params' => $args 805 ); 806 $this->calls[] = $struct; 807 } 808 function query() { 809 // Prepare multicall, then call the parent::query() method 810 return parent::query('system.multicall', $this->calls); 811 } 813 812 } 814 813 815 814 ?> 815 No newline at end of file -
wp-includes/class-pop3.php
1 <?php 1 <?php 2 2 3 /**4 * mail_fetch/setup.php5 *6 * Copyright (c) 1999-2002 The SquirrelMail Project Team7 *8 * Copyright (c) 1999 CDI (cdi@thewebmasters.net) All Rights Reserved9 * Modified by Philippe Mingo 2001 mingo@rotedic.com10 * An RFC 1939 compliant wrapper class for the POP3 protocol.11 *12 * Licensed under the GNU GPL. For full terms see the file COPYING.13 *14 * pop3 class15 *16 * $Id$17 */3 /** 4 * mail_fetch/setup.php 5 * 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team 7 * 8 * Copyright (c) 1999 CDI (cdi@thewebmasters.net) All Rights Reserved 9 * Modified by Philippe Mingo 2001 mingo@rotedic.com 10 * An RFC 1939 compliant wrapper class for the POP3 protocol. 11 * 12 * Licensed under the GNU GPL. For full terms see the file COPYING. 13 * 14 * pop3 class 15 * 16 * $Id$ 17 */ 18 18 19 19 class POP3 { 20 var $ERROR = ''; // Error string.20 var $ERROR = ''; // Error string. 21 21 22 var $TIMEOUT = 60; // Default timeout before giving up on a23 // network operation.22 var $TIMEOUT = 60; // Default timeout before giving up on a 23 // network operation. 24 24 25 var $COUNT = -1; // Mailbox msg count25 var $COUNT = -1; // Mailbox msg count 26 26 27 var $BUFFER = 512; // Socket buffer for socket fgets() calls.28 // Per RFC 1939 the returned line a POP329 // server can send is 512 bytes.27 var $BUFFER = 512; // Socket buffer for socket fgets() calls. 28 // Per RFC 1939 the returned line a POP3 29 // server can send is 512 bytes. 30 30 31 var $FP = ''; // The connection to the server's32 // file descriptor31 var $FP = ''; // The connection to the server's 32 // file descriptor 33 33 34 var $MAILSERVER = ''; // Set this to hard code the server name34 var $MAILSERVER = ''; // Set this to hard code the server name 35 35 36 var $DEBUG = FALSE; // set to true to echo pop337 // commands and responses to error_log38 // this WILL log passwords!36 var $DEBUG = FALSE; // set to true to echo pop3 37 // commands and responses to error_log 38 // this WILL log passwords! 39 39 40 var $BANNER = ''; // Holds the banner returned by the41 // pop server - used for apop()40 var $BANNER = ''; // Holds the banner returned by the 41 // pop server - used for apop() 42 42 43 var $RFC1939 = TRUE; // Set by noop(). See rfc1939.txt44 //43 var $RFC1939 = TRUE; // Set by noop(). See rfc1939.txt 44 // 45 45 46 var $ALLOWAPOP = FALSE; // Allow or disallow apop()47 // This must be set to true48 // manually46 var $ALLOWAPOP = FALSE; // Allow or disallow apop() 47 // This must be set to true 48 // manually 49 49 50 function POP3 ( $server = '', $timeout = '' ) {51 settype($this->BUFFER,"integer");52 if( !empty($server) ) {53 // Do not allow programs to alter MAILSERVER54 // if it is already specified. They can get around55 // this if they -really- want to, so don't count on it.56 if(empty($this->MAILSERVER))57 $this->MAILSERVER = $server;58 }59 if(!empty($timeout)) {60 settype($timeout,"integer");61 $this->TIMEOUT = $timeout;62 set_time_limit($timeout);63 }64 return true;65 }50 function POP3 ( $server = '', $timeout = '' ) { 51 settype($this->BUFFER,"integer"); 52 if( !empty($server) ) { 53 // Do not allow programs to alter MAILSERVER 54 // if it is already specified. They can get around 55 // this if they -really- want to, so don't count on it. 56 if(empty($this->MAILSERVER)) 57 $this->MAILSERVER = $server; 58 } 59 if(!empty($timeout)) { 60 settype($timeout,"integer"); 61 $this->TIMEOUT = $timeout; 62 set_time_limit($timeout); 63 } 64 return true; 65 } 66 66 67 function update_timer () {68 set_time_limit($this->TIMEOUT);69 return true;70 }67 function update_timer () { 68 set_time_limit($this->TIMEOUT); 69 return true; 70 } 71 71 72 function connect ($server, $port = 110) {73 // Opens a socket to the specified server. Unless overridden,74 // port defaults to 110. Returns true on success, false on fail72 function connect ($server, $port = 110) { 73 // Opens a socket to the specified server. Unless overridden, 74 // port defaults to 110. Returns true on success, false on fail 75 75 76 // If MAILSERVER is set, override $server with it's value76 // If MAILSERVER is set, override $server with it's value 77 77 78 if(!empty($this->MAILSERVER))79 $server = $this->MAILSERVER;78 if(!empty($this->MAILSERVER)) 79 $server = $this->MAILSERVER; 80 80 81 if(empty($server)){82 $this->ERROR = _("POP3 connect:") . ' ' . _("No server specified");83 unset($this->FP);84 return false;85 }81 if(empty($server)){ 82 $this->ERROR = _("POP3 connect:") . ' ' . _("No server specified"); 83 unset($this->FP); 84 return false; 85 } 86 86 87 $fp = fsockopen("$server", $port, $errno, $errstr);87 $fp = fsockopen("$server", $port, $errno, $errstr); 88 88 89 if(!$fp) {90 $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$errno] [$errstr]";91 unset($this->FP);92 return false;93 }89 if(!$fp) { 90 $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$errno] [$errstr]"; 91 unset($this->FP); 92 return false; 93 } 94 94 95 socket_set_blocking($fp,-1);96 $this->update_timer();97 $reply = fgets($fp,$this->BUFFER);98 $reply = $this->strip_clf($reply);99 if($this->DEBUG)100 error_log("POP3 SEND [connect: $server] GOT [$reply]",0);101 if(!$this->is_ok($reply)) {102 $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$reply]";103 unset($this->FP);104 return false;105 }106 $this->FP = $fp;107 $this->BANNER = $this->parse_banner($reply);108 $this->RFC1939 = $this->noop();109 if($this->RFC1939) {110 $this->ERROR = _("POP3: premature NOOP OK, NOT an RFC 1939 Compliant server");111 $this->quit();112 return false;113 } else114 return true;115 }95 socket_set_blocking($fp,-1); 96 $this->update_timer(); 97 $reply = fgets($fp,$this->BUFFER); 98 $reply = $this->strip_clf($reply); 99 if($this->DEBUG) 100 error_log("POP3 SEND [connect: $server] GOT [$reply]",0); 101 if(!$this->is_ok($reply)) { 102 $this->ERROR = _("POP3 connect:") . ' ' . _("Error ") . "[$reply]"; 103 unset($this->FP); 104 return false; 105 } 106 $this->FP = $fp; 107 $this->BANNER = $this->parse_banner($reply); 108 $this->RFC1939 = $this->noop(); 109 if($this->RFC1939) { 110 $this->ERROR = _("POP3: premature NOOP OK, NOT an RFC 1939 Compliant server"); 111 $this->quit(); 112 return false; 113 } else 114 return true; 115 } 116 116 117 function noop () { 118 119 if(!isset($this->FP)) { 120 $this->ERROR = _("POP3 noop:") . ' ' . _("No connection to server"); 121 return false; 122 } else { 123 $cmd = "NOOP"; 124 $reply = $this->send_cmd( $cmd ); 125 return( $this->is_ok( $reply ) ); 126 } 127 } 117 function noop () { 128 118 129 function user ($user = "") { 130 // Sends the USER command, returns true or false 119 if(!isset($this->FP)) { 120 $this->ERROR = _("POP3 noop:") . ' ' . _("No connection to server"); 121 return false; 122 } else { 123 $cmd = "NOOP"; 124 $reply = $this->send_cmd( $cmd ); 125 return( $this->is_ok( $reply ) ); 126 } 127 } 131 128 132 if( empty($user) ) { 133 $this->ERROR = _("POP3 user:") . ' ' . _("no login ID submitted"); 134 return false; 135 } elseif(!isset($this->FP)) { 136 $this->ERROR = _("POP3 user:") . ' ' . _("connection not established"); 137 return false; 138 } else { 139 $reply = $this->send_cmd("USER $user"); 140 if(!$this->is_ok($reply)) { 141 $this->ERROR = _("POP3 user:") . ' ' . _("Error ") . "[$reply]"; 142 return false; 143 } else 144 return true; 145 } 146 } 129 function user ($user = "") { 130 // Sends the USER command, returns true or false 147 131 148 function pass ($pass = "") { 149 // Sends the PASS command, returns # of msgs in mailbox, 150 // returns false (undef) on Auth failure 132 if( empty($user) ) { 133 $this->ERROR = _("POP3 user:") . ' ' . _("no login ID submitted"); 134 return false; 135 } elseif(!isset($this->FP)) { 136 $this->ERROR = _("POP3 user:") . ' ' . _("connection not established"); 137 return false; 138 } else { 139 $reply = $this->send_cmd("USER $user"); 140 if(!$this->is_ok($reply)) { 141 $this->ERROR = _("POP3 user:") . ' ' . _("Error ") . "[$reply]"; 142 return false; 143 } else 144 return true; 145 } 146 } 151 147 152 if(empty($pass)) { 153 $this->ERROR = _("POP3 pass:") . ' ' . _("No password submitted"); 154 return false; 155 } elseif(!isset($this->FP)) { 156 $this->ERROR = _("POP3 pass:") . ' ' . _("connection not established"); 157 return false; 158 } else { 159 $reply = $this->send_cmd("PASS $pass"); 160 if(!$this->is_ok($reply)) { 161 $this->ERROR = _("POP3 pass:") . ' ' . _("authentication failed ") . "[$reply]"; 162 $this->quit(); 163 return false; 164 } else { 165 // Auth successful. 166 $count = $this->last("count"); 167 $this->COUNT = $count; 168 $this->RFC1939 = $this->noop(); 169 if(!$this->RFC1939) { 170 $this->ERROR = _("POP3 pass:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant"); 171 $this->quit(); 172 return false; 173 } else 174 return $count; 175 } 176 } 177 } 148 function pass ($pass = "") { 149 // Sends the PASS command, returns # of msgs in mailbox, 150 // returns false (undef) on Auth failure 178 151 179 function apop ($login,$pass) { 180 // Attempts an APOP login. If this fails, it'll 181 // try a standard login. YOUR SERVER MUST SUPPORT 182 // THE USE OF THE APOP COMMAND! 183 // (apop is optional per rfc1939) 152 if(empty($pass)) { 153 $this->ERROR = _("POP3 pass:") . ' ' . _("No password submitted"); 154 return false; 155 } elseif(!isset($this->FP)) { 156 $this->ERROR = _("POP3 pass:") . ' ' . _("connection not established"); 157 return false; 158 } else { 159 $reply = $this->send_cmd("PASS $pass"); 160 if(!$this->is_ok($reply)) { 161 $this->ERROR = _("POP3 pass:") . ' ' . _("authentication failed ") . "[$reply]"; 162 $this->quit(); 163 return false; 164 } else { 165 // Auth successful. 166 $count = $this->last("count"); 167 $this->COUNT = $count; 168 $this->RFC1939 = $this->noop(); 169 if(!$this->RFC1939) { 170 $this->ERROR = _("POP3 pass:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant"); 171 $this->quit(); 172 return false; 173 } else 174 return $count; 175 } 176 } 177 } 184 178 185 if(!isset($this->FP)) { 186 $this->ERROR = _("POP3 apop:") . ' ' . _("No connection to server"); 187 return false; 188 } elseif(!$this->ALLOWAPOP) { 189 $retVal = $this->login($login,$pass); 190 return $retVal; 191 } elseif(empty($login)) { 192 $this->ERROR = _("POP3 apop:") . ' ' . _("No login ID submitted"); 193 return false; 194 } elseif(empty($pass)) { 195 $this->ERROR = _("POP3 apop:") . ' ' . _("No password submitted"); 196 return false; 197 } else { 198 $banner = $this->BANNER; 199 if( (!$banner) or (empty($banner)) ) { 200 $this->ERROR = _("POP3 apop:") . ' ' . _("No server banner") . ' - ' . _("abort"); 201 $retVal = $this->login($login,$pass); 202 return $retVal; 203 } else { 204 $AuthString = $banner; 205 $AuthString .= $pass; 206 $APOPString = md5($AuthString); 207 $cmd = "APOP $login $APOPString"; 208 $reply = $this->send_cmd($cmd); 209 if(!$this->is_ok($reply)) { 210 $this->ERROR = _("POP3 apop:") . ' ' . _("apop authentication failed") . ' - ' . _("abort"); 211 $retVal = $this->login($login,$pass); 212 return $retVal; 213 } else { 214 // Auth successful. 215 $count = $this->last("count"); 216 $this->COUNT = $count; 217 $this->RFC1939 = $this->noop(); 218 if(!$this->RFC1939) { 219 $this->ERROR = _("POP3 apop:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant"); 220 $this->quit(); 221 return false; 222 } else 223 return $count; 224 } 225 } 226 } 227 } 179 function apop ($login,$pass) { 180 // Attempts an APOP login. If this fails, it'll 181 // try a standard login. YOUR SERVER MUST SUPPORT 182 // THE USE OF THE APOP COMMAND! 183 // (apop is optional per rfc1939) 228 184 229 function login ($login = "", $pass = "") { 230 // Sends both user and pass. Returns # of msgs in mailbox or 231 // false on failure (or -1, if the error occurs while getting 232 // the number of messages.) 185 if(!isset($this->FP)) { 186 $this->ERROR = _("POP3 apop:") . ' ' . _("No connection to server"); 187 return false; 188 } elseif(!$this->ALLOWAPOP) { 189 $retVal = $this->login($login,$pass); 190 return $retVal; 191 } elseif(empty($login)) { 192 $this->ERROR = _("POP3 apop:") . ' ' . _("No login ID submitted"); 193 return false; 194 } elseif(empty($pass)) { 195 $this->ERROR = _("POP3 apop:") . ' ' . _("No password submitted"); 196 return false; 197 } else { 198 $banner = $this->BANNER; 199 if( (!$banner) or (empty($banner)) ) { 200 $this->ERROR = _("POP3 apop:") . ' ' . _("No server banner") . ' - ' . _("abort"); 201 $retVal = $this->login($login,$pass); 202 return $retVal; 203 } else { 204 $AuthString = $banner; 205 $AuthString .= $pass; 206 $APOPString = md5($AuthString); 207 $cmd = "APOP $login $APOPString"; 208 $reply = $this->send_cmd($cmd); 209 if(!$this->is_ok($reply)) { 210 $this->ERROR = _("POP3 apop:") . ' ' . _("apop authentication failed") . ' - ' . _("abort"); 211 $retVal = $this->login($login,$pass); 212 return $retVal; 213 } else { 214 // Auth successful. 215 $count = $this->last("count"); 216 $this->COUNT = $count; 217 $this->RFC1939 = $this->noop(); 218 if(!$this->RFC1939) { 219 $this->ERROR = _("POP3 apop:") . ' ' . _("NOOP failed. Server not RFC 1939 compliant"); 220 $this->quit(); 221 return false; 222 } else 223 return $count; 224 } 225 } 226 } 227 } 233 228 234 if( !isset($this->FP) ) { 235 $this->ERROR = _("POP3 login:") . ' ' . _("No connection to server"); 236 return false; 237 } else { 238 $fp = $this->FP; 239 if( !$this->user( $login ) ) { 240 // Preserve the error generated by user() 241 return false; 242 } else { 243 $count = $this->pass($pass); 244 if( (!$count) || ($count == -1) ) { 245 // Preserve the error generated by last() and pass() 246 return false; 247 } else 248 return $count; 249 } 250 } 251 } 229 function login ($login = "", $pass = "") { 230 // Sends both user and pass. Returns # of msgs in mailbox or 231 // false on failure (or -1, if the error occurs while getting 232 // the number of messages.) 252 233 253 function top ($msgNum, $numLines = "0") { 254 // Gets the header and first $numLines of the msg body 255 // returns data in an array with each returned line being 256 // an array element. If $numLines is empty, returns 257 // only the header information, and none of the body. 234 if( !isset($this->FP) ) { 235 $this->ERROR = _("POP3 login:") . ' ' . _("No connection to server"); 236 return false; 237 } else { 238 $fp = $this->FP; 239 if( !$this->user( $login ) ) { 240 // Preserve the error generated by user() 241 return false; 242 } else { 243 $count = $this->pass($pass); 244 if( (!$count) || ($count == -1) ) { 245 // Preserve the error generated by last() and pass() 246 return false; 247 } else 248 return $count; 249 } 250 } 251 } 258 252 259 if(!isset($this->FP)) {260 $this->ERROR = _("POP3 top:") . ' ' . _("No connection to server"); 261 return false; 262 } 263 $this->update_timer(); 253 function top ($msgNum, $numLines = "0") { 254 // Gets the header and first $numLines of the msg body 255 // returns data in an array with each returned line being 256 // an array element. If $numLines is empty, returns 257 // only the header information, and none of the body. 264 258 265 $fp = $this->FP; 266 $buffer = $this->BUFFER; 267 $cmd = "TOP $msgNum $numLines"; 268 fwrite($fp, "TOP $msgNum $numLines\r\n"); 269 $reply = fgets($fp, $buffer); 270 $reply = $this->strip_clf($reply); 271 if($this->DEBUG) { 272 @error_log("POP3 SEND [$cmd] GOT [$reply]",0); 273 } 274 if(!$this->is_ok($reply)) 275 { 276 $this->ERROR = _("POP3 top:") . ' ' . _("Error ") . "[$reply]"; 277 return false; 278 } 259 if(!isset($this->FP)) { 260 $this->ERROR = _("POP3 top:") . ' ' . _("No connection to server"); 261 return false; 262 } 263 $this->update_timer(); 279 264 280 $count = 0; 281 $MsgArray = array(); 265 $fp = $this->FP; 266 $buffer = $this->BUFFER; 267 $cmd = "TOP $msgNum $numLines"; 268 fwrite($fp, "TOP $msgNum $numLines\r\n"); 269 $reply = fgets($fp, $buffer); 270 $reply = $this->strip_clf($reply); 271 if($this->DEBUG) { 272 @error_log("POP3 SEND [$cmd] GOT [$reply]",0); 273 } 274 if(!$this->is_ok($reply)) 275 { 276 $this->ERROR = _("POP3 top:") . ' ' . _("Error ") . "[$reply]"; 277 return false; 278 } 282 279 283 $line = fgets($fp,$buffer); 284 while ( !ereg("^\.\r\n",$line)) 285 { 286 $MsgArray[$count] = $line; 287 $count++; 288 $line = fgets($fp,$buffer); 289 if(empty($line)) { break; } 290 } 280 $count = 0; 281 $MsgArray = array(); 291 282 292 return $MsgArray; 293 } 283 $line = fgets($fp,$buffer); 284 while ( !ereg("^\.\r\n",$line)) 285 { 286 $MsgArray[$count] = $line; 287 $count++; 288 $line = fgets($fp,$buffer); 289 if(empty($line)) { break; } 290 } 294 291 295 function pop_list ($msgNum = "") { 296 // If called with an argument, returns that msgs' size in octets 297 // No argument returns an associative array of undeleted 298 // msg numbers and their sizes in octets 292 return $MsgArray; 293 } 299 294 300 if(!isset($this->FP)) 301 { 302 $this->ERROR = _("POP3 pop_list:") . ' ' . _("No connection to server"); 303 return false; 304 } 305 $fp = $this->FP; 306 $Total = $this->COUNT; 307 if( (!$Total) or ($Total == -1) ) 308 { 309 return false; 310 } 311 if($Total == 0) 312 { 313 return array("0","0"); 314 // return -1; // mailbox empty 315 } 295 function pop_list ($msgNum = "") { 296 // If called with an argument, returns that msgs' size in octets 297 // No argument returns an associative array of undeleted 298 // msg numbers and their sizes in octets 316 299 317 $this->update_timer(); 300 if(!isset($this->FP)) 301 { 302 $this->ERROR = _("POP3 pop_list:") . ' ' . _("No connection to server"); 303 return false; 304 } 305 $fp = $this->FP; 306 $Total = $this->COUNT; 307 if( (!$Total) or ($Total == -1) ) 308 { 309 return false; 310 } 311 if($Total == 0) 312 { 313 return array("0","0"); 314 // return -1; // mailbox empty 315 } 318 316 319 if(!empty($msgNum)) 320 { 321 $cmd = "LIST $msgNum"; 322 fwrite($fp,"$cmd\r\n"); 323 $reply = fgets($fp,$this->BUFFER); 324 $reply = $this->strip_clf($reply); 325 if($this->DEBUG) { 326 @error_log("POP3 SEND [$cmd] GOT [$reply]",0); 327 } 328 if(!$this->is_ok($reply)) 329 { 330 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") . "[$reply]"; 331 return false; 332 } 333 list($junk,$num,$size) = explode(" ",$reply); 334 return $size; 335 } 336 $cmd = "LIST"; 337 $reply = $this->send_cmd($cmd); 338 if(!$this->is_ok($reply)) 339 { 340 $reply = $this->strip_clf($reply); 341 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") . "[$reply]"; 342 return false; 343 } 344 $MsgArray = array(); 345 $MsgArray[0] = $Total; 346 for($msgC=1;$msgC <= $Total; $msgC++) 347 { 348 if($msgC > $Total) { break; } 349 $line = fgets($fp,$this->BUFFER); 350 $line = $this->strip_clf($line); 351 if(ereg("^\.",$line)) 352 { 353 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Premature end of list"); 354 return false; 355 } 356 list($thisMsg,$msgSize) = explode(" ",$line); 357 settype($thisMsg,"integer"); 358 if($thisMsg != $msgC) 359 { 360 $MsgArray[$msgC] = "deleted"; 361 } 362 else 363 { 364 $MsgArray[$msgC] = $msgSize; 365 } 366 } 367 return $MsgArray; 368 } 317 $this->update_timer(); 369 318 370 function get ($msgNum) { 371 // Retrieve the specified msg number. Returns an array 372 // where each line of the msg is an array element. 319 if(!empty($msgNum)) 320 { 321 $cmd = "LIST $msgNum"; 322 fwrite($fp,"$cmd\r\n"); 323 $reply = fgets($fp,$this->BUFFER); 324 $reply = $this->strip_clf($reply); 325 if($this->DEBUG) { 326 @error_log("POP3 SEND [$cmd] GOT [$reply]",0); 327 } 328 if(!$this->is_ok($reply)) 329 { 330 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") . "[$reply]"; 331 return false; 332 } 333 list($junk,$num,$size) = explode(" ",$reply); 334 return $size; 335 } 336 $cmd = "LIST"; 337 $reply = $this->send_cmd($cmd); 338 if(!$this->is_ok($reply)) 339 { 340 $reply = $this->strip_clf($reply); 341 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Error ") . "[$reply]"; 342 return false; 343 } 344 $MsgArray = array(); 345 $MsgArray[0] = $Total; 346 for($msgC=1;$msgC <= $Total; $msgC++) 347 { 348 if($msgC > $Total) { break; } 349 $line = fgets($fp,$this->BUFFER); 350 $line = $this->strip_clf($line); 351 if(ereg("^\.",$line)) 352 { 353 $this->ERROR = _("POP3 pop_list:") . ' ' . _("Premature end of list"); 354 return false; 355 } 356 list($thisMsg,$msgSize) = explode(" ",$line); 357 settype($thisMsg,"integer"); 358 if($thisMsg != $msgC) 359 { 360 $MsgArray[$msgC] = "deleted"; 361 } 362 else 363 { 364 $MsgArray[$msgC] = $msgSize; 365 } 366 } 367 return $MsgArray; 368 } 373 369 374 if(!isset($this->FP)) 375 { 376 $this->ERROR = _("POP3 get:") . ' ' . _("No connection to server"); 377 return false; 378 } 370 function get ($msgNum) { 371 // Retrieve the specified msg number. Returns an array 372 // where each line of the msg is an array element. 379 373 380 $this->update_timer(); 374 if(!isset($this->FP)) 375 { 376 $this->ERROR = _("POP3 get:") . ' ' . _("No connection to server"); 377 return false; 378 } 381 379 382 $fp = $this->FP; 383 $buffer = $this->BUFFER; 384 $cmd = "RETR $msgNum"; 385 $reply = $this->send_cmd($cmd); 380 $this->update_timer(); 386 381 387 if(!$this->is_ok($reply)) 388 { 389 $this->ERROR = _("POP3 get:") . ' ' . _("Error ") . "[$reply]"; 390 return false; 391 } 382 $fp = $this->FP; 383 $buffer = $this->BUFFER; 384 $cmd = "RETR $msgNum"; 385 $reply = $this->send_cmd($cmd); 392 386 393 $count = 0; 394 $MsgArray = array(); 387 if(!$this->is_ok($reply)) 388 { 389 $this->ERROR = _("POP3 get:") . ' ' . _("Error ") . "[$reply]"; 390 return false; 391 } 395 392 396 $line = fgets($fp,$buffer); 397 while ( !ereg("^\.\r\n",$line)) 398 { 399 $MsgArray[$count] = $line; 400 $count++; 401 $line = fgets($fp,$buffer); 402 if(empty($line)) { break; } 403 } 404 return $MsgArray; 405 } 393 $count = 0; 394 $MsgArray = array(); 406 395 407 function last ( $type = "count" ) { 408 // Returns the highest msg number in the mailbox. 409 // returns -1 on error, 0+ on success, if type != count 410 // results in a popstat() call (2 element array returned) 396 $line = fgets($fp,$buffer); 397 while ( !ereg("^\.\r\n",$line)) 398 { 399 $MsgArray[$count] = $line; 400 $count++; 401 $line = fgets($fp,$buffer); 402 if(empty($line)) { break; } 403 } 404 return $MsgArray; 405 } 411 406 412 $last = -1; 413 if(!isset($this->FP)) 414 { 415 $this->ERROR = _("POP3 last:") . ' ' . _("No connection to server"); 416 return $last; 417 } 407 function last ( $type = "count" ) { 408 // Returns the highest msg number in the mailbox. 409 // returns -1 on error, 0+ on success, if type != count 410 // results in a popstat() call (2 element array returned) 418 411 419 $reply = $this->send_cmd("STAT");420 if(!$this->is_ok($reply))421 {422 $this->ERROR = _("POP3 last:") . ' ' . _("Error ") . "[$reply]";423 return $last;424 }412 $last = -1; 413 if(!isset($this->FP)) 414 { 415 $this->ERROR = _("POP3 last:") . ' ' . _("No connection to server"); 416 return $last; 417 } 425 418 426 $Vars = explode(" ",$reply); 427 $count = $Vars[1]; 428 $size = $Vars[2]; 429 settype($count,"integer"); 430 settype($size,"integer"); 431 if($type != "count") 432 { 433 return array($count,$size); 434 } 435 return $count; 436 } 419 $reply = $this->send_cmd("STAT"); 420 if(!$this->is_ok($reply)) 421 { 422 $this->ERROR = _("POP3 last:") . ' ' . _("Error ") . "[$reply]"; 423 return $last; 424 } 437 425 438 function reset () { 439 // Resets the status of the remote server. This includes 440 // resetting the status of ALL msgs to not be deleted. 441 // This method automatically closes the connection to the server. 426 $Vars = explode(" ",$reply); 427 $count = $Vars[1]; 428 $size = $Vars[2]; 429 settype($count,"integer"); 430 settype($size,"integer"); 431 if($type != "count") 432 { 433 return array($count,$size); 434 } 435 return $count; 436 } 442 437 443 if(!isset($this->FP)) 444 { 445 $this->ERROR = _("POP3 reset:") . ' ' . _("No connection to server"); 446 return false; 447 } 448 $reply = $this->send_cmd("RSET"); 449 if(!$this->is_ok($reply)) 450 { 451 // The POP3 RSET command -never- gives a -ERR 452 // response - if it ever does, something truely 453 // wild is going on. 438 function reset () { 439 // Resets the status of the remote server. This includes 440 // resetting the status of ALL msgs to not be deleted. 441 // This method automatically closes the connection to the server. 454 442 455 $this->ERROR = _("POP3 reset:") . ' ' . _("Error ") . "[$reply]"; 456 @error_log("POP3 reset: ERROR [$reply]",0); 457 } 458 $this->quit(); 459 return true; 460 } 443 if(!isset($this->FP)) 444 { 445 $this->ERROR = _("POP3 reset:") . ' ' . _("No connection to server"); 446 return false; 447 } 448 $reply = $this->send_cmd("RSET"); 449 if(!$this->is_ok($reply)) 450 { 451 // The POP3 RSET command -never- gives a -ERR 452 // response - if it ever does, something truely 453 // wild is going on. 461 454 462 function send_cmd ( $cmd = "" ) 463 { 464 // Sends a user defined command string to the 465 // POP server and returns the results. Useful for 466 // non-compliant or custom POP servers. 467 // Do NOT includ the \r\n as part of your command 468 // string - it will be appended automatically. 455 $this->ERROR = _("POP3 reset:") . ' ' . _("Error ") . "[$reply]"; 456 @error_log("POP3 reset: ERROR [$reply]",0); 457 } 458 $this->quit(); 459 return true; 460 } 469 461 470 // The return value is a standard fgets() call, which 471 // will read up to $this->BUFFER bytes of data, until it 472 // encounters a new line, or EOF, whichever happens first. 462 function send_cmd ( $cmd = "" ) 463 { 464 // Sends a user defined command string to the 465 // POP server and returns the results. Useful for 466 // non-compliant or custom POP servers. 467 // Do NOT includ the \r\n as part of your command 468 // string - it will be appended automatically. 473 469 474 // This method works best if $cmd responds with only 475 // one line of data. 470 // The return value is a standard fgets() call, which 471 // will read up to $this->BUFFER bytes of data, until it 472 // encounters a new line, or EOF, whichever happens first. 476 473 477 if(!isset($this->FP)) 478 { 479 $this->ERROR = _("POP3 send_cmd:") . ' ' . _("No connection to server"); 480 return false; 481 } 474 // This method works best if $cmd responds with only 475 // one line of data. 482 476 483 if(empty($cmd))484 {485 $this->ERROR = _("POP3 send_cmd:") . ' ' . _("Empty command string");486 return "";487 }477 if(!isset($this->FP)) 478 { 479 $this->ERROR = _("POP3 send_cmd:") . ' ' . _("No connection to server"); 480 return false; 481 } 488 482 489 $fp = $this->FP; 490 $buffer = $this->BUFFER; 491 $this->update_timer(); 492 fwrite($fp,"$cmd\r\n"); 493 $reply = fgets($fp,$buffer); 494 $reply = $this->strip_clf($reply); 495 if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } 496 return $reply; 497 } 483 if(empty($cmd)) 484 { 485 $this->ERROR = _("POP3 send_cmd:") . ' ' . _("Empty command string"); 486 return ""; 487 } 498 488 499 function quit() { 500 // Closes the connection to the POP3 server, deleting 501 // any msgs marked as deleted. 489 $fp = $this->FP; 490 $buffer = $this->BUFFER; 491 $this->update_timer(); 492 fwrite($fp,"$cmd\r\n"); 493 $reply = fgets($fp,$buffer); 494 $reply = $this->strip_clf($reply); 495 if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } 496 return $reply; 497 } 502 498 503 if(!isset($this->FP)) 504 { 505 $this->ERROR = _("POP3 quit:") . ' ' . _("connection does not exist"); 506 return false; 507 } 508 $fp = $this->FP; 509 $cmd = "QUIT"; 510 fwrite($fp,"$cmd\r\n"); 511 $reply = fgets($fp,$this->BUFFER); 512 $reply = $this->strip_clf($reply); 513 if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } 514 fclose($fp); 515 unset($this->FP); 516 return true; 517 } 499 function quit() { 500 // Closes the connection to the POP3 server, deleting 501 // any msgs marked as deleted. 518 502 519 function popstat () { 520 // Returns an array of 2 elements. The number of undeleted 521 // msgs in the mailbox, and the size of the mbox in octets. 503 if(!isset($this->FP)) 504 { 505 $this->ERROR = _("POP3 quit:") . ' ' . _("connection does not exist"); 506 return false; 507 } 508 $fp = $this->FP; 509 $cmd = "QUIT"; 510 fwrite($fp,"$cmd\r\n"); 511 $reply = fgets($fp,$this->BUFFER); 512 $reply = $this->strip_clf($reply); 513 if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } 514 fclose($fp); 515 unset($this->FP); 516 return true; 517 } 522 518 523 $PopArray = $this->last("array"); 519 function popstat () { 520 // Returns an array of 2 elements. The number of undeleted 521 // msgs in the mailbox, and the size of the mbox in octets. 524 522 525 if($PopArray == -1) { return false; } 523 $PopArray = $this->last("array"); 526 524 527 if( (!$PopArray) or (empty($PopArray)) ) 528 { 529 return false; 530 } 531 return $PopArray; 532 } 525 if($PopArray == -1) { return false; } 533 526 534 function uidl ($msgNum = "")535 {536 // Returns the UIDL of the msg specified. If called with 537 // no arguments, returns an associative array where each 538 // undeleted msg num is a key, and the msg's uidl is the element 539 // Array element 0 will contain the total number of msgs 527 if( (!$PopArray) or (empty($PopArray)) ) 528 { 529 return false; 530 } 531 return $PopArray; 532 } 540 533 541 if(!isset($this->FP)) { 542 $this->ERROR = _("POP3 uidl:") . ' ' . _("No connection to server"); 543 return false; 544 } 534 function uidl ($msgNum = "") 535 { 536 // Returns the UIDL of the msg specified. If called with 537 // no arguments, returns an associative array where each 538 // undeleted msg num is a key, and the msg's uidl is the element 539 // Array element 0 will contain the total number of msgs 545 540 546 $fp = $this->FP; 547 $buffer = $this->BUFFER; 541 if(!isset($this->FP)) { 542 $this->ERROR = _("POP3 uidl:") . ' ' . _("No connection to server"); 543 return false; 544 } 548 545 549 if(!empty($msgNum)) { 550 $cmd = "UIDL $msgNum"; 551 $reply = $this->send_cmd($cmd); 552 if(!$this->is_ok($reply)) 553 { 554 $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]"; 555 return false; 556 } 557 list ($ok,$num,$myUidl) = explode(" ",$reply); 558 return $myUidl; 559 } else { 560 $this->update_timer(); 546 $fp = $this->FP; 547 $buffer = $this->BUFFER; 561 548 562 $UIDLArray = array(); 563 $Total = $this->COUNT; 564 $UIDLArray[0] = $Total; 549 if(!empty($msgNum)) { 550 $cmd = "UIDL $msgNum"; 551 $reply = $this->send_cmd($cmd); 552 if(!$this->is_ok($reply)) 553 { 554 $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]"; 555 return false; 556 } 557 list ($ok,$num,$myUidl) = explode(" ",$reply); 558 return $myUidl; 559 } else { 560 $this->update_timer(); 565 561 566 if ($Total < 1) 567 { 568 return $UIDLArray; 569 } 570 $cmd = "UIDL"; 571 fwrite($fp, "UIDL\r\n"); 572 $reply = fgets($fp, $buffer); 573 $reply = $this->strip_clf($reply); 574 if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } 575 if(!$this->is_ok($reply)) 576 { 577 $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]"; 578 return false; 579 } 562 $UIDLArray = array(); 563 $Total = $this->COUNT; 564 $UIDLArray[0] = $Total; 580 565 581 $line = ""; 582 $count = 1; 583 $line = fgets($fp,$buffer); 584 while ( !ereg("^\.\r\n",$line)) { 585 if(ereg("^\.\r\n",$line)) { 586 break; 587 } 588 list ($msg,$msgUidl) = explode(" ",$line); 589 $msgUidl = $this->strip_clf($msgUidl); 590 if($count == $msg) { 591 $UIDLArray[$msg] = $msgUidl; 592 } 593 else 594 { 595 $UIDLArray[$count] = 'deleted'; 596 } 597 $count++; 598 $line = fgets($fp,$buffer); 599 } 600 } 601 return $UIDLArray; 602 } 566 if ($Total < 1) 567 { 568 return $UIDLArray; 569 } 570 $cmd = "UIDL"; 571 fwrite($fp, "UIDL\r\n"); 572 $reply = fgets($fp, $buffer); 573 $reply = $this->strip_clf($reply); 574 if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } 575 if(!$this->is_ok($reply)) 576 { 577 $this->ERROR = _("POP3 uidl:") . ' ' . _("Error ") . "[$reply]"; 578 return false; 579 } 603 580 604 function delete ($msgNum = "") { 605 // Flags a specified msg as deleted. The msg will not 606 // be deleted until a quit() method is called. 581 $line = ""; 582 $count = 1; 583 $line = fgets($fp,$buffer); 584 while ( !ereg("^\.\r\n",$line)) { 585 if(ereg("^\.\r\n",$line)) { 586 break; 587 } 588 list ($msg,$msgUidl) = explode(" ",$line); 589 $msgUidl = $this->strip_clf($msgUidl); 590 if($count == $msg) { 591 $UIDLArray[$msg] = $msgUidl; 592 } 593 else 594 { 595 $UIDLArray[$count] = 'deleted'; 596 } 597 $count++; 598 $line = fgets($fp,$buffer); 599 } 600 } 601 return $UIDLArray; 602 } 607 603 608 if(!isset($this->FP)) 609 { 610 $this->ERROR = _("POP3 delete:") . ' ' . _("No connection to server"); 611 return false; 612 } 613 if(empty($msgNum)) 614 { 615 $this->ERROR = _("POP3 delete:") . ' ' . _("No msg number submitted"); 616 return false; 617 } 618 $reply = $this->send_cmd("DELE $msgNum"); 619 if(!$this->is_ok($reply)) 620 { 621 $this->ERROR = _("POP3 delete:") . ' ' . _("Command failed ") . "[$reply]"; 622 return false; 623 } 624 return true; 625 } 604 function delete ($msgNum = "") { 605 // Flags a specified msg as deleted. The msg will not 606 // be deleted until a quit() method is called. 626 607 627 // ********************************************************* 608 if(!isset($this->FP)) 609 { 610 $this->ERROR = _("POP3 delete:") . ' ' . _("No connection to server"); 611 return false; 612 } 613 if(empty($msgNum)) 614 { 615 $this->ERROR = _("POP3 delete:") . ' ' . _("No msg number submitted"); 616 return false; 617 } 618 $reply = $this->send_cmd("DELE $msgNum"); 619 if(!$this->is_ok($reply)) 620 { 621 $this->ERROR = _("POP3 delete:") . ' ' . _("Command failed ") . "[$reply]"; 622 return false; 623 } 624 return true; 625 } 628 626 629 // The following methods are internal to the class. 627 // ********************************************************* 630 628 631 function is_ok ($cmd = "") { 632 // Return true or false on +OK or -ERR 629 // The following methods are internal to the class. 633 630 634 if( empty($cmd) ) 635 return false; 636 else 637 return( ereg ("^\+OK", $cmd ) ); 638 } 631 function is_ok ($cmd = "") { 632 // Return true or false on +OK or -ERR 639 633 640 function strip_clf ($text = "") { 641 // Strips \r\n from server responses 634 if( empty($cmd) ) 635 return false; 636 else 637 return( ereg ("^\+OK", $cmd ) ); 638 } 642 639 643 if(empty($text)) 644 return $text; 645 else { 646 $stripped = str_replace("\r",'',$text); 647 $stripped = str_replace("\n",'',$stripped); 648 return $stripped; 649 } 650 } 640 function strip_clf ($text = "") { 641 // Strips \r\n from server responses 651 642 652 function parse_banner ( $server_text ) { 653 $outside = true; 654 $banner = ""; 655 $length = strlen($server_text); 656 for($count =0; $count < $length; $count++) 657 { 658 $digit = substr($server_text, $count, 1); 659 if ( false !== $digit ) { 660 if( (!$outside) && ($digit != '<') && ($digit != '>') ) 661 { 662 $banner .= $digit; 663 } 664 if ($digit == '<') 665 { 666 $outside = false; 667 } 668 if($digit == '>') 669 { 670 $outside = true; 671 } 672 } 673 } 674 $banner = $this->strip_clf($banner); // Just in case 675 return "<$banner>"; 676 } 643 if(empty($text)) 644 return $text; 645 else { 646 $stripped = str_replace("\r",'',$text); 647 $stripped = str_replace("\n",'',$stripped); 648 return $stripped; 649 } 650 } 677 651 652 function parse_banner ( $server_text ) { 653 $outside = true; 654 $banner = ""; 655 $length = strlen($server_text); 656 for($count =0; $count < $length; $count++) 657 { 658 $digit = substr($server_text, $count, 1); 659 if ( false !== $digit ) { 660 if( (!$outside) && ($digit != '<') && ($digit != '>') ) 661 { 662 $banner .= $digit; 663 } 664 if ($digit == '<') 665 { 666 $outside = false; 667 } 668 if($digit == '>') 669 { 670 $outside = true; 671 } 672 } 673 } 674 $banner = $this->strip_clf($banner); // Just in case 675 return "<$banner>"; 676 } 677 678 678 } // End class 679 679 680 680 ?> -
wp-includes/class-snoopy.php
206 206 if(!$this->curl_path) 207 207 return false; 208 208 if(function_exists("is_executable")) 209 if (!is_executable($this->curl_path))210 return false;209 if (!is_executable($this->curl_path)) 210 return false; 211 211 $this->host = $URI_PARTS["host"]; 212 212 if(!empty($URI_PARTS["port"])) 213 213 $this->port = $URI_PARTS["port"]; … … 365 365 if(!$this->curl_path) 366 366 return false; 367 367 if(function_exists("is_executable")) 368 if (!is_executable($this->curl_path))369 return false;368 if (!is_executable($this->curl_path)) 369 return false; 370 370 $this->host = $URI_PARTS["host"]; 371 371 if(!empty($URI_PARTS["port"])) 372 372 $this->port = $URI_PARTS["port"]; … … 816 816 $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; 817 817 } 818 818 $headers .= substr($cookie_headers,0,-2) . "\r\n"; 819 } 819 } 820 820 } 821 821 if(!empty($this->rawheaders)) 822 822 { … … 886 886 887 887 if(preg_match("|^HTTP/|",$currentHeader)) 888 888 { 889 if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))889 if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) 890 890 { 891 891 $this->status= $status[1]; 892 }892 } 893 893 $this->response_code = $currentHeader; 894 894 } 895 895 … … 898 898 899 899 $results = ''; 900 900 do { 901 $_data = fread($fp, $this->maxlength);902 if (strlen($_data) == 0) {903 break;904 }905 $results .= $_data;901 $_data = fread($fp, $this->maxlength); 902 if (strlen($_data) == 0) { 903 break; 904 } 905 $results .= $_data; 906 906 } while(true); 907 907 908 908 if ($this->read_timeout > 0 && $this->_check_timeout($fp)) -
wp-includes/classes.php
84 84 var $matched_rule; 85 85 var $matched_query; 86 86 var $did_permalink = false; 87 87 88 88 function add_query_var($qv) { 89 89 $this->public_query_vars[] = $qv; 90 90 } … … 160 160 preg_match("!^$match!", urldecode($request_match), $matches)) { 161 161 // Got a match. 162 162 $this->matched_rule = $match; 163 163 164 164 // Trim the query of everything up to the '?'. 165 165 $query = preg_replace("!^.+\?!", '', $query); 166 166 … … 219 219 for ($i=0; $i<count($this->private_query_vars); $i += 1) { 220 220 $wpvar = $this->private_query_vars[$i]; 221 221 if (isset($this->extra_query_vars[$wpvar])) 222 $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar]; 222 $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar]; 223 223 } 224 224 225 225 if ( isset($error) ) … … 241 241 // We're showing a feed, so WP is indeed the only thing that last changed 242 242 if ( $this->query_vars['withcomments'] ) 243 243 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT'; 244 else 244 else 245 245 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; 246 246 $wp_etag = '"' . md5($wp_last_modified) . '"'; 247 247 @header("Last-Modified: $wp_last_modified"); 248 248 @header("ETag: $wp_etag"); 249 249 250 250 // Support for Conditional GET 251 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) 251 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) 252 252 $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); 253 253 else $client_etag = false; 254 254 … … 315 315 function query_posts() { 316 316 $this->build_query_string(); 317 317 query_posts($this->query_string); 318 }318 } 319 319 320 320 function handle_404() { 321 321 global $wp_query; … … 367 367 if ( empty($codes) ) 368 368 return ''; 369 369 370 return $codes[0]; 370 return $codes[0]; 371 371 } 372 372 373 373 function get_error_messages($code = '') { … … 383 383 if ( isset($this->errors[$code]) ) 384 384 return $this->errors[$code]; 385 385 else 386 return array(); 386 return array(); 387 387 } 388 388 389 389 function get_error_message($code = '') { … … 396 396 } 397 397 398 398 function add($code, $message) { 399 $this->errors[$code][] = $message; 399 $this->errors[$code][] = $message; 400 400 } 401 401 } 402 402 … … 409 409 410 410 // A class for displaying various tree-like structures. Extend the Walker class to use it, see examples at the bottom 411 411 412 class Walker { 412 class Walker { 413 413 var $tree_type; 414 414 var $db_fields; 415 415 416 416 //abstract callbacks 417 417 function start_lvl($output) { return $output; } 418 418 function end_lvl($output) { return $output; } 419 419 function start_el($output) { return $output; } 420 420 function end_el($output) { return $output; } 421 421 422 422 function walk($elements, $to_depth) { 423 423 $args = array_slice(func_get_args(), 2); $parents = array(); $depth = 1; $previous_element = ''; $output = ''; 424 424 425 425 //padding at the end 426 426 $last_element->post_parent = 0; 427 427 $last_element->post_id = 0; 428 428 $elements[] = $last_element; 429 429 430 430 $id_field = $this->db_fields['id']; 431 431 $parent_field = $this->db_fields['parent']; 432 432 433 433 $flat = ($to_depth == -1) ? true : false; 434 434 435 435 foreach ( $elements as $element ) { 436 436 // If flat, start and end the element and skip the level checks. 437 437 if ( $flat) { … … 440 440 $cb_args = array_merge( array($output, $element, $depth - 1), $args); 441 441 $output = call_user_func_array(array(&$this, 'start_el'), $cb_args); 442 442 } 443 443 444 444 // End the element. 445 445 if ( $element->$id_field != 0 ) { 446 446 $cb_args = array_merge( array($output, $element, $depth - 1), $args); 447 447 $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 448 448 } 449 450 continue; 449 450 continue; 451 451 } 452 452 453 453 // Walk the tree. 454 454 if ( !empty($previous_element) && ($element->$parent_field == $previous_element->$id_field) ) { 455 455 // Previous element is my parent. Descend a level. … … 471 471 $cb_args = array_merge( array($output, $previous_element, $depth - 1), $args); 472 472 $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 473 473 } 474 474 475 475 while ( $parent = array_shift($parents) ) { 476 476 $depth--; 477 477 if ( !$to_depth || ($depth < $to_depth) ) { … … 491 491 $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 492 492 } 493 493 } 494 494 495 495 // Start the element. 496 496 if ( !$to_depth || ($depth <= $to_depth) ) { 497 497 if ( $element->$id_field != 0 ) { … … 499 499 $output = call_user_func_array(array(&$this, 'start_el'), $cb_args); 500 500 } 501 501 } 502 502 503 503 $previous_element = $element; 504 504 } 505 505 506 506 return $output; 507 507 } 508 508 } … … 510 510 class Walker_Page extends Walker { 511 511 var $tree_type = 'page'; 512 512 var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this 513 513 514 514 function start_lvl($output, $depth) { 515 515 $indent = str_repeat("\t", $depth); 516 516 $output .= "$indent<ul>\n"; 517 517 return $output; 518 518 } 519 519 520 520 function end_lvl($output, $depth) { 521 521 $indent = str_repeat("\t", $depth); 522 522 $output .= "$indent</ul>\n"; 523 523 return $output; 524 524 } 525 525 526 526 function start_el($output, $page, $depth, $current_page, $show_date, $date_format) { 527 527 if ( $depth ) 528 528 $indent = str_repeat("\t", $depth); … … 532 532 $css_class .= ' current_page_item'; 533 533 534 534 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . wp_specialchars($page->post_title) . '">' . $page->post_title . '</a>'; 535 535 536 536 if ( !empty($show_date) ) { 537 537 if ( 'modified' == $show_date ) 538 538 $time = $page->post_modified; 539 539 else 540 540 $time = $page->post_date; 541 541 542 542 $output .= " " . mysql2date($date_format, $time); 543 543 } 544 544 545 545 return $output; 546 546 } 547 547 548 548 function end_el($output, $page, $depth) { 549 549 $output .= "</li>\n"; 550 550 … … 558 558 var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this 559 559 560 560 function start_el($output, $page, $depth, $args) { 561 $pad = str_repeat(' ', $depth * 3);561 $pad = str_repeat(' ', $depth * 3); 562 562 563 $output .= "\t<option value=\"$page->ID\"";564 if ( $page->ID == $args['selected'] )565 $output .= ' selected="selected"';566 $output .= '>';567 $title = wp_specialchars($page->post_title);568 $output .= "$pad$title";569 $output .= "</option>\n";563 $output .= "\t<option value=\"$page->ID\""; 564 if ( $page->ID == $args['selected'] ) 565 $output .= ' selected="selected"'; 566 $output .= '>'; 567 $title = wp_specialchars($page->post_title); 568 $output .= "$pad$title"; 569 $output .= "</option>\n"; 570 570 571 return $output;571 return $output; 572 572 } 573 573 } 574 574 575 575 class Walker_Category extends Walker { 576 576 var $tree_type = 'category'; 577 577 var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this 578 578 579 579 function start_lvl($output, $depth, $args) { 580 580 if ( 'list' != $args['style'] ) 581 581 return $output; 582 582 583 583 $indent = str_repeat("\t", $depth); 584 584 $output .= "$indent<ul class='children'>\n"; 585 585 return $output; 586 586 } 587 587 588 588 function end_lvl($output, $depth, $args) { 589 589 if ( 'list' != $args['style'] ) 590 590 return $output; 591 591 592 592 $indent = str_repeat("\t", $depth); 593 593 $output .= "$indent</ul>\n"; 594 594 return $output; 595 595 } 596 596 597 597 function start_el($output, $category, $depth, $args) { 598 598 extract($args); 599 599 600 600 $link = '<a href="' . get_category_link($category->cat_ID) . '" '; 601 601 if ( $use_desc_for_title == 0 || empty($category->category_description) ) 602 602 $link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"'; … … 604 604 $link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"'; 605 605 $link .= '>'; 606 606 $link .= apply_filters('list_cats', $category->cat_name, $category).'</a>'; 607 607 608 608 if ( (! empty($feed_image)) || (! empty($feed)) ) { 609 609 $link .= ' '; 610 610 611 611 if ( empty($feed_image) ) 612 612 $link .= '('; 613 613 614 614 $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"'; 615 615 616 616 if ( !empty($feed) ) { 617 617 $title = ' title="' . $feed . '"'; 618 618 $alt = ' alt="' . $feed . '"'; 619 619 $name = $feed; 620 620 $link .= $title; 621 621 } 622 622 623 623 $link .= '>'; 624 624 625 625 if ( !empty($feed_image) ) 626 626 $link .= "<img src='$feed_image' $alt$title" . ' />'; 627 627 else … … 630 630 if (empty($feed_image)) 631 631 $link .= ')'; 632 632 } 633 633 634 634 if ( $show_count ) 635 635 $link .= ' ('.intval($category->category_count).')'; 636 636 637 637 if ( $show_date ) { 638 638 $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); 639 639 } 640 640 641 641 if ( 'list' == $args['style'] ) { 642 642 $output .= "\t<li"; 643 643 if ( ($category->cat_ID == $current_category) && is_category() ) … … 646 646 } else { 647 647 $output .= "\t$link<br />\n"; 648 648 } 649 649 650 650 return $output; 651 651 } 652 652 653 653 function end_el($output, $page, $depth, $args) { 654 654 if ( 'list' != $args['style'] ) 655 655 return $output; 656 656 657 657 $output .= "</li>\n"; 658 658 return $output; 659 659 } … … 663 663 class Walker_CategoryDropdown extends Walker { 664 664 var $tree_type = 'category'; 665 665 var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this 666 667 function start_el($output, $category, $depth, $args) { 666 667 function start_el($output, $category, $depth, $args) { 668 668 $pad = str_repeat(' ', $depth * 3); 669 669 670 670 $cat_name = apply_filters('list_cats', $category->cat_name, $category); 671 671 $output .= "\t<option value=\"".$category->cat_ID."\""; 672 672 if ( $category->cat_ID == $args['selected'] ) … … 680 680 $output .= ' ' . gmdate($format, $category->last_update_timestamp); 681 681 } 682 682 $output .= "</option>\n"; 683 683 684 684 return $output; 685 685 } 686 686 } -
wp-includes/comment-template.php
142 142 } 143 143 144 144 function comments_link( $file = '', $echo = true ) { 145 echo get_comments_link();145 echo get_comments_link(); 146 146 } 147 147 148 148 function get_comments_number( $post_id = 0 ) { … … 239 239 function trackback_rdf($timezone = 0) { 240 240 global $id; 241 241 if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { 242 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 243 xmlns:dc="http://purl.org/dc/elements/1.1/"244 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">242 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 243 xmlns:dc="http://purl.org/dc/elements/1.1/" 244 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> 245 245 <rdf:Description rdf:about="'; 246 246 the_permalink(); 247 247 echo '"'."\n"; … … 264 264 265 265 function pings_open() { 266 266 global $post; 267 if ( 'open' == $post->ping_status ) 267 if ( 'open' == $post->ping_status ) 268 268 return true; 269 269 else 270 270 return false; … … 298 298 } 299 299 300 300 function comments_popup_script($width=400, $height=400, $file='') { 301 global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript;301 global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; 302 302 303 303 if (empty ($file)) { 304 304 $wpcommentspopupfile = ''; // Use the index. … … 306 306 $wpcommentspopupfile = $file; 307 307 } 308 308 309 $wpcommentsjavascript = 1;310 $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n";311 echo $javascript;309 $wpcommentsjavascript = 1; 310 $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n"; 311 echo $javascript; 312 312 } 313 313 314 314 function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { -
wp-includes/comment.php
18 18 // Skip empty lines 19 19 if (empty($word)) { continue; } 20 20 21 // Do some escaping magic so that '#' chars in the 21 // Do some escaping magic so that '#' chars in the 22 22 // spam words don't break things: 23 23 $word = preg_quote($word, '#'); 24 24 25 $pattern = "#$word#i"; 25 $pattern = "#$word#i"; 26 26 if ( preg_match($pattern, $author) ) return false; 27 27 if ( preg_match($pattern, $email) ) return false; 28 28 if ( preg_match($pattern, $url) ) return false; … … 103 103 if ($no_cache) { 104 104 $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'"; 105 105 if (false == $include_unapproved) { 106 $query .= " AND comment_approved = '1'";106 $query .= " AND comment_approved = '1'"; 107 107 } 108 $myrow = $wpdb->get_row($query, ARRAY_A);108 $myrow = $wpdb->get_row($query, ARRAY_A); 109 109 } else { 110 110 $myrow['comment_ID'] = $postc->comment_ID; 111 111 $myrow['comment_post_ID'] = $postc->comment_post_ID; … … 157 157 if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { 158 158 $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); 159 159 $comment_author_email = stripslashes($comment_author_email); 160 $comment_author_email = wp_specialchars($comment_author_email, true); 160 $comment_author_email = wp_specialchars($comment_author_email, true); 161 161 $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email; 162 162 } 163 163 … … 244 244 // Skip empty lines 245 245 if ( empty($word) ) { continue; } 246 246 247 // Do some escaping magic so that '#' chars in the 247 // Do some escaping magic so that '#' chars in the 248 248 // spam words don't break things: 249 249 $word = preg_quote($word, '#'); 250 250 251 $pattern = "#$word#i"; 251 $pattern = "#$word#i"; 252 252 if ( preg_match($pattern, $author ) ) return true; 253 253 if ( preg_match($pattern, $email ) ) return true; 254 254 if ( preg_match($pattern, $url ) ) return true; … … 333 333 if ( ! isset($user_id) ) 334 334 $user_id = 0; 335 335 336 $result = $wpdb->query("INSERT INTO $wpdb->comments 336 $result = $wpdb->query("INSERT INTO $wpdb->comments 337 337 (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent, comment_type, comment_parent, user_id) 338 VALUES 338 VALUES 339 339 ('$comment_post_ID', '$comment_author', '$comment_author_email', '$comment_author_url', '$comment_author_IP', '$comment_date', '$comment_date_gmt', '$comment_content', '$comment_approved', '$comment_agent', '$comment_type', '$comment_parent', '$user_id') 340 340 "); 341 341 … … 394 394 } 395 395 396 396 function wp_set_comment_status($comment_id, $comment_status) { 397 global $wpdb;397 global $wpdb; 398 398 399 switch($comment_status) {399 switch($comment_status) { 400 400 case 'hold': 401 401 $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; 402 402 break; 403 403 case 'approve': 404 404 $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; 405 405 break; 406 case 'spam':407 $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1";408 break;406 case 'spam': 407 $query = "UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID='$comment_id' LIMIT 1"; 408 break; 409 409 case 'delete': 410 410 return wp_delete_comment($comment_id); 411 411 break; 412 412 default: 413 413 return false; 414 }415 416 if ($wpdb->query($query)) {414 } 415 416 if ($wpdb->query($query)) { 417 417 do_action('wp_set_comment_status', $comment_id, $comment_status); 418 418 419 419 $comment = get_comment($comment_id); … … 422 422 if( is_object( $c ) ) 423 423 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" ); 424 424 return true; 425 } else {425 } else { 426 426 return false; 427 }427 } 428 428 } 429 429 430 430 function wp_update_comment($commentarr) { … … 579 579 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';"); 580 580 pingback($ping->post_content, $ping->ID); 581 581 } 582 582 583 583 // Do Enclosures 584 584 while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) { 585 585 $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';"); … … 616 616 $excerpt = str_replace(']]>', ']]>', $excerpt); 617 617 $excerpt = strip_tags($excerpt); 618 618 if ( function_exists('mb_strcut') ) // For international trackbacks 619 $excerpt = mb_strcut($excerpt, 0, 252, get_settings('blog_charset')) . '...';619 $excerpt = mb_strcut($excerpt, 0, 252, get_settings('blog_charset')) . '...'; 620 620 else 621 621 $excerpt = substr($excerpt, 0, 252) . '...'; 622 622 … … 702 702 $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048); 703 703 704 704 if ($pingback_server_url) { 705 @ set_time_limit( 60 ); 705 @ set_time_limit( 60 ); 706 706 // Now, the RPC call 707 707 debug_fwrite($log, "Page Linked To: $pagelinkedto \n"); 708 708 debug_fwrite($log, 'Page Linked From: '); -
wp-includes/compat.php
36 36 /* Added in PHP 4.3.0 */ 37 37 38 38 function printr($var, $do_not_echo = false) { 39 // from php.net/print_r user contributed notes 39 // from php.net/print_r user contributed notes 40 40 ob_start(); 41 41 print_r($var); 42 42 $code = htmlentities(ob_get_contents()); 43 43 ob_clean(); 44 44 if (!$do_not_echo) { 45 echo "<pre>$code</pre>";45 echo "<pre>$code</pre>"; 46 46 } 47 47 ob_end_clean(); 48 48 return $code; … … 57 57 } 58 58 59 59 if (!defined('CASE_LOWER')) { 60 define('CASE_LOWER', 0);60 define('CASE_LOWER', 0); 61 61 } 62 62 63 63 if (!defined('CASE_UPPER')) { 64 define('CASE_UPPER', 1);64 define('CASE_UPPER', 1); 65 65 } 66 66 67 67 … … 78 78 * @require PHP 4.0.0 (user_error) 79 79 */ 80 80 if (!function_exists('array_change_key_case')) { 81 function array_change_key_case($input, $case = CASE_LOWER)82 {83 if (!is_array($input)) {84 user_error('array_change_key_case(): The argument should be an array',85 E_USER_WARNING);86 return false;87 }81 function array_change_key_case($input, $case = CASE_LOWER) 82 { 83 if (!is_array($input)) { 84 user_error('array_change_key_case(): The argument should be an array', 85 E_USER_WARNING); 86 return false; 87 } 88 88 89 $output = array ();90 $keys = array_keys($input);91 $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper';89 $output = array (); 90 $keys = array_keys($input); 91 $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper'; 92 92 93 foreach ($keys as $key) {94 $output[$casefunc($key)] = $input[$key];95 }93 foreach ($keys as $key) { 94 $output[$casefunc($key)] = $input[$key]; 95 } 96 96 97 return $output;98 }97 return $output; 98 } 99 99 } 100 100 101 101 // From php.net 102 102 if(!function_exists('http_build_query')) { 103 function http_build_query( $formdata, $numeric_prefix = null, $key = null ) {104 $res = array();105 foreach ((array)$formdata as $k=>$v) {106 $tmp_key = urlencode(is_int($k) ? $numeric_prefix.$k : $k);107 if ($key) $tmp_key = $key.'['.$tmp_key.']';108 $res[] = ( ( is_array($v) || is_object($v) ) ? http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) );109 }110 $separator = ini_get('arg_separator.output');111 return implode($separator, $res);112 }103 function http_build_query( $formdata, $numeric_prefix = null, $key = null ) { 104 $res = array(); 105 foreach ((array)$formdata as $k=>$v) { 106 $tmp_key = urlencode(is_int($k) ? $numeric_prefix.$k : $k); 107 if ($key) $tmp_key = $key.'['.$tmp_key.']'; 108 $res[] = ( ( is_array($v) || is_object($v) ) ? http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) ); 109 } 110 $separator = ini_get('arg_separator.output'); 111 return implode($separator, $res); 112 } 113 113 } 114 114 115 115 if ( !function_exists('_') ) { -
wp-includes/cron.php
66 66 67 67 function spawn_cron() { 68 68 $crons = get_option( 'cron' ); 69 69 70 70 if ( !is_array($crons) ) 71 71 return; 72 72 73 73 $keys = array_keys( $crons ); 74 74 if ( array_shift( $keys ) > time() ) 75 75 return; … … 80 80 $argyle = @ fsockopen( $parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01 ); 81 81 if ( $argyle ) 82 82 fputs( $argyle, 83 "GET {$parts['path']}?check=" . md5(DB_PASS . '187425') . " HTTP/1.0\r\n"83 "GET {$parts['path']}?check=" . md5(DB_PASS . '187425') . " HTTP/1.0\r\n" 84 84 . "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n" 85 85 ); 86 86 } 87 87 88 88 function wp_cron() { 89 89 $crons = get_option( 'cron' ); 90 90 91 91 if ( !is_array($crons) ) 92 92 return; 93 93 -
wp-includes/deprecated.php
129 129 $post_author_data = get_userdata($post->post_author); 130 130 131 131 if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' && $author_data->user_level < 2)) 132 || ($author_data->user_level > $post_author_data->user_level)133 || ($author_data->user_level >= 10) ) {132 || ($author_data->user_level > $post_author_data->user_level) 133 || ($author_data->user_level >= 10) ) { 134 134 return true; 135 135 } else { 136 136 return false; … … 199 199 ** show_updated (default 0) - whether to show last updated timestamp 200 200 */ 201 201 function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />', 202 $between = " ", $show_images = true, $orderby = 'id',203 $show_description = true, $show_rating = false,204 $limit = -1, $show_updated = 0) {205 global $wpdb;206 $cat_id = -1;207 $results = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'");208 if ($results) {209 foreach ($results as $result) {210 $cat_id = $result->cat_ID;211 }212 }213 get_links($cat_id, $before, $after, $between, $show_images, $orderby,214 $show_description, $show_rating, $limit, $show_updated);202 $between = " ", $show_images = true, $orderby = 'id', 203 $show_description = true, $show_rating = false, 204 $limit = -1, $show_updated = 0) { 205 global $wpdb; 206 $cat_id = -1; 207 $results = $wpdb->get_results("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$cat_name'"); 208 if ($results) { 209 foreach ($results as $result) { 210 $cat_id = $result->cat_ID; 211 } 212 } 213 get_links($cat_id, $before, $after, $between, $show_images, $orderby, 214 $show_description, $show_rating, $limit, $show_updated); 215 215 } 216 216 217 217 /** function wp_get_linksbyname() … … 252 252 **/ 253 253 // Deprecate in favor of get_linkz(). 254 254 function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) { 255 global $wpdb;256 $cat_id = -1;257 //$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'");258 // TODO: Fix me.259 if ($results) {260 foreach ($results as $result) {261 $cat_id = $result->cat_id;262 }263 }264 return get_linkobjects($cat_id, $orderby, $limit);255 global $wpdb; 256 $cat_id = -1; 257 //$results = $wpdb->get_results("SELECT cat_id FROM $wpdb->linkcategories WHERE cat_name='$cat_name'"); 258 // TODO: Fix me. 259 if ($results) { 260 foreach ($results as $result) { 261 $cat_id = $result->cat_id; 262 } 263 } 264 return get_linkobjects($cat_id, $orderby, $limit); 265 265 } 266 266 267 267 /** function get_linkobjects() … … 301 301 **/ 302 302 // Deprecate in favor of get_linkz(). 303 303 function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) { 304 global $wpdb;304 global $wpdb; 305 305 306 $sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'";307 if ($category != -1) {308 $sql .= " AND link_category = $category ";309 }310 if ($orderby == '')311 $orderby = 'id';312 if (substr($orderby,0,1) == '_') {313 $direction = ' DESC';314 $orderby = substr($orderby,1);315 }316 if (strcasecmp('rand',$orderby) == 0) {317 $orderby = 'rand()';318 } else {319 $orderby = " link_" . $orderby;320 }321 $sql .= ' ORDER BY ' . $orderby;322 $sql .= $direction;323 /* The next 2 lines implement LIMIT TO processing */324 if ($limit != -1)325 $sql .= " LIMIT $limit";306 $sql = "SELECT * FROM $wpdb->links WHERE link_visible = 'Y'"; 307 if ($category != -1) { 308 $sql .= " AND link_category = $category "; 309 } 310 if ($orderby == '') 311 $orderby = 'id'; 312 if (substr($orderby,0,1) == '_') { 313 $direction = ' DESC'; 314 $orderby = substr($orderby,1); 315 } 316 if (strcasecmp('rand',$orderby) == 0) { 317 $orderby = 'rand()'; 318 } else { 319 $orderby = " link_" . $orderby; 320 } 321 $sql .= ' ORDER BY ' . $orderby; 322 $sql .= $direction; 323 /* The next 2 lines implement LIMIT TO processing */ 324 if ($limit != -1) 325 $sql .= " LIMIT $limit"; 326 326 327 $results = $wpdb->get_results($sql);328 if ($results) {329 foreach ($results as $result) {330 $result->link_url = $result->link_url;331 $result->link_name = $result->link_name;332 $result->link_description = $result->link_description;333 $result->link_notes = $result->link_notes;334 $newresults[] = $result;335 }336 }337 return $newresults;327 $results = $wpdb->get_results($sql); 328 if ($results) { 329 foreach ($results as $result) { 330 $result->link_url = $result->link_url; 331 $result->link_name = $result->link_name; 332 $result->link_description = $result->link_description; 333 $result->link_notes = $result->link_notes; 334 $newresults[] = $result; 335 } 336 } 337 return $newresults; 338 338 } 339 339 340 340 /** function get_linksbyname_withrating() … … 359 359 ** show_updated (default 0) - whether to show last updated timestamp 360 360 */ 361 361 function get_linksbyname_withrating($cat_name = "noname", $before = '', 362 $after = '<br />', $between = " ",363 $show_images = true, $orderby = 'id',364 $show_description = true, $limit = -1, $show_updated = 0) {362 $after = '<br />', $between = " ", 363 $show_images = true, $orderby = 'id', 364 $show_description = true, $limit = -1, $show_updated = 0) { 365 365 366 get_linksbyname($cat_name, $before, $after, $between, $show_images,367 $orderby, $show_description, true, $limit, $show_updated);366 get_linksbyname($cat_name, $before, $after, $between, $show_images, 367 $orderby, $show_description, true, $limit, $show_updated); 368 368 } 369 369 370 370 /** function get_links_withrating() … … 389 389 ** show_updated (default 0) - whether to show last updated timestamp 390 390 */ 391 391 function get_links_withrating($category = -1, $before = '', $after = '<br />', 392 $between = " ", $show_images = true,393 $orderby = 'id', $show_description = true,394 $limit = -1, $show_updated = 0) {392 $between = " ", $show_images = true, 393 $orderby = 'id', $show_description = true, 394 $limit = -1, $show_updated = 0) { 395 395 396 get_links($category, $before, $after, $between, $show_images, $orderby,397 $show_description, true, $limit, $show_updated);396 get_links($category, $before, $after, $between, $show_images, $orderby, 397 $show_description, true, $limit, $show_updated); 398 398 } 399 399 400 400 /** function get_get_autotoggle() … … 403 403 ** uses 0 404 404 */ 405 405 function get_autotoggle($id = 0) { 406 return 0; 406 return 0; 407 407 } 408 408 409 409 function list_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = '', $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1, $use_desc_for_title = 1, $children=FALSE, $child_of=0, $categories=0, $recurse=0, $feed = '', $feed_image = '', $exclude = '', $hierarchical=FALSE) { … … 433 433 $r['style'] = 'break'; 434 434 $r['title_li'] = ''; 435 435 436 return wp_list_categories($r); 436 return wp_list_categories($r); 437 437 } 438 438 439 439 function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = 'asc', -
wp-includes/feed.php
59 59 } 60 60 61 61 function permalink_single_rss($file = '') { 62 echo get_permalink();62 echo get_permalink(); 63 63 } 64 64 65 65 function comment_link() { … … 96 96 } 97 97 98 98 function get_author_rss_link($echo = false, $author_id, $author_nicename) { 99 $auth_ID = $author_id;100 $permalink_structure = get_settings('permalink_structure');99 $auth_ID = $author_id; 100 $permalink_structure = get_settings('permalink_structure'); 101 101 102 if ('' == $permalink_structure) {102 if ('' == $permalink_structure) { 103 103 $link = get_settings('home') . '?feed=rss2&author=' . $author_id; 104 } else {104 } else { 105 105 $link = get_author_link(0, $author_id, $author_nicename); 106 106 $link = $link . "feed/"; 107 }108 107 } 108 109 109 $link = apply_filters('author_feed_link', $link); 110 110 111 if ($echo) echo $link;112 return $link;111 if ($echo) echo $link; 112 return $link; 113 113 } 114 114 115 115 function get_category_rss_link($echo = false, $cat_ID, $category_nicename) { 116 $permalink_structure = get_settings('permalink_structure');116 $permalink_structure = get_settings('permalink_structure'); 117 117 118 if ('' == $permalink_structure) {118 if ('' == $permalink_structure) { 119 119 $link = get_settings('home') . '?feed=rss2&cat=' . $cat_ID; 120 } else {120 } else { 121 121 $link = get_category_link($cat_ID); 122 122 $link = $link . "feed/"; 123 }123 } 124 124 125 125 $link = apply_filters('category_feed_link', $link); 126 126 127 if ($echo) echo $link;128 return $link;127 if ($echo) echo $link; 128 return $link; 129 129 } 130 130 131 131 function the_category_rss($type = 'rss') { 132 $categories = get_the_category();133 $the_list = '';134 foreach ($categories as $category) {135 $category->cat_name = convert_chars($category->cat_name);136 if ('rdf' == $type) {137 $the_list .= "\n\t<dc:subject>$category->cat_name</dc:subject>";138 } else {139 $the_list .= "\n\t<category>$category->cat_name</category>";140 }141 }142 echo apply_filters('the_category_rss', $the_list, $type);132 $categories = get_the_category(); 133 $the_list = ''; 134 foreach ($categories as $category) { 135 $category->cat_name = convert_chars($category->cat_name); 136 if ('rdf' == $type) { 137 $the_list .= "\n\t<dc:subject>$category->cat_name</dc:subject>"; 138 } else { 139 $the_list .= "\n\t<category>$category->cat_name</category>"; 140 } 141 } 142 echo apply_filters('the_category_rss', $the_list, $type); 143 143 } 144 144 145 145 function rss_enclosure() { … … 148 148 149 149 $custom_fields = get_post_custom(); 150 150 if( is_array( $custom_fields ) ) { 151 while( list( $key, $val ) = each( $custom_fields ) ) { 151 while( list( $key, $val ) = each( $custom_fields ) ) { 152 152 if( $key == 'enclosure' ) { 153 153 if (is_array($val)) { 154 154 foreach($val as $enc) { -
wp-includes/formatting.php
58 58 $pee = $pee . "\n"; // just to make things a little easier, pad the end 59 59 $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); 60 60 // Space things out a little 61 $pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "\n$1", $pee); 61 $pee = preg_replace('!(<(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "\n$1", $pee); 62 62 $pee = preg_replace('!(</(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])>)!', "$1\n\n", $pee); 63 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 63 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 64 64 $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates 65 $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end 66 $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 65 $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end 66 $pee = preg_replace('|<p>\s*?</p>|', '', $pee); // under certain strange conditions it could create a P of entirely whitespace 67 67 $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); // don't pee all over a tag 68 68 $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists 69 69 $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee); 70 70 $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee); 71 71 $pee = preg_replace('!<p>\s*(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|hr|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)!', "$1", $pee); 72 $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); 72 $pee = preg_replace('!(</?(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6])[^>]*>)\s*</p>!', "$1", $pee); 73 73 if ($br) { 74 74 $pee = preg_replace('/<(script|style).*?<\/\\1>/se', 'str_replace("\n", "<WPPreserveNewline />", "\\0")', $pee); 75 75 $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks … … 79 79 $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!', '$1', $pee); 80 80 $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' ", $pee); 81 81 82 return $pee; 82 return $pee; 83 83 } 84 84 85 85 … … 117 117 } 118 118 119 119 function utf8_uri_encode( $utf8_string ) { 120 $unicode = ''; 121 $values = array(); 122 $num_octets = 1; 123 124 for ($i = 0; $i < strlen( $utf8_string ); $i++ ) { 120 $unicode = ''; 121 $values = array(); 122 $num_octets = 1; 125 123 126 $value = ord( $utf8_string[ $i ] ); 127 128 if ( $value < 128 ) { 129 $unicode .= chr($value); 130 } else { 131 if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; 132 133 $values[] = $value; 134 135 if ( count( $values ) == $num_octets ) { 124 for ($i = 0; $i < strlen( $utf8_string ); $i++ ) { 125 126 $value = ord( $utf8_string[ $i ] ); 127 128 if ( $value < 128 ) { 129 $unicode .= chr($value); 130 } else { 131 if ( count( $values ) == 0 ) $num_octets = ( $value < 224 ) ? 2 : 3; 132 133 $values[] = $value; 134 135 if ( count( $values ) == $num_octets ) { 136 136 if ($num_octets == 3) { 137 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]);137 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]) . '%' . dechex($values[2]); 138 138 } else { 139 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]);139 $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); 140 140 } 141 141 142 142 $values = array(); 143 143 $num_octets = 1; 144 }145 }146 }144 } 145 } 146 } 147 147 148 return $unicode; 148 return $unicode; 149 149 } 150 150 151 151 function remove_accents($string) { … … 325 325 return $title; 326 326 } 327 327 328 function convert_chars($content, $flag = 'obsolete') { 328 function convert_chars($content, $flag = 'obsolete') { 329 329 // Translation of invalid Unicode references range to valid range 330 330 $wp_htmltranswinuni = array( 331 331 '€' => '€', // the Euro sign … … 391 391 392 392 /* 393 393 balanceTags 394 394 395 395 Balances Tags of string using a modified stack. 396 396 397 397 @param text Text to be balanced 398 398 @return Returns balanced text 399 399 @author Leonard Lin (leonard@acm.org) 400 400 @version v1.1 401 401 @date November 4, 2001 402 402 @license GPL v2.0 403 @notes 404 @changelog 403 @notes 404 @changelog 405 405 --- Modified by Scott Reilly (coffee2code) 02 Aug 2004 406 1.2 ***TODO*** Make better - change loop condition to $text407 1.1 Fixed handling of append/stack pop order of end text408 Added Cleaning Hooks409 1.0 First Version406 1.2 ***TODO*** Make better - change loop condition to $text 407 1.1 Fixed handling of append/stack pop order of end text 408 Added Cleaning Hooks 409 1.0 First Version 410 410 */ 411 411 function balanceTags($text, $is_comment = 0, $force = false) { 412 412 … … 432 432 if ($regex[1][0] == "/") { // End Tag 433 433 $tag = strtolower(substr($regex[1],1)); 434 434 // if too many closing tags 435 if($stacksize <= 0) { 435 if($stacksize <= 0) { 436 436 $tag = ''; 437 437 //or close to be safe $tag = '/' . $tag; 438 438 } … … 489 489 } 490 490 $newtext .= substr($text,0,$i) . $tag; 491 491 $text = substr($text,$i+$l); 492 } 492 } 493 493 494 494 // Clear Tag Queue 495 495 $newtext .= $tagqueue; … … 538 538 } 539 539 540 540 function trailingslashit($string) { 541 if ( '/' != substr($string, -1)) {542 $string .= '/';543 }544 return $string;541 if ( '/' != substr($string, -1)) { 542 $string .= '/'; 543 } 544 return $string; 545 545 } 546 546 547 547 function addslashes_gpc($gpc) { … … 557 557 558 558 function stripslashes_deep($value) 559 559 { 560 $value = is_array($value) ?561 array_map('stripslashes_deep', $value) :562 stripslashes($value);560 $value = is_array($value) ? 561 array_map('stripslashes_deep', $value) : 562 stripslashes($value); 563 563 564 return $value;564 return $value; 565 565 } 566 566 567 567 function antispambot($emailaddy, $mailto=0) { … … 601 601 602 602 function convert_smilies($text) { 603 603 global $wp_smiliessearch, $wp_smiliesreplace; 604 $output = '';604 $output = ''; 605 605 if (get_settings('use_smilies')) { 606 606 // HTML loop taken from texturize function, could possible be consolidated 607 607 $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between … … 636 636 637 637 // used by wp-mail to handle charsets in email subjects 638 638 function wp_iso_descrambler($string) { 639 /* this may only work with iso-8859-1, I'm afraid */640 if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) {641 return $string;642 } else {643 $subject = str_replace('_', ' ', $matches[2]);644 $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject);645 return $subject;646 }639 /* this may only work with iso-8859-1, I'm afraid */ 640 if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $string, $matches)) { 641 return $string; 642 } else { 643 $subject = str_replace('_', ' ', $matches[2]); 644 $subject = preg_replace('#\=([0-9a-f]{2})#ei', "chr(hexdec(strtolower('$1')))", $subject); 645 return $subject; 646 } 647 647 } 648 648 649 649 650 650 // give it a date, it will give you the same date as GMT 651 651 function get_gmt_from_date($string) { 652 // note: this only substracts $time_difference from the given date653 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);654 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);655 $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_settings('gmt_offset') * 3600);656 return $string_gmt;652 // note: this only substracts $time_difference from the given date 653 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 654 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 655 $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_settings('gmt_offset') * 3600); 656 return $string_gmt; 657 657 } 658 658 659 659 // give it a GMT date, it will give you the same date with $time_difference added 660 660 function get_date_from_gmt($string) { 661 // note: this only adds $time_difference to the given date662 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);663 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);664 $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_settings('gmt_offset')*3600);665 return $string_localtime;661 // note: this only adds $time_difference to the given date 662 preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 663 $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 664 $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_settings('gmt_offset')*3600); 665 return $string_localtime; 666 666 } 667 667 668 668 // computes an offset in seconds from an iso8601 timezone 669 669 function iso8601_timezone_to_offset($timezone) { 670 // $timezone is either 'Z' or '[+|-]hhmm'671 if ($timezone == 'Z') {672 $offset = 0;673 } else {674 $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1;675 $hours = intval(substr($timezone, 1, 2));676 $minutes = intval(substr($timezone, 3, 4)) / 60;677 $offset = $sign * 3600 * ($hours + $minutes);678 }679 return $offset;670 // $timezone is either 'Z' or '[+|-]hhmm' 671 if ($timezone == 'Z') { 672 $offset = 0; 673 } else { 674 $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1; 675 $hours = intval(substr($timezone, 1, 2)); 676 $minutes = intval(substr($timezone, 3, 4)) / 60; 677 $offset = $sign * 3600 * ($hours + $minutes); 678 } 679 return $offset; 680 680 } 681 681 682 682 // converts an iso8601 date to MySQL DateTime format used by post_date[_gmt] 683 683 function iso8601_to_datetime($date_string, $timezone = USER) { 684 if ($timezone == GMT) {685 preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits);686 if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset687 $offset = iso8601_timezone_to_offset($date_bits[7]);688 } else { // we don't have a timezone, so we assume user local timezone (not server's!)689 $offset = 3600 * get_settings('gmt_offset');690 }691 $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);692 $timestamp -= $offset;693 return gmdate('Y-m-d H:i:s', $timestamp);694 } elseif ($timezone == USER) {695 return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);696 }684 if ($timezone == GMT) { 685 preg_match('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', $date_string, $date_bits); 686 if (!empty($date_bits[7])) { // we have a timezone, so let's compute an offset 687 $offset = iso8601_timezone_to_offset($date_bits[7]); 688 } else { // we don't have a timezone, so we assume user local timezone (not server's!) 689 $offset = 3600 * get_settings('gmt_offset'); 690 } 691 $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]); 692 $timestamp -= $offset; 693 return gmdate('Y-m-d H:i:s', $timestamp); 694 } elseif ($timezone == USER) { 695 return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string); 696 } 697 697 } 698 698 699 699 function popuplinks($text) { … … 708 708 return preg_replace('/[^a-z0-9+_.@-]/i', '', $email); 709 709 } 710 710 711 function human_time_diff( $from, $to = '' ) { 711 function human_time_diff( $from, $to = '' ) { 712 712 if ( empty($to) ) 713 713 $to = time(); 714 714 $diff = (int) abs($to - $from); … … 722 722 $hours = round($diff / 3600); 723 723 if ($hours <= 1) 724 724 $since = __('1 hour'); 725 else 725 else 726 726 $since = sprintf( __('%s hours'), $hours ); 727 727 } elseif ($diff >= 86400) { 728 728 $days = round($diff / 86400); -
wp-includes/functions.php
12 12 13 13 if( 'U' == $dateformatstring ) 14 14 return $i; 15 15 16 16 if ( -1 == $i || false == $i ) 17 17 $i = 0; 18 18 … … 438 438 @set_time_limit( 60 ); 439 439 440 440 if ( $red > 5 ) 441 return false;441 return false; 442 442 443 443 $parts = parse_url( $url ); 444 444 $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : ''); … … 467 467 preg_match('/.*([0-9]{3}).*/', $response, $return); 468 468 $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404 469 469 470 $code = $headers['response'];471 if ( ('302' == $code || '301' == $code) && isset($headers['location']) )472 return wp_get_http_headers( $headers['location'], ++$red );470 $code = $headers['response']; 471 if ( ('302' == $code || '301' == $code) && isset($headers['location']) ) 472 return wp_get_http_headers( $headers['location'], ++$red ); 473 473 474 474 return $headers; 475 475 } … … 743 743 } 744 744 745 745 function bool_from_yn($yn) { 746 if ($yn == 'Y') return 1;747 return 0;746 if ($yn == 'Y') return 1; 747 return 0; 748 748 } 749 749 750 750 function do_feed() { … … 754 754 $feed = preg_replace('/^_+/', '', $feed); 755 755 756 756 if ($feed == '' || $feed == 'feed') 757 $feed = 'rss2';757 $feed = 'rss2'; 758 758 759 759 $for_comments = false; 760 760 if ( is_single() || (get_query_var('withcomments') == 1) ) { 761 761 $feed = 'rss2'; 762 $for_comments = true; 762 $for_comments = true; 763 763 } 764 764 765 765 $hook = 'do_feed_' . $feed; … … 899 899 return array('error' => $message); 900 900 } 901 901 902 $uploads = array('path' => $dir, 'url' => $url, 'error' => false);902 $uploads = array('path' => $dir, 'url' => $url, 'error' => false); 903 903 return apply_filters('upload_dir', $uploads); 904 904 } 905 905 -
wp-includes/general-template.php
438 438 FROM $wpdb->posts 439 439 WHERE post_date > '$thisyear-$thismonth-01' 440 440 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 441 AND post_type = 'post' AND post_status = 'publish' 441 AND post_type = 'post' AND post_status = 'publish' 442 442 ORDER BY post_date ASC 443 443 LIMIT 1"); 444 444 … … 741 741 var i = tinyMCE.selectedInstance; 742 742 if(typeof i == 'undefined') 743 743 return true; 744 tinyMCE.execCommand("mceStartTyping");744 tinyMCE.execCommand("mceStartTyping"); 745 745 this.blur(); 746 746 i.contentWindow.focus(); 747 747 e.returnValue = false; … … 756 756 var i = tinyMCE.selectedInstance; 757 757 if(typeof i == 'undefined') 758 758 return true; 759 tinyMCE.execCommand("mceStartTyping");759 tinyMCE.execCommand("mceStartTyping"); 760 760 this.blur(); 761 761 i.contentWindow.focus(); 762 762 e.returnValue = false; -
wp-includes/gettext.php
1 1 <?php 2 2 /* 3 Copyright (c) 2003 Danilo Segan <danilo@kvota.net>. 4 Copyright (c) 2005 Nico Kaiser <nico@siriux.net> 5 6 This file is part of PHP-gettext. 3 Copyright (c) 2003 Danilo Segan <danilo@kvota.net>. 4 Copyright (c) 2005 Nico Kaiser <nico@siriux.net> 7 5 8 PHP-gettext is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 6 This file is part of PHP-gettext. 12 7 13 PHP-gettext is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details.8 PHP-gettext is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 17 12 18 You should have received a copy of the GNU General Public License 19 along with PHP-gettext; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 13 PHP-gettext is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 21 17 18 You should have received a copy of the GNU General Public License 19 along with PHP-gettext; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 22 */ 23 23 24 24 /** 25 25 * Provides a simple gettext replacement that works independently from 26 26 * the system's gettext abilities. 27 27 * It can read MO files and use them for translating strings. 28 28 * The files are passed to gettext_reader as a Stream (see streams.php) 29 * 29 * 30 30 * This version has the ability to cache all strings and translations to 31 31 * speed up the string lookup. 32 32 * While the cache is enabled by default, it can be switched off with the … … 34 34 * that you don't want to keep in memory) 35 35 */ 36 36 class gettext_reader { 37 //public: 38 var $error = 0; // public variable that holds error code (0 if no error) 39 40 //private: 41 var $BYTEORDER = 0; // 0: low endian, 1: big endian 42 var $STREAM = NULL; 43 var $short_circuit = false; 44 var $enable_cache = false; 45 var $originals = NULL; // offset of original table 46 var $translations = NULL; // offset of translation table 47 var $pluralheader = NULL; // cache header field for plural forms 48 var $total = 0; // total string count 49 var $table_originals = NULL; // table for original strings (offsets) 50 var $table_translations = NULL; // table for translated strings (offsets) 51 var $cache_translations = NULL; // original -> translation mapping 37 //public: 38 var $error = 0; // public variable that holds error code (0 if no error) 52 39 40 //private: 41 var $BYTEORDER = 0; // 0: low endian, 1: big endian 42 var $STREAM = NULL; 43 var $short_circuit = false; 44 var $enable_cache = false; 45 var $originals = NULL; // offset of original table 46 var $translations = NULL; // offset of translation table 47 var $pluralheader = NULL; // cache header field for plural forms 48 var $total = 0; // total string count 49 var $table_originals = NULL; // table for original strings (offsets) 50 var $table_translations = NULL; // table for translated strings (offsets) 51 var $cache_translations = NULL; // original -> translation mapping 53 52 54 /* Methods */55 56 57 /**58 * Reads a 32bit Integer from the Stream59 *60 * @access private61 * @return Integer from the Stream62 */63 function readint() {64 $stream = $this->STREAM->read(4);65 if ($this->BYTEORDER == 0) {66 // low endian67 $unpacked = unpack('V',$stream);68 return array_shift($unpacked);69 } else {70 // big endian71 $unpacked = unpack('N',$stream);72 return array_shift($unpacked);73 }74 }75 53 76 /** 77 * Reads an array of Integers from the Stream 78 * 79 * @param int count How many elements should be read 80 * @return Array of Integers 81 */ 82 function readintarray($count) { 83 if ($this->BYTEORDER == 0) { 84 // low endian 85 return unpack('V'.$count, $this->STREAM->read(4 * $count)); 86 } else { 87 // big endian 88 return unpack('N'.$count, $this->STREAM->read(4 * $count)); 89 } 90 } 91 92 /** 93 * Constructor 94 * 95 * @param object Reader the StreamReader object 96 * @param boolean enable_cache Enable or disable caching of strings (default on) 97 */ 98 function gettext_reader($Reader, $enable_cache = true) { 99 // If there isn't a StreamReader, turn on short circuit mode. 100 if (! $Reader) { 101 $this->short_circuit = true; 102 return; 103 } 104 105 // Caching can be turned off 106 $this->enable_cache = $enable_cache; 54 /* Methods */ 107 55 108 // $MAGIC1 = (int)0x950412de; //bug in PHP 5109 $MAGIC1 = (int) - 1794895138;110 // $MAGIC2 = (int)0xde120495; //bug111 $MAGIC2 = (int) - 569244523;112 56 113 $this->STREAM = $Reader; 114 $magic = $this->readint(); 115 if ($magic == $MAGIC1) { 116 $this->BYTEORDER = 0; 117 } elseif ($magic == $MAGIC2) { 118 $this->BYTEORDER = 1; 119 } else { 120 $this->error = 1; // not MO file 121 return false; 122 } 123 124 // FIXME: Do we care about revision? We should. 125 $revision = $this->readint(); 126 127 $this->total = $this->readint(); 128 $this->originals = $this->readint(); 129 $this->translations = $this->readint(); 130 } 131 132 /** 133 * Loads the translation tables from the MO file into the cache 134 * If caching is enabled, also loads all strings into a cache 135 * to speed up translation lookups 136 * 137 * @access private 138 */ 139 function load_tables() { 140 if (is_array($this->cache_translations) && 141 is_array($this->table_originals) && 142 is_array($this->table_translations)) 143 return; 144 145 /* get original and translations tables */ 146 $this->STREAM->seekto($this->originals); 147 $this->table_originals = $this->readintarray($this->total * 2); 148 $this->STREAM->seekto($this->translations); 149 $this->table_translations = $this->readintarray($this->total * 2); 150 151 if ($this->enable_cache) { 152 $this->cache_translations = array (); 153 /* read all strings in the cache */ 154 for ($i = 0; $i < $this->total; $i++) { 155 $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); 156 $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); 157 $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); 158 $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); 159 $this->cache_translations[$original] = $translation; 160 } 161 } 162 } 163 164 /** 165 * Returns a string from the "originals" table 166 * 167 * @access private 168 * @param int num Offset number of original string 169 * @return string Requested string if found, otherwise '' 170 */ 171 function get_original_string($num) { 172 $length = $this->table_originals[$num * 2 + 1]; 173 $offset = $this->table_originals[$num * 2 + 2]; 174 if (! $length) 175 return ''; 176 $this->STREAM->seekto($offset); 177 $data = $this->STREAM->read($length); 178 return (string)$data; 179 } 180 181 /** 182 * Returns a string from the "translations" table 183 * 184 * @access private 185 * @param int num Offset number of original string 186 * @return string Requested string if found, otherwise '' 187 */ 188 function get_translation_string($num) { 189 $length = $this->table_translations[$num * 2 + 1]; 190 $offset = $this->table_translations[$num * 2 + 2]; 191 if (! $length) 192 return ''; 193 $this->STREAM->seekto($offset); 194 $data = $this->STREAM->read($length); 195 return (string)$data; 196 } 197 198 /** 199 * Binary search for string 200 * 201 * @access private 202 * @param string string 203 * @param int start (internally used in recursive function) 204 * @param int end (internally used in recursive function) 205 * @return int string number (offset in originals table) 206 */ 207 function find_string($string, $start = -1, $end = -1) { 208 if (($start == -1) or ($end == -1)) { 209 // find_string is called with only one parameter, set start end end 210 $start = 0; 211 $end = $this->total; 212 } 213 if (abs($start - $end) <= 1) { 214 // We're done, now we either found the string, or it doesn't exist 215 $txt = $this->get_original_string($start); 216 if ($string == $txt) 217 return $start; 218 else 219 return -1; 220 } else if ($start > $end) { 221 // start > end -> turn around and start over 222 return $this->find_string($string, $end, $start); 223 } else { 224 // Divide table in two parts 225 $half = (int)(($start + $end) / 2); 226 $cmp = strcmp($string, $this->get_original_string($half)); 227 if ($cmp == 0) 228 // string is exactly in the middle => return it 229 return $half; 230 else if ($cmp < 0) 231 // The string is in the upper half 232 return $this->find_string($string, $start, $half); 233 else 234 // The string is in the lower half 235 return $this->find_string($string, $half, $end); 236 } 237 } 238 239 /** 240 * Translates a string 241 * 242 * @access public 243 * @param string string to be translated 244 * @return string translated string (or original, if not found) 245 */ 246 function translate($string) { 247 if ($this->short_circuit) 248 return $string; 249 $this->load_tables(); 250 251 if ($this->enable_cache) { 252 // Caching enabled, get translated string from cache 253 if (array_key_exists($string, $this->cache_translations)) 254 return $this->cache_translations[$string]; 255 else 256 return $string; 257 } else { 258 // Caching not enabled, try to find string 259 $num = $this->find_string($string); 260 if ($num == -1) 261 return $string; 262 else 263 return $this->get_translation_string($num); 264 } 265 } 57 /** 58 * Reads a 32bit Integer from the Stream 59 * 60 * @access private 61 * @return Integer from the Stream 62 */ 63 function readint() { 64 $stream = $this->STREAM->read(4); 65 if ($this->BYTEORDER == 0) { 66 // low endian 67 $unpacked = unpack('V',$stream); 68 return array_shift($unpacked); 69 } else { 70 // big endian 71 $unpacked = unpack('N',$stream); 72 return array_shift($unpacked); 73 } 74 } 266 75 267 /** 268 * Get possible plural forms from MO header 269 * 270 * @access private 271 * @return string plural form header 272 */ 273 function get_plural_forms() { 274 // lets assume message number 0 is header 275 // this is true, right? 276 $this->load_tables(); 277 278 // cache header field for plural forms 279 if (! is_string($this->pluralheader)) { 280 if ($this->enable_cache) { 281 $header = $this->cache_translations[""]; 282 } else { 283 $header = $this->get_translation_string(0); 284 } 285 if (eregi("plural-forms: (.*)\n", $header, $regs)) 286 $expr = $regs[1]; 287 else 288 $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; 289 $this->pluralheader = $expr; 290 } 291 return $this->pluralheader; 292 } 76 /** 77 * Reads an array of Integers from the Stream 78 * 79 * @param int count How many elements should be read 80 * @return Array of Integers 81 */ 82 function readintarray($count) { 83 if ($this->BYTEORDER == 0) { 84 // low endian 85 return unpack('V'.$count, $this->STREAM->read(4 * $count)); 86 } else { 87 // big endian 88 return unpack('N'.$count, $this->STREAM->read(4 * $count)); 89 } 90 } 293 91 294 /** 295 * Detects which plural form to take 296 * 297 * @access private 298 * @param n count 299 * @return int array index of the right plural form 300 */ 301 function select_string($n) { 302 $string = $this->get_plural_forms(); 303 $string = str_replace('nplurals',"\$total",$string); 304 $string = str_replace("n",$n,$string); 305 $string = str_replace('plural',"\$plural",$string); 306 307 $total = 0; 308 $plural = 0; 92 /** 93 * Constructor 94 * 95 * @param object Reader the StreamReader object 96 * @param boolean enable_cache Enable or disable caching of strings (default on) 97 */ 98 function gettext_reader($Reader, $enable_cache = true) { 99 // If there isn't a StreamReader, turn on short circuit mode. 100 if (! $Reader) { 101 $this->short_circuit = true; 102 return; 103 } 309 104 310 eval("$string"); 311 if ($plural >= $total) $plural = 0; 312 return $plural; 313 } 105 // Caching can be turned off 106 $this->enable_cache = $enable_cache; 314 107 315 /** 316 * Plural version of gettext 317 * 318 * @access public 319 * @param string single 320 * @param string plural 321 * @param string number 322 * @return translated plural form 323 */ 324 function ngettext($single, $plural, $number) { 325 if ($this->short_circuit) { 326 if ($number != 1) 327 return $plural; 328 else 329 return $single; 330 } 108 // $MAGIC1 = (int)0x950412de; //bug in PHP 5 109 $MAGIC1 = (int) - 1794895138; 110 // $MAGIC2 = (int)0xde120495; //bug 111 $MAGIC2 = (int) - 569244523; 331 112 332 // find out the appropriate form 333 $select = $this->select_string($number); 334 335 // this should contains all strings separated by NULLs 336 $key = $single.chr(0).$plural; 337 338 339 if ($this->enable_cache) { 340 if (! array_key_exists($key, $this->cache_translations)) { 341 return ($number != 1) ? $plural : $single; 342 } else { 343 $result = $this->cache_translations[$key]; 344 $list = explode(chr(0), $result); 345 return $list[$select]; 346 } 347 } else { 348 $num = $this->find_string($key); 349 if ($num == -1) { 350 return ($number != 1) ? $plural : $single; 351 } else { 352 $result = $this->get_translation_string($num); 353 $list = explode(chr(0), $result); 354 return $list[$select]; 355 } 356 } 357 } 113 $this->STREAM = $Reader; 114 $magic = $this->readint(); 115 if ($magic == $MAGIC1) { 116 $this->BYTEORDER = 0; 117 } elseif ($magic == $MAGIC2) { 118 $this->BYTEORDER = 1; 119 } else { 120 $this->error = 1; // not MO file 121 return false; 122 } 358 123 124 // FIXME: Do we care about revision? We should. 125 $revision = $this->readint(); 126 127 $this->total = $this->readint(); 128 $this->originals = $this->readint(); 129 $this->translations = $this->readint(); 130 } 131 132 /** 133 * Loads the translation tables from the MO file into the cache 134 * If caching is enabled, also loads all strings into a cache 135 * to speed up translation lookups 136 * 137 * @access private 138 */ 139 function load_tables() { 140 if (is_array($this->cache_translations) && 141 is_array($this->table_originals) && 142 is_array($this->table_translations)) 143 return; 144 145 /* get original and translations tables */ 146 $this->STREAM->seekto($this->originals); 147 $this->table_originals = $this->readintarray($this->total * 2); 148 $this->STREAM->seekto($this->translations); 149 $this->table_translations = $this->readintarray($this->total * 2); 150 151 if ($this->enable_cache) { 152 $this->cache_translations = array (); 153 /* read all strings in the cache */ 154 for ($i = 0; $i < $this->total; $i++) { 155 $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); 156 $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); 157 $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); 158 $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); 159 $this->cache_translations[$original] = $translation; 160 } 161 } 162 } 163 164 /** 165 * Returns a string from the "originals" table 166 * 167 * @access private 168 * @param int num Offset number of original string 169 * @return string Requested string if found, otherwise '' 170 */ 171 function get_original_string($num) { 172 $length = $this->table_originals[$num * 2 + 1]; 173 $offset = $this->table_originals[$num * 2 + 2]; 174 if (! $length) 175 return ''; 176 $this->STREAM->seekto($offset); 177 $data = $this->STREAM->read($length); 178 return (string)$data; 179 } 180 181 /** 182 * Returns a string from the "translations" table 183 * 184 * @access private 185 * @param int num Offset number of original string 186 * @return string Requested string if found, otherwise '' 187 */ 188 function get_translation_string($num) { 189 $length = $this->table_translations[$num * 2 + 1]; 190 $offset = $this->table_translations[$num * 2 + 2]; 191 if (! $length) 192 return ''; 193 $this->STREAM->seekto($offset); 194 $data = $this->STREAM->read($length); 195 return (string)$data; 196 } 197 198 /** 199 * Binary search for string 200 * 201 * @access private 202 * @param string string 203 * @param int start (internally used in recursive function) 204 * @param int end (internally used in recursive function) 205 * @return int string number (offset in originals table) 206 */ 207 function find_string($string, $start = -1, $end = -1) { 208 if (($start == -1) or ($end == -1)) { 209 // find_string is called with only one parameter, set start end end 210 $start = 0; 211 $end = $this->total; 212 } 213 if (abs($start - $end) <= 1) { 214 // We're done, now we either found the string, or it doesn't exist 215 $txt = $this->get_original_string($start); 216 if ($string == $txt) 217 return $start; 218 else 219 return -1; 220 } else if ($start > $end) { 221 // start > end -> turn around and start over 222 return $this->find_string($string, $end, $start); 223 } else { 224 // Divide table in two parts 225 $half = (int)(($start + $end) / 2); 226 $cmp = strcmp($string, $this->get_original_string($half)); 227 if ($cmp == 0) 228 // string is exactly in the middle => return it 229 return $half; 230 else if ($cmp < 0) 231 // The string is in the upper half 232 return $this->find_string($string, $start, $half); 233 else 234 // The string is in the lower half 235 return $this->find_string($string, $half, $end); 236 } 237 } 238 239 /** 240 * Translates a string 241 * 242 * @access public 243 * @param string string to be translated 244 * @return string translated string (or original, if not found) 245 */ 246 function translate($string) { 247 if ($this->short_circuit) 248 return $string; 249 $this->load_tables(); 250 251 if ($this->enable_cache) { 252 // Caching enabled, get translated string from cache 253 if (array_key_exists($string, $this->cache_translations)) 254 return $this->cache_translations[$string]; 255 else 256 return $string; 257 } else { 258 // Caching not enabled, try to find string 259 $num = $this->find_string($string); 260 if ($num == -1) 261 return $string; 262 else 263 return $this->get_translation_string($num); 264 } 265 } 266 267 /** 268 * Get possible plural forms from MO header 269 * 270 * @access private 271 * @return string plural form header 272 */ 273 function get_plural_forms() { 274 // lets assume message number 0 is header 275 // this is true, right? 276 $this->load_tables(); 277 278 // cache header field for plural forms 279 if (! is_string($this->pluralheader)) { 280 if ($this->enable_cache) { 281 $header = $this->cache_translations[""]; 282 } else { 283 $header = $this->get_translation_string(0); 284 } 285 if (eregi("plural-forms: (.*)\n", $header, $regs)) 286 $expr = $regs[1]; 287 else 288 $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; 289 $this->pluralheader = $expr; 290 } 291 return $this->pluralheader; 292 } 293 294 /** 295 * Detects which plural form to take 296 * 297 * @access private 298 * @param n count 299 * @return int array index of the right plural form 300 */ 301 function select_string($n) { 302 $string = $this->get_plural_forms(); 303 $string = str_replace('nplurals',"\$total",$string); 304 $string = str_replace("n",$n,$string); 305 $string = str_replace('plural',"\$plural",$string); 306 307 $total = 0; 308 $plural = 0; 309 310 eval("$string"); 311 if ($plural >= $total) $plural = 0; 312 return $plural; 313 } 314 315 /** 316 * Plural version of gettext 317 * 318 * @access public 319 * @param string single 320 * @param string plural 321 * @param string number 322 * @return translated plural form 323 */ 324 function ngettext($single, $plural, $number) { 325 if ($this->short_circuit) { 326 if ($number != 1) 327 return $plural; 328 else 329 return $single; 330 } 331 332 // find out the appropriate form 333 $select = $this->select_string($number); 334 335 // this should contains all strings separated by NULLs 336 $key = $single.chr(0).$plural; 337 338 339 if ($this->enable_cache) { 340 if (! array_key_exists($key, $this->cache_translations)) { 341 return ($number != 1) ? $plural : $single; 342 } else { 343 $result = $this->cache_translations[$key]; 344 $list = explode(chr(0), $result); 345 return $list[$select]; 346 } 347 } else { 348 $num = $this->find_string($key); 349 if ($num == -1) { 350 return ($number != 1) ? $plural : $single; 351 } else { 352 $result = $this->get_translation_string($num); 353 $list = explode(chr(0), $result); 354 return $list[$select]; 355 } 356 } 357 } 358 359 359 } 360 360 361 361 ?> -
wp-includes/l10n.php
23 23 return $locale; 24 24 } 25 25 26 // Return a translated string. 26 // Return a translated string. 27 27 function __($text, $domain = 'default') { 28 28 global $l10n; 29 29 -
wp-includes/link-template.php
63 63 $authordata = get_userdata($post->post_author); 64 64 $author = $authordata->user_nicename; 65 65 $date = explode(" ",date('Y m d H i s', $unixtime)); 66 $rewritereplace = 66 $rewritereplace = 67 67 array( 68 68 $date[0], 69 69 $date[1], … … 266 266 for ( $i = 1; $i < (count($cat_array)); $i++ ) { 267 267 $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID); 268 268 } 269 $join .= ')'; 269 $join .= ')'; 270 270 } 271 271 272 272 $sql_exclude_cats = ''; … … 299 299 for ( $i = 1; $i < (count($cat_array)); $i++ ) { 300 300 $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID); 301 301 } 302 $join .= ')'; 302 $join .= ')'; 303 303 } 304 304 305 305 $sql_exclude_cats = ''; … … 334 334 335 335 $format = str_replace('%link', $link, $format); 336 336 337 echo $format; 337 echo $format; 338 338 } 339 339 340 340 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { … … 349 349 $link = $string . $link . '</a>'; 350 350 $format = str_replace('%link', $link, $format); 351 351 352 echo $format; 352 echo $format; 353 353 } 354 354 355 355 function get_pagenum_link($pagenum = 1) { … … 357 357 358 358 $qstr = wp_specialchars($_SERVER['REQUEST_URI']); 359 359 360 $page_querystring = "paged"; 360 $page_querystring = "paged"; 361 361 $page_modstring = "page/"; 362 362 $page_modregex = "page/?"; 363 363 $permalink = 0; … … 474 474 function _max_num_pages() { 475 475 static $max_num_pages; 476 476 global $wpdb, $wp_query; 477 477 478 478 if (isset($max_num_pages)) return $max_num_pages; 479 479 480 480 if ( 'posts' == get_query_var('what_to_show') ) { 481 481 preg_match('#FROM\s(.*)\sORDER BY#siU', $wp_query->request, $matches); 482 482 $fromwhere = $matches[1]; … … 496 496 if ( !is_single() ) { 497 497 $max_num_pages = _max_num_pages(); 498 498 $paged = get_query_var('paged'); 499 499 500 500 //only have sep if there's both prev and next results 501 501 if ($paged < 2 || $paged >= $max_num_pages) { 502 502 $sep = ''; -
wp-includes/pluggable.php
46 46 if ( ! empty($current_user) ) 47 47 return; 48 48 49 if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || 49 if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || 50 50 !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { 51 51 wp_set_current_user(0); 52 52 return false; … … 162 162 function wp_mail($to, $subject, $message, $headers = '') { 163 163 if( $headers == '' ) { 164 164 $headers = "MIME-Version: 1.0\n" . 165 "From: wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n" . 165 "From: wordpress@" . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n" . 166 166 "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n"; 167 167 } 168 168 … … 216 216 if ( !function_exists('auth_redirect') ) : 217 217 function auth_redirect() { 218 218 // Checks if a user is logged in, if not redirects them to the login page 219 if ( (!empty($_COOKIE[USER_COOKIE]) && 219 if ( (!empty($_COOKIE[USER_COOKIE]) && 220 220 !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) || 221 221 (empty($_COOKIE[USER_COOKIE])) ) { 222 222 nocache_headers(); … … 327 327 if ( ! function_exists('wp_notify_postauthor') ) : 328 328 function wp_notify_postauthor($comment_id, $comment_type='') { 329 329 global $wpdb; 330 330 331 331 $comment = get_comment($comment_id); 332 332 $post = get_post($comment->comment_post_ID); 333 333 $user = get_userdata( $post->post_author ); … … 374 374 $from = "From: \"$blogname\" <$wp_email>"; 375 375 if ( '' != $comment->comment_author_email ) 376 376 $reply_to = "Reply-To: $comment->comment_author_email"; 377 } else {377 } else { 378 378 $from = "From: \"$comment->comment_author\" <$wp_email>"; 379 379 if ( '' != $comment->comment_author_email ) 380 380 $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; 381 }381 } 382 382 383 383 $message_headers = "MIME-Version: 1.0\n" 384 384 . "$from\n" … … 392 392 $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); 393 393 394 394 @wp_mail($user->user_email, $subject, $notify_message, $message_headers); 395 395 396 396 return true; 397 397 } 398 398 endif; 399 399 400 400 /* wp_notify_moderator 401 notifies the moderator of the blog (usually the admin)402 about a new comment that waits for approval403 always returns true401 notifies the moderator of the blog (usually the admin) 402 about a new comment that waits for approval 403 always returns true 404 404 */ 405 405 if ( !function_exists('wp_notify_moderator') ) : 406 406 function wp_notify_moderator($comment_id) { 407 407 global $wpdb; 408 408 409 409 if( get_settings( "moderation_notify" ) == 0 ) 410 return true; 411 410 return true; 411 412 412 $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); 413 413 $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1"); 414 414 … … 435 435 $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); 436 436 437 437 @wp_mail($admin_email, $subject, $notify_message); 438 438 439 439 return true; 440 440 } 441 441 endif; … … 485 485 $uid = $user->id; 486 486 487 487 $i = ceil(time() / 43200); 488 488 489 489 return substr(wp_hash($i . $action . $uid), -12, 10); 490 490 } 491 491 endif; -
wp-includes/plugin.php
103 103 function do_action($tag, $arg = '') { 104 104 global $wp_filter; 105 105 $extra_args = array_slice(func_get_args(), 2); 106 if ( is_array($arg) )107 $args = array_merge($arg, $extra_args);106 if ( is_array($arg) ) 107 $args = array_merge($arg, $extra_args); 108 108 else 109 109 $args = array_merge(array($arg), $extra_args); 110 110 -
wp-includes/post.php
160 160 $inclusions = ''; 161 161 if ( !empty($include) ) { 162 162 $offset = 0; //ignore offset, category, exclude, meta_key, and meta_value params if using include 163 $category = ''; 164 $exclude = ''; 163 $category = ''; 164 $exclude = ''; 165 165 $meta_key = ''; 166 166 $meta_value = ''; 167 167 $incposts = preg_split('/[\s,]+/',$include); … … 175 175 } 176 176 } 177 177 } 178 if (!empty($inclusions)) 179 $inclusions .= ')'; 178 if (!empty($inclusions)) 179 $inclusions .= ')'; 180 180 181 181 $exclusions = ''; 182 182 if ( !empty($exclude) ) { … … 190 190 } 191 191 } 192 192 } 193 if (!empty($exclusions)) 193 if (!empty($exclusions)) 194 194 $exclusions .= ')'; 195 195 196 196 $query ="SELECT DISTINCT * FROM $wpdb->posts " ; 197 $query .= ( empty( $category ) ? "" : ", $wpdb->post2cat " ) ; 198 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 197 $query .= ( empty( $category ) ? "" : ", $wpdb->post2cat " ) ; 198 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 199 199 $query .= " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " ; 200 200 $query .= ( empty( $category ) ? "" : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") " ) ; 201 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' )" ) ; … … 429 429 430 430 $post_ID = (int) $post_ID; 431 431 432 $sql = "SELECT category_id 433 FROM $wpdb->post2cat 434 WHERE post_id = '$post_ID' 432 $sql = "SELECT category_id 433 FROM $wpdb->post2cat 434 WHERE post_id = '$post_ID' 435 435 ORDER BY category_id"; 436 436 437 437 $result = $wpdb->get_col($sql); … … 464 464 // Set categories 465 465 if($mode == OBJECT) { 466 466 $post->post_category = wp_get_post_categories($postid); 467 } 467 } 468 468 else { 469 469 $post['post_category'] = wp_get_post_categories($postid); 470 470 } … … 657 657 if ( !defined('WP_IMPORTING') ) { 658 658 if ( $post_pingback ) 659 659 $result = $wpdb->query(" 660 INSERT INTO $wpdb->postmeta 661 (post_id,meta_key,meta_value) 660 INSERT INTO $wpdb->postmeta 661 (post_id,meta_key,meta_value) 662 662 VALUES ('$post_ID','_pingme','1') 663 663 "); 664 664 $result = $wpdb->query(" 665 INSERT INTO $wpdb->postmeta 666 (post_id,meta_key,meta_value) 665 INSERT INTO $wpdb->postmeta 666 (post_id,meta_key,meta_value) 667 667 VALUES ('$post_ID','_encloseme','1') 668 668 "); 669 669 wp_schedule_single_event(time(), 'do_pings'); … … 675 675 if ( !empty($page_template) ) 676 676 if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template)) 677 677 add_post_meta($post_ID, '_wp_page_template', $page_template, true); 678 678 679 679 if ( $post_status == 'publish' ) 680 680 do_action('publish_page', $post_ID); 681 681 } … … 683 683 if ( 'future' == $post_status ) { 684 684 wp_schedule_single_event(mysql2date('U', $post_date), 'publish_future_post', $post_ID); 685 685 } 686 686 687 687 do_action('save_post', $post_ID); 688 688 do_action('wp_insert_post', $post_ID); 689 689 … … 703 703 $post = add_magic_quotes($post); 704 704 705 705 // Passed post category list overwrites existing category list if not empty. 706 if ( isset($postarr['post_category']) && is_array($postarr['post_category'])706 if ( isset($postarr['post_category']) && is_array($postarr['post_category']) 707 707 && 0 != count($postarr['post_category']) ) 708 $post_cats = $postarr['post_category'];709 else 710 $post_cats = $post['post_category'];708 $post_cats = $postarr['post_category']; 709 else 710 $post_cats = $post['post_category']; 711 711 712 712 // Drafts shouldn't be assigned a date unless explicitly done so by the user 713 if ( 'draft' == $post['post_status'] && empty($postarr['edit_date']) && empty($postarr['post_date']) && 714 ('0000-00-00 00:00:00' == $post['post_date']) )713 if ( 'draft' == $post['post_status'] && empty($postarr['edit_date']) && empty($postarr['post_date']) && 714 ('0000-00-00 00:00:00' == $post['post_date']) ) 715 715 $clear_date = true; 716 716 else 717 717 $clear_date = false; 718 718 719 // Merge old and new fields with new fields overwriting old ones.720 $postarr = array_merge($post, $postarr);721 $postarr['post_category'] = $post_cats;719 // Merge old and new fields with new fields overwriting old ones. 720 $postarr = array_merge($post, $postarr); 721 $postarr['post_category'] = $post_cats; 722 722 if ( $clear_date ) { 723 723 $postarr['post_date'] = ''; 724 724 $postarr['post_date_gmt'] = ''; … … 739 739 if ( 'publish' == $post->post_status ) 740 740 return; 741 741 742 return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id)); 742 return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id)); 743 743 } 744 744 745 745 function wp_set_post_categories($post_ID = 0, $post_categories = array()) { … … 752 752 753 753 // First the old categories 754 754 $old_categories = $wpdb->get_col(" 755 SELECT category_id 756 FROM $wpdb->post2cat 755 SELECT category_id 756 FROM $wpdb->post2cat 757 757 WHERE post_id = $post_ID"); 758 758 759 759 if (!$old_categories) { … … 768 768 if ($delete_cats) { 769 769 foreach ($delete_cats as $del) { 770 770 $wpdb->query(" 771 DELETE FROM $wpdb->post2cat 772 WHERE category_id = $del 773 AND post_id = $post_ID 771 DELETE FROM $wpdb->post2cat 772 WHERE category_id = $del 773 AND post_id = $post_ID 774 774 "); 775 775 } 776 776 } … … 781 781 if ($add_cats) { 782 782 foreach ($add_cats as $new_cat) { 783 783 $wpdb->query(" 784 INSERT INTO $wpdb->post2cat (post_id, category_id) 784 INSERT INTO $wpdb->post2cat (post_id, category_id) 785 785 VALUES ($post_ID, $new_cat)"); 786 786 } 787 787 } … … 866 866 867 867 $trackback_urls = explode(',', $tb_list); 868 868 foreach($trackback_urls as $tb_url) { 869 $tb_url = trim($tb_url);870 trackback($tb_url, stripslashes($post_title), $excerpt, $post_id);869 $tb_url = trim($tb_url); 870 trackback($tb_url, stripslashes($post_title), $excerpt, $post_id); 871 871 } 872 }872 } 873 873 } 874 874 875 875 // … … 946 946 947 947 $pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = '$leaf_path' AND post_type='page'"); 948 948 949 if ( empty($pages) ) 949 if ( empty($pages) ) 950 950 return NULL; 951 951 952 952 foreach ($pages as $page) { … … 1026 1026 1027 1027 $inclusions = ''; 1028 1028 if ( !empty($include) ) { 1029 $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include 1030 $exclude = ''; 1029 $child_of = 0; //ignore child_of, exclude, meta_key, and meta_value params if using include 1030 $exclude = ''; 1031 1031 $meta_key = ''; 1032 1032 $meta_value = ''; 1033 1033 $incpages = preg_split('/[\s,]+/',$include); … … 1040 1040 } 1041 1041 } 1042 1042 } 1043 if (!empty($inclusions)) 1044 $inclusions .= ')'; 1043 if (!empty($inclusions)) 1044 $inclusions .= ')'; 1045 1045 1046 1046 $exclusions = ''; 1047 1047 if ( !empty($exclude) ) { … … 1055 1055 } 1056 1056 } 1057 1057 } 1058 if (!empty($exclusions)) 1058 if (!empty($exclusions)) 1059 1059 $exclusions .= ')'; 1060 1060 1061 1061 $query = "SELECT * FROM $wpdb->posts " ; 1062 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 1062 $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 1063 1063 $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ; 1064 1064 $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' )" ) ; 1065 1065 $query .= " ORDER BY " . $sort_column . " " . $sort_order ; … … 1177 1177 1178 1178 if (empty($post_date)) 1179 1179 $post_date = current_time('mysql'); 1180 if (empty($post_date_gmt)) 1180 if (empty($post_date_gmt)) 1181 1181 $post_date_gmt = current_time('mysql', 1); 1182 1182 1183 1183 if ( empty($comment_status) ) { -
wp-includes/query.php
3 3 /* 4 4 * The Big Query. 5 5 */ 6 6 7 7 function get_query_var($var) { 8 8 global $wp_query; 9 9 … … 217 217 /* 218 218 * The Loop. Post loop control. 219 219 */ 220 220 221 221 function have_posts() { 222 222 global $wp_query; 223 223 … … 359 359 } elseif ( $qv['p'] ) { 360 360 $this->is_single = true; 361 361 } elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) { 362 // If year, month, day, hour, minute, and second are set, a single 363 // post is being queried. 362 // If year, month, day, hour, minute, and second are set, a single 363 // post is being queried. 364 364 $this->is_single = true; 365 365 } elseif ('' != $qv['static'] || '' != $qv['pagename'] || '' != $qv['page_id']) { 366 366 $this->is_page = true; … … 436 436 if ('' != $qv['category_name']) { 437 437 $this->is_category = true; 438 438 } 439 439 440 440 if ((empty($qv['author'])) || ($qv['author'] == '0')) { 441 441 $this->is_author = false; 442 442 } else { … … 700 700 701 701 // Category stuff 702 702 703 if ((empty($q['cat'])) || ($q['cat'] == '0') || 703 if ((empty($q['cat'])) || ($q['cat'] == '0') || 704 704 // Bypass cat checks if fetching specific posts 705 705 ( $this->is_single || $this->is_page )) { 706 706 $whichcat=''; … … 717 717 if ( $in ) 718 718 $in_cats .= "$cat, " . get_category_children($cat, '', ', '); 719 719 else 720 $out_cats .= "$cat, " . get_category_children($cat, '', ', '); 720 $out_cats .= "$cat, " . get_category_children($cat, '', ', '); 721 721 } 722 722 $in_cats = substr($in_cats, 0, -2); 723 723 $out_cats = substr($out_cats, 0, -2); … … 762 762 $reqcat = 0; 763 763 764 764 $q['cat'] = $reqcat; 765 765 766 766 $tables = ", $wpdb->post2cat, $wpdb->categories"; 767 767 $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) "; 768 768 $whichcat = " AND category_id IN ({$q['cat']}, "; … … 853 853 854 854 if ( is_admin() ) 855 855 $where .= " OR post_status = 'future' OR post_status = 'draft'"; 856 856 857 857 if ( is_user_logged_in() ) { 858 858 if ( 'post' == $post_type ) 859 859 $cap = 'edit_private_posts'; … … 963 963 } 964 964 965 965 function next_post() { 966 966 967 967 $this->current_post++; 968 968 969 969 $this->post = $this->posts[$this->current_post]; … … 999 999 $this->post = $this->posts[0]; 1000 1000 } 1001 1001 } 1002 1002 1003 1003 function &query($query) { 1004 1004 $this->parse_query($query); 1005 1005 return $this->get_posts(); -
wp-includes/registration.php
85 85 $wpdb->query( $query ); 86 86 $user_id = $ID; 87 87 } else { 88 $query = "INSERT INTO $wpdb->users 88 $query = "INSERT INTO $wpdb->users 89 89 (user_login, user_pass, user_email, user_url, user_registered, user_nicename, display_name) 90 VALUES 90 VALUES 91 91 ('$user_login', '$user_pass', '$user_email', '$user_url', '$user_registered', '$user_nicename', '$display_name')"; 92 92 $query = apply_filters('create_user_query', $query); 93 93 $wpdb->query( $query ); -
wp-includes/rewrite.php
16 16 if (strlen($tagname) < 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%') { 17 17 return; 18 18 } 19 19 20 20 $qv = trim($tagname, '%'); 21 21 22 22 global $wp_rewrite, $wp; 23 23 $wp->add_query_var($qv); 24 24 $wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '='); 25 25 } 26 26 27 //Add a new feed type like /atom1/ 27 //Add a new feed type like /atom1/ 28 28 function add_feed($feedname, $function) { 29 29 global $wp_rewrite; 30 30 if (!in_array($feedname, $wp_rewrite->feeds)) { //override the file if it is … … 169 169 var $non_wp_rules; //rules that don't redirect to WP's index.php 170 170 var $endpoints; 171 171 var $use_verbose_rules = false; 172 var $rewritecode = 172 var $rewritecode = 173 173 array( 174 174 '%year%', 175 175 '%monthnum%', … … 185 185 '%search%' 186 186 ); 187 187 188 var $rewritereplace = 188 var $rewritereplace = 189 189 array( 190 190 '([0-9]{4})', 191 191 '([0-9]{1,2})', … … 201 201 '(.+)' 202 202 ); 203 203 204 var $queryreplace = 204 var $queryreplace = 205 205 array ( 206 206 'year=', 207 207 'monthnum=', … … 218 218 ); 219 219 220 220 var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); 221 221 222 222 function using_permalinks() { 223 223 if (empty($this->permalink_structure)) 224 224 return false; … … 235 235 if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) { 236 236 return true; 237 237 } 238 238 239 239 return false; 240 240 } 241 241 … … 251 251 $match_suffix = ''; 252 252 253 253 if (! empty($this->matches)) { 254 $match_prefix = '$' . $this->matches . '['; 254 $match_prefix = '$' . $this->matches . '['; 255 255 $match_suffix = ']'; 256 } 256 } 257 257 258 return "$match_prefix$number$match_suffix"; 258 return "$match_prefix$number$match_suffix"; 259 259 } 260 260 261 261 function page_rewrite_rules() { … … 301 301 $date_endian= $endian; 302 302 break; 303 303 } 304 } 304 } 305 305 306 306 if ( empty($date_endian) ) 307 307 $date_endian = '%year%/%monthnum%/%day%'; 308 308 309 309 // Do not allow the date tags and %post_id% to overlap in the permalink 310 // structure. If they do, move the date tags to $front/date/. 310 // structure. If they do, move the date tags to $front/date/. 311 311 $front = $this->front; 312 312 preg_match_all('/%.+?%/', $this->permalink_structure, $tokens); 313 313 $tok_index = 1; … … 481 481 //build a regex to match the trackback and page/xx parts of URLs 482 482 $trackbackregex = 'trackback/?$'; 483 483 $pageregex = 'page/?([0-9]{1,})/?$'; 484 484 485 485 //build up an array of endpoint regexes to append => queries to append 486 486 if ($endpoints) { 487 487 $ep_query_append = array (); 488 foreach ($this->endpoints as $endpoint) { 488 foreach ($this->endpoints as $endpoint) { 489 489 //match everything after the endpoint name, but allow for nothing to appear there 490 490 $epmatch = $endpoint[1] . '(/(.*))?/?$'; 491 491 //this will be appended on to the rest of the query for each dir … … 510 510 if (0 < $i) { 511 511 $queries[$i] = $queries[$i - 1] . '&'; 512 512 } 513 513 514 514 $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1); 515 515 $queries[$i] .= $query_token; 516 516 } … … 547 547 $num_toks = preg_match_all('/%.+?%/', $struct, $toks); 548 548 //get the 'tagname=$matches[i]' 549 549 $query = $queries[$num_toks - 1]; 550 550 551 551 //set up $ep_mask_specific which is used to match more specific URL types 552 552 switch ($dirs[$j]) { 553 553 case '%year%': $ep_mask_specific = EP_YEAR; break; … … 579 579 $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2); 580 580 if ($paged) //...and /page/xx ones 581 581 $rewrite = array_merge($rewrite, array($pagematch => $pagequery)); 582 582 583 583 //if we've got some tags in this dir 584 584 if ($num_toks) { 585 585 $post = false; 586 586 $page = false; 587 588 //check to see if this dir is permalink-level: i.e. the structure specifies an 587 588 //check to see if this dir is permalink-level: i.e. the structure specifies an 589 589 //individual post. Do this by checking it contains at least one of 1) post name, 590 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and 590 //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and 591 591 //minute all present). Set these flags now as we need them for the endpoints. 592 592 if (strstr($struct, '%postname%') || strstr($struct, '%post_id%') 593 593 || strstr($struct, '%pagename%') … … 596 596 if ( strstr($struct, '%pagename%') ) 597 597 $page = true; 598 598 } 599 599 600 600 //do endpoints 601 601 if ($endpoints) { 602 602 foreach ($ep_query_append as $regex => $ep) { … … 606 606 } 607 607 } 608 608 } 609 609 610 610 //if we're creating rules for a permalink, do all the endpoints like attachments etc 611 611 if ($post) { 612 612 $post = true; … … 617 617 $match = rtrim($match, '/'); 618 618 //get rid of brackets 619 619 $submatchbase = str_replace(array('(',')'),'',$match); 620 620 621 621 //add a rule for at attachments, which take the form of <permalink>/some-text 622 622 $sub1 = $submatchbase . '/([^/]+)/'; 623 623 $sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/... … … 625 625 $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...) 626 626 //add an ? as we don't have to match that last slash, and finally a $ so we 627 627 //match to the end of the URL 628 628 629 629 //add another rule to match attachments in the explicit form: 630 630 //<permalink>/attachment/some-text 631 631 $sub2 = $submatchbase . '/attachment/([^/]+)/'; 632 632 $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback 633 633 $sub2feed = $sub2 . $feedregex; //feeds, <permalink>/attachment/feed/(atom|...) 634 634 $sub2feed2 = $sub2 . $feedregex2; //and feeds again on to this <permalink>/attachment/(feed|atom...) 635 635 636 636 //create queries for these extra tag-ons we've just dealt with 637 637 $subquery = $index . '?attachment=' . $this->preg_index(1); 638 638 $subtbquery = $subquery . '&tb=1'; 639 639 $subfeedquery = $subquery . '&feed=' . $this->preg_index(2); 640 640 641 641 //do endpoints for attachments 642 642 if ($endpoint) { foreach ($ep_query_append as $regex => $ep) { 643 643 if ($ep[0] & EP_ATTACHMENT) { … … 645 645 $rewrite[$sub2 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2); 646 646 } 647 647 } } 648 648 649 649 //now we've finished with endpoints, finish off the $sub1 and $sub2 matches 650 650 $sub1 .= '?$'; 651 651 $sub2 .= '?$'; 652 652 653 653 //allow URLs like <permalink>/2 for <permalink>/page/2 654 654 $match = $match . '(/[0-9]+)?/?$'; 655 655 $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1); … … 658 658 $match .= '?$'; 659 659 $query = $index . '?' . $query; 660 660 } 661 661 662 662 //create the final array for this dir by joining the $rewrite array (which currently 663 663 //only contains rules/queries for trackback, pages etc) to the main regex/query for 664 664 //this dir … … 668 668 if ($post) { 669 669 //add trackback 670 670 $rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite); 671 671 672 672 //add regexes/queries for attachments, attachment trackbacks and so on 673 673 if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages 674 674 $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery)); … … 762 762 763 763 $home_root = parse_url(get_settings('home')); 764 764 $home_root = trailingslashit($home_root['path']); 765 765 766 766 $rules = "<IfModule mod_rewrite.c>\n"; 767 767 $rules .= "RewriteEngine On\n"; 768 768 $rules .= "RewriteBase $home_root\n"; 769 769 770 770 //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all) 771 771 foreach ($this->non_wp_rules as $match => $query) { 772 772 // Apache 1.3 does not support the reluctant (non-greedy) modifier. … … 818 818 819 819 return $rules; 820 820 } 821 821 822 822 //Add a straight rewrite rule 823 823 function add_rule($regex, $redirect) { 824 824 //get everything up to the first ? … … 830 830 $this->extra_rules[$regex] = $redirect; 831 831 } 832 832 } 833 833 834 834 //add a rule that doesn't redirect to index.php 835 835 function add_external_rule($regex, $redirect) { 836 836 $this->non_wp_rules[$regex] = $redirect; 837 837 } 838 838 839 839 //add an endpoint, like /trackback/, to be inserted after certain URL types (specified in $places) 840 840 function add_endpoint($name, $places) { 841 841 global $wp; -
wp-includes/rss.php
11 11 define('ATOM', 'Atom'); 12 12 define('MAGPIE_USER_AGENT', 'WordPress/' . $wp_version); 13 13 14 class MagpieRSS { 14 class MagpieRSS { 15 15 var $parser; 16 16 var $current_item = array(); // item currently being parsed 17 17 var $items = array(); // collection of parsed items … … 25 25 var $stack = array(); // parser stack 26 26 var $inchannel = false; 27 27 var $initem = false; 28 var $incontent = false; // if in Atom <content mode="xml"> field 28 var $incontent = false; // if in Atom <content mode="xml"> field 29 29 var $intextinput = false; 30 30 var $inimage = false; 31 31 var $current_field = ''; … … 54 54 # setup handlers 55 55 # 56 56 xml_set_object( $this->parser, $this ); 57 xml_set_element_handler($this->parser, 57 xml_set_element_handler($this->parser, 58 58 'feed_start_element', 'feed_end_element' ); 59 59 60 xml_set_character_data_handler( $this->parser, 'feed_cdata' ); 60 xml_set_character_data_handler( $this->parser, 'feed_cdata' ); 61 61 62 62 $status = xml_parse( $this->parser, $source ); 63 63 … … 85 85 // check for a namespace, and split if found 86 86 $ns = false; 87 87 if ( strpos( $element, ':' ) ) { 88 list($ns, $el) = split( ':', $element, 2); 88 list($ns, $el) = split( ':', $element, 2); 89 89 } 90 90 if ( $ns and $ns != 'rdf' ) { 91 91 $this->current_namespace = $ns; … … 111 111 return; 112 112 } 113 113 114 if ( $el == 'channel' ) 114 if ( $el == 'channel' ) 115 115 { 116 116 $this->inchannel = true; 117 117 } 118 elseif ($el == 'item' or $el == 'entry' ) 118 elseif ($el == 'item' or $el == 'entry' ) 119 119 { 120 120 $this->initem = true; 121 121 if ( isset($attrs['rdf:about']) ) { … … 125 125 126 126 // if we're in the default namespace of an RSS feed, 127 127 // record textinput or image fields 128 elseif ( 129 $this->feed_type == RSS and 130 $this->current_namespace == '' and 131 $el == 'textinput' ) 128 elseif ( 129 $this->feed_type == RSS and 130 $this->current_namespace == '' and 131 $el == 'textinput' ) 132 132 { 133 133 $this->intextinput = true; 134 134 } 135 135 136 136 elseif ( 137 $this->feed_type == RSS and 138 $this->current_namespace == '' and 139 $el == 'image' ) 137 $this->feed_type == RSS and 138 $this->current_namespace == '' and 139 $el == 'image' ) 140 140 { 141 141 $this->inimage = true; 142 142 } … … 155 155 } 156 156 157 157 // if inside an Atom content construct (e.g. content or summary) field treat tags as text 158 elseif ($this->feed_type == ATOM and $this->incontent ) 158 elseif ($this->feed_type == ATOM and $this->incontent ) 159 159 { 160 160 // if tags are inlined, then flatten 161 $attrs_str = join(' ', 162 array_map('map_attrs', 163 array_keys($attrs), 161 $attrs_str = join(' ', 162 array_map('map_attrs', 163 array_keys($attrs), 164 164 array_values($attrs) ) ); 165 165 166 166 $this->append_content( "<$element $attrs_str>" ); … … 172 172 // Magpie treats link elements of type rel='alternate' 173 173 // as being equivalent to RSS's simple link element. 174 174 // 175 elseif ($this->feed_type == ATOM and $el == 'link' ) 175 elseif ($this->feed_type == ATOM and $el == 'link' ) 176 176 { 177 if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) 177 if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) 178 178 { 179 179 $link_el = 'link'; 180 180 } … … 194 194 195 195 function feed_cdata ($p, $text) { 196 196 197 if ($this->feed_type == ATOM and $this->incontent) 197 if ($this->feed_type == ATOM and $this->incontent) 198 198 { 199 199 $this->append_content( $text ); 200 200 } … … 207 207 function feed_end_element ($p, $el) { 208 208 $el = strtolower($el); 209 209 210 if ( $el == 'item' or $el == 'entry' ) 210 if ( $el == 'item' or $el == 'entry' ) 211 211 { 212 212 $this->items[] = $this->current_item; 213 213 $this->current_item = array(); 214 214 $this->initem = false; 215 215 } 216 elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) 216 elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) 217 217 { 218 218 $this->intextinput = false; 219 219 } 220 elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) 220 elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) 221 221 { 222 222 $this->inimage = false; 223 223 } … … 225 225 { 226 226 $this->incontent = false; 227 227 } 228 elseif ($el == 'channel' or $el == 'feed' ) 228 elseif ($el == 'channel' or $el == 'feed' ) 229 229 { 230 230 $this->inchannel = false; 231 231 } 232 232 elseif ($this->feed_type == ATOM and $this->incontent ) { 233 233 // balance tags properly 234 234 // note: i don't think this is actually neccessary 235 if ( $this->stack[0] == $el ) 235 if ( $this->stack[0] == $el ) 236 236 { 237 237 $this->append_content("</$el>"); 238 238 } … … 270 270 if (!$el) { 271 271 return; 272 272 } 273 if ( $this->current_namespace ) 273 if ( $this->current_namespace ) 274 274 { 275 275 if ( $this->initem ) { 276 276 $this->concat( … … 395 395 // error("Failed to fetch $url and cache is off"); 396 396 return false; 397 397 } 398 } 398 } 399 399 // else cache is ON 400 400 else { 401 401 // Flow … … 472 472 if ( $resp->error ) { 473 473 # compensate for Snoopy's annoying habbit to tacking 474 474 # on '\n' 475 $http_error = substr($resp->error, 0, -2); 475 $http_error = substr($resp->error, 0, -2); 476 476 $errormsg .= "(HTTP Error: $http_error)"; 477 477 } 478 478 else { … … 613 613 } 614 614 } 615 615 616 function is_info ($sc) { 617 return $sc >= 100 && $sc < 200; 616 function is_info ($sc) { 617 return $sc >= 100 && $sc < 200; 618 618 } 619 619 620 function is_success ($sc) { 621 return $sc >= 200 && $sc < 300; 620 function is_success ($sc) { 621 return $sc >= 200 && $sc < 300; 622 622 } 623 623 624 function is_redirect ($sc) { 625 return $sc >= 300 && $sc < 400; 624 function is_redirect ($sc) { 625 return $sc >= 300 && $sc < 400; 626 626 } 627 627 628 function is_error ($sc) { 629 return $sc >= 400 && $sc < 600; 628 function is_error ($sc) { 629 return $sc >= 400 && $sc < 600; 630 630 } 631 631 632 function is_client_error ($sc) { 633 return $sc >= 400 && $sc < 500; 632 function is_client_error ($sc) { 633 return $sc >= 400 && $sc < 500; 634 634 } 635 635 636 function is_server_error ($sc) { 637 return $sc >= 500 && $sc < 600; 636 function is_server_error ($sc) { 637 return $sc >= 500 && $sc < 600; 638 638 } 639 639 640 640 class RSSCache { … … 685 685 $cache_option = 'rss_' . $this->file_name( $url ); 686 686 687 687 if ( ! get_option( $cache_option ) ) { 688 $this->debug( 688 $this->debug( 689 689 "Cache doesn't contain: $url (cache option: $cache_option)" 690 690 ); 691 691 return 0; … … 757 757 \*=======================================================================*/ 758 758 function error ($errormsg, $lvl=E_USER_WARNING) { 759 759 // append PHP's error message if track_errors enabled 760 if ( isset($php_errormsg) ) { 760 if ( isset($php_errormsg) ) { 761 761 $errormsg .= " ($php_errormsg)"; 762 762 } 763 763 $this->ERROR = $errormsg; … … 781 781 $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; 782 782 783 783 if ( preg_match( $pat, $date_str, $match ) ) { 784 list( $year, $month, $day, $hours, $minutes, $seconds) = 784 list( $year, $month, $day, $hours, $minutes, $seconds) = 785 785 array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); 786 786 787 787 # calc epoch for current date assuming GMT -
wp-includes/script-loader.php
69 69 } 70 70 } 71 71 } 72 73 72 73 74 74 /** 75 75 * Determines dependencies of scripts 76 76 * … … 155 155 endswitch; 156 156 return false; 157 157 } 158 158 159 159 } 160 160 161 161 class _WP_Script { -
wp-includes/streams.php
1 1 <?php 2 2 /* 3 Copyright (c) 2003, 2005 Danilo Segan <danilo@kvota.net>.3 Copyright (c) 2003, 2005 Danilo Segan <danilo@kvota.net>. 4 4 5 This file is part of PHP-gettext.5 This file is part of PHP-gettext. 6 6 7 PHP-gettext is free software; you can redistribute it and/or modify8 it under the terms of the GNU General Public License as published by9 the Free Software Foundation; either version 2 of the License, or10 (at your option) any later version.7 PHP-gettext is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 11 12 PHP-gettext is distributed in the hope that it will be useful,13 but WITHOUT ANY WARRANTY; without even the implied warranty of14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 GNU General Public License for more details.12 PHP-gettext is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 16 17 You should have received a copy of the GNU General Public License18 along with PHP-gettext; if not, write to the Free Software19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17 You should have received a copy of the GNU General Public License 18 along with PHP-gettext; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 20 21 21 */ 22 22 … … 24 24 // Simple class to wrap file streams, string streams, etc. 25 25 // seek is essential, and it should be byte stream 26 26 class StreamReader { 27 // should return a string [FIXME: perhaps return array of bytes?]28 function read($bytes) {29 return false;30 }31 32 // should return new position33 function seekto($position) {34 return false;35 }36 37 // returns current position38 function currentpos() {39 return false;40 }41 42 // returns length of entire stream (limit for seekto()s)43 function length() {44 return false;45 }27 // should return a string [FIXME: perhaps return array of bytes?] 28 function read($bytes) { 29 return false; 30 } 31 32 // should return new position 33 function seekto($position) { 34 return false; 35 } 36 37 // returns current position 38 function currentpos() { 39 return false; 40 } 41 42 // returns length of entire stream (limit for seekto()s) 43 function length() { 44 return false; 45 } 46 46 } 47 47 48 48 class StringReader { 49 var $_pos;50 var $_str;49 var $_pos; 50 var $_str; 51 51 52 function StringReader($str='') {53 $this->_str = $str;54 $this->_pos = 0;55 }52 function StringReader($str='') { 53 $this->_str = $str; 54 $this->_pos = 0; 55 } 56 56 57 function read($bytes) {58 $data = substr($this->_str, $this->_pos, $bytes);59 $this->_pos += $bytes;60 if (strlen($this->_str)<$this->_pos)61 $this->_pos = strlen($this->_str);57 function read($bytes) { 58 $data = substr($this->_str, $this->_pos, $bytes); 59 $this->_pos += $bytes; 60 if (strlen($this->_str)<$this->_pos) 61 $this->_pos = strlen($this->_str); 62 62 63 return $data;64 }63 return $data; 64 } 65 65 66 function seekto($pos) {67 $this->_pos = $pos;68 if (strlen($this->_str)<$this->_pos)69 $this->_pos = strlen($this->_str);70 return $this->_pos;71 }66 function seekto($pos) { 67 $this->_pos = $pos; 68 if (strlen($this->_str)<$this->_pos) 69 $this->_pos = strlen($this->_str); 70 return $this->_pos; 71 } 72 72 73 function currentpos() {74 return $this->_pos;75 }73 function currentpos() { 74 return $this->_pos; 75 } 76 76 77 function length() {78 return strlen($this->_str);79 }77 function length() { 78 return strlen($this->_str); 79 } 80 80 81 81 } 82 82 83 83 84 84 class FileReader { 85 var $_pos;86 var $_fd;87 var $_length;85 var $_pos; 86 var $_fd; 87 var $_length; 88 88 89 function FileReader($filename) {90 if (file_exists($filename)) {89 function FileReader($filename) { 90 if (file_exists($filename)) { 91 91 92 $this->_length=filesize($filename);93 $this->_pos = 0;94 $this->_fd = fopen($filename,'rb');95 if (!$this->_fd) {92 $this->_length=filesize($filename); 93 $this->_pos = 0; 94 $this->_fd = fopen($filename,'rb'); 95 if (!$this->_fd) { 96 96 $this->error = 3; // Cannot read file, probably permissions 97 97 return false; 98 }99 } else {100 $this->error = 2; // File doesn't exist101 return false;102 }103 }98 } 99 } else { 100 $this->error = 2; // File doesn't exist 101 return false; 102 } 103 } 104 104 105 function read($bytes) { 106 if ($bytes) { 107 fseek($this->_fd, $this->_pos); 108 $data = fread($this->_fd, $bytes); 109 $this->_pos = ftell($this->_fd); 110 111 return $data; 112 } else return ''; 113 } 105 function read($bytes) { 106 if ($bytes) { 107 fseek($this->_fd, $this->_pos); 108 $data = fread($this->_fd, $bytes); 109 $this->_pos = ftell($this->_fd); 114 110 115 function seekto($pos) { 116 fseek($this->_fd, $pos); 117 $this->_pos = ftell($this->_fd); 118 return $this->_pos; 119 } 111 return $data; 112 } else return ''; 113 } 120 114 121 function currentpos() { 122 return $this->_pos; 123 } 115 function seekto($pos) { 116 fseek($this->_fd, $pos); 117 $this->_pos = ftell($this->_fd); 118 return $this->_pos; 119 } 124 120 125 function length() {126 return $this->_length;127 }121 function currentpos() { 122 return $this->_pos; 123 } 128 124 129 function close() {130 fclose($this->_fd);131 }125 function length() { 126 return $this->_length; 127 } 132 128 129 function close() { 130 fclose($this->_fd); 131 } 132 133 133 } 134 134 135 // Preloads entire file in memory first, then creates a StringReader 135 // Preloads entire file in memory first, then creates a StringReader 136 136 // over it (it assumes knowledge of StringReader internals) 137 137 class CachedFileReader extends StringReader { 138 function CachedFileReader($filename) {139 if (file_exists($filename)) {138 function CachedFileReader($filename) { 139 if (file_exists($filename)) { 140 140 141 $length=filesize($filename);142 $fd = fopen($filename,'rb');141 $length=filesize($filename); 142 $fd = fopen($filename,'rb'); 143 143 144 if (!$fd) {144 if (!$fd) { 145 145 $this->error = 3; // Cannot read file, probably permissions 146 146 return false; 147 }148 $this->_str = fread($fd, $length);149 fclose($fd);147 } 148 $this->_str = fread($fd, $length); 149 fclose($fd); 150 150 151 } else {152 $this->error = 2; // File doesn't exist153 return false;154 }155 }151 } else { 152 $this->error = 2; // File doesn't exist 153 return false; 154 } 155 } 156 156 } 157 157 158 158 -
wp-includes/theme.php
1 1 <?php 2 2 /* 3 * Theme/template/stylesheet functions. 3 * Theme/template/stylesheet functions. 4 4 */ 5 5 6 6 function get_stylesheet() { -
wp-includes/user.php
150 150 151 151 if ( '' == $user_id ) 152 152 $user = wp_get_current_user(); 153 else 153 else 154 154 $user = new WP_User($user_id); 155 155 156 156 if ( 0 == $user->ID ) -
wp-includes/vars.php
34 34 $is_apache = ( strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') || strstr($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') ) ? 1 : 0; 35 35 $is_IIS = strstr($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') ? 1 : 0; 36 36 37 // On OS X Server, $_SERVER['REMOTE_ADDR'] is the server's address. Workaround this 37 // On OS X Server, $_SERVER['REMOTE_ADDR'] is the server's address. Workaround this 38 38 // by using $_SERVER['HTTP_PC_REMOTE_ADDR'], which *is* the remote address. 39 39 if ( isset($_SERVER['HTTP_PC_REMOTE_ADDR']) ) 40 40 $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_PC_REMOTE_ADDR']; -
wp-includes/wp-db.php
90 90 function print_error($str = '') { 91 91 global $EZSQL_ERROR; 92 92 if (!$str) $str = mysql_error(); 93 $EZSQL_ERROR[] = 93 $EZSQL_ERROR[] = 94 94 array ('query' => $this->last_query, 'error_str' => $str); 95 95 96 96 // Is error output turned on or not..
