1.0-version
This commit is contained in:
395
application/models/public/Func_model.php
Normal file
395
application/models/public/Func_model.php
Normal file
@@ -0,0 +1,395 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Func_model extends CI_Model {
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
//$this->load->database();
|
||||
}
|
||||
|
||||
/*
|
||||
数组转字符串
|
||||
*/
|
||||
function arrToString($arr, $ico1, $ico2)
|
||||
{
|
||||
$len = count($arr);
|
||||
for($j = 0; $j < $len; $j++)
|
||||
{
|
||||
$_str = implode($ico1, $arr[$j]);
|
||||
$arr[$j]=$_str;
|
||||
}
|
||||
return implode($ico2, $arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 作用:将xml转为array
|
||||
*/
|
||||
function xmlToArray($xml)
|
||||
{
|
||||
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
||||
return $array_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建session
|
||||
* @param $arr
|
||||
* $arr = array(
|
||||
'name_1' => '1',
|
||||
'name_2' => '2',
|
||||
'name_3' => 3
|
||||
);
|
||||
*/
|
||||
function create_session($arr)
|
||||
{
|
||||
$this->session->set_userdata($arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看pc session
|
||||
*/
|
||||
function check_session($skip = true)
|
||||
{
|
||||
$msg = $this->session->userdata();
|
||||
|
||||
if ($skip)
|
||||
{
|
||||
if ($msg == false || $msg == null || isset($msg) == false || count($msg) <= 1)
|
||||
{
|
||||
$this->setPage(base_url().'Login/index');
|
||||
return;
|
||||
}else if ($msg['type'] == null || $msg['type'] != 0 )
|
||||
{
|
||||
$this->setPage(base_url().'Login/index');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看wap session
|
||||
*/
|
||||
function check_wapSession($skip = true)
|
||||
{
|
||||
$msg = $this->session->userdata();
|
||||
|
||||
if ($skip)
|
||||
{
|
||||
if ($msg == false || $msg == null || isset($msg) == false || count($msg) <= 1)
|
||||
{
|
||||
$this->setPage(base_url().'Login/wap');
|
||||
return;
|
||||
}else if ($msg['wtype'] == null || $msg['wtype'] != 1 )
|
||||
{
|
||||
$this->setPage(base_url().'Login/wap');
|
||||
return;
|
||||
}
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁session
|
||||
* @param $arr
|
||||
*/
|
||||
function unset_session($arr)
|
||||
{
|
||||
$this->session->unset_userdata($arr);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 设置定向页面(父框架整体刷新)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public function setPage($url)
|
||||
{
|
||||
echo '<script language="JavaScript">';
|
||||
echo 'if (top.location!=self.location){';
|
||||
echo 'top.location.href = "'.$url.'";';
|
||||
echo '}else{';
|
||||
echo 'location.href = "'.$url.'";';
|
||||
echo '}';
|
||||
echo '</script>';
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 设置定向页面(子页面刷新)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public function setConPage($url)
|
||||
{
|
||||
echo '<script language="JavaScript">';
|
||||
echo 'if (top.location!=self.location){';
|
||||
echo 'location.href = "'.$url.'";';
|
||||
echo '}';
|
||||
echo '</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字符串中得所有空格
|
||||
* @param $str
|
||||
* 字符串
|
||||
*/
|
||||
function check_trim($str)
|
||||
{
|
||||
$str = trim($str);
|
||||
$str = preg_replace('/\s(?=\s)/', '', $str);
|
||||
$str = str_replace(' ', '', $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查字符串长度
|
||||
* @param $str
|
||||
* 字符串
|
||||
*/
|
||||
function check_len($str)
|
||||
{
|
||||
$len = mb_strlen($str,'utf8');
|
||||
return $len;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成json
|
||||
*/
|
||||
function decodeUnicode($str){
|
||||
$json = json_encode($str);
|
||||
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', create_function('$matches', 'return iconv("UCS-2BE","UTF-8",pack("H*", $matches[1]));'), $json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成array
|
||||
*/
|
||||
function decodeArray($str, $bol = true)
|
||||
{
|
||||
return json_decode($str, $bol);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符转数组
|
||||
*/
|
||||
function str_array($result)
|
||||
{
|
||||
$arr = array();
|
||||
$i = 0;
|
||||
$arr[$i] = $result;
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通数组转数组
|
||||
*/
|
||||
function arr_array($result)
|
||||
{
|
||||
$arr = array();
|
||||
$i = 0;
|
||||
foreach ($result as $v)
|
||||
{
|
||||
$arr[$i] = $v;
|
||||
$i++;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符替换
|
||||
*/
|
||||
function str_strtr($str, $from, $to)
|
||||
{
|
||||
$arr = array($from=>$to);
|
||||
return strtr($str,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间格式
|
||||
*/
|
||||
function format_date($time)
|
||||
{
|
||||
$date = date('Y-m-d H:i:s',$time);;
|
||||
return $date;
|
||||
}
|
||||
|
||||
/*
|
||||
上传图片
|
||||
*/
|
||||
public function do_upload($inputname,$config)
|
||||
{
|
||||
$this->load->library('upload', $config);
|
||||
$this->upload->do_upload($inputname);
|
||||
return $this->upload->data();
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 设置提示
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public function setTip($idname,$msg)
|
||||
{
|
||||
echo '<script language="JavaScript">';
|
||||
echo 'parent.setErrorTips("'.$idname.'","errorTips","'.$msg.'");';
|
||||
echo '</script>';
|
||||
}
|
||||
|
||||
/*
|
||||
提示信息
|
||||
*/
|
||||
public function setAlert($msg)
|
||||
{
|
||||
echo '<script type="text/javascript">';
|
||||
echo 'parent.tip("'.$msg.'");';
|
||||
echo '</script>';
|
||||
}
|
||||
|
||||
/*
|
||||
调用js函数
|
||||
*/
|
||||
public function toJsFunc($func,$msg)
|
||||
{
|
||||
echo '<script type="text/javascript">';
|
||||
echo 'parent.'.$func.'('.$msg.');';
|
||||
echo '</script>';
|
||||
}
|
||||
|
||||
/*
|
||||
发送服务端信息
|
||||
*/
|
||||
public function sendServiceMsg($msg)
|
||||
{
|
||||
$callBackFunc = isset($_POST['clientCallBackFunc'])?stripslashes($_POST['clientCallBackFunc']):"";
|
||||
if ($callBackFunc != "")
|
||||
{
|
||||
echo '<script language="JavaScript">';
|
||||
echo 'parent.'.$callBackFunc.'('.$msg.');';
|
||||
echo '</script>';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
重新构造字符串截取函数。
|
||||
*/
|
||||
public function bbt_str($strs, $startIndex = 0, $strLength, $after_str = '...', $strCode = 'UTF-8')
|
||||
{
|
||||
if($strCode == 'UTF-8')
|
||||
{
|
||||
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
|
||||
preg_match_all($pa, $strs, $t_string);
|
||||
|
||||
if(count($t_string[0]) - $startIndex > $strLength)
|
||||
return preg_replace("/<[^>]+>/", '', join("", array_slice($t_string[0], $startIndex, $strLength)).$after_str);
|
||||
return preg_replace("/<[^>]+>/", '', join("", array_slice($t_string[0], $startIndex, $strLength)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$startIndex = $startIndex*2;
|
||||
$strLength = $strLength*2;
|
||||
$strlen = strlen($strs);
|
||||
$tmpstr = "";
|
||||
|
||||
for($i=0; $i< $strlen; $i )
|
||||
{
|
||||
if($i>=$startIndex && $i< $startIndex && $i<$strLength)
|
||||
{
|
||||
if(ord(substr($strs, $i, 1))>129)
|
||||
{
|
||||
$tmpstr.= substr($strs, $i, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpstr.= substr($strs, $i, 1);
|
||||
}
|
||||
}
|
||||
if(ord(substr($strs, $i, 1))>129)
|
||||
$i ;
|
||||
}
|
||||
if(strlen($tmpstr)< $strlen )
|
||||
$tmpstr.= $after_str;
|
||||
return preg_replace("/<[^>]+>/", '', $tmpstr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* array unique_rand( int $min, int $max, int $num )
|
||||
* 生成一定数量的不重复随机数
|
||||
* $min 和 $max: 指定随机数的范围
|
||||
* $num: 指定生成数量
|
||||
*/
|
||||
|
||||
//随机生成不重复的N个数
|
||||
public function unique_rand($min, $max, $num)
|
||||
{
|
||||
//初始化变量为0
|
||||
$count = 0;
|
||||
//建一个新数组
|
||||
$_arr = array();
|
||||
while($count < $num)
|
||||
{
|
||||
$_arr[] = mt_rand($min, $max);
|
||||
$_arr = array_flip(array_flip($_arr));
|
||||
$count = count($_arr);
|
||||
}
|
||||
shuffle($_arr);
|
||||
return $_arr;
|
||||
}
|
||||
|
||||
/*
|
||||
截取数组
|
||||
*/
|
||||
public function getArr($arr,$start,$len)
|
||||
{
|
||||
$tmp = array();
|
||||
$tmp = array_slice($arr,$start,$len);
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
public function uploadFile($file,$url)
|
||||
{
|
||||
$data = "";
|
||||
$allowedExts = array("gif", "jpeg", "jpg", "png");
|
||||
$temp = explode(".", $_FILES[$file]["name"]);
|
||||
//echo $_FILES["file"]["size"];
|
||||
$extension = end($temp);
|
||||
if ((($_FILES[$file]["type"] == "image/gif")
|
||||
|| ($_FILES[$file]["type"] == "image/jpeg")
|
||||
|| ($_FILES[$file]["type"] == "image/jpg")
|
||||
|| ($_FILES[$file]["type"] == "image/pjpeg")
|
||||
|| ($_FILES[$file]["type"] == "image/x-png")
|
||||
|| ($_FILES[$file]["type"] == "image/png"))
|
||||
&& ($_FILES[$file]["size"] < (1024*500))
|
||||
&& in_array($extension, $allowedExts))
|
||||
{
|
||||
if ($_FILES[$file]["error"] > 0)
|
||||
{
|
||||
//$data = "错误:: " . $_FILES[$file]["error"] . "<br>";
|
||||
$data = 14;
|
||||
}
|
||||
else
|
||||
{
|
||||
//echo "上传文件名: " . $_FILES[$file]["name"] . "<br>";
|
||||
//echo "文件类型: " . $_FILES[$file]["type"] . "<br>";
|
||||
//echo "文件大小: " . ($_FILES[$file]["size"] / 1024) . " kB<br>";
|
||||
//echo "文件临时存储的位置: " . $_FILES[$file]["tmp_name"] . "<br>";
|
||||
$_file = $url . date("Y").date("m").date("d").date("H").date("i").date("s").rand(100, 999).".".$extension;
|
||||
move_uploaded_file($_FILES[$file]["tmp_name"], $_file);
|
||||
//echo "文件存储在: " . $url . $_FILES[$file]["name"];
|
||||
$data = $_file;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//$data = "非法的文件格式";
|
||||
$data = 14;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user