非常大米搞了中文Drupal站点串联,但是要跨站调用java脚本,在上网高峰时期,DNS和大米网站的出口速度限制导致了经常无法显示。而且对于有的利用table布局的模板,会在ie下长时间无法显示整个页面(参见 http://www.kylinx.net/node/50 )
所以,我用php做了一个带缓存功能的Drupal站点大串连,它可以自行设置每隔一段时间,才和大米的网站同步一次串连站点的数据,在你自己的服务器上实现大米串连的所有功能(当然注册站点出外),比如随机显示,这样一来速度快了,也有更多的drupaler愿意加入串连。
注意:需要你的服务器打开allow_url_fopen支持,不过好像大多都是开着的。
安装方法如下先把updateCDL.php下载到你的files目录,确保files目录可写,请新建一个Drupal中文链接的block,然后加入下面代码:Download Code: cdlBlock.php<?php
$num=7; //一次显示的站点数
$cachetime=24; //从大米那更新一次的时间间隔,小时为单位
$cachefilename="files/drupal_list.html"; //cache文件的文件名
$fp1=fopen($cachefilename,'r');
if($fp1===false)
{
echo "<script type=\"text/javascript\" src=\"http://www.verydummy.com/drupal_demo/drupalcnlist.php?num=7\"></script><iframe marginheight=0 frameborder=0 scrolling=no height=20 width=20 src=\"files/updateCDL.php?hours=".$cachetime."\"></iframe>";
}
else{
$contents = fread($fp1, filesize ($cachefilename));
fclose($fp1);
$ii=1;
while($ii)
{
if(preg_match('#(.*?)\</li><li>(.*?)\</li>(.*?)#sie',$contents,$match_site)){
$drupalsite[] ="</li><li>$match_site[2]</li>";
}
$contents=strstr($contents,"</li>");
if($contents==FALSE)
$ii=0;
$contents=strstr($contents,"l");
}
//var_dump($drupalsite);
$rand_keys = array_rand($drupalsite, $num);
echo '<div class="item-list"><ul>';
while($num>=0){
echo stripslashes($drupalsite[$rand_keys[--$num]]);
}
echo '</ul></div><div class="more-link"><a href="http://www.verydummy.com/drupal_demo/node/45">more</a></div>';
echo $contents."<iframe marginheight=0 frameborder=0 scrolling=no height=2 width=2 src=\"files/updateCDL.php?hours=".$cachetime."\"></iframe>";
}
?>
在输入格式那里选择php,然后enable它就ok了
附:updateCDL.php的代码
Download Code: updateCDL.php<?php
$cachefilename="drupal_list.html"; //cache文件的文件名,和block中的保持一致,
//但是前面没有files这个目录名
$listurl="http://www.verydummy.com/drupal_demo/drupalcnlist.php?num=50";
if (isset($_GET['hours'])) {
$updatetime=$_GET['hours'];
settype($updatetime,"integer");
if ($updatetime<1)
$updatetime=12;
$updatetime=$updatetime*60*60;
//echo "$updatetime";
$t=filemtime($cachefilename);
$nt=time();
if(($nt-$t)<$updatetime){
echo "no need";
exit();
}
$fpURL=fopen($listurl,'r');
if($fpURL===false)
exit();
while(!feof($fpURL))
$contents.=fgets($fpURL);
if(strstr($contents,"kylinx"))
{
if (!$fp=fopen($cachefilename,'w'))
exit;
fwrite($fp, $contents);
fclose($fp);
echo "ok";
}
fclose($fpURL);
}
?>
所以,我用php做了一个带缓存功能的Drupal站点大串连,它可以自行设置每隔一段时间,才和大米的网站同步一次串连站点的数据,在你自己的服务器上实现大米串连的所有功能(当然注册站点出外),比如随机显示,这样一来速度快了,也有更多的drupaler愿意加入串连。
注意:需要你的服务器打开allow_url_fopen支持,不过好像大多都是开着的。
安装方法如下先把updateCDL.php下载到你的files目录,确保files目录可写,请新建一个Drupal中文链接的block,然后加入下面代码:Download Code: cdlBlock.php<?php
$num=7; //一次显示的站点数
$cachetime=24; //从大米那更新一次的时间间隔,小时为单位
$cachefilename="files/drupal_list.html"; //cache文件的文件名
$fp1=fopen($cachefilename,'r');
if($fp1===false)
{
echo "<script type=\"text/javascript\" src=\"http://www.verydummy.com/drupal_demo/drupalcnlist.php?num=7\"></script><iframe marginheight=0 frameborder=0 scrolling=no height=20 width=20 src=\"files/updateCDL.php?hours=".$cachetime."\"></iframe>";
}
else{
$contents = fread($fp1, filesize ($cachefilename));
fclose($fp1);
$ii=1;
while($ii)
{
if(preg_match('#(.*?)\</li><li>(.*?)\</li>(.*?)#sie',$contents,$match_site)){
$drupalsite[] ="</li><li>$match_site[2]</li>";
}
$contents=strstr($contents,"</li>");
if($contents==FALSE)
$ii=0;
$contents=strstr($contents,"l");
}
//var_dump($drupalsite);
$rand_keys = array_rand($drupalsite, $num);
echo '<div class="item-list"><ul>';
while($num>=0){
echo stripslashes($drupalsite[$rand_keys[--$num]]);
}
echo '</ul></div><div class="more-link"><a href="http://www.verydummy.com/drupal_demo/node/45">more</a></div>';
echo $contents."<iframe marginheight=0 frameborder=0 scrolling=no height=2 width=2 src=\"files/updateCDL.php?hours=".$cachetime."\"></iframe>";
}
?>
在输入格式那里选择php,然后enable它就ok了
附:updateCDL.php的代码
Download Code: updateCDL.php<?php
$cachefilename="drupal_list.html"; //cache文件的文件名,和block中的保持一致,
//但是前面没有files这个目录名
$listurl="http://www.verydummy.com/drupal_demo/drupalcnlist.php?num=50";
if (isset($_GET['hours'])) {
$updatetime=$_GET['hours'];
settype($updatetime,"integer");
if ($updatetime<1)
$updatetime=12;
$updatetime=$updatetime*60*60;
//echo "$updatetime";
$t=filemtime($cachefilename);
$nt=time();
if(($nt-$t)<$updatetime){
echo "no need";
exit();
}
$fpURL=fopen($listurl,'r');
if($fpURL===false)
exit();
while(!feof($fpURL))
$contents.=fgets($fpURL);
if(strstr($contents,"kylinx"))
{
if (!$fp=fopen($cachefilename,'w'))
exit;
fwrite($fp, $contents);
fclose($fp);
echo "ok";
}
fclose($fpURL);
}
?>