Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/burlakastudio.realcommenter/lib/ |
Upload File : |
<?php /** * ����� "��������� ����������� D7" ��� ������� * �������� ���� �����: www.realcommenter.com * �������� ���� �����������: burlaka.studio * ����� � ����������: ������� ������� (AlexeyGfi) -> alexeygfi@gmail.com */ namespace Burlakastudio\Realcommenter; //require_once 'URL_TABLE.php'; use Bitrix\Main\Context; use Bitrix\Main\ORM\Data\UpdateResult; class URL extends REALCOMMENTER_HL_GENERAL_PROVIDER { protected static function getLeadFieldName() { return [ 'UF_URL' ]; } public static function set_counter(&$id = 0, &$comments_in_url = 0, &$arParams = []) { if (!$id) { return false; } return self::update($id, ['UF_COMMENTS_INSIDE' => $comments_in_url], $arParams); } /** * �������������, ���� ������� ����� * * @param int $recordId * @param array $recordFields * @param array $arParams * * @return UpdateResult|bool * @throws \Exception */ public static function update($recordId = 0, array $recordFields = [], &$arParams = []) { EVENT::call('OnBeforeUrlUpdate', [ 'record_id' => &$recordId, 'record_Fields' => &$recordFields, 'arParams' => &$arParams ]); $result = parent::update($recordId, $recordFields); if (!$result->isSuccess()) { throw new \RuntimeException(implode(', ', $result->getErrorMessages())); } EVENT::call('OnAfterUrlUpdate', [ 'record_id' => &$recordId, 'record_Fields' => &$recordFields, 'arParams' => &$arParams ]); return $result; } /** * @param array $options [id, url, groupId, createIfNotFound, pageTitle] * * @return array|bool|false * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\ObjectPropertyException * @throws \Bitrix\Main\SystemException */ public static function getInfo($options = []) { $id = $options['id'] ?? null; $url = $options['url'] ?? null; $options['createIfNotFound'] = $options['createIfNotFound'] ?? false; if (!$id && !$url) { return false; } /** * ������... =( * �����, ��� ������� ����, �������� ��������� ���������� ������ ������������, * ��� ��������� �� ����. * * � ����� ���� ��� ����� �� id. * * ����������� ������������� ������ ����� ���. * � ��-�� ������ �� ���� * * !!! ��-����� �����, ��� ����� ����� ��� ������� ��� � ������ ��� !!! */ if (!$url) { $urlInternalInfo = static::getList([ 'filter' => [ 'ID' => $id ], 'limit' => 1 ])->fetch(); if (!empty($urlInternalInfo)) { $url = $urlInternalInfo['UF_URL']; } } if (!$url) { return false; } $result = []; $cacheObj = CACHE::getCacheObj(); $cacheKey = CACHE::get_url_key($url); $cacheTtl = CACHE::getTtl(); if ($cacheObj->initCache($cacheTtl, $cacheKey, TOOLS::getModuleName())) { $result = $cacheObj->getVars(); } /** * � ��������� ��������� �� ���� ��� �����, * �� � ��� �� ���� ��� ��� ����� * ...� ��� �� �������� � ���� ����� */ $groupInRequest = $options['groupId'] ?? false; if ($groupInRequest) { $groupInResult= $result['UF_GROUP_ID'] ?? false; if ($groupInResult !== $groupInRequest) { $result = []; } } if (empty($result)) { $urlFilter = []; if ($id) { $urlFilter['ID'] = $id; } elseif ($url) { $urlFilter['UF_URL'] = $url; } if (isset($options['groupId']) && $options['groupId']) { $urlFilter['UF_GROUP_ID'] = $options['groupId']; } $result = static::getList([ 'filter' => $urlFilter, 'limit' => 1 ])->fetch(); if (!empty($result)) { TOOLS::normalizeValues($result); $result = array_filter($result); } if (empty($result) && $options['createIfNotFound']) { try { $row = static::get_free_row(); if ($row && $row['ID']) { $urlFilter['UF_ACTIVE'] = 1; $urlFilter['UF_PAGE_TITLE'] = $options['pageTitle'] ?? null; static::update($row['ID'], $urlFilter); $result = array_merge($row, $urlFilter); } } catch (\Exception $exception) { return false; } } if (!empty($result)) { if ($cacheObj->startDataCache($cacheTtl, $cacheKey)) { // ���� � �� $cacheObj->endDataCache($result); } } } return $result; } public static function syncTitles($options = []) { $siteDomains = OPTIONS::getModuleDomains(); $domain = Context::getCurrent()->getServer()->get('HTTP_HOST'); if (!$domain || !in_array($domain, $siteDomains, false)) { return ''; } $protocol = Context::getCurrent()->getRequest()->isHttps() ? 'https' : 'http'; $urlInfo = self::getInfo($options); if (empty($urlInfo)) { return ''; } if ($urlInfo['UF_PAGE_TITLE']) { return $urlInfo['UF_PAGE_TITLE']; } $url = $protocol . '://' . $domain . $urlInfo['UF_URL']; $content = @file_get_contents($url); $titles = []; if ( preg_match( '~<title[^>]*?>([^<]+?)</title>~is' . BX_UTF_PCRE_MODIFIER, $content, $browserTitleMatch ) ) { $titles['browserTitle'] = $browserTitleMatch[1]; } if ( preg_match( '~<(h1)[^>]*?>([^\1]+?)</\1>~is' . BX_UTF_PCRE_MODIFIER, $content, $browserH1Match ) ) { // Prevent situation: <h1>Title contain <strong>bold</strong></h1> $titles['h1Title'] = preg_replace( '~<[^>]+>~is' . BX_UTF_PCRE_MODIFIER, '', $browserH1Match[2] ); } $titleOptions = [ 'id' => $urlInfo['ID'], 'titles' => $titles ]; self::pageTitleCheckAndSync($titleOptions); $urlInfo = self::getInfo($options); return $urlInfo['UF_PAGE_TITLE']; } public static function pageTitleCheckAndSync($options = []) { $titles = array_filter($options['titles'] ?? []); if (empty($titles)) { return; } $options['createIfNotFound'] = false; $urlInfo = self::getInfo($options); if (empty($urlInfo)) { return; } $titleLeadField = OPTIONS::get('page_title_lead_field'); if (!$titleLeadField) { $titleLeadField = 'browserTitle'; } // $tabTree = OPTIONS::getModuleOptions(); // $titleKeysVariants = array_keys($tabTree['itape_admin_tab']['LIST']['page_title_lead_field']['LIST']); $titleLead = $titles[$titleLeadField] ?? ''; $titleAlt = ''; foreach ($titles as $title => $value) { if ( !$value || $title === $titleLeadField // || !in_array($title, $titleKeysVariants, false) ) { continue; } $titleAlt = $value; break; } $mustBeTitle = $titleLead ?: $titleAlt; if (!$mustBeTitle) { return; } if ( !$urlInfo['UF_PAGE_TITLE'] || ($urlInfo['UF_PAGE_TITLE'] !== $mustBeTitle && OPTIONS::get('keep_actual')) ) { static::update($urlInfo['ID'], ['UF_PAGE_TITLE' => $mustBeTitle]); } } /** * @param int $id * @param string $url * @param int $talk_id * @param bool $create_if_not_found * * @return array|bool|mixed * @deprecated use getInfo */ public static function get_info($id = 0, &$url = '', &$talk_id = 0, $create_if_not_found = false) { if (!$id && !$url) { return false; } /** * ������... =( * �����, ��� ������� ����, �������� ��������� ���������� ������ ������������, * ��� ��������� �� ����. * * � ����� ���� ��� ����� �� id. * * ����������� ������������� ������ ����� ���. * � ��-�� ������ �� ���� * * !!! ��-����� �����, ��� ����� ����� ��� ������� ��� � ������ ��� !!! */ if (!$url) { $url_internal_info = parent::getList_EX(['ID' => $id], [], 1); if (!empty($url_internal_info)) { $url_internal_info = array_shift($url_internal_info); if (!empty($url_internal_info)) { $url = $url_internal_info['UF_URL']; } } } if (!$url) { return false; } $cache_obj = CACHE::getCacheObj(); $cache_key = CACHE::get_url_key($url); $cache_TTL = CACHE::getTtl(); if ($cache_obj->initCache($cache_TTL, $cache_key, TOOLS::getModuleName())) { // ���� �� ��� $_info = $cache_obj->getVars(); } if (empty($_info)) { $url_filter = []; if ($id) { $url_filter['ID'] = $id; } elseif ($url) { $url_filter['UF_URL'] = $url; } if ($talk_id) { $url_filter['UF_GROUP_ID'] = $talk_id; } $_info = self::getList_EX( $url_filter, [], 1 ); $_info = array_shift($_info); TOOLS::normalizeValues($_info); if (!empty($_info)) { $_info = array_filter($_info); } if (empty($_info) && $create_if_not_found) { try { $row = self::get_free_row([ 'UF_URL' => false ]); if ($row && $row['ID']) { $url_filter['UF_ACTIVE'] = 1; self::update($row['ID'], $url_filter); $_info = array_merge($row, $url_filter); } } catch (\Exception $exception) { return false; } } if ($cache_obj->startDataCache($cache_TTL, $cache_key)) { // ���� � �� $cache_obj->endDataCache($_info); } } return $_info; } }