2 function get_attached_data($body) {
5 - type: link, video, photo
14 if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism",$body, $attached, PREG_SET_ORDER)) {
15 foreach ($attached AS $data) {
16 if (!in_array($data[1], array("type-link", "type-video", "type-photo")))
19 $post["type"] = substr($data[1], 5);
21 $post["text"] = trim(str_replace($data[0], "", $body));
23 $attacheddata = $data[2];
25 if (preg_match("/\[img\](.*?)\[\/img\]/ism", $attacheddata, $matches))
26 $post["image"] = $matches[1];
28 if (preg_match("/\[bookmark\=(.*?)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) {
29 $post["url"] = $matches[1];
30 $post["title"] = $matches[2];
33 // Search for description
34 if (preg_match("/\[quote\](.*?)\[\/quote\]/ism", $attacheddata, $matches))
35 $post["description"] = $matches[1];
42 function plaintext($a, $b, $limit = 0, $includedlinks = false) {
43 require_once("include/bbcode.php");
44 require_once("include/html2plain.php");
45 require_once("mod/parse_url.php");
46 require_once("include/network.php");
48 // Simplify image codes
49 $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $b["body"]);
51 // At first look at data that is attached via "type-..." stuff
52 // This will hopefully replaced with a dedicated bbcode later
53 $post = get_attached_data($body);
55 // if nothing is found, it maybe having an image.
56 if (!isset($post["type"])) {
57 if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
58 if (count($pictures) == 1) {
59 // Checking, if the link goes to a picture
60 $data = parseurl_getsiteinfo($pictures[0][1], true);
61 if ($data["type"] == "photo") {
62 $post["type"] = "photo";
63 if (isset($data["images"][0]))
64 $post["image"] = $data["images"][0]["src"];
66 $post["image"] = $data["url"];
68 $post["preview"] = $pictures[0][2];
69 $post["text"] = str_replace($pictures[0][0], "", $body);
71 } elseif (count($pictures) > 1) {
72 $post["type"] = "link";
73 $post["url"] = $b["plink"];
74 $post["image"] = $pictures[0][2];
75 $post["text"] = $body;
77 } elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) {
78 if (count($pictures) == 1) {
79 $post["type"] = "photo";
80 $post["image"] = $pictures[0][1];
81 $post["text"] = str_replace($pictures[0][0], "", $body);
82 } elseif (count($pictures) > 1) {
83 $post["type"] = "link";
84 $post["url"] = $b["plink"];
85 $post["image"] = $pictures[0][1];
86 $post["text"] = $body;
89 $post["type"] = "text";
90 $post["text"] = trim($body);
94 if (($b["title"] != "") AND ($post["text"] != ""))
95 $post["text"] = trim($b["title"]."\n\n".$post["text"]);
96 elseif ($b["title"] != "")
97 $post["text"] = trim($b["title"]);
99 $html = bbcode($post["text"], false, false, 2);
100 $msg = html2plain($html, 0, true);
101 $msg = trim(html_entity_decode($msg,ENT_QUOTES,'UTF-8'));
104 if ($includedlinks) {
105 if ($post["type"] == "link")
106 $link = $post["url"];
107 elseif ($post["type"] == "video")
108 $link = $post["url"];
109 elseif ($post["type"] == "photo")
110 $link = $post["image"];
112 if (($msg == "") AND isset($post["title"]))
113 $msg = trim($post["title"]);
115 if (($msg == "") AND isset($post["description"]))
116 $msg = trim($post["description"]);
118 // If the link is already contained in the post, then it neeedn't to be added again
119 // But: if the link is beyond the limit, then it has to be added.
120 if (($link != "") AND strstr($msg, $link)) {
121 $pos = strpos($msg, $link);
122 if (($limit == 0) OR ($pos < $limit))
128 // Reduce multiple spaces
129 // When posted to a network with limited space, we try to gain space where possible
130 while (strpos($msg, " ") !== false)
131 $msg = str_replace(" ", " ", $msg);
133 // Twitter is using its own limiter, so we always assume that shortened links will have this length
134 if (strlen($link) > 0)
135 $limit = $limit - 23;
137 if (strlen($msg) > $limit) {
139 if (!isset($post["url"])) {
140 $limit = $limit - 23;
141 $post["url"] = $b["plink"];
144 $lines = explode("\n", $msg);
146 $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
147 foreach ($lines AS $row=>$line) {
148 if (strlen(trim($msg."\n".$line)) <= $limit)
149 $msg = trim($msg."\n".$line);
150 // Is the new message empty by now or is it a reshared message?
151 elseif (($msg == "") OR (($row == 1) AND (substr($msg, 0, 4) == $recycle)))
152 $msg = substr(substr(trim($msg."\n".$line), 0, $limit), 0, -3)."...";
157 $post["text"] = trim($msg);