PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/apps/diary/action/my.php

https://bitbucket.org/johnroyer/phpwind8.7
PHP | 593 lines | 453 code | 80 blank | 60 comment | 136 complexity | 65de748e2c29702a731cad7686cb4141 MD5 | raw file
  1. <?php
  2. !defined('A_P') && exit('Forbidden');
  3. //TODO 刪除不用的請求處理分支,分離出ajax請求
  4. if(!$winduid){
  5. S::gp(array('a','q','did'));
  6. $did = (int)S::getGP('did');
  7. ('detail' !== $a) && ('diary' !== $q) && !is_numeric($did) && Showmsg("not_login");
  8. $diaryService = L::loadClass('Diary', 'diary');
  9. $diaryTemp = $diaryService->get($did);
  10. $url = $db_bbsurl."/apps.php?q=diary&a=detail&did=".$did."&uid=".$diaryTemp['uid'];
  11. ObHeader($url);
  12. }
  13. $USCR = 'user_diary';
  14. //TODO 暫時調用
  15. S::gp(array('s','diraryAjax'));
  16. if ($diraryAjax == 1) define('AJAX', '1');
  17. $a = isset($a) ? $a : 'list';
  18. $basename = 'apps.php?q='.$q.'&';
  19. $temp_basename = 'apps.php?q='.$q.'&a='.$a.'&';
  20. if ($a == 'list') {//我的日誌列表
  21. $dtid = (int)S::getGP('dtid');//TODO 查看日誌分類ID
  22. $diaryTypeId = $dtid == '-1' ? 0 : (is_numeric($dtid) && $dtid > 0 ? $dtid : null);
  23. $diaryPrivacy = $dtid == '-2' ? array(2) : array();
  24. $diaryService = L::loadClass('Diary', 'diary'); /* @var $diaryService PW_Diary */
  25. list($diaryNums, $diaryType, $defaultTypeNum, $privacyNum) = $diaryService->getDiaryTypeMode($winduid, 0); //TODO 右側分類Start
  26. $count = (int)$diaryService->countUserDiarys($winduid, $diaryTypeId, $diaryPrivacy);
  27. $page > ceil($count/$db_perpage) && $page = ceil($count/$db_perpage);
  28. $diaryDb = ($count) ? $diaryService->findUserDiarysInPage($winduid, $page, $db_perpage, $diaryTypeId, $diaryPrivacy) : array();
  29. $pages = numofpage($count,$page,ceil($count/$db_perpage),"{$basename}a=$a&dtid=$dtid&");
  30. } elseif ($a == 'detail') {//查看我的日誌
  31. $stylepath = L::style('stylepath');
  32. $did = (int)S::getGP('did');
  33. $fuid = (int)S::getGP('fuid');
  34. !$did && Showmsg("日誌不存在");
  35. $diaryService = L::loadClass('Diary', 'diary'); /* @var $diaryService PW_Diary */
  36. list($diaryNums, $diaryType, $defaultTypeNum, $privacyNum) = $diaryService->getDiaryTypeMode($winduid, 0);//TODO 右側分類Start
  37. $diaryTemp = $diaryService->get($did);
  38. if ($diaryTemp['uid'] != $winduid) {//轉跳處理
  39. $url = $db_bbsurl."/apps.php?q=diary&a=detail&did=".$did."&uid=".$diaryTemp['uid'];
  40. ObHeader($url);
  41. }
  42. $diary = $diaryService->getDiaryDbView($diaryTemp);
  43. list($commentdb,$subcommentdb,$pages) = getCommentDbByTypeid('diary',$did,$page,"{$basename}a={$a}&did={$did}&#createcommentbox");
  44. $comment_type = 'diary';
  45. $comment_typeid = $did;
  46. $myOuserData = array();
  47. $ouserdataService = L::loadClass('Ouserdata', 'sns'); /* @var $ouserdataService PW_Ouserdata */
  48. $myOuserData = $ouserdataService->get($winduid);
  49. $weiboPriv = false;
  50. if (!$myOuserData['index_privacy'] && !$myOuserData['diary_privacy'] && !$diary['privacy']){
  51. $weiboPriv = true;
  52. }
  53. $diaryNextName=getNextOrPreDiaryName($did, $fuid,'next');
  54. $diaryPreName=getNextOrPreDiaryName($did, $fuid,'pre');
  55. } elseif ($a == 'friendslists') {//好友日誌列表
  56. $friendsService = L::loadClass('Friend', 'friend'); /* @var $friendsService PW_Friend */
  57. $friendsUids = array();
  58. $friendsUids = $friendsService->findFriendsByUid($winduid);
  59. $diaryService = L::loadClass('Diary', 'diary'); /* @var $diaryService PW_Diary */
  60. $count = (int)$diaryService->countFriendsDiarys($friendsUids);
  61. $page > ceil($count/$db_perpage) && $page = ceil($count/$db_perpage);
  62. $diaryDb = ($count) ? $diaryService->findFriendsDiarysInPage($friendsUids, $page, $db_perpage) : array();
  63. $page > ceil($count/$db_perpage) && $page = ceil($count/$db_perpage);
  64. $pages = numofpage($count, $page, ceil($count/$db_perpage), $basename."a=$a&");
  65. } elseif ($a == 'friendlist') {//單個好友列表
  66. S::gp(array('fuid', 'dtid'));
  67. !$fuid && Showmsg('好友不存在');
  68. $ouserPrivacy = array();
  69. if ($isGM) {
  70. $ouserPrivacy['index'] = true;
  71. $ouserPrivacy['diary'] = true;
  72. } else{
  73. $ouserdataService = L::loadClass('Ouserdata', 'sns'); /* @var $ouserdataService PW_Ouserdata */
  74. $ouserDb = array();
  75. $ouserDb = $ouserdataService->get($fuid);
  76. list(,$ouserPrivacy) = pwUserPrivacy($fuid,$ouserDb);
  77. }
  78. !$ouserPrivacy['index'] && Showmsg('該朋友的空間設置了查看權限');
  79. !$ouserPrivacy['diary'] && Showmsg('該朋友的日誌設置了查看權限');
  80. $diaryTypeId = ($dtid == '-1') ? 0 : ( (is_numeric($dtid) && $dtid > 0) ? $dtid : null );
  81. $friendsService = L::loadClass('Friend', 'friend'); /* @var $friendsService PW_Friend */
  82. if ($friendsService->isFriend($winduid,$fuid) !== true) Showmsg('好友不存在');
  83. $diaryPrivacy = array(0,1);
  84. $diaryService = L::loadClass('Diary', 'diary'); /* @var $diaryService PW_Diary */
  85. list($diaryNums, $diaryType, $defaultTypeNum, $privacyNum) = $diaryService->getDiaryTypeMode($fuid, $diaryPrivacy);//TODO 右側分類Start
  86. $count = (int)$diaryService->countUserDiarys($fuid, $diaryTypeId, $diaryPrivacy);
  87. $page > ceil($count/$db_perpage) && $page = ceil($count/$db_perpage);
  88. $diaryDb = ($count) ? $diaryService->findUserDiarysInPage($fuid, $page, $db_perpage, $diaryTypeId, $diaryPrivacy) : array();
  89. $page > ceil($count/$db_perpage) && $page = ceil($count/$db_perpage);
  90. $pages = numofpage($count,$page,ceil($count/$db_perpage),"{$basename}a=$a&fuid=$fuid&dtid=$dtid&");
  91. } elseif ($a == 'frienddetail') {//查看好友日誌
  92. S::gp(array('did', 'fuid'));
  93. !$did && Showmsg("日誌不存在");
  94. !$fuid && Showmsg("好友不存在");
  95. $ouserPrivacy = array();
  96. if ($isGM) {
  97. $ouserPrivacy['index'] = true;
  98. $ouserPrivacy['diary'] = true;
  99. } else{
  100. $ouserdataService = L::loadClass('Ouserdata', 'sns'); /* @var $ouserdataService PW_Ouserdata */
  101. $ouserDb = array();
  102. $ouserDb = $ouserdataService->get($fuid);
  103. list(,$ouserPrivacy) = pwUserPrivacy($fuid,$ouserDb);
  104. }
  105. !$ouserPrivacy['index'] && Showmsg('該朋友的空間設置了查看權限');
  106. !$ouserPrivacy['diary'] && Showmsg('該朋友的日誌設置了查看權限');
  107. $diaryService = L::loadClass('Diary', 'diary'); /* @var $diaryService PW_Diary */
  108. $diaryTemp = $diaryService->get($did);
  109. $diaryTemp['uid'] != $fuid && Showmsg('日誌不存在');
  110. $diaryTemp['privacy'] == 2 && Showmsg("日誌不存在");
  111. $diary = $diaryService->getDiaryDbView($diaryTemp);
  112. $friendsService = L::loadClass('Friend', 'friend'); /* @var $friendsService PW_Friend */
  113. if ($friendsService->isFriend($winduid,$fuid) !== true) Showmsg('好友不存在');
  114. $diaryPrivacy = array(0,1);
  115. list($diaryNums, $diaryType, $defaultTypeNum, $privacyNum) = $diaryService->getDiaryTypeMode($fuid, $diaryPrivacy);
  116. list($commentdb,$subcommentdb,$pages) = getCommentDbByTypeid('diary',$did,$page,"{$basename}a={$a}&fuid={$fuid}&did={$did}&");
  117. $comment_type = 'diary';
  118. $comment_typeid = $did;
  119. $myOuserData = array();
  120. $ouserdataService = L::loadClass('Ouserdata', 'sns'); /* @var $ouserdataService PW_Ouserdata */
  121. $myOuserData = $ouserdataService->get($fuid);
  122. $weiboPriv = false;
  123. if (!$myOuserData['index_privacy'] && !$myOuserData['diary_privacy'] && !$diary['privacy']){
  124. $weiboPriv = true;
  125. }
  126. $friendDiaryNextName=getNextOrPreDiaryName($did, $fuid,'next');
  127. $friendDiaryPreName=getNextOrPreDiaryName($did, $fuid,'pre');
  128. } elseif ($a == 'write') {
  129. //權限設置
  130. /**
  131. * 禁止受限制用戶發言
  132. */
  133. banUser();
  134. /*
  135. * 新註冊會員發日誌時間限制
  136. */
  137. $userGroupsService = L::loadClass('UserGroups', 'user');
  138. $systemGroup = $userGroupsService->getUserGroupIds('system');
  139. if (!S::inArray($groupid,$systemGroup) && $db_postallowtime && $timestamp - $winddb['regdate'] < $db_postallowtime*60) {
  140. Showmsg('post_newd_limit');
  141. }
  142. /*
  143. * 用戶組發日誌權限限制
  144. */
  145. if ($groupid != 3 && $o_diary_groups && strpos($o_diary_groups,",$groupid,") === false) {
  146. Showmsg('diary_group_right');
  147. }
  148. /*
  149. * 灌水機制
  150. */
  151. $endtime = $tdtime + 24*3600;
  152. $postdate = $db->get_value("SELECT postdate FROM pw_diary WHERE uid=".S::sqlEscape($winduid)." ORDER BY postdate DESC LIMIT 1");
  153. $todaycount = $db->get_value("SELECT COUNT(*) as count FROM pw_diary WHERE uid=".S::sqlEscape($winduid)." AND postdate>=".S::sqlEscape($tdtime)." AND postdate<".S::sqlEscape($endtime));
  154. $tdtime >= $postdate && $todaycount = 0;
  155. if ($groupid != 3 && $o_diarylimit && $todaycount >= $o_diarylimit) {
  156. Showmsg('diary_gp_limit');
  157. }
  158. if ($groupid != 3 && $o_diarypertime && $timestamp >= $postdate && $timestamp - $postdate <= $o_diarypertime) {
  159. Showmsg('diary_limit');
  160. }
  161. //權限設置
  162. $db_uploadfiletype = $o_uploadsize = !empty($o_uploadsize) ? unserialize($o_uploadsize) : array();
  163. $imageAllow = pwJsonEncode($db_uploadfiletype);
  164. $myAppsData = array();
  165. $ouserDataService = L::loadClass('Ouserdata', 'sns'); /* @var $ouserDataService PW_Ouserdata */
  166. $myAppsData = $ouserDataService->get($winduid);
  167. $appsDiaryPrivacy = false;
  168. $myAppsData['index_privacy'] < 1 && $myAppsData['diary_privacy'] < 1 && $appsDiaryPrivacy = true;
  169. $sendWeiboPrivacy = $appsDiaryPrivacy;
  170. $weibocheck = $appsDiaryPrivacy === true ? 'checked=checked' : '';
  171. $weibodisplay = $appsDiaryPrivacy === true ? '' : 'style="display:none"';
  172. if (!$_POST['step']) {
  173. $editor = getstatus($winddb['userstatus'], PW_USERSTATUS_EDITOR) ? 'wysiwyg' : 'textmode';
  174. $dtsel = '';
  175. $query = $db->query("SELECT * FROM pw_diarytype WHERE uid=".S::sqlEscape($winduid)." ORDER BY dtid");
  176. while ($rt = $db->fetch_array($query)) {
  177. $dtsel .= "<option value=\"$rt[dtid]\">$rt[name]</option>";
  178. }
  179. $convertChecked = $checked = 'checked';
  180. $disabled = '';
  181. } elseif ($_POST['step'] == 2) {
  182. S::gp(array("privacy"));
  183. require_once(R_P.'require/postfunc.php');
  184. PostCheck(1,$o_diary_gdcheck,$o_diary_qcheck);
  185. S::gp(array('dtid','privacy','ifcopy','ifsendweibo','flashatt','atc_title'),'P');
  186. require_once(R_P.'require/bbscode.php');
  187. $wordsfb = L::loadClass('FilterUtil', 'filter');
  188. if (($banword = $wordsfb->comprise($_POST['atc_title'])) !== false) {
  189. Showmsg('diary_title_wordsfb');
  190. }
  191. if (($banword = $wordsfb->comprise($_POST['atc_content'], false)) !== false) {
  192. Showmsg('diary_content_wordsfb');
  193. }
  194. if (!$atc_title) $_POST['atc_title'] = get_date($timestamp,'Y.m.d').' 日誌';
  195. list($atc_title,$atc_content,$ifconvert,$ifwordsfb) = check_data('new');
  196. $userService = L::loadClass('UserService', 'user'); /* @var $userService PW_UserService */
  197. if ($db_tcheck) { //內容驗證
  198. $userDataInfo = $userService->get($winduid, false, true, false);
  199. $postcheck = unserialize($userDataInfo['postcheck']);
  200. $postcheck['diary'] == ($diaryCheck = tcheck($atc_content)) && Showmsg('diary_content_same');
  201. }
  202. //$db_tcheck && $winddb['postcheck'] == tcheck($atc_content) && Showmsg('diary_content_same'); //內容驗證
  203. $dtid = (int)$dtid;
  204. $privacy = (int)$privacy;
  205. $ifcopy = (int)$ifcopy;
  206. $ifupload = 0;
  207. // !$privacy && $ifcopy = 1;
  208. $aids = $attachs = array();
  209. L::loadClass('diaryupload', 'upload', false);
  210. if (PwUpload::getUploadNum() || $flashatt) {
  211. S::gp(array('savetoalbum', 'albumid'), 'P', 2);
  212. $diaryUpload = new DiaryUpload($winduid, $flashatt, $savetoalbum, $albumid);
  213. $diaryUpload->check();
  214. PwUpload::upload($diaryUpload);
  215. $aids = $diaryUpload->getAids();
  216. $attachs = $diaryUpload->getAttachs();
  217. $attachIds = $diaryUpload->getAttachIds();
  218. $ifupload = $diaryUpload->ifupload;
  219. }
  220. /**
  221. $pwSQL = S::sqlSingle(array(
  222. 'uid' => $winduid,
  223. 'dtid' => $dtid,
  224. 'aid' => (!empty($attachs) ? addslashes(serialize($attachs)) : ''),
  225. 'username' => $windid,
  226. 'privacy' => $privacy,
  227. 'subject' => $atc_title,
  228. 'content' => $atc_content,
  229. 'ifcopy' => $ifcopy,
  230. 'ifconvert' => $ifconvert,
  231. 'ifupload' => $ifupload,
  232. 'ifwordsfb' => $ifwordsfb,
  233. 'postdate' => $timestamp,
  234. ));
  235. $db->update("INSERT INTO pw_diary SET $pwSQL");**/
  236. $pwSQL = array(
  237. 'uid' => $winduid,
  238. 'dtid' => $dtid,
  239. 'aid' => (!empty($attachs) ? addslashes(serialize($attachs)) : ''),
  240. 'username' => $windid,
  241. 'privacy' => $privacy,
  242. 'subject' => $atc_title,
  243. 'content' => $atc_content,
  244. 'ifcopy' => $ifcopy,
  245. 'ifconvert' => $ifconvert,
  246. 'ifupload' => $ifupload,
  247. 'ifwordsfb' => $ifwordsfb,
  248. 'postdate' => $timestamp,
  249. );
  250. pwQuery::insert('pw_diary', $pwSQL);
  251. $did = $db->insert_id();
  252. $db->update("UPDATE pw_diarytype SET num=num+1 WHERE uid=".S::sqlEscape($winduid)." AND dtid=".S::sqlEscape($dtid));//更新分類日誌數
  253. if ($aids) {
  254. $diaryService = L::loadClass('Diary', 'diary');
  255. $diaryService->updateDiaryContentByAttach($did, $attachIds);
  256. $db->update("UPDATE pw_attachs SET did=" . S::sqlEscape($did) . " WHERE aid IN(" . S::sqlImplode($aids) . ")");
  257. $pwInfoSQL = array(
  258. 'uploadtime' => $winddb['uploadtime'],
  259. 'uploadnum' => $winddb['uploadnum']
  260. );
  261. }
  262. if (!$privacy && !$myAppsData['index_privacy'] && !$myAppsData['diary_privacy']) {
  263. $userCache = L::loadClass('Usercache', 'user');
  264. $userCache->delete($winduid, 'carddiary');
  265. updateDatanalyse($did,'diaryNew',$timestamp);
  266. if ($sendWeiboPrivacy && $ifsendweibo) {
  267. $weiboService = L::loadClass('weibo','sns');/* @var $weiboService PW_Weibo */
  268. $atc_content = substrs(stripWindCode($weiboService->escapeStr($atc_content)), 125);
  269. $weiboExtra = array(
  270. 'did' => $did,
  271. 'title' => stripslashes($atc_title),
  272. );
  273. $weiboService->send($winduid,$atc_content,'diary',$did,$weiboExtra);
  274. }
  275. }
  276. countPosts('+1');
  277. //積分變動
  278. require_once(R_P.'require/credit.php');
  279. $o_diary_creditset = unserialize($o_diary_creditset);
  280. $creditset = getCreditset($o_diary_creditset['Post']);
  281. $creditset = array_diff($creditset,array(0));
  282. if (!empty($creditset)) {
  283. $credit->sets($winduid,$creditset,true);
  284. updateMemberid($winduid);
  285. }
  286. if ($creditlog = unserialize($o_diary_creditlog)) {
  287. addLog($creditlog['Post'],$windid,$winduid,'diary_Post');
  288. }
  289. updateUserAppNum($winduid,'diary');
  290. if ($db_tcheck) {
  291. $postcheck['diary'] = $diaryCheck;
  292. $pwInfoSQL['postcheck'] = serialize($postcheck);
  293. }
  294. S::isArray($pwInfoSQL) && $userService->update($winduid, array(), $pwInfoSQL);
  295. $url = "{$basename}a=detail&did=$did";
  296. $msg = defined('AJAX') ? "success\t".$url : 'operate_success';
  297. // defend start
  298. CloudWind::YunPostDefend ( $winduid, $windid, $groupid, $did, $atc_title, $atc_content, 'diary' );
  299. // defend end
  300. refreshto($url,$msg);
  301. }
  302. } elseif ($a == 'edit') {
  303. $db_uploadfiletype = $o_uploadsize = !empty($o_uploadsize) ? unserialize($o_uploadsize) : array();
  304. $imageAllow = pwJsonEncode($db_uploadfiletype);
  305. $sendWeiboPrivacy = false;
  306. if (!$_POST['step']) {
  307. $did = (int)S::getGP('did');
  308. $editor = getstatus($winddb['userstatus'], PW_USERSTATUS_EDITOR) ? 'wysiwyg' : 'textmode';
  309. $dtsel = '';
  310. $diary = $db->get_one("SELECT did,dtid,aid,privacy,subject,content,ifcopy,ifconvert FROM pw_diary WHERE uid=".S::sqlEscape($winduid)." AND did=".S::sqlEscape($did));
  311. !$diary && Showmsg('illegal_request');
  312. $attach = '';
  313. if ($diary['aid']) {
  314. $attachs = unserialize($diary['aid']);
  315. if (is_array($attachs)) {
  316. foreach ($attachs as $key => $value) {
  317. list($value['attachurl'],) = geturl($value['attachurl'], 'lf');
  318. $attach .= "'$key' : ['$value[name]', '$value[size]', '$value[attachurl]', '$value[type]', '$value[special]', '$value[needrvrc]', '$value[ctype]', '$value[desc]'],";
  319. }
  320. $attach = rtrim($attach,',');
  321. }
  322. }
  323. $atc_content = $diary['content'];
  324. ${'privacy_'.$diary['privacy']} = 'selected';
  325. $diary['ifcopy'] && $checked = 'checked';
  326. $diary['ifconvert'] == 2 && $convertChecked = 'checked';
  327. ($diary['privacy'] == '2') && $disabled = 'disabled';
  328. $query = $db->query("SELECT * FROM pw_diarytype WHERE uid=".S::sqlEscape($winduid)." ORDER BY dtid");
  329. while ($rs = $db->fetch_array($query)) {
  330. $selected = '';
  331. $rs['dtid'] == $diary['dtid'] && $selected .= 'selected';
  332. $dtsel .= "<option value=\"$rs[dtid]\" $selected>$rs[name]</option>";
  333. }
  334. if (strpos($atc_content,$db_bbsurl) !== false) {
  335. $atc_content = str_replace('p_w_picpath',$db_picpath,$atc_content);
  336. $atc_content = str_replace('p_w_upload',$db_attachname,$atc_content);
  337. }
  338. } elseif ($_POST['step'] == 2) {
  339. S::gp(array('did','dtid','dtided','privacy','privacyed','ifcopy','flashatt'),'P');
  340. require_once(R_P.'require/bbscode.php');
  341. require_once(R_P.'require/postfunc.php');
  342. PostCheck(1,$o_diary_gdcheck,$o_diary_qcheck);
  343. $wordsfb = L::loadClass('FilterUtil', 'filter');
  344. if (($banword = $wordsfb->comprise($_POST['atc_title'])) !== false) {
  345. Showmsg('diary_title_wordsfb');
  346. }
  347. if (($banword = $wordsfb->comprise($_POST['atc_content'], false)) !== false) {
  348. Showmsg('diary_content_wordsfb');
  349. }
  350. list($atc_title,$atc_content,$ifconvert,$ifwordsfb) = check_data('modify');
  351. //$db_tcheck && $winddb['postcheck'] == tcheck($atc_content) && Showmsg('diary_content_same'); //內容驗證
  352. $dtid = (int)$dtid;
  353. $dtided = (int)$dtided;
  354. $privacy = (int)$privacy;
  355. $ifcopy = (int)$ifcopy;
  356. $ifupload = 0;
  357. /**
  358. * 附件修改
  359. */
  360. $oldattach = $replacedb = $unsetattach = array();
  361. $aid = $db->get_value("SELECT aid FROM pw_diary WHERE uid=".S::sqlEscape($winduid)." AND did=".S::sqlEscape($did));
  362. if ($aid) {
  363. S::gp(array('oldatt_desc'), 'P');
  364. $oldattach = unserialize(stripslashes($aid));
  365. foreach ($oldattach as $key => $value) {
  366. $v = array(
  367. 'special' => 0, 'ctype' => '',
  368. 'needrvrc' => 0, 'desc' => $oldatt_desc[$key]
  369. );
  370. $oldattach[$key] = array_merge($oldattach[$key], $v);
  371. if (array_key_exists('replace_'.$key, $_FILES)) {
  372. $db_attachnum++;
  373. $replacedb[$key] = $oldattach[$key];
  374. } elseif ($value['desc'] <> $v['desc']) {
  375. $runsql[] = 'UPDATE pw_attachs SET ' . S::sqlSingle(array(
  376. 'needrvrc' => $v['needrvrc'],
  377. 'descrip' => $v['desc'],
  378. 'special' => $v['special'],
  379. 'ctype' => $v['ctype']
  380. )) . ' WHERE aid=' . S::sqlEscape($key);
  381. }
  382. }
  383. }
  384. $aids = $attachs = array();
  385. L::loadClass('diaryupload', 'upload', false);
  386. if (PwUpload::getUploadNum() || $flashatt) {
  387. S::gp(array('savetoalbum', 'albumid'), 'P', 2);
  388. $diaryUpload = new DiaryUpload($winduid, $flashatt, $savetoalbum, $albumid);
  389. $diaryUpload->check();
  390. $diaryUpload->setReplaceAtt($replacedb);
  391. PwUpload::upload($diaryUpload);
  392. $aids = $diaryUpload->getAids();
  393. $attachs = $diaryUpload->getAttachs();
  394. $attachIds = $diaryUpload->getAttachIds();
  395. $ifupload = $diaryUpload->ifupload;
  396. if ($oldattach && $diaryUpload->replacedb) {
  397. foreach ($diaryUpload->replacedb as $key => $value) {
  398. $oldattach[$key] = $value;
  399. }
  400. }
  401. }
  402. if ($attachs) {
  403. foreach ($attachs as $key => $value) {
  404. $oldattach[$key] = $value;
  405. }
  406. $userService = L::loadClass('UserService', 'user'); /* @var $userService PW_UserService */
  407. $userService->update($winduid, array(), array('uploadtime'=>$winddb['uploadtime'], 'uploadnum'=>$winddb['uploadnum']));
  408. }
  409. if ($oldattach) {
  410. $oldattach = addslashes(serialize($oldattach));
  411. } else {
  412. $oldattach = '';
  413. }
  414. /**
  415. * 附件修改
  416. */
  417. /**
  418. $pwSQL = S::sqlSingle(array(
  419. 'dtid' => $dtid,
  420. 'aid' => $oldattach,
  421. 'privacy' => $privacy,
  422. 'subject' => $atc_title,
  423. 'content' => $atc_content,
  424. 'ifcopy' => $ifcopy,
  425. 'ifconvert' => $ifconvert,
  426. 'ifupload' => $ifupload,
  427. 'ifwordsfb' => $ifwordsfb,
  428. ));
  429. $db->update("UPDATE pw_diary SET $pwSQL WHERE uid=".S::sqlEscape($winduid)." AND did=".S::sqlEscape($did));
  430. **/
  431. $pwSQL = array(
  432. 'dtid' => $dtid,
  433. 'aid' => $oldattach,
  434. 'privacy' => $privacy,
  435. 'subject' => $atc_title,
  436. 'content' => $atc_content,
  437. 'ifcopy' => $ifcopy,
  438. 'ifconvert' => $ifconvert,
  439. 'ifupload' => $ifupload,
  440. 'ifwordsfb' => $ifwordsfb,
  441. );
  442. pwQuery::update('pw_diary', 'uid =:uid AND did =:did', array($winduid, $did), $pwSQL);
  443. if ($aids) {
  444. $diaryService = L::loadClass('Diary', 'diary');
  445. $diaryService->updateDiaryContentByAttach($did, $attachIds);
  446. $db->update("UPDATE pw_attachs SET did=" . S::sqlEscape($did) . " WHERE aid IN(" . S::sqlImplode($aids) . ")");
  447. }
  448. if ($dtided != $dtid) {
  449. $db->update("UPDATE pw_diarytype SET num=num-1 WHERE uid=".S::sqlEscape($winduid)." AND dtid=".S::sqlEscape($dtided));
  450. $db->update("UPDATE pw_diarytype SET num=num+1 WHERE uid=".S::sqlEscape($winduid)." AND dtid=".S::sqlEscape($dtid));
  451. }
  452. if ($privacyed == 2 && $privacy !=2) {
  453. countPosts('+1');
  454. } elseif ($privacyed != 2 && $privacy ==2) {
  455. if ($affected_rows = delAppAction('diary',$did)) {
  456. countPosts("-$affected_rows");
  457. }
  458. }
  459. // defend start
  460. CloudWind::YunPostDefend ( $winduid, $windid, $groupid, $did, $atc_title, $atc_content, 'editdiary' );
  461. // defend end
  462. $url = "{$basename}a=detail&did=$did";
  463. $msg = defined('AJAX') ? "success\t".$url : 'operate_success';
  464. refreshto($url, $msg);
  465. }
  466. } elseif ($a == 'copydiary') {
  467. define('AJAX', 1);
  468. define('F_M',true);
  469. banUser();
  470. S::gp(array('did'));
  471. empty($did) && Showmsg('data_error');
  472. $dtsel = '';
  473. $query = $db->query("SELECT * FROM pw_diarytype WHERE uid=".S::sqlEscape($winduid)." ORDER BY dtid");
  474. while ($rt = $db->fetch_array($query)) {
  475. $dtsel .= "<option value=\"$rt[dtid]\">$rt[name]</option>";
  476. }
  477. require_once PrintEot('m_ajax');ajax_footer();
  478. } elseif ($a == 'next') {
  479. define('AJAX',1);
  480. $did = (int)S::getGP('did');
  481. $fuid = (int)S::getGP('fuid');
  482. $uid = $fuid ? $fuid : $winduid;
  483. $sqladd = "WHERE uid=".S::sqlEscape($uid);
  484. if ($uid != $winduid) {
  485. $sqladd .= " AND privacy!=2 AND did>".S::sqlEscape($did);
  486. $basename = $basename."a=frienddetail&fuid=$uid&";
  487. } else {
  488. $sqladd .= " AND did>".S::sqlEscape($did);
  489. $basename = $basename."a=detail&";
  490. }
  491. $did = $db->get_value("SELECT MIN(did) FROM pw_diary $sqladd");
  492. echo "success\t$did\t$basename";
  493. ajax_footer();
  494. } elseif ($a == 'pre') {
  495. define('AJAX',1);
  496. $did = (int)S::getGP('did');
  497. $fuid = (int)S::getGP('fuid');
  498. $uid = $fuid ? $fuid : $winduid;
  499. $sqladd = "WHERE uid=".S::sqlEscape($uid);
  500. if ($uid != $winduid) {
  501. $sqladd .= " AND privacy!=2 AND did<".S::sqlEscape($did);
  502. $basename = $basename."a=frienddetail&fuid=$uid&";
  503. } else {
  504. $sqladd .= " AND did<".S::sqlEscape($did);
  505. $basename = $basename."a=detail&";
  506. }
  507. $did = $db->get_value("SELECT MAX(did) FROM pw_diary $sqladd");
  508. echo "success\t$did\t$basename";
  509. ajax_footer();
  510. }
  511. if($s) require_once PrintEot('m_diary_bottom');
  512. else require_once PrintEot('m_diary');
  513. pwOutPut();