PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/emlog/src/lib/C_cache.php

http://mycaptain.googlecode.com/
PHP | 238 lines | 212 code | 9 blank | 17 comment | 16 complexity | 5f063fd134c2e54c90dbd8f0ba0ca7fe MD5 | raw file
  1. <?php
  2. /**
  3. * ???????
  4. * @copyright (c) 2008, Emlog All Rights Reserved
  5. * @version emlog-2.6.0
  6. */
  7. class mkcache extends MySql{
  8. var $db_prefix;
  9. var $link;
  10. var $Archives;
  11. var $log_tags;
  12. var $log_atts;//??
  13. var $tags;
  14. var $comment;
  15. function mkcache($host,$user,$pass,$db,$prefix)
  16. {
  17. $this->host = $host;
  18. $this->pass = $pass;
  19. $this->user = $user;
  20. $this->db = $db;
  21. $this->db_prefix = $prefix;
  22. $this->dbconnect($this->host, $this->user, $this->pass,$this->db);
  23. }
  24. //??????
  25. function mc_config($cf)
  26. {
  27. $show_config=$this->fetch_array($this->query("SELECT * FROM ".$this->db_prefix."config"));
  28. $exarea = addslashes($show_config['exarea']);
  29. $config ="\n\$config_cache = array('sitekey' =>\"".htmlspecialchars($show_config['site_key'])."\",'blogname' =>\"".htmlspecialchars(stripslashes($show_config['blogname']))."\",'bloginfo'=>\"".htmlspecialchars(stripslashes($show_config['bloginfo']))."\",'index_lognum' =>\"".$show_config['index_lognum']."\",'index_tagnum' =>\"".$show_config['index_tagnum']."\",'index_comment_num' =>\"".$show_config['index_comnum']."\",'ischkcomment'=>\"".$show_config['ischkcomment']."\",'isurlrewrite'=>\"".$show_config['isurlrewrite']."\",'istrackback'=>\"".$show_config['istrackback']."\",'comment_code'=>\"".$show_config['comment_code']."\",'login_code'=>\"".$show_config['login_code']."\",'comment_subnum'=>\"".$show_config['comment_subnum']."\",'nonce_templet'=>\"".$show_config['nonce_templet']."\",'blogurl'=>\"".htmlspecialchars($show_config['blogurl'])."\",'icp'=>\"".htmlspecialchars($show_config['icp'])."\",'timezone'=>\"".$show_config['timezone']."\",'exarea'=>\"".$exarea."\");";
  30. $cache = "<?php".$config."\n?>";
  31. $this->mc_print($cache,$cf);
  32. }
  33. //????
  34. function mc_blogger($cf)
  35. {
  36. $blogger = $this->fetch_one_array("select * from ".$this->db_prefix."user ");
  37. $icon = '';
  38. if($blogger['photo'])
  39. {
  40. $photosrc = substr($blogger['photo'],3);
  41. $imgsize = chImage($blogger['photo'],ICON_MAX_W,ICON_MAX_H);
  42. $icon = "<img src=\\\"".htmlspecialchars($photosrc)."\\\" width=\\\"".$imgsize['w']."\\\" height=\\\"".$imgsize['h']."\\\" alt=\\\"blogger\\\" />";
  43. }
  44. $user="\n\$user_cache = array('photo' => \"$icon\",'name' =>\"".htmlspecialchars($blogger['nickname'])."\",'mail' =>\"".htmlspecialchars($blogger['email'])."\",'des'=>\"".htmlspecialchars($blogger['description'])."\");";
  45. $cache = "<?php".$user."\n?>";
  46. $this->mc_print($cache,$cf);
  47. }
  48. //????
  49. function mc_sta($cf)
  50. {
  51. $dh = $this->fetch_one_array("select * from ".$this->db_prefix."statistics");
  52. $lognum = $this->num_rows($this->query("SELECT gid FROM ".$this->db_prefix."blog WHERE hide='n' "));
  53. $comnum = $this->num_rows($this->query("SELECT cid FROM ".$this->db_prefix."comment WHERE hide='n' "));
  54. $tbnum = $this->num_rows($this->query("SELECT gid FROM ".$this->db_prefix."trackback "));
  55. $hidecom = $this->num_rows($this->query("SELECT gid FROM ".$this->db_prefix."comment where hide='y' "));
  56. $sta="\n\$sta_cache = array(
  57. 'day_view_count' => \"".$dh['day_view_count']."\",
  58. 'view_count' =>\"".$dh['view_count']."\",
  59. 'lognum'=>\"".$lognum."\",
  60. 'comnum'=>\"".$comnum."\",
  61. 'hidecom'=>\"".$hidecom."\",
  62. 'tbnum'=>\"".$tbnum."\"
  63. );";
  64. $cache = "<?php".$sta."\n?>";
  65. $this->mc_print($cache,$cf);
  66. }
  67. //????
  68. function mc_comment($cf)
  69. {
  70. $show_config=$this->fetch_array($this->query("SELECT * FROM ".$this->db_prefix."config"));
  71. $index_comment_num = $show_config['index_comnum'];
  72. $comment_subnum = $show_config['comment_subnum'];
  73. $query=$this->query("SELECT cid,gid,comment,date,poster FROM ".$this->db_prefix."comment WHERE hide='n' ORDER BY cid DESC LIMIT 0, $index_comment_num ");
  74. $j = 0;
  75. while($show_com=$this->fetch_array($query)){
  76. $this->comment.= "\n\$com_cache[".$j."] = array('url'=>\"index.php?action=showlog&gid=".$show_com['gid']."#".$show_com['cid']."\",'name'=>\"".base64_encode(htmlspecialchars($show_com['poster']))."\",'content'=>\"".base64_encode(htmlClean2(subString($show_com['comment'],0,$comment_subnum)))."\");";
  77. $j++;
  78. }
  79. $cache = "<?php".$this->comment."\n?>";
  80. $this->mc_print($cache,$cf);
  81. }
  82. //???????
  83. function mc_tags($cf)
  84. {
  85. $show_config=$this->fetch_array($this->query("SELECT index_tagnum FROM ".$this->db_prefix."config"));
  86. $index_tagnum = $show_config['index_tagnum'];
  87. $query=$this->query("SELECT tagname,usenum FROM ".$this->db_prefix."tag ORDER BY usenum DESC LIMIT 0, $index_tagnum ");
  88. $m = 0;
  89. while($show_tag = $this->fetch_array($query)){
  90. $size = 14+round($show_tag['usenum']/3);
  91. $fontsize = $size >40?40:$size;
  92. $tag = $show_tag['tagname'];
  93. $tagurl = urlencode($show_tag['tagname']);
  94. $this->tags.= "\n\$tag_cache[".$m."] = array('tagurl'=>\"$tagurl\",'tagname'=>\"".htmlspecialchars($show_tag['tagname'])."\",'fontsize'=>\"$fontsize\");";
  95. $m++;
  96. }
  97. $cache = "<?php".$this->tags."\n?>";
  98. $this->mc_print($cache,$cf);
  99. }
  100. //????
  101. function mc_link($cf)
  102. {
  103. $query=$this->query("SELECT siteurl,sitename,description FROM ".$this->db_prefix."link ORDER BY taxis ASC");
  104. $k = 0;
  105. while($show_link=$this->fetch_array($query)){
  106. $this->link.= "\n\$link_cache[".$k."] = array('link'=>\"".htmlspecialchars($show_link['sitename'])."\",'url'=>\"".htmlspecialchars($show_link['siteurl'])."\",'des'=>\"".htmlspecialchars($show_link['description'])."\");";
  107. $k++;
  108. }
  109. $cache = "<?php".$this->link."\n?>";
  110. $this->mc_print($cache,$cf);
  111. }
  112. //??????
  113. function mc_record($cf)
  114. {
  115. global $isurlrewrite;
  116. $query=$this->query("select date from ".$this->db_prefix."blog WHERE hide='n' ORDER BY date DESC");
  117. $record='xxxx_x';
  118. $p = 0;
  119. $lognum = 1;
  120. while($show_record=$this->fetch_array($query)){
  121. $f_record=date('Y_n',$show_record['date']);
  122. if ($record!=$f_record){
  123. $h = $p-1;
  124. if($h!=-1)
  125. {
  126. $this->Archives.= "\n\$dang_cache[".$h."]['lognum']=\"".$lognum."\";";
  127. }
  128. if($isurlrewrite == 'y')
  129. {
  130. $this->Archives.= "\n\$dang_cache[".$p."] = array('record'=>\"".date("Y?n?",$show_record['date'])."\",'url'=>\"record-".date("Ym",$show_record['date']).".html\",'lognum'=>\"\");";
  131. }
  132. else
  133. {
  134. $this->Archives.= "\n\$dang_cache[".$p."] = array('record'=>\"".date("Y?n?",$show_record['date'])."\",'url'=>\"index.php?record=".date("Ym",$show_record['date'])."\",'lognum'=>\"\");";
  135. }
  136. $p++;
  137. $lognum = 1;
  138. }else{
  139. $lognum++;
  140. continue;
  141. }
  142. $record=$f_record;
  143. }
  144. $j = $p-1;
  145. if($j>=0)
  146. {
  147. $this->Archives.= "\n\$dang_cache[".$j."]['lognum']=\"".$lognum."\";";
  148. }
  149. $cache = "<?php".$this->Archives."\n?>";
  150. $this->mc_print($cache,$cf);
  151. }
  152. //??????
  153. function mc_logtags($cf)
  154. {
  155. $sql="SELECT gid FROM ".$this->db_prefix."blog ORDER BY top DESC ,date DESC";
  156. $query1=$this->query($sql);
  157. while($show_log=$this->fetch_array($query1)) {
  158. $tag = '';
  159. $gid = $show_log['gid'];
  160. //tag
  161. $tquery = "SELECT tagname FROM ".$this->db_prefix."tag WHERE gid LIKE '%,$gid,%' " ;
  162. $result = $this->query($tquery);
  163. $tagnum = $this->num_rows($result);
  164. if($tagnum>0){
  165. while($show_tag=$this->fetch_array($result)){
  166. $tag .= " <a href=\\\"./?action=taglog&tag=".urlencode($show_tag['tagname'])."\\\">".htmlspecialchars($show_tag['tagname']).'</a>';
  167. }
  168. }else {
  169. $tag = '';
  170. }
  171. $this->log_tags .= "\n\$log_cache_tags[".$show_log['gid']."] = \"".$tag."\";";
  172. unset($tag);
  173. }
  174. $cache = "<?php".$this->log_tags."\n?>";
  175. $this->mc_print($cache,$cf);
  176. }
  177. //??????
  178. function mc_logatts($cf,$cont_attid='')
  179. {
  180. $sql="SELECT gid,attcache FROM ".$this->db_prefix."blog ORDER BY top DESC ,date DESC";
  181. $query1=$this->query($sql);
  182. while($rows=$this->fetch_array($query1)){
  183. $gid = $rows['gid'];
  184. $att_img = '';
  185. $attachment = '';
  186. //attachment
  187. $attquery = $this->query("SELECT * FROM ".$this->db_prefix."attachment WHERE blogid=$gid ");
  188. while($show_attach=$this->fetch_array($attquery)){
  189. $cont_attid = unserialize($rows['attcache']);
  190. if($cont_attid && in_array($show_attach['aid'],$cont_attid))
  191. {
  192. continue;
  193. }
  194. $att_path = $show_attach['filepath'];//eg: ../uploadfile/200710/b.jpg
  195. $atturl = substr($att_path,3);//eg: uploadfile/200710/b.jpg
  196. $postfix = strtolower(substr(strrchr($show_attach['filename'], "."),1));//????
  197. if($postfix == 'jpg' OR $postfix == 'jpeg' OR $postfix == 'gif' OR $postfix == 'png')
  198. {
  199. $imgsrc = $atturl;
  200. if(substr(basename($imgsrc),0,5) == 'thum-')
  201. {
  202. $imgsrc2 = str_replace('thum-','',$imgsrc);
  203. }else{
  204. $imgsrc2 = $imgsrc;
  205. }
  206. $imgsize = chImage($att_path,IMG_ATT_MAX_W,IMG_ATT_MAX_H);
  207. $att_img .= "<br />???? : ".$show_attach['attdes']."<br /><a href=\\\"$imgsrc2\\\" target=\\\"_blank\\\"><img src=\\\"$imgsrc\\\" width=\\\"".$imgsize['w']."\\\" height=\\\"".$imgsize['h']."\\\" border=\\\"0\\\" alt=\\\"??????\\\" /></a>";
  208. }else
  209. {
  210. $file_atturl = $atturl;
  211. $attachment .= "<br /><a href=\\\"".$file_atturl."\\\" target=\\\"_blank\\\">".$show_attach['filename']."</a>\t".changeFileSize($show_attach['filesize']).' '.$show_attach['attdes'];
  212. }
  213. }
  214. $this->log_atts .= "\n\$log_cache_atts[".$gid."] = array('attachment'=>\"".$attachment."\",'att_img'=>\"".$att_img."\");";
  215. unset($attachment);
  216. unset($att_img);
  217. }
  218. $cache = "<?php".$this->log_atts."\n?>";
  219. $this->mc_print($cache,$cf);
  220. }
  221. //????
  222. function mc_print ($content,$cachefile)
  223. {
  224. @ $fp = fopen($cachefile, 'wb') OR sysMsg('????????????????');
  225. @ $fw = fwrite($fp,$content) OR sysMsg('??????????????');
  226. fclose($fp);
  227. }
  228. }
  229. ?>