/**
  * Reload Bot configuration
  *
  */
 public function reloadConfiguration()
 {
     $this->config->reset();
     $this->lists = array();
     // Set base directory for lists relative to that of the config file's
     $base = dirname($this->config->getFilename()) . DIRECTORY_SEPARATOR;
     // Read word/message lists
     foreach ($this->config->readSection('lists') as $identifier => $file) {
         $this->lists[$identifier] = array();
         $f = new File($base . $file);
         try {
             if ($f->open(FILE_MODE_READ)) {
                 while (($line = $f->readLine()) && !$f->eof()) {
                     $this->lists[$identifier][] = $line;
                 }
             }
             $f->close();
         } catch (IOException $e) {
             $e->printStackTrace();
             return FALSE;
         }
     }
     // Read karma recognition phrases
     $f = new File($base . $this->config->readString('karma', 'recognition'));
     try {
         if ($f->open(FILE_MODE_READ)) {
             while (!$f->eof()) {
                 $line = $f->readLine();
                 if (empty($line) || strspn($line, ';#')) {
                     continue;
                 }
                 list($pattern, $channel, $direct) = explode(':', $line);
                 $this->recognition[$pattern] = array((int) $channel, (int) $direct);
             }
         }
         $f->close();
     } catch (IOException $e) {
         $e->printStackTrace();
         return FALSE;
     }
     // If no karma is set and the karma storage exists, load it
     if (0 == sizeof($this->karma)) {
         try {
             $f = new File($base . 'karma.list');
             if ($f->exists()) {
                 $karma = unserialize(FileUtil::getContents($f));
                 if ($karma) {
                     $this->karma = $karma;
                 }
             }
         } catch (IOException $e) {
             // Karma loading failed - log, but ignore...
             $this->cat && $this->cat->error($e);
         }
     }
 }
Example #2
0
 /**
  * @covers mychaelstyle\storage\File::eof
  */
 public function testEof()
 {
     // opened and final line
     $this->object->open('r');
     while (!$this->object->eof()) {
         $result = $this->object->gets();
     }
     $result = $this->object->eof();
     $this->assertEquals(true, $result);
     $this->object->close();
 }
Example #3
0
	/**
	 * Faz a comparação com o arquivo
	 * @param integer $byteNumber Número do byte que deverá ser iniciada a verificação
	 * @param string $dataContents Conteúdo que deverá ser comparado
	 * @return boolean
	 */
	private function compare( $byteNumber , $dataContents ) {
		$ret = false;

		$this->file->seek( $byteNumber );

		if (  !$this->file->eof() ) {
			$read = $this->file->read( strlen( $dataContents ) );

			return $read == $dataContents;
		}

		return $ret;
	}
	/**
	 * Verifica se o Iterator é válido
	 * @return boolean
	 * @see Iterator::valid()
	 */
	public function valid() {
		if ( $this->testFile() ) {
			return  !is_null( $this->current ) && ( $this->current !== false ) &&  !$this->file->eof();
		}
	}
Example #5
0
 /**
  * Downloads a package archive from an http URL.
  * 
  * @param	string		$httpUrl
  * @param	string		$prefix
  * @return	string		path to the dowloaded file
  */
 public static function downloadFileFromHttp($httpUrl, $prefix = 'package')
 {
     $extension = strrchr($httpUrl, '.');
     //$newFileName = self::getTemporaryFilename($prefix.'_', $extension);
     $newFileName = self::getTemporaryFilename($prefix . '_');
     $localFile = new File($newFileName);
     // the file to write.
     // get proxy
     $options = array();
     if (PROXY_SERVER_HTTP) {
         $options['http']['proxy'] = PROXY_SERVER_HTTP;
     }
     // first look if php's built-in fopen() is available, and if so, use it.
     if (function_exists('fopen') && ini_get('allow_url_fopen')) {
         $remoteFile = new File($httpUrl, 'rb', $options);
         // the file to read.
         // get the content of the remote file and write it to a local file.
         while (!$remoteFile->eof()) {
             $buffer = $remoteFile->gets(4096);
             $localFile->write($buffer);
         }
     } else {
         $port = 80;
         $parsedUrl = parse_url($httpUrl);
         $host = $parsedUrl['host'];
         $path = $parsedUrl['path'];
         require_once WCF_DIR . 'lib/system/io/RemoteFile.class.php';
         $remoteFile = new RemoteFile($host, $port, 30, $options);
         // the file to read.
         if (!isset($remoteFile)) {
             $localFile->close();
             unlink($newFileName);
             throw new SystemException("cannot connect to http host '" . $host . "'", 14000);
         }
         // build and send the http request.
         $request = "GET " . $path . (!empty($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '') . " HTTP/1.0\r\n";
         $request .= "User-Agent: HTTP.PHP (FileUtil.class.php; WoltLab Community Framework/" . WCF_VERSION . "; " . WCF::getLanguage()->getLanguageCode() . ")\r\n";
         $request .= "Accept: */*\r\n";
         $request .= "Accept-Language: " . WCF::getLanguage()->getLanguageCode() . "\r\n";
         $request .= "Host: " . $host . "\r\n";
         $request .= "Connection: Close\r\n\r\n";
         $remoteFile->puts($request);
         $waiting = true;
         $readResponse = array();
         // read http response.
         while (!$remoteFile->eof()) {
             $readResponse[] = $remoteFile->gets();
             // look if we are done with transferring the requested file.
             if ($waiting) {
                 if (rtrim($readResponse[count($readResponse) - 1]) == '') {
                     $waiting = false;
                 }
             } else {
                 // look if the webserver sent an error http statuscode
                 // This has still to be checked if really sufficient!
                 $arrayHeader = array('201', '301', '302', '303', '307', '404');
                 foreach ($arrayHeader as $code) {
                     $error = strpos($readResponse[0], $code);
                 }
                 if ($error !== false) {
                     $localFile->close();
                     unlink($newFileName);
                     throw new SystemException("file " . $path . " not found at host '" . $host . "'", 14001);
                 }
                 // write to the target system.
                 $localFile->write($readResponse[count($readResponse) - 1]);
             }
         }
     }
     $remoteFile->close();
     $localFile->close();
     return $newFileName;
 }