1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/yiimaker/yii2-helpers |
4
|
|
|
* @copyright Copyright (c) 2017 Yii Maker |
5
|
|
|
* @license BSD 3-Clause License |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace ymaker\helpers; |
9
|
|
|
|
10
|
|
|
use yii\helpers\BaseHtml; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Extended default Html helper. |
14
|
|
|
* |
15
|
|
|
* @author Vladimir Kuprienko <[email protected]> |
16
|
|
|
* @since 1.0 |
17
|
|
|
*/ |
18
|
|
|
class Html extends BaseHtml |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* This class should not be instantiated. |
22
|
|
|
*/ |
23
|
|
|
private function __construct() |
24
|
|
|
{ |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Generates a callto hyperlink. |
29
|
|
|
* |
30
|
|
|
* @see mailto() |
31
|
|
|
* |
32
|
|
|
* @param string $phone |
33
|
|
|
* @param null|string $text |
34
|
|
|
* @param array $options |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public static function callTo($phone, $text = null, $options = []) |
39
|
|
|
{ |
40
|
|
|
$options['href'] = 'tel:' . preg_replace('/(\s|-)+/', '', $phone); |
41
|
|
|
$text = (null === $text) ? $phone : $text; |
42
|
|
|
|
43
|
|
|
return static::tag('a', $text, $options); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Generates safe hyperlink to external resource. |
48
|
|
|
* |
49
|
|
|
* @param string $text |
50
|
|
|
* @param string $url |
51
|
|
|
* @param array $options |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public static function externalLink($text, $url, $options = []) |
56
|
|
|
{ |
57
|
|
|
$options['rel'] = 'noopener'; |
58
|
|
|
$options['target'] = '_blank'; |
59
|
|
|
$options['href'] = $url; |
60
|
|
|
|
61
|
|
|
return static::tag('a', $text, $options); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns HTML wrapped in to `noindex` comment. |
66
|
|
|
* |
67
|
|
|
* @param string $html |
68
|
|
|
* |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public static function wrapToNoIndex($html) |
72
|
|
|
{ |
73
|
|
|
return '<!--noindex-->' . $html . '<!--/noindex-->'; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns HTML wrapped into `<noindex>` tag. |
78
|
|
|
* |
79
|
|
|
* @param string $html |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public static function wrapToNoIndexTag($html) |
84
|
|
|
{ |
85
|
|
|
return '<noindex>' . $html . '</noindex>'; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|