Ticket #986: 986-includes.diff

File 986-includes.diff, 210.5 KB (added by Nazgul, 6 years ago)
  • wp-includes/bookmark-template.php

     
    7777                $order = 'DESC'; 
    7878                $orderby = substr($orderby, 1); 
    7979        } 
    80          
     80 
    8181        if ($category == -1) {  //get_bookmarks uses '' to signify all categories 
    8282                $category = ''; 
    8383        } 
     
    159159} 
    160160 
    161161function get_linkrating($link) { 
    162     return apply_filters('link_rating', $link->link_rating); 
     162        return apply_filters('link_rating', $link->link_rating); 
    163163} 
    164164 
    165165/** function get_linkcatname() 
     
    170170function get_linkcatname($id = 0) { 
    171171        $id = (int) $id; 
    172172 
    173     if ( empty($id) ) 
    174         return ''; 
    175    
     173        if ( empty($id) ) 
     174                return ''; 
     175 
    176176        $cats = wp_get_link_cats($id); 
    177177 
    178178        if ( empty($cats) || ! is_array($cats) ) 
     
    195195 **   count (default true) - the number of links in the db 
    196196 */ 
    197197function 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        } 
    202202 
    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; 
    208208 
    209    if ($count == true) { 
    210       $javascript .= " ($counts)"; 
    211    } 
     209        if ($count == true) { 
     210                $javascript .= " ($counts)"; 
     211        } 
    212212 
    213    $javascript .="</a>\n\n"; 
    214    echo $javascript; 
     213        $javascript .="</a>\n\n"; 
     214        echo $javascript; 
    215215} 
    216216 
    217217 
     
    345345                'category_orderby' => 'name', 'category_order' => 'ASC'); 
    346346        $r = array_merge($defaults, $r); 
    347347        extract($r); 
    348          
     348 
    349349        // TODO: The rest of it. 
    350350        // 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. 
    352352        // If $categorize and $category or $category_name, list links for the given category 
    353353        // with the category name as the title li.  If not $categorize, use title_li. 
    354354        // When using each category's name as a title li, use before and after args for specifying 
  • wp-includes/bookmark.php

     
    1919 
    2020// Deprecate 
    2121function get_link($bookmark_id, $output = OBJECT) { 
    22         return get_bookmark($bookmark_id, $output);      
     22        return get_bookmark($bookmark_id, $output); 
    2323} 
    2424 
    2525function get_bookmarks($args = '') { 
     
    5050                        } 
    5151                } 
    5252        } 
    53         if (!empty($inclusions))  
     53        if (!empty($inclusions)) 
    5454                $inclusions .= ')'; 
    5555 
    5656        $exclusions = ''; 
     
    6565                        } 
    6666                } 
    6767        } 
    68         if (!empty($exclusions))  
     68        if (!empty($exclusions)) 
    6969                $exclusions .= ')'; 
    70                  
     70 
    7171        if ( ! empty($category_name) ) { 
    7272                if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") ) 
    7373                        $category = $cat_id; 
     
    8787                } 
    8888        } 
    8989        if (!empty($category_query)) { 
    90                 $category_query .= ')';  
     90                $category_query .= ')'; 
    9191                $join = " LEFT JOIN $wpdb->link2cat ON ($wpdb->links.link_id = $wpdb->link2cat.link_id) "; 
    9292        } 
    9393 
  • wp-includes/cache.php

     
    6767        var $secret = ''; 
    6868 
    6969        function acquire_lock() { 
    70                 // Acquire a write lock.  
     70                // Acquire a write lock. 
    7171                $this->mutex = @fopen($this->cache_dir.$this->flock_filename, 'w'); 
    7272                if ( false == $this->mutex) 
    7373                        return false; 
     
    239239                while ($index < count($stack)) { 
    240240                        # Get indexed directory from stack 
    241241                        $dir = $stack[$index]; 
    242        
     242 
    243243                        $dh = @ opendir($dir); 
    244244                        if (!$dh) 
    245245                                return false; 
    246        
     246 
    247247                        while (($file = @ readdir($dh)) !== false) { 
    248248                                if ($file == '.' or $file == '..') 
    249249                                        continue; 
  • wp-includes/capabilities.php

     
    211211        } 
    212212 
    213213        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                } 
    220220        } 
    221221 
    222222        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); 
    226226        } 
    227227 
    228228        function add_cap($cap, $grant = true) { 
     
    288288                $post = get_post($args[0]); 
    289289                if ( 'page' == $post->post_type ) { 
    290290                        $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); 
    292292                } 
    293293                $post_author_data = get_userdata($post->post_author); 
    294294                //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br/>"; 
     
    342342                $post = get_post($args[0]); 
    343343                if ( 'page' == $post->post_type ) { 
    344344                        $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); 
    346346                } 
    347347                $post_author_data = get_userdata($post->post_author); 
    348348                //echo "current user id : $user_id, post author id: " . $post_author_data->ID . "<br/>"; 
     
    392392                $post = get_post($args[0]); 
    393393                if ( 'page' == $post->post_type ) { 
    394394                        $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); 
    396396                } 
    397397 
    398398                if ( 'private' != $post->post_status ) { 
  • wp-includes/category-template.php

     
    184184                        $output .= "\t<option value='0'>$show_option_all</option>\n"; 
    185185                } 
    186186 
    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); 
    189189                        $output .= "\t<option value='-1'>$show_option_none</option>\n"; 
    190190                } 
    191191 
     
    222222        extract($r); 
    223223 
    224224        $categories = get_categories($r); 
    225          
     225 
    226226        $output = ''; 
    227227        if ( $title_li && 'list' == $style ) 
    228228                        $output = '<li class="categories">' . $r['title_li'] . '<ul>'; 
     
    245245 
    246246        if ( $title_li && 'list' == $style ) 
    247247                $output .= '</ul></li>'; 
    248                          
     248 
    249249        echo apply_filters('list_cats', $output); 
    250250} 
    251251 
  • wp-includes/category.php

     
    2828        $where = 'cat_ID > 0'; 
    2929        $inclusions = ''; 
    3030        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 = ''; 
    3333                $incategories = preg_split('/[\s,]+/',$include); 
    3434                if ( count($incategories) ) { 
    3535                        foreach ( $incategories as $incat ) { 
     
    4040                        } 
    4141                } 
    4242        } 
    43         if (!empty($inclusions))  
    44                 $inclusions .= ')';      
     43        if (!empty($inclusions)) 
     44                $inclusions .= ')'; 
    4545        $where .= $inclusions; 
    4646 
    4747        $exclusions = ''; 
     
    5757                        } 
    5858                } 
    5959        } 
    60         if (!empty($exclusions))  
     60        if (!empty($exclusions)) 
    6161                $exclusions .= ')'; 
    6262        $exclusions = apply_filters('list_cats_exclusions', $exclusions ); 
    6363        $where .= $exclusions; 
     
    8585                function stamp_cat($cat) { 
    8686                        global $cat_stamps; 
    8787                        $cat->last_update_timestamp = $cat_stamps[$cat->cat_ID]; 
    88                         return $cat;     
     88                        return $cat; 
    8989                } 
    9090                $categories = array_map('stamp_cat', $categories); 
    9191                unset($cat_stamps); 
     
    139139 
    140140        $categories = $wpdb->get_results("SELECT cat_ID, category_nicename, category_parent FROM $wpdb->categories WHERE category_nicename = '$leaf_path'"); 
    141141 
    142         if ( empty($categories) )  
     142        if ( empty($categories) ) 
    143143                return NULL; 
    144144 
    145145        foreach ($categories as $category) { 
  • wp-includes/class-IXR.php

     
    11<?php 
    2 /*  
    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 
     2/* 
     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 
    88*/ 
    99 
    1010class 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) { 
    9089                                        $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        } 
    115114} 
    116115 
    117116 
    118117class IXR_Message { 
    119     var $message; 
    120     var $messageType;  // methodCall / methodResponse / fault 
    121     var $faultCode; 
    122     var $faultString; 
    123     var $methodName; 
    124     var $params; 
    125     // Current variable stacks 
    126     var $_arraystructs = array();   // The stack used to keep track of the current array/struct 
    127     var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array 
    128     var $_currentStructName = array();  // A stack as well 
    129     var $_param; 
    130     var $_value; 
    131     var $_currentTag; 
    132     var $_currentTagContents; 
    133     // The XML parser 
    134     var $_parser; 
    135     function IXR_Message ($message) { 
    136         $this->message = $message; 
    137     } 
    138     function parse() { 
    139         // first remove the XML declaration 
    140         $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 account 
    146         xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); 
    147         // Set XML parser callback functions 
    148         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 any 
    159         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) { 
    166165                $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 array 
    176                 $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 array 
    244                 if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { 
    245                     // Add to struct 
    246                     $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; 
    247                 } else { 
    248                     // Add to array 
    249                     $this->_arraystructs[count($this->_arraystructs)-1][] = $value; 
    250                 } 
    251             } else { 
    252                 // Just add as a paramater 
    253                 $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                } 
    256255                $this->_currentTagContents = ''; 
    257     }        
     256        } 
    258257} 
    259258 
    260259 
    261260class 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 result 
    295         $r = new IXR_Value($result); 
    296         $resultxml = $r->getXml(); 
    297         // Create the XML 
    298         $xml = <<<EOD 
     261        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 
    299298<methodResponse> 
    300   <params> 
    301     <param> 
    302       <value> 
    303         $resultxml 
    304       </value> 
    305     </param> 
    306   </params> 
     299        <params> 
     300                <param> 
     301                        <value> 
     302                                $resultxml 
     303                        </value> 
     304                </param> 
     305        </params> 
    307306</methodResponse> 
    308307 
    309308EOD; 
    310         // Send it 
    311         $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 response 
    319         if (count($args) == 1) { 
    320             // If only one paramater just send that instead of the whole array 
    321             $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 exists 
    326             $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 method 
    331             $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 function 
    342             $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        } 
    346345 
    347     function error($error, $message = false) { 
    348         // Accepts either an error object or an error code and message 
    349         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 array 
    369         $this->capabilities = array( 
    370             'xmlrpc' => array( 
    371                 'specUrl' => 'http://www.xmlrpc.com/spec', 
    372                 'specVersion' => 1 
    373             ), 
    374             'faults_interop' => array( 
    375                 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', 
    376                 'specVersion' => 20010516 
    377             ), 
    378             'system.multicall' => array( 
    379                 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', 
    380                 'specVersion' => 1 
    381             ), 
    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 defined 
    394         // methods are listed before server defined methods 
    395         return array_reverse(array_keys($this->callbacks)); 
    396     } 
    397     function multiCall($methodcalls) { 
    398         // See http://www.xmlrpc.com/discuss/msgReader$1208 
    399         $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->message 
    412                 ); 
    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        } 
    419418} 
    420419 
    421420class 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 = <<<EOD 
     421        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 
    429428<?xml version="1.0"?> 
    430429<methodCall> 
    431430<methodName>{$this->method}</methodName> 
    432431<params> 
    433432 
    434433EOD; 
    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        } 
    449448} 
    450449 
    451450 
    452451class 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; 
    460459        var $timeout; 
    461     // Storage place for an error message 
    462     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 instead 
    466             $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 path 
    471             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'; 
    480479                $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 request 
    496         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 back 
    533         $this->message = new IXR_Message($contents); 
    534         if (!$this->message->parse()) { 
    535             // XML error 
    536             $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 OK 
    545         return true; 
    546     } 
    547     function getResponse() { 
    548         // methodResponses can only have one param - return that 
    549         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        } 
    560559} 
    561560 
    562561 
    563562class 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 = <<<EOD 
     563        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 
    572571<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> 
    588587 
    589588EOD; 
    590         return $xml; 
    591     } 
     589                return $xml; 
     590        } 
    592591} 
    593592 
    594593 
    595594class 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 one 
    604         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        } 
    636635} 
    637636 
    638637 
    639638class 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        } 
    647646} 
    648647 
    649648 
    650649class 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' => 1 
    659         ); 
    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 array 
    692         if ($args && !is_array($args)) { 
    693             $args = array($args); 
    694         } 
    695         // Over-rides default call method, adds signature check 
    696         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 arguments 
    703         if (count($args) != count($signature)) { 
    704             return new IXR_Error(-32602, 'server error. wrong number of method parameters'); 
    705         } 
    706         // Check the argument types 
    707         $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 call 
    748         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 types 
    755         $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        } 
    791790} 
    792791 
    793792 
    794793class 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' => $args 
    806         ); 
    807         $this->calls[] = $struct; 
    808     } 
    809     function query() { 
    810         // Prepare multicall, then call the parent::query() method 
    811         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        } 
    813812} 
    814813 
    815814?> 
     815 No newline at end of file 
  • wp-includes/class-pop3.php

     
    1 <?php  
     1<?php 
    22 
    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     */ 
     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                */ 
    1818 
    1919class POP3 { 
    20     var $ERROR      = '';       //  Error string. 
     20                var $ERROR      = '';       //  Error string. 
    2121 
    22     var $TIMEOUT    = 60;       //  Default timeout before giving up on a 
    23                                 //  network operation. 
     22                var $TIMEOUT    = 60;       //  Default timeout before giving up on a 
     23                                                                                                                                //  network operation. 
    2424 
    25     var $COUNT      = -1;       //  Mailbox msg count 
     25                var $COUNT      = -1;       //  Mailbox msg count 
    2626 
    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. 
     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. 
    3030 
    31     var $FP         = '';       //  The connection to the server's 
    32                                 //  file descriptor 
     31                var $FP         = '';       //  The connection to the server's 
     32                                                                                                                                //  file descriptor 
    3333 
    34     var $MAILSERVER = '';       // Set this to hard code the server name 
     34                var $MAILSERVER = '';       // Set this to hard code the server name 
    3535 
    36     var $DEBUG      = FALSE;    // set to true to echo pop3 
    37                                 // commands and responses to error_log 
    38                                 // 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! 
    3939 
    40     var $BANNER     = '';       //  Holds the banner returned by the 
    41                                 //  pop server - used for apop() 
     40                var $BANNER     = '';       //  Holds the banner returned by the 
     41                                                                                                                                //  pop server - used for apop() 
    4242 
    43     var $RFC1939    = TRUE;     //  Set by noop(). See rfc1939.txt 
    44                                 // 
     43                var $RFC1939    = TRUE;     //  Set by noop(). See rfc1939.txt 
     44                                                                                                                                // 
    4545 
    46     var $ALLOWAPOP  = FALSE;    //  Allow or disallow apop() 
    47                                 //  This must be set to true 
    48                                 //  manually 
     46                var $ALLOWAPOP  = FALSE;    //  Allow or disallow apop() 
     47                                                                                                                                //  This must be set to true 
     48                                                                                                                                //  manually 
    4949 
    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     } 
     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                } 
    6666 
    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                } 
    7171 
    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 fail 
     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 fail 
    7575 
    76         // If MAILSERVER is set, override $server with it's value 
     76                                // If MAILSERVER is set, override $server with it's value 
    7777 
    78         if(!empty($this->MAILSERVER)) 
    79             $server = $this->MAILSERVER; 
     78                                if(!empty($this->MAILSERVER)) 
     79                                                $server = $this->MAILSERVER; 
    8080 
    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                                } 
    8686 
    87         $fp = fsockopen("$server", $port, $errno, $errstr); 
     87                                $fp = fsockopen("$server", $port, $errno, $errstr); 
    8888 
    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                                } 
    9494 
    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     } 
     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                } 
    116116 
    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 () { 
    128118 
    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                } 
    131128 
    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 
    147131 
    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                } 
    151147 
    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 
    178151 
    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                } 
    184178 
    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) 
    228184 
    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                } 
    233228 
    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.) 
    252233 
    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                } 
    258252 
    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. 
    264258 
    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(); 
    279264 
    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                                } 
    282279 
    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(); 
    291282 
    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                                } 
    294291 
    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                } 
    299294 
    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 
    316299 
    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                                } 
    318316 
    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(); 
    369318 
    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                } 
    373369 
    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. 
    379373 
    380         $this->update_timer(); 
     374                                if(!isset($this->FP)) 
     375                                { 
     376                                                $this->ERROR = _("POP3 get:") . ' ' . _("No connection to server"); 
     377                                                return false; 
     378                                } 
    381379 
    382         $fp = $this->FP; 
    383         $buffer = $this->BUFFER; 
    384         $cmd = "RETR $msgNum"; 
    385         $reply = $this->send_cmd($cmd); 
     380                                $this->update_timer(); 
    386381 
    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); 
    392386 
    393         $count = 0; 
    394         $MsgArray = array(); 
     387                                if(!$this->is_ok($reply)) 
     388                                { 
     389                                                $this->ERROR = _("POP3 get:") . ' ' . _("Error ") . "[$reply]"; 
     390                                                return false; 
     391                                } 
    395392 
    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(); 
    406395 
    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                } 
    411406 
    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) 
    418411 
    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                                } 
    425418 
    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                                } 
    437425 
    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                } 
    442437 
    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. 
    454442 
    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. 
    461454 
    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                } 
    469461 
    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. 
    473469 
    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. 
    476473 
    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. 
    482476 
    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                                } 
    488482 
    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                                } 
    498488 
    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                } 
    502498 
    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. 
    518502 
    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                } 
    522518 
    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. 
    524522 
    525         if($PopArray == -1) { return false; } 
     523                                $PopArray = $this->last("array"); 
    526524 
    527         if( (!$PopArray) or (empty($PopArray)) ) 
    528         { 
    529             return false; 
    530         } 
    531         return $PopArray; 
    532     } 
     525                                if($PopArray == -1) { return false; } 
    533526 
    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                } 
    540533 
    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 
    545540 
    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                                } 
    548545 
    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; 
    561548 
    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(); 
    565561 
    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; 
    580565 
    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                                                } 
    603580 
    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                } 
    607603 
    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. 
    626607 
    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                } 
    628626 
    629     //  The following methods are internal to the class. 
     627                //  ********************************************************* 
    630628 
    631     function is_ok ($cmd = "") { 
    632         //  Return true or false on +OK or -ERR 
     629                //  The following methods are internal to the class. 
    633630 
    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 
    639633 
    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                } 
    642639 
    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 
    651642 
    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                } 
    677651 
     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 
    678678}   // End class 
    679679 
    680680?> 
  • wp-includes/class-snoopy.php

     
    206206                                if(!$this->curl_path) 
    207207                                        return false; 
    208208                                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; 
    211211                                $this->host = $URI_PARTS["host"]; 
    212212                                if(!empty($URI_PARTS["port"])) 
    213213                                        $this->port = $URI_PARTS["port"]; 
     
    365365                                if(!$this->curl_path) 
    366366                                        return false; 
    367367                                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; 
    370370                                $this->host = $URI_PARTS["host"]; 
    371371                                if(!empty($URI_PARTS["port"])) 
    372372                                        $this->port = $URI_PARTS["port"]; 
     
    816816                                $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; 
    817817                                } 
    818818                                $headers .= substr($cookie_headers,0,-2) . "\r\n"; 
    819                         }  
     819                        } 
    820820                } 
    821821                if(!empty($this->rawheaders)) 
    822822                { 
     
    886886 
    887887                        if(preg_match("|^HTTP/|",$currentHeader)) 
    888888                        { 
    889                 if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) 
     889                                                                if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) 
    890890                                { 
    891891                                        $this->status= $status[1]; 
    892                 } 
     892                                                                } 
    893893                                $this->response_code = $currentHeader; 
    894894                        } 
    895895 
     
    898898 
    899899                $results = ''; 
    900900                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; 
    906906                } while(true); 
    907907 
    908908                if ($this->read_timeout > 0 && $this->_check_timeout($fp)) 
  • wp-includes/classes.php

     
    8484        var $matched_rule; 
    8585        var $matched_query; 
    8686        var $did_permalink = false; 
    87          
     87 
    8888        function add_query_var($qv) { 
    8989                $this->public_query_vars[] = $qv; 
    9090        } 
     
    160160                                        preg_match("!^$match!", urldecode($request_match), $matches)) { 
    161161                                        // Got a match. 
    162162                                        $this->matched_rule = $match; 
    163                                          
     163 
    164164                                        // Trim the query of everything up to the '?'. 
    165165                                        $query = preg_replace("!^.+\?!", '', $query); 
    166166 
     
    219219                for ($i=0; $i<count($this->private_query_vars); $i += 1) { 
    220220                        $wpvar = $this->private_query_vars[$i]; 
    221221                        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]; 
    223223                } 
    224224 
    225225                if ( isset($error) ) 
     
    241241                        // We're showing a feed, so WP is indeed the only thing that last changed 
    242242                        if ( $this->query_vars['withcomments'] ) 
    243243                                $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT'; 
    244                         else  
     244                        else 
    245245                                $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; 
    246246                        $wp_etag = '"' . md5($wp_last_modified) . '"'; 
    247247                        @header("Last-Modified: $wp_last_modified"); 
    248248                        @header("ETag: $wp_etag"); 
    249249 
    250250                        // Support for Conditional GET 
    251                         if (isset($_SERVER['HTTP_IF_NONE_MATCH']))  
     251                        if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) 
    252252                                $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])); 
    253253                        else $client_etag = false; 
    254254 
     
    315315        function query_posts() { 
    316316                $this->build_query_string(); 
    317317                query_posts($this->query_string); 
    318         } 
     318        } 
    319319 
    320320        function handle_404() { 
    321321                global $wp_query; 
     
    367367                if ( empty($codes) ) 
    368368                        return ''; 
    369369 
    370                 return $codes[0];        
     370                return $codes[0]; 
    371371        } 
    372372 
    373373        function get_error_messages($code = '') { 
     
    383383                if ( isset($this->errors[$code]) ) 
    384384                        return $this->errors[$code]; 
    385385                else 
    386                         return array();  
     386                        return array(); 
    387387        } 
    388388 
    389389        function get_error_message($code = '') { 
     
    396396        } 
    397397 
    398398        function add($code, $message) { 
    399                 $this->errors[$code][] = $message;       
     399                $this->errors[$code][] = $message; 
    400400        } 
    401401} 
    402402 
     
    409409 
    410410// A class for displaying various tree-like structures. Extend the Walker class to use it, see examples at the bottom 
    411411 
    412 class Walker {   
     412class Walker { 
    413413        var $tree_type; 
    414414        var $db_fields; 
    415          
     415 
    416416        //abstract callbacks 
    417417        function start_lvl($output) { return $output; } 
    418418        function end_lvl($output)   { return $output; } 
    419419        function start_el($output)  { return $output; } 
    420420        function end_el($output)    { return $output; } 
    421          
     421 
    422422        function walk($elements, $to_depth) { 
    423423                $args = array_slice(func_get_args(), 2); $parents = array(); $depth = 1; $previous_element = ''; $output = ''; 
    424          
     424 
    425425                //padding at the end 
    426426                $last_element->post_parent = 0; 
    427427                $last_element->post_id = 0; 
    428428                $elements[] = $last_element; 
    429          
     429 
    430430                $id_field = $this->db_fields['id']; 
    431431                $parent_field = $this->db_fields['parent']; 
    432          
     432 
    433433                $flat = ($to_depth == -1) ? true : false; 
    434          
     434 
    435435                foreach ( $elements as $element ) { 
    436436                        // If flat, start and end the element and skip the level checks. 
    437437                        if ( $flat) { 
     
    440440                                        $cb_args = array_merge( array($output, $element, $depth - 1), $args); 
    441441                                        $output = call_user_func_array(array(&$this, 'start_el'), $cb_args); 
    442442                                } 
    443          
     443 
    444444                                // End the element. 
    445445                                if ( $element->$id_field != 0 ) { 
    446446                                        $cb_args = array_merge( array($output, $element, $depth - 1), $args); 
    447447                                        $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 
    448448                                } 
    449          
    450                                 continue;        
     449 
     450                                continue; 
    451451                        } 
    452          
     452 
    453453                        // Walk the tree. 
    454454                        if ( !empty($previous_element) && ($element->$parent_field == $previous_element->$id_field) ) { 
    455455                                // Previous element is my parent. Descend a level. 
     
    471471                                        $cb_args = array_merge( array($output, $previous_element, $depth - 1), $args); 
    472472                                        $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 
    473473                                } 
    474          
     474 
    475475                                while ( $parent = array_shift($parents) ) { 
    476476                                        $depth--; 
    477477                                        if ( !$to_depth || ($depth < $to_depth) ) { 
     
    491491                                        $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 
    492492                                } 
    493493                        } 
    494          
     494 
    495495                        // Start the element. 
    496496                        if ( !$to_depth || ($depth <= $to_depth) ) { 
    497497                                if ( $element->$id_field != 0 ) { 
     
    499499                                        $output = call_user_func_array(array(&$this, 'start_el'), $cb_args); 
    500500                                } 
    501501                        } 
    502          
     502 
    503503                        $previous_element = $element; 
    504504                } 
    505                  
     505 
    506506                return $output; 
    507507        } 
    508508} 
     
    510510class Walker_Page extends Walker { 
    511511        var $tree_type = 'page'; 
    512512        var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this 
    513          
     513 
    514514        function start_lvl($output, $depth) { 
    515515                $indent = str_repeat("\t", $depth); 
    516516                $output .= "$indent<ul>\n"; 
    517517                return $output; 
    518518        } 
    519          
     519 
    520520        function end_lvl($output, $depth) { 
    521521                $indent = str_repeat("\t", $depth); 
    522522                $output .= "$indent</ul>\n"; 
    523523                return $output; 
    524524        } 
    525          
     525 
    526526        function start_el($output, $page, $depth, $current_page, $show_date, $date_format) { 
    527527                if ( $depth ) 
    528528                        $indent = str_repeat("\t", $depth); 
     
    532532                        $css_class .= ' current_page_item'; 
    533533 
    534534                $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 
    536536                if ( !empty($show_date) ) { 
    537537                        if ( 'modified' == $show_date ) 
    538538                                $time = $page->post_modified; 
    539539                        else 
    540540                                $time = $page->post_date; 
    541          
     541 
    542542                        $output .= " " . mysql2date($date_format, $time); 
    543543                } 
    544544 
    545545                return $output; 
    546546        } 
    547          
     547 
    548548        function end_el($output, $page, $depth) { 
    549549                $output .= "</li>\n"; 
    550550 
     
    558558        var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this 
    559559 
    560560        function start_el($output, $page, $depth, $args) { 
    561         $pad = str_repeat('&nbsp;', $depth * 3); 
     561                                $pad = str_repeat('&nbsp;', $depth * 3); 
    562562 
    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"; 
    570570 
    571         return $output; 
     571                                return $output; 
    572572        } 
    573573} 
    574574 
    575575class Walker_Category extends Walker { 
    576576        var $tree_type = 'category'; 
    577577        var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this 
    578          
     578 
    579579        function start_lvl($output, $depth, $args) { 
    580580                if ( 'list' != $args['style'] ) 
    581581                        return $output; 
    582          
     582 
    583583                $indent = str_repeat("\t", $depth); 
    584584                $output .= "$indent<ul class='children'>\n"; 
    585585                return $output; 
    586586        } 
    587          
     587 
    588588        function end_lvl($output, $depth, $args) { 
    589589                if ( 'list' != $args['style'] ) 
    590590                        return $output; 
    591          
     591 
    592592                $indent = str_repeat("\t", $depth); 
    593593                $output .= "$indent</ul>\n"; 
    594594                return $output; 
    595595        } 
    596          
     596 
    597597        function start_el($output, $category, $depth, $args) { 
    598598                extract($args); 
    599          
     599 
    600600                $link = '<a href="' . get_category_link($category->cat_ID) . '" '; 
    601601                if ( $use_desc_for_title == 0 || empty($category->category_description) ) 
    602602                        $link .= 'title="'. sprintf(__("View all posts filed under %s"), wp_specialchars($category->cat_name)) . '"'; 
     
    604604                        $link .= 'title="' . wp_specialchars(apply_filters('category_description',$category->category_description,$category)) . '"'; 
    605605                $link .= '>'; 
    606606                $link .= apply_filters('list_cats', $category->cat_name, $category).'</a>'; 
    607          
     607 
    608608                if ( (! empty($feed_image)) || (! empty($feed)) ) { 
    609609                        $link .= ' '; 
    610          
     610 
    611611                        if ( empty($feed_image) ) 
    612612                                $link .= '('; 
    613          
     613 
    614614                        $link .= '<a href="' . get_category_rss_link(0, $category->cat_ID, $category->category_nicename) . '"'; 
    615          
     615 
    616616                        if ( !empty($feed) ) { 
    617617                                $title = ' title="' . $feed . '"'; 
    618618                                $alt = ' alt="' . $feed . '"'; 
    619619                                $name = $feed; 
    620620                                $link .= $title; 
    621621                        } 
    622          
     622 
    623623                        $link .= '>'; 
    624          
     624 
    625625                        if ( !empty($feed_image) ) 
    626626                                $link .= "<img src='$feed_image' $alt$title" . ' />'; 
    627627                        else 
     
    630630                        if (empty($feed_image)) 
    631631                                $link .= ')'; 
    632632                } 
    633          
     633 
    634634                if ( $show_count ) 
    635635                        $link .= ' ('.intval($category->category_count).')'; 
    636          
     636 
    637637                if ( $show_date ) { 
    638638                        $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp); 
    639639                } 
    640          
     640 
    641641                if ( 'list' == $args['style'] ) { 
    642642                        $output .= "\t<li"; 
    643643                        if ( ($category->cat_ID == $current_category) && is_category() ) 
     
    646646                } else { 
    647647                        $output .= "\t$link<br />\n"; 
    648648                } 
    649          
     649 
    650650                return $output; 
    651651        } 
    652          
     652 
    653653        function end_el($output, $page, $depth, $args) { 
    654654                if ( 'list' != $args['style'] ) 
    655655                        return $output; 
    656          
     656 
    657657                $output .= "</li>\n"; 
    658658                return $output; 
    659659        } 
     
    663663class Walker_CategoryDropdown extends Walker { 
    664664        var $tree_type = 'category'; 
    665665        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) { 
    668668                $pad = str_repeat('&nbsp;', $depth * 3); 
    669                  
     669 
    670670                $cat_name = apply_filters('list_cats', $category->cat_name, $category); 
    671671                $output .= "\t<option value=\"".$category->cat_ID."\""; 
    672672                if ( $category->cat_ID == $args['selected'] ) 
     
    680680                        $output .= '&nbsp;&nbsp;' . gmdate($format, $category->last_update_timestamp); 
    681681                } 
    682682                $output .= "</option>\n"; 
    683                  
     683 
    684684                return $output; 
    685685        } 
    686686} 
  • wp-includes/comment-template.php

     
    142142} 
    143143 
    144144function comments_link( $file = '', $echo = true ) { 
    145     echo get_comments_link(); 
     145                echo get_comments_link(); 
    146146} 
    147147 
    148148function get_comments_number( $post_id = 0 ) { 
     
    239239function trackback_rdf($timezone = 0) { 
    240240        global $id; 
    241241        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/"> 
    245245                <rdf:Description rdf:about="'; 
    246246        the_permalink(); 
    247247        echo '"'."\n"; 
     
    264264 
    265265function pings_open() { 
    266266        global $post; 
    267         if ( 'open' == $post->ping_status )  
     267        if ( 'open' == $post->ping_status ) 
    268268                return true; 
    269269        else 
    270270                return false; 
     
    298298} 
    299299 
    300300function comments_popup_script($width=400, $height=400, $file='') { 
    301     global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; 
     301                global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; 
    302302 
    303303                if (empty ($file)) { 
    304304                        $wpcommentspopupfile = '';  // Use the index. 
     
    306306                        $wpcommentspopupfile = $file; 
    307307                } 
    308308 
    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; 
    312312} 
    313313 
    314314function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { 
  • wp-includes/comment.php

     
    1818                        // Skip empty lines 
    1919                        if (empty($word)) { continue; } 
    2020 
    21                         // Do some escaping magic so that '#' chars in the  
     21                        // Do some escaping magic so that '#' chars in the 
    2222                        // spam words don't break things: 
    2323                        $word = preg_quote($word, '#'); 
    2424 
    25                         $pattern = "#$word#i";  
     25                        $pattern = "#$word#i"; 
    2626                        if ( preg_match($pattern, $author) ) return false; 
    2727                        if ( preg_match($pattern, $email) ) return false; 
    2828                        if ( preg_match($pattern, $url) ) return false; 
     
    103103        if ($no_cache) { 
    104104                $query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'"; 
    105105                if (false == $include_unapproved) { 
    106                     $query .= " AND comment_approved = '1'"; 
     106                                $query .= " AND comment_approved = '1'"; 
    107107                } 
    108                 $myrow = $wpdb->get_row($query, ARRAY_A); 
     108                                $myrow = $wpdb->get_row($query, ARRAY_A); 
    109109        } else { 
    110110                $myrow['comment_ID'] = $postc->comment_ID; 
    111111                $myrow['comment_post_ID'] = $postc->comment_post_ID; 
     
    157157        if ( isset($_COOKIE['comment_author_email_'.COOKIEHASH]) ) { 
    158158                $comment_author_email = apply_filters('pre_comment_author_email', $_COOKIE['comment_author_email_'.COOKIEHASH]); 
    159159                $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); 
    161161                $_COOKIE['comment_author_email_'.COOKIEHASH] = $comment_author_email; 
    162162        } 
    163163 
     
    244244                // Skip empty lines 
    245245                if ( empty($word) ) { continue; } 
    246246 
    247                 // Do some escaping magic so that '#' chars in the  
     247                // Do some escaping magic so that '#' chars in the 
    248248                // spam words don't break things: 
    249249                $word = preg_quote($word, '#'); 
    250250 
    251                 $pattern = "#$word#i";  
     251                $pattern = "#$word#i"; 
    252252                if ( preg_match($pattern, $author    ) ) return true; 
    253253                if ( preg_match($pattern, $email     ) ) return true; 
    254254                if ( preg_match($pattern, $url       ) ) return true; 
     
    333333        if ( ! isset($user_id) ) 
    334334                $user_id = 0; 
    335335 
    336         $result = $wpdb->query("INSERT INTO $wpdb->comments  
     336        $result = $wpdb->query("INSERT INTO $wpdb->comments 
    337337        (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 
    339339        ('$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') 
    340340        "); 
    341341 
     
    394394} 
    395395 
    396396function wp_set_comment_status($comment_id, $comment_status) { 
    397     global $wpdb; 
     397                global $wpdb; 
    398398 
    399     switch($comment_status) { 
     399                switch($comment_status) { 
    400400                case 'hold': 
    401401                        $query = "UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; 
    402402                break; 
    403403                case 'approve': 
    404404                        $query = "UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; 
    405405                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; 
    409409                case 'delete': 
    410410                        return wp_delete_comment($comment_id); 
    411411                break; 
    412412                default: 
    413413                        return false; 
    414     } 
    415      
    416     if ($wpdb->query($query)) { 
     414                } 
     415 
     416                if ($wpdb->query($query)) { 
    417417                do_action('wp_set_comment_status', $comment_id, $comment_status); 
    418418 
    419419                $comment = get_comment($comment_id); 
     
    422422                if( is_object( $c ) ) 
    423423                        $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" ); 
    424424                return true; 
    425     } else { 
     425                } else { 
    426426                return false; 
    427     } 
     427                } 
    428428} 
    429429 
    430430function wp_update_comment($commentarr) { 
     
    579579                $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';"); 
    580580                pingback($ping->post_content, $ping->ID); 
    581581        } 
    582          
     582 
    583583        // Do Enclosures 
    584584        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")) { 
    585585                $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$enclosure->ID} AND meta_key = '_encloseme';"); 
     
    616616        $excerpt = str_replace(']]>', ']]&gt;', $excerpt); 
    617617        $excerpt = strip_tags($excerpt); 
    618618        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')) . '...'; 
    620620        else 
    621621                $excerpt = substr($excerpt, 0, 252) . '...'; 
    622622 
     
    702702                $pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048); 
    703703 
    704704                if ($pingback_server_url) { 
    705                         @ set_time_limit( 60 );  
     705                        @ set_time_limit( 60 ); 
    706706                         // Now, the RPC call 
    707707                        debug_fwrite($log, "Page Linked To: $pagelinkedto \n"); 
    708708                        debug_fwrite($log, 'Page Linked From: '); 
  • wp-includes/compat.php

     
    3636/* Added in PHP 4.3.0 */ 
    3737 
    3838function printr($var, $do_not_echo = false) { 
    39         // from php.net/print_r user contributed notes  
     39        // from php.net/print_r user contributed notes 
    4040        ob_start(); 
    4141        print_r($var); 
    4242        $code =  htmlentities(ob_get_contents()); 
    4343        ob_clean(); 
    4444        if (!$do_not_echo) { 
    45           echo "<pre>$code</pre>"; 
     45                echo "<pre>$code</pre>"; 
    4646        } 
    4747        ob_end_clean(); 
    4848        return $code; 
     
    5757} 
    5858 
    5959if (!defined('CASE_LOWER')) { 
    60     define('CASE_LOWER', 0); 
     60                define('CASE_LOWER', 0); 
    6161} 
    6262 
    6363if (!defined('CASE_UPPER')) { 
    64     define('CASE_UPPER', 1); 
     64                define('CASE_UPPER', 1); 
    6565} 
    6666 
    6767 
     
    7878 * @require     PHP 4.0.0 (user_error) 
    7979 */ 
    8080if (!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                                } 
    8888 
    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'; 
    9292 
    93         foreach ($keys as $key) { 
    94             $output[$casefunc($key)] = $input[$key]; 
    95         } 
     93                                foreach ($keys as $key) { 
     94                                                $output[$casefunc($key)] = $input[$key]; 
     95                                } 
    9696 
    97         return $output; 
    98     } 
     97                                return $output; 
     98                } 
    9999} 
    100100 
    101101// From php.net 
    102102if(!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        } 
    113113} 
    114114 
    115115if ( !function_exists('_') ) { 
  • wp-includes/cron.php

     
    6666 
    6767function spawn_cron() { 
    6868        $crons = get_option( 'cron' ); 
    69          
     69 
    7070        if ( !is_array($crons) ) 
    7171                return; 
    72          
     72 
    7373        $keys = array_keys( $crons ); 
    7474        if ( array_shift( $keys ) > time() ) 
    7575                return; 
     
    8080        $argyle = @ fsockopen( $parts['host'], $_SERVER['SERVER_PORT'], $errno, $errstr, 0.01 ); 
    8181        if ( $argyle ) 
    8282                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" 
    8484                        . "Host: {$_SERVER['HTTP_HOST']}\r\n\r\n" 
    8585                ); 
    8686} 
    8787 
    8888function wp_cron() { 
    8989        $crons = get_option( 'cron' ); 
    90          
     90 
    9191        if ( !is_array($crons) ) 
    9292                return; 
    9393 
  • wp-includes/deprecated.php

     
    129129        $post_author_data = get_userdata($post->post_author); 
    130130 
    131131        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) ) { 
    134134                return true; 
    135135        } else { 
    136136                return false; 
     
    199199 **   show_updated (default 0) - whether to show last updated timestamp 
    200200 */ 
    201201function 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); 
    215215} 
    216216 
    217217/** function wp_get_linksbyname() 
     
    252252 **/ 
    253253// Deprecate in favor of get_linkz(). 
    254254function 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); 
    265265} 
    266266 
    267267/** function get_linkobjects() 
     
    301301 **/ 
    302302// Deprecate in favor of get_linkz(). 
    303303function get_linkobjects($category = -1, $orderby = 'name', $limit = -1) { 
    304     global $wpdb; 
     304                global $wpdb; 
    305305 
    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"; 
    326326 
    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; 
    338338} 
    339339 
    340340/** function get_linksbyname_withrating() 
     
    359359 **   show_updated (default 0) - whether to show last updated timestamp 
    360360 */ 
    361361function 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) { 
    365365 
    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); 
    368368} 
    369369 
    370370/** function get_links_withrating() 
     
    389389 **   show_updated (default 0) - whether to show last updated timestamp 
    390390 */ 
    391391function 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) { 
    395395 
    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); 
    398398} 
    399399 
    400400/** function get_get_autotoggle() 
     
    403403 **                uses 0 
    404404 */ 
    405405function get_autotoggle($id = 0) { 
    406         return 0;   
     406        return 0; 
    407407} 
    408408 
    409409function 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) { 
     
    433433                $r['style'] = 'break'; 
    434434        $r['title_li'] = ''; 
    435435 
    436         return wp_list_categories($r);   
     436        return wp_list_categories($r); 
    437437} 
    438438 
    439439function dropdown_cats($optionall = 1, $all = 'All', $orderby = 'ID', $order = 'asc', 
  • wp-includes/feed.php

     
    5959} 
    6060 
    6161function permalink_single_rss($file = '') { 
    62     echo get_permalink(); 
     62                echo get_permalink(); 
    6363} 
    6464 
    6565function comment_link() { 
     
    9696} 
    9797 
    9898function 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'); 
    101101 
    102       if ('' == $permalink_structure) { 
     102                        if ('' == $permalink_structure) { 
    103103                                 $link = get_settings('home') . '?feed=rss2&amp;author=' . $author_id; 
    104       } else { 
     104                        } else { 
    105105                                 $link = get_author_link(0, $author_id, $author_nicename); 
    106106                                 $link = $link . "feed/"; 
    107       } 
    108                           
     107                        } 
     108 
    109109                         $link = apply_filters('author_feed_link', $link); 
    110110 
    111       if ($echo) echo $link; 
    112       return $link; 
     111                        if ($echo) echo $link; 
     112                        return $link; 
    113113} 
    114114 
    115115function get_category_rss_link($echo = false, $cat_ID, $category_nicename) { 
    116       $permalink_structure = get_settings('permalink_structure'); 
     116                        $permalink_structure = get_settings('permalink_structure'); 
    117117 
    118       if ('' == $permalink_structure) { 
     118                        if ('' == $permalink_structure) { 
    119119                                 $link = get_settings('home') . '?feed=rss2&amp;cat=' . $cat_ID; 
    120       } else { 
     120                        } else { 
    121121                                 $link = get_category_link($cat_ID); 
    122122                                 $link = $link . "feed/"; 
    123       } 
     123                        } 
    124124 
    125125                         $link = apply_filters('category_feed_link', $link); 
    126126 
    127       if ($echo) echo $link; 
    128       return $link; 
     127                        if ($echo) echo $link; 
     128                        return $link; 
    129129} 
    130130 
    131131function 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); 
    143143} 
    144144 
    145145function rss_enclosure() { 
     
    148148 
    149149        $custom_fields = get_post_custom(); 
    150150        if( is_array( $custom_fields ) ) { 
    151                 while( list( $key, $val ) = each( $custom_fields ) ) {  
     151                while( list( $key, $val ) = each( $custom_fields ) ) { 
    152152                        if( $key == 'enclosure' ) { 
    153153                                if (is_array($val)) { 
    154154                                        foreach($val as $enc) { 
  • wp-includes/formatting.php

     
    5858        $pee = $pee . "\n"; // just to make things a little easier, pad the end 
    5959        $pee = preg_replace('|<br />\s*<br />|', "\n\n", $pee); 
    6060        // 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); 
    6262        $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 
    6464        $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 
    6767        $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 
    6868        $pee = preg_replace("|<p>(<li.+?)</p>|", "$1", $pee); // problem with nested lists 
    6969        $pee = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee); 
    7070        $pee = str_replace('</blockquote></p>', '</p></blockquote>', $pee); 
    7171        $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); 
    7373        if ($br) { 
    7474                $pee = preg_replace('/<(script|style).*?<\/\\1>/se', 'str_replace("\n", "<WPPreserveNewline />", "\\0")', $pee); 
    7575                $pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks 
     
    7979        $pee = preg_replace('!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)!', '$1', $pee); 
    8080        $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</pre>' ", $pee); 
    8181 
    82         return $pee;  
     82        return $pee; 
    8383} 
    8484 
    8585 
     
    117117} 
    118118 
    119119function 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; 
    125123 
    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 ) { 
    136136        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]); 
    138138        } else { 
    139           $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); 
     139                $unicode .= '%' . dechex($values[0]) . '%' . dechex($values[1]); 
    140140        } 
    141141 
    142142        $values = array(); 
    143143        $num_octets = 1; 
    144       } 
    145     } 
    146   } 
     144                        } 
     145                } 
     146        } 
    147147 
    148   return $unicode;     
     148        return $unicode; 
    149149} 
    150150 
    151151function remove_accents($string) { 
     
    325325        return $title; 
    326326} 
    327327 
    328 function convert_chars($content, $flag = 'obsolete') {  
     328function convert_chars($content, $flag = 'obsolete') { 
    329329        // Translation of invalid Unicode references range to valid range 
    330330        $wp_htmltranswinuni = array( 
    331331        '&#128;' => '&#8364;', // the Euro sign 
     
    391391 
    392392/* 
    393393 balanceTags 
    394   
     394 
    395395 Balances Tags of string using a modified stack. 
    396   
     396 
    397397 @param text      Text to be balanced 
    398398 @return          Returns balanced text 
    399399 @author          Leonard Lin (leonard@acm.org) 
    400400 @version         v1.1 
    401401 @date            November 4, 2001 
    402402 @license         GPL v2.0 
    403  @notes            
    404  @changelog        
     403 @notes 
     404 @changelog 
    405405 ---  Modified by Scott Reilly (coffee2code) 02 Aug 2004 
    406             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 
     406                                                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 
    410410*/ 
    411411function balanceTags($text, $is_comment = 0, $force = false) { 
    412412 
     
    432432                if ($regex[1][0] == "/") { // End Tag 
    433433                        $tag = strtolower(substr($regex[1],1)); 
    434434                        // if too many closing tags 
    435                         if($stacksize <= 0) {  
     435                        if($stacksize <= 0) { 
    436436                                $tag = ''; 
    437437                                //or close to be safe $tag = '/' . $tag; 
    438438                        } 
     
    489489                } 
    490490                $newtext .= substr($text,0,$i) . $tag; 
    491491                $text = substr($text,$i+$l); 
    492         }   
     492        } 
    493493 
    494494        // Clear Tag Queue 
    495495        $newtext .= $tagqueue; 
     
    538538} 
    539539 
    540540function trailingslashit($string) { 
    541     if ( '/' != substr($string, -1)) { 
    542         $string .= '/'; 
    543     } 
    544     return $string; 
     541                if ( '/' != substr($string, -1)) { 
     542                                $string .= '/'; 
     543                } 
     544                return $string; 
    545545} 
    546546 
    547547function addslashes_gpc($gpc) { 
     
    557557 
    558558function stripslashes_deep($value) 
    559559{ 
    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); 
    563563 
    564   return $value; 
     564        return $value; 
    565565} 
    566566 
    567567function antispambot($emailaddy, $mailto=0) { 
     
    601601 
    602602function convert_smilies($text) { 
    603603        global $wp_smiliessearch, $wp_smiliesreplace; 
    604     $output = ''; 
     604                $output = ''; 
    605605        if (get_settings('use_smilies')) { 
    606606                // HTML loop taken from texturize function, could possible be consolidated 
    607607                $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between 
     
    636636 
    637637// used by wp-mail to handle charsets in email subjects 
    638638function 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        } 
    647647} 
    648648 
    649649 
    650650// give it a date, it will give you the same date as GMT 
    651651function get_gmt_from_date($string) { 
    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; 
     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; 
    657657} 
    658658 
    659659// give it a GMT date, it will give you the same date with $time_difference added 
    660660function get_date_from_gmt($string) { 
    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; 
     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; 
    666666} 
    667667 
    668668// computes an offset in seconds from an iso8601 timezone 
    669669function 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; 
    680680} 
    681681 
    682682// converts an iso8601 date to MySQL DateTime format used by post_date[_gmt] 
    683683function 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 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   } 
     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        } 
    697697} 
    698698 
    699699function popuplinks($text) { 
     
    708708        return preg_replace('/[^a-z0-9+_.@-]/i', '', $email); 
    709709} 
    710710 
    711 function human_time_diff( $from, $to = '' ) {      
     711function human_time_diff( $from, $to = '' ) { 
    712712        if ( empty($to) ) 
    713713                $to = time(); 
    714714        $diff = (int) abs($to - $from); 
     
    722722                $hours = round($diff / 3600); 
    723723                if ($hours <= 1) 
    724724                        $since = __('1 hour'); 
    725                 else  
     725                else 
    726726                        $since = sprintf( __('%s hours'), $hours ); 
    727727        } elseif ($diff >= 86400) { 
    728728                $days = round($diff / 86400); 
  • wp-includes/functions.php

     
    1212 
    1313        if( 'U' == $dateformatstring ) 
    1414                return $i; 
    15          
     15 
    1616        if ( -1 == $i || false == $i ) 
    1717                $i = 0; 
    1818 
     
    438438        @set_time_limit( 60 ); 
    439439 
    440440        if ( $red > 5 ) 
    441           return false; 
     441                return false; 
    442442 
    443443        $parts = parse_url( $url ); 
    444444        $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : ''); 
     
    467467        preg_match('/.*([0-9]{3}).*/', $response, $return); 
    468468        $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404 
    469469 
    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 ); 
    473473 
    474474        return $headers; 
    475475} 
     
    743743} 
    744744 
    745745function bool_from_yn($yn) { 
    746     if ($yn == 'Y') return 1; 
    747     return 0; 
     746                if ($yn == 'Y') return 1; 
     747                return 0; 
    748748} 
    749749 
    750750function do_feed() { 
     
    754754        $feed = preg_replace('/^_+/', '', $feed); 
    755755 
    756756        if ($feed == '' || $feed == 'feed') 
    757         $feed = 'rss2'; 
     757                        $feed = 'rss2'; 
    758758 
    759759        $for_comments = false; 
    760760        if ( is_single() || (get_query_var('withcomments') == 1) ) { 
    761761                $feed = 'rss2'; 
    762                 $for_comments = true;    
     762                $for_comments = true; 
    763763        } 
    764764 
    765765        $hook = 'do_feed_' . $feed; 
     
    899899                return array('error' => $message); 
    900900        } 
    901901 
    902     $uploads = array('path' => $dir, 'url' => $url, 'error' => false); 
     902                $uploads = array('path' => $dir, 'url' => $url, 'error' => false); 
    903903        return apply_filters('upload_dir', $uploads); 
    904904} 
    905905 
  • wp-includes/general-template.php

     
    438438                FROM $wpdb->posts 
    439439                WHERE post_date >       '$thisyear-$thismonth-01' 
    440440                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' 
    442442                        ORDER   BY post_date ASC 
    443443                        LIMIT 1"); 
    444444 
     
    741741                                        var i = tinyMCE.selectedInstance; 
    742742                                        if(typeof i ==  'undefined') 
    743743                                                return true; 
    744                                         tinyMCE.execCommand("mceStartTyping"); 
     744                                                                                                                                        tinyMCE.execCommand("mceStartTyping"); 
    745745                                        this.blur(); 
    746746                                        i.contentWindow.focus(); 
    747747                                        e.returnValue = false; 
     
    756756                                        var i = tinyMCE.selectedInstance; 
    757757                                        if(typeof i ==  'undefined') 
    758758                                                return true; 
    759                                         tinyMCE.execCommand("mceStartTyping"); 
     759                                                                                                                                        tinyMCE.execCommand("mceStartTyping"); 
    760760                                        this.blur(); 
    761761                                        i.contentWindow.focus(); 
    762762                                        e.returnValue = false; 
  • wp-includes/gettext.php

     
    11<?php 
    22/* 
    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> 
    75 
    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. 
    127 
    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. 
    1712 
    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. 
    2117 
     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 
    2222*/ 
    23   
     23 
    2424/** 
    2525 * Provides a simple gettext replacement that works independently from 
    2626 * the system's gettext abilities. 
    2727 * It can read MO files and use them for translating strings. 
    2828 * The files are passed to gettext_reader as a Stream (see streams.php) 
    29  *  
     29 * 
    3030 * This version has the ability to cache all strings and translations to 
    3131 * speed up the string lookup. 
    3232 * While the cache is enabled by default, it can be switched off with the 
     
    3434 * that you don't want to keep in memory) 
    3535 */ 
    3636class 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) 
    5239 
     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 
    5352 
    54   /* Methods */ 
    55    
    56      
    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     } 
    7553 
    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 */ 
    10755 
    108     // $MAGIC1 = (int)0x950412de; //bug in PHP 5 
    109     $MAGIC1 = (int) - 1794895138; 
    110     // $MAGIC2 = (int)0xde120495; //bug 
    111     $MAGIC2 = (int) - 569244523; 
    11256 
    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                } 
    26675 
    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        } 
    29391 
    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                } 
    309104 
    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; 
    314107 
    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; 
    331112 
    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                } 
    358123 
     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 
    359359} 
    360360 
    361361?> 
  • wp-includes/l10n.php

     
    2323        return $locale; 
    2424} 
    2525 
    26 // Return a translated string.     
     26// Return a translated string. 
    2727function __($text, $domain = 'default') { 
    2828        global $l10n; 
    2929 
  • wp-includes/link-template.php

     
    6363                $authordata = get_userdata($post->post_author); 
    6464                $author = $authordata->user_nicename; 
    6565                $date = explode(" ",date('Y m d H i s', $unixtime)); 
    66                 $rewritereplace =  
     66                $rewritereplace = 
    6767                array( 
    6868                        $date[0], 
    6969                        $date[1], 
     
    266266                for ( $i = 1; $i < (count($cat_array)); $i++ ) { 
    267267                        $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID); 
    268268                } 
    269                 $join .= ')';  
     269                $join .= ')'; 
    270270        } 
    271271 
    272272        $sql_exclude_cats = ''; 
     
    299299                for ( $i = 1; $i < (count($cat_array)); $i++ ) { 
    300300                        $join .= ' OR category_id = ' . intval($cat_array[$i]->cat_ID); 
    301301                } 
    302                 $join .= ')';  
     302                $join .= ')'; 
    303303        } 
    304304 
    305305        $sql_exclude_cats = ''; 
     
    334334 
    335335        $format = str_replace('%link', $link, $format); 
    336336 
    337         echo $format;        
     337        echo $format; 
    338338} 
    339339 
    340340function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') { 
     
    349349        $link = $string . $link . '</a>'; 
    350350        $format = str_replace('%link', $link, $format); 
    351351 
    352         echo $format;        
     352        echo $format; 
    353353} 
    354354 
    355355function get_pagenum_link($pagenum = 1) { 
     
    357357 
    358358        $qstr = wp_specialchars($_SERVER['REQUEST_URI']); 
    359359 
    360         $page_querystring = "paged";  
     360        $page_querystring = "paged"; 
    361361        $page_modstring = "page/"; 
    362362        $page_modregex = "page/?"; 
    363363        $permalink = 0; 
     
    474474function _max_num_pages() { 
    475475        static $max_num_pages; 
    476476        global $wpdb, $wp_query; 
    477          
     477 
    478478        if (isset($max_num_pages)) return $max_num_pages; 
    479          
     479 
    480480        if ( 'posts' == get_query_var('what_to_show') ) { 
    481481                preg_match('#FROM\s(.*)\sORDER BY#siU', $wp_query->request, $matches); 
    482482                $fromwhere = $matches[1]; 
     
    496496        if ( !is_single() ) { 
    497497                $max_num_pages = _max_num_pages(); 
    498498                $paged = get_query_var('paged'); 
    499                  
     499 
    500500                //only have sep if there's both prev and next results 
    501501                if ($paged < 2 || $paged >= $max_num_pages) { 
    502502                        $sep = ''; 
  • wp-includes/pluggable.php

     
    4646        if ( ! empty($current_user) ) 
    4747                return; 
    4848 
    49         if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) ||  
     49        if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || 
    5050                !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { 
    5151                wp_set_current_user(0); 
    5252                return false; 
     
    162162function wp_mail($to, $subject, $message, $headers = '') { 
    163163        if( $headers == '' ) { 
    164164                $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" . 
    166166                        "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n"; 
    167167        } 
    168168 
     
    216216if ( !function_exists('auth_redirect') ) : 
    217217function auth_redirect() { 
    218218        // 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]) && 
    220220                                !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) || 
    221221                         (empty($_COOKIE[USER_COOKIE])) ) { 
    222222                nocache_headers(); 
     
    327327if ( ! function_exists('wp_notify_postauthor') ) : 
    328328function wp_notify_postauthor($comment_id, $comment_type='') { 
    329329        global $wpdb; 
    330      
     330 
    331331        $comment = get_comment($comment_id); 
    332332        $post    = get_post($comment->comment_post_ID); 
    333333        $user    = get_userdata( $post->post_author ); 
     
    374374                $from = "From: \"$blogname\" <$wp_email>"; 
    375375                if ( '' != $comment->comment_author_email ) 
    376376                        $reply_to = "Reply-To: $comment->comment_author_email"; 
    377         } else { 
     377        } else { 
    378378                $from = "From: \"$comment->comment_author\" <$wp_email>"; 
    379379                if ( '' != $comment->comment_author_email ) 
    380380                        $reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>"; 
    381         } 
     381        } 
    382382 
    383383        $message_headers = "MIME-Version: 1.0\n" 
    384384                . "$from\n" 
     
    392392        $message_headers = apply_filters('comment_notification_headers', $message_headers, $comment_id); 
    393393 
    394394        @wp_mail($user->user_email, $subject, $notify_message, $message_headers); 
    395     
     395 
    396396        return true; 
    397397} 
    398398endif; 
    399399 
    400400/* wp_notify_moderator 
    401   notifies the moderator of the blog (usually the admin) 
    402   about a new comment that waits for approval 
    403   always returns true 
     401        notifies the moderator of the blog (usually the admin) 
     402        about a new comment that waits for approval 
     403        always returns true 
    404404 */ 
    405405if ( !function_exists('wp_notify_moderator') ) : 
    406406function wp_notify_moderator($comment_id) { 
    407407        global $wpdb; 
    408408 
    409409        if( get_settings( "moderation_notify" ) == 0 ) 
    410                 return true;  
    411      
     410                return true; 
     411 
    412412        $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1"); 
    413413        $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1"); 
    414414 
     
    435435        $subject = apply_filters('comment_moderation_subject', $subject, $comment_id); 
    436436 
    437437        @wp_mail($admin_email, $subject, $notify_message); 
    438      
     438 
    439439        return true; 
    440440} 
    441441endif; 
     
    485485        $uid = $user->id; 
    486486 
    487487        $i = ceil(time() / 43200); 
    488          
     488 
    489489        return substr(wp_hash($i . $action . $uid), -12, 10); 
    490490} 
    491491endif; 
  • wp-includes/plugin.php

     
    103103function do_action($tag, $arg = '') { 
    104104        global $wp_filter; 
    105105        $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); 
    108108        else 
    109109                $args = array_merge(array($arg), $extra_args); 
    110110 
  • wp-includes/post.php

     
    160160        $inclusions = ''; 
    161161        if ( !empty($include) ) { 
    162162                $offset = 0;    //ignore offset, category, exclude, meta_key, and meta_value params if using include 
    163                 $category = '';  
    164                 $exclude = '';   
     163                $category = ''; 
     164                $exclude = ''; 
    165165                $meta_key = ''; 
    166166                $meta_value = ''; 
    167167                $incposts = preg_split('/[\s,]+/',$include); 
     
    175175                        } 
    176176                } 
    177177        } 
    178         if (!empty($inclusions))  
    179                 $inclusions .= ')';      
     178        if (!empty($inclusions)) 
     179                $inclusions .= ')'; 
    180180 
    181181        $exclusions = ''; 
    182182        if ( !empty($exclude) ) { 
     
    190190                        } 
    191191                } 
    192192        } 
    193         if (!empty($exclusions))  
     193        if (!empty($exclusions)) 
    194194                $exclusions .= ')'; 
    195195 
    196196        $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 " ) ; 
    199199        $query .= " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " ; 
    200200        $query .= ( empty( $category ) ? "" : "AND ($wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. ") " ) ; 
    201201        $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' )" ) ; 
     
    429429 
    430430        $post_ID = (int) $post_ID; 
    431431 
    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' 
    435435                ORDER BY category_id"; 
    436436 
    437437        $result = $wpdb->get_col($sql); 
     
    464464        // Set categories 
    465465        if($mode == OBJECT) { 
    466466                $post->post_category = wp_get_post_categories($postid); 
    467         }  
     467        } 
    468468        else { 
    469469                $post['post_category'] = wp_get_post_categories($postid); 
    470470        } 
     
    657657                if ( !defined('WP_IMPORTING') ) { 
    658658                        if ( $post_pingback ) 
    659659                                $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) 
    662662                                        VALUES ('$post_ID','_pingme','1') 
    663663                                "); 
    664664                        $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) 
    667667                                VALUES ('$post_ID','_encloseme','1') 
    668668                        "); 
    669669                        wp_schedule_single_event(time(), 'do_pings'); 
     
    675675                if ( !empty($page_template) ) 
    676676                        if ( ! update_post_meta($post_ID, '_wp_page_template',  $page_template)) 
    677677                                add_post_meta($post_ID, '_wp_page_template',  $page_template, true); 
    678                                  
     678 
    679679                if ( $post_status == 'publish' ) 
    680680                        do_action('publish_page', $post_ID); 
    681681        } 
     
    683683        if ( 'future' == $post_status ) { 
    684684                wp_schedule_single_event(mysql2date('U', $post_date), 'publish_future_post', $post_ID); 
    685685        } 
    686                  
     686 
    687687        do_action('save_post', $post_ID); 
    688688        do_action('wp_insert_post', $post_ID); 
    689689 
     
    703703        $post = add_magic_quotes($post); 
    704704 
    705705        // 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']) 
    707707                         && 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']; 
    711711 
    712712        // 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']) ) 
    715715                $clear_date = true; 
    716716        else 
    717717                $clear_date = false; 
    718718 
    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; 
    722722        if ( $clear_date ) { 
    723723                $postarr['post_date'] = ''; 
    724724                $postarr['post_date_gmt'] = ''; 
     
    739739        if ( 'publish' == $post->post_status ) 
    740740                return; 
    741741 
    742         return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id));      
     742        return wp_update_post(array('post_status' => 'publish', 'ID' => $post_id)); 
    743743} 
    744744 
    745745function wp_set_post_categories($post_ID = 0, $post_categories = array()) { 
     
    752752 
    753753        // First the old categories 
    754754        $old_categories = $wpdb->get_col(" 
    755                 SELECT category_id  
    756                 FROM $wpdb->post2cat  
     755                SELECT category_id 
     756                FROM $wpdb->post2cat 
    757757                WHERE post_id = $post_ID"); 
    758758 
    759759        if (!$old_categories) { 
     
    768768        if ($delete_cats) { 
    769769                foreach ($delete_cats as $del) { 
    770770                        $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 
    774774                                "); 
    775775                } 
    776776        } 
     
    781781        if ($add_cats) { 
    782782                foreach ($add_cats as $new_cat) { 
    783783                        $wpdb->query(" 
    784                                 INSERT INTO $wpdb->post2cat (post_id, category_id)  
     784                                INSERT INTO $wpdb->post2cat (post_id, category_id) 
    785785                                VALUES ($post_ID, $new_cat)"); 
    786786                } 
    787787        } 
     
    866866 
    867867                $trackback_urls = explode(',', $tb_list); 
    868868                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); 
    871871                } 
    872     } 
     872                } 
    873873} 
    874874 
    875875// 
     
    946946 
    947947        $pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = '$leaf_path' AND post_type='page'"); 
    948948 
    949         if ( empty($pages) )  
     949        if ( empty($pages) ) 
    950950                return NULL; 
    951951 
    952952        foreach ($pages as $page) { 
     
    10261026 
    10271027        $inclusions = ''; 
    10281028        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 = ''; 
    10311031                $meta_key = ''; 
    10321032                $meta_value = ''; 
    10331033                $incpages = preg_split('/[\s,]+/',$include); 
     
    10401040                        } 
    10411041                } 
    10421042        } 
    1043         if (!empty($inclusions))  
    1044                 $inclusions .= ')';      
     1043        if (!empty($inclusions)) 
     1044                $inclusions .= ')'; 
    10451045 
    10461046        $exclusions = ''; 
    10471047        if ( !empty($exclude) ) { 
     
    10551055                        } 
    10561056                } 
    10571057        } 
    1058         if (!empty($exclusions))  
     1058        if (!empty($exclusions)) 
    10591059                $exclusions .= ')'; 
    10601060 
    10611061        $query = "SELECT * FROM $wpdb->posts " ; 
    1062         $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ;  
     1062        $query .= ( empty( $meta_key ) ? "" : ", $wpdb->postmeta " ) ; 
    10631063        $query .= " WHERE (post_type = 'page' AND post_status = 'publish') $exclusions $inclusions " ; 
    10641064        $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' )" ) ; 
    10651065        $query .= " ORDER BY " . $sort_column . " " . $sort_order ; 
     
    11771177 
    11781178        if (empty($post_date)) 
    11791179                $post_date = current_time('mysql'); 
    1180         if (empty($post_date_gmt))  
     1180        if (empty($post_date_gmt)) 
    11811181                $post_date_gmt = current_time('mysql', 1); 
    11821182 
    11831183        if ( empty($comment_status) ) { 
  • wp-includes/query.php

     
    33/* 
    44 * The Big Query. 
    55 */ 
    6   
     6 
    77function get_query_var($var) { 
    88        global $wp_query; 
    99 
     
    217217/* 
    218218 * The Loop.  Post loop control. 
    219219 */ 
    220   
     220 
    221221function have_posts() { 
    222222        global $wp_query; 
    223223 
     
    359359                } elseif ( $qv['p'] ) { 
    360360                        $this->is_single = true; 
    361361                } 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. 
    364364                        $this->is_single = true; 
    365365                } elseif ('' != $qv['static'] || '' != $qv['pagename'] || '' != $qv['page_id']) { 
    366366                        $this->is_page = true; 
     
    436436                        if ('' != $qv['category_name']) { 
    437437                                $this->is_category = true; 
    438438                        } 
    439              
     439 
    440440                        if ((empty($qv['author'])) || ($qv['author'] == '0')) { 
    441441                                $this->is_author = false; 
    442442                        } else { 
     
    700700 
    701701                // Category stuff 
    702702 
    703                 if ((empty($q['cat'])) || ($q['cat'] == '0') ||  
     703                if ((empty($q['cat'])) || ($q['cat'] == '0') || 
    704704                                // Bypass cat checks if fetching specific posts 
    705705                                ( $this->is_single || $this->is_page )) { 
    706706                        $whichcat=''; 
     
    717717                                if ( $in ) 
    718718                                        $in_cats .= "$cat, " . get_category_children($cat, '', ', '); 
    719719                                else 
    720                                         $out_cats .= "$cat, " . get_category_children($cat, '', ', ');                           
     720                                        $out_cats .= "$cat, " . get_category_children($cat, '', ', '); 
    721721                        } 
    722722                        $in_cats = substr($in_cats, 0, -2); 
    723723                        $out_cats = substr($out_cats, 0, -2); 
     
    762762                                $reqcat = 0; 
    763763 
    764764                        $q['cat'] = $reqcat; 
    765                                  
     765 
    766766                        $tables = ", $wpdb->post2cat, $wpdb->categories"; 
    767767                        $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) "; 
    768768                        $whichcat = " AND category_id IN ({$q['cat']}, "; 
     
    853853 
    854854                        if ( is_admin() ) 
    855855                                $where .= " OR post_status = 'future' OR post_status = 'draft'"; 
    856          
     856 
    857857                        if ( is_user_logged_in() ) { 
    858858                                if ( 'post' == $post_type ) 
    859859                                        $cap = 'edit_private_posts'; 
     
    963963        } 
    964964 
    965965        function next_post() { 
    966          
     966 
    967967                $this->current_post++; 
    968968 
    969969                $this->post = $this->posts[$this->current_post]; 
     
    999999                        $this->post = $this->posts[0]; 
    10001000                } 
    10011001        } 
    1002      
     1002 
    10031003        function &query($query) { 
    10041004                $this->parse_query($query); 
    10051005                return $this->get_posts(); 
  • wp-includes/registration.php

     
    8585                $wpdb->query( $query ); 
    8686                $user_id = $ID; 
    8787        } else { 
    88                 $query = "INSERT INTO $wpdb->users  
     88                $query = "INSERT INTO $wpdb->users 
    8989                (user_login, user_pass, user_email, user_url, user_registered, user_nicename, display_name) 
    90         VALUES  
     90        VALUES 
    9191                ('$user_login', '$user_pass', '$user_email', '$user_url', '$user_registered', '$user_nicename', '$display_name')"; 
    9292                $query = apply_filters('create_user_query', $query); 
    9393                $wpdb->query( $query ); 
  • wp-includes/rewrite.php

     
    1616        if (strlen($tagname) < 3 || $tagname{0} != '%' || $tagname{strlen($tagname)-1} != '%') { 
    1717                return; 
    1818        } 
    19          
     19 
    2020        $qv = trim($tagname, '%'); 
    21          
     21 
    2222        global $wp_rewrite, $wp; 
    2323        $wp->add_query_var($qv); 
    2424        $wp_rewrite->add_rewrite_tag($tagname, $regex, $qv . '='); 
    2525} 
    2626 
    27 //Add a new feed type like /atom1/  
     27//Add a new feed type like /atom1/ 
    2828function add_feed($feedname, $function) { 
    2929        global $wp_rewrite; 
    3030        if (!in_array($feedname, $wp_rewrite->feeds)) { //override the file if it is 
     
    169169        var $non_wp_rules; //rules that don't redirect to WP's index.php 
    170170        var $endpoints; 
    171171        var $use_verbose_rules = false; 
    172         var $rewritecode =  
     172        var $rewritecode = 
    173173                array( 
    174174                                        '%year%', 
    175175                                        '%monthnum%', 
     
    185185                                        '%search%' 
    186186                                        ); 
    187187 
    188         var $rewritereplace =  
     188        var $rewritereplace = 
    189189                array( 
    190190                                        '([0-9]{4})', 
    191191                                        '([0-9]{1,2})', 
     
    201201                                        '(.+)' 
    202202                                        ); 
    203203 
    204         var $queryreplace =  
     204        var $queryreplace = 
    205205                array ( 
    206206                                        'year=', 
    207207                                        'monthnum=', 
     
    218218                                        ); 
    219219 
    220220        var $feeds = array ( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); 
    221          
     221 
    222222        function using_permalinks() { 
    223223                if (empty($this->permalink_structure)) 
    224224                        return false; 
     
    235235                if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) { 
    236236                        return true; 
    237237                } 
    238      
     238 
    239239                return false; 
    240240        } 
    241241 
     
    251251                $match_suffix = ''; 
    252252 
    253253                if (! empty($this->matches)) { 
    254                         $match_prefix = '$' . $this->matches . '[';  
     254                        $match_prefix = '$' . $this->matches . '['; 
    255255                        $match_suffix = ']'; 
    256                 }         
     256                } 
    257257 
    258                 return "$match_prefix$number$match_suffix";         
     258                return "$match_prefix$number$match_suffix"; 
    259259        } 
    260260 
    261261        function page_rewrite_rules() { 
     
    301301                                $date_endian= $endian; 
    302302                                break; 
    303303                        } 
    304                 }  
     304                } 
    305305 
    306306                if ( empty($date_endian) ) 
    307307                        $date_endian = '%year%/%monthnum%/%day%'; 
    308308 
    309309                // 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/. 
    311311                $front = $this->front; 
    312312                preg_match_all('/%.+?%/', $this->permalink_structure, $tokens); 
    313313                $tok_index = 1; 
     
    481481                //build a regex to match the trackback and page/xx parts of URLs 
    482482                $trackbackregex = 'trackback/?$'; 
    483483                $pageregex = 'page/?([0-9]{1,})/?$'; 
    484                  
     484 
    485485                //build up an array of endpoint regexes to append => queries to append 
    486486                if ($endpoints) { 
    487487                        $ep_query_append = array (); 
    488                         foreach ($this->endpoints as $endpoint) {  
     488                        foreach ($this->endpoints as $endpoint) { 
    489489                                //match everything after the endpoint name, but allow for nothing to appear there 
    490490                                $epmatch = $endpoint[1] . '(/(.*))?/?$'; 
    491491                                //this will be appended on to the rest of the query for each dir 
     
    510510                        if (0 < $i) { 
    511511                                $queries[$i] = $queries[$i - 1] . '&'; 
    512512                        } 
    513               
     513 
    514514                        $query_token = str_replace($this->rewritecode, $this->queryreplace, $tokens[0][$i]) . $this->preg_index($i+1); 
    515515                        $queries[$i] .= $query_token; 
    516516                } 
     
    547547                        $num_toks = preg_match_all('/%.+?%/', $struct, $toks); 
    548548                        //get the 'tagname=$matches[i]' 
    549549                        $query = $queries[$num_toks - 1]; 
    550                          
     550 
    551551                        //set up $ep_mask_specific which is used to match more specific URL types 
    552552                        switch ($dirs[$j]) { 
    553553                                case '%year%': $ep_mask_specific = EP_YEAR; break; 
     
    579579                                $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2); 
    580580                        if ($paged) //...and /page/xx ones 
    581581                                $rewrite = array_merge($rewrite, array($pagematch => $pagequery)); 
    582                          
     582 
    583583                        //if we've got some tags in this dir 
    584584                        if ($num_toks) { 
    585585                                $post = false; 
    586586                                $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 
    589589                                //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 
    591591                                //minute all present). Set these flags now as we need them for the endpoints. 
    592592                                if (strstr($struct, '%postname%') || strstr($struct, '%post_id%') 
    593593                                                || strstr($struct, '%pagename%') 
     
    596596                                        if  ( strstr($struct, '%pagename%') ) 
    597597                                                $page = true; 
    598598                                } 
    599                                  
     599 
    600600                                //do endpoints 
    601601                                if ($endpoints) { 
    602602                                        foreach ($ep_query_append as $regex => $ep) { 
     
    606606                                                } 
    607607                                        } 
    608608                                } 
    609                                  
     609 
    610610                                //if we're creating rules for a permalink, do all the endpoints like attachments etc 
    611611                                if ($post) { 
    612612                                        $post = true; 
     
    617617                                        $match = rtrim($match, '/'); 
    618618                                        //get rid of brackets 
    619619                                        $submatchbase = str_replace(array('(',')'),'',$match); 
    620                                          
     620 
    621621                                        //add a rule for at attachments, which take the form of <permalink>/some-text 
    622622                                        $sub1 = $submatchbase . '/([^/]+)/'; 
    623623                                        $sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/... 
     
    625625                                        $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...) 
    626626                                        //add an ? as we don't have to match that last slash, and finally a $ so we 
    627627                                        //match to the end of the URL 
    628                                          
     628 
    629629                                        //add another rule to match attachments in the explicit form: 
    630630                                        //<permalink>/attachment/some-text 
    631631                                        $sub2 = $submatchbase . '/attachment/([^/]+)/'; 
    632632                                        $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback 
    633633                                        $sub2feed = $sub2 . $feedregex;    //feeds, <permalink>/attachment/feed/(atom|...) 
    634634                                        $sub2feed2 = $sub2 . $feedregex2;  //and feeds again on to this <permalink>/attachment/(feed|atom...) 
    635                                          
     635 
    636636                                        //create queries for these extra tag-ons we've just dealt with 
    637637                                        $subquery = $index . '?attachment=' . $this->preg_index(1); 
    638638                                        $subtbquery = $subquery . '&tb=1'; 
    639639                                        $subfeedquery = $subquery . '&feed=' . $this->preg_index(2); 
    640                                          
     640 
    641641                                        //do endpoints for attachments 
    642642                                        if ($endpoint) { foreach ($ep_query_append as $regex => $ep) { 
    643643                                                if ($ep[0] & EP_ATTACHMENT) { 
     
    645645                                                        $rewrite[$sub2 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2); 
    646646                                                } 
    647647                                        } } 
    648                                          
     648 
    649649                                        //now we've finished with endpoints, finish off the $sub1 and $sub2 matches 
    650650                                        $sub1 .= '?$'; 
    651651                                        $sub2 .= '?$'; 
    652                                          
     652 
    653653                                        //allow URLs like <permalink>/2 for <permalink>/page/2 
    654654                                        $match = $match . '(/[0-9]+)?/?$'; 
    655655                                        $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1); 
     
    658658                                        $match .= '?$'; 
    659659                                        $query = $index . '?' . $query; 
    660660                                } 
    661                                  
     661 
    662662                                //create the final array for this dir by joining the $rewrite array (which currently 
    663663                                //only contains rules/queries for trackback, pages etc) to the main regex/query for 
    664664                                //this dir 
     
    668668                                if ($post) { 
    669669                                        //add trackback 
    670670                                        $rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite); 
    671                                          
     671 
    672672                                        //add regexes/queries for attachments, attachment trackbacks and so on 
    673673                                        if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages 
    674674                                                $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery)); 
     
    762762 
    763763                $home_root = parse_url(get_settings('home')); 
    764764                $home_root = trailingslashit($home_root['path']); 
    765      
     765 
    766766                $rules = "<IfModule mod_rewrite.c>\n"; 
    767767                $rules .= "RewriteEngine On\n"; 
    768768                $rules .= "RewriteBase $home_root\n"; 
    769                  
     769 
    770770                //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all) 
    771771                foreach ($this->non_wp_rules as $match => $query) { 
    772772                        // Apache 1.3 does not support the reluctant (non-greedy) modifier. 
     
    818818 
    819819                return $rules; 
    820820        } 
    821          
     821 
    822822        //Add a straight rewrite rule 
    823823        function add_rule($regex, $redirect) { 
    824824                //get everything up to the first ? 
     
    830830                        $this->extra_rules[$regex] = $redirect; 
    831831                } 
    832832        } 
    833          
     833 
    834834        //add a rule that doesn't redirect to index.php 
    835835        function add_external_rule($regex, $redirect) { 
    836836                $this->non_wp_rules[$regex] = $redirect; 
    837837        } 
    838          
     838 
    839839        //add an endpoint, like /trackback/, to be inserted after certain URL types (specified in $places) 
    840840        function add_endpoint($name, $places) { 
    841841                global $wp; 
  • wp-includes/rss.php

     
    1111define('ATOM', 'Atom'); 
    1212define('MAGPIE_USER_AGENT', 'WordPress/' . $wp_version); 
    1313 
    14 class MagpieRSS {  
     14class MagpieRSS { 
    1515        var $parser; 
    1616        var $current_item       = array();      // item currently being parsed 
    1717        var $items                      = array();      // collection of parsed items 
     
    2525        var $stack                              = array(); // parser stack 
    2626        var $inchannel                  = false; 
    2727        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 
    2929        var $intextinput                = false; 
    3030        var $inimage                    = false; 
    3131        var $current_field              = ''; 
     
    5454                # setup handlers 
    5555                # 
    5656                xml_set_object( $this->parser, $this ); 
    57                 xml_set_element_handler($this->parser,  
     57                xml_set_element_handler($this->parser, 
    5858                                'feed_start_element', 'feed_end_element' ); 
    5959 
    60                 xml_set_character_data_handler( $this->parser, 'feed_cdata' );  
     60                xml_set_character_data_handler( $this->parser, 'feed_cdata' ); 
    6161 
    6262                $status = xml_parse( $this->parser, $source ); 
    6363 
     
    8585                // check for a namespace, and split if found 
    8686                $ns     = false; 
    8787                if ( strpos( $element, ':' ) ) { 
    88                         list($ns, $el) = split( ':', $element, 2);  
     88                        list($ns, $el) = split( ':', $element, 2); 
    8989                } 
    9090                if ( $ns and $ns != 'rdf' ) { 
    9191                        $this->current_namespace = $ns; 
     
    111111                        return; 
    112112                } 
    113113 
    114                 if ( $el == 'channel' )  
     114                if ( $el == 'channel' ) 
    115115                { 
    116116                        $this->inchannel = true; 
    117117                } 
    118                 elseif ($el == 'item' or $el == 'entry' )  
     118                elseif ($el == 'item' or $el == 'entry' ) 
    119119                { 
    120120                        $this->initem = true; 
    121121                        if ( isset($attrs['rdf:about']) ) { 
     
    125125 
    126126                // if we're in the default namespace of an RSS feed, 
    127127                //  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' ) 
    132132                { 
    133133                        $this->intextinput = true; 
    134134                } 
    135135 
    136136                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' ) 
    140140                { 
    141141                        $this->inimage = true; 
    142142                } 
     
    155155                } 
    156156 
    157157                // 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 ) 
    159159                { 
    160160                        // 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), 
    164164                                        array_values($attrs) ) ); 
    165165 
    166166                        $this->append_content( "<$element $attrs_str>"  ); 
     
    172172                // Magpie treats link elements of type rel='alternate' 
    173173                // as being equivalent to RSS's simple link element. 
    174174                // 
    175                 elseif ($this->feed_type == ATOM and $el == 'link' )  
     175                elseif ($this->feed_type == ATOM and $el == 'link' ) 
    176176                { 
    177                         if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' )  
     177                        if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) 
    178178                        { 
    179179                                $link_el = 'link'; 
    180180                        } 
     
    194194 
    195195        function feed_cdata ($p, $text) { 
    196196 
    197                 if ($this->feed_type == ATOM and $this->incontent)  
     197                if ($this->feed_type == ATOM and $this->incontent) 
    198198                { 
    199199                        $this->append_content( $text ); 
    200200                } 
     
    207207        function feed_end_element ($p, $el) { 
    208208                $el = strtolower($el); 
    209209 
    210                 if ( $el == 'item' or $el == 'entry' )  
     210                if ( $el == 'item' or $el == 'entry' ) 
    211211                { 
    212212                        $this->items[] = $this->current_item; 
    213213                        $this->current_item = array(); 
    214214                        $this->initem = false; 
    215215                } 
    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' ) 
    217217                { 
    218218                        $this->intextinput = false; 
    219219                } 
    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' ) 
    221221                { 
    222222                        $this->inimage = false; 
    223223                } 
     
    225225                { 
    226226                        $this->incontent = false; 
    227227                } 
    228                 elseif ($el == 'channel' or $el == 'feed' )  
     228                elseif ($el == 'channel' or $el == 'feed' ) 
    229229                { 
    230230                        $this->inchannel = false; 
    231231                } 
    232232                elseif ($this->feed_type == ATOM and $this->incontent  ) { 
    233233                        // balance tags properly 
    234234                        // note:  i don't think this is actually neccessary 
    235                         if ( $this->stack[0] == $el )  
     235                        if ( $this->stack[0] == $el ) 
    236236                        { 
    237237                                $this->append_content("</$el>"); 
    238238                        } 
     
    270270                if (!$el) { 
    271271                        return; 
    272272                } 
    273                 if ( $this->current_namespace )  
     273                if ( $this->current_namespace ) 
    274274                { 
    275275                        if ( $this->initem ) { 
    276276                                $this->concat( 
     
    395395                        // error("Failed to fetch $url and cache is off"); 
    396396                        return false; 
    397397                } 
    398         }  
     398        } 
    399399        // else cache is ON 
    400400        else { 
    401401                // Flow 
     
    472472                                if ( $resp->error ) { 
    473473                                        # compensate for Snoopy's annoying habbit to tacking 
    474474                                        # on '\n' 
    475                                         $http_error = substr($resp->error, 0, -2);  
     475                                        $http_error = substr($resp->error, 0, -2); 
    476476                                        $errormsg .= "(HTTP Error: $http_error)"; 
    477477                                } 
    478478                                else { 
     
    613613        } 
    614614} 
    615615 
    616 function is_info ($sc) {  
    617         return $sc >= 100 && $sc < 200;  
     616function is_info ($sc) { 
     617        return $sc >= 100 && $sc < 200; 
    618618} 
    619619 
    620 function is_success ($sc) {  
    621         return $sc >= 200 && $sc < 300;  
     620function is_success ($sc) { 
     621        return $sc >= 200 && $sc < 300; 
    622622} 
    623623 
    624 function is_redirect ($sc) {  
    625         return $sc >= 300 && $sc < 400;  
     624function is_redirect ($sc) { 
     625        return $sc >= 300 && $sc < 400; 
    626626} 
    627627 
    628 function is_error ($sc) {  
    629         return $sc >= 400 && $sc < 600;  
     628function is_error ($sc) { 
     629        return $sc >= 400 && $sc < 600; 
    630630} 
    631631 
    632 function is_client_error ($sc) {  
    633         return $sc >= 400 && $sc < 500;  
     632function is_client_error ($sc) { 
     633        return $sc >= 400 && $sc < 500; 
    634634} 
    635635 
    636 function is_server_error ($sc) {  
    637         return $sc >= 500 && $sc < 600;  
     636function is_server_error ($sc) { 
     637        return $sc >= 500 && $sc < 600; 
    638638} 
    639639 
    640640class RSSCache { 
     
    685685                $cache_option = 'rss_' . $this->file_name( $url ); 
    686686 
    687687                if ( ! get_option( $cache_option ) ) { 
    688                         $this->debug(  
     688                        $this->debug( 
    689689                                "Cache doesn't contain: $url (cache option: $cache_option)" 
    690690                        ); 
    691691                        return 0; 
     
    757757\*=======================================================================*/ 
    758758        function error ($errormsg, $lvl=E_USER_WARNING) { 
    759759                // append PHP's error message if track_errors enabled 
    760                 if ( isset($php_errormsg) ) {  
     760                if ( isset($php_errormsg) ) { 
    761761                        $errormsg .= " ($php_errormsg)"; 
    762762                } 
    763763                $this->ERROR = $errormsg; 
     
    781781        $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; 
    782782 
    783783        if ( preg_match( $pat, $date_str, $match ) ) { 
    784                 list( $year, $month, $day, $hours, $minutes, $seconds) =  
     784                list( $year, $month, $day, $hours, $minutes, $seconds) = 
    785785                        array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); 
    786786 
    787787                # calc epoch for current date assuming GMT 
  • wp-includes/script-loader.php

     
    6969                        } 
    7070                } 
    7171        } 
    72                                  
    7372 
     73 
    7474        /** 
    7575         * Determines dependencies of scripts 
    7676         * 
     
    155155                endswitch; 
    156156                return false; 
    157157        } 
    158                          
     158 
    159159} 
    160160 
    161161class _WP_Script { 
  • wp-includes/streams.php

     
    11<?php 
    22/* 
    3   Copyright (c) 2003, 2005 Danilo Segan <danilo@kvota.net>. 
     3        Copyright (c) 2003, 2005 Danilo Segan <danilo@kvota.net>. 
    44 
    5   This file is part of PHP-gettext. 
     5        This file is part of PHP-gettext. 
    66 
    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. 
     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. 
    1111 
    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. 
     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. 
    1616 
    17   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 
     17        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 
    2020 
    2121*/ 
    2222 
     
    2424// Simple class to wrap file streams, string streams, etc. 
    2525// seek is essential, and it should be byte stream 
    2626class 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 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   } 
     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        } 
    4646} 
    4747 
    4848class StringReader { 
    49   var $_pos; 
    50   var $_str; 
     49        var $_pos; 
     50        var $_str; 
    5151 
    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        } 
    5656 
    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); 
    6262 
    63     return $data; 
    64   } 
     63                return $data; 
     64        } 
    6565 
    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        } 
    7272 
    73   function currentpos() { 
    74     return $this->_pos; 
    75   } 
     73        function currentpos() { 
     74                return $this->_pos; 
     75        } 
    7676 
    77   function length() { 
    78     return strlen($this->_str); 
    79   } 
     77        function length() { 
     78                return strlen($this->_str); 
     79        } 
    8080 
    8181} 
    8282 
    8383 
    8484class FileReader { 
    85   var $_pos; 
    86   var $_fd; 
    87   var $_length; 
     85        var $_pos; 
     86        var $_fd; 
     87        var $_length; 
    8888 
    89   function FileReader($filename) { 
    90     if (file_exists($filename)) { 
     89        function FileReader($filename) { 
     90                if (file_exists($filename)) { 
    9191 
    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) { 
    9696        $this->error = 3; // Cannot read file, probably permissions 
    9797        return false; 
    98       } 
    99     } else { 
    100       $this->error = 2; // File doesn't exist 
    101       return false; 
    102     } 
    103   } 
     98                        } 
     99                } else { 
     100                        $this->error = 2; // File doesn't exist 
     101                        return false; 
     102                } 
     103        } 
    104104 
    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); 
    114110 
    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        } 
    120114 
    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        } 
    124120 
    125   function length() { 
    126     return $this->_length; 
    127   } 
     121        function currentpos() { 
     122                return $this->_pos; 
     123        } 
    128124 
    129   function close() { 
    130     fclose($this->_fd); 
    131   } 
     125        function length() { 
     126                return $this->_length; 
     127        } 
    132128 
     129        function close() { 
     130                fclose($this->_fd); 
     131        } 
     132 
    133133} 
    134134 
    135 // Preloads entire file in memory first, then creates a StringReader  
     135// Preloads entire file in memory first, then creates a StringReader 
    136136// over it (it assumes knowledge of StringReader internals) 
    137137class CachedFileReader extends StringReader { 
    138   function CachedFileReader($filename) { 
    139     if (file_exists($filename)) { 
     138        function CachedFileReader($filename) { 
     139                if (file_exists($filename)) { 
    140140 
    141       $length=filesize($filename); 
    142       $fd = fopen($filename,'rb'); 
     141                        $length=filesize($filename); 
     142                        $fd = fopen($filename,'rb'); 
    143143 
    144       if (!$fd) { 
     144                        if (!$fd) { 
    145145        $this->error = 3; // Cannot read file, probably permissions 
    146146        return false; 
    147       } 
    148       $this->_str = fread($fd, $length); 
    149       fclose($fd); 
     147                        } 
     148                        $this->_str = fread($fd, $length); 
     149                        fclose($fd); 
    150150 
    151     } else { 
    152       $this->error = 2; // File doesn't exist 
    153       return false; 
    154     } 
    155   } 
     151                } else { 
     152                        $this->error = 2; // File doesn't exist 
     153                        return false; 
     154                } 
     155        } 
    156156} 
    157157 
    158158 
  • wp-includes/theme.php

     
    11<?php 
    22/* 
    3  * Theme/template/stylesheet functions.   
     3 * Theme/template/stylesheet functions. 
    44 */ 
    55 
    66function get_stylesheet() { 
  • wp-includes/user.php

     
    150150 
    151151        if ( '' == $user_id ) 
    152152                $user = wp_get_current_user(); 
    153         else  
     153        else 
    154154                $user = new WP_User($user_id); 
    155155 
    156156        if ( 0 == $user->ID ) 
  • wp-includes/vars.php

     
    3434$is_apache = ( strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') || strstr($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') ) ? 1 : 0; 
    3535$is_IIS = strstr($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') ? 1 : 0; 
    3636 
    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 
    3838// by using $_SERVER['HTTP_PC_REMOTE_ADDR'], which *is* the remote address. 
    3939if ( isset($_SERVER['HTTP_PC_REMOTE_ADDR']) ) 
    4040        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_PC_REMOTE_ADDR']; 
  • wp-includes/wp-db.php

     
    9090        function print_error($str = '') { 
    9191                global $EZSQL_ERROR; 
    9292                if (!$str) $str = mysql_error(); 
    93                 $EZSQL_ERROR[] =  
     93                $EZSQL_ERROR[] = 
    9494                array ('query' => $this->last_query, 'error_str' => $str); 
    9595 
    9696                // Is error output turned on or not..