function_portalcp.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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 35943 2016-05-18 03:26:08Z nemohou $
  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. if(preg_match("/[^a-z0-9:;'\(\)!\.#\-_\s\{\}\/\,\"\?\>\=\?\%]+/i", $str)) {
  401. showmessage('css_contains_elements_of_insecurity');
  402. }
  403. $str = preg_replace($filter, '', $str);
  404. if(preg_match("/(expression|import|javascript)/i", $str)) {
  405. showmessage('css_contains_elements_of_insecurity');
  406. }
  407. return true;
  408. }
  409. function block_export($bids) {
  410. $return = array('block'=>array(), 'style'=>array());
  411. if(empty($bids)) {
  412. return;
  413. }
  414. $styleids = array();
  415. foreach(C::t('common_block')->fetch_all($bids) as $value) {
  416. $value['param'] = dunserialize($value['param']);
  417. if(!empty($value['blockstyle'])) $value['blockstyle'] = dunserialize($value['blockstyle']);
  418. $return['block'][$value['bid']] = $value;
  419. if(!empty($value['styleid'])) $styleids[] = intval($value['styleid']);
  420. }
  421. if($styleids) {
  422. $styleids = array_unique($styleids);
  423. foreach(C::t('common_block_style')->fetch_all($styleids) as $value) {
  424. $value['template'] = dunserialize($value['template']);
  425. if(!empty($value['fields'])) $value['fields'] = dunserialize($value['fields']);
  426. $return['style'][$value['styleid']] = $value;
  427. }
  428. }
  429. return $return ;
  430. }
  431. function block_import($data) {
  432. global $_G;
  433. if(!is_array($data['block'])) {
  434. return ;
  435. }
  436. $stylemapping = array();
  437. if($data['style']) {
  438. $hashes = $styles = array();
  439. foreach($data['style'] as $value) {
  440. $hashes[] = $value['hash'];
  441. $styles[$value['hash']] = $value['styleid'];
  442. }
  443. if(!empty($hashes)) {
  444. foreach(C::t('common_block_style')->fetch_all_by_hash($hashes) as $value) {
  445. $id = $styles[$value['hash']];
  446. $stylemapping[$id] = intval($value['styleid']);
  447. unset($styles[$value['hash']]);
  448. }
  449. }
  450. foreach($styles as $id) {
  451. $style = $data['style'][$id];
  452. $style['styleid'] = '';
  453. if(is_array($style['template'])) {
  454. $style['template'] = serialize($style['template']);
  455. }
  456. if(is_array($style['fields'])) {
  457. $style['fields'] = serialize($style['fields']);
  458. }
  459. $newid = C::t('common_block_style')->insert($style, true);
  460. $stylemapping[$id] = $newid;
  461. }
  462. }
  463. $blockmapping = array();
  464. foreach($data['block'] as $block) {
  465. $oid = $block['bid'];
  466. if(!empty($block['styleid'])) {
  467. $block['styleid'] = intval($stylemapping[$block['styleid']]);
  468. }
  469. $block['bid'] = '';
  470. $block['uid'] = $_G['uid'];
  471. $block['username'] = $_G['username'];
  472. $block['dateline'] = 0;
  473. $block['notinherited'] = 0;
  474. if(is_array($block['param'])) {
  475. $block['param'] = serialize($block['param']);
  476. }
  477. if(is_array($block['blockstyle'])) {
  478. $block['blockstyle'] = serialize($block['blockstyle']);
  479. }
  480. $newid = C::t('common_block')->insert($block, true);
  481. $blockmapping[$oid] = $newid;
  482. }
  483. include_once libfile('function/cache');
  484. updatecache('blockclass');
  485. return $blockmapping;
  486. }
  487. function getobjbyname($name, $data) {
  488. if (!$name || !$data) return false;
  489. foreach ((array)$data as $id => $content) {
  490. list($type, $curname) = explode('`', $id);
  491. if ($curname == $name) {
  492. return array('type'=>$type,'content'=>$content);
  493. } elseif ($type == 'frame' || $type == 'tab' || $type == 'column') {
  494. $r = getobjbyname($name, $content);
  495. if ($r) return $r;
  496. }
  497. }
  498. return false;
  499. }
  500. function getframeblock($data) {
  501. global $_G;
  502. if (!isset($_G['curtplbid'])) $_G['curtplbid'] = array();
  503. if (!isset($_G['curtplframe'])) $_G['curtplframe'] = array();
  504. foreach ((array)$data as $id => $content) {
  505. list($flag, $name) = explode('`', $id);
  506. if ($flag == 'frame' || $flag == 'tab') {
  507. foreach ((array)$content as $colid => $coldata) {
  508. list($colflag, $colname) = explode('`', $colid);
  509. if ($colflag == 'column') {
  510. getframeblock($coldata,$framename);
  511. }
  512. }
  513. $_G['curtplframe'][$name] = array('type'=>$flag,'name'=>$name);
  514. } elseif ($flag == 'block') {
  515. $battr = $content['attr'];
  516. $bid = intval(str_replace('portal_block_', '', $battr['name']));
  517. if (!empty($bid)) {
  518. $_G['curtplbid'][$bid] = $bid;
  519. }
  520. }
  521. }
  522. }
  523. function getcssdata($css) {
  524. global $_G;
  525. if (empty($css)) return '';
  526. $reglist = array();
  527. foreach ((array)$_G['curtplframe'] as $value) {
  528. $reglist[] = '#'.$value['name'].'.*?\{.*?\}';
  529. }
  530. foreach ((array)$_G['curtplbid'] as $value) {
  531. $reglist[] = '#portal_block_'.$value.'.*?\{.*?\}';
  532. }
  533. $reg = implode('|',$reglist);
  534. preg_match_all('/'.$reg.'/',$css,$csslist);
  535. return implode('', $csslist[0]);
  536. }
  537. function import_diy($file) {
  538. global $_G;
  539. $css = '';
  540. $html = array();
  541. $arr = array();
  542. $content = file_get_contents($file);
  543. require_once libfile('class/xml');
  544. if (empty($content)) return $arr;
  545. $content = preg_replace("/\<\!\-\-\[name\](.+?)\[\/name\]\-\-\>\s+/i", '', $content);
  546. $diycontent = xml2array($content);
  547. if ($diycontent) {
  548. foreach ($diycontent['layoutdata'] as $key => $value) {
  549. if (!empty($value)) getframeblock($value);
  550. }
  551. $newframe = array();
  552. foreach ($_G['curtplframe'] as $value) {
  553. $newframe[] = $value['type'].random(6);
  554. }
  555. $mapping = array();
  556. if (!empty($diycontent['blockdata'])) {
  557. $mapping = block_import($diycontent['blockdata']);
  558. unset($diycontent['blockdata']);
  559. }
  560. $oldbids = $newbids = array();
  561. if (!empty($mapping)) {
  562. foreach($mapping as $obid=>$nbid) {
  563. $oldbids[] = '#portal_block_'.$obid.' ';
  564. $newbids[] = '#portal_block_'.$nbid.' ';
  565. $oldbids[] = '[portal_block_'.$obid.']';
  566. $newbids[] = '[portal_block_'.$nbid.']';
  567. $oldbids[] = '~portal_block_'.$obid.'"';
  568. $newbids[] = '~portal_block_'.$nbid.'"';
  569. }
  570. }
  571. require_once libfile('class/xml');
  572. $xml = array2xml($diycontent['layoutdata'],true);
  573. $xml = str_replace($oldbids, $newbids, $xml);
  574. $xml = str_replace((array)array_keys($_G['curtplframe']), $newframe, $xml);
  575. $diycontent['layoutdata'] = xml2array($xml);
  576. $css = str_replace($oldbids, $newbids, $diycontent['spacecss']);
  577. $css = str_replace((array)array_keys($_G['curtplframe']), $newframe, $css);
  578. foreach ($diycontent['layoutdata'] as $key => $value) {
  579. $html[$key] = getframehtml($value);
  580. }
  581. }
  582. if (!empty($html)) {
  583. $xml = array2xml($html, true);
  584. require_once libfile('function/block');
  585. block_get_batch(implode(',', $mapping));
  586. foreach ($mapping as $bid) {
  587. $blocktag[] = '<!--{block/'.$bid.'}-->';
  588. $blockcontent[] = block_fetch_content($bid);
  589. }
  590. $xml = str_replace($blocktag,$blockcontent,$xml);
  591. $html = xml2array($xml);
  592. $arr = array('html'=>$html,'css'=>$css,'mapping'=>$mapping);
  593. }
  594. return $arr;
  595. }
  596. function checkprimaltpl($template) {
  597. global $_G;
  598. $tpldirectory = '';
  599. if(strpos($template, ':') !== false) {
  600. list($tpldirectory, $template) = explode(':', $template);
  601. }
  602. if(!$template || preg_match("/(\.)(exe|jsp|asp|aspx|cgi|fcgi|pl)(\.|$)/i", $template)) {
  603. return 'diy_template_filename_invalid';
  604. }
  605. if(strpos($template, '..') !== false || strpos($template, "\0") !== false) {
  606. return 'diy_template_filename_invalid';
  607. }
  608. $tpldirectoryarr = explode('/', trim($tpldirectory, './'));
  609. if(strpos($tpldirectory, '..') !== false || strpos($tpldirectory, "\0") !== false || ($tpldirectoryarr[0] != 'template' && $tpldirectoryarr[0] != 'source')) {
  610. return 'diy_tpldirectory_invalid';
  611. }
  612. $primaltplname = (!$tpldirectory ? DISCUZ_ROOT.$_G['cache']['style_default']['tpldir'] : $tpldirectory).'/'.$template.'.htm';
  613. if (!file_exists($primaltplname)) {
  614. $primaltplname = DISCUZ_ROOT.'./template/default/'.$template.'.htm';
  615. }
  616. $pathinfos = pathinfo($primaltplname);
  617. if(strtolower($pathinfos['extension']) != 'htm') {
  618. return 'diy_template_extension_invalid';
  619. }
  620. if (!is_file($primaltplname)) {
  621. return 'diy_template_noexist';
  622. }
  623. return true;
  624. }
  625. function article_tagnames() {
  626. global $_G;
  627. if(!isset($_G['article_tagnames'])) {
  628. $_G['article_tagnames'] = array();
  629. for($i=1; $i<=8; $i++) {
  630. if(isset($_G['setting']['article_tags']) && isset($_G['setting']['article_tags'][$i])) {
  631. $_G['article_tagnames'][$i] = $_G['setting']['article_tags'][$i];
  632. } else {
  633. $_G['article_tagnames'][$i] = lang('portalcp', 'article_tag').$i;
  634. }
  635. }
  636. }
  637. return $_G['article_tagnames'];
  638. }
  639. function article_parse_tags($tag) {
  640. $tag = intval($tag);
  641. $article_tags = array();
  642. for($i=1; $i<=8; $i++) {
  643. $k = pow(2, $i-1);
  644. $article_tags[$i] = ($tag & $k) ? 1 : 0;
  645. }
  646. return $article_tags;
  647. }
  648. function article_make_tag($tags) {
  649. $tags = (array)$tags;
  650. $tag = 0;
  651. for($i=1; $i<=8; $i++) {
  652. if(!empty($tags[$i])) {
  653. $tag += pow(2, $i-1);
  654. }
  655. }
  656. return $tag;
  657. }
  658. function category_showselect($type, $name='catid', $shownull=true, $current='') {
  659. global $_G;
  660. if(! in_array($type, array('portal', 'blog', 'album'))) {
  661. return '';
  662. }
  663. loadcache($type.'category');
  664. $category = $_G['cache'][$type.'category'];
  665. $select = "<select id=\"$name\" name=\"$name\" class=\"ps vm\">";
  666. if($shownull) {
  667. $select .= '<option value="">'.lang('portalcp', 'select_category').'</option>';
  668. }
  669. foreach ($category as $value) {
  670. if($value['level'] == 0) {
  671. $selected = ($current && $current==$value['catid']) ? 'selected="selected"' : '';
  672. $select .= "<option value=\"$value[catid]\"$selected>$value[catname]</option>";
  673. if(!$value['children']) {
  674. continue;
  675. }
  676. foreach ($value['children'] as $catid) {
  677. $selected = ($current && $current==$catid) ? 'selected="selected"' : '';
  678. $select .= "<option value=\"{$category[$catid][catid]}\"$selected>-- {$category[$catid][catname]}</option>";
  679. if($category[$catid]['children']) {
  680. foreach ($category[$catid]['children'] as $catid2) {
  681. $selected = ($current && $current==$catid2) ? 'selected="selected"' : '';
  682. $select .= "<option value=\"{$category[$catid2][catid]}\"$selected>---- {$category[$catid2][catname]}</option>";
  683. }
  684. }
  685. }
  686. }
  687. }
  688. $select .= "</select>";
  689. return $select;
  690. }
  691. function category_get_childids($type, $catid, $depth=3) {
  692. global $_G;
  693. if(! in_array($type, array('portal', 'blog', 'album'))) {
  694. return array();
  695. }
  696. loadcache($type.'category');
  697. $category = $_G['cache'][$type.'category'];
  698. $catids = array();
  699. if(isset($category[$catid]) && !empty($category[$catid]['children']) && $depth) {
  700. $catids = $category[$catid]['children'];
  701. foreach($category[$catid]['children'] as $id) {
  702. $catids = array_merge($catids, category_get_childids($type, $id, $depth-1));
  703. }
  704. }
  705. return $catids;
  706. }
  707. function category_get_num($type, $catid) {
  708. global $_G;
  709. if(! in_array($type, array('portal', 'blog', 'album'))) {
  710. return array();
  711. }
  712. loadcache($type.'category');
  713. $category = $_G['cache'][$type.'category'];
  714. $numkey = $type == 'portal' ? 'articles' : 'num';
  715. if(! isset($_G[$type.'category_nums'])) {
  716. $_G[$type.'category_nums'] = array();
  717. $tables = array('portal'=>'portal_category', 'blog'=>'home_blog_category', 'album'=>'home_album_category');
  718. $query = C::t($tables[$type])->fetch_all_numkey($numkey);
  719. foreach ($query as $value) {
  720. $_G[$type.'category_nums'][$value['catid']] = intval($value[$numkey]);
  721. }
  722. }
  723. $nums = $_G[$type.'category_nums'];
  724. $num = intval($nums[$catid]);
  725. if($category[$catid]['children']) {
  726. foreach($category[$catid]['children'] as $id) {
  727. $num += category_get_num($type, $id);
  728. }
  729. }
  730. return $num;
  731. }
  732. function updatetopic($topic = ''){
  733. global $_G;
  734. $topicid = empty($topic) ? '' : $topic['topicid'];
  735. include_once libfile('function/home');
  736. $_POST['title'] = getstr(trim($_POST['title']), 255);
  737. $_POST['name'] = getstr(trim($_POST['name']), 255);
  738. $_POST['domain'] = getstr(trim($_POST['domain']), 255);
  739. if(empty($_POST['title'])) {
  740. return 'topic_title_cannot_be_empty';
  741. }
  742. if(empty($_POST['name'])) {
  743. $_POST['name'] = $_POST['title'];
  744. }
  745. if(!preg_match('/^[\w\_\.]+$/i', $_POST['name'])) {
  746. return 'topic_created_failed';
  747. }
  748. if(!$topicid || $_POST['name'] != $topic['name']) {
  749. if(($value = C::t('portal_topic')->fetch_by_name($_POST['name']))) {
  750. return 'topic_name_duplicated';
  751. }
  752. }
  753. if($topicid && !empty($topic['domain'])) {
  754. require_once libfile('function/delete');
  755. deletedomain($topicid, 'topic');
  756. }
  757. if(!empty($_POST['domain'])) {
  758. require_once libfile('function/domain');
  759. domaincheck($_POST['domain'], $_G['setting']['domain']['root']['topic'], 1);
  760. }
  761. $setarr = array(
  762. 'title' => $_POST['title'],
  763. 'name' => $_POST['name'],
  764. 'domain' => $_POST['domain'],
  765. 'summary' => getstr($_POST['summary']),
  766. 'keyword' => getstr($_POST['keyword']),
  767. 'useheader' => $_POST['useheader'] ? '1' : '0',
  768. 'usefooter' => $_POST['usefooter'] ? '1' : '0',
  769. 'allowcomment' => $_POST['allowcomment'] ? 1 : 0,
  770. 'closed' => $_POST['closed'] ? 0 : 1,
  771. );
  772. if($_POST['deletecover'] && $topic['cover']) {
  773. if($topic['picflag'] != '0') pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0');
  774. $setarr['cover'] = '';
  775. } else {
  776. if($_FILES['cover']['tmp_name']) {
  777. if($topic['cover'] && $topic['picflag'] != '0') pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0');
  778. $pic = pic_upload($_FILES['cover'], 'portal');
  779. if($pic) {
  780. $setarr['cover'] = 'portal/'.$pic['pic'];
  781. $setarr['picflag'] = $pic['remote'] ? '2' : '1';
  782. }
  783. } else {
  784. if(!empty($_POST['cover']) && $_POST['cover'] != $topic['cover']) {
  785. if($topic['cover'] && $topic['picflag'] != '0') pic_delete(str_replace('portal/', '', $topic['cover']), 'portal', 0, $topic['picflag'] == '2' ? '1' : '0');
  786. $setarr['cover'] = $_POST['cover'];
  787. $setarr['picflag'] = '0';
  788. }
  789. }
  790. }
  791. $primaltplname = '';
  792. if(empty($topicid) || empty($topic['primaltplname']) || ($topic['primaltplname'] && $topic['primaltplname'] != $_POST['primaltplname'])) {
  793. $primaltplname = $_POST['primaltplname'];
  794. if(!isset($_POST['signs'][dsign($primaltplname)])) {
  795. return 'diy_sign_invalid';
  796. }
  797. $checktpl = checkprimaltpl($primaltplname);
  798. if($checktpl !== true) {
  799. return $checktpl;
  800. }
  801. $setarr['primaltplname'] = $primaltplname;
  802. }
  803. if($topicid) {
  804. C::t('portal_topic')->update($topicid, $setarr);
  805. C::t('common_diy_data')->update('portal/portal_topic_content_'.$topicid, getdiydirectory($topic['primaltplname']), array('name'=>$setarr['title']));
  806. } else {
  807. $setarr['uid'] = $_G['uid'];
  808. $setarr['username'] = $_G['username'];
  809. $setarr['dateline'] = $_G['timestamp'];
  810. $setarr['closed'] = '1';
  811. $topicid = addtopic($setarr);
  812. if(!$topicid) {
  813. return 'topic_created_failed';
  814. }
  815. }
  816. if(!empty($_POST['domain'])) {
  817. C::t('common_domain')->insert(array('domain' => $_POST['domain'], 'domainroot' => $_G['setting']['domain']['root']['topic'], 'id' => $topicid, 'idtype' => 'topic'));
  818. }
  819. $tpldirectory = '';
  820. if($primaltplname && $topic['primaltplname'] != $primaltplname) {
  821. $targettplname = 'portal/portal_topic_content_'.$topicid;
  822. if(strpos($primaltplname, ':') !== false) {
  823. list($tpldirectory, $primaltplname) = explode(':', $primaltplname);
  824. }
  825. C::t('common_diy_data')->update($targettplname, getdiydirectory($topic['primaltplname']), array('primaltplname'=>$primaltplname, 'tpldirectory'=>$tpldirectory));
  826. updatediytemplate($targettplname);
  827. }
  828. if($primaltplname && empty($topic['primaltplname'])) {
  829. $tpldirectory = ($tpldirectory ? $tpldirectory : $_G['cache']['style_default']['tpldir']);
  830. $content = file_get_contents(DISCUZ_ROOT.$tpldirectory.'/'.$primaltplname.'.htm');
  831. $tplfile = DISCUZ_ROOT.'./data/diy/'.$tpldirectory.'/portal/portal_topic_content_'.$topicid.'.htm';
  832. $tplpath = dirname($tplfile);
  833. if (!is_dir($tplpath)) {
  834. dmkdir($tplpath);
  835. }
  836. file_put_contents($tplfile, $content);
  837. }
  838. include_once libfile('function/cache');
  839. updatecache(array('diytemplatename', 'setting'));
  840. return $topicid;
  841. }
  842. function addtopic($topic) {
  843. global $_G;
  844. $topicid = '';
  845. if($topic && is_array($topic)) {
  846. $topicid = C::t('portal_topic')->insert($topic, true);
  847. if(!empty($topicid)) {
  848. $diydata = array(
  849. 'targettplname' => 'portal/portal_topic_content_'.$topicid,
  850. 'name' => $topic['title'],
  851. 'uid' => $_G['uid'],
  852. 'username' => $_G['username'],
  853. 'dateline' => TIMESTAMP,
  854. );
  855. C::t('common_diy_data')->insert($diydata);
  856. }
  857. }
  858. return $topicid;
  859. }
  860. function getblockperm($bid) {
  861. global $_G;
  862. $perm = array('allowmanage'=>'0','allowrecommend'=>'0','needverify'=>'1');
  863. $bid = max(0, intval($bid));
  864. if(!$bid) return $perm;
  865. $allperm = array('allowmanage'=>'1','allowrecommend'=>'1','needverify'=>'0');
  866. if(checkperm('allowdiy')) {
  867. return $allperm;
  868. } elseif (!getstatus($_G['member']['allowadmincp'], 4) && !getstatus($_G['member']['allowadmincp'], 5) && !getstatus($_G['member']['allowadmincp'], 6) && !checkperm('allowmanagetopic') && !checkperm('allowaddtopic')) {
  869. return $perm;
  870. }
  871. require_once libfile('class/blockpermission');
  872. $blockpermsission = & block_permission::instance();
  873. $perm = $blockpermsission->get_perms_by_bid($bid, $_G['uid']);
  874. $perm = $perm ? current($perm) : '';
  875. if(empty($perm)) {
  876. if(($block = C::t('common_block')->fetch($bid))) {
  877. $block = array_merge($block, C::t('common_template_block')->fetch_by_bid($bid));
  878. }
  879. if(empty($block['targettplname']) && empty($block['blocktype'])) {
  880. if(($_G['group']['allowmanagetopic'] || ($_G['group']['allowaddtopic'] && $block['uid'] == $_G['uid']))) {
  881. $perm = $allperm;
  882. }
  883. } elseif(substr($block['targettplname'], 0, 28) == 'portal/portal_topic_content_') {
  884. if(!empty($_G['group']['allowmanagetopic'])) {
  885. $perm = $allperm;
  886. } elseif($_G['group']['allowaddtopic']) {
  887. $id = str_replace('portal/portal_topic_content_', '', $block['targettplname']);
  888. $topic = C::t('portal_topic')->fetch(intval($id));
  889. if($topic['uid'] == $_G['uid']) {
  890. $perm = $allperm;
  891. }
  892. }
  893. }
  894. }
  895. return $perm;
  896. }
  897. function check_articleperm($catid, $aid = 0, $article = array(), $isverify = false, $return = false) {
  898. global $_G;
  899. if(empty($catid)) {
  900. if(!$return) {
  901. showmessage('article_category_empty');
  902. } else {
  903. return 'article_category_empty';
  904. }
  905. }
  906. if($_G['group']['allowmanagearticle'] || (empty($aid) && $_G['group']['allowpostarticle'])) {
  907. return true;
  908. }
  909. $permission = getallowcategory($_G['uid']);
  910. if(isset($permission[$catid])) {
  911. if($permission[$catid]['allowmanage'] || (empty($aid) && $permission[$catid]['allowpublish'])) {
  912. return true;
  913. }
  914. }
  915. if(!$isverify && $aid && !empty($article['uid']) && $article['uid'] == $_G['uid'] && ($article['status'] == 1 && $_G['group']['allowpostarticlemod'] || empty($_G['group']['allowpostarticlemod']))) {
  916. return true;
  917. }
  918. if(!$return) {
  919. showmessage('article_edit_nopermission');
  920. } else {
  921. return 'article_edit_nopermission';
  922. }
  923. }
  924. function addportalarticlecomment($id, $message, $idtype = 'aid') {
  925. global $_G;
  926. $id = intval($id);
  927. if(empty($id)) {
  928. return 'comment_comment_noexist';
  929. }
  930. $message = getstr($message, $_G['group']['allowcommentarticle'], 0, 0, 1, 0);
  931. if(strlen($message) < 2) return 'content_is_too_short';
  932. $idtype = in_array($idtype, array('aid' ,'topicid')) ? $idtype : 'aid';
  933. $tablename = $idtype == 'aid' ? 'portal_article_title' : 'portal_topic';
  934. $data = C::t($tablename)->fetch($id);
  935. if(empty($data)) {
  936. return 'comment_comment_noexist';
  937. }
  938. if($data['allowcomment'] != 1) {
  939. return 'comment_comment_notallowed';
  940. }
  941. $message = censor($message);
  942. if(censormod($message)) {
  943. $comment_status = 1;
  944. } else {
  945. $comment_status = 0;
  946. }
  947. $setarr = array(
  948. 'uid' => $_G['uid'],
  949. 'username' => $_G['username'],
  950. 'id' => $id,
  951. 'idtype' => $idtype,
  952. 'postip' => $_G['clientip'],
  953. 'port' => $_G['remoteport'],
  954. 'dateline' => $_G['timestamp'],
  955. 'status' => $comment_status,
  956. 'message' => $message
  957. );
  958. $pcid = C::t('portal_comment')->insert($setarr, true);
  959. if($comment_status == 1) {
  960. updatemoderate($idtype.'_cid', $pcid);
  961. $notifykey = $idtype == 'aid' ? 'verifyacommont' : 'verifytopiccommont';
  962. manage_addnotify($notifykey);
  963. }
  964. $tablename = $idtype == 'aid' ? 'portal_article_count' : 'portal_topic';
  965. C::t($tablename)->increase($id, array('commentnum' => 1));
  966. C::t('common_member_status')->update($_G['uid'], array('lastpost' => $_G['timestamp']), 'UNBUFFERED');
  967. if($data['uid'] != $_G['uid']) {
  968. updatecreditbyaction('portalcomment', 0, array(), $idtype.$id);
  969. }
  970. return 'do_success';
  971. }
  972. function trimdxtpllang($s){
  973. return str_replace(array('{', '$', '<', '>'), array('{ ', '$ ', '', ''), $s);
  974. }
  975. function addrelatedarticle($aid, $raids) {
  976. C::t('portal_article_related')->delete_by_aid_raid($aid, $aid);
  977. if($raids) {
  978. $relatedarr = array();
  979. $relatedarr = array_map('intval', $raids);
  980. $relatedarr = array_unique($relatedarr);
  981. $relatedarr = array_filter($relatedarr);
  982. if($relatedarr) {
  983. $list = C::t('portal_article_title')->fetch_all($relatedarr);
  984. C::t('portal_article_related')->insert_batch($aid, $list);
  985. }
  986. }
  987. return true;
  988. }
  989. function getprimaltplname($filename) {
  990. global $_G, $lang;
  991. $tpldirectory = '';
  992. if(strpos($filename, ':') !== false) {
  993. list($tpldirectory, $filename) = explode(':', $filename);
  994. }
  995. if(empty($tpldirectory)) {
  996. $tpldirectory = ($_G['cache']['style_default']['tpldir'] ? $_G['cache']['style_default']['tpldir'] : './template/default');
  997. }
  998. $content = @file_get_contents(DISCUZ_ROOT.$tpldirectory.'/'.$filename);
  999. $name = $tpldirectory.'/'.$filename;
  1000. if($content) {
  1001. preg_match("/\<\!\-\-\[name\](.+?)\[\/name\]\-\-\>/i", trim($content), $mathes);
  1002. if(!empty($mathes[1])) {
  1003. preg_match("/^\{lang (.+?)\}$/", $mathes[1], $langs);
  1004. if(!empty($langs[1])) {
  1005. $name = !$lang[$langs[1]] ? $langs[1] : $lang[$langs[1]];
  1006. } else {
  1007. $name = dhtmlspecialchars($mathes[1]);
  1008. }
  1009. }
  1010. }
  1011. return $name;
  1012. }
  1013. function getdiydirectory($value) {
  1014. $directory = '';
  1015. if($value && strpos($value, ':') !== false) {
  1016. list($directory) = explode(':', $value);
  1017. }
  1018. return $directory;
  1019. }
  1020. ?>