public function mubstr($str, $start, $length) { import('ORG.Util.String'); $a = new String(); $b = $a->msubstr($str, $start, $length); return $b; }
static function GBVerify($length = 4, $type = 'png', $width = 180, $height = 50, $fontface = 'simhei.ttf', $verifyName = 'verify') { import('ORG.Util.String'); $code = String::randString($length, 4); $width = $length * 45 > $width ? $length * 45 : $width; session($verifyName, md5($code)); $im = imagecreatetruecolor($width, $height); $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色 $bkcolor = imagecolorallocate($im, 250, 250, 250); imagefill($im, 0, 0, $bkcolor); @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor); // 干扰 for ($i = 0; $i < 15; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor); } for ($i = 0; $i < 255; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor); } if (!is_file($fontface)) { $fontface = dirname(__FILE__) . "/" . $fontface; } for ($i = 0; $i < $length; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120)); //这样保证随机出来的颜色较深。 $codex = String::msubstr($code, $i, 1); imagettftext($im, mt_rand(16, 20), mt_rand(-60, 60), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $fontface, $codex); } Image::output($im, $type); }
/** +---------------------------------------------------------- * 处理城市指南用户发的文章 * @date 2011-2-28 - @time 下午02:47:19 +---------------------------------------------------------- * @static * @access public +---------------------------------------------------------- * @param string +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ function ctg_article_do() { //处理城市指南用户发的文章 //增加新闻 $dao = D("Archives"); $_POST['my_content'] = Input::getVar($_POST['my_content']); $vo = $dao->create(); if ($vo) { if (empty($_POST['my_content'])) { $this->error("You must fill in the field of 'Summary'"); } $vo['description'] = String::msubstr($vo['my_content'], 0, 200); $vo['my_content'] = nl2br($vo['my_content']); $vo['my_content'] = trim($vo['my_content'], '<br>'); if ($vo['showstart']) { $t = explode('/', $vo['showstart']); $vo['showstart'] = mktime('0', 0, 0, $t['1'], $t['0'], $t['2']); } else { $vo['showstart'] = time(); } if ($vo['showend']) { $t = explode('/', $vo['showend']); $vo['showend'] = mktime('0', 0, 0, $t['1'], $t['0'], $t['2']); } else { $vo['showend'] = $vo['showstart'] + 60 * 60 * 60 * 24; } $vo['typeid'] = "2002"; $vo['channel'] = "12"; $kw = str_word_count($vo['description'], 1); $keywords = ""; foreach ($kw as $vkw) { $keywords .= $vkw . ','; } $vo['keywords'] = empty($_POST['keywords']) ? trim($keywords, ',') : $_POST['keywords']; $eid = ''; $xid = Input::getVar($_REQUEST['id']); if ($xid) { $aid = $xid; $eid = $xid; $dao->where("id={$aid}")->save($vo); } else { $aid = $dao->add($vo); } $actlog = $dao->getLastSql(); if ($aid) { $data = array(); $_POST['content'] = Input::getVar($_POST['content']); if (empty($_POST['content'])) { $this->error("You must fill in the field of 'Content'"); } //$data['content']=nl2br($_REQUEST['content']); $data['content'] = $_POST['content']; if (!empty($xid)) { $id = $dao->Table("iic_addon_arc")->where("aid={$aid}")->save($data); } else { $data['aid'] = $aid; $id = $dao->Table("iic_addon_arc")->add($data); } //dump($dao->getLastSql()); if ($id || $id == '0') { $actlog .= '<br>' . $dao->getLastSql(); if (empty($xid)) { $this->_act_log($aid, $vo['channel'], 'add', $actlog); } else { $this->_act_log($aid, $vo['channel'], 'edit', $actlog); } //echo "发布成功!"; $txt = '<h4>Successful release. </h4><br><a href="' . __APP__ . '/article/' . $aid . '.html">View articles </a> / '; $txt .= '<a href="' . __APP__ . '/Usercenter/ctg_article/act/add/ctgid/' . $_POST['typeid2'] . '">Post articles</a><br>'; $txt .= '<a href="' . __APP__ . '/Usercenter/ctg_article/">Back to the list </a>'; $txt .= 'You will be directed to the list page in three seconds! '; $this->assign('jumpUrl', __APP__ . '/Usercenter/ctg_article/ctgid/' . $_POST['typeid2']); $this->success($txt); } else { if (empty($xid)) { $dao->Table("iic_archives")->where("id={$aid}")->limit('1')->delete(); } $this->error("Failed to write in subsidiary table. "); } } else { if ($this->user['username'] == 'iicc') { dump($dao->getLastSql()); } $this->error('Failed to update the main profile table. '); } //dump($vo); } else { $this->error($dao->getError()); } }
/** *增加活动信息 *@date 2010-6-11 *@time 下午04:54:49 */ function event_add() { //增加活动信息 $dao = D("Archives"); /*if(!empty($_FILES["picurl"]['name'])) { $this->_upload(); }*/ $vo = $dao->create(); //dump($vo); if ($vo) { $area = $this->_get_city('fair'); $vo['description'] = String::msubstr(strip_tags($_POST['detail']), 0, 200); $vo['my_content'] = nl2br($vo['description']); $t = explode('/', $vo['showstart']); $vo['showstart'] = mktime('0', 0, 0, $t['1'], $t['0'], $t['2']); $t = explode('/', $vo['showend']); $vo['showend'] = mktime('0', 0, 0, $t['1'], $t['0'], $t['2']); $t = explode('_', $vo['typeid']); $vo['typeid'] = $t['1']; $vo['channel'] = $t['0']; $vo['maps'] = empty($_POST['position']) ? '' : $_POST['position'] . ','; $vo['maps'] .= $_POST['zone_id'] != 0 ? $area[$_POST['city_id']]['_zone'][$_POST['zone_id']]['name'] . ',' : ''; $vo['maps'] .= $_POST['city_id'] != 0 ? $area[$_POST['city_id']]['ctitle'] : ''; $vo['maps'] = empty($vo['maps']) ? $_POST['old_maps'] : $vo['maps']; $kw = str_word_count($vo['my_content'], 1); $keywords = ""; foreach ($kw as $vkw) { $keywords .= $vkw . ','; } $vo['keywords'] = trim($keywords, ','); $eid = ''; $xid = Input::getVar($_REQUEST['id']); if ($xid) { $aid = $xid; $eid = $xid; $dao->where("id={$aid}")->save($vo); } else { $aid = $dao->add($vo); } $actlog = $dao->getLastSql(); if ($aid) { $data = array(); $data['detail'] = nl2br($_REQUEST['detail']); if (!empty($xid)) { $id = $dao->Table("iic_event")->where("aid={$aid}")->save($data); } else { $data['aid'] = $aid; $data['public'] = '2'; $data['membernum'] = '0'; $id = $dao->Table("iic_event")->add($data); } if ($id || $id == '0') { $actlog = '<br>' . $dao->getLastSql(); if (empty($xid)) { $this->_act_log($aid, $vo['channel'], 'add', $actlog); } else { $this->_act_log($aid, $vo['channel'], 'edit', $actlog); } $txt = '<h4>Successful release. </h4><br><a href="/Art/show/aid/' . $aid . '">View articles </a> / '; $txt .= '<a href="/Cp/photo/info/' . $vo['channel'] . '_' . $aid . '">Add pictures</a><br>'; $txt .= '<a href="/Cp/post_art">Post articles</a> / '; $txt .= '<a href="/Cp/my_art">Back to the list </a><br>'; $txt .= 'You will be directed to the picture uploading page in three seconds! '; $this->assign('jumpUrl', '/Cp/photo/info/' . $vo['channel'] . '_' . $aid); $this->success($txt); } else { if (empty($xid)) { $dao->Table("iic_archives")->where("id={$aid}")->limit('1')->delete(); } $this->error("Failed to write in subsidiary table. "); } } else { $this->error('Failed to update the main profile table. '); } //dump($vo); } else { $this->error($dao->getError()); } }
/** * 格式化字段 * * @access private * @param mixed $typeInfo * @param mixed $value * @return mixed */ private function formatField($typeInfo, $value) { preg_match("/(\\w+)(\\((\\d+)\\))?/", $typeInfo, $matches); if (isset($matches[1])) { $type = $matches[1]; } if (isset($matches[3])) { $len = $matches[3]; } $_type = "string"; $type = strtolower($type); switch ($type) { case 'bit': case 'bigbit': case 'bool': case 'boolean': case 'decimal': case 'decimal': case 'dec': case 'double': case 'float': case 'int': case 'bigint': case 'mediumint': case 'smallint': case 'tinyint': case 'real': if (!is_numeric($value)) { $value = 0; } if ($value == '' || $value == null || empty($value)) { $value = 0; } $_type = 'numeric'; break; } if (isset($len)) { if (!is_array($value) && String::strlen($value) > $len) { $value = String::msubstr($value, 0, $len, 'utf-8', ''); } } if (is_array($value)) { $value = serialize($value); } if ($_type == 'string') { $value = '\'' . $value . '\''; } return $value; }
/** * 分割字符串为数组 * @param unknown_type $string */ public function phaseContent($string) { import("ORG.Util.String"); $data = array(); $string_arr = explode("\n", $string); //必须用双引号 foreach ($string_arr as $value) { $lenth = mb_strlen(trim($value), 'utf-8'); if ($lenth > $this->contentLimt) { for ($i = 0; $i < $lenth; $i += $this->contentLimt) { $temp = String::msubstr(trim($value), $i, $this->contentLimt, 'utf-8', false); array_push($data, $temp); } continue; } array_push($data, $value); } if (count($data) > 4) { array_splice($data, 4); } return $data; }
public function get_review() { $page = Filter::int(Req::args("page")); $id = Filter::int(Req::args("id")); $pagetype = Filter::int(Req::args("pagetype")); $score = Req::args("score"); $where = "re.status=1 and re.goods_id = {$id}"; switch ($score) { case 'a': $where .= " and re.point > 3"; break; case 'b': $where .= " and re.point = 3"; break; case 'c': $where .= " and re.point < 3"; break; default: break; } $review = $this->model->table("review as re")->join("left join user as us on re.user_id = us.id")->fields("re.*,re.id as id,us.name as uname,us.head_pic")->where($where)->order("re.id desc")->findPage($page, 10, $pagetype, true); $data = $review['data']; foreach ($data as $key => $value) { $data[$key]['point'] = round($data[$key]['point'] / 5, 2) * 100; $data[$key]['head_pic'] = $value['head_pic'] != '' ? Url::urlFormat("@") . $value['head_pic'] : Url::urlFormat("#images/no-img.png"); $data[$key]['uname'] = String::msubstr($value['uname'], 0, 3, 'utf-8', '***'); } $review['data'] = $data; $review['status'] = "success"; echo JSON::encode($review); }