예제 #1
0
 function get_page($url)
 {
     $_SESSION['fw_search_count']++;
     global $links_list;
     global $index_list;
     global $local_check;
     global $db;
     global $error404;
     global $noindex;
     global $start_time;
     $link_matches = array();
     $page = '';
     $can_process = true;
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
     $page = curl_exec($curl);
     $result = curl_getinfo($curl);
     curl_close($curl);
     if ($page != '' && in_array($result['http_code'], array('200', '302', '301'))) {
         preg_match_all("/<a[^>]*?href\\s*=\\s*[\"\\'\\s]*([^\\s\"\\'>]+)/i", $page, $link_matches);
         preg_match("/<title>([^<]*)<\\/title>/i", $page, $title);
         preg_replace("/<title>[^<]*<\\/title>/i", "", $page);
         if (isset($title[1])) {
             $title = $title[1];
         } else {
             $title = '';
         }
         //----------------------------ИНДЕКСАЦИЯ-----------------------------------
         $page = str_replace("\r", " ", $page);
         $page = str_replace("\n", " ", $page);
         $page = preg_replace("/<!--[^>]+?-->/i", " ", $page);
         $page = preg_replace("/<script[^>]*>[^>]+?<\\/script>/im", " ", $page);
         $page = preg_replace("/<skip>[^\$]+?<\\/skip>/im", " ", $page);
         $page = preg_replace("/<[^>]*>/i", " ", $page);
         $page = preg_replace("/<\\/[^>]*>/i", " ", $page);
         $page = preg_replace("/\\s+/", " ", $page);
         $page = str_replace('&nbsp;', "", $page);
         $page = mysql_real_escape_string($page);
         $title = mysql_real_escape_string($title);
         $sqlurl = $result['url'];
         $index_list[] = $url;
         $db->query("REPLACE INTO fw_search(url,title,content) VALUES('{$sqlurl}','{$title}','{$page}')");
         //-------------------------------------------------------------------------
         $tmp_list = $link_matches[1];
         for ($i = 0; $i < sizeof($tmp_list); $i++) {
             $check = true;
             if (substr($tmp_list[$i], -1) == '/') {
                 $tmp_list[$i] = substr($tmp_list[$i], 0, -1);
             }
             if (substr($tmp_list[$i], 0, 1) == '/') {
                 $tmp_list[$i] = substr($tmp_list[$i], 1);
             }
             if (!stristr($tmp_list[$i], 'http://')) {
                 $tmp_list[$i] = BASE_URL . '/' . $tmp_list[$i];
             }
             $ext = substr($tmp_list[$i], -4);
             if (in_array($tmp_list[$i], $links_list) || in_array($tmp_list[$i], $index_list) || $tmp_list[$i] == BASE_URL || $tmp_list[$i] == BASE_URL . '/#' || !stristr($tmp_list[$i], $local_check) || preg_match("/^\\.[a-z]{3}\$/", $ext)) {
                 $check = false;
             }
             foreach ($noindex as $k => $v) {
                 if (stristr($tmp_list[$i], $v)) {
                     $check = false;
                 }
             }
             if ($check) {
                 $links_list[] = $tmp_list[$i];
             }
         }
     }
     if ($_SESSION['fw_search_count'] >= 50 && isset($links_list[0]) && strlen($links_list[0]) >= strlen(BASE_URL)) {
         $_SESSION['fw_links_list'] = serialize($links_list);
         $_SESSION['fw_index_list'] = serialize($index_list);
         $end_time = time();
         $result_time = $end_time - $start_time;
         $_SESSION['fw_search_time'] += $result_time;
         $location = BASE_URL . '/admin/index.php?mod=search&action=index&do=update_search_index&next=true';
         header("Location: {$location}");
         die;
     }
     if (isset($links_list[0]) && strlen($links_list[0]) >= strlen(BASE_URL)) {
         $goto = $links_list[0];
         $links_list = MyArray::unset_element($links_list, 0);
         get_page($goto);
     }
     return $index_list;
 }
예제 #2
0
 $current_poll_found = false;
 $active_polls = array();
 $finished_polls = array();
 $polls_list = $db->get_all("SELECT * FROM fw_polls WHERE status>'0' ORDER BY publish_date DESC");
 for ($i = 0; $i < count($polls_list); $i++) {
     if ($polls_list[$i]['status'] == '1') {
         $current_poll = $polls_list[$i];
         $answers_list = $db->get_all("SELECT *,(SELECT SUM(answers) FROM fw_polls_answers WHERE parent='" . $current_poll['id'] . "') AS total_answers FROM fw_polls_answers WHERE parent='" . $current_poll['id'] . "' ORDER BY sort_order");
         $total_answers = $answers_list[0]['total_answers'];
         for ($a = 0; $a < count($answers_list); $a++) {
             if ($answers_list[$a]['answers'] > 0) {
                 $answers_list[$a]['percent'] = round($answers_list[$a]['answers'] / $total_answers * 100, 1);
             }
         }
         $current_poll['answers'] = $answers_list;
         $polls_list = MyArray::unset_element($polls_list, $i);
         $current_poll_found = true;
         $check_poll = explode(",", @$_COOKIE['fw_polls']);
         if (in_array($current_poll['id'], $check_poll)) {
             $smarty->assign("poll_done", "true");
         }
         break;
     }
 }
 for ($i = 0; $i < count($polls_list); $i++) {
     if ($polls_list[$i]['status'] == '1') {
         $active_polls[] = $polls_list[$i];
     } else {
         $finished_polls[] = $polls_list[$i];
     }
 }