diff options
author | Dries Buytaert <dries@buytaert.net> | 2006-03-10 18:59:05 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2006-03-10 18:59:05 +0000 |
commit | f5fff25e6fdfccf7eb9ff1e1d2b4500b532546ff (patch) | |
tree | 6a8cbafe02fff59579650db0e82e839781e3d5dc /database | |
parent | e4a6ff42700316af10b9eac09e68292a3f74347a (diff) | |
download | brdo-f5fff25e6fdfccf7eb9ff1e1d2b4500b532546ff.tar.gz brdo-f5fff25e6fdfccf7eb9ff1e1d2b4500b532546ff.tar.bz2 |
- Patch #13148 by Matt: upgrade path for relative links.
Diffstat (limited to 'database')
-rw-r--r-- | database/updates.inc | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/database/updates.inc b/database/updates.inc index c96972601..8dcdff8ca 100644 --- a/database/updates.inc +++ b/database/updates.inc @@ -1700,3 +1700,71 @@ function system_update_177() { return $ret; } +function _update_178_url_fix($text) { + //key is attribute to replace. + $urlpatterns['href'] = "/<a[^>]+href=\"([^\"]+)/i"; + $urlpatterns['src'] = "/<img[^>]+src=\"([^\"]+)/i"; + + foreach ($urlpatterns as $type => $pattern) { + preg_match_all($pattern, $text, $matches); + foreach($matches[1] as $url) { + if ($url != '' && !strstr($url, 'mailto:') && !strstr($url, '://') && !strstr($url, '../') && !strstr($url, './') && $url[0] != '/' && $url[0] != '#') { + $text = preg_replace('|'. $type .'\s*=\s*"'. preg_quote($url) .'\s*"|', $type. '="'.base_path(). $url .'"', $text); + } + } + } + return $text; +} + +/** + * Update base paths for relative URLs in node and comment content. + */ +function system_update_178() { + + if(variable_get('clean_url', 0) == 1) { + // Multi-part update + if (!isset($_SESSION['system_update_178_comment'])) { + $_SESSION['system_update_178_comment'] = 0; + $_SESSION['system_update_178_node'] = 0; + $_SESSION['system_update_178_comment_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments}')); + $_SESSION['system_update_178_node_max'] = db_result(db_query('SELECT MAX(nid) FROM {node_revisions}')); + } + + $limit = 20; + $result = db_query_range("SELECT cid, comment FROM {comments} WHERE cid > %d", $_SESSION['system_update_178_comment'], 0, $limit); + while ($comment = db_fetch_object($result)) { + $_SESSION['system_update_178_comment'] = $comment->cid; + $comment->comment = _update_178_url_fix($comment->comment); + db_query("UPDATE {comments} SET comment = '%s' WHERE cid = %d", $comment->comment, $comment->cid); + } + + $result = db_query_range("SELECT nid, vid, teaser, body FROM {node_revisions} WHERE nid > %d", $_SESSION['system_update_178_node'], 0, $limit); + while ($node = db_fetch_object($result)) { + // Catch the infinite loop for node revisions. We ignore updating + // content past the 20th revision. + if ($_SESSION['system_update_178_node'] == $node->nid) { + $_SESSION['system_update_178_node']++; + } + else { + $_SESSION['system_update_178_node'] = $node->nid; + } + $node->teaser = _update_178_url_fix($node->teaser); + $node->body = _update_178_url_fix($node->body); + db_query('UPDATE {node_revisions} SET body = "%s", teaser = "%s" WHERE nid = %d AND vid = %d', $node->body, $node->teaser, $node->nid, $node->vid); + } + + if ($_SESSION['system_update_178_comment'] == $_SESSION['system_update_178_comment_max'] && + $_SESSION['system_update_178_node'] == $_SESSION['system_update_178_node_max']) { + unset($_SESSION['system_update_178_comment']); + unset($_SESSION['system_update_178_comment_max']); + unset($_SESSION['system_update_178_node']); + unset($_SESSION['system_update_178_node_max']); + return array(); + } + else { + return array('#finished' => FALSE); + } + } + + return array(); +} |