/** * 设置上传驱动 * @param string $class 驱动类名称 */ private function setDriver($class) { //引入上传驱动文件 Yaf_loader::import("Upload/Driver/" . $class . ".php"); //上传驱动实例 $this->uploader = new $class($this->rootPath); //不存在此驱动 if (!$this->uploader) { } }
/** * 日志直接写入 * @static * @access public * @param string $message 日志信息 * @param string $level 日志级别 * @param integer $type 日志记录方式 * @param string $destination 写入目标 * @return void */ static function write($message, $level = self::ERR, $type = '', $destination = '') { //获取上传配置 $options = Yaf_Registry::get('logbase'); //日志目录 $log_path = !empty(self::$log_path) ? self::$log_path : $options['path']; if (!self::$storage) { $type = $type ? $type : $options['type']; $class = ucwords($type); Yaf_loader::import("Log/Driver/" . $class . ".php"); self::$storage = new $class(); } if (empty($destination)) { $destination = $log_path . date('y_m_d') . '.log'; } self::$storage->write("{$level}: {$message}", $destination); }
/** * 连接缓存 * @access public * @param string $type 缓存类型 * @param array $options 配置数组 * @return object */ public function connect($type = '', $options = array()) { if (empty($options)) { $options = Yaf_Registry::get('cachebase'); } if (empty($type)) { $type = $options['type']; } $class = strpos($type, '\\') ? $type : ucwords(strtolower($type)); //要载入的文件路径, 可以为绝对路径和相对路径. 如果为相对路径, 则会以应用的本地类目录(ap.library)为基目录 Yaf_loader::import("Cache/Driver/" . $class . ".php"); $class_name = $class . "_session"; // if(class_exists($class_name)) $cache = new $class_name($options); // else // trigger_error('not found this cache class',E_USER_ERROR); return $cache; }
public function handleAvatarAction() { header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); Yaf_Dispatcher::getInstance()->disableView(); if ($this->getRequest()->isGet()) { $this->notify("页面不存在"); die; } $current = date("Y-m"); $upfile_dir = APP_PATH . "/public/Uploads/Face/" . $current . "/"; if (!is_dir($upfile_dir)) { mkdir($upfile_dir, true); } $raw_post_data = file_get_contents('php://input', 'r'); //$raw_post_data = fopen('php://input', 'r'); $pic_tmp_name = "tbl" . substr(md5(time()), 0, 10); $pic_name = $pic_tmp_name . ".png"; $face = $upfile_dir . $pic_name; file_put_contents($face, $raw_post_data); //Helper::import('Img'); //Helper::import('File'); //createThumb($face,$upfile_dir,$pic_tmp_name,600,600); Yaf_loader::import(LIB_PATH . '/L_Image.class.php'); $new_pic = $upfile_dir . $pic_tmp_name . ".jpg"; //image_png_size_add($face,$new_pic); L_Image::thumb($face, $new_pic, 150, 150); $face_dir = str_replace(APP_PATH . "/public", "", $new_pic); @unlink($face); $this->m_user->UpdateByID(array("avatar" => $face_dir), $this->uid); }
public function _initLoader() { $loader = Yaf_loader::getInstance(); $loader->registerLocalNamespace(array('Db', 'Model', 'View', 'Controller', 'Helper')); //$loader->import(APP_PATH.'helpers/function.php'); }
<?php Yaf_loader::import("SDK/getui/IGt.Push.php"); $tConf = Yaf_Registry::get("config")->getui->default; #define('APPKEY','PgpQ1Y0Pl26XZBFJuZOA79'); #define('APPID','9L962lenTk72TOlvz7Z023'); #define('MASTERSECRET','chHjMhADq99Mi8glEe3S81'); define('APPKEY', $tConf['appkey']); define('APPID', $tConf['appid']); define('MASTERSECRET', $tConf['mastersecret']); define('HOST', 'http://sdk.open.api.igexin.com/apiex.htm'); define('taskId', 'OSS-0213_UA9Aq1pG1W97zj1zJ3q0e5'); $tCid = empty($_GET['cid']) ? '' : $_GET['cid']; $tDevicetoken = empty($_GET['devicetoken']) ? '' : $_GET['devicetoken']; $tContent = empty($_GET['content']) ? '' : $_GET['content']; $tTitle = empty($_GET['title']) ? '' : $_GET['title']; $tContent = mb_strcut($tContent, 0, 85, 'utf-8'); $tType = empty($_GET['type']) ? '' : $_GET['type']; $tID = empty($_GET['id']) ? '0' : $_GET['id']; define('CID', $tCid); define('DEVICETOKEN', $tDevicetoken); define('TITLE', $tTitle); define('CONTENT', $tContent); define('TYPE', $tType); #tx 透析提醒 article 文章 define('ID', $tID); class GetuiController extends Ctrl_Base { protected $_auth = 1; public function indexAction() {
/** * 邮件发送函数 * @param string $toMail 接收者邮箱 * @param string $subject 邮件标题 * @param string $body 邮件内容 * @return string $message 发送成功或失败消息 */ function sendMail($to, $title, $content) { Yaf_loader::import(LIB_PATH . '/PHPMailer/PHPMailerAutoload.php'); $config = Yaf_Application::app()->getConfig(); $mail = new PHPMailer(); //实例化 $mail->IsSMTP(); // 启用SMTP $mail->Host = $config["mail_server"]; //smtp服务器的名称 $mail->SMTPAuth = true; //启用smtp认证 $mail->Username = $config['mail_user']; //你的邮箱名 $mail->Password = $config['mail_password']; //邮箱密码 $mail->From = $config['mail_from']; //发件人地址(也就是你的邮箱地址) $mail->FromName = $config['mail_name']; //发件人姓名 $mail->AddAddress($to); $mail->WordWrap = 50; //设置每行字符长度 $mail->IsHTML(true); // 是否HTML格式邮件 $mail->CharSet = "utf-8"; //设置邮件编码 $mail->Subject = $title; //邮件主题 $mail->Body = $content; //邮件内容 $mail->AltBody = $content; //邮件正文不支持HTML的备用显示 return $mail->Send(); }
public function handleUploadImgAction() { Yaf_Dispatcher::getInstance()->disableView(); Yaf_loader::import(LIB_PATH . '/L_Upload.class.php'); $obj = new L_Upload(); //实例化上传类 $obj->maxSize = 1000000; //图片最大上传大小 $obj->savePath = getcwd() . '/Uploads/new/'; //图片保存路径 $obj->saveRule = 'uniqid'; //保存文件名 $obj->uploadReplace = true; //是否覆盖同名文件 是 $obj->allowExts = array(0 => 'jpg', 1 => 'jpeg', 2 => 'gif', 3 => 'png'); //允许上传文件后缀名 $obj->thumb = false; //生成缩略图 $obj->autoSub = true; //使用子目录保存上传文件 $obj->subType = 'date'; //使用日期为子目录名称 $obj->dateFormat = 'Y_m_d'; //使用年-月形式 if (!$obj->upload()) { echo json_encode(array('status' => 0, 'msg' => $obj->getErrorMsg())); die; } else { $info = $obj->getUploadFileInfo(); $pic = explode('/', $info[0]['savename']); $return = array('status' => 1, 'path' => '/Uploads/new/' . $pic[0] . '/' . $pic[1]); //压缩图片 image_png_size_add(getcwd() . '/Uploads/new/' . $pic[0] . '/' . $pic[1], getcwd() . '/Uploads/new/' . $pic[0] . '/' . $pic[1]); echo json_encode($return); die; } }
/** * 邮件发送函数 * @param string $toMail 接收者邮箱 * @param string $subject 邮件标题 * @param string $body 邮件内容 * @return string $message 发送成功或失败消息 */ function sendMail($toMail, $subject, $body) { Yaf_loader::import(LIB_PATH . '/PHPMailer/class.phpmailer.php'); Yaf_Loader::import(LIB_PATH . '/PHPMailer/class.smtp.php'); $config = Yaf_Application::app()->getConfig(); $mail = new PHPMailer(); if (1 == $config['mail_type']) { $mail->IsSMTP(); // 经smtp发送 $mail->SMTPAuth = true; // 打开SMTP 认证 $mail->Host = $config['mail_server']; // SMTP 服务器 $mail->Port = $config['mail_port']; // SMTP 端口 $mail->Username = $config['mail_user']; // 用户名 $mail->Password = $config['mail_password']; // 密码 $mail->From = $config['mail_from']; // 发信人 $mail->FromName = $config['mail_name']; // 发信人别名 } else { $mail->IsSendmail(); // 系统自带的 SENDMAIL 发送 $mail->From = $config['mail_sender']; // 发信人 $mail->FromName = $config['mail_name']; // 发信人别名 $mail->AddAddress($toMail); //设置发件人的姓名 } $mail->AddAddress($toMail); // 收信人 $mail->WordWrap = 50; $mail->CharSet = "utf-8"; $mail->IsHTML(true); // 以html方式发送 $mail->Subject = $subject; // 邮件标题 $mail->Body = $body; // 邮件内空 $mail->AltBody = "请使用HTML方式查看邮件。"; $code = ''; if (!@$mail->Send()) { $code = 0; } else { $code = 1; } return $code; }
public function authAction() { Yaf_Dispatcher::getInstance()->disableView(); $type = parent::get("type", false); if ($type == "qq") { Yaf_loader::import(LIB_PATH . '/L_QqConnect.class.php'); $qqObj = new L_QqConnect(); $info = $qqObj->callback(); $model_user_three = $this->load('user_three'); $user_three = $model_user_three->Where("openid='" . $info["openid"] . "' AND type=0")->SelectOne(); if ($user_three) { $user_info = $this->m_user->Where("id=" . $user_three["user_id"])->Field(array("id", "email"))->SelectOne(); parent::setSession('uid', $user_info["id"]); parent::setSession('email', $user_info["email"]); $this->notify("QQ授权登录成功...", "/member", "success"); die; } else { $user_info = $qqObj->get_user_info($info["token"], $info["openid"]); parent::setSession('openid', $info["openid"]); parent::setSession("token", $info["token"]); parent::setSession("nickname", $user_info["nickname"]); parent::setSession("type", 0); $this->notify("QQ授权成功...", "/login/three", "success"); die; } } else { if ($type == "weibo") { Yaf_loader::import(LIB_PATH . '/L_Weibo.class.php'); $weiboObj = new L_Weibo(); $info = $weiboObj->callback(); $model_user_three = $this->load('user_three'); $user_three = $model_user_three->Where("openid='" . $info["openid"] . "' AND type=1")->SelectOne(); if ($user_three) { $user_info = $this->m_user->Where("id=" . $user_three["user_id"])->Field(array("id", "email"))->SelectOne(); parent::setSession('uid', $user_info["id"]); parent::setSession('email', $user_info["email"]); $this->notify("微博授权登录成功...", "/member", "success"); die; } else { $user_info = $weiboObj->get_user_info($info["token"], $info["openid"]); parent::setSession('openid', $info["openid"]); parent::setSession("token", $info["token"]); parent::setSession("nickname", $user_info["screen_name"]); parent::setSession("type", 1); $this->notify("微博授权成功...", "/login/three", "success"); die; } } else { $this->notify("无效回调的类型", "http://" . $_SERVER["HTTP_HOST"]); die; } } }