Example #1
0
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;
}
Example #2
0
 }
 $istopic = $iscategory = $isarticle = false;
 if ($template == 'portal/portal_topic_content') {
     $template = gettopictplname($clonefile);
     $istopic = true;
 } elseif ($template == 'portal/list') {
     $template = getportalcategorytplname($clonefile);
     $iscategory = true;
 } elseif ($template == 'portal/view') {
     $template = getportalarticletplname($clonefile, $template);
     $isarticle = true;
 }
 if (($istopic || $iscategory || $isarticle) && strpos($template, ':') !== false) {
     list($tpldirectory, $template) = explode(':', $template);
 }
 $checktpl = checkprimaltpl($tpldirectory . ':' . $template);
 if ($checktpl !== true) {
     showmessage($checktpl);
 }
 if ($optype == 'canceldiy') {
     @unlink(DISCUZ_ROOT . './data/diy/' . $tpldirectory . '/' . $targettplname . '_diy_preview.htm');
     if ($targettplname == $template) {
         @unlink(DISCUZ_ROOT . './data/diy/' . $tpldirectory . '/' . $targettplname . '_' . $clonefile . '_diy_preview.htm');
     }
     showmessage('do_success');
 }
 if ($recover == '1') {
     $file = './data/diy/' . $tpldirectory . '/' . $targettplname . '.htm';
     if (is_file($file . '.bak')) {
         copy($file . '.bak', $file);
     } else {
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;
}
Example #4
0
 if ($template == 'portal/portal_topic_content') {
     $template = gettopictplname($clonefile);
     $istopic = true;
 } elseif ($template == 'portal/list') {
     $template = getportalcategorytplname($clonefile);
     $iscategory = true;
 } elseif ($template == 'portal/view') {
     $arr = getportalarticletplname($clonefile, $template);
     if ($clonefile != $arr[0]) {
         $clonefile = $arr[0];
         $targettplname = $template . '_' . $clonefile;
     }
     $template = $arr[1];
     $isarticle = true;
 }
 $checktpl = checkprimaltpl($template);
 if ($checktpl !== true) {
     showmessage($checktpl);
 }
 if ($recover == '1') {
     $file = './data/diy/' . $targettplname . '.htm';
     if (is_file($file . '.bak')) {
         copy($file . '.bak', $file);
     } else {
         showmessage('diy_backup_noexist');
     }
 } else {
     $templatedata = array();
     checksecurity($_POST['spacecss']);
     $_POST['spacecss'] = dstripslashes($_POST['spacecss']);
     $templatedata['spacecss'] = preg_replace("/(\\<|\\>)/is", '', $_POST['spacecss']);
         cpmsg(cplang('diy_sign_invalid') . ',' . cplang('return'), NULL, 'error');
     }
     $checktpl = checkprimaltpl($primaltplname);
     if ($checktpl !== true) {
         cpmsg(cplang($checktpl) . ',' . cplang('return'), NULL, 'error');
     }
 }
 if (empty($_GET['viewprimaltplname'])) {
     $_GET['viewprimaltplname'] = getparentviewprimaltplname($_GET['catid']);
 } else {
     if (!isset($_GET['signs']['view'][dsign($_GET['viewprimaltplname'])])) {
         cpmsg(cplang('diy_sign_invalid') . ',' . cplang('return'), NULL, 'error');
     }
 }
 $viewprimaltplname = strpos($_GET['viewprimaltplname'], ':') === false ? $_G['cache']['style_default']['tpldir'] . ':portal/' . $_GET['viewprimaltplname'] : $_GET['viewprimaltplname'];
 $checktpl = checkprimaltpl($viewprimaltplname);
 if ($checktpl !== true) {
     cpmsg(cplang($checktpl) . ',' . cplang('return'), NULL, 'error');
 }
 $editcat['primaltplname'] = $primaltplname;
 $editcat['articleprimaltplname'] = $viewprimaltplname;
 if ($_GET['catid']) {
     if ($portalcategory[$_G['catid']]['level'] < 2) {
         $editcat['shownav'] = intval($_GET['shownav']);
     }
     if ($domain && $portalcategory[$_G['catid']]['level'] == 0) {
         $editcat['domain'] = $domain;
     } else {
         $editcat['domain'] = '';
     }
 } else {
Example #6
0
         $setarr['cover'] = 'portal/' . $pic['pic'];
         $setarr['picflag'] = $pic['remote'] ? '2' : '1';
     }
 } elseif (!empty($_POST['cover'])) {
     $setarr['cover'] = $_POST['cover'];
     $setarr['picflag'] = '0';
 }
 if ($topicid) {
     DB::update('portal_topic', $setarr, array('topicid' => $topicid));
 } else {
     $primaltplname = $_POST['primaltplname'];
     if (!$primaltplname || preg_match("/(\\.)(exe|jsp|asp|aspx|cgi|fcgi|pl)(\\.|\$)/i", $primaltplname)) {
         showmessage('filename_invalid');
     }
     $primaltplname = 'portal/' . str_replace(array('/', '\\', '.'), '', $primaltplname);
     checkprimaltpl($primaltplname);
     $setarr['uid'] = $_G['uid'];
     $setarr['username'] = $_G['username'];
     $setarr['dateline'] = $_G['timestamp'];
     $setarr['closed'] = '1';
     $setarr['primaltplname'] = $primaltplname;
     $topicid = DB::insert('portal_topic', $setarr, true);
     if (!$topicid) {
         showmessage('topic_created_failed');
     }
     $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);
     }
Example #7
0
 if ($optype == 'canceldiy') {
     @unlink(DISCUZ_ROOT . './data/diy/' . $targettplname . '_diy_preview.htm');
     if ($targettplname == $template) {
         @unlink(DISCUZ_ROOT . './data/diy/' . $targettplname . '_' . $clonefile . '_diy_preview.htm');
     }
     showmessage('do_success');
 }
 $istopic = $iscategory = false;
 if ($template == 'portal/portal_topic_content') {
     $template = gettopictplname($clonefile);
     $istopic = true;
 } elseif ($template == 'portal/list') {
     $template = getportalcategorytplname($clonefile);
     $iscategory = true;
 }
 $primaltplname = checkprimaltpl($template);
 if ($recover == '1') {
     $file = './data/diy/' . $targettplname . '.htm';
     if (is_file($file . '.bak')) {
         copy($file . '.bak', $file);
     } else {
         showmessage('diy_backup_noexist');
     }
 } else {
     $templatedata = array();
     checksecurity($_POST['spacecss']);
     $_POST['spacecss'] = dstripslashes($_POST['spacecss']);
     $templatedata['spacecss'] = preg_replace("/(\\<|\\>)/is", '', $_POST['spacecss']);
     $style = empty($_POST['style']) ? '' : preg_replace("/[^0-9a-z]/i", '', $_POST['style']);
     if ($style) {
         $cssfile = DISCUZ_ROOT . './static/topic/' . $style . '/style.css';