Example #1
0
function page_admin_images($act = "", $id = "")
{
    requires_admin();
    use_template("admin");
    if ($act == "add") {
        if (form_file_uploaded("file")) {
            $fname = $_FILES["file"]['name'];
            db_query("INSERT INTO images (link) VALUES ('')");
            $id = db_last_id();
            $fname = $id . "." . fileext($fname);
            form_file_uploaded_move("file", "img/" . $fname);
            db_query("UPDATE images SET link='img/{$fname}' WHERE id=%d", $id);
            redir("admin/images");
        }
        form_start("", "post", " enctype='multipart/form-data' ");
        form_file("Файл", "file");
        form_submit("Загрузить", "submit");
        form_end();
        $o = form();
        return $o;
    }
    if ($act == "del") {
        $im = db_object_get("images", $id);
        @unlink("../{$im->link}");
    }
    $o = table_edit("images", "admin/images", $act, $id, "", "", "", "image_func");
    return $o;
}
function build_cache_postimg()
{
    $imgextarray = array('jpg', 'gif', 'png');
    $imgdir = array('hrline', 'postbg');
    $postimgjs = 'var postimg_type = new Array();';
    foreach ($imgdir as $perdir) {
        $count = 0;
        $pdir = DISCUZ_ROOT . './static/image/' . $perdir;
        $postimgdir = dir($pdir);
        $postimgjs .= 'postimg_type["' . $perdir . '"]=[';
        while ($entry = $postimgdir->read()) {
            if (in_array(strtolower(fileext($entry)), $imgextarray) && preg_match("/^[\\w\\-\\.\\[\\]\\(\\)\\<\\> &]+\$/", substr($entry, 0, strrpos($entry, '.'))) && strlen($entry) < 30 && is_file($pdir . '/' . $entry)) {
                $postimg[$perdir][] = array('url' => $entry);
                $postimgjs .= ($count ? ',' : '') . '"' . $entry . '"';
                $count++;
            }
        }
        $postimgjs .= '];';
        $postimgdir->close();
    }
    savecache('postimg', $postimg);
    $cachedir = 'saekv://data/cache/';
    if (@($fp = fopen($cachedir . 'common_postimg.js', 'w'))) {
        fwrite($fp, $postimgjs);
        fclose($fp);
    } else {
        exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .');
    }
}
Example #3
0
 function poll_upload()
 {
     global $_G;
     $this->uid = intval($_G['gp_uid']);
     $swfhash = md5(substr(md5($_G['config']['security']['authkey']), 8) . $this->uid);
     if (!$_FILES['Filedata']['error'] && $_G['gp_hash'] == $swfhash && $this->uid) {
         $this->aid = 0;
         $this->simple = 0;
         $this->user = getuserbyuid($this->uid);
         if (empty($this->user['adminid'])) {
             $this->uploadmsg(9);
         }
         $_G['uid'] = $this->uid;
         $this->pollid = !empty($_G['gp_pollid']) ? intval($_G['gp_pollid']) : 0;
         if ($this->pollid <= 0 || !intval(DB::result_first("SELECT contenttype FROM " . DB::table('poll_item') . " WHERE itemid='{$this->pollid}'"))) {
             $this->uploadmsg(9);
         }
         $attach = upload_images($_FILES['Filedata'], 'poll', 176, 176);
         $caption = dhtmlspecialchars(trim($attach['name']));
         $caption = substr($caption, 0, -(strlen(fileext($caption)) + 1));
         $data = array('itemid' => $this->pollid, 'caption' => $caption, 'displayorder' => 0, 'imageurl' => $attach['attachment'], 'aid' => $attach['aid']);
         DB::insert('poll_choice', $data);
         $this->aid = $this->pollid;
         $this->uploadmsg(0);
     }
 }
