From 202a13a47fe7ec257f76fb99040af8ac6327b6d1 Mon Sep 17 00:00:00 2001 From: molong Date: Wed, 29 Jun 2016 21:23:48 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E8=B0=83=E6=95=B4=20bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 63 +- application/admin/controller/Addons.php | 22 +- application/common/model/Hooks.php | 15 +- application/database.php | 2 +- application/index/view/index/index.html | 216 +- application/user/lang/zh-cn.php | 12 + application/user/view/login/find.html | 140 + application/user/view/login/forget.html | 126 + {extend => core/extend}/com/Auth.php | 0 {extend => core/extend}/com/Database.php | 0 {extend => core/extend}/com/Datatable.php | 0 core/extend/com/Email.php | 2343 +++++++++++++++++ {extend => core/extend}/com/Sent.php | 0 {extend => core/extend}/com/Tree.php | 0 {extend => core/extend}/com/Ueditor.php | 0 {extend => core/extend}/org/Crypt.php | 0 {extend => core/extend}/org/Image.php | 0 {extend => core/extend}/org/Oauth.php | 0 {extend => core/extend}/org/Parser.php | 0 {extend => core/extend}/org/Transform.php | 0 {extend => core/extend}/org/Upload.php | 0 {extend => core/extend}/org/Verify.php | 0 .../extend}/org/image/driver/Gd.php | 0 .../extend}/org/image/driver/Gif.php | 0 .../extend}/org/image/driver/Imagick.php | 0 {extend => core/extend}/org/oauth/Driver.php | 0 .../extend}/org/oauth/driver/Diandian.php | 0 .../extend}/org/oauth/driver/Douban.php | 0 .../extend}/org/oauth/driver/Github.php | 0 .../extend}/org/oauth/driver/Google.php | 0 .../extend}/org/oauth/driver/Kaixin.php | 0 .../extend}/org/oauth/driver/Msn.php | 0 .../extend}/org/oauth/driver/Qq.php | 0 .../extend}/org/oauth/driver/Renren.php | 0 .../extend}/org/oauth/driver/Sina.php | 0 .../extend}/org/oauth/driver/Sohu.php | 0 .../extend}/org/oauth/driver/T163.php | 0 .../extend}/org/oauth/driver/Taobao.php | 0 .../extend}/org/oauth/driver/Tencent.php | 0 .../extend}/org/oauth/driver/X360.php | 0 .../extend}/org/parser/driver/Markdown.php | 0 .../extend}/org/parser/driver/Ubb.php | 0 .../extend}/org/transform/driver/Base64.php | 0 .../extend}/org/transform/driver/Json.php | 0 .../extend}/org/transform/driver/Xml.php | 0 .../extend}/org/upload/driver/Ftp.php | 0 .../extend}/org/upload/driver/Local.php | 0 .../extend}/org/upload/driver/Qiniu.php | 0 .../extend}/org/upload/driver/Sae.php | 0 .../extend}/org/upload/driver/Upyun.php | 0 .../org/upload/driver/qiniu/QiniuStorage.php | 0 {extend => core/extend}/org/verify/bgs/1.jpg | Bin {extend => core/extend}/org/verify/bgs/2.jpg | Bin {extend => core/extend}/org/verify/bgs/3.jpg | Bin {extend => core/extend}/org/verify/bgs/4.jpg | Bin {extend => core/extend}/org/verify/bgs/5.jpg | Bin {extend => core/extend}/org/verify/bgs/6.jpg | Bin {extend => core/extend}/org/verify/bgs/7.jpg | Bin {extend => core/extend}/org/verify/bgs/8.jpg | Bin {extend => core/extend}/org/verify/ttfs/1.ttf | Bin {extend => core/extend}/org/verify/ttfs/2.ttf | Bin {extend => core/extend}/org/verify/ttfs/3.ttf | Bin {extend => core/extend}/org/verify/ttfs/4.ttf | Bin {extend => core/extend}/org/verify/ttfs/5.ttf | Bin {extend => core/extend}/org/verify/ttfs/6.ttf | Bin .../extend}/org/verify/zhttfs/1.ttf | Bin core/library/think/db/Query.php | 34 +- core/vendor/.gitignore | 0 data/sql.sql | 338 ++- index.php | 10 + public/images/logo.png | Bin 5489 -> 54121 bytes public/images/slogo.png | Bin 5489 -> 11207 bytes 72 files changed, 3155 insertions(+), 166 deletions(-) create mode 100644 application/user/lang/zh-cn.php create mode 100644 application/user/view/login/find.html create mode 100644 application/user/view/login/forget.html rename {extend => core/extend}/com/Auth.php (100%) rename {extend => core/extend}/com/Database.php (100%) rename {extend => core/extend}/com/Datatable.php (100%) create mode 100644 core/extend/com/Email.php rename {extend => core/extend}/com/Sent.php (100%) rename {extend => core/extend}/com/Tree.php (100%) rename {extend => core/extend}/com/Ueditor.php (100%) rename {extend => core/extend}/org/Crypt.php (100%) rename {extend => core/extend}/org/Image.php (100%) rename {extend => core/extend}/org/Oauth.php (100%) rename {extend => core/extend}/org/Parser.php (100%) rename {extend => core/extend}/org/Transform.php (100%) rename {extend => core/extend}/org/Upload.php (100%) rename {extend => core/extend}/org/Verify.php (100%) rename {extend => core/extend}/org/image/driver/Gd.php (100%) rename {extend => core/extend}/org/image/driver/Gif.php (100%) rename {extend => core/extend}/org/image/driver/Imagick.php (100%) rename {extend => core/extend}/org/oauth/Driver.php (100%) rename {extend => core/extend}/org/oauth/driver/Diandian.php (100%) rename {extend => core/extend}/org/oauth/driver/Douban.php (100%) rename {extend => core/extend}/org/oauth/driver/Github.php (100%) rename {extend => core/extend}/org/oauth/driver/Google.php (100%) rename {extend => core/extend}/org/oauth/driver/Kaixin.php (100%) rename {extend => core/extend}/org/oauth/driver/Msn.php (100%) rename {extend => core/extend}/org/oauth/driver/Qq.php (100%) rename {extend => core/extend}/org/oauth/driver/Renren.php (100%) rename {extend => core/extend}/org/oauth/driver/Sina.php (100%) rename {extend => core/extend}/org/oauth/driver/Sohu.php (100%) rename {extend => core/extend}/org/oauth/driver/T163.php (100%) rename {extend => core/extend}/org/oauth/driver/Taobao.php (100%) rename {extend => core/extend}/org/oauth/driver/Tencent.php (100%) rename {extend => core/extend}/org/oauth/driver/X360.php (100%) rename {extend => core/extend}/org/parser/driver/Markdown.php (100%) rename {extend => core/extend}/org/parser/driver/Ubb.php (100%) rename {extend => core/extend}/org/transform/driver/Base64.php (100%) rename {extend => core/extend}/org/transform/driver/Json.php (100%) rename {extend => core/extend}/org/transform/driver/Xml.php (100%) rename {extend => core/extend}/org/upload/driver/Ftp.php (100%) rename {extend => core/extend}/org/upload/driver/Local.php (100%) rename {extend => core/extend}/org/upload/driver/Qiniu.php (100%) rename {extend => core/extend}/org/upload/driver/Sae.php (100%) rename {extend => core/extend}/org/upload/driver/Upyun.php (100%) rename {extend => core/extend}/org/upload/driver/qiniu/QiniuStorage.php (100%) rename {extend => core/extend}/org/verify/bgs/1.jpg (100%) rename {extend => core/extend}/org/verify/bgs/2.jpg (100%) rename {extend => core/extend}/org/verify/bgs/3.jpg (100%) rename {extend => core/extend}/org/verify/bgs/4.jpg (100%) rename {extend => core/extend}/org/verify/bgs/5.jpg (100%) rename {extend => core/extend}/org/verify/bgs/6.jpg (100%) rename {extend => core/extend}/org/verify/bgs/7.jpg (100%) rename {extend => core/extend}/org/verify/bgs/8.jpg (100%) rename {extend => core/extend}/org/verify/ttfs/1.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/2.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/3.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/4.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/5.ttf (100%) rename {extend => core/extend}/org/verify/ttfs/6.ttf (100%) rename {extend => core/extend}/org/verify/zhttfs/1.ttf (100%) create mode 100644 core/vendor/.gitignore diff --git a/README.md b/README.md index 7a1baf85..e14c6b3a 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,10 @@ -## SentCMS介绍 -> SentCMS网站管理系统是南昌腾速科技有限公司倾力打造的一款简单易用的网站管理系统,SentCMS网站管理系统(下文简称SentCMS)继承了thinkphp5.0的优秀品质,秉承“大道至简”的设计理念。SnetCMS为网站建设而生,为网站建设减少90%的代码编写,只需前端设计师就可以设计出完美的网站,而如此完美的系统还是完全开源的。 +>[danger] #### SentCMS网站管理系统是南昌腾速科技有限公司倾力打造的一款简单易用的网站管理系统,SentCMS网站管理系统(下文简称SentCMS)继承了thinkphp5.0的优秀品质,秉承“大道至简”的设计理念。SnetCMS为网站建设而生,为网站建设减少90%的代码编写,只需前端设计师就可以设计出完美的网站,而如此完美的系统还是完全开源的。 -## SentCMS特性包括: +SentCMS特性包括: * 全新的路由体系,完美的路由解决方案 * 全新的系统架构,采用thinkphp5.0内核框架 * 完善而健全的会员体系 * 健全的权限系统,权限细化到界面上的按钮和链接 * 漂亮的后台界面,后台界面采用世界领先的前端框架bootstrap,自适应的体验 * 简单易用的标签体系 -* 便捷的文档系统,无需程序即可设计出完美的模型,做出完美的网站 - -下载最新版框架后,解压缩到web目录下面,可以看到初始的目录结构如下: -## 目录结构 -~~~ -├─addons 扩展插件目录 -├─application 项目目录文件 -│ ├─admin 网站后台模型 -│ │ ├─controller -│ │ ├─static -│ │ ├─view -│ │ ├─config.php -│ ├─api API接口模型 -│ │ ├─controller -│ │ ├─static -│ │ ├─view -│ │ ├─config.php -│ ├─common COMMON公共模型,不可访问 -│ │ ├─controller -│ │ ├─static -│ │ ├─view -│ │ ├─config.php -│ ├─index 前台模型 -│ │ ├─controller -│ │ ├─static -│ │ ├─view -│ │ ├─config.php -│ ├─user 用户中心模型 -│ │ ├─controller -│ │ ├─static -│ │ ├─view -│ │ ├─config.php -│ ├─common.php 公共函数库文件 -│ ├─config.php 基础配置文件 -│ ├─database.php 数据库配置文件 -│ ├─route.php 路由配置文件 -│ ├─tags.php 行为扩展配置文件 -│ ├─ueditor.json 编辑配置文件 -├─core thinkphp框架目录 -├─data 缓存以及备份目录 -├─extend 扩展类库目录(后期可能会变更目录) -├─public 公共资源库 -├─uploads 上传文件目录 -├─.htaccess Apache下伪静态文件 -├─favicon.ico ico图标 -├─index.php 入口文件 -├─README.md 系统介绍文件 -~~~ - -## 安装 - -目前暂无安装文件,可按以下方法安装: - -* 第一步、修改数据库配置文件 application/database.php -* 第二步、通过数据库导入工具,比如phpmyadmin导入数据,数据sql文件data/sql.sql - -初始账号:admin,密码:admin888 \ No newline at end of file +* 便捷的文档系统,无需程序即可设计出完美的模型,做出完美的网站 \ No newline at end of file diff --git a/application/admin/controller/Addons.php b/application/admin/controller/Addons.php index d8ce7b37..611bc8eb 100644 --- a/application/admin/controller/Addons.php +++ b/application/admin/controller/Addons.php @@ -244,14 +244,9 @@ class Addons extends Admin { public function addhook(){ $hooks = model('Hooks'); if (IS_POST) { - $data = input(); - if ($data) { - $result = $hooks->change($data); - if ($result !== false) { - return $this->success("修改成功"); - }else{ - return $this->error($hooks->getError()); - } + $result = $hooks->change(); + if ($result !== false) { + return $this->success("修改成功"); }else{ return $this->error($hooks->getError()); } @@ -270,14 +265,9 @@ class Addons extends Admin { public function edithook($id){ $hooks = model('Hooks'); if (IS_POST) { - $data = input('post.'); - if ($data) { - $result = $hooks->change($data); - if ($result !== false) { - return $this->success("修改成功"); - }else{ - return $this->error($hooks->getError()); - } + $result = $hooks->change(); + if ($result !== false) { + return $this->success("修改成功"); }else{ return $this->error($hooks->getError()); } diff --git a/application/common/model/Hooks.php b/application/common/model/Hooks.php index ffe20730..e20d895f 100644 --- a/application/common/model/Hooks.php +++ b/application/common/model/Hooks.php @@ -64,19 +64,6 @@ class Hooks extends Base { return $keylist; } - public function change($data){ - if (!empty($data)) { - if ($data['id']) { - $this->save($data,array('id'=>$data['id'])); - }else{ - $this->save($data); - } - }else{ - $this->error = "非法操作!"; - return false; - } - } - public function addHooks($addons_name){ $addons_class = get_addon_class($addons_name);//获取插件名 if(!class_exists($addons_class)){ @@ -94,5 +81,5 @@ class Hooks extends Base { return false; } $methods = get_class_methods($addons_class); - } + } } \ No newline at end of file diff --git a/application/database.php b/application/database.php index 40c193b7..ef2a84d1 100644 --- a/application/database.php +++ b/application/database.php @@ -19,7 +19,7 @@ return array( // 数据库用户名 'username' => 'root', // 数据库密码 - 'password' => '', + 'password' => 'nitbbs_org', // 数据库连接端口 'hostport' => '', // 数据库连接参数 diff --git a/application/index/view/index/index.html b/application/index/view/index/index.html index f836f74a..9be16609 100644 --- a/application/index/view/index/index.html +++ b/application/index/view/index/index.html @@ -1,14 +1,202 @@ - - - - -SentCMS3.0网站管理系统 - - - - - \ No newline at end of file +{extend name="public/base"/} +{block name="banner"} +{:ad('banner')} +{/block} +{block name="body"} +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +
+
+
+ + + 科研成果 + Scientific research work + + 更多>> +
+
+ +
+
+
+
+ + + 科研工作 + Scientific research work + + 更多>> +
+
+ +
+
+
+
+ + + 科研动态 + Scientific research work + + 更多>> +
+
+ +
+
+
+
+ + + 国外文献 + Scientific research work + + 更多>> +
+
+ +
+
+
+
+ + +
+
+ 在线图书 +
+ +
    + +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    + + +
    +
    + 本院新闻 +
    +
    + + 查看更多>> +
    +
    + + +
    +
    + 通知公告 +
    +
    + + 查看更多>> +
    +
    + + +
    +
    + 常用链接 +
    +
    + +
    +
    +
    +
    +{/block} \ No newline at end of file diff --git a/application/user/lang/zh-cn.php b/application/user/lang/zh-cn.php new file mode 100644 index 00000000..37fcf19b --- /dev/null +++ b/application/user/lang/zh-cn.php @@ -0,0 +1,12 @@ + +// +---------------------------------------------------------------------- + +return array( + 'find_password' => '您的找回密码确认地址为:{:url}', +); \ No newline at end of file diff --git a/application/user/view/login/find.html b/application/user/view/login/find.html new file mode 100644 index 00000000..41401003 --- /dev/null +++ b/application/user/view/login/find.html @@ -0,0 +1,140 @@ + + + + + + +找回密码 + + + + + + + + +
    +
    +

    + +

    + +
    +
    + + + + + + + \ No newline at end of file diff --git a/application/user/view/login/forget.html b/application/user/view/login/forget.html new file mode 100644 index 00000000..d3910e15 --- /dev/null +++ b/application/user/view/login/forget.html @@ -0,0 +1,126 @@ + + + + + + +找回密码 + + + + + + + + +
    +
    +

    + +

    + +
    +
    + + + + + + + \ No newline at end of file diff --git a/extend/com/Auth.php b/core/extend/com/Auth.php similarity index 100% rename from extend/com/Auth.php rename to core/extend/com/Auth.php diff --git a/extend/com/Database.php b/core/extend/com/Database.php similarity index 100% rename from extend/com/Database.php rename to core/extend/com/Database.php diff --git a/extend/com/Datatable.php b/core/extend/com/Datatable.php similarity index 100% rename from extend/com/Datatable.php rename to core/extend/com/Datatable.php diff --git a/core/extend/com/Email.php b/core/extend/com/Email.php new file mode 100644 index 00000000..07737810 --- /dev/null +++ b/core/extend/com/Email.php @@ -0,0 +1,2343 @@ + '1 (Highest)', + 2 => '2 (High)', + 3 => '3 (Normal)', + 4 => '4 (Low)', + 5 => '5 (Lowest)' + ); + + // -------------------------------------------------------------------- + + /** + * Constructor - Sets Email Preferences + * + * The constructor can be passed an array of config values + * + * @param array $config = array() + * @return void + */ + public function __construct(array $config = array()) + { + $this->charset = \think\Config::get('charset'); + + if (count($config) > 0) + { + $this->initialize($config); + } + else + { + $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === ''); + } + + $this->_safe_mode = ( ! version_compare("5.4", PHP_VERSION, ">") && ini_get('safe_mode')); + $this->charset = strtoupper($this->charset); + + \think\Log::write('Email Class Initialized', 'info'); + } + + // -------------------------------------------------------------------- + + /** + * Destructor - Releases Resources + * + * @return void + */ + public function __destruct() + { + if (is_resource($this->_smtp_connect)) + { + $this->_send_command('quit'); + } + } + + // -------------------------------------------------------------------- + + /** + * Initialize preferences + * + * @param array + * @return CI_Email + */ + public function initialize($config = array()) + { + foreach ($config as $key => $val) + { + if (isset($this->$key)) + { + $method = 'set_'.$key; + + if (method_exists($this, $method)) + { + $this->$method($val); + } + else + { + $this->$key = $val; + } + } + } + $this->clear(); + + $this->_smtp_auth = ! ($this->smtp_user === '' && $this->smtp_pass === ''); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Initialize the Email Data + * + * @param bool + * @return CI_Email + */ + public function clear($clear_attachments = FALSE) + { + $this->_subject = ''; + $this->_body = ''; + $this->_finalbody = ''; + $this->_header_str = ''; + $this->_replyto_flag = FALSE; + $this->_recipients = array(); + $this->_cc_array = array(); + $this->_bcc_array = array(); + $this->_headers = array(); + $this->_debug_msg = array(); + + $this->set_header('User-Agent', $this->useragent); + $this->set_header('Date', $this->_set_date()); + + if ($clear_attachments !== FALSE) + { + $this->_attachments = array(); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set FROM + * + * @param string $from + * @param string $name + * @param string $return_path = NULL Return-Path + * @return CI_Email + */ + public function from($from, $name = '', $return_path = NULL) + { + if (preg_match('/\<(.*)\>/', $from, $match)) + { + $from = $match[1]; + } + + if ($this->validate) + { + $this->validate_email($this->_str_to_array($from)); + if ($return_path) + { + $this->validate_email($this->_str_to_array($return_path)); + } + } + + // prepare the display name + if ($name !== '') + { + // only use Q encoding if there are characters that would require it + if ( ! preg_match('/[\200-\377]/', $name)) + { + // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes + $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; + } + else + { + $name = $this->_prep_q_encoding($name); + } + } + + $this->set_header('From', $name.' <'.$from.'>'); + + isset($return_path) OR $return_path = $from; + $this->set_header('Return-Path', '<'.$return_path.'>'); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Reply-to + * + * @param string + * @param string + * @return CI_Email + */ + public function reply_to($replyto, $name = '') + { + if (preg_match('/\<(.*)\>/', $replyto, $match)) + { + $replyto = $match[1]; + } + + if ($this->validate) + { + $this->validate_email($this->_str_to_array($replyto)); + } + + if ($name !== '') + { + // only use Q encoding if there are characters that would require it + if ( ! preg_match('/[\200-\377]/', $name)) + { + // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes + $name = '"'.addcslashes($name, "\0..\37\177'\"\\").'"'; + } + else + { + $name = $this->_prep_q_encoding($name); + } + } + + $this->set_header('Reply-To', $name.' <'.$replyto.'>'); + $this->_replyto_flag = TRUE; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Recipients + * + * @param string + * @return CI_Email + */ + public function to($to) + { + $to = $this->_str_to_array($to); + $to = $this->clean_email($to); + + if ($this->validate) + { + $this->validate_email($to); + } + + if ($this->_get_protocol() !== 'mail') + { + $this->set_header('To', implode(', ', $to)); + } + + $this->_recipients = $to; + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set CC + * + * @param string + * @return CI_Email + */ + public function cc($cc) + { + $cc = $this->clean_email($this->_str_to_array($cc)); + + if ($this->validate) + { + $this->validate_email($cc); + } + + $this->set_header('Cc', implode(', ', $cc)); + + if ($this->_get_protocol() === 'smtp') + { + $this->_cc_array = $cc; + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set BCC + * + * @param string + * @param string + * @return CI_Email + */ + public function bcc($bcc, $limit = '') + { + if ($limit !== '' && is_numeric($limit)) + { + $this->bcc_batch_mode = TRUE; + $this->bcc_batch_size = $limit; + } + + $bcc = $this->clean_email($this->_str_to_array($bcc)); + + if ($this->validate) + { + $this->validate_email($bcc); + } + + if ($this->_get_protocol() === 'smtp' OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) + { + $this->_bcc_array = $bcc; + } + else + { + $this->set_header('Bcc', implode(', ', $bcc)); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Email Subject + * + * @param string + * @return CI_Email + */ + public function subject($subject) + { + $subject = $this->_prep_q_encoding($subject); + $this->set_header('Subject', $subject); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Body + * + * @param string + * @return CI_Email + */ + public function message($body) + { + $this->_body = rtrim(str_replace("\r", '', $body)); + + /* strip slashes only if magic quotes is ON + if we do it with magic quotes OFF, it strips real, user-inputted chars. + + NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and + it will probably not exist in future versions at all. + */ + if ( ! version_compare("5.4", PHP_VERSION, ">") && get_magic_quotes_gpc()) + { + $this->_body = stripslashes($this->_body); + } + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Assign file attachments + * + * @param string $file Can be local path, URL or buffered content + * @param string $disposition = 'attachment' + * @param string $newname = NULL + * @param string $mime = '' + * @return CI_Email + */ + public function attach($file, $disposition = '', $newname = NULL, $mime = '') + { + if ($mime === '') + { + if (strpos($file, '://') === FALSE && ! file_exists($file)) + { + $this->_set_error_message('lang:email_attachment_missing', $file); + return FALSE; + } + + if ( ! $fp = @fopen($file, 'rb')) + { + $this->_set_error_message('lang:email_attachment_unreadable', $file); + return FALSE; + } + + $file_content = stream_get_contents($fp); + $mime = $this->_mime_types(pathinfo($file, PATHINFO_EXTENSION)); + fclose($fp); + } + else + { + $file_content =& $file; // buffered file + } + + $this->_attachments[] = array( + 'name' => array($file, $newname), + 'disposition' => empty($disposition) ? 'attachment' : $disposition, // Can also be 'inline' Not sure if it matters + 'type' => $mime, + 'content' => chunk_split(base64_encode($file_content)) + ); + + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set and return attachment Content-ID + * + * Useful for attached inline pictures + * + * @param string $filename + * @return string + */ + public function attachment_cid($filename) + { + if ($this->multipart !== 'related') + { + $this->multipart = 'related'; // Thunderbird need this for inline images + } + + for ($i = 0, $c = count($this->_attachments); $i < $c; $i++) + { + if ($this->_attachments[$i]['name'][0] === $filename) + { + $this->_attachments[$i]['cid'] = uniqid(basename($this->_attachments[$i]['name'][0]).'@'); + return $this->_attachments[$i]['cid']; + } + } + + return FALSE; + } + + // -------------------------------------------------------------------- + + /** + * Add a Header Item + * + * @param string + * @param string + * @return CI_Email + */ + public function set_header($header, $value) + { + $this->_headers[$header] = str_replace(array("\n", "\r"), '', $value); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Convert a String to an Array + * + * @param string + * @return array + */ + protected function _str_to_array($email) + { + if ( ! is_array($email)) + { + return (strpos($email, ',') !== FALSE) + ? preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY) + : (array) trim($email); + } + + return $email; + } + + // -------------------------------------------------------------------- + + /** + * Set Multipart Value + * + * @param string + * @return CI_Email + */ + public function set_alt_message($str) + { + $this->alt_message = (string) $str; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Mailtype + * + * @param string + * @return CI_Email + */ + public function set_mailtype($type = 'text') + { + $this->mailtype = ($type === 'html') ? 'html' : 'text'; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Wordwrap + * + * @param bool + * @return CI_Email + */ + public function set_wordwrap($wordwrap = TRUE) + { + $this->wordwrap = (bool) $wordwrap; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Protocol + * + * @param string + * @return CI_Email + */ + public function set_protocol($protocol = 'mail') + { + $this->protocol = in_array($protocol, $this->_protocols, TRUE) ? strtolower($protocol) : 'mail'; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Priority + * + * @param int + * @return CI_Email + */ + public function set_priority($n = 3) + { + $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Newline Character + * + * @param string + * @return CI_Email + */ + public function set_newline($newline = "\n") + { + $this->newline = in_array($newline, array("\n", "\r\n", "\r")) ? $newline : "\n"; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set CRLF + * + * @param string + * @return CI_Email + */ + public function set_crlf($crlf = "\n") + { + $this->crlf = ($crlf !== "\n" && $crlf !== "\r\n" && $crlf !== "\r") ? "\n" : $crlf; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set Message Boundary + * + * @return void + */ + protected function _set_boundaries() + { + $this->_alt_boundary = 'B_ALT_'.uniqid(''); // multipart/alternative + $this->_atc_boundary = 'B_ATC_'.uniqid(''); // attachment boundary + } + + // -------------------------------------------------------------------- + + /** + * Get the Message ID + * + * @return string + */ + protected function _get_message_id() + { + $from = str_replace(array('>', '<'), '', $this->_headers['Return-Path']); + return '<'.uniqid('').strstr($from, '@').'>'; + } + + // -------------------------------------------------------------------- + + /** + * Get Mail Protocol + * + * @param bool + * @return mixed + */ + protected function _get_protocol($return = TRUE) + { + $this->protocol = strtolower($this->protocol); + in_array($this->protocol, $this->_protocols, TRUE) OR $this->protocol = 'mail'; + + if ($return === TRUE) + { + return $this->protocol; + } + } + + // -------------------------------------------------------------------- + + /** + * Get Mail Encoding + * + * @param bool + * @return string + */ + protected function _get_encoding($return = TRUE) + { + in_array($this->_encoding, $this->_bit_depths) OR $this->_encoding = '8bit'; + + foreach ($this->_base_charsets as $charset) + { + if (strpos($charset, $this->charset) === 0) + { + $this->_encoding = '7bit'; + } + } + + if ($return === TRUE) + { + return $this->_encoding; + } + } + + // -------------------------------------------------------------------- + + /** + * Get content type (text/html/attachment) + * + * @return string + */ + protected function _get_content_type() + { + if ($this->mailtype === 'html') + { + return (count($this->_attachments) === 0) ? 'html' : 'html-attach'; + } + elseif ($this->mailtype === 'text' && count($this->_attachments) > 0) + { + return 'plain-attach'; + } + else + { + return 'plain'; + } + } + + // -------------------------------------------------------------------- + + /** + * Set RFC 822 Date + * + * @return string + */ + protected function _set_date() + { + $timezone = date('Z'); + $operator = ($timezone[0] === '-') ? '-' : '+'; + $timezone = abs($timezone); + $timezone = floor($timezone/3600) * 100 + ($timezone % 3600) / 60; + + return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone); + } + + // -------------------------------------------------------------------- + + /** + * Mime message + * + * @return string + */ + protected function _get_mime_message() + { + return 'This is a multi-part message in MIME format.'.$this->newline.'Your email application may not support this format.'; + } + + // -------------------------------------------------------------------- + + /** + * Validate Email Address + * + * @param string + * @return bool + */ + public function validate_email($email) + { + if ( ! is_array($email)) + { + $this->_set_error_message('lang:email_must_be_array'); + return FALSE; + } + + foreach ($email as $val) + { + if ( ! $this->valid_email($val)) + { + $this->_set_error_message('lang:email_invalid_address', $val); + return FALSE; + } + } + + return TRUE; + } + + // -------------------------------------------------------------------- + + /** + * Email Validation + * + * @param string + * @return bool + */ + public function valid_email($email) + { + if (function_exists('idn_to_ascii') && $atpos = strpos($email, '@')) + { + $email = substr($email, 0, ++$atpos).idn_to_ascii(substr($email, $atpos)); + } + + return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); + } + + // -------------------------------------------------------------------- + + /** + * Clean Extended Email Address: Joe Smith + * + * @param string + * @return string + */ + public function clean_email($email) + { + if ( ! is_array($email)) + { + return preg_match('/\<(.*)\>/', $email, $match) ? $match[1] : $email; + } + + $clean_email = array(); + + foreach ($email as $addy) + { + $clean_email[] = preg_match('/\<(.*)\>/', $addy, $match) ? $match[1] : $addy; + } + + return $clean_email; + } + + // -------------------------------------------------------------------- + + /** + * Build alternative plain text message + * + * Provides the raw message for use in plain-text headers of + * HTML-formatted emails. + * If the user hasn't specified his own alternative message + * it creates one by stripping the HTML + * + * @return string + */ + protected function _get_alt_message() + { + if ( ! empty($this->alt_message)) + { + return ($this->wordwrap) + ? $this->word_wrap($this->alt_message, 76) + : $this->alt_message; + } + + $body = preg_match('/\(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body; + $body = str_replace("\t", '', preg_replace('#