}
$media = self::unsetEmptyFields($media);
+ $media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media);
// We are storing as fast as possible to avoid duplicated network requests
// when fetching additional information for pictures and other content.
$media = self::fetchAdditionalData($media);
$media = self::unsetEmptyFields($media);
+ $media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media);
if (array_diff_assoc($media, $stored)) {
$result = DBA::insert('post-media', $media, Database::INSERT_UPDATE);
if (($media['type'] == self::IMAGE) || ($filetype == 'image')) {
$imagedata = Images::getInfoFromURLCached($media['url']);
- if (!empty($imagedata)) {
+ if ($imagedata) {
$media['mimetype'] = $imagedata['mime'];
$media['size'] = $imagedata['size'];
$media['width'] = $imagedata[0];
}
if (!empty($media['preview'])) {
$imagedata = Images::getInfoFromURLCached($media['preview']);
- if (!empty($imagedata)) {
+ if ($imagedata) {
$media['preview-width'] = $imagedata[0];
$media['preview-height'] = $imagedata[1];
}
/**
* Add media attachments to the body
*
- * @param int $uriid
+ * @param int $uriid
* @param string $body
+ * @param array $types
+ *
* @return string body
*/
- public static function addAttachmentsToBody(int $uriid, string $body = ''): string
+ public static function addAttachmentsToBody(int $uriid, string $body = '', array $types = [self::IMAGE, self::AUDIO, self::VIDEO]): string
{
if (empty($body)) {
$item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
- foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) {
+ foreach (self::getByURIId($uriid, $types) as $media) {
if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) {
continue;
}