Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * shimansky.biz, mobile-english.ru
- *
- * Static web site core scripts
- * @package shimansky.biz
- * @author Serguei Shimansky <[email protected]>
- * @copyright Serguei Shimansky 11:28 23.07.2011
- * @access public
- * @version 0.1
- * @link https://bitbucket.org/englishextra/shimansky.biz
- * @link https://bitbucket.org/englishextra/mobile-english.ru
- * @link https://github.com/englishextra/shimansky.biz.git
- * @link https://github.com/englishextra/mobile-english.ru.git
- */
- $relpa = ($relpa0 = preg_replace("/[\/]+/", "/", $_SERVER['DOCUMENT_ROOT'] . '/')) ? $relpa0 : '';
- $a_inc = array(
- 'lib/lib_global2.inc',
- 'lib/lib_mysql2.inc',
- 'inc/vars2.inc',
- 'inc/regional.inc',
- 'inc/adminauth.inc',
- 'inc/mysql.inc',
- 'inc/update_config_' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . '.inc'
- );
- foreach ($a_inc as $v) {require_once $relpa . $v;}
- /**
- * functions
- */
- function lib_local_write_file ($data, $w, $type) {
- if (!$fo = fopen($data, $type)) {
- die('Cannot open file: ' . $data);
- }
- if (!is_writable($data)) {
- die('Cannot write file: ' . $data);
- }
- flock($fo, LOCK_EX);
- fputs($fo, $w);
- fflush($fo);
- flock($fo, LOCK_UN);
- fclose($fo);
- }
- function lib_write_dir_index_html($title, $description, $filepath, $relpa, $site_root_printable, $p, $uplevel_link, $qrcode_sprite_image, $qrcode, $qrcode_title, $css, $js) {
- lib_local_write_file ($relpa . $filepath . 'index.html', '<!--#include virtual="/virtual/head.html" -->
- <meta name="description" content="' . lib_global2_ensure_amp(lib_global2_remove_tags($description)) . '" />
- <title>' . $site_root_printable . ' - ' . lib_global2_ensure_amp($title) . '</title>
- </head>
- <body>
- <!--#include virtual="/virtual/top.html" -->
- <h1><a href="' . $uplevel_link . '"> ↑ </a> ' . lib_global2_ensure_amp($title) . '</h1>
- <!--<div id="pageqrcode" title="' . $qrcode_title . '" style="background:url(' . $qrcode_sprite_image . ') no-repeat top left;background-position:' . $qrcode . ';"></div>-->
- <!--<div id="pageqrcode" title="' . $qrcode_title . '" style="width:137px;height:137px;background:url(/images/QR_CODE/' . $qrcode . ') no-repeat top left;background-color:transparent;"></div>-->
- ' . "\n" . '<p>' . lib_global2_ensure_amp($description) . '</p>' . "\n" . $p . '
- <!--#include virtual="/virtual/bottom.html" -->
- <!--#include virtual="/virtual/counters.html" -->
- <!--#include virtual="/virtual/foot.html" -->' . "\n", "w+");
- echo 'written dir index in file ' . $filepath . "<br />\n";
- }
- function lib_local_update_dir_info($title, $description, $production_dir, $ext, $relpa, $site_root, $site_root_printable, $table_name, $read_length, $qrcode_sprite_image, $qrcode, $qrcode_title, $css, $js) {
- $dir = $relpa . $production_dir;
- if ($opendir = opendir($dir)) {
- $files = array();while ($files[] = readdir($opendir));sort($files, SORT_STRING);reset($files);closedir($opendir);
- $p = '';
- foreach($files as $file) {
- if (!is_dir($dir . $file)) {
- $content = lib_global2_read_local_file($dir . $file, $f = '');
- if (preg_match("/\." . preg_quote($ext, "/") . "$/i", $file) && $file !='index.html' && $file !='index.php' && preg_match('#<title[^>]*>(.+?)</title>#', $content, $matches0) && preg_match('#<meta name="description" content="(.+?)" />#', $content, $matches1)) {
- $heading = preg_replace("/[ ]+/", " ", str_replace(array($site_root_printable, 'localhost', 'mobile-english.ru', 'shimansky.biz', ' - ' . $title . ' - ', '\''), array('', '', '', '', '', '''), $matches0[1]));
- $about = preg_replace("/[ ]+/", " ", str_replace(array('\''), array('''), $matches1[1]));
- $wordhash = lib_global2_html_to_safe_str(str_replace(array($site_root_printable . ' - ', '\'', $heading, $about), array('', ''', '', ''), $content), $read_length);
- if (!empty($heading) && !empty($about)) {
- $p .= '<h2><a href="' . htmlentities('/' . $production_dir . $file) . '">' . lib_global2_ensure_amp($heading) . '</a></h2><p>' . lib_global2_ensure_amp($about) . '</p>';//' . "\n";
- //$p .= '<dl><dt><a href="' . htmlentities('/' . $production_dir . $file) . '">' . lib_global2_ensure_amp($heading) . '</a></dt><dd>' . lib_global2_ensure_amp($about) . '</dd></dl>';//' . "\n";
- @mysql_query("INSERT INTO `" . $table_name . "` (`page_title`, `page_url`, `description`, `wordhash`) VALUES ('" . mysql_real_escape_string (lib_global2_ensure_amp($title . ' - ' . $heading)) . "', '" . mysql_real_escape_string (lib_global2_ensure_amp(htmlentities('/' . $production_dir . $file))) . "', '" . mysql_real_escape_string (lib_global2_ensure_amp($about)) . "', '" . mysql_real_escape_string (lib_global2_ensure_amp($wordhash)) . "');") or die(@mysql_error());
- }
- }
- }
- }
- lib_write_dir_index_html($title, $description, $production_dir, $relpa, $site_root_printable, $p, '../', $qrcode_sprite_image, $qrcode, $qrcode_title, $css, $js);
- }
- }
- $table_name = $pt_pages_table_name;
- /**
- * clear index table
- */
- @mysql_query("DROP TABLE IF EXISTS `" . $table_name . "`;") or die(@mysql_error());
- @mysql_query("CREATE TABLE `" . $table_name . "` ( `id` mediumint(9) NOT NULL AUTO_INCREMENT, `page_title` mediumtext NOT NULL, `page_url` varchar(255) NOT NULL DEFAULT '', `description` mediumtext NOT NULL, `wordhash` mediumtext NOT NULL, PRIMARY KEY (`id`), FULLTEXT KEY `page_title` (`page_title`), FULLTEXT KEY `description` (`description`), FULLTEXT KEY `wordhash` (`wordhash`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or die(@mysql_error());
- /**
- * update directories
- * $dirs is an array in inc/update_config_' . str_replace('www.', '', $_SERVER['HTTP_HOST']) . '.inc
- */
- sort($dir, 0);reset($dir);
- /**
- * write index.html in each directory
- */
- for ($i = 0; $i < count($dir); $i++) {
- if (!empty($dir[$i][0]) && !empty($dir[$i][1]) && !empty($dir[$i][2]) && !empty($dir[$i][3]) && !empty($dir[$i][4])) {
- lib_local_update_dir_info($dir[$i][0], $dir[$i][1], $dir[$i][2], $dir[$i][3], $relpa, $vars2_site_root, $vars2_site_root_printable, $table_name, $update_config_read_length, $update_config_qrcode_sprite_image, $dir[$i][4], $update_config_qrcode_title, $update_config_css, $update_config_js);
- }
- }
- /**
- * generate list for directories contents index.html
- */
- $p = '';
- $pages_xml_str = '';
- for ($i = 0; $i < count($dir); $i++) {
- if (!empty($dir[$i][0]) && !empty($dir[$i][1]) && !empty($dir[$i][2]) && !empty($dir[$i][3])) {
- $p .= '<h2><a href="/' . htmlentities($dir[$i][2]). '">' . lib_global2_ensure_amp($dir[$i][0]) . '</a></h2><p>' . lib_global2_ensure_amp($dir[$i][1]) . '</p>';//' . "\n";
- //$p .= '<dl><dt><a href="/' . htmlentities($dir[$i][2]). '">' . lib_global2_ensure_amp($dir[$i][0]) . '</a></dt><dd>' . lib_global2_ensure_amp($dir[$i][1]) . '</dd></dl>';//' . "\n";
- $pages_xml_str .= '<item><title>' . lib_global2_ensure_amp($dir[$i][0]) . '</title><link>' . htmlentities($vars2_site_root . $dir[$i][2]) . '</link><description>' . lib_global2_ensure_amp($dir[$i][1]) . '</description><category>Pages</category><pubDate>' . date("r") . '</pubDate></item>';//' . "\n";
- }
- }
- /**
- * write directories contents index.html
- */
- lib_write_dir_index_html($update_config_msg_site_contents, lib_global2_ensure_amp(lib_global2_remove_tags($pt_regional['site_description'])), $update_config_pages_dir, $relpa, $vars2_site_root_printable, $p, '../', $update_config_qrcode_sprite_image, $update_config_contents_qrcode, $update_config_qrcode_title, $update_config_css, $update_config_js);
- /**
- * update pages.xml
- */
- lib_local_write_file($relpa . $update_config_pages_xml, '<?xml version="1.0" encoding="UTF-8"?>
- <rss version="2.0"
- xmlns:content="http://purl.org/rss/1.0/modules/content/"
- xmlns:wfw="http://wellformedweb.org/CommentAPI/"
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:atom="http://www.w3.org/2005/Atom"
- xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
- xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
- >
- <channel>
- <title>' . ucwords($vars2_site_root_printable) . ' - ' . lib_global2_ensure_amp($pt_regional['root_page_title']) . '</title>
- <atom:link href="' . htmlentities($vars2_site_root . $update_config_pages_xml) . '" rel="self" type="application/rss+xml" />
- <link>' . htmlentities($vars2_site_root . $update_config_pages_xml) . '</link>
- <description>' . lib_global2_ensure_amp(lib_global2_remove_tags($pt_regional['site_description'])) . '</description>
- <lastBuildDate>' . date("r") . '</lastBuildDate>
- <language>en</language>
- <sy:updatePeriod>hourly</sy:updatePeriod>
- <sy:updateFrequency>1</sy:updateFrequency>
- <generator>http://wordpress.org/?v=3.0.1</generator>
- ' . $pages_xml_str . '
- </channel>
- </rss>', "w+");
- /**
- * update root directory index.html
- */
- lib_local_write_file($relpa . 'index.html', '<!--#include virtual="/virtual/head.html" -->
- <meta name="description" content="' . lib_global2_ensure_amp(lib_global2_remove_tags($pt_regional['site_description'])) . '" />
- <link rel="stylesheet" href="/scripts/minify/?type=css&load=homepage" type="text/css" />
- <title>' . $vars2_site_root_printable . ' - ' . lib_global2_ensure_amp($pt_regional['root_page_title']) . '</title>
- </head>
- <body>
- <!--#include virtual="/virtual/top.html" -->
- <!--#include virtual="/virtual/homepage.html" -->
- <!--#include virtual="/virtual/bottom.html" -->
- <!--#include virtual="/virtual/counters.html" -->
- <!--#include virtual="/virtual/foot.html" -->', "w+");
- /**
- * update Cache-Control, Expires, Last-Modified
- */
- $p = lib_global2_read_local_file($relpa . 'virtual/head.html');
- $p = preg_replace("/\<meta http\-equiv\=\"Cache-Control\" content\=\"(.*?)\" \/\>/i", "<meta http-equiv=\"Cache-Control\" content=\"public, max-age=" . $update_config_expires_offset . "\" />", $p);
- $p = preg_replace("/\<meta http\-equiv\=\"Expires\" content\=\"(.*?)\" \/\>/i", "<meta http-equiv=\"Expires\" content=\"" . gmdate('D, d M Y H:i:s', time() + $update_config_expires_offset ) . " GMT\" />", $p);
- $p = preg_replace("/\<meta http\-equiv\=\"Last\-Modified\" content\=\"(.*?)\" \/\>/i", "<meta http-equiv=\"Last-Modified\" content=\"" . gmdate('D, d M Y H:i:s \G\M\T') . "\" />", $p);
- lib_local_write_file($relpa . 'virtual/head.html', $p, "w+");
- /**
- * clear logs
- */
- lib_local_write_file($relpa . 'logs/sniffer.log', '', "w+");
- lib_local_write_file($relpa . 'logs/sniffer_robots.log', '', "w+");
- lib_local_write_file($relpa . 'logs/ua.log', '', "w+");
- /**
- * print out
- */
- echo 'done!';
Advertisement
Add Comment
Please, Sign In to add comment