text:
<?php

	include_once(TOOLKIT . '/class.entrymanager.php');
	include_once(TOOLKIT . '/class.sectionmanager.php');

	include_once(EXTENSIONS . '/members/lib/class.role.php');
	include_once(EXTENSIONS . '/members/lib/class.members.php');
	include_once(EXTENSIONS . '/members/lib/member.symphony.php');

	Class extension_Members extends Extension {

		/**
		 * @var integer $members_section
		 */
		private static $initialised = null;

		/**
		 * @var integer $members_section
		 */
		private static $members_section = null;

		/**
		 * @var array $member_fields
		 */
		private static $member_fields = array(
			'memberusername', 'memberemail'
		);

		/**
		 * @var array $member_events
		 */
		private static $member_events = array(
			'members_regenerate_activation_code',
			'members_activate_account',
			'members_generate_recovery_code',
			'members_reset_password'
		);

		/**
		 * Holds the current Member class that is in place, for this release
		 * this will always the SymphonyMember, which extends Member and implements
		 * the Member interface.
		 *
		 * @see getMemberDriver()
		 * @var Member $Member
		 */
		protected $Member = null;

		/**
		 * Accessible via `getField()`
		 *
		 * @see getField()
		 * @var array $fields
		 */
		protected static $fields = array();

		/**
		 * Accessible via `getFieldHandle()`
		 *
		 * @see getFieldHandle()
		 * @var array $handles
		 */
		protected static $handles = array();

		/**
		 * Returns an associative array of errors that have occurred while
		 * logging in or preforming a Members custom event. The key is the
		 * field's `element_name` and the value is the error message.
		 *
		 * @var array $_errors
		 */
		public static $_errors = array();

		/**
		 * By default this is set to `false`. If a Member attempts to login
		 * but is unsuccessful, this will be `true`. Useful in the
		 * `appendLoginStatusToEventXML` function to determine whether to display
		 * `extension_Members::$_errors` or not.
		 *
		 * @var boolean $failed_login_attempt
		 */
		public static $_failed_login_attempt = false;

		/**
		 * Only create a Member object on the Frontend of the site.
		 * There is no need to create this in the Administration context
		 * as authenticated users are Authors and are handled by Symphony,
		 * not this extension.
		 */
		public function __construct() {
			if(!extension_Members::$initialised) {
				if(class_exists('Symphony') && Symphony::Engine() instanceof Frontend) {
					Symphony::ExtensionManager()->notifyMembers('InitialiseMember', '/frontend/', array(
						'member' => &$this->Member
					));

					if(is_null($this->Member)) {
						$this->Member = new SymphonyMember;
					}
				}

				extension_Members::$initialised = true;
			}
		}

		public function fetchNavigation(){
			return array(
				array(
					'location' 	=> __('System'),
					'name' 		=> __('Member Roles'),
					'link' 		=> '/roles/'
				)
			);
		}

		public function getSubscribedDelegates(){
			return array(
				/*
					FRONTEND
				*/
				array(
					'page' => '/frontend/',
					'delegate' => 'FrontendPageResolved',
					'callback' => 'checkFrontendPagePermissions'
				),
				array(
					'page' => '/frontend/',
					'delegate' => 'FrontendParamsResolve',
					'callback' => 'addMemberDetailsToPageParams'
				),
				array(
					'page' => '/frontend/',
					'delegate' => 'FrontendProcessEvents',
					'callback' => 'appendLoginStatusToEventXML'
				),
				array(
					'page' => '/frontend/',
					'delegate' => 'EventPreSaveFilter',
					'callback' => 'checkEventPermissions'
				),
				array(
					'page' => '/frontend/',
					'delegate' => 'EventPostSaveFilter',
					'callback' => 'processPostSaveFilter'
				),
				/*
					BACKEND
				*/
				array(
					'page' => '/backend/',
					'delegate' => 'AdminPagePreGenerate',
					'callback' => 'appendAssets'
				),
				array(
					'page'		=> '/system/preferences/',
					'delegate'	=> 'AddCustomPreferenceFieldsets',
					'callback'	=> 'appendPreferences'
				),
				array(
					'page'		=> '/system/preferences/',
					'delegate'	=> 'Save',
					'callback'	=> 'savePreferences'
				),
				array(
					'page'		=> '/blueprints/events/new/',
					'delegate'	=> 'AppendEventFilter',
					'callback'	=> 'appendFilter'
				),
				array(
					'page'		=> '/blueprints/events/edit/',
					'delegate'	=> 'AppendEventFilter',
					'callback'	=> 'appendFilter'
				),
			);
		}

	/*-------------------------------------------------------------------------
		Versioning:
	-------------------------------------------------------------------------*/

		/**
		 * Sets the `cookie-prefix` of `sym-members` in the Configuration
		 * and creates all of the field's tables in the database
		 *
		 * @return boolean
		 */
		public function install(){

			Symphony::Configuration()->set('cookie-prefix', 'sym-members', 'members');
			Symphony::Configuration()->write();

			return Symphony::Database()->import("
				DROP TABLE IF EXISTS `tbl_members_roles`;
				CREATE TABLE `tbl_members_roles` (
				  `id` int(11) unsigned NOT NULL auto_increment,
				  `name` varchar(255) NOT NULL,
				  `handle` varchar(255) NOT NULL,
				  PRIMARY KEY  (`id`),
				  UNIQUE KEY `handle` (`handle`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

				INSERT INTO `tbl_members_roles` VALUES(1, 'Public', 'public');

				DROP TABLE IF EXISTS `tbl_members_roles_event_permissions`;
				CREATE TABLE `tbl_members_roles_event_permissions` (
				  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
				  `role_id` int(11) unsigned NOT NULL,
				  `event` varchar(50) NOT NULL,
				  `action` varchar(60) NOT NULL,
				  `level` smallint(1) unsigned NOT NULL DEFAULT '0',
				  PRIMARY KEY (`id`),
				  KEY `role_id` (`role_id`,`event`,`action`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

				DROP TABLE IF EXISTS `tbl_members_roles_forbidden_pages`;
				CREATE TABLE `tbl_members_roles_forbidden_pages` (
				  `id` int(11) unsigned NOT NULL auto_increment,
				  `role_id` int(11) unsigned NOT NULL,
				  `page_id` int(11) unsigned NOT NULL,
				  PRIMARY KEY  (`id`),
				  KEY `role_id` (`role_id`,`page_id`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			");
		}

		/**
		 * Remove's all `members` Configuration values and then drops all the
		 * database tables created by the Members extension
		 *
		 * @return boolean
		 */
		public function uninstall(){
			Symphony::Configuration()->remove('members');
			Symphony::Configuration()->write();

			return Symphony::Database()->query("
				DROP TABLE IF EXISTS
					`tbl_fields_memberusername`,
					`tbl_fields_memberpassword`,
					`tbl_fields_memberemail`,
					`tbl_fields_memberactivation`,
					`tbl_fields_memberrole`,
					`tbl_fields_membertimezone`,
					`tbl_members_roles`,
					`tbl_members_roles_event_permissions`,
					`tbl_members_roles_forbidden_pages`
			");
		}

		public function update($previousVersion) {
			if(version_compare($previousVersion, '1.0 Beta 3', '<')) {
				$activation_table = Symphony::Database()->fetchRow(0, "SHOW TABLES LIKE 'tbl_fields_memberactivation';");
				if(!empty($activation_table)) {
					Symphony::Database()->import("
						ALTER TABLE `tbl_fields_memberactivation` ADD `auto_login` ENUM('yes','no') NULL DEFAULT 'yes';
						ALTER TABLE `tbl_fields_memberactivation` ADD `deny_login` ENUM('yes','no') NULL DEFAULT 'yes';
					");
				}

				$password_table = Symphony::Database()->fetchRow(0, "SHOW TABLES LIKE 'tbl_fields_memberpassword';");
				if(!empty($password_table)) {
					Symphony::Database()->query("
						ALTER TABLE `tbl_fields_memberpassword` ADD `code_expiry` VARCHAR(50) NOT NULL;
					");
				}
			}

			if(version_compare($previousVersion, '1.0RC1', '<')) {
				// Move the auto_login setting from the Activation Field to the config
				$field = extension_Members::getField('activation');
				if($field instanceof Field) {
					Symphony::Configuration()->set('activate-account-auto-login', $field->get('auto_login'));

					$activation_table = Symphony::Database()->fetchRow(0, "SHOW TABLES LIKE 'tbl_fields_memberactivation';");
					if(!empty($activation_table)) {
						Symphony::Database()->query("
							ALTER TABLE `tbl_fields_memberpassword` DROP `auto_login`;
						");
					}
				}

				// These are now loaded dynamically
				Symphony::Configuration()->remove('timezone', 'members');
				Symphony::Configuration()->remove('role', 'members');
				Symphony::Configuration()->remove('activation', 'members');
				Symphony::Configuration()->remove('identity', 'members');
				Symphony::Configuration()->remove('email', 'members');
				Symphony::Configuration()->remove('authentication', 'members');
				Symphony::Configuration()->write();
			}

			if(version_compare($previousVersion, '1.1 Beta 1', '<') || version_compare($previousVersion, '1.1.1RC1', '<')) {
				$tables = array();

				// For any Member: Username or Member: Email fields, add a handle column
				// and adjust the indexes to reflect that. Uniqueness is on the handle,
				// not the value.
				$field = extension_Members::getField('identity');
				if($field instanceof fieldMemberUsername) {
					$identity_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_memberusername`");

					if(is_array($identity_tables) && !empty($identity_tables)) {
						$tables = array_merge($tables, $identity_tables);
					}
				}

				if(is_array($tables) && !empty($tables)) foreach($tables as $field) {
					if(!Symphony::Database()->tableContainsField('tbl_entries_data_' . $field, 'handle')) {
						// Add handle field
						Symphony::Database()->query(sprintf(
							"ALTER TABLE `tbl_entries_data_%d` ADD `handle` VARCHAR(255) DEFAULT NULL",
							$field
						));

						// Populate handle field
						$rows = Symphony::Database()->fetch(sprintf(
							"SELECT `id`, `value` FROM `tbl_entries_data_%d`",
							$field
						));

						foreach($rows as $row) {
							Symphony::Database()->query(sprintf("
									UPDATE `tbl_entries_data_%d`
									SET handle = '%s'
									WHERE id = %d
								", $field, Lang::createHandle($row['value']), $row['id']
							));
						}
					}

					// Try to drop the old `username` INDEX
					try {
						Symphony::Database()->query(sprintf(
							'ALTER TABLE `tbl_entries_data_%d` DROP INDEX `username`, DROP INDEX `value`', $field
						));
					}
					catch(Exception $ex) {}

					// Create the new UNIQUE INDEX `username` on `handle`
					try {
						Symphony::Database()->query(sprintf(
							'CREATE UNIQUE INDEX `username` ON `tbl_entries_data_%d` (`handle`)', $field
						));
					}
					catch(Exception $ex) {}

					// Create an index on the `value` column
					try {
						Symphony::Database()->query(sprintf(
							'CREATE INDEX `value` ON `tbl_entries_data_%d` (`value`)', $field
						));
					}
					catch(Exception $ex) {}
				}
			}

			// So `handle` for Email fields is useless as me@example.com will become
			// the same as meex@ample.com. Reverting previous change by dropping
			// `handle` column from Member: Email tables and restoring the UNIQUE KEY
			// index to the `value` column.
			if(version_compare($previousVersion, '1.1 Beta 2', '<')) {
				$tables = array();

				$field = extension_Members::getField('email');
				if($field instanceof fieldMemberEmail) {
					$email_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_memberemail`");

					if(is_array($email_tables) && !empty($email_tables)) {
						$tables = array_merge($tables, $email_tables);
					}
				}

				if(is_array($tables) && !empty($tables)) foreach($tables as $field) {
					if(Symphony::Database()->tableContainsField('tbl_entries_data_' . $field, 'handle')) {
						try {
							// Drop handle field
							Symphony::Database()->query(sprintf(
								"ALTER TABLE `tbl_entries_data_%d` DROP `handle`",
								$field
							));

							// Drop `value` index
							Symphony::Database()->query(sprintf(
								'ALTER TABLE `tbl_entries_data_%d` DROP INDEX `value`', $field
							));

							// Readd UNIQUE `value` index
							Symphony::Database()->query(sprintf(
								'CREATE UNIQUE INDEX `value` ON `tbl_entries_data_%d` (`value`)', $field
							));
						}
						catch(Exception $ex) {
							// Ignore, this may be because a user is updating directly from 1.0 and
							// never had the INDEX's created during the 1.1* betas
						}
					}
				}
			}
		}

	/*-------------------------------------------------------------------------
		Utilities:
	-------------------------------------------------------------------------*/

		public static function baseURL(){
			return SYMPHONY_URL . '/extension/members/';
		}

		/**
		 * Returns an instance of the currently logged in Member, which is a `Entry` object.
		 * If there is no logged in Member, this function will return `null`
		 *
		 * @return Member
		 */
		public function getMemberDriver() {
			return $this->Member;
		}

		/**
		 * Given a `$handle`, this function will return a value from the Members
		 * configuration. Typically this is an shortcut accessor to
		 * `Symphony::Configuration()->get($handle, 'members')`. If no `$handle`
		 * is given this function will return all the configuration values for
		 * the Members extension as an array.
		 *
		 * @param string $handle
		 * @return mixed
		 */
		public static function getSetting($handle = null) {
			if(is_null($handle)) return Symphony::Configuration()->get('members');

			$value = Symphony::Configuration()->get($handle, 'members');
			return ((is_numeric($value) && $value == 0) || is_null($value) || empty($value)) ? null : $value;
		}

		/**
		 * Shortcut accessor for the active Members Section. This function
		 * caches the result of the `getSetting('section')`.
		 *
		 * @return integer
		 */
		public static function getMembersSection() {
			if(is_null(extension_Members::$members_section)) {
				extension_Members::$members_section = extension_Members::getSetting('section');
			}

			return extension_Members::$members_section;
		}

		/**
		 * Given a string representing a field type, return the actual field type
		 * that will be saved in Symphony. This is mainly for legacy reasons, where
		 * the Members extension uses slightly different types to what is actually
		 * saved. For example, `role` is `memberrole`, `authentication` is `memberpassword`
		 * etc.
		 *
		 * @param string $type
		 *
		 * @return string
		 */
		public static function getFieldType($type) {
			switch($type) {
				case 'authentication':
					return 'memberpassword';
				case 'identity':
					return 'memberusername';
				default:
					return 'member' . $type;
			}
		}

		/**
		 * Where `$name` is one of the following values, `role`, `timezone`,
		 * `email`, `activation`, `authentication` and `identity`, this function
		 * will return a Field instance. Typically this allows extensions to access
		 * the Fields that are currently being used in the active Members section.
		 *
		 * @param string $type
		 * @param integer $section_id
		 *  The Section ID to find the given `$type` in. If this isn't provided this
		 *  extension will just look for any Fields with the given `$type`
		 * @return Field|null
		 *  If `$type` is not given, or no Field was found, null will be returned.
		 */
		public static function getField($type = null, $section_id = null) {
			if(is_null($type)) return null;

			$type = self::getFieldType($type);

			// Check to see if this name has been stored in our 'static' cache
			// If it hasn't, lets go find it (for better or worse)
			if(!isset(extension_Members::$fields[$type])) {
				self::initialiseField($type, $section_id);
			}

			// No field, return null
			if(!isset(extension_Members::$fields[$type])) return null;

			// If it has, return it.
			return extension_Members::$fields[$type];
		}

		/**
		 * Where `$name` is one of the following values, `role`, `timezone`,
		 * `email`, `activation`, `authentication` and `identity`, this function
		 * will return the Field's `element_name`. `element_name` is a handle
		 * of the Field's label, used most commonly by events in `$_POST` data.
		 * If no `$name` is given, an array of all Member field handles will
		 * be returned.
		 *
		 * @param string $type
		 * @param integer $section_id
		 *  The Section ID to find the given `$type` in. If this isn't provided this
		 *  extension will just look for any Fields with the given `$type`
		 * @return string
		 */
		public static function getFieldHandle($type = null, $section_id = null) {
			$type = self::getFieldType($type);

			// Check to see if this name has been stored in our 'static' cache
			// If it hasn't, lets go find it (for better or worse)
			if(!isset(extension_Members::$handles[$type])) {
				self::initialiseField($type, $section_id);
			}

			// No field, return null
			if(!isset(extension_Members::$handles[$type])) return null;

			// Return the handle
			return extension_Members::$handles[$type];
		}

		/**
		 * Given a `$type` and potentially `$section_id`, fetch the Field
		 * instance and populate the static `$fields` and `$handles` arrays
		 *
		 * @param string $type
		 * @param integer $section_id
		 */
		public static function initialiseField($type, $section_id = null) {
			$field = FieldManager::fetch(null, $section_id, 'ASC', 'sortorder', $type);

			if(!empty($field)) {
				$field = current($field);
				extension_Members::$fields[$type] = $field;
				extension_Members::$handles[$type] = $field->get('element_name');
			}
		}

		/**
		 * This function will adjust the locale for the currently logged in
		 * user if the active Member section has a Member: Timezone field.
		 *
		 * @param integer $member_id
		 * @return void
		 */
		public function updateSystemTimezoneOffset($member_id) {
			$timezone = extension_Members::getField('timezone');

			if(!$timezone instanceof fieldMemberTimezone) return;

			$tz = $timezone->getMemberTimezone($member_id);

			if(is_null($tz)) return;

			try {
				DateTimeObj::setDefaultTimezone($tz);
			}
			catch(Exception $ex) {
				Symphony::Log()->pushToLog(__('Members Timezone') . ': ' . $ex->getMessage(), $ex->getCode(), true);
			}
		}

		/**
		 * Given an array of grouped options ready for use in `Widget::Select`
		 * loop over all the options and compare the value to configuration value
		 * (as specified by `$handle`) and if it matches, set that option to true
		 *
		 * @param array $options
		 * @param string $handle
		 * @return array
		 */
		public static function setActiveTemplate(array $options, $handle) {
			$templates = explode(',', extension_Members::getSetting($handle));

			foreach($options as $index => $ext) {
				foreach($ext['options'] as $key => $opt) {
					if(in_array($opt[0], $templates)) {
						$options[$index]['options'][$key][1] = true;
					}
				}
			}

			array_unshift($options, array(null,false,null));

			return $options;
		}

		/**
		 * The Members extension provides a number of filters for users to add their
		 * events to do various functionality. This negates the need for custom events
		 *
		 * @uses AppendEventFilter
		 *
		 * @param $context
		 */
		public function appendFilter($context) {
			$selected = !is_array($context['selected']) ? array() : $context['selected'];

			// Add Member: Lock Role filter
			$context['options'][] = array(
				'member-lock-role',
				in_array('member-lock-role', $selected),
				__('Members: Lock Role')
			);

			if(!is_null(extension_Members::getFieldHandle('activation')) && !is_null(extension_Members::getFieldHandle('email'))) {
				// Add Member: Lock Activation filter
				$context['options'][] = array(
					'member-lock-activation',
					in_array('member-lock-activation', $selected),
					__('Members: Lock Activation')
				);
			}

			if(!is_null(extension_Members::getFieldHandle('authentication'))) {
				// Add Member: Update Password filter
				$context['options'][] = array(
					'member-update-password',
					in_array('member-update-password', $selected),
					__('Members: Update Password')
				);
			}
		}

		public static function findCodeExpiry($table) {
			$default = array('1 hour' => '1 hour', '24 hours' => '24 hours');

			try {
				$used = Symphony::Database()->fetchCol('code_expiry', sprintf("
					SELECT DISTINCT(code_expiry) FROM `%s`
				", $table));

				if(is_array($used) && !empty($used)) {
					$default = array_merge($default, array_combine($used, $used));
				}
			}
			catch (DatabaseException $ex) {
				// Table doesn't exist yet, it's ok we have defaults.
			}

			return $default;
		}

		public static function fetchEmailTemplates() {
			$options = array();
			// Email Template Filter
			// @link http://symphony-cms.com/download/extensions/view/20743/
			try {
				$driver = Symphony::ExtensionManager()->getInstance('emailtemplatefilter');
				if($driver instanceof Extension) {
					$templates = $driver->getTemplates();

					$g = array('label' => __('Email Template Filter'));
					$group_options = array();

					foreach($templates as $template) {
						$group_options[] = array('etf-'.$template['id'], false, $template['name']);
					}
					$g['options'] = $group_options;

					if(!empty($g['options'])) {
						$options[] = $g;
					}
				}
			}
			catch(Exception $ex) {}

			// Email Template Manager
			// @link http://symphony-cms.com/download/extensions/view/64322/
			try {
				$handles = Symphony::ExtensionManager()->listInstalledHandles();
				if(in_array('email_template_manager', $handles)){
					if(file_exists(EXTENSIONS . '/email_template_manager/lib/class.emailtemplatemanager.php') && !class_exists("EmailTemplateManager")) {
						include_once(EXTENSIONS . '/email_template_manager/lib/class.emailtemplatemanager.php');
					}

					if(class_exists("EmailTemplateManager")){
						$templates = EmailTemplateManager::listAll();

						$g = array('label' => __('Email Template Manager'));
						$group_options = array();

						foreach($templates as $template) {
							$group_options[] = array('etm-'.$template->getHandle(), false, $template->getName());
						}
						$g['options'] = $group_options;

						if(!empty($g['options'])) {
							$options[] = $g;
						}
					}
				}
			}
			catch(Exception $ex) {}

			return $options;
		}

	/*-------------------------------------------------------------------------
		Preferences:
	-------------------------------------------------------------------------*/

		/**
		 * Allows a user to select which section they would like to use as their
		 * active members section. This allows developers to build multiple sections
		 * for migration during development.
		 *
		 * @uses AddCustomPreferenceFieldsets
		 * @todo Look at how this could be expanded so users can log into multiple sections. This is not in scope for 1.0
		 *
		 * @param array $context
		 */
		public function appendPreferences($context) {
			$fieldset = new XMLElement('fieldset');
			$fieldset->setAttribute('class', 'settings');
			$fieldset->appendChild(new XMLElement('legend', __('Members')));

			$div = new XMLElement('div');
			$label = new XMLElement('label', __('Active Members Section'));

			// Get the Sections that contain a Member field.
			$sections = SectionManager::fetch();
			$member_sections = array();
			if(is_array($sections) && !empty($sections)) {
				foreach($sections as $section) {
					$schema = $section->fetchFieldsSchema();

					foreach($schema as $field) {
						if(!in_array($field['type'], extension_Members::$member_fields)) continue;

						if(array_key_exists($section->get('id'), $member_sections)) continue;

						$member_sections[$section->get('id')] = $section->get();
					}
				}
			}

			// Build the options
			$options = array(
				array(null, false, null)
			);
			foreach($member_sections as $section_id => $section) {
				$options[] = array($section_id, ($section_id == extension_Members::getMembersSection()), $section['name']);
			}

			$label->appendChild(Widget::Select('settings[members][section]', $options));
			$div->appendChild($label);

			if(count($options) == 1) {
				$div->appendChild(
					new XMLElement('p', __('A Members section will at minimum contain either a Member: Email or a Member: Username field'), array('class' => 'help'))
				);
			}

			$fieldset->appendChild($div);

			$context['wrapper']->appendChild($fieldset);
		}

		/**
		 * Saves the Member Section to the configuration
		 *
		 * @uses savePreferences
		 *
		 * @param array $context
		 * @return boolean
		 */
		public function savePreferences(array &$context){
			$settings = $context['settings'];

			// Active Section
			Symphony::Configuration()->set('section', $settings['members']['section'], 'members');

			return Symphony::Configuration()->write();
		}

	/*-------------------------------------------------------------------------
		Role Manager:
	-------------------------------------------------------------------------*/

		public function checkFrontendPagePermissions($context) {
			$isLoggedIn = false;
			$errors = array();

			// Checks $_REQUEST to see if a Member Action has been requested,
			// member-action['login'] and member-action['logout']/?member-action=logout
			// are the only two supported at this stage.
			if(is_array($_REQUEST['member-action'])){
				list($action) = array_keys($_REQUEST['member-action']);
			} else {
				$action = $_REQUEST['member-action'];
			}

			// Check to see a Member is already logged in.
			$isLoggedIn = $this->getMemberDriver()->isLoggedIn($errors);

			// Logout
			if(trim($action) == 'logout') {
				/**
				 * Fired just before a member is logged out (and page redirection),
				 * this delegate provides the current Member ID
				 *
				 * @delegate MembersPreLogout
				 * @param string $context
				 *  '/frontend/'
				 * @param integer $member_id
				 *  The Member ID of the member who is about to logged out
				 */
				Symphony::ExtensionManager()->notifyMembers('MembersPreLogout', '/frontend/', array(
					'member_id' => $this->getMemberDriver()->getMemberID()
				));

				$this->getMemberDriver()->logout();

				// If a redirect is provided, redirect to that, otherwise return the user
				// to the index of the site. Issue #51 & #121
				if(isset($_REQUEST['redirect'])) redirect($_REQUEST['redirect']);

				redirect(URL);
			}

			// Login
			else if(trim($action) == 'login' && !is_null($_POST['fields'])) {
				// If a Member is already logged in and another Login attempt is requested
				// log the Member out first before trying to login with new details.
				if($isLoggedIn) {
					$this->getMemberDriver()->logout();
				}
				if($this->getMemberDriver()->login($_POST['fields'])) {
					/**
					 * Fired just after a Member has successfully logged in, this delegate
					 * provides the current Member ID. This delegate is fired just before
					 * the page redirection (if it is provided)
					 *
					 * @delegate MembersPostLogin
					 * @param string $context
					 *  '/frontend/'
					 * @param integer $member_id
					 *  The Member ID of the member who just logged in.
					 * @param Entry $member
					 *  The Entry object of the logged in Member.
					 */
					Symphony::ExtensionManager()->notifyMembers('MembersPostLogin', '/frontend/', array(
						'member_id' => $this->getMemberDriver()->getMemberID(),
						'member' => $this->getMemberDriver()->getMember()
					));

					if(isset($_POST['redirect'])) redirect($_POST['redirect']);
				}
				else {
					self::$_failed_login_attempt = true;
				}
			}

			$this->Member->initialiseMemberObject();

			if($isLoggedIn && $this->getMemberDriver()->getMember() instanceOf Entry) {
				$this->updateSystemTimezoneOffset($this->getMemberDriver()->getMemberID());

				if(!is_null(extension_Members::getFieldHandle('role'))) {
					$role_data = $this->getMemberDriver()->getMember()->getData(extension_Members::getField('role')->get('id'));
				}
			}

			// If there is no role field, or a Developer is logged in, return, as Developers
			// should be able to access every page.
			if(
				is_null(extension_Members::getFieldHandle('role'))
				|| (Frontend::instance()->Author instanceof Author && Frontend::instance()->Author->isDeveloper())
			) return;

			$role_id = ($isLoggedIn) ? $role_data['role_id'] : Role::PUBLIC_ROLE;
			$role = RoleManager::fetch($role_id);

			if($role instanceof Role && !$role->canAccessPage((int)$context['page_data']['id'])) {
				// User has no access to this page, so look for a custom 403 page
				if($row = PageManager::fetchPageByType('403')) {
					$row['type'] = PageManager::fetchPageTypes($row['id']);
					$row['filelocation'] = PageManager::resolvePageFileLocation($row['path'], $row['handle']);

					$context['page_data'] = $row;
					return;
				}
				else {
					// No custom 403, just throw default 403
					GenericExceptionHandler::$enabled = true;
					throw new SymphonyErrorPage(
						__('The page you have requested has restricted access permissions.'),
						__('Forbidden'),
						'error',
						array('header' => 'HTTP/1.0 403 Forbidden')
					);
				}
			}
		}

	/*-------------------------------------------------------------------------
		Events:
	-------------------------------------------------------------------------*/

		/**
		 * Adds Javascript to the custom Members events when they are viewed in the
		 * backend to enable developers to set the appropriate Email Templates for
		 * each event
		 *
		 * @uses AdminPagePreGenerate
		 *
		 * @param $context
		 */
		public function appendAssets(&$context) {
			if(class_exists('Administration')
				&& Administration::instance() instanceof Administration
				&& Administration::instance()->Page instanceof HTMLPage
			) {
				$callback = Administration::instance()->getPageCallback();

				// Event Info
				if(
					$context['oPage'] instanceof contentBlueprintsEvents &&
					$callback['context'][0] == "info" &&
					in_array($callback['context'][1], extension_Members::$member_events)
				) {
					Administration::instance()->Page->addScriptToHead(URL . '/extensions/members/assets/members.events.js', 10001, false);
				}
				// Temporary fix
				else if($context['oPage'] instanceof contentPublish) {
					Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/members/assets/members.publish.css', 'screen', 45);
				}
			}
		}

		/**
		 * This function will ensure that the user who has submitted the form (and
		 * hence is requesting that an event be triggered) is actually allowed to
		 * do this request.
		 * There are 2 action types, creation and editing. Creation is a simple yes/no
		 * affair, whereas editing has three levels of permission, None, Own Entries
		 * or All Entries:
		 * - None: This user can't do process this event
		 * - Own Entries: If the entry the user is trying to update is their own
		 *   determined by if the `entry_id` or, in the case of a SBL or
		 *   similar field, the `entry_id` of the linked entry matches the logged in
		 *   user's id, process the event.
		 * - All Entries: The user can update any entry in Symphony.
		 * If there are no Roles in this system, or the event is set to ignore permissions
		 * (by including a function, `ignoreRolePermissions` that returns `true`, it will
		 * immediately proceed to processing any of the Filters attached to the event
		 * before returning.
		 *
		 * @uses EventPreSaveFilter
		 *
		 * @param array $context
		 * @return null
		 */
		public function checkEventPermissions(array &$context){
			// If this system has no Roles, or the event is set to ignore role permissions
			// continue straight to processing the Filters
			if(
				is_null(extension_Members::getFieldHandle('role')) ||
				(method_exists($context['event'], 'ignoreRolePermissions') && $context['event']->ignoreRolePermissions() == true)
			) {
				$this->__processEventFilters($context);
				return null;
			}

			// Prior to Symphony 2.2.2, the EventPreSaveFilter delegate doesn't
			// pass the `$entry_id`. This can cause an issue when an Event has the
			// `allow_multiple` filter set as we can't determine the correct `$entry_id`
			// This will check to see if the `$entry_id` is set, otherwise fallback
			// to the previous logic. This will mean that using `allow_multiple` will
			// not be compatible without Symphony 2.2.2 and Members 1.1
			// @see https://github.com/symphonycms/members/issues/167
			if(isset($context['entry_id']) && is_numeric($context['entry_id'])) {
				$entry_id = (int)$context['entry_id'];
				$action = 'edit';
			}
			else if(isset($_POST['id']) && !empty($_POST['id'])) {
				$entry_id = (int)$_POST['id'];
				$action = 'edit';
			}
			else {
				$action = 'create';
				$entry_id = 0;
			}

			$required_level = $action == 'create' ? EventPermissions::CREATE : EventPermissions::ALL_ENTRIES;
			$role_id = Role::PUBLIC_ROLE;

			$isLoggedIn = $this->getMemberDriver()->isLoggedIn();

			if($isLoggedIn && $this->getMemberDriver()->initialiseMemberObject()) {
				if($this->getMemberDriver()->getMember() instanceOf Entry) {
					$required_level = EventPermissions::OWN_ENTRIES;
					$role_data = $this->getMemberDriver()->getMember()->getData(extension_Members::getField('role')->get('id'));
					$role_id = $role_data['role_id'];

					if($action == 'edit' && method_exists($context['event'], 'getSource')) {
						$section_id = $context['event']->getSource();
						$isOwner = false;

						// If the event is the same section as the Members section, then for `$isOwner`
						// to be true, the `$entry_id` must match the currently logged in user.
						if($section_id == extension_Members::getMembersSection()) {
							// Check the logged in member is the same as the `entry_id` that is about to
							// be updated. If so the user is the Owner and can modify EventPermissions::OWN_ENTRIES
							$isOwner = ($this->getMemberDriver()->getMemberID() == $entry_id);
						}

						// If the $section_id !== members_section, check the section associations table
						// for any links to either of the Member fields that my be used for linking,
						// that is the Username or Email field.
						else {
							$field_ids = array();

							// Get the ID's of the fields that may be used for Linking (Username/Email)
							if(!is_null(extension_Members::getFieldHandle('identity'))) {
								$field_ids[] = extension_Members::getField('identity')->get('id');
							}

							if(!is_null(extension_Members::getFieldHandle('email'))) {
								$field_ids[] = extension_Members::getField('email')->get('id');
							}

							// Query for the `field_id` of any linking fields that link to the members
							// section AND to one of the linking fields (Username/Email)
							$fields = Symphony::Database()->fetchCol('child_section_field_id', sprintf("
									SELECT `child_section_field_id`
									FROM `tbl_sections_association`
									WHERE `parent_section_id` = %d
									AND `child_section_id` = %d
									AND `parent_section_field_id` IN ('%s')
								",
								extension_Members::getMembersSection(),
								$section_id,
								implode("','", $field_ids)
							));

							// If there was a link found, get the `relation_id`, which is the `member_id` of
							// an entry in the active Members section.
							if(!empty($fields)) {
								foreach($fields as $field_id) {
									if($isOwner === true) break;
									$field = FieldManager::fetch($field_id);
									if($field instanceof Field) {
										// So we are trying to find all entries that have selected the Member entry
										// to determine ownership. This check will use the `fetchAssociatedEntryIDs`
										// function, which typically works backwards, by accepting the `entry_id` (in
										// this case, our logged in Member ID). This will return an array of all the
										// linked entries, so we then just check that the current entry that is going to
										// be updated is in that array
										$member_id = $field->fetchAssociatedEntryIDs($this->getMemberDriver()->getMemberID());
										$isOwner = in_array($entry_id, $member_id);
									}
								}
							}
						}

						// User is not the owner, so they can edit EventPermissions::ALL_ENTRIES
						if($isOwner === false) $required_level = EventPermissions::ALL_ENTRIES;
					}
				}
			}

			$role = RoleManager::fetch($role_id);
			$event_handle = strtolower(preg_replace('/^event/i', NULL, get_class($context['event'])));
			$success = $role->canProcessEvent($event_handle, $action, $required_level) ? true : false;

			$context['messages'][] = array(
				'permission',
				$success,
				($success === false) ? __('You are not authorised to perform this action.') : null
			);

			// Process the Filters for this event.
			$this->__processEventFilters($context);
		}

		/**
		 * We can safely assume at this stage of the process that whatever user has
		 * requested this event has permission to actually do so.
		 *
		 * @param array $context
		 */
		private function __processEventFilters(array &$context) {
			// Process the Member Lock Role
			if (in_array('member-lock-role', $context['event']->eParamFILTERS)) {
				$this->getMemberDriver()->filter_LockRole($context);
			}

			// Process the Member Lock Activation
			if (in_array('member-lock-activation', $context['event']->eParamFILTERS)) {
				$this->getMemberDriver()->filter_LockActivation($context);
			}

			// Process updating a Member's Password
			if (in_array('member-update-password', $context['event']->eParamFILTERS)) {
				$this->getMemberDriver()->filter_UpdatePassword($context);
			}
		}

		/**
		 * Any post save behaviour
		 *
		 * @uses EventPostSaveFilter
		 *
		 * @param array $context
		 */
		public function processPostSaveFilter(array &$context) {
			// Process updating a Member's Password
			if (in_array('member-update-password', $context['event']->eParamFILTERS)) {
				$this->getMemberDriver()->filter_UpdatePasswordLogin($context);
			}
		}

	/*-------------------------------------------------------------------------
		Output:
	-------------------------------------------------------------------------*/

		public function addMemberDetailsToPageParams(array $context = null) {
			$this->getMemberDriver()->addMemberDetailsToPageParams($context);
		}

		public function appendLoginStatusToEventXML(array $context = null){
			$this->getMemberDriver()->appendLoginStatusToEventXML($context);
		}

	}


text:
#ifndef INCLUDE_LOGGER_H
#define INCLUDE_LOGGER_H

#include <string>
#include <sstream>
#include <cstdio>

enum LogLevel : uint8_t {
	INFO,
	WARN,
	ERROR,
	DEBUG
};

#define Log(level) Logger().log(level)

/**
* Class used for logging.
*
*/
class Logger {

	public:
		Logger();
		virtual ~Logger();

		std::ostringstream& log(const LogLevel level_);

	private:
		std::string levelToString(const LogLevel level_);

		std::ostringstream os;

};

#endif //INCLUDE_LOGGER_H

redpajama_set_name: RedPajamaGithub


text:
package com.o2d.pkayjava.runtime.systems.render;

import box2dLight.RayHandler;

import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Affine2;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World;
import com.o2d.pkayjava.runtime.commons.IExternalItemType;
import com.o2d.pkayjava.runtime.components.CompositeTransformComponent;
import com.o2d.pkayjava.runtime.components.MainItemComponent;
import com.o2d.pkayjava.runtime.components.NodeComponent;
import com.o2d.pkayjava.runtime.components.ParentNodeComponent;
import com.o2d.pkayjava.runtime.components.TransformComponent;
import com.o2d.pkayjava.runtime.components.ViewPortComponent;
import com.o2d.pkayjava.runtime.physics.PhysicsBodyLoader;
import com.o2d.pkayjava.runtime.systems.render.logic.DrawableLogicMapper;

public class Overlap2dRenderer extends IteratingSystem {
    private final float TIME_STEP = 1f / 60;

    private ComponentMapper<ViewPortComponent> viewPortMapper = ComponentMapper.getFor(ViewPortComponent.class);
    private ComponentMapper<CompositeTransformComponent> compositeTransformMapper = ComponentMapper.getFor(CompositeTransformComponent.class);
    private ComponentMapper<NodeComponent> nodeMapper = ComponentMapper.getFor(NodeComponent.class);
    private ComponentMapper<ParentNodeComponent> parentNodeMapper = ComponentMapper.getFor(ParentNodeComponent.class);
    private ComponentMapper<TransformComponent> transformMapper = ComponentMapper.getFor(TransformComponent.class);
    private ComponentMapper<MainItemComponent> mainItemComponentMapper = ComponentMapper.getFor(MainItemComponent.class);

    private DrawableLogicMapper drawableLogicMapper;
    private RayHandler rayHandler;
    private World world;
    private boolean isPhysicsOn = true;

    private float accumulator = 0;
    //private Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();

    public Batch batch;

    public Overlap2dRenderer(Batch batch) {
        super(Family.all(ViewPortComponent.class).get());
        this.batch = batch;
        drawableLogicMapper = new DrawableLogicMapper();
    }

    public void addDrawableType(com.o2d.pkayjava.runtime.commons.IExternalItemType itemType) {
        drawableLogicMapper.addDrawableToMap(itemType.getTypeId(), itemType.getDrawable());
    }

    @Override
    public void processEntity(Entity entity, float deltaTime) {
        ViewPortComponent ViewPortComponent = viewPortMapper.get(entity);
        Camera camera = ViewPortComponent.viewPort.getCamera();
        camera.update();
        batch.setProjectionMatrix(camera.combined);
        batch.begin();
        drawRecursively(entity);
        batch.end();

        //TODO kinda not cool (this should be done in separate lights renderer maybe?
        if (rayHandler != null) {
            rayHandler.setCulling(false);
            OrthographicCamera orthoCamera = (OrthographicCamera) camera;
            camera.combined.scl(1f / PhysicsBodyLoader.getScale());
            rayHandler.setCombinedMatrix(orthoCamera);
            rayHandler.updateAndRender();
        }

        if (world != null && isPhysicsOn) {
            doPhysicsStep(deltaTime);
        }

        //debugRenderer.render(world, camera.combined);
        //TODO Spine rendere thing
    }

    private void doPhysicsStep(float deltaTime) {
        // fixed time step
        // max frame time to avoid spiral of death (on slow devices)
        float frameTime = Math.min(deltaTime, 0.25f);
        accumulator += frameTime;
        while (accumulator >= TIME_STEP) {
            world.step(TIME_STEP, 6, 2);
            accumulator -= TIME_STEP;
        }
    }

    private void drawRecursively(Entity rootEntity) {

        //currentComposite = rootEntity;
        CompositeTransformComponent curCompositeTransformComponent = compositeTransformMapper.get(rootEntity);

        if (curCompositeTransformComponent.transform) {
            computeTransform(rootEntity);
            applyTransform(rootEntity, batch);
        }
        drawChildren(rootEntity, batch, curCompositeTransformComponent);
        if (curCompositeTransformComponent.transform) resetTransform(rootEntity, batch);
    }

    private void drawChildren(Entity rootEntity, Batch batch, CompositeTransformComponent curCompositeTransformComponent) {
        NodeComponent nodeComponent = nodeMapper.get(rootEntity);
        Entity[] children = nodeComponent.children.begin();
        if (curCompositeTransformComponent.transform) {
            for (int i = 0, n = nodeComponent.children.size; i < n; i++) {
                Entity child = children[i];

                MainItemComponent childMainItemComponent = mainItemComponentMapper.get(child);
                if (!childMainItemComponent.visible) {
                    continue;
                }

                int entityType = childMainItemComponent.entityType;

                //TODO Alpha thing

                NodeComponent childNodeComponent = nodeMapper.get(child);

                if (childNodeComponent == null) {
                    //Find logic from the mapper and draw it
                    drawableLogicMapper.getDrawable(entityType).draw(batch, child);
                } else {
                    //Step into Composite
                    drawRecursively(child);
                }
            }
        } else {
            // No transform for this group, offset each child.
            TransformComponent compositeTransform = transformMapper.get(rootEntity);

            float offsetX = compositeTransform.getX(), offsetY = compositeTransform.getY();

            if (viewPortMapper.has(rootEntity)) {
                offsetX = 0;
                offsetY = 0;
            }

            for (int i = 0, n = nodeComponent.children.size; i < n; i++) {
                Entity child = children[i];

                //TODO visibility and parent Alpha thing
                //if (!child.isVisible()) continue;
                //if (!child.isVisible()) continue;

                TransformComponent childTransformComponent = transformMapper.get(child);
                float cx = childTransformComponent.getX(), cy = childTransformComponent.getY();
                childTransformComponent.setX(cx + offsetX);
                childTransformComponent.setY(cy + offsetY);

                NodeComponent childNodeComponent = nodeMapper.get(child);
                int entityType = mainItemComponentMapper.get(child).entityType;

                if (childNodeComponent == null) {
                    //Finde the logic from mapper and draw it
                    drawableLogicMapper.getDrawable(entityType).draw(batch, child);
                } else {
                    //Step into Composite
                    drawRecursively(child);
                }
                childTransformComponent.setX(cx);
                childTransformComponent.setY(cy);

                if (childNodeComponent != null) {
                    drawRecursively(child);
                }
            }
        }
        nodeComponent.children.end();
    }

    /**
     * Returns the transform for this group's coordinate system.
     *
     * @param rootEntity
     */
    protected Matrix4 computeTransform(Entity rootEntity) {
        CompositeTransformComponent curCompositeTransformComponent = compositeTransformMapper.get(rootEntity);
        //NodeComponent nodeComponent = nodeMapper.get(rootEntity);
        ParentNodeComponent parentNodeComponent = parentNodeMapper.get(rootEntity);
        TransformComponent curTransform = transformMapper.get(rootEntity);
        Affine2 worldTransform = curCompositeTransformComponent.worldTransform;
        //TODO origin thing
        float originX = 0;
        float originY = 0;
        float x = curTransform.getX();
        float y = curTransform.getY();
        float rotation = curTransform.getRotation();
        float scaleX = curTransform.getScaleX();
        float scaleY = curTransform.getScaleY();

        worldTransform.setToTrnRotScl(x + originX, y + originY, rotation, scaleX, scaleY);
        if (originX != 0 || originY != 0) worldTransform.translate(-originX, -originY);

        // Find the first parent that transforms.

        CompositeTransformComponent parentTransformComponent = null;
        //NodeComponent parentNodeComponent;

        Entity parentEntity = null;
        if (parentNodeComponent != null) {
            parentEntity = parentNodeComponent.parentEntity;
        }
//		if (parentEntity != null){
//
//		}

//		while (parentEntity != null) {
//			parentNodeComponent = nodeMapper.get(parentEntity);
//			if (parentTransformComponent.transform) break;
//			System.out.println("Gand");
//			parentEntity = parentNodeComponent.parentEntity;
//			parentTransformComponent = compositeTransformMapper.get(parentEntity);
//
//		}

        if (parentEntity != null) {
            parentTransformComponent = compositeTransformMapper.get(parentEntity);
            worldTransform.preMul(parentTransformComponent.worldTransform);
            //MainItemComponent main = parentEntity.getComponent(MainItemComponent.class);
            //System.out.println("NAME " + main.itemIdentifier);
        }

        curCompositeTransformComponent.computedTransform.set(worldTransform);
        return curCompositeTransformComponent.computedTransform;
    }

    protected void applyTransform(Entity rootEntity, Batch batch) {
        CompositeTransformComponent curCompositeTransformComponent = compositeTransformMapper.get(rootEntity);
        curCompositeTransformComponent.oldTransform.set(batch.getTransformMatrix());
        batch.setTransformMatrix(curCompositeTransformComponent.computedTransform);
    }

    protected void resetTransform(Entity rootEntity, Batch batch) {
        CompositeTransformComponent curCompositeTransformComponent = compositeTransformMapper.get(rootEntity);
        batch.setTransformMatrix(curCompositeTransformComponent.oldTransform);
    }

    public void setRayHandler(RayHandler rayHandler) {
        this.rayHandler = rayHandler;
    }

    public void setBox2dWorld(World world) {
        this.world = world;
    }

    public void setPhysicsOn(boolean isPhysicsOn) {
        this.isPhysicsOn = isPhysicsOn;
    }

    public Batch getBatch() {
        return batch;
    }
}


text:
package com.devsar.android.ucbindings;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by Juan on 8/11/16.
 */

public class UCB {

    public static <T> Observable<T> timer(Func1<Long, T> mappingFunction, int seconds) {
        return Observable.interval(1, TimeUnit.SECONDS, Schedulers.computation())
                .take(seconds)
                .map(mappingFunction);
    }

    public static <T> Observable<T> timer(Func1<Long, T> mappingFunction) {
        return timer(mappingFunction, 60);
    }

    public static <T> Observable<T> poll(Func1<Long, Observable<T>> pollObservable, Func1<T, Boolean> until) {
        return Observable.interval(1, TimeUnit.SECONDS, Schedulers.io())
                .flatMap(pollObservable)
                .takeUntil(until)
                .filter(until);
    }
}


text:
[![license: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/avramidis/FigureWhitespaceRemove/blob/master/LICENSE)
[![DOI](https://zenodo.org/badge/49196982.svg)](https://zenodo.org/badge/latestdoi/49196982)

FigureWhitespaceRemove is a MATLAB function for the removal of white space around exported figures to png and tiff files.

## Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

### Prerequisites

To download the code you can use the "clone or download" button to download the zip with the code or use git.
To install git on Ubuntu use the following commands in a terminal

```
sudo apt update
sudo apt install git
```

To pull the repository from github use the following command in a terminal

```
git clone https://github.com/avramidis/FigureWhitespaceRemove.git
```

### Installing

To use FigureWhitespaceRemove function in any folder use the following command in MATLAB in the folder where FigureWhitespaceRemove folder is located. More information can be found at https://www.mathworks.com/help/matlab/ref/addpath.html

```
addpath('FigureWhitespaceRemove')
```

### Example

An example code that uses FigureWhitespaceRemove is the following

```matlab
iminfo=figureWhitespaceRemove('testFigure');
```

If the run was successful the output will be the iminfor struct that includes information about the image generated by the testFigure.fig. Also, the images testFigure.png and testFigure.tif are generated.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

## How to cite FigureWhitespaceRemove
To cite FigureWhitespaceRemove please cite the URL and the DOI of the release version you used. The DOI of the latest release is at the badge at the top of this README.md file.

## Acknowledgments

* This readme file is based on the template found at https://gist.github.com/PurpleBooth/109311bb0361f32d87a2


text:
/**
 * ajax
 * Utility to perform ajax get and post requests. Supported browsers:
 * Chrome, Firefox, Opera, Safari, Internet Explorer 7+.
 */
var ajax = (function () {
    function fetch (method, url, body, headers, callback) {
        try {
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function() {
                if (xhr.readyState == 4) {
                    callback(xhr.responseText, xhr.status);
                }
            };
            xhr.open(method, url, true);
            if (headers) {
                for (var name in headers) {
                    if (headers.hasOwnProperty(name)) {
                        xhr.setRequestHeader(name, headers[name]);
                    }
                }
            }
            xhr.send(body);
        }
        catch (err) {
            callback(err, 0);
        }
    }

    function get (url, headers, callback) {
        fetch('GET', url, null, headers, callback);
    }

    function post (url, body, headers, callback) {
        fetch('POST', url, body, headers, callback)
    }

    return {
        'fetch': fetch,
        'get': get,
        'post': post
    }
})();


text:
package de.hofuniversity.iisys.neo4j.websock.query;

import java.util.HashMap;
import java.util.Map;

/**
 * Basic class for all queries sent over the websocket connection, having at
 * least a type and an ID for response identification.
 * Optionally, there can be a payload and named parameters, each being either
 * of primitive types, maps or lists.
 */
public class WebsockQuery
{
    private int fId;
    private EQueryType fType;

    private Object fPayload;
    private Map<String, Object> fParameters;

    /**
     * Creates an empty ping type query with ID 0.
     */
    public WebsockQuery()
    {
        this(0, EQueryType.PING);
    }

    /**
     * Creates an empty query with ID 0 and the given type.
     * The type may not be null.
     *
     * @param type query type
     */
    public WebsockQuery(EQueryType type)
    {
        this(0, type);
    }

    /**
     * Creates a query with the given ID and type.
     * The type may not be null.
     *
     * @param id query ID
     * @param type query type
     */
    public WebsockQuery(int id, EQueryType type)
    {
        if(type == null)
        {
            throw new RuntimeException("query type was null");
        }

        fId = id;
        fType = type;

        fParameters = new HashMap<String, Object>();
    }

    /**
     * @return internal parameter map
     */
    public Map<String, Object> getParameters()
    {
        return fParameters;
    }

    /**
     * Sets the internal parameter map, replacing the old one.
     * The map given may not be null.
     *
     * @param parameters new internal parameter map
     */
    public void setParameters(Map<String, Object> parameters)
    {
        if(parameters == null)
        {
            throw new NullPointerException("parameter map was null");
        }

        fParameters = parameters;
    }

    /**
     * @param key name of the parameter to retrieve
     * @return value of the parameter or null
     */
    public Object getParameter(String key)
    {
        return fParameters.get(key);
    }

    /**
     * Sets a named parameter to a certain value. Only primitive types, maps
     * and lists are valid values.
     *
     * @param key name of the parameter to set
     * @param value value of the parameter to set
     */
    public void setParameter(String key, Object value)
    {
        fParameters.put(key, value);
    }

    /**
     * @return ID of the websocket query
     */
    public int getId()
    {
        return fId;
    }

    /**
     * @param fId new ID for the query
     */
    public void setId(int id)
    {
        fId = id;
    }

    /**
     * @return the query's type
     */
    public EQueryType getType()
    {
        return fType;
    }

    /**
     * Sets a new type for this query which may not be null.
     *
     * @param type new type for the query
     */
    public void setType(EQueryType type)
    {
        if(type == null)
        {
            throw new NullPointerException("query type was null");
        }

        this.fType = type;
    }

    /**
     * @return payload of the query or null
     */
    public Object getPayload()
    {
        return fPayload;
    }

    /**
     * Sets the query's payload.
     * Only primitive types, maps and lists are valid values.
     *
     * @param payload new payload for the query
     */
    public void setPayload(Object payload)
    {
        this.fPayload = payload;
    }
}


text:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * File survey2.fix.php
 * Fixtures for survey2
 *
 * Since the id comes from autoincrement, the loading order is important.
 */

  // Copy files for survey : Handlebars vs something else
  copy('resources/fixtures_data/survey_2_xls.xls', 'files/surveys/survey_2_xls.xls');
  copy('resources/fixtures_data/survey_2_xml.xml', 'files/surveys/survey_2_xml.xml');

  // Survey 2.
  $survey = new Survey_entity(array(
    // Sid will be 2 (auto increment)
    'title' => 'Handlebars',
    'client' => 'Digital Dreams Inc',
    'status' => Survey_entity::STATUS_OPEN,
    'goal' => 20,
    'introduction' => 'Hi, my name is ______ and I am calling on behalf of Digital Dreams. Handlebars is interested in learning more about you and your relation with it. You are being contacted because of your participation in the workshop held near your house. We would like to ask you some questions about your coffee consumption while using handlebars. Your participation is very important, because your responses will help us improve our framework and thus make it more usable. This survey will only take about 5 minutes of your time.',
    'description' => 'This survey will help us understand how handlebars is used by developers and how it can be improved.',
    'files' => array(
      'xls' => "survey_2_xls.xls",
      'xml' => "survey_2_xml.xml",
      'last_conversion' => array(
        'date' => NULL,
        'warnings' => NULL,
      )
     )
  ));
  // Assign agent, user 3
  $survey->assign_agent(3);
  $this->survey_model->save($survey);

  //////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////
  // Call task.
  $call_task = new Call_task_entity(array(
    // uid will be 1 (auto increment)
    'number' => "1000000000001",
    'assigned' => Mongo_db::date(),
    'author' => 1, // Admin
    'assignee_uid' => 3, // The Agent
    'survey_sid' => 2, // Handlebars - Applied knowledge
  ));

  $call_task->add_status(new Call_task_status(array(
    'code' => Call_task_status::NO_REPLY,
    'message' => NULL,
    'author' => 3, // The Agent (The author is usually the assignee)
    'created' => Mongo_db::date()
  )));

  $call_task->add_status(new Call_task_status(array(
    'code' => Call_task_status::NO_REPLY,
    'message' => NULL,
    'author' => 3, // The Agent (The author is usually the assignee)
    'created' => Mongo_db::date()
  )));

  $this->call_task_model->save($call_task);

  ///////////////////////////////////////////////////////
  // Call task.
  $call_task = new Call_task_entity(array(
    // uid will be 2 (auto increment)
    'number' => "1000000000002",
    'assigned' => Mongo_db::date(),
    'author' => 1, // Admin
    'assignee_uid' => 3, // The Agent
    'survey_sid' => 2, // Handlebars - Applied knowledge
  ));

  $call_task->add_status(new Call_task_status(array(
    'code' => Call_task_status::CANT_COMPLETE,
    'message' => 'Not to be done right now. Maybe later.',
    'author' => 3, // The Agent (The author is usually the assignee)
    'created' => Mongo_db::date()
  )));

  $this->call_task_model->save($call_task);

  ///////////////////////////////////////////////////////
  // Call task.
  $call_task = new Call_task_entity(array(
    // uid will be 3 (auto increment)
    'number' => "1000000000003",
    'assigned' => Mongo_db::date(),
    'author' => 1, // Admin
    'assignee_uid' => 3, // The Agent
    'survey_sid' => 2, // Handlebars - Applied knowledge
  ));

  $call_task->add_status(new Call_task_status(array(
    'code' => Call_task_status::INVALID_NUMBER,
    'message' => NULL,
    'author' => 3, // The Agent (The author is usually the assignee)
    'created' => Mongo_db::date()
  )));

  $this->call_task_model->save($call_task);

  ///////////////////////////////////////////////////////

  // Add some respondents to be used for data collection.
  for($r = 0; $r < 100; $r++) {
    // Call task.
    $call_task = new Call_task_entity(array(
      // uid will be from 4 to 104 (auto increment)
      'number' => (string)(2000000000000 + $r),
      'assigned' => Mongo_db::date(),
      'author' => 1, // Admin
      ///'assignee_uid' => NULL // Not assigned
      'survey_sid' => 2, // Handlebars - Applied knowledge
    ));

    $this->call_task_model->save($call_task);
  }


text:
package br.com.tamandua.ws.security;

/**
 *
 * @author SmartSW
 *

 * Exceção para Erro de Assinatura de Password.
 *

 *
Extends :	 RuntimeException

 *

 *
 */
public class PasswordSignatureException extends RuntimeException {

	private static final long serialVersionUID = 6245931481360438862L;

	/**
	 * Construtor padrão para Exceção com mensagem e a Causa da Exceção.
	 * @param message atributo message do Tipo String para montagem da Exceção.
	 * @param cause causa da Exceção gerada.
	 */
	public PasswordSignatureException(String message, Throwable cause){
		super(message, cause);
	}
}


text:
<?php

namespace morph;

require_once dirname(__FILE__).'/../src/morph/Enum.php';
require_once dirname(__FILE__).'/../src/morph/IQuery.php';
require_once dirname(__FILE__).'/../src/morph/query/Property.php';
require_once dirname(__FILE__).'/../src/morph/Query.php';

/**
 * @package Morph
 */
class TestQuery extends \PHPUnit_Framework_TestCase
{

    public function testLimit()
    {
        $query = new Query();
        $query->limit(10);
        $this->assertEquals(10, $query->getLimit());
    }

    public function testSkip()
    {
        $query = new Query();
        $query->skip(10);
        $this->assertEquals(10, $query->getSkip());
    }

    public function testProperty()
    {
        $expected = array('bob' => 'hoskins');
        $query = new Query();
        $query->property('bob')->equals('hoskins');
        $this->assertEquals($expected, $query->getRawQuery());

    }

    public function testFluent()
    {
        $expected = array('bob' => 'hoskins');
        $query = Query::instance()
        ->property('bob')
        ->equals('hoskins');
        $this->assertEquals($expected, $query->getRawQuery());
    }

    public function testMultipleProperties()
    {
        $expected = array('bob' => 'hoskins', 'abc' => 12);
        $query = Query::instance()
        ->property('bob')
        ->equals('hoskins')
        ->property('abc')
        ->equals(12);
        $this->assertEquals($expected, $query->getRawQuery());
    }

    public function testFullFluency()
    {
        $expected = array('bob' => 'hoskins', 'abc' => 12);
        $query = Query::instance()
        ->limit(10)->skip(12)
        ->property('bob')
        ->equals('hoskins')
        ->sort(1)
        ->property('abc')
        ->equals(12);
        $this->assertEquals($expected, $query->getRawQuery());
        $this->assertEquals(10, $query->getLimit());
        $this->assertEquals(12, $query->getSkip());
        $this->assertEquals(array('bob'=>1), $query->getRawSort());
    }
}


text:
package com.freetymekiyan.algorithms.level.medium;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 402. Remove K Digits
 *

 * Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is
 * the smallest possible.
 *

 * Note:
 * The length of num is less than 10002 and will be ≥ k.
 * The given num does not contain any leading zero.
 *

 * Example 1:
 *

 * Input: num = "1432219", k = 3
 * Output: "1219"
 * Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.
 *

 * Example 2:
 *

 * Input: num = "10200", k = 1
 * Output: "200"
 * Explanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.
 *

 * Example 3:
 *

 * Input: num = "10", k = 2
 * Output: "0"
 * Explanation: Remove all the digits from the number and it is left with nothing which is 0.
 *

 * Tags: Stack, Greedy
 * Similar Problems: (H) Create Maximum Number
 */
public class RemoveKDigits {

  private RemoveKDigits r;

  /**
   * Stack, Greedy.
   * Find the last digit of the increasing sequence and the first digit of the decreasing sequence.
   * Remove it and decrement k by 1.
   * Why is it greedy? Since operation like this will generate a smallest number for each removal.
   * Stop till k is zero.
   * Convert remaining string to a valid number format.
   */
  public String removeKdigits(String num, int k) {
    // Remove all
    if (num.length() == k) {
      return "0";
    }
    Deque<Character> stack = new ArrayDeque<>();
    for (int i = 0; i < num.length(); i++) {
      // Remove digits that are larger than current one in stack
      while (k > 0 && !stack.isEmpty() && stack.peek() > num.charAt(i)) {
        stack.pop();
        k--;
      }
      stack.push(num.charAt(i));
    }
    // If there are too few decreasing sequences
    while (k > 0) {
      stack.pop();
      k--;
    }
    // Convert characters in stack to a string
    StringBuilder sb = new StringBuilder();
    while (!stack.isEmpty()) {
      sb.append(stack.pop());
    }
    sb.reverse();
    // Trim leading zeros
    while (sb.length() > 1 && sb.charAt(0) == '0') {
      sb.deleteCharAt(0);
    }
    return sb.toString();
  }

  /**
   * Stack, Greedy.
   * The only difference is that stack is imitated with an Object(Character) array and a pointer to its top.
   * Because we know the largest possible size of a stack.
   */
  public String removeKdigitsB(String num, int k) {
    int len = num.length() - k;
    char[] stk = new char[num.length()];
    int top = 0;
    for (int i = 0; i < num.length(); i++) {
      char c = num.charAt(i);
      while (k > 0 && top > 0 && stk[top - 1] > c) {
        top--; // Pop
        k--;
      }
      stk[top++] = c; // Push
    }
    int offset = 0;
    while (offset < len && stk[offset] == '0') {
      offset++;
    }
    return offset == len ? "0" // All zeros
        : new String(stk, offset, len - offset);
  }

  @Before
  public void setUp() {
    r = new RemoveKDigits();
  }

  @Test
  public void testExamples() {
    Assert.assertEquals("1219", r.removeKdigits("1432219", 3));
    Assert.assertEquals("200", r.removeKdigits("10200", 1));
    Assert.assertEquals("0", r.removeKdigits("10", 2));
    Assert.assertEquals("1234", r.removeKdigits("123456", 2));
    Assert.assertEquals("5432", r.removeKdigits("765432", 2));
    // Test B
    Assert.assertEquals("1219", r.removeKdigitsB("1432219", 3));
    Assert.assertEquals("200", r.removeKdigitsB("10200", 1));
    Assert.assertEquals("0", r.removeKdigitsB("10", 2));
    Assert.assertEquals("1234", r.removeKdigitsB("123456", 2));
    Assert.assertEquals("5432", r.removeKdigitsB("765432", 2));
  }

  @After
  public void tearDown() {
    r = null;
  }

}


text:
var ExResponse = /** @class */ (function () {
    function ExResponse() {
    }
    ExResponse.type = {
        any: '',
        blob: 'blob',
        json: 'json',
        text: 'text',
        document: 'document',
        arraybuffer: 'arraybuffer'
    };
    return ExResponse;
}());
export { ExResponse };
//# sourceMappingURL=AudioImplementation.js.map


text:
var gulp = require('gulp'),
    plugins = require('gulp-load-plugins')(),
	rootPath = './'
;

// LESS
gulp.task('less', function() {
	return gulp.src(rootPath + 'rastr.less')
		.pipe(plugins.less({
			strictMath: true
		}))
		.pipe(plugins.autoprefixer('> 0.5%', 'last 2 versions', 'ie 10'))
		.pipe(plugins.cssnano({
			safe: false,
			calc: false
		}))
		.pipe(plugins.replace(/\.col-([^\}]*)\{-webkit-box-flex:0\}/g, '')) // remove redundant rules
		.pipe(plugins.replace(/-webkit-box-flex:0;/g, '')) // remove redundant rules
		.pipe(gulp.dest(rootPath))
	;
});

// WATCH
gulp.task('watch', function() {
	gulp.watch([rootPath + '*.less'], ['less']);
});

// DEFAULT
gulp.task('default', ['watch']);


text:
.. include:: ../README.rst

.. toctree::
   :maxdepth: 2
   :hidden:
   :caption: Using cetbuildtools2

   /users/introduction
   /users/CetCMakeSettings
   /users/CetCompilerSettings
   /users/CetInstallDirs
   /users/CetTest
   /users/CetUPS
   /users/CetCMakeUtilities
   /users/CetUninstallTarget
   /users/CetWriteCXXVersionAPI
   /users/BasicPlugin
   /users/CetMake

.. toctree::
   :maxdepth: 2
   :hidden:
   :caption: Additional Find Modules

   /find-modules/FindBoost
   /find-modules/FindCppUnit
   /find-modules/FindSQLite
   /find-modules/FindTBB

.. toctree::
   :maxdepth: 2
   :hidden:
   :caption: Developing cetbuildtools2

   /developers/cmakeguide
   /developers/cmakedocs


text:
using System.Linq;
using ModestTree;
using ModestTree.Util;
using UnityEngine;
using Zenject.Internal;

namespace Zenject
{
    public class ProjectKernel : MonoKernel
    {
        [Inject]
        ZenjectSettings _settings = null;

        // One issue with relying on MonoKernel.OnDestroy to call IDisposable.Dispose
        // is that the order that OnDestroy is called in is difficult to predict
        // One good thing is that it does follow the heirarchy order (so root game objects
        // will have thier OnDestroy called before child objects)
        // However, the order that OnDestroy is called for the root game objects themselves
        // is largely random
        // Within an individual scene, this can be helped somewhat by placing all game objects
        // underneath the SceneContext and then also checking the 'ParentNewObjectsUnderRoot'
        // property to ensure any new game objects will also be parented underneath SceneContext
        // By doing this, we can be guaranteed to have any bound IDisposable's have their
        // Dispose called before any game object is destroyed in the scene
        // However, when using multiple scenes (each with their own SceneContext) the order
        // that these SceneContext game objects are destroyed is random
        // So to address that, we explicitly call GameObject.DestroyImmediate for all
        // SceneContext's in the reverse order that the scenes were loaded in below
        // (this works because OnApplicationQuit is always called before OnDestroy)
        // Note that this only works when stopping the app and not when changing scenes
        // When changing scenes, if you have multiple scenes loaded at once, you will have to
        // manually unload the scenes in the reverse order they were loaded before going to
        // the new scene, if you require a predictable destruction order.  Or you can always use
        // ZenjectSceneLoader which will do this for you
        public void OnApplicationQuit()
        {
            if (_settings.EnsureDeterministicDestructionOrderOnApplicationQuit)
            {
                DestroyEverythingInOrder();
            }
        }

        public void DestroyEverythingInOrder()
        {
            ForceUnloadAllScenes(true);

            // Destroy project context after all scenes
            Assert.That(!IsDestroyed);
            GameObject.DestroyImmediate(this.gameObject);
            Assert.That(IsDestroyed);
        }

        public void ForceUnloadAllScenes(bool immediate = false)
        {
            // OnApplicationQuit should always be called before OnDestroy
            // (Unless it is destroyed manually)
            Assert.That(!IsDestroyed);

            // Destroy the scene contexts from bottom to top
            // Since this is the reverse order that they were loaded in
            foreach (var sceneContext in ZenUtilInternal.GetAllSceneContexts().Reverse().ToList())
            {
                if (immediate)
                {
                    GameObject.DestroyImmediate(sceneContext.gameObject);
                }
                else
                {
                    GameObject.Destroy(sceneContext.gameObject);
                }
            }
        }
    }
}

#endif


text:
@class TGTopicM;

@interface TGPicV : UIView
@property (nonatomic, strong) TGTopicM *topic;
@end


text:
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>ip::resolver_service::resolve</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../../../boost_asio.html" title="Boost.Asio">
<link rel="up" href="../ip__resolver_service.html" title="ip::resolver_service">
<link rel="prev" href="query_type.html" title="ip::resolver_service::query_type">
<link rel="next" href="resolve/overload1.html" title="ip::resolver_service::resolve (1 of 2 overloads)">

Home
Libraries
People
FAQ
More

ip::resolver_service::resolve

Resolve a query to a list of entries.

iterator_type resolve(
    implementation_type & impl,
    const query_type & query,
    boost::system::error_code & ec);
  » more...

          Resolve an endpoint to a list of entries.

iterator_type resolve(
    implementation_type & impl,
    const endpoint_type & endpoint,
    boost::system::error_code & ec);
  » more...

Copyright © 2003-2015 Christopher M.
      Kohlhoff

        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)


text:
package com.github.vcbr.bidr.profile.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "user_role", catalog = "bidr")
public class UserRoleImpl implements UserRole {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "user_role_id", unique = true, nullable = false)
	private Integer id;

	@ManyToOne(targetEntity = UserImpl.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id", nullable = false)
	private User user;

	@Column(name = "role", nullable = false, length = 45)
	private String role;

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getRole() {
		return this.role;
	}

	public void setRole(String role) {
		this.role = role;
	}

}