protected function _preSave() { $team = $this->_getTeamData(); if (!$team) { $this->error(new XenForo_Phrase('requested_team_not_found'), 'team_id'); } if ($team['user_id'] == $this->get('user_id')) { throw new Nobita_Teams_Exception_Abstract("You can't give banning to Owner of Team.", true); return false; } if ($this->isChanged('user_id')) { $userBan = $this->_getBanningModel()->getBanningByKeys($team['team_id'], $this->get('user_id')); if ($userBan) { $this->error(new XenForo_Phrase('this_user_is_already_banned'), 'user_id'); } else { $user = $this->getModelFromCache('XenForo_Model_User')->getUserById($this->get('user_id')); if (!$user || $user['is_moderator'] || $user['is_admin']) { $this->error(new XenForo_Phrase('this_user_is_an_admin_or_moderator_choose_another'), 'user_id'); } } } $reason = trim($this->get('user_reason')); if (!utf8_strlen($reason)) { $this->error(new XenForo_Phrase('Teams_please_enter_reason_for_ban_user'), 'user_reason'); } elseif (utf8_strlen($reason) > 255) { $this->error(new XenForo_Phrase('please_enter_message_with_no_more_than_x_characters', array('count' => 255)), 'user_reason'); } if (!$this->get('end_date')) { throw new Nobita_Teams_Exception_Abstract("Please provide the end date.", true); } }
/** * Replacement for str_pad. $padStr may contain multi-byte characters. * * @author Oliver Saunders <oliver (a) osinternetservices.com> * @param string $input * @param int $length * @param string $padStr * @param int $type ( same constants as str_pad ) * @return string * @see http://www.php.net/str_pad * @see utf8_substr * @package utf8 * @subpackage strings */ function utf8_str_pad($input, $length, $padStr = ' ', $type = STR_PAD_RIGHT) { $inputLen = utf8_strlen($input); if ($length <= $inputLen) { return $input; } $padStrLen = utf8_strlen($padStr); $padLen = $length - $inputLen; if ($type == STR_PAD_RIGHT) { $repeatTimes = ceil($padLen / $padStrLen); return utf8_substr($input . str_repeat($padStr, $repeatTimes), 0, $length); } if ($type == STR_PAD_LEFT) { $repeatTimes = ceil($padLen / $padStrLen); return utf8_substr(str_repeat($padStr, $repeatTimes), 0, floor($padLen)) . $input; } if ($type == STR_PAD_BOTH) { $padLen /= 2; $padAmountLeft = floor($padLen); $padAmountRight = ceil($padLen); $repeatTimesLeft = ceil($padAmountLeft / $padStrLen); $repeatTimesRight = ceil($padAmountRight / $padStrLen); $paddingLeft = utf8_substr(str_repeat($padStr, $repeatTimesLeft), 0, $padAmountLeft); $paddingRight = utf8_substr(str_repeat($padStr, $repeatTimesRight), 0, $padAmountLeft); return $paddingLeft . $input . $paddingRight; } trigger_error('utf8_str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR); }
/** * Builds the regex and censor cache value for a find/replace pair * * @param string $find * @param string $replace * * @return array|bool */ public static function buildCensorCacheValue($find, $replace) { $find = trim(strval($find)); if ($find === '') { return false; } $prefixWildCard = preg_match('#^\\*#', $find); $suffixWildCard = preg_match('#\\*$#', $find); $replace = is_int($replace) ? '' : trim(strval($replace)); if ($replace === '') { $replace = utf8_strlen($find); if ($prefixWildCard) { $replace--; } if ($suffixWildCard) { $replace--; } } $regexFind = $find; if ($prefixWildCard) { $regexFind = substr($regexFind, 1); } if ($suffixWildCard) { $regexFind = substr($regexFind, 0, -1); } if (!strlen($regexFind)) { return false; } $regex = '#' . ($prefixWildCard ? '' : '(?<=\\W|^)') . preg_quote($regexFind, '#') . ($suffixWildCard ? '' : '(?=\\W|$)') . '#iu'; return array('word' => $find, 'regex' => $regex, 'replace' => $replace); }
public function validate() { $this->language->load('module/pim_localfilesystem'); $error = array(); if (utf8_strlen($this->request->post['alias']) < 1 || utf8_strlen($this->request->post['alias']) > 64) { $error['error_localfilesystem_alias'] = $this->language->get('error_localfilesystem_alias'); } else { if (!isset($this->request->get['alias']) || isset($this->request->get['alias']) && $this->request->get['alias'] != $this->request->post['alias']) { // check if this volume alias already exist. $current_volumes = $this->config->get('pim_volumes'); if (!empty($current_volumes) && is_array($current_volumes)) { foreach ($current_volumes as $key => $volume) { if (is_array($volume)) { foreach ($volume as $vkey => $val) { if ($vkey == $this->request->post['alias']) { $error['error_alias_exist'] = $this->language->get('error_alias_exist'); } } } } } } } if (utf8_strlen($this->request->post['path']) < 1 || utf8_strlen($this->request->post['path']) > 600) { $error['error_localfilesystem_path'] = $this->language->get('error_localfilesystem_path'); } return $error; }
function utf8_strrpos($string, $needle, $offset = NULL) { if (is_null($offset)) { $data = explode($needle, $string); if (count($data) > 1) { array_pop($data); $string = join($needle, $data); return utf8_strlen($string); } return false; } else { if (!is_int($offset)) { trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_WARNING); return false; } $string = utf8_substr($string, $offset); if (false !== ($position = utf8_strrpos($string, $needle))) { return $position + $offset; } return false; } }
/** * Validate entered profile field data * * @param string $field_type Field type (string or text) * @param mixed $field_value Field value to validate * @param array $field_data Array with requirements of the field * @return mixed String with key of the error language string, false otherwise */ public function validate_string_profile_field($field_type, &$field_value, $field_data) { if (trim($field_value) === '' && !$field_data['field_required']) { return false; } else { if (trim($field_value) === '' && $field_data['field_required']) { return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name'])); } } if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) { return $this->user->lang('FIELD_TOO_SHORT', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name'])); } else { if ($field_data['field_maxlen'] && utf8_strlen(html_entity_decode($field_value)) > $field_data['field_maxlen']) { return $this->user->lang('FIELD_TOO_LONG', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name'])); } } if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*') { $field_validate = $field_type != 'text' ? $field_value : bbcode_nl2br($field_value); if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#iu', $field_validate)) { $validation = array_search($field_data['field_validation'], $this->validation_options); if ($validation) { return $this->user->lang('FIELD_INVALID_CHARS_' . $validation, $this->get_field_name($field_data['lang_name'])); } return $this->user->lang('FIELD_INVALID_CHARS_INVALID', $this->get_field_name($field_data['lang_name'])); } } return false; }
public function index($setting = false) { if (!$setting || !$this->config->get('tracking_input_status') || $setting['language_id'] != $this->config->get('config_language_id') || isset($this->session->data['tracking_input_show']) && !$this->session->data['tracking_input_show'] || $this->config->get('tracking_input_no_cookie_only') && (isset($this->request->request['tracking']) || isset($this->request->cookie['tracking'])) || $this->config->get('tracking_input_show') == 'once' && isset($this->request->cookie['__octfsh__']) && (!isset($this->session->data['tracking_input_show']) || !$this->session->data['tracking_input_show'])) { return ''; } $this->document->addScript('catalog/view/javascript/triyp.min.js'); //$this->document->addScript('catalog/view/javascript/triyp.js'); $this->session->data['tracking_input_show'] = true; if ($this->config->get('tracking_input_show') == 'once') { setcookie('__octfsh__', '1', time() + 2592000, '/'); } $data['show_close_button'] = $this->config->get('tracking_input_show_close_button'); $data['image_close'] = file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/image/close.png') ? 'catalog/view/theme/' . $this->config->get('config_template') . '/image/close.png' : 'catalog/view/theme/default/image/close.png'; $data['image_loading'] = file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/image/loading.gif') ? 'catalog/view/theme/' . $this->config->get('config_template') . '/image/loading.gif' : 'catalog/view/theme/default/image/loading.gif'; $data['send_link'] = html_entity_decode($this->url->link('module/tracking_input/send', '', isset($this->request->server['HTTPS']) && $this->request->server['HTTPS'] == 'on' ? 'SSL' : 'NONSSL'), ENT_QUOTES, 'UTF-8'); $data['close_link'] = html_entity_decode($this->url->link('module/tracking_input/close', '', isset($this->request->server['HTTPS']) && $this->request->server['HTTPS'] == 'on' ? 'SSL' : 'NONSSL'), ENT_QUOTES, 'UTF-8'); $data['text_thankyou'] = isset($setting['text_thankyou']) && utf8_strlen($setting['text_thankyou']) > 0 ? addcslashes(str_replace(array("\r\n", "\n", "\r"), array(' ', ' ', ' '), html_entity_decode($setting['text_thankyou'], ENT_QUOTES, 'UTF-8')), "'") : ''; $data['error_message'] = isset($setting['error_message']) && utf8_strlen($setting['error_message']) > 0 ? addcslashes(str_replace(array("\r\n", "\n", "\r"), array(' ', ' ', ' '), html_entity_decode($setting['error_message'], ENT_QUOTES, 'UTF-8')), "'") : ''; $data['json'] = array(); foreach (array('send_link', 'close_link', 'text_thankyou', 'error_message') as $_v) { $data['json'][$_v] = $data[$_v]; } $data['json'] = json_encode($data['json']); $data['text_message'] = html_entity_decode($setting['text'], ENT_QUOTES, 'UTF-8'); $data['text_heading'] = html_entity_decode($setting['text_heading'], ENT_QUOTES, 'UTF-8'); $data['send_button'] = $setting['button']; $this->language->load('affiliate/tracking_input'); $data['text_loading'] = $this->language->get('text_please_wait'); $_tpl = '/template/module/tracking_input_' . (isset($setting['template']) ? $setting['template'] : 'default_' . (substr($setting['position'], 0, 3) === 'col' ? 'column' : 'row')) . '.tpl'; $_tpl = (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . $_tpl) ? $this->config->get('config_template') : 'default') . $_tpl; return $this->load->view($_tpl, $data); }
protected function _preSave() { if ($this->isChanged('req_message')) { $reqMessage = $this->get('req_message'); $maxLength = 140; $reqMessage = preg_replace('/\\r?\\n/', ' ', $reqMessage); if (utf8_strlen($reqMessage) > $maxLength) { $this->error(new XenForo_Phrase('please_enter_message_with_no_more_than_x_characters', array('count' => $maxLength)), 'req_message'); } $this->set('req_message', $reqMessage); } $maxTeams = 999; // secure? if ($this->isInsert()) { if ($this->_getMemberModel()->countAllTeamsForUser($this->get('user_id')) >= $maxTeams) { $this->error(new XenForo_Phrase('Teams_you_only_join_x_teams', array('max' => $maxTeams))); } } if ($this->get('user_id')) { $user = $this->_getUserModel()->getUserById($this->get('user_id')); if ($user) { $this->set('username', $user['username']); } else { $this->set('user_id', 0); } } if ($this->get('action_user_id')) { $user = $this->_getUserModel()->getUserById($this->get('action_user_id')); if ($user) { if ($user['username'] != $this->get('action_username')) { $this->set('action_username', $user['username']); } } } }
function validate_password($password) { global $pwd_policy; if (isset($pwd_policy)) { // Set up regular expressions. Use p{Ll} instead of [a-z] etc. // to make sure accented characters are included $pattern = array('alpha' => '/\\p{L}/', 'lower' => '/\\p{Ll}/', 'upper' => '/\\p{Lu}/', 'numeric' => '/\\p{N}/', 'special' => '/[^\\p{L}|\\p{N}]/'); // Check for conformance to each rule foreach ($pwd_policy as $rule => $value) { switch ($rule) { case 'length': if (utf8_strlen($password) < $pwd_policy[$rule]) { return FALSE; } break; default: // turn on Unicode matching $pattern[$rule] .= 'u'; $n = preg_match_all($pattern[$rule], $password, $matches); if ($n === FALSE || $n < $pwd_policy[$rule]) { return FALSE; } break; } } } // Everything is OK return TRUE; }
public function validate() { if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*.[a-z]{2,15}$/i', $this->request->post['email'])) { $this->error['email'] = $this->language->get('error_email'); } return !$this->error; }
public static function explodeTags($tagsStr) { // sondh@2013-03-27 // process the string manually to make sure unicode character works $len = utf8_strlen($tagsStr); $tags = array(); $start = 0; $i = 0; while ($i <= $len) { if ($i < $len) { $char = utf8_substr($tagsStr, $i, 1); } else { $char = false; } if ($char === false or preg_match('/^' . Tinhte_XenTag_Constants::REGEX_SEPARATOR . '$/', $char)) { // this is a separator $tagLen = $i - $start; if ($tagLen > 0) { $tags[] = utf8_substr($tagsStr, $start, $tagLen); } // skip the separator for the next tag $start = $i + 1; } else { // this is some other character } $i++; } return $tags; }
public static function update($targetClass, $targetPath, $sourceClass, $sourcesContents) { $targetContents = str_replace($sourceClass, $targetClass, $sourcesContents); $php = '<?php'; $pos = utf8_strpos($targetContents, $php); if ($pos !== false) { $replacement = sprintf("%s\n\n// updated by %s at %s", $php, __CLASS__, date('c')); $targetContents = utf8_substr_replace($targetContents, $replacement, $pos, utf8_strlen($php)); } $classPrefix = substr($targetClass, 0, strpos($targetClass, 'ShippableHelper_')); $offset = 0; while (true) { if (!preg_match('#DevHelper_Helper_ShippableHelper_[a-zA-Z_]+#', $targetContents, $matches, PREG_OFFSET_CAPTURE, $offset)) { break; } $siblingSourceClass = $matches[0][0]; $offset = $matches[0][1]; $siblingTargetClass = str_replace('DevHelper_Helper_', $classPrefix, $siblingSourceClass); $targetContents = substr_replace($targetContents, $siblingTargetClass, $offset, strlen($siblingSourceClass)); class_exists($siblingTargetClass); $offset += 1; } $targetContents = preg_replace('#\\* @version \\d+\\s*\\n#', '$0 * @see ' . $sourceClass . "\n", $targetContents, -1, $count); return DevHelper_Generator_File::filePutContents($targetPath, $targetContents); }
public static function IsCorrectLenght($text, $min, $max) { if (utf8_strlen($text) < $min || utf8_strlen($text) > $max) { return false; } return true; }
public function validate_configure() { $json = array(); if ($this->request->post['database'] == 'mysqli') { $connection = @new mysqli($this->request->post['database_hostname'], $this->request->post['database_username'], $this->request->post['database_password'], $this->request->post['database_name']); if ($connection->connect_error) { $json['error'] = $connection->connect_error; } else { $connection->close(); } } if ($this->request->post['database'] == 'mysql') { $connection = @mysql_connect($this->request->post['database_hostname'], $this->request->post['database_username'], $this->request->post['database_password']); if (!$connection) { $json['error'] = $this->language->get('error_connection'); } else { if (!@mysql_select_db($this->request->post['database_name'], $connection)) { $json['error'] = $this->language->get('error_database'); } mysql_close($connection); } } if (utf8_strlen($this->request->post['admin_username']) < 3 || utf8_strlen($this->request->post['admin_username']) > 32) { $json['error'] = $this->language->get('error_username'); } if (utf8_strlen($this->request->post['admin_password']) < 6 || utf8_strlen($this->request->post['admin_password']) > 25) { $json['error'] = $this->language->get('error_password'); } if (utf8_strlen($this->request->post['admin_email']) > 96 || !preg_match('/^[^\\@]+@.*.[a-z]{2,15}$/i', $this->request->post['admin_email'])) { $json['error'] = $this->language->get('error_email'); } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); }
/** * Converts WYSIWYG editor HTML back to BB code * * @param string $messageTextHtml HTML to convert * @param XenForo_Input $input * @param integer $htmlCharacterLimit Max length of HTML before processing; defaults to 4 * message length option * * @return string BB code input */ public function convertEditorHtmlToBbCode($messageTextHtml, XenForo_Input $input, $htmlCharacterLimit = -1) { if ($htmlCharacterLimit < 0) { $htmlCharacterLimit = 4 * XenForo_Application::get('options')->messageMaxLength; // quadruple the limit as HTML can be a lot more verbose } if ($htmlCharacterLimit && utf8_strlen($messageTextHtml) > $htmlCharacterLimit) { throw new XenForo_Exception(new XenForo_Phrase('submitted_message_is_too_long_to_be_processed'), true); } $options = array(); $requestPaths = XenForo_Application::get('requestPaths'); $options['baseUrl'] = $requestPaths['fullBasePath']; $relativeResolver = $input->filterSingle('_xfRelativeResolver', XenForo_Input::STRING); if ($relativeResolver && isset($_SERVER['HTTP_USER_AGENT'])) { if (preg_match('#Firefox/([0-9]+)\\.([0-9]+)\\.([0-9]+)#i', $_SERVER['HTTP_USER_AGENT'], $match)) { // FF versions sometime before 3.6.12 have an issue with respecting the base tag of the editor, // 3.6.8 is a known version that has problems $useResolver = $match[1] <= 3 && $match[2] <= 6 && $match[3] <= 8; } else { $useResolver = false; } if ($useResolver) { // take off query string and then up to the last directory $relativeResolver = preg_replace('/\\?.*$/', '', $relativeResolver); $relativeResolver = preg_replace('#/[^/]+$#', '', $relativeResolver); $options['baseUrl'] = $relativeResolver; } } $rendered = XenForo_Html_Renderer_BbCode::renderFromHtml($messageTextHtml, $options); return trim(XenForo_Input::cleanString($rendered)); }
function formatUserNameMobile($ID, $login, $realname, $firstname, $link = 0, $cut = 0) { global $CFG_GLPI; $before = ""; $after = ""; $viewID = ""; if (strlen($realname) > 0) { $temp = $realname; if (strlen($firstname) > 0) { if ($CFG_GLPI["names_format"] == FIRSTNAME_BEFORE) { $temp = $firstname . " " . $temp; } else { $temp .= " " . $firstname; } } if ($cut > 0 && utf8_strlen($temp) > $cut) { $temp = utf8_substr($temp, 0, $cut); $temp .= " ..."; } } else { $temp = $login; } if ($ID > 0 && (strlen($temp) == 0 || $_SESSION["glpiis_ids_visible"])) { $viewID = " ({$ID})"; } if ($link == 1 && $ID > 0) { /*$before="<a title=\"".$temp."\" href=\"".$CFG_GLPI["root_doc"]."/front/user.form.php?id=".$ID."\">";*/ $before = "<a title=\"" . $temp . "\"\n href=\"item.php?itemtype=user&menu=" . $_GET['menu'] . "&ssmenu=" . $_GET['ssmenu'] . "&id=" . $ID . "\" data-back='false'>"; $after = "</a>"; } //$username=$before.$temp.$viewID.$after; $username = $temp . $viewID; return $username; }
public function actionGetFind() { $users = array(); $username = $this->_input->filterSingle('username', XenForo_Input::STRING); $email = $this->_input->filterSingle('user_email', XenForo_Input::STRING); if (empty($email)) { // backward compatibility $email = $this->_input->filterSingle('email', XenForo_Input::STRING); } if (XenForo_Helper_Email::isEmailValid($email)) { $visitor = XenForo_Visitor::getInstance(); $session = bdApi_Data_Helper_Core::safeGetSession(); if ($visitor->hasAdminPermission('user') && $session->checkScope(bdApi_Model_OAuth2::SCOPE_MANAGE_SYSTEM)) { // perform email search only if visitor is an admin and granted admincp scope $user = $this->_getUserModel()->getUserByEmail($email); if (!empty($user)) { $users[$user['user_id']] = $user; } } } if (empty($users) && utf8_strlen($username) >= 2) { // perform username search only if nothing found and username is long enough $users = $this->_getUserModel()->getUsers(array('username' => array($username, 'r')), array('limit' => 10)); } $data = array('users' => $this->_filterDataMany($this->_getUserModel()->prepareApiDataForUsers($users))); return $this->responseData('bdApi_ViewData_User_Find', $data); }
/** * @param string $internalUrl * @return mixed The URL to access the target file from outside, if available, or FALSE. */ public static function toExternalUrl($internalUrl) { $currentProc = ProcManager::getInstance()->getCurrentProcess(); if ($currentProc) { $checknum = $currentProc->getChecknum(); } else { $checknum = -1; } $urlParts = AdvancedPathLib::parse_url($internalUrl); if ($urlParts === false) { return $internalUrl; } if ($urlParts['scheme'] === EyeosAbstractVirtualFile::URL_SCHEME_SYSTEM) { // EXTERN try { $externPath = AdvancedPathLib::resolvePath($urlParts['path'], '/extern', AdvancedPathLib::OS_UNIX | AdvancedPathLib::RESOLVEPATH_RETURN_REFDIR_RELATIVE); return 'index.php?extern=' . $externPath; } catch (Exception $e) { } // APPS try { $appPath = AdvancedPathLib::resolvePath($urlParts['path'], '/apps', AdvancedPathLib::OS_UNIX | AdvancedPathLib::RESOLVEPATH_RETURN_REFDIR_RELATIVE); $appName = utf8_substr($appPath, 1, utf8_strpos($appPath, '/', 1)); $appFile = utf8_substr($appPath, utf8_strlen($appName) + 1); return 'index.php?checknum=' . $checknum . '&appName=' . $appName . '&appFile=' . $appFile; } catch (Exception $e) { } return $internalUrl; } //TODO return $internalUrl; }
protected function validateForm() { if (utf8_strlen(trim($this->request->post['fullname'])) < 2 || utf8_strlen(trim($this->request->post['fullname'])) > 32) { $this->error['fullname'] = $this->language->get('error_fullname'); } if ($this->request->post['password'] || !isset($this->request->get['user_id'])) { if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $this->error['password'] = $this->language->get('error_password'); } if ($this->request->post['password'] != $this->request->post['confirm']) { $this->error['confirm'] = $this->language->get('error_confirm'); } } if (!preg_match('/1[123456789]{1}\\d{9}$/', $this->request->post['telephone'])) { $this->error['telephone'] = $this->language->get('error_telephone'); } if (utf8_strlen(trim($this->request->post['shipping_telephone'])) < 8 || utf8_strlen(trim($this->request->post['shipping_telephone'])) > 14) { $this->error['shipping_telephone'] = $this->language->get('error_shipping_telephone'); } if (utf8_strlen(trim($this->request->post['address'])) < 3 || utf8_strlen(trim($this->request->post['address'])) > 128) { $this->error['address'] = $this->language->get('error_address'); } if (utf8_strlen(trim($this->request->post['city'])) < 2 || utf8_strlen(trim($this->request->post['city'])) > 128) { $this->error['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) { $this->error['postcode'] = $this->language->get('error_postcode'); } if ($this->request->post['country_id'] == '') { $this->error['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $this->error['zone'] = $this->language->get('error_zone'); } // 身份认证图片上check // if (!isset($this->request->post['filename']) || $this->request->post['filename'] == '') { // $this->error['identity_img'] = $this->language->get('error_identity_img'); // } // Add sangsanghu 2015/09/11 ST if (isset($this->request->post['sub_commission_def_percent']) && isset($this->request->post['sub_settle_suspend_days'])) { if (!$this->request->post['sub_commission_def_percent']) { $this->error['sub_commission_def_percent'] = $this->language->get('error_commission_def_percent'); } else { if (!preg_match('/^[0-9]*[1-9][0-9]*$/', $this->request->post['sub_commission_def_percent']) || $this->request->post['sub_commission_def_percent'] > $this->model_salesman_user->getParentCommission()) { $this->error['sub_commission_def_percent'] = sprintf($this->language->get('error_commission_def_percent0'), $this->model_salesman_user->getParentCommission() . "%"); } } if (!$this->request->post['sub_settle_suspend_days']) { $this->error['sub_settle_suspend_days'] = $this->language->get('error_settle_suspend_days'); } else { if (!preg_match('/^[0-9]*[1-9][0-9]*$/', $this->request->post['sub_settle_suspend_days'])) { $this->error['sub_settle_suspend_days'] = $this->language->get('error_settle_suspend_days0'); } } } // Add sangsanghu 2015/09/11 END return !$this->error; }
function newProductBacklog() { global $agilemantis_au; // Check if team-user name fits into MantisBT regulations if (!(utf8_strlen($this->name) < 22 && user_is_name_valid($this->name) && user_is_name_unique($this->name))) { return null; } $p_username = $this->generateTeamUser($this->name); $p_email = $this->email; $p_email = trim($p_email); $t_seed = $p_email . $p_username; $t_password = auth_generate_random_password($t_seed); if (user_is_name_unique($p_username) === true) { user_create($p_username, $t_password, $p_email, 55, false, true, 'Team-User-' . $_POST['pbl_name']); } else { $t_user_id = $this->getUserIdByName($p_username); user_set_field($t_user_id, 'email', $p_email); } $user_id = $this->getLatestUser(); $agilemantis_au->setAgileMantisUserRights($user_id, 1, 0, 0); if ($this->team == 0) { $this->team = $this->getLatestUser(); } $t_sql = "INSERT INTO gadiv_productbacklogs (name, description, user_id) VALUES ( " . db_param(0) . ", " . db_param(1) . ", " . db_param(2) . ") "; $t_params = array($this->name, $this->description, $user_id); db_query_bound($t_sql, $t_params); $this->id = db_insert_id("gadiv_productbacklogs"); $this->user_id = $user_id; return $this->id; }
function run(&$xml_reponse, $p) { $clientid = $p["clientid"]; $param = $p["param"]; $sender = $p["sender"]; $recipient = $p["recipient"]; $recipientid = $p["recipientid"]; $c =& pfcGlobalConfig::Instance(); $u =& pfcUserConfig::Instance(); /** * fixes some anoying issues with noflood not detecting user flooding the chat * those are notice and invite */ $cmdtocheck = array("send", "nick", "me", "notice", "invite"); // fixes the count of noflood even if the text posted was empty (Neumann Valle (UTAN)) if (in_array($this->name, $cmdtocheck) && $param != "") { $container =& pfcContainer::Instance(); $nickid = $u->nickid; $isadmin = $container->getUserMeta($nickid, 'isadmin'); $lastfloodtime = $container->getUserMeta($nickid, 'floodtime'); $flood_nbmsg = $container->getUserMeta($nickid, 'flood_nbmsg'); $flood_nbchar = $container->getUserMeta($nickid, 'flood_nbchar'); $floodtime = time(); if ($floodtime - $lastfloodtime <= $c->proxies_cfg[$this->proxyname]["delay"]) { // update the number of posted message indicator $flood_nbmsg++; // update the number of posted characteres indicator $flood_nbchar += utf8_strlen($param); } else { $flood_nbmsg = 0; $flood_nbchar = 0; } if (!$isadmin && ($flood_nbmsg > $c->proxies_cfg[$this->proxyname]["msglimit"] || $flood_nbchar > $c->proxies_cfg[$this->proxyname]["charlimit"])) { // warn the flooder $msg = _pfc("Please don't post so many message, flood is not tolerated"); $xml_reponse->script("alert('" . addslashes($msg) . "');"); // kick the flooder $cmdp = $p; $cmdp["param"] = null; $cmdp["params"][0] = "ch"; $cmdp["params"][1] = $u->channels[$recipientid]["name"]; $cmdp["params"][2] .= _pfc("kicked from %s by %s", $u->channels[$recipientid]["name"], "noflood"); $cmd =& pfcCommand::Factory("leave"); $cmd->run($xml_reponse, $cmdp); return false; } if ($flood_nbmsg == 0) { $container->setUserMeta($nickid, 'floodtime', $floodtime); } $container->setUserMeta($nickid, 'flood_nbmsg', $flood_nbmsg); $container->setUserMeta($nickid, 'flood_nbchar', $flood_nbchar); } // forward the command to the next proxy or to the final command $p["clientid"] = $clientid; $p["param"] = $param; $p["sender"] = $sender; $p["recipient"] = $recipient; $p["recipientid"] = $recipientid; return $this->next->run($xml_reponse, $p); }
function document_end() { parent::document_end(); // Prepare the TOC global $TOC, $ID; $meta = array(); // NOTOC, and no forceTOC if ($this->info['toc'] === false && !($this->info['forceTOC'] || $this->meta['forceTOC'])) { $TOC = $this->toc = array(); $meta['internal']['toc'] = false; $meta['description']['tableofcontents'] = array(); $meta['forceTOC'] = false; } else { if ($this->info['forceTOC'] || $this->meta['forceTOC'] || utf8_strlen(strip_tags($this->doc)) >= $this->getConf('documentlengthfortoc') && count($this->toc) > 1) { $TOC = $this->toc; // This is a little bit like cheating ... but this will force the TOC into the metadata $meta = array(); $meta['internal']['toc'] = true; $meta['forceTOC'] = $this->info['forceTOC'] || $this->meta['forceTOC']; $meta['description']['tableofcontents'] = $TOC; } } // allways write new metadata p_set_metadata($ID, $meta); $this->doc = preg_replace('#<p( class=".*?")?>\\s*</p>#', '', $this->doc); }
private function validate() { // email $email = !$this->request->getHttpPost('email') ? $this->response->jsonOutputExit('empty_email') : $this->request->getHttpPost('email'); if (!$this->request->isEmail($email)) { $this->response->jsonOutputExit('invalid_email'); } // 判断email是否已存在 $user_info = $this->model_user_main->fetchOne(array('email' => $email)); if (is_array($user_info) && !empty($user_info)) { $this->response->jsonOutputExit('email_already_exist'); } // password $password = !$this->request->getHttpPost('password') ? $this->response->jsonOutputExit('empty_password') : $this->request->getHttpPost('password'); if (utf8_strlen($password) > 30 || utf8_strlen($password) < 6) { $this->response->jsonOutputExit('invalid_password_length'); } // name if ($this->request->getHttpPost('name') && (utf8_strlen($this->request->getHttpPost('name')) > 50 || utf8_strlen($this->request->getHttpPost('name')) < 2)) { $this->response->jsonOutputExit('invalid_name_length'); } // group_id if ($this->request->getHttpPost('group_id') !== false) { $this->checkUserGroup($this->request->getHttpPost('parent_user_id'), $this->request->getHttpPost('group_id')); } }
public function validate() { if (utf8_strlen(trim($this->request->post['accountname'])) < 1 || utf8_strlen(trim($this->request->post['accountname'])) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); $this->error['error'] = $this->language->get('error_firstname_message'); return false; } if (utf8_strlen($this->request->post['phonenumber']) < 3 || utf8_strlen($this->request->post['phonenumber']) > 32) { $this->error['phonenumber'] = $this->language->get('error_telephone'); $this->error['error'] = $this->language->get('error_telephone_message_length'); return false; } $this->load->model('account/customer'); $customer = $this->model_account_customer->getCustomerByPhone($this->request->post['phonenumber']); if (!empty($customer)) { $this->error['error'] = $this->language->get('error_telephone_message_conflict'); return false; } if (utf8_strlen($this->request->post['pwd_1st']) < 4 || utf8_strlen($this->request->post['pwd_1st']) > 20) { $this->error['password'] = $this->language->get('error_password'); $this->error['error'] = $this->language->get('error_password_message_length'); return false; } if ($this->request->post['pwd_2nd'] != $this->request->post['pwd_2nd']) { $this->error['confirm'] = $this->language->get('error_confirm'); $this->error['error'] = $this->language->get('error_password_message_notsame'); } return !$this->error; }
public function send() { $json = array(); $this->load->model('account/customer'); if (isset($this->request->post['email']) && $this->request->post['email']) { if (isset($this->request->post['name']) && empty($this->request->post['name'])) { $json['error'] = 'Digite seu nome corretamente.'; } $email = $this->request->post['email']; if (utf8_strlen($email) > 96 || !$this->functions->validEmail($email)) { $json['error'] = 'Insira um email válido.'; } if (strpos(strtolower($email), 'teste')) { $json['error'] = 'Este e-mail já está cadastrado.'; } if ($this->model_account_customer->getTotalNewsletterByEmail($email)) { $json['error'] = 'Este e-mail já está cadastrado.'; } if (!$json) { $name = ''; if (isset($this->request->post['name'])) { $name = $this->request->post['name']; } $this->model_account_customer->addNewsletter($email, $name); $json['success'] = true; } } else { $json['error'] = 'Digite seu e-mail.'; } $this->response->setOutput(json_encode($json)); }
function utf8_str_pad($input, $pad_length, $pad_string = '', $pad_type = 1, $charset = "UTF-8") { $str = ''; $length = $pad_length - utf8_strlen($input); if ($length > 0) { if ($pad_type == STR_PAD_RIGHT) { $str = $input . str_repeat($pad_string, $length); } else { if ($pad_type == STR_PAD_LEFT) { $str = str_repeat($pad_string, $length) . $input; } else { if ($pad_type == STR_PAD_BOTH) { $str = str_repeat($pad_string, floor($length / 2)); $str .= $input; $str .= str_repeat($pad_string, ceil($length / 2)); } else { $str = str_repeat($pad_string, $length) . $input; } } } } else { $str = $input; } return $str; }
function getTitle($url) { $fd = @fopen($url, 'r'); if ($fd) { $html = fread($fd, 1750); fclose($fd); // Get title from title tag preg_match_all('/<title>(.*)<\\/title>/si', $html, $matches); $title = $matches[1][0]; // Get encoding from charset attribute preg_match_all('/<meta.*charset=([^;"]*)">/i', $html, $matches); $encoding = strtoupper($matches[1][0]); // Convert to UTF-8 from the original encoding if (function_exists('mb_convert_encoding')) { $title = @mb_convert_encoding($title, 'UTF-8', $encoding); } if (utf8_strlen($title) > 0) { return $title; } else { // No title, so return filename $uriparts = explode('/', $url); $filename = end($uriparts); unset($uriparts); return $filename; } } else { return false; } }
public function index() { $this->load->language('api/customer'); // Delete past customer in case there is an error unset($this->session->data['customer']); $json = array(); if (!isset($this->session->data['api_id'])) { $json['error']['warning'] = $this->language->get('error_permission'); } else { // Add keys for missing post vars $keys = array('customer_id', 'customer_group_id', 'firstname', 'lastname', 'email', 'telephone', 'fax'); foreach ($keys as $key) { if (!isset($this->request->post[$key])) { $this->request->post[$key] = ''; } } // Customer if ($this->request->post['customer_id']) { $this->load->model('account/customer'); $customer_info = $this->model_account_customer->getCustomer($this->request->post['customer_id']); if (!$customer_info || !$this->customer->login($customer_info['email'], '', true)) { $json['error']['warning'] = $this->language->get('error_customer'); } } if (utf8_strlen(trim($this->request->post['firstname'])) < 1 || utf8_strlen(trim($this->request->post['firstname'])) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } /*去掉lastname,统一用姓名代替 by qingt 15-5-13 if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) { $json['error']['lastname'] = $this->language->get('error_lastname'); } */ if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*.[a-z]{2,15}$/i', $this->request->post['email'])) { $json['error']['email'] = $this->language->get('error_email'); } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $json['error']['telephone'] = $this->language->get('error_telephone'); } // Customer Group if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } // Custom field validation $this->load->model('account/custom_field'); $custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id); foreach ($custom_fields as $custom_field) { if ($custom_field['location'] == 'account' && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) { $json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); } } if (!$json) { $this->session->data['customer'] = array('customer_id' => $this->request->post['customer_id'], 'customer_group_id' => $customer_group_id, 'firstname' => $this->request->post['firstname'], 'lastname' => $this->request->post['lastname'], 'email' => $this->request->post['email'], 'telephone' => $this->request->post['telephone'], 'fax' => $this->request->post['fax'], 'custom_field' => isset($this->request->post['custom_field']) ? $this->request->post['custom_field'] : array()); $json['success'] = $this->language->get('text_success'); } } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); }
public function ajaxReview() { header('dataType: application/x-json, charset: utf-8'); $data = array(); $data['type'] = 1; // 0. no error, 1. error if (!$this->input->post('name') && utf8_strlen($this->input->post('name')) <= 0) { $data['error_name'] = lang('error_name'); } if (!$this->input->post('review') && utf8_strlen($this->input->post('review') <= 10)) { $data['error_review'] = lang('error_review'); } $ip_address = $this->input->ip_address(); $expiration = time() - 7200; $captcha_sess = $this->session->userdata('captcha_review' . $this->input->post('product_id')); if (!$this->input->post('captcha') || $captcha_sess['captcha_word'] != $this->input->post('captcha') || $captcha_sess['captcha_ip_address'] != $ip_address || $captcha_sess['captcha_time'] <= $expiration) { $data['error_captcha'] = lang('error_captcha'); } if ($_SERVER['REQUEST_METHOD'] === 'POST' && count($data) <= 1) { $data['author'] = $this->input->post('name'); $data['text'] = $this->input->post('review'); $data['rating'] = $this->input->post('rating'); $this->load->model('catalog/review_model'); $this->review_model->addReview($this->input->post('product_id'), $data); $data['type'] = 0; $data['success'] = lang('review_success'); } echo json_encode($data); }
public function cart() { $this->load->model('tool/image'); $this->data['products'] = array(); foreach ($this->cart->getProducts() as $product) { if ($product['image']) { $image = $this->model_tool_image->resize($product['image'], $this->config->get('image_cart_width'), $this->config->get('image_cart_height')); } else { $image = ''; } $option_data = array(); foreach ($product['option'] as $option) { if ($option['type'] != 'file') { $value = $option['option_value']; } else { $filename = $this->encryption->decrypt($option['option_value']); $value = utf8_substr($filename, 0, utf8_strrpos($filename, '.')); } $option_data[] = array('name' => $option['name'], 'value' => utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value, 'type' => $option['type']); } $this->data['products'][] = array('product_id' => $product['product_id'], 'key' => $product['key'], 'thumb' => $image, 'name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $product['price'], 'total' => $product['total'], 'tax' => $product['tax_percentage'], 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])); } // Gift Voucher if (!empty($this->session->data['vouchers'])) { foreach ($this->session->data['vouchers'] as $key => $voucher) { $this->data['products'][] = array('key' => $key, 'name' => $voucher['description'], 'price' => $voucher['amount'], 'amount' => 1, 'total' => $voucher['amount']); } } $this->template = 'cart.tpl'; $this->response->setOutput($this->render()); }