PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/emlog/src/adm/add_log.php

http://mycaptain.googlecode.com/
PHP | 147 lines | 121 code | 7 blank | 19 comment | 19 complexity | 5ae4ad2142f885a6a90f8a976c3ec568 MD5 | raw file
  1. <?php
  2. /**
  3. * ????
  4. * @copyright (c) 2008, Emlog All Rights Reserved
  5. * @version emlog-2.6.0
  6. */
  7. require_once('./globals.php');
  8. $pid = isset($_GET['pid'])?$_GET['pid']:'';
  9. if($action == '')
  10. {
  11. include getViews('header');
  12. //??tags
  13. $query = $DB->query("select tagname from {$db_prefix}tag");
  14. $oldtags = '';
  15. while($tags = $DB->fetch_array($query))
  16. {
  17. $oldtags .=" <a href=\"javascript: inserttag('".$tags['tagname']."','tags');\">".$tags['tagname']."</a> " ;
  18. }
  19. //??
  20. $year = date('Y');
  21. $month = date('m');
  22. $day = date('d');
  23. $hour = date('H');
  24. $minute = date('i');
  25. $second = date('s');
  26. require_once(getViews('add_log'));
  27. include getViews('footer');cleanPage();
  28. }
  29. ##################????##################
  30. if($action== 'addlog')
  31. {
  32. if($pid == 'draft')
  33. {
  34. $ishide='y';
  35. $ok_msg = '???????';
  36. $ok_url = 'admin_log.php?pid=draft';
  37. }else
  38. {
  39. $ishide = 'n';
  40. $ok_msg = '???????';
  41. $ok_url = 'admin_log.php';
  42. }
  43. $title = isset($_POST['title'])?addslashes(trim($_POST['title'])):'';
  44. $tagstring = isset($_POST['tag'])?addslashes(trim($_POST['tag'])):'';
  45. $edittime = isset($_POST['edittime'])?intval(isset($_POST['edittime'])):'';
  46. $content = isset($_POST['content'])?addslashes(trim($_POST['content'])):'';
  47. $pingurl = isset($_POST['pingurl'])?addslashes($_POST['pingurl']):'';
  48. $allow_remark = isset($_POST['allow_remark'])?addslashes($_POST['allow_remark']):'';
  49. $allow_tb = isset($_POST['allow_tb'])?addslashes($_POST['allow_tb']):'';
  50. $tbmsg = ''; //define trackback msg
  51. if(!$title)
  52. {
  53. formMsg('???????','./add_log.php',0);
  54. }
  55. //????
  56. if($timezone!=8)
  57. {
  58. $oversec = ($timezone-8)*3600;
  59. $localtime = time()-$oversec;
  60. }else
  61. $localtime = time();
  62. if($edittime)
  63. {
  64. $newtime = @gmmktime(intval($_POST['newhour']),intval($_POST['newmin']),
  65. intval($_POST['newsec']),intval($_POST['newmonth']),
  66. intval($_POST['newday']),intval($_POST['newyear']))-$timezone*3600;
  67. if(empty($newtime))
  68. $newtime = $localtime;
  69. } else
  70. $newtime = $localtime;
  71. //???????????id ????
  72. //preg_match_all("/ematt:([0-9]+)/i",$content, $matches );
  73. //$cont_attid = serialize($matches[1]);
  74. //???????
  75. $sql="insert into {$db_prefix}blog (`title`,`date`,`content`,`hide`,`allow_remark`,`allow_tb`,`attcache`) values('$title','$newtime','$content','$ishide','$allow_remark','$allow_tb','')";
  76. $DB->query($sql);
  77. //????????ID
  78. $logid=$DB->insert_id();
  79. //??tag
  80. if (!empty($tagstring))
  81. {
  82. $tag = explode(',',$tagstring);
  83. $tag = formatArray($tag);
  84. for ($i = 0; $i < count($tag); $i++)
  85. {
  86. $result = $DB->fetch_one_array("SELECT tagname FROM {$db_prefix}tag WHERE `tagname`='".trim($tag[$i])."' ");
  87. if(empty($result)) {
  88. $query="INSERT INTO {$db_prefix}tag (`tagname`,`gid`) VALUES('".$tag[$i]."',',$logid,')";
  89. $DB->query($query);
  90. }else{
  91. $query="UPDATE {$db_prefix}tag SET `usenum`=`usenum`+1, `gid`=concat(`gid`,'$logid,') where `tagname` = '".$tag[$i]."' ";
  92. $DB->query($query);
  93. }
  94. }
  95. $MC->mc_tags('../cache/tags');
  96. }
  97. //????
  98. $attach = isset($_FILES['attach'])?$_FILES['attach']:'';
  99. if($attach){
  100. $des = $_POST['attdes'];
  101. for ($i = 0; $i < count($attach['name']); $i++)
  102. {
  103. if($attach['error'][$i]!=4){
  104. $ades = addslashes(trim($des[$i]));
  105. //$att_type ????????
  106. $upfname = uploadFile($attach['name'][$i],$attach['tmp_name'][$i],$attach['size'][$i],$att_type,$attach['type'][$i]);
  107. //??????
  108. $query="INSERT INTO {$db_prefix}attachment (`blogid`,`filename`,`attdes`,`filesize`,`filepath`,`addtime`) values ('".$logid."','".$attach['name'][$i]."','".$ades."','".$attach['size'][$i]."','".$upfname."','".time()."')";
  109. $DB->query($query);
  110. }
  111. }
  112. }
  113. // ??Trackback??
  114. if(!empty($pingurl))
  115. {
  116. $url = $blogurl."index.php?action=showlog&gid=".$logid;
  117. $hosts = explode("\n", $pingurl);
  118. $tbmsg = '';
  119. foreach ($hosts as $key => $value)
  120. {
  121. $host = trim($value);
  122. if(strstr(strtolower($host), "http://") || strstr(strtolower($host), "https://"))
  123. {
  124. $data ="url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blogname)."&excerpt=".rawurlencode($content);
  125. $result = strtolower(sendPacket($host, $data));
  126. if (strstr($result, "<error>0</error>") === false) {
  127. $tbmsg .= "(??{$key}:????)";
  128. } else {
  129. $tbmsg .= "(??{$key}:????)";
  130. }
  131. }
  132. }
  133. }
  134. $MC->mc_sta('../cache/sta');
  135. $MC->mc_record('../cache/records');
  136. $MC->mc_logtags('../cache/log_tags');
  137. $MC->mc_logatts('../cache/log_atts');
  138. formMsg("$ok_msg\t$tbmsg",$ok_url,1);
  139. }//end add log
  140. ?>