Skip to content
wiki.fftac.org

Antichrist Content System Implementation - Source Excerpt 30

Back to Antichrist Content System Implementation

Summary

This source excerpt preserves a bounded section of Antichrist.net/wp-content/plugins/antichrist-content-system/includes/antichrist-content-system-implementation.php so readers can inspect the evidence without opening the full source file.

**Source path:** Antichrist.net/wp-content/plugins/antichrist-content-system/includes/antichrist-content-system-implementation.php

/**
 * Render card grid.
 *
 * @param array $cards Cards.
 * @return string
 */
function acn_cs_card_grid( $cards ) {
	$html = '<div class="section-directory-grid">';
	foreach ( $cards as $card ) {
		$label = isset( $card['label'] ) ? $card['label'] : 'Open';
		$html .= acn_cs_card_markup( $card['path'], $card['title'], $card['text'], $label );
	}
	$html .= '</div>';
	return $html;
}

/**
 * Render source cards by filename.
 *
 * @param array $filenames Filenames.
 * @return string
 */
function acn_cs_source_file_cards_by_name( $filenames ) {
	return '';
}

/**
 * Render a linked card.
 *
 * @param string $path Path.
 * @param string $title Title.
 * @param string $text Text.
 * @param string $label Label.
 * @return string
 */
function acn_cs_card_markup( $path, $title, $text, $label ) {
	return sprintf(
		'<a class="section-directory-card" href="%1$s"><span class="kicker">%4$s</span><strong>%2$s</strong><span>%3$s</span></a>',
		esc_url( home_url( '/' . trim( $path, '/' ) . '/' ) ),
		esc_html( $title ),
		esc_html( $text ),
		esc_html( $label )
	);
}

/**
 * Render source note.
 *
 * @param array $sources Source filenames.
 * @return string
 */
function acn_cs_source_note( $sources ) {
	return '';
}

/**
 * Shortcode for rendering a whitelisted handoff source file.
 *
 * @param array $atts Shortcode attributes.
 * @return string
 */
function acn_cs_handoff_source_shortcode( $atts ) {
	$atts = shortcode_atts(
		array(
			'file' => '',
		),
		$atts,
		'acn_handoff_source'
	);

	$file = sanitize_text_field( $atts['file'] );
	if ( ! acn_cs_is_allowed_source_file( $file ) ) {
		return '<div class="source-doc"><p class="missing-source">This source note is under editorial review.</p></div>';
	}

	$path = acn_cs_handoff_file_path( $file );
	if ( ! is_readable( $path ) ) {
		return '<div class="source-doc"><p class="missing-source">This source note is under editorial review.</p></div>';
	}

	$markdown = file_get_contents( $path );
	if ( false === $markdown ) {
		return '<div class="source-doc"><p class="missing-source">This source note is under editorial review.</p></div>';
	}

	return '<article class="source-doc">' . acn_cs_markdown_to_html( $markdown ) . '</article>';
}

/**
 * Handoff directory.
 *
 * @return string
 */
function acn_cs_handoff_dir() {
	$dirs = acn_cs_handoff_dirs();
	return empty( $dirs ) ? '' : $dirs[0];
}

/**
 * Candidate handoff directories, compatible with regular plugin and mu-plugin paths.
 *
 * @return array
 */
function acn_cs_handoff_dirs() {
	$roots = array_unique(
		array(
			dirname( __DIR__, 4 ),
			dirname( __DIR__, 3 ),
			dirname( __DIR__, 2 ),
		)
	);
	$dirs  = array();

	foreach ( $roots as $root ) {
		$handoff = $root . DIRECTORY_SEPARATOR . 'agent-file-handoff';
		if ( ! is_dir( $handoff ) ) {
			continue;
		}

		$candidates = array(
			$handoff . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . '2026-05-13-content-user-seo' . DIRECTORY_SEPARATOR . 'Content',
			$handoff . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . '2026-05-13-content-user-seo' . DIRECTORY_SEPARATOR . 'Improvement',
			$handoff . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . '2026-05-13-content-user-seo',
			$handoff . DIRECTORY_SEPARATOR . 'Content',
			$handoff . DIRECTORY_SEPARATOR . 'Improvement',
			$handoff . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . '2026-05-12-improvement',
		);

		foreach ( $candidates as $candidate ) {
			if ( is_dir( $candidate ) && ! in_array( $candidate, $dirs, true ) ) {
				$dirs[] = $candidate;
			}
		}
	}

	return $dirs;
}

/**
 * Resolve a whitelisted handoff file.
 *
 * @param string $file File name.
 * @return string
 */
function acn_cs_handoff_file_path( $file ) {
	$file = basename( $file );
	foreach ( acn_cs_handoff_dirs() as $dir ) {
		$path = $dir . DIRECTORY_SEPARATOR . $file;
		if ( is_readable( $path ) ) {
			return $path;
		}
	}

	return '';
}

/**
 * Check source whitelist.
 *
 * @param string $file File name.
 * @return bool
 */
function acn_cs_is_allowed_source_file( $file ) {
	foreach ( acn_cs_source_files() as $source ) {
		if ( $source['file'] === $file ) {
			return true;
		}
	}
	return false;
}

/**
 * Small Markdown renderer for handoff files.
 *
 * @param string $markdown Markdown.
 * @return string
 */
