function attachtag($pid, $aid, &$postlist, $sidauth)
{
    global $attachrefcheck, $thumbstatus, $extcredits, $creditstrans, $creditstransextra, $ftp, $exthtml;
    $attach = $postlist[$pid]['attachments'][$aid];
    if ($attach['attachimg']) {
        $attachrefcheck = ($attachrefcheck || $attach['remote']) && !($attach['remote'] && substr($ftp['attachurl'], 0, 3) == 'ftp' && !$ftp['hideurl']);
    }
    return attachinpost($attach, $sidauth);
}
Example #2
0
function attachtag($pid, $aid, &$postlist)
{
    return attachinpost($postlist[$pid]['attachments'][$aid]);
}
Example #3
0
function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array())
{
    global $_G;
    if (!$attachpids) {
        return;
    }
    $attachpids = is_array($attachpids) ? $attachpids : array($attachpids);
    $attachexists = FALSE;
    $skipattachcode = $aids = $payaids = $findattach = array();
    foreach (C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $_G['tid'], 'pid', $attachpids) as $attach) {
        $attachexists = TRUE;
        if ($skipaids && in_array($attach['aid'], $skipaids)) {
            $skipattachcode[$attach[pid]][] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            continue;
        }
        $attached = 0;
        $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']);
        if ($attach['isimage'] && !$_G['setting']['attachimgpost']) {
            $attach['isimage'] = 0;
        }
        $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
        if ($attach['attachimg']) {
            $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
        }
        if ($attach['price']) {
            if ($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
                C::t('forum_attachment_n')->update('tid:' . $_G['tid'], $attach['aid'], array('price' => 0));
                $attach['price'] = 0;
            } elseif (!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
                $payaids[$attach['aid']] = $attach['pid'];
            }
        }
        $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['uid'] ? 1 : 0;
        $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'forum/';
        $attach['dbdateline'] = $attach['dateline'];
        $attach['dateline'] = dgmdate($attach['dateline'], 'u');
        $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
        if (!defined('IN_MOBILE_API') && !empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
            $findattach[$attach['pid']][$attach['aid']] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            $attached = 1;
        }
        if (!$attached) {
            if ($attach['isimage']) {
                $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
                $postlist[$attach['pid']]['imagelistcount']++;
                if ($postlist[$attach['pid']]['first']) {
                    $GLOBALS['firstimgs'][] = $attach['aid'];
                }
            } else {
                if (!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
                    $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
                }
            }
        }
        $aids[] = $attach['aid'];
    }
    if ($aids) {
        $attachs = C::t('forum_attachment')->fetch_all($aids);
        foreach ($attachs as $aid => $attach) {
            if ($postlist[$attach['pid']]) {
                $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
            }
        }
    }
    if ($payaids) {
        foreach (C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', array_keys($payaids)) as $creditlog) {
            $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
        }
    }
    if (!empty($skipattachcode)) {
        foreach ($skipattachcode as $pid => $findskipattach) {
            foreach ($findskipattach as $findskip) {
                $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
            }
        }
    }
    if ($attachexists) {
        foreach ($attachtags as $pid => $aids) {
            if ($findattach[$pid]) {
                foreach ($findattach[$pid] as $aid => $find) {
                    $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
                    $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
                }
            }
        }
    } else {
        loadcache('posttableids');
        $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
        foreach ($posttableids as $id) {
            C::t('forum_post')->update($id, $attachpids, array('attachment' => '0'), true);
        }
    }
}
function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array())
{
    global $_G;
    $query = DB::query("SELECT * FROM " . DB::table(getattachtablebytid($_G['tid'])) . " a WHERE a.pid IN ({$attachpids})");
    $attachexists = FALSE;
    $skipattachcode = $aids = $payaids = $findattach = array();
    while ($attach = DB::fetch($query)) {
        $attachexists = TRUE;
        if ($skipaids && in_array($attach['aid'], $skipaids)) {
            $skipattachcode[$attach[pid]][] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            continue;
        }
        $attached = 0;
        $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']);
        if ($attach['isimage'] && !$_G['setting']['attachimgpost']) {
            $attach['isimage'] = 0;
        }
        $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
        if ($attach['attachimg']) {
            $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
        }
        if ($attach['price']) {
            if ($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
                DB::query("UPDATE " . DB::table(getattachtablebytid($_G['tid'])) . " SET price='0' WHERE aid='{$attach['aid']}'");
                $attach['price'] = 0;
            } elseif (!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
                $payaids[$attach['aid']] = $attach['pid'];
            }
        }
        $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['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['aid']] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            $attached = 1;
        }
        if (!$attached) {
            if ($attach['isimage']) {
                $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
                $postlist[$attach['pid']]['imagelistcount']++;
                if ($postlist[$attach['pid']]['first']) {
                    $GLOBALS['firstimgs'][] = $attach['aid'];
                }
            } else {
                if (!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
                    $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
                }
            }
        }
        $aids[] = $attach['aid'];
    }
    if ($aids) {
        $query = DB::query("SELECT aid, pid, downloads FROM " . DB::table('forum_attachment') . " WHERE aid IN (" . dimplode($aids) . ")");
        while ($attach = DB::fetch($query)) {
            $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
        }
    }
    if ($payaids) {
        $query = DB::query("SELECT relatedid FROM " . DB::table('common_credit_log') . " WHERE relatedid IN (" . dimplode(array_keys($payaids)) . ") AND uid='{$_G['uid']}' AND operation='BAC'");
        while ($creditlog = DB::fetch($query)) {
            $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
        }
    }
    if (!empty($skipattachcode)) {
        foreach ($skipattachcode as $pid => $findskipattach) {
            foreach ($findskipattach as $findskip) {
                $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
            }
        }
    }
    if ($attachexists) {
        foreach ($attachtags as $pid => $aids) {
            if ($findattach[$pid]) {
                foreach ($findattach[$pid] as $aid => $find) {
                    $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]['first']), $postlist[$pid]['message'], 1);
                    $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
                }
            }
        }
    } else {
        updatepost(array('attachment' => '0'), "pid IN ({$attachpids})", true);
    }
}
function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array())
{
    global $_G;
    if (!$attachpids) {
        return;
    }
    $attachpids = is_array($attachpids) ? $attachpids : array($attachpids);
    $attachexists = FALSE;
    $skipattachcode = $aids = $payaids = $findattach = array();
    //start
    foreach (C::t('forum_attachment_n')->fetch_all_by_id('tid:' . $_G['tid'], 'pid', $attachpids) as $attach) {
        $attachexists = TRUE;
        if ($skipaids && in_array($attach['aid'], $skipaids)) {
            $skipattachcode[$attach[pid]][] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            continue;
        }
        $attached = 0;
        $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']);
        if ($attach['isimage'] && !$_G['setting']['attachimgpost']) {
            $attach['isimage'] = 0;
        }
        $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
        if ($attach['attachimg']) {
            $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
        }
        if ($attach['price']) {
            if ($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
                C::t('forum_attachment_n')->update('tid:' . $_G['tid'], $attach['aid'], array('price' => 0));
                $attach['price'] = 0;
            } elseif (!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
                $payaids[$attach['aid']] = $attach['pid'];
            }
        }
        $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['uid'] ? 1 : 0;
        $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'forum/';
        $attach['dbdateline'] = $attach['dateline'];
        $attach['dateline'] = dgmdate($attach['dateline'], 'u');
        $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
        if (!defined('IN_MOBILE_API') && !empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
            $findattach[$attach['pid']][$attach['aid']] = "/\\[attach\\]{$attach['aid']}\\[\\/attach\\]/i";
            $attached = 1;
        }
        if (!$attached) {
            if ($attach['isimage']) {
                $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
                $postlist[$attach['pid']]['imagelistcount']++;
                if ($postlist[$attach['pid']]['first']) {
                    $GLOBALS['firstimgs'][] = $attach['aid'];
                }
            } else {
                if (!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
                    $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
                }
            }
        }
        $aids[] = $attach['aid'];
    }
    //end
    if ($aids) {
        $attachs = C::t('forum_attachment')->fetch_all($aids);
        foreach ($attachs as $aid => $attach) {
            if ($postlist[$attach['pid']]) {
                $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
            }
        }
    }
    if ($payaids) {
        foreach (C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', array_keys($payaids)) as $creditlog) {
            $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
        }
    }
    if (!empty($skipattachcode)) {
        foreach ($skipattachcode as $pid => $findskipattach) {
            foreach ($findskipattach as $findskip) {
                $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
            }
        }
    }
    if ($attachexists) {
        foreach ($attachtags as $pid => $aids) {
            if ($findattach[$pid]) {
                foreach ($findattach[$pid] as $aid => $find) {
                    // 嵌入录像解析代码 by BangZ 20160202
                    //debug($postlist[$pid]['message']);
                    if (preg_match("/^cnc4replay\$|^ra3replay\$|^kwreplay\$|^cnc3replay\$|^rep\$|^rec\$\t/", $postlist[$pid]['attachments'][$aid]['ext'])) {
                        if (in_array('replay_tool', $_G['setting']['plugins']['available'])) {
                            //判断插件是否启用
                            @(include_once DISCUZ_ROOT . './source/plugin/replay_tool/core.func.php');
                            // showmessage(function_exists('resolve_replay'));
                            // debug($postlist[$pid]['attachments'][$aid]);
                            $aidencode = packaids($postlist[$pid]['attachments'][$aid]);
                            $is_archive = $_G['forum_thread']['is_archived'] ? '&fid=' . $_G['fid'] . '&archiveid=' . $_G[forum_thread][archiveid] : '';
                            $resolve = resolve_replay($aid, $postlist[$pid]['attachments'][$aid], $aidencode, $is_archive);
                            $postlist[$pid]['message'] = preg_replace($find, $resolve, $postlist[$pid]['message'], 1);
                            $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
                            continue;
                        }
                    }
                    //end
                    $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
                    $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
                }
            }
        }
    } else {
        loadcache('posttableids');
        $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
        foreach ($posttableids as $id) {
            C::t('forum_post')->update($id, $attachpids, array('attachment' => '0'), true);
        }
    }
}