~katiekitty/+junk/wordpress-byet

« back to all changes in this revision

Viewing changes to wp-includes/classes.php

  • Committer: kserver
  • Date: 2010-05-15 01:16:36 UTC
  • Revision ID: kserver@kserver-desktop-20100515011636-mnr1j7t637suptdq
Wordpress 2.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
 
215
215
                                        // Trim the query of everything up to the '?'.
216
216
                                        $query = preg_replace("!^.+\?!", '', $query);
217
 
                                                                                
 
217
 
218
218
                                        // Substitute the substring matches into the query.
219
219
                                        $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
220
220
 
1594
1594
 
1595
1595
/**
1596
1596
 * Helper class to remove the need to use eval to replace $matches[] in query strings.
1597
 
 * 
 
1597
 *
1598
1598
 * @since 2.9.0
1599
1599
 */
1600
1600
class WP_MatchesMapRegex {
1601
1601
        /**
1602
1602
         * store for matches
1603
 
         * 
 
1603
         *
1604
1604
         * @access private
1605
1605
         * @var array
1606
1606
         */
1607
1607
        var $_matches;
1608
 
        
 
1608
 
1609
1609
        /**
1610
1610
         * store for mapping result
1611
 
         * 
 
1611
         *
1612
1612
         * @access public
1613
1613
         * @var string
1614
1614
         */
1615
1615
        var $output;
1616
 
        
 
1616
 
1617
1617
        /**
1618
1618
         * subject to perform mapping on (query string containing $matches[] references
1619
 
         * 
 
1619
         *
1620
1620
         * @access private
1621
1621
         * @var string
1622
1622
         */
1623
1623
        var $_subject;
1624
 
        
 
1624
 
1625
1625
        /**
1626
 
         * regexp pattern to match $matches[] references 
1627
 
         * 
 
1626
         * regexp pattern to match $matches[] references
 
1627
         *
1628
1628
         * @var string
1629
1629
         */
1630
1630
        var $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number
1631
 
        
 
1631
 
1632
1632
        /**
1633
1633
         * constructor
1634
 
         * 
 
1634
         *
1635
1635
         * @param string $subject subject if regex
1636
1636
         * @param array  $matches data to use in map
1637
1637
         * @return self
1638
 
         */                                             
 
1638
         */
1639
1639
        function WP_MatchesMapRegex($subject, $matches) {
1640
1640
                $this->_subject = $subject;
1641
1641
                $this->_matches = $matches;
1642
 
                $this->output = $this->_map();                          
 
1642
                $this->output = $this->_map();
1643
1643
        }
1644
 
        
 
1644
 
1645
1645
        /**
1646
1646
         * Substitute substring matches in subject.
1647
 
         * 
 
1647
         *
1648
1648
         * static helper function to ease use
1649
 
         * 
 
1649
         *
1650
1650
         * @access public
1651
1651
         * @param string $subject subject
1652
1652
         * @param array  $matches data used for subsitution
1654
1654
         */
1655
1655
        function apply($subject, $matches) {
1656
1656
                $oSelf =& new WP_MatchesMapRegex($subject, $matches);
1657
 
                return $oSelf->output;                                                                                                                          
 
1657
                return $oSelf->output;
1658
1658
        }
1659
 
        
 
1659
 
1660
1660
        /**
1661
 
         * do the actual mapping 
1662
 
         * 
 
1661
         * do the actual mapping
 
1662
         *
1663
1663
         * @access private
1664
1664
         * @return string
1665
1665
         */
1667
1667
                $callback = array(&$this, 'callback');
1668
1668
                return preg_replace_callback($this->_pattern, $callback, $this->_subject);
1669
1669
        }
1670
 
        
 
1670
 
1671
1671
        /**
1672
1672
         * preg_replace_callback hook
1673
 
         * 
 
1673
         *
1674
1674
         * @access public
1675
1675
         * @param  array $matches preg_replace regexp matches
1676
1676
         * @return string
1679
1679
                $index = intval(substr($matches[0], 9, -1));
1680
1680
                return ( isset( $this->_matches[$index] ) ? $this->_matches[$index] : '' );
1681
1681
        }
1682
 
        
 
1682
 
1683
1683
}
1684
1684
 
1685
1685
?>