-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
2267 lines (1519 loc) · 60.8 KB
/
functions.php
File metadata and controls
2267 lines (1519 loc) · 60.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
class pdPetitions {
public $campaign = [];
public function __construct($campaign_id){
if (is_object($campaign_id)){
$this->campaign = $campaign_id ;
}
else {
$this->campaign = db_campaigns_list::find_by_id($campaign_id);
}
}
public function get(){
return $this->campaign ;
}
static function loadCampaign($campaign_id){
return new pdPetitions($campaign_id);
}
public function isExists(){
if (empty($this->campaign))
return false;
return true ;
}
public function getCampaignId(){
return $this->get()->id;
}
public function hasPrevi(){
Global $_USER ;
if (!$this->isExists())
return false ;
if ($_USER->hasRole('coordinator')) {
// also check domains
if (!empty($_USER->getMainUser()->getDomains()))
if (!in_array($this->campaign->domain, $_USER->getMainUser()->getDomains()))
return false;
//if (!empty($_USER->getMainUser()->getDomains()))
// if ($this->campaign->domain == 'yabloko' AND in_array('yabloko', $_USER->getMainUser()->getDomains()))
// return false;
if ($this->campaign->petition_city == $_USER->getOptions('petition_city'))
return true;
if ($this->campaign->owner_id == $_USER->getOptions('id'))
return true;
}
if ($_USER->hasRole('admin'))
return true;
if ($this->campaign->owner_id == $_USER->getOptions('id'))
return true;
return false ;
}
public function getStats(){
$pskov_region_total = db_appeals_list::count([
'conditions' => ['destination=? AND region_name="Псковская область"', $this->getCampaignId()],
]);
$pskov_total = db_appeals_list::count([
'conditions' => ['destination=? AND city="Псков"', $this->getCampaignId()],
]);
$luki_total = db_appeals_list::count([
'conditions' => ['destination=? AND city="Великие Луки"', $this->getCampaignId()],
]);
$abroad_total = db_appeals_list::count([
'conditions' => ['destination=? AND region_name="не РФ"', $this->getCampaignId()],
]);
$subregions_pskov = [];
$pskov_subregions = db_appeals_list::find('all', [
'select' => 'COUNT(*) as amount, rn_name',
'conditions' => ['destination=? AND region_name="Псковская область" AND rn_name!="" AND city NOT IN ("Псков", "Великие Луки")', $this->getCampaignId()],
'order' => 'rn_name ASC',
'group' => 'rn_name',
]);
foreach ($pskov_subregions as $subregion)
$subregions_pskov[] = [
'rn_name' => $subregion->rn_name,
'amount' => $subregion->amount,
];
$regions = [];
$regions_sum = 0;
$russia_regions = db_appeals_list::find('all', [
'select' => 'COUNT(*) as amount, region_name',
'conditions' => ['destination=? AND region_name!="Псковская область" AND region_name!="не РФ"', $this->getCampaignId()],
'order' => 'region_name ASC',
'group' => 'region_name',
]);
foreach ($russia_regions as $region) {
$regions[] = [
'region_name' => $region->region_name,
'amount' => $region->amount,
];
$regions_sum += $region->amount;
}
$output = [
'amount_total' => self::appealsAmountAt($this->getCampaignId()),
'pskov_region_total' => $pskov_region_total,
'city_pskov_total' => $pskov_total,
'city_luki_total' => $luki_total,
'abroad_total' => $abroad_total,
'regions' => $regions,
'regions_sum' => $regions_sum,
'subregions_pskov' => $subregions_pskov,
];
return $output ;
}
static function appealsAmountAt($campaign_id){
$amount = db_appeals_list::count([
'conditions' => ['destination=?', $campaign_id],
]);
return $amount;
}
static function formatParagraph($text){
$tmpText = nl2br($text);
$tmpText = str_replace("<br />\n<br />", '<br />', $tmpText);
$tmpText = str_replace("<br />", '</p><p>', $tmpText);
$tmpText = '<p>' . $tmpText . '</p>';
return $tmpText;
}
/*
* По умоланию доступны только созданные самим человеком петици
* Для админа все
* Для координатора все из его города или созданные им
*/
static function getListForUser(db_main_users $user){
$params = [];
$conditions = ['owner_id=?', $user->id];
if ($user->role == 'admin')
$conditions = ['1=1'];
if ($user->role == 'coordinator'){
$conditions = ['(petition_city=? OR owner_id=?)', $user->petition_city, $user->id];
if (!empty($user->getDomains())) {
$conditions[0] .= ' AND domain IN (?)';
$conditions[] = $user->getDomains();
}
}
$campaigns = db_campaigns_list::find('all', [
'order' => 'id DESC',
'select' => 'id, owner_id, url, title, is_active, is_confirmed, petition_city, domain',
'conditions' => $conditions,
]);
$petitions = [];
$usersIds = gdHandlerSkeleton::collectKeys($campaigns, ['owner_id']);
$users = [];
if (!empty($usersIds)){
$users = db_main_users::find('all', [
'select' => 'id, name, surname',
'conditions' => ['id IN (?)', $usersIds],
]);
$users = gdHandlerSkeleton::collectKeys($users, ['id'], [
'mapScope' => ['name', 'surname'],
]);
}
foreach ($campaigns as $_campaign) {
$item = $_campaign->to_array();
$item['abs_url'] = $_campaign->getAbsUrl();
$item['owner'] = $users[$item['owner_id']];
$item['people'] = $_campaign->getAppealsAmount();
$petitions[] = $item;
}
return $petitions ;
}
}
class mdFiles {
static function inner__saveImageSizeIfRequired(&$attach){
Global $_CFG ;
// get image size, if required
if (in_array($attach->extension, ['png', 'jpg', 'gif']) AND $attach->img_width == ''){
$attachInfo = self::getAttachInfo($attach);
$imgInfo = getimagesize($_CFG['root'] . $attachInfo['absLink']);
$attach->img_width = $imgInfo[0];
$attach->img_height = $imgInfo[1];
$attach->save();
//print '<pre>' . print_r($imgInfo, true) . '</pre>';
}
}
static function getAttachLink($attach){
self::inner__saveImageSizeIfRequired($attach);
$attachInfo = self::getAttachInfo($attach);
return $attachInfo['absLink'];
}
static function getAttachInfo($attach, $params = []){
$link = substr($attach->read_attribute('download_hash_md5'), 0, 10) . '/' . $attach->read_attribute('download_hash_md5') . '.' . $attach->read_attribute('extension') ;
$details = [];
if ($attach->img_width != ''){
$details['cropClass'] = 'crop-height';
if ($attach->img_width > $attach->img_height)
$details['cropClass'] = 'crop-width';
}
$attachInfo = array_merge($attach->to_array(), array('link' => $link, 'absLink' => '/static/attach/' . $link), $details);
return $attachInfo;
}
static function parseAttachesOutput($attaches_list, $params = []){
Global $_CFG ;
$attachList = array();
foreach ($attaches_list as $_attach){
self::inner__saveImageSizeIfRequired($_attach);
$attachInfo = self::getAttachInfo($_attach, $params);
$attachList[] = $attachInfo ;
}
return $attachList ;
}
static function removeAttachedFile($attach = false){
Global $_USER, $_CFG ;
$output = [];
if (empty($attach)){
$output['error'] = 'ntf attach';
$output['error_text'] = 'Прикреплённый файл не найден';
return ;
}
$attach_id = $attach->read_attribute('attach_id');
list($attach_dir, $filename) = self::getPathToAttach($attach);
//print $attach_dir . $filename;
//exit();
if (!file_exists($attach_dir . $filename)){
//$this->output['error'] = 'attach file ntf';
//$this->output['error_text'] = 'Прикреплённый файл не найден №2';
//return ;
$output['deleted_id'] = -1 ;
}
else {
$attach->delete();
unlink($attach_dir . $filename);
//remove resized
$cdirFiles = scandir($attach_dir);
foreach ($cdirFiles as $_key => $_file) {
if (in_array($_file, array(".","..")))
continue ;
if (is_dir($attach_dir.$_file)) continue;
if(strpos(basename($_file),basename($filename)) !== false)
unlink($attach_dir.$_file);
}
// remove dir if it is empty now
$files_in_dir = count(scandir($attach_dir));
if ($files_in_dir == 2) rmdir($attach_dir);
$output['deleted_id'] = $attach_id ;
}
}
static function getPathToAttach($attach){
Global $_CFG ;
$subdir_name = substr($attach->read_attribute('download_hash_md5'), 0, 10);
$attach_dir = $_CFG['root'] . 'static/attach/' . $subdir_name . '/';
$filename = $attach->read_attribute('download_hash_md5') . '.' . $attach->read_attribute('extension');
return array($attach_dir, $filename);
}
}
function postFile($file_url, $params){
$tmpfile = $file_url;
$filename = $params['file_name'];
// deprecated for 5.6
$data = array(
'fileupload' => '@'.$tmpfile.';filename='.$filename,
);
// actual for 5.6 PHP
$data = [
'fileupload' => new \CurlFile($tmpfile, 'image/jpg', $filename)
];
if (isset($params['debug'])){
print '<pre>' . print_r($data, true) . '</pre>';
print '<pre>' . print_r($params, true) . '</pre>';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $params['upload_url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec ($ch);
return $result ;
}
class gdCache {
static function initMemcache(){
Global $_CFG ;
if (isset($_CFG['memcache']))
return ;
$_CFG['memcache'] = new Memcache;
$_CFG['memcache']->connect('127.0.0.1', 11211) or die ("Could not connect to main five server");
}
static function closure($cached_key, $closure_or_value, $time = 60){
$cached_content = gdCache::get($cached_key);
if ($cached_content !== false)
return $cached_content ;
if (is_callable($closure_or_value))
$cached_content = $closure_or_value();
if (!is_callable($closure_or_value))
$cached_content = $closure_or_value();
gdCache::put($cached_key, $cached_content, $time);
return $cached_content;
}
static function put($cached_key, $value, $time = 60){
Global $_CFG ;
gdCache::initMemcache();
$cached_result = $_CFG['memcache']->set($cached_key, $value, MEMCACHE_COMPRESSED, $time);
if (isset($_GET['standartOil'])){
//print 'Set up cache ' . $cached_key ;
//var_dump($cached_result);
}
}
static function get($cached_key, $format = 'string'){
Global $_CFG ;
gdCache::initMemcache();
$cache_result = $_CFG['memcache']->get($cached_key);
if (isset($_GET['standartOil'])){
//print 'Desired ' . $cached_key ;
//var_dump($cache_result);
}
if ($cache_result === false)
return false ;
if ($format == 'string'){
return $cache_result ;
}
if ($format == 'json'){
$cache_result = json_decode($cache_result, true);
if (!is_array($cache_result))
return false ;
return $cache_result;
}
if ($format == 'serialized'){
$cache_result = unserialize($cache_result);
if (!is_array($cache_result))
return false ;
return $cache_result;
}
}
static function remove($cached_key){
Global $_CFG ;
gdCache::initMemcache();
return $_CFG['memcache']->delete($cached_key);
}
}
class gdUserTask {
static function isFinalAdvancewithChosed($user_id, $desired_advancewith = '', $params = array()){
/*
Проверяем выдвигается ли этот человек от Яблока
*/
$cache_key = 'advwith_' . $user_id . $desired_advancewith ;
$cached = gdCache::get($cache_key);
if (!in_array('nocache', $params))
if ($cached !== false)
if ($cached == 'b:1;'){
return true ;
}
else {
return false ;
}
$conditions = array('created_account=? AND advancewith_final="N/A"', $user_id);
if ($desired_advancewith != '')
$conditions = array('created_account=? AND advancewith_final=?', $user_id, $desired_advancewith);
$hasAdvancewith = db_regions_deputy::exists(array(
'conditions' => $conditions,
));
$returnValue = $hasAdvancewith ;
gdCache::put($cache_key, serialize($returnValue), 60 * 1);
return $returnValue ;
}
static function isChosedYabloko($user_id){
/*
Проверяем выдвигается ли этот человек от Яблока
*/
$finished_task2_yabloko = db_extra_variables::exists(array(
'conditions' => array('name=? AND connected_to=? AND value_large!="[]" AND (value_large LIKE "%yabloko\":\"5\"%" OR value_large LIKE "%yabloko\":\"4\"%")', 'task2Data', $user_id),
));
if (!$finished_task2_yabloko)
return false;
return true ;
}
static function isVisitedTraining($user_id, $event_type, $params = array()){
if ($user_id == 1143 AND $event_type == 'training')
return true ;
/*
Проверяем прошёл ли человек тренинг
*/
$cache_key = 'visited_' . $user_id . $event_type ;
$cached = gdCache::get($cache_key);
if (!in_array('nocache', $params))
if ($cached !== false)
if ($cached == 'b:1;'){
return true ;
}
else {
return false ;
}
$joiningFound = db_extra_variables::exists(array(
'conditions' => array('name=? AND connected_to=? AND value LIKE "%visited_training;%"', 'task_' . $event_type . '_join', $user_id),
));
$returnValue = $joiningFound ;
gdCache::put($cache_key, serialize($returnValue), 60 * 1);
return $returnValue ;
}
static function isQuenedTraining($user_id, $event_type){
if ($user_id == 1143 AND $event_type == 'training')
return true ;
/*
Проверяем записан ли человек на тренинг
*/
$joiningFound = db_extra_variables::exists(array(
'conditions' => array('name=? AND connected_to=? AND value_timestamp>NOW()', 'task_' . $event_type . '_join', $user_id),
));
return $joiningFound;
if (!$joiningFound)
return false;
return true ;
}
}
class gdTemplate {
public function __construct($name, $parentVars = []){
Global $_CFG ;
$this->root = $_CFG['root'];
$this->name = $name ;
return $this->open($name, $parentVars);
}
public function open($name, $parentVars = []){
Global $_CFG ;
$tpl_path = $_CFG['root'] . 'modules/templates/';
ob_start ();
$path = $this->root . 'modules/templates/' . $name . '.php';
include($path);
$this->content = ob_get_contents();
ob_end_clean();
}
public function draw(){
return $this->content ;
}
public function getTemplateConditionsChunks(&$html){
$listBlocks = array();
$offset = 0;
$prev = array();
$limit = 0;
while (true){
$startedWithOffset = $offset ;
$position_start = strpos($html, '<!--[!template=if:', $offset);
//print 'position_start ' . $position_start . '<br/>';
if ($position_start === false)
break ;
$offset = $position_start ;
$position_start_c = strpos($html, ']-->', $offset) + 4;
$offset = $position_start_c;
$position_end_c = strpos($html, '<!--/[!template=if:', $offset);
$offset = $position_end_c;
$position_end = strpos($html, ']-->', $offset) + 4;
$offset = $position_end;
//print 'position_end ' . $position_end . '<br/>';
$content = substr($html, $position_start, $position_end - $position_start);
if ($startedWithOffset == 0){
$listBlocks[] = substr($html, $startedWithOffset, $position_start);
}
//if ($startedWithOffset != 0)
//if ($startedWithOffset == $previousWithOffset)
if ($startedWithOffset != 0){
//print 'From end ' . $prev['end'] . '==' . $position_start;
$listBlocks[] = substr($html, $prev['end'], $position_start - $prev['end']);
}
$listBlocks[] = array(
'start' => $position_start,
'start_c' => $position_start_c,
'end' => $position_end,
'end_c' => $position_end_c,
'content' => $content,
);
$prev = array(
'start' => $position_start,
'start_c' => $position_start_c,
'end' => $position_end,
'end_c' => $position_end_c,
);
if ($limit > 10)
break ;
$limit++;
}
$listBlocks[] = substr($html, $startedWithOffset);
return $listBlocks ;
}
public function executeTemplateConditions($params, &$listBlocks){
foreach ($listBlocks as $_key => $_block){
if (!is_array($_block))
continue ;
$condition = str_replace('<!--[!template=if:', '', $_block['content']);
$condition = explode(']-->', $condition);
$condition = $condition[0];
if (strpos($condition, '==') !== false){
list ($c_var, $c_value) = explode('==', $condition);
// condition failed
if ($params[$c_var] != $c_value){
// cut it
unset($listBlocks[$_key]);
//$lengthChanged = $lengthChanged - strlen($html) ;
//print 'failed';
}
// condition success
else {
//print 'success ' ;
$listBlocks[$_key]['content'] = substr($_block['content'], $_block['start_c'] - $_block['start'], $_block['end_c'] - $_block['start_c']);
}
}
if (strpos($condition, '!=') !== false){
list ($c_var, $c_value) = explode('!=', $condition);
$c_value = explode(',', $c_value);
// succcess by default
$is_failed = false ;
foreach ($c_value as $_c_key => $_c_sub) {
// condition failed
if ($params[$c_var] == $_c_sub) {
// cut it
unset($listBlocks[$_key]);
$is_failed = true ;
}
}
if ($is_failed == false)
$listBlocks[$_key]['content'] = substr($_block['content'], $_block['start_c'] - $_block['start'], $_block['end_c'] - $_block['start_c']);
}
}
}
public function processTemplateConditions($params, $html = ''){
/*
Вырезаем все условия
*/
if ($html == '')
$html = $this->content ;
$listBlocks = $this->getTemplateConditionsChunks($html);
$this->executeTemplateConditions($params, $listBlocks);
// Соединяем страницу со списка частей в единое целое
$html_new = '';
$offset = 0;
foreach ($listBlocks as $_block){
if (is_array($_block)){
$html_new .= $_block['content'];
$offset = $_block['start_c'];
}
else {
$html_new .= $_block ;
}
}
//print $html ;
//print '<pre>' . print_r($listBlocks, true) . '</pre>';
//exit();
return $html_new ;
}
private function replaceInTemplate($name, $value){
$this->content = str_replace($name, $value, $this->content);
}
public function set($params, $extra = array()){
$this->content = $this->processTemplateConditions($params);
if (is_array($params)){
foreach ($params as $_key => $_value)
if ($_key[0] == '{')
$this->replaceInTemplate($_key, $_value);
}
else {
$this->replaceInTemplate($params, $extra);
}
}
}
class gdPanel {
static function flushMetaFor($url){
$cache_key = 'meta4_' . $url ;
gdCache::remove($cache_key);
}
static function getMetaFor($url){
if ($url == 'against')
$url = 'index';
$cache_key = 'meta4_' . $url ;
$cached = gdCache::get($cache_key);
if ($cached !== false) {
return json_decode($cached, true);
}
else {
$metaInfo = db_meta_tags::find_by_inner_url($url);
$details = '[]';
if (!empty($metaInfo)) {
gdCache::put($cache_key, $metaInfo->details, 60 * 5);
$details = $metaInfo->details ;
}
}
return json_decode($details, true);
}
static function getStringLength($text){
return strlen(iconv('utf-8', 'windows-1251', $text));
}
static function forceTypograph($text, $indesign_mode = false){
Global $_CFG ;
include_once($_CFG['root'] . "classes/EMT_typograph.php");
$typographed = EMTypograph::fast_apply($text);
//$typographed = str_replace(' ', ' ', $typographed);
$typographed = str_replace(array('<p>', '</p>'), '', $typographed);
if ($indesign_mode){
$typographed = html_entity_decode($typographed);
$typographed = str_replace('<br />', "", $typographed);
}
//$typographed = str_replace(' ', ' ', $typographed);
return $typographed ;
}
static function inner__removeAttachFromSbmachine($external_attach_hash, $refresh_key = ''){
Global $_CFG ;
$url = 'https://.ru/ajax/ajax_ext_attach.php?context=dmachine__attempToRemove&external_attach_hash=%s&action_signature=%s&refresh_key=' . $refresh_key;
$url = sprintf($url, $external_attach_hash, md5($external_attach_hash . $_CFG['dmachine_flkey']));
$output = file_get_contents($url);
$output = @json_decode($output, true);
if (!is_array($output)){
$output = array(
'error' => 'impossible',
'error_text' => 'unable to parse json',
);
}
return $output ;
}
static function utfToLower($text){
return (mb_convert_case($text, MB_CASE_LOWER, 'utf-8'));
}
static function sendToTelegram($telegram_id, $question_reply, $from_site_id = -1, $params = array()){
$status = ['error' => 'false'];
$question_reply = str_replace(['<br>', '<br/>'], '', $question_reply);
$encoded_message = base64_encode($question_reply);
$messageAdded = db_massbot_messages::find_by_message($encoded_message, array(
'select' => 'message_id',
));
if (!empty($messageAdded)){
}
else {