Example #1
0
public function __construct ($configs)
{
	parent::__construct($configs);

	if (!coren::depend('_path_normalizer_0'))
		throw new exception("Tool '_path_normalizer_0' missed.");

	if(isset($configs['lock_relax'])) $this->lock_relax = $configs['lock_relax'];
	if(isset($configs['lock_count'])) $this->lock_count = $configs['lock_count'];
	if(isset($configs['lock_sleep'])) $this->lock_sleep = $configs['lock_sleep'];

	if(isset($configs['chunk_size'])) $this->chunk_size = $configs['chunk_size'];
	$this->chink_size = (integer) $this->chunk_size;
	if ($this->chunk_size <= 0) $this->chunk_size = 1024;

	if(isset($configs['dir_path'    ])) $this->dir_path     = $configs['dir_path'    ];
	if(isset($configs['dir_absolute'])) $this->dir_absolute = $configs['dir_absolute'];
	if(isset($configs['dir_required'])) $this->dir_required = $configs['dir_required'];
	if(isset($configs['dir_automake'])) $this->dir_automake = $configs['dir_automake'];
	if(isset($configs['dir_umask'   ])) $this->dir_umask    = $configs['dir_umask'   ];
	$this->dir = _path_normalizer_0::normalize_dir($this->dir_path, $this->dir_absolute ? null : SITEPATH);
	if ($this->dir_automake && !file_exists($this->dir))
	{
		$old_umask = umask(octdec($this->dir_umask));
		mkdir($this->dir, 0777, true);
		umask($old_umask);
	}
	if ($this->dir_required && !is_dir($this->dir))
	{
		throw new exception("Required directory '{$this->dir}' does not exist.");
	}
}
Example #2
0
<?php defined('CORENINPAGE') or die('Hack!');
####################################################################################################
####################################################################################################
####################################################################################################
#
#...
#
####################################################################################################
####################################################################################################
####################################################################################################
#
if (!coren::depend('cache_directory_0')) return;
#
class cache_directory_string_0 extends cache_directory_0
{
#
####################################################################################################
####################################################################################################
####################################################################################################
#
public function __construct ($configs)
{
	parent::__construct($configs);
}
#
####################################################################################################
####################################################################################################
####################################################################################################
#
protected function _encode_ ($decoded)
{
Example #3
0
<?php defined('CORENINPAGE') or die('Hack!');
####################################################################################################
####################################################################################################
####################################################################################################
#
if (!coren::depend('generator_0')) return;
#
class generator_uniqid_0 extends generator_0
{
#
####################################################################################################
####################################################################################################
####################################################################################################
#
protected $prefix;
protected $entropy;
#
####################################################################################################
#
function __construct ($configs)
{
	parent::__construct($configs);

	if (isset($configs['prefix' ])) $this->prefix  = $configs['prefix' ];
	if (isset($configs['entropy'])) $this->entropy = $configs['entropy'];
}
#
####################################################################################################
####################################################################################################
####################################################################################################
#
Example #4
0
public function flush ($data)
{
	if (!coren::have($this->privilege_for_flush))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_not_authorized);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'flush', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'not-authorized', null));
			coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_not_authorized), $this->slot_for_not_authorized);
		}
