Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.8/wp-includes/classes.php

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