Changeset 8540 for trunk/wp-includes/formatting.php
- Timestamp:
- 08/04/2008 09:01:09 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/formatting.php
r8525 r8540 1421 1421 } 1422 1422 1423 /** 1424 * Add a Base url to relative links in passed content. 1425 * 1426 * By default it supports the 'src' and 'href' attributes, 1427 * However this may be changed via the 3rd param. 1428 * 1429 * @package WordPress 1430 * @since 2.7 1431 * 1432 * @param string $content String to search for links in 1433 * @param string $base The base URL to prefix to links 1434 * @param array $attrs The attributes which should be processed. 1435 * @eaturn string The processed content. 1436 */ 1437 function links_add_base_url( $content, $base, $attrs = array('src', 'href') ) { 1438 $attrs = implode('|', (array)$attrs); 1439 return preg_replace_callback("!($attrs)=(['\"])(.+?)\\2!i", 1440 create_function('$m', 'return _links_add_base($m, "' . $base . '");'), 1441 $content); 1442 } 1443 1444 /** 1445 * Callback to add a base url to relative links in passed content. 1446 * 1447 * 1448 * @package WordPress 1449 * @since 2.7 1450 * 1451 * @internal 1452 * @param string $m The matched link 1453 * @param string $base The base URL to prefix to links 1454 * @eaturn string The processed link 1455 */ 1456 function _links_add_base($m, $base) { 1457 //1 = attribute name 2 = quotation mark 3 = URL 1458 return $m[1] . '=' . $m[2] . 1459 (strpos($m[3], 'http://') === false ? 1460 path_join($base, $m[3]) : 1461 $m[3]) 1462 . $m[2]; 1463 } 1464 1465 /** 1466 * Adds a Target attribute to all links in passed content. 1467 * 1468 * This function by default only applies to <a> tags, 1469 * however this can be modified by the 3rd param. 1470 * NOTE: Any current target attributed will be striped and replaced. 1471 * 1472 * @package WordPress 1473 * @since 2.7 1474 * 1475 * @param string $content String to search for links in 1476 * @param string $target The Target to add to the links 1477 * @param array $tags An array of tags to apply to. 1478 * @eaturn string The processed content. 1479 */ 1480 function links_add_target( $content, $target = '_blank', $tags = array('a') ) { 1481 $tags = implode('|', (array)$tags); 1482 return preg_replace_callback("!<($tags)(.+?)>!i", 1483 create_function('$m', 'return _links_add_target($m, "' . $target . '");'), 1484 $content); 1485 } 1486 /** 1487 * Callback to add a target attribute to all links in passed content 1488 * 1489 * 1490 * @package WordPress 1491 * @since 2.7 1492 * 1493 * @internal 1494 * @param string $m The matched link 1495 * @param string $target The Target to add to the links 1496 * @eaturn string The processed link. 1497 */ 1498 function _links_add_target( $m, $target ) { 1499 $tag = $m[1]; 1500 $link = preg_replace('|(target=[\'"](.*?)[\'"])|i', '', $m[2]); 1501 return '<' . $tag . $link . ' target="' . $target . '">'; 1502 } 1503 1423 1504 ?>
Note: See TracChangeset
for help on using the changeset viewer.