<commit_before><?php 
/***********************************************
* This file is part of PeoplePods
* (c) xoxco, inc  
* http://peoplepods.net http://xoxco.com
*
* lib/Core.php
* This file defines the core PeoplePod object!
*
* Documentation for this object can be found here:
* http://peoplepods.net/readme/peoplepods-object
/**********************************************/

// where is this library file?  we need it to include subordinate libraries
$libPath = dirname(__FILE__);

// require child libraries
require_once($libPath ."/Comment.php");
require_once($libPath ."/Tag.php");
require_once($libPath ."/Content.php");
require_once($libPath ."/Users.php");
require_once($libPath ."/Groups.php");

require_once($libPath ."/Msg.php");		
require_once($libPath ."/Messages.php");		
require_once($libPath ."/Activity.php");		
require_once($libPath ."/Alerts.php");		

require_once($libPath ."/Files.php");		
require_once($libPath ."/Stack.php");		
	
	
class PeoplePod {

	public $VERSION = 0.9;
	public $DATABASE;

	protected $error_code;
	protected $error;
	protected $success = true;
	protected $USE_CACHE = true;
	protected $USE_SESSIONS = true;
	protected $CACHE_STACKS = false;

	public $PODS; // contains info about installable pods
	
	protected $CSS_FILES = array();
	protected $JS_FILES =  array();
	protected $MESSAGES =  array();

	static protected $CURRENT_USER;
	static protected $IS_AUTHENTICATED = false;

	static private $LIBOPTIONS = array(); // 
	static private $DEBUG = null;  // 1 = debug messages 2 = sql commands
	static private $CACHE = array();

	static private $EXTRA_METHODS = array();
	
