116 Commits

Autor SHA1 Mensagem Data
Daniel Supernault 096dda22ce Add User Model 2019-11-02 17:11:43 +00:00
Daniel Supernault 84b5dbb305 Add UserGroup Model 2019-11-02 17:11:43 +00:00
Daniel Supernault a42503817b Add basic ORM implementation 2019-11-02 17:11:40 +00:00
Alexei Sorokin 5f97b139bc [DATABASE] Set SQL NULLs properly as string literals
DataObject_Cast's caused problems in (email|sms)settings,
DataObject handles 'NULL' (case-insensitive) as a special case.
2019-11-01 14:09:09 +01:00
Alexei Sorokin fe3e33e702 [DAEMONS][TwitterBridge] Set PUBLICDIR 2019-11-01 15:27:36 +03:00
Alexei Sorokin 3f56459734 [COMPOSER] Remove some pre-composer remnants from the code 2019-11-01 14:19:42 +03:00
Alexei Sorokin 4903241e4b [DOCUMENTATION][NGINX conf] snippets/fastcgi-php.conf is Debian-specific 2019-11-01 08:52:21 +03:00
Alexei Sorokin 85be003cf5 [Embed][CORE] hex2bin should always get an even amount of symbols 2019-11-01 08:29:52 +03:00
tenma bddc1c0f9d [ActivityPub] Fix successive "Cannot use object of type stdClass as array" errors in the postman 2019-11-01 02:23:39 +00:00
tenma 01f6d83b86 [MODULES] Fix VERSION constant to MODULE_VERSION in various modules 2019-10-30 23:52:14 +00:00
Diogo Cordeiro aa994ee4fb [CORE] Allow to force non-fancy URLs
Essential to allow toggling fancy urls later. In some cases it is
critical to keep the URL an unique URI.
2019-10-27 17:40:37 +00:00
Diogo Cordeiro d058a70557 [MEDIA] Simplify Attachment actions 2019-10-19 02:57:32 +01:00
Diogo Cordeiro 7298468df7 [FILE] Fix Return value of File::getFileOrThumbnailSize() must be of the type int, null returned 2019-10-19 01:16:37 +01:00
Diogo Cordeiro 63caa5044d [LIB_REFACTOR] Fix minor issues 2019-10-19 00:51:52 +01:00
tenma 2ae93dbec6 [ActivityPub] Revert usage of bitwise-operator & in the inbox_handler class. 2019-10-17 20:25:00 +01:00
Diogo Cordeiro b434bead2c [ActivityPub] The protocol allows content to be null, GNU social doesn't, we'll reject silentiously
Reported by kaniini
2019-10-11 19:09:12 +01:00
Diogo Cordeiro 6284b155b8 [ActivityPub] attributedTo itself is not required, if not present then it should be inferred from the actor
Reported by kaniini
2019-10-11 17:51:20 +01:00
Diogo Cordeiro b12c2d17d5 [ActivityPub] Fix security issue concerning remote profile deletes
Reported by kaniini
2019-10-11 17:41:43 +01:00
Diogo Cordeiro 5fb1e26a4c [ActivityPub] Inbox Handler: Remove old guzzle import
Improve exception information in doc blocks
2019-10-11 17:18:50 +01:00
Diogo Cordeiro 6423750250 [ActivityPub] Slightly increase robustness on exception handling
Also ported Activitypub_rsa to PHP7
Minor indentation fixes
2019-10-11 17:08:41 +01:00
Diogo Cordeiro d9b5ef1cee [ActivityPub] Consistent headers in explorer requests
Minor indentation fixes
2019-10-11 16:00:14 +01:00
Miguel Dantas f1717bde51 Fix 'Call to a member function getPayload() on null'
Trying to enable the RedisCache with the latest nightly, getting this with the daemon:

sep 25 11:40:18 friedrich startdaemons.sh[21428]: PHP Fatal error:  Uncaught Error: Call to a member function getPayload() on null in /var/www/social/plugins/RedisCache/RedisCachePlugin.php:96
sep 25 11:40:18 friedrich startdaemons.sh[21428]: Stack trace:
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #0 /var/www/social/lib/util/event.php(89): RedisCachePlugin->onStartCacheSet('gnusocial:herds...', Object(HubSub), NULL, 86400, false)
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #1 /var/www/social/lib/cache/cache.php(202): Event::handle('StartCacheSet', Array)
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #2 /var/www/social/classes/Memcached_DataObject.php(520): Cache->set('gnusocial:herds...', Object(HubSub))
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #3 /var/www/social/classes/Memcached_DataObject.php(52): Memcached_DataObject->encache()
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #4 /var/www/social/classes/Managed_DataObject.php(50): Memcached_DataObject::getClassKV('HubSub', 'hashkey', 'a38b9dc516371af...')
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #5 /var/www/social/plugins/OStatus/classes/HubSub.php(47): Managed_DataObject::getKV('hashkey', 'a38b9dc516371af...')
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #6 /var/www/social/plugins/OStatus/lib/hubprepqueuehandler.php(68): HubSub::getByHashkey('https://herds.e...', 'https://raki.so...')
sep 25 11:40:18 friedrich startdaemons.sh[21428]: #7 /var/www/social/plugins/RedisQueue/classes/RedisQueueManager.php(58): HubPrepQueueHandl in /var/www/social/plugins/RedisCache/RedisCachePlugin.php on line 96
Sign in to j
2019-09-26 11:29:31 +01:00
Miguel Dantas c6f4f40bba [Embed][CORE] Fixes 'Invalid Filename' on Embed. Regex didn't get updated 2019-09-26 11:29:31 +01:00
Alexei Sorokin 65f1b1e1e3 Fix minor git merge resolving issues 2019-09-18 17:43:00 +03:00
Alexei Sorokin ad91ef66bd [SCRIPTS] Set PUBLICDIR in plugin scripts as well 2019-09-18 17:15:00 +03:00
Alexei Sorokin 6bfa593988 [DAEMONS] Move resetDb to the Daemon class
As it is used inside the Daemon class now, it should always be available.
2019-09-13 22:08:42 +03:00
Diogo Cordeiro 3ea580b537 [ActivityPub] Add missing parenthesis in class instantiation
Fixed some issues related to thrown exceptions in the doblocks; also boolean -> bool
2019-09-13 18:58:41 +01:00
Alexei Sorokin 87b0b493eb [ActivityPub] Fix an unhandled error in onStartGetProfileFromURI 2019-09-13 20:55:23 +03:00
Diogo Cordeiro 4eb4a2de00 [ActivityPub] Fix some bugs with onStartNoticeSearch
Refactored Activitypub_profile::ensure_web_finger to Activitypub_profile::ensure_webfinger
Do not throw exceptions in the handling of this event because we don't
want to stop the regular search just because we were unable to find
ActivityPub actors or notes.
2019-09-13 18:10:20 +01:00
Alexei Sorokin 1f2f57b03b [CORE] Fix logging of very early failures 2019-09-13 12:11:43 +03:00
Alexei Sorokin 4afaad3df5 [DATABASE][MariaDB] Properly account for foreign keys 2019-09-13 10:34:48 +03:00
Diogo Cordeiro c3ba2e0f94 [BugFix] Plugins ExtendedProfile and OverwriteThemeBackground - admin is identical to system path names. 2019-09-12 23:18:50 +01:00
Alexei Sorokin 693c3168da [OStatus] The unsubscribe state also needs a label 2019-09-12 14:19:21 +03:00
Alexei Sorokin 8f309bc768 Merge branch 'pgsql_support' into nightly 2019-09-12 12:01:50 +03:00
Alexei Sorokin 1a0d6a90c2 [INSTALL] Fix lib/util/installer.php import path 2019-09-12 11:52:04 +03:00
Diogo Cordeiro 7f2019b4af [MODULES] Make disable in admin panel effective 2019-09-12 04:50:46 +01:00
Alexei Sorokin ee7f0a2016 [DATABASE] Re-introduce PostgreSQL support 2019-09-11 14:14:40 +03:00
Alexei Sorokin 644b417f6c [DATABASE] Use "<>" as an SQL non-equality sign
"!=" is not SQL compliant.
2019-09-11 13:27:36 +03:00
Alexei Sorokin 471576d6e8 [DATABASE] Columns not in GROUP BY must not be queried 2019-09-11 13:12:41 +03:00
Alexei Sorokin 7ee8aa7838 [DATABASE] Re-introduce the enum type abstraction 2019-09-11 12:48:28 +03:00
Alexei Sorokin af63e9a7ad [DATABASE] Set all primary keys as "not null" explicitly 2019-09-11 12:27:40 +03:00
Alexei Sorokin 95c7344557 [DATABASE] Various table schema related fixes 2019-09-11 12:07:54 +03:00
Alexei Sorokin 0c936e54ba [DATABASE] Re-order tables to be created
Foreign keys need to be created after the respective tables are already in
place. This order makes sure this is the case.
2019-09-11 11:56:36 +03:00
Alexei Sorokin 62b90c29db [DATABASE] Introduce a bool type in schema
PostgreSQL has a clear distinction between integers and booleans, so it makes
sense to draw a clear line.
2019-09-11 11:25:39 +03:00
Alexei Sorokin 6911b499d3 [DATABASE] Consistently use the "LIMIT $limit OFFSET $offset" syntax
The "LIMIT $offset, $limit" syntax is only supported by MySQL and MariaDB.
2019-09-11 10:12:49 +03:00
Alexei Sorokin 44f4c9374d [DATABASE] Use time intervals in a SQL standard compliant way 2019-09-11 09:58:13 +03:00
Alexei Sorokin 11dabbe44d [DATABASE] Only use single quotation marks for SQL strings
Double quotation marks are only used for identifiers in the SQL standard.
2019-09-11 09:46:30 +03:00
Alexei Sorokin 0a5a3845db [DATABASE] Set NULL in DB_DataObject in a more reliable manner
Also stop assuming that FeedSub::sub_state (enum) and FeedSub::sub_end
(datetime) can possibly be set to an empty string.
2019-09-11 08:32:19 +03:00
Alexei Sorokin 5b797328f2 [DATABASE] Always quote identifiers
The code used to operate under the assumption that MariaDB doesn't support
quoting identifiers. Not only is that not exactly true, but MariaDB has
reserved keywords that cannot be used as table or column names unquoted.
2019-09-11 08:15:16 +03:00
Alexei Sorokin b89f1ad7d8 [CORE] Another inboxnoticestream improvement 2019-09-10 22:25:45 +03:00
Alexei Sorokin b0104d9992 [DAEMONS] Switch daemons to double-forking for daemonisation 2019-09-10 21:14:27 +03:00
Alexei Sorokin 9d8f4c774f [DAEMONS] Properly disconnect daemons from the database 2019-09-10 20:25:28 +03:00
Diogo Cordeiro 8b7a22ecd9 Merge branch 'nightly' of biodantas/gnu-social into nightly 2019-09-10 17:11:00 +00:00
Miguel Dantas a4e6db8d76 [OpportunisticQM] Revamped plugin to be able to use other poll based queuemanagers, no just the DB 2019-09-05 01:39:00 +02:00
Miguel Dantas 78506d5249 [StompQueue] Changed StompQueueManager to use polling rather than sockets 2019-09-05 01:39:00 +02:00
Miguel Dantas 6747b18b75 [PLUGINS] Added UnQueue, a new default plugin which does all actions immediately 2019-09-05 01:39:00 +02:00
Miguel Dantas 544f13c52a [PLUGINS] Added DBQueue plugin 2019-09-05 01:38:59 +02:00
Miguel Dantas 4644f6e96b [PLUGINS] Added StompQueue plugin, based on the implementation in lib/queue/stompqueuemanager. Updated to new STOMP library version. Dropped liberalstomp.php and stompqueuemanager.php 2019-09-05 01:38:40 +02:00
Miguel Dantas a3b228399b [PLUGINS] Added RedisQueue 2019-09-03 14:01:27 +01:00
Miguel Dantas 100a557c7c [CORE][AUTOLOAD] Fix class OAuthRequest not found
Issue description as reported by aab:

2019-08-28 17:34:48 LOG_ERR: [khp.ignorelist.com:61055.f5f7f51c GET /api/statuses/show/178372.atom] ServerErrorAction: 500 Class 'OAuthRequest' not found
2019-08-28 17:39:50 LOG_ERR: [khp.ignorelist.com:65390.4483ff85 GET /api/statusnet/conversation/104672.rss] Handled serverError (500) but cannot output into desired format ('rss'): 'Class \'OAuthRequest\' not found'
2019-08-28 17:39:50 LOG_ERR: [khp.ignorelist.com:65390.4483ff85 GET /api/statusnet/conversation/104672.rss] ServerErrorAction: 500 Class 'OAuthRequest' not found
2019-08-28 17:40:49 LOG_ERR: [khp.ignorelist.com:65390.4c745f68 GET /api/statuses/show/18132.atom] Handled serverError (500) but cannot output into desired format ('atom'): 'Class \'OAuthRequest\' not found'
2019-08-28 17:40:49 LOG_ERR: [khp.ignorelist.com:65390.4c745f68 GET /api/statuses/show/18132.atom] ServerErrorAction: 500 Class 'OAuthRequest' not found
2019-08-28 17:47:41 LOG_ERR: [khp.ignorelist.com:65390.42ee9fd4 GET /api/statusnet/conversation/133023.as] Handled serverError (500) but cannot output into desired format ('as'): 'Class \'OAuthRequest\' not found'
2019-09-03 03:33:14 +01:00
Miguel Dantas 6acc75ccff [FRAMEWORK][AUTOLOAD] Fix autoloads 2019-09-03 03:33:14 +01:00
Miguel Dantas b41f9620fa [LIB_REFACTOR] Fix requires 2019-09-03 03:33:13 +01:00
Miguel Dantas 58bde08425 [LIB_REFACTOR] Moving files into separate semantic categories 2019-09-03 03:33:13 +01:00
Miguel Dantas 7d6c6edab3 [RedisCache] Fix call to getPayload on int. The library is badly documented, but seems to return the TTL instead of the normal redis response
Issue description as reported by aab:

About one day after enabling redis plugin:

PHP Fatal error:  Uncaught Error: Call to a member function getPayload() on int in /var/www/html/plugins/RedisCache/RedisCachePlugin.php:96
Stack trace:
0 /var/www/html/lib/event.php(89): RedisCachePlugin->onStartCacheSet('gnusocial:gatea...', Object(Queue_item), NULL, 86400, false)
1 /var/www/html/lib/cache.php(202): Event::handle('StartCacheSet', Array)
2 /var/www/html/classes/Memcached_DataObject.php(496): Cache->set('gnusocial:gatea...', Object(Queue_item))
3 /var/www/html/classes/Memcached_DataObject.php(416): Memcached_DataObject->encache()
4 /var/www/html/classes/Managed_DataObject.php(620): Memcached_DataObject->update(Object(Queue_item))
5 /var/www/html/classes/Queue_item.php(74): Managed_DataObject->update(Object(Queue_item))
6 /var/www/html/lib/dbqueuemanager.php(75): Queue_item::top(Array, Array)
7 /var/www/html/lib/iomaster.php(287): DBQueueManager->poll()
8 /var/www/html/lib/iomaster.php(161): IoMaster->poll()
9 /var/www/html/scripts/queuedaemon.php(112): IoMaster->service()
10 /var/www/html/lib/spawni in /var/www/html/plugins/RedisCache/RedisCachePlugin.php on line 96
2019-09-03 03:31:59 +01:00
Miguel Dantas d209964718 [Memcached] Fix call to undefined method close
Issue description as reported by aab:

Memcached config in config.php:

    addPlugin('Memcached', [ 'servers' => ['127.0.0.1', 11211],
                             'defaultExpiry' => 86400 // 24h
                           ]);

Memcached and php-memchached installed.

The error appears when executing startdaemons.

Log:

    PHP Fatal error:  Uncaught Error: Call to undefined method Memcached::close() in /var/www/html/plugins/Memcached/MemcachedPlugin.php:202
    Stack trace:
    #0 /var/www/html/lib/event.php(89): MemcachedPlugin->onStartCacheReconnect(false)
    #1 /var/www/html/lib/cache.php(273): Event::handle('StartCacheRecon...', Array)
    #2 /var/www/html/lib/spawningdaemon.php(209): Cache->reconnect()
    #3 /var/www/html/lib/spawningdaemon.php(188): SpawningDaemon->resetDb()
    #4 /var/www/html/lib/spawningdaemon.php(118): SpawningDaemon->initAndRunChild(3)
    #5 /var/www/html/lib/daemon.php(168): SpawningDaemon->run()
    #6 /var/www/html/scripts/queuedaemon.php(186): Daemon->runOnce()
    #7 {main}
      thrown in /var/www/html/plugins/Memcached/MemcachedPlugin.php on line 202
2019-09-03 03:30:07 +01:00
Miguel Dantas c03f659efb [Embed] Fix use of undefined img_data
Got error 'PHP message: PHP Notice: Undefined variable: img_data in /var/www/html/plugins/Embed/EmbedPlugin.php on line 544'
2019-09-03 03:29:32 +01:00
tenma 2e66cbeb60 [CORE] Fix undefined offset warnings in different files
This problem was presentend in the following issue:
https://notabug.org/diogo/gnu-social/issues/60

AcceptHeader/util:
- Perform isset before using the required array values
2019-09-03 03:26:35 +01:00
tenma 19409cb999 [ActivityPub] Add support fox search-box profile/notice grabbing
NoticeSearchAction:
- Add new event before finding query matches

ActivityPubPlugin:
- Subscribe new searchNotice event
- Bump minor version number

Activitypub_explorer:
- Update lookup to make remote-grabbing optional
2019-09-03 03:26:35 +01:00
tenma c06182c38f [ActivityPub] Handle DELETE-Person activity
ActivityPubPlugin:
- update grab_notice_from_url to make online grab optional
- subscribe events of user and profile deletion
- bump minor version number

Activitypub_inbox_handler:
- separate handle_delete for delete-note and delete-person

Activitypub_postman:
- add delete-person logic

Activitypub_delete:
- update validation method to check for the "Person" type
- update to_array method to target the activity
2019-09-03 03:26:35 +01:00
Miguel Dantas f79cd8cee3 [CORE] Fix small bug where Notice was sending a JSON representation to the queue, instead of sending itself 2019-09-03 03:26:35 +01:00
tenma c130739de0 [AP] Fix subscription events
Both StartSubscribe and StartUnsubscribe had a wrong initial if-condition.
Furthermore, this events were calling Activitypub_profile::from_profile()
which is wrong because it creates the Activitypub_profile object when
the goal is only to check if it exists already.
2019-09-03 03:26:35 +01:00
tenma 1a4a1583d5 [AP] Subscribe RemoteFollow plugin events for allowing following with the remote-follow button 2019-09-03 03:26:35 +01:00
tenma 3633ca04eb [OStatus] Port remote-follow to the RemoteFollow plugin
OStatusPlugin:
- Stop adding the remote-follow button
- Subscribe to required RemoteFollow plugin events
- Drop main/ostatussub route and update urls to the main/RemoteFollowSub route
- Bump plugin minor version number

actions/ostatusgroup,
actions/ostatuspeopletag:
- Update urls to the main/RemoteFollowSub route

lib/util:
- Port required functions from OStatusSubAction and adapt to be used with the new events
2019-09-03 03:26:35 +01:00
tenma e61c0c45aa [RemoteFollow] Initial work in the RemoteFollow plugin
lib/default.php
- Add RemoteFollow to the list of default plugins

RemoteFollowPlugin:
- Subscribe events to add the remote-follow button

RemoteFollowInitAction:
- Handles the remote-follow form and getting the redirection url for follow completion

RemoteFollowSubAction:
- Handles the remote profile pulling and actual following
2019-09-03 03:26:35 +01:00
Miguel Dantas 6d81848f25 [URLMAPPER] Fix small bug in URLMapper: a dynamic route might not exist even if a static one does 2019-09-03 03:26:35 +01:00
Miguel Dantas 10b3b343dd [DirectMessage] Fixed use of incorrect type which prevented posting notices with only one word 2019-09-03 03:26:35 +01:00
tenma f6fd025be2 [AP] Update version info 2019-09-03 03:26:35 +01:00
tenma b5897687a6 [AP] Prevent postman to include the actor's followers for every sent activity 2019-09-03 03:26:35 +01:00
tenma ebeae261de [AP] Support Private Messaging
ActivityPubPlugin:
- Subscribe DirectMessage events

Activitypub_inbox_handler:
- Update handle_create_note to create private messages

Activitypub_postman:
- Add create_direct_note for sending private messages

Activitypub_create:
- Update create_to_array to support the 'directMessage' attribute
- Add isPrivateNote to verify private activities

Activitypub_notice:
- Update create_note to support the 'directMessage' attribute
- Remove isPrivateNote

lib/models:
- Add Activitypub_message, the model in charge of private notes
2019-09-03 03:26:35 +01:00
tenma 9733f3c02c [AP] Fix Follow collections
Activitypub_profile:
- Fix subscription-counter getter functions, invalid profiles were being counted

apActorFollowingAction:
- Small rewrite of generate_following, didn't make sense to not use try-catch block

apActorFollowersAction:
- Small rewrite of generate_followers, didn't make sense to not use try-catch block
2019-09-03 03:26:35 +01:00
tenma 217c8a3933 [AP] Handle unlisted/followers-only notices
Note that this commit isn't intended to add support for sending such notes
in GS. Instead, we handle the reception, storage and direct reply to this
type of notices, in AP.

ActivityPubPlugin:
- Subscribe the event StartNoticeSave to hack answering non-public notes

Activitypub_create:
- Add 'directMessage' attribute to the Create activity, defaulting to false for now
- Update validation method: validate 'directMessage' and add debug

Activitypub_notice:
- Handle incoming unlisted/followers-only notes
- Add support for unlisted-replies
- Add method to verify private (direct) notices

inbox_handler:
- Add handler for CREATE Note
- Prepare logic for private-messaging
- Overall refactor: Class members were continuously being passed as function arguments without need

SharePlugin:
- Stop showing the announce button in non public posts
2019-09-03 03:26:35 +01:00
tenma 7188d81ad4 [AP] Properly target public notices
ActivityPubPlugin:
- Use TO as principal audience, CC as secondary
- Update note validation
2019-09-03 03:26:35 +01:00
Miguel Dantas 48cacd6d9d [RedisCache] Added plugin description, fixes 'empty msgid' error 2019-09-03 03:26:35 +01:00
Diogo Cordeiro 1e378a514d [OverwriteThemeBackground] This new plugin will let the admin set a custom background theme independent 2019-09-03 03:26:35 +01:00
Diogo Cordeiro 92ab5e18ee [ExtendedProfile] Fix Admin menu option 2019-08-24 01:59:42 +01:00
Diogo Cordeiro b42af10905 [MODULES] Allow to delete third party plugins 2019-08-24 01:59:42 +01:00
Diogo Cordeiro afe8158cb7 [MODULES] Allow to upload third party plugins
Fixed some bugs
2019-08-24 01:59:42 +01:00
Diogo Cordeiro a05bea0af5 [MODULES] List all available plugins and allow enabling them via UI
Yet another revision of the Admin Plugin Management tool
2019-08-24 01:59:41 +01:00
Diogo Cordeiro e1514a151c [DOCUMENTATION][DEVELOPERS][PLUGINS] Some updates to Plugins doc 2019-08-24 01:59:41 +01:00
Diogo Cordeiro 2a82cfdb2a [TagCloud] Add Readme 2019-08-24 01:59:40 +01:00
Diogo Cordeiro 49da433879 [SearchSub][README] No longer is a default plugin since 8614cd77 2019-08-24 01:59:40 +01:00
Diogo Cordeiro 92388e1734 [SamplePlugin] Review and update with the latest GNU social best practices 2019-08-24 01:59:40 +01:00
Diogo Cordeiro 3860c25dc0 [ConversationTree] Format the plugin, add strict typing and fix docblocks 2019-08-24 01:59:39 +01:00
Diogo Cordeiro 25ee5ed1f9 [OfflineBackup] Fix plugin 2019-08-24 01:59:39 +01:00
Diogo Cordeiro 566214ac62 [PLUGINS] Removed OpenX as the service doesn't exist anymore 2019-08-24 01:59:39 +01:00
Diogo Cordeiro 1459f10803 [GroupFavorited] Fix plugin 2019-08-24 01:59:38 +01:00
Diogo Cordeiro 0795a39459 [ExtendedProfile] Hide 'Extra fields' from profile when no field was created by the sysadmin 2019-08-24 01:59:38 +01:00
Diogo Cordeiro e5831d6807 [ExtendedProfile] Allow to delete custom profile field 2019-08-24 01:59:38 +01:00
Diogo Cordeiro 88bdb5114f [Plugins] Incorporated GNUsocialExtendedProfile as part of ExtendedProfile
Also improved a lot of the plugin and made things in a way it would make sense
2019-08-24 01:59:37 +01:00
Diogo Cordeiro 90bd9088bb [GNUsocialProfileExtensions] Fixed plugin 2019-08-24 01:59:37 +01:00
Diogo Cordeiro 01cf8ab82c [PLUGINS] Removed GNUsocial{Photo, Photos, Video} as we don't need them anymore 2019-08-24 01:59:36 +01:00
Diogo Cordeiro aee5506f00 [PLUGINS] Removed GeoURL as the service doesn't exist anymore 2019-08-24 01:59:36 +01:00
Diogo Cordeiro b6183f2de1 [ForceGroup] Modernized plugin and improved documentation 2019-08-24 01:59:36 +01:00
Diogo Cordeiro 452e0fe553 [DEFAULT] Add 'DirectionDetector' as a default plugin 2019-08-24 01:59:35 +01:00
Diogo Cordeiro 2f341a3369 [ChooseTheme] Fixed plugin 2019-08-24 01:59:35 +01:00
Diogo Cordeiro 66e55d1a1f [BlankAd] Fixed plugin 2019-08-24 01:59:34 +01:00
Diogo Cordeiro 63fac32bc0 [Awesomeness] Fixed plugin 2019-08-24 01:59:34 +01:00
Diogo Cordeiro aaeaeba57c [DEFAULT] Add 'AccountManager' as a default plugin 2019-08-24 01:59:34 +01:00
Diogo Cordeiro d3c56897a3 [CORE] Core modules shouldn't show up in version action 2019-08-24 01:59:33 +01:00
Diogo Cordeiro 0c2c3ec862 [CORE] Plugin API now extends a new Module API 2019-08-24 01:59:33 +01:00
Diogo Cordeiro b6e7b18c7b [PLUGIN API] Bug fixes and improvements 2019-08-24 01:59:32 +01:00
Diogo Cordeiro 55d049b1e8 [CORE] Move plugin superclasses from /lib/ to /lib/modules/ 2019-08-22 03:13:58 +01:00
Diogo Cordeiro 8c0601816f [CORE] Move core plugins to a new modules directory
For reference (raised by rozzin in IRC):

* http://foldoc.org/module
* http://foldoc.org/library
* http://foldoc.org/plugin

As noted by XRevan86, modules are not necessarily non-essential.
As we will keep the modules directory in GS root [therefore, near to
plugins/], it is evidenced the difference between both.

This is a simple yet fundamental structural change. It doesn't change
functionality but makes clearer the way we understand GNU social's
internals.
2019-08-22 03:13:58 +01:00
Miguel Dantas 350cde08d8 [Embed] Added support for inline images 2019-08-22 03:13:58 +01:00
tenma db5a29fd9a [DirectMessage] Major plugin rework
This commit does the necessary rework to store private messages
as Notices and to support Federation. The plugin's README presents
some more detail about the changes and future work that is still
required to do.
2019-08-22 03:13:58 +01:00
tenma 0716605e94 [CORE][ROUTES] Update urlmapper to search dynamic routes before static ones when generating URLs.
This solves the problem of routes that differ only in having
or not $_GET params. The ones not having params (static) were
being matched first during URL generation.

The way this problem was solved was by separating the $reverse
array in both $reverse_statics and $reverse_dynamics and explicitly
traversing this last one first in the generation function. Note that
maintaining the $reverse array and unshifting dynamic routes to its
head ( and therefore to the front of the static ones ) doesn't work
since even among dynamic routes the order of arrival should be kept.
2019-08-22 03:13:58 +01:00
2237 arquivos alterados com 182284 adições e 12591 exclusões
+13
Ver Arquivo
@@ -1496,3 +1496,16 @@ StartDocNav: Before outputting the docs Nav
EndDocNav: After outputting the docs Nav
- $nav: The DoclNav widget
StartNoticeSearch: Before finding notices that match the given query
- string $query: The text query
StartNoticeSearchShowResults: Before displaying notices matching the query
- $out: HTMLOutputter used to output
- $query: The text query
- $notices: Array of DB notice objects
EndNoticeSearchShowResults: After displaying notices matching the query
- $out: HTMLOutputter used to output
- $query: The text query
- $notices: Array of DB notice objects
@@ -17,13 +17,8 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
<<<<<<< HEAD
#. TRANS: Plugin description for a sample plugin.
#: AwesomenessPlugin.php:55
=======
#. TRANS: Module description for a sample plugin.
#: AwesomenessModule.php:67
>>>>>>> 6b0ad03771... [PLUGINS] Removed GeoURL as the service doesn't exist anymore
msgid ""
"The Awesomeness plugin adds additional awesomeness to a GNU social "
"installation."
+6 -10
Ver Arquivo
@@ -164,10 +164,9 @@ The ones that you may want to set are listed below for clarity.
* `database` (string, required, default null): a DSN (Data Source Name) for your
GNU social database. This is in the format
'protocol://username:password@hostname/databasename', where 'protocol' is '
mysql' or 'mysqli' (or possibly 'postgresql', if you really know what
you're doing), 'username' is the username, 'password' is the password,
and etc.
'protocol://username:password@hostname/databasename', where 'protocol' is
'mysqli' or 'pgsql' or 'mysql', 'username' is the username, 'password' is
the password, and etc.
* `ini_yourdbname` (string, default null): if your database is not named 'statusnet',
you'll need to set this to point to the location of the statusnet.ini file.
@@ -178,12 +177,9 @@ The ones that you may want to set are listed below for clarity.
'MDB2' to use the other driver type for DB_DataObject, but note that it
breaks the OpenID libraries, which only support PEAR::DB.
* `quote_identifiers`(boolean, default false): Set this to true if you're using
postgresql.
* `type` (enum["mysql", "postgresql"], default 'mysql'): Used for certain
database-specific optimization code. Assumes mysql if not set. MySQL also
covers MySQLi and MariaDB.
* `type` (enum["mysql", "pgsql"], default 'mysql'): Used for certain
database-specific optimization code. Assumes mysql if not set. "mysql"
covers MariaDB, Oracle MySQL, mysqli or otherwise.
* `mirror` (array, default null): you can set this to an array of DSNs, in the
format of the above 'database' value. If it's set, certain read-only
@@ -43,10 +43,16 @@ server {
location ~ ^/(index|install)\.php(/.*)?$ {
#location ^~ /index.php {
include fastcgi_params;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
fastcgi_pass unix:/run/php/php7.X-fpm.sock;
fastcgi_index index.php;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Don't allow any PHP file other than index.php to be executed
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/togglepeopletag.php';
require_once INSTALLDIR . '/lib/profile/togglepeopletag.php';
/**
*
+39 -51
Ver Arquivo
@@ -1,55 +1,45 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Show the newest groups
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category API
* @package StatusNet
* @package GNUsocial
* @author Craig Andrews <candrews@integralblue.com>
* @author Evan Prodromou <evan@status.net>
* @author Jeffery To <jeffery.to@gmail.com>
* @author Zach Copley <zach@status.net>
* @copyright 2009 StatusNet, Inc.
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Returns of the lastest 20 groups for the site
*
* @category API
* @package StatusNet
* @author Craig Andrews <candrews@integralblue.com>
* @author Evan Prodromou <evan@status.net>
* @author Jeffery To <jeffery.to@gmail.com>
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @copyright 2009 StatusNet, Inc.
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class ApiGroupListAllAction extends ApiPrivateAuthAction
{
var $groups = null;
public $groups = null;
/**
* Take arguments for running
@@ -58,7 +48,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return boolean success flag
*/
function prepare(array $args = array())
public function prepare(array $args = [])
{
parent::prepare($args);
@@ -77,7 +67,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return void
*/
function handle()
public function handle()
{
parent::handle();
@@ -90,7 +80,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
// TRANS: Message is used as a subtitle when listing the latest 20 groups. %s is a site name.
$subtitle = sprintf(_("groups on %s"), $sitename);
switch($this->format) {
switch ($this->format) {
case 'xml':
$this->showXmlGroups($this->groups);
break;
@@ -128,21 +118,20 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return array groups
*/
function getGroups()
public function getGroups()
{
$qry = 'SELECT user_group.* '.
'from user_group join local_group on user_group.id = local_group.group_id '.
'order by created desc ';
$offset = intval($this->page - 1) * intval($this->count);
$limit = intval($this->count);
if (common_config('db', 'type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
$group = new User_group();
$group->query($qry);
$offset = intval($this->page - 1) * intval($this->count);
$limit = intval($this->count);
$group->query(
'SELECT user_group.* '.
'FROM user_group INNER JOIN local_group ' .
'ON user_group.id = local_group.group_id '.
'ORDER BY created DESC ' .
'LIMIT ' . $limit . ' OFFSET ' . $offset
);
$groups = array();
while ($group->fetch()) {
@@ -159,7 +148,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return boolean true
*/
function isReadOnly($args)
public function isReadOnly($args)
{
return true;
}
@@ -169,7 +158,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return string datestamp of the site's latest group
*/
function lastModified()
public function lastModified()
{
if (!empty($this->groups) && (count($this->groups) > 0)) {
return strtotime($this->groups[0]->created);
@@ -186,10 +175,9 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return string etag
*/
function etag()
public function etag()
{
if (!empty($this->groups) && (count($this->groups) > 0)) {
$last = count($this->groups) - 1;
return '"' . implode(
+1 -1
Ver Arquivo
@@ -30,7 +30,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/apilistusers.php';
require_once INSTALLDIR . '/lib/api/apilistusers.php';
class ApiListMembersAction extends ApiListUsersAction
{
+1 -1
Ver Arquivo
@@ -29,7 +29,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/apilistusers.php';
require_once INSTALLDIR . '/lib/api/apilistusers.php';
class ApiListSubscribersAction extends ApiListUsersAction
{
+1 -1
Ver Arquivo
@@ -35,7 +35,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/atomlistnoticefeed.php';
require_once INSTALLDIR . '/lib/feeds/atomlistnoticefeed.php';
/**
* Returns the most recent notices (default 20) posted to the list specified by ID
+69 -67
Ver Arquivo
@@ -1,33 +1,20 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Show notice attachments
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Personal
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Show notice attachments
@@ -43,7 +30,13 @@ class AttachmentAction extends ManagedAction
/**
* Attachment File object to show
*/
var $attachment = null;
public $attachment = null;
public $filehash = null;
public $filepath = null;
public $filesize = null;
public $mimetype = null;
public $filename = null;
/**
* Load attributes based on database arguments
@@ -52,41 +45,48 @@ class AttachmentAction extends ManagedAction
*
* @param array $args $_REQUEST array
*
* @return success flag
* @return bool flag
* @throws ClientException
* @throws FileNotFoundException
* @throws FileNotStoredLocallyException
* @throws InvalidFilenameException
* @throws ServerException
*/
protected function prepare(array $args=array())
protected function prepare(array $args = [])
{
parent::prepare($args);
try {
if (!empty($id = $this->trimmed('attachment'))) {
$this->attachment = File::getByID($id);
} elseif (!empty($filehash = $this->trimmed('filehash'))) {
$this->attachment = File::getByHash($filehash);
} elseif (!empty($this->filehash = $this->trimmed('filehash'))) {
$this->attachment = File::getByHash($this->filehash);
}
} catch (Exception $e) {
// Not found
}
if (!$this->attachment instanceof File) {
// TRANS: Client error displayed trying to get a non-existing attachment.
$this->clientError(_('No such attachment.'), 404);
$this->clientError(_m('No such attachment.'), 404);
}
$filename = $this->attachment->getFileOrThumbnailPath();
if (empty($filename)) {
$this->clientError(_('Requested local URL for a file that is not stored locally.'), 404);
$this->filepath = $this->attachment->getFileOrThumbnailPath();
if (empty($this->filepath)) {
$this->clientError(_m('Requested local URL for a file that is not stored locally.'), 404);
}
$this->filesize = $this->attachment->getFileOrThumbnailSize();
$this->mimetype = $this->attachment->getFileOrThumbnailMimetype();
$this->filename = MediaFile::getDisplayName($this->attachment);
return true;
}
/**
* Is this action read-only?
*
* @return boolean true
* @return bool true
*/
function isReadOnly($args)
public function isReadOnly($args): bool
{
return true;
}
@@ -96,15 +96,15 @@ class AttachmentAction extends ManagedAction
*
* @return string title of the page
*/
function title()
public function title(): string
{
$a = new Attachment($this->attachment);
return $a->title();
}
public function showPage()
public function showPage(): void
{
if (empty($this->attachment->getFileOrThumbnailPath())) {
if (empty($this->filepath)) {
// if it's not a local file, gtfo
common_redirect($this->attachment->getUrl(), 303);
}
@@ -119,10 +119,10 @@ class AttachmentAction extends ManagedAction
*
* @return void
*/
function showContent()
public function showContent(): void
{
$ali = new Attachment($this->attachment, $this);
$cnt = $ali->show();
$ali->show();
}
/**
@@ -130,7 +130,7 @@ class AttachmentAction extends ManagedAction
*
* @return void
*/
function showPageNoticeBlock()
public function showPageNoticeBlock(): void
{
}
@@ -139,7 +139,8 @@ class AttachmentAction extends ManagedAction
*
* @return void
*/
function showSections() {
public function showSections(): void
{
$ns = new AttachmentNoticeSection($this);
$ns->show();
}
@@ -148,13 +149,14 @@ class AttachmentAction extends ManagedAction
* Last-modified date for file
*
* @return int last-modified date as unix timestamp
* @throws ServerException
*/
public function lastModified()
public function lastModified(): ?int
{
if (common_config('site', 'use_x_sendfile')) {
return null;
}
$path = $this->attachment->getFileOrThumbnailPath();
$path = $this->filepath;
if (!empty($path)) {
return filemtime($path);
} else {
@@ -169,26 +171,26 @@ class AttachmentAction extends ManagedAction
* but in decimal instead of hex.
*
* @return string etag http header
* @throws ServerException
*/
function etag()
public function etag(): string
{
if (common_config('site', 'use_x_sendfile')) {
return null;
}
$path = $this->attachment->getFileOrThumbnailPath();
$path = $this->filepath;
$cache = Cache::instance();
if($cache) {
if ($cache) {
if (empty($path)) {
return null;
}
$key = Cache::key('attachments:etag:' . $path);
$etag = $cache->get($key);
if($etag === false) {
if ($etag === false) {
$etag = crc32(file_get_contents($path));
$cache->set($key,$etag);
$cache->set($key, $etag);
}
return $etag;
}
@@ -205,30 +207,30 @@ class AttachmentAction extends ManagedAction
* Include $filepath in the response, for viewing and downloading.
* If provided, $filesize is used to size the HTTP request,
* otherwise it's value is calculated
* @param string $filepath the absolute path to the file to send
* @param $filesize optional, calculated if unkown
* @throws ServerException
*/
static function sendFile(string $filepath, $filesize) {
public function sendFile(): void
{
if (is_string(common_config('site', 'x-static-delivery'))) {
$tmp = explode(INSTALLDIR, $filepath);
$tmp = explode(INSTALLDIR, $this->filepath);
$relative_path = end($tmp);
common_debug("Using Static Delivery with header: '" .
common_config('site', 'x-static-delivery') . ": {$relative_path}'");
header(common_config('site', 'x-static-delivery') . ": {$relative_path}");
} else {
if (empty($filesize)) {
$filesize = filesize($filepath);
if (empty($this->filesize)) {
$this->filesize = filesize($this->filepath);
}
header("Content-Length: {$filesize}");
header("Content-Length: {$this->filesize}");
// header('Cache-Control: private, no-transform, no-store, must-revalidate');
$ret = @readfile($filepath);
$ret = @readfile($this->filepath);
if ($ret === false) {
common_log(LOG_ERR, "Couldn't read file at {$filepath}.");
} elseif ($ret !== $filesize) {
common_log(LOG_ERR, "Couldn't read file at {$this->filepath}.");
} elseif ($ret !== $this->filesize) {
common_log(LOG_ERR, "The lengths of the file as recorded on the DB (or on disk) for the file " .
"{$filepath} differ from what was sent to the user ({$filesize} vs {$ret}).");
"{$this->filepath} differ from what was sent to the user ({$this->filesize} vs {$ret}).");
}
}
}
+4 -15
Ver Arquivo
@@ -13,30 +13,19 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/
class Attachment_downloadAction extends AttachmentAction
{
public function showPage()
public function showPage(): void
{
// Checks file exists or throws FileNotFoundException
$filepath = $this->attachment->getFileOrThumbnailPath();
$filesize = $this->attachment->getFileOrThumbnailSize();
$mimetype = $this->attachment->getFileOrThumbnailMimetype();
if (empty($filepath)) {
$this->clientError(_('No such attachment'), 404);
}
$filename = MediaFile::getDisplayName($this->attachment);
// Disable errors, to not mess with the file contents (suppress errors in case access to this
// function is blocked, like in some shared hosts). Automatically reset at the end of the
// script execution, and we don't want to have any more errors until then, so don't reset it
@ini_set('display_errors', 0);
header("Content-Description: File Transfer");
header("Content-Type: {$mimetype}");
header("Content-Disposition: attachment; filename=\"{$filename}\"");
header("Content-Type: {$this->mimetype}");
header("Content-Disposition: attachment; filename=\"{$this->filename}\"");
header('Expires: 0');
header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
AttachmentAction::sendFile($filepath, $filesize);
parent::sendFile();
}
}
+24 -41
Ver Arquivo
@@ -1,33 +1,20 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Show notice attachments
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Personal
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Show notice attachments
@@ -58,10 +45,12 @@ class Attachment_thumbnailAction extends AttachmentAction
* requested in the GET variables (read in the constructor). Tries
* to send the most appropriate file with the correct size and
* headers or displays an error if it's not possible.
* @throws ClientException
* @throws ReflectionException
* @throws ServerException
*/
public function showPage()
public function showPage(): void
{
// Returns a File_thumbnail object or throws exception if not available
try {
$thumbnail = $this->attachment->getThumbnail($this->thumb_w, $this->thumb_h, $this->thumb_c);
@@ -69,27 +58,21 @@ class Attachment_thumbnailAction extends AttachmentAction
} catch (UseFileAsThumbnailException $e) {
// With this exception, the file exists locally
$file = $e->file;
} catch(FileNotFoundException $e) {
$this->clientError(_('No such attachment'), 404);
} catch (FileNotFoundException $e) {
$this->clientError(_m('No such attachment'), 404);
}
// Checks file exists or throws FileNotFoundException
$filepath = $file->getFileOrThumbnailPath($thumbnail);
$filesize = $this->attachment->getFileOrThumbnailSize($thumbnail);
$mimetype = $file->getFileOrThumbnailMimetype($thumbnail);
$filename = MediaFile::getDisplayName($file);
// Disable errors, to not mess with the file contents (suppress errors in case access to this
// function is blocked, like in some shared hosts). Automatically reset at the end of the
// script execution, and we don't want to have any more errors until then, so don't reset it
@ini_set('display_errors', 0);
header("Content-Description: File Transfer");
header("Content-Type: {$mimetype}");
header("Content-Disposition: inline; filename=\"{$filename}\"");
header("Content-Type: {$this->mimetype}");
header("Content-Disposition: inline; filename=\"{$this->filename}\"");
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
AttachmentAction::sendFile($filepath, $filesize);
parent::sendFile();
}
}
+21 -18
Ver Arquivo
@@ -1,6 +1,20 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* View notice attachment
@@ -11,34 +25,23 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/
class Attachment_viewAction extends AttachmentAction
{
public function showPage()
public function showPage(): void
{
// Checks file exists or throws FileNotFoundException
$filepath = $this->attachment->getFileOrThumbnailPath();
$filesize = $this->attachment->getFileOrThumbnailSize();
$mimetype = $this->attachment->getFileOrThumbnailMimetype();
if (empty($filepath)) {
$this->clientError(_('No such attachment'), 404);
}
$filename = MediaFile::getDisplayName($this->attachment);
// Disable errors, to not mess with the file contents (suppress errors in case access to this
// function is blocked, like in some shared hosts). Automatically reset at the end of the
// script execution, and we don't want to have any more errors until then, so don't reset it
@ini_set('display_errors', 0);
header("Content-Description: File Transfer");
header("Content-Type: {$mimetype}");
if (in_array(common_get_mime_media($mimetype), ['image', 'video'])) {
header("Content-Disposition: inline; filename=\"{$filename}\"");
header("Content-Type: {$this->mimetype}");
if (in_array(common_get_mime_media($this->mimetype), ['image', 'video'])) {
header("Content-Disposition: inline; filename=\"{$this->filename}\"");
} else {
header("Content-Disposition: attachment; filename=\"{$filename}\"");
header("Content-Disposition: attachment; filename=\"{$this->filename}\"");
}
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
AttachmentAction::sendFile($filepath, $filesize);
parent::sendFile();
}
}
+110 -100
Ver Arquivo
@@ -1,48 +1,40 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Settings for email
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Settings
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Settings for email
*
* @category Settings
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see Widget
*/
class EmailsettingsAction extends SettingsAction
{
/**
@@ -50,7 +42,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return string Title of the page
*/
function title()
public function title()
{
// TRANS: Title for e-mail settings.
return _('Email settings');
@@ -61,7 +53,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return instructions for use
*/
function getInstructions()
public function getInstructions()
{
// XXX: For consistency of parameters in messages, this should be a
// regular parameters, replaced with sprintf().
@@ -70,7 +62,7 @@ class EmailsettingsAction extends SettingsAction
return _('Manage how you get email from %%site.name%%.');
}
function showScripts()
public function showScripts()
{
parent::showScripts();
$this->script('emailsettings.js');
@@ -85,7 +77,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
function showContent()
public function showContent()
{
$user = $this->scoped->getUser();
@@ -106,50 +98,58 @@ class EmailsettingsAction extends SettingsAction
$this->element('p', array('class' => 'form_note'), _('Current confirmed email address.'));
$this->hidden('email', $user->email);
// TRANS: Button label to remove a confirmed e-mail address.
$this->submit('remove', _m('BUTTON','Remove'));
$this->submit('remove', _m('BUTTON', 'Remove'));
} else {
try {
$confirm = $this->getConfirmation();
$this->element('p', array('id' => 'form_unconfirmed'), $confirm->address);
$this->element('p', array('class' => 'form_note'),
// TRANS: Form note in e-mail settings form.
_('Awaiting confirmation on this address. '.
'Check your inbox (and spam box!) for a message '.
'with further instructions.'));
$this->element(
'p',
['class' => 'form_note'],
// TRANS: Form note in e-mail settings form.
_('Awaiting confirmation on this address. '.
'Check your inbox (and spam box!) for a message '.
'with further instructions.')
);
$this->hidden('email', $confirm->address);
// TRANS: Button label to cancel an e-mail address confirmation procedure.
$this->submit('cancel', _m('BUTTON','Cancel'));
$this->submit('cancel', _m('BUTTON', 'Cancel'));
} catch (NoResultException $e) {
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
// TRANS: Field label for e-mail address input in e-mail settings form.
$this->input('email', _('Email address'),
$this->trimmed('email') ?: null,
// TRANS: Instructions for e-mail address input form. Do not translate
// TRANS: "example.org". It is one of the domain names reserved for
// TRANS: use in examples by http://www.rfc-editor.org/rfc/rfc2606.txt.
// TRANS: Any other domain may be owned by a legitimate person or
// TRANS: organization.
_('Email address, like "UserName@example.org"'));
$this->input(
'email',
_('Email address'),
$this->trimmed('email') ?: null,
// TRANS: Instructions for e-mail address input form. Do not translate
// TRANS: "example.org". It is one of the domain names reserved for
// TRANS: use in examples by http://www.rfc-editor.org/rfc/rfc2606.txt.
// TRANS: Any other domain may be owned by a legitimate person or
// TRANS: organization.
_('Email address, like "UserName@example.org"')
);
$this->elementEnd('li');
$this->elementEnd('ul');
// TRANS: Button label for adding an e-mail address in e-mail settings form.
$this->submit('add', _m('BUTTON','Add'));
$this->submit('add', _m('BUTTON', 'Add'));
}
}
$this->elementEnd('fieldset');
if (common_config('emailpost', 'enabled') && $user->email) {
if (common_config('emailpost', 'enabled') && $user->email) {
$this->elementStart('fieldset', array('id' => 'settings_email_incoming'));
// TRANS: Form legend for incoming e-mail settings form.
$this->element('legend', null, _('Incoming email'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->checkbox('emailpost',
// TRANS: Checkbox label in e-mail preferences form.
_('I want to post notices by email.'),
$user->emailpost);
$this->checkbox(
'emailpost',
// TRANS: Checkbox label in e-mail preferences form.
_('I want to post notices by email.'),
$user->emailpost
);
$this->elementEnd('li');
$this->elementEnd('ul');
@@ -168,12 +168,15 @@ class EmailsettingsAction extends SettingsAction
$this->element('span', 'address', $user->incomingemail);
// @todo XXX: Looks a little awkward in the UI.
// Something like "xxxx@identi.ca Send email ..". Needs improvement.
$this->element('span', 'input_instructions',
// TRANS: Form instructions for incoming e-mail form in e-mail settings.
_('Send email to this address to post new notices.'));
$this->element(
'span',
'input_instructions',
// TRANS: Form instructions for incoming e-mail form in e-mail settings.
_('Send email to this address to post new notices.')
);
$this->elementEnd('p');
// TRANS: Button label for removing a set sender e-mail address to post notices from.
$this->submit('removeincoming', _m('BUTTON','Remove'));
$this->submit('removeincoming', _m('BUTTON', 'Remove'));
}
$this->elementStart('p');
@@ -189,7 +192,7 @@ class EmailsettingsAction extends SettingsAction
$this->elementEnd('p');
// TRANS: Button label for adding an e-mail address to send notices from.
$this->submit('newincoming', _m('BUTTON','New'));
$this->submit('newincoming', _m('BUTTON', 'New'));
$this->elementEnd('div'); // div#emailincoming
@@ -204,34 +207,42 @@ class EmailsettingsAction extends SettingsAction
if (Event::handle('StartEmailFormData', array($this, $this->scoped))) {
$this->elementStart('li');
$this->checkbox('emailnotifysub',
// TRANS: Checkbox label in e-mail preferences form.
_('Send me notices of new subscriptions through email.'),
$user->emailnotifysub);
$this->checkbox(
'emailnotifysub',
// TRANS: Checkbox label in e-mail preferences form.
_('Send me notices of new subscriptions through email.'),
$user->emailnotifysub
);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('emailnotifymsg',
// TRANS: Checkbox label in e-mail preferences form.
_('Send me email when someone sends me a private message.'),
$user->emailnotifymsg);
$this->checkbox(
'emailnotifymsg',
// TRANS: Checkbox label in e-mail preferences form.
_('Send me email when someone sends me a private message.'),
$user->emailnotifymsg
);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('emailnotifyattn',
// TRANS: Checkbox label in e-mail preferences form.
_('Send me email when someone sends me an "@-reply".'),
$user->emailnotifyattn);
$this->checkbox(
'emailnotifyattn',
// TRANS: Checkbox label in e-mail preferences form.
_('Send me email when someone sends me an "@-reply".'),
$user->emailnotifyattn
);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('emailnotifynudge',
// TRANS: Checkbox label in e-mail preferences form.
_('Allow friends to nudge me and send me an email.'),
$user->emailnotifynudge);
$this->checkbox(
'emailnotifynudge',
// TRANS: Checkbox label in e-mail preferences form.
_('Allow friends to nudge me and send me an email.'),
$user->emailnotifynudge
);
$this->elementEnd('li');
Event::handle('EndEmailFormData', array($this, $this->scoped));
}
$this->elementEnd('ul');
// TRANS: Button label to save e-mail preferences.
$this->submit('save', _m('BUTTON','Save'));
$this->submit('save', _m('BUTTON', 'Save'));
$this->elementEnd('fieldset');
$this->elementEnd('fieldset');
$this->elementEnd('form');
@@ -242,7 +253,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return Confirm_address Email address confirmation for user, or null
*/
function getConfirmation()
public function getConfirmation()
{
$confirm = new Confirm_address();
@@ -260,15 +271,15 @@ class EmailsettingsAction extends SettingsAction
{
if ($this->arg('save')) {
return $this->savePreferences();
} else if ($this->arg('add')) {
} elseif ($this->arg('add')) {
return $this->addAddress();
} else if ($this->arg('cancel')) {
} elseif ($this->arg('cancel')) {
return $this->cancelConfirmation();
} else if ($this->arg('remove')) {
} elseif ($this->arg('remove')) {
return $this->removeAddress();
} else if ($this->arg('removeincoming')) {
} elseif ($this->arg('removeincoming')) {
return $this->removeIncoming();
} else if ($this->arg('newincoming')) {
} elseif ($this->arg('newincoming')) {
return $this->newIncoming();
}
@@ -281,14 +292,14 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
function savePreferences()
public function savePreferences()
{
if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
$emailnotifysub = $this->booleanintstring('emailnotifysub');
$emailnotifymsg = $this->booleanintstring('emailnotifymsg');
$emailnotifynudge = $this->booleanintstring('emailnotifynudge');
$emailnotifyattn = $this->booleanintstring('emailnotifyattn');
$emailpost = $this->booleanintstring('emailpost');
$emailnotifysub = $this->boolean('emailnotifysub');
$emailnotifymsg = $this->boolean('emailnotifymsg');
$emailnotifynudge = $this->boolean('emailnotifynudge');
$emailnotifyattn = $this->boolean('emailnotifyattn');
$emailpost = $this->boolean('emailpost');
$user = $this->scoped->getUser();
$user->query('BEGIN');
@@ -322,7 +333,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
function addAddress()
public function addAddress()
{
$user = $this->scoped->getUser();
@@ -344,16 +355,15 @@ class EmailsettingsAction extends SettingsAction
if (!Validate::email($email, common_config('email', 'check_domain'))) {
// TRANS: Message given saving e-mail address that not valid.
throw new ClientException(_('Not a valid email address.'));
} else if ($user->email == $email) {
} elseif ($user->email === $email) {
// TRANS: Message given saving e-mail address that is already set.
throw new ClientException(_('That is already your email address.'));
} else if ($this->emailExists($email)) {
} elseif ($this->emailExists($email)) {
// TRANS: Message given saving e-mail address that is already set for another user.
throw new ClientException(_('That email address already belongs to another user.'));
}
if (Event::handle('StartAddEmailAddress', array($user, $email))) {
$confirm = new Confirm_address();
$confirm->address = $email;
@@ -385,7 +395,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
function cancelConfirmation()
public function cancelConfirmation()
{
$email = $this->trimmed('email');
@@ -411,7 +421,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
function removeAddress()
public function removeAddress()
{
$user = common_current_user();
@@ -425,7 +435,7 @@ class EmailsettingsAction extends SettingsAction
}
$original = clone($user);
$user->email = null;
$user->email = 'NULL';
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($original);
@@ -438,7 +448,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
function removeIncoming()
public function removeIncoming()
{
$user = common_current_user();
@@ -448,8 +458,8 @@ class EmailsettingsAction extends SettingsAction
}
$orig = clone($user);
$user->incomingemail = null;
$user->emailpost = 0;
$user->incomingemail = 'NULL';
$user->emailpost = false;
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($orig);
@@ -462,12 +472,12 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
function newIncoming()
public function newIncoming()
{
$user = common_current_user();
$orig = clone($user);
$user->incomingemail = mail_new_incoming_address();
$user->emailpost = 1;
$user->emailpost = true;
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($orig);
@@ -485,7 +495,7 @@ class EmailsettingsAction extends SettingsAction
* @return boolean Whether the email already exists.
*/
function emailExists($email)
public function emailExists($email)
{
$user = common_current_user();
+41 -45
Ver Arquivo
@@ -1,60 +1,51 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* List of featured users
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Public
* @package StatusNet
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @author Evan Prodromou <evan@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/lib/profilelist.php';
require_once INSTALLDIR.'/lib/publicgroupnav.php';
require_once INSTALLDIR . '/lib/profile/profilelist.php';
require_once INSTALLDIR . '/lib/groups/publicgroupnav.php';
/**
* List of featured users
*
* @category Public
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class FeaturedAction extends Action
{
var $page = null;
public $page = null;
function isReadOnly($args)
public function isReadOnly($args)
{
return true;
}
function prepare(array $args = array())
public function prepare(array $args = [])
{
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
@@ -62,7 +53,7 @@ class FeaturedAction extends Action
return true;
}
function title()
public function title()
{
if ($this->page == 1) {
// TRANS: Page title for first page of featured users.
@@ -74,14 +65,14 @@ class FeaturedAction extends Action
}
}
function handle()
public function handle()
{
parent::handle();
$this->showPage();
}
function showPageNotice()
public function showPageNotice()
{
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
@@ -90,14 +81,16 @@ class FeaturedAction extends Action
$this->elementEnd('div');
}
function getInstructions()
public function getInstructions()
{
// TRANS: Description on page displaying featured users.
return sprintf(_('A selection of some great users on %s.'),
common_config('site', 'name'));
return sprintf(
_('A selection of some great users on %s.'),
common_config('site', 'name')
);
}
function showContent()
public function showContent()
{
// XXX: Note I'm doing it this two-stage way because a raw query
// with a JOIN was *not* working. --Zach
@@ -105,7 +98,6 @@ class FeaturedAction extends Action
$featured_nicks = common_config('nickname', 'featured');
if (count($featured_nicks) > 0) {
$quoted = array();
foreach ($featured_nicks as $nick) {
@@ -115,7 +107,7 @@ class FeaturedAction extends Action
$user = new User;
$user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
$user->limit(($this->page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
$user->orderBy(common_database_tablename('user') .'.nickname ASC');
$user->orderBy($user->escapedTableName() . '.nickname ASC');
$user->find();
@@ -138,8 +130,12 @@ class FeaturedAction extends Action
$profile->free();
$this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
$this->page, 'featured');
$this->pagination(
$this->page > 1,
$cnt > PROFILES_PER_PAGE,
$this->page,
'featured'
);
}
}
}
+2 -2
Ver Arquivo
@@ -31,8 +31,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once(INSTALLDIR.'/lib/profilelist.php');
require_once INSTALLDIR.'/lib/publicgroupnav.php';
require_once INSTALLDIR . '/lib/profile/profilelist.php';
require_once INSTALLDIR . '/lib/groups/publicgroupnav.php';
/**
* List of group members
+1 -1
Ver Arquivo
@@ -32,7 +32,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/grouplist.php';
require_once INSTALLDIR . '/lib/groups/grouplist.php';
/**
* Latest groups
+2 -2
Ver Arquivo
@@ -32,8 +32,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
//require_once INSTALLDIR.'/lib/searchaction.php';
//require_once INSTALLDIR.'/lib/profilelist.php';
require_once INSTALLDIR . '/lib/search/searchaction.php';
require_once INSTALLDIR . '/lib/profile/profilelist.php';
/**
* Group search action class.
+57 -57
Ver Arquivo
@@ -1,50 +1,41 @@
<?php
/**
* Make another user an admin of a group
*
* PHP version 5
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Make another user an admin of a group
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
* Make another user an admin of a group
*
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class MakeadminAction extends RedirectingAction
{
var $profile = null;
var $group = null;
public $profile = null;
public $group = null;
/**
* Take arguments for running
@@ -54,7 +45,7 @@ class MakeadminAction extends RedirectingAction
* @return boolean success flag
*/
function prepare(array $args = array())
public function prepare(array $args = [])
{
parent::prepare($args);
if (!common_logged_in()) {
@@ -95,10 +86,14 @@ class MakeadminAction extends RedirectingAction
if ($this->profile->isAdmin($this->group)) {
// TRANS: Client error displayed when trying to make another user admin on the Make Admin page who already is admin.
// TRANS: %1$s is the user that is already admin, %2$s is the group user is already admin for.
$this->clientError(sprintf(_('%1$s is already an admin for group "%2$s".'),
$this->profile->getBestName(),
$this->group->getBestName()),
401);
$this->clientError(
sprintf(
_('%1$s is already an admin for group "%2$s".'),
$this->profile->getBestName(),
$this->group->getBestName()
),
401
);
}
return true;
}
@@ -111,7 +106,7 @@ class MakeadminAction extends RedirectingAction
* @return void
*/
function handle()
public function handle()
{
parent::handle();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -125,7 +120,7 @@ class MakeadminAction extends RedirectingAction
* @return void
*/
function makeAdmin()
public function makeAdmin()
{
$member = Group_member::pkeyGet(array('group_id' => $this->group->id,
'profile_id' => $this->profile->id));
@@ -134,14 +129,16 @@ class MakeadminAction extends RedirectingAction
// TRANS: Server error displayed when trying to make another user admin on the Make Admin page fails
// TRANS: because the group membership record could not be gotten.
// TRANS: %1$s is the to be admin user, %2$s is the group user should be admin for.
$this->serverError(_('Can\'t get membership record for %1$s in group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName());
$this->serverError(
_('Can\'t get membership record for %1$s in group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName()
);
}
$orig = clone($member);
$member->is_admin = 1;
$member->is_admin = true;
$result = $member->update($orig);
@@ -150,9 +147,11 @@ class MakeadminAction extends RedirectingAction
// TRANS: Server error displayed when trying to make another user admin on the Make Admin page fails
// TRANS: because the group adminship record coud not be saved properly.
// TRANS: %1$s is the to be admin user, %2$s is the group user is already admin for.
$this->serverError(_('Can\'t make %1$s an admin for group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName());
$this->serverError(
_('Can\'t make %1$s an admin for group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName()
);
}
$this->returnToPrevious();
@@ -161,13 +160,14 @@ class MakeadminAction extends RedirectingAction
/**
* If we reached this form without returnto arguments, default to
* the top of the group's member list.
*
*
* @return string URL
*/
function defaultReturnTo()
public function defaultReturnTo()
{
return common_local_url('groupmembers',
array('nickname' => $this->group->nickname));
return common_local_url(
'groupmembers',
['nickname' => $this->group->nickname]
);
}
}
+3 -1
Ver Arquivo
@@ -33,7 +33,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/searchaction.php';
require_once INSTALLDIR . '/lib/search/searchaction.php';
/**
* Notice search action class.
@@ -65,6 +65,8 @@ class NoticesearchAction extends SearchAction
if (!empty($this->q)) {
Event::handle('StartNoticeSearch', [$this->q]);
$stream = new SearchNoticeStream($this->q, $this->scoped);
$page = $this->trimmed('page');
+1 -1
Ver Arquivo
@@ -33,7 +33,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/mail.php';
require_once INSTALLDIR . '/lib/util/mail.php';
/**
* Nudge a user action class.
+2 -2
Ver Arquivo
@@ -32,8 +32,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/searchaction.php';
require_once INSTALLDIR.'/lib/profilelist.php';
require_once INSTALLDIR . '/lib/search/searchaction.php';
require_once INSTALLDIR . '/lib/profile/profilelist.php';
/**
* People search action class.
+1 -1
Ver Arquivo
@@ -35,7 +35,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/peopletaglist.php';
require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
// cache 3 pages
define('PEOPLETAG_CACHE_WINDOW', PEOPLETAGS_PER_PAGE*3 + 1);
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once(INSTALLDIR.'/lib/profilelist.php');
require_once INSTALLDIR . '/lib/profile/profilelist.php';
/**
* List of people tagged by the user with a tag
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/peopletaglist.php';
require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
class PeopletagsbyuserAction extends Action
{
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/peopletaglist.php';
require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
class PeopletagsforuserAction extends Action
{
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once(INSTALLDIR.'/lib/profilelist.php');
require_once INSTALLDIR . '/lib/profile/profilelist.php';
/**
* List of peopletag subscribers
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/peopletaglist.php';
require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
class PeopletagsubscriptionsAction extends Action
{
+1 -1
Ver Arquivo
@@ -16,7 +16,7 @@
defined('STATUSNET') || die();
require_once INSTALLDIR . '/lib/deletetree.php';
require_once INSTALLDIR . '/lib/util/deletetree.php';
/**
* Form for deleting a plugin
+46
Ver Arquivo
@@ -38,6 +38,52 @@ defined('STATUSNET') || die();
*/
class PlugindisableAction extends PluginenableAction
{
/**
* Handle request
*
* Disables the plugin and returns results.
*
* @return void
* @throws ClientException
*/
function handle()
{
if (PluginList::isPluginLoaded($this->plugin)) {
$config_file = INSTALLDIR . DIRECTORY_SEPARATOR . 'config.php';
$config_lines = file($config_file, FILE_IGNORE_NEW_LINES);
foreach($config_lines as $key => $line) {
// We are doing it this way to avoid deleting things we shouldn't
$line = str_replace('addPlugin(\''.$this->plugin.'\');', '', $line);
$config_lines[$key] = $line;
if($line === ' // Added by sysadmin\'s Plugin UI.') {
unset($config_lines[$key]);
}
}
$new_config_data = implode(PHP_EOL, $config_lines);
if (!file_put_contents($config_file, $new_config_data)) {
$this->clientError(_m('No permissions for writing to config.php'));
}
}
$key = 'disable-' . $this->plugin;
Config::save('plugins', $key, $this->overrideValue());
// @fixme this is a pretty common pattern and should be refactored down
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
$this->element('title', null, $this->successShortTitle());
$this->elementEnd('head');
$this->elementStart('body');
$form = $this->successNextForm();
$form->show();
$this->elementEnd('body');
$this->endHTML();
} else {
$url = common_local_url('pluginsadminpanel');
common_redirect($url, 303);
}
}
/**
* Value to save into $config['plugins']['disable-<name>']
*/
+1 -1
Ver Arquivo
@@ -16,7 +16,7 @@
defined('STATUSNET') || die();
require_once INSTALLDIR . '/lib/deletetree.php';
require_once INSTALLDIR . '/lib/util/deletetree.php';
/**
* Plugin install action.
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/peopletageditform.php';
require_once INSTALLDIR . '/lib/profile/peopletageditform.php';
/**
* Subscription action
+171 -132
Ver Arquivo
@@ -1,46 +1,38 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Change profile settings
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Settings
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Change profile settings
*
* @category Settings
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class ProfilesettingsAction extends SettingsAction
{
@@ -49,7 +41,7 @@ class ProfilesettingsAction extends SettingsAction
*
* @return string Title of the page
*/
function title()
public function title()
{
// TRANS: Page title for profile settings.
return _('Profile settings');
@@ -60,14 +52,14 @@ class ProfilesettingsAction extends SettingsAction
*
* @return instructions for use
*/
function getInstructions()
public function getInstructions()
{
// TRANS: Usage instructions for profile settings.
return _('You can update your personal profile info here '.
'so people know more about you.');
}
function showScripts()
public function showScripts()
{
parent::showScripts();
$this->autofocus('fullname');
@@ -80,7 +72,7 @@ class ProfilesettingsAction extends SettingsAction
*
* @return void
*/
function showContent()
public function showContent()
{
$user = $this->scoped->getUser();
@@ -98,29 +90,40 @@ class ProfilesettingsAction extends SettingsAction
if (Event::handle('StartProfileFormData', array($this))) {
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('nickname', _('Nickname'),
$this->trimmed('nickname') ?: $this->scoped->getNickname(),
// TRANS: Tooltip for field label in form for profile settings.
_('1-64 lowercase letters or numbers, no punctuation or spaces.'),
null, false, // "name" (will be set to id), then "required"
!common_config('profile', 'changenick')
? array('disabled' => 'disabled', 'placeholder' => null)
: array('placeholder' => null));
$this->input(
'nickname',
_('Nickname'),
$this->trimmed('nickname') ?: $this->scoped->getNickname(),
// TRANS: Tooltip for field label in form for profile settings.
_('1-64 lowercase letters or numbers, no punctuation or spaces.'),
null,
false, // "name" (will be set to id), then "required"
(common_config('profile', 'changenick')
? ['placeholder' => null]
: ['disabled' => 'disabled', 'placeholder' => null])
);
$this->elementEnd('li');
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('fullname', _('Full name'),
$this->trimmed('fullname') ?: $this->scoped->getFullname(),
// TRANS: Instructions for full name text field on profile settings
_('A full name is required, if empty it will be set to your nickname.'),
null, true);
$this->input(
'fullname',
_('Full name'),
$this->trimmed('fullname') ?: $this->scoped->getFullname(),
// TRANS: Instructions for full name text field on profile settings
_('A full name is required, if empty it will be set to your nickname.'),
null,
true
);
$this->elementEnd('li');
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('homepage', _('Homepage'),
$this->trimmed('homepage') ?: $this->scoped->getHomepage(),
// TRANS: Tooltip for field label in form for profile settings.
_('URL of your homepage, blog, or profile on another site.'));
$this->input(
'homepage',
_('Homepage'),
$this->trimmed('homepage') ?: $this->scoped->getHomepage(),
// TRANS: Tooltip for field label in form for profile settings.
_('URL of your homepage, blog, or profile on another site.')
);
$this->elementEnd('li');
$this->elementStart('li');
$maxBio = Profile::maxBio();
@@ -128,97 +131,129 @@ class ProfilesettingsAction extends SettingsAction
// TRANS: Tooltip for field label in form for profile settings. Plural
// TRANS: is decided by the number of characters available for the
// TRANS: biography (%d).
$bioInstr = sprintf(_m('Describe yourself and your interests in %d character.',
'Describe yourself and your interests in %d characters.',
$maxBio),
$maxBio);
$bioInstr = sprintf(
_m('Describe yourself and your interests in %d character.',
'Describe yourself and your interests in %d characters.',
$maxBio),
$maxBio
);
} else {
// TRANS: Tooltip for field label in form for profile settings.
$bioInstr = _('Describe yourself and your interests.');
}
// TRANS: Text area label in form for profile settings where users can provide
// TRANS: their biography.
$this->textarea('bio', _('Bio'),
$this->trimmed('bio') ?: $this->scoped->getDescription(),
$bioInstr);
$this->textarea(
'bio',
_('Bio'),
($this->trimmed('bio') ?: $this->scoped->getDescription()),
$bioInstr
);
$this->elementEnd('li');
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('location', _('Location'),
$this->trimmed('location') ?: $this->scoped->location,
// TRANS: Tooltip for field label in form for profile settings.
_('Where you are, like "City, State (or Region), Country".'));
$this->input(
'location',
_('Location'),
($this->trimmed('location') ?: $this->scoped->location),
// TRANS: Tooltip for field label in form for profile settings.
_('Where you are, like "City, State (or Region), Country".')
);
$this->elementEnd('li');
if (common_config('location', 'share') == 'user') {
$this->elementStart('li');
// TRANS: Checkbox label in form for profile settings.
$this->checkbox('sharelocation', _('Share my current location when posting notices'),
($this->arg('sharelocation')) ?
$this->boolean('sharelocation') : $this->scoped->shareLocation());
$this->checkbox(
'sharelocation',
_('Share my current location when posting notices'),
($this->arg('sharelocation') ?
$this->boolean('sharelocation') : $this->scoped->shareLocation())
);
$this->elementEnd('li');
}
Event::handle('EndProfileFormData', array($this));
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('tags', _('Tags'),
$this->trimmed('tags') ?: implode(' ', Profile_tag::getSelfTagsArray($this->scoped)),
// TRANS: Tooltip for field label in form for profile settings.
_('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated.'));
$this->input(
'tags',
_('Tags'),
($this->trimmed('tags') ?: implode(' ', Profile_tag::getSelfTagsArray($this->scoped))),
// TRANS: Tooltip for field label in form for profile settings.
_('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated.')
);
$this->elementEnd('li');
$this->elementStart('li');
$language = common_language();
// TRANS: Dropdownlist label in form for profile settings.
$this->dropdown('language', _('Language'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
get_nice_language_list(), _('Preferred language.'),
false, $language);
$this->dropdown(
'language',
_('Language'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
get_nice_language_list(),
_('Preferred language.'),
false,
$language
);
$this->elementEnd('li');
$timezone = common_timezone();
$timezones = array();
foreach(DateTimeZone::listIdentifiers() as $k => $v) {
foreach (DateTimeZone::listIdentifiers() as $k => $v) {
$timezones[$v] = $v;
}
$this->elementStart('li');
// TRANS: Dropdownlist label in form for profile settings.
$this->dropdown('timezone', _('Timezone'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
$timezones, _('What timezone are you normally in?'),
true, $timezone);
$this->dropdown(
'timezone',
_('Timezone'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
$timezones,
_('What timezone are you normally in?'),
true,
$timezone
);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('autosubscribe',
// TRANS: Checkbox label in form for profile settings.
_('Automatically subscribe to whoever '.
'subscribes to me (best for non-humans)'),
($this->arg('autosubscribe')) ?
$this->boolean('autosubscribe') : $user->autosubscribe);
$this->checkbox(
'autosubscribe',
// TRANS: Checkbox label in form for profile settings.
_('Automatically subscribe to whoever '.
'subscribes to me (best for non-humans)'),
($this->arg('autosubscribe') ?
$this->boolean('autosubscribe') : $user->autosubscribe)
);
$this->elementEnd('li');
$this->elementStart('li');
$this->dropdown('subscribe_policy',
// TRANS: Dropdown field label on profile settings, for what policies to apply when someone else tries to subscribe to your updates.
_('Subscription policy'),
// TRANS: Dropdown field option for following policy.
array(User::SUBSCRIBE_POLICY_OPEN => _('Let anyone follow me'),
// TRANS: Dropdown field option for following policy.
User::SUBSCRIBE_POLICY_MODERATE => _('Ask me first')),
// TRANS: Dropdown field title on group edit form.
_('Whether other users need your permission to follow your updates.'),
false,
(empty($user->subscribe_policy)) ? User::SUBSCRIBE_POLICY_OPEN : $user->subscribe_policy);
$this->dropdown(
'subscribe_policy',
// TRANS: Dropdown field label on profile settings, for what policies to apply when someone else tries to subscribe to your updates.
_('Subscription policy'),
[
// TRANS: Dropdown field option for following policy.
User::SUBSCRIBE_POLICY_OPEN => _('Let anyone follow me'),
// TRANS: Dropdown field option for following policy.
User::SUBSCRIBE_POLICY_MODERATE => _('Ask me first'),
],
// TRANS: Dropdown field title on group edit form.
_('Whether other users need your permission to follow your updates.'),
false,
(empty($user->subscribe_policy) ? User::SUBSCRIBE_POLICY_OPEN : $user->subscribe_policy)
);
$this->elementEnd('li');
}
if (common_config('profile', 'allowprivate') || $user->private_stream) {
$this->elementStart('li');
$this->checkbox('private_stream',
// TRANS: Checkbox label in profile settings.
_('Make updates visible only to my followers'),
($this->arg('private_stream')) ?
$this->boolean('private_stream') : $user->private_stream);
$this->checkbox(
'private_stream',
// TRANS: Checkbox label in profile settings.
_('Make updates visible only to my followers'),
($this->arg('private_stream') ?
$this->boolean('private_stream') : $user->private_stream)
);
$this->elementEnd('li');
}
$this->elementEnd('ul');
// TRANS: Button to save input in profile settings.
$this->submit('save', _m('BUTTON','Save'));
$this->submit('save', _m('BUTTON', 'Save'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
@@ -255,7 +290,7 @@ class ProfilesettingsAction extends SettingsAction
$homepage = $this->trimmed('homepage');
$bio = $this->trimmed('bio');
$location = $this->trimmed('location');
$autosubscribe = $this->booleanintstring('autosubscribe');
$autosubscribe = $this->boolean('autosubscribe');
$subscribe_policy = $this->trimmed('subscribe_policy');
$language = $this->trimmed('language');
$timezone = $this->trimmed('timezone');
@@ -266,24 +301,26 @@ class ProfilesettingsAction extends SettingsAction
!common_valid_http_url($homepage)) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Homepage is not a valid URL.'));
} else if (!is_null($fullname) && mb_strlen($fullname) > 191) {
} elseif (!is_null($fullname) && mb_strlen($fullname) > 191) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Full name is too long (maximum 191 characters).'));
} else if (Profile::bioTooLong($bio)) {
} elseif (Profile::bioTooLong($bio)) {
// TRANS: Validation error in form for profile settings.
// TRANS: Plural form is used based on the maximum number of allowed
// TRANS: characters for the biography (%d).
throw new ClientException(sprintf(_m('Bio is too long (maximum %d character).',
'Bio is too long (maximum %d characters).',
Profile::maxBio()),
Profile::maxBio()));
} else if (!is_null($location) && mb_strlen($location) > 191) {
throw new ClientException(sprintf(
_m('Bio is too long (maximum %d character).',
'Bio is too long (maximum %d characters).',
Profile::maxBio()),
Profile::maxBio()
));
} elseif (!is_null($location) && mb_strlen($location) > 191) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Location is too long (maximum 191 characters).'));
} else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
} elseif (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Timezone not selected.'));
} else if (!is_null($language) && strlen($language) > 50) {
} elseif (!is_null($language) && strlen($language) > 50) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Language is too long (maximum 50 characters).'));
}
@@ -291,7 +328,6 @@ class ProfilesettingsAction extends SettingsAction
$tags = array();
$tag_priv = array();
if (is_string($tagstring) && strlen($tagstring) > 0) {
$tags = preg_split('/[\s,]+/', $tagstring);
foreach ($tags as &$tag) {
@@ -314,21 +350,19 @@ class ProfilesettingsAction extends SettingsAction
// Only allow setting private_stream if site policy allows it
// (or user already _has_ a private stream, then you can unset it)
if (common_config('profile', 'allowprivate') || $user->private_stream) {
$private_stream = $this->booleanintstring('private_stream');
$private_stream = $this->boolean('private_stream');
} else {
// if not allowed, we set to the existing value
$private_stream = $user->private_stream;
$private_stream = (bool) $user->private_stream;
}
// $user->nickname is updated through Profile->update();
// XXX: XOR
if (($user->autosubscribe ^ $autosubscribe)
|| ($user->private_stream ^ $private_stream)
if ((bool) $user->autosubscribe != $autosubscribe
|| (bool) $user->private_stream != $private_stream
|| $user->timezone != $timezone
|| $user->language != $language
|| $user->subscribe_policy != $subscribe_policy) {
$original = clone($user);
$user->autosubscribe = $autosubscribe;
@@ -378,7 +412,6 @@ class ProfilesettingsAction extends SettingsAction
}
if (common_config('location', 'share') == 'user') {
$exists = false;
$prefs = User_location_prefs::getKV('user_id', $this->scoped->getID());
@@ -393,7 +426,7 @@ class ProfilesettingsAction extends SettingsAction
$orig = clone($prefs);
}
$prefs->share_location = $this->booleanintstring('sharelocation');
$prefs->share_location = $this->boolean('sharelocation');
if ($exists) {
$result = $prefs->update($orig);
@@ -429,11 +462,11 @@ class ProfilesettingsAction extends SettingsAction
// TRANS: Confirmation shown when user profile settings are saved.
return _('Settings saved.');
}
}
function showAside() {
public function showAside()
{
$this->elementStart('div', array('id' => 'aside_primary',
'class' => 'aside'));
@@ -443,26 +476,32 @@ class ProfilesettingsAction extends SettingsAction
if (Event::handle('StartProfileSettingsActions', array($this))) {
if ($this->scoped->hasRight(Right::BACKUPACCOUNT)) {
$this->elementStart('li');
$this->element('a',
array('href' => common_local_url('backupaccount')),
// TRANS: Option in profile settings to create a backup of the account of the currently logged in user.
_('Backup account'));
$this->element(
'a',
['href' => common_local_url('backupaccount')],
// TRANS: Option in profile settings to create a backup of the account of the currently logged in user.
_('Backup account')
);
$this->elementEnd('li');
}
if ($this->scoped->hasRight(Right::DELETEACCOUNT)) {
$this->elementStart('li');
$this->element('a',
array('href' => common_local_url('deleteaccount')),
// TRANS: Option in profile settings to delete the account of the currently logged in user.
_('Delete account'));
$this->element(
'a',
['href' => common_local_url('deleteaccount')],
// TRANS: Option in profile settings to delete the account of the currently logged in user.
_('Delete account')
);
$this->elementEnd('li');
}
if ($this->scoped->hasRight(Right::RESTOREACCOUNT)) {
$this->elementStart('li');
$this->element('a',
array('href' => common_local_url('restoreaccount')),
// TRANS: Option in profile settings to restore the account of the currently logged in user from a backup.
_('Restore account'));
$this->element(
'a',
['href' => common_local_url('restoreaccount')],
// TRANS: Option in profile settings to restore the account of the currently logged in user from a backup.
_('Restore account')
);
$this->elementEnd('li');
}
Event::handle('EndProfileSettingsActions', array($this));
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/togglepeopletag.php';
require_once INSTALLDIR . '/lib/account/togglepeopletag.php';
/**
* Subscription action
+51 -57
Ver Arquivo
@@ -1,53 +1,45 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Action for showing profiles self-tagged with a given tag
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Action
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* This class outputs a paginated list of profiles self-tagged with a given tag
*
* @category Output
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @category Output
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see Action
* @see Action
*/
class SelftagAction extends Action
{
var $tag = null;
var $page = null;
public $tag = null;
public $page = null;
/**
* For initializing members of the class.
@@ -57,7 +49,7 @@ class SelftagAction extends Action
* @return boolean true
* @throws ClientException
*/
function prepare(array $args = [])
public function prepare(array $args = [])
{
parent::prepare($args);
@@ -66,8 +58,10 @@ class SelftagAction extends Action
if (!common_valid_profile_tag($this->tag)) {
// TRANS: Client error displayed when trying to list a profile with an invalid list.
// TRANS: %s is the invalid list name.
$this->clientError(sprintf(_('Not a valid list: %s.'),
$this->tag));
$this->clientError(sprintf(
_('Not a valid list: %s.'),
$this->tag
));
return null;
}
@@ -83,7 +77,7 @@ class SelftagAction extends Action
*
* @return void is read only action?
*/
function handle()
public function handle()
{
parent::handle();
$this->showPage();
@@ -94,19 +88,13 @@ class SelftagAction extends Action
* people tag and page, initalizes a ProfileList widget, and displays
* it to the user.
*/
function showContent()
public function showContent()
{
$profile = new Profile();
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
$limit = PROFILES_PER_PAGE + 1;
if (common_config('db', 'type') == 'pgsql') {
$lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$lim = ' LIMIT ' . $offset . ', ' . $limit;
}
// XXX: memcached this
$qry = 'SELECT profile.* ' .
@@ -125,18 +113,21 @@ class SelftagAction extends Action
' OR profile_list.private = false) ';
}
$qry .= 'ORDER BY profile_tag.modified DESC%s';
$qry .= 'ORDER BY profile_tag.modified DESC ' .
'LIMIT ' . $limit . ' OFFSET ' . $offset;
$profile->query(sprintf($qry, $this->tag, $lim));
$profile->query(sprintf($qry, $this->tag));
$ptl = new SelfTagProfileList($profile, $this); // pass the ammunition
$cnt = $ptl->show();
$this->pagination($this->page > 1,
$cnt > PROFILES_PER_PAGE,
$this->page,
'selftag',
array('tag' => $this->tag));
$this->pagination(
$this->page > 1,
$cnt > PROFILES_PER_PAGE,
$this->page,
'selftag',
['tag' => $this->tag]
);
}
/**
@@ -144,18 +135,21 @@ class SelftagAction extends Action
*
* @return string page title
*/
function title()
public function title()
{
// TRANS: Page title for page showing self tags.
// TRANS: %1$s is a tag, %2$d is a page number.
return sprintf(_('Users self-tagged with %1$s, page %2$d'),
$this->tag, $this->page);
return sprintf(
_('Users self-tagged with %1$s, page %2$d'),
$this->tag,
$this->page
);
}
}
class SelfTagProfileList extends ProfileList
{
function newListItem(Profile $target)
public function newListItem(Profile $target)
{
return new SelfTagProfileListItem($target, $this->action);
}
@@ -163,7 +157,7 @@ class SelfTagProfileList extends ProfileList
class SelfTagProfileListItem extends ProfileListItem
{
function linkAttributes()
public function linkAttributes()
{
$aAttrs = parent::linkAttributes();
@@ -174,7 +168,7 @@ class SelfTagProfileListItem extends ProfileListItem
return $aAttrs;
}
function homepageAttributes()
public function homepageAttributes()
{
$aAttrs = parent::linkAttributes();
@@ -185,7 +179,7 @@ class SelfTagProfileListItem extends ProfileListItem
return $aAttrs;
}
function showTags()
public function showTags()
{
$selftags = new SelfTagsWidget($this->out, $this->profile, $this->profile);
$selftags->show();
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('GNUSOCIAL')) {
exit(1);
}
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR . '/lib/notices/noticelist.php';
/**
* Show a single notice
+144 -112
Ver Arquivo
@@ -1,46 +1,39 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
* Settings for SMS.
*
* Settings for SMS
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Settings
* @package StatusNet
* @category Setting
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Settings for SMS
*
* @category Settings
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see SettingsAction
*/
class SmssettingsAction extends SettingsAction
{
protected function doPreparation()
@@ -56,7 +49,7 @@ class SmssettingsAction extends SettingsAction
*
* @return string Title of the page
*/
function title()
public function title()
{
// TRANS: Title for SMS settings.
return _('SMS settings');
@@ -67,7 +60,7 @@ class SmssettingsAction extends SettingsAction
*
* @return instructions for use
*/
function getInstructions()
public function getInstructions()
{
// XXX: For consistency of parameters in messages, this should be a
// regular parameters, replaced with sprintf().
@@ -76,7 +69,7 @@ class SmssettingsAction extends SettingsAction
return _('You can receive SMS messages through email from %%site.name%%.');
}
function showScripts()
public function showScripts()
{
parent::showScripts();
$this->autofocus('sms');
@@ -90,7 +83,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function showContent()
public function showContent()
{
$user = $this->scoped->getUser();
@@ -107,80 +100,105 @@ class SmssettingsAction extends SettingsAction
if ($user->sms) {
$carrier = $user->getCarrier();
$this->element('p', 'form_confirmed',
$user->sms . ' (' . $carrier->name . ')');
$this->element('p', 'form_guide',
// TRANS: Form guide in SMS settings form.
_('Current confirmed SMS-enabled phone number.'));
$this->element(
'p',
'form_confirmed',
$user->sms . ' (' . $carrier->name . ')'
);
$this->element(
'p',
'form_guide',
// TRANS: Form guide in SMS settings form.
_('Current confirmed SMS-enabled phone number.')
);
$this->hidden('sms', $user->sms);
$this->hidden('carrier', $user->carrier);
// TRANS: Button label to remove a confirmed SMS address.
$this->submit('remove', _m('BUTTON','Remove'));
$this->submit('remove', _m('BUTTON', 'Remove'));
} else {
try {
$confirm = $this->getConfirmation();
$carrier = Sms_carrier::getKV($confirm->address_extra);
$this->element('p', 'form_unconfirmed',
$confirm->address . ' (' . $carrier->name . ')');
$this->element('p', 'form_guide',
// TRANS: Form guide in IM settings form.
_('Awaiting confirmation on this phone number.'));
$this->element(
'p',
'form_unconfirmed',
$confirm->address . ' (' . $carrier->name . ')'
);
$this->element(
'p',
'form_guide',
// TRANS: Form guide in IM settings form.
_('Awaiting confirmation on this phone number.')
);
$this->hidden('sms', $confirm->address);
$this->hidden('carrier', $confirm->address_extra);
// TRANS: Button label to cancel a SMS address confirmation procedure.
$this->submit('cancel', _m('BUTTON','Cancel'));
$this->submit('cancel', _m('BUTTON', 'Cancel'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
// TRANS: Field label for SMS address input in SMS settings form.
$this->input('code', _('Confirmation code'), null,
// TRANS: Form field instructions in SMS settings form.
_('Enter the code you received on your phone.'));
$this->input(
'code',
_('Confirmation code'),
null,
// TRANS: Form field instructions in SMS settings form.
_('Enter the code you received on your phone.')
);
$this->elementEnd('li');
$this->elementEnd('ul');
// TRANS: Button label to confirm SMS confirmation code in SMS settings.
$this->submit('confirm', _m('BUTTON','Confirm'));
$this->submit('confirm', _m('BUTTON', 'Confirm'));
} catch (NoResultException $e) {
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
// TRANS: Field label for SMS phone number input in SMS settings form.
$this->input('sms', _('SMS phone number'),
($this->arg('sms')) ? $this->arg('sms') : null,
// TRANS: SMS phone number input field instructions in SMS settings form.
_('Phone number, no punctuation or spaces, '.
'with area code.'));
$this->input(
'sms',
_('SMS phone number'),
($this->arg('sms') ?: null),
// TRANS: SMS phone number input field instructions in SMS settings form.
_('Phone number, no punctuation or spaces, ' .
'with area code.')
);
$this->elementEnd('li');
$this->elementEnd('ul');
$this->carrierSelect();
// TRANS: Button label for adding a SMS phone number in SMS settings form.
$this->submit('add', _m('BUTTON','Add'));
$this->submit('add', _m('BUTTON', 'Add'));
}
}
$this->elementEnd('fieldset');
if ($user->sms) {
$this->elementStart('fieldset', array('id' => 'settings_sms_incoming_email'));
$this->elementStart('fieldset', ['id' => 'settings_sms_incoming_email']);
// XXX: Confused! This is about SMS. Should this message be updated?
// TRANS: Form legend for incoming SMS settings form.
$this->element('legend', null, _('Incoming email'));
if ($user->incomingemail) {
$this->element('p', 'form_unconfirmed', $user->incomingemail);
$this->element('p', 'form_note',
// XXX: Confused! This is about SMS. Should this message be updated?
// TRANS: Form instructions for incoming SMS e-mail address form in SMS settings.
_('Send email to this address to post new notices.'));
$this->element(
'p',
'form_note',
// XXX: Confused! This is about SMS. Should this message be updated?
// TRANS: Form instructions for incoming SMS e-mail address form in SMS settings.
_('Send email to this address to post new notices.')
);
// TRANS: Button label for removing a set sender SMS e-mail address to post notices from.
$this->submit('removeincoming', _m('BUTTON','Remove'));
$this->submit('removeincoming', _m('BUTTON', 'Remove'));
}
$this->element('p', 'form_guide',
// XXX: Confused! This is about SMS. Should this message be updated?
// TRANS: Instructions for incoming SMS e-mail address input form.
_('Make a new email address for posting to; '.
'cancels the old one.'));
$this->element(
'p',
'form_guide',
// XXX: Confused! This is about SMS. Should this message be updated?
// TRANS: Instructions for incoming SMS e-mail address input form.
_('Make a new email address for posting to; ' .
'cancels the old one.')
);
// TRANS: Button label for adding an SMS e-mail address to send notices from.
$this->submit('newincoming', _m('BUTTON','New'));
$this->submit('newincoming', _m('BUTTON', 'New'));
$this->elementEnd('fieldset');
}
@@ -190,17 +208,19 @@ class SmssettingsAction extends SettingsAction
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->checkbox('smsnotify',
// TRANS: Checkbox label in SMS preferences form.
_('Send me notices through SMS; '.
'I understand I may incur '.
'exorbitant charges from my carrier.'),
$user->smsnotify);
$this->checkbox(
'smsnotify',
// TRANS: Checkbox label in SMS preferences form.
_('Send me notices through SMS; ' .
'I understand I may incur ' .
'exorbitant charges from my carrier.'),
$user->smsnotify
);
$this->elementEnd('li');
$this->elementEnd('ul');
// TRANS: Button label to save SMS preferences.
$this->submit('save', _m('BUTTON','Save'));
$this->submit('save', _m('BUTTON', 'Save'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
@@ -213,7 +233,7 @@ class SmssettingsAction extends SettingsAction
*
* @todo very similar to EmailsettingsAction::getConfirmation(); refactor?
*/
function getConfirmation()
public function getConfirmation()
{
$confirm = new Confirm_address();
@@ -229,20 +249,19 @@ class SmssettingsAction extends SettingsAction
protected function doPost()
{
if ($this->arg('save')) {
return $this->savePreferences();
} else if ($this->arg('add')) {
} elseif ($this->arg('add')) {
return $this->addAddress();
} else if ($this->arg('cancel')) {
} elseif ($this->arg('cancel')) {
return $this->cancelConfirmation();
} else if ($this->arg('remove')) {
} elseif ($this->arg('remove')) {
return $this->removeAddress();
} else if ($this->arg('removeincoming')) {
} elseif ($this->arg('removeincoming')) {
return $this->removeIncoming();
} else if ($this->arg('newincoming')) {
} elseif ($this->arg('newincoming')) {
return $this->newIncoming();
} else if ($this->arg('confirm')) {
} elseif ($this->arg('confirm')) {
return $this->confirmCode();
}
// TRANS: Message given submitting a form with an unknown action in SMS settings.
@@ -256,7 +275,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function savePreferences()
public function savePreferences()
{
$user = $this->scoped->getUser();
@@ -288,7 +307,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function addAddress()
public function addAddress()
{
$user = common_current_user();
@@ -312,7 +331,7 @@ class SmssettingsAction extends SettingsAction
if ($user->sms === $sms) {
// TRANS: Message given saving SMS phone number that is already set.
throw new AlreadyFulfilledException(_('That is already your phone number.'));
} else if ($this->smsExists($sms)) {
} elseif ($this->smsExists($sms)) {
// TRANS: Message given saving SMS phone number that is already set for another user.
throw new ClientException(_('That phone number already belongs to another user.'));
}
@@ -335,9 +354,11 @@ class SmssettingsAction extends SettingsAction
$carrier = Sms_carrier::getKV($carrier_id);
mail_confirm_sms($confirm->code,
$user->nickname,
$carrier->toEmailAddress($sms));
mail_confirm_sms(
$confirm->code,
$user->nickname,
$carrier->toEmailAddress($sms)
);
// TRANS: Message given saving valid SMS phone number that is to be confirmed.
return _('A confirmation code was sent to the phone number you added. '.
@@ -352,7 +373,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function cancelConfirmation()
public function cancelConfirmation()
{
$sms = $this->trimmed('sms');
$carrier = $this->trimmed('carrier');
@@ -379,7 +400,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function removeAddress()
public function removeAddress()
{
$user = $this->scoped->getUser();
@@ -396,9 +417,9 @@ class SmssettingsAction extends SettingsAction
$original = clone($user);
$user->sms = null;
$user->carrier = null;
$user->smsemail = null;
$user->sms = 'NULL';
$user->carrier = 'NULL';
$user->smsemail = 'NULL';
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($original);
@@ -416,7 +437,7 @@ class SmssettingsAction extends SettingsAction
*
* @return boolean does the number exist
*/
function smsExists($sms)
public function smsExists($sms)
{
$other = User::getKV('sms', $sms);
@@ -432,7 +453,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function carrierSelect()
public function carrierSelect()
{
$carrier = new Sms_carrier();
@@ -444,22 +465,33 @@ class SmssettingsAction extends SettingsAction
$this->element('label', array('for' => 'carrier'), _('Mobile carrier'));
$this->elementStart('select', array('name' => 'carrier',
'id' => 'carrier'));
$this->element('option', array('value' => 0),
// TRANS: Default option for mobile carrier dropdown menu in SMS settings.
_('Select a carrier'));
$this->element(
'option',
['value' => 0],
// TRANS: Default option for mobile carrier dropdown menu in SMS settings.
_('Select a carrier')
);
while ($carrier->fetch()) {
$this->element('option', array('value' => $carrier->id),
$carrier->name);
$this->element(
'option',
['value' => $carrier->id],
$carrier->name
);
}
$this->elementEnd('select');
$this->element('p', 'form_guide',
// TRANS: Form instructions for mobile carrier dropdown menu in SMS settings.
// TRANS: %s is an administrative contact's e-mail address.
sprintf(_('Mobile carrier for your phone. '.
'If you know a carrier that accepts ' .
'SMS over email but isn\'t listed here, ' .
'send email to let us know at %s.'),
common_config('site', 'email')));
$this->element(
'p',
'form_guide',
// TRANS: Form instructions for mobile carrier dropdown menu in SMS settings.
// TRANS: %s is an administrative contact's e-mail address.
sprintf(
_('Mobile carrier for your phone. ' .
'If you know a carrier that accepts ' .
'SMS over email but isn\'t listed here, ' .
'send email to let us know at %s.'),
common_config('site', 'email')
)
);
$this->elementEnd('li');
$this->elementEnd('ul');
}
@@ -471,7 +503,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function confirmCode()
public function confirmCode()
{
$code = $this->trimmed('code');
@@ -488,7 +520,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
function removeIncoming()
public function removeIncoming()
{
$user = common_current_user();
@@ -499,7 +531,7 @@ class SmssettingsAction extends SettingsAction
$orig = clone($user);
$user->incomingemail = null;
$user->incomingemail = 'NULL';
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($orig);
@@ -515,7 +547,7 @@ class SmssettingsAction extends SettingsAction
*
* @see Emailsettings::newIncoming
*/
function newIncoming()
public function newIncoming()
{
$user = $this->scoped->getUser();
+24 -27
Ver Arquivo
@@ -1,28 +1,25 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
defined('GNUSOCIAL') || die();
// @todo FIXME: documentation needed.
class SupAction extends Action
{
function handle()
public function handle()
{
parent::handle();
@@ -43,21 +40,23 @@ class SupAction extends Action
'updates' => $updates));
}
function availablePeriods()
public function availablePeriods()
{
static $periods = array(86400, 43200, 21600, 7200,
3600, 1800, 600, 300, 120,
60, 30, 15);
$available = array();
foreach ($periods as $period) {
$available[$period] = common_local_url('sup',
array('seconds' => $period));
$available[$period] = common_local_url(
'sup',
['seconds' => $period]
);
}
return $available;
}
function getUpdates($seconds)
public function getUpdates($seconds)
{
$notice = new Notice();
@@ -69,9 +68,7 @@ class SupAction extends Action
$notice->query('SELECT profile_id, max(id) AS max_id ' .
'FROM ( ' .
'SELECT profile_id, id FROM notice ' .
((common_config('db','type') == 'pgsql') ?
'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' :
'WHERE created > "'.$divider.'" ' ) .
"WHERE created > TIMESTAMP '" . $divider . "' " .
') AS latest ' .
'GROUP BY profile_id');
@@ -84,7 +81,7 @@ class SupAction extends Action
return $updates;
}
function isReadOnly($args)
public function isReadOnly($args)
{
return true;
}
+1 -1
Ver Arquivo
@@ -32,7 +32,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/grouplist.php';
require_once INSTALLDIR . '/lib/groups/grouplist.php';
/**
* User groups page
+10
Ver Arquivo
@@ -0,0 +1,10 @@
<?php
namespace App;
class User extends \Illuminate\Database\Eloquent\Model {
protected $table = 'user';
protected $hidden = [];
public $timestamps = false;
}
+16
Ver Arquivo
@@ -0,0 +1,16 @@
<?php
namespace App;
class UserGroup extends \Illuminate\Database\Eloquent\Model {
protected $table = 'user_group';
protected $guarded = [];
public $timestamps = false;
public function url()
{
return '/groups/' . $this->id;
}
}
+10
Ver Arquivo
@@ -0,0 +1,10 @@
<?php
namespace App;
class UserModel extends \Illuminate\Database\Eloquent\Model {
protected $table = 'user';
protected $hidden = [];
public $timestamps = false;
}
+42 -20
Ver Arquivo
@@ -1,6 +1,20 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for avatar
@@ -10,20 +24,20 @@ class Avatar extends Managed_DataObject
{
public $__table = 'avatar'; // table name
public $profile_id; // int(4) primary_key not_null
public $original; // tinyint(1)
public $original; // bool default_false
public $width; // int(4) primary_key not_null
public $height; // int(4) primary_key not_null
public $mediatype; // varchar(32) not_null
public $filename; // varchar(191) not 255 because utf8mb4 takes more space
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
public static function schemaDef()
{
return array(
'fields' => array(
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
'original' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'uploaded by user or generated?'),
'original' => array('type' => 'bool', 'default' => false, 'description' => 'uploaded by user or generated?'),
'width' => array('type' => 'int', 'not null' => true, 'description' => 'image width'),
'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
@@ -45,7 +59,7 @@ class Avatar extends Managed_DataObject
}
// We clean up the file, too
function delete($useWhere=false)
public function delete($useWhere = false)
{
$filename = $this->filename;
if (file_exists(Avatar::path($filename))) {
@@ -57,11 +71,12 @@ class Avatar extends Managed_DataObject
/*
* Deletes all avatars (but may spare the original) from a profile.
*
*
* @param Profile $target The profile we're deleting avatars of.
* @param boolean $original Whether original should be removed or not.
*/
public static function deleteFromProfile(Profile $target, $original=true) {
public static function deleteFromProfile(Profile $target, $original = true)
{
try {
$avatars = self::getProfileAvatars($target);
foreach ($avatars as $avatar) {
@@ -77,7 +92,7 @@ class Avatar extends Managed_DataObject
return true;
}
static protected $_avatars = array();
protected static $_avatars = [];
/*
* Get an avatar by profile. Currently can't call newSize with $height
@@ -93,7 +108,7 @@ class Avatar extends Managed_DataObject
$size = "{$width}x{$height}";
if (!isset(self::$_avatars[$target->id])) {
self::$_avatars[$target->id] = array();
} elseif (isset(self::$_avatars[$target->id][$size])){
} elseif (isset(self::$_avatars[$target->id][$size])) {
return self::$_avatars[$target->id][$size];
}
@@ -137,7 +152,8 @@ class Avatar extends Managed_DataObject
return $avatar;
}
public static function getProfileAvatars(Profile $target) {
public static function getProfileAvatars(Profile $target)
{
$avatar = new Avatar();
$avatar->profile_id = $target->id;
if (!$avatar->find()) {
@@ -149,7 +165,7 @@ class Avatar extends Managed_DataObject
/**
* Where should the avatar go for this user?
*/
static function filename($id, $extension, $size=null, $extra=null)
public static function filename($id, $extension, $size = null, $extra = null)
{
if ($size) {
return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
@@ -158,7 +174,7 @@ class Avatar extends Managed_DataObject
}
}
static function path($filename)
public static function path($filename)
{
$dir = common_config('avatar', 'dir');
@@ -169,7 +185,7 @@ class Avatar extends Managed_DataObject
return $dir . $filename;
}
static function url($filename)
public static function url($filename)
{
$path = common_config('avatar', 'path');
@@ -194,20 +210,21 @@ class Avatar extends Managed_DataObject
return $protocol.'://'.$server.$path.$filename;
}
function displayUrl()
public function displayUrl()
{
return Avatar::url($this->filename);
}
static function urlByProfile(Profile $target, $width=null, $height=null) {
public static function urlByProfile(Profile $target, $width = null, $height = null)
{
try {
return self::byProfile($target, $width, $height)->displayUrl();
return self::byProfile($target, $width, $height)->displayUrl();
} catch (Exception $e) {
return self::defaultImage($width);
}
}
static function defaultImage($size=null)
public static function defaultImage($size = null)
{
if (is_null($size)) {
$size = AVATAR_PROFILE_SIZE;
@@ -218,7 +235,8 @@ class Avatar extends Managed_DataObject
return Theme::path('default-avatar-'.$sizenames[$size].'.png');
}
static function newSize(Profile $target, $width) {
public static function newSize(Profile $target, $width)
{
$width = intval($width);
if ($width < 1 || $width > common_config('avatar', 'maxsize')) {
// TRANS: An error message when avatar size is unreasonable
@@ -231,8 +249,12 @@ class Avatar extends Managed_DataObject
$original = Avatar::getUploaded($target);
$imagefile = new ImageFile(null, Avatar::path($original->filename));
$filename = Avatar::filename($target->getID(), image_type_to_extension($imagefile->preferredType()),
$width, common_timestamp());
$filename = Avatar::filename(
$target->getID(),
image_type_to_extension($imagefile->preferredType()),
$width,
common_timestamp()
);
$imagefile->resizeTo(Avatar::path($filename), array('width'=>$width, 'height'=>$height));
$scaled = clone($original);
+1 -1
Ver Arquivo
@@ -142,7 +142,7 @@ class Confirm_address extends Managed_DataObject
$args['sitename'],
$args['url']);
require_once(INSTALLDIR . '/lib/mail.php');
require_once INSTALLDIR . '/lib/util/mail.php';
return mail_to_user($this->getProfile()->getUser(), $subject, $body, $args['headers'], $this->getAddress());
}
+33 -31
Ver Arquivo
@@ -1,35 +1,32 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Data class for Conversations
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Data
* @package StatusNet
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2010 StatusNet Inc.
* @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
class Conversation extends Managed_DataObject
{
@@ -57,14 +54,14 @@ class Conversation extends Managed_DataObject
);
}
static public function beforeSchemaUpdate()
public static function beforeSchemaUpdate()
{
$table = strtolower(get_called_class());
$schema = Schema::get();
$schemadef = $schema->getTableDef($table);
// 2016-01-06 We have to make sure there is no conversation with id==0 since it will screw up auto increment resequencing
if ($schemadef['fields']['id']['auto_increment']) {
if ($schemadef['fields']['id']['auto_increment'] ?? false) {
// since we already have auto incrementing ('serial') we can continue
return;
}
@@ -91,7 +88,7 @@ class Conversation extends Managed_DataObject
*
* @return Conversation the new conversation DO
*/
static function create(ActivityContext $ctx=null, $created=null)
public static function create(ActivityContext $ctx = null, $created = null)
{
// Be aware that the Notice does not have an id yet since it's not inserted!
$conv = new Conversation();
@@ -100,11 +97,16 @@ class Conversation extends Managed_DataObject
$conv->uri = $ctx->conversation;
$conv->url = $ctx->conversation_url;
} else {
$conv->uri = sprintf('%s%s=%s:%s=%s',
TagURI::mint(),
'objectType', 'thread',
'nonce', common_random_hexstr(8));
$conv->url = null; // locally generated Conversation objects don't get static URLs stored
$conv->uri = sprintf(
'%s%s=%s:%s=%s',
TagURI::mint(),
'objectType',
'thread',
'nonce',
common_random_hexstr(8)
);
// locally generated Conversation objects don't get static URLs stored
$conv->url = 'NULL';
}
// This insert throws exceptions on failure
$conv->insert();
@@ -112,7 +114,7 @@ class Conversation extends Managed_DataObject
return $conv;
}
static function noticeCount($id)
public static function noticeCount($id)
{
$keypart = sprintf('conversation:notice_count:%d', $id);
@@ -132,7 +134,7 @@ class Conversation extends Managed_DataObject
return $cnt;
}
static public function getUrlFromNotice(Notice $notice, $anchor=true)
public static function getUrlFromNotice(Notice $notice, $anchor = true)
{
$conv = Conversation::getByID($notice->conversation);
return $conv->getUrl($anchor ? $notice->getID() : null);
+61 -45
Ver Arquivo
@@ -1,29 +1,26 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* GNU social - a federating social network
*
* Abstraction for files
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Files
* @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se>
* @author Miguel Dantas <biodantas@gmail.com>
* @copyright 2008-2009, 2019 Free Software Foundation http://fsf.org
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link https://www.gnu.org/software/social/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
@@ -248,14 +245,14 @@ class File extends Managed_DataObject
// TRANS: gettext support multiple plurals in the same message, unfortunately...
throw new ClientException(
sprintf(
_m(
_m(
'No file may be larger than %1$d byte and the file you sent was %2$s. Try to upload a smaller version.',
'No file may be larger than %1$d bytes and the file you sent was %2$s. Try to upload a smaller version.',
$fileQuota
),
$fileQuota,
$fileSizeText
)
$fileQuota,
$fileSizeText
)
);
}
@@ -277,13 +274,13 @@ class File extends Managed_DataObject
// TRANS: %d (number) is the user quota in bytes and is used for plural.
throw new ClientException(
sprintf(
_m(
_m(
'A file this large would exceed your user quota of %d byte.',
'A file this large would exceed your user quota of %d bytes.',
common_config('attachments', 'user_quota')
),
common_config('attachments', 'user_quota')
)
common_config('attachments', 'user_quota')
)
);
}
$query .= ' AND EXTRACT(month FROM file.modified) = EXTRACT(month FROM now()) AND EXTRACT(year FROM file.modified) = EXTRACT(year FROM now())';
@@ -295,13 +292,13 @@ class File extends Managed_DataObject
// TRANS: $d (number) is the monthly user quota in bytes and is used for plural.
throw new ClientException(
sprintf(
_m(
_m(
'A file this large would exceed your monthly quota of %d byte.',
'A file this large would exceed your monthly quota of %d bytes.',
common_config('attachments', 'monthly_quota')
),
common_config('attachments', 'monthly_quota')
)
common_config('attachments', 'monthly_quota')
)
);
}
return true;
@@ -312,9 +309,9 @@ class File extends Managed_DataObject
return self::tryFilename($this->filename);
}
public function getSize()
public function getSize(): int
{
return intval($this->size);
return (int)$this->size;
}
// where should the file go?
@@ -345,8 +342,10 @@ class File extends Managed_DataObject
/**
* @param string $filename
* @return string|bool Value from the 'extblacklist' array, in the config
* @throws ServerException
*/
public static function getSafeExtension(string $filename) {
public static function getSafeExtension(string $filename)
{
if (preg_match('/^.+?\.([A-Za-z0-9]+)$/', $filename, $matches) === 1) {
// we matched on a file extension, so let's see if it means something.
$ext = mb_strtolower($matches[1]);
@@ -375,6 +374,7 @@ class File extends Managed_DataObject
* @param $filename string An optional filename which we can use on failure.
* @return mixed|string
* @throws ClientException
* @throws ServerException
*/
public static function guessMimeExtension($mimetype, $filename=null)
{
@@ -433,6 +433,7 @@ class File extends Managed_DataObject
* @param $filename
* @return string
* @throws InvalidFilenameException
* @throws ServerException
*/
public static function path($filename)
{
@@ -563,7 +564,7 @@ class File extends Managed_DataObject
* @throws UnsupportedMediaException if, despite trying, we can't understand how to make a thumbnail for this format
* @throws ServerException on various other errors
*/
public function getThumbnail($width=null, $height=null, $crop=false, $force_still=true, $upscale=null)
public function getThumbnail($width = null, $height = null, $crop = false, $force_still = true, $upscale = null): File_thumbnail
{
// Get some more information about this file through our ImageFile class
$image = ImageFile::fromFileObject($this);
@@ -602,13 +603,14 @@ class File extends Managed_DataObject
* Returns the path to either a file, or it's thumbnail if the file doesn't exist.
* This is useful in case the original file is deleted, or, as is the case for Embed
* thumbnails, we only have a thumbnail and not a file
* @param File_thumbnail|null $thumbnail
* @return string Path
* @throws FileNotFoundException
* @throws FileNotStoredLocallyException
* @throws InvalidFilenameException
* @throws ServerException
*/
public function getFileOrThumbnailPath($thumbnail = null) : string
public function getFileOrThumbnailPath(?File_thumbnail $thumbnail = null): string
{
if (!empty($thumbnail)) {
return $thumbnail->getPath();
@@ -632,13 +634,15 @@ class File extends Managed_DataObject
/**
* Return the mime type of the thumbnail if we have it, or, if not, of the File
* @param File_thumbnail|null $thumbnail
* @return string
* @throws FileNotFoundException
* @throws NoResultException
* @throws ServerException
* @throws UnsupportedMediaException
* @throws Exception
*/
public function getFileOrThumbnailMimetype($thumbnail = null) : string
public function getFileOrThumbnailMimetype(?File_thumbnail $thumbnail = null) : string
{
if (!empty($thumbnail)) {
$filepath = $thumbnail->getPath();
@@ -658,17 +662,18 @@ class File extends Managed_DataObject
/**
* Return the size of the thumbnail if we have it, or, if not, of the File
* @param File_thumbnail|null $thumbnail
* @return int
* @throws FileNotFoundException
* @throws NoResultException
* @throws ServerException
*/
public function getFileOrThumbnailSize($thumbnail = null) : int
public function getFileOrThumbnailSize(?File_thumbnail $thumbnail = null) : int
{
if (!empty($thumbnail)) {
return filesize($thumbnail->getPath());
} elseif (!empty($this->filename)) {
return $this->size;
return $this->getSize();
} else {
return filesize(File_thumbnail::byFile($this)->getPath());
}
@@ -798,7 +803,7 @@ class File extends Managed_DataObject
public function noticeCount()
{
$cacheKey = sprintf('file:notice-count:%d', $this->id);
$count = self::cacheGet($cacheKey);
if ($count === false) {
@@ -888,7 +893,11 @@ class File extends Managed_DataObject
echo "\nFound old $table table, upgrading it to contain 'urlhash' field...";
$file = new File();
$file->query(sprintf('SELECT id, LEFT(url, 191) AS shortenedurl, COUNT(*) AS c FROM %1$s WHERE LENGTH(url)>191 GROUP BY shortenedurl HAVING c > 1', $schema->quoteIdentifier($table)));
$file->query(sprintf(
'SELECT id, LEFT(url, 191) AS shortenedurl, COUNT(*) FROM %1$s ' .
'WHERE LENGTH(url) > 191 GROUP BY id, shortenedurl HAVING COUNT(*) > 1',
common_database_tablename($table)
));
print "\nFound {$file->N} URLs with too long entries in file table\n";
while ($file->fetch()) {
// We've got a URL that is too long for our future file table
@@ -941,13 +950,20 @@ class File extends Managed_DataObject
$tablefix = new $classname;
// urlhash is hash('sha256', $url) in the File table
echo "Updating urlhash fields in $table table...";
// Maybe very MySQL specific :(
switch (common_config('db', 'type')) {
case 'pgsql':
$url_sha256 = 'encode(sha256(CAST("url" AS bytea)), \'hex\')';
break;
case 'mysql':
$url_sha256 = 'sha2(`url`, 256)';
break;
default:
throw new ServerException('Unknown DB type selected.');
}
$tablefix->query(sprintf(
'UPDATE %1$s SET %2$s=%3$s;',
$schema->quoteIdentifier($table),
'urlhash',
// The line below is "result of sha256 on column `url`"
'SHA2(url, 256)'
'UPDATE %1$s SET urlhash = %2$s;',
$tablefix->escapedTableName(),
$url_sha256
));
echo "DONE.\n";
echo "Resuming core schema upgrade...";
+115 -82
Ver Arquivo
@@ -1,28 +1,24 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for file_redirection
*/
class File_redirection extends Managed_DataObject
{
###START_AUTOCODE
@@ -54,17 +50,18 @@ class File_redirection extends Managed_DataObject
),
'primary key' => array('urlhash'),
'foreign keys' => array(
'file_redirection_file_id_fkey' => array('file' => array('file_id' => 'id')),
'file_redirection_file_id_fkey' => array('file', array('file_id' => 'id')),
),
);
}
static public function getByUrl($url)
public static function getByUrl($url)
{
return self::getByPK(array('urlhash' => File::hashurl($url)));
}
static function _commonHttp($url, $redirs) {
public static function _commonHttp($url, $redirs)
{
$request = new HTTPClient($url);
$request->setConfig(array(
'connect_timeout' => 10, // # seconds to wait
@@ -96,10 +93,13 @@ class File_redirection extends Managed_DataObject
* size (optional): byte size from Content-Length header
* time (optional): timestamp from Last-Modified header
*/
static function lookupWhere($short_url, $redirs = 10, $protected = false) {
if ($redirs < 0) return false;
public static function lookupWhere($short_url, $redirs = 10, $protected = false)
{
if ($redirs < 0) {
return false;
}
if(strpos($short_url,'://') === false){
if (strpos($short_url, '://') === false) {
return $short_url;
}
try {
@@ -128,13 +128,13 @@ class File_redirection extends Managed_DataObject
common_log(LOG_ERR, "Error while following redirects for $short_url: " . $e->getMessage());
return $short_url;
}
// if last url after all redirections is protected,
// use the url before it in the redirection chain
// if last url after all redirections is protected,
// use the url before it in the redirection chain
if ($response->getRedirectCount() && File::isProtected($response->getEffectiveUrl())) {
$return_url = $response->redirUrls[$response->getRedirectCount()-1];
$return_url = $response->redirUrls[$response->getRedirectCount() - 1];
} else {
$return_url = $response->getEffectiveUrl();
$return_url = $response->getEffectiveUrl();
}
$ret = array('code' => $response->getStatus()
@@ -142,12 +142,20 @@ class File_redirection extends Managed_DataObject
, 'url' => $return_url);
$type = $response->getHeader('Content-Type');
if ($type) $ret['type'] = $type;
if ($protected) $ret['protected'] = true;
if ($type) {
$ret['type'] = $type;
}
if ($protected) {
$ret['protected'] = true;
}
$size = $response->getHeader('Content-Length'); // @fixme bytes?
if ($size) $ret['size'] = $size;
if ($size) {
$ret['size'] = $size;
}
$time = $response->getHeader('Last-Modified');
if ($time) $ret['time'] = strtotime($time);
if ($time) {
$ret['time'] = strtotime($time);
}
return $ret;
}
@@ -164,7 +172,8 @@ class File_redirection extends Managed_DataObject
* @param boolean $discover true to attempt dereferencing the redirect if we don't know it already
* @return File_redirection
*/
static function where($in_url, $discover=true) {
public static function where($in_url, $discover = true)
{
$redir = new File_redirection();
$redir->url = $in_url;
$redir->urlhash = File::hashurl($redir->url);
@@ -179,14 +188,16 @@ class File_redirection extends Managed_DataObject
$r->redir_url = $f->url;
} catch (NoResultException $e) {
// Invalid entry, delete and run again
common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File redirection entry and and trying again...");
common_log(
LOG_ERR,
'Could not find File with id=' . $r->file_id . ' referenced in File_redirection, deleting File redirection entry and and trying again...'
);
$r->delete();
return self::where($in_url);
return self::where($in_url);
}
// File_redirecion and File record found, return both
return $r;
} catch (NoResultException $e) {
// File_redirecion record not found, but this might be a direct link to a file
try {
@@ -194,15 +205,15 @@ class File_redirection extends Managed_DataObject
$redir->file_id = $f->id;
$redir->file = $f;
return $redir;
} catch (NoResultException $e) {
} catch (NoResultException $e) {
// nope, this was not a direct link to a file either, let's keep going
}
}
if ($discover) {
// try to follow redirects and get the final url
if ($discover) {
// try to follow redirects and get the final url
$redir_info = File_redirection::lookupWhere($in_url);
if(is_string($redir_info)) {
if (is_string($redir_info)) {
$redir_info = array('url' => $redir_info);
}
@@ -212,29 +223,32 @@ class File_redirection extends Managed_DataObject
try {
$r = File_redirection::getByUrl($redir_info['url']);
$f = File::getKV('id',$r->file_id);
$f = File::getKV('id', $r->file_id);
if($f instanceof File) {
if ($f instanceof File) {
$redir->file = $f;
$redir->redir_url = $f->url;
$redir->redir_url = $f->url;
} else {
// Invalid entry in File_redirection, delete and run again
common_log(LOG_ERR, "Could not find File with id=".$r->file_id." referenced in File_redirection, deleting File_redirection entry and trying again...");
common_log(
LOG_ERR,
'Could not find File with id=' . $r->file_id . ' referenced in File_redirection, deleting File_redirection entry and trying again...'
);
$r->delete();
return self::where($in_url);
return self::where($in_url);
}
} catch (NoResultException $e) {
// save the file now when we know that we don't have it in File_redirection
try {
$redir->file = File::saveNew($redir_info,$redir_info['url']);
$redir->file = File::saveNew($redir_info, $redir_info['url']);
} catch (ServerException $e) {
common_log(LOG_ERR, $e);
}
}
}
// If this is a redirection and we have a file to redirect to, save it
// (if it doesn't exist in File_redirection already)
if($redir->file instanceof File && $redir_info['url'] != $in_url) {
// (if it doesn't exist in File_redirection already)
if ($redir->file instanceof File && $redir_info['url'] != $in_url) {
try {
$file_redir = File_redirection::getByUrl($in_url);
} catch (NoResultException $e) {
@@ -243,12 +257,12 @@ class File_redirection extends Managed_DataObject
$file_redir->url = $in_url;
$file_redir->file_id = $redir->file->getID();
$file_redir->insert();
$file_redir->redir_url = $redir->file->url;
}
$file_redir->redir_url = $redir->file->url;
}
$file_redir->file = $redir->file;
return $file_redir;
}
$file_redir->file = $redir->file;
return $file_redir;
}
}
return $redir;
@@ -268,7 +282,7 @@ class File_redirection extends Managed_DataObject
* @param User $user whose shortening options to use; defaults to the current web session user
* @return string
*/
static function makeShort($long_url, $user=null)
public static function makeShort($long_url, $user = null)
{
$canon = File_redirection::_canonUrl($long_url);
@@ -293,7 +307,7 @@ class File_redirection extends Managed_DataObject
* @return string
*/
static function forceShort($long_url, $user)
public static function forceShort($long_url, $user)
{
$canon = File_redirection::_canonUrl($long_url);
@@ -303,7 +317,8 @@ class File_redirection extends Managed_DataObject
return !empty($short_url) ? $short_url : $long_url;
}
static function _userMakeShort($long_url, User $user=null, $force = false) {
public static function _userMakeShort($long_url, User $user = null, $force = false)
{
$short_url = common_shorten_url($long_url, $user, $force);
if (!empty($short_url) && $short_url != $long_url) {
$short_url = (string)$short_url;
@@ -343,8 +358,11 @@ class File_redirection extends Managed_DataObject
* @param string $default_scheme if given a bare link; defaults to 'http://'
* @return string
*/
static function _canonUrl($in_url, $default_scheme = 'http://') {
if (empty($in_url)) return false;
public static function _canonUrl($in_url, $default_scheme = 'http://')
{
if (empty($in_url)) {
return false;
}
$out_url = $in_url;
$p = parse_url($out_url);
if (empty($p['host']) || empty($p['scheme'])) {
@@ -377,13 +395,17 @@ class File_redirection extends Managed_DataObject
default:
$out_url = $default_scheme . ltrim($out_url, '/');
$p = parse_url($out_url);
if (empty($p['scheme'])) return false;
if (empty($p['scheme'])) {
return false;
}
break;
}
}
if (('ftp' == $p['scheme']) || ('ftps' == $p['scheme']) || ('http' == $p['scheme']) || ('https' == $p['scheme'])) {
if (empty($p['host'])) return false;
if (empty($p['host'])) {
return false;
}
if (empty($p['path'])) {
$out_url .= '/';
}
@@ -392,7 +414,8 @@ class File_redirection extends Managed_DataObject
return $out_url;
}
static function saveNew($data, $file_id, $url) {
public static function saveNew($data, $file_id, $url)
{
$file_redir = new File_redirection;
$file_redir->urlhash = File::hashurl($url);
$file_redir->url = $url;
@@ -402,7 +425,7 @@ class File_redirection extends Managed_DataObject
$file_redir->insert();
}
static public function beforeSchemaUpdate()
public static function beforeSchemaUpdate()
{
$table = strtolower(get_called_class());
$schema = Schema::get();
@@ -416,16 +439,16 @@ class File_redirection extends Managed_DataObject
echo "\nFound old $table table, upgrading it to contain 'urlhash' field...";
// We have to create a urlhash that is _not_ the primary key,
// transfer data and THEN run checkSchema
$schemadef['fields']['urlhash'] = array (
'type' => 'varchar',
'length' => 64,
'not null' => true,
'description' => 'sha256 hash of the URL',
);
$schemadef['fields']['url'] = array (
'type' => 'text',
'description' => 'short URL (or any other kind of redirect) for file (id)',
);
$schemadef['fields']['urlhash'] = [
'type' => 'varchar',
'length' => 64,
'not null' => true,
'description' => 'sha256 hash of the URL',
];
$schemadef['fields']['url'] = [
'type' => 'text',
'description' => 'short URL (or any other kind of redirect) for file (id)',
];
unset($schemadef['primary key']);
$schema->ensureTable($table, $schemadef);
echo "DONE.\n";
@@ -434,17 +457,27 @@ class File_redirection extends Managed_DataObject
$tablefix = new $classname;
// urlhash is hash('sha256', $url) in the File table
echo "Updating urlhash fields in $table table...";
// Maybe very MySQL specific :(
$tablefix->query(sprintf('UPDATE %1$s SET %2$s=%3$s;',
$schema->quoteIdentifier($table),
'urlhash',
// The line below is "result of sha256 on column `url`"
'SHA2(url, 256)'));
switch (common_config('db', 'type')) {
case 'pgsql':
$url_sha256 = 'encode(sha256(CAST("url" AS bytea)), \'hex\')';
break;
case 'mysql':
$url_sha256 = 'sha2(`url`, 256)';
break;
default:
throw new ServerException('Unknown DB type selected.');
}
$tablefix->query(sprintf(
'UPDATE %1$s SET urlhash = %2$s;',
$tablefix->escapedTableName(),
$url_sha256
));
echo "DONE.\n";
echo "Resuming core schema upgrade...";
}
public function getFile() {
public function getFile()
{
if (!$this->file instanceof File) {
$this->file = File::getByID($this->file_id);
}
+41 -34
Ver Arquivo
@@ -1,28 +1,29 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for file_thumbnail
*/
class File_thumbnail extends Managed_DataObject
{
public $__table = 'file_thumbnail'; // table name
@@ -44,8 +45,8 @@ class File_thumbnail extends Managed_DataObject
'urlhash' => array('type' => 'varchar', 'length' => 64, 'description' => 'sha256 of url field if non-empty'),
'url' => array('type' => 'text', 'description' => 'URL of thumbnail'),
'filename' => array('type' => 'text', 'description' => 'if stored locally, filename is put here'),
'width' => array('type' => 'int', 'description' => 'width of thumbnail'),
'height' => array('type' => 'int', 'description' => 'height of thumbnail'),
'width' => array('type' => 'int', 'not null' => true, 'description' => 'width of thumbnail'),
'height' => array('type' => 'int', 'not null' => true, 'description' => 'height of thumbnail'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
'primary key' => array('file_id', 'width', 'height'),
@@ -65,21 +66,26 @@ class File_thumbnail extends Managed_DataObject
* @param object $data
* @param int $file_id
*/
public static function saveNew($data, $file_id) {
public static function saveNew($data, $file_id)
{
if (!empty($data->thumbnail_url)) {
// Non-photo types such as video will usually
// show us a thumbnail, though it's not required.
self::saveThumbnail($file_id,
$data->thumbnail_url,
$data->thumbnail_width,
$data->thumbnail_height);
} else if ($data->type == 'photo') {
self::saveThumbnail(
$file_id,
$data->thumbnail_url,
$data->thumbnail_width,
$data->thumbnail_height
);
} elseif ($data->type == 'photo') {
// The inline photo URL given should also fit within
// our requested thumbnail size, per oEmbed spec.
self::saveThumbnail($file_id,
$data->url,
$data->width,
$data->height);
self::saveThumbnail(
$file_id,
$data->url,
$data->width,
$data->height
);
}
}
@@ -92,7 +98,8 @@ class File_thumbnail extends Managed_DataObject
* @return File_thumbnail
* @throws NoResultException if no File_thumbnail matched the criteria
*/
static function byFile(File $file, $notNullUrl=true) {
public static function byFile(File $file, $notNullUrl = true)
{
$thumb = new File_thumbnail();
$thumb->file_id = $file->getID();
if ($notNullUrl) {
@@ -116,7 +123,7 @@ class File_thumbnail extends Managed_DataObject
* @param int $width
* @param int $height
*/
static function saveThumbnail($file_id, $url, $width, $height, $filename=null)
public static function saveThumbnail($file_id, $url, $width, $height, $filename = null)
{
$tn = new File_thumbnail;
$tn->file_id = $file_id;
@@ -128,7 +135,7 @@ class File_thumbnail extends Managed_DataObject
return $tn;
}
static function path($filename)
public static function path($filename)
{
File::tryFilename($filename);
@@ -142,7 +149,7 @@ class File_thumbnail extends Managed_DataObject
return $dir . $filename;
}
static function url($filename)
public static function url($filename)
{
File::tryFilename($filename);
@@ -276,7 +283,7 @@ class File_thumbnail extends Managed_DataObject
return $this->file_id;
}
static public function hashurl($url)
public static function hashurl($url)
{
if (!mb_strlen($url)) {
throw new Exception('No URL provided to hash algorithm.');
+24 -7
Ver Arquivo
@@ -1,4 +1,21 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
/**
* Table Definition for request_queue
*/
@@ -23,7 +40,7 @@ class Group_join_queue extends Managed_DataObject
'description' => 'Holder for group join requests awaiting moderation.',
'fields' => array(
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
'group_id' => array('type' => 'int', 'description' => 'remote or local group to join, if any'),
'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local group to join, if any'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
),
'primary key' => array('profile_id', 'group_id'),
@@ -48,27 +65,27 @@ class Group_join_queue extends Managed_DataObject
return $rq;
}
function getMember()
public function getMember()
{
$member = Profile::getKV('id', $this->profile_id);
if (empty($member)) {
// TRANS: Exception thrown providing an invalid profile ID.
// TRANS: %s is the invalid profile ID.
throw new Exception(sprintf(_('Profile ID %s is invalid.'),$this->profile_id));
throw new Exception(sprintf(_('Profile ID %s is invalid.'), $this->profile_id));
}
return $member;
}
function getGroup()
public function getGroup()
{
$group = User_group::getKV('id', $this->group_id);
if (empty($group)) {
// TRANS: Exception thrown providing an invalid group ID.
// TRANS: %s is the invalid group ID.
throw new Exception(sprintf(_('Group ID %s is invalid.'),$this->group_id));
throw new Exception(sprintf(_('Group ID %s is invalid.'), $this->group_id));
}
return $group;
@@ -77,7 +94,7 @@ class Group_join_queue extends Managed_DataObject
/**
* Abort the pending group join...
*/
function abort()
public function abort()
{
$profile = $this->getMember();
$group = $this->getGroup();
@@ -93,7 +110,7 @@ class Group_join_queue extends Managed_DataObject
*
* @return Group_member object on success
*/
function complete()
public function complete()
{
$join = null;
$profile = $this->getMember();
+46 -21
Ver Arquivo
@@ -1,4 +1,21 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
/**
* Table Definition for group_member
*/
@@ -11,7 +28,7 @@ class Group_member extends Managed_DataObject
public $__table = 'group_member'; // table name
public $group_id; // int(4) primary_key not_null
public $profile_id; // int(4) primary_key not_null
public $is_admin; // tinyint(1)
public $is_admin; // bool default_false
public $uri; // varchar(191) not 255 because utf8mb4 takes more space
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@@ -25,7 +42,7 @@ class Group_member extends Managed_DataObject
'fields' => array(
'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
'is_admin' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this user an admin?'),
'is_admin' => array('type' => 'bool', 'default' => false, 'description' => 'is this user an admin?'),
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universal identifier'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
@@ -54,20 +71,22 @@ class Group_member extends Managed_DataObject
*
* @param integer $group_id Group to add to
* @param integer $profile_id Profile being added
*
*
* @return Group_member new membership object
*/
static function join($group_id, $profile_id)
public static function join($group_id, $profile_id)
{
$member = new Group_member();
$member->group_id = $group_id;
$member->profile_id = $profile_id;
$member->created = common_sql_now();
$member->uri = self::newUri(Profile::getByID($profile_id),
User_group::getByID($group_id),
$member->created);
$member->uri = self::newUri(
Profile::getByID($profile_id),
User_group::getByID($group_id),
$member->created
);
$result = $member->insert();
@@ -80,7 +99,7 @@ class Group_member extends Managed_DataObject
return $member;
}
static function leave($group_id, $profile_id)
public static function leave($group_id, $profile_id)
{
$member = Group_member::pkeyGet(array('group_id' => $group_id,
'profile_id' => $profile_id));
@@ -101,27 +120,27 @@ class Group_member extends Managed_DataObject
return true;
}
function getMember()
public function getMember()
{
$member = Profile::getKV('id', $this->profile_id);
if (empty($member)) {
// TRANS: Exception thrown providing an invalid profile ID.
// TRANS: %s is the invalid profile ID.
throw new Exception(sprintf(_("Profile ID %s is invalid."),$this->profile_id));
throw new Exception(sprintf(_("Profile ID %s is invalid."), $this->profile_id));
}
return $member;
}
function getGroup()
public function getGroup()
{
$group = User_group::getKV('id', $this->group_id);
if (empty($group)) {
// TRANS: Exception thrown providing an invalid group ID.
// TRANS: %s is the invalid group ID.
throw new Exception(sprintf(_("Group ID %s is invalid."),$this->group_id));
throw new Exception(sprintf(_('Group ID %s is invalid.'), $this->group_id));
}
return $group;
@@ -137,7 +156,7 @@ class Group_member extends Managed_DataObject
* @return Group_member stream of memberships, use fetch() to iterate
*/
static function byMember($memberId, $offset=0, $limit=GROUPS_PER_PAGE)
public static function byMember($memberId, $offset = 0, $limit = GROUPS_PER_PAGE)
{
$membership = new Group_member();
@@ -152,7 +171,7 @@ class Group_member extends Managed_DataObject
return $membership;
}
function asActivity()
public function asActivity()
{
$member = $this->getMember();
@@ -180,13 +199,19 @@ class Group_member extends Managed_DataObject
// TRANS: Success message for subscribe to group attempt through OStatus.
// TRANS: %1$s is the member name, %2$s is the subscribed group's name.
$act->content = sprintf(_('%1$s has joined group %2$s.'),
$member->getBestName(),
$group->getBestName());
$act->content = sprintf(
_('%1$s has joined group %2$s.'),
$member->getBestName(),
$group->getBestName()
);
$url = common_local_url('AtomPubShowMembership',
array('profile' => $member->id,
'group' => $group->id));
$url = common_local_url(
'AtomPubShowMembership',
[
'profile' => $member->id,
'group' => $group->id,
]
);
$act->selfLink = $url;
$act->editLink = $url;
@@ -203,7 +228,7 @@ class Group_member extends Managed_DataObject
mail_notify_group_join($this->getGroup(), $this->getMember());
}
function getUri()
public function getUri()
{
return $this->uri ?: self::newUri($this->getMember(), $this->getGroup()->getProfile(), $this->created);
}
+102 -75
Ver Arquivo
@@ -1,28 +1,31 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Wrapper for Memcached_DataObject which knows its own schema definition.
* Builds its own damn settings from a schema definition.
*
* @author Brion Vibber <brion@status.net>
* @package GNUsocial
* @author Brion Vibber <brion@status.net>
* @copyright 2010 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
abstract class Managed_DataObject extends Memcached_DataObject
{
/**
@@ -42,7 +45,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return get_called_class() object if found, or null for no hits
*
*/
static function getKV($k,$v=NULL)
public static function getKV($k, $v = null)
{
return parent::getClassKV(get_called_class(), $k, $v);
}
@@ -59,12 +62,12 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return get_called_class() object if found, or null for no hits
*
*/
static function pkeyGet(array $kv)
public static function pkeyGet(array $kv)
{
return parent::pkeyGetClass(get_called_class(), $kv);
}
static function pkeyCols()
public static function pkeyCols()
{
return parent::pkeyColsClass(get_called_class());
}
@@ -78,10 +81,10 @@ abstract class Managed_DataObject extends Memcached_DataObject
*
* @return array Array of objects, in order
*/
static function multiGet($keyCol, array $keyVals, $skipNulls=true)
{
return parent::multiGetClass(get_called_class(), $keyCol, $keyVals, $skipNulls);
}
public static function multiGet($keyCol, array $keyVals, $skipNulls = true)
{
return parent::multiGetClass(get_called_class(), $keyCol, $keyVals, $skipNulls);
}
/**
* Get multiple items from the database by key
@@ -92,10 +95,10 @@ abstract class Managed_DataObject extends Memcached_DataObject
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
static function pivotGet($keyCol, array $keyVals, array $otherCols=array())
{
return parent::pivotGetClass(get_called_class(), $keyCol, $keyVals, $otherCols);
}
public static function pivotGet($keyCol, array $keyVals, array $otherCols = [])
{
return parent::pivotGetClass(get_called_class(), $keyCol, $keyVals, $otherCols);
}
/**
* Get a multi-instance object
@@ -110,7 +113,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* Exception is thrown when no entries are found.
*
*/
static function listFind($keyCol, array $keyVals)
public static function listFind($keyCol, array $keyVals)
{
return parent::listFindClass(get_called_class(), $keyCol, $keyVals);
}
@@ -128,7 +131,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return array with an get_called_class() object for each $keyVals entry
*
*/
static function listGet($keyCol, array $keyVals)
public static function listGet($keyCol, array $keyVals)
{
return parent::listGetClass(get_called_class(), $keyCol, $keyVals);
}
@@ -149,11 +152,11 @@ abstract class Managed_DataObject extends Memcached_DataObject
* get/set an array of table primary keys
*
* Key info is pulled from the table definition array.
*
*
* @access private
* @return array
*/
function keys()
public function keys()
{
return array_keys($this->keyTypes());
}
@@ -167,7 +170,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return array (column,use_native,sequence_name)
*/
function sequenceKey()
public function sequenceKey()
{
$table = static::schemaDef();
foreach ($table['fields'] as $name => $column) {
@@ -191,7 +194,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return array key definitions
*/
function keyTypes()
public function keyTypes()
{
$table = static::schemaDef();
$keys = array();
@@ -218,16 +221,17 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @param array $column
* @return int
*/
function columnBitmap($column)
public function columnBitmap($column)
{
$type = $column['type'];
// For quoting style...
$intTypes = array('int',
'integer',
'float',
'serial',
'numeric');
$intTypes = [
'int',
'float',
'serial',
'numeric'
];
if (in_array($type, $intTypes)) {
$style = DB_DATAOBJECT_INT;
} else {
@@ -235,12 +239,15 @@ abstract class Managed_DataObject extends Memcached_DataObject
}
// Data type formatting style...
$formatStyles = array('blob' => DB_DATAOBJECT_BLOB,
'text' => DB_DATAOBJECT_TXT,
'date' => DB_DATAOBJECT_DATE,
'time' => DB_DATAOBJECT_TIME,
'datetime' => DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME,
'timestamp' => DB_DATAOBJECT_MYSQLTIMESTAMP);
$formatStyles = [
'blob' => DB_DATAOBJECT_BLOB,
'text' => DB_DATAOBJECT_TXT,
'bool' => DB_DATAOBJECT_BOOL,
'date' => DB_DATAOBJECT_DATE,
'time' => DB_DATAOBJECT_TIME,
'datetime' => DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME,
'timestamp' => DB_DATAOBJECT_MYSQLTIMESTAMP,
];
if (isset($formatStyles[$type])) {
$style |= $formatStyles[$type];
@@ -254,7 +261,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
return $style;
}
function links()
public function links()
{
$links = array();
@@ -276,8 +283,10 @@ abstract class Managed_DataObject extends Memcached_DataObject
* Memcached_DataObject doesn't have enough info to handle properly.
*
* @return array of strings
* @throws MethodNotImplementedException
* @throws ServerException
*/
function _allCacheKeys()
public function _allCacheKeys()
{
$table = static::schemaDef();
$ckeys = array();
@@ -322,7 +331,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return Managed_DataObject of the get_called_class() type
* @throws NoResultException if no object with that primary key
*/
static function getByPK(array $vals)
public static function getByPK(array $vals)
{
$classname = get_called_class();
@@ -356,7 +365,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return Managed_DataObject of the get_called_class() type
* @throws NoResultException if no object with that primary key
*/
static function getByKeys(array $vals)
public static function getByKeys(array $vals)
{
$classname = get_called_class();
@@ -381,7 +390,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
return $object;
}
static function getByID($id)
public static function getByID($id)
{
if (!property_exists(get_called_class(), 'id')) {
throw new ServerException('Trying to get undefined property of dataobject class.');
@@ -394,7 +403,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
return static::getByPK(array('id' => $id));
}
static function getByUri($uri)
public static function getByUri($uri)
{
if (!property_exists(get_called_class(), 'uri')) {
throw new ServerException('Trying to get undefined property of dataobject class.');
@@ -487,14 +496,18 @@ abstract class Managed_DataObject extends Memcached_DataObject
return $aliases;
}
// 'update' won't write key columns, so we have to do it ourselves.
// This also automatically calls "update" _before_ it sets the keys.
// FIXME: This only works with single-column primary keys so far! Beware!
/**
* @param DB_DataObject &$orig Must be "instanceof" $this
* @param string $pid Primary ID column (no escaping is done on column name!)
* "update" won't write key columns, so we have to do it ourselves.
* This also automatically calls "update" _before_ it sets the keys.
* FIXME: This only works with single-column primary keys so far! Beware!
*
* @param Managed_DataObject $orig Must be "instanceof" $this
* @param string|null $pid (optional) Primary ID column (no escaping is done on column name!)
* @return bool|void|number of changed rows, no guarantees are made about the return really...
* @throws MethodNotImplementedException
* @throws ServerException
*/
public function updateWithKeys(Managed_DataObject $orig, $pid=null)
public function updateWithKeys(Managed_DataObject $orig, ?string $pid = null)
{
if (!$orig instanceof $this) {
throw new ServerException('Tried updating a DataObject with a different class than itself.');
@@ -509,10 +522,20 @@ abstract class Managed_DataObject extends Memcached_DataObject
// do it in a transaction
$this->query('BEGIN');
$parts = array();
$parts = [];
foreach ($this->keys() as $k) {
if (strcmp($this->$k, $orig->$k) != 0) {
$parts[] = $k . ' = ' . $this->_quote($this->$k);
$v = $this->table()[$k];
if ($this->$k !== $orig->$k) {
if (is_object($this->$k) && $this->$k instanceof DB_DataObject_Cast) {
$value = $this->$k->toString($v, $this->getDatabaseConnection());
} elseif (DB_DataObject::_is_null($this, $k)) {
$value = 'NULL';
} elseif ($v & DB_DATAOBJECT_STR) { // if a string
$value = $this->_quote((string) $this->$k);
} else {
$value = (int) $this->$k;
}
$parts[] = "{$k} = {$value}";
}
}
if (count($parts) == 0) {
@@ -537,18 +560,20 @@ abstract class Managed_DataObject extends Memcached_DataObject
$pid = $schema['primary key'];
unset($schema);
}
$pidWhere = array();
foreach((array)$pid as $pidCol) {
$pidWhere = [];
foreach ((array) $pid as $pidCol) {
$pidWhere[] = sprintf('%1$s = %2$s', $pidCol, $this->_quote($orig->$pidCol));
}
if (empty($pidWhere)) {
throw new ServerException('No primary ID column(s) set for updateWithKeys');
}
$qry = sprintf('UPDATE %1$s SET %2$s WHERE %3$s',
common_database_tablename($this->tableName()),
implode(', ', $parts),
implode(' AND ', $pidWhere));
$qry = sprintf(
'UPDATE %1$s SET %2$s WHERE %3$s',
$this->escapedTableName(),
implode(', ', $parts),
implode(' AND ', $pidWhere)
);
$result = $this->query($qry);
if ($result === false) {
@@ -576,21 +601,23 @@ abstract class Managed_DataObject extends Memcached_DataObject
return $result;
}
static public function beforeSchemaUpdate()
public static function beforeSchemaUpdate()
{
// NOOP
}
static function newUri(Profile $actor, Managed_DataObject $object, $created=null)
public static function newUri(Profile $actor, Managed_DataObject $object, $created = null)
{
if (is_null($created)) {
$created = common_sql_now();
}
return TagURI::mint(strtolower(get_called_class()).':%d:%s:%d:%s',
$actor->getID(),
ActivityUtils::resolveUri($object->getObjectType(), true),
$object->getID(),
common_date_iso8601($created));
return TagURI::mint(
strtolower(get_called_class()) . ':%d:%s:%d:%s',
$actor->getID(),
ActivityUtils::resolveUri($object->getObjectType(), true),
$object->getID(),
common_date_iso8601($created)
);
}
protected function onInsert()
+110 -83
Ver Arquivo
@@ -1,23 +1,25 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
class Memcached_DataObject extends Safe_DataObject
{
@@ -30,7 +32,7 @@ class Memcached_DataObject extends Safe_DataObject
* @param mixed $v key field value, or leave out for primary key lookup
* @return mixed Memcached_DataObject subtype or false
*/
static function getClassKV($cls, $k, $v=null)
public static function getClassKV($cls, $k, $v = null)
{
if (is_null($v)) {
$v = $k;
@@ -71,7 +73,7 @@ class Memcached_DataObject extends Safe_DataObject
*
* @return array Array of objects, in order
*/
static function multiGetClass($cls, $keyCol, array $keyVals, $skipNulls=true)
public static function multiGetClass($cls, $keyCol, array $keyVals, $skipNulls = true)
{
$obj = new $cls;
@@ -100,8 +102,27 @@ class Memcached_DataObject extends Safe_DataObject
$keyVals[$key] = $obj->escape($val);
}
// FIND_IN_SET will make sure we keep the desired order
$obj->orderBy(sprintf("FIND_IN_SET(%s, '%s')", $keyCol, implode(',', $keyVals)));
switch (common_config('db', 'type')) {
case 'pgsql':
// "position" will make sure we keep the desired order
$obj->orderBy(sprintf(
"position(',' || CAST(%s AS text) || ',' IN ',%s,')",
$keyCol,
implode(',', $keyVals)
));
break;
case 'mysql':
// "find_in_set" will make sure we keep the desired order
$obj->orderBy(sprintf(
"find_in_set(%s, '%s')",
$keyCol,
implode(',', $keyVals)
));
break;
default:
throw new ServerException('Unknown DB type selected.');
}
$obj->find();
return $obj;
@@ -117,7 +138,7 @@ class Memcached_DataObject extends Safe_DataObject
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
static function pivotGetClass($cls, $keyCol, array $keyVals, array $otherCols = array())
public static function pivotGetClass($cls, $keyCol, array $keyVals, array $otherCols = [])
{
if (is_array($keyCol)) {
foreach ($keyVals as $keyVal) {
@@ -130,7 +151,6 @@ class Memcached_DataObject extends Safe_DataObject
$toFetch = array();
foreach ($keyVals as $keyVal) {
if (is_array($keyCol)) {
$kv = array_combine($keyCol, $keyVal);
} else {
@@ -147,7 +167,7 @@ class Memcached_DataObject extends Safe_DataObject
} else {
$result[$keyVal] = $i;
}
} else if (!empty($keyVal)) {
} elseif (!empty($keyVal)) {
$toFetch[] = $keyVal;
}
}
@@ -207,7 +227,7 @@ class Memcached_DataObject extends Safe_DataObject
return $result;
}
static function _inMultiKey($i, $cols, $values)
public static function _inMultiKey($i, $cols, $values)
{
$types = array();
@@ -255,7 +275,7 @@ class Memcached_DataObject extends Safe_DataObject
return $query;
}
static function pkeyColsClass($cls)
public static function pkeyColsClass($cls)
{
$i = new $cls;
$types = $i->keyTypes();
@@ -272,7 +292,7 @@ class Memcached_DataObject extends Safe_DataObject
return $pkey;
}
static function listFindClass($cls, $keyCol, array $keyVals)
public static function listFindClass($cls, $keyCol, array $keyVals)
{
$i = new $cls;
$i->whereAddIn($keyCol, $keyVals, $i->columnType($keyCol));
@@ -283,7 +303,7 @@ class Memcached_DataObject extends Safe_DataObject
return $i;
}
static function listGetClass($cls, $keyCol, array $keyVals)
public static function listGetClass($cls, $keyCol, array $keyVals)
{
$pkeyMap = array_fill_keys($keyVals, array());
$result = array_fill_keys($keyVals, array());
@@ -296,7 +316,7 @@ class Memcached_DataObject extends Safe_DataObject
// We only cache keys -- not objects!
foreach ($keyVals as $keyVal) {
$l = self::cacheGet(sprintf("%s:list-ids:%s:%s", strtolower($cls), $keyCol, $keyVal));
$l = self::cacheGet(sprintf('%s:list-ids:%s:%s', strtolower($cls), $keyCol, $keyVal));
if ($l !== false) {
$pkeyMap[$keyVal] = $l;
foreach ($l as $pkey) {
@@ -312,7 +332,7 @@ class Memcached_DataObject extends Safe_DataObject
foreach ($pkeyMap as $keyVal => $pkeyList) {
foreach ($pkeyList as $pkeyVal) {
$i = $keyResults[implode(',',$pkeyVal)];
$i = $keyResults[implode(',', $pkeyVal)];
if (!empty($i)) {
$result[$keyVal][] = $i;
}
@@ -338,15 +358,17 @@ class Memcached_DataObject extends Safe_DataObject
// no results found for our keyVals, so we leave them as empty arrays
}
foreach ($toFetch as $keyVal) {
self::cacheSet(sprintf("%s:list-ids:%s:%s", strtolower($cls), $keyCol, $keyVal),
$pkeyMap[$keyVal]);
self::cacheSet(
sprintf("%s:list-ids:%s:%s", strtolower($cls), $keyCol, $keyVal),
$pkeyMap[$keyVal]
);
}
}
return $result;
}
function columnType($columnName)
public function columnType($columnName)
{
$keys = $this->table();
if (!array_key_exists($columnName, $keys)) {
@@ -365,7 +387,7 @@ class Memcached_DataObject extends Safe_DataObject
/**
* @todo FIXME: Should this return false on lookup fail to match getKV?
*/
static function pkeyGetClass($cls, array $kv)
public static function pkeyGetClass($cls, array $kv)
{
$i = self::multicache($cls, $kv);
if ($i !== false) { // false == cache miss
@@ -395,7 +417,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
function insert()
public function insert()
{
$result = parent::insert();
if ($result) {
@@ -405,7 +427,7 @@ class Memcached_DataObject extends Safe_DataObject
return $result;
}
function update($dataObject=false)
public function update($dataObject = false)
{
if (is_object($dataObject) && $dataObject instanceof Memcached_DataObject) {
$dataObject->decache(); # might be different keys
@@ -418,17 +440,19 @@ class Memcached_DataObject extends Safe_DataObject
return $result;
}
function delete($useWhere=false)
public function delete($useWhere = false)
{
$this->decache(); # while we still have the values!
return parent::delete($useWhere);
}
static function memcache() {
public static function memcache()
{
return Cache::instance();
}
static function cacheKey($cls, $k, $v) {
public static function cacheKey($cls, $k, $v)
{
if (is_object($cls) || is_object($k) || (is_object($v) && !($v instanceof DB_DataObject_Cast))) {
$e = new Exception();
common_log(LOG_ERR, __METHOD__ . ' object in param: ' .
@@ -438,7 +462,8 @@ class Memcached_DataObject extends Safe_DataObject
return Cache::key(strtolower($cls).':'.$k.':'.$vstr);
}
static function getcached($cls, $k, $v) {
public static function getcached($cls, $k, $v)
{
$c = self::memcache();
if (!$c) {
return false;
@@ -456,7 +481,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
function keyTypes()
public function keyTypes()
{
// ini-based classes return number-indexed arrays. handbuilt
// classes return column => keytype. Make this uniform.
@@ -472,18 +497,17 @@ class Memcached_DataObject extends Safe_DataObject
global $_DB_DATAOBJECT;
if (!isset($_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"])) {
$this->databaseStructure();
}
return $_DB_DATAOBJECT['INI'][$this->_database][$this->tableName()."__keys"];
}
function encache()
public function encache()
{
$c = self::memcache();
if (!$c) {
return false;
} else if ($this->tableName() == 'user' && is_object($this->id)) {
} elseif ($this->tableName() === 'user' && is_object($this->id)) {
// Special case for User bug
$e = new Exception();
common_log(LOG_ERR, __METHOD__ . ' caching user with User object as ID ' .
@@ -498,7 +522,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
function decache()
public function decache()
{
$c = self::memcache();
@@ -513,7 +537,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
function _allCacheKeys()
public function _allCacheKeys()
{
$ckeys = array();
@@ -524,7 +548,6 @@ class Memcached_DataObject extends Safe_DataObject
$pval = array();
foreach ($types as $key => $type) {
assert(!empty($key));
if ($type == 'U') {
@@ -532,7 +555,7 @@ class Memcached_DataObject extends Safe_DataObject
continue;
}
$ckeys[] = self::cacheKey($this->tableName(), $key, self::valueString($this->$key));
} else if ($type == 'K' || $type == 'N') {
} elseif (in_array($type, ['K', 'N'])) {
$pkey[] = $key;
$pval[] = self::valueString($this->$key);
} else {
@@ -552,7 +575,7 @@ class Memcached_DataObject extends Safe_DataObject
return $ckeys;
}
static function multicache($cls, $kv)
public static function multicache($cls, $kv)
{
ksort($kv);
$c = self::memcache();
@@ -563,7 +586,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
static function multicacheKey($cls, $kv)
public static function multicacheKey($cls, $kv)
{
ksort($kv);
$pkeys = implode(',', array_keys($kv));
@@ -571,30 +594,35 @@ class Memcached_DataObject extends Safe_DataObject
return self::cacheKey($cls, $pkeys, $pvals);
}
function getSearchEngine($table)
public function getSearchEngine($table)
{
require_once INSTALLDIR.'/lib/search_engines.php';
require_once INSTALLDIR . '/lib/search/search_engines.php';
if (Event::handle('GetSearchEngine', array($this, $table, &$search_engine))) {
if ('mysql' === common_config('db', 'type')) {
$type = common_config('search', 'type');
if ($type == 'like') {
$search_engine = new MySQLLikeSearch($this, $table);
} else if ($type == 'fulltext') {
$search_engine = new MySQLSearch($this, $table);
} else {
// Low level exception. No need for i18n as discussed with Brion.
throw new ServerException('Unknown search type: ' . $type);
if (Event::handle('GetSearchEngine', [$this, $table, &$search_engine])) {
$type = common_config('search', 'type');
if ($type === 'like') {
$search_engine = new SQLLikeSearch($this, $table);
} elseif ($type === 'fulltext') {
switch (common_config('db', 'type')) {
case 'pgsql':
$search_engine = new PostgreSQLSearch($this, $table);
break;
case 'mysql':
$search_engine = new MySQLSearch($this, $table);
break;
default:
throw new ServerException('Unknown DB type selected.');
}
} else {
$search_engine = new PGSearch($this, $table);
// Low level exception. No need for i18n as discussed with Brion.
throw new ServerException('Unknown search type: ' . $type);
}
}
return $search_engine;
}
static function cachedQuery($cls, $qry, $expiry=3600)
public static function cachedQuery($cls, $qry, $expiry = 3600)
{
$c = self::memcache();
if (!$c) {
@@ -631,7 +659,7 @@ class Memcached_DataObject extends Safe_DataObject
* @access private
* @return mixed none or PEAR_Error
*/
function _query($string)
public function _query($string)
{
if (common_config('db', 'annotate_queries')) {
$string = $this->annotateQuery($string);
@@ -680,7 +708,7 @@ class Memcached_DataObject extends Safe_DataObject
* @param string $string SQL query string
* @return string SQL query string, with a comment in it
*/
function annotateQuery($string)
public function annotateQuery($string)
{
$ignore = array('annotateQuery',
'_query',
@@ -707,7 +735,7 @@ class Memcached_DataObject extends Safe_DataObject
}
$here = $frame['class'] . '::' . $func;
break;
} else if (isset($frame['type']) && $frame['type'] == '->') {
} elseif (isset($frame['type']) && $frame['type'] === '->') {
if ($frame['object'] === $this && in_array($func, $ignore)) {
continue;
}
@@ -736,7 +764,7 @@ class Memcached_DataObject extends Safe_DataObject
// Sanitize a query for logging
// @fixme don't trim spaces in string literals
function sanitizeQuery($string)
public function sanitizeQuery($string)
{
$string = preg_replace('/\s+/', ' ', $string);
$string = trim($string);
@@ -746,7 +774,7 @@ class Memcached_DataObject extends Safe_DataObject
// We overload so that 'SET NAMES "utf8mb4"' is called for
// each connection
function _connect()
public function _connect()
{
global $_DB_DATAOBJECT, $_PEAR;
@@ -757,7 +785,7 @@ class Memcached_DataObject extends Safe_DataObject
$exists = true;
} else {
$exists = false;
}
}
// @fixme horrible evil hack!
//
@@ -794,7 +822,7 @@ class Memcached_DataObject extends Safe_DataObject
if (!empty($conn)) {
if ($DB instanceof DB_mysqli || $DB instanceof MDB2_Driver_mysqli) {
mysqli_set_charset($conn, 'utf8mb4');
} else if ($DB instanceof DB_mysql || $DB instanceof MDB2_Driver_mysql) {
} elseif ($DB instanceof DB_mysql || $DB instanceof MDB2_Driver_mysql) {
mysql_set_charset('utf8mb4', $conn);
}
}
@@ -810,7 +838,7 @@ class Memcached_DataObject extends Safe_DataObject
// XXX: largely cadged from DB_DataObject
function _getDbDsnMD5()
public function _getDbDsnMD5()
{
if ($this->_database_dsn_md5) {
return $this->_database_dsn_md5;
@@ -828,7 +856,7 @@ class Memcached_DataObject extends Safe_DataObject
return $sum;
}
function _getDbDsn()
public function _getDbDsn()
{
global $_DB_DATAOBJECT;
@@ -843,14 +871,13 @@ class Memcached_DataObject extends Safe_DataObject
$dsn = isset($this->_database_dsn) ? $this->_database_dsn : null;
if (!$dsn) {
if (!$this->_database) {
$this->_database = isset($options["table_{$this->tableName()}"]) ? $options["table_{$this->tableName()}"] : null;
}
if ($this->_database && !empty($options["database_{$this->_database}"])) {
if ($this->_database && !empty($options["database_{$this->_database}"])) {
$dsn = $options["database_{$this->_database}"];
} else if (!empty($options['database'])) {
} elseif (!empty($options['database'])) {
$dsn = $options['database'];
}
}
@@ -863,7 +890,7 @@ class Memcached_DataObject extends Safe_DataObject
return $dsn;
}
static function blow()
public static function blow()
{
$c = self::memcache();
@@ -882,7 +909,7 @@ class Memcached_DataObject extends Safe_DataObject
return $c->delete($cacheKey);
}
function fixupTimestamps()
public function fixupTimestamps()
{
// Fake up timestamp columns
$columns = $this->table();
@@ -893,12 +920,12 @@ class Memcached_DataObject extends Safe_DataObject
}
}
function debugDump()
public function debugDump()
{
common_debug("debugDump: " . common_log_objstring($this));
}
function raiseError($message, $type = null, $behaviour = null)
public function raiseError($message, $type = null, $behavior = null)
{
$id = get_class($this);
if (!empty($this->id)) {
@@ -911,7 +938,7 @@ class Memcached_DataObject extends Safe_DataObject
throw new ServerException("[$id] DB_DataObject error [$type]: $message");
}
static function cacheGet($keyPart)
public static function cacheGet($keyPart)
{
$c = self::memcache();
@@ -924,7 +951,7 @@ class Memcached_DataObject extends Safe_DataObject
return $c->get($cacheKey);
}
static function cacheSet($keyPart, $value, $flag=null, $expiry=null)
public static function cacheSet($keyPart, $value, $flag = null, $expiry = null)
{
$c = self::memcache();
@@ -937,7 +964,7 @@ class Memcached_DataObject extends Safe_DataObject
return $c->set($cacheKey, $value, $flag, $expiry);
}
static function valueString($v)
public static function valueString($v)
{
$vstr = null;
if (is_object($v) && $v instanceof DB_DataObject_Cast) {
+297 -284
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+38 -32
Ver Arquivo
@@ -1,32 +1,32 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* GNU social
*
* Data class for Notice preferences
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Data
* @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2013 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://www.gnu.org/software/social/
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @copyright 2013 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
class Notice_prefs extends Managed_DataObject
{
public $__table = 'notice_prefs'; // table name
@@ -58,7 +58,7 @@ class Notice_prefs extends Managed_DataObject
);
}
static function getNamespacePrefs(Notice $notice, $namespace, array $topic=array())
public static function getNamespacePrefs(Notice $notice, $namespace, array $topic = [])
{
if (empty($topic)) {
$prefs = new Notice_prefs();
@@ -76,13 +76,13 @@ class Notice_prefs extends Managed_DataObject
return $prefs;
}
static function getNamespace(Notice $notice, $namespace, array $topic=array())
public static function getNamespace(Notice $notice, $namespace, array $topic = [])
{
$prefs = self::getNamespacePrefs($notice, $namespace, $topic);
return $prefs->fetchAll();
}
static function getAll(Notice $notice)
public static function getAll(Notice $notice)
{
try {
$prefs = self::listFind('notice_id', array($notice->getID()));
@@ -100,13 +100,17 @@ class Notice_prefs extends Managed_DataObject
return $list;
}
static function getTopic(Notice $notice, $namespace, $topic) {
return self::getByPK(array('notice_id' => $notice->getID(),
'namespace' => $namespace,
'topic' => $topic));
public static function getTopic(Notice $notice, $namespace, $topic)
{
return self::getByPK([
'notice_id' => $notice->getID(),
'namespace' => $namespace,
'topic' => $topic,
]);
}
static function getData(Notice $notice, $namespace, $topic, $def=null) {
public static function getData(Notice $notice, $namespace, $topic, $def = null)
{
try {
$pref = self::getTopic($notice, $namespace, $topic);
} catch (NoResultException $e) {
@@ -120,7 +124,8 @@ class Notice_prefs extends Managed_DataObject
return $pref->data;
}
static function getConfigData(Notice $notice, $namespace, $topic) {
public static function getConfigData(Notice $notice, $namespace, $topic)
{
try {
$data = self::getData($notice, $namespace, $topic);
} catch (NoResultException $e) {
@@ -140,14 +145,15 @@ class Notice_prefs extends Managed_DataObject
* @return true if changes are made, false if no action taken
* @throws ServerException if preference could not be saved
*/
static function setData(Notice $notice, $namespace, $topic, $data=null) {
public static function setData(Notice $notice, $namespace, $topic, $data = null)
{
try {
$pref = self::getTopic($notice, $namespace, $topic);
if (is_null($data)) {
$pref->delete();
} else {
$orig = clone($pref);
$pref->data = $data;
$pref->data = DB_DataObject_Cast::blob($data);
$pref->update($orig);
}
return true;
@@ -161,7 +167,7 @@ class Notice_prefs extends Managed_DataObject
$pref->notice_id = $notice->getID();
$pref->namespace = $namespace;
$pref->topic = $topic;
$pref->data = $data;
$pref->data = DB_DataObject_Cast::blob($data);
$pref->created = common_sql_now();
if ($pref->insert() === false) {
+20 -3
Ver Arquivo
@@ -1,9 +1,26 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
/**
* Table Definition for notice_source
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Notice_source extends Managed_DataObject
{
###START_AUTOCODE
@@ -26,7 +43,7 @@ class Notice_source extends Managed_DataObject
'code' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'source code'),
'name' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'name of the source'),
'url' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'url to link to'),
'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'date this record was created'),
'notice_id' => array('type' => 'int', 'not null' => true, 'default' => 0, 'description' => 'date this record was created'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
+26 -11
Ver Arquivo
@@ -1,9 +1,26 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
/**
* Table Definition for oauth_application_user
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Oauth_application_user extends Managed_DataObject
{
###START_AUTOCODE
@@ -39,7 +56,7 @@ class Oauth_application_user extends Managed_DataObject
);
}
static function getByUserAndToken($user, $token)
public static function getByUserAndToken($user, $token)
{
if (empty($user) || empty($token)) {
return null;
@@ -56,7 +73,7 @@ class Oauth_application_user extends Managed_DataObject
return empty($result) ? null : $oau;
}
function updateKeys(&$orig)
public function updateKeys(&$orig)
{
$this->_connect();
$parts = array();
@@ -72,13 +89,11 @@ class Oauth_application_user extends Managed_DataObject
$toupdate = implode(', ', $parts);
$table = $this->tableName();
if(common_config('db','quote_identifiers')) {
$table = '"' . $table . '"';
}
$qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
' WHERE profile_id = ' . $orig->profile_id
. ' AND application_id = ' . $orig->application_id
. " AND token = '$orig->token'";
$tableName = $this->escapedTableName();
$qry = 'UPDATE ' . $tableName . ' SET ' . $toupdate .
' WHERE profile_id = ' . $orig->profile_id .
' AND application_id = ' . $orig->application_id .
" AND token = '" . $orig->token . "'";
$orig->decache();
$result = $this->query($qry);
if ($result) {
+22 -5
Ver Arquivo
@@ -1,9 +1,26 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
/**
* Table Definition for oauth_association
*/
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
class Oauth_token_association extends Managed_DataObject
{
###START_AUTOCODE
@@ -19,7 +36,7 @@ class Oauth_token_association extends Managed_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
static function getByUserAndToken($user, $token)
public static function getByUserAndToken($user, $token)
{
if (empty($user) || empty($token)) {
return null;
@@ -49,8 +66,8 @@ class Oauth_token_association extends Managed_DataObject
),
'primary key' => array('profile_id', 'application_id', 'token'),
'foreign keys' => array(
'oauth_token_association_profile_fkey' => array('profile_id', array('profile' => 'id')),
'oauth_token_association_application_fkey' => array('application_id', array('application' => 'id')),
'oauth_token_association_profile_fkey' => array('profile', array('profile_id' => 'id')),
'oauth_token_association_application_fkey' => array('oauth_application', array('application_id' => 'id')),
)
);
}
+25 -40
Ver Arquivo
@@ -1,48 +1,36 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Older-style UI preferences
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category UI
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Separate table for storing UI preferences
*
* @category UI
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Old_school_prefs extends Managed_DataObject
@@ -60,17 +48,14 @@ class Old_school_prefs extends Managed_DataObject
return array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
'stream_mode_only' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'stream_mode_only' => array('type' => 'bool',
'default' => true,
'description' => 'No conversation streams'),
'conversation_tree' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'conversation_tree' => array('type' => 'bool',
'default' => true,
'description' => 'Hierarchical tree view for conversations'),
'stream_nicknames' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'stream_nicknames' => array('type' => 'bool',
'default' => true,
'description' => 'Show nicknames for authors and addressees in streams'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
+187 -155
Ver Arquivo
@@ -1,23 +1,25 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008-2011, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* @copyright 2008-2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for profile
@@ -81,7 +83,7 @@ class Profile extends Managed_DataObject
throw new NoSuchUserException(array('email'=>$email));
}
return $user->getProfile();
}
}
protected $_user = array();
@@ -202,16 +204,16 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function getBestName()
public function getBestName()
{
return ($this->fullname) ? $this->fullname : $this->nickname;
}
/**
* Takes the currently scoped profile into account to give a name
* Takes the currently scoped profile into account to give a name
* to list in notice streams. Preferences may differ between profiles.
*/
function getStreamName()
public function getStreamName()
{
$user = common_current_user();
if ($user instanceof User && $user->streamNicknames()) {
@@ -228,7 +230,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function getFancyName()
public function getFancyName()
{
$uri = null;
try {
@@ -243,7 +245,7 @@ class Profile extends Managed_DataObject
if (mb_strlen($this->getFullname()) > 0) {
// TRANS: The "fancy name": Full name of a profile or group (%1$s) followed by some URI (%2$s) in parentheses.
return sprintf(_m('FANCYNAME','%1$s (%2$s)'), $this->getFullname(), $uri);
return sprintf(_m('FANCYNAME', '%1$s (%2$s)'), $this->getFullname(), $uri);
} else {
return $uri;
}
@@ -254,7 +256,7 @@ class Profile extends Managed_DataObject
*
* @return mixed Notice or null
*/
function getCurrentNotice(Profile $scoped=null)
public function getCurrentNotice(Profile $scoped = null)
{
try {
$notice = $this->getNotices(0, 1, 0, 0, $scoped);
@@ -271,16 +273,16 @@ class Profile extends Managed_DataObject
// Maybe we should let this through if it's handled well upstream
return null;
}
return null;
}
function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
public function getReplies($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
{
return Reply::stream($this->getID(), $offset, $limit, $since_id, $before_id);
}
function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
public function getTaggedNotices($tag, $offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $max_id = 0)
{
//FIXME: Get Profile::current() some other way to avoid possible
// confusion between current session profile and background processing.
@@ -289,39 +291,39 @@ class Profile extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0, Profile $scoped=null)
public function getNotices($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $max_id = 0, Profile $scoped = null)
{
$stream = new ProfileNoticeStream($this, $scoped);
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
function isMember(User_group $group)
public function isMember(User_group $group)
{
$groups = $this->getGroups(0, null);
$groups = $this->getGroups(0, null);
while ($groups instanceof User_group && $groups->fetch()) {
if ($groups->id == $group->id) {
return true;
}
}
return false;
if ($groups->id == $group->id) {
return true;
}
}
return false;
}
function isAdmin(User_group $group)
public function isAdmin(User_group $group)
{
$gm = Group_member::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id));
return (!empty($gm) && $gm->is_admin);
}
function isPendingMember($group)
public function isPendingMember($group)
{
$request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id));
return !empty($request);
}
function getGroups($offset=0, $limit=PROFILES_PER_PAGE)
public function getGroups($offset = 0, $limit = PROFILES_PER_PAGE)
{
$ids = array();
@@ -356,14 +358,15 @@ class Profile extends Managed_DataObject
}
}
function getGroupCount() {
public function getGroupCount()
{
$groups = $this->getGroups(0, null);
return $groups instanceof User_group
? $groups->N
: 0;
}
function isTagged($peopletag)
public function isTagged($peopletag)
{
$tag = Profile_tag::pkeyGet(array('tagger' => $peopletag->tagger,
'tagged' => $this->id,
@@ -371,7 +374,7 @@ class Profile extends Managed_DataObject
return !empty($tag);
}
function canTag($tagged)
public function canTag($tagged)
{
if (empty($tagged)) {
return false;
@@ -395,16 +398,16 @@ class Profile extends Managed_DataObject
if ($local) {
return true;
}
} else if ($subs) {
} elseif ($subs) {
return (Subscription::exists($this, $tagged) ||
Subscription::exists($tagged, $this));
} else if ($remote) {
} elseif ($remote) {
return true;
}
return false;
}
function getLists(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
public function getLists(Profile $scoped = null, $offset = 0, $limit = null, $since_id = 0, $max_id = 0)
{
$ids = array();
@@ -421,15 +424,15 @@ class Profile extends Managed_DataObject
$list->tagger = $this->id;
$list->selectAdd('id as "cursor"');
if ($since_id>0) {
$list->whereAdd('id > '.$since_id);
if ($since_id > 0) {
$list->whereAdd('id > ' . $since_id);
}
if ($max_id>0) {
$list->whereAdd('id <= '.$max_id);
if ($max_id > 0) {
$list->whereAdd('id <= ' . $max_id);
}
if($offset>=0 && !is_null($limit)) {
if ($offset >= 0 && !is_null($limit)) {
$list->limit($offset, $limit);
}
@@ -452,7 +455,6 @@ class Profile extends Managed_DataObject
$list = Profile_list::getKV('id', $id);
if (!empty($list) &&
($showPrivate || !$list->private)) {
if (!isset($list->cursor)) {
$list->cursor = $list->id;
}
@@ -476,33 +478,47 @@ class Profile extends Managed_DataObject
* @return Profile_list resulting lists
*/
function getOtherTags(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
public function getOtherTags(Profile $scoped = null, int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
{
$list = new Profile_list();
$qry = sprintf('select profile_list.*, unix_timestamp(profile_tag.modified) as "cursor" ' .
'from profile_tag join profile_list '.
'on (profile_tag.tagger = profile_list.tagger ' .
' and profile_tag.tag = profile_list.tag) ' .
'where profile_tag.tagged = %d ',
$this->id);
if (common_config('db', 'type') !== 'mysql') {
$cursor = sprintf(
'((EXTRACT(DAY %1$s) * 24 + EXTRACT(HOUR %1$s)) * 60 + ' .
'EXTRACT(MINUTE %1$s)) * 60 + FLOOR(EXTRACT(SECOND %1$s)) AS "cursor"',
"FROM (profile_tag.modified - TIMESTAMP '1970-01-01 00:00:00')"
);
} else {
// The SQL/Foundation conforming implementation above doesn't work on MariaDB/MySQL
$cursor = "timestampdiff(SECOND, '1970-01-01', profile_tag.modified) AS `cursor`";
}
$qry = sprintf(
'SELECT profile_list.*, ' . $cursor . ' ' .
'FROM profile_tag INNER JOIN profile_list ' .
'ON (profile_tag.tagger = profile_list.tagger ' .
' AND profile_tag.tag = profile_list.tag) ' .
'WHERE profile_tag.tagged = %d ',
$this->id
);
if (!is_null($scoped)) {
$qry .= sprintf('AND ( ( profile_list.private = false ) ' .
'OR ( profile_list.tagger = %d AND ' .
'profile_list.private = true ) )',
$scoped->getID());
$qry .= sprintf(
'AND ( profile_list.private = false ' .
'OR ( profile_list.tagger = %d AND ' .
'profile_list.private = TRUE ) )',
$scoped->getID()
);
} else {
$qry .= 'AND profile_list.private = 0 ';
$qry .= 'AND profile_list.private = FALSE ';
}
if ($since_id > 0) {
$qry .= sprintf('AND (cursor > %d) ', $since_id);
if ($since > 0) {
$qry .= 'AND cursor > ' . $since . ' ';
}
if ($max_id > 0) {
$qry .= sprintf('AND (cursor < %d) ', $max_id);
if ($upto > 0) {
$qry .= 'AND cursor < ' . $upto . ' ';
}
$qry .= 'ORDER BY profile_tag.modified DESC ';
@@ -515,21 +531,21 @@ class Profile extends Managed_DataObject
return $list;
}
function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0)
public function getPrivateTags($offset = 0, $limit = null, $since_id = 0, $max_id = 0)
{
$tags = new Profile_list();
$tags->private = true;
$tags->tagger = $this->id;
if ($since_id>0) {
$tags->whereAdd('id > '.$since_id);
if ($since_id > 0) {
$tags->whereAdd('id > ' . $since_id);
}
if ($max_id>0) {
$tags->whereAdd('id <= '.$max_id);
if ($max_id > 0) {
$tags->whereAdd('id <= ' . $max_id);
}
if($offset>=0 && !is_null($limit)) {
if ($offset >= 0 && !is_null($limit)) {
$tags->limit($offset, $limit);
}
@@ -539,13 +555,13 @@ class Profile extends Managed_DataObject
return $tags;
}
function hasLocalTags()
public function hasLocalTags()
{
$tags = new Profile_tag();
$tags->joinAdd(array('tagger', 'user:id'));
$tags->whereAdd('tagged = '.$this->id);
$tags->whereAdd('tagger != '.$this->id);
$tags->whereAdd('tagged = ' . $this->id);
$tags->whereAdd('tagger <> ' . $this->id);
$tags->limit(0, 1);
$tags->fetch();
@@ -553,31 +569,38 @@ class Profile extends Managed_DataObject
return ($tags->N == 0) ? false : true;
}
function getTagSubscriptions($offset=0, $limit=null, $since_id=0, $max_id=0)
public function getTagSubscriptions(int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
{
$lists = new Profile_list();
$subs = new Profile_tag_subscription();
$lists->joinAdd(array('id', 'profile_tag_subscription:profile_tag_id'));
$lists->joinAdd(['id', 'profile_tag_subscription:profile_tag_id']);
#@fixme: postgres (round(date_part('epoch', my_date)))
$lists->selectAdd('unix_timestamp(profile_tag_subscription.created) as "cursor"');
if (common_config('db', 'type') !== 'mysql') {
$lists->selectAdd(sprintf(
'((EXTRACT(DAY %1$s) * 24 + EXTRACT(HOUR %1$s)) * 60 + ' .
'EXTRACT(MINUTE %1$s)) * 60 + FLOOR(EXTRACT(SECOND %1$s)) AS "cursor"',
"FROM (profile_tag_subscription.created - TIMESTAMP '1970-01-01 00:00:00')"
));
} else {
$lists->selectAdd("timestampdiff(SECOND, '1970-01-01', profile_tag_subscription.created) AS `cursor`");
}
$lists->whereAdd('profile_tag_subscription.profile_id = '.$this->id);
if ($since_id>0) {
$lists->whereAdd('cursor > '.$since_id);
if ($since > 0) {
$lists->whereAdd('cursor > ' . $since);
}
if ($max_id>0) {
$lists->whereAdd('cursor <= '.$max_id);
if ($upto > 0) {
$lists->whereAdd('cursor <= ' . $upto);
}
if($offset>=0 && !is_null($limit)) {
if ($offset >= 0 && !is_null($limit)) {
$lists->limit($offset, $limit);
}
$lists->orderBy('"cursor" DESC');
$lists->orderBy('profile_tag_subscription.created DESC');
$lists->find();
return $lists;
@@ -590,7 +613,7 @@ class Profile extends Managed_DataObject
* @param User_group $group
* @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
*/
function joinGroup(User_group $group)
public function joinGroup(User_group $group)
{
$join = null;
if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
@@ -616,7 +639,7 @@ class Profile extends Managed_DataObject
*
* @param User_group $group
*/
function leaveGroup(User_group $group)
public function leaveGroup(User_group $group)
{
if (Event::handle('StartLeaveGroup', array($group, $this))) {
Group_member::leave($group->id, $this->id);
@@ -627,12 +650,12 @@ class Profile extends Managed_DataObject
}
}
function avatarUrl($size=AVATAR_PROFILE_SIZE)
public function avatarUrl($size = AVATAR_PROFILE_SIZE)
{
return Avatar::urlByProfile($this, $size);
}
function getSubscribed($offset=0, $limit=null)
public function getSubscribed($offset = 0, $limit = null)
{
$subs = Subscription::getSubscribedIDs($this->id, $offset, $limit);
try {
@@ -643,7 +666,7 @@ class Profile extends Managed_DataObject
return $profiles;
}
function getSubscribers($offset=0, $limit=null)
public function getSubscribers($offset = 0, $limit = null)
{
$subs = Subscription::getSubscriberIDs($this->id, $offset, $limit);
try {
@@ -654,7 +677,7 @@ class Profile extends Managed_DataObject
return $profiles;
}
function getTaggedSubscribers($tag, $offset=0, $limit=null)
public function getTaggedSubscribers($tag, $offset = 0, $limit = null)
{
$qry =
'SELECT profile.* ' .
@@ -664,7 +687,7 @@ class Profile extends Managed_DataObject
'AND profile_tag.tagger = subscription.subscribed) ' .
'WHERE subscription.subscribed = %d ' .
"AND profile_tag.tag = '%s' " .
'AND subscription.subscribed != subscription.subscriber ' .
'AND subscription.subscribed <> subscription.subscriber ' .
'ORDER BY subscription.created DESC ';
if ($offset) {
@@ -678,7 +701,7 @@ class Profile extends Managed_DataObject
return $profile;
}
function getTaggedSubscriptions($tag, $offset=0, $limit=null)
public function getTaggedSubscriptions($tag, $offset = 0, $limit = null)
{
$qry =
'SELECT profile.* ' .
@@ -688,7 +711,7 @@ class Profile extends Managed_DataObject
'AND profile_tag.tagger = subscription.subscriber) ' .
'WHERE subscription.subscriber = %d ' .
"AND profile_tag.tag = '%s' " .
'AND subscription.subscribed != subscription.subscriber ' .
'AND subscription.subscribed <> subscription.subscriber ' .
'ORDER BY subscription.created DESC ';
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
@@ -707,7 +730,7 @@ class Profile extends Managed_DataObject
* @param int $limit
* @return Profile
*/
function getRequests($offset=0, $limit=null)
public function getRequests($offset = 0, $limit = null)
{
// FIXME: mysql only
$subqueue = new Profile();
@@ -721,7 +744,7 @@ class Profile extends Managed_DataObject
return $subqueue;
}
function subscriptionCount()
public function subscriptionCount()
{
$c = Cache::instance();
@@ -749,7 +772,7 @@ class Profile extends Managed_DataObject
return $cnt;
}
function subscriberCount()
public function subscriberCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -761,8 +784,8 @@ class Profile extends Managed_DataObject
$sub = new Subscription();
$sub->subscribed = $this->id;
$sub->whereAdd('subscriber != subscribed');
$cnt = (int) $sub->count('distinct subscriber');
$sub->whereAdd('subscriber <> subscribed');
$cnt = (int) $sub->count('DISTINCT subscriber');
if (!empty($c)) {
$c->set(Cache::key('profile:subscriber_count:'.$this->id), $cnt);
@@ -777,12 +800,12 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
function isSubscribed(Profile $other)
public function isSubscribed(Profile $other)
{
return Subscription::exists($this, $other);
}
function readableBy(Profile $other=null)
public function readableBy(Profile $other = null)
{
// If it's not a private stream, it's readable by anyone
if (!$this->isPrivateStream()) {
@@ -793,7 +816,7 @@ class Profile extends Managed_DataObject
return is_null($other) ? false : $other->isSubscribed($this);
}
function requiresSubscriptionApproval(Profile $other=null): bool
public function requiresSubscriptionApproval(Profile $other = null): bool
{
if (!$this->isLocal()) {
// We don't know for remote users, and we'll always be able to send
@@ -818,7 +841,7 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
function hasPendingSubscription(Profile $other)
public function hasPendingSubscription(Profile $other)
{
return Subscription_queue::exists($this, $other);
}
@@ -829,13 +852,13 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
function mutuallySubscribed(Profile $other)
public function mutuallySubscribed(Profile $other)
{
return $this->isSubscribed($other) &&
$other->isSubscribed($this);
}
function noticeCount()
public function noticeCount()
{
$c = Cache::instance();
@@ -858,7 +881,7 @@ class Profile extends Managed_DataObject
return $cnt;
}
function blowSubscriberCount()
public function blowSubscriberCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -866,7 +889,7 @@ class Profile extends Managed_DataObject
}
}
function blowSubscriptionCount()
public function blowSubscriptionCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -874,7 +897,7 @@ class Profile extends Managed_DataObject
}
}
function blowNoticeCount()
public function blowNoticeCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -882,7 +905,7 @@ class Profile extends Managed_DataObject
}
}
static function maxBio()
public static function maxBio()
{
$biolimit = common_config('profile', 'biolimit');
// null => use global limit (distinct from 0!)
@@ -892,13 +915,13 @@ class Profile extends Managed_DataObject
return $biolimit;
}
static function bioTooLong($bio)
public static function bioTooLong($bio)
{
$biolimit = self::maxBio();
return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
}
function update($dataObject=false)
public function update($dataObject = false)
{
if (is_object($dataObject) && $this->nickname != $dataObject->nickname) {
try {
@@ -946,7 +969,7 @@ class Profile extends Managed_DataObject
return $relMes;
}
function delete($useWhere=false)
public function delete($useWhere = false)
{
$this->_deleteNotices();
$this->_deleteSubscriptions();
@@ -957,10 +980,11 @@ class Profile extends Managed_DataObject
// Warning: delete() will run on the batch objects,
// not on individual objects.
$related = array('Reply',
'Group_member',
'Profile_role'
);
$related = [
'Reply',
'Group_member',
'Profile_role',
];
Event::handle('ProfileDeleteRelated', array($this, &$related));
foreach ($related as $cls) {
@@ -968,7 +992,7 @@ class Profile extends Managed_DataObject
$inst->profile_id = $this->id;
$inst->delete();
}
$this->grantRole(Profile_role::DELETED);
$localuser = User::getKV('id', $this->id);
@@ -979,7 +1003,7 @@ class Profile extends Managed_DataObject
return parent::delete($useWhere);
}
function _deleteNotices()
public function _deleteNotices()
{
$notice = new Notice();
$notice->profile_id = $this->id;
@@ -992,7 +1016,7 @@ class Profile extends Managed_DataObject
}
}
function _deleteSubscriptions()
public function _deleteSubscriptions()
{
$sub = new Subscription();
$sub->subscriber = $this->getID();
@@ -1040,14 +1064,14 @@ class Profile extends Managed_DataObject
$self->delete();
}
function _deleteTags()
public function _deleteTags()
{
$tag = new Profile_tag();
$tag->tagged = $this->id;
$tag->delete();
}
function _deleteBlocks()
public function _deleteBlocks()
{
$block = new Profile_block();
$block->blocked = $this->id;
@@ -1058,7 +1082,7 @@ class Profile extends Managed_DataObject
$block->delete();
}
function _deleteAttentions()
public function _deleteAttentions()
{
$att = new Attention();
$att->profile_id = $this->getID();
@@ -1103,7 +1127,7 @@ class Profile extends Managed_DataObject
if ($cfg == 'always') {
return true;
} else if ($cfg == 'never') {
} elseif ($cfg == 'never') {
return false;
} else { // user
$share = common_config('location', 'sharedefault');
@@ -1120,7 +1144,7 @@ class Profile extends Managed_DataObject
}
}
function hasRole($name)
public function hasRole($name)
{
$has_role = false;
if (Event::handle('StartHasRole', array($this, $name, &$has_role))) {
@@ -1132,10 +1156,9 @@ class Profile extends Managed_DataObject
return $has_role;
}
function grantRole($name)
public function grantRole($name)
{
if (Event::handle('StartGrantRole', array($this, $name))) {
$role = new Profile_role();
$role->profile_id = $this->id;
@@ -1158,17 +1181,20 @@ class Profile extends Managed_DataObject
return $result;
}
function revokeRole($name)
public function revokeRole($name)
{
if (Event::handle('StartRevokeRole', array($this, $name))) {
$role = Profile_role::pkeyGet(array('profile_id' => $this->id,
'role' => $name));
if (empty($role)) {
// TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist.
// TRANS: %1$s is the role name, %2$s is the user ID (number).
throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id));
throw new Exception(sprintf(
_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),
$name,
$this->id
));
}
$result = $role->delete();
@@ -1177,7 +1203,11 @@ class Profile extends Managed_DataObject
common_log_db_error($role, 'DELETE', __FILE__);
// TRANS: Exception thrown when trying to revoke a role for a user with a failing database query.
// TRANS: %1$s is the role name, %2$s is the user ID (number).
throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id));
throw new Exception(sprintf(
_('Cannot revoke role "%1$s" for user #%2$d; database error.'),
$name,
$this->id
));
}
if ($name == 'owner') {
@@ -1190,27 +1220,27 @@ class Profile extends Managed_DataObject
}
}
function isSandboxed()
public function isSandboxed()
{
return $this->hasRole(Profile_role::SANDBOXED);
}
function isSilenced()
public function isSilenced()
{
return $this->hasRole(Profile_role::SILENCED);
}
function sandbox()
public function sandbox()
{
$this->grantRole(Profile_role::SANDBOXED);
}
function unsandbox()
public function unsandbox()
{
$this->revokeRole(Profile_role::SANDBOXED);
}
function silence()
public function silence()
{
$this->grantRole(Profile_role::SILENCED);
if (common_config('notice', 'hidespam')) {
@@ -1218,7 +1248,7 @@ class Profile extends Managed_DataObject
}
}
function silenceAs(Profile $actor)
public function silenceAs(Profile $actor)
{
if (!$actor->hasRight(Right::SILENCEUSER)) {
throw new AuthorizationException(_('You cannot silence users on this site.'));
@@ -1234,7 +1264,7 @@ class Profile extends Managed_DataObject
return $this->silence();
}
function unsilence()
public function unsilence()
{
$this->revokeRole(Profile_role::SILENCED);
if (common_config('notice', 'hidespam')) {
@@ -1242,7 +1272,7 @@ class Profile extends Managed_DataObject
}
}
function unsilenceAs(Profile $actor)
public function unsilenceAs(Profile $actor)
{
if (!$actor->hasRight(Right::SILENCEUSER)) {
// TRANS: Client error displayed trying to unsilence a user when the user does not have the right.
@@ -1255,7 +1285,7 @@ class Profile extends Managed_DataObject
return $this->unsilence();
}
function flushVisibility()
public function flushVisibility()
{
// Get all notices
$stream = new ProfileNoticeStream($this, $this);
@@ -1301,8 +1331,7 @@ class Profile extends Managed_DataObject
}
if (Event::handle('UserRightsCheck', array($this, $right, &$result))) {
switch ($right)
{
switch ($right) {
case Right::DELETEOTHERSNOTICE:
case Right::MAKEGROUPADMIN:
case Right::SANDBOXUSER:
@@ -1380,7 +1409,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function asAtomAuthor($cur = null)
public function asAtomAuthor($cur = null)
{
$xs = new XMLStringer(true);
@@ -1388,7 +1417,7 @@ class Profile extends Managed_DataObject
$xs->element('name', null, $this->nickname);
$xs->element('uri', null, $this->getUri());
if ($cur != null) {
$attrs = Array();
$attrs = [];
$attrs['following'] = $cur->isSubscribed($this) ? 'true' : 'false';
$attrs['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false';
$xs->element('statusnet:profile_info', $attrs, null);
@@ -1409,7 +1438,7 @@ class Profile extends Managed_DataObject
* @return array representation of <statusnet:profile_info> element or null
*/
function profileInfo(Profile $scoped=null)
public function profileInfo(Profile $scoped = null)
{
$profileInfoAttr = array('local_id' => $this->id);
@@ -1431,7 +1460,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function asActivityActor()
public function asActivityActor()
{
return $this->asActivityNoun('actor');
}
@@ -1447,7 +1476,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function asActivityNoun($element)
public function asActivityNoun($element)
{
$noun = $this->asActivityObject();
return $noun->asString('activity:' . $element);
@@ -1619,7 +1648,7 @@ class Profile extends Managed_DataObject
return $scheme ? $acct : mb_substr($acct, 5);
}
function hasBlocked(Profile $other)
public function hasBlocked(Profile $other)
{
$block = Profile_block::exists($this, $other);
return !empty($block);
@@ -1652,7 +1681,7 @@ class Profile extends Managed_DataObject
*
* @param string $uri A unique identifier for a resource (profile/group/whatever)
*/
static function fromUri($uri)
public static function fromUri($uri)
{
$profile = null;
@@ -1677,7 +1706,7 @@ class Profile extends Managed_DataObject
return $profile;
}
function canRead(Notice $notice)
public function canRead(Notice $notice)
{
if ($notice->scope & Notice::SITE_SCOPE) {
$user = $this->getUser();
@@ -1717,7 +1746,7 @@ class Profile extends Managed_DataObject
return true;
}
static function current()
public static function current()
{
$user = common_current_user();
if (empty($user)) {
@@ -1728,7 +1757,7 @@ class Profile extends Managed_DataObject
return $profile;
}
static function ensureCurrent()
public static function ensureCurrent()
{
$profile = self::current();
if (!$profile instanceof Profile) {
@@ -1747,7 +1776,7 @@ class Profile extends Managed_DataObject
* @return array of variable names to include in serialization.
*/
function __sleep()
public function __sleep()
{
$vars = parent::__sleep();
$skip = array('_user', '_group');
@@ -1802,11 +1831,13 @@ class Profile extends Managed_DataObject
return !is_null($private_stream) && $private_stream;
}
public function delPref($namespace, $topic) {
public function delPref($namespace, $topic)
{
return Profile_prefs::setData($this, $namespace, $topic, null);
}
public function getPref($namespace, $topic, $default=null) {
public function getPref($namespace, $topic, $default = null)
{
// If you want an exception to be thrown, call Profile_prefs::getData directly
try {
return Profile_prefs::getData($this, $namespace, $topic, $default);
@@ -1821,7 +1852,8 @@ class Profile extends Managed_DataObject
return Profile_prefs::getConfigData($this, $namespace, $topic);
}
public function setPref($namespace, $topic, $data) {
public function setPref($namespace, $topic, $data)
{
return Profile_prefs::setData($this, $namespace, $topic, $data);
}
+126 -96
Ver Arquivo
@@ -1,27 +1,28 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet - the distributed open-source microblogging tool
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Notices
* @package StatusNet
* @author Shashi Gowda <connect2shashi@gmail.com>
* @license GNU Affero General Public License http://www.gnu.org/licenses/
* @category Notices
* @package GNUsocial
* @author Shashi Gowda <connect2shashi@gmail.com>
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
class Profile_list extends Managed_DataObject
{
@@ -30,7 +31,7 @@ class Profile_list extends Managed_DataObject
public $tagger; // int(4)
public $tag; // varchar(64)
public $description; // text
public $private; // tinyint(1)
public $private; // bool default_false
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
public $uri; // varchar(191) unique_key not 255 because utf8mb4 takes more space
@@ -46,7 +47,7 @@ class Profile_list extends Managed_DataObject
'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'people tag'),
'description' => array('type' => 'text', 'description' => 'description of the people tag'),
'private' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this tag private'),
'private' => array('type' => 'bool', 'default' => false, 'description' => 'is this tag private'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date the tag was added'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date the tag was modified'),
@@ -58,7 +59,8 @@ class Profile_list extends Managed_DataObject
),
'primary key' => array('tagger', 'tag'),
'unique keys' => array(
'profile_list_id_key' => array('id')
'profile_list_id_key' => array('id'),
'profile_list_tag_key' => array('tag'),
),
'foreign keys' => array(
'profile_list_tagger_fkey' => array('profile', array('tagger' => 'id')),
@@ -79,7 +81,7 @@ class Profile_list extends Managed_DataObject
* @return Profile the tagger
*/
function getTagger()
public function getTagger()
{
return Profile::getByID($this->tagger);
}
@@ -91,7 +93,7 @@ class Profile_list extends Managed_DataObject
* @return String
*/
function getBestName()
public function getBestName()
{
return $this->tag;
}
@@ -102,15 +104,17 @@ class Profile_list extends Managed_DataObject
* @return String uri
*/
function getUri()
public function getUri()
{
$uri = null;
if (Event::handle('StartProfiletagGetUri', array($this, &$uri))) {
if (!empty($this->uri)) {
$uri = $this->uri;
} else {
$uri = common_local_url('profiletagbyid',
array('id' => $this->id, 'tagger_id' => $this->tagger));
$uri = common_local_url(
'profiletagbyid',
['id' => $this->id, 'tagger_id' => $this->tagger]
);
}
}
Event::handle('EndProfiletagGetUri', array($this, &$uri));
@@ -123,7 +127,7 @@ class Profile_list extends Managed_DataObject
* @return String home url
*/
function homeUrl()
public function homeUrl()
{
$url = null;
if (Event::handle('StartUserPeopletagHomeUrl', array($this, &$url))) {
@@ -131,9 +135,13 @@ class Profile_list extends Managed_DataObject
if (!empty($this->mainpage)) {
$url = $this->mainpage;
} else {
$url = common_local_url('showprofiletag',
array('nickname' => $this->getTagger()->nickname,
'tag' => $this->tag));
$url = common_local_url(
'showprofiletag',
[
'nickname' => $this->getTagger()->nickname,
'tag' => $this->tag,
]
);
}
}
Event::handle('EndUserPeopletagHomeUrl', array($this, &$url));
@@ -146,12 +154,14 @@ class Profile_list extends Managed_DataObject
* @return String permalink
*/
function permalink()
public function permalink()
{
$url = null;
if (Event::handle('StartProfiletagPermalink', array($this, &$url))) {
$url = common_local_url('profiletagbyid',
array('id' => $this->id));
$url = common_local_url(
'profiletagbyid',
['id' => $this->id]
);
}
Event::handle('EndProfiletagPermalink', array($this, &$url));
return $url;
@@ -169,7 +179,7 @@ class Profile_list extends Managed_DataObject
* @return Notice the query
*/
function getNotices($offset, $limit, $since_id=null, $max_id=null)
public function getNotices($offset, $limit, $since_id = null, $max_id = null)
{
// FIXME: Use something else than Profile::current() to avoid
// possible confusion between session user and queue processing.
@@ -190,7 +200,7 @@ class Profile_list extends Managed_DataObject
* @return Profile results
*/
function getSubscribers($offset=0, $limit=null, $since=0, $upto=0)
public function getSubscribers(int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
{
$subs = new Profile();
@@ -199,8 +209,15 @@ class Profile_list extends Managed_DataObject
);
$subs->whereAdd('profile_tag_subscription.profile_tag_id = ' . $this->id);
$subs->selectAdd('unix_timestamp(profile_tag_subscription.' .
'created) as "cursor"');
if (common_config('db', 'type') !== 'mysql') {
$subs->selectAdd(sprintf(
'((EXTRACT(DAY %1$s) * 24 + EXTRACT(HOUR %1$s)) * 60 + ' .
'EXTRACT(MINUTE %1$s)) * 60 + FLOOR(EXTRACT(SECOND %1$s)) AS "cursor"',
"FROM (profile_tag_subscription.created - TIMESTAMP '1970-01-01 00:00:00')"
));
} else {
$subs->selectAdd("timestampdiff(SECOND, '1970-01-01', profile_tag_subscription.created) AS `cursor`");
}
if ($since != 0) {
$subs->whereAdd('cursor > ' . $since);
@@ -227,24 +244,22 @@ class Profile_list extends Managed_DataObject
* @return array ids of users
*/
function getUserSubscribers()
public function getUserSubscribers()
{
// XXX: cache this
$user = new User();
if(common_config('db','quote_identifiers'))
$user_table = '"user"';
else $user_table = 'user';
$qry =
'SELECT id ' .
'FROM '. $user_table .' JOIN profile_tag_subscription '.
'ON '. $user_table .'.id = profile_tag_subscription.profile_id ' .
'WHERE profile_tag_subscription.profile_tag_id = %d ';
$user->query(sprintf(
'SELECT id ' .
'FROM %1$s INNER JOIN profile_tag_subscription ' .
'ON %1$s.id = profile_tag_subscription.profile_id ' .
'WHERE profile_tag_subscription.profile_tag_id = %2$d ',
$user->escapedTableName(),
$this->id
));
$user->query(sprintf($qry, $this->id));
$ids = array();
$ids = [];
while ($user->fetch()) {
$ids[] = $user->id;
@@ -264,7 +279,7 @@ class Profile_list extends Managed_DataObject
* @return boolean subscription status
*/
function hasSubscriber($id)
public function hasSubscriber($id)
{
if (!is_numeric($id)) {
$id = $id->id;
@@ -288,13 +303,21 @@ class Profile_list extends Managed_DataObject
* @return Profile results
*/
function getTagged($offset=0, $limit=null, $since=0, $upto=0)
public function getTagged(int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
{
$tagged = new Profile();
$tagged->joinAdd(array('id', 'profile_tag:tagged'));
$tagged->joinAdd(['id', 'profile_tag:tagged']);
if (common_config('db', 'type') !== 'mysql') {
$tagged->selectAdd(sprintf(
'((EXTRACT(DAY %1$s) * 24 + EXTRACT(HOUR %1$s)) * 60 + ' .
'EXTRACT(MINUTE %1$s)) * 60 + FLOOR(EXTRACT(SECOND %1$s)) AS "cursor"',
"FROM (profile_tag.modified - TIMESTAMP '1970-01-01 00:00:00')"
));
} else {
$tagged->selectAdd("timestampdiff(SECOND, '1970-01-01', profile_tag.modified) AS `cursor`");
}
#@fixme: postgres
$tagged->selectAdd('unix_timestamp(profile_tag.modified) as "cursor"');
$tagged->whereAdd('profile_tag.tagger = '.$this->tagger);
$tagged->whereAdd("profile_tag.tag = '{$this->tag}'");
@@ -323,7 +346,7 @@ class Profile_list extends Managed_DataObject
* @return boolean success
*/
function delete($useWhere=false)
public function delete($useWhere = false)
{
// force delete one item at a time.
if (empty($this->id)) {
@@ -350,7 +373,7 @@ class Profile_list extends Managed_DataObject
* @return boolean success
*/
function update($dataObject=false)
public function update($dataObject = false)
{
if (!is_object($dataObject) && !$dataObject instanceof Profile_list) {
return parent::update($dataObject);
@@ -361,9 +384,9 @@ class Profile_list extends Managed_DataObject
// if original tag was different
// check to see if the new tag already exists
// if not, rename the tag correctly
if($dataObject->tag != $this->tag || $dataObject->tagger != $this->tagger) {
if ($dataObject->tag != $this->tag || $dataObject->tagger != $this->tagger) {
$existing = Profile_list::getByTaggerAndTag($this->tagger, $this->tag);
if(!empty($existing)) {
if (!empty($existing)) {
// TRANS: Server exception.
throw new ServerException(_('The tag you are trying to rename ' .
'to already exists.'));
@@ -382,7 +405,7 @@ class Profile_list extends Managed_DataObject
* @return string atom author element
*/
function asAtomAuthor()
public function asAtomAuthor()
{
$xs = new XMLStringer(true);
@@ -404,7 +427,7 @@ class Profile_list extends Managed_DataObject
* @return string activitystreams noun
*/
function asActivityNoun($element)
public function asActivityNoun($element)
{
$noun = ActivityObject::fromPeopletag($this);
return $noun->asString('activity:' . $element);
@@ -419,11 +442,13 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
function taggedCount($recount=false)
public function taggedCount($recount = false)
{
$keypart = sprintf('profile_list:tagged_count:%d:%s',
$this->tagger,
$this->tag);
$keypart = sprintf(
'profile_list:tagged_count:%d:%s',
$this->tagger,
$this->tag
);
$count = self::cacheGet($keypart);
@@ -450,15 +475,16 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
function subscriberCount($recount=false)
public function subscriberCount($recount = false)
{
$keypart = sprintf('profile_list:subscriber_count:%d',
$this->id);
$keypart = sprintf(
'profile_list:subscriber_count:%d',
$this->id
);
$count = self::cacheGet($keypart);
if ($count === false) {
$sub = new Profile_tag_subscription();
$sub->profile_tag_id = $this->id;
$count = (int) $sub->count('distinct profile_id');
@@ -478,7 +504,7 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
function blowNoticeStreamCache($all=false)
public function blowNoticeStreamCache($all = false)
{
self::blow('profile_list:notice_ids:%d', $this->id);
if ($all) {
@@ -496,7 +522,7 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
static function getByTaggerAndTag($tagger, $tag)
public static function getByTaggerAndTag($tagger, $tag)
{
$ptag = Profile_list::pkeyGet(array('tagger' => $tagger, 'tag' => $tag));
return $ptag;
@@ -514,11 +540,11 @@ class Profile_list extends Managed_DataObject
* @return Profile_list the people tag object
*/
static function ensureTag($tagger, $tag, $description=null, $private=false)
public static function ensureTag($tagger, $tag, $description = null, $private = false)
{
$ptag = Profile_list::getByTaggerAndTag($tagger, $tag);
if(empty($ptag->id)) {
if (empty($ptag->id)) {
$args = array(
'tag' => $tag,
'tagger' => $tagger,
@@ -544,7 +570,7 @@ class Profile_list extends Managed_DataObject
* @return integer maximum number of characters
*/
static function maxDescription()
public static function maxDescription()
{
$desclimit = common_config('peopletag', 'desclimit');
// null => use global limit (distinct from 0!)
@@ -563,7 +589,7 @@ class Profile_list extends Managed_DataObject
* @return boolean is the descripition too long?
*/
static function descriptionTooLong($desc)
public static function descriptionTooLong($desc)
{
$desclimit = self::maxDescription();
return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
@@ -578,7 +604,8 @@ class Profile_list extends Managed_DataObject
*
* @return mixed Profile_list on success, false on fail
*/
static function saveNew(array $fields) {
public static function saveNew(array $fields)
{
extract($fields);
$ptag = new Profile_list();
@@ -639,7 +666,7 @@ class Profile_list extends Managed_DataObject
$result = $ptag->update($orig);
if (!$result) {
common_log_db_error($ptag, 'UPDATE', __FILE__);
// TRANS: Server exception saving new tag.
// TRANS: Server exception saving new tag.
throw new ServerException(_('Could not set profile tag URI.'));
}
}
@@ -647,7 +674,7 @@ class Profile_list extends Managed_DataObject
if (!isset($mainpage) || empty($mainpage)) {
$orig = clone($ptag);
$user = User::getKV('id', $ptag->tagger);
if(!empty($user)) {
if (!empty($user)) {
$ptag->mainpage = common_local_url('showprofiletag', array('tag' => $ptag->tag, 'nickname' => $user->getNickname()));
} else {
$ptag->mainpage = $uri; // assume this is a remote peopletag and the uri works
@@ -687,9 +714,9 @@ class Profile_list extends Managed_DataObject
* @returns array (array (mixed items), int next_cursor, int previous_cursor)
*/
// XXX: This should be in Memcached_DataObject... eventually.
// XXX: This should be in Memcached_DataObject... eventually
static function getAtCursor($fn, array $args, $cursor, $count=20)
public static function getAtCursor($fn, array $args, $cursor, $count = 20)
{
$items = array();
@@ -698,12 +725,12 @@ class Profile_list extends Managed_DataObject
$next_cursor = 0;
$prev_cursor = 0;
if($cursor > 0) {
if ($cursor > 0) {
// if cursor is +ve fetch $count+2 items before cursor starting at cursor
$max_id = $cursor;
$fn_args = array_merge($args, array(0, $count+2, 0, $max_id));
$list = call_user_func_array($fn, $fn_args);
while($list->fetch()) {
while ($list->fetch()) {
$items[] = clone($list);
}
@@ -734,15 +761,14 @@ class Profile_list extends Managed_DataObject
$next_cursor = isset($next->cursor) ?
$items[$count-1]->cursor : $items[$count-1]->id;
}
} else if($cursor < -1) {
} elseif ($cursor < -1) {
// if cursor is -ve fetch $count+2 items created after -$cursor-1
$cursor = abs($cursor);
$since_id = $cursor-1;
$fn_args = array_merge($args, array(0, $count+2, $since_id));
$list = call_user_func_array($fn, $fn_args);
while($list->fetch()) {
while ($list->fetch()) {
$items[] = clone($list);
}
@@ -755,7 +781,10 @@ class Profile_list extends Managed_DataObject
} else {
$next_cursor = isset($items[$end]->cursor) ?
$items[$end]->cursor : $items[$end]->id;
if ($end > $count) array_pop($items); // excess item.
if ($end > $count) {
// excess item
array_pop($items);
}
// check if there are more items for next page
$fn_args = array_merge($args, array(0, 1, 0, $cursor));
@@ -771,23 +800,22 @@ class Profile_list extends Managed_DataObject
$prev_cursor = isset($prev->cursor) ?
-$items[0]->cursor : -$items[0]->id;
}
} else if($cursor == -1) {
} elseif ($cursor == -1) {
$fn_args = array_merge($args, array(0, $count+1));
$list = call_user_func_array($fn, $fn_args);
while($list->fetch()) {
while ($list->fetch()) {
$items[] = clone($list);
}
if (count($items)==$count+1) {
$next = array_pop($items);
if(isset($next->cursor)) {
if (isset($next->cursor)) {
$next_cursor = $items[$count-1]->cursor;
} else {
$next_cursor = $items[$count-1]->id;
}
}
}
return array($items, $next_cursor, $prev_cursor);
}
@@ -803,7 +831,8 @@ class Profile_list extends Managed_DataObject
* @return boolean success
*/
static function setCache($ckey, &$tag, $offset=0, $limit=null) {
public static function setCache($ckey, &$tag, $offset = 0, $limit = null)
{
$cache = Cache::instance();
if (empty($cache)) {
return false;
@@ -834,8 +863,8 @@ class Profile_list extends Managed_DataObject
* @return Profile_list results
*/
static function getCached($ckey, $offset=0, $limit=null) {
public static function getCached($ckey, $offset = 0, $limit = null)
{
$keys_str = self::cacheGet($ckey);
if ($keys_str === false) {
return false;
@@ -862,7 +891,8 @@ class Profile_list extends Managed_DataObject
* @return Profile_list results
*/
static function getByKeys(array $keys) {
public static function getByKeys(array $keys)
{
$cache = Cache::instance();
if (!empty($cache)) {
@@ -910,7 +940,7 @@ class Profile_list extends Managed_DataObject
}
}
function insert()
public function insert()
{
$result = parent::insert();
if ($result) {
+32 -29
Ver Arquivo
@@ -1,32 +1,31 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Data class for Profile preferences
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Data
* @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2013 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://www.gnu.org/software/social/
* @copyright 2013 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
class Profile_prefs extends Managed_DataObject
{
public $__table = 'profile_prefs'; // table name
@@ -58,7 +57,7 @@ class Profile_prefs extends Managed_DataObject
);
}
static function getNamespacePrefs(Profile $profile, $namespace, array $topic=array())
public static function getNamespacePrefs(Profile $profile, $namespace, array $topic = [])
{
if (empty($topic)) {
$prefs = new Profile_prefs();
@@ -76,13 +75,13 @@ class Profile_prefs extends Managed_DataObject
return $prefs;
}
static function getNamespace(Profile $profile, $namespace, array $topic=array())
public static function getNamespace(Profile $profile, $namespace, array $topic = [])
{
$prefs = self::getNamespacePrefs($profile, $namespace, $topic);
return $prefs->fetchAll();
}
static function getAll(Profile $profile)
public static function getAll(Profile $profile)
{
try {
$prefs = self::listFind('profile_id', array($profile->getID()));
@@ -100,13 +99,15 @@ class Profile_prefs extends Managed_DataObject
return $list;
}
static function getTopic(Profile $profile, $namespace, $topic) {
public static function getTopic(Profile $profile, $namespace, $topic)
{
return Profile_prefs::getByPK(array('profile_id' => $profile->getID(),
'namespace' => $namespace,
'topic' => $topic));
}
static function getData(Profile $profile, $namespace, $topic, $def=null) {
public static function getData(Profile $profile, $namespace, $topic, $def = null)
{
try {
$pref = self::getTopic($profile, $namespace, $topic);
} catch (NoResultException $e) {
@@ -120,7 +121,8 @@ class Profile_prefs extends Managed_DataObject
return $pref->data;
}
static function getConfigData(Profile $profile, $namespace, $topic) {
public static function getConfigData(Profile $profile, $namespace, $topic)
{
try {
$data = self::getData($profile, $namespace, $topic);
} catch (NoResultException $e) {
@@ -140,14 +142,15 @@ class Profile_prefs extends Managed_DataObject
* @return true if changes are made, false if no action taken
* @throws ServerException if preference could not be saved
*/
static function setData(Profile $profile, $namespace, $topic, $data=null) {
public static function setData(Profile $profile, $namespace, $topic, $data = null)
{
try {
$pref = self::getTopic($profile, $namespace, $topic);
if (is_null($data)) {
$pref->delete();
} else {
$orig = clone($pref);
$pref->data = $data;
$pref->data = DB_DataObject_Cast::blob($data);
$pref->update($orig);
}
return true;
@@ -161,7 +164,7 @@ class Profile_prefs extends Managed_DataObject
$pref->profile_id = $profile->getID();
$pref->namespace = $namespace;
$pref->topic = $topic;
$pref->data = $data;
$pref->data = DB_DataObject_Cast::blob($data);
$pref->created = common_sql_now();
if ($pref->insert() === false) {
+87 -56
Ver Arquivo
@@ -1,8 +1,24 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
/**
* Table Definition for profile_tag
*/
class Profile_tag extends Managed_DataObject
{
public $__table = 'profile_tag'; // table name
@@ -35,35 +51,34 @@ class Profile_tag extends Managed_DataObject
);
}
function links()
public function links()
{
return array('tagger,tag' => 'profile_list:tagger,tag');
}
function getMeta()
public function getMeta()
{
return Profile_list::pkeyGet(array('tagger' => $this->tagger, 'tag' => $this->tag));
}
static function getSelfTagsArray(Profile $target)
public static function getSelfTagsArray(Profile $target)
{
return self::getTagsArray($target->getID(), $target->getID(), $target);
}
static function setSelfTags(Profile $target, array $newtags, array $privacy=array())
public static function setSelfTags(Profile $target, array $newtags, array $privacy = [])
{
return self::setTags($target->getID(), $target->getID(), $newtags, $privacy);
}
static function getTags($tagger, $tagged, $auth_user=null) {
public static function getTags($tagger, $tagged, $auth_user = null)
{
$profile_list = new Profile_list();
$include_priv = 1;
if (!($auth_user instanceof User ||
$auth_user instanceof Profile) ||
($auth_user->id !== $tagger)) {
$profile_list->private = false;
$include_priv = 0;
}
@@ -81,7 +96,7 @@ class Profile_tag extends Managed_DataObject
$qry = sprintf($qry, $tagger, $tagged);
if (!$include_priv) {
$qry .= ' and profile_list.private = 0';
$qry .= ' AND profile_list.private = FALSE';
}
$profile_list->query($qry);
@@ -91,20 +106,23 @@ class Profile_tag extends Managed_DataObject
return $profile_list;
}
static function getTagsArray($tagger, $tagged, Profile $scoped=null)
public static function getTagsArray($tagger, $tagged, Profile $scoped = null)
{
$ptag = new Profile_tag();
$qry = sprintf('select profile_tag.tag '.
'from profile_tag join profile_list '.
' on (profile_tag.tagger = profile_list.tagger ' .
' and profile_tag.tag = profile_list.tag) ' .
'where profile_tag.tagger = %d ' .
'and profile_tag.tagged = %d ',
$tagger, $tagged);
$qry = sprintf(
'SELECT profile_tag.tag '.
'FROM profile_tag INNER JOIN profile_list '.
' ON (profile_tag.tagger = profile_list.tagger ' .
' and profile_tag.tag = profile_list.tag) ' .
'WHERE profile_tag.tagger = %d ' .
'AND profile_tag.tagged = %d ',
$tagger,
$tagged
);
if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) {
$qry .= 'and profile_list.private = 0';
$qry .= 'AND profile_list.private = FALSE';
}
$tags = array();
@@ -118,8 +136,8 @@ class Profile_tag extends Managed_DataObject
return $tags;
}
static function setTags($tagger, $tagged, array $newtags, array $privacy=array()) {
public static function setTags($tagger, $tagged, array $newtags, array $privacy = [])
{
$newtags = array_unique($newtags);
$oldtags = self::getTagsArray($tagger, $tagged, Profile::getByID($tagger));
@@ -145,8 +163,8 @@ class Profile_tag extends Managed_DataObject
}
# set a single tag
static function setTag($tagger, $tagged, $tag, $desc=null, $private=false) {
public static function setTag($tagger, $tagged, $tag, $desc=null, $private = false)
{
$ptag = Profile_tag::pkeyGet(array('tagger' => $tagger,
'tagged' => $tagged,
'tag' => $tag));
@@ -160,7 +178,6 @@ class Profile_tag extends Managed_DataObject
$tagged_profile = Profile::getByID($tagged);
if (Event::handle('StartTagProfile', array($tagger_profile, $tagged_profile, $tag))) {
if (!$tagger_profile->canTag($tagged_profile)) {
// TRANS: Client exception thrown trying to set a tag for a user that cannot be tagged.
throw new ClientException(_('You cannot tag this user.'));
@@ -172,10 +189,12 @@ class Profile_tag extends Managed_DataObject
if ($count >= common_config('peopletag', 'maxtags')) {
// TRANS: Client exception thrown trying to set more tags than allowed.
throw new ClientException(sprintf(_('You already have created %d or more tags ' .
'which is the maximum allowed number of tags. ' .
'Try using or deleting some existing tags.'),
common_config('peopletag', 'maxtags')));
throw new ClientException(sprintf(
_('You already have created %d or more tags ' .
'which is the maximum allowed number of tags. ' .
'Try using or deleting some existing tags.'),
common_config('peopletag', 'maxtags')
));
}
$plist = new Profile_list();
@@ -185,10 +204,13 @@ class Profile_tag extends Managed_DataObject
if ($profile_list->taggedCount() >= common_config('peopletag', 'maxpeople')) {
// TRANS: Client exception thrown when trying to add more people than allowed to a list.
throw new ClientException(sprintf(_('You already have %1$d or more people in list %2$s, ' .
'which is the maximum allowed number. ' .
'Try unlisting others first.'),
common_config('peopletag', 'maxpeople'), $tag));
throw new ClientException(sprintf(
_('You already have %1$d or more people in list %2$s, ' .
'which is the maximum allowed number. ' .
'Try unlisting others first.'),
common_config('peopletag', 'maxpeople'),
$tag
));
}
$newtag = new Profile_tag();
@@ -221,7 +243,8 @@ class Profile_tag extends Managed_DataObject
return $newtag;
}
static function unTag($tagger, $tagged, $tag) {
public static function unTag($tagger, $tagged, $tag)
{
$ptag = Profile_tag::pkeyGet(array('tagger' => $tagger,
'tagged' => $tagged,
'tag' => $tag));
@@ -247,13 +270,14 @@ class Profile_tag extends Managed_DataObject
}
// @fixme: move this to Profile_list?
static function cleanup($profile_list) {
public static function cleanup($profile_list)
{
$ptag = new Profile_tag();
$ptag->tagger = $profile_list->tagger;
$ptag->tag = $profile_list->tag;
$ptag->find();
while($ptag->fetch()) {
while ($ptag->fetch()) {
if (Event::handle('StartUntagProfile', array($ptag))) {
$orig = clone($ptag);
$result = $ptag->delete();
@@ -266,17 +290,18 @@ class Profile_tag extends Managed_DataObject
}
// move a tag!
static function moveTag($orig, $new) {
public static function moveTag($orig, $new)
{
$tags = new Profile_tag();
$qry = 'UPDATE profile_tag SET ' .
'tag = "%s", tagger = "%s" ' .
'WHERE tag = "%s" ' .
'AND tagger = "%s"';
$result = $tags->query(sprintf($qry,
$tags->escape($new->tag),
$tags->escape($new->tagger),
$tags->escape($orig->tag),
$tags->escape($orig->tagger)));
$qry = "UPDATE profile_tag SET tag = '%s', tagger = '%s' " .
"WHERE tag = '%s' AND tagger = '%s'";
$result = $tags->query(sprintf(
$qry,
$tags->escape($new->tag),
$tags->escape($new->tagger),
$tags->escape($orig->tag),
$tags->escape($orig->tagger)
));
if ($result === false) {
common_log_db_error($tags, 'UPDATE', __FILE__);
@@ -285,7 +310,8 @@ class Profile_tag extends Managed_DataObject
return $result;
}
static function blowCaches($tagger, $tagged) {
public static function blowCaches($tagger, $tagged)
{
foreach (array(0, 1) as $perm) {
self::blow(sprintf('profile_tag:tagger_tagged_privacy:%d-%d-%d', $tagger, $tagged, $perm));
}
@@ -293,38 +319,43 @@ class Profile_tag extends Managed_DataObject
}
// Return profiles with a given tag
static function getTagged($tagger, $tag) {
public static function getTagged($tagger, $tag)
{
$profile = new Profile();
$profile->query('SELECT profile.* ' .
'FROM profile JOIN profile_tag ' .
'ON profile.id = profile_tag.tagged ' .
'WHERE profile_tag.tagger = ' . $profile->escape($tagger) . ' ' .
'AND profile_tag.tag = "' . $profile->escape($tag) . '" ');
$tagged = array();
"AND profile_tag.tag = '" . $profile->escape($tag) . "' ");
$tagged = [];
while ($profile->fetch()) {
$tagged[] = clone($profile);
}
return true;
}
function insert()
public function insert()
{
$result = parent::insert();
if ($result) {
self::blow('profile_list:tagged_count:%d:%s',
$this->tagger,
$this->tag);
self::blow(
'profile_list:tagged_count:%d:%s',
$this->tagger,
$this->tag
);
}
return $result;
}
function delete($useWhere=false)
public function delete($useWhere = false)
{
$result = parent::delete($useWhere);
if ($result !== false) {
self::blow('profile_list:tagged_count:%d:%s',
$this->tagger,
$this->tag);
self::blow(
'profile_list:tagged_count:%d:%s',
$this->tagger,
$this->tag
);
}
return $result;
}
+57 -48
Ver Arquivo
@@ -1,23 +1,25 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* @copyright 2008, 2009, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for subscription
@@ -30,8 +32,8 @@ class Subscription extends Managed_DataObject
public $__table = 'subscription'; // table name
public $subscriber; // int(4) primary_key not_null
public $subscribed; // int(4) primary_key not_null
public $jabber; // tinyint(1) default_1
public $sms; // tinyint(1) default_1
public $jabber; // bool default_true
public $sms; // bool default_true
public $token; // varchar(191) not 255 because utf8mb4 takes more space
public $secret; // varchar(191) not 255 because utf8mb4 takes more space
public $uri; // varchar(191) not 255 because utf8mb4 takes more space
@@ -44,8 +46,8 @@ class Subscription extends Managed_DataObject
'fields' => array(
'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'profile listening'),
'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'profile being listened to'),
'jabber' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'deliver jabber messages'),
'sms' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'deliver sms messages'),
'jabber' => array('type' => 'bool', 'default' => true, 'description' => 'deliver jabber messages'),
'sms' => array('type' => 'bool', 'default' => true, 'description' => 'deliver sms messages'),
'token' => array('type' => 'varchar', 'length' => 191, 'description' => 'authorization token'),
'secret' => array('type' => 'varchar', 'length' => 191, 'description' => 'token secret'),
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier'),
@@ -74,7 +76,7 @@ class Subscription extends Managed_DataObject
* @return mixed Subscription or Subscription_queue: new subscription info
*/
static function start(Profile $subscriber, Profile $other, $force=false)
public static function start(Profile $subscriber, Profile $other, $force = false)
{
if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
// TRANS: Exception thrown when trying to subscribe while being banned from subscribing.
@@ -117,7 +119,6 @@ class Subscription extends Managed_DataObject
$otherUser->autosubscribe &&
!self::exists($other, $subscriber) &&
!$subscriber->hasBlocked($other)) {
try {
self::start($other, $subscriber);
} catch (AlreadyFulfilledException $e) {
@@ -137,7 +138,7 @@ class Subscription extends Managed_DataObject
return $sub;
}
static function ensureStart(Profile $subscriber, Profile $other, $force=false)
public static function ensureStart(Profile $subscriber, Profile $other, $force = false)
{
try {
$sub = self::start($subscriber, $other, $force);
@@ -157,12 +158,14 @@ class Subscription extends Managed_DataObject
$sub->subscriber = $subscriber->getID();
$sub->subscribed = $other->getID();
$sub->jabber = 1;
$sub->sms = 1;
$sub->jabber = true;
$sub->sms = true;
$sub->created = common_sql_now();
$sub->uri = self::newUri($subscriber,
$other,
$sub->created);
$sub->uri = self::newUri(
$subscriber,
$other,
$sub->created
);
$result = $sub->insert();
@@ -175,7 +178,7 @@ class Subscription extends Managed_DataObject
return $sub;
}
function notify()
public function notify()
{
// XXX: add other notifications (Jabber, SMS) here
// XXX: queue this and handle it offline
@@ -184,12 +187,11 @@ class Subscription extends Managed_DataObject
$this->notifyEmail();
}
function notifyEmail()
public function notifyEmail()
{
$subscribedUser = User::getKV('id', $this->subscribed);
if ($subscribedUser instanceof User) {
$subscriber = Profile::getKV('id', $this->subscriber);
mail_subscribe_notify_profile($subscribedUser, $subscriber);
@@ -200,7 +202,7 @@ class Subscription extends Managed_DataObject
* Cancel a subscription
*
*/
static function cancel(Profile $subscriber, Profile $other)
public static function cancel(Profile $subscriber, Profile $other)
{
if (!self::exists($subscriber, $other)) {
// TRANS: Exception thrown when trying to unsibscribe without a subscription.
@@ -215,7 +217,6 @@ class Subscription extends Managed_DataObject
}
if (Event::handle('StartUnsubscribe', array($subscriber, $other))) {
$sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
'subscribed' => $other->id));
@@ -245,7 +246,7 @@ class Subscription extends Managed_DataObject
return;
}
static function exists(Profile $subscriber, Profile $other)
public static function exists(Profile $subscriber, Profile $other)
{
try {
$sub = self::getSubscription($subscriber, $other);
@@ -256,7 +257,7 @@ class Subscription extends Managed_DataObject
return true;
}
static function getSubscription(Profile $subscriber, Profile $other)
public static function getSubscription(Profile $subscriber, Profile $other)
{
// This is essentially a pkeyGet but we have an object to return in NoResultException
$sub = new Subscription();
@@ -278,7 +279,7 @@ class Subscription extends Managed_DataObject
return Profile::getByID($this->subscribed);
}
function asActivity()
public function asActivity()
{
$subscriber = $this->getSubscriber();
$subscribed = $this->getSubscribed();
@@ -293,19 +294,25 @@ class Subscription extends Managed_DataObject
$act->time = strtotime($this->created);
// TRANS: Activity title when subscribing to another person.
$act->title = _m('TITLE','Follow');
$act->title = _m('TITLE', 'Follow');
// TRANS: Notification given when one person starts following another.
// TRANS: %1$s is the subscriber, %2$s is the subscribed.
$act->content = sprintf(_('%1$s is now following %2$s.'),
$subscriber->getBestName(),
$subscribed->getBestName());
$act->content = sprintf(
_('%1$s is now following %2$s.'),
$subscriber->getBestName(),
$subscribed->getBestName()
);
$act->actor = $subscriber->asActivityObject();
$act->objects[] = $subscribed->asActivityObject();
$url = common_local_url('AtomPubShowSubscription',
array('subscriber' => $subscriber->id,
'subscribed' => $subscribed->id));
$url = common_local_url(
'AtomPubShowSubscription',
[
'subscriber' => $subscriber->id,
'subscribed' => $subscribed->id,
]
);
$act->selfLink = $url;
$act->editLink = $url;
@@ -356,11 +363,13 @@ class Subscription extends Managed_DataObject
// The following are helper functions to the subscription lists,
// notably the public ones get used in places such as Profile
public static function getSubscribedIDs($profile_id, $offset, $limit) {
public static function getSubscribedIDs($profile_id, $offset, $limit)
{
return self::getSubscriptionIDs('subscribed', $profile_id, $offset, $limit);
}
public static function getSubscriberIDs($profile_id, $offset, $limit) {
public static function getSubscriberIDs($profile_id, $offset, $limit)
{
return self::getSubscriptionIDs('subscriber', $profile_id, $offset, $limit);
}
@@ -397,7 +406,7 @@ class Subscription extends Managed_DataObject
$sub = new Subscription();
$sub->$by_type = $profile_id;
$sub->selectAdd($get_type);
$sub->whereAdd("{$get_type} != {$profile_id}");
$sub->whereAdd($get_type . ' <> ' . $profile_id);
$sub->orderBy('created DESC');
$sub->limit($queryoffset, $querylimit);
@@ -426,7 +435,7 @@ class Subscription extends Managed_DataObject
*
* @return boolean success flag.
*/
function update($dataObject=false)
public function update($dataObject = false)
{
self::blow('subscription:by-subscriber:'.$this->subscriber);
self::blow('subscription:by-subscribed:'.$this->subscribed);
+137 -126
Ver Arquivo
@@ -1,23 +1,20 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for user
@@ -37,24 +34,24 @@ class User extends Managed_DataObject
public $password; // varchar(191) not 255 because utf8mb4 takes more space
public $email; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $incomingemail; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $emailnotifysub; // tinyint(1) default_1
public $emailnotifyfav; // tinyint(1) default_1
public $emailnotifynudge; // tinyint(1) default_1
public $emailnotifymsg; // tinyint(1) default_1
public $emailnotifyattn; // tinyint(1) default_1
public $emailnotifysub; // bool default_true
public $emailnotifyfav; // tinyint(1) default_null
public $emailnotifynudge; // bool default_true
public $emailnotifymsg; // bool default_true
public $emailnotifyattn; // bool default_true
public $language; // varchar(50)
public $timezone; // varchar(50)
public $emailpost; // tinyint(1) default_1
public $emailpost; // bool default_true
public $sms; // varchar(64) unique_key
public $carrier; // int(4)
public $smsnotify; // tinyint(1)
public $smsreplies; // tinyint(1)
public $smsnotify; // bool default_false
public $smsreplies; // bool default_false
public $smsemail; // varchar(191) not 255 because utf8mb4 takes more space
public $uri; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $autosubscribe; // tinyint(1)
public $autosubscribe; // bool default_false
public $subscribe_policy; // tinyint(1)
public $urlshorteningservice; // varchar(50) default_ur1.ca
public $private_stream; // tinyint(1) default_0
public $private_stream; // bool default_false
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@@ -71,24 +68,24 @@ class User extends Managed_DataObject
'password' => array('type' => 'varchar', 'length' => 191, 'description' => 'salted password, can be null for OpenID users'),
'email' => array('type' => 'varchar', 'length' => 191, 'description' => 'email address for password recovery etc.'),
'incomingemail' => array('type' => 'varchar', 'length' => 191, 'description' => 'email address for post-by-email'),
'emailnotifysub' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
'emailnotifysub' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of subscriptions'),
'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => null, 'description' => 'Notify by email of favorites'),
'emailnotifynudge' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of nudges'),
'emailnotifymsg' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of direct messages'),
'emailnotifyattn' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of @-replies'),
'emailnotifynudge' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of nudges'),
'emailnotifymsg' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of direct messages'),
'emailnotifyattn' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of @-replies'),
'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
'emailpost' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Post by email'),
'emailpost' => array('type' => 'bool', 'default' => true, 'description' => 'Post by email'),
'sms' => array('type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'),
'carrier' => array('type' => 'int', 'description' => 'foreign key to sms_carrier'),
'smsnotify' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS'),
'smsreplies' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS on replies'),
'smsnotify' => array('type' => 'bool', 'default' => false, 'description' => 'whether to send notices to SMS'),
'smsreplies' => array('type' => 'bool', 'default' => false, 'description' => 'whether to send notices to SMS on replies'),
'smsemail' => array('type' => 'varchar', 'length' => 191, 'description' => 'built from sms and carrier'),
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'),
'autosubscribe' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'automatically subscribe to users who subscribe to us'),
'autosubscribe' => array('type' => 'bool', 'default' => false, 'description' => 'automatically subscribe to users who subscribe to us'),
'subscribe_policy' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can subscribe; 1 = require approval'),
'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
'private_stream' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to limit all notices to followers only'),
'private_stream' => array('type' => 'bool', 'default' => false, 'description' => 'whether to limit all notices to followers only'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
@@ -144,7 +141,7 @@ class User extends Managed_DataObject
return $this->getProfile()->getNickname();
}
static function getByNickname($nickname)
public static function getByNickname($nickname)
{
$user = User::getKV('nickname', $nickname);
if (!$user instanceof User) {
@@ -154,12 +151,12 @@ class User extends Managed_DataObject
return $user;
}
function isSubscribed(Profile $other)
public function isSubscribed(Profile $other)
{
return $this->getProfile()->isSubscribed($other);
}
function hasPendingSubscription(Profile $other)
public function hasPendingSubscription(Profile $other)
{
return $this->getProfile()->hasPendingSubscription($other);
}
@@ -169,17 +166,17 @@ class User extends Managed_DataObject
*
* @return mixed Notice or null
*/
function getCurrentNotice()
public function getCurrentNotice()
{
return $this->getProfile()->getCurrentNotice();
}
function getCarrier()
public function getCarrier()
{
return Sms_carrier::getKV('id', $this->carrier);
}
function hasBlocked(Profile $other)
public function hasBlocked(Profile $other)
{
return $this->getProfile()->hasBlocked($other);
}
@@ -206,10 +203,9 @@ class User extends Managed_DataObject
* @return User object
* @throws Exception on failure
*/
static function register(array $fields, $accept_email_fail=false) {
public static function register(array $fields, $accept_email_fail = false)
{
// MAGICALLY put fields into current scope
extract($fields);
$profile = new Profile();
@@ -262,23 +258,22 @@ class User extends Managed_DataObject
}
}
if(isset($email_confirmed) && $email_confirmed) {
if (isset($email_confirmed) && $email_confirmed) {
$user->email = $email;
}
// Set default-on options here, otherwise they'll be disabled
// initially for sites using caching, since the initial encache
// doesn't know about the defaults in the database.
$user->emailnotifysub = 1;
$user->emailnotifynudge = 1;
$user->emailnotifymsg = 1;
$user->emailnotifyattn = 1;
$user->emailpost = 1;
$user->emailnotifysub = true;
$user->emailnotifynudge = true;
$user->emailnotifymsg = true;
$user->emailnotifyattn = true;
$user->emailpost = true;
$user->created = common_sql_now();
if (Event::handle('StartUserRegister', array($profile))) {
$profile->query('BEGIN');
$id = $profile->insert();
@@ -291,7 +286,7 @@ class User extends Managed_DataObject
// Necessary because id has been known to be reissued.
if ($profile->hasRole(Profile_role::DELETED)) {
$profile->revokeRole(Profile_role::DELETED);
$profile->revokeRole(Profile_role::DELETED);
}
$user->id = $id;
@@ -367,8 +362,11 @@ class User extends Managed_DataObject
if (!empty($defnick)) {
$defuser = User::getKV('nickname', $defnick);
if (empty($defuser)) {
common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
__FILE__);
common_log(
LOG_WARNING,
sprintf('Default user %s does not exist.', $defnick),
__FILE__
);
} else {
Subscription::ensureStart($profile, $defuser->getProfile());
}
@@ -394,16 +392,23 @@ class User extends Managed_DataObject
if (!empty($welcome)) {
$welcomeuser = User::getKV('nickname', $welcome);
if (empty($welcomeuser)) {
common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick),
__FILE__);
common_log(
LOG_WARNING,
sprintf('Welcome user %s does not exist.', $defnick),
__FILE__
);
} else {
$notice = Notice::saveNew($welcomeuser->id,
// TRANS: Notice given on user registration.
// TRANS: %1$s is the sitename, $2$s is the registering user's nickname.
sprintf(_('Welcome to %1$s, @%2$s!'),
common_config('site', 'name'),
$profile->getNickname()),
'system');
$notice = Notice::saveNew(
$welcomeuser->id,
// TRANS: Notice given on user registration.
// TRANS: %1$s is the sitename, $2$s is the registering user's nickname.
sprintf(
_('Welcome to %1$s, @%2$s!'),
common_config('site', 'name'),
$profile->getNickname()
),
'system'
);
}
}
@@ -418,9 +423,8 @@ class User extends Managed_DataObject
}
// Things we do when the email changes
function emailChanged()
public function emailChanged()
{
$invites = new Invitation();
$invites->address = $this->email;
$invites->address_type = 'email';
@@ -441,48 +445,53 @@ class User extends Managed_DataObject
}
}
function mutuallySubscribed(Profile $other)
public function mutuallySubscribed(Profile $other)
{
return $this->getProfile()->mutuallySubscribed($other);
}
function mutuallySubscribedUsers()
public function mutuallySubscribedUsers()
{
// 3-way join; probably should get cached
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = "SELECT $UT.* " .
"FROM subscription sub1 JOIN $UT ON sub1.subscribed = $UT.id " .
"JOIN subscription sub2 ON $UT.id = sub2.subscriber " .
'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
"ORDER BY $UT.nickname";
$user = new User();
$user->query(sprintf($qry, $this->id, $this->id));
// 3-way join; probably should get cached
$user->query(sprintf(
'SELECT %1$s.* ' .
'FROM subscription AS sub1 INNER JOIN %1$s ON sub1.subscribed = %1$s.id ' .
'INNER JOIN subscription AS sub2 ON %1$s.id = sub2.subscriber ' .
'WHERE sub1.subscriber = %2$d AND sub2.subscribed = %2$d ' .
'ORDER BY %1$s.nickname',
$user->escapedTableName(),
$this->id
));
return $user;
}
function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
public function getReplies($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
{
return $this->getProfile()->getReplies($offset, $limit, $since_id, $before_id);
}
function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
public function getTaggedNotices($tag, $offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
{
return $this->getProfile()->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
}
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
public function getNotices($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
{
return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
}
function block(Profile $other)
public function block(Profile $other)
{
// Add a new block record
// no blocking (and thus unsubbing from) yourself
if ($this->id == $other->id) {
common_log(LOG_WARNING,
common_log(
LOG_WARNING,
sprintf(
"Profile ID %d (%s) tried to block themself.",
$this->id,
@@ -521,7 +530,7 @@ class User extends Managed_DataObject
return true;
}
function unblock(Profile $other)
public function unblock(Profile $other)
{
// Get the block record
@@ -541,17 +550,17 @@ class User extends Managed_DataObject
return true;
}
function isMember(User_group $group)
public function isMember(User_group $group)
{
return $this->getProfile()->isMember($group);
}
function isAdmin(User_group $group)
public function isAdmin(User_group $group)
{
return $this->getProfile()->isAdmin($group);
}
function getGroups($offset=0, $limit=null)
public function getGroups($offset = 0, $limit = null)
{
return $this->getProfile()->getGroups($offset, $limit);
}
@@ -563,7 +572,7 @@ class User extends Managed_DataObject
* @param User_group $group
* @return Group_member
*/
function joinGroup(User_group $group)
public function joinGroup(User_group $group)
{
return $this->getProfile()->joinGroup($group);
}
@@ -573,37 +582,37 @@ class User extends Managed_DataObject
*
* @param User_group $group
*/
function leaveGroup(User_group $group)
public function leaveGroup(User_group $group)
{
return $this->getProfile()->leaveGroup($group);
}
function getSubscribed($offset=0, $limit=null)
public function getSubscribed($offset = 0, $limit = null)
{
return $this->getProfile()->getSubscribed($offset, $limit);
}
function getSubscribers($offset=0, $limit=null)
public function getSubscribers($offset = 0, $limit = null)
{
return $this->getProfile()->getSubscribers($offset, $limit);
}
function getTaggedSubscribers($tag, $offset=0, $limit=null)
public function getTaggedSubscribers($tag, $offset = 0, $limit = null)
{
return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit);
}
function getTaggedSubscriptions($tag, $offset=0, $limit=null)
public function getTaggedSubscriptions($tag, $offset = 0, $limit = null)
{
return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit);
}
function hasRight($right)
public function hasRight($right)
{
return $this->getProfile()->hasRight($right);
}
function delete($useWhere=false)
public function delete($useWhere = false)
{
if (empty($this->id)) {
common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
@@ -640,14 +649,14 @@ class User extends Managed_DataObject
return parent::delete($useWhere);
}
function _deleteTags()
public function _deleteTags()
{
$tag = new Profile_tag();
$tag->tagger = $this->id;
$tag->delete();
}
function _deleteBlocks()
public function _deleteBlocks()
{
$block = new Profile_block();
$block->blocker = $this->id;
@@ -655,32 +664,32 @@ class User extends Managed_DataObject
// XXX delete group block? Reset blocker?
}
function hasRole($name)
public function hasRole($name)
{
return $this->getProfile()->hasRole($name);
}
function grantRole($name)
public function grantRole($name)
{
return $this->getProfile()->grantRole($name);
}
function revokeRole($name)
public function revokeRole($name)
{
return $this->getProfile()->revokeRole($name);
}
function isSandboxed()
public function isSandboxed()
{
return $this->getProfile()->isSandboxed();
}
function isSilenced()
public function isSilenced()
{
return $this->getProfile()->isSilenced();
}
function receivesEmailNotifications()
public function receivesEmailNotifications()
{
// We could do this in one large if statement, but that's not as easy to read
// Don't send notifications if we don't know the user's email address or it is
@@ -695,7 +704,7 @@ class User extends Managed_DataObject
return true;
}
function repeatedByMe($offset=0, $limit=20, $since_id=null, $max_id=null)
public function repeatedByMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
{
// FIXME: Use another way to get Profile::current() since we
// want to avoid confusion between session user and queue processing.
@@ -704,7 +713,7 @@ class User extends Managed_DataObject
}
function repeatsOfMe($offset=0, $limit=20, $since_id=null, $max_id=null)
public function repeatsOfMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
{
// FIXME: Use another way to get Profile::current() since we
// want to avoid confusion between session user and queue processing.
@@ -712,7 +721,7 @@ class User extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
public function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null)
public function repeatedToMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
{
return $this->getProfile()->repeatedToMe($offset, $limit, $since_id, $max_id);
}
@@ -791,7 +800,7 @@ class User extends Managed_DataObject
* @throws ServerException if no valid single user account is present
* @throws ServerException if called when not in single-user mode
*/
static function singleUserNickname()
public static function singleUserNickname()
{
try {
$user = User::singleUser();
@@ -828,7 +837,7 @@ class User extends Managed_DataObject
* Get a list of OAuth client applications that have access to this
* user's account.
*/
function getConnectedApps($offset = 0, $limit = null)
public function getConnectedApps($offset = 0, $limit = null)
{
$qry =
'SELECT u.* ' .
@@ -839,11 +848,7 @@ class User extends Managed_DataObject
'ORDER BY u.created DESC ';
if ($offset > 0) {
if (common_config('db','type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
}
$apps = new Oauth_application_user();
@@ -863,16 +868,16 @@ class User extends Managed_DataObject
* @return array of variable names to include in serialization.
*/
function __sleep()
public function __sleep()
{
$vars = parent::__sleep();
$skip = array('_profile');
return array_diff($vars, $skip);
}
static function recoverPassword($nore)
public static function recoverPassword($nore)
{
require_once(INSTALLDIR . '/lib/mail.php');
require_once INSTALLDIR . '/lib/util/mail.php';
// $confirm_email will be used as a fallback if our user doesn't have a confirmed email
$confirm_email = null;
@@ -943,7 +948,7 @@ class User extends Managed_DataObject
throw new ServerException(_('Error saving address confirmation.'));
}
// @todo FIXME: needs i18n.
// @todo FIXME: needs i18n.
$body = "Hey, $user->nickname.";
$body .= "\n\n";
$body .= 'Someone just asked for a new password ' .
@@ -951,8 +956,10 @@ class User extends Managed_DataObject
$body .= "\n\n";
$body .= 'If it was you, and you want to confirm, use the URL below:';
$body .= "\n\n";
$body .= "\t".common_local_url('recoverpassword',
array('code' => $confirm->code));
$body .= "\t" . common_local_url(
'recoverpassword',
['code' => $confirm->code]
);
$body .= "\n\n";
$body .= 'If not, just ignore this message.';
$body .= "\n\n";
@@ -966,7 +973,7 @@ class User extends Managed_DataObject
mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
}
function streamModeOnly()
public function streamModeOnly()
{
if (common_config('oldschool', 'enabled')) {
$osp = Old_school_prefs::getKV('user_id', $this->id);
@@ -978,7 +985,7 @@ class User extends Managed_DataObject
return false;
}
function streamNicknames()
public function streamNicknames()
{
if (common_config('oldschool', 'enabled')) {
$osp = Old_school_prefs::getKV('user_id', $this->id);
@@ -989,7 +996,7 @@ class User extends Managed_DataObject
return false;
}
function registrationActivity()
public function registrationActivity()
{
$profile = $this->getProfile();
@@ -1007,16 +1014,20 @@ class User extends Managed_DataObject
$act->objects[] = $service;
$act->id = TagURI::mint('user:register:%d',
$this->id);
$act->id = TagURI::mint(
'user:register:%d',
$this->id
);
$act->time = strtotime($this->created);
$act->title = _("Register");
$act->content = sprintf(_('%1$s joined %2$s.'),
$profile->getBestName(),
$service->title);
$act->content = sprintf(
_('%1$s joined %2$s.'),
$profile->getBestName(),
$service->title
);
return $act;
}
+94 -76
Ver Arquivo
@@ -1,8 +1,24 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
/**
* Table Definition for user_group
*/
class User_group extends Managed_DataObject
{
const JOIN_POLICY_OPEN = 0;
@@ -63,7 +79,7 @@ class User_group extends Managed_DataObject
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universal identifier'),
'mainpage' => array('type' => 'varchar', 'length' => 191, 'description' => 'page for group info to link to'),
'join_policy' => array('type' => 'int', 'size' => 'tiny', 'description' => '0=open; 1=requires admin approval'),
'join_policy' => array('type' => 'int', 'size' => 'tiny', 'description' => '0=open; 1=requires admin approval'),
'force_scope' => array('type' => 'int', 'size' => 'tiny', 'description' => '0=never,1=sometimes,-1=always'),
),
'primary key' => array('id'),
@@ -118,40 +134,38 @@ class User_group extends Managed_DataObject
return Theme::path('default-avatar-'.$sizenames[$size].'.png');
}
function homeUrl()
public function homeUrl()
{
return $this->getProfile()->getUrl();
}
function getUri()
public function getUri()
{
$uri = null;
if (Event::handle('StartUserGroupGetUri', array($this, &$uri))) {
if (!empty($this->uri)) {
$uri = $this->uri;
} elseif ($this->isLocal()) {
$uri = common_local_url('groupbyid',
array('id' => $this->id));
$uri = common_local_url('groupbyid', ['id' => $this->id]);
}
}
Event::handle('EndUserGroupGetUri', array($this, &$uri));
return $uri;
}
function permalink()
public function permalink()
{
$url = null;
if (Event::handle('StartUserGroupPermalink', array($this, &$url))) {
if ($this->isLocal()) {
$url = common_local_url('groupbyid',
array('id' => $this->id));
$url = common_local_url('groupbyid', ['id' => $this->id]);
}
}
Event::handle('EndUserGroupPermalink', array($this, &$url));
return $url;
}
function getNotices($offset, $limit, $since_id=null, $max_id=null)
public function getNotices($offset, $limit, $since_id = null, $max_id = null)
{
// FIXME: Get the Profile::current() some other way, to avoid
// possible confusion between current session and queue process.
@@ -160,29 +174,26 @@ class User_group extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
function getMembers($offset=0, $limit=null) {
public function getMembers($offset = 0, $limit = null)
{
$ids = null;
if (is_null($limit) || $offset + $limit > User_group::CACHE_WINDOW) {
$ids = $this->getMemberIDs($offset,
$limit);
$ids = $this->getMemberIDs($offset, $limit);
} else {
$key = sprintf('group:member_ids:%d', $this->id);
$window = self::cacheGet($key);
if ($window === false) {
$window = $this->getMemberIDs(0,
User_group::CACHE_WINDOW);
$window = $this->getMemberIDs(0, User_group::CACHE_WINDOW);
self::cacheSet($key, $window);
}
$ids = array_slice($window,
$offset,
$limit);
$ids = array_slice($window, $offset, $limit);
}
return Profile::multiGet('id', $ids);
}
function getMemberIDs($offset=0, $limit=null)
public function getMemberIDs($offset = 0, $limit = null)
{
$gm = new Group_member();
@@ -215,7 +226,7 @@ class User_group extends Managed_DataObject
* @param int $limit
* @return Profile
*/
function getRequests($offset=0, $limit=null)
public function getRequests($offset = 0, $limit = null)
{
$rq = new Group_join_queue();
$rq->group_id = $this->id;
@@ -237,7 +248,7 @@ class User_group extends Managed_DataObject
{
$block = new Group_member();
$block->group_id = $this->id;
$block->is_admin = 1;
$block->is_admin = true;
return $block->count();
}
@@ -264,7 +275,7 @@ class User_group extends Managed_DataObject
return $cnt;
}
function getBlockedCount()
public function getBlockedCount()
{
// XXX: WORM cache this
@@ -274,7 +285,7 @@ class User_group extends Managed_DataObject
return $block->count();
}
function getQueueCount()
public function getQueueCount()
{
// XXX: WORM cache this
@@ -284,11 +295,12 @@ class User_group extends Managed_DataObject
return $queue->count();
}
function getAdmins($offset=null, $limit=null) // offset is null because DataObject wants it, 0 would mean no results
// offset is null because DataObject wants it, 0 would mean no results
public function getAdmins($offset = null, $limit = null)
{
$admins = new Profile();
$admins->joinAdd(array('id', 'group_member:profile_id'));
$admins->whereAdd(sprintf('group_member.group_id = %u AND group_member.is_admin = 1', $this->id));
$admins->whereAdd('group_member.group_id = ' . $this->id . ' AND group_member.is_admin = true');
$admins->orderBy('group_member.modified ASC');
$admins->limit($offset, $limit);
$admins->find();
@@ -296,7 +308,8 @@ class User_group extends Managed_DataObject
return $admins;
}
function getBlocked($offset=null, $limit=null) // offset is null because DataObject wants it, 0 would mean no results
// offset is null because DataObject wants it, 0 would mean no results
public function getBlocked($offset = null, $limit = null)
{
$blocked = new Profile();
$blocked->joinAdd(array('id', 'group_block:blocked'));
@@ -308,7 +321,7 @@ class User_group extends Managed_DataObject
return $blocked;
}
function setOriginal($filename)
public function setOriginal($filename)
{
// This should be handled by the Profile->setOriginal function so user and group avatars are handled the same
$imagefile = new ImageFile(null, Avatar::path($filename));
@@ -320,8 +333,12 @@ class User_group extends Managed_DataObject
$orig = clone($this);
$this->original_logo = Avatar::url($filename);
foreach ($sizes as $name=>$size) {
$filename = Avatar::filename($this->profile_id, image_type_to_extension($imagefile->preferredType()),
$size, common_timestamp());
$filename = Avatar::filename(
$this->profile_id,
image_type_to_extension($imagefile->preferredType()),
$size,
common_timestamp()
);
$imagefile->resizeTo(Avatar::path($filename), array('width'=>$size, 'height'=>$size));
$this->$name = Avatar::url($filename);
}
@@ -329,7 +346,7 @@ class User_group extends Managed_DataObject
return $this->update($orig);
}
function getBestName()
public function getBestName()
{
return ($this->fullname) ? $this->fullname : $this->nickname;
}
@@ -340,17 +357,17 @@ class User_group extends Managed_DataObject
*
* @return string
*/
function getFancyName()
public function getFancyName()
{
if ($this->fullname) {
// TRANS: Full name of a profile or group followed by nickname in parens
return sprintf(_m('FANCYNAME','%1$s (%2$s)'), $this->fullname, $this->nickname);
return sprintf(_m('FANCYNAME', '%1$s (%2$s)'), $this->fullname, $this->nickname);
} else {
return $this->nickname;
}
}
function getAliases()
public function getAliases()
{
$aliases = array();
@@ -371,8 +388,8 @@ class User_group extends Managed_DataObject
return $aliases;
}
function setAliases($newaliases) {
public function setAliases($newaliases)
{
$newaliases = array_unique($newaliases);
$oldaliases = $this->getAliases();
@@ -413,7 +430,7 @@ class User_group extends Managed_DataObject
return true;
}
static function getForNickname($nickname, Profile $profile=null)
public static function getForNickname($nickname, Profile $profile = null)
{
$nickname = Nickname::normalize($nickname);
@@ -440,24 +457,21 @@ class User_group extends Managed_DataObject
return null;
}
function getUserMembers()
public function getUserMembers()
{
// XXX: cache this
$user = new User();
if(common_config('db','quote_identifiers'))
$user_table = '"user"';
else $user_table = 'user';
$qry =
'SELECT id ' .
'FROM '. $user_table .' JOIN group_member '.
'ON '. $user_table .'.id = group_member.profile_id ' .
'WHERE group_member.group_id = %d ';
$user->query(sprintf(
'SELECT id FROM %1$s INNER JOIN group_member ' .
'ON %1$s.id = group_member.profile_id ' .
'WHERE group_member.group_id = %2$d ',
$user->escapedTableName(),
$this->id
));
$user->query(sprintf($qry, $this->id));
$ids = array();
$ids = [];
while ($user->fetch()) {
$ids[] = $user->id;
@@ -468,7 +482,7 @@ class User_group extends Managed_DataObject
return $ids;
}
static function maxDescription()
public static function maxDescription()
{
$desclimit = common_config('group', 'desclimit');
// null => use global limit (distinct from 0!)
@@ -478,13 +492,13 @@ class User_group extends Managed_DataObject
return $desclimit;
}
static function descriptionTooLong($desc)
public static function descriptionTooLong($desc)
{
$desclimit = self::maxDescription();
return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
}
function asAtomEntry($namespace=false, $source=false)
public function asAtomEntry($namespace = false, $source = false)
{
$xs = new XMLStringer(true);
@@ -528,7 +542,7 @@ class User_group extends Managed_DataObject
return $xs->getString();
}
function asAtomAuthor()
public function asAtomAuthor()
{
$xs = new XMLStringer(true);
@@ -551,20 +565,21 @@ class User_group extends Managed_DataObject
*
* @return string
*/
function asActivityNoun($element)
public function asActivityNoun($element)
{
$noun = ActivityObject::fromGroup($this);
return $noun->asString('activity:' . $element);
}
function getAvatar()
public function getAvatar()
{
return empty($this->homepage_logo)
? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
: $this->homepage_logo;
}
static function register($fields) {
public static function register($fields)
{
if (!empty($fields['userid'])) {
$profile = Profile::getKV('id', $fields['userid']);
if ($profile && !$profile->hasRight(Right::CREATEGROUP)) {
@@ -580,18 +595,20 @@ class User_group extends Managed_DataObject
// MAGICALLY put fields into current scope
// @fixme kill extract(); it makes debugging absurdly hard
$defaults = array('nickname' => null,
'fullname' => null,
'homepage' => null,
'description' => null,
'location' => null,
'uri' => null,
'mainpage' => null,
'aliases' => array(),
'userid' => null);
$fields = array_merge($defaults, $fields);
$defaults = [
'nickname' => null,
'fullname' => null,
'homepage' => null,
'description' => null,
'location' => null,
'uri' => null,
'mainpage' => null,
'aliases' => [],
'userid' => null,
];
$fields = array_merge($defaults, $fields);
extract($fields);
$group = new User_group();
@@ -645,7 +662,6 @@ class User_group extends Managed_DataObject
}
if (Event::handle('StartGroupSave', array(&$group))) {
$result = $group->insert();
if ($result === false) {
@@ -676,7 +692,7 @@ class User_group extends Managed_DataObject
$member->group_id = $group->id;
$member->profile_id = $userid;
$member->is_admin = 1;
$member->is_admin = true;
$member->created = $group->created;
$result = $member->insert();
@@ -721,7 +737,7 @@ class User_group extends Managed_DataObject
* are not de-cached in the UI, including the sidebar lists on
* GroupsAction
*/
function delete($useWhere=false)
public function delete($useWhere = false)
{
if (empty($this->id)) {
common_log(LOG_WARNING, "Ambiguous User_group->delete(); skipping related tables.");
@@ -813,7 +829,7 @@ class User_group extends Managed_DataObject
return parent::update($dataObject);
}
function isPrivate()
public function isPrivate()
{
return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
intval($this->force_scope) === 1);
@@ -825,14 +841,16 @@ class User_group extends Managed_DataObject
return ($local instanceof Local_group);
}
static function groupsFromText($text, Profile $profile)
public static function groupsFromText($text, Profile $profile)
{
$groups = array();
/* extract all !group */
$count = preg_match_all('/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/',
strtolower($text),
$match);
$count = preg_match_all(
'/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/',
strtolower($text),
$match
);
if (!$count) {
return $groups;
@@ -848,7 +866,7 @@ class User_group extends Managed_DataObject
return $groups;
}
static function idsFromText($text, Profile $profile)
public static function idsFromText($text, Profile $profile)
{
$ids = array();
$groups = self::groupsFromText($text, $profile);
+25 -27
Ver Arquivo
@@ -1,32 +1,31 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Data class for user IM preferences
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Data
* @package StatusNet
* @package GNUsocial
* @author Craig Andrews <candrews@integralblue.com>
* @copyright 2009 StatusNet Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class User_im_prefs extends Managed_DataObject
@@ -38,9 +37,9 @@ class User_im_prefs extends Managed_DataObject
public $user_id; // int(4) primary_key not_null
public $screenname; // varchar(191) not_null not 255 because utf8mb4 takes more space
public $transport; // varchar(191) not_null not 255 because utf8mb4 takes more space
public $notify; // tinyint(1)
public $replies; // tinyint(1)
public $updatefrompresence; // tinyint(1)
public $notify; // bool not_null default_false
public $replies; // bool not_null default_false
public $updatefrompresence; // bool not_null default_false
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@@ -54,9 +53,9 @@ class User_im_prefs extends Managed_DataObject
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
'screenname' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'screenname on this service'),
'transport' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex xmpp, aim)'),
'notify' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Notify when a new notice is sent'),
'replies' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Send replies from people not subscribed to'),
'updatefrompresence' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Send replies from people not subscribed to.'),
'notify' => array('type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify when a new notice is sent'),
'replies' => array('type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Send replies from people not subscribed to'),
'updatefrompresence' => array('type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Update from presence.'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
@@ -69,5 +68,4 @@ class User_im_prefs extends Managed_DataObject
),
);
}
}
+19 -22
Ver Arquivo
@@ -1,30 +1,27 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Data class for user location preferences
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Data
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
@@ -36,7 +33,7 @@ class User_location_prefs extends Managed_DataObject
public $__table = 'user_location_prefs'; // table name
public $user_id; // int(4) primary_key not_null
public $share_location; // tinyint(1) default_1
public $share_location; // bool default_true
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@@ -48,7 +45,7 @@ class User_location_prefs extends Managed_DataObject
return array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
'share_location' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Whether to share location data'),
'share_location' => array('type' => 'bool', 'default' => true, 'description' => 'Whether to share location data'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
+24 -7
Ver Arquivo
@@ -1,9 +1,26 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
/**
* Table Definition for user_username
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class User_username extends Managed_DataObject
{
###START_AUTOCODE
@@ -23,8 +40,8 @@ class User_username extends Managed_DataObject
{
return array(
'fields' => array(
'provider_name' => array('type' => 'varchar', 'length' => 191, 'description' => 'provider name'),
'username' => array('type' => 'varchar', 'length' => 191, 'description' => 'username'),
'provider_name' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'provider name'),
'username' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'username'),
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
@@ -46,7 +63,7 @@ class User_username extends Managed_DataObject
* @param provider_name string name of the provider
* @return mixed User_username instance if the registration succeeded, false if it did not
*/
static function register($user, $username, $provider_name)
public static function register($user, $username, $provider_name)
{
$user_username = new User_username();
$user_username->user_id = $user->id;
@@ -54,9 +71,9 @@ class User_username extends Managed_DataObject
$user_username->username = $username;
$user_username->created = common_sql_now();
if($user_username->insert()){
if ($user_username->insert()) {
return $user_username;
}else{
} else {
return false;
}
}
+4 -2
Ver Arquivo
@@ -6,6 +6,7 @@
"require": {
"php": "^7.3.0",
"ext-bcmath": "*",
"ext-ctype": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-gd": "*",
@@ -16,12 +17,14 @@
"ext-simplexml": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
"ext-ctype": "*",
"apereo/phpcas": "^1.3",
"diogocomposer/xmpphp": "^3.0",
"embed/embed": "^3.4",
"ezyang/htmlpurifier": "^4.10",
"hoa/consistency": "^1.17.05.02",
"hoa/console": "^3.17",
"illuminate/database": "5.8.*",
"illuminate/events": "5.8.*",
"intervention/image": "^2.5",
"masterminds/html5": "^2.6",
"mf2/mf2": "^0.4.6",
@@ -34,7 +37,6 @@
"stomp-php/stomp-php": "^4.5.1"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "^2.9",
"phpunit/phpunit": "^8.2",
"psy/psysh": "^0.9.9"
},
+1397 -3289
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();
+75 -62
Ver Arquivo
@@ -1,13 +1,23 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
*
* Some notes...
*
* Drupal docs don't list a bool type, but it might be nice to use rather than 'tinyint'
* Note however that we use bitfields and things as well in tinyints, and PG's
* "bool" type isn't 100% compatible with 0/1 checks. Just keeping tinyints. :)
*
* decimal <-> numeric
*
* MySQL 'timestamp' columns were formerly used for 'modified' files for their
@@ -29,64 +39,67 @@
* double-check what we've been doing on postgres?
*/
$classes = array('Schema_version',
'Profile',
'Avatar',
'Sms_carrier',
'User',
'Subscription',
'Group_join_queue',
'Subscription_queue',
'Oauth_token_association',
'Notice',
'Notice_location',
'Notice_source',
'Notice_prefs',
'Reply',
'Consumer',
'Token',
'Nonce',
'Oauth_application',
'Oauth_application_user',
'Confirm_address',
'Remember_me',
'Queue_item',
'Notice_tag',
'Foreign_service',
'Foreign_user',
'Foreign_link',
'Foreign_subscription',
'Invitation',
'Profile_prefs',
'Profile_tag',
'Profile_list',
'Profile_tag_subscription',
'Profile_block',
'User_group',
'Related_group',
'Group_inbox',
'Group_member',
'File',
'File_redirection',
'File_thumbnail',
'File_to_post',
'Group_block',
'Group_alias',
'Session',
'Config',
'Profile_role',
'Location_namespace',
'Login_token',
'User_location_prefs',
'User_im_prefs',
'Conversation',
'Local_group',
'User_urlshortener_prefs',
'Old_school_prefs',
'User_username',
'Attention',
);
defined('GNUSOCIAL') || die();
$classes = [
'Schema_version',
'Profile',
'Avatar',
'Sms_carrier',
'User',
'User_group',
'Subscription',
'Group_join_queue',
'Subscription_queue',
'Consumer',
'Oauth_application',
'Oauth_token_association',
'Conversation',
'Notice',
'Notice_location',
'Notice_source',
'Notice_prefs',
'Reply',
'Token',
'Nonce',
'Oauth_application_user',
'Confirm_address',
'Remember_me',
'Queue_item',
'Notice_tag',
'Foreign_service',
'Foreign_user',
'Foreign_link',
'Foreign_subscription',
'Invitation',
'Profile_prefs',
'Profile_list',
'Profile_tag',
'Profile_tag_subscription',
'Profile_block',
'Related_group',
'Group_inbox',
'Group_member',
'File',
'File_redirection',
'File_thumbnail',
'File_to_post',
'Group_block',
'Group_alias',
'Session',
'Config',
'Profile_role',
'Location_namespace',
'Login_token',
'User_location_prefs',
'User_im_prefs',
'Local_group',
'User_urlshortener_prefs',
'Old_school_prefs',
'User_username',
'Attention'
];
foreach ($classes as $cls) {
$schema[strtolower($cls)] = call_user_func(array($cls, 'schemaDef'));
$schema[strtolower($cls)] = call_user_func([$cls, 'schemaDef']);
}
+1 -1
Ver Arquivo
@@ -36,7 +36,7 @@ VALUES
(100088, 'Orange (Poland)', '%s@orange.pl', now()),
(100089, 'Personal (Argentina)', '%s@personal-net.com.ar', now()),
(100090, 'Plus GSM (Poland)', '%s@text.plusgsm.pl', now()),
(100091, 'President\'s Choice (Canada)', '%s@txt.bell.ca', now()),
(100091, 'President''s Choice (Canada)', '%s@txt.bell.ca', now()),
(100092, 'Qwest', '%s@qwestmp.com', now()),
(100093, 'Rogers (Canada)', '%s@pcs.rogers.com', now()),
(100094, 'Sasktel (Canada)', '%s@sms.sasktel.com', now()),
+12 -6
Ver Arquivo
@@ -49,12 +49,18 @@ class AcceptHeader extends \ArrayObject
foreach ($items as $item) {
$elems = explode(';', $item);
$acceptElement = [];
$mime = current($elems);
list($type, $subtype) = explode('/', $mime);
$acceptElement['type'] = trim($type);
$acceptElement['subtype'] = trim($subtype);
$acceptElement['raw'] = $mime;
$mime = current($elems);
$types = explode('/', $mime);
if (!isset($types[1])) {
continue;
}
$acceptElement = [
'raw' => $mime,
'type' => trim($types[0]),
'subtype' => trim($types[1]),
];
$acceptElement['params'] = [];
while (next($elems)) {
+47 -3
Ver Arquivo
@@ -1787,12 +1787,34 @@ class DB_DataObject extends DB_DataObject_Overload
// note: we dont declare this to keep the print_r size down.
$_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid] = array_flip(array_keys($array));
}
$dbtype = $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->dsn['phptype'];
if ($dbtype === 'pgsql') {
if (($_DB_DATAOBJECT['CONFIG']['db_driver'] ?? 'DB') === 'DB') {
$tableInfo = $result->tableInfo();
} elseif ($result->db->supports('result_introspection')) { // MDB2
$result->db->loadModule('Reverse', null, true);
$tableInfo = $result->db->reverse->tableInfo($result);
}
}
$replace = array('.', ' ');
foreach ($array as $k => $v) {
foreach (array_keys($array) as $i => $k) {
// use strpos as str_replace is slow.
$kk = (strpos($k, '.') === false && strpos($k, ' ') === false) ?
$k : str_replace($replace, '_', $k);
if ($dbtype === 'pgsql') {
switch ($tableInfo[$i]['type']) {
case 'bool':
$array[$k] = str_replace(['t', 'f'], ['1', '0'], $array[$k]);
break;
case 'bytea':
$array[$k] = pg_unescape_bytea($array[$k]);
break;
}
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("$kk = " . $array[$k], "fetchrow LINE", 3);
}
@@ -2418,7 +2440,7 @@ class DB_DataObject extends DB_DataObject_Overload
case 'pgsql':
if (!$seq) {
$seq = $DB->getSequenceName(strtolower($this->tableName()));
$seq = $DB->getSequenceName(strtolower($this->tableName() . '_' . $key));
}
$db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver'];
$method = ($db_driver == 'DB') ? 'getOne' : 'queryOne';
@@ -2949,12 +2971,34 @@ class DB_DataObject extends DB_DataObject_Overload
$this->raiseError("fetchrow: No results available", DB_DATAOBJECT_ERROR_NODATA);
return false;
}
$dbtype = $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->dsn['phptype'];
if ($dbtype === 'pgsql') {
if (($_DB_DATAOBJECT['CONFIG']['db_driver'] ?? 'DB') === 'DB') {
$tableInfo = $result->tableInfo();
} elseif ($result->db->supports('result_introspection')) { // MDB2
$result->db->loadModule('Reverse', null, true);
$tableInfo = $result->db->reverse->tableInfo($result);
}
}
$replace = array('.', ' ');
foreach ($array as $k => $v) {
foreach (array_keys($array) as $i => $k) {
// use strpos as str_replace is slow.
$kk = (strpos($k, '.') === false && strpos($k, ' ') === false) ?
$k : str_replace($replace, '_', $k);
if ($dbtype === 'pgsql') {
switch ($tableInfo[$i]['type']) {
case 'bool':
$array[$k] = str_replace(['t', 'f'], ['1', '0'], $array[$k]);
break;
case 'bytea':
$array[$k] = pg_unescape_bytea($array[$k]);
break;
}
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("$kk = " . $array[$k], "fetchrow LINE", 3);
}
+22 -43
Ver Arquivo
@@ -1,36 +1,31 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Base class for all actions (~views)
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Action
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Base class for all actions
@@ -41,14 +36,11 @@ if (!defined('GNUSOCIAL')) {
* Actions are responsible for extracting and validating parameters; using
* model classes to read and write to the database; and doing ouput.
*
* @category Output
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @category Output
* @copyright 2008 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see HTMLOutputter
* @see HTMLOutputter
*/
class Action extends HTMLOutputter // lawsuit
{
@@ -1566,19 +1558,6 @@ class Action extends HTMLOutputter // lawsuit
// needs to be defined by the class
}
/**
* This is a cheap hack to avoid a bug in DB_DataObject
* where '' is non-type-aware compared to 0, which means it
* will always be true for values like false and 0 too...
*
* Upstream bug is::
* https://pear.php.net/bugs/bug.php?id=20291
*/
public function booleanintstring($key, $def = false)
{
return $this->boolean($key, $def) ? '1' : '0';
}
/**
* Integer value of an argument
*
@@ -32,7 +32,7 @@ if (!defined('GNUSOCIAL')) {
exit(1);
}
require_once(INSTALLDIR . '/lib/activitystreamjsondocument.php');
require_once INSTALLDIR . '/lib/activitystreams/activitystreamjsondocument.php';
/**
* A noun-ish thing in the activity universe
@@ -359,7 +359,7 @@ class UserActivityStream extends AtomUserNoticeFeed
function writeJSON($handle)
{
require_once INSTALLDIR.'/lib/activitystreamjsondocument.php';
require_once INSTALLDIR . '/lib/activitystreams/activitystreamjsondocument.php';
fwrite($handle, '{"items": [');
$this->renderEntries(Feed::JSON, $handle);
fwrite($handle, ']}');
@@ -16,7 +16,7 @@
defined('STATUSNET') || die();
require_once INSTALLDIR . '/lib/form.php';
require_once INSTALLDIR . '/lib/util/form.php';
/**
* Form for enabling a plugin

Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais