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('\\', '\', 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; }
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; }
exit('Access Denied'); } include_once libfile('function/block'); $oparr = array('block', 'data', 'style', 'itemdata', 'setting', 'remove', 'item', 'additem', 'blockclass', 'getblock', 'thumbsetting', 'push', 'recommend', 'verifydata', 'managedata', 'saveblockclassname', 'saveblocktitle', 'convert', 'favorite', 'banids', 'delrecommend', 'moreurl'); $op = in_array($_GET['op'], $oparr, true) ? $_GET['op'] : 'block'; $_GET['from'] = $_GET['from'] == 'cp' ? 'cp' : null; $allowmanage = $allowdata = 0; $block = array(); $bid = !empty($_GET['bid']) ? intval($_GET['bid']) : 0; if ($bid) { if (!($block = C::t('common_block')->fetch($bid))) { showmessage('block_not_exist'); } $blockstyle = array(); if (!empty($block['styleid'])) { $blockstyle = block_getstyle($block['styleid']); } else { $blockstyle = dunserialize($block['blockstyle']); } $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'])) {
if ($_GET['styleid']) { $styleid = intval($_GET['styleid']); DB::update('common_block_style', $arr, array('styleid' => $styleid)); $msg = 'blockstyle_edit_succeed'; } else { $styleid = DB::insert('common_block_style', $arr, true); $msg = 'blockstyle_create_succeed'; } require_once libfile('function/cache'); updatecache('blockclass'); cpmsg($msg, 'action=blockstyle&operation=edit&blockclass=' . $_GET[blockclass] . '&styleid=' . $styleid . '&preview=' . ($_POST['preview'] ? '1' : '0'), 'succeed'); } if ($_GET['styleid']) { $_GET['styleid'] = intval($_GET['styleid']); include_once libfile('function/block'); $thestyle = block_getstyle($_GET['styleid']); if (!$thestyle) { cpmsg('blockstyle_not_found!'); } $thestyle['template'] = block_build_template($thestyle['template']); $_GET['blockclass'] = $thestyle['blockclass']; } else { $_GET['styleid'] = 0; $thestyle = array('template' => "<div class=\"module cl\">\n<ul>\n[loop]\n\t<li><a href=\"{url}\"{target}>{title}</a></li>\n[/loop]\n</ul>\n</div>"); } $theclass = block_getclass($_GET['blockclass']); if ($preview) { echo '<h4 style="margin-bottom:15px;">' . lang('preview') . '</h4>' . $preview; } showformheader('blockstyle&operation=' . $operation . '&blockclass=' . $_GET['blockclass'] . '&styleid=' . $_GET['styleid']); jsinsertunit();