PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/source/function/function_blog.php

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