Index: linodef.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/linodef/linodef.module,v retrieving revision 1.1.2.12 diff -u -r1.1.2.12 linodef.module --- linodef.module 17 Dec 2009 23:23:04 -0000 1.1.2.12 +++ linodef.module 29 Dec 2009 01:30:52 -0000 @@ -10,6 +10,7 @@ define('LINODEF_FORMAT_TITLE_NODE', t('Node') . ' [nid]: [title]'); define('LINODEF_FORMAT_TITLE_TERM', t('Shows a teaser list of nodes using term !term', array('!term' => '[cat-raw]'))); define('LINODEF_FORMAT_TITLE_VIEW', t('Show !view', array('!view' => '[viewname]'))); +define('LINODEF_JOKER', '~'); /** * @file @@ -55,6 +56,7 @@ case 'process': // Check if the current node is in teaser of full view. + // Major downside of this method: In a view teaser is set always. $buildmode = (arg(0) == 'node' && is_numeric(arg(1))) ? 'full' : 'teaser'; define('LINODEF_BUILDMODE', $buildmode); @@ -129,6 +131,55 @@ } /** + * Implementation of hook_nodeapi. + * + * Load joker replacements on node load. + */ +function linodef_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { + switch ($op) { + case 'load': + // No replacement when editing or adding translation. + if (arg(0) == 'node' && (arg(2) == 'edit' || arg(1) == 'add')) { + break; + } + // Debug: print('
');print_r($node);print('
'); + // Alter body & teaser. Check if linodef is set in the used format. + if (array_key_exists('linodef/0', filter_list_format($node->format))) { + $node->body = linodef_joker($node->body, $node); + $node->teaser = linodef_joker($node->teaser, $node); + } + // Alter fields. + foreach($node as $key => &$value) { + // Check each field. + if (substr($key, 0, 6) == 'field_' && isset($value[0]['format'])) { + // Check each field value. + foreach ($value as &$field) { + // Check if linodef is set for the current field format. + if (array_key_exists('linodef/0', filter_list_format($field['format'])) && !empty($field['value'])) { + // Replace. + $field['value'] = linodef_joker($field['value'], $node); + } + } + } + } + break; + } +} + +/** + * Replaces the joker character with content. + */ +function linodef_joker($text, $node) { + $joker = array( + // Add id of current node. + '[#' . LINODEF_JOKER => '[#' . $node->nid, + // Add language of current node. + ',translation="' . LINODEF_JOKER . '"' => ',translation="' . $node->language . '"', + ); + return str_replace(array_keys($joker), array_values($joker), $text); +} + +/** * Implementation of hook_filter_tips. */ function linodef_filter_tips($delta, $format, $long = FALSE) {