The best method, in hindsight, is to ensure folks use Drupal functions to make all links:
l
(that's the letter L)
drupal_get_path()
base_path()
The l()
function takes care of base path worries, and provides a systematic way to define your URL's. Using things like theme_image()
plus the l()
function are a sure win. Use the second and third functions above if you have to write your own <a>
tags and for use inside theme functions like theme_image()
.
But for your current situation:
As regards Andy's solution, it would be better if you could limit your changes to certain database fields where you know the links are located.
So write a query to select all those fields (e.g. all body fields):
$my_query = db_query("SELECT vid, body FROM {node_revisions}");
This, for example, will get you every body
field in the node_revisions
table, so even your old revisions would have proper links.
Then run through those results, do str_replace()
on each, and then write the changes back:
while($node = db_fetch_object($my_query)) {
$new_body = str_replace('what you have', 'what you want', $node->body);
db_query("UPDATE {node_revisions} SET body = '%s' WHERE vid = %d", $new_body, $node->vid);
}
I'd obviously try it on one record first, to make sure your code behaves as intended (just add a WHERE vid = 5
, for example, to narrow it down to one revision). Furthermore, I haven't taken advantage of node_load
and node_save
, which are better for loading and saving nodes properly, so as to provide a more general solution (for you to replace text in blocks, etc.).
For your files, I'd suggest a good ol' sed
command, by running something like the following from within your "sites" folder:
find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;
Nabbed that from here, so take a look on that site for more explanation. If you're going to be working with paths, you'll either need to escape the /
of the paths in your version of the sed
command, or use a different sed
separator (i.e. you can write s#string1#string2#
instead of s/string1/string2/
, so you could write s#/drupalsite/img/#/img#
instead of s/\/drupalsite\/img\//\/img/
:-). See also Drupal handbook page for quick sed
commands: http://drupal.org/node/128513.
A bit of a mess, which is why I try to enforce using the proper functions up front. But this is difficult if you want themers to create Drupal content but you don't want to give them access to the "PHP Filter" input format, or they simply don't know PHP. Proper Drupal theming, at any point past basic HTML/CSS work, requires a knowledge of PHP and Drupal's theme-related functions.