<commit_before><?php

abstract class MvcLoader {

	protected $admin_controller_names = array();
	protected $core_path = '';
	protected $dispatcher = null;
	protected $file_includer = null;
	protected $model_names = array();
	protected $public_controller_names = array();
	protected $query_vars = array();

	function __construct() {
	
		if (!defined('MVC_CORE_PATH')) {
			define('MVC_CORE_PATH', MVC_PLUGIN_PATH.'core/');
		}
		
		$this->core_path = MVC_CORE_PATH;
		
		$this->load_core();
		$this->load_plugins();
		
		$this->file_includer = new MvcFileIncluder();
		$this->file_includer->include_all_app_files('config/bootstrap.php');
		$this->file_includer->include_all_app_files('config/routes.php');
		
		$this->dispatcher = new MvcDispatcher();
		
	}
	
	protected function load_core() {
		
		$files = array(
			'mvc_error',
			'mvc_configuration',
			'mvc_directory',
			'mvc_dispatcher',
			'mvc_file',
			'mvc_file_includer',
			'mvc_model_registry',
			'mvc_object_registry',
			'mvc_settings_registry',
			'mvc_plugin_loader',
			'mvc_templater',
			'mvc_inflector',
			'mvc_router',
			'mvc_settings',
			'controllers/mvc_controller',
			'controllers/mvc_admin_controller',
			'controllers/mvc_public_controller',
			'functions/functions',
			'models/mvc_database_adapter',
			'models/mvc_database',
			'models/mvc_data_validation_error',
			'models/mvc_data_validator',
			'models/mvc_model_object',
			'models/mvc_model',
			'models/wp_models/mvc_comment',
			'models/wp_models/mvc_comment_meta',
			'models/wp_models/mvc_post_adapter',
			'models/wp_models/mvc_post',
			'models/wp_models/mvc_post_meta',
			'models/wp_models/mvc_user',
			'helpers/mvc_helper',
			'helpers/mvc_form_tags_helper',
			'helpers/mvc_form_helper',
			'helpers/mvc_html_helper',
			'shells/mvc_shell',
			'shells/mvc_shell_dispatcher'
		);
		
		foreach ($files as $file) {
			require_once $this->core_path.$file.'.php';
		}
		
	}
	
	protected function load_plugins() {
	
		$plugins = $this->get_ordered_plugins();
		$plugin_app_paths = array();
		foreach ($plugins as $plugin) {
			$plugin_app_paths[$plugin] = rtrim(WP_PLUGIN_DIR, '/').'/'.$plugin.'/app/';
		}

		MvcConfiguration::set(array(
			'Plugins' => $plugins,
			'PluginAppPaths' => $plugin_app_paths
		));

		$this->plugin_app_paths = $plugin_app_paths;
	
	}
	
	protected function get_ordered_plugins() {
	
		$plugins = get_option('mvc_plugins', array());
		$plugin_app_paths = array();
		
		// Allow plugins to be loaded in a specific order by setting a PluginOrder config value like
		// this ('all' is an optional token; it includes all unenumerated plugins):
		// MvcConfiguration::set(array(
		//		'PluginOrder' => array('my-first-plugin', 'my-second-plugin', 'all', 'my-last-plugin')
		// );
		$plugin_order = MvcConfiguration::get('PluginOrder');
		if (!empty($plugin_order)) {
			$ordered_plugins = array();
			$index_of_all = array_search('all', $plugin_order);
			if ($index_of_all !== false) {
				$first_plugins = array_slice($plugin_order, 0, $index_of_all - 1);
				$last_plugins = array_slice($plugin_order, $index_of_all);
				$middle_plugins = array_diff($plugins, $first_plugins, $last_plugins);
				$plugins = array_merge($first_plugins, $middle_plugins, $last_plugins);
			} else {
				$unordered_plugins = array_diff($plugins, $plugin_order);
				$plugins = array_merge($plugin_order, $unordered_plugins);
			}
		}
		
		return $plugins;
		
	}
	
	public function init() {
	
		$this->load_controllers();
		$this->load_libs();
		$this->load_models();
		$this->load_settings();
		$this->load_functions();
	
	}
	
