<commit_before><?php
/**
 * The class file for Component
 */
/**
 * Copyright (c) 2009 JadeIT cc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * @license http://www.eclipse.org/legal/epl-v10.html
 * @package Controllers
 *
 * Contributors:
 * @author <NAME> (JadeIT cc) - initial API and implementation
 */

/**
 * This is the controller for the table components.
 */
class Component extends TableCtl {
	public static function fromFolder() {
		$toret = array();
		$base_c = self::getBaseComponents(array('filenames' => true));
		$toret  = array_merge($toret, files_from_folder(BACKEND_FOLDER . '/controllers/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(APP_FOLDER . '/controllers/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(BACKEND_FOLDER . '/views/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(APP_FOLDER . '/views/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(APP_FOLDER . '/classes/', array('prepend_folder' => true)));
		$toret  = preg_replace('/(' . str_replace('/', '\/', BACKEND_FOLDER) . '\/|' . str_replace('/', '\/', APP_FOLDER) . '\/)/', '/', $toret);

		$toret  = array_unique(array_merge(array_values($base_c), $toret));
		
		return $toret;
	}

	private static function getBaseComponents() {
		$toret = array();
		$toret['Controller']  = '/classes/Controller.obj.php';
		$toret['Render']      = '/classes/Render.obj.php';
		$toret['Backend']     = '/classes/Backend.obj.php';
		$toret['GateKeeper']  = '/classes/GateKeeper.obj.php';
		$toret['View']        = '/classes/View.obj.php';
		$toret['HtmlView']    = '/views/HtmlView.obj.php';
		$toret['ImageView']   = '/views/ImageView.obj.php';
		$toret['JsonView']    = '/views/JsonView.obj.php';
		$toret['SerializeView'] = '/views/SerializeView.obj.php';
		$toret['PhpView']     = '/views/PhpView.obj.php';
		$toret['Component']   = '/controllers/Component.obj.php';
		$toret['Hook']        = '/controllers/Hook.obj.php';
		$toret['GateManager'] = '/controllers/GateManager.obj.php';
		$toret['Admin']       = '/controllers/Admin.obj.php';
		$toret['Content']     = '/controllers/Content.obj.php';
		$toret['Value']       = '/controllers/Value.obj.php';
		$toret['Account']     = '/controllers/Account.obj.php';
		$toret['Assignment']  = '/controllers/Assignment.obj.php';
		return $toret;
	}
	
	public static function getActive($refresh = false) {
		$toret = Backend::get('Component::active', false);
		if (!$toret || $refresh) {
			$component = new ComponentObj();
			list ($query, $params) = $component->getSelectSQL(array('conditions' => '`active` = 1'));
			$query = new CustomQuery($query);
			$toret = $query->fetchAll();
			Backend::add('Component::active', $toret);
		}
		return $toret;
	}
	
	public static function isActive($name) {
		$toret = false;
		$active = self::getActive();
		if ($active) {
			$active = array_flatten($active, 'id', 'name');
			$toret = in_array($name, $active);
		}
		return $toret;
	}
	
	public static function hook_init() {
		self::getActive();
	}
	
	public static function install() {
		$toret = true;

		$components = self::fromFolder();

		$component = new ComponentObj();
		$component->truncate();
		foreach($components as $component_file) {
			$name = preg_replace('/\.obj\.php$/', '', basename($component_file));
			$active = in_array($name, array_keys(self::getBaseComponents())) ||
					  $name == Backend::getConfig('backend.application.class');

			$data = array(<commit_msg>Only Admin is active when not installed<commit_after><?php
/**
 * The class file for Component
 */
/**
 * Copyright (c) 2009 JadeIT cc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * @license http://www.eclipse.org/legal/epl-v10.html
 * @package Controllers
 *
 * Contributors:
 * @author <NAME> (JadeIT cc) - initial API and implementation
 */

/**
 * This is the controller for the table components.
 */
class Component extends TableCtl {
	public static function fromFolder() {
		$toret = array();
		$base_c = self::getBaseComponents(array('filenames' => true));
		$toret  = array_merge($toret, files_from_folder(BACKEND_FOLDER . '/controllers/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(APP_FOLDER . '/controllers/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(BACKEND_FOLDER . '/views/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(APP_FOLDER . '/views/', array('prepend_folder' => true)));
		$toret  = array_merge($toret, files_from_folder(APP_FOLDER . '/classes/', array('prepend_folder' => true)));
		$toret  = preg_replace('/(' . str_replace('/', '\/', BACKEND_FOLDER) . '\/|' . str_replace('/', '\/', APP_FOLDER) . '\/)/', '/', $toret);

		$toret  = array_unique(array_merge(array_values($base_c), $toret));
		
		return $toret;
	}

	private static function getBaseComponents() {
		$toret = array();
		$toret['Controller']  = '/classes/Controller.obj.php';
		$toret['Render']      = '/classes/Render.obj.php';
		$toret['Backend']     = '/classes/Backend.obj.php';
		$toret['GateKeeper']  = '/classes/GateKeeper.obj.php';
		$toret['View']        = '/classes/View.obj.php';
		$toret['HtmlView']    = '/views/HtmlView.obj.php';
		$toret['ImageView']   = '/views/ImageView.obj.php';
		$toret['JsonView']    = '/views/JsonView.obj.php';
		$toret['SerializeView'] = '/views/SerializeView.obj.php';
		$toret['PhpView']     = '/views/PhpView.obj.php';
		$toret['Component']   = '/controllers/Component.obj.php';
		$toret['Hook']        = '/controllers/Hook.obj.php';
		$toret['GateManager'] = '/controllers/GateManager.obj.php';
		$toret['Admin']       = '/controllers/Admin.obj.php';
		$toret['Content']     = '/controllers/Content.obj.php';
		$toret['Value']       = '/controllers/Value.obj.php';
		$toret['Account']     = '/controllers/Account.obj.php';
		$toret['Assignment']  = '/controllers/Assignment.obj.php';
		return $toret;
	}
	
	public static function getActive($refresh = false) {
		$toret = Backend::get('Component::active', false);
		if (!$toret || $refresh) {
			$component = new ComponentObj();
			list ($query, $params) = $component->getSelectSQL(array('conditions' => '`active` = 1'));
			$query = new CustomQuery($query);
			$toret = $query->fetchAll();
			Backend::add('Component::active', $toret);
		}
		return $toret;
	}
	
	public static function isActive($name) {
		$toret = false;
		if (Value::get('admin_installed', false)) {
			$active = self::getActive();
			if ($active) {
				$active = array_flatten($active, 'id', 'name');
				$toret = in_array($name, $active);
			}
		} else if ($name == 'Admin') {
			$toret = true;
		}
		return $toret;
	}
	
	public static function hook_init() {
		self::getActive();
	}
	
	public static function install() {
		$toret = true;

		$components = self::fromFolder();

		$component = new ComponentObj();
		$component->truncate();
		foreach($components as $component_file) {
			$name = preg_replace('/\.obj\.php$/', '', basename($component_file));
			$active = in_array($name, array_keys(self::getBaseComponents())) ||
					  $name == Backend::getConfig('backend.application.class');

			$data = array(
{'fraction_non_alphanumeric': 0.19012966393225722, 'fraction_numerical': 0.0023815824292140776, 'mean_word_length': 4.177397260273972, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '790462', 'n_tokens_mistral': 2740, 'n_tokens_neox': 2541, 'n_words': 490}