Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pathindex.php
1<?php
2
4
8
13 extends Index\Internals\EO_PathIndex
14{
15
23 public static function loadByPath($path): ?self
24 {
25 $path = '/'. \trim($path, '/');
26 $path = Translate\IO\Path::replaceLangId($path, '#LANG_ID#');
27
29 $indexPath = Translate\Index\Internals\PathIndexTable::getList(['filter' => ['=PATH' => $path]])->fetchObject();
30
31 // if it is lang folder when find the lang/#LANG_ID# folder
32 if (
33 $indexPath instanceof Translate\Index\PathIndex
34 && $indexPath->getIsLang()
35 && $indexPath->getName() === 'lang'
36 )
37 {
38 $topPathRes = Translate\Index\Internals\PathIndexTable::getList([
39 'filter' => [
40 '=NAME' => '#LANG_ID#',
41 '=DEPTH_LEVEL' => $indexPath->getDepthLevel() + 1,
42 '=DESCENDANTS.PARENT_ID' => $indexPath->getId(),//ancestor
43 ],
44 ]);
45 $indexPath = $topPathRes->fetchObject();
46 }
47
48 return $indexPath;
49 }
50
51
57 public function detectModuleId(): ?string
58 {
59 $arr = \explode('/', $this->getPath());
60 $pos = \array_search('modules', $arr);
61 if ($pos !== false)
62 {
63 if ($arr[$pos - 1] === 'bitrix' && !empty($arr[$pos + 1]))
64 {
65 return $arr[$pos + 1];
66 }
67 }
68
69 return null;
70 }
71
77 public function detectAssignment(): ?string
78 {
79 $path = $this->getPath();
80
81 // /bitrix/mobileapp/[moduleName]
82 // /bitrix/templates/[templateName]
83 // /bitrix/components/bitrix/[componentName]
84 // /bitrix/activities/bitrix/[activityName]
85 // /bitrix/wizards/bitrix/[wizardsName]
86 // /bitrix/gadgets/bitrix/[gadgetName]
87 // /bitrix/js/[moduleName]/[smth]
88 foreach (Translate\ASSIGNMENT_TYPES as $testEntry)
89 {
90 $testPath = '/bitrix/'. $testEntry;
91 if (\mb_strpos($path, $testPath.'/') === 0 || $path == $testPath)
92 {
93 return $testEntry;
94 }
95 }
96
97 $assignment = null;
98
99 $moduleName = $this->detectModuleId();
100
101 if ($moduleName !== null)
102 {
103 $assignment = 'modules';
104
105 foreach (Translate\ASSIGNMENT_TYPES as $testEntry)
106 {
107 // /bitrix/modules/[moduleName]/install/mobileapp/[moduleName]
108 // /bitrix/modules/[moduleName]/install/templates/[templateName]
109 // /bitrix/modules/[moduleName]/install/components/bitrix/[componentName]
110 // /bitrix/modules/[moduleName]/install/activities/bitrix/[activityName]
111 // /bitrix/modules/[moduleName]/install/wizards/bitrix/[wizardsName]
112 // /bitrix/modules/[moduleName]/install/gadgets/bitrix/[gadgetName]
113 // /bitrix/modules/[moduleName]/install/js/[moduleName]/[smth]
114 $testPath = '/bitrix/modules/'.$moduleName.'/install/'. $testEntry;
115 if (\mb_strpos($path, $testPath.'/') === 0 || $path == $testPath)
116 {
117 return $testEntry;
118 }
119 if ($testEntry == 'templates')
120 {
121 // /bitrix/modules/[moduleName]/install/public/templates/[templateName]
122 $testPath = '/bitrix/modules/'.$moduleName.'/install/public/'. $testEntry;
123 if (\mb_strpos($path, $testPath.'/') === 0 || $path == $testPath)
124 {
125 return $testEntry;
126 }
127 }
128 // /bitrix/modules/[moduleName]/install/bitrix/templates/[templateName]
129 $testPath = '/bitrix/modules/'.$moduleName.'/install/bitrix/'. $testEntry;
130 if (\mb_strpos($path, $testPath.'/') === 0 || $path == $testPath)
131 {
132 return $testEntry;
133 }
134 // /bitrix/modules/[moduleName]/install/public/templates/[templateName]
135 /*$testPath = '/bitrix/modules/'.$moduleName.'/install/public/'. $testEntry;
136 if (\mb_strpos($path, $testPath. '/') === 0 || $path == $testPath)
137 {
138 return $testEntry;
139 }*/
140 // /bitrix/modules/[moduleName]/lang/#LANG_ID#/[smth]
141 $testPath = '/bitrix/modules/'.$moduleName.'/lang/#LANG_ID#/'. $testEntry;
142 if (\mb_strpos($path, $testPath.'/') === 0 || $path == $testPath)
143 {
144 return $testEntry;
145 }
146 // /bitrix/modules/[moduleName]/lang/#LANG_ID#/install/[smth]
147 $testPath = '/bitrix/modules/'.$moduleName.'/lang/#LANG_ID#/install/'. $testEntry;
148 if (\mb_strpos($path, $testPath.'/') === 0 || $path == $testPath)
149 {
150 return $testEntry;
151 }
152
153 // /bitrix/modules/[moduleName]/handlers/delivery/[smth]
154 // /bitrix/modules/[moduleName]/handlers/paysystem/[smth]
155 $testPath = '/bitrix/modules/'.$moduleName.'/handlers/'. $testEntry;
156 if (\mb_strpos($path, $testPath.'/') === 0 || $path == $testPath)
157 {
158 return $testEntry;
159 }
160
161
162 // /bitrix/modules/[moduleName]/payment/[paymentHandler]
163 }
164 }
165
166 return $assignment;
167 }
168}