function doSave() { $uid = (int) $_POST['uid']; $info = array(); if ($_POST['pwd'] || $_POST['pwd1'] || $_POST['pwd2']) { $pwd = md5(trim($_POST['pwd'])); $pwd1 = md5(trim($_POST['pwd1'])); $pwd2 = md5(trim($_POST['pwd2'])); if (!$_POST['pwd'] || !$_POST['pwd1'] || !$_POST['pwd2']) { javascript::alert("修改密码.原密码,新密码,确认密码不能为空"); } $pwd != $user['password'] && javascript::alert("原密码错误!"); $pwd1 != $pwd2 && javascript::alert("新密码与确认密码不一致!"); iCMS_DB::query("UPDATE `#iCMS@__members` SET `password` = '{$pwd2}' WHERE `uid` ='{$uid}' LIMIT 1"); } // $username=dhtmlspecialchars($_POST['name']); $_POST['email'] && !eregi("^([_\\.0-9a-z-]+)@([0-9a-z][0-9a-z-]+)\\.([a-z]{2,6})\$", $_POST['email']) && javascript::alert("E-mail格式错误!!"); $email = stripslashes($_POST['email']); $gender = intval($_POST['gender']); $info['nickname'] = dhtmlspecialchars(stripslashes($_POST['nickname'])); cstrlen($info['nickname']) > 12 && javascript::alert("昵称长度大于12"); $info['icq'] = intval($_POST['icq']); $info['home'] = dhtmlspecialchars(stripslashes($_POST['home'])); $info['year'] = intval($_POST['year']); $info['month'] = intval($_POST['month']); $info['day'] = intval($_POST['day']); $info['from'] = dhtmlspecialchars(stripslashes($_POST['from'])); $info['signature'] = dhtmlspecialchars(stripslashes($_POST['signature'])); $user['info'] = $info; iCMS_DB::query("UPDATE `#iCMS@__members` SET `info` = '" . addslashes(serialize($user['info'])) . "',`email`='{$email}',`gender`='{$gender}' WHERE `uid` ='{$uid}' LIMIT 1"); javascript::dialog('用户编辑完成!', 'url:' . __SELF__ . '?mo=user&do=manage'); }
function htmlSubString($content, $maxlen = 300, $suffix = FALSE) { $content = preg_split("/(<[^>]+?>)/si", $content, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $wordrows = 0; $outstr = ""; $wordend = false; $beginTags = 0; $endTags = 0; foreach ($content as $value) { if (trim($value) == "") { continue; } if (strpos(";{$value}", "<") > 0) { if (!preg_match("/(<[^>]+?>)/si", $value) && cstrlen($value) <= $maxlen) { $wordend = true; $outstr .= $value; } if ($wordend == false) { $outstr .= $value; if (!preg_match("/<img([^>]+?)>/is", $value) && !preg_match("/<param([^>]+?)>/is", $value) && !preg_match("/<!([^>]+?)>/is", $value) && !preg_match("/<[br|BR]([^>]+?)>/is", $value) && !preg_match("/<hr([^>]+?)>/is", $value) && !preg_match("/<\\/([^>]+?)>/is", $value)) { $beginTags++; } else { if (preg_match("/<\\/([^>]+?)>/is", $value, $matches)) { $endTags++; } } } else { if (preg_match("/<\\/([^>]+?)>/is", $value, $matches)) { $endTags++; $outstr .= $value; if ($beginTags == $endTags && $wordend == true) { break; } } else { if (!preg_match("/<img([^>]+?)>/is", $value) && !preg_match("/<param([^>]+?)>/is", $value) && !preg_match("/<!([^>]+?)>/is", $value) && !preg_match("/<[br|BR]([^>]+?)>/is", $value) && !preg_match("/<hr([^>]+?)>/is", $value) && !preg_match("/<\\/([^>]+?)>/is", $value)) { $beginTags++; $outstr .= $value; } } } } else { if (is_numeric($maxlen)) { $curLength = cstrlen($value); $maxLength = $curLength + $wordrows; if ($wordend == false) { if ($maxLength > $maxlen) { $outstr .= csubstr($value, $maxlen - $wordrows, FALSE, 0); $wordend = true; } else { $wordrows = $maxLength; $outstr .= $value; } } } else { if ($wordend == false) { $outstr .= $value; } } } } while (preg_match("/<([^\\/][^>]*?)><\\/([^>]+?)>/is", $outstr)) { $outstr = preg_replace_callback("/<([^\\/][^>]*?)><\\/([^>]+?)>/is", "strip_empty_html", $outstr); } if (strpos(";" . $outstr, "[html_") > 0) { $outstr = str_replace("[html_<]", "<", $outstr); $outstr = str_replace("[html_>]", ">", $outstr); } if ($suffix && cstrlen($outstr) >= $maxlen) { $outstr .= "..."; } return $outstr; }
case 'logout': member::cleancookie(); break; default: require_once iPATH . 'include/UI.class.php'; $action = $_POST['action']; //$forward= $_POST['forward']; if ($action == 'register') { ckseccode($_POST['seccode'], 'U') && javascript::json('seccode', 'error:seccode'); $username = dhtmlspecialchars($_POST['username']); !preg_match("/^([\\w\\.-]+)@([a-zA-Z0-9-]+)(\\.[a-zA-Z\\.]+)\$/i", $username) && javascript::json('username', 'register:emailerror'); iCMS_DB::getValue("SELECT uid FROM `#iCMS@__members` where `username`='{$username}'") && javascript::json('username', 'register:emailusr'); $password = md5(trim($_POST['password'])); $pwdrepeat = md5(trim($_POST['pwdrepeat'])); $password != $pwdrepeat && javascript::json('pwdrepeat', 'register:different'); $nickname = dhtmlspecialchars($_POST['nickname']); cstrlen($nickname) > 12 && javascript::json(0, 'register:nicknamelong'); iCMS_DB::query("INSERT INTO `#iCMS@__members` (`groupid`,`username`,`password`,`nickname`,`gender`,`info`,`power`,`cpower`,`regtime`,`lastip`,`lastlogintime`,`logintimes`,`post`,`type`,`status`) VALUES ('4','{$username}','{$password}', '{$nickname}','2','','','','" . time() . "','" . getip() . "', '" . time() . "','0','0','0','1') "); $uid = iCMS_DB::$insert_id; //设置为登陆状态 member::set_user_cookie($username, $password, $nickname); javascript::json(1, 'register:finish'); } elseif ($action == "login") { ckseccode($_POST['seccode'], 'U') && javascript::json(0, 'error:seccode'); if (member::checklogin(true)) { javascript::json(1, 'login:success'); } else { javascript::json(0, 'login:failed'); } } }
$pwd = md5(trim($_POST['pwd'])); $pwd1 = md5(trim($_POST['pwd1'])); $pwd2 = md5(trim($_POST['pwd2'])); if (!$_POST['pwd'] || !$_POST['pwd1'] || !$_POST['pwd2']) { alert("修改密码.原密码,新密码,确认密码不能为空"); } $pwd != $user['password'] && alert("原密码错误!"); $pwd1 != $pwd2 && alert("新密码与确认密码不一致!"); $DreamCMS->db->query("UPDATE `#DC@__members` SET `password` = '{$pwd2}' WHERE `uid` ='{$uid}' LIMIT 1"); } // $username=htmlspecialchars($_POST['name']); //$_POST['email']&&!eregi("^([_\.0-9a-z-]+)@([0-9a-z][0-9a-z-]+)\.([a-z]{2,6})$",$_POST['email'])&&alert("E-mail格式错误!!"); $_POST['email'] && !preg_match("/^([_\\.0-9a-z-]+)@([0-9a-z][0-9a-z-]+)\\.([a-z]{2,6})\$/i", $_POST['email']) && alert("E-mail格式错误!!"); //zhaoyanmin php5.3以上版本 eregi在php5.3以上版本改成preg_match $email = stripslashes($_POST['email']); $gender = intval($_POST['gender']); $info['nickname'] = htmlspecialchars(stripslashes($_POST['nickname'])); cstrlen($info['nickname']) > 12 && alert("昵称长度大于12"); $info['icq'] = intval($_POST['icq']); $info['home'] = htmlspecialchars(stripslashes($_POST['home'])); $info['year'] = intval($_POST['year']); $info['month'] = intval($_POST['month']); $info['day'] = intval($_POST['day']); $info['from'] = htmlspecialchars(stripslashes($_POST['from'])); $info['introduce'] = htmlspecialchars(stripslashes($_POST['introduce'])); $user['info'] = $info; $DreamCMS->db->query("UPDATE `#DC@__members` SET `info` = '" . addslashes(serialize($user['info'])) . "',`email`='{$email}',`gender`='{$gender}' WHERE `uid` ='{$uid}' LIMIT 1"); _Header('admincp.php?do=user&operation=edit&userid=' . $uid); } break; }
function page($content, $maxlen = 300, $_pageNum = 0) { $_content = preg_replace(array('/<[\\/\\!]*?[^<>]*?>/is', "/\n+/", "/ +/", "/^\n/"), '', $content); $_length = cstrlen($_content); $_pageCount = floor($_length / $maxlen); $contentA = preg_split("/(<[^>]+?>)/si", $content, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $_caCount = count($contentA); $wordrows = 0; $outstr = ""; $wordend = false; $beginTags = 0; $endTags = 0; foreach ($contentA as $key => $value) { if (trim($value) == "") { continue; } if (strpos(";{$value}", "<") > 0) { if (!preg_match("/(<[^>]+?>)/si", $value) && cstrlen($value) <= $maxlen) { $wordend = true; $outstr .= $value; } if ($wordend == false) { $outstr .= $value; if (!preg_match("/<img([^>]+?)>/is", $value) && !preg_match("/<param([^>]+?)>/is", $value) && !preg_match("/<!([^>]+?)>/is", $value) && !preg_match("/<br([^>]+?)>/is", $value) && !preg_match("/<hr([^>]+?)>/is", $value) && !preg_match("/<\\/([^>]+?)>/is", $value)) { $beginTags++; } else { if (preg_match("/<\\/([^>]+?)>/is", $value, $matches)) { $endTags++; } } } else { if (preg_match("/<\\/([^>]+?)>/is", $value, $matches)) { $endTags++; $outstr .= $value; if ($beginTags == $endTags && $wordend == true) { break; } } else { if (!preg_match("/<img([^>]+?)>/is", $value) && !preg_match("/<param([^>]+?)>/is", $value) && !preg_match("/<!([^>]+?)>/is", $value) && !preg_match("/<[br|BR]([^>]+?)>/is", $value) && !preg_match("/<hr([^>]+?)>/is", $value) && !preg_match("/<\\/([^>]+?)>/is", $value)) { $beginTags++; $outstr .= $value; } } } } else { if (is_numeric($maxlen)) { $curLength = cstrlen($value); $maxLength = $curLength + $wordrows; if ($wordend == false) { if ($maxLength > $maxlen) { //$outstr.=csubstr($value,$maxlen-$wordrows,FALSE,0); $outstr .= $value; $wordend = true; } else { $wordrows = $maxLength; $outstr .= $value; } } } else { if ($wordend == false) { $outstr .= $value; } } } } while (preg_match("/<([^\\/][^>]*?)><\\/([^>]+?)>/is", $outstr)) { $outstr = preg_replace_callback("/<([^\\/][^>]*?)><\\/([^>]+?)>/is", "strip_empty_html", $outstr); } if (strpos(";" . $outstr, "[html_") > 0) { $outstr = str_replace("[html_<]", "<", $outstr); $outstr = str_replace("[html_>]", ">", $outstr); } self::$Rs[] = $outstr; $_pageNum++; $contentA = array_slice($contentA, $key + 1); $content = implode('', $contentA); if ($_pageNum < $_pageCount) { self::page($content, $maxlen, $_pageNum); } else { trim($content) != "" && (self::$Rs[] = $content); } }
function watermark($groundImage) { global $iCMS; if (empty($iCMS->config['iswatermark'])) { return; } list($width, $height, $imagetype) = @getimagesize($groundImage); if ($width < $iCMS->config['waterwidth'] || $height < $iCMS->config['waterheight']) { return FALSE; } $isWaterImage = FALSE; $formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG等格式。"; //读取水印文件 if (!empty($iCMS->config['waterimg']) && file_exists(iPATH . "include/watermark/" . $iCMS->config['waterimg'])) { $waterImage = iPATH . "include/watermark/" . $iCMS->config['waterimg']; $isWaterImage = TRUE; $water_info = @getimagesize($waterImage); $water_w = $water_info[0]; //取得水印图片的宽 $water_h = $water_info[1]; //取得水印图片的高 switch ($water_info[2]) { //取得水印图片的格式 case 1: $water_im = imagecreatefromgif($waterImage); break; case 2: $water_im = imagecreatefromjpeg($waterImage); break; case 3: $water_im = imagecreatefrompng($waterImage); break; default: die($formatMsg); } } else { //putenv('GDFONTPATH=' .iPATH.'include/'); //$iCMS->config['watertext']=g2u($iCMS->config['watertext']); $fontfile = iPATH . 'include/' . $iCMS->config['waterfont']; } //读取背景图片 if (!empty($groundImage) && file_exists($groundImage)) { $ground_info = @getimagesize($groundImage); $ground_w = $ground_info[0]; //取得背景图片的宽 $ground_h = $ground_info[1]; //取得背景图片的高 $ground_im = self::imagecreate($ground_info[2], $groundImage); //取得背景图片的格式 } else { die("需要加水印的图片不存在!"); } //水印位置 if ($isWaterImage) { //图片水印 $w = $water_w; $h = $water_h; } else { //文字水印 if ($iCMS->config['waterfont']) { $temp = imagettfbbox($iCMS->config['waterfontsize'], 0, $fontfile, $iCMS->config['watertext']); //取得使用 TrueType 字体的文本的范围 $w = $temp[2] - $temp[6]; $h = $temp[3] - $temp[7]; unset($temp); } else { $w = $iCMS->config['waterfontsize'] * cstrlen($iCMS->config['watertext']); $h = $iCMS->config['waterfontsize'] + 5; } } if ($ground_w < $w || $ground_h < $h) { // echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!"; return; } switch ($iCMS->config['waterpos']) { case 0: //随机 $posX = rand(0, $ground_w - $w); $posY = rand($h, $ground_h - $h); break; case 1: //1为顶端居左 $posX = 0; $posY = 0; break; case 2: //2为顶端居中 $posX = ($ground_w - $w) / 2; $posY = 0; break; case 3: //3为顶端居右 $posX = $ground_w - $w; $posY = 0; break; case 4: //4为中部居左 $posX = 0; $posY = ($ground_h - $h) / 2; break; case 5: //5为中部居中 $posX = ($ground_w - $w) / 2; $posY = ($ground_h - $h) / 2; break; case 6: //6为中部居右 $posX = $ground_w - $w; $posY = ($ground_h - $h) / 2; break; case 7: //7为底端居左 $posX = 0; $posY = $ground_h - $h; break; case 8: //8为底端居中 $posX = ($ground_w - $w) / 2; $posY = $ground_h - $h; break; case 9: //9为底端居右 $posX = $ground_w - $w; $posY = $ground_h - $h; break; default: //随机 $posX = rand(0, $ground_w - $w); $posY = rand($h, $ground_h - $h); break; } //设定图像的混色模式 imagealphablending($ground_im, true); if ($isWaterImage) { //图片水印 imagecopymerge($ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h, $iCMS->config['waterpct']); //拷贝水印到目标文件 } else { //文字水印 if (empty($iCMS->config['watercolor'])) { $iCMS->config['watercolor'] = "#FFFFFF"; } if (!empty($iCMS->config['watercolor']) && strlen($iCMS->config['watercolor']) == 7) { $R = hexdec(substr($iCMS->config['watercolor'], 1, 2)); $G = hexdec(substr($iCMS->config['watercolor'], 3, 2)); $B = hexdec(substr($iCMS->config['watercolor'], 5)); $textcolor = imagecolorallocate($ground_im, $R, $G, $B); } else { die("水印文字颜色格式不正确!"); } if ($iCMS->config['waterfont']) { imagettftext($ground_im, $iCMS->config['waterfontsize'], 0, $posX, $posY, $textcolor, $fontfile, $iCMS->config['watertext']); } else { imagestring($ground_im, $iCMS->config['waterfontsize'], $posX, $posY, $iCMS->config['watertext'], $textcolor); } } //生成水印后的图片 @unlink($groundImage); self::image($ground_im, $ground_info[2], $groundImage); //释放内存 unset($water_info); isset($water_im) && imagedestroy($water_im); unset($ground_info); }
public function API_check() { $name = iS::escapeStr($_GET['name']); $value = iS::escapeStr($_GET['value']); $a = iPHP::code(1, '', $name); switch ($name) { case 'username': if (!preg_match("/^[\\w\\-\\.]+@[\\w\\-]+(\\.\\w+)+\$/i", $value)) { $a = iPHP::code(0, 'user:register:username:error', 'username'); } else { user::check($value, 'username') && ($a = iPHP::code(0, 'user:register:username:exist', 'username')); } break; case 'nickname': if (preg_match("/\\d/", $value[0]) || cstrlen($value) > 20 || cstrlen($value) < 4) { $a = iPHP::code(0, 'user:register:nickname:error', 'nickname'); } else { user::check($value, 'nickname') && ($a = iPHP::code(0, 'user:register:nickname:exist', 'nickname')); } break; case 'password': strlen($value) < 6 && ($a = iPHP::code(0, 'user:password:error', 'password')); break; case 'seccode': iPHP::seccode($value) or $a = iPHP::code(0, 'iCMS:seccode:error', 'seccode'); break; } iPHP::json($a); }
public static function dataClean($rules, $content) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $ruleArray = explode("\n", $rules); foreach ($ruleArray as $key => $rule) { $rule = trim($rule); $rule = str_replace('<BR>', "\n", $rule); if (strpos($rule, 'BEFOR::') !== false) { $rule = str_replace('BEFOR::', '', $rule); $content = $rule . $content; continue; } if (strpos($rule, 'AFTER::') !== false) { $rule = str_replace('AFTER::', '', $rule); $content = $rule . $content; continue; } if (strpos($rule, '<%SELF%>') !== false) { $content = str_replace('<%SELF%>', $content, $rule); continue; } list($_pattern, $_replacement) = explode("==", $rule); $_pattern = trim($_pattern); $_replacement = trim($_replacement); $_replacement = str_replace('\\n', "\n", $_replacement); if (strpos($_pattern, 'NEED::') !== false) { $need = str_replace('NEED::', '', $_pattern); if (strpos($content, $need) === false) { return false; } } if (strpos($_pattern, 'NOT::') !== false) { $not = str_replace('NOT::', '', $_pattern); if (strpos($content, $not) !== false) { return false; } } if (strpos($_pattern, 'LEN::') !== false) { $len = str_replace('LEN::', '', $_pattern); $len_content = preg_replace(array('/<[\\/\\!]*?[^<>]*?>/is', '/\\s*/is'), '', $content); if (cstrlen($len_content) < $len) { return false; } } if (strpos($_pattern, 'IMG::') !== false) { $img_count = str_replace('IMG::', '', $_pattern); preg_match_all("/<img.*?src\\s*=[\"|'](.*?)[\"|']/is", $content, $match); $img_array = array_unique($match[1]); if (count($img_array) < $img_count) { return false; } } if (strpos($_pattern, 'DOM::') !== false) { iPHP::import(iPHP_LIB . '/phpQuery.php'); $doc = phpQuery::newDocumentHTML($content, 'UTF-8'); //echo 'dataClean:getDocumentID:'.$doc->getDocumentID()."\n"; $_pattern = str_replace('DOM::', '', $_pattern); list($pq_dom, $pq_fun, $pq_attr) = explode("::", $_pattern); $pq_array = phpQuery::pq($pq_dom); foreach ($pq_array as $pq_key => $pq_val) { if ($pq_fun) { if ($pq_attr) { $pq_content = phpQuery::pq($pq_val)->{$pq_fun}($pq_attr); } else { $pq_content = phpQuery::pq($pq_val)->{$pq_fun}(); } } else { $pq_content = (string) phpQuery::pq($pq_val); } $pq_pattern[$pq_key] = $pq_content; $pq_replacement[$pq_key] = $_replacement; } phpQuery::unloadDocuments($doc->getDocumentID()); //var_dump(array_map('htmlspecialchars', $pq_pattern)); $content = str_replace($pq_pattern, $pq_replacement, $content); unset($doc, $pq_array); } else { if ($_pattern == '~SELF~') { $_pattern = $content; } if (strpos($_replacement, '~SELF~') !== false) { $_replacement = str_replace('~SELF~', $content, $_replacement); } if (strpos($_replacement, '~S~') !== false) { $_replacement = str_replace('~S~', ' ', $_replacement); } $replacement[$key] = $_replacement; $pattern[$key] = '|' . self::pregTag($_pattern) . '|is'; } } if ($pattern) { return preg_replace($pattern, $replacement, $content); } else { return $content; } }
<?php require_once "global.php"; require_once iPATH . "include/function/template.php"; $do = $_GET['do']; if (empty($do)) { $iCMS->iPrint("iSYSTEM", "register"); } elseif ($do == 'post') { if ($_POST['action'] == 'save') { ckseccode($_POST['seccode']) && msgJson('seccode', 'error:seccode'); $username = dhtmlspecialchars($_POST['username']); WordFilter($username) && msgJson('username', 'filter:username'); cstrlen($username) < 3 && msgJson('username', 'register:usernameShort'); cstrlen($username) > 12 && msgJson('username', 'register:usernameLong'); $iCMS->db->getValue("SELECT uid FROM `#iCMS@__members` where `username`='{$username}'") && msgJson('username', 'register:usernameusr'); $password = md5(trim($_POST['password'])); $pwdrepeat = md5(trim($_POST['pwdrepeat'])); $password != $pwdrepeat && msgJson('pwdrepeat', 'register:different'); $_POST['email'] && !eregi("^([_\\.0-9a-z-]+)@([0-9a-z][0-9a-z-]+)\\.([a-z]{2,6})\$", $_POST['email']) && msgJson('email', 'register:emailerror'); $email = $_POST['email']; $gender = intval($_POST['gender']); $nickname = dhtmlspecialchars($_POST['nickname']); // cstrlen($info['nickname'])>12 && msgJson(0,'register:nicknamelong'); $_POST['icq'] && ($info['icq'] = intval($_POST['icq'])); $_POST['home'] && ($info['home'] = dhtmlspecialchars(stripslashes($_POST['home']))); $_POST['year'] && ($info['year'] = intval($_POST['year'])); $_POST['month'] && ($info['month'] = intval($_POST['month'])); $_POST['day'] && ($info['day'] = intval($_POST['day'])); $_POST['from'] && ($info['from'] = dhtmlspecialchars(stripslashes($_POST['from']))); $_POST['signature'] && ($info['signature'] = dhtmlspecialchars(stripslashes($_POST['signature']))); $info = empty($info) ? '' : addslashes(serialize($info));
public static function watermark($pf) { if (!self::$config['enable']) { return; } list($width, $height, $imagetype) = @getimagesize($pf); if ($width < self::$config['width'] || $height < self::$config['height']) { return FALSE; } $isWaterImage = FALSE; $formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG等格式。"; //读取水印文件 $waterImgPath = self::$watermark . '/' . self::$config['img']; if (self::$config['img'] && file_exists($waterImgPath)) { list($water_w, $water_h, $water_imagetype) = @getimagesize($waterImgPath); $water_im = self::imagecreate($water_imagetype, $waterImgPath); $water_im or die($formatMsg); $isWaterImage = TRUE; } else { $fontfile = self::$watermark . '/' . self::$config['font']; } //读取背景图片 if ($pf && file_exists($pf)) { list($ground_w, $ground_h, $ground_imagetype) = @getimagesize($pf); $ground_info = @getimagesize($pf); $ground_im = self::imagecreate($ground_imagetype, $pf); //取得背景图片的格式 if (empty($ground_im)) { return; } } else { die("需要加水印的图片不存在!"); } //水印位置 if ($isWaterImage) { //图片水印 $w = $water_w; $h = $water_h; } else { //文字水印 if (self::$config['font']) { $temp = imagettfbbox(self::$config['fontsize'], 0, $fontfile, self::$config['text']); //取得使用 TrueType 字体的文本的范围 $w = $temp[2] - $temp[6]; $h = $temp[3] - $temp[7]; unset($temp); } else { $w = self::$config['fontsize'] * cstrlen(self::$config['text']); $h = self::$config['fontsize'] + 5; } } if ($ground_w < $w || $ground_h < $h) { // echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!"; return; } switch (self::$config['pos']) { case '-1': //自定义 $posX = $ground_w - $w - self::$config['x']; $posY = $ground_h - $h - self::$config['y']; break; case 1: //1为顶端居左 $posX = 0; $posY = 0; break; case 2: //2为顶端居中 $posX = ($ground_w - $w) / 2; $posY = 0; break; case 3: //3为顶端居右 $posX = $ground_w - $w; $posY = 0; break; case 4: //4为中部居左 $posX = 0; $posY = ($ground_h - $h) / 2; break; case 5: //5为中部居中 $posX = ($ground_w - $w) / 2; $posY = ($ground_h - $h) / 2; break; case 6: //6为中部居右 $posX = $ground_w - $w; $posY = ($ground_h - $h) / 2; break; case 7: //7为底端居左 $posX = 0; $posY = $ground_h - $h; break; case 8: //8为底端居中 $posX = ($ground_w - $w) / 2; $posY = $ground_h - $h; break; case 9: //9为底端居右 $posX = $ground_w - $w; $posY = $ground_h - $h; break; default: //随机 $posX = rand(0, $ground_w - $w); $posY = rand($h, $ground_h - $h); break; } $posX = $posX - self::$config['x']; $posY = $posY - self::$config['y']; //设定图像的混色模式 imagealphablending($ground_im, true); if ($isWaterImage) { //图片水印 if (strtolower(substr(strrchr($waterImgPath, "."), 1)) == 'png') { imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h); } else { imagecopymerge($ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h, self::$config['transparent']); //拷贝水印到目标文件 } } else { //文字水印 self::$config['color'] or self::$config['color'] = "#FFFFFF"; if (!empty(self::$config['color']) && strlen(self::$config['color']) == 7) { $R = hexdec(substr(self::$config['color'], 1, 2)); $G = hexdec(substr(self::$config['color'], 3, 2)); $B = hexdec(substr(self::$config['color'], 5)); $textcolor = imagecolorallocate($ground_im, $R, $G, $B); } else { die("水印文字颜色格式不正确!"); } if (self::$config['font']) { imagettftext($ground_im, self::$config['fontsize'], 0, $posX, $posY, $textcolor, $fontfile, self::$config['text']); } else { imagestring($ground_im, self::$config['fontsize'], $posX, $posY, self::$config['text'], $textcolor); } } //生成水印后的图片 @unlink($pf); self::image($ground_im, $ground_info[2], $pf); //释放内存 unset($water_info); isset($water_im) && imagedestroy($water_im); unset($ground_info); return @is_file($pf) ? true : false; }
public function hot_word($N = "") { $HW = array_count_values($this->result); arsort($HW); if ($N) { $i = 0; foreach ($HW as $key => $val) { if ($i < $N && cstrlen($key) > 1) { $R[] = $key; $i++; } elseif ($i > $N) { break; } } return $R; } return $HW; }