<?php
global $website_options;

Abstract Class baseController {

/*
 * @registry object
 */
protected $registry;

function __construct($registry = null) {
	$this->registry = $registry;

    // THESE ARE THE OPTIONS UNDER THE ADMIN > DESIGN TAB FOR 
    // SETTING IMPORTANT GLOBAL VARIABLES, LIKE LOGOS, SITE NAME, ETC.
	$optionsModel = new optionsModel();
	$this->website_options = $optionsModel->getList(); 

	// DO SOMETHING FOR LOGGED IN USERS ONLY
	if ($_SESSION['user_id'] && $_SESSION['user']['id']) {
		// REAL-TIME ALERTS + INBOX/MESSAGING NOTIFICATIONS - AVAILABLE IN THE BASE+ VERSION
	}

	$db   = Mysql::getInstance();
	$opts = $db->select("website_options");

	$website_options = [];
	foreach ($opts as $opt)
		$website_options[$opt['name']] = $opt['value'];
}

////////////////////////////////////////////////////////////////
/////// HELPFUL GLOBAL FUNCTIONS CAN GO HERE
////////////////////////////////////////////////////////////////

// A SECURITY FUNCTION FOR PROTECTING TEXT INPUTS, ETC.
function secureInput($string, $br = true, $strip = 0){
	$string = trim($string);
	$string = preg_replace("/&#?[a-z0-9]+;/i", "", $string);
	$string = htmlspecialchars($string, ENT_QUOTES);
	if ($br == true) {
		$string = str_replace('\r\n', " <br>", $string);
		$string = str_replace('\n\r', " <br>", $string);
		$string = str_replace('\r', " <br>", $string);
		$string = str_replace('\n', " <br>", $string);
	} else {
		$string = str_replace('\r\n', "", $string);
		$string = str_replace('\n\r', "", $string);
		$string = str_replace('\r', "", $string);
		$string = str_replace('\n', "", $string);
	}
	if ($strip == 1) {
		$string = stripslashes($string);
	}
	$string = str_replace('&amp;#', '&#', $string);
	return $string;
}

// REMOVE ANYTHING THAT IS NOT AN INTEGER
function intOnly($string){
	$string = preg_replace('/[^\d+$]/', "", $string);
	return $string;
}

/**
 * @all controllers must contain an index method
 */
abstract function index();
}