//???		do nto throw here. see file ...inject... for reasoning.
//???		throw new exception("Not authorized to flush queue of messages.");
		return;
	}

	$limit = max(1, $this->limit_per_call);//min(max(1, $this->limit_per_call)/*, max(1, $this->limit_per_*), ...*/);
	$envelopes = coren::db('select_envelopes', compact('limit'));

	$reports = array();
	if (is_array($envelopes) && !empty($envelopes))
	{
		$identifiers = array();
		foreach ($envelopes as $envelope) $identifiers[] = $envelope['template'];
		$identifiers = array_unique($identifiers);
		$templates = empty($identifiers) ? array() : coren::db('select_templates', compact('identifiers'));

		foreach ($envelopes as $index => $item)
		{
			$envelope    = $item['envelope'   ];
			$template    = $item['template'   ];
			$recipient   = $item['recipient'  ];
			$current_try = $item['current_try'];
			$current_age = $item['current_age'];
			$subject = isset($templates[$template]['subject']) ? $templates[$template]['subject'] : null;
			$message = isset($templates[$template]['message']) ? $templates[$template]['message'] : null;

			try
			{
				$status = +1;
				$error = $errno = null;
				coren::event($this->event_for_send_message, compact('recipient', 'subject', 'message', 'envelope', 'template'));
			}
			catch (exception $exception)
			{
				$status = (isset($this->max_age) && ($current_age >= $this->max_age))
					||(isset($this->max_try) && ($current_try >= $this->max_try))
					? -1 : 0;
				$error  = $exception->getMessage();
				$errno  = $exception->getCode();
			}
			$reports[] = compact('envelope', 'template', 'recipient', 'error', 'errno', 'status');

			if ($this->one_by_one)
			if ($status <= 0)
			{
				coren::db('mark_envelope_failure', compact('envelope', 'error', 'errno', 'status'));
			} else
			{
				coren::db('mark_envelope_success', compact('envelope', 'status'));
			}
		}
	}

	if (!$this->one_by_one)
	{
		$envelopes = array();//NB: this is a list of identifiers of envelopes, that were successfuly sent.
		foreach ($reports as $report)
		{
			$envelope = $report['envelope'];
			$status   = $report['status'  ];
			if ($status <= 0)
			{
				$error = $report['error'];
				$errno = $report['errno'];
				coren::db('mark_envelope_failure', compact('envelope', 'error', 'errno', 'status'));
			} else
			{
				$envelopes[] = $envelope;
			}
		}
		if (!empty($envelopes))
		{
			$status = +1;
			coren::db('mark_envelope_success', compact('envelopes', 'status'));
		}
	}

	if (!$this->silent)
	{
		//!!!??? trigger event about successful or failed send! or maybe it must be dependent
		//!!!??? on one_by_one: event one-by-one, or all at once?
		//coren::event($this->event_for_flush_success, compact(???!!!));
		coren::event($this->event_for_flush_success);
	}
	if (!$this->hidden)
	{
		if (!coren::depend('_dom_builder_0'))
			throw new exception("Tool '_dom_builder_0' missed.");

		$doc = coren::xml();
		$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'flush', null);
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'limit'  , $limit));
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'max-age', $this->max_age));
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'max-try', $this->max_try));

		$eler = $ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'reports', null));
		foreach ($reports as $report)
		$eler->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'report', $report));

		$elet = $ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'templates', null));
		foreach ($templates as $identifier => $template)
		$elet->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'template', $template))
		   ->setAttributeNodeNS(_dom_builder_0::build_attribute($doc, self::namespace, $this->prefix, 'id', $identifier));

		coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_flush_success), $this->slot_for_flush_success);
	}
}
<?php defined('CORENINPAGE') or die('Hack!');
####################################################################################################
####################################################################################################
####################################################################################################
#
if (!coren::depend('requisites_request_0')) return;
#
class requisites_request_mapped_0 extends requisites_request_0
{
#
####################################################################################################
####################################################################################################
####################################################################################################
#
protected $direct;
protected $map;
#
####################################################################################################
#
public function __construct ($configs)
{
	parent::__construct($configs);

	if (isset($configs['direct'])) $this->direct = $configs['direct'];

	$map = isset($configs['map']) ? $configs['map'] : null;
	$map_parts = explode(' ', $map); $map = array();
	foreach ($map_parts as $map_part)
	{
		$map_part = explode('=', $map_part, 2);
		$dstkey = isset($map_part[0]) ? trim($map_part[0]) : null;
Example #6
0
public function inject ($data)
{
	if (!coren::have($this->privilege_for_inject))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_not_authorized);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'inject', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'not-authorized', null));
			coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_not_authorized), $this->slot_for_not_authorized);
		}
//???		absence of authrization for some action is an error, but not an exception.
//???		exceptions are for unpredicted situations, and access violation is predicted.
//???		So this is an error, it has an event & data about error, and do nothing more,
//???		but it do not throw an exception, which breaks all workflow of the script
//???		and causes rollbacks in all databases.
//???		throw new exception("Not authorized to inject message into queue of messages.");
		return;
	}

	$priority = isset($data['priority']) ? $data['priority'] :  0; if (is_scalar($priority)) $priority = (integer) $priority; else throw new exception("Bad priority for message queue (must be integer).");
	$subject  = isset($data['subject' ]) ? $data['subject' ] : ''; if (is_scalar($subject )) $subject  = (string ) $subject ; else throw new exception("Bad subject for message queue (must be string).");
	$message  = isset($data['message' ]) ? $data['message' ] : ''; if (is_scalar($message )) $message  = (string ) $message ; else throw new exception("Bad message for message queue (must be string).");

	//??? if both [recipient] and [recipients] are set, should be send to both of them, or to [recipients] only?
	//??? now we use the second way: if [recipients] is set, then [recipient] is ignored.
	$recipient  = isset($data['recipient' ]) ? $data['recipient' ] : null;
	$recipients = isset($data['recipients']) ? $data['recipients'] : array($recipient);
	if (!is_array($recipients)) $recipients = array($recipients);//NB: $recipients will never be null here, so we don't recheck.
	$temp = array();
	foreach ($recipients as $recipient)
		if (is_null  ($recipient)) { continue; } else
		if (is_scalar($recipient)) { $temp[] = (string) $recipient; } else //NB: use recipient even if it is an empty string.
		throw new exception("Bad type of recipient in message queue (must be either null, or string).");
	$recipients = array_unique($temp);

	$template = coren::db('insert_template', compact('subject', 'message'));
	if (!empty($recipients)) coren::db('insert_envelopes', compact('template', 'priority', 'recipients'));

	if (!$this->silent)
	{
		coren::event($this->event_for_inject_success, compact('priority', 'subject', 'message', 'recipients'));
	}
	if (!$this->hidden)
	{
		if (!coren::depend('_dom_builder_0'))
			throw new exception("Tool '_dom_builder_0' missed.");

		$doc = coren::xml();
		$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'inject', compact('priority', 'subject', 'message'));
		foreach ($recipients as $recipient)
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'recipient', $recipient));
		coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name_for_inject_success), $this->slot_for_inject_success);
	}
}
# в один единственный файл, который ссылается на ядро. При запросе таких ресурсов ядро будет
# все видеть так, будто оно получило запрос прямым обращением к файлу в соответствующем каталоге.
# И набор модулей данного класса могут решить какие данные генерировать на основании пути в запросе,
# хотя и существует один-единственный файл скрипта в корне сайта/каталога.
#
# Этот модуль также делает некоторые различия для главного и вспомогательного контента на странице.
# Если какой-то другой модуль через систему событий заявил что он сам будет генерировать главный
# контент, а в нашем модуле тоже предплагается главный контент, то мы его уже не будем генерировать.
# С другой стороны, если контент данного модуля помечен как вспомогательный, то он будет всегда
# генерироваться вне зависимости от наличия главного контента в других модулях.
#
####################################################################################################
####################################################################################################
####################################################################################################
#
if (!coren::depend('event_if_0')) return;
#
class event_if_http_path_regex_0 extends event_if_0
{
#
####################################################################################################
####################################################################################################
####################################################################################################
#
protected $regex;
#
####################################################################################################
#
public function __construct ($configs)
{
	parent::__construct($configs);
Example #8
0
public function send ($data)
{
	if (!coren::have($this->privilege_for_send))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_not_authorized);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'send', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'not-authorized', null));
		}
