*** freelinking/freelinking.module 2008-12-17 11:58:39.000000000 -0800 --- freelinking.module 2009-01-23 15:50:26.000000000 -0800 *************** *** 274,279 **** --- 274,285 ---- '#default_value' => variable_get("freelinking_camelcase", 0), '#description' => t('If desired, you can enable CamelCase linking'), ); + $form["freelinking_images"] = array( + '#title' => t('Change Image Links to Images'), + '#type' => 'checkbox', + '#default_value' => variable_get("freelinking_images", 0), + '#description' => t('If an image node is linked, display the image instead of the node title.'), + ); $form["freelinking_onceonly"] = array( '#title' => t('Only link first occurance'), '#type' => 'checkbox', *************** *** 451,456 **** --- 457,463 ---- function _freelinking_do_filtering($text, $store = FALSE) { $allowcamelcase = variable_get("freelinking_camelcase", TRUE); + $displayimages = variable_get("freelinking_images", TRUE); $freelinkingregexp = '/[^!](\[\[.+]])/Uu'; // this finds [[links like this]], un-greedily and utf-8 preg_match_all($freelinkingregexp, $text, $flmatches, PREG_PATTERN_ORDER); if ($allowcamelcase) { *************** *** 476,482 **** $store = FALSE; } else { ! $replacement = l(html_entity_decode($phrase), 'freelinking/' . rawurlencode($freelink), array('attributes' => array('class' => 'freelinking'))); } } --- 483,494 ---- $store = FALSE; } else { ! if($displayimages) $imgtag = _freelinking_get_image_preview($phrase); ! if(!$imgtag || !$displayimages) { ! $replacement = l(html_entity_decode($phrase), 'freelinking/' . rawurlencode($freelink), array('attributes' => array('class' => "freelinking"))); ! } else { ! $replacement = l($imgtag, 'freelinking/' . rawurlencode($freelink), array('attributes' => array('class' => 'freelinking freelinking_image'), 'html' => TRUE)); ! } } } *************** *** 546,551 **** --- 558,580 ---- return (empty($nid) ? 0 : $nid); } + function _freelinking_get_image_preview($thetitle) { + // If the node is an image, this function returns an image tag to the preview. + // Otherwise, it returns FALSE + $nid = _freelinking_exists($thetitle); + + // Note: This is inefficient, since we already loaded the node in _freelinking_exists, + // but I'm concentrating on code re-use. + $node = node_load($nid); + if($node->type == 'image') { + $preview_link = base_path() . $node->images['preview']; + $imgtag = "$thetitle"; + return $imgtag; + } else { + return FALSE; + } + } + function _freelinking_make_link($thetitle) { // helper function for freelinking_page global $user; $freelink = array('options' => array()); // ensure that 'options' is an array