function_blog.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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_blog.php 36278 2016-12-09 07:52:35Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function blog_check_url($url) {
  12. $url = durlencode(trim($url));
  13. if(preg_match("/^(https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\//i", $url)) {
  14. $return = '<a href="'.$url.'" target="_blank">';
  15. } else {
  16. $return = '<a href="'.(!empty($GLOBALS['_G']['siteurl']) ? $GLOBALS['_G']['siteurl'] : 'http://').$url.'" target="_blank">';
  17. }
  18. return $return;
  19. }
  20. function blog_post($POST, $olds=array()) {
  21. global $_G, $space;
  22. $isself = 1;
  23. if(!empty($olds['uid']) && $olds['uid'] != $_G['uid']) {
  24. $isself = 0;
  25. $__G = $_G;
  26. $_G['uid'] = $olds['uid'];
  27. $_G['username'] = addslashes($olds['username']);
  28. }
  29. $POST['subject'] = getstr(trim($POST['subject']), 80);
  30. $POST['subject'] = censor($POST['subject']);
  31. if(strlen($POST['subject'])<1) $POST['subject'] = dgmdate($_G['timestamp'], 'Y-m-d');
  32. $POST['friend'] = intval($POST['friend']);
  33. $POST['target_ids'] = '';
  34. if($POST['friend'] == 2) {
  35. $uids = array();
  36. $names = empty($_POST['target_names'])?array():explode(',', preg_replace("/(\s+)/s", ',', $_POST['target_names']));
  37. if($names) {
  38. $uids = C::t('common_member')->fetch_all_uid_by_username($names);
  39. }
  40. if(empty($uids)) {
  41. $POST['friend'] = 3;
  42. } else {
  43. $POST['target_ids'] = implode(',', $uids);
  44. }
  45. } elseif($POST['friend'] == 4) {
  46. $POST['password'] = trim($POST['password']);
  47. if($POST['password'] == '') $POST['friend'] = 0;
  48. }
  49. if($POST['friend'] !== 2) {
  50. $POST['target_ids'] = '';
  51. }
  52. if($POST['friend'] !== 4) {
  53. $POST['password'] == '';
  54. }
  55. $POST['tag'] = dhtmlspecialchars(trim($POST['tag']));
  56. $POST['tag'] = getstr($POST['tag'], 500);
  57. $POST['tag'] = censor($POST['tag']);
  58. $POST['message'] = checkhtml($POST['message']);
  59. if($_G['mobile']) {
  60. $POST['message'] = getstr($POST['message'], 0, 0, 0, 1);
  61. $POST['message'] = censor($POST['message']);
  62. } else {
  63. $POST['message'] = getstr($POST['message'], 0, 0, 0, 0, 1);
  64. $POST['message'] = censor($POST['message']);
  65. $POST['message'] = preg_replace("/\<div\>\<\/div\>/i", '', $POST['message']);
  66. $POST['message'] = preg_replace_callback("/\<a\s+href\=\"([^\>]+?)\"\>/i", 'blog_post_callback_blog_check_url_1', $POST['message']);
  67. }
  68. $message = $POST['message'];
  69. if(censormod($message) || censormod($POST['subject']) || $_G['group']['allowblogmod']) {
  70. $blog_status = 1;
  71. } else {
  72. $blog_status = 0;
  73. }
  74. if(empty($olds['classid']) || $POST['classid'] != $olds['classid']) {
  75. if(!empty($POST['classid']) && substr($POST['classid'], 0, 4) == 'new:') {
  76. $classname = dhtmlspecialchars(trim(substr($POST['classid'], 4)));
  77. $classname = getstr($classname);
  78. $classname = censor($classname);
  79. if(empty($classname)) {
  80. $classid = 0;
  81. } else {
  82. $classid = C::t('home_class')->fetch_classid_by_uid_classname($_G['uid'], $classname);
  83. if(empty($classid)) {
  84. $setarr = array(
  85. 'classname' => $classname,
  86. 'uid' => $_G['uid'],
  87. 'dateline' => $_G['timestamp']
  88. );
  89. $classid = C::t('home_class')->insert($setarr, true);
  90. }
  91. }
  92. } else {
  93. $classid = intval($POST['classid']);
  94. }
  95. } else {
  96. $classid = $olds['classid'];
  97. }
  98. if($classid && empty($classname)) {
  99. $query = C::t('home_class')->fetch($classid);
  100. $classname = ($query['uid'] == $_G['uid']) ? $query['classname'] : '';
  101. if(empty($classname)) $classid = 0;
  102. }
  103. $blogarr = array(
  104. 'subject' => $POST['subject'],
  105. 'classid' => $classid,
  106. 'friend' => $POST['friend'],
  107. 'password' => $POST['password'],
  108. 'noreply' => empty($POST['noreply'])?0:1,
  109. 'catid' => intval($POST['catid']),
  110. 'status' => $blog_status,
  111. );
  112. $titlepic = '';
  113. $uploads = array();
  114. if(!empty($POST['picids'])) {
  115. $picids = array_keys($POST['picids']);
  116. $query = C::t('home_pic')->fetch_all_by_uid($_G['uid'], 0, 0, $picids);
  117. foreach($query as $value) {
  118. if(empty($titlepic) && $value['thumb']) {
  119. $titlepic = getimgthumbname($value['filepath']);
  120. $blogarr['picflag'] = $value['remote']?2:1;
  121. }
  122. $picurl = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote'], 0);
  123. $uploads[md5($picurl)] = $value;
  124. }
  125. if(empty($titlepic) && $value) {
  126. $titlepic = $value['filepath'];
  127. $blogarr['picflag'] = $value['remote']?2:1;
  128. }
  129. }
  130. if($uploads) {
  131. $albumid = 0;
  132. if($POST['savealbumid'] < 0 && !empty($POST['newalbum'])) {
  133. $albumname = addslashes(dhtmlspecialchars(trim($POST['newalbum'])));
  134. if(empty($albumname)) $albumname = dgmdate($_G['timestamp'],'Ymd');
  135. $albumarr = array('albumname' => $albumname);
  136. $albumid = album_creat($albumarr);
  137. } else {
  138. $albumid = $POST['savealbumid'] < 0 ? 0 : intval($POST['savealbumid']);
  139. }
  140. if($albumid) {
  141. C::t('home_pic')->update_for_uid($_G['uid'], $picids, array('albumid' => $albumid));
  142. album_update_pic($albumid);
  143. }
  144. preg_match_all("/\s*\<img src=\"(.+?)\".*?\>\s*/is", $message, $mathes);
  145. if(!empty($mathes[1])) {
  146. foreach ($mathes[1] as $key => $value) {
  147. $urlmd5 = md5($value);
  148. if(!empty($uploads[$urlmd5])) {
  149. unset($uploads[$urlmd5]);
  150. }
  151. }
  152. }
  153. foreach ($uploads as $value) {
  154. $picurl = pic_get($value['filepath'], 'album', $value['thumb'], $value['remote'], 0);
  155. $message .= "<div class=\"uchome-message-pic\"><img src=\"$picurl\"><p>$value[title]</p></div>";
  156. }
  157. }
  158. $ckmessage = preg_replace("/(\<div\>|\<\/div\>|\s|\&nbsp\;|\<br\>|\<p\>|\<\/p\>)+/is", '', $message);
  159. if(empty($ckmessage)) {
  160. return false;
  161. }
  162. if(checkperm('manageblog')) {
  163. $blogarr['hot'] = intval($POST['hot']);
  164. }
  165. if($olds['blogid']) {
  166. if($blogarr['catid'] != $olds['catid']) {
  167. if($olds['catid']) {
  168. C::t('home_blog_category')->update_num_by_catid(-1, $olds['catid'], true, true);
  169. }
  170. if($blogarr['catid']) {
  171. C::t('home_blog_category')->update_num_by_catid(1, $blogarr['catid']);
  172. }
  173. }
  174. $blogid = $olds['blogid'];
  175. C::t('home_blog')->update($blogid, $blogarr);
  176. $fuids = array();
  177. $blogarr['uid'] = $olds['uid'];
  178. $blogarr['username'] = $olds['username'];
  179. } else {
  180. if($blogarr['catid']) {
  181. C::t('home_blog_category')->update_num_by_catid(1, $blogarr['catid']);
  182. }
  183. $blogarr['uid'] = $_G['uid'];
  184. $blogarr['username'] = $_G['username'];
  185. $blogarr['dateline'] = empty($POST['dateline'])?$_G['timestamp']:$POST['dateline'];
  186. $blogid = C::t('home_blog')->insert($blogarr, true);
  187. C::t('common_member_status')->update($_G['uid'], array('lastpost' => $_G['timestamp']));
  188. C::t('common_member_field_home')->update($_G['uid'], array('recentnote'=>$POST['subject']));
  189. }
  190. $blogarr['blogid'] = $blogid;
  191. $class_tag = new tag();
  192. $POST['tag'] = $olds ? $class_tag->update_field($POST['tag'], $blogid, 'blogid') : $class_tag->add_tag($POST['tag'], $blogid, 'blogid');
  193. $fieldarr = array(
  194. 'message' => $message,
  195. 'postip' => $_G['clientip'],
  196. 'port' => $_G['remoteport'],
  197. 'target_ids' => $POST['target_ids'],
  198. 'tag' => $POST['tag']
  199. );
  200. if(!empty($titlepic)) {
  201. $fieldarr['pic'] = $titlepic;
  202. }
  203. if($olds) {
  204. C::t('home_blogfield')->update($blogid, $fieldarr);
  205. } else {
  206. $fieldarr['blogid'] = $blogid;
  207. $fieldarr['uid'] = $blogarr['uid'];
  208. C::t('home_blogfield')->insert($fieldarr);
  209. }
  210. if($isself && !$olds && $blog_status == 0) {
  211. updatecreditbyaction('publishblog', 0, array('blogs' => 1));
  212. include_once libfile('function/stat');
  213. updatestat('blog');
  214. }
  215. if($olds['blogid'] && $blog_status == 1) {
  216. updatecreditbyaction('publishblog', 0, array('blogs' => -1), '', -1);
  217. include_once libfile('function/stat');
  218. updatestat('blog');
  219. }
  220. if($POST['makefeed'] && $blog_status == 0) {
  221. include_once libfile('function/feed');
  222. feed_publish($blogid, 'blogid', $olds?0:1);
  223. }
  224. if(!empty($__G)) $_G = $__G;
  225. if($blog_status == 1) {
  226. updatemoderate('blogid', $blogid);
  227. manage_addnotify('verifyblog');
  228. }
  229. return $blogarr;
  230. }
  231. function blog_post_callback_blog_check_url_1($matches) {
  232. return blog_check_url($matches[1]);
  233. }
  234. function checkhtml($html) {
  235. if(!checkperm('allowhtml')) {
  236. preg_match_all("/\<([^\<]+)\>/is", $html, $ms);
  237. $searchs[] = '<';
  238. $replaces[] = '&lt;';
  239. $searchs[] = '>';
  240. $replaces[] = '&gt;';
  241. if($ms[1]) {
  242. $allowtags = 'img|a|font|div|table|tbody|caption|tr|td|th|br|p|b|strong|i|u|em|span|ol|ul|li|blockquote';
  243. $ms[1] = array_unique($ms[1]);
  244. foreach ($ms[1] as $value) {
  245. $searchs[] = "&lt;".$value."&gt;";
  246. $value = str_replace('&amp;', '_uch_tmp_str_', $value);
  247. $value = dhtmlspecialchars($value);
  248. $value = str_replace('_uch_tmp_str_', '&amp;', $value);
  249. $value = str_replace(array('\\','/*'), array('.','/.'), $value);
  250. $skipkeys = array('onabort','onactivate','onafterprint','onafterupdate','onbeforeactivate','onbeforecopy','onbeforecut','onbeforedeactivate',
  251. 'onbeforeeditfocus','onbeforepaste','onbeforeprint','onbeforeunload','onbeforeupdate','onblur','onbounce','oncellchange','onchange',
  252. 'onclick','oncontextmenu','oncontrolselect','oncopy','oncut','ondataavailable','ondatasetchanged','ondatasetcomplete','ondblclick',
  253. 'ondeactivate','ondrag','ondragend','ondragenter','ondragleave','ondragover','ondragstart','ondrop','onerror','onerrorupdate',
  254. 'onfilterchange','onfinish','onfocus','onfocusin','onfocusout','onhelp','onkeydown','onkeypress','onkeyup','onlayoutcomplete',
  255. 'onload','onlosecapture','onmousedown','onmouseenter','onmouseleave','onmousemove','onmouseout','onmouseover','onmouseup','onmousewheel',
  256. 'onmove','onmoveend','onmovestart','onpaste','onpropertychange','onreadystatechange','onreset','onresize','onresizeend','onresizestart',
  257. 'onrowenter','onrowexit','onrowsdelete','onrowsinserted','onscroll','onselect','onselectionchange','onselectstart','onstart','onstop',
  258. 'onsubmit','onunload','javascript','script','eval','behaviour','expression','style','class');
  259. $skipstr = implode('|', $skipkeys);
  260. $value = preg_replace(array("/($skipstr)/i"), '.', $value);
  261. if(!preg_match("/^[\/|\s]?($allowtags)(\s+|$)/is", $value)) {
  262. $value = '';
  263. }
  264. $replaces[] = empty($value)?'':"<".str_replace('&quot;', '"', $value).">";
  265. }
  266. }
  267. $html = str_replace($searchs, $replaces, $html);
  268. }
  269. return $html;
  270. }
  271. function blog_bbcode($message) {
  272. $message = preg_replace_callback("/\[flash\=?(media|real|mp3)*\](.+?)\[\/flash\]/i", 'blog_bbcode_callback_blog_flash_21', $message);
  273. return $message;
  274. }
  275. function blog_bbcode_callback_blog_flash_21($matches) {
  276. return blog_flash($matches[2], $matches[1]);
  277. }
  278. function blog_flash($swf_url, $type='') {
  279. $width = '520';
  280. $height = '390';
  281. preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", $swf_url, $matches);
  282. $swf_url = $matches[0];
  283. if ($type == 'media') {
  284. $html = '<object classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" width="'.$width.'" height="'.$height.'">
  285. <param name="autostart" value="0">
  286. <param name="url" value="'.$swf_url.'">
  287. <embed autostart="false" src="'.$swf_url.'" type="video/x-ms-wmv" width="'.$width.'" height="'.$height.'" controls="imagewindow" console="cons"></embed>
  288. </object>';
  289. } elseif ($type == 'real') {
  290. $html = '<object classid="clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa" width="'.$width.'" height="'.$height.'">
  291. <param name="autostart" value="0">
  292. <param name="src" value="'.$swf_url.'">
  293. <param name="controls" value="Imagewindow,controlpanel">
  294. <param name="console" value="cons">
  295. <embed autostart="false" src="'.$swf_url.'" type="audio/x-pn-realaudio-plugin" width="'.$width.'" height="'.$height.'" controls="controlpanel" console="cons"></embed>
  296. </object>';
  297. } elseif ($type == 'mp3') {
  298. $swf_url = urlencode(str_replace('&amp;', '&', $swf_url));
  299. $html = '<object id="audioplayer_SHAREID" height="24" width="290" data="'.STATICURL.'image/common/player.swf" type="application/x-shockwave-flash">
  300. <param value="'.STATICURL.'image/common/player.swf" name="movie"/>
  301. <param value="autostart=yes&bg=0xCDDFF3&leftbg=0x357DCE&lefticon=0xF2F2F2&rightbg=0xF06A51&rightbghover=0xAF2910&righticon=0xF2F2F2&righticonhover=0xFFFFFF&text=0x357DCE&slider=0x357DCE&track=0xFFFFFF&border=0xFFFFFF&loader=0xAF2910&soundFile='.$swf_url.'" name="FlashVars"/>
  302. <param value="high" name="quality"/>
  303. <param value="false" name="menu"/>
  304. <param name="allowscriptaccess" value="never">
  305. <param name="allowNetworking" value="internal">
  306. <param value="#FFFFFF" name="bgcolor"/>
  307. </object>';
  308. } else {
  309. $extname = substr($swf_url, strrpos($swf_url, '.')+1);
  310. $randomid = 'swf_'.random(3);
  311. if($extname == 'swf') {
  312. $html = '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'width\', \''.$width.'\', \'height\', \''.$height.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', encodeURI(\''.$swf_url.'\'), \'quality\', \'high\', \'bgcolor\', \'#ffffff\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  313. } else {
  314. $html = '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'width\', \''.$width.'\', \'height\', \''.$height.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.STATICURL.'image/common/flvplayer.swf\', \'flashvars\', \'file='.rawurlencode($swf_url).'\', \'quality\', \'high\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  315. }
  316. }
  317. return $html;
  318. }
  319. ?>