/** * 上传帖子图片(正常的附件目录) * * @param mixed $uid Description. * @param mixed $allowValue Description. * * @access private * * @return mixed Value. */ private function _uploadAttach($uid, $allowValue) { global $_G; $fileExtension = FileUtils::getFileExtension($_FILES['uploadFile']['name'][$allowValue], 'jpg'); $type = 'forum'; $extid = 0; $forcename = ''; Yii::import('application.components.discuz.source.class.discuz.discuz_upload', true); $upload = new Mobcent_upload(); $attach['extension'] = $fileExtension; $attach['attachdir'] = $upload->get_target_dir($type, $extid); $filename = $upload->get_target_filename($type, $extid, $forcename) . '.' . $attach['extension']; $attach['attachment'] = $attach['attachdir'] . $filename; $attach['target'] = getglobal('setting/attachdir') . './' . $type . '/' . $attach['attachment']; $savePath = getglobal('setting/attachdir') . './' . $type . '/' . $attach['attachdir']; if (!is_dir($savePath)) { mkdir($savePath, 0777, true); } $remote = $width = $thumb = 0; $res = array(); $saveName = $savePath . $filename; if (move_uploaded_file($_FILES['uploadFile']['tmp_name'][$allowValue], $saveName)) { $aid = getattachnewaid($uid); $img_info = getimagesize($attach['target']); $size = filesize($attach['target']); $insert = array('aid' => $aid, 'dateline' => $_G['timestamp'], 'filename' => $filename, 'filesize' => $size, 'attachment' => $attach['attachment'], 'isimage' => 1, 'uid' => $uid, 'thumb' => $thumb, 'remote' => $remote, 'width' => $img_info[0]); C::t('forum_attachment_unused')->insert($insert); // 添加水印 Yii::import('application.components.discuz.source.class.class_image', true); $image = new Mobcent_Image(); if ($image->param['watermarkstatus']['forum'] > 0) { $image->makeWatermark($attach['target'], '', 'forum'); } $path_url = ImageUtils::getAttachUrl() . '/' . $type . '/' . $attach['attachment']; ImageUtils::getThumbImageEx($path_url, 10, false, false, true); $res['id'] = $aid; $res['urlName'] = $path_url; } return $res; }
function mobcent_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']; $picsource = ImageUtils::getAttachUrl($attach['remote']) . '/' . '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; } }