예제 #1
0
	/**
	 * Connect to the set hostname using the appropriate credentials.
	 *
	 * @throws \Exception
	 */
	public function connect(){
		if($this->connected){
			// Already connected, YAY!
			return;
		}

		if(!$this->host){
			throw new \Exception('Please set the host before connecting to an FTP server.');
		}

		if(!$this->root){
			throw new \Exception('Please set the root path before connecting to an FTP server.');
		}

		$this->conn = ftp_connect($this->host);
		if(!$this->conn){
			throw new \Exception('Unable to connect to the FTP server at ' . $this->host);
		}

		if($this->username){
			if(!ftp_login($this->conn, $this->username, $this->password)){
				throw new \Exception('Bad FTP username or password for ' . $this->host);
			}

			// Now that it's connected, hide the password.
			$this->password = '******';
		}
		else{
			if(!ftp_login($this->conn, 'anonymous', '')){
				throw new \Exception('Anonymous logins are disabled for ' . $this->host);
			}
		}

		ftp_set_option($this->conn, FTP_TIMEOUT_SEC, 600);

		$this->reset();

		if($this->host == '127.0.0.1'){
			$this->isLocal = true;
		}

		$this->connected = true;
		$this->lastSave = DateTime::NowGMT();

		self::$_OpenConnections[] = $this;
		if(sizeof(self::$_OpenConnections) == 1){
			// First open connection, register the shutdown hook!
			\HookHandler::AttachToHook('/core/shutdown', '\\Core\\Filestore\\FTP\\FTPConnection::ShutdownHook');
		}
	}
예제 #2
0
	public function loadFiles() {

		// First of all, this cannot be called on disabled or uninstalled components.
		if(!$this->isInstalled()) return false;
		if(!$this->isEnabled()) return false;
		if($this->_filesloaded) return true;

		Core\Utilities\Logger\write_debug('Loading files for component [' . $this->getName() . ']');

		$dir = $this->getBaseDir();

		// Include any includes requested.
		// This adds support for namespaced functions.
		// <includes>
		//     <include filename="core/functions/Core.functions.php"/>
		// </includes>
		foreach ($this->_xmlloader->getElements('/includes/include') as $f) {
			require_once($dir . $f->getAttribute('filename'));
		}


		// Register any hooks that may be present.
		foreach ($this->_xmlloader->getElementsByTagName('hookregister') as $h) {
			$hook              = new Hook($h->getAttribute('name'));
			$hook->description = $h->getAttribute('description');
			if($h->getAttribute('return')){
				$hook->returnType = $h->getAttribute('return');
			}
		}

		// Register any events that may be present.
		foreach ($this->_xmlloader->getElementsByTagName('hook') as $h) {
			$event = $h->getAttribute('name');
			$call  = $h->getAttribute('call');
			$type  = @$h->getAttribute('type');
			HookHandler::AttachToHook($event, $call, $type);
		}


		// This component may have special form elements registered.  Check!
		foreach ($this->_xmlloader->getElements('/forms/formelement') as $node) {
			Form::$Mappings[$node->getAttribute('name')] = $node->getAttribute('class');
		}

		if(DEVELOPMENT_MODE && defined('AUTO_INSTALL_ASSETS') && AUTO_INSTALL_ASSETS && EXEC_MODE == 'WEB' && CDN_TYPE == 'local'){
			Core\Utilities\Logger\write_debug('Auto-installing assets for component [' . $this->getName() . ']');
			$this->_parseAssets();
		}

		$this->_filesloaded = true;

		return true;
	}