'fieldset',
'#title' => t("Link Node codes"),
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
$form['filter_link_node']['link_node'] = array(
'#type' => 'item',
'#title' => t('Instructions'),
'#value' => t('This filter translates special node tags into links to other nodes.
Syntax: [node:node_id,title="val2"]; every param but node_id is optional.
Each list below should be a comma separated list (no spaces) of what node properties users are
allowed to override for the purposes of displaying a node. E.g. title,border')
);
foreach (node_get_types() as $type => $name) {
$form['filter_link_node']["link_node_allowed_vars_$type"] = array(
'#type' => 'textfield',
'#title' => t("Allowed parameters for %type nodes", array('%type' => $type)),
'#default_value' => variable_get("link_node_allowed_vars_$type", ""),
'#size' => 40,
'#maxlength' => 256
);
}
return $form;
}
/**
* Actually execute filter on given text.
* Parse text for all meta tags.
* Lookup each specified node.
* Parse all parameters specified in each meta tag and apply them to the corresponding node.
* Replace meta tag with themed thumbnail view of the referrent node.
*/
function link_node_filter_process($text, $show_error_msgs=1) {
if (variable_get("link_node_enabled", 1)) {
// *** [node:NID,a="b",c="d",width="40",etc="foo"] ***
// first we find every tag
$meta_tag_regexp = '/\[node:(\d+)([^\]]*)\]/i';
if (preg_match_all($meta_tag_regexp, $text, $match)) {
// then we make the html
foreach ($match[1] as $key => $nid) {
if (module_exists('i18n') && module_exists('translation')) {
$lang = i18n_get_lang();
$transnids = translation_node_get_translations($nid);
if ($transnids[$lang]) {
$nid = $transnids[$lang]->nid;
}
}
$node = node_load(array("nid" => $nid));
if ($node) {
// check here to see if user has permissions to access this node
if (!node_access("view", $node)) {
$matches_html[$key] = t('You do not have access to view this node');
continue;
}
$meta_tag_params_regexp = '/,\s*([\w_-]+)\s*=\s*"([^"]+)"\s*/';
$meta_tag_params_regexp2 = '/,\s*([\w_-]+)\s*=\s*"([^,]+)"\s*/';
if ( preg_match_all($meta_tag_params_regexp, $match[2][$key], $parm_match) == 0 ) {
$meta_tag_params_regexp=$meta_tag_params_regexp2 ;
}
if (preg_match_all($meta_tag_params_regexp, $match[2][$key], $parm_match)) {
$allowed_vars = explode(',', variable_get("link_node_allowed_vars_$node->type", ""));
for ($i=0; $i Nodes That Link To Other Nodes
You can link nodes to other nodes using the following syntax:
Some examples: Currently available parameters:". variable_get("link_node_allowed_vars_$node->type", "") ."'.");
}
}
}
}
#$matches_html[$key] = theme("link_node_thumbnail", $node);
# issue 772894 workaround for broken PHP5.3 ?
$matches_html[$key] = theme_link_node_thumbnail($node);
}
else {
if ($show_error_msgs) {
$matches_html[$key] = theme("link_node_format", t("Nonexistent node nid: ") ."$nid.");
}
else {
$matches_html[$key] = "";
}
}
}
// PHP (4.3.2) str_replace appears to use some internal order
// rather than array index when finding replace elements
// corresponding to search elements. To make sure that the
// order of the arrays correspond, we make new copies here.
foreach ($match[1] as $key => $value) {
$mtch[] = $match[0][$key];
$repl[] = $matches_html[$key];
}
$text = str_replace($mtch, $repl, $text);
}
}
return $text;
}
/**
* Generates a thumbnail view of a node.
*/
function theme_link_node_thumbnail(&$node) {
$main = TRUE;
if ($node->type == "image") {
// offer theme developers and module developers to override this
if (function_exists("image_link_node_thumbnail")) {
return image_link_node_thumbnail($node);
}
}
$output = l($node->title, drupal_get_path_alias('node/'. $node->nid), array('absolute' => TRUE) );
return $output;
}
/**
* Puts a box around the attached_node's content
*/
function theme_link_node_format($content) {
return '
[node:node_id,title="val1"]
[node:123]
[node:123,title="original"]
');
foreach (node_get_types() as $type => $name) {
$output .= "
\n";
}
$output .= t('". t("Allowed parameters for $type nodes: ") ." ". variable_get("link_node_allowed_vars_$type", "") ."
Site admin: If there are properties of a node that you want to allow your users to modify when referring to them, you can specify those in the filter configuration.
'); break; } return $output; } /** * Implementation of hook_filter_tips(). */ function link_node_filter_tips($delta, $format, $long = FALSE) { if ($long) { $txt = t('Linking Nodes To Other Nodes
You can link nodes to other nodes using the following syntax:
[node:node_id,title="val2"]
Some examples:
[node:123]
[node:123,title="original"]
Currently available parameters:
| ". t("Allowed parameters for $type nodes: ") ." | ". variable_get("link_node_allowed_vars_$type", "") ." |
Site admin: If there are properties of a node that you want to allow your users to modify when referring to them, you can specify those in the filter configuration.
'); return $txt; } else { return t('You can link nodes to other nodes using the following syntax: