Query Code: ".$resource);
}
return false;
}
- /**
- * Purpose a query on selected database.
- *
- * @param string The SQL query
- *
- * @return resource Results of the query
- */
+
+ public function getFirstRow($resource)
+ {
+ return $this->uniquequery($resource);
+ }
public function uniquequery($resource)
{
@@ -124,6 +103,10 @@ public function uniquequery($resource)
* @return resource Results of the query
*/
+ public function getFirstCell($resource)
+ {
+ return $this->countquery($resource);
+ }
public function countquery($resource)
{
$result = $this->query($resource);
@@ -162,6 +145,11 @@ public function fetchquery($resource, $encode = array())
*
* @return array The data of a row
*/
+ public function fetchArray($result)
+ {
+ return $result->fetch_array(MYSQLI_ASSOC);
+ }
+
public function fetch_array($result)
{
return $result->fetch_array(MYSQLI_ASSOC);
@@ -186,10 +174,15 @@ public function fetch_num($result)
*
* @return integer The total row number
*/
- public function num_rows($query)
+ public function numRows($query)
{
return $query->num_rows;
}
+
+ public function affectedRows()
+ {
+ return $this->affected_rows;
+ }
/**
* Returns the total row numbers of a query.
@@ -211,6 +204,11 @@ public function GetInsertID()
* @return string Returns the escaped string, or false on error.
*/
+ public function escape($string, $flag = false)
+ {
+ return $this->sql_escape($string, $flag);
+ }
+
public function sql_escape($string, $flag = false)
{
return ($flag === false) ? parent::escape_string($string): addcslashes(parent::escape_string($string), '%_');
@@ -273,11 +271,7 @@ public function multi_query($resource)
if ($this->errno)
{
- if($this->exception == true) {
- throw new Exception("SQL Error: ".$this->error."
");
- exit;
- }
- } else {
- $USER['rights'] = unserialize($USER['rights']);
- $LANG->includeLang(array('ADMIN'));
+ $USER['rights'] = unserialize($USER['rights']);
+ $LNG->includeData(array('ADMIN', 'CUSTOM'));
}
-} elseif(defined('LOGIN')) {
- //Login
- $LANG->GetLangFromBrowser();
- $LANG->includeLang(array('INGAME', 'PUBLIC'));
}
-
-if (!defined('AJAX') && !defined('CLI'))
- require_once(ROOT_PATH.'includes/classes/class.template.php');
-
-?>
\ No newline at end of file
+elseif(MODE === 'LOGIN')
+{
+ $LNG = new Language();
+ $LNG->getUserAgentLanguage();
+ $LNG->includeData(array('L18N', 'INGAME', 'PUBLIC', 'CUSTOM'));
+}
\ No newline at end of file
diff --git a/includes/config.sample.php b/includes/config.sample.php
index be2e7b1..f9591d3 100644
--- a/includes/config.sample.php
+++ b/includes/config.sample.php
@@ -1,13 +1,14 @@
\ No newline at end of file
diff --git a/includes/constants.php b/includes/constants.php
index 0a2b3bd..bf67a4b 100644
--- a/includes/constants.php
+++ b/includes/constants.php
@@ -2,7 +2,7 @@
/**
* 2Moons
- * Copyright (C) 2011 Slaver
+ * Copyright (C) 2012 Jan Kröpke
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,139 +18,212 @@
* along with this program. If not, see .
*
* @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
+ * @author Jan Kröpke
+ * @copyright 2012 Jan Kröpke
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
+ * @version 1.7.0 (2013-01-17)
* @info $Id$
- * @link http://code.google.com/p/2moons/
+ * @link http://2moons.cc/
*/
//SET TIMEZONE (if Server Timezone are not correct)
//date_default_timezone_set('America/Chicago');
+
//TEMPLATES DEFAULT SETTINGS
-define('DEFAULT_THEME' , 'gow');
+define('DEFAULT_THEME' , 'gow');
+define('HTTPS' , isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on');
+define('PROTOCOL' , HTTPS ? 'https://' : 'http://');
-define('PROTOCOL' , (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? 'https://' : 'http://');
-define('HTTP_ROOT' , str_replace(basename($_SERVER["PHP_SELF"]), '', $_SERVER["PHP_SELF"]));
+define('HTTP_BASE' , str_replace(array('\\', '//'), '/', dirname($_SERVER['SCRIPT_NAME']).'/'));
+define('HTTP_ROOT' , str_replace(basename($_SERVER['SCRIPT_FILENAME']), '', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
-define('AJAX_CHAT_PATH' , ROOT_PATH.'/chat/');
+define('HTTP_FILE' , basename($_SERVER['SCRIPT_NAME']));
+define('HTTP_HOST' , $_SERVER['HTTP_HOST']);
+define('HTTP_PATH' , PROTOCOL.HTTP_HOST.HTTP_ROOT);
-define('DEFAULT_LANG' , "de"); // For Fatal Errors!
-define('PHPEXT' , "php");
+if(!defined('AJAX_CHAT_PATH')) {
+ define('AJAX_CHAT_PATH', ROOT_PATH.'/chat/');
+}
-// SUPPORT WILDCAST DOMAINS
-define('UNIS_WILDCAST' , false);
+if(!defined('CACHE_PATH')) {
+ define('CACHE_PATH', ROOT_PATH.'/cache/');
+}
-// SUPPORT OWN vars.php / UNIVERSE | NOTE: make a COPY of vars.php and rename it to vars_uni1.php, vars_uni2.php, etc...
-define('UNIS_MULTIVARS' , false);
+// For Fatal Errors!
+define('DEFAULT_LANG' , 'de');
-// NUMBER OF COLUMNS FOR SPY REPORTS
-define('SPY_REPORT_ROW' , 2);
+// SUPPORT WILDCAST DOMAINS
+define('UNIS_WILDCAST' , false);
// FIELDS FOR EACH LEVEL OF THE LUNAR BASE
-define('FIELDS_BY_MOONBASIS_LEVEL', 3);
+define('FIELDS_BY_MOONBASIS_LEVEL' , 3);
// FIELDS FOR EACH LEVEL OF THE TERRAFORMER
-define('FIELDS_BY_TERRAFORMER' , 5);
+define('FIELDS_BY_TERRAFORMER' , 5);
+
+// TIME IN SECONDS, TO (i) APPEAR ON GALAXY
+define('INACTIVE' , 604800);
-// ADDED PLANET PRO 2 TECH LEVELS
-define('PLANETS_PER_TECH' , 1);
+// TIME IN SECONDS, TO (i I) APPEAR ON GALAXY
+define('INACTIVE_LONG' , 2419200);
+
+// FEE FOR CANCEL QUEUE IN SHIPYARD
+define('FACTOR_CANCEL_SHIPYARD' , 0.6);
+
+// MINIMUM FLEET TIME
+define('MIN_FLEET_TIME' , 5);
+
+// PHALANX COST'S
+define('PHALANX_DEUTERIUM' , 5000);
// Time of changable nick after changing nick.
-define('USERNAME_CHANGETIME' , 604800);
+define('USERNAME_CHANGETIME' , 604800);
// Factor for Metal/Crystal and Deuterium Storages
-define('STORAGE_FACTOR' , 1.0);
+define('STORAGE_FACTOR' , 1.0);
// Max Results in Searchpage (-1 = disable)
-define('SEARCH_LIMIT' , 25);
+define('SEARCH_LIMIT' , 25);
+
+// Messages per page at message list
+define('MESSAGES_PER_PAGE' , 10);
+
+// banned users per page at ban list
+define('BANNED_USERS_PER_PAGE' , 25);
// How much IP Block ll be checked
// 1 = (AAA); 2 = (AAA.BBB); 3 = (AAA.BBB.CCC)
-define('COMPARE_IP_BLOCKS' , 2);
+define('COMPARE_IP_BLOCKS' , 2);
// Max Round on Combats
-define('MAX_ATTACK_ROUNDS' , 6);
+define('MAX_ATTACK_ROUNDS' , 6);
// Enable the one-Click SImulation on Spy-Raports
-define('ENABLE_SIMULATOR_LINK' , true);
-
-// Planetrows on overview
-define('PLANET_ROWS_ON_OVERVIEW' , 2);
+define('ENABLE_SIMULATOR_LINK' , true);
// Max. User Session in Seconds
-define('SESSION_LIFETIME' , 43200);
+define('SESSION_LIFETIME' , 43200);
+
+// ENABLE Mutlialert on sending fleets
+define('ENABLE_MULTIALERT' , true);
+
+// UTF-8 support for names (required for non-english chars!)
+define('UTF8_SUPPORT' , true);
-// DISCLAMER INFOS
-define('DICLAMER_NAME' , "Edit constans.php!");
-define('DICLAMER_ADRESS1' , "Edit constans.php!");
-define('DICLAMER_ADRESS2' , "Edit constans.php!");
-define('DICLAMER_TEL' , "Edit constans.php!");
-define('DICLAMER_EMAIL' , "Edit constans.php!");
+// Define, how its more hard to spy all inforation
+/*
+ if [Spy tech level of sender] > [Spy tech level of target]
+ min amount of spies = -1 * (abs([Spy tech level of sender] - [Spy tech level of target]) * SPY_DIFFENCE_FACTOR) ^ 2;
+ else
+ min amount of spies = -1 * (abs([Spy tech level of sender] - [Spy tech level of target]) * SPY_DIFFENCE_FACTOR) ^ 2;
+
+*/
+define('SPY_DIFFENCE_FACTOR' , 1);
-// UTF-8 Support for Names (Requried for non-english Chars!)
-define('UTF8_SUPPORT' , true);
+// Define, how its more hard to spy all inforation
+/*
+ min amount of spies = see MissionCaseSpy.php#78
-// EventHandler Settings. Not in use!
-define('EH_ACTIVE_ECO' , BETA);
-define('EH_ACTIVE_FLEETS' , BETA);
+ To see Fleet = {min amount of spies}
+ To see Defense = {min amount of spies} + 1 * SPY_VIEW_FACTOR
+ To see Buildings = {min amount of spies} + 3 * SPY_VIEW_FACTOR
+ To see Technology = {min amount of spies} + 5 * SPY_VIEW_FACTOR
+*/
+define('SPY_VIEW_FACTOR' , 1);
// Bash Settings
-define('BASH_ON' , false);
-define('BASH_COUNT' , 6);
-define('BASH_TIME' , 86400);
+define('BASH_ON' , false);
+define('BASH_COUNT' , 6);
+define('BASH_TIME' , 86400);
+
+// Bash rule on wars:
+// 0 = NORMAL
+// 1 = ON WAR, BASH RULE IS DEACTIVE
+define('BASH_WAR' , 0);
-// Invisible Missions for Phalanx
-// Exsample: '1','4','7','10'
-define('INV_PHALANX_MISSIONS' , '');
+// MINIMUM FLEET TIME MUST HIGHER THEN BASH_TIME
+define('FLEETLOG_AGE' , 86400);
// Root IDs
-define('ROOT_UNI' , 1);
-define('ROOT_USER' , 1);
-
-// AdminAuthlevels
-define('AUTH_ADM' , 3);
-define('AUTH_OPS' , 2);
-define('AUTH_MOD' , 1);
-define('AUTH_USR' , 0);
-
-// Data Tabells
-define('DB_NAME' , $database['databasename']);
-define('DB_PREFIX' , $database['tableprefix']);
-
-define('AKS' , $database['tableprefix'].'aks');
-define('ALLIANCE' , $database['tableprefix'].'alliance');
-define('ALLIANCE_REQUEST' , $database['tableprefix'].'alliance_request');
-define('BANNED' , $database['tableprefix'].'banned');
-define('BUDDY' , $database['tableprefix'].'buddy');
-define('BUDDY_REQUEST' , $database['tableprefix'].'buddy_request');
-define('CHAT_ON' , $database['tableprefix'].'chat_online');
-define('CHAT_MES' , $database['tableprefix'].'chat_messages');
-define('CHAT_BAN' , $database['tableprefix'].'chat_bans');
-define('CHAT_INV' , $database['tableprefix'].'chat_invitations');
-define('CONFIG' , $database['tableprefix'].'config');
-define('DIPLO' , $database['tableprefix'].'diplo');
-define('FLEETS' , $database['tableprefix'].'fleets');
-define('LOG' , $database['tableprefix'].'log');
-define('LOG_FLEETS' , $database['tableprefix'].'log_fleets');
-define('NEWS' , $database['tableprefix'].'news');
-define('NOTES' , $database['tableprefix'].'notes');
-define('MESSAGES' , $database['tableprefix'].'messages');
-define('PLANETS' , $database['tableprefix'].'planets');
-define('RW' , $database['tableprefix'].'raports');
-define('SESSION' , $database['tableprefix'].'session');
-define('STATPOINTS' , $database['tableprefix'].'statpoints');
-define('SUPP' , $database['tableprefix'].'supp');
-define('TOPKB' , $database['tableprefix'].'topkb');
-define('TOPKB_USERS' , $database['tableprefix'].'users_to_topkb');
-define('USERS' , $database['tableprefix'].'users');
-define('USERS_VALID' , $database['tableprefix'].'users_valid');
-
-
-
-// MOD-TABLES
-
-
-?>
\ No newline at end of file
+define('ROOT_UNI' , 1);
+define('ROOT_USER' , 1);
+
+// AUTHLEVEL
+define('AUTH_ADM' , 3);
+define('AUTH_OPS' , 2);
+define('AUTH_MOD' , 1);
+define('AUTH_USR' , 0);
+
+// Modules
+define('MODULE_AMOUNT' , 43);
+define('MODULE_ALLIANCE' , 0);
+define('MODULE_BANLIST' , 21);
+define('MODULE_BANNER' , 37);
+define('MODULE_BATTLEHALL' , 12);
+define('MODULE_BUDDYLIST' , 6);
+define('MODULE_BUILDING' , 2);
+define('MODULE_CHAT' , 7);
+define('MODULE_DMEXTRAS' , 8);
+define('MODULE_FLEET_EVENTS' , 10);
+define('MODULE_FLEET_TABLE' , 9);
+define('MODULE_FLEET_TRADER' , 38);
+define('MODULE_GALAXY' , 11);
+define('MODULE_IMPERIUM' , 15);
+define('MODULE_INFORMATION' , 14);
+define('MODULE_MESSAGES' , 16);
+define('MODULE_MISSILEATTACK' , 40);
+define('MODULE_MISSION_ATTACK' , 1);
+define('MODULE_MISSION_ACS' , 42);
+define('MODULE_MISSION_COLONY' , 35);
+define('MODULE_MISSION_DARKMATTER' , 31);
+define('MODULE_MISSION_DESTROY' , 29);
+define('MODULE_MISSION_EXPEDITION' , 30);
+define('MODULE_MISSION_HOLD' , 33);
+define('MODULE_MISSION_RECYCLE' , 32);
+define('MODULE_MISSION_SPY' , 24);
+define('MODULE_MISSION_STATION' , 36);
+define('MODULE_MISSION_TRANSPORT' , 34);
+define('MODULE_NOTICE' , 17);
+define('MODULE_OFFICIER' , 18);
+define('MODULE_PHALANX' , 19);
+define('MODULE_PLAYERCARD' , 20);
+define('MODULE_RECORDS' , 22);
+define('MODULE_RESEARCH' , 3);
+define('MODULE_RESSOURCE_LIST' , 23);
+define('MODULE_SEARCH' , 26);
+define('MODULE_SHIPYARD_FLEET' , 4);
+define('MODULE_SHIPYARD_DEFENSIVE' , 5);
+define('MODULE_SHORTCUTS' , 41);
+define('MODULE_SIMULATOR' , 39);
+define('MODULE_STATISTICS' , 25);
+define('MODULE_SUPPORT' , 27);
+define('MODULE_TECHTREE' , 28);
+define('MODULE_TRADER' , 13);
+
+// FLEET STATE
+define('FLEET_OUTWARD' , 0);
+define('FLEET_RETURN' , 1);
+define('FLEET_HOLD' , 2);
+
+// ELEMENT FLAGS
+define('ELEMENT_BUILD' , 1); # ID 0 - 99
+define('ELEMENT_TECH' , 2); # ID 101 - 199
+define('ELEMENT_FLEET' , 4); # ID 201 - 399
+define('ELEMENT_DEFENSIVE' , 8); # ID 401 - 599
+define('ELEMENT_OFFICIER' , 16); # ID 601 - 699
+define('ELEMENT_BONUS' , 32); # ID 701 - 799
+define('ELEMENT_RACE' , 64); # ID 801 - 899
+define('ELEMENT_PLANET_RESOURCE' , 128); # ID 901 - 949
+define('ELEMENT_USER_RESOURCE' , 256); # ID 951 - 999
+
+// .. 512, 1024, 2048, 4096, 8192, 16384, 32768
+
+define('ELEMENT_PRODUCTION' , 65536);
+define('ELEMENT_STORAGE' , 131072);
+define('ELEMENT_ONEPERPLANET' , 262144);
+define('ELEMENT_BOUNS' , 524288);
+define('ELEMENT_BUILD_ON_PLANET' , 1048576);
+define('ELEMENT_BUILD_ON_MOONS' , 2097152);
+define('ELEMENT_RESOURCE_ON_TF' , 4194304);
+define('ELEMENT_RESOURCE_ON_FLEET' , 8388608);
+define('ELEMENT_RESOURCE_ON_STEAL' , 16777216);
diff --git a/includes/dbtables.php b/includes/dbtables.php
new file mode 100644
index 0000000..7e2ece0
--- /dev/null
+++ b/includes/dbtables.php
@@ -0,0 +1,79 @@
+.
+ *
+ * @package 2Moons
+ * @author Jan Kröpke
+ * @copyright 2009 Lucky
+ * @copyright 2011 Jan Kröpke
+ * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
+ * @version 1.5 (2011-07-31)
+ * @info $Id$
+ * @link http://2moons.cc/
+ */
+
+// Global configkeys
+$BASICCONFIG = array('VERSION', 'game_name', 'stat', 'stat_level', 'stat_last_update', 'stat_settings', 'stat_update_time', 'stat_last_db_update', 'stats_fly_lock', 'cron_lock', 'ts_modon', 'ts_server', 'ts_tcpport', 'ts_udpport', 'ts_timeout', 'ts_version', 'ts_cron_last', 'ts_cron_interval', 'ts_login', 'ts_password', 'capaktiv', 'cappublic', 'capprivate', 'mail_active', 'mail_use', 'smtp_host', 'smtp_port', 'smtp_user', 'smtp_pass', 'smtp_ssl', 'smtp_sendmail', 'smail_path', 'fb_on', 'fb_apikey', 'fb_skey', 'ga_active', 'ga_key', 'chat_closed', 'chat_allowchan', 'chat_allowmes', 'chat_allowdelmes', 'chat_logmessage', 'chat_nickchange', 'chat_botname', 'chat_channelname', 'chat_socket_active', 'chat_socket_host', 'chat_socket_ip', 'chat_socket_port', 'chat_socket_chatid', 'ttf_file', 'sendmail_inactive', 'del_user_sendmail', 'del_user_automatic', 'del_oldstuff', 'del_user_manually', 'ref_max_referals', 'disclamerAddress','disclamerPhone','disclamerMail','disclamerNotice');
+
+// Data Tabells
+define('DB_NAME' , $database['databasename']);
+define('DB_PREFIX' , $database['tableprefix']);
+
+define('AKS' , DB_PREFIX.'aks');
+define('ALLIANCE' , DB_PREFIX.'alliance');
+define('ALLIANCE_RANK' , DB_PREFIX.'alliance_ranks');
+define('ALLIANCE_REQUEST' , DB_PREFIX.'alliance_request');
+define('BANNED' , DB_PREFIX.'banned');
+define('BUDDY' , DB_PREFIX.'buddy');
+define('BUDDY_REQUEST' , DB_PREFIX.'buddy_request');
+define('CHAT_BAN' , DB_PREFIX.'chat_bans');
+define('CHAT_INV' , DB_PREFIX.'chat_invitations');
+define('CHAT_MES' , DB_PREFIX.'chat_messages');
+define('CHAT_ON' , DB_PREFIX.'chat_online');
+define('CONFIG' , DB_PREFIX.'config');
+define('CRONJOBS' , DB_PREFIX.'cronjobs');
+define('DIPLO' , DB_PREFIX.'diplo');
+define('FLEETS' , DB_PREFIX.'fleets');
+define('FLEETS_EVENT' , DB_PREFIX.'fleet_event');
+define('LOG' , DB_PREFIX.'log');
+define('LOG_FLEETS' , DB_PREFIX.'log_fleets');
+define('LOSTPASSWORD' , DB_PREFIX.'lostpassword');
+define('NEWS' , DB_PREFIX.'news');
+define('NOTES' , DB_PREFIX.'notes');
+define('MESSAGES' , DB_PREFIX.'messages');
+define('MULTI' , DB_PREFIX.'multi');
+define('PLANETS' , DB_PREFIX.'planets');
+define('RW' , DB_PREFIX.'raports');
+define('RECORDS' , DB_PREFIX.'records');
+define('SESSION' , DB_PREFIX.'session');
+define('SHORTCUTS' , DB_PREFIX.'shortcuts');
+define('STATPOINTS' , DB_PREFIX.'statpoints');
+define('TICKETS' , DB_PREFIX.'ticket');
+define('TICKETS_ANSWER' , DB_PREFIX.'ticket_answer');
+define('TICKETS_CATEGORY' , DB_PREFIX.'ticket_category');
+define('TOPKB' , DB_PREFIX.'topkb');
+define('TOPKB_USERS' , DB_PREFIX.'users_to_topkb');
+define('USERS' , DB_PREFIX.'users');
+define('USERS_ACS' , DB_PREFIX.'users_to_acs');
+define('USERS_AUTH' , DB_PREFIX.'users_to_extauth');
+define('USERS_VALID' , DB_PREFIX.'users_valid');
+define('VARS' , DB_PREFIX.'vars');
+define('VARS_RAPIDFIRE' , DB_PREFIX.'vars_rapidfire');
+define('VARS_REQUIRE' , DB_PREFIX.'vars_requriements');
+
+// MOD-TABLES
\ No newline at end of file
diff --git a/includes/extauth/facebook.class.php b/includes/extauth/facebook.class.php
new file mode 100644
index 0000000..9e4416c
--- /dev/null
+++ b/includes/extauth/facebook.class.php
@@ -0,0 +1,103 @@
+.
+ *
+ * @package 2Moons
+ * @author Jan Kröpke
+ * @copyright 2012 Jan Kröpke
+ * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
+ * @version 1.7.0 (2013-01-17)
+ * @info $Id$
+ * @link http://2moons.cc/
+ */
+
+require(ROOT_PATH.'/includes/libs/facebook/facebook.php');
+class FacebookAuth extends Facebook {
+ function __construct()
+ {
+ if($this->isActiveMode())
+ {
+ parent::__construct(array(
+ 'appId' => $GLOBALS['CONF']['fb_apikey'],
+ 'secret' => $GLOBALS['CONF']['fb_skey'],
+ 'cookie' => true,
+ ));
+ }
+ }
+
+ function isActiveMode() {
+ return $GLOBALS['CONF']['fb_on'] == 1;
+ }
+
+ function isVaild() {
+ if($this->getUser() != 0)
+ {
+ return $this->getUser();
+ }
+
+ HTTP::sendHeader('Location', $this->getLoginUrl(array(
+ 'scope' => 'publish_stream,publish_actions,user_games_activity',
+ 'redirect_uri' => HTTP_PATH.'index.php?page=externalAuth&method=facebook'
+ )));
+ exit;
+ }
+
+ function getAccount()
+ {
+ return $this->getUser();
+ }
+
+ function register()
+ {
+ $uid = $this->getAccount();
+
+ $me = $this->api('/me');
+ $ValidReg = $GLOBALS['DATABASE']->getFirstCell("SELECT cle FROM ".USERS_VALID." WHERE universe = ".$UNI." AND email = '".$GLOBALS['DATABASE']->sql_escape($me['email'])."';");
+ if(!empty($ValidReg))
+ HTTP::redirectTo("index.php?uni=".$UNI."&page=reg&action=valid&clef=".$ValidReg);
+
+ $GLOBALS['DATABASE']->query("INSERT INTO ".USERS_AUTH." SET
+ id = (SELECT id FROM ".USERS." WHERE email = '".$GLOBALS['DATABASE']->sql_escape($me['email'])."' OR email_2 = '".$GLOBALS['DATABASE']->sql_escape($me['email'])."'),
+ account = ".$uid.",
+ mode = 'facebook';");
+ }
+
+ function getLoginData()
+ {
+ global $UNI;
+
+ $uid = $this->getAccount();
+
+ return $GLOBALS['DATABASE']->getFirstRow("SELECT
+ user.id, id_planet
+ FROM ".USERS_AUTH." auth
+ INNER JOIN ".USERS." user ON auth.id = user.id AND user.universe = ".$UNI."
+ WHERE auth.account = ".$uid." AND mode = 'facebook';");
+ }
+
+ function getAccountData()
+ {
+ $data = $this->api('/me', array('access_token' => $this->getAccessToken()));
+
+ return array(
+ 'id' => $data['id'],
+ 'name' => $data['name'],
+ 'locale' => $data['locale']
+ );
+ }
+}
\ No newline at end of file
diff --git a/includes/extauth/openid.class.php b/includes/extauth/openid.class.php
new file mode 100644
index 0000000..fb2d3e6
--- /dev/null
+++ b/includes/extauth/openid.class.php
@@ -0,0 +1,114 @@
+.
+ *
+ * @package 2Moons
+ * @author Jan Kröpke
+ * @copyright 2012 Jan Kröpke
+ * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
+ * @version 1.7.0 (2013-01-17)
+ * @info $Id$
+ * @link http://2moons.cc/
+ */
+
+require(ROOT_PATH.'/includes/libs/OpenID/openid.php');
+
+class OpenIDAuth extends LightOpenID {
+
+ function __construct()
+ {
+ parent::__construct(PROTOCOL.HTTP_HOST);
+ if(!$this->mode) {
+ if(isset($_REQUEST['openid_identifier'])) {
+ $this->identity = $_REQUEST['openid_identifier'];
+
+ $this->required = array('contact/email');
+ $this->optional = array('namePerson', 'namePerson/friendly');
+ header('Location: ' . $this->authUrl());
+ exit;
+ } else {
+ HTTP::redirectTo('index.php?code=4');
+ }
+ }
+ }
+
+ function isVaild() {
+ return $this->mode && $this->mode != 'cancel';
+ }
+
+ function getAccount() {
+ $user = $this->getAttributes();
+
+ if(!empty($user['contact/email'])) {
+ return $user['contact/email'];
+ }
+
+ if(!empty($user['namePerson/friendly'])) {
+ return $user['namePerson/friendly'];
+ }
+
+ if(!empty($user['namePerson'])) {
+ return $user['namePerson'];
+ }
+
+ HTTP::redirectTo('index.php?code=4');
+ }
+
+ function register()
+ {
+
+ $uid = getAccount();
+ $user = $this->getAttributes();
+
+ if(empty($user['contact/email'])) {
+ $user['contact/email'] = "";
+ }
+
+ if(!empty($user['namePerson/friendly'])) {
+ $username = $user['namePerson/friendly'];
+ } elseif(!empty($user['namePerson'])) {
+ $username = $user['namePerson'];
+ }
+
+ $ValidReg = $GLOBALS['DATABASE']->getFirstCell("SELECT cle FROM ".USERS_VALID." WHERE universe = ".$UNI." AND email = '".$GLOBALS['DATABASE']->sql_escape($user['contact/email'])."';");
+ if(!empty($ValidReg))
+ HTTP::redirectTo("index.php?uni=".$UNI."&page=reg&action=valid&clef=".$ValidReg);
+
+ $GLOBALS['DATABASE']->query("INSERT INTO ".USERS_AUTH." SET
+ id = (SELECT id FROM ".USERS." WHERE email = '".$GLOBALS['DATABASE']->sql_escape($me['email'])."' OR email_2 = '".$GLOBALS['DATABASE']->sql_escape($user['contact/email'])."'),
+ account = '".$uid."',
+ mode = '".$GLOBALS['DATABASE']->sql_escape($_REQUEST['openid_identifier'])."';");
+ }
+
+ function getLoginData()
+ {
+ global $UNI;
+
+ try {
+ $user = $this->getAttributes();
+ } catch (FacebookApiException $e) {
+ HTTP::redirectTo('index.php?code=4');
+ }
+
+ return $GLOBALS['DATABASE']->getFirstRow("SELECT
+ user.id, user.username, user.dpath, user.authlevel, user.id_planet
+ FROM ".USERS_AUTH." auth
+ INNER JOIN ".USERS." user ON auth.id = user.id AND user.universe = ".$UNI."
+ WHERE auth.account = '".$user['contact/email']."' AND mode = '".$GLOBALS['DATABASE']->sql_escape($_REQUEST['openid_identifier'])."';");
+ }
+}
\ No newline at end of file
diff --git a/includes/functions/BBCode.php b/includes/functions/BBCode.php
index 41c2f61..1d30a6f 100644
--- a/includes/functions/BBCode.php
+++ b/includes/functions/BBCode.php
@@ -2,7 +2,7 @@
/**
* 2Moons
- * Copyright (C) 2011 Slaver
+ * Copyright (C) 2012 Jan Kröpke
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,13 +18,12 @@
* along with this program. If not, see .
*
* @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
+ * @author Jan Kröpke
+ * @copyright 2012 Jan Kröpke
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
+ * @version 1.7.0 (2013-01-17)
* @info $Id$
- * @link http://code.google.com/p/2moons/
+ * @link http://2moons.cc/
*/
function bbcode($text) {
@@ -83,7 +82,7 @@ function bbcode($text) {
}
- return makebr($bbcode->parse($text));
+ return str_replace('&', '&', makebr($bbcode->parse($text)));
}
function convertlinebreaks ($text) {
@@ -209,5 +208,4 @@ function bbcode_color($action, $attributes, $content, $params, $node_object) {
function bbcode_bgcolor($action, $attributes, $content, $params, $node_object) {
if ($action == 'validate') return true;
return ''.$content.'';
-}
-?>
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/includes/functions/CreateOneMoonRecord.php b/includes/functions/CreateOneMoonRecord.php
index 5c5c503..709c79c 100644
--- a/includes/functions/CreateOneMoonRecord.php
+++ b/includes/functions/CreateOneMoonRecord.php
@@ -2,7 +2,7 @@
/**
* 2Moons
- * Copyright (C) 2011 Slaver
+ * Copyright (C) 2012 Jan Kr�pke
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,78 +18,64 @@
* along with this program. If not, see .
*
* @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
+ * @author Jan Kr�pke
+ * @copyright 2012 Jan Kr�pke
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
+ * @version 1.7.0 (2013-01-17)
* @info $Id$
- * @link http://code.google.com/p/2moons/
+ * @link http://2moons.cc/
*/
-if(!defined('INSIDE')) die('Hacking attempt!');
+function CreateOneMoonRecord($Galaxy, $System, $Planet, $Universe, $Owner, $MoonName, $Chance, $time = 0, $Size = 0)
+{
+ global $USER;
- function CreateOneMoonRecord($Galaxy, $System, $Planet, $Universe, $Owner, $MoonID, $MoonName, $Chance, $Size = 0)
- {
- global $LNG, $USER, $db;
+ $SQL = "SELECT id_luna,planet_type,id,name,temp_max,temp_min FROM ".PLANETS." ";
+ $SQL .= "WHERE ";
+ $SQL .= "universe = '".$Universe."' AND ";
+ $SQL .= "galaxy = '".$Galaxy."' AND ";
+ $SQL .= "system = '".$System."' AND ";
+ $SQL .= "planet = '".$Planet."' AND ";
+ $SQL .= "planet_type = '1';";
+ $MoonPlanet = $GLOBALS['DATABASE']->getFirstRow($SQL);
- $SQL = "SELECT id_luna,planet_type,id,name,temp_max,temp_min FROM ".PLANETS." ";
- $SQL .= "WHERE ";
- $SQL .= "`universe` = '".$Universe."' AND ";
- $SQL .= "`galaxy` = '".$Galaxy."' AND ";
- $SQL .= "`system` = '".$System."' AND ";
- $SQL .= "`planet` = '".$Planet."' AND ";
- $SQL .= "`planet_type` = '1';";
- $MoonPlanet = $db->uniquequery($SQL);
+ if ($MoonPlanet['id_luna'] != 0)
+ return false;
- if ($MoonPlanet['id_luna'] != 0)
- return false;
-
- if($Size == 0) {
- $size = floor(pow(mt_rand(10, 20) + 3 * $Chance, 0.5) * 1000); # New Calculation - 23.04.2011
- } else {
- $size = $Size;
- }
-
- $maxtemp = $MoonPlanet['temp_max'] - mt_rand(10, 45);
- $mintemp = $MoonPlanet['temp_min'] - mt_rand(10, 45);
-
- $SQL = "INSERT INTO ".PLANETS." SET ";
- $SQL .= "`name` = '".$MoonName."', ";
- $SQL .= "`id_owner` = '".$Owner."', ";
- $SQL .= "`universe` = '".$Universe."', ";
- $SQL .= "`galaxy` = '".$Galaxy."', ";
- $SQL .= "`system` = '".$System."', ";
- $SQL .= "`planet` = '".$Planet."', ";
- $SQL .= "`last_update` = '".TIMESTAMP."', ";
- $SQL .= "`planet_type` = '3', ";
- $SQL .= "`image` = 'mond', ";
- $SQL .= "`diameter` = '".$size."', ";
- $SQL .= "`field_max` = '1', ";
- $SQL .= "`temp_min` = '".$mintemp."', ";
- $SQL .= "`temp_max` = '".$maxtemp."', ";
- $SQL .= "`metal` = '0', ";
- $SQL .= "`metal_perhour` = '0', ";
- $SQL .= "`metal_max` = '".BASE_STORAGE_SIZE."', ";
- $SQL .= "`crystal` = '0', ";
- $SQL .= "`crystal_perhour` = '0', ";
- $SQL .= "`crystal_max` = '".BASE_STORAGE_SIZE."', ";
- $SQL .= "`deuterium` = '0', ";
- $SQL .= "`deuterium_perhour` = '0', ";
- $SQL .= "`deuterium_max` = '".BASE_STORAGE_SIZE."';";
- $db->query($SQL);
-
- $SQL = "UPDATE ".PLANETS." SET ";
- $SQL .= "`id_luna` = '".$db->GetInsertID()."' ";
- $SQL .= "WHERE ";
- $SQL .= "`universe` = '".$Universe."' AND ";
- $SQL .= "`galaxy` = '".$Galaxy."' AND ";
- $SQL .= "`system` = '".$System."' AND ";
- $SQL .= "`planet` = '".$Planet."' AND ";
- $SQL .= "`planet_type` = '1';";
- $db->query($SQL);
-
- return $MoonPlanet['name'];
+ if($Size == 0) {
+ $size = floor(pow(mt_rand(10, 20) + 3 * $Chance, 0.5) * 1000); # New Calculation - 23.04.2011
+ } else {
+ $size = $Size;
}
+
+ $maxtemp = $MoonPlanet['temp_max'] - mt_rand(10, 45);
+ $mintemp = $MoonPlanet['temp_min'] - mt_rand(10, 45);
+
+ $GLOBALS['DATABASE']->multi_query("INSERT INTO ".PLANETS." SET
+ name = '".$MoonName."',
+ id_owner = ".$Owner.",
+ universe = ".$Universe.",
+ galaxy = ".$Galaxy.",
+ system = ".$System.",
+ planet = ".$Planet.",
+ last_update = ".TIMESTAMP.",
+ planet_type = '3',
+ image = 'mond',
+ diameter = ".$size.",
+ field_max = '1',
+ temp_min = ".$mintemp.",
+ temp_max = ".$maxtemp.",
+ metal = 0,
+ metal_perhour = 0,
+ crystal = 0,
+ crystal_perhour = 0,
+ deuterium = 0,
+ deuterium_perhour = 0;
+ SET @moonID = LAST_INSERT_ID();
+ UPDATE ".PLANETS." SET
+ id_luna = @moonID
+ WHERE
+ id = ".$MoonPlanet['id'].";");
-?>
\ No newline at end of file
+ return true;
+}
diff --git a/includes/functions/CreateOnePlanetRecord.php b/includes/functions/CreateOnePlanetRecord.php
index df79d6d..8eb02fc 100644
--- a/includes/functions/CreateOnePlanetRecord.php
+++ b/includes/functions/CreateOnePlanetRecord.php
@@ -2,7 +2,7 @@
/**
* 2Moons
- * Copyright (C) 2011 Slaver
+ * Copyright (C) 2012 Jan Kr�pke
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,30 +18,28 @@
* along with this program. If not, see .
*
* @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
+ * @author Jan Kr�pke
+ * @copyright 2012 Jan Kr�pke
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
+ * @version 1.7.0 (2013-01-17)
* @info $Id$
- * @link http://code.google.com/p/2moons/
+ * @link http://2moons.cc/
*/
function CreateOnePlanetRecord($Galaxy, $System, $Position, $Universe, $PlanetOwnerID, $PlanetName = '', $HomeWorld = false, $AuthLevel = 0)
{
- global $LNG, $db;
+ global $LNG;
- $CONF = getConfig($Universe);
-
- if ($CONF['max_galaxy'] < $Galaxy || 1 > $Galaxy) {
+ $CONF = Config::getAll(NULL, $Universe);
+ if (Config::get('max_galaxy') < $Galaxy || 1 > $Galaxy) {
throw new Exception("Access denied for CreateOnePlanetRecord.php. Try to create a planet at position:".$Galaxy.":".$System.":".$Position);
}
- if ($CONF['max_system'] < $System || 1 > $System) {
+ if (Config::get('max_system') < $System || 1 > $System) {
throw new Exception("Access denied for CreateOnePlanetRecord.php. Try to create a planet at position:".$Galaxy.":".$System.":".$Position);
}
- if ($CONF['max_planets'] < $Position || 1 > $Position) {
+ if (Config::get('max_planets') < $Position || 1 > $Position) {
throw new Exception("Access denied for CreateOnePlanetRecord.php. Try to create a planet at position:".$Galaxy.":".$System.":".$Position);
}
@@ -49,41 +47,37 @@ function CreateOnePlanetRecord($Galaxy, $System, $Position, $Universe, $PlanetOw
return false;
}
- $FieldFactor = $CONF['planet_factor'];
+ $FieldFactor = Config::get('planet_factor');
require(ROOT_PATH.'includes/PlanetData.php');
- $Pos = ceil($Position / ($CONF['max_planets'] / count($PlanetData)));
+ $Pos = ceil($Position / (Config::get('max_planets') / count($PlanetData)));
$TMax = $PlanetData[$Pos]['temp'];
$TMin = $TMax - 40;
- $Fields = $PlanetData[$Pos]['fields'] * $CONF['planet_factor'];
+ $Fields = $PlanetData[$Pos]['fields'] * Config::get('planet_factor');
$Types = array_keys($PlanetData[$Pos]['image']);
$Type = $Types[array_rand($Types)];
$Class = $Type.'planet'.($PlanetData[$Pos]['image'][$Type] < 10 ? '0' : '').$PlanetData[$Pos]['image'][$Type];
+ $Name = !empty($PlanetName) ? $GLOBALS['DATABASE']->sql_escape($PlanetName) : $LNG['type_planet'][1];
- $SQL = "INSERT INTO ".PLANETS." SET ";
+ $GLOBALS['DATABASE']->query("INSERT INTO ".PLANETS." SET
+ name = '".$Name."',
+ universe = ".$Universe.",
+ id_owner = ".$PlanetOwnerID.",
+ galaxy = ".$Galaxy.",
+ system = ".$System.",
+ planet = ".$Position.",
+ last_update = ".TIMESTAMP.",
+ planet_type = '1',
+ image = '".$Class."',
+ diameter = ".floor(1000 * sqrt($Fields)).",
+ field_max = ".(($HomeWorld) ? Config::get('initial_fields') : floor($Fields)).",
+ temp_min = ".$TMin.",
+ temp_max = ".$TMax.",
+ metal = ".Config::get('metal_start').",
+ metal_perhour = ".Config::get('metal_basic_income').",
+ crystal = ".Config::get('crystal_start').",
+ crystal_perhour = ".Config::get('crystal_basic_income').",
+ deuterium = ".Config::get('deuterium_start').",
+ deuterium_perhour = ".Config::get('deuterium_basic_income').";");
- if(!empty($PlanetName))
- $SQL .= "`name` = '".$db->sql_escape($PlanetName)."', ";
-
- $SQL .= "`universe` = '".$Universe."', ";
- $SQL .= "`id_owner` = '".$PlanetOwnerID."', ";
- $SQL .= "`galaxy` = '".$Galaxy."', ";
- $SQL .= "`system` = '".$System."', ";
- $SQL .= "`planet` = '".$Position."', ";
- $SQL .= "`last_update` = '".TIMESTAMP."', ";
- $SQL .= "`planet_type` = '1', ";
- $SQL .= "`image` = '".$Class."', ";
- $SQL .= "`diameter` = '".floor(1000 * sqrt($Fields))."', ";
- $SQL .= "`field_max` = '".(($HomeWorld) ? $CONF['initial_fields'] : floor($Fields))."', ";
- $SQL .= "`temp_min` = '".$TMin."', ";
- $SQL .= "`temp_max` = '".$TMax."', ";
- $SQL .= "`metal` = '".$CONF['metal_start']."', ";
- $SQL .= "`metal_perhour` = '".$CONF['metal_basic_income']."', ";
- $SQL .= "`crystal` = '".$CONF['crystal_start']."', ";
- $SQL .= "`crystal_perhour` = '".$CONF['crystal_basic_income']."', ";
- $SQL .= "`deuterium` = '".$CONF['deuterium_start']."', ";
- $SQL .= "`deuterium_perhour` = '".$CONF['deuterium_basic_income']."';";
-
- $db->query($SQL);
- return $db->GetInsertID();
-}
-?>
\ No newline at end of file
+ return $GLOBALS['DATABASE']->GetInsertID();
+}
\ No newline at end of file
diff --git a/includes/functions/DeleteSelectedUser.php b/includes/functions/DeleteSelectedUser.php
index 29f526e..36273cc 100644
--- a/includes/functions/DeleteSelectedUser.php
+++ b/includes/functions/DeleteSelectedUser.php
@@ -2,7 +2,7 @@
/**
* 2Moons
- * Copyright (C) 2011 Slaver
+ * Copyright (C) 2012 Jan Kr�pke
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,92 +18,83 @@
* along with this program. If not, see .
*
* @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
+ * @author Jan Kr�pke
+ * @copyright 2012 Jan Kr�pke
* @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
+ * @version 1.7.0 (2013-01-17)
* @info $Id$
- * @link http://code.google.com/p/2moons/
+ * @link http://2moons.cc/
*/
-function DeleteSelectedUser($UserID)
+require_once(ROOT_PATH.'includes/classes/class.FleetFunctions.php');
+
+function DeleteSelectedUser($userID)
{
global $db ,$CONF;
- if(ROOT_USER == $UserId)
+ if(ROOT_USER == $userID) {
return false;
-
- $TheUser = $db->uniquequery("SELECT universe, ally_id FROM ".USERS." WHERE `id` = '".$UserID."';");
+ }
+
+ $userData = $GLOBALS['DATABASE']->getFirstRow("SELECT universe, ally_id FROM ".USERS." WHERE id = '".$userID."';");
$SQL = "";
- if ($TheUser['ally_id'] != 0 )
+ if ($userData['ally_id'] != 0)
{
- $TheAlly = $db->uniquequery("SELECT ally_members FROM ".ALLIANCE." WHERE `id` = '".$TheUser['ally_id']."';");
- $TheAlly['ally_members'] -= 1;
+ $memberCount = $GLOBALS['DATABASE']->getFirstCell("SELECT ally_members FROM ".ALLIANCE." WHERE id = ".$userData['ally_id'].";");
- if ($TheAlly['ally_members'] > 0)
+ if ($memberCount >= 2)
{
- $SQL .= "UPDATE ".ALLIANCE." SET `ally_members` = '".$TheAlly['ally_members']."' WHERE `id` = '".$TheUser['ally_id']."';";
+ $SQL .= "UPDATE ".ALLIANCE." SET ally_members = ally_members - 1 WHERE id = ".$userData['ally_id'].";";
}
else
{
- $SQL .= "DELETE FROM ".ALLIANCE." WHERE `id` = '" . $TheUser['ally_id'] . "';";
- $SQL .= "DELETE FROM ".STATPOINTS." WHERE `stat_type` = '2' AND `id_owner` = '".$TheUser['ally_id']."';";
+ $SQL .= "DELETE FROM ".ALLIANCE." WHERE id = ".$userData['ally_id'].";";
+ $SQL .= "DELETE FROM ".STATPOINTS." WHERE stat_type = '2' AND id_owner = ".$userID.";";
+ $SQL .= "UPDATE ".STATPOINTS." SET id_ally = 0 WHERE id_ally = ".$userData['ally_id'].";";
}
}
-
- $SQL .= "DELETE FROM ".BUDDY." WHERE `owner` = ".$UserID." OR `sender` = ".$UserID.";";
- $SQL .= "DELETE FROM ".FLEETS." WHERE `fleet_owner` = ".$UserID.";";
- $SQL .= "DELETE FROM ".MESSAGES." WHERE `message_owner` = ".$UserID.";";
- $SQL .= "DELETE FROM ".NOTES." WHERE `owner` = ".$UserID.";";
- $SQL .= "DELETE FROM ".PLANETS." WHERE `id_owner` = ".$UserID.";";
- $SQL .= "DELETE FROM ".USERS." WHERE `id` = ".$UserID.";";
- $SQL .= "DELETE FROM ".STATPOINTS." WHERE `stat_type` = '1' AND `id_owner` = ".$UserID.";";
- $db->multi_query($SQL);
- $SQL = $db->query("SELECT fleet_id FROM ".FLEETS." WHERE `fleet_target_owner` = '".$UserID."';");
- while($FleetID = $db->fetch_array($SQL)) {
- SendFleetBack($UserID, $FleetID);
+ $SQL .= "DELETE FROM ".ALLIANCE_REQUEST." WHERE userID = ".$userID.";";
+ $SQL .= "DELETE FROM ".BUDDY." WHERE owner = ".$userID." OR sender = ".$userID.";";
+ $SQL .= "DELETE FROM ".FLEETS." WHERE fleet_owner = ".$userID.";";
+ $SQL .= "DELETE FROM ".MESSAGES." WHERE message_owner = ".$userID.";";
+ $SQL .= "DELETE FROM ".NOTES." WHERE owner = ".$userID.";";
+ $SQL .= "DELETE FROM ".PLANETS." WHERE id_owner = ".$userID.";";
+ $SQL .= "DELETE FROM ".USERS." WHERE id = ".$userID.";";
+ $SQL .= "DELETE FROM ".STATPOINTS." WHERE stat_type = '1' AND id_owner = ".$userID.";";
+ $GLOBALS['DATABASE']->multi_query($SQL);
+
+ $fleetData = $GLOBALS['DATABASE']->query("SELECT fleet_id FROM ".FLEETS." WHERE fleet_target_owner = ".$userID.";");
+
+ while($FleetID = $GLOBALS['DATABASE']->fetch_array($fleetData)) {
+ FleetFunctions::SendFleetBack($userID, $FleetID['fleet_id']);
}
- update_config(array('users_amount' => $CONF['users_amount'] - 1), $TheUser['universe']);
+
+ $GLOBALS['DATABASE']->free_result($fleetData);
+
+ Config::update(array('users_amount' => Config::get('users_amount') - 1), $userData['universe']);
}
-function SendFleetBack($CurrentUser, $FleetID)
+function DeleteSelectedPlanet($planetID)
{
- global $db;
-
- $FleetRow = $db->uniquequery("SELECT `start_time`, `fleet_mission`, `fleet_group`, `fleet_owner`, `fleet_mess` FROM ".FLEETS." WHERE `fleet_id` = '". $FleetID ."';");
- if ($FleetRow['fleet_owner'] != $CurrentUser || $FleetRow['fleet_mess'] == 1)
- return;
-
- $where = 'fleet_id';
-
- if($FleetRow['fleet_mission'] == 1 && $FleetRow['fleet_group'] > 0)
- {
- $Aks = $db->uniquequery("SELECT teilnehmer FROM ".AKS." WHERE id = '". $FleetRow['fleet_group'] ."';");
-
- if($Aks['teilnehmer'] == $FleetRow['fleet_owner'])
- {
- $db->query("DELETE FROM ".AKS." WHERE id ='". $FleetRow['fleet_group'] ."';");
- $FleetID = $FleetRow['fleet_group'];
- $where = 'fleet_group';
- }
+ $planetData = $GLOBALS['DATABASE']->getFirstRow("SELECT planet_type FROM ".PLANETS." WHERE id = ".$planetID." AND id NOT IN (SELECT id_planet FROM ".USERS.");");
+
+ if(empty($planetData)) {
+ return false;
}
- $db->query("UPDATE ".FLEETS." SET `fleet_group` = '0', `start_time` = '".TIMESTAMP."', `fleet_end_stay` = '".TIMESTAMP."', `fleet_end_time` = '".((TIMESTAMP - $FleetRow['start_time']) + TIMESTAMP)."', `fleet_mess` = '1' WHERE `".$where."` = '".$FleetID."';");
-}
-
-function DeleteSelectedPlanet ($ID)
-{
- global $db;
-
- $QueryPlanet = $db->uniquequery("SELECT universe,galaxy,planet,system,planet_type FROM ".PLANETS." WHERE id = '".$ID."';");
-
- if ($QueryPlanet['planet_type'] == '3')
- $db->multi_query("DELETE FROM ".PLANETS." WHERE id = '".$ID."';UPDATE ".PLANETS." SET id_luna = '0' WHERE id_luna = '".$ID."';");
- else
- $db->query("DELETE FROM ".PLANETS." WHERE universe = '".$QueryPlanet['universe']."' AND galaxy = '".$QueryPlanet['galaxy']."' AND system = '".$QueryPlanet['system']."' AND planet = '".$QueryPlanet['planet']."';");
+ $fleetData = $GLOBALS['DATABASE']->query("SELECT fleet_id FROM ".FLEETS." WHERE fleet_end_id = ".$planetID.";");
+
+ while($FleetID = $GLOBALS['DATABASE']->fetch_array($fleetData)) {
+ FleetFunctions::SendFleetBack($$planetID, $FleetID['fleet_id']);
+ }
+
+ $GLOBALS['DATABASE']->free_result($fleetData);
+
+ if ($planetData['planet_type'] == 3) {
+ $GLOBALS['DATABASE']->multi_query("DELETE FROM ".PLANETS." WHERE id = ".$planetID.";UPDATE ".PLANETS." SET id_luna = 0 WHERE id_luna = ".$planetID.";");
+ } else {
+ $GLOBALS['DATABASE']->query("DELETE FROM ".PLANETS." WHERE id = ".$planetID." OR id_luna = ".$planetID.";");
+ }
}
-
-?>
\ No newline at end of file
diff --git a/includes/functions/GetBuildingPrice.php b/includes/functions/GetBuildingPrice.php
deleted file mode 100644
index 7b0a395..0000000
--- a/includes/functions/GetBuildingPrice.php
+++ /dev/null
@@ -1,50 +0,0 @@
-.
- *
- * @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
- * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
- * @info $Id$
- * @link http://code.google.com/p/2moons/
- */
-
-if(!defined('INSIDE')) die('Hacking attempt!');
-
- function GetBuildingPrice ($CurrentUser, $CurrentPlanet, $Element, $Incremental = true, $ForDestroy = false)
- {
- global $pricelist, $resource;
-
- if ($Incremental)
- $level = (isset($CurrentPlanet[$resource[$Element]])) ? $CurrentPlanet[$resource[$Element]] : $CurrentUser[$resource[$Element]];
-
- $array = array('metal', 'crystal', 'deuterium', 'darkmatter', 'energy_max');
- foreach ($array as $ResType)
- {
- $cost[$ResType] = $Incremental ? floor($pricelist[$Element][$ResType] * pow($pricelist[$Element]['factor'], $level)) : floor($pricelist[$Element][$ResType]);
-
- if ($ForDestroy == true)
- $cost[$ResType] /= 2;
- }
-
- return $cost;
- }
-?>
\ No newline at end of file
diff --git a/includes/functions/GetBuildingTime.php b/includes/functions/GetBuildingTime.php
deleted file mode 100644
index 3afd725..0000000
--- a/includes/functions/GetBuildingTime.php
+++ /dev/null
@@ -1,71 +0,0 @@
-.
- *
- * @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
- * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
- * @info $Id$
- * @link http://code.google.com/p/2moons/
- */
-
-if(!defined('INSIDE')) die('Hacking attempt!');
-
- function GetBuildingTime ($USER, $PLANET, $Element, $Destroy = false)
- {
- global $pricelist, $resource, $reslist, $requeriments;
- $CONF = getConfig($USER['universe']);
- $level = isset($PLANET[$resource[$Element]]) ? $PLANET[$resource[$Element]] : $USER[$resource[$Element]];
-
- $Cost = floor($pricelist[$Element]['metal'] * pow($pricelist[$Element]['factor'], $level)) + floor($pricelist[$Element]['crystal'] * pow($pricelist[$Element]['factor'], $level));
-
- if (in_array($Element, $reslist['build']))
- $time = $Cost / ($CONF['game_speed'] * (1 + $PLANET[$resource[14]])) * pow(0.5, $PLANET[$resource[15]]) * $USER['factor']['bulidspeed'];
- elseif (in_array($Element, $reslist['fleet']))
- $time = $Cost / ($CONF['game_speed'] * (1 + $PLANET[$resource[21]])) * pow(0.5, $PLANET[$resource[15]]) * $USER['factor']['fleetspeed'];
- elseif (in_array($Element, $reslist['defense']))
- $time = $Cost / ($CONF['game_speed'] * (1 + $PLANET[$resource[21]])) * pow(0.5, $PLANET[$resource[15]]) * $USER['factor']['defspeed'];
- elseif (in_array($Element, $reslist['tech']))
- {
- if(is_array($PLANET[$resource[31].'_inter']))
- {
- $Level = 0;
- foreach($PLANET[$resource[31].'_inter'] as $Levels)
- {
- if($Levels >= $requeriments[$Element][31])
- $Level += $Levels;
- }
- }
- else
- $Level = $PLANET[$resource[31]];
-
- $time = $Cost / (1000 * (1 + $Level)) / ($CONF['game_speed'] / 2500) * pow(1 - $CONF['factor_university'] / 100, $PLANET[$resource[6]]) * $USER['factor']['techspeed'];
- }
-
- if(!$Destroy)
- $time = floor($time * 3600);
- else
- $time = floor($time * 1300);
-
- return max($time, $CONF['min_build_time']);
- }
-
-?>
\ No newline at end of file
diff --git a/includes/functions/GetElementPrice.php b/includes/functions/GetElementPrice.php
deleted file mode 100644
index 14ef7f6..0000000
--- a/includes/functions/GetElementPrice.php
+++ /dev/null
@@ -1,54 +0,0 @@
-.
- *
- * @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
- * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
- * @info $Id$
- * @link http://code.google.com/p/2moons/
- */
-
-function GetElementPrice ($USER, $PLANET, $Element, $USERfactor = true) {
- global $pricelist, $resource, $LNG;
- if ($USERfactor)
- $level = (isset($PLANET[$resource[$Element]])) ? $PLANET[$resource[$Element]] : $USER[$resource[$Element]];
-
- $array = array(
- 'metal' => $LNG['Metal'],
- 'crystal' => $LNG['Crystal'],
- 'deuterium' => $LNG['Deuterium'],
- 'energy_max' => $LNG['Energy'],
- 'darkmatter' => $LNG['Darkmatter'],
- );
- $text = "";
- foreach ($array as $ResType => $ResTitle)
- {
- if ($pricelist[$Element][$ResType] != 0)
- {
- $text .= $ResTitle . ": ";
- $cost = $USERfactor ? floor($pricelist[$Element][$ResType] * pow($pricelist[$Element]['factor'], $level)) : floor($pricelist[$Element][$ResType]);
- $text .= (isset($PLANET[$ResType]) && $cost > $PLANET[$ResType]) || (isset($USER[$ResType]) && $cost > $USER[$ResType]) ? "" . pretty_number($cost) . " " : "" . pretty_number($cost) . " ";
- }
- }
- return $text;
-}
-?>
\ No newline at end of file
diff --git a/includes/functions/IsElementBuyable.php b/includes/functions/IsElementBuyable.php
deleted file mode 100644
index b54ad66..0000000
--- a/includes/functions/IsElementBuyable.php
+++ /dev/null
@@ -1,62 +0,0 @@
-.
- *
- * @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
- * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
- * @info $Id$
- * @link http://code.google.com/p/2moons/
- */
-
-if(!defined('INSIDE')) die('Hacking attempt!');
-
- function IsElementBuyable ($USER, $PLANET, $Element, $Incremental = true, $ForDestroy = false)
- {
- global $pricelist, $resource;
-
- include_once(ROOT_PATH . 'includes/functions/IsVacationMode.php');
-
- if (IsVacationMode($USER))
- return false;
-
- if ($Incremental)
- $level = isset($PLANET[$resource[$Element]]) ? $PLANET[$resource[$Element]] : $USER[$resource[$Element]];
-
- $array = array('metal', 'crystal', 'deuterium', 'energy_max', 'darkmatter');
-
- foreach ($array as $ResType)
- {
- if (empty($pricelist[$Element][$ResType]))
- continue;
-
- $cost[$ResType] = $Incremental ? floor($pricelist[$Element][$ResType] * pow($pricelist[$Element]['factor'], $level)) : floor($pricelist[$Element][$ResType]);
-
- if ($ForDestroy)
- $cost[$ResType] = floor($cost[$ResType] / 2);
-
- if ((isset($PLANET[$ResType]) && $cost[$ResType] > $PLANET[$ResType]) || (isset($USER[$ResType]) && $cost[$ResType] > $USER[$ResType]))
- return false;
- }
- return true;
- }
-
-?>
\ No newline at end of file
diff --git a/includes/functions/IsTechnologieAccessible.php b/includes/functions/IsTechnologieAccessible.php
deleted file mode 100644
index 7e3976c..0000000
--- a/includes/functions/IsTechnologieAccessible.php
+++ /dev/null
@@ -1,46 +0,0 @@
-.
- *
- * @package 2Moons
- * @author Slaver
- * @copyright 2009 Lucky (XGProyecto)
- * @copyright 2011 Slaver (Fork/2Moons)
- * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
- * @version 1.6.1 (2011-11-19)
- * @info $Id$
- * @link http://code.google.com/p/2moons/
- */
-
-if(!defined('INSIDE')) die('Hacking attempt!');
-
- function IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)
- {
- global $requeriments, $resource, $reslist;
-
- if(!isset($requeriments[$Element]))
- return true;
-
- foreach($requeriments[$Element] as $ReqElement => $EleLevel)
- {
- if ((isset($CurrentPlanet[$resource[$ReqElement]]) && $CurrentPlanet[$resource[$ReqElement]] < $EleLevel) || (isset($CurrentUser[$resource[$ReqElement]]) && $CurrentUser[$resource[$ReqElement]] < $EleLevel))
- return false;
- }
- return true;
- }
-?>
\ No newline at end of file
diff --git a/includes/functions/mvc/mvc_2Moons.php b/includes/functions/mvc/mvc_2Moons.php
deleted file mode 100644
index 2940e63..0000000
--- a/includes/functions/mvc/mvc_2Moons.php
+++ /dev/null
@@ -1,13 +0,0 @@
- 'Slaver',
- 'title' => '2Moons',
- 'tag' => 'moons_update',
- 'version' => '1.3',
- 'link' => 'http://2moons.cc/',
- 'update' => 'http://2moons.cc/update.xml',
- 'description' => array('de' => 'Basis', 'en' => 'Basic', 'ru' => 'Основной', 'pt' => 'Básico'),
-);
-
-?>
\ No newline at end of file
diff --git a/includes/libs/FirePHP/FirePHP.class.php b/includes/libs/FirePHP/FirePHP.class.php
deleted file mode 100644
index 67ef84f..0000000
--- a/includes/libs/FirePHP/FirePHP.class.php
+++ /dev/null
@@ -1,1784 +0,0 @@
-
- * @license http://www.opensource.org/licenses/bsd-license.php
- * @package FirePHPCore
- */
-
-/**
- * @see http://code.google.com/p/firephp/issues/detail?id=112
- */
-if (!defined('E_STRICT')) {
- define('E_STRICT', 2048);
-}
-if (!defined('E_RECOVERABLE_ERROR')) {
- define('E_RECOVERABLE_ERROR', 4096);
-}
-if (!defined('E_DEPRECATED')) {
- define('E_DEPRECATED', 8192);
-}
-if (!defined('E_USER_DEPRECATED')) {
- define('E_USER_DEPRECATED', 16384);
-}
-
-/**
- * Sends the given data to the FirePHP Firefox Extension.
- * The data can be displayed in the Firebug Console or in the
- * "Server" request tab.
- *
- * For more information see: http://www.firephp.org/
- *
- * @copyright Copyright (C) 2007-2009 Christoph Dorn
- * @author Christoph Dorn
- * @license http://www.opensource.org/licenses/bsd-license.php
- * @package FirePHPCore
- */
-class FirePHP {
-
- /**
- * FirePHP version
- *
- * @var string
- */
- const VERSION = '0.3'; // @pinf replace '0.3' with '%%package.version%%'
-
- /**
- * Firebug LOG level
- *
- * Logs a message to firebug console.
- *
- * @var string
- */
- const LOG = 'LOG';
-
- /**
- * Firebug INFO level
- *
- * Logs a message to firebug console and displays an info icon before the message.
- *
- * @var string
- */
- const INFO = 'INFO';
-
- /**
- * Firebug WARN level
- *
- * Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise.
- *
- * @var string
- */
- const WARN = 'WARN';
-
- /**
- * Firebug ERROR level
- *
- * Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count.
- *
- * @var string
- */
- const ERROR = 'ERROR';
-
- /**
- * Dumps a variable to firebug's server panel
- *
- * @var string
- */
- const DUMP = 'DUMP';
-
- /**
- * Displays a stack trace in firebug console
- *
- * @var string
- */
- const TRACE = 'TRACE';
-
- /**
- * Displays an exception in firebug console
- *
- * Increments the firebug error count.
- *
- * @var string
- */
- const EXCEPTION = 'EXCEPTION';
-
- /**
- * Displays an table in firebug console
- *
- * @var string
- */
- const TABLE = 'TABLE';
-
- /**
- * Starts a group in firebug console
- *
- * @var string
- */
- const GROUP_START = 'GROUP_START';
-
- /**
- * Ends a group in firebug console
- *
- * @var string
- */
- const GROUP_END = 'GROUP_END';
-
- /**
- * Singleton instance of FirePHP
- *
- * @var FirePHP
- */
- protected static $instance = null;
-
- /**
- * Flag whether we are logging from within the exception handler
- *
- * @var boolean
- */
- protected $inExceptionHandler = false;
-
- /**
- * Flag whether to throw PHP errors that have been converted to ErrorExceptions
- *
- * @var boolean
- */
- protected $throwErrorExceptions = true;
-
- /**
- * Flag whether to convert PHP assertion errors to Exceptions
- *
- * @var boolean
- */
- protected $convertAssertionErrorsToExceptions = true;
-
- /**
- * Flag whether to throw PHP assertion errors that have been converted to Exceptions
- *
- * @var boolean
- */
- protected $throwAssertionExceptions = false;
-
- /**
- * Wildfire protocol message index
- *
- * @var int
- */
- protected $messageIndex = 1;
-
- /**
- * Options for the library
- *
- * @var array
- */
- protected $options = array('maxDepth' => 10,
- 'maxObjectDepth' => 5,
- 'maxArrayDepth' => 5,
- 'useNativeJsonEncode' => true,
- 'includeLineNumbers' => true);
-
- /**
- * Filters used to exclude object members when encoding
- *
- * @var array
- */
- protected $objectFilters = array(
- 'firephp' => array('objectStack', 'instance', 'json_objectStack'),
- 'firephp_test_class' => array('objectStack', 'instance', 'json_objectStack')
- );
-
- /**
- * A stack of objects used to detect recursion during object encoding
- *
- * @var object
- */
- protected $objectStack = array();
-
- /**
- * Flag to enable/disable logging
- *
- * @var boolean
- */
- protected $enabled = true;
-
- /**
- * The insight console to log to if applicable
- *
- * @var object
- */
- protected $logToInsightConsole = null;
-
- /**
- * When the object gets serialized only include specific object members.
- *
- * @return array
- */
- public function __sleep()
- {
- return array('options','objectFilters','enabled');
- }
-
- /**
- * Gets singleton instance of FirePHP
- *
- * @param boolean $AutoCreate
- * @return FirePHP
- */
- public static function getInstance($AutoCreate = false)
- {
- if ($AutoCreate===true && !self::$instance) {
- self::init();
- }
- return self::$instance;
- }
-
- /**
- * Creates FirePHP object and stores it for singleton access
- *
- * @return FirePHP
- */
- public static function init()
- {
- return self::setInstance(new self());
- }
-
- /**
- * Set the instance of the FirePHP singleton
- *
- * @param FirePHP $instance The FirePHP object instance
- * @return FirePHP
- */
- public static function setInstance($instance)
- {
- return self::$instance = $instance;
- }
-
- /**
- * Set an Insight console to direct all logging calls to
- *
- * @param object $console The console object to log to
- * @return void
- */
- public function setLogToInsightConsole($console)
- {
- if(is_string($console)) {
- if(get_class($this)!='FirePHP_Insight' && !is_subclass_of($this, 'FirePHP_Insight')) {
- throw new Exception('FirePHP instance not an instance or subclass of FirePHP_Insight!');
- }
- $this->logToInsightConsole = $this->to('request')->console($console);
- } else {
- $this->logToInsightConsole = $console;
- }
- }
-
- /**
- * Enable and disable logging to Firebug
- *
- * @param boolean $Enabled TRUE to enable, FALSE to disable
- * @return void
- */
- public function setEnabled($Enabled)
- {
- $this->enabled = $Enabled;
- }
-
- /**
- * Check if logging is enabled
- *
- * @return boolean TRUE if enabled
- */
- public function getEnabled()
- {
- return $this->enabled;
- }
-
- /**
- * Specify a filter to be used when encoding an object
- *
- * Filters are used to exclude object members.
- *
- * @param string $Class The class name of the object
- * @param array $Filter An array of members to exclude
- * @return void
- */
- public function setObjectFilter($Class, $Filter)
- {
- $this->objectFilters[strtolower($Class)] = $Filter;
- }
-
- /**
- * Set some options for the library
- *
- * Options:
- * - maxDepth: The maximum depth to traverse (default: 10)
- * - maxObjectDepth: The maximum depth to traverse objects (default: 5)
- * - maxArrayDepth: The maximum depth to traverse arrays (default: 5)
- * - useNativeJsonEncode: If true will use json_encode() (default: true)
- * - includeLineNumbers: If true will include line numbers and filenames (default: true)
- *
- * @param array $Options The options to be set
- * @return void
- */
- public function setOptions($Options)
- {
- $this->options = array_merge($this->options,$Options);
- }
-
- /**
- * Get options from the library
- *
- * @return array The currently set options
- */
- public function getOptions()
- {
- return $this->options;
- }
-
- /**
- * Set an option for the library
- *
- * @param string $Name
- * @param mixed $Value
- * @throws Exception
- * @return void
- */
- public function setOption($Name, $Value)
- {
- if (!isset($this->options[$Name])) {
- throw $this->newException('Unknown option: ' . $Name);
- }
- $this->options[$Name] = $Value;
- }
-
- /**
- * Get an option from the library
- *
- * @param string $Name
- * @throws Exception
- * @return mixed
- */
- public function getOption($Name)
- {
- if (!isset($this->options[$Name])) {
- throw $this->newException('Unknown option: ' . $Name);
- }
- return $this->options[$Name];
- }
-
- /**
- * Register FirePHP as your error handler
- *
- * Will throw exceptions for each php error.
- *
- * @return mixed Returns a string containing the previously defined error handler (if any)
- */
- public function registerErrorHandler($throwErrorExceptions = false)
- {
- //NOTE: The following errors will not be caught by this error handler:
- // E_ERROR, E_PARSE, E_CORE_ERROR,
- // E_CORE_WARNING, E_COMPILE_ERROR,
- // E_COMPILE_WARNING, E_STRICT
-
- $this->throwErrorExceptions = $throwErrorExceptions;
-
- return set_error_handler(array($this,'errorHandler'));
- }
-
- /**
- * FirePHP's error handler
- *
- * Throws exception for each php error that will occur.
- *
- * @param int $errno
- * @param string $errstr
- * @param string $errfile
- * @param int $errline
- * @param array $errcontext
- */
- public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
- {
- // Don't throw exception if error reporting is switched off
- if (error_reporting() == 0) {
- return;
- }
- // Only throw exceptions for errors we are asking for
- if (error_reporting() & $errno) {
-
- $exception = new ErrorException($errstr, 0, $errno, $errfile, $errline);
- if ($this->throwErrorExceptions) {
- throw $exception;
- } else {
- $this->fb($exception);
- }
- }
- }
-
- /**
- * Register FirePHP as your exception handler
- *
- * @return mixed Returns the name of the previously defined exception handler,
- * or NULL on error.
- * If no previous handler was defined, NULL is also returned.
- */
- public function registerExceptionHandler()
- {
- return set_exception_handler(array($this,'exceptionHandler'));
- }
-
- /**
- * FirePHP's exception handler
- *
- * Logs all exceptions to your firebug console and then stops the script.
- *
- * @param Exception $Exception
- * @throws Exception
- */
- function exceptionHandler($Exception)
- {
-
- $this->inExceptionHandler = true;
-
- header('HTTP/1.1 500 Internal Server Error');
-
- try {
- $this->fb($Exception);
- } catch (Exception $e) {
- echo 'We had an exception: ' . $e;
- }
- $this->inExceptionHandler = false;
- }
-
- /**
- * Register FirePHP driver as your assert callback
- *
- * @param boolean $convertAssertionErrorsToExceptions
- * @param boolean $throwAssertionExceptions
- * @return mixed Returns the original setting or FALSE on errors
- */
- public function registerAssertionHandler($convertAssertionErrorsToExceptions = true, $throwAssertionExceptions = false)
- {
- $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions;
- $this->throwAssertionExceptions = $throwAssertionExceptions;
-
- if ($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) {
- throw $this->newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!');
- }
-
- return assert_options(ASSERT_CALLBACK, array($this, 'assertionHandler'));
- }
-
- /**
- * FirePHP's assertion handler
- *
- * Logs all assertions to your firebug console and then stops the script.
- *
- * @param string $file File source of assertion
- * @param int $line Line source of assertion
- * @param mixed $code Assertion code
- */
- public function assertionHandler($file, $line, $code)
- {
- if ($this->convertAssertionErrorsToExceptions) {
-
- $exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line);
-
- if ($this->throwAssertionExceptions) {
- throw $exception;
- } else {
- $this->fb($exception);
- }
-
- } else {
- $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file,'Line'=>$line));
- }
- }
-
- /**
- * Start a group for following messages.
- *
- * Options:
- * Collapsed: [true|false]
- * Color: [#RRGGBB|ColorName]
- *
- * @param string $Name
- * @param array $Options OPTIONAL Instructions on how to log the group
- * @return true
- * @throws Exception
- */
- public function group($Name, $Options = null)
- {
-
- if (!$Name) {
- throw $this->newException('You must specify a label for the group!');
- }
-
- if ($Options) {
- if (!is_array($Options)) {
- throw $this->newException('Options must be defined as an array!');
- }
- if (array_key_exists('Collapsed', $Options)) {
- $Options['Collapsed'] = ($Options['Collapsed'])?'true':'false';
- }
- }
-
- return $this->fb(null, $Name, FirePHP::GROUP_START, $Options);
- }
-
- /**
- * Ends a group you have started before
- *
- * @return true
- * @throws Exception
- */
- public function groupEnd()
- {
- return $this->fb(null, null, FirePHP::GROUP_END);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::LOG
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public function log($Object, $Label = null, $Options = array())
- {
- return $this->fb($Object, $Label, FirePHP::LOG, $Options);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::INFO
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public function info($Object, $Label = null, $Options = array())
- {
- return $this->fb($Object, $Label, FirePHP::INFO, $Options);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::WARN
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public function warn($Object, $Label = null, $Options = array())
- {
- return $this->fb($Object, $Label, FirePHP::WARN, $Options);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::ERROR
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public function error($Object, $Label = null, $Options = array())
- {
- return $this->fb($Object, $Label, FirePHP::ERROR, $Options);
- }
-
- /**
- * Dumps key and variable to firebug server panel
- *
- * @see FirePHP::DUMP
- * @param string $Key
- * @param mixed $Variable
- * @return true
- * @throws Exception
- */
- public function dump($Key, $Variable, $Options = array())
- {
- if (!is_string($Key)) {
- throw $this->newException('Key passed to dump() is not a string');
- }
- if (strlen($Key)>100) {
- throw $this->newException('Key passed to dump() is longer than 100 characters');
- }
- if (!preg_match_all('/^[a-zA-Z0-9-_\.:]*$/', $Key, $m)) {
- throw $this->newException('Key passed to dump() contains invalid characters [a-zA-Z0-9-_\.:]');
- }
- return $this->fb($Variable, $Key, FirePHP::DUMP, $Options);
- }
-
- /**
- * Log a trace in the firebug console
- *
- * @see FirePHP::TRACE
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public function trace($Label)
- {
- return $this->fb($Label, FirePHP::TRACE);
- }
-
- /**
- * Log a table in the firebug console
- *
- * @see FirePHP::TABLE
- * @param string $Label
- * @param string $Table
- * @return true
- * @throws Exception
- */
- public function table($Label, $Table, $Options = array())
- {
- return $this->fb($Table, $Label, FirePHP::TABLE, $Options);
- }
-
- /**
- * Insight API wrapper
- *
- * @see Insight_Helper::to()
- */
- public static function to()
- {
- $instance = self::getInstance();
- if (!method_exists($instance, "_to")) {
- throw new Exception("FirePHP::to() implementation not loaded");
- }
- $args = func_get_args();
- return call_user_func_array(array($instance, '_to'), $args);
- }
-
- /**
- * Insight API wrapper
- *
- * @see Insight_Helper::plugin()
- */
- public static function plugin()
- {
- $instance = self::getInstance();
- if (!method_exists($instance, "_plugin")) {
- throw new Exception("FirePHP::plugin() implementation not loaded");
- }
- $args = func_get_args();
- return call_user_func_array(array($instance, '_plugin'), $args);
- }
-
- /**
- * Check if FirePHP is installed on client
- *
- * @return boolean
- */
- public function detectClientExtension()
- {
- // Check if FirePHP is installed on client via User-Agent header
- if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this->getUserAgent(),$m) &&
- version_compare($m[1][0],'0.0.6','>=')) {
- return true;
- } else
- // Check if FirePHP is installed on client via X-FirePHP-Version header
- if (@preg_match_all('/^([\.\d]*)$/si',$this->getRequestHeader("X-FirePHP-Version"),$m) &&
- version_compare($m[1][0],'0.0.6','>=')) {
- return true;
- }
- return false;
- }
-
- /**
- * Log varible to Firebug
- *
- * @see http://www.firephp.org/Wiki/Reference/Fb
- * @param mixed $Object The variable to be logged
- * @return true Return TRUE if message was added to headers, FALSE otherwise
- * @throws Exception
- */
- public function fb($Object)
- {
- if($this instanceof FirePHP_Insight && method_exists($this, '_logUpgradeClientMessage')) {
- if(!FirePHP_Insight::$upgradeClientMessageLogged) { // avoid infinite recursion as _logUpgradeClientMessage() logs a message
- $this->_logUpgradeClientMessage();
- }
- }
-
- static $insightGroupStack = array();
-
- if (!$this->getEnabled()) {
- return false;
- }
-
- if ($this->headersSent($filename, $linenum)) {
- // If we are logging from within the exception handler we cannot throw another exception
- if ($this->inExceptionHandler) {
- // Simply echo the error out to the page
- echo '
FirePHP ERROR: Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.
';
- } else {
- throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.');
- }
- }
-
- $Type = null;
- $Label = null;
- $Options = array();
-
- if (func_num_args()==1) {
- } else
- if (func_num_args()==2) {
- switch(func_get_arg(1)) {
- case self::LOG:
- case self::INFO:
- case self::WARN:
- case self::ERROR:
- case self::DUMP:
- case self::TRACE:
- case self::EXCEPTION:
- case self::TABLE:
- case self::GROUP_START:
- case self::GROUP_END:
- $Type = func_get_arg(1);
- break;
- default:
- $Label = func_get_arg(1);
- break;
- }
- } else
- if (func_num_args()==3) {
- $Type = func_get_arg(2);
- $Label = func_get_arg(1);
- } else
- if (func_num_args()==4) {
- $Type = func_get_arg(2);
- $Label = func_get_arg(1);
- $Options = func_get_arg(3);
- } else {
- throw $this->newException('Wrong number of arguments to fb() function!');
- }
-
- if($this->logToInsightConsole!==null && (get_class($this)=='FirePHP_Insight' || is_subclass_of($this, 'FirePHP_Insight'))) {
- $msg = $this->logToInsightConsole;
- if ($Object instanceof Exception) {
- $Type = self::EXCEPTION;
- }
- if($Label && $Type!=self::TABLE && $Type!=self::GROUP_START) {
- $msg = $msg->label($Label);
- }
- switch($Type) {
- case self::DUMP:
- case self::LOG:
- return $msg->log($Object);
- case self::INFO:
- return $msg->info($Object);
- case self::WARN:
- return $msg->warn($Object);
- case self::ERROR:
- return $msg->error($Object);
- case self::TRACE:
- return $msg->trace($Object);
- case self::EXCEPTION:
- return $this->plugin('engine')->handleException($Object, $msg);
- case self::TABLE:
- if (isset($Object[0]) && !is_string($Object[0]) && $Label) {
- $Object = array($Label, $Object);
- }
- return $msg->table($Object[0], array_slice($Object[1],1), $Object[1][0]);
- case self::GROUP_START:
- $insightGroupStack[] = $msg->group(md5($Label))->open();
- return $msg->log($Label);
- case self::GROUP_END:
- if(count($insightGroupStack)==0) {
- throw new Error('Too many groupEnd() as opposed to group() calls!');
- }
- $group = array_pop($insightGroupStack);
- return $group->close();
- default:
- return $msg->log($Object);
- }
- }
-
- if (!$this->detectClientExtension()) {
- return false;
- }
-
- $meta = array();
- $skipFinalObjectEncode = false;
-
- if ($Object instanceof Exception) {
-
- $meta['file'] = $this->_escapeTraceFile($Object->getFile());
- $meta['line'] = $Object->getLine();
-
- $trace = $Object->getTrace();
- if ($Object instanceof ErrorException
- && isset($trace[0]['function'])
- && $trace[0]['function']=='errorHandler'
- && isset($trace[0]['class'])
- && $trace[0]['class']=='FirePHP') {
-
- $severity = false;
- switch($Object->getSeverity()) {
- case E_WARNING: $severity = 'E_WARNING'; break;
- case E_NOTICE: $severity = 'E_NOTICE'; break;
- case E_USER_ERROR: $severity = 'E_USER_ERROR'; break;
- case E_USER_WARNING: $severity = 'E_USER_WARNING'; break;
- case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break;
- case E_STRICT: $severity = 'E_STRICT'; break;
- case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break;
- case E_DEPRECATED: $severity = 'E_DEPRECATED'; break;
- case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break;
- }
-
- $Object = array('Class'=>get_class($Object),
- 'Message'=>$severity.': '.$Object->getMessage(),
- 'File'=>$this->_escapeTraceFile($Object->getFile()),
- 'Line'=>$Object->getLine(),
- 'Type'=>'trigger',
- 'Trace'=>$this->_escapeTrace(array_splice($trace,2)));
- $skipFinalObjectEncode = true;
- } else {
- $Object = array('Class'=>get_class($Object),
- 'Message'=>$Object->getMessage(),
- 'File'=>$this->_escapeTraceFile($Object->getFile()),
- 'Line'=>$Object->getLine(),
- 'Type'=>'throw',
- 'Trace'=>$this->_escapeTrace($trace));
- $skipFinalObjectEncode = true;
- }
- $Type = self::EXCEPTION;
-
- } else
- if ($Type==self::TRACE) {
-
- $trace = debug_backtrace();
- if (!$trace) return false;
- for( $i=0 ; $i_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
- || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
- /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
- } else
- if (isset($trace[$i]['class'])
- && isset($trace[$i+1]['file'])
- && $trace[$i]['class']=='FirePHP'
- && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
- /* Skip fb() */
- } else
- if ($trace[$i]['function']=='fb'
- || $trace[$i]['function']=='trace'
- || $trace[$i]['function']=='send') {
-
- $Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'',
- 'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'',
- 'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'',
- 'Message'=>$trace[$i]['args'][0],
- 'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'',
- 'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'',
- 'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'',
- 'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1)));
-
- $skipFinalObjectEncode = true;
- $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'';
- $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
- break;
- }
- }
-
- } else
- if ($Type==self::TABLE) {
-
- if (isset($Object[0]) && is_string($Object[0])) {
- $Object[1] = $this->encodeTable($Object[1]);
- } else {
- $Object = $this->encodeTable($Object);
- }
-
- $skipFinalObjectEncode = true;
-
- } else
- if ($Type==self::GROUP_START) {
-
- if (!$Label) {
- throw $this->newException('You must specify a label for the group!');
- }
-
- } else {
- if ($Type===null) {
- $Type = self::LOG;
- }
- }
-
- if ($this->options['includeLineNumbers']) {
- if (!isset($meta['file']) || !isset($meta['line'])) {
-
- $trace = debug_backtrace();
- for( $i=0 ; $trace && $i_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php'
- || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) {
- /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */
- } else
- if (isset($trace[$i]['class'])
- && isset($trace[$i+1]['file'])
- && $trace[$i]['class']=='FirePHP'
- && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') {
- /* Skip fb() */
- } else
- if (isset($trace[$i]['file'])
- && substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') {
- /* Skip FB::fb() */
- } else {
- $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'';
- $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:'';
- break;
- }
- }
- }
- } else {
- unset($meta['file']);
- unset($meta['line']);
- }
-
- $this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2');
- $this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION);
-
- $structure_index = 1;
- if ($Type==self::DUMP) {
- $structure_index = 2;
- $this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1');
- } else {
- $this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1');
- }
-
- if ($Type==self::DUMP) {
- $msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}';
- } else {
- $msg_meta = $Options;
- $msg_meta['Type'] = $Type;
- if ($Label!==null) {
- $msg_meta['Label'] = $Label;
- }
- if (isset($meta['file']) && !isset($msg_meta['File'])) {
- $msg_meta['File'] = $meta['file'];
- }
- if (isset($meta['line']) && !isset($msg_meta['Line'])) {
- $msg_meta['Line'] = $meta['line'];
- }
- $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']';
- }
-
- $parts = explode("\n",chunk_split($msg, 5000, "\n"));
-
- for( $i=0 ; $i2) {
- // Message needs to be split into multiple parts
- $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex,
- (($i==0)?strlen($msg):'')
- . '|' . $part . '|'
- . (($isetHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex,
- strlen($part) . '|' . $part . '|');
- }
-
- $this->messageIndex++;
-
- if ($this->messageIndex > 99999) {
- throw $this->newException('Maximum number (99,999) of messages reached!');
- }
- }
- }
-
- $this->setHeader('X-Wf-1-Index',$this->messageIndex-1);
-
- return true;
- }
-
- /**
- * Standardizes path for windows systems.
- *
- * @param string $Path
- * @return string
- */
- protected function _standardizePath($Path)
- {
- return preg_replace('/\\\\+/','/',$Path);
- }
-
- /**
- * Escape trace path for windows systems
- *
- * @param array $Trace
- * @return array
- */
- protected function _escapeTrace($Trace)
- {
- if (!$Trace) return $Trace;
- for( $i=0 ; $i_escapeTraceFile($Trace[$i]['file']);
- }
- if (isset($Trace[$i]['args'])) {
- $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']);
- }
- }
- return $Trace;
- }
-
- /**
- * Escape file information of trace for windows systems
- *
- * @param string $File
- * @return string
- */
- protected function _escapeTraceFile($File)
- {
- /* Check if we have a windows filepath */
- if (strpos($File,'\\')) {
- /* First strip down to single \ */
-
- $file = preg_replace('/\\\\+/','\\',$File);
-
- return $file;
- }
- return $File;
- }
-
- /**
- * Check if headers have already been sent
- *
- * @param string $Filename
- * @param integer $Linenum
- */
- protected function headersSent(&$Filename, &$Linenum)
- {
- return headers_sent($Filename, $Linenum);
- }
-
- /**
- * Send header
- *
- * @param string $Name
- * @param string $Value
- */
- protected function setHeader($Name, $Value)
- {
- return header($Name.': '.$Value);
- }
-
- /**
- * Get user agent
- *
- * @return string|false
- */
- protected function getUserAgent()
- {
- if (!isset($_SERVER['HTTP_USER_AGENT'])) return false;
- return $_SERVER['HTTP_USER_AGENT'];
- }
-
- /**
- * Get all request headers
- *
- * @return array
- */
- public static function getAllRequestHeaders() {
- static $_cached_headers = false;
- if($_cached_headers!==false) {
- return $_cached_headers;
- }
- $headers = array();
- if(function_exists('getallheaders')) {
- foreach( getallheaders() as $name => $value ) {
- $headers[strtolower($name)] = $value;
- }
- } else {
- foreach($_SERVER as $name => $value) {
- if(substr($name, 0, 5) == 'HTTP_') {
- $headers[strtolower(str_replace(' ', '-', str_replace('_', ' ', substr($name, 5))))] = $value;
- }
- }
- }
- return $_cached_headers = $headers;
- }
-
- /**
- * Get a request header
- *
- * @return string|false
- */
- protected function getRequestHeader($Name)
- {
- $headers = self::getAllRequestHeaders();
- if (isset($headers[strtolower($Name)])) {
- return $headers[strtolower($Name)];
- }
- return false;
- }
-
- /**
- * Returns a new exception
- *
- * @param string $Message
- * @return Exception
- */
- protected function newException($Message)
- {
- return new Exception($Message);
- }
-
- /**
- * Encode an object into a JSON string
- *
- * Uses PHP's jeson_encode() if available
- *
- * @param object $Object The object to be encoded
- * @return string The JSON string
- */
- public function jsonEncode($Object, $skipObjectEncode = false)
- {
- if (!$skipObjectEncode) {
- $Object = $this->encodeObject($Object);
- }
-
- if (function_exists('json_encode')
- && $this->options['useNativeJsonEncode']!=false) {
-
- return json_encode($Object);
- } else {
- return $this->json_encode($Object);
- }
- }
-
- /**
- * Encodes a table by encoding each row and column with encodeObject()
- *
- * @param array $Table The table to be encoded
- * @return array
- */
- protected function encodeTable($Table)
- {
-
- if (!$Table) return $Table;
-
- $new_table = array();
- foreach($Table as $row) {
-
- if (is_array($row)) {
- $new_row = array();
-
- foreach($row as $item) {
- $new_row[] = $this->encodeObject($item);
- }
-
- $new_table[] = $new_row;
- }
- }
-
- return $new_table;
- }
-
- /**
- * Encodes an object including members with
- * protected and private visibility
- *
- * @param Object $Object The object to be encoded
- * @param int $Depth The current traversal depth
- * @return array All members of the object
- */
- protected function encodeObject($Object, $ObjectDepth = 1, $ArrayDepth = 1, $MaxDepth = 1)
- {
- if ($MaxDepth > $this->options['maxDepth']) {
- return '** Max Depth ('.$this->options['maxDepth'].') **';
- }
-
- $return = array();
-
- if (is_resource($Object)) {
-
- return '** '.(string)$Object.' **';
-
- } else
- if (is_object($Object)) {
-
- if ($ObjectDepth > $this->options['maxObjectDepth']) {
- return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **';
- }
-
- foreach ($this->objectStack as $refVal) {
- if ($refVal === $Object) {
- return '** Recursion ('.get_class($Object).') **';
- }
- }
- array_push($this->objectStack, $Object);
-
- $return['__className'] = $class = get_class($Object);
- $class_lower = strtolower($class);
-
- $reflectionClass = new ReflectionClass($class);
- $properties = array();
- foreach( $reflectionClass->getProperties() as $property) {
- $properties[$property->getName()] = $property;
- }
-
- $members = (array)$Object;
-
- foreach( $properties as $plain_name => $property ) {
-
- $name = $raw_name = $plain_name;
- if ($property->isStatic()) {
- $name = 'static:'.$name;
- }
- if ($property->isPublic()) {
- $name = 'public:'.$name;
- } else
- if ($property->isPrivate()) {
- $name = 'private:'.$name;
- $raw_name = "\0".$class."\0".$raw_name;
- } else
- if ($property->isProtected()) {
- $name = 'protected:'.$name;
- $raw_name = "\0".'*'."\0".$raw_name;
- }
-
- if (!(isset($this->objectFilters[$class_lower])
- && is_array($this->objectFilters[$class_lower])
- && in_array($plain_name,$this->objectFilters[$class_lower]))) {
-
- if (array_key_exists($raw_name,$members)
- && !$property->isStatic()) {
-
- $return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1, $MaxDepth + 1);
-
- } else {
- if (method_exists($property,'setAccessible')) {
- $property->setAccessible(true);
- $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1);
- } else
- if ($property->isPublic()) {
- $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1);
- } else {
- $return[$name] = '** Need PHP 5.3 to get value **';
- }
- }
- } else {
- $return[$name] = '** Excluded by Filter **';
- }
- }
-
- // Include all members that are not defined in the class
- // but exist in the object
- foreach( $members as $raw_name => $value ) {
-
- $name = $raw_name;
-
- if ($name{0} == "\0") {
- $parts = explode("\0", $name);
- $name = $parts[2];
- }
-
- $plain_name = $name;
-
- if (!isset($properties[$name])) {
- $name = 'undeclared:'.$name;
-
- if (!(isset($this->objectFilters[$class_lower])
- && is_array($this->objectFilters[$class_lower])
- && in_array($plain_name,$this->objectFilters[$class_lower]))) {
-
- $return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1, $MaxDepth + 1);
- } else {
- $return[$name] = '** Excluded by Filter **';
- }
- }
- }
-
- array_pop($this->objectStack);
-
- } elseif (is_array($Object)) {
-
- if ($ArrayDepth > $this->options['maxArrayDepth']) {
- return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **';
- }
-
- foreach ($Object as $key => $val) {
-
- // Encoding the $GLOBALS PHP array causes an infinite loop
- // if the recursion is not reset here as it contains
- // a reference to itself. This is the only way I have come up
- // with to stop infinite recursion in this case.
- if ($key=='GLOBALS'
- && is_array($val)
- && array_key_exists('GLOBALS',$val)) {
- $val['GLOBALS'] = '** Recursion (GLOBALS) **';
- }
-
- $return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1, $MaxDepth + 1);
- }
- } else {
- if (self::is_utf8($Object)) {
- return $Object;
- } else {
- return utf8_encode($Object);
- }
- }
- return $return;
- }
-
- /**
- * Returns true if $string is valid UTF-8 and false otherwise.
- *
- * @param mixed $str String to be tested
- * @return boolean
- */
- protected static function is_utf8($str)
- {
- if(function_exists('mb_detect_encoding')) {
- return (mb_detect_encoding($str) == 'UTF-8');
- }
- $c=0; $b=0;
- $bits=0;
- $len=strlen($str);
- for($i=0; $i<$len; $i++){
- $c=ord($str[$i]);
- if ($c > 128){
- if (($c >= 254)) return false;
- elseif ($c >= 252) $bits=6;
- elseif ($c >= 248) $bits=5;
- elseif ($c >= 240) $bits=4;
- elseif ($c >= 224) $bits=3;
- elseif ($c >= 192) $bits=2;
- else return false;
- if (($i+$bits) > $len) return false;
- while($bits > 1){
- $i++;
- $b=ord($str[$i]);
- if ($b < 128 || $b > 191) return false;
- $bits--;
- }
- }
- }
- return true;
- }
-
- /**
- * Converts to and from JSON format.
- *
- * JSON (JavaScript Object Notation) is a lightweight data-interchange
- * format. It is easy for humans to read and write. It is easy for machines
- * to parse and generate. It is based on a subset of the JavaScript
- * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
- * This feature can also be found in Python. JSON is a text format that is
- * completely language independent but uses conventions that are familiar
- * to programmers of the C-family of languages, including C, C++, C#, Java,
- * JavaScript, Perl, TCL, and many others. These properties make JSON an
- * ideal data-interchange language.
- *
- * This package provides a simple encoder and decoder for JSON notation. It
- * is intended for use with client-side Javascript applications that make
- * use of HTTPRequest to perform server communication functions - data can
- * be encoded into JSON notation for use in a client-side javascript, or
- * decoded from incoming Javascript requests. JSON format is native to
- * Javascript, and can be directly eval()'ed with no further parsing
- * overhead
- *
- * All strings should be in ASCII or UTF-8 format!
- *
- * LICENSE: Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met: Redistributions of source code must retain the
- * above copyright notice, this list of conditions and the following
- * disclaimer. Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
- * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * @category
- * @package Services_JSON
- * @author Michal Migurski
- * @author Matt Knapp
- * @author Brett Stimmerman
- * @author Christoph Dorn
- * @copyright 2005 Michal Migurski
- * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
- * @license http://www.opensource.org/licenses/bsd-license.php
- * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
- */
-
-
- /**
- * Keep a list of objects as we descend into the array so we can detect recursion.
- */
- private $json_objectStack = array();
-
-
- /**
- * convert a string from one UTF-8 char to one UTF-16 char
- *
- * Normally should be handled by mb_convert_encoding, but
- * provides a slower PHP-only method for installations
- * that lack the multibye string extension.
- *
- * @param string $utf8 UTF-8 character
- * @return string UTF-16 character
- * @access private
- */
- private function json_utf82utf16($utf8)
- {
- // oh please oh please oh please oh please oh please
- if (function_exists('mb_convert_encoding')) {
- return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
- }
-
- switch(strlen($utf8)) {
- case 1:
- // this case should never be reached, because we are in ASCII range
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return $utf8;
-
- case 2:
- // return a UTF-16 character from a 2-byte UTF-8 char
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr(0x07 & (ord($utf8{0}) >> 2))
- . chr((0xC0 & (ord($utf8{0}) << 6))
- | (0x3F & ord($utf8{1})));
-
- case 3:
- // return a UTF-16 character from a 3-byte UTF-8 char
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- return chr((0xF0 & (ord($utf8{0}) << 4))
- | (0x0F & (ord($utf8{1}) >> 2)))
- . chr((0xC0 & (ord($utf8{1}) << 6))
- | (0x7F & ord($utf8{2})));
- }
-
- // ignoring UTF-32 for now, sorry
- return '';
- }
-
- /**
- * encodes an arbitrary variable into JSON format
- *
- * @param mixed $var any number, boolean, string, array, or object to be encoded.
- * see argument 1 to Services_JSON() above for array-parsing behavior.
- * if var is a strng, note that encode() always expects it
- * to be in ASCII or UTF-8 format!
- *
- * @return mixed JSON string representation of input var or an error if a problem occurs
- * @access public
- */
- private function json_encode($var)
- {
-
- if (is_object($var)) {
- if (in_array($var,$this->json_objectStack)) {
- return '"** Recursion **"';
- }
- }
-
- switch (gettype($var)) {
- case 'boolean':
- return $var ? 'true' : 'false';
-
- case 'NULL':
- return 'null';
-
- case 'integer':
- return (int) $var;
-
- case 'double':
- case 'float':
- return (float) $var;
-
- case 'string':
- // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
- $ascii = '';
- $strlen_var = strlen($var);
-
- /*
- * Iterate over every character in the string,
- * escaping with a slash or encoding to UTF-8 where necessary
- */
- for ($c = 0; $c < $strlen_var; ++$c) {
-
- $ord_var_c = ord($var{$c});
-
- switch (true) {
- case $ord_var_c == 0x08:
- $ascii .= '\b';
- break;
- case $ord_var_c == 0x09:
- $ascii .= '\t';
- break;
- case $ord_var_c == 0x0A:
- $ascii .= '\n';
- break;
- case $ord_var_c == 0x0C:
- $ascii .= '\f';
- break;
- case $ord_var_c == 0x0D:
- $ascii .= '\r';
- break;
-
- case $ord_var_c == 0x22:
- case $ord_var_c == 0x2F:
- case $ord_var_c == 0x5C:
- // double quote, slash, slosh
- $ascii .= '\\'.$var{$c};
- break;
-
- case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
- // characters U-00000000 - U-0000007F (same as ASCII)
- $ascii .= $var{$c};
- break;
-
- case (($ord_var_c & 0xE0) == 0xC0):
- // characters U-00000080 - U-000007FF, mask 110XXXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
- $c += 1;
- $utf16 = $this->json_utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xF0) == 0xE0):
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}));
- $c += 2;
- $utf16 = $this->json_utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xF8) == 0xF0):
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}));
- $c += 3;
- $utf16 = $this->json_utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xFC) == 0xF8):
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}),
- ord($var{$c + 4}));
- $c += 4;
- $utf16 = $this->json_utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
-
- case (($ord_var_c & 0xFE) == 0xFC):
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
- $char = pack('C*', $ord_var_c,
- ord($var{$c + 1}),
- ord($var{$c + 2}),
- ord($var{$c + 3}),
- ord($var{$c + 4}),
- ord($var{$c + 5}));
- $c += 5;
- $utf16 = $this->json_utf82utf16($char);
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
- break;
- }
- }
-
- return '"'.$ascii.'"';
-
- case 'array':
- /*
- * As per JSON spec if any array key is not an integer
- * we must treat the the whole array as an object. We
- * also try to catch a sparsely populated associative
- * array with numeric keys here because some JS engines
- * will create an array with empty indexes up to
- * max_index which can cause memory issues and because
- * the keys, which may be relevant, will be remapped
- * otherwise.
- *
- * As per the ECMA and JSON specification an object may
- * have any string as a property. Unfortunately due to
- * a hole in the ECMA specification if the key is a
- * ECMA reserved word or starts with a digit the
- * parameter is only accessible using ECMAScript's
- * bracket notation.
- */
-
- // treat as a JSON object
- if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
-
- $this->json_objectStack[] = $var;
-
- $properties = array_map(array($this, 'json_name_value'),
- array_keys($var),
- array_values($var));
-
- array_pop($this->json_objectStack);
-
- foreach($properties as $property) {
- if ($property instanceof Exception) {
- return $property;
- }
- }
-
- return '{' . join(',', $properties) . '}';
- }
-
- $this->json_objectStack[] = $var;
-
- // treat it like a regular array
- $elements = array_map(array($this, 'json_encode'), $var);
-
- array_pop($this->json_objectStack);
-
- foreach($elements as $element) {
- if ($element instanceof Exception) {
- return $element;
- }
- }
-
- return '[' . join(',', $elements) . ']';
-
- case 'object':
- $vars = self::encodeObject($var);
-
- $this->json_objectStack[] = $var;
-
- $properties = array_map(array($this, 'json_name_value'),
- array_keys($vars),
- array_values($vars));
-
- array_pop($this->json_objectStack);
-
- foreach($properties as $property) {
- if ($property instanceof Exception) {
- return $property;
- }
- }
-
- return '{' . join(',', $properties) . '}';
-
- default:
- return null;
- }
- }
-
- /**
- * array-walking function for use in generating JSON-formatted name-value pairs
- *
- * @param string $name name of key to use
- * @param mixed $value reference to an array element to be encoded
- *
- * @return string JSON-formatted name-value pair, like '"name":value'
- * @access private
- */
- private function json_name_value($name, $value)
- {
- // Encoding the $GLOBALS PHP array causes an infinite loop
- // if the recursion is not reset here as it contains
- // a reference to itself. This is the only way I have come up
- // with to stop infinite recursion in this case.
- if ($name=='GLOBALS'
- && is_array($value)
- && array_key_exists('GLOBALS',$value)) {
- $value['GLOBALS'] = '** Recursion **';
- }
-
- $encoded_value = $this->json_encode($value);
-
- if ($encoded_value instanceof Exception) {
- return $encoded_value;
- }
-
- return $this->json_encode(strval($name)) . ':' . $encoded_value;
- }
-
- /**
- * @deprecated
- */
- public function setProcessorUrl($URL)
- {
- trigger_error("The FirePHP::setProcessorUrl() method is no longer supported", E_USER_DEPRECATED);
- }
-
- /**
- * @deprecated
- */
- public function setRendererUrl($URL)
- {
- trigger_error("The FirePHP::setRendererUrl() method is no longer supported", E_USER_DEPRECATED);
- }
-}
diff --git a/includes/libs/FirePHP/fb.php b/includes/libs/FirePHP/fb.php
deleted file mode 100644
index 9ed9c42..0000000
--- a/includes/libs/FirePHP/fb.php
+++ /dev/null
@@ -1,276 +0,0 @@
-
- * @license http://www.opensource.org/licenses/bsd-license.php
- * @package FirePHPCore
- */
-
-if(!class_exists('FirePHP')) {
- require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'FirePHP.class.php';
-}
-
-/**
- * Sends the given data to the FirePHP Firefox Extension.
- * The data can be displayed in the Firebug Console or in the
- * "Server" request tab.
- *
- * @see http://www.firephp.org/Wiki/Reference/Fb
- * @param mixed $Object
- * @return true
- * @throws Exception
- */
-function fb()
-{
- $instance = FirePHP::getInstance(true);
-
- $args = func_get_args();
- return call_user_func_array(array($instance,'fb'),$args);
-}
-
-
-class FB
-{
- /**
- * Enable and disable logging to Firebug
- *
- * @see FirePHP->setEnabled()
- * @param boolean $Enabled TRUE to enable, FALSE to disable
- * @return void
- */
- public static function setEnabled($Enabled)
- {
- $instance = FirePHP::getInstance(true);
- $instance->setEnabled($Enabled);
- }
-
- /**
- * Check if logging is enabled
- *
- * @see FirePHP->getEnabled()
- * @return boolean TRUE if enabled
- */
- public static function getEnabled()
- {
- $instance = FirePHP::getInstance(true);
- return $instance->getEnabled();
- }
-
- /**
- * Specify a filter to be used when encoding an object
- *
- * Filters are used to exclude object members.
- *
- * @see FirePHP->setObjectFilter()
- * @param string $Class The class name of the object
- * @param array $Filter An array or members to exclude
- * @return void
- */
- public static function setObjectFilter($Class, $Filter)
- {
- $instance = FirePHP::getInstance(true);
- $instance->setObjectFilter($Class, $Filter);
- }
-
- /**
- * Set some options for the library
- *
- * @see FirePHP->setOptions()
- * @param array $Options The options to be set
- * @return void
- */
- public static function setOptions($Options)
- {
- $instance = FirePHP::getInstance(true);
- $instance->setOptions($Options);
- }
-
- /**
- * Get options for the library
- *
- * @see FirePHP->getOptions()
- * @return array The options
- */
- public static function getOptions()
- {
- $instance = FirePHP::getInstance(true);
- return $instance->getOptions();
- }
-
- /**
- * Log object to firebug
- *
- * @see http://www.firephp.org/Wiki/Reference/Fb
- * @param mixed $Object
- * @return true
- * @throws Exception
- */
- public static function send()
- {
- $instance = FirePHP::getInstance(true);
- $args = func_get_args();
- return call_user_func_array(array($instance,'fb'),$args);
- }
-
- /**
- * Start a group for following messages
- *
- * Options:
- * Collapsed: [true|false]
- * Color: [#RRGGBB|ColorName]
- *
- * @param string $Name
- * @param array $Options OPTIONAL Instructions on how to log the group
- * @return true
- */
- public static function group($Name, $Options=null)
- {
- $instance = FirePHP::getInstance(true);
- return $instance->group($Name, $Options);
- }
-
- /**
- * Ends a group you have started before
- *
- * @return true
- * @throws Exception
- */
- public static function groupEnd()
- {
- return self::send(null, null, FirePHP::GROUP_END);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::LOG
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public static function log($Object, $Label=null)
- {
- return self::send($Object, $Label, FirePHP::LOG);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::INFO
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public static function info($Object, $Label=null)
- {
- return self::send($Object, $Label, FirePHP::INFO);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::WARN
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public static function warn($Object, $Label=null)
- {
- return self::send($Object, $Label, FirePHP::WARN);
- }
-
- /**
- * Log object with label to firebug console
- *
- * @see FirePHP::ERROR
- * @param mixes $Object
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public static function error($Object, $Label=null)
- {
- return self::send($Object, $Label, FirePHP::ERROR);
- }
-
- /**
- * Dumps key and variable to firebug server panel
- *
- * @see FirePHP::DUMP
- * @param string $Key
- * @param mixed $Variable
- * @return true
- * @throws Exception
- */
- public static function dump($Key, $Variable)
- {
- return self::send($Variable, $Key, FirePHP::DUMP);
- }
-
- /**
- * Log a trace in the firebug console
- *
- * @see FirePHP::TRACE
- * @param string $Label
- * @return true
- * @throws Exception
- */
- public static function trace($Label)
- {
- return self::send($Label, FirePHP::TRACE);
- }
-
- /**
- * Log a table in the firebug console
- *
- * @see FirePHP::TABLE
- * @param string $Label
- * @param string $Table
- * @return true
- * @throws Exception
- */
- public static function table($Label, $Table)
- {
- return self::send($Table, $Label, FirePHP::TABLE);
- }
-
-}
diff --git a/includes/libs/OpenID/openid.php b/includes/libs/OpenID/openid.php
new file mode 100644
index 0000000..1556887
--- /dev/null
+++ b/includes/libs/OpenID/openid.php
@@ -0,0 +1,831 @@
+
+ * $openid = new LightOpenID('my-host.example.org');
+ * $openid->identity = 'ID supplied by user';
+ * header('Location: ' . $openid->authUrl());
+ *
+ * The provider then sends various parameters via GET, one of them is openid_mode.
+ * Step two is verification:
+ *
+ * $openid = new LightOpenID('my-host.example.org');
+ * if ($openid->mode) {
+ * echo $openid->validate() ? 'Logged in.' : 'Failed';
+ * }
+ *
+ *
+ * Change the 'my-host.example.org' to your domain name. Do NOT use $_SERVER['HTTP_HOST']
+ * for that, unless you know what you are doing.
+ *
+ * Optionally, you can set $returnUrl and $realm (or $trustRoot, which is an alias).
+ * The default values for those are:
+ * $openid->realm = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];
+ * $openid->returnUrl = $openid->realm . $_SERVER['REQUEST_URI'];
+ * If you don't know their meaning, refer to any openid tutorial, or specification. Or just guess.
+ *
+ * AX and SREG extensions are supported.
+ * To use them, specify $openid->required and/or $openid->optional before calling $openid->authUrl().
+ * These are arrays, with values being AX schema paths (the 'path' part of the URL).
+ * For example:
+ * $openid->required = array('namePerson/friendly', 'contact/email');
+ * $openid->optional = array('namePerson/first');
+ * If the server supports only SREG or OpenID 1.1, these are automaticaly
+ * mapped to SREG names, so that user doesn't have to know anything about the server.
+ *
+ * To get the values, use $openid->getAttributes().
+ *
+ *
+ * The library requires PHP >= 5.1.2 with curl or http/https stream wrappers enabled.
+ * @author Mewp
+ * @copyright Copyright (c) 2010, Mewp
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ */
+class LightOpenID
+{
+ public $returnUrl
+ , $required = array()
+ , $optional = array()
+ , $verify_peer = null
+ , $capath = null
+ , $cainfo = null
+ , $data;
+ private $identity, $claimed_id;
+ protected $server, $version, $trustRoot, $aliases, $identifier_select = false
+ , $ax = false, $sreg = false, $setup_url = null, $headers = array();
+ static protected $ax_to_sreg = array(
+ 'namePerson/friendly' => 'nickname',
+ 'contact/email' => 'email',
+ 'namePerson' => 'fullname',
+ 'birthDate' => 'dob',
+ 'person/gender' => 'gender',
+ 'contact/postalCode/home' => 'postcode',
+ 'contact/country/home' => 'country',
+ 'pref/language' => 'language',
+ 'pref/timezone' => 'timezone',
+ );
+
+ function __construct($host)
+ {
+ $this->trustRoot = (strpos($host, '://') ? $host : 'http://' . $host);
+ if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
+ || (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
+ && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
+ ) {
+ $this->trustRoot = (strpos($host, '://') ? $host : 'https://' . $host);
+ }
+
+ if(($host_end = strpos($this->trustRoot, '/', 8)) !== false) {
+ $this->trustRoot = substr($this->trustRoot, 0, $host_end);
+ }
+
+ $uri = rtrim(preg_replace('#((?<=\?)|&)openid\.[^&]+#', '', $_SERVER['REQUEST_URI']), '?');
+ $this->returnUrl = $this->trustRoot . $uri;
+
+ $this->data = ($_SERVER['REQUEST_METHOD'] === 'POST') ? $_POST : $_GET;
+
+ if(!function_exists('curl_init') && !in_array('https', stream_get_wrappers())) {
+ throw new ErrorException('You must have either https wrappers or curl enabled.');
+ }
+ }
+
+ function __set($name, $value)
+ {
+ switch ($name) {
+ case 'identity':
+ if (strlen($value = trim((String) $value))) {
+ if (preg_match('#^xri:/*#i', $value, $m)) {
+ $value = substr($value, strlen($m[0]));
+ } elseif (!preg_match('/^(?:[=@+\$!\(]|https?:)/i', $value)) {
+ $value = "http://$value";
+ }
+ if (preg_match('#^https?://[^/]+$#i', $value, $m)) {
+ $value .= '/';
+ }
+ }
+ $this->$name = $this->claimed_id = $value;
+ break;
+ case 'trustRoot':
+ case 'realm':
+ $this->trustRoot = trim($value);
+ }
+ }
+
+ function __get($name)
+ {
+ switch ($name) {
+ case 'identity':
+ # We return claimed_id instead of identity,
+ # because the developer should see the claimed identifier,
+ # i.e. what he set as identity, not the op-local identifier (which is what we verify)
+ return $this->claimed_id;
+ case 'trustRoot':
+ case 'realm':
+ return $this->trustRoot;
+ case 'mode':
+ return empty($this->data['openid_mode']) ? null : $this->data['openid_mode'];
+ }
+ }
+
+ /**
+ * Checks if the server specified in the url exists.
+ *
+ * @param $url url to check
+ * @return true, if the server exists; false otherwise
+ */
+ function hostExists($url)
+ {
+ if (strpos($url, '/') === false) {
+ $server = $url;
+ } else {
+ $server = @parse_url($url, PHP_URL_HOST);
+ }
+
+ if (!$server) {
+ return false;
+ }
+
+ return !!gethostbynamel($server);
+ }
+
+ protected function request_curl($url, $method='GET', $params=array(), $update_claimed_id)
+ {
+ $params = http_build_query($params, '', '&');
+ $curl = curl_init($url . ($method == 'GET' && $params ? '?' . $params : ''));
+ curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($curl, CURLOPT_HEADER, false);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/xrds+xml, */*'));
+
+ if($this->verify_peer !== null) {
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verify_peer);
+ if($this->capath) {
+ curl_setopt($curl, CURLOPT_CAPATH, $this->capath);
+ }
+
+ if($this->cainfo) {
+ curl_setopt($curl, CURLOPT_CAINFO, $this->cainfo);
+ }
+ }
+
+ if ($method == 'POST') {
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
+ } elseif ($method == 'HEAD') {
+ curl_setopt($curl, CURLOPT_HEADER, true);
+ curl_setopt($curl, CURLOPT_NOBODY, true);
+ } else {
+ curl_setopt($curl, CURLOPT_HEADER, true);
+ curl_setopt($curl, CURLOPT_HTTPGET, true);
+ }
+ $response = curl_exec($curl);
+
+ if($method == 'HEAD' && curl_getinfo($curl, CURLINFO_HTTP_CODE) == 405) {
+ curl_setopt($curl, CURLOPT_HTTPGET, true);
+ $response = curl_exec($curl);
+ $response = substr($response, 0, strpos($response, "\r\n\r\n"));
+ }
+
+ if($method == 'HEAD' || $method == 'GET') {
+ $header_response = $response;
+
+ # If it's a GET request, we want to only parse the header part.
+ if($method == 'GET') {
+ $header_response = substr($response, 0, strpos($response, "\r\n\r\n"));
+ }
+
+ $headers = array();
+ foreach(explode("\n", $header_response) as $header) {
+ $pos = strpos($header,':');
+ if ($pos !== false) {
+ $name = strtolower(trim(substr($header, 0, $pos)));
+ $headers[$name] = trim(substr($header, $pos+1));
+ }
+ }
+
+ if($update_claimed_id) {
+ # Updating claimed_id in case of redirections.
+ $effective_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
+ if($effective_url != $url) {
+ $this->identity = $this->claimed_id = $effective_url;
+ }
+ }
+
+ if($method == 'HEAD') {
+ return $headers;
+ } else {
+ $this->headers = $headers;
+ }
+ }
+
+ if (curl_errno($curl)) {
+ throw new ErrorException(curl_error($curl), curl_errno($curl));
+ }
+
+ return $response;
+ }
+
+ protected function parse_header_array($array, $update_claimed_id)
+ {
+ $headers = array();
+ foreach($array as $header) {
+ $pos = strpos($header,':');
+ if ($pos !== false) {
+ $name = strtolower(trim(substr($header, 0, $pos)));
+ $headers[$name] = trim(substr($header, $pos+1));
+
+ # Following possible redirections. The point is just to have
+ # claimed_id change with them, because the redirections
+ # are followed automatically.
+ # We ignore redirections with relative paths.
+ # If any known provider uses them, file a bug report.
+ if($name == 'location' && $update_claimed_id) {
+ if(strpos($headers[$name], 'http') === 0) {
+ $this->identity = $this->claimed_id = $headers[$name];
+ } elseif($headers[$name][0] == '/') {
+ $parsed_url = parse_url($this->claimed_id);
+ $this->identity =
+ $this->claimed_id = $parsed_url['scheme'] . '://'
+ . $parsed_url['host']
+ . $headers[$name];
+ }
+ }
+ }
+ }
+ return $headers;
+ }
+
+ protected function request_streams($url, $method='GET', $params=array(), $update_claimed_id)
+ {
+ if(!$this->hostExists($url)) {
+ throw new ErrorException("Could not connect to $url.", 404);
+ }
+
+ $params = http_build_query($params, '', '&');
+ switch($method) {
+ case 'GET':
+ $opts = array(
+ 'http' => array(
+ 'method' => 'GET',
+ 'header' => 'Accept: application/xrds+xml, */*',
+ 'ignore_errors' => true,
+ ), 'ssl' => array(
+ 'CN_match' => parse_url($url, PHP_URL_HOST),
+ ),
+ );
+ $url = $url . ($params ? '?' . $params : '');
+ break;
+ case 'POST':
+ $opts = array(
+ 'http' => array(
+ 'method' => 'POST',
+ 'header' => 'Content-type: application/x-www-form-urlencoded',
+ 'content' => $params,
+ 'ignore_errors' => true,
+ ), 'ssl' => array(
+ 'CN_match' => parse_url($url, PHP_URL_HOST),
+ ),
+ );
+ break;
+ case 'HEAD':
+ # We want to send a HEAD request,
+ # but since get_headers doesn't accept $context parameter,
+ # we have to change the defaults.
+ $default = stream_context_get_options(stream_context_get_default());
+ stream_context_get_default(
+ array(
+ 'http' => array(
+ 'method' => 'HEAD',
+ 'header' => 'Accept: application/xrds+xml, */*',
+ 'ignore_errors' => true,
+ ), 'ssl' => array(
+ 'CN_match' => parse_url($url, PHP_URL_HOST),
+ ),
+ )
+ );
+
+ $url = $url . ($params ? '?' . $params : '');
+ $headers = get_headers ($url);
+ if(!$headers) {
+ return array();
+ }
+
+ if(intval(substr($headers[0], strlen('HTTP/1.1 '))) == 405) {
+ # The server doesn't support HEAD, so let's emulate it with
+ # a GET.
+ $args = func_get_args();
+ $args[1] = 'GET';
+ call_user_func_array(array($this, 'request_streams'), $args);
+ return $this->headers;
+ }
+
+ $headers = $this->parse_header_array($headers, $update_claimed_id);
+
+ # And restore them.
+ stream_context_get_default($default);
+ return $headers;
+ }
+
+ if($this->verify_peer) {
+ $opts['ssl'] += array(
+ 'verify_peer' => true,
+ 'capath' => $this->capath,
+ 'cafile' => $this->cainfo,
+ );
+ }
+
+ $context = stream_context_create ($opts);
+ $data = file_get_contents($url, false, $context);
+ # This is a hack for providers who don't support HEAD requests.
+ # It just creates the headers array for the last request in $this->headers.
+ if(isset($http_response_header)) {
+ $this->headers = $this->parse_header_array($http_response_header, $update_claimed_id);
+ }
+
+ return file_get_contents($url, false, $context);
+ }
+
+ protected function request($url, $method='GET', $params=array(), $update_claimed_id=false)
+ {
+ if (function_exists('curl_init')
+ && (!in_array('https', stream_get_wrappers()) || !ini_get('safe_mode') && !ini_get('open_basedir'))
+ ) {
+ return $this->request_curl($url, $method, $params, $update_claimed_id);
+ }
+ return $this->request_streams($url, $method, $params, $update_claimed_id);
+ }
+
+ protected function build_url($url, $parts)
+ {
+ if (isset($url['query'], $parts['query'])) {
+ $parts['query'] = $url['query'] . '&' . $parts['query'];
+ }
+
+ $url = $parts + $url;
+ $url = $url['scheme'] . '://'
+ . (empty($url['username'])?''
+ :(empty($url['password'])? "{$url['username']}@"
+ :"{$url['username']}:{$url['password']}@"))
+ . $url['host']
+ . (empty($url['port'])?'':":{$url['port']}")
+ . (empty($url['path'])?'':$url['path'])
+ . (empty($url['query'])?'':"?{$url['query']}")
+ . (empty($url['fragment'])?'':"#{$url['fragment']}");
+ return $url;
+ }
+
+ /**
+ * Helper function used to scan for / tags and extract information
+ * from them
+ */
+ protected function htmlTag($content, $tag, $attrName, $attrValue, $valueName)
+ {
+ preg_match_all("#<{$tag}[^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*$valueName=['\"](.+?)['\"][^>]*/?>#i", $content, $matches1);
+ preg_match_all("#<{$tag}[^>]*$valueName=['\"](.+?)['\"][^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*/?>#i", $content, $matches2);
+
+ $result = array_merge($matches1[1], $matches2[1]);
+ return empty($result)?false:$result[0];
+ }
+
+ /**
+ * Performs Yadis and HTML discovery. Normally not used.
+ * @param $url Identity URL.
+ * @return String OP Endpoint (i.e. OpenID provider address).
+ * @throws ErrorException
+ */
+ function discover($url)
+ {
+ if (!$url) throw new ErrorException('No identity supplied.');
+ # Use xri.net proxy to resolve i-name identities
+ if (!preg_match('#^https?:#', $url)) {
+ $url = "https://xri.net/$url";
+ }
+
+ # We save the original url in case of Yadis discovery failure.
+ # It can happen when we'll be lead to an XRDS document
+ # which does not have any OpenID2 services.
+ $originalUrl = $url;
+
+ # A flag to disable yadis discovery in case of failure in headers.
+ $yadis = true;
+
+ # We'll jump a maximum of 5 times, to avoid endless redirections.
+ for ($i = 0; $i < 5; $i ++) {
+ if ($yadis) {
+ $headers = $this->request($url, 'HEAD', array(), true);
+
+ $next = false;
+ if (isset($headers['x-xrds-location'])) {
+ $url = $this->build_url(parse_url($url), parse_url(trim($headers['x-xrds-location'])));
+ $next = true;
+ }
+
+ if (isset($headers['content-type'])
+ && (strpos($headers['content-type'], 'application/xrds+xml') !== false
+ || strpos($headers['content-type'], 'text/xml') !== false)
+ ) {
+ # Apparently, some providers return XRDS documents as text/html.
+ # While it is against the spec, allowing this here shouldn't break
+ # compatibility with anything.
+ # ---
+ # Found an XRDS document, now let's find the server, and optionally delegate.
+ $content = $this->request($url, 'GET');
+
+ preg_match_all('#(.*?)#s', $content, $m);
+ foreach($m[1] as $content) {
+ $content = ' ' . $content; # The space is added, so that strpos doesn't return 0.
+
+ # OpenID 2
+ $ns = preg_quote('http://specs.openid.net/auth/2.0/', '#');
+ if(preg_match('#\s*'.$ns.'(server|signon)\s*#s', $content, $type)) {
+ if ($type[1] == 'server') $this->identifier_select = true;
+
+ preg_match('#(.*)#', $content, $server);
+ preg_match('#<(Local|Canonical)ID>(.*)\1ID>#', $content, $delegate);
+ if (empty($server)) {
+ return false;
+ }
+ # Does the server advertise support for either AX or SREG?
+ $this->ax = (bool) strpos($content, 'http://openid.net/srv/ax/1.0');
+ $this->sreg = strpos($content, 'http://openid.net/sreg/1.0')
+ || strpos($content, 'http://openid.net/extensions/sreg/1.1');
+
+ $server = $server[1];
+ if (isset($delegate[2])) $this->identity = trim($delegate[2]);
+ $this->version = 2;
+
+ $this->server = $server;
+ return $server;
+ }
+
+ # OpenID 1.1
+ $ns = preg_quote('http://openid.net/signon/1.1', '#');
+ if (preg_match('#\s*'.$ns.'\s*#s', $content)) {
+
+ preg_match('#(.*)#', $content, $server);
+ preg_match('#<.*?Delegate>(.*)#', $content, $delegate);
+ if (empty($server)) {
+ return false;
+ }
+ # AX can be used only with OpenID 2.0, so checking only SREG
+ $this->sreg = strpos($content, 'http://openid.net/sreg/1.0')
+ || strpos($content, 'http://openid.net/extensions/sreg/1.1');
+
+ $server = $server[1];
+ if (isset($delegate[1])) $this->identity = $delegate[1];
+ $this->version = 1;
+
+ $this->server = $server;
+ return $server;
+ }
+ }
+
+ $next = true;
+ $yadis = false;
+ $url = $originalUrl;
+ $content = null;
+ break;
+ }
+ if ($next) continue;
+
+ # There are no relevant information in headers, so we search the body.
+ $content = $this->request($url, 'GET', array(), true);
+
+ if (isset($this->headers['x-xrds-location'])) {
+ $url = $this->build_url(parse_url($url), parse_url(trim($this->headers['x-xrds-location'])));
+ continue;
+ }
+
+ $location = $this->htmlTag($content, 'meta', 'http-equiv', 'X-XRDS-Location', 'content');
+ if ($location) {
+ $url = $this->build_url(parse_url($url), parse_url($location));
+ continue;
+ }
+ }
+
+ if (!$content) $content = $this->request($url, 'GET');
+
+ # At this point, the YADIS Discovery has failed, so we'll switch
+ # to openid2 HTML discovery, then fallback to openid 1.1 discovery.
+ $server = $this->htmlTag($content, 'link', 'rel', 'openid2.provider', 'href');
+ $delegate = $this->htmlTag($content, 'link', 'rel', 'openid2.local_id', 'href');
+ $this->version = 2;
+
+ if (!$server) {
+ # The same with openid 1.1
+ $server = $this->htmlTag($content, 'link', 'rel', 'openid.server', 'href');
+ $delegate = $this->htmlTag($content, 'link', 'rel', 'openid.delegate', 'href');
+ $this->version = 1;
+ }
+
+ if ($server) {
+ # We found an OpenID2 OP Endpoint
+ if ($delegate) {
+ # We have also found an OP-Local ID.
+ $this->identity = $delegate;
+ }
+ $this->server = $server;
+ return $server;
+ }
+
+ throw new ErrorException("No OpenID Server found at $url", 404);
+ }
+ throw new ErrorException('Endless redirection!', 500);
+ }
+
+ protected function sregParams()
+ {
+ $params = array();
+ # We always use SREG 1.1, even if the server is advertising only support for 1.0.
+ # That's because it's fully backwards compatibile with 1.0, and some providers
+ # advertise 1.0 even if they accept only 1.1. One such provider is myopenid.com
+ $params['openid.ns.sreg'] = 'http://openid.net/extensions/sreg/1.1';
+ if ($this->required) {
+ $params['openid.sreg.required'] = array();
+ foreach ($this->required as $required) {
+ if (!isset(self::$ax_to_sreg[$required])) continue;
+ $params['openid.sreg.required'][] = self::$ax_to_sreg[$required];
+ }
+ $params['openid.sreg.required'] = implode(',', $params['openid.sreg.required']);
+ }
+
+ if ($this->optional) {
+ $params['openid.sreg.optional'] = array();
+ foreach ($this->optional as $optional) {
+ if (!isset(self::$ax_to_sreg[$optional])) continue;
+ $params['openid.sreg.optional'][] = self::$ax_to_sreg[$optional];
+ }
+ $params['openid.sreg.optional'] = implode(',', $params['openid.sreg.optional']);
+ }
+ return $params;
+ }
+
+ protected function axParams()
+ {
+ $params = array();
+ if ($this->required || $this->optional) {
+ $params['openid.ns.ax'] = 'http://openid.net/srv/ax/1.0';
+ $params['openid.ax.mode'] = 'fetch_request';
+ $this->aliases = array();
+ $counts = array();
+ $required = array();
+ $optional = array();
+ foreach (array('required','optional') as $type) {
+ foreach ($this->$type as $alias => $field) {
+ if (is_int($alias)) $alias = strtr($field, '/', '_');
+ $this->aliases[$alias] = 'http://axschema.org/' . $field;
+ if (empty($counts[$alias])) $counts[$alias] = 0;
+ $counts[$alias] += 1;
+ ${$type}[] = $alias;
+ }
+ }
+ foreach ($this->aliases as $alias => $ns) {
+ $params['openid.ax.type.' . $alias] = $ns;
+ }
+ foreach ($counts as $alias => $count) {
+ if ($count == 1) continue;
+ $params['openid.ax.count.' . $alias] = $count;
+ }
+
+ # Don't send empty ax.requied and ax.if_available.
+ # Google and possibly other providers refuse to support ax when one of these is empty.
+ if($required) {
+ $params['openid.ax.required'] = implode(',', $required);
+ }
+ if($optional) {
+ $params['openid.ax.if_available'] = implode(',', $optional);
+ }
+ }
+ return $params;
+ }
+
+ protected function authUrl_v1($immediate)
+ {
+ $returnUrl = $this->returnUrl;
+ # If we have an openid.delegate that is different from our claimed id,
+ # we need to somehow preserve the claimed id between requests.
+ # The simplest way is to just send it along with the return_to url.
+ if($this->identity != $this->claimed_id) {
+ $returnUrl .= (strpos($returnUrl, '?') ? '&' : '?') . 'openid.claimed_id=' . $this->claimed_id;
+ }
+
+ $params = array(
+ 'openid.return_to' => $returnUrl,
+ 'openid.mode' => $immediate ? 'checkid_immediate' : 'checkid_setup',
+ 'openid.identity' => $this->identity,
+ 'openid.trust_root' => $this->trustRoot,
+ ) + $this->sregParams();
+
+ return $this->build_url(parse_url($this->server)
+ , array('query' => http_build_query($params, '', '&')));
+ }
+
+ protected function authUrl_v2($immediate)
+ {
+ $params = array(
+ 'openid.ns' => 'http://specs.openid.net/auth/2.0',
+ 'openid.mode' => $immediate ? 'checkid_immediate' : 'checkid_setup',
+ 'openid.return_to' => $this->returnUrl,
+ 'openid.realm' => $this->trustRoot,
+ );
+ if ($this->ax) {
+ $params += $this->axParams();
+ }
+ if ($this->sreg) {
+ $params += $this->sregParams();
+ }
+ if (!$this->ax && !$this->sreg) {
+ # If OP doesn't advertise either SREG, nor AX, let's send them both
+ # in worst case we don't get anything in return.
+ $params += $this->axParams() + $this->sregParams();
+ }
+
+ if ($this->identifier_select) {
+ $params['openid.identity'] = $params['openid.claimed_id']
+ = 'http://specs.openid.net/auth/2.0/identifier_select';
+ } else {
+ $params['openid.identity'] = $this->identity;
+ $params['openid.claimed_id'] = $this->claimed_id;
+ }
+
+ return $this->build_url(parse_url($this->server)
+ , array('query' => http_build_query($params, '', '&')));
+ }
+
+ /**
+ * Returns authentication url. Usually, you want to redirect your user to it.
+ * @return String The authentication url.
+ * @param String $select_identifier Whether to request OP to select identity for an user in OpenID 2. Does not affect OpenID 1.
+ * @throws ErrorException
+ */
+ function authUrl($immediate = false)
+ {
+ if ($this->setup_url && !$immediate) return $this->setup_url;
+ if (!$this->server) $this->discover($this->identity);
+
+ if ($this->version == 2) {
+ return $this->authUrl_v2($immediate);
+ }
+ return $this->authUrl_v1($immediate);
+ }
+
+ /**
+ * Performs OpenID verification with the OP.
+ * @return Bool Whether the verification was successful.
+ * @throws ErrorException
+ */
+ function validate()
+ {
+ # If the request was using immediate mode, a failure may be reported
+ # by presenting user_setup_url (for 1.1) or reporting
+ # mode 'setup_needed' (for 2.0). Also catching all modes other than
+ # id_res, in order to avoid throwing errors.
+ if(isset($this->data['openid_user_setup_url'])) {
+ $this->setup_url = $this->data['openid_user_setup_url'];
+ return false;
+ }
+ if($this->mode != 'id_res') {
+ return false;
+ }
+
+ $this->claimed_id = isset($this->data['openid_claimed_id'])?$this->data['openid_claimed_id']:$this->data['openid_identity'];
+ $params = array(
+ 'openid.assoc_handle' => $this->data['openid_assoc_handle'],
+ 'openid.signed' => $this->data['openid_signed'],
+ 'openid.sig' => $this->data['openid_sig'],
+ );
+
+ if (isset($this->data['openid_ns'])) {
+ # We're dealing with an OpenID 2.0 server, so let's set an ns
+ # Even though we should know location of the endpoint,
+ # we still need to verify it by discovery, so $server is not set here
+ $params['openid.ns'] = 'http://specs.openid.net/auth/2.0';
+ } elseif (isset($this->data['openid_claimed_id'])
+ && $this->data['openid_claimed_id'] != $this->data['openid_identity']
+ ) {
+ # If it's an OpenID 1 provider, and we've got claimed_id,
+ # we have to append it to the returnUrl, like authUrl_v1 does.
+ $this->returnUrl .= (strpos($this->returnUrl, '?') ? '&' : '?')
+ . 'openid.claimed_id=' . $this->claimed_id;
+ }
+
+ if ($this->data['openid_return_to'] != $this->returnUrl) {
+ # The return_to url must match the url of current request.
+ # I'm assuing that noone will set the returnUrl to something that doesn't make sense.
+ return false;
+ }
+
+ $server = $this->discover($this->claimed_id);
+
+ foreach (explode(',', $this->data['openid_signed']) as $item) {
+ # Checking whether magic_quotes_gpc is turned on, because
+ # the function may fail if it is. For example, when fetching
+ # AX namePerson, it might containg an apostrophe, which will be escaped.
+ # In such case, validation would fail, since we'd send different data than OP
+ # wants to verify. stripslashes() should solve that problem, but we can't
+ # use it when magic_quotes is off.
+ $value = $this->data['openid_' . str_replace('.','_',$item)];
+ $params['openid.' . $item] = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ? stripslashes($value) : $value;
+
+ }
+
+ $params['openid.mode'] = 'check_authentication';
+
+ $response = $this->request($server, 'POST', $params);
+
+ return preg_match('/is_valid\s*:\s*true/i', $response);
+ }
+
+ protected function getAxAttributes()
+ {
+ $alias = null;
+ if (isset($this->data['openid_ns_ax'])
+ && $this->data['openid_ns_ax'] != 'http://openid.net/srv/ax/1.0'
+ ) { # It's the most likely case, so we'll check it before
+ $alias = 'ax';
+ } else {
+ # 'ax' prefix is either undefined, or points to another extension,
+ # so we search for another prefix
+ foreach ($this->data as $key => $val) {
+ if (substr($key, 0, strlen('openid_ns_')) == 'openid_ns_'
+ && $val == 'http://openid.net/srv/ax/1.0'
+ ) {
+ $alias = substr($key, strlen('openid_ns_'));
+ break;
+ }
+ }
+ }
+ if (!$alias) {
+ # An alias for AX schema has not been found,
+ # so there is no AX data in the OP's response
+ return array();
+ }
+
+ $attributes = array();
+ foreach (explode(',', $this->data['openid_signed']) as $key) {
+ $keyMatch = $alias . '.value.';
+ if (substr($key, 0, strlen($keyMatch)) != $keyMatch) {
+ continue;
+ }
+ $key = substr($key, strlen($keyMatch));
+ if (!isset($this->data['openid_' . $alias . '_type_' . $key])) {
+ # OP is breaking the spec by returning a field without
+ # associated ns. This shouldn't happen, but it's better
+ # to check, than cause an E_NOTICE.
+ continue;
+ }
+ $value = $this->data['openid_' . $alias . '_value_' . $key];
+ $key = substr($this->data['openid_' . $alias . '_type_' . $key],
+ strlen('http://axschema.org/'));
+
+ $attributes[$key] = $value;
+ }
+ return $attributes;
+ }
+
+ protected function getSregAttributes()
+ {
+ $attributes = array();
+ $sreg_to_ax = array_flip(self::$ax_to_sreg);
+ foreach (explode(',', $this->data['openid_signed']) as $key) {
+ $keyMatch = 'sreg.';
+ if (substr($key, 0, strlen($keyMatch)) != $keyMatch) {
+ continue;
+ }
+ $key = substr($key, strlen($keyMatch));
+ if (!isset($sreg_to_ax[$key])) {
+ # The field name isn't part of the SREG spec, so we ignore it.
+ continue;
+ }
+ $attributes[$sreg_to_ax[$key]] = $this->data['openid_sreg_' . $key];
+ }
+ return $attributes;
+ }
+
+ /**
+ * Gets AX/SREG attributes provided by OP. should be used only after successful validaton.
+ * Note that it does not guarantee that any of the required/optional parameters will be present,
+ * or that there will be no other attributes besides those specified.
+ * In other words. OP may provide whatever information it wants to.
+ * * SREG names will be mapped to AX names.
+ * * @return Array Array of attributes with keys being the AX schema names, e.g. 'contact/email'
+ * @see http://www.axschema.org/types/
+ */
+ function getAttributes()
+ {
+ if (isset($this->data['openid_ns'])
+ && $this->data['openid_ns'] == 'http://specs.openid.net/auth/2.0'
+ ) { # OpenID 2.0
+ # We search for both AX and SREG attributes, with AX taking precedence.
+ return $this->getAxAttributes() + $this->getSregAttributes();
+ }
+ return $this->getSregAttributes();
+ }
+}
diff --git a/includes/libs/Smarty/Smarty.class.php b/includes/libs/Smarty/Smarty.class.php
index e48bf94..4e3cacd 100644
--- a/includes/libs/Smarty/Smarty.class.php
+++ b/includes/libs/Smarty/Smarty.class.php
@@ -1,55 +1,55 @@
-* @author Uwe Tews
-* @author Rodney Rehm
-* @package Smarty
-* @version 3.1-DEV
-*/
+ * Project: Smarty: the PHP compiling template engine
+ * File: Smarty.class.php
+ * SVN: $Id$
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For questions, help, comments, discussion, etc., please join the
+ * Smarty mailing list. Send a blank e-mail to
+ * smarty-discussion-subscribe@googlegroups.com
+ *
+ * @link http://www.smarty.net/
+ * @copyright 2008 New Digital Group, Inc.
+ * @author Monte Ohrt
+ * @author Uwe Tews
+ * @author Rodney Rehm
+ * @package Smarty
+ * @version 3.1.12
+ */
/**
-* define shorthand directory separator constant
-*/
+ * define shorthand directory separator constant
+ */
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
/**
-* set SMARTY_DIR to absolute path to Smarty library files.
-* Sets SMARTY_DIR only if user application has not already defined it.
-*/
+ * set SMARTY_DIR to absolute path to Smarty library files.
+ * Sets SMARTY_DIR only if user application has not already defined it.
+ */
if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', dirname(__FILE__) . DS);
}
/**
-* set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins.
-* Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it.
-*/
+ * set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins.
+ * Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it.
+ */
if (!defined('SMARTY_SYSPLUGINS_DIR')) {
define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
}
@@ -57,19 +57,25 @@
define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);
}
if (!defined('SMARTY_MBSTRING')) {
- define('SMARTY_MBSTRING', function_exists('mb_strlen'));
+ define('SMARTY_MBSTRING', function_exists('mb_split'));
}
if (!defined('SMARTY_RESOURCE_CHAR_SET')) {
// UTF-8 can only be done properly when mbstring is available!
+ /**
+ * @deprecated in favor of Smarty::$_CHARSET
+ */
define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1');
}
if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
+ /**
+ * @deprecated in favor of Smarty::$_DATE_FORMAT
+ */
define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
}
/**
-* register the class autoloader
-*/
+ * register the class autoloader
+ */
if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0);
}
@@ -84,8 +90,8 @@
}
/**
-* Load always needed external class files
-*/
+ * Load always needed external class files
+ */
include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_data.php';
include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_templatebase.php';
include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_template.php';
@@ -95,56 +101,56 @@
include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_cacheresource_file.php';
/**
-* This is the main Smarty class
-* @package Smarty
-*/
+ * This is the main Smarty class
+ * @package Smarty
+ */
class Smarty extends Smarty_Internal_TemplateBase {
/**#@+
- * constant definitions
- */
+ * constant definitions
+ */
/**
- * smarty version
- */
- const SMARTY_VERSION = 'Smarty 3.1-DEV';
+ * smarty version
+ */
+ const SMARTY_VERSION = 'Smarty-3.1.12';
/**
- * define variable scopes
- */
+ * define variable scopes
+ */
const SCOPE_LOCAL = 0;
const SCOPE_PARENT = 1;
const SCOPE_ROOT = 2;
const SCOPE_GLOBAL = 3;
/**
- * define caching modes
- */
+ * define caching modes
+ */
const CACHING_OFF = 0;
const CACHING_LIFETIME_CURRENT = 1;
const CACHING_LIFETIME_SAVED = 2;
/**
- * define compile check modes
- */
+ * define compile check modes
+ */
const COMPILECHECK_OFF = 0;
const COMPILECHECK_ON = 1;
const COMPILECHECK_CACHEMISS = 2;
/**
- * modes for handling of "" tags in templates.
- */
+ * modes for handling of "" tags in templates.
+ */
const PHP_PASSTHRU = 0; //-> print tags as plain text
const PHP_QUOTE = 1; //-> escape tags as entities
const PHP_REMOVE = 2; //-> escape tags as entities
const PHP_ALLOW = 3; //-> escape tags as entities
/**
- * filter types
- */
+ * filter types
+ */
const FILTER_POST = 'post';
const FILTER_PRE = 'pre';
const FILTER_OUTPUT = 'output';
const FILTER_VARIABLE = 'variable';
/**
- * plugin types
- */
+ * plugin types
+ */
const PLUGIN_FUNCTION = 'function';
const PLUGIN_BLOCK = 'block';
const PLUGIN_COMPILER = 'compiler';
@@ -154,10 +160,10 @@ class Smarty extends Smarty_Internal_TemplateBase {
/**#@-*/
/**
- * assigned global tpl vars
- */
+ * assigned global tpl vars
+ */
public static $global_tpl_vars = array();
-
+
/**
* error handler returned by set_error_hanlder() in Smarty::muteExpectedErrors()
*/
@@ -166,90 +172,112 @@ class Smarty extends Smarty_Internal_TemplateBase {
* contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors()
*/
public static $_muted_directories = array();
+ /**
+ * Flag denoting if Multibyte String functions are available
+ */
+ public static $_MBSTRING = SMARTY_MBSTRING;
+ /**
+ * The character set to adhere to (e.g. "UTF-8")
+ */
+ public static $_CHARSET = SMARTY_RESOURCE_CHAR_SET;
+ /**
+ * The date format to be used internally
+ * (accepts date() and strftime())
+ */
+ public static $_DATE_FORMAT = SMARTY_RESOURCE_DATE_FORMAT;
+ /**
+ * Flag denoting if PCRE should run in UTF-8 mode
+ */
+ public static $_UTF8_MODIFIER = 'u';
+
+ /**
+ * Flag denoting if operating system is windows
+ */
+ public static $_IS_WINDOWS = false;
/**#@+
- * variables
- */
+ * variables
+ */
/**
- * auto literal on delimiters with whitspace
- * @var boolean
- */
+ * auto literal on delimiters with whitspace
+ * @var boolean
+ */
public $auto_literal = true;
/**
- * display error on not assigned variables
- * @var boolean
- */
+ * display error on not assigned variables
+ * @var boolean
+ */
public $error_unassigned = false;
/**
- * look up relative filepaths in include_path
- * @var boolean
- */
+ * look up relative filepaths in include_path
+ * @var boolean
+ */
public $use_include_path = false;
/**
- * template directory
- * @var array
- */
- protected $template_dir = array();
+ * template directory
+ * @var array
+ */
+ private $template_dir = array();
/**
- * joined template directory string used in cache keys
- * @var string
- */
+ * joined template directory string used in cache keys
+ * @var string
+ */
public $joined_template_dir = null;
/**
- * joined config directory string used in cache keys
- * @var string
- */
+ * joined config directory string used in cache keys
+ * @var string
+ */
public $joined_config_dir = null;
/**
- * default template handler
- * @var callable
- */
+ * default template handler
+ * @var callable
+ */
public $default_template_handler_func = null;
/**
- * default config handler
- * @var callable
- */
+ * default config handler
+ * @var callable
+ */
public $default_config_handler_func = null;
/**
- * default plugin handler
- * @var callable
- */
+ * default plugin handler
+ * @var callable
+ */
public $default_plugin_handler_func = null;
/**
- * compile directory
- * @var string
- */
- protected $compile_dir = null;
- /**
- * plugins directory
- * @var array
- */
- protected $plugins_dir = array();
- /**
- * cache directory
- * @var string
- */
- protected $cache_dir = null;
- /**
- * config directory
- * @var array
- */
- protected $config_dir = array();
- /**
- * force template compiling?
- * @var boolean
- */
+ * compile directory
+ * @var string
+ */
+ private $compile_dir = null;
+ /**
+ * plugins directory
+ * @var array
+ */
+ private $plugins_dir = array();
+ /**
+ * cache directory
+ * @var string
+ */
+ private $cache_dir = null;
+ /**
+ * config directory
+ * @var array
+ */
+ private $config_dir = array();
+ /**
+ * force template compiling?
+ * @var boolean
+ */
public $force_compile = false;
/**
- * check template for modifications?
- * @var boolean
- */
+ * check template for modifications?
+ * @var boolean
+ */
public $compile_check = true;
/**
- * use sub dirs for compiled/cached files?
- * @var boolean
- */
+ * use sub dirs for compiled/cached files?
+ * @var boolean
+ */
public $use_sub_dirs = false;
/**
* allow ambiguous resources (that are made unique by the resource handler)
@@ -257,24 +285,24 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/
public $allow_ambiguous_resources = false;
/**
- * caching enabled
- * @var boolean
- */
+ * caching enabled
+ * @var boolean
+ */
public $caching = false;
/**
- * merge compiled includes
- * @var boolean
- */
+ * merge compiled includes
+ * @var boolean
+ */
public $merge_compiled_includes = false;
/**
- * cache lifetime in seconds
- * @var integer
- */
+ * cache lifetime in seconds
+ * @var integer
+ */
public $cache_lifetime = 3600;
/**
- * force cache file creation
- * @var boolean
- */
+ * force cache file creation
+ * @var boolean
+ */
public $force_cache = false;
/**
* Set this if you want different sets of cache files for the same
@@ -291,63 +319,63 @@ class Smarty extends Smarty_Internal_TemplateBase {
*/
public $compile_id = null;
/**
- * template left-delimiter
- * @var string
- */
+ * template left-delimiter
+ * @var string
+ */
public $left_delimiter = "{";
/**
- * template right-delimiter
- * @var string
- */
+ * template right-delimiter
+ * @var string
+ */
public $right_delimiter = "}";
/**#@+
- * security
- */
- /**
- * class name
- *
- * This should be instance of Smarty_Security.
- *
- * @var string
- * @see Smarty_Security
- */
+ * security
+ */
+ /**
+ * class name
+ *
+ * This should be instance of Smarty_Security.
+ *
+ * @var string
+ * @see Smarty_Security
+ */
public $security_class = 'Smarty_Security';
/**
- * implementation of security class
- *
- * @var Smarty_Security
- */
+ * implementation of security class
+ *
+ * @var Smarty_Security
+ */
public $security_policy = null;
/**
- * controls handling of PHP-blocks
- *
- * @var integer
- */
+ * controls handling of PHP-blocks
+ *
+ * @var integer
+ */
public $php_handling = self::PHP_PASSTHRU;
/**
- * controls if the php template file resource is allowed
- *
- * @var bool
- */
+ * controls if the php template file resource is allowed
+ *
+ * @var bool
+ */
public $allow_php_templates = false;
/**
- * Should compiled-templates be prevented from being called directly?
- *
- * {@internal
- * Currently used by Smarty_Internal_Template only.
- * }}
- *
- * @var boolean
- */
+ * Should compiled-templates be prevented from being called directly?
+ *
+ * {@internal
+ * Currently used by Smarty_Internal_Template only.
+ * }}
+ *
+ * @var boolean
+ */
public $direct_access_security = true;
/**#@-*/
/**
- * debug mode
- *
- * Setting this to true enables the debug-console.
- *
- * @var boolean
- */
+ * debug mode
+ *
+ * Setting this to true enables the debug-console.
+ *
+ * @var boolean
+ */
public $debugging = false;
/**
* This determines if debugging is enable-able from the browser.
@@ -355,64 +383,64 @@ class Smarty extends Smarty_Internal_TemplateBase {
*
NONE => no debugging control allowed
*
URL => enable debugging when SMARTY_DEBUG is found in the URL.
*
- * @var string
- */
+ * @var string
+ */
public $debugging_ctrl = 'NONE';
/**
- * Name of debugging URL-param.
- *
- * Only used when $debugging_ctrl is set to 'URL'.
- * The name of the URL-parameter that activates debugging.
- *
- * @var type
- */
+ * Name of debugging URL-param.
+ *
+ * Only used when $debugging_ctrl is set to 'URL'.
+ * The name of the URL-parameter that activates debugging.
+ *
+ * @var type
+ */
public $smarty_debug_id = 'SMARTY_DEBUG';
/**
- * Path of debug template.
- * @var string
- */
+ * Path of debug template.
+ * @var string
+ */
public $debug_tpl = null;
/**
- * When set, smarty uses this value as error_reporting-level.
- * @var int
- */
+ * When set, smarty uses this value as error_reporting-level.
+ * @var int
+ */
public $error_reporting = null;
/**
- * Internal flag for getTags()
- * @var boolean
- */
+ * Internal flag for getTags()
+ * @var boolean
+ */
public $get_used_tags = false;
/**#@+
- * config var settings
- */
+ * config var settings
+ */
/**
- * Controls whether variables with the same name overwrite each other.
- * @var boolean
- */
+ * Controls whether variables with the same name overwrite each other.
+ * @var boolean
+ */
public $config_overwrite = true;
/**
- * Controls whether config values of on/true/yes and off/false/no get converted to boolean.
- * @var boolean
- */
+ * Controls whether config values of on/true/yes and off/false/no get converted to boolean.
+ * @var boolean
+ */
public $config_booleanize = true;
/**
- * Controls whether hidden config sections/vars are read from the file.
- * @var boolean
- */
+ * Controls whether hidden config sections/vars are read from the file.
+ * @var boolean
+ */
public $config_read_hidden = false;
/**#@-*/
/**#@+
- * resource locking
- */
+ * resource locking
+ */
/**
- * locking concurrent compiles
- * @var boolean
- */
+ * locking concurrent compiles
+ * @var boolean
+ */
public $compile_locking = true;
/**
* Controls whether cache resources should emply locking mechanism
@@ -428,163 +456,163 @@ class Smarty extends Smarty_Internal_TemplateBase {
/**#@-*/
/**
- * global template functions
- * @var array
- */
+ * global template functions
+ * @var array
+ */
public $template_functions = array();
/**
- * resource type used if none given
- *
- * Must be an valid key of $registered_resources.
- * @var string
- */
+ * resource type used if none given
+ *
+ * Must be an valid key of $registered_resources.
+ * @var string
+ */
public $default_resource_type = 'file';
/**
- * caching type
- *
- * Must be an element of $cache_resource_types.
- *
- * @var string
- */
+ * caching type
+ *
+ * Must be an element of $cache_resource_types.
+ *
+ * @var string
+ */
public $caching_type = 'file';
/**
- * internal config properties
- * @var array
- */
+ * internal config properties
+ * @var array
+ */
public $properties = array();
/**
- * config type
- * @var string
- */
+ * config type
+ * @var string
+ */
public $default_config_type = 'file';
/**
- * cached template objects
- * @var array
- */
+ * cached template objects
+ * @var array
+ */
public $template_objects = array();
/**
- * check If-Modified-Since headers
- * @var boolean
- */
+ * check If-Modified-Since headers
+ * @var boolean
+ */
public $cache_modified_check = false;
/**
- * registered plugins
- * @var array
- */
+ * registered plugins
+ * @var array
+ */
public $registered_plugins = array();
/**
- * plugin search order
- * @var array
- */
+ * plugin search order
+ * @var array
+ */
public $plugin_search_order = array('function', 'block', 'compiler', 'class');
/**
- * registered objects
- * @var array
- */
+ * registered objects
+ * @var array
+ */
public $registered_objects = array();
/**
- * registered classes
- * @var array
- */
+ * registered classes
+ * @var array
+ */
public $registered_classes = array();
/**
- * registered filters
- * @var array
- */
+ * registered filters
+ * @var array
+ */
public $registered_filters = array();
/**
- * registered resources
- * @var array
- */
+ * registered resources
+ * @var array
+ */
public $registered_resources = array();
/**
- * resource handler cache
- * @var array
- */
+ * resource handler cache
+ * @var array
+ */
public $_resource_handlers = array();
/**
- * registered cache resources
- * @var array
- */
+ * registered cache resources
+ * @var array
+ */
public $registered_cache_resources = array();
/**
- * cache resource handler cache
- * @var array
- */
+ * cache resource handler cache
+ * @var array
+ */
public $_cacheresource_handlers = array();
/**
- * autoload filter
- * @var array
- */
+ * autoload filter
+ * @var array
+ */
public $autoload_filters = array();
/**
- * default modifier
- * @var array
- */
+ * default modifier
+ * @var array
+ */
public $default_modifiers = array();
/**
- * autoescape variable output
- * @var boolean
- */
+ * autoescape variable output
+ * @var boolean
+ */
public $escape_html = false;
/**
- * global internal smarty vars
- * @var array
- */
+ * global internal smarty vars
+ * @var array
+ */
public static $_smarty_vars = array();
/**
- * start time for execution time calculation
- * @var int
- */
+ * start time for execution time calculation
+ * @var int
+ */
public $start_time = 0;
/**
- * default file permissions
- * @var int
- */
+ * default file permissions
+ * @var int
+ */
public $_file_perms = 0644;
/**
- * default dir permissions
- * @var int
- */
+ * default dir permissions
+ * @var int
+ */
public $_dir_perms = 0771;
/**
- * block tag hierarchy
- * @var array
- */
+ * block tag hierarchy
+ * @var array
+ */
public $_tag_stack = array();
/**
- * self pointer to Smarty object
- * @var Smarty
- */
+ * self pointer to Smarty object
+ * @var Smarty
+ */
public $smarty;
/**
- * required by the compiler for BC
- * @var string
- */
+ * required by the compiler for BC
+ * @var string
+ */
public $_current_file = null;
/**
- * internal flag to enable parser debugging
- * @var bool
- */
+ * internal flag to enable parser debugging
+ * @var bool
+ */
public $_parserdebug = false;
/**
- * Saved parameter of merged templates during compilation
- *
- * @var array
- */
+ * Saved parameter of merged templates during compilation
+ *
+ * @var array
+ */
public $merged_templates_func = array();
/**#@-*/
/**
- * Initialize new Smarty object
- *
- */
+ * Initialize new Smarty object
+ *
+ */
public function __construct()
{
// selfpointer needed by some other class methods
$this->smarty = $this;
if (is_callable('mb_internal_encoding')) {
- mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET);
+ mb_internal_encoding(Smarty::$_CHARSET);
}
$this->start_time = microtime(true);
// set default dirs
@@ -593,25 +621,25 @@ public function __construct()
->setPluginsDir(SMARTY_PLUGINS_DIR)
->setCacheDir('.' . DS . 'cache' . DS)
->setConfigDir('.' . DS . 'configs' . DS);
-
+
$this->debug_tpl = 'file:' . dirname(__FILE__) . '/debug.tpl';
if (isset($_SERVER['SCRIPT_NAME'])) {
$this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
}
}
-
+
/**
- * Class destructor
- */
+ * Class destructor
+ */
public function __destruct()
{
// intentionally left blank
}
/**
- * <> set selfpointer on cloned object
- */
+ * <> set selfpointer on cloned object
+ */
public function __clone()
{
$this->smarty = $this;
@@ -619,14 +647,14 @@ public function __clone()
/**
- * <> Generic getter.
- *
- * Calls the appropriate getter function.
- * Issues an E_USER_NOTICE if no valid getter is found.
- *
- * @param string $name property name
- * @return mixed
- */
+ * <> Generic getter.
+ *
+ * Calls the appropriate getter function.
+ * Issues an E_USER_NOTICE if no valid getter is found.
+ *
+ * @param string $name property name
+ * @return mixed
+ */
public function __get($name)
{
$allowed = array(
@@ -645,14 +673,14 @@ public function __get($name)
}
/**
- * <> Generic setter.
- *
- * Calls the appropriate setter function.
- * Issues an E_USER_NOTICE if no valid setter is found.
- *
- * @param string $name property name
- * @param mixed $value parameter passed to setter
- */
+ * <> Generic setter.
+ *
+ * Calls the appropriate setter function.
+ * Issues an E_USER_NOTICE if no valid setter is found.
+ *
+ * @param string $name property name
+ * @param mixed $value parameter passed to setter
+ */
public function __set($name, $value)
{
$allowed = array(
@@ -671,11 +699,11 @@ public function __set($name, $value)
}
/**
- * Check if a template resource exists
- *
- * @param string $resource_name template name
- * @return boolean status
- */
+ * Check if a template resource exists
+ *
+ * @param string $resource_name template name
+ * @return boolean status
+ */
public function templateExists($resource_name)
{
// create template object
@@ -688,12 +716,12 @@ public function templateExists($resource_name)
}
/**
- * Returns a single or all global variables
- *
- * @param object $smarty
- * @param string $varname variable name or null
- * @return string variable value or or array of variables
- */
+ * Returns a single or all global variables
+ *
+ * @param object $smarty
+ * @param string $varname variable name or null
+ * @return string variable value or or array of variables
+ */
public function getGlobal($varname = null)
{
if (isset($varname)) {
@@ -712,12 +740,12 @@ public function getGlobal($varname = null)
}
/**
- * Empty cache folder
- *
- * @param integer $exp_time expiration time
- * @param string $type resource type
- * @return integer number of cache files deleted
- */
+ * Empty cache folder
+ *
+ * @param integer $exp_time expiration time
+ * @param string $type resource type
+ * @return integer number of cache files deleted
+ */
function clearAllCache($exp_time = null, $type = null)
{
// load cache resource and call clearAll
@@ -727,15 +755,15 @@ function clearAllCache($exp_time = null, $type = null)
}
/**
- * Empty cache for a specific template
- *
- * @param string $template_name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param integer $exp_time expiration time
- * @param string $type resource type
- * @return integer number of cache files deleted
- */
+ * Empty cache for a specific template
+ *
+ * @param string $template_name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param integer $exp_time expiration time
+ * @param string $type resource type
+ * @return integer number of cache files deleted
+ */
public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
{
// load cache resource and call clear
@@ -745,12 +773,12 @@ public function clearCache($template_name, $cache_id = null, $compile_id = null,
}
/**
- * Loads security class and enables security
- *
- * @param string|Smarty_Security $security_class if a string is used, it must be class-name
- * @return Smarty current Smarty instance for chaining
- * @throws SmartyException when an invalid class name is provided
- */
+ * Loads security class and enables security
+ *
+ * @param string|Smarty_Security $security_class if a string is used, it must be class-name
+ * @return Smarty current Smarty instance for chaining
+ * @throws SmartyException when an invalid class name is provided
+ */
public function enableSecurity($security_class = null)
{
if ($security_class instanceof Smarty_Security) {
@@ -774,9 +802,9 @@ public function enableSecurity($security_class = null)
}
/**
- * Disable security
- * @return Smarty current Smarty instance for chaining
- */
+ * Disable security
+ * @return Smarty current Smarty instance for chaining
+ */
public function disableSecurity()
{
$this->security_policy = null;
@@ -785,11 +813,11 @@ public function disableSecurity()
}
/**
- * Set template directory
- *
- * @param string|array $template_dir directory(s) of template sources
- * @return Smarty current Smarty instance for chaining
- */
+ * Set template directory
+ *
+ * @param string|array $template_dir directory(s) of template sources
+ * @return Smarty current Smarty instance for chaining
+ */
public function setTemplateDir($template_dir)
{
$this->template_dir = array();
@@ -802,13 +830,13 @@ public function setTemplateDir($template_dir)
}
/**
- * Add template directory(s)
- *
- * @param string|array $template_dir directory(s) of template sources
- * @param string $key of the array element to assign the template dir to
- * @return Smarty current Smarty instance for chaining
- * @throws SmartyException when the given template directory is not valid
- */
+ * Add template directory(s)
+ *
+ * @param string|array $template_dir directory(s) of template sources
+ * @param string $key of the array element to assign the template dir to
+ * @return Smarty current Smarty instance for chaining
+ * @throws SmartyException when the given template directory is not valid
+ */
public function addTemplateDir($template_dir, $key=null)
{
// make sure we're dealing with an array
@@ -836,11 +864,11 @@ public function addTemplateDir($template_dir, $key=null)
}
/**
- * Get template directories
- *
- * @param mixed index of directory to get, null to get all
- * @return array|string list of template directories, or directory of $index
- */
+ * Get template directories
+ *
+ * @param mixed index of directory to get, null to get all
+ * @return array|string list of template directories, or directory of $index
+ */
public function getTemplateDir($index=null)
{
if ($index !== null) {
@@ -851,29 +879,29 @@ public function getTemplateDir($index=null)
}
/**
- * Set config directory
- *
- * @param string|array $template_dir directory(s) of configuration sources
- * @return Smarty current Smarty instance for chaining
- */
+ * Set config directory
+ *
+ * @param string|array $template_dir directory(s) of configuration sources
+ * @return Smarty current Smarty instance for chaining
+ */
public function setConfigDir($config_dir)
{
$this->config_dir = array();
foreach ((array) $config_dir as $k => $v) {
$this->config_dir[$k] = rtrim($v, '/\\') . DS;
}
-
+
$this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
return $this;
}
/**
- * Add config directory(s)
- *
- * @param string|array $config_dir directory(s) of config sources
- * @param string key of the array element to assign the config dir to
- * @return Smarty current Smarty instance for chaining
- */
+ * Add config directory(s)
+ *
+ * @param string|array $config_dir directory(s) of config sources
+ * @param string key of the array element to assign the config dir to
+ * @return Smarty current Smarty instance for chaining
+ */
public function addConfigDir($config_dir, $key=null)
{
// make sure we're dealing with an array
@@ -896,17 +924,17 @@ public function addConfigDir($config_dir, $key=null)
// append new directory
$this->config_dir[] = rtrim($config_dir, '/\\') . DS;
}
-
+
$this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir);
return $this;
}
/**
- * Get config directory
- *
- * @param mixed index of directory to get, null to get all
- * @return array|string configuration directory
- */
+ * Get config directory
+ *
+ * @param mixed index of directory to get, null to get all
+ * @return array|string configuration directory
+ */
public function getConfigDir($index=null)
{
if ($index !== null) {
@@ -917,11 +945,11 @@ public function getConfigDir($index=null)
}
/**
- * Set plugins directory
- *
- * @param string|array $plugins_dir directory(s) of plugins
- * @return Smarty current Smarty instance for chaining
- */
+ * Set plugins directory
+ *
+ * @param string|array $plugins_dir directory(s) of plugins
+ * @return Smarty current Smarty instance for chaining
+ */
public function setPluginsDir($plugins_dir)
{
$this->plugins_dir = array();
@@ -933,12 +961,12 @@ public function setPluginsDir($plugins_dir)
}
/**
- * Adds directory of plugin files
- *
- * @param object $smarty
- * @param string $ |array $ plugins folder
- * @return Smarty current Smarty instance for chaining
- */
+ * Adds directory of plugin files
+ *
+ * @param object $smarty
+ * @param string $ |array $ plugins folder
+ * @return Smarty current Smarty instance for chaining
+ */
public function addPluginsDir($plugins_dir)
{
// make sure we're dealing with an array
@@ -964,21 +992,21 @@ public function addPluginsDir($plugins_dir)
}
/**
- * Get plugin directories
- *
- * @return array list of plugin directories
- */
+ * Get plugin directories
+ *
+ * @return array list of plugin directories
+ */
public function getPluginsDir()
{
return (array)$this->plugins_dir;
}
/**
- * Set compile directory
- *
- * @param string $compile_dir directory to store compiled templates in
- * @return Smarty current Smarty instance for chaining
- */
+ * Set compile directory
+ *
+ * @param string $compile_dir directory to store compiled templates in
+ * @return Smarty current Smarty instance for chaining
+ */
public function setCompileDir($compile_dir)
{
$this->compile_dir = rtrim($compile_dir, '/\\') . DS;
@@ -989,21 +1017,21 @@ public function setCompileDir($compile_dir)
}
/**
- * Get compiled directory
- *
- * @return string path to compiled templates
- */
+ * Get compiled directory
+ *
+ * @return string path to compiled templates
+ */
public function getCompileDir()
{
return $this->compile_dir;
}
/**
- * Set cache directory
- *
- * @param string $cache_dir directory to store cached templates in
- * @return Smarty current Smarty instance for chaining
- */
+ * Set cache directory
+ *
+ * @param string $cache_dir directory to store cached templates in
+ * @return Smarty current Smarty instance for chaining
+ */
public function setCacheDir($cache_dir)
{
$this->cache_dir = rtrim($cache_dir, '/\\') . DS;
@@ -1014,21 +1042,21 @@ public function setCacheDir($cache_dir)
}
/**
- * Get cache directory
- *
- * @return string path of cache directory
- */
+ * Get cache directory
+ *
+ * @return string path of cache directory
+ */
public function getCacheDir()
{
return $this->cache_dir;
}
/**
- * Set default modifiers
- *
- * @param array|string $modifiers modifier or list of modifiers to set
- * @return Smarty current Smarty instance for chaining
- */
+ * Set default modifiers
+ *
+ * @param array|string $modifiers modifier or list of modifiers to set
+ * @return Smarty current Smarty instance for chaining
+ */
public function setDefaultModifiers($modifiers)
{
$this->default_modifiers = (array) $modifiers;
@@ -1036,11 +1064,11 @@ public function setDefaultModifiers($modifiers)
}
/**
- * Add default modifiers
- *
- * @param array|string $modifiers modifier or list of modifiers to add
- * @return Smarty current Smarty instance for chaining
- */
+ * Add default modifiers
+ *
+ * @param array|string $modifiers modifier or list of modifiers to add
+ * @return Smarty current Smarty instance for chaining
+ */
public function addDefaultModifiers($modifiers)
{
if (is_array($modifiers)) {
@@ -1053,10 +1081,10 @@ public function addDefaultModifiers($modifiers)
}
/**
- * Get default modifiers
- *
- * @return array list of default modifiers
- */
+ * Get default modifiers
+ *
+ * @return array list of default modifiers
+ */
public function getDefaultModifiers()
{
return $this->default_modifiers;
@@ -1064,12 +1092,12 @@ public function getDefaultModifiers()
/**
- * Set autoload filters
- *
- * @param array $filters filters to load automatically
- * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
- * @return Smarty current Smarty instance for chaining
- */
+ * Set autoload filters
+ *
+ * @param array $filters filters to load automatically
+ * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
+ * @return Smarty current Smarty instance for chaining
+ */
public function setAutoloadFilters($filters, $type=null)
{
if ($type !== null) {
@@ -1082,12 +1110,12 @@ public function setAutoloadFilters($filters, $type=null)
}
/**
- * Add autoload filters
- *
- * @param array $filters filters to load automatically
- * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
- * @return Smarty current Smarty instance for chaining
- */
+ * Add autoload filters
+ *
+ * @param array $filters filters to load automatically
+ * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types
+ * @return Smarty current Smarty instance for chaining
+ */
public function addAutoloadFilters($filters, $type=null)
{
if ($type !== null) {
@@ -1110,11 +1138,11 @@ public function addAutoloadFilters($filters, $type=null)
}
/**
- * Get autoload filters
- *
- * @param string $type type of filter to get autoloads for. Defaults to all autoload filters
- * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified
- */
+ * Get autoload filters
+ *
+ * @param string $type type of filter to get autoloads for. Defaults to all autoload filters
+ * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified
+ */
public function getAutoloadFilters($type=null)
{
if ($type !== null) {
@@ -1125,22 +1153,22 @@ public function getAutoloadFilters($type=null)
}
/**
- * return name of debugging template
- *
- * @return string
- */
+ * return name of debugging template
+ *
+ * @return string
+ */
public function getDebugTemplate()
{
return $this->debug_tpl;
}
/**
- * set the debug template
- *
- * @param string $tpl_name
- * @return Smarty current Smarty instance for chaining
- * @throws SmartyException if file is not readable
- */
+ * set the debug template
+ *
+ * @param string $tpl_name
+ * @return Smarty current Smarty instance for chaining
+ * @throws SmartyException if file is not readable
+ */
public function setDebugTemplate($tpl_name)
{
if (!is_readable($tpl_name)) {
@@ -1152,15 +1180,15 @@ public function setDebugTemplate($tpl_name)
}
/**
- * creates a template object
- *
- * @param string $template the resource handle of the template file
- * @param mixed $cache_id cache id to be used with this template
- * @param mixed $compile_id compile id to be used with this template
- * @param object $parent next higher level of Smarty variables
- * @param boolean $do_clone flag is Smarty object shall be cloned
- * @return object template object
- */
+ * creates a template object
+ *
+ * @param string $template the resource handle of the template file
+ * @param mixed $cache_id cache id to be used with this template
+ * @param mixed $compile_id compile id to be used with this template
+ * @param object $parent next higher level of Smarty variables
+ * @param boolean $do_clone flag is Smarty object shall be cloned
+ * @return object template object
+ */
public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
{
if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) {
@@ -1191,6 +1219,8 @@ public function createTemplate($template, $cache_id = null, $compile_id = null,
$tpl = clone $this->template_objects[$_templateId];
$tpl->smarty = clone $tpl->smarty;
$tpl->parent = $parent;
+ $tpl->tpl_vars = array();
+ $tpl->config_vars = array();
} else {
$tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
}
@@ -1198,6 +1228,9 @@ public function createTemplate($template, $cache_id = null, $compile_id = null,
if (isset($this->template_objects[$_templateId])) {
// return cached template object
$tpl = $this->template_objects[$_templateId];
+ $tpl->parent = $parent;
+ $tpl->tpl_vars = array();
+ $tpl->config_vars = array();
} else {
$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
}
@@ -1214,14 +1247,14 @@ public function createTemplate($template, $cache_id = null, $compile_id = null,
/**
- * Takes unknown classes and loads plugin files for them
- * class name format: Smarty_PluginType_PluginName
- * plugin filename format: plugintype.pluginname.php
- *
- * @param string $plugin_name class plugin name to load
- * @param bool $check check if already loaded
- * @return string |boolean filepath of loaded file or false
- */
+ * Takes unknown classes and loads plugin files for them
+ * class name format: Smarty_PluginType_PluginName
+ * plugin filename format: plugintype.pluginname.php
+ *
+ * @param string $plugin_name class plugin name to load
+ * @param bool $check check if already loaded
+ * @return string |boolean filepath of loaded file or false
+ */
public function loadPlugin($plugin_name, $check = true)
{
// if function or class exists, exit silently (already loaded)
@@ -1249,6 +1282,8 @@ public function loadPlugin($plugin_name, $check = true)
// plugin filename is expected to be: [type].[name].php
$_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
+ $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
+
// loop through plugin dirs and find the plugin
foreach($this->getPluginsDir() as $_plugin_dir) {
$names = array(
@@ -1262,7 +1297,13 @@ public function loadPlugin($plugin_name, $check = true)
}
if ($this->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
// try PHP include_path
- if (($file = Smarty_Internal_Get_Include_Path::getIncludePath($file)) !== false) {
+ if ($_stream_resolve_include_path) {
+ $file = stream_resolve_include_path($file);
+ } else {
+ $file = Smarty_Internal_Get_Include_Path::getIncludePath($file);
+ }
+
+ if ($file !== false) {
require_once($file);
return $file;
}
@@ -1274,41 +1315,41 @@ public function loadPlugin($plugin_name, $check = true)
}
/**
- * Compile all template files
- *
- * @param string $extension file extension
- * @param bool $force_compile force all to recompile
- * @param int $time_limit
- * @param int $max_errors
- * @return integer number of template files recompiled
- */
+ * Compile all template files
+ *
+ * @param string $extension file extension
+ * @param bool $force_compile force all to recompile
+ * @param int $time_limit
+ * @param int $max_errors
+ * @return integer number of template files recompiled
+ */
public function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null)
{
return Smarty_Internal_Utility::compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, $this);
}
/**
- * Compile all config files
- *
- * @param string $extension file extension
- * @param bool $force_compile force all to recompile
- * @param int $time_limit
- * @param int $max_errors
- * @return integer number of template files recompiled
- */
+ * Compile all config files
+ *
+ * @param string $extension file extension
+ * @param bool $force_compile force all to recompile
+ * @param int $time_limit
+ * @param int $max_errors
+ * @return integer number of template files recompiled
+ */
public function compileAllConfig($extention = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null)
{
return Smarty_Internal_Utility::compileAllConfig($extention, $force_compile, $time_limit, $max_errors, $this);
}
/**
- * Delete compiled template file
- *
- * @param string $resource_name template name
- * @param string $compile_id compile id
- * @param integer $exp_time expiration time
- * @return integer number of template files deleted
- */
+ * Delete compiled template file
+ *
+ * @param string $resource_name template name
+ * @param string $compile_id compile id
+ * @param integer $exp_time expiration time
+ * @return integer number of template files deleted
+ */
public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
{
return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this);
@@ -1316,11 +1357,11 @@ public function clearCompiledTemplate($resource_name = null, $compile_id = null,
/**
- * Return array of tag/attributes of all tags used by an template
- *
- * @param object $templae template object
- * @return array of tag/attributes
- */
+ * Return array of tag/attributes of all tags used by an template
+ *
+ * @param object $templae template object
+ * @return array of tag/attributes
+ */
public function getTags(Smarty_Internal_Template $template)
{
return Smarty_Internal_Utility::getTags($template);
@@ -1347,7 +1388,7 @@ public function testInstall(&$errors=null)
public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
$_is_muted_directory = false;
-
+
// add the SMARTY_DIR to the list of muted directories
if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) {
$smarty_dir = realpath(SMARTY_DIR);
@@ -1356,7 +1397,7 @@ public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $
'length' => strlen($smarty_dir),
);
}
-
+
// walk the muted directories and test against $errfile
foreach (Smarty::$_muted_directories as $key => &$dir) {
if (!$dir) {
@@ -1427,23 +1468,34 @@ public static function unmuteExpectedErrors()
}
}
+// Check if we're running on windows
+Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
+
+// let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8
+if (Smarty::$_CHARSET !== 'UTF-8') {
+ Smarty::$_UTF8_MODIFIER = '';
+}
+
/**
-* Smarty exception class
-* @package Smarty
-*/
+ * Smarty exception class
+ * @package Smarty
+ */
class SmartyException extends Exception {
+ public function __construct($message) {
+ $this->message = htmlentities($message);
+ }
}
/**
-* Smarty compiler exception class
-* @package Smarty
-*/
+ * Smarty compiler exception class
+ * @package Smarty
+ */
class SmartyCompilerException extends SmartyException {
}
/**
-* Autoloader
-*/
+ * Autoloader
+ */
function smartyAutoload($class)
{
$_class = strtolower($class);
diff --git a/includes/libs/Smarty/debug.tpl b/includes/libs/Smarty/debug.tpl
deleted file mode 100644
index 058c5b2..0000000
--- a/includes/libs/Smarty/debug.tpl
+++ /dev/null
@@ -1,133 +0,0 @@
-{capture name='_smarty_debug' assign=debug_output}
-
-
-
- Smarty Debug Console
-
-
-
-
-
Smarty Debug Console - {if isset($template_name)}{$template_name|debug_print_var}{else}Total Time {$execution_time|string_format:"%.5f"}{/if}
-
-{if !empty($template_data)}
-
included templates & config files (load time in seconds)
-{include file="adm/overall_footer.tpl"}
\ No newline at end of file
+{include file="overall_footer.tpl"}
\ No newline at end of file
diff --git a/styles/templates/adm/CreatePage.tpl b/styles/templates/adm/CreatePage.tpl
index 0af19d5..04a3c59 100644
--- a/styles/templates/adm/CreatePage.tpl
+++ b/styles/templates/adm/CreatePage.tpl
@@ -1,10 +1,10 @@
-{include file="adm/overall_header.tpl"}
+{include file="overall_header.tpl"}
-{include file="adm/overall_footer.tpl"}
\ No newline at end of file
+{include file="overall_footer.tpl"}
\ No newline at end of file
diff --git a/styles/templates/adm/CreatePageMoon.tpl b/styles/templates/adm/CreatePageMoon.tpl
index b213caf..8855279 100644
--- a/styles/templates/adm/CreatePageMoon.tpl
+++ b/styles/templates/adm/CreatePageMoon.tpl
@@ -1,4 +1,4 @@
-{include file="adm/overall_header.tpl"}
+{include file="overall_header.tpl"}
@@ -15,7 +15,7 @@
{$mo_diameter}
- (Random)
+ ({$LNG.mo_moon_random})
{$mo_fields_avaibles}
@@ -28,4 +28,4 @@
-{include file="adm/overall_footer.tpl"}
\ No newline at end of file
+{include file="overall_footer.tpl"}
\ No newline at end of file
diff --git a/styles/templates/adm/CreatePagePlanet.tpl b/styles/templates/adm/CreatePagePlanet.tpl
index 136f6d4..4b676f4 100644
--- a/styles/templates/adm/CreatePagePlanet.tpl
+++ b/styles/templates/adm/CreatePagePlanet.tpl
@@ -1,4 +1,4 @@
-{include file="adm/overall_header.tpl"}
+{include file="overall_header.tpl"}
@@ -10,9 +10,9 @@
{$new_creator_coor}
-
:
- :
-
+
:
+ :
+
{$po_name_planet}
@@ -27,4 +27,4 @@
-{include file="adm/overall_footer.tpl"}
\ No newline at end of file
+{include file="overall_footer.tpl"}
\ No newline at end of file
diff --git a/styles/templates/adm/CreatePageUser.tpl b/styles/templates/adm/CreatePageUser.tpl
index 1d03fc6..f6ded41 100644
--- a/styles/templates/adm/CreatePageUser.tpl
+++ b/styles/templates/adm/CreatePageUser.tpl
@@ -1,4 +1,4 @@
-{include file="adm/overall_header.tpl"}
+{include file="overall_header.tpl"}
-{include file="adm/overall_footer.tpl"}
\ No newline at end of file
+{include file="overall_footer.tpl"}
\ No newline at end of file
diff --git a/styles/templates/adm/CronjobDetail.tpl b/styles/templates/adm/CronjobDetail.tpl
new file mode 100644
index 0000000..0bec5f4
--- /dev/null
+++ b/styles/templates/adm/CronjobDetail.tpl
@@ -0,0 +1,57 @@
+{include file="overall_header.tpl"}
+