Completed
Push — master ( 32bab2...1c8a4d )
by Seong
01:40
created

DiscussHelper.php ➔ processThreadBody()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
if (!function_exists('limitText')) {
4
5
    function limitText($text, $size = 200)
6
    {
7
        if (strlen($text) > $size)
8
            return substr($text, 0, $size) . '...';
9
        else
10
            return $text;
11
    }
12
}
13
14
if (!function_exists('getUserImage')) {
15
16
    function getUserImage($user, $imageField, $imagePath, $defaultImage)
17
    {
18
        if ($imageField == "")
19
            return  $defaultImage;
20
        else
21
            return $imagePath.$user->$imageField;
22
    }
23
}
24
25
if (!function_exists('getYoutubeEmbedUrl')) {
26
27
    function getYoutubeEmbedUrl($url)
28
    {
29
        return preg_replace(
30
            "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
31
            "<div style='position: relative;padding-bottom: 56.25%;padding-top: 25px;height: 0;'><iframe src=\"//www.youtube.com/embed/$2\" allowfullscreen style='position: absolute;top: 0;left: 0;width: 100%;height: 100%;'></iframe></div>",
32
            $url
33
        );
34
    }
35
}
36
37
if (!function_exists('processThreadBody')) {
38
39
    function processThreadBody($string)
40
    {
41
        if (strpos($string, 'youtube.com'))
42
            $string = preg_replace(
43
                "/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i",
44
                "<div style='position: relative;padding-bottom: 56.25%;padding-top: 25px;height: 0;'><iframe src=\"//www.youtube.com/embed/$2\" allowfullscreen style='position: absolute;top: 0;left: 0;width: 100%;height: 100%;'></iframe></div>",
45
                $string
46
            );
47
48
        return nl2br($string);
49
    }
50
}
51
52
53