function getremotefile($file) { global $_G; @set_time_limit(0); if (!@readfile($_G['setting']['ftp']['attachurl'] . 'portal/' . $file)) { $ftp = new discuz_ftp(); if (!($_G['setting']['ftp']['connid'] = $ftp->connect())) { return FALSE; } $tmpfile = @tempnam($_G['setting']['attachdir'], ''); if ($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) { @readfile($tmpfile); @unlink($tmpfile); } else { @unlink($tmpfile); return FALSE; } } return TRUE; }
function ftp_chmod($filename, $mod = 0777) { $filename = discuz_ftp::clear($filename); if (function_exists('ftp_chmod')) { return @ftp_chmod($this->connectid, $mod, $filename); } else { return @ftp_site($this->connectid, 'CHMOD ' . $mod . ' ' . $filename); } }
function ftp_delete($path) { #print_r("-----------------------<br>"); #die("die"); $path = discuz_ftp::clear($path); return $this->bos_util->deleteObject($path); }
function siteftp_check($siteftp, $dir) { global $_G; $siteftp['on'] = 1; $siteftp['password'] = authcode($siteftp['password'], 'ENCODE', md5($_G['config']['security']['authkey'])); $ftp =& discuz_ftp::instance($siteftp); $ftp->connect(); $ftp->upload(DISCUZ_ROOT . './source/discuz_version.php', $dir . '/discuz_version.php'); if ($ftp->error()) { cpmsg('setting_ftp_remote_' . $ftp->error(), '', 'error'); } if (!file_exists(DISCUZ_ROOT . './' . $dir . '/discuz_version.php')) { cpmsg('cloudaddons_ftp_path_error', '', 'error'); } $ftp->ftp_delete($typedir . '/discuz_version.php'); $_G['siteftp'] = $ftp; }
function ftpcmd($cmd, $arg1 = '') { static $ftp; $ftpon = getglobal('setting/ftp/on'); if (!$ftpon) { return $cmd == 'error' ? -101 : 0; } elseif ($ftp == null) { $ftp =& discuz_ftp::instance(); } if (!$ftp->enabled) { return $ftp->error(); } elseif ($ftp->enabled && !$ftp->connectid) { $ftp->connect(); } switch ($cmd) { case 'upload': return $ftp->upload(getglobal('setting/attachdir') . '/' . $arg1, $arg1); break; case 'delete': return $ftp->ftp_delete($arg1); break; case 'close': return $ftp->ftp_close(); break; case 'error': return $ftp->error(); break; case 'object': return $ftp; break; default: return false; } }
function block_updateitem($bid, $items = array()) { global $_G; $block = $_G['block'][$bid]; if (!$block) { if (!($block = C::t('common_block')->fetch($bid))) { return false; } $_G['block'][$bid] = $block; } $block['shownum'] = max($block['shownum'], 1); $showlist = array(); $archivelist = array(); $prelist = array(); $oldvalue = $fixedvalue = $fixedkeys = array(); foreach (C::t('common_block_item')->fetch_all_by_bid($bid, true) as $value) { $key = $value['idtype'] . '_' . $value['id']; if ($value['itemtype'] == '1') { $fixedvalue[$value['displayorder']][] = $value; $fixedkeys[$key] = 1; continue; } elseif (!isset($oldvalue[$key])) { $oldvalue[$key] = $value; } else { $archivelist[$value['itemid']] = 1; } } $processkeys = array(); $itemcount = count($items); for ($k = 0; $k < $itemcount; $k++) { $v = $items[$k]; $key = $v['idtype'] . '_' . $v['id']; if (isset($fixedkeys[$key])) { $items[$k] = null; } elseif (isset($oldvalue[$key]) && !isset($processkeys[$key])) { if ($oldvalue[$key]['itemtype'] == '2') { $items[$k] = $oldvalue[$key]; } else { $items[$k]['itemid'] = $oldvalue[$key]['itemid']; } unset($oldvalue[$key]); $processkeys[$key] = 1; } elseif (isset($processkeys[$key])) { unset($items[$k]); } } $items = array_filter($items); foreach ($oldvalue as $value) { $archivelist[$value['itemid']] = 1; } for ($i = 1; $i <= $block['shownum']; $i++) { $jump = false; if (isset($fixedvalue[$i])) { foreach ($fixedvalue[$i] as $value) { if ($value['startdate'] > TIMESTAMP) { $prelist[] = $value; } elseif ((!$value['startdate'] || $value['startdate'] <= TIMESTAMP) && (!$value['enddate'] || $value['enddate'] > TIMESTAMP)) { $showlist[] = $value; $jump = true; } else { $archivelist[$value['itemid']] = 1; } } } if (!$jump) { $curitem = array(); if (!($curitem = array_shift($items))) { break; } $curitem['displayorder'] = $i; $curitem['makethumb'] = 0; if ($block['picwidth'] && $block['picheight'] && $curitem['picflag']) { //picflag=0为url地址 $thumbpath = empty($curitem['thumbpath']) ? block_thumbpath($block, $curitem) : $curitem['thumbpath']; if ($_G['setting']['ftp']['on']) { if (empty($ftp) || empty($ftp->connectid)) { $ftp =& discuz_ftp::instance(); $ftp->connect(); } if ($ftp->ftp_size($thumbpath) > 0) { $curitem['makethumb'] = 1; $curitem['picflag'] = 2; } } else { if (file_exists($_G['setting']['attachdir'] . $thumbpath)) { $curitem['makethumb'] = 1; $curitem['picflag'] = 1; } } $curitem['thumbpath'] = $thumbpath; } if (is_array($curitem['fields'])) { $curitem['fields'] = serialize($curitem['fields']); } $showlist[] = $curitem; } } foreach ($items as $value) { if (!empty($value['itemid'])) { $archivelist[$value['itemid']] = 1; } } if ($archivelist) { $delids = array_keys($archivelist); C::t('common_block_item')->delete_by_itemid_bid($delids, $bid); block_delete_pic($bid, $delids); } $inserts = $itemlist = array(); $itemlist = array_merge($showlist, $prelist); C::t('common_block_item')->insert_batch($bid, $itemlist); $showlist = array_filter($showlist); return $showlist; }
public function copy_file($srcfile, $desfile, $type) { global $_G; if (!is_file($srcfile)) { return false; } if ($type == 'file') { $this->mkdirs(dirname($desfile)); copy($srcfile, $desfile); } elseif ($type == 'ftp') { $siteftp = $_GET['siteftp']; $siteftp['on'] = 1; $siteftp['password'] = authcode($siteftp['password'], 'ENCODE', md5($_G['config']['security']['authkey'])); $ftp =& discuz_ftp::instance($siteftp); $ftp->connect(); $ftp->upload($srcfile, $desfile); if ($ftp->error()) { return false; } } return true; }
C::t('common_block_item_data')->insert($item, false, true); if ($_GET['showrecommendtip'] && in_array($_GET['idtype'], array('tids', 'tid', 'gtid'))) { $modarr = array('tid' => $item['id'], 'uid' => $item['uid'], 'username' => $item['username'], 'dateline' => TIMESTAMP, 'action' => 'REB', 'status' => '1', 'stamp' => '', 'reason' => getstr($_GET['recommendto'], 20)); C::t('forum_threadmod')->insert($modarr); $data = array('moderated' => 1); loadcache('stamptypeid'); if (array_key_exists(4, $_G['cache']['stamptypeid'])) { $data['stamp'] = $_G['cache']['stamptypeid']['4']; } C::t('forum_thread')->update($item['id'], $data); } if ($_POST['icflag'] && !C::t('common_block_pic')->count_by_bid_pic($block['bid'], $thumbpath)) { $picflag = 0; //common_block_pic表中的picflag标识(0本地,1远程) if ($_G['setting']['ftp']['on']) { $ftp =& discuz_ftp::instance(); $ftp->connect(); if ($ftp->connectid && $ftp->ftp_size($thumbpath) > 0 || $ftp->upload($_G['setting']['attachurl'] . '/' . $thumbpath, $thumbpath)) { $picflag = 1; //common_block_pic表中的picflag标识(0本地,1远程) @unlink($_G['setting']['attachdir'] . './' . $thumbpath); } } $thumbdata = array('bid' => $block['bid'], 'itemid' => 0, 'pic' => $thumbpath, 'picflag' => $picflag, 'type' => '0'); C::t('common_block_pic')->insert($thumbdata); } if (!empty($_POST['updateblock'])) { block_updatecache($bid, true); } if ($_G['group']['reasonpm'] == 2 || $_G['group']['reasonpm'] == 3 || !empty($_GET['sendreasonpm'])) { $sendreasonpm = 1;
function block_updateitem($bid, $items = array()) { global $_G; $block = $_G['block'][$bid]; if (!$block) { $block = DB::fetch_first('SELECT * FROM ' . DB::table('common_block') . " WHERE bid='{$bid}'"); if (!$block) { return false; } $_G['block'][$bid] = $block; } $block['shownum'] = max($block['shownum'], 1); $showlist = array(); $archivelist = array(); $prelist = array(); $query = DB::query('SELECT * FROM ' . DB::table('common_block_item') . " WHERE bid='{$bid}' ORDER BY displayorder, itemtype DESC"); $oldvalue = $fixedvalue = $fixedkeys = array(); while ($value = DB::fetch($query)) { $key = $value['idtype'] . '_' . $value['id']; if ($value['itemtype'] == '1') { $fixedvalue[$value['displayorder']][] = $value; $fixedkeys[$key] = 1; continue; } else { $oldvalue[$key] = $value; } } $itemcount = count($items); for ($k = 0; $k < $itemcount; $k++) { $v = $items[$k]; $key = $v['idtype'] . '_' . $v['id']; if (isset($fixedkeys[$key])) { $items[$k] = null; } elseif (isset($oldvalue[$key])) { if ($oldvalue[$key]['itemtype'] == '2') { $items[$k] = $oldvalue[$key]; } else { $items[$k]['itemid'] = $oldvalue[$key]['itemid']; } unset($oldvalue[$key]); } } $items = array_filter($items); foreach ($oldvalue as $value) { $archivelist[$value['itemid']] = 1; } for ($i = 1; $i <= $block['shownum']; $i++) { $jump = false; if (isset($fixedvalue[$i])) { foreach ($fixedvalue[$i] as $value) { if ($value['startdate'] > TIMESTAMP) { $prelist[] = $value; } elseif ((!$value['startdate'] || $value['startdate'] <= TIMESTAMP) && (!$value['enddate'] || $value['enddate'] > TIMESTAMP)) { $showlist[] = $value; $jump = true; } else { $archivelist[$value['itemid']] = 1; } } } if (!$jump) { $curitem = array(); if (!($curitem = array_shift($items))) { break; } $curitem['displayorder'] = $i; $curitem['makethumb'] = 0; /*vot*/ if ($block['picwidth'] && $block['picheight'] && $curitem['picflag']) { //picflag=0 for the local Url address $thumbpath = empty($curitem['thumbpath']) ? block_thumbpath($block, $curitem) : $curitem['thumbpath']; if ($_G['setting']['ftp']['on']) { if (empty($ftp) || empty($ftp->connectid)) { require_once libfile('class/ftp'); $ftp =& discuz_ftp::instance(); $ftp->connect(); } if ($ftp->ftp_size($thumbpath) > 0) { $curitem['makethumb'] = 1; $curitem['picflag'] = 2; } } else { if (file_exists($_G['setting']['attachdir'] . $thumbpath)) { $curitem['makethumb'] = 1; $curitem['picflag'] = 1; } } $curitem['thumbpath'] = $thumbpath; } if (is_array($curitem['fields'])) { $curitem['fields'] = serialize($curitem['fields']); } $showlist[] = $curitem; } } foreach ($items as $value) { if (!empty($value['itemid'])) { $archivelist[$value['itemid']] = 1; } } if ($archivelist) { $delids = array_keys($archivelist); DB::query('DELETE FROM ' . DB::table('common_block_item') . " WHERE bid='{$bid}' AND itemid IN (" . dimplode($delids) . ")"); block_delete_pic($bid, $delids); } $inserts = $itemlist = array(); $itemlist = array_merge($showlist, $prelist); foreach ($itemlist as $value) { if ($value) { $value = daddslashes($value); $inserts[] = "('{$value['itemid']}', '{$bid}', '{$value['itemtype']}', '{$value['id']}', '{$value['idtype']}', '{$value['title']}',\r\n\t\t\t\t '{$value['url']}', '{$value['pic']}', '{$value['picflag']}', '{$value['makethumb']}', '{$value['thumbpath']}', '{$value['summary']}',\r\n\t\t\t\t '{$value['showstyle']}', '{$value['related']}', '{$value['fields']}', '{$value['displayorder']}', '{$value['startdate']}', '{$value['enddate']}')"; } } if ($inserts) { DB::query('REPLACE INTO ' . DB::table('common_block_item') . "(itemid, bid, itemtype, id, idtype, title, url, pic, picflag, makethumb, thumbpath, summary, showstyle, related, `fields`, displayorder, startdate, enddate) VALUES " . implode(',', $inserts)); } $showlist = array_filter($showlist); return $showlist; }
function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) { $upyun = new UpYun($this->upyun_config['bucket_name'], $this->upyun_config['operator_name'], $this->upyun_config['operator_pwd']); $remote_file = discuz_ftp::clear($remote_file); $local_file = discuz_ftp::clear($local_file); try { if ($fh = fopen($local_file, 'wb')) { $rsp = $upyun->readFile($this->upyun_dir . ltrim($remote_file, '/'), $fh); fclose($fh); return $rsp; } else { return 0; } } catch (Exception $e) { return 0; } }
public static function ftpUpload($files) { $ftpconfig = array('host' => zmf::config('ftp_host'), 'username' => zmf::config('ftp_username'), 'password' => zmf::config('ftp_password'), 'on' => 1, 'attachdir' => zmf::config('ftp_attachdir')); $ftp =& discuz_ftp::instance($ftpconfig); $ftp->connect(); $succ = array(); foreach ($files as $file) { $toimgpath = $ftpconfig['attachdir'] . $file['to']; $ftp->upload($file['from'], $toimgpath); if ($ftp->error()) { $errinfo = tools::ftpError($ftp->error()); //ftpError //MsgController::jsonOutPut(0, $errinfo); } else { $succ[] = $file; } } return $succ; }
function ftp_delete($path) { // $path = discuz_ftp::clear($path); switch ($this->curstorage) { case 'upyun': $path = substr($path, 0, 1) == "/" ? $path : '/' . $path; return $this->curobj->delete($path); case 'aliyun': $path = substr($path, 0, 1) == "/" ? substr($path, 1) : $path; $return = $this->curobj->delete_object($this->config_ext['bucket'], $path); return substr((string) $return->status, 0, 1) == 2 ? 1 : 0; case 'qiniu': $this->curobj = new Qiniu_MacHttpClient(null); $path = substr($path, 0, 1) == '/' ? substr($path, 1) : (substr($path, 0, 2) == './' ? substr($path, 2) : $path); $err = Qiniu_RS_Delete($this->curobj, $this->config_ext['bucket'], $path); return $err === null ? 1 : 0; case 'grand': return 0; } return @ftp_delete($this->connectid, $path); }