public function uninstallDB() { if (Loader::includeModule($this->MODULE_ID)) { $connection = Application::getInstance()->getConnection(); $connection->dropTable(ExampleTable::getTableName()); } }
function mobileDiskPrepareForJson($string) { if (!Application::getInstance()->isUtfMode()) { return Encoding::convertEncodingArray($string, SITE_CHARSET, 'UTF-8'); } return $string; }
function __CrmActivityViewPrepareNameForJson($string) { if (!\Bitrix\Main\Application::getInstance()->isUtfMode()) { return \Bitrix\Main\Text\Encoding::convertEncodingArray($string, SITE_CHARSET, 'UTF-8'); } return $string; }
function acrit_exportpro() { require __DIR__ . '/version.php'; $path = str_replace("\\", "/", __FILE__); $path = substr($path, 0, strlen($path) - strlen("/index.php")); include $path . "/version.php"; if (is_array($arModuleVersion) && array_key_exists("VERSION", $arModuleVersion)) { $this->MODULE_VERSION = $arModuleVersion["VERSION"]; $this->MODULE_VERSION_DATE = $arModuleVersion["VERSION_DATE"]; } $this->MODULE_NAME = GetMessage('ACRIT_EXPORTPRO_MODULE_NAME'); $this->MODULE_DESCRIPTION = GetMessage('ACRIT_EXPORTPRO_MODULE_DESC'); $this->PARTNER_NAME = GetMessage("ACRIT_EXPORTPRO_PARTNER_NAME"); $this->PARTNER_URI = GetMessage("ACRIT_EXPORTPRO_PARTNER_URI"); $app = \Bitrix\Main\Application::getInstance(); $dbSite = \Bitrix\Main\SiteTable::getList(); while ($arSite = $dbSite->Fetch()) { if (!$arSite['DOC_ROOT']) { $this->siteArray[$arSite['LID']] = $app->getDocumentRoot() . $arSite['DIR']; } else { $this->siteArray[$arSite['LID']] = $arSite['DOC_ROOT']; } $this->siteArray[$arSite['LID']] = \Bitrix\Main\IO\Path::normalize($this->siteArray[$arSite['LID']]); } }
public function addComment($authorId, array $data) { $this->loadBlogPostData(); $commentFields = array("POST_ID" => $this->entityId, "BLOG_ID" => $this->blogPostData['BLOG_ID'], "POST_TEXT" => $data['text'], "DATE_CREATE" => new DateTime(), "PARENT_ID" => false, "AUTHOR_ID" => $authorId, "HAS_PROPS" => 'Y'); if (!empty($data['fileId'])) { $commentFields['UF_BLOG_COMMENT_FILE'] = array($data['fileId']); } elseif (!empty($data['versionId'])) { $commentFields['UF_BLOG_COMMENT_FH'] = $data['versionId']; } $comId = \CBlogComment::add($commentFields); if (!$comId) { return; } if (method_exists("CBlogComment", "addLiveComment")) { /** @noinspection PhpDynamicAsStaticMethodCallInspection */ \CBlogComment::addLiveComment($comId, array("MODE" => "PULL_MESSAGE")); } BXClearCache(true, "/blog/comment/" . $this->entityId . "/"); if (!Loader::includeModule('socialnetwork')) { return; } $query = \CSocNetLog::getList(array("ID" => "DESC"), array("EVENT_ID" => array("blog_post", "blog_post_important"), "SOURCE_ID" => $this->entityId), false, false, array("ID", "TMP_ID")); $row = $query->fetch(); if (!$row) { return; } $fieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_USER, "ENTITY_ID" => $this->blogPostData["AUTHOR_ID"], "EVENT_ID" => "blog_comment", "=LOG_DATE" => Application::getInstance()->getConnection()->getSqlHelper()->getCurrentDateTimeFunction(), "MESSAGE" => "file", "TEXT_MESSAGE" => "file", "URL" => "", "MODULE_ID" => false, "SOURCE_ID" => $comId, "LOG_ID" => $row["ID"], "RATING_TYPE_ID" => "BLOG_COMMENT", "RATING_ENTITY_ID" => $comId, "USER_ID" => $authorId); \CSocNetLogComments::add($fieldsForSocnet, false, false, false); }
/** * Passes an A/B-test mode string from request to session * * @return void */ public static function onPageStart() { $applicationContext = Application::getInstance()->getContext(); if ($mode = $applicationContext->getRequest()->get('abtest_mode')) { $_SESSION['ABTEST_MODE'] = $mode; } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $dir = $input->getOption('dir'); $tag = $input->getOption('tag'); $cache = Cache::createInstance(); if (empty($dir) && empty($tag)) { Application::getInstance()->getManagedCache()->cleanAll(); $cache->cleanDir(); $cache->cleanDir(false, 'stack_cache'); StaticHtmlCache::getInstance()->deleteAll(); if (Cache::clearCache(true)) { $output->writeln('<info>All Bitrix cache was deleted</info>'); } else { $output->writeln('<error>Error deleting Bitrix cache</error>'); } } if ($dir) { $cache->cleanDir($dir); $output->writeln('<info>Bitrix cache by "/' . BX_ROOT . '/cache/' . $dir . '" dir was deleted</info>'); } if ($tag) { Application::getInstance()->getTaggedCache()->clearByTag($tag); $output->writeln('<info>Bitrix cache by tag "' . $tag . '" was deleted</info>'); } }
/** * @param array $data * @return Main\Entity\AddResult */ public static function send(array $data) { $manageCache = Application::getInstance()->getManagedCache(); if (CACHED_b_event !== false && $manageCache->read(CACHED_b_event, "events")) { $manageCache->clean('events'); } $arFiles = array(); if (isset($data['FILE'])) { if (is_array($data['FILE'])) { $arFiles = $data['FILE']; } unset($data['FILE']); } $result = MailInternal\EventTable::add($data); if ($result->isSuccess()) { $id = $result->getId(); foreach ($arFiles as $file) { $arFile = \CFile::MakeFileArray($file); $arFile["MODULE_ID"] = "main"; $fid = \CFile::SaveFile($arFile, "main"); $dataAttachment = array('EVENT_ID' => $id, 'FILE_ID' => $fid); MailInternal\EventAttachmentTable::add($dataAttachment); } } return $result; }
function InstallDB($install_wizard = true) { global $DB, $DBType, $APPLICATION; $errors = null; if (!$DB->Query("SELECT 'x' FROM b_disk_storage", true)) { $errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/disk/install/db/" . $DBType . "/install.sql"); } $this->InstallTasks(); if (!empty($errors)) { $APPLICATION->ThrowException(implode("", $errors)); return false; } $isWebdavInstalled = isModuleInstalled('webdav'); $this->RegisterModuleDependences(!$isWebdavInstalled); RegisterModule("disk"); $this->InstallUserFields(); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ CAgent::addAgent('\\Bitrix\\Disk\\ExternalLink::removeExpiredWithTypeAuto();', 'disk', 'N'); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ CAgent::addAgent('\\Bitrix\\Disk\\Bitrix24Disk\\UploadFileManager::removeIrrelevant();', 'disk', 'N'); if (!$isWebdavInstalled) { require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/disk/lib/configuration.php"; \Bitrix\Main\Config\Option::set('disk', 'successfully_converted', 'Y'); \Bitrix\Main\Config\Option::set('disk', 'disk_revision_api', \Bitrix\Disk\Configuration::REVISION_API); } else { \CAdminNotify::add(array("MESSAGE" => Loc::getMessage("DISK_NOTIFY_MIGRATE_WEBDAV", array("#LINK#" => "/bitrix/admin/disk_from_webdav_convertor.php?lang=" . \Bitrix\Main\Application::getInstance()->getContext()->getLanguage())), "TAG" => "disk_migrate_from_webdav", "MODULE_ID" => "disk", "ENABLE_CLOSE" => "N")); } return true; }
private function __construct() { $this->sqlBehavior = self::SQL_SKIP; $this->memoryBehavior = self::MEMORY_SKIP; $this->levelReporting = E_ALL | E_STRICT; $this->connection = Application::getInstance()->getConnection(); }
/** * Add products from order or updates existing. * * @param $orderId * * @return void */ public static function addProductsFromOrder($orderId = 0) { $orderId = (int) $orderId; if (Sale\OrderProcessingTable::hasAddedProducts($orderId)) { return; } $connection = Main\Application::getConnection(); $type = $connection->getType(); // Update existing if ($type == "mysql") { $sqlUpdate = "UPDATE b_sale_product2product p2p, b_sale_basket b, b_sale_basket b1\n\t\t\t\tSET p2p.CNT = p2p.CNT + 1\n\t\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\t\tp2p.PRODUCT_ID = b.PRODUCT_ID AND\n\t\t\t\t\tp2p.PARENT_PRODUCT_ID = b1.PRODUCT_ID"; } elseif ($type == "mssql") { $sqlUpdate = "UPDATE b_sale_product2product\n\t\t\t\tSET CNT = CNT + 1\n\t\t\t\tFROM b_sale_product2product p2p, b_sale_basket b, b_sale_basket b1\n\t\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\t\tp2p.PRODUCT_ID = b.PRODUCT_ID AND\n\t\t\t\t\tp2p.PARENT_PRODUCT_ID = b1.PRODUCT_ID"; } else { $sqlUpdate = "UPDATE b_sale_product2product\n\t\t\t\tSET CNT = CNT + 1\n\t\t\t\tWHERE ID IN (\n\t\t\t\t\tSELECT p2p.ID FROM b_sale_product2product p2p, b_sale_basket b, b_sale_basket b1\n\t\t\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\t\t\tp2p.PRODUCT_ID = b.PRODUCT_ID AND\n\t\t\t\t\t\tp2p.PARENT_PRODUCT_ID = b1.PRODUCT_ID\n\t\t\t\t\t)"; } $connection->query($sqlUpdate); // Insert new $sqlInsert = "INSERT INTO b_sale_product2product (PRODUCT_ID, PARENT_PRODUCT_ID, CNT)\n\t\t\tSELECT b.PRODUCT_ID, b1.PRODUCT_ID, 1\n\t\t\tFROM b_sale_basket b, b_sale_basket b1\n\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\tNOT EXISTS (SELECT 1 FROM b_sale_product2product d WHERE d.PRODUCT_ID = b.PRODUCT_ID AND d.PARENT_PRODUCT_ID = b1.PRODUCT_ID)"; $connection->query($sqlInsert); Sale\OrderProcessingTable::markProductsAdded($orderId); if (defined("BX_COMP_MANAGED_CACHE")) { $app = Main\Application::getInstance(); $app->getTaggedCache()->clearByTag('sale_product_buy'); } }
public static function getInstance() { if (!self::$instance) { $storage = new EnvironmentStorage(Application::getInstance()->getContext()->getRequest()); self::$instance = new static($storage); } return self::$instance; }
public function check($dummy, array $restrictionParams, $deliveryId = 0) { $context = Application::getInstance()->getContext(); $request = $context->getRequest(); if (empty($restrictionParams) || $request->isAdminSection()) { return true; } return $restrictionParams["PUBLIC_SHOW"] == 'Y'; }
public static function update($primary, array $data) { $result = parent::update($primary, $data); if (CACHED_b_lang !== false && $result->isSuccess()) { $cache = \Bitrix\Main\Application::getInstance()->getManagedCache(); $cache->cleanDir("b_lang"); } return $result; }
public function uninstallDB() { if (Loader::includeModule($this->MODULE_ID)) { $connection = Application::getInstance()->getConnection(); $connection->dropTable(LotinfoConfigTable::getTableName()); $connection->dropTable(LotinfoFieldsToPropsTable::getTableName()); $connection->dropTable(LotinfoTypeToIBlockTable::getTableName()); } }
public function getGlobals() { global $APPLICATION, $USER; $coreVariables = array('APPLICATION' => $APPLICATION, 'USER' => $USER); if ($this->isD7()) { $coreVariables['app'] = Application::getInstance(); } return $coreVariables; }
/** * Returns connection name for entity * Have side affect, keep it in mind! * Clone default database connection if connection {@link SessionTable::CONNECTION_NAME} doesn't exists * * @return string */ public static function getConnectionName() { $pool = \Bitrix\Main\Application::getInstance()->getConnectionPool(); $isConnectionExists = $pool->getConnection(static::CONNECTION_NAME) !== null; if (!$isConnectionExists) { $pool->cloneConnection($pool::DEFAULT_CONNECTION_NAME, static::CONNECTION_NAME); } return static::CONNECTION_NAME; }
protected function parsePath($requestUri) { static $storages; if (empty($storages)) { $cache = new \CPHPCache(); if ($cache->initCache(30 * 24 * 3600, 'webdav_disk_common_storage', '/webdav/storage')) { $storages = $cache->getVars(); } else { $storages = \Bitrix\Disk\Storage::getModelList(array('filter' => array('=ENTITY_TYPE' => \Bitrix\Disk\ProxyType\Common::className()))); foreach ($storages as $key => $storage) { $storages[$key] = array('id' => $storage->getEntityId(), 'path' => $storage->getProxyType()->getStorageBaseUrl()); } $cache->startDataCache(); if (defined('BX_COMP_MANAGED_CACHE')) { $taggedCache = \Bitrix\Main\Application::getInstance()->getTaggedCache(); $taggedCache->startTagCache('/webdav/storage'); $taggedCache->registerTag('disk_common_storage'); $taggedCache->endTagCache(); } $cache->endDataCache($storages); } } $patterns = array(array('user', '/(?:company|contacts)/personal/user/(\\d+)/files/lib(.*)$'), array('user', '/(?:company|contacts)/personal/user/(\\d+)/disk/path(.*)$'), array('group', '/workgroups/group/(\\d+)/files(.*)$'), array('group', '/workgroups/group/(\\d+)/disk/path(.*)$')); foreach ($storages as $storage) { $storagePath = trim($storage['path'], '/'); $patterns[] = array('docs', sprintf('^/%s/path(.*)$', $storagePath), $storage['id']); $patterns[] = array('docs', sprintf('^/%s(.*)$', $storagePath), $storage['id']); } // @TODO: aggregator $patterns[] = array('docs', '^/docs/path(.*)$', 'shared_files_s1'); $patterns[] = array('docs', '^/docs(.*)$', 'shared_files_s1'); $type = null; $id = null; $path = null; foreach ($patterns as $pattern) { $matches = array(); if (preg_match('#' . $pattern[1] . '#i', $requestUri, $matches)) { $type = $pattern[0]; list($id, $path) = $type == 'docs' ? array($pattern[2], $matches[1]) : array($matches[1], $matches[2]); break; } } /** @var Storage $storage */ $storage = null; if ($type == 'user') { $storage = Driver::getInstance()->getStorageByUserId((int) $id); } elseif ($type == 'group') { $storage = Driver::getInstance()->getStorageByGroupId((int) $id); } elseif ($type == 'docs') { $storage = Driver::getInstance()->getStorageByCommonId($id); } else { return array(null, null); } $path = static::UrlDecode($path); return array($storage, $path); }
/** * @param array $credentials */ public function addDbConnection($credentials = []) { if (empty($credentials)) { $bitrixDbCredentials = \Bitrix\Main\Application::getInstance()->getConnection()->getConfiguration(); $credentials = ['driver' => 'mysql', 'database' => $bitrixDbCredentials['database'], 'username' => $bitrixDbCredentials['login'], 'password' => $bitrixDbCredentials['password'], 'host' => $bitrixDbCredentials['host'], 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false]; } $this->capsule->addConnection($credentials); $this->capsule->setAsGlobal(); $this->capsule->bootEloquent(); }
function initBitrixCore() { // manual saving of DB resource global $DB; $app = \Bitrix\Main\Application::getInstance(); $con = $app->getConnection(); $DB->db_Conn = $con->getResource(); // "authorizing" as admin $_SESSION["SESS_AUTH"]["USER_ID"] = 1; }
/** * @param array $values * @return array */ public function filter(array $values) { if (Application::getInstance()->isUtfMode()) { return null; } if (empty($values['post']) || !is_array($values['post'])) { return null; } return array('post' => Encoding::convertEncodingArray($values['post'], 'UTF-8', SITE_CHARSET)); }
function qiwiWalletXmlResponse($code) { global $APPLICATION; $APPLICATION->RestartBuffer(); header("Content-Type: text/xml"); header("Pragma: no-cache"); $xml = '<?xml version="1.0" encoding="UTF-8"?><result><result_code>' . $code . '</result_code></result>'; $siteCharset = Application::getInstance()->getContext()->getCulture()->getCharset(); print \CharsetConverter::getInstance()->ConvertCharset($xml, $siteCharset, "utf-8"); die; }
public static function getPropertyFieldHtml($property, $value, $strHTMLControlName) { $request = Application::getInstance()->getContext()->getRequest(); if (empty($value['VALUE']) && $request->get('I18N_RELATED_ID')) { $rsRelatedElement = \CIBlockElement::GetList([], ['IBLOCK_ID' => $property['IBLOCK_ID'], 'ID' => $request->get('I18N_RELATED_ID')], false, false, ['ID', 'IBLOCK_ID', 'PROPERTY_' . $property['CODE']]); if ($relatedElement = $rsRelatedElement->Fetch()) { $value['VALUE'] = $relatedElement['PROPERTY_' . $property['CODE'] . '_VALUE']; } } return $value['VALUE'] . '<input type="hidden" name="' . $strHTMLControlName['VALUE'] . '" value="' . $value['VALUE'] . '">'; }
public function __construct() { $this->validUrls = array("/bitrix/groupdav.php", "/index.php", "/.well-known"); $site = \Bitrix\Main\Application::getInstance()->getContext()->getSite(); $urls = UrlRewriter::getList($site); foreach ($urls as $url) { if (in_array($url['ID'], array('bitrix:socialnetwork_user', 'bitrix:socialnetwork_group', 'bitrix:disk.common'))) { $this->validUrls[] = $url['PATH']; } } }
public function __construct($customOptions = array(), $char = "") { if (isset($customOptions["stop"])) { $this->doBlock = $customOptions["stop"]; } else { $this->doBlock = \COption::getOptionString("security", "filter_stop") === 'Y'; } $this->requestFilter = new Filter\Request($customOptions); $this->serverFilter = new Filter\Server($customOptions); $this->context = \Bitrix\Main\Application::getInstance()->getContext(); $this->splittingChar = $char; }
/** * @param array $arFields * @return string */ public static function getLinkSub(array $fields) { $tag = \Bitrix\Main\Mail\Tracking::getSignedTag(static::MODULE_ID, $fields); $urlPage = \Bitrix\Main\Config\Option::get('sender', 'sub_link'); if ($urlPage == "") { $bitrixDirectory = \Bitrix\Main\Application::getInstance()->getPersonalRoot(); $result = $bitrixDirectory . '/tools/sender_sub_confirm.php?sender_subscription=confirm&tag=' . urlencode($tag); } else { $result = $urlPage . (strpos($urlPage, "?") === false ? "?" : "&") . 'sender_subscription=confirm&tag=' . urlencode($tag); } return $result; }
/** * @param mixed $content * @param int $options - default is JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT * @return string */ public static function encode($content, $options = null) { /** @global CMain $APPLICATION */ global $APPLICATION; if (!Application::getInstance()->isUtfMode()) { $content = $APPLICATION->convertCharsetarray($content, SITE_CHARSET, 'UTF-8'); } if ($options === null) { $options = JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT; } return json_encode($content, $options); }
/** * returns locations data */ private function getData() { $ttl = 2592000; $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache(); if ($cacheManager->read($ttl, $this->cacheId)) { $cityNames = $cacheManager->get($this->cacheId); } else { $cityNames = $this->loadDataToCache(); $cacheManager->set($this->cacheId, $cityNames); } $this->cityNames = $cityNames; return $cityNames; }
public function decode($data) { $res = json_decode($data, true); self::checkException(); // PHP<5.3.3 returns no error for JSON_ERROR_UTF8 and some other ones if ($res === null && ToLower($data) != 'null') { self::throwException(self::JSON_ERROR_UNKNOWN); } if (!Application::getInstance()->isUtfMode()) { $res = self::unConvertData($res); } return $res; }
public static function renderExceptionMessage(\Exception $exception, $debug = false) { if ($debug) { echo ExceptionHandlerFormatter::format($exception, false); } else { $context = Main\Application::getInstance(); if ($context) { echo Main\Localization\Loc::getMessage("eho_render_exception_message"); } else { echo "A error occurred during execution of this script. You can turn on extended error reporting in .settings.php file."; } } }