/** * 系统自动加载ThinkPHP类库 * 并且支持配置自动加载路径 * @param string $classname 对象类名 */ public static function autoload($classname) { // 检查是否存在别名定义 if (tsload($classname)) { return; } // 自动加载当前项目的Actioon类和Model类 if (substr($classname, -5) == 'Model') { tsload(APP_MODEL_PATH . '/' . $classname . '.class.php'); } elseif (substr($classname, -6) == 'Action') { tsload(APP_ACTION_PATH . '/' . $classname . '.class.php'); } else { // 根据自动加载路径设置进行尝试搜索 if (tsconfig('APP_AUTOLOAD_PATH')) { $paths = explode(',', tsconfig('APP_AUTOLOAD_PATH')); foreach ($paths as $path) { if (tsload($path . '/' . $classname . '.class.php')) { // 如果加载类成功则返回 return; } } } } return; }
/** * 获取该插件所需的钩子列表 * @param string $name 插件名称 * @return array 插件所需的钩子列表 */ public function getHooksList($name) { $hooks = $this->getHooksInfo(); $hooksBase = get_class_methods('Hooks'); $list = array(); // 生成插件列表 foreach ($hooks['list'] as $value) { $dirName = ADDON_PATH . DIRECTORY_SEPARATOR . 'plugins'; tsload($this->path . DIRECTORY_SEPARATOR . 'hooks' . DIRECTORY_SEPARATOR . $value . '.class.php'); $hook = array_diff(get_class_methods($value), $hooksBase); foreach ($hook as $v) { $list[$v][$name][] = $value; } } // 排序 foreach ($hooks['sort'] as $key => $value) { if (isset($list[$name][$key])) { $temp = array(); foreach ($value as $v) { $temp[] = $hooks['list'][$v]; } $list[$name][$key] = $temp; } } return $list; }
/** * 初始化方法,生成部门的树形对象模型 * @return void */ public function _initialize() { $field = array('id' => 'department_id', 'name' => 'title', 'pid' => 'parent_dept_id', 'sort' => 'display_order'); tsload(ADDON_PATH . '/model/CateTreeModel'); $this->treeDo = new CateTreeModel('department'); $this->treeDo->setField($field); }
/** * 初始化方法,加载phpmailer,初始化默认参数 * @return void */ public function __construct() { tsload(ADDON_PATH . '/library/phpmailer/class.phpmailer.php'); tsload(ADDON_PATH . '/library/phpmailer/class.pop3.php'); tsload(ADDON_PATH . '/library/phpmailer/class.smtp.php'); $emailset = model('Xdata')->get('admin_Config:email'); $this->option = array('email_sendtype' => $emailset['email_sendtype'], 'email_host' => $emailset['email_host'], 'email_port' => $emailset['email_port'], 'email_ssl' => $emailset['email_ssl'], 'email_account' => $emailset['email_account'], 'email_password' => $emailset['email_password'], 'email_sender_name' => $emailset['email_sender_name'], 'email_sender_email' => $emailset['email_sender_email'], 'email_reply_account' => $emailset['email_sender_email']); }
function save_charge() { $data['charge_value'] = floatval($_REQUEST['charge_value']); $data['charge_score'] = floatval($_REQUEST['charge_score']); tsload(ADDON_PATH . '/library/WxPayPubHelper/WxPayPubHelper.php'); // dump(WxPayConf_pub::APPID); // dump(WxPayConf_pub::MCHID); // dump(WxPayConf_pub::KEY); // dump(WxPayConf_pub::APPSECRET); // dump(WxPayConf_pub::NOTIFY_URL); $out_trade_no = $_REQUEST["out_trade_no"]; empty($out_trade_no) && ($out_trade_no = 'e2e5096d574976e8f115a8f1e0ffb52b'); // 使用订单查询接口 $orderQuery = new OrderQuery_pub(); $orderQuery->setParameter("out_trade_no", "{$out_trade_no}"); // 商户订单号 // 获取订单查询结果 $orderQueryResult = $orderQuery->getResult(); // 商户根据实际情况设置相应的处理流程,此处仅作举例 if ($orderQueryResult["return_code"] == "FAIL") { return array('status' => 0, 'msg' => "通信出错:" . $orderQueryResult['return_msg']); } elseif ($orderQueryResult["result_code"] == "FAIL") { return array('status' => 0, 'msg' => "错误代码:" . $orderQueryResult['err_code'] . " " . "错误代码描述:" . $orderQueryResult['err_code_des']); } elseif ($data['charge_value'] != $orderQueryResult['total_fee']) { return array('status' => 0, 'msg' => "对账失败"); } // echo "交易状态:" . $orderQueryResult ['trade_state'] . "<br>"; // echo "设备号:" . $orderQueryResult ['device_info'] . "<br>"; // echo "用户标识:" . $orderQueryResult ['openid'] . "<br>"; // echo "是否关注公众账号:" . $orderQueryResult ['is_subscribe'] . "<br>"; // echo "交易类型:" . $orderQueryResult ['trade_type'] . "<br>"; // echo "付款银行:" . $orderQueryResult ['bank_type'] . "<br>"; // echo "总金额:" . $orderQueryResult ['total_fee'] . "<br>"; // echo "现金券金额:" . $orderQueryResult ['coupon_fee'] . "<br>"; // echo "货币种类:" . $orderQueryResult ['fee_type'] . "<br>"; // echo "微信支付订单号:" . $orderQueryResult ['transaction_id'] . "<br>"; // echo "商户订单号:" . $orderQueryResult ['out_trade_no'] . "<br>"; // echo "商家数据包:" . $orderQueryResult ['attach'] . "<br>"; // echo "支付完成时间:" . $orderQueryResult ['time_end'] . "<br>"; $data['serial_number'] = t($_REQUEST['serial_number']); $data['uid'] = $this->mid; // TODO 以下信息海全需要从财富通接口取 $data['charge_order'] = t($_REQUEST['charge_order']); $data['charge_type'] = intval($_REQUEST['charge_type']); $data['ctime'] = intval($_REQUEST['ctime']); $data['status'] = intval($_REQUEST['status']); M('credit_charge')->add($data); $des['content'] = "充值了" . $data['charge_score'] . "积分"; model('Credit')->setUserCredit($data['uid'], array('name' => 'credit_charge', 'score' => $data['charge_score']), 1, $des); return array('status' => 1, 'msg' => '充值成功'); }
/** * 连接缓存 * @access public * @param string $type 缓存类型 * @param array $options 配置数组 * @return object */ public function connect($type = '', $options = array()) { if (empty($type)) { $type = C('DATA_CACHE_TYPE'); } $type = strtolower(trim($type)); $class = 'Cache' . ucwords($type); tsload(ADDON_PATH . '/library/cache/' . $class . '.class.php'); if (class_exists($class)) { $cache = new $class($options); } else { throw_exception(L('_CACHE_TYPE_INVALID_') . ':' . $type); } return $cache; }
<?php /** * 缓存模型 - 业务逻辑模型 * @example * setType($type) 主动设置缓存类型 * set($key, $value, $expire = null) 设置缓存key=>value,expire表示有效时间,null表示永久 * get($key, $mutex = false) 获取缓存数据,支持mutex模式 * getList($prefix, $key) 批量获取指定前缀下的多个key值的缓存 * rm($key) 删除缓存 * @author jason <*****@*****.**> * @version TS3.0 */ // 加载缓存操作类 tsload(CORE_LIB_PATH . '/Cache.class.php'); class CacheModel { //public static $_cacheHash = array(); // 缓存的静态变量 protected $handler; // 操作句柄 protected $type = 'FILE'; // 缓存类型,默认为文件缓存 /** * 初始化缓存模型对象,缓存类型 * @return void */ public function __construct($type = '') { $type = model('Xdata')->get('cacheconfig:cachetype'); // $type = empty($type) ? C('DATA_CACHE_TYPE') : $type; !$type && ($type = $this->type);
public function save_charge() { $data['charge_value'] = floatval($_REQUEST['charge_value']); $data['charge_score'] = floatval($_REQUEST['charge_score']); tsload(ADDON_PATH . '/library/WxPayPubHelper/WxPayPubHelper.php'); // dump(WxPayConf_pub::APPID); // dump(WxPayConf_pub::MCHID); // dump(WxPayConf_pub::KEY); // dump(WxPayConf_pub::APPSECRET); // dump(WxPayConf_pub::NOTIFY_URL); $out_trade_no = $_REQUEST['out_trade_no']; empty($out_trade_no) && ($out_trade_no = 'e2e5096d574976e8f115a8f1e0ffb52b'); // 使用订单查询接口 $orderQuery = new OrderQuery_pub(); $orderQuery->setParameter('out_trade_no', "{$out_trade_no}"); // 商户订单号 // 获取订单查询结果 $orderQueryResult = $orderQuery->getResult(); // 商户根据实际情况设置相应的处理流程,此处仅作举例 if ($orderQueryResult['return_code'] == 'FAIL') { return array('status' => 0, 'msg' => '通信出错:' . $orderQueryResult['return_msg']); } elseif ($orderQueryResult['result_code'] == 'FAIL') { return array('status' => 0, 'msg' => '错误代码:' . $orderQueryResult['err_code'] . ' ' . '错误代码描述:' . $orderQueryResult['err_code_des']); } elseif ($data['charge_value'] != $orderQueryResult['total_fee']) { return array('status' => 0, 'msg' => '对账失败'); } $data['serial_number'] = t($_REQUEST['serial_number']); $data['uid'] = $this->mid; // TODO 以下信息海全需要从积分通接口取 $data['charge_order'] = t($_REQUEST['charge_order']); $data['charge_type'] = intval($_REQUEST['charge_type']); $data['ctime'] = intval($_REQUEST['ctime']); $data['status'] = intval($_REQUEST['status']); M('credit_charge')->add($data); $des['content'] = '充值了' . $data['charge_score'] . '积分'; model('Credit')->setUserCredit($data['uid'], array('name' => 'credit_charge', 'score' => $data['charge_score']), 1, $des); return array('status' => 1, 'msg' => '充值成功'); }
/** * 获取验证码图片操作 */ public function verify() { tsload(ADDON_PATH . '/library/Image.class.php'); tsload(ADDON_PATH . '/library/String.class.php'); Image::buildImageVerify(); }
/** * 系统自动加载函数 * @param string $classname 对象类名 * @return void */ function tsautoload($classname) { // 检查是否存在别名定义 if (tsload($classname)) { return; } // 自动加载当前项目的Actioon类和Model类 if (substr($classname, -5) == "Model") { if (!tsload(ADDON_PATH . '/model/' . $classname . '.class.php')) { tsload(APP_LIB_PATH . '/Model/' . $classname . '.class.php'); } } elseif (substr($classname, -6) == "Action") { tsload(APP_LIB_PATH . '/Action/' . $classname . '.class.php'); } elseif (substr($classname, -6) == "Widget") { if (!tsload(ADDON_PATH . '/widget/' . $classname . '.class.php')) { tsload(APP_LIB_PATH . '/Widget/' . $classname . '.class.php'); } } elseif (substr($classname, -6) == "Addons") { if (!tsload(ADDON_PATH . '/plugin/' . $classname . '.class.php')) { tsload(APP_LIB_PATH . '/Plugin/' . $classname . '.class.php'); } } else { $paths = array(ADDON_PATH . '/library'); foreach ($paths as $path) { if (tsload($path . '/' . $classname . '.class.php')) { // 如果加载类成功则返回 return; } } } return; }
/** * 执行Widget控制器 */ public static function execWidget() { //防止CSRF if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' && stripos($_SERVER['HTTP_REFERER'], SITE_URL) !== 0 && $_SERVER['HTTP_USER_AGENT'] !== 'Shockwave Flash' && strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'adobe flash player') === false && MODULE_NAME != 'Weixin') { die('illegal request.'); } $className = MODULE_NAME . 'Widget'; if (!class_exists($className)) { if (file_exists(APP_PATH . '/Lib/Widget/' . MODULE_NAME . 'Widget/' . MODULE_NAME . 'Widget.class.php')) { tsload(APP_PATH . '/Lib/Widget/' . MODULE_NAME . 'Widget/' . MODULE_NAME . 'Widget.class.php'); } else { tsload(APPS_PATH . '/' . $_GET['app_widget'] . '/Lib/Widget/' . MODULE_NAME . 'Widget/' . MODULE_NAME . 'Widget.class.php'); } } $module = new $className(); //异常处理 if (!$module) { // 模块不存在 抛出异常 throw_exception(L('_MODULE_NOT_EXIST_') . MODULE_NAME); } //获取当前操作名 $action = ACTION_NAME; //执行当前操作 if ($rs = call_user_func(array(&$module, $action))) { echo $rs; } return; }
<?php /** * 标准插件抽象。该插件具备插件的标准行为。 * 获取信息,以及该插件拥有的管理操作 * @author sampeng * */ tsload(CORE_LIB_PATH . '/addons/AbstractAddons.class.php'); abstract class SimpleAddons extends AbstractAddons { private $name; private $hooklist = array(); /** * getHooksList * 获取该插件的所有钩子列表 * @access public * @return void */ public function getHooksList($name) { $this->name = $name; $this->getHooksInfo(); return $this->hooklist; } //管理面板 public function adminMenu() { return array(); } //注册hook位该执行的方法
/** * 模板解析入口 * 支持普通标签和TagLib解析 支持自定义标签库 * @access public * @param string $content 要解析的模板内容 * @return string */ public function parse($content) { // 内容为空不解析 if (empty($content)) { return ''; } $begin = $this->config['taglib_begin']; $end = $this->config['taglib_end']; // 检查include语法 $content = $this->parseInclude($content); // 检查PHP语法 $content = $this->parsePhp($content); // 首先替换literal标签内容 $content = preg_replace('/' . $begin . 'literal' . $end . '(.*?)' . $begin . '\\/literal' . $end . '/eis', "\$this->parseLiteral('\\1')", $content); // 获取需要引入的标签库列表 // 标签库只需要定义一次,允许引入多个一次 // 一般放在文件的最前面 // 格式:<taglib name="html,mytag..." /> // 当TAGLIB_LOAD配置为true时才会进行检测 if (C('TAGLIB_LOAD')) { $this->getIncludeTagLib($content); if (!empty($this->tagLib)) { // 对导入的TagLib进行解析 $_taglibs = C('_taglibs_'); foreach ($this->tagLib as $tagLibName) { // 内置标签库 if (!tsload(CORE_LIB_PATH . '/TagLib/TagLib' . ucwords(strtolower($tagLibName)) . '.class.php')) { // 扩展标签库 if ($_taglibs && isset($_taglibs[$tagLibName])) { tsload(CORE_LIB_PATH . '/TagLib/TagLib' . $_taglibs[$tagLibName] . '.class.php'); } else { throw_exception($tagLibName . L('_TAGLIB_NOT_EXIST_')); } } $this->parseTagLib($tagLibName, $content); } } } // 预先加载的标签库 无需在每个模板中使用taglib标签加载 if (C('TAGLIB_PRE_LOAD')) { $tagLibs = explode(',', C('TAGLIB_PRE_LOAD')); foreach ((array) $taglibs as $tag) { $this->parseTagLib($tag, $content); } } // 内置标签库 无需使用taglib标签导入就可以使用 $tagLibs = explode(',', C('TAGLIB_BUILD_IN')); foreach ($tagLibs as $tag) { $this->parseTagLib($tag, $content, true); } //解析普通模板标签 {tagName:} $content = preg_replace('/(' . $this->config['tmpl_begin'] . ')(\\S.+?)(' . $this->config['tmpl_end'] . ')/eis', "\$this->parseTag('\\2')", $content); return $content; }
/** * 官方服务器生成后台页面配置信息 * * @return [type] void */ public function createSystemConfigPHPFile() { set_time_limit(0); // 判断文件夹路径是否存在 if (!file_exists(LANG_PATH)) { mkdir(LANG_PATH, 0777); } $data = D('system_config')->findAll(); $fileName = LANG_PATH . '/system_config.php'; // 权限处理 $fp = fopen($fileName, 'w+'); $fileData = "<?php\n"; $fileData .= "return array(\n"; foreach ($data as $val) { $val['value'] = unserialize($val['value']); $arr = 'array('; if ($val['value']['key']) { $arr .= '\'key\'=>array('; foreach ($val['value']['key'] as $k0 => $v0) { $arr .= '\'' . $k0 . '\'=>\'' . htmlspecialchars($v0, ENT_QUOTES) . '\','; } $arr .= '),'; } if ($val['value']['key_name']) { $arr .= '\'key_name\'=>array('; foreach ($val['value']['key_name'] as $k1 => $v1) { $arr .= '\'' . $k1 . '\'=>\'' . htmlspecialchars($v1, ENT_QUOTES) . '\','; } $arr .= '),'; } if ($val['value']['key_hidden']) { $arr .= '\'key_hidden\'=>array('; foreach ($val['value']['key_hidden'] as $k2 => $v2) { $arr .= '\'' . $k2 . '\'=>\'' . htmlspecialchars($v2, ENT_QUOTES) . '\','; } $arr .= '),'; } if ($val['value']['key_type']) { $arr .= '\'key_type\'=>array('; foreach ($val['value']['key_type'] as $k3 => $v3) { $arr .= '\'' . $k3 . '\'=>\'' . htmlspecialchars($v3, ENT_QUOTES) . '\','; } $arr .= '),'; } if ($val['value']['key_default']) { $arr .= '\'key_default\'=>array('; foreach ($val['value']['key_default'] as $k4 => $v4) { $arr .= '\'' . $k4 . '\'=>\'' . htmlspecialchars($v4, ENT_QUOTES) . '\','; } $arr .= '),'; } if ($val['value']['key_tishi']) { $arr .= '\'key_tishi\'=>array('; foreach ($val['value']['key_tishi'] as $k5 => $v5) { $arr .= '\'' . $k5 . '\'=>\'' . htmlspecialchars($v5, ENT_QUOTES) . '\','; } $arr .= '),'; } if ($val['value']['key_javascript']) { $arr .= '\'key_javascript\'=>array('; foreach ($val['value']['key_javascript'] as $k6 => $v6) { $arr .= '\'' . $k6 . '\'=>\'' . htmlspecialchars($v6, ENT_QUOTES) . '\','; } $arr .= ')'; } $arr .= ')'; if (empty($val['key']) || empty($val['list']) || $arr == 'array()') { continue; } $content[] = "'{$val['key']}-{$val['list']}'=>" . $arr; } $fileData .= implode(",\n", $content); $fileData .= "\n);"; fwrite($fp, $fileData); fclose($fp); unset($fileData); unset($content); @chmod($fileName, 0775); tsload(ADDON_PATH . '/library/Update.class.php'); $updateClass = new Update(); $res = $updateClass->zipPackage($fileName, LANG_PATH, 'system_config', LANG_PATH); unlink($fileName); echo $res; }
/** * 上传文件 * @access public * @param string $savePath 上传文件保存路径 * @return string * @throws ThinkExecption */ public function upload($savePath = '') { if (!$this->isOpen()) { $this->error = '没有开启云图片功能'; return false; } $fileInfo = array(); $isUpload = false; // 获取上传的文件信息,对$_FILES数组信息处理 $files = $this->dealFiles($_FILES); foreach ($files as $key => $file) { //过滤无效的上传 if (!empty($file['name'])) { $file['key'] = $key; $file['extension'] = $this->getExt($file['name']); if ($this->savePath) { $file['savepath'] = $this->savePath; } else { $file['savepath'] = $this->customPath; } if ($this->saveName) { $file['savename'] = $this->saveName; } else { $file['savename'] = uniqid() . "." . $file['extension']; } //移动设备上传的无后缀的图片,默认为jpg if ($GLOBALS['fromMobile'] == true && empty($file['extension'])) { $file['extension'] = 'jpg'; $file['savename'] = trim($file['savename'], '.') . '.jpg'; } elseif ($this->autoCheck) { if (!$this->check($file)) { return false; } } //计算hash if (function_exists($this->hashType)) { $fun = $this->hashType; $file['hash'] = $fun($file['tmp_name']); } //上传到云服务器 $config = $this->getConfig(); tsload(ADDON_PATH . '/library/upyun.class.php'); $cloud = new UpYun($config['cloud_image_bucket'], $config['cloud_image_admin'], $config['cloud_image_password']); $cloud->setTimeout(60); $file_content = file_get_contents($file['tmp_name']); $res = $cloud->writeFile('/' . $file['savepath'] . $file['savename'], $file_content, true); if (!$res) { $this->error = '上传到云服务器失败!'; return false; } //上传成功后保存文件信息,供其它地方调用 unset($file['tmp_name'], $file['error'], $file_content); $fileInfo[] = $file; $isUpload = true; } } if ($isUpload) { $this->uploadFileInfo = $fileInfo; return true; } else { $this->error = '上传出错!文件不符合上传要求。'; return false; } }
/** * 上传至阿里云视频或音频 * @return array */ public function multiupload($weiba_id, $post_id, $uploadFile, $upImage = null) { //$this->mid = $this->mid; //$this->error($this->mid); //判断是否是圈主 $weibaer = D('weiba')->where(array('uid' => $this->mid))->field('weiba_id')->select(); $manage = D('user_group_link')->where(array('uid' => $this->mid))->field('user_group_id')->find(); if ($weibaer == null || $manage['user_group_id'] != 1) { return array('status' => 0, 'message' => '您还没有权限发表视频或音频,仅限管理员或圈主发表!'); } else { //$uploadFile = 'E:\007.JPG'; tsload('./addons/oss/samples/RunAll.php'); //判定是否是文件夹 if (is_dir($uploadFile)) { return array('status' => '0', 'message' => '不支持文件夹上传'); // $arr = uploadDir($uploadFile); // $data['up_oss_type'] = 2; //print_r($arr); // $info = pathinfo($uploadFile); // echo $info['extension']; } else { // echo $uploadFile.'<br/>';var_dump(filesize($uploadFile));exit(); if ($upImage != null) { if (file_exists($upImage)) { //var_dump($upImage); $info = pathinfo($upImage); $extension = strtolower($info['extension']); //分片上传 $arr = putObjectByRawApis($upImage, $extension); if ($arr != null) { $objectMeta = getObjectMeta($arr['object']); $image_path = $objectMeta['oss-request-url']; $upImage = str_replace('http://ts-video.oss-cn-hangzhou.aliyuncs.com', 'http://video.chuangyejia.com', $image_path); } } else { return array('status' => '0', 'message' => '上传失败'); } } $info = pathinfo($uploadFile); $extension = $info['extension']; $data['up_oss_type'] = 1; //分片上传 $arr = putObjectByRawApis($uploadFile, $extension); //print_r($arr); } //$this->error($arr['object']); if ($arr != null) { //得到上传文件的oss属性 $objectMeta = getObjectMeta($arr['object']); // $this->error( '测试'); // print_r($objectMeta); //得到文件路径 $object_path = $objectMeta['oss-request-url']; //echo $object_path; $object_size = $objectMeta['content-length']; $info = pathinfo($object_path); $object_path_extension = $info['extension']; $data['up_oss_extension'] = $object_path_extension; $data['uid'] = $this->mid; $data['weiba_id'] = $weiba_id; $data['post_id'] = $post_id; $data['up_oss_image'] = $upImage; // $data['up_oss_title'] = $title; // $data['up_oss_describe'] = $Describe; $data['up_oss_size'] = $object_size; $data['up_oss_path'] = str_replace('http://ts-video.oss-cn-hangzhou.aliyuncs.com', 'http://video.chuangyejia.com', $object_path); // $data['up_oss_path']=$this->str_replace_once('http://ts-video.oss-cn-hangzhou.aliyuncs.com','http://video.chuangyejia.com',$object_path); $data['up_oss_ctime'] = time(); $flag = M('up_oss')->add($data); //print_r($data); // var_dump($flag); if ($flag) { return array('status' => '1', 'up_oss_id' => $flag, 'url' => $object_path, 'videoImage' => $upImage, 'message' => '上传成功'); } else { //return false; return array('status' => '0', 'message' => '上传失败'); ///$this->error('上传失败'); } } else { return array('status' => '0', 'message' => '上传失败'); //$this->error('上传失败'); } // getObject($arr['uploadFile'], $arr['object']); } }
static function GBVerify($length = 4, $type = 'png', $width = 180, $height = 50, $fontface = 'simhei.ttf', $verifyName = 'verify') { tsload(ADDON_PATH . '/library/String.class.php'); $code = String::rand_string($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); }
/** * DES解密函数 * * @param string $input * @param string $key */ function desdecrypt($encrypted, $key) { //使用新版的加密方式 tsload(ADDON_PATH . '/library/DES_MOBILE.php'); $desc = new DES_MOBILE(); return $desc->setKey($key)->decrypt($encrypted); }
if (file_exists(APP_COMMON_PATH . '/common.php')) { tsload(APP_COMMON_PATH . '/common.php'); } //合并应用配置 if (file_exists(APP_CONFIG_PATH . '/config.php')) { tsconfig(include APP_CONFIG_PATH . '/config.php'); } //根据应用配置重定义以下常量 if (C('THEME_NAME')) { tsdefine('THEME_NAME', C('THEME_NAME')); } //根据应用配置重定义以下常量 if (C('APP_TPL_PATH')) { tsdefine('APP_TPL_PATH', C('APP_TPL_PATH')); } //如果是部署模式、则如下定义 if (C('DEPLOY_STATIC')) { tsdefine('THEME_PUBLIC_URL', PUBLIC_URL . '/' . THEME_NAME); tsdefine('APP_PUBLIC_URL', THEME_PUBLIC_URL . '/' . TRUE_APPNAME); } //载入插件钩子 //$ts['_config']['hooks'] = array('app_init'=>array('check_access','check_access2')); //根据应用配置信息. 重置一些常量 tsload(CORE_LIB_PATH . '/Think.class.php'); tsload(CORE_LIB_PATH . '/App.class.php'); //tsload(CORE_LIB_PATH.'/Action.class.php'); //tsload(CORE_LIB_PATH.'/Model.class.php'); //tsload(CORE_LIB_PATH.'/DB.class.php'); //tsload(CORE_LIB_PATH.'/Widget.class.php'); //tsload(CORE_LIB_PATH.'/Api.class.php'); //tsload(CORE_LIB_PATH.'/Page.class.php');
/** * 设置所有插件对象 * @return void */ private function _getFileAddons() { if (!empty($this->fileAddons)) { return $this->fileAddons; } // 获取文件夹下面的所有插件 $dirName = ADDON_PATH . '/plugin/'; $dir = dir($dirName); $fileAddons = array(); while (false !== ($entry = $dir->read())) { if ($entry == '.' || $entry == '..' || $entry == ".svn") { continue; } $path = $dirName . '/' . $entry; $addonsFile = $path . '/' . $entry . 'Addons.class.php'; tsload(CORE_PATH . '/OpenSociax/addons/AbstractAddons.class.php'); tsload(CORE_PATH . '/OpenSociax/addons/NormalAddons.class.php'); tsload(CORE_PATH . '/OpenSociax/addons/SimpleAddons.class.php'); if (file_exists($addonsFile)) { tsload($addonsFile); $class = $entry . 'Addons'; $fileAddons[$entry] = new $class(); $fileAddons[$entry]->setPath($path); } } $this->fileAddons = $fileAddons; }
/** * 同步后台菜单配置 */ public function doUpdateAdminTab() { $tab_id = explode(',', $_REQUEST['tab_id']); $tabFileArr = (include LANG_PATH . '/system_config.php'); if ($tabFileArr) { foreach ($tab_id as $k => $v) { $keys = explode('-', $v); if ($tabFileArr[$v]) { $map['key'] = $keys[0]; $map['list'] = $keys[1]; foreach ($tabFileArr[$v] as $key => $val) { foreach ($val as $a => $b) { $tabFileArr[$v][$key][$a] = htmlspecialchars_decode($b, ENT_QUOTES); // 反转义 } } $data['value'] = serialize($tabFileArr[$v]); if ($lang = D('system_config')->where($map)->find()) { D('system_config')->where($map)->save($data); } else { $data = array_merge($data, $map); M('system_config')->add($data); } } } $data['status'] = 1; $data['data'] = L('PUBLIC_ADMIN_OPRETING_SUCCESS'); } else { $data['status'] = 0; $data['data'] = L('PUBLIC_ADMIN_OPRETING_ERROR'); } // 清空缓存 tsload(ADDON_PATH . '/library/Update.class.php'); $updateClass = new Update(); $cacheDir = C('F_CACHE_PATH'); $updateClass->rmdirr($cacheDir); exit(json_encode($data)); }
/** * 下载附件 * * @param int $aid 附件ID 为空时使用$_REQUEST['id']作为附件ID */ public function download($aid) { if (intval($aid) == 0) { $aid = intval($_REQUEST['id']); } $attach = model('Attach')->field('savepath,savename,name')->where("id='{$aid}'")->find(); if (!$attach) { $this->error('附件不存在或已被删除!'); } //下载函数 tsload('./addons/library/Http.class.php'); $file_path = UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename']; if (file_exists($file_path)) { $filename = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? iconv('utf-8', 'gbk', $attach['name']) : preg_replace('/\\s/', '_', $attach['name']); Http::download($file_path, $filename); } else { $this->error('附件不存在或已被删除!'); } }
function step06_overWritten() { // 提示需要删除的文件 $filePath = $targetDir = DATA_PATH . '/update/download/unzip/fileForDeleteList.php'; if (file_exists($filePath)) { $deleteList = (require_once $filePath); foreach ($deleteList as $d) { unlink(SITE_PATH . '/' . $d); } unlink($filePath); } // 执行文件替换 tsload(ADDON_PATH . '/library/Update.class.php'); $updateClass = new Update(); $res = $updateClass->overWrittenFile(); if (!empty($res['error'])) { $this->assign('error', $res['error']); $this->display(); } else { echo 1; } }
/** * 附件下载 */ public function down() { $aid = intval($_GET['attach_id']); $attach = model('Attach')->getAttachById($aid); if (!$attach) { die(L('PUBLIC_ATTACH_ISNULL')); } $filename = $attach['save_path'] . $attach['save_name']; $realname = auto_charset($attach['name'], "UTF-8", 'GBK//IGNORE'); //下载函数 tsload(ADDON_PATH . '/library/Http.class.php'); //从云端下载 $cloud = model('CloudAttach'); if ($cloud->isOpen()) { $url = $cloud->getFileUrl($filename); redirect($url); //$content = $cloud->getFileContent($filename); //读文件下载 //Http::download('', $realname, $content); //从本地下载 } else { if (file_exists(UPLOAD_PATH . '/' . $filename)) { Http::download(UPLOAD_PATH . '/' . $filename, $realname); } else { echo L('PUBLIC_ATTACH_ISNULL'); } } }
<?php /** * 插件数据模型 - 数据对象模型 * @author jason <*****@*****.**> * @version TS3.0 */ // 载入Key-Value存储引擎模型 - 数据对象模型 tsload(ADDON_PATH . '/model/XdataModel.class.php'); class AddonDataModel extends XdataModel { const PREFIX = 'addons:'; // 前缀 protected $list_name = 'addons'; // 存储的list名称 /** * 写入插件参数列表 * @param string $addonName 插件名称 * @param array $data 插件相关数据 * @return bool 是否写入成功 */ public function lputAddons($addonName, $data = array()) { return parent::lput(self::PREFIX . $addonName, $data); } /** * 读取插件参数列表 * @param string $addonName 插件名称 * @return array 插件参数列表 */ public function lgetAddons($addonName)
private function formatContent($content, $data, $type) { switch ($type) { case 1: case 2: case 4: case 5: $content = str_replace('{rand}', $data['rand'], $this->_defaultHash[$type]); break; case 3: tsload(ADDON_PATH . 'brary/String.class.php'); $rndstr = String::rand_string(5, 3); $pwd = $rndstr . $data['rand']; $content = str_replace('{pwd}', $pwd, $this->_defaultHash[$type]); $map['login'] = $data['communication']; $uname = model('User')->where($map)->getField('uname'); $content = str_replace('{name}', $uname, $content); $setuser['login_salt'] = rand(10000, 99999); $setuser['password'] = md5(md5($pwd) . $setuser['login_salt']); model('User')->where($map)->save($setuser); break; } return $content; }
/** * 系统自动加载函数 * @param string $classname 对象类名 */ function tsautoload($classname) { // 检查是否存在别名定义 if (tsload($classname)) { return; } // 自动加载当前项目的Actioon类和Model类 if (substr($classname, -5) == 'Model') { tsload(APP_LIB_PATH . '/Model/' . $classname . '.class.php'); } elseif (substr($classname, -6) == 'Action') { tsload(APP_LIB_PATH . '/Action/' . $classname . '.class.php'); } elseif (substr($classname, -6) == 'Widget') { $filename = sprintf('%s/Widget/%s/%s.class.php', APP_LIB_PATH, $classname, $classname); tsload($filename); } elseif (substr($classname, -6) == 'Addons') { tsload(APP_LIB_PATH . '/Plugin/' . $classname . '.class.php'); } return; }
/** * 执行Widget控制器 * @access public * @return void */ public static function execWidget() { //防止CSRF if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' && stripos($_SERVER['HTTP_REFERER'], SITE_URL) !== 0 && $_SERVER['HTTP_USER_AGENT'] !== 'Shockwave Flash') { die('illegal request.'); } //include_once (ADDON_PATH.'/widget/'.MODULE_NAME.'Widget/'.MODULE_NAME.'Widget.class.php'); //$className = MODULE_NAME.'Widget'; if (file_exists(ADDON_PATH . '/widget/' . MODULE_NAME . 'Widget/' . MODULE_NAME . 'Widget.class.php')) { tsload(ADDON_PATH . '/widget/' . MODULE_NAME . 'Widget/' . MODULE_NAME . 'Widget.class.php'); } else { if (file_exists(APP_PATH . '/Lib/Widget/' . MODULE_NAME . 'Widget/' . MODULE_NAME . 'Widget.class.php')) { tsload(APP_PATH . '/Lib/Widget/' . MODULE_NAME . 'Widget/' . MODULE_NAME . 'Widget.class.php'); } } $className = MODULE_NAME . 'Widget'; $module = new $className(); //异常处理 if (!$module) { // 模块不存在 抛出异常 throw_exception(L('_MODULE_NOT_EXIST_') . MODULE_NAME); } //获取当前操作名 $action = ACTION_NAME; //执行当前操作 if ($rs = call_user_func(array(&$module, $action))) { echo $rs; } return; }
<?php /** * 后台,用户管理控制器 * @author liuxiaoqing <*****@*****.**> * @version TS3.0 */ // 加载后台控制器 tsload(APPS_PATH . '/admin/Lib/Action/AdministratorAction.class.php'); class UserAction extends AdministratorAction { public $pageTitle = array(); /** * 初始化,初始化页面表头信息,用于双语 */ public function _initialize() { $this->pageTitle['index'] = L('PUBLIC_USER_MANAGEMENT'); $this->pageTitle['pending'] = L('PUBLIC_PENDING_LIST'); $this->pageTitle['profile'] = L('PUBLIC_PROFILE_SETTING'); $this->pageTitle['profileCategory'] = L('PUBLIC_PROFILE_SETTING'); $this->pageTitle['dellist'] = L('PUBLIC_DISABLE_LIST'); $this->pageTitle['online'] = '在线用户列表'; $this->pageTitle['addUser'] = L('PUBLIC_ADD_USER_INFO'); $this->pageTitle['editUser'] = L('PUBLIC_EDIT_USER'); $this->pageTitle['addProfileField'] = L('PUBLIC_ADD_FIELD'); $this->pageTitle['editProfileField'] = L('PUBLIC_EDIT_FIELD'); $this->pageTitle['addProfileCategory'] = L('PUBLIC_ADD_FIELD_CLASSIFICATION'); $this->pageTitle['editProfileCategory'] = L('PUBLIC_EDITCATEOGRY'); $this->pageTitle['verify'] = '待认证用户'; $this->pageTitle['verifyGroup'] = '待认证企业';
/** * 单个调用钩子 * @param string $addonsName 插件名称 * @param string $name 钩子名称 * @param array $param 相关参数 * @param boolean $admin 是否是管理员 * @return void */ public static function addonsHook($addonsName, $name, $param = array(), $admin = false) { if (!$addonsName) { return; } $addonsName = basename($addonsName); $dirName = ADDON_PATH . '/plugin'; $urlDir = SITE_URL . '/addons/plugin'; $path = $dirName . '/' . $addonsName; $addonUrl = $urlDir . '/' . $addonsName; $adminHooks = array(); if (isset(self::$addonsObj[$addonsName])) { $obj = self::$addonsObj[$addonsName]; } else { $filename = $path . '/' . $addonsName . 'Addons.class.php'; tsload($filename); $className = $addonsName . 'Addons'; if (!class_exists($className)) { die('不存在该类'); } $obj = new $className(); $obj->setPath($path); $obj->setUrl($addonUrl); self::$addonsObj[$addonsName] = $addonsName; } $simple = $obj instanceof SimpleAddons; $adminHooks = $obj->adminMenu(); if (!$admin && isset($adminHooks[$name])) { throw new ThinkException('非法操作,该操作只允许管理员操作'); } if ($simple) { $obj->{$name}($param); } else { $list = self::$validHooks[$name]; foreach ($list[$addonsName] as $hooks) { if (isset(self::$hooksObj[$hooks])) { self::$hooksObj[$hooks]->{$name}($param); } else { $filename = $dirName . '/' . $addonsName . '/hooks/' . $hooks . '.class.php'; tsload($filename); $tempObj = new $hooks(); self::$hooksObj[$hooks] = $tempObj; $tempObj->setPath($path); $tempObj->setPath($obj->getUrl(), true); $tempObj->{$name}($param); } } // foreach } }