public static function make_html() { global $_G; if (self::$htmlfilename) { $filepath = DISCUZ_ROOT . '/' . self::$htmlfilename . '.' . $_G['setting']['makehtml']['extendname']; dmkdir(dirname($filepath)); $cend = '</body></html>'; $code = ob_get_clean() . $cend; $code = preg_replace('/language\\s*=[\\s|\'|\\"]*php/is', '_', $code); $code = str_replace(array('<?', '?>'), array('<?', '?>'), $code); if (file_put_contents($filepath, $code) !== false) { $_G['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start(); if (self::$callback && is_callable(self::$callback)) { call_user_func(self::$callback); self::$callback = self::$callbackdata = null; } self::$returndata['status'] = 'html_ok'; if (isset(self::$viewurl)) { self::$returndata['path'] = self::$viewurl; } else { self::$returndata['path'] = self::$htmlfilename . '.' . $_G['setting']['makehtml']['extendname']; } showmessage('do_success', null, self::$returndata); } } }
function update_mokuai($biaoshi, $version, $mukauidata) { global $_G; require_once libfile('class/xml'); $mokuais = $mokuais_temp = xml2array(file_get_contents(MOKUAI_DIR . "/server/1.0/Data/mokuai.xml")); if (!is_dir(MOKUAI_DIR . '/' . $biaoshi)) { $mokuais_temp[$biaoshi]['biaoshi'] = $biaoshi; dmkdir(MOKUAI_DIR . '/' . $biaoshi); } $mokuaivers = getmokuaivers($biaoshi); if (count($mokuaivers) == 1) { $mokuais_temp[$biaoshi]['currentversion'] = $mokuaivers[0]; } if (!is_dir(MOKUAI_DIR . '/' . $biaoshi . '/' . $version)) { $mokuais_temp[$biaoshi]['version'][$version]['biaoshi'] = $version; dmkdir(MOKUAI_DIR . '/' . $biaoshi . '/' . $version); } foreach (array('Controler', 'Modal', 'View', 'Data') as $k => $v) { if (!is_dir(MOKUAI_DIR . '/' . $biaoshi . '/' . $version . '/' . $v)) { dmkdir(MOKUAI_DIR . '/' . $biaoshi . '/' . $version . '/' . $v); } } foreach ($mukauidata as $k2 => $v2) { $mokuais_temp[$biaoshi]['version'][$version][$k2] = $v2; } if ($mokuais != $mokuais_temp) { $mokuais = $mokuais_temp; $mokuais = array_sort($mokuais, 'displayorder', 'asc'); file_put_contents(MOKUAI_DIR . "/server/1.0/Data/mokuai.xml", diconv(array2xml($mokuais, 1), "UTF-8", $_G['charset'] . "//IGNORE")); } }
function check_github_update($path = '') { global $_G; //dump('1'); $github_dir = 'C:\\GitHub\\17xue8'; //本地的GitHub的17xue8文件夹 clearstatcache(); if ($path == '') { $path = $github_dir; } $out_path = substr(DISCUZ_ROOT, 0, -1) . str_replace($github_dir, '', $path); //本地的wamp的17xue8文件夹 if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && substr($file, 0, 1) != "." && $file != "mokuai") { if (is_dir($path . "/" . $file)) { if (!is_dir($out_path . "/" . $file)) { dmkdir($out_path . "/" . $file); } check_github_update($path . "/" . $file); } else { if (filemtime($path . "/" . $file) > filemtime($out_path . "/" . $file)) { //GitHub文件修改时间大于wamp时 file_put_contents($out_path . "/" . $file, diconv(file_get_contents($path . "/" . $file), "UTF-8", "GBK//IGNORE")); } } } } } }
private function init() { if (!function_exists('curl_init')) { throw new Exception('您的当前环境不支持curl,请开通后再使用'); } $this->ch = curl_init(); if ($this->debug && $this->proxy) { //本机开启代理,抓包时非常有用. curl_setopt($this->ch, CURLOPT_PROXY, $this->proxy); } curl_setopt($this->ch, CURLOPT_HEADER, false); //将头文件的信息作为数据流输出。 curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回 curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在 curl_setopt($this->ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true); // 使用自动跳转 curl_setopt($this->ch, CURLOPT_MAXREDIRS, 5); //指定最多的HTTP重定向的数量,这个选项是和CURLOPT_FOLLOWLOCATION一起使用的。 curl_setopt($this->ch, CURLOPT_AUTOREFERER, true); // 自动设置Referer curl_setopt($this->ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // curl_setopt($this->ch_, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded")); if ($this->is_save_cookie) { if (!$this->cookie_file) { $uri = parse_url($this->url); $this->cookie_file = str_replace('.', '_', $uri['host']) . '.txt'; } if (!is_dir(dirname(__FILE__) . '/' . $this->dir)) { dmkdir(dirname(__FILE__) . '/' . $this->dir); } $this->cookie_file = dirname(__FILE__) . '/' . $this->dir . $this->cookie_file; if (!file_exists($this->cookie_file)) { file_put_contents($this->cookie_file, ''); } curl_setopt($this->ch, CURLOPT_COOKIE, true); curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->cookie_file); // 存放Cookie信息的文件名称 curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->cookie_file); // 读取上面所储存的Cookie信息 } curl_setopt($this->ch, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环 curl_setopt($this->ch, CURLOPT_HEADER, $this->is_get_headers); // 显示返回的Header区域内容 curl_setopt($this->ch, CURLOPT_REFERER, $this->referer ? $this->referer : $this->url); $this->header = array("Accept: */*", "Accept-Language: zh-CN,zh;q=0.8", "Cache-Control:no-cache", "Connection:keep-alive", "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT']); if ($this->ip) { $this->header[] = "X-Forwarded-For: " . $this->ip; $this->header[] = "CLIENT-IP: " . $this->ip; } curl_setopt($this->ch, CURLOPT_HTTPHEADER, $this->header); //设置头信息的地方 }
function album_update_pic($albumid, $picid = 0) { global $_G; $setarr = array(); if ($picid) { $wheresql = "AND picid='{$picid}'"; } else { $wheresql = "ORDER BY picid DESC LIMIT 1"; $piccount = getcount('home_pic', array('albumid' => $albumid, 'status' => '0')); if (empty($piccount) && getcount('home_pic', array('albumid' => $albumid)) == 0) { DB::query("DELETE FROM " . DB::table('home_album') . " WHERE albumid='{$albumid}'"); return false; } else { $setarr['picnum'] = $piccount; } } $query = DB::query("SELECT * FROM " . DB::table('home_pic') . " WHERE albumid='{$albumid}' {$wheresql}"); if (!($pic = DB::fetch($query))) { return false; } $from = $pic['remote']; $pic['remote'] = $pic['remote'] > 1 ? $pic['remote'] - 2 : $pic['remote']; $basedir = !getglobal('setting/attachdir') ? DISCUZ_ROOT . './data/attachment/' : getglobal('setting/attachdir'); $picdir = 'cover/' . substr(md5($albumid), 0, 2) . '/'; dmkdir($basedir . './album/' . $picdir); if ($pic['remote']) { $picsource = pic_get($pic['filepath'], $from > 1 ? 'forum' : 'album', $pic['thumb'], $pic['remote'], 0); } else { $picsource = $basedir . './' . ($from > 1 ? 'forum' : 'album') . '/' . $pic['filepath']; } require_once libfile('class/image'); $image = new image(); if ($image->Thumb($picsource, 'album/' . $picdir . $albumid . '.jpg', 120, 120, 2)) { $setarr['pic'] = $picdir . $albumid . '.jpg'; $setarr['picflag'] = 1; if (getglobal('setting/ftp/on')) { if (ftpcmd('upload', 'album/' . $picdir . $albumid . '.jpg')) { $setarr['picflag'] = 2; @unlink($_G['setting']['attachdir'] . 'album/' . $picdir . $albumid . '.jpg'); } } } else { if ($pic['status'] == 0) { $setarr['pic'] = $pic['thumb'] ? $pic['filepath'] . '.thumb.jpg' : $pic['filepath']; } if ($from > 1) { $setarr['picflag'] = $pic['remote'] ? 4 : 3; } else { $setarr['picflag'] = $pic['remote'] ? 2 : 1; } } $setarr['updatetime'] = $_G['timestamp']; DB::update('home_album', $setarr, array('albumid' => $albumid)); return true; }
function album_update_pic($albumid, $picid = 0) { global $_G; $setarr = array(); if (!$picid) { $piccount = C::t('home_pic')->check_albumpic($albumid, 0); if (empty($piccount) && C::t('home_pic')->check_albumpic($albumid) == 0) { C::t('home_album')->delete($albumid); return false; } else { $setarr['picnum'] = $piccount; } } $query = C::t('home_pic')->fetch_all_by_albumid($albumid, 0, 1, $picid, 1); if (!($pic = $query[0])) { return false; } $from = $pic['remote']; $pic['remote'] = $pic['remote'] > 1 ? $pic['remote'] - 2 : $pic['remote']; $basedir = !getglobal('setting/attachdir') ? DISCUZ_ROOT . './data/attachment/' : getglobal('setting/attachdir'); $picdir = 'cover/' . substr(md5($albumid), 0, 2) . '/'; dmkdir($basedir . './album/' . $picdir); if ($pic['remote']) { $picsource = pic_get($pic['filepath'], $from > 1 ? 'forum' : 'album', $pic['thumb'], $pic['remote'], 0); } else { $picsource = $basedir . './' . ($from > 1 ? 'forum' : 'album') . '/' . $pic['filepath']; } require_once libfile('class/image'); $image = new image(); if ($image->Thumb($picsource, 'album/' . $picdir . $albumid . '.jpg', 120, 120, 2)) { $setarr['pic'] = $picdir . $albumid . '.jpg'; $setarr['picflag'] = 1; if (getglobal('setting/ftp/on')) { if (ftpcmd('upload', 'album/' . $picdir . $albumid . '.jpg')) { $setarr['picflag'] = 2; @unlink($_G['setting']['attachdir'] . 'album/' . $picdir . $albumid . '.jpg'); } } } else { if ($pic['status'] == 0) { $setarr['pic'] = $pic['thumb'] ? getimgthumbname($pic['filepath']) : $pic['filepath']; } if ($from > 1) { $setarr['picflag'] = $pic['remote'] ? 4 : 3; } else { $setarr['picflag'] = $pic['remote'] ? 2 : 1; } } $setarr['updatetime'] = $_G['timestamp']; C::t('home_album')->update($albumid, $setarr); return true; }
public function getQRcodeBySid($sid) { $target = './qrcode/' . $sid[0] . '/' . $sid . '.png'; $targetpath = dirname(getglobal('setting/attachdir') . $target); dmkdir($targetpath); if (@getimagesize(getglobal('setting/attachdir') . $target)) { return getglobal('setting/attachurl') . $target; } else { //生成二维码 QRcode::png(getglobal('siteurl') . 's.php?sid=' . $sid, getglobal('setting/attachdir') . $target, 'M', 4, 2); return getglobal('setting/attachurl') . $target; } }
function downloadmyappicon($appid) { $iconpath = getglobal('setting/attachdir') . './' . 'myapp/icon/' . $appid . '.jpg'; if (!is_dir(dirname($iconpath))) { dmkdir(dirname($iconpath)); } DB::update('common_myapp', array('iconstatus' => '-1'), array('appid' => $appid)); $icondata = file_get_contents(getmyappiconpath($appid, 0)); if ($icondata) { file_put_contents($iconpath, $icondata); DB::update('common_myapp', array('iconstatus' => '1', 'icondowntime' => TIMESTAMP), array('appid' => $appid)); } }
function upload($file) { global $_G; if (!class_exists('upload')) { include ROOT_PATH . 'web/upload.class.php'; } if (!is_array($file)) { $file = $this->file; } $upload = new upload(); $img_arr = $attach = array(); $upload_path = '/assets/uploads/'; $rs = $upload->init($file, $upload_path); if (!$rs) { return false; } $attach =& $upload->attach; if ($attach['extension'] != 'jpg' && $attach['extension'] != 'png') { $this->file_type = '.' . $attach['extension']; $this->__construct(); } if ($attach['extension'] == 'attach' && $attach['isimage'] != 1) { $this->msg = '上传的文件非图片'; L($this->msg); @unlink($attach['tmp_name']); return false; //非可上传的文件,就禁止上传了 } $upload_max_size = $_G['setting']['upload_max_size'] ? intval($_G['setting']['upload_max_size']) : 2; if ($attach['size'] > 1024 * 1024 * $upload_max_size) { $this->msg = '上传文件失败,系统设置最大上传大为:' . $upload_max_size . 'MB'; L($this->msg); @unlink($attach['tmp_name']); return false; } if ($attach['errorcode']) { $this->msg = '上传图片失败' . errormessage(); @unlink($attach['tmp_name']); L($this->msg); return false; } $lang_path = ROOT_PATH . $upload_path . $this->dir2; if (!is_dir($lang_path)) { dmkdir($lang_path); } $attach['target'] = $lang_path . $this->name; $upload->save(); return $upload_path . $this->dir2 . $this->name; }
function srsysfilecache($data, $file) { global $_G; $data = stripcslashes($data); $dir = DISCUZ_ROOT . './data/sysdata/'; if (!is_dir($dir)) { dmkdir($dir, 0777); } if ($fp = @fopen($dir . 'cache_' . $file, 'wb')) { fwrite($fp, $data); fclose($fp); } else { exit('Can not write to cache files, please check directory ./data/ and ./data/sysdata/ .'); } }
function set_cache($key, $value, $life) { global $_G; $data = array($key => array('data' => $value, 'life' => $life)); require_once libfile('function/cache'); $cache_file = $this->get_cache_file_path($key); dmkdir(dirname($cache_file)); $cachedata = "\$data = " . arrayeval($data) . ";\n"; if ($fp = @fopen($cache_file, 'wb')) { fwrite($fp, "<?php\n//Discuz! cache file, DO NOT modify me!" . "\n//Created: " . date("M j, Y, G:i") . "\n//Identify: " . md5($cache_file . $cachedata . $_G['config']['security']['authkey']) . "\n\nif(!defined('IN_DISCUZ')) {\n\texit('Access Denied');\n}\n\n{$cachedata}?>"); fclose($fp); } else { exit('Can not write to cache files, please check directory ./data/ and ./data/ultraxcache/ .'); } return true; }
function writetocache($script, $cachedata, $prefix = 'cache_', $define_path = '') { global $_G; if ($define_path) { $dir = $define_path; } else { $dir = SITE_ROOT . './data/sysdata/'; } if (!is_dir($dir)) { dmkdir($dir, 0777); } if ($fp = @fopen("{$dir}{$prefix}{$script}.php", 'wb')) { fwrite($fp, "<?php\n//DZF! cache file, DO NOT modify me!\n//Identify: " . md5($prefix . $script . '.php' . $cachedata . $_G['config']['security']['authkey']) . "\n\n{$cachedata}?>"); fclose($fp); } else { exit('Can not write to cache files, please check directory ./data/ and ./data/sysdata/ .'); } }
public static function make_html() { global $_G; if (self::$htmlfilename) { $filepath = DISCUZ_ROOT . '/' . self::$htmlfilename . '.' . $_G['setting']['makehtml']['extendname']; dmkdir(dirname($filepath)); $cend = '</body></html>'; if (file_put_contents($filepath, ob_get_clean() . $cend) !== false) { $_G['gzipcompress'] ? ob_start('ob_gzhandler') : ob_start(); if (self::$callback && is_callable(self::$callback)) { call_user_func(self::$callback); self::$callback = self::$callbackdata = null; } self::$returndata['status'] = 'html_ok'; if (isset(self::$viewurl)) { self::$returndata['path'] = self::$viewurl; } else { self::$returndata['path'] = self::$htmlfilename . '.' . $_G['setting']['makehtml']['extendname']; } showmessage('do_success', null, self::$returndata); } } }
function setthreadcover($pid, $tid = 0, $aid = 0) { global $_G; $cover = 0; if (empty($_G['uid']) || !intval($_G['setting']['forumpicstyle']['thumbwidth']) || !intval($_G['setting']['forumpicstyle']['thumbwidth'])) { return false; } if (($pid || $aid) && empty($tid)) { if ($aid) { $attachtable = getattachtablebyaid($aid); $wheresql = "aid='{$aid}' AND isimage IN ('1', '-1')"; } else { $attachtable = getattachtablebypid($pid); $wheresql = "pid='{$pid}' AND isimage IN ('1', '-1') ORDER BY width DESC LIMIT 1"; } $query = DB::query("SELECT * FROM " . DB::table($attachtable) . " WHERE {$wheresql}"); if (!($attach = DB::fetch($query))) { return false; } if (empty($_G['forum']['ismoderator']) && $_G['uid'] != $attach['uid']) { return false; } $pid = empty($pid) ? $attach['pid'] : $pid; $tid = empty($tid) ? $attach['tid'] : $tid; $basedir = !$_G['setting']['attachdir'] ? DISCUZ_ROOT . './data/attachment/' : $_G['setting']['attachdir']; $coverdir = 'threadcover/' . substr(md5($tid), 0, 2) . '/' . substr(md5($tid), 2, 2) . '/'; dmkdir($basedir . './forum/' . $coverdir); $picsource = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'forum/' . $attach['attachment']; require_once libfile('class/image'); $image = new image(); if ($image->Thumb($picsource, 'forum/' . $coverdir . $tid . '.jpg', $_G['setting']['forumpicstyle']['thumbwidth'], $_G['setting']['forumpicstyle']['thumbheight'], 2)) { $remote = ''; if (getglobal('setting/ftp/on')) { if (ftpcmd('upload', 'forum/' . $coverdir . $tid . '.jpg')) { $remote = '-'; } } $cover = DB::result_first("SELECT COUNT(*) FROM " . DB::table($attachtable) . " WHERE pid='{$pid}' AND isimage IN ('1', '-1')"); $cover = $remote . $cover; } else { return false; } } if ($tid || $cover) { if (empty($cover)) { $oldcover = DB::result_first("SELECT cover FROM " . DB::table('forum_thread') . " WHERE tid='{$tid}'"); $cover = DB::result_first("SELECT COUNT(*) FROM " . DB::table(getattachtablebytid($tid)) . " WHERE pid='{$pid}' AND isimage IN ('1', '-1')"); $cover = $cover && $oldcover < 0 ? '-' . $cover : $cover; } DB::update('forum_thread', array('cover' => $cover), array('tid' => $tid)); } return true; }
function setthreadcover($pid, $tid = 0, $aid = 0, $countimg = 0, $imgurl = '') { global $_G; $cover = 0; if (empty($_G['uid']) || !intval($_G['setting']['forumpicstyle']['thumbheight']) || !intval($_G['setting']['forumpicstyle']['thumbwidth'])) { return false; } if (($pid || $aid) && empty($countimg)) { if (empty($imgurl)) { if ($aid) { $attachtable = 'aid:' . $aid; $attach = C::t('forum_attachment_n')->fetch('aid:' . $aid, $aid, array(1, -1)); } else { $attachtable = 'pid:' . $pid; $attach = C::t('forum_attachment_n')->fetch_max_image('pid:' . $pid, 'pid', $pid); } if (!$attach) { return false; } if (empty($_G['forum']['ismoderator']) && $_G['uid'] != $attach['uid']) { return false; } $pid = empty($pid) ? $attach['pid'] : $pid; $tid = empty($tid) ? $attach['tid'] : $tid; $picsource = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'forum/' . $attach['attachment']; } else { $attachtable = 'pid:' . $pid; $picsource = $imgurl; } $basedir = !$_G['setting']['attachdir'] ? DISCUZ_ROOT . './data/attachment/' : $_G['setting']['attachdir']; $coverdir = 'threadcover/' . substr(md5($tid), 0, 2) . '/' . substr(md5($tid), 2, 2) . '/'; dmkdir($basedir . './forum/' . $coverdir); require_once libfile('class/image'); $image = new image(); if ($image->Thumb($picsource, 'forum/' . $coverdir . $tid . '.jpg', $_G['setting']['forumpicstyle']['thumbwidth'], $_G['setting']['forumpicstyle']['thumbheight'], 2)) { $remote = ''; if (getglobal('setting/ftp/on')) { if (ftpcmd('upload', 'forum/' . $coverdir . $tid . '.jpg')) { $remote = '-'; } } $cover = C::t('forum_attachment_n')->count_image_by_id($attachtable, 'pid', $pid); if ($imgurl && empty($cover)) { $cover = 1; } $cover = $remote . $cover; } else { return false; } } if ($countimg) { if (empty($cover)) { $thread = C::t('forum_thread')->fetch($tid); $oldcover = $thread['cover']; $cover = C::t('forum_attachment_n')->count_image_by_id('tid:' . $tid, 'pid', $pid); if ($cover) { $cover = $oldcover < 0 ? '-' . $cover : $cover; } } } if ($cover) { C::t('forum_thread')->update($tid, array('cover' => $cover)); return true; } }
function updatetopic($topic = '') { global $_G; $topicid = empty($topic) ? '' : $topic['topicid']; include_once libfile('function/home'); $_POST['title'] = getstr(trim($_POST['title']), 255); $_POST['name'] = getstr(trim($_POST['name']), 255); $_POST['domain'] = getstr(trim($_POST['domain']), 255); if (empty($_POST['title'])) { return 'topic_title_cannot_be_empty'; } if (empty($_POST['name'])) { $_POST['name'] = $_POST['title']; } if (!$topicid || $_POST['name'] != $topic['name']) { if ($value = C::t('portal_topic')->fetch_by_name($_POST['name'])) { return 'topic_name_duplicated'; } } if ($topicid && !empty($topic['domain'])) { require_once libfile('function/delete'); deletedomain($topicid, 'topic'); } if (!empty($_POST['domain'])) { require_once libfile('function/domain'); domaincheck($_POST['domain'], $_G['setting']['domain']['root']['topic'], 1); } $setarr = array('title' => $_POST['title'], 'name' => $_POST['name'], 'domain' => $_POST['domain'], 'summary' => getstr($_POST['summary']), 'keyword' => getstr($_POST['keyword']), 'useheader' => $_POST['useheader'] ? '1' : '0', 'usefooter' => $_POST['usefooter'] ? '1' : '0', 'allowcomment' => $_POST['allowcomment'] ? 1 : 0, 'closed' => $_POST['closed'] ? 0 : 1); if ($_POST['deletecover'] && $topic['cover']) { if ($topic['picflag'] != '0') { pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0'); } $setarr['cover'] = ''; } else { if ($_FILES['cover']['tmp_name']) { if ($topic['cover'] && $topic['picflag'] != '0') { pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0'); } $pic = pic_upload($_FILES['cover'], 'portal'); if ($pic) { $setarr['cover'] = 'portal/' . $pic['pic']; $setarr['picflag'] = $pic['remote'] ? '2' : '1'; } } else { if (!empty($_POST['cover']) && $_POST['cover'] != $topic['cover']) { if ($topic['cover'] && $topic['picflag'] != '0') { pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0'); } $setarr['cover'] = $_POST['cover']; $setarr['picflag'] = '0'; } } } $primaltplname = ''; if (empty($topicid) || empty($topic['primaltplname']) || $topic['primaltplname'] && $topic['primaltplname'] != $_POST['primaltplname']) { $primaltplname = $_POST['primaltplname']; if (!isset($_POST['signs'][dsign($primaltplname)])) { return 'diy_sign_invalid'; } $checktpl = checkprimaltpl($primaltplname); if ($checktpl !== true) { return $checktpl; } $setarr['primaltplname'] = $primaltplname; } if ($topicid) { C::t('portal_topic')->update($topicid, $setarr); C::t('common_diy_data')->update('portal/portal_topic_content_' . $topicid, getdiydirectory($topic['primaltplname']), array('name' => $setarr['title'])); } else { $setarr['uid'] = $_G['uid']; $setarr['username'] = $_G['username']; $setarr['dateline'] = $_G['timestamp']; $setarr['closed'] = '1'; $topicid = addtopic($setarr); if (!$topicid) { return 'topic_created_failed'; } } if (!empty($_POST['domain'])) { C::t('common_domain')->insert(array('domain' => $_POST['domain'], 'domainroot' => $_G['setting']['domain']['root']['topic'], 'id' => $topicid, 'idtype' => 'topic')); } $tpldirectory = ''; if ($primaltplname && $topic['primaltplname'] != $primaltplname) { $targettplname = 'portal/portal_topic_content_' . $topicid; if (strpos($primaltplname, ':') !== false) { list($tpldirectory, $primaltplname) = explode(':', $primaltplname); } C::t('common_diy_data')->update($targettplname, getdiydirectory($topic['primaltplname']), array('primaltplname' => $primaltplname, 'tpldirectory' => $tpldirectory)); updatediytemplate($targettplname); } if ($primaltplname && empty($topic['primaltplname'])) { $tpldirectory = $tpldirectory ? $tpldirectory : $_G['cache']['style_default']['tpldir']; $content = file_get_contents(DISCUZ_ROOT . $tpldirectory . '/' . $primaltplname . '.htm'); $tplfile = DISCUZ_ROOT . './data/diy/' . $tpldirectory . '/portal/portal_topic_content_' . $topicid . '.htm'; $tplpath = dirname($tplfile); if (!is_dir($tplpath)) { dmkdir($tplpath); } file_put_contents($tplfile, $content); } include_once libfile('function/cache'); updatecache(array('diytemplatename', 'setting')); return $topicid; }
function updatetopic($topic = '') { global $_G; $topicid = empty($topic) ? '' : $topic['topicid']; include_once libfile('function/home'); $_POST['title'] = getstr(trim($_POST['title']), 255, 1, 1); $_POST['name'] = getstr(trim($_POST['name']), 255, 1, 1); $_POST['domain'] = getstr(trim($_POST['domain']), 255, 1, 1); if (empty($_POST['title'])) { return 'topic_title_cannot_be_empty'; } if (empty($_POST['name'])) { $_POST['name'] = $_POST['title']; } if (!$topicid || $_POST['name'] != $topic['name']) { $value = DB::fetch_first('SELECT * FROM ' . DB::table('portal_topic') . " WHERE name = '{$_POST['name']}' LIMIT 1"); if ($value) { return 'topic_name_duplicated'; } } if ($topicid && !empty($topic['domain'])) { require_once libfile('function/delete'); deletedomain($topicid, 'topic'); } if (!empty($_POST['domain'])) { require_once libfile('function/domain'); domaincheck($_POST['domain'], $_G['setting']['domain']['root']['topic'], 1); } $setarr = array('title' => $_POST['title'], 'name' => $_POST['name'], 'domain' => $_POST['domain'], 'summary' => getstr($_POST['summary'], '', 1, 1), 'keyword' => getstr($_POST['keyword'], '', 1, 1), 'useheader' => $_POST['useheader'] ? '1' : '0', 'usefooter' => $_POST['usefooter'] ? '1' : '0', 'allowcomment' => $_POST['allowcomment'] ? 1 : 0, 'closed' => $_POST['closed'] ? 0 : 1); if ($_POST['deletecover'] && $topic['cover']) { if ($topic['picflag'] != '0') { pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0'); } $setarr['cover'] = ''; } else { if ($_FILES['cover']['tmp_name']) { if ($topic['cover'] && $topic['picflag'] != '0') { pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0'); } $pic = pic_upload($_FILES['cover'], 'portal'); if ($pic) { $setarr['cover'] = 'portal/' . $pic['pic']; $setarr['picflag'] = $pic['remote'] ? '2' : '1'; } } else { if (!empty($_POST['cover']) && $_POST['cover'] != $topic['cover']) { if ($topic['cover'] && $topic['picflag'] != '0') { pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0'); } $setarr['cover'] = $_POST['cover']; $setarr['picflag'] = '0'; } } } $primaltplname = ''; if (empty($topicid) || empty($topic['primaltplname']) || $topic['primaltplname'] && $topic['primaltplname'] != 'portal/' . $_POST['primaltplname']) { $primaltplname = 'portal/' . $_POST['primaltplname']; $checktpl = checkprimaltpl($primaltplname); if ($checktpl !== true) { return $checktpl; } $setarr['primaltplname'] = $primaltplname; } if ($topicid) { DB::update('portal_topic', $setarr, array('topicid' => $topicid)); DB::update('common_diy_data', array('name' => $setarr['title']), array('targettplname' => 'portal/portal_topic_content_' . $topicid)); } else { $setarr['uid'] = $_G['uid']; $setarr['username'] = $_G['username']; $setarr['dateline'] = $_G['timestamp']; $setarr['closed'] = '1'; $topicid = addtopic($setarr); if (!$topicid) { return 'topic_created_failed'; } } if (!empty($_POST['domain'])) { DB::insert('common_domain', array('domain' => $_POST['domain'], 'domainroot' => addslashes($_G['setting']['domain']['root']['topic']), 'id' => $topicid, 'idtype' => 'topic')); } if ($topic['primaltplname'] != $primaltplname) { $targettplname = 'portal/portal_topic_content_' . $topicid; DB::update('common_diy_data', array('primaltplname' => $primaltplname), array('targettplname' => $targettplname)); updatediytemplate($targettplname); } if ($primaltplname && empty($topic['primaltplname'])) { $content = file_get_contents(DISCUZ_ROOT . './template/default/' . $primaltplname . '.htm'); $tplfile = DISCUZ_ROOT . './data/diy/portal/portal_topic_content_' . $topicid . '.htm'; $tplpath = dirname($tplfile); if (!is_dir($tplpath)) { dmkdir($tplpath); } file_put_contents($tplfile, $content); } include_once libfile('function/cache'); updatecache(array('diytemplatename', 'setting')); return $topicid; }
$data = cloudaddons_open('&mod=app&ac=download&rid=' . $_GET['rid'] . '&packnum=' . $packnum); $_GET['importtxt'] = $data; $array = getimportdata('Discuz! File Pack'); if (!$array['Status']) { list($_cur, $_max) = explode('/', $array['part']); $percent = intval($_cur / $_max * 100); if ($array['type'] != $_GET['type'] || $array['key'] != $_GET['key'] || !$array['files']) { dir_clear($tmpdir); @unlink($md5tmp); cloudaddons_faillog($_GET['rid'], 100); cpmsg('cloudaddons_download_error', '', 'error', array('ErrorCode' => 100)); } foreach ($array['files'] as $file => $data) { $filename = $tmpdir . '/' . $file . '._addons_'; $dirname = dirname($filename); dmkdir($dirname, 0777, false); $fp = fopen($filename, !$data['Part'] ? 'w' : 'a'); if (!$fp) { dir_clear($tmpdir); @unlink($md5tmp); cloudaddons_faillog($_GET['rid'], 101); cpmsg('cloudaddons_download_write_error', '', 'error'); } fwrite($fp, gzuncompress(base64_decode($data['Data']))); fclose($fp); if ($data['MD5']) { $md5total .= $data['MD5']; $md5s[$filename] = $data['MD5']; } } $fp = fopen($md5tmp, 'w');
if (submitcheck("postsubmit")) { $chapterorder = intval($_G['gp_chapterorder']); $volumeid = intval($_G['gp_volumeid']); $chaptername = addslashes(cutstr($_G['gp_chaptername'], 50)); $content = $_G['gp_chaptercontent']; $lastchaptercontent = addslashes(cutstr(strip_tags($content), 600)); $content = str_replace(array(" ", "<", ">", "\r\n"), array(" ", "<", ">", "<br/>"), $content); $chapterwords = ceil(strlen($content) / 2); $content = stripslashes($content); preg_match_all('/\\[upimg\\](.+?)\\[\\/upimg\\]/i', $content, $matchvar); foreach ($matchvar[1] as $v) { DB::insert("pdnovel_image", array("novelid" => $volume[novelid], "chapterid" => $chapterid)); $imgid = DB::insert_id(); $subimgid = floor($imgid / 1000); $subsubimgid = floor($subimgid / 1000); dmkdir($imgpath . $subsubimgid . '/' . $subimgid); @rename($v, $imgpath . $subsubimgid . '/' . $subimgid . '/' . $imgid . '.jpg'); $content = str_replace($v, 'data/attachment/pdnovel/img/' . $subsubimgid . '/' . $subimgid . '/' . $imgid . '.jpg', $content); } $content = str_replace(array('[upimg]', '[/upimg]'), array('[img]', '[/img]'), $content); DB::update('pdnovel_text_' . $tableid, array('text' => $content), "id={$chapterid}"); DB::query("UPDATE " . DB::table("pdnovel_chapter") . (" SET chaptername='" . $chaptername . ("', chapterwords=" . $chapterwords . ", chapterorder=" . $chapterorder . ", volumeid=" . $volumeid . " WHERE chapterid={$chapterid}"))); DB::query("UPDATE " . DB::table("pdnovel_volume") . (" SET volumewords=volumewords+" . $chapterwords . ("-" . $chapter['chapterwords'] . " WHERE volumeid={$volumeid}"))); if ($chapter['chapterid'] == $novel['lastchapterid']) { DB::query("UPDATE " . DB::table("pdnovel_view") . (" SET words=words+" . $chapterwords . ("-" . $chapter['chapterwords'] . ", lastchapter='{$chaptername}', lastchaptercontent='{$lastchaptercontent}' WHERE novelid={$novelid}"))); } else { DB::query("UPDATE " . DB::table("pdnovel_view") . (" SET words=words+" . $chapterwords . ("-" . $chapter['chapterwords'] . " WHERE novelid={$novelid}"))); } showmessage("do_success", "pdnovel.php?mod=home&do=manage&novelid=" . $novelid . ("#chapterid" . $chapterid)); } else { $content = DB::result_first('SELECT text FROM ' . DB::table('pdnovel_text_' . $tableid . " WHERE id={$chapterid}"));
function dmkdir($dir, $mode = 0777) { if (!is_dir($dir)) { dmkdir(dirname($dir)); @mkdir($dir, $mode); @touch($dir . '/index.htm'); @chmod($dir . '/index.htm', 0777); } return true; }
function cloudaddons_copytree($from, $to) { global $_G; $dh = opendir($from); while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { $readfile = $from . '/' . $file; $writefile = $to . '/' . $file; if (is_file($readfile)) { if (!in_array($readfile, $_G['treeop']['copy'])) { continue; } if (!isset($_G['siteftp'])) { $content = -1; if ($fp = @fopen($readfile, 'r')) { $startTime = microtime(); do { $canRead = flock($fp, LOCK_SH); if (!$canRead) { usleep(round(rand(0, 100) * 1000)); } } while (!$canRead && microtime() - $startTime < 1000); if (!$canRead) { cpmsg('cloudaddons_file_read_error', '', 'error'); } $content = fread($fp, filesize($readfile)); flock($fp, LOCK_UN); fclose($fp); } if ($content < 0) { cpmsg('cloudaddons_file_read_error', '', 'error'); } dmkdir(dirname($writefile), 0777, false); $writefile = preg_replace('/\\._addons_$/', '', $writefile); if ($fp = fopen($writefile, 'w')) { $startTime = microtime(); do { $canWrite = flock($fp, LOCK_EX); if (!$canWrite) { usleep(round(rand(0, 100) * 1000)); } } while (!$canWrite && microtime() - $startTime < 1000); if (!$canWrite) { cpmsg('cloudaddons_file_write_error', '', 'error'); } fwrite($fp, $content); flock($fp, LOCK_UN); fclose($fp); } if (!$canWrite) { cpmsg('cloudaddons_file_write_error', '', 'error'); } } else { $writefile = preg_replace('/\\._addons_$/', '', $writefile); siteftp_upload($readfile, preg_replace('/^' . preg_quote(DISCUZ_ROOT) . '/', '', $writefile)); } if (md5_file($readfile) != md5_file($writefile)) { cpmsg('cloudaddons_file_write_error', '', 'error'); } } else { cloudaddons_copytree($readfile, $writefile); } } } }
public function getPath($filename, $dir = 'dzz') { global $_G; $pathinfo = pathinfo($filename); $ext = $pathinfo['extension'] ? $pathinfo['extension'] : ''; if ($ext && in_array(strtolower($ext), getglobal('setting/unRunExts'))) { $ext = 'dzz'; } $subdir = $subdir1 = $subdir2 = ''; $subdir1 = date('Ym'); $subdir2 = date('d'); $subdir = $subdir1 . '/' . $subdir2 . '/'; $target1 = $dir . '/' . $subdir . 'index.html'; $target = $dir . '/' . $subdir; $target_attach = $_G['setting']['attachdir'] . $target1; $targetpath = dirname($target_attach); dmkdir($targetpath); return $target . date('His') . '' . strtolower(random(16)) . '.' . $ext; }
public static function writeErrorLog($message) { global $_G; //$message = self::clear($message); $time = dgmdate(TIMESTAMP, 'dt'); $file = ROOT_PATH . 'web/log/' . date('Y.m.d') . '_errorlog.php'; $dir = dirname($file); if (!is_dir($dir) && !TAE) { dmkdir($dir); } if (!is_file($file) && !TAE) { file_put_contents($file, ''); } $message = str_replace('<li>', "\r\n<li>", $message); $ip = $_G[clientip]; $user = '******' . htmlspecialchars($_G[username]) . '; RIP:' . $_SERVER['REMOTE_ADDR']; $message = "<?php exit;?>\r\n{$time}\r\n{$message}{$user}\r\n"; // 判断该$message是否在时间间隔$maxtime内已记录过,有,则不用再记录了 $fp = @fopen($file, 'rb'); $lastlen = 50000; // 读取最后的 $lastlen 长度字节内容 $maxtime = 60 * 10; // 时间间隔:10分钟 $offset = filesize($file) - $lastlen; if ($offset > 0) { fseek($fp, $offset); } if ($data = fread($fp, $lastlen)) { $array = explode("\n", $data); if (is_array($array)) { foreach ($array as $key => $val) { $row = explode("\t", $val); if ($row[0] != '<?php exit;?>') { continue; } if ($row[3] == $hash && $row[1] > $time - $maxtime) { return; } } } } error_log($message, 3, $file); }
function init($method, $source, $target, $nosuffix = 0) { global $_G; $this->errorcode = 0; if (empty($source)) { return -2; } $parse = parse_url($source); if (isset($parse['host'])) { if (empty($target)) { return -2; } $data = dfsockopen($source); $this->tmpfile = $source = tempnam($_G['setting']['attachdir'] . './temp/', 'tmpimg_'); file_put_contents($source, $data); if (!$data || $source === FALSE) { return -2; } } if ($method == 'thumb') { $target = empty($target) ? !$nosuffix ? getimgthumbname($source) : $source : $_G['setting']['attachdir'] . './' . $target; } elseif ($method == 'watermask') { $target = empty($target) ? $source : $_G['setting']['attachdir'] . './' . $target; } $targetpath = dirname($target); dmkdir($targetpath); clearstatcache(); if (!is_readable($source) || !is_writable($targetpath)) { return -2; } $imginfo = @getimagesize($source); if ($imginfo === FALSE) { return -1; } $this->source = $source; $this->target = $target; $this->imginfo['width'] = $imginfo[0]; $this->imginfo['height'] = $imginfo[1]; $this->imginfo['mime'] = $imginfo['mime']; $this->imginfo['size'] = @filesize($source); $this->libmethod = $this->param['imagelib'] && $this->param['imageimpath']; if (!$this->libmethod) { switch ($this->imginfo['mime']) { case 'image/jpeg': $this->imagecreatefromfunc = function_exists('imagecreatefromjpeg') ? 'imagecreatefromjpeg' : ''; $this->imagefunc = function_exists('imagejpeg') ? 'imagejpeg' : ''; break; case 'image/gif': $this->imagecreatefromfunc = function_exists('imagecreatefromgif') ? 'imagecreatefromgif' : ''; $this->imagefunc = function_exists('imagegif') ? 'imagegif' : ''; break; case 'image/png': $this->imagecreatefromfunc = function_exists('imagecreatefrompng') ? 'imagecreatefrompng' : ''; $this->imagefunc = function_exists('imagepng') ? 'imagepng' : ''; break; } } else { $this->imagecreatefromfunc = $this->imagefunc = TRUE; } if (!$this->libmethod && $this->imginfo['mime'] == 'image/gif') { if (!$this->imagecreatefromfunc) { return -4; } if (!($fp = @fopen($source, 'rb'))) { return -2; } $content = fread($fp, $this->imginfo['size']); fclose($fp); $this->imginfo['animated'] = strpos($content, 'NETSCAPE2.0') === FALSE ? 0 : 1; } return $this->imagecreatefromfunc ? 1 : -4; }
public function getThumb($path, $width, $height, $original) { global $_G; $enable_cache = true; //是否启用缓存 $quality = 80; $imgcachePath = './imgcache/'; $cachepath = str_replace('//', '/', str_replace(':', '/', $path)); if ($original) { $width = 50000; $height = 50000; } $target = $imgcachePath . $cachepath . '.' . $width . '_' . $height . '.jpeg'; if ($enable_cache && @getimagesize($_G['setting']['attachdir'] . $target)) { header('Content-Type: image/JPEG'); @ob_end_clean(); if (getglobal('gzipcompress')) { @ob_start('ob_gzhandler'); } @readfile($_G['setting']['attachdir'] . $target); @flush(); @ob_flush(); exit; } //获取缩略图 $bzarr = self::parsePath($path); $pcs = self::init($path, 1); if (is_array($pcs) && $pcs['error']) { return $pcs; } $result = $pcs->thumbnail($bzarr['path'], $width, $height, $quality); $targetpath = dirname($_G['setting']['attachurl'] . $target); dmkdir($targetpath); if ($enable_cache) { file_put_contents($_G['setting']['attachdir'] . $target, $result); } header('Content-Type: image/JPEG'); @ob_end_clean(); if (getglobal('gzipcompress')) { @ob_start('ob_gzhandler'); } echo $result; @flush(); @ob_flush(); }
function dmkdir($dir, $mode = 0777, $makeindex = TRUE) { if (!is_dir($dir)) { dmkdir(dirname($dir), $mode, $makeindex); @mkdir($dir, $mode); if (!empty($makeindex)) { @touch($dir . '/index.html'); @chmod($dir . '/index.html', 0777); } } return true; }
function get_rss_obj() { require_once PICK_DIR . '/lib/lastRSS.class.php'; $set = get_pick_set(); $cache_time = 0; $rss = new lastRSS(); $rss->cache_dir = PICK_CACHE . '/rss/'; //设置缓存目录 if (!is_dir($rss->cache_dir)) { dmkdir($rss->cache_dir); } $rss->cache_time = $set['cache_time'] * 60; $rss->default_cp = 'GB2312'; //目标字符编码,默认为UTF-8 $rss->cp = CHARSET; //自己的编码 $rss->items_limit = 0; //设置输出数量,默认为10 $rss->date_format = 'U'; //设置时间格式。默认为字符串;U为时间戳,可以用date设置格式 $rss->stripHTML = FALSE; //设置过滤html脚本。默认为false,即不过滤<br> $rss->CDATA = 'content'; //设置处理CDATA信息。默认为nochange。另有strip和content两个选项 return $rss; //输出 }
function getcacheinfo($tid) { global $_G; $tid = intval($tid); $cachethreaddir2 = DISCUZ_ROOT . './' . $_G['setting']['cachethreaddir']; $cache = array('filemtime' => 0, 'filename' => ''); $tidmd5 = substr(md5($tid), 3); $fulldir = $cachethreaddir2 . '/' . $tidmd5[0] . '/' . $tidmd5[1] . '/' . $tidmd5[2] . '/'; $cache['filename'] = $fulldir . $tid . '.htm'; if (file_exists($cache['filename'])) { $cache['filemtime'] = filemtime($cache['filename']); } else { if (!is_dir($fulldir)) { dmkdir($fulldir); } } return $cache; }
function makecategoryfile($dir, $catid, $domain) { dmkdir(DISCUZ_ROOT . './' . $dir, 0777, FALSE); $portalcategory = getglobal('cache/portalcategory'); $prepath = str_repeat('../', $portalcategory[$catid]['level'] + 1); if ($portalcategory[$catid]['level']) { $upid = $portalcategory[$catid]['upid']; while ($portalcategory[$upid]['upid']) { $upid = $portalcategory[$upid]['upid']; } $domain = $portalcategory[$upid]['domain']; } $sub_dir = $dir; if ($sub_dir) { $sub_dir = substr($sub_dir, -1, 1) == '/' ? '/' . $sub_dir : '/' . $sub_dir . '/'; } $code = "<?php\nchdir('{$prepath}');\ndefine('SUB_DIR', '{$sub_dir}');\n\$_GET['mod'] = 'list';\n\$_GET['catid'] = '{$catid}';\nrequire_once './portal.php';\n?>"; $r = file_put_contents($dir . '/index.php', $code); return $r; }
} $settingnew['makehtml']['articlehtmldir'] = trim($settingnew['makehtml']['articlehtmldir'], ' /\\'); $re = NULL; preg_match_all('/[^\\w\\d\\_\\]/', $settingnew['makehtml']['articlehtmldir'], $re); if (!empty($re[0]) || !check_html_dir($settingnew['makehtml']['articlehtmldir'])) { cpmsg(cplang('setting_functions_makehtml_articlehtmldir_invalid') . ',' . cplang('return'), NULL, 'error'); } $settingnew['makehtml']['topichtmldir'] = trim($settingnew['makehtml']['topichtmldir'], ' /\\'); $re = NULL; preg_match_all('/[^\\w\\d\\_\\]/', $settingnew['makehtml']['topichtmldir'], $re); if (!empty($re[0]) || !check_html_dir($settingnew['makehtml']['topichtmldir'])) { cpmsg(cplang('setting_functions_makehtml_topichtmldir_invalid') . ',' . cplang('return'), NULL, 'error'); } $topichtmldir = realpath($settingnew['makehtml']['topichtmldir']); if ($topichtmldir === false) { dmkdir($settingnew['makehtml']['topichtmldir'], 777, false); $topichtmldir = realpath($settingnew['makehtml']['topichtmldir']); rmdir($settingnew['makehtml']['topichtmldir']); if ($topichtmldir === false) { cpmsg(cplang('setting_functions_makehtml_topichtmldir_invalid') . ',' . cplang('return'), NULL, 'error'); } } $topichtmldir = str_replace(DISCUZ_ROOT, '', $topichtmldir); $sysdir = array('api', 'archiver', 'config', 'data/diy', 'data\\diy', 'install', 'source', 'static', 'template', 'uc_client', 'uc_server'); foreach ($sysdir as $_dir) { if (stripos($topichtmldir, $_dir) === 0) { cpmsg(cplang('setting_functions_makehtml_topichtmldir_invalid') . ',' . cplang('return'), NULL, 'error'); } } $settingnew['makehtml']['htmldirformat'] = intval($settingnew['makehtml']['htmldirformat']); C::t('common_setting')->update('makehtml', $settingnew['makehtml']);