$password = '';
}
if (!isset($image) || !pcpin_ctype_digit($image)) {
    $image = 0;
}
if (!empty($current_user->id) && $current_user->is_admin === 'y' && $session->_s_user_id == $current_user->id) {
    $errortext = array();
    $name = trim($name);
    $description = trim($description);
    if (empty($category_id) || !$category->_db_getList('id', 'id = ' . $category_id, 1)) {
        $errortext[] = $l->g('select_category');
    } elseif ($name == '') {
        $errortext[] = $l->g('room_name_empty');
    } elseif ($room->_db_getList('category_id = ' . $category_id, 'name LIKE ' . $name, 1)) {
        $errortext[] = str_replace('[NAME]', $name, $l->g('room_already_exists_in_category'));
    } elseif (!empty($password_protect) && !empty($change_password) && _pcpin_strlen($password) < 3) {
        $errortext[] = $l->g('password_too_short');
    }
    if (!empty($errortext)) {
        $xmlwriter->setHeaderStatus(1);
        $xmlwriter->setHeaderMessage(implode("\n", $errortext));
    } else {
        // Check image
        if (!empty($image) && $tmpdata->_db_getList('binaryfile_id', 'user_id = ' . $session->_s_user_id, 'type = 1', 1)) {
            $binaryfile_id = $tmpdata->_db_list[0]['binaryfile_id'];
            $tmpdata->_db_freeList();
        } else {
            $binaryfile_id = 0;
        }
        $tmpdata->deleteUserRecords($session->_s_user_id, 1, 0, true);
        if (!empty($password_protect)) {
}
if (!empty($profile_user_id) && !empty($nickname_id)) {
    $new_nickname = trim($new_nickname);
    if (!empty($nickname_id) && $new_nickname != '') {
        $new_nickname = $nickname->optimizeColored('^' . $session->_conf_all['default_nickname_color'] . $new_nickname);
        $new_nickname_plain = $nickname->coloredToPlain($new_nickname, false);
        // Check nickname
        if ($new_nickname_plain == '') {
            // Nickname is empty
            $xmlwriter->setHeaderStatus(1);
            $xmlwriter->setHeaderMessage($l->g('nickname_empty_error'));
        } elseif (_pcpin_strlen($new_nickname_plain) < $session->_conf_all['nickname_length_min']) {
            // Nickname is too short
            $xmlwriter->setHeaderStatus(1);
            $xmlwriter->setHeaderMessage(str_replace('[LENGTH]', $session->_conf_all['nickname_length_min'], $l->g('nickname_too_short_error')));
        } elseif (_pcpin_strlen($new_nickname_plain) > $session->_conf_all['nickname_length_max']) {
            // Nickname is too long
            $xmlwriter->setHeaderStatus(1);
            $xmlwriter->setHeaderMessage(str_replace('[LENGTH]', $session->_conf_all['nickname_length_max'], $l->g('nickname_too_long')));
        } elseif ($nickname->_db_getList('id', 'id != ' . $nickname_id, 'nickname_plain LIKE ' . $new_nickname_plain, 1)) {
            // Nickname already exists
            $xmlwriter->setHeaderStatus(1);
            $xmlwriter->setHeaderMessage(str_replace('[NICKNAME]', $new_nickname_plain, $l->g('nickname_not_available')));
            $nickname->_db_freeList();
        } elseif (false === $badword->checkString($new_nickname_plain) || false === $disallowed_name->checkString($new_nickname_plain) && $current_user->is_admin !== 'y') {
            // Nickname is not allowed
            $xmlwriter->setHeaderStatus(1);
            $xmlwriter->setHeaderMessage(str_replace('[NICKNAME]', $new_nickname_plain, $l->g('nickname_not_available')));
        } else {
            // Nickname is free
            if ($nickname->updateNickname($profile_user_id, $nickname_id, $new_nickname)) {
 /**
  * Generate random string from pattern
  * @param   int       $length     Desired string length
  * @param   string    $pattern    Pattern to use
  * @param   boolean   $binary     Optional. If TRUE, then the pattern is a binary string and will be handled byte-by-byte.
  * @return  string    Generated random string
  */
 function randomString($length = 0, $pattern = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', $binary = false)
 {
     $out = '';
     if ($length > 0 && $pattern != '') {
         if (!$binary) {
             // Pattern is a text string
             $pattern_length_minus_one = strlen($pattern) - 1;
             for ($i = 0; $i < $length; $i++) {
                 $out .= substr($pattern, mt_rand(0, $pattern_length_minus_one), 1);
             }
         } else {
             // Pattern is a binary string
             $pattern_length_minus_one = _pcpin_strlen($pattern) - 1;
             for ($i = 0; $i < $length; $i++) {
                 $out .= _pcpin_substr($pattern, mt_rand(0, $pattern_length_minus_one), 1);
             }
         }
     }
     return $out;
 }
     $xmlwriter->setHeaderStatus(1);
     $errortext[] = $l->g('user_room_create_category_error');
 } else {
     $name = trim($name);
     $description = trim($description);
     if ($name == '') {
         $xmlwriter->setHeaderStatus(1);
         $errortext[] = $l->g('room_name_empty');
     } elseif ($room->_db_getList('id', 'category_id = ' . $category_id, 'name = ' . $name)) {
         // Duplicate room name
         $xmlwriter->setHeaderStatus(1);
         $errortext[] = str_replace('[NAME]', $name, $l->g('room_already_exists_in_category'));
     }
     if (!empty($password_protect)) {
         $password = base64_decode($password);
         if (_pcpin_strlen($password) < 3) {
             $xmlwriter->setHeaderStatus(1);
             $errortext[] = $l->g('password_too_short');
         }
     }
 }
 if (empty($errortext)) {
     // Check image
     $background_image = 0;
     if (!empty($image) && $tmpdata->_db_getList('id, binaryfile_id', 'user_id = ' . $current_user->id, 'type = 1', 1)) {
         // There is an image
         $background_image = $tmpdata->_db_list[0]['binaryfile_id'];
         // Delete temporary data
         $tmpdata->_db_freeList();
         $tmpdata->deleteUserRecords($session->_s_user_id, 1, 0, true);
     }
Exemplo n.º 5
0
 function coloredToPlain($nickname = '', $escape_html_chars = true)
 {
     $plain = '';
     if ($nickname != '') {
         $parts = explode('^', $nickname);
         if (!isset($parts[1])) {
             $plain = $parts[0];
         } else {
             foreach ($parts as $part) {
                 if (_pcpin_strlen($part) > 6) {
                     $plain .= substr($part, 6);
                 } elseif (_pcpin_strlen($part) < 6) {
                     $plain .= $part;
                 }
             }
         }
     }
     if ($escape_html_chars) {
         $plain = htmlspecialchars($plain);
     }
     return $plain;
 }
 /**
  * Import language from string. String format: see $this->() documentation.
  * On success, ID of created language will be returned.
  * Error codes:
  *          10:  Invalid / damaged file
  *          100: Language already exists
  * @param   string    $raw            Raw data
  * @param   int       $language_id    Language ID will be stored here
  * @return  int   0 (zero) on success or error number on error
  */
 function importLanguage($raw, &$language_id)
 {
     $status = 10;
     $language_id = 0;
     if ($raw != '') {
         $hash = substr($raw, 0, 32);
         $raw = substr($raw, 32);
         if (strlen($hash) == 32 && $raw != '' && strtoupper(md5($raw)) === $hash) {
             // Hash OK
             if ($raw = @base64_decode($raw)) {
                 if ($lng = @unserialize($raw)) {
                     unset($raw);
                     if (is_array($lng) && isset($lng['data_type']) && $lng['data_type'] == 'language' && isset($lng['pcpin_version']) && 0 === strpos($lng['pcpin_version'], 'pcpin_chat_') && floor(PCPIN_VERSION * 10) === floor(substr($lng['pcpin_version'], 11) * 10) && !empty($lng['data']) && is_array($lng['data'])) {
                         $lng = $lng['data'];
                         // Check ISO name
                         if (!empty($lng['iso_name'])) {
                             $this->iso_name = PCPIN_Common::hexToString($lng['iso_name']);
                             if (_pcpin_strlen($this->iso_name) == 2 && defined('PCPIN_ISO_LNG_' . strtoupper($this->iso_name))) {
                                 if ($this->_db_getList('id', 'iso_name = ' . $this->iso_name, 1)) {
                                     // Language already exists
                                     $status = 100;
                                     $language_id = $this->_db_list[0]['id'];
                                     $this->_db_freeList();
                                 } else {
                                     // Name
                                     $this->name = substr(constant('PCPIN_ISO_LNG_' . strtoupper($this->iso_name)), 3);
                                     // Get local name
                                     if (isset($lng['local_name'])) {
                                         $this->local_name = PCPIN_Common::hexToString($lng['local_name']);
                                         if ($this->local_name == '') {
                                             $this->local_name = $this->name;
                                         }
                                         // Get expressions
                                         if (!empty($lng['expressions']) && is_array($lng['expressions'])) {
                                             $lng = $lng['expressions'];
                                             // Insert new object
                                             $this->id = 0;
                                             $this->active = 'n';
                                             if ($this->_db_insertObj()) {
                                                 $language_id = $this->_db_lastInsertID();
                                                 $this->id = $language_id;
                                                 // Insert language expressions
                                                 _pcpin_loadClass('language_expression');
                                                 foreach ($lng as $expr) {
                                                     $language_expression = new PCPIN_Language_Expression($this);
                                                     $language_expression->language_id = $language_id;
                                                     $language_expression->code = PCPIN_Common::hexToString($expr['code']);
                                                     $language_expression->value = PCPIN_Common::hexToString($expr['value']);
                                                     $language_expression->multi_row = PCPIN_Common::hexToString($expr['multi_row']);
                                                     if ($language_expression->code != '' && is_scalar($language_expression->value)) {
                                                         $language_expression->_db_insertObj();
                                                     }
                                                 }
                                                 unset($lng);
                                                 $status = 0;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $status;
 }
 /**
  * Convert string with color codes into HTML colored string
  * @param   string    colored     String with color codes
  * @param   string    tag         HTML tag to use (default: SPAN)
  * @return  string
  */
 function coloredToHTML($colored = '', $tag = 'span')
 {
     $html = '';
     $parts = explode('^', $colored);
     if (count($parts) == 1) {
         $html = str_replace(' ', '&nbsp;', htmlspecialchars($parts[0]));
     } else {
         foreach ($parts as $part) {
             if (_pcpin_strlen($part) > 6) {
                 $html .= '<' . $tag . ' style="color:#' . substr($part, 0, 6) . '">' . str_replace(' ', '&nbsp;', htmlspecialchars(substr($part, 6))) . '</' . $tag . '>';
             }
         }
     }
     return $html;
 }