Completed
Push — master ( af4c7f...3dc19b )
by Agel_Nash
03:45
created
assets/snippets/DocLister/lib/DLphx.class.php 2 patches
Doc Comments   +56 added lines patch added patch discarded remove patch
@@ -56,6 +56,10 @@  discard block
 block discarded – undo
56 56
     }
57 57
 
58 58
     // Parser: Preparation, cleaning and checkup
59
+
60
+    /**
61
+     * @return string
62
+     */
59 63
     public function Parse($template = '')
60 64
     {
61 65
         global $modx;
@@ -204,6 +208,10 @@  discard block
 block discarded – undo
204 208
     }
205 209
 
206 210
     // Parser: modifier detection and eXtended processing if needed
211
+
212
+    /**
213
+     * @param string $modifiers
214
+     */
207 215
     public function Filter($input, $modifiers)
208 216
     {
209 217
         global $modx;
@@ -511,6 +519,12 @@  discard block
 block discarded – undo
511 519
 
512 520
     // Returns the specified field from the user record
513 521
     // positive userid = manager, negative integer = webuser
522
+
523
+	/**
524
+	 * @param string $field
525
+	 *
526
+	 * @return string
527
+	 */
514 528
 	public function ModUser($userid, $field)
515 529
     {
516 530
         global $modx;
@@ -558,6 +572,10 @@  discard block
 block discarded – undo
558 572
     }
559 573
 
560 574
     // Returns the value of a PHx/MODx placeholder.
575
+
576
+	/**
577
+	 * @param string $name
578
+	 */
561 579
 	public function getPHxVariable($name)
562 580
     {
563 581
         global $modx;
@@ -572,36 +590,59 @@  discard block
 block discarded – undo
572 590
     }
573 591
 
574 592
     // Sets a placeholder variable which can only be access by PHx
593
+
594
+	/**
595
+	 * @param string $name
596
+	 * @param string $value
597
+	 */
575 598
 	public function setPHxVariable($name, $value)
576 599
     {
577 600
         if ($name != "phx") $this->placeholders[$name] = $value;
578 601
     }
579 602
 
580 603
     //mbstring
604
+
605
+	/**
606
+	 * @param string $str
607
+	 * @param integer $s
608
+	 * @param integer $l
609
+	 */
581 610
 	public function substr($str, $s, $l = null)
582 611
     {
583 612
         if (function_exists('mb_substr')) return mb_substr($str, $s, $l);
584 613
         return substr($str, $s, $l);
585 614
     }
586 615
 
616
+	/**
617
+	 * @param string $str
618
+	 */
587 619
 	public function strlen($str)
588 620
     {
589 621
         if (function_exists('mb_strlen')) return mb_strlen($str);
590 622
         return strlen($str);
591 623
     }
592 624
 
625
+	/**
626
+	 * @param string $str
627
+	 */
593 628
 	public function strtolower($str)
594 629
     {
595 630
         if (function_exists('mb_strtolower')) return mb_strtolower($str);
596 631
         return strtolower($str);
597 632
     }
598 633
 
634
+	/**
635
+	 * @param string $str
636
+	 */
599 637
 	public function strtoupper($str)
600 638
     {
601 639
         if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
602 640
         return strtoupper($str);
603 641
     }
604 642
 
643
+	/**
644
+	 * @param string $str
645
+	 */
605 646
 	public function ucfirst($str)
606 647
     {
607 648
         if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen'))
@@ -609,6 +650,9 @@  discard block
 block discarded – undo
609 650
         return ucfirst($str);
610 651
     }
611 652
 
653
+	/**
654
+	 * @param string $str
655
+	 */
612 656
 	public function lcfirst($str)
613 657
     {
614 658
         if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen'))
@@ -616,6 +660,9 @@  discard block
 block discarded – undo
616 660
         return lcfirst($str);
617 661
     }
618 662
 
663
+	/**
664
+	 * @param string $str
665
+	 */
619 666
 	public function ucwords($str)
620 667
     {
621 668
         if (function_exists('mb_convert_case'))
@@ -623,12 +670,18 @@  discard block
 block discarded – undo
623 670
         return ucwords($str);
624 671
     }
625 672
 
673
+	/**
674
+	 * @param string $str
675
+	 */
626 676
 	public function strrev($str)
627 677
     {
628 678
         preg_match_all('/./us', $str, $ar);
629 679
         return implode(array_reverse($ar[0]));
630 680
     }
631 681
 
682
+	/**
683
+	 * @param string $str
684
+	 */
632 685
 	public function str_shuffle($str)
633 686
     {
634 687
         preg_match_all('/./us', $str, $ar);
@@ -636,6 +689,9 @@  discard block
 block discarded – undo
636 689
         return implode($ar[0]);
637 690
     }
638 691
 
692
+	/**
693
+	 * @param string $str
694
+	 */
639 695
 	public function str_word_count($str)
640 696
     {
641 697
         return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
Please login to merge, or discard this patch.
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
                     case "eq":
230 230
                         $condition[] = intval(($output == $modifier_value[$i]));
231 231
                         break;
232
-					case "empty":
233
-						 $condition[] = intval(empty($output));
234
-						break;
232
+                    case "empty":
233
+                         $condition[] = intval(empty($output));
234
+                        break;
235 235
                     case "notequals":
236 236
                     case "isnot":
237 237
                     case "isnt":
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
                         if (!$isvalid) {
277 277
                             $output = NULL;
278 278
                         }
279
-						break;
279
+                        break;
280 280
                     case "then":
281 281
                         $conditional = implode(' ', $condition);
282 282
                         $isvalid = intval(eval("return (" . $conditional . ");"));
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                         break;
289 289
                     case "else":
290 290
                         $conditional = implode(' ', $condition);
291
-						$isvalid = intval(eval("return (" . $conditional . ");"));
291
+                        $isvalid = intval(eval("return (" . $conditional . ");"));
292 292
                         if (!$isvalid) {
293 293
                             $output = $modifier_value[$i];
294 294
                         }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
                     case "select":
297 297
                         $raw = explode("&", $modifier_value[$i]);
298 298
                         $map = array();
299
-						$count = count($raw);
299
+                        $count = count($raw);
300 300
                         for ($m = 0; $m < $count; $m++) {
301 301
                             $mi = explode("=", $raw[$m]);
302 302
                             $map[$mi[0]] = $mi[1];
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
                     ##### End of Conditional Modifiers
307 307
 
308 308
                     #####  String Modifiers
309
-					case "default":{
309
+                    case "default":{
310 310
                         $output = ($output === '') ? $modifier_value[0] : $output;
311 311
                         break;
312 312
                     }
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
     }
472 472
 
473 473
     // Returns a cleaned string escaping the HTML and special MODx characters
474
-	public function LogClean($string)
474
+    public function LogClean($string)
475 475
     {
476 476
         $string = preg_replace("/&amp;(#[0-9]+|[a-z]+);/i", "&$1;", $string);
477 477
         $string = APIHelpers::sanitarTag($string);
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
     }
480 480
 
481 481
     // Simple log entry
482
-	public function Log($string)
482
+    public function Log($string)
483 483
     {
484 484
         if ($this->debug) {
485 485
             $this->debugLog = true;
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
     }
489 489
 
490 490
     // Log snippet output
491
-	public function LogSnippet($string)
491
+    public function LogSnippet($string)
492 492
     {
493 493
         if ($this->debug) {
494 494
             $this->debugLog = true;
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
     }
498 498
 
499 499
     // Log pass
500
-	public function LogPass()
500
+    public function LogPass()
501 501
     {
502 502
         $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Pass " . $this->curPass . "</div>";
503 503
     }
504 504
 
505 505
     // Log pass
506
-	public function LogSource($string)
506
+    public function LogSource($string)
507 507
     {
508 508
         $this->console[] = "<div style='margin: 2px;margin-top: 5px;border-bottom: 1px solid black;'>Source:</div>" . $this->LogClean($string);
509 509
     }
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 
512 512
     // Returns the specified field from the user record
513 513
     // positive userid = manager, negative integer = webuser
514
-	public function ModUser($userid, $field)
514
+    public function ModUser($userid, $field)
515 515
     {
516 516
         global $modx;
517 517
         if (!array_key_exists($userid, $this->cache["ui"])) {
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     }
529 529
 
530 530
     // Returns true if the user id is in one the specified webgroups
531
-	public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array())
531
+    public function isMemberOfWebGroupByUserId($userid = 0, $groupNames = array())
532 532
     {
533 533
         global $modx;
534 534
 
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
     }
559 559
 
560 560
     // Returns the value of a PHx/MODx placeholder.
561
-	public function getPHxVariable($name)
561
+    public function getPHxVariable($name)
562 562
     {
563 563
         global $modx;
564 564
         // Check if this variable is created by PHx
@@ -572,71 +572,71 @@  discard block
 block discarded – undo
572 572
     }
573 573
 
574 574
     // Sets a placeholder variable which can only be access by PHx
575
-	public function setPHxVariable($name, $value)
575
+    public function setPHxVariable($name, $value)
576 576
     {
577 577
         if ($name != "phx") $this->placeholders[$name] = $value;
578 578
     }
579 579
 
580 580
     //mbstring
581
-	public function substr($str, $s, $l = null)
581
+    public function substr($str, $s, $l = null)
582 582
     {
583 583
         if (function_exists('mb_substr')) return mb_substr($str, $s, $l);
584 584
         return substr($str, $s, $l);
585 585
     }
586 586
 
587
-	public function strlen($str)
587
+    public function strlen($str)
588 588
     {
589 589
         if (function_exists('mb_strlen')) return mb_strlen($str);
590 590
         return strlen($str);
591 591
     }
592 592
 
593
-	public function strtolower($str)
593
+    public function strtolower($str)
594 594
     {
595 595
         if (function_exists('mb_strtolower')) return mb_strtolower($str);
596 596
         return strtolower($str);
597 597
     }
598 598
 
599
-	public function strtoupper($str)
599
+    public function strtoupper($str)
600 600
     {
601 601
         if (function_exists('mb_strtoupper')) return mb_strtoupper($str);
602 602
         return strtoupper($str);
603 603
     }
604 604
 
605
-	public function ucfirst($str)
605
+    public function ucfirst($str)
606 606
     {
607 607
         if (function_exists('mb_strtoupper') && function_exists('mb_substr') && function_exists('mb_strlen'))
608 608
             return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
609 609
         return ucfirst($str);
610 610
     }
611 611
 
612
-	public function lcfirst($str)
612
+    public function lcfirst($str)
613 613
     {
614 614
         if (function_exists('mb_strtolower') && function_exists('mb_substr') && function_exists('mb_strlen'))
615 615
             return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1, mb_strlen($str));
616 616
         return lcfirst($str);
617 617
     }
618 618
 
619
-	public function ucwords($str)
619
+    public function ucwords($str)
620 620
     {
621 621
         if (function_exists('mb_convert_case'))
622 622
             return mb_convert_case($str, MB_CASE_TITLE);
623 623
         return ucwords($str);
624 624
     }
625 625
 
626
-	public function strrev($str)
626
+    public function strrev($str)
627 627
     {
628 628
         preg_match_all('/./us', $str, $ar);
629 629
         return implode(array_reverse($ar[0]));
630 630
     }
631 631
 
632
-	public function str_shuffle($str)
632
+    public function str_shuffle($str)
633 633
     {
634 634
         preg_match_all('/./us', $str, $ar);
635 635
         shuffle($ar[0]);
636 636
         return implode($ar[0]);
637 637
     }
638 638
 
639
-	public function str_word_count($str)
639
+    public function str_word_count($str)
640 640
     {
641 641
         return count(preg_split('~[^\p{L}\p{N}\']+~u', $str));
642 642
     }
Please login to merge, or discard this patch.
assets/snippets/DocLister/lib/jsonHelper.class.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         return isset(self::$_error[$error]) ? self::$_error[$error] : 'other';
70 70
     }
71 71
 	
72
-	public static function toJSON(array $data = array()){
72
+    public static function toJSON(array $data = array()){
73 73
         if (version_compare(PHP_VERSION, '5.4.0') < 0) {
74 74
             $out = json_encode($data);
75 75
             $out = str_replace('\\/', '/', $out);
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         return self::json_format($out);
80 80
     }
81 81
 	
82
-	 public static function json_format($json){
82
+        public static function json_format($json){
83 83
         $tab = "  ";
84 84
         $new_json = "";
85 85
         $indent_level = 0;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                     if($c > 0 && $json[$c-1] != '\\'){
128 128
                         $in_string = !$in_string;
129 129
                     }
130
-					// no break
130
+                    // no break
131 131
                 default:
132 132
                     $new_json .= $char;
133 133
                     break;
Please login to merge, or discard this patch.
assets/lib/SimpleTab/table.abstract.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,9 +6,9 @@
 block discarded – undo
6 6
 class dataTable extends \autoTable {
7 7
     protected $params = array();
8 8
     protected $fs = null;
9
-	protected $indexName = null;
10
-	protected $rfName = null;
11
-	protected $thumbsCache = null;
9
+    protected $indexName = null;
10
+    protected $rfName = null;
11
+    protected $thumbsCache = null;
12 12
 
13 13
     public function __construct($modx, $debug = false) {
14 14
         parent::__construct($modx, $debug);
Please login to merge, or discard this patch.
assets/lib/Helpers/Video.php 1 patch
Indentation   +381 added lines, -381 removed lines patch added patch discarded remove patch
@@ -13,385 +13,385 @@
 block discarded – undo
13 13
  */
14 14
 class Video
15 15
 {
16
-	/** Ссылка на ролик */
17
-	protected $link;
18
-
19
-	/** Распарсенные части ссылки */
20
-	protected $link_parts;
21
-
22
-	/** Видеохостинг */
23
-	protected $hosting;
24
-
25
-	/** Идентификатор видео */
26
-	protected $id;
27
-
28
-	/** Картинка */
29
-	protected $image;
30
-
31
-	/** Название видео */
32
-	protected $title;
33
-
34
-	/** Видео */
35
-	protected $video;
36
-
37
-	protected $width = 420;
38
-	protected $height = 315;
39
-	protected $autoplay = false;
40
-
41
-	public $scheme = 'https';
42
-
43
-	const YOUTUBE = 'youtube';
44
-	const VIMEO   = 'vimeo';
45
-	const RUTUBE  = 'rutube';
46
-
47
-	/** Регулярки для определения видеохостинга и идентификатора ролика */
48
-	protected $regexp = array(
49
-		self::YOUTUBE => array( //Не используются
50
-			'/[http|https]+:\/\/(?:www\.|)youtube\.com\/watch\?(?:.*)?v=([a-zA-Z0-9_\-]+)/i',
51
-			'/[http|https]+:\/\/(?:www\.|)youtube\.com\/embed\/([a-zA-Z0-9_\-]+)/i',
52
-			'/[http|https]+:\/\/(?:www\.|)youtu\.be\/([a-zA-Z0-9_\-]+)/i'
53
-		),
54
-		self::VIMEO   => array( //Не используются
55
-			'/[http|https]+:\/\/(?:www\.|)vimeo\.com\/([a-zA-Z0-9_\-]+)(&.+)?/i',
56
-			'/[http|https]+:\/\/player\.vimeo\.com\/video\/([a-zA-Z0-9_\-]+)(&.+)?/i'
57
-		),
58
-		self::RUTUBE  => array(
59
-			'/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/embed\/([a-zA-Z0-9_\-]+)/i',
60
-			'/[http|https]+:\/\/(?:www\.|)rutube\.ru\/tracks\/([a-zA-Z0-9_\-]+)(&.+)?/i'
61
-		)
62
-	);
63
-
64
-	/** Ссылка на RUtube без идентификатора в адресе */
65
-	protected $regexp_rutube_extra = '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/([a-zA-Z0-9_\-]+)\//i';
66
-
67
-	/** Варианты ссылок, которые поддерживаются */
68
-	protected static $test = array(
69
-		'http://youtube.com/watch?v=ShPq2Dmy6X8',
70
-		'http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be',
71
-		'http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel',
72
-		'www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub',
73
-		'http://www.youtube.com/embed/ShPq2Dmy6X8?rel=0',
74
-		'http://youtu.be/ShPq2Dmy6X8',
75
-		'youtu.be/6dwqZw0j_jY',
76
-		'http://www.youtu.be/afa-5HQHiAs',
77
-
78
-		'vimeo.com/55028438',
79
-		'http://player.vimeo.com/video/55028438?title=0&byline=0&portrait=0&badge=0&color=e1a931',
80
-
81
-		'http://rutube.ru/video/6fd81c1c212c002673280850a1c56415/#.UMQYln9yTWQ',
82
-		'http://rutube.ru/video/dec0a58c8cb4d226abc7b1030bbb63b9/?ref=top',
83
-		'rutube.ru/tracks/6032725.html',
84
-		'http://www.rutube.ru/video/embed/6032725',
85
-	);
86
-
87
-	protected $info = false;
88
-
89
-	/**
90
-	 * @param $link      ссылка на видео
91
-	 * @param $autostart сразу определить превью и клип
92
-	 */
93
-	public function __construct($link = null, $autostart = true, $info = false)
94
-	{
95
-		if ($link) {
96
-			$this->setLink($link);
97
-			$this->setInfo($info);
98
-			if ($autostart) {
99
-				$this->process();
100
-			}
101
-		}
102
-	}
103
-	public function getScheme(){
104
-		switch($this->scheme){
105
-			case 'http':{
106
-				$out = 'http://';
107
-				break;
108
-			}
109
-			case 'https':{
110
-				$out = 'https://';
111
-				break;
112
-			}
113
-			default:{
114
-			$out = '//';
115
-			break;
116
-			}
117
-		}
118
-
119
-		return $out;
120
-	}
121
-	public function setInfo($info){
122
-		$this->info = (bool)$info;
123
-	}
124
-	public function getInfo(){
125
-		return $this->info;
126
-	}
127
-	/** Видеохостинг */
128
-	public function getHosting()
129
-	{
130
-		return $this->hosting;
131
-	}
132
-
133
-	/** Идентификатор видео */
134
-	public function getId()
135
-	{
136
-		return $this->id;
137
-	}
138
-
139
-	/** Ссылка на превью */
140
-	public function getImage()
141
-	{
142
-		return $this->getScheme().$this->image;
143
-	}
144
-
145
-	/** Ссылка на видео */
146
-	public function getVideo($autoplay = false)
147
-	{
148
-		$url = $this->video;
149
-		if($autoplay){
150
-			$url .= '&autoplay=1';
151
-		}
152
-
153
-		return $this->getScheme().$url;
154
-	}
155
-
156
-	/** Название видео */
157
-	public function getTitle()
158
-	{
159
-		return $this->title;
160
-	}
161
-
162
-	/** Задать ссылку на видео */
163
-	public function setLink($link)
164
-	{
165
-		$this->link = $link;
166
-
167
-		return $this;
168
-	}
169
-
170
-	/** Обработка ссылки. Возвращает идентификатор видеохостинга или false */
171
-	public function process($link = null, $info = null)
172
-	{
173
-		if(!empty($link)) $this->setLink($link);
174
-		if(!empty($info)) $this->setInfo($info);
175
-
176
-		if ($this->cleanLink()) {
177
-			if ($this->maybeYoutube()) {
178
-				return self::YOUTUBE;
179
-			}
180
-
181
-			if ($this->maybeVimeo()) {
182
-				return self::VIMEO;
183
-			}
184
-
185
-			if ($this->maybeRutube()) {
186
-				return self::RUTUBE;
187
-			}
188
-		}
189
-
190
-		return false;
191
-	}
192
-
193
-	/** Скачать превью. Если не указать имя файла для записи - функция вернет содержимое файла */
194
-	public function fetchImage($filename = null)
195
-	{
196
-		if (!$url = $this->getImage()) {
197
-			return false;
198
-		}
199
-
200
-		if (!$res = $this->fetchPage($url)) {
201
-			return false;
202
-		}
203
-
204
-		return $filename
205
-			? file_put_contents($filename, $res)
206
-			: $res;
207
-	}
208
-
209
-	/** Проверка и подготовка ссылки и частей */
210
-	protected function cleanLink()
211
-	{
212
-		if (!preg_match('/^(http|https)\:\/\//i', $this->link)) {
213
-			$this->link = 'http://' . $this->link;
214
-		}
215
-
216
-		if (!$this->link_parts = parse_url($this->link)) {
217
-			return false;
218
-		}
219
-
220
-		return true;
221
-	}
222
-
223
-	/** Проверка YOUTUBE */
224
-	protected function maybeYoutube()
225
-	{
226
-		$h = str_replace('www.', '', $this->link_parts['host']);
227
-		$p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false;
228
-
229
-		if ('youtube.com' == $h) {
230
-			parse_str($this->link_parts['query'], $q);
231
-
232
-			if ('/watch' == $p && !empty($q['v'])) {
233
-				return $this->foundYoutube($q['v']);
234
-			}
235
-			if (0 === strpos($p, '/embed/')) {
236
-				return $this->foundYoutube(str_replace('/embed/', '', $p));
237
-			}
238
-		} elseif ('youtu.be' == $h) {
239
-			return $this->foundYoutube(trim($p, '/'));
240
-		}
241
-
242
-		return false;
243
-	}
244
-
245
-	/** Проверка VIMEO */
246
-	protected function maybeVimeo()
247
-	{
248
-		$h = str_replace('www.', '', $this->link_parts['host']);
249
-		$p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false;
250
-
251
-		if ('vimeo.com' == $h) {
252
-			return $this->foundVimeo(trim($p, '/'));
253
-		} elseif ('player.vimeo.com' == $h && 0 === strpos($p, '/video/')) {
254
-			return $this->foundVimeo(str_replace('/video/', '', $p));
255
-		}
256
-
257
-		return false;
258
-	}
259
-
260
-	/** Проверка RUTUBE */
261
-	protected function maybeRutube($html = null)
262
-	{
263
-		$link = $html ?: $this->link;
264
-
265
-		foreach ($this->regexp[self::RUTUBE] as $regexp) {
266
-			if (preg_match($regexp, $link, $matches)) {
267
-				return $this->foundRutube($matches[1]);
268
-			}
269
-		}
270
-
271
-		// Проверка на особенную ссылку RUtube`a
272
-		if (is_null($html) && preg_match($this->regexp_rutube_extra, $this->link, $matches)) {
273
-			$html = $this->fetchPage($matches[0]);
274
-			if ($r = $this->maybeRutube($html)) {
275
-				return $r;
276
-			}
277
-		}
278
-
279
-		return false;
280
-	}
281
-
282
-	/** Обработка YOUTUBE */
283
-	protected function foundYoutube($id)
284
-	{
285
-		if (empty($id) || strlen($id) != 11) {
286
-			return false;
287
-		}
288
-
289
-		$this->hosting = self::YOUTUBE;
290
-		$this->id = $id;
291
-		$this->image = 'img.youtube.com/vi/' . $id . '/0.jpg';
292
-		/** @see https://developers.google.com/youtube/player_parameters */
293
-		$this->video = 'www.youtube.com/embed/' . $id.'?showinfo=0&modestbranding=1&rel=0';
294
-
295
-		if ($this->info) {
296
-			$this->getYoutubeInfo($id);
297
-		}
298
-		return true;
299
-	}
300
-
301
-	/** Обработка VIMEO */
302
-	protected function foundVimeo($id)
303
-	{
304
-		if (empty($id) || !is_numeric($id)) {
305
-			return false;
306
-		}
307
-
308
-		$this->hosting = self::VIMEO;
309
-		$this->id      = $id;
310
-		$this->video   = 'player.vimeo.com/video/' . $id.'?';
311
-
312
-		if($this->info) {
313
-			$this->getVimeoInfo($id);
314
-		}
315
-		return true;
316
-	}
317
-
318
-	/** Обработка RUTUBE */
319
-	protected function foundRutube($id)
320
-	{
321
-		$this->hosting = self::RUTUBE;
322
-		$this->id      = $id;
323
-		$this->video   = 'rutube.ru/video/embed/' . $id.'?';
324
-
325
-		if($this->info) {
326
-			$this->getRutubeInfo($id);
327
-		}
328
-		return true;
329
-	}
330
-
331
-	/** Парсинг XML от RUTUBE и определение превьюхи */
332
-	protected function getRutubeInfo($id)
333
-	{
334
-		if (@$xml = simplexml_load_file("http://rutube.ru/cgi-bin/xmlapi.cgi?rt_mode=movie&rt_movie_id=" . $id . "&utf=1")) {
335
-			$this->title = (string)$xml->title;
336
-			$this->image = (string)$xml->thumbnail_url;
337
-		}
338
-	}
339
-
340
-	/** Парсинг XML от VIMEO и определение превьюхи */
341
-	protected function getVimeoInfo($id)
342
-	{
343
-		if (@$xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $id . '.xml')) {
344
-			$this->title = (string)$xml->video->title;
345
-			$this->image = (string)$xml->video->thumbnail_large ? : $xml->video->thumbnail_medium;
346
-		}
347
-	}
348
-
349
-	/** Получение названия ролика */
350
-	protected function getYoutubeInfo($id)
351
-	{
352
-		if (@$xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/' . $id)) {
353
-			$this->title = (string)$xml->title;
354
-		}
355
-	}
356
-
357
-	/** Скачивание страницы с помощью CURL */
358
-	protected function fetchPage($url)
359
-	{
360
-		$ch = curl_init();
361
-		curl_setopt($ch, CURLOPT_URL, $url);
362
-		curl_setopt($ch, CURLOPT_FAILONERROR, true);
363
-		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
364
-		curl_setopt($ch, CURLOPT_TIMEOUT, 3);
365
-
366
-		return curl_exec($ch);
367
-	}
368
-
369
-	public function getEmbed($options){
370
-		$autoplay = isset($options["autoplay"]) ? $options["autoplay"] : $this->autoplay;
371
-		$width = isset($options["width"]) ? (int)$options["width"] : $this->width;
372
-		$height = isset($options["height"]) ? (int)$options["height"] : $this->height;
373
-		$class = isset($options['class']) ? $options['class'] : '';
374
-
375
-		$url = $this->getVideo($autoplay);
376
-		if(!empty($class)){
377
-			$class = ' class="'.$class.'"';
378
-		}
379
-		return '<iframe src="'.$url.'" width="'.$width.'" height="'.$height.'" frameborder="0" allowfullscreen'.$class.'></iframe>';
380
-	}
381
-	/** Прогоняем тест по видам URL */
382
-	public static function RunTest($links = null)
383
-	{
384
-		if (!is_array($links)) {
385
-			$links = static::$test;
386
-		}
387
-
388
-		foreach ($links as $link) {
389
-			$v = new static($link);
390
-			echo "<h1>$link</h1>\n"
391
-				. "<h3>" . $v->getHosting() . "</h3>"
392
-				. "<b>Видео:</b> " . $v->getVideo() . "<br />\n"
393
-				. "<b>Название:</b> " . $v->getTitle() . "<br />\n"
394
-				. "<b>Картинка:</b> " . $v->getImage() . "<hr />\n";
395
-		}
396
-	}
16
+    /** Ссылка на ролик */
17
+    protected $link;
18
+
19
+    /** Распарсенные части ссылки */
20
+    protected $link_parts;
21
+
22
+    /** Видеохостинг */
23
+    protected $hosting;
24
+
25
+    /** Идентификатор видео */
26
+    protected $id;
27
+
28
+    /** Картинка */
29
+    protected $image;
30
+
31
+    /** Название видео */
32
+    protected $title;
33
+
34
+    /** Видео */
35
+    protected $video;
36
+
37
+    protected $width = 420;
38
+    protected $height = 315;
39
+    protected $autoplay = false;
40
+
41
+    public $scheme = 'https';
42
+
43
+    const YOUTUBE = 'youtube';
44
+    const VIMEO   = 'vimeo';
45
+    const RUTUBE  = 'rutube';
46
+
47
+    /** Регулярки для определения видеохостинга и идентификатора ролика */
48
+    protected $regexp = array(
49
+        self::YOUTUBE => array( //Не используются
50
+            '/[http|https]+:\/\/(?:www\.|)youtube\.com\/watch\?(?:.*)?v=([a-zA-Z0-9_\-]+)/i',
51
+            '/[http|https]+:\/\/(?:www\.|)youtube\.com\/embed\/([a-zA-Z0-9_\-]+)/i',
52
+            '/[http|https]+:\/\/(?:www\.|)youtu\.be\/([a-zA-Z0-9_\-]+)/i'
53
+        ),
54
+        self::VIMEO   => array( //Не используются
55
+            '/[http|https]+:\/\/(?:www\.|)vimeo\.com\/([a-zA-Z0-9_\-]+)(&.+)?/i',
56
+            '/[http|https]+:\/\/player\.vimeo\.com\/video\/([a-zA-Z0-9_\-]+)(&.+)?/i'
57
+        ),
58
+        self::RUTUBE  => array(
59
+            '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/embed\/([a-zA-Z0-9_\-]+)/i',
60
+            '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/tracks\/([a-zA-Z0-9_\-]+)(&.+)?/i'
61
+        )
62
+    );
63
+
64
+    /** Ссылка на RUtube без идентификатора в адресе */
65
+    protected $regexp_rutube_extra = '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/([a-zA-Z0-9_\-]+)\//i';
66
+
67
+    /** Варианты ссылок, которые поддерживаются */
68
+    protected static $test = array(
69
+        'http://youtube.com/watch?v=ShPq2Dmy6X8',
70
+        'http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be',
71
+        'http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel',
72
+        'www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub',
73
+        'http://www.youtube.com/embed/ShPq2Dmy6X8?rel=0',
74
+        'http://youtu.be/ShPq2Dmy6X8',
75
+        'youtu.be/6dwqZw0j_jY',
76
+        'http://www.youtu.be/afa-5HQHiAs',
77
+
78
+        'vimeo.com/55028438',
79
+        'http://player.vimeo.com/video/55028438?title=0&byline=0&portrait=0&badge=0&color=e1a931',
80
+
81
+        'http://rutube.ru/video/6fd81c1c212c002673280850a1c56415/#.UMQYln9yTWQ',
82
+        'http://rutube.ru/video/dec0a58c8cb4d226abc7b1030bbb63b9/?ref=top',
83
+        'rutube.ru/tracks/6032725.html',
84
+        'http://www.rutube.ru/video/embed/6032725',
85
+    );
86
+
87
+    protected $info = false;
88
+
89
+    /**
90
+     * @param $link      ссылка на видео
91
+     * @param $autostart сразу определить превью и клип
92
+     */
93
+    public function __construct($link = null, $autostart = true, $info = false)
94
+    {
95
+        if ($link) {
96
+            $this->setLink($link);
97
+            $this->setInfo($info);
98
+            if ($autostart) {
99
+                $this->process();
100
+            }
101
+        }
102
+    }
103
+    public function getScheme(){
104
+        switch($this->scheme){
105
+            case 'http':{
106
+                $out = 'http://';
107
+                break;
108
+            }
109
+            case 'https':{
110
+                $out = 'https://';
111
+                break;
112
+            }
113
+            default:{
114
+            $out = '//';
115
+            break;
116
+            }
117
+        }
118
+
119
+        return $out;
120
+    }
121
+    public function setInfo($info){
122
+        $this->info = (bool)$info;
123
+    }
124
+    public function getInfo(){
125
+        return $this->info;
126
+    }
127
+    /** Видеохостинг */
128
+    public function getHosting()
129
+    {
130
+        return $this->hosting;
131
+    }
132
+
133
+    /** Идентификатор видео */
134
+    public function getId()
135
+    {
136
+        return $this->id;
137
+    }
138
+
139
+    /** Ссылка на превью */
140
+    public function getImage()
141
+    {
142
+        return $this->getScheme().$this->image;
143
+    }
144
+
145
+    /** Ссылка на видео */
146
+    public function getVideo($autoplay = false)
147
+    {
148
+        $url = $this->video;
149
+        if($autoplay){
150
+            $url .= '&autoplay=1';
151
+        }
152
+
153
+        return $this->getScheme().$url;
154
+    }
155
+
156
+    /** Название видео */
157
+    public function getTitle()
158
+    {
159
+        return $this->title;
160
+    }
161
+
162
+    /** Задать ссылку на видео */
163
+    public function setLink($link)
164
+    {
165
+        $this->link = $link;
166
+
167
+        return $this;
168
+    }
169
+
170
+    /** Обработка ссылки. Возвращает идентификатор видеохостинга или false */
171
+    public function process($link = null, $info = null)
172
+    {
173
+        if(!empty($link)) $this->setLink($link);
174
+        if(!empty($info)) $this->setInfo($info);
175
+
176
+        if ($this->cleanLink()) {
177
+            if ($this->maybeYoutube()) {
178
+                return self::YOUTUBE;
179
+            }
180
+
181
+            if ($this->maybeVimeo()) {
182
+                return self::VIMEO;
183
+            }
184
+
185
+            if ($this->maybeRutube()) {
186
+                return self::RUTUBE;
187
+            }
188
+        }
189
+
190
+        return false;
191
+    }
192
+
193
+    /** Скачать превью. Если не указать имя файла для записи - функция вернет содержимое файла */
194
+    public function fetchImage($filename = null)
195
+    {
196
+        if (!$url = $this->getImage()) {
197
+            return false;
198
+        }
199
+
200
+        if (!$res = $this->fetchPage($url)) {
201
+            return false;
202
+        }
203
+
204
+        return $filename
205
+            ? file_put_contents($filename, $res)
206
+            : $res;
207
+    }
208
+
209
+    /** Проверка и подготовка ссылки и частей */
210
+    protected function cleanLink()
211
+    {
212
+        if (!preg_match('/^(http|https)\:\/\//i', $this->link)) {
213
+            $this->link = 'http://' . $this->link;
214
+        }
215
+
216
+        if (!$this->link_parts = parse_url($this->link)) {
217
+            return false;
218
+        }
219
+
220
+        return true;
221
+    }
222
+
223
+    /** Проверка YOUTUBE */
224
+    protected function maybeYoutube()
225
+    {
226
+        $h = str_replace('www.', '', $this->link_parts['host']);
227
+        $p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false;
228
+
229
+        if ('youtube.com' == $h) {
230
+            parse_str($this->link_parts['query'], $q);
231
+
232
+            if ('/watch' == $p && !empty($q['v'])) {
233
+                return $this->foundYoutube($q['v']);
234
+            }
235
+            if (0 === strpos($p, '/embed/')) {
236
+                return $this->foundYoutube(str_replace('/embed/', '', $p));
237
+            }
238
+        } elseif ('youtu.be' == $h) {
239
+            return $this->foundYoutube(trim($p, '/'));
240
+        }
241
+
242
+        return false;
243
+    }
244
+
245
+    /** Проверка VIMEO */
246
+    protected function maybeVimeo()
247
+    {
248
+        $h = str_replace('www.', '', $this->link_parts['host']);
249
+        $p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false;
250
+
251
+        if ('vimeo.com' == $h) {
252
+            return $this->foundVimeo(trim($p, '/'));
253
+        } elseif ('player.vimeo.com' == $h && 0 === strpos($p, '/video/')) {
254
+            return $this->foundVimeo(str_replace('/video/', '', $p));
255
+        }
256
+
257
+        return false;
258
+    }
259
+
260
+    /** Проверка RUTUBE */
261
+    protected function maybeRutube($html = null)
262
+    {
263
+        $link = $html ?: $this->link;
264
+
265
+        foreach ($this->regexp[self::RUTUBE] as $regexp) {
266
+            if (preg_match($regexp, $link, $matches)) {
267
+                return $this->foundRutube($matches[1]);
268
+            }
269
+        }
270
+
271
+        // Проверка на особенную ссылку RUtube`a
272
+        if (is_null($html) && preg_match($this->regexp_rutube_extra, $this->link, $matches)) {
273
+            $html = $this->fetchPage($matches[0]);
274
+            if ($r = $this->maybeRutube($html)) {
275
+                return $r;
276
+            }
277
+        }
278
+
279
+        return false;
280
+    }
281
+
282
+    /** Обработка YOUTUBE */
283
+    protected function foundYoutube($id)
284
+    {
285
+        if (empty($id) || strlen($id) != 11) {
286
+            return false;
287
+        }
288
+
289
+        $this->hosting = self::YOUTUBE;
290
+        $this->id = $id;
291
+        $this->image = 'img.youtube.com/vi/' . $id . '/0.jpg';
292
+        /** @see https://developers.google.com/youtube/player_parameters */
293
+        $this->video = 'www.youtube.com/embed/' . $id.'?showinfo=0&modestbranding=1&rel=0';
294
+
295
+        if ($this->info) {
296
+            $this->getYoutubeInfo($id);
297
+        }
298
+        return true;
299
+    }
300
+
301
+    /** Обработка VIMEO */
302
+    protected function foundVimeo($id)
303
+    {
304
+        if (empty($id) || !is_numeric($id)) {
305
+            return false;
306
+        }
307
+
308
+        $this->hosting = self::VIMEO;
309
+        $this->id      = $id;
310
+        $this->video   = 'player.vimeo.com/video/' . $id.'?';
311
+
312
+        if($this->info) {
313
+            $this->getVimeoInfo($id);
314
+        }
315
+        return true;
316
+    }
317
+
318
+    /** Обработка RUTUBE */
319
+    protected function foundRutube($id)
320
+    {
321
+        $this->hosting = self::RUTUBE;
322
+        $this->id      = $id;
323
+        $this->video   = 'rutube.ru/video/embed/' . $id.'?';
324
+
325
+        if($this->info) {
326
+            $this->getRutubeInfo($id);
327
+        }
328
+        return true;
329
+    }
330
+
331
+    /** Парсинг XML от RUTUBE и определение превьюхи */
332
+    protected function getRutubeInfo($id)
333
+    {
334
+        if (@$xml = simplexml_load_file("http://rutube.ru/cgi-bin/xmlapi.cgi?rt_mode=movie&rt_movie_id=" . $id . "&utf=1")) {
335
+            $this->title = (string)$xml->title;
336
+            $this->image = (string)$xml->thumbnail_url;
337
+        }
338
+    }
339
+
340
+    /** Парсинг XML от VIMEO и определение превьюхи */
341
+    protected function getVimeoInfo($id)
342
+    {
343
+        if (@$xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $id . '.xml')) {
344
+            $this->title = (string)$xml->video->title;
345
+            $this->image = (string)$xml->video->thumbnail_large ? : $xml->video->thumbnail_medium;
346
+        }
347
+    }
348
+
349
+    /** Получение названия ролика */
350
+    protected function getYoutubeInfo($id)
351
+    {
352
+        if (@$xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/' . $id)) {
353
+            $this->title = (string)$xml->title;
354
+        }
355
+    }
356
+
357
+    /** Скачивание страницы с помощью CURL */
358
+    protected function fetchPage($url)
359
+    {
360
+        $ch = curl_init();
361
+        curl_setopt($ch, CURLOPT_URL, $url);
362
+        curl_setopt($ch, CURLOPT_FAILONERROR, true);
363
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
364
+        curl_setopt($ch, CURLOPT_TIMEOUT, 3);
365
+
366
+        return curl_exec($ch);
367
+    }
368
+
369
+    public function getEmbed($options){
370
+        $autoplay = isset($options["autoplay"]) ? $options["autoplay"] : $this->autoplay;
371
+        $width = isset($options["width"]) ? (int)$options["width"] : $this->width;
372
+        $height = isset($options["height"]) ? (int)$options["height"] : $this->height;
373
+        $class = isset($options['class']) ? $options['class'] : '';
374
+
375
+        $url = $this->getVideo($autoplay);
376
+        if(!empty($class)){
377
+            $class = ' class="'.$class.'"';
378
+        }
379
+        return '<iframe src="'.$url.'" width="'.$width.'" height="'.$height.'" frameborder="0" allowfullscreen'.$class.'></iframe>';
380
+    }
381
+    /** Прогоняем тест по видам URL */
382
+    public static function RunTest($links = null)
383
+    {
384
+        if (!is_array($links)) {
385
+            $links = static::$test;
386
+        }
387
+
388
+        foreach ($links as $link) {
389
+            $v = new static($link);
390
+            echo "<h1>$link</h1>\n"
391
+                . "<h3>" . $v->getHosting() . "</h3>"
392
+                . "<b>Видео:</b> " . $v->getVideo() . "<br />\n"
393
+                . "<b>Название:</b> " . $v->getTitle() . "<br />\n"
394
+                . "<b>Картинка:</b> " . $v->getImage() . "<hr />\n";
395
+        }
396
+    }
397 397
 }
398 398
\ No newline at end of file
Please login to merge, or discard this patch.
assets/modules/redirectMap2/src/Action.class.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 class Action extends \Module\Action
4 4
 {
5
-	protected static $TABLE = "redirect_map";
5
+    protected static $TABLE = "redirect_map";
6 6
 
7 7
     public static function checkPageID($uri, $page, $active = 1)
8 8
     {
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
         $json = $log = $stat = array();
148 148
         self::$TPL = 'ajax/getValue';
149 149
         $file = Template::getParam('filedata', $_FILES);
150
-		$name = explode(".", Template::getParam('name', $file));
150
+        $name = explode(".", Template::getParam('name', $file));
151 151
         $name = strtolower(end($name));
152 152
 
153 153
         switch ($name) {
Please login to merge, or discard this patch.