]> git.mxchange.org Git - friendica.git/commitdiff
several fixes for attachments
authorFriendika <info@friendika.com>
Thu, 4 Aug 2011 02:18:58 +0000 (19:18 -0700)
committerFriendika <info@friendika.com>
Thu, 4 Aug 2011 02:18:58 +0000 (19:18 -0700)
include/attach.php
include/items.php
include/text.php
library/simplepie/simplepie.inc
mod/item.php
mod/wall_attach.php

index ca53081d9347ea764909a9445f0632fa820a539e..4001d2af1351bd7f92714ad3263357365b3eee46 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
-if(!function_exists('mime_content_type')) {
-function mime_content_type($filename) {
+
+function z_mime_content_type($filename) {
 
        $mime_types = array(
 
@@ -61,8 +61,9 @@ function mime_content_type($filename) {
                'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
        );
 
-       if(strpos($filename,'.') !== false) {
-               $ext = strtolower(array_pop(explode('.',$filename)));
+       $dot = strpos($filename,'.');
+       if($dot !== false) {
+               $ext = strtolower(substr($filename,$dot+1));
                if (array_key_exists($ext, $mime_types)) {
                        return $mime_types[$ext];
                }
@@ -76,5 +77,5 @@ function mime_content_type($filename) {
        else {
                return 'application/octet-stream';
        }
-}}
+}
 
index 6d69c6cc9e0dd3579fad262107230b517e6863d9..8c6134f94f7fa205e56a581cef1ed7be1aea88c2 100644 (file)
@@ -518,7 +518,7 @@ function get_atom_elements($feed,$item) {
                        if(! $type)
                                $type = 'application/octet-stream';
 
-                       $att_arr[] = '[attach]href="' . $link . '" size="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]'; 
+                       $att_arr[] = '[attach]href="' . $link . '" length="' . $len . '" type="' . $type . '" title="' . $title . '"[/attach]'; 
                }
                $res['attach'] = implode(',', $att_arr);
        }
@@ -1725,11 +1725,11 @@ function item_getfeedattach($item) {
        if(count($arr)) {
                foreach($arr as $r) {
                        $matches = false;
-                       $cnt = preg_match('|\[attach\]href=\"(.*?)\" size=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
+                       $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
                        if($cnt) {
                                $ret .= '<link rel="enclosure" href="' . xmlify($matches[1]) . '" type="' . xmlify($matches[3]) . '" ';
                                if(intval($matches[2]))
-                                       $ret .= 'size="' . intval($matches[2]) . '" ';
+                                       $ret .= 'length="' . intval($matches[2]) . '" ';
                                if($matches[4] !== ' ')
                                        $ret .= 'title="' . xmlify(trim($matches[4])) . '" ';
                                $ret .= ' />' . "\r\n";
index d65c7787222a9781885f65341fcb3d57398fb329..a568b7a948ad7861735e0db47cedbbea36c3f684 100644 (file)
@@ -746,7 +746,7 @@ function prepare_body($item,$attach = false) {
                foreach($arr as $r) {
                        $matches = false;
                        $icon = '';
-                       $cnt = preg_match('|\[attach\]href=\"(.*?)\" size=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
+                       $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
                        if($cnt) {
                                $icontype = strtolower(substr($matches[3],0,strpos($matches[3],'/')));
                                switch($icontype) {
index c3ba02b7db9531d63ff49c815baec37827e21798..8a2739f525d9512f21eb9049bf409aecfa9f0edc 100644 (file)
@@ -5517,6 +5517,7 @@ class SimplePie_Item
                                        $type = null;
                                        $url = null;
                                        $width = null;
+                                       $title = $title_parent;
 
                                        $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
                                        if (isset($link['attribs']['']['type']))
@@ -5527,9 +5528,13 @@ class SimplePie_Item
                                        {
                                                $length = ceil($link['attribs']['']['length']);
                                        }
+                                       if (isset($link['attribs']['']['title']))
+                                       {
+                                               $title = $this->sanitize($link['attribs']['']['title'], SIMPLEPIE_CONSTRUCT_TEXT);
+                                       }
 
                                        // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
-                                       $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
+                                       $this->data['enclosures'][] = new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title, $width);
                                }
                        }
 
index b71c35041c29ea8dd7af7d801e590bc11d5f6c58..fd5d405ff6cac3a071a431f95220c4eaf37dd147 100644 (file)
@@ -304,6 +304,10 @@ function item_post(&$a) {
                                if(count($r)) {
                                        $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
                                                WHERE `uid` = %d AND `id` = %d LIMIT 1",
+                                               dbesc($str_contact_allow),
+                                               dbesc($str_group_allow),
+                                               dbesc($str_contact_deny),
+                                               dbesc($str_group_deny),
                                                intval($profile_uid),
                                                intval($attach)
                                        );
@@ -436,7 +440,7 @@ function item_post(&$a) {
                        if(count($r)) {
                                if(strlen($attachments))
                                        $attachments .= ',';
-                               $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" size="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : ' ') . '"[/attach]'; 
+                               $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . (($r[0]['filename']) ? $r[0]['filename'] : '') . '"[/attach]'; 
                        }
                        $body = str_replace($match[1],'',$body);
                }
index f18fd10b74faf004daeced684628d559de30ee46..ef6554df39809118c13f1329296726cd9d8842ed 100644 (file)
@@ -60,11 +60,11 @@ function wall_attach_post(&$a) {
        }
 
        $filedata = @file_get_contents($src);
-
-       $mimetype = mime_content_type($src);
+       $mimetype = z_mime_content_type($filename);
+       if((! strlen($mimetype)) || ($mimetype === 'application/octet-stream') && function_exists('mime_content_type'))
+               $mimetype = mime_content_type($filename);
        $hash = random_string();
        $created = datetime_convert();
-
        $r = q("INSERT INTO `attach` ( `uid`, `hash`, `filename`, `filetype`, `filesize`, `data`, `created`, `edited`, `allow_cid`, `allow_gid`,`deny_cid`, `deny_gid` )
                VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
                intval($page_owner_uid),