	function PeoplePod($PARAMETERS = null) {

		$this->useCache(false);
		
		if ($PARAMETERS == null) {
			$PARAMETERS = array();
		}

		if (isset($PARAMETERS['debug']) && $PARAMETERS['debug'] != "0") {
			$this->debug($PARAMETERS['debug']);
		}			

		if (!isset($PARAMETERS['authSecret']) && isset($_COOKIE['pp_auth'])) {
			$PARAMETERS['authSecret'] = $_COOKIE['pp_auth'];
		}


		$this->tolog("CREATING NEW PEOPLEPOD");

		if ($this->USE_SESSIONS) { 
			// turn on PHP session handling
			if (!session_id() && !session_start()) { 
				$this->USE_SESSIONS = false;
				$this->tolog("Tried to use PHP sessions but failed. Reverting to temporary mem cache");
			} else {
				session_cache_expire(10);
			}
		}		

		// where is this library file?  we need it to include subordinate libraries
		$libPath = dirname(__FILE__);
		
		if (!file_exists("$libPath/etc/options.php") || !include("$libPath/etc/options.php")) { 
			$this->throwError("Install Dir not set!");
			$this->error_code = 100;

			$this->success= false;
			return false;	
		}				
		
			
		if ($this->libOptions('installDir')) { 

			if (!$this->libOptions('default_document_path')) {
				$this->setLibOptions('default_document_path','show');
			}
			if (!$this->libOptions('default_document_editpath')) {
				$this->setLibOptions('default_document_editpath','edit');
			}

			# set up some default options if they haven't already been overridden by plugin pods.
			if (!$this->libOptions('profilePath')) {
				$this->setLibOptions('profilePath','/people');
			}
			if (!$this->libOptions('groupPath')) {
				$this->setLibOptions('groupPath','groups');
			}

			if (!$this->libOptions('imgPath')) {
				$this->setLibOptions('imgPath',$this->libOptions("siteRoot") . $this->libOptions('podRoot') ."/files/images");
			}
			if (!$this->libOptions('docPath')) {
				$this->setLibOptions('docPath',$this->libOptions("siteRoot") . $this->libOptions('podRoot') ."/files/docs");
			}

			if (!$this->libOptions('imgDir')) {
				$this->setLibOptions('imgDir',$this->libOptions("installDir") ."/files/images");
			}
			if (!$this->libOptions('docDir')) {
				$this->setLibOptions('docDir',$this->libOptions("installDir") ."/files/docs");
			}

			if (!$this->libOptions('cacheDir')) {
				$this->setLibOptions('cacheDir',$this->libOptions("installDir") ."/files/cache");
			}
			
			if (!$this->libOptions('currentTheme')) { 
				$this->setLibOptions('currentTheme','default');
			}
			
			$this->setLibOptions('templateDir',$this->libOptions("installDir") ."/themes/" . $this->libOptions('currentTheme'));
	
		} else {
			$this->throwError("Install Dir not set!");
			$this->error_code = 100;

			$this->success= false;
			return false;	
		}

		if ($this->libOptions('mysql_server') && $this->libOptions('mysql_user')) { 
			// connect to the database
			$this->DATABASE = $this->connectToDatabase($this->libOptions('mysql_server'),$this->libOptions('mysql_user'),$this->libOptions('mysql_pass'),$this->libOptions('mysql_db'));
		}
		
		if (!$this->DATABASE) { 
			$this->throwError("Unable to connect to the database " . $this->libOptions('mysql_server') . ' with user ' . $this->libOptions('mysql_user'));
			$this->success= false;
			$this->error_code = 101;
			return false;
		}
		
		if (!isset($PARAMETERS['cache']) || !in_array($PARAMETERS['cache'],array('false',false))) {		
			// now that we're sure everything is configured correctly, we can start using the cache
			$this->useCache(true);
		}
		
		
		// validate user and set auth status
		if (isset($PARAMETERS['authSecret'])) {
			self::$CURRENT_USER = $this->getPerson(array('authSecret'=>$PARAMETERS['authSecret']));
			if (self::$CURRENT_USER->success()) {
					self::$IS_AUTHENTICATED = true;
					$this->tolog("POD Authenticated!");
			} else {
				$this->tolog("POD NOT AUTHENTICATED");
				self::$IS_AUTHENTICATED = false;
				self::$CURRENT_USER = null;
			}
		} else {
			self::$IS_AUTHENTICATED = false;
			self::$CURRENT_USER = null;
		}

		$this->processIncludes();
		

		if (isset($PARAMETERS['lockdown']) && $PARAMETERS['lockdown'] == "login" && !self::$IS_AUTHENTICATED) {
			$this->tolog('POD LOGIN REQUIRED!');
			header("Location: " . $this->libOptions('siteRoot') . "/join?error=access+denied");	
			exit;

			$this->success = false;
		}

		if (isset($PARAMETERS['lockdown']) && $PARAMETERS['lockdown'] == "adminUser" && (!self::$IS_AUTHENTICATED || (self::$IS_AUTHENTICATED && $this->currentUser()->get('adminUser') == ''))) {
			$this->tolog('POD ADMINUSER REQUIRED!');
			header("Location: " . $this->libOptions('siteRoot') . "/login");	
			exit;
			$this->success = false;
		}

		if (isset($PARAMETERS['lockdown']) && $PARAMETERS['lockdown'] == "verified" && (!self::$IS_AUTHENTICATED || (self::$IS_AUTHENTICATED && $this->currentUser()->get('verificationKey') != ''))) {<commit_msg>The PeoplePod class now loads all the plugin methods before authenticating the user.<commit_after><?php 
/***********************************************
* This file is part of PeoplePods
* (c) xoxco, inc  
* http://peoplepods.net http://xoxco.com
*
* lib/Core.php
* This file defines the core PeoplePod object!
*
* Documentation for this object can be found here:
* http://peoplepods.net/readme/peoplepods-object
/**********************************************/

// where is this library file?  we need it to include subordinate libraries
$libPath = dirname(__FILE__);

// require child libraries
require_once($libPath ."/Comment.php");
require_once($libPath ."/Tag.php");
require_once($libPath ."/Content.php");
require_once($libPath ."/Users.php");
require_once($libPath ."/Groups.php");

require_once($libPath ."/Msg.php");		
require_once($libPath ."/Messages.php");		
require_once($libPath ."/Activity.php");		
require_once($libPath ."/Alerts.php");		

require_once($libPath ."/Files.php");		
require_once($libPath ."/Stack.php");		
	
	
class PeoplePod {

	public $VERSION = 0.9;
	public $DATABASE;

	protected $error_code;
	protected $error;
	protected $success = true;
	protected $USE_CACHE = true;
	protected $USE_SESSIONS = true;
	protected $CACHE_STACKS = false;

	public $PODS; // contains info about installable pods
	
	protected $CSS_FILES = array();
	protected $JS_FILES =  array();
	protected $MESSAGES =  array();

	static protected $CURRENT_USER;
	static protected $IS_AUTHENTICATED = false;

	static private $LIBOPTIONS = array(); // 
	static private $DEBUG = null;  // 1 = debug messages 2 = sql commands
	static private $CACHE = array();

	static private $EXTRA_METHODS = array();
	
	function PeoplePod($PARAMETERS = null) {

		$this->useCache(false);
		
		if ($PARAMETERS == null) {
			$PARAMETERS = array();
		}

		if (isset($PARAMETERS['debug']) && $PARAMETERS['debug'] != "0") {
			$this->debug($PARAMETERS['debug']);
		}			

		if (!isset($PARAMETERS['authSecret']) && isset($_COOKIE['pp_auth'])) {
			$PARAMETERS['authSecret'] = $_COOKIE['pp_auth'];
		}


		$this->tolog("CREATING NEW PEOPLEPOD");

		if ($this->USE_SESSIONS) { 
			// turn on PHP session handling
			if (!session_id() && !session_start()) { 
				$this->USE_SESSIONS = false;
				$this->tolog("Tried to use PHP sessions but failed. Reverting to temporary mem cache");
			} else {
				session_cache_expire(10);
			}
		}		

		// where is this library file?  we need it to include subordinate libraries
		$libPath = dirname(__FILE__);
		
		if (!file_exists("$libPath/etc/options.php") || !include("$libPath/etc/options.php")) { 
			$this->throwError("Install Dir not set!");
			$this->error_code = 100;

			$this->success= false;
			return false;	
		}				
		
			
		if ($this->libOptions('installDir')) { 

			if (!$this->libOptions('default_document_path')) {
				$this->setLibOptions('default_document_path','show');
			}
			if (!$this->libOptions('default_document_editpath')) {
				$this->setLibOptions('default_document_editpath','edit');
			}

			# set up some default options if they haven't already been overridden by plugin pods.
			if (!$this->libOptions('profilePath')) {
				$this->setLibOptions('profilePath','/people');
			}
			if (!$this->libOptions('groupPath')) {
				$this->setLibOptions('groupPath','groups');
			}

			if (!$this->libOptions('imgPath')) {
				$this->setLibOptions('imgPath',$this->libOptions("siteRoot") . $this->libOptions('podRoot') ."/files/images");
			}
			if (!$this->libOptions('docPath')) {
				$this->setLibOptions('docPath',$this->libOptions("siteRoot") . $this->libOptions('podRoot') ."/files/docs");
			}

			if (!$this->libOptions('imgDir')) {
				$this->setLibOptions('imgDir',$this->libOptions("installDir") ."/files/images");
			}
			if (!$this->libOptions('docDir')) {
				$this->setLibOptions('docDir',$this->libOptions("installDir") ."/files/docs");
			}

			if (!$this->libOptions('cacheDir')) {
				$this->setLibOptions('cacheDir',$this->libOptions("installDir") ."/files/cache");
			}
			
			if (!$this->libOptions('currentTheme')) { 
				$this->setLibOptions('currentTheme','default');
			}
			
			$this->setLibOptions('templateDir',$this->libOptions("installDir") ."/themes/" . $this->libOptions('currentTheme'));
	
		} else {
			$this->throwError("Install Dir not set!");
			$this->error_code = 100;

			$this->success= false;
			return false;	
		}

		if ($this->libOptions('mysql_server') && $this->libOptions('mysql_user')) { 
			// connect to the database
			$this->DATABASE = $this->connectToDatabase($this->libOptions('mysql_server'),$this->libOptions('mysql_user'),$this->libOptions('mysql_pass'),$this->libOptions('mysql_db'));
		}
		
		if (!$this->DATABASE) { 
			$this->throwError("Unable to connect to the database " . $this->libOptions('mysql_server') . ' with user ' . $this->libOptions('mysql_user'));
			$this->success= false;
			$this->error_code = 101;
			return false;
		}
		
		if (!isset($PARAMETERS['cache']) || !in_array($PARAMETERS['cache'],array('false',false))) {		
			// now that we're sure everything is configured correctly, we can start using the cache
			$this->useCache(true);
		}
		
		$this->processIncludes();
		
		// validate user and set auth status
		if (isset($PARAMETERS['authSecret'])) {
			self::$CURRENT_USER = $this->getPerson(array('authSecret'=>$PARAMETERS['authSecret']));
			if (self::$CURRENT_USER->success()) {
					self::$IS_AUTHENTICATED = true;
					$this->tolog("POD Authenticated!");
			} else {
				$this->tolog("POD NOT AUTHENTICATED");
				self::$IS_AUTHENTICATED = false;
				self::$CURRENT_USER = null;
			}
		} else {
			self::$IS_AUTHENTICATED = false;
			self::$CURRENT_USER = null;
		}

		if (isset($PARAMETERS['lockdown']) && $PARAMETERS['lockdown'] == "login" && !self::$IS_AUTHENTICATED) {
			$this->tolog('POD LOGIN REQUIRED!');
			header("Location: " . $this->libOptions('siteRoot') . "/join?error=access+denied");	
			exit;

			$this->success = false;
		}

		if (isset($PARAMETERS['lockdown']) && $PARAMETERS['lockdown'] == "adminUser" && (!self::$IS_AUTHENTICATED || (self::$IS_AUTHENTICATED && $this->currentUser()->get('adminUser') == ''))) {
			$this->tolog('POD ADMINUSER REQUIRED!');
			header("Location: " . $this->libOptions('siteRoot') . "/login");	
			exit;
			$this->success = false;
		}

		if (isset($PARAMETERS['lockdown']) && $PARAMETERS['lockdown'] == "verified" && (!self::$IS_AUTHENTICATED || (self::$IS_AUTHENTICATED && $this->currentUser()->get('verificationKey') != ''))) {
{'fraction_non_alphanumeric': 0.2025951957982544, 'fraction_numerical': 0.002471615045956592, 'mean_word_length': 4.458684654300169, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 151, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5139479', 'n_tokens_mistral': 4755, 'n_tokens_neox': 4220, 'n_words': 792}