/** * utf8::str_pad * * @package Core * @author Kohana Team * @copyright (c) 2007 Kohana Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _str_pad($str, $final_str_length, $pad_str = ' ', $pad_type = STR_PAD_RIGHT) { if (utf8::is_ascii($str) and utf8::is_ascii($pad_str)) { return str_pad($str, $final_str_length, $pad_str, $pad_type); } $str_length = utf8::strlen($str); if ($final_str_length <= 0 or $final_str_length <= $str_length) { return $str; } $pad_str_length = utf8::strlen($pad_str); $pad_length = $final_str_length - $str_length; if ($pad_type == STR_PAD_RIGHT) { $repeat = ceil($pad_length / $pad_str_length); return utf8::substr($str . str_repeat($pad_str, $repeat), 0, $final_str_length); } if ($pad_type == STR_PAD_LEFT) { $repeat = ceil($pad_length / $pad_str_length); return utf8::substr(str_repeat($pad_str, $repeat), 0, floor($pad_length)) . $str; } if ($pad_type == STR_PAD_BOTH) { $pad_length /= 2; $pad_length_left = floor($pad_length); $pad_length_right = ceil($pad_length); $repeat_left = ceil($pad_length_left / $pad_str_length); $repeat_right = ceil($pad_length_right / $pad_str_length); $pad_left = utf8::substr(str_repeat($pad_str, $repeat_left), 0, $pad_length_left); $pad_right = utf8::substr(str_repeat($pad_str, $repeat_right), 0, $pad_length_left); return $pad_left . $str . $pad_right; } trigger_error('utf8::str_pad: Unknown padding type (' . $type . ')', E_USER_ERROR); }
/** * Outputs the Captcha image. * * @param boolean $html HTML output * @return mixed */ public function render($html = TRUE) { // Creates a black image to start from $this->image_create(Captcha::$config['background']); // Add random white/gray arcs, amount depends on complexity setting $count = (Captcha::$config['width'] + Captcha::$config['height']) / 2; $count = $count / 5 * min(10, Captcha::$config['complexity']); for ($i = 0; $i < $count; $i++) { imagesetthickness($this->image, mt_rand(1, 2)); $color = imagecolorallocatealpha($this->image, 255, 255, 255, mt_rand(0, 120)); imagearc($this->image, mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(-Captcha::$config['width'], Captcha::$config['width']), mt_rand(-Captcha::$config['height'], Captcha::$config['height']), mt_rand(0, 360), mt_rand(0, 360), $color); } // Use different fonts if available $font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])]; // Draw the character's white shadows $size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / utf8::strlen($this->response)); $angle = mt_rand(-15 + utf8::strlen($this->response), 15 - utf8::strlen($this->response)); $x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * utf8::strlen($this->response)); $y = (Captcha::$config['height'] - $size) / 2 + $size; $color = imagecolorallocate($this->image, 255, 255, 255); imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response); // Add more shadows for lower complexities Captcha::$config['complexity'] < 10 and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, $font, $this->response); Captcha::$config['complexity'] < 8 and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, $font, $this->response); Captcha::$config['complexity'] < 6 and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, $font, $this->response); Captcha::$config['complexity'] < 4 and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, $font, $this->response); Captcha::$config['complexity'] < 2 and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, $font, $this->response); // Finally draw the foreground characters $color = imagecolorallocate($this->image, 0, 0, 0); imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response); // Output return $this->image_render($html); }
/** * utf8::substr * * @package Core * @author Kohana Team * @copyright (c) 2007 Kohana Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _substr($str, $offset, $length = NULL) { if (SERVER_UTF8) { return $length === NULL ? mb_substr($str, $offset) : mb_substr($str, $offset, $length); } if (utf8::is_ascii($str)) { return $length === NULL ? substr($str, $offset) : substr($str, $offset, $length); } // Normalize params $str = (string) $str; $strlen = utf8::strlen($str); $offset = (int) ($offset < 0) ? max(0, $strlen + $offset) : $offset; // Normalize to positive offset $length = $length === NULL ? NULL : (int) $length; // Impossible if ($length === 0 or $offset >= $strlen or $length < 0 and $length <= $offset - $strlen) { return ''; } // Whole string if ($offset == 0 and ($length === NULL or $length >= $strlen)) { return $str; } // Build regex $regex = '^'; // Create an offset expression if ($offset > 0) { // PCRE repeating quantifiers must be less than 65536, so repeat when necessary $x = (int) ($offset / 65535); $y = (int) ($offset % 65535); $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}'; $regex .= $y == 0 ? '' : '.{' . $y . '}'; } // Create a length expression if ($length === NULL) { $regex .= '(.*)'; // No length set, grab it all } elseif ($length > 0) { // Reduce length so that it can't go beyond the end of the string $length = min($strlen - $offset, $length); $x = (int) ($length / 65535); $y = (int) ($length % 65535); $regex .= '('; $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}'; $regex .= '.{' . $y . '})'; } else { $x = (int) (-$length / 65535); $y = (int) (-$length % 65535); $regex .= '(.*)'; $regex .= $x == 0 ? '' : '(?:.{65535}){' . $x . '}'; $regex .= '.{' . $y . '}'; } preg_match('/' . $regex . '/us', $str, $matches); return $matches[1]; }
/** * utf8::substr_replace * * @package Core * @author Kohana Team * @copyright (c) 2007 Kohana Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _substr_replace($str, $replacement, $offset, $length = NULL) { if (utf8::is_ascii($str)) { return $length === NULL ? substr_replace($str, $replacement, $offset) : substr_replace($str, $replacement, $offset, $length); } $length = $length === NULL ? utf8::strlen($str) : (int) $length; preg_match_all('/./us', $str, $str_array); preg_match_all('/./us', $replacement, $replacement_array); array_splice($str_array[0], $offset, $length, $replacement_array[0]); return implode('', $str_array[0]); }
public static function number_to_text($value, $separator = ' ') { $digits = (string) $value; if (utf8::strpos($digits, '.') !== FALSE) { $digits = explode('.', $digits); return static::number_to_text($digits[0]) . $separator . static::number_to_text($digits[1]); } $jednosci = array('zero', 'jeden', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć', 'siedem', 'osiem', 'dziewięć'); $dziesiatki = array('', 'dziesięć', 'dwadzieścia', 'trzydzieści', 'czterdzieści', 'piećdziesiąt', 'sześćdziesiąt', 'siedemdziesiąt', 'osiemdziesiąt', 'dziewiećdziesiąt'); $setki = array('', 'sto', 'dwieście', 'trzysta', 'czterysta', 'piećset', 'sześćset', 'siedemset', 'osiemset', 'dziewiećset'); $nastki = array('dziesieć', 'jedenaście', 'dwanaście', 'trzynaście', 'czternaście', 'piętnaście', 'szesnaście', 'siedemnaście', 'osiemnaście', 'dzięwietnaście'); $tysiace = array('tysiąc', 'tysiące', 'tysięcy'); $digits = (string) $value; $digits = utf8::strrev($digits); $i = utf8::strlen($digits); $string = ''; if ($i > 5 && $digits[5] > 0) { $string .= $setki[$digits[5]] . ' '; } if ($i > 4 && $digits[4] > 1) { $string .= $dziesiatki[$digits[4]] . ' '; } elseif ($i > 3 && $digits[4] == 1) { $string .= $nastki[$digits[3]] . ' '; } if ($i > 3 && $digits[3] > 0 && $digits[4] != 1) { $string .= $jednosci[$digits[3]] . ' '; } $tmpStr = utf8::substr(utf8::strrev($digits), 0, -3); if (utf8::strlen($tmpStr) > 0) { $tmpInt = (int) $tmpStr; if ($tmpInt == 1) { $string .= $tysiace[0] . ' '; } elseif ($tmpInt % 10 > 1 && $tmpInt % 10 < 5 && ($tmpInt < 10 || $tmpInt > 20)) { $string .= $tysiace[1] . ' '; } else { $string .= $tysiace[2] . ' '; } } if ($i > 2 && $digits[2] > 0) { $string .= $setki[$digits[2]] . ' '; } if ($i > 1 && $digits[1] > 1) { $string .= $dziesiatki[$digits[1]] . ' '; } elseif ($i > 0 && $digits[1] == 1) { $string .= $nastki[$digits[0]] . ' '; } if ($digits[0] > 0 && $digits[1] != 1) { $string .= $jednosci[$digits[0]] . ' '; } return $string; }
/** * utf8::strrpos * * @package Kohana * @author Kohana Team * @copyright (c) 2007-2008 Kohana Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _strrpos($str, $search, $offset = 0) { $offset = (int) $offset; if (utf8::is_ascii($str) and utf8::is_ascii($search)) { return strrpos($str, $search, $offset); } if ($offset == 0) { $array = explode($search, $str, -1); return isset($array[0]) ? utf8::strlen(implode($search, $array)) : FALSE; } $str = utf8::substr($str, $offset); $pos = utf8::strrpos($str, $search); return $pos === FALSE ? FALSE : $pos + $offset; }
/** * utf8::str_split * * @package Core * @author Kohana Team * @copyright (c) 2007 Kohana Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _str_split($str, $split_length = 1) { $split_length = (int) $split_length; if (utf8::is_ascii($str)) { return str_split($str, $split_length); } if ($split_length < 1) { return FALSE; } if (utf8::strlen($str) <= $split_length) { return array($str); } preg_match_all('/.{' . $split_length . '}|[^\\x00]{1,' . $split_length . '}$/us', $str, $matches); return $matches[0]; }
/** * Generates a new Captcha challenge. * * @return string The challenge answer */ public function generate_challenge() { // Load words from the current language and randomize them $words = Kohana::config('captcha.words'); shuffle($words); // Loop over each word... foreach ($words as $word) { // ...until we find one of the desired length if (abs(Captcha::$config['complexity'] - utf8::strlen($word)) < 2) { return utf8::strtoupper($word); } } // Return any random word as final fallback return utf8::strtoupper($words[array_rand($words)]); }
/** * utf8::strcspn * * @package Core * @author Kohana Team * @copyright (c) 2007 Kohana Team * @copyright (c) 2005 Harry Fuecks * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt */ function _strcspn($str, $mask, $offset = NULL, $length = NULL) { if ($str == '' or $mask == '') { return 0; } if (utf8::is_ascii($str) and utf8::is_ascii($mask)) { return $offset === NULL ? strcspn($str, $mask) : ($length === NULL ? strcspn($str, $mask, $offset) : strcspn($str, $mask, $offset, $length)); } if ($start !== NULL or $length !== NULL) { $str = utf8::substr($str, $offset, $length); } // Escape these characters: - [ ] . : \ ^ / // The . and : are escaped to prevent possible warnings about POSIX regex elements $mask = preg_replace('#[-[\\].:\\\\^/]#', '\\\\$0', $mask); preg_match('/^[^' . $mask . ']+/u', $str, $matches); return isset($matches[0]) ? utf8::strlen($matches[0]) : 0; }
/** * Rule: length. Generates an error if the field is too long or too short. * * @param mixed input value * @param array minimum, maximum, or exact length to match * @return bool */ public function length($str, array $length) { if (!is_string($str)) { return FALSE; } $str = strip_tags($str); $size = utf8::strlen($str); $status = FALSE; if (count($length) > 1) { list($min, $max) = $length; if ($size >= $min and $size <= $max) { $status = TRUE; } } else { $status = $size === (int) $length[0]; } return $status; }
public function upload() { if (!$_FILES) { return; } $surfix = Kohana::config('torn')->surfix->temp; $surfix_len = utf8::strlen($surfix); foreach ($_POST as $key => $tmp_name) { if (utf8::substr($key, -$surfix_len) == $surfix) { $field = utf8::substr($key, 0, -$surfix_len); $this->parent->model->set($field, $tmp_name); } } $cache = Cache::instance(); foreach ($_FILES as $key => $upload) { $this->parent->model->set($key, $upload); if (!isset($this->parent->fields[$key]) or !$this->parent->fields[$key] instanceof Torn_Field_File) { continue; } if (upload::not_empty($upload) and upload::valid($upload)) { $seed = Arr::get($_POST, '__SEED__', md5(Request::current()->uri() . time())); $tmp_name = $seed . '-' . md5_file($upload['tmp_name']); if (upload::save($upload, $tmp_name, Kohana::$cache_dir) !== FALSE) { $timestamp = 24 * 60 * 60; $cache->set($tmp_name, array('upload' => $upload, 'timestamp' => $timestamp), $timestamp); $tmp_old_file = Arr::get($_POST, $key . $surfix); if (!empty($tmp_old_file) and file_exists(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file)) { try { unlink(Kohana::$cache_dir . DIRECTORY_SEPARATOR . $tmp_old_file); $cache->delete($tmp_old_file); } catch (Exception $e) { } } $this->parent->model->set($key, $tmp_name); } } } }
public function account_number($p_iNRB) { // Usuniecie spacji $iNRB = utf8::str_ireplace(' ', '', $p_iNRB); // Sprawdzenie czy przekazany numer zawiera 26 znaków if (utf8::strlen($iNRB) != 26) { die('fail #1'); return false; } // Zdefiniowanie tablicy z wagami poszczególnych cyfr $aWagiCyfr = array(1, 10, 3, 30, 9, 90, 27, 76, 81, 34, 49, 5, 50, 15, 53, 45, 62, 38, 89, 17, 73, 51, 25, 56, 75, 71, 31, 19, 93, 57); // Dodanie kodu kraju (w tym przypadku dodajemy kod PL) $iNRB = $iNRB . '2521'; $iNRB = utf8::substr($iNRB, 2) . utf8::substr($iNRB, 0, 2); // Wyzerowanie zmiennej $iSumaCyfr = 0; // Pćtla obliczająca sumć cyfr w numerze konta for ($i = 0; $i < 30; $i++) { $iSumaCyfr += $iNRB[29 - $i] * $aWagiCyfr[$i]; } // Sprawdzenie czy modulo z sumy wag poszczegolnych cyfr jest rowne 1 return $iSumaCyfr % 97 == 1; }
/** * Outputs the Captcha image. * * @param boolean $html HTML output * @return mixed */ public function render($html = TRUE) { // Creates $this->image $this->image_create(Captcha::$config['background']); // Add a random gradient if (empty(Captcha::$config['background'])) { $color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255)); $color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255)); $this->image_gradient($color1, $color2); } // Add a few random lines for ($i = 0, $count = mt_rand(5, Captcha::$config['complexity'] * 4); $i < $count; $i++) { $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(100, 255), mt_rand(50, 120)); imageline($this->image, mt_rand(0, Captcha::$config['width']), 0, mt_rand(0, Captcha::$config['width']), Captcha::$config['height'], $color); } // Calculate character font-size and spacing $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / (utf8::strlen($this->response) + 1); $spacing = (int) (Captcha::$config['width'] * 0.9 / utf8::strlen($this->response)); // Draw each Captcha character with varying attributes for ($i = 0, $strlen = utf8::strlen($this->response); $i < $strlen; $i++) { // Use different fonts if available $font = Captcha::$config['fontpath'] . Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])]; // Allocate random color, size and rotation attributes to text $color = imagecolorallocate($this->image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150)); $angle = mt_rand(-40, 20); // Scale the character size on image height $size = $default_size / 10 * mt_rand(8, 12); $box = imageftbbox($size, $angle, $font, utf8::substr($this->response, $i, 1)); // Calculate character starting coordinates $x = $spacing / 4 + $i * $spacing; $y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4; // Write text character to image imagefttext($this->image, $size, $angle, $x, $y, $color, $font, utf8::substr($this->response, $i, 1)); } // Output return $this->image_render($html); }
public static function shorten_string($str, $max_length, $mid_cut = false) { if (!is_scalar($str)) { return false; } if (!is_int($max_length)) { return false; } $length = utf8::strlen($str); if ($length <= $max_length) { return $str; } elseif ($mid_cut) { $mid = (int) ceil($max_length / 2); $string = utf8::substr($str, 0, $mid) . '...' . utf8::substr($str, $mid); } else { return utf8::substr($str, 0, $max_length) . '...'; } }
function aggiungiutente() { global $SITENAME, $SITEEMAIL, $db, $BASEURL, $VALIDATION, $USERLANG, $USE_IMAGECODE; $utente = $db->real_escape_string($_POST["user"]); $pwd = $db->real_escape_string($_POST["pwd"]); $pwd1 = $db->real_escape_string($_POST["pwd1"]); $email = $db->real_escape_string($_POST["email"]); $idlangue = intval($_POST["language"]); $idstyle = intval($_POST["style"]); $idflag = intval($_POST["flag"]); $timezone = intval($_POST["timezone"]); if (utf8::strtoupper($utente) == utf8::strtoupper("Guest")) { print ERROR . " " . ERR_GUEST_EXISTS . "<br />\n"; print "<a href='account.php'>" . BACK . "</a>"; block_end(); stdfoot(); exit; } if ($pwd != $pwd1) { print ERROR . " " . DIF_PASSWORDS . "<br />\n"; print "<a href='account.php'>" . BACK . "</a>"; block_end(); stdfoot(); exit; } if ($VALIDATION == "none") { $idlevel = 3; } else { $idlevel = 2; } # Create Random number $floor = 100000; $ceiling = 999999; srand((double) microtime() * 1000000); $random = mt_rand($floor, $ceiling); if ($utente == "" || $pwd == "" || $email == "") { return -1; exit; } $res = $db->query("SELECT email FROM users WHERE email = '" . $email . "'"); if ($res->num_rows > 0) { return -2; exit; } if (!security::valid_email($email)) { return -3; exit; } // duplicate username $res = $db->query("SELECT username FROM users WHERE username = '******'"); if ($res->num_rows > 0) { return -4; exit; } // duplicate username if (strpos($db->real_escape_string($utente), " ") == true) { return -7; exit; } if ($USE_IMAGECODE) { if (extension_loaded('gd')) { $arr = gd_info(); if ($arr['FreeType Support'] == 1) { $public = $_POST['public_key']; $private = $_POST['private_key']; $p = new ocr_captcha(); if ($p->check_captcha($public, $private) != true) { err_msg(ERROR, ERR_IMAGE_CODE); block_end(); stdfoot(); exit; } } } } $bannedchar = array("\\", "/", ":", "*", "?", "\"", "@", "\$", "'", "`", ",", ";", ".", "<", ">", "!", "£", "%", "^", "&", "(", ")", "+", "=", "#", "~"); if (straipos($db->real_escape_string($utente), $bannedchar) == true) { return -8; exit; } if (utf8::strlen($db->real_escape_string($pwd)) < 4) { return -9; exit; } @$db->query("INSERT INTO users (username, password, random, id_level, email, style, language, flag, joined, lastconnect, pid, time_offset) VALUES ('" . $utente . "', '" . md5($pwd) . "', " . $random . ", " . $idlevel . ", '" . $email . "', " . $idstyle . ", " . $idlangue . ", " . $idflag . ", NOW(), NOW(), '" . md5(uniqid(mt_rand(), true)) . "', '" . $timezone . "')"); if ($VALIDATION == "user") { ini_set("sendmail_from", ""); if ($db->errno == 0) { mail($email, ACCOUNT_CONFIRM, ACCOUNT_MSG . "\n\n" . $BASEURL . "/account.php?act=confirm&confirm=" . $random . "&language=" . $idlangue . "", "From: " . $SITENAME . " <" . $SITEEMAIL . ">"); write_log("Signup new User " . $utente . " (" . $email . ")", "add"); } else { die($db->error); } } return $db->errno; }
/** * Validate length. */ protected function rule_length($min, $max = NULL) { // Get the length, return if zero if (($length = utf8::strlen($this->value)) === 0) { return; } if ($max == NULL) { if ($length != $min) { $this->errors['exact_length'] = array($min); } } else { if ($length < $min) { $this->errors['min_length'] = array($min); } elseif ($length > $max) { $this->errors['max_length'] = array($max); } } }
$wait = 0; if (intval($rowuser['downloaded']) > 0) { $ratio = number_format((int) $rowuser['uploaded'] / (int) $rowuser['downloaded'], 2); } else { $ratio = 0.0; } $vz = $data["added"]; $timer = floor((vars::$timestamp - $vz) / 3600); if ($ratio < 1.0 && $rowuser['id'] != $data["uploader"]) { $wait = user::$current["WT"]; } $wait -= $timer; if ($wait <= 0) { $wait = 0; } if (utf8::strlen($data["hash"]) > 0) { echo "\t<td align='center' class='lista'>" . ($wait > 0 ? $wait . " h" : "---") . "</td>\n"; } //end waitingtime } echo "\t<td align='center' class='lista'><a href='download.php?id=" . $data["hash"] . "&f=" . urlencode($data["filename"]) . ".torrent'>" . image_or_link("images/download.gif", "", "torrent") . "</a></td>\n"; include INCL_PATH . "offset.php"; echo "\t<td align='center' class='lista'>" . date("d/m/Y H:m:s", $data["added"] - $offset) . "</td>\n"; echo "\t<td align='center' class='lista'>" . misc::makesize((int) $data["size"]) . "</td>\n"; //Uploaders nick details if ($SHOW_UPLOADER && $data["anonymous"] == "true") { echo "\t<td align='center' class='lista'>" . ANONYMOUS . "</td>\n"; } elseif ($SHOW_UPLOADER && $data["anonymous"] == "false") { echo "\t<td align='center' class='lista'><a href='userdetails.php?id=" . (int) $data["upname"] . "'>" . StripSlashes($data['prefixcolor'] . security::html_safe($data["uploader"]) . $data['suffixcolor']) . "</a></td>\n"; } //Uploaders nick details
public function browse() { // Parameters $params = array('join_columns' => array()); // Process filters $params = $this->parseCounters($params); // Process query string $qstring = $this->parseQuerystring($params['total']); // Create actions $actions = array(0 => __('select', 'system'), 'dismiss' => __('report_dismiss', 'reports')); // Check form action if (input::post('do_action')) { // Delete selected reports if (input::post('action') == 'dismiss') { if (input::post('report_id') && is_array(input::post('report_id'))) { foreach (input::post('report_id') as $reportID) { $reportID = (int) $reportID; if ($reportID && $reportID > 0) { $this->dismiss($reportID); } } } } // Success view::setInfo(__('action_applied', 'system')); router::redirect('cp/content/reports?' . $qstring['url'] . 'page=' . $qstring['page']); } // Get reports $reports = array(); if ($params['total']) { $reports = $this->reports_model->getReports('', $params['join_columns'], $qstring['order'], $qstring['limit']); } // Load subjects model loader::model('reports/subjects', array(), 'reports_subjects_model'); // Get subjects $subjects = array(); $data = $this->reports_subjects_model->getSubjects(); foreach ($data as $subject) { $subjects[$subject['subject_id']] = $subject['name']; } // Create table grid $grid = array('uri' => 'cp/content/reports', 'keyword' => 'reports', 'header' => array('check' => array('html' => 'report_id', 'class' => 'check'), 'subject' => array('html' => __('report_subject', 'reports'), 'class' => 'subject'), 'message' => array('html' => __('report_message', 'reports'), 'class' => 'comment'), 'item' => array('html' => __('report_item', 'reports'), 'class' => 'item'), 'user' => array('html' => __('reporter', 'reports'), 'class' => 'user'), 'post_date' => array('html' => __('post_date', 'system'), 'class' => 'date', 'sortable' => true), 'actions' => array('html' => __('actions', 'system'), 'class' => 'actions')), 'content' => array()); // Create grid content foreach ($reports as $report) { $grid['content'][] = array('check' => array('html' => $report['report_id']), 'subject' => array('html' => isset($subjects[$report['subject_id']]) ? $subjects[$report['subject_id']] : ''), 'message' => array('html' => text_helper::truncate($report['message'], 56) . (utf8::strlen($report['message']) > 56 ? ' ' . html_helper::anchor('', __('view', 'system'), array('data-title' => __('message', 'reports'), 'data-role' => 'modal', 'data-display' => 'html', 'data-html' => text_helper::entities($report['message']))) : '')), 'item' => array('html' => __(config::item('resources', 'core', $report['resource_id']), config::item('resources', 'core', config::item('resources', 'core', $report['resource_id']), 'plugin'))), 'user' => array('html' => users_helper::anchor($report['user'])), 'post_date' => array('html' => date_helper::formatDate($report['post_date'])), 'actions' => array('html' => array('actions' => html_helper::anchor('cp/content/reports/actions/' . $report['report_id'], __('report_actions', 'reports'), array('class' => 'action', 'data-role' => 'modal', 'data-display' => 'iframe', 'data-title' => __('report_action_select', 'reports'))), 'view' => html_helper::anchor('cp/content/reports/view/' . $report['report_id'], __('report_view', 'reports'), array('class' => 'view')), 'dismiss' => html_helper::anchor('cp/content/reports/dismiss/' . $report['report_id'] . '?' . $qstring['url'] . 'page=' . $qstring['page'], __('report_dismiss', 'reports'), array('data-html' => __('report_dismiss?', 'reports'), 'data-role' => 'confirm', 'class' => 'delete'))))); } // Set pagination $config = array('base_url' => config::siteURL('cp/content/reports?' . $qstring['url']), 'total_items' => $params['total'], 'items_per_page' => $this->reportsPerPage, 'current_page' => $qstring['page'], 'uri_segment' => 'page'); $pagination = loader::library('pagination', $config, null); // Filter hooks hook::filter('cp/content/reports/browse/grid', $grid); hook::filter('cp/content/reports/browse/actions', $actions); // Assign vars view::assign(array('grid' => $grid, 'actions' => $actions, 'pagination' => $pagination)); // Set title view::setTitle(__('reports_manage', 'system_navigation')); // Set trail if ($qstring['search_id']) { view::setTrail('cp/content/reports?' . $qstring['url'] . 'page=' . $qstring['page'], __('search_results', 'system')); } // Assign actions view::setAction('#', __('search', 'system'), array('class' => 'icon-text icon-system-search', 'onclick' => '$(\'#reports-search\').toggle();return false;')); // Load view view::load('cp/content/reports/browse'); }
/** * Replaces the given words with a string. * * @param string phrase to replace words in * @param array words to replace * @param string replacement string * @param boolean replace words across word boundries (space, period, etc) * @return string */ public static function censor($str, $badwords, $replacement = '#', $replace_partial_words = FALSE) { foreach ((array) $badwords as $key => $badword) { $badwords[$key] = str_replace('\\*', '\\S*?', preg_quote((string) $badword)); } $regex = '(' . implode('|', $badwords) . ')'; if ($replace_partial_words == TRUE) { // Just using \b isn't sufficient when we need to replace a badword that already contains word boundaries itself $regex = '(?<=\\b|\\s|^)' . $regex . '(?=\\b|\\s|$)'; } $regex = '!' . $regex . '!ui'; if (utf8::strlen($replacement) == 1) { $regex .= 'e'; return preg_replace($regex, 'str_repeat($replacement, utf8::strlen(\'$1\'))', $str); } return preg_replace($regex, $replacement, $str); }
/** * Limits a phrase to a given number of characters. * * @param string phrase to limit characters of * @param integer number of characters to limit to * @param string end character or entity * @param boolean enable or disable the preservation of words while limiting * @return string */ public static function limitChars($str, $limit = 100, $end_char = NULL, $preserve_words = FALSE) { $end_char = $end_char === NULL ? '…' : $end_char; $limit = (int) $limit; if (trim($str) === '' or utf8::strlen($str) <= $limit) { return $str; } if ($limit <= 0) { return $end_char; } if ($preserve_words == FALSE) { return rtrim(utf8::substr($str, 0, $limit)) . $end_char; } preg_match('/^.{' . ($limit - 1) . '}\\S*/us', $str, $matches); return rtrim($matches[0]) . (strlen($matches[0]) == strlen($str) ? '' : $end_char); }
$id = 0 + (int) $_GET["id"]; $random = intval($_GET["random"]); if (!$id || !$random || empty($random) || $random == 0) { stderr(ERROR, ERR_UPDATE_USER); } $res = $db->query("SELECT username, email, random FROM users WHERE id = " . $id); $arr = $res->fetch_array(MYSQLI_BOTH) or httperr(); if ($random != $arr["random"]) { stderr(ERROR, ERR_UPDATE_USER); } $email = $arr["email"]; // generate new password; $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; $newpassword = ''; for ($i = 0; $i < 10; $i++) { $newpassword .= $chars[mt_rand(0, utf8::strlen($chars) - 1)]; } $db->query("UPDATE users SET password = '******' WHERE id = " . $id . " AND random = " . $random); if (!$db->affected_rows) { stderr(ERROR, ERR_UPDATE_USER); } $body = <<<EOD As per your request we have generated a new password for your account. Here is the information we now have on file for this account: User name: {$arr["username"]} Password: {$newpassword} You may login at {$BASEURL}/login.php
function check_homepage(&$homepage) { if (!empty($homepage)) { core::htmlspecialchars($homepage); if (utf8::strlen($homepage) > 40) { return '网址不能超过 40 个字符'; } elseif (!misc::is_url($homepage)) { return '网址格式不正确!'; } } return false; }
function mb_strlen($str) { return utf8::strlen($str); }
/** * Tests the text::random() function. * @dataProvider random_provider * @group core.helpers.text.random * @test */ public function random($type, $length = 8) { $this->markTestIncomplete('Test for PHP 5.3 bug needs to be counted, Kohana is still supporting 5.2'); $result = text::random($type, $length); if ((string) $type) { // Checking length $this->assertEquals(utf8::strlen($result), $length); $pool = ''; switch ($type) { case 'alnum': $this->assertTrue(valid::alpha_numeric($result)); break; case 'alpha': $this->assertTrue(valid::alpha($result)); break; case 'numeric': $this->assertTrue(valid::numeric($result)); break; case 'nozero': $this->assertTrue(is_numeric($result)); break; case 'hexdec': $pool = '0123456789abcdef'; break; case 'distinct': $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; break; default: $pool = (string) $type; } if ($pool) { if (preg_match('/[' . preg_quote((string) $pool, '/') . ']*/u', $result, $match)) { $this->assertEquals($match[0], $result); } else { $this->assertTrue(FALSE); } } } else { // Checking length $this->assertEquals($result, ''); } }