//???		do nto throw here. see file ...inject... for reasoning.
//???		throw new exception("Not authorized to flush queue of messages.");
		return;
	}

	$recipient = isset($data['recipient']) ? $data['recipient'] : ''; if (is_scalar($recipient)) $recipient = (string ) $recipient; else throw new exception("Bad recipient for message mail (must be string).");
	$subject   = isset($data['subject'  ]) ? $data['subject'  ] : ''; if (is_scalar($subject  )) $subject   = (string ) $subject  ; else throw new exception("Bad subject for message mail (must be string).");
	$message   = isset($data['message'  ]) ? $data['message'  ] : ''; if (is_scalar($message  )) $message   = (string ) $message  ; else throw new exception("Bad message for message mail (must be string).");
	$headers   = (string) $this->headers;

	$recipient = trim(preg_replace("/(\\r|\\n)+/"   , " "      , $recipient));//NB: strip all newlines at all.
	$subject   = trim(preg_replace("/(\\r|\\n)+/"   , " "      , $subject  ));//NB: strip all newlines at all.
	$message   = trim(preg_replace("/(\\r(\\n?))/"  , "\n"     , $message  ));//NB: force   LF (  \n).
	$headers   = trim(preg_replace("/([^\\r]|^)\\n/", "\\1\r\n", $headers  ));//NB: force CRLF (\r\n).

	$result = @mail($recipient, $subject, $message, $headers);
	$errormsg = isset($php_errormsg) ? $php_errormsg : "Error in mail(); \$php_errormsg isn't set.";
	if (!$result) throw new exception($errormsg);

	if (!$this->silent)
	{
		coren::event($this->event_for_send_success);
	}
	if (!$this->hidden)
	{
		if (!coren::depend('_dom_builder_0'))
			throw new exception("Tool '_dom_builder_0' missed.");

		$doc = coren::xml();
		$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'send', null);
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'recipient', $recipient));
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'subject'  , $subject  ));
		$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'message'  , $message  ));
		coren::slot(coren::name($doc->documentElement->appendChild($ele), $this->name), $this->slot);
	}
}
public function identify ($data)
{
	$identifier = coren::event($this->event_for_account_detect_identifier, null);

	if (is_null($identifier))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_account_detect_skipped);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'nothing', null);
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_account_detect_skipped),
				$this->slot_for_account_detect_skipped);
		}
		return;
	}

	$information = coren::event($this->event_for_account_detect_information, compact('identifier'));

	$code =
		(is_null($information)    ? 'absent'   :
		($information['disabled'] ? 'disabled' :
		(null)));

	if (is_null($code))
	{
		$this->identifier  = $identifier ;
		$this->information = $information;

		if (!$this->silent)
		{
			coren::event($this->event_for_account_detect_successed, compact('identifier', 'information'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'account-detect-success', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'information', $information));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_account_detect_successed),
				$this->slot_for_account_detect_successed);
		}
		return true;//NB: this stops futher handling of current event.
	} else
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_account_detect_failed, compact('identifier', 'information', 'code'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'account-detect-failure', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'code'       , $code       ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'information', $information));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_account_detect_failed),
				$this->slot_for_account_detect_failed);
		}
	}
}
Example #10
0
public function start ($data)
{
	$requisites = array('origin');
	$requisites = coren::event($this->event_for_session_start_context, compact('requisites'));
	$origin = isset($requisites['origin']) ? $requisites['origin'] : null;

	$requisites = array('logname', 'password', 'remember');
	$requisites = coren::event($this->event_for_session_start_credentials, compact('requisites'));
	$logname  = isset($requisites['logname' ]) ? $requisites['logname' ] : null;
	$password = isset($requisites['password']) ? $requisites['password'] : null;
	$remember = isset($requisites['remember']) ? $requisites['remember'] : null;
	$credentials = compact('logname', 'password');

	if (!is_null($logname) && !is_null($password))
	{
		$acknowledge = coren::event($this->event_for_session_start_acknowledge, $credentials);
		$code =
			(is_null($acknowledge)    ? 'wrong'    :
			($acknowledge['disabled'] ? 'disabled' :
			(null)));
	} else
	{
		$acknowledge = null;
		$code = 'nothing';
	}

	if (is_null($code))
	{
		$trycount = max($this->trycount, 1);
		$account  = $acknowledge['account'];
		$remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
		$secure = 0;//!!!todo later: configurable default secure mode; selectable loginfo secure mode; account info with secure field.
		$period = $remember ? 0 : 60*60;//!!!todo later: configurable default period; from account settings; from credentials
		for ($i = 1; $i <= $trycount; $i++)
		{
			$identifier = coren::event($this->event_for_session_start_identifier, null);
			if (is_null($identifier)) throw new exception("Noone have generated identifier for new session.");
			try
			{
				coren::db('session_start', compact('identifier', 'account', 'remote', 'secure', 'period'));
				break;
			}
			catch (identify_session_start_0_exception_duplicate $exception)
			{
				if ($i >= $trycount) throw $exception;
			}
		}

		if (!$this->silent)
		{
			coren::event($this->event_for_session_start_successed, compact('origin', 'identifier', 'credentials', 'acknowledge', 'remote', 'secure', 'period'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-start-success', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'credentials', $credentials));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'acknowledge', $acknowledge));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'remote'     , $remote     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'secure'     , $secure     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'period'     , $period     ));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_start_successed),
				$this->slot_for_session_start_successed);
		}
	} else
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_start_failed, compact('identifier', 'origin', 'credentials', 'acknowledge', 'code'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-start-failure', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'code'       , $code       ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'credentials', $credentials));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'acknowledge', $acknowledge));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_start_failed),
				$this->slot_for_session_start_failed);
		}
	}
}
Example #11
0
public function close ($data)
{
	$requisites = array('origin');
	$requisites = coren::event($this->event_for_session_close_context, compact('requisites'));
	$origin = isset($requisites['origin']) ? $requisites['origin'] : null;

	$identifier = coren::event($this->event_for_session_close_identifier, null);

	$code =
		(is_null($identifier) ? 'already' :
		(null));

	if (is_null($code))
	{
		coren::db('close_session', compact('identifier'));

		if (!$this->silent)
		{
			coren::event($this->event_for_session_close_successed, compact('origin', 'identifier'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-close-success', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_close_successed),
				$this->slot_for_session_close_successed);
		}
	} else
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_close_failed, compact('identifier', 'origin', 'code'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-close-failure', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'code'       , $code       ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'origin'     , $origin     ));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_close_failed),
				$this->slot_for_session_close_failed);
		}
	}
}
Example #12
0
public function detect ($data)
{
	$requisites = array('identifier');
	$requisites = coren::event($this->event_for_session_detect_identifier, compact('requisites'));
	$identifier = isset($requisites['identifier']) ? $requisites['identifier'] : null;

	if (is_null($identifier) || !is_scalar($identifier) || ($identifier == ''))
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_detect_skipped);
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'nothing', null);
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_detect_skipped),
				$this->slot_for_session_detect_skipped);
		}
		return;
	}

	$information = coren::db('select_information', compact('identifier'));

	$code =
		(is_null($information)            ? 'absent'  :
		(is_null($information['account']) ? 'orphan'  :
		($information['status'] == 1      ? 'expired' :
		($information['status'] == 2      ? 'closed'  :
		($information['status'] == 3      ? 'halted'  :
		($information['status'] != 0      ? 'status'  :
		(null)))))));

	if (is_null($code))
	{
		$this->identifier  = $identifier ;
		$this->information = $information;

		if (!$this->silent)
		{
			coren::event($this->event_for_session_detect_successed, compact('identifier', 'information'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-detect-success', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'information', $information));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_detect_successed),
				$this->slot_for_session_detect_successed);
		}
		return $information['account'];//NB: this stops futher handling of current event.
	} else
	{
		if (!$this->silent)
		{
			coren::event($this->event_for_session_detect_failed, compact('identifier', 'information', 'code'));
		}
		if (!$this->hidden)
		{
			if (!coren::depend('_dom_builder_0'))
				throw new exception("Tool '_dom_builder_0' missed.");

			$doc = coren::xml();
			$ele = _dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'session-detect-failure', null);
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'code'       , $code       ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'identifier' , $identifier ));
			$ele->appendChild(_dom_builder_0::build_nodetree($doc, self::namespace, $this->prefix, 'information', $information));
			coren::slot(coren::name($doc->documentElement->appendChild($ele),
				$this->name_for_session_detect_failed),
				$this->slot_for_session_detect_failed);
		}
	}
}