1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
adminhelper.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\ABTest;
4
5
use Bitrix\Main\Loader;
6
use Bitrix\Main\IO;
7
use Bitrix\Main\Web;
8
use Bitrix\Main\Type;
9
use Bitrix\Conversion;
10
11
const
MIN_EFFECT
= 0.1;
12
13
class
AdminHelper
14
{
15
23
public
static
function
getRealPath
(
$site
,
$url
)
24
{
25
$docRoot
= rtrim(\
Bitrix
\
Main
\SiteTable::getDocumentRoot(
$site
),
'/'
);
26
27
$url
= str_replace(
'\\'
,
'/'
,
$url
);
28
$url
=
\CHTTP::urnEncode
(
$url
);
29
$uri
=
new
Web\Uri
(
$url
);
30
31
$path
=
\CHTTP::urnDecode
(
$uri
->getPath());
32
if
(mb_substr(
$path
, -1, 1) ==
'/'
)
33
$path
.=
'index.php'
;
34
35
$file =
new
IO\File
(
$docRoot
.$path);
36
if
($file->isExists())
37
return
mb_substr($file->getPath(), mb_strlen(
$docRoot
));
38
39
if
($rewriteRules = AdminHelper::getRewriteRules(
$site
))
40
{
41
$pathQuery =
\CHTTP::urnDecode
(
$uri
->getPathQuery());
42
43
foreach
($rewriteRules as &$item)
44
{
45
if
(preg_match($item[
'CONDITION'
], $pathQuery))
46
{
47
$url
= empty($item[
'PATH'
]) && !empty($item[
'RULE'
])
48
? preg_replace($item[
'CONDITION'
], $item[
'RULE'
], $pathQuery)
49
: $item[
'PATH'
];
50
51
$url
=
\CHTTP::urnEncode
(
$url
);
52
$uri
=
new
Web\Uri
(
$url
);
53
54
$path
=
\CHTTP::urnDecode
(
$uri
->getPath());
55
56
$file =
new
IO\File
(
$docRoot
.$path);
57
if
($file->isExists())
58
{
59
$pathTmp = str_replace(
'.'
,
''
, mb_strtolower(ltrim(
$path
,
'/\\'
)));
60
$pathTmp7 = mb_substr($pathTmp, 0, 7);
61
62
if
($pathTmp7 ==
'upload/'
|| $pathTmp7 ==
'bitrix/'
)
63
continue
;
64
65
if
($file->getExtension() !=
'php'
)
66
continue
;
67
68
return
mb_substr($file->getPath(), mb_strlen(
$docRoot
));
69
}
70
}
71
}
72
}
73
74
return
null
;
75
}
76
83
private
static
function
getRewriteRules(
$site
)
84
{
85
$docRoot
= rtrim(\
Bitrix
\
Main
\SiteTable::getDocumentRoot(
$site
),
'/'
);
86
87
$rewriteRules =
array
();
88
$arUrlRewrite
=& $rewriteRules;
89
90
$rewriteFile =
new
IO\File
(
$docRoot
.
'/urlrewrite.php'
);
91
if
($rewriteFile->isExists())
92
include $rewriteFile->getPath();
93
94
return
$rewriteRules;
95
}
96
103
public
static
function
getSiteCapacity
($id)
104
{
105
$cache = new \CPHPCache();
106
107
if
($cache->initCache(time()-strtotime(
'today'
),
'abtest_site_capacity'
,
'/abtest'
))
108
{
109
$capacity = $cache->getVars();
110
}
111
else
if
(Loader::includeModule(
'conversion'
))
112
{
113
if
($conversionRates =
Conversion
\RateManager::getTypes(
array
(
'ACTIVE'
=>
true
)))
114
{
115
$baseRate = array_slice($conversionRates, 0, 1,
true
);
116
117
$reportContext =
new
Conversion\ReportContext
;
118
119
$from = new \DateTime(
'first day of last month'
);
120
$to = new \DateTime(
'today'
);
121
122
$capacity =
array
();
123
124
$res
=
\Bitrix\Main\SiteTable::getList
();
125
while
(
$site
=
$res
->fetch())
126
{
127
$lid =
$site
[
'LID'
];
128
129
$reportContext->setAttribute(
'conversion_site'
, $lid);
130
131
$rateData = reset($reportContext->getRatesDeprecated(
132
$baseRate,
array
(
133
'>=DAY'
=>
Type
\Date::createFromPhp($from),
134
'<=DAY'
=>
Type
\Date::createFromPhp($to)
135
),
null
136
));
137
138
$reportContext->unsetAttribute(
'conversion_site'
, $lid);
139
140
$rate = $rateData[
'RATE'
];
141
$hits = $rateData[
'DENOMINATOR'
];
142
143
$daily = floor($hits / (date_diff($from, $to)->format(
'%a'
)+1));
144
145
$min = $rate > 0 && $rate < 1 ? ceil(16 * (1 / $rate - 1) / pow(
MIN_EFFECT
, 2)) : 0;
146
$est = $daily ? $min / ($daily / 2) : 0;
147
148
$capacity[$lid] =
array
(
149
'daily'
=> $daily,
150
'min'
=> $min,
151
'est'
=> $est
152
);
153
}
154
155
$cache->startDataCache(strtotime(
'tomorrow'
)-time());
156
$cache->endDataCache($capacity);
157
}
158
}
159
160
$result
=
array
();
161
foreach
((
array
) $id as $lid)
162
$result
[$lid] = isset($capacity[$lid]) ? $capacity[$lid] :
array
(
'min'
=> 0,
'est'
=> 0);
163
164
return
is_array($id) ?
$result
: reset(
$result
);
165
}
166
173
public
static
function
getTestCapacity
($id)
174
{
175
$cache = new \CPHPCache();
176
177
if
($cache->initCache(time()-strtotime(
'today'
),
'abtest_capacity_'
.intval($id),
'/abtest'
))
178
{
179
$capacity = $cache->getVars();
180
}
181
else
if
(Loader::includeModule(
'conversion'
))
182
{
183
if
($conversionRates =
Conversion
\RateManager::getTypes(
array
(
'ACTIVE'
=>
true
)))
184
{
185
if
($abtest = ABTestTable::getById($id)->fetch())
186
{
187
$lid = $abtest[
'SITE_ID'
];
188
189
$baseRate = array_slice($conversionRates, 0, 1,
true
);
190
191
$reportContext =
new
Conversion\ReportContext
;
192
193
$reportContext->
setAttribute
(
'conversion_site'
, $lid);
194
$reportContext->setAttribute(
'abtest'
, $id);
195
196
$reportContext->setAttribute(
'abtest_section'
,
'A'
);
197
$groupAData = reset($reportContext->getRatesDeprecated($baseRate,
array
(),
null
));
198
199
$reportContext->unsetAttribute(
'abtest_section'
,
'A'
);
200
$reportContext->setAttribute(
'abtest_section'
,
'B'
);
201
$groupBData = reset($reportContext->getRatesDeprecated($baseRate,
array
(),
null
));
202
203
$capacity =
array
(
204
'A'
=> $groupAData[
'DENOMINATOR'
],
205
'B'
=> $groupBData[
'DENOMINATOR'
]
206
);
207
208
$cache->startDataCache(strtotime(
'tomorrow'
)-time());
209
$cache->endDataCache($capacity);
210
}
211
}
212
}
213
214
return
!empty($capacity) ? $capacity :
array
(
'A'
=> 0,
'B'
=> 0);
215
}
216
217
}
$path
$path
Определения
access_edit.php:21
Bitrix\ABTest\AdminHelper
Определения
adminhelper.php:14
Bitrix\ABTest\AdminHelper\getTestCapacity
static getTestCapacity($id)
Определения
adminhelper.php:173
Bitrix\ABTest\AdminHelper\getSiteCapacity
static getSiteCapacity($id)
Определения
adminhelper.php:103
Bitrix\ABTest\AdminHelper\getRealPath
static getRealPath($site, $url)
Определения
adminhelper.php:23
Bitrix\Conversion\Internals\BaseContext\setAttribute
setAttribute($name, $value=null)
Определения
basecontext.php:111
Bitrix\Conversion\ReportContext
Определения
reportcontext.php:12
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
Bitrix\Main\Web\Uri
Определения
uri.php:17
CHTTP\urnDecode
static urnDecode($str, $charset=false)
Определения
http.php:604
CHTTP\urnEncode
static urnEncode($str, $charset=false)
Определения
http.php:596
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$result
$result
Определения
get_property_values.php:14
$docRoot
$docRoot
Определения
options.php:20
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$arUrlRewrite
$arUrlRewrite
Определения
urlrewrite.php:55
Bitrix\ABTest\MIN_EFFECT
const MIN_EFFECT
Определения
adminhelper.php:11
Bitrix\Conversion
Определения
attributegroupmanager.php:3
Bitrix\Main\File
Определения
Image.php:9
Bitrix\Main\Type
Определения
collection.php:2
Bitrix\Main
Bitrix
$url
$url
Определения
iframe.php:7
$site
$site
Определения
yandex_run.php:614
bitrix
modules
abtest
lib
adminhelper.php
Создано системой
1.14.0