-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc.php
140 lines (101 loc) · 4.88 KB
/
func.php
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
<?php
function generateSlug($string) {
// Remove any special characters except alphanumeric, spaces, and dashes
$string = preg_replace('/[^a-zA-Z0-9\s-]/', '', $string);
// Replace multiple spaces with a single space
$string = preg_replace('/\s+/', ' ', $string);
// Trim spaces from the beginning and end of the string
$string = trim($string);
// Convert spaces to dashes
$string = str_replace(' ', '-', $string);
// Convert the string to lowercase
$slug = strtolower($string);
return $slug;
}
function youtubeLikeDescription($text) {
// Convert URLs to clickable links
$text = preg_replace('/\b(?:https?|ftp):\/\/\S+\b/', '<a href="$0" target="_blank">$0</a>', $text);
// Markdown support: bold, italic, code blocks, headers, and lists
$text = preg_replace('/(\*\*|__)(.*?)\1/', '<strong>$2</strong>', $text);
$text = preg_replace('/(\*|_)(.*?)\1/', '<em>$2</em>', $text);
$text = preg_replace('/`([^`\n]+)`/', '<code>$1</code>', $text);
// Headers (h1 to h6)
$text = preg_replace('/^#{1,6}\s+(.*?)$/m', '<h$1>$2</h$1>', $text);
// Unordered lists
$text = preg_replace('/^\*\s+(.*?)$/m', '<li>$1</li>', $text);
$text = '<ul>' . preg_replace('/<\/li><li>/', '</li><li>', $text) . '</ul>';
// Ordered lists
$text = preg_replace('/^\d+\.\s+(.*?)$/m', '<li>$1</li>', $text);
$text = '<ol>' . preg_replace('/<\/li><li>/', '</li><li>', $text) . '</ol>';
// Add support for line breaks
$text = nl2br($text);
// Additional Markdown support can be added here as needed
return $text;
}
function convertToRelativeTime($dateString) {
// Convert the date string to a Unix timestamp
$timestamp = strtotime($dateString);
// Get the current timestamp
$now = time();
// Calculate the time difference in seconds
$diff = $now - $timestamp;
// Define time intervals in seconds
$minute = 60;
$hour = 60 * $minute;
$day = 24 * $hour;
$week = 7 * $day;
$month = 30 * $day;
$year = 365 * $day;
// Format the relative time string based on the time difference
if ($diff < $minute) {
return "Just now";
} elseif ($diff < $hour) {
$minutes = floor($diff / $minute);
return $minutes . " minute" . ($minutes > 1 ? "s" : "") . " ago";
} elseif ($diff < $day) {
$hours = floor($diff / $hour);
return $hours . " hour" . ($hours > 1 ? "s" : "") . " ago";
} elseif ($diff < $week) {
$days = floor($diff / $day);
return $days . " day" . ($days > 1 ? "s" : "") . " ago";
} elseif ($diff < $month) {
$weeks = floor($diff / $week);
return $weeks . " week" . ($weeks > 1 ? "s" : "") . " ago";
} elseif ($diff < $year) {
$months = floor($diff / $month);
return $months . " month" . ($months > 1 ? "s" : "") . " ago";
} else {
$years = floor($diff / $year);
return $years . " year" . ($years > 1 ? "s" : "") . " ago";
}
}
function formatViewsCount($views) {
$suffixes = array('', 'k', 'M', 'B', 'T');
$suffixIndex = 0;
while ($views >= 1000 && $suffixIndex < count($suffixes) - 1) {
$views /= 1000;
$suffixIndex++;
}
// Format the views count to have at most one decimal point
$formattedViews = number_format($views, $suffixIndex > 0 ? 1 : 0);
// Append the appropriate suffix
$formattedViews .= $suffixes[$suffixIndex];
return $formattedViews;
}
function getUser($id) {
// Use the $id parameter in the API URL
$api_url = 'https://driveplyr.appspages.online/dashboard/api/user.php?id=' . $id;
// Fetch the API response as a JSON string
return $api_response = json_decode(file_get_contents($api_url));
}
function is_youtube_link($url) {
return preg_match('/youtube\.com\/watch\?/', $url) || preg_match('/youtu\.be\//', $url);
}
function youtube_link_to_embed($url) {
if (is_youtube_link($url)) {
$videoId = explode('v=', $url)[1];
return '<iframe width="100%" height="100%" src="https://www.youtube.com/embed/' . $videoId . '" frameborder="0" allowfullscreen></iframe>';
}
return ''; // Return empty string if it's not a YouTube link
}
?>