/** @noinspection PhpMissingDocCommentInspection */ public static function AddAttachmentsToLayoutExport(&$gtl_settings, &$xml) { $regex = '/' . str_replace('/', '\\/', WP_CONTENT_URL) . '\\/uploads\\/[^"]+/im'; $matches = array(); $n = null; if (preg_match_all($regex, $gtl_settings, $matches)) { $n = array(); foreach ($matches[0] as $url) { if (!isset($n[$url])) { $n[$url] = GFontsDB::uuid(); } } /* @var $wpdb wpdb */ global $wpdb; $attachments = array(); foreach ($n as $url => $uuid) { $loc = str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $url); $sql = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts WHERE guid = %s AND post_type = 'attachment' AND post_status = 'inherit'", $url); $att = $wpdb->get_row($sql); if ($att != null) { $pinfo = pathinfo($loc); $attachments[] = array('guid' => $url, 'uuid' => $uuid, 'diskloc' => $loc, 'mime_type' => $att->post_mime_type, 'extension' => isset($pinfo['extension']) ? $pinfo['extension'] : null); } } if (count($attachments) > 0) { $xml .= "<attachments>\n"; foreach ($attachments as $attachment) { $xml .= "<attachment>\n"; $xml .= "<guid>" . $attachment['uuid'] . "</guid>\n"; $xml .= "<mimetype>" . $attachment['mime_type'] . "</mimetype>\n"; $xml .= "<ext>" . $attachment['extension'] . "</ext>\n"; $xml .= "<data>" . base64_encode(file_get_contents($attachment['diskloc'])) . "</data>\n"; $xml .= "</attachment>\n"; } $xml .= "</attachments>\n"; } } $gtl = unserialize($gtl_settings); if (is_array($n)) { self::ReplaceAttachmentsInExportArray($gtl, $n); } $gtl_settings = serialize($gtl); }