Beispiel #1
0
 /**
  * Internal encoding function that does the actual job
  *
  * @return bencoded string
  */
 private function _benc()
 {
     if (!is_array($this->Data)) {
         if (Int64::is_int($this->Data)) {
             // Integer
             return 'i' . Int64::get($this->Data) . 'e';
         }
         if ($this->Data === true) {
             // Empty dictionary
             return 'de';
         }
         return strlen($this->Data) . ':' . $this->Data;
         // String
     }
     if (empty($this->Data) || Int64::is_int(key($this->Data))) {
         $IsDict = false;
     } else {
         $IsDict = true;
         ksort($this->Data);
         // Dictionaries must be sorted
     }
     $Ret = $IsDict ? 'd' : 'l';
     foreach ($this->Data as $Key => $Value) {
         if ($IsDict) {
             $Ret .= strlen($Key) . ':' . $Key;
         }
         $this->Data = $Value;
         $Ret .= $this->_benc();
     }
     return $Ret . 'e';
 }
 /**
  * Add the "private" flag to the torrent
  *
  * @return true if a change was required
  */
 public function make_private()
 {
     if (empty($this->Dec)) {
         return false;
     }
     if ($this->is_private()) {
         return false;
     }
     $this->Dec['info']['private'] = Int64::make(1);
     ksort($this->Dec['info']);
     return true;
 }
Beispiel #3
0
 /**
  * Convert everything to the correct data types and optionally escape strings
  *
  * @param bool $Escape whether to escape the textual data
  * @param mixed $Data decoded data or false to use the $Dec property
  * @return decoded data with more useful data types
  */
 public function dump($Escape = true, $Data = false)
 {
     if ($Data === false) {
         $Data = $this->Dec;
     }
     if (Int64::is_int($Data)) {
         return Int64::get($Data);
     }
     if (is_bool($Data)) {
         return array();
     }
     if (is_array($Data)) {
         $Output = array();
         foreach ($Data as $Key => $Val) {
             $Output[$Key] = $this->dump($Escape, $Val);
         }
         return $Output;
     }
     return $Escape ? htmlentities($Data) : $Data;
 }