-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.php
45 lines (30 loc) · 958 Bytes
/
Message.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
<?php
require_once 'GetRandomText.php';
class Message {
public $text;
function __construct($file_path, $reply_to) {
$MPTextFile = $file_path; //need to be absolute path for cron to work
$MPSepString = ".";
$MPTextToHTML = true;
$output = MPPrintRandomText($MPTextFile, $MPSepString, $MPTextToHTML);
$cleaned_text = preg_replace("/&#?[a-z0-9]+;/i","", $output);
$cleaned_with_mention = $reply_to . $cleaned_text;
$this->text .= checkLength($cleaned_with_mention);
$this->text .= '. #epistle'; //add a hashtag
}
}
function checkLength($text) {
if (strlen($text) <= 136) {
return $text;
} else {
// compute how far over the text length is, leaving room for the hashtag
$strdiff = (140 - strlen($text)) - 9;
$newtext = substr($text, 0, $strdiff);
//takes off the last bit up to a space
$parts = explode(" ", $newtext);
$removed = array_pop($parts);
$newtext = implode(" ", $parts);
return $newtext;
}
}
?>