Created
November 11, 2012 13:42
-
-
Save cyrilis/4054930 to your computer and use it in GitHub Desktop.
博客php代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require("simple_html_dom.php"); | |
function get_files($dir) { | |
$files = array(); | |
for (; $dir->valid(); $dir->next()) { | |
if ($dir->isDir() && !$dir->isDot()) { | |
if ($dir->haschildren()) { | |
//$files = array_merge($files, get_files($dir->getChildren())); | |
$files =get_files($dir->getChildren()); | |
}; | |
}else if($dir->isFile()){ | |
$files[] = $dir->getBaseName(); | |
} | |
} | |
return array_reverse($files); | |
} | |
$path = "./blog"; | |
$dir = new RecursiveDirectoryIterator($path); | |
$indexs=get_files($dir); | |
rsort($indexs,SORT_NUMERIC); | |
if(isset($_GET['s'])) | |
{ | |
$single=substr($_GET['s'],1); | |
if(in_array($single, $indexs)) | |
{ | |
$singles=file_get_html("./blog/".$single); | |
foreach($singles->find('body') as $e) | |
{ | |
echo "<div id='single'>".$e->innertext.'<br></div>'; | |
echo("<div id='disqus_thread'></div><script type='text/javascript'>/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */var disqus_shortname = 'cyrilis'; // required: replace example with your forum shortname/* * * DON'T EDIT BELOW THIS LINE * * */(function() {var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);})();</script><noscript>Please enable JavaScript to view the <a href='http://disqus.com/?ref_noscript'>comments powered by Disqus.</a></noscript><a href='http://disqus.com' class='dsq-brlink'>comments powered by <span class='logo-disqus'>Disqus</span></a>"); | |
} | |
}else{ | |
echo("<h1>404-----页面无法找到。</h1>"); | |
} | |
} | |
else if(isset($_GET['p'])) | |
{ | |
if(is_numeric($_GET['p'])&& $_GET['p']>0 && $_GET['p']<= count($indexs)/10+1){ | |
$a=0; | |
foreach($indexs as $page){ | |
$a++; | |
if($a<=($_GET['p']-1)*10) | |
{ | |
continue; | |
} | |
else | |
{ | |
$html=file_get_html("./blog/".$page); | |
foreach($html->find('body') as $e) | |
{ | |
$e->find('h1', 0)->innertext ="<a href='".$page."'>".$e->find('h1', 0)->innertext ."</a>"; | |
echo "<div id='single'>".$e->innertext.'<br>'; | |
echo("<a href='".$page."#disqus_thread'>查看评论->>></a></div>"); | |
$b=($_GET['p']-1)*10+10; | |
if($a==$b) | |
{ | |
break 2; | |
} | |
} | |
} | |
} | |
echo "<div style='padding:15px;border-top:solid 1px #f9f9f9;height:34px;'>"; | |
if($_GET['p']>1){echo "<a href='?p=" .($_GET['p']-1)."'><button style='margin-left:10px;'>上一页</button></a>";}; | |
if($_GET['p']<count($indexs)/10){echo "<a href='?p=" .($_GET['p']+1)."'><button style='float:right;margin-right:20px;'>下一页</button></a>";} | |
echo "</div>"; | |
//echo "<div style='padding:15px;border-top:solid 1px #f9f9f9;'><a href='?p=" .($_GET['p']-1)."'><button style='margin-right:400px;'>上一页</button></a><a href='?p=" .($_GET['p']+1)."'><button>下一页</button></a></div>"; | |
} | |
else{ | |
echo '参数错误 !'; | |
} | |
} | |
else | |
{ | |
$a=0; | |
foreach($indexs as $page){ | |
$a++; | |
$html=file_get_html("./blog/".$page); | |
foreach($html->find('body') as $e) | |
{ | |
$e->find('h1', 0)->innertext ="<a href='".$page."'>".$e->find('h1', 0)->innertext ."</a>"; | |
echo "<div id='single'>".$e->innertext.'<br>'; | |
echo("<a href='".$page."#disqus_thread'>查看评论->>></a></div>"); | |
if($a==10) | |
{ | |
break 2; | |
} | |
} | |
} | |
echo "<div style='padding:15px;border-top:solid 1px #f9f9f9;height:34px'><a href='?p=2'><button style='margin-left:500px;'>下一页</button></a></div>"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment