You are here

function _pathfilter_replace_links in Path Filter 6.2

Same name and namespace in other branches
  1. 5.2 pathfilter.module \_pathfilter_replace_links()

Replaces the links in select node properties (body, teaser, and any textfields that have formatting defined for them)

$node : StdClass Object $func_name : String Can be either _pathfilter_internalize or _pathfilter_replace_internal both functions replace links, one is before saving and one is before viewing

1 call to _pathfilter_replace_links()
pathfilter_nodeapi in ./pathfilter.module
Modifies submitted node body values. Replaces base_path() in images, hrefs, etc with 'internal:' on save. When editing a node, the body's 'internal:' strings are replaced with 'base_path()'.

File

./pathfilter.module, line 224
This filter takes internal Drupal paths in double quotes, written as e.g. "internal:node/99", and replaces them with the appropriate absolute http URL using Drupal's url() function [1]. E.g. for a site located at http://example.com/mysite

Code

function _pathfilter_replace_links(&$node, $func_name) {

  // If we have our pathfilter variable defined let's replace otherwise bail out.
  if (variable_get('pathfilter_process_all', 1)) {

    // Let's get all the pathfilters we have defined and their corresponding formats.
    $defined_formats = array();
    $result = db_query("SELECT format FROM {filters} WHERE module = 'pathfilter'");
    while ($row = db_fetch_object($result)) {
      $defined_formats[] = $row->format;
    }

    // Iterate through our objects properties looking for body, teaser, and any fields that have
    // formatting defined for them.
    foreach ($node as $key => &$value) {

      //if this is the body or teaser lets run our replaces
      if ($key == "body" || $key == "teaser") {
        if (in_array($node->format, $defined_formats)) {
          $func_name($node->format, $value);
        }
      }
      elseif (is_array($value)) {

        // Look at the rest of the fields...if they have a format from our defined formats list
        // and we have a value that is a string run our replace...otherwise ignore them
        if (isset($value[0]) && is_array($value[0]) && !empty($value[0]['format']) && in_array($value[0]['format'], $defined_formats) && !empty($value[0]['value']) && is_string($value[0]['value'])) {
          $func_name($value[0]['format'], $value[0]['value']);
        }
      }
    }
  }
}