function bb_rearrange_share($shared) { if (!in_array(strtolower($shared[2]), array("type-link", "type-audio", "type-video"))) { return $shared[0]; } if (!preg_match_all("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", $shared[3], $bookmark)) { return $shared[0]; } $type = substr(trim(strtolower($shared[2])), 5); $title = ""; $url = ""; $preview = ""; $description = ""; if (isset($bookmark[2][0])) { $title = $bookmark[2][0]; } if (isset($bookmark[1][0])) { $url = $bookmark[1][0]; } $cleanedshare = trim($shared[3]); $cleanedshare = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '[img]$3[/img]', $cleanedshare); preg_match("/\\[img\\](.*?)\\[\\/img\\]/ism", $cleanedshare, $matches); if ($matches) { $preview = trim($matches[1]); } preg_match("/\\[quote\\](.*?)\\[\\/quote\\]/ism", $cleanedshare, $matches); if ($matches) { $description = trim($matches[1]); } $url = str_replace(array("[", "]"), array("[", "]"), htmlentities($url, ENT_QUOTES, 'UTF-8', false)); $title = str_replace(array("[", "]"), array("[", "]"), htmlentities($title, ENT_QUOTES, 'UTF-8', false)); $preview = str_replace(array("[", "]"), array("[", "]"), htmlentities($preview, ENT_QUOTES, 'UTF-8', false)); $Text = trim($shared[1]) . "\n[attachment type='" . $type . "'"; if ($url != "") { $Text .= " url='" . $url . "'"; } if ($title != "") { $Text .= " title='" . $title . "'"; } if ($preview != "") { require_once "include/Photo.php"; $picturedata = get_photo_info($preview); if (count($picturedata) > 0) { // if the preview picture is larger than 500 pixels then show it in a larger mode // But only, if the picture isn't higher than large (To prevent huge posts) if ($picturedata[0] >= 500 and $picturedata[0] >= $picturedata[1]) { $Text .= " image='" . $preview . "'"; } else { $Text .= " preview='" . $preview . "'"; } } else { $Text .= " preview='" . $preview . "'"; } } $Text .= "]" . $description . "[/attachment]"; return $Text; }
function item_get_attachment($item) { $o = ""; $siteinfo = get_attached_data($item["body"]); switch ($siteinfo["type"]) { case 'link': $o = '<link rel="enclosure" href="' . xmlify($siteinfo["url"]) . '" type="text/html; charset=UTF-8" length="" title="' . xmlify($siteinfo["title"]) . '"/>' . "\r\n"; break; case 'photo': $imgdata = get_photo_info($siteinfo["image"]); $o = '<link rel="enclosure" href="' . xmlify($siteinfo["image"]) . '" type="' . $imgdata["mime"] . '" length="' . $imgdata["size"] . '"/>' . "\r\n"; break; case 'video': $o = '<link rel="enclosure" href="' . xmlify($siteinfo["url"]) . '" type="text/html; charset=UTF-8" length="" title="' . xmlify($siteinfo["title"]) . '"/>' . "\r\n"; break; default: break; } return $o; }
function api_get_entitities(&$text, $bbcode) { /* To-Do: * Links at the first character of the post */ $a = get_app(); $include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false"); if ($include_entities != "true") { preg_match_all("/\\[img](.*?)\\[\\/img\\]/ism", $bbcode, $images); foreach ($images[1] as $image) { $replace = proxy_url($image); $text = str_replace($image, $replace, $text); } return array(); } $bbcode = bb_CleanPictureLinks($bbcode); // Change pure links in text to bbcode uris $bbcode = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1[url=$2]$2[/url]', $bbcode); $entities = array(); $entities["hashtags"] = array(); $entities["symbols"] = array(); $entities["urls"] = array(); $entities["user_mentions"] = array(); $URLSearchString = "^\\[\\]"; $bbcode = preg_replace("/#\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '#$2', $bbcode); $bbcode = preg_replace("/\\[bookmark\\=([{$URLSearchString}]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $bbcode); //$bbcode = preg_replace("/\[url\](.*?)\[\/url\]/ism",'[url=$1]$1[/url]',$bbcode); $bbcode = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", '[url=https://www.youtube.com/watch?v=$1]https://www.youtube.com/watch?v=$1[/url]', $bbcode); $bbcode = preg_replace("/\\[youtube\\](.*?)\\[\\/youtube\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", '[url=https://vimeo.com/$1]https://vimeo.com/$1[/url]', $bbcode); $bbcode = preg_replace("/\\[vimeo\\](.*?)\\[\\/vimeo\\]/ism", '[url=$1]$1[/url]', $bbcode); $bbcode = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '[img]$3[/img]', $bbcode); //preg_match_all("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $bbcode, $urls1); preg_match_all("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", $bbcode, $urls); $ordered_urls = array(); foreach ($urls[1] as $id => $url) { //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $url, 0, "UTF-8"); if (!($start === false)) { $ordered_urls[$start] = array("url" => $url, "title" => $urls[2][$id]); } } ksort($ordered_urls); $offset = 0; //foreach ($urls[1] AS $id=>$url) { foreach ($ordered_urls as $url) { if (substr($url["title"], 0, 7) != "http://" and substr($url["title"], 0, 8) != "https://" and !strpos($url["title"], "http://") and !strpos($url["title"], "https://")) { $display_url = $url["title"]; } else { $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url["url"]); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25) . "…"; } } //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $url["url"], $offset, "UTF-8"); if (!($start === false)) { $entities["urls"][] = array("url" => $url["url"], "expanded_url" => $url["url"], "display_url" => $display_url, "indices" => array($start, $start + strlen($url["url"]))); $offset = $start + 1; } } preg_match_all("/\\[img](.*?)\\[\\/img\\]/ism", $bbcode, $images); $ordered_images = array(); foreach ($images[1] as $image) { //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $image, 0, "UTF-8"); if (!($start === false)) { $ordered_images[$start] = $image; } } //$entities["media"] = array(); $offset = 0; foreach ($ordered_images as $url) { $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25) . "…"; } $start = iconv_strpos($text, $url, $offset, "UTF-8"); if (!($start === false)) { $image = get_photo_info($url); if ($image) { // If image cache is activated, then use the following sizes: // thumb (150), small (340), medium (600) and large (1024) if (!get_config("system", "proxy_disabled")) { $media_url = proxy_url($url); $sizes = array(); $scale = scale_image($image[0], $image[1], 150); $sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); if ($image[0] > 150 or $image[1] > 150) { $scale = scale_image($image[0], $image[1], 340); $sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); } $scale = scale_image($image[0], $image[1], 600); $sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); if ($image[0] > 600 or $image[1] > 600) { $scale = scale_image($image[0], $image[1], 1024); $sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"); } } else { $media_url = $url; $sizes["medium"] = array("w" => $image[0], "h" => $image[1], "resize" => "fit"); } $entities["media"][] = array("id" => $start + 1, "id_str" => (string) $start + 1, "indices" => array($start, $start + strlen($url)), "media_url" => normalise_link($media_url), "media_url_https" => $media_url, "url" => $url, "display_url" => $display_url, "expanded_url" => $url, "type" => "photo", "sizes" => $sizes); } $offset = $start + 1; } } return $entities; }
function twitter_fix_avatar($avatar) { require_once "include/Photo.php"; $new_avatar = str_replace("_normal.", ".", $avatar); $info = get_photo_info($new_avatar); if (!$info) { $new_avatar = $avatar; } return $new_avatar; }
function fromgplus_cleanupgoogleproxy($fullImage, $image) { //$preview = "/w".$fullImage->width."-h".$fullImage->height."/"; //$preview2 = "/w".$fullImage->width."-h".$fullImage->height."-p/"; //$fullImage = str_replace(array($preview, $preview2), array("/", "/"), $fullImage->url); $fullImage = $fullImage->url; //$preview = "/w".$image->width."-h".$image->height."/"; //$preview2 = "/w".$image->width."-h".$image->height."-p/"; //$image = str_replace(array($preview, $preview2), array("/", "/"), $image->url); $image = $image->url; $cleaned = array(); $queryvar = fromgplus_parse_query($fullImage); if ($queryvar['url'] != "") { $cleaned["full"] = urldecode($queryvar['url']); } else { $cleaned["full"] = $fullImage; } if (@exif_imagetype($cleaned["full"]) == 0) { $cleaned["full"] = ""; } $queryvar = fromgplus_parse_query($image); if ($queryvar['url'] != "") { $cleaned["preview"] = urldecode($queryvar['url']); } else { $cleaned["preview"] = $image; } if (@exif_imagetype($cleaned["preview"]) == 0) { $cleaned["preview"] = ""; } if ($cleaned["full"] == "") { $cleaned["full"] = $cleaned["preview"]; $cleaned["preview"] = ""; } if ($cleaned["full"] != "") { $infoFull = get_photo_info($cleaned["full"]); } else { $infoFull = array("0" => 0, "1" => 0); } if ($cleaned["preview"] != "") { $infoPreview = get_photo_info($cleaned["preview"]); } else { $infoFull = array("0" => 0, "1" => 0); } if ($infoPreview[0] >= $infoFull[0] and $infoPreview[1] >= $infoFull[1]) { $temp = $cleaned["full"]; $cleaned["full"] = $cleaned["preview"]; $cleaned["preview"] = $temp; } if ($cleaned["full"] == $cleaned["preview"] or $infoPreview[0] == $infoFull[0] and $infoPreview[1] == $infoFull[1]) { $cleaned["preview"] = ""; } if ($cleaned["full"] == "") { if (@exif_imagetype($fullImage) != 0) { $cleaned["full"] = $fullImage; } } if ($cleaned["full"] == "") { if (@exif_imagetype($image) != 0) { $cleaned["full"] = $image; } } // Could be changed in the future to a link to the album $cleaned["page"] = $cleaned["full"]; return $cleaned; }
$author = $_SESSION['uid']; $upload = date("Y-m-d H:i"); $update = date("Y-m-d H:i"); $json = get_option('stor'); $stor = json_decode($json); $i = 0; // 2143289344 = 2GB*1024*1024*1024 - 4MB*1024*1024 while ($storage->getDomainCapacity($stor[$i]) > 2143289344) { $i++; } $domain = $stor[$i]; $storage->upload($domain, 'original/' . $name, $_FILES['file']['tmp_name']); if ($storage->errno == 0) { // 生成缩略图 $img_data = $storage->read($domain, 'original/' . $name); $img_info = getimagesize($_FILES['file']['tmp_name']); $width = $img_info[0]; $height = $img_info[1]; add_photo($author, $name, $title, $filesize, $width, $height, $upload, $update, $domain, '1'); $uid = get_photo_info($name, 'uid', 'name'); $url = photo_link($uid); header("Location: {$url}"); exit; } } else { header("refresh:1;url=" . SITE_URL . "upload.php"); echo '你提交的不是图片...'; exit; } } }
function fbpost_cleanpicture($url) { require_once "include/Photo.php"; $urldata = parse_url($url); if (isset($urldata["query"])) { parse_str($urldata["query"], $querydata); if (isset($querydata["url"]) and get_photo_info($querydata["url"])) { return $querydata["url"]; } } return $url; }
function twitter_fetch_contact($uid, $contact, $create_user) { require_once "include/Photo.php"; if ($contact->id_str == "") { return -1; } $avatar = str_replace("_normal.", ".", $contact->profile_image_url_https); $info = get_photo_info($avatar); if (!$info) { $avatar = $contact->profile_image_url_https; } // Check if the unique contact is existing // To-Do: only update once a while $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link("https://twitter.com/" . $contact->screen_name))); if (count($r) == 0) { q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", dbesc(normalise_link("https://twitter.com/" . $contact->screen_name)), dbesc($contact->name), dbesc($contact->screen_name), dbesc($avatar)); } else { q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'", dbesc($contact->name), dbesc($contact->screen_name), dbesc($avatar), dbesc(normalise_link("https://twitter.com/" . $contact->screen_name))); } if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", dbesc($contact->location), dbesc($contact->description), dbesc(normalise_link("https://twitter.com/" . $contact->screen_name))); } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc("twitter::" . $contact->id_str)); if (!count($r) and !$create_user) { return 0; } if (count($r) and ($r[0]["readonly"] or $r[0]["blocked"])) { logger("twitter_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.", LOGGER_DEBUG); return -1; } if (!count($r)) { // create contact record q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,\n\t\t\t\t\t`name`, `nick`, `photo`, `network`, `rel`, `priority`,\n\t\t\t\t\t`writable`, `blocked`, `readonly`, `pending` )\n\t\t\t\t\tVALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0) ", intval($uid), dbesc(datetime_convert()), dbesc("https://twitter.com/" . $contact->screen_name), dbesc(normalise_link("https://twitter.com/" . $contact->screen_name)), dbesc($contact->screen_name . "@twitter.com"), dbesc("twitter::" . $contact->id_str), dbesc(''), dbesc("twitter::" . $contact->id_str), dbesc($contact->name), dbesc($contact->screen_name), dbesc($avatar), dbesc(NETWORK_TWITTER), intval(CONTACT_IS_FRIEND), intval(1), intval(1)); $r = q("SELECT * FROM `contact` WHERE `alias` = '%s' AND `uid` = %d LIMIT 1", dbesc("twitter::" . $contact->id_str), intval($uid)); if (!count($r)) { return false; } $contact_id = $r[0]['id']; $g = q("SELECT def_gid FROM user WHERE uid = %d LIMIT 1", intval($uid)); if ($g && intval($g[0]['def_gid'])) { require_once 'include/group.php'; group_add_member($uid, '', $contact_id, $g[0]['def_gid']); } require_once "Photo.php"; $photos = import_profile_photo($avatar, $uid, $contact_id); q("UPDATE `contact` SET `photo` = '%s',\n\t\t\t\t\t`thumb` = '%s',\n\t\t\t\t\t`micro` = '%s',\n\t\t\t\t\t`name-date` = '%s',\n\t\t\t\t\t`uri-date` = '%s',\n\t\t\t\t\t`avatar-date` = '%s'\n\t\t\t\tWHERE `id` = %d", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), intval($contact_id)); if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `contact` SET `location` = '%s',\n\t\t\t\t\t\t`about` = '%s'\n\t\t\t\t\tWHERE `id` = %d", dbesc($contact->location), dbesc($contact->description), intval($contact_id)); } } else { // update profile photos once every two weeks as we have no notification of when they change. //$update_photo = (($r[0]['avatar-date'] < datetime_convert('','','now -2 days')) ? true : false); $update_photo = $r[0]['avatar-date'] < datetime_convert('', '', 'now -12 hours'); // check that we have all the photos, this has been known to fail on occasion if (!$r[0]['photo'] || !$r[0]['thumb'] || !$r[0]['micro'] || $update_photo) { logger("twitter_fetch_contact: Updating contact " . $contact->screen_name, LOGGER_DEBUG); require_once "Photo.php"; $photos = import_profile_photo($avatar, $uid, $r[0]['id']); q("UPDATE `contact` SET `photo` = '%s',\n\t\t\t\t\t\t`thumb` = '%s',\n\t\t\t\t\t\t`micro` = '%s',\n\t\t\t\t\t\t`name-date` = '%s',\n\t\t\t\t\t\t`uri-date` = '%s',\n\t\t\t\t\t\t`avatar-date` = '%s',\n\t\t\t\t\t\t`url` = '%s',\n\t\t\t\t\t\t`nurl` = '%s',\n\t\t\t\t\t\t`addr` = '%s',\n\t\t\t\t\t\t`name` = '%s',\n\t\t\t\t\t\t`nick` = '%s'\n\t\t\t\t\tWHERE `id` = %d", dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc("https://twitter.com/" . $contact->screen_name), dbesc(normalise_link("https://twitter.com/" . $contact->screen_name)), dbesc($contact->screen_name . "@twitter.com"), dbesc($contact->name), dbesc($contact->screen_name), intval($r[0]['id'])); if (DB_UPDATE_VERSION >= "1177") { q("UPDATE `contact` SET `location` = '%s',\n\t\t\t\t\t\t\t`about` = '%s'\n\t\t\t\t\t\tWHERE `id` = %d", dbesc($contact->location), dbesc($contact->description), intval($r[0]['id'])); } } } return $r[0]["id"]; }
function get_attached_data($body) { /* - text: - type: link, video, photo - title: - url: - image: - description: - (thumbnail) */ // Simplify image codes $body = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '[img]$3[/img]', $body); $post = array(); if (preg_match_all("(\\[class=(.*?)\\](.*?)\\[\\/class\\])ism", $body, $attached, PREG_SET_ORDER)) { foreach ($attached as $data) { if (!in_array($data[1], array("type-link", "type-video", "type-photo"))) { continue; } $post["type"] = substr($data[1], 5); $post["text"] = trim(str_replace($data[0], "", $body)); $attacheddata = $data[2]; $URLSearchString = "^\\[\\]"; if (preg_match("/\\[img\\]([{$URLSearchString}]*)\\[\\/img\\]/ism", $attacheddata, $matches)) { $post["image"] = $matches[1]; } if (preg_match("/\\[bookmark\\=([{$URLSearchString}]*)\\](.*?)\\[\\/bookmark\\]/ism", $attacheddata, $matches)) { $post["url"] = $matches[1]; $post["title"] = $matches[2]; } // Search for description if (preg_match("/\\[quote\\](.*?)\\[\\/quote\\]/ism", $attacheddata, $matches)) { $post["description"] = $matches[1]; } } } // if nothing is found, it maybe having an image. if (!isset($post["type"])) { require_once "mod/parse_url.php"; require_once "include/Photo.php"; $URLSearchString = "^\\[\\]"; if (preg_match_all("(\\[url=([{$URLSearchString}]*)\\]\\s*\\[img\\]([{$URLSearchString}]*)\\[\\/img\\]\\s*\\[\\/url\\])ism", $body, $pictures, PREG_SET_ORDER)) { if (count($pictures) == 1) { // Checking, if the link goes to a picture $data = parseurl_getsiteinfo_cached($pictures[0][1], true); if ($data["type"] == "photo") { $post["type"] = "photo"; if (isset($data["images"][0])) { $post["image"] = $data["images"][0]["src"]; } else { $post["image"] = $data["url"]; } $post["preview"] = $pictures[0][2]; $post["text"] = str_replace($pictures[0][0], "", $body); } else { $imgdata = get_photo_info($pictures[0][1]); if (substr($imgdata["mime"], 0, 6) == "image/") { $post["type"] = "photo"; $post["image"] = $pictures[0][1]; $post["preview"] = $pictures[0][2]; $post["text"] = str_replace($pictures[0][0], "", $body); } } } elseif (count($pictures) > 1) { $post["type"] = "link"; $post["url"] = $b["plink"]; $post["image"] = $pictures[0][2]; $post["text"] = $body; } } elseif (preg_match_all("(\\[img\\]([{$URLSearchString}]*)\\[\\/img\\])ism", $body, $pictures, PREG_SET_ORDER)) { if (count($pictures) == 1) { $post["type"] = "photo"; $post["image"] = $pictures[0][1]; $post["text"] = str_replace($pictures[0][0], "", $body); } elseif (count($pictures) > 1) { $post["type"] = "link"; $post["url"] = $b["plink"]; $post["image"] = $pictures[0][1]; $post["text"] = $body; } } if (!isset($post["type"])) { $post["type"] = "text"; $post["text"] = trim($body); } } elseif (isset($post["url"]) and $post["type"] == "video") { require_once "mod/parse_url.php"; $data = parseurl_getsiteinfo_cached($post["url"], true); if (isset($data["images"][0])) { $post["image"] = $data["images"][0]["src"]; } } return $post; }
function ostatus_get_attachment($doc, $root, $item) { $o = ""; $siteinfo = get_attached_data($item["body"]); switch ($siteinfo["type"]) { case 'link': $attributes = array("rel" => "enclosure", "href" => $siteinfo["url"], "type" => "text/html; charset=UTF-8", "length" => "", "title" => $siteinfo["title"]); xml_add_element($doc, $root, "link", "", $attributes); break; case 'photo': $imgdata = get_photo_info($siteinfo["image"]); $attributes = array("rel" => "enclosure", "href" => $siteinfo["image"], "type" => $imgdata["mime"], "length" => intval($imgdata["size"])); xml_add_element($doc, $root, "link", "", $attributes); break; case 'video': $attributes = array("rel" => "enclosure", "href" => $siteinfo["url"], "type" => "text/html; charset=UTF-8", "length" => "", "title" => $siteinfo["title"]); xml_add_element($doc, $root, "link", "", $attributes); break; default: break; } if ($siteinfo["type"] != "photo" and isset($siteinfo["image"])) { $photodata = get_photo_info($siteinfo["image"]); $attributes = array("rel" => "preview", "href" => $siteinfo["image"], "media:width" => $photodata[0], "media:height" => $photodata[1]); xml_add_element($doc, $root, "link", "", $attributes); } $arr = explode('[/attach],', $item['attach']); if (count($arr)) { foreach ($arr as $r) { $matches = false; $cnt = preg_match('|\\[attach\\]href=\\"(.*?)\\" length=\\"(.*?)\\" type=\\"(.*?)\\" title=\\"(.*?)\\"|', $r, $matches); if ($cnt) { $attributes = array("rel" => "enclosure", "href" => $matches[1], "type" => $matches[3]); if (intval($matches[2])) { $attributes["length"] = intval($matches[2]); } if (trim($matches[4]) != "") { $attributes["title"] = trim($matches[4]); } xml_add_element($doc, $root, "link", "", $attributes); } } } }