Пример #1
0
 private static function getInstance()
 {
     if (self::$instance) {
         return self::$instance;
     }
     $loader = new BitrixLoader($_SERVER['DOCUMENT_ROOT']);
     $c = Configuration::getInstance();
     $config = $c->get('maximaster');
     $twigConfig = (array) $config['tools']['twig'];
     $defaultConfig = array('debug' => false, 'charset' => SITE_CHARSET, 'cache' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/maximaster/tools.twig', 'auto_reload' => isset($_GET['clear_cache']) && strtoupper($_GET['clear_cache']) == 'Y', 'autoescape' => false);
     $twigOptions = array_merge($defaultConfig, $twigConfig);
     $twig = new \Twig_Environment($loader, $twigOptions);
     if ($twig->isDebug()) {
         $twig->addExtension(new \Twig_Extension_Debug());
     }
     $twig->addExtension(new BitrixExtension());
     $twig->addExtension(new CustomFunctionsExtension());
     $event = new Event('', 'onAfterTwigTemplateEngineInited', array($twig));
     $event->send();
     if ($event->getResults()) {
         foreach ($event->getResults() as $evenResult) {
             if ($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS) {
                 $twig = current($evenResult->getParameters());
             }
         }
     }
     return self::$instance = $twig;
 }
Пример #2
0
 public function getOptions()
 {
     $c = Configuration::getInstance();
     $config = $c->get('maximaster');
     $twigConfig = (array) $config['tools']['twig'];
     $this->options = array_merge($this->getDefaultOptions(), $twigConfig);
     return $this->options;
 }
 /**
  * Constructor.
  *
  * @param string $connectionName
  *
  * @throws Exception
  */
 public function __construct($connectionName = 'default')
 {
     $connections = Configuration::getInstance()->get('connections');
     if (!array_key_exists($connectionName, $connections)) {
         throw new Exception("Connection '{$connectionName}' is not found in .settings.php");
     }
     $connection = $connections[$connectionName];
     parent::__construct("mysql:dbname={$connection['database']};host={$connection['host']}", $connection['login'], $connection['password']);
 }
 /**
  * Load a configuration for the loggers from `.settings.php` or `.settings_extra.php`.
  *
  * @param bool $force Load even if the configuration has already been loaded.
  *
  * @return bool
  */
 public static function loadConfiguration($force = false)
 {
     if ($force === false && static::$isConfigurationLoaded === true) {
         return true;
     }
     if (class_exists('\\Bitrix\\Main\\Config\\Configuration')) {
         $config = Configuration::getInstance()->get('monolog');
         if (is_array($config) && !empty($config)) {
             Cascade::fileConfig($config);
             return true;
         }
     }
     return false;
 }
Пример #5
0
 /**
  * Sets configs to .settings.php.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param array $settings
  */
 protected function configureSettings(InputInterface $input, OutputInterface $output, array $settings)
 {
     $configuration = Configuration::getInstance();
     foreach ($settings as $name => $value) {
         $configuration->setValue($name, $value);
     }
 }
Пример #6
0
<?php

/**
 * @link https://github.com/bitrix-expert/monolog-adapter
 * @copyright Copyright © 2015 Nik Samokhvalov
 * @license MIT
 */
use Bitrix\Main\Config\Configuration;
use Cascade\Cascade;
if (class_exists('\\Bitrix\\Main\\Config\\Configuration')) {
    $config = Configuration::getInstance()->get('monolog');
    if (is_array($config) && !empty($config)) {
        Cascade::fileConfig($config);
    }
}
Пример #7
0
 public static function wnc()
 {
     $configuration = Configuration::getInstance();
     $configuration->loadConfiguration();
     $ar = array("utf_mode" => array("value" => defined('BX_UTF'), "readonly" => true), "default_charset" => array("value" => defined('BX_DEFAULT_CHARSET'), "readonly" => false), "no_accelerator_reset" => array("value" => defined('BX_NO_ACCELERATOR_RESET'), "readonly" => false), "http_status" => array("value" => defined('BX_HTTP_STATUS') && BX_HTTP_STATUS ? true : false, "readonly" => false));
     $cache = array();
     if (defined('BX_CACHE_SID')) {
         $cache["sid"] = BX_CACHE_SID;
     }
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/cluster/memcache.php")) {
         $arList = null;
         include $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/cluster/memcache.php";
         if (defined("BX_MEMCACHE_CLUSTER") && is_array($arList)) {
             foreach ($arList as $listKey => $listVal) {
                 $bOtherGroup = defined("BX_CLUSTER_GROUP") && $listVal["GROUP_ID"] !== BX_CLUSTER_GROUP;
                 if ($listVal["STATUS"] !== "ONLINE" || $bOtherGroup) {
                     unset($arList[$listKey]);
                 }
             }
             if (count($arList) > 0) {
                 $cache["type"] = array("extension" => "memcache", "required_file" => "modules/cluster/classes/general/memcache_cache.php", "class_name" => "CPHPCacheMemcacheCluster");
             }
         }
     }
     if (!isset($cache["type"])) {
         if (defined('BX_CACHE_TYPE')) {
             $cache["type"] = BX_CACHE_TYPE;
             switch ($cache["type"]) {
                 case "memcache":
                 case "CPHPCacheMemcache":
                     $cache["type"] = "memcache";
                     break;
                 case "eaccelerator":
                 case "CPHPCacheEAccelerator":
                     $cache["type"] = "eaccelerator";
                     break;
                 case "apc":
                 case "CPHPCacheAPC":
                     $cache["type"] = "apc";
                     break;
                 case "xcache":
                 case "CPHPCacheXCache":
                     $cache["type"] = array("extension" => "xcache", "required_file" => "modules/main/classes/general/cache_xcache.php", "class_name" => "CPHPCacheXCache");
                     break;
                 default:
                     if (defined("BX_CACHE_CLASS_FILE") && file_exists(BX_CACHE_CLASS_FILE)) {
                         $cache["type"] = array("required_remote_file" => BX_CACHE_CLASS_FILE, "class_name" => BX_CACHE_TYPE);
                     } else {
                         $cache["type"] = "files";
                     }
                     break;
             }
         } else {
             $cache["type"] = "files";
         }
     }
     if (defined("BX_MEMCACHE_PORT")) {
         $cache["memcache"]["port"] = intval(BX_MEMCACHE_PORT);
     }
     if (defined("BX_MEMCACHE_HOST")) {
         $cache["memcache"]["host"] = BX_MEMCACHE_HOST;
     }
     $ar["cache"] = array("value" => $cache, "readonly" => false);
     $cacheFlags = array();
     $arCacheConsts = array("CACHED_b_option" => "config_options", "CACHED_b_lang_domain" => "site_domain");
     foreach ($arCacheConsts as $const => $name) {
         $cacheFlags[$name] = defined($const) ? constant($const) : 0;
     }
     $ar["cache_flags"] = array("value" => $cacheFlags, "readonly" => false);
     $ar["cookies"] = array("value" => array("secure" => false, "http_only" => true), "readonly" => false);
     $ar["exception_handling"] = array("value" => array("debug" => true, "handled_errors_types" => E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE, "exception_errors_types" => E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_WARNING & ~E_COMPILE_WARNING, "ignore_silence" => false, "assertion_throws_exception" => true, "assertion_error_type" => E_USER_ERROR, "log" => array("settings" => array("file" => "bitrix/modules/error.log", "log_size" => 1000000))), "readonly" => false);
     global $DBType, $DBHost, $DBName, $DBLogin, $DBPassword;
     $DBType = strtolower($DBType);
     if ($DBType == 'mysql') {
         $dbClassName = "\\Bitrix\\Main\\DB\\MysqlConnection";
     } elseif ($DBType == 'mssql') {
         $dbClassName = "\\Bitrix\\Main\\DB\\MssqlConnection";
     } else {
         $dbClassName = "\\Bitrix\\Main\\DB\\OracleConnection";
     }
     $ar['connections']['value']['default'] = array('className' => $dbClassName, 'host' => $DBHost, 'database' => $DBName, 'login' => $DBLogin, 'password' => $DBPassword, 'options' => (!defined("DBPersistent") || DBPersistent ? 1 : 0) | (defined("DELAY_DB_CONNECT") && DELAY_DB_CONNECT === true ? 2 : 0));
     $ar['connections']['readonly'] = true;
     foreach ($ar as $k => $v) {
         if ($configuration->get($k) === null) {
             if ($v["readonly"]) {
                 $configuration->addReadonly($k, $v["value"]);
             } else {
                 $configuration->add($k, $v["value"]);
             }
         }
     }
     $configuration->saveConfiguration();
     $filename1 = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/after_connect.php";
     $filename2 = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/after_connect_d7.php";
     if (file_exists($filename1) && !file_exists($filename2)) {
         $source = file_get_contents($filename1);
         $source = trim($source);
         $pos = 2;
         if (strtolower(substr($source, 0, 5)) == '<?php') {
             $pos = 5;
         }
         $source = substr($source, 0, $pos) . "\n" . '$connection = \\Bitrix\\Main\\Application::getConnection();' . substr($source, $pos);
         $source = preg_replace("#\\\$DB->Query\\(#i", "\$connection->queryExecute(", $source);
         file_put_contents($filename2, $source);
     }
 }
