<commit_before><?php
require_once(dirname(__FILE__) . '/User.php');

/**
 * StartupAPI class contains some global static functions and entry points for API
 *
 * @package StartupAPI
 */
class StartupAPI {

	/**
	 * @var int Startup API major version number - to be changed only manually in this code
	 */
	private static $major_version = 0;

	/**
	 * @var int Startup API minor version - to be incremented automatically when asked for
	 */
	private static $minor_version = 4;

	/**
	 * @var int	Startup API patch level (version number) - to be incremented automatically when build script is ran
	 */
	private static $patch_level = 0;

	/**
	 * @var string Startup API pre-release version string
	 */
	private static $pre_release_version;

	/**
	 * @var string Startup API build version string
	 */
	private static $build_version;

	/**
	 * Just a proxy to static User::get() method in User class
	 *
	 * @return User|null
	 */
	static function getUser() {
		return User::get();
	}

	/**
	 * Just a proxy to static User::require_login() method in User class
	 *
	 * @return User
	 */
	static function requireLogin() {
		return User::requireLogin();
	}

	/**
	 * This finction should be called within the head of HTML to insert
	 * styles, scripts and potentially meta-tags into the head of the pages on the site
	 */
	static function head() {
		?><link rel="stylesheet" type="text/css" href="<?php echo UserConfig::$USERSROOTURL ?>/themes/<?php echo UserConfig::$theme ?>/startupapi.css"><?php
	}

	/**
	 * This finction renders the power strip (navigation bar at the top right corner)
	 */
	static function power_strip() {
		$current_user = User::get();
		$current_account = null;

		$accounts = array();
		if (UserConfig::$useAccounts && !is_null($current_user)) {
			$accounts = Account::getUserAccounts($current_user);

			$current_account = Account::getCurrentAccount($current_user);
		}
		?>
		<div id="startupapi-navbox">
			<?php
			if (!is_null($current_user)) {
				if ($current_user->isImpersonated()) {
					?><b id="startupapi-navbox-impersonating"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/stopimpersonation.php" title="Impersonated by <?php echo UserTools::escape($current_user->getImpersonator()->getName()) ?>">Stop Impersonation</a></b> | <?php
			}

			if ($current_user->isAdmin()) {
					?><b id="startupapi-navbox-admin"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/">Admin</a></b> | <?php
			}

			if (count($accounts) > 1) {
				$destination = "'+encodeURIComponent(document.location)+'";
				if (!is_null(UserConfig::$accountSwitchDestination)) {
					$destination = UserConfig::$accountSwitchDestination;
				}
					?><select id="startupapi-navbox-account-picker" name="account" onchange="document.location.href='<?php echo UserConfig::$USERSROOTURL ?>/change_account.php?return=<?php echo $destination ?>&account='+this.value"><?php
				foreach ($accounts as $account) {
						?><option value="<?php echo $account->getID() ?>"<?php
					if ($current_account->isTheSameAs($account)) {
						echo ' selected';
					}
						?>><?php echo UserTools::escape($account->getName()) ?></option><?php
				}
					?></select>
					<?php
				}

				if (!is_null(UserConfig::$onLoginStripLinks)) {
					$links = call_user_func_array(
							UserConfig::$onLoginStripLinks, array($current_user, $current_account)
					);

					foreach ($links as $link) {
						?><span<?php
					if (array_key_exists('id', $link)) {
							?> id="<?php echo $link['id'] ?>"<?php
					}
						?>><a href="<?php echo $link['url'] ?>"<?php
					if (array_key_exists('title', $link)) {
							?> title="<?php echo $link['title'] ?>"<?php
					}
					if (array_key_exists('target', $link)) {
							?> target="<?php echo $link['target'] ?>"<?php
					}
						?>><?php echo $link['text'] ?></a></span> | <?php
				}
			}
				?>

				<span id="startupapi-navbox-username"><a href="<?php echo UserConfig::$USERSROOTURL ?>/edit.php" title="<?php echo UserTools::escape($current_user->getName()) ?>'s user information"><?php echo UserTools::escape($current_user->getName()) ?></a></span> |
				<span id="startupapi-navbox-logout"><a href="<?php echo UserConfig::$USERSROOTURL ?>/logout.php">logout</a></span>
				<?php
			} else {
				?>
				<span id="startupapi-navbox-signup"><a href="<?php echo UserConfig::$USERSROOTURL ?>/register.php">Sign Up Now!</a></span> |
				<span id="startupapi-navbox-login"><a href="<?php echo UserConfig::$USERSROOTURL ?>/login.php">log in</a></span>
				<?php
			}
			?>
		</div>
		<?php
	}

	/**
	 * Incrememts minor version of software
	 */
	public static function incrementMinorVersion() {
		self::$minor_version++;
	}

	/**
	 * Incrememts patch level of software
	 */
	public static function incrementPatchLevel() {
		self::$patch_level++;
	}

	/**
	 * Returns a string representing Statup API version
	 *
	 * @return string Startup API version
	 */
	public static function getVersion() {
		$version = self::$major_version . '.' . self::$minor_version . '.' . self::$patch_level;

		if (!is_null(self::$pre_release_version)) {
			$version .= '-' . self::$pre_release_version;
		}

		if (!is_null(self::$build_version)) {
			$version .= '+build.' . self::$build_version;
		}

		return $version;
	}

	/**
	 * This function should be called after all configuration is loaded to initialize the system.
	 */
	static function _init() {
		//currently empty
	}

}

/**
 * Exception superclass used for all exceptions in StartupAPI
 *
 * @package StartupAPI
 */
class StartupAPIException extends Exception {

	/**
	 * General Startup API Exception
	 *
	 * @param string $message Exception message
	 * @param int $code Exception code
	 * @param Exception $previous Previous exception in the chain
	 */
	function __construct($message, $code, $previous) {
		parent::__construct('[StartupAPI] ' . $message, $code, $previous);
	}

}

/**
 * Exception for database-related problems
 *
 * @package StartupAPI
 */<commit_msg>Fixed default values for 2nd and 3rd params of StartupAPIException constructor)<commit_after><?php
require_once(dirname(__FILE__) . '/User.php');

/**
 * StartupAPI class contains some global static functions and entry points for API
 *
 * @package StartupAPI
 */
class StartupAPI {

	/**
	 * @var int Startup API major version number - to be changed only manually in this code
	 */
	private static $major_version = 0;

	/**
	 * @var int Startup API minor version - to be incremented automatically when asked for
	 */
	private static $minor_version = 4;

	/**
	 * @var int	Startup API patch level (version number) - to be incremented automatically when build script is ran
	 */
	private static $patch_level = 0;

	/**
	 * @var string Startup API pre-release version string
	 */
	private static $pre_release_version;

	/**
	 * @var string Startup API build version string
	 */
	private static $build_version;

	/**
	 * Just a proxy to static User::get() method in User class
	 *
	 * @return User|null
	 */
	static function getUser() {
		return User::get();
	}

	/**
	 * Just a proxy to static User::require_login() method in User class
	 *
	 * @return User
	 */
	static function requireLogin() {
		return User::requireLogin();
	}

	/**
	 * This finction should be called within the head of HTML to insert
	 * styles, scripts and potentially meta-tags into the head of the pages on the site
	 */
	static function head() {
		?><link rel="stylesheet" type="text/css" href="<?php echo UserConfig::$USERSROOTURL ?>/themes/<?php echo UserConfig::$theme ?>/startupapi.css"><?php
	}

