信呼OA版本v2.3.8

This commit is contained in:
雨中磐石
2022-08-14 16:47:40 +08:00
parent 4640677d27
commit e3fcd913e3
1405 changed files with 133635 additions and 73 deletions

209
include/Action.php Normal file
View File

@@ -0,0 +1,209 @@
<?php
/**
*****************************************************************
* 联系QQ 290802026/1073744729 *
* 版 本: V2.0 *
* 开发者:雨中磐石工作室 *
* 邮 箱: admin@rockoa.com *
* 网 址: http://www.rockoa.com/ *
* 说 明: 主控制器处理 *
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
*****************************************************************
*/
abstract class mainAction{
public $rock;
public $db;
public $smarty;
public $smartydata = array(); //模版数据
public $assigndata = array();
public $display = true; //是否显示模板
public $bodytitle = ''; //副标题
public $keywords = ''; //关键词
public $description = ''; //说明
public $linkdb = true; //是否连接数据库
public $params = array(); //参数
public $now;
public $date;
public $ip;
public $web;
public $title = TITLE;
public $titles = '';
public $option;
public $jm;
public $table;
public $extentid = 0;
public $importjs = '';
public $perfix = '';
public $tplname = ''; //模板文件
public $tplpath = ''; //模板文件路径
public $tpltype = 'tpl';
public $tpldom = 'html';
public $displayfile = '';
public $bodyMessage = ''; //返回的内容
public function __construct()
{
$this->rock = $GLOBALS['rock'];
$this->smarty = $GLOBALS['smarty'];
$this->jm = c('jm', true);
$_obj = c('lang');if($_obj!=NULL && method_exists($_obj,'initLang'))$_obj->initLang();
$this->now = $this->rock->now();
$this->date = $this->rock->date;
$this->ip = $this->rock->ip;
$this->web = $this->rock->web;
$this->perfix = PREFIX;
$this->display = true;
$this->initMysql();
$this->initConstruct();
$this->initProject();
$this->initAction();
}
public function defaultAction(){}
public function initAction(){}
public function initProject(){}
public function afterAction(){}
public function initMysql(){}
public function beforeAction(){}
public function T($n)
{
return $this->perfix.''.$n;
}
public function assign($k, $v)
{
$this->assigndata[$k]=$v;
}
private function initConstruct()
{
$linkdb = $this->rock->get('linkdb','true');
$this->params = explode('-', $this->rock->get('s')); //参数
if($linkdb == 'true' && $this->linkdb){
$this->initMysqllink();
}
}
private function initMysqllink()
{
$this->db = import(DB_DRIVE);
$GLOBALS['db'] = $this->db;
include_once(''.ROOT_PATH.'/include/Model.php');
$this->option = m('option');
}
private function setBasedata()
{
$this->smartydata['bodytitle'] = $this->bodytitle;
$this->smartydata['keywords'] = $this->keywords;
$this->smartydata['description']= $this->description;
$this->smartydata['title'] = $this->title;
$this->smartydata['titles'] = $this->titles;
$this->smartydata['rewrite'] = REWRITE;
$this->smartydata['now'] = $this->now;
$this->smartydata['web'] = $this->rock->web;
$this->smartydata['ip'] = $this->ip;
$this->smartydata['url'] = URL;
$this->smartydata['urly'] = URLY;
$web = $this->rock->web;
$this->assign('web', $web);
$showheader = 1;
$hide = $this->get('hideheader', $this->getsession('hideheader'));
if($hide=='true')$this->rock->savesession(array('hideheader' => $hide));
if($this->rock->iswebbro(0)
|| $this->rock->iswebbro(1)
|| $this->rock->iswebbro(4)
|| $this->rock->iswebbro(7)
|| $hide=='true'
|| $this->get('headerhide')=='true'
|| $this->rock->iswebbro(2))$showheader = 0; //隐藏头部
if($this->get('showheader')=='true')$showheader = 1;
$this->assign('showheader', $showheader);
}
public function setSmartyData()
{
$this->setBasedata();
}
public function setHtmlData()
{
$this->setBasedata();
}
public function getsession($name,$dev='')
{
return $this->rock->session($name, $dev);
}
public function post($na, $dev='', $lx=0)
{
return $this->rock->post($na, $dev, $lx);
}
public function get($na, $dev='', $lx=0)
{
return $this->rock->get($na, $dev, $lx);
}
public function request($na, $dev='', $lx=0)
{
return $this->rock->request($na, $dev, $lx);
}
public function isempt($str)
{
return $this->rock->isempt($str);
}
public function contain($str, $a)
{
return $this->rock->contain($str, $a);
}
public function getcookie($name, $dev='')
{
return $this->rock->cookie($name, $dev);
}
public function stringformat($str, $arr=array())
{
return $this->rock->stringformat($str, $arr);
}
public function getcan($i,$dev='')
{
$val = '';
if(isset($this->params[$i]))$val=$this->params[$i];
if($this->rock->isempt($val)){
$val=$dev;
}else{
$val=str_replace('[a]','-',$val);
}
return $val;
}
public function getmnumAjax()
{
$mnum = $this->rock->request('mnum');
$rows = $this->option->getmnum($mnum);
echo json_encode($rows);
}
public function returnjson($arr)
{
echo json_encode($arr);
exit();
}
public function showreturn($arr='', $msg='', $code=200)
{
showreturn($arr, $msg, $code);
}
}

47
include/Chajian.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
/**
*****************************************************************
* 联系QQ 290802026/1073744729 *
* 版 本: V2.0 *
* 开发者:雨中磐石工作室 *
* 邮 箱: qqqq2900@126.com *
* 网 址: http://www.rockoa.com/ *
* 说 明: 插件主类 *
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
* 创建时间: 2014-08-30 *
*****************************************************************
*/
abstract class Chajian{
public $rock;
public $db;
public $adminname;
public $adminid;
public function __construct()
{
$this->rock = $GLOBALS['rock'];
$this->db = $GLOBALS['db'];
$this->adminid = $this->rock->adminid;
$this->adminname = $this->rock->adminname;
$this->initChajian();
}
public function __destruct()
{
$this->destChajian();
}
public function isempt($str)
{
return $this->rock->isempt($str);
}
public function contain($str, $s1)
{
return $this->rock->contain($str, $s1);
}
protected function initChajian(){}
protected function destChajian(){}
}

191
include/Model.php Normal file
View File