	public function filter_post_link($permalink, $post) {
		if (substr($post->post_type, 0, 4) == 'mvc_') {
			$model_name = substr($post->post_type, 4);
			$controller = MvcInflector::tableize($model_name);
			$model_name = MvcInflector::camelize($model_name);
			$model = MvcModelRegistry::get_model($model_name);
			$object = $model->find_one(array('post_id' => $post->ID));<commit_msg>Resolves an issue whereby permalinks for associated posts always display as the peramalink to the very first object in the collection (based on the defined sort order) instead of the associated post of the object in question.<commit_after><?php

abstract class MvcLoader {

	protected $admin_controller_names = array();
	protected $core_path = '';
	protected $dispatcher = null;
	protected $file_includer = null;
	protected $model_names = array();
	protected $public_controller_names = array();
	protected $query_vars = array();

	function __construct() {
	
		if (!defined('MVC_CORE_PATH')) {
			define('MVC_CORE_PATH', MVC_PLUGIN_PATH.'core/');
		}
		
		$this->core_path = MVC_CORE_PATH;
		
		$this->load_core();
		$this->load_plugins();
		
		$this->file_includer = new MvcFileIncluder();
		$this->file_includer->include_all_app_files('config/bootstrap.php');
		$this->file_includer->include_all_app_files('config/routes.php');
		
		$this->dispatcher = new MvcDispatcher();
		
	}
	
	protected function load_core() {
		
		$files = array(
			'mvc_error',
			'mvc_configuration',
			'mvc_directory',
			'mvc_dispatcher',
			'mvc_file',
			'mvc_file_includer',
			'mvc_model_registry',
			'mvc_object_registry',
			'mvc_settings_registry',
			'mvc_plugin_loader',
			'mvc_templater',
			'mvc_inflector',
			'mvc_router',
			'mvc_settings',
			'controllers/mvc_controller',
			'controllers/mvc_admin_controller',
			'controllers/mvc_public_controller',
			'functions/functions',
			'models/mvc_database_adapter',
			'models/mvc_database',
			'models/mvc_data_validation_error',
			'models/mvc_data_validator',
			'models/mvc_model_object',
			'models/mvc_model',
			'models/wp_models/mvc_comment',
			'models/wp_models/mvc_comment_meta',
			'models/wp_models/mvc_post_adapter',
			'models/wp_models/mvc_post',
			'models/wp_models/mvc_post_meta',
			'models/wp_models/mvc_user',
			'helpers/mvc_helper',
			'helpers/mvc_form_tags_helper',
			'helpers/mvc_form_helper',
			'helpers/mvc_html_helper',
			'shells/mvc_shell',
			'shells/mvc_shell_dispatcher'
		);
		
		foreach ($files as $file) {
			require_once $this->core_path.$file.'.php';
		}
		
	}
	
	protected function load_plugins() {
	
		$plugins = $this->get_ordered_plugins();
		$plugin_app_paths = array();
		foreach ($plugins as $plugin) {
			$plugin_app_paths[$plugin] = rtrim(WP_PLUGIN_DIR, '/').'/'.$plugin.'/app/';
		}

		MvcConfiguration::set(array(
			'Plugins' => $plugins,
			'PluginAppPaths' => $plugin_app_paths
		));

		$this->plugin_app_paths = $plugin_app_paths;
	
	}
	
	protected function get_ordered_plugins() {
	
		$plugins = get_option('mvc_plugins', array());
		$plugin_app_paths = array();
		
		// Allow plugins to be loaded in a specific order by setting a PluginOrder config value like
		// this ('all' is an optional token; it includes all unenumerated plugins):
		// MvcConfiguration::set(array(
		//		'PluginOrder' => array('my-first-plugin', 'my-second-plugin', 'all', 'my-last-plugin')
		// );
		$plugin_order = MvcConfiguration::get('PluginOrder');
		if (!empty($plugin_order)) {
			$ordered_plugins = array();
			$index_of_all = array_search('all', $plugin_order);
			if ($index_of_all !== false) {
				$first_plugins = array_slice($plugin_order, 0, $index_of_all - 1);
				$last_plugins = array_slice($plugin_order, $index_of_all);
				$middle_plugins = array_diff($plugins, $first_plugins, $last_plugins);
				$plugins = array_merge($first_plugins, $middle_plugins, $last_plugins);
			} else {
				$unordered_plugins = array_diff($plugins, $plugin_order);
				$plugins = array_merge($plugin_order, $unordered_plugins);
			}
		}
		
		return $plugins;
		
	}
	
	public function init() {
	
		$this->load_controllers();
		$this->load_libs();
		$this->load_models();
		$this->load_settings();
		$this->load_functions();
	
	}
	
	public function filter_post_link($permalink, $post) {
		if (substr($post->post_type, 0, 4) == 'mvc_') {
			$model_name = substr($post->post_type, 4);
			$controller = MvcInflector::tableize($model_name);
			$model_name = MvcInflector::camelize($model_name);
			$model = MvcModelRegistry::get_model($model_name);
			$object = $model->find_one_by_post_id($post->ID);
{'fraction_non_alphanumeric': 0.14952696891510014, 'fraction_numerical': 0.0012286521685710775, 'mean_word_length': 4.6685236768802225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '2983079', 'n_tokens_mistral': 3284, 'n_tokens_neox': 2860, 'n_words': 468}