Пример #8
0
<?php

/**
 * Created by PhpStorm.
 * User: Abai Adelshin
 * www.orendev.ru
 */
use Bitrix\Main\Localization\Loc;
if (!check_bitrix_sessid()) {
    return;
}
#работа с .settings.php
$install_count = \Bitrix\Main\Config\Configuration::getInstance()->get('adelshin_module_person');
$cache_type = \Bitrix\Main\Config\Configuration::getInstance()->get('cache');
// считаем данный из файла .settings.php секция 'cache'
#работа с .settings.php
Loc::loadMessages(__FILE__);
if ($ex = $APPLICATION->GetException()) {
    //получаем обЪект который содержит последние ошибки
    echo CAdminMessage::ShowMessage(array("TYPE" => "ERROR", "MESSAGE" => Loc::getMessage("MOD_INST_ERR"), "DETAILS" => $ex->GetString(), "HTML" => true));
} else {
    echo CAdminMessage::ShowNote(Loc::getMessage("MOD_INST_OK"));
}
#работа с .settings.php
echo CAdminMessage::ShowMessage(array("MESSAGE" => Loc::getMessage("ADELSHIN_PERSON_INSTALL_COUNT") . $install_count['install'], "TYPE" => "OK"));
if (!$cache_type['type'] || $cache_type['type'] == 'none') {
    // проверим секцию 'cache' подсекцию 'type' - если ее нет или установлена none выведем сообщение, что кеширование не настроено
    echo CAdminMessage::ShowMessage(array("MESSAGE" => Loc::getMessage("ADELSHIN_PERSON_NO_CACHE"), "TYPE" => "ERROR"));
}
#работа с .settings.php
?>
Пример #9
0
<?php

