-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli
executable file
·150 lines (128 loc) · 4.29 KB
/
cli
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
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env php
<?php
/**
* This CLI Create a Valentine's Day Greeting Card Webpage Link and ASCII Text art.
* Get a Valentine's Day Greeting with an image page link.
* Create ASCII Valentine's Text art Greeting image.
*
* CLI written by Santhosh MSK, sanweb (https://github.com/sanwebinfo)
* Free Online Valentine's Day Card Maker (https://love.sanweb.info)
*
*/
function to_prety_url($str){
if($str !== mb_convert_encoding( mb_convert_encoding($str, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32') )
$str = mb_convert_encoding($str, 'UTF-8', mb_detect_encoding($str));
$str = htmlentities($str, ENT_NOQUOTES, 'UTF-8');
$str = preg_replace('`&([a-z]{1,2})(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i', '\1', $str);
$str = html_entity_decode($str, ENT_NOQUOTES, 'UTF-8');
$str = preg_replace(array('`[^a-z0-9]`i','`[-]+`'), '-', $str);
$str = strtolower( trim($str, '-') );
return $str;
}
function get_user_input($prompt = null) {
$name = readline($prompt);
return $name;
}
function loadingSpinner($iterations = 30, $delay = 100000) {
$colors = ["\033[36m"];
$chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
$countColors = count($colors);
$countChars = count($chars);
for ($i = 0; $i < $iterations; $i++) {
$color = $colors[$i % $countColors];
$char = $chars[$i % $countChars];
echo "\033[0G";
echo $color . $char . $color . " Generating...." . "\033[0m";
usleep($delay);
}
echo "\033[2K\r";
}
function clearGap() {
echo "\033[1A";
echo "\r\033[K";
}
function clearOutput() {
echo "\033[1F";
echo "\033[K";
}
function copyToClipboard($text) {
$escapedText = escapeshellarg($text);
shell_exec("echo $escapedText | xclip -r -sel clip 1> /dev/null 2> /dev/null");
}
if ($argc > 1) {
if ($argv[1] == 'create') {
$name = get_user_input("Your Partner Name: ");
sleep(1);
clearOutput();
clearGap();
if($name) {
if (isset($name[25])) {
echo "\e[31m\nText is too long. It should be no longer than 25 characters\e[0m \n\n";
} else {
echo "\n";
loadingSpinner();
sleep(1);
clearOutput();
$user = to_prety_url($name);
$url = "https://love.sanweb.info/$user";
echo "\e[32m\nDownload your Greeting at:\e[0m \e[33m$url\e[0m \n\n";
copyToClipboard($url);
}
} else {
echo "\e[31m\nEmpty Data \e[0m \n\n";
}
}
elseif($argv[1] == 'greeting') {
$name = get_user_input("Your Partner Name: ");
sleep(1);
clearOutput();
clearGap();
if($name) {
if (isset($name[25])) {
echo "\e[31m\nText is too long. It should be no longer than 25 characters\e[0m \n\n";
} else {
echo "\n";
loadingSpinner();
sleep(1);
clearOutput();
$user = to_prety_url($name);
$greeting = "
\e[32m$name@:~/💑 $\e[0m
\e[91m
||
___\||
____\| %%% %%%
\ % % % %
\% % % %
%\ % % %
% \ % %
% \ %
% \ BE MY %
% \ %
% VALENTINE %
% \ %
% \ %
% \ %
% \ %
% \ %
% %\
% % \ ||
% __\||
___\|
\e[0m";
echo $greeting;
}
} else {
echo "\e[31m\nEmpty Data \e[0m \n\n";
}
} elseif($argv[1] == 'help') {
echo "\e[94m Valentine's Day Greetings
php cli create : Get a Valentine's Day Greeting with an image page link.
php cli greeting : Create ASCII Valentine's Text art Greeting image
php ci help : Get information related to CLI\e[0m \n\n";
} elseif(!empty($argv[1])) {
echo "\e[31mCommand not Found\n \e[0m \n";
}
} else {
echo "\e[31mEmpty data Was Passed\n \e[0m \n";
}