<commit_before><?php
/**
 * Rewrites anchor links in email content with a link to a controller which
 * tracks the click and then redirects the user.
 *
 * @package silverstripe-newsletter-tracking
 */
class NewsletterEmailLinkTrackingExtension extends Extension {

	public function onBeforeSend() {
		$email  = $this->owner;
		$letter = $email->Newsletter();
		$body   = new SS_HTMLValue($email->Body()->forTemplate());
		$links  = array();
		$member = null;

		if (!$body || !$letter) {
			return;
		}

		if ($email->To()) {
			$member = DataObject::get_one('Member', sprintf(
				'"Email" = \'%s\'', Convert::raw2sql($email->To())
			));
		}

		// First build up a set of all the unique links within the newsletter,
		// along with the elements that link to them.
		foreach ($body->getElementsByTagName('a') as $link) {
			$href = $link->getAttribute('href');

			// ignore links with keywords
			if ((strpos($href, '{$') !== false) || (strpos($href, 'mailto:') !== false)) {<commit_msg>Don't rewrite links without a href attribute.<commit_after><?php
/**
 * Rewrites anchor links in email content with a link to a controller which
 * tracks the click and then redirects the user.
 *
 * @package silverstripe-newsletter-tracking
 */
class NewsletterEmailLinkTrackingExtension extends Extension {

	public function onBeforeSend() {
		$email  = $this->owner;
		$letter = $email->Newsletter();
		$body   = new SS_HTMLValue($email->Body()->forTemplate());
		$links  = array();
		$member = null;

		if (!$body || !$letter) {
			return;
		}

		if ($email->To()) {
			$member = DataObject::get_one('Member', sprintf(
				'"Email" = \'%s\'', Convert::raw2sql($email->To())
			));
		}

		// First build up a set of all the unique links within the newsletter,
		// along with the elements that link to them.
		foreach ($body->getElementsByTagName('a') as $link) {
			if(!$link->hasAttribute('href')) {
				continue;
			}

			$href = $link->getAttribute('href');

			// ignore links with keywords
			if ((strpos($href, '{$') !== false) || (strpos($href, 'mailto:') !== false)) {
{'fraction_non_alphanumeric': 0.17053140096618358, 'fraction_numerical': 0.000966183574879227, 'mean_word_length': 3.7939814814814814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6436510', 'n_tokens_mistral': 712, 'n_tokens_neox': 635, 'n_words': 190}