When I do not set a class on admin/build/alinks/edit, and I go to a node that has alinks inside it, the module still tries to apply a style to it. If I go to view the source-code, I can see <a href=example.com class="" ....>alink example</a>. This is breaking some of our CSS.

Comments

DavidWhite’s picture

Certainly this isn't the cleanest way to do this, but it works. I nested another if/else statement into two of the current if/else statements, and it works. I also cleaned up the code a little and got rid of some unnecessary (old?) code.

		if ($word['alink_external'] == 1) {
        	if ($aword['alink_class'] != "") {
          		$alink_url[] = l('alink_check\1alink_check', 
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check', 
                           array(
	                           'attributes' =>array('class' => 'alink_check'.str_replace(' ', 'alink_space', $word['alink_class']).'alink_check', 
		                                            'title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
		                          
		                       'absolute' => true
	                       		)
                           );
       	 		}
			else {
	          $alink_url[] = l('alink_check\1alink_check', 
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check', 
                           array(
	                           'attributes' =>array('title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
		                        
		                       'absolute' => true
	                       		)
                           );
        		}		
			}

        else {
        	if ($aword['alink_class'] != "") {
          		$alink_url[] = l('alink_check\1alink_check', 
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check', 
                           array(
	                           'attributes' =>array('class' => 'alink_check'.str_replace(' ', 'alink_space', $word['alink_class']).'alink_check', 
		                                            'title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
		                          
		                       'absolute' => true
	                       		)
                           );
       	 	}
			else {
	          $alink_url[] = l('alink_check\1alink_check', 
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check', 
                           array(
	                           'attributes' =>array('title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
		                        
		                       'absolute' => true
	                       		)
                           );
        		}		
			}
DavidWhite’s picture

There's a silly mistake in my code - take out the last 'absolute' => true. Here's the corrected code, with a little context. My own code starts at line 172 of the module:

      if ($word['alink_url'] != $url) {
        $alink_start_boundary = ($word['alink_start_boundary'] == 1) ? 'B' : 'b';
        $alink_end_boundary = ($word['alink_end_boundary'] == 1) ? 'B' : 'b';
        $alink_case_insensivity = ($word['alink_case_insensitive'] == 1) ? 'i' : '';
        $word['alink_text'] = htmlspecialchars($word['alink_text']);
        $alink_text[] = '$\\' . $alink_start_boundary . '(' . preg_quote($word['alink_text'], '$') . ')\\' . $alink_end_boundary . '$' . $alink_case_insensivity;
        if ($word['alink_external'] == 1) {
            if ($aword['alink_class'] != "") {
                  $alink_url[] = l('alink_check\1alink_check',
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check',
                           array(
                               'attributes' =>array('class' => 'alink_check'.str_replace(' ', 'alink_space', $word['alink_class']).'alink_check',
                                                    'title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
                                 
                               'absolute' => true
                                   )
                           );
                    }
            else {
              $alink_url[] = l('alink_check\1alink_check',
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check',
                           array(
                               'attributes' =>array('title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
                               
                               'absolute' => true
                                )
                           );
                }       
            }

        else {
            if ($aword['alink_class'] != "") {
                  $alink_url[] = l('alink_check\1alink_check',
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check',
                           array(
                               'attributes' =>array('class' => 'alink_check'.str_replace(' ', 'alink_space', $word['alink_class']).'alink_check',
                                                    'title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
                                 )
                           );
                }
            else {
              $alink_url[] = l('alink_check\1alink_check',
                           str_replace($links_chars, $links_chars_replace, $word['alink_url']) . 'alink_check',
                           array(
                               'attributes' =>array('title' => 'alink_check' . str_replace(' ', 'alink_space', check_plain($word['url_title'])) . 'alink_check'),
                                )
                           );
                }       
            }
        $i++;
greg boggs’s picture

This code is a jumbled mess. Anyone want to create a patch off the latest 7.x dev release

The logic would be a lot more maintainable and readable like:
Check values, assign attributes to an attributes variable as needed, create replacement based on $attributes[].

greg boggs’s picture

Version: 6.x-1.0-rc1 » 7.x-1.x-dev
Issue summary: View changes
Status: Active » Needs work
greg boggs’s picture

Status: Needs work » Closed (fixed)

I rewrote the link rewrite to conditionally rewrite the values of the link. This fixes both bad class and title tags when none are provided.