Example #4
0
function parseattach($attachpids, $attachtags, &$postlist, $showimages = 1, $skipaids = array())
{
    global $db, $tablepre, $discuz_uid, $skipaidlist, $readaccess, $attachlist, $attachimgpost, $maxchargespan, $timestamp, $forum, $ftp, $attachurl, $dateformat, $timeformat, $timeoffset, $hideattach, $thread, $tradesaids, $trades, $exthtml, $tagstatus, $sid, $authkey, $exempt;
    $query = $db->query("SELECT a.*, af.description, ap.aid AS payed FROM {$tablepre}attachments a LEFT JOIN {$tablepre}attachmentfields af ON a.aid=af.aid LEFT JOIN {$tablepre}attachpaymentlog ap ON ap.aid=a.aid AND ap.uid='{$discuz_uid}' WHERE a.pid IN ({$attachpids})");
    $attachexists = FALSE;
    while ($attach = $db->fetch_array($query)) {
        $attachexists = TRUE;
        $exthtml = '';
        if ($skipaids && in_array($attach['aid'], $skipaids)) {
            continue;
        }
        $attached = 0;
        $extension = strtolower(fileext($attach['filename']));
        $attach['ext'] = $extension;
        $attach['attachicon'] = attachtype($extension . "\t" . $attach['filetype']);
        $attach['attachsize'] = sizecount($attach['filesize']);
        $attach['attachimg'] = $showimages && $attachimgpost && $attach['isimage'] && (!$attach['readperm'] || $readaccess >= $attach['readperm']) ? 1 : 0;
        if ($attach['price']) {
            if ($maxchargespan && $timestamp - $attach['dateline'] >= $maxchargespan * 3600) {
                $db->query("UPDATE {$tablepre}attachments SET price='0' WHERE aid='{$attach['aid']}'");
                $attach['price'] = 0;
            } else {
                if (!$discuz_uid || !$forum['ismoderator'] && $attach['uid'] != $discuz_uid && !$attach['payed']) {
                    $attach['unpayed'] = 1;
                }
            }
        }
        $exemptattachpay = $exempt & 8 ? 1 : 0;
        $attach['payed'] = $attach['payed'] || $forum['ismoderator'] || $attach['uid'] == $discuz_uid ? 1 : 0;
        $attach['url'] = $attach['remote'] ? $ftp['attachurl'] : $attachurl;
        $attach['dateline'] = dgmdate("{$dateformat} {$timeformat}", $attach['dateline'] + $timeoffset * 3600);
        $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
        if (is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
            $findattach[$attach['pid']][] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            $replaceattach[$attach['pid']][] = $hideattach[$attach['pid']] ? '[attach]***[/attach]' : attachtag($attach['pid'], $attach['aid'], $postlist);
            $attached = 1;
        }
        if (!$attached || $attach['unpayed']) {
            if ($attach['isimage']) {
                $postlist[$attach['pid']]['imagelist'] .= attachlist($attach);
            } else {
                if (!$skipaidlist || !in_array($attach['aid'], $skipaidlist)) {
                    $postlist[$attach['pid']]['attachlist'] .= attachlist($attach);
                }
            }
        }
    }
    if ($attachexists) {
        foreach ($attachtags as $pid => $aids) {
            if ($findattach[$pid]) {
                $postlist[$pid]['message'] = preg_replace($findattach[$pid], $replaceattach[$pid], $postlist[$pid]['message'], 1);
                $postlist[$pid]['message'] = preg_replace($findattach[$pid], '', $postlist[$pid]['message']);
            }
        }
    } else {
        $db->query("UPDATE {$tablepre}posts SET attachment='0' WHERE pid IN ({$attachpids})", 'UNBUFFERED');
    }
}
function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array())
{
    global $_G;
    $query = DB::query("SELECT a.*, af.description, l.relatedid AS payed\n\t\tFROM " . DB::table('forum_attachment') . " a\n\t\tLEFT JOIN " . DB::table('forum_attachmentfield') . " af ON a.aid=af.aid\n\t\tLEFT JOIN " . DB::table('common_credit_log') . " l ON l.relatedid=a.aid AND l.uid='{$_G['uid']}' AND l.operation='BAC'\n\t\tWHERE a.pid IN ({$attachpids})");
    $attachexists = FALSE;
    while ($attach = DB::fetch($query)) {
        $attachexists = TRUE;
        if ($skipaids && in_array($attach['aid'], $skipaids)) {
            continue;
        }
        $attached = 0;
        $extension = strtolower(fileext($attach['filename']));
        $attach['ext'] = $extension;
        $attach['attachicon'] = attachtype($extension . "\t" . $attach['filetype']);
        $attach['attachsize'] = sizecount($attach['filesize']);
        $attach['attachimg'] = $_G['setting']['attachimgpost'] && $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
        if ($attach['price']) {
            if ($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
                DB::query("UPDATE " . DB::table('forum_attachment') . " SET price='0' WHERE aid='{$attach['aid']}'");
                $attach['price'] = 0;
            } else {
                if (!$_G['uid'] || !$_G['forum']['ismoderator'] && $attach['uid'] != $_G['uid'] && !$attach['payed']) {
                    $attach['unpayed'] = 1;
                }
            }
        }
        $exemptattachpay = $_G['group']['exempt'] & 8 ? 1 : 0;
        $attach['payed'] = $attach['payed'] || $_G['forum']['ismoderator'] || $attach['uid'] == $_G['uid'] ? 1 : 0;
        $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] . '/' : $_G['setting']['attachurl']) . 'forum/';
        $attach['dateline'] = dgmdate($attach['dateline'], 'u');
        $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
        if (!empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
            $findattach[$attach['pid']][] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            $replaceattach[$attach['pid']][] = attachtag($attach['pid'], $attach['aid'], $postlist);
            $attached = 1;
        }
        if (!$attached) {
            if ($attach['isimage']) {
                $postlist[$attach['pid']]['imagelist'] .= attachlist($attach);
            } else {
                if (!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
                    $postlist[$attach['pid']]['attachlist'] .= attachlist($attach);
                }
            }
        }
    }
    if ($attachexists) {
        foreach ($attachtags as $pid => $aids) {
            if ($findattach[$pid]) {
                $postlist[$pid]['message'] = preg_replace($findattach[$pid], $replaceattach[$pid], $postlist[$pid]['message'], 1);
                $postlist[$pid]['message'] = preg_replace($findattach[$pid], '', $postlist[$pid]['message']);
            }
        }
    } else {
        updatepost(array('attachment' => '0'), "pid IN ({$attachpids})", true);
    }
}
function import_styles($ignoreversion = 1, $dir = '')
{
    global $db, $tablepre, $version, $importtxt, $stylearray;
    if (!isset($dir)) {
        $stylearrays = array(getimportdata('Discuz! Style'));
    } else {
        $dir = str_replace(array('/', '\\'), '', $dir);
        $templatedir = DISCUZ_ROOT . './templates/' . $dir;
        $searchdir = dir($templatedir);
        $stylearrays = array();
        while ($searchentry = $searchdir->read()) {
            if (substr($searchentry, 0, 13) == 'discuz_style_' && fileext($searchentry) == 'xml') {
                $importfile = $templatedir . '/' . $searchentry;
                $importtxt = implode('', file($importfile));
                $stylearrays[] = getimportdata('Discuz! Style');
            }
        }
    }
    foreach ($stylearrays as $stylearray) {
        if (empty($ignoreversion) && strip_tags($stylearray['version']) != strip_tags($version)) {
            cpmsg('styles_import_version_invalid', '', 'error');
        }
        $renamed = 0;
        if ($stylearray['templateid'] != 1) {
            $templatedir = DISCUZ_ROOT . './' . $stylearray['directory'];
            if (!is_dir($templatedir)) {
                if (!@mkdir($templatedir, 0777)) {
                    $basedir = dirname($stylearray['directory']);
                    cpmsg('styles_import_directory_invalid', '', 'error');
                }
            }
            if (!($templateid = $db->result_first("SELECT templateid FROM {$tablepre}templates WHERE name='{$stylearray['tplname']}'"))) {
                $db->query("INSERT INTO {$tablepre}templates (name, directory, copyright)\r\n\t\t\t\t\tVALUES ('{$stylearray['tplname']}', '{$stylearray['directory']}', '{$stylearray['copyright']}')");
                $templateid = $db->insert_id();
            }
        } else {
            $templateid = 1;
        }
        if ($db->result_first("SELECT COUNT(*) FROM {$tablepre}styles WHERE name='{$stylearray['name']}'")) {
            $stylearray['name'] .= '_' . random(4);
            $renamed = 1;
        }
        $db->query("INSERT INTO {$tablepre}styles (name, templateid)\r\n\t\t\tVALUES ('{$stylearray['name']}', '{$templateid}')");
        $styleidnew = $db->insert_id();
        foreach ($stylearray['style'] as $variable => $substitute) {
            $substitute = @htmlspecialchars($substitute);
            $db->query("INSERT INTO {$tablepre}stylevars (styleid, variable, substitute)\r\n\t\t\t\tVALUES ('{$styleidnew}', '{$variable}', '{$substitute}')");
        }
    }
    updatecache('styles');
    updatecache('settings');
    return $renamed;
}
Example #7
0
 /**
  * Copy and assign the images
  * @return array of struct_corecatalog_cat_images - or array() (with count==0 elements, or empty)
  */
 protected function _assignImage($data_name, $filePathForSave)
 {
     if (!empty($_FILES[$data_name])) {
         $orig_name = $_FILES[$data_name]['name'];
         if (!$_FILES[$data_name]['error'] and (int) $_FILES[$data_name]['size']) {
             $currentUser = $this->getController()->getCurrentUser();
             $image = new struct_corecatalog_cat_images();
             $image->img_filename = 't_' . $currentUser->u_id . md5(time() . $currentUser->u_id . $orig_name) . '.' . strtolower(fileext($orig_name));
             move_uploaded_file($_FILES[$data_name]['tmp_name'], $filePathForSave . $image->img_filename);
             return $image->img_filename;
         }
     }
 }
Example #8
0
 public function getReader($filename)
 {
     //获取reader对象
     $Reader = NULL;
     $ext = fileext($filename);
     //取得文件扩展名
     if ($ext == 'xls') {
         $Reader = new PHPExcel_Reader_Excel5();
     } elseif ($ext == 'xlsx') {
         $Reader = new PHPExcel_Reader_Excel2007();
     }
     //excel 2007
     return $Reader;
 }
Example #9
0
function addPostFix($fileName)
{
    if (file_exists($fileName)) {
        $LpostFix = fileext($fileName);
        $length = strrpos($fileName, '.');
        $name = substr($fileName, 0, $length);
        $fix = randChar();
        $name = $name . $fix;
        $fileName = $name . "." . $LpostFix;
        if (file_exists($fileName)) {
            addPostFix($fileName);
        }
    }
    return $fileName;
}
Example #10
0
function file_down($file)
{
    global $lang_setdbNotExist;
    !file_exists($file) && okinfox('database.php?action=import', $lang_setdbNotExist);
    $filename = $filename ? $filename : basename($file);
    $filetype = fileext($filename);
    $filesize = filesize($file);
    header('Cache-control: max-age=31536000');
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT');
    header('Content-Encoding: none');
    header('Content-Length: ' . $filesize);
    header('Content-Disposition: attachment; filename=' . $filename);
    header('Content-Type: ' . $filetype);
    readfile($file);
    exit;
}
Example #11
0
function page_admin_images($act = "", $id = "")
{
    requires_admin();
    use_layout("admin");
    form_start("", "post", " enctype='multipart/form-data' ");
    form_file("Файл", "file");
    $caption = "Загрузить картинку";
    if ($act == "edit") {
        $caption = "Изменить картинку";
    }
    form_submit($caption, "submit");
    form_end();
    $upload = form();
    if (form_file_uploaded("file")) {
        $fname = $_FILES["file"]['name'];
        $ext = strtolower(fileext($fname));
        if (!($ext == "swf" || $ext == "jpg" || $ext == "gif" || $ext == "png" || $ext == "bmp" || $ext == "jpeg" || $ext == "pdf")) {
            $o = "Данный тип файла не является картинкой";
            return $o;
        } else {
            if ($act == "add") {
                db_query("INSERT INTO images (link) VALUES ('')");
                $id = db_last_id();
            } else {
                @unlink(db_result(db_query("SELECT link FROM images WHERE id=%d", $id)));
            }
            $fname = $id . "." . fileext($fname);
            form_file_uploaded_move("file", "img/" . $fname);
            db_query("UPDATE images SET link='img/{$fname}' WHERE id=%d", $id);
            redir("admin/images/edit/{$id}");
        }
    }
    if ($act == "add") {
        $o = $upload;
        return $o;
    }
    if ($act == "del") {
        $im = db_object_get("images", $id);
        @unlink("{$im->link}");
    }
    $o = table_edit("images", "admin/images", $act, $id, "", "", "", "image_func");
    if ($act == 'edit') {
        $im = db_object_get("images", $id);
        $o .= "<img width=100px src={$im->link}><br>{$upload}";
    }
    return $o;
}
Example #12
0
/**
 * 缩略图片
 */
function thumb($img, $width = 200, $height = 200)
{
    if (empty($img) || strlen($img) < 4) {
        return SITE_PATH . 'data/upload/nopic.gif';
    }
    if (file_exists(XIAOCMS_PATH . $img)) {
        $ext = fileext($img);
        $thumb = $img . '.thumb.' . $width . 'x' . $height . '.' . $ext;
        if (!file_exists(XIAOCMS_PATH . $thumb)) {
            $image = xiaocms::load_class('image');
            $image->thumb(XIAOCMS_PATH . $img, XIAOCMS_PATH . $thumb, $width, $height);
            // 生成图像缩略图
        }
        return $thumb;
    }
    return $img;
}
Example #13
0
function checkfilename($filename)
{
    global $tpldir;
    $isedit = false;
    if (!empty($filename)) {
        $filename = str_replace(array('..', '/', '\\'), array('', '', ''), $filename);
        if (!empty($filename) && fileext($filename) == 'htm') {
            if (is_writeable($tpldir . $filename)) {
                $isedit = true;
            }
        }
    }
    if (!$isedit) {
        cpmessage('template_files_editing_failure_check_directory_competence');
    }
    return $filename;
}
Example #14
0
function dreaddir($dir, $extarr = array())
{
    $dirs = array();
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if (!empty($extarr) && is_array($extarr)) {
                if (in_array(strtolower(fileext($file)), $extarr)) {
                    $dirs[] = $file;
                }
            } else {
                if ($file != '.' && $file != '..') {
                    $dirs[] = $file;
                }
            }
        }
        closedir($dh);
    }
    return $dirs;
}
 public function download($field, $value, $watermark = '0', $ext = 'gif|jpg|jpeg|bmp|png', $absurl = '', $basehref = '')
 {
     $dir = date('Y-m-d/');
     $upload_url = '/Uploads/';
     $uploadpath = $upload_url . $dir;
     $uploaddir = './Uploads/' . $dir;
     $string = stripslashes($value);
     //判断是否需要下载
     if (!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\\.({$ext}))\\2/i", $string, $matches)) {
         return $value;
     }
     //取出下载的图片
     $remotefileurls = array();
     foreach ($matches[3] as $matche) {
         //如果是本地图片, 则跳过
         if (strpos($matche, '://') === false) {
             continue;
         }
         $remotefileurls[] = $matche;
     }
     unset($matches, $string);
     $remotefileurls = array_unique($remotefileurls);
     $oldpath = $newpath = array();
     //开始下载
     //import("Org.Net.Http");
     foreach ($remotefileurls as $k => $file) {
         //判断是否是本地图片
         if (strpos($file, '://') === false || strpos($file, $upload_url) !== false) {
             continue;
         }
         //获取文件扩展名
         $filename = fileext($file);
         //$file_name = basename($file);
         $filename = $this->getname($filename);
         $newfile = $uploaddir . $filename;
         \Org\Net\Http::curlDownload($file, $newfile);
         //var_dump($newfile);exit;
     }
     //替换下载后的地址
 }
Example #16
0
function ftpupload($aids, $uid = 0)
{
    global $_G;
    $uid = $uid ? $uid : $_G['uid'];
    if (!$aids || !$_G['setting']['ftp']['on']) {
        return;
    }
    $query = DB::query("SELECT aid, thumb, attachment, filename, filesize FROM " . DB::table('forum_attachment') . " WHERE aid IN (" . dimplode($aids) . ") AND uid='{$_G['uid']}' AND remote='0'");
    $aids = array();
    while ($attach = DB::fetch($query)) {
        $attach['ext'] = fileext($attach['filename']);
        if ((!$_G['setting']['ftp']['allowedexts'] && !$_G['setting']['ftp']['disallowedexts'] || $_G['setting']['ftp']['allowedexts'] && in_array($attach['ext'], explode("\n", strtolower($_G['setting']['ftp']['allowedexts']))) || $_G['setting']['ftp']['disallowedexts'] && !in_array($attach['ext'], explode("\n", strtolower($_G['setting']['ftp']['disallowedexts'])))) && (!$_G['setting']['ftp']['minsize'] || $attach['filesize'] >= $_G['setting']['ftp']['minsize'] * 1024)) {
            if (ftpcmd('upload', 'forum/' . $attach['attachment']) && (!$attach['thumb'] || ftpcmd('upload', 'forum/' . $attach['attachment'] . '.thumb.jpg'))) {
                dunlink($attach);
                $aids[] = $attach['aid'];
            }
        }
    }
    if ($aids) {
        DB::update('forum_attachment', array('remote' => 1), "aid IN (" . dimplode($aids) . ")");
    }
}
Example #17
0
 function downloadfile($filename)
 {
     $this->setfilename($filename);
     if ($this->filecheck()) {
         if (empty($this->attach_filename)) {
             $fn = array_pop(explode('/', strtr($this->filename, '\\', '/')));
         } else {
             $fn = $this->attach_filename . fileext($this->filename);
         }
         header("Pragma: public");
         header("Expires: 0");
         // set expiration time
         header("Cache-Component: must-revalidate, post-check=0, pre-check=0");
         header("Content-type:application/java-archive");
         header("Content-Length: " . filesize($this->filename));
         header("Content-Disposition: attachment; filename=" . $fn);
         header('Content-Transfer-Encoding: binary');
         readfile($this->filename);
         return true;
     } else {
         return false;
     }
 }
Example #18
0
 public function addAction()
 {
     $dir = $this->get('dir') ? urldecode($this->get('dir')) : '';
     $dir = str_replace(array('..\\', '../', './', '.\\'), '', trim($dir));
     $dir = substr($dir, 0, 1) == '/' ? substr($dir, 1) : $dir;
     $dir = str_replace(array('\\', '//'), DIRECTORY_SEPARATOR, $dir);
     $filepath = $this->dir . $dir;
     $local = str_replace(XIAOCMS_PATH, '', $filepath);
     $filecontent = '';
     if ($this->post('submit')) {
         $filename = $this->post('file_name');
         if (file_exists($filepath . $filename)) {
             $this->show_message('该文件已经存在', 2, 1);
         }
         $ext = fileext($filename);
         if (!in_array($ext, array('html', 'css', 'js', 'txt'))) {
             $this->show_message('文件名后缀不对', 2, 1);
         }
         file_put_contents($filepath . $filename, $this->post('file_content'), LOCK_EX);
         $this->show_message('提交成功', 1, url('template', array('dir' => $dir)));
     }
     include $this->admin_tpl('template_add');
 }
