2 function get_attached_data($body) {
5 - type: link, video, photo
13 // Simplify image codes
14 $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
18 if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism",$body, $attached, PREG_SET_ORDER)) {
19 foreach ($attached AS $data) {
20 if (!in_array($data[1], array("type-link", "type-video", "type-photo")))
23 $post["type"] = substr($data[1], 5);
25 $post["text"] = trim(str_replace($data[0], "", $body));
27 $attacheddata = $data[2];
29 $URLSearchString = "^\[\]";
31 if (preg_match("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $attacheddata, $matches))
32 $post["image"] = $matches[1];
34 if (preg_match("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) {
35 $post["url"] = $matches[1];
36 $post["title"] = $matches[2];
39 // Search for description
40 if (preg_match("/\[quote\](.*?)\[\/quote\]/ism", $attacheddata, $matches))
41 $post["description"] = $matches[1];
46 // if nothing is found, it maybe having an image.
47 if (!isset($post["type"])) {
48 require_once("mod/parse_url.php");
49 require_once("include/Photo.php");
51 $URLSearchString = "^\[\]";
52 if (preg_match_all("(\[url=([$URLSearchString]*)\]\s*\[img\]([$URLSearchString]*)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
53 if (count($pictures) == 1) {
54 // Checking, if the link goes to a picture
55 $data = parseurl_getsiteinfo($pictures[0][1], true);
56 if ($data["type"] == "photo") {
57 $post["type"] = "photo";
58 if (isset($data["images"][0]))
59 $post["image"] = $data["images"][0]["src"];
61 $post["image"] = $data["url"];
63 $post["preview"] = $pictures[0][2];
64 $post["text"] = str_replace($pictures[0][0], "", $body);
66 $imgdata = get_photo_info($pictures[0][1]);
67 if (substr($imgdata["mime"], 0, 6) == "image/") {
68 $post["type"] = "photo";
69 $post["image"] = $pictures[0][1];
70 $post["preview"] = $pictures[0][2];
71 $post["text"] = str_replace($pictures[0][0], "", $body);
74 } elseif (count($pictures) > 1) {
75 $post["type"] = "link";
76 $post["url"] = $b["plink"];
77 $post["image"] = $pictures[0][2];
78 $post["text"] = $body;
80 } elseif (preg_match_all("(\[img\]([$URLSearchString]*)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) {
81 if (count($pictures) == 1) {
82 $post["type"] = "photo";
83 $post["image"] = $pictures[0][1];
84 $post["text"] = str_replace($pictures[0][0], "", $body);
85 } elseif (count($pictures) > 1) {
86 $post["type"] = "link";
87 $post["url"] = $b["plink"];
88 $post["image"] = $pictures[0][1];
89 $post["text"] = $body;
92 if (!isset($post["type"])) {
93 $post["type"] = "text";
94 $post["text"] = trim($body);
96 } elseif (isset($post["url"]) AND ($post["type"] == "video")) {
97 require_once("mod/parse_url.php");
98 $data = parseurl_getsiteinfo($post["url"], true);
100 if (isset($data["images"][0]))
101 $post["image"] = $data["images"][0]["src"];
107 function shortenmsg($msg, $limit, $twitter = false) {
109 // For Twitter URLs aren't shortened, but they have to be calculated as if.
111 $lines = explode("\n", $msg);
113 $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
114 foreach ($lines AS $row=>$line) {
115 if (iconv_strlen(trim($msg."\n".$line), "UTF-8") <= $limit)
116 $msg = trim($msg."\n".$line);
117 // Is the new message empty by now or is it a reshared message?
118 elseif (($msg == "") OR (($row == 1) AND (substr($msg, 0, 4) == $recycle)))
119 $msg = iconv_substr(iconv_substr(trim($msg."\n".$line), 0, $limit, "UTF-8"), 0, -3, "UTF-8")."...";
126 function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
127 require_once("include/bbcode.php");
128 require_once("include/html2plain.php");
129 require_once("include/network.php");
131 // At first look at data that is attached via "type-..." stuff
132 // This will hopefully replaced with a dedicated bbcode later
133 $post = get_attached_data($b["body"]);
135 if (($b["title"] != "") AND ($post["text"] != ""))
136 $post["text"] = trim($b["title"]."\n\n".$post["text"]);
137 elseif ($b["title"] != "")
138 $post["text"] = trim($b["title"]);
140 $html = bbcode($post["text"], false, false, $htmlmode);
141 $msg = html2plain($html, 0, true);
142 $msg = trim(html_entity_decode($msg,ENT_QUOTES,'UTF-8'));
145 if ($includedlinks) {
146 if ($post["type"] == "link")
147 $link = $post["url"];
148 elseif ($post["type"] == "video")
149 $link = $post["url"];
150 elseif ($post["type"] == "photo")
151 $link = $post["image"];
153 if (($msg == "") AND isset($post["title"]))
154 $msg = trim($post["title"]);
156 if (($msg == "") AND isset($post["description"]))
157 $msg = trim($post["description"]);
159 // If the link is already contained in the post, then it neeedn't to be added again
160 // But: if the link is beyond the limit, then it has to be added.
161 if (($link != "") AND strstr($msg, $link)) {
162 $pos = strpos($msg, $link);
163 if (($limit == 0) OR ($pos < $limit))
169 // Reduce multiple spaces
170 // When posted to a network with limited space, we try to gain space where possible
171 while (strpos($msg, " ") !== false)
172 $msg = str_replace(" ", " ", $msg);
174 // Twitter is using its own limiter, so we always assume that shortened links will have this length
175 if (iconv_strlen($link, "UTF-8") > 0)
176 $limit = $limit - 23;
178 if (iconv_strlen($msg, "UTF-8") > $limit) {
180 if (!isset($post["url"])) {
181 $limit = $limit - 23;
182 $post["url"] = $b["plink"];
183 } elseif (strpos($b["body"], "[share") !== false)
184 $post["url"] = $b["plink"];
186 $msg = shortenmsg($msg, $limit);
190 $post["text"] = trim($msg);