function scrapPageSnippets(&$snippets_array, $key_value, $conn, $page_url) { $function = new Functions(); $snippet_extractor = new Google(); $google_image = new ImagesGoogle(); $snippets_array = getPageSnippets($conn, $page_url); if (count($snippets_array) == 0) { #echo "Saving snippets."; $rand_index_array = array(); $index = 0; while (count($rand_index_array) < 3) { $rand_value = rand(0, 8); if (!in_array($rand_value, $rand_index_array)) { $rand_index_array[$index] = $rand_value; $index++; } } $snippet_image_array = $google_image->Start($key_value, count($rand_index_array), $function); $snippet_array = array(); while (!$snippet_array) { $snippet_array = $snippet_extractor->Start($key_value, 'ru', count($rand_index_array), $function); } for ($i = 0; $i < count($rand_index_array); $i++) { $snippets_array[$rand_index_array[$i]]['title'] = preg_replace('/ {0,}\\.{2,}/', '.', $snippet_array[$i]['title']); $snippets_array[$rand_index_array[$i]]['description'] = preg_replace('/ {0,}\\.{2,}/', '.', $snippet_array[$i]['description']); if ($snippet_image_array && $snippet_image_array[$i]) { $snippets_array[$rand_index_array[$i]]['small'] = $snippet_image_array[$i]['small']; $snippets_array[$rand_index_array[$i]]['large'] = $snippet_image_array[$i]['large']; } } savePageSnippets($conn, $page_url, $snippets_array); } }
//fill [BREAD_CRUMBS] $bread_crumbs = "<a href =\"http://" . $site_main_domain . "\">Главная</a> > <a href =\"#\">" . $key_info['key_value'] . "</a>"; } else { #PAGE NOT FOUND REDIRECT header('HTTP/1.1 404 Not Found'); #header('Location: /'); $_GET['e'] = 404; include $_SERVER['DOCUMENT_ROOT'] . '/404.html'; exit; } } if (!$is_cached) { $page_meta_description = false; while (!$page_meta_description) { #echo "Page_title: ".$page_title."<br/>"; $snippet_array = $snippet_extractor->Start(preg_replace('/\\|/', ' ', $page_title), 'ru', 1, $function); #var_dump($snippet_array); if (isset($snippet_array[0])) { $page_meta_description = preg_replace('/ {0,}\\.{2,}/', '.', $snippet_array[0]["description"]); } } $page_title = $page_title . " | " . $site_main_domain; savePageInfo($con, $url_for_cache, $page_title, $page_title, $page_meta_description); } if ($current_page == "KEY_PAGE") { $template = fillSnippetsContent($template, $key_info['key_value'], $con, $domain); //delete all unnecessary templates anchors for ($i = 0; $i < 9; $i++) { $template = preg_replace("/\\[SNIPPET_TITLE_" . ($i + 1) . "\\]/", '', $template); $template = preg_replace("/\\[SNIPPET_CONTENT_" . ($i + 1) . "\\]/", '', $template); $template = preg_replace("/\\[SNIPPET_IMG_LARGE_" . ($i + 1) . "\\]/", '', $template);