Example #19
0
function parseforumattach(&$post, $aids)
{
    global $_G;
    if ($aids = array_unique($aids)) {
        require_once libfile('function/attachment');
        $finds = $replaces = array();
        foreach (C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $post['tid'], 'aid', $aids) as $attach) {
            $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'forum/';
            $attach['dateline'] = dgmdate($attach['dateline'], 'u');
            $extension = strtolower(fileext($attach['filename']));
            $attach['ext'] = $extension;
            $attach['imgalt'] = $attach['isimage'] ? strip_tags(str_replace('"', '\\"', $attach['description'] ? $attach['description'] : $attach['filename'])) : '';
            $attach['attachicon'] = attachtype($extension . "\t" . $attach['filetype']);
            $attach['attachsize'] = sizecount($attach['filesize']);
            $attach['refcheck'] = !$attach['remote'] && $_G['setting']['attachrefcheck'] || $attach['remote'] && ($_G['setting']['ftp']['hideurl'] || $attach['isimage'] && $_G['setting']['attachimgpost'] && strtolower(substr($_G['setting']['ftp']['attachurl'], 0, 3)) == 'ftp');
            $aidencode = packaids($attach);
            $widthcode = attachwidth($attach['width']);
            $is_archive = $_G['forum_thread']['is_archived'] ? "&fid=" . $_G['fid'] . "&archiveid=" . $_G['forum_thread']['archiveid'] : '';
            if ($attach['isimage']) {
                $attachthumb = getimgthumbname($attach['attachment']);
                if ($_G['setting']['thumbstatus'] && $attach['thumb']) {
                    $replaces[$attach['aid']] = "<a href=\"javascript:;\"><img id=\"_aimg_{$attach['aid']}\" aid=\"{$attach['aid']}\" onclick=\"zoom(this, this.getAttribute('zoomfile'), 0, 0, '{$_G[forum][showexif]}')\"\n\t\t\t\t\t\tzoomfile=\"" . ($attach['refcheck'] ? "forum.php?mod=attachment{$is_archive}&aid={$aidencode}&noupdate=yes&nothumb=yes" : $attach['url'] . $attach['attachment']) . "\"\n\t\t\t\t\t\tsrc=\"" . ($attach['refcheck'] ? "forum.php?mod=attachment{$is_archive}&aid={$aidencode}" : $attach['url'] . $attachthumb) . "\" alt=\"{$attach['imgalt']}\" title=\"{$attach['imgalt']}\" w=\"{$attach['width']}\" /></a>";
                } else {
                    $replaces[$attach['aid']] = "<img id=\"_aimg_{$attach['aid']}\" aid=\"{$attach['aid']}\"\n\t\t\t\t\t\tzoomfile=\"" . ($attach['refcheck'] ? "forum.php?mod=attachment{$is_archive}&aid={$aidencode}&noupdate=yes&nothumb=yes" : $attach['url'] . $attach['attachment']) . "\"\n\t\t\t\t\t\tsrc=\"" . ($attach['refcheck'] ? "forum.php?mod=attachment{$is_archive}&aid={$aidencode}&noupdate=yes " : $attach['url'] . $attach['attachment']) . "\" {$widthcode} alt=\"{$attach['imgalt']}\" title=\"{$attach['imgalt']}\" w=\"{$attach['width']}\" />";
                }
            } else {
                $replaces[$attach['aid']] = "{$attach['attachicon']}<a href=\"forum.php?mod=attachment{$is_archive}&aid={$aidencode}\" onmouseover=\"showMenu({'ctrlid':this.id,'pos':'12'})\" id=\"aid{$attach['aid']}\" target=\"_blank\">{$attach['filename']}</a>";
            }
            $finds[$attach['aid']] = '[attach]' . $attach['aid'] . '[/attach]';
        }
        if ($finds && $replaces) {
            $post['message'] = str_ireplace($finds, $replaces, $post['message']);
        }
    }
}
Example #20
0
function writetocsscache($data) {
	global $_G;
/*vot*/	$dir = DISCUZ_ROOT.'template/default/common/';
//DEBUG
//echo "writetocsscache: discuz_root=".DISCUZ_ROOT."<br>";
//echo "writetocsscache: dir=".$dir."<br>";
	$dh = opendir($dir);
	$data['staticurl'] = STATICURL;
	while(($entry = readdir($dh)) !== false) {
		if(fileext($entry) == 'css') {
/*vot*/			$cssfile = DISCUZ_ROOT.$data['tpldir'].'/common/'.$entry;
//DEBUG
//echo "writetocsscache: entry=".$entry."<br>";
//echo "writetocsscache: cssfile=".$cssfile."<br>";
			!file_exists($cssfile) && $cssfile = $dir.$entry;
			$cssdata = @implode('', file($cssfile));
//DEBUG
//echo "writetocsscache: check 1 for cssfile=".DISCUZ_ROOT.$data['tpldir'].'/common/extend_'.$entry."<br>";
			if(file_exists($cssfile = DISCUZ_ROOT.'./'.$data['tpldir'].'/common/extend_'.$entry)) {
				$cssdata .= @implode('', file($cssfile));
			}
			if(is_array($_G['setting']['plugins']['available']) && $_G['setting']['plugins']['available']) {
				foreach($_G['setting']['plugins']['available'] as $plugin) {
//DEBUG
//echo "writetocsscache: check 2 for cssfile=".DISCUZ_ROOT.'./source/plugin/'.$plugin.'/template/extend_'.$entry."<br>";
					if(file_exists($cssfile = DISCUZ_ROOT.'./source/plugin/'.$plugin.'/template/extend_'.$entry)) {
						$cssdata .= @implode('', file($cssfile));
					}
				}
			}
			$cssdata = preg_replace("/\{([A-Z0-9]+)\}/e", '\$data[strtolower(\'\1\')]', $cssdata);
			$cssdata = preg_replace("/<\?.+?\?>\s*/", '', $cssdata);
			$cssdata = !preg_match('/^http:\/\//i', $data['styleimgdir']) ? preg_replace("/url\(([\"'])?".preg_quote($data['styleimgdir'], '/')."/i", "url(\\1../../$data[styleimgdir]", $cssdata) : $cssdata;
			$cssdata = !preg_match('/^http:\/\//i', $data['imgdir']) ? preg_replace("/url\(([\"'])?".preg_quote($data['imgdir'], '/')."/i", "url(\\1../../$data[imgdir]", $cssdata) : $cssdata;
			$cssdata = !preg_match('/^http:\/\//i', $data['staticurl']) ? preg_replace("/url\(([\"'])?".preg_quote($data['staticurl'], '/')."/i", "url(\\1../../$data[staticurl]", $cssdata) : $cssdata;
/*vot*/			if($entry == 'module.css' || $entry == 'module_rtl.css') {
				$cssdata = preg_replace('/\/\*\*\s*(.+?)\s*\*\*\//', '[\\1]', $cssdata);
			}
			$cssdata = preg_replace(array('/\s*([,;:\{\}])\s*/', '/[\t\n\r]/', '/\/\*.+?\*\//'), array('\\1', '',''), $cssdata);
			if(@$fp = fopen(DISCUZ_ROOT.'./data/cache/style_'.$data['styleid'].'_'.$entry, 'w')) {
				fwrite($fp, $cssdata);
				fclose($fp);
			} else {
				exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .');
			}
		}
	}
}
Example #21
0
 function newMediaObject($uid, $username, $password, $mediaobject = array())
 {
     global $_SGLOBAL, $space;
     $fileext = fileext($mediaobject['name']);
     if (!in_array($fileext, array('jpg', 'gif', 'png'))) {
         $this->sendFault(500, 'You should choose image file to upload.');
     }
     $this->authUser($username, $password);
     include_once S_ROOT . './source/function_cp.php';
     $struct = array();
     if ($stream_save = stream_save(sstripslashes($mediaobject['bits']), '0', $fileext)) {
         $struct['url'] = pic_get($stream_save['filepath'], $stream_save['thumb'], $stream_save['remote'], 0);
     } else {
         $this->sendFault(500, 'Sorry, your image could not be uploaded. Something wrong happened.');
     }
     if (!preg_match("/^(http\\:\\/\\/|\\/)/i", $struct['url'])) {
         $struct['url'] = $this->siteUrl . $struct['url'];
     }
     return $struct;
 }
Example #22
0
function recyclebinpostshowpostlist($fid, $authors, $starttime, $endtime, $keywords, $start_limit, $lpp)
{
    global $_G, $lang, $posttableid, $security;
    $tids = $fids = array();
    if ($security) {
        $postlist = C::t('#security#security_evilpost')->fetch_all_by_search($posttableid, null, $keywords, -5, $fid, null, $authors ? explode(',', str_replace(' ', '', $authors)) : null, strtotime($starttime), strtotime($endtime), null, null, $start_limit, $lpp);
    } else {
        $postlist = C::t('forum_post')->fetch_all_by_search($posttableid, null, $keywords, -5, $fid, null, $authors ? explode(',', str_replace(' ', '', $authors)) : null, strtotime($starttime), strtotime($endtime), null, null, $start_limit, $lpp);
    }
    if (empty($postlist)) {
        return false;
    }
    foreach ($postlist as $key => $post) {
        $tids[$post['tid']] = $post['tid'];
        $fids[$post['fid']] = $post['fid'];
    }
    foreach (C::t('forum_thread')->fetch_all_by_tid($tids) as $thread) {
        $thread['tsubject'] = $thread['subject'];
        $threadlist[$thread['tid']] = $thread;
    }
    $query = C::t('forum_forum')->fetch_all_by_fid($fids);
    foreach ($query as $val) {
        $forum = array('fid' => $val['fid'], 'forumname' => $val['name'], 'allowsmilies' => $val['allowsmilies'], 'allowhtml' => $val['allowhtml'], 'allowbbcode' => $val['allowbbcode'], 'allowimgcode' => $val['allowimgcode']);
        $forumlist[$forum['fid']] = $forum;
    }
    foreach ($postlist as $key => $post) {
        $post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], sprintf('%00b', $post['htmlon']), $forumlist[$post['fid']]['allowsmilies'], $forumlist[$post['fid']]['allowbbcode'], $forumlist[$post['fid']]['allowimgcode'], $forumlist[$post['fid']]['allowhtml']);
        $post['dateline'] = dgmdate($post['dateline']);
        if ($post['attachment']) {
            require_once libfile('function/attachment');
            foreach (C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $post['tid'], 'pid', $post['pid']) as $attach) {
                $_G['setting']['attachurl'] = $attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl'];
                $attach['url'] = $attach['isimage'] ? " {$attach['filename']} (" . sizecount($attach['filesize']) . ")<br /><br /><img src=\"" . $_G['setting']['attachurl'] . "forum/{$attach['attachment']}\" onload=\"if(this.width > 100) {this.resized=true; this.width=100;}\">" : "<a href=\"" . $_G['setting']['attachurl'] . "forum/{$attach['attachment']}\" target=\"_blank\">{$attach['filename']}</a> (" . sizecount($attach['filesize']) . ")";
                $post['message'] .= "<br /><br />{$lang['attachment']}: " . attachtype(fileext($attach['filename']) . "\t") . $attach['url'];
            }
        }
        showtablerow("id=\"mod_{$post['pid']}_row1\"", array('rowspan="3" class="rowform threadopt" style="width:80px;"', 'class="threadtitle"'), array("<ul class=\"nofloat\"><li><input class=\"radio\" type=\"radio\" name=\"moderate[{$post['pid']}]\" id=\"mod_{$post['pid']}_1\" value=\"delete\" checked=\"checked\" /><label for=\"mod_{$post['pid']}_1\">{$lang['delete']}</label></li><li><input class=\"radio\" type=\"radio\" name=\"moderate[{$post['pid']}]\" id=\"mod_{$post['pid']}_2\" value=\"undelete\" /><label for=\"mod_{$post['pid']}_2\">{$lang['undelete']}</label></li><li><input class=\"radio\" type=\"radio\" name=\"moderate[{$post['pid']}]\" id=\"mod_{$post['pid']}_3\" value=\"ignore\" /><label for=\"mod_{$post['pid']}_3\">{$lang['ignore']}</label></li></ul>", "<h3><a href=\"forum.php?mod=forumdisplay&fid={$post['fid']}\" target=\"_blank\">" . $forumlist[$post['fid']]['forumname'] . "</a> &raquo; <a href=\"forum.php?mod=viewthread&tid={$post['tid']}\" target=\"_blank\">" . $threadlist[$post['tid']]['tsubject'] . "</a>" . ($post['subject'] ? ' &raquo; ' . $post['subject'] : '') . "</h3><p><span class=\"bold\">{$lang['author']}:</span> <a href=\"home.php?mod=space&uid={$post['authorid']}\" target=\"_blank\">{$post['author']}</a> &nbsp;&nbsp; <span class=\"bold\">{$lang['time']}:</span> {$post['dateline']} &nbsp;&nbsp; IP: {$post['useip']}</p>"));
        showtablerow("id=\"mod_{$post['pid']}_row2\"", 'colspan="2" style="padding: 10px; line-height: 180%;"', '<div style="overflow: auto; overflow-x: hidden; max-height:120px; height:auto !important; height:120px; word-break: break-all;">' . $post['message'] . '</div>');
        showtablerow("id=\"mod_{$post['pid']}_row3\"", 'class="threadopt threadtitle" colspan="2"', "{$lang['isanonymous']}: " . ($post['anonymous'] ? $lang['yes'] : $lang['no']) . " &nbsp;&nbsp; {$lang['ishtmlon']}: " . ($post['htmlon'] ? $lang['yes'] : $lang['no']));
    }
    return true;
}
Example #23
0
                }
            } elseif ($value['subtype'] == 'real') {
                foreach ($remoteurl as $rs) {
                    $value['message'] .= '<div>
						<object id="RVOCX" classid="CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" width="420" height="315">
						<param name="AUTOSTART" value="0">
						<param name="SRC" value="' . $rs['remoteurl'] . '">
						<param name="CONTROLS" value="ControlPanel">
						<param name="CONSOLE" value="cons">
						<embed autostart="false" src="' . $rs['remoteurl'] . '" type="audio/x-pn-realaudio-plugin" width="420" height="315" controls="ControlPanel" console="cons"></embed>
						</object>
						<br>' . $rs['remoteurlname'] . '</div>';
                }
            } elseif ($value['subtype'] == 'flash') {
                foreach ($remoteurl as $rs) {
                    if (fileext($rs['remoteurl']) == 'flv') {
                        $rs['remoteurl'] = 'image/flv.swf?flvurl=' . $rs['remoteurl'];
                    }
                    $value['message'] .= '<div>
						<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="photo" align="middle" height="315" width="420">
						<param name="movie" value="' . $rs['remoteurl'] . '">
						<param name="quality" value="high">
						<param name="allowFullScreen" value="true">
						<embed src="' . $rs['remoteurl'] . '" quality="high" name="photo" type="application/x-shockwave-flash" allowfullscreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" align="middle" height="315" width="420">
						</object>
						<br>' . $rs['remoteurlname'] . '</div>';
                }
            } else {
                foreach ($remoteurl as $rs) {
                    $value['message'] .= '<div><a href="' . $rs['remoteurl'] . '">' . $rs['remoteurlname'] . '</a></div>';
                }
Example #24
0
			$aid = $a['aid'];
			$tid = $a['tid'];
			$dateline = $a['dateline'];
			$filename = $a['filename'];
			$filetype = $a['filetype'];
			$attachment = $a['attachment'];
			$isimage = $a['isimage'];
			$thumb = $a['thumb'];
			$oldpath = $attachpath.'/'.$attachment;
			if(file_exists($oldpath)) {
				$realname = substr(strrchr('/'.$attachment, '/'), 1);
				if($newattachsave == 1) {
					$fid = $db->result($db->query("SELECT fid FROM {$tablepre}threads WHERE tid = '$tid' LIMIT 1"), 0);
					$fid = $fid ? $fid : 0;
				} elseif($newattachsave == 2) {
					$extension = strtolower(fileext($filename));
				}

				if($newattachsave) {
					switch($newattachsave) {
						case 1: $attach_subdir = 'forumid_'.$fid; break;
						case 2: $attach_subdir = 'ext_'.$extension; break;
						case 3: $attach_subdir = 'month_'.gmdate('ym', $dateline); break;
						case 4: $attach_subdir = 'day_'.gmdate('ymd', $dateline); break;
					}
					$attach_dir = $attachpath.'/'.$attach_subdir;
					if(!is_dir($attach_dir)) {
						mkdir($attach_dir, 0777);
						@fclose(fopen($attach_dir.'/index.htm', 'w'));
					}
					$newattachment = $attach_subdir.'/'.$realname;
Example #25
0
/**
 * 文件下载
 * @param $filepath 文件路径
 * @param $filename 文件名称
 */
function file_down($filepath, $filename = '')
{
    if (!$filename) {
        $filename = basename($filepath);
    }
    if (is_ie()) {
        $filename = rawurlencode($filename);
    }
    $filetype = fileext($filename);
    $filesize = sprintf("%u", filesize($filepath));
    if (ob_get_length() !== false) {
        @ob_end_clean();
    }
    header('Pragma: public');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: pre-check=0, post-check=0, max-age=0');
    header('Content-Transfer-Encoding: binary');
    header('Content-Encoding: none');
    header('Content-type: ' . $filetype);
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header('Content-length: ' . $filesize);
    readfile($filepath);
    exit;
}
Example #26
0
/**
 * 判断是否为视频
 */
function is_video($file)
{
    $ext_arr = array('rm', 'mpg', 'avi', 'mpeg', 'wmv', 'flv', 'asf', 'rmvb');
    $ext = fileext($file);
    return in_array($ext, $ext_arr) ? $ext_arr : false;
}
Example #27
0
function updateattach()
{
    global $db, $tablepre, $attachsave, $attachdir, $discuz_uid, $postattachcredits, $tid, $pid, $attachextensions, $attachnew, $attachdel, $allowsetattachperm, $maxprice, $watermarkstatus;
    $imageexists = 0;
    $attachnew = (array) $attachnew;
    $sqladd = $pid > 0 ? "OR pid='{$pid}'" : '';
    $query = $db->query("SELECT * FROM {$tablepre}attachments WHERE (uid='{$discuz_uid}' AND tid='0') {$sqladd}");
    $attachnum = $db->num_rows($query);
    if ($attachnum) {
        if ($attachnum -= count($attachdel)) {
            checklowerlimit($postattachcredits, $attachnum);
        }
        $attachcount = 0;
        $delaids = array();
        while ($attach = $db->fetch_array($query)) {
            if (is_array($attachdel) && in_array($attach['aid'], $attachdel)) {
                dunlink($attach['attachment'], $attach['thumb']);
                $delaids[] = $attach['aid'];
                continue;
            }
            $extension = strtolower(fileext($attach['filename']));
            if ($attachextensions && (!preg_match("/(^|\\s|,)" . preg_quote($extension, '/') . "(\$|\\s|,)/i", $attachextensions) || !$extension)) {
                continue;
            }
            $anew = $attachnew[$attach['aid']];
            $anew['aid'] = $attach['aid'];
            $anew['ext'] = $extension;
            $anew['size'] = $attach['filesize'];
            if ($attach['pid'] == 0) {
                $attach_basename = basename($attach['attachment']);
                $attach_src = $attachdir . '/' . $attach['attachment'];
                if ($attachsave) {
                    switch ($attachsave) {
                        case 1:
                            $attach_subdir = 'forumid_' . $GLOBALS['fid'];
                            break;
                        case 2:
                            $attach_subdir = 'ext_' . $extension;
                            break;
                        case 3:
                            $attach_subdir = 'month_' . date('ym');
                            break;
                        case 4:
                            $attach_subdir = 'day_' . date('ymd');
                            break;
                    }
                    $attach_descdir = $attachdir . '/' . $attach_subdir;
                    $anew['attachment'] = $attach_subdir . '/' . $attach_basename;
                } else {
                    $attach_descdir = $attachdir;
                    $anew['attachment'] = $attach_basename;
                }
                $anew['thumb'] = $attach['thumb'];
                $attach_desc = $attach_descdir . '/' . $attach_basename;
                if ($attach['isimage'] && $watermarkstatus) {
                    require_once DISCUZ_ROOT . './include/image.class.php';
                    $image = new Image($attach_src, $attach);
                    if ($image->imagecreatefromfunc && $image->imagefunc) {
                        $image->Watermark();
                        $attach = $image->attach;
                        $attach['filesize'] = $attach['size'];
                    }
                }
                if (!is_dir($attach_descdir)) {
                    @mkdir($attach_descdir, 0777);
                    @fclose(fopen($attach_descdir . '/index.htm', 'w'));
                }
                if ($attach['thumb'] == 1) {
                    if (!@rename($attach_src . '.thumb.jpg', $attach_desc . '.thumb.jpg') && @copy($attach_src . '.thumb.jpg', $attach_desc . '.thumb.jpg')) {
                        @unlink($attach_src . '.thumb.jpg');
                    }
                }
                if (!@rename($attach_src, $attach_desc) && @copy($attach_src, $attach_desc)) {
                    @unlink($attach_src);
                }
                $anew['remote'] = ftpupload($attach_desc, $anew);
                $attachcount++;
            }
            if ($attach['isimage']) {
                $imageexists = 1;
            }
            $anew['filesize'] = $attach['filesize'];
            $anew['perm'] = $allowsetattachperm ? $anew['perm'] : 0;
            $anew['description'] = cutstr(dhtmlspecialchars($anew['description']), 100);
            $anew['price'] = $maxprice ? intval($anew['price']) <= $maxprice ? intval($anew['price']) : $maxprice : 0;
            $sqladd = $attach['pid'] == 0 ? ", tid='{$tid}', pid='{$pid}', attachment='{$anew['attachment']}', remote='{$anew['remote']}'" : '';
            $db->query("UPDATE {$tablepre}attachments SET readperm='{$anew['readperm']}', price='{$anew['price']}', filesize='{$anew['filesize']}' {$sqladd} WHERE aid='{$attach['aid']}'");
            if ($anew['description']) {
                $db->query("REPLACE INTO {$tablepre}attachmentfields (aid, tid, pid, uid, description) VALUES ('{$attach['aid']}', '{$tid}', '{$pid}', '{$attach['uid']}', '{$anew['description']}')");
            }
        }
        if ($delaids) {
            $db->query("DELETE FROM {$tablepre}attachments WHERE aid IN (" . implodeids($delaids) . ")", 'UNBUFFERED');
            $db->query("DELETE FROM {$tablepre}attachmentfields WHERE aid IN (" . implodeids($delaids) . ")", 'UNBUFFERED');
        }
        $attachment = $imageexists ? 2 : 1;
        if ($attachcount) {
            $db->query("UPDATE {$tablepre}threads SET attachment='{$attachment}' WHERE tid='{$tid}'", 'UNBUFFERED');
            $db->query("UPDATE {$tablepre}posts SET attachment='{$attachment}' WHERE pid='{$pid}'", 'UNBUFFERED');
            updatecredits($discuz_uid, $postattachcredits, $attachcount);
        }
    }
}
function import_styles($ignoreversion = 1, $dir = '', $restoreid = 0, $updatecache = 1)
{
    global $_G, $importtxt, $stylearray;
    if (!isset($dir)) {
        $stylearrays = array(getimportdata('Discuz! Style'));
    } else {
        if (!$restoreid) {
            $dir = str_replace(array('/', '\\'), '', $dir);
            $templatedir = DISCUZ_ROOT . './template/' . $dir;
        } else {
            $templatedir = DISCUZ_ROOT . $dir;
        }
        $searchdir = dir($templatedir);
        $stylearrays = array();
        while ($searchentry = $searchdir->read()) {
            if (substr($searchentry, 0, 13) == 'discuz_style_' && fileext($searchentry) == 'xml') {
                $importfile = $templatedir . '/' . $searchentry;
                $importtxt = implode('', file($importfile));
                $stylearrays[] = getimportdata('Discuz! Style');
            }
        }
    }
    foreach ($stylearrays as $stylearray) {
        if (empty($ignoreversion) && strip_tags($stylearray['version']) != strip_tags($_G['setting']['version'])) {
            cpmsg('styles_import_version_invalid', '', 'error', array('cur_version' => $stylearray['version'], 'set_version' => $_G['setting']['version']));
        }
        if (!$restoreid) {
            $renamed = 0;
            if ($stylearray['templateid'] != 1) {
                $templatedir = DISCUZ_ROOT . './' . $stylearray['directory'];
                if (!is_dir($templatedir)) {
                    if (!@mkdir($templatedir, 0777)) {
                        $basedir = dirname($stylearray['directory']);
                        cpmsg('styles_import_directory_invalid', '', 'error', array('basedir' => $basedir, 'directory' => $stylearray['directory']));
                    }
                }
                if (!($templateid = DB::result_first("SELECT templateid FROM " . DB::table('common_template') . " WHERE name='{$stylearray['tplname']}'"))) {
                    DB::query("INSERT INTO " . DB::table('common_template') . " (name, directory, copyright)\n\t\t\t\t\t\tVALUES ('{$stylearray['tplname']}', '{$stylearray['directory']}', '{$stylearray['copyright']}')");
                    $templateid = DB::insert_id();
                }
            } else {
                $templateid = 1;
            }
            if (DB::result_first("SELECT COUNT(*) FROM " . DB::table('common_style') . " WHERE name='{$stylearray['name']}'")) {
                $stylearray['name'] .= '_' . random(4);
                $renamed = 1;
            }
            DB::query("INSERT INTO " . DB::table('common_style') . " (name, templateid)\n\t\t\t\tVALUES ('{$stylearray['name']}', '{$templateid}')");
            $styleidnew = DB::insert_id();
        } else {
            $styleidnew = $restoreid;
            DB::query("DELETE FROM " . DB::table('common_stylevar') . " WHERE styleid='{$styleidnew}'");
        }
        foreach ($stylearray['style'] as $variable => $substitute) {
            $substitute = @htmlspecialchars($substitute);
            DB::query("INSERT INTO " . DB::table('common_stylevar') . " (styleid, variable, substitute)\n\t\t\t\tVALUES ('{$styleidnew}', '{$variable}', '{$substitute}')");
        }
    }
    if ($updatecache) {
        updatecache('styles');
        updatecache('setting');
    }
    return $renamed;
}
Example #29
0
                 if (isset($issettids[$thread['tid']])) {
                     $disabledstr = 'disabled';
                 } else {
                     $issettids[$thread['tid']] = $thread['tid'];
                 }
                 $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($thread['tid']);
                 $thread = array_merge($thread, $post);
                 $thread['message'] = discuzcode($thread['message'], $thread['smileyoff'], $thread['bbcodeoff'], sprintf('%00b', $thread['htmlon']), $thread['allowsmilies'], $thread['allowbbcode'], $thread['allowimgcode'], $thread['allowhtml']);
                 $thread['moddateline'] = dgmdate($thread['moddateline']);
                 $thread['dateline'] = dgmdate($thread['dateline']);
                 if ($thread['attachment']) {
                     require_once libfile('function/attachment');
                     foreach (C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $thread['tid'], 'tid', $thread['tid']) as $attach) {
                         $_G['setting']['attachurl'] = $attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl'];
                         $attach['url'] = $attach['isimage'] ? " {$attach['filename']} (" . sizecount($attach['filesize']) . ")<br /><br /><img src=\"" . $_G['setting']['attachurl'] . "forum/{$attach['attachment']}\" onload=\"if(this.width > 100) {this.resized=true; this.width=100;}\">" : "<a href=\"" . $_G['setting']['attachurl'] . "forum/{$attach['attachment']}\" target=\"_blank\">{$attach['filename']}</a> (" . sizecount($attach['filesize']) . ")";
                         $thread['message'] .= "<br /><br />{$lang['attachment']}: " . attachtype(fileext($attach['filename']) . "\t") . $attach['url'];
                     }
                 }
                 showtablerow("id=\"mod_{$thread['tid']}_row1\"", array('rowspan="3" class="rowform threadopt" style="width:80px;"', 'class="threadtitle"'), array("<ul class=\"nofloat\"><li><input class=\"radio\" type=\"radio\" name=\"moderate[{$thread['tid']}]\" id=\"mod_{$thread['tid']}_1\" value=\"delete\" " . (empty($disabledstr) ? "checked=\"checked\"" : '') . " {$disabledstr} /><label for=\"mod_{$thread['tid']}_1\">{$lang['delete']}</label></li><li><input class=\"radio\" type=\"radio\" name=\"moderate[{$thread['tid']}]\" id=\"mod_{$thread['tid']}_2\" value=\"undelete\" {$disabledstr}/><label for=\"mod_{$thread['tid']}_2\">{$lang['undelete']}</label></li><li><input class=\"radio\" type=\"radio\" name=\"moderate[{$thread['tid']}]\" id=\"mod_{$thread['tid']}_3\" value=\"ignore\" {$disabledstr}/><label for=\"mod_{$thread['tid']}_3\">{$lang['ignore']}</label></li></ul>", "<h3><a href=\"forum.php?mod=forumdisplay&fid={$thread['fid']}\" target=\"_blank\">{$thread['forumname']}</a> &raquo; {$thread['subject']}</h3><p><span class=\"bold\">{$lang['author']}:</span> <a href=\"home.php?mod=space&uid={$thread['authorid']}\" target=\"_blank\">{$thread['author']}</a> &nbsp;&nbsp; <span class=\"bold\">{$lang['time']}:</span> {$thread['dateline']} &nbsp;&nbsp; {$lang['threads_replies']}: {$thread['replies']} {$lang['threads_views']}: {$thread['views']}</p>"));
                 showtablerow("id=\"mod_{$thread['tid']}_row2\"", 'colspan="2" style="padding: 10px; line-height: 180%;"', '<div style="overflow: auto; overflow-x: hidden; max-height:120px; height:auto !important; height:120px; word-break: break-all;">' . $thread['message'] . '</div>');
                 showtablerow("id=\"mod_{$thread['tid']}_row3\"", 'class="threadopt threadtitle" colspan="2"', "{$lang['operator']}: <a href=\"home.php?mod=space&uid={$thread['moduid']}\" target=\"_blank\">{$thread['modusername']}</a> &nbsp;&nbsp; {$lang['recyclebin_delete_time']}: {$thread['moddateline']}&nbsp;&nbsp; {$lang['reason']}: {$thread['reason']}");
             }
         }
         showsubmit('rbsubmit', 'submit', '', '<a href="#rb" onclick="checkAll(\'option\', $(\'rbform\'), \'delete\')">' . cplang('recyclebin_all_delete') . '</a> &nbsp;<a href="#rb" onclick="checkAll(\'option\', $(\'rbform\'), \'undelete\')">' . cplang('recyclebin_all_undelete') . '</a> &nbsp;<a href="#rb" onclick="checkAll(\'option\', $(\'rbform\'), \'ignore\')">' . cplang('recyclebin_all_ignore') . '</a> &nbsp;', $multi);
         showtablefooter();
         showformfooter();
         echo '<iframe name="rbframe" style="display:none"></iframe>';
         showtagfooter('div');
     }
 } else {
     $moderate = $_GET['moderate'];
function pic_save($FILE, $albumid, $title, $topicid=0) {
	global $_SGLOBAL, $_SCONFIG, $space, $_SC;

	if($albumid<0) $albumid = 0;
	
	//允许上传类型
	$allowpictype = array('jpg','jpeg','gif','png');

	//检查
	$FILE['size'] = intval($FILE['size']);
	if(empty($FILE['size']) || empty($FILE['tmp_name']) || !empty($FILE['error'])) {
		return cplang('lack_of_access_to_upload_file_size');
	}

	//判断后缀
	$fileext = fileext($FILE['name']);
	if(!in_array($fileext, $allowpictype)) {
		return cplang('only_allows_upload_file_types');
	}

	//获取目录
	if(!$filepath = getfilepath($fileext, true)) {
		return cplang('unable_to_create_upload_directory_server');
	}

	//检查空间大小
	if(empty($space)) {
		$space = getspace($_SGLOBAL['supe_uid']);
	}
	
	//用户组
	if(!checkperm('allowupload')) {
		ckspacelog();
		return cplang('inadequate_capacity_space');
	}
	
	//实名认证
	if(!ckrealname('album', 1)) {
		return cplang('inadequate_capacity_space');
	}
	
	//视频认证
	if(!ckvideophoto('album', array(), 1)) {
		return cplang('inadequate_capacity_space');
	}
	
	//新用户见习
	if(!cknewuser(1)) {
		return cplang('inadequate_capacity_space');
	}

	$maxattachsize = checkperm('maxattachsize');//单位MB
	if($maxattachsize) {//0为不限制
		if($space['attachsize'] + $FILE['size'] > $maxattachsize + $space['addsize']) {
			return cplang('inadequate_capacity_space');
		}
	}

	//相册选择
	$showtip = true;
	$albumfriend = 0;
	if($albumid) {
		preg_match("/^new\:(.+)$/i", $albumid, $matchs);
		if(!empty($matchs[1])) {
			$albumname = shtmlspecialchars(trim($matchs[1]));
			if(empty($albumname)) $albumname = sgmdate('Ymd');
			$albumid = album_creat(array('albumname' => $albumname));
		} else {
			$albumid = intval($albumid);
			if($albumid) {
				$query = $_SGLOBAL['db']->query("SELECT albumname,friend FROM ".tname('album')." WHERE albumid='$albumid' AND uid='$_SGLOBAL[supe_uid]'");
				if($value = $_SGLOBAL['db']->fetch_array($query)) {
					$albumname = addslashes($value['albumname']);
					$albumfriend = $value['friend'];
				} else {
					$albumname = sgmdate('Ymd');
					$albumid = album_creat(array('albumname' => $albumname));
				}
			}
		}
	} else {
		$albumid = 0;
		$showtip = false;
	}

	//本地上传
	$new_name = $_SC['attachdir'].'./'.$filepath;
	$tmp_name = $FILE['tmp_name'];
	if(@copy($tmp_name, $new_name)) {
		@unlink($tmp_name);
	} elseif((function_exists('move_uploaded_file') && @move_uploaded_file($tmp_name, $new_name))) {
	} elseif(@rename($tmp_name, $new_name)) {
	} else {
		return cplang('mobile_picture_temporary_failure');
	}
	
	//检查是否图片
	if(function_exists('getimagesize')) {
		$tmp_imagesize = @getimagesize($new_name);
		list($tmp_width, $tmp_height, $tmp_type) = (array)$tmp_imagesize;
		$tmp_size = $tmp_width * $tmp_height;
		if($tmp_size > 16777216 || $tmp_size < 4 || empty($tmp_type) || strpos($tmp_imagesize['mime'], 'flash') > 0) {
			@unlink($new_name);
			return cplang('only_allows_upload_file_types');
		}
	}

	//缩略图
	include_once(S_ROOT.'./source/function_image.php');
	$thumbpath = makethumb($new_name);
	$thumb = empty($thumbpath)?0:1;

	//是否压缩
	//获取上传后图片大小
	if(@$newfilesize = filesize($new_name)) {
		$FILE['size'] = $newfilesize;
	}

	//水印
	if($_SCONFIG['allowwatermark']) {
		makewatermark($new_name);
	}

	//进行ftp上传
	if($_SCONFIG['allowftp']) {
		include_once(S_ROOT.'./source/function_ftp.php');
		if(ftpupload($new_name, $filepath)) {
			$pic_remote = 1;
			$album_picflag = 2;
		} else {
			@unlink($new_name);
			@unlink($new_name.'.thumb.jpg');
			runlog('ftp', 'Ftp Upload '.$new_name.' failed.');
			return cplang('ftp_upload_file_size');
		}
	} else {
		$pic_remote = 0;
		$album_picflag = 1;
	}
	
	//入库
	$title = getstr($title, 200, 1, 1, 1);

	//入库
	$setarr = array(
		'albumid' => $albumid,
		'uid' => $_SGLOBAL['supe_uid'],
		'username' => $_SGLOBAL['supe_username'],
		'dateline' => $_SGLOBAL['timestamp'],
		'filename' => addslashes($FILE['name']),
		'postip' => getonlineip(),
		'title' => $title,
		'type' => addslashes($FILE['type']),
		'size' => $FILE['size'],
		'filepath' => $filepath,
		'thumb' => $thumb,
		'remote' => $pic_remote,
		'topicid' => $topicid
	);
	$setarr['picid'] = inserttable('pic', $setarr, 1);

	//更新附件大小
	//积分
	$setsql = '';
	if($showtip) {
		$reward = getreward('uploadimage', 0);
		if($reward['credit']) {
			$setsql = ",credit=credit+$reward[credit]";
		}
		if($reward['experience']) {
			$setsql .= ",experience=experience+$reward[experience]";
		}
	}
	$_SGLOBAL['db']->query("UPDATE ".tname('space')." SET attachsize=attachsize+'$FILE[size]', updatetime='$_SGLOBAL[timestamp]' $setsql WHERE uid='$_SGLOBAL[supe_uid]'");

	//相册更新
	if($albumid) {
		$file = $filepath.($thumb?'.thumb.jpg':'');
		$_SGLOBAL['db']->query("UPDATE ".tname('album')."
			SET picnum=picnum+1, updatetime='$_SGLOBAL[timestamp]', pic='$file', picflag='$album_picflag'
			WHERE albumid='$albumid'");
	}
	
	//统计
	updatestat('pic');

	return $setarr;
}