PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_portalcp.php

https://github.com/kuaileshike/upload
PHP | 1104 lines | 1079 code | 19 blank | 6 comment | 42 complexity | 15f5a06fe7a77fa1fc2e4682048e31f5 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_portalcp.php 31861 2012-10-17 08:36:52Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function get_uploadcontent($attach, $type='portal', $dotype='') {
  12. $return = '';
  13. $dotype = $dotype ? 'checked' : '';
  14. if($attach['isimage']) {
  15. $pic = pic_get($attach['attachment'], $type, $attach['thumb'], $attach['remote'], 0);
  16. $small_pic = $attach['thumb'] ? getimgthumbname($pic) : '';
  17. $check = $attach['pic'] == $type.'/'.$attach['attachment'] ? 'checked' : $dotype;
  18. $aid = $check ? $attach['aid'] : '';
  19. $return .= '<a href="javascript:;" class="opattach"><span class="opattach_ctrl">';
  20. $return .= '<span onclick="insertImage(\''.$pic.'\');" class="cur1">'.lang('portalcp', 'insert_large_image').'</span>';
  21. $return .= '<span class="pipe">|</span>';
  22. if($small_pic) $return .= '<span onclick="insertImage(\''.$small_pic.'\', \''.$pic.'\');" class="cur1">'.lang('portalcp', 'small_image').'</span>';
  23. $return .= '</span><img src="'.($small_pic ? $small_pic : $pic).'" onclick="insertImage(\''.$pic.'\');" class="cur1"></a>';
  24. $return .= '<label for="setconver'.$attach['attachid'].'" class="cur1 xi2"><input type="radio" name="setconver" id="setconver'.$attach['attachid'].'" class="pr" value="1" onclick="setConver(\''.addslashes(serialize(array('pic'=>$type.'/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote']))).'\') '.$check.'>'.lang('portalcp', 'set_to_conver').'</label>';
  25. $return .= '<span class="pipe">|</span>';
  26. if($type == 'portal') $return .= '<span class="cur1 xi2" onclick="deleteAttach(\''.$attach['attachid'].'\', \'portal.php?mod=attachment&id='.$attach['attachid'].'&aid='.$aid.'&op=delete\');">'.lang('portalcp', 'delete').'</span>';
  27. } else {
  28. $attach_url = $type == 'forum' ? 'forum.php?mod=attachment&aid='.aidencode($attach['attachid'], 1) : 'portal.php?mod=attachment&id='.$attach['attachid'];
  29. $return .= '<table id="attach_list_'.$attach['attachid'].'" width="100%" class="xi2">';
  30. $return .= '<td width="50" class="bbs"><a href="'.$attach_url.'" target="_blank">'.$attach['filename'].'</a></td>';
  31. $return .= '<td align="right" class="bbs">';
  32. $return .= '<a href="javascript:void(0);" onclick="insertFile(\''.$attach['filename'].'\', \''.$attach_url.'\');return false;">'.lang('portalcp', 'insert_file').'</a><br>';
  33. if($type == 'portal') $return .= '<a href="javascript:void(0);" onclick="deleteAttach(\''.$attach['attachid'].'\', \'portal.php?mod=attachment&id='.$attach['attachid'].'&op=delete\');return false;">'.lang('portalcp', 'delete').'</a>';
  34. $return .= '</td>';
  35. $return .= '</table>';
  36. }
  37. return $return;
  38. }
  39. function get_upload_content($attachs, $dotype='') {
  40. $html = '';
  41. $dotype = $dotype ? 'checked' : '';
  42. $i = 0;
  43. foreach($attachs as $key => $attach) {
  44. $type = $attach['from'] == 'forum' ? 'forum' : 'portal';
  45. $html .= '<td id="attach_list_'.$attach['attachid'].'">';
  46. if($attach['isimage']) {
  47. $pic = pic_get($attach['attachment'], $type, $attach['thumb'], $attach['remote'], 0);
  48. $small_pic = $attach['thumb'] ? getimgthumbname($pic) : '';
  49. $check = $attach['pic'] == $type.'/'.$attach['attachment'] ? 'checked' : $dotype;
  50. $aid = $check ? $attach['aid'] : '';
  51. $html .= '<a href="javascript:;" class="opattach">';
  52. $html .= '<span class="opattach_ctrl">';
  53. $html .= '<span onclick="insertImage(\''.$pic.'\');" class="cur1">'.lang('portalcp', 'insert_large_image').'</span><span class="pipe">|</span>';
  54. if($small_pic) $html .= '<span onclick="insertImage(\''.$small_pic.'\', \''.$pic.'\');" class="cur1">'.lang('portalcp', 'small_image').'</span>';
  55. $html .= '</span><img src="'.($small_pic ? $small_pic : $pic).'" onclick="insertImage(\''.$pic.'\');" class="cur1" /></a>';
  56. $html .= '<label for="setconver'.$attach['attachid'].'" class="cur1 xi2"><input type="radio" name="setconver" id="setconver'.$attach['attachid'].'" class="pr" value="1" onclick=setConver(\''.addslashes(serialize(array('pic'=>$type.'/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote']))).'\') '.$check.'>'.lang('portalcp', 'set_to_conver').'</label>';
  57. if($type == 'portal') {
  58. $html .= '<span class="pipe">|</span><span class="cur1 xi2" onclick="deleteAttach(\''.$attach['attachid'].'\', \'portal.php?mod=attachment&id='.$attach['attachid'].'&aid='.$aid.'&op=delete\');">'.lang('portalcp', 'delete').'</span>';
  59. }
  60. } else {
  61. $html .= '<img src="static/image/editor/editor_file_thumb.png" class="cur1" onclick="insertFile(\''.$attach['filename'].'\', \'portal.php?mod=attachment&id='.$attach['attachid'].'\');" tip="'.$attach['filename'].'" onmouseover="showTip(this);" /><br/>';
  62. $html .= '<span onclick="deleteAttach(\''.$attach['attachid'].'\', \'portal.php?mod=attachment&id='.$attach['attachid'].'&op=delete\');" class="cur1 xi2">'.lang('portalcp', 'delete').'</span>';
  63. }
  64. $html .= '</td>';
  65. $i++;
  66. if($i % 4 == 0 && isset($attachs[$i])) {
  67. $html .= '</tr><tr>';
  68. }
  69. }
  70. if(!empty($html)) {
  71. if(($imgpad = $i % 4) > 0) {
  72. $html .= str_repeat('<td width="25%"></td>', 4 - $imgpad);
  73. }
  74. $html = '<table class="imgl"><tr>'.$html.'</tr></table>';
  75. }
  76. return $html;
  77. }
  78. function getallowcategory($uid){
  79. global $_G;
  80. $permission = array();
  81. if (empty($uid)) return $permission;
  82. if(getstatus($_G['member']['allowadmincp'], 2) || getstatus($_G['member']['allowadmincp'], 3)) {
  83. $uid = max(0,intval($uid));
  84. foreach(C::t('portal_category_permission')->fetch_all_by_uid($uid) as $catid=>$value) {
  85. if ($value['allowpublish'] || $value['allowmanage']) {
  86. $permission[$catid] = $value;
  87. }
  88. }
  89. }
  90. return $permission;
  91. }
  92. function getpermissioncategory($category, $permission = array()) {
  93. $cats = array();
  94. foreach ($permission as $k=>$v) {
  95. $cur = $category[$v];
  96. if ($cur['level'] != 0) {
  97. while ($cur['level']) {
  98. $cats[$cur['upid']]['permissionchildren'][$cur['catid']] = $cur['catid'];
  99. $cur = $category[$cur['upid']];
  100. }
  101. } elseif(empty($cats[$v])) {
  102. $cats[$v] = array();
  103. }
  104. }
  105. return $cats;
  106. }
  107. function getallowdiytemplate($uid){
  108. if (empty($uid)) return false;
  109. $permission = array();
  110. $uid = max(0,intval($uid));
  111. $permission = C::t('common_template_permission')->fetch_all_by_uid($uid);
  112. return $permission;
  113. }
  114. function getdiytpldir($targettplname) {
  115. global $_G;
  116. $tpldir = $pre = '';
  117. if (substr($targettplname, 0, 13) === ($pre = 'forum/discuz_')) {
  118. } elseif (substr($targettplname, 0, 19) === ($pre = 'forum/forumdisplay_')) {
  119. }
  120. if($pre) {
  121. $forum = C::t('forum_forum')->fetch(intval(str_replace($pre, '', $targettplname)));
  122. if(!empty($forum['styleid'])) {
  123. $_cname = 'style_'.$forum['styleid'];
  124. loadcache($_cname);
  125. $tpldir = empty($_G['cache'][$_cname]['tpldir']) ? '' : $_G['cache'][$_cname]['tpldir'];
  126. }
  127. }
  128. return $tpldir ? $tpldir : ($_G['cache']['style_default']['tpldir'] ? $_G['cache']['style_default']['tpldir'] : './template/default');
  129. }
  130. function save_diy_data($tpldirectory, $primaltplname, $targettplname, $data, $database = false, $optype = '') {
  131. global $_G;
  132. if (empty($data) || !is_array($data)) return false;
  133. checksecurity($data['spacecss']);
  134. if(empty($tpldirectory)) {
  135. $tpldirectory = getdiytpldir($targettplname);
  136. }
  137. $isextphp = false;
  138. $file = $tpldirectory.'/'.$primaltplname.'.htm';
  139. if (!file_exists($file)) {
  140. $file = $tpldirectory.'/'.$primaltplname.'.php';
  141. if (!file_exists($file)) {
  142. $file = './template/default/'.$primaltplname.'.htm';
  143. } else {
  144. $isextphp = true;
  145. }
  146. }
  147. if(!file_exists($file)) return false;
  148. $content = file_get_contents(DISCUZ_ROOT.$file);
  149. if($isextphp) {
  150. $content = substr($content, strpos($content, "\n"));
  151. }
  152. $content = preg_replace("/\<\!\-\-\[name\].+?\[\/name\]\-\-\>\s+/is", '', $content);
  153. $content = preg_replace("/\<script src\=\"misc\.php\?mod\=diyhelp\&action\=get.+?\>\<\/script\>/", '', $content);
  154. foreach ($data['layoutdata'] as $key => $value) {
  155. $key = trimdxtpllang($key);
  156. $html = '';
  157. $html .= '<div id="'.$key.'" class="area">';
  158. $html .= getframehtml($value);
  159. $html .= '</div>';
  160. $content = preg_replace("/(\<\!\-\-\[diy\=$key\]\-\-\>).+?(\<\!\-\-\[\/diy\]\-\-\>)/is", "\\1".$html."\\2", $content);
  161. }
  162. $data['spacecss'] = str_replace('.content', '.dxb_bc', $data['spacecss']);
  163. $data['spacecss'] = trimdxtpllang($data['spacecss']);
  164. $content = preg_replace("/(\<style id\=\"diy_style\" type\=\"text\/css\"\>).*?(\<\/style\>)/is", "\\1".$data['spacecss']."\\2", $content);
  165. if (!empty($data['style'])) {
  166. $content = preg_replace("/(\<link id\=\"style_css\" rel\=\"stylesheet\" type\=\"text\/css\" href\=\").+?(\"\>)/is", "\\1".$data['style']."\\2", $content);
  167. }
  168. $flag = $optype == 'savecache' ? true : false;
  169. if($flag) {
  170. $targettplname = $targettplname.'_diy_preview';
  171. } else {
  172. @unlink('./data/diy/'.$tpldirectory.'/'.$targettplname.'_diy_preview.htm');
  173. }
  174. $tplfile =DISCUZ_ROOT.'./data/diy/'.$tpldirectory.'/'.$targettplname.'.htm';
  175. $tplpath = dirname($tplfile);
  176. if (!is_dir($tplpath)) {
  177. dmkdir($tplpath);
  178. } else {
  179. if (file_exists($tplfile) && !$flag) copy($tplfile, $tplfile.'.bak');
  180. }
  181. $r = file_put_contents($tplfile, $content);
  182. if ($r && $database && !$flag) {
  183. $diytplname = getdiytplname($targettplname, $tpldirectory);
  184. C::t('common_diy_data')->insert(array(
  185. 'targettplname' => $targettplname,
  186. 'tpldirectory' => $tpldirectory,
  187. 'primaltplname' => $primaltplname,
  188. 'diycontent' => serialize($data),
  189. 'name' => $diytplname,
  190. 'uid' => $_G['uid'],
  191. 'username' => $_G['username'],
  192. 'dateline' => TIMESTAMP,
  193. ), false, true);
  194. }
  195. return $r;
  196. }
  197. function getdiytplnames($tpls) {
  198. $arr = $ret = array();
  199. foreach((array)$tpls as $targettplname) {
  200. $id = $pre = '';
  201. if (substr($targettplname, 0, 12) === ($pre = 'portal/list_')) {
  202. } elseif (substr($targettplname, 0, 12) === ($pre = 'portal/view_')) {
  203. } elseif (substr($targettplname, 0, 13) === ($pre = 'forum/discuz_')) {
  204. } elseif (substr($targettplname, 0, 17) === ($pre = 'forum/viewthread_')) {
  205. } elseif (substr($targettplname, 0, 19) === ($pre = 'forum/forumdisplay_')) {
  206. } elseif (substr($targettplname, 0, 28) === ($pre = 'portal/portal_topic_content_')) {
  207. }
  208. if($pre && ($id = dintval(str_replace($pre, '', $targettplname)))) {
  209. $arr[$pre][$id] = $id;
  210. }
  211. }
  212. foreach($arr as $pre => $ids) {
  213. if ($pre === 'portal/list_') {
  214. foreach(C::t('portal_category')->fetch_all($ids) as $id => $value) {
  215. $ret[$pre][$id] = $value['catname'];
  216. }
  217. } elseif ($pre === 'portal/view_') {
  218. $portal_view_name = lang('portalcp', 'portal_view_name');
  219. foreach(C::t('portal_category')->fetch_all($ids) as $id => $value) {
  220. $ret[$pre][$id] = $value['catname'].$portal_view_name;
  221. }
  222. } elseif ($pre === 'forum/forumdisplay_' || $pre === 'forum/discuz_') {
  223. foreach(C::t('forum_forum')->fetch_all($ids) as $id => $value) {
  224. $ret[$pre][$id] = $value['name'];
  225. }
  226. } elseif ($pre === 'forum/viewthread_') {
  227. $forum_viewthread_name = lang('portalcp', 'forum_viewthread_name');
  228. foreach(C::t('forum_forum')->fetch_all($ids) as $id => $value) {
  229. $ret[$pre][$id] = $value['name'].$forum_viewthread_name;
  230. }
  231. } elseif ($pre === 'portal/portal_topic_content_') {
  232. foreach(C::t('portal_topic')->fetch_all($ids) as $id => $value) {
  233. $ret[$pre][$id] = $value['title'];
  234. }
  235. }
  236. }
  237. return $ret;
  238. }
  239. function getdiytplname($targettplname, $tpldirectory) {
  240. $diydata = C::t('common_diy_data')->fetch($targettplname, $tpldirectory);
  241. $diytplname = $diydata ? $diydata['name'] : '';
  242. if(empty($diytplname) && ($data = getdiytplnames(array($targettplname)))) {
  243. $diytplname = array_shift(array_shift($data));
  244. }
  245. return $diytplname;
  246. }
  247. function getframehtml($data = array()) {
  248. global $_G;
  249. $html = $style = '';
  250. foreach ((array)$data as $id => $content) {
  251. $id = trimdxtpllang($id);
  252. $flag = $name = '';
  253. list($flag, $name) = explode('`', $id);
  254. if ($flag == 'frame') {
  255. $fattr = $content['attr'];
  256. $fattr['name'] = trimdxtpllang($fattr['name']);
  257. $fattr['className'] = trimdxtpllang($fattr['className']);
  258. $moveable = $fattr['moveable'] == 'true' ? ' move-span' : '';
  259. $html .= '<div id="'.$fattr['name'].'" class="'.$fattr['className'].'">';
  260. if (checkhastitle($fattr['titles'])) {
  261. $style = gettitlestyle($fattr['titles']);
  262. $cn = trimdxtpllang(implode(' ',$fattr['titles']['className']));
  263. $html .= '<div class="'.$cn.'"'.$style.'>'.gettitlehtml($fattr['titles'], 'frame').'</div>';
  264. }
  265. foreach ((array)$content as $colid => $coldata) {
  266. list($colflag, $colname) = explode('`', $colid);
  267. $colname = trimdxtpllang($colname);
  268. $cn = trimdxtpllang($coldata['attr']['className']);
  269. if ($colflag == 'column') {
  270. $html .= '<div id="'.$colname.'" class="'.$cn.'">';
  271. $html .= '<div id="'.$colname.'_temp" class="move-span temp"></div>';
  272. $html .= getframehtml($coldata);
  273. $html .= '</div>';
  274. }
  275. }
  276. $html .= '</div>';
  277. } elseif ($flag == 'tab') {
  278. $fattr = $content['attr'];
  279. $fattr['name'] = trimdxtpllang($fattr['name']);
  280. $fattr['className'] = trimdxtpllang($fattr['className']);
  281. $moveable = $fattr['moveable'] == 'true' ? ' move-span' : '';
  282. $html .= '<div id="'.$fattr['name'].'" class="'.$fattr['className'].'">';
  283. $switchtype = 'click';
  284. foreach ((array)$content as $colid => $coldata) {
  285. list($colflag, $colname) = explode('`', $colid);
  286. $colname = trimdxtpllang($colname);
  287. $cn = trimdxtpllang($coldata['attr']['className']);
  288. if ($colflag == 'column') {
  289. if (checkhastitle($fattr['titles'])) {
  290. $style = gettitlestyle($fattr['titles']);
  291. $title = gettitlehtml($fattr['titles'], 'tab');
  292. }
  293. $switchtype = is_array($fattr['titles']['switchType']) && !empty($fattr['titles']['switchType'][0]) ? $fattr['titles']['switchType'][0] : 'click';
  294. $switchtype = in_array(strtolower($switchtype), array('click', 'mouseover')) ? $switchtype : 'click';
  295. $html .= '<div id="'.$colname.'" class="'.$cn.'"'.$style.' switchtype="'.$switchtype.'">'.$title;
  296. $html .= getframehtml($coldata);
  297. $html .= '</div>';
  298. }
  299. }
  300. $html .= '<div id="'.$fattr['name'].'_content" class="tb-c"></div>';
  301. $html .= '<script type="text/javascript">initTab("'.$fattr['name'].'","'.$switchtype.'");</script>';
  302. $html .= '</div>';
  303. } elseif ($flag == 'block') {
  304. $battr = $content['attr'];
  305. $bid = intval(str_replace('portal_block_', '', $battr['name']));
  306. if (!empty($bid)) {
  307. $html .= "<!--{block/{$bid}}-->";
  308. $_G['curtplbid'][$bid] = $bid;
  309. }
  310. }
  311. }
  312. return $html;
  313. }
  314. function gettitlestyle($title) {
  315. $style = '';
  316. if (is_array($title['style']) && count($title['style'])) {
  317. foreach ($title['style'] as $k=>$v){
  318. $style .= trimdxtpllang($k).':'.trimdxtpllang($v).';';
  319. }
  320. }
  321. $style = $style ? ' style=\''.$style.'\'' : '';
  322. return $style;
  323. }
  324. function checkhastitle($title) {
  325. if (!is_array($title)) return false;
  326. foreach ($title as $k => $v) {
  327. if (strval($k) == 'className') continue;
  328. if (!empty($v['text'])) return true;
  329. }
  330. return false;
  331. }
  332. function gettitlehtml($title, $type) {
  333. global $_G;
  334. if (!is_array($title)) return '';
  335. $html = $one = $style = $color = '';
  336. foreach ($title as $k => $v) {
  337. if (in_array(strval($k),array('className','style'))) continue;
  338. if (empty($v['src']) && empty($v['text'])) continue;
  339. $v['className'] = trimdxtpllang($v['className']);
  340. $v['font-size'] = intval($v['font-size']);
  341. $v['margin'] = intval($v['margin']);
  342. $v['float'] = trimdxtpllang($v['float']);
  343. $v['color'] = trimdxtpllang($v['color']);
  344. $v['src'] = trimdxtpllang($v['src']);
  345. $v['href'] = trimdxtpllang($v['href']);
  346. $v['text'] = dhtmlspecialchars(str_replace(array('{', '$'), array('{ ', '$ '), $v['text']));
  347. $one = "<span class=\"{$v['className']}\"";
  348. $style = $color = "";
  349. $style .= empty($v['font-size']) ? '' : "font-size:{$v['font-size']}px;";
  350. $style .= empty($v['float']) ? '' : "float:{$v['float']};";
  351. $margin_ = empty($v['float']) ? 'left' : $v['float'];
  352. $style .= empty($v['margin']) ? '' : "margin-{$margin_}:{$v['margin']}px;";
  353. $color = empty($v['color']) ? '' : "color:{$v['color']};";
  354. $img = !empty($v['src']) ? '<img src="'.$v['src'].'" class="vm" alt="'.$v['text'].'"/>' : '';
  355. if (empty($v['href'])) {
  356. $style = empty($style)&&empty($color) ? '' : ' style="'.$style.$color.'"';
  357. $one .= $style.">$img{$v['text']}";
  358. } else {
  359. $style = empty($style) ? '' : ' style="'.$style.'"';
  360. $colorstyle = empty($color) ? '' : ' style="'.$color.'"';
  361. $one .= $style.'><a href="'.$v['href'].'" target="_blank"'.$colorstyle.'>'.$img.$v['text'].'</a>';
  362. }
  363. $one .= '</span>';
  364. $siteurl = str_replace(array('/','.'),array('\/','\.'),$_G['siteurl']);
  365. $one = preg_replace('/\"'.$siteurl.'(.*?)\"/','"$1"',$one);
  366. $html = $k === 'first' ? $one.$html : $html.$one;
  367. }
  368. return $html;
  369. }
  370. function gettheme($type) {
  371. $themes = array();
  372. $themedirs = dreaddir(DISCUZ_ROOT."/static/$type");
  373. foreach ($themedirs as $key => $dirname) {
  374. $now_dir = DISCUZ_ROOT."/static/$type/$dirname";
  375. if(file_exists($now_dir.'/style.css') && file_exists($now_dir.'/preview.jpg')) {
  376. $themes[] = array(
  377. 'dir' => $type.'/'.$dirname,
  378. 'name' => getcssname($type.'/'.$dirname)
  379. );
  380. }
  381. }
  382. return $themes;
  383. }
  384. function getcssname($dirname) {
  385. $css = @file_get_contents(DISCUZ_ROOT.'./static/'.$dirname.'/style.css');
  386. if($css) {
  387. preg_match("/\[name\](.+?)\[\/name\]/i", trim($css), $mathes);
  388. if(!empty($mathes[1])) $name = dhtmlspecialchars($mathes[1]);
  389. } else {
  390. $name = 'No name';
  391. }
  392. return $name;
  393. }
  394. function checksecurity($str) {
  395. $filter = array(
  396. '/\/\*[\n\r]*(.+?)[\n\r]*\*\//is',
  397. '/[^a-z0-9]+/i',
  398. '/important/i',
  399. );
  400. $str = preg_replace($filter, '', $str);
  401. if(preg_match("/(expression|import|javascript)/i", $str)) {
  402. showmessage('css_contains_elements_of_insecurity');
  403. }
  404. return true;
  405. }
  406. function block_export($bids) {
  407. $return = array('block'=>array(), 'style'=>array());
  408. if(empty($bids)) {
  409. return;
  410. }
  411. $styleids = array();
  412. foreach(C::t('common_block')->fetch_all($bids) as $value) {
  413. $value['param'] = dunserialize($value['param']);
  414. if(!empty($value['blockstyle'])) $value['blockstyle'] = dunserialize($value['blockstyle']);
  415. $return['block'][$value['bid']] = $value;
  416. if(!empty($value['styleid'])) $styleids[] = intval($value['styleid']);
  417. }
  418. if($styleids) {
  419. $styleids = array_unique($styleids);
  420. foreach(C::t('common_block_style')->fetch_all($styleids) as $value) {
  421. $value['template'] = dunserialize($value['template']);
  422. if(!empty($value['fields'])) $value['fields'] = dunserialize($value['fields']);
  423. $return['style'][$value['styleid']] = $value;
  424. }
  425. }
  426. return $return ;
  427. }
  428. function block_import($data) {
  429. global $_G;
  430. if(!is_array($data['block'])) {
  431. return ;
  432. }
  433. $stylemapping = array();
  434. if($data['style']) {
  435. $hashes = $styles = array();
  436. foreach($data['style'] as $value) {
  437. $hashes[] = $value['hash'];
  438. $styles[$value['hash']] = $value['styleid'];
  439. }
  440. if(!empty($hashes)) {
  441. foreach(C::t('common_block_style')->fetch_all_by_hash($hashes) as $value) {
  442. $id = $styles[$value['hash']];
  443. $stylemapping[$id] = intval($value['styleid']);
  444. unset($styles[$value['hash']]);
  445. }
  446. }
  447. foreach($styles as $id) {
  448. $style = $data['style'][$id];
  449. $style['styleid'] = '';
  450. if(is_array($style['template'])) {
  451. $style['template'] = serialize($style['template']);
  452. }
  453. if(is_array($style['fields'])) {
  454. $style['fields'] = serialize($style['fields']);
  455. }
  456. $newid = C::t('common_block_style')->insert($style, true);
  457. $stylemapping[$id] = $newid;
  458. }
  459. }
  460. $blockmapping = array();
  461. foreach($data['block'] as $block) {
  462. $oid = $block['bid'];
  463. if(!empty($block['styleid'])) {
  464. $block['styleid'] = intval($stylemapping[$block['styleid']]);
  465. }
  466. $block['bid'] = '';
  467. $block['uid'] = $_G['uid'];
  468. $block['username'] = $_G['username'];
  469. $block['dateline'] = 0;
  470. $block['notinherited'] = 0;
  471. if(is_array($block['param'])) {
  472. $block['param'] = serialize($block['param']);
  473. }
  474. if(is_array($block['blockstyle'])) {
  475. $block['blockstyle'] = serialize($block['blockstyle']);
  476. }
  477. $newid = C::t('common_block')->insert($block, true);
  478. $blockmapping[$oid] = $newid;
  479. }
  480. include_once libfile('function/cache');
  481. updatecache('blockclass');
  482. return $blockmapping;
  483. }
  484. function getobjbyname($name, $data) {
  485. if (!$name || !$data) return false;
  486. foreach ((array)$data as $id => $content) {
  487. list($type, $curname) = explode('`', $id);
  488. if ($curname == $name) {
  489. return array('type'=>$type,'content'=>$content);
  490. } elseif ($type == 'frame' || $type == 'tab' || $type == 'column') {
  491. $r = getobjbyname($name, $content);
  492. if ($r) return $r;
  493. }
  494. }
  495. return false;
  496. }
  497. function getframeblock($data) {
  498. global $_G;
  499. if (!isset($_G['curtplbid'])) $_G['curtplbid'] = array();
  500. if (!isset($_G['curtplframe'])) $_G['curtplframe'] = array();
  501. foreach ((array)$data as $id => $content) {
  502. list($flag, $name) = explode('`', $id);
  503. if ($flag == 'frame' || $flag == 'tab') {
  504. foreach ((array)$content as $colid => $coldata) {
  505. list($colflag, $colname) = explode('`', $colid);
  506. if ($colflag == 'column') {
  507. getframeblock($coldata,$framename);
  508. }
  509. }
  510. $_G['curtplframe'][$name] = array('type'=>$flag,'name'=>$name);
  511. } elseif ($flag == 'block') {
  512. $battr = $content['attr'];
  513. $bid = intval(str_replace('portal_block_', '', $battr['name']));
  514. if (!empty($bid)) {
  515. $_G['curtplbid'][$bid] = $bid;
  516. }
  517. }
  518. }
  519. }
  520. function getcssdata($css) {
  521. global $_G;
  522. if (empty($css)) return '';
  523. $reglist = array();
  524. foreach ((array)$_G['curtplframe'] as $value) {
  525. $reglist[] = '#'.$value['name'].'.*?\{.*?\}';
  526. }
  527. foreach ((array)$_G['curtplbid'] as $value) {
  528. $reglist[] = '#portal_block_'.$value.'.*?\{.*?\}';
  529. }
  530. $reg = implode('|',$reglist);
  531. preg_match_all('/'.$reg.'/',$css,$csslist);
  532. return implode('', $csslist[0]);
  533. }
  534. function import_diy($file) {
  535. global $_G;
  536. $css = '';
  537. $html = array();
  538. $arr = array();
  539. $content = file_get_contents($file);
  540. require_once libfile('class/xml');
  541. if (empty($content)) return $arr;
  542. $content = preg_replace("/\<\!\-\-\[name\](.+?)\[\/name\]\-\-\>\s+/i", '', $content);
  543. $diycontent = xml2array($content);
  544. if ($diycontent) {
  545. foreach ($diycontent['layoutdata'] as $key => $value) {
  546. if (!empty($value)) getframeblock($value);
  547. }
  548. $newframe = array();
  549. foreach ($_G['curtplframe'] as $value) {
  550. $newframe[] = $value['type'].random(6);
  551. }
  552. $mapping = array();
  553. if (!empty($diycontent['blockdata'])) {
  554. $mapping = block_import($diycontent['blockdata']);
  555. unset($diycontent['blockdata']);
  556. }
  557. $oldbids = $newbids = array();
  558. if (!empty($mapping)) {
  559. foreach($mapping as $obid=>$nbid) {
  560. $oldbids[] = '#portal_block_'.$obid.' ';
  561. $newbids[] = '#portal_block_'.$nbid.' ';
  562. $oldbids[] = '[portal_block_'.$obid.']';
  563. $newbids[] = '[portal_block_'.$nbid.']';
  564. $oldbids[] = '~portal_block_'.$obid.'"';
  565. $newbids[] = '~portal_block_'.$nbid.'"';
  566. }
  567. }
  568. require_once libfile('class/xml');
  569. $xml = array2xml($diycontent['layoutdata'],true);
  570. $xml = str_replace($oldbids, $newbids, $xml);
  571. $xml = str_replace((array)array_keys($_G['curtplframe']), $newframe, $xml);
  572. $diycontent['layoutdata'] = xml2array($xml);
  573. $css = str_replace($oldbids, $newbids, $diycontent['spacecss']);
  574. $css = str_replace((array)array_keys($_G['curtplframe']), $newframe, $css);
  575. foreach ($diycontent['layoutdata'] as $key => $value) {
  576. $html[$key] = getframehtml($value);
  577. }
  578. }
  579. if (!empty($html)) {
  580. $xml = array2xml($html, true);
  581. require_once libfile('function/block');
  582. block_get_batch(implode(',', $mapping));
  583. foreach ($mapping as $bid) {
  584. $blocktag[] = '<!--{block/'.$bid.'}-->';
  585. $blockcontent[] = block_fetch_content($bid);
  586. }
  587. $xml = str_replace($blocktag,$blockcontent,$xml);
  588. $html = xml2array($xml);
  589. $arr = array('html'=>$html,'css'=>$css,'mapping'=>$mapping);
  590. }
  591. return $arr;
  592. }
  593. function checkprimaltpl($template) {
  594. global $_G;
  595. $tpldirectory = '';
  596. if(strpos($template, ':') !== false) {
  597. list($tpldirectory, $template) = explode(':', $template);
  598. }
  599. if(!$template || preg_match("/(\.)(exe|jsp|asp|aspx|cgi|fcgi|pl)(\.|$)/i", $template)) {
  600. return 'diy_template_filename_invalid';
  601. }
  602. if(strpos($tpldirectory, '..') !== false || strpos($tpldirectory, "\0") !== false) {
  603. return 'diy_tpldirectory_invalid';
  604. }
  605. $primaltplname = (!$tpldirectory ? DISCUZ_ROOT.$_G['cache']['style_default']['tpldir'] : $tpldirectory).'/'.$template.'.htm';
  606. if (!file_exists($primaltplname)) {
  607. $primaltplname = DISCUZ_ROOT.'./template/default/'.$template.'.htm';
  608. }
  609. $pathinfos = pathinfo($primaltplname);
  610. if(strtolower($pathinfos['extension']) != 'htm') {
  611. return 'diy_template_extension_invalid';
  612. }
  613. if (!is_file($primaltplname)) {
  614. return 'diy_template_noexist';
  615. }
  616. return true;
  617. }
  618. function article_tagnames() {
  619. global $_G;
  620. if(!isset($_G['article_tagnames'])) {
  621. $_G['article_tagnames'] = array();
  622. for($i=1; $i<=8; $i++) {
  623. if(isset($_G['setting']['article_tags']) && isset($_G['setting']['article_tags'][$i])) {
  624. $_G['article_tagnames'][$i] = $_G['setting']['article_tags'][$i];
  625. } else {
  626. $_G['article_tagnames'][$i] = lang('portalcp', 'article_tag').$i;
  627. }
  628. }
  629. }
  630. return $_G['article_tagnames'];
  631. }
  632. function article_parse_tags($tag) {
  633. $tag = intval($tag);
  634. $article_tags = array();
  635. for($i=1; $i<=8; $i++) {
  636. $k = pow(2, $i-1);
  637. $article_tags[$i] = ($tag & $k) ? 1 : 0;
  638. }
  639. return $article_tags;
  640. }
  641. function article_make_tag($tags) {
  642. $tags = (array)$tags;
  643. $tag = 0;
  644. for($i=1; $i<=8; $i++) {
  645. if(!empty($tags[$i])) {
  646. $tag += pow(2, $i-1);
  647. }
  648. }
  649. return $tag;
  650. }
  651. function category_showselect($type, $name='catid', $shownull=true, $current='') {
  652. global $_G;
  653. if(! in_array($type, array('portal', 'blog', 'album'))) {
  654. return '';
  655. }
  656. loadcache($type.'category');
  657. $category = $_G['cache'][$type.'category'];
  658. $select = "<select id=\"$name\" name=\"$name\" class=\"ps vm\">";
  659. if($shownull) {
  660. $select .= '<option value="">'.lang('portalcp', 'select_category').'</option>';
  661. }
  662. foreach ($category as $value) {
  663. if($value['level'] == 0) {
  664. $selected = ($current && $current==$value['catid']) ? 'selected="selected"' : '';
  665. $select .= "<option value=\"$value[catid]\"$selected>$value[catname]</option>";
  666. if(!$value['children']) {
  667. continue;
  668. }
  669. foreach ($value['children'] as $catid) {
  670. $selected = ($current && $current==$catid) ? 'selected="selected"' : '';
  671. $select .= "<option value=\"{$category[$catid][catid]}\"$selected>-- {$category[$catid][catname]}</option>";
  672. if($category[$catid]['children']) {
  673. foreach ($category[$catid]['children'] as $catid2) {
  674. $selected = ($current && $current==$catid2) ? 'selected="selected"' : '';
  675. $select .= "<option value=\"{$category[$catid2][catid]}\"$selected>---- {$category[$catid2][catname]}</option>";
  676. }
  677. }
  678. }
  679. }
  680. }
  681. $select .= "</select>";
  682. return $select;
  683. }
  684. function category_get_childids($type, $catid, $depth=3) {
  685. global $_G;
  686. if(! in_array($type, array('portal', 'blog', 'album'))) {
  687. return array();
  688. }
  689. loadcache($type.'category');
  690. $category = $_G['cache'][$type.'category'];
  691. $catids = array();
  692. if(isset($category[$catid]) && !empty($category[$catid]['children']) && $depth) {
  693. $catids = $category[$catid]['children'];
  694. foreach($category[$catid]['children'] as $id) {
  695. $catids = array_merge($catids, category_get_childids($type, $id, $depth-1));
  696. }
  697. }
  698. return $catids;
  699. }
  700. function category_get_num($type, $catid) {
  701. global $_G;
  702. if(! in_array($type, array('portal', 'blog', 'album'))) {
  703. return array();
  704. }
  705. loadcache($type.'category');
  706. $category = $_G['cache'][$type.'category'];
  707. $numkey = $type == 'portal' ? 'articles' : 'num';
  708. if(! isset($_G[$type.'category_nums'])) {
  709. $_G[$type.'category_nums'] = array();
  710. $tables = array('portal'=>'portal_category', 'blog'=>'home_blog_category', 'album'=>'home_album_category');
  711. $query = C::t($tables[$type])->fetch_all_numkey($numkey);
  712. foreach ($query as $value) {
  713. $_G[$type.'category_nums'][$value['catid']] = intval($value[$numkey]);
  714. }
  715. }
  716. $nums = $_G[$type.'category_nums'];
  717. $num = intval($nums[$catid]);
  718. if($category[$catid]['children']) {
  719. foreach($category[$catid]['children'] as $id) {
  720. $num += category_get_num($type, $id);
  721. }
  722. }
  723. return $num;
  724. }
  725. function updatetopic($topic = ''){
  726. global $_G;
  727. $topicid = empty($topic) ? '' : $topic['topicid'];
  728. include_once libfile('function/home');
  729. $_POST['title'] = getstr(trim($_POST['title']), 255);
  730. $_POST['name'] = getstr(trim($_POST['name']), 255);
  731. $_POST['domain'] = getstr(trim($_POST['domain']), 255);
  732. if(empty($_POST['title'])) {
  733. return 'topic_title_cannot_be_empty';
  734. }
  735. if(empty($_POST['name'])) {
  736. $_POST['name'] = $_POST['title'];
  737. }
  738. if(!$topicid || $_POST['name'] != $topic['name']) {
  739. if(($value = C::t('portal_topic')->fetch_by_name($_POST['name']))) {
  740. return 'topic_name_duplicated';
  741. }
  742. }
  743. if($topicid && !empty($topic['domain'])) {
  744. require_once libfile('function/delete');
  745. deletedomain($topicid, 'topic');
  746. }
  747. if(!empty($_POST['domain'])) {
  748. require_once libfile('function/domain');
  749. domaincheck($_POST['domain'], $_G['setting']['domain']['root']['topic'], 1);
  750. }
  751. $setarr = array(
  752. 'title' => $_POST['title'],
  753. 'name' => $_POST['name'],
  754. 'domain' => $_POST['domain'],
  755. 'summary' => getstr($_POST['summary']),
  756. 'keyword' => getstr($_POST['keyword']),
  757. 'useheader' => $_POST['useheader'] ? '1' : '0',
  758. 'usefooter' => $_POST['usefooter'] ? '1' : '0',
  759. 'allowcomment' => $_POST['allowcomment'] ? 1 : 0,
  760. 'closed' => $_POST['closed'] ? 0 : 1,
  761. );
  762. if($_POST['deletecover'] && $topic['cover']) {
  763. if($topic['picflag'] != '0') pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0');
  764. $setarr['cover'] = '';
  765. } else {
  766. if($_FILES['cover']['tmp_name']) {
  767. if($topic['cover'] && $topic['picflag'] != '0') pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0');
  768. $pic = pic_upload($_FILES['cover'], 'portal');
  769. if($pic) {
  770. $setarr['cover'] = 'portal/'.$pic['pic'];
  771. $setarr['picflag'] = $pic['remote'] ? '2' : '1';
  772. }
  773. } else {
  774. if(!empty($_POST['cover']) && $_POST['cover'] != $topic['cover']) {
  775. if($topic['cover'] && $topic['picflag'] != '0') pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0');
  776. $setarr['cover'] = $_POST['cover'];
  777. $setarr['picflag'] = '0';
  778. }
  779. }
  780. }
  781. $primaltplname = '';
  782. if(empty($topicid) || empty($topic['primaltplname']) || ($topic['primaltplname'] && $topic['primaltplname'] != $_POST['primaltplname'])) {
  783. $primaltplname = $_POST['primaltplname'];
  784. if(!isset($_POST['signs'][dsign($primaltplname)])) {
  785. return 'diy_sign_invalid';
  786. }
  787. $checktpl = checkprimaltpl($primaltplname);
  788. if($checktpl !== true) {
  789. return $checktpl;
  790. }
  791. $setarr['primaltplname'] = $primaltplname;
  792. }
  793. if($topicid) {
  794. C::t('portal_topic')->update($topicid, $setarr);
  795. C::t('common_diy_data')->update('portal/portal_topic_content_'.$topicid, getdiydirectory($topic['primaltplname']), array('name'=>$setarr['title']));
  796. } else {
  797. $setarr['uid'] = $_G['uid'];
  798. $setarr['username'] = $_G['username'];
  799. $setarr['dateline'] = $_G['timestamp'];
  800. $setarr['closed'] = '1';
  801. $topicid = addtopic($setarr);
  802. if(!$topicid) {
  803. return 'topic_created_failed';
  804. }
  805. }
  806. if(!empty($_POST['domain'])) {
  807. C::t('common_domain')->insert(array('domain' => $_POST['domain'], 'domainroot' => $_G['setting']['domain']['root']['topic'], 'id' => $topicid, 'idtype' => 'topic'));
  808. }
  809. $tpldirectory = '';
  810. if($primaltplname && $topic['primaltplname'] != $primaltplname) {
  811. $targettplname = 'portal/portal_topic_content_'.$topicid;
  812. if(strpos($primaltplname, ':') !== false) {
  813. list($tpldirectory, $primaltplname) = explode(':', $primaltplname);
  814. }
  815. C::t('common_diy_data')->update($targettplname, getdiydirectory($topic['primaltplname']), array('primaltplname'=>$primaltplname, 'tpldirectory'=>$tpldirectory));
  816. updatediytemplate($targettplname);
  817. }
  818. if($primaltplname && empty($topic['primaltplname'])) {
  819. $tpldirectory = ($tpldirectory ? $tpldirectory : $_G['cache']['style_default']['tpldir']);
  820. $content = file_get_contents(DISCUZ_ROOT.$tpldirectory.'/'.$primaltplname.'.htm');
  821. $tplfile = DISCUZ_ROOT.'./data/diy/'.$tpldirectory.'/portal/portal_topic_content_'.$topicid.'.htm';
  822. $tplpath = dirname($tplfile);
  823. if (!is_dir($tplpath)) {
  824. dmkdir($tplpath);
  825. }
  826. file_put_contents($tplfile, $content);
  827. }
  828. include_once libfile('function/cache');
  829. updatecache(array('diytemplatename', 'setting'));
  830. return $topicid;
  831. }
  832. function addtopic($topic) {
  833. global $_G;
  834. $topicid = '';
  835. if($topic && is_array($topic)) {
  836. $topicid = C::t('portal_topic')->insert($topic, true);
  837. if(!empty($topicid)) {
  838. $diydata = array(
  839. 'targettplname' => 'portal/portal_topic_content_'.$topicid,
  840. 'name' => $topic['title'],
  841. 'uid' => $_G['uid'],
  842. 'username' => $_G['username'],
  843. 'dateline' => TIMESTAMP,
  844. );
  845. C::t('common_diy_data')->insert($diydata);
  846. }
  847. }
  848. return $topicid;
  849. }
  850. function getblockperm($bid) {
  851. global $_G;
  852. $perm = array('allowmanage'=>'0','allowrecommend'=>'0','needverify'=>'1');
  853. $bid = max(0, intval($bid));
  854. if(!$bid) return $perm;
  855. $allperm = array('allowmanage'=>'1','allowrecommend'=>'1','needverify'=>'0');
  856. if(checkperm('allowdiy')) {
  857. return $allperm;
  858. } elseif (!getstatus($_G['member']['allowadmincp'], 4) && !getstatus($_G['member']['allowadmincp'], 5) && !getstatus($_G['member']['allowadmincp'], 6) && !checkperm('allowmanagetopic') && !checkperm('allowaddtopic')) {
  859. return $perm;
  860. }
  861. require_once libfile('class/blockpermission');
  862. $blockpermsission = & block_permission::instance();
  863. $perm = $blockpermsission->get_perms_by_bid($bid, $_G['uid']);
  864. $perm = $perm ? current($perm) : '';
  865. if(empty($perm)) {
  866. if(($block = C::t('common_block')->fetch($bid))) {
  867. $block = array_merge($block, C::t('common_template_block')->fetch_by_bid($bid));
  868. }
  869. if(empty($block['targettplname']) && empty($block['blocktype'])) {
  870. if(($_G['group']['allowmanagetopic'] || ($_G['group']['allowaddtopic'] && $block['uid'] == $_G['uid']))) {
  871. $perm = $allperm;
  872. }
  873. } elseif(substr($block['targettplname'], 0, 28) == 'portal/portal_topic_content_') {
  874. if(!empty($_G['group']['allowmanagetopic'])) {
  875. $perm = $allperm;
  876. } elseif($_G['group']['allowaddtopic']) {
  877. $id = str_replace('portal/portal_topic_content_', '', $block['targettplname']);
  878. $topic = C::t('portal_topic')->fetch(intval($id));
  879. if($topic['uid'] == $_G['uid']) {
  880. $perm = $allperm;
  881. }
  882. }
  883. }
  884. }
  885. return $perm;
  886. }
  887. function check_articleperm($catid, $aid = 0, $article = array(), $isverify = false, $return = false) {
  888. global $_G;
  889. if(empty($catid)) {
  890. if(!$return) {
  891. showmessage('article_category_empty');
  892. } else {
  893. return 'article_category_empty';
  894. }
  895. }
  896. if($_G['group']['allowmanagearticle'] || (empty($aid) && $_G['group']['allowpostarticle']) || $_GET['modarticlekey'] == modauthkey($aid)) {
  897. return true;
  898. }
  899. $permission = getallowcategory($_G['uid']);
  900. if(isset($permission[$catid])) {
  901. if($permission[$catid]['allowmanage'] || (empty($aid) && $permission[$catid]['allowpublish'])) {
  902. return true;
  903. }
  904. }
  905. if(!$isverify && $aid && !empty($article['uid']) && $article['uid'] == $_G['uid'] && ($article['status'] == 1 && $_G['group']['allowpostarticlemod'] || empty($_G['group']['allowpostarticlemod']))) {
  906. return true;
  907. }
  908. if(!$return) {
  909. showmessage('article_edit_nopermission');
  910. } else {
  911. return 'article_edit_nopermission';
  912. }
  913. }
  914. function addportalarticlecomment($id, $message, $idtype = 'aid') {
  915. global $_G;
  916. $id = intval($id);
  917. if(empty($id)) {
  918. return 'comment_comment_noexist';
  919. }
  920. $message = getstr($message, $_G['group']['allowcommentarticle'], 0, 0, 1, 0);
  921. if(strlen($message) < 2) return 'content_is_too_short';
  922. $idtype = in_array($idtype, array('aid' ,'topicid')) ? $idtype : 'aid';
  923. $tablename = $idtype == 'aid' ? 'portal_article_title' : 'portal_topic';
  924. $data = C::t($tablename)->fetch($id);
  925. if(empty($data)) {
  926. return 'comment_comment_noexist';
  927. }
  928. if($data['allowcomment'] != 1) {
  929. return 'comment_comment_notallowed';
  930. }
  931. $message = censor($message);
  932. if(censormod($message)) {
  933. $comment_status = 1;
  934. } else {
  935. $comment_status = 0;
  936. }
  937. $setarr = array(
  938. 'uid' => $_G['uid'],
  939. 'username' => $_G['username'],
  940. 'id' => $id,
  941. 'idtype' => $idtype,
  942. 'postip' => $_G['clientip'],
  943. 'dateline' => $_G['timestamp'],
  944. 'status' => $comment_status,
  945. 'message' => $message
  946. );
  947. $pcid = C::t('portal_comment')->insert($setarr, true);
  948. if($comment_status == 1) {
  949. updatemoderate($idtype.'_cid', $pcid);
  950. $notifykey = $idtype == 'aid' ? 'verifyacommont' : 'verifytopiccommont';
  951. manage_addnotify($notifykey);
  952. }
  953. $tablename = $idtype == 'aid' ? 'portal_article_count' : 'portal_topic';
  954. C::t($tablename)->increase($id, array('commentnum' => 1));
  955. C::t('common_member_status')->update($_G['uid'], array('lastpost' => $_G['timestamp']), 'UNBUFFERED');
  956. if($data['uid'] != $_G['uid']) {
  957. updatecreditbyaction('portalcomment', 0, array(), $idtype.$id);
  958. }
  959. return 'do_success';
  960. }
  961. function trimdxtpllang($s){
  962. return str_replace(array('{', '$', '<', '>'), array('{ ', '$ ', '', ''), $s);
  963. }
  964. function addrelatedarticle($aid, $raids) {
  965. C::t('portal_article_related')->delete_by_aid_raid($aid, $aid);
  966. if($raids) {
  967. $relatedarr = array();
  968. $relatedarr = array_map('intval', $raids);
  969. $relatedarr = array_unique($relatedarr);
  970. $relatedarr = array_filter($relatedarr);
  971. if($relatedarr) {
  972. $list = C::t('portal_article_title')->fetch_all($relatedarr);
  973. C::t('portal_article_related')->insert_batch($aid, $list);
  974. }
  975. }
  976. return true;
  977. }
  978. function getprimaltplname($filename) {
  979. global $_G, $lang;
  980. $tpldirectory = '';
  981. if(strpos($filename, ':') !== false) {
  982. list($tpldirectory, $filename) = explode(':', $filename);
  983. }
  984. if(empty($tpldirectory)) {
  985. $tpldirectory = ($_G['cache']['style_default']['tpldir'] ? $_G['cache']['style_default']['tpldir'] : './template/default');
  986. }
  987. $content = @file_get_contents(DISCUZ_ROOT.$tpldirectory.'/'.$filename);
  988. $name = $tpldirectory.'/'.$filename;
  989. if($content) {
  990. preg_match("/\<\!\-\-\[name\](.+?)\[\/name\]\-\-\>/i", trim($content), $mathes);
  991. if(!empty($mathes[1])) {
  992. preg_match("/^\{lang (.+?)\}$/", $mathes[1], $langs);
  993. if(!empty($langs[1])) {
  994. $name = !$lang[$langs[1]] ? $langs[1] : $lang[$langs[1]];
  995. } else {
  996. $name = dhtmlspecialchars($mathes[1]);
  997. }
  998. }
  999. }
  1000. return $name;
  1001. }
  1002. function getdiydirectory($value) {
  1003. $directory = '';
  1004. if($value && strpos($value, ':') !== false) {
  1005. list($directory) = explode(':', $value);
  1006. }
  1007. return $directory;
  1008. }
  1009. ?>