Skip to content

Instantly share code, notes, and snippets.

@englishextra
Created April 21, 2011 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save englishextra/935614 to your computer and use it in GitHub Desktop.
Save englishextra/935614 to your computer and use it in GitHub Desktop.
shimansky.biz/scripts/update.php
<?php
/**
* Documents the class following or the file?
* @package Shimansky.biz-web-site-source-code
*/
$relpa = preg_replace("/[\/]+/", "/", $_SERVER['DOCUMENT_ROOT'] . '/');
$a = array(
'inc/init2.inc'
);
foreach ($a as $v) { require_once $relpa . $v; }
/**
* functions
*/
function lib_local_write_file ($f, $s, $t) {
if (file_exists($f)) {
fopen($f, $t);
lib_global2_write_file($f, $s, $t);
}
}
function lib_local_return_feed_header($vars2_site_root_printable, $page_title, $page_description, $vars2_site_root, $filepath) {
return '<?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($page_title) . '</title>
<atom:link href="' . htmlentities($vars2_site_root . $filepath) . '" rel="self" type="application/rss+xml" />
<link>' . htmlentities($vars2_site_root . $filepath) . '</link>
<description>' . lib_global2_ensure_amp($page_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>' . "\n";
}
function lib_local_return_sitemap_header($vars2_site_root, $relpa) {
return '<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="' . htmlentities($vars2_site_root) . 'feeds/sitemap.xsl"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>' . htmlentities($vars2_site_root) . '</loc>
<lastmod>' . date('Y-m-d\TH:i:s+00:00', filemtime($relpa . 'index.php')) . '</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>' . "\n";
}
function lib_write_dir_index($page_title, $page_description, $filepath, $relpa, $vars2_site_root_printable, $p) {
lib_local_write_file ($relpa . $filepath, '<!--#include virtual="/virtual/head.html" -->
<meta name="description" content="' . lib_global2_ensure_amp(lib_global2_remove_tags($page_description)) . '" />
<link rel="stylesheet" href="/css/?ver=1300592841&amp;type=css&amp;load=sen,shimanskybiz,simplemodal" type="text/css" />
<title>' . lib_global2_ensure_amp($vars2_site_root_printable . ' - ' . $page_title) . '</title>
<script type="text/javascript" src="/js/?ver=1300592908&amp;type=js&amp;load=global,jquery,preloadimages,simplemodal,feedback,search,login,guestbook"></script>
</head>
<body>
<!--#include virtual="/virtual/top.html" -->
<h1>' . lib_global2_ensure_amp($page_title) . '</h1>' . "\n" . '<p>' . lib_global2_ensure_amp($page_description) . '</p>' . "\n" . $p . '
<!--#include virtual="/virtual/bottom.html" -->
<!--#include virtual="/virtual/counters.html" -->
<!--#include virtual="/virtual/foot.html" -->' . "\n", "w+");
}
function lib_local_update_dir_info($page_title, $page_description, $production_dir, $ext, $relpa, $vars2_site_root, $vars2_site_root_printable, $table_name, $read_length) {
$dir = $relpa . $production_dir;
if ($opendir = opendir($dir)) {
$files = array();while ($files[] = readdir($opendir));sort($files, SORT_STRING);reset($files);closedir($opendir);
$p = '';
$p1 = '';
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)) {
$h1 = preg_replace("/[ ]+/", " ", str_replace(array($vars2_site_root_printable, 'localhost', 'mobile-english.ru', 'shimansky.biz', ' - ' . $page_title . ' - ', '\''), array('', '', '', '', '', '&#39;'), $matches0[1]));
$description = preg_replace("/[ ]+/", " ", str_replace(array('\''), array('&#39;'), $matches1[1]));
$wordhash = lib_global2_html_to_safe_str(str_replace(array($vars2_site_root_printable . ' - ', '\'', $h1, $description), array('', '&#39;', '', ''), $content), $read_length);
if (!empty($h1) && !empty($description)) {
$p .= '<h2><a href="' . htmlentities('/' . $production_dir . $file) . '">' . lib_global2_ensure_amp($h1) . '</a></h2><p>' . lib_global2_ensure_amp($description) . '</p>' . "\n";
@mysql_query("INSERT INTO `" . $table_name . "` (`page_title`, `page_url`, `description`, `wordhash`) VALUES ('" . mysql_real_escape_string (lib_global2_ensure_amp($page_title . ' - ' . $h1)) . "', '" . mysql_real_escape_string (lib_global2_ensure_amp('/' . $production_dir . $file)) . "', '" . mysql_real_escape_string (lib_global2_ensure_amp($description)) . "', '" . mysql_real_escape_string (lib_global2_ensure_amp($wordhash)) . "');") or die(@mysql_error());
}
}
}
}
lib_write_dir_index($page_title, $page_description, $production_dir .'index.html', $relpa, $vars2_site_root_printable, $p);
//echo $p . "\n";
}
}
function lib_local_update_download_dir_info($page_title, $page_description, $production_dir, $ext, $feed_xml, $table_name, $array_inc, $relpa, $vars2_site_root, $vars2_site_root_printable) {
$dir = $relpa . $production_dir;
if ($opendir = opendir($dir)) {
$files = array();while ($files[] = readdir($opendir));sort($files, SORT_STRING);reset($files);closedir($opendir);
$p = '' . "\n";
$p1 = '';
$p2 = lib_local_return_feed_header($vars2_site_root_printable, $page_title, $page_description, $vars2_site_root, $feed_xml);
$query1 = @mysql_query("DROP TABLE IF EXISTS `" . $table_name . "`;") or die(@mysql_error());
$query2 = @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 '', PRIMARY KEY (`id`), FULLTEXT KEY `page_title` (`page_title`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;") or die(@mysql_error());
foreach($files as $file) {
if (!is_dir($dir . $file)) {
if (preg_match("/\." . preg_quote($ext, "/") . "$/i", $file) && $file !='index.html' && $file !='index.php' && preg_match("/[^\.]+$/", $file, $matches)) {
$tail = strstr($file, '.');
$ext = strtoupper($matches[0]);
$lastmod = str_replace(' ', '&#160;', date("j/m/y h:i", filemtime($dir . $file)));
$h1 = preg_replace("/[\_]+/", "_", preg_replace("/[ ]+/", " ", (ucwords(str_replace(array($tail, '_','-','\''), array('', ' ', ' ',''), $file)))));
$p .= '<h2><a href="' . htmlentities($vars2_site_root . $production_dir . $file) . '">' . lib_global2_ensure_amp($h1) . '</a></h2><p>' . str_replace(' ', '&#160;', number_format(filesize($dir . $file)/1024, 0, '', ' ')) . '&#160;Kb&#160;&#183; ' . $lastmod . '&#160;&#183; <a href="' . htmlentities('/' . $production_dir . $file) . '">Скачать</a></p>' . "\n";
$p1 .= '$a[]=array(\'' . lib_global2_ensure_amp($h1) . '\', \'' . lib_global2_ensure_amp('/' . $production_dir . $file) . '\' ,\''. str_replace(' ', '&#160;', number_format(filesize($dir . $file)/1024, 0, '', ' ')) . '&#160;Kb\', \'' . $lastmod . '\');' . "\n";
@mysql_query("INSERT INTO `" . $table_name . "` (`page_title`, `page_url`) VALUES ('" . mysql_real_escape_string (lib_global2_ensure_amp($h1)) . "', '" . mysql_real_escape_string (lib_global2_ensure_amp('/' . $production_dir . $file)) . "');") or die(@mysql_error());
}
}
}
$p .= '' . "\n";
lib_local_write_file ($relpa . $array_inc, '<?php' . "\n" . $p1 . "\n", "w+");
lib_local_write_file ($relpa . $feed_xml, $p2 . '</channel>' . "\n" . '</rss>' . "\n", "w+");
lib_write_dir_index($page_title, $page_description, $production_dir .'index.html', $relpa, $vars2_site_root_printable, $p);
//echo $p;
}
}
/**
* start of indexing
*/
$page_title = $pt_regional['root_page_title'];
/**
* main output string
*/
$p = '';
/**
* show popular
*/
$p .= '<div class="one_fourth_left_column"><h2>Популярные</h2>' . "\n";
$a = null;//empty $a array
$a[]=array('Готовимся к ЕГЭ по английскому', 'Варианты, бланки, билеты, задания, пособия.', 'pages/more/more_state_exam_gia_ege.html');
$a[]=array('Ключи. 6-е издание', 'Ответы к упражнениям популярного учебника по грамматике. Издание 6-е.', 'pages/aids/aids_golitsynsky_keys2007.html');
$a[]=array('Фильмы на английском без перевода с субтитрами (PSP/iPod)', 'Фильмы на английском с субтитрами без перевода.', 'pages/more/more_movies_3gp_ipod_psp.html');
$a[]=array('PDF архив материалов ресурса', 'Материалы в формате PDF для свободного скачивания.', 'pages/more/more_pdf.html');
$a[]=array('Сборник рефератов на английском', 'Самые разные темы для школьников и студентов тоже.', 'pages/aids/aids_essays.html');
$a[]=array('Топики на английском', 'Типовые темы по английскому с переводом на русский.', 'pages/aids/aids_topics.html');
$a[]=array('Тесты по английскому', 'Тесты по грамматике с вариантами ответов.', 'pages/aids/aids_tests.html');
$a[]=array('Статьи по грамматике английского языка', 'Кратко изложенная грамматика английского с таблицами.', 'pages/aids/aids_grammar.html');
$a[]=array('Игры', 'Интерактивные тесты по лексике, грамматике и правилам чтения.', 'pages/more/more_games.html');
$a[]=array('Заставки для Рабочего стола', 'Скачать наши заставки для Рабочего стола бесплатно.', 'pages/products/products_screensavers.html');
$a[]=array('Тематический словарь в картинках', 'Словарь в картинках с переводом на русский.', 'pages/aids/aids_visual_dictionary_online.html');
sort($a, 0);reset($a);
for ($i = 0; $i < count($a); $i++) {
if (!empty($a[$i][0]) && !empty($a[$i][1]) && !empty($a[$i][2])) {
$p .= '<p><a href="' . htmlentities('/' . $a[$i][2]) . '">' . lib_global2_ensure_amp($a[$i][0]) . '</a></p><p>' . lib_global2_ensure_amp($a[$i][1]) . '</p>' . "\n";
}
}
$a = null;//empty $a array
$p .= '' . "\n" . '</div>' . "\n";
/**
* index directories in pages/ and update /sitemap.xml and feeds/pages.xml
*/
$pages_xml_str = lib_local_return_feed_header($vars2_site_root_printable, $pt_regional['root_page_title'], $pt_regional['site_description'], $vars2_site_root, 'feeds/pages.xml');
$sitemap_xml_str = lib_local_return_sitemap_header($vars2_site_root, $relpa);
/**
* clear index table
*/
@mysql_query("DROP TABLE IF EXISTS `" . $pt_pages_table_name . "`;") or die(@mysql_error());
@mysql_query("CREATE TABLE `" . $pt_pages_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());
/**
* directories to index array
*/
$a = null;//empty $a array
$a[]=array('Пособия', 'Разговорные и лексические курсы, сценарии, топики, тесты.', 'pages/aids/', 'html');
$a[]=array('Еще!', 'Статьи, которые трудно отнести к какой-либо категории, но очень содержательные и посещаемые.', 'pages/more/', 'html');
$a[]=array('Галерея', 'Фото англоязычных городов.', 'pages/gallery/', 'html');
$a[]=array('Продукты', 'Заставки для рабочего стола, коды для вебмастеров и прочее.', 'pages/products/', 'html');
$a[]=array('Блог', 'Что-то, что не совсем относится к тематике сайта, но может оказаться полезным.', 'pages/blog/', 'html');
$a[]=array('Викторины по английскому', 'Викторины по грамматике с ответами.', 'pages/quizzes/', 'html');
$a[]=array('Лексический курс Learning English Words', 'Тематические подборки из наиболее употребляемых слов на английском.', 'pages/learning_english_words/', 'html');
$a[]=array('Разговорный курс English for Business Meetings', 'Текст к курсу &#171;Английский для деловых переговоров&#187;.', 'pages/english_for_business_meetings/', 'html');
$a[]=array('Разговорный курс English for Russian Speakers (100% аудио английский)', 'Текст к популярному курсу &#171;100% Аудио Английский&#187;.', 'pages/english_for_russian_speakers/', 'html');
$a[]=array('Сборник рефератов на английском', 'Самые разные темы.', 'pages/essays/', 'html');
$a[]=array('Статьи по грамматике английского языка', 'Кратко изложенная грамматика английского с таблицами.', 'pages/grammar/', 'html');
$a[]=array('Тематический словарь в картинках', 'Словарь в картинках с переводом на русский.', 'pages/visual_dictionary_online/', 'html');
$a[]=array('Тесты по английскому', 'Тесты по грамматике с ответами.', 'pages/tests/', 'html');
$a[]=array('Топики на английском', 'Типовые темы по английскому.', 'pages/topics/', 'html');
$a[]=array('Транскрипты', 'Сценарии фильмов на английском.', 'pages/transcripts/', 'html');
$a[]=array('Bridge to English &#8212; лингафонный курс Без проблем...', 'Текст к курсу &#171;Без проблем...&#187;', 'pages/bridge_to_english2/', 'html');
$a[]=array('Effortless English Lessons', '&#171;Английский без труда.&#187; Разве бывает такое?', 'pages/effortless_english_lessons/', 'html');
$a[]=array('Idiom Drills английские идиомы: диалоги, упражнения, тексты', 'Идиоматические выражения на английском с упражнениями и текстами для чтения и пересказа.', 'pages/idiom_drills/', 'html');
sort($a, 0);reset($a);
for ($i = 0; $i < count($a); $i++) {
if (!empty($a[$i][0]) && !empty($a[$i][1]) && !empty($a[$i][2]) && !empty($a[$i][3])) {
lib_local_update_dir_info($a[$i][0], $a[$i][1], $a[$i][2], $a[$i][3], $relpa, $vars2_site_root, $vars2_site_root_printable, $pt_pages_table_name, 4000);
$pages_xml_str .= '<item><title>' . lib_global2_ensure_amp($a[$i][0]) . '</title><link>' . htmlentities($vars2_site_root . $a[$i][2]) . '</link><description>' . lib_global2_ensure_amp($a[$i][1]) . '</description><category>Pages</category><pubDate>' . date("r") . '</pubDate></item>' . "\n";
$sitemap_xml_str .= '<url>' . "\n" . '<loc>' . htmlentities($vars2_site_root . $a[$i][2]) . '</loc>' . "\n" . '<lastmod>' . date('Y-m-d\TH:i:s+00:00', filemtime($relpa . $a[$i][2] . 'index.html')) . '</lastmod>' . "\n" . '<changefreq>monthly</changefreq>' . "\n" . '<priority>0.2</priority>' . "\n" . '</url>' . "\n";
}
}
$pages_xml_str .= '</channel>' . "\n" . '</rss>' . "\n";
$sitemap_xml_str .= '</urlset>' . "\n";
lib_local_write_file ($relpa . 'feeds/pages.xml', $pages_xml_str, "w+");
lib_local_write_file ($relpa . 'sitemap.xml', $sitemap_xml_str, "w+");
/**
* output for Contents -- just list of directories in pages/
*/
$p .= '<div class="one_fourth_left_column"><h2>Разделы</h2>' . "\n";
for ($i = 0; $i < count($a); $i++) {
if (!empty($a[$i][0]) && !empty($a[$i][1]) && !empty($a[$i][2]) && !empty($a[$i][3])) {
$p .= '<p><a href="/' . htmlentities($a[$i][2]). '">' . lib_global2_ensure_amp($a[$i][0]) . '</a></p><p>' . lib_global2_ensure_amp($a[$i][1]) . '</p>' . "\n";
}
}
$a = null;//empty $a array
$p .= '' . "\n" . '</div>' . "\n";
/**
* update downloads indexes
*/
$p .= '<div class="one_fourth_left_column"><h2>Скачать</h2>' . "\n";
$a = null;//empty $a array
$a[]=array('Скачать ePub по английскому', 'Материалы в формате ePub для свободного скачивания.', 'dl/epub/', 'epub', 'feeds/epub.xml', 'pt_epub', 'pt_epub.inc', 'pages/more/more_epub.html');
$a[]=array('Скачать DjVu по английскому', 'Материалы в формате DjVu для свободного скачивания.', 'dl/djvu/', 'djvu', 'feeds/djvu.xml', 'pt_djvu', 'pt_djvu.inc', 'pages/more/more_djvu.html');
$a[]=array('Скачать PDF по английскому', 'Материалы в формате PDF для свободного скачивания.', 'dl/pdf/', 'pdf', 'feeds/pdf.xml', 'pt_pdf', 'pt_pdf.inc', 'pages/more/more_pdf.html');
sort($a, 0);reset($a);
for ($i = 0; $i < count($a); $i++) {
if (!empty($a[$i][0]) && !empty($a[$i][1]) && !empty($a[$i][2]) && !empty($a[$i][3]) && !empty($a[$i][4]) && !empty($a[$i][5]) && !empty($a[$i][6]) && !empty($a[$i][7])) {
lib_local_update_download_dir_info($a[$i][0], $a[$i][1], $a[$i][2], $a[$i][3], $a[$i][4], $a[$i][5], $a[$i][6], $relpa, $vars2_site_root, $vars2_site_root_printable);
$p .= '<p><a href="' . htmlentities('/' . $a[$i][7]) . '">' . lib_global2_ensure_amp($a[$i][0]) . '</a></p><p>' . lib_global2_ensure_amp($a[$i][1]) . '</p>' . "\n";
}
}
$a = null;//empty $a array
$p .= '' . "\n" . '</div>' . "\n";
$p .= '<div style="clear:both;"></div>' . "\n";
lib_write_dir_index($page_title, $pt_regional['site_description'], 'pages/index.html', $relpa, $vars2_site_root_printable, $p);
//lib_local_write_file($relpa . 'virtual/homepage.html', '<h1>' . lib_global2_ensure_amp($page_title) . '</h1>' . "\n" . '<p>' . $pt_regional['site_description'] . '</p>' . "\n" . $p, "w+");
/**
* update Last-Modified
*/
lib_local_write_file($relpa . 'virtual/head.html', preg_replace("/\<meta http\-equiv\=\"Last\-Modified\" content\=\"(.*?)\" \/\>/i", "<meta http-equiv=\"Last-Modified\" content=\"" . date("r") . "\" />", lib_global2_read_local_file($relpa . 'virtual/head.html')), "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+");
/**
* make file list to parse by phpDocumentor
*/
if (file_exists($relpa . 'phpdoc.txt')) {
$a = array("addressbook",
"externalcounters",
"inc",
"lib",
"scripts",
"search",
"weekcalendar");
$p3 = '';
foreach($a as $v) {
$dir = $relpa . $v;
if (file_exists($dir)) {
if ($opendir = opendir($dir)) {
$files = array();while ($files[] = readdir($opendir));sort($files, SORT_STRING);reset($files);closedir($opendir);
foreach($files as $file) {
if (!is_dir($dir .'/' . $file) && ( preg_match("/\.php$/i", $dir .'/' . $file) || preg_match("/\.inc$/i", $dir .'/' . $file) ) ) {
$p3 .= $dir .'/' . $file . ',';
}
}
}
}
}
$p3 = preg_replace("/\,$/i", "", $p3);
lib_local_write_file($relpa . 'phpdoc.txt', $p3, "w+");
}
/**
* print out
*/
//echo $p;
echo 'done!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment