showformfooter();
        } else {
            showsubtitle(array('block_name', 'block_script', 'block_style', 'block_dateline', 'block_page', 'operation'));
            $multipage = '';
            $count = DB::result(DB::query("SELECT COUNT(*) FROM " . DB::table('common_block') . " b LEFT JOIN " . DB::table('common_template_block') . " tb ON tb.bid=b.bid WHERE {$wheresql}"), 0);
            if ($count) {
                $query = DB::query("SELECT b.*, tb.targettplname FROM " . DB::table('common_block') . " b LEFT JOIN " . DB::table('common_template_block') . " tb ON b.bid=tb.bid WHERE {$wheresql} {$ordersql} LIMIT {$start},{$perpage}");
                while ($value = DB::fetch($query)) {
                    if ($value['targettplname']) {
                        $diyurl = block_getdiyurl($value['targettplname']);
                        $diyurl = $diyurl['url'];
                        $tplname = isset($_G['cache']['diytemplatename'][$value['targettplname']]) ? $_G['cache']['diytemplatename'][$value['targettplname']] : $value['targettplname'];
                        $diypage[$value['bid']][$value['targettplname']] = $diyurl ? '<a href="' . $diyurl . '" target="_blank">' . $tplname . '</a>' : $tplname;
                    }
                    $list[$value['bid']] = $value;
                }
                if ($list) {
                    foreach ($list as $bid => $value) {
                        $inpage = empty($diypage[$bid]) ? cplang('block_page_unused') : implode('<br/>', $diypage[$bid]);
                        $theclass = block_getclass($value['blockclass'], true);
                        showtablerow('', '', array($value['name'] ? $value['name'] : cplang('block_name_null'), $theclass['script'][$value['script']], $value['styleid'] ? $theclass['style'][$value['styleid']]['name'] : lang('portalcp', 'blockstyle_diy'), !empty($value['dateline']) ? dgmdate($value['dateline']) : cplang('block_dateline_null'), $inpage, "<a href=\"portal.php?mod=portalcp&ac=block&op=block&bid={$value['bid']}&from=cp\" target=\"_blank\" onclick=\"showWindow('showblock',this.href);return false;\">" . cplang('block_setting') . "</a> &nbsp;&nbsp" . "<a href=\"portal.php?mod=portalcp&ac=block&op=data&bid={$value['bid']}&from=cp\" target=\"_blank\" onclick=\"showWindow('showblock',this.href);return false;\">" . cplang('block_data') . "</a> &nbsp;&nbsp" . $diyop . "&nbsp;&nbsp;<a href=\"" . ADMINSCRIPT . "?action=block&operation=perm&bid={$value['bid']}\">" . cplang('portalcategory_perm') . '</a>'));
                    }
                }
                $multipage = multi($count, $perpage, $page, $mpurl);
            }
            showsubmit('', '', '', '<input type="submit" class="btn" name="clearsubmit" value="' . cplang('block_clear_unused') . '" />', $multipage);
            showtablefooter();
            showformfooter();
        }
    }
}
function formatblockvalue($value)
{
    global $blockfavorite;
    $value['name'] = empty($value['name']) ? '<strong>#' . $value['bid'] . '</strong>' : $value['name'];
    $theclass = block_getclass($value['blockclass']);
    $value['blockclassname'] = $theclass['name'];
    $value['datasrc'] = $theclass['script'][$value['script']];
    $value['isrecommendable'] = block_isrecommendable($value);
    $value['perm'] = formatblockpermissoin($value);
    $value['favorite'] = isset($blockfavorite[$value['bid']]) ? true : false;
    return $value;
}
if ($count) {
    require_once libfile('function/block');
    $query = DB::query($sql);
    while ($value = DB::fetch($query)) {
        if ($value['blocktype']) {
            $value['url'] = lang('portal/template', 'block_jscall');
        } else {
            $tplinfo = block_getdiyurl($value['targettplname']);
            if ($tplinfo['url']) {
                $value['url'] = lang('portal/template', 'block_view_link', array('url' => $tplinfo['url']));
            } else {
                $value['url'] = lang('portal/template', 'block_unused');
            }
        }
        $value['name'] = empty($value['name']) ? '#' . $value['bid'] : trim($value['name']);
        $theclass = block_getclass($value['blockclass']);
        $value['datasrc'] = $theclass['script'][$value['script']];
        $value['allowdata'] = checkperm('allowdiy') || $permission[$value['bid']]['allowdata'] ? true : false;
        $value['allowsetting'] = checkperm('allowdiy') || $permission[$value['bid']]['allowsetting'] ? true : false;
        $blocks[] = $value;
    }
    $multi = multi($count, $perpage, $page, "portal.php?mod=portalcp&ac=portalblock");
}
$language = lang('portal/template');
$navtitle = $language['block_management'] . ' - ' . $language['portal_management'];
include_once template("portal/portalcp_portalblock");
function getallowblock($uid)
{
    if (empty($uid)) {
        return false;
    }
Example #4
0
function block_template($bid)
{
    global $_G;
    $block = empty($_G['block'][$bid]) ? array() : $_G['block'][$bid];
    $theclass = block_getclass($block['blockclass'], false);
    $thestyle = !empty($block['styleid']) ? block_getstyle($block['styleid']) : dunserialize($block['blockstyle']);
    if (empty($block) || empty($theclass) || empty($thestyle)) {
        return false;
    }
    $template = block_build_template($thestyle['template']);
    if (!empty($block['itemlist'])) {
        if ($thestyle['moreurl']) {
            $template = str_replace('{moreurl}', 'portal.php?mod=block&bid=' . $bid, $template);
        }
        $fields = array('picwidth' => array(), 'picheight' => array(), 'target' => array(), 'currentorder' => array());
        if ($block['hidedisplay']) {
            $fields = array_merge($fields, $theclass['fields']);
        } else {
            $thestyle['fields'] = !empty($thestyle['fields']) && is_array($thestyle['fields']) ? $thestyle['fields'] : block_parse_fields($template);
            foreach ($thestyle['fields'] as $k) {
                if (isset($theclass['fields'][$k])) {
                    $fields[$k] = $theclass['fields'][$k];
                }
            }
        }
        $order = 0;
        $dynamicparts = array();
        foreach ($block['itemlist'] as $position => $blockitem) {
            $itemid = $blockitem['itemid'];
            $order++;
            $rkey = $rpattern = $rvalue = $rtpl = array();
            $rkeyplug = false;
            if (isset($thestyle['template']['index']) && is_array($thestyle['template']['index']) && isset($thestyle['template']['index'][$order])) {
                $rkey[] = 'index_' . $order;
                $rpattern[] = '/\\s*\\[index=' . $order . '\\](.*?)\\[\\/index\\]\\s*/is';
                $rvalue[] = '';
                $rtpl[] = $thestyle['template']['index'][$order];
            }
            if (empty($rkey)) {
                $rkey[] = 'loop';
                $rpattern[] = '/\\s*\\[loop\\](.*?)\\[\\/loop\\]\\s*/is';
                $rvalue[] = isset($dynamicparts['loop']) ? $dynamicparts['loop'][1] : '';
                if (is_array($thestyle['template']['order']) && isset($thestyle['template']['order'][$order])) {
                    $rtpl[] = $thestyle['template']['order'][$order];
                } elseif (is_array($thestyle['template']['order']) && isset($thestyle['template']['order']['odd']) && $order % 2 == 1) {
                    $rtpl[] = $thestyle['template']['order']['odd'];
                } elseif (is_array($thestyle['template']['order']) && isset($thestyle['template']['order']['even']) && $order % 2 == 0) {
                    $rtpl[] = $thestyle['template']['order']['even'];
                } else {
                    $rtpl[] = $thestyle['template']['loop'];
                }
            }
            if (!empty($thestyle['template']['indexplus'])) {
                foreach ($thestyle['template']['indexplus'] as $k => $v) {
                    if (isset($v[$order])) {
                        $rkey[] = 'index' . $k . '=' . $order;
                        $rkeyplug = true;
                        $rpattern[] = '/\\[index' . $k . '=' . $order . '\\](.*?)\\[\\/index' . $k . '\\]/is';
                        $rvalue[] = '';
                        $rtpl[] = $v[$order];
                    }
                }
            }
            if (empty($rkeyplug)) {
                if (!empty($thestyle['template']['loopplus'])) {
                    foreach ($thestyle['template']['loopplus'] as $k => $v) {
                        $rkey[] = 'loop' . $k;
                        $rpattern[] = '/\\s*\\[loop' . $k . '\\](.*?)\\[\\/loop' . $k . '\\]\\s*/is';
                        $rvalue[] = isset($dynamicparts['loop' . $k]) ? $dynamicparts['loop' . $k][1] : '';
                        if (is_array($thestyle['template']['orderplus'][$k]) && isset($thestyle['template']['orderplus'][$k][$order])) {
                            $rtpl[] = $thestyle['template']['orderplus'][$k][$order];
                        } elseif (is_array($thestyle['template']['orderplus'][$k]) && isset($thestyle['template']['orderplus'][$k]['odd']) && $order % 2 == 1) {
                            $rtpl[] = $thestyle['template']['orderplus'][$k]['odd'];
                        } elseif (is_array($thestyle['template']['orderplus'][$k]) && isset($thestyle['template']['orderplus'][$k]['even']) && $order % 2 == 0) {
                            $rtpl[] = $thestyle['template']['orderplus'][$k]['even'];
                        } else {
                            $rtpl[] = $thestyle['template']['loopplus'][$k];
                        }
                    }
                }
            }
            $blockitem['fields'] = !empty($blockitem['fields']) ? $blockitem['fields'] : array();
            $blockitem['fields'] = is_array($blockitem['fields']) ? $blockitem['fields'] : dunserialize($blockitem['fields']);
            if (!empty($blockitem['showstyle'])) {
                $blockitem['fields']['showstyle'] = dunserialize($blockitem['showstyle']);
            }
            isset($blockitem['fields']['lastpost']) && ($block['dateuformat'] = 'u');
            $blockitem = $blockitem['fields'] + $blockitem;
            $blockitem['picwidth'] = !empty($block['picwidth']) ? intval($block['picwidth']) : 'auto';
            $blockitem['picheight'] = !empty($block['picheight']) ? intval($block['picheight']) : 'auto';
            $blockitem['target'] = !empty($block['target']) ? ' target="_' . $block['target'] . '"' : '';
            $blockitem['currentorder'] = $order;
            $blockitem['parity'] = $order % 2;
            $searcharr = $replacearr = array();
            $searcharr[] = '{parity}';
            $replacearr[] = $blockitem['parity'];
            foreach ($fields as $key => $field) {
                $replacevalue = $blockitem[$key];
                $field['datatype'] = !empty($field['datatype']) ? $field['datatype'] : '';
                if ($field['datatype'] == 'int') {
                    // int
                    $replacevalue = intval($replacevalue);
                } elseif ($field['datatype'] == 'string') {
                    $replacevalue = preg_quote($replacevalue);
                } elseif ($field['datatype'] == 'date') {
                    $replacevalue = dgmdate($replacevalue, $block['dateuformat'] ? 'u' : $block['dateformat'], '9999', $block['dateuformat'] ? $block['dateformat'] : '');
                } elseif ($field['datatype'] == 'title') {
                    //title
                    $searcharr[] = '{title-title}';
                    $replacearr[] = preg_quote(!empty($blockitem['fields']['fulltitle']) ? $blockitem['fields']['fulltitle'] : dhtmlspecialchars($replacevalue));
                    $searcharr[] = '{alt-title}';
                    $replacearr[] = preg_quote(!empty($blockitem['fields']['fulltitle']) ? $blockitem['fields']['fulltitle'] : dhtmlspecialchars($replacevalue));
                    $replacevalue = preg_quote($replacevalue);
                    if ($blockitem['showstyle'] && ($style = block_showstyle($blockitem['showstyle'], 'title'))) {
                        $replacevalue = '<font style="' . $style . '">' . $replacevalue . '</font>';
                    }
                } elseif ($field['datatype'] == 'summary') {
                    //summary
                    $replacevalue = preg_quote($replacevalue);
                    if ($blockitem['showstyle'] && ($style = block_showstyle($blockitem['showstyle'], 'summary'))) {
                        $replacevalue = '<font style="' . $style . '">' . $replacevalue . '</font>';
                    }
                } elseif ($field['datatype'] == 'pic') {
                    if ($blockitem['picflag'] == '1') {
                        $replacevalue = $_G['setting']['attachurl'] . $replacevalue;
                    } elseif ($blockitem['picflag'] == '2') {
                        $replacevalue = $_G['setting']['ftp']['attachurl'] . $replacevalue;
                    }
                    if ($blockitem['picflag'] && $block['picwidth'] && $block['picheight'] && $block['picwidth'] != 'auto' && $block['picheight'] != 'auto') {
                        if ($blockitem['makethumb'] == 1) {
                            if ($blockitem['picflag'] == '1') {
                                $replacevalue = $_G['setting']['attachurl'] . $blockitem['thumbpath'];
                            } elseif ($blockitem['picflag'] == '2') {
                                $replacevalue = $_G['setting']['ftp']['attachurl'] . $blockitem['thumbpath'];
                            }
                        } elseif (!$_G['block_makethumb'] && !$blockitem['makethumb']) {
                            C::t('common_block_item')->update($itemid, array('makethumb' => 2));
                            require_once libfile('class/image');
                            $image = new image();
                            $thumbpath = block_thumbpath($block, $blockitem);
                            if ($_G['setting']['ftp']['on']) {
                                $ftp =& discuz_ftp::instance();
                                $ftp->connect();
                                if ($ftp->connectid && $ftp->ftp_size($thumbpath) > 0 || ($return = $image->Thumb($replacevalue, $thumbpath, $block['picwidth'], $block['picheight'], 2) && $ftp->upload($_G['setting']['attachurl'] . '/' . $thumbpath, $thumbpath))) {
                                    $picflag = 1;
                                    //common_block_pic表中的picflag标识(0本地,1远程)
                                    $_G['block_makethumb'] = true;
                                    @unlink($_G['setting']['attachdir'] . './' . $thumbpath);
                                }
                            } elseif (file_exists($_G['setting']['attachdir'] . $thumbpath) || ($return = $image->Thumb($replacevalue, $thumbpath, $block['picwidth'], $block['picheight'], 2))) {
                                $picflag = 0;
                                //common_block_pic表中的picflag标识(0本地,1远程)
                                $_G['block_makethumb'] = true;
                            }
                            if ($_G['block_makethumb']) {
                                C::t('common_block_item')->update($itemid, array('makethumb' => 1, 'thumbpath' => $thumbpath));
                                C::t('common_block')->clear_cache($block['bid']);
                                $thumbdata = array('bid' => $block['bid'], 'itemid' => $itemid, 'pic' => $thumbpath, 'picflag' => $picflag, 'type' => '0');
                                C::t('common_block_pic')->insert($thumbdata);
                            }
                        }
                    }
                }
                $searcharr[] = '{' . $key . '}';
                $replacearr[] = $replacevalue;
                if ($block['hidedisplay']) {
                    if (strpos($replacevalue, "\\") !== false) {
                        $replacevalue = str_replace(array('\\.', '\\\\', '\\+', '\\*', '\\?', '\\[', '\\^', '\\]', '\\$', '\\(', '\\)', '\\{', '\\}', '\\=', '\\!', '\\<', '\\>', '\\|', '\\:', '\\-'), array('.', '\\', '+', '*', '?', '[', '^', ']', '$', '(', ')', '{', '}', '=', '!', '<', '>', '|', ':', '-'), $replacevalue);
                    }
                    $_G['block_' . $bid][$order - 1][$key] = $replacevalue;
                }
            }
            foreach ($rtpl as $k => $str_template) {
                if ($str_template) {
                    $str_template = preg_replace('/title=[\'"]{title}[\'"]/', 'title="{title-title}"', $str_template);
                    $str_template = preg_replace('/alt=[\'"]{title}[\'"]/', 'alt="{alt-title}"', $str_template);
                    $rvalue[$k] .= str_replace($searcharr, $replacearr, $str_template);
                    $dynamicparts[$rkey[$k]] = array($rpattern[$k], $rvalue[$k]);
                }
            }
        }
        // foreach($block['itemlist'] as $itemid=>$blockitem) {
        foreach ($dynamicparts as $value) {
            $template = preg_replace($value[0], $value[1], $template);
        }
        $template = str_replace('\\', '&#92;', stripslashes($template));
    }
    $template = preg_replace('/\\s*\\[(order\\d*)=\\w+\\](.*?)\\[\\/\\1\\]\\s*/is', '', $template);
    $template = preg_replace('/\\s*\\[(index\\d*)=\\w+\\](.*?)\\[\\/\\1\\]\\s*/is', '', $template);
    $template = preg_replace('/\\s*\\[(loop\\d{0,1})\\](.*?)\\[\\/\\1\\]\\s*/is', '', $template);
    return $template;
}
    $block['moreurl'] = $blockstyle['moreurl'] && in_array($block['blockclass'], array('forum_thread', 'portal_article', 'group_thread'), true) ? 1 : 0;
    $_G['block'][$bid] = $block;
    $blockperm = getblockperm($bid);
    if ($blockperm['allowmanage']) {
        $allowmanage = 1;
        $allowdata = 1;
    }
    if ($blockperm['allowrecommend'] && !$blockperm['needverify']) {
        $allowdata = 1;
    }
}
if (empty($block['bid'])) {
    $bid = 0;
}
$_GET['classname'] = !empty($_GET['classname']) ? $_GET['classname'] : ($block ? $block['blockclass'] : 'html_html');
$theclass = block_getclass($_GET['classname'], true);
$theclass['script'] = isset($theclass['script']) ? $theclass['script'] : array();
if (!empty($_GET['styleid']) && isset($theclass['style'][$_GET['styleid']])) {
    $thestyle = $theclass['style'][$_GET['styleid']];
} elseif (isset($theclass['style'][$block['styleid']])) {
    $_GET['styleid'] = intval($block['styleid']);
    $thestyle = $theclass['style'][$_GET['styleid']];
} else {
    $_GET['styleid'] = 0;
    $thestyle = (array) dunserialize($block['blockstyle']);
}
$_GET['script'] = !empty($_GET['script']) && isset($theclass['script'][$_GET['script']]) ? $_GET['script'] : (!empty($block['script']) ? $block['script'] : key($theclass['script']));
$blocktype = !empty($_GET['blocktype']) || !empty($block['blocktype']) ? 1 : 0;
$nocachetime = in_array($_GET['script'], array('blank', 'line', 'banner', 'vedio', 'google')) ? true : false;
$is_htmlblock = $_GET['classname'] == 'html_html' ? 1 : 0;
$showhtmltip = false;
Example #6
0
function block_template($bid)
{
    global $_G;
    $block = empty($_G['block'][$bid]) ? array() : $_G['block'][$bid];
    $theclass = block_getclass($block['blockclass'], false);
    $thestyle = !empty($block['styleid']) ? block_getstyle($block['styleid']) : unserialize($block['blockstyle']);
    if (empty($block) || empty($theclass) || empty($thestyle)) {
        return;
    }
    $template = block_build_template($thestyle['template']);
    if (!empty($block['itemlist'])) {
        $fields = array('picwidth' => array(), 'picheight' => array(), 'target' => array(), 'currentorder' => array());
        if ($block['hidedisplay']) {
            $fields = array_merge($fields, $theclass['fields']);
        } else {
            $thestyle['fields'] = !empty($thestyle['fields']) && is_array($thestyle['fields']) ? $thestyle['fields'] : block_parse_fields($template);
            foreach ($thestyle['fields'] as $k) {
                if (isset($theclass['fields'][$k])) {
                    $fields[$k] = $theclass['fields'][$k];
                }
            }
        }
        $order = 0;
        $dynamicparts = array();
        foreach ($block['itemlist'] as $itemid => $blockitem) {
            $order++;
            $rkey = $rpattern = $rvalue = $rtpl = array();
            $rkeyplug = false;
            if (isset($thestyle['template']['index']) && is_array($thestyle['template']['index']) && isset($thestyle['template']['index'][$order])) {
                $rkey[] = 'index_' . $order;
                $rpattern[] = '/\\s*\\[index=' . $order . '\\](.*?)\\[\\/index\\]\\s*/is';
                $rvalue[] = '';
                $rtpl[] = $thestyle['template']['index'][$order];
            }
            if (empty($rkey)) {
                $rkey[] = 'loop';
                $rpattern[] = '/\\s*\\[loop\\](.*?)\\[\\/loop\\]\\s*/is';
                $rvalue[] = isset($dynamicparts['loop']) ? $dynamicparts['loop'][1] : '';
                if (is_array($thestyle['template']['order']) && isset($thestyle['template']['order'][$order])) {
                    $rtpl[] = $thestyle['template']['order'][$order];
                } elseif (is_array($thestyle['template']['order']) && isset($thestyle['template']['order']['odd']) && $order % 2 == 1) {
                    $rtpl[] = $thestyle['template']['order']['odd'];
                } elseif (is_array($thestyle['template']['order']) && isset($thestyle['template']['order']['even']) && $order % 2 == 0) {
                    $rtpl[] = $thestyle['template']['order']['even'];
                } else {
                    $rtpl[] = $thestyle['template']['loop'];
                }
            }
            if (!empty($thestyle['template']['indexplus'])) {
                foreach ($thestyle['template']['indexplus'] as $k => $v) {
                    if (isset($v[$order])) {
                        $rkey[] = 'index' . $k . '=' . $order;
                        $rkeyplug = true;
                        $rpattern[] = '/\\[index' . $k . '=' . $order . '\\](.*?)\\[\\/index' . $k . '\\]/is';
                        $rvalue[] = '';
                        $rtpl[] = $v[$order];
                    }
                }
            }
            if (empty($rkeyplug)) {
                if (!empty($thestyle['template']['loopplus'])) {
                    foreach ($thestyle['template']['loopplus'] as $k => $v) {
                        $rkey[] = 'loop' . $k;
                        $rpattern[] = '/\\s*\\[loop' . $k . '\\](.*?)\\[\\/loop' . $k . '\\]\\s*/is';
                        $rvalue[] = isset($dynamicparts['loop' . $k]) ? $dynamicparts['loop' . $k][1] : '';
                        if (is_array($thestyle['template']['orderplus'][$k]) && isset($thestyle['template']['orderplus'][$k][$order])) {
                            $rtpl[] = $thestyle['template']['orderplus'][$k][$order];
                        } elseif (is_array($thestyle['template']['orderplus'][$k]) && isset($thestyle['template']['orderplus'][$k]['odd']) && $order % 2 == 1) {
                            $rtpl[] = $thestyle['template']['order' . $k]['odd'];
                        } elseif (is_array($thestyle['template']['orderplus'][$k]) && isset($thestyle['template']['orderplus'][$k]['even']) && $order % 2 == 0) {
                            $rtpl[] = $thestyle['template']['orderplus'][$k]['even'];
                        } else {
                            $rtpl[] = $thestyle['template']['loopplus'][$k];
                        }
                    }
                }
            }
            $blockitem['fields'] = !empty($blockitem['fields']) ? $blockitem['fields'] : array();
            $blockitem['fields'] = is_array($blockitem['fields']) ? $blockitem['fields'] : unserialize($blockitem['fields']);
            $blockitem['showstyle'] = !empty($blockitem['showstyle']) ? unserialize($blockitem['showstyle']) : array();
            $blockitem['showstyle'] = !empty($blockitem['showstyle']) ? $blockitem['showstyle'] : (!empty($blockitem['fields']['showstyle']) ? $blockitem['fields']['showstyle'] : array());
            $blockitem['picwidth'] = !empty($block['picwidth']) ? intval($block['picwidth']) : 'auto';
            $blockitem['picheight'] = !empty($block['picheight']) ? intval($block['picheight']) : 'auto';
            $blockitem['target'] = !empty($block['target']) ? ' target="_' . $block['target'] . '"' : '';
            $blockitem['currentorder'] = $order;
            $blockitem['parity'] = $order % 2;
            $searcharr = $replacearr = array();
            $searcharr[] = '{parity}';
            $replacearr[] = $blockitem['parity'];
            foreach ($fields as $key => $field) {
                $replacevalue = isset($blockitem[$key]) ? $blockitem[$key] : (isset($blockitem['fields'][$key]) ? $blockitem['fields'][$key] : '');
                $field['datatype'] = !empty($field['datatype']) ? $field['datatype'] : '';
                if ($field['datatype'] == 'int') {
                    // int
                    $replacevalue = intval($replacevalue);
                } elseif ($field['datatype'] == 'string') {
                    $replacevalue = $replacevalue;
                } elseif ($field['datatype'] == 'date') {
                    $replacevalue = dgmdate($replacevalue, $block['dateuformat'] ? 'u' : $block['dateformat'], '9999', $block['dateuformat'] ? $block['dateformat'] : '');
                } elseif ($field['datatype'] == 'title') {
                    //title
                    $replacevalue = stripslashes($replacevalue);
                    $searcharr[] = '{title-title}';
                    $replacearr[] = !empty($blockitem['fields']['fulltitle']) ? $blockitem['fields']['fulltitle'] : htmlspecialchars($replacevalue);
                    $searcharr[] = '{alt-title}';
                    $replacearr[] = !empty($blockitem['fields']['fulltitle']) ? $blockitem['fields']['fulltitle'] : htmlspecialchars($replacevalue);
                    if ($blockitem['showstyle'] && ($style = block_showstyle($blockitem['showstyle'], 'title'))) {
                        $replacevalue = '<font style="' . $style . '">' . $replacevalue . '</font>';
                    }
                } elseif ($field['datatype'] == 'summary') {
                    //summary
                    $replacevalue = stripslashes($replacevalue);
                    if ($blockitem['showstyle'] && ($style = block_showstyle($blockitem['showstyle'], 'summary'))) {
                        $replacevalue = '<font style="' . $style . '">' . $replacevalue . '</font>';
                    }
                } elseif ($field['datatype'] == 'pic') {
                    if ($blockitem['picflag'] == '1') {
                        $replacevalue = $_G['setting']['attachurl'] . $replacevalue;
                    } elseif ($blockitem['picflag'] == '2') {
                        $replacevalue = $_G['setting']['ftp']['attachurl'] . $replacevalue;
                    }
                    if ($blockitem['picflag'] && $block['picwidth'] && $block['picheight'] && $block['picwidth'] != 'auto' && $block['picheight'] != 'auto') {
                        if ($blockitem['makethumb'] == 1) {
                            if ($blockitem['picflag'] == '1') {
                                $replacevalue = $_G['setting']['attachurl'] . $blockitem['thumbpath'];
                            } elseif ($blockitem['picflag'] == '2') {
                                $replacevalue = $_G['setting']['ftp']['attachurl'] . $blockitem['thumbpath'];
                            }
                        } elseif (!$_G['block_makethumb'] && !$blockitem['makethumb']) {
                            $where = array('itemid' => $blockitem['itemid']);
                            DB::update('common_block_item', array('makethumb' => 2), $where);
                            require_once libfile('class/image');
                            $image = new image();
                            $thumbpath = block_thumbpath($block, $blockitem);
                            if ($_G['setting']['ftp']['on']) {
                                require_once libfile('class/ftp');
                                $ftp =& discuz_ftp::instance();
                                $ftp->connect();
                                if ($ftp->connectid && $ftp->ftp_size($thumbpath) > 0 || ($return = $image->Thumb($replacevalue, $thumbpath, $block['picwidth'], $block['picheight'], 2) && $ftp->upload($_G['setting']['attachurl'] . '/' . $thumbpath, $thumbpath))) {
                                    /*vot*/
                                    $picflag = 1;
                                    //common_block_pic table: picflag identity (0 = local, 1 = remote)
                                    $_G['block_makethumb'] = true;
                                    @unlink($_G['setting']['attachdir'] . './' . $thumbpath);
                                }
                            } elseif (file_exists($_G['setting']['attachdir'] . $thumbpath) || ($return = $image->Thumb($replacevalue, $thumbpath, $block['picwidth'], $block['picheight'], 2))) {
                                /*vot*/
                                $picflag = 0;
                                //common_block_pic table: picflag identity (0 = local, 1 = remote)
                                $_G['block_makethumb'] = true;
                            }
                            if ($_G['block_makethumb']) {
                                DB::update('common_block_item', array('makethumb' => 1, 'thumbpath' => $thumbpath), $where);
                                $thumbdata = array('bid' => $block['bid'], 'itemid' => $blockitem['itemid'], 'pic' => $thumbpath, 'picflag' => $picflag, 'type' => '0');
                                DB::insert('common_block_pic', $thumbdata);
                            }
                        }
                    }
                }
                $searcharr[] = '{' . $key . '}';
                $replacearr[] = $replacevalue;
                if ($block['hidedisplay']) {
                    $_G['block_' . $bid][$order - 1][$key] = $replacevalue;
                }
            }
            foreach ($rtpl as $k => $str_template) {
                if ($str_template) {
                    $str_template = preg_replace('/title=[\'"]{title}[\'"]/', 'title="{title-title}"', $str_template);
                    $str_template = preg_replace('/alt=[\'"]{title}[\'"]/', 'alt="{alt-title}"', $str_template);
                    $rvalue[$k] .= str_replace($searcharr, $replacearr, $str_template);
                    $dynamicparts[$rkey[$k]] = array($rpattern[$k], $rvalue[$k]);
                }
            }
        }
        // foreach($block['itemlist'] as $itemid=>$blockitem) {
        foreach ($dynamicparts as $value) {
            $template = stripslashes(preg_replace($value[0], preg_quote($value[1]), $template));
        }
    }
    $template = preg_replace('/\\s*\\[(order\\d{0,1})=\\w+\\](.*?)\\[\\/\\1\\]\\s*/is', '', $template);
    $template = preg_replace('/\\s*\\[(index\\d{0,1})=\\w+\\](.*?)\\[\\/\\1\\]\\s*/is', '', $template);
    $template = preg_replace('/\\s*\\[(loop\\d{0,1})\\](.*?)\\[\\/\\1\\]\\s*/is', '', $template);
    return $template;
}
Example #7
0
function block_template($bid)
{
    global $_G;
    $block = empty($_G['block'][$bid]) ? array() : $_G['block'][$bid];
    $theclass = block_getclass($block['blockclass']);
    // for short
    $thestyle = $theclass['style'][$block['styleid']];
    // for short
    if (empty($block) || empty($theclass) || empty($thestyle)) {
        return;
    }
    $template = '';
    if ($block['itemlist']) {
        $template = $thestyle['template']['header'];
        $order = 0;
        foreach ($block['itemlist'] as $blockitem) {
            $order++;
            if (isset($thestyle['template']['order'][$order])) {
                $theteamplte = $thestyle['template']['order'][$order];
            } else {
                $theteamplte = $thestyle['template']['loop'];
            }
            $blockitem['showstyle'] = !empty($blockitem['showstyle']) ? unserialize($blockitem['showstyle']) : array();
            $blockitem['fields'] = !empty($blockitem['fields']) ? $blockitem['fields'] : array();
            $blockitem['fields'] = is_array($blockitem['fields']) ? $blockitem['fields'] : unserialize($blockitem['fields']);
            $blockitem['picwidth'] = !empty($block['picwidth']) ? intval($block['picwidth']) : 'auto';
            $blockitem['picheight'] = !empty($block['picheight']) ? intval($block['picheight']) : 'auto';
            $blockitem['target'] = !empty($block['target']) ? ' target="_' . $block['target'] . '"' : '';
            $fields = array('picwidth' => array(), 'picheight' => array(), 'target' => array());
            $fields = array_merge($fields, $theclass['fields']);
            $searcharr = $replacearr = array();
            foreach ($fields as $key => $field) {
                $replacevalue = isset($blockitem[$key]) ? $blockitem[$key] : (isset($blockitem['fields'][$key]) ? $blockitem['fields'][$key] : '');
                $field['datatype'] = !empty($field['datatype']) ? $field['datatype'] : '';
                if ($field['datatype'] == 'int') {
                    // int
                    $replacevalue = intval($replacevalue);
                } elseif ($field['datatype'] == 'string') {
                    $replacevalue = dhtmlspecialchars($replacevalue);
                } elseif ($field['datatype'] == 'date') {
                    $replacevalue = dgmdate($replacevalue, 'u');
                } elseif ($field['datatype'] == 'title') {
                    //title
                    $replacevalue = stripslashes($replacevalue);
                    $style = block_showstyle($blockitem['showstyle'], 'title');
                    if ($style) {
                        $theteamplte = preg_replace('/title=[\'"]{title}[\'"]/', 'title="{title-title}"', $theteamplte);
                        $theteamplte = preg_replace('/alt=[\'"]{title}[\'"]/', 'alt="{alt-title}"', $theteamplte);
                        $searcharr[] = '{title-title}';
                        $replacearr[] = $replacevalue;
                        $searcharr[] = '{alt-title}';
                        $replacearr[] = $replacevalue;
                        $replacevalue = '<font style="' . $style . '">' . $replacevalue . '</font>';
                    }
                } elseif ($field['datatype'] == 'summary') {
                    //summary
                    $replacevalue = stripslashes($replacevalue);
                    $style = block_showstyle($blockitem['showstyle'], 'summary');
                    if ($style) {
                        $replacevalue = htmlspecialchars($replacevalue);
                        $replacevalue = '<font style="' . $style . '">' . $replacevalue . '</font>';
                    }
                } elseif ($field['datatype'] == 'pic') {
                    if ($blockitem['picflag'] == '1') {
                        $replacevalue = $_G['setting']['attachurl'] . $replacevalue;
                    } elseif ($blockitem['picflag'] == '2') {
                        $replacevalue = $_G['setting']['ftp']['attachurl'] . $replacevalue;
                    }
                    if ($block['picwidth'] && $block['picheight'] && $block['picwidth'] != 'auto' && $block['picheight'] != 'auto') {
                        if ($blockitem['makethumb'] == 1) {
                            $replacevalue = $_G['setting']['attachurl'] . block_thumbpath($block, $blockitem);
                        } elseif (!$_G['block_makethumb'] && !$blockitem['makethumb']) {
                            require_once libfile('class/image');
                            $image = new image();
                            $thumbpath = block_thumbpath($block, $blockitem);
                            $return = $image->Thumb($replacevalue, $thumbpath, $block['picwidth'], $block['picheight'], 2);
                            if ($return) {
                                DB::update('common_block_item', array('makethumb' => 1), array('itemid' => $blockitem['itemid']));
                                $replacevalue = $_G['setting']['attachurl'] . $thumbpath;
                            } else {
                                DB::update('common_block_item', array('makethumb' => 2), array('itemid' => $blockitem['itemid']));
                            }
                            $_G['block_makethumb'] = true;
                        }
                    }
                }
                $searcharr[] = '{' . $key . '}';
                $replacearr[] = $replacevalue;
            }
            $template .= str_replace($searcharr, $replacearr, $theteamplte);
        }
        $template .= $thestyle['template']['footer'];
    }
    return $template;
}
Example #8
0
if ($bid && !$allowmanage) {
    $blockpermission = DB::fetch_first('SELECT * FROM ' . DB::table('common_block_permission') . " WHERE bid='{$bid}' AND uid='{$_G['uid']}'");
    $blockdataperm = $blockpermission && $blockpermission['allowdata'] ? true : false;
    $blocksettingperm = $blockpermission && $blockpermission['allowsetting'] ? true : false;
    if ($blockdataperm || $blocksettingperm) {
        $allowmanage = 1;
    }
} else {
    $blockdataperm = $blocksettingperm = true;
}
$block['param'] = empty($block['param']) ? array() : unserialize($block['param']);
if (empty($block['bid'])) {
    $bid = 0;
}
$_GET['classname'] = !empty($_GET['classname']) ? $_GET['classname'] : ($block ? $block['blockclass'] : 'html_html');
$theclass = block_getclass($_GET['classname']);
$theclass['style'] = isset($theclass['style']) ? $theclass['style'] : array();
$theclass['script'] = isset($theclass['script']) ? $theclass['script'] : array();
$_GET['styleid'] = !empty($_GET['styleid']) && isset($theclass['style'][$_GET['styleid']]) ? $_GET['styleid'] : (!empty($block['styleid']) ? $block['styleid'] : key($theclass['style']));
$thestyle = $theclass['style'][$_GET['styleid']];
$_GET['script'] = !empty($_GET['script']) && isset($theclass['script'][$_GET['script']]) ? $_GET['script'] : (!empty($block['script']) ? $block['script'] : key($theclass['script']));
$is_htmlblock = $_GET['classname'] == 'html_html' ? 1 : 0;
$nocachetime = in_array($_GET['script'], array('blank', 'line', 'banner', 'vedio', 'google')) ? true : false;
$blocktype = !empty($_GET['blocktype']) || !empty($block['blocktype']) ? 1 : 0;
if ($op == 'block') {
    if ($bid && !$allowmanage) {
        showmessage('block_edit_nopermission');
    }
    if (!$bid) {
        list($tpl, $id) = explode(':', $_GET['tpl']);
        if (trim($tpl) == 'portal/portal_topic_content') {