帝国cms生成公共模板变量静态缓存,提升刷新生成页面效率

 本插件可将公共模板变量生成为静态缓存,让刷新页面效率更高,特别是大量使用公共模板变量的页面,效果非常明显。

折叠PHP 代码
  1. <?php  
  2. define('EmpireCMSAdmin','1');  
  3. require("../../class/connect.php");  
  4. require("../../class/db_sql.php");  
  5. require("../../class/functions.php");  
  6. $link=db_connect();  
  7. $empire=new mysqlquery();  
  8. $editor=1;  
  9. //验证用户  
  10. $lur=is_login();  
  11. $logininid=$lur['userid'];  
  12. $loginin=$lur['username'];  
  13. $loginrnd=$lur['rnd'];  
  14. $loginlevel=$lur['groupid'];  
  15. $loginadminstyleid=$lur['adminstyleid'];  
  16. include "../".LoadLang("pub/fun.php");  
  17. //ehash  
  18. $ecms_hashur=function_exists('hReturnEcmsHashStrAll')?hReturnEcmsHashStrAll():'';  
  19. $tempsql=$empire->query("select varid,myvar from {$dbtbpre}enewstempvar");  
  20. $url="<a href=index.php{$ecms_hashur['whhref']}>管理生成缓存</a>";  
  21. if($_POST['var']){  
  22.     foreach ($_POST['var'as $val) {  
  23.         $sqlin.=(int)$val.',';  
  24.     }  
  25.     $sqlin=$sqlin?substr($sqlin,0,-1):0;  
  26.     $filepath=ECMS_PATH.'d/Cache/tempvar/';  
  27.     if(!is_dir($filepath)){  
  28.         printerror2("请建立缓存目录!");  
  29.     }  
  30.     $head="<?php if(!defined('InEmpireCMS')){exit();}?>".PHP_EOL;  
  31.     $scsql=$empire->query("select * from {$dbtbpre}enewstempvar where varid in ($sqlin)");  
  32.     while ($r = $empire->fetch($scsql)) {  
  33.         $text=RepBq(DoRepEcmsLoopBq(ReplaceTempvar(stripSlashes($r['varvalue']))));  
  34.         $text=  str_replace('[!--news.url--]''<?=$public_r[newsurl]?>'$text);  
  35.         file_put_contents($filepath.$r['varid'].'.php'$head.$text);  
  36.     }  
  37.     printerror2("生成缓存成功!");  
  38. }  
  39. ?>  
  40. <!doctype html>  
  41. <html lang="zh-cn">  
  42. <head>  
  43. <meta charset="utf-8">  
  44. <title>管理生成缓存</title>  
  45. </head>  
  46. <body>  
  47.   
  48.     <form action="index.php" method="post">  
  49.     <?=$ecms_hashur['form']?>  
  50.     <?  
  51.     while ($row = $empire->fetch($tempsql)) {  
  52.         ?>  
  53.     <input type="checkbox" name="var[]" value="<?=$row['varid']?>" /><?=$row['myvar']?><br />  
  54.     <?  
  55.     }  
  56.     ?>  
  57.     <input type="submit" value="提交">  
  58. </form>  
  59.     备注:生成位置在:/d/Cache/tempvar。  
  60. </body>  
  61. </html>  
  62.   
  63. <?  
  64. db_close();  
  65. $empire=null;  
  66. ?>  

 

Tags: 模板   变量   缓存   生成
cms大学,为帝国cms用户提供动力
Copyright © 2016 CmsDX.com All Rights Reserved.