Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions src/crest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
require_once (__DIR__.'/settings.php');

if (C_REST_USE_SESSIONS === true)
session_start();

/**
* @version 1.36
* @version 1.37
* define:
* C_REST_WEB_HOOK_URL = 'https://rest-api.bitrix24.com/rest/1/doutwqkjxgc3mgc1/' //url on creat Webhook
* or
Expand All @@ -18,7 +20,7 @@

class CRest
{
const VERSION = '1.36';
const VERSION = '1.37';
const BATCH_COUNT = 50;//count batch 1 query
const TYPE_TRANSPORT = 'json';// json or xml

Expand Down Expand Up @@ -407,18 +409,26 @@ private static function getAppSettings()
protected static function getSettingData()
{
$return = [];
if(file_exists(__DIR__ . '/settings.json'))

if (!empty($_SESSION['CRestSettings']) && C_REST_USE_SESSIONS === true) {
$return = static::expandData($_SESSION['CRestSettings']);
$skipSettingsFile = true;
}

if(file_exists(__DIR__ . '/settings.json') && !$skipSettingsFile)
{
$return = static::expandData(file_get_contents(__DIR__ . '/settings.json'));
if(defined("C_REST_CLIENT_ID") && !empty(C_REST_CLIENT_ID))
{
$return['C_REST_CLIENT_ID'] = C_REST_CLIENT_ID;
}
if(defined("C_REST_CLIENT_SECRET") && !empty(C_REST_CLIENT_SECRET))
{
$return['C_REST_CLIENT_SECRET'] = C_REST_CLIENT_SECRET;
}
}

if (!empty($return))
{
if(defined("C_REST_CLIENT_ID") && !empty(C_REST_CLIENT_ID))
$return['C_REST_CLIENT_ID'] = C_REST_CLIENT_ID;

if(defined("C_REST_CLIENT_SECRET") && !empty(C_REST_CLIENT_SECRET))
$return['C_REST_CLIENT_SECRET'] = C_REST_CLIENT_SECRET;

}
return $return;
}

Expand Down Expand Up @@ -508,7 +518,12 @@ protected static function expandData($data)

protected static function setSettingData($arSettings)
{
return (boolean)file_put_contents(__DIR__ . '/settings.json', static::wrapData($arSettings));
if (C_REST_USE_SESSIONS === true) {
$_SESSION['CRestSettings'] = static::wrapData($arSettings);
return ($_SESSION['CRestSettings'] == static::wrapData($arSettings));
} else {
return (boolean)file_put_contents(__DIR__ . '/settings.json', static::wrapData($arSettings));
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
//define('C_REST_IGNORE_SSL',true);//turn off validate ssl by curl
//define('C_REST_LOG_TYPE_DUMP',true); //logs save var_export for viewing convenience
//define('C_REST_BLOCK_LOG',true);//turn off default logs
//define('C_REST_LOGS_DIR', __DIR__ .'/logs/'); //directory path to save the log
//define('C_REST_LOGS_DIR', __DIR__ .'/logs/'); //directory path to save the log
//define('C_REST_USE_SESSIONS', true); // Save settings to sessions instead of the settings.json file