Passed
Branch master (249862)
by Adam
07:51
created

Helpers.php ➔ plain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Removes all html tags
5
 *
6
 * @param string $value
7
 * @return string
8
 */
9
function plain($value)
10
{
11
    return html_entity_decode(strip_tags($value));
12
}
13
14
/**
15
 * @param $value
16
 * @param int $limit
17
 * @return string
18
 */
19
function excerpt($value, $limit = 84)
20
{
21
    $value = str_replace(["\n", "\t", "\r"], ' ', plain($value));
22
    $value = trim(preg_replace('/ {2,}/', ' ', $value));
23
24
    return str_limit($value, $limit);
25
}
26
27
/**
28
 * Zwraca tablice najczesciej wykorzystywanych slow kluczowych w tekscie
29
 *
30
 * @param string $text
31
 * @param int $limit Limit slow kluczowych
32
 * @return array
33
 */
34
function keywords($text, $limit = 10)
35
{
36
    $text = preg_replace('/[^a-zA-Z0-9 -]/', '', mb_strtolower(plain($text), 'UTF-8'));
37
    $keywords = [];
38
39
    foreach (explode(' ', $text) as $word) {
40
        if (mb_strlen($word, 'UTF-8') >= 3) {
41
            $keywords[] = $word;
42
        }
43
    }
44
45
    $keywords = array_count_values($keywords);
46
    arsort($keywords);
47
48
    $keywords = array_keys($keywords);
49
50
    if ($limit) {
51
        $keywords = array_slice($keywords, 0, $limit);
52
    }
53
54
    return $keywords;
55
}
56
57
/**
58
 * @param \Coyote\Services\Stream\Activities\Activity|string $activity
59
 * @param \Coyote\Services\Stream\Objects\ObjectInterface|null $object
60
 * @param \Coyote\Services\Stream\Objects\ObjectInterface|null $target
61
 */
62
function stream($activity, $object = null, $target = null)
63
{
64
    $manager = app(\Coyote\Services\Stream\Manager::class);
65
66
    return $manager->save($activity, $object, $target);
67
}
68
69
/**
70
 * Creates CDN assets url
71
 *
72
 * @param string $path
73
 * @param null|bool $secure
74
 * @return string
75
 */
76
function cdn($path, $secure = null)
77
{
78
    if (!config('app.cdn')) {
79
        return asset($path, $secure);
80
    }
81
82
    $path = trim($path, '/');
83
    if (in_array(pathinfo($path, PATHINFO_EXTENSION), ['css', 'js'])) {
84
        $path = elixir($path);
85
    }
86
87
    return ($secure ? 'https:' : '') . '//' . config('app.cdn') . ($path[0] !== '/' ? ('/' . $path) : $path);
88
}
89
90
/**
91
 * Uppercase first character of each word
92
 *
93
 * @param $string
94
 * @return string
95
 */
96
function capitalize($string)
97
{
98
    return mb_convert_case($string, MB_CASE_TITLE, 'UTF-8');
99
}
100