/**
 * Created by PhpStorm.
 * User: Abai Adelshin
 * www.orendev.ru
 */
use Bitrix\Main\Localization\Loc;
if (!check_bitrix_sessid()) {
    return;
}
#работа с .settings.php
$install_count = \Bitrix\Main\Config\Configuration::getInstance()->get('adelshin_module_person');
#работа с .settings.php
if ($ex = $APPLICATION->GetException()) {
    echo CAdminMessage::ShowMessage(array("TYPE" => "ERROR", "MESSAGE" => Loc::getMessage("MOD_UNINST_ERR"), "DETAILS" => $ex->GetString(), "HTML" => true));
} else {
    echo CAdminMessage::ShowNote(Loc::getMessage("MOD_UNINST_OK"));
}
#работа с .settings.php
echo CAdminMessage::ShowMessage(array("MESSAGE" => Loc::getMessage("ADELSHIN_PERSON_UNINSTALL_COUNT") . $install_count['uninstall'], "TYPE" => "OK"));
#работа с .settings.php
?>
<form action="<?php 
echo $APPLICATION->GetCurPage();
?>
">
	<input type="hidden" name="lang" value="<?php 
echo LANGUAGE_ID;
?>
">
Пример #10
0
 /**
  *
  */
 function DoUninstall()
 {
     global $APPLICATION;
     $context = Application::getInstance()->getContext();
     $request = $context->getRequest();
     if ($request["step"] < 2) {
         $APPLICATION->IncludeAdminFile(Loc::getMessage("ADELSHIN_PERSONE_UNINSTALL_TITLE"), $this->GetPath() . "/install/unstep1.php");
     } elseif ($request["step"] == 2) {
         $this->UnInstallFiles();
         $this->UnInstallEvents();
         if ($request['savedata'] != 'Y') {
             $this->UnInstallDB();
         }
         ModuleManager::unRegisterModule($this->MODULE_ID);
         #работа с .settings.php
         $configuration = Conf\Configuration::getInstance();
         $adelshin_module_person = $configuration->get('adelshin_module_person');
         $adelshin_module_person['uninstall'] = $adelshin_module_person['uninstall'] + 1;
         $configuration->add('adelshin_module_person', $adelshin_module_person);
         $configuration->saveConfiguration();
         #работа с .settings.php
         $APPLICATION->IncludeAdminFile(Loc::getMessage("ADELSHIN_PERSONE_UNINSTALL_TITLE"), $this->GetPath() . "/install/unstep2.php");
     }
 }