@@ -0,0 +1,191 @@
<?php
/**
*****************************************************************
* 联系QQ 290802026 *
* 版 本: V2.0 *
* 开发者:雨中磐石工作室 *
* 邮 箱: admin@rockoa.com *
* 网 址: http://www.rockoa.com/ *
* 说 明: 数据模型 *
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
*****************************************************************
*/
abstract class Model{
public $perfix = PREFIX;
public $rock;
public $db;
public $table;
public $adminname;
public $adminid;
public $tempxinxi = array();
public function __construct($table='')
{
$this->rock = $GLOBALS['rock'];
$this->db = $GLOBALS['db'];
$this->adminid = $this->rock->adminid;
$this->adminname = $this->rock->adminname;
$this->settable($table);
$this->initModel();
}
public function settable($table, $qzbo=true)
{
$this->table = ''.$this->perfix.''.$table.'';
if(!$qzbo)$this->table = $table;
}
public function initModel(){}
public function getmou($fields, $where, $order='')
{
return $this->db->getmou($this->table, $fields, $where, $order);
}
public function getone($where, $fields='*', $order='')
{
return $this->db->getone($this->table, $where, $fields, $order);
}
public function getrows($where, $fields='*', $order='', $limit='')
{
return $this->db->getrows($this->table, $where, $fields, $order, $limit);
}
public function getall($where, $fields='*', $order='', $limit='')
{
$sql = $this->db->getsql(array(
'fields' => $fields,
'table' => $this->table,
'where' => $where,
'order' => $order,
'limit' => $limit
));
return $this->db->getall($sql);
}
public function getarr($where, $fields='*', $kfied='id')
{
return $this->db->getarr($this->table, $where, $fields, $kfied);
}
public function rows($where)
{
return $this->db->rows($this->table, $where);
}
public function query($where, $fields='*', $order='', $limit='')
{
$sql = $this->db->getsql(array(
'fields' => $fields,
'table' => $this->table,
'where' => $where,
'order' => $order,
'limit' => $limit
));
return $this->db->query($sql);
}
public function record($arr, $where='')
{
return $this->db->record($this->table, $arr, $where);
}
public function update($arr,$where)
{
return $this->record($arr, $where);
}
public function insert($arr)
{
$nid = 0;
if($this->record($arr, ''))$nid = $this->db->insert_id();
return $nid;
}
public function insertAll($arr)
{
$name = $values = '';
foreach($arr as $k=>$rs){
$cont = '';
foreach($rs as $i=>$v){
if($k==0)$name.=',`'.$i.'`';
$cont.=",".$this->db->toaddval($v)."";
}
$cont = substr($cont, 1);
if($k>0)$values.=',';
$values.='('.$cont.')';
}
return $this->db->insert($this->table, substr($name, 1),'values '.$values.'', true);
}
public function getwhere($where='')
{
return $this->db->getwhere($where);
}
public function getfields()
{
return $this->db->getallfields($this->table);
}
public function delete($where)
{
return $this->db->delete($this->table, $where);
}
public function getlimit($where, $page=1, $fields='*', $order='', $limit=20, $table='')
{
if($order != '')$order = 'order by '.$order.'';
$where = $this->getwhere($where);
if($table == '')$table = $this->table;
$sql = "select $fields from $table where $where $order ";
$count = $this->db->rows($table, $where);
if($page <= 0)$page=1;
$sql .= "limit ".($page-1)*$limit.",$limit";
$rows = $this->db->getall($sql);
$maxpage = ceil($count/$limit);
return array(
'rows' => $rows,
'count' => $count,
'maxpage' => $maxpage,
'page' => $page,
'limit' => $limit,
'prevpage' => $page-1,
'nextpage' => $page+1,
'url' => ''
);
}
public function isempt($str)
{
return $this->rock->isempt($str);
}
public function contain($str, $s1)
{
return $this->rock->contain($str, $s1);
}
public function getLastSql()
{
return $this->db->getLastSql();
}
public function count($where='1=1')
{
return $this->rows($where);
}
public function getXinxi($id,$fields='*')
{
if(isset($this->tempxinxi[$id]))return $this->tempxinxi[$id];
$rs = $this->getone($id,$fields);
$this->tempxinxi[$id] = $rs;
return $rs;
}
}
class sModel extends Model{}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,407 @@
<?php
/*~ class.pop3.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
| Version: 5.1 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
| Info: http://phpmailer.sourceforge.net |
| Support: http://sourceforge.net/projects/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Andy Prevost (project admininistrator) |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
| ------------------------------------------------------------------------- |
| We offer a number of paid services (www.codeworxtech.com): |
| - Web Hosting on highly optimized fast and secure servers |
| - Technology Consulting |
| - Oursourcing (highly qualified programmers and graphic designers) |
'---------------------------------------------------------------------------'
*/
/**
* PHPMailer - PHP POP Before SMTP Authentication Class
* NOTE: Designed for use with PHP version 5 and up
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
* @version $Id: class.pop3.php 444 2009-05-05 11:22:26Z coolbru $
*/
/**
* POP Before SMTP Authentication Class
* Version 5.0.0
*
* Author: Richard Davey (rich@corephp.co.uk)
* Modifications: Andy Prevost
* License: LGPL, see PHPMailer License
*
* Specifically for PHPMailer to allow POP before SMTP authentication.
* Does not yet work with APOP - if you have an APOP account, contact Richard Davey
* and we can test changes to this script.
*
* This class is based on the structure of the SMTP class originally authored by Chris Ryan
*
* This class is rfc 1939 compliant and implements all the commands
* required for POP3 connection, authentication and disconnection.
*
* @package PHPMailer
* @author Richard Davey
*/
class POP3 {
/**
* Default POP3 port
* @var int
*/
public $POP3_PORT = 110;
/**
* Default Timeout
* @var int
*/
public $POP3_TIMEOUT = 30;
/**
* POP3 Carriage Return + Line Feed
* @var string
*/
public $CRLF = "\r\n";
/**
* Displaying Debug warnings? (0 = now, 1+ = yes)
* @var int
*/
public $do_debug = 2;
/**
* POP3 Mail Server
* @var string
*/
public $host;
/**
* POP3 Port
* @var int
*/
public $port;
/**
* POP3 Timeout Value
* @var int
*/
public $tval;
/**
* POP3 Username
* @var string
*/
public $username;
/**
* POP3 Password
* @var string
*/
public $password;
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
private $pop_conn;
private $connected;
private $error; // Error log array
/**
* Constructor, sets the initial values
* @access public
* @return POP3
*/
public function __construct() {
$this->pop_conn = 0;
$this->connected = false;
$this->error = null;
}
/**
* Combination of public events - connect, login, disconnect
* @access public
* @param string $host
* @param integer $port
* @param integer $tval
* @param string $username
* @param string $password
*/
public function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0) {
$this->host = $host;
// If no port value is passed, retrieve it
if ($port == false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
}
// If no port value is passed, retrieve it
if ($tval == false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Refresh the error log
$this->error = null;
// Connect
$result = $this->Connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->Login($this->username, $this->password);
if ($login_result) {
$this->Disconnect();
return true;
}
}
// We need to disconnect regardless if the login succeeded
$this->Disconnect();
return false;
}
/**
* Connect to the POP3 server
* @access public
* @param string $host
* @param integer $port
* @param integer $tval
* @return boolean
*/
public function Connect ($host, $port = false, $tval = 30) {
// Are we already connected?
if ($this->connected) {
return true;
}
/*
On Windows this will raise a PHP Warning error if the hostname doesn't exist.
Rather than supress it with @fsockopen, let's capture it cleanly instead
*/
set_error_handler(array(&$this, 'catchWarning'));
// Connect to the POP3 server
$this->pop_conn = fsockopen($host, // POP3 Host
$port, // Port #
$errno, // Error Number
$errstr, // Error Message
$tval); // Timeout (seconds)
// Restore the error handler
restore_error_handler();
// Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) {
$this->displayErrors();
}
// Did we connect?
if ($this->pop_conn == false) {
// It would appear not...
$this->error = array(
'error' => "Failed to connect to server $host on port $port",
'errno' => $errno,
'errstr' => $errstr
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
}
// Increase the stream time-out
// Check for PHP 4.3.0 or later
if (version_compare(phpversion(), '5.0.0', 'ge')) {
stream_set_timeout($this->pop_conn, $tval, 0);
} else {
// Does not work on Windows
if (substr(PHP_OS, 0, 3) !== 'WIN') {
socket_set_timeout($this->pop_conn, $tval, 0);
}
}
// Get the POP3 server response
$pop3_response = $this->getResponse();
// Check for the +OK
if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking
$this->connected = true;
return true;
}
}
/**
* Login to the POP3 server (does not support APOP yet)
* @access public
* @param string $username
* @param string $password
* @return boolean
*/
public function Login ($username = '', $password = '') {
if ($this->connected == false) {
$this->error = 'Not connected to POP3 server';
if ($this->do_debug >= 1) {
$this->displayErrors();
}
}
if (empty($username)) {
$username = $this->username;
}
if (empty($password)) {
$password = $this->password;
}
$pop_username = "USER $username" . $this->CRLF;
$pop_password = "PASS $password" . $this->CRLF;
// Send the Username
$this->sendString($pop_username);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
// Send the Password
$this->sendString($pop_password);
$pop3_response = $this->getResponse();
if ($this->checkResponse($pop3_response)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Disconnect from the POP3 server
* @access public
*/
public function Disconnect () {
$this->sendString('QUIT');
fclose($this->pop_conn);
}
/////////////////////////////////////////////////
// Private Methods
/////////////////////////////////////////////////
/**
* Get the socket response back.
* $size is the maximum number of bytes to retrieve
* @access private
* @param integer $size
* @return string
*/
private function getResponse ($size = 128) {
$pop3_response = fgets($this->pop_conn, $size);
return $pop3_response;
}
/**
* Send a string down the open socket connection to the POP3 server
* @access private
* @param string $string
* @return integer
*/
private function sendString ($string) {
$bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
return $bytes_sent;
}
/**
* Checks the POP3 server response for +OK or -ERR
* @access private
* @param string $string
* @return boolean
*/
private function checkResponse ($string) {
if (substr($string, 0, 3) !== '+OK') {
$this->error = array(
'error' => "Server reported an error: $string",
'errno' => 0,
'errstr' => ''
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false;
} else {
return true;
}
}
/**
* If debug is enabled, display the error message array
* @access private
*/
private function displayErrors () {
echo '<pre>';
foreach ($this->error as $single_error) {
print_r($single_error);
}
echo '</pre>';
}
/**
* Takes over from PHP for the socket warning handler
* @access private
* @param integer $errno
* @param string $errstr
* @param string $errfile
* @param integer $errline
*/
private function catchWarning ($errno, $errstr, $errfile, $errline) {
$this->error[] = array(
'error' => "Connecting to the POP3 server raised a PHP warning: ",
'errno' => $errno,
'errstr' => $errstr
);
}
// End of class
}
?>

View File

@@ -0,0 +1,814 @@
<?php
/*~ class.smtp.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
| Version: 5.1 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
| Info: http://phpmailer.sourceforge.net |
| Support: http://sourceforge.net/projects/phpmailer/ |
| ------------------------------------------------------------------------- |
| Admin: Andy Prevost (project admininistrator) |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
| ------------------------------------------------------------------------- |
| We offer a number of paid services (www.codeworxtech.com): |
| - Web Hosting on highly optimized fast and secure servers |
| - Technology Consulting |
| - Oursourcing (highly qualified programmers and graphic designers) |
'---------------------------------------------------------------------------'
*/
/**
* PHPMailer - PHP SMTP email transport class
* NOTE: Designed for use with PHP version 5 and up
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
* @copyright 2004 - 2008 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
* @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $
*/
/**
* SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
* commands except TURN which will always return a not implemented
* error. SMTP also provides some utility methods for sending mail
* to an SMTP server.
* original author: Chris Ryan
*/
class SMTP {
/**
* SMTP server port
* @var int
*/
public $SMTP_PORT = 25;
/**
* SMTP reply line ending
* @var string
*/
public $CRLF = "\r\n";
/**
* Sets whether debugging is turned on
* @var bool
*/
public $do_debug; // the level of debug to perform
/**
* Sets VERP use on/off (default is off)
* @var bool
*/
public $do_verp = false;
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
private $smtp_conn; // the socket to the server
private $error; // error if any on the last call
private $helo_rply; // the reply the server sent to us for HELO
/**
* Initialize the class so that the data is in a known state.
* @access public
* @return void
*/
public function __construct() {
$this->smtp_conn = 0;
$this->error = null;
$this->helo_rply = null;
$this->do_debug = 0;
}
/////////////////////////////////////////////////
// CONNECTION FUNCTIONS
/////////////////////////////////////////////////
/**
* Connect to the server specified on the port specified.
* If the port is not specified use the default SMTP_PORT.
* If tval is specified then a connection will try and be
* established with the server for that number of seconds.
* If tval is not specified the default is 30 seconds to
* try on the connection.
*
* SMTP CODE SUCCESS: 220
* SMTP CODE FAILURE: 421
* @access public
* @return bool
*/
public function Connect($host, $port = 0, $tval = 30) {
// set the error val to null so there is no confusion
$this->error = null;
// make sure we are __not__ connected
if($this->connected()) {
// already connected, generate error
$this->error = array("error" => "Already connected to a server");
return false;
}
if(empty($port)) {
$port = $this->SMTP_PORT;
}
// connect to the smtp server
$this->smtp_conn = @fsockopen($host, // the host of the server
$port, // the port to use
$errno, // error number if any
$errstr, // error message if any
$tval); // give up after ? secs
// verify we connected properly
if(empty($this->smtp_conn)) {
$this->error = array("error" => "Failed to connect to server",
"errno" => $errno,
"errstr" => $errstr);
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
}
return false;
}
// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
if(substr(PHP_OS, 0, 3) != "WIN")
socket_set_timeout($this->smtp_conn, $tval, 0);
// get any announcement
$announce = $this->get_lines();
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
}
return true;
}
/**
* Initiate a TLS communication with the server.
*
* SMTP CODE 220 Ready to start TLS
* SMTP CODE 501 Syntax error (no parameters allowed)
* SMTP CODE 454 TLS not available due to temporary reason
* @access public
* @return bool success
*/
public function StartTLS() {
$this->error = null; # to avoid confusion
if(!$this->connected()) {
$this->error = array("error" => "Called StartTLS() without being connected");
return false;
}
fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 220) {
$this->error =
array("error" => "STARTTLS not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Begin encrypted connection
if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
return false;
}
return true;
}
/**
* Performs SMTP authentication. Must be run after running the
* Hello() method. Returns true if successfully authenticated.
* @access public
* @return bool
*/
public function Authenticate($username, $password) {
// Start authentication
fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($code != 334) {
$this->error =
array("error" => "AUTH not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Send encoded username
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($code != 334) {
$this->error =
array("error" => "Username not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
// Send encoded password
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($code != 235) {
$this->error =
array("error" => "Password not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Returns true if connected to a server otherwise false
* @access public
* @return bool
*/
public function Connected() {
if(!empty($this->smtp_conn)) {
$sock_status = socket_get_status($this->smtp_conn);
if($sock_status["eof"]) {
// the socket is valid but we are not connected
if($this->do_debug >= 1) {
echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
}
$this->Close();
return false;
}
return true; // everything looks good
}
return false;
}
/**
* Closes the socket and cleans up the state of the class.
* It is not considered good to use this function without
* first trying to use QUIT.
* @access public
* @return void
*/
public function Close() {
$this->error = null; // so there is no confusion
$this->helo_rply = null;
if(!empty($this->smtp_conn)) {
// close the connection and cleanup
fclose($this->smtp_conn);
$this->smtp_conn = 0;
}
}
/////////////////////////////////////////////////
// SMTP COMMANDS
/////////////////////////////////////////////////
/**
* Issues a data command and sends the msg_data to the server
* finializing the mail transaction. $msg_data is the message
* that is to be send with the headers. Each header needs to be
* on a single line followed by a <CRLF> with the message headers
* and the message body being seperated by and additional <CRLF>.
*
* Implements rfc 821: DATA <CRLF>
*
* SMTP CODE INTERMEDIATE: 354
* [data]
* <CRLF>.<CRLF>
* SMTP CODE SUCCESS: 250
* SMTP CODE FAILURE: 552,554,451,452
* SMTP CODE FAILURE: 451,554
* SMTP CODE ERROR : 500,501,503,421
* @access public
* @return bool
*/
public function Data($msg_data) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Data() without being connected");
return false;
}
fputs($this->smtp_conn,"DATA" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 354) {
$this->error =
array("error" => "DATA command not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
/* the server is ready to accept data!
* according to rfc 821 we should not send more than 1000
* including the CRLF
* characters on a single line so we will break the data up
* into lines by \r and/or \n then if needed we will break
* each of those into smaller lines to fit within the limit.
* in addition we will be looking for lines that start with
* a period '.' and append and additional period '.' to that
* line. NOTE: this does not count towards limit.
*/
// normalize the line breaks so we know the explode works
$msg_data = str_replace("\r\n","\n",$msg_data);
$msg_data = str_replace("\r","\n",$msg_data);
$lines = explode("\n",$msg_data);
/* we need to find a good way to determine is headers are
* in the msg_data or if it is a straight msg body
* currently I am assuming rfc 822 definitions of msg headers
* and if the first field of the first line (':' sperated)
* does not contain a space then it _should_ be a header
* and we can process all lines before a blank "" line as
* headers.
*/
$field = substr($lines[0],0,strpos($lines[0],":"));
$in_headers = false;
if(!empty($field) && !strstr($field," ")) {
$in_headers = true;
}
$max_line_length = 998; // used below; set here for ease in change
while(list(,$line) = @each($lines)) {
$lines_out = null;
if($line == "" && $in_headers) {
$in_headers = false;
}
// ok we need to break this line up into several smaller lines
while(strlen($line) > $max_line_length) {
$pos = strrpos(substr($line,0,$max_line_length)," ");
// Patch to fix DOS attack
if(!$pos) {
$pos = $max_line_length - 1;
$lines_out[] = substr($line,0,$pos);
$line = substr($line,$pos);
} else {
$lines_out[] = substr($line,0,$pos);
$line = substr($line,$pos + 1);
}
/* if processing headers add a LWSP-char to the front of new line
* rfc 822 on long msg headers
*/
if($in_headers) {
$line = "\t" . $line;
}
}
$lines_out[] = $line;
// send the lines to the server
while(list(,$line_out) = @each($lines_out)) {
if(strlen($line_out) > 0)
{
if(substr($line_out, 0, 1) == ".") {
$line_out = "." . $line_out;
}
}
fputs($this->smtp_conn,$line_out . $this->CRLF);
}
}
// message data has been sent
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "DATA not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Sends the HELO command to the smtp server.
* This makes sure that we and the server are in
* the same known state.
*
* Implements from rfc 821: HELO <SP> <domain> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500, 501, 504, 421
* @access public
* @return bool
*/
public function Hello($host = '') {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Hello() without being connected");
return false;
}
// if hostname for HELO was not specified send default
if(empty($host)) {
// determine appropriate default to send to server
$host = "localhost";
}
// Send extended hello first (RFC 2821)
if(!$this->SendHello("EHLO", $host)) {
if(!$this->SendHello("HELO", $host)) {
return false;
}
}
return true;
}
/**
* Sends a HELO/EHLO command.
* @access private
* @return bool
*/
private function SendHello($hello, $host) {
fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => $hello . " not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
$this->helo_rply = $rply;
return true;
}
/**
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command.
*
* Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,421
* @access public
* @return bool
*/
public function Mail($from) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Mail() without being connected");
return false;
}
$useVerp = ($this->do_verp ? "XVERP" : "");
fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "MAIL not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Sends the quit command to the server and then closes the socket
* if there is no error or the $close_on_error argument is true.
*
* Implements from rfc 821: QUIT <CRLF>
*
* SMTP CODE SUCCESS: 221
* SMTP CODE ERROR : 500
* @access public
* @return bool
*/
public function Quit($close_on_error = true) {
$this->error = null; // so there is no confusion
if(!$this->connected()) {
$this->error = array(
"error" => "Called Quit() without being connected");
return false;
}
// send the quit command to the server
fputs($this->smtp_conn,"quit" . $this->CRLF);
// get any good-bye messages
$byemsg = $this->get_lines();
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
}
$rval = true;
$e = null;
$code = substr($byemsg,0,3);
if($code != 221) {
// use e as a tmp var cause Close will overwrite $this->error
$e = array("error" => "SMTP server rejected quit command",
"smtp_code" => $code,
"smtp_rply" => substr($byemsg,4));
$rval = false;
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
}
}
if(empty($e) || $close_on_error) {
$this->Close();
}
return $rval;
}
/**
* Sends the command RCPT to the SMTP server with the TO: argument of $to.
* Returns true if the recipient was accepted false if it was rejected.
*
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
*
* SMTP CODE SUCCESS: 250,251
* SMTP CODE FAILURE: 550,551,552,553,450,451,452
* SMTP CODE ERROR : 500,501,503,421
* @access public
* @return bool
*/
public function Recipient($to) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Recipient() without being connected");
return false;
}
fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250 && $code != 251) {
$this->error =
array("error" => "RCPT not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Sends the RSET command to abort and transaction that is
* currently in progress. Returns true if successful false
* otherwise.
*
* Implements rfc 821: RSET <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE ERROR : 500,501,504,421
* @access public
* @return bool
*/
public function Reset() {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called Reset() without being connected");
return false;
}
fputs($this->smtp_conn,"RSET" . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "RSET failed",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* Starts a mail transaction from the email address specified in
* $from. Returns true if successful or false otherwise. If True
* the mail transaction is started and then one or more Recipient
* commands may be called followed by a Data command. This command
* will send the message to the users terminal if they are logged
* in and send them an email.
*
* Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE SUCCESS: 552,451,452
* SMTP CODE SUCCESS: 500,501,502,421
* @access public
* @return bool
*/
public function SendAndMail($from) {
$this->error = null; // so no confusion is caused
if(!$this->connected()) {
$this->error = array(
"error" => "Called SendAndMail() without being connected");
return false;
}
fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
}
if($code != 250) {
$this->error =
array("error" => "SAML not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
}
return false;
}
return true;
}
/**
* This is an optional command for SMTP that this class does not
* support. This method is here to make the RFC821 Definition
* complete for this class and __may__ be implimented in the future
*
* Implements from rfc 821: TURN <CRLF>
*
* SMTP CODE SUCCESS: 250
* SMTP CODE FAILURE: 502
* SMTP CODE ERROR : 500, 503
* @access public
* @return bool
*/
public function Turn() {
$this->error = array("error" => "This method, TURN, of the SMTP ".
"is not implemented");
if($this->do_debug >= 1) {
echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
}
return false;
}
/**
* Get the current error
* @access public
* @return array
*/
public function getError() {
return $this->error;
}
/////////////////////////////////////////////////
// INTERNAL FUNCTIONS
/////////////////////////////////////////////////
/**
* Read in as many lines as possible
* either before eof or socket timeout occurs on the operation.
* With SMTP we can tell if we have more lines to read if the
* 4th character is '-' symbol. If it is a space then we don't
* need to read anything else.
* @access private
* @return string
*/
private function get_lines() {
$data = "";
while($str = @fgets($this->smtp_conn,515)) {
if($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
}
$data .= $str;
if($this->do_debug >= 4) {
echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
}
// if 4th character is a space, we are done reading, break the loop
if(substr($str,3,1) == " ") { break; }
}
return $data;
}
}
?>

90
include/View.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
if(!isset($ajaxbool))$ajaxbool = $rock->jm->gettoken('ajaxbool', 'false');
$ajaxbool = $rock->get('ajaxbool', $ajaxbool);
$p = PROJECT;
if(!isset($m))$m='index';
if(!isset($a))$a='default';
if(!isset($d))$d='';
$m = $rock->get('m', $m);
$a = $rock->get('a', $a);
$d = $rock->get('d', $d);
define('M', $m);
define('A', $a);
define('D', $d);
define('P', $p);
$_m = $m;
if($rock->contain($m, '|')){
$_mas = explode('|', $m);
$m = $_mas[0];
$_m = $_mas[1];
}
include_once($rock->strformat('?0/?1/?1Action.php',ROOT_PATH, $p));
$rand = date('YmdHis').rand(1000,9999);
if(substr($d,-1)!='/' && $d!='')$d.='/';
$errormsg = '';
$methodbool = true;
$actpath = $rock->strformat('?0/?1/?2?3',ROOT_PATH, $p, $d, $_m);
define('ACTPATH', $actpath);
$actfile = $rock->strformat('?0/?1Action.php',$actpath, $m);
$actfile1 = $rock->strformat('?0/?1Action.php',$actpath, $_m);
$actbstr = null;
if(file_exists($actfile1))include_once($actfile1);
if(file_exists($actfile)){
include_once($actfile);
$clsname = ''.$m.'ClassAction';
$xhrock = new $clsname();
$actname = ''.$a.'Action';
if($ajaxbool == 'true')$actname = ''.$a.'Ajax';
if(method_exists($xhrock, $actname)){
$xhrock->beforeAction();
$actbstr = $xhrock->$actname();
$xhrock->bodyMessage = $actbstr;
if(is_string($actbstr)){echo $actbstr;$xhrock->display=false;}
if(is_array($actbstr)){echo json_encode($actbstr);$xhrock->display=false;}
}else{
$methodbool = false;
if($ajaxbool == 'false')echo ''.$actname.' not found;';
}
$xhrock->afterAction();
}else{
echo 'actionfile not exists;';
$xhrock = new Action();
}
$_showbool = false;
if($xhrock->display && ($ajaxbool == 'html' || $ajaxbool == 'false')){
$xhrock->smartydata['p'] = $p;
$xhrock->smartydata['a'] = $a;
$xhrock->smartydata['m'] = $m;
$xhrock->smartydata['d'] = $d;
$xhrock->smartydata['rand'] = $rand;
$xhrock->smartydata['qom'] = QOM;
$xhrock->smartydata['path'] = PATH;
$xhrock->smartydata['sysurl']= SYSURL;
$temppath = ''.ROOT_PATH.'/'.$p.'/';
$tplpaths = ''.$temppath.''.$d.''.$m.'/';
$tplname = 'tpl_'.$m.'';
if($a!='default')$tplname .= '_'.$a.'';
$tplname .= '.'.$xhrock->tpldom.'';
$mpathname = $tplpaths.$tplname;
if($xhrock->displayfile!='' && file_exists($xhrock->displayfile))$mpathname = $xhrock->displayfile;
if(!file_exists($mpathname) || !$methodbool){
if(!$methodbool){
$errormsg = 'in ('.$m.') not found Method('.$a.');';
}else{
$errormsg = ''.$tplname.' not exists;';
}
echo $errormsg;
}else{
$_showbool = true;
}
}
if($xhrock->display && ($ajaxbool == 'html' || $xhrock->tpltype=='html' || $ajaxbool == 'false') && $_showbool){
$xhrock->setHtmlData();
$da = $xhrock->smartydata;
foreach($xhrock->assigndata as $_k=>$_v)$$_k=$_v;
include_once($mpathname);
$_showbool = false;
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* 最新系统推送1.9.7后
* 软件信呼OA
* 最后更新2021-10-09
*/
class JPushChajian extends Chajian{
//-------------最新原生app推送app是1.2.3版本 和 最新app+---------------
public function push($title, $desc, $cont, $palias)
{
$alias = $palias['alias'];
$xmalias = $palias['xmalias']; //小米的
$newalias = $palias['newalias']; //最新使用的
$oldalias = $palias['oldalias']; //一般自己编译
$uids = $palias['uids'];
$alias2019 = $palias['alias2019'];
$pushuids = $palias['pushuids']; //可以推送的用户ID
$xmpush = c('xmpush');
$hwpush = c('hwpush');
//可推送判断
$ketualia = array();
foreach($alias2019 as $ali1){
$ali1aa = explode('|', $ali1);
$_uid = $ali1aa[2];
if(in_array($_uid, $pushuids))$ketualia[] = $ali1;
}
$alias2019 = $ketualia;
//$this->rock->debugs($palias,'pushalias');//判断能不能推送,打印这个
$xharr = array(
'uids' => $uids,
'title' => $this->rock->jm->base64encode($title),
'cont' => $this->rock->jm->base64encode($cont),
'desc' => $desc,
'systype'=> getconfig('systype')
);
$isuguanw = false;
//没有设置推送(走的信呼官网渠道)
if(!$xmpush->sendbool() && !$hwpush->sendbool()){
if($xmalias || $newalias || $oldalias || $alias2019){
if($xmalias)$xharr['xmalias'] = join(',', $xmalias);
if($newalias)$xharr['newalias'] = join(',', $newalias);
if($oldalias)$xharr['oldalias'] = join(',', $oldalias);
if($alias2019)$xharr['alias2019'] = join(',', $alias2019);
$isuguanw = true;
}
}else{
$desc = $this->rock->jm->base64decode($desc);
$xmarr = array();//小米的人员
$othar = array();//其他人用
$iosar = array(); //IOS
$hwarr = array(); //华为
$iospas= array();
if($alias2019)foreach($alias2019 as $ali1){
$ali1aa = explode('|', $ali1);
$regid = $ali1aa[0];
$sjlxx = $ali1aa[1];
if(contain($sjlxx,'xiaomi')){
$xmarr[] = $regid;
}else if(contain($sjlxx,'huawei')){
if(isset($ali1aa[3]) && $ali1aa[3])$hwarr[] = $ali1aa[3];
}else if(contain($sjlxx,'iphone')){
$iosar[] = $regid;
$iospas[]= $ali1;
}else{
$othar[] = $regid;
}
}
$msg = $msg1 = $msg2 = '';
if($oldalias)$msg = $xmpush->androidsend($oldalias, $title, $desc, $cont);
if($xmarr)$msg = $xmpush->androidsend($xmarr, $title, $desc);
if($iosar){
if(!$xmpush->jpushiosbool()){
$xharr['alias2019'] = join(',', $iospas);
$isuguanw = true;
}else{
$msg1= $xmpush->jpushiossend($iosar, $title, $desc);
}
}
if($hwarr)$msg2= $hwpush->androidsend($hwarr, $title, $desc);
$msg5 = $msg.$msg1.$msg2;
if($msg5)$this->rock->debugs($msg5,'mypush');
}
if($isuguanw){
$runurl = c('xinhu')->geturlstr('jpushplat', $xharr);
c('curl')->getcurl($runurl);
}
}
}

View File

@@ -0,0 +1,383 @@
<?php
/**
* PHPExcel类
*/
class PHPExcelChajian extends Chajian{
public $excel = null;
public $sheetObj;
public $headlen = 0;
public $headbgcolor = 'CDF79E';
public $bordercolor = '000000';
public $headfontcolor = '';
public $headfontbold = false;
public $borderbool = true;
public $title = '';
public $titlebool = true;
public $titlebgbool = false;
public $sheettitle = '';
public $headArr = array();
public $rows = array();
public $titleboolArray = array();
public $titleArray = array();
public $headArrArray = array();
public $rowsArray = array();
public $pageCode = 'utf-8';
public $code = 'utf-8';
public $createbool = false;
public function initChajian()
{
$this->A = explode(',','A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ,BA,BB,BC,BD,BE,BF,BG,BH,BI,BJ,BK,BL,BM,BN,BO,BP,BQ,BR,BS,BT,BU,BV,BW,BX,BY,BZ,CA,CB,CC,CD,CE,CF,CG,CH,CI,CJ,CK,CL,CM,CN,CO,CP,CQ,CR,CS,CT,CU,CV,CW,CX,CY,CZ');
$this->headWidth= array();
$pastr = ROOT_PATH.'/include/PHPExcel.php';
if(file_exists($pastr)){
include_once($pastr);
$this->excel = new PHPExcel();
}
}
public function isBool()
{
if($this->excel==null){
return false;
}else{
return true;
}
}
/**
设置表头
*/
private function setHead($sheet=0)
{
$arrh = $this->headArr;
$title = $this->sheettitle;
if($title=='')$title = $this->title;
$this->headWidth = array();
if($sheet>0)$this->excel->createSheet();
$this->excel->setActiveSheetIndex($sheet);//设置当前的sheet工作簿
$this->sheetObj = $this->excel->getActiveSheet();
$this->sheetObj->setTitle($title);//设置sheet的工作簿标题
$k = 0;
if($sheet == 0){
$this->excel->getProperties()->setCreator('rock'); //创建者
$this->excel->getProperties()->setLastModifiedBy('rock'); //最后修改
$this->excel->getProperties()->setTitle('rock'); //设置标题
$this->excel->getProperties()->setSubject('rock'); //设置备注
$this->excel->getProperties()->setDescription('rock'); //设置描述
$this->excel->getProperties()->setKeywords('rock'); //设置关键字 | 标记
$this->excel->getProperties()->setCategory('rock'); //设置类别
}
$this->headlen = -1;
foreach($arrh as $_arrh)$this->headlen++;
$this->rowslen = 0;
if(is_array($this->rows))$this->rowslen=count($this->rows);//长度
if($this->headlen==-1)return false;
//整体添加边框颜色,居中
$zta = ($this->titlebool)?2:1;
$getStyle = $this->sheetObj->getStyle('A1:'.$this->A[$this->headlen].''.($this->rowslen+$zta).'');
$getStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
$getStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);//水平居中
if($this->borderbool){
$getStyle->getBorders()->getAllborders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);//边框
if($this->bordercolor!='000000')$getStyle->getBorders()->getAllborders()->getColor()->setARGB('FF'.$this->bordercolor.'');//边框颜色
}
//设置头部标题
if($this->titlebool){
$this->sheetObj->mergeCells('A1:'.$this->A[$this->headlen].'1'); //合并单元格
$this->sheetObj->setCellValue('A1', $title);
$this->sheetObj->getRowDimension(1)->setRowHeight(30); //设置行高
$getStyle = $this->sheetObj->getStyle('A1');
$getStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$getStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直剧中
$getStyle->getFont()->setBold(true);
$getStyle->getFont()->setSize(16);
//标题背景颜色
if($this->titlebgbool){
$getStyle->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$getStyle->getFill()->getStartColor()->setARGB('FF'.$this->headbgcolor.'');
}
}
//设置表头列标题
if($this->headfontbold)$this->sheetObj->getStyle('A'.$zta.':'.$this->A[$this->headlen].''.$zta.'')->getFont()->setBold(true);//标题是否加粗
foreach($arrh as $key=>$_arrh){
$name = $_arrh;
$xlsfontcolor = $this->headfontcolor;
$xlsbgcolor = $this->headbgcolor;
$xlsbordercolor = $this->bordercolor;
$xlsfontsize = '';//字体大小
$xlswidth = 0; //宽度
$xlsalign = 'center'; //对齐方式
$xlsbold = false; //是否加粗
if(is_array($_arrh)){
if(isset($_arrh['xlsfontcolor']))$xlsfontcolor=$_arrh['xlsfontcolor'];
if(isset($_arrh['xlsbgcolor']))$xlsbgcolor=$_arrh['xlsbgcolor'];
if(isset($_arrh['xlsbordercolor']))$xlsbordercolor=$_arrh['xlsbordercolor'];
if(isset($_arrh['xlswidth']))$xlswidth=$_arrh['xlswidth'];
if(isset($_arrh['xlsalign']))$xlswidth=$_arrh['xlsalign'];
if(isset($_arrh['xlsbold']))$xlsbold=$_arrh['xlsbold'];
if(isset($_arrh['xlsfontsize']))$xlsfontsize=$_arrh['xlsfontsize'];
$name= $_arrh['name'];
}
$this->headWidth[$key] = array(strlen($name), $xlswidth); //设置宽度
//设置样式
$vk = ''.$this->A[$k].'2';
if(!$this->titlebool)$vk = ''.$this->A[$k].'1';
$getStyle = $this->sheetObj->getStyle($vk);
//边框
if($xlsbordercolor!='000000')$getStyle->getBorders()->getAllborders()->getColor()->setARGB('FF'.$xlsbordercolor.'');
//设置背景色
$getStyle->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$getStyle->getFill()->getStartColor()->setARGB('FF'.$xlsbgcolor.'');
//设置字体颜色加粗,大小
if($xlsfontcolor!='')$getStyle->getFont()->getColor()->setARGB('FF'.$xlsfontcolor.'');
if($xlsbold)$getStyle->getFont()->setBold(true);
if($xlsfontsize!='')$getStyle->getFont()->setSize($xlsfontsize);
//设置对齐方式
if($xlsalign!='center')$getStyle->getAlignment()->setHorizontal($xlsalign);
$this->sheetObj->setCellValue($vk, $name);
$k++;
}
}
/**
添加数据
*/
private function setData()
{
$rows = $this->rows;
if(!is_array($rows))return false;
$arrh = $this->headArr;
$zta = ($this->titlebool)?3:2;
//添加数据
foreach($rows as $r=>$rs){
if(!is_array($rs))continue;
$k = 0;
$xlsmerge = '';
$xlsbgcolor = '';
$xua = $r+$zta;
if(isset($rs['xlsmerge']))$xlsmerge=$rs['xlsmerge'];
if(isset($rs['xlsbgcolor']))$xlsbgcolor=$rs['xlsbgcolor'];
//整行背景色
if($xlsbgcolor!=''){
$this->sheetObj->getStyle('A'.$xua.':'.$this->A[$this->headlen].''.$xua.'')
->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
->getStartColor()->setARGB('FF'.$xlsbgcolor.'');
}
//判断是否有合并单元格的(A:D)
if($xlsmerge!=''){
$ncta = explode(':',$xlsmerge);
$this->sheetObj->mergeCells(''.$ncta[0].''.$xua.':'.$ncta[1].''.$xua.'');
}
foreach($arrh as $key=>$_arrh){
if(!isset($rs[$key])){
$k++;
continue;
}
$vk = ''.$this->A[$k].''.$xua.'';
$xlsfontcolor = $xlsbgcolor = '';
$xlsbordercolor = $this->bordercolor;
$xlsunderline = '';
$xlsfontsize = '';
$xlsalign = 'center'; //对齐方式
$xlsbold = false; //是否加粗
$xlsitalic = false; //是否斜体
$val = $rs[$key];
$vallen = strlen(''.$val.'');
if($this->headWidth[$key][0]<$vallen)$this->headWidth[$key][0]=$vallen;
if(is_array($_arrh)){
if(isset($_arrh['xlsfontcolor']))$xlsfontcolor=$_arrh['xlsfontcolor'];
if(isset($_arrh['xlsbgcolor']))$xlsbgcolor=$_arrh['xlsbgcolor'];
if(isset($_arrh['xlsbordercolor']))$xlsbordercolor=$_arrh['xlsbordercolor'];
if(isset($_arrh['xlsalign']))$xlsalign=$_arrh['xlsalign'];
}
if(isset($rs['xlsfontcolor']))$xlsfontcolor=$rs['xlsfontcolor'];
if(isset($rs['xlsbordercolor']))$xlsbordercolor=$rs['xlsbordercolor'];
if(isset($rs['xlsalign']))$xlsalign=$rs['xlsalign'];
if(isset($rs['xlsbold']))$xlsbold=$rs['xlsbold'];
if(isset($rs['xlsfontsize']))$xlsfontsize=$rs['xlsfontsize'];
if(isset($rs['xlsunderline']))$xlsunderline=$rs['xlsunderline'];
if(isset($rs[''.$key.'xlsfontcolor']))$xlsfontcolor=$rs[''.$key.'xlsfontcolor'];
if(isset($rs[''.$key.'xlsbgcolor']))$xlsbgcolor=$rs[''.$key.'xlsbgcolor'];
if(isset($rs[''.$key.'xlsbordercolor']))$xlsbordercolor=$rs[''.$key.'xlsbordercolor'];
if(isset($rs[''.$key.'xlsalign']))$xlsalign=$rs[''.$key.'xlsalign'];
if(isset($rs[''.$key.'xlsbold']))$xlsbold=$rs[''.$key.'xlsbold'];
if(isset($rs[''.$key.'xlsfontsize']))$xlsfontsize=$rs[''.$key.'xlsfontsize'];
if(isset($rs[''.$key.'xlsitalic']))$xlsitalic=$rs[''.$key.'xlsitalic'];
if(isset($rs[''.$key.'xlsunderline']))$xlsunderline=$rs[''.$key.'xlsunderline'];
$getStyle = $this->sheetObj->getStyle($vk);
//设置背景色
if($xlsbgcolor!=''){
$getStyle->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$getStyle->getFill()->getStartColor()->setARGB('FF'.$xlsbgcolor.'');
}
//字体颜色
if($xlsfontcolor!='')$getStyle->getFont()->getColor()->setARGB('FF'.$xlsfontcolor.'');
if($xlsbold)$getStyle->getFont()->setBold(true);
if($xlsitalic)$getStyle->getFont()->setItalic(true);//斜体
if($xlsfontsize!='')$getStyle->getFont()->setSize($xlsfontsize);
if($xlsunderline!='')$getStyle->getFont()->setUnderline($xlsunderline);//下划线情况double,双下划线、doubleAccounting,整个单元格双下划线、single,单下划线、singleAccounting,整个单元格单下划线
//设置边框颜色
if($xlsbordercolor!='000000')$getStyle->getBorders()->getAllborders()->getColor()->setARGB('FF'.$xlsbordercolor.'');
//对齐方式
if($xlsalign!='center')$getStyle->getAlignment()->setHorizontal($xlsalign);
$this->sheetObj->setCellValue($vk, $val);
$k++;
}
//设置行高
$xlsrowheight = 0;
if(isset($rs['xlsrowheight']))$xlsrowheight=$rs['xlsrowheight'];
if($xlsrowheight != 0)$this->sheetObj->getRowDimension($r+$zta)->setRowHeight($xlsrowheight);
}
}
/**
设置列宽
*/
private function setColwidth()
{
$k=0;
foreach($this->headWidth as $key=>$v){
$w = $v[1];
if($w<=0){
$w= $v[0] * 1.2;
}else{
$w= $w/70*12;
}
if($w>0)$this->sheetObj->getColumnDimension($this->A[$k])->setWidth($w);
$k++;
}
}
/**
创建数据
*/
public function createData()
{
$len1 = count($this->titleArray);
$len2 = count($this->headArrArray);
$len3 = count($this->rowsArray);
if($len1==$len2 && $len2==$len3 && $len1>0){
for($i=0; $i<$len1; $i++){
$this->sheettitle = $this->titleArray[$i];
$this->headArr = $this->headArrArray[$i];
$this->rows = $this->rowsArray[$i];
$this->titlebool = true;
if(isset($this->titleboolArray[$i]))$this->titlebool=$this->titleboolArray[$i];
$this->setHead($i);
$this->setData();
$this->setColwidth();
}
$this->excel->setActiveSheetIndex(0);
}else{
$this->setHead(0);
$this->setData();
$this->setColwidth();
}
$this->createbool = true;
}
/**
输出显示
@param string $ext 输出类型 xls,xlsx
@param string $type 是否直接下载
@return string 文件名
*/
public function display($ext='xls', $type='down')
{
if(!$this->createbool){
$this->createData();
}
$title = $this->title;
//有随机数
$rand = '';
if(contain($type,'rand'))$rand = date('YmdHis');
$filename = ''.$title.''.$rand.'.'.$ext.'';
//输出
if($ext!='xlsx'){
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
}else{
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007'); //保存excel—2007格式或者
}
$backfile = 'down';
//保存文件
if(contain($type,'savelogs')){
$dir = 'logs';
$path = ''.ROOT_PATH.'/'.UPDIR.'/'.$dir.'/';
if(!is_dir($path))mkdir($path);
$savefile = $path.''.$this->iconvstr($filename).'';
$objWriter->save($savefile); //是否保存本地
$backfile = ''.UPDIR.'/'.$dir.'/'.$filename.'';
}
//下载
if(contain($type, 'down')){
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.iconv('utf-8', 'gbk', $filename).'"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
}
return $backfile;
}
/**
编码转化
*/
private function iconvstr($str)
{
if($this->pageCode=='utf-8')$str = iconv('utf-8', 'gbk', $str);
return $str;
}
/**
合并单元格
*/
public function mergeCells($cel1, $cel2, $val=null, $sheet=-1)
{
if($sheet != -1)$this->excel->setActiveSheetIndex($sheet);
$this->excel->getActiveSheet()->mergeCells(''.$cel1.':'.$cel2.'');
if($val != null)$this->sheetObj->setCellValue($cel1, $val);
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* PHPExcel 读取插件类
*/
class PHPExcelReaderChajian extends Chajian{
public $A;
public $AT;
protected function initChajian()
{
$this->Astr = 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF,AG,AH,AI,AJ,AK,AL,AM,AN,AO,AP,AQ,AR,AS,AT,AU,AV,AW,AX,AY,AZ,BA,BB,BC,BD,BE,BF,BG,BH,BI,BJ,BK,BL,BM,BN,BO,BP,BQ,BR,BS,BT,BU,BV,BW,BX,BY,BZ,CA,CB,CC,CD,CE,CF,CG,CH,CI,CJ,CK,CL,CM,CN,CO,CP,CQ,CR,CS,CT,CU,CV,CW,CX,CY,CZ';
$this->A = explode(',', $this->Astr);
$this->AT = array('A'=>0,'B'=>1,'C'=>2,'D'=>3,'E'=>4,'F'=>5,'G'=>6,'H'=>7,'I'=>8,'J'=>9,'K'=>10,'L'=>11,'M'=>12,'N'=>13,'O'=>14,'P'=>15,'Q'=>16,'R'=>17,'S'=>18,'T'=>19,'U'=>20,'V'=>21,'W'=>22,'X'=>23,'Y'=>24,'Z'=>25,'AA'=>26,'AB'=>27,'AC'=>28,'AD'=>29,'AE'=>30,'AF'=>31,'AG'=>32,'AH'=>33,'AI'=>34,'AJ'=>35,'AK'=>36,'AL'=>37,'AM'=>38,'AN'=>39,'AO'=>40,'AP'=>41,'AQ'=>42,'AR'=>43,'AS'=>44,'AT'=>45,'AU'=>46,'AV'=>47,'AW'=>48,'AX'=>49,'AY'=>50,'AZ'=>51,'BA'=>52,'BB'=>53,'BC'=>54,'BD'=>55,'BE'=>56,'BF'=>57,'BG'=>58,'BH'=>59,'BI'=>60,'BJ'=>61,'BK'=>62,'BL'=>63,'BM'=>64,'BN'=>65,'BO'=>66,'BP'=>67,'BQ'=>68,'BR'=>69,'BS'=>70,'BT'=>71,'BU'=>72,'BV'=>73,'BW'=>74,'BX'=>75,'BY'=>76,'BZ'=>77,'CA'=>78,'CB'=>79,'CC'=>80,'CD'=>81,'CE'=>82,'CF'=>83,'CG'=>84,'CH'=>85,'CI'=>86,'CJ'=>87,'CK'=>88,'CL'=>89,'CM'=>90,'CN'=>91,'CO'=>92,'CP'=>93,'CQ'=>94,'CR'=>95,'CS'=>96,'CT'=>97,'CU'=>98,'CV'=>99,'CW'=>100,'CX'=>101,'CY'=>102,'CZ'=>103);
}
public function reader($filePath=null, $index=2)
{
if(file_exists(ROOT_PATH.'/include/PHPExcel/Reader/Excel2007.php'))include_once(ROOT_PATH.'/include/PHPExcel/Reader/Excel2007.php');
if(file_exists(ROOT_PATH.'/include/PHPExcel/Reader/Excel5.php'))include_once(ROOT_PATH.'/include/PHPExcel/Reader/Excel5.php');
$help = c('xinhu')->helpstr('phpexcel');
if(!class_exists('PHPExcel_Reader_Excel2007'))return '没有安装PHPExcel插件'.$help.'';
if($filePath==null)$filePath = $_FILES['file']['tmp_name'];
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
return '不是正规的Excel文件'.$help.'';
}
}
$PHPExcel = $PHPReader->load($filePath);
$rows = array();
$sheet = $PHPExcel->getSheet(0); //第一个表
$allColumn = $sheet->getHighestColumn();
$allRow = $sheet->getHighestRow();
$allCell = $this->AT[$allColumn];
for($row = $index; $row <= $allRow; $row++){
$arr = array();
for($cell= 0; $cell<= $allCell; $cell++){
$val = $sheet->getCellByColumnAndRow($cell, $row)->getValue();
$arr[$this->A[$cell]] = $val;
}
$rows[] = $arr;
}
return $rows;
}
/**
导入到表
*/
public function importTable($table, $rows, $fields)
{
}
public function ExcelToDate($lx, $val)
{
if($lx=='date')$lx = 'Y-m-d';
if($lx=='datetime')$lx = 'Y-m-d H:i:s';
return date($lx, PHPExcel_Shared_Date::ExcelToPHP($val)-8*3600);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* PHPWord类
*/
class PHPWordChajian extends Chajian{
private $vendorbool=false;
protected function initChajian()
{
$path = ''.ROOT_PATH.'/include/vendor/autoload.php';
if(file_exists($path)){
require_once($path);
$this->vendorbool = true;
}
}
public function isbool()
{
return $this->vendorbool;
}
public function test()
{
if(!$this->vendorbool)return;
\PhpOffice\PhpWord\Settings::loadConfig();
\PhpOffice\PhpWord\Settings::setPdfRenderer(\PhpOffice\PhpWord\Settings::PDF_RENDERER_DOMPDF, ''.ROOT_PATH.'/include/vendor/dompdf/dompdf');
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
$languageEnGb = new \PhpOffice\PhpWord\Style\Language(\PhpOffice\PhpWord\Style\Language::EN_GB);
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setThemeFontLang($languageEnGb);
$section = $phpWord->addSection();
// Adding Text element to the Section having font styled by default...
$section->addText(
'"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is信呼 not to stop questioning." '
. '(Albert Einstein)'
);
//$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
//$objWriter->save('wfewew.docx');
$phpWord->save('helloWorld'.time().'.pdf','PDF');
}
/**
* 只能替换.docx
*/
public function replaceWord($path, $data=array(), $npath='')
{
if(!$this->vendorbool)return returnerror('未安装插件');
$PhpWord = new \PhpOffice\PhpWord\TemplateProcessor($path);
foreach($data as $k=>$v)$PhpWord->setValue($k, $v);
if($npath=='')$npath = str_replace('.docx',''.rand(1000,9999).'.docx', $path);
$PhpWord->saveAs($npath);
return returnsuccess($npath);
}
}

View File

@@ -0,0 +1,180 @@
<?php
/**
* 阿里云短信服务api
*/
class alismsChajian extends Chajian{
private $accesskeyid;
private $accesskeysecret;
protected function initChajian()
{
$this->accesskeyid = getconfig('alisms_keyid');
$this->accesskeysecret = getconfig('alisms_keysecret');
}
/**
* 批量发送短信
*/
public function send($mobiles, $qianm, $tplid, $cans=array())
{
if(isempt($this->accesskeyid) || isempt($this->accesskeysecret))return returnerror('没有设置短信keyid或keysecret');
if(isempt($qianm))return returnerror('请设置短信签名');
if(isempt($tplid) || substr($tplid,0,4) != 'SMS_')return returnerror('短信模版CODE格式有误');
$mbarr = $this->getTplcont($tplid);
if(!$mbarr['success'])return $mbarr;
$tplcont = $mbarr['data']['TemplateContent'];
if(isset($cans['url']))$cans['url'] = c('xinhuapi')->urlsmall($cans['url']); //如果有短域名用这个生成,不要就删掉这行
//把没用参数删掉
$csarr = $this->rock->matcharr($tplcont);
foreach($csarr as $cs1)if(!isset($cans[$cs1]))return returnerror('模版里有{'.$cs1.'}参数,发送必须传');
foreach($cans as $k1=>$v1)if(!in_array($k1, $csarr))unset($cans[$k1]);
$params = array();
$shoujha= explode(',', $mobiles);
$params["PhoneNumberJson"] = $shoujha;
$params["TemplateCode"] = $tplid;
foreach($shoujha as $smid){
$params["SignNameJson"][] = $qianm;
if($cans)$params["TemplateParamJson"][] = $cans;
}
if($cans)$params["TemplateParamJson"] = json_encode($params["TemplateParamJson"], JSON_UNESCAPED_UNICODE);
$params["SignNameJson"] = json_encode($params["SignNameJson"], JSON_UNESCAPED_UNICODE);
$params["PhoneNumberJson"] = json_encode($params["PhoneNumberJson"], JSON_UNESCAPED_UNICODE);
$helper = new SignatureHelper();
$result = $helper->request(
$this->accesskeyid,
$this->accesskeysecret,
'dysmsapi.aliyuncs.com',
array_merge($params, array(
"RegionId" => "cn-hangzhou",
"Action" => "SendBatchSms",
"Version" => "2017-05-25",
))
);
if(!$result)return returnerror('发送失败');
$barr = json_decode($result, true);
if($barr['Code']=='OK')return returnsuccess($barr);
return returnerror('发送失败:'.$result.'');
}
public function getTplcont($tplid)
{
$num = 'alisms_'.$tplid.'';
$val = m('option')->getval($num);
if(!isempt($val)){
return returnsuccess(array('TemplateContent'=>$val));
}
if(isempt($this->accesskeyid) || isempt($this->accesskeysecret))return returnerror('没有设置短信keyid或keysecret');
$helper = new SignatureHelper();
$params['TemplateCode'] = $tplid;
$result = $helper->request(
$this->accesskeyid,
$this->accesskeysecret,
'dysmsapi.aliyuncs.com',
array_merge($params, array(
"RegionId" => "cn-hangzhou",
"Action" => "QuerySmsTemplate",
"Version" => "2017-05-25",
))
);
if(!$result)return returnerror('获取模版失败'.$tplid.'');
$barr = json_decode($result, true);
if($barr['Code']=='OK'){
m('option')->setval($num, $barr['TemplateContent']);
return returnsuccess($barr);
}
return returnerror('获取失败:'.$result.'');
}
}
/**
* 签名助手 2017/11/19
*
* Class SignatureHelper
*/
class SignatureHelper {
/**
* 生成签名并发起请求
*
* @param $accessKeyId string AccessKeyId (https://ak-console.aliyun.com/)
* @param $accessKeySecret string AccessKeySecret
* @param $domain string API接口所在域名
* @param $params array API具体参数
* @param $security boolean 使用https
* @return bool|\stdClass 返回API接口调用结果当发生错误时返回false
*/
public function request($accessKeyId, $accessKeySecret, $domain, $params, $security=false) {
$apiParams = array_merge(array (
"SignatureMethod" => "HMAC-SHA1",
"SignatureNonce" => uniqid(mt_rand(0,0xffff), true),
"SignatureVersion" => "1.0",
"AccessKeyId" => $accessKeyId,
"Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
"Format" => "JSON",
), $params);
ksort($apiParams);
$sortedQueryStringTmp = "";
foreach ($apiParams as $key => $value) {
$sortedQueryStringTmp .= "&" . $this->encode($key) . "=" . $this->encode($value);
}
$stringToSign = "GET&%2F&" . $this->encode(substr($sortedQueryStringTmp, 1));
$sign = base64_encode(hash_hmac("sha1", $stringToSign, $accessKeySecret . "&",true));
$signature = $this->encode($sign);
$url = ($security ? 'https' : 'http')."://{$domain}/?Signature={$signature}{$sortedQueryStringTmp}";
try {
$content = $this->fetchContent($url);
return $content;
} catch( \Exception $e) {
return false;
}
}
private function encode($str)
{
$res = urlencode($str);
$res = preg_replace("/\+/", "%20", $res);
$res = preg_replace("/\*/", "%2A", $res);
$res = preg_replace("/%7E/", "~", $res);
return $res;
}
private function fetchContent($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"x-sdk-client" => "php/2.0.0"
));
if(substr($url, 0,5) == 'https') {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$rtn = curl_exec($ch);
if($rtn === false) {
trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR);
}
curl_close($ch);
return $rtn;
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
数组操作
*/
class arrayChajian extends Chajian{
/**
二维数组排序
*/
public function order($arr, $field, $tyee='desc')
{
$temp_a = array();
foreach ($arr as $arrs) {
$temp_a[] = $arrs[$field];
}
$tyee = strtolower($tyee);
if($tyee == 'desc'){
array_multisort($temp_a, SORT_DESC, $arr);
}else{
array_multisort($temp_a, SORT_ASC, $arr);
}
return $arr;
}
/**
转换为用数字做的键值
*/
public function tonumarray($arr, $otarr='')
{
$varr=array();
if(is_array($otarr))$varr[]=$otarr;
if(is_array($arr)){
foreach($arr as $da){
$key = array_keys($da);
$zarr=array();
for($i=0;$i<count($key);$i++)$zarr[$i]=$da[$key[$i]];
$varr[]=$zarr;
}
}
return $varr;
}
/**
$str 转化为 数组 0|昨天,2|d
*/
public function strtoarray($str)
{
$a = explode(',', $str);
$arr= array();
foreach($a as $a1){
$a2 = explode('|', $a1);
$k = $a2[0];
$v = $a2[0];
$c = '';
if(isset($a2[1]))$v = $a2[1];
if(isset($a2[2]))$c = $a2[2];
$arr[] = array($k, $v, $c);
}
return $arr;
}
/**
$str 转化为 数组对象 0|昨天,2|d
*/
public function strtoobject($str)
{
$rowa = $this->strtoarray($str);
$arr = array();
foreach($rowa as $k=>$rs){
$arr[$rs[0]] = $rs[1];
}
return $arr;
}
/**
[{}]数组转化为{ke1:ke2}
*/
public function arrrytoobject($arr, $lx=0)
{
$rows = array();
foreach($arr as $k=>$da){
$karr = array_keys($da);
$key = $da[$karr[0]];
$nav = $key;
if(count($karr)>1){
$nav = $da[$karr[1]];
}
if($lx == 1){
$rows[$key] = $da;
}else{
$rows[$key] = $nav;
}
}
return $rows;
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* 缓存,目前是使用磁盘文件存储
*/
class cacheChajian extends Chajian{
private $dirvie = 'file'; //redis,file
/**
* 设置缓存
* $time 缓存时间(秒)
*/
public function set($key, $data, $time=0)
{
$this->del($key); //删除原来的
$sarr['key'] = $this->getkey($key);
$sarr['data'] = $data;
if($time>0){
$time = time()+$time;
}else{
$time = 0;
}
$sarr['time'] = $time;
if($time>0)$sarr['timedt'] = date('Y-m-d H:i:s', $time);
$sarr['url'] = $this->rock->nowurl();
$this->delexpire();
return $this->rock->createtxt($this->getpath($key, $time, 1), json_encode($sarr));
}
private function getkey($key)
{
return ''.QOM.''.$key.'';
}
private function getpath($key, $time=0, $lx=0)
{
$key = $this->getkey($key);
$ske = '';
if($time>0)$ske='_'.$time.'';
if($lx==0)return ''.ROOT_PATH.'/'.UPDIR.'/cache/'.md5($key).''.$ske.'';
return ''.UPDIR.'/cache/'.md5($key).''.$ske.'';
}
//获取文件名
private function getpaths($key)
{
$key = $this->getkey($key);
$file= ''.ROOT_PATH.'/'.UPDIR.'/cache/'.md5($key).'';
$bar = glob(''.$file.'*');
if(is_array($bar))foreach($bar as $k=>$fil1){
if($k==0){
$file = $fil1;
}else{
unlink($fil1);
}
}
return $file;
}
/**
* 获取缓存
*/
public function get($key, $dev='')
{
$file= $this->getpaths($key);
$data= $dev;
if(file_exists($file)){
$filea= explode('_', $file);
$time = (int)arrvalue($filea, count($filea)-1,'0');
if($time==0 || $time>=time()){
$cont = file_get_contents($file);
if(!isempt($cont)){
$sarr = json_decode($cont, true);
$data = arrvalue($sarr, 'data');
}
}else{
unlink($file); //已经过期了
}
}
return $data;
}
/**
* 删除缓存
*/
public function del($key)
{
$file= $this->getpaths($key);
if(file_exists($file))@unlink($file);
return true;
}
/**
* 删除所有缓存
*/
public function delall()
{
$bar = glob(''.ROOT_PATH.'/'.UPDIR.'/cache/*');
foreach($bar as $k=>$fil1){
unlink($fil1);
}
}
/**
* 删除过期的缓存
*/
public function delexpire()
{
$bar = glob(''.ROOT_PATH.'/'.UPDIR.'/cache/*');
$time= time();
foreach($bar as $k=>$fil1){
if(contain($fil1,'_')){
$fil11 = substr($fil1, strripos($fil1, '_')+1);
if(is_numeric($fil11)){
if($fil11<$time){
unlink($fil1);
}
}
}
}
}
}

View File

@@ -0,0 +1,247 @@
<?php
class calendarChajian extends Chajian{
//农历每月的天数
private $everyCMonth=array(
0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1),
1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2),
2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3),
3=>array(5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4),
4=>array(0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5),
5=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6),
6=>array(4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7),
7=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8),
8=>array(0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9),
9=>array(2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10),
10=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11),
11=>array(6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12),
12=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1),
13=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2),
14=>array(5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3),
15=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4),
16=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5),
17=>array(2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6),
18=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7),
19=>array(7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8),
20=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9),
21=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10),
22=>array(5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11),
23=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12),
24=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1),
25=>array(4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2),
26=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3),
27=>array(0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4),
28=>array(2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5),
29=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6),
30=>array(6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7),
31=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8),
32=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9),
33=>array(5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10),
34=>array(0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11),
35=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12),
36=>array(3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1),
37=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2),
38=>array(7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3),
39=>array(0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4),
40=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5),
41=>array(6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6),
42=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7),
43=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8),
44=>array(4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9),
45=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10),
46=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11),
47=>array(2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12),
48=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1),
49=>array(7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2),
50=>array(0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3),
51=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4),
52=>array(5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5),
53=>array(0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6),
54=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7),
55=>array(3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8),
56=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9),
57=>array(8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10),
58=>array(0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11),
59=>array(0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12),
60=>array(6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1),
61=>array(0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2),
62=>array(0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3),
63=>array(4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4),
64=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5),
65=>array(0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6),
66=>array(3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7),
67=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8),
68=>array(7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9),
69=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10),
70=>array(0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11),
71=>array(5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12),
72=>array(0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1),
73=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2),
74=>array(4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3),
75=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4),
76=>array(8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5),
77=>array(0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6),
78=>array(0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7),
79=>array(6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8),
80=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9),
81=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10),
82=>array(4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11),
83=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12),
84=>array(10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1),
85=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2),
86=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3),
87=>array(6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4),
88=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5),
89=>array(0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6),
90=>array(5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7),
91=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8),
92=>array(0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9),
93=>array(3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10),
94=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11),
95=>array(8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12),
96=>array(0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1),
97=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2),
98=>array(5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3),
99=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4),
100=>array(0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5),
101=>array(4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6),
102=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7),
103=>array(0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8),
104=>array(2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9),
105=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10),
106=>array(7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11),
107=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12),
108=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1),
109=>array(5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2),
110=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3),
111=>array(0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4),
112=>array(4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5),
113=>array(0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6),
114=>array(9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7),
115=>array(0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8),
116=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9),
117=>array(6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10),
118=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11),
119=>array(0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12),
120=>array(4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1)
);
//农历天干
private $mten=array("null","","","","","","","","","",""); //农历地支
private $mtwelve=array("null","子(鼠)","丑(牛)","寅(虎)","卯(兔)","辰(龙)",
"巳(蛇)","午(马)","未(羊)","申(猴)","酉(鸡)","戌(狗)","亥(猪)"); //农历月份
private $mmonth=array("","","","","","","",
"","","","","十一","十二","");
private $mday=array("null","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十",
"十一","十二","十三","十四","十五","十六","十七","十八","十九","二十",
"廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十");//农历日
//赋给初值
//天干地支
private $ten=0;
private $twelve=0;
private function MyPub($cYear,$cMonth,$cDay)
{
$total=11;//阳历总天数 至1900年12月21日
$mtotal=0;//阴历总天数
for ($y=1901;$y<$cYear;$y++)
{
$total+=365;
if ($y%4==0) $total ++;
}
//再加当年的几个月
switch ($cMonth){
case 12:
$total+=30;
case 11:
$total+=31;
case 10:
$total+=30;
case 9:
$total+=31;
case 8:
$total+=31;
case 7:
$total+=30;
case 6:
$total+=31;
case 5:
$total+=30;
case 4:
$total+=31;
case 3:
$total+=28;
case 2:
$total+=31;
}
//如果当年是闰年还要加一天
if ($cYear%4==0 and $cMonth>2)
{
$total++;
}
$total+=$cDay-1;
$flag = 0;
//用农历的天数累加来判断是否超过阳历的天数
for($j=0;$j<=120;$j++)
{
$i=1;
for($i=1;$i<=13;$i++)
{
$mtotal+=$this->everyCMonth[$j][$i];
if ($mtotal>=$total)
{
$flag=1;
break;
}
}
if ($flag==1)break;
}
return array("m"=>$j,"d"=>$i,"t"=>$total,"n"=>$mtotal);
}
public function Cal($Year,$Month,$Day)
{
$Par=$this->MyPub($Year,$Month,$Day);
$md=$this->everyCMonth[$Par["m"]][$Par["d"]]-($Par["n"]-$Par["t"]);
$week=($Par["t"]+5)%7;
if ($this->everyCMonth[$Par["m"]][0]<>0 and $this->everyCMonth[$Par["m"]][0]<$Par["d"])
{
$mm=$Par["d"]-1;
}else{
$mm=$Par["d"];
}
if ($Par["d"]==$this->everyCMonth[$Par["d"]][0]+1 and $this->everyCMonth[$Par["d"]][0]<>0)
{
$cMonth=$this->mmonth[0].$this->mmonth[$mm];//闰月
}else{
$cMonth=$this->mmonth[$mm].$this->mmonth[13];
}
$mmd = ($mm<10)? '0'.$mm.'' : $mm;
$mdd = ($md<10)? '0'.$md.'' : $md;
return array("year"=>$this->mten[$this->everyCMonth[$Par["m"]][14]].$this->mtwelve[$this->everyCMonth[$Par["m"]][15]],
"month" =>$cMonth,
"day" =>$this->mday[$md],
"week" =>$week,
"m" =>$mm,
'd' =>$md,
'cal' => ''.$mmd.'-'.$mdd.''
);
}
public function toCalday($dt)
{
$dts = explode('-', $dt);
return $this->Cal((int)$dts[0],(int)$dts[1],(int)$dts[2]);
}
public function daytocal($dt)
{
$dts = explode('-', $dt);
$mm = (int)$dts[1];
$md = (int)$dts[2];
$my = (int)$dts[0];
return array(
'year' => $my,
'month' => $this->mmonth[$mm],
'day' => $this->mday[$md],
);
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* 字符检查插件
*/
class checkChajian extends Chajian{
/**
* 是否为邮箱
*/
public function isemail($str)
{
if(isempt($str))return false;
return filter_var($str, FILTER_VALIDATE_EMAIL);
}
/**
* 是否为手机号
*/
public function ismobile($str)
{
if(isempt($str))return false;
if(!is_numeric($str) || strlen($str)<5)return false;
return true;
}
/**
* 判断是否为国内手机号
*/
public function iscnmobile($str)
{
if(isempt($str))return false;
if(!is_numeric($str) || strlen($str)!=11)return false;
if(!preg_match("/1[3458769]{1}\d{9}$/", $str))return false;
return true;
}
/**
* 是否有中文
*/
public function isincn($str)
{
return preg_match("/[\x7f-\xff]/", $str);
}
//是否整个的英文a-z,0-9
public function iszgen($str)
{
if(isempt($str))return false;
if($this->isincn($str)){
return false;
}
return true;
}
//返回字符串编码
public function getencode($str)
{
$encode = mb_detect_encoding($str, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
$encode = strtolower($encode);
return $encode;
}
/**
* 是否为数字
*/
public function isnumber($str)
{
if(isempt($str))return false;
return is_numeric($str);
}
/**
* 字符是否包含数字
*/
public function isinnumber($str)
{
return preg_match("/[0-9]/", $str);
}
/**
* 是否为日期
*/
public function isdate($str)
{
return preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $str);
}
/**
* 是否为日期时间
*/
public function isdatetime($str)
{
return preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/", $str);
}
/**
* 是否为月份
*/
public function ismonth($str)
{
return preg_match("/^([0-9]{4})-([0-9]{2})$/", $str);
}
/**
* 过滤字母,只留数字
*/
public function onlynumber($str)
{
return preg_replace('/[a-zA-Z]/','', $str);
}
/**
* 替换空格
*/
public function replacekg($str)
{
$str = preg_replace('/\s*/', '', $str);
$qian = array(" "," ","\t","\n","\r");
return str_replace($qian, '', $str);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
颜色操作
*/
class colorChajian extends Chajian{
/**
颜色
*/
public function color($color,$l=127.5)
{
$r=hexdec(substr($color,1,2));
$g=hexdec(substr($color,3,2));
$b=hexdec(substr($color,5));
$yb=127.5;
if($l > $yb){
$l = $l - $yb;
$r = ($r * ($yb - $l) + 255 * $l) / $yb;
$g = ($g * ($yb - $l) + 255 * $l) / $yb;
$b = ($b * ($yb - $l) + 255 * $l) / $yb;
}else{
$r = ($r * $l) / $yb;
$g = ($g * $l) / $yb;
$b = ($b * $l) / $yb;
}
$nr=$this->tohex($r);
$ng=$this->tohex($g);
$nb=$this->tohex($b);
return '#'.$nr.$ng.$nb;
}
private function tohex($n)
{
$hexch = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
$n = round($n);
$l = $n % 16;
$h = floor(($n / 16)) % 16;
return ''.$hexch[$h].''.$hexch[$l].'';
}
}

View File

@@ -0,0 +1,146 @@
<?php
/**
curl
*/
class curlChajian extends Chajian{
private $TIMEOUT = 30;
private function strurl($url)
{
$url = str_replace('&#47;', '/', $url);
$url = str_replace(' ', '', $url);
$url = str_replace("\n", '', $url);
return $url;
}
/**
* 设置超时是手机
* $ms 秒数
*/
public function setTimeout($ms)
{
$this->TIMEOUT = $ms;
return $this;
}
private function getdatastr($data)
{
$cont = '';
if(is_array($data)){
foreach($data as $k=>$v)$cont.='&'.$k.'='.$v.'';
if($cont!='')$cont=substr($cont,1);
}else{
$cont = $data;
}
return $cont;
}
public function getfilecont($url)
{
$url = $this->strurl($url);
@$result = file_get_contents($url);
return $result;
}
public function postfilecont($url, $data=array())
{
$url = $this->strurl($url);
$cont = $this->getdatastr($data);
$len = strlen($cont);
$opts = array(
'http' => array(
'method' => 'POST',
'header' =>
"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-length: $len\r\n",
'content' => $cont,
)
);
$cxContext = stream_context_create($opts);
@$sFile = file_get_contents($url, false, $cxContext);
return $sFile;
}
public function getcurl($url, $headarr=array())
{
if(!function_exists('curl_init')){
return $this->getfilecont($url);
}
$url= $this->strurl($url);
$ishttps = 0;
if(substr($url,0, 5)=='https')$ishttps=1;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
if($ishttps==1){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
//设置head
if($headarr){
$heads = array();
foreach($headarr as $k=>$v)$heads[] = ''.$k.':'.$v.'';
curl_setopt($ch, CURLOPT_HTTPHEADER, $heads);
}
curl_setopt($ch, CURLOPT_TIMEOUT, $this->TIMEOUT);
$output = curl_exec($ch);
$this->setResponseHeaders($ch);
curl_close($ch);
return $output;
}
public function postcurl($url, $data=array(), $lx=0, $headarr=array())
{
if(!function_exists('curl_init')){
return $this->postfilecont($url, $data);
}
$url = $this->strurl($url);
$cont = $data;
if($lx==0)$cont = $this->getdatastr($data);
$ishttps = 0;
if(substr($url,0, 5)=='https')$ishttps=1;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_HEADER, 0); //不返回header
curl_setopt($ch, CURLOPT_POST, 1);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $cont);
if($ishttps==1){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
//设置head
if($headarr){
$heads = array();
foreach($headarr as $k=>$v)$heads[] = ''.$k.':'.$v.'';
curl_setopt($ch, CURLOPT_HTTPHEADER, $heads);
}
curl_setopt($ch, CURLOPT_TIMEOUT, $this->TIMEOUT);
$output = curl_exec($ch);
$curl_errno = curl_errno($ch);
$this->setResponseHeaders($ch);
curl_close($ch);
return $output;
}
/**
* postjson的类型
*/
public function postjson($url, $data=array())
{
return $this->postcurl($url, $data, 0, array(
'Content-Type' => 'application/json'
));
}
public function getResponseHeaders()
{
return $this->ResponseHeaders;
}
private function setResponseHeaders($ch)
{
$this->ResponseHeaders = curl_getinfo($ch);
}
}

View File

@@ -0,0 +1,313 @@
<?php
class dateChajian extends Chajian
{
public $now;
public $date;
protected function initChajian()
{
$this->now = $this->rock->now;
$this->date = $this->rock->date;
}
public function formatdt($dt='',$format='Y-m-d H:i:s')
{
return date($format,strtotime($dt));
}
/**
获取上月
*/
public function lastmonth($dt, $type='Y-m')
{
return $this->adddate($dt,'m',-1,$type);
}
/**
计算时间间隔
*/
public function datediff($type,$start,$end)
{
$time1 = strtotime($start);
$time2 = strtotime($end);
$val=0;
switch($type){
case 'Y'://
$Y1 = date('Y',$time1);
$Y2 = date('Y',$time2);
$val = $Y2 - $Y1;
break;
case 'm'://月份
$y1 = date('Y',$time1);
$y2 = date('Y',$time2);
$m1 = date('m',$time1);
$m2 = date('m',$time2);
$y = $y1 - $y2;
$mz = 0;
if($y1 == $y2){
$mz=$m2-$m1;
}elseif($y1<$y2){
$mz = 12-$m1+$m2+12*($y2-$y1-1);
}else{
$mz = -(12-$m2+$m1+12*($y1-$y2-1));
}
$val = $mz;
break;
case 'd'://
$dt1 = strtotime(date('Y-m-d',$time1));
$dt2 = strtotime(date('Y-m-d',$time2));
$time=$dt2-$dt1;
$val = $time/3600/24;
break;
case 'H'://小时
$time = $time2 - $time1;
$val = floor($time/3600);
break;
case 'i'://分钟
$time = $time2 - $time1;
$val = floor($time/60);
break;
case 's'://
$val = $time2 - $time1;
break;
}
return $val;
}
/**
时间计算添加
*/
public function adddate($dt,$lx,$v=0,$type='')
{
$time = strtotime($dt);
$arrn1 = explode(' ',$dt);
$arrn = explode('-',$arrn1[0]);
$Y = (int)$arrn[0];
$m = (int)$arrn[1];
$d = (int)$arrn[2];
$H=$i=$s=0;
if($this->contain($dt,':')){
$arrn2 = explode(':',$arrn1[1]);
$H = (int)$arrn2[0];
$i = (int)$arrn2[1];
$s = (int)$arrn2[2];
}
$rval = $dt;
if($type=='')$type=($H==0)?'Y-m-d':'Y-m-d H:i:s';
if($type=='datetime')$type='Y-m-d H:i:s';
if($v ==0)return date($type, $time);
switch($lx){
case 'm'://月份
$time = mktime($H, $i, $s, $m+$v, $d, $Y);
break;
case 'Y'://
$time = mktime($H, $i, $s, $m, $d, $Y+$v);
break;
case 'd'://日期
$time = mktime($H, $i, $s, $m, $d+$v, $Y);
break;
case 'H'://
$time = mktime($H+$v, $i, $s, $m, $d, $Y);
break;
case 'i'://
$time = mktime($H, $i+$v, $s, $m, $d, $Y);
break;
case 's'://
$time = mktime($H, $i, $s+$v, $m, $d, $Y);
break;
}
$rval = date($type,$time);
return $rval;
}
//是否包含返回bool
public function contain($str,$a)
{
return $this->rock->contain($str,$a);
}
//判断是否为空
public function isempt($str)
{
return $this->rock->isempt($str);
}
public function diffstr($start, $end, $str, $lx=0, $restr='')
{
$time1 = strtotime($start);
$time2 = strtotime($end);
$sj = $time1-$time2;
if($lx==1 && $sj<=0)return '';
return $this->sjdate($sj, $str, $restr);
}
public function sjdate($sj, $str='', $restr='')
{
$h = $i = $s = $d = 0;
$d = floor($sj/3600/24);
$sj = $sj - $d * 3600 * 24;
$h = floor($sj/3600);
$sj = $sj - $h*3600;
$i = floor($sj/60);
$s = $sj - $i * 60;
$str = str_replace(array('d','H','i','s'),array($d,$h,$i,$s), $str);
if($restr!=''){
$resta = explode(',', $restr);
foreach($resta as $restas)$str = str_replace($restas,'', $str);
}
return $str;
}
public function isdate($dt)
{
$bo = false;
if($this->isempt($dt))return $bo;
$arr = explode('-', $dt);
if(count($arr)>2)$bo = true;
$len = strlen($dt);
if($len>10){
$sfm = explode(' ', $dt);
if(!isset($sfm[1]))return false;
$arr = explode(':', $sfm[1]);
if(count($arr)<2)return false;
}
return $bo;
}
/**
返回月份最大日期
*/
public function getenddt($month)
{
$month = substr($month,0,7);
$max = $this->getmaxdt($month);
return ''.$month.'-'.$max.'';
}
public function getmaxdt($dt)
{
$d = explode('-', $dt);
$m = (int)$d[1];
$y = (int)$d[0];
$a = array(31,28,31,30,31,30,31,31,30,31,30,31);
$d = $a[$m-1];
if($y%4 == 0 && $m==2 && $y%100 != 0)$d++;
return $d;
}
public function cnweek($date)
{
$arr = array('日','一','二','三','四','五','六');
return $arr[date('w', strtotime($date))];
}
//读取本周日期
public function getweekarr($dt)
{
$w = date('w', strtotime($dt));
$a = array(-6,0,-1,-2,-3,-4,-5);
$oi = $a[$w];
$le = $oi+7;
for($j=$oi; $j<$le; $j++){
$arr[] = $this->adddate($dt, 'd', $j);
}
return $arr;
}
public function getweekfirst($dt)
{
$arr = $this->getweekarr($dt);
return $arr[0];
}
public function getweeklast($dt)
{
$arr = $this->getweekarr($dt);
return $arr[6];
}
/**
计算返回当前间隔分析:今天 10:20
*/
public function stringdt($dttime, $type='G H:i')
{
$s = '';$H=$s=$i='00';
$dts= explode(' ', $dttime);
$yms= explode('-', $dts[0]);
$Y = $yms[0];$m = $yms[1];$d = $yms[2];
$jg = $this->datediff('d', $dts[0], $this->date);
$G = '';
if($jg==0)$G='今天';
if($jg==1)$G='昨天';
if($jg==2)$G='前天';
if($jg==-1)$G='明天';
if($jg==-2)$G='后天';
$A = $G;
if($G=='')$G=substr($dts[0], 5);
if($A=='')$A=$dts[0];
$w = $this->cnweek($dts[0]);
if(isset($dts[1])){
$sjs = explode(':', $dts[1]);
$H = $sjs[0];
if(isset($sjs[1]))$i = $sjs[1];
if(isset($sjs[2]))$s = $sjs[2];
}
$str = str_replace(
array('A','G','H','i','s','w','Y','m','d'),
array($A,$G,$H,$i,$s,$w, $Y, $m, $d),
$type);
return $str;
}
/**
* 计算周期$rate:d1,d2,$dt开始时间
* 返回日期,根据日期判断是不是今天
*/
public function daterate($rate, $dt, $nowdt='')
{
if(isempt($rate) || isempt($dt))return false;//没有周期
$dt = substr($dt,0, 10);//日期的类型
if($nowdt=='')$nowdt = $this->rock->date;
$nowdt = substr($nowdt, 0, 10);
$jg = str_replace(array('m','d','w','y'),array('','','',''),$rate);
if($jg=='')$jg='1';
$jg = (int)$jg;
$lx = substr($rate, 0, 1);
if($lx=='d'){
$jge = $this->datediff('d', $dt, $nowdt);
if($jge % $jg==0 || $jge==0){
return $nowdt;
}
}
//每月
if($lx=='m'){
$jge = $this->datediff('m', $dt, $nowdt);
if($jge % $jg==0 || $jge==0){
$ndt = date('Y-m-'.substr($dt, 8).'');
if($ndt==$nowdt)return $nowdt;
}
}
//每年
if($lx=='y'){
$jge = $this->datediff('y', $dt, $nowdt);
if($jge % $jg==0 || $jge==0){
$ndt = date('Y-'.substr($dt, 5).'');
if($ndt==$nowdt)return $nowdt;
}
}
//每周
if($lx=='w'){
$w = (int)date('w', strtotime($nowdt));if($w==0)$w=7;//星期7
if($w==$jg){
return $nowdt;
}
}
return false;
}
}

View File

@@ -0,0 +1,219 @@
<?php
/**
下载文件类插件
*/
class downChajian extends Chajian{
private $upobj;
private $messign;
protected function initChajian()
{
$this->messign = '';
$this->upobj = c('upfile');
}
/**
* 获取随机文件名
*/
public function getallfilename($ext)
{
if(!is_dir(UPDIR))mkdir(UPDIR);
$mkdir = ''.UPDIR.'/'.date('Y-m').'';
if(!is_dir($mkdir))mkdir($mkdir);
$allfilename = ''.$mkdir.'/'.date('d_His').''.rand(10,99).'.'.$ext.'';
return $allfilename;
}
/**
* 根据扩展名保存文件(一般邮件附件下载)
*/
public function savefilecont($ext, $cont)
{
$bo = $this->upobj->issavefile($ext);
if(isempt($cont))return;
$file= '';
if(!$bo){
$file = $this->getallfilename('uptemp');
$bo = @file_put_contents($file, base64_encode($cont));
}else{
$file = $this->getallfilename($ext);
$bo = @file_put_contents($file, $cont);
}
if(!$bo){
$file = '';
}else{
if($this->upobj->isimg($ext)){
$bo = $this->upobj->isimgsave($ext, $file);
if(!$bo)$file = '';
}
}
return $file;
}
private function reutnmsg($msg)
{
$this->messign = $msg;
return false;
}
//获取提示内容
public function gettishi($msg1='')
{
$msg = $this->messign;
if(isempt($msg))$msg = $msg1;
return $msg;
}
/**
* 根据内容创建文件
*/
public function createimage($cont, $ext, $filename, $thumbnail='')
{
if(isempt($cont))return $this->reutnmsg('创建内容为空');
$allfilename = $this->getallfilename($ext);
$upses['oldfilename'] = $filename.'.'.$ext;
$upses['fileext'] = $ext;
@file_put_contents($allfilename, $cont);
if(!file_exists($allfilename))return $this->reutnmsg('无法写入:'.$allfilename.'');
$fileobj = getimagesize($allfilename);
$mime = strtolower($fileobj['mime']);
$next = 'jpg';
if(contain($mime,'bmp'))$next = 'bmp';
if($mime=='image/gif')$next = 'gif';
if($mime=='image/png')$next = 'png';
if($ext != $next){
@unlink($allfilename);
$ext = $next;
$allfilename = $this->getallfilename($ext);
$upses['oldfilename'] = $filename.'.'.$ext;
$upses['fileext'] = $ext;
@file_put_contents($allfilename, $cont);
if(!file_exists($allfilename))return $this->reutnmsg('无法写入:'.$allfilename.'');
}
$filesize = filesize($allfilename);
$filesizecn = $this->upobj->formatsize($filesize);
$picw = $fileobj[0];
$pich = $fileobj[1];
if($picw==0||$pich==0){
@unlink($allfilename);
return $this->reutnmsg('无效的图片');;
}
$upses['filesize'] = $filesize;
$upses['filesizecn'] = $filesizecn;
$upses['allfilename'] = $allfilename;
$upses['picw'] = $picw;
$upses['pich'] = $pich;
$arr = $this->uploadback($upses, $thumbnail);
return $arr;
}
public function uploadback($upses, $thumbnail='', $subo=true)
{
if($thumbnail=='')$thumbnail='150x150';
$msg = '';
$data = array();
if(is_array($upses)){
$noasyn = $this->rock->get('noasyn'); //=yes就不同步到文件平台
$noyaso = $this->rock->get('noyaso'); //=yes就不压缩
$fileext= substr($upses['fileext'],0,10);
$arrs = array(
'adddt' => $this->rock->now,
'valid' => 1,
'filename' => $this->replacefile($upses['oldfilename']),
'web' => $this->rock->web,
'ip' => $this->rock->ip,
'mknum' => $this->rock->get('sysmodenum'),
//'mid' => $this->rock->get('sysmid','0'),
'fileext' => $fileext,
'filesize' => (int)$this->rock->get('filesize', $upses['filesize']),
'filesizecn'=> $upses['filesizecn'],
'filepath' => str_replace('../','',$upses['allfilename']),
'optid' => $this->adminid,
'optname' => $this->adminname,
'comid' => m('admin')->getcompanyid(),
);
$arrs['filetype'] = m('file')->getmime($fileext);
$thumbpath = $arrs['filepath'];
$sttua = explode('x', $thumbnail);
$lw = (int)$sttua[0];
$lh = (int)$sttua[1];
//判断是不是需要压缩jpg和jpeg
$compress = getconfig('imgcompress');
if($compress && $noyaso!='yes' && ($fileext=='jpg' || $fileext=='jpeg') && $upses['picw']>0 && $upses['pich']>0){
$sttuc = explode('x', $compress);
$yw = (int)$sttuc[0];
$yh = (int)arrvalue($sttuc, 1, 0);
if($upses['picw'] > $yw || $upses['pich'] > $yh){
$imgac = c('image', true);
$imgac->createimg($thumbpath);
$yspaht = $imgac->compress($yw, $yh);
if($yspaht){
if($thumbpath != $yspaht)unlink($thumbpath);
$thumbpath = $yspaht;
$arrs['filepath'] = $yspaht;
$arrs['filesize'] = filesize($yspaht);
$arrs['filesizecn'] = $this->upobj->formatsize($arrs['filesize']);
}
}
}
if($upses['picw']>$lw || $upses['pich']>$lh){
$imgaa = c('image', true);
$imgaa->createimg($thumbpath);
$thumbpath = $imgaa->thumbnail($lw, $lh, 1);
}
if($upses['picw'] == 0 && $upses['pich']==0)$thumbpath = '';
$arrs['thumbpath'] = $thumbpath;
$bo = $this->db->record('[Q]file',$arrs);
if(!$bo)$this->reutnmsg($this->db->error());
$id = $this->db->insert_id();
$arrs['id'] = $id;
$arrs['picw'] = $upses['picw'];
$arrs['pich'] = $upses['pich'];
$data= $arrs;
//上传到上传的文件管理2021-08-09
if(getconfig('rockfile_autoup') && $noasyn != 'yes'){
$stime = time()+rand(3,6);
if($subo)$stime=0;
c('rockqueue')->push('flow,uptofile', array('fileid'=>$id), $stime);
}
//自动上传到腾讯云存储/阿里云oss存储
if((getconfig('qcloudCos_autoup') || getconfig('alioss_autoup')) && $noasyn != 'yes'){
$stime = time()+rand(3,6);
if($subo)$stime=0;
c('rockqueue')->sendfile($id, $stime);
}
}else{
$data['msg'] = $upses;
}
return $data;
}
//过滤特殊文件名
private function replacefile($str)
{
$s = strtolower($str);
$s2 = $s.'';
$lvlaraa = explode(',','user(),found_rows,(),select*from,select*,%20,<,>');
$s = str_replace($lvlaraa, '', $s);
if($s!=$s2)$str = $s;
return $str;
}
//获取扩展名
public function getext($file)
{
return strtolower(substr($file,strrpos($file,'.')+1));
}
}

View File

@@ -0,0 +1,113 @@
<?php
/**
修改记录插件
*/
class editChajian extends Chajian{
public $editarr = array();
/**
获取修改记录
$table 表
$id id值
$oners 旧数组
$newrs 新数组
return string
*/
public function record($table, $id, $oners, $newrs, $glx=1)
{
$str = '';
$db = m($table);
$this->editarr = array();
if($oners){
$farr = $this->getfield($table);
$str = $this->editcont($farr, $oners, $newrs);
}
if($glx == 1 && $str != ''){
$str = '['.$this->adminname.']('.$this->rock->now.')修改:'.$str.'';
}
if($glx == 2){
$this->addrecord($table, $id);
}
return $str;
}
public function records($farr,$table, $id, $oners, $newrs)
{
$this->editcont($farr, $oners, $newrs);
$this->addrecord($table, $id);
}
public function editcont($farr, $oners, $narr)
{
$str = '';
$this->editarr = array();
if($oners){
foreach($narr as $k=>$v){
if(!isset($farr[$k]))continue;
$fa = $farr[$k];
$nv = $v;
$ov = '';
if(isset($oners[$k]))$ov = $oners[$k];
if($nv != $ov){
$sel = array();
if(isset($fa['selarr']))$sel = $fa['selarr'];
if(isset($sel[$ov]))$ov = $sel[$ov];
if(isset($sel[$nv]))$nv = $sel[$nv];
$str .= ''.$fa['name'].':'.$ov.'→'.$nv.';';
$this->editarr[] = array(
'fieldsname' => $fa['name'],
'oldval' => $ov,
'newval' => $nv
);
}
}
}
return $str;
}
public function addrecord($table, $id)
{
$dbs = m('editrecord');
foreach($this->editarr as $k=>$rs){
$rs['optid'] = $this->adminid;
$rs['optname'] = $this->adminname;
$rs['optdt'] = $this->rock->now;
$rs['table'] = $table;
$rs['mid'] = $id;
$dbs->insert($rs);
}
}
/**
获取对应表上字段信息
$glx 0基本字段1流程上
return {字段名:对应信息}
*/
public function getfield($table, $glx=0)
{
$farr = $this->db->gettablefields($this->rock->T($table));
$rows = array();
$arrar = c('array');
foreach($farr as $k=>$rs){
$va = $rs['explain'];
$vn = $rs['name'];
$sel= array();
if(!$this->rock->isempt($va)){
$vas = explode('@', $va);
$va = $vas[0];
$len = count($vas);
if($len>1)$sel = $arrar->strtoobject($vas[1]);
if($len>2&&$glx==1&&$vas[2]=='not')$va='';
}
if(!$this->rock->isempt($va)){
$rows[$vn] = array(
'name' => $va,
'selarr' => $sel
);
}
}
return $rows;
}
}

View File

@@ -0,0 +1,366 @@
<?php
class fileChajian extends Chajian
{
public $path; //文件路径
public $name; //文件名称
public $ext; //扩展名
private $mimitype = array(
'unkown' => 'application/octet-stream',
'acx' => 'application/internet-property-stream',
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'asp' => 'text/plain',
'aspx' => 'text/plain',
'asf' => 'video/x-ms-asf',
'asr' => 'video/x-ms-asf',
'asx' => 'video/x-ms-asf',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
'axs' => 'application/olescript',
'bas' => 'text/plain',
'bcpio' => 'application/x-bcpio',
'bin' => 'application/octet-stream',
'bmp' => 'image/bmp',
'c' => 'text/plain',
'cat' => 'application/vnd.ms-pkiseccat',
'cdf' => 'application/x-cdf',
'cer' => 'application/x-x509-ca-cert',
'class' => 'application/octet-stream',
'clp' => 'application/x-msclip',
'cmx' => 'image/x-cmx',
'cod' => 'image/cis-cod',
'cpio' => 'application/x-cpio',
'crd' => 'application/x-mscardfile',
'crl' => 'application/pkix-crl',
'crt' => 'application/x-x509-ca-cert',
'csh' => 'application/x-csh',
'css' => 'text/css',
'dcr' => 'application/x-director',
'der' => 'application/x-x509-ca-cert',
'dir' => 'application/x-director',
'dll' => 'application/x-msdownload',
'dms' => 'application/octet-stream',
'doc' => 'application/msword',
'docx' => 'application/msword',
'dot' => 'application/msword',
'dvi' => 'application/x-dvi',
'dxr' => 'application/x-director',
'eps' => 'application/postscript',
'etx' => 'text/x-setext',
'evy' => 'application/envoy',
'exe' => 'application/octet-stream',
'fif' => 'application/fractals',
'flr' => 'x-world/x-vrml',
'flv' => 'video/x-flv',
'gif' => 'image/gif',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'h' => 'text/plain',
'hdf' => 'application/x-hdf',
'hlp' => 'application/winhlp',
'hqx' => 'application/mac-binhex40',
'hta' => 'application/hta',
'htc' => 'text/x-component',
'htm' => 'text/html',
'html' => 'text/html',
'shtml' => 'text/html',
'htt' => 'text/webviewhtml',
'ico' => 'image/x-icon',
'ief' => 'image/ief',
'iii' => 'application/x-iphone',
'ins' => 'application/x-internet-signup',
'isp' => 'application/x-internet-signup',
'jfif' => 'image/pipeg',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'js' => 'application/x-javascript',
'latex' => 'application/x-latex',
'lha' => 'application/octet-stream',
'lsf' => 'video/x-la-asf',
'lsx' => 'video/x-la-asf',
'lzh' => 'application/octet-stream',
'm13' => 'application/x-msmediaview',
'm14' => 'application/x-msmediaview',
'm3u' => 'audio/x-mpegurl',
'man' => 'application/x-troff-man',
'mdb' => 'application/x-msaccess',
'me' => 'application/x-troff-me',
'mht' => 'message/rfc822',
'mhtml' => 'message/rfc822',
'mid' => 'audio/mid',
'mny' => 'application/x-msmoney',
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp2' => 'video/mpeg',
'mp3' => 'audio/mpeg',
'mpa' => 'video/mpeg',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpp' => 'application/vnd.ms-project',
'mpv2' => 'video/mpeg',
'ms' => 'application/x-troff-ms',
'mvb' => 'application/x-msmediaview',
'nws' => 'message/rfc822',
'oda' => 'application/oda',
'p10' => 'application/pkcs10',
'p12' => 'application/x-pkcs12',
'p7b' => 'application/x-pkcs7-certificates',
'p7c' => 'application/x-pkcs7-mime',
'p7m' => 'application/x-pkcs7-mime',
'p7r' => 'application/x-pkcs7-certreqresp',
'p7s' => 'application/x-pkcs7-signature',
'pbm' => 'image/x-portable-bitmap',
'pdf' => 'application/pdf',
'pfx' => 'application/x-pkcs12',
'pgm' => 'image/x-portable-graymap',
'pko' => 'application/ynd.ms-pkipko',
'pma' => 'application/x-perfmon',
'pmc' => 'application/x-perfmon',
'pml' => 'application/x-perfmon',
'pmr' => 'application/x-perfmon',
'pmw' => 'application/x-perfmon',
'png' => 'image/png',
'pnm' => 'image/x-portable-anymap',
'pot,' => 'application/vnd.ms-powerpoint',
'ppm' => 'image/x-portable-pixmap',
'pps' => 'application/vnd.ms-powerpoint',
'ppt' => 'application/vnd.ms-powerpoint',
'pptx' => 'application/vnd.ms-powerpoint',
'prf' => 'application/pics-rules',
'ps' => 'application/postscript',
'pub' => 'application/x-mspublisher',
'qt' => 'video/quicktime',
'ra' => 'audio/x-pn-realaudio',
'ram' => 'audio/x-pn-realaudio',
'ras' => 'image/x-cmu-raster',
'rgb' => 'image/x-rgb',
'rmi' => 'audio/mid',
'roff' => 'application/x-troff',
'rtf' => 'application/rtf',
'rtx' => 'text/richtext',
'scd' => 'application/x-msschedule',
'sct' => 'text/scriptlet',
'setpay' => 'application/set-payment-initiation',
'setreg' => 'application/set-registration-initiation',
'sh' => 'application/x-sh',
'shar' => 'application/x-shar',
'sit' => 'application/x-stuffit',
'snd' => 'audio/basic',
'spc' => 'application/x-pkcs7-certificates',
'spl' => 'application/futuresplash',
'src' => 'application/x-wais-source',
'sst' => 'application/vnd.ms-pkicertstore',
'stl' => 'application/vnd.ms-pkistl',
'stm' => 'text/html',
'svg' => 'image/svg+xml',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'swf' => 'application/x-shockwave-flash',
't' => 'application/x-troff',
'tar' => 'application/x-tar',
'tcl' => 'application/x-tcl',
'tex' => 'application/x-tex',
'texi' => 'application/x-texinfo',
'texinfo' => 'application/x-texinfo',
'tgz' => 'application/x-compressed',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'tr' => 'application/x-troff',
'trm' => 'application/x-msterminal',
'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain',
'uls' => 'text/iuls',
'ustar' => 'application/x-ustar',
'vcf' => 'text/x-vcard',
'vrml' => 'x-world/x-vrml',
'wav' => 'audio/x-wav',
'wcm' => 'application/vnd.ms-works',
'wdb' => 'application/vnd.ms-works',
'wks' => 'application/vnd.ms-works',
'wmf' => 'application/x-msmetafile',
'wmv' => 'video/x-ms-wmv',
'wps' => 'application/vnd.ms-works',
'wri' => 'application/x-mswrite',
'wrl' => 'x-world/x-vrml',
'wrz' => 'x-world/x-vrml',
'xaf' => 'x-world/x-vrml',
'xbm' => 'image/x-xbitmap',
'xla' => 'application/vnd.ms-excel',
'xlc' => 'application/vnd.ms-excel',
'xlm' => 'application/vnd.ms-excel',
'xls' => 'application/vnd.ms-excel',
'xlsx' => 'application/vnd.ms-excel',
'xlt' => 'application/vnd.ms-excel',
'xlw' => 'application/vnd.ms-excel',
'xof' => 'x-world/x-vrml',
'xpm' => 'image/x-xpixmap',
'xwd' => 'image/x-xwindowdump',
'z' => 'application/x-compress',
'zip' => 'application/zip',
'rar' => 'application/zip',
'php' => 'text/x-php',
);
public function getAllMime()
{
return $this->mimitype;
}
/**
文件信息
*/
public function fileinfo($path)
{
if($this->filebool($path)){
$arr=pathinfo($path);
$this->name = $arr['basename'];
$this->path = $arr['dirname'];
$this->ext = $arr['extension'];
}
}
/**
删除文件
*/
public function delfile($file)
{
$bool = false;
if($this->filebool($file)){
$bool = unlink($file);
}
return $bool;
}
/**
重命名
*/
public function rename($oldf,$newf)
{
$bool = false;
if($this->filebool($oldf)){
$bool = rename($oldf,$newf);
}
return $bool;
}
/**
判断文件是否存在
*/
public function filebool($path)
{
return file_exists($path);
}
/**
创建文件
@pamars $path 文件路径
@pamars $cont 内容
*/
public function caretefile($path,$cont)
{
}
public function createdir($path, $oi=1)
{
$zpath = explode('/', $path);
$len = count($zpath);
$mkdir = '';
for($i=0; $i<$len-$oi; $i++){
if(!$this->isempt($zpath[$i])){
$mkdir.='/'.$zpath[$i].'';
$wzdir = ROOT_PATH.''.$mkdir;
if(!is_dir($wzdir)){
mkdir($wzdir);
}
}
}
}
/**
* 获取某个目录下所有文件
*/
public function getfilerows($path)
{
$rows = array();
if(!is_dir($path))return $rows;
@$d = opendir($path);
$nyunf = array('.', '..');
while( false !== ($file = readdir($d))){
if(!in_array($file, $nyunf)){
$filess = $path.'/'.$file;
if(is_file($filess)){
$editdt = filectime($filess);//上次修改时间
$lastdt = filemtime($filess);//最后修改的时间
$rows[] = array(
'filename' => $file,
'editdt' => date('Y-m-d H:i:s', $editdt),
'lastdt' => date('Y-m-d H:i:s', $lastdt),
);
}
}
}
return $rows;
}
/**
* 获取某个目录下所有文件夹
*/
public function getfolderrows($path)
{
$rows = array();
if(!is_dir($path))return $rows;
@$d = opendir($path);
$nyunf = array('.', '..');
while( false !== ($file = readdir($d))){
if(!in_array($file, $nyunf)){
$filess = $path.'/'.$file;
if(is_dir($filess)){
$rows[] = array(
'filename' => $file,
);
}
}
}
return $rows;
}
/**
* 获取文件的mime类型
*/
public function getMime($file)
{
$mime = '';
if(!file_exists($file))return $mime;
if(class_exists('finfo')){
$fi = new finfo(FILEINFO_MIME_TYPE);
$mime = $fi->file($file);
}else{
$fobj = getimagesize($file);
$mime = strtolower($fobj['mime']);
}
return $mime;
}
/**
* 根据文件获取对应扩展名
*/
public function getfiletoExt($file, $ext='')
{
$mime = $this->getMime($file);
if($mime=='')return $ext;
foreach($this->mimitype as $kz=>$mita){
if($mita == $mime){
$ext = $kz;
break;
}
}
return $ext;
}
}

View File

@@ -0,0 +1,245 @@
<?php
/**
html相关插件
*/
class htmlChajian extends Chajian{
public function replace($cont)
{
if(isempt($cont))return '';
//$cont = str_replace(array('<', '>'), array('&lt;', '&gt;'), $cont);
//$cont = str_replace(array('[B]','[/B]', '[/A]', "\n"), array('<B>','</B>', '</A>','</p><p>'), $cont);
$cont = str_replace(array('[B]','[/B]', '[/A]'), array('<B>','</B>', '</A>'), $cont);
preg_match_all('/\[(.*?)\]/', $cont, $list);
foreach($list[0] as $k=>$nrs){
if($this->rock->contain($nrs, '[A,')){
$url = str_replace('[A,', '', $nrs);
$url = str_replace(']', '', $url);
$cont = str_replace($nrs, '<A href="'.$url.'" target="_blank">', $cont);
}
if($this->rock->contain($nrs, '[IMG,')){
$url = str_replace('[IMG,', '', $nrs);
$url = str_replace(']', '', $url);
$a = explode(',', $url);
$str = '<img src="'.$a[0].'"';
if(isset($a[1]))$str.=' width="'.$a[1].'"';
if(isset($a[2]))$str.=' height="'.$a[2].'"';
$str.='>';
$cont = str_replace($nrs, $str, $cont);
}
}
return $cont;
}
public function createtable($fields, $arr, $title='',$lx='',$bcolor='')
{
if(isempt($bcolor))$bcolor = '#cccccc';
if($lx=='print'){
$bcolor = '#000000';
$title='';
}
$s = '<table border="0" class="createtable" cellspacing="0" cellpadding="0" style="border-collapse:collapse;">';
if($title != ''){
$s .= '<tr><td colspan="2" align="center" style="border:1px '.$bcolor.' solid;padding:10px;font-size:16px;background:#D2E9FF;">'.$title.'</td></tr>';
}
foreach($fields as $fid=>$na){
$val = '';
$sty = 'padding:8px;';
if(isset($arr[$fid]))$val = $arr[$fid];
if(isset($arr[$fid.'_style']))$sty .= $arr[$fid.'_style'];
$s .= '<tr><td align="right" nowrap style="border:1px '.$bcolor.' solid;padding:5px 8px;">'.$na.'</td><td style="border:1px '.$bcolor.' solid;'.$sty.'" align="left">'.$val.'</td></tr>';
}
$s .='</table>';
return $s;
}
/**
* 单据详情默认展示的
*/
public function xiangtable($fields, $arr,$bcolor='', $lx='')
{
return $this->createtable($fields, $arr,'',$lx, $bcolor);
}
/**
创建table表格数据
@param string $rows 下载导出数据
@param string $headstr 表格表头(如lie1,列1,left@lie2,列2,center)
@return string
*/
public function createrows($rows, $headstr='', $bor='#C9ECFF',$lx='')
{
if($headstr == '')$headstr = $this->request('header');
if($headstr == '')return '';
$arrh = explode('@', $headstr);
$thead = count($arrh);
$lens = $thead-1;
$rlen = count($rows);
for($i=0; $i<$thead; $i++){
$te_str = $arrh[$i];
if(count(explode(',', $te_str)) < 3)$te_str.=',center';
$head[] = explode(',', $te_str);
}
$txt = '';
$style = "padding:3px;border:1px ".$bor." solid";
if($lx=='print')$style = "border:.5pt #000000 solid";
$txt .= '<table width="100%" class="createrows" border="0" cellspacing="0" cellpadding="0" align="center" style="border-collapse:collapse;" >';
$txt .= '<tr>';
for($h=0; $h<$thead; $h++){
$stls= $style;
if($lx=='noborder'){
$stls.=';border-top:none';
if($h==0)$stls.=';border-left:none';
if($h==$lens)$stls.=';border-right:none';
}
$txt.= '<td style="'.$stls.'" bgcolor="#eeeeee" align="'.$head[$h][2].'"><b>'.$head[$h][1].'</b></td>';
}
$txt .= '</tr>';
foreach($rows as $k=>$rs){
$txt .= '<tr>';
$rs['xuhaos'] = $k+1;
for($h=0; $h<$thead; $h++){
$stls= $style;
$stls.='';
if($lx=='noborder'){
if($h==0)$stls.=';border-left:none';
if($h==$lens)$stls.=';border-right:none';
if($k==$rlen-1)$stls.=';border-bottom:none';
}
$val = isset($rs[$head[$h][0]]) ? $rs[$head[$h][0]] : '';
$txt .= '<td style="'.$stls.'" align="'.$head[$h][2].'">'.$val.'</td>';
}
$txt .= '</tr>';
}
$txt .= '</table>';
return $txt;
}
/**
* 创建excel导出表格
*/
public function execltable($title, $headArr, $rows, $lx='')
{
if($lx=='')$lx='xls';
$borst = '.5pt';
$sty = 'style="white-space:nowrap;border:'.$borst.' solid #000000;font-size:12px;"';
$s = '<html><head><meta charset="utf-8"><title>'.$title.'</title></head><body>';
$s .= '<table border="0" style="border-collapse:collapse;">';
$hlen = 1;
$s1='<tr height="30"><td '.$sty.'>序号</td>';
foreach($headArr as $na){
$hlen++;
$s1.='<td '.$sty.'>'.$na.'</td>';
}
$s1.='</tr>';
$s.='<tr height="40"><td '.$sty.' colspan="'.$hlen.'">'.$title.'</td></tr>';
$s.=$s1;
foreach($rows as $k=>$rs){
$atr = '';
if(isset($rs['trbgcolor']))$atr=' bgcolor="'.$rs['trbgcolor'].'"';
$s.='<tr height="26"'.$atr.'>';
$s.='<td align="center" '.$sty.'>'.($k+1).'</td>';
foreach($headArr as $kf=>$na){
$val = '';
if(isset($rs[$kf]))$val=$rs[$kf];
$s.='<td '.$sty.'>'.$this->execelval($val).'</td>';
}
$s.='</tr>';
}
$s.='</table>';
$s.='</body></html>';
$mkdir = ''.UPDIR.'/logs/'.date('Y-m').'';
if(!contain(strtolower(PHP_OS),'win')){
$title = c('pingyin')->get($title, 1);//linux要用拼音不然会乱码
}
$filename = ''.$title.'_'.date('d_His').'.'.$lx.'';
$filename = str_replace('/','',$filename);
$url = ''.$mkdir.'/'.$filename.'';
$bo = $this->rock->createtxt(iconv('utf-8','gb2312',$url), $s);
return $url;
}
//超过11位的数字就会变型处理
private function execelval($str)
{
if($str!=''){
if(is_numeric($str) && strlen($str)>11)$str=''.$str.'&nbsp;';
}
return $str;
}
public function htmlremove($str)
{
$str = preg_replace("/<[^>]*>/si",'',$str);
$str = str_replace(array(' ',"\n"),'', $str);
return $str;
}
public function substrstr($str, $start, $length=null) {
preg_match_all('/./us', $str, $match);
$chars = is_null($length)? array_slice($match[0], $start ) : array_slice($match[0], $start, $length);
unset($str);
return implode('', $chars);
}
//判断字符串是否包含html代码
public function ishtml($val)
{
$bo = false;
if(isempt($val))return $bo;
$valstr = strtolower($val);
$sparr = explode(',','p,div,span,font,table,b,a');
foreach($sparr as $sp){
if(contain($valstr,'<'.$sp.'')){
$bo=true;
break;
}
}
return $bo;
}
public function importdata($fields,$btfid='', $fid='')
{
if($fid=='')$fid='importcont';
$rows = array();
$val = $this->rock->post($fid);
if($val=='')return $rows;
$arrs = explode("\n", $val);
$farr = explode(',', $fields);
$fars = explode(',', $btfid);
foreach($arrs as $valss){
$dars = explode(' ', $valss);
$barr = array();
foreach($farr as $k=>$fid){
$barr[$fid] = isset($dars[$k]) ? $dars[$k] : '';
$barr[$fid] = str_replace('[XINHUBR]', "\n", $barr[$fid]);
}
$bos = true;
foreach($fars as $fids){
if(isset($barr[$fids]) && isempt($barr[$fids]))$bos = false;
}
if($bos)$rows[] = $barr;
}
return $rows;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* 来自:信呼开发团队
* 作者:磐石(rainrock)
* 网址http://www.rockoa.com/
* 华为的推送服务
* 参考的开发https://developer.huawei.com/consumer/cn/service/hms/catalog/huaweipush_v3.html?page=hmssdk_huaweipush_api_reference_messagesend
*/
class hwpushChajian extends Chajian{
//华为推送的设置【自己编译app】以下2个必须设置
private $appid = '';
private $appsecret = '';
/**
* 相关域名定义
*/
private $tokenurl = 'https://login.cloud.huawei.com/oauth2/v2/token';
private $pushurl = 'https://push-api.cloud.huawei.com/v1/{appid}/messages:send';
protected function initChajian()
{
if(!$this->appid)$this->appid = getconfig('hw_appid');
if(!$this->appsecret)$this->appsecret = getconfig('hw_appsecret');
}
public function sendbool()
{
if($this->appsecret=='')return false;
return true;
}
public function setinfo($apid,$apse)
{
$this->appid = $apid;
$this->appsecret = $apse;
return $this;
}
/**
* 获取token
*/
public function gettoken(){
if($this->appid=='' || $this->appsecret=='')return '';
$token = c('cache')->get('hwtoken');
if(isempt($token)){
$result = c('curl')->postcurl($this->tokenurl, array(
"grant_type" => "client_credentials",
"client_secret" => $this->appsecret,
"client_id" => $this->appid,
));
if($result){
$barr = json_decode($result, true);
$token = $barr['access_token'];
c('cache')->set('hwtoken',$token, $barr['expires_in']-1);
}
}
return $token;
}
/**
* 安卓推送通知
*/
public function androidsend($alias, $title, $cont)
{
if(!$this->sendbool())return '';
$url = str_replace('{appid}',$this->appid, $this->pushurl);
$token = $this->gettoken();
if(!$token)return '';
$data = '{"validate_only": false, "message": {"android": { "notification": { "title": "'.$title.'", "body": "'.$cont.'", "click_action": { "type": 1, "intent": "#Intent;compo=com.rvr/.Activity;S.W=U;end" } } }, "token": '.json_encode($alias).' }}';
$result = c('curl')->postcurl($url, $data, 0, array(
"Content-Type" => 'application/json',
"Authorization" => "Bearer {$token}"
));
return $result;
}
}

View File

@@ -0,0 +1,352 @@
<?php
/**
gd2库图片处理添加水印
*/
class imageChajian extends Chajian
{
public $ext; //图片类型
public $img; //图片对象
public $mime; //图片对象
public $path; //图片地址
public $w = 0;
public $h = 0;
public $bool = false;
public $size = 0;
public $whbili = 0;//高和宽的比例
protected function initChajian()
{
$this->bool = function_exists('ImageCreate');
}
/**
创建图片对象$rotate旋转角度
*/
public function createimg($path,$rotate=0)
{
if(!$this->bool)return false;
$this->bool = false;
if(!file_exists($path))return false;
$this->ext = $this->getext($path);
$this->path = $path;
$img = $this->createimgobj($path);
$this->img = $img;
if(!$img)return false;
//判断是否旋转
if($rotate != 0 && $rotate<360 && $rotate>-360){
$white = $this->color('#ffffff',$img);
$img = imagerotate($img, $rotate, $white);//旋转
}
$this->w = imagesx($this->img);
$this->h = imagesy($this->img);
$this->size = ceil(filesize($this->path)/1024);
$this->whbili = $this->w/$this->h;
$this->bool = true;
}
/**
获取图片对象
*/
public function createimgobj($path)
{
$ext = $this->getmime($path);
$img = false;
switch ($ext){
case 'image/gif':
$img=imagecreatefromgif($path);
break;
case 'image/png':
$img=imagecreatefrompng($path);
break;
default:
$img=imagecreatefromjpeg($path);
break;
}
return $img;
}
public function conver($opath, $npath)
{
if(!file_exists($opath))return;
$img = $this->createimgobj($opath);
$this->saveas($npath, $img);
}
/**
获取图片的格式
*/
public function getext($img_name)
{
$type = strtolower(substr($img_name,strrpos($img_name,'.')+1));
return $type;
}
public function getmime($img_name)
{
$mime = '';
if(file_exists($img_name)){
$fileobj = getimagesize($img_name);
$mime = strtolower($fileobj['mime']);
$this->mime = $mime;
}
return $mime;
}
/**
添加文字水印
$str 添加文字
*/
public function addwater($str,$color='#000000',$size=20,$align='rb')
{
if(!$this->bool)return;
$font = '../fonts/FZZHYJW.TTF'; //方正稚艺简体
$lw = strlen($str)*($size/2);
$lh = $size*0.5;
$color = $this->color($color,$this->img);
$x = 2;
$y = 2;
switch($align){
case 'rb'://右下角
$x = $this->w - $lw-2;
$y = $this->h - $lh-2;
break;
case 'tr'://右上角
$x = $this->w - $lw-2;
break;
case 'lb'://左下角
$y = $this->h - $lh-2;
break;
case 'cn'://居中
$x = ($this->w - $lw) * 0.5;
$y = ($this->h - $lh) * 0.5;
break;
}
imagettftext($this->img, $size,0, $x, $y, $color, $font, $str);
$sapath = str_replace('.'.$this->ext.'', '_water.'.$this->ext.'', $this->path);
$sapath = $this->path;
$this->saveas($sapath, $this->img);//另存为
}
/**
添加图片水印
@params $align 图片位置
*/
public function imgwater($imgpath,$align='rb')
{
if(!$this->bool || !file_exists($imgpath))return;
list($lw, $lh) = getimagesize($imgpath);
$logoimg = $this->createimgobj($imgpath);
$x = 2;
$y = 2;
switch($align){
case 'rb'://右下角
$x = $this->w - $lw-2;
$y = $this->h - $lh-2;
break;
case 'tr'://右上角
$x = $this->w - $lw-2;
break;
case 'lb'://左下角
$y = $this->h - $lh-2;
break;
case 'cn'://居中
$x = ($this->w - $lw) * 0.5;
$y = ($this->h - $lh) * 0.5;
break;
}
imagecopymerge($this->img, $logoimg, $x ,$y ,0 ,0 ,$lw ,$lh, 100);
$this->saveas($this->path, $this->img);
}
/**
创建颜色
*/
public function color($color,$img)
{
if(!empty($color)&&(strlen($color)==7)){
$r=hexdec(substr($color,1,2));
$g=hexdec(substr($color,3,2));
$b=hexdec(substr($color,5));
}else{
$r=$g=$b='00';
}
return imagecolorallocate($img, $r, $g, $b);
}
public function colorTorgb($color)
{
if(!empty($color)&&(strlen($color)==7)){
$r=hexdec(substr($color,1,2));
$g=hexdec(substr($color,3,2));
$b=hexdec(substr($color,5));
}else{
$r=$g=$b='00';
}
return array($r, $g, $b);
}
public function colorToHsl($color)
{
$rgba = $this->colorTorgb($color);
$r = floatval($rgba[0])/255;
$g = floatval($rgba[1])/255;
$b = floatval($rgba[2])/255;
$rgb = array($r, $g, $b);
$max = max($rgb);
$min = min($rgb);
$diff = $max - $min;
if ($max == $min) {
$h = 0;
} else if ($max == $r && $g >= $b) {
$h = 60 * (($g - $b) / $diff);
} else if ($max == $r && $g < $b) {
$h = 60 * (($g - $b) / $diff) + 360;
} else if ($max == $g) {
$h = 60 * (($b - $r) / $diff) + 120;
} else if ($max == $b) {
$h = 60 * (($r - $g) / $diff) + 240;
}
$l = ($max + $min) / 2;
if ($l == 0 || $max == $min) {
$s = 0;
} else if (0 < $l && $l <= 0.5) {
$s = $diff / (2 * $l);
} else if ($l > 0.5) {
$s = $diff / (2 - 2 * $l);
}
return array($h, round($s*100,2), round($l*100,2));
}
/**
注销图片
*/
private function destroy()
{
imagedestroy($this->img);
}
/**
另存图片
*/
private function saveas($spath,$img)
{
$ext = $this->getmime($spath);
$this->saveass($ext, $img, $spath);
}
private function saveass($ext,$img, $spath)
{
switch($ext){
case 'image/gif':
imagegif($img,$spath);
break;
case 'image/png':
imagepng($img,$spath);
break;
case 'image/bmp':
imagewbmp($img,$spath);
break;
default:
imagejpeg($img,$spath,80);
break;
}
}
/**
* 压缩图片
*/
public function compress($w,$h)
{
if(!$this->bool)return '';
$bili = 1;
$nh = $h;
$nw = $w;
if($w < $this->w){
$bili = $w / $this->w;
$nh = $bili * $this->h;
}
if($h>0 && $nh > $h){
$bili = $h / $this->h;
$nh = $h;
$nw = $bili * $this->w;
}
if($bili==1)return '';
$yspath = str_replace('.'.$this->ext.'', 'y.'.$this->ext.'', $this->path);
return $this->thumbnail($nw, $nh, 0, $yspath);
}
/**
图片缩略图
@param $w 宽
@param $h 高
*/
public function thumbnail($w,$h,$lx=0, $sapath='')
{
if(!$this->bool)return '';
list($mw, $mh, $bili) = $this->imgwh($w,$h);
$tmpimg = imagecreatetruecolor($w,$h);
imagefill($tmpimg,0,0,$this->color('#ffffff',$tmpimg));
$tx = 0;
$ty = 0;
//开始截的位置
$sx = 0;
$sy = 0;
if($w > $mw){
if($lx==1){//整图缩略可以看到白边
$tx = ($w-$mw)/2;
}else if($lx == 0){//可能去掉看不到的
$mw = $w;
$mh = $mw/$this->whbili;
$nbl= $mh/$this->h;
$sy = ($mh-$h)/2/$nbl; //当前缩放比例
}
}
if($h > $mh){
if($lx==1){
$ty = ($h-$mh)/2;
}else if($lx == 0){
$mh = $h;
$mw = $mh*$this->whbili;
$nbl= $mw/$this->w;
$sx = ($mw-$w)/2/$nbl; //当前缩放比例
}
}
//imagecopyresized
imagecopyresampled($tmpimg, $this->img, $tx,$ty, $sx,$sy, $mw,$mh,$this->w,$this->h);//生成缩略图
//$sapath = str_replace('.'.$this->ext.'', '_thumb'.$w.'x'.$h.'.'.$this->ext.'', $this->path);
if($sapath=='')$sapath = str_replace('.'.$this->ext.'', '_s.'.$this->ext.'', $this->path);
$this->saveass($this->mime ,$tmpimg, $sapath);//保存图片
return $sapath;
}
/**
图片显示宽高
*/
public function imgwh($mw,$mh)
{
$w = $this->w;
$h = $this->h;
$bili=1;
if($w>$mw){
$bili=($mw/$w);
$h=$bili*$h;
$w=$mw;
}
if($h>$mh){
$bili=($mh/$this->h);
$w=$bili*$this->w;
$h=$mh;
}
return array($w,$h,$bili);
}
}

View File

@@ -0,0 +1,317 @@
<?php
/**
* imap 收邮件扩展
imap_search 使用返回Id
http://php.net/manual/en/function.imap-search.php
ALL 返回所有合乎标准的信件
ANSWERED 信件有配置 \\ANSWERED 标志者
BCC "字符串" Bcc 栏中有指定 "字符串" 的信件
BEFORE "日期" 指定 "日期" 以前的信件
BODY "字符串" 内文字段中有指定 "字符串" 的信件
CC "字符串" Cc 栏中有指定 "字符串" 的信件
DELETED 合乎已删除的信件
FLAGGED 信件有配置 \\FLAGGED 标志者
FROM "字符串" From 栏中有指定 "字符串" 的信件
KEYWORD "字符串" 关键字为指定 "字符串" 者
NEW 新的信件
OLD 旧的信件
ON "日期" 指定 "日期" 的信件
RECENT 信件有配置 \\RECENT 标志者
SEEN 信件有配置 \\SEEN 标志者
SINCE "日期" 指定 "日期" 之后的信件
SUBJECT "字符串" Subject 栏中有指定 "字符串" 的信件
TEXT "字符串" Text 栏中有指定 "字符串" 的信件
TO "字符串" To 栏中有指定 "字符串" 的信件
UNANSWERED 未回应的信件
UNDELETED 未删除的信件
UNFLAGGED 未配置标志的信件
UNKEYWORD "字符串" 未配置关键 "字符串" 的信件
UNSEEN 未读取的信件
*/
class imapChajian extends Chajian
{
private $supportbool = true;
protected function initChajian()
{
$this->supportbool = $this->isimap();
$this->marubox = false;
}
public function isimap()
{
return function_exists('imap_open');
}
/**
* 读取某日期后的邮件
* @params $link 服务器
* @params $user 邮箱
* @params $pass 邮箱密码
* @params $time 时间戳默认7天前的
*/
public function receemail($link, $user, $pass, $time=0)
{
if(isempt($link))return '未设置收邮件imap服务器';
if(isempt($user))return '用户未设置邮箱';
if(isempt($pass))return '邮箱['.$user.']未设置密码';
if(!$this->supportbool)return '系统未开启imap收邮件扩展';
$this->marubox = @imap_open($link,$user,$pass);
$this->struck_tearr = array();
if(!$this->marubox)return '不能连接到['.$link.']可能帐号密码有错';
if($time == 0)$time = time() - 7*24*3600;
$ondt = date('j M Y', $time);
$searcharr = imap_search($this->marubox, 'SINCE "'.$ondt.'"');//指定日期之后
$rows = array();
//return $searcharr;
if($searcharr)foreach($searcharr as $k=>$i){
$headers = $this->getheader($i);
$body = $this->getBody($i);
$headers['body'] = $body;
$headers['num'] = $i;
$headers['attach'] = $this->getattach($i);
$rows[] = $headers;
}
imap_close($this->marubox, CL_EXPUNGE);
return $rows;
$totalrows = imap_num_msg($this->marubox); //取得信件数
$rows = array();
for ($i=1;$i<=$totalrows;$i++){
$headers = $this->getheader($i); //获取某信件的标头信息
$body = $this->getBody($i); //获取信件正文
$headers['body'] = $body;
$headers['num'] = $i;
$headers['attach'] = $this->getattach($i);
$rows[] = $headers;
}
imap_close($this->marubox, CL_EXPUNGE);
return $rows;
}
/**
* 下载附件
*/
public function downattach($link, $user, $pass, $num, $key)
{
}
private function getfetchstructure($i)
{
if(!isset($this->struck_tearr[$i])){
$struck = imap_fetchstructure($this->marubox,$i);
}else{
$struck = $this->struck_tearr[$i];
}
return $struck;
}
/**
* 获取附件
*/
private function getattach($i)
{
$arr = array();
$struck = $this->getfetchstructure($i);
if($struck && isset($struck->parts))foreach($struck->parts as $key=>$val){
if($val->subtype=='OCTET-STREAM'){
if(isset($val->dparameters[0]))$arr[] = array(
'filename' => $this->_imap_utf8($val->dparameters[0]->value),
'filesize' => $val->bytes,
'encoding' => $val->encoding,
'filekey' => $key,
'attachcont' => $this->getattachcont($i, $key, $val->encoding) //获取附件内容
);
}
}
return $arr;
}
/**
* 附件内容读取,需要额外读取
*/
public function getattachcont($i, $key, $encoding)
{
$message = imap_fetchbody($this->marubox, $i, $key + 1);
switch ($encoding) {
case 0:
$message = imap_8bit($message);
break;
case 1:
$message = imap_8bit($message);
break;
case 2:
$message = imap_binary($message);
break;
case 3:
$message = imap_base64($message);
break;
case 4:
$message = quoted_printable_decode($message);
break;
case 5:
$message = $message;
break;
}
return $message;
}
private function getkevel($st, $kdy, $dev='')
{
return objvalue($st, $kdy, $dev);
}
/**
* 获取某信件的标头信息
*/
private function getheader($i)
{
$headers = imap_header($this->marubox, $i);
$arr['subject'] = $this->_imap_utf8($this->getkevel($headers,'subject'));//标题
$arr['message_id'] = $this->getkevel($headers,'message_id');//邮件ID
$arr['size'] = $this->getkevel($headers,'Size','0'); //邮件大小
$arr['date'] = date('Y-m-d H:i:s', strtotime($this->getkevel($headers,'date')));
$arr['to'] = array();
$arr['from'] = array();
//发给
if(isset($headers->to)){
$arr['to'] = $headers->to;
foreach($arr['to'] as $k=>$rs){
$arr['to'][$k]->personal = $this->_imap_utf8($this->getkevel($rs, 'personal'));
$arr['to'][$k]->email = ''.$rs->mailbox.'@'.$rs->host.'';
}
}
$arr['toemail'] = $this->stremail($arr['to']);
//发件人
if(isset($headers->from)){
$arr['from'] = $headers->from;
foreach($arr['from'] as $k=>$rs){
$arr['from'][$k]->personal = $this->_imap_utf8($this->getkevel($rs, 'personal'));
$arr['from'][$k]->email = ''.$rs->mailbox.'@'.$rs->host.'';
}
}
$arr['fromemail'] = $this->stremail($arr['from']);
//回复的邮件
if(isset($headers->reply_to)){
$arr['reply_to'] = $headers->reply_to;
foreach($arr['reply_to'] as $k=>$rs){
$arr['reply_to'][$k]->personal = $this->_imap_utf8($this->getkevel($rs, 'personal'));
$arr['reply_to'][$k]->email = ''.$rs->mailbox.'@'.$rs->host.'';
}
$arr['reply_toemail'] = $this->stremail($arr['reply_to']);
}else{
$arr['reply_toemail'] = $arr['fromemail'];
}
//抄送
$arr['cc'] = array();
if(isset($headers->cc)){
$arr['cc'] = $headers->cc;
foreach($arr['cc'] as $k=>$rs){
$arr['cc'][$k]->personal = $this->_imap_utf8($this->getkevel($rs, 'personal'));
$arr['cc'][$k]->email = ''.$rs->mailbox.'@'.$rs->host.'';
}
}
$arr['ccemail'] = $this->stremail($arr['cc']);
$arr['headers'] = $headers;
return $arr;
}
private function stremail($arr)
{
$str = '';
if(is_array($arr))foreach($arr as $k=>$rs){
$str.=','.$rs->personal.'('.$rs->mailbox.'@'.$rs->host.')';
}
if($str!='')$str = substr($str, 1);
return $str;
}
private function _imap_utf8($text) {
$text = iconv_mime_decode($text,0, 'UTF-8');
return $text;
}
private function _iconv_utf8($text) {
$encode = mb_detect_encoding($text, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
if($encode != 'UTF-8'){
return @iconv($encode, 'utf-8', $text);
}else{
return $text;
}
@$s1 = iconv('gbk', 'utf-8', $text);
$s0 = iconv('utf-8', 'gbk', $s1);
if ($s0 == $text) {
return $s1;
} else {
return $text;
}
}
function get_mime_type(&$structure) { //Get Mime type Internal Private Use
$primary_mime_type = array("TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER");
if ($structure->subtype) {
return $primary_mime_type[(int) $structure->type] . '/' . $structure->subtype;
}
return "TEXT/PLAIN";
}
private function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) { //Get Part Of Message Internal Private Use
if (!$structure) {
$structure = $this->getfetchstructure($msg_number);;
}
if ($structure) {
if ($mime_type == $this->get_mime_type($structure)) {
if (!$part_number) {
$part_number = "1";
}
$text = imap_fetchbody($stream, $msg_number, $part_number);
if ($structure->encoding == 3) {
return imap_base64($text);
} else if ($structure->encoding == 4) {
return imap_qprint($text);
} else {
return $text;
}
}
if ($structure->type == 1) /* multipart */ {
while (list($index, $sub_structure) = each($structure->parts)) {
$prefix = '';
if ($part_number) {
$prefix = $part_number . '.';
}
$data = $this->get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
if ($data) {
return $data;
}
}
}
}
return false;
}
/**
* 获取邮件内容
*/
private function getBody($mid) {
$body = $this->get_part($this->marubox, $mid, "TEXT/HTML");
if ($body == "") {
$body = $this->get_part($this->marubox, $mid, "TEXT/PLAIN");
}
if ($body == "") {
return "";
}
return $this->_iconv_utf8($body);
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* 图片验证码
*/
class imgcodeChajian extends Chajian{
public function check($key,$val)
{
if(isempt($val))return false;
$code = 'abc'.$val.'';
$geval = c('cache')->get('code'.$key.'');
if(md5($code)!=$geval)return false;
c('cache')->del('code'.$key.'');
return true;
}
public function show($key)
{
header("Content-type:image/gif");
$a = rand(0,9);
$b = rand(0,9);
$h = 30;
$code = 'abc'.($a+$b).'';
$w = 70;
$im = imagecreatetruecolor($w,$h);
c('cache')->set('code'.$key.'', md5($code), 5*60);
$bg = imagecolorallocate($im,255,255,255);
imagefill($im,0,0,$bg); //添加背景颜色
$black = imagecolorallocate($im,0,0,0);
for($i=0;$i<2;$i++){//画线条
$at1=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,0,rand(0,$h),$w,rand(0,$h),$at1);
}
for($i=0;$i<200;$i++){//画点
$at1=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im,rand(0,$w),rand(0,$h),$at1);
}
imagestring($im,5,rand(0,30),rand(0,$h-15),''.$a.'+'.$b.'=?',$black);
imagegif($im);
imagedestroy($im);
}
}

View File

@@ -0,0 +1,443 @@
<?php
/**
* 系统表单插件
*/
class inputChajian extends Chajian
{
public $fieldarr = array();
public $flow = null;
public $ismobile = 0;
public $urs = array();
public $mid = 0;
protected function initChajian()
{
$this->date = $this->rock->date;
$this->now = $this->rock->now;
$this->option = m('option');
}
public function initUser($uid)
{
$this->adminid = $uid;
$this->urs = m('admin')->getone($uid, '`name`,`deptname`');
$this->adminname= $this->urs['name'];
}
public function initFields($stwhe='')
{
$fieldarr = m('flow_element')->getrows($stwhe,'*','`sort`');
foreach($fieldarr as $k=>$rs){
$this->fieldarr[$rs['fields']] = $rs;
}
return $fieldarr;
}
/**
* 读取表单样式(有默认值的)
*/
public function getfieldcontval($fid, $val=false, $objs=null)
{
return $this->getfieldcont($fid, $objs,'',0, $val);
}
/**
* 读取表单样式
*/
public function getfieldcont($fid, $objs=null, $leox='', $iszb=0, $deval=false)
{
$fida= explode(',', $fid);$xu0='0';
$ism = $this->ismobile;
$fid = $fida[0];
$str = $val ='';
if(isset($fida[1]))$xu0=$fida[1];
if($fid=='base_name'){
$str = '<input class="inputs" style="border:none;background:none" name="base_name" value="'.$this->adminname.'" readonly>';
}
if($fid=='base_deptname'){
$str = '<input class="inputs" style="border:none;background:none" name="base_deptname" value="'.$this->urs['deptname'].'" readonly>';
}
if($fid=='base_sericnum'){
$str = '<input class="inputs" style="border:none;background:none" name="base_sericnum" value="'.$this->flow->createnum().'" readonly>';
}
if($fid=='file_content'){
$str = '<input name="fileid" type="hidden" id="fileidview-inputEl"><div id="view_fileidview" style="width:98%;height:auto;min-height:60px;border:1px #cccccc solid; background:white;overflow:auto"></div><div id="fileupaddbtn"><a href="javascript:;" class="blue" onclick="c.upload()"><u>+添加文件</u></a></div>';
}
if($fid=='删'){
$str='<a href="javascript:;" onclick="c.delrow(this,'.$xu0.')">删</a>';
}
if($fid=='新增'){
$str='<a href="javascript:;" onclick="c.addrow(this,'.$xu0.')">+新增</a>';
}
if($str!='')return $str;
if(!isset($this->fieldarr[$fid]))return '';
$isasm = 1;
$a = $this->fieldarr[$fid];
$fname = $fid.$leox;
$type = $a['fieldstype'];
$placeholder = arrvalue($a, 'placeholder');
$isbt = arrvalue($a, 'isbt');
$data = $a['data'];
$val = $a['dev'];
if(isset($a['value']))$val=$a['value'];
$attr = $a['attr'];
$lens = (int)arrvalue($a, 'lens','0');
$styles = '';
$style = '';
if(contain($attr,',')){
$attra = explode(',', $a['attr']);
$style = $attra[1];
$attr = $attra[0];
}
if(!isempt($style))$styles=' style="'.$style.'"';
$fnams = $this->rock->arrvalue($a,'name');$fieldname = $fnams;
if($isbt==1)$fnams='*'.$fnams.'';
$val = $this->rock->get('def_'.$fname.'', $val);
if(isempt($val))$val='';
if($deval !== false)$val = $deval; //设置默认值
if(isempt($attr))$attr='';
if($val!='' && contain($val,'{')){
$val = m('base')->strreplace($val, $this->adminid, 1);
if($val=='{sericnum}' && $this->flow!=null)$val = $this->flow->createnum();
}
if($type=='num'){
if($this->flow != null){
$val = $this->flow->createinputnum($data, $fid);
}
}
//读默认值
if($objs != null && method_exists($objs, 'inputfieldsval')){
$_vals = $objs->inputfieldsval($fname, $a);
if(!isempt($_vals))$val = $_vals;
}
if(!isempt($placeholder))$attr.=' placeholder="'.$placeholder.'"';
if($type=='email' || $type=='tel' || $type=='mobile' || $type=='url'){
$attr.=' inputtype="'.$type.'"';
}
$lenstr = '';
if($lens>0)$lenstr=' maxlength="'.$lens.'"';
$onblue = ' onblur="c.inputblur(this, '.$iszb.')"';
$iszhang= false;
$str = '<input class="inputs" type="text" value="'.$val.'" '.$attr.''.$onblue.''.$styles.''.$lenstr.' name="'.$fname.'">';
if($type=='fixed'||$type=='hidden'){
$str = '<input value="'.$val.'" '.$attr.' type="hidden" name="'.$fname.'">';
$isasm=0;
}
if($type=='textarea'){
$iszhang= false;
$str = '<textarea class="textarea" onblur="js.changdu(this)" style="height:80px;'.$style.'" '.$attr.''.$lenstr.' name="'.$fname.'">'.$val.'</textarea>';
}
if($type=='rockcombo' || $type=='select' || $type=='checkboxall' || $type=='radio'){
$attr.=' onchange="c.inputblur(this, '.$iszb.')"';
$str ='<select style="width:99%;'.$style.'" '.$attr.' name="'.$fname.'" class="inputs">';
$str.='<option value="">-请选择-</option>';
$str1= '';
$str2= '';
$datanum = $data;
$fopt = $this->getdatastore($type, $objs, $datanum, $fid);
$optgroup = '';
if($fopt)foreach($fopt as $k=>$rs){
$_val= arrvalue($rs,'value', $rs['name']);
$sel = ($_val==$val)?'selected':'';
$sel2 = ($_val==$val)?'checked':'';
$ocn = '';
if($type=='select')foreach($rs as $k1=>$v1)if($k1!='id'&&$k1!='value'&&$k1!='name')$ocn.=' '.$k1.'="'.$v1.'"';
if($type=='select' && isset($rs['optgroup']) && !isempt($rs['optgroup'])){
if($optgroup!=$rs['optgroup']){
if($optgroup!='')$str.='</optgroup>';
$str.='<optgroup label="'.$rs['optgroup'].'">';
}
$optgroup = $rs['optgroup'];
}
$str.='<option'.$ocn.' value="'.$_val.'" '.$sel.'>'.$rs['name'].'</option>';
$str1.='<label><input name="'.$fname.'[]" value="'.$_val.'" type="checkbox">'.$rs['name'].'</label>&nbsp;&nbsp;';
$str2.='<label><input'.$ocn.' name="'.$fname.'" '.$sel2.' value="'.$_val.'" type="radio">'.$rs['name'].'</label>&nbsp;&nbsp;';
}
if($type=='select' && $optgroup!='')$str.='</optgroup>';
$str.='</select>';
if($type=='checkboxall')$str = $str1;
if($type=='radio')$str = $str2;
}
if($type=='datetime'||$type=='date'||$type=='time'||$type=='month'){
$str = '<input onclick="js.datechange(this,\''.$type.'\')" value="'.$val.'" '.$attr.''.$onblue.''.$styles.' class="inputs datesss" inputtype="'.$type.'" readonly name="'.$fname.'">';
}
//数字类型
if($type=='number'){
$str = '<input class="inputs" '.$attr.''.$styles.' value="'.$val.'" type="number" onfocus="js.focusval=this.value" '.$lenstr.' onblur="js.number(this);c.inputblur(this,'.$iszb.')" name="'.$fname.'">';
}
if($type=='xuhao'){
$str = '<input class="inputs xuhao" '.$attr.' type="text" value="'.$val.'" name="'.$fname.'">';
$str.= '<input value="0" type="hidden" name="'.$a['fieldss'].$leox.'">';
}
if($type=='changeusercheck'||$type=='changeuser'||$type=='changedept'||$type=='changedeptcheck'||$type=='changedeptusercheck'){
$zbnae = $data;
if($iszb>0)$zbnae = $data.''.($iszb-1).''.$leox.'';
$str = $this->inputchangeuser(array(
'name' => $fname,
'id' => $zbnae,
'value' => $val,
'type' => $type,
'title' => $fieldname,
'changerange' => arrvalue($a, 'gongsi'),
'placeholder' => $placeholder,
'attr' => $onblue,
'style' => '',
));
}
if($type=='selectdatafalse' || $type=='selectdatatrue'){
$str = '<table width="98%" cellpadding="0" border="0"><tr><td width="100%"><input '.$attr.''.$onblue.''.$styles.' class="inputs" style="width:99%" value="'.$val.'" readonly type="text" name="'.$fname.'"></td>';
$str .= '<td nowrap>';
if($isbt=='0')$str .= '<button onclick="c.selectdataclear(\''.$fname.'\',\''.$data.'\','.$iszb.')" class="webbtn" type="button">x</button>';
$str .= '<button type="button" onclick="c.selectdata(\''.$data.'\','.substr($type,10).',\''.$fname.'\',\''.$fieldname.'\','.$iszb.')" class="webbtn">选</button></td></tr></table>';
}
if($type=='ditumap'){
$zbnae = $data;
if($iszb>0)$zbnae = ''.($iszb-1).''.$leox.'';
$str = '<table width="99%" cellpadding="0" border="0"><tr><td width="100%"><input '.$attr.''.$onblue.''.$styles.''.$lenstr.' class="inputs" style="width:99%" value="'.$val.'" type="text" name="'.$fname.'"></td>';
$str .= '<td nowrap>';
if($isbt=='0')$str .= '<button onclick="c.selectmapclear(\''.$fname.'\',\''.$zbnae.'\','.$iszb.')" class="webbtn" type="button">x</button>';
$str .= '<button type="button" onclick="c.selectmap(\''.$fname.'\',\''.$zbnae.'\',\''.$fieldname.'\','.$iszb.')" class="webbtn">选</button></td></tr></table>';
}
if($type=='htmlediter'){
$iszhang= false;
$str = '<textarea class="textarea" style="height:130px;'.$style.'" '.$attr.' name="'.$fname.'">'.$val.'</textarea>';
}
if($type=='checkbox'){
$chk = '';
if($val=='1'||$val=='true')$chk='checked';
$str = '<input name="'.$fname.'" '.$chk.' '.$attr.''.$styles.' type="checkbox" value="1"> ';
}
if($type=='uploadimg'){
$str = '<input name="'.$fname.'" value="'.$val.'" type="hidden">';
$str.= '<img src="images/noimg.jpg" onclick="c.showviews(this)" id="imgview_'.$fname.'" height="100">';
$str.= '<div style="display:" tsye="img" tnam="'.$fname.'" id="filed_'.$fname.'"><a href="javascript:;" onclick="c.uploadimgclear(\''.$fname.'\')">删</a>&nbsp;<input onclick="c.initupss(\''.$fname.'\');" type="file" style="width:120px" accept="image/jpg,image/jpeg,image/png" id="filed_'.$fname.'_inp"></div>';
}
if($type=='uploadfile'){
$str = '<input name="'.$fname.'" value="'.$val.'" type="hidden">';
$str.= '<div style="display:inline-block" id="fileview_'.$fname.'"><div onclick="c.uploadfilei(\''.$fname.'\')" style="display:;border:dashed 1px #cccccc" id="'.$fname.'_divadd" class="upload_items"><img class="imgs" src="images/jia.png"></div></div>';
$str.= '<div style="display:none" tsye="file" tnam="'.$fname.'" tdata="'.$data.'" id="filed_'.$fname.'"><input type="file" style="width:120px" multiple="multiple" id="filed_'.$fname.'_inp"></div>';
}
if($type=='graph'){
$str = '<input name="'.$fname.'" value="'.$val.'" type="hidden">';
$str.= '<div id="graphview_'.$fname.'" >';
$str.= '<button type="button" onclick="c.autograph(\''.$fname.'\',0)" class="webbtn">手写</button><button type="button" onclick="c.autograph(\''.$fname.'\',1)" class="webbtn">引入</button><button onclick="c.autograph(\''.$fname.'\',2)" class="webbtn" type="button">x</button></div>';
}
if($type=='auto'){
$datanum = $data;
if(!isempt($datanum)){
if($objs!=null && method_exists($objs, $datanum)){
$str = $objs->$datanum($this->mid, $this->flow);
}
}
}
if($iszb>0)return $str;
if($isasm==1){
$lx = 'span';if($ism==1)$lx='div';
$str = '<'.$lx.' id="div_'.$fname.'" class="divinput">'.$str.'</'.$lx.'>';
if($ism==1 && $iszb==0){
if($iszhang){
$str = '<tr class="lumtr"><td colspan="2"><div style="padding-left:10px;padding-top:10px">'.$fnams.'</div>'.$str.'</td></tr>';
}else{
$str = '<tr class="lumtr"><td class="lurim" nowrap>'.str_replace(' ','<br>', $fnams).'</td><td width="90%">'.$str.'</td></tr>';
}
}
}
return $str;
}
/**
* 输出选择人员html
*/
public function inputchangeuser($arr=array())
{
$oarr = array(
'name'=>'',
'id'=>'',
'type'=>'changeuser',
'value'=> '',
'valueid'=> '',
'title' => '',
'changerange' => '',
'placeholder' => '',
'attr' => '',
);
foreach($arr as $k=>$v)$oarr[$k]=$v;
$fname = $oarr['name'];
$zbnae = $oarr['id'];
$type = $oarr['type'];
$valea = explode('|', $oarr['value']);
$_vals0 = $valea[0];
$_vals1 = arrvalue($valea,1, $oarr['valueid']);
$str = '<table width="99%" cellpadding="0" border="0"><tr><td width="100%"><input class="inputs" style="width:99%" '.$oarr['attr'].' placeholder="'.$oarr['placeholder'].'" id="change'.$fname.'" value="'.$_vals0.'" readonly type="text" name="'.$fname.'"><input name="'.$zbnae.'" value="'.$_vals1.'" id="change'.$fname.'_id" type="hidden"></td>';
$str .= '<td nowrap><button onclick="js.changeclear(\'change'.$fname.'\')" class="webbtn" type="button">x</button><button id="btnchange_'.$fname.'" onclick="js.changeuser(\'change'.$fname.'\',\''.$type.'\',\''.$oarr['title'].'\' ,{changerange:\''.$oarr['changerange'].'\'})" type="button" class="webbtn">选</button></td></tr></table>';
return $str;
}
private function issql($str)
{
$bo = false;
$str = strtoupper($str);
if(contain($str,' FROM '))$bo=true;
return $bo;
}
public function getdatastore($type, $objs, $datanum, $fid='')
{
$fopt = array();
$tyepa = explode(',','rockcombo,select,checkboxall,radio');
if(!in_array($type, $tyepa) || isempt($datanum))return $fopt;
//判断是不是SQL([SQL] name,value from [Q]abc)
if($this->issql($datanum)){
$sql = str_replace('[SQL]','select ', $datanum);
$sql = m('base')->strreplace($sql);
$rows = $this->db->getall($sql);
if($rows)foreach($rows as $k=>$rs){
$nam = arrvalue($rs,'name');
$val = $nam;
if(isset($rs['id']))$val = $rs['id'];
if(isset($rs['value']))$val = $rs['value'];
$fopt[] = array(
'name' => $nam,
'value' => $val,
);
}
}
//2021-02-26新增新的数据源,开头
if(substr($datanum,0,1)==','){
return $this->sqlstore($datanum);
}
//用:读取model上的数据
if(!$fopt && !isempt($datanum) && contain($datanum,':')){
$tata = explode(',', $datanum);
$acta = explode(':', $tata[0]);
$objs = m($acta[0]);
$tacs = $acta[1];
$cshu1= arrvalue($tata, 1);
if(method_exists($objs, $tacs)){
$fopt = $objs->$tacs($cshu1);
if(is_array($fopt)){
return $fopt;
}
}
}
//自定义方法读取数据源
if(!$fopt && $objs!=null && method_exists($objs, $datanum)){
$fopt = $objs->$datanum($fid,$this->mid);
if(is_array($fopt)){
return $fopt;
}
}
//从flow上读取
if(!$fopt && $this->flow!=null && method_exists($this->flow, $datanum)){
$fopt = $this->flow->$datanum($fid,$this->mid);
if(is_array($fopt)){
return $fopt;
}
}
if(!$fopt && ($type=='rockcombo' || $type=='checkboxall' || $type=='radio')){
$_ars = explode(',', $datanum);
$fopt = $this->option->getselectdata($_ars[0], isset($_ars[2]));
$fvad = 'name';
if(isset($_ars[1])&&($_ars[1]=='value'||$_ars[1]=='id'||$_ars[1]=='num'))$fvad=$_ars[1];
if($fopt){
foreach($fopt as $k=>$rs){
$fopt[$k]['value'] = $rs[$fvad];
}
if($type=='rockcombo' && $fvad=='name' && M=='input'){
//$fopt[] = array('name' => '其它..','value' => $_ars[0],);
}
}
}
if(!$fopt && ($type=='select' || $type=='checkboxall' || $type=='radio')){
$fopt = c('array')->strtoarray($datanum);
$barr = array();
foreach($fopt as $k=>$rs){
$barr[] = array(
'name' => $rs[1],
'value' => $rs[0],
);
}
$fopt = $barr;
}
return $fopt;
}
/**
* 新的获取数据源方法
*/
public function sqlstore($actstr1)
{
$rows = array();
$acta = explode(',', $actstr1);
if(count($acta)>=3){
if($acta[1]){
$cats = explode(','.$acta[1].',', $actstr1);
$sqlw = $cats[1];
}else{
$sqlw = substr($actstr1,2);
}
$sqla = explode('|', $sqlw);
$wher = arrvalue($sqla,2,'1=1');
if(contain($wher,'{'))$wher = m('where')->getstrwhere($wher,$this->adminid);
$wher = str_replace('$','"', $wher);
$rowa = m($sqla[0])->getall($wher,$sqla[1]);
$ndf = 'name';
$vdf = 'id';
if($rowa)foreach($rowa as $k=>$rs1){
if($k==0){
if(!isset($rs1[$ndf])){
foreach($rs1 as $k1=>$v1){$ndf = $k1;break;}
}
if(!isset($rs1[$vdf])){
$xus = 0;
foreach($rs1 as $k1=>$v1){
$xus++;
$vdf = $k1;
if($xus>=2)break;
}
}
}
$rs1['name'] = $rs1[$ndf];
$rs1['value'] = $rs1[$vdf];
$rows[] = $rs1;
}
}
return $rows;
}
/**
* 创建签名图片生成的
*/
public function createqianming($_val)
{
if(isempt($_val))return '';
if(substr($_val,0,10)=='data:image'){
$_vlu = ''.UPDIR.'/'.date('Y-m').'/qmimg'.time().''.rand(10,99).'.png';
$bar= explode(',', $_val);
$bo = $this->rock->createtxt($_vlu, base64_decode($bar[1]));
if($bo)$_val = $_vlu;
}
return $_val;
}
}

View File

@@ -0,0 +1,290 @@
<?php
/**
加密解密插件
*/
class jmChajian extends Chajian{
private $keystr = 'abcdefghijklmnopqrstuvwxyz';
private $jmsstr = '';
public $rocktokenarr = array();
protected function initChajian()
{
$this->initJm();
}
public function initJm()
{
$this->jmsstr = getconfig('randkey');
$this->setRandkey($this->jmsstr);
$this->getkeyshow();
}
public function setRandkey($str)
{
$this->jmsstr = $str;
if(strlen($this->jmsstr)!=26)$this->jmsstr = $this->keystr;
$this->getrocktoken();
}
public function getRandkey()
{
$str = $this->keystr;
$s = '';$len = strlen($str);
$j = $len-1;
for($i=0; $i<$len; $i++){
$r = rand(0, $j);
$zm= substr($str, $r, 1);
$s.= $zm;
$str = str_replace($zm,'',$str);
$j--;
}
return $s;
}
public function getint($str)
{
$len = strlen($str);
$oi = 0;
for($i=0; $i<$len; $i++){
$l = substr($str,$i,1);
$j = ord($l)-90;
$oi+=$j;
}
if($oi<0)$oi=0-$oi;
return $oi;
}
private function getrandstr($oi, $str='')
{
if($str=='')$str=$this->keystr;
if($oi>100)$oi=100;
$len = strlen($str);
$qs = 6;
$s1 = substr($str, 0, $qs);
$s2 = substr($str, $qs, $qs);
$s3 = substr($str, $qs*2, $len-$qs*2);
$s = $s3.$s2.$s1;
if($oi>0)$s=$this->getrandstr($oi-1, $s);
return $s;
}
public function getkeyshow()
{
$str = '~!@#$%^&*()_+{}[];"<>?:-=.';
$len = strlen($this->jmsstr);
$s = '';
for($i=0;$i<$len;$i++){
$l = substr($this->jmsstr,$i,1);
$j = ord($l)-97;
$s.= substr($str,$j,1);
}
return $s;
}
public function base64encode($str)
{
if(isempt($str))return '';
$str = base64_encode($str);
$str = str_replace(array('+', '/', '='), array('!', '.', ':'), $str);
return $str;
}
public function base64decode($str)
{
if(isempt($str))return '';
$str = str_replace(array('!', '.', ':'), array('+', '/', '='), $str);
$str = base64_decode($str);
return $str;
}
private function _getss($lx)
{
$st = '';
if(is_numeric($lx)&&$lx>0){
$st = $this->getrandstr($lx);
}else if(is_string($lx)){
if(strlen($lx)==26)$st=$lx;
}
return $st;
}
public function encrypt($str, $lx='')
{
$st = $this->_getss($lx);
$s = $this->base64encode($str);
$s = $this->encrypts($s, $st);
return $s;
}
public function uncrypt($str, $lx='')
{
$st = $this->_getss($lx);
$s = $this->uncrypts($str, $st);
$s = $this->base64decode($s);
return $s;
}
public function encrypts($str, $a='')
{
if($a=='')$a = $this->jmsstr;
$nstr = '';
if($this->rock->isempt($str)) return $nstr;
$len = strlen($str);
$t = rand(1, 14);
if($t == 10)$t++;
for($i=0; $i<$len; $i++){
$nstr.='0';
$sta = substr($str,$i,1);
$orstr = ''.ord($sta).'';
$ile = strlen($orstr);
for($j=0; $j<$ile; $j++){
$oi = (int)substr($orstr,$j,1)+$t;
$nstr.= substr($a,$oi,1);
}
}
if($nstr != ''){
$nstr = substr($nstr,1);
$nstr.= '0'.$t.'';
}
return $nstr;
}
public function uncrypts($str, $a1='')
{
$nstr = '';
if($this->rock->isempt($str)) return $nstr;
if($a1=='')$a1 = $this->jmsstr;
$a = array();
for($i=0; $i<strlen($a1); $i++)$a[substr($a1, $i, 1)] = ''.$i.'';
$na = explode('0', $str);
$len= count($na);
$r = (int)$na[$len-1];
for($i=0; $i<$len-1; $i++){
$st = $na[$i];
$sl = strlen($st);
$sa = '';
for($j=0; $j<$sl; $j++){
$ha = substr($st,$j,1);
if(isset($a[$ha]))$ha = $a[$ha] - $r;
$sa.=$ha;
}
$sa = (int)$sa;
$nstr.=chr($sa);
}
return $nstr;
}
public function getrocktoken()
{
$toke = $this->rock->get('rocktoken');
$str = $this->uncrypt($toke);
if($toke!='' && !$this->contain($str,'&'))exit('sorry,not found!');
$arr = array('m'=>'index','a'=>'default','d'=>'');
if($str){
$a = explode('&', $str);
foreach($a as $a1){
$a2 = explode('=', $a1);
$arr[$a2[0]] = $a2[1];
}
}
$this->rocktokenarr = $arr;
return $arr;
}
public function gettoken($na, $dev='')
{
$s = $dev;
if(isset($this->rocktokenarr[$na])){
$s = $this->rocktokenarr[$na];
}else{
$s = $this->rock->get($na, $dev);
}
return $s;
}
public function strrocktoken($a=array())
{
$s = '';
foreach($a as $k=>$v){
$s .='&'.$k.'='.$v.'';
}
if($s!=''){
$s = $this->encrypt(substr($s, 1));
}
return $s;
}
public function mcrypt_encrypt($str)
{
if(isempt($str))return '';
if(!function_exists('mcrypt_encrypt'))return $str;
$key = substr(md5($this->jmsstr),0,8);
$getstr = mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
return $this->base64encode($getstr);
}
public function mcrypt_decrypt($str)
{
if(isempt($str))return '';
if(!function_exists('mcrypt_decrypt'))return $str;
$str = $this->base64decode($str);
$key = substr(md5($this->jmsstr),0,8);
$getstr = mcrypt_decrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB);
return trim($getstr);
}
/**
* 字符串加密处理
*/
public function strlook($data,$key='')
{
if(isempt($data))return '';
if($key=='')$key = md5($this->jmsstr);
$x = 0;
$len = strlen($data);
$l = strlen($key);
$char = $str = '';
for ($i = 0; $i < $len; $i++){
if ($x == $l) {
$x = 0;
}
$char .= $key[$x];
$x++;
}
for ($i = 0; $i < $len; $i++){
$str .= chr(ord($data[$i]) + (ord($char[$i])) % 256);
}
return $this->base64encode($str);
}
/**
* 字符串解密
*/
public function strunlook($data,$key='')
{
if(isempt($data))return '';
if($key=='')$key = md5($this->jmsstr);
$x = 0;
$data = $this->base64decode($data);
$len = strlen($data);
$l = strlen($key);
$char = $str = '';
for ($i = 0; $i < $len; $i++){
if ($x == $l) {
$x = 0;
}
$char .= substr($key, $x, 1);
$x++;
}
for ($i = 0; $i < $len; $i++){
if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))){
$str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
}else{
$str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
}
}
return $str;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* 语言包
*/
class langChajian extends Chajian{
//支持的语言包
private $langArray = array('zh-CN','en-US','zh-TW','jp');
private $locallang = 'zh-CN'; //默认的语言包
/**
* 初始化语言包
*/
public function initLang()
{
$moren= getconfig('locallang', $this->locallang);
$lang = $this->rock->get('locallang', $moren);
if(!in_array($lang, $this->langArray))$lang = $moren;
if(!defined('LANG'))define('LANG', $lang);
$langs = str_replace('-','_', $lang);
$langr = str_replace('-','_', $moren);
$obj = c('lang_'.$langs.'');
$objmr = c('lang_'.$langr.'');
$data[$moren] = method_exists($objmr, 'getLang') ? $objmr->getLang() : array();
$data[$lang] = method_exists($obj, 'getLang') ? $obj->getLang() : $data[$moren];
$GLOBALS['langdata'] = $data;
}
}

View File

@@ -0,0 +1,15 @@
<?php
/**
* 语言包(英文),需要自行翻译
*/
class lang_en_USChajian extends Chajian{
public function getLang()
{
$da = array(
);
return $da;
}
}

View File

@@ -0,0 +1,15 @@
<?php
/**
* 语言包
*/
class lang_zh_CNChajian extends Chajian{
public function getLang()
{
$da = array(
);
return $da;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 用libreoffice相关linux和win都可以用
*/
class libreofficeChajian extends Chajian{
/**
* 转pdf
*/
public function filetopdf($fileid)
{
$path = getconfig('libreoffice_path');
if(isempt($path))return returnerror('未配置libreoffice的路径');
$frs = m('file')->getone($fileid);
if(!$frs)return returnerror('文件不存在');
$filepath = $frs['filepath'];
$pdfpath = $frs['pdfpath'];
if(!isempt($pdfpath) && file_exists($pdfpath))return returnerror('已经转化过了');;
$fpath = ''.ROOT_PATH.'/'.$filepath.'';
$outdir = substr($fpath,0, strripos($fpath,'/'));
if(contain(PHP_OS,'WIN')){
$cmd = '"'.str_ireplace('LibreOffice','libreoffice',$path).'\program\soffice.exe"';
$fpath = str_replace('/','\\', $fpath);
$outdir = str_replace('/','\\', $outdir);
}else{
$cmd = $path;
}
$cmd .=' --headless --invisible --convert-to pdf:writer_pdf_Export "'.$fpath.'" --outdir "'.$outdir.'"';
return c('rockqueue')->pushcmd($cmd);
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
PHPMailer 读取插件类
*/
include_once(ROOT_PATH.'/include/PHPMailer/class.phpmailer.php');
include_once(ROOT_PATH.'/include/PHPMailer/class.smtp.php');
class mailerChajian extends Chajian{
private $mail;
private $mailbool;
public function initChajian(){
$this->mail = new PHPMailer();
$this->mail->IsSMTP();
$this->mail->SMTPAuth = true;
$this->mail->SMTPDebug = 0;
$this->mail->CharSet = 'UTF-8';
$this->mailbool = false;
}
public function setHost($host, $port=25, $secure=''){
$this->mail->Host = $host;
$this->mail->SMTPSecure = $secure;
$this->mail->Port = (int)$port;
}
public function setUser($email, $pass){
$this->mail->Username = $email;
$this->mail->Password = $pass;
$this->setFrom($email);
$this->addReplyTo($email);
}
//发件人邮箱地址
public function setFrom($from, $name=''){
$this->mail->SetFrom($from, $this->tojoin($name));
}
//设置回复
public function addReplyTo($address, $name=''){
$this->mail->AddReplyTo($address, $this->tojoin($name));
}
//添加抄送
public function addCC($address, $name=''){
$a1 = explode(',', $address);
$n1 = array();
if($name != '')$n1 = explode(',', $name);
for($i=0; $i<count($a1); $i++){
$na = '';
if(isset($n1[$i]))$na = $n1[$i];
$this->mail->AddCC($a1[$i], $this->tojoin($na));
}
}
//添加秘密送
public function addBCC($address, $name=''){
$a1 = explode(',', $address);
$n1 = array();
if($name != '')$n1 = explode(',', $name);
for($i=0; $i<count($a1); $i++){
$na = '';
if(isset($n1[$i]))$na = $n1[$i];
$this->mail->AddBCC($a1[$i], $this->tojoin($na));
}
}
//添加收件人
public function addAddress($address, $name=''){
$a1 = explode(',', $address);
$n1 = array();
if($name != '')$n1 = explode(',', $name);
for($i=0; $i<count($a1); $i++){
$na = '';
if(isset($n1[$i]))$na = $n1[$i];
$this->mail->AddAddress($a1[$i], $this->tojoin($na));
}
}
//添加附件
public function addAttachment($address, $name=''){
if($this->rock->isempt($address))return;
$a1 = explode(',', $address);
$n1 = array();
if($name != '')$n1 = explode(',', $name);
for($i=0; $i<count($a1); $i++){
$na = '';
if(isset($n1[$i]))$na = $n1[$i];
$this->mail->AddAttachment(ROOT_PATH.'/'.$a1[$i], $this->tojoin($na));
}
}
//发送邮件
public function sendMail($Subject, $body=''){
$this->mail->Subject = $this->tojoin($Subject);
$this->mail->Body = $body;
$this->mail->IsHTML(true);
$this->mailbool = $this->mail->Send();
}
public function isSuccess(){
return $this->mailbool;
}
public function getErrror(){
return $this->mail->ErrorInfo;
}
private function tojoin($name='')
{
if($name=='')return '';
return "=?UTF-8?B?".base64_encode($name)."?=";
}
}

View File

@@ -0,0 +1,13 @@
<?php
class mapqqChajian extends Chajian{
private $mapqqkey = 'I3EBZ-TYP6F-RGZJI-J3W3V-ERKDT-PTBK4';
public function geocoder($location)
{
$url = 'http://apis.map.qq.com/ws/geocoder/v1/?location='.$location.'&coord_type=5&key='.$this->mapqqkey.'';
$result = c('curl')->getcurl($url);
echo $result;
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* 来自:信呼开发团队
* 作者:磐石(rainrock)
* 网址http://www.rockoa.com/
* 自己短信服务
* 此文件放到include/chajian/mysmsChajian.php 下
* 开发帮助地址http://www.rockoa.com/view_mysms.html
*/
class mysmsChajian extends Chajian{
/**
* 短信模版写这里的
*/
protected function initChajian()
{
$mobian['defyzm'] = '您短信验证码为:#code#请勿将验证码提供给他人5分钟内有效。';
$mobian['defsucc'] = '您提交单据(#modename#,单号:#sericnum#)已全部处理完成,可登录系统查看详情。';
$mobian['default'] = '您有单据(#modename#,单号:#sericnum#)需要处理,请登录系统及时去处理。';
$mobian['birthday'] = '尊敬的#name#,今天是#dt#,农历#dtnong#,是您的生日,我们在这里祝您生日快乐。';
$mobian['defnum'] = '您有#applyname#的(#modename#)单据需要您处理,详情:#url#';
$mobian['defurls'] = '您有单据(#modename#,单号:#sericnum#)需要处理,请及时去处理,详情:#url#。';
$mobian['gongsms'] = '您收到一条“#title#”的通知,详情:#url#';
$mobian['meetapply'] = '#optname#发起会议“#title#”在#hyname#,时间#startdt#至#enddt#';
$mobian['meetcancel'] = '#optname#取消会议“#title#”,时间#startdt#至#enddt#,请悉知。';
$mobian['meettodo'] = '会议“#title#”将在#fenz#分钟后的#time#开始请做好准备,在会议室“#hyname#”';
$this->mobianarr = $mobian;
}
/**
* 批量发送短信
* $mobiles 接收人手机号多个,分开
* $qianm 签名
* $tplid 模版编号在上面initChajian()数组中查找
* $cans 模版中的参数数组
* 例子c('mysms')->send('15800000000,15800000001','信呼', 'default', array('modename'=>'模块名','sericnum'=>'单号')); 这例子是不需要自己调用,只要短信设置下切换为“我的短信服务”就可以了
*/
public function send($mobiles, $qianm, $tplid, $cans=array())
{
//要发送短信的内容
$text = arrvalue($this->mobianarr, $tplid);
if(isempt($text))return returnerror('模版'.$tplid.'不存在');
foreach($cans as $k=>$v)$text = str_replace('#'.$k.'#', $v, $text);
//这里你要自己写你发送短信的代码------------
return returnerror('你没有开发自己短信接口,查看'.c('xinhu')->helpstr('mysms').'看如何开发');
//------------------------------------------
return returnsuccess();
}
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* win下将word转html
*/
class officeChajian extends Chajian{
public function tohtml($path)
{
if(!class_exists('COM'))return '没有开启COM组件';
$word = new COM('Word.Application');
$word->Visible = true; //可看见
$word->Documents->Open($path);
$word->Documents[1]->SaveAs('upload/abc.html',8);
}
}

View File

@@ -0,0 +1,449 @@
<?php
class pingyinChajian extends Chajian
{
private $PinYinDB=array(
array("a",-20319),
array("ai",-20317),
array("an",-20304),
array("ang",-20295),
array("ao",-20292),
array("ba",-20283),
array("bai",-20265),
array("ban",-20257),
array("bang",-20242),
array("bao",-20230),
array("bei",-20051),
array("ben",-20036),
array("beng",-20032),
array("bi",-20026),
array("bian",-20002),
array("biao",-19990),
array("bie",-19986),
array("bin",-19982),
array("bing",-19976),
array("bo",-19805),
array("bu",-19784),
array("ca",-19775),
array("cai",-19774),
array("can",-19763),
array("cang",-19756),
array("cao",-19751),
array("ce",-19746),
array("ceng",-19741),
array("cha",-19739),
array("chai",-19728),
array("chan",-19725),
array("chang",-19715),
array("chao",-19540),
array("che",-19531),
array("chen",-19525),
array("cheng",-19515),
array("chi",-19500),
array("chong",-19484),
array("chou",-19479),
array("chu",-19467),
array("chuai",-19289),
array("chuan",-19288),
array("chuang",-19281),
array("chui",-19275),
array("chun",-19270),
array("chuo",-19263),
array("ci",-19261),
array("cong",-19249),
array("cou",-19243),
array("cu",-19242),
array("cuan",-19238),
array("cui",-19235),
array("cun",-19227),
array("cuo",-19224),
array("da",-19218),
array("dai",-19212),
array("dan",-19038),
array("dang",-19023),
array("dao",-19018),
array("de",-19006),
array("deng",-19003),
array("di",-18996),
array("dian",-18977),
array("diao",-18961),
array("die",-18952),
array("ding",-18783),
array("diu",-18774),
array("dong",-18773),
array("dou",-18763),
array("du",-18756),
array("duan",-18741),
array("dui",-18735),
array("dun",-18731),
array("duo",-18722),
array("e",-18710),
array("en",-18697),
array("er",-18696),
array("fa",-18526),
array("fan",-18518),
array("fang",-18501),
array("fei",-18490),
array("fen",-18478),
array("feng",-18463),
array("fo",-18448),
array("fou",-18447),
array("fu",-18446),
array("ga",-18239),
array("gai",-18237),
array("gan",-18231),
array("gang",-18220),
array("gao",-18211),
array("ge",-18201),
array("gei",-18184),
array("gen",-18183),
array("geng",-18181),
array("gong",-18012),
array("gou",-17997),
array("gu",-17988),
array("gua",-17970),
array("guai",-17964),
array("guan",-17961),
array("guang",-17950),
array("gui",-17947),
array("gun",-17931),
array("guo",-17928),
array("ha",-17922),
array("hai",-17759),
array("han",-17752),
array("hang",-17733),
array("hao",-17730),
array("he",-17721),
array("hei",-17703),
array("hen",-17701),
array("heng",-17697),
array("hong",-17692),
array("hou",-17683),
array("hu",-17676),
array("hua",-17496),
array("huai",-17487),
array("huan",-17482),
array("huang",-17468),
array("hui",-17454),
array("hun",-17433),
array("huo",-17427),
array("ji",-17417),
array("jia",-17202),
array("jian",-17185),
array("jiang",-16983),
array("jiao",-16970),
array("jie",-16942),
array("jin",-16915),
array("jing",-16733),
array("jiong",-16708),
array("jiu",-16706),
array("ju",-16689),
array("juan",-16664),
array("jue",-16657),
array("jun",-16647),
array("ka",-16474),
array("kai",-16470),
array("kan",-16465),
array("kang",-16459),
array("kao",-16452),
array("ke",-16448),
array("ken",-16433),
array("keng",-16429),
array("kong",-16427),
array("kou",-16423),
array("ku",-16419),
array("kua",-16412),
array("kuai",-16407),
array("kuan",-16403),
array("kuang",-16401),
array("kui",-16393),
array("kun",-16220),
array("kuo",-16216),
array("la",-16212),
array("lai",-16205),
array("lan",-16202),
array("lang",-16187),
array("lao",-16180),
array("le",-16171),
array("lei",-16169),
array("leng",-16158),
array("li",-16155),
array("lia",-15959),
array("lian",-15958),
array("liang",-15944),
array("liao",-15933),
array("lie",-15920),
array("lin",-15915),
array("ling",-15903),
array("liu",-15889),
array("long",-15878),
array("lou",-15707),
array("lu",-15701),
array("lv",-15681),
array("luan",-15667),
array("lue",-15661),
array("lun",-15659),
array("luo",-15652),
array("ma",-15640),
array("mai",-15631),
array("man",-15625),
array("mang",-15454),
array("mao",-15448),
array("me",-15436),
array("mei",-15435),
array("men",-15419),
array("meng",-15416),
array("mi",-15408),
array("mian",-15394),
array("miao",-15385),
array("mie",-15377),
array("min",-15375),
array("ming",-15369),
array("miu",-15363),
array("mo",-15362),
array("mou",-15183),
array("mu",-15180),
array("na",-15165),
array("nai",-15158),
array("nan",-15153),
array("nang",-15150),
array("nao",-15149),
array("ne",-15144),
array("nei",-15143),
array("nen",-15141),
array("neng",-15140),
array("ni",-15139),
array("nian",-15128),
array("niang",-15121),
array("niao",-15119),
array("nie",-15117),
array("nin",-15110),
array("ning",-15109),
array("niu",-14941),
array("nong",-14937),
array("nu",-14933),
array("nv",-14930),
array("nuan",-14929),
array("nue",-14928),
array("nuo",-14926),
array("o",-14922),
array("ou",-14921),
array("pa",-14914),
array("pai",-14908),
array("pan",-14902),
array("pang",-14894),
array("pao",-14889),
array("pei",-14882),
array("pen",-14873),
array("peng",-14871),
array("pi",-14857),
array("pian",-14678),
array("piao",-14674),
array("pie",-14670),
array("pin",-14668),
array("ping",-14663),
array("po",-14654),
array("pu",-14645),
array("qi",-14630),
array("qia",-14594),
array("qian",-14429),
array("qiang",-14407),
array("qiao",-14399),
array("qie",-14384),
array("qin",-14379),
array("qing",-14368),
array("qiong",-14355),
array("qiu",-14353),
array("qu",-14345),
array("quan",-14170),
array("que",-14159),
array("qun",-14151),
array("ran",-14149),
array("rang",-14145),
array("rao",-14140),
array("re",-14137),
array("ren",-14135),
array("reng",-14125),
array("ri",-14123),
array("rong",-14122),
array("rou",-14112),
array("ru",-14109),
array("ruan",-14099),
array("rui",-14097),
array("run",-14094),
array("ruo",-14092),
array("sa",-14090),
array("sai",-14087),
array("san",-14083),
array("sang",-13917),
array("sao",-13914),
array("se",-13910),
array("sen",-13907),
array("seng",-13906),
array("sha",-13905),
array("shai",-13896),
array("shan",-13894),
array("shang",-13878),
array("shao",-13870),
array("she",-13859),
array("shen",-13847),
array("sheng",-13831),
array("shi",-13658),
array("shou",-13611),
array("shu",-13601),
array("shua",-13406),
array("shuai",-13404),
array("shuan",-13400),
array("shuang",-13398),
array("shui",-13395),
array("shun",-13391),
array("shuo",-13387),
array("si",-13383),
array("song",-13367),
array("sou",-13359),
array("su",-13356),
array("suan",-13343),
array("sui",-13340),
array("sun",-13329),
array("suo",-13326),
array("ta",-13318),
array("tai",-13147),
array("tan",-13138),
array("tang",-13120),
array("tao",-13107),
array("te",-13096),
array("teng",-13095),
array("ti",-13091),
array("tian",-13076),
array("tiao",-13068),
array("tie",-13063),
array("ting",-13060),
array("tong",-12888),
array("tou",-12875),
array("tu",-12871),
array("tuan",-12860),
array("tui",-12858),
array("tun",-12852),
array("tuo",-12849),
array("wa",-12838),
array("wai",-12831),
array("wan",-12829),
array("wang",-12812),
array("wei",-12802),
array("wen",-12607),
array("weng",-12597),
array("wo",-12594),
array("wu",-12585),
array("xi",-12556),
array("xia",-12359),
array("xian",-12346),
array("xiang",-12320),
array("xiao",-12300),
array("xie",-12120),
array("xin",-12099),
array("xing",-12089),
array("xiong",-12074),
array("xiu",-12067),
array("xu",-12058),
array("xuan",-12039),
array("xue",-11867),
array("xun",-11861),
array("ya",-11847),
array("yan",-11831),
array("yang",-11798),
array("yao",-11781),
array("ye",-11604),
array("yi",-11589),
array("yin",-11536),
array("ying",-11358),
array("yo",-11340),
array("yong",-11339),
array("you",-11324),
array("yu",-11303),
array("yuan",-11097),
array("yue",-11077),
array("yun",-11067),
array("za",-11055),
array("zai",-11052),
array("zan",-11045),
array("zang",-11041),
array("zao",-11038),
array("ze",-11024),
array("zei",-11020),
array("zen",-11019),
array("zeng",-11018),
array("zha",-11014),
array("zhai",-10838),
array("zhan",-10832),
array("zhang",-10815),
array("zhao",-10800),
array("zhe",-10790),
array("zhen",-10780),
array("zheng",-10764),
array("zhi",-10587),
array("zhong",-10544),
array("zhou",-10533),
array("zhu",-10519),
array("zhua",-10331),
array("zhuai",-10329),
array("zhuan",-10328),
array("zhuang",-10322),
array("zhui",-10315),
array("zhun",-10309),
array("zhuo",-10307),
array("zi",-10296),
array("zong",-10281),
array("zou",-10274),
array("zu",-10270),
array("zuan",-10262),
array("zui",-10260),
array("zun",-10256),
array("zuo",-10254)
);
private function GetPinYin($num,$type){
$PinYinDB = $this->PinYinDB;
$string='';
if($num>0&&$num<160){
return chr($num);
}
elseif($num<-20319||$num>-10247){
return "";
}else{
for($i=count($PinYinDB)-1;$i>=0;$i--)
{
if($PinYinDB[$i][1]<=$num)break;
}
if($type==1){
for($ii=0;$ii<strlen($PinYinDB[$i][0]);$ii++){
$letter=substr($PinYinDB[$i][0],$ii,1);
if($ii==0){
$letter=strtoupper($letter);
}
$string.=$letter;
}
return $string;
}else if($type == 2){
return substr($PinYinDB[$i][0], 0, 1);
}else{
return $PinYinDB[$i][0];
}
}
}
public function get($str,$type=''){
$ret = '';
@$str = iconv('utf-8','gb2312',$str);
for($i=0;$i<strlen($str);$i++){
$p=ord(substr($str,$i,1));
if($p>160){
$q=ord(substr($str,++$i,1));
$p=$p*256+$q-65536;
}
$ret.=$this->GetPinYin($p,$type);
}
$ret = strtolower($ret);
return $ret;
}
}
//echo get('中国人',1);

View File

@@ -0,0 +1,123 @@
<?php
/**
* 腾讯云上文件存储上传管理
*/
include_once(ROOT_PATH.'/include/cos-php-sdk-v4-master/include.php');
use Qcloud\Cos\Api;
class qcloudCosChajian extends Chajian{
private $bucket = 'xinhuoa';
private $folder = 'defile'; //默认目录
private $region = 'sh'; //默认分区
protected function initChajian()
{
$this->bucket = getconfig('qcloudCos_bucket', $this->bucket);
$this->region = getconfig('qcloudCos_region', $this->region);
$this->folder = getconfig('qcloudCos_folder', $this->folder);
$this->app_id = getconfig('qcloudCos_APPID');
$config = array(
'app_id' => $this->app_id,
'secret_id' => getconfig('qcloudCos_SecretId'),
'secret_key'=> getconfig('qcloudCos_SecretKey'),
'region' => $this->region,
'timeout' => 180
);
$this->cosApi = new Api($config);
}
/**
* 上传文件
* filepath 要上传的文件全路径
* updir 上传到哪个目录
* upname 上传后保存文件名
*/
public function upload($filepath, $updir='', $upname='')
{
if(!file_exists($filepath))return false;
$filea = explode('/', $filepath);
if($upname=='')$upname = $filea[count($filea)-1];
if($updir=='')$updir = $this->folder;
$ret = $this->cosApi->upload($this->bucket, $filepath, ''.$updir.'/'.$upname.'');
if($ret['code']==0)$ret['url'] = $this->geturl().'/'.$updir.'/'.$upname.'';
return $ret;
}
/**
* 创建文件夹
*/
public function createFolder($folder)
{
$ret = Cosapi::createFolder($this->bucket, $folder);
return $ret;
}
/**
* 获取目录下的文件
*/
public function listFolder($folder='', $num=20)
{
if($folder=='')$folder = $this->folder;
$ret = $this->cosApi->listFolder($this->bucket, $folder, $num);
if($ret['code'] != 0){
return returnerror($ret['message']);
}else{
$barr = returnsuccess($ret['data']['infos']);
$barr['folder'] = $folder;
return $barr;
}
}
/**
* 删除文件
*/
public function delFile($path)
{
$ret = $this->cosApi->delFile($this->bucket, $path);
return $ret;
}
public function delListFile()
{
$barr = $this->listFolder('',100);
if($barr['success']){
foreach($barr['data'] as $k=>$rs){
$this->delFile($this->folder.'/'.$rs['name']);
}
}
}
/**
* 下载文件到服务器本地
*/
public function download($srcPath, $dstPath)
{
$res = $this->cosApi->download($this->bucket, $srcPath, $dstPath);
return $res;
}
/**
* 获取外网访问地址
*/
public function geturl()
{
$xarr['nj'] = 'ap-nanjing';
$xarr['cd'] = 'ap-chengdu';
$xarr['bj'] = 'ap-beijing';
$xarr['gz'] = 'ap-guangzhou';
$xarr['sh'] = 'ap-shanghai';
$xarr['cq'] = 'ap-chongqing';
$xarr['bjfsi'] = 'ap-beijing-fsi';
$xarr['szfsi'] = 'ap-shenzhen-fsi';
$xarr['shfsi'] = 'ap-shanghai-fsi';
$xarr['hk'] = 'ap-hongkong';
$qustr = arrvalue($xarr, $this->region,'ap-shanghai');
$url = 'https://'.$this->bucket.'-'.$this->app_id.'.cos.'.$qustr.'.myqcloud.com';
return $url;
}
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* 创建二维码
*/
include_once(ROOT_PATH.'/include/phpqrcode/phpqrcode.php');
class qrcodeChajian extends Chajian
{
public function show($url='')
{
if($url=='')$url = URL;
$errorCorrectionLevel = 'L'; // 纠错级别L、M、Q、H
$matrixPointSize = 6; // 点的大小1到10
$margin = 1; //表示二维码周围边框空白区域间距值;
$bo = QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize, $margin, false);
return $bo;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* 连接官网在线编辑文档
*/
class rockeditChajian extends Chajian{
protected function initChajian()
{
$urs = $this->rock->jm->base64decode('aHR0cDovL29mZmljZS5yb2Nrb2EuY29tLw::');
$url = getconfig('officebj_url', $urs);
$this->agentkey = getconfig('officebj_key');
if(substr($url,-1)!='/')$url.='/';
$this->updatekel = $url;
$this->updatekey = $url.'api.php';
}
public function geturlstr($mod, $act, $can=array())
{
$url = $this->updatekey;
$url.= '?m='.$mod.'&a='.$act.'';
$url.= '&host='.$this->rock->jm->base64encode(HOST).'&ip='.$this->rock->ip.'&xinhukey='.getconfig('xinhukey').'';
$url.= '&adminid='.$this->adminid.'';
$url.= '&agentkey='.$this->agentkey.'';
foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
return $url;
}
/**
* get获取数据
*/
public function getdata($mod, $act, $can=array())
{
$url = $this->geturlstr($mod, $act, $can);
$cont = c('curl')->getcurl($url);
if(!isempt($cont) && contain($cont, 'success')){
$data = json_decode($cont, true);
}else{
$data = returnerror('无法访问,'.$cont.'');
}
return $data;
}
/**
* post发送数据
*/
public function postdata($mod, $act, $can=array())
{
$url = $this->geturlstr($mod, $act);
$cont = c('curl')->postcurl($url, $can);
if(!isempt($cont) && contain($cont, 'success')){
$data = json_decode($cont, true);
}else{
$data = returnerror('无法访问,'.$cont.'');
}
return $data;
}
public function sendedit($id, $admintoken='', $otype=0)
{
$frs = m('file')->getone($id);
if(!$frs)return returnerror('文件不存在');
$filepath = $frs['filepath'];
$filepathout= arrvalue($frs, 'filepathout');
$onlynum = $frs['onlynum'];
$recedata = '';
if(substr($filepath,0,4)!='http' && !file_exists($filepath)){
if(isempt($filepathout))return returnerror('文件不存在2');
$filepath = $filepathout;
$recedata = $filepath;
}
if(isempt($onlynum)){
$onlynum = md5(''.$this->rock->jm->getRandkey().date('YmdHis').'file'.$id.'');
m('file')->update("`onlynum`='$onlynum'", $id);
}
$urs = m('admin')->getone($this->adminid);
$barr = $this->getdata('file','change', array(
'filenum' => $onlynum,
'optid' => $this->adminid,
'optname' => $this->rock->jm->base64encode($this->adminname),
'face' => $this->rock->jm->base64encode(m('admin')->getface($urs['face'])),
));
if(!$barr['success'])return $barr;
$data = $barr['data'];
$type = $data['type'];
$gokey = $data['gokey'];
$gourl = arrvalue($data,'gourl');
if(isempt($gourl))$gourl = $this->updatekel;
$bsar = $data;
if($type=='0'){
if($recedata=='')$recedata = $this->rock->jm->base64encode(file_get_contents($filepath));
$barr = $this->postdata('file','recedata', array(
'data' => $recedata,
'fileid' => $id,
'filenum' => $onlynum,
'fileext' => $frs['fileext'],
'filename' => $frs['filename'],
'optid' => $frs['optid'],
'optname' => $frs['optname'],
'filesize' => $frs['filesize'],
'filesizecn'=> $frs['filesizecn'],
));
if(!$barr['success'])return $barr;
$bsar['type'] = '1';
}
if($bsar['type']=='1'){
$url = $gourl.'api.php?m=file&a=goto&filenum='.$onlynum.'&sign='.md5($this->rock->HTTPweb).'';
$url.= '&optid='.$this->adminid.'';
$url.= '&gokey='.$gokey.'';
$url.= '&otype='.$otype.'';
if($otype==0){
$callurl = $this->rock->getouturl().'api.php?m=upload&a=upfilevb&fileid='.$id.'&adminid='.$this->adminid.'&token='.$admintoken.'';
$url.='&callurl='.$this->rock->jm->base64encode($callurl).'';
}
$bsar['url'] = $url;
}
return returnsuccess($bsar);
}
}

View File

@@ -0,0 +1,155 @@
<?php
/**
* 文件上传管理中心相关接口
*/
class rockfileChajian extends Chajian{
protected function initChajian()
{
$url = getconfig('rockfile_url');
$urlb = getconfig('rockfile_localurl');
if($urlb)$url = $urlb;
$this->agentkey = getconfig('rockfile_key');
if(substr($url,-1)!='/')$url.='/';
$this->updatekel = $url;
$this->updatekey = $url.'api.php';
}
public function geturlstr($mod, $act, $can=array())
{
$url = $this->updatekey;
$url.= '?m='.$mod.'&a='.$act.'';
$url.= '&agentkey='.$this->agentkey.'';
$url.= '&websign='.md5($this->rock->HTTPweb).'';
foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
return $url;
}
/**
* get获取数据
*/
public function getdata($mod, $act, $can=array())
{
$url = $this->geturlstr($mod, $act, $can);
$cont = c('curl')->getcurl($url);
if(!isempt($cont) && contain($cont, 'success')){
$data = json_decode($cont, true);
}else{
$data = returnerror('无法访问,'.$cont.'');
}
return $data;
}
/**
* post发送数据
*/
public function postdata($mod, $act, $can=array(), $cans=array())
{
$url = $this->geturlstr($mod, $act, $cans);
$cont = c('curl')->postcurl($url, $can);
if(!isempt($cont) && contain($cont, 'success')){
$data = json_decode($cont, true);
}else{
$data = returnerror('无法访问,'.$cont.'');
}
return $data;
}
/**
* 同步保存到自己的库
*/
public function getsave($fnum)
{
if(!$fnum)return $fnum;
$nums = '';
$fanu = explode(',', $fnum);
$ids = '';
foreach($fanu as $st1){
if(is_numeric($st1)){
$ids.=','.$st1.'';
}else{
$nums.=','.$st1.'';
}
}
if($nums){
$nums = substr($nums, 1);
$barr = $this->getdata('upload','filesaveinfo',array('nums'=>$nums));
return $barr;
}else{
return returnerror('error');
}
}
/**
* 删除文件
*/
public function filedel($nums)
{
$barr = $this->getdata('upload','filedel',array('nums'=>$nums));
return $barr;
}
/**
* 上传
*/
public function uploadfile($fileid)
{
$frs = m('file')->getone($fileid);
if(!$frs)return returnerror('1');
$path = ROOT_PATH.'/'.$frs['filepath'];
if(!file_exists($path))return returnerror('404');
$barr = $this->upload($path, array(
'optid' => $frs['optid'],
'noasyn' => 'no', //no和yes
'fileexs' => $frs['fileext'],
'optname' => $this->rock->jm->base64encode($frs['optname']),
'filename' => $this->rock->jm->base64encode($frs['filename']),
));
if(!$barr['success'])return $barr;
$data = $barr['data'];
$filenum = arrvalue($data, 'filenum');
$thumbpath = arrvalue($data, 'thumbpath');
if($filenum){
$guar['filenum'] = $filenum;
if($thumbpath)$guar['thumbplat'] = $thumbpath;
m('file')->update($guar,$fileid);
unlink($path);
$path = ROOT_PATH.'/'.$frs['thumbpath'];
if($path && file_exists($path))unlink($path);
}
return $barr;
}
/**
* 上传文件(分割发送)
*/
public function upload($path,$upcs=array(), $fcs=0.5)
{
if(!file_exists($path))return returnerror('404');
$oi = 0;
$fp = fopen($path,'rb');
$filesize= filesize($path);
$fileext = c('upfile')->getext($path);
$size = $fcs*1024*1024;
$zong = ceil($filesize/$size);
if($zong<=0)$zong = 1;
$barr = false;
$biaoshi = rand(100000,999999);
while(!feof($fp)){
$cont = fread($fp, $size);
$conts= base64_encode($cont);
$upcan= array('ci'=>$oi,'biaoshi'=>$biaoshi,'zong'=>$zong,'filesize' => $filesize,'fileext'=>$fileext);
foreach($upcs as $k=>$v)$upcan[$k] = $v;
$barr = $this->postdata('upfile','index', $conts, $upcan);
if(!$barr['success'])break;
$oi++;
}
fclose ($fp);
if($barr)return $barr;
return returnerror('无效文件');
}
}

View File

@@ -0,0 +1,175 @@
<?php
/**
* 信呼中node队列的处理
*/
class rockqueueChajian extends Chajian
{
//队列服务器主机
private $rockqueue_host = '127.0.0.1';
//队列服务端口数字类型为0从服务器设置上读取
private $rockqueue_port = 0;
//初始化配置读取
protected function initChajian()
{
$this->rockqueue_host = getconfig('rockqueue_host', $this->rockqueue_host);
$this->rockqueue_port = getconfig('rockqueue_port', $this->rockqueue_port);
if($this->rockqueue_port==0){
$reim = m('reim');
$reimhot = $reim->getpushhostport($reim->serverpushurl);
$this->rockqueue_host = $reimhot['host'];
$this->rockqueue_port = $reimhot['port'];
}
$this->cmdshell = array(
array('soffice.exe','php.exe'), //win下必须包含
array('libreoffice'), //Linux下包含
array('pdf:writer_pdf_Export') //命令里至少要有一个
);
}
/**
* 发送队列信息
* $cont 内容可以是http地址也可以如:cli,run
* $param 参数
* 使用 c('rockqueue')->push('cli,run');
*/
public function push($cont, $param=array(), $runtime=0, $id=0)
{
$type = 'cmd';
$url = $cont;
$queuelogid = 0;
if(!isset($param['nolog'])){
$queuelogid= m('log')->addlogs('异步队列','', 3);
$param['queuelogid'] = $queuelogid;
}
if(substr($cont,0,4)=='http'){
$type='url';
}else{
if(!contain($url, ','))$url='cli,'.$url.'';
$phppath = getconfig('phppath');
if(!contain($this->rockqueue_host, '127.0.0.1') || isempt($phppath)){
$urla= explode(',', $url);
$url = URL.'task.php?m='.$urla[0].'|runt&a='.$urla[1].'';
$type= 'url';
}else{
$st1 = '';
$check = c('check');
foreach($param as $k=>$v)$st1.=' -'.$k.'='.$v.'';
if(contain($phppath,' ') || $check->isincn($phppath))
return returnerror('配置文件phppath不能有空格请加入环境变量设置并为php');
if(contain(ROOT_PATH,' ') || $check->isincn(ROOT_PATH))
return returnerror('OA系统目录“'.ROOT_PATH.'”有空格,无法使用');
$url = ''.$phppath.' '.ROOT_PATH.'/task.php '.$url.''.$st1.'';
}
}
if($type=='url'){
$jg = contain($url,'?')?'&':'?';
$st1 = '';
foreach($param as $k=>$v)$st1.='&'.$k.'='.$v.'';
if($st1!='')$url.=''.$jg.''.substr($st1,1).'';
}
if($id==0)$id = rand(1,99999);
$rarr[] = array(
'qtype' => $type,
'runtime' => $runtime,
'url' => $url,
'id' => $id
);
$barr = $this->pushdata($rarr);
$barr['cmdurl'] = ''.$type.':'.$url;
if($runtime==0)$runtime = time();
if($queuelogid>0){
m('log')->update(array(
'url' => $url,
'remark'=> '['.$type.']'.date('Y-m-d H:i:s', $runtime).'',
),$queuelogid);
}
return $barr;
}
/**
* 执行shell命令
*/
public function pushcmd($cmd)
{
if(contain(PHP_OS,'WIN')){
$cmdshell = $this->cmdshell[0];
}else{
$cmdshell = $this->cmdshell[1];
}
$qianz = explode(' ', $cmd);
$qianz = $qianz[0];
//$boa = false;
//foreach($cmdshell as $sell)if(contain($qianz, $sell))$boa = true;
//if(!$boa)return returnerror('非法操作');
$boa = false;
foreach($this->cmdshell[2] as $sell)if(contain($cmd, $sell))$boa = true;
if(!$boa)return returnerror('无效参数');
$id = rand(1,99999);
$rarr[] = array(
'qtype' => 'cmd',
'runtime' => '0',
'url' => escapeshellcmd($cmd),
'id' => $id
);
return $this->pushdata($rarr);
}
/**
* 推送数据过去
*/
public function pushdata($rarr)
{
if(is_array($rarr))$rarr = json_encode($rarr);
$url = 'http://'.$this->rockqueue_host.':'.$this->rockqueue_port.'/?atype=send&data='.urlencode($rarr).'';
$reqult = c('curl')->setTimeout(3)->getcurl($url);
if($reqult){
return returnsuccess($reqult);
}else{
return returnerror('服务端配置不能用');
}
//return c('socket')->udppush($rarr, $this->rockqueue_host, $this->rockqueue_port);
}
/**
* 推送类型
*/
public function pushtype($type, $url, $can=array())
{
$can['qtype'] = $type;
$can['url'] = $url;
$rarr[] = $can;
return $this->pushdata($rarr);
}
/**
* 发送腾讯云存储
* 调用c('rockqueue')->sendfile(文件Id);
*/
public function sendfile($fileid, $runtime=0)
{
return $this->push('qcloudCos,run', array('fileid'=>$fileid), $runtime);
}
public function senddown($fileid)
{
return $this->push('qcloudCos,down', array('fileid'=>$fileid));
}
/**
* 在信呼文件管理平台上删除对应文件
* 调用c('rockqueue')->delfile(文件编号);
*/
public function delfile($fileid)
{
return $this->push('qcloudCos,del', array('fileid'=>$fileid));
}
}

View File

@@ -0,0 +1,68 @@
<?php
class socketChajian extends Chajian
{
//UDP服务器主机不需要修改
private $serverhost = '127.0.0.1';
//UDP服务端口数字类型
private $serverport = 780;
/**
* UDP发送文本
*/
public function udpsend($str)
{
if(!function_exists('socket_create'))return '没有开启Socket组件';
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$len = strlen($str);
$bo = socket_sendto($sock, $str, $len, 0, $this->serverhost, $this->serverport);
socket_close($sock);
return $bo;
}
/**
* 转pdf发送命令
*/
public function topdf($path, $fid, $type)
{
$flx = 'doc';
if($type=='xls' || $type=='xlsx')$flx='xls';
if($type=='ppt' || $type=='pptx')$flx='ppt';
$topah = ''.ROOT_PATH.'/mode/pdfjs/topdf/'.$flx.'.js';
if(!file_exists($topah))return '没有安装转化插件';
$url = m('base')->getasynurl('asynrun', 'topdfok', array('id'=>$fid,'type'=>'pdf'));
$url = URL;
$path = ''.ROOT_PATH.'/mode/pdfjs/topdf/start.bat "'.$topah.'" "'.ROOT_PATH.'/'.$path.'" "'.$url.'"';
$bo = $this->udpsend($path);
return $bo;
}
/**
* 用udp推送
*/
public function udppush($str, $host='', $port=0)
{
$msg = $bstr = '';
if(!function_exists('stream_socket_client'))$msg= '没有开启Socket组件';
if($msg==''){
$handle = stream_socket_client("udp://{$host}:{$port}", $errno, $errstr);
if(!$handle){
$msg = "ERROR: {$errno} - {$errstr}";
}
if($msg==''){
fwrite($handle, $str);
//$bstr = fread($handle, 1024); //去掉这个,不然容易阻塞
fclose($handle);
}
}
$barr['code'] = 0;
$barr['success'] = true;
$barr['msg'] = 'ok';
$barr['data'] = $bstr;
if($msg!=''){
$barr['code'] = 2;
$barr['msg'] = $msg;
}
return $barr;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* pThread 多线程插件php.ini需要开启php_pthreads.dll扩展
* 来自:信呼开发团队
* 使用方法 c('thread')->startrun('http://127.0.0.1/');
*/
class threadChajian extends Thread{
private $urlstr = '';
private $result = '';
/**
* 执行的地址
* isback 是否等待返回内容
*/
public function startrun($url, $isback=false){
$this->urlstr = $url;
$this->start();
if($isback)while($this->isRunning())usleep(10);
return $this->result;
}
public function run(){
@$this->result = c('curl')->getcurl($this->urlstr);
}
public function getresult()
{
return $this->result;
}
}
if(!class_exists('Thread')){
abstract class Thread {
public function run(){}
public function start(){
$this->run();
}
public function join(){return true;}
public function isRunning(){return false;}
}
}

View File

@@ -0,0 +1,263 @@
<?php
/**
上传文件类upfileChajian
createchenxihu
createdt2013-11-15
explain上传文件类可上传任何文件类型
*/
class upfileChajian extends Chajian{
public $ext; //上传类型
public $maxsize; //上传大小(MB)
public $path; //文件夹
private $jpgallext = '|jpg|png|gif|bmp|jpeg|'; //图片格式
//可上传文件类型也就是不保存为uptemp的文件
private $upallfile = '|doc|docx|xls|xlsx|ppt|pptx|pdf|swf|rar|zip|txt|gz|wav|mp3|avi|mp4|flv|wma|chm|apk|amr|log|json|cdr|psd|';
/**
初始化
@param $ext string 上传类型
@param $path string 上传目录 如upload|e|ee
@param $maxsize ing 上传大小(MB)
*/
public function initupfile($ext,$path,$maxsize=1)
{
if($ext=='image')$ext = $this->jpgallext;
$this->ext = $ext;
$this->maxsize = $maxsize;
$this->path = $path;
}
private function _getmaxupsize($lx)
{
$iniMax = strtolower(ini_get($lx));
if ('' === $iniMax) {
return PHP_INT_MAX;
}
$max = ltrim($iniMax, '+');
if (0 === strpos($max, '0x')) {
$max = intval($max, 16);
} elseif (0 === strpos($max, '0')) {
$max = intval($max, 8);
} else {
$max = (int) $max;
}
switch (substr($iniMax, -1)) {
case 't': $max *= 1024;
case 'g': $max *= 1024;
case 'm': $max *= 1024;
case 'k': $max *= 1024;
}
return $max;
}
public function getmaxupsize()
{
$post = $this->_getmaxupsize('post_max_size');
$upmx = $this->_getmaxupsize('upload_max_filesize');
if($post < $upmx)$upmx = $post;
return $upmx;
}
public function getmaxzhao()
{
$size = $this->getmaxupsize();
$size = $size / 1024 / 1024;
return (int)$size;
}
/**
* 是否在可保存范围内容
*/
public function issavefile($ext)
{
$bo = false;
$upallfile = $this->jpgallext.$this->upallfile;
if($this->contain($upallfile, '|'.$ext.'|'))$bo = true;
return $bo;
}
public function isimg($ext)
{
return $this->contain($this->jpgallext, '|'.$ext.'|');
}
/**
* 判断是不是图片
*/
public function isimgsave($ext, $file)
{
$arr = array();
if(!file_exists($file))return $arr;
if($this->isimg($ext)){
list($picw,$pich) = getimagesize($file);
if($picw==0||$pich==0){
@unlink($file);
}
$arr[0] = $picw;
$arr[1] = $pich;
}
return $arr;
}
public function isoffice($ext)
{
return contain('|doc|docx|xls|xlsx|ppt|pptx|pdf|', '|'.$ext.'|');
}
/**
上传
@param $name string 对应文本框名称
@param $cfile string 文件名心的文件名,不带扩展名的
@return string/array
*/
public function up($name,$cfile='')
{
if(!$_FILES)return 'sorry!';
$file_name = $_FILES[$name]['name'];
$file_size = $_FILES[$name]['size'];//字节
$file_type = $_FILES[$name]['type'];
$file_error = $_FILES[$name]['error'];
$file_tmp_name = $_FILES[$name]['tmp_name'];
$zongmax = $this->getmaxupsize();
if($file_size<=0 || $file_size > $zongmax){
return '文件为0字节/超过'.$this->formatsize($zongmax).',不能上传';
}
$file_sizecn = $this->formatsize($file_size);
$file_ext = $this->getext($file_name);//文件扩展名
$file_img = $this->isimg($file_ext);
$file_kup = $this->issavefile($file_ext);
if(!$file_img && !$this->isoffice($file_ext) && getconfig('systype')=='demo')return '演示站点禁止文件上传';
if($file_error>0){
$rrs = $this->geterrmsg($file_error);
return $rrs;
}
if(!$this->contain('|'.$this->ext.'|', '|'.$file_ext.'|') && $this->ext != '*'){
return '禁止上传文件类型['.$file_ext.']';
}
if($file_size>$this->maxsize*1024*1024){
return '上传文件过大,限制在:'.$this->formatsize($this->maxsize*1024*1024).'内,当前文件大小是:'.$file_sizecn.'';
}
//创建目录
$zpath=explode('|',$this->path);
$mkdir='';
for($i=0;$i<count($zpath);$i++){
$mkdir.=''.$zpath[$i].'/';
if(!is_dir($mkdir))mkdir($mkdir);
}
//新的文件名
$file_newname = $file_name;
$randname = $file_name;
if(!$cfile==''){
$file_newname=''.$cfile.'.'.$file_ext.'';
}else{
$_oldval = m('option')->getval('randfilename');
$randname = $this->getrandfile(1, $_oldval);
m('option')->setval('randfilename', $randname);
$file_newname=''.$randname.'.'.$file_ext.'';
}
$save_path = ''.str_replace('|','/',$this->path);
//if(!is_writable($save_path))return '目录'.$save_path.'无法写入不能上传';
$allfilename= $save_path.'/'.$file_newname.'';
$uptempname = $save_path.'/'.$randname.'.uptemp';
$upbool = true;
if(!$file_kup){
$allfilename= $this->filesave($file_tmp_name, $file_newname, $save_path, $file_ext);
if(isempt($allfilename))return '无法保存到'.$save_path.'';
}else{
$upbool = @move_uploaded_file($file_tmp_name,$allfilename);
}
if($upbool){
$picw=0;$pich=0;
if($file_img){
$fobj = $this->isimgsave($file_ext, $allfilename);
if(!$fobj){
return 'error:非法图片文件';
}else{
$picw = $fobj[0];
$pich = $fobj[1];
}
}
return array(
'newfilename' => $file_newname,
'oldfilename' => $file_name,
'filesize' => $file_size,
'filesizecn' => $file_sizecn,
'filetype' => $file_type,
'filepath' => $save_path,
'fileext' => $file_ext,
'allfilename' => $allfilename,
'picw' => $picw,
'pich' => $pich
);
}else{
return '上传失败:'.$this->geterrmsg($file_error).'';
}
}
private function getrandfile($xu, $val)
{
$randname = ''.date('d_His').''.rand(10,99*$xu).'';
if($val==$randname)return $this->getrandfile($xu+1, $val);
return $randname;
}
private function geterrmsg($code)
{
$arrs[1] = '上传文件大小超过服务器允许上传的最大值';
$arrs[2] = '上传文件大小超过HTML表单中隐藏域MAX_FILE_SIZE选项指定的值';
$arrs[6] = '没有找不到临时文件夹';
$arrs[7] = '文件写入失败';
$arrs[8] = 'php文件上传扩展没有打开';
$arrs[3] = '文件只有部分被上传';
$rrs = '上传失败,可能是服务器内部出错,请重试';
if(isset($arrs[$code]))$rrs=$arrs[$code];
return $rrs;
}
//返回文件大小
public function formatsize($size)
{
return $this->rock->formatsize($size);
}
//获取扩展名
public function getext($file)
{
return strtolower(substr($file,strrpos($file,'.')+1));
}
/**
* 非法文件保存为临时uptemp的形式
*/
public function filesave($oldfile, $filename, $savepath, $ext)
{
$file_kup = $this->issavefile($ext);
$ldisn = strrpos($filename, '.');
if($ldisn>0)$filename = substr($filename, 0, $ldisn);
$filepath = ''.$savepath.'/'.$filename.'.'.$ext.'';
if(!$file_kup){
$filebase64 = base64_encode(file_get_contents($oldfile));
$filepath = ''.$savepath.'/'.$filename.'.uptemp';
$bo = $this->rock->createtxt($filepath, $filebase64);
@unlink($oldfile);
if(!$bo)$filepath = '';
}else{
}
return $filepath;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* 微信小程序接口
*/
class wxxcyChajian extends Chajian{
protected function initChajian()
{
$this->wxxcy_url = getconfig('wxxcy_url'); //微信小程序地址
if(getconfig('systype')=='dev')$this->wxxcy_url='http://localhost/app/xcy_hosh/';
}
/**
* 发送订阅消息
* $xcytype 类型入hetong
* $mobile 接收人员手机号
* $params 参数,多个|分开
* $tplid 发给哪个模版用0,1,2,3等
*/
public function subscribe($xcytype, $mobile, $params,$tplid='0',$path='')
{
if(!$this->wxxcy_url)return returnerror('wxxcy_url empty');
$onr = m('wxxcyus')->getone("`xcytype`='$xcytype' and `mobile`='$mobile'");
if(!$onr)return returnerror('no subscribe');
$url = ''.$this->wxxcy_url.'api.php?m=weixin&a=subscribe&xcytype='.$xcytype.'';
$data['mobile'] = $mobile;
$data['params'] = $params;
$data['tplid'] = $tplid;
$data['path'] = $path;
$result = c('curl')->postcurl($url, $data);
if(!$result)return returnerror('api not data');
if(substr($result,0,1)!='{')return returnerror('err:'.$result.'');
return json_decode($result, true);
}
}

View File

@@ -0,0 +1,50 @@
<?php
class xinhuChajian extends Chajian{
private $updatekey = '';
private $updatekeys = 'aHR0cDovLzEyNy4wLjAuMS9hcHAvcm9ja3hpbmh1d2ViLw::';
protected function initChajian()
{
if(getconfig('systype')=='dev'){
$this->updatekey = $this->rock->jm->base64decode($this->updatekeys);
}else{
$this->updatekey = URLY;
}
if(isempt($this->updatekey))$this->updatekey=$this->rock->jm->base64decode('aHR0cDovL3d3dy5yb2Nrb2EuY29tLw::');
}
public function getwebsite()
{
return $this->updatekey;
}
public function geturlstr($act, $can=array())
{
$url = $this->updatekey;
$url.= 'api.php?a='.$act.'';
$url.= '&host='.$this->rock->jm->base64encode(HOST).'&version='.VERSION.'&time='.time().'&web='.$this->rock->web.'&ipstr='.$this->rock->ip.'&randkey='.getconfig('randkey').'&xinhukey='.getconfig('xinhukey').'';
$url.= '&authorkey='.getconfig('authorkey').'&cfrom='.getconfig('xinhutype').'';
if($act!='xinhuinstall')$url.= '&aukey='.m('option')->getval('auther_aukey').'';
foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
return $url;
}
public function getdata($act, $can=array())
{
$url = $this->geturlstr($act, $can);
$cont = c('curl')->getcurl($url);
$data = array('code'=>199,'msg'=>'出错'.URLY.',返回:'.htmlspecialchars($cont).'');
if($cont!='' && substr($cont,0,1)=='{'){
$data = json_decode($cont, true);
}
return $data;
}
public function helpstr($num, $na='')
{
if($na=='')$na='帮助';
return '<a style="color:blue" href="'.$this->updatekey.'view_'.$num.'.html" target="_blank">['.$na.']</a>';
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,32 @@
<?php
/**
* 连接信呼文件管理平台
*/
class xinhudocChajian extends Chajian{
public function geturlstr($mod, $act, $can=array())
{
$url = getconfig('xinhudoc_platurl');
$key = getconfig('xinhudoc_openkey');
if(substr($url,-1)!='/')$url.='/';
$url .= 'openapi/'.$mod.'/'.$act.'?openkey='.md5($key).'';
foreach($can as $k=>$v)$url.='&'.$k.'='.$v.'';
return $url;
}
/**
* 返回内容处理
*/
public function returnresult($result)
{
if($result && contain($result,'success')){
$stat = strpos($result,'{');
if(!$stat)$stat=0;
$barr = json_decode(substr($result, $stat), true);
if(isset($barr['success']))return $barr;
}
return returnerror('returnerr:'.$result.'');
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* 小米推送
* 参考的开发https://dev.mi.com/console/doc/detail?pId=1163
*/
class xmpushChajian extends Chajian{
private $api_url = 'https://api.xmpush.xiaomi.com/v2/message/alias';
private $api_urltest = 'https://sandbox.xmpush.xiaomi.com/v2/message/alias';
//安卓的
private $android_secret = ''; //安卓小米的secret
private $android_package = ''; //包名
//IOS苹果(弃用不要去设置修改)
private $ios_secret = ''; //IOS的secret
private $ios_bundleid = '';
//2021-10-09最新IOS推送使用极光的如果自己编译IOS就要配置
private $jpush_app_key = '';
private $jpush_master_secret = '';
private $jpush_ios_ver = ''; //IOS编译的版本1正式版
protected function initChajian()
{
if(!$this->android_secret)$this->android_secret = getconfig('xm_android_secret');
if(!$this->android_package)$this->android_package = getconfig('xm_android_package');
$this->jpush_app_key = getconfig('jpush_app_key');
$this->jpush_master_secret = getconfig('jpush_master_secret');
$this->jpush_ios_ver = getconfig('jpush_ios_ver');
}
public function sendbool()
{
if($this->android_secret=='')return false;
return true;
}
/**
* 安卓推送通知
*/
public function androidsend($alias, $title, $cont, $payload='')
{
if(!$alias || !$this->sendbool())return '';
if(is_array($alias))$alias = join(',', $alias);
$data = array(
'payload' => '',
'restricted_package_name' => $this->android_package,
'pass_through' => '0', // 0 表示通知栏消息1表示透传消息
'title' => $title,
'description' => $cont,
'alias' => $alias,
'notify_type' => '1', //提示语就好了
'notify_id' => rand(1,45), //可多条显示
'extra.notify_foreground' => '1',
'extra.notify_effect' => '1',
);
if($payload)$data['payload'] = urlencode($payload);
return c('curl')->postcurl($this->api_url, $data, 0, array(
'Authorization'=> 'key='.$this->android_secret
));
}
//弃用(2021-10-09)
public function iossend($alias, $title, $cont)
{
if(!$alias || $this->ios_secret=='')return '';
if(is_array($alias))$alias = join(',', $alias);
$data = array(
'title' => $title,
'aps_proper_fields.title' => $title,
'description' => $cont,
'aps_proper_fields.body' => $cont,
'alias' => $alias,
'extra.badge'=>'1'
);
return c('curl')->postcurl($this->api_url, $data, 0, array(
'Authorization'=> 'key='.$this->ios_secret
));
}
/**
* 推送以下,你用不到不要去管和修改
*/
public function jpushiosbool()
{
if($this->jpush_app_key=='')return false;
return true;
}
public function jpushiossend($alias, $title, $cont, $iszs=false)
{
if(!$this->jpushiosbool())return '';
if($this->jpush_ios_ver==1)$iszs = true;
$url = 'https://api.jpush.cn/v3/push';
$body = array();
$base64_auth_string = base64_encode(''.$this->jpush_app_key.':'.$this->jpush_master_secret.'');
$headarr['Authorization'] = 'Basic '.$base64_auth_string.'';
if(is_string($alias))$alias = explode(',', $alias);
$body['platform'] = array('ios');
$body['audience'] = array(
'alias' => $alias
);
$sound = 'widget/res/sound/sound.aif';
if($cont=='邀请与您视频通话...' || $cont=='邀请与您语音通话...')$sound='widget/res/sound/call.mp3';
$body['notification'] = array(
'ios' => array(
'alert' => array(
'title' => $title,
'body' => $cont,
),
'sound' => $sound,
'badge' => '+1',
'thread-id' => 'default',
)
);
$body['options'] = array(
'time_to_live' => 60,
'apns_production' => $iszs, //false测试环境
);
$result = c('curl')->postcurl($url, json_encode($body, JSON_UNESCAPED_UNICODE), 0, $headarr);
return $result;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* 来自:信呼开发团队
* 作者:磐石(rainrock)
* 网址http://www.rockoa.com/
* 云片网短信服务
* 此文件放到include/chajian/yunpsmsChajian.php 下
* 开发帮助地址http://www.rockoa.com/view_yunpsms.html
*/
class yunpsmsChajian extends Chajian{
private $sendurl = 'https://sms.yunpian.com/v2/sms/batch_send.json';
private $yunpian_key = '你的短信apikey'; //这里填写你的云片网的apikey
/**
* 短信模版写这里的
*/
protected function initChajian()
{
$mobian['defyzm'] = '欢迎使用,您的短信验证码为:#code#,为保障系统安全,请勿将验证码和办公系统网址提供给他人,祝您工作愉快。';
$mobian['defsucc'] = '您提交单据(#modename#,单号:#sericnum#)已全部处理完成,可登录系统查看详情。';
$mobian['default'] = '您有单据(#modename#,单号:#sericnum#)需要处理,请登录系统及时去处理。';
$mobian['birthday'] = '尊敬的#name#,今天是#dt#,农历#dtnong#,是您的生日,我们在这里祝您生日快乐。';
$mobian['defnum'] = '您有#applyname#的(#modename#)单据需要您处理,详情:#url#';
$mobian['defurls'] = '您有单据(#modename#,单号:#sericnum#)需要处理,请及时去处理,详情:#url#。';
$mobian['gongsms'] = '您收到一条“#title#”的通知,详情:#url#';
$mobian['meetapply'] = '#optname#发起会议“#title#”在#hyname#,时间#startdt#至#enddt#';
$mobian['meetcancel'] = '#optname#取消会议“#title#”,时间#startdt#至#enddt#,请悉知。';
$mobian['meettodo'] = '会议“#title#”将在#fenz#分钟后的#time#开始请做好准备,在会议室“#hyname#”';
//上面加你的模版
$this->mobianarr = $mobian;
}
/**
* 批量发送短信
* $mobiles 接收人手机号多个,分开
* $qianm 签名
* $tplid 模版编号在上面initChajian()数组中查找
* $cans 模版中的参数数组
* 例子c('mysms')->send('15800000000,15800000001','信呼', 'default', array('modename'=>'模块名','sericnum'=>'单号')); 这例子是不需要自己调用,只要短信设置下切换为“我的短信服务”就可以了
*/
public function send($mobiles, $qianm, $tplid, $cans=array())
{
//要发送短信的内容
$text = arrvalue($this->mobianarr, $tplid);
if(isempt($text))return returnerror('模版'.$tplid.'不存在');
foreach($cans as $k=>$v)$text = str_replace('#'.$k.'#', $v, $text);
if(isempt($qianm))return returnerror('没有设置短信签名');
if(isempt($this->yunpian_key))return returnerror('没有设置云片网的apikey');
$text = '【'.$qianm.'】'.$text.''; //发的短信
$arr['apikey'] = $this->yunpian_key;
$arr['mobile'] = $mobiles;
$arr['text'] = $text;
$result = c('curl')->postcurl($this->sendurl, $arr);
if(isempt($result))return returnerror('发送失败');
$barr = json_decode($result, true);
$data = arrvalue($barr,'data');
$total_count = 0; //总发送条数
$sendbo = false;
$msg = '';
if(is_array($data))foreach($data as $k=>$rs){
if($rs['code']==0){
$sendbo = true;
}else{
$msg .= $rs['msg'].';';
}
}
//成功
if($sendbo){
return returnsuccess(array(
'count' => $barr['total_count'],
'text' => $text,
'mobile'=> $mobiles,
));
}else{
return returnerror('发送失败:'.$msg.'('.$text.')', 202);
}
}
}

View File

@@ -0,0 +1,105 @@
<?php
class zipChajian extends Chajian{
/**
* 解压zip文件
*/
public function unzip($filename, $path){
if(!function_exists('zip_open'))return 'php未开启zip模块';
if(!file_exists($filename))return '文件不存在';
@$resource = zip_open($filename);
if(!$resource)return '无法打开文件';
while ($dir_resource = zip_read($resource)){
if(zip_entry_open($resource,$dir_resource)){
$file_name = $path.zip_entry_name($dir_resource);
$file_path = substr($file_name,0,strrpos($file_name, "/"));
if(!is_dir($file_path))mkdir($file_path,0777,true);
if(!is_dir($file_name)){
$file_size = zip_entry_filesize($dir_resource);
$file_content = zip_entry_read($dir_resource, $file_size);
$bos = $this->writefile($file_name, $file_content);
if(!$bos)return '无权限写入文件:'.$file_name.'';
}
zip_entry_close($dir_resource);
}
}
zip_close($resource);
return 'ok';
}
private function writefile($file_name, $file_content)
{
$oldcont = '';
if(file_exists($file_name)){
$oldcont = file_get_contents($file_name);
if($oldcont != $file_content){
$barfile = ''.UPDIR.'/upage/'.$file_name.'';
$this->rock->createdir($barfile);
copy($file_name, $barfile);
}
}
@$bos = file_put_contents($file_name,$file_content);
return $bos;
}
/**
* 获取zip上文件
*/
public function zipget($filename){
if(!function_exists('zip_open'))return 'php未开启zip模块';
if(!file_exists($filename))return '文件不存在';
@$resource = zip_open($filename);
if(!$resource)return '无法打开文件';
$farr = array();
while ($dir_resource = zip_read($resource)){
if(zip_entry_open($resource,$dir_resource)){
$file_name = zip_entry_name($dir_resource);
$file_path = substr($file_name,0,strrpos($file_name, "/"));
if(!is_dir($file_name) && substr($file_name,-1)!='/'){
$file_size = zip_entry_filesize($dir_resource);
$file_content = zip_entry_read($dir_resource, $file_size);
if(substr($file_name,0,1)=='/')$file_name = substr($file_name,1);
$farr[] = array(
'filepath' => $file_name,
'filesize' => $file_size,
'filecontent' => base64_encode($file_content),
);
}
zip_entry_close($dir_resource);
}
}
zip_close($resource);
return $farr;
}
private function addFileToZip($path, $zip, $wz){
$handler = opendir($path);
while(($filename=readdir($handler))!==false){
if($filename != '.' && $filename != '..'){
$addfile = $path.'/'.$filename;
if(is_dir($addfile)){
$this->addFileToZip($addfile, $zip, $wz);
}else{
$localwz = substr($addfile, $wz);
$zip->addFile($addfile, $localwz);
}
}
}
@closedir($path);
}
/**
* zip打包
*/
public function packzip($path, $topath)
{
$zip = new ZipArchive();
if($zip->open($topath, ZipArchive::OVERWRITE)=== TRUE){
$this->addFileToZip($path, $zip, strlen($path));
$zip->close();
}
if(!file_exists($topath))$topath='';
return $topath;
}
}

759
include/class/mysql.php Normal file
View File

@@ -0,0 +1,759 @@
<?php
/**
*****************************************************************
* 联系QQ 290802026 *
* 版 本: V2.0 *
* 开发者:雨中磐石工作室 *
* 网 址: http://www.rockoa.com/ *
* 说 明: 数据库核心类 *
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
*****************************************************************
*/
if(!defined('HOST'))exit('not access');
abstract class mysql{
public $conn = null;
public $iudcount = 0;
public $iudarr = array();
public $tran = false;
public $rock;
public $nowsql;
public $countsql = 0;
public $sqlarr = array();
public $total = 0;
public $count = 0;
public $perfix = PREFIX;
public $errorbool = false;
public $errormsg = '';
public $errorlast = '';
public $nowerror = false;
public $basename;
protected $db_host;
protected $db_user;
protected $db_pass;
protected $db_base;
protected $exparray = array(
'eq' => "='?0'", 'neq' => "<>'?0'", 'eqi' => '=?0', 'neqi' => '<>?0', 'lt' => "<'?0'", 'elt' => "<='?0'",
'gt' => ">'?0'", 'egt' => ">='?0'", 'lti' => '<?0', 'elti' => '<=?0', 'gti' => '>?0', 'egti' => '>=?0',
'like' => "LIKE '%?0%'", 'notlike' => "NOT LIKE '%?0%'", 'leftlike' => "LIKE '%?0'", 'rightlike' => "LIKE '?0%'",
'in' => "IN(?0)", 'notin' => "NOT IN(?0)",
'between' => "BETWEEN '?0' AND '?1'", 'notbetween' => "NOT BETWEEN '?0' AND '?1'",
'betweeni' => "BETWEEN ?0 AND ?1", 'notbetweeni' => "NOT BETWEEN ?0 AND ?1"
);
//sql中禁用方法
protected $disabledfua = array('dumpfile','outfile','load_file','system_user');
public function __construct()
{
$this->rock = $GLOBALS['rock'];
$this->errorbool = false;
$this->errormsg = '';
if(getconfig('dbencrypt')){
$this->db_host = $this->rock->jm->uncrypt(DB_HOST);
$this->db_user = $this->rock->jm->uncrypt(DB_USER);
$this->db_pass = $this->rock->jm->uncrypt(DB_PASS);
$this->db_base = $this->rock->jm->uncrypt(DB_BASE);
}else{
$this->db_host = DB_HOST;
$this->db_user = DB_USER;
$this->db_pass = DB_PASS;
$this->db_base = DB_BASE;
}
$this->basename = $this->db_base;
}
public function __destruct()
{
if($this->conn){
$this->tranend();
$this->close();
}
//记录访问sql日志
if(getconfig('sqllog')){
$sql = '';
$filstr = 'sqllog_'.date('Y.m.d.H.i.s').'_'.$this->rock->adminid.'_'.str_shuffle('abcdefghijklmn').'.log';
foreach($this->sqlarr as $sql1)$sql.="\n\n$sql1;";
if($sql!='')$this->rock->createtxt(''.UPDIR.'/sqllog/'.date('Y-m-d').'/'.$filstr.'', "时间[".$this->rock->now."],用户[".$this->rock->adminid.".".$this->rock->adminname."],IP[".$this->rock->ip."],WEB[".$this->rock->web."],URL[".$this->rock->nowurl()."]".$sql);
}
}
protected function connect(){}
protected function selectdb($name)
{
$this->basename = $name;
}
protected function querysql($sql){return false;}
protected function starttran(){}
protected function endtran($bo){}
public function fetch_array($res, $type=0){return false;}
public function insert_id(){return 0;}
public function error(){return '';}
public function close(){}
public function changeattr($host, $user, $pass, $base)
{
$this->db_host = $host;
$this->db_user = $user;
$this->db_pass = $pass;
$this->db_base = $base;
}
public function connectdb()
{
$this->errormsg = '';
$this->connect();
return $this->conn;
}
public function query($sql, $ebo=true)
{
if($this->conn == null)$this->connect();
if($this->conn == null)exit('数据库的帐号/密码有错误!'.$this->errormsg.'');
$sql = trim($sql);
$sql = str_replace(array('[Q]','[q]','{asqom}'), array($this->perfix, $this->perfix,''), $sql);
$sqls = strtolower($sql);
foreach($this->disabledfua as $fus)if(contain($sqls,$fus))exit('禁止包含'.$fus.'字符串');
$this->countsql++;
$this->sqlarr[] = $sql;
$this->nowsql = $sql;
$this->count = 0;
try {
$rsbool = $this->querysql($sql);
} catch (Exception $e) {
$rsbool = false;
$this->errormsg = $e->getMessage();
}
$this->nowerror = false;
if(!$rsbool)$this->nowerror = true;
$stabs = ''.$this->perfix.'log';
if(!contain($sql, $stabs) && !$rsbool)$this->errorlast = $this->error(); //最后错误信息
//记录错误sql
if(!$rsbool && $ebo){
$txt = '[ERROR SQL]'.chr(10).''.$sql.''.chr(10).''.chr(10).'[Reason]'.chr(10).''.$this->error().''.chr(10).'';
$efile = $this->rock->debug($txt,''.DB_DRIVE.'_sqlerr', true);
$errmsg = str_replace("'",'&#39;', $this->error());
if(!contain($sql, $stabs)){
m('log')->addlogs('错误SQL',''.$errmsg.'', 2, array(
'url' => $efile
));
}
}
return $rsbool;
}
/**
* 返回最后错误信息
*/
public function lasterror()
{
$err = $this->errorlast;
if($err=='')$err = $this->error();
return $err;
}
public function execsql($sql)
{
$rsa = $this->query($sql);
$this->iudarr[]=$rsa;
return $rsa;
}
public function getLastSql()
{
return $this->nowsql;
}
public function getsyscount($lx='')
{
$to = 0;
if($lx=='')return $to;
$lx = strtoupper($lx);
$rsa = $this->getall('SELECT '.$lx.'() as total');
$to = $rsa[0]['total'];
return $to;
}
/**
* 返回使用SQL_CALC_FOUND_ROWS统计总记录数
*/
public function found_rows()
{
return $this->getsyscount('found_rows');
}
/**
* 返回update,insert,delete上所影响的条数
*/
public function row_count()
{
return $this->getsyscount('row_count');
}
/**
* 获取select的sql
*/
public function getsql($arr=array())
{
$where = $table = $order = $limit = $group = '';
$fields = '*';
if(isset($arr['table']))$table=$arr['table'];
if(isset($arr['where']))$where=$arr['where'];
if(isset($arr['order']))$order=$arr['order'];
if(isset($arr['limit']))$limit=$arr['limit'];
if(isset($arr['group']))$group=$arr['group'];
if(isset($arr['fields']))$fields=$arr['fields'];
$where = $this->getwhere($where);
$table = $this->gettable($table);
$sql = "SELECT $fields FROM $table";
if($where!=''){
//$where = $this->filterstr($where);
$sql.=" WHERE $where";
}
if($order!='')$sql.=" ORDER BY $order";
if($group!='')$sql.=" GROUP BY $group";
if($limit!='')$sql.=" LIMIT $limit";
return $sql;
}
//弃用过滤
public function filterstr($str)
{
$str = strtolower($str);
$file= explode(',','delete,drop,update,union,exec,insert,declare,master,truncate,create,alter,database');
$res = array();
foreach($file as $fid)$res[]='';
$str = str_replace($file, $res, $str);
return $str;
}
public function getone($table,$where,$fields='*',$order='')
{
$rows = $this->getrows($table,$where,$fields,$order,'1');
$row = false;
if($this->count>0)$row=$rows[0];
return $row;
}
public function getrows($table,$where,$fields='*',$order='', $limit='',$group='')
{
$sql = $this->getsql(array(
'table' => $table,
'where' => $where,
'fields'=> $fields,
'order' => $order,
'limit' => $limit,
'group' => $group
));
return $this->getall($sql);
}
public function getall($sql)
{
$res=$this->query($sql);
$arr=array();
if($res){
while($row=$this->fetch_array($res)){
$arr[] = $row;
$this->count++;
}
}
return $arr;
}
/**
string table1 a left JOIN table2 b on b.uid=a.id
array(table=>$table,join=>'left')
*/
public function gettable($arr)
{
if(is_array($arr)){
$s = '';$oi=0;
foreach($arr as $k=>$v){
if($oi==0){
$s=''.$v.' a';
}else{
if($k=='join')$s.=' '.$v.' JOIN';
if($k=='table1')$s.=' '.$v.' b';
if($k=='where')$s.=' ON '.$v.'';
if($k=='where1')$s.=' AND '.$v.'';
}
$oi++;
}
$arr = $s;
}
return $arr;
}
/**
条件的
$arrs = array(
'id|eqi|a' => '0',
'name|like' => '我',
'id|notin' => '0,12',
'enddt|rightlike' => '2015-10',
'startdt|between' => '2015-10-01@@@2015-10-31',
'price|notbetweeni' => '1@@@10',
'sid > ?0 and <?1' => '0@@@2'
);
*/
public function getwhere($where='')
{
$len = func_num_args();
$arr = array();
$sfh1 = '';
for($i=0; $i<$len; $i++){
$sfh = func_get_arg($i);
if(is_numeric($sfh)){
$arr[] = "`id`='$sfh'";
}else if($sfh=='AND' || $sfh=='OR' || $sfh=='and' || $sfh=='or'){
$sfh1 = $sfh;
}else{
$arr[] = $this->_getwhere($sfh);
}
}
$joins = ') AND (';
if($sfh1!='')$joins = ') '.$sfh1.' (';
$where = join($joins, $arr);
if($sfh1!='')$where = "($where)";
return $where;
}
private function _getwhere($where='')
{
if($where=='')return '';
if(is_numeric($where)){
$where = "`id`='$where'";
}else if(is_array($where)){
$sarr = array();
foreach($where as $fid=>$val){
$qz = '';
$farr = explode('|', $fid);
$fid = $farr[0];
$_fhs = "='?0'";
if(isset($farr[1])){
$_fh = $farr[1];
if(isset($this->exparray[$_fh]))$_fhs=$this->exparray[$_fh];
}
if(isset($farr[2]))$qz=''.$farr[2].'.';
$vala = explode('@@@', $val);
$val1 = $vala[0];$val2='';
if(isset($vala[1]))$val2=$vala[1];
$_bo1 = $this->contain($fid,'?0');
if($_bo1)$_fhs = $fid;
$_fhs = str_replace(array('?0','?1'), array($val1,$val2), $_fhs);
$s = $_fhs;
if(!$_bo1)$s = ''.$qz.'`'.$fid.'` '.$_fhs.'';
$sarr[]=$s;
}
$where = join(' AND ', $sarr);
}
return $where;
}
/**
* 以$kfied作为主键返回数组
*/
public function getarr($table, $where='', $fields='*', $kfied='id')
{
$sql = $this->getsql(array(
'table' => $table,
'where' => $where,
'fields'=> "`$kfied`,$fields"
));
$res = $this->query($sql);
$arr = array();
if($res){
while($row=$this->fetch_array($res)){
$arr[$row[$kfied]] = $row;
$this->count++;
}
}
return $arr;
}
/**
读取全部同时将第一个字段作为主键(读取的数据存在数组里)
*/
public function getkeyall($table,$fields,$where='')
{
$sql = $this->getsql(array(
'table' => $table,
'where' => $where,
'fields'=> $fields
));
$res=$this->query($sql);
$arr=array();
if($res){
while(list($ka,$ab) = $this->fetch_array($res, 1)){
$arr[$ka]=$ab;
$this->count++;
}
}
return $arr;
}
/**
读取一条sql语句用规定字符连接起来
*/
public function getjoinval($table,$fields,$where='',$join=',')
{
$sql = $this->getsql(array(
'table' => $table,
'where' => $where,
'fields'=> $fields
));
$res=$this->query($sql);
$arr=array();
if($res){
while(list($kv) = $this->fetch_array($res, 1)){
$arr[]=$kv;
$this->count++;
}
}
return join($join,$arr);
}
/**
读取某行某字段的
*/
public function getmou($table,$fields,$where,$order='')
{
$sql = $this->getsql(array(
'table' => $table,
'where' => $where,
'fields'=> $fields,
'order' => $order
));
$res=$this->query($sql);
if($res){
$row = $this->fetch_array($res, 1);
if($row){
$this->count = 1;
return $row[0];
}
}
return false;
}
/**
* 开启事务
*/
public function routinestart()
{
$this->starttran();
}
/**
* 提交/回滚事务
* $bo=null 自动 true 提交,false 回滚
*/
public function routineend($bo=null)
{
if(!is_bool($bo))$bo = $this->backsql();
$this->endtran($bo);
return $bo;
}
/**
* 启用事务,没有事务
*/
private function tranbegin($sql)
{
//if($this->errorbool)return false;
if($this->conn == null)$this->connect();
$this->iudcount++;
if(!$this->tran){
//$this->starttran();
//$this->tran=true;
}
$rsa = $this->query($sql);
$this->iudarr[]=$rsa;
if(!$rsa)$this->errorbool = true;
return $rsa;
}
/**
事务结束
*/
private function tranend()
{
if($this->tran){
//$this->endtran($this->backsql());
}
$this->tran=false;
}
/**
判断插入更新删除sql语句是否有错
*/
public function backsql()
{
$subt=true;
foreach($this->iudarr as $tra){
if(!$tra){
$subt=false;
break;
}
}
return $subt;
}
public function insert($table,$name,$values,$sel=false)
{
$sql="insert into `$table` ($name) ";
if(!$sel){
$sql.="values($values)";
}else{
$sql.=$values;
}
return $this->tranbegin($sql);
}
public function update($table,$content,$where)
{
$where = $this->getwhere($where);
$sql="update `$table` set $content where $where ";
return $this->tranbegin($sql);
}
public function delete($table,$where)
{
$where = $this->getwhere($where);
$sql="delete from `$table` where $where ";
return $this->tranbegin($sql);
}
/**
记录添加修改
*/
public function record($table,$array,$where='')
{
$addbool = true;
if(!$this->isempt($where))$addbool=false;
$cont = '';
if(is_array($array)){
foreach($array as $key=>$val){
$cont.=",`$key`=".$this->toaddval($val)."";
}
$cont = substr($cont,1);
}else{
$cont = $array;
}
if($addbool){
$sql="insert into `$table` set $cont";
}else{
$where = $this->getwhere($where);
$sql="update `$table` set $cont where $where";
}
return $this->tranbegin($sql);
}
/**
返回总条数
*/
public function rows($table,$where,$rowtype='count(1)'){
return (int)$this->getmou($table,$rowtype,$where);
}
/**
返回所有数据库的表
*/
public function getalltable($base='')
{
if($base=='')$base = $this->basename;
$sql = "select `TABLE_NAME` from information_schema.`TABLES` where `TABLE_SCHEMA`='$base'";
$arr = $this->getall($sql);
$rows= array();
foreach($arr as $k=>$rs)$rows[] = $rs['TABLE_NAME'];
return $rows;
}
/**
返回表所有字段
*/
public function getallfields($table)
{
$finfo = $this->gettablefields($table);
foreach ($finfo as $val) {
$arr[] = $val['name'];
}
return $arr;
}
public function getfields($table)
{
$f = $this->getallfields($table);
foreach($f as $f1)$arr[$f1]='';
return $arr;
}
public function gettablefields($table, $base='',$whe='')
{
if($base=='')$base = $this->db_base;
$sql = "select COLUMN_NAME as `name`,DATA_TYPE as `type`,COLUMN_COMMENT as `explain`,COLUMN_TYPE as `types`,`COLUMN_DEFAULT` as dev,`IS_NULLABLE` as isnull,`CHARACTER_MAXIMUM_LENGTH` as lens,`NUMERIC_PRECISION` as xslen1,`NUMERIC_SCALE` as xslen2 from information_schema.COLUMNS where `TABLE_NAME`='$table' and `TABLE_SCHEMA` ='$base' $whe order by `ORDINAL_POSITION`";
return $this->getall($sql);
}
/**
读取表结构
*/
public function gettablecolumn($table, $fields='')
{
$where = '';
if($fields!='')$where = "and `COLUMN_NAME`='$fields'";
$sql = "select COLUMN_NAME as `name`,DATA_TYPE as `type`,COLUMN_COMMENT as `explain`,COLUMN_TYPE as `types`,COLUMN_DEFAULT as 'defval' from information_schema.COLUMNS where `TABLE_NAME`='$table' and `TABLE_SCHEMA` ='$this->db_base' $where order by `ORDINAL_POSITION`";
$arr = $this->getall($sql);
$rows = array();
foreach($arr as $k=>$rs){
$dev = 'NULL';
if(!$this->isempt($rs['defval']))$dev=$rs['defval'];
$str = "`".$rs['name']."` ".$rs['types']." DEFAULT ".$dev."";
if(!$this->isempt($rs['explain']))$str.=" COMMENT '".$rs['explain']."'";
$rows[] = $str;
}
return $rows;
}
public function showcreatetable($table)
{
$sql = "show create table `$table`";
$res= $this->query($sql);
list($ka,$nr) = $this->fetch_array($res, 1);
return $nr;
}
/**
判断变量是否为空
*/
public function isempt($str)
{
return isempt($str);
}
public function contain($str,$a)
{
$bool=false;
if(!$this->isempt($a) && !$this->isempt($str)){
$ad=strpos($str,$a);
if($ad>0||!is_bool($ad))$bool=true;
}
return $bool;
}
/**
转换数据库可插入的对象
*/
public function toaddval($str)
{
$adstr="'$str'";
if($this->isempt($str)){
$adstr='null';
}else{
if(substr($str,0,4)=='(&;)')$adstr=substr($str,4);
}
return $adstr;
}
/**
* 替换特殊符合'
*/
public function tocovexec($str, $lx=0)
{
$str = str_replace('\'', '&#39;',$str);
if($lx==1){
$str = str_replace("\n", '',$str);
}
return $str;
}
/**
创建随机编号
*/
public function ranknum($table,$field='num',$n=6, $dx=0)
{
$arr = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$num = '';
for($i=1;$i<=$n;$i++)$num.=$arr[rand(0,count($arr)-1)];
if($dx==1)$num = strtoupper($num);//转换成大写
$rsnum = $this->getmou($table,$field,"`$field`='$num'");
return ($rsnum)?$this->ranknum($table,$field,$n, $dx):$num;
}
/**
流水编号
*/
public function sericnum($num, $table,$fields='sericnum', $ws=4, $whe='')
{
$dts = explode('-', date('Y-m-d'));
$ymd = $dts[0].$dts[1].$dts[2];
$ym = $dts[0].$dts[1];
$num = str_replace('Ymd', $ymd, $num);
$num = str_replace('Ym', $ym, $num);
$num = str_replace('Year', $dts[0], $num);
$num = str_replace('Day', $dts[2], $num);
$num = str_replace('Month', $dts[1], $num);
$where = "`$fields` like '".$num."%' $whe";
$max = (int)$this->getmou($table, "max(cast(replace(`$fields`,'$num','') as decimal(10)))", $where);
$max++;
$wsnum = ''.$max.'';
$len = strlen($wsnum);
$oix = $ws - $len;
for($i=1;$i<=$oix;$i++)$wsnum='0'.$wsnum;
$num .= $wsnum;
return $num;
}
/**
* 获取所有顶级信息连接起来
* @param $table 表名
* @param $pfields 上级字段 $jfield 要连接的字段名 $afid = 值
*/
private $joinarr=array();
public function getpval($table,$pfields,$jfield,$afid,$plit='/',$afield='id',$maxlen=8)
{
$this->joinarr = array();
$this->joinlen = 0;
$this->getpvala($table,$pfields,$jfield,$afid,$afield,$maxlen);
return join($plit,array_reverse($this->joinarr));
}
private function getpvala($table,$pfields,$jfield,$afid,$afield,$maxlen)
{
if(count($this->joinarr)>=$maxlen)return;
$rsa = $this->getone($table,"`$afield`='$afid'","`id`,`$pfields`,`$jfield`");
if($rsa){
$this->joinarr[]=$rsa[$jfield];
$pid = $rsa[$pfields];
if($pid!=$afid)if($this->rows($table,"`$afield`='$pid'")>0)$this->getpvala($table,$pfields,$jfield,$pid,$afield,$maxlen);
}
}
}
class DB{
public static $tablename;
public static function table($tab)
{
self::$tablename = ''.getconfig('.perfix.').$tab.'';
return m($tab);
}
public static function where($f, $v)
{
}
}

View File

@@ -0,0 +1,90 @@
<?php
include_once('mysql.php');
class mysqlClass extends mysql{
protected function connect()
{
$this->errormsg = '';
if(!function_exists('mysql_connect'))exit('不支持mysql_connect的php扩展');
$this->conn = @mysql_connect($this->db_host,$this->db_user, $this->db_pass);
$msg = $this->error();
if($msg){
$this->conn = null;
$this->errormsg = $msg;
}else{
$this->selectdb($this->db_base);
$this->query("SET NAMES 'utf8'");
}
}
protected function selectdb($name)
{
$this->basename = $name;
@mysql_select_db($name, $this->conn);
$msg = $this->error();
if($msg){
$this->errormsg = $msg;
}
}
protected function querysql($sql)
{
return mysql_query($sql,$this->conn);
}
public function fetch_array($result, $type = 0)
{
$result_type = ($type==0)?MYSQL_ASSOC:MYSQL_NUM;
return mysql_fetch_array($result, $result_type);
}
public function insert_id()
{
return mysql_insert_id();
}
protected function starttran()
{
$this->query('BEGIN');
}
protected function endtran($bo)
{
if(!$bo){
$this->query('ROLLBACK');
}else{
$this->query('COMMIT');
}
}
public function getalltable_old()
{
@$result = mysql_list_tables($this->basename);
while($row = mysql_fetch_row($result)) {
$arr[]=$row[0];
}
return $arr;
}
public function getallfields($table)
{
$sql = 'select * from '.$table.' limit 0,0';
$row = $this->query($sql);
$scount = mysql_num_fields($row);
for($i=0; $i<$scount; $i++){
$arr[] = mysql_field_name($row, $i);
}
return $arr;
}
public function error()
{
return mysql_error();
}
public function close()
{
return @mysql_close($this->conn);
}
}

View File

@@ -0,0 +1,71 @@
<?php
include_once('mysql.php');
class mysqliClass extends mysql{
protected function connect()
{
$this->errormsg = '';
$this->conn = @new mysqli($this->db_host,$this->db_user, $this->db_pass, $this->db_base);
if (mysqli_connect_errno()) {
$this->conn = null;
$this->errormsg = mysqli_connect_error();
}else{
$this->selectdb($this->db_base);
$this->conn->query("SET NAMES 'utf8'");
}
}
protected function querysql($sql)
{
return $this->conn->query($sql);
}
public function fetch_array($result, $type = 0)
{
$result_type = ($type==0)?MYSQLI_ASSOC:MYSQLI_NUM;
return $result->fetch_array($result_type);
}
public function insert_id()
{
return $this->conn->insert_id;
}
protected function starttran()
{
$this->conn->autocommit(FALSE);
}
protected function endtran($bo)
{
if(!$bo){
$this->conn->rollback();
}else{
$this->conn->commit();
}
}
public function getallfields($table)
{
$sql = 'select * from '.$table.' limit 0,0';
$result = $this->query($sql);
if(!$result)return array();
$finfo = $result->fetch_fields();
foreach ($finfo as $val) {
$arr[] = $val->name;
}
return $arr;
}
public function error()
{
return 'mysqliError:'.$this->conn->error;
}
public function close()
{
if($this->conn==null)return;
return $this->conn->close();
}
}

View File

@@ -0,0 +1,66 @@
<?php
include_once('mysql.php');
class pdoClass extends mysql{
protected function connect()
{
$this->errormsg = '';
try {
$this->conn = @new PDO('mysql:host='.$this->db_host.';dbname='.$this->db_base.'', $this->db_user, $this->db_pass);
$this->conn->query("SET NAMES 'utf8'");
$this->selectdb($this->db_base);
} catch (PDOException $e) {
$this->conn = null;
$this->errormsg = $e->getMessage();
}
}
protected function querysql($sql)
{
try {
$bo = $this->conn->query($sql);
} catch (PDOException $e) {
$bo = false;
$this->errormsg = $e->getMessage();
}
return $bo;
}
public function fetch_array($result, $type = 0)
{
$result_type = ($type==0)? PDO::FETCH_ASSOC : PDO::FETCH_NUM;
return $result->fetch($result_type);
}
public function insert_id()
{
return $this->conn->lastInsertId();
}
protected function starttran()
{
$this->conn->beginTransaction();
}
protected function endtran($bo)
{
if(!$bo){
$this->conn->rollBack();
}else{
$this->conn->commit();
}
}
public function error()
{
$str = $this->conn->errorInfo();
return 'pdoError('.$str[0].'):'.$str[2].''.$this->errormsg.'';
}
public function close()
{
if($this->conn==null)return;
return $this->conn=null;
}
}

681
include/class/rockClass.php Normal file
View File

@@ -0,0 +1,681 @@
<?php
/**
*****************************************************************
* 联系QQ 290802026 *
* 版 本: V2.0 *
* 开发者:雨中磐石(rainrock) *
* 邮 箱: admin@rockoa.com *
* 说 明: 基础操作类方法 *
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
*****************************************************************
*/
final class rockClass
{
public $ip;
public $host;
public $url;
public $win;
public $web;
public $unarr;
public $now;
public $date;
public $jm;
public $adminid;
public $adminuser;
public $adminname;
public function __construct()
{
$this->ip = $this->getclientip();
$this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '' ;
$this->url = '';
$this->isqywx = false;
$this->win = php_uname();
$this->HTTPweb = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT'] : '' ;
$this->web = $this->getbrowser();
$this->unarr = explode(',','1,2');
$this->now = $this->now();
$this->date = date('Y-m-d');
$this->lvlaras = explode(',','select ,
alter table,delete ,drop ,update ,insert into,load_file,/*,*/,union,<script,</script,sleep(,outfile,eval(,user(,phpinfo(),select*,union%20,sleep%20,select%20,delete%20,drop%20,and%20');
$this->lvlaraa = explode(',','select,alter,delete,drop,update,/*,*/,insert,from,time_so_sec,convert,from_unixtime,unix_timestamp,curtime,time_format,union,concat,information_schema,group_concat,length,load_file,outfile,database,system_user,current_user,user(),found_rows,declare,master,exec,(),select*from,select*');
$this->lvlarab = array();
foreach($this->lvlaraa as $_i)$this->lvlarab[]='';
}
/**
* 特殊字符过滤
*/
public function xssrepstr($str)
{
$xpd = explode(',','(,), , ,<,>,\\,*,&,%,$,^,[,],{,},!,@,#,",+,?,;\'');
$xpd[]= "\n";
return str_ireplace($xpd, '', $str);
}
/*
* 获取IP
*/
public function getclientip()
{
$ip = '';
if(isset($_SERVER['HTTP_CLIENT_IP'])){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else if(isset($_SERVER['REMOTE_ADDR'])){
$ip = $_SERVER['REMOTE_ADDR'];
}
$ip= htmlspecialchars($this->xssrepstr($ip));
if($ip){$ipar = explode('.', $ip);foreach($ipar as $ip1)if(!is_numeric($ip1))$ip='';}
if(!$ip)$ip = 'unknow';
return $ip;
}
public function initRock()
{
$this->jm = c('jm', true);
$this->adminid = (int)$this->session('adminid',0);
$this->adminname= $this->session('adminname');
$this->adminuser= $this->session('adminuser');
}
public function iconvsql($str,$lx=0)
{
$str = str_ireplace($this->lvlaraa,$this->lvlarab,$str);
$str = str_replace("\n",'', $str);
if($lx==1)$str = str_replace(array(' ',' ',' '),array('','',''),$str);
return $str;
}
private function unstr($str)
{
$ystr = '';
for($i=0;$i<count($this->unarr);$i++){
if($this->contain($str,$this->unarr[$i])){
$ystr = $this->unarr[$i];
break;
}
}
return $ystr;
}
public function get($name,$dev='', $lx=0)
{
$val=$dev;
if(isset($_GET[$name]))$val=$_GET[$name];
if($this->isempt($val))$val=$dev;
return $this->jmuncode($val, $lx, $name);
}
public function post($name,$dev='', $lx=0)
{
$val = '';
if(isset($_POST[$name])){$val=$_POST[$name];}else{if(isset($_GET[$name]))$val=$_GET[$name];}
if($this->isempt($val))$val=$dev;
return $this->jmuncode($val, $lx, $name);
}
public function request($name,$dev='', $lx=0)
{
return $this->post($name,$dev,$lx);
}
//get和post参数处理$lx=1:rockjm6:basejm, 3:判断是否rockjm
public function jmuncode($s, $lx=0, $na='')
{
$jmbo = false;
if($lx==3)$jmbo = $this->isjm($s);
if(substr($s, 0, 7)=='rockjm_' || $lx == 1 || $jmbo){
$s = str_replace('rockjm_', '', $s);
$s = $this->jm->uncrypt($s);
if($lx==1){
$jmbo = $this->isjm($s);
if($jmbo)$s = $this->jm->uncrypt($s);
}
}
if(substr($s, 0, 7)=='basejm_' || $lx==5){
$s = str_replace('basejm_', '', $s);
$s = $this->jm->base64decode($s);
}
$s=str_replace("'", '&#39', $s);
$s=str_replace('%20', '', $s);
if($lx==2)$s=str_replace(array('{','}'), array('[H1]','[H2]'), $s);
$str = strtolower($s);
foreach($this->lvlaras as $v1)if($this->contain($str, $v1)){
$this->debug(''.$na.'《'.$s.'》error:包含非法字符《'.$v1.'》','params_err');
$s = $this->lvlarrep($str, $v1);
$str = $s;
}
$cslv = array('m','a','p','d','ip','web','host','ajaxbool','token','adminid');
if(in_array($na, $cslv))$s = $this->xssrepstr($s);
return $this->reteistrs($s);
}
//参数里面禁用/*,*/
private function reteistrs($s){
$lvlaras = array('/*','*/');
$bo = false;
foreach($lvlaras as $v1)if($this->contain($s, $v1)){
$s = str_replace($v1,'', $s);
$bo = true;
}
if($bo)$s = $this->reteistrs($s);
return $s;
}
private function lvlarrep($str, $v1){
$s = str_ireplace($v1,'', $str);
if(contain($s, $v1))$s = $this->lvlarrep($s, $v1);
return $s;
}
public function debug($txt, $lx, $dabo=false)
{
if(!DEBUG && !$dabo)return;
$txt = ''.$txt.''.chr(10).'[URL]'.chr(10).''.$this->nowurl().'';
if($_POST){
$pstr = '';
foreach($_POST as $k=>$v)$pstr.=''.chr(10).'['.$k.']:'.$v.'';
$txt.=''.chr(10).''.chr(10).'[POST]'.$pstr.'';
}
$txt.=''.chr(10).''.chr(10).'[IP]'.chr(10).''.$this->ip.'';
$txt.=''.chr(10).''.chr(10).'[datetime]'.chr(10).''.$this->now().'';
$txt.=''.chr(10).''.chr(10).'[Browser]'.chr(10).''.$this->HTTPweb.'';
$file = ''.UPDIR.'/logs/'.date('Y-m').'/'.$lx.''.date('YmdHis').'_'.str_shuffle('abcdefghijklmn').'.txt';
$this->createtxt($file, $txt);
return $file;
}
/**
* 是否加密的字符串
*/
public function isjm($s)
{
$bo = false;
if(!$s)return $bo;
$bo = preg_match("/^([a-z]{2,3})0([a-z]{2,3})0([a-z]{2,3})0([a-z0])*([1-9]{1,2})$/", $s);
return $bo;
$a = explode('0', $s);
$len= count($a);
if($len>1){
$ls=(int)$a[$len-1];
if($ls>=1&&$ls<=14)$bo=true;
}
return $bo;
}
public function savesession($arr)
{
foreach($arr as $kv=>$vv)$this->setsession($kv,$vv);
}
public function setsession($kv,$vv)
{
$_SESSION[QOM.$kv]=$vv;
}
public function session($name,$dev='')
{
$val = '';
$name = QOM.$name;
if(isset($_SESSION[$name]))$val=$_SESSION[$name];
if($this->isempt($val))$val=$dev;
return $val;
}
public function clearsession($name)
{
$arrn=explode(',',$name);
for($i=0;$i<count($arrn);$i++){
@$_SESSION[QOM.$arrn[$i]]='';
}
}
public function clearallsession()
{
foreach($_SESSION as $key=>$value){
$this->clearsession($key);
}
}
//保存cookie默认是7天
public function savecookie($namarr,$valarr,$expire=360,$path='/',$domain='')
{
$time = time()+$expire*3600*24;
$arrn = explode(',',$namarr);
$valn = $valarr;
if(!is_array($valarr))$valn=explode(',',$valarr);
for($i=0;$i<count($arrn);$i++){
setcookie(QOM.$arrn[$i],$valn[$i], $time, $path,'');
}
}
//获取cookie
public function cookie($name,$dev='')
{
$val = '';
$name = QOM.$name;
if(isset($_COOKIE[$name]))$val=$_COOKIE[$name];
if($this->isempt($val))$val=$dev;
return $val;
}
public function getcookie($namarr)
{
$arrn=explode(',',$namarr);
for($i=0;$i<count($arrn);$i++){
$val[$arrn[$i]]=$this->cookie($arrn[$i]);
}
return $val;
}
//删除cookie
public function clearcookie($name,$path='/',$domain='')
{
//$domain=(empty($domain))?$this->host:$domain;
$arr=explode(',',$name);
for($i=0;$i<count($arr);$i++){
setcookie(QOM.$arr[$i],'',time()-1,$path,$domain);
@$_COOKIE[$arr[$i]]='';
}
}
//删除所有cookie
public function clearallcookie()
{
foreach($_COOKIE as $key=>$value){
$this->clearcookie($key);
}
}
//跳转
public function location($url)
{
header('location:'.$url.'');
exit;
}
public function now($type='Y-m-d H:i:s',$kmti='')
{
if($kmti=='')$kmti=time();
return date($type,$kmti);
}
public function cnweek($date)
{
$arr = array('日','一','二','三','四','五','六');
return $arr[date('w', strtotime($date))];
}
/**
* 判断类型0微信,1钉钉,2安卓原生app,3企业微信,4华为welink,5苹果,6QQ,7REIM平台
*/
public function iswebbro($lx=0)
{
$lxar = array('micromessenger','dingtalk','xinhuapp','wxwork','huawei-anyoffice','iphone','mqqbrowser','reimplat');
return contain(strtolower($this->HTTPweb), $lxar[$lx]);
}
public function getbrowser()
{
$web = $this->HTTPweb;
$val = 'IE';
$parr = array(
array('MSIE 5'),array('MSIE 6'),array('XIAOMI','xiaomi'),array('HUAWEI','huawei'),array('XINHUAPP','xinhu'),array('DingTalk','ding'),array('MSIE 7'),array('MSIE 8'),array('MSIE 9'),array('MSIE 10'),array('MSIE 11'),array('rv:11','MSIE 11'),array('MSIE 12'),array('HuaWei-AnyOffice','welink'),array('MicroMessenger','wxbro'),
array('MSIE 13'),array('Firefox'),array('OPR/','Opera'),array('Edge'),array('MQQBrowser','mqq'),array('Chrome'),array('Safari'),array('Android'),array('iPhone')
);
foreach($parr as $wp){
if(contain($web, $wp[0])){
$val = $wp[0];
if(isset($wp[1]))$val = $wp[1];
break;
}
}
$web = strtolower($web);
if(contain($web,'micromessenger'))$val='wxbro';//微信浏览器
if(contain($web,'dingtalk'))$val='ding';//钉钉浏览器
if($val=='wxbro' && contain($web, 'wxwork'))$this->isqywx = true;
return $val;
}
public function ismobile()
{
$web = strtolower($this->HTTPweb);
$bo = false;
$strar = explode(',','micromessenger,android,mobile,iphone');
foreach($strar as $str){
if(contain($web, $str))return true;
}
return $bo;
}
public function script($daima)
{
echo '<script type="text/javascript">
'.$daima.'
</script>';
}
/**
全角半角转换
*/
public function replace($str,$quantoban=true)
{
$search=array('0','1','2','3','4','5','6','7','8','9',',','.','?','\'','(',')',';','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$replace=array('','','','','','','','','','','','。','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','');
if($quantoban){
$str=str_replace($replace,$search,$str);
}else{
$str=str_replace($search,$replace,$str);
}
return $str;
}
/**
过滤特殊符合
*/
public function repmark($str)
{
$search=array('select','delete','join','inner','outer');
$str=strtolower($str);//转为小写
$str=str_replace($search,'',$str);
return $str;
}
/**
html编码
*/
public function htmlescape($str)
{
$str = htmlspecialchars($str);
return $str;
}
/**
小数点位数
*/
public function number($num,$w=2)
{
if(!$num)$num='0';
return number_format($num,$w,'.','');
}
/**
是否包含返回bool
*/
public function contain($str,$a)
{
$bool=false;
if(!$this->isempt($a) && !$this->isempt($str)){
$ad=strpos($str,$a);
if($ad>0||!is_bool($ad))$bool=true;
}
return $bool;
}
/**
将&#39;转换'
*/
public function covexec($str)
{
$dt = date('Y-m-d');
$str = str_replace(
array('&#39;', '&#39','[F]', '[X]', '[K]', '[A]', '[D]', '[adminid]', '[date]', '{adminid}', '{date}','[H1]','[H2]','&#xing;'),
array('\'', '\'', '\'', '\\', ' ', 'and', '=', $this->adminid, $dt, $this->adminid, $dt,'{','}','*'),
$str
);
return $str;
}
//判断是否为空
public function isempt($str)
{
$bool=false;
if( ($str==''||$str==NULL||empty($str)) && (!is_numeric($str)) )$bool=true;
return $bool;
}
/**
地址
*/
public function rewrite($m,$a,$s)
{
$url = '';
if(REWRITE=='true'){
$url = ''.$m.'';
if($a == '' && $s == ''){
$url = ''.$url.'.html';
}elseif($a == ''){
$url = ''.$url.'_'.$s.'.html';
}else{
$url = ''.$url.'_'.$a.'_'.$s.'_a.html';
}
}else{
$url = 'index.php?m='.$m.'';
if($a != '')$url.='&a='.$a.'';
if($s != '')$url.='&s='.$s.'';
}
return $url;
}
//设置所有的GET方法
public function setallcan($rep=4)
{
foreach($_GET as $key=>$val)$GLOBALS['get_'.$key]=$this->get($key,'',0);
foreach($_POST as $key=>$val)$GLOBALS['post_'.$key]=$this->post($key,'',0);
}
/**
如果字符为空,使用默认的
*/
public function repempt($str,$dev='')
{
$s = $str;
if($this->isempt($s))$s=$dev;
return $s;
}
//返回文件大小
public function formatsize($size)
{
$arr = array('Byte', 'KB', 'MB', 'GB', 'TB', 'PB');
if($size == 0)return '0';
$e = floor(log($size)/log(1024));
return number_format(($size/pow(1024,floor($e))),2,'.','').' '.$arr[$e];
}
/**
采集字符串截取
*/
public function getcai($content,$start,$end)
{
$geju = strpos($content,$start);
if($geju===false){
$cont1='';
}else{
$stard = $geju+strlen($start);
$cont1 = substr($content,$stard);
$endd = strpos($cont1,$end);
$cont1 = substr($cont1,0,$endd);
$cont1 = trim($cont1);
}
return $cont1;
}
/**
* 写入文件
*/
public function createtxt($path, $txt)
{
$this->createdir($path);
$path = ''.ROOT_PATH.'/'.$path.'';
@$file = fopen($path,'w');
$bo = false;
if($file){
$bo = true;
if($txt)$bo = fwrite($file,$txt);
fclose($file);
}
return $bo;
}
/**
* 创建文件夹
*/
public function createdir($path, $oi=1)
{
$zpath = explode('/', $path);
$len = count($zpath);
$mkdir = '';
for($i=0; $i<$len-$oi; $i++){
if(!isempt($zpath[$i])){
$mkdir.='/'.$zpath[$i].'';
$wzdir = ROOT_PATH.''.$mkdir;
if(!is_dir($wzdir)){
mkdir($wzdir);
}
}
}
}
public function stringformat($str, $arr=array())
{
$s = $str;
for($i=0; $i<count($arr); $i++){
$s=str_replace('?'.$i.'', $arr[$i], $s);
}
return $s;
}
public function strformat($str)
{
$len = func_num_args();
$arr = array();
for($i=1; $i<$len; $i++)$arr[] = func_get_arg($i);
$s = $this->stringformat($str, $arr);
return $s;
}
public function T($n)
{
return PREFIX.''.$n;
}
public function reparr($str, $arr=array())
{
if($this->isempt($str))return '';
preg_match_all('/\{(.*?)\}/', $str, $list);
$s = $str;
foreach($list[1] as $k=>$nrs){
$nts = '';
if(isset($arr[$nrs]))$nts = $arr[$nrs];
$s = str_replace('{'.$nrs.'}', $nts, $s);
}
return $s;
}
/**
字段中包含
*/
public function dbinstr($fiekd, $str, $spl1=',', $spl2=',')
{
return "instr(concat('$spl1', $fiekd, '$spl2'), '".$spl1.$str.$spl2."')>0";
}
public function debugs($str, $lxs='')
{
if(!DEBUG)return;
if(is_array($str))$str = json_encode($str, JSON_UNESCAPED_UNICODE);
$msg = '['.$this->now.']:'.$this->nowurl().''.chr(10).''.$str.'';
$mkdir = ''.UPDIR.'/logs/'.date('Y-m').'';
$this->createtxt(''.$mkdir.'/'.$lxs.''.date('Y-m-d.H.i.s').'_'.str_shuffle('abcdefghijklmn').'.log', $msg);
}
public function arrvalue($arr, $k, $dev='')
{
$val = $dev;
if(isset($arr[$k]))$val= $arr[$k];
return $val;
}
/*
* 获取当前访问全部url
*/
public function nowurl()
{
if(!isset($_SERVER['HTTP_HOST']))return '';
$qz = 'http';
if($_SERVER['SERVER_PORT']==443)$qz='https';
$url = ''.$qz.'://'.$_SERVER['HTTP_HOST'];
if(isset($_SERVER['REQUEST_URI']))$url.= $_SERVER['REQUEST_URI'];
return $url;
}
/**
* 获取当前访问URL地址
*/
public function url()
{
$url = $this->nowurl();
$wz = strrpos($url,'/');
return substr($url,0, $wz+1);
}
/**
* 匹配
*/
public function matcharr($str, $lx=0)
{
$match = '/\{(.*?)\}/';
if($lx==1)$match = '/\[(.*?)\]/';
if($lx==2)$match = '/\`(.*?)\`/';
if($lx==3)$match = '/\#(.*?)\#/';
preg_match_all($match, $str, $list);
$barr = array();
foreach($list[1] as $k=>$nrs){
$barr[] = $nrs;
}
return $barr;
}
/**
* 函数参数转为key
*/
public function getfunkey($arr=array(),$qz='a')
{
$s = '';
foreach($arr as $k=>$v)$s.='_'.$v.'';
$s = ''.$qz.''.$s.'';
return $s;
}
/**
* 获取外网地址
*/
public function getouturl($dz='')
{
if($dz=='')$dz = URL;
$xurl = URL;
$xurl1 = getconfig('outurl');
if(!isempt($xurl1))$xurl = $xurl1;
if(substr($xurl,-1)!='/')$xurl.='/';
return $xurl;
}
/**
* 一个完整绝对路径
*/
public function gethttppath($path, $url='', $dev='')
{
if($url=='')$url = URL;
if(isempt($path))return $dev;
if(contain($path, '{FILEURL}')){
$platurl = getconfig('rockfile_url');
if(substr($platurl,-1)!='/')$platurl.='/';
$path = str_replace('{FILEURL}',$platurl,$path);
}
if(substr($path,0,4)!='http')$path = ''.$url.''.$path.'';
return $path;
}
}

File diff suppressed because it is too large Load Diff

291
include/rockFun.php Normal file
View File

@@ -0,0 +1,291 @@
<?php
/**
*****************************************************************
* 联系QQ 290802026 *
* 版 本: V2.0 *
* 开发者:雨中磐石工作室 *
* 邮 箱: admin@rockoa.com *
* 网 址: http://www.rockoa.com/ *
* 说 明: 定义常用的方法 *
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
*****************************************************************
*/
/**
* m 读取数据模型,操作数据库的
* $name 表名/文件名
*/
function m($name)
{
$cls = NULL;
$pats = $nac = '';
$nas = $name;
$asq = explode(':', $nas);
if(count($asq)>1){
$nas = $asq[1];
$nac = $asq[0];
$pats = $nac.'/';
$_pats = ''.ROOT_PATH.'/'.PROJECT.'/model/'.$nac.'/'.$nac.'.php';
if(file_exists($_pats)){
include_once($_pats);
$class = ''.$nac.'Model';
$cls = new $class($nas);
}
}
$class = ''.$nas.'ClassModel';
$path = ''.ROOT_PATH.'/'.PROJECT.'/model/'.$pats.''.$nas.'Model.php';
if(file_exists($path)){
include_once($path);
if($nac!='')$class= $nac.'_'.$class;
$cls = new $class($nas);
}
if($cls==NULL)$cls = new sModel($nas);
return $cls;
}
/**
* 引入插件
* $name 插件名称
* $inbo 是否初始化
* $param1,2,参数
*/
function c($name, $inbo=true, $param1='', $param2='')
{
$class = ''.$name.'Chajian';
$path = ''.ROOT_PATH.'/include/chajian/'.$class.'.php';
$cls = NULL;
if(file_exists($path)){
include_once($path);
if($inbo)$cls = new $class($param1, $param2);
}
return $cls;
}
/**
* 引入class文件
*/
function import($name, $inbo=true)
{
$class = ''.$name.'Class';
$path = ''.ROOT_PATH.'/include/class/'.$class.'.php';
$cls = NULL;
if(file_exists($path)){
include_once($path);
if($inbo){
$cls = new $class();
}
}
return $cls;
}
/**
* 读取配置
*/
function getconfig($key, $dev='')
{
$a = array();
if(isset($GLOBALS['config']))$a = $GLOBALS['config'];
$s = '';
if(isset($a[$key]))$s = $a[$key];
if($s==='')$s = $dev;
return $s;
}
/**
* 判断变量是否为空
* @return boolean
*/
function isempt($str)
{
$bool=false;
if( ($str==''||$str==NULL||empty($str)) && (!is_numeric($str)) )$bool=true;
return $bool;
}
/**
* 判断变量是否包含在另一变量里面
* @return boolean
*/
function contain($str,$a)
{
$bool=false;
if(!isempt($a) && !isempt($str)){
$ad=strpos($str,$a);
if($ad>0||!is_bool($ad))$bool=true;
}
return $bool;
}
/**
* 获取请求的头
* @return string/array
*/
function getheader($key='')
{
$arr = array();
if(function_exists('getallheaders'))$arr = getallheaders();
if($key=='')return $arr;
return arrvalue($arr, $key);
}
/**
* 是否ajax请求
* @return boolean
*/
function isajax()
{
if(strtolower(getheader('X-Requested-With'))=='xmlhttprequest'){
return true;
}else{
return false;
};
}
function backmsg($msg='', $demsg='处理成功', $da=array())
{
$code = 201;
if($msg == ''){
$msg = $demsg;
$code= 200;
}
showreturn($da, $msg, $code);
}
/**
* 返回错误信息
*/
function returnerror($msg='', $code=201, $carr=array())
{
$carr['msg'] = $msg;
$carr['code'] = $code;
$carr['success'] = false;
$carr['data'] = '';
return $carr;
}
/**
* 返回正确信息
*/
function returnsuccess($data=array())
{
$carr['msg'] = '';
$carr['code'] = 200;
$carr['success'] = true;
$carr['data'] = $data;
return $carr;
}
function showreturn($arr='', $msg='', $code=200)
{
$callback = @$_GET['callback'];
$success = true;
if($code != 200)$success = false;
$result = json_encode(array(
'code' => $code,
'msg' => $msg,
'data' => $arr,
'success'=> $success
));
if(!isempt($callback)){
echo ''.$callback.'('.$result.')';
}else{
echo $result;
}
exit();
}
/**
* 错误处理
*/
function rockerror($errno, $errstr,$err_file = '', $err_line = 0){
$str = "File:".$err_file." Line:[$err_line] Error: [$errno] $errstr";
echo $str;exit();
}
/**
* 在数组里读取变量
* @return value
*/
function arrvalue($arr, $k, $dev='')
{
$val = $dev;
if(isset($arr[$k]))$val= $arr[$k];
return $val;
}
/**
* 在对象里读取变量
* @return value
*/
function objvalue($arr, $k, $dev='')
{
$val = $dev;
if(isset($arr->$k))$val= $arr->$k;
return $val;
}
/**
* 过滤字符串的空格
*/
function trimstr($str)
{
return trim(str_replace(' ','',$str));
}
/**
* getallheaders不存在时
*/
if (!function_exists('getallheaders')){
function getallheaders(){
$headers = array();
foreach ($_SERVER as $name => $value) {
if(substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}
function getparams($key, $dev='')
{
if(PHP_SAPI != 'cli'){
return arrvalue($_GET,$key,$dev);
}
$arr = arrvalue($GLOBALS, 'argv');
$sss = '';
if($arr)for($i=2;$i<count($arr);$i++){
$str = $arr[$i];
if(!isempt($str)){
$stra = explode('=', $str);
if($stra[0]=='-'.$key.''){
$sss = arrvalue($stra, 1);
break;
}
}
}
if(isempt($sss))$sss = $dev;
return $sss;
}
/**
* 多语言返回
*/
function lang($key)
{
$data = arrvalue($GLOBALS,'langdata');
$val = '';
if(!$data)return $val;
if(strpos($key,'.')>0){
$skad = explode('.', $key);
$key1 = $skad[0];
$key2 = $skad[1];
$sdat = arrvalue($data[LANG], $key1);
if($sdat)$val = arrvalue($sdat, $key2);
}else{
$val = arrvalue($data[LANG], $key);
}
return $val;
}

View File

@@ -0,0 +1,183 @@
<?php
/**
* 企业微信回调消息加解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
*/
include_once "sha1.php";
include_once "xmlparse.php";
include_once "pkcs7Encoder.php";
include_once "errorCode.php";
class WXBizMsgCrypt
{
private $m_sToken;
private $m_sEncodingAesKey;
private $m_sReceiveId;
/**
* 构造函数
* @param $token string 开发者设置的token
* @param $encodingAesKey string 开发者设置的EncodingAESKey
* @param $receiveId string, 不同应用场景传不同的id
*/
public function __construct($token, $encodingAesKey, $receiveId)
{
$this->m_sToken = $token;
$this->m_sEncodingAesKey = $encodingAesKey;
$this->m_sReceiveId = $receiveId;
}
/*
*验证URL
*@param sMsgSignature: 签名串对应URL参数的msg_signature
*@param sTimeStamp: 时间戳对应URL参数的timestamp
*@param sNonce: 随机串对应URL参数的nonce
*@param sEchoStr: 随机串对应URL参数的echostr
*@param sReplyEchoStr: 解密之后的echostr当return返回0时有效
*@return成功0失败返回对应的错误码
*/
public function VerifyURL($sMsgSignature, $sTimeStamp, $sNonce, $sEchoStr, &$sReplyEchoStr)
{
if (strlen($this->m_sEncodingAesKey) != 43) {
return ErrorCode::$IllegalAesKey;
}
$pc = new Prpcrypt($this->m_sEncodingAesKey);
//verify msg_signature
$sha1 = new SHA1;
$array = $sha1->getSHA1($this->m_sToken, $sTimeStamp, $sNonce, $sEchoStr);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
if ($signature != $sMsgSignature) {
return ErrorCode::$ValidateSignatureError;
}
$result = $pc->decrypt($sEchoStr, $this->m_sReceiveId);
if ($result[0] != 0) {
return $result[0];
}
$sReplyEchoStr = $result[1];
return ErrorCode::$OK;
}
/**
* 将公众平台回复用户的消息加密打包.
* <ol>
* <li>对要发送的消息进行AES-CBC加密</li>
* <li>生成安全签名</li>
* <li>将消息密文和安全签名打包成xml格式</li>
* </ol>
*
* @param $replyMsg string 公众平台待回复用户的消息xml格式的字符串
* @param $timeStamp string 时间戳可以自己生成也可以用URL参数的timestamp
* @param $nonce string 随机串可以自己生成也可以用URL参数的nonce
* @param &$encryptMsg string 加密后的可以直接回复用户的密文包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串,
* 当return返回0时有效
*
* @return int 成功0失败返回对应的错误码
*/
public function EncryptMsg($sReplyMsg, $sTimeStamp, $sNonce, &$sEncryptMsg)
{
$pc = new Prpcrypt($this->m_sEncodingAesKey);
//加密
$array = $pc->encrypt($sReplyMsg, $this->m_sReceiveId);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
if ($sTimeStamp == null) {
$sTimeStamp = time();
}
$encrypt = $array[1];
//生成安全签名
$sha1 = new SHA1;
$array = $sha1->getSHA1($this->m_sToken, $sTimeStamp, $sNonce, $encrypt);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
//生成发送的xml
$xmlparse = new XMLParse;
$sEncryptMsg = $xmlparse->generate($encrypt, $signature, $sTimeStamp, $sNonce);
return ErrorCode::$OK;
}
/**
* 检验消息的真实性,并且获取解密后的明文.
* <ol>
* <li>利用收到的密文生成安全签名,进行签名验证</li>
* <li>若验证通过则提取xml中的加密消息</li>
* <li>对消息进行解密</li>
* </ol>
*
* @param $msgSignature string 签名串对应URL参数的msg_signature
* @param $timestamp string 时间戳 对应URL参数的timestamp
* @param $nonce string 随机串对应URL参数的nonce
* @param $postData string 密文对应POST请求的数据
* @param &$msg string 解密后的原文当return返回0时有效
*
* @return int 成功0失败返回对应的错误码
*/
public function DecryptMsg($sMsgSignature, $sTimeStamp = null, $sNonce, $sPostData, &$sMsg)
{
if (strlen($this->m_sEncodingAesKey) != 43) {
return ErrorCode::$IllegalAesKey;
}
$pc = new Prpcrypt($this->m_sEncodingAesKey);
//提取密文
$xmlparse = new XMLParse;
$array = $xmlparse->extract($sPostData);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
if ($sTimeStamp == null) {
$sTimeStamp = time();
}
$encrypt = $array[1];
//验证安全签名
$sha1 = new SHA1;
$array = $sha1->getSHA1($this->m_sToken, $sTimeStamp, $sNonce, $encrypt);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
if ($signature != $sMsgSignature) {
return ErrorCode::$ValidateSignatureError;
}
$result = $pc->decrypt($encrypt, $this->m_sReceiveId);
if ($result[0] != 0) {
return $result[0];
}
$sMsg = $result[1];
return ErrorCode::$OK;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* error code 说明.
* <ul>
* <li>-40001: 签名验证错误</li>
* <li>-40002: xml解析失败</li>
* <li>-40003: sha加密生成签名失败</li>
* <li>-40004: encodingAesKey 非法</li>
* <li>-40005: corpid 校验错误</li>
* <li>-40006: aes 加密失败</li>
* <li>-40007: aes 解密失败</li>
* <li>-40008: 解密后得到的buffer非法</li>
* <li>-40009: base64加密失败</li>
* <li>-40010: base64解密失败</li>
* <li>-40011: 生成xml失败</li>
* </ul>
*/
class ErrorCode
{
public static $OK = 0;
public static $ValidateSignatureError = -40001;
public static $ParseXmlError = -40002;
public static $ComputeSignatureError = -40003;
public static $IllegalAesKey = -40004;
public static $ValidateCorpidError = -40005;
public static $EncryptAESError = -40006;
public static $DecryptAESError = -40007;
public static $IllegalBuffer = -40008;
public static $EncodeBase64Error = -40009;
public static $DecodeBase64Error = -40010;
public static $GenReturnXmlError = -40011;
}
?>

View File

@@ -0,0 +1,160 @@
<?php
include_once "errorCode.php";
/**
* PKCS7Encoder class
*
* 提供基于PKCS7算法的加解密接口.
*/
class PKCS7Encoder
{
public static $block_size = 32;
/**
* 对需要加密的明文进行填充补位
* @param $text 需要进行填充补位操作的明文
* @return 补齐明文字符串
*/
function encode($text)
{
$block_size = PKCS7Encoder::$block_size;
$text_length = strlen($text);
//计算需要填充的位数
$amount_to_pad = PKCS7Encoder::$block_size - ($text_length % PKCS7Encoder::$block_size);
if ($amount_to_pad == 0) {
$amount_to_pad = PKCS7Encoder::block_size;
}
//获得补位所用的字符
$pad_chr = chr($amount_to_pad);
$tmp = "";
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr;
}
return $text . $tmp;
}
/**
* 对解密后的明文进行补位删除
* @param decrypted 解密后的明文
* @return 删除填充补位后的明文
*/
function decode($text)
{
$pad = ord(substr($text, -1));
if ($pad < 1 || $pad > PKCS7Encoder::$block_size) {
$pad = 0;
}
return substr($text, 0, (strlen($text) - $pad));
}
}
/**
* Prpcrypt class
*
* 提供接收和推送给公众平台消息的加解密接口.
*/
class Prpcrypt
{
public $key = null;
public $iv = null;
/**
* Prpcrypt constructor.
* @param $k
*/
public function __construct($k)
{
$this->key = base64_decode($k . '=');
$this->iv = substr($this->key, 0, 16);
}
/**
* 加密
*
* @param $text
* @param $receiveId
* @return array
*/
public function encrypt($text, $receiveId)
{
try {
//拼接
$text = $this->getRandomStr() . pack('N', strlen($text)) . $text . $receiveId;
//添加PKCS#7填充
$pkc_encoder = new PKCS7Encoder;
$text = $pkc_encoder->encode($text);
//加密
if (function_exists('openssl_encrypt')) {
$encrypted = openssl_encrypt($text, 'AES-256-CBC', $this->key, OPENSSL_ZERO_PADDING, $this->iv);
} else {
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, base64_decode($text), MCRYPT_MODE_CBC, $this->iv);
}
return array(ErrorCode::$OK, $encrypted);
} catch (Exception $e) {
print $e;
return array(MyErrorCode::$EncryptAESError, null);
}
}
/**
* 解密
*
* @param $encrypted
* @param $receiveId
* @return array
*/
public function decrypt($encrypted, $receiveId)
{
try {
//解密
if (function_exists('openssl_decrypt')) {
$decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', $this->key, OPENSSL_ZERO_PADDING, $this->iv);
} else {
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, base64_decode($encrypted), MCRYPT_MODE_CBC, $this->iv);
}
} catch (Exception $e) {
return array(ErrorCode::$DecryptAESError, null);
}
try {
//删除PKCS#7填充
$pkc_encoder = new PKCS7Encoder;
$result = $pkc_encoder->decode($decrypted);
if (strlen($result) < 16) {
return array();
}
//拆分
$content = substr($result, 16, strlen($result));
$len_list = unpack('N', substr($content, 0, 4));
$xml_len = $len_list[1];
$xml_content = substr($content, 4, $xml_len);
$from_receiveId = substr($content, $xml_len + 4);
} catch (Exception $e) {
print $e;
return array(ErrorCode::$IllegalBuffer, null);
}
if ($from_receiveId != $receiveId) {
return array(ErrorCode::$ValidateCorpidError, null);
}
return array(0, $xml_content);
}
/**
* 生成随机字符串
*
* @return string
*/
private function getRandomStr()
{
$str = '';
$str_pol = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyl';
$max = strlen($str_pol) - 1;
for ($i = 0; $i < 16; $i++) {
$str .= $str_pol[mt_rand(0, $max)];
}
return $str;
}
}

36
include/weixin/sha1.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
include_once "errorCode.php";
/**
* SHA1 class
*
* 计算公众平台的消息签名接口.
*/
class SHA1
{
/**
* 用SHA1算法生成安全签名
* @param string $token 票据
* @param string $timestamp 时间戳
* @param string $nonce 随机字符串
* @param string $encrypt 密文消息
*/
public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
{
//排序
try {
$array = array($encrypt_msg, $token, $timestamp, $nonce);
sort($array, SORT_STRING);
$str = implode($array);
return array(ErrorCode::$OK, sha1($str));
} catch (Exception $e) {
print $e . "\n";
return array(ErrorCode::$ComputeSignatureError, null);
}
}
}
?>

View File

@@ -0,0 +1,61 @@
<?php
include_once "errorCode.php";
/**
* XMLParse class
*
* 提供提取消息格式中的密文及生成回复消息格式的接口.
*/
class XMLParse
{
/**
* 提取出xml数据包中的加密消息
* @param string $xmltext 待提取的xml字符串
* @return string 提取出的加密消息字符串
*/
public function extract($xmltext)
{
try {
$xml = new DOMDocument();
$xml->loadXML($xmltext);
$array_e = $xml->getElementsByTagName('Encrypt');
$encrypt = $array_e->item(0)->nodeValue;
return array(0, $encrypt);
} catch (Exception $e) {
print $e . "\n";
return array(ErrorCode::$ParseXmlError, null);
}
}
/**
* 生成xml消息
* @param string $encrypt 加密后的消息密文
* @param string $signature 安全签名
* @param string $timestamp 时间戳
* @param string $nonce 随机字符串
*/
public function generate($encrypt, $signature, $timestamp, $nonce)
{
$format = "<xml>
<Encrypt><![CDATA[%s]]></Encrypt>
<MsgSignature><![CDATA[%s]]></MsgSignature>
<TimeStamp>%s</TimeStamp>
<Nonce><![CDATA[%s]]></Nonce>
</xml>";
return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
}
}
//
// Test
/*
$sPostData = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><AgentID><![CDATA[toAgentID]]></AgentID><Encrypt><![CDATA[msg_encrypt]]></Encrypt></xml>";
$xmlparse = new XMLParse;
$array = $xmlparse->extract($sPostData);
var_dump($array);
*/
?>