You are here

function _site_disclaimer_checkbox_label_substitute_links in Site Disclaimer 6

Same name and namespace in other branches
  1. 7 site_disclaimer.module \_site_disclaimer_checkbox_label_substitute_links()

Go through the $checkbox_label string, replacing each @"Terms Link" with an actual node link

Parameters

$checkbox_label: The label from the admin form saved in the DB.

$linked_nodes: (Optional) return an array of all linked node nids.

$linked_errors: (Optional) return an array of all linked node errors.

Return value

Substituted text output.

3 calls to _site_disclaimer_checkbox_label_substitute_links()
site_disclaimer_admin_settings_validate in ./site_disclaimer.admin.inc
Validate the site_disclaimer_admin_settings form.
theme_site_disclaimer_checkbox_label in ./site_disclaimer.module
Theme the Site Disclaimer checkbox label.
_site_disclaimer_prep_allowed_paths in ./site_disclaimer.admin.inc
Create 'site_disclaimer_allow_nodes' variable from links found in:

File

./site_disclaimer.module, line 119
This module adds Site Disclaimer to the registration page.

Code

function _site_disclaimer_checkbox_label_substitute_links($checkbox_label, &$linked_nodes = NULL, &$linked_errors = NULL) {
  $linked_nodes = array();
  $linked_errors = array();

  // Go through the $output string, replacing @"Terms Link" with an actual node link
  $output = str_replace('"', '"', $checkbox_label);
  $i = 0;
  while ($i < drupal_strlen($output)) {
    if (drupal_substr($output, $i, 2) == '@"') {
      $start = $i + 2;
      $end = strpos($output, '"', $start);
      while (drupal_substr($output, $end - 1, 1) == "\\") {
        $end = strpos($output, '"', $end + 1);
      }
      $title = drupal_substr($output, $start, $end - $start);
      $node = node_load(array(
        'title' => str_replace('\\"', '"', $title),
      ));
      if (empty($node)) {
        $linked_errors[$title] = t('No post was found with "!title" title.', array(
          '!title' => $title,
        ));
      }
      else {
        $linked_nodes[] = $node->nid;
        $link = l($node->title, 'node/' . $node->nid);
        $output = str_replace('@"' . $title . '"', $link, $output);
        $i += drupal_strlen($link) - 1;
      }
    }
    $i++;
  }
  return $output;
}