function GetDynamicList($URL, &$by, &$order, $arFilter = array()) { $err_mess = "File: " . __FILE__ . "<br>Line: "; $DB = CDatabase::GetModuleConnection('statistic'); $arSqlSearch = array(); $strSqlSearch = ""; $counter = "SUM(D.COUNTER)"; $enter_counter = "SUM(D.ENTER_COUNTER)"; $exit_counter = "SUM(if(D.EXIT_COUNTER>0,D.EXIT_COUNTER,0))"; if (is_array($arFilter)) { if (strlen($arFilter["ADV"]) > 0) { $from_adv = " , b_stat_page_adv A "; $where_adv = "and A.PAGE_ID = D.ID"; if ($arFilter["ADV_DATA_TYPE"] == "B") { $counter = "SUM(A.COUNTER_BACK)"; $enter_counter = "SUM(A.ENTER_COUNTER_BACK)"; $exit_counter = "SUM(if(A.EXIT_COUNTER_BACK>0,A.EXIT_COUNTER_BACK,0))"; } elseif ($arFilter["ADV_DATA_TYPE"] == "P") { $counter = "SUM(A.COUNTER)"; $enter_counter = "SUM(A.ENTER_COUNTER)"; $exit_counter = "SUM(if(A.EXIT_COUNTER>0,A.EXIT_COUNTER,0))"; } else { $counter = "SUM(A.COUNTER + A.COUNTER_BACK)"; $enter_counter = "SUM(A.ENTER_COUNTER + A.ENTER_COUNTER_BACK)"; $exit_counter = "SUM(if(A.EXIT_COUNTER>0,A.EXIT_COUNTER,0) + if(A.EXIT_COUNTER_BACK>0,A.EXIT_COUNTER_BACK,0))"; } } else { $from_adv = ""; $where_adv = ""; } foreach ($arFilter as $key => $val) { if (is_array($val)) { if (count($val) <= 0) { continue; } } else { if (strlen($val) <= 0 || $val === "NOT_REF") { continue; } } $match_value_set = array_key_exists($key . "_EXACT_MATCH", $arFilter); $key = strtoupper($key); switch ($key) { case "DATE1": if (CheckDateTime($val)) { $arSqlSearch[] = "D.DATE_STAT>=" . $DB->CharToDateFunction($val, "SHORT"); } break; case "DATE2": if (CheckDateTime($val)) { $arSqlSearch[] = "D.DATE_STAT<" . $DB->CharToDateFunction($val, "SHORT") . " + INTERVAL 1 DAY"; } break; case "ADV": $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N"; $arSqlSearch[] = GetFilterQuery("A.ADV_ID", $val, $match); break; case "IS_DIR": $arSqlSearch[] = $val == "Y" ? "D.DIR = 'Y'" : "D.DIR = 'N'"; break; } } } if ($by == "s_date") { $strSqlOrder = "ORDER BY D.DATE_STAT"; } else { $by = "s_date"; $strSqlOrder = "ORDER BY D.DATE_STAT"; } if ($order != "asc") { $strSqlOrder .= " desc "; $order = "desc"; } $strSqlSearch = GetFilterSqlSearch($arSqlSearch); $strSql = "\n\t\t\tSELECT\n\t\t\t\t" . $DB->DateToCharFunction("D.DATE_STAT", "SHORT") . "\t\tDATE_STAT,\n\t\t\t\tDAYOFMONTH(D.DATE_STAT)\t\t\t\t\t\t\t\t\tDAY,\n\t\t\t\tMONTH(D.DATE_STAT)\t\t\t\t\t\t\t\t\t\tMONTH,\n\t\t\t\tYEAR(D.DATE_STAT)\t\t\t\t\t\t\t\t\t\tYEAR,\n\t\t\t\t{$counter}\t\t\t\t\t\t\t\t\t\t\t\tCOUNTER,\n\t\t\t\t{$enter_counter}\t\t\t\t\t\t\t\t\t\t\tENTER_COUNTER,\n\t\t\t\t{$exit_counter}\t\t\t\t\t\t\t\t\t\t\tEXIT_COUNTER\n\t\t\tFROM\n\t\t\t\tb_stat_page D\n\t\t\t\t{$from_adv}\n\t\t\tWHERE\n\t\t\t{$strSqlSearch}\n\t\t\tand D.URL_HASH = '" . crc32ex($URL) . "'\n\t\t\t{$where_adv}\n\t\t\tGROUP BY D.DATE_STAT\n\t\t\t{$strSqlOrder}\n\t\t\t"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); return $res; }
function GetStatPathID($URL, $PREV_PATH_ID = "") { return crc32ex($URL . strval($PREV_PATH_ID)); }
public static function EndBuffer() { $err_mess = "File: ".__FILE__."<br>Line: "; global $APPLICATION, $arHashLink; $DB = CDatabase::GetModuleConnection('statistic'); if (defined("ADMIN_SECTION") && ADMIN_SECTION===true) return; if (defined("BX_STATISTIC_BUFFER_USED") && BX_STATISTIC_BUFFER_USED===true) { $content = ob_get_contents(); ob_end_clean(); // this JS will open new windows with statistics data ob_start(); ?> <script language="JavaScript"> function ShowStatLinkPage() { try { ShowStatLinkPageEx(); } catch (e) { alert('<?echo GetMessage("STAT_LINK_STAT_PANEL_BUTTON_ALERT")?>'); } } </script> <? $content .= ob_get_contents(); ob_end_clean(); $arUniqLink = array(); $arHashLink = array(); // parse the content in order to get links if(preg_match_all("#<a[^>]+?href\\s*=\\s*([\"'])(.*?)\\1#is", $content, $arr)) { foreach($arr[2] as $link) { if (!__IsHiddenLink($link)) { // relative URL found $link = __GetFullRequestUri(__GetFullCurPage($link)); if (strpos($link, $_SERVER["HTTP_HOST"])!==false) { $arUniqLink[crc32ex($link)] = $link; } } } } // we found some links if (count($arUniqLink)>0) { // read database to get their data $SUM = 0; $MAX = false; $CURRENT_PAGE = __GetFullRequestUri(__GetFullCurPage()); $CURRENT_PAGE_CRC32 = crc32ex($CURRENT_PAGE); foreach($arUniqLink as $link_crc => $link) { if ($CURRENT_PAGE != $link) { $strSql = " SELECT LAST_PAGE_HASH, sum(COUNTER) CNT FROM b_stat_path WHERE PREV_PAGE_HASH = '".$CURRENT_PAGE_CRC32."' and LAST_PAGE_HASH = '".$link_crc."' GROUP BY LAST_PAGE_HASH "; $rs = $DB->Query($strSql, false, $err_mess.__LINE__); $ar = $rs->Fetch(); $CNT = intval($ar["CNT"]); if($CNT > 0) { $arHashLink[$link_crc] = array( "LINK" => $link, "CNT" => $CNT, ); $SUM += $CNT; if($MAX === false || ($CNT > $MAX)) $MAX = $CNT; } } } // если имеем массив количеств переходов по ссылкам то if((count($arHashLink) > 0) && ($SUM > 0)) { // отсортируем ссылки в порядке убывания количества переходов и // 1) присвоим каждой ссылке порядковый номер // 2) посчитаем процент переходов по каждой ссылке uasort($arHashLink, "__SortLinkStat"); $i=0; foreach($arHashLink as $link_crc => $arLink) { $i++; $arHashLink[$link_crc]["ID"] = $i; $arHashLink[$link_crc]["PERCENT"] = round((100*$arLink["CNT"])/$SUM, 1); } // парсим контент и добавляем к тэгам <a> желтую табличку с процентом переходов $pcre_backtrack_limit = intval(ini_get("pcre.backtrack_limit")); $content_len = function_exists('mb_strlen')? mb_strlen($content, 'latin1'): strlen($content); $content_len++; if($pcre_backtrack_limit < $content_len) @ini_set("pcre.backtrack_limit", $content_len); $content = preg_replace_callback("#(<a[^>]+?href\\s*=\\s*)([\"'])(.*?)(\\2.*?>)(.*?)(</.+?>)#is", "__ModifyATags", $content); // сформируем диаграмму переходов для данной страницы ob_start(); ?> <style> div.stat_pages h2 { background-color:#EEEEEE; font-family:Verdana,Arial,sans-serif; font-size:82%; padding:4px 10px; } div.stat_pages p { font-family:Verdana,Arial,sans-serif; font-size:82%; } div.stat_pages td { font-family:Verdana,Arial,sans-serif; font-size:70%; border: 1px solid #BDC6E0; padding:3px; background-color: white; } div.stat_pages table { border-collapse:collapse; } div.stat_pages td.head { background-color:#E6E9F4; } div.stat_pages td.tail { background-color:#EAEDF7; } </style> <div class="stat_pages"> <h2><?php echo GetMessage("STAT_LINK_STAT"); ?> </h2> <p><?php echo $CURRENT_PAGE; ?> </p> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td class="head" align="center">#</td> <td class="head"><?php echo GetMessage("STAT_LINK"); ?> </td> <td colspan="2" class="head"><?php echo GetMessage("STAT_CLICKS"); ?> </td> <td class="head"> </td> </tr> <? $max_relation = ($MAX*100)/90; foreach($arHashLink as $ar): $w = round(($ar["CNT"]*100)/$max_relation); ?> <tr> <td valign="top" align="right" width="0%" nowrap><?php echo $ar["ID"]; ?> .</td> <td valign="top" width="50%"><?php echo InsertSpaces($ar["LINK"], 60, "<wbr>"); ?> </td> <td valign="top" align="right" width="5%" nowrap><?php echo $ar["PERCENT"] . "%"; ?> </td> <td valign="top" align="right" width="5%" nowrap><?php echo $ar["CNT"]; ?> </td> <td valign="top" nowrap width="40%"><img src="/bitrix/images/statistic/votebar.gif" width="<?echo ($w==0) ? "0" : $w."%"?>" height="10" border=0 alt=""></td> </tr> <?endforeach?> <tr> <td width="0%" colspan="3" nowrap align="right" class="tail"><?echo GetMessage("STAT_TOTAL")?></td> <td width="0%" nowrap align="right" class="tail"><?php echo $SUM; ?> </td> <td width="100%" class="tail"> </td> </tr> </table> <p><form><input type="button" onClick="window.close()" value="<?echo GetMessage("STAT_CLOSE")?>"></form></p> </div> <? $stat_table = trim(ob_get_contents()); $js_table = "wnd.document.write('".CUtil::JSEscape($stat_table)."');"; ob_end_clean(); // сформируем JS открывающий отдельное окно со статистикой переходов ob_start(); ?> <script language="JavaScript"> function ShowStatLinkPageEx() { var top=0, left=0; var width=800, height=600; if(width > screen.width-10 || height > screen.height-28) scroll = "yes"; if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14); if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5); width = Math.min(width, screen.width-10); height = Math.min(height, screen.height-28); var wnd = window.open("","","scrollbars=yes,resizable=yes,width="+width+",height="+height+",left="+left+",top="+top); wnd.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"); wnd.document.write("<html><head>\n"); wnd.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=<?echo LANG_CHARSET?>\">\n"); wnd.document.write("<"+"script language=\'JavaScript\'>\n"); wnd.document.write("<!--\n"); wnd.document.write("function KeyPress()\n"); wnd.document.write("{\n"); wnd.document.write(" if(window.event.keyCode == 27)\n"); wnd.document.write(" window.close();\n"); wnd.document.write("}\n"); wnd.document.write("//-->\n"); wnd.document.write("</"+"script>\n"); wnd.document.write("<title><?php echo GetMessage("STAT_LINK_STAT_TITLE"); ?> </title></head>\n"); wnd.document.write("<body style=\"padding:10px;\" topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" onKeyPress=\"KeyPress()\">\n"); <?php echo $js_table; ?> wnd.document.write("</body>"); wnd.document.write("</html>"); wnd.document.close(); } </script> <? $js = ob_get_contents(); ob_end_clean(); } } echo $content.$js; } }
function SaveVisits($sql_site, $SESSION_NEW, $CURRENT_DIR, $CURRENT_PAGE, $ERROR_404) { $DB = CDatabase::GetModuleConnection('statistic'); $DB_now_date = $DB->GetNowDate(); $enter_counter = $SESSION_NEW == "Y" ? 1 : 0; if (strlen($CURRENT_DIR) > 0 && strlen($CURRENT_PAGE) > 0) { $LAST_DIR_ID = intval($_SESSION["SESS_LAST_DIR_ID"]); $LAST_PAGE_ID = intval($_SESSION["SESS_LAST_PAGE_ID"]); $CURRENT_DIR_ID = 0; $CURRENT_PAGE_ID = 0; $exit_dir_counter = 0; // счетчик точки выхода для раздела $exit_page_counter = 0; // счетчик точки выхода для страницы if ($_SESSION["SESS_LAST_DIR"] != $CURRENT_DIR || $_SESSION["SESS_LAST_PAGE"] != $CURRENT_PAGE) { $strSql = "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tID,\n\t\t\t\t\t\tDIR\n\t\t\t\t\tFROM\n\t\t\t\t\t\tb_stat_page\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tDATE_STAT = " . $DB_now_date . "\n\t\t\t\t\tand (\n\t\t\t\t\t\t(URL='" . $DB->ForSql($CURRENT_DIR, 2000) . "' and DIR='Y') or\n\t\t\t\t\t\t(URL='" . $DB->ForSql($CURRENT_PAGE, 2000) . "' and DIR='N')\n\t\t\t\t\t\t)\n\t\t\t\t\t"; $rsID = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arID = $rsID->Fetch()) { if ($arID["DIR"] == "Y") { $CURRENT_DIR_ID = $arID["ID"]; } elseif ($arID["DIR"] == "N") { $CURRENT_PAGE_ID = $arID["ID"]; } } if ($CURRENT_DIR_ID != $LAST_DIR_ID) { $exit_dir_counter = 1; } if ($CURRENT_PAGE_ID != $LAST_PAGE_ID) { $exit_page_counter = 1; } } else { $CURRENT_DIR_ID = $LAST_DIR_ID; $CURRENT_PAGE_ID = $LAST_PAGE_ID; } // определим ID рекламной кампании if (intval($_SESSION["SESS_ADV_ID"]) > 0) { $ADV_ID = intval($_SESSION["SESS_ADV_ID"]); $bADV_BACK = false; } elseif (intval($_SESSION["SESS_LAST_ADV_ID"]) > 0) { $ADV_ID = intval($_SESSION["SESS_LAST_ADV_ID"]); $bADV_BACK = true; } else { $ADV_ID = 0; } // обновляем раздел if ($LAST_DIR_ID > 0 && $exit_dir_counter > 0) { $arFields = array("EXIT_COUNTER" => "EXIT_COUNTER - 1"); $DB->Update("b_stat_page", $arFields, "WHERE ID = '" . $LAST_DIR_ID . "'", "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); if ($ADV_ID > 0) { if ($bADV_BACK) { $arFields = array("EXIT_COUNTER_BACK" => "EXIT_COUNTER_BACK - 1"); } $DB->Update("b_stat_page_adv", $arFields, "WHERE PAGE_ID = '" . $LAST_DIR_ID . "' and ADV_ID=" . $ADV_ID, "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); } } $adv_rows_dir = 0; if ($CURRENT_DIR_ID > 0) { $arFields = array("COUNTER" => "COUNTER + 1", "EXIT_COUNTER" => "EXIT_COUNTER + " . $exit_dir_counter, "ENTER_COUNTER" => "ENTER_COUNTER + " . $enter_counter); $DB->Update("b_stat_page", $arFields, "WHERE ID = '" . $CURRENT_DIR_ID . "'", "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); if ($ADV_ID > 0) { if ($bADV_BACK) { $arFields = array("COUNTER_BACK" => "COUNTER_BACK + 1", "EXIT_COUNTER_BACK" => "EXIT_COUNTER_BACK + " . $exit_dir_counter, "ENTER_COUNTER_BACK" => "ENTER_COUNTER_BACK + " . $enter_counter); } $adv_rows_dir = $DB->Update("b_stat_page_adv", $arFields, "WHERE PAGE_ID = '" . $CURRENT_DIR_ID . "' and ADV_ID = " . $ADV_ID, "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); } } else { $arFields = array("DATE_STAT" => $DB_now_date, "COUNTER" => 1, "EXIT_COUNTER" => 1, "ENTER_COUNTER" => $enter_counter, "DIR" => "'Y'", "URL" => "'" . $DB->ForSql($CURRENT_DIR, 2000) . "'", "URL_HASH" => crc32ex($CURRENT_DIR), "SITE_ID" => $sql_site); $CURRENT_DIR_ID = $DB->Insert("b_stat_page", $arFields, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $_SESSION["SESS_LAST_DIR_ID"] = $CURRENT_DIR_ID; if (intval($adv_rows_dir) <= 0) { if ($ADV_ID > 0) { $arFields = array("DATE_STAT" => $DB_now_date, "PAGE_ID" => $CURRENT_DIR_ID, "ADV_ID" => $ADV_ID, "COUNTER" => 1, "EXIT_COUNTER" => 1, "ENTER_COUNTER" => $enter_counter, "COUNTER_BACK" => 0, "EXIT_COUNTER_BACK" => 0, "ENTER_COUNTER_BACK" => 0); if ($bADV_BACK) { $arFields["COUNTER"] = 0; $arFields["EXIT_COUNTER"] = 0; $arFields["ENTER_COUNTER"] = 0; $arFields["COUNTER_BACK"] = 1; $arFields["EXIT_COUNTER_BACK"] = 1; $arFields["ENTER_COUNTER_BACK"] = $enter_counter; } $DB->Insert("b_stat_page_adv", $arFields, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } // обновим страницу if ($LAST_PAGE_ID > 0 && $exit_page_counter > 0) { $arFields = array("EXIT_COUNTER" => "EXIT_COUNTER - 1"); $DB->Update("b_stat_page", $arFields, "WHERE ID = '" . $LAST_PAGE_ID . "'", "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); if ($ADV_ID > 0) { if ($bADV_BACK) { $arFields = array("EXIT_COUNTER_BACK" => "EXIT_COUNTER_BACK - 1"); } $DB->Update("b_stat_page_adv", $arFields, "WHERE PAGE_ID = '" . $LAST_PAGE_ID . "' and ADV_ID=" . $ADV_ID, "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); } } $adv_rows_page = 0; if ($CURRENT_PAGE_ID > 0) { $arFields = array("COUNTER" => "COUNTER + 1", "EXIT_COUNTER" => "EXIT_COUNTER + " . $exit_page_counter, "ENTER_COUNTER" => "ENTER_COUNTER + " . $enter_counter, "URL_404" => "'" . $ERROR_404 . "'"); $DB->Update("b_stat_page", $arFields, "WHERE ID = '" . $CURRENT_PAGE_ID . "'", "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); if ($ERROR_404 == "N") { CStatistics::Set404("b_stat_page", "ID = " . intval($CURRENT_PAGE_ID), array("URL_404" => "Y")); } if ($ADV_ID > 0) { if ($bADV_BACK) { $arFields = array("COUNTER_BACK" => "COUNTER_BACK + 1", "EXIT_COUNTER_BACK" => "EXIT_COUNTER_BACK + " . $exit_dir_counter, "ENTER_COUNTER_BACK" => "ENTER_COUNTER_BACK + " . $enter_counter); } unset($arFields["URL_404"]); $adv_rows_page = $DB->Update("b_stat_page_adv", $arFields, "WHERE PAGE_ID = '" . $CURRENT_PAGE_ID . "' and ADV_ID = " . $ADV_ID, "File: " . __FILE__ . "<br>Line: " . __LINE__, false, false, false); } } else { $arFields = array("DATE_STAT" => $DB_now_date, "COUNTER" => 1, "EXIT_COUNTER" => 1, "ENTER_COUNTER" => $enter_counter, "DIR" => "'N'", "URL" => "'" . $DB->ForSql($CURRENT_PAGE, 2000) . "'", "URL_404" => "'" . $ERROR_404 . "'", "URL_HASH" => crc32ex($CURRENT_PAGE), "SITE_ID" => $sql_site); $CURRENT_PAGE_ID = $DB->Insert("b_stat_page", $arFields, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($ERROR_404 == "N") { CStatistics::Set404("b_stat_page", "ID = " . intval($CURRENT_PAGE_ID), array("URL_404" => "Y")); } } $_SESSION["SESS_LAST_PAGE_ID"] = $CURRENT_PAGE_ID; if (intval($adv_rows_page) <= 0 && $ADV_ID > 0) { $arFields = array("DATE_STAT" => $DB_now_date, "PAGE_ID" => $CURRENT_PAGE_ID, "ADV_ID" => $ADV_ID, "COUNTER" => $bADV_BACK ? 0 : 1, "EXIT_COUNTER" => $bADV_BACK ? 0 : 1, "ENTER_COUNTER" => $bADV_BACK ? 0 : $enter_counter, "COUNTER_BACK" => $bADV_BACK ? 1 : 0, "EXIT_COUNTER_BACK" => $bADV_BACK ? 1 : 0, "ENTER_COUNTER_BACK" => $bADV_BACK ? $enter_counter : 0); $DB->Insert("b_stat_page_adv", $arFields, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } }