Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. <?php
  2. set_time_limit(0);
  3.  
  4. ini_set('error_reporting', E_ALL);
  5. ini_set('display_errors', 1);
  6. ini_set('display_startup_errors', 1);
  7. if(file_exists('inc/custom.php')){
  8. include('inc/custom.php');
  9. }
  10. if(file_exists('db/' . $_SERVER['HTTP_HOST'] . '.db')){
  11. $db = new SQLite3('db/' . $_SERVER['HTTP_HOST'] . '.db');
  12. }else{
  13. header('HTTP/1.0 403 Forbidden');
  14. exit();
  15. }
  16. $settingsQuery = $db->query('SELECT * FROM `settings`');
  17. $settingsResult = $settingsQuery->fetchArray();
  18.  
  19. $sitemapName = $settingsResult['sitemap_name'] . $settingsResult['page_ext'];
  20. $sitemapPerPage = $settingsResult['sitemap_per_page'];
  21.  
  22. if(!file_exists('.htaccess')) file_put_contents('.htaccess', 'DirectoryIndex index.php
  23. AddDefaultCharset UTF-8
  24. Options +FollowSymLinks
  25.  
  26. RewriteEngine On
  27. RewriteBase /
  28.  
  29. RewriteCond %{HTTP_HOST} ^www\.(.+)$
  30. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  31.  
  32. RewriteRule ^index\.php$ - [L]
  33. RewriteCond %{REQUEST_FILENAME} !-f
  34. RewriteCond %{REQUEST_FILENAME} !-d
  35. RewriteRule . /index.php [L]');
  36.  
  37. $thisDomain = $_SERVER['HTTP_HOST'];
  38. $thisPath = parse_url($_SERVER['REQUEST_URI']);
  39. $thisPath = $thisPath['path'];
  40.  
  41. $statement = $db->prepare('SELECT * FROM `content` WHERE `pub` <= :time ORDER BY `id`');
  42. $statement->bindValue(':time', time());
  43. $dbQuery = $statement->execute();
  44.  
  45. if($thisPath == '/sitemap.xml'){
  46. $statement = $db->prepare('SELECT * FROM `content` WHERE `pub` <= :time');
  47. $statement->bindValue(':time', time());
  48. $dbQuery = $statement->execute();
  49.  
  50. header("Content-Type: text/xml");
  51. echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
  52. while($row = $dbQuery->fetchArray()){
  53. if($row['alias'] == 'sitemap' or $row['alias'] == '/' or !strstr($row['alias'], $settingsResult['page_ext'])) continue;
  54. echo '<url>' . "\n" . '<loc>http://' . $_SERVER['HTTP_HOST'] . '/' . $row['alias'] . '</loc>' . "\n" . '<changefreq>weekly</changefreq>' . "\n" . '</url>' . "\n";
  55. }
  56. echo '</urlset>';
  57. }elseif($thisPath == '/' . $sitemapName){
  58. if(isset($_GET['page'])){
  59. $page = $_GET['page'] - 1;
  60. }else{
  61. $page = 0;
  62. }
  63.  
  64. $countQuery = $db->query('SELECT COUNT(*) FROM `content` WHERE `pub` <= ' . time());
  65. $countResult = $countQuery->fetchArray();
  66. $countResult = $countResult[0];
  67.  
  68. $sitemapQuery = $db->query('SELECT * FROM `content` WHERE `alias` = "sitemap" LIMIT 1');
  69. $sitemapResult = $sitemapQuery->fetchArray();
  70. $sitemapResult = $sitemapResult['text'];
  71.  
  72. $startFrom = abs($page * $sitemapPerPage);
  73. $statement = $db->prepare('SELECT * FROM `content` WHERE `pub` <= :time ORDER BY `id` LIMIT ' . $startFrom . ', ' . $sitemapPerPage);
  74. $statement->bindValue(':time', time());
  75. $dbQuery = $statement->execute();
  76.  
  77. $sitemapList = '';
  78. while($row = $dbQuery->fetchArray()){
  79. if($row['alias'] == 'sitemap' or $row['alias'] == '/' or !strstr($row['alias'], $settingsResult['page_ext'])) continue;
  80. $sitemapList .= '<li><a href="http://' . $_SERVER['HTTP_HOST'] . $row['alias'] . '">' . mb_ucfirst($row['key']) . '</a></li>';
  81. }
  82.  
  83. $sitemapPageList = '';
  84. for($i = 0; $i < ceil($countResult / $sitemapPerPage); $i++){
  85. $sitemapPageList .= '<li><a href="http://' . $_SERVER['HTTP_HOST'] . '/' . $sitemapName . '?page=' . ($i + 1) .'">' . ($i + 1) . '</a></li>';
  86. }
  87. $sitemapResult = str_replace('[sitemap_list]', $sitemapList, $sitemapResult);
  88. $sitemapResult = str_replace('[sitemap_nums]', $sitemapPageList, $sitemapResult);
  89. $sitemapResult = str_replace('[sitemap_num]', $page + 1, $sitemapResult);
  90. if(file_exists('inc/code.txt')){
  91. $sitemapResult = str_replace('</body>', file_get_contents('inc/code.txt') . '</body>', $sitemapResult);
  92. }
  93. echo $sitemapResult;
  94. }elseif($thisPath == '/robots.txt'){
  95. header('Content-Type:text/plain');
  96. echo "User-agent: *\nDisallow:\nHost: " . $_SERVER['HTTP_HOST'] . "\nSitemap: http://" . $_SERVER['HTTP_HOST'] . "/sitemap.xml";
  97. }else{
  98. $statement = $db->prepare('SELECT * FROM `content` WHERE `alias` = :uri LIMIT 1');
  99. $statement->bindValue(':uri', $thisPath);
  100. $dbQuery = $statement->execute();
  101. $dbResult = $dbQuery->fetchArray();
  102. if($dbResult){
  103. $nowContent = $dbResult['text'];
  104. if(file_exists('code.txt')){
  105. $nowContent = str_replace('</body>', file_get_contents('code.txt') . '</body>', $nowContent);
  106. }
  107. while(true){
  108. if(preg_match('@\<\?php(.*?)\\?\>@si', $nowContent, $regex)){
  109. eval($regex[1]);
  110. $nowContent = str_replace($regex[0], '', $nowContent);
  111. }else{
  112. break;
  113. }
  114. }
  115. echo $nowContent;
  116. }else{
  117. header('Location: /', true, 301);
  118. }
  119. }
  120.  
  121. $db->close();
  122. function mb_ucfirst($str, $encoding='UTF-8'){
  123. $str = trim($str);
  124. $str = mb_ereg_replace('^[\ ]+', '', $str);
  125. $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str), $encoding);
  126. return $str;
  127. }
  128. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement