Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- ini_set('error_reporting', E_ALL);
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- if(file_exists('inc/custom.php')){
- include('inc/custom.php');
- }
- if(file_exists('db/' . $_SERVER['HTTP_HOST'] . '.db')){
- $db = new SQLite3('db/' . $_SERVER['HTTP_HOST'] . '.db');
- }else{
- header('HTTP/1.0 403 Forbidden');
- exit();
- }
- $settingsQuery = $db->query('SELECT * FROM `settings`');
- $settingsResult = $settingsQuery->fetchArray();
- $sitemapName = $settingsResult['sitemap_name'] . $settingsResult['page_ext'];
- $sitemapPerPage = $settingsResult['sitemap_per_page'];
- if(!file_exists('.htaccess')) file_put_contents('.htaccess', 'DirectoryIndex index.php
- AddDefaultCharset UTF-8
- Options +FollowSymLinks
- RewriteEngine On
- RewriteBase /
- RewriteCond %{HTTP_HOST} ^www\.(.+)$
- RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
- RewriteRule ^index\.php$ - [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]');
- $thisDomain = $_SERVER['HTTP_HOST'];
- $thisPath = parse_url($_SERVER['REQUEST_URI']);
- $thisPath = $thisPath['path'];
- $statement = $db->prepare('SELECT * FROM `content` WHERE `pub` <= :time ORDER BY `id`');
- $statement->bindValue(':time', time());
- $dbQuery = $statement->execute();
- if($thisPath == '/sitemap.xml'){
- $statement = $db->prepare('SELECT * FROM `content` WHERE `pub` <= :time');
- $statement->bindValue(':time', time());
- $dbQuery = $statement->execute();
- header("Content-Type: text/xml");
- echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
- while($row = $dbQuery->fetchArray()){
- if($row['alias'] == 'sitemap' or $row['alias'] == '/' or !strstr($row['alias'], $settingsResult['page_ext'])) continue;
- echo '<url>' . "\n" . '<loc>http://' . $_SERVER['HTTP_HOST'] . '/' . $row['alias'] . '</loc>' . "\n" . '<changefreq>weekly</changefreq>' . "\n" . '</url>' . "\n";
- }
- echo '</urlset>';
- }elseif($thisPath == '/' . $sitemapName){
- if(isset($_GET['page'])){
- $page = $_GET['page'] - 1;
- }else{
- $page = 0;
- }
- $countQuery = $db->query('SELECT COUNT(*) FROM `content` WHERE `pub` <= ' . time());
- $countResult = $countQuery->fetchArray();
- $countResult = $countResult[0];
- $sitemapQuery = $db->query('SELECT * FROM `content` WHERE `alias` = "sitemap" LIMIT 1');
- $sitemapResult = $sitemapQuery->fetchArray();
- $sitemapResult = $sitemapResult['text'];
- $startFrom = abs($page * $sitemapPerPage);
- $statement = $db->prepare('SELECT * FROM `content` WHERE `pub` <= :time ORDER BY `id` LIMIT ' . $startFrom . ', ' . $sitemapPerPage);
- $statement->bindValue(':time', time());
- $dbQuery = $statement->execute();
- $sitemapList = '';
- while($row = $dbQuery->fetchArray()){
- if($row['alias'] == 'sitemap' or $row['alias'] == '/' or !strstr($row['alias'], $settingsResult['page_ext'])) continue;
- $sitemapList .= '<li><a href="http://' . $_SERVER['HTTP_HOST'] . $row['alias'] . '">' . mb_ucfirst($row['key']) . '</a></li>';
- }
- $sitemapPageList = '';
- for($i = 0; $i < ceil($countResult / $sitemapPerPage); $i++){
- $sitemapPageList .= '<li><a href="http://' . $_SERVER['HTTP_HOST'] . '/' . $sitemapName . '?page=' . ($i + 1) .'">' . ($i + 1) . '</a></li>';
- }
- $sitemapResult = str_replace('[sitemap_list]', $sitemapList, $sitemapResult);
- $sitemapResult = str_replace('[sitemap_nums]', $sitemapPageList, $sitemapResult);
- $sitemapResult = str_replace('[sitemap_num]', $page + 1, $sitemapResult);
- if(file_exists('inc/code.txt')){
- $sitemapResult = str_replace('</body>', file_get_contents('inc/code.txt') . '</body>', $sitemapResult);
- }
- echo $sitemapResult;
- }elseif($thisPath == '/robots.txt'){
- header('Content-Type:text/plain');
- echo "User-agent: *\nDisallow:\nHost: " . $_SERVER['HTTP_HOST'] . "\nSitemap: http://" . $_SERVER['HTTP_HOST'] . "/sitemap.xml";
- }else{
- $statement = $db->prepare('SELECT * FROM `content` WHERE `alias` = :uri LIMIT 1');
- $statement->bindValue(':uri', $thisPath);
- $dbQuery = $statement->execute();
- $dbResult = $dbQuery->fetchArray();
- if($dbResult){
- $nowContent = $dbResult['text'];
- if(file_exists('code.txt')){
- $nowContent = str_replace('</body>', file_get_contents('code.txt') . '</body>', $nowContent);
- }
- while(true){
- if(preg_match('@\<\?php(.*?)\\?\>@si', $nowContent, $regex)){
- eval($regex[1]);
- $nowContent = str_replace($regex[0], '', $nowContent);
- }else{
- break;
- }
- }
- echo $nowContent;
- }else{
- header('Location: /', true, 301);
- }
- }
- $db->close();
- function mb_ucfirst($str, $encoding='UTF-8'){
- $str = trim($str);
- $str = mb_ereg_replace('^[\ ]+', '', $str);
- $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str), $encoding);
- return $str;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement