@@ -49,6 +49,9 @@ discard block |
||
49 | 49 | */ |
50 | 50 | class SimplePie_Misc |
51 | 51 | { |
52 | + /** |
|
53 | + * @param integer $seconds |
|
54 | + */ |
|
52 | 55 | public static function time_hms($seconds) |
53 | 56 | { |
54 | 57 | $time = ''; |
@@ -329,6 +332,11 @@ discard block |
||
329 | 332 | } |
330 | 333 | } |
331 | 334 | |
335 | + /** |
|
336 | + * @param string $data |
|
337 | + * @param string $input |
|
338 | + * @param string $output |
|
339 | + */ |
|
332 | 340 | protected static function change_encoding_mbstring($data, $input, $output) |
333 | 341 | { |
334 | 342 | if ($input === 'windows-949') |
@@ -367,6 +375,11 @@ discard block |
||
367 | 375 | return false; |
368 | 376 | } |
369 | 377 | |
378 | + /** |
|
379 | + * @param string $data |
|
380 | + * @param string $input |
|
381 | + * @param string $output |
|
382 | + */ |
|
370 | 383 | protected static function change_encoding_iconv($data, $input, $output) |
371 | 384 | { |
372 | 385 | return @iconv($input, $output, $data); |
@@ -1696,6 +1709,9 @@ discard block |
||
1696 | 1709 | } |
1697 | 1710 | } |
1698 | 1711 | |
1712 | + /** |
|
1713 | + * @return string |
|
1714 | + */ |
|
1699 | 1715 | public static function get_curl_version() |
1700 | 1716 | { |
1701 | 1717 | if (is_array($curl = curl_version())) |
@@ -1763,7 +1779,6 @@ discard block |
||
1763 | 1779 | /** |
1764 | 1780 | * Remove RFC822 comments |
1765 | 1781 | * |
1766 | - * @param string $data Data to strip comments from |
|
1767 | 1782 | * @return string Comment stripped string |
1768 | 1783 | */ |
1769 | 1784 | public static function uncomment_rfc822($string) |
@@ -2019,7 +2034,7 @@ discard block |
||
2019 | 2034 | * @todo Add support for EBCDIC |
2020 | 2035 | * @param string $data XML data |
2021 | 2036 | * @param SimplePie_Registry $registry Class registry |
2022 | - * @return array Possible encodings |
|
2037 | + * @return string[] Possible encodings |
|
2023 | 2038 | */ |
2024 | 2039 | public static function xml_encoding($data, $registry) |
2025 | 2040 | { |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | $seconds = $remainder % 60; |
65 | 65 | if ($minutes < 10 && $hours > 0) |
66 | 66 | { |
67 | - $minutes = '0' . $minutes; |
|
67 | + $minutes = '0'.$minutes; |
|
68 | 68 | } |
69 | 69 | if ($seconds < 10) |
70 | 70 | { |
71 | - $seconds = '0' . $seconds; |
|
71 | + $seconds = '0'.$seconds; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $time .= $minutes.':'; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | $return = array(); |
101 | 101 | $name = preg_quote($realname, '/'); |
102 | - if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) |
|
102 | + if (preg_match_all("/<($name)".SIMPLEPIE_PCRE_HTML_ATTRIBUTE."(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) |
|
103 | 103 | { |
104 | 104 | for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++) |
105 | 105 | { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $return[$i]['content'] = $matches[$i][4][0]; |
117 | 117 | } |
118 | 118 | $return[$i]['attribs'] = array(); |
119 | - if (isset($matches[$i][2][0]) && preg_match_all('/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER)) |
|
119 | + if (isset($matches[$i][2][0]) && preg_match_all('/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/', ' '.$matches[$i][2][0].' ', $attribs, PREG_SET_ORDER)) |
|
120 | 120 | { |
121 | 121 | for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++) |
122 | 122 | { |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | foreach ($element['attribs'] as $key => $value) |
139 | 139 | { |
140 | 140 | $key = strtolower($key); |
141 | - $full .= " $key=\"" . htmlspecialchars($value['data']) . '"'; |
|
141 | + $full .= " $key=\"".htmlspecialchars($value['data']).'"'; |
|
142 | 142 | } |
143 | 143 | if ($element['self_closing']) |
144 | 144 | { |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | } |
173 | 173 | |
174 | 174 | $log_error = true; |
175 | - if (!function_exists('error_log')) |
|
175 | + if ( ! function_exists('error_log')) |
|
176 | 176 | { |
177 | 177 | $log_error = false; |
178 | 178 | } |
179 | 179 | |
180 | 180 | $log_file = @ini_get('error_log'); |
181 | - if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file)) |
|
181 | + if ( ! empty($log_file) && ('syslog' !== $log_file) && ! @is_writable($log_file)) |
|
182 | 182 | { |
183 | 183 | $log_error = false; |
184 | 184 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http); |
202 | 202 | } |
203 | 203 | |
204 | - if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url)) |
|
204 | + if ($parsed['scheme'] === '' && $parsed['authority'] === '' && ! file_exists($url)) |
|
205 | 205 | { |
206 | 206 | return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http); |
207 | 207 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | if ($input === 'US-ASCII') |
298 | 298 | { |
299 | 299 | static $non_ascii_octects = ''; |
300 | - if (!$non_ascii_octects) |
|
300 | + if ( ! $non_ascii_octects) |
|
301 | 301 | { |
302 | 302 | for ($i = 0x80; $i <= 0xFF; $i++) |
303 | 303 | { |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | { |
354 | 354 | return false; |
355 | 355 | } |
356 | - if (!in_array($input, mb_list_encodings())) |
|
356 | + if ( ! in_array($input, mb_list_encodings())) |
|
357 | 357 | { |
358 | 358 | return false; |
359 | 359 | } |
@@ -1738,7 +1738,7 @@ discard block |
||
1738 | 1738 | $data = ''; |
1739 | 1739 | } |
1740 | 1740 | } |
1741 | - return $output . $data; |
|
1741 | + return $output.$data; |
|
1742 | 1742 | } |
1743 | 1743 | |
1744 | 1744 | public static function parse_date($dt) |
@@ -1965,15 +1965,15 @@ discard block |
||
1965 | 1965 | } |
1966 | 1966 | else if ($codepoint <= 0x7ff) |
1967 | 1967 | { |
1968 | - return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f)); |
|
1968 | + return chr(0xc0 | ($codepoint >> 6)).chr(0x80 | ($codepoint & 0x3f)); |
|
1969 | 1969 | } |
1970 | 1970 | else if ($codepoint <= 0xffff) |
1971 | 1971 | { |
1972 | - return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f)); |
|
1972 | + return chr(0xe0 | ($codepoint >> 12)).chr(0x80 | (($codepoint >> 6) & 0x3f)).chr(0x80 | ($codepoint & 0x3f)); |
|
1973 | 1973 | } |
1974 | 1974 | else if ($codepoint <= 0x10ffff) |
1975 | 1975 | { |
1976 | - return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f)); |
|
1976 | + return chr(0xf0 | ($codepoint >> 18)).chr(0x80 | (($codepoint >> 12) & 0x3f)).chr(0x80 | (($codepoint >> 6) & 0x3f)).chr(0x80 | ($codepoint & 0x3f)); |
|
1977 | 1977 | } |
1978 | 1978 | else |
1979 | 1979 | { |
@@ -2129,7 +2129,7 @@ discard block |
||
2129 | 2129 | } |
2130 | 2130 | header('Content-type: text/javascript; charset: UTF-8'); |
2131 | 2131 | header('Cache-Control: must-revalidate'); |
2132 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days |
|
2132 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + 604800).' GMT'); // 7 days |
|
2133 | 2133 | ?> |
2134 | 2134 | function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) { |
2135 | 2135 | if (placeholder != '') { |
@@ -2163,14 +2163,14 @@ discard block |
||
2163 | 2163 | public static function get_build() |
2164 | 2164 | { |
2165 | 2165 | $root = dirname(dirname(__FILE__)); |
2166 | - if (file_exists($root . '/.git/index')) |
|
2166 | + if (file_exists($root.'/.git/index')) |
|
2167 | 2167 | { |
2168 | - return filemtime($root . '/.git/index'); |
|
2168 | + return filemtime($root.'/.git/index'); |
|
2169 | 2169 | } |
2170 | - elseif (file_exists($root . '/SimplePie')) |
|
2170 | + elseif (file_exists($root.'/SimplePie')) |
|
2171 | 2171 | { |
2172 | 2172 | $time = 0; |
2173 | - foreach (glob($root . '/SimplePie/*.php') as $file) |
|
2173 | + foreach (glob($root.'/SimplePie/*.php') as $file) |
|
2174 | 2174 | { |
2175 | 2175 | if (($mtime = filemtime($file)) > $time) |
2176 | 2176 | { |
@@ -2179,9 +2179,9 @@ discard block |
||
2179 | 2179 | } |
2180 | 2180 | return $time; |
2181 | 2181 | } |
2182 | - elseif (file_exists(dirname(__FILE__) . '/Core.php')) |
|
2182 | + elseif (file_exists(dirname(__FILE__).'/Core.php')) |
|
2183 | 2183 | { |
2184 | - return filemtime(dirname(__FILE__) . '/Core.php'); |
|
2184 | + return filemtime(dirname(__FILE__).'/Core.php'); |
|
2185 | 2185 | } |
2186 | 2186 | else |
2187 | 2187 | { |
@@ -2194,11 +2194,11 @@ discard block |
||
2194 | 2194 | */ |
2195 | 2195 | public static function debug(&$sp) |
2196 | 2196 | { |
2197 | - $info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n"; |
|
2198 | - $info .= 'PHP ' . PHP_VERSION . "\n"; |
|
2197 | + $info = 'SimplePie '.SIMPLEPIE_VERSION.' Build '.SIMPLEPIE_BUILD."\n"; |
|
2198 | + $info .= 'PHP '.PHP_VERSION."\n"; |
|
2199 | 2199 | if ($sp->error() !== null) |
2200 | 2200 | { |
2201 | - $info .= 'Error occurred: ' . $sp->error() . "\n"; |
|
2201 | + $info .= 'Error occurred: '.$sp->error()."\n"; |
|
2202 | 2202 | } |
2203 | 2203 | else |
2204 | 2204 | { |
@@ -2214,20 +2214,20 @@ discard block |
||
2214 | 2214 | switch ($ext) |
2215 | 2215 | { |
2216 | 2216 | case 'pcre': |
2217 | - $info .= ' Version ' . PCRE_VERSION . "\n"; |
|
2217 | + $info .= ' Version '.PCRE_VERSION."\n"; |
|
2218 | 2218 | break; |
2219 | 2219 | case 'curl': |
2220 | 2220 | $version = curl_version(); |
2221 | - $info .= ' Version ' . $version['version'] . "\n"; |
|
2221 | + $info .= ' Version '.$version['version']."\n"; |
|
2222 | 2222 | break; |
2223 | 2223 | case 'mbstring': |
2224 | - $info .= ' Overloading: ' . mb_get_info('func_overload') . "\n"; |
|
2224 | + $info .= ' Overloading: '.mb_get_info('func_overload')."\n"; |
|
2225 | 2225 | break; |
2226 | 2226 | case 'iconv': |
2227 | - $info .= ' Version ' . ICONV_VERSION . "\n"; |
|
2227 | + $info .= ' Version '.ICONV_VERSION."\n"; |
|
2228 | 2228 | break; |
2229 | 2229 | case 'xml': |
2230 | - $info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n"; |
|
2230 | + $info .= ' Version '.LIBXML_DOTTED_VERSION."\n"; |
|
2231 | 2231 | break; |
2232 | 2232 | } |
2233 | 2233 | } |
@@ -109,8 +109,7 @@ discard block |
||
109 | 109 | if (strlen($matches[$i][3][0]) <= 2) |
110 | 110 | { |
111 | 111 | $return[$i]['self_closing'] = true; |
112 | - } |
|
113 | - else |
|
112 | + } else |
|
114 | 113 | { |
115 | 114 | $return[$i]['self_closing'] = false; |
116 | 115 | $return[$i]['content'] = $matches[$i][4][0]; |
@@ -143,8 +142,7 @@ discard block |
||
143 | 142 | if ($element['self_closing']) |
144 | 143 | { |
145 | 144 | $full .= ' />'; |
146 | - } |
|
147 | - else |
|
145 | + } else |
|
148 | 146 | { |
149 | 147 | $full .= ">$element[content]</$element[tag]>"; |
150 | 148 | } |
@@ -209,16 +207,13 @@ discard block |
||
209 | 207 | if ($http === 2 && $parsed['scheme'] !== '') |
210 | 208 | { |
211 | 209 | return "feed:$url"; |
212 | - } |
|
213 | - elseif ($http === 3 && strtolower($parsed['scheme']) === 'http') |
|
210 | + } elseif ($http === 3 && strtolower($parsed['scheme']) === 'http') |
|
214 | 211 | { |
215 | 212 | return substr_replace($url, 'podcast', 0, 4); |
216 | - } |
|
217 | - elseif ($http === 4 && strtolower($parsed['scheme']) === 'http') |
|
213 | + } elseif ($http === 4 && strtolower($parsed['scheme']) === 'http') |
|
218 | 214 | { |
219 | 215 | return substr_replace($url, 'itpc', 0, 4); |
220 | - } |
|
221 | - else |
|
216 | + } else |
|
222 | 217 | { |
223 | 218 | return $url; |
224 | 219 | } |
@@ -259,8 +254,7 @@ discard block |
||
259 | 254 | if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E) |
260 | 255 | { |
261 | 256 | return chr($integer); |
262 | - } |
|
263 | - else |
|
257 | + } else |
|
264 | 258 | { |
265 | 259 | return strtoupper($match[0]); |
266 | 260 | } |
@@ -1701,16 +1695,13 @@ discard block |
||
1701 | 1695 | if (is_array($curl = curl_version())) |
1702 | 1696 | { |
1703 | 1697 | $curl = $curl['version']; |
1704 | - } |
|
1705 | - elseif (substr($curl, 0, 5) === 'curl/') |
|
1698 | + } elseif (substr($curl, 0, 5) === 'curl/') |
|
1706 | 1699 | { |
1707 | 1700 | $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5)); |
1708 | - } |
|
1709 | - elseif (substr($curl, 0, 8) === 'libcurl/') |
|
1701 | + } elseif (substr($curl, 0, 8) === 'libcurl/') |
|
1710 | 1702 | { |
1711 | 1703 | $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8)); |
1712 | - } |
|
1713 | - else |
|
1704 | + } else |
|
1714 | 1705 | { |
1715 | 1706 | $curl = 0; |
1716 | 1707 | } |
@@ -1732,8 +1723,7 @@ discard block |
||
1732 | 1723 | if (($end = strpos($data, '-->', $start)) !== false) |
1733 | 1724 | { |
1734 | 1725 | $data = substr_replace($data, '', 0, $end + 3); |
1735 | - } |
|
1736 | - else |
|
1726 | + } else |
|
1737 | 1727 | { |
1738 | 1728 | $data = ''; |
1739 | 1729 | } |
@@ -1789,8 +1779,7 @@ discard block |
||
1789 | 1779 | { |
1790 | 1780 | $position++; |
1791 | 1781 | continue; |
1792 | - } |
|
1793 | - elseif (isset($string[$position])) |
|
1782 | + } elseif (isset($string[$position])) |
|
1794 | 1783 | { |
1795 | 1784 | switch ($string[$position]) |
1796 | 1785 | { |
@@ -1803,14 +1792,12 @@ discard block |
||
1803 | 1792 | break; |
1804 | 1793 | } |
1805 | 1794 | $position++; |
1806 | - } |
|
1807 | - else |
|
1795 | + } else |
|
1808 | 1796 | { |
1809 | 1797 | break; |
1810 | 1798 | } |
1811 | 1799 | } |
1812 | - } |
|
1813 | - else |
|
1800 | + } else |
|
1814 | 1801 | { |
1815 | 1802 | $output .= '('; |
1816 | 1803 | } |
@@ -1825,8 +1812,7 @@ discard block |
||
1825 | 1812 | if (($pos = strpos($mime, ';')) === false) |
1826 | 1813 | { |
1827 | 1814 | return trim($mime); |
1828 | - } |
|
1829 | - else |
|
1815 | + } else |
|
1830 | 1816 | { |
1831 | 1817 | return trim(substr($mime, 0, $pos)); |
1832 | 1818 | } |
@@ -1837,8 +1823,7 @@ discard block |
||
1837 | 1823 | if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64')) |
1838 | 1824 | { |
1839 | 1825 | $mode = SIMPLEPIE_CONSTRUCT_BASE64; |
1840 | - } |
|
1841 | - else |
|
1826 | + } else |
|
1842 | 1827 | { |
1843 | 1828 | $mode = SIMPLEPIE_CONSTRUCT_NONE; |
1844 | 1829 | } |
@@ -1861,8 +1846,7 @@ discard block |
||
1861 | 1846 | default: |
1862 | 1847 | return SIMPLEPIE_CONSTRUCT_NONE | $mode; |
1863 | 1848 | } |
1864 | - } |
|
1865 | - else |
|
1849 | + } else |
|
1866 | 1850 | { |
1867 | 1851 | return SIMPLEPIE_CONSTRUCT_TEXT | $mode; |
1868 | 1852 | } |
@@ -1909,13 +1893,11 @@ discard block |
||
1909 | 1893 | if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/') |
1910 | 1894 | { |
1911 | 1895 | return SIMPLEPIE_CONSTRUCT_NONE; |
1912 | - } |
|
1913 | - else |
|
1896 | + } else |
|
1914 | 1897 | { |
1915 | 1898 | return SIMPLEPIE_CONSTRUCT_BASE64; |
1916 | 1899 | } |
1917 | - } |
|
1918 | - else |
|
1900 | + } else |
|
1919 | 1901 | { |
1920 | 1902 | return SIMPLEPIE_CONSTRUCT_TEXT; |
1921 | 1903 | } |
@@ -1958,24 +1940,19 @@ discard block |
||
1958 | 1940 | if ($codepoint < 0) |
1959 | 1941 | { |
1960 | 1942 | return false; |
1961 | - } |
|
1962 | - else if ($codepoint <= 0x7f) |
|
1943 | + } else if ($codepoint <= 0x7f) |
|
1963 | 1944 | { |
1964 | 1945 | return chr($codepoint); |
1965 | - } |
|
1966 | - else if ($codepoint <= 0x7ff) |
|
1946 | + } else if ($codepoint <= 0x7ff) |
|
1967 | 1947 | { |
1968 | 1948 | return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f)); |
1969 | - } |
|
1970 | - else if ($codepoint <= 0xffff) |
|
1949 | + } else if ($codepoint <= 0xffff) |
|
1971 | 1950 | { |
1972 | 1951 | return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f)); |
1973 | - } |
|
1974 | - else if ($codepoint <= 0x10ffff) |
|
1952 | + } else if ($codepoint <= 0x10ffff) |
|
1975 | 1953 | { |
1976 | 1954 | return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f)); |
1977 | - } |
|
1978 | - else |
|
1955 | + } else |
|
1979 | 1956 | { |
1980 | 1957 | // U+FFFD REPLACEMENT CHARACTER |
1981 | 1958 | return "\xEF\xBF\xBD"; |
@@ -2003,8 +1980,7 @@ discard block |
||
2003 | 1980 | { |
2004 | 1981 | list($name, $value) = explode('=', $section, 2); |
2005 | 1982 | $return[urldecode($name)][] = urldecode($value); |
2006 | - } |
|
2007 | - else |
|
1983 | + } else |
|
2008 | 1984 | { |
2009 | 1985 | $return[urldecode($section)][] = null; |
2010 | 1986 | } |
@@ -2166,8 +2142,7 @@ discard block |
||
2166 | 2142 | if (file_exists($root . '/.git/index')) |
2167 | 2143 | { |
2168 | 2144 | return filemtime($root . '/.git/index'); |
2169 | - } |
|
2170 | - elseif (file_exists($root . '/SimplePie')) |
|
2145 | + } elseif (file_exists($root . '/SimplePie')) |
|
2171 | 2146 | { |
2172 | 2147 | $time = 0; |
2173 | 2148 | foreach (glob($root . '/SimplePie/*.php') as $file) |
@@ -2178,12 +2153,10 @@ discard block |
||
2178 | 2153 | } |
2179 | 2154 | } |
2180 | 2155 | return $time; |
2181 | - } |
|
2182 | - elseif (file_exists(dirname(__FILE__) . '/Core.php')) |
|
2156 | + } elseif (file_exists(dirname(__FILE__) . '/Core.php')) |
|
2183 | 2157 | { |
2184 | 2158 | return filemtime(dirname(__FILE__) . '/Core.php'); |
2185 | - } |
|
2186 | - else |
|
2159 | + } else |
|
2187 | 2160 | { |
2188 | 2161 | return filemtime(__FILE__); |
2189 | 2162 | } |
@@ -2199,8 +2172,7 @@ discard block |
||
2199 | 2172 | if ($sp->error() !== null) |
2200 | 2173 | { |
2201 | 2174 | $info .= 'Error occurred: ' . $sp->error() . "\n"; |
2202 | - } |
|
2203 | - else |
|
2175 | + } else |
|
2204 | 2176 | { |
2205 | 2177 | $info .= "No error found.\n"; |
2206 | 2178 | } |
@@ -2230,8 +2202,7 @@ discard block |
||
2230 | 2202 | $info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n"; |
2231 | 2203 | break; |
2232 | 2204 | } |
2233 | - } |
|
2234 | - else |
|
2205 | + } else |
|
2235 | 2206 | { |
2236 | 2207 | $info .= " $ext not loaded\n"; |
2237 | 2208 | } |
@@ -190,7 +190,7 @@ |
||
190 | 190 | * 0:0:0:0:0:FFFF:129.144.52.38 |
191 | 191 | * |
192 | 192 | * @param string $ip An IPv6 address |
193 | - * @return array [0] contains the IPv6 represented part, and [1] the IPv4 represented part |
|
193 | + * @return string[] [0] contains the IPv6 represented part, and [1] the IPv4 represented part |
|
194 | 194 | */ |
195 | 195 | private static function split_v6_v4($ip) |
196 | 196 | { |
@@ -123,7 +123,7 @@ |
||
123 | 123 | // xxx::xxx |
124 | 124 | else |
125 | 125 | { |
126 | - $fill = ':' . str_repeat('0:', 6 - $c2 - $c1); |
|
126 | + $fill = ':'.str_repeat('0:', 6 - $c2 - $c1); |
|
127 | 127 | $ip = str_replace('::', $fill, $ip); |
128 | 128 | } |
129 | 129 | } |
@@ -86,16 +86,14 @@ discard block |
||
86 | 86 | if ($ip1 === '') |
87 | 87 | { |
88 | 88 | $c1 = -1; |
89 | - } |
|
90 | - else |
|
89 | + } else |
|
91 | 90 | { |
92 | 91 | $c1 = substr_count($ip1, ':'); |
93 | 92 | } |
94 | 93 | if ($ip2 === '') |
95 | 94 | { |
96 | 95 | $c2 = -1; |
97 | - } |
|
98 | - else |
|
96 | + } else |
|
99 | 97 | { |
100 | 98 | $c2 = substr_count($ip2, ':'); |
101 | 99 | } |
@@ -173,8 +171,7 @@ discard block |
||
173 | 171 | if ($ip_parts[1] !== '') |
174 | 172 | { |
175 | 173 | return implode(':', $ip_parts); |
176 | - } |
|
177 | - else |
|
174 | + } else |
|
178 | 175 | { |
179 | 176 | return $ip_parts[0]; |
180 | 177 | } |
@@ -200,8 +197,7 @@ discard block |
||
200 | 197 | $ipv6_part = substr($ip, 0, $pos); |
201 | 198 | $ipv4_part = substr($ip, $pos + 1); |
202 | 199 | return array($ipv6_part, $ipv4_part); |
203 | - } |
|
204 | - else |
|
200 | + } else |
|
205 | 201 | { |
206 | 202 | return array($ip, ''); |
207 | 203 | } |
@@ -226,35 +222,39 @@ discard block |
||
226 | 222 | foreach ($ipv6 as $ipv6_part) |
227 | 223 | { |
228 | 224 | // The section can't be empty |
229 | - if ($ipv6_part === '') |
|
230 | - return false; |
|
225 | + if ($ipv6_part === '') { |
|
226 | + return false; |
|
227 | + } |
|
231 | 228 | |
232 | 229 | // Nor can it be over four characters |
233 | - if (strlen($ipv6_part) > 4) |
|
234 | - return false; |
|
230 | + if (strlen($ipv6_part) > 4) { |
|
231 | + return false; |
|
232 | + } |
|
235 | 233 | |
236 | 234 | // Remove leading zeros (this is safe because of the above) |
237 | 235 | $ipv6_part = ltrim($ipv6_part, '0'); |
238 | - if ($ipv6_part === '') |
|
239 | - $ipv6_part = '0'; |
|
236 | + if ($ipv6_part === '') { |
|
237 | + $ipv6_part = '0'; |
|
238 | + } |
|
240 | 239 | |
241 | 240 | // Check the value is valid |
242 | 241 | $value = hexdec($ipv6_part); |
243 | - if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) |
|
244 | - return false; |
|
242 | + if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF) { |
|
243 | + return false; |
|
244 | + } |
|
245 | 245 | } |
246 | 246 | if (count($ipv4) === 4) |
247 | 247 | { |
248 | 248 | foreach ($ipv4 as $ipv4_part) |
249 | 249 | { |
250 | 250 | $value = (int) $ipv4_part; |
251 | - if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) |
|
252 | - return false; |
|
251 | + if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF) { |
|
252 | + return false; |
|
253 | + } |
|
253 | 254 | } |
254 | 255 | } |
255 | 256 | return true; |
256 | - } |
|
257 | - else |
|
257 | + } else |
|
258 | 258 | { |
259 | 259 | return false; |
260 | 260 | } |
@@ -704,7 +704,6 @@ |
||
704 | 704 | * Remove RFC822 comments |
705 | 705 | * |
706 | 706 | * @access protected |
707 | - * @param string $data Data to strip comments from |
|
708 | 707 | * @return string Comment stripped string |
709 | 708 | */ |
710 | 709 | public function remove_rfc2822_comments($string) |
@@ -541,11 +541,11 @@ discard block |
||
541 | 541 | */ |
542 | 542 | public function __construct() |
543 | 543 | { |
544 | - $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')'; |
|
545 | - $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')'; |
|
544 | + $this->day_pcre = '('.implode(array_keys($this->day), '|').')'; |
|
545 | + $this->month_pcre = '('.implode(array_keys($this->month), '|').')'; |
|
546 | 546 | |
547 | 547 | static $cache; |
548 | - if (!isset($cache[get_class($this)])) |
|
548 | + if ( ! isset($cache[get_class($this)])) |
|
549 | 549 | { |
550 | 550 | $all_methods = get_class_methods($this); |
551 | 551 | |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | public static function get() |
573 | 573 | { |
574 | 574 | static $object; |
575 | - if (!$object) |
|
575 | + if ( ! $object) |
|
576 | 576 | { |
577 | 577 | $object = new SimplePie_Parse_Date; |
578 | 578 | } |
@@ -638,13 +638,13 @@ discard block |
||
638 | 638 | public function date_w3cdtf($date) |
639 | 639 | { |
640 | 640 | static $pcre; |
641 | - if (!$pcre) |
|
641 | + if ( ! $pcre) |
|
642 | 642 | { |
643 | 643 | $year = '([0-9]{4})'; |
644 | 644 | $month = $day = $hour = $minute = $second = '([0-9]{2})'; |
645 | 645 | $decimal = '([0-9]*)'; |
646 | 646 | $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))'; |
647 | - $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/'; |
|
647 | + $pcre = '/^'.$year.'(?:-?'.$month.'(?:-?'.$day.'(?:[Tt\x09\x20]+'.$hour.'(?::?'.$minute.'(?::?'.$second.'(?:.'.$decimal.')?)?)?'.$zone.')?)?)?$/'; |
|
648 | 648 | } |
649 | 649 | if (preg_match($pcre, $date, $match)) |
650 | 650 | { |
@@ -770,11 +770,11 @@ discard block |
||
770 | 770 | public function date_rfc2822($date) |
771 | 771 | { |
772 | 772 | static $pcre; |
773 | - if (!$pcre) |
|
773 | + if ( ! $pcre) |
|
774 | 774 | { |
775 | 775 | $wsp = '[\x09\x20]'; |
776 | - $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)'; |
|
777 | - $optional_fws = $fws . '?'; |
|
776 | + $fws = '(?:'.$wsp.'+|'.$wsp.'*(?:\x0D\x0A'.$wsp.'+)+)'; |
|
777 | + $optional_fws = $fws.'?'; |
|
778 | 778 | $day_name = $this->day_pcre; |
779 | 779 | $month = $this->month_pcre; |
780 | 780 | $day = '([0-9]{1,2})'; |
@@ -782,8 +782,8 @@ discard block |
||
782 | 782 | $year = '([0-9]{2,4})'; |
783 | 783 | $num_zone = '([+\-])([0-9]{2})([0-9]{2})'; |
784 | 784 | $character_zone = '([A-Z]{1,5})'; |
785 | - $zone = '(?:' . $num_zone . '|' . $character_zone . ')'; |
|
786 | - $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i'; |
|
785 | + $zone = '(?:'.$num_zone.'|'.$character_zone.')'; |
|
786 | + $pcre = '/(?:'.$optional_fws.$day_name.$optional_fws.',)?'.$optional_fws.$day.$fws.$month.$fws.$year.$fws.$hour.$optional_fws.':'.$optional_fws.$minute.'(?:'.$optional_fws.':'.$optional_fws.$second.')?'.$fws.$zone.'/i'; |
|
787 | 787 | } |
788 | 788 | if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) |
789 | 789 | { |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | public function date_rfc850($date) |
864 | 864 | { |
865 | 865 | static $pcre; |
866 | - if (!$pcre) |
|
866 | + if ( ! $pcre) |
|
867 | 867 | { |
868 | 868 | $space = '[\x09\x20]+'; |
869 | 869 | $day_name = $this->day_pcre; |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | $day = '([0-9]{1,2})'; |
872 | 872 | $year = $hour = $minute = $second = '([0-9]{2})'; |
873 | 873 | $zone = '([A-Z]{1,5})'; |
874 | - $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i'; |
|
874 | + $pcre = '/^'.$day_name.','.$space.$day.'-'.$month.'-'.$year.$space.$hour.':'.$minute.':'.$second.$space.$zone.'$/i'; |
|
875 | 875 | } |
876 | 876 | if (preg_match($pcre, $date, $match)) |
877 | 877 | { |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | public function date_asctime($date) |
929 | 929 | { |
930 | 930 | static $pcre; |
931 | - if (!$pcre) |
|
931 | + if ( ! $pcre) |
|
932 | 932 | { |
933 | 933 | $space = '[\x09\x20]+'; |
934 | 934 | $wday_name = $this->day_pcre; |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | $hour = $sec = $min = '([0-9]{2})'; |
938 | 938 | $year = '([0-9]{4})'; |
939 | 939 | $terminator = '\x0A?\x00?'; |
940 | - $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i'; |
|
940 | + $pcre = '/^'.$wday_name.$space.$mon_name.$space.$day.$space.$hour.':'.$min.':'.$sec.$space.$year.$terminator.'$/i'; |
|
941 | 941 | } |
942 | 942 | if (preg_match($pcre, $date, $match)) |
943 | 943 | { |
@@ -620,8 +620,7 @@ discard block |
||
620 | 620 | if (is_callable($callback)) |
621 | 621 | { |
622 | 622 | $this->user[] = $callback; |
623 | - } |
|
624 | - else |
|
623 | + } else |
|
625 | 624 | { |
626 | 625 | trigger_error('User-supplied function must be a valid callback', E_USER_WARNING); |
627 | 626 | } |
@@ -683,8 +682,7 @@ discard block |
||
683 | 682 | { |
684 | 683 | $timezone = 0 - $timezone; |
685 | 684 | } |
686 | - } |
|
687 | - else |
|
685 | + } else |
|
688 | 686 | { |
689 | 687 | $timezone = 0; |
690 | 688 | } |
@@ -693,8 +691,7 @@ discard block |
||
693 | 691 | $second = round($match[6] + $match[7] / pow(10, strlen($match[7]))); |
694 | 692 | |
695 | 693 | return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; |
696 | - } |
|
697 | - else |
|
694 | + } else |
|
698 | 695 | { |
699 | 696 | return false; |
700 | 697 | } |
@@ -730,8 +727,7 @@ discard block |
||
730 | 727 | { |
731 | 728 | $position++; |
732 | 729 | continue; |
733 | - } |
|
734 | - elseif (isset($string[$position])) |
|
730 | + } elseif (isset($string[$position])) |
|
735 | 731 | { |
736 | 732 | switch ($string[$position]) |
737 | 733 | { |
@@ -744,14 +740,12 @@ discard block |
||
744 | 740 | break; |
745 | 741 | } |
746 | 742 | $position++; |
747 | - } |
|
748 | - else |
|
743 | + } else |
|
749 | 744 | { |
750 | 745 | break; |
751 | 746 | } |
752 | 747 | } |
753 | - } |
|
754 | - else |
|
748 | + } else |
|
755 | 749 | { |
756 | 750 | $output .= '('; |
757 | 751 | } |
@@ -830,8 +824,7 @@ discard block |
||
830 | 824 | if ($match[4] < 50) |
831 | 825 | { |
832 | 826 | $match[4] += 2000; |
833 | - } |
|
834 | - elseif ($match[4] < 1000) |
|
827 | + } elseif ($match[4] < 1000) |
|
835 | 828 | { |
836 | 829 | $match[4] += 1900; |
837 | 830 | } |
@@ -840,15 +833,13 @@ discard block |
||
840 | 833 | if ($match[7] !== '') |
841 | 834 | { |
842 | 835 | $second = $match[7]; |
843 | - } |
|
844 | - else |
|
836 | + } else |
|
845 | 837 | { |
846 | 838 | $second = 0; |
847 | 839 | } |
848 | 840 | |
849 | 841 | return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone; |
850 | - } |
|
851 | - else |
|
842 | + } else |
|
852 | 843 | { |
853 | 844 | return false; |
854 | 845 | } |
@@ -905,15 +896,13 @@ discard block |
||
905 | 896 | if ($match[4] < 50) |
906 | 897 | { |
907 | 898 | $match[4] += 2000; |
908 | - } |
|
909 | - else |
|
899 | + } else |
|
910 | 900 | { |
911 | 901 | $match[4] += 1900; |
912 | 902 | } |
913 | 903 | |
914 | 904 | return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone; |
915 | - } |
|
916 | - else |
|
905 | + } else |
|
917 | 906 | { |
918 | 907 | return false; |
919 | 908 | } |
@@ -954,8 +943,7 @@ discard block |
||
954 | 943 | |
955 | 944 | $month = $this->month[strtolower($match[2])]; |
956 | 945 | return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]); |
957 | - } |
|
958 | - else |
|
946 | + } else |
|
959 | 947 | { |
960 | 948 | return false; |
961 | 949 | } |
@@ -973,8 +961,7 @@ discard block |
||
973 | 961 | if ($strtotime === -1 || $strtotime === false) |
974 | 962 | { |
975 | 963 | return false; |
976 | - } |
|
977 | - else |
|
964 | + } else |
|
978 | 965 | { |
979 | 966 | return $strtotime; |
980 | 967 | } |
@@ -265,6 +265,9 @@ discard block |
||
265 | 265 | return $this->data; |
266 | 266 | } |
267 | 267 | |
268 | + /** |
|
269 | + * @param string $tag |
|
270 | + */ |
|
268 | 271 | public function tag_open($parser, $tag, $attributes) |
269 | 272 | { |
270 | 273 | list($this->namespace[], $this->element[]) = $this->split_ns($tag); |
@@ -332,6 +335,9 @@ discard block |
||
332 | 335 | } |
333 | 336 | } |
334 | 337 | |
338 | + /** |
|
339 | + * @param string $cdata |
|
340 | + */ |
|
335 | 341 | public function cdata($parser, $cdata) |
336 | 342 | { |
337 | 343 | if ($this->current_xhtml_construct >= 0) |
@@ -344,6 +350,9 @@ discard block |
||
344 | 350 | } |
345 | 351 | } |
346 | 352 | |
353 | + /** |
|
354 | + * @param string $tag |
|
355 | + */ |
|
347 | 356 | public function tag_close($parser, $tag) |
348 | 357 | { |
349 | 358 | if ($this->current_xhtml_construct >= 0) |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | if ($declaration->parse()) |
121 | 121 | { |
122 | 122 | $data = substr($data, $pos + 2); |
123 | - $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data; |
|
123 | + $data = '<?xml version="'.$declaration->version.'" encoding="'.$encoding.'" standalone="'.(($declaration->standalone) ? 'yes' : 'no').'"?>'.$data; |
|
124 | 124 | } |
125 | 125 | else |
126 | 126 | { |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | xml_set_element_handler($xml, 'tag_open', 'tag_close'); |
152 | 152 | |
153 | 153 | // Parse! |
154 | - if (!xml_parse($xml, $data, true)) |
|
154 | + if ( ! xml_parse($xml, $data, true)) |
|
155 | 155 | { |
156 | 156 | $this->error_code = xml_get_error_code($xml); |
157 | 157 | $this->error_string = xml_error_string($this->error_code); |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | case constant('XMLReader::END_ELEMENT'): |
177 | 177 | if ($xml->namespaceURI !== '') |
178 | 178 | { |
179 | - $tagName = $xml->namespaceURI . $this->separator . $xml->localName; |
|
179 | + $tagName = $xml->namespaceURI.$this->separator.$xml->localName; |
|
180 | 180 | } |
181 | 181 | else |
182 | 182 | { |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $empty = $xml->isEmptyElement; |
189 | 189 | if ($xml->namespaceURI !== '') |
190 | 190 | { |
191 | - $tagName = $xml->namespaceURI . $this->separator . $xml->localName; |
|
191 | + $tagName = $xml->namespaceURI.$this->separator.$xml->localName; |
|
192 | 192 | } |
193 | 193 | else |
194 | 194 | { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | { |
200 | 200 | if ($xml->namespaceURI !== '') |
201 | 201 | { |
202 | - $attrName = $xml->namespaceURI . $this->separator . $xml->localName; |
|
202 | + $attrName = $xml->namespaceURI.$this->separator.$xml->localName; |
|
203 | 203 | } |
204 | 204 | else |
205 | 205 | { |
@@ -305,12 +305,12 @@ discard block |
||
305 | 305 | $this->current_xhtml_construct++; |
306 | 306 | if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML) |
307 | 307 | { |
308 | - $this->data['data'] .= '<' . end($this->element); |
|
308 | + $this->data['data'] .= '<'.end($this->element); |
|
309 | 309 | if (isset($attribs[''])) |
310 | 310 | { |
311 | 311 | foreach ($attribs[''] as $name => $value) |
312 | 312 | { |
313 | - $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"'; |
|
313 | + $this->data['data'] .= ' '.$name.'="'.htmlspecialchars($value, ENT_COMPAT, $this->encoding).'"'; |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | $this->data['data'] .= '>'; |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | } |
319 | 319 | else |
320 | 320 | { |
321 | - $this->datas[] =& $this->data; |
|
322 | - $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][]; |
|
321 | + $this->datas[] = & $this->data; |
|
322 | + $this->data = & $this->data['child'][end($this->namespace)][end($this->element)][]; |
|
323 | 323 | $this->data = array('data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang)); |
324 | 324 | if ((end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_03 && in_array(end($this->element), array('title', 'tagline', 'copyright', 'info', 'summary', 'content')) && isset($attribs['']['mode']) && $attribs['']['mode'] === 'xml') |
325 | 325 | || (end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_10 && in_array(end($this->element), array('rights', 'subtitle', 'summary', 'info', 'title', 'content')) && isset($attribs['']['type']) && $attribs['']['type'] === 'xhtml') |
@@ -349,14 +349,14 @@ discard block |
||
349 | 349 | if ($this->current_xhtml_construct >= 0) |
350 | 350 | { |
351 | 351 | $this->current_xhtml_construct--; |
352 | - if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML && !in_array(end($this->element), array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param'))) |
|
352 | + if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML && ! in_array(end($this->element), array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param'))) |
|
353 | 353 | { |
354 | - $this->data['data'] .= '</' . end($this->element) . '>'; |
|
354 | + $this->data['data'] .= '</'.end($this->element).'>'; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | if ($this->current_xhtml_construct === -1) |
358 | 358 | { |
359 | - $this->data =& $this->datas[count($this->datas) - 1]; |
|
359 | + $this->data = & $this->datas[count($this->datas) - 1]; |
|
360 | 360 | array_pop($this->datas); |
361 | 361 | } |
362 | 362 | |
@@ -370,12 +370,12 @@ discard block |
||
370 | 370 | public function split_ns($string) |
371 | 371 | { |
372 | 372 | static $cache = array(); |
373 | - if (!isset($cache[$string])) |
|
373 | + if ( ! isset($cache[$string])) |
|
374 | 374 | { |
375 | 375 | if ($pos = strpos($string, $this->separator)) |
376 | 376 | { |
377 | 377 | static $separator_length; |
378 | - if (!$separator_length) |
|
378 | + if ( ! $separator_length) |
|
379 | 379 | { |
380 | 380 | $separator_length = strlen($this->separator); |
381 | 381 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 || |
392 | 392 | $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 || |
393 | 393 | $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 || |
394 | - $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 ) |
|
394 | + $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5) |
|
395 | 395 | { |
396 | 396 | $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS; |
397 | 397 | } |
@@ -81,8 +81,7 @@ discard block |
||
81 | 81 | if (strtoupper($encoding) === 'US-ASCII') |
82 | 82 | { |
83 | 83 | $this->encoding = 'UTF-8'; |
84 | - } |
|
85 | - else |
|
84 | + } else |
|
86 | 85 | { |
87 | 86 | $this->encoding = $encoding; |
88 | 87 | } |
@@ -121,8 +120,7 @@ discard block |
||
121 | 120 | { |
122 | 121 | $data = substr($data, $pos + 2); |
123 | 122 | $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data; |
124 | - } |
|
125 | - else |
|
123 | + } else |
|
126 | 124 | { |
127 | 125 | $this->error_string = 'SimplePie bug! Please report this!'; |
128 | 126 | return false; |
@@ -162,8 +160,7 @@ discard block |
||
162 | 160 | $this->current_byte = xml_get_current_byte_index($xml); |
163 | 161 | xml_parser_free($xml); |
164 | 162 | return $return; |
165 | - } |
|
166 | - else |
|
163 | + } else |
|
167 | 164 | { |
168 | 165 | libxml_clear_errors(); |
169 | 166 | $xml = new XMLReader(); |
@@ -177,8 +174,7 @@ discard block |
||
177 | 174 | if ($xml->namespaceURI !== '') |
178 | 175 | { |
179 | 176 | $tagName = $xml->namespaceURI . $this->separator . $xml->localName; |
180 | - } |
|
181 | - else |
|
177 | + } else |
|
182 | 178 | { |
183 | 179 | $tagName = $xml->localName; |
184 | 180 | } |
@@ -189,8 +185,7 @@ discard block |
||
189 | 185 | if ($xml->namespaceURI !== '') |
190 | 186 | { |
191 | 187 | $tagName = $xml->namespaceURI . $this->separator . $xml->localName; |
192 | - } |
|
193 | - else |
|
188 | + } else |
|
194 | 189 | { |
195 | 190 | $tagName = $xml->localName; |
196 | 191 | } |
@@ -200,8 +195,7 @@ discard block |
||
200 | 195 | if ($xml->namespaceURI !== '') |
201 | 196 | { |
202 | 197 | $attrName = $xml->namespaceURI . $this->separator . $xml->localName; |
203 | - } |
|
204 | - else |
|
198 | + } else |
|
205 | 199 | { |
206 | 200 | $attrName = $xml->localName; |
207 | 201 | } |
@@ -227,8 +221,7 @@ discard block |
||
227 | 221 | $this->current_line = $error->line; |
228 | 222 | $this->current_column = $error->column; |
229 | 223 | return false; |
230 | - } |
|
231 | - else |
|
224 | + } else |
|
232 | 225 | { |
233 | 226 | return true; |
234 | 227 | } |
@@ -284,8 +277,7 @@ discard block |
||
284 | 277 | $this->xml_base[] = $base; |
285 | 278 | $this->xml_base_explicit[] = true; |
286 | 279 | } |
287 | - } |
|
288 | - else |
|
280 | + } else |
|
289 | 281 | { |
290 | 282 | $this->xml_base[] = end($this->xml_base); |
291 | 283 | $this->xml_base_explicit[] = end($this->xml_base_explicit); |
@@ -294,8 +286,7 @@ discard block |
||
294 | 286 | if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang'])) |
295 | 287 | { |
296 | 288 | $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang']; |
297 | - } |
|
298 | - else |
|
289 | + } else |
|
299 | 290 | { |
300 | 291 | $this->xml_lang[] = end($this->xml_lang); |
301 | 292 | } |
@@ -315,8 +306,7 @@ discard block |
||
315 | 306 | } |
316 | 307 | $this->data['data'] .= '>'; |
317 | 308 | } |
318 | - } |
|
319 | - else |
|
309 | + } else |
|
320 | 310 | { |
321 | 311 | $this->datas[] =& $this->data; |
322 | 312 | $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][]; |
@@ -337,8 +327,7 @@ discard block |
||
337 | 327 | if ($this->current_xhtml_construct >= 0) |
338 | 328 | { |
339 | 329 | $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding); |
340 | - } |
|
341 | - else |
|
330 | + } else |
|
342 | 331 | { |
343 | 332 | $this->data['data'] .= $cdata; |
344 | 333 | } |
@@ -396,8 +385,7 @@ discard block |
||
396 | 385 | $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS; |
397 | 386 | } |
398 | 387 | $cache[$string] = array($namespace, $local_name); |
399 | - } |
|
400 | - else |
|
388 | + } else |
|
401 | 389 | { |
402 | 390 | $cache[$string] = array('', $string); |
403 | 391 | } |
@@ -222,6 +222,9 @@ discard block |
||
222 | 222 | $this->replace_url_attributes = (array) $element_attribute; |
223 | 223 | } |
224 | 224 | |
225 | + /** |
|
226 | + * @param string $data |
|
227 | + */ |
|
225 | 228 | public function sanitize($data, $type, $base = '') |
226 | 229 | { |
227 | 230 | $data = trim($data); |
@@ -381,6 +384,9 @@ discard block |
||
381 | 384 | return $data; |
382 | 385 | } |
383 | 386 | |
387 | + /** |
|
388 | + * @param string $html |
|
389 | + */ |
|
384 | 390 | protected function preprocess($html, $type) |
385 | 391 | { |
386 | 392 | $ret = ''; |
@@ -404,6 +410,9 @@ discard block |
||
404 | 410 | return $ret; |
405 | 411 | } |
406 | 412 | |
413 | + /** |
|
414 | + * @param DOMDocument $document |
|
415 | + */ |
|
407 | 416 | public function replace_urls($document, $tag, $attributes) |
408 | 417 | { |
409 | 418 | if (!is_array($attributes)) |
@@ -456,6 +465,9 @@ discard block |
||
456 | 465 | } |
457 | 466 | } |
458 | 467 | |
468 | + /** |
|
469 | + * @param DOMDocument $document |
|
470 | + */ |
|
459 | 471 | protected function strip_tag($tag, $document, $type) |
460 | 472 | { |
461 | 473 | $xpath = new DOMXPath($document); |
@@ -541,6 +553,9 @@ discard block |
||
541 | 553 | } |
542 | 554 | } |
543 | 555 | |
556 | + /** |
|
557 | + * @param DOMDocument $document |
|
558 | + */ |
|
544 | 559 | protected function strip_attr($attrib, $document) |
545 | 560 | { |
546 | 561 | $xpath = new DOMXPath($document); |
@@ -1,46 +1,46 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * SimplePie |
|
4 | - * |
|
5 | - * A PHP-Based RSS and Atom Feed Framework. |
|
6 | - * Takes the hard work out of managing a complete RSS/Atom solution. |
|
7 | - * |
|
8 | - * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors |
|
9 | - * All rights reserved. |
|
10 | - * |
|
11 | - * Redistribution and use in source and binary forms, with or without modification, are |
|
12 | - * permitted provided that the following conditions are met: |
|
13 | - * |
|
14 | - * * Redistributions of source code must retain the above copyright notice, this list of |
|
15 | - * conditions and the following disclaimer. |
|
16 | - * |
|
17 | - * * Redistributions in binary form must reproduce the above copyright notice, this list |
|
18 | - * of conditions and the following disclaimer in the documentation and/or other materials |
|
19 | - * provided with the distribution. |
|
20 | - * |
|
21 | - * * Neither the name of the SimplePie Team nor the names of its contributors may be used |
|
22 | - * to endorse or promote products derived from this software without specific prior |
|
23 | - * written permission. |
|
24 | - * |
|
25 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS |
|
26 | - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
27 | - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS |
|
28 | - * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
29 | - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
30 | - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
31 | - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
32 | - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
33 | - * POSSIBILITY OF SUCH DAMAGE. |
|
34 | - * |
|
35 | - * @package SimplePie |
|
36 | - * @version 1.3.1 |
|
37 | - * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue |
|
38 | - * @author Ryan Parman |
|
39 | - * @author Geoffrey Sneddon |
|
40 | - * @author Ryan McCue |
|
41 | - * @link http://simplepie.org/ SimplePie |
|
42 | - * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
43 | - */ |
|
3 | + * SimplePie |
|
4 | + * |
|
5 | + * A PHP-Based RSS and Atom Feed Framework. |
|
6 | + * Takes the hard work out of managing a complete RSS/Atom solution. |
|
7 | + * |
|
8 | + * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors |
|
9 | + * All rights reserved. |
|
10 | + * |
|
11 | + * Redistribution and use in source and binary forms, with or without modification, are |
|
12 | + * permitted provided that the following conditions are met: |
|
13 | + * |
|
14 | + * * Redistributions of source code must retain the above copyright notice, this list of |
|
15 | + * conditions and the following disclaimer. |
|
16 | + * |
|
17 | + * * Redistributions in binary form must reproduce the above copyright notice, this list |
|
18 | + * of conditions and the following disclaimer in the documentation and/or other materials |
|
19 | + * provided with the distribution. |
|
20 | + * |
|
21 | + * * Neither the name of the SimplePie Team nor the names of its contributors may be used |
|
22 | + * to endorse or promote products derived from this software without specific prior |
|
23 | + * written permission. |
|
24 | + * |
|
25 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS |
|
26 | + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
27 | + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS |
|
28 | + * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
29 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
30 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
31 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
32 | + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
33 | + * POSSIBILITY OF SUCH DAMAGE. |
|
34 | + * |
|
35 | + * @package SimplePie |
|
36 | + * @version 1.3.1 |
|
37 | + * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue |
|
38 | + * @author Ryan Parman |
|
39 | + * @author Geoffrey Sneddon |
|
40 | + * @author Ryan McCue |
|
41 | + * @link http://simplepie.org/ SimplePie |
|
42 | + * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
43 | + */ |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Used for data cleanup and post-processing |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | { |
230 | 230 | if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML) |
231 | 231 | { |
232 | - if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) |
|
232 | + if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*'.SIMPLEPIE_PCRE_HTML_ATTRIBUTE.'>)/', $data)) |
|
233 | 233 | { |
234 | 234 | $type |= SIMPLEPIE_CONSTRUCT_HTML; |
235 | 235 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML)) |
248 | 248 | { |
249 | 249 | |
250 | - if (!class_exists('DOMDocument')) |
|
250 | + if ( ! class_exists('DOMDocument')) |
|
251 | 251 | { |
252 | 252 | $this->registry->call('Misc', 'error', array('DOMDocument not found, unable to use sanitizer', E_USER_WARNING, __FILE__, __LINE__)); |
253 | 253 | return ''; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | |
312 | 312 | if ($cache->load()) |
313 | 313 | { |
314 | - $img->setAttribute('src', $this->image_handler . $image_url); |
|
314 | + $img->setAttribute('src', $this->image_handler.$image_url); |
|
315 | 315 | } |
316 | 316 | else |
317 | 317 | { |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | { |
323 | 323 | if ($cache->save(array('headers' => $file->headers, 'body' => $file->body))) |
324 | 324 | { |
325 | - $img->setAttribute('src', $this->image_handler . $image_url); |
|
325 | + $img->setAttribute('src', $this->image_handler.$image_url); |
|
326 | 326 | } |
327 | 327 | else |
328 | 328 | { |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | |
351 | 351 | if ($this->remove_div) |
352 | 352 | { |
353 | - $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data); |
|
353 | + $data = preg_replace('/^<div'.SIMPLEPIE_PCRE_XML_ATTRIBUTE.'>/', '', $data); |
|
354 | 354 | $data = preg_replace('/<\/div>$/', '', $data); |
355 | 355 | } |
356 | 356 | else |
357 | 357 | { |
358 | - $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data); |
|
358 | + $data = preg_replace('/^<div'.SIMPLEPIE_PCRE_XML_ATTRIBUTE.'>/', '<div>', $data); |
|
359 | 359 | } |
360 | 360 | } |
361 | 361 | |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | { |
389 | 389 | // Atom XHTML constructs are wrapped with a div by default |
390 | 390 | // Note: No protection if $html contains a stray </div>! |
391 | - $html = '<div>' . $html . '</div>'; |
|
391 | + $html = '<div>'.$html.'</div>'; |
|
392 | 392 | $ret .= '<!DOCTYPE html>'; |
393 | 393 | $content_type = 'text/html'; |
394 | 394 | } |
@@ -399,19 +399,19 @@ discard block |
||
399 | 399 | } |
400 | 400 | |
401 | 401 | $ret .= '<html><head>'; |
402 | - $ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />'; |
|
403 | - $ret .= '</head><body>' . $html . '</body></html>'; |
|
402 | + $ret .= '<meta http-equiv="Content-Type" content="'.$content_type.'; charset=utf-8" />'; |
|
403 | + $ret .= '</head><body>'.$html.'</body></html>'; |
|
404 | 404 | return $ret; |
405 | 405 | } |
406 | 406 | |
407 | 407 | public function replace_urls($document, $tag, $attributes) |
408 | 408 | { |
409 | - if (!is_array($attributes)) |
|
409 | + if ( ! is_array($attributes)) |
|
410 | 410 | { |
411 | 411 | $attributes = array($attributes); |
412 | 412 | } |
413 | 413 | |
414 | - if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags)) |
|
414 | + if ( ! is_array($this->strip_htmltags) || ! in_array($tag, $this->strip_htmltags)) |
|
415 | 415 | { |
416 | 416 | $elements = $document->getElementsByTagName($tag); |
417 | 417 | foreach ($elements as $element) |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | { |
436 | 436 | if ($this->encode_instead_of_strip) |
437 | 437 | { |
438 | - if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) |
|
438 | + if (isset($match[4]) && ! in_array(strtolower($match[1]), array('script', 'style'))) |
|
439 | 439 | { |
440 | 440 | $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8'); |
441 | 441 | $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8'); |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8'); |
447 | 447 | } |
448 | 448 | } |
449 | - elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) |
|
449 | + elseif (isset($match[4]) && ! in_array(strtolower($match[1]), array('script', 'style'))) |
|
450 | 450 | { |
451 | 451 | return $match[4]; |
452 | 452 | } |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | protected function strip_tag($tag, $document, $type) |
460 | 460 | { |
461 | 461 | $xpath = new DOMXPath($document); |
462 | - $elements = $xpath->query('body//' . $tag); |
|
462 | + $elements = $xpath->query('body//'.$tag); |
|
463 | 463 | if ($this->encode_instead_of_strip) |
464 | 464 | { |
465 | 465 | foreach ($elements as $element) |
@@ -467,9 +467,9 @@ discard block |
||
467 | 467 | $fragment = $document->createDocumentFragment(); |
468 | 468 | |
469 | 469 | // For elements which aren't script or style, include the tag itself |
470 | - if (!in_array($tag, array('script', 'style'))) |
|
470 | + if ( ! in_array($tag, array('script', 'style'))) |
|
471 | 471 | { |
472 | - $text = '<' . $tag; |
|
472 | + $text = '<'.$tag; |
|
473 | 473 | if ($element->hasAttributes()) |
474 | 474 | { |
475 | 475 | $attrs = array(); |
@@ -490,9 +490,9 @@ discard block |
||
490 | 490 | } |
491 | 491 | |
492 | 492 | // Standard attribute text |
493 | - $attrs[] = $name . '="' . $attr->value . '"'; |
|
493 | + $attrs[] = $name.'="'.$attr->value.'"'; |
|
494 | 494 | } |
495 | - $text .= ' ' . implode(' ', $attrs); |
|
495 | + $text .= ' '.implode(' ', $attrs); |
|
496 | 496 | } |
497 | 497 | $text .= '>'; |
498 | 498 | $fragment->appendChild(new DOMText($text)); |
@@ -505,9 +505,9 @@ discard block |
||
505 | 505 | $fragment->appendChild($child); |
506 | 506 | } |
507 | 507 | |
508 | - if (!in_array($tag, array('script', 'style'))) |
|
508 | + if ( ! in_array($tag, array('script', 'style'))) |
|
509 | 509 | { |
510 | - $fragment->appendChild(new DOMText('</' . $tag . '>')); |
|
510 | + $fragment->appendChild(new DOMText('</'.$tag.'>')); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | $element->parentNode->replaceChild($fragment, $element); |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | protected function strip_attr($attrib, $document) |
545 | 545 | { |
546 | 546 | $xpath = new DOMXPath($document); |
547 | - $elements = $xpath->query('//*[@' . $attrib . ']'); |
|
547 | + $elements = $xpath->query('//*[@'.$attrib.']'); |
|
548 | 548 | |
549 | 549 | foreach ($elements as $element) |
550 | 550 | { |
@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | if ($page) |
89 | 89 | { |
90 | 90 | $this->image_handler = (string) $page; |
91 | - } |
|
92 | - else |
|
91 | + } else |
|
93 | 92 | { |
94 | 93 | $this->image_handler = false; |
95 | 94 | } |
@@ -143,13 +142,11 @@ discard block |
||
143 | 142 | if (is_array($tags)) |
144 | 143 | { |
145 | 144 | $this->strip_htmltags = $tags; |
146 | - } |
|
147 | - else |
|
145 | + } else |
|
148 | 146 | { |
149 | 147 | $this->strip_htmltags = explode(',', $tags); |
150 | 148 | } |
151 | - } |
|
152 | - else |
|
149 | + } else |
|
153 | 150 | { |
154 | 151 | $this->strip_htmltags = false; |
155 | 152 | } |
@@ -167,13 +164,11 @@ discard block |
||
167 | 164 | if (is_array($attribs)) |
168 | 165 | { |
169 | 166 | $this->strip_attributes = $attribs; |
170 | - } |
|
171 | - else |
|
167 | + } else |
|
172 | 168 | { |
173 | 169 | $this->strip_attributes = explode(',', $attribs); |
174 | 170 | } |
175 | - } |
|
176 | - else |
|
171 | + } else |
|
177 | 172 | { |
178 | 173 | $this->strip_attributes = false; |
179 | 174 | } |
@@ -232,8 +227,7 @@ discard block |
||
232 | 227 | if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data)) |
233 | 228 | { |
234 | 229 | $type |= SIMPLEPIE_CONSTRUCT_HTML; |
235 | - } |
|
236 | - else |
|
230 | + } else |
|
237 | 231 | { |
238 | 232 | $type |= SIMPLEPIE_CONSTRUCT_TEXT; |
239 | 233 | } |
@@ -312,8 +306,7 @@ discard block |
||
312 | 306 | if ($cache->load()) |
313 | 307 | { |
314 | 308 | $img->setAttribute('src', $this->image_handler . $image_url); |
315 | - } |
|
316 | - else |
|
309 | + } else |
|
317 | 310 | { |
318 | 311 | $file = $this->registry->create('File', array($img->getAttribute('src'), $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen)); |
319 | 312 | $headers = $file->headers; |
@@ -323,8 +316,7 @@ discard block |
||
323 | 316 | if ($cache->save(array('headers' => $file->headers, 'body' => $file->body))) |
324 | 317 | { |
325 | 318 | $img->setAttribute('src', $this->image_handler . $image_url); |
326 | - } |
|
327 | - else |
|
319 | + } else |
|
328 | 320 | { |
329 | 321 | trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); |
330 | 322 | } |
@@ -352,8 +344,7 @@ discard block |
||
352 | 344 | { |
353 | 345 | $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data); |
354 | 346 | $data = preg_replace('/<\/div>$/', '', $data); |
355 | - } |
|
356 | - else |
|
347 | + } else |
|
357 | 348 | { |
358 | 349 | $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data); |
359 | 350 | } |
@@ -391,8 +382,7 @@ discard block |
||
391 | 382 | $html = '<div>' . $html . '</div>'; |
392 | 383 | $ret .= '<!DOCTYPE html>'; |
393 | 384 | $content_type = 'text/html'; |
394 | - } |
|
395 | - else |
|
385 | + } else |
|
396 | 386 | { |
397 | 387 | $ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; |
398 | 388 | $content_type = 'application/xhtml+xml'; |
@@ -440,17 +430,14 @@ discard block |
||
440 | 430 | $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8'); |
441 | 431 | $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8'); |
442 | 432 | return "<$match[1]$match[2]>$match[3]</$match[1]>"; |
443 | - } |
|
444 | - else |
|
433 | + } else |
|
445 | 434 | { |
446 | 435 | return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8'); |
447 | 436 | } |
448 | - } |
|
449 | - elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) |
|
437 | + } elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style'))) |
|
450 | 438 | { |
451 | 439 | return $match[4]; |
452 | - } |
|
453 | - else |
|
440 | + } else |
|
454 | 441 | { |
455 | 442 | return ''; |
456 | 443 | } |
@@ -514,8 +501,7 @@ discard block |
||
514 | 501 | } |
515 | 502 | |
516 | 503 | return; |
517 | - } |
|
518 | - elseif (in_array($tag, array('script', 'style'))) |
|
504 | + } elseif (in_array($tag, array('script', 'style'))) |
|
519 | 505 | { |
520 | 506 | foreach ($elements as $element) |
521 | 507 | { |
@@ -523,8 +509,7 @@ discard block |
||
523 | 509 | } |
524 | 510 | |
525 | 511 | return; |
526 | - } |
|
527 | - else |
|
512 | + } else |
|
528 | 513 | { |
529 | 514 | foreach ($elements as $element) |
530 | 515 | { |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | * @global WP $wp WP instance. |
329 | 329 | * |
330 | 330 | * @param string $taxonomy Taxonomy key, must not exceed 32 characters. |
331 | - * @param array|string $object_type Name of the object type for the taxonomy object. |
|
331 | + * @param string $object_type Name of the object type for the taxonomy object. |
|
332 | 332 | * @param array|string $args See optional args description above. |
333 | 333 | * @return WP_Error|void WP_Error, if errors. |
334 | 334 | */ |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * @global wpdb $wpdb WordPress database abstraction object. |
599 | 599 | * |
600 | 600 | * @param int|array $term_ids Term id or array of term ids of terms that will be used. |
601 | - * @param string|array $taxonomies String of taxonomy name or Array of string values of taxonomy names. |
|
601 | + * @param string $taxonomies String of taxonomy name or Array of string values of taxonomy names. |
|
602 | 602 | * @param array|string $args Change the order of the object_ids, either ASC or DESC. |
603 | 603 | * @return WP_Error|array If the taxonomy does not exist, then WP_Error will be returned. On success. |
604 | 604 | * the array can be empty meaning that there are no $object_ids found or it will return the $object_ids found. |
@@ -3730,7 +3730,7 @@ discard block |
||
3730 | 3730 | * |
3731 | 3731 | * @param array $terms The term_taxonomy_id of terms to update. |
3732 | 3732 | * @param string $taxonomy The context of the term. |
3733 | - * @return true Always true when complete. |
|
3733 | + * @return boolean Always true when complete. |
|
3734 | 3734 | */ |
3735 | 3735 | function wp_update_term_count_now( $terms, $taxonomy ) { |
3736 | 3736 | $terms = array_map('intval', $terms); |
@@ -4714,7 +4714,7 @@ discard block |
||
4714 | 4714 | * |
4715 | 4715 | * @since 2.5.0 |
4716 | 4716 | * |
4717 | - * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
|
4717 | + * @param integer $post Optional. Post ID or WP_Post object. Default is global $post. |
|
4718 | 4718 | * @param array $args { |
4719 | 4719 | * Optional. Arguments about how to format the list of taxonomies. Default empty array. |
4720 | 4720 | * |
@@ -4776,7 +4776,7 @@ discard block |
||
4776 | 4776 | * |
4777 | 4777 | * @since 2.5.0 |
4778 | 4778 | * |
4779 | - * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
|
4779 | + * @param integer $post Optional. Post ID or WP_Post object. Default is global $post. |
|
4780 | 4780 | * @return array |
4781 | 4781 | */ |
4782 | 4782 | function get_post_taxonomies( $post = 0 ) { |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Taxonomy API |
|
4 | - * |
|
5 | - * @since 2.3.0 |
|
6 | - * |
|
7 | - * @package WordPress |
|
8 | - * @subpackage Taxonomy |
|
9 | - */ |
|
3 | + * Taxonomy API |
|
4 | + * |
|
5 | + * @since 2.3.0 |
|
6 | + * |
|
7 | + * @package WordPress |
|
8 | + * @subpackage Taxonomy |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | // |
12 | 12 | // Taxonomy Registration |
@@ -2856,7 +2856,6 @@ discard block |
||
2856 | 2856 | * |
2857 | 2857 | * If the taxonomy is hierarchical, and the 'parent' argument is not empty, |
2858 | 2858 | * the term is inserted and the term_id will be given. |
2859 | - |
|
2860 | 2859 | * Error handling: |
2861 | 2860 | * If $taxonomy does not exist or $term is empty, |
2862 | 2861 | * a WP_Error object will be returned. |
@@ -2865,7 +2864,6 @@ discard block |
||
2865 | 2864 | * or the term slug and name are not unique, a WP_Error object will be returned. |
2866 | 2865 | * |
2867 | 2866 | * @global wpdb $wpdb WordPress database abstraction object. |
2868 | - |
|
2869 | 2867 | * @since 2.3.0 |
2870 | 2868 | * |
2871 | 2869 | * @param string $term The term to add or update. |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | function create_initial_taxonomies() { |
27 | 27 | global $wp_rewrite; |
28 | 28 | |
29 | - if ( ! did_action( 'init' ) ) { |
|
30 | - $rewrite = array( 'category' => false, 'post_tag' => false, 'post_format' => false ); |
|
29 | + if ( ! did_action('init')) { |
|
30 | + $rewrite = array('category' => false, 'post_tag' => false, 'post_format' => false); |
|
31 | 31 | } else { |
32 | 32 | |
33 | 33 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param string $context Context of the rewrite base. Default 'type'. |
39 | 39 | */ |
40 | - $post_format_base = apply_filters( 'post_format_rewrite_base', 'type' ); |
|
40 | + $post_format_base = apply_filters('post_format_rewrite_base', 'type'); |
|
41 | 41 | $rewrite = array( |
42 | 42 | 'category' => array( |
43 | 43 | 'hierarchical' => true, |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | 'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(), |
52 | 52 | 'ep_mask' => EP_TAGS, |
53 | 53 | ), |
54 | - 'post_format' => $post_format_base ? array( 'slug' => $post_format_base ) : false, |
|
54 | + 'post_format' => $post_format_base ? array('slug' => $post_format_base) : false, |
|
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | - register_taxonomy( 'category', 'post', array( |
|
58 | + register_taxonomy('category', 'post', array( |
|
59 | 59 | 'hierarchical' => true, |
60 | 60 | 'query_var' => 'category_name', |
61 | 61 | 'rewrite' => $rewrite['category'], |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | 'show_ui' => true, |
64 | 64 | 'show_admin_column' => true, |
65 | 65 | '_builtin' => true, |
66 | - ) ); |
|
66 | + )); |
|
67 | 67 | |
68 | - register_taxonomy( 'post_tag', 'post', array( |
|
68 | + register_taxonomy('post_tag', 'post', array( |
|
69 | 69 | 'hierarchical' => false, |
70 | 70 | 'query_var' => 'tag', |
71 | 71 | 'rewrite' => $rewrite['post_tag'], |
@@ -73,34 +73,34 @@ discard block |
||
73 | 73 | 'show_ui' => true, |
74 | 74 | 'show_admin_column' => true, |
75 | 75 | '_builtin' => true, |
76 | - ) ); |
|
76 | + )); |
|
77 | 77 | |
78 | - register_taxonomy( 'nav_menu', 'nav_menu_item', array( |
|
78 | + register_taxonomy('nav_menu', 'nav_menu_item', array( |
|
79 | 79 | 'public' => false, |
80 | 80 | 'hierarchical' => false, |
81 | 81 | 'labels' => array( |
82 | - 'name' => __( 'Navigation Menus' ), |
|
83 | - 'singular_name' => __( 'Navigation Menu' ), |
|
82 | + 'name' => __('Navigation Menus'), |
|
83 | + 'singular_name' => __('Navigation Menu'), |
|
84 | 84 | ), |
85 | 85 | 'query_var' => false, |
86 | 86 | 'rewrite' => false, |
87 | 87 | 'show_ui' => false, |
88 | 88 | '_builtin' => true, |
89 | 89 | 'show_in_nav_menus' => false, |
90 | - ) ); |
|
90 | + )); |
|
91 | 91 | |
92 | - register_taxonomy( 'link_category', 'link', array( |
|
92 | + register_taxonomy('link_category', 'link', array( |
|
93 | 93 | 'hierarchical' => false, |
94 | 94 | 'labels' => array( |
95 | - 'name' => __( 'Link Categories' ), |
|
96 | - 'singular_name' => __( 'Link Category' ), |
|
97 | - 'search_items' => __( 'Search Link Categories' ), |
|
95 | + 'name' => __('Link Categories'), |
|
96 | + 'singular_name' => __('Link Category'), |
|
97 | + 'search_items' => __('Search Link Categories'), |
|
98 | 98 | 'popular_items' => null, |
99 | - 'all_items' => __( 'All Link Categories' ), |
|
100 | - 'edit_item' => __( 'Edit Link Category' ), |
|
101 | - 'update_item' => __( 'Update Link Category' ), |
|
102 | - 'add_new_item' => __( 'Add New Link Category' ), |
|
103 | - 'new_item_name' => __( 'New Link Category Name' ), |
|
99 | + 'all_items' => __('All Link Categories'), |
|
100 | + 'edit_item' => __('Edit Link Category'), |
|
101 | + 'update_item' => __('Update Link Category'), |
|
102 | + 'add_new_item' => __('Add New Link Category'), |
|
103 | + 'new_item_name' => __('New Link Category Name'), |
|
104 | 104 | 'separate_items_with_commas' => null, |
105 | 105 | 'add_or_remove_items' => null, |
106 | 106 | 'choose_from_most_used' => null, |
@@ -116,21 +116,21 @@ discard block |
||
116 | 116 | 'public' => false, |
117 | 117 | 'show_ui' => false, |
118 | 118 | '_builtin' => true, |
119 | - ) ); |
|
119 | + )); |
|
120 | 120 | |
121 | - register_taxonomy( 'post_format', 'post', array( |
|
121 | + register_taxonomy('post_format', 'post', array( |
|
122 | 122 | 'public' => true, |
123 | 123 | 'hierarchical' => false, |
124 | 124 | 'labels' => array( |
125 | - 'name' => _x( 'Format', 'post format' ), |
|
126 | - 'singular_name' => _x( 'Format', 'post format' ), |
|
125 | + 'name' => _x('Format', 'post format'), |
|
126 | + 'singular_name' => _x('Format', 'post format'), |
|
127 | 127 | ), |
128 | 128 | 'query_var' => true, |
129 | 129 | 'rewrite' => $rewrite['post_format'], |
130 | 130 | 'show_ui' => false, |
131 | 131 | '_builtin' => true, |
132 | - 'show_in_nav_menus' => current_theme_supports( 'post-formats' ), |
|
133 | - ) ); |
|
132 | + 'show_in_nav_menus' => current_theme_supports('post-formats'), |
|
133 | + )); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * Default 'and'. |
150 | 150 | * @return array A list of taxonomy names or objects. |
151 | 151 | */ |
152 | -function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) { |
|
152 | +function get_taxonomies($args = array(), $output = 'names', $operator = 'and') { |
|
153 | 153 | global $wp_taxonomies; |
154 | 154 | |
155 | 155 | $field = ('names' == $output) ? 'name' : false; |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | * taxonomy 'names' or 'objects'. Default 'names'. |
176 | 176 | * @return array The names of all taxonomy of $object_type. |
177 | 177 | */ |
178 | -function get_object_taxonomies( $object, $output = 'names' ) { |
|
178 | +function get_object_taxonomies($object, $output = 'names') { |
|
179 | 179 | global $wp_taxonomies; |
180 | 180 | |
181 | - if ( is_object($object) ) { |
|
182 | - if ( $object->post_type == 'attachment' ) |
|
181 | + if (is_object($object)) { |
|
182 | + if ($object->post_type == 'attachment') |
|
183 | 183 | return get_attachment_taxonomies($object); |
184 | 184 | $object = $object->post_type; |
185 | 185 | } |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | $object = (array) $object; |
188 | 188 | |
189 | 189 | $taxonomies = array(); |
190 | - foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) { |
|
191 | - if ( array_intersect($object, (array) $tax_obj->object_type) ) { |
|
192 | - if ( 'names' == $output ) |
|
190 | + foreach ((array) $wp_taxonomies as $tax_name => $tax_obj) { |
|
191 | + if (array_intersect($object, (array) $tax_obj->object_type)) { |
|
192 | + if ('names' == $output) |
|
193 | 193 | $taxonomies[] = $tax_name; |
194 | 194 | else |
195 | - $taxonomies[ $tax_name ] = $tax_obj; |
|
195 | + $taxonomies[$tax_name] = $tax_obj; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | * @param string $taxonomy Name of taxonomy object to return. |
213 | 213 | * @return object|false The Taxonomy Object or false if $taxonomy doesn't exist. |
214 | 214 | */ |
215 | -function get_taxonomy( $taxonomy ) { |
|
215 | +function get_taxonomy($taxonomy) { |
|
216 | 216 | global $wp_taxonomies; |
217 | 217 | |
218 | - if ( ! taxonomy_exists( $taxonomy ) ) |
|
218 | + if ( ! taxonomy_exists($taxonomy)) |
|
219 | 219 | return false; |
220 | 220 | |
221 | 221 | return $wp_taxonomies[$taxonomy]; |
@@ -233,10 +233,10 @@ discard block |
||
233 | 233 | * @param string $taxonomy Name of taxonomy object. |
234 | 234 | * @return bool Whether the taxonomy exists. |
235 | 235 | */ |
236 | -function taxonomy_exists( $taxonomy ) { |
|
236 | +function taxonomy_exists($taxonomy) { |
|
237 | 237 | global $wp_taxonomies; |
238 | 238 | |
239 | - return isset( $wp_taxonomies[$taxonomy] ); |
|
239 | + return isset($wp_taxonomies[$taxonomy]); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | * @return bool Whether the taxonomy is hierarchical. |
254 | 254 | */ |
255 | 255 | function is_taxonomy_hierarchical($taxonomy) { |
256 | - if ( ! taxonomy_exists($taxonomy) ) |
|
256 | + if ( ! taxonomy_exists($taxonomy)) |
|
257 | 257 | return false; |
258 | 258 | |
259 | 259 | $taxonomy = get_taxonomy($taxonomy); |
@@ -332,10 +332,10 @@ discard block |
||
332 | 332 | * @param array|string $args See optional args description above. |
333 | 333 | * @return WP_Error|void WP_Error, if errors. |
334 | 334 | */ |
335 | -function register_taxonomy( $taxonomy, $object_type, $args = array() ) { |
|
335 | +function register_taxonomy($taxonomy, $object_type, $args = array()) { |
|
336 | 336 | global $wp_taxonomies, $wp; |
337 | 337 | |
338 | - if ( ! is_array( $wp_taxonomies ) ) |
|
338 | + if ( ! is_array($wp_taxonomies)) |
|
339 | 339 | $wp_taxonomies = array(); |
340 | 340 | |
341 | 341 | $defaults = array( |
@@ -356,58 +356,58 @@ discard block |
||
356 | 356 | 'update_count_callback' => '', |
357 | 357 | '_builtin' => false, |
358 | 358 | ); |
359 | - $args = wp_parse_args( $args, $defaults ); |
|
359 | + $args = wp_parse_args($args, $defaults); |
|
360 | 360 | |
361 | - if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) { |
|
362 | - _doing_it_wrong( __FUNCTION__, __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2' ); |
|
363 | - return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) ); |
|
361 | + if (empty($taxonomy) || strlen($taxonomy) > 32) { |
|
362 | + _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2'); |
|
363 | + return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.')); |
|
364 | 364 | } |
365 | 365 | |
366 | - if ( false !== $args['query_var'] && ! empty( $wp ) ) { |
|
367 | - if ( true === $args['query_var'] ) |
|
366 | + if (false !== $args['query_var'] && ! empty($wp)) { |
|
367 | + if (true === $args['query_var']) |
|
368 | 368 | $args['query_var'] = $taxonomy; |
369 | 369 | else |
370 | - $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); |
|
371 | - $wp->add_query_var( $args['query_var'] ); |
|
370 | + $args['query_var'] = sanitize_title_with_dashes($args['query_var']); |
|
371 | + $wp->add_query_var($args['query_var']); |
|
372 | 372 | } |
373 | 373 | |
374 | - if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) { |
|
375 | - $args['rewrite'] = wp_parse_args( $args['rewrite'], array( |
|
374 | + if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) { |
|
375 | + $args['rewrite'] = wp_parse_args($args['rewrite'], array( |
|
376 | 376 | 'with_front' => true, |
377 | 377 | 'hierarchical' => false, |
378 | 378 | 'ep_mask' => EP_NONE, |
379 | - ) ); |
|
379 | + )); |
|
380 | 380 | |
381 | - if ( empty( $args['rewrite']['slug'] ) ) |
|
382 | - $args['rewrite']['slug'] = sanitize_title_with_dashes( $taxonomy ); |
|
381 | + if (empty($args['rewrite']['slug'])) |
|
382 | + $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy); |
|
383 | 383 | |
384 | - if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) |
|
384 | + if ($args['hierarchical'] && $args['rewrite']['hierarchical']) |
|
385 | 385 | $tag = '(.+?)'; |
386 | 386 | else |
387 | 387 | $tag = '([^/]+)'; |
388 | 388 | |
389 | - add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" ); |
|
390 | - add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] ); |
|
389 | + add_rewrite_tag("%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term="); |
|
390 | + add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // If not set, default to the setting for public. |
394 | - if ( null === $args['show_ui'] ) |
|
394 | + if (null === $args['show_ui']) |
|
395 | 395 | $args['show_ui'] = $args['public']; |
396 | 396 | |
397 | 397 | // If not set, default to the setting for show_ui. |
398 | - if ( null === $args['show_in_menu' ] || ! $args['show_ui'] ) |
|
399 | - $args['show_in_menu' ] = $args['show_ui']; |
|
398 | + if (null === $args['show_in_menu'] || ! $args['show_ui']) |
|
399 | + $args['show_in_menu'] = $args['show_ui']; |
|
400 | 400 | |
401 | 401 | // If not set, default to the setting for public. |
402 | - if ( null === $args['show_in_nav_menus'] ) |
|
402 | + if (null === $args['show_in_nav_menus']) |
|
403 | 403 | $args['show_in_nav_menus'] = $args['public']; |
404 | 404 | |
405 | 405 | // If not set, default to the setting for show_ui. |
406 | - if ( null === $args['show_tagcloud'] ) |
|
406 | + if (null === $args['show_tagcloud']) |
|
407 | 407 | $args['show_tagcloud'] = $args['show_ui']; |
408 | 408 | |
409 | 409 | // If not set, default to the setting for show_ui. |
410 | - if ( null === $args['show_in_quick_edit'] ) { |
|
410 | + if (null === $args['show_in_quick_edit']) { |
|
411 | 411 | $args['show_in_quick_edit'] = $args['show_ui']; |
412 | 412 | } |
413 | 413 | |
@@ -417,27 +417,27 @@ discard block |
||
417 | 417 | 'delete_terms' => 'manage_categories', |
418 | 418 | 'assign_terms' => 'edit_posts', |
419 | 419 | ); |
420 | - $args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] ); |
|
421 | - unset( $args['capabilities'] ); |
|
420 | + $args['cap'] = (object) array_merge($default_caps, $args['capabilities']); |
|
421 | + unset($args['capabilities']); |
|
422 | 422 | |
423 | 423 | $args['name'] = $taxonomy; |
424 | - $args['object_type'] = array_unique( (array) $object_type ); |
|
424 | + $args['object_type'] = array_unique((array) $object_type); |
|
425 | 425 | |
426 | - $args['labels'] = get_taxonomy_labels( (object) $args ); |
|
426 | + $args['labels'] = get_taxonomy_labels((object) $args); |
|
427 | 427 | $args['label'] = $args['labels']->name; |
428 | 428 | |
429 | 429 | // If not set, use the default meta box |
430 | - if ( null === $args['meta_box_cb'] ) { |
|
431 | - if ( $args['hierarchical'] ) |
|
430 | + if (null === $args['meta_box_cb']) { |
|
431 | + if ($args['hierarchical']) |
|
432 | 432 | $args['meta_box_cb'] = 'post_categories_meta_box'; |
433 | 433 | else |
434 | 434 | $args['meta_box_cb'] = 'post_tags_meta_box'; |
435 | 435 | } |
436 | 436 | |
437 | - $wp_taxonomies[ $taxonomy ] = (object) $args; |
|
437 | + $wp_taxonomies[$taxonomy] = (object) $args; |
|
438 | 438 | |
439 | 439 | // register callback handling for metabox |
440 | - add_filter( 'wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term' ); |
|
440 | + add_filter('wp_ajax_add-'.$taxonomy, '_wp_ajax_add_hierarchical_term'); |
|
441 | 441 | |
442 | 442 | /** |
443 | 443 | * Fires after a taxonomy is registered. |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | * @param array|string $object_type Object type or array of object types. |
449 | 449 | * @param array $args Array of taxonomy registration arguments. |
450 | 450 | */ |
451 | - do_action( 'registered_taxonomy', $taxonomy, $object_type, $args ); |
|
451 | + do_action('registered_taxonomy', $taxonomy, $object_type, $args); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -484,37 +484,37 @@ discard block |
||
484 | 484 | * @param object $tax Taxonomy object. |
485 | 485 | * @return object object with all the labels as member variables. |
486 | 486 | */ |
487 | -function get_taxonomy_labels( $tax ) { |
|
487 | +function get_taxonomy_labels($tax) { |
|
488 | 488 | $tax->labels = (array) $tax->labels; |
489 | 489 | |
490 | - if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) |
|
490 | + if (isset($tax->helps) && empty($tax->labels['separate_items_with_commas'])) |
|
491 | 491 | $tax->labels['separate_items_with_commas'] = $tax->helps; |
492 | 492 | |
493 | - if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) |
|
493 | + if (isset($tax->no_tagcloud) && empty($tax->labels['not_found'])) |
|
494 | 494 | $tax->labels['not_found'] = $tax->no_tagcloud; |
495 | 495 | |
496 | 496 | $nohier_vs_hier_defaults = array( |
497 | - 'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ), |
|
498 | - 'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ), |
|
499 | - 'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ), |
|
500 | - 'popular_items' => array( __( 'Popular Tags' ), null ), |
|
501 | - 'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ), |
|
502 | - 'parent_item' => array( null, __( 'Parent Category' ) ), |
|
503 | - 'parent_item_colon' => array( null, __( 'Parent Category:' ) ), |
|
504 | - 'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ), |
|
505 | - 'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ), |
|
506 | - 'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ), |
|
507 | - 'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ), |
|
508 | - 'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ), |
|
509 | - 'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ), |
|
510 | - 'add_or_remove_items' => array( __( 'Add or remove tags' ), null ), |
|
511 | - 'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ), |
|
512 | - 'not_found' => array( __( 'No tags found.' ), __( 'No categories found.' ) ), |
|
513 | - 'no_terms' => array( __( 'No tags' ), __( 'No categories' ) ), |
|
497 | + 'name' => array(_x('Tags', 'taxonomy general name'), _x('Categories', 'taxonomy general name')), |
|
498 | + 'singular_name' => array(_x('Tag', 'taxonomy singular name'), _x('Category', 'taxonomy singular name')), |
|
499 | + 'search_items' => array(__('Search Tags'), __('Search Categories')), |
|
500 | + 'popular_items' => array(__('Popular Tags'), null), |
|
501 | + 'all_items' => array(__('All Tags'), __('All Categories')), |
|
502 | + 'parent_item' => array(null, __('Parent Category')), |
|
503 | + 'parent_item_colon' => array(null, __('Parent Category:')), |
|
504 | + 'edit_item' => array(__('Edit Tag'), __('Edit Category')), |
|
505 | + 'view_item' => array(__('View Tag'), __('View Category')), |
|
506 | + 'update_item' => array(__('Update Tag'), __('Update Category')), |
|
507 | + 'add_new_item' => array(__('Add New Tag'), __('Add New Category')), |
|
508 | + 'new_item_name' => array(__('New Tag Name'), __('New Category Name')), |
|
509 | + 'separate_items_with_commas' => array(__('Separate tags with commas'), null), |
|
510 | + 'add_or_remove_items' => array(__('Add or remove tags'), null), |
|
511 | + 'choose_from_most_used' => array(__('Choose from the most used tags'), null), |
|
512 | + 'not_found' => array(__('No tags found.'), __('No categories found.')), |
|
513 | + 'no_terms' => array(__('No tags'), __('No categories')), |
|
514 | 514 | ); |
515 | 515 | $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; |
516 | 516 | |
517 | - return _get_custom_object_labels( $tax, $nohier_vs_hier_defaults ); |
|
517 | + return _get_custom_object_labels($tax, $nohier_vs_hier_defaults); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -528,20 +528,20 @@ discard block |
||
528 | 528 | * @param string $object_type Name of the object type. |
529 | 529 | * @return bool True if successful, false if not. |
530 | 530 | */ |
531 | -function register_taxonomy_for_object_type( $taxonomy, $object_type) { |
|
531 | +function register_taxonomy_for_object_type($taxonomy, $object_type) { |
|
532 | 532 | global $wp_taxonomies; |
533 | 533 | |
534 | - if ( !isset($wp_taxonomies[$taxonomy]) ) |
|
534 | + if ( ! isset($wp_taxonomies[$taxonomy])) |
|
535 | 535 | return false; |
536 | 536 | |
537 | - if ( ! get_post_type_object($object_type) ) |
|
537 | + if ( ! get_post_type_object($object_type)) |
|
538 | 538 | return false; |
539 | 539 | |
540 | - if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) ) |
|
540 | + if ( ! in_array($object_type, $wp_taxonomies[$taxonomy]->object_type)) |
|
541 | 541 | $wp_taxonomies[$taxonomy]->object_type[] = $object_type; |
542 | 542 | |
543 | 543 | // Filter out empties. |
544 | - $wp_taxonomies[ $taxonomy ]->object_type = array_filter( $wp_taxonomies[ $taxonomy ]->object_type ); |
|
544 | + $wp_taxonomies[$taxonomy]->object_type = array_filter($wp_taxonomies[$taxonomy]->object_type); |
|
545 | 545 | |
546 | 546 | return true; |
547 | 547 | } |
@@ -557,20 +557,20 @@ discard block |
||
557 | 557 | * @param string $object_type Name of the object type. |
558 | 558 | * @return bool True if successful, false if not. |
559 | 559 | */ |
560 | -function unregister_taxonomy_for_object_type( $taxonomy, $object_type ) { |
|
560 | +function unregister_taxonomy_for_object_type($taxonomy, $object_type) { |
|
561 | 561 | global $wp_taxonomies; |
562 | 562 | |
563 | - if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) |
|
563 | + if ( ! isset($wp_taxonomies[$taxonomy])) |
|
564 | 564 | return false; |
565 | 565 | |
566 | - if ( ! get_post_type_object( $object_type ) ) |
|
566 | + if ( ! get_post_type_object($object_type)) |
|
567 | 567 | return false; |
568 | 568 | |
569 | - $key = array_search( $object_type, $wp_taxonomies[ $taxonomy ]->object_type, true ); |
|
570 | - if ( false === $key ) |
|
569 | + $key = array_search($object_type, $wp_taxonomies[$taxonomy]->object_type, true); |
|
570 | + if (false === $key) |
|
571 | 571 | return false; |
572 | 572 | |
573 | - unset( $wp_taxonomies[ $taxonomy ]->object_type[ $key ] ); |
|
573 | + unset($wp_taxonomies[$taxonomy]->object_type[$key]); |
|
574 | 574 | return true; |
575 | 575 | } |
576 | 576 | |
@@ -603,34 +603,34 @@ discard block |
||
603 | 603 | * @return WP_Error|array If the taxonomy does not exist, then WP_Error will be returned. On success. |
604 | 604 | * the array can be empty meaning that there are no $object_ids found or it will return the $object_ids found. |
605 | 605 | */ |
606 | -function get_objects_in_term( $term_ids, $taxonomies, $args = array() ) { |
|
606 | +function get_objects_in_term($term_ids, $taxonomies, $args = array()) { |
|
607 | 607 | global $wpdb; |
608 | 608 | |
609 | - if ( ! is_array( $term_ids ) ) { |
|
610 | - $term_ids = array( $term_ids ); |
|
609 | + if ( ! is_array($term_ids)) { |
|
610 | + $term_ids = array($term_ids); |
|
611 | 611 | } |
612 | - if ( ! is_array( $taxonomies ) ) { |
|
613 | - $taxonomies = array( $taxonomies ); |
|
612 | + if ( ! is_array($taxonomies)) { |
|
613 | + $taxonomies = array($taxonomies); |
|
614 | 614 | } |
615 | - foreach ( (array) $taxonomies as $taxonomy ) { |
|
616 | - if ( ! taxonomy_exists( $taxonomy ) ) { |
|
617 | - return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); |
|
615 | + foreach ((array) $taxonomies as $taxonomy) { |
|
616 | + if ( ! taxonomy_exists($taxonomy)) { |
|
617 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | - $defaults = array( 'order' => 'ASC' ); |
|
622 | - $args = wp_parse_args( $args, $defaults ); |
|
621 | + $defaults = array('order' => 'ASC'); |
|
622 | + $args = wp_parse_args($args, $defaults); |
|
623 | 623 | |
624 | - $order = ( 'desc' == strtolower( $args['order'] ) ) ? 'DESC' : 'ASC'; |
|
624 | + $order = ('desc' == strtolower($args['order'])) ? 'DESC' : 'ASC'; |
|
625 | 625 | |
626 | - $term_ids = array_map('intval', $term_ids ); |
|
626 | + $term_ids = array_map('intval', $term_ids); |
|
627 | 627 | |
628 | - $taxonomies = "'" . implode( "', '", $taxonomies ) . "'"; |
|
629 | - $term_ids = "'" . implode( "', '", $term_ids ) . "'"; |
|
628 | + $taxonomies = "'".implode("', '", $taxonomies)."'"; |
|
629 | + $term_ids = "'".implode("', '", $term_ids)."'"; |
|
630 | 630 | |
631 | 631 | $object_ids = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($term_ids) ORDER BY tr.object_id $order"); |
632 | 632 | |
633 | - if ( ! $object_ids ){ |
|
633 | + if ( ! $object_ids) { |
|
634 | 634 | return array(); |
635 | 635 | } |
636 | 636 | return $object_ids; |
@@ -648,9 +648,9 @@ discard block |
||
648 | 648 | * @param string $primary_id_column |
649 | 649 | * @return array |
650 | 650 | */ |
651 | -function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) { |
|
652 | - $tax_query_obj = new WP_Tax_Query( $tax_query ); |
|
653 | - return $tax_query_obj->get_sql( $primary_table, $primary_id_column ); |
|
651 | +function get_tax_sql($tax_query, $primary_table, $primary_id_column) { |
|
652 | + $tax_query_obj = new WP_Tax_Query($tax_query); |
|
653 | + return $tax_query_obj->get_sql($primary_table, $primary_id_column); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | /** |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | * @access private |
694 | 694 | * @var string |
695 | 695 | */ |
696 | - private static $no_results = array( 'join' => array( '' ), 'where' => array( '0 = 1' ) ); |
|
696 | + private static $no_results = array('join' => array(''), 'where' => array('0 = 1')); |
|
697 | 697 | |
698 | 698 | /** |
699 | 699 | * A flat list of table aliases used in the JOIN clauses. |
@@ -761,14 +761,14 @@ discard block |
||
761 | 761 | * } |
762 | 762 | * } |
763 | 763 | */ |
764 | - public function __construct( $tax_query ) { |
|
765 | - if ( isset( $tax_query['relation'] ) ) { |
|
766 | - $this->relation = $this->sanitize_relation( $tax_query['relation'] ); |
|
764 | + public function __construct($tax_query) { |
|
765 | + if (isset($tax_query['relation'])) { |
|
766 | + $this->relation = $this->sanitize_relation($tax_query['relation']); |
|
767 | 767 | } else { |
768 | 768 | $this->relation = 'AND'; |
769 | 769 | } |
770 | 770 | |
771 | - $this->queries = $this->sanitize_query( $tax_query ); |
|
771 | + $this->queries = $this->sanitize_query($tax_query); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
@@ -783,7 +783,7 @@ discard block |
||
783 | 783 | * @param array $queries Array of queries clauses. |
784 | 784 | * @return array Sanitized array of query clauses. |
785 | 785 | */ |
786 | - public function sanitize_query( $queries ) { |
|
786 | + public function sanitize_query($queries) { |
|
787 | 787 | $cleaned_query = array(); |
788 | 788 | |
789 | 789 | $defaults = array( |
@@ -794,14 +794,14 @@ discard block |
||
794 | 794 | 'include_children' => true, |
795 | 795 | ); |
796 | 796 | |
797 | - foreach ( $queries as $key => $query ) { |
|
798 | - if ( 'relation' === $key ) { |
|
799 | - $cleaned_query['relation'] = $this->sanitize_relation( $query ); |
|
797 | + foreach ($queries as $key => $query) { |
|
798 | + if ('relation' === $key) { |
|
799 | + $cleaned_query['relation'] = $this->sanitize_relation($query); |
|
800 | 800 | |
801 | 801 | // First-order clause. |
802 | - } elseif ( self::is_first_order_clause( $query ) ) { |
|
802 | + } elseif (self::is_first_order_clause($query)) { |
|
803 | 803 | |
804 | - $cleaned_clause = array_merge( $defaults, $query ); |
|
804 | + $cleaned_clause = array_merge($defaults, $query); |
|
805 | 805 | $cleaned_clause['terms'] = (array) $cleaned_clause['terms']; |
806 | 806 | $cleaned_query[] = $cleaned_clause; |
807 | 807 | |
@@ -809,32 +809,32 @@ discard block |
||
809 | 809 | * Keep a copy of the clause in the flate |
810 | 810 | * $queried_terms array, for use in WP_Query. |
811 | 811 | */ |
812 | - if ( ! empty( $cleaned_clause['taxonomy'] ) && 'NOT IN' !== $cleaned_clause['operator'] ) { |
|
812 | + if ( ! empty($cleaned_clause['taxonomy']) && 'NOT IN' !== $cleaned_clause['operator']) { |
|
813 | 813 | $taxonomy = $cleaned_clause['taxonomy']; |
814 | - if ( ! isset( $this->queried_terms[ $taxonomy ] ) ) { |
|
815 | - $this->queried_terms[ $taxonomy ] = array(); |
|
814 | + if ( ! isset($this->queried_terms[$taxonomy])) { |
|
815 | + $this->queried_terms[$taxonomy] = array(); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | /* |
819 | 819 | * Backward compatibility: Only store the first |
820 | 820 | * 'terms' and 'field' found for a given taxonomy. |
821 | 821 | */ |
822 | - if ( ! empty( $cleaned_clause['terms'] ) && ! isset( $this->queried_terms[ $taxonomy ]['terms'] ) ) { |
|
823 | - $this->queried_terms[ $taxonomy ]['terms'] = $cleaned_clause['terms']; |
|
822 | + if ( ! empty($cleaned_clause['terms']) && ! isset($this->queried_terms[$taxonomy]['terms'])) { |
|
823 | + $this->queried_terms[$taxonomy]['terms'] = $cleaned_clause['terms']; |
|
824 | 824 | } |
825 | 825 | |
826 | - if ( ! empty( $cleaned_clause['field'] ) && ! isset( $this->queried_terms[ $taxonomy ]['field'] ) ) { |
|
827 | - $this->queried_terms[ $taxonomy ]['field'] = $cleaned_clause['field']; |
|
826 | + if ( ! empty($cleaned_clause['field']) && ! isset($this->queried_terms[$taxonomy]['field'])) { |
|
827 | + $this->queried_terms[$taxonomy]['field'] = $cleaned_clause['field']; |
|
828 | 828 | } |
829 | 829 | } |
830 | 830 | |
831 | 831 | // Otherwise, it's a nested query, so we recurse. |
832 | - } elseif ( is_array( $query ) ) { |
|
833 | - $cleaned_subquery = $this->sanitize_query( $query ); |
|
832 | + } elseif (is_array($query)) { |
|
833 | + $cleaned_subquery = $this->sanitize_query($query); |
|
834 | 834 | |
835 | - if ( ! empty( $cleaned_subquery ) ) { |
|
835 | + if ( ! empty($cleaned_subquery)) { |
|
836 | 836 | // All queries with children must have a relation. |
837 | - if ( ! isset( $cleaned_subquery['relation'] ) ) { |
|
837 | + if ( ! isset($cleaned_subquery['relation'])) { |
|
838 | 838 | $cleaned_subquery['relation'] = 'AND'; |
839 | 839 | } |
840 | 840 | |
@@ -855,8 +855,8 @@ discard block |
||
855 | 855 | * @param string $relation Raw relation key from the query argument. |
856 | 856 | * @return string Sanitized relation ('AND' or 'OR'). |
857 | 857 | */ |
858 | - public function sanitize_relation( $relation ) { |
|
859 | - if ( 'OR' === strtoupper( $relation ) ) { |
|
858 | + public function sanitize_relation($relation) { |
|
859 | + if ('OR' === strtoupper($relation)) { |
|
860 | 860 | return 'OR'; |
861 | 861 | } else { |
862 | 862 | return 'AND'; |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @param array $query Tax query arguments. |
881 | 881 | * @return bool Whether the query clause is a first-order clause. |
882 | 882 | */ |
883 | - protected static function is_first_order_clause( $query ) { |
|
884 | - return is_array( $query ) && ( empty( $query ) || array_key_exists( 'terms', $query ) || array_key_exists( 'taxonomy', $query ) || array_key_exists( 'include_children', $query ) || array_key_exists( 'field', $query ) || array_key_exists( 'operator', $query ) ); |
|
883 | + protected static function is_first_order_clause($query) { |
|
884 | + return is_array($query) && (empty($query) || array_key_exists('terms', $query) || array_key_exists('taxonomy', $query) || array_key_exists('include_children', $query) || array_key_exists('field', $query) || array_key_exists('operator', $query)); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
@@ -901,7 +901,7 @@ discard block |
||
901 | 901 | * @type string $where SQL fragment to append to the main WHERE clause. |
902 | 902 | * } |
903 | 903 | */ |
904 | - public function get_sql( $primary_table, $primary_id_column ) { |
|
904 | + public function get_sql($primary_table, $primary_id_column) { |
|
905 | 905 | $this->primary_table = $primary_table; |
906 | 906 | $this->primary_id_column = $primary_id_column; |
907 | 907 | |
@@ -930,10 +930,10 @@ discard block |
||
930 | 930 | * To keep $this->queries unaltered, pass a copy. |
931 | 931 | */ |
932 | 932 | $queries = $this->queries; |
933 | - $sql = $this->get_sql_for_query( $queries ); |
|
933 | + $sql = $this->get_sql_for_query($queries); |
|
934 | 934 | |
935 | - if ( ! empty( $sql['where'] ) ) { |
|
936 | - $sql['where'] = ' AND ' . $sql['where']; |
|
935 | + if ( ! empty($sql['where'])) { |
|
936 | + $sql['where'] = ' AND '.$sql['where']; |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | return $sql; |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | * @type string $where SQL fragment to append to the main WHERE clause. |
959 | 959 | * } |
960 | 960 | */ |
961 | - protected function get_sql_for_query( &$query, $depth = 0 ) { |
|
961 | + protected function get_sql_for_query(&$query, $depth = 0) { |
|
962 | 962 | $sql_chunks = array( |
963 | 963 | 'join' => array(), |
964 | 964 | 'where' => array(), |
@@ -970,32 +970,32 @@ discard block |
||
970 | 970 | ); |
971 | 971 | |
972 | 972 | $indent = ''; |
973 | - for ( $i = 0; $i < $depth; $i++ ) { |
|
973 | + for ($i = 0; $i < $depth; $i++) { |
|
974 | 974 | $indent .= " "; |
975 | 975 | } |
976 | 976 | |
977 | - foreach ( $query as $key => &$clause ) { |
|
978 | - if ( 'relation' === $key ) { |
|
977 | + foreach ($query as $key => &$clause) { |
|
978 | + if ('relation' === $key) { |
|
979 | 979 | $relation = $query['relation']; |
980 | - } elseif ( is_array( $clause ) ) { |
|
980 | + } elseif (is_array($clause)) { |
|
981 | 981 | |
982 | 982 | // This is a first-order clause. |
983 | - if ( $this->is_first_order_clause( $clause ) ) { |
|
984 | - $clause_sql = $this->get_sql_for_clause( $clause, $query ); |
|
983 | + if ($this->is_first_order_clause($clause)) { |
|
984 | + $clause_sql = $this->get_sql_for_clause($clause, $query); |
|
985 | 985 | |
986 | - $where_count = count( $clause_sql['where'] ); |
|
987 | - if ( ! $where_count ) { |
|
986 | + $where_count = count($clause_sql['where']); |
|
987 | + if ( ! $where_count) { |
|
988 | 988 | $sql_chunks['where'][] = ''; |
989 | - } elseif ( 1 === $where_count ) { |
|
989 | + } elseif (1 === $where_count) { |
|
990 | 990 | $sql_chunks['where'][] = $clause_sql['where'][0]; |
991 | 991 | } else { |
992 | - $sql_chunks['where'][] = '( ' . implode( ' AND ', $clause_sql['where'] ) . ' )'; |
|
992 | + $sql_chunks['where'][] = '( '.implode(' AND ', $clause_sql['where']).' )'; |
|
993 | 993 | } |
994 | 994 | |
995 | - $sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] ); |
|
995 | + $sql_chunks['join'] = array_merge($sql_chunks['join'], $clause_sql['join']); |
|
996 | 996 | // This is a subquery, so we recurse. |
997 | 997 | } else { |
998 | - $clause_sql = $this->get_sql_for_query( $clause, $depth + 1 ); |
|
998 | + $clause_sql = $this->get_sql_for_query($clause, $depth + 1); |
|
999 | 999 | |
1000 | 1000 | $sql_chunks['where'][] = $clause_sql['where']; |
1001 | 1001 | $sql_chunks['join'][] = $clause_sql['join']; |
@@ -1004,21 +1004,21 @@ discard block |
||
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | // Filter to remove empties. |
1007 | - $sql_chunks['join'] = array_filter( $sql_chunks['join'] ); |
|
1008 | - $sql_chunks['where'] = array_filter( $sql_chunks['where'] ); |
|
1007 | + $sql_chunks['join'] = array_filter($sql_chunks['join']); |
|
1008 | + $sql_chunks['where'] = array_filter($sql_chunks['where']); |
|
1009 | 1009 | |
1010 | - if ( empty( $relation ) ) { |
|
1010 | + if (empty($relation)) { |
|
1011 | 1011 | $relation = 'AND'; |
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | // Filter duplicate JOIN clauses and combine into a single string. |
1015 | - if ( ! empty( $sql_chunks['join'] ) ) { |
|
1016 | - $sql['join'] = implode( ' ', array_unique( $sql_chunks['join'] ) ); |
|
1015 | + if ( ! empty($sql_chunks['join'])) { |
|
1016 | + $sql['join'] = implode(' ', array_unique($sql_chunks['join'])); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | // Generate a single WHERE clause with proper brackets and indentation. |
1020 | - if ( ! empty( $sql_chunks['where'] ) ) { |
|
1021 | - $sql['where'] = '( ' . "\n " . $indent . implode( ' ' . "\n " . $indent . $relation . ' ' . "\n " . $indent, $sql_chunks['where'] ) . "\n" . $indent . ')'; |
|
1020 | + if ( ! empty($sql_chunks['where'])) { |
|
1021 | + $sql['where'] = '( '."\n ".$indent.implode(' '."\n ".$indent.$relation.' '."\n ".$indent, $sql_chunks['where'])."\n".$indent.')'; |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | return $sql; |
@@ -1041,7 +1041,7 @@ discard block |
||
1041 | 1041 | * @type string $where SQL fragment to append to the main WHERE clause. |
1042 | 1042 | * } |
1043 | 1043 | */ |
1044 | - public function get_sql_for_clause( &$clause, $parent_query ) { |
|
1044 | + public function get_sql_for_clause(&$clause, $parent_query) { |
|
1045 | 1045 | global $wpdb; |
1046 | 1046 | |
1047 | 1047 | $sql = array( |
@@ -1051,31 +1051,31 @@ discard block |
||
1051 | 1051 | |
1052 | 1052 | $join = $where = ''; |
1053 | 1053 | |
1054 | - $this->clean_query( $clause ); |
|
1054 | + $this->clean_query($clause); |
|
1055 | 1055 | |
1056 | - if ( is_wp_error( $clause ) ) { |
|
1056 | + if (is_wp_error($clause)) { |
|
1057 | 1057 | return self::$no_results; |
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | $terms = $clause['terms']; |
1061 | - $operator = strtoupper( $clause['operator'] ); |
|
1061 | + $operator = strtoupper($clause['operator']); |
|
1062 | 1062 | |
1063 | - if ( 'IN' == $operator ) { |
|
1063 | + if ('IN' == $operator) { |
|
1064 | 1064 | |
1065 | - if ( empty( $terms ) ) { |
|
1065 | + if (empty($terms)) { |
|
1066 | 1066 | return self::$no_results; |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - $terms = implode( ',', $terms ); |
|
1069 | + $terms = implode(',', $terms); |
|
1070 | 1070 | |
1071 | 1071 | /* |
1072 | 1072 | * Before creating another table join, see if this clause has a |
1073 | 1073 | * sibling with an existing join that can be shared. |
1074 | 1074 | */ |
1075 | - $alias = $this->find_compatible_table_alias( $clause, $parent_query ); |
|
1076 | - if ( false === $alias ) { |
|
1077 | - $i = count( $this->table_aliases ); |
|
1078 | - $alias = $i ? 'tt' . $i : $wpdb->term_relationships; |
|
1075 | + $alias = $this->find_compatible_table_alias($clause, $parent_query); |
|
1076 | + if (false === $alias) { |
|
1077 | + $i = count($this->table_aliases); |
|
1078 | + $alias = $i ? 'tt'.$i : $wpdb->term_relationships; |
|
1079 | 1079 | |
1080 | 1080 | // Store the alias as part of a flat array to build future iterators. |
1081 | 1081 | $this->table_aliases[] = $alias; |
@@ -1091,13 +1091,13 @@ discard block |
||
1091 | 1091 | |
1092 | 1092 | $where = "$alias.term_taxonomy_id $operator ($terms)"; |
1093 | 1093 | |
1094 | - } elseif ( 'NOT IN' == $operator ) { |
|
1094 | + } elseif ('NOT IN' == $operator) { |
|
1095 | 1095 | |
1096 | - if ( empty( $terms ) ) { |
|
1096 | + if (empty($terms)) { |
|
1097 | 1097 | return $sql; |
1098 | 1098 | } |
1099 | 1099 | |
1100 | - $terms = implode( ',', $terms ); |
|
1100 | + $terms = implode(',', $terms); |
|
1101 | 1101 | |
1102 | 1102 | $where = "$this->primary_table.$this->primary_id_column NOT IN ( |
1103 | 1103 | SELECT object_id |
@@ -1105,15 +1105,15 @@ discard block |
||
1105 | 1105 | WHERE term_taxonomy_id IN ($terms) |
1106 | 1106 | )"; |
1107 | 1107 | |
1108 | - } elseif ( 'AND' == $operator ) { |
|
1108 | + } elseif ('AND' == $operator) { |
|
1109 | 1109 | |
1110 | - if ( empty( $terms ) ) { |
|
1110 | + if (empty($terms)) { |
|
1111 | 1111 | return $sql; |
1112 | 1112 | } |
1113 | 1113 | |
1114 | - $num_terms = count( $terms ); |
|
1114 | + $num_terms = count($terms); |
|
1115 | 1115 | |
1116 | - $terms = implode( ',', $terms ); |
|
1116 | + $terms = implode(',', $terms); |
|
1117 | 1117 | |
1118 | 1118 | $where = "( |
1119 | 1119 | SELECT COUNT(1) |
@@ -1122,16 +1122,16 @@ discard block |
||
1122 | 1122 | AND object_id = $this->primary_table.$this->primary_id_column |
1123 | 1123 | ) = $num_terms"; |
1124 | 1124 | |
1125 | - } elseif ( 'NOT EXISTS' === $operator || 'EXISTS' === $operator ) { |
|
1125 | + } elseif ('NOT EXISTS' === $operator || 'EXISTS' === $operator) { |
|
1126 | 1126 | |
1127 | - $where = $wpdb->prepare( "$operator ( |
|
1127 | + $where = $wpdb->prepare("$operator ( |
|
1128 | 1128 | SELECT 1 |
1129 | 1129 | FROM $wpdb->term_relationships |
1130 | 1130 | INNER JOIN $wpdb->term_taxonomy |
1131 | 1131 | ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id |
1132 | 1132 | WHERE $wpdb->term_taxonomy.taxonomy = %s |
1133 | 1133 | AND $wpdb->term_relationships.object_id = $this->primary_table.$this->primary_id_column |
1134 | - )", $clause['taxonomy'] ); |
|
1134 | + )", $clause['taxonomy']); |
|
1135 | 1135 | |
1136 | 1136 | } |
1137 | 1137 | |
@@ -1160,32 +1160,32 @@ discard block |
||
1160 | 1160 | * @param array $parent_query Parent query of $clause. |
1161 | 1161 | * @return string|false Table alias if found, otherwise false. |
1162 | 1162 | */ |
1163 | - protected function find_compatible_table_alias( $clause, $parent_query ) { |
|
1163 | + protected function find_compatible_table_alias($clause, $parent_query) { |
|
1164 | 1164 | $alias = false; |
1165 | 1165 | |
1166 | 1166 | // Sanity check. Only IN queries use the JOIN syntax . |
1167 | - if ( ! isset( $clause['operator'] ) || 'IN' !== $clause['operator'] ) { |
|
1167 | + if ( ! isset($clause['operator']) || 'IN' !== $clause['operator']) { |
|
1168 | 1168 | return $alias; |
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | // Since we're only checking IN queries, we're only concerned with OR relations. |
1172 | - if ( ! isset( $parent_query['relation'] ) || 'OR' !== $parent_query['relation'] ) { |
|
1172 | + if ( ! isset($parent_query['relation']) || 'OR' !== $parent_query['relation']) { |
|
1173 | 1173 | return $alias; |
1174 | 1174 | } |
1175 | 1175 | |
1176 | - $compatible_operators = array( 'IN' ); |
|
1176 | + $compatible_operators = array('IN'); |
|
1177 | 1177 | |
1178 | - foreach ( $parent_query as $sibling ) { |
|
1179 | - if ( ! is_array( $sibling ) || ! $this->is_first_order_clause( $sibling ) ) { |
|
1178 | + foreach ($parent_query as $sibling) { |
|
1179 | + if ( ! is_array($sibling) || ! $this->is_first_order_clause($sibling)) { |
|
1180 | 1180 | continue; |
1181 | 1181 | } |
1182 | 1182 | |
1183 | - if ( empty( $sibling['alias'] ) || empty( $sibling['operator'] ) ) { |
|
1183 | + if (empty($sibling['alias']) || empty($sibling['operator'])) { |
|
1184 | 1184 | continue; |
1185 | 1185 | } |
1186 | 1186 | |
1187 | 1187 | // The sibling must both have compatible operator to share its alias. |
1188 | - if ( in_array( strtoupper( $sibling['operator'] ), $compatible_operators ) ) { |
|
1188 | + if (in_array(strtoupper($sibling['operator']), $compatible_operators)) { |
|
1189 | 1189 | $alias = $sibling['alias']; |
1190 | 1190 | break; |
1191 | 1191 | } |
@@ -1202,37 +1202,37 @@ discard block |
||
1202 | 1202 | * |
1203 | 1203 | * @param array &$query The single query. |
1204 | 1204 | */ |
1205 | - private function clean_query( &$query ) { |
|
1206 | - if ( empty( $query['taxonomy'] ) ) { |
|
1207 | - if ( 'term_taxonomy_id' !== $query['field'] ) { |
|
1208 | - $query = new WP_Error( 'Invalid taxonomy' ); |
|
1205 | + private function clean_query(&$query) { |
|
1206 | + if (empty($query['taxonomy'])) { |
|
1207 | + if ('term_taxonomy_id' !== $query['field']) { |
|
1208 | + $query = new WP_Error('Invalid taxonomy'); |
|
1209 | 1209 | return; |
1210 | 1210 | } |
1211 | 1211 | |
1212 | 1212 | // so long as there are shared terms, include_children requires that a taxonomy is set |
1213 | 1213 | $query['include_children'] = false; |
1214 | - } elseif ( ! taxonomy_exists( $query['taxonomy'] ) ) { |
|
1215 | - $query = new WP_Error( 'Invalid taxonomy' ); |
|
1214 | + } elseif ( ! taxonomy_exists($query['taxonomy'])) { |
|
1215 | + $query = new WP_Error('Invalid taxonomy'); |
|
1216 | 1216 | return; |
1217 | 1217 | } |
1218 | 1218 | |
1219 | - $query['terms'] = array_unique( (array) $query['terms'] ); |
|
1219 | + $query['terms'] = array_unique((array) $query['terms']); |
|
1220 | 1220 | |
1221 | - if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) { |
|
1222 | - $this->transform_query( $query, 'term_id' ); |
|
1221 | + if (is_taxonomy_hierarchical($query['taxonomy']) && $query['include_children']) { |
|
1222 | + $this->transform_query($query, 'term_id'); |
|
1223 | 1223 | |
1224 | - if ( is_wp_error( $query ) ) |
|
1224 | + if (is_wp_error($query)) |
|
1225 | 1225 | return; |
1226 | 1226 | |
1227 | 1227 | $children = array(); |
1228 | - foreach ( $query['terms'] as $term ) { |
|
1229 | - $children = array_merge( $children, get_term_children( $term, $query['taxonomy'] ) ); |
|
1228 | + foreach ($query['terms'] as $term) { |
|
1229 | + $children = array_merge($children, get_term_children($term, $query['taxonomy'])); |
|
1230 | 1230 | $children[] = $term; |
1231 | 1231 | } |
1232 | 1232 | $query['terms'] = $children; |
1233 | 1233 | } |
1234 | 1234 | |
1235 | - $this->transform_query( $query, 'term_taxonomy_id' ); |
|
1235 | + $this->transform_query($query, 'term_taxonomy_id'); |
|
1236 | 1236 | } |
1237 | 1237 | |
1238 | 1238 | /** |
@@ -1246,59 +1246,59 @@ discard block |
||
1246 | 1246 | * @param string $resulting_field The resulting field. Accepts 'slug', 'name', 'term_taxonomy_id', |
1247 | 1247 | * or 'term_id'. Default 'term_id'. |
1248 | 1248 | */ |
1249 | - public function transform_query( &$query, $resulting_field ) { |
|
1249 | + public function transform_query(&$query, $resulting_field) { |
|
1250 | 1250 | global $wpdb; |
1251 | 1251 | |
1252 | - if ( empty( $query['terms'] ) ) |
|
1252 | + if (empty($query['terms'])) |
|
1253 | 1253 | return; |
1254 | 1254 | |
1255 | - if ( $query['field'] == $resulting_field ) |
|
1255 | + if ($query['field'] == $resulting_field) |
|
1256 | 1256 | return; |
1257 | 1257 | |
1258 | - $resulting_field = sanitize_key( $resulting_field ); |
|
1258 | + $resulting_field = sanitize_key($resulting_field); |
|
1259 | 1259 | |
1260 | - switch ( $query['field'] ) { |
|
1260 | + switch ($query['field']) { |
|
1261 | 1261 | case 'slug': |
1262 | 1262 | case 'name': |
1263 | - foreach ( $query['terms'] as &$term ) { |
|
1263 | + foreach ($query['terms'] as &$term) { |
|
1264 | 1264 | /* |
1265 | 1265 | * 0 is the $term_id parameter. We don't have a term ID yet, but it doesn't |
1266 | 1266 | * matter because `sanitize_term_field()` ignores the $term_id param when the |
1267 | 1267 | * context is 'db'. |
1268 | 1268 | */ |
1269 | - $term = "'" . esc_sql( sanitize_term_field( $query['field'], $term, 0, $query['taxonomy'], 'db' ) ) . "'"; |
|
1269 | + $term = "'".esc_sql(sanitize_term_field($query['field'], $term, 0, $query['taxonomy'], 'db'))."'"; |
|
1270 | 1270 | } |
1271 | 1271 | |
1272 | - $terms = implode( ",", $query['terms'] ); |
|
1272 | + $terms = implode(",", $query['terms']); |
|
1273 | 1273 | |
1274 | - $terms = $wpdb->get_col( " |
|
1274 | + $terms = $wpdb->get_col(" |
|
1275 | 1275 | SELECT $wpdb->term_taxonomy.$resulting_field |
1276 | 1276 | FROM $wpdb->term_taxonomy |
1277 | 1277 | INNER JOIN $wpdb->terms USING (term_id) |
1278 | 1278 | WHERE taxonomy = '{$query['taxonomy']}' |
1279 | 1279 | AND $wpdb->terms.{$query['field']} IN ($terms) |
1280 | - " ); |
|
1280 | + "); |
|
1281 | 1281 | break; |
1282 | 1282 | case 'term_taxonomy_id': |
1283 | - $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); |
|
1284 | - $terms = $wpdb->get_col( " |
|
1283 | + $terms = implode(',', array_map('intval', $query['terms'])); |
|
1284 | + $terms = $wpdb->get_col(" |
|
1285 | 1285 | SELECT $resulting_field |
1286 | 1286 | FROM $wpdb->term_taxonomy |
1287 | 1287 | WHERE term_taxonomy_id IN ($terms) |
1288 | - " ); |
|
1288 | + "); |
|
1289 | 1289 | break; |
1290 | 1290 | default: |
1291 | - $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); |
|
1292 | - $terms = $wpdb->get_col( " |
|
1291 | + $terms = implode(',', array_map('intval', $query['terms'])); |
|
1292 | + $terms = $wpdb->get_col(" |
|
1293 | 1293 | SELECT $resulting_field |
1294 | 1294 | FROM $wpdb->term_taxonomy |
1295 | 1295 | WHERE taxonomy = '{$query['taxonomy']}' |
1296 | 1296 | AND term_id IN ($terms) |
1297 | - " ); |
|
1297 | + "); |
|
1298 | 1298 | } |
1299 | 1299 | |
1300 | - if ( 'AND' == $query['operator'] && count( $terms ) < count( $query['terms'] ) ) { |
|
1301 | - $query = new WP_Error( 'Inexistent terms' ); |
|
1300 | + if ('AND' == $query['operator'] && count($terms) < count($query['terms'])) { |
|
1301 | + $query = new WP_Error('Inexistent terms'); |
|
1302 | 1302 | return; |
1303 | 1303 | } |
1304 | 1304 | |
@@ -1349,27 +1349,27 @@ discard block |
||
1349 | 1349 | function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { |
1350 | 1350 | global $wpdb; |
1351 | 1351 | |
1352 | - if ( empty( $term ) ) { |
|
1353 | - return new WP_Error( 'invalid_term', __( 'Empty Term' ) ); |
|
1352 | + if (empty($term)) { |
|
1353 | + return new WP_Error('invalid_term', __('Empty Term')); |
|
1354 | 1354 | } |
1355 | 1355 | |
1356 | - if ( ! taxonomy_exists( $taxonomy ) ) { |
|
1357 | - return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); |
|
1356 | + if ( ! taxonomy_exists($taxonomy)) { |
|
1357 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | - if ( is_object($term) && empty($term->filter) ) { |
|
1361 | - wp_cache_add( $term->term_id, $term, $taxonomy ); |
|
1360 | + if (is_object($term) && empty($term->filter)) { |
|
1361 | + wp_cache_add($term->term_id, $term, $taxonomy); |
|
1362 | 1362 | $_term = $term; |
1363 | 1363 | } else { |
1364 | - if ( is_object($term) ) |
|
1364 | + if (is_object($term)) |
|
1365 | 1365 | $term = $term->term_id; |
1366 | - if ( !$term = (int) $term ) |
|
1366 | + if ( ! $term = (int) $term) |
|
1367 | 1367 | return null; |
1368 | - if ( ! $_term = wp_cache_get( $term, $taxonomy ) ) { |
|
1369 | - $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) ); |
|
1370 | - if ( ! $_term ) |
|
1368 | + if ( ! $_term = wp_cache_get($term, $taxonomy)) { |
|
1369 | + $_term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term)); |
|
1370 | + if ( ! $_term) |
|
1371 | 1371 | return null; |
1372 | - wp_cache_add( $term, $_term, $taxonomy ); |
|
1372 | + wp_cache_add($term, $_term, $taxonomy); |
|
1373 | 1373 | } |
1374 | 1374 | } |
1375 | 1375 | |
@@ -1381,7 +1381,7 @@ discard block |
||
1381 | 1381 | * @param int|object $_term Term object or ID. |
1382 | 1382 | * @param string $taxonomy The taxonomy slug. |
1383 | 1383 | */ |
1384 | - $_term = apply_filters( 'get_term', $_term, $taxonomy ); |
|
1384 | + $_term = apply_filters('get_term', $_term, $taxonomy); |
|
1385 | 1385 | |
1386 | 1386 | /** |
1387 | 1387 | * Filter a taxonomy. |
@@ -1394,15 +1394,15 @@ discard block |
||
1394 | 1394 | * @param int|object $_term Term object or ID. |
1395 | 1395 | * @param string $taxonomy The taxonomy slug. |
1396 | 1396 | */ |
1397 | - $_term = apply_filters( "get_$taxonomy", $_term, $taxonomy ); |
|
1397 | + $_term = apply_filters("get_$taxonomy", $_term, $taxonomy); |
|
1398 | 1398 | $_term = sanitize_term($_term, $taxonomy, $filter); |
1399 | 1399 | |
1400 | - if ( $output == OBJECT ) { |
|
1400 | + if ($output == OBJECT) { |
|
1401 | 1401 | return $_term; |
1402 | - } elseif ( $output == ARRAY_A ) { |
|
1402 | + } elseif ($output == ARRAY_A) { |
|
1403 | 1403 | $__term = get_object_vars($_term); |
1404 | 1404 | return $__term; |
1405 | - } elseif ( $output == ARRAY_N ) { |
|
1405 | + } elseif ($output == ARRAY_N) { |
|
1406 | 1406 | $__term = array_values(get_object_vars($_term)); |
1407 | 1407 | return $__term; |
1408 | 1408 | } else { |
@@ -1440,47 +1440,47 @@ discard block |
||
1440 | 1440 | function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') { |
1441 | 1441 | global $wpdb; |
1442 | 1442 | |
1443 | - if ( ! taxonomy_exists($taxonomy) ) |
|
1443 | + if ( ! taxonomy_exists($taxonomy)) |
|
1444 | 1444 | return false; |
1445 | 1445 | |
1446 | - if ( 'slug' == $field ) { |
|
1446 | + if ('slug' == $field) { |
|
1447 | 1447 | $field = 't.slug'; |
1448 | 1448 | $value = sanitize_title($value); |
1449 | - if ( empty($value) ) |
|
1449 | + if (empty($value)) |
|
1450 | 1450 | return false; |
1451 | - } elseif ( 'name' == $field ) { |
|
1451 | + } elseif ('name' == $field) { |
|
1452 | 1452 | // Assume already escaped |
1453 | 1453 | $value = wp_unslash($value); |
1454 | 1454 | $field = 't.name'; |
1455 | - } elseif ( 'term_taxonomy_id' == $field ) { |
|
1455 | + } elseif ('term_taxonomy_id' == $field) { |
|
1456 | 1456 | $value = (int) $value; |
1457 | 1457 | $field = 'tt.term_taxonomy_id'; |
1458 | 1458 | } else { |
1459 | - $term = get_term( (int) $value, $taxonomy, $output, $filter ); |
|
1460 | - if ( is_wp_error( $term ) ) |
|
1459 | + $term = get_term((int) $value, $taxonomy, $output, $filter); |
|
1460 | + if (is_wp_error($term)) |
|
1461 | 1461 | $term = false; |
1462 | 1462 | return $term; |
1463 | 1463 | } |
1464 | 1464 | |
1465 | - $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value ) ); |
|
1466 | - if ( ! $term ) |
|
1465 | + $term = $wpdb->get_row($wpdb->prepare("SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value)); |
|
1466 | + if ( ! $term) |
|
1467 | 1467 | return false; |
1468 | 1468 | |
1469 | - wp_cache_add( $term->term_id, $term, $taxonomy ); |
|
1469 | + wp_cache_add($term->term_id, $term, $taxonomy); |
|
1470 | 1470 | |
1471 | 1471 | /** This filter is documented in wp-includes/taxonomy.php */ |
1472 | - $term = apply_filters( 'get_term', $term, $taxonomy ); |
|
1472 | + $term = apply_filters('get_term', $term, $taxonomy); |
|
1473 | 1473 | |
1474 | 1474 | /** This filter is documented in wp-includes/taxonomy.php */ |
1475 | - $term = apply_filters( "get_$taxonomy", $term, $taxonomy ); |
|
1475 | + $term = apply_filters("get_$taxonomy", $term, $taxonomy); |
|
1476 | 1476 | |
1477 | 1477 | $term = sanitize_term($term, $taxonomy, $filter); |
1478 | 1478 | |
1479 | - if ( $output == OBJECT ) { |
|
1479 | + if ($output == OBJECT) { |
|
1480 | 1480 | return $term; |
1481 | - } elseif ( $output == ARRAY_A ) { |
|
1481 | + } elseif ($output == ARRAY_A) { |
|
1482 | 1482 | return get_object_vars($term); |
1483 | - } elseif ( $output == ARRAY_N ) { |
|
1483 | + } elseif ($output == ARRAY_N) { |
|
1484 | 1484 | return array_values(get_object_vars($term)); |
1485 | 1485 | } else { |
1486 | 1486 | return $term; |
@@ -1501,25 +1501,25 @@ discard block |
||
1501 | 1501 | * @param string $taxonomy Taxonomy Name. |
1502 | 1502 | * @return array|WP_Error List of Term IDs. WP_Error returned if `$taxonomy` does not exist. |
1503 | 1503 | */ |
1504 | -function get_term_children( $term_id, $taxonomy ) { |
|
1505 | - if ( ! taxonomy_exists($taxonomy) ) |
|
1504 | +function get_term_children($term_id, $taxonomy) { |
|
1505 | + if ( ! taxonomy_exists($taxonomy)) |
|
1506 | 1506 | return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
1507 | 1507 | |
1508 | - $term_id = intval( $term_id ); |
|
1508 | + $term_id = intval($term_id); |
|
1509 | 1509 | |
1510 | 1510 | $terms = _get_term_hierarchy($taxonomy); |
1511 | 1511 | |
1512 | - if ( ! isset($terms[$term_id]) ) |
|
1512 | + if ( ! isset($terms[$term_id])) |
|
1513 | 1513 | return array(); |
1514 | 1514 | |
1515 | 1515 | $children = $terms[$term_id]; |
1516 | 1516 | |
1517 | - foreach ( (array) $terms[$term_id] as $child ) { |
|
1518 | - if ( $term_id == $child ) { |
|
1517 | + foreach ((array) $terms[$term_id] as $child) { |
|
1518 | + if ($term_id == $child) { |
|
1519 | 1519 | continue; |
1520 | 1520 | } |
1521 | 1521 | |
1522 | - if ( isset($terms[$child]) ) |
|
1522 | + if (isset($terms[$child])) |
|
1523 | 1523 | $children = array_merge($children, get_term_children($child, $taxonomy)); |
1524 | 1524 | } |
1525 | 1525 | |
@@ -1541,16 +1541,16 @@ discard block |
||
1541 | 1541 | * @param string $context Optional, default is display. Look at sanitize_term_field() for available options. |
1542 | 1542 | * @return string|int|null|WP_Error Will return an empty string if $term is not an object or if $field is not set in $term. |
1543 | 1543 | */ |
1544 | -function get_term_field( $field, $term, $taxonomy, $context = 'display' ) { |
|
1544 | +function get_term_field($field, $term, $taxonomy, $context = 'display') { |
|
1545 | 1545 | $term = (int) $term; |
1546 | - $term = get_term( $term, $taxonomy ); |
|
1547 | - if ( is_wp_error($term) ) |
|
1546 | + $term = get_term($term, $taxonomy); |
|
1547 | + if (is_wp_error($term)) |
|
1548 | 1548 | return $term; |
1549 | 1549 | |
1550 | - if ( !is_object($term) ) |
|
1550 | + if ( ! is_object($term)) |
|
1551 | 1551 | return ''; |
1552 | 1552 | |
1553 | - if ( !isset($term->$field) ) |
|
1553 | + if ( ! isset($term->$field)) |
|
1554 | 1554 | return ''; |
1555 | 1555 | |
1556 | 1556 | return sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context); |
@@ -1568,13 +1568,13 @@ discard block |
||
1568 | 1568 | * @param string $taxonomy Taxonomy name. |
1569 | 1569 | * @return string|int|null|WP_Error Will return empty string if $term is not an object. |
1570 | 1570 | */ |
1571 | -function get_term_to_edit( $id, $taxonomy ) { |
|
1572 | - $term = get_term( $id, $taxonomy ); |
|
1571 | +function get_term_to_edit($id, $taxonomy) { |
|
1572 | + $term = get_term($id, $taxonomy); |
|
1573 | 1573 | |
1574 | - if ( is_wp_error($term) ) |
|
1574 | + if (is_wp_error($term)) |
|
1575 | 1575 | return $term; |
1576 | 1576 | |
1577 | - if ( !is_object($term) ) |
|
1577 | + if ( ! is_object($term)) |
|
1578 | 1578 | return ''; |
1579 | 1579 | |
1580 | 1580 | return sanitize_term($term, $taxonomy, 'edit'); |
@@ -1655,18 +1655,18 @@ discard block |
||
1655 | 1655 | * @return array|int|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies |
1656 | 1656 | * do not exist. |
1657 | 1657 | */ |
1658 | -function get_terms( $taxonomies, $args = '' ) { |
|
1658 | +function get_terms($taxonomies, $args = '') { |
|
1659 | 1659 | global $wpdb; |
1660 | 1660 | $empty_array = array(); |
1661 | 1661 | |
1662 | - $single_taxonomy = ! is_array( $taxonomies ) || 1 === count( $taxonomies ); |
|
1663 | - if ( ! is_array( $taxonomies ) ) { |
|
1664 | - $taxonomies = array( $taxonomies ); |
|
1662 | + $single_taxonomy = ! is_array($taxonomies) || 1 === count($taxonomies); |
|
1663 | + if ( ! is_array($taxonomies)) { |
|
1664 | + $taxonomies = array($taxonomies); |
|
1665 | 1665 | } |
1666 | 1666 | |
1667 | - foreach ( $taxonomies as $taxonomy ) { |
|
1668 | - if ( ! taxonomy_exists($taxonomy) ) { |
|
1669 | - return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); |
|
1667 | + foreach ($taxonomies as $taxonomy) { |
|
1668 | + if ( ! taxonomy_exists($taxonomy)) { |
|
1669 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
1670 | 1670 | } |
1671 | 1671 | } |
1672 | 1672 | |
@@ -1674,30 +1674,30 @@ discard block |
||
1674 | 1674 | 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), |
1675 | 1675 | 'number' => '', 'fields' => 'all', 'name' => '', 'slug' => '', 'parent' => '', 'childless' => false, |
1676 | 1676 | 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', |
1677 | - 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); |
|
1678 | - $args = wp_parse_args( $args, $defaults ); |
|
1679 | - $args['number'] = absint( $args['number'] ); |
|
1680 | - $args['offset'] = absint( $args['offset'] ); |
|
1677 | + 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core'); |
|
1678 | + $args = wp_parse_args($args, $defaults); |
|
1679 | + $args['number'] = absint($args['number']); |
|
1680 | + $args['offset'] = absint($args['offset']); |
|
1681 | 1681 | |
1682 | 1682 | // Save queries by not crawling the tree in the case of multiple taxes or a flat tax. |
1683 | 1683 | $has_hierarchical_tax = false; |
1684 | - foreach ( $taxonomies as $_tax ) { |
|
1685 | - if ( is_taxonomy_hierarchical( $_tax ) ) { |
|
1684 | + foreach ($taxonomies as $_tax) { |
|
1685 | + if (is_taxonomy_hierarchical($_tax)) { |
|
1686 | 1686 | $has_hierarchical_tax = true; |
1687 | 1687 | } |
1688 | 1688 | } |
1689 | 1689 | |
1690 | - if ( ! $has_hierarchical_tax ) { |
|
1690 | + if ( ! $has_hierarchical_tax) { |
|
1691 | 1691 | $args['hierarchical'] = false; |
1692 | 1692 | $args['pad_counts'] = false; |
1693 | 1693 | } |
1694 | 1694 | |
1695 | 1695 | // 'parent' overrides 'child_of'. |
1696 | - if ( 0 < intval( $args['parent'] ) ) { |
|
1696 | + if (0 < intval($args['parent'])) { |
|
1697 | 1697 | $args['child_of'] = false; |
1698 | 1698 | } |
1699 | 1699 | |
1700 | - if ( 'all' == $args['get'] ) { |
|
1700 | + if ('all' == $args['get']) { |
|
1701 | 1701 | $args['childless'] = false; |
1702 | 1702 | $args['child_of'] = 0; |
1703 | 1703 | $args['hide_empty'] = 0; |
@@ -1713,46 +1713,46 @@ discard block |
||
1713 | 1713 | * @param array $args An array of get_term() arguments. |
1714 | 1714 | * @param array $taxonomies An array of taxonomies. |
1715 | 1715 | */ |
1716 | - $args = apply_filters( 'get_terms_args', $args, $taxonomies ); |
|
1716 | + $args = apply_filters('get_terms_args', $args, $taxonomies); |
|
1717 | 1717 | |
1718 | 1718 | // Avoid the query if the queried parent/child_of term has no descendants. |
1719 | 1719 | $child_of = $args['child_of']; |
1720 | 1720 | $parent = $args['parent']; |
1721 | 1721 | |
1722 | - if ( $child_of ) { |
|
1722 | + if ($child_of) { |
|
1723 | 1723 | $_parent = $child_of; |
1724 | - } elseif ( $parent ) { |
|
1724 | + } elseif ($parent) { |
|
1725 | 1725 | $_parent = $parent; |
1726 | 1726 | } else { |
1727 | 1727 | $_parent = false; |
1728 | 1728 | } |
1729 | 1729 | |
1730 | - if ( $_parent ) { |
|
1730 | + if ($_parent) { |
|
1731 | 1731 | $in_hierarchy = false; |
1732 | - foreach ( $taxonomies as $_tax ) { |
|
1733 | - $hierarchy = _get_term_hierarchy( $_tax ); |
|
1732 | + foreach ($taxonomies as $_tax) { |
|
1733 | + $hierarchy = _get_term_hierarchy($_tax); |
|
1734 | 1734 | |
1735 | - if ( isset( $hierarchy[ $_parent ] ) ) { |
|
1735 | + if (isset($hierarchy[$_parent])) { |
|
1736 | 1736 | $in_hierarchy = true; |
1737 | 1737 | } |
1738 | 1738 | } |
1739 | 1739 | |
1740 | - if ( ! $in_hierarchy ) { |
|
1740 | + if ( ! $in_hierarchy) { |
|
1741 | 1741 | return $empty_array; |
1742 | 1742 | } |
1743 | 1743 | } |
1744 | 1744 | |
1745 | 1745 | // $args can be whatever, only use the args defined in defaults to compute the key. |
1746 | - $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : ''; |
|
1747 | - $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $defaults ) ) ) . serialize( $taxonomies ) . $filter_key ); |
|
1748 | - $last_changed = wp_cache_get( 'last_changed', 'terms' ); |
|
1749 | - if ( ! $last_changed ) { |
|
1746 | + $filter_key = (has_filter('list_terms_exclusions')) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : ''; |
|
1747 | + $key = md5(serialize(wp_array_slice_assoc($args, array_keys($defaults))).serialize($taxonomies).$filter_key); |
|
1748 | + $last_changed = wp_cache_get('last_changed', 'terms'); |
|
1749 | + if ( ! $last_changed) { |
|
1750 | 1750 | $last_changed = microtime(); |
1751 | - wp_cache_set( 'last_changed', $last_changed, 'terms' ); |
|
1751 | + wp_cache_set('last_changed', $last_changed, 'terms'); |
|
1752 | 1752 | } |
1753 | 1753 | $cache_key = "get_terms:$key:$last_changed"; |
1754 | - $cache = wp_cache_get( $cache_key, 'terms' ); |
|
1755 | - if ( false !== $cache ) { |
|
1754 | + $cache = wp_cache_get($cache_key, 'terms'); |
|
1755 | + if (false !== $cache) { |
|
1756 | 1756 | |
1757 | 1757 | /** |
1758 | 1758 | * Filter the given taxonomy's terms cache. |
@@ -1763,26 +1763,26 @@ discard block |
||
1763 | 1763 | * @param array $taxonomies An array of taxonomies. |
1764 | 1764 | * @param array $args An array of get_terms() arguments. |
1765 | 1765 | */ |
1766 | - return apply_filters( 'get_terms', $cache, $taxonomies, $args ); |
|
1766 | + return apply_filters('get_terms', $cache, $taxonomies, $args); |
|
1767 | 1767 | } |
1768 | 1768 | |
1769 | - $_orderby = strtolower( $args['orderby'] ); |
|
1770 | - if ( 'count' == $_orderby ) { |
|
1769 | + $_orderby = strtolower($args['orderby']); |
|
1770 | + if ('count' == $_orderby) { |
|
1771 | 1771 | $orderby = 'tt.count'; |
1772 | - } elseif ( 'name' == $_orderby ) { |
|
1772 | + } elseif ('name' == $_orderby) { |
|
1773 | 1773 | $orderby = 't.name'; |
1774 | - } elseif ( 'slug' == $_orderby ) { |
|
1774 | + } elseif ('slug' == $_orderby) { |
|
1775 | 1775 | $orderby = 't.slug'; |
1776 | - } elseif ( 'include' == $_orderby && ! empty( $args['include'] ) ) { |
|
1777 | - $include = implode( ',', array_map( 'absint', $args['include'] ) ); |
|
1776 | + } elseif ('include' == $_orderby && ! empty($args['include'])) { |
|
1777 | + $include = implode(',', array_map('absint', $args['include'])); |
|
1778 | 1778 | $orderby = "FIELD( t.term_id, $include )"; |
1779 | - } elseif ( 'term_group' == $_orderby ) { |
|
1779 | + } elseif ('term_group' == $_orderby) { |
|
1780 | 1780 | $orderby = 't.term_group'; |
1781 | - } elseif ( 'description' == $_orderby ) { |
|
1781 | + } elseif ('description' == $_orderby) { |
|
1782 | 1782 | $orderby = 'tt.description'; |
1783 | - } elseif ( 'none' == $_orderby ) { |
|
1783 | + } elseif ('none' == $_orderby) { |
|
1784 | 1784 | $orderby = ''; |
1785 | - } elseif ( empty($_orderby) || 'id' == $_orderby ) { |
|
1785 | + } elseif (empty($_orderby) || 'id' == $_orderby) { |
|
1786 | 1786 | $orderby = 't.term_id'; |
1787 | 1787 | } else { |
1788 | 1788 | $orderby = 't.name'; |
@@ -1797,65 +1797,65 @@ discard block |
||
1797 | 1797 | * @param array $args An array of terms query arguments. |
1798 | 1798 | * @param array $taxonomies An array of taxonomies. |
1799 | 1799 | */ |
1800 | - $orderby = apply_filters( 'get_terms_orderby', $orderby, $args, $taxonomies ); |
|
1800 | + $orderby = apply_filters('get_terms_orderby', $orderby, $args, $taxonomies); |
|
1801 | 1801 | |
1802 | - $order = strtoupper( $args['order'] ); |
|
1803 | - if ( ! empty( $orderby ) ) { |
|
1802 | + $order = strtoupper($args['order']); |
|
1803 | + if ( ! empty($orderby)) { |
|
1804 | 1804 | $orderby = "ORDER BY $orderby"; |
1805 | 1805 | } else { |
1806 | 1806 | $order = ''; |
1807 | 1807 | } |
1808 | 1808 | |
1809 | - if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) { |
|
1809 | + if ('' !== $order && ! in_array($order, array('ASC', 'DESC'))) { |
|
1810 | 1810 | $order = 'ASC'; |
1811 | 1811 | } |
1812 | 1812 | |
1813 | - $where = "tt.taxonomy IN ('" . implode("', '", $taxonomies) . "')"; |
|
1813 | + $where = "tt.taxonomy IN ('".implode("', '", $taxonomies)."')"; |
|
1814 | 1814 | |
1815 | 1815 | $exclude = $args['exclude']; |
1816 | 1816 | $exclude_tree = $args['exclude_tree']; |
1817 | 1817 | $include = $args['include']; |
1818 | 1818 | |
1819 | 1819 | $inclusions = ''; |
1820 | - if ( ! empty( $include ) ) { |
|
1820 | + if ( ! empty($include)) { |
|
1821 | 1821 | $exclude = ''; |
1822 | 1822 | $exclude_tree = ''; |
1823 | - $inclusions = implode( ',', wp_parse_id_list( $include ) ); |
|
1823 | + $inclusions = implode(',', wp_parse_id_list($include)); |
|
1824 | 1824 | } |
1825 | 1825 | |
1826 | - if ( ! empty( $inclusions ) ) { |
|
1827 | - $inclusions = ' AND t.term_id IN ( ' . $inclusions . ' )'; |
|
1826 | + if ( ! empty($inclusions)) { |
|
1827 | + $inclusions = ' AND t.term_id IN ( '.$inclusions.' )'; |
|
1828 | 1828 | $where .= $inclusions; |
1829 | 1829 | } |
1830 | 1830 | |
1831 | 1831 | $exclusions = array(); |
1832 | - if ( ! empty( $exclude_tree ) ) { |
|
1833 | - $exclude_tree = wp_parse_id_list( $exclude_tree ); |
|
1832 | + if ( ! empty($exclude_tree)) { |
|
1833 | + $exclude_tree = wp_parse_id_list($exclude_tree); |
|
1834 | 1834 | $excluded_children = $exclude_tree; |
1835 | - foreach ( $exclude_tree as $extrunk ) { |
|
1835 | + foreach ($exclude_tree as $extrunk) { |
|
1836 | 1836 | $excluded_children = array_merge( |
1837 | 1837 | $excluded_children, |
1838 | - (array) get_terms( $taxonomies[0], array( 'child_of' => intval( $extrunk ), 'fields' => 'ids', 'hide_empty' => 0 ) ) |
|
1838 | + (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids', 'hide_empty' => 0)) |
|
1839 | 1839 | ); |
1840 | 1840 | } |
1841 | - $exclusions = array_merge( $excluded_children, $exclusions ); |
|
1841 | + $exclusions = array_merge($excluded_children, $exclusions); |
|
1842 | 1842 | } |
1843 | 1843 | |
1844 | - if ( ! empty( $exclude ) ) { |
|
1845 | - $exclusions = array_merge( wp_parse_id_list( $exclude ), $exclusions ); |
|
1844 | + if ( ! empty($exclude)) { |
|
1845 | + $exclusions = array_merge(wp_parse_id_list($exclude), $exclusions); |
|
1846 | 1846 | } |
1847 | 1847 | |
1848 | 1848 | // 'childless' terms are those without an entry in the flattened term hierarchy. |
1849 | 1849 | $childless = (bool) $args['childless']; |
1850 | - if ( $childless ) { |
|
1851 | - foreach ( $taxonomies as $_tax ) { |
|
1852 | - $term_hierarchy = _get_term_hierarchy( $_tax ); |
|
1853 | - $exclusions = array_merge( array_keys( $term_hierarchy ), $exclusions ); |
|
1850 | + if ($childless) { |
|
1851 | + foreach ($taxonomies as $_tax) { |
|
1852 | + $term_hierarchy = _get_term_hierarchy($_tax); |
|
1853 | + $exclusions = array_merge(array_keys($term_hierarchy), $exclusions); |
|
1854 | 1854 | } |
1855 | 1855 | } |
1856 | 1856 | |
1857 | - if ( ! empty( $exclusions ) ) { |
|
1858 | - $exclusions = ' AND t.term_id NOT IN (' . implode( ',', array_map( 'intval', $exclusions ) ) . ')'; |
|
1857 | + if ( ! empty($exclusions)) { |
|
1858 | + $exclusions = ' AND t.term_id NOT IN ('.implode(',', array_map('intval', $exclusions)).')'; |
|
1859 | 1859 | } else { |
1860 | 1860 | $exclusions = ''; |
1861 | 1861 | } |
@@ -1869,49 +1869,49 @@ discard block |
||
1869 | 1869 | * @param array $args An array of terms query arguments. |
1870 | 1870 | * @param array $taxonomies An array of taxonomies. |
1871 | 1871 | */ |
1872 | - $exclusions = apply_filters( 'list_terms_exclusions', $exclusions, $args, $taxonomies ); |
|
1872 | + $exclusions = apply_filters('list_terms_exclusions', $exclusions, $args, $taxonomies); |
|
1873 | 1873 | |
1874 | - if ( ! empty( $exclusions ) ) { |
|
1874 | + if ( ! empty($exclusions)) { |
|
1875 | 1875 | $where .= $exclusions; |
1876 | 1876 | } |
1877 | 1877 | |
1878 | - if ( ! empty( $args['name'] ) ) { |
|
1878 | + if ( ! empty($args['name'])) { |
|
1879 | 1879 | $names = (array) $args['name']; |
1880 | - foreach ( $names as &$_name ) { |
|
1881 | - $_name = sanitize_term_field( 'name', $_name, 0, reset( $taxonomies ), 'db' ); |
|
1880 | + foreach ($names as &$_name) { |
|
1881 | + $_name = sanitize_term_field('name', $_name, 0, reset($taxonomies), 'db'); |
|
1882 | 1882 | } |
1883 | 1883 | |
1884 | - $where .= " AND t.name IN ('" . implode( "', '", array_map( 'esc_sql', $names ) ) . "')"; |
|
1884 | + $where .= " AND t.name IN ('".implode("', '", array_map('esc_sql', $names))."')"; |
|
1885 | 1885 | } |
1886 | 1886 | |
1887 | - if ( ! empty( $args['slug'] ) ) { |
|
1888 | - if ( is_array( $args['slug'] ) ) { |
|
1889 | - $slug = array_map( 'sanitize_title', $args['slug'] ); |
|
1890 | - $where .= " AND t.slug IN ('" . implode( "', '", $slug ) . "')"; |
|
1887 | + if ( ! empty($args['slug'])) { |
|
1888 | + if (is_array($args['slug'])) { |
|
1889 | + $slug = array_map('sanitize_title', $args['slug']); |
|
1890 | + $where .= " AND t.slug IN ('".implode("', '", $slug)."')"; |
|
1891 | 1891 | } else { |
1892 | - $slug = sanitize_title( $args['slug'] ); |
|
1892 | + $slug = sanitize_title($args['slug']); |
|
1893 | 1893 | $where .= " AND t.slug = '$slug'"; |
1894 | 1894 | } |
1895 | 1895 | } |
1896 | 1896 | |
1897 | - if ( ! empty( $args['name__like'] ) ) { |
|
1898 | - $where .= $wpdb->prepare( " AND t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' ); |
|
1897 | + if ( ! empty($args['name__like'])) { |
|
1898 | + $where .= $wpdb->prepare(" AND t.name LIKE %s", '%'.$wpdb->esc_like($args['name__like']).'%'); |
|
1899 | 1899 | } |
1900 | 1900 | |
1901 | - if ( ! empty( $args['description__like'] ) ) { |
|
1902 | - $where .= $wpdb->prepare( " AND tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' ); |
|
1901 | + if ( ! empty($args['description__like'])) { |
|
1902 | + $where .= $wpdb->prepare(" AND tt.description LIKE %s", '%'.$wpdb->esc_like($args['description__like']).'%'); |
|
1903 | 1903 | } |
1904 | 1904 | |
1905 | - if ( '' !== $parent ) { |
|
1905 | + if ('' !== $parent) { |
|
1906 | 1906 | $parent = (int) $parent; |
1907 | 1907 | $where .= " AND tt.parent = '$parent'"; |
1908 | 1908 | } |
1909 | 1909 | |
1910 | 1910 | $hierarchical = $args['hierarchical']; |
1911 | - if ( 'count' == $args['fields'] ) { |
|
1911 | + if ('count' == $args['fields']) { |
|
1912 | 1912 | $hierarchical = false; |
1913 | 1913 | } |
1914 | - if ( $args['hide_empty'] && !$hierarchical ) { |
|
1914 | + if ($args['hide_empty'] && ! $hierarchical) { |
|
1915 | 1915 | $where .= ' AND tt.count > 0'; |
1916 | 1916 | } |
1917 | 1917 | |
@@ -1919,43 +1919,43 @@ discard block |
||
1919 | 1919 | $offset = $args['offset']; |
1920 | 1920 | |
1921 | 1921 | // Don't limit the query results when we have to descend the family tree. |
1922 | - if ( $number && ! $hierarchical && ! $child_of && '' === $parent ) { |
|
1923 | - if ( $offset ) { |
|
1924 | - $limits = 'LIMIT ' . $offset . ',' . $number; |
|
1922 | + if ($number && ! $hierarchical && ! $child_of && '' === $parent) { |
|
1923 | + if ($offset) { |
|
1924 | + $limits = 'LIMIT '.$offset.','.$number; |
|
1925 | 1925 | } else { |
1926 | - $limits = 'LIMIT ' . $number; |
|
1926 | + $limits = 'LIMIT '.$number; |
|
1927 | 1927 | } |
1928 | 1928 | } else { |
1929 | 1929 | $limits = ''; |
1930 | 1930 | } |
1931 | 1931 | |
1932 | - if ( ! empty( $args['search'] ) ) { |
|
1933 | - $like = '%' . $wpdb->esc_like( $args['search'] ) . '%'; |
|
1934 | - $where .= $wpdb->prepare( ' AND ((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); |
|
1932 | + if ( ! empty($args['search'])) { |
|
1933 | + $like = '%'.$wpdb->esc_like($args['search']).'%'; |
|
1934 | + $where .= $wpdb->prepare(' AND ((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like); |
|
1935 | 1935 | } |
1936 | 1936 | |
1937 | 1937 | $selects = array(); |
1938 | - switch ( $args['fields'] ) { |
|
1938 | + switch ($args['fields']) { |
|
1939 | 1939 | case 'all': |
1940 | - $selects = array( 't.*', 'tt.*' ); |
|
1940 | + $selects = array('t.*', 'tt.*'); |
|
1941 | 1941 | break; |
1942 | 1942 | case 'ids': |
1943 | 1943 | case 'id=>parent': |
1944 | - $selects = array( 't.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy' ); |
|
1944 | + $selects = array('t.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy'); |
|
1945 | 1945 | break; |
1946 | 1946 | case 'names': |
1947 | - $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy' ); |
|
1947 | + $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy'); |
|
1948 | 1948 | break; |
1949 | 1949 | case 'count': |
1950 | 1950 | $orderby = ''; |
1951 | 1951 | $order = ''; |
1952 | - $selects = array( 'COUNT(*)' ); |
|
1952 | + $selects = array('COUNT(*)'); |
|
1953 | 1953 | break; |
1954 | 1954 | case 'id=>name': |
1955 | - $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' ); |
|
1955 | + $selects = array('t.term_id', 't.name', 'tt.count', 'tt.taxonomy'); |
|
1956 | 1956 | break; |
1957 | 1957 | case 'id=>slug': |
1958 | - $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' ); |
|
1958 | + $selects = array('t.term_id', 't.slug', 'tt.count', 'tt.taxonomy'); |
|
1959 | 1959 | break; |
1960 | 1960 | } |
1961 | 1961 | |
@@ -1977,11 +1977,11 @@ discard block |
||
1977 | 1977 | * @param array $args An array of term query arguments. |
1978 | 1978 | * @param array $taxonomies An array of taxonomies. |
1979 | 1979 | */ |
1980 | - $fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) ); |
|
1980 | + $fields = implode(', ', apply_filters('get_terms_fields', $selects, $args, $taxonomies)); |
|
1981 | 1981 | |
1982 | 1982 | $join = "INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id"; |
1983 | 1983 | |
1984 | - $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); |
|
1984 | + $pieces = array('fields', 'join', 'where', 'orderby', 'order', 'limits'); |
|
1985 | 1985 | |
1986 | 1986 | /** |
1987 | 1987 | * Filter the terms query SQL clauses. |
@@ -1992,58 +1992,58 @@ discard block |
||
1992 | 1992 | * @param array $taxonomies An array of taxonomies. |
1993 | 1993 | * @param array $args An array of terms query arguments. |
1994 | 1994 | */ |
1995 | - $clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args ); |
|
1995 | + $clauses = apply_filters('terms_clauses', compact($pieces), $taxonomies, $args); |
|
1996 | 1996 | |
1997 | - $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : ''; |
|
1998 | - $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : ''; |
|
1999 | - $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : ''; |
|
2000 | - $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : ''; |
|
2001 | - $order = isset( $clauses[ 'order' ] ) ? $clauses[ 'order' ] : ''; |
|
2002 | - $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
|
1997 | + $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; |
|
1998 | + $join = isset($clauses['join']) ? $clauses['join'] : ''; |
|
1999 | + $where = isset($clauses['where']) ? $clauses['where'] : ''; |
|
2000 | + $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; |
|
2001 | + $order = isset($clauses['order']) ? $clauses['order'] : ''; |
|
2002 | + $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; |
|
2003 | 2003 | |
2004 | 2004 | $query = "SELECT $fields FROM $wpdb->terms AS t $join WHERE $where $orderby $order $limits"; |
2005 | 2005 | |
2006 | - if ( 'count' == $_fields ) { |
|
2007 | - return $wpdb->get_var( $query ); |
|
2006 | + if ('count' == $_fields) { |
|
2007 | + return $wpdb->get_var($query); |
|
2008 | 2008 | } |
2009 | 2009 | |
2010 | 2010 | $terms = $wpdb->get_results($query); |
2011 | - if ( 'all' == $_fields ) { |
|
2012 | - update_term_cache( $terms ); |
|
2011 | + if ('all' == $_fields) { |
|
2012 | + update_term_cache($terms); |
|
2013 | 2013 | } |
2014 | 2014 | |
2015 | - if ( empty($terms) ) { |
|
2016 | - wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); |
|
2015 | + if (empty($terms)) { |
|
2016 | + wp_cache_add($cache_key, array(), 'terms', DAY_IN_SECONDS); |
|
2017 | 2017 | |
2018 | 2018 | /** This filter is documented in wp-includes/taxonomy.php */ |
2019 | - return apply_filters( 'get_terms', array(), $taxonomies, $args ); |
|
2019 | + return apply_filters('get_terms', array(), $taxonomies, $args); |
|
2020 | 2020 | } |
2021 | 2021 | |
2022 | - if ( $child_of ) { |
|
2023 | - foreach ( $taxonomies as $_tax ) { |
|
2024 | - $children = _get_term_hierarchy( $_tax ); |
|
2025 | - if ( ! empty( $children ) ) { |
|
2026 | - $terms = _get_term_children( $child_of, $terms, $_tax ); |
|
2022 | + if ($child_of) { |
|
2023 | + foreach ($taxonomies as $_tax) { |
|
2024 | + $children = _get_term_hierarchy($_tax); |
|
2025 | + if ( ! empty($children)) { |
|
2026 | + $terms = _get_term_children($child_of, $terms, $_tax); |
|
2027 | 2027 | } |
2028 | 2028 | } |
2029 | 2029 | } |
2030 | 2030 | |
2031 | 2031 | // Update term counts to include children. |
2032 | - if ( $args['pad_counts'] && 'all' == $_fields ) { |
|
2033 | - foreach ( $taxonomies as $_tax ) { |
|
2034 | - _pad_term_counts( $terms, $_tax ); |
|
2032 | + if ($args['pad_counts'] && 'all' == $_fields) { |
|
2033 | + foreach ($taxonomies as $_tax) { |
|
2034 | + _pad_term_counts($terms, $_tax); |
|
2035 | 2035 | } |
2036 | 2036 | } |
2037 | 2037 | |
2038 | 2038 | // Make sure we show empty categories that have children. |
2039 | - if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) { |
|
2040 | - foreach ( $terms as $k => $term ) { |
|
2041 | - if ( ! $term->count ) { |
|
2042 | - $children = get_term_children( $term->term_id, $term->taxonomy ); |
|
2043 | - if ( is_array( $children ) ) { |
|
2044 | - foreach ( $children as $child_id ) { |
|
2045 | - $child = get_term( $child_id, $term->taxonomy ); |
|
2046 | - if ( $child->count ) { |
|
2039 | + if ($hierarchical && $args['hide_empty'] && is_array($terms)) { |
|
2040 | + foreach ($terms as $k => $term) { |
|
2041 | + if ( ! $term->count) { |
|
2042 | + $children = get_term_children($term->term_id, $term->taxonomy); |
|
2043 | + if (is_array($children)) { |
|
2044 | + foreach ($children as $child_id) { |
|
2045 | + $child = get_term($child_id, $term->taxonomy); |
|
2046 | + if ($child->count) { |
|
2047 | 2047 | continue 2; |
2048 | 2048 | } |
2049 | 2049 | } |
@@ -2056,40 +2056,40 @@ discard block |
||
2056 | 2056 | } |
2057 | 2057 | |
2058 | 2058 | $_terms = array(); |
2059 | - if ( 'id=>parent' == $_fields ) { |
|
2060 | - foreach ( $terms as $term ) { |
|
2061 | - $_terms[ $term->term_id ] = $term->parent; |
|
2059 | + if ('id=>parent' == $_fields) { |
|
2060 | + foreach ($terms as $term) { |
|
2061 | + $_terms[$term->term_id] = $term->parent; |
|
2062 | 2062 | } |
2063 | - } elseif ( 'ids' == $_fields ) { |
|
2064 | - foreach ( $terms as $term ) { |
|
2063 | + } elseif ('ids' == $_fields) { |
|
2064 | + foreach ($terms as $term) { |
|
2065 | 2065 | $_terms[] = $term->term_id; |
2066 | 2066 | } |
2067 | - } elseif ( 'names' == $_fields ) { |
|
2068 | - foreach ( $terms as $term ) { |
|
2067 | + } elseif ('names' == $_fields) { |
|
2068 | + foreach ($terms as $term) { |
|
2069 | 2069 | $_terms[] = $term->name; |
2070 | 2070 | } |
2071 | - } elseif ( 'id=>name' == $_fields ) { |
|
2072 | - foreach ( $terms as $term ) { |
|
2073 | - $_terms[ $term->term_id ] = $term->name; |
|
2071 | + } elseif ('id=>name' == $_fields) { |
|
2072 | + foreach ($terms as $term) { |
|
2073 | + $_terms[$term->term_id] = $term->name; |
|
2074 | 2074 | } |
2075 | - } elseif ( 'id=>slug' == $_fields ) { |
|
2076 | - foreach ( $terms as $term ) { |
|
2077 | - $_terms[ $term->term_id ] = $term->slug; |
|
2075 | + } elseif ('id=>slug' == $_fields) { |
|
2076 | + foreach ($terms as $term) { |
|
2077 | + $_terms[$term->term_id] = $term->slug; |
|
2078 | 2078 | } |
2079 | 2079 | } |
2080 | 2080 | |
2081 | - if ( ! empty( $_terms ) ) { |
|
2081 | + if ( ! empty($_terms)) { |
|
2082 | 2082 | $terms = $_terms; |
2083 | 2083 | } |
2084 | 2084 | |
2085 | - if ( $number && is_array( $terms ) && count( $terms ) > $number ) { |
|
2086 | - $terms = array_slice( $terms, $offset, $number ); |
|
2085 | + if ($number && is_array($terms) && count($terms) > $number) { |
|
2086 | + $terms = array_slice($terms, $offset, $number); |
|
2087 | 2087 | } |
2088 | 2088 | |
2089 | - wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); |
|
2089 | + wp_cache_add($cache_key, $terms, 'terms', DAY_IN_SECONDS); |
|
2090 | 2090 | |
2091 | 2091 | /** This filter is documented in wp-includes/taxonomy */ |
2092 | - return apply_filters( 'get_terms', $terms, $taxonomies, $args ); |
|
2092 | + return apply_filters('get_terms', $terms, $taxonomies, $args); |
|
2093 | 2093 | } |
2094 | 2094 | |
2095 | 2095 | /** |
@@ -2109,24 +2109,24 @@ discard block |
||
2109 | 2109 | * an array of the term ID and the term taxonomy ID the taxonomy |
2110 | 2110 | * is specified and the pairing exists. |
2111 | 2111 | */ |
2112 | -function term_exists( $term, $taxonomy = '', $parent = null ) { |
|
2112 | +function term_exists($term, $taxonomy = '', $parent = null) { |
|
2113 | 2113 | global $wpdb; |
2114 | 2114 | |
2115 | 2115 | $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; |
2116 | 2116 | $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE "; |
2117 | 2117 | |
2118 | - if ( is_int($term) ) { |
|
2119 | - if ( 0 == $term ) |
|
2118 | + if (is_int($term)) { |
|
2119 | + if (0 == $term) |
|
2120 | 2120 | return 0; |
2121 | 2121 | $where = 't.term_id = %d'; |
2122 | - if ( !empty($taxonomy) ) |
|
2123 | - return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A ); |
|
2122 | + if ( ! empty($taxonomy)) |
|
2123 | + return $wpdb->get_row($wpdb->prepare($tax_select.$where." AND tt.taxonomy = %s", $term, $taxonomy), ARRAY_A); |
|
2124 | 2124 | else |
2125 | - return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) ); |
|
2125 | + return $wpdb->get_var($wpdb->prepare($select.$where, $term)); |
|
2126 | 2126 | } |
2127 | 2127 | |
2128 | - $term = trim( wp_unslash( $term ) ); |
|
2129 | - $slug = sanitize_title( $term ); |
|
2128 | + $term = trim(wp_unslash($term)); |
|
2129 | + $slug = sanitize_title($term); |
|
2130 | 2130 | |
2131 | 2131 | $where = 't.slug = %s'; |
2132 | 2132 | $else_where = 't.name = %s'; |
@@ -2134,8 +2134,8 @@ discard block |
||
2134 | 2134 | $else_where_fields = array($term); |
2135 | 2135 | $orderby = 'ORDER BY t.term_id ASC'; |
2136 | 2136 | $limit = 'LIMIT 1'; |
2137 | - if ( !empty($taxonomy) ) { |
|
2138 | - if ( is_numeric( $parent ) ) { |
|
2137 | + if ( ! empty($taxonomy)) { |
|
2138 | + if (is_numeric($parent)) { |
|
2139 | 2139 | $parent = (int) $parent; |
2140 | 2140 | $where_fields[] = $parent; |
2141 | 2141 | $else_where_fields[] = $parent; |
@@ -2146,16 +2146,16 @@ discard block |
||
2146 | 2146 | $where_fields[] = $taxonomy; |
2147 | 2147 | $else_where_fields[] = $taxonomy; |
2148 | 2148 | |
2149 | - if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields), ARRAY_A) ) |
|
2149 | + if ($result = $wpdb->get_row($wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields), ARRAY_A)) |
|
2150 | 2150 | return $result; |
2151 | 2151 | |
2152 | - return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields), ARRAY_A); |
|
2152 | + return $wpdb->get_row($wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields), ARRAY_A); |
|
2153 | 2153 | } |
2154 | 2154 | |
2155 | - if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields) ) ) |
|
2155 | + if ($result = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields))) |
|
2156 | 2156 | return $result; |
2157 | 2157 | |
2158 | - return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields) ); |
|
2158 | + return $wpdb->get_var($wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields)); |
|
2159 | 2159 | } |
2160 | 2160 | |
2161 | 2161 | /** |
@@ -2170,18 +2170,18 @@ discard block |
||
2170 | 2170 | * @param string $taxonomy Taxonomy name that $term1 and `$term2` belong to. |
2171 | 2171 | * @return bool Whether `$term2` is a child of `$term1`. |
2172 | 2172 | */ |
2173 | -function term_is_ancestor_of( $term1, $term2, $taxonomy ) { |
|
2174 | - if ( ! isset( $term1->term_id ) ) |
|
2175 | - $term1 = get_term( $term1, $taxonomy ); |
|
2176 | - if ( ! isset( $term2->parent ) ) |
|
2177 | - $term2 = get_term( $term2, $taxonomy ); |
|
2173 | +function term_is_ancestor_of($term1, $term2, $taxonomy) { |
|
2174 | + if ( ! isset($term1->term_id)) |
|
2175 | + $term1 = get_term($term1, $taxonomy); |
|
2176 | + if ( ! isset($term2->parent)) |
|
2177 | + $term2 = get_term($term2, $taxonomy); |
|
2178 | 2178 | |
2179 | - if ( empty( $term1->term_id ) || empty( $term2->parent ) ) |
|
2179 | + if (empty($term1->term_id) || empty($term2->parent)) |
|
2180 | 2180 | return false; |
2181 | - if ( $term2->parent == $term1->term_id ) |
|
2181 | + if ($term2->parent == $term1->term_id) |
|
2182 | 2182 | return true; |
2183 | 2183 | |
2184 | - return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy ); |
|
2184 | + return term_is_ancestor_of($term1, get_term($term2->parent, $taxonomy), $taxonomy); |
|
2185 | 2185 | } |
2186 | 2186 | |
2187 | 2187 | /** |
@@ -2202,23 +2202,23 @@ discard block |
||
2202 | 2202 | * @return array|object Term with all fields sanitized. |
2203 | 2203 | */ |
2204 | 2204 | function sanitize_term($term, $taxonomy, $context = 'display') { |
2205 | - $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' ); |
|
2205 | + $fields = array('term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id'); |
|
2206 | 2206 | |
2207 | - $do_object = is_object( $term ); |
|
2207 | + $do_object = is_object($term); |
|
2208 | 2208 | |
2209 | 2209 | $term_id = $do_object ? $term->term_id : (isset($term['term_id']) ? $term['term_id'] : 0); |
2210 | 2210 | |
2211 | - foreach ( (array) $fields as $field ) { |
|
2212 | - if ( $do_object ) { |
|
2213 | - if ( isset($term->$field) ) |
|
2211 | + foreach ((array) $fields as $field) { |
|
2212 | + if ($do_object) { |
|
2213 | + if (isset($term->$field)) |
|
2214 | 2214 | $term->$field = sanitize_term_field($field, $term->$field, $term_id, $taxonomy, $context); |
2215 | 2215 | } else { |
2216 | - if ( isset($term[$field]) ) |
|
2216 | + if (isset($term[$field])) |
|
2217 | 2217 | $term[$field] = sanitize_term_field($field, $term[$field], $term_id, $taxonomy, $context); |
2218 | 2218 | } |
2219 | 2219 | } |
2220 | 2220 | |
2221 | - if ( $do_object ) |
|
2221 | + if ($do_object) |
|
2222 | 2222 | $term->filter = $context; |
2223 | 2223 | else |
2224 | 2224 | $term['filter'] = $context; |
@@ -2250,17 +2250,17 @@ discard block |
||
2250 | 2250 | * @return mixed Sanitized field. |
2251 | 2251 | */ |
2252 | 2252 | function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { |
2253 | - $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' ); |
|
2254 | - if ( in_array( $field, $int_fields ) ) { |
|
2253 | + $int_fields = array('parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id'); |
|
2254 | + if (in_array($field, $int_fields)) { |
|
2255 | 2255 | $value = (int) $value; |
2256 | - if ( $value < 0 ) |
|
2256 | + if ($value < 0) |
|
2257 | 2257 | $value = 0; |
2258 | 2258 | } |
2259 | 2259 | |
2260 | - if ( 'raw' == $context ) |
|
2260 | + if ('raw' == $context) |
|
2261 | 2261 | return $value; |
2262 | 2262 | |
2263 | - if ( 'edit' == $context ) { |
|
2263 | + if ('edit' == $context) { |
|
2264 | 2264 | |
2265 | 2265 | /** |
2266 | 2266 | * Filter a term field to edit before it is sanitized. |
@@ -2273,7 +2273,7 @@ discard block |
||
2273 | 2273 | * @param int $term_id Term ID. |
2274 | 2274 | * @param string $taxonomy Taxonomy slug. |
2275 | 2275 | */ |
2276 | - $value = apply_filters( "edit_term_{$field}", $value, $term_id, $taxonomy ); |
|
2276 | + $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy); |
|
2277 | 2277 | |
2278 | 2278 | /** |
2279 | 2279 | * Filter the taxonomy field to edit before it is sanitized. |
@@ -2286,13 +2286,13 @@ discard block |
||
2286 | 2286 | * @param mixed $value Value of the taxonomy field to edit. |
2287 | 2287 | * @param int $term_id Term ID. |
2288 | 2288 | */ |
2289 | - $value = apply_filters( "edit_{$taxonomy}_{$field}", $value, $term_id ); |
|
2289 | + $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id); |
|
2290 | 2290 | |
2291 | - if ( 'description' == $field ) |
|
2291 | + if ('description' == $field) |
|
2292 | 2292 | $value = esc_html($value); // textarea_escaped |
2293 | 2293 | else |
2294 | 2294 | $value = esc_attr($value); |
2295 | - } elseif ( 'db' == $context ) { |
|
2295 | + } elseif ('db' == $context) { |
|
2296 | 2296 | |
2297 | 2297 | /** |
2298 | 2298 | * Filter a term field value before it is sanitized. |
@@ -2304,7 +2304,7 @@ discard block |
||
2304 | 2304 | * @param mixed $value Value of the term field. |
2305 | 2305 | * @param string $taxonomy Taxonomy slug. |
2306 | 2306 | */ |
2307 | - $value = apply_filters( "pre_term_{$field}", $value, $taxonomy ); |
|
2307 | + $value = apply_filters("pre_term_{$field}", $value, $taxonomy); |
|
2308 | 2308 | |
2309 | 2309 | /** |
2310 | 2310 | * Filter a taxonomy field before it is sanitized. |
@@ -2316,10 +2316,10 @@ discard block |
||
2316 | 2316 | * |
2317 | 2317 | * @param mixed $value Value of the taxonomy field. |
2318 | 2318 | */ |
2319 | - $value = apply_filters( "pre_{$taxonomy}_{$field}", $value ); |
|
2319 | + $value = apply_filters("pre_{$taxonomy}_{$field}", $value); |
|
2320 | 2320 | |
2321 | 2321 | // Back compat filters |
2322 | - if ( 'slug' == $field ) { |
|
2322 | + if ('slug' == $field) { |
|
2323 | 2323 | /** |
2324 | 2324 | * Filter the category nicename before it is sanitized. |
2325 | 2325 | * |
@@ -2329,10 +2329,10 @@ discard block |
||
2329 | 2329 | * |
2330 | 2330 | * @param string $value The category nicename. |
2331 | 2331 | */ |
2332 | - $value = apply_filters( 'pre_category_nicename', $value ); |
|
2332 | + $value = apply_filters('pre_category_nicename', $value); |
|
2333 | 2333 | } |
2334 | 2334 | |
2335 | - } elseif ( 'rss' == $context ) { |
|
2335 | + } elseif ('rss' == $context) { |
|
2336 | 2336 | |
2337 | 2337 | /** |
2338 | 2338 | * Filter the term field for use in RSS. |
@@ -2344,7 +2344,7 @@ discard block |
||
2344 | 2344 | * @param mixed $value Value of the term field. |
2345 | 2345 | * @param string $taxonomy Taxonomy slug. |
2346 | 2346 | */ |
2347 | - $value = apply_filters( "term_{$field}_rss", $value, $taxonomy ); |
|
2347 | + $value = apply_filters("term_{$field}_rss", $value, $taxonomy); |
|
2348 | 2348 | |
2349 | 2349 | /** |
2350 | 2350 | * Filter the taxonomy field for use in RSS. |
@@ -2356,7 +2356,7 @@ discard block |
||
2356 | 2356 | * |
2357 | 2357 | * @param mixed $value Value of the taxonomy field. |
2358 | 2358 | */ |
2359 | - $value = apply_filters( "{$taxonomy}_{$field}_rss", $value ); |
|
2359 | + $value = apply_filters("{$taxonomy}_{$field}_rss", $value); |
|
2360 | 2360 | } else { |
2361 | 2361 | // Use display filters by default. |
2362 | 2362 | |
@@ -2372,7 +2372,7 @@ discard block |
||
2372 | 2372 | * @param string $taxonomy Taxonomy slug. |
2373 | 2373 | * @param string $context Context to retrieve the term field value. |
2374 | 2374 | */ |
2375 | - $value = apply_filters( "term_{$field}", $value, $term_id, $taxonomy, $context ); |
|
2375 | + $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context); |
|
2376 | 2376 | |
2377 | 2377 | /** |
2378 | 2378 | * Filter the taxonomy field sanitized for display. |
@@ -2386,12 +2386,12 @@ discard block |
||
2386 | 2386 | * @param int $term_id Term ID. |
2387 | 2387 | * @param string $context Context to retrieve the taxonomy field value. |
2388 | 2388 | */ |
2389 | - $value = apply_filters( "{$taxonomy}_{$field}", $value, $term_id, $context ); |
|
2389 | + $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context); |
|
2390 | 2390 | } |
2391 | 2391 | |
2392 | - if ( 'attribute' == $context ) { |
|
2392 | + if ('attribute' == $context) { |
|
2393 | 2393 | $value = esc_attr($value); |
2394 | - } elseif ( 'js' == $context ) { |
|
2394 | + } elseif ('js' == $context) { |
|
2395 | 2395 | $value = esc_js($value); |
2396 | 2396 | } |
2397 | 2397 | return $value; |
@@ -2410,12 +2410,12 @@ discard block |
||
2410 | 2410 | * @param array|string $args Overwrite defaults. See get_terms() |
2411 | 2411 | * @return array|int|WP_Error How many terms are in $taxonomy. WP_Error if $taxonomy does not exist. |
2412 | 2412 | */ |
2413 | -function wp_count_terms( $taxonomy, $args = array() ) { |
|
2413 | +function wp_count_terms($taxonomy, $args = array()) { |
|
2414 | 2414 | $defaults = array('hide_empty' => false); |
2415 | 2415 | $args = wp_parse_args($args, $defaults); |
2416 | 2416 | |
2417 | 2417 | // backwards compatibility |
2418 | - if ( isset($args['ignore_empty']) ) { |
|
2418 | + if (isset($args['ignore_empty'])) { |
|
2419 | 2419 | $args['hide_empty'] = $args['ignore_empty']; |
2420 | 2420 | unset($args['ignore_empty']); |
2421 | 2421 | } |
@@ -2437,16 +2437,16 @@ discard block |
||
2437 | 2437 | * @param int $object_id The term Object Id that refers to the term. |
2438 | 2438 | * @param string|array $taxonomies List of Taxonomy Names or single Taxonomy name. |
2439 | 2439 | */ |
2440 | -function wp_delete_object_term_relationships( $object_id, $taxonomies ) { |
|
2440 | +function wp_delete_object_term_relationships($object_id, $taxonomies) { |
|
2441 | 2441 | $object_id = (int) $object_id; |
2442 | 2442 | |
2443 | - if ( !is_array($taxonomies) ) |
|
2443 | + if ( ! is_array($taxonomies)) |
|
2444 | 2444 | $taxonomies = array($taxonomies); |
2445 | 2445 | |
2446 | - foreach ( (array) $taxonomies as $taxonomy ) { |
|
2447 | - $term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids' ) ); |
|
2448 | - $term_ids = array_map( 'intval', $term_ids ); |
|
2449 | - wp_remove_object_terms( $object_id, $term_ids, $taxonomy ); |
|
2446 | + foreach ((array) $taxonomies as $taxonomy) { |
|
2447 | + $term_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'ids')); |
|
2448 | + $term_ids = array_map('intval', $term_ids); |
|
2449 | + wp_remove_object_terms($object_id, $term_ids, $taxonomy); |
|
2450 | 2450 | } |
2451 | 2451 | } |
2452 | 2452 | |
@@ -2473,36 +2473,36 @@ discard block |
||
2473 | 2473 | * @param array|string $args Optional. Change 'default' term id and override found term ids. |
2474 | 2474 | * @return bool|int|WP_Error Returns false if not term; true if completes delete action. |
2475 | 2475 | */ |
2476 | -function wp_delete_term( $term, $taxonomy, $args = array() ) { |
|
2476 | +function wp_delete_term($term, $taxonomy, $args = array()) { |
|
2477 | 2477 | global $wpdb; |
2478 | 2478 | |
2479 | 2479 | $term = (int) $term; |
2480 | 2480 | |
2481 | - if ( ! $ids = term_exists($term, $taxonomy) ) |
|
2481 | + if ( ! $ids = term_exists($term, $taxonomy)) |
|
2482 | 2482 | return false; |
2483 | - if ( is_wp_error( $ids ) ) |
|
2483 | + if (is_wp_error($ids)) |
|
2484 | 2484 | return $ids; |
2485 | 2485 | |
2486 | 2486 | $tt_id = $ids['term_taxonomy_id']; |
2487 | 2487 | |
2488 | 2488 | $defaults = array(); |
2489 | 2489 | |
2490 | - if ( 'category' == $taxonomy ) { |
|
2491 | - $defaults['default'] = get_option( 'default_category' ); |
|
2492 | - if ( $defaults['default'] == $term ) |
|
2490 | + if ('category' == $taxonomy) { |
|
2491 | + $defaults['default'] = get_option('default_category'); |
|
2492 | + if ($defaults['default'] == $term) |
|
2493 | 2493 | return 0; // Don't delete the default category |
2494 | 2494 | } |
2495 | 2495 | |
2496 | 2496 | $args = wp_parse_args($args, $defaults); |
2497 | 2497 | |
2498 | - if ( isset( $args['default'] ) ) { |
|
2498 | + if (isset($args['default'])) { |
|
2499 | 2499 | $default = (int) $args['default']; |
2500 | - if ( ! term_exists( $default, $taxonomy ) ) { |
|
2501 | - unset( $default ); |
|
2500 | + if ( ! term_exists($default, $taxonomy)) { |
|
2501 | + unset($default); |
|
2502 | 2502 | } |
2503 | 2503 | } |
2504 | 2504 | |
2505 | - if ( isset( $args['force_default'] ) ) { |
|
2505 | + if (isset($args['force_default'])) { |
|
2506 | 2506 | $force_default = $args['force_default']; |
2507 | 2507 | } |
2508 | 2508 | |
@@ -2514,17 +2514,17 @@ discard block |
||
2514 | 2514 | * @param int $term Term ID. |
2515 | 2515 | * @param string $taxonomy Taxonomy Name. |
2516 | 2516 | */ |
2517 | - do_action( 'pre_delete_term', $term, $taxonomy ); |
|
2517 | + do_action('pre_delete_term', $term, $taxonomy); |
|
2518 | 2518 | |
2519 | 2519 | // Update children to point to new parent |
2520 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
2520 | + if (is_taxonomy_hierarchical($taxonomy)) { |
|
2521 | 2521 | $term_obj = get_term($term, $taxonomy); |
2522 | - if ( is_wp_error( $term_obj ) ) |
|
2522 | + if (is_wp_error($term_obj)) |
|
2523 | 2523 | return $term_obj; |
2524 | 2524 | $parent = $term_obj->parent; |
2525 | 2525 | |
2526 | - $edit_ids = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int)$term_obj->term_id ); |
|
2527 | - $edit_tt_ids = wp_list_pluck( $edit_ids, 'term_taxonomy_id' ); |
|
2526 | + $edit_ids = $wpdb->get_results("SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = ".(int) $term_obj->term_id); |
|
2527 | + $edit_tt_ids = wp_list_pluck($edit_ids, 'term_taxonomy_id'); |
|
2528 | 2528 | |
2529 | 2529 | /** |
2530 | 2530 | * Fires immediately before a term to delete's children are reassigned a parent. |
@@ -2533,13 +2533,13 @@ discard block |
||
2533 | 2533 | * |
2534 | 2534 | * @param array $edit_tt_ids An array of term taxonomy IDs for the given term. |
2535 | 2535 | */ |
2536 | - do_action( 'edit_term_taxonomies', $edit_tt_ids ); |
|
2536 | + do_action('edit_term_taxonomies', $edit_tt_ids); |
|
2537 | 2537 | |
2538 | - $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id) + compact( 'taxonomy' ) ); |
|
2538 | + $wpdb->update($wpdb->term_taxonomy, compact('parent'), array('parent' => $term_obj->term_id) + compact('taxonomy')); |
|
2539 | 2539 | |
2540 | 2540 | // Clean the cache for all child terms. |
2541 | - $edit_term_ids = wp_list_pluck( $edit_ids, 'term_id' ); |
|
2542 | - clean_term_cache( $edit_term_ids, $taxonomy ); |
|
2541 | + $edit_term_ids = wp_list_pluck($edit_ids, 'term_id'); |
|
2542 | + clean_term_cache($edit_term_ids, $taxonomy); |
|
2543 | 2543 | |
2544 | 2544 | /** |
2545 | 2545 | * Fires immediately after a term to delete's children are reassigned a parent. |
@@ -2548,14 +2548,14 @@ discard block |
||
2548 | 2548 | * |
2549 | 2549 | * @param array $edit_tt_ids An array of term taxonomy IDs for the given term. |
2550 | 2550 | */ |
2551 | - do_action( 'edited_term_taxonomies', $edit_tt_ids ); |
|
2551 | + do_action('edited_term_taxonomies', $edit_tt_ids); |
|
2552 | 2552 | } |
2553 | 2553 | |
2554 | - $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) ); |
|
2554 | + $objects = $wpdb->get_col($wpdb->prepare("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id)); |
|
2555 | 2555 | |
2556 | - foreach ( (array) $objects as $object ) { |
|
2556 | + foreach ((array) $objects as $object) { |
|
2557 | 2557 | $terms = wp_get_object_terms($object, $taxonomy, array('fields' => 'ids', 'orderby' => 'none')); |
2558 | - if ( 1 == count($terms) && isset($default) ) { |
|
2558 | + if (1 == count($terms) && isset($default)) { |
|
2559 | 2559 | $terms = array($default); |
2560 | 2560 | } else { |
2561 | 2561 | $terms = array_diff($terms, array($term)); |
@@ -2567,12 +2567,12 @@ discard block |
||
2567 | 2567 | } |
2568 | 2568 | |
2569 | 2569 | // Clean the relationship caches for all object types using this term. |
2570 | - $tax_object = get_taxonomy( $taxonomy ); |
|
2571 | - foreach ( $tax_object->object_type as $object_type ) |
|
2572 | - clean_object_term_cache( $objects, $object_type ); |
|
2570 | + $tax_object = get_taxonomy($taxonomy); |
|
2571 | + foreach ($tax_object->object_type as $object_type) |
|
2572 | + clean_object_term_cache($objects, $object_type); |
|
2573 | 2573 | |
2574 | 2574 | // Get the object before deletion so we can pass to actions below |
2575 | - $deleted_term = get_term( $term, $taxonomy ); |
|
2575 | + $deleted_term = get_term($term, $taxonomy); |
|
2576 | 2576 | |
2577 | 2577 | /** |
2578 | 2578 | * Fires immediately before a term taxonomy ID is deleted. |
@@ -2581,8 +2581,8 @@ discard block |
||
2581 | 2581 | * |
2582 | 2582 | * @param int $tt_id Term taxonomy ID. |
2583 | 2583 | */ |
2584 | - do_action( 'delete_term_taxonomy', $tt_id ); |
|
2585 | - $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); |
|
2584 | + do_action('delete_term_taxonomy', $tt_id); |
|
2585 | + $wpdb->delete($wpdb->term_taxonomy, array('term_taxonomy_id' => $tt_id)); |
|
2586 | 2586 | |
2587 | 2587 | /** |
2588 | 2588 | * Fires immediately after a term taxonomy ID is deleted. |
@@ -2591,11 +2591,11 @@ discard block |
||
2591 | 2591 | * |
2592 | 2592 | * @param int $tt_id Term taxonomy ID. |
2593 | 2593 | */ |
2594 | - do_action( 'deleted_term_taxonomy', $tt_id ); |
|
2594 | + do_action('deleted_term_taxonomy', $tt_id); |
|
2595 | 2595 | |
2596 | 2596 | // Delete the term if no taxonomies use it. |
2597 | - if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) |
|
2598 | - $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); |
|
2597 | + if ( ! $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term))) |
|
2598 | + $wpdb->delete($wpdb->terms, array('term_id' => $term)); |
|
2599 | 2599 | |
2600 | 2600 | clean_term_cache($term, $taxonomy); |
2601 | 2601 | |
@@ -2610,7 +2610,7 @@ discard block |
||
2610 | 2610 | * @param mixed $deleted_term Copy of the already-deleted term, in the form specified |
2611 | 2611 | * by the parent function. WP_Error otherwise. |
2612 | 2612 | */ |
2613 | - do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term ); |
|
2613 | + do_action('delete_term', $term, $tt_id, $taxonomy, $deleted_term); |
|
2614 | 2614 | |
2615 | 2615 | /** |
2616 | 2616 | * Fires after a term in a specific taxonomy is deleted. |
@@ -2625,7 +2625,7 @@ discard block |
||
2625 | 2625 | * @param mixed $deleted_term Copy of the already-deleted term, in the form specified |
2626 | 2626 | * by the parent function. WP_Error otherwise. |
2627 | 2627 | */ |
2628 | - do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term ); |
|
2628 | + do_action("delete_$taxonomy", $term, $tt_id, $deleted_term); |
|
2629 | 2629 | |
2630 | 2630 | return true; |
2631 | 2631 | } |
@@ -2639,8 +2639,8 @@ discard block |
||
2639 | 2639 | * @return bool|int|WP_Error Returns true if completes delete action; false if term doesn't exist; |
2640 | 2640 | * Zero on attempted deletion of default Category; WP_Error object is also a possibility. |
2641 | 2641 | */ |
2642 | -function wp_delete_category( $cat_ID ) { |
|
2643 | - return wp_delete_term( $cat_ID, 'category' ); |
|
2642 | +function wp_delete_category($cat_ID) { |
|
2643 | + return wp_delete_term($cat_ID, 'category'); |
|
2644 | 2644 | } |
2645 | 2645 | |
2646 | 2646 | /** |
@@ -2671,18 +2671,18 @@ discard block |
||
2671 | 2671 | function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { |
2672 | 2672 | global $wpdb; |
2673 | 2673 | |
2674 | - if ( empty( $object_ids ) || empty( $taxonomies ) ) |
|
2674 | + if (empty($object_ids) || empty($taxonomies)) |
|
2675 | 2675 | return array(); |
2676 | 2676 | |
2677 | - if ( !is_array($taxonomies) ) |
|
2677 | + if ( ! is_array($taxonomies)) |
|
2678 | 2678 | $taxonomies = array($taxonomies); |
2679 | 2679 | |
2680 | - foreach ( $taxonomies as $taxonomy ) { |
|
2681 | - if ( ! taxonomy_exists($taxonomy) ) |
|
2680 | + foreach ($taxonomies as $taxonomy) { |
|
2681 | + if ( ! taxonomy_exists($taxonomy)) |
|
2682 | 2682 | return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
2683 | 2683 | } |
2684 | 2684 | |
2685 | - if ( !is_array($object_ids) ) |
|
2685 | + if ( ! is_array($object_ids)) |
|
2686 | 2686 | $object_ids = array($object_ids); |
2687 | 2687 | $object_ids = array_map('intval', $object_ids); |
2688 | 2688 | |
@@ -2692,20 +2692,20 @@ discard block |
||
2692 | 2692 | 'fields' => 'all', |
2693 | 2693 | 'parent' => '', |
2694 | 2694 | ); |
2695 | - $args = wp_parse_args( $args, $defaults ); |
|
2695 | + $args = wp_parse_args($args, $defaults); |
|
2696 | 2696 | |
2697 | 2697 | $terms = array(); |
2698 | - if ( count($taxonomies) > 1 ) { |
|
2699 | - foreach ( $taxonomies as $index => $taxonomy ) { |
|
2698 | + if (count($taxonomies) > 1) { |
|
2699 | + foreach ($taxonomies as $index => $taxonomy) { |
|
2700 | 2700 | $t = get_taxonomy($taxonomy); |
2701 | - if ( isset($t->args) && is_array($t->args) && $args != array_merge($args, $t->args) ) { |
|
2701 | + if (isset($t->args) && is_array($t->args) && $args != array_merge($args, $t->args)) { |
|
2702 | 2702 | unset($taxonomies[$index]); |
2703 | 2703 | $terms = array_merge($terms, wp_get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args))); |
2704 | 2704 | } |
2705 | 2705 | } |
2706 | 2706 | } else { |
2707 | 2707 | $t = get_taxonomy($taxonomies[0]); |
2708 | - if ( isset($t->args) && is_array($t->args) ) |
|
2708 | + if (isset($t->args) && is_array($t->args)) |
|
2709 | 2709 | $args = array_merge($args, $t->args); |
2710 | 2710 | } |
2711 | 2711 | |
@@ -2713,13 +2713,13 @@ discard block |
||
2713 | 2713 | $order = $args['order']; |
2714 | 2714 | $fields = $args['fields']; |
2715 | 2715 | |
2716 | - if ( in_array( $orderby, array( 'term_id', 'name', 'slug', 'term_group' ) ) ) { |
|
2716 | + if (in_array($orderby, array('term_id', 'name', 'slug', 'term_group'))) { |
|
2717 | 2717 | $orderby = "t.$orderby"; |
2718 | - } elseif ( in_array( $orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id' ) ) ) { |
|
2718 | + } elseif (in_array($orderby, array('count', 'parent', 'taxonomy', 'term_taxonomy_id'))) { |
|
2719 | 2719 | $orderby = "tt.$orderby"; |
2720 | - } elseif ( 'term_order' === $orderby ) { |
|
2720 | + } elseif ('term_order' === $orderby) { |
|
2721 | 2721 | $orderby = 'tr.term_order'; |
2722 | - } elseif ( 'none' === $orderby ) { |
|
2722 | + } elseif ('none' === $orderby) { |
|
2723 | 2723 | $orderby = ''; |
2724 | 2724 | $order = ''; |
2725 | 2725 | } else { |
@@ -2727,31 +2727,31 @@ discard block |
||
2727 | 2727 | } |
2728 | 2728 | |
2729 | 2729 | // tt_ids queries can only be none or tr.term_taxonomy_id |
2730 | - if ( ('tt_ids' == $fields) && !empty($orderby) ) |
|
2730 | + if (('tt_ids' == $fields) && ! empty($orderby)) |
|
2731 | 2731 | $orderby = 'tr.term_taxonomy_id'; |
2732 | 2732 | |
2733 | - if ( !empty($orderby) ) |
|
2733 | + if ( ! empty($orderby)) |
|
2734 | 2734 | $orderby = "ORDER BY $orderby"; |
2735 | 2735 | |
2736 | - $order = strtoupper( $order ); |
|
2737 | - if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) |
|
2736 | + $order = strtoupper($order); |
|
2737 | + if ('' !== $order && ! in_array($order, array('ASC', 'DESC'))) |
|
2738 | 2738 | $order = 'ASC'; |
2739 | 2739 | |
2740 | 2740 | $taxonomy_array = $taxonomies; |
2741 | 2741 | $object_id_array = $object_ids; |
2742 | - $taxonomies = "'" . implode("', '", $taxonomies) . "'"; |
|
2742 | + $taxonomies = "'".implode("', '", $taxonomies)."'"; |
|
2743 | 2743 | $object_ids = implode(', ', $object_ids); |
2744 | 2744 | |
2745 | 2745 | $select_this = ''; |
2746 | - if ( 'all' == $fields ) { |
|
2746 | + if ('all' == $fields) { |
|
2747 | 2747 | $select_this = 't.*, tt.*'; |
2748 | - } elseif ( 'ids' == $fields ) { |
|
2748 | + } elseif ('ids' == $fields) { |
|
2749 | 2749 | $select_this = 't.term_id'; |
2750 | - } elseif ( 'names' == $fields ) { |
|
2750 | + } elseif ('names' == $fields) { |
|
2751 | 2751 | $select_this = 't.name'; |
2752 | - } elseif ( 'slugs' == $fields ) { |
|
2752 | + } elseif ('slugs' == $fields) { |
|
2753 | 2753 | $select_this = 't.slug'; |
2754 | - } elseif ( 'all_with_object_id' == $fields ) { |
|
2754 | + } elseif ('all_with_object_id' == $fields) { |
|
2755 | 2755 | $select_this = 't.*, tt.*, tr.object_id'; |
2756 | 2756 | } |
2757 | 2757 | |
@@ -2760,44 +2760,44 @@ discard block |
||
2760 | 2760 | "tr.object_id IN ($object_ids)", |
2761 | 2761 | ); |
2762 | 2762 | |
2763 | - if ( '' !== $args['parent'] ) { |
|
2764 | - $where[] = $wpdb->prepare( 'tt.parent = %d', $args['parent'] ); |
|
2763 | + if ('' !== $args['parent']) { |
|
2764 | + $where[] = $wpdb->prepare('tt.parent = %d', $args['parent']); |
|
2765 | 2765 | } |
2766 | 2766 | |
2767 | - $where = implode( ' AND ', $where ); |
|
2767 | + $where = implode(' AND ', $where); |
|
2768 | 2768 | |
2769 | 2769 | $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN $wpdb->term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE $where $orderby $order"; |
2770 | 2770 | |
2771 | 2771 | $objects = false; |
2772 | - if ( 'all' == $fields || 'all_with_object_id' == $fields ) { |
|
2773 | - $_terms = $wpdb->get_results( $query ); |
|
2774 | - foreach ( $_terms as $key => $term ) { |
|
2775 | - $_terms[$key] = sanitize_term( $term, $taxonomy, 'raw' ); |
|
2772 | + if ('all' == $fields || 'all_with_object_id' == $fields) { |
|
2773 | + $_terms = $wpdb->get_results($query); |
|
2774 | + foreach ($_terms as $key => $term) { |
|
2775 | + $_terms[$key] = sanitize_term($term, $taxonomy, 'raw'); |
|
2776 | 2776 | } |
2777 | - $terms = array_merge( $terms, $_terms ); |
|
2778 | - update_term_cache( $terms ); |
|
2777 | + $terms = array_merge($terms, $_terms); |
|
2778 | + update_term_cache($terms); |
|
2779 | 2779 | $objects = true; |
2780 | - } elseif ( 'ids' == $fields || 'names' == $fields || 'slugs' == $fields ) { |
|
2781 | - $_terms = $wpdb->get_col( $query ); |
|
2782 | - $_field = ( 'ids' == $fields ) ? 'term_id' : 'name'; |
|
2783 | - foreach ( $_terms as $key => $term ) { |
|
2784 | - $_terms[$key] = sanitize_term_field( $_field, $term, $term, $taxonomy, 'raw' ); |
|
2780 | + } elseif ('ids' == $fields || 'names' == $fields || 'slugs' == $fields) { |
|
2781 | + $_terms = $wpdb->get_col($query); |
|
2782 | + $_field = ('ids' == $fields) ? 'term_id' : 'name'; |
|
2783 | + foreach ($_terms as $key => $term) { |
|
2784 | + $_terms[$key] = sanitize_term_field($_field, $term, $term, $taxonomy, 'raw'); |
|
2785 | 2785 | } |
2786 | - $terms = array_merge( $terms, $_terms ); |
|
2787 | - } elseif ( 'tt_ids' == $fields ) { |
|
2786 | + $terms = array_merge($terms, $_terms); |
|
2787 | + } elseif ('tt_ids' == $fields) { |
|
2788 | 2788 | $terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN ($object_ids) AND tt.taxonomy IN ($taxonomies) $orderby $order"); |
2789 | - foreach ( $terms as $key => $tt_id ) { |
|
2790 | - $terms[$key] = sanitize_term_field( 'term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw' ); // 0 should be the term id, however is not needed when using raw context. |
|
2789 | + foreach ($terms as $key => $tt_id) { |
|
2790 | + $terms[$key] = sanitize_term_field('term_taxonomy_id', $tt_id, 0, $taxonomy, 'raw'); // 0 should be the term id, however is not needed when using raw context. |
|
2791 | 2791 | } |
2792 | 2792 | } |
2793 | 2793 | |
2794 | - if ( ! $terms ) { |
|
2794 | + if ( ! $terms) { |
|
2795 | 2795 | $terms = array(); |
2796 | - } elseif ( $objects && 'all_with_object_id' !== $fields ) { |
|
2796 | + } elseif ($objects && 'all_with_object_id' !== $fields) { |
|
2797 | 2797 | $_tt_ids = array(); |
2798 | 2798 | $_terms = array(); |
2799 | - foreach ( $terms as $term ) { |
|
2800 | - if ( in_array( $term->term_taxonomy_id, $_tt_ids ) ) { |
|
2799 | + foreach ($terms as $term) { |
|
2800 | + if (in_array($term->term_taxonomy_id, $_tt_ids)) { |
|
2801 | 2801 | continue; |
2802 | 2802 | } |
2803 | 2803 | |
@@ -2805,8 +2805,8 @@ discard block |
||
2805 | 2805 | $_terms[] = $term; |
2806 | 2806 | } |
2807 | 2807 | $terms = $_terms; |
2808 | - } elseif ( ! $objects ) { |
|
2809 | - $terms = array_values( array_unique( $terms ) ); |
|
2808 | + } elseif ( ! $objects) { |
|
2809 | + $terms = array_values(array_unique($terms)); |
|
2810 | 2810 | } |
2811 | 2811 | |
2812 | 2812 | /** |
@@ -2820,7 +2820,7 @@ discard block |
||
2820 | 2820 | * @param array $args An array of arguments for retrieving terms for the given |
2821 | 2821 | * object(s). See wp_get_object_terms() for details. |
2822 | 2822 | */ |
2823 | - $terms = apply_filters( 'get_object_terms', $terms, $object_id_array, $taxonomy_array, $args ); |
|
2823 | + $terms = apply_filters('get_object_terms', $terms, $object_id_array, $taxonomy_array, $args); |
|
2824 | 2824 | |
2825 | 2825 | /** |
2826 | 2826 | * Filter the terms for a given object or objects. |
@@ -2836,7 +2836,7 @@ discard block |
||
2836 | 2836 | * @param array $args An array of arguments for retrieving terms for the given object(s). |
2837 | 2837 | * See {@see wp_get_object_terms()} for details. |
2838 | 2838 | */ |
2839 | - return apply_filters( 'wp_get_object_terms', $terms, $object_ids, $taxonomies, $args ); |
|
2839 | + return apply_filters('wp_get_object_terms', $terms, $object_ids, $taxonomies, $args); |
|
2840 | 2840 | } |
2841 | 2841 | |
2842 | 2842 | /** |
@@ -2882,10 +2882,10 @@ discard block |
||
2882 | 2882 | * @return array|WP_Error An array containing the `term_id` and `term_taxonomy_id`, |
2883 | 2883 | * {@see WP_Error} otherwise. |
2884 | 2884 | */ |
2885 | -function wp_insert_term( $term, $taxonomy, $args = array() ) { |
|
2885 | +function wp_insert_term($term, $taxonomy, $args = array()) { |
|
2886 | 2886 | global $wpdb; |
2887 | 2887 | |
2888 | - if ( ! taxonomy_exists($taxonomy) ) { |
|
2888 | + if ( ! taxonomy_exists($taxonomy)) { |
|
2889 | 2889 | return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
2890 | 2890 | } |
2891 | 2891 | /** |
@@ -2896,54 +2896,54 @@ discard block |
||
2896 | 2896 | * @param string $term The term to add or update. |
2897 | 2897 | * @param string $taxonomy Taxonomy slug. |
2898 | 2898 | */ |
2899 | - $term = apply_filters( 'pre_insert_term', $term, $taxonomy ); |
|
2900 | - if ( is_wp_error( $term ) ) { |
|
2899 | + $term = apply_filters('pre_insert_term', $term, $taxonomy); |
|
2900 | + if (is_wp_error($term)) { |
|
2901 | 2901 | return $term; |
2902 | 2902 | } |
2903 | - if ( is_int($term) && 0 == $term ) { |
|
2903 | + if (is_int($term) && 0 == $term) { |
|
2904 | 2904 | return new WP_Error('invalid_term_id', __('Invalid term ID')); |
2905 | 2905 | } |
2906 | - if ( '' == trim($term) ) { |
|
2906 | + if ('' == trim($term)) { |
|
2907 | 2907 | return new WP_Error('empty_term_name', __('A name is required for this term')); |
2908 | 2908 | } |
2909 | - $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); |
|
2910 | - $args = wp_parse_args( $args, $defaults ); |
|
2909 | + $defaults = array('alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); |
|
2910 | + $args = wp_parse_args($args, $defaults); |
|
2911 | 2911 | |
2912 | - if ( $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) { |
|
2913 | - return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) ); |
|
2912 | + if ($args['parent'] > 0 && ! term_exists((int) $args['parent'])) { |
|
2913 | + return new WP_Error('missing_parent', __('Parent term does not exist.')); |
|
2914 | 2914 | } |
2915 | 2915 | $args['name'] = $term; |
2916 | 2916 | $args['taxonomy'] = $taxonomy; |
2917 | 2917 | $args = sanitize_term($args, $taxonomy, 'db'); |
2918 | 2918 | |
2919 | 2919 | // expected_slashed ($name) |
2920 | - $name = wp_unslash( $args['name'] ); |
|
2921 | - $description = wp_unslash( $args['description'] ); |
|
2920 | + $name = wp_unslash($args['name']); |
|
2921 | + $description = wp_unslash($args['description']); |
|
2922 | 2922 | $parent = (int) $args['parent']; |
2923 | 2923 | |
2924 | - $slug_provided = ! empty( $args['slug'] ); |
|
2925 | - if ( ! $slug_provided ) { |
|
2926 | - $slug = sanitize_title( $name ); |
|
2924 | + $slug_provided = ! empty($args['slug']); |
|
2925 | + if ( ! $slug_provided) { |
|
2926 | + $slug = sanitize_title($name); |
|
2927 | 2927 | } else { |
2928 | 2928 | $slug = $args['slug']; |
2929 | 2929 | } |
2930 | 2930 | |
2931 | 2931 | $term_group = 0; |
2932 | - if ( $args['alias_of'] ) { |
|
2933 | - $alias = get_term_by( 'slug', $args['alias_of'], $taxonomy ); |
|
2934 | - if ( ! empty( $alias->term_group ) ) { |
|
2932 | + if ($args['alias_of']) { |
|
2933 | + $alias = get_term_by('slug', $args['alias_of'], $taxonomy); |
|
2934 | + if ( ! empty($alias->term_group)) { |
|
2935 | 2935 | // The alias we want is already in a group, so let's use that one. |
2936 | 2936 | $term_group = $alias->term_group; |
2937 | - } elseif ( ! empty( $alias->term_id ) ) { |
|
2937 | + } elseif ( ! empty($alias->term_id)) { |
|
2938 | 2938 | /* |
2939 | 2939 | * The alias is not in a group, so we create a new one |
2940 | 2940 | * and add the alias to it. |
2941 | 2941 | */ |
2942 | 2942 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; |
2943 | 2943 | |
2944 | - wp_update_term( $alias->term_id, $taxonomy, array( |
|
2944 | + wp_update_term($alias->term_id, $taxonomy, array( |
|
2945 | 2945 | 'term_group' => $term_group, |
2946 | - ) ); |
|
2946 | + )); |
|
2947 | 2947 | } |
2948 | 2948 | } |
2949 | 2949 | |
@@ -2951,54 +2951,54 @@ discard block |
||
2951 | 2951 | * Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy, |
2952 | 2952 | * unless a unique slug has been explicitly provided. |
2953 | 2953 | */ |
2954 | - if ( $name_match = get_term_by( 'name', $name, $taxonomy ) ) { |
|
2955 | - $slug_match = get_term_by( 'slug', $slug, $taxonomy ); |
|
2956 | - if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) { |
|
2957 | - if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
2958 | - $siblings = get_terms( $taxonomy, array( 'get' => 'all', 'parent' => $parent ) ); |
|
2954 | + if ($name_match = get_term_by('name', $name, $taxonomy)) { |
|
2955 | + $slug_match = get_term_by('slug', $slug, $taxonomy); |
|
2956 | + if ( ! $slug_provided || $name_match->slug === $slug || $slug_match) { |
|
2957 | + if (is_taxonomy_hierarchical($taxonomy)) { |
|
2958 | + $siblings = get_terms($taxonomy, array('get' => 'all', 'parent' => $parent)); |
|
2959 | 2959 | |
2960 | 2960 | $existing_term = null; |
2961 | - if ( $name_match->slug === $slug && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) { |
|
2961 | + if ($name_match->slug === $slug && in_array($name, wp_list_pluck($siblings, 'name'))) { |
|
2962 | 2962 | $existing_term = $name_match; |
2963 | - } elseif ( $slug_match && in_array( $slug, wp_list_pluck( $siblings, 'slug' ) ) ) { |
|
2963 | + } elseif ($slug_match && in_array($slug, wp_list_pluck($siblings, 'slug'))) { |
|
2964 | 2964 | $existing_term = $slug_match; |
2965 | 2965 | } |
2966 | 2966 | |
2967 | - if ( $existing_term ) { |
|
2968 | - return new WP_Error( 'term_exists', __( 'A term with the name provided already exists with this parent.' ), $existing_term->term_id ); |
|
2967 | + if ($existing_term) { |
|
2968 | + return new WP_Error('term_exists', __('A term with the name provided already exists with this parent.'), $existing_term->term_id); |
|
2969 | 2969 | } |
2970 | 2970 | } else { |
2971 | - return new WP_Error( 'term_exists', __( 'A term with the name provided already exists in this taxonomy.' ), $name_match->term_id ); |
|
2971 | + return new WP_Error('term_exists', __('A term with the name provided already exists in this taxonomy.'), $name_match->term_id); |
|
2972 | 2972 | } |
2973 | 2973 | } |
2974 | 2974 | } |
2975 | 2975 | |
2976 | - $slug = wp_unique_term_slug( $slug, (object) $args ); |
|
2976 | + $slug = wp_unique_term_slug($slug, (object) $args); |
|
2977 | 2977 | |
2978 | - if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { |
|
2979 | - return new WP_Error( 'db_insert_error', __( 'Could not insert term into the database' ), $wpdb->last_error ); |
|
2978 | + if (false === $wpdb->insert($wpdb->terms, compact('name', 'slug', 'term_group'))) { |
|
2979 | + return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); |
|
2980 | 2980 | } |
2981 | 2981 | |
2982 | 2982 | $term_id = (int) $wpdb->insert_id; |
2983 | 2983 | |
2984 | 2984 | // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string. |
2985 | - if ( empty($slug) ) { |
|
2985 | + if (empty($slug)) { |
|
2986 | 2986 | $slug = sanitize_title($slug, $term_id); |
2987 | 2987 | |
2988 | 2988 | /** This action is documented in wp-includes/taxonomy.php */ |
2989 | - do_action( 'edit_terms', $term_id, $taxonomy ); |
|
2990 | - $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
|
2989 | + do_action('edit_terms', $term_id, $taxonomy); |
|
2990 | + $wpdb->update($wpdb->terms, compact('slug'), compact('term_id')); |
|
2991 | 2991 | |
2992 | 2992 | /** This action is documented in wp-includes/taxonomy.php */ |
2993 | - do_action( 'edited_terms', $term_id, $taxonomy ); |
|
2993 | + do_action('edited_terms', $term_id, $taxonomy); |
|
2994 | 2994 | } |
2995 | 2995 | |
2996 | - $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) ); |
|
2996 | + $tt_id = $wpdb->get_var($wpdb->prepare("SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id)); |
|
2997 | 2997 | |
2998 | - if ( !empty($tt_id) ) { |
|
2998 | + if ( ! empty($tt_id)) { |
|
2999 | 2999 | return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
3000 | 3000 | } |
3001 | - $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) ); |
|
3001 | + $wpdb->insert($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent') + array('count' => 0)); |
|
3002 | 3002 | $tt_id = (int) $wpdb->insert_id; |
3003 | 3003 | |
3004 | 3004 | /* |
@@ -3007,16 +3007,16 @@ discard block |
||
3007 | 3007 | * and term_taxonomy_id of the older term instead. Then return out of the function so that the "create" hooks |
3008 | 3008 | * are not fired. |
3009 | 3009 | */ |
3010 | - $duplicate_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, tt.term_taxonomy_id FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id ) ); |
|
3011 | - if ( $duplicate_term ) { |
|
3012 | - $wpdb->delete( $wpdb->terms, array( 'term_id' => $term_id ) ); |
|
3013 | - $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); |
|
3010 | + $duplicate_term = $wpdb->get_row($wpdb->prepare("SELECT t.term_id, tt.term_taxonomy_id FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id)); |
|
3011 | + if ($duplicate_term) { |
|
3012 | + $wpdb->delete($wpdb->terms, array('term_id' => $term_id)); |
|
3013 | + $wpdb->delete($wpdb->term_taxonomy, array('term_taxonomy_id' => $tt_id)); |
|
3014 | 3014 | |
3015 | 3015 | $term_id = (int) $duplicate_term->term_id; |
3016 | 3016 | $tt_id = (int) $duplicate_term->term_taxonomy_id; |
3017 | 3017 | |
3018 | - clean_term_cache( $term_id, $taxonomy ); |
|
3019 | - return array( 'term_id' => $term_id, 'term_taxonomy_id' => $tt_id ); |
|
3018 | + clean_term_cache($term_id, $taxonomy); |
|
3019 | + return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
|
3020 | 3020 | } |
3021 | 3021 | |
3022 | 3022 | /** |
@@ -3028,7 +3028,7 @@ discard block |
||
3028 | 3028 | * @param int $tt_id Term taxonomy ID. |
3029 | 3029 | * @param string $taxonomy Taxonomy slug. |
3030 | 3030 | */ |
3031 | - do_action( "create_term", $term_id, $tt_id, $taxonomy ); |
|
3031 | + do_action("create_term", $term_id, $tt_id, $taxonomy); |
|
3032 | 3032 | |
3033 | 3033 | /** |
3034 | 3034 | * Fires after a new term is created for a specific taxonomy. |
@@ -3041,7 +3041,7 @@ discard block |
||
3041 | 3041 | * @param int $term_id Term ID. |
3042 | 3042 | * @param int $tt_id Term taxonomy ID. |
3043 | 3043 | */ |
3044 | - do_action( "create_$taxonomy", $term_id, $tt_id ); |
|
3044 | + do_action("create_$taxonomy", $term_id, $tt_id); |
|
3045 | 3045 | |
3046 | 3046 | /** |
3047 | 3047 | * Filter the term ID after a new term is created. |
@@ -3051,7 +3051,7 @@ discard block |
||
3051 | 3051 | * @param int $term_id Term ID. |
3052 | 3052 | * @param int $tt_id Taxonomy term ID. |
3053 | 3053 | */ |
3054 | - $term_id = apply_filters( 'term_id_filter', $term_id, $tt_id ); |
|
3054 | + $term_id = apply_filters('term_id_filter', $term_id, $tt_id); |
|
3055 | 3055 | |
3056 | 3056 | clean_term_cache($term_id, $taxonomy); |
3057 | 3057 | |
@@ -3064,7 +3064,7 @@ discard block |
||
3064 | 3064 | * @param int $tt_id Term taxonomy ID. |
3065 | 3065 | * @param string $taxonomy Taxonomy slug. |
3066 | 3066 | */ |
3067 | - do_action( 'created_term', $term_id, $tt_id, $taxonomy ); |
|
3067 | + do_action('created_term', $term_id, $tt_id, $taxonomy); |
|
3068 | 3068 | |
3069 | 3069 | /** |
3070 | 3070 | * Fires after a new term in a specific taxonomy is created, and after the term |
@@ -3077,7 +3077,7 @@ discard block |
||
3077 | 3077 | * @param int $term_id Term ID. |
3078 | 3078 | * @param int $tt_id Term taxonomy ID. |
3079 | 3079 | */ |
3080 | - do_action( "created_$taxonomy", $term_id, $tt_id ); |
|
3080 | + do_action("created_$taxonomy", $term_id, $tt_id); |
|
3081 | 3081 | |
3082 | 3082 | return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
3083 | 3083 | } |
@@ -3104,19 +3104,19 @@ discard block |
||
3104 | 3104 | * @param bool $append Optional. If false will delete difference of terms. Default false. |
3105 | 3105 | * @return array|WP_Error Affected Term IDs. |
3106 | 3106 | */ |
3107 | -function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { |
|
3107 | +function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { |
|
3108 | 3108 | global $wpdb; |
3109 | 3109 | |
3110 | 3110 | $object_id = (int) $object_id; |
3111 | 3111 | |
3112 | - if ( ! taxonomy_exists($taxonomy) ) |
|
3112 | + if ( ! taxonomy_exists($taxonomy)) |
|
3113 | 3113 | return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
3114 | 3114 | |
3115 | - if ( !is_array($terms) ) |
|
3115 | + if ( ! is_array($terms)) |
|
3116 | 3116 | $terms = array($terms); |
3117 | 3117 | |
3118 | - if ( ! $append ) |
|
3119 | - $old_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none')); |
|
3118 | + if ( ! $append) |
|
3119 | + $old_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none')); |
|
3120 | 3120 | else |
3121 | 3121 | $old_tt_ids = array(); |
3122 | 3122 | |
@@ -3124,23 +3124,23 @@ discard block |
||
3124 | 3124 | $term_ids = array(); |
3125 | 3125 | $new_tt_ids = array(); |
3126 | 3126 | |
3127 | - foreach ( (array) $terms as $term) { |
|
3128 | - if ( !strlen(trim($term)) ) |
|
3127 | + foreach ((array) $terms as $term) { |
|
3128 | + if ( ! strlen(trim($term))) |
|
3129 | 3129 | continue; |
3130 | 3130 | |
3131 | - if ( !$term_info = term_exists($term, $taxonomy) ) { |
|
3131 | + if ( ! $term_info = term_exists($term, $taxonomy)) { |
|
3132 | 3132 | // Skip if a non-existent term ID is passed. |
3133 | - if ( is_int($term) ) |
|
3133 | + if (is_int($term)) |
|
3134 | 3134 | continue; |
3135 | 3135 | $term_info = wp_insert_term($term, $taxonomy); |
3136 | 3136 | } |
3137 | - if ( is_wp_error($term_info) ) |
|
3137 | + if (is_wp_error($term_info)) |
|
3138 | 3138 | return $term_info; |
3139 | 3139 | $term_ids[] = $term_info['term_id']; |
3140 | 3140 | $tt_id = $term_info['term_taxonomy_id']; |
3141 | 3141 | $tt_ids[] = $tt_id; |
3142 | 3142 | |
3143 | - if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) |
|
3143 | + if ($wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id))) |
|
3144 | 3144 | continue; |
3145 | 3145 | |
3146 | 3146 | /** |
@@ -3151,8 +3151,8 @@ discard block |
||
3151 | 3151 | * @param int $object_id Object ID. |
3152 | 3152 | * @param int $tt_id Term taxonomy ID. |
3153 | 3153 | */ |
3154 | - do_action( 'add_term_relationship', $object_id, $tt_id ); |
|
3155 | - $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id ) ); |
|
3154 | + do_action('add_term_relationship', $object_id, $tt_id); |
|
3155 | + $wpdb->insert($wpdb->term_relationships, array('object_id' => $object_id, 'term_taxonomy_id' => $tt_id)); |
|
3156 | 3156 | |
3157 | 3157 | /** |
3158 | 3158 | * Fires immediately after an object-term relationship is added. |
@@ -3162,42 +3162,42 @@ discard block |
||
3162 | 3162 | * @param int $object_id Object ID. |
3163 | 3163 | * @param int $tt_id Term taxonomy ID. |
3164 | 3164 | */ |
3165 | - do_action( 'added_term_relationship', $object_id, $tt_id ); |
|
3165 | + do_action('added_term_relationship', $object_id, $tt_id); |
|
3166 | 3166 | $new_tt_ids[] = $tt_id; |
3167 | 3167 | } |
3168 | 3168 | |
3169 | - if ( $new_tt_ids ) |
|
3170 | - wp_update_term_count( $new_tt_ids, $taxonomy ); |
|
3169 | + if ($new_tt_ids) |
|
3170 | + wp_update_term_count($new_tt_ids, $taxonomy); |
|
3171 | 3171 | |
3172 | - if ( ! $append ) { |
|
3173 | - $delete_tt_ids = array_diff( $old_tt_ids, $tt_ids ); |
|
3172 | + if ( ! $append) { |
|
3173 | + $delete_tt_ids = array_diff($old_tt_ids, $tt_ids); |
|
3174 | 3174 | |
3175 | - if ( $delete_tt_ids ) { |
|
3176 | - $in_delete_tt_ids = "'" . implode( "', '", $delete_tt_ids ) . "'"; |
|
3177 | - $delete_term_ids = $wpdb->get_col( $wpdb->prepare( "SELECT tt.term_id FROM $wpdb->term_taxonomy AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ($in_delete_tt_ids)", $taxonomy ) ); |
|
3178 | - $delete_term_ids = array_map( 'intval', $delete_term_ids ); |
|
3175 | + if ($delete_tt_ids) { |
|
3176 | + $in_delete_tt_ids = "'".implode("', '", $delete_tt_ids)."'"; |
|
3177 | + $delete_term_ids = $wpdb->get_col($wpdb->prepare("SELECT tt.term_id FROM $wpdb->term_taxonomy AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ($in_delete_tt_ids)", $taxonomy)); |
|
3178 | + $delete_term_ids = array_map('intval', $delete_term_ids); |
|
3179 | 3179 | |
3180 | - $remove = wp_remove_object_terms( $object_id, $delete_term_ids, $taxonomy ); |
|
3181 | - if ( is_wp_error( $remove ) ) { |
|
3180 | + $remove = wp_remove_object_terms($object_id, $delete_term_ids, $taxonomy); |
|
3181 | + if (is_wp_error($remove)) { |
|
3182 | 3182 | return $remove; |
3183 | 3183 | } |
3184 | 3184 | } |
3185 | 3185 | } |
3186 | 3186 | |
3187 | 3187 | $t = get_taxonomy($taxonomy); |
3188 | - if ( ! $append && isset($t->sort) && $t->sort ) { |
|
3188 | + if ( ! $append && isset($t->sort) && $t->sort) { |
|
3189 | 3189 | $values = array(); |
3190 | 3190 | $term_order = 0; |
3191 | 3191 | $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); |
3192 | - foreach ( $tt_ids as $tt_id ) |
|
3193 | - if ( in_array($tt_id, $final_tt_ids) ) |
|
3194 | - $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); |
|
3195 | - if ( $values ) |
|
3196 | - if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ) |
|
3197 | - return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database' ), $wpdb->last_error ); |
|
3192 | + foreach ($tt_ids as $tt_id) |
|
3193 | + if (in_array($tt_id, $final_tt_ids)) |
|
3194 | + $values[] = $wpdb->prepare("(%d, %d, %d)", $object_id, $tt_id, ++$term_order); |
|
3195 | + if ($values) |
|
3196 | + if (false === $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES ".join(',', $values)." ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)")) |
|
3197 | + return new WP_Error('db_insert_error', __('Could not insert term relationship into the database'), $wpdb->last_error); |
|
3198 | 3198 | } |
3199 | 3199 | |
3200 | - wp_cache_delete( $object_id, $taxonomy . '_relationships' ); |
|
3200 | + wp_cache_delete($object_id, $taxonomy.'_relationships'); |
|
3201 | 3201 | |
3202 | 3202 | /** |
3203 | 3203 | * Fires after an object's terms have been set. |
@@ -3211,7 +3211,7 @@ discard block |
||
3211 | 3211 | * @param bool $append Whether to append new terms to the old terms. |
3212 | 3212 | * @param array $old_tt_ids Old array of term taxonomy IDs. |
3213 | 3213 | */ |
3214 | - do_action( 'set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ); |
|
3214 | + do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); |
|
3215 | 3215 | return $tt_ids; |
3216 | 3216 | } |
3217 | 3217 | |
@@ -3225,8 +3225,8 @@ discard block |
||
3225 | 3225 | * @param array|string $taxonomy Taxonomy name. |
3226 | 3226 | * @return array|WP_Error Affected Term IDs |
3227 | 3227 | */ |
3228 | -function wp_add_object_terms( $object_id, $terms, $taxonomy ) { |
|
3229 | - return wp_set_object_terms( $object_id, $terms, $taxonomy, true ); |
|
3228 | +function wp_add_object_terms($object_id, $terms, $taxonomy) { |
|
3229 | + return wp_set_object_terms($object_id, $terms, $taxonomy, true); |
|
3230 | 3230 | } |
3231 | 3231 | |
3232 | 3232 | /** |
@@ -3241,42 +3241,42 @@ discard block |
||
3241 | 3241 | * @param array|string $taxonomy Taxonomy name. |
3242 | 3242 | * @return bool|WP_Error True on success, false or WP_Error on failure. |
3243 | 3243 | */ |
3244 | -function wp_remove_object_terms( $object_id, $terms, $taxonomy ) { |
|
3244 | +function wp_remove_object_terms($object_id, $terms, $taxonomy) { |
|
3245 | 3245 | global $wpdb; |
3246 | 3246 | |
3247 | 3247 | $object_id = (int) $object_id; |
3248 | 3248 | |
3249 | - if ( ! taxonomy_exists( $taxonomy ) ) { |
|
3250 | - return new WP_Error( 'invalid_taxonomy', __( 'Invalid Taxonomy' ) ); |
|
3249 | + if ( ! taxonomy_exists($taxonomy)) { |
|
3250 | + return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); |
|
3251 | 3251 | } |
3252 | 3252 | |
3253 | - if ( ! is_array( $terms ) ) { |
|
3254 | - $terms = array( $terms ); |
|
3253 | + if ( ! is_array($terms)) { |
|
3254 | + $terms = array($terms); |
|
3255 | 3255 | } |
3256 | 3256 | |
3257 | 3257 | $tt_ids = array(); |
3258 | 3258 | |
3259 | - foreach ( (array) $terms as $term ) { |
|
3260 | - if ( ! strlen( trim( $term ) ) ) { |
|
3259 | + foreach ((array) $terms as $term) { |
|
3260 | + if ( ! strlen(trim($term))) { |
|
3261 | 3261 | continue; |
3262 | 3262 | } |
3263 | 3263 | |
3264 | - if ( ! $term_info = term_exists( $term, $taxonomy ) ) { |
|
3264 | + if ( ! $term_info = term_exists($term, $taxonomy)) { |
|
3265 | 3265 | // Skip if a non-existent term ID is passed. |
3266 | - if ( is_int( $term ) ) { |
|
3266 | + if (is_int($term)) { |
|
3267 | 3267 | continue; |
3268 | 3268 | } |
3269 | 3269 | } |
3270 | 3270 | |
3271 | - if ( is_wp_error( $term_info ) ) { |
|
3271 | + if (is_wp_error($term_info)) { |
|
3272 | 3272 | return $term_info; |
3273 | 3273 | } |
3274 | 3274 | |
3275 | 3275 | $tt_ids[] = $term_info['term_taxonomy_id']; |
3276 | 3276 | } |
3277 | 3277 | |
3278 | - if ( $tt_ids ) { |
|
3279 | - $in_tt_ids = "'" . implode( "', '", $tt_ids ) . "'"; |
|
3278 | + if ($tt_ids) { |
|
3279 | + $in_tt_ids = "'".implode("', '", $tt_ids)."'"; |
|
3280 | 3280 | |
3281 | 3281 | /** |
3282 | 3282 | * Fires immediately before an object-term relationship is deleted. |
@@ -3286,8 +3286,8 @@ discard block |
||
3286 | 3286 | * @param int $object_id Object ID. |
3287 | 3287 | * @param array $tt_ids An array of term taxonomy IDs. |
3288 | 3288 | */ |
3289 | - do_action( 'delete_term_relationships', $object_id, $tt_ids ); |
|
3290 | - $deleted = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id ) ); |
|
3289 | + do_action('delete_term_relationships', $object_id, $tt_ids); |
|
3290 | + $deleted = $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_tt_ids)", $object_id)); |
|
3291 | 3291 | |
3292 | 3292 | /** |
3293 | 3293 | * Fires immediately after an object-term relationship is deleted. |
@@ -3297,9 +3297,9 @@ discard block |
||
3297 | 3297 | * @param int $object_id Object ID. |
3298 | 3298 | * @param array $tt_ids An array of term taxonomy IDs. |
3299 | 3299 | */ |
3300 | - do_action( 'deleted_term_relationships', $object_id, $tt_ids ); |
|
3300 | + do_action('deleted_term_relationships', $object_id, $tt_ids); |
|
3301 | 3301 | |
3302 | - wp_update_term_count( $tt_ids, $taxonomy ); |
|
3302 | + wp_update_term_count($tt_ids, $taxonomy); |
|
3303 | 3303 | |
3304 | 3304 | return (bool) $deleted; |
3305 | 3305 | } |
@@ -3330,14 +3330,14 @@ discard block |
||
3330 | 3330 | * @param object $term The term object that the `$slug` will belong to. |
3331 | 3331 | * @return string Will return a true unique slug. |
3332 | 3332 | */ |
3333 | -function wp_unique_term_slug( $slug, $term ) { |
|
3333 | +function wp_unique_term_slug($slug, $term) { |
|
3334 | 3334 | global $wpdb; |
3335 | 3335 | |
3336 | 3336 | $needs_suffix = true; |
3337 | 3337 | $original_slug = $slug; |
3338 | 3338 | |
3339 | 3339 | // As of 4.1, duplicate slugs are allowed as long as they're in different taxonomies. |
3340 | - if ( ! term_exists( $slug ) || get_option( 'db_version' ) >= 30133 && ! get_term_by( 'slug', $slug, $term->taxonomy ) ) { |
|
3340 | + if ( ! term_exists($slug) || get_option('db_version') >= 30133 && ! get_term_by('slug', $slug, $term->taxonomy)) { |
|
3341 | 3341 | $needs_suffix = false; |
3342 | 3342 | } |
3343 | 3343 | |
@@ -3346,18 +3346,18 @@ discard block |
||
3346 | 3346 | * by incorporating parent slugs. |
3347 | 3347 | */ |
3348 | 3348 | $parent_suffix = ''; |
3349 | - if ( $needs_suffix && is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) ) { |
|
3349 | + if ($needs_suffix && is_taxonomy_hierarchical($term->taxonomy) && ! empty($term->parent)) { |
|
3350 | 3350 | $the_parent = $term->parent; |
3351 | - while ( ! empty($the_parent) ) { |
|
3351 | + while ( ! empty($the_parent)) { |
|
3352 | 3352 | $parent_term = get_term($the_parent, $term->taxonomy); |
3353 | - if ( is_wp_error($parent_term) || empty($parent_term) ) |
|
3353 | + if (is_wp_error($parent_term) || empty($parent_term)) |
|
3354 | 3354 | break; |
3355 | - $parent_suffix .= '-' . $parent_term->slug; |
|
3356 | - if ( ! term_exists( $slug . $parent_suffix ) ) { |
|
3355 | + $parent_suffix .= '-'.$parent_term->slug; |
|
3356 | + if ( ! term_exists($slug.$parent_suffix)) { |
|
3357 | 3357 | break; |
3358 | 3358 | } |
3359 | 3359 | |
3360 | - if ( empty($parent_term->parent) ) |
|
3360 | + if (empty($parent_term->parent)) |
|
3361 | 3361 | break; |
3362 | 3362 | $the_parent = $parent_term->parent; |
3363 | 3363 | } |
@@ -3374,22 +3374,22 @@ discard block |
||
3374 | 3374 | * @param string $slug The slug. |
3375 | 3375 | * @param object $term Term object. |
3376 | 3376 | */ |
3377 | - if ( apply_filters( 'wp_unique_term_slug_is_bad_slug', $needs_suffix, $slug, $term ) ) { |
|
3378 | - if ( $parent_suffix ) { |
|
3377 | + if (apply_filters('wp_unique_term_slug_is_bad_slug', $needs_suffix, $slug, $term)) { |
|
3378 | + if ($parent_suffix) { |
|
3379 | 3379 | $slug .= $parent_suffix; |
3380 | 3380 | } else { |
3381 | - if ( ! empty( $term->term_id ) ) |
|
3382 | - $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); |
|
3381 | + if ( ! empty($term->term_id)) |
|
3382 | + $query = $wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id); |
|
3383 | 3383 | else |
3384 | - $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); |
|
3384 | + $query = $wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug); |
|
3385 | 3385 | |
3386 | - if ( $wpdb->get_var( $query ) ) { |
|
3386 | + if ($wpdb->get_var($query)) { |
|
3387 | 3387 | $num = 2; |
3388 | 3388 | do { |
3389 | - $alt_slug = $slug . "-$num"; |
|
3389 | + $alt_slug = $slug."-$num"; |
|
3390 | 3390 | $num++; |
3391 | - $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) ); |
|
3392 | - } while ( $slug_check ); |
|
3391 | + $slug_check = $wpdb->get_var($wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug)); |
|
3392 | + } while ($slug_check); |
|
3393 | 3393 | $slug = $alt_slug; |
3394 | 3394 | } |
3395 | 3395 | } |
@@ -3404,7 +3404,7 @@ discard block |
||
3404 | 3404 | * @param object $term Term object. |
3405 | 3405 | * @param string $original_slug Slug originally passed to the function for testing. |
3406 | 3406 | */ |
3407 | - return apply_filters( 'wp_unique_term_slug', $slug, $term, $original_slug ); |
|
3407 | + return apply_filters('wp_unique_term_slug', $slug, $term, $original_slug); |
|
3408 | 3408 | } |
3409 | 3409 | |
3410 | 3410 | /** |
@@ -3437,24 +3437,24 @@ discard block |
||
3437 | 3437 | * @param array|string $args Optional. Array of get_terms() arguments. Default empty array. |
3438 | 3438 | * @return array|WP_Error Returns Term ID and Taxonomy Term ID |
3439 | 3439 | */ |
3440 | -function wp_update_term( $term_id, $taxonomy, $args = array() ) { |
|
3440 | +function wp_update_term($term_id, $taxonomy, $args = array()) { |
|
3441 | 3441 | global $wpdb; |
3442 | 3442 | |
3443 | - if ( ! taxonomy_exists( $taxonomy ) ) { |
|
3444 | - return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy' ) ); |
|
3443 | + if ( ! taxonomy_exists($taxonomy)) { |
|
3444 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
3445 | 3445 | } |
3446 | 3446 | |
3447 | 3447 | $term_id = (int) $term_id; |
3448 | 3448 | |
3449 | 3449 | // First, get all of the original args |
3450 | - $term = get_term( $term_id, $taxonomy, ARRAY_A ); |
|
3450 | + $term = get_term($term_id, $taxonomy, ARRAY_A); |
|
3451 | 3451 | |
3452 | - if ( is_wp_error( $term ) ) { |
|
3452 | + if (is_wp_error($term)) { |
|
3453 | 3453 | return $term; |
3454 | 3454 | } |
3455 | 3455 | |
3456 | - if ( ! $term ) { |
|
3457 | - return new WP_Error( 'invalid_term', __( 'Empty Term' ) ); |
|
3456 | + if ( ! $term) { |
|
3457 | + return new WP_Error('invalid_term', __('Empty Term')); |
|
3458 | 3458 | } |
3459 | 3459 | |
3460 | 3460 | // Escape data pulled from DB. |
@@ -3463,27 +3463,27 @@ discard block |
||
3463 | 3463 | // Merge old and new args with new args overwriting old ones. |
3464 | 3464 | $args = array_merge($term, $args); |
3465 | 3465 | |
3466 | - $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); |
|
3466 | + $defaults = array('alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); |
|
3467 | 3467 | $args = wp_parse_args($args, $defaults); |
3468 | 3468 | $args = sanitize_term($args, $taxonomy, 'db'); |
3469 | 3469 | $parsed_args = $args; |
3470 | 3470 | |
3471 | 3471 | // expected_slashed ($name) |
3472 | - $name = wp_unslash( $args['name'] ); |
|
3473 | - $description = wp_unslash( $args['description'] ); |
|
3472 | + $name = wp_unslash($args['name']); |
|
3473 | + $description = wp_unslash($args['description']); |
|
3474 | 3474 | |
3475 | 3475 | $parsed_args['name'] = $name; |
3476 | 3476 | $parsed_args['description'] = $description; |
3477 | 3477 | |
3478 | - if ( '' == trim($name) ) |
|
3478 | + if ('' == trim($name)) |
|
3479 | 3479 | return new WP_Error('empty_term_name', __('A name is required for this term')); |
3480 | 3480 | |
3481 | - if ( $parsed_args['parent'] > 0 && ! term_exists( (int) $parsed_args['parent'] ) ) { |
|
3482 | - return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) ); |
|
3481 | + if ($parsed_args['parent'] > 0 && ! term_exists((int) $parsed_args['parent'])) { |
|
3482 | + return new WP_Error('missing_parent', __('Parent term does not exist.')); |
|
3483 | 3483 | } |
3484 | 3484 | |
3485 | 3485 | $empty_slug = false; |
3486 | - if ( empty( $args['slug'] ) ) { |
|
3486 | + if (empty($args['slug'])) { |
|
3487 | 3487 | $empty_slug = true; |
3488 | 3488 | $slug = sanitize_title($name); |
3489 | 3489 | } else { |
@@ -3492,22 +3492,22 @@ discard block |
||
3492 | 3492 | |
3493 | 3493 | $parsed_args['slug'] = $slug; |
3494 | 3494 | |
3495 | - $term_group = isset( $parsed_args['term_group'] ) ? $parsed_args['term_group'] : 0; |
|
3496 | - if ( $args['alias_of'] ) { |
|
3497 | - $alias = get_term_by( 'slug', $args['alias_of'], $taxonomy ); |
|
3498 | - if ( ! empty( $alias->term_group ) ) { |
|
3495 | + $term_group = isset($parsed_args['term_group']) ? $parsed_args['term_group'] : 0; |
|
3496 | + if ($args['alias_of']) { |
|
3497 | + $alias = get_term_by('slug', $args['alias_of'], $taxonomy); |
|
3498 | + if ( ! empty($alias->term_group)) { |
|
3499 | 3499 | // The alias we want is already in a group, so let's use that one. |
3500 | 3500 | $term_group = $alias->term_group; |
3501 | - } elseif ( ! empty( $alias->term_id ) ) { |
|
3501 | + } elseif ( ! empty($alias->term_id)) { |
|
3502 | 3502 | /* |
3503 | 3503 | * The alias is not in a group, so we create a new one |
3504 | 3504 | * and add the alias to it. |
3505 | 3505 | */ |
3506 | 3506 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1; |
3507 | 3507 | |
3508 | - wp_update_term( $alias->term_id, $taxonomy, array( |
|
3508 | + wp_update_term($alias->term_id, $taxonomy, array( |
|
3509 | 3509 | 'term_group' => $term_group, |
3510 | - ) ); |
|
3510 | + )); |
|
3511 | 3511 | } |
3512 | 3512 | |
3513 | 3513 | $parsed_args['term_group'] = $term_group; |
@@ -3526,24 +3526,24 @@ discard block |
||
3526 | 3526 | * @param array $parsed_args An array of potentially altered update arguments for the given term. |
3527 | 3527 | * @param array $args An array of update arguments for the given term. |
3528 | 3528 | */ |
3529 | - $parent = apply_filters( 'wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args ); |
|
3529 | + $parent = apply_filters('wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args); |
|
3530 | 3530 | |
3531 | 3531 | // Check for duplicate slug |
3532 | - $duplicate = get_term_by( 'slug', $slug, $taxonomy ); |
|
3533 | - if ( $duplicate && $duplicate->term_id != $term_id ) { |
|
3532 | + $duplicate = get_term_by('slug', $slug, $taxonomy); |
|
3533 | + if ($duplicate && $duplicate->term_id != $term_id) { |
|
3534 | 3534 | // If an empty slug was passed or the parent changed, reset the slug to something unique. |
3535 | 3535 | // Otherwise, bail. |
3536 | - if ( $empty_slug || ( $parent != $term['parent']) ) |
|
3536 | + if ($empty_slug || ($parent != $term['parent'])) |
|
3537 | 3537 | $slug = wp_unique_term_slug($slug, (object) $args); |
3538 | 3538 | else |
3539 | 3539 | return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); |
3540 | 3540 | } |
3541 | 3541 | |
3542 | - $tt_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) ); |
|
3542 | + $tt_id = (int) $wpdb->get_var($wpdb->prepare("SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id)); |
|
3543 | 3543 | |
3544 | 3544 | // Check whether this is a shared term that needs splitting. |
3545 | - $_term_id = _split_shared_term( $term_id, $tt_id ); |
|
3546 | - if ( ! is_wp_error( $_term_id ) ) { |
|
3545 | + $_term_id = _split_shared_term($term_id, $tt_id); |
|
3546 | + if ( ! is_wp_error($_term_id)) { |
|
3547 | 3547 | $term_id = $_term_id; |
3548 | 3548 | } |
3549 | 3549 | |
@@ -3555,11 +3555,11 @@ discard block |
||
3555 | 3555 | * @param int $term_id Term ID. |
3556 | 3556 | * @param string $taxonomy Taxonomy slug. |
3557 | 3557 | */ |
3558 | - do_action( 'edit_terms', $term_id, $taxonomy ); |
|
3559 | - $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) ); |
|
3560 | - if ( empty($slug) ) { |
|
3558 | + do_action('edit_terms', $term_id, $taxonomy); |
|
3559 | + $wpdb->update($wpdb->terms, compact('name', 'slug', 'term_group'), compact('term_id')); |
|
3560 | + if (empty($slug)) { |
|
3561 | 3561 | $slug = sanitize_title($name, $term_id); |
3562 | - $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) ); |
|
3562 | + $wpdb->update($wpdb->terms, compact('slug'), compact('term_id')); |
|
3563 | 3563 | } |
3564 | 3564 | |
3565 | 3565 | /** |
@@ -3570,7 +3570,7 @@ discard block |
||
3570 | 3570 | * @param int $term_id Term ID |
3571 | 3571 | * @param string $taxonomy Taxonomy slug. |
3572 | 3572 | */ |
3573 | - do_action( 'edited_terms', $term_id, $taxonomy ); |
|
3573 | + do_action('edited_terms', $term_id, $taxonomy); |
|
3574 | 3574 | |
3575 | 3575 | /** |
3576 | 3576 | * Fires immediate before a term-taxonomy relationship is updated. |
@@ -3580,9 +3580,9 @@ discard block |
||
3580 | 3580 | * @param int $tt_id Term taxonomy ID. |
3581 | 3581 | * @param string $taxonomy Taxonomy slug. |
3582 | 3582 | */ |
3583 | - do_action( 'edit_term_taxonomy', $tt_id, $taxonomy ); |
|
3583 | + do_action('edit_term_taxonomy', $tt_id, $taxonomy); |
|
3584 | 3584 | |
3585 | - $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) ); |
|
3585 | + $wpdb->update($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent'), array('term_taxonomy_id' => $tt_id)); |
|
3586 | 3586 | |
3587 | 3587 | /** |
3588 | 3588 | * Fires immediately after a term-taxonomy relationship is updated. |
@@ -3592,13 +3592,13 @@ discard block |
||
3592 | 3592 | * @param int $tt_id Term taxonomy ID. |
3593 | 3593 | * @param string $taxonomy Taxonomy slug. |
3594 | 3594 | */ |
3595 | - do_action( 'edited_term_taxonomy', $tt_id, $taxonomy ); |
|
3595 | + do_action('edited_term_taxonomy', $tt_id, $taxonomy); |
|
3596 | 3596 | |
3597 | 3597 | // Clean the relationship caches for all object types using this term. |
3598 | - $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) ); |
|
3599 | - $tax_object = get_taxonomy( $taxonomy ); |
|
3600 | - foreach ( $tax_object->object_type as $object_type ) { |
|
3601 | - clean_object_term_cache( $objects, $object_type ); |
|
3598 | + $objects = $wpdb->get_col($wpdb->prepare("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id)); |
|
3599 | + $tax_object = get_taxonomy($taxonomy); |
|
3600 | + foreach ($tax_object->object_type as $object_type) { |
|
3601 | + clean_object_term_cache($objects, $object_type); |
|
3602 | 3602 | } |
3603 | 3603 | |
3604 | 3604 | /** |
@@ -3610,7 +3610,7 @@ discard block |
||
3610 | 3610 | * @param int $tt_id Term taxonomy ID. |
3611 | 3611 | * @param string $taxonomy Taxonomy slug. |
3612 | 3612 | */ |
3613 | - do_action( "edit_term", $term_id, $tt_id, $taxonomy ); |
|
3613 | + do_action("edit_term", $term_id, $tt_id, $taxonomy); |
|
3614 | 3614 | |
3615 | 3615 | /** |
3616 | 3616 | * Fires after a term in a specific taxonomy has been updated, but before the term |
@@ -3623,10 +3623,10 @@ discard block |
||
3623 | 3623 | * @param int $term_id Term ID. |
3624 | 3624 | * @param int $tt_id Term taxonomy ID. |
3625 | 3625 | */ |
3626 | - do_action( "edit_$taxonomy", $term_id, $tt_id ); |
|
3626 | + do_action("edit_$taxonomy", $term_id, $tt_id); |
|
3627 | 3627 | |
3628 | 3628 | /** This filter is documented in wp-includes/taxonomy.php */ |
3629 | - $term_id = apply_filters( 'term_id_filter', $term_id, $tt_id ); |
|
3629 | + $term_id = apply_filters('term_id_filter', $term_id, $tt_id); |
|
3630 | 3630 | |
3631 | 3631 | clean_term_cache($term_id, $taxonomy); |
3632 | 3632 | |
@@ -3639,7 +3639,7 @@ discard block |
||
3639 | 3639 | * @param int $tt_id Term taxonomy ID. |
3640 | 3640 | * @param string $taxonomy Taxonomy slug. |
3641 | 3641 | */ |
3642 | - do_action( "edited_term", $term_id, $tt_id, $taxonomy ); |
|
3642 | + do_action("edited_term", $term_id, $tt_id, $taxonomy); |
|
3643 | 3643 | |
3644 | 3644 | /** |
3645 | 3645 | * Fires after a term for a specific taxonomy has been updated, and the term |
@@ -3652,7 +3652,7 @@ discard block |
||
3652 | 3652 | * @param int $term_id Term ID. |
3653 | 3653 | * @param int $tt_id Term taxonomy ID. |
3654 | 3654 | */ |
3655 | - do_action( "edited_$taxonomy", $term_id, $tt_id ); |
|
3655 | + do_action("edited_$taxonomy", $term_id, $tt_id); |
|
3656 | 3656 | |
3657 | 3657 | return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
3658 | 3658 | } |
@@ -3667,14 +3667,14 @@ discard block |
||
3667 | 3667 | * @param bool $defer Optional. Enable if true, disable if false. |
3668 | 3668 | * @return bool Whether term counting is enabled or disabled. |
3669 | 3669 | */ |
3670 | -function wp_defer_term_counting($defer=null) { |
|
3670 | +function wp_defer_term_counting($defer = null) { |
|
3671 | 3671 | static $_defer = false; |
3672 | 3672 | |
3673 | - if ( is_bool($defer) ) { |
|
3673 | + if (is_bool($defer)) { |
|
3674 | 3674 | $_defer = $defer; |
3675 | 3675 | // flush any deferred counts |
3676 | - if ( !$defer ) |
|
3677 | - wp_update_term_count( null, null, true ); |
|
3676 | + if ( ! $defer) |
|
3677 | + wp_update_term_count(null, null, true); |
|
3678 | 3678 | } |
3679 | 3679 | |
3680 | 3680 | return $_defer; |
@@ -3697,30 +3697,30 @@ discard block |
||
3697 | 3697 | * @param string $taxonomy The context of the term. |
3698 | 3698 | * @return bool If no terms will return false, and if successful will return true. |
3699 | 3699 | */ |
3700 | -function wp_update_term_count( $terms, $taxonomy, $do_deferred=false ) { |
|
3700 | +function wp_update_term_count($terms, $taxonomy, $do_deferred = false) { |
|
3701 | 3701 | static $_deferred = array(); |
3702 | 3702 | |
3703 | - if ( $do_deferred ) { |
|
3704 | - foreach ( (array) array_keys($_deferred) as $tax ) { |
|
3705 | - wp_update_term_count_now( $_deferred[$tax], $tax ); |
|
3706 | - unset( $_deferred[$tax] ); |
|
3703 | + if ($do_deferred) { |
|
3704 | + foreach ((array) array_keys($_deferred) as $tax) { |
|
3705 | + wp_update_term_count_now($_deferred[$tax], $tax); |
|
3706 | + unset($_deferred[$tax]); |
|
3707 | 3707 | } |
3708 | 3708 | } |
3709 | 3709 | |
3710 | - if ( empty($terms) ) |
|
3710 | + if (empty($terms)) |
|
3711 | 3711 | return false; |
3712 | 3712 | |
3713 | - if ( !is_array($terms) ) |
|
3713 | + if ( ! is_array($terms)) |
|
3714 | 3714 | $terms = array($terms); |
3715 | 3715 | |
3716 | - if ( wp_defer_term_counting() ) { |
|
3717 | - if ( !isset($_deferred[$taxonomy]) ) |
|
3716 | + if (wp_defer_term_counting()) { |
|
3717 | + if ( ! isset($_deferred[$taxonomy])) |
|
3718 | 3718 | $_deferred[$taxonomy] = array(); |
3719 | - $_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) ); |
|
3719 | + $_deferred[$taxonomy] = array_unique(array_merge($_deferred[$taxonomy], $terms)); |
|
3720 | 3720 | return true; |
3721 | 3721 | } |
3722 | 3722 | |
3723 | - return wp_update_term_count_now( $terms, $taxonomy ); |
|
3723 | + return wp_update_term_count_now($terms, $taxonomy); |
|
3724 | 3724 | } |
3725 | 3725 | |
3726 | 3726 | /** |
@@ -3732,25 +3732,25 @@ discard block |
||
3732 | 3732 | * @param string $taxonomy The context of the term. |
3733 | 3733 | * @return true Always true when complete. |
3734 | 3734 | */ |
3735 | -function wp_update_term_count_now( $terms, $taxonomy ) { |
|
3735 | +function wp_update_term_count_now($terms, $taxonomy) { |
|
3736 | 3736 | $terms = array_map('intval', $terms); |
3737 | 3737 | |
3738 | 3738 | $taxonomy = get_taxonomy($taxonomy); |
3739 | - if ( !empty($taxonomy->update_count_callback) ) { |
|
3739 | + if ( ! empty($taxonomy->update_count_callback)) { |
|
3740 | 3740 | call_user_func($taxonomy->update_count_callback, $terms, $taxonomy); |
3741 | 3741 | } else { |
3742 | 3742 | $object_types = (array) $taxonomy->object_type; |
3743 | - foreach ( $object_types as &$object_type ) { |
|
3744 | - if ( 0 === strpos( $object_type, 'attachment:' ) ) |
|
3745 | - list( $object_type ) = explode( ':', $object_type ); |
|
3743 | + foreach ($object_types as &$object_type) { |
|
3744 | + if (0 === strpos($object_type, 'attachment:')) |
|
3745 | + list($object_type) = explode(':', $object_type); |
|
3746 | 3746 | } |
3747 | 3747 | |
3748 | - if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) { |
|
3748 | + if ($object_types == array_filter($object_types, 'post_type_exists')) { |
|
3749 | 3749 | // Only post types are attached to this taxonomy |
3750 | - _update_post_term_count( $terms, $taxonomy ); |
|
3750 | + _update_post_term_count($terms, $taxonomy); |
|
3751 | 3751 | } else { |
3752 | 3752 | // Default count updater |
3753 | - _update_generic_term_count( $terms, $taxonomy ); |
|
3753 | + _update_generic_term_count($terms, $taxonomy); |
|
3754 | 3754 | } |
3755 | 3755 | } |
3756 | 3756 | |
@@ -3778,13 +3778,13 @@ discard block |
||
3778 | 3778 | * @param array|string $object_type The taxonomy object type. |
3779 | 3779 | */ |
3780 | 3780 | function clean_object_term_cache($object_ids, $object_type) { |
3781 | - if ( !is_array($object_ids) ) |
|
3781 | + if ( ! is_array($object_ids)) |
|
3782 | 3782 | $object_ids = array($object_ids); |
3783 | 3783 | |
3784 | - $taxonomies = get_object_taxonomies( $object_type ); |
|
3784 | + $taxonomies = get_object_taxonomies($object_type); |
|
3785 | 3785 | |
3786 | - foreach ( $object_ids as $id ) { |
|
3787 | - foreach ( $taxonomies as $taxonomy ) { |
|
3786 | + foreach ($object_ids as $id) { |
|
3787 | + foreach ($taxonomies as $taxonomy) { |
|
3788 | 3788 | wp_cache_delete($id, "{$taxonomy}_relationships"); |
3789 | 3789 | } |
3790 | 3790 | } |
@@ -3797,7 +3797,7 @@ discard block |
||
3797 | 3797 | * @param array $object_ids An array of object IDs. |
3798 | 3798 | * @param string $objet_type Object type. |
3799 | 3799 | */ |
3800 | - do_action( 'clean_object_term_cache', $object_ids, $object_type ); |
|
3800 | + do_action('clean_object_term_cache', $object_ids, $object_type); |
|
3801 | 3801 | } |
3802 | 3802 | |
3803 | 3803 | /** |
@@ -3817,21 +3817,21 @@ discard block |
||
3817 | 3817 | function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { |
3818 | 3818 | global $wpdb, $_wp_suspend_cache_invalidation; |
3819 | 3819 | |
3820 | - if ( ! empty( $_wp_suspend_cache_invalidation ) ) { |
|
3820 | + if ( ! empty($_wp_suspend_cache_invalidation)) { |
|
3821 | 3821 | return; |
3822 | 3822 | } |
3823 | 3823 | |
3824 | - if ( !is_array($ids) ) |
|
3824 | + if ( ! is_array($ids)) |
|
3825 | 3825 | $ids = array($ids); |
3826 | 3826 | |
3827 | 3827 | $taxonomies = array(); |
3828 | 3828 | // If no taxonomy, assume tt_ids. |
3829 | - if ( empty($taxonomy) ) { |
|
3829 | + if (empty($taxonomy)) { |
|
3830 | 3830 | $tt_ids = array_map('intval', $ids); |
3831 | 3831 | $tt_ids = implode(', ', $tt_ids); |
3832 | 3832 | $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)"); |
3833 | 3833 | $ids = array(); |
3834 | - foreach ( (array) $terms as $term ) { |
|
3834 | + foreach ((array) $terms as $term) { |
|
3835 | 3835 | $taxonomies[] = $term->taxonomy; |
3836 | 3836 | $ids[] = $term->term_id; |
3837 | 3837 | wp_cache_delete($term->term_id, $term->taxonomy); |
@@ -3839,15 +3839,15 @@ discard block |
||
3839 | 3839 | $taxonomies = array_unique($taxonomies); |
3840 | 3840 | } else { |
3841 | 3841 | $taxonomies = array($taxonomy); |
3842 | - foreach ( $taxonomies as $taxonomy ) { |
|
3843 | - foreach ( $ids as $id ) { |
|
3842 | + foreach ($taxonomies as $taxonomy) { |
|
3843 | + foreach ($ids as $id) { |
|
3844 | 3844 | wp_cache_delete($id, $taxonomy); |
3845 | 3845 | } |
3846 | 3846 | } |
3847 | 3847 | } |
3848 | 3848 | |
3849 | - foreach ( $taxonomies as $taxonomy ) { |
|
3850 | - if ( $clean_taxonomy ) { |
|
3849 | + foreach ($taxonomies as $taxonomy) { |
|
3850 | + if ($clean_taxonomy) { |
|
3851 | 3851 | wp_cache_delete('all_ids', $taxonomy); |
3852 | 3852 | wp_cache_delete('get', $taxonomy); |
3853 | 3853 | delete_option("{$taxonomy}_children"); |
@@ -3863,10 +3863,10 @@ discard block |
||
3863 | 3863 | * @param array $ids An array of term IDs. |
3864 | 3864 | * @param string $taxonomy Taxonomy slug. |
3865 | 3865 | */ |
3866 | - do_action( 'clean_term_cache', $ids, $taxonomy ); |
|
3866 | + do_action('clean_term_cache', $ids, $taxonomy); |
|
3867 | 3867 | } |
3868 | 3868 | |
3869 | - wp_cache_set( 'last_changed', microtime(), 'terms' ); |
|
3869 | + wp_cache_set('last_changed', microtime(), 'terms'); |
|
3870 | 3870 | } |
3871 | 3871 | |
3872 | 3872 | /** |
@@ -3879,8 +3879,8 @@ discard block |
||
3879 | 3879 | * @return bool|mixed Empty array if $terms found, but not `$taxonomy`. False if nothing is in cache |
3880 | 3880 | * for `$taxonomy` and `$id`. |
3881 | 3881 | */ |
3882 | -function get_object_term_cache( $id, $taxonomy ) { |
|
3883 | - return wp_cache_get( $id, "{$taxonomy}_relationships" ); |
|
3882 | +function get_object_term_cache($id, $taxonomy) { |
|
3883 | + return wp_cache_get($id, "{$taxonomy}_relationships"); |
|
3884 | 3884 | } |
3885 | 3885 | |
3886 | 3886 | /** |
@@ -3900,10 +3900,10 @@ discard block |
||
3900 | 3900 | * @return void|false False if all of the terms in `$object_ids` are already cached. |
3901 | 3901 | */ |
3902 | 3902 | function update_object_term_cache($object_ids, $object_type) { |
3903 | - if ( empty($object_ids) ) |
|
3903 | + if (empty($object_ids)) |
|
3904 | 3904 | return; |
3905 | 3905 | |
3906 | - if ( !is_array($object_ids) ) |
|
3906 | + if ( ! is_array($object_ids)) |
|
3907 | 3907 | $object_ids = explode(',', $object_ids); |
3908 | 3908 | |
3909 | 3909 | $object_ids = array_map('intval', $object_ids); |
@@ -3911,37 +3911,37 @@ discard block |
||
3911 | 3911 | $taxonomies = get_object_taxonomies($object_type); |
3912 | 3912 | |
3913 | 3913 | $ids = array(); |
3914 | - foreach ( (array) $object_ids as $id ) { |
|
3915 | - foreach ( $taxonomies as $taxonomy ) { |
|
3916 | - if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) { |
|
3914 | + foreach ((array) $object_ids as $id) { |
|
3915 | + foreach ($taxonomies as $taxonomy) { |
|
3916 | + if (false === wp_cache_get($id, "{$taxonomy}_relationships")) { |
|
3917 | 3917 | $ids[] = $id; |
3918 | 3918 | break; |
3919 | 3919 | } |
3920 | 3920 | } |
3921 | 3921 | } |
3922 | 3922 | |
3923 | - if ( empty( $ids ) ) |
|
3923 | + if (empty($ids)) |
|
3924 | 3924 | return false; |
3925 | 3925 | |
3926 | 3926 | $terms = wp_get_object_terms($ids, $taxonomies, array('fields' => 'all_with_object_id')); |
3927 | 3927 | |
3928 | 3928 | $object_terms = array(); |
3929 | - foreach ( (array) $terms as $term ) |
|
3929 | + foreach ((array) $terms as $term) |
|
3930 | 3930 | $object_terms[$term->object_id][$term->taxonomy][] = $term; |
3931 | 3931 | |
3932 | - foreach ( $ids as $id ) { |
|
3933 | - foreach ( $taxonomies as $taxonomy ) { |
|
3934 | - if ( ! isset($object_terms[$id][$taxonomy]) ) { |
|
3935 | - if ( !isset($object_terms[$id]) ) |
|
3932 | + foreach ($ids as $id) { |
|
3933 | + foreach ($taxonomies as $taxonomy) { |
|
3934 | + if ( ! isset($object_terms[$id][$taxonomy])) { |
|
3935 | + if ( ! isset($object_terms[$id])) |
|
3936 | 3936 | $object_terms[$id] = array(); |
3937 | 3937 | $object_terms[$id][$taxonomy] = array(); |
3938 | 3938 | } |
3939 | 3939 | } |
3940 | 3940 | } |
3941 | 3941 | |
3942 | - foreach ( $object_terms as $id => $value ) { |
|
3943 | - foreach ( $value as $taxonomy => $terms ) { |
|
3944 | - wp_cache_add( $id, $terms, "{$taxonomy}_relationships" ); |
|
3942 | + foreach ($object_terms as $id => $value) { |
|
3943 | + foreach ($value as $taxonomy => $terms) { |
|
3944 | + wp_cache_add($id, $terms, "{$taxonomy}_relationships"); |
|
3945 | 3945 | } |
3946 | 3946 | } |
3947 | 3947 | } |
@@ -3954,13 +3954,13 @@ discard block |
||
3954 | 3954 | * @param array $terms List of term objects to change. |
3955 | 3955 | * @param string $taxonomy Optional. Update Term to this taxonomy in cache. Default empty. |
3956 | 3956 | */ |
3957 | -function update_term_cache( $terms, $taxonomy = '' ) { |
|
3958 | - foreach ( (array) $terms as $term ) { |
|
3957 | +function update_term_cache($terms, $taxonomy = '') { |
|
3958 | + foreach ((array) $terms as $term) { |
|
3959 | 3959 | $term_taxonomy = $taxonomy; |
3960 | - if ( empty($term_taxonomy) ) |
|
3960 | + if (empty($term_taxonomy)) |
|
3961 | 3961 | $term_taxonomy = $term->taxonomy; |
3962 | 3962 | |
3963 | - wp_cache_add( $term->term_id, $term, $term_taxonomy ); |
|
3963 | + wp_cache_add($term->term_id, $term, $term_taxonomy); |
|
3964 | 3964 | } |
3965 | 3965 | } |
3966 | 3966 | |
@@ -3977,17 +3977,17 @@ discard block |
||
3977 | 3977 | * @param string $taxonomy Taxonomy name. |
3978 | 3978 | * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs. |
3979 | 3979 | */ |
3980 | -function _get_term_hierarchy( $taxonomy ) { |
|
3981 | - if ( !is_taxonomy_hierarchical($taxonomy) ) |
|
3980 | +function _get_term_hierarchy($taxonomy) { |
|
3981 | + if ( ! is_taxonomy_hierarchical($taxonomy)) |
|
3982 | 3982 | return array(); |
3983 | 3983 | $children = get_option("{$taxonomy}_children"); |
3984 | 3984 | |
3985 | - if ( is_array($children) ) |
|
3985 | + if (is_array($children)) |
|
3986 | 3986 | return $children; |
3987 | 3987 | $children = array(); |
3988 | 3988 | $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent')); |
3989 | - foreach ( $terms as $term_id => $parent ) { |
|
3990 | - if ( $parent > 0 ) |
|
3989 | + foreach ($terms as $term_id => $parent) { |
|
3990 | + if ($parent > 0) |
|
3991 | 3991 | $children[$parent][] = $term_id; |
3992 | 3992 | } |
3993 | 3993 | update_option("{$taxonomy}_children", $children); |
@@ -4014,48 +4014,48 @@ discard block |
||
4014 | 4014 | * with 1 as value. Default empty array. |
4015 | 4015 | * @return array|WP_Error The subset of $terms that are descendants of $term_id. |
4016 | 4016 | */ |
4017 | -function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() ) { |
|
4017 | +function _get_term_children($term_id, $terms, $taxonomy, &$ancestors = array()) { |
|
4018 | 4018 | $empty_array = array(); |
4019 | - if ( empty($terms) ) |
|
4019 | + if (empty($terms)) |
|
4020 | 4020 | return $empty_array; |
4021 | 4021 | |
4022 | 4022 | $term_list = array(); |
4023 | 4023 | $has_children = _get_term_hierarchy($taxonomy); |
4024 | 4024 | |
4025 | - if ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) ) |
|
4025 | + if ((0 != $term_id) && ! isset($has_children[$term_id])) |
|
4026 | 4026 | return $empty_array; |
4027 | 4027 | |
4028 | 4028 | // Include the term itself in the ancestors array, so we can properly detect when a loop has occurred. |
4029 | - if ( empty( $ancestors ) ) { |
|
4030 | - $ancestors[ $term_id ] = 1; |
|
4029 | + if (empty($ancestors)) { |
|
4030 | + $ancestors[$term_id] = 1; |
|
4031 | 4031 | } |
4032 | 4032 | |
4033 | - foreach ( (array) $terms as $term ) { |
|
4033 | + foreach ((array) $terms as $term) { |
|
4034 | 4034 | $use_id = false; |
4035 | - if ( !is_object($term) ) { |
|
4035 | + if ( ! is_object($term)) { |
|
4036 | 4036 | $term = get_term($term, $taxonomy); |
4037 | - if ( is_wp_error( $term ) ) |
|
4037 | + if (is_wp_error($term)) |
|
4038 | 4038 | return $term; |
4039 | 4039 | $use_id = true; |
4040 | 4040 | } |
4041 | 4041 | |
4042 | 4042 | // Don't recurse if we've already identified the term as a child - this indicates a loop. |
4043 | - if ( isset( $ancestors[ $term->term_id ] ) ) { |
|
4043 | + if (isset($ancestors[$term->term_id])) { |
|
4044 | 4044 | continue; |
4045 | 4045 | } |
4046 | 4046 | |
4047 | - if ( $term->parent == $term_id ) { |
|
4048 | - if ( $use_id ) |
|
4047 | + if ($term->parent == $term_id) { |
|
4048 | + if ($use_id) |
|
4049 | 4049 | $term_list[] = $term->term_id; |
4050 | 4050 | else |
4051 | 4051 | $term_list[] = $term; |
4052 | 4052 | |
4053 | - if ( !isset($has_children[$term->term_id]) ) |
|
4053 | + if ( ! isset($has_children[$term->term_id])) |
|
4054 | 4054 | continue; |
4055 | 4055 | |
4056 | - $ancestors[ $term->term_id ] = 1; |
|
4056 | + $ancestors[$term->term_id] = 1; |
|
4057 | 4057 | |
4058 | - if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors) ) |
|
4058 | + if ($children = _get_term_children($term->term_id, $terms, $taxonomy, $ancestors)) |
|
4059 | 4059 | $term_list = array_merge($term_list, $children); |
4060 | 4060 | } |
4061 | 4061 | } |
@@ -4077,23 +4077,23 @@ discard block |
||
4077 | 4077 | * @param array $terms List of term IDs, passed by reference. |
4078 | 4078 | * @param string $taxonomy Term context. |
4079 | 4079 | */ |
4080 | -function _pad_term_counts( &$terms, $taxonomy ) { |
|
4080 | +function _pad_term_counts(&$terms, $taxonomy) { |
|
4081 | 4081 | global $wpdb; |
4082 | 4082 | |
4083 | 4083 | // This function only works for hierarchical taxonomies like post categories. |
4084 | - if ( !is_taxonomy_hierarchical( $taxonomy ) ) |
|
4084 | + if ( ! is_taxonomy_hierarchical($taxonomy)) |
|
4085 | 4085 | return; |
4086 | 4086 | |
4087 | 4087 | $term_hier = _get_term_hierarchy($taxonomy); |
4088 | 4088 | |
4089 | - if ( empty($term_hier) ) |
|
4089 | + if (empty($term_hier)) |
|
4090 | 4090 | return; |
4091 | 4091 | |
4092 | 4092 | $term_items = array(); |
4093 | 4093 | $terms_by_id = array(); |
4094 | 4094 | $term_ids = array(); |
4095 | 4095 | |
4096 | - foreach ( (array) $terms as $key => $term ) { |
|
4096 | + foreach ((array) $terms as $key => $term) { |
|
4097 | 4097 | $terms_by_id[$term->term_id] = & $terms[$key]; |
4098 | 4098 | $term_ids[$term->term_taxonomy_id] = $term->term_id; |
4099 | 4099 | } |
@@ -4101,33 +4101,33 @@ discard block |
||
4101 | 4101 | // Get the object and term ids and stick them in a lookup table. |
4102 | 4102 | $tax_obj = get_taxonomy($taxonomy); |
4103 | 4103 | $object_types = esc_sql($tax_obj->object_type); |
4104 | - $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode(',', array_keys($term_ids)) . ") AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status = 'publish'"); |
|
4105 | - foreach ( $results as $row ) { |
|
4104 | + $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".implode(',', array_keys($term_ids)).") AND post_type IN ('".implode("', '", $object_types)."') AND post_status = 'publish'"); |
|
4105 | + foreach ($results as $row) { |
|
4106 | 4106 | $id = $term_ids[$row->term_taxonomy_id]; |
4107 | 4107 | $term_items[$id][$row->object_id] = isset($term_items[$id][$row->object_id]) ? ++$term_items[$id][$row->object_id] : 1; |
4108 | 4108 | } |
4109 | 4109 | |
4110 | 4110 | // Touch every ancestor's lookup row for each post in each term. |
4111 | - foreach ( $term_ids as $term_id ) { |
|
4111 | + foreach ($term_ids as $term_id) { |
|
4112 | 4112 | $child = $term_id; |
4113 | 4113 | $ancestors = array(); |
4114 | - while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) { |
|
4114 | + while ( ! empty($terms_by_id[$child]) && $parent = $terms_by_id[$child]->parent) { |
|
4115 | 4115 | $ancestors[] = $child; |
4116 | - if ( !empty( $term_items[$term_id] ) ) |
|
4117 | - foreach ( $term_items[$term_id] as $item_id => $touches ) { |
|
4118 | - $term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id]: 1; |
|
4116 | + if ( ! empty($term_items[$term_id])) |
|
4117 | + foreach ($term_items[$term_id] as $item_id => $touches) { |
|
4118 | + $term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id] : 1; |
|
4119 | 4119 | } |
4120 | 4120 | $child = $parent; |
4121 | 4121 | |
4122 | - if ( in_array( $parent, $ancestors ) ) { |
|
4122 | + if (in_array($parent, $ancestors)) { |
|
4123 | 4123 | break; |
4124 | 4124 | } |
4125 | 4125 | } |
4126 | 4126 | } |
4127 | 4127 | |
4128 | 4128 | // Transfer the touched cells. |
4129 | - foreach ( (array) $term_items as $id => $items ) |
|
4130 | - if ( isset($terms_by_id[$id]) ) |
|
4129 | + foreach ((array) $term_items as $id => $items) |
|
4130 | + if (isset($terms_by_id[$id])) |
|
4131 | 4131 | $terms_by_id[$id]->count = count($items); |
4132 | 4132 | } |
4133 | 4133 | |
@@ -4149,40 +4149,40 @@ discard block |
||
4149 | 4149 | * @param array $terms List of Term taxonomy IDs. |
4150 | 4150 | * @param object $taxonomy Current taxonomy object of terms. |
4151 | 4151 | */ |
4152 | -function _update_post_term_count( $terms, $taxonomy ) { |
|
4152 | +function _update_post_term_count($terms, $taxonomy) { |
|
4153 | 4153 | global $wpdb; |
4154 | 4154 | |
4155 | 4155 | $object_types = (array) $taxonomy->object_type; |
4156 | 4156 | |
4157 | - foreach ( $object_types as &$object_type ) |
|
4158 | - list( $object_type ) = explode( ':', $object_type ); |
|
4157 | + foreach ($object_types as &$object_type) |
|
4158 | + list($object_type) = explode(':', $object_type); |
|
4159 | 4159 | |
4160 | - $object_types = array_unique( $object_types ); |
|
4160 | + $object_types = array_unique($object_types); |
|
4161 | 4161 | |
4162 | - if ( false !== ( $check_attachments = array_search( 'attachment', $object_types ) ) ) { |
|
4163 | - unset( $object_types[ $check_attachments ] ); |
|
4162 | + if (false !== ($check_attachments = array_search('attachment', $object_types))) { |
|
4163 | + unset($object_types[$check_attachments]); |
|
4164 | 4164 | $check_attachments = true; |
4165 | 4165 | } |
4166 | 4166 | |
4167 | - if ( $object_types ) |
|
4168 | - $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) ); |
|
4167 | + if ($object_types) |
|
4168 | + $object_types = esc_sql(array_filter($object_types, 'post_type_exists')); |
|
4169 | 4169 | |
4170 | - foreach ( (array) $terms as $term ) { |
|
4170 | + foreach ((array) $terms as $term) { |
|
4171 | 4171 | $count = 0; |
4172 | 4172 | |
4173 | 4173 | // Attachments can be 'inherit' status, we need to base count off the parent's status if so. |
4174 | - if ( $check_attachments ) |
|
4175 | - $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) ); |
|
4174 | + if ($check_attachments) |
|
4175 | + $count += (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term)); |
|
4176 | 4176 | |
4177 | - if ( $object_types ) |
|
4178 | - $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) ); |
|
4177 | + if ($object_types) |
|
4178 | + $count += (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('".implode("', '", $object_types)."') AND term_taxonomy_id = %d", $term)); |
|
4179 | 4179 | |
4180 | 4180 | /** This action is documented in wp-includes/taxonomy.php */ |
4181 | - do_action( 'edit_term_taxonomy', $term, $taxonomy->name ); |
|
4182 | - $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); |
|
4181 | + do_action('edit_term_taxonomy', $term, $taxonomy->name); |
|
4182 | + $wpdb->update($wpdb->term_taxonomy, compact('count'), array('term_taxonomy_id' => $term)); |
|
4183 | 4183 | |
4184 | 4184 | /** This action is documented in wp-includes/taxonomy.php */ |
4185 | - do_action( 'edited_term_taxonomy', $term, $taxonomy->name ); |
|
4185 | + do_action('edited_term_taxonomy', $term, $taxonomy->name); |
|
4186 | 4186 | } |
4187 | 4187 | } |
4188 | 4188 | |
@@ -4198,18 +4198,18 @@ discard block |
||
4198 | 4198 | * @param array $terms List of term taxonomy IDs. |
4199 | 4199 | * @param object $taxonomy Current taxonomy object of terms. |
4200 | 4200 | */ |
4201 | -function _update_generic_term_count( $terms, $taxonomy ) { |
|
4201 | +function _update_generic_term_count($terms, $taxonomy) { |
|
4202 | 4202 | global $wpdb; |
4203 | 4203 | |
4204 | - foreach ( (array) $terms as $term ) { |
|
4205 | - $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); |
|
4204 | + foreach ((array) $terms as $term) { |
|
4205 | + $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term)); |
|
4206 | 4206 | |
4207 | 4207 | /** This action is documented in wp-includes/taxonomy.php */ |
4208 | - do_action( 'edit_term_taxonomy', $term, $taxonomy->name ); |
|
4209 | - $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); |
|
4208 | + do_action('edit_term_taxonomy', $term, $taxonomy->name); |
|
4209 | + $wpdb->update($wpdb->term_taxonomy, compact('count'), array('term_taxonomy_id' => $term)); |
|
4210 | 4210 | |
4211 | 4211 | /** This action is documented in wp-includes/taxonomy.php */ |
4212 | - do_action( 'edited_term_taxonomy', $term, $taxonomy->name ); |
|
4212 | + do_action('edited_term_taxonomy', $term, $taxonomy->name); |
|
4213 | 4213 | } |
4214 | 4214 | } |
4215 | 4215 | |
@@ -4236,23 +4236,23 @@ discard block |
||
4236 | 4236 | * database schema), `$term_id` is returned. When the term is successfully split, the |
4237 | 4237 | * new term_id is returned. A WP_Error is returned for miscellaneous errors. |
4238 | 4238 | */ |
4239 | -function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { |
|
4239 | +function _split_shared_term($term_id, $term_taxonomy_id, $record = true) { |
|
4240 | 4240 | global $wpdb; |
4241 | 4241 | |
4242 | - if ( is_object( $term_id ) ) { |
|
4242 | + if (is_object($term_id)) { |
|
4243 | 4243 | $shared_term = $term_id; |
4244 | - $term_id = intval( $shared_term->term_id ); |
|
4244 | + $term_id = intval($shared_term->term_id); |
|
4245 | 4245 | } |
4246 | 4246 | |
4247 | - if ( is_object( $term_taxonomy_id ) ) { |
|
4247 | + if (is_object($term_taxonomy_id)) { |
|
4248 | 4248 | $term_taxonomy = $term_taxonomy_id; |
4249 | - $term_taxonomy_id = intval( $term_taxonomy->term_taxonomy_id ); |
|
4249 | + $term_taxonomy_id = intval($term_taxonomy->term_taxonomy_id); |
|
4250 | 4250 | } |
4251 | 4251 | |
4252 | 4252 | // If there are no shared term_taxonomy rows, there's nothing to do here. |
4253 | - $shared_tt_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy tt WHERE tt.term_id = %d AND tt.term_taxonomy_id != %d", $term_id, $term_taxonomy_id ) ); |
|
4253 | + $shared_tt_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_taxonomy tt WHERE tt.term_id = %d AND tt.term_taxonomy_id != %d", $term_id, $term_taxonomy_id)); |
|
4254 | 4254 | |
4255 | - if ( ! $shared_tt_count ) { |
|
4255 | + if ( ! $shared_tt_count) { |
|
4256 | 4256 | return $term_id; |
4257 | 4257 | } |
4258 | 4258 | |
@@ -4260,14 +4260,14 @@ discard block |
||
4260 | 4260 | * Verify that the term_taxonomy_id passed to the function is actually associated with the term_id. |
4261 | 4261 | * If there's a mismatch, it may mean that the term is already split. Return the actual term_id from the db. |
4262 | 4262 | */ |
4263 | - $check_term_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) ); |
|
4264 | - if ( $check_term_id != $term_id ) { |
|
4263 | + $check_term_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id)); |
|
4264 | + if ($check_term_id != $term_id) { |
|
4265 | 4265 | return $check_term_id; |
4266 | 4266 | } |
4267 | 4267 | |
4268 | 4268 | // Pull up data about the currently shared slug, which we'll use to populate the new one. |
4269 | - if ( empty( $shared_term ) ) { |
|
4270 | - $shared_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.* FROM $wpdb->terms t WHERE t.term_id = %d", $term_id ) ); |
|
4269 | + if (empty($shared_term)) { |
|
4270 | + $shared_term = $wpdb->get_row($wpdb->prepare("SELECT t.* FROM $wpdb->terms t WHERE t.term_id = %d", $term_id)); |
|
4271 | 4271 | } |
4272 | 4272 | |
4273 | 4273 | $new_term_data = array( |
@@ -4276,54 +4276,54 @@ discard block |
||
4276 | 4276 | 'term_group' => $shared_term->term_group, |
4277 | 4277 | ); |
4278 | 4278 | |
4279 | - if ( false === $wpdb->insert( $wpdb->terms, $new_term_data ) ) { |
|
4280 | - return new WP_Error( 'db_insert_error', __( 'Could not split shared term.' ), $wpdb->last_error ); |
|
4279 | + if (false === $wpdb->insert($wpdb->terms, $new_term_data)) { |
|
4280 | + return new WP_Error('db_insert_error', __('Could not split shared term.'), $wpdb->last_error); |
|
4281 | 4281 | } |
4282 | 4282 | |
4283 | 4283 | $new_term_id = (int) $wpdb->insert_id; |
4284 | 4284 | |
4285 | 4285 | // Update the existing term_taxonomy to point to the newly created term. |
4286 | - $wpdb->update( $wpdb->term_taxonomy, |
|
4287 | - array( 'term_id' => $new_term_id ), |
|
4288 | - array( 'term_taxonomy_id' => $term_taxonomy_id ) |
|
4286 | + $wpdb->update($wpdb->term_taxonomy, |
|
4287 | + array('term_id' => $new_term_id), |
|
4288 | + array('term_taxonomy_id' => $term_taxonomy_id) |
|
4289 | 4289 | ); |
4290 | 4290 | |
4291 | 4291 | // Reassign child terms to the new parent. |
4292 | - if ( empty( $term_taxonomy ) ) { |
|
4293 | - $term_taxonomy = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) ); |
|
4292 | + if (empty($term_taxonomy)) { |
|
4293 | + $term_taxonomy = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id)); |
|
4294 | 4294 | } |
4295 | 4295 | |
4296 | - $children_tt_ids = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = %s", $term_id, $term_taxonomy->taxonomy ) ); |
|
4297 | - if ( ! empty( $children_tt_ids ) ) { |
|
4298 | - foreach ( $children_tt_ids as $child_tt_id ) { |
|
4299 | - $wpdb->update( $wpdb->term_taxonomy, |
|
4300 | - array( 'parent' => $new_term_id ), |
|
4301 | - array( 'term_taxonomy_id' => $child_tt_id ) |
|
4296 | + $children_tt_ids = $wpdb->get_col($wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = %s", $term_id, $term_taxonomy->taxonomy)); |
|
4297 | + if ( ! empty($children_tt_ids)) { |
|
4298 | + foreach ($children_tt_ids as $child_tt_id) { |
|
4299 | + $wpdb->update($wpdb->term_taxonomy, |
|
4300 | + array('parent' => $new_term_id), |
|
4301 | + array('term_taxonomy_id' => $child_tt_id) |
|
4302 | 4302 | ); |
4303 | - clean_term_cache( $term_id, $term_taxonomy->taxonomy ); |
|
4303 | + clean_term_cache($term_id, $term_taxonomy->taxonomy); |
|
4304 | 4304 | } |
4305 | 4305 | } else { |
4306 | 4306 | // If the term has no children, we must force its taxonomy cache to be rebuilt separately. |
4307 | - clean_term_cache( $new_term_id, $term_taxonomy->taxonomy ); |
|
4307 | + clean_term_cache($new_term_id, $term_taxonomy->taxonomy); |
|
4308 | 4308 | } |
4309 | 4309 | |
4310 | 4310 | // Clean the cache for term taxonomies formerly shared with the current term. |
4311 | - $shared_term_taxonomies = $wpdb->get_row( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) ); |
|
4312 | - if ( $shared_term_taxonomies ) { |
|
4313 | - foreach ( $shared_term_taxonomies as $shared_term_taxonomy ) { |
|
4314 | - clean_term_cache( $term_id, $shared_term_taxonomy ); |
|
4311 | + $shared_term_taxonomies = $wpdb->get_row($wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id)); |
|
4312 | + if ($shared_term_taxonomies) { |
|
4313 | + foreach ($shared_term_taxonomies as $shared_term_taxonomy) { |
|
4314 | + clean_term_cache($term_id, $shared_term_taxonomy); |
|
4315 | 4315 | } |
4316 | 4316 | } |
4317 | 4317 | |
4318 | 4318 | // Keep a record of term_ids that have been split, keyed by old term_id. See {@see wp_get_split_term()}. |
4319 | - if ( $record ) { |
|
4320 | - $split_term_data = get_option( '_split_terms', array() ); |
|
4321 | - if ( ! isset( $split_term_data[ $term_id ] ) ) { |
|
4322 | - $split_term_data[ $term_id ] = array(); |
|
4319 | + if ($record) { |
|
4320 | + $split_term_data = get_option('_split_terms', array()); |
|
4321 | + if ( ! isset($split_term_data[$term_id])) { |
|
4322 | + $split_term_data[$term_id] = array(); |
|
4323 | 4323 | } |
4324 | 4324 | |
4325 | - $split_term_data[ $term_id ][ $term_taxonomy->taxonomy ] = $new_term_id; |
|
4326 | - update_option( '_split_terms', $split_term_data ); |
|
4325 | + $split_term_data[$term_id][$term_taxonomy->taxonomy] = $new_term_id; |
|
4326 | + update_option('_split_terms', $split_term_data); |
|
4327 | 4327 | } |
4328 | 4328 | |
4329 | 4329 | /** |
@@ -4336,7 +4336,7 @@ discard block |
||
4336 | 4336 | * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
4337 | 4337 | * @param string $taxonomy Taxonomy for the split term. |
4338 | 4338 | */ |
4339 | - do_action( 'split_shared_term', $term_id, $new_term_id, $term_taxonomy_id, $term_taxonomy->taxonomy ); |
|
4339 | + do_action('split_shared_term', $term_id, $new_term_id, $term_taxonomy_id, $term_taxonomy->taxonomy); |
|
4340 | 4340 | |
4341 | 4341 | return $new_term_id; |
4342 | 4342 | } |
@@ -4354,20 +4354,20 @@ discard block |
||
4354 | 4354 | $lock_name = 'term_split.lock'; |
4355 | 4355 | |
4356 | 4356 | // Try to lock. |
4357 | - $lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time() ) ); |
|
4357 | + $lock_result = $wpdb->query($wpdb->prepare("INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time())); |
|
4358 | 4358 | |
4359 | - if ( ! $lock_result ) { |
|
4360 | - $lock_result = get_option( $lock_name ); |
|
4359 | + if ( ! $lock_result) { |
|
4360 | + $lock_result = get_option($lock_name); |
|
4361 | 4361 | |
4362 | 4362 | // Bail if we were unable to create a lock, or if the existing lock is still valid. |
4363 | - if ( ! $lock_result || ( $lock_result > ( time() - HOUR_IN_SECONDS ) ) ) { |
|
4364 | - wp_schedule_single_event( time() + ( 5 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' ); |
|
4363 | + if ( ! $lock_result || ($lock_result > (time() - HOUR_IN_SECONDS))) { |
|
4364 | + wp_schedule_single_event(time() + (5 * MINUTE_IN_SECONDS), 'wp_split_shared_term_batch'); |
|
4365 | 4365 | return; |
4366 | 4366 | } |
4367 | 4367 | } |
4368 | 4368 | |
4369 | 4369 | // Update the lock, as by this point we've definitely got a lock, just need to fire the actions. |
4370 | - update_option( $lock_name, time() ); |
|
4370 | + update_option($lock_name, time()); |
|
4371 | 4371 | |
4372 | 4372 | // Get a list of shared terms (those with more than one associated row in term_taxonomy). |
4373 | 4373 | $shared_terms = $wpdb->get_results( |
@@ -4379,61 +4379,61 @@ discard block |
||
4379 | 4379 | ); |
4380 | 4380 | |
4381 | 4381 | // No more terms, we're done here. |
4382 | - if ( ! $shared_terms ) { |
|
4383 | - update_option( 'finished_splitting_shared_terms', true ); |
|
4384 | - delete_option( $lock_name ); |
|
4382 | + if ( ! $shared_terms) { |
|
4383 | + update_option('finished_splitting_shared_terms', true); |
|
4384 | + delete_option($lock_name); |
|
4385 | 4385 | return; |
4386 | 4386 | } |
4387 | 4387 | |
4388 | 4388 | // Shared terms found? We'll need to run this script again. |
4389 | - wp_schedule_single_event( time() + ( 2 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' ); |
|
4389 | + wp_schedule_single_event(time() + (2 * MINUTE_IN_SECONDS), 'wp_split_shared_term_batch'); |
|
4390 | 4390 | |
4391 | 4391 | // Rekey shared term array for faster lookups. |
4392 | 4392 | $_shared_terms = array(); |
4393 | - foreach ( $shared_terms as $shared_term ) { |
|
4394 | - $term_id = intval( $shared_term->term_id ); |
|
4395 | - $_shared_terms[ $term_id ] = $shared_term; |
|
4393 | + foreach ($shared_terms as $shared_term) { |
|
4394 | + $term_id = intval($shared_term->term_id); |
|
4395 | + $_shared_terms[$term_id] = $shared_term; |
|
4396 | 4396 | } |
4397 | 4397 | $shared_terms = $_shared_terms; |
4398 | 4398 | |
4399 | 4399 | // Get term taxonomy data for all shared terms. |
4400 | - $shared_term_ids = implode( ',', array_keys( $shared_terms ) ); |
|
4401 | - $shared_tts = $wpdb->get_results( "SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})" ); |
|
4400 | + $shared_term_ids = implode(',', array_keys($shared_terms)); |
|
4401 | + $shared_tts = $wpdb->get_results("SELECT * FROM {$wpdb->term_taxonomy} WHERE `term_id` IN ({$shared_term_ids})"); |
|
4402 | 4402 | |
4403 | 4403 | // Split term data recording is slow, so we do it just once, outside the loop. |
4404 | - $split_term_data = get_option( '_split_terms', array() ); |
|
4404 | + $split_term_data = get_option('_split_terms', array()); |
|
4405 | 4405 | $skipped_first_term = $taxonomies = array(); |
4406 | - foreach ( $shared_tts as $shared_tt ) { |
|
4407 | - $term_id = intval( $shared_tt->term_id ); |
|
4406 | + foreach ($shared_tts as $shared_tt) { |
|
4407 | + $term_id = intval($shared_tt->term_id); |
|
4408 | 4408 | |
4409 | 4409 | // Don't split the first tt belonging to a given term_id. |
4410 | - if ( ! isset( $skipped_first_term[ $term_id ] ) ) { |
|
4411 | - $skipped_first_term[ $term_id ] = 1; |
|
4410 | + if ( ! isset($skipped_first_term[$term_id])) { |
|
4411 | + $skipped_first_term[$term_id] = 1; |
|
4412 | 4412 | continue; |
4413 | 4413 | } |
4414 | 4414 | |
4415 | - if ( ! isset( $split_term_data[ $term_id ] ) ) { |
|
4416 | - $split_term_data[ $term_id ] = array(); |
|
4415 | + if ( ! isset($split_term_data[$term_id])) { |
|
4416 | + $split_term_data[$term_id] = array(); |
|
4417 | 4417 | } |
4418 | 4418 | |
4419 | 4419 | // Keep track of taxonomies whose hierarchies need flushing. |
4420 | - if ( ! isset( $taxonomies[ $shared_tt->taxonomy ] ) ) { |
|
4421 | - $taxonomies[ $shared_tt->taxonomy ] = 1; |
|
4420 | + if ( ! isset($taxonomies[$shared_tt->taxonomy])) { |
|
4421 | + $taxonomies[$shared_tt->taxonomy] = 1; |
|
4422 | 4422 | } |
4423 | 4423 | |
4424 | 4424 | // Split the term. |
4425 | - $split_term_data[ $term_id ][ $shared_tt->taxonomy ] = _split_shared_term( $shared_terms[ $term_id ], $shared_tt, false ); |
|
4425 | + $split_term_data[$term_id][$shared_tt->taxonomy] = _split_shared_term($shared_terms[$term_id], $shared_tt, false); |
|
4426 | 4426 | } |
4427 | 4427 | |
4428 | 4428 | // Rebuild the cached hierarchy for each affected taxonomy. |
4429 | - foreach ( array_keys( $taxonomies ) as $tax ) { |
|
4430 | - delete_option( "{$tax}_children" ); |
|
4431 | - _get_term_hierarchy( $tax ); |
|
4429 | + foreach (array_keys($taxonomies) as $tax) { |
|
4430 | + delete_option("{$tax}_children"); |
|
4431 | + _get_term_hierarchy($tax); |
|
4432 | 4432 | } |
4433 | 4433 | |
4434 | - update_option( '_split_terms', $split_term_data ); |
|
4434 | + update_option('_split_terms', $split_term_data); |
|
4435 | 4435 | |
4436 | - delete_option( $lock_name ); |
|
4436 | + delete_option($lock_name); |
|
4437 | 4437 | } |
4438 | 4438 | |
4439 | 4439 | /** |
@@ -4444,8 +4444,8 @@ discard block |
||
4444 | 4444 | * @since 4.3.0 |
4445 | 4445 | */ |
4446 | 4446 | function _wp_check_for_scheduled_split_terms() { |
4447 | - if ( ! get_option( 'finished_splitting_shared_terms' ) && ! wp_next_scheduled( 'wp_batch_split_terms' ) ) { |
|
4448 | - wp_schedule_single_event( time() + MINUTE_IN_SECONDS, 'wp_batch_split_terms' ); |
|
4447 | + if ( ! get_option('finished_splitting_shared_terms') && ! wp_next_scheduled('wp_batch_split_terms')) { |
|
4448 | + wp_schedule_single_event(time() + MINUTE_IN_SECONDS, 'wp_batch_split_terms'); |
|
4449 | 4449 | } |
4450 | 4450 | } |
4451 | 4451 | |
@@ -4460,14 +4460,14 @@ discard block |
||
4460 | 4460 | * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
4461 | 4461 | * @param string $taxonomy Taxonomy for the split term. |
4462 | 4462 | */ |
4463 | -function _wp_check_split_default_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
|
4464 | - if ( 'category' != $taxonomy ) { |
|
4463 | +function _wp_check_split_default_terms($term_id, $new_term_id, $term_taxonomy_id, $taxonomy) { |
|
4464 | + if ('category' != $taxonomy) { |
|
4465 | 4465 | return; |
4466 | 4466 | } |
4467 | 4467 | |
4468 | - foreach ( array( 'default_category', 'default_link_category', 'default_email_category' ) as $option ) { |
|
4469 | - if ( $term_id == get_option( $option, -1 ) ) { |
|
4470 | - update_option( $option, $new_term_id ); |
|
4468 | + foreach (array('default_category', 'default_link_category', 'default_email_category') as $option) { |
|
4469 | + if ($term_id == get_option($option, -1)) { |
|
4470 | + update_option($option, $new_term_id); |
|
4471 | 4471 | } |
4472 | 4472 | } |
4473 | 4473 | } |
@@ -4485,9 +4485,9 @@ discard block |
||
4485 | 4485 | * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
4486 | 4486 | * @param string $taxonomy Taxonomy for the split term. |
4487 | 4487 | */ |
4488 | -function _wp_check_split_terms_in_menus( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
|
4488 | +function _wp_check_split_terms_in_menus($term_id, $new_term_id, $term_taxonomy_id, $taxonomy) { |
|
4489 | 4489 | global $wpdb; |
4490 | - $post_ids = $wpdb->get_col( $wpdb->prepare( |
|
4490 | + $post_ids = $wpdb->get_col($wpdb->prepare( |
|
4491 | 4491 | "SELECT m1.post_id |
4492 | 4492 | FROM {$wpdb->postmeta} AS m1 |
4493 | 4493 | INNER JOIN {$wpdb->postmeta} AS m2 ON ( m2.post_id = m1.post_id ) |
@@ -4497,11 +4497,11 @@ discard block |
||
4497 | 4497 | AND ( m3.meta_key = '_menu_item_object_id' AND m3.meta_value = %d )", |
4498 | 4498 | $taxonomy, |
4499 | 4499 | $term_id |
4500 | - ) ); |
|
4500 | + )); |
|
4501 | 4501 | |
4502 | - if ( $post_ids ) { |
|
4503 | - foreach ( $post_ids as $post_id ) { |
|
4504 | - update_post_meta( $post_id, '_menu_item_object_id', $new_term_id, $term_id ); |
|
4502 | + if ($post_ids) { |
|
4503 | + foreach ($post_ids as $post_id) { |
|
4504 | + update_post_meta($post_id, '_menu_item_object_id', $new_term_id, $term_id); |
|
4505 | 4505 | } |
4506 | 4506 | } |
4507 | 4507 | } |
@@ -4519,19 +4519,19 @@ discard block |
||
4519 | 4519 | * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. |
4520 | 4520 | * @param string $taxonomy Taxonomy for the split term. |
4521 | 4521 | */ |
4522 | -function _wp_check_split_nav_menu_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { |
|
4523 | - if ( 'nav_menu' !== $taxonomy ) { |
|
4522 | +function _wp_check_split_nav_menu_terms($term_id, $new_term_id, $term_taxonomy_id, $taxonomy) { |
|
4523 | + if ('nav_menu' !== $taxonomy) { |
|
4524 | 4524 | return; |
4525 | 4525 | } |
4526 | 4526 | |
4527 | 4527 | // Update menu locations. |
4528 | 4528 | $locations = get_nav_menu_locations(); |
4529 | - foreach ( $locations as $location => $menu_id ) { |
|
4530 | - if ( $term_id == $menu_id ) { |
|
4531 | - $locations[ $location ] = $new_term_id; |
|
4529 | + foreach ($locations as $location => $menu_id) { |
|
4530 | + if ($term_id == $menu_id) { |
|
4531 | + $locations[$location] = $new_term_id; |
|
4532 | 4532 | } |
4533 | 4533 | } |
4534 | - set_theme_mod( 'nav_menu_locations', $locations ); |
|
4534 | + set_theme_mod('nav_menu_locations', $locations); |
|
4535 | 4535 | } |
4536 | 4536 | |
4537 | 4537 | /** |
@@ -4542,12 +4542,12 @@ discard block |
||
4542 | 4542 | * @param int $old_term_id Term ID. This is the old, pre-split term ID. |
4543 | 4543 | * @return array Array of new term IDs, keyed by taxonomy. |
4544 | 4544 | */ |
4545 | -function wp_get_split_terms( $old_term_id ) { |
|
4546 | - $split_terms = get_option( '_split_terms', array() ); |
|
4545 | +function wp_get_split_terms($old_term_id) { |
|
4546 | + $split_terms = get_option('_split_terms', array()); |
|
4547 | 4547 | |
4548 | 4548 | $terms = array(); |
4549 | - if ( isset( $split_terms[ $old_term_id ] ) ) { |
|
4550 | - $terms = $split_terms[ $old_term_id ]; |
|
4549 | + if (isset($split_terms[$old_term_id])) { |
|
4550 | + $terms = $split_terms[$old_term_id]; |
|
4551 | 4551 | } |
4552 | 4552 | |
4553 | 4553 | return $terms; |
@@ -4564,12 +4564,12 @@ discard block |
||
4564 | 4564 | * the new term_id will be returned. If no previously split term is found matching |
4565 | 4565 | * the parameters, returns false. |
4566 | 4566 | */ |
4567 | -function wp_get_split_term( $old_term_id, $taxonomy ) { |
|
4568 | - $split_terms = wp_get_split_terms( $old_term_id ); |
|
4567 | +function wp_get_split_term($old_term_id, $taxonomy) { |
|
4568 | + $split_terms = wp_get_split_terms($old_term_id); |
|
4569 | 4569 | |
4570 | 4570 | $term_id = false; |
4571 | - if ( isset( $split_terms[ $taxonomy ] ) ) { |
|
4572 | - $term_id = (int) $split_terms[ $taxonomy ]; |
|
4571 | + if (isset($split_terms[$taxonomy])) { |
|
4572 | + $term_id = (int) $split_terms[$taxonomy]; |
|
4573 | 4573 | } |
4574 | 4574 | |
4575 | 4575 | return $term_id; |
@@ -4586,21 +4586,21 @@ discard block |
||
4586 | 4586 | * @param string $taxonomy Optional. Taxonomy. Default empty. |
4587 | 4587 | * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist. |
4588 | 4588 | */ |
4589 | -function get_term_link( $term, $taxonomy = '' ) { |
|
4589 | +function get_term_link($term, $taxonomy = '') { |
|
4590 | 4590 | global $wp_rewrite; |
4591 | 4591 | |
4592 | - if ( !is_object($term) ) { |
|
4593 | - if ( is_int( $term ) ) { |
|
4594 | - $term = get_term( $term, $taxonomy ); |
|
4592 | + if ( ! is_object($term)) { |
|
4593 | + if (is_int($term)) { |
|
4594 | + $term = get_term($term, $taxonomy); |
|
4595 | 4595 | } else { |
4596 | - $term = get_term_by( 'slug', $term, $taxonomy ); |
|
4596 | + $term = get_term_by('slug', $term, $taxonomy); |
|
4597 | 4597 | } |
4598 | 4598 | } |
4599 | 4599 | |
4600 | - if ( !is_object($term) ) |
|
4600 | + if ( ! is_object($term)) |
|
4601 | 4601 | $term = new WP_Error('invalid_term', __('Empty Term')); |
4602 | 4602 | |
4603 | - if ( is_wp_error( $term ) ) |
|
4603 | + if (is_wp_error($term)) |
|
4604 | 4604 | return $term; |
4605 | 4605 | |
4606 | 4606 | $taxonomy = $term->taxonomy; |
@@ -4610,19 +4610,19 @@ discard block |
||
4610 | 4610 | $slug = $term->slug; |
4611 | 4611 | $t = get_taxonomy($taxonomy); |
4612 | 4612 | |
4613 | - if ( empty($termlink) ) { |
|
4614 | - if ( 'category' == $taxonomy ) |
|
4615 | - $termlink = '?cat=' . $term->term_id; |
|
4616 | - elseif ( $t->query_var ) |
|
4613 | + if (empty($termlink)) { |
|
4614 | + if ('category' == $taxonomy) |
|
4615 | + $termlink = '?cat='.$term->term_id; |
|
4616 | + elseif ($t->query_var) |
|
4617 | 4617 | $termlink = "?$t->query_var=$slug"; |
4618 | 4618 | else |
4619 | 4619 | $termlink = "?taxonomy=$taxonomy&term=$slug"; |
4620 | 4620 | $termlink = home_url($termlink); |
4621 | 4621 | } else { |
4622 | - if ( $t->rewrite['hierarchical'] ) { |
|
4622 | + if ($t->rewrite['hierarchical']) { |
|
4623 | 4623 | $hierarchical_slugs = array(); |
4624 | - $ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' ); |
|
4625 | - foreach ( (array)$ancestors as $ancestor ) { |
|
4624 | + $ancestors = get_ancestors($term->term_id, $taxonomy, 'taxonomy'); |
|
4625 | + foreach ((array) $ancestors as $ancestor) { |
|
4626 | 4626 | $ancestor_term = get_term($ancestor, $taxonomy); |
4627 | 4627 | $hierarchical_slugs[] = $ancestor_term->slug; |
4628 | 4628 | } |
@@ -4632,10 +4632,10 @@ discard block |
||
4632 | 4632 | } else { |
4633 | 4633 | $termlink = str_replace("%$taxonomy%", $slug, $termlink); |
4634 | 4634 | } |
4635 | - $termlink = home_url( user_trailingslashit($termlink, 'category') ); |
|
4635 | + $termlink = home_url(user_trailingslashit($termlink, 'category')); |
|
4636 | 4636 | } |
4637 | 4637 | // Back Compat filters. |
4638 | - if ( 'post_tag' == $taxonomy ) { |
|
4638 | + if ('post_tag' == $taxonomy) { |
|
4639 | 4639 | |
4640 | 4640 | /** |
4641 | 4641 | * Filter the tag link. |
@@ -4646,8 +4646,8 @@ discard block |
||
4646 | 4646 | * @param string $termlink Tag link URL. |
4647 | 4647 | * @param int $term_id Term ID. |
4648 | 4648 | */ |
4649 | - $termlink = apply_filters( 'tag_link', $termlink, $term->term_id ); |
|
4650 | - } elseif ( 'category' == $taxonomy ) { |
|
4649 | + $termlink = apply_filters('tag_link', $termlink, $term->term_id); |
|
4650 | + } elseif ('category' == $taxonomy) { |
|
4651 | 4651 | |
4652 | 4652 | /** |
4653 | 4653 | * Filter the category link. |
@@ -4658,7 +4658,7 @@ discard block |
||
4658 | 4658 | * @param string $termlink Category link URL. |
4659 | 4659 | * @param int $term_id Term ID. |
4660 | 4660 | */ |
4661 | - $termlink = apply_filters( 'category_link', $termlink, $term->term_id ); |
|
4661 | + $termlink = apply_filters('category_link', $termlink, $term->term_id); |
|
4662 | 4662 | } |
4663 | 4663 | |
4664 | 4664 | /** |
@@ -4670,7 +4670,7 @@ discard block |
||
4670 | 4670 | * @param object $term Term object. |
4671 | 4671 | * @param string $taxonomy Taxonomy slug. |
4672 | 4672 | */ |
4673 | - return apply_filters( 'term_link', $termlink, $term, $taxonomy ); |
|
4673 | + return apply_filters('term_link', $termlink, $term, $taxonomy); |
|
4674 | 4674 | } |
4675 | 4675 | |
4676 | 4676 | /** |
@@ -4693,7 +4693,7 @@ discard block |
||
4693 | 4693 | * } |
4694 | 4694 | * @param array $args See {@link get_the_taxonomies()} for a description of arguments and their defaults. |
4695 | 4695 | */ |
4696 | -function the_taxonomies( $args = array() ) { |
|
4696 | +function the_taxonomies($args = array()) { |
|
4697 | 4697 | $defaults = array( |
4698 | 4698 | 'post' => 0, |
4699 | 4699 | 'before' => '', |
@@ -4701,9 +4701,9 @@ discard block |
||
4701 | 4701 | 'after' => '', |
4702 | 4702 | ); |
4703 | 4703 | |
4704 | - $r = wp_parse_args( $args, $defaults ); |
|
4704 | + $r = wp_parse_args($args, $defaults); |
|
4705 | 4705 | |
4706 | - echo $r['before'] . join( $r['sep'], get_the_taxonomies( $r['post'], $r ) ) . $r['after']; |
|
4706 | + echo $r['before'].join($r['sep'], get_the_taxonomies($r['post'], $r)).$r['after']; |
|
4707 | 4707 | } |
4708 | 4708 | |
4709 | 4709 | /** |
@@ -4725,47 +4725,47 @@ discard block |
||
4725 | 4725 | * } |
4726 | 4726 | * @return array List of taxonomies. |
4727 | 4727 | */ |
4728 | -function get_the_taxonomies( $post = 0, $args = array() ) { |
|
4729 | - $post = get_post( $post ); |
|
4728 | +function get_the_taxonomies($post = 0, $args = array()) { |
|
4729 | + $post = get_post($post); |
|
4730 | 4730 | |
4731 | - $args = wp_parse_args( $args, array( |
|
4731 | + $args = wp_parse_args($args, array( |
|
4732 | 4732 | /* translators: %s: taxonomy label, %l: list of terms formatted as per $term_template */ |
4733 | - 'template' => __( '%s: %l.' ), |
|
4733 | + 'template' => __('%s: %l.'), |
|
4734 | 4734 | 'term_template' => '<a href="%1$s">%2$s</a>', |
4735 | - ) ); |
|
4735 | + )); |
|
4736 | 4736 | |
4737 | 4737 | $taxonomies = array(); |
4738 | 4738 | |
4739 | - if ( ! $post ) { |
|
4739 | + if ( ! $post) { |
|
4740 | 4740 | return $taxonomies; |
4741 | 4741 | } |
4742 | 4742 | |
4743 | - foreach ( get_object_taxonomies( $post ) as $taxonomy ) { |
|
4744 | - $t = (array) get_taxonomy( $taxonomy ); |
|
4745 | - if ( empty( $t['label'] ) ) { |
|
4743 | + foreach (get_object_taxonomies($post) as $taxonomy) { |
|
4744 | + $t = (array) get_taxonomy($taxonomy); |
|
4745 | + if (empty($t['label'])) { |
|
4746 | 4746 | $t['label'] = $taxonomy; |
4747 | 4747 | } |
4748 | - if ( empty( $t['args'] ) ) { |
|
4748 | + if (empty($t['args'])) { |
|
4749 | 4749 | $t['args'] = array(); |
4750 | 4750 | } |
4751 | - if ( empty( $t['template'] ) ) { |
|
4751 | + if (empty($t['template'])) { |
|
4752 | 4752 | $t['template'] = $args['template']; |
4753 | 4753 | } |
4754 | - if ( empty( $t['term_template'] ) ) { |
|
4754 | + if (empty($t['term_template'])) { |
|
4755 | 4755 | $t['term_template'] = $args['term_template']; |
4756 | 4756 | } |
4757 | 4757 | |
4758 | - $terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
4759 | - if ( false === $terms ) { |
|
4760 | - $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); |
|
4758 | + $terms = get_object_term_cache($post->ID, $taxonomy); |
|
4759 | + if (false === $terms) { |
|
4760 | + $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); |
|
4761 | 4761 | } |
4762 | 4762 | $links = array(); |
4763 | 4763 | |
4764 | - foreach ( $terms as $term ) { |
|
4765 | - $links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link( $term ) ), $term->name ); |
|
4764 | + foreach ($terms as $term) { |
|
4765 | + $links[] = wp_sprintf($t['term_template'], esc_attr(get_term_link($term)), $term->name); |
|
4766 | 4766 | } |
4767 | - if ( $links ) { |
|
4768 | - $taxonomies[$taxonomy] = wp_sprintf( $t['template'], $t['label'], $links, $terms ); |
|
4767 | + if ($links) { |
|
4768 | + $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms); |
|
4769 | 4769 | } |
4770 | 4770 | } |
4771 | 4771 | return $taxonomies; |
@@ -4779,8 +4779,8 @@ discard block |
||
4779 | 4779 | * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
4780 | 4780 | * @return array |
4781 | 4781 | */ |
4782 | -function get_post_taxonomies( $post = 0 ) { |
|
4783 | - $post = get_post( $post ); |
|
4782 | +function get_post_taxonomies($post = 0) { |
|
4783 | + $post = get_post($post); |
|
4784 | 4784 | |
4785 | 4785 | return get_object_taxonomies($post); |
4786 | 4786 | } |
@@ -4799,43 +4799,43 @@ discard block |
||
4799 | 4799 | * @param int|string|array $terms Optional. Term term_id, name, slug or array of said. Default null. |
4800 | 4800 | * @return bool|WP_Error WP_Error on input error. |
4801 | 4801 | */ |
4802 | -function is_object_in_term( $object_id, $taxonomy, $terms = null ) { |
|
4803 | - if ( !$object_id = (int) $object_id ) |
|
4804 | - return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) ); |
|
4802 | +function is_object_in_term($object_id, $taxonomy, $terms = null) { |
|
4803 | + if ( ! $object_id = (int) $object_id) |
|
4804 | + return new WP_Error('invalid_object', __('Invalid object ID')); |
|
4805 | 4805 | |
4806 | - $object_terms = get_object_term_cache( $object_id, $taxonomy ); |
|
4807 | - if ( false === $object_terms ) |
|
4808 | - $object_terms = wp_get_object_terms( $object_id, $taxonomy ); |
|
4806 | + $object_terms = get_object_term_cache($object_id, $taxonomy); |
|
4807 | + if (false === $object_terms) |
|
4808 | + $object_terms = wp_get_object_terms($object_id, $taxonomy); |
|
4809 | 4809 | |
4810 | - if ( is_wp_error( $object_terms ) ) |
|
4810 | + if (is_wp_error($object_terms)) |
|
4811 | 4811 | return $object_terms; |
4812 | - if ( empty( $object_terms ) ) |
|
4812 | + if (empty($object_terms)) |
|
4813 | 4813 | return false; |
4814 | - if ( empty( $terms ) ) |
|
4815 | - return ( !empty( $object_terms ) ); |
|
4814 | + if (empty($terms)) |
|
4815 | + return ( ! empty($object_terms)); |
|
4816 | 4816 | |
4817 | 4817 | $terms = (array) $terms; |
4818 | 4818 | |
4819 | - if ( $ints = array_filter( $terms, 'is_int' ) ) |
|
4820 | - $strs = array_diff( $terms, $ints ); |
|
4819 | + if ($ints = array_filter($terms, 'is_int')) |
|
4820 | + $strs = array_diff($terms, $ints); |
|
4821 | 4821 | else |
4822 | - $strs =& $terms; |
|
4822 | + $strs = & $terms; |
|
4823 | 4823 | |
4824 | - foreach ( $object_terms as $object_term ) { |
|
4824 | + foreach ($object_terms as $object_term) { |
|
4825 | 4825 | // If term is an int, check against term_ids only. |
4826 | - if ( $ints && in_array( $object_term->term_id, $ints ) ) { |
|
4826 | + if ($ints && in_array($object_term->term_id, $ints)) { |
|
4827 | 4827 | return true; |
4828 | 4828 | } |
4829 | 4829 | |
4830 | - if ( $strs ) { |
|
4830 | + if ($strs) { |
|
4831 | 4831 | // Only check numeric strings against term_id, to avoid false matches due to type juggling. |
4832 | - $numeric_strs = array_map( 'intval', array_filter( $strs, 'is_numeric' ) ); |
|
4833 | - if ( in_array( $object_term->term_id, $numeric_strs, true ) ) { |
|
4832 | + $numeric_strs = array_map('intval', array_filter($strs, 'is_numeric')); |
|
4833 | + if (in_array($object_term->term_id, $numeric_strs, true)) { |
|
4834 | 4834 | return true; |
4835 | 4835 | } |
4836 | 4836 | |
4837 | - if ( in_array( $object_term->name, $strs ) ) return true; |
|
4838 | - if ( in_array( $object_term->slug, $strs ) ) return true; |
|
4837 | + if (in_array($object_term->name, $strs)) return true; |
|
4838 | + if (in_array($object_term->slug, $strs)) return true; |
|
4839 | 4839 | } |
4840 | 4840 | } |
4841 | 4841 | |
@@ -4851,12 +4851,12 @@ discard block |
||
4851 | 4851 | * @param string $taxonomy Single taxonomy name. |
4852 | 4852 | * @return bool True if object is associated with the taxonomy, otherwise false. |
4853 | 4853 | */ |
4854 | -function is_object_in_taxonomy( $object_type, $taxonomy ) { |
|
4855 | - $taxonomies = get_object_taxonomies( $object_type ); |
|
4856 | - if ( empty( $taxonomies ) ) { |
|
4854 | +function is_object_in_taxonomy($object_type, $taxonomy) { |
|
4855 | + $taxonomies = get_object_taxonomies($object_type); |
|
4856 | + if (empty($taxonomies)) { |
|
4857 | 4857 | return false; |
4858 | 4858 | } |
4859 | - return in_array( $taxonomy, $taxonomies ); |
|
4859 | + return in_array($taxonomy, $taxonomies); |
|
4860 | 4860 | } |
4861 | 4861 | |
4862 | 4862 | /** |
@@ -4872,32 +4872,32 @@ discard block |
||
4872 | 4872 | * or 'taxonomy'. Default empty. |
4873 | 4873 | * @return array An array of ancestors from lowest to highest in the hierarchy. |
4874 | 4874 | */ |
4875 | -function get_ancestors( $object_id = 0, $object_type = '', $resource_type = '' ) { |
|
4875 | +function get_ancestors($object_id = 0, $object_type = '', $resource_type = '') { |
|
4876 | 4876 | $object_id = (int) $object_id; |
4877 | 4877 | |
4878 | 4878 | $ancestors = array(); |
4879 | 4879 | |
4880 | - if ( empty( $object_id ) ) { |
|
4880 | + if (empty($object_id)) { |
|
4881 | 4881 | |
4882 | 4882 | /** This filter is documented in wp-includes/taxonomy.php */ |
4883 | - return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type, $resource_type ); |
|
4883 | + return apply_filters('get_ancestors', $ancestors, $object_id, $object_type, $resource_type); |
|
4884 | 4884 | } |
4885 | 4885 | |
4886 | - if ( ! $resource_type ) { |
|
4887 | - if ( is_taxonomy_hierarchical( $object_type ) ) { |
|
4886 | + if ( ! $resource_type) { |
|
4887 | + if (is_taxonomy_hierarchical($object_type)) { |
|
4888 | 4888 | $resource_type = 'taxonomy'; |
4889 | - } elseif ( post_type_exists( $object_type ) ) { |
|
4889 | + } elseif (post_type_exists($object_type)) { |
|
4890 | 4890 | $resource_type = 'post_type'; |
4891 | 4891 | } |
4892 | 4892 | } |
4893 | 4893 | |
4894 | - if ( 'taxonomy' === $resource_type ) { |
|
4894 | + if ('taxonomy' === $resource_type) { |
|
4895 | 4895 | $term = get_term($object_id, $object_type); |
4896 | - while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { |
|
4896 | + while ( ! is_wp_error($term) && ! empty($term->parent) && ! in_array($term->parent, $ancestors)) { |
|
4897 | 4897 | $ancestors[] = (int) $term->parent; |
4898 | 4898 | $term = get_term($term->parent, $object_type); |
4899 | 4899 | } |
4900 | - } elseif ( 'post_type' === $resource_type ) { |
|
4900 | + } elseif ('post_type' === $resource_type) { |
|
4901 | 4901 | $ancestors = get_post_ancestors($object_id); |
4902 | 4902 | } |
4903 | 4903 | |
@@ -4912,7 +4912,7 @@ discard block |
||
4912 | 4912 | * @param string $object_type Type of object. |
4913 | 4913 | * @param string $resource_type Type of resource $object_type is. |
4914 | 4914 | */ |
4915 | - return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type, $resource_type ); |
|
4915 | + return apply_filters('get_ancestors', $ancestors, $object_id, $object_type, $resource_type); |
|
4916 | 4916 | } |
4917 | 4917 | |
4918 | 4918 | /** |
@@ -4924,9 +4924,9 @@ discard block |
||
4924 | 4924 | * @param string $taxonomy Taxonomy name. |
4925 | 4925 | * @return int|false False on error. |
4926 | 4926 | */ |
4927 | -function wp_get_term_taxonomy_parent_id( $term_id, $taxonomy ) { |
|
4928 | - $term = get_term( $term_id, $taxonomy ); |
|
4929 | - if ( ! $term || is_wp_error( $term ) ) { |
|
4927 | +function wp_get_term_taxonomy_parent_id($term_id, $taxonomy) { |
|
4928 | + $term = get_term($term_id, $taxonomy); |
|
4929 | + if ( ! $term || is_wp_error($term)) { |
|
4930 | 4930 | return false; |
4931 | 4931 | } |
4932 | 4932 | return (int) $term->parent; |
@@ -4946,26 +4946,26 @@ discard block |
||
4946 | 4946 | * |
4947 | 4947 | * @return int The new parent for the term. |
4948 | 4948 | */ |
4949 | -function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) { |
|
4949 | +function wp_check_term_hierarchy_for_loops($parent, $term_id, $taxonomy) { |
|
4950 | 4950 | // Nothing fancy here - bail |
4951 | - if ( !$parent ) |
|
4951 | + if ( ! $parent) |
|
4952 | 4952 | return 0; |
4953 | 4953 | |
4954 | 4954 | // Can't be its own parent. |
4955 | - if ( $parent == $term_id ) |
|
4955 | + if ($parent == $term_id) |
|
4956 | 4956 | return 0; |
4957 | 4957 | |
4958 | 4958 | // Now look for larger loops. |
4959 | - if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) ) |
|
4959 | + if ( ! $loop = wp_find_hierarchy_loop('wp_get_term_taxonomy_parent_id', $term_id, $parent, array($taxonomy))) |
|
4960 | 4960 | return $parent; // No loop |
4961 | 4961 | |
4962 | 4962 | // Setting $parent to the given value causes a loop. |
4963 | - if ( isset( $loop[$term_id] ) ) |
|
4963 | + if (isset($loop[$term_id])) |
|
4964 | 4964 | return 0; |
4965 | 4965 | |
4966 | 4966 | // There's a loop, but it doesn't contain $term_id. Break the loop. |
4967 | - foreach ( array_keys( $loop ) as $loop_member ) |
|
4968 | - wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) ); |
|
4967 | + foreach (array_keys($loop) as $loop_member) |
|
4968 | + wp_update_term($loop_member, $taxonomy, array('parent' => 0)); |
|
4969 | 4969 | |
4970 | 4970 | return $parent; |
4971 | 4971 | } |
@@ -179,8 +179,9 @@ discard block |
||
179 | 179 | global $wp_taxonomies; |
180 | 180 | |
181 | 181 | if ( is_object($object) ) { |
182 | - if ( $object->post_type == 'attachment' ) |
|
183 | - return get_attachment_taxonomies($object); |
|
182 | + if ( $object->post_type == 'attachment' ) { |
|
183 | + return get_attachment_taxonomies($object); |
|
184 | + } |
|
184 | 185 | $object = $object->post_type; |
185 | 186 | } |
186 | 187 | |
@@ -189,10 +190,11 @@ discard block |
||
189 | 190 | $taxonomies = array(); |
190 | 191 | foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) { |
191 | 192 | if ( array_intersect($object, (array) $tax_obj->object_type) ) { |
192 | - if ( 'names' == $output ) |
|
193 | - $taxonomies[] = $tax_name; |
|
194 | - else |
|
195 | - $taxonomies[ $tax_name ] = $tax_obj; |
|
193 | + if ( 'names' == $output ) { |
|
194 | + $taxonomies[] = $tax_name; |
|
195 | + } else { |
|
196 | + $taxonomies[ $tax_name ] = $tax_obj; |
|
197 | + } |
|
196 | 198 | } |
197 | 199 | } |
198 | 200 | |
@@ -215,8 +217,9 @@ discard block |
||
215 | 217 | function get_taxonomy( $taxonomy ) { |
216 | 218 | global $wp_taxonomies; |
217 | 219 | |
218 | - if ( ! taxonomy_exists( $taxonomy ) ) |
|
219 | - return false; |
|
220 | + if ( ! taxonomy_exists( $taxonomy ) ) { |
|
221 | + return false; |
|
222 | + } |
|
220 | 223 | |
221 | 224 | return $wp_taxonomies[$taxonomy]; |
222 | 225 | } |
@@ -253,8 +256,9 @@ discard block |
||
253 | 256 | * @return bool Whether the taxonomy is hierarchical. |
254 | 257 | */ |
255 | 258 | function is_taxonomy_hierarchical($taxonomy) { |
256 | - if ( ! taxonomy_exists($taxonomy) ) |
|
257 | - return false; |
|
259 | + if ( ! taxonomy_exists($taxonomy) ) { |
|
260 | + return false; |
|
261 | + } |
|
258 | 262 | |
259 | 263 | $taxonomy = get_taxonomy($taxonomy); |
260 | 264 | return $taxonomy->hierarchical; |
@@ -335,8 +339,9 @@ discard block |
||
335 | 339 | function register_taxonomy( $taxonomy, $object_type, $args = array() ) { |
336 | 340 | global $wp_taxonomies, $wp; |
337 | 341 | |
338 | - if ( ! is_array( $wp_taxonomies ) ) |
|
339 | - $wp_taxonomies = array(); |
|
342 | + if ( ! is_array( $wp_taxonomies ) ) { |
|
343 | + $wp_taxonomies = array(); |
|
344 | + } |
|
340 | 345 | |
341 | 346 | $defaults = array( |
342 | 347 | 'labels' => array(), |
@@ -364,10 +369,11 @@ discard block |
||
364 | 369 | } |
365 | 370 | |
366 | 371 | if ( false !== $args['query_var'] && ! empty( $wp ) ) { |
367 | - if ( true === $args['query_var'] ) |
|
368 | - $args['query_var'] = $taxonomy; |
|
369 | - else |
|
370 | - $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); |
|
372 | + if ( true === $args['query_var'] ) { |
|
373 | + $args['query_var'] = $taxonomy; |
|
374 | + } else { |
|
375 | + $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); |
|
376 | + } |
|
371 | 377 | $wp->add_query_var( $args['query_var'] ); |
372 | 378 | } |
373 | 379 | |
@@ -378,33 +384,39 @@ discard block |
||
378 | 384 | 'ep_mask' => EP_NONE, |
379 | 385 | ) ); |
380 | 386 | |
381 | - if ( empty( $args['rewrite']['slug'] ) ) |
|
382 | - $args['rewrite']['slug'] = sanitize_title_with_dashes( $taxonomy ); |
|
387 | + if ( empty( $args['rewrite']['slug'] ) ) { |
|
388 | + $args['rewrite']['slug'] = sanitize_title_with_dashes( $taxonomy ); |
|
389 | + } |
|
383 | 390 | |
384 | - if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) |
|
385 | - $tag = '(.+?)'; |
|
386 | - else |
|
387 | - $tag = '([^/]+)'; |
|
391 | + if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) { |
|
392 | + $tag = '(.+?)'; |
|
393 | + } else { |
|
394 | + $tag = '([^/]+)'; |
|
395 | + } |
|
388 | 396 | |
389 | 397 | add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" ); |
390 | 398 | add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] ); |
391 | 399 | } |
392 | 400 | |
393 | 401 | // If not set, default to the setting for public. |
394 | - if ( null === $args['show_ui'] ) |
|
395 | - $args['show_ui'] = $args['public']; |
|
402 | + if ( null === $args['show_ui'] ) { |
|
403 | + $args['show_ui'] = $args['public']; |
|
404 | + } |
|
396 | 405 | |
397 | 406 | // If not set, default to the setting for show_ui. |
398 | - if ( null === $args['show_in_menu' ] || ! $args['show_ui'] ) |
|
399 | - $args['show_in_menu' ] = $args['show_ui']; |
|
407 | + if ( null === $args['show_in_menu' ] || ! $args['show_ui'] ) { |
|
408 | + $args['show_in_menu' ] = $args['show_ui']; |
|
409 | + } |
|
400 | 410 | |
401 | 411 | // If not set, default to the setting for public. |
402 | - if ( null === $args['show_in_nav_menus'] ) |
|
403 | - $args['show_in_nav_menus'] = $args['public']; |
|
412 | + if ( null === $args['show_in_nav_menus'] ) { |
|
413 | + $args['show_in_nav_menus'] = $args['public']; |
|
414 | + } |
|
404 | 415 | |
405 | 416 | // If not set, default to the setting for show_ui. |
406 | - if ( null === $args['show_tagcloud'] ) |
|
407 | - $args['show_tagcloud'] = $args['show_ui']; |
|
417 | + if ( null === $args['show_tagcloud'] ) { |
|
418 | + $args['show_tagcloud'] = $args['show_ui']; |
|
419 | + } |
|
408 | 420 | |
409 | 421 | // If not set, default to the setting for show_ui. |
410 | 422 | if ( null === $args['show_in_quick_edit'] ) { |
@@ -428,10 +440,11 @@ discard block |
||
428 | 440 | |
429 | 441 | // If not set, use the default meta box |
430 | 442 | if ( null === $args['meta_box_cb'] ) { |
431 | - if ( $args['hierarchical'] ) |
|
432 | - $args['meta_box_cb'] = 'post_categories_meta_box'; |
|
433 | - else |
|
434 | - $args['meta_box_cb'] = 'post_tags_meta_box'; |
|
443 | + if ( $args['hierarchical'] ) { |
|
444 | + $args['meta_box_cb'] = 'post_categories_meta_box'; |
|
445 | + } else { |
|
446 | + $args['meta_box_cb'] = 'post_tags_meta_box'; |
|
447 | + } |
|
435 | 448 | } |
436 | 449 | |
437 | 450 | $wp_taxonomies[ $taxonomy ] = (object) $args; |
@@ -487,11 +500,13 @@ discard block |
||
487 | 500 | function get_taxonomy_labels( $tax ) { |
488 | 501 | $tax->labels = (array) $tax->labels; |
489 | 502 | |
490 | - if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) |
|
491 | - $tax->labels['separate_items_with_commas'] = $tax->helps; |
|
503 | + if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) { |
|
504 | + $tax->labels['separate_items_with_commas'] = $tax->helps; |
|
505 | + } |
|
492 | 506 | |
493 | - if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) |
|
494 | - $tax->labels['not_found'] = $tax->no_tagcloud; |
|
507 | + if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) { |
|
508 | + $tax->labels['not_found'] = $tax->no_tagcloud; |
|
509 | + } |
|
495 | 510 | |
496 | 511 | $nohier_vs_hier_defaults = array( |
497 | 512 | 'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ), |
@@ -531,14 +546,17 @@ discard block |
||
531 | 546 | function register_taxonomy_for_object_type( $taxonomy, $object_type) { |
532 | 547 | global $wp_taxonomies; |
533 | 548 | |
534 | - if ( !isset($wp_taxonomies[$taxonomy]) ) |
|
535 | - return false; |
|
549 | + if ( !isset($wp_taxonomies[$taxonomy]) ) { |
|
550 | + return false; |
|
551 | + } |
|
536 | 552 | |
537 | - if ( ! get_post_type_object($object_type) ) |
|
538 | - return false; |
|
553 | + if ( ! get_post_type_object($object_type) ) { |
|
554 | + return false; |
|
555 | + } |
|
539 | 556 | |
540 | - if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) ) |
|
541 | - $wp_taxonomies[$taxonomy]->object_type[] = $object_type; |
|
557 | + if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) ) { |
|
558 | + $wp_taxonomies[$taxonomy]->object_type[] = $object_type; |
|
559 | + } |
|
542 | 560 | |
543 | 561 | // Filter out empties. |
544 | 562 | $wp_taxonomies[ $taxonomy ]->object_type = array_filter( $wp_taxonomies[ $taxonomy ]->object_type ); |
@@ -560,15 +578,18 @@ discard block |
||
560 | 578 | function unregister_taxonomy_for_object_type( $taxonomy, $object_type ) { |
561 | 579 | global $wp_taxonomies; |
562 | 580 | |
563 | - if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) |
|
564 | - return false; |
|
581 | + if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) { |
|
582 | + return false; |
|
583 | + } |
|
565 | 584 | |
566 | - if ( ! get_post_type_object( $object_type ) ) |
|
567 | - return false; |
|
585 | + if ( ! get_post_type_object( $object_type ) ) { |
|
586 | + return false; |
|
587 | + } |
|
568 | 588 | |
569 | 589 | $key = array_search( $object_type, $wp_taxonomies[ $taxonomy ]->object_type, true ); |
570 | - if ( false === $key ) |
|
571 | - return false; |
|
590 | + if ( false === $key ) { |
|
591 | + return false; |
|
592 | + } |
|
572 | 593 | |
573 | 594 | unset( $wp_taxonomies[ $taxonomy ]->object_type[ $key ] ); |
574 | 595 | return true; |
@@ -1221,8 +1242,9 @@ discard block |
||
1221 | 1242 | if ( is_taxonomy_hierarchical( $query['taxonomy'] ) && $query['include_children'] ) { |
1222 | 1243 | $this->transform_query( $query, 'term_id' ); |
1223 | 1244 | |
1224 | - if ( is_wp_error( $query ) ) |
|
1225 | - return; |
|
1245 | + if ( is_wp_error( $query ) ) { |
|
1246 | + return; |
|
1247 | + } |
|
1226 | 1248 | |
1227 | 1249 | $children = array(); |
1228 | 1250 | foreach ( $query['terms'] as $term ) { |
@@ -1249,11 +1271,13 @@ discard block |
||
1249 | 1271 | public function transform_query( &$query, $resulting_field ) { |
1250 | 1272 | global $wpdb; |
1251 | 1273 | |
1252 | - if ( empty( $query['terms'] ) ) |
|
1253 | - return; |
|
1274 | + if ( empty( $query['terms'] ) ) { |
|
1275 | + return; |
|
1276 | + } |
|
1254 | 1277 | |
1255 | - if ( $query['field'] == $resulting_field ) |
|
1256 | - return; |
|
1278 | + if ( $query['field'] == $resulting_field ) { |
|
1279 | + return; |
|
1280 | + } |
|
1257 | 1281 | |
1258 | 1282 | $resulting_field = sanitize_key( $resulting_field ); |
1259 | 1283 | |
@@ -1361,14 +1385,17 @@ discard block |
||
1361 | 1385 | wp_cache_add( $term->term_id, $term, $taxonomy ); |
1362 | 1386 | $_term = $term; |
1363 | 1387 | } else { |
1364 | - if ( is_object($term) ) |
|
1365 | - $term = $term->term_id; |
|
1366 | - if ( !$term = (int) $term ) |
|
1367 | - return null; |
|
1388 | + if ( is_object($term) ) { |
|
1389 | + $term = $term->term_id; |
|
1390 | + } |
|
1391 | + if ( !$term = (int) $term ) { |
|
1392 | + return null; |
|
1393 | + } |
|
1368 | 1394 | if ( ! $_term = wp_cache_get( $term, $taxonomy ) ) { |
1369 | 1395 | $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) ); |
1370 | - if ( ! $_term ) |
|
1371 | - return null; |
|
1396 | + if ( ! $_term ) { |
|
1397 | + return null; |
|
1398 | + } |
|
1372 | 1399 | wp_cache_add( $term, $_term, $taxonomy ); |
1373 | 1400 | } |
1374 | 1401 | } |
@@ -1440,14 +1467,16 @@ discard block |
||
1440 | 1467 | function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') { |
1441 | 1468 | global $wpdb; |
1442 | 1469 | |
1443 | - if ( ! taxonomy_exists($taxonomy) ) |
|
1444 | - return false; |
|
1470 | + if ( ! taxonomy_exists($taxonomy) ) { |
|
1471 | + return false; |
|
1472 | + } |
|
1445 | 1473 | |
1446 | 1474 | if ( 'slug' == $field ) { |
1447 | 1475 | $field = 't.slug'; |
1448 | 1476 | $value = sanitize_title($value); |
1449 | - if ( empty($value) ) |
|
1450 | - return false; |
|
1477 | + if ( empty($value) ) { |
|
1478 | + return false; |
|
1479 | + } |
|
1451 | 1480 | } elseif ( 'name' == $field ) { |
1452 | 1481 | // Assume already escaped |
1453 | 1482 | $value = wp_unslash($value); |
@@ -1457,14 +1486,16 @@ discard block |
||
1457 | 1486 | $field = 'tt.term_taxonomy_id'; |
1458 | 1487 | } else { |
1459 | 1488 | $term = get_term( (int) $value, $taxonomy, $output, $filter ); |
1460 | - if ( is_wp_error( $term ) ) |
|
1461 | - $term = false; |
|
1489 | + if ( is_wp_error( $term ) ) { |
|
1490 | + $term = false; |
|
1491 | + } |
|
1462 | 1492 | return $term; |
1463 | 1493 | } |
1464 | 1494 | |
1465 | 1495 | $term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value ) ); |
1466 | - if ( ! $term ) |
|
1467 | - return false; |
|
1496 | + if ( ! $term ) { |
|
1497 | + return false; |
|
1498 | + } |
|
1468 | 1499 | |
1469 | 1500 | wp_cache_add( $term->term_id, $term, $taxonomy ); |
1470 | 1501 | |
@@ -1502,15 +1533,17 @@ discard block |
||
1502 | 1533 | * @return array|WP_Error List of Term IDs. WP_Error returned if `$taxonomy` does not exist. |
1503 | 1534 | */ |
1504 | 1535 | function get_term_children( $term_id, $taxonomy ) { |
1505 | - if ( ! taxonomy_exists($taxonomy) ) |
|
1506 | - return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
1536 | + if ( ! taxonomy_exists($taxonomy) ) { |
|
1537 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
1538 | + } |
|
1507 | 1539 | |
1508 | 1540 | $term_id = intval( $term_id ); |
1509 | 1541 | |
1510 | 1542 | $terms = _get_term_hierarchy($taxonomy); |
1511 | 1543 | |
1512 | - if ( ! isset($terms[$term_id]) ) |
|
1513 | - return array(); |
|
1544 | + if ( ! isset($terms[$term_id]) ) { |
|
1545 | + return array(); |
|
1546 | + } |
|
1514 | 1547 | |
1515 | 1548 | $children = $terms[$term_id]; |
1516 | 1549 | |
@@ -1519,8 +1552,9 @@ discard block |
||
1519 | 1552 | continue; |
1520 | 1553 | } |
1521 | 1554 | |
1522 | - if ( isset($terms[$child]) ) |
|
1523 | - $children = array_merge($children, get_term_children($child, $taxonomy)); |
|
1555 | + if ( isset($terms[$child]) ) { |
|
1556 | + $children = array_merge($children, get_term_children($child, $taxonomy)); |
|
1557 | + } |
|
1524 | 1558 | } |
1525 | 1559 | |
1526 | 1560 | return $children; |
@@ -1544,14 +1578,17 @@ discard block |
||
1544 | 1578 | function get_term_field( $field, $term, $taxonomy, $context = 'display' ) { |
1545 | 1579 | $term = (int) $term; |
1546 | 1580 | $term = get_term( $term, $taxonomy ); |
1547 | - if ( is_wp_error($term) ) |
|
1548 | - return $term; |
|
1581 | + if ( is_wp_error($term) ) { |
|
1582 | + return $term; |
|
1583 | + } |
|
1549 | 1584 | |
1550 | - if ( !is_object($term) ) |
|
1551 | - return ''; |
|
1585 | + if ( !is_object($term) ) { |
|
1586 | + return ''; |
|
1587 | + } |
|
1552 | 1588 | |
1553 | - if ( !isset($term->$field) ) |
|
1554 | - return ''; |
|
1589 | + if ( !isset($term->$field) ) { |
|
1590 | + return ''; |
|
1591 | + } |
|
1555 | 1592 | |
1556 | 1593 | return sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context); |
1557 | 1594 | } |
@@ -1571,11 +1608,13 @@ discard block |
||
1571 | 1608 | function get_term_to_edit( $id, $taxonomy ) { |
1572 | 1609 | $term = get_term( $id, $taxonomy ); |
1573 | 1610 | |
1574 | - if ( is_wp_error($term) ) |
|
1575 | - return $term; |
|
1611 | + if ( is_wp_error($term) ) { |
|
1612 | + return $term; |
|
1613 | + } |
|
1576 | 1614 | |
1577 | - if ( !is_object($term) ) |
|
1578 | - return ''; |
|
1615 | + if ( !is_object($term) ) { |
|
1616 | + return ''; |
|
1617 | + } |
|
1579 | 1618 | |
1580 | 1619 | return sanitize_term($term, $taxonomy, 'edit'); |
1581 | 1620 | } |
@@ -2116,13 +2155,15 @@ discard block |
||
2116 | 2155 | $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE "; |
2117 | 2156 | |
2118 | 2157 | if ( is_int($term) ) { |
2119 | - if ( 0 == $term ) |
|
2120 | - return 0; |
|
2158 | + if ( 0 == $term ) { |
|
2159 | + return 0; |
|
2160 | + } |
|
2121 | 2161 | $where = 't.term_id = %d'; |
2122 | - if ( !empty($taxonomy) ) |
|
2123 | - return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A ); |
|
2124 | - else |
|
2125 | - return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) ); |
|
2162 | + if ( !empty($taxonomy) ) { |
|
2163 | + return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A ); |
|
2164 | + } else { |
|
2165 | + return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) ); |
|
2166 | + } |
|
2126 | 2167 | } |
2127 | 2168 | |
2128 | 2169 | $term = trim( wp_unslash( $term ) ); |
@@ -2146,14 +2187,16 @@ discard block |
||
2146 | 2187 | $where_fields[] = $taxonomy; |
2147 | 2188 | $else_where_fields[] = $taxonomy; |
2148 | 2189 | |
2149 | - if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields), ARRAY_A) ) |
|
2150 | - return $result; |
|
2190 | + if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields), ARRAY_A) ) { |
|
2191 | + return $result; |
|
2192 | + } |
|
2151 | 2193 | |
2152 | 2194 | return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields), ARRAY_A); |
2153 | 2195 | } |
2154 | 2196 | |
2155 | - if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields) ) ) |
|
2156 | - return $result; |
|
2197 | + if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields) ) ) { |
|
2198 | + return $result; |
|
2199 | + } |
|
2157 | 2200 | |
2158 | 2201 | return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields) ); |
2159 | 2202 | } |
@@ -2171,15 +2214,19 @@ discard block |
||
2171 | 2214 | * @return bool Whether `$term2` is a child of `$term1`. |
2172 | 2215 | */ |
2173 | 2216 | function term_is_ancestor_of( $term1, $term2, $taxonomy ) { |
2174 | - if ( ! isset( $term1->term_id ) ) |
|
2175 | - $term1 = get_term( $term1, $taxonomy ); |
|
2176 | - if ( ! isset( $term2->parent ) ) |
|
2177 | - $term2 = get_term( $term2, $taxonomy ); |
|
2217 | + if ( ! isset( $term1->term_id ) ) { |
|
2218 | + $term1 = get_term( $term1, $taxonomy ); |
|
2219 | + } |
|
2220 | + if ( ! isset( $term2->parent ) ) { |
|
2221 | + $term2 = get_term( $term2, $taxonomy ); |
|
2222 | + } |
|
2178 | 2223 | |
2179 | - if ( empty( $term1->term_id ) || empty( $term2->parent ) ) |
|
2180 | - return false; |
|
2181 | - if ( $term2->parent == $term1->term_id ) |
|
2182 | - return true; |
|
2224 | + if ( empty( $term1->term_id ) || empty( $term2->parent ) ) { |
|
2225 | + return false; |
|
2226 | + } |
|
2227 | + if ( $term2->parent == $term1->term_id ) { |
|
2228 | + return true; |
|
2229 | + } |
|
2183 | 2230 | |
2184 | 2231 | return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy ); |
2185 | 2232 | } |
@@ -2210,18 +2257,21 @@ discard block |
||
2210 | 2257 | |
2211 | 2258 | foreach ( (array) $fields as $field ) { |
2212 | 2259 | if ( $do_object ) { |
2213 | - if ( isset($term->$field) ) |
|
2214 | - $term->$field = sanitize_term_field($field, $term->$field, $term_id, $taxonomy, $context); |
|
2260 | + if ( isset($term->$field) ) { |
|
2261 | + $term->$field = sanitize_term_field($field, $term->$field, $term_id, $taxonomy, $context); |
|
2262 | + } |
|
2215 | 2263 | } else { |
2216 | - if ( isset($term[$field]) ) |
|
2217 | - $term[$field] = sanitize_term_field($field, $term[$field], $term_id, $taxonomy, $context); |
|
2264 | + if ( isset($term[$field]) ) { |
|
2265 | + $term[$field] = sanitize_term_field($field, $term[$field], $term_id, $taxonomy, $context); |
|
2266 | + } |
|
2218 | 2267 | } |
2219 | 2268 | } |
2220 | 2269 | |
2221 | - if ( $do_object ) |
|
2222 | - $term->filter = $context; |
|
2223 | - else |
|
2224 | - $term['filter'] = $context; |
|
2270 | + if ( $do_object ) { |
|
2271 | + $term->filter = $context; |
|
2272 | + } else { |
|
2273 | + $term['filter'] = $context; |
|
2274 | + } |
|
2225 | 2275 | |
2226 | 2276 | return $term; |
2227 | 2277 | } |
@@ -2253,12 +2303,14 @@ discard block |
||
2253 | 2303 | $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' ); |
2254 | 2304 | if ( in_array( $field, $int_fields ) ) { |
2255 | 2305 | $value = (int) $value; |
2256 | - if ( $value < 0 ) |
|
2257 | - $value = 0; |
|
2306 | + if ( $value < 0 ) { |
|
2307 | + $value = 0; |
|
2308 | + } |
|
2258 | 2309 | } |
2259 | 2310 | |
2260 | - if ( 'raw' == $context ) |
|
2261 | - return $value; |
|
2311 | + if ( 'raw' == $context ) { |
|
2312 | + return $value; |
|
2313 | + } |
|
2262 | 2314 | |
2263 | 2315 | if ( 'edit' == $context ) { |
2264 | 2316 | |
@@ -2288,10 +2340,13 @@ discard block |
||
2288 | 2340 | */ |
2289 | 2341 | $value = apply_filters( "edit_{$taxonomy}_{$field}", $value, $term_id ); |
2290 | 2342 | |
2291 | - if ( 'description' == $field ) |
|
2292 | - $value = esc_html($value); // textarea_escaped |
|
2293 | - else |
|
2294 | - $value = esc_attr($value); |
|
2343 | + if ( 'description' == $field ) { |
|
2344 | + $value = esc_html($value); |
|
2345 | + } |
|
2346 | + // textarea_escaped |
|
2347 | + else { |
|
2348 | + $value = esc_attr($value); |
|
2349 | + } |
|
2295 | 2350 | } elseif ( 'db' == $context ) { |
2296 | 2351 | |
2297 | 2352 | /** |
@@ -2440,8 +2495,9 @@ discard block |
||
2440 | 2495 | function wp_delete_object_term_relationships( $object_id, $taxonomies ) { |
2441 | 2496 | $object_id = (int) $object_id; |
2442 | 2497 | |
2443 | - if ( !is_array($taxonomies) ) |
|
2444 | - $taxonomies = array($taxonomies); |
|
2498 | + if ( !is_array($taxonomies) ) { |
|
2499 | + $taxonomies = array($taxonomies); |
|
2500 | + } |
|
2445 | 2501 | |
2446 | 2502 | foreach ( (array) $taxonomies as $taxonomy ) { |
2447 | 2503 | $term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids' ) ); |
@@ -2478,10 +2534,12 @@ discard block |
||
2478 | 2534 | |
2479 | 2535 | $term = (int) $term; |
2480 | 2536 | |
2481 | - if ( ! $ids = term_exists($term, $taxonomy) ) |
|
2482 | - return false; |
|
2483 | - if ( is_wp_error( $ids ) ) |
|
2484 | - return $ids; |
|
2537 | + if ( ! $ids = term_exists($term, $taxonomy) ) { |
|
2538 | + return false; |
|
2539 | + } |
|
2540 | + if ( is_wp_error( $ids ) ) { |
|
2541 | + return $ids; |
|
2542 | + } |
|
2485 | 2543 | |
2486 | 2544 | $tt_id = $ids['term_taxonomy_id']; |
2487 | 2545 | |
@@ -2489,8 +2547,10 @@ discard block |
||
2489 | 2547 | |
2490 | 2548 | if ( 'category' == $taxonomy ) { |
2491 | 2549 | $defaults['default'] = get_option( 'default_category' ); |
2492 | - if ( $defaults['default'] == $term ) |
|
2493 | - return 0; // Don't delete the default category |
|
2550 | + if ( $defaults['default'] == $term ) { |
|
2551 | + return 0; |
|
2552 | + } |
|
2553 | + // Don't delete the default category |
|
2494 | 2554 | } |
2495 | 2555 | |
2496 | 2556 | $args = wp_parse_args($args, $defaults); |
@@ -2519,8 +2579,9 @@ discard block |
||
2519 | 2579 | // Update children to point to new parent |
2520 | 2580 | if ( is_taxonomy_hierarchical($taxonomy) ) { |
2521 | 2581 | $term_obj = get_term($term, $taxonomy); |
2522 | - if ( is_wp_error( $term_obj ) ) |
|
2523 | - return $term_obj; |
|
2582 | + if ( is_wp_error( $term_obj ) ) { |
|
2583 | + return $term_obj; |
|
2584 | + } |
|
2524 | 2585 | $parent = $term_obj->parent; |
2525 | 2586 | |
2526 | 2587 | $edit_ids = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int)$term_obj->term_id ); |
@@ -2559,8 +2620,9 @@ discard block |
||
2559 | 2620 | $terms = array($default); |
2560 | 2621 | } else { |
2561 | 2622 | $terms = array_diff($terms, array($term)); |
2562 | - if (isset($default) && isset($force_default) && $force_default) |
|
2563 | - $terms = array_merge($terms, array($default)); |
|
2623 | + if (isset($default) && isset($force_default) && $force_default) { |
|
2624 | + $terms = array_merge($terms, array($default)); |
|
2625 | + } |
|
2564 | 2626 | } |
2565 | 2627 | $terms = array_map('intval', $terms); |
2566 | 2628 | wp_set_object_terms($object, $terms, $taxonomy); |
@@ -2568,8 +2630,9 @@ discard block |
||
2568 | 2630 | |
2569 | 2631 | // Clean the relationship caches for all object types using this term. |
2570 | 2632 | $tax_object = get_taxonomy( $taxonomy ); |
2571 | - foreach ( $tax_object->object_type as $object_type ) |
|
2572 | - clean_object_term_cache( $objects, $object_type ); |
|
2633 | + foreach ( $tax_object->object_type as $object_type ) { |
|
2634 | + clean_object_term_cache( $objects, $object_type ); |
|
2635 | + } |
|
2573 | 2636 | |
2574 | 2637 | // Get the object before deletion so we can pass to actions below |
2575 | 2638 | $deleted_term = get_term( $term, $taxonomy ); |
@@ -2594,8 +2657,9 @@ discard block |
||
2594 | 2657 | do_action( 'deleted_term_taxonomy', $tt_id ); |
2595 | 2658 | |
2596 | 2659 | // Delete the term if no taxonomies use it. |
2597 | - if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) |
|
2598 | - $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); |
|
2660 | + if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) { |
|
2661 | + $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); |
|
2662 | + } |
|
2599 | 2663 | |
2600 | 2664 | clean_term_cache($term, $taxonomy); |
2601 | 2665 | |
@@ -2671,19 +2735,23 @@ discard block |
||
2671 | 2735 | function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { |
2672 | 2736 | global $wpdb; |
2673 | 2737 | |
2674 | - if ( empty( $object_ids ) || empty( $taxonomies ) ) |
|
2675 | - return array(); |
|
2738 | + if ( empty( $object_ids ) || empty( $taxonomies ) ) { |
|
2739 | + return array(); |
|
2740 | + } |
|
2676 | 2741 | |
2677 | - if ( !is_array($taxonomies) ) |
|
2678 | - $taxonomies = array($taxonomies); |
|
2742 | + if ( !is_array($taxonomies) ) { |
|
2743 | + $taxonomies = array($taxonomies); |
|
2744 | + } |
|
2679 | 2745 | |
2680 | 2746 | foreach ( $taxonomies as $taxonomy ) { |
2681 | - if ( ! taxonomy_exists($taxonomy) ) |
|
2682 | - return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
2747 | + if ( ! taxonomy_exists($taxonomy) ) { |
|
2748 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
2749 | + } |
|
2683 | 2750 | } |
2684 | 2751 | |
2685 | - if ( !is_array($object_ids) ) |
|
2686 | - $object_ids = array($object_ids); |
|
2752 | + if ( !is_array($object_ids) ) { |
|
2753 | + $object_ids = array($object_ids); |
|
2754 | + } |
|
2687 | 2755 | $object_ids = array_map('intval', $object_ids); |
2688 | 2756 | |
2689 | 2757 | $defaults = array( |
@@ -2705,8 +2773,9 @@ discard block |
||
2705 | 2773 | } |
2706 | 2774 | } else { |
2707 | 2775 | $t = get_taxonomy($taxonomies[0]); |
2708 | - if ( isset($t->args) && is_array($t->args) ) |
|
2709 | - $args = array_merge($args, $t->args); |
|
2776 | + if ( isset($t->args) && is_array($t->args) ) { |
|
2777 | + $args = array_merge($args, $t->args); |
|
2778 | + } |
|
2710 | 2779 | } |
2711 | 2780 | |
2712 | 2781 | $orderby = $args['orderby']; |
@@ -2727,15 +2796,18 @@ discard block |
||
2727 | 2796 | } |
2728 | 2797 | |
2729 | 2798 | // tt_ids queries can only be none or tr.term_taxonomy_id |
2730 | - if ( ('tt_ids' == $fields) && !empty($orderby) ) |
|
2731 | - $orderby = 'tr.term_taxonomy_id'; |
|
2799 | + if ( ('tt_ids' == $fields) && !empty($orderby) ) { |
|
2800 | + $orderby = 'tr.term_taxonomy_id'; |
|
2801 | + } |
|
2732 | 2802 | |
2733 | - if ( !empty($orderby) ) |
|
2734 | - $orderby = "ORDER BY $orderby"; |
|
2803 | + if ( !empty($orderby) ) { |
|
2804 | + $orderby = "ORDER BY $orderby"; |
|
2805 | + } |
|
2735 | 2806 | |
2736 | 2807 | $order = strtoupper( $order ); |
2737 | - if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) |
|
2738 | - $order = 'ASC'; |
|
2808 | + if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) { |
|
2809 | + $order = 'ASC'; |
|
2810 | + } |
|
2739 | 2811 | |
2740 | 2812 | $taxonomy_array = $taxonomies; |
2741 | 2813 | $object_id_array = $object_ids; |
@@ -3109,39 +3181,46 @@ discard block |
||
3109 | 3181 | |
3110 | 3182 | $object_id = (int) $object_id; |
3111 | 3183 | |
3112 | - if ( ! taxonomy_exists($taxonomy) ) |
|
3113 | - return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
3184 | + if ( ! taxonomy_exists($taxonomy) ) { |
|
3185 | + return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); |
|
3186 | + } |
|
3114 | 3187 | |
3115 | - if ( !is_array($terms) ) |
|
3116 | - $terms = array($terms); |
|
3188 | + if ( !is_array($terms) ) { |
|
3189 | + $terms = array($terms); |
|
3190 | + } |
|
3117 | 3191 | |
3118 | - if ( ! $append ) |
|
3119 | - $old_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none')); |
|
3120 | - else |
|
3121 | - $old_tt_ids = array(); |
|
3192 | + if ( ! $append ) { |
|
3193 | + $old_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none')); |
|
3194 | + } else { |
|
3195 | + $old_tt_ids = array(); |
|
3196 | + } |
|
3122 | 3197 | |
3123 | 3198 | $tt_ids = array(); |
3124 | 3199 | $term_ids = array(); |
3125 | 3200 | $new_tt_ids = array(); |
3126 | 3201 | |
3127 | 3202 | foreach ( (array) $terms as $term) { |
3128 | - if ( !strlen(trim($term)) ) |
|
3129 | - continue; |
|
3203 | + if ( !strlen(trim($term)) ) { |
|
3204 | + continue; |
|
3205 | + } |
|
3130 | 3206 | |
3131 | 3207 | if ( !$term_info = term_exists($term, $taxonomy) ) { |
3132 | 3208 | // Skip if a non-existent term ID is passed. |
3133 | - if ( is_int($term) ) |
|
3134 | - continue; |
|
3209 | + if ( is_int($term) ) { |
|
3210 | + continue; |
|
3211 | + } |
|
3135 | 3212 | $term_info = wp_insert_term($term, $taxonomy); |
3136 | 3213 | } |
3137 | - if ( is_wp_error($term_info) ) |
|
3138 | - return $term_info; |
|
3214 | + if ( is_wp_error($term_info) ) { |
|
3215 | + return $term_info; |
|
3216 | + } |
|
3139 | 3217 | $term_ids[] = $term_info['term_id']; |
3140 | 3218 | $tt_id = $term_info['term_taxonomy_id']; |
3141 | 3219 | $tt_ids[] = $tt_id; |
3142 | 3220 | |
3143 | - if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) |
|
3144 | - continue; |
|
3221 | + if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) { |
|
3222 | + continue; |
|
3223 | + } |
|
3145 | 3224 | |
3146 | 3225 | /** |
3147 | 3226 | * Fires immediately before an object-term relationship is added. |
@@ -3166,8 +3245,9 @@ discard block |
||
3166 | 3245 | $new_tt_ids[] = $tt_id; |
3167 | 3246 | } |
3168 | 3247 | |
3169 | - if ( $new_tt_ids ) |
|
3170 | - wp_update_term_count( $new_tt_ids, $taxonomy ); |
|
3248 | + if ( $new_tt_ids ) { |
|
3249 | + wp_update_term_count( $new_tt_ids, $taxonomy ); |
|
3250 | + } |
|
3171 | 3251 | |
3172 | 3252 | if ( ! $append ) { |
3173 | 3253 | $delete_tt_ids = array_diff( $old_tt_ids, $tt_ids ); |
@@ -3189,12 +3269,14 @@ discard block |
||
3189 | 3269 | $values = array(); |
3190 | 3270 | $term_order = 0; |
3191 | 3271 | $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids')); |
3192 | - foreach ( $tt_ids as $tt_id ) |
|
3193 | - if ( in_array($tt_id, $final_tt_ids) ) |
|
3272 | + foreach ( $tt_ids as $tt_id ) { |
|
3273 | + if ( in_array($tt_id, $final_tt_ids) ) |
|
3194 | 3274 | $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); |
3195 | - if ( $values ) |
|
3196 | - if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ) |
|
3275 | + } |
|
3276 | + if ( $values ) { |
|
3277 | + if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ) |
|
3197 | 3278 | return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database' ), $wpdb->last_error ); |
3279 | + } |
|
3198 | 3280 | } |
3199 | 3281 | |
3200 | 3282 | wp_cache_delete( $object_id, $taxonomy . '_relationships' ); |
@@ -3350,15 +3432,17 @@ discard block |
||
3350 | 3432 | $the_parent = $term->parent; |
3351 | 3433 | while ( ! empty($the_parent) ) { |
3352 | 3434 | $parent_term = get_term($the_parent, $term->taxonomy); |
3353 | - if ( is_wp_error($parent_term) || empty($parent_term) ) |
|
3354 | - break; |
|
3435 | + if ( is_wp_error($parent_term) || empty($parent_term) ) { |
|
3436 | + break; |
|
3437 | + } |
|
3355 | 3438 | $parent_suffix .= '-' . $parent_term->slug; |
3356 | 3439 | if ( ! term_exists( $slug . $parent_suffix ) ) { |
3357 | 3440 | break; |
3358 | 3441 | } |
3359 | 3442 | |
3360 | - if ( empty($parent_term->parent) ) |
|
3361 | - break; |
|
3443 | + if ( empty($parent_term->parent) ) { |
|
3444 | + break; |
|
3445 | + } |
|
3362 | 3446 | $the_parent = $parent_term->parent; |
3363 | 3447 | } |
3364 | 3448 | } |
@@ -3378,10 +3462,11 @@ discard block |
||
3378 | 3462 | if ( $parent_suffix ) { |
3379 | 3463 | $slug .= $parent_suffix; |
3380 | 3464 | } else { |
3381 | - if ( ! empty( $term->term_id ) ) |
|
3382 | - $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); |
|
3383 | - else |
|
3384 | - $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); |
|
3465 | + if ( ! empty( $term->term_id ) ) { |
|
3466 | + $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); |
|
3467 | + } else { |
|
3468 | + $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); |
|
3469 | + } |
|
3385 | 3470 | |
3386 | 3471 | if ( $wpdb->get_var( $query ) ) { |
3387 | 3472 | $num = 2; |
@@ -3475,8 +3560,9 @@ discard block |
||
3475 | 3560 | $parsed_args['name'] = $name; |
3476 | 3561 | $parsed_args['description'] = $description; |
3477 | 3562 | |
3478 | - if ( '' == trim($name) ) |
|
3479 | - return new WP_Error('empty_term_name', __('A name is required for this term')); |
|
3563 | + if ( '' == trim($name) ) { |
|
3564 | + return new WP_Error('empty_term_name', __('A name is required for this term')); |
|
3565 | + } |
|
3480 | 3566 | |
3481 | 3567 | if ( $parsed_args['parent'] > 0 && ! term_exists( (int) $parsed_args['parent'] ) ) { |
3482 | 3568 | return new WP_Error( 'missing_parent', __( 'Parent term does not exist.' ) ); |
@@ -3533,10 +3619,11 @@ discard block |
||
3533 | 3619 | if ( $duplicate && $duplicate->term_id != $term_id ) { |
3534 | 3620 | // If an empty slug was passed or the parent changed, reset the slug to something unique. |
3535 | 3621 | // Otherwise, bail. |
3536 | - if ( $empty_slug || ( $parent != $term['parent']) ) |
|
3537 | - $slug = wp_unique_term_slug($slug, (object) $args); |
|
3538 | - else |
|
3539 | - return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); |
|
3622 | + if ( $empty_slug || ( $parent != $term['parent']) ) { |
|
3623 | + $slug = wp_unique_term_slug($slug, (object) $args); |
|
3624 | + } else { |
|
3625 | + return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); |
|
3626 | + } |
|
3540 | 3627 | } |
3541 | 3628 | |
3542 | 3629 | $tt_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) ); |
@@ -3673,8 +3760,9 @@ discard block |
||
3673 | 3760 | if ( is_bool($defer) ) { |
3674 | 3761 | $_defer = $defer; |
3675 | 3762 | // flush any deferred counts |
3676 | - if ( !$defer ) |
|
3677 | - wp_update_term_count( null, null, true ); |
|
3763 | + if ( !$defer ) { |
|
3764 | + wp_update_term_count( null, null, true ); |
|
3765 | + } |
|
3678 | 3766 | } |
3679 | 3767 | |
3680 | 3768 | return $_defer; |
@@ -3707,15 +3795,18 @@ discard block |
||
3707 | 3795 | } |
3708 | 3796 | } |
3709 | 3797 | |
3710 | - if ( empty($terms) ) |
|
3711 | - return false; |
|
3798 | + if ( empty($terms) ) { |
|
3799 | + return false; |
|
3800 | + } |
|
3712 | 3801 | |
3713 | - if ( !is_array($terms) ) |
|
3714 | - $terms = array($terms); |
|
3802 | + if ( !is_array($terms) ) { |
|
3803 | + $terms = array($terms); |
|
3804 | + } |
|
3715 | 3805 | |
3716 | 3806 | if ( wp_defer_term_counting() ) { |
3717 | - if ( !isset($_deferred[$taxonomy]) ) |
|
3718 | - $_deferred[$taxonomy] = array(); |
|
3807 | + if ( !isset($_deferred[$taxonomy]) ) { |
|
3808 | + $_deferred[$taxonomy] = array(); |
|
3809 | + } |
|
3719 | 3810 | $_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) ); |
3720 | 3811 | return true; |
3721 | 3812 | } |
@@ -3741,8 +3832,9 @@ discard block |
||
3741 | 3832 | } else { |
3742 | 3833 | $object_types = (array) $taxonomy->object_type; |
3743 | 3834 | foreach ( $object_types as &$object_type ) { |
3744 | - if ( 0 === strpos( $object_type, 'attachment:' ) ) |
|
3745 | - list( $object_type ) = explode( ':', $object_type ); |
|
3835 | + if ( 0 === strpos( $object_type, 'attachment:' ) ) { |
|
3836 | + list( $object_type ) = explode( ':', $object_type ); |
|
3837 | + } |
|
3746 | 3838 | } |
3747 | 3839 | |
3748 | 3840 | if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) { |
@@ -3778,8 +3870,9 @@ discard block |
||
3778 | 3870 | * @param array|string $object_type The taxonomy object type. |
3779 | 3871 | */ |
3780 | 3872 | function clean_object_term_cache($object_ids, $object_type) { |
3781 | - if ( !is_array($object_ids) ) |
|
3782 | - $object_ids = array($object_ids); |
|
3873 | + if ( !is_array($object_ids) ) { |
|
3874 | + $object_ids = array($object_ids); |
|
3875 | + } |
|
3783 | 3876 | |
3784 | 3877 | $taxonomies = get_object_taxonomies( $object_type ); |
3785 | 3878 | |
@@ -3821,8 +3914,9 @@ discard block |
||
3821 | 3914 | return; |
3822 | 3915 | } |
3823 | 3916 | |
3824 | - if ( !is_array($ids) ) |
|
3825 | - $ids = array($ids); |
|
3917 | + if ( !is_array($ids) ) { |
|
3918 | + $ids = array($ids); |
|
3919 | + } |
|
3826 | 3920 | |
3827 | 3921 | $taxonomies = array(); |
3828 | 3922 | // If no taxonomy, assume tt_ids. |
@@ -3900,11 +3994,13 @@ discard block |
||
3900 | 3994 | * @return void|false False if all of the terms in `$object_ids` are already cached. |
3901 | 3995 | */ |
3902 | 3996 | function update_object_term_cache($object_ids, $object_type) { |
3903 | - if ( empty($object_ids) ) |
|
3904 | - return; |
|
3997 | + if ( empty($object_ids) ) { |
|
3998 | + return; |
|
3999 | + } |
|
3905 | 4000 | |
3906 | - if ( !is_array($object_ids) ) |
|
3907 | - $object_ids = explode(',', $object_ids); |
|
4001 | + if ( !is_array($object_ids) ) { |
|
4002 | + $object_ids = explode(',', $object_ids); |
|
4003 | + } |
|
3908 | 4004 | |
3909 | 4005 | $object_ids = array_map('intval', $object_ids); |
3910 | 4006 | |
@@ -3920,20 +4016,23 @@ discard block |
||
3920 | 4016 | } |
3921 | 4017 | } |
3922 | 4018 | |
3923 | - if ( empty( $ids ) ) |
|
3924 | - return false; |
|
4019 | + if ( empty( $ids ) ) { |
|
4020 | + return false; |
|
4021 | + } |
|
3925 | 4022 | |
3926 | 4023 | $terms = wp_get_object_terms($ids, $taxonomies, array('fields' => 'all_with_object_id')); |
3927 | 4024 | |
3928 | 4025 | $object_terms = array(); |
3929 | - foreach ( (array) $terms as $term ) |
|
3930 | - $object_terms[$term->object_id][$term->taxonomy][] = $term; |
|
4026 | + foreach ( (array) $terms as $term ) { |
|
4027 | + $object_terms[$term->object_id][$term->taxonomy][] = $term; |
|
4028 | + } |
|
3931 | 4029 | |
3932 | 4030 | foreach ( $ids as $id ) { |
3933 | 4031 | foreach ( $taxonomies as $taxonomy ) { |
3934 | 4032 | if ( ! isset($object_terms[$id][$taxonomy]) ) { |
3935 | - if ( !isset($object_terms[$id]) ) |
|
3936 | - $object_terms[$id] = array(); |
|
4033 | + if ( !isset($object_terms[$id]) ) { |
|
4034 | + $object_terms[$id] = array(); |
|
4035 | + } |
|
3937 | 4036 | $object_terms[$id][$taxonomy] = array(); |
3938 | 4037 | } |
3939 | 4038 | } |
@@ -3957,8 +4056,9 @@ discard block |
||
3957 | 4056 | function update_term_cache( $terms, $taxonomy = '' ) { |
3958 | 4057 | foreach ( (array) $terms as $term ) { |
3959 | 4058 | $term_taxonomy = $taxonomy; |
3960 | - if ( empty($term_taxonomy) ) |
|
3961 | - $term_taxonomy = $term->taxonomy; |
|
4059 | + if ( empty($term_taxonomy) ) { |
|
4060 | + $term_taxonomy = $term->taxonomy; |
|
4061 | + } |
|
3962 | 4062 | |
3963 | 4063 | wp_cache_add( $term->term_id, $term, $term_taxonomy ); |
3964 | 4064 | } |
@@ -3978,17 +4078,20 @@ discard block |
||
3978 | 4078 | * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs. |
3979 | 4079 | */ |
3980 | 4080 | function _get_term_hierarchy( $taxonomy ) { |
3981 | - if ( !is_taxonomy_hierarchical($taxonomy) ) |
|
3982 | - return array(); |
|
4081 | + if ( !is_taxonomy_hierarchical($taxonomy) ) { |
|
4082 | + return array(); |
|
4083 | + } |
|
3983 | 4084 | $children = get_option("{$taxonomy}_children"); |
3984 | 4085 | |
3985 | - if ( is_array($children) ) |
|
3986 | - return $children; |
|
4086 | + if ( is_array($children) ) { |
|
4087 | + return $children; |
|
4088 | + } |
|
3987 | 4089 | $children = array(); |
3988 | 4090 | $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent')); |
3989 | 4091 | foreach ( $terms as $term_id => $parent ) { |
3990 | - if ( $parent > 0 ) |
|
3991 | - $children[$parent][] = $term_id; |
|
4092 | + if ( $parent > 0 ) { |
|
4093 | + $children[$parent][] = $term_id; |
|
4094 | + } |
|
3992 | 4095 | } |
3993 | 4096 | update_option("{$taxonomy}_children", $children); |
3994 | 4097 | |
@@ -4016,14 +4119,16 @@ discard block |
||
4016 | 4119 | */ |
4017 | 4120 | function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() ) { |
4018 | 4121 | $empty_array = array(); |
4019 | - if ( empty($terms) ) |
|
4020 | - return $empty_array; |
|
4122 | + if ( empty($terms) ) { |
|
4123 | + return $empty_array; |
|
4124 | + } |
|
4021 | 4125 | |
4022 | 4126 | $term_list = array(); |
4023 | 4127 | $has_children = _get_term_hierarchy($taxonomy); |
4024 | 4128 | |
4025 | - if ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) ) |
|
4026 | - return $empty_array; |
|
4129 | + if ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) ) { |
|
4130 | + return $empty_array; |
|
4131 | + } |
|
4027 | 4132 | |
4028 | 4133 | // Include the term itself in the ancestors array, so we can properly detect when a loop has occurred. |
4029 | 4134 | if ( empty( $ancestors ) ) { |
@@ -4034,8 +4139,9 @@ discard block |
||
4034 | 4139 | $use_id = false; |
4035 | 4140 | if ( !is_object($term) ) { |
4036 | 4141 | $term = get_term($term, $taxonomy); |
4037 | - if ( is_wp_error( $term ) ) |
|
4038 | - return $term; |
|
4142 | + if ( is_wp_error( $term ) ) { |
|
4143 | + return $term; |
|
4144 | + } |
|
4039 | 4145 | $use_id = true; |
4040 | 4146 | } |
4041 | 4147 | |
@@ -4045,18 +4151,21 @@ discard block |
||
4045 | 4151 | } |
4046 | 4152 | |
4047 | 4153 | if ( $term->parent == $term_id ) { |
4048 | - if ( $use_id ) |
|
4049 | - $term_list[] = $term->term_id; |
|
4050 | - else |
|
4051 | - $term_list[] = $term; |
|
4154 | + if ( $use_id ) { |
|
4155 | + $term_list[] = $term->term_id; |
|
4156 | + } else { |
|
4157 | + $term_list[] = $term; |
|
4158 | + } |
|
4052 | 4159 | |
4053 | - if ( !isset($has_children[$term->term_id]) ) |
|
4054 | - continue; |
|
4160 | + if ( !isset($has_children[$term->term_id]) ) { |
|
4161 | + continue; |
|
4162 | + } |
|
4055 | 4163 | |
4056 | 4164 | $ancestors[ $term->term_id ] = 1; |
4057 | 4165 | |
4058 | - if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors) ) |
|
4059 | - $term_list = array_merge($term_list, $children); |
|
4166 | + if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors) ) { |
|
4167 | + $term_list = array_merge($term_list, $children); |
|
4168 | + } |
|
4060 | 4169 | } |
4061 | 4170 | } |
4062 | 4171 | |
@@ -4081,13 +4190,15 @@ discard block |
||
4081 | 4190 | global $wpdb; |
4082 | 4191 | |
4083 | 4192 | // This function only works for hierarchical taxonomies like post categories. |
4084 | - if ( !is_taxonomy_hierarchical( $taxonomy ) ) |
|
4085 | - return; |
|
4193 | + if ( !is_taxonomy_hierarchical( $taxonomy ) ) { |
|
4194 | + return; |
|
4195 | + } |
|
4086 | 4196 | |
4087 | 4197 | $term_hier = _get_term_hierarchy($taxonomy); |
4088 | 4198 | |
4089 | - if ( empty($term_hier) ) |
|
4090 | - return; |
|
4199 | + if ( empty($term_hier) ) { |
|
4200 | + return; |
|
4201 | + } |
|
4091 | 4202 | |
4092 | 4203 | $term_items = array(); |
4093 | 4204 | $terms_by_id = array(); |
@@ -4113,9 +4224,10 @@ discard block |
||
4113 | 4224 | $ancestors = array(); |
4114 | 4225 | while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) { |
4115 | 4226 | $ancestors[] = $child; |
4116 | - if ( !empty( $term_items[$term_id] ) ) |
|
4117 | - foreach ( $term_items[$term_id] as $item_id => $touches ) { |
|
4227 | + if ( !empty( $term_items[$term_id] ) ) { |
|
4228 | + foreach ( $term_items[$term_id] as $item_id => $touches ) { |
|
4118 | 4229 | $term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id]: 1; |
4230 | + } |
|
4119 | 4231 | } |
4120 | 4232 | $child = $parent; |
4121 | 4233 | |
@@ -4126,10 +4238,11 @@ discard block |
||
4126 | 4238 | } |
4127 | 4239 | |
4128 | 4240 | // Transfer the touched cells. |
4129 | - foreach ( (array) $term_items as $id => $items ) |
|
4130 | - if ( isset($terms_by_id[$id]) ) |
|
4241 | + foreach ( (array) $term_items as $id => $items ) { |
|
4242 | + if ( isset($terms_by_id[$id]) ) |
|
4131 | 4243 | $terms_by_id[$id]->count = count($items); |
4132 | -} |
|
4244 | + } |
|
4245 | + } |
|
4133 | 4246 | |
4134 | 4247 | // |
4135 | 4248 | // Default callbacks |
@@ -4154,8 +4267,9 @@ discard block |
||
4154 | 4267 | |
4155 | 4268 | $object_types = (array) $taxonomy->object_type; |
4156 | 4269 | |
4157 | - foreach ( $object_types as &$object_type ) |
|
4158 | - list( $object_type ) = explode( ':', $object_type ); |
|
4270 | + foreach ( $object_types as &$object_type ) { |
|
4271 | + list( $object_type ) = explode( ':', $object_type ); |
|
4272 | + } |
|
4159 | 4273 | |
4160 | 4274 | $object_types = array_unique( $object_types ); |
4161 | 4275 | |
@@ -4164,18 +4278,21 @@ discard block |
||
4164 | 4278 | $check_attachments = true; |
4165 | 4279 | } |
4166 | 4280 | |
4167 | - if ( $object_types ) |
|
4168 | - $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) ); |
|
4281 | + if ( $object_types ) { |
|
4282 | + $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) ); |
|
4283 | + } |
|
4169 | 4284 | |
4170 | 4285 | foreach ( (array) $terms as $term ) { |
4171 | 4286 | $count = 0; |
4172 | 4287 | |
4173 | 4288 | // Attachments can be 'inherit' status, we need to base count off the parent's status if so. |
4174 | - if ( $check_attachments ) |
|
4175 | - $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) ); |
|
4289 | + if ( $check_attachments ) { |
|
4290 | + $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) ); |
|
4291 | + } |
|
4176 | 4292 | |
4177 | - if ( $object_types ) |
|
4178 | - $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) ); |
|
4293 | + if ( $object_types ) { |
|
4294 | + $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) ); |
|
4295 | + } |
|
4179 | 4296 | |
4180 | 4297 | /** This action is documented in wp-includes/taxonomy.php */ |
4181 | 4298 | do_action( 'edit_term_taxonomy', $term, $taxonomy->name ); |
@@ -4597,11 +4714,13 @@ discard block |
||
4597 | 4714 | } |
4598 | 4715 | } |
4599 | 4716 | |
4600 | - if ( !is_object($term) ) |
|
4601 | - $term = new WP_Error('invalid_term', __('Empty Term')); |
|
4717 | + if ( !is_object($term) ) { |
|
4718 | + $term = new WP_Error('invalid_term', __('Empty Term')); |
|
4719 | + } |
|
4602 | 4720 | |
4603 | - if ( is_wp_error( $term ) ) |
|
4604 | - return $term; |
|
4721 | + if ( is_wp_error( $term ) ) { |
|
4722 | + return $term; |
|
4723 | + } |
|
4605 | 4724 | |
4606 | 4725 | $taxonomy = $term->taxonomy; |
4607 | 4726 | |
@@ -4611,12 +4730,13 @@ discard block |
||
4611 | 4730 | $t = get_taxonomy($taxonomy); |
4612 | 4731 | |
4613 | 4732 | if ( empty($termlink) ) { |
4614 | - if ( 'category' == $taxonomy ) |
|
4615 | - $termlink = '?cat=' . $term->term_id; |
|
4616 | - elseif ( $t->query_var ) |
|
4617 | - $termlink = "?$t->query_var=$slug"; |
|
4618 | - else |
|
4619 | - $termlink = "?taxonomy=$taxonomy&term=$slug"; |
|
4733 | + if ( 'category' == $taxonomy ) { |
|
4734 | + $termlink = '?cat=' . $term->term_id; |
|
4735 | + } elseif ( $t->query_var ) { |
|
4736 | + $termlink = "?$t->query_var=$slug"; |
|
4737 | + } else { |
|
4738 | + $termlink = "?taxonomy=$taxonomy&term=$slug"; |
|
4739 | + } |
|
4620 | 4740 | $termlink = home_url($termlink); |
4621 | 4741 | } else { |
4622 | 4742 | if ( $t->rewrite['hierarchical'] ) { |
@@ -4800,26 +4920,32 @@ discard block |
||
4800 | 4920 | * @return bool|WP_Error WP_Error on input error. |
4801 | 4921 | */ |
4802 | 4922 | function is_object_in_term( $object_id, $taxonomy, $terms = null ) { |
4803 | - if ( !$object_id = (int) $object_id ) |
|
4804 | - return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) ); |
|
4923 | + if ( !$object_id = (int) $object_id ) { |
|
4924 | + return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) ); |
|
4925 | + } |
|
4805 | 4926 | |
4806 | 4927 | $object_terms = get_object_term_cache( $object_id, $taxonomy ); |
4807 | - if ( false === $object_terms ) |
|
4808 | - $object_terms = wp_get_object_terms( $object_id, $taxonomy ); |
|
4928 | + if ( false === $object_terms ) { |
|
4929 | + $object_terms = wp_get_object_terms( $object_id, $taxonomy ); |
|
4930 | + } |
|
4809 | 4931 | |
4810 | - if ( is_wp_error( $object_terms ) ) |
|
4811 | - return $object_terms; |
|
4812 | - if ( empty( $object_terms ) ) |
|
4813 | - return false; |
|
4814 | - if ( empty( $terms ) ) |
|
4815 | - return ( !empty( $object_terms ) ); |
|
4932 | + if ( is_wp_error( $object_terms ) ) { |
|
4933 | + return $object_terms; |
|
4934 | + } |
|
4935 | + if ( empty( $object_terms ) ) { |
|
4936 | + return false; |
|
4937 | + } |
|
4938 | + if ( empty( $terms ) ) { |
|
4939 | + return ( !empty( $object_terms ) ); |
|
4940 | + } |
|
4816 | 4941 | |
4817 | 4942 | $terms = (array) $terms; |
4818 | 4943 | |
4819 | - if ( $ints = array_filter( $terms, 'is_int' ) ) |
|
4820 | - $strs = array_diff( $terms, $ints ); |
|
4821 | - else |
|
4822 | - $strs =& $terms; |
|
4944 | + if ( $ints = array_filter( $terms, 'is_int' ) ) { |
|
4945 | + $strs = array_diff( $terms, $ints ); |
|
4946 | + } else { |
|
4947 | + $strs =& $terms; |
|
4948 | + } |
|
4823 | 4949 | |
4824 | 4950 | foreach ( $object_terms as $object_term ) { |
4825 | 4951 | // If term is an int, check against term_ids only. |
@@ -4834,8 +4960,12 @@ discard block |
||
4834 | 4960 | return true; |
4835 | 4961 | } |
4836 | 4962 | |
4837 | - if ( in_array( $object_term->name, $strs ) ) return true; |
|
4838 | - if ( in_array( $object_term->slug, $strs ) ) return true; |
|
4963 | + if ( in_array( $object_term->name, $strs ) ) { |
|
4964 | + return true; |
|
4965 | + } |
|
4966 | + if ( in_array( $object_term->slug, $strs ) ) { |
|
4967 | + return true; |
|
4968 | + } |
|
4839 | 4969 | } |
4840 | 4970 | } |
4841 | 4971 | |
@@ -4948,24 +5078,30 @@ discard block |
||
4948 | 5078 | */ |
4949 | 5079 | function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) { |
4950 | 5080 | // Nothing fancy here - bail |
4951 | - if ( !$parent ) |
|
4952 | - return 0; |
|
5081 | + if ( !$parent ) { |
|
5082 | + return 0; |
|
5083 | + } |
|
4953 | 5084 | |
4954 | 5085 | // Can't be its own parent. |
4955 | - if ( $parent == $term_id ) |
|
4956 | - return 0; |
|
5086 | + if ( $parent == $term_id ) { |
|
5087 | + return 0; |
|
5088 | + } |
|
4957 | 5089 | |
4958 | 5090 | // Now look for larger loops. |
4959 | - if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) ) |
|
4960 | - return $parent; // No loop |
|
5091 | + if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) ) { |
|
5092 | + return $parent; |
|
5093 | + } |
|
5094 | + // No loop |
|
4961 | 5095 | |
4962 | 5096 | // Setting $parent to the given value causes a loop. |
4963 | - if ( isset( $loop[$term_id] ) ) |
|
4964 | - return 0; |
|
5097 | + if ( isset( $loop[$term_id] ) ) { |
|
5098 | + return 0; |
|
5099 | + } |
|
4965 | 5100 | |
4966 | 5101 | // There's a loop, but it doesn't contain $term_id. Break the loop. |
4967 | - foreach ( array_keys( $loop ) as $loop_member ) |
|
4968 | - wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) ); |
|
5102 | + foreach ( array_keys( $loop ) as $loop_member ) { |
|
5103 | + wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) ); |
|
5104 | + } |
|
4969 | 5105 | |
4970 | 5106 | return $parent; |
4971 | 5107 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | * @since 1.5.0 |
18 | 18 | * |
19 | 19 | * @param string $type Filename without extension. |
20 | - * @param array $templates An optional list of template candidates |
|
20 | + * @param string[] $templates An optional list of template candidates |
|
21 | 21 | * @return string Full path to template file. |
22 | 22 | */ |
23 | 23 | function get_query_template( $type, $templates = array() ) { |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Template loading functions. |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Template |
|
7 | - */ |
|
3 | + * Template loading functions. |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Template |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Retrieve path to a template |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | * @param array $templates An optional list of template candidates |
21 | 21 | * @return string Full path to template file. |
22 | 22 | */ |
23 | -function get_query_template( $type, $templates = array() ) { |
|
24 | - $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); |
|
23 | +function get_query_template($type, $templates = array()) { |
|
24 | + $type = preg_replace('|[^a-z0-9-]+|', '', $type); |
|
25 | 25 | |
26 | - if ( empty( $templates ) ) |
|
26 | + if (empty($templates)) |
|
27 | 27 | $templates = array("{$type}.php"); |
28 | 28 | |
29 | - $template = locate_template( $templates ); |
|
29 | + $template = locate_template($templates); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Filter the path of the queried template by type. |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @param string $template Path to the template. See locate_template(). |
41 | 41 | */ |
42 | - return apply_filters( "{$type}_template", $template ); |
|
42 | + return apply_filters("{$type}_template", $template); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -87,17 +87,17 @@ discard block |
||
87 | 87 | * @return string Full path to archive template file. |
88 | 88 | */ |
89 | 89 | function get_archive_template() { |
90 | - $post_types = array_filter( (array) get_query_var( 'post_type' ) ); |
|
90 | + $post_types = array_filter((array) get_query_var('post_type')); |
|
91 | 91 | |
92 | 92 | $templates = array(); |
93 | 93 | |
94 | - if ( count( $post_types ) == 1 ) { |
|
95 | - $post_type = reset( $post_types ); |
|
94 | + if (count($post_types) == 1) { |
|
95 | + $post_type = reset($post_types); |
|
96 | 96 | $templates[] = "archive-{$post_type}.php"; |
97 | 97 | } |
98 | 98 | $templates[] = 'archive.php'; |
99 | 99 | |
100 | - return get_query_template( 'archive', $templates ); |
|
100 | + return get_query_template('archive', $templates); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | * @return string Full path to archive template file. |
114 | 114 | */ |
115 | 115 | function get_post_type_archive_template() { |
116 | - $post_type = get_query_var( 'post_type' ); |
|
117 | - if ( is_array( $post_type ) ) |
|
118 | - $post_type = reset( $post_type ); |
|
116 | + $post_type = get_query_var('post_type'); |
|
117 | + if (is_array($post_type)) |
|
118 | + $post_type = reset($post_type); |
|
119 | 119 | |
120 | - $obj = get_post_type_object( $post_type ); |
|
121 | - if ( ! $obj->has_archive ) |
|
120 | + $obj = get_post_type_object($post_type); |
|
121 | + if ( ! $obj->has_archive) |
|
122 | 122 | return ''; |
123 | 123 | |
124 | 124 | return get_archive_template(); |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | |
142 | 142 | $templates = array(); |
143 | 143 | |
144 | - if ( $author instanceof WP_User ) { |
|
144 | + if ($author instanceof WP_User) { |
|
145 | 145 | $templates[] = "author-{$author->user_nicename}.php"; |
146 | 146 | $templates[] = "author-{$author->ID}.php"; |
147 | 147 | } |
148 | 148 | $templates[] = 'author.php'; |
149 | 149 | |
150 | - return get_query_template( 'author', $templates ); |
|
150 | + return get_query_template('author', $templates); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | |
172 | 172 | $templates = array(); |
173 | 173 | |
174 | - if ( ! empty( $category->slug ) ) { |
|
174 | + if ( ! empty($category->slug)) { |
|
175 | 175 | $templates[] = "category-{$category->slug}.php"; |
176 | 176 | $templates[] = "category-{$category->term_id}.php"; |
177 | 177 | } |
178 | 178 | $templates[] = 'category.php'; |
179 | 179 | |
180 | - return get_query_template( 'category', $templates ); |
|
180 | + return get_query_template('category', $templates); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | |
202 | 202 | $templates = array(); |
203 | 203 | |
204 | - if ( ! empty( $tag->slug ) ) { |
|
204 | + if ( ! empty($tag->slug)) { |
|
205 | 205 | $templates[] = "tag-{$tag->slug}.php"; |
206 | 206 | $templates[] = "tag-{$tag->term_id}.php"; |
207 | 207 | } |
208 | 208 | $templates[] = 'tag.php'; |
209 | 209 | |
210 | - return get_query_template( 'tag', $templates ); |
|
210 | + return get_query_template('tag', $templates); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -236,14 +236,14 @@ discard block |
||
236 | 236 | |
237 | 237 | $templates = array(); |
238 | 238 | |
239 | - if ( ! empty( $term->slug ) ) { |
|
239 | + if ( ! empty($term->slug)) { |
|
240 | 240 | $taxonomy = $term->taxonomy; |
241 | 241 | $templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; |
242 | 242 | $templates[] = "taxonomy-$taxonomy.php"; |
243 | 243 | } |
244 | 244 | $templates[] = 'taxonomy.php'; |
245 | 245 | |
246 | - return get_query_template( 'taxonomy', $templates ); |
|
246 | + return get_query_template('taxonomy', $templates); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | * @return string Full path to home template file. |
279 | 279 | */ |
280 | 280 | function get_home_template() { |
281 | - $templates = array( 'home.php', 'index.php' ); |
|
281 | + $templates = array('home.php', 'index.php'); |
|
282 | 282 | |
283 | - return get_query_template( 'home', $templates ); |
|
283 | + return get_query_template('home', $templates); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | function get_front_page_template() { |
299 | 299 | $templates = array('front-page.php'); |
300 | 300 | |
301 | - return get_query_template( 'front_page', $templates ); |
|
301 | + return get_query_template('front_page', $templates); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -322,23 +322,23 @@ discard block |
||
322 | 322 | $template = get_page_template_slug(); |
323 | 323 | $pagename = get_query_var('pagename'); |
324 | 324 | |
325 | - if ( ! $pagename && $id ) { |
|
325 | + if ( ! $pagename && $id) { |
|
326 | 326 | // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object |
327 | 327 | $post = get_queried_object(); |
328 | - if ( $post ) |
|
328 | + if ($post) |
|
329 | 329 | $pagename = $post->post_name; |
330 | 330 | } |
331 | 331 | |
332 | 332 | $templates = array(); |
333 | - if ( $template && 0 === validate_file( $template ) ) |
|
333 | + if ($template && 0 === validate_file($template)) |
|
334 | 334 | $templates[] = $template; |
335 | - if ( $pagename ) |
|
335 | + if ($pagename) |
|
336 | 336 | $templates[] = "page-$pagename.php"; |
337 | - if ( $id ) |
|
337 | + if ($id) |
|
338 | 338 | $templates[] = "page-$id.php"; |
339 | 339 | $templates[] = 'page.php'; |
340 | 340 | |
341 | - return get_query_template( 'page', $templates ); |
|
341 | + return get_query_template('page', $templates); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -390,11 +390,11 @@ discard block |
||
390 | 390 | |
391 | 391 | $templates = array(); |
392 | 392 | |
393 | - if ( ! empty( $object->post_type ) ) |
|
393 | + if ( ! empty($object->post_type)) |
|
394 | 394 | $templates[] = "single-{$object->post_type}.php"; |
395 | 395 | $templates[] = "single.php"; |
396 | 396 | |
397 | - return get_query_template( 'single', $templates ); |
|
397 | + return get_query_template('single', $templates); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @return string Full path to singular template file |
411 | 411 | */ |
412 | 412 | function get_singular_template() { |
413 | - return get_query_template( 'singular' ); |
|
413 | + return get_query_template('singular'); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -440,14 +440,14 @@ discard block |
||
440 | 440 | |
441 | 441 | $templates = array(); |
442 | 442 | |
443 | - if ( $attachment ) { |
|
444 | - if ( false !== strpos( $attachment->post_mime_type, '/' ) ) { |
|
445 | - list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); |
|
443 | + if ($attachment) { |
|
444 | + if (false !== strpos($attachment->post_mime_type, '/')) { |
|
445 | + list($type, $subtype) = explode('/', $attachment->post_mime_type); |
|
446 | 446 | } else { |
447 | - list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); |
|
447 | + list($type, $subtype) = array($attachment->post_mime_type, ''); |
|
448 | 448 | } |
449 | 449 | |
450 | - if ( ! empty( $subtype ) ) { |
|
450 | + if ( ! empty($subtype)) { |
|
451 | 451 | $templates[] = "{$type}-{$subtype}.php"; |
452 | 452 | $templates[] = "{$subtype}.php"; |
453 | 453 | } |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | } |
456 | 456 | $templates[] = 'attachment.php'; |
457 | 457 | |
458 | - return get_query_template( 'attachment', $templates ); |
|
458 | + return get_query_template('attachment', $templates); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -474,11 +474,11 @@ discard block |
||
474 | 474 | * @return string Full path to comments popup template file. |
475 | 475 | */ |
476 | 476 | function get_comments_popup_template() { |
477 | - $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) ); |
|
477 | + $template = get_query_template('comments_popup', array('comments-popup.php')); |
|
478 | 478 | |
479 | 479 | // Backward compat code will be removed in a future release. |
480 | 480 | if ('' == $template) |
481 | - $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; |
|
481 | + $template = ABSPATH.WPINC.'/theme-compat/comments-popup.php'; |
|
482 | 482 | |
483 | 483 | return $template; |
484 | 484 | } |
@@ -496,22 +496,22 @@ discard block |
||
496 | 496 | * @param bool $require_once Whether to require_once or require. Default true. Has no effect if $load is false. |
497 | 497 | * @return string The template filename if one is located. |
498 | 498 | */ |
499 | -function locate_template($template_names, $load = false, $require_once = true ) { |
|
499 | +function locate_template($template_names, $load = false, $require_once = true) { |
|
500 | 500 | $located = ''; |
501 | - foreach ( (array) $template_names as $template_name ) { |
|
502 | - if ( !$template_name ) |
|
501 | + foreach ((array) $template_names as $template_name) { |
|
502 | + if ( ! $template_name) |
|
503 | 503 | continue; |
504 | - if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { |
|
505 | - $located = STYLESHEETPATH . '/' . $template_name; |
|
504 | + if (file_exists(STYLESHEETPATH.'/'.$template_name)) { |
|
505 | + $located = STYLESHEETPATH.'/'.$template_name; |
|
506 | 506 | break; |
507 | - } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { |
|
508 | - $located = TEMPLATEPATH . '/' . $template_name; |
|
507 | + } elseif (file_exists(TEMPLATEPATH.'/'.$template_name)) { |
|
508 | + $located = TEMPLATEPATH.'/'.$template_name; |
|
509 | 509 | break; |
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
513 | - if ( $load && '' != $located ) |
|
514 | - load_template( $located, $require_once ); |
|
513 | + if ($load && '' != $located) |
|
514 | + load_template($located, $require_once); |
|
515 | 515 | |
516 | 516 | return $located; |
517 | 517 | } |
@@ -540,21 +540,21 @@ discard block |
||
540 | 540 | * @param string $_template_file Path to template file. |
541 | 541 | * @param bool $require_once Whether to require_once or require. Default true. |
542 | 542 | */ |
543 | -function load_template( $_template_file, $require_once = true ) { |
|
543 | +function load_template($_template_file, $require_once = true) { |
|
544 | 544 | global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; |
545 | 545 | |
546 | - if ( is_array( $wp_query->query_vars ) ) { |
|
547 | - extract( $wp_query->query_vars, EXTR_SKIP ); |
|
546 | + if (is_array($wp_query->query_vars)) { |
|
547 | + extract($wp_query->query_vars, EXTR_SKIP); |
|
548 | 548 | } |
549 | 549 | |
550 | - if ( isset( $s ) ) { |
|
551 | - $s = esc_attr( $s ); |
|
550 | + if (isset($s)) { |
|
551 | + $s = esc_attr($s); |
|
552 | 552 | } |
553 | 553 | |
554 | - if ( $require_once ) { |
|
555 | - require_once( $_template_file ); |
|
554 | + if ($require_once) { |
|
555 | + require_once($_template_file); |
|
556 | 556 | } else { |
557 | - require( $_template_file ); |
|
557 | + require($_template_file); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 |
@@ -23,8 +23,9 @@ discard block |
||
23 | 23 | function get_query_template( $type, $templates = array() ) { |
24 | 24 | $type = preg_replace( '|[^a-z0-9-]+|', '', $type ); |
25 | 25 | |
26 | - if ( empty( $templates ) ) |
|
27 | - $templates = array("{$type}.php"); |
|
26 | + if ( empty( $templates ) ) { |
|
27 | + $templates = array("{$type}.php"); |
|
28 | + } |
|
28 | 29 | |
29 | 30 | $template = locate_template( $templates ); |
30 | 31 | |
@@ -114,12 +115,14 @@ discard block |
||
114 | 115 | */ |
115 | 116 | function get_post_type_archive_template() { |
116 | 117 | $post_type = get_query_var( 'post_type' ); |
117 | - if ( is_array( $post_type ) ) |
|
118 | - $post_type = reset( $post_type ); |
|
118 | + if ( is_array( $post_type ) ) { |
|
119 | + $post_type = reset( $post_type ); |
|
120 | + } |
|
119 | 121 | |
120 | 122 | $obj = get_post_type_object( $post_type ); |
121 | - if ( ! $obj->has_archive ) |
|
122 | - return ''; |
|
123 | + if ( ! $obj->has_archive ) { |
|
124 | + return ''; |
|
125 | + } |
|
123 | 126 | |
124 | 127 | return get_archive_template(); |
125 | 128 | } |
@@ -325,17 +328,21 @@ discard block |
||
325 | 328 | if ( ! $pagename && $id ) { |
326 | 329 | // If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object |
327 | 330 | $post = get_queried_object(); |
328 | - if ( $post ) |
|
329 | - $pagename = $post->post_name; |
|
331 | + if ( $post ) { |
|
332 | + $pagename = $post->post_name; |
|
333 | + } |
|
330 | 334 | } |
331 | 335 | |
332 | 336 | $templates = array(); |
333 | - if ( $template && 0 === validate_file( $template ) ) |
|
334 | - $templates[] = $template; |
|
335 | - if ( $pagename ) |
|
336 | - $templates[] = "page-$pagename.php"; |
|
337 | - if ( $id ) |
|
338 | - $templates[] = "page-$id.php"; |
|
337 | + if ( $template && 0 === validate_file( $template ) ) { |
|
338 | + $templates[] = $template; |
|
339 | + } |
|
340 | + if ( $pagename ) { |
|
341 | + $templates[] = "page-$pagename.php"; |
|
342 | + } |
|
343 | + if ( $id ) { |
|
344 | + $templates[] = "page-$id.php"; |
|
345 | + } |
|
339 | 346 | $templates[] = 'page.php'; |
340 | 347 | |
341 | 348 | return get_query_template( 'page', $templates ); |
@@ -390,8 +397,9 @@ discard block |
||
390 | 397 | |
391 | 398 | $templates = array(); |
392 | 399 | |
393 | - if ( ! empty( $object->post_type ) ) |
|
394 | - $templates[] = "single-{$object->post_type}.php"; |
|
400 | + if ( ! empty( $object->post_type ) ) { |
|
401 | + $templates[] = "single-{$object->post_type}.php"; |
|
402 | + } |
|
395 | 403 | $templates[] = "single.php"; |
396 | 404 | |
397 | 405 | return get_query_template( 'single', $templates ); |
@@ -477,8 +485,9 @@ discard block |
||
477 | 485 | $template = get_query_template( 'comments_popup', array( 'comments-popup.php' ) ); |
478 | 486 | |
479 | 487 | // Backward compat code will be removed in a future release. |
480 | - if ('' == $template) |
|
481 | - $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; |
|
488 | + if ('' == $template) { |
|
489 | + $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; |
|
490 | + } |
|
482 | 491 | |
483 | 492 | return $template; |
484 | 493 | } |
@@ -499,8 +508,9 @@ discard block |
||
499 | 508 | function locate_template($template_names, $load = false, $require_once = true ) { |
500 | 509 | $located = ''; |
501 | 510 | foreach ( (array) $template_names as $template_name ) { |
502 | - if ( !$template_name ) |
|
503 | - continue; |
|
511 | + if ( !$template_name ) { |
|
512 | + continue; |
|
513 | + } |
|
504 | 514 | if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { |
505 | 515 | $located = STYLESHEETPATH . '/' . $template_name; |
506 | 516 | break; |
@@ -510,8 +520,9 @@ discard block |
||
510 | 520 | } |
511 | 521 | } |
512 | 522 | |
513 | - if ( $load && '' != $located ) |
|
514 | - load_template( $located, $require_once ); |
|
523 | + if ( $load && '' != $located ) { |
|
524 | + load_template( $located, $require_once ); |
|
525 | + } |
|
515 | 526 | |
516 | 527 | return $located; |
517 | 528 | } |
@@ -145,6 +145,7 @@ discard block |
||
145 | 145 | * the two files do not match, and likewise that the last lines do not |
146 | 146 | * match. The caller must trim matching lines from the beginning and end |
147 | 147 | * of the portions it is going to specify. |
148 | + * @param double $nchunks |
|
148 | 149 | */ |
149 | 150 | function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) |
150 | 151 | { |
@@ -265,6 +266,10 @@ discard block |
||
265 | 266 | * |
266 | 267 | * Note that XLIM, YLIM are exclusive bounds. All line numbers are |
267 | 268 | * origin-0 and discarded lines are not counted. |
269 | + * @param integer $xoff |
|
270 | + * @param integer $xlim |
|
271 | + * @param integer $yoff |
|
272 | + * @param integer $ylim |
|
268 | 273 | */ |
269 | 274 | function _compareseq ($xoff, $xlim, $yoff, $ylim) |
270 | 275 | { |
@@ -1,341 +1,341 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Class used internally by Text_Diff to actually compute the diffs. |
|
4 | - * |
|
5 | - * This class is implemented using native PHP code. |
|
6 | - * |
|
7 | - * The algorithm used here is mostly lifted from the perl module |
|
8 | - * Algorithm::Diff (version 1.06) by Ned Konz, which is available at: |
|
9 | - * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip |
|
10 | - * |
|
11 | - * More ideas are taken from: http://www.ics.uci.edu/~eppstein/161/960229.html |
|
12 | - * |
|
13 | - * Some ideas (and a bit of code) are taken from analyze.c, of GNU |
|
14 | - * diffutils-2.7, which can be found at: |
|
15 | - * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz |
|
16 | - * |
|
17 | - * Some ideas (subdivision by NCHUNKS > 2, and some optimizations) are from |
|
18 | - * Geoffrey T. Dairiki <[email protected]>. The original PHP version of this |
|
19 | - * code was written by him, and is used/adapted with his permission. |
|
20 | - * |
|
21 | - * Copyright 2004-2010 The Horde Project (http://www.horde.org/) |
|
22 | - * |
|
23 | - * See the enclosed file COPYING for license information (LGPL). If you did |
|
24 | - * not receive this file, see http://opensource.org/licenses/lgpl-license.php. |
|
25 | - * |
|
26 | - * @author Geoffrey T. Dairiki <[email protected]> |
|
27 | - * @package Text_Diff |
|
28 | - */ |
|
3 | + * Class used internally by Text_Diff to actually compute the diffs. |
|
4 | + * |
|
5 | + * This class is implemented using native PHP code. |
|
6 | + * |
|
7 | + * The algorithm used here is mostly lifted from the perl module |
|
8 | + * Algorithm::Diff (version 1.06) by Ned Konz, which is available at: |
|
9 | + * http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip |
|
10 | + * |
|
11 | + * More ideas are taken from: http://www.ics.uci.edu/~eppstein/161/960229.html |
|
12 | + * |
|
13 | + * Some ideas (and a bit of code) are taken from analyze.c, of GNU |
|
14 | + * diffutils-2.7, which can be found at: |
|
15 | + * ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz |
|
16 | + * |
|
17 | + * Some ideas (subdivision by NCHUNKS > 2, and some optimizations) are from |
|
18 | + * Geoffrey T. Dairiki <[email protected]>. The original PHP version of this |
|
19 | + * code was written by him, and is used/adapted with his permission. |
|
20 | + * |
|
21 | + * Copyright 2004-2010 The Horde Project (http://www.horde.org/) |
|
22 | + * |
|
23 | + * See the enclosed file COPYING for license information (LGPL). If you did |
|
24 | + * not receive this file, see http://opensource.org/licenses/lgpl-license.php. |
|
25 | + * |
|
26 | + * @author Geoffrey T. Dairiki <[email protected]> |
|
27 | + * @package Text_Diff |
|
28 | + */ |
|
29 | 29 | class Text_Diff_Engine_native { |
30 | 30 | |
31 | - function diff($from_lines, $to_lines) |
|
32 | - { |
|
33 | - array_walk($from_lines, array('Text_Diff', 'trimNewlines')); |
|
34 | - array_walk($to_lines, array('Text_Diff', 'trimNewlines')); |
|
35 | - |
|
36 | - $n_from = count($from_lines); |
|
37 | - $n_to = count($to_lines); |
|
38 | - |
|
39 | - $this->xchanged = $this->ychanged = array(); |
|
40 | - $this->xv = $this->yv = array(); |
|
41 | - $this->xind = $this->yind = array(); |
|
42 | - unset($this->seq); |
|
43 | - unset($this->in_seq); |
|
44 | - unset($this->lcs); |
|
45 | - |
|
46 | - // Skip leading common lines. |
|
47 | - for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) { |
|
48 | - if ($from_lines[$skip] !== $to_lines[$skip]) { |
|
49 | - break; |
|
50 | - } |
|
51 | - $this->xchanged[$skip] = $this->ychanged[$skip] = false; |
|
52 | - } |
|
53 | - |
|
54 | - // Skip trailing common lines. |
|
55 | - $xi = $n_from; $yi = $n_to; |
|
56 | - for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) { |
|
57 | - if ($from_lines[$xi] !== $to_lines[$yi]) { |
|
58 | - break; |
|
59 | - } |
|
60 | - $this->xchanged[$xi] = $this->ychanged[$yi] = false; |
|
61 | - } |
|
62 | - |
|
63 | - // Ignore lines which do not exist in both files. |
|
64 | - for ($xi = $skip; $xi < $n_from - $endskip; $xi++) { |
|
65 | - $xhash[$from_lines[$xi]] = 1; |
|
66 | - } |
|
67 | - for ($yi = $skip; $yi < $n_to - $endskip; $yi++) { |
|
68 | - $line = $to_lines[$yi]; |
|
69 | - if (($this->ychanged[$yi] = empty($xhash[$line]))) { |
|
70 | - continue; |
|
71 | - } |
|
72 | - $yhash[$line] = 1; |
|
73 | - $this->yv[] = $line; |
|
74 | - $this->yind[] = $yi; |
|
75 | - } |
|
76 | - for ($xi = $skip; $xi < $n_from - $endskip; $xi++) { |
|
77 | - $line = $from_lines[$xi]; |
|
78 | - if (($this->xchanged[$xi] = empty($yhash[$line]))) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - $this->xv[] = $line; |
|
82 | - $this->xind[] = $xi; |
|
83 | - } |
|
84 | - |
|
85 | - // Find the LCS. |
|
86 | - $this->_compareseq(0, count($this->xv), 0, count($this->yv)); |
|
87 | - |
|
88 | - // Merge edits when possible. |
|
89 | - $this->_shiftBoundaries($from_lines, $this->xchanged, $this->ychanged); |
|
90 | - $this->_shiftBoundaries($to_lines, $this->ychanged, $this->xchanged); |
|
91 | - |
|
92 | - // Compute the edit operations. |
|
93 | - $edits = array(); |
|
94 | - $xi = $yi = 0; |
|
95 | - while ($xi < $n_from || $yi < $n_to) { |
|
96 | - assert($yi < $n_to || $this->xchanged[$xi]); |
|
97 | - assert($xi < $n_from || $this->ychanged[$yi]); |
|
98 | - |
|
99 | - // Skip matching "snake". |
|
100 | - $copy = array(); |
|
101 | - while ($xi < $n_from && $yi < $n_to |
|
102 | - && !$this->xchanged[$xi] && !$this->ychanged[$yi]) { |
|
103 | - $copy[] = $from_lines[$xi++]; |
|
104 | - ++$yi; |
|
105 | - } |
|
106 | - if ($copy) { |
|
107 | - $edits[] = new Text_Diff_Op_copy($copy); |
|
108 | - } |
|
109 | - |
|
110 | - // Find deletes & adds. |
|
111 | - $delete = array(); |
|
112 | - while ($xi < $n_from && $this->xchanged[$xi]) { |
|
113 | - $delete[] = $from_lines[$xi++]; |
|
114 | - } |
|
115 | - |
|
116 | - $add = array(); |
|
117 | - while ($yi < $n_to && $this->ychanged[$yi]) { |
|
118 | - $add[] = $to_lines[$yi++]; |
|
119 | - } |
|
120 | - |
|
121 | - if ($delete && $add) { |
|
122 | - $edits[] = new Text_Diff_Op_change($delete, $add); |
|
123 | - } elseif ($delete) { |
|
124 | - $edits[] = new Text_Diff_Op_delete($delete); |
|
125 | - } elseif ($add) { |
|
126 | - $edits[] = new Text_Diff_Op_add($add); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - return $edits; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Divides the Largest Common Subsequence (LCS) of the sequences (XOFF, |
|
135 | - * XLIM) and (YOFF, YLIM) into NCHUNKS approximately equally sized |
|
136 | - * segments. |
|
137 | - * |
|
138 | - * Returns (LCS, PTS). LCS is the length of the LCS. PTS is an array of |
|
139 | - * NCHUNKS+1 (X, Y) indexes giving the diving points between sub |
|
140 | - * sequences. The first sub-sequence is contained in (X0, X1), (Y0, Y1), |
|
141 | - * the second in (X1, X2), (Y1, Y2) and so on. Note that (X0, Y0) == |
|
142 | - * (XOFF, YOFF) and (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM). |
|
143 | - * |
|
144 | - * This function assumes that the first lines of the specified portions of |
|
145 | - * the two files do not match, and likewise that the last lines do not |
|
146 | - * match. The caller must trim matching lines from the beginning and end |
|
147 | - * of the portions it is going to specify. |
|
148 | - */ |
|
149 | - function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) |
|
150 | - { |
|
151 | - $flip = false; |
|
152 | - |
|
153 | - if ($xlim - $xoff > $ylim - $yoff) { |
|
154 | - /* Things seems faster (I'm not sure I understand why) when the |
|
31 | + function diff($from_lines, $to_lines) |
|
32 | + { |
|
33 | + array_walk($from_lines, array('Text_Diff', 'trimNewlines')); |
|
34 | + array_walk($to_lines, array('Text_Diff', 'trimNewlines')); |
|
35 | + |
|
36 | + $n_from = count($from_lines); |
|
37 | + $n_to = count($to_lines); |
|
38 | + |
|
39 | + $this->xchanged = $this->ychanged = array(); |
|
40 | + $this->xv = $this->yv = array(); |
|
41 | + $this->xind = $this->yind = array(); |
|
42 | + unset($this->seq); |
|
43 | + unset($this->in_seq); |
|
44 | + unset($this->lcs); |
|
45 | + |
|
46 | + // Skip leading common lines. |
|
47 | + for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) { |
|
48 | + if ($from_lines[$skip] !== $to_lines[$skip]) { |
|
49 | + break; |
|
50 | + } |
|
51 | + $this->xchanged[$skip] = $this->ychanged[$skip] = false; |
|
52 | + } |
|
53 | + |
|
54 | + // Skip trailing common lines. |
|
55 | + $xi = $n_from; $yi = $n_to; |
|
56 | + for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) { |
|
57 | + if ($from_lines[$xi] !== $to_lines[$yi]) { |
|
58 | + break; |
|
59 | + } |
|
60 | + $this->xchanged[$xi] = $this->ychanged[$yi] = false; |
|
61 | + } |
|
62 | + |
|
63 | + // Ignore lines which do not exist in both files. |
|
64 | + for ($xi = $skip; $xi < $n_from - $endskip; $xi++) { |
|
65 | + $xhash[$from_lines[$xi]] = 1; |
|
66 | + } |
|
67 | + for ($yi = $skip; $yi < $n_to - $endskip; $yi++) { |
|
68 | + $line = $to_lines[$yi]; |
|
69 | + if (($this->ychanged[$yi] = empty($xhash[$line]))) { |
|
70 | + continue; |
|
71 | + } |
|
72 | + $yhash[$line] = 1; |
|
73 | + $this->yv[] = $line; |
|
74 | + $this->yind[] = $yi; |
|
75 | + } |
|
76 | + for ($xi = $skip; $xi < $n_from - $endskip; $xi++) { |
|
77 | + $line = $from_lines[$xi]; |
|
78 | + if (($this->xchanged[$xi] = empty($yhash[$line]))) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + $this->xv[] = $line; |
|
82 | + $this->xind[] = $xi; |
|
83 | + } |
|
84 | + |
|
85 | + // Find the LCS. |
|
86 | + $this->_compareseq(0, count($this->xv), 0, count($this->yv)); |
|
87 | + |
|
88 | + // Merge edits when possible. |
|
89 | + $this->_shiftBoundaries($from_lines, $this->xchanged, $this->ychanged); |
|
90 | + $this->_shiftBoundaries($to_lines, $this->ychanged, $this->xchanged); |
|
91 | + |
|
92 | + // Compute the edit operations. |
|
93 | + $edits = array(); |
|
94 | + $xi = $yi = 0; |
|
95 | + while ($xi < $n_from || $yi < $n_to) { |
|
96 | + assert($yi < $n_to || $this->xchanged[$xi]); |
|
97 | + assert($xi < $n_from || $this->ychanged[$yi]); |
|
98 | + |
|
99 | + // Skip matching "snake". |
|
100 | + $copy = array(); |
|
101 | + while ($xi < $n_from && $yi < $n_to |
|
102 | + && !$this->xchanged[$xi] && !$this->ychanged[$yi]) { |
|
103 | + $copy[] = $from_lines[$xi++]; |
|
104 | + ++$yi; |
|
105 | + } |
|
106 | + if ($copy) { |
|
107 | + $edits[] = new Text_Diff_Op_copy($copy); |
|
108 | + } |
|
109 | + |
|
110 | + // Find deletes & adds. |
|
111 | + $delete = array(); |
|
112 | + while ($xi < $n_from && $this->xchanged[$xi]) { |
|
113 | + $delete[] = $from_lines[$xi++]; |
|
114 | + } |
|
115 | + |
|
116 | + $add = array(); |
|
117 | + while ($yi < $n_to && $this->ychanged[$yi]) { |
|
118 | + $add[] = $to_lines[$yi++]; |
|
119 | + } |
|
120 | + |
|
121 | + if ($delete && $add) { |
|
122 | + $edits[] = new Text_Diff_Op_change($delete, $add); |
|
123 | + } elseif ($delete) { |
|
124 | + $edits[] = new Text_Diff_Op_delete($delete); |
|
125 | + } elseif ($add) { |
|
126 | + $edits[] = new Text_Diff_Op_add($add); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + return $edits; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Divides the Largest Common Subsequence (LCS) of the sequences (XOFF, |
|
135 | + * XLIM) and (YOFF, YLIM) into NCHUNKS approximately equally sized |
|
136 | + * segments. |
|
137 | + * |
|
138 | + * Returns (LCS, PTS). LCS is the length of the LCS. PTS is an array of |
|
139 | + * NCHUNKS+1 (X, Y) indexes giving the diving points between sub |
|
140 | + * sequences. The first sub-sequence is contained in (X0, X1), (Y0, Y1), |
|
141 | + * the second in (X1, X2), (Y1, Y2) and so on. Note that (X0, Y0) == |
|
142 | + * (XOFF, YOFF) and (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM). |
|
143 | + * |
|
144 | + * This function assumes that the first lines of the specified portions of |
|
145 | + * the two files do not match, and likewise that the last lines do not |
|
146 | + * match. The caller must trim matching lines from the beginning and end |
|
147 | + * of the portions it is going to specify. |
|
148 | + */ |
|
149 | + function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) |
|
150 | + { |
|
151 | + $flip = false; |
|
152 | + |
|
153 | + if ($xlim - $xoff > $ylim - $yoff) { |
|
154 | + /* Things seems faster (I'm not sure I understand why) when the |
|
155 | 155 | * shortest sequence is in X. */ |
156 | - $flip = true; |
|
157 | - list ($xoff, $xlim, $yoff, $ylim) |
|
158 | - = array($yoff, $ylim, $xoff, $xlim); |
|
159 | - } |
|
160 | - |
|
161 | - if ($flip) { |
|
162 | - for ($i = $ylim - 1; $i >= $yoff; $i--) { |
|
163 | - $ymatches[$this->xv[$i]][] = $i; |
|
164 | - } |
|
165 | - } else { |
|
166 | - for ($i = $ylim - 1; $i >= $yoff; $i--) { |
|
167 | - $ymatches[$this->yv[$i]][] = $i; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - $this->lcs = 0; |
|
172 | - $this->seq[0]= $yoff - 1; |
|
173 | - $this->in_seq = array(); |
|
174 | - $ymids[0] = array(); |
|
175 | - |
|
176 | - $numer = $xlim - $xoff + $nchunks - 1; |
|
177 | - $x = $xoff; |
|
178 | - for ($chunk = 0; $chunk < $nchunks; $chunk++) { |
|
179 | - if ($chunk > 0) { |
|
180 | - for ($i = 0; $i <= $this->lcs; $i++) { |
|
181 | - $ymids[$i][$chunk - 1] = $this->seq[$i]; |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $chunk) / $nchunks); |
|
186 | - for (; $x < $x1; $x++) { |
|
187 | - $line = $flip ? $this->yv[$x] : $this->xv[$x]; |
|
188 | - if (empty($ymatches[$line])) { |
|
189 | - continue; |
|
190 | - } |
|
191 | - $matches = $ymatches[$line]; |
|
192 | - reset($matches); |
|
193 | - while (list(, $y) = each($matches)) { |
|
194 | - if (empty($this->in_seq[$y])) { |
|
195 | - $k = $this->_lcsPos($y); |
|
196 | - assert($k > 0); |
|
197 | - $ymids[$k] = $ymids[$k - 1]; |
|
198 | - break; |
|
199 | - } |
|
200 | - } |
|
201 | - while (list(, $y) = each($matches)) { |
|
202 | - if ($y > $this->seq[$k - 1]) { |
|
203 | - assert($y <= $this->seq[$k]); |
|
204 | - /* Optimization: this is a common case: next match is |
|
156 | + $flip = true; |
|
157 | + list ($xoff, $xlim, $yoff, $ylim) |
|
158 | + = array($yoff, $ylim, $xoff, $xlim); |
|
159 | + } |
|
160 | + |
|
161 | + if ($flip) { |
|
162 | + for ($i = $ylim - 1; $i >= $yoff; $i--) { |
|
163 | + $ymatches[$this->xv[$i]][] = $i; |
|
164 | + } |
|
165 | + } else { |
|
166 | + for ($i = $ylim - 1; $i >= $yoff; $i--) { |
|
167 | + $ymatches[$this->yv[$i]][] = $i; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + $this->lcs = 0; |
|
172 | + $this->seq[0]= $yoff - 1; |
|
173 | + $this->in_seq = array(); |
|
174 | + $ymids[0] = array(); |
|
175 | + |
|
176 | + $numer = $xlim - $xoff + $nchunks - 1; |
|
177 | + $x = $xoff; |
|
178 | + for ($chunk = 0; $chunk < $nchunks; $chunk++) { |
|
179 | + if ($chunk > 0) { |
|
180 | + for ($i = 0; $i <= $this->lcs; $i++) { |
|
181 | + $ymids[$i][$chunk - 1] = $this->seq[$i]; |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $chunk) / $nchunks); |
|
186 | + for (; $x < $x1; $x++) { |
|
187 | + $line = $flip ? $this->yv[$x] : $this->xv[$x]; |
|
188 | + if (empty($ymatches[$line])) { |
|
189 | + continue; |
|
190 | + } |
|
191 | + $matches = $ymatches[$line]; |
|
192 | + reset($matches); |
|
193 | + while (list(, $y) = each($matches)) { |
|
194 | + if (empty($this->in_seq[$y])) { |
|
195 | + $k = $this->_lcsPos($y); |
|
196 | + assert($k > 0); |
|
197 | + $ymids[$k] = $ymids[$k - 1]; |
|
198 | + break; |
|
199 | + } |
|
200 | + } |
|
201 | + while (list(, $y) = each($matches)) { |
|
202 | + if ($y > $this->seq[$k - 1]) { |
|
203 | + assert($y <= $this->seq[$k]); |
|
204 | + /* Optimization: this is a common case: next match is |
|
205 | 205 | * just replacing previous match. */ |
206 | - $this->in_seq[$this->seq[$k]] = false; |
|
207 | - $this->seq[$k] = $y; |
|
208 | - $this->in_seq[$y] = 1; |
|
209 | - } elseif (empty($this->in_seq[$y])) { |
|
210 | - $k = $this->_lcsPos($y); |
|
211 | - assert($k > 0); |
|
212 | - $ymids[$k] = $ymids[$k - 1]; |
|
213 | - } |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff); |
|
219 | - $ymid = $ymids[$this->lcs]; |
|
220 | - for ($n = 0; $n < $nchunks - 1; $n++) { |
|
221 | - $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks); |
|
222 | - $y1 = $ymid[$n] + 1; |
|
223 | - $seps[] = $flip ? array($y1, $x1) : array($x1, $y1); |
|
224 | - } |
|
225 | - $seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim); |
|
226 | - |
|
227 | - return array($this->lcs, $seps); |
|
228 | - } |
|
229 | - |
|
230 | - function _lcsPos($ypos) |
|
231 | - { |
|
232 | - $end = $this->lcs; |
|
233 | - if ($end == 0 || $ypos > $this->seq[$end]) { |
|
234 | - $this->seq[++$this->lcs] = $ypos; |
|
235 | - $this->in_seq[$ypos] = 1; |
|
236 | - return $this->lcs; |
|
237 | - } |
|
238 | - |
|
239 | - $beg = 1; |
|
240 | - while ($beg < $end) { |
|
241 | - $mid = (int)(($beg + $end) / 2); |
|
242 | - if ($ypos > $this->seq[$mid]) { |
|
243 | - $beg = $mid + 1; |
|
244 | - } else { |
|
245 | - $end = $mid; |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - assert($ypos != $this->seq[$end]); |
|
250 | - |
|
251 | - $this->in_seq[$this->seq[$end]] = false; |
|
252 | - $this->seq[$end] = $ypos; |
|
253 | - $this->in_seq[$ypos] = 1; |
|
254 | - return $end; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Finds LCS of two sequences. |
|
259 | - * |
|
260 | - * The results are recorded in the vectors $this->{x,y}changed[], by |
|
261 | - * storing a 1 in the element for each line that is an insertion or |
|
262 | - * deletion (ie. is not in the LCS). |
|
263 | - * |
|
264 | - * The subsequence of file 0 is (XOFF, XLIM) and likewise for file 1. |
|
265 | - * |
|
266 | - * Note that XLIM, YLIM are exclusive bounds. All line numbers are |
|
267 | - * origin-0 and discarded lines are not counted. |
|
268 | - */ |
|
269 | - function _compareseq ($xoff, $xlim, $yoff, $ylim) |
|
270 | - { |
|
271 | - /* Slide down the bottom initial diagonal. */ |
|
272 | - while ($xoff < $xlim && $yoff < $ylim |
|
273 | - && $this->xv[$xoff] == $this->yv[$yoff]) { |
|
274 | - ++$xoff; |
|
275 | - ++$yoff; |
|
276 | - } |
|
277 | - |
|
278 | - /* Slide up the top initial diagonal. */ |
|
279 | - while ($xlim > $xoff && $ylim > $yoff |
|
280 | - && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) { |
|
281 | - --$xlim; |
|
282 | - --$ylim; |
|
283 | - } |
|
284 | - |
|
285 | - if ($xoff == $xlim || $yoff == $ylim) { |
|
286 | - $lcs = 0; |
|
287 | - } else { |
|
288 | - /* This is ad hoc but seems to work well. $nchunks = |
|
206 | + $this->in_seq[$this->seq[$k]] = false; |
|
207 | + $this->seq[$k] = $y; |
|
208 | + $this->in_seq[$y] = 1; |
|
209 | + } elseif (empty($this->in_seq[$y])) { |
|
210 | + $k = $this->_lcsPos($y); |
|
211 | + assert($k > 0); |
|
212 | + $ymids[$k] = $ymids[$k - 1]; |
|
213 | + } |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff); |
|
219 | + $ymid = $ymids[$this->lcs]; |
|
220 | + for ($n = 0; $n < $nchunks - 1; $n++) { |
|
221 | + $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks); |
|
222 | + $y1 = $ymid[$n] + 1; |
|
223 | + $seps[] = $flip ? array($y1, $x1) : array($x1, $y1); |
|
224 | + } |
|
225 | + $seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim); |
|
226 | + |
|
227 | + return array($this->lcs, $seps); |
|
228 | + } |
|
229 | + |
|
230 | + function _lcsPos($ypos) |
|
231 | + { |
|
232 | + $end = $this->lcs; |
|
233 | + if ($end == 0 || $ypos > $this->seq[$end]) { |
|
234 | + $this->seq[++$this->lcs] = $ypos; |
|
235 | + $this->in_seq[$ypos] = 1; |
|
236 | + return $this->lcs; |
|
237 | + } |
|
238 | + |
|
239 | + $beg = 1; |
|
240 | + while ($beg < $end) { |
|
241 | + $mid = (int)(($beg + $end) / 2); |
|
242 | + if ($ypos > $this->seq[$mid]) { |
|
243 | + $beg = $mid + 1; |
|
244 | + } else { |
|
245 | + $end = $mid; |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + assert($ypos != $this->seq[$end]); |
|
250 | + |
|
251 | + $this->in_seq[$this->seq[$end]] = false; |
|
252 | + $this->seq[$end] = $ypos; |
|
253 | + $this->in_seq[$ypos] = 1; |
|
254 | + return $end; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Finds LCS of two sequences. |
|
259 | + * |
|
260 | + * The results are recorded in the vectors $this->{x,y}changed[], by |
|
261 | + * storing a 1 in the element for each line that is an insertion or |
|
262 | + * deletion (ie. is not in the LCS). |
|
263 | + * |
|
264 | + * The subsequence of file 0 is (XOFF, XLIM) and likewise for file 1. |
|
265 | + * |
|
266 | + * Note that XLIM, YLIM are exclusive bounds. All line numbers are |
|
267 | + * origin-0 and discarded lines are not counted. |
|
268 | + */ |
|
269 | + function _compareseq ($xoff, $xlim, $yoff, $ylim) |
|
270 | + { |
|
271 | + /* Slide down the bottom initial diagonal. */ |
|
272 | + while ($xoff < $xlim && $yoff < $ylim |
|
273 | + && $this->xv[$xoff] == $this->yv[$yoff]) { |
|
274 | + ++$xoff; |
|
275 | + ++$yoff; |
|
276 | + } |
|
277 | + |
|
278 | + /* Slide up the top initial diagonal. */ |
|
279 | + while ($xlim > $xoff && $ylim > $yoff |
|
280 | + && $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) { |
|
281 | + --$xlim; |
|
282 | + --$ylim; |
|
283 | + } |
|
284 | + |
|
285 | + if ($xoff == $xlim || $yoff == $ylim) { |
|
286 | + $lcs = 0; |
|
287 | + } else { |
|
288 | + /* This is ad hoc but seems to work well. $nchunks = |
|
289 | 289 | * sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5); $nchunks = |
290 | 290 | * max(2,min(8,(int)$nchunks)); */ |
291 | - $nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1; |
|
292 | - list($lcs, $seps) |
|
293 | - = $this->_diag($xoff, $xlim, $yoff, $ylim, $nchunks); |
|
294 | - } |
|
291 | + $nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1; |
|
292 | + list($lcs, $seps) |
|
293 | + = $this->_diag($xoff, $xlim, $yoff, $ylim, $nchunks); |
|
294 | + } |
|
295 | 295 | |
296 | - if ($lcs == 0) { |
|
297 | - /* X and Y sequences have no common subsequence: mark all |
|
296 | + if ($lcs == 0) { |
|
297 | + /* X and Y sequences have no common subsequence: mark all |
|
298 | 298 | * changed. */ |
299 | - while ($yoff < $ylim) { |
|
300 | - $this->ychanged[$this->yind[$yoff++]] = 1; |
|
301 | - } |
|
302 | - while ($xoff < $xlim) { |
|
303 | - $this->xchanged[$this->xind[$xoff++]] = 1; |
|
304 | - } |
|
305 | - } else { |
|
306 | - /* Use the partitions to split this problem into subproblems. */ |
|
307 | - reset($seps); |
|
308 | - $pt1 = $seps[0]; |
|
309 | - while ($pt2 = next($seps)) { |
|
310 | - $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]); |
|
311 | - $pt1 = $pt2; |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Adjusts inserts/deletes of identical lines to join changes as much as |
|
318 | - * possible. |
|
319 | - * |
|
320 | - * We do something when a run of changed lines include a line at one end |
|
321 | - * and has an excluded, identical line at the other. We are free to |
|
322 | - * choose which identical line is included. `compareseq' usually chooses |
|
323 | - * the one at the beginning, but usually it is cleaner to consider the |
|
324 | - * following identical line to be the "change". |
|
325 | - * |
|
326 | - * This is extracted verbatim from analyze.c (GNU diffutils-2.7). |
|
327 | - */ |
|
328 | - function _shiftBoundaries($lines, &$changed, $other_changed) |
|
329 | - { |
|
330 | - $i = 0; |
|
331 | - $j = 0; |
|
332 | - |
|
333 | - assert('count($lines) == count($changed)'); |
|
334 | - $len = count($lines); |
|
335 | - $other_len = count($other_changed); |
|
336 | - |
|
337 | - while (1) { |
|
338 | - /* Scan forward to find the beginning of another run of |
|
299 | + while ($yoff < $ylim) { |
|
300 | + $this->ychanged[$this->yind[$yoff++]] = 1; |
|
301 | + } |
|
302 | + while ($xoff < $xlim) { |
|
303 | + $this->xchanged[$this->xind[$xoff++]] = 1; |
|
304 | + } |
|
305 | + } else { |
|
306 | + /* Use the partitions to split this problem into subproblems. */ |
|
307 | + reset($seps); |
|
308 | + $pt1 = $seps[0]; |
|
309 | + while ($pt2 = next($seps)) { |
|
310 | + $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]); |
|
311 | + $pt1 = $pt2; |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Adjusts inserts/deletes of identical lines to join changes as much as |
|
318 | + * possible. |
|
319 | + * |
|
320 | + * We do something when a run of changed lines include a line at one end |
|
321 | + * and has an excluded, identical line at the other. We are free to |
|
322 | + * choose which identical line is included. `compareseq' usually chooses |
|
323 | + * the one at the beginning, but usually it is cleaner to consider the |
|
324 | + * following identical line to be the "change". |
|
325 | + * |
|
326 | + * This is extracted verbatim from analyze.c (GNU diffutils-2.7). |
|
327 | + */ |
|
328 | + function _shiftBoundaries($lines, &$changed, $other_changed) |
|
329 | + { |
|
330 | + $i = 0; |
|
331 | + $j = 0; |
|
332 | + |
|
333 | + assert('count($lines) == count($changed)'); |
|
334 | + $len = count($lines); |
|
335 | + $other_len = count($other_changed); |
|
336 | + |
|
337 | + while (1) { |
|
338 | + /* Scan forward to find the beginning of another run of |
|
339 | 339 | * changes. Also keep track of the corresponding point in the |
340 | 340 | * other file. |
341 | 341 | * |
@@ -346,91 +346,91 @@ discard block |
||
346 | 346 | * |
347 | 347 | * Furthermore, $j is always kept so that $j == $other_len or |
348 | 348 | * $other_changed[$j] == false. */ |
349 | - while ($j < $other_len && $other_changed[$j]) { |
|
350 | - $j++; |
|
351 | - } |
|
352 | - |
|
353 | - while ($i < $len && ! $changed[$i]) { |
|
354 | - assert('$j < $other_len && ! $other_changed[$j]'); |
|
355 | - $i++; $j++; |
|
356 | - while ($j < $other_len && $other_changed[$j]) { |
|
357 | - $j++; |
|
358 | - } |
|
359 | - } |
|
360 | - |
|
361 | - if ($i == $len) { |
|
362 | - break; |
|
363 | - } |
|
364 | - |
|
365 | - $start = $i; |
|
366 | - |
|
367 | - /* Find the end of this run of changes. */ |
|
368 | - while (++$i < $len && $changed[$i]) { |
|
369 | - continue; |
|
370 | - } |
|
371 | - |
|
372 | - do { |
|
373 | - /* Record the length of this run of changes, so that we can |
|
349 | + while ($j < $other_len && $other_changed[$j]) { |
|
350 | + $j++; |
|
351 | + } |
|
352 | + |
|
353 | + while ($i < $len && ! $changed[$i]) { |
|
354 | + assert('$j < $other_len && ! $other_changed[$j]'); |
|
355 | + $i++; $j++; |
|
356 | + while ($j < $other_len && $other_changed[$j]) { |
|
357 | + $j++; |
|
358 | + } |
|
359 | + } |
|
360 | + |
|
361 | + if ($i == $len) { |
|
362 | + break; |
|
363 | + } |
|
364 | + |
|
365 | + $start = $i; |
|
366 | + |
|
367 | + /* Find the end of this run of changes. */ |
|
368 | + while (++$i < $len && $changed[$i]) { |
|
369 | + continue; |
|
370 | + } |
|
371 | + |
|
372 | + do { |
|
373 | + /* Record the length of this run of changes, so that we can |
|
374 | 374 | * later determine whether the run has grown. */ |
375 | - $runlength = $i - $start; |
|
375 | + $runlength = $i - $start; |
|
376 | 376 | |
377 | - /* Move the changed region back, so long as the previous |
|
377 | + /* Move the changed region back, so long as the previous |
|
378 | 378 | * unchanged line matches the last changed one. This merges |
379 | 379 | * with previous changed regions. */ |
380 | - while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) { |
|
381 | - $changed[--$start] = 1; |
|
382 | - $changed[--$i] = false; |
|
383 | - while ($start > 0 && $changed[$start - 1]) { |
|
384 | - $start--; |
|
385 | - } |
|
386 | - assert('$j > 0'); |
|
387 | - while ($other_changed[--$j]) { |
|
388 | - continue; |
|
389 | - } |
|
390 | - assert('$j >= 0 && !$other_changed[$j]'); |
|
391 | - } |
|
392 | - |
|
393 | - /* Set CORRESPONDING to the end of the changed run, at the |
|
380 | + while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) { |
|
381 | + $changed[--$start] = 1; |
|
382 | + $changed[--$i] = false; |
|
383 | + while ($start > 0 && $changed[$start - 1]) { |
|
384 | + $start--; |
|
385 | + } |
|
386 | + assert('$j > 0'); |
|
387 | + while ($other_changed[--$j]) { |
|
388 | + continue; |
|
389 | + } |
|
390 | + assert('$j >= 0 && !$other_changed[$j]'); |
|
391 | + } |
|
392 | + |
|
393 | + /* Set CORRESPONDING to the end of the changed run, at the |
|
394 | 394 | * last point where it corresponds to a changed run in the |
395 | 395 | * other file. CORRESPONDING == LEN means no such point has |
396 | 396 | * been found. */ |
397 | - $corresponding = $j < $other_len ? $i : $len; |
|
397 | + $corresponding = $j < $other_len ? $i : $len; |
|
398 | 398 | |
399 | - /* Move the changed region forward, so long as the first |
|
399 | + /* Move the changed region forward, so long as the first |
|
400 | 400 | * changed line matches the following unchanged one. This |
401 | 401 | * merges with following changed regions. Do this second, so |
402 | 402 | * that if there are no merges, the changed region is moved |
403 | 403 | * forward as far as possible. */ |
404 | - while ($i < $len && $lines[$start] == $lines[$i]) { |
|
405 | - $changed[$start++] = false; |
|
406 | - $changed[$i++] = 1; |
|
407 | - while ($i < $len && $changed[$i]) { |
|
408 | - $i++; |
|
409 | - } |
|
410 | - |
|
411 | - assert('$j < $other_len && ! $other_changed[$j]'); |
|
412 | - $j++; |
|
413 | - if ($j < $other_len && $other_changed[$j]) { |
|
414 | - $corresponding = $i; |
|
415 | - while ($j < $other_len && $other_changed[$j]) { |
|
416 | - $j++; |
|
417 | - } |
|
418 | - } |
|
419 | - } |
|
420 | - } while ($runlength != $i - $start); |
|
421 | - |
|
422 | - /* If possible, move the fully-merged run of changes back to a |
|
404 | + while ($i < $len && $lines[$start] == $lines[$i]) { |
|
405 | + $changed[$start++] = false; |
|
406 | + $changed[$i++] = 1; |
|
407 | + while ($i < $len && $changed[$i]) { |
|
408 | + $i++; |
|
409 | + } |
|
410 | + |
|
411 | + assert('$j < $other_len && ! $other_changed[$j]'); |
|
412 | + $j++; |
|
413 | + if ($j < $other_len && $other_changed[$j]) { |
|
414 | + $corresponding = $i; |
|
415 | + while ($j < $other_len && $other_changed[$j]) { |
|
416 | + $j++; |
|
417 | + } |
|
418 | + } |
|
419 | + } |
|
420 | + } while ($runlength != $i - $start); |
|
421 | + |
|
422 | + /* If possible, move the fully-merged run of changes back to a |
|
423 | 423 | * corresponding run in the other file. */ |
424 | - while ($corresponding < $i) { |
|
425 | - $changed[--$start] = 1; |
|
426 | - $changed[--$i] = 0; |
|
427 | - assert('$j > 0'); |
|
428 | - while ($other_changed[--$j]) { |
|
429 | - continue; |
|
430 | - } |
|
431 | - assert('$j >= 0 && !$other_changed[$j]'); |
|
432 | - } |
|
433 | - } |
|
434 | - } |
|
424 | + while ($corresponding < $i) { |
|
425 | + $changed[--$start] = 1; |
|
426 | + $changed[--$i] = 0; |
|
427 | + assert('$j > 0'); |
|
428 | + while ($other_changed[--$j]) { |
|
429 | + continue; |
|
430 | + } |
|
431 | + assert('$j >= 0 && !$other_changed[$j]'); |
|
432 | + } |
|
433 | + } |
|
434 | + } |
|
435 | 435 | |
436 | 436 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | // Skip matching "snake". |
100 | 100 | $copy = array(); |
101 | 101 | while ($xi < $n_from && $yi < $n_to |
102 | - && !$this->xchanged[$xi] && !$this->ychanged[$yi]) { |
|
102 | + && ! $this->xchanged[$xi] && ! $this->ychanged[$yi]) { |
|
103 | 103 | $copy[] = $from_lines[$xi++]; |
104 | 104 | ++$yi; |
105 | 105 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * match. The caller must trim matching lines from the beginning and end |
147 | 147 | * of the portions it is going to specify. |
148 | 148 | */ |
149 | - function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks) |
|
149 | + function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) |
|
150 | 150 | { |
151 | 151 | $flip = false; |
152 | 152 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | $this->lcs = 0; |
172 | - $this->seq[0]= $yoff - 1; |
|
172 | + $this->seq[0] = $yoff - 1; |
|
173 | 173 | $this->in_seq = array(); |
174 | 174 | $ymids[0] = array(); |
175 | 175 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $chunk) / $nchunks); |
|
185 | + $x1 = $xoff + (int) (($numer + ($xlim - $xoff) * $chunk) / $nchunks); |
|
186 | 186 | for (; $x < $x1; $x++) { |
187 | 187 | $line = $flip ? $this->yv[$x] : $this->xv[$x]; |
188 | 188 | if (empty($ymatches[$line])) { |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff); |
219 | 219 | $ymid = $ymids[$this->lcs]; |
220 | 220 | for ($n = 0; $n < $nchunks - 1; $n++) { |
221 | - $x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks); |
|
221 | + $x1 = $xoff + (int) (($numer + ($xlim - $xoff) * $n) / $nchunks); |
|
222 | 222 | $y1 = $ymid[$n] + 1; |
223 | 223 | $seps[] = $flip ? array($y1, $x1) : array($x1, $y1); |
224 | 224 | } |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | $beg = 1; |
240 | 240 | while ($beg < $end) { |
241 | - $mid = (int)(($beg + $end) / 2); |
|
241 | + $mid = (int) (($beg + $end) / 2); |
|
242 | 242 | if ($ypos > $this->seq[$mid]) { |
243 | 243 | $beg = $mid + 1; |
244 | 244 | } else { |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * Note that XLIM, YLIM are exclusive bounds. All line numbers are |
267 | 267 | * origin-0 and discarded lines are not counted. |
268 | 268 | */ |
269 | - function _compareseq ($xoff, $xlim, $yoff, $ylim) |
|
269 | + function _compareseq($xoff, $xlim, $yoff, $ylim) |
|
270 | 270 | { |
271 | 271 | /* Slide down the bottom initial diagonal. */ |
272 | 272 | while ($xoff < $xlim && $yoff < $ylim |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | reset($seps); |
308 | 308 | $pt1 = $seps[0]; |
309 | 309 | while ($pt2 = next($seps)) { |
310 | - $this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]); |
|
310 | + $this->_compareseq($pt1[0], $pt2[0], $pt1[1], $pt2[1]); |
|
311 | 311 | $pt1 = $pt2; |
312 | 312 | } |
313 | 313 | } |
@@ -148,6 +148,12 @@ discard block |
||
148 | 148 | return $output . $this->_endDiff(); |
149 | 149 | } |
150 | 150 | |
151 | + /** |
|
152 | + * @param integer $xbeg |
|
153 | + * @param integer $xlen |
|
154 | + * @param integer $ybeg |
|
155 | + * @param integer $ylen |
|
156 | + */ |
|
151 | 157 | function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) |
152 | 158 | { |
153 | 159 | $output = $this->_startBlock($this->_blockHeader($xbeg, $xlen, $ybeg, $ylen)); |
@@ -204,6 +210,9 @@ discard block |
||
204 | 210 | return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; |
205 | 211 | } |
206 | 212 | |
213 | + /** |
|
214 | + * @param string $header |
|
215 | + */ |
|
207 | 216 | function _startBlock($header) |
208 | 217 | { |
209 | 218 | return $header . "\n"; |
@@ -14,34 +14,34 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Text_Diff_Renderer { |
16 | 16 | |
17 | - /** |
|
18 | - * Number of leading context "lines" to preserve. |
|
19 | - * |
|
20 | - * This should be left at zero for this class, but subclasses may want to |
|
21 | - * set this to other values. |
|
22 | - */ |
|
23 | - var $_leading_context_lines = 0; |
|
24 | - |
|
25 | - /** |
|
26 | - * Number of trailing context "lines" to preserve. |
|
27 | - * |
|
28 | - * This should be left at zero for this class, but subclasses may want to |
|
29 | - * set this to other values. |
|
30 | - */ |
|
31 | - var $_trailing_context_lines = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * Constructor. |
|
35 | - */ |
|
36 | - function __construct( $params = array() ) |
|
37 | - { |
|
38 | - foreach ($params as $param => $value) { |
|
39 | - $v = '_' . $param; |
|
40 | - if (isset($this->$v)) { |
|
41 | - $this->$v = $value; |
|
42 | - } |
|
43 | - } |
|
44 | - } |
|
17 | + /** |
|
18 | + * Number of leading context "lines" to preserve. |
|
19 | + * |
|
20 | + * This should be left at zero for this class, but subclasses may want to |
|
21 | + * set this to other values. |
|
22 | + */ |
|
23 | + var $_leading_context_lines = 0; |
|
24 | + |
|
25 | + /** |
|
26 | + * Number of trailing context "lines" to preserve. |
|
27 | + * |
|
28 | + * This should be left at zero for this class, but subclasses may want to |
|
29 | + * set this to other values. |
|
30 | + */ |
|
31 | + var $_trailing_context_lines = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * Constructor. |
|
35 | + */ |
|
36 | + function __construct( $params = array() ) |
|
37 | + { |
|
38 | + foreach ($params as $param => $value) { |
|
39 | + $v = '_' . $param; |
|
40 | + if (isset($this->$v)) { |
|
41 | + $this->$v = $value; |
|
42 | + } |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * PHP4 constructor. |
@@ -50,193 +50,193 @@ discard block |
||
50 | 50 | self::__construct( $params ); |
51 | 51 | } |
52 | 52 | |
53 | - /** |
|
54 | - * Get any renderer parameters. |
|
55 | - * |
|
56 | - * @return array All parameters of this renderer object. |
|
57 | - */ |
|
58 | - function getParams() |
|
59 | - { |
|
60 | - $params = array(); |
|
61 | - foreach (get_object_vars($this) as $k => $v) { |
|
62 | - if ($k[0] == '_') { |
|
63 | - $params[substr($k, 1)] = $v; |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - return $params; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Renders a diff. |
|
72 | - * |
|
73 | - * @param Text_Diff $diff A Text_Diff object. |
|
74 | - * |
|
75 | - * @return string The formatted output. |
|
76 | - */ |
|
77 | - function render($diff) |
|
78 | - { |
|
79 | - $xi = $yi = 1; |
|
80 | - $block = false; |
|
81 | - $context = array(); |
|
82 | - |
|
83 | - $nlead = $this->_leading_context_lines; |
|
84 | - $ntrail = $this->_trailing_context_lines; |
|
85 | - |
|
86 | - $output = $this->_startDiff(); |
|
87 | - |
|
88 | - $diffs = $diff->getDiff(); |
|
89 | - foreach ($diffs as $i => $edit) { |
|
90 | - /* If these are unchanged (copied) lines, and we want to keep |
|
53 | + /** |
|
54 | + * Get any renderer parameters. |
|
55 | + * |
|
56 | + * @return array All parameters of this renderer object. |
|
57 | + */ |
|
58 | + function getParams() |
|
59 | + { |
|
60 | + $params = array(); |
|
61 | + foreach (get_object_vars($this) as $k => $v) { |
|
62 | + if ($k[0] == '_') { |
|
63 | + $params[substr($k, 1)] = $v; |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + return $params; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Renders a diff. |
|
72 | + * |
|
73 | + * @param Text_Diff $diff A Text_Diff object. |
|
74 | + * |
|
75 | + * @return string The formatted output. |
|
76 | + */ |
|
77 | + function render($diff) |
|
78 | + { |
|
79 | + $xi = $yi = 1; |
|
80 | + $block = false; |
|
81 | + $context = array(); |
|
82 | + |
|
83 | + $nlead = $this->_leading_context_lines; |
|
84 | + $ntrail = $this->_trailing_context_lines; |
|
85 | + |
|
86 | + $output = $this->_startDiff(); |
|
87 | + |
|
88 | + $diffs = $diff->getDiff(); |
|
89 | + foreach ($diffs as $i => $edit) { |
|
90 | + /* If these are unchanged (copied) lines, and we want to keep |
|
91 | 91 | * leading or trailing context lines, extract them from the copy |
92 | 92 | * block. */ |
93 | - if (is_a($edit, 'Text_Diff_Op_copy')) { |
|
94 | - /* Do we have any diff blocks yet? */ |
|
95 | - if (is_array($block)) { |
|
96 | - /* How many lines to keep as context from the copy |
|
93 | + if (is_a($edit, 'Text_Diff_Op_copy')) { |
|
94 | + /* Do we have any diff blocks yet? */ |
|
95 | + if (is_array($block)) { |
|
96 | + /* How many lines to keep as context from the copy |
|
97 | 97 | * block. */ |
98 | - $keep = $i == count($diffs) - 1 ? $ntrail : $nlead + $ntrail; |
|
99 | - if (count($edit->orig) <= $keep) { |
|
100 | - /* We have less lines in the block than we want for |
|
98 | + $keep = $i == count($diffs) - 1 ? $ntrail : $nlead + $ntrail; |
|
99 | + if (count($edit->orig) <= $keep) { |
|
100 | + /* We have less lines in the block than we want for |
|
101 | 101 | * context => keep the whole block. */ |
102 | - $block[] = $edit; |
|
103 | - } else { |
|
104 | - if ($ntrail) { |
|
105 | - /* Create a new block with as many lines as we need |
|
102 | + $block[] = $edit; |
|
103 | + } else { |
|
104 | + if ($ntrail) { |
|
105 | + /* Create a new block with as many lines as we need |
|
106 | 106 | * for the trailing context. */ |
107 | - $context = array_slice($edit->orig, 0, $ntrail); |
|
108 | - $block[] = new Text_Diff_Op_copy($context); |
|
109 | - } |
|
110 | - /* @todo */ |
|
111 | - $output .= $this->_block($x0, $ntrail + $xi - $x0, |
|
112 | - $y0, $ntrail + $yi - $y0, |
|
113 | - $block); |
|
114 | - $block = false; |
|
115 | - } |
|
116 | - } |
|
117 | - /* Keep the copy block as the context for the next block. */ |
|
118 | - $context = $edit->orig; |
|
119 | - } else { |
|
120 | - /* Don't we have any diff blocks yet? */ |
|
121 | - if (!is_array($block)) { |
|
122 | - /* Extract context lines from the preceding copy block. */ |
|
123 | - $context = array_slice($context, count($context) - $nlead); |
|
124 | - $x0 = $xi - count($context); |
|
125 | - $y0 = $yi - count($context); |
|
126 | - $block = array(); |
|
127 | - if ($context) { |
|
128 | - $block[] = new Text_Diff_Op_copy($context); |
|
129 | - } |
|
130 | - } |
|
131 | - $block[] = $edit; |
|
132 | - } |
|
133 | - |
|
134 | - if ($edit->orig) { |
|
135 | - $xi += count($edit->orig); |
|
136 | - } |
|
137 | - if ($edit->final) { |
|
138 | - $yi += count($edit->final); |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - if (is_array($block)) { |
|
143 | - $output .= $this->_block($x0, $xi - $x0, |
|
144 | - $y0, $yi - $y0, |
|
145 | - $block); |
|
146 | - } |
|
147 | - |
|
148 | - return $output . $this->_endDiff(); |
|
149 | - } |
|
150 | - |
|
151 | - function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) |
|
152 | - { |
|
153 | - $output = $this->_startBlock($this->_blockHeader($xbeg, $xlen, $ybeg, $ylen)); |
|
154 | - |
|
155 | - foreach ($edits as $edit) { |
|
156 | - switch (strtolower(get_class($edit))) { |
|
157 | - case 'text_diff_op_copy': |
|
158 | - $output .= $this->_context($edit->orig); |
|
159 | - break; |
|
160 | - |
|
161 | - case 'text_diff_op_add': |
|
162 | - $output .= $this->_added($edit->final); |
|
163 | - break; |
|
164 | - |
|
165 | - case 'text_diff_op_delete': |
|
166 | - $output .= $this->_deleted($edit->orig); |
|
167 | - break; |
|
168 | - |
|
169 | - case 'text_diff_op_change': |
|
170 | - $output .= $this->_changed($edit->orig, $edit->final); |
|
171 | - break; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - return $output . $this->_endBlock(); |
|
176 | - } |
|
177 | - |
|
178 | - function _startDiff() |
|
179 | - { |
|
180 | - return ''; |
|
181 | - } |
|
182 | - |
|
183 | - function _endDiff() |
|
184 | - { |
|
185 | - return ''; |
|
186 | - } |
|
187 | - |
|
188 | - function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
|
189 | - { |
|
190 | - if ($xlen > 1) { |
|
191 | - $xbeg .= ',' . ($xbeg + $xlen - 1); |
|
192 | - } |
|
193 | - if ($ylen > 1) { |
|
194 | - $ybeg .= ',' . ($ybeg + $ylen - 1); |
|
195 | - } |
|
196 | - |
|
197 | - // this matches the GNU Diff behaviour |
|
198 | - if ($xlen && !$ylen) { |
|
199 | - $ybeg--; |
|
200 | - } elseif (!$xlen) { |
|
201 | - $xbeg--; |
|
202 | - } |
|
203 | - |
|
204 | - return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; |
|
205 | - } |
|
206 | - |
|
207 | - function _startBlock($header) |
|
208 | - { |
|
209 | - return $header . "\n"; |
|
210 | - } |
|
211 | - |
|
212 | - function _endBlock() |
|
213 | - { |
|
214 | - return ''; |
|
215 | - } |
|
216 | - |
|
217 | - function _lines($lines, $prefix = ' ') |
|
218 | - { |
|
219 | - return $prefix . implode("\n$prefix", $lines) . "\n"; |
|
220 | - } |
|
221 | - |
|
222 | - function _context($lines) |
|
223 | - { |
|
224 | - return $this->_lines($lines, ' '); |
|
225 | - } |
|
226 | - |
|
227 | - function _added($lines) |
|
228 | - { |
|
229 | - return $this->_lines($lines, '> '); |
|
230 | - } |
|
231 | - |
|
232 | - function _deleted($lines) |
|
233 | - { |
|
234 | - return $this->_lines($lines, '< '); |
|
235 | - } |
|
236 | - |
|
237 | - function _changed($orig, $final) |
|
238 | - { |
|
239 | - return $this->_deleted($orig) . "---\n" . $this->_added($final); |
|
240 | - } |
|
107 | + $context = array_slice($edit->orig, 0, $ntrail); |
|
108 | + $block[] = new Text_Diff_Op_copy($context); |
|
109 | + } |
|
110 | + /* @todo */ |
|
111 | + $output .= $this->_block($x0, $ntrail + $xi - $x0, |
|
112 | + $y0, $ntrail + $yi - $y0, |
|
113 | + $block); |
|
114 | + $block = false; |
|
115 | + } |
|
116 | + } |
|
117 | + /* Keep the copy block as the context for the next block. */ |
|
118 | + $context = $edit->orig; |
|
119 | + } else { |
|
120 | + /* Don't we have any diff blocks yet? */ |
|
121 | + if (!is_array($block)) { |
|
122 | + /* Extract context lines from the preceding copy block. */ |
|
123 | + $context = array_slice($context, count($context) - $nlead); |
|
124 | + $x0 = $xi - count($context); |
|
125 | + $y0 = $yi - count($context); |
|
126 | + $block = array(); |
|
127 | + if ($context) { |
|
128 | + $block[] = new Text_Diff_Op_copy($context); |
|
129 | + } |
|
130 | + } |
|
131 | + $block[] = $edit; |
|
132 | + } |
|
133 | + |
|
134 | + if ($edit->orig) { |
|
135 | + $xi += count($edit->orig); |
|
136 | + } |
|
137 | + if ($edit->final) { |
|
138 | + $yi += count($edit->final); |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + if (is_array($block)) { |
|
143 | + $output .= $this->_block($x0, $xi - $x0, |
|
144 | + $y0, $yi - $y0, |
|
145 | + $block); |
|
146 | + } |
|
147 | + |
|
148 | + return $output . $this->_endDiff(); |
|
149 | + } |
|
150 | + |
|
151 | + function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) |
|
152 | + { |
|
153 | + $output = $this->_startBlock($this->_blockHeader($xbeg, $xlen, $ybeg, $ylen)); |
|
154 | + |
|
155 | + foreach ($edits as $edit) { |
|
156 | + switch (strtolower(get_class($edit))) { |
|
157 | + case 'text_diff_op_copy': |
|
158 | + $output .= $this->_context($edit->orig); |
|
159 | + break; |
|
160 | + |
|
161 | + case 'text_diff_op_add': |
|
162 | + $output .= $this->_added($edit->final); |
|
163 | + break; |
|
164 | + |
|
165 | + case 'text_diff_op_delete': |
|
166 | + $output .= $this->_deleted($edit->orig); |
|
167 | + break; |
|
168 | + |
|
169 | + case 'text_diff_op_change': |
|
170 | + $output .= $this->_changed($edit->orig, $edit->final); |
|
171 | + break; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + return $output . $this->_endBlock(); |
|
176 | + } |
|
177 | + |
|
178 | + function _startDiff() |
|
179 | + { |
|
180 | + return ''; |
|
181 | + } |
|
182 | + |
|
183 | + function _endDiff() |
|
184 | + { |
|
185 | + return ''; |
|
186 | + } |
|
187 | + |
|
188 | + function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
|
189 | + { |
|
190 | + if ($xlen > 1) { |
|
191 | + $xbeg .= ',' . ($xbeg + $xlen - 1); |
|
192 | + } |
|
193 | + if ($ylen > 1) { |
|
194 | + $ybeg .= ',' . ($ybeg + $ylen - 1); |
|
195 | + } |
|
196 | + |
|
197 | + // this matches the GNU Diff behaviour |
|
198 | + if ($xlen && !$ylen) { |
|
199 | + $ybeg--; |
|
200 | + } elseif (!$xlen) { |
|
201 | + $xbeg--; |
|
202 | + } |
|
203 | + |
|
204 | + return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; |
|
205 | + } |
|
206 | + |
|
207 | + function _startBlock($header) |
|
208 | + { |
|
209 | + return $header . "\n"; |
|
210 | + } |
|
211 | + |
|
212 | + function _endBlock() |
|
213 | + { |
|
214 | + return ''; |
|
215 | + } |
|
216 | + |
|
217 | + function _lines($lines, $prefix = ' ') |
|
218 | + { |
|
219 | + return $prefix . implode("\n$prefix", $lines) . "\n"; |
|
220 | + } |
|
221 | + |
|
222 | + function _context($lines) |
|
223 | + { |
|
224 | + return $this->_lines($lines, ' '); |
|
225 | + } |
|
226 | + |
|
227 | + function _added($lines) |
|
228 | + { |
|
229 | + return $this->_lines($lines, '> '); |
|
230 | + } |
|
231 | + |
|
232 | + function _deleted($lines) |
|
233 | + { |
|
234 | + return $this->_lines($lines, '< '); |
|
235 | + } |
|
236 | + |
|
237 | + function _changed($orig, $final) |
|
238 | + { |
|
239 | + return $this->_deleted($orig) . "---\n" . $this->_added($final); |
|
240 | + } |
|
241 | 241 | |
242 | 242 | } |
@@ -154,21 +154,21 @@ |
||
154 | 154 | |
155 | 155 | foreach ($edits as $edit) { |
156 | 156 | switch (strtolower(get_class($edit))) { |
157 | - case 'text_diff_op_copy': |
|
158 | - $output .= $this->_context($edit->orig); |
|
159 | - break; |
|
157 | + case 'text_diff_op_copy': |
|
158 | + $output .= $this->_context($edit->orig); |
|
159 | + break; |
|
160 | 160 | |
161 | - case 'text_diff_op_add': |
|
162 | - $output .= $this->_added($edit->final); |
|
163 | - break; |
|
161 | + case 'text_diff_op_add': |
|
162 | + $output .= $this->_added($edit->final); |
|
163 | + break; |
|
164 | 164 | |
165 | - case 'text_diff_op_delete': |
|
166 | - $output .= $this->_deleted($edit->orig); |
|
167 | - break; |
|
165 | + case 'text_diff_op_delete': |
|
166 | + $output .= $this->_deleted($edit->orig); |
|
167 | + break; |
|
168 | 168 | |
169 | - case 'text_diff_op_change': |
|
170 | - $output .= $this->_changed($edit->orig, $edit->final); |
|
171 | - break; |
|
169 | + case 'text_diff_op_change': |
|
170 | + $output .= $this->_changed($edit->orig, $edit->final); |
|
171 | + break; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * Constructor. |
35 | 35 | */ |
36 | - function __construct( $params = array() ) |
|
36 | + function __construct($params = array()) |
|
37 | 37 | { |
38 | 38 | foreach ($params as $param => $value) { |
39 | - $v = '_' . $param; |
|
39 | + $v = '_'.$param; |
|
40 | 40 | if (isset($this->$v)) { |
41 | 41 | $this->$v = $value; |
42 | 42 | } |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | /** |
47 | 47 | * PHP4 constructor. |
48 | 48 | */ |
49 | - public function Text_Diff_Renderer( $params = array() ) { |
|
50 | - self::__construct( $params ); |
|
49 | + public function Text_Diff_Renderer($params = array()) { |
|
50 | + self::__construct($params); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $context = $edit->orig; |
119 | 119 | } else { |
120 | 120 | /* Don't we have any diff blocks yet? */ |
121 | - if (!is_array($block)) { |
|
121 | + if ( ! is_array($block)) { |
|
122 | 122 | /* Extract context lines from the preceding copy block. */ |
123 | 123 | $context = array_slice($context, count($context) - $nlead); |
124 | 124 | $x0 = $xi - count($context); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $block); |
146 | 146 | } |
147 | 147 | |
148 | - return $output . $this->_endDiff(); |
|
148 | + return $output.$this->_endDiff(); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - return $output . $this->_endBlock(); |
|
175 | + return $output.$this->_endBlock(); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | function _startDiff() |
@@ -188,25 +188,25 @@ discard block |
||
188 | 188 | function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
189 | 189 | { |
190 | 190 | if ($xlen > 1) { |
191 | - $xbeg .= ',' . ($xbeg + $xlen - 1); |
|
191 | + $xbeg .= ','.($xbeg + $xlen - 1); |
|
192 | 192 | } |
193 | 193 | if ($ylen > 1) { |
194 | - $ybeg .= ',' . ($ybeg + $ylen - 1); |
|
194 | + $ybeg .= ','.($ybeg + $ylen - 1); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | // this matches the GNU Diff behaviour |
198 | - if ($xlen && !$ylen) { |
|
198 | + if ($xlen && ! $ylen) { |
|
199 | 199 | $ybeg--; |
200 | - } elseif (!$xlen) { |
|
200 | + } elseif ( ! $xlen) { |
|
201 | 201 | $xbeg--; |
202 | 202 | } |
203 | 203 | |
204 | - return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; |
|
204 | + return $xbeg.($xlen ? ($ylen ? 'c' : 'd') : 'a').$ybeg; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | function _startBlock($header) |
208 | 208 | { |
209 | - return $header . "\n"; |
|
209 | + return $header."\n"; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function _endBlock() |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | function _lines($lines, $prefix = ' ') |
218 | 218 | { |
219 | - return $prefix . implode("\n$prefix", $lines) . "\n"; |
|
219 | + return $prefix.implode("\n$prefix", $lines)."\n"; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | function _context($lines) |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | function _changed($orig, $final) |
238 | 238 | { |
239 | - return $this->_deleted($orig) . "---\n" . $this->_added($final); |
|
239 | + return $this->_deleted($orig)."---\n".$this->_added($final); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | } |