Commit Graph

189 Commits

Author SHA1 Message Date
Stephen Paul Weber
a9b1b60a97 Refactor on File::processNew
The code was so involved there was even a comment asking for a refactor.

Now, File_redirection::where always returns a nice File_redirection
object instead of an array or string or nothing.  The object is
either one which already existed or else a new, unsaved object.

Instead of duplicating "does it exist" checks everywhere, do it in
File_redirection::where.  You either get what exists or something to save.

An unsaved File_redirection may be paired with an unsaved File.
You will want to save the File first (using ->saveFile()) and put the
id in File_redirection#file_id before saving.
2015-11-02 05:15:08 +00:00
Mikael Nordfeldth
80bc7f0e25 File handling changes for better logic
Also prepares for StoreRemoteMediaPlugin, coming up...
2015-10-01 22:14:49 +02:00
Mikael Nordfeldth
edb73ec480 Use exception instead of if-statement in File::saveNew 2015-09-27 12:29:38 +02:00
Mikael Nordfeldth
02418cffd8 Be harsher on database saving failure for File entry 2015-09-27 11:54:52 +02:00
Mikael Nordfeldth
daaafd86e2 DB_DataObject recommends using ->tableName() 2015-06-06 19:35:10 +02:00
Mikael Nordfeldth
fe6498e7c8 Send objects instead of integers to File_to_post::processNew 2015-06-04 17:36:11 +02:00
Mikael Nordfeldth
5358fb3cce Use the same cache string in all places for file:notice-ids 2015-06-04 17:02:45 +02:00
Mikael Nordfeldth
3294d704a4 scripts/nukefile.php for blasting crap from the server
Deletes notices and the locally stored file based on File id, as
you may want to just get rid of shit sometimes.
2015-05-30 15:41:04 +02:00
Mikael Nordfeldth
f926e27a65 urlhash will _be_ NULL on update, so NOT NULL won't work 2015-05-27 22:37:20 +02:00
Mikael Nordfeldth
c31d6608a8 remove _all_ file URLs not just the duplicates 2015-05-27 21:54:51 +02:00
Mikael Nordfeldth
cd0b70dbc1 upgrade fix for file URLs longer than 191 chars 2015-05-27 21:31:29 +02:00
Mikael Nordfeldth
c5715bc756 File_to_post indexing and cleaning preparations 2015-04-15 23:25:12 +02:00
Mikael Nordfeldth
a4af51b5ba Move thumbnail algorithm mainly to ImageFile class 2015-03-04 13:12:42 +01:00
Mikael Nordfeldth
8fac7a9f6c StatusNet class renamed GNUsocial
also added backward compatible StatusNet class for the two calls I know
third party plugins use, isHTTPS and getActivePlugins
2015-02-27 12:44:15 +01:00
Mikael Nordfeldth
7e6ba94241 Documentation + filename uniqueness in File class 2015-02-25 15:19:27 +01:00
Mikael Nordfeldth
9a843548c0 Save thumbnails with proper extension
This might cause double extensions, but that's ok since the filename
is stored in the database. We might want to look at it later though.
2015-02-25 01:34:00 +01:00
Mikael Nordfeldth
325e784ccd Don't store duplicates of files.
If a new file is uploaded, it will be matched with a previously uploaded
file so we don't have to store duplicates. SHA256 is random enough and
also unlikely enough to cause collisions.
2015-02-24 21:11:25 +01:00
Mikael Nordfeldth
0e6c83e521 Had to avoid using indexes in the migration phase
File and File_redirection still had their indexes in the temporary migration table definition.
2015-02-19 22:06:43 +01:00
Mikael Nordfeldth
b54710950f unique keys and indexes must be NOT NULL or MySQL fucks up
If this merge throws exception on scripts/upgrade.php and you recently
tried a nightly (i.e. during 2015-02-19) then just go back a commit or two
and try again.

Or delete the duplicate entries. Find the entries like this:

SELECT COUNT(*), urlhash FROM file_redirection
    GROUP BY urlhash
    HAVING COUNT(*) > 1;

then for each urlhash (or come up with a smart SQL query) do:
DELETE FROM file_redirection WHERE urlhash='hashfrompreviousquery' LIMIT 1;

You'll have to remove duplicates more than once if you have >2 identical
urlhash entries. LIMIT -1 might do that for you. I'm not sure.
2015-02-19 21:21:39 +01:00
Mikael Nordfeldth
0590f2975e Merge branch 'utf8mb4' into nightly
Conflicts because of urlhash fixes:
	classes/File.php
	classes/File_redirection.php
	classes/File_thumbnail.php
2015-02-19 20:50:40 +01:00
Mikael Nordfeldth
5471c65c9a less newlines for the scripts/upgrade.php output 2015-02-19 19:40:36 +01:00
Mikael Nordfeldth
e299583eee Bad check on existing urlhash key 2015-02-19 19:36:59 +01:00
Mikael Nordfeldth
8ac8e2e734 Use new ::getByUrl for File and File_redirection
and make use of the exceptions instead endless if statements
2015-02-19 19:29:55 +01:00
Mikael Nordfeldth
c05e9b118c function is hashurl, variable is urlhash 2015-02-19 19:07:43 +01:00
Mikael Nordfeldth
45dc76de26 File and File_redirection adhoc storage methods updated for urlhash 2015-02-19 19:05:24 +01:00
Mikael Nordfeldth
27480d8e8e File_redirection also got urlhash column 2015-02-19 18:34:48 +01:00
Mikael Nordfeldth
5a8f24eb46 urlhash first steps, including scripts/upgrade.php 2015-02-17 18:55:12 +01:00
Mikael Nordfeldth
2f86cd8602 utf8mb4 conversion on database with index adjusts 2015-02-12 18:18:55 +01:00
Mikael Nordfeldth
67d09532dd Improved animated image thumbnail freedom of choice
Default is now to take still thumbnails of animated GIFs and then
show them as originals in an AttachmentListItem. The still frames
are mostly used with front-ends like qvitter.
2015-01-26 16:33:39 +01:00
Mikael Nordfeldth
a8e613e508 Animated GIF restructuring, ImageMagick only used for resizing animated sequences. 2015-01-25 23:00:00 +01:00
Mikael Nordfeldth
2a7d45c986 No need for ImageMagick to detected animated GIF 2015-01-25 22:45:25 +01:00
Mikael Nordfeldth
97bf470895 File class improved debugging and filename generation
In some development code I noticed that when handling File objects without
filename values, there would be problems calling getPath and such.

The width and height value testing will be validated later anyway, and by
removing such a narrow test we can use events to generate thumbnails of
media formats supported by recently added plugins on demand.
2015-01-25 02:30:43 +01:00
Mikael Nordfeldth
3927acdde5 getUrl() fixed for File and File_thumbnail to correct http/https stuff and other 2015-01-12 19:22:10 +01:00
Mikael Nordfeldth
cbb7ec07a5 When called in offline queue, File::url was HTTP
Despite having the site configured "always" for HTTPS, File generated
thumbnails and such with HTTP urls.
2015-01-12 19:19:41 +01:00
Hannes Mannerheim
a3574bac6c we _do_ want to show text/html as attachments, since that's how mustard and crow expands oversized notices 2014-10-20 16:21:42 +02:00
Mikael Nordfeldth
1c04601a9c Removing excessive "inline" attachment listings 2014-08-05 11:30:45 +02:00
Mikael Nordfeldth
17b9614ff8 File->getEnclosure improvements (text/html is not an attachment) 2014-08-05 10:54:00 +02:00
Mikael Nordfeldth
d16af504f6 File basename call lacked a dot 2014-06-22 17:05:11 +02:00
Mikael Nordfeldth
79824a3625 Could not update avatar due to Bad Thumbnail parameters 2014-06-17 12:48:10 +02:00
Mikael Nordfeldth
adf896bc12 Add support for plugins to resize images
This also adds an event hook to get more metadata of the ImageFile.
Such as if it's animated or so.
2014-06-05 13:29:36 +02:00
Mikael Nordfeldth
db443e9374 File::processNew now static and always throws exception on failure 2014-06-02 02:11:23 +02:00
Mikael Nordfeldth
d6f52f5939 File::processNew can return -1 which was not true for empty()
Also, File->getEnclosure() now throws exception if not enough metadata.
2014-06-02 01:46:09 +02:00
Mikael Nordfeldth
2755e23707 Clear out stored files and reltaed thumbnails when a File is deleted. 2014-05-12 15:16:41 +02:00
Mikael Nordfeldth
214a10ddec File_thumbnail fixes (run scripts/upgrade.php)
We're now capable of doing image rotation for thumbnails based on
EXIF orientation data. Also, thumbnails are tracked by filenames and
thus we can delete them from storage when we feel like it.
2014-05-12 14:33:41 +02:00
Mikael Nordfeldth
a7a4eeef09 width and height are now properties in the File class 2014-05-07 09:51:37 +02:00
Mikael Nordfeldth
621533a7c2 Bad variable reference in event hook. 2014-05-06 23:40:45 +02:00
Mikael Nordfeldth
1776c90cb9 Moved oEmbed stuff out to a plugin (Oembed). 2014-05-06 23:32:13 +02:00
Mikael Nordfeldth
cd6bd07c9d Handle File thumbnail errors better 2014-04-28 20:26:32 +02:00
Mikael Nordfeldth
37ce1f4766 Better fallback on UnsupportedMediaException 2014-04-28 12:12:06 +02:00
Mikael Nordfeldth
e526909bd8 File width and height is now properly set for File 2014-04-22 12:09:24 +02:00
Mikael Nordfeldth
d59eb5e184 Dynamically generate thumbnails (see full text)
The File object now stores width and height of files that can
supply this kind of information. Formats which we can not read
natively in PHP do not currently benefit from this. However an
event hook will be introduced later.

The CreateFileImageThumbnail event is renamed to:
CreateFileImageThumbnailSource to clarify that the hooks should not
generate their own thumbnails but only the source image. Also it now
accepts File objects, not MediaFile objects.

The thumbnail generation is documented in the source code. For
developers, call 'getThumbnail' on a File object and hope for the best.

Default thumbnail sizes have increased to be more appealing.
2014-04-21 20:46:11 +02:00
Mikael Nordfeldth
b3bf036975 Preparing File for dynamic thumbnail generation. 2014-04-21 12:33:26 +02:00
Mikael Nordfeldth
43a3f5ea90 File_oembed::saveNew are File::saveNew are static
Also did some non-backwards-compatible (to StatusNet) code cleanup.
2014-04-20 16:10:05 +02:00
Mikael Nordfeldth
d3b4a8616d Original name preserved in uploaded file.
Avoiding collisions with date (shorter than before) and 4 character
random alphanumeric string. I bet someone could mass-upload files
and generate all combinations of aaaa-zzzz during the course of a
day, but then maybe that user should be disabled anyway :)
(filling the collision space will cause a never-ending loop).
2014-04-16 23:17:27 +02:00
Mikael Nordfeldth
06d4cecf7f MediaFile thumbnail event hooks + VideoThumbnails plugin
The exception thrown from MediaFile will be caught and simply result in
no thumbnail at all right now. In the future we might use a catch-all
and have a "cannot generate preview"-icon or something.

VideoThumbnails requires php5-ffmpeg and php5-gd.
2014-04-16 21:48:58 +02:00
Mikael Nordfeldth
639f1a01e0 File class no longer depends on MIME
+ minor tweaks to MediaFile
2014-03-08 03:51:47 +01:00
Jean Baptiste Favre
29f0922705 Add check after oembed API call. In case of error, returned value is false which generate error messages 'Trying to get property of non-object'. 2014-03-02 15:06:06 +01:00
Mikael Nordfeldth
73fe8a81b7 Slight cleanup in typing and syntax of File and File_* classes 2013-11-10 14:33:45 +01:00
Mikael Nordfeldth
48da97f204 MediaFile code improvements, preparing to implement multi-attachments
Maybe in the future we can use this for anonymous file uploads too?
With some kind of anonymous/pseudonymous profile. That'd be neat.
2013-10-05 18:47:45 +02:00
Mikael Nordfeldth
b3e61ce7d0 Stronger typing, require array where param array 2013-08-29 10:27:39 +02:00
Mikael Nordfeldth
2a4dc77a63 The overloaded DB_DataObject function staticGet is now called getKV
I used this hacky sed-command (run it from your GNU Social root, or change the first grep's path to where it actually lies) to do a rough fix on all ::staticGet calls and rename them to ::getKV

   sed -i -s -e '/DataObject::staticGet/I!s/::staticGet/::getKV/Ig' $(grep -R ::staticGet `pwd`/* | grep -v -e '^extlib' | grep -v DataObject:: |grep -v "function staticGet"|cut -d: -f1 |sort |uniq)

If you're applying this, remember to change the Managed_DataObject and Memcached_DataObject function definitions of staticGet to getKV!

This might of course take some getting used to, or modification fo StatusNet plugins, but the result is that all the static calls (to staticGet) are now properly made without breaking PHP Strict Standards. Standards are there to be followed (and they caused some very bad confusion when used with get_called_class)

Reasonably any plugin or code that tests for the definition of 'GNUSOCIAL' or similar will take this change into consideration.
2013-08-18 13:13:56 +02:00
Mikael Nordfeldth
1a9a8ea730 staticGet for sub-Managed_DataObject classes now calls parent
The parent class for our database objects, Managed_DataObject, has a
dynamically assigned class in staticGet which objects get put into,
leaving us with less code to do the same thing.

We will probably have to move away from the DB_DataObject 'staticGet'
call as it is nowadays deprecated.
2013-08-12 19:46:44 +02:00
Siebrand Mazeland
2624afbcd4 Crazy gettext way to support two plurals in one string. 2011-12-28 12:44:42 +01:00
Evan Prodromou
e3c010a870 try to check whether file exists over and over and over 2011-09-30 13:03:42 -04:00
Evan Prodromou
9ca3c3d1c3 move core schema to class files 2011-08-22 17:52:02 -04:00
Evan Prodromou
9a84907d17 Remove unused File::getAttachments() 2011-08-02 23:11:41 -04:00
Evan Prodromou
44bcc942b8 Break up stream code to use separate notice stream classes
Rearchitect (again!) notice stream code to delegate different functionality up and down the stack.

Now, different classes implement NoticeStream.
2011-03-24 18:04:19 -04:00
Evan Prodromou
0b35ce7c37 New NoticeStream class to reify streams of notices
We've been muddling through with 6- or 8-argument functions for managing streams. I'd
like to start thinking of streams as their own thing, and give them some more value.

So, the new NoticeStream class takes over the Notice::stream() function and Notice::getStreamByIds().

There's probably some fine-tuning to do on the object interface.
2011-03-23 11:29:55 -04:00
Brion Vibber
b896a37da0 Use cachedQuery on File::getAttachments, plus other cleanups:
* dropped unnecessary join on notice table
* made the function actually static, since it makes no sense as an instance variable. The only caller (in AttachmentList) is updated.
2011-01-31 12:22:50 -08:00
Evan Prodromou
d31397bd45 method to count notices linking to an URL 2010-12-28 13:44:49 -08:00
Evan Prodromou
faf0081a8b Fixes from testing File::stream() 2010-12-28 12:57:31 -08:00
Evan Prodromou
bf4c5cb41a Stream of notices linking to an URL 2010-12-28 11:58:55 -08:00
Brion Vibber
e1ffbfed04 doc comments on File::processNew 2010-11-15 11:00:42 -08:00
Brion Vibber
dbb95b76a4 Allow YouTube-style media links to be counted as enclosures for purposes of listing attachments/thumbs 2010-11-09 12:04:07 -08:00
Brion Vibber
6d7f02ff31 Pass file attachment thumbnails along with oEmbed data. 2010-11-08 17:22:01 -08:00
Brion Vibber
a2994e3aa2 Testing... using photo info for temp thumbnails 2010-11-08 15:50:06 -08:00
Brion Vibber
883f7a6c0b Avoid marking files as attachments that are not locally uploaded, unless they're really oembedable. HTML-y things now excluded properly. 2010-11-08 13:27:54 -08:00
Siebrand Mazeland
6aeba0cb7c i18n/L10n updates. 2010-11-04 18:33:39 +01:00
Brion Vibber
2692b5fc84 Fix for ticket #2853: fix for some unknown MIME type error cases by adjusting the PEAR error handling temporarily around MIME_Type_Extension usage. 2010-11-03 17:05:26 -07:00
Evan Prodromou
b31c49c5d4 Make HTTPS urls in File::url() if necessary 2010-10-14 14:22:17 -04:00
Siebrand Mazeland
b03ece26eb * i18n/L10n and translator documentation updates.
* whitespace and indentation updates
2010-09-28 23:21:09 +02:00
Siebrand Mazeland
8f8588026b Fixes for messages after review by Brion. 2010-07-30 19:25:55 +02:00
Siebrand Mazeland
5813ecada2 * add translator documentation
* mark strings for translation
* add FIXME for unclear/confusing message
2010-07-29 13:01:04 +02:00
Siebrand Mazeland
e694da24a9 Number parameters 2010-07-28 22:17:54 +02:00
Brion Vibber
dcfe5b24f6 Fix regression in 92ded7c6cb56056a89bc8b3caabd08049104898e: spewed PHP notices when checking for enclosures due to uninitialized variables. 2010-06-28 15:20:50 -04:00
Brion Vibber
696aeea113 Merge branch 'testing' of gitorious.org:statusnet/mainline into 0.9.x
Conflicts:
	lib/language.php
	plugins/OpenID/finishaddopenid.php
2010-05-27 14:57:32 -07:00
Brion Vibber
95159112b2 Hotpatch for infinite redirection-following loop seen processing URLs to http://clojure.org/ -- if we end up with an unstable redirect target (final item in a redirect chain ends up redirecting us somewhere else when we visit it again), just save the last version we saw instead of trying to start over.
Pretty much everything in File and File_redirection initial processing needs to be rewritten to be non-awful; this code is very hard to follow and very easy to make huge bugs. A fair amount of the complication is probably obsoleted by the redirection following being built into HTTPClient now.
2010-05-25 13:09:21 -07:00
Nick Holliday
92ded7c6cb Fixes problem with IRC URLs showing as attachments 2010-03-26 18:16:44 -04:00
Craig Andrews
74fd755556 A null mimetype is not an enclosure (more likely than not means there was an error) 2010-03-11 17:27:25 -05:00
Brion Vibber
c6f09306b1 Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x 2010-03-10 17:04:51 -08:00
Brion Vibber
294b290dd9 Fixup script for files w/ bogus data saved into file record ('h bug') 2010-03-10 15:13:16 -08:00
Brion Vibber
f02cb7c718 Fix for attachment "h bug": posting a shortened link to an oembed-able resource that has been previously used in the system would incorrectly save "h" as the item's type and title. 2010-03-10 15:13:16 -08:00
Brion Vibber
b218aee94e Merge commit 'origin/testing' into 0.9.x
Conflicts:
	lib/action.php
	lib/adminpanelaction.php
2010-03-04 06:07:28 -08:00
Brion Vibber
79ffebb51b OStatus: save file records for enclosures
Also stripping id from foreign HTML messages (could interfere with UI) and disabled failing attachment popup for a.attachment links that don't have a proper id, so you can click through instead of getting an error.

Issues:
* any other links aren't marked and saved
* inconsistent behavior between local and remote attachments (local displays in lightbox, remote doesn't)
* if the enclosure'd object isn't referenced in the content, you won't be offered a link to it in our UI
2010-03-02 16:36:08 -08:00
Craig Andrews
c30f95c55c Updated some references to the long gnone "isEnclosure" function to the new "getEnclosure" 2010-03-02 14:25:06 -08:00
Craig Andrews
a0114f2006 Correctly handle the case when MIME/Type doesn't know what file extension a mime type maps to 2010-03-01 21:44:42 -05:00
Brion Vibber
d5cbfe8071 Merge branch 'testing' into 0.9.x
Conflicts:
	lib/iomaster.php
2010-02-16 09:25:09 -08:00
Evan Prodromou
31461e120f let files go to SSL dir too 2010-02-11 17:06:57 -05:00
Brion Vibber
f4c81fa1e1 Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x 2010-02-02 09:57:50 -08:00
Brion Vibber
51c3606715 Fix regression breaking file attachments. This is what I get for rushing fixes and not properly testing them. :P 2010-02-02 09:32:28 -08:00