function blockclass_cache() { global $_G; $data = $dirs = $styles = $dataconvert = array(); $dir = DISCUZ_ROOT . '/source/class/block/'; $dh = opendir($dir); while ($filename = readdir($dh)) { if (is_dir($dir . $filename) && substr($filename, 0, 1) != '.') { $dirs[$filename] = $dir . $filename . '/'; } } ksort($dirs); foreach ($dirs as $name => $dir) { $blockclass = $blockconvert = array(); if (file_exists($dir . 'blockclass.php')) { include_once $dir . 'blockclass.php'; } if (empty($blockclass['name'])) { $blockclass['name'] = $name; } else { $blockclass['name'] = dhtmlspecialchars($blockclass['name']); } $blockclass['subs'] = array(); $dh = opendir($dir); while ($filename = readdir($dh)) { $match = $infos = $oneinfo = $fieldsconvert = array(); $scriptname = $scriptclass = ''; if (preg_match('/^(block_[\\w]+)\\.php$/i', $filename, $match)) { $scriptclass = $match[1]; $scriptname = preg_replace('/^block_/i', '', $scriptclass); include_once $dir . $filename; if (class_exists($scriptclass, false)) { $obj = new $scriptclass(); if (method_exists($obj, 'name') && method_exists($obj, 'blockclass') && method_exists($obj, 'fields') && method_exists($obj, 'getsetting') && method_exists($obj, 'getdata')) { if ($scriptclass == 'block_xml') { foreach ($obj->blockdata as $one) { $oneinfo['name'] = dhtmlspecialchars($one['data']['name']); $oneinfo['blockclass'] = array($one['id'], $oneinfo['name']); $oneinfo['fields'] = dhtmlspecialchars($one['data']['fields']); foreach ($one['data']['style'] as $value) { $arr = array('blockclass' => 'xml_' . $one['id'], 'name' => dhtmlspecialchars($value['name'])); block_parse_template($value['template'], $arr); $styles[$arr['hash']] = $arr; } $infos[] = $oneinfo; } } else { $oneinfo['name'] = $obj->name(); $oneinfo['blockclass'] = $obj->blockclass(); $oneinfo['fields'] = $obj->fields(); $infos[] = $oneinfo; } } if (method_exists($obj, 'fieldsconvert')) { $fieldsconvert = $obj->fieldsconvert(); } } } foreach ($infos as $info) { if ($info['name'] && is_array($info['blockclass']) && $info['blockclass'][0] && $info['blockclass'][1]) { list($key, $title) = $info['blockclass']; $key = $name . '_' . $key; if (!isset($blockclass['subs'][$key])) { $blockclass['subs'][$key] = array('name' => $title, 'fields' => $info['fields'], 'script' => array()); } $blockclass['subs'][$key]['script'][$scriptname] = $info['name']; if (!isset($blockconvert[$key]) && !empty($fieldsconvert)) { $blockconvert[$key] = $fieldsconvert; } } } } if ($blockclass['subs']) { $data[$name] = $blockclass; $blockstyle = array(); if (file_exists($dir . 'blockstyle.php')) { include_once $dir . 'blockstyle.php'; } if ($blockstyle) { foreach ($blockstyle as $value) { $arr = array('blockclass' => $name . '_' . $value['blockclass'], 'name' => $value['name']); block_parse_template($value['template'], $arr); $styles[$arr['hash']] = $arr; } } } if (!empty($blockconvert)) { $dataconvert[$name] = $blockconvert; } } if ($styles) { $hashes = array_keys($styles); foreach (C::t('common_block_style')->fetch_all_by_hash($hashes) as $value) { unset($styles[$value['hash']]); } if ($styles) { C::t('common_block_style')->insert_batch($styles); } } savecache('blockclass', $data); savecache('blockconvert', $dataconvert); }
unset($itemlist[$key]); } } } } $block['param']['bannedids'] = !empty($block['param']['bannedids']) ? $block['param']['bannedids'] : ''; } elseif ($op == 'style') { if (!$bid || !$allowmanage) { showmessage('block_edit_nopermission'); } if (submitcheck('stylesubmit')) { $_POST['name'] = trim($_POST['name']); $arr = array('name' => $_POST['name'], 'blockclass' => $_GET['classname']); $_POST['template'] = $_POST['template']; include_once libfile('function/block'); block_parse_template($_POST['template'], $arr); if (!empty($_POST['name'])) { $styleid = C::t('common_block_style')->insert($arr, true); } $arr['fields'] = dunserialize($arr['fields']); $arr['template'] = dunserialize($arr['template']); $arr = serialize($arr); C::t('common_block')->update($bid, array('blockstyle' => $arr, 'styleid' => '0')); showmessage('do_success', 'portal.php?mod=portalcp&ac=block&op=style&bid=' . $bid, array('bid' => $bid, 'eleid' => $_GET['eleid'])); } $template = block_build_template($blockstyle['template']); $samplecode = ''; if ($block['hidedisplay']) { $samplecode = '<ul>\\n' . '<!--{loop $_G[block_1] $key $value}-->\\n' . '<li><a href="$value[url]">$value[title]</a></li>\\n' . '<!--{/loop}-->\\n' . '</ul>'; $samplecode = dhtmlspecialchars($samplecode); $samplecode = str_replace('\\n', '<br />', $samplecode);
function block_style_conver_to_thread($style, $blockclass) { $template = block_build_template($style['template']); $search = array('threadurl', 'threadsubject', 'threadsummary', 'filesize', 'downloads'); $replace = array('url', 'title', 'summary', ''); $template = str_replace($search, $replace, $template); $arr = array( 'name' => '', 'blockclass' => $blockclass, ); block_parse_template($template, $arr); $arr['fields'] = dunserialize($arr['fields']); $arr['template'] = dunserialize($arr['template']); $arr = serialize($arr); return $arr; }
function blockclass_cache() { global $_G; $data = $dirs = $styles = $dataconvert = array(); $dir = DISCUZ_ROOT . '/source/class/block/'; $dh = opendir($dir); while ($filename = readdir($dh)) { if (is_dir($dir . $filename) && substr($filename, 0, 1) != '.') { $dirs[$filename] = $dir . $filename . '/'; } } foreach ($dirs as $name => $dir) { $blockclass = $blockconvert = array(); if (file_exists($dir . 'blockclass.php')) { include_once $dir . 'blockclass.php'; } if (empty($blockclass['name'])) { $blockclass['name'] = $name; } else { $blockclass['name'] = htmlspecialchars($blockclass['name']); } $blockclass['subs'] = array(); $dh = opendir($dir); while ($filename = readdir($dh)) { $match = $infos = $oneinfo = $fieldsconvert = array(); $scriptname = $scriptclass = ''; if (preg_match('/^(block_[\\w]+)\\.php$/i', $filename, $match)) { $scriptclass = $match[1]; $scriptname = preg_replace('/^block_/i', '', $scriptclass); include_once $dir . $filename; if (class_exists($scriptclass)) { $obj = new $scriptclass(); if (method_exists($obj, 'name') && method_exists($obj, 'blockclass') && method_exists($obj, 'fields') && method_exists($obj, 'getsetting') && method_exists($obj, 'getdata')) { if ($scriptclass == 'block_xml') { foreach ($obj->blockdata as $one) { $oneinfo['name'] = htmlspecialchars($one['data']['name']); $oneinfo['blockclass'] = array($one['id'], $oneinfo['name']); $oneinfo['fields'] = dhtmlspecialchars($one['data']['fields']); foreach ($one['data']['style'] as $value) { $arr = array('blockclass' => 'xml_' . $one['id'], 'name' => htmlspecialchars($value['name'])); block_parse_template($value['template'], $arr); $styles[$arr['hash']] = $arr; } $infos[] = $oneinfo; } } else { $oneinfo['name'] = $obj->name(); $oneinfo['blockclass'] = $obj->blockclass(); $oneinfo['fields'] = $obj->fields(); $infos[] = $oneinfo; } } if (method_exists($obj, 'fieldsconvert')) { $fieldsconvert = $obj->fieldsconvert(); } } } foreach ($infos as $info) { if ($info['name'] && is_array($info['blockclass']) && $info['blockclass'][0] && $info['blockclass'][1]) { list($key, $title) = $info['blockclass']; $key = $name . '_' . $key; if (!isset($blockclass['subs'][$key])) { $blockclass['subs'][$key] = array('name' => $title, 'fields' => $info['fields'], 'script' => array()); } $blockclass['subs'][$key]['script'][$scriptname] = $info['name']; if (!isset($blockconvert[$key]) && !empty($fieldsconvert)) { $blockconvert[$key] = $fieldsconvert; } } } } if ($blockclass['subs']) { $data[$name] = $blockclass; $blockstyle = array(); if (file_exists($dir . 'blockstyle.php')) { include_once $dir . 'blockstyle.php'; } if ($blockstyle) { foreach ($blockstyle as $value) { $arr = array('blockclass' => $name . '_' . $value['blockclass'], 'name' => $value['name']); block_parse_template($value['template'], $arr); $styles[$arr['hash']] = $arr; } } } if (!empty($blockconvert)) { $dataconvert[$name] = $blockconvert; } } if ($styles) { $hashes = array_keys($styles); $query = DB::query('SELECT `hash` FROM ' . DB::table('common_block_style') . " WHERE `hash` IN (" . dimplode($hashes) . ")"); while ($value = DB::fetch($query)) { unset($styles[$value['hash']]); } if ($styles) { $inserts = array(); foreach ($styles as $value) { $value = daddslashes($value); $inserts[] = "('{$value['blockclass']}', '{$value['name']}', '{$value['template']}', '{$value['hash']}', '{$value['getpic']}', '{$value['getsummary']}', '{$value['settarget']}', '{$value['fields']}')"; } DB::query('INSERT INTO ' . DB::table('common_block_style') . "(`blockclass`, `name`, `template`, `hash`, `getpic`, `getsummary`, `settarget`, `fields`) VALUES " . implode(',', $inserts)); } } save_syscache('blockclass', $data); save_syscache('blockconvert', $dataconvert); }
function add_diy_template($template, $arr) { global $_G; $template = stripslashes($template); include_once libfile('function/block'); block_parse_template($template, $arr); $appVer = $_G['setting']['version']; if ($appVer != 'X2') { $arr = daddslashes($arr); } $hash = $arr['hash']; $result = C::t('#sanree_brand#sanree_brand_businesses')->fix_get_block($hash); if ($result) { C::t('#sanree_brand#sanree_brand_businesses')->fix_update_block($hash, $arr); } else { C::t('#sanree_brand#sanree_brand_businesses')->fix_insert_block($arr); } require_once libfile('function/cache'); updatecache('blockclass'); blockclass_cache(); }