Beispiel #1
0
 /**
  * Set nickname.
  *
  * @access public
  * @param string $nickname
  * @throws Exception
  * @return void
  */
 public function setNickname($nickname)
 {
     if (!Sjcl::isValid($nickname)) {
         throw new Exception('Invalid data.', 66);
     }
     $this->_data->meta->nickname = $nickname;
     // If a nickname is provided, we generate an icon based on a SHA512 HMAC
     // of the users IP. (We assume that if the user did not enter a nickname,
     // the user wants to be anonymous and we will not generate an icon.)
     $icon = $this->_conf->getKey('icon');
     if ($icon != 'none') {
         $pngdata = '';
         $hmac = TrafficLimiter::getHash();
         if ($icon == 'identicon') {
             $identicon = new Identicon();
             $pngdata = $identicon->getImageDataUri($hmac, 16);
         } elseif ($icon == 'vizhash') {
             $vh = new Vizhash16x16();
             $pngdata = 'data:image/png;base64,' . base64_encode($vh->generate($hmac));
         }
         if ($pngdata != '') {
             $this->_data->meta->vizhash = $pngdata;
         }
     }
     // Once the icon is generated, we do not keep the IP address hash.
 }
 /**
  * Set data and recalculate ID.
  *
  * @access public
  * @param string $data
  * @throws Exception
  * @return void
  */
 public function setData($data)
 {
     if (!Sjcl::isValid($data)) {
         throw new Exception('Invalid data.', 61);
     }
     $this->_data->data = $data;
     // We just want a small hash to avoid collisions:
     // Half-MD5 (64 bits) will do the trick
     $this->setId(substr(hash('md5', $data), 0, 16));
 }
Beispiel #3
0
 /**
  * Set paste's attachment name.
  *
  * @access public
  * @param string $attachmentname
  * @throws Exception
  * @return void
  */
 public function setAttachmentName($attachmentname)
 {
     if (!$this->_conf->getKey('fileupload') || !Sjcl::isValid($attachmentname)) {
         throw new Exception('Invalid attachment.', 72);
     }
     $this->_data->meta->attachmentname = $attachmentname;
 }