	/**
	 * This finction renders the power strip (navigation bar at the top right corner)
	 */
	static function power_strip() {
		$current_user = User::get();
		$current_account = null;

		$accounts = array();
		if (UserConfig::$useAccounts && !is_null($current_user)) {
			$accounts = Account::getUserAccounts($current_user);

			$current_account = Account::getCurrentAccount($current_user);
		}
		?>
		<div id="startupapi-navbox">
			<?php
			if (!is_null($current_user)) {
				if ($current_user->isImpersonated()) {
					?><b id="startupapi-navbox-impersonating"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/stopimpersonation.php" title="Impersonated by <?php echo UserTools::escape($current_user->getImpersonator()->getName()) ?>">Stop Impersonation</a></b> | <?php
			}

			if ($current_user->isAdmin()) {
					?><b id="startupapi-navbox-admin"><a href="<?php echo UserConfig::$USERSROOTURL ?>/admin/">Admin</a></b> | <?php
			}

			if (count($accounts) > 1) {
				$destination = "'+encodeURIComponent(document.location)+'";
				if (!is_null(UserConfig::$accountSwitchDestination)) {
					$destination = UserConfig::$accountSwitchDestination;
				}
					?><select id="startupapi-navbox-account-picker" name="account" onchange="document.location.href='<?php echo UserConfig::$USERSROOTURL ?>/change_account.php?return=<?php echo $destination ?>&account='+this.value"><?php
				foreach ($accounts as $account) {
						?><option value="<?php echo $account->getID() ?>"<?php
					if ($current_account->isTheSameAs($account)) {
						echo ' selected';
					}
						?>><?php echo UserTools::escape($account->getName()) ?></option><?php
				}
					?></select>
					<?php
				}

				if (!is_null(UserConfig::$onLoginStripLinks)) {
					$links = call_user_func_array(
							UserConfig::$onLoginStripLinks, array($current_user, $current_account)
					);

					foreach ($links as $link) {
						?><span<?php
					if (array_key_exists('id', $link)) {
							?> id="<?php echo $link['id'] ?>"<?php
					}
						?>><a href="<?php echo $link['url'] ?>"<?php
					if (array_key_exists('title', $link)) {
							?> title="<?php echo $link['title'] ?>"<?php
					}
					if (array_key_exists('target', $link)) {
							?> target="<?php echo $link['target'] ?>"<?php
					}
						?>><?php echo $link['text'] ?></a></span> | <?php
				}
			}
				?>

				<span id="startupapi-navbox-username"><a href="<?php echo UserConfig::$USERSROOTURL ?>/edit.php" title="<?php echo UserTools::escape($current_user->getName()) ?>'s user information"><?php echo UserTools::escape($current_user->getName()) ?></a></span> |
				<span id="startupapi-navbox-logout"><a href="<?php echo UserConfig::$USERSROOTURL ?>/logout.php">logout</a></span>
				<?php
			} else {
				?>
				<span id="startupapi-navbox-signup"><a href="<?php echo UserConfig::$USERSROOTURL ?>/register.php">Sign Up Now!</a></span> |
				<span id="startupapi-navbox-login"><a href="<?php echo UserConfig::$USERSROOTURL ?>/login.php">log in</a></span>
				<?php
			}
			?>
		</div>
		<?php
	}

	/**
	 * Incrememts minor version of software
	 */
	public static function incrementMinorVersion() {
		self::$minor_version++;
	}

	/**
	 * Incrememts patch level of software
	 */
	public static function incrementPatchLevel() {
		self::$patch_level++;
	}

	/**
	 * Returns a string representing Statup API version
	 *
	 * @return string Startup API version
	 */
	public static function getVersion() {
		$version = self::$major_version . '.' . self::$minor_version . '.' . self::$patch_level;

		if (!is_null(self::$pre_release_version)) {
			$version .= '-' . self::$pre_release_version;
		}

		if (!is_null(self::$build_version)) {
			$version .= '+build.' . self::$build_version;
		}

		return $version;
	}

	/**
	 * This function should be called after all configuration is loaded to initialize the system.
	 */
	static function _init() {
		//currently empty
	}

}

/**
 * Exception superclass used for all exceptions in StartupAPI
 *
 * @package StartupAPI
 */
class StartupAPIException extends Exception {

	/**
	 * General Startup API Exception
	 *
	 * @param string $message Exception message
	 * @param int $code Exception code
	 * @param Exception $previous Previous exception in the chain
	 */
	function __construct($message, $code = null, $previous = null) {
		parent::__construct('[StartupAPI] ' . $message, $code, $previous);
	}

}

/**
 * Exception for database-related problems
 *
 * @package StartupAPI
 */
{'fraction_non_alphanumeric': 0.1651092941765393, 'fraction_numerical': 0.0008343066911396629, 'mean_word_length': 3.8826883910386965, 'pattern_counts': {'":': 0, '<': 149, '<?xml version=': 0, '>': 167, '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': '175617', 'n_tokens_mistral': 4205, 'n_tokens_neox': 3709, 'n_words': 952}