function acn_cs_markdown_to_html( $markdown ) {
	$markdown = str_replace( array( "\r\n", "\r" ), "\n", $markdown );
	$lines    = explode( "\n", $markdown );
	$html     = '';
	$list     = '';
	$count    = count( $lines );

	for ( $i = 0; $i < $count; $i++ ) {
		$line = rtrim( $lines[ $i ] );
		$trim = trim( $line );

		if ( '' === $trim ) {
			$html .= acn_cs_close_list( $list );
			continue;
		}

		if ( preg_match( '/^(#{1,6})\s+(.+)$/', $trim, $matches ) ) {
			$html .= acn_cs_close_list( $list );
			$level = min( 6, strlen( $matches[1] ) );
			$text  = acn_cs_clean_markdown_text( $matches[2] );
			$html .= '<h' . $level . '>' . acn_cs_inline_markdown( $text ) . '</h' . $level . '>';
			continue;
		}

		if ( acn_cs_is_table_start( $lines, $i ) ) {
			$html .= acn_cs_close_list( $list );
			$html .= acn_cs_render_table( $lines, $i );
			continue;
		}

		if ( preg_match( '/^\s*[-*]\s+(.+)$/', $line, $matches ) ) {
			if ( 'ul' !== $list ) {
				$html .= acn_cs_close_list( $list );
				$list  = 'ul';
				$html .= '<ul>';
			}
			$html .= '<li>' . acn_cs_inline_markdown( acn_cs_clean_markdown_text( $matches[1] ) ) . '</li>';
			continue;
		}

		if ( preg_match( '/^\s*\d+\.\s+(.+)$/', $line, $matches ) ) {
			if ( 'ol' !== $list ) {
				$html .= acn_cs_close_list( $list );
				$list  = 'ol';
				$html .= '<ol>';
			}
			$html .= '<li>' . acn_cs_inline_markdown( acn_cs_clean_markdown_text( $matches[1] ) ) . '</li>';
			continue;
		}

		$html .= acn_cs_close_list( $list );
		$html .= '<p>' . acn_cs_inline_markdown( acn_cs_clean_markdown_text( $trim ) ) . '</p>';
	}

	$html .= acn_cs_close_list( $list );
	return $html;
}

/**
 * Close current list.
 *
 * @param string $list Current list type, passed by reference.
 * @return string
 */
function acn_cs_close_list( &$list ) {
	if ( ! $list ) {
		return '';
	}
	$tag  = $list;
	$list = '';
	return '</' . $tag . '>';
}

/**
 * Detect a Markdown table.
 *
 * @param array $lines Lines.
 * @param int   $index Current index.
 * @return bool
 */
function acn_cs_is_table_start( $lines, $index ) {
	if ( empty( $lines[ $index + 1 ] ) ) {
		return false;
	}
	return false !== strpos( $lines[ $index ], '|' ) && preg_match( '/^\s*\|?[\s:\-|]+\|[\s:\-|]*$/', trim( $lines[ $index + 1 ] ) );
}

/**
 * Render a Markdown table and advance line pointer.
 *
 * @param array $lines Lines.
 * @param int   $index Current index, passed by reference.
 * @return string
 */
function acn_cs_render_table( $lines, &$index ) {
	$rows  = array();
	$count = count( $lines );

	for ( ; $index < $count; $index++ ) {
		$line = trim( $lines[ $index ] );
		if ( '' === $line || false === strpos( $line, '|' ) ) {
			break;
		}
		if ( preg_match( '/^\|?[\s:\-|]+\|[\s:\-|]*$/', $line ) ) {
			continue;
		}
		$cells = array_map( 'trim', explode( '|', trim( $line, '|' ) ) );
		$rows[] = $cells;
	}
	$index--;

	if ( empty( $rows ) ) {
		return '';
	}

	$html = '<table><thead><tr>';
	foreach ( $rows[0] as $cell ) {
		$html .= '<th>' . acn_cs_inline_markdown( acn_cs_clean_markdown_text( $cell ) ) . '</th>';
	}
	$html .= '</tr></thead><tbody>';

	for ( $i = 1; $i < count( $rows ); $i++ ) {
		$html .= '<tr>';
		foreach ( $rows[ $i ] as $cell ) {
			$html .= '<td>' . acn_cs_inline_markdown( acn_cs_clean_markdown_text( $cell ) ) . '</td>';
		}
		$html .= '</tr>';
	}

	$html .= '</tbody></table>';
	return $html;
}

/**
 * Clean simple Markdown escapes and heading wrappers.
 *
 * @param string $text Text.
 * @return string
 */
function acn_cs_clean_markdown_text( $text ) {
	$text = trim( $text );
	$text = preg_replace( '/^\*\*(.+)\*\*$/', '$1', $text );
	$text = str_replace( array( '\\-', '\\_', '\\.', '\\)', '\\(', '\\"' ), array( '-', '_', '.', ')', '(', '"' ), $text );
	return $text;
}

/**
 * Render inline Markdown safely.
 *
 * @param string $text Text.
 * @return string
 */
function acn_cs_inline_markdown( $text ) {
	$text = esc_html( $text );
	$text = preg_replace( '/\*\*(.+?)\*\*/', '<strong>$1</strong>', $text );
	$text = preg_replace_callback(
		'/\[([^\]]+)\]\((https?:\/\/[^\s\)]+)\)/',
		function ( $matches ) {
			return sprintf(
				'<a href="%1$s" rel="nofollow noopener">%2$s</a>',
				esc_url( html_entity_decode( $matches[2], ENT_QUOTES, 'UTF-8' ) ),
				esc_html( html_entity_decode( $matches[1], ENT_QUOTES, 'UTF-8' ) )
			);
		},
		$text
	);
	return $text;
}