33 Commits

Autor SHA1 Mensagem Data
Diogo Cordeiro abc2315af6 [OverwriteThemeBackground] This new plugin will let the admin set a custom background theme independent 2019-08-21 19:02:24 +01:00
Diogo Cordeiro 67a08833ef [ExtendedProfile] Fix Admin menu option 2019-08-21 19:02:23 +01:00
Diogo Cordeiro b7ec6811cf [MODULES] Allow to delete third party plugins 2019-08-21 17:00:09 +01:00
Diogo Cordeiro e498c04e4d [MODULES] Allow to upload third party plugins
Fixed some bugs
2019-08-21 17:00:09 +01:00
Diogo Cordeiro 5d62118dc2 [MODULES] List all available plugins and allow enabling them via UI
Yet another revision of the Admin Plugin Management tool
2019-08-21 17:00:09 +01:00
Diogo Cordeiro fb13624d6e [DOCUMENTATION][DEVELOPERS][PLUGINS] Some updates to Plugins doc 2019-08-21 17:00:09 +01:00
Diogo Cordeiro 3fc86e6535 [TagCloud] Add Readme 2019-08-21 17:00:08 +01:00
Diogo Cordeiro 3ebf4db632 [SearchSub][README] No longer is a default plugin since 8614cd77 2019-08-21 17:00:08 +01:00
Diogo Cordeiro 91f5a9e442 [SamplePlugin] Review and update with the latest GNU social best practices 2019-08-21 17:00:08 +01:00
Diogo Cordeiro 1e63aeb4f2 [ConversationTree] Format the plugin, add strict typing and fix docblocks 2019-08-21 17:00:07 +01:00
Diogo Cordeiro 7c93c34d66 [OfflineBackup] Fix plugin 2019-08-21 17:00:07 +01:00
Diogo Cordeiro 3bdba42c08 [PLUGINS] Removed OpenX as the service doesn't exist anymore 2019-08-21 17:00:07 +01:00
Diogo Cordeiro bdde933224 [GroupFavorited] Fix plugin 2019-08-21 17:00:07 +01:00
Diogo Cordeiro ca8312b592 [ExtendedProfile] Hide 'Extra fields' from profile when no field was created by the sysadmin 2019-08-21 17:00:07 +01:00
Diogo Cordeiro 7c4f254881 [ExtendedProfile] Allow to delete custom profile field 2019-08-21 17:00:06 +01:00
Diogo Cordeiro e88f99b3e1 [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-21 17:00:03 +01:00
Diogo Cordeiro 57dd6ff9e7 [GNUsocialProfileExtensions] Fixed plugin 2019-08-21 16:54:51 +01:00
Diogo Cordeiro 7abfb17ac4 [PLUGINS] Removed GNUsocial{Photo, Photos, Video} as we don't need them anymore 2019-08-21 16:54:51 +01:00
Diogo Cordeiro 6a8d4893fc [PLUGINS] Removed GeoURL as the service doesn't exist anymore 2019-08-21 16:54:50 +01:00
Diogo Cordeiro 4f78b89b90 [ForceGroup] Modernized plugin and improved documentation 2019-08-21 16:54:50 +01:00
Diogo Cordeiro e35c351c62 [DEFAULT] Add 'DirectionDetector' as a default plugin 2019-08-21 16:54:50 +01:00
Diogo Cordeiro 7c1a4c5e69 [ChooseTheme] Fixed plugin 2019-08-21 16:54:50 +01:00
Diogo Cordeiro c62c3051d1 [BlankAd] Fixed plugin 2019-08-21 16:54:49 +01:00
Diogo Cordeiro 72e685dfb9 [Awesomeness] Fixed plugin 2019-08-21 16:54:49 +01:00
Diogo Cordeiro d56659beec [DEFAULT] Add 'AccountManager' as a default plugin 2019-08-21 16:54:49 +01:00
Diogo Cordeiro dd01794049 [CORE] Core modules shouldn't show up in version action 2019-08-21 16:54:49 +01:00
Diogo Cordeiro 6aec5e00ba [CORE] Plugin API now extends a new Module API 2019-08-21 16:54:49 +01:00
Diogo Cordeiro 9fe1cae1ac [PLUGIN API] Bug fixes and improvements 2019-08-21 16:54:48 +01:00
Diogo Cordeiro 6c92c6dac2 [CORE] Move plugin superclasses from /lib/ to /lib/modules/ 2019-08-21 16:54:48 +01:00
Diogo Cordeiro 3b61c399ee [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-21 16:54:48 +01:00
Miguel Dantas 90487bd67c [Embed] Added support for inline images 2019-08-21 16:54:47 +01:00
tenma fb2ef68910 [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-21 16:54:47 +01:00
tenma ff406a9526 [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.
2019-08-21 16:54:47 +01:00
2237 arquivos alterados com 12583 adições e 182276 exclusões
-13
Ver Arquivo
@@ -1496,16 +1496,3 @@ 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,8 +17,13 @@ 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."
+10 -6
Ver Arquivo
@@ -164,9 +164,10 @@ 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
'mysqli' or 'pgsql' or 'mysql', 'username' is the username, 'password' is
the password, and etc.
'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.
* `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.
@@ -177,9 +178,12 @@ 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.
* `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.
* `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.
* `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,16 +43,10 @@ server {
location ~ ^/(index|install)\.php(/.*)?$ {
#location ^~ /index.php {
include fastcgi_params;
include snippets/fastcgi-php.conf;
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;
fastcgi_pass unix:/run/php/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
# 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/profile/togglepeopletag.php';
require_once INSTALLDIR . '/lib/togglepeopletag.php';
/**
*
+50 -38
Ver Arquivo
@@ -1,45 +1,55 @@
<?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 GNUsocial
* @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>
* @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
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('STATUSNET')) {
exit(1);
}
/**
* Returns of the lastest 20 groups for the site
*
* @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
* @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/
*/
class ApiGroupListAllAction extends ApiPrivateAuthAction
{
public $groups = null;
var $groups = null;
/**
* Take arguments for running
@@ -48,7 +58,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return boolean success flag
*/
public function prepare(array $args = [])
function prepare(array $args = array())
{
parent::prepare($args);
@@ -67,7 +77,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return void
*/
public function handle()
function handle()
{
parent::handle();
@@ -80,7 +90,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;
@@ -118,20 +128,21 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return array groups
*/
public function getGroups()
function getGroups()
{
$group = new User_group();
$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(
'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
);
$group->query($qry);
$groups = array();
while ($group->fetch()) {
@@ -148,7 +159,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return boolean true
*/
public function isReadOnly($args)
function isReadOnly($args)
{
return true;
}
@@ -158,7 +169,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return string datestamp of the site's latest group
*/
public function lastModified()
function lastModified()
{
if (!empty($this->groups) && (count($this->groups) > 0)) {
return strtotime($this->groups[0]->created);
@@ -175,9 +186,10 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
*
* @return string etag
*/
public function etag()
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/api/apilistusers.php';
require_once INSTALLDIR . '/lib/apilistusers.php';
class ApiListMembersAction extends ApiListUsersAction
{
+1 -1
Ver Arquivo
@@ -29,7 +29,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/api/apilistusers.php';
require_once INSTALLDIR . '/lib/apilistusers.php';
class ApiListSubscribersAction extends ApiListUsersAction
{
+1 -1
Ver Arquivo
@@ -35,7 +35,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/feeds/atomlistnoticefeed.php';
require_once INSTALLDIR . '/lib/atomlistnoticefeed.php';
/**
* Returns the most recent notices (default 20) posted to the list specified by ID
+67 -69
Ver Arquivo
@@ -1,20 +1,33 @@
<?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 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/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Show notice attachments
@@ -30,13 +43,7 @@ class AttachmentAction extends ManagedAction
/**
* Attachment File object to show
*/
public $attachment = null;
public $filehash = null;
public $filepath = null;
public $filesize = null;
public $mimetype = null;
public $filename = null;
var $attachment = null;
/**
* Load attributes based on database arguments
@@ -45,48 +52,41 @@ class AttachmentAction extends ManagedAction
*
* @param array $args $_REQUEST array
*
* @return bool flag
* @throws ClientException
* @throws FileNotFoundException
* @throws FileNotStoredLocallyException
* @throws InvalidFilenameException
* @throws ServerException
* @return success flag
*/
protected function prepare(array $args = [])
protected function prepare(array $args=array())
{
parent::prepare($args);
try {
if (!empty($id = $this->trimmed('attachment'))) {
$this->attachment = File::getByID($id);
} elseif (!empty($this->filehash = $this->trimmed('filehash'))) {
$this->attachment = File::getByHash($this->filehash);
} elseif (!empty($filehash = $this->trimmed('filehash'))) {
$this->attachment = File::getByHash($filehash);
}
} catch (Exception $e) {
// Not found
}
if (!$this->attachment instanceof File) {
// TRANS: Client error displayed trying to get a non-existing attachment.
$this->clientError(_m('No such attachment.'), 404);
$this->clientError(_('No such attachment.'), 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);
$filename = $this->attachment->getFileOrThumbnailPath();
if (empty($filename)) {
$this->clientError(_('Requested local URL for a file that is not stored locally.'), 404);
}
return true;
}
/**
* Is this action read-only?
*
* @return bool true
* @return boolean true
*/
public function isReadOnly($args): bool
function isReadOnly($args)
{
return true;
}
@@ -96,15 +96,15 @@ class AttachmentAction extends ManagedAction
*
* @return string title of the page
*/
public function title(): string
function title()
{
$a = new Attachment($this->attachment);
return $a->title();
}
public function showPage(): void
public function showPage()
{
if (empty($this->filepath)) {
if (empty($this->attachment->getFileOrThumbnailPath())) {
// if it's not a local file, gtfo
common_redirect($this->attachment->getUrl(), 303);
}
@@ -119,10 +119,10 @@ class AttachmentAction extends ManagedAction
*
* @return void
*/
public function showContent(): void
function showContent()
{
$ali = new Attachment($this->attachment, $this);
$ali->show();
$cnt = $ali->show();
}
/**
@@ -130,7 +130,7 @@ class AttachmentAction extends ManagedAction
*
* @return void
*/
public function showPageNoticeBlock(): void
function showPageNoticeBlock()
{
}
@@ -139,8 +139,7 @@ class AttachmentAction extends ManagedAction
*
* @return void
*/
public function showSections(): void
{
function showSections() {
$ns = new AttachmentNoticeSection($this);
$ns->show();
}
@@ -149,14 +148,13 @@ class AttachmentAction extends ManagedAction
* Last-modified date for file
*
* @return int last-modified date as unix timestamp
* @throws ServerException
*/
public function lastModified(): ?int
public function lastModified()
{
if (common_config('site', 'use_x_sendfile')) {
return null;
}
$path = $this->filepath;
$path = $this->attachment->getFileOrThumbnailPath();
if (!empty($path)) {
return filemtime($path);
} else {
@@ -171,26 +169,26 @@ class AttachmentAction extends ManagedAction
* but in decimal instead of hex.
*
* @return string etag http header
* @throws ServerException
*/
public function etag(): string
function etag()
{
if (common_config('site', 'use_x_sendfile')) {
return null;
}
$path = $this->filepath;
$path = $this->attachment->getFileOrThumbnailPath();
$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;
}
@@ -207,30 +205,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
* @throws ServerException
* @param string $filepath the absolute path to the file to send
* @param $filesize optional, calculated if unkown
*/
public function sendFile(): void
{
static function sendFile(string $filepath, $filesize) {
if (is_string(common_config('site', 'x-static-delivery'))) {
$tmp = explode(INSTALLDIR, $this->filepath);
$tmp = explode(INSTALLDIR, $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($this->filesize)) {
$this->filesize = filesize($this->filepath);
if (empty($filesize)) {
$filesize = filesize($filepath);
}
header("Content-Length: {$this->filesize}");
header("Content-Length: {$filesize}");
// header('Cache-Control: private, no-transform, no-store, must-revalidate');
$ret = @readfile($this->filepath);
$ret = @readfile($filepath);
if ($ret === false) {
common_log(LOG_ERR, "Couldn't read file at {$this->filepath}.");
} elseif ($ret !== $this->filesize) {
common_log(LOG_ERR, "Couldn't read file at {$filepath}.");
} elseif ($ret !== $filesize) {
common_log(LOG_ERR, "The lengths of the file as recorded on the DB (or on disk) for the file " .
"{$this->filepath} differ from what was sent to the user ({$this->filesize} vs {$ret}).");
"{$filepath} differ from what was sent to the user ({$filesize} vs {$ret}).");
}
}
}
+15 -4
Ver Arquivo
@@ -13,19 +13,30 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/
class Attachment_downloadAction extends AttachmentAction
{
public function showPage(): void
public function showPage()
{
// 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: {$this->mimetype}");
header("Content-Disposition: attachment; filename=\"{$this->filename}\"");
header("Content-Type: {$mimetype}");
header("Content-Disposition: attachment; filename=\"{$filename}\"");
header('Expires: 0');
header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
parent::sendFile();
AttachmentAction::sendFile($filepath, $filesize);
}
}
+41 -24
Ver Arquivo
@@ -1,20 +1,33 @@
<?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 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/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Show notice attachments
@@ -45,12 +58,10 @@ 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(): void
public function showPage()
{
// 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);
@@ -58,21 +69,27 @@ class Attachment_thumbnailAction extends AttachmentAction
} catch (UseFileAsThumbnailException $e) {
// With this exception, the file exists locally
$file = $e->file;
} catch (FileNotFoundException $e) {
$this->clientError(_m('No such attachment'), 404);
} catch(FileNotFoundException $e) {
$this->clientError(_('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: {$this->mimetype}");
header("Content-Disposition: inline; filename=\"{$this->filename}\"");
header("Content-Type: {$mimetype}");
header("Content-Disposition: inline; filename=\"{$filename}\"");
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
parent::sendFile();
AttachmentAction::sendFile($filepath, $filesize);
}
}
+18 -21
Ver Arquivo
@@ -1,20 +1,6 @@
<?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();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* View notice attachment
@@ -25,23 +11,34 @@ defined('GNUSOCIAL') || die();
*/
class Attachment_viewAction extends AttachmentAction
{
public function showPage(): void
public function showPage()
{
// 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: {$this->mimetype}");
if (in_array(common_get_mime_media($this->mimetype), ['image', 'video'])) {
header("Content-Disposition: inline; filename=\"{$this->filename}\"");
header("Content-Type: {$mimetype}");
if (in_array(common_get_mime_media($mimetype), ['image', 'video'])) {
header("Content-Disposition: inline; filename=\"{$filename}\"");
} else {
header("Content-Disposition: attachment; filename=\"{$this->filename}\"");
header("Content-Disposition: attachment; filename=\"{$filename}\"");
}
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
parent::sendFile();
AttachmentAction::sendFile($filepath, $filesize);
}
}
+100 -110
Ver Arquivo
@@ -1,40 +1,48 @@
<?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 GNUsocial
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Settings for email
*
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*
* @see Widget
*/
class EmailsettingsAction extends SettingsAction
{
/**
@@ -42,7 +50,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return string Title of the page
*/
public function title()
function title()
{
// TRANS: Title for e-mail settings.
return _('Email settings');
@@ -53,7 +61,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return instructions for use
*/
public function getInstructions()
function getInstructions()
{
// XXX: For consistency of parameters in messages, this should be a
// regular parameters, replaced with sprintf().
@@ -62,7 +70,7 @@ class EmailsettingsAction extends SettingsAction
return _('Manage how you get email from %%site.name%%.');
}
public function showScripts()
function showScripts()
{
parent::showScripts();
$this->script('emailsettings.js');
@@ -77,7 +85,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
public function showContent()
function showContent()
{
$user = $this->scoped->getUser();
@@ -98,58 +106,50 @@ 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',
['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', 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->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,15 +168,12 @@ 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');
@@ -192,7 +189,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
@@ -207,42 +204,34 @@ 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');
@@ -253,7 +242,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return Confirm_address Email address confirmation for user, or null
*/
public function getConfirmation()
function getConfirmation()
{
$confirm = new Confirm_address();
@@ -271,15 +260,15 @@ class EmailsettingsAction extends SettingsAction
{
if ($this->arg('save')) {
return $this->savePreferences();
} elseif ($this->arg('add')) {
} else if ($this->arg('add')) {
return $this->addAddress();
} elseif ($this->arg('cancel')) {
} else if ($this->arg('cancel')) {
return $this->cancelConfirmation();
} elseif ($this->arg('remove')) {
} else if ($this->arg('remove')) {
return $this->removeAddress();
} elseif ($this->arg('removeincoming')) {
} else if ($this->arg('removeincoming')) {
return $this->removeIncoming();
} elseif ($this->arg('newincoming')) {
} else if ($this->arg('newincoming')) {
return $this->newIncoming();
}
@@ -292,14 +281,14 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
public function savePreferences()
function savePreferences()
{
if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
$emailnotifysub = $this->boolean('emailnotifysub');
$emailnotifymsg = $this->boolean('emailnotifymsg');
$emailnotifynudge = $this->boolean('emailnotifynudge');
$emailnotifyattn = $this->boolean('emailnotifyattn');
$emailpost = $this->boolean('emailpost');
$emailnotifysub = $this->booleanintstring('emailnotifysub');
$emailnotifymsg = $this->booleanintstring('emailnotifymsg');
$emailnotifynudge = $this->booleanintstring('emailnotifynudge');
$emailnotifyattn = $this->booleanintstring('emailnotifyattn');
$emailpost = $this->booleanintstring('emailpost');
$user = $this->scoped->getUser();
$user->query('BEGIN');
@@ -333,7 +322,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
public function addAddress()
function addAddress()
{
$user = $this->scoped->getUser();
@@ -355,15 +344,16 @@ 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.'));
} elseif ($user->email === $email) {
} else if ($user->email == $email) {
// TRANS: Message given saving e-mail address that is already set.
throw new ClientException(_('That is already your email address.'));
} elseif ($this->emailExists($email)) {
} else if ($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;
@@ -395,7 +385,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
public function cancelConfirmation()
function cancelConfirmation()
{
$email = $this->trimmed('email');
@@ -421,7 +411,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
public function removeAddress()
function removeAddress()
{
$user = common_current_user();
@@ -435,7 +425,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);
@@ -448,7 +438,7 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
public function removeIncoming()
function removeIncoming()
{
$user = common_current_user();
@@ -458,8 +448,8 @@ class EmailsettingsAction extends SettingsAction
}
$orig = clone($user);
$user->incomingemail = 'NULL';
$user->emailpost = false;
$user->incomingemail = null;
$user->emailpost = 0;
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($orig);
@@ -472,12 +462,12 @@ class EmailsettingsAction extends SettingsAction
*
* @return void
*/
public function newIncoming()
function newIncoming()
{
$user = common_current_user();
$orig = clone($user);
$user->incomingemail = mail_new_incoming_address();
$user->emailpost = true;
$user->emailpost = 1;
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($orig);
@@ -495,7 +485,7 @@ class EmailsettingsAction extends SettingsAction
* @return boolean Whether the email already exists.
*/
public function emailExists($email)
function emailExists($email)
{
$user = common_current_user();
+45 -41
Ver Arquivo
@@ -1,51 +1,60 @@
<?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 GNUsocial
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @author Evan Prodromou <evan@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR . '/lib/profile/profilelist.php';
require_once INSTALLDIR . '/lib/groups/publicgroupnav.php';
require_once INSTALLDIR.'/lib/profilelist.php';
require_once INSTALLDIR.'/lib/publicgroupnav.php';
/**
* List of featured users
*
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*/
class FeaturedAction extends Action
{
public $page = null;
var $page = null;
public function isReadOnly($args)
function isReadOnly($args)
{
return true;
}
public function prepare(array $args = [])
function prepare(array $args = array())
{
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
@@ -53,7 +62,7 @@ class FeaturedAction extends Action
return true;
}
public function title()
function title()
{
if ($this->page == 1) {
// TRANS: Page title for first page of featured users.
@@ -65,14 +74,14 @@ class FeaturedAction extends Action
}
}
public function handle()
function handle()
{
parent::handle();
$this->showPage();
}
public function showPageNotice()
function showPageNotice()
{
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
@@ -81,16 +90,14 @@ class FeaturedAction extends Action
$this->elementEnd('div');
}
public function getInstructions()
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'));
}
public function showContent()
function showContent()
{
// XXX: Note I'm doing it this two-stage way because a raw query
// with a JOIN was *not* working. --Zach
@@ -98,6 +105,7 @@ class FeaturedAction extends Action
$featured_nicks = common_config('nickname', 'featured');
if (count($featured_nicks) > 0) {
$quoted = array();
foreach ($featured_nicks as $nick) {
@@ -107,7 +115,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($user->escapedTableName() . '.nickname ASC');
$user->orderBy(common_database_tablename('user') .'.nickname ASC');
$user->find();
@@ -130,12 +138,8 @@ 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/profile/profilelist.php';
require_once INSTALLDIR . '/lib/groups/publicgroupnav.php';
require_once(INSTALLDIR.'/lib/profilelist.php');
require_once INSTALLDIR.'/lib/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/groups/grouplist.php';
require_once INSTALLDIR.'/lib/grouplist.php';
/**
* Latest groups
+2 -2
Ver Arquivo
@@ -32,8 +32,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR . '/lib/search/searchaction.php';
require_once INSTALLDIR . '/lib/profile/profilelist.php';
//require_once INSTALLDIR.'/lib/searchaction.php';
//require_once INSTALLDIR.'/lib/profilelist.php';
/**
* Group search action class.
+57 -57
Ver Arquivo
@@ -1,41 +1,50 @@
<?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/>.
/**
* 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);
}
/**
* Make another user an admin of a group
*
* @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
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*/
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
{
public $profile = null;
public $group = null;
var $profile = null;
var $group = null;
/**
* Take arguments for running
@@ -45,7 +54,7 @@ class MakeadminAction extends RedirectingAction
* @return boolean success flag
*/
public function prepare(array $args = [])
function prepare(array $args = array())
{
parent::prepare($args);
if (!common_logged_in()) {
@@ -86,14 +95,10 @@ 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;
}
@@ -106,7 +111,7 @@ class MakeadminAction extends RedirectingAction
* @return void
*/
public function handle()
function handle()
{
parent::handle();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -120,7 +125,7 @@ class MakeadminAction extends RedirectingAction
* @return void
*/
public function makeAdmin()
function makeAdmin()
{
$member = Group_member::pkeyGet(array('group_id' => $this->group->id,
'profile_id' => $this->profile->id));
@@ -129,16 +134,14 @@ 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 = true;
$member->is_admin = 1;
$result = $member->update($orig);
@@ -147,11 +150,9 @@ 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();
@@ -160,14 +161,13 @@ 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
*/
public function defaultReturnTo()
function defaultReturnTo()
{
return common_local_url(
'groupmembers',
['nickname' => $this->group->nickname]
);
return common_local_url('groupmembers',
array('nickname' => $this->group->nickname));
}
}
+1 -3
Ver Arquivo
@@ -33,7 +33,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR . '/lib/search/searchaction.php';
require_once INSTALLDIR.'/lib/searchaction.php';
/**
* Notice search action class.
@@ -65,8 +65,6 @@ 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/util/mail.php';
require_once INSTALLDIR.'/lib/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/search/searchaction.php';
require_once INSTALLDIR . '/lib/profile/profilelist.php';
require_once INSTALLDIR.'/lib/searchaction.php';
require_once INSTALLDIR.'/lib/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/profile/peopletaglist.php';
require_once INSTALLDIR.'/lib/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/profile/profilelist.php';
require_once(INSTALLDIR.'/lib/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/profile/peopletaglist.php';
require_once INSTALLDIR.'/lib/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/profile/peopletaglist.php';
require_once INSTALLDIR.'/lib/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/profile/profilelist.php';
require_once(INSTALLDIR.'/lib/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/profile/peopletaglist.php';
require_once INSTALLDIR.'/lib/peopletaglist.php';
class PeopletagsubscriptionsAction extends Action
{
+1 -1
Ver Arquivo
@@ -16,7 +16,7 @@
defined('STATUSNET') || die();
require_once INSTALLDIR . '/lib/util/deletetree.php';
require_once INSTALLDIR . '/lib/deletetree.php';
/**
* Form for deleting a plugin
-46
Ver Arquivo
@@ -38,52 +38,6 @@ 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/util/deletetree.php';
require_once INSTALLDIR . '/lib/deletetree.php';
/**
* Plugin install action.
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/profile/peopletageditform.php';
require_once INSTALLDIR . '/lib/peopletageditform.php';
/**
* Subscription action
+132 -171
Ver Arquivo
@@ -1,38 +1,46 @@
<?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 GNUsocial
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Change profile settings
*
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*/
class ProfilesettingsAction extends SettingsAction
{
@@ -41,7 +49,7 @@ class ProfilesettingsAction extends SettingsAction
*
* @return string Title of the page
*/
public function title()
function title()
{
// TRANS: Page title for profile settings.
return _('Profile settings');
@@ -52,14 +60,14 @@ class ProfilesettingsAction extends SettingsAction
*
* @return instructions for use
*/
public function getInstructions()
function getInstructions()
{
// TRANS: Usage instructions for profile settings.
return _('You can update your personal profile info here '.
'so people know more about you.');
}
public function showScripts()
function showScripts()
{
parent::showScripts();
$this->autofocus('fullname');
@@ -72,7 +80,7 @@ class ProfilesettingsAction extends SettingsAction
*
* @return void
*/
public function showContent()
function showContent()
{
$user = $this->scoped->getUser();
@@ -90,40 +98,29 @@ 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')
? ['placeholder' => null]
: ['disabled' => 'disabled', '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')
? array('disabled' => 'disabled', 'placeholder' => null)
: array('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();
@@ -131,129 +128,97 @@ 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.
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.
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->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');
@@ -290,7 +255,7 @@ class ProfilesettingsAction extends SettingsAction
$homepage = $this->trimmed('homepage');
$bio = $this->trimmed('bio');
$location = $this->trimmed('location');
$autosubscribe = $this->boolean('autosubscribe');
$autosubscribe = $this->booleanintstring('autosubscribe');
$subscribe_policy = $this->trimmed('subscribe_policy');
$language = $this->trimmed('language');
$timezone = $this->trimmed('timezone');
@@ -301,26 +266,24 @@ 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.'));
} elseif (!is_null($fullname) && mb_strlen($fullname) > 191) {
} else if (!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).'));
} elseif (Profile::bioTooLong($bio)) {
} else if (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()
));
} elseif (!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()));
} else if (!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).'));
} elseif (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
} else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Timezone not selected.'));
} elseif (!is_null($language) && strlen($language) > 50) {
} else if (!is_null($language) && strlen($language) > 50) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Language is too long (maximum 50 characters).'));
}
@@ -328,6 +291,7 @@ 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) {
@@ -350,19 +314,21 @@ 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->boolean('private_stream');
$private_stream = $this->booleanintstring('private_stream');
} else {
// if not allowed, we set to the existing value
$private_stream = (bool) $user->private_stream;
$private_stream = $user->private_stream;
}
// $user->nickname is updated through Profile->update();
if ((bool) $user->autosubscribe != $autosubscribe
|| (bool) $user->private_stream != $private_stream
// XXX: XOR
if (($user->autosubscribe ^ $autosubscribe)
|| ($user->private_stream ^ $private_stream)
|| $user->timezone != $timezone
|| $user->language != $language
|| $user->subscribe_policy != $subscribe_policy) {
$original = clone($user);
$user->autosubscribe = $autosubscribe;
@@ -412,6 +378,7 @@ class ProfilesettingsAction extends SettingsAction
}
if (common_config('location', 'share') == 'user') {
$exists = false;
$prefs = User_location_prefs::getKV('user_id', $this->scoped->getID());
@@ -426,7 +393,7 @@ class ProfilesettingsAction extends SettingsAction
$orig = clone($prefs);
}
$prefs->share_location = $this->boolean('sharelocation');
$prefs->share_location = $this->booleanintstring('sharelocation');
if ($exists) {
$result = $prefs->update($orig);
@@ -462,11 +429,11 @@ class ProfilesettingsAction extends SettingsAction
// TRANS: Confirmation shown when user profile settings are saved.
return _('Settings saved.');
}
}
public function showAside()
{
function showAside() {
$this->elementStart('div', array('id' => 'aside_primary',
'class' => 'aside'));
@@ -476,32 +443,26 @@ class ProfilesettingsAction extends SettingsAction
if (Event::handle('StartProfileSettingsActions', array($this))) {
if ($this->scoped->hasRight(Right::BACKUPACCOUNT)) {
$this->elementStart('li');
$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->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->elementEnd('li');
}
if ($this->scoped->hasRight(Right::DELETEACCOUNT)) {
$this->elementStart('li');
$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->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->elementEnd('li');
}
if ($this->scoped->hasRight(Right::RESTOREACCOUNT)) {
$this->elementStart('li');
$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->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->elementEnd('li');
}
Event::handle('EndProfileSettingsActions', array($this));
+1 -1
Ver Arquivo
@@ -31,7 +31,7 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/account/togglepeopletag.php';
require_once INSTALLDIR . '/lib/togglepeopletag.php';
/**
* Subscription action
+57 -51
Ver Arquivo
@@ -1,45 +1,53 @@
<?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 GNUsocial
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
/**
* This class outputs a paginated list of profiles self-tagged with a given tag
*
* @category Output
* @copyright 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*
* @see Action
* @see Action
*/
class SelftagAction extends Action
{
public $tag = null;
public $page = null;
var $tag = null;
var $page = null;
/**
* For initializing members of the class.
@@ -49,7 +57,7 @@ class SelftagAction extends Action
* @return boolean true
* @throws ClientException
*/
public function prepare(array $args = [])
function prepare(array $args = [])
{
parent::prepare($args);
@@ -58,10 +66,8 @@ 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;
}
@@ -77,7 +83,7 @@ class SelftagAction extends Action
*
* @return void is read only action?
*/
public function handle()
function handle()
{
parent::handle();
$this->showPage();
@@ -88,13 +94,19 @@ class SelftagAction extends Action
* people tag and page, initalizes a ProfileList widget, and displays
* it to the user.
*/
public function showContent()
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.* ' .
@@ -113,21 +125,18 @@ class SelftagAction extends Action
' OR profile_list.private = false) ';
}
$qry .= 'ORDER BY profile_tag.modified DESC ' .
'LIMIT ' . $limit . ' OFFSET ' . $offset;
$qry .= 'ORDER BY profile_tag.modified DESC%s';
$profile->query(sprintf($qry, $this->tag));
$profile->query(sprintf($qry, $this->tag, $lim));
$ptl = new SelfTagProfileList($profile, $this); // pass the ammunition
$cnt = $ptl->show();
$this->pagination(
$this->page > 1,
$cnt > PROFILES_PER_PAGE,
$this->page,
'selftag',
['tag' => $this->tag]
);
$this->pagination($this->page > 1,
$cnt > PROFILES_PER_PAGE,
$this->page,
'selftag',
array('tag' => $this->tag));
}
/**
@@ -135,21 +144,18 @@ class SelftagAction extends Action
*
* @return string page title
*/
public function title()
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
{
public function newListItem(Profile $target)
function newListItem(Profile $target)
{
return new SelfTagProfileListItem($target, $this->action);
}
@@ -157,7 +163,7 @@ class SelfTagProfileList extends ProfileList
class SelfTagProfileListItem extends ProfileListItem
{
public function linkAttributes()
function linkAttributes()
{
$aAttrs = parent::linkAttributes();
@@ -168,7 +174,7 @@ class SelfTagProfileListItem extends ProfileListItem
return $aAttrs;
}
public function homepageAttributes()
function homepageAttributes()
{
$aAttrs = parent::linkAttributes();
@@ -179,7 +185,7 @@ class SelfTagProfileListItem extends ProfileListItem
return $aAttrs;
}
public function showTags()
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/notices/noticelist.php';
require_once INSTALLDIR.'/lib/noticelist.php';
/**
* Show a single notice
+112 -144
Ver Arquivo
@@ -1,39 +1,46 @@
<?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/>.
/**
* Settings for SMS.
* StatusNet, the distributed open-source microblogging tool
*
* @category Setting
* @package GNUsocial
* 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
* @author Evan Prodromou <evan@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Settings for SMS
*
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*
* @see SettingsAction
*/
class SmssettingsAction extends SettingsAction
{
protected function doPreparation()
@@ -49,7 +56,7 @@ class SmssettingsAction extends SettingsAction
*
* @return string Title of the page
*/
public function title()
function title()
{
// TRANS: Title for SMS settings.
return _('SMS settings');
@@ -60,7 +67,7 @@ class SmssettingsAction extends SettingsAction
*
* @return instructions for use
*/
public function getInstructions()
function getInstructions()
{
// XXX: For consistency of parameters in messages, this should be a
// regular parameters, replaced with sprintf().
@@ -69,7 +76,7 @@ class SmssettingsAction extends SettingsAction
return _('You can receive SMS messages through email from %%site.name%%.');
}
public function showScripts()
function showScripts()
{
parent::showScripts();
$this->autofocus('sms');
@@ -83,7 +90,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function showContent()
function showContent()
{
$user = $this->scoped->getUser();
@@ -100,105 +107,80 @@ 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') ?: 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')) ? $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', ['id' => 'settings_sms_incoming_email']);
$this->elementStart('fieldset', array('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');
}
@@ -208,19 +190,17 @@ 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');
@@ -233,7 +213,7 @@ class SmssettingsAction extends SettingsAction
*
* @todo very similar to EmailsettingsAction::getConfirmation(); refactor?
*/
public function getConfirmation()
function getConfirmation()
{
$confirm = new Confirm_address();
@@ -249,19 +229,20 @@ class SmssettingsAction extends SettingsAction
protected function doPost()
{
if ($this->arg('save')) {
return $this->savePreferences();
} elseif ($this->arg('add')) {
} else if ($this->arg('add')) {
return $this->addAddress();
} elseif ($this->arg('cancel')) {
} else if ($this->arg('cancel')) {
return $this->cancelConfirmation();
} elseif ($this->arg('remove')) {
} else if ($this->arg('remove')) {
return $this->removeAddress();
} elseif ($this->arg('removeincoming')) {
} else if ($this->arg('removeincoming')) {
return $this->removeIncoming();
} elseif ($this->arg('newincoming')) {
} else if ($this->arg('newincoming')) {
return $this->newIncoming();
} elseif ($this->arg('confirm')) {
} else if ($this->arg('confirm')) {
return $this->confirmCode();
}
// TRANS: Message given submitting a form with an unknown action in SMS settings.
@@ -275,7 +256,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function savePreferences()
function savePreferences()
{
$user = $this->scoped->getUser();
@@ -307,7 +288,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function addAddress()
function addAddress()
{
$user = common_current_user();
@@ -331,7 +312,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.'));
} elseif ($this->smsExists($sms)) {
} else if ($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.'));
}
@@ -354,11 +335,9 @@ 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. '.
@@ -373,7 +352,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function cancelConfirmation()
function cancelConfirmation()
{
$sms = $this->trimmed('sms');
$carrier = $this->trimmed('carrier');
@@ -400,7 +379,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function removeAddress()
function removeAddress()
{
$user = $this->scoped->getUser();
@@ -417,9 +396,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);
@@ -437,7 +416,7 @@ class SmssettingsAction extends SettingsAction
*
* @return boolean does the number exist
*/
public function smsExists($sms)
function smsExists($sms)
{
$other = User::getKV('sms', $sms);
@@ -453,7 +432,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function carrierSelect()
function carrierSelect()
{
$carrier = new Sms_carrier();
@@ -465,33 +444,22 @@ class SmssettingsAction extends SettingsAction
$this->element('label', array('for' => 'carrier'), _('Mobile carrier'));
$this->elementStart('select', array('name' => 'carrier',
'id' => 'carrier'));
$this->element(
'option',
['value' => 0],
// TRANS: Default option for mobile carrier dropdown menu in SMS settings.
_('Select a carrier')
);
$this->element('option', array('value' => 0),
// TRANS: Default option for mobile carrier dropdown menu in SMS settings.
_('Select a carrier'));
while ($carrier->fetch()) {
$this->element(
'option',
['value' => $carrier->id],
$carrier->name
);
$this->element('option', array('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');
}
@@ -503,7 +471,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function confirmCode()
function confirmCode()
{
$code = $this->trimmed('code');
@@ -520,7 +488,7 @@ class SmssettingsAction extends SettingsAction
*
* @return void
*/
public function removeIncoming()
function removeIncoming()
{
$user = common_current_user();
@@ -531,7 +499,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);
@@ -547,7 +515,7 @@ class SmssettingsAction extends SettingsAction
*
* @see Emailsettings::newIncoming
*/
public function newIncoming()
function newIncoming()
{
$user = $this->scoped->getUser();
+27 -24
Ver Arquivo
@@ -1,25 +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
* 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/>.
*/
defined('GNUSOCIAL') || die();
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
// @todo FIXME: documentation needed.
class SupAction extends Action
{
public function handle()
function handle()
{
parent::handle();
@@ -40,23 +43,21 @@ class SupAction extends Action
'updates' => $updates));
}
public function availablePeriods()
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',
['seconds' => $period]
);
$available[$period] = common_local_url('sup',
array('seconds' => $period));
}
return $available;
}
public function getUpdates($seconds)
function getUpdates($seconds)
{
$notice = new Notice();
@@ -68,7 +69,9 @@ class SupAction extends Action
$notice->query('SELECT profile_id, max(id) AS max_id ' .
'FROM ( ' .
'SELECT profile_id, id FROM notice ' .
"WHERE created > TIMESTAMP '" . $divider . "' " .
((common_config('db','type') == 'pgsql') ?
'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' :
'WHERE created > "'.$divider.'" ' ) .
') AS latest ' .
'GROUP BY profile_id');
@@ -81,7 +84,7 @@ class SupAction extends Action
return $updates;
}
public function isReadOnly($args)
function isReadOnly($args)
{
return true;
}
+1 -1
Ver Arquivo
@@ -32,7 +32,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR . '/lib/groups/grouplist.php';
require_once INSTALLDIR.'/lib/grouplist.php';
/**
* User groups page
-10
Ver Arquivo
@@ -1,10 +0,0 @@
<?php
namespace App;
class User extends \Illuminate\Database\Eloquent\Model {
protected $table = 'user';
protected $hidden = [];
public $timestamps = false;
}
-16
Ver Arquivo
@@ -1,16 +0,0 @@
<?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
@@ -1,10 +0,0 @@
<?php
namespace App;
class UserModel extends \Illuminate\Database\Eloquent\Model {
protected $table = 'user';
protected $hidden = [];
public $timestamps = false;
}
+20 -42
Ver Arquivo
@@ -1,20 +1,6 @@
<?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();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for avatar
@@ -24,20 +10,20 @@ class Avatar extends Managed_DataObject
{
public $__table = 'avatar'; // table name
public $profile_id; // int(4) primary_key not_null
public $original; // bool default_false
public $original; // tinyint(1)
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' => 'bool', 'default' => false, 'description' => 'uploaded by user or generated?'),
'original' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, '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'),
@@ -59,7 +45,7 @@ class Avatar extends Managed_DataObject
}
// We clean up the file, too
public function delete($useWhere = false)
function delete($useWhere=false)
{
$filename = $this->filename;
if (file_exists(Avatar::path($filename))) {
@@ -71,12 +57,11 @@ 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) {
@@ -92,7 +77,7 @@ class Avatar extends Managed_DataObject
return true;
}
protected static $_avatars = [];
static protected $_avatars = array();
/*
* Get an avatar by profile. Currently can't call newSize with $height
@@ -108,7 +93,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];
}
@@ -152,8 +137,7 @@ 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()) {
@@ -165,7 +149,7 @@ class Avatar extends Managed_DataObject
/**
* Where should the avatar go for this user?
*/
public static function filename($id, $extension, $size = null, $extra = null)
static function filename($id, $extension, $size=null, $extra=null)
{
if ($size) {
return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
@@ -174,7 +158,7 @@ class Avatar extends Managed_DataObject
}
}
public static function path($filename)
static function path($filename)
{
$dir = common_config('avatar', 'dir');
@@ -185,7 +169,7 @@ class Avatar extends Managed_DataObject
return $dir . $filename;
}
public static function url($filename)
static function url($filename)
{
$path = common_config('avatar', 'path');
@@ -210,21 +194,20 @@ class Avatar extends Managed_DataObject
return $protocol.'://'.$server.$path.$filename;
}
public function displayUrl()
function displayUrl()
{
return Avatar::url($this->filename);
}
public static function urlByProfile(Profile $target, $width = null, $height = null)
{
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);
}
}
public static function defaultImage($size = null)
static function defaultImage($size=null)
{
if (is_null($size)) {
$size = AVATAR_PROFILE_SIZE;
@@ -235,8 +218,7 @@ class Avatar extends Managed_DataObject
return Theme::path('default-avatar-'.$sizenames[$size].'.png');
}
public static function newSize(Profile $target, $width)
{
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
@@ -249,12 +231,8 @@ 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/util/mail.php';
require_once(INSTALLDIR . '/lib/mail.php');
return mail_to_user($this->getProfile()->getUser(), $subject, $body, $args['headers'], $this->getAddress());
}
+31 -33
Ver Arquivo
@@ -1,32 +1,35 @@
<?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 GNUsocial
* @package StatusNet
* @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 https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
class Conversation extends Managed_DataObject
{
@@ -54,14 +57,14 @@ class Conversation extends Managed_DataObject
);
}
public static function beforeSchemaUpdate()
static public 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'] ?? false) {
if ($schemadef['fields']['id']['auto_increment']) {
// since we already have auto incrementing ('serial') we can continue
return;
}
@@ -88,7 +91,7 @@ class Conversation extends Managed_DataObject
*
* @return Conversation the new conversation DO
*/
public static function create(ActivityContext $ctx = null, $created = null)
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();
@@ -97,16 +100,11 @@ 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)
);
// locally generated Conversation objects don't get static URLs stored
$conv->url = 'NULL';
$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
}
// This insert throws exceptions on failure
$conv->insert();
@@ -114,7 +112,7 @@ class Conversation extends Managed_DataObject
return $conv;
}
public static function noticeCount($id)
static function noticeCount($id)
{
$keypart = sprintf('conversation:notice_count:%d', $id);
@@ -134,7 +132,7 @@ class Conversation extends Managed_DataObject
return $cnt;
}
public static function getUrlFromNotice(Notice $notice, $anchor = true)
static public function getUrlFromNotice(Notice $notice, $anchor=true)
{
$conv = Conversation::getByID($notice->conversation);
return $conv->getUrl($anchor ? $notice->getID() : null);
+45 -61
Ver Arquivo
@@ -1,26 +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/>.
/**
* 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 https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*/
defined('GNUSOCIAL') || die();
@@ -245,14 +248,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
)
);
}
@@ -274,13 +277,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())';
@@ -292,13 +295,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;
@@ -309,9 +312,9 @@ class File extends Managed_DataObject
return self::tryFilename($this->filename);
}
public function getSize(): int
public function getSize()
{
return (int)$this->size;
return intval($this->size);
}
// where should the file go?
@@ -342,10 +345,8 @@ 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]);
@@ -374,7 +375,6 @@ 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,7 +433,6 @@ class File extends Managed_DataObject
* @param $filename
* @return string
* @throws InvalidFilenameException
* @throws ServerException
*/
public static function path($filename)
{
@@ -564,7 +563,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): File_thumbnail
public function getThumbnail($width=null, $height=null, $crop=false, $force_still=true, $upscale=null)
{
// Get some more information about this file through our ImageFile class
$image = ImageFile::fromFileObject($this);
@@ -603,14 +602,13 @@ 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(?File_thumbnail $thumbnail = null): string
public function getFileOrThumbnailPath($thumbnail = null) : string
{
if (!empty($thumbnail)) {
return $thumbnail->getPath();
@@ -634,15 +632,13 @@ 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(?File_thumbnail $thumbnail = null) : string
public function getFileOrThumbnailMimetype($thumbnail = null) : string
{
if (!empty($thumbnail)) {
$filepath = $thumbnail->getPath();
@@ -662,18 +658,17 @@ 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(?File_thumbnail $thumbnail = null) : int
public function getFileOrThumbnailSize($thumbnail = null) : int
{
if (!empty($thumbnail)) {
return filesize($thumbnail->getPath());
} elseif (!empty($this->filename)) {
return $this->getSize();
return $this->size;
} else {
return filesize(File_thumbnail::byFile($this)->getPath());
}
@@ -803,7 +798,7 @@ class File extends Managed_DataObject
public function noticeCount()
{
$cacheKey = sprintf('file:notice-count:%d', $this->id);
$count = self::cacheGet($cacheKey);
if ($count === false) {
@@ -893,11 +888,7 @@ 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(*) FROM %1$s ' .
'WHERE LENGTH(url) > 191 GROUP BY id, shortenedurl HAVING COUNT(*) > 1',
common_database_tablename($table)
));
$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)));
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
@@ -950,20 +941,13 @@ class File extends Managed_DataObject
$tablefix = new $classname;
// urlhash is hash('sha256', $url) in the File table
echo "Updating urlhash fields in $table table...";
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.');
}
// Maybe very MySQL specific :(
$tablefix->query(sprintf(
'UPDATE %1$s SET urlhash = %2$s;',
$tablefix->escapedTableName(),
$url_sha256
'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)'
));
echo "DONE.\n";
echo "Resuming core schema upgrade...";
+82 -115
Ver Arquivo
@@ -1,24 +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
* 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/>.
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for file_redirection
*/
class File_redirection extends Managed_DataObject
{
###START_AUTOCODE
@@ -50,18 +54,17 @@ 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')),
),
);
}
public static function getByUrl($url)
static public function getByUrl($url)
{
return self::getByPK(array('urlhash' => File::hashurl($url)));
}
public static function _commonHttp($url, $redirs)
{
static function _commonHttp($url, $redirs) {
$request = new HTTPClient($url);
$request->setConfig(array(
'connect_timeout' => 10, // # seconds to wait
@@ -93,13 +96,10 @@ class File_redirection extends Managed_DataObject
* size (optional): byte size from Content-Length header
* time (optional): timestamp from Last-Modified header
*/
public static function lookupWhere($short_url, $redirs = 10, $protected = false)
{
if ($redirs < 0) {
return false;
}
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,20 +142,12 @@ 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;
}
@@ -172,8 +164,7 @@ 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
*/
public static function where($in_url, $discover = true)
{
static function where($in_url, $discover=true) {
$redir = new File_redirection();
$redir->url = $in_url;
$redir->urlhash = File::hashurl($redir->url);
@@ -188,16 +179,14 @@ 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 {
@@ -205,15 +194,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);
}
@@ -223,32 +212,29 @@ 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) {
@@ -257,12 +243,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;
@@ -282,7 +268,7 @@ class File_redirection extends Managed_DataObject
* @param User $user whose shortening options to use; defaults to the current web session user
* @return string
*/
public static function makeShort($long_url, $user = null)
static function makeShort($long_url, $user=null)
{
$canon = File_redirection::_canonUrl($long_url);
@@ -307,7 +293,7 @@ class File_redirection extends Managed_DataObject
* @return string
*/
public static function forceShort($long_url, $user)
static function forceShort($long_url, $user)
{
$canon = File_redirection::_canonUrl($long_url);
@@ -317,8 +303,7 @@ class File_redirection extends Managed_DataObject
return !empty($short_url) ? $short_url : $long_url;
}
public static function _userMakeShort($long_url, User $user = null, $force = false)
{
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;
@@ -358,11 +343,8 @@ class File_redirection extends Managed_DataObject
* @param string $default_scheme if given a bare link; defaults to 'http://'
* @return string
*/
public static function _canonUrl($in_url, $default_scheme = 'http://')
{
if (empty($in_url)) {
return false;
}
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'])) {
@@ -395,17 +377,13 @@ 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 .= '/';
}
@@ -414,8 +392,7 @@ class File_redirection extends Managed_DataObject
return $out_url;
}
public static function saveNew($data, $file_id, $url)
{
static function saveNew($data, $file_id, $url) {
$file_redir = new File_redirection;
$file_redir->urlhash = File::hashurl($url);
$file_redir->url = $url;
@@ -425,7 +402,7 @@ class File_redirection extends Managed_DataObject
$file_redir->insert();
}
public static function beforeSchemaUpdate()
static public function beforeSchemaUpdate()
{
$table = strtolower(get_called_class());
$schema = Schema::get();
@@ -439,16 +416,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'] = [
'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)',
];
$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)',
);
unset($schemadef['primary key']);
$schema->ensureTable($table, $schemadef);
echo "DONE.\n";
@@ -457,27 +434,17 @@ 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...";
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
));
// 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)'));
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);
}
+34 -41
Ver Arquivo
@@ -1,29 +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/>.
/*
* @copyright 2008-2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* 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/>.
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for file_thumbnail
*/
class File_thumbnail extends Managed_DataObject
{
public $__table = 'file_thumbnail'; // table name
@@ -45,8 +44,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', 'not null' => true, 'description' => 'width of thumbnail'),
'height' => array('type' => 'int', 'not null' => true, 'description' => 'height of thumbnail'),
'width' => array('type' => 'int', 'description' => 'width of thumbnail'),
'height' => array('type' => 'int', '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'),
@@ -66,26 +65,21 @@ 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
);
} elseif ($data->type == 'photo') {
self::saveThumbnail($file_id,
$data->thumbnail_url,
$data->thumbnail_width,
$data->thumbnail_height);
} else if ($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);
}
}
@@ -98,8 +92,7 @@ class File_thumbnail extends Managed_DataObject
* @return File_thumbnail
* @throws NoResultException if no File_thumbnail matched the criteria
*/
public static function byFile(File $file, $notNullUrl = true)
{
static function byFile(File $file, $notNullUrl=true) {
$thumb = new File_thumbnail();
$thumb->file_id = $file->getID();
if ($notNullUrl) {
@@ -123,7 +116,7 @@ class File_thumbnail extends Managed_DataObject
* @param int $width
* @param int $height
*/
public static function saveThumbnail($file_id, $url, $width, $height, $filename = null)
static function saveThumbnail($file_id, $url, $width, $height, $filename=null)
{
$tn = new File_thumbnail;
$tn->file_id = $file_id;
@@ -135,7 +128,7 @@ class File_thumbnail extends Managed_DataObject
return $tn;
}
public static function path($filename)
static function path($filename)
{
File::tryFilename($filename);
@@ -149,7 +142,7 @@ class File_thumbnail extends Managed_DataObject
return $dir . $filename;
}
public static function url($filename)
static function url($filename)
{
File::tryFilename($filename);
@@ -283,7 +276,7 @@ class File_thumbnail extends Managed_DataObject
return $this->file_id;
}
public static function hashurl($url)
static public function hashurl($url)
{
if (!mb_strlen($url)) {
throw new Exception('No URL provided to hash algorithm.');
+7 -24
Ver Arquivo
@@ -1,21 +1,4 @@
<?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
*/
@@ -40,7 +23,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', 'not null' => true, 'description' => 'remote or local group to join, if any'),
'group_id' => array('type' => 'int', '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'),
@@ -65,27 +48,27 @@ class Group_join_queue extends Managed_DataObject
return $rq;
}
public function getMember()
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;
}
public function getGroup()
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;
@@ -94,7 +77,7 @@ class Group_join_queue extends Managed_DataObject
/**
* Abort the pending group join...
*/
public function abort()
function abort()
{
$profile = $this->getMember();
$group = $this->getGroup();
@@ -110,7 +93,7 @@ class Group_join_queue extends Managed_DataObject
*
* @return Group_member object on success
*/
public function complete()
function complete()
{
$join = null;
$profile = $this->getMember();
+21 -46
Ver Arquivo
@@ -1,21 +1,4 @@
<?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
*/
@@ -28,7 +11,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; // bool default_false
public $is_admin; // tinyint(1)
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
@@ -42,7 +25,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' => 'bool', 'default' => false, 'description' => 'is this user an admin?'),
'is_admin' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, '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'),
@@ -71,22 +54,20 @@ 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
*/
public static function join($group_id, $profile_id)
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();
@@ -99,7 +80,7 @@ class Group_member extends Managed_DataObject
return $member;
}
public static function leave($group_id, $profile_id)
static function leave($group_id, $profile_id)
{
$member = Group_member::pkeyGet(array('group_id' => $group_id,
'profile_id' => $profile_id));
@@ -120,27 +101,27 @@ class Group_member extends Managed_DataObject
return true;
}
public function getMember()
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;
}
public function getGroup()
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;
@@ -156,7 +137,7 @@ class Group_member extends Managed_DataObject
* @return Group_member stream of memberships, use fetch() to iterate
*/
public static function byMember($memberId, $offset = 0, $limit = GROUPS_PER_PAGE)
static function byMember($memberId, $offset=0, $limit=GROUPS_PER_PAGE)
{
$membership = new Group_member();
@@ -171,7 +152,7 @@ class Group_member extends Managed_DataObject
return $membership;
}
public function asActivity()
function asActivity()
{
$member = $this->getMember();
@@ -199,19 +180,13 @@ 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',
[
'profile' => $member->id,
'group' => $group->id,
]
);
$url = common_local_url('AtomPubShowMembership',
array('profile' => $member->id,
'group' => $group->id));
$act->selfLink = $url;
$act->editLink = $url;
@@ -228,7 +203,7 @@ class Group_member extends Managed_DataObject
mail_notify_group_join($this->getGroup(), $this->getMember());
}
public function getUri()
function getUri()
{
return $this->uri ?: self::newUri($this->getMember(), $this->getGroup()->getProfile(), $this->created);
}
+75 -102
Ver Arquivo
@@ -1,31 +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
* 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/>.
*/
/**
* Wrapper for Memcached_DataObject which knows its own schema definition.
* Builds its own damn settings from a schema definition.
*
* @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
* @author Brion Vibber <brion@status.net>
*/
defined('GNUSOCIAL') || die();
abstract class Managed_DataObject extends Memcached_DataObject
{
/**
@@ -45,7 +42,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return get_called_class() object if found, or null for no hits
*
*/
public static function getKV($k, $v = null)
static function getKV($k,$v=NULL)
{
return parent::getClassKV(get_called_class(), $k, $v);
}
@@ -62,12 +59,12 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return get_called_class() object if found, or null for no hits
*
*/
public static function pkeyGet(array $kv)
static function pkeyGet(array $kv)
{
return parent::pkeyGetClass(get_called_class(), $kv);
}
public static function pkeyCols()
static function pkeyCols()
{
return parent::pkeyColsClass(get_called_class());
}
@@ -81,10 +78,10 @@ abstract class Managed_DataObject extends Memcached_DataObject
*
* @return array Array of objects, in order
*/
public static function multiGet($keyCol, array $keyVals, $skipNulls = true)
{
return parent::multiGetClass(get_called_class(), $keyCol, $keyVals, $skipNulls);
}
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
@@ -95,10 +92,10 @@ abstract class Managed_DataObject extends Memcached_DataObject
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
public static function pivotGet($keyCol, array $keyVals, array $otherCols = [])
{
return parent::pivotGetClass(get_called_class(), $keyCol, $keyVals, $otherCols);
}
static function pivotGet($keyCol, array $keyVals, array $otherCols=array())
{
return parent::pivotGetClass(get_called_class(), $keyCol, $keyVals, $otherCols);
}
/**
* Get a multi-instance object
@@ -113,7 +110,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* Exception is thrown when no entries are found.
*
*/
public static function listFind($keyCol, array $keyVals)
static function listFind($keyCol, array $keyVals)
{
return parent::listFindClass(get_called_class(), $keyCol, $keyVals);
}
@@ -131,7 +128,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return array with an get_called_class() object for each $keyVals entry
*
*/
public static function listGet($keyCol, array $keyVals)
static function listGet($keyCol, array $keyVals)
{
return parent::listGetClass(get_called_class(), $keyCol, $keyVals);
}
@@ -152,11 +149,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
*/
public function keys()
function keys()
{
return array_keys($this->keyTypes());
}
@@ -170,7 +167,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return array (column,use_native,sequence_name)
*/
public function sequenceKey()
function sequenceKey()
{
$table = static::schemaDef();
foreach ($table['fields'] as $name => $column) {
@@ -194,7 +191,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @return array key definitions
*/
public function keyTypes()
function keyTypes()
{
$table = static::schemaDef();
$keys = array();
@@ -221,17 +218,16 @@ abstract class Managed_DataObject extends Memcached_DataObject
* @param array $column
* @return int
*/
public function columnBitmap($column)
function columnBitmap($column)
{
$type = $column['type'];
// For quoting style...
$intTypes = [
'int',
'float',
'serial',
'numeric'
];
$intTypes = array('int',
'integer',
'float',
'serial',
'numeric');
if (in_array($type, $intTypes)) {
$style = DB_DATAOBJECT_INT;
} else {
@@ -239,15 +235,12 @@ abstract class Managed_DataObject extends Memcached_DataObject
}
// Data type formatting style...
$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,
];
$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);
if (isset($formatStyles[$type])) {
$style |= $formatStyles[$type];
@@ -261,7 +254,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
return $style;
}
public function links()
function links()
{
$links = array();
@@ -283,10 +276,8 @@ 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
*/
public function _allCacheKeys()
function _allCacheKeys()
{
$table = static::schemaDef();
$ckeys = array();
@@ -331,7 +322,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
*/
public static function getByPK(array $vals)
static function getByPK(array $vals)
{
$classname = get_called_class();
@@ -365,7 +356,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
*/
public static function getByKeys(array $vals)
static function getByKeys(array $vals)
{
$classname = get_called_class();
@@ -390,7 +381,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
return $object;
}
public static function getByID($id)
static function getByID($id)
{
if (!property_exists(get_called_class(), 'id')) {
throw new ServerException('Trying to get undefined property of dataobject class.');
@@ -403,7 +394,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
return static::getByPK(array('id' => $id));
}
public static function getByUri($uri)
static function getByUri($uri)
{
if (!property_exists(get_called_class(), 'uri')) {
throw new ServerException('Trying to get undefined property of dataobject class.');
@@ -496,18 +487,14 @@ 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!
/**
* "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
* @param DB_DataObject &$orig Must be "instanceof" $this
* @param string $pid Primary ID column (no escaping is done on column name!)
*/
public function updateWithKeys(Managed_DataObject $orig, ?string $pid = null)
public function updateWithKeys(Managed_DataObject $orig, $pid=null)
{
if (!$orig instanceof $this) {
throw new ServerException('Tried updating a DataObject with a different class than itself.');
@@ -522,20 +509,10 @@ abstract class Managed_DataObject extends Memcached_DataObject
// do it in a transaction
$this->query('BEGIN');
$parts = [];
$parts = array();
foreach ($this->keys() as $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 (strcmp($this->$k, $orig->$k) != 0) {
$parts[] = $k . ' = ' . $this->_quote($this->$k);
}
}
if (count($parts) == 0) {
@@ -560,20 +537,18 @@ abstract class Managed_DataObject extends Memcached_DataObject
$pid = $schema['primary key'];
unset($schema);
}
$pidWhere = [];
foreach ((array) $pid as $pidCol) {
$pidWhere = array();
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',
$this->escapedTableName(),
implode(', ', $parts),
implode(' AND ', $pidWhere)
);
$qry = sprintf('UPDATE %1$s SET %2$s WHERE %3$s',
common_database_tablename($this->tableName()),
implode(', ', $parts),
implode(' AND ', $pidWhere));
$result = $this->query($qry);
if ($result === false) {
@@ -601,23 +576,21 @@ abstract class Managed_DataObject extends Memcached_DataObject
return $result;
}
public static function beforeSchemaUpdate()
static public function beforeSchemaUpdate()
{
// NOOP
}
public static function newUri(Profile $actor, Managed_DataObject $object, $created = null)
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()
+83 -110
Ver Arquivo
@@ -1,25 +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/>.
/**
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
/*
* 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/>.
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
class Memcached_DataObject extends Safe_DataObject
{
@@ -32,7 +30,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
*/
public static function getClassKV($cls, $k, $v = null)
static function getClassKV($cls, $k, $v=null)
{
if (is_null($v)) {
$v = $k;
@@ -73,7 +71,7 @@ class Memcached_DataObject extends Safe_DataObject
*
* @return array Array of objects, in order
*/
public static function multiGetClass($cls, $keyCol, array $keyVals, $skipNulls = true)
static function multiGetClass($cls, $keyCol, array $keyVals, $skipNulls=true)
{
$obj = new $cls;
@@ -102,27 +100,8 @@ class Memcached_DataObject extends Safe_DataObject
$keyVals[$key] = $obj->escape($val);
}
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.');
}
// FIND_IN_SET will make sure we keep the desired order
$obj->orderBy(sprintf("FIND_IN_SET(%s, '%s')", $keyCol, implode(',', $keyVals)));
$obj->find();
return $obj;
@@ -138,7 +117,7 @@ class Memcached_DataObject extends Safe_DataObject
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
public static function pivotGetClass($cls, $keyCol, array $keyVals, array $otherCols = [])
static function pivotGetClass($cls, $keyCol, array $keyVals, array $otherCols = array())
{
if (is_array($keyCol)) {
foreach ($keyVals as $keyVal) {
@@ -151,6 +130,7 @@ class Memcached_DataObject extends Safe_DataObject
$toFetch = array();
foreach ($keyVals as $keyVal) {
if (is_array($keyCol)) {
$kv = array_combine($keyCol, $keyVal);
} else {
@@ -167,7 +147,7 @@ class Memcached_DataObject extends Safe_DataObject
} else {
$result[$keyVal] = $i;
}
} elseif (!empty($keyVal)) {
} else if (!empty($keyVal)) {
$toFetch[] = $keyVal;
}
}
@@ -227,7 +207,7 @@ class Memcached_DataObject extends Safe_DataObject
return $result;
}
public static function _inMultiKey($i, $cols, $values)
static function _inMultiKey($i, $cols, $values)
{
$types = array();
@@ -275,7 +255,7 @@ class Memcached_DataObject extends Safe_DataObject
return $query;
}
public static function pkeyColsClass($cls)
static function pkeyColsClass($cls)
{
$i = new $cls;
$types = $i->keyTypes();
@@ -292,7 +272,7 @@ class Memcached_DataObject extends Safe_DataObject
return $pkey;
}
public static function listFindClass($cls, $keyCol, array $keyVals)
static function listFindClass($cls, $keyCol, array $keyVals)
{
$i = new $cls;
$i->whereAddIn($keyCol, $keyVals, $i->columnType($keyCol));
@@ -303,7 +283,7 @@ class Memcached_DataObject extends Safe_DataObject
return $i;
}
public static function listGetClass($cls, $keyCol, array $keyVals)
static function listGetClass($cls, $keyCol, array $keyVals)
{
$pkeyMap = array_fill_keys($keyVals, array());
$result = array_fill_keys($keyVals, array());
@@ -316,7 +296,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) {
@@ -332,7 +312,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;
}
@@ -358,17 +338,15 @@ 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;
}
public function columnType($columnName)
function columnType($columnName)
{
$keys = $this->table();
if (!array_key_exists($columnName, $keys)) {
@@ -387,7 +365,7 @@ class Memcached_DataObject extends Safe_DataObject
/**
* @todo FIXME: Should this return false on lookup fail to match getKV?
*/
public static function pkeyGetClass($cls, array $kv)
static function pkeyGetClass($cls, array $kv)
{
$i = self::multicache($cls, $kv);
if ($i !== false) { // false == cache miss
@@ -417,7 +395,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
public function insert()
function insert()
{
$result = parent::insert();
if ($result) {
@@ -427,7 +405,7 @@ class Memcached_DataObject extends Safe_DataObject
return $result;
}
public function update($dataObject = false)
function update($dataObject=false)
{
if (is_object($dataObject) && $dataObject instanceof Memcached_DataObject) {
$dataObject->decache(); # might be different keys
@@ -440,19 +418,17 @@ class Memcached_DataObject extends Safe_DataObject
return $result;
}
public function delete($useWhere = false)
function delete($useWhere=false)
{
$this->decache(); # while we still have the values!
return parent::delete($useWhere);
}
public static function memcache()
{
static function memcache() {
return Cache::instance();
}
public static function cacheKey($cls, $k, $v)
{
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: ' .
@@ -462,8 +438,7 @@ class Memcached_DataObject extends Safe_DataObject
return Cache::key(strtolower($cls).':'.$k.':'.$vstr);
}
public static function getcached($cls, $k, $v)
{
static function getcached($cls, $k, $v) {
$c = self::memcache();
if (!$c) {
return false;
@@ -481,7 +456,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
public function keyTypes()
function keyTypes()
{
// ini-based classes return number-indexed arrays. handbuilt
// classes return column => keytype. Make this uniform.
@@ -497,17 +472,18 @@ 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"];
}
public function encache()
function encache()
{
$c = self::memcache();
if (!$c) {
return false;
} elseif ($this->tableName() === 'user' && is_object($this->id)) {
} else if ($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 ' .
@@ -522,7 +498,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
public function decache()
function decache()
{
$c = self::memcache();
@@ -537,7 +513,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
public function _allCacheKeys()
function _allCacheKeys()
{
$ckeys = array();
@@ -548,6 +524,7 @@ class Memcached_DataObject extends Safe_DataObject
$pval = array();
foreach ($types as $key => $type) {
assert(!empty($key));
if ($type == 'U') {
@@ -555,7 +532,7 @@ class Memcached_DataObject extends Safe_DataObject
continue;
}
$ckeys[] = self::cacheKey($this->tableName(), $key, self::valueString($this->$key));
} elseif (in_array($type, ['K', 'N'])) {
} else if ($type == 'K' || $type == 'N') {
$pkey[] = $key;
$pval[] = self::valueString($this->$key);
} else {
@@ -575,7 +552,7 @@ class Memcached_DataObject extends Safe_DataObject
return $ckeys;
}
public static function multicache($cls, $kv)
static function multicache($cls, $kv)
{
ksort($kv);
$c = self::memcache();
@@ -586,7 +563,7 @@ class Memcached_DataObject extends Safe_DataObject
}
}
public static function multicacheKey($cls, $kv)
static function multicacheKey($cls, $kv)
{
ksort($kv);
$pkeys = implode(',', array_keys($kv));
@@ -594,35 +571,30 @@ class Memcached_DataObject extends Safe_DataObject
return self::cacheKey($cls, $pkeys, $pvals);
}
public function getSearchEngine($table)
function getSearchEngine($table)
{
require_once INSTALLDIR . '/lib/search/search_engines.php';
require_once INSTALLDIR.'/lib/search_engines.php';
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.');
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);
}
} else {
// Low level exception. No need for i18n as discussed with Brion.
throw new ServerException('Unknown search type: ' . $type);
$search_engine = new PGSearch($this, $table);
}
}
return $search_engine;
}
public static function cachedQuery($cls, $qry, $expiry = 3600)
static function cachedQuery($cls, $qry, $expiry=3600)
{
$c = self::memcache();
if (!$c) {
@@ -659,7 +631,7 @@ class Memcached_DataObject extends Safe_DataObject
* @access private
* @return mixed none or PEAR_Error
*/
public function _query($string)
function _query($string)
{
if (common_config('db', 'annotate_queries')) {
$string = $this->annotateQuery($string);
@@ -708,7 +680,7 @@ class Memcached_DataObject extends Safe_DataObject
* @param string $string SQL query string
* @return string SQL query string, with a comment in it
*/
public function annotateQuery($string)
function annotateQuery($string)
{
$ignore = array('annotateQuery',
'_query',
@@ -735,7 +707,7 @@ class Memcached_DataObject extends Safe_DataObject
}
$here = $frame['class'] . '::' . $func;
break;
} elseif (isset($frame['type']) && $frame['type'] === '->') {
} else if (isset($frame['type']) && $frame['type'] == '->') {
if ($frame['object'] === $this && in_array($func, $ignore)) {
continue;
}
@@ -764,7 +736,7 @@ class Memcached_DataObject extends Safe_DataObject
// Sanitize a query for logging
// @fixme don't trim spaces in string literals
public function sanitizeQuery($string)
function sanitizeQuery($string)
{
$string = preg_replace('/\s+/', ' ', $string);
$string = trim($string);
@@ -774,7 +746,7 @@ class Memcached_DataObject extends Safe_DataObject
// We overload so that 'SET NAMES "utf8mb4"' is called for
// each connection
public function _connect()
function _connect()
{
global $_DB_DATAOBJECT, $_PEAR;
@@ -785,7 +757,7 @@ class Memcached_DataObject extends Safe_DataObject
$exists = true;
} else {
$exists = false;
}
}
// @fixme horrible evil hack!
//
@@ -822,7 +794,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');
} elseif ($DB instanceof DB_mysql || $DB instanceof MDB2_Driver_mysql) {
} else if ($DB instanceof DB_mysql || $DB instanceof MDB2_Driver_mysql) {
mysql_set_charset('utf8mb4', $conn);
}
}
@@ -838,7 +810,7 @@ class Memcached_DataObject extends Safe_DataObject
// XXX: largely cadged from DB_DataObject
public function _getDbDsnMD5()
function _getDbDsnMD5()
{
if ($this->_database_dsn_md5) {
return $this->_database_dsn_md5;
@@ -856,7 +828,7 @@ class Memcached_DataObject extends Safe_DataObject
return $sum;
}
public function _getDbDsn()
function _getDbDsn()
{
global $_DB_DATAOBJECT;
@@ -871,13 +843,14 @@ 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}"];
} elseif (!empty($options['database'])) {
} else if (!empty($options['database'])) {
$dsn = $options['database'];
}
}
@@ -890,7 +863,7 @@ class Memcached_DataObject extends Safe_DataObject
return $dsn;
}
public static function blow()
static function blow()
{
$c = self::memcache();
@@ -909,7 +882,7 @@ class Memcached_DataObject extends Safe_DataObject
return $c->delete($cacheKey);
}
public function fixupTimestamps()
function fixupTimestamps()
{
// Fake up timestamp columns
$columns = $this->table();
@@ -920,12 +893,12 @@ class Memcached_DataObject extends Safe_DataObject
}
}
public function debugDump()
function debugDump()
{
common_debug("debugDump: " . common_log_objstring($this));
}
public function raiseError($message, $type = null, $behavior = null)
function raiseError($message, $type = null, $behaviour = null)
{
$id = get_class($this);
if (!empty($this->id)) {
@@ -938,7 +911,7 @@ class Memcached_DataObject extends Safe_DataObject
throw new ServerException("[$id] DB_DataObject error [$type]: $message");
}
public static function cacheGet($keyPart)
static function cacheGet($keyPart)
{
$c = self::memcache();
@@ -951,7 +924,7 @@ class Memcached_DataObject extends Safe_DataObject
return $c->get($cacheKey);
}
public static function cacheSet($keyPart, $value, $flag = null, $expiry = null)
static function cacheSet($keyPart, $value, $flag=null, $expiry=null)
{
$c = self::memcache();
@@ -964,7 +937,7 @@ class Memcached_DataObject extends Safe_DataObject
return $c->set($cacheKey, $value, $flag, $expiry);
}
public static function valueString($v)
static function valueString($v)
{
$vstr = null;
if (is_object($v) && $v instanceof DB_DataObject_Cast) {
+276 -289
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+32 -38
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>
* @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
* @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/
*/
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
);
}
public static function getNamespacePrefs(Notice $notice, $namespace, array $topic = [])
static function getNamespacePrefs(Notice $notice, $namespace, array $topic=array())
{
if (empty($topic)) {
$prefs = new Notice_prefs();
@@ -76,13 +76,13 @@ class Notice_prefs extends Managed_DataObject
return $prefs;
}
public static function getNamespace(Notice $notice, $namespace, array $topic = [])
static function getNamespace(Notice $notice, $namespace, array $topic=array())
{
$prefs = self::getNamespacePrefs($notice, $namespace, $topic);
return $prefs->fetchAll();
}
public static function getAll(Notice $notice)
static function getAll(Notice $notice)
{
try {
$prefs = self::listFind('notice_id', array($notice->getID()));
@@ -100,17 +100,13 @@ class Notice_prefs extends Managed_DataObject
return $list;
}
public static function getTopic(Notice $notice, $namespace, $topic)
{
return self::getByPK([
'notice_id' => $notice->getID(),
'namespace' => $namespace,
'topic' => $topic,
]);
static function getTopic(Notice $notice, $namespace, $topic) {
return self::getByPK(array('notice_id' => $notice->getID(),
'namespace' => $namespace,
'topic' => $topic));
}
public static function getData(Notice $notice, $namespace, $topic, $def = null)
{
static function getData(Notice $notice, $namespace, $topic, $def=null) {
try {
$pref = self::getTopic($notice, $namespace, $topic);
} catch (NoResultException $e) {
@@ -124,8 +120,7 @@ class Notice_prefs extends Managed_DataObject
return $pref->data;
}
public static function getConfigData(Notice $notice, $namespace, $topic)
{
static function getConfigData(Notice $notice, $namespace, $topic) {
try {
$data = self::getData($notice, $namespace, $topic);
} catch (NoResultException $e) {
@@ -145,15 +140,14 @@ 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
*/
public static function setData(Notice $notice, $namespace, $topic, $data = null)
{
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 = DB_DataObject_Cast::blob($data);
$pref->data = $data;
$pref->update($orig);
}
return true;
@@ -167,7 +161,7 @@ class Notice_prefs extends Managed_DataObject
$pref->notice_id = $notice->getID();
$pref->namespace = $namespace;
$pref->topic = $topic;
$pref->data = DB_DataObject_Cast::blob($data);
$pref->data = $data;
$pref->created = common_sql_now();
if ($pref->insert() === false) {
+3 -20
Ver Arquivo
@@ -1,26 +1,9 @@
<?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
@@ -43,7 +26,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, 'default' => 0, 'description' => 'date this record was created'),
'notice_id' => array('type' => 'int', 'not null' => true, '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'),
),
+11 -26
Ver Arquivo
@@ -1,26 +1,9 @@
<?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
@@ -56,7 +39,7 @@ class Oauth_application_user extends Managed_DataObject
);
}
public static function getByUserAndToken($user, $token)
static function getByUserAndToken($user, $token)
{
if (empty($user) || empty($token)) {
return null;
@@ -73,7 +56,7 @@ class Oauth_application_user extends Managed_DataObject
return empty($result) ? null : $oau;
}
public function updateKeys(&$orig)
function updateKeys(&$orig)
{
$this->_connect();
$parts = array();
@@ -89,11 +72,13 @@ class Oauth_application_user extends Managed_DataObject
$toupdate = implode(', ', $parts);
$table = $this->tableName();
$tableName = $this->escapedTableName();
$qry = 'UPDATE ' . $tableName . ' SET ' . $toupdate .
' WHERE profile_id = ' . $orig->profile_id .
' AND application_id = ' . $orig->application_id .
" AND token = '" . $orig->token . "'";
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'";
$orig->decache();
$result = $this->query($qry);
if ($result) {
+5 -22
Ver Arquivo
@@ -1,26 +1,9 @@
<?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
@@ -36,7 +19,7 @@ class Oauth_token_association extends Managed_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
public static function getByUserAndToken($user, $token)
static function getByUserAndToken($user, $token)
{
if (empty($user) || empty($token)) {
return null;
@@ -66,8 +49,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', array('profile_id' => 'id')),
'oauth_token_association_application_fkey' => array('oauth_application', array('application_id' => 'id')),
'oauth_token_association_profile_fkey' => array('profile_id', array('profile' => 'id')),
'oauth_token_association_application_fkey' => array('application_id', array('application' => 'id')),
)
);
}
+40 -25
Ver Arquivo
@@ -1,36 +1,48 @@
<?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 GNUsocial
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Separate table for storing UI preferences
*
* @category UI
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class Old_school_prefs extends Managed_DataObject
@@ -48,14 +60,17 @@ 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' => 'bool',
'default' => true,
'stream_mode_only' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'description' => 'No conversation streams'),
'conversation_tree' => array('type' => 'bool',
'default' => true,
'conversation_tree' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'description' => 'Hierarchical tree view for conversations'),
'stream_nicknames' => array('type' => 'bool',
'default' => true,
'stream_nicknames' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'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'),
+155 -187
Ver Arquivo
@@ -1,25 +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/>.
/**
* @copyright 2008-2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
/*
* 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/>.
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for profile
@@ -83,7 +81,7 @@ class Profile extends Managed_DataObject
throw new NoSuchUserException(array('email'=>$email));
}
return $user->getProfile();
}
}
protected $_user = array();
@@ -204,16 +202,16 @@ class Profile extends Managed_DataObject
*
* @return string
*/
public function getBestName()
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.
*/
public function getStreamName()
function getStreamName()
{
$user = common_current_user();
if ($user instanceof User && $user->streamNicknames()) {
@@ -230,7 +228,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
public function getFancyName()
function getFancyName()
{
$uri = null;
try {
@@ -245,7 +243,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;
}
@@ -256,7 +254,7 @@ class Profile extends Managed_DataObject
*
* @return mixed Notice or null
*/
public function getCurrentNotice(Profile $scoped = null)
function getCurrentNotice(Profile $scoped=null)
{
try {
$notice = $this->getNotices(0, 1, 0, 0, $scoped);
@@ -273,16 +271,16 @@ class Profile extends Managed_DataObject
// Maybe we should let this through if it's handled well upstream
return null;
}
return null;
}
public function getReplies($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
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);
}
public function getTaggedNotices($tag, $offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $max_id = 0)
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.
@@ -291,39 +289,39 @@ class Profile extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
public function getNotices($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $max_id = 0, Profile $scoped = null)
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);
}
public function isMember(User_group $group)
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;
}
public function isAdmin(User_group $group)
function isAdmin(User_group $group)
{
$gm = Group_member::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id));
return (!empty($gm) && $gm->is_admin);
}
public function isPendingMember($group)
function isPendingMember($group)
{
$request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id));
return !empty($request);
}
public function getGroups($offset = 0, $limit = PROFILES_PER_PAGE)
function getGroups($offset=0, $limit=PROFILES_PER_PAGE)
{
$ids = array();
@@ -358,15 +356,14 @@ class Profile extends Managed_DataObject
}
}
public function getGroupCount()
{
function getGroupCount() {
$groups = $this->getGroups(0, null);
return $groups instanceof User_group
? $groups->N
: 0;
}
public function isTagged($peopletag)
function isTagged($peopletag)
{
$tag = Profile_tag::pkeyGet(array('tagger' => $peopletag->tagger,
'tagged' => $this->id,
@@ -374,7 +371,7 @@ class Profile extends Managed_DataObject
return !empty($tag);
}
public function canTag($tagged)
function canTag($tagged)
{
if (empty($tagged)) {
return false;
@@ -398,16 +395,16 @@ class Profile extends Managed_DataObject
if ($local) {
return true;
}
} elseif ($subs) {
} else if ($subs) {
return (Subscription::exists($this, $tagged) ||
Subscription::exists($tagged, $this));
} elseif ($remote) {
} else if ($remote) {
return true;
}
return false;
}
public function getLists(Profile $scoped = null, $offset = 0, $limit = null, $since_id = 0, $max_id = 0)
function getLists(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
{
$ids = array();
@@ -424,15 +421,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);
}
@@ -455,6 +452,7 @@ 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;
}
@@ -478,47 +476,33 @@ class Profile extends Managed_DataObject
* @return Profile_list resulting lists
*/
public function getOtherTags(Profile $scoped = null, int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
function getOtherTags(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
{
$list = new Profile_list();
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.*, 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);
$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 = FALSE ';
$qry .= 'AND profile_list.private = 0 ';
}
if ($since > 0) {
$qry .= 'AND cursor > ' . $since . ' ';
if ($since_id > 0) {
$qry .= sprintf('AND (cursor > %d) ', $since_id);
}
if ($upto > 0) {
$qry .= 'AND cursor < ' . $upto . ' ';
if ($max_id > 0) {
$qry .= sprintf('AND (cursor < %d) ', $max_id);
}
$qry .= 'ORDER BY profile_tag.modified DESC ';
@@ -531,21 +515,21 @@ class Profile extends Managed_DataObject
return $list;
}
public function getPrivateTags($offset = 0, $limit = null, $since_id = 0, $max_id = 0)
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);
}
@@ -555,13 +539,13 @@ class Profile extends Managed_DataObject
return $tags;
}
public function hasLocalTags()
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();
@@ -569,38 +553,31 @@ class Profile extends Managed_DataObject
return ($tags->N == 0) ? false : true;
}
public function getTagSubscriptions(int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
function getTagSubscriptions($offset=0, $limit=null, $since_id=0, $max_id=0)
{
$lists = new Profile_list();
$subs = new Profile_tag_subscription();
$lists->joinAdd(['id', 'profile_tag_subscription:profile_tag_id']);
$lists->joinAdd(array('id', 'profile_tag_subscription:profile_tag_id'));
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`");
}
#@fixme: postgres (round(date_part('epoch', my_date)))
$lists->selectAdd('unix_timestamp(profile_tag_subscription.created) as "cursor"');
$lists->whereAdd('profile_tag_subscription.profile_id = '.$this->id);
if ($since > 0) {
$lists->whereAdd('cursor > ' . $since);
if ($since_id>0) {
$lists->whereAdd('cursor > '.$since_id);
}
if ($upto > 0) {
$lists->whereAdd('cursor <= ' . $upto);
if ($max_id>0) {
$lists->whereAdd('cursor <= '.$max_id);
}
if ($offset >= 0 && !is_null($limit)) {
if($offset>=0 && !is_null($limit)) {
$lists->limit($offset, $limit);
}
$lists->orderBy('profile_tag_subscription.created DESC');
$lists->orderBy('"cursor" DESC');
$lists->find();
return $lists;
@@ -613,7 +590,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?
*/
public function joinGroup(User_group $group)
function joinGroup(User_group $group)
{
$join = null;
if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
@@ -639,7 +616,7 @@ class Profile extends Managed_DataObject
*
* @param User_group $group
*/
public function leaveGroup(User_group $group)
function leaveGroup(User_group $group)
{
if (Event::handle('StartLeaveGroup', array($group, $this))) {
Group_member::leave($group->id, $this->id);
@@ -650,12 +627,12 @@ class Profile extends Managed_DataObject
}
}
public function avatarUrl($size = AVATAR_PROFILE_SIZE)
function avatarUrl($size=AVATAR_PROFILE_SIZE)
{
return Avatar::urlByProfile($this, $size);
}
public function getSubscribed($offset = 0, $limit = null)
function getSubscribed($offset=0, $limit=null)
{
$subs = Subscription::getSubscribedIDs($this->id, $offset, $limit);
try {
@@ -666,7 +643,7 @@ class Profile extends Managed_DataObject
return $profiles;
}
public function getSubscribers($offset = 0, $limit = null)
function getSubscribers($offset=0, $limit=null)
{
$subs = Subscription::getSubscriberIDs($this->id, $offset, $limit);
try {
@@ -677,7 +654,7 @@ class Profile extends Managed_DataObject
return $profiles;
}
public function getTaggedSubscribers($tag, $offset = 0, $limit = null)
function getTaggedSubscribers($tag, $offset=0, $limit=null)
{
$qry =
'SELECT profile.* ' .
@@ -687,7 +664,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) {
@@ -701,7 +678,7 @@ class Profile extends Managed_DataObject
return $profile;
}
public function getTaggedSubscriptions($tag, $offset = 0, $limit = null)
function getTaggedSubscriptions($tag, $offset=0, $limit=null)
{
$qry =
'SELECT profile.* ' .
@@ -711,7 +688,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;
@@ -730,7 +707,7 @@ class Profile extends Managed_DataObject
* @param int $limit
* @return Profile
*/
public function getRequests($offset = 0, $limit = null)
function getRequests($offset=0, $limit=null)
{
// FIXME: mysql only
$subqueue = new Profile();
@@ -744,7 +721,7 @@ class Profile extends Managed_DataObject
return $subqueue;
}
public function subscriptionCount()
function subscriptionCount()
{
$c = Cache::instance();
@@ -772,7 +749,7 @@ class Profile extends Managed_DataObject
return $cnt;
}
public function subscriberCount()
function subscriberCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -784,8 +761,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);
@@ -800,12 +777,12 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
public function isSubscribed(Profile $other)
function isSubscribed(Profile $other)
{
return Subscription::exists($this, $other);
}
public function readableBy(Profile $other = null)
function readableBy(Profile $other=null)
{
// If it's not a private stream, it's readable by anyone
if (!$this->isPrivateStream()) {
@@ -816,7 +793,7 @@ class Profile extends Managed_DataObject
return is_null($other) ? false : $other->isSubscribed($this);
}
public function requiresSubscriptionApproval(Profile $other = null): bool
function requiresSubscriptionApproval(Profile $other=null): bool
{
if (!$this->isLocal()) {
// We don't know for remote users, and we'll always be able to send
@@ -841,7 +818,7 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
public function hasPendingSubscription(Profile $other)
function hasPendingSubscription(Profile $other)
{
return Subscription_queue::exists($this, $other);
}
@@ -852,13 +829,13 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
public function mutuallySubscribed(Profile $other)
function mutuallySubscribed(Profile $other)
{
return $this->isSubscribed($other) &&
$other->isSubscribed($this);
}
public function noticeCount()
function noticeCount()
{
$c = Cache::instance();
@@ -881,7 +858,7 @@ class Profile extends Managed_DataObject
return $cnt;
}
public function blowSubscriberCount()
function blowSubscriberCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -889,7 +866,7 @@ class Profile extends Managed_DataObject
}
}
public function blowSubscriptionCount()
function blowSubscriptionCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -897,7 +874,7 @@ class Profile extends Managed_DataObject
}
}
public function blowNoticeCount()
function blowNoticeCount()
{
$c = Cache::instance();
if (!empty($c)) {
@@ -905,7 +882,7 @@ class Profile extends Managed_DataObject
}
}
public static function maxBio()
static function maxBio()
{
$biolimit = common_config('profile', 'biolimit');
// null => use global limit (distinct from 0!)
@@ -915,13 +892,13 @@ class Profile extends Managed_DataObject
return $biolimit;
}
public static function bioTooLong($bio)
static function bioTooLong($bio)
{
$biolimit = self::maxBio();
return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
}
public function update($dataObject = false)
function update($dataObject=false)
{
if (is_object($dataObject) && $this->nickname != $dataObject->nickname) {
try {
@@ -969,7 +946,7 @@ class Profile extends Managed_DataObject
return $relMes;
}
public function delete($useWhere = false)
function delete($useWhere=false)
{
$this->_deleteNotices();
$this->_deleteSubscriptions();
@@ -980,11 +957,10 @@ class Profile extends Managed_DataObject
// Warning: delete() will run on the batch objects,
// not on individual objects.
$related = [
'Reply',
'Group_member',
'Profile_role',
];
$related = array('Reply',
'Group_member',
'Profile_role'
);
Event::handle('ProfileDeleteRelated', array($this, &$related));
foreach ($related as $cls) {
@@ -992,7 +968,7 @@ class Profile extends Managed_DataObject
$inst->profile_id = $this->id;
$inst->delete();
}
$this->grantRole(Profile_role::DELETED);
$localuser = User::getKV('id', $this->id);
@@ -1003,7 +979,7 @@ class Profile extends Managed_DataObject
return parent::delete($useWhere);
}
public function _deleteNotices()
function _deleteNotices()
{
$notice = new Notice();
$notice->profile_id = $this->id;
@@ -1016,7 +992,7 @@ class Profile extends Managed_DataObject
}
}
public function _deleteSubscriptions()
function _deleteSubscriptions()
{
$sub = new Subscription();
$sub->subscriber = $this->getID();
@@ -1064,14 +1040,14 @@ class Profile extends Managed_DataObject
$self->delete();
}
public function _deleteTags()
function _deleteTags()
{
$tag = new Profile_tag();
$tag->tagged = $this->id;
$tag->delete();
}
public function _deleteBlocks()
function _deleteBlocks()
{
$block = new Profile_block();
$block->blocked = $this->id;
@@ -1082,7 +1058,7 @@ class Profile extends Managed_DataObject
$block->delete();
}
public function _deleteAttentions()
function _deleteAttentions()
{
$att = new Attention();
$att->profile_id = $this->getID();
@@ -1127,7 +1103,7 @@ class Profile extends Managed_DataObject
if ($cfg == 'always') {
return true;
} elseif ($cfg == 'never') {
} else if ($cfg == 'never') {
return false;
} else { // user
$share = common_config('location', 'sharedefault');
@@ -1144,7 +1120,7 @@ class Profile extends Managed_DataObject
}
}
public function hasRole($name)
function hasRole($name)
{
$has_role = false;
if (Event::handle('StartHasRole', array($this, $name, &$has_role))) {
@@ -1156,9 +1132,10 @@ class Profile extends Managed_DataObject
return $has_role;
}
public function grantRole($name)
function grantRole($name)
{
if (Event::handle('StartGrantRole', array($this, $name))) {
$role = new Profile_role();
$role->profile_id = $this->id;
@@ -1181,20 +1158,17 @@ class Profile extends Managed_DataObject
return $result;
}
public function revokeRole($name)
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();
@@ -1203,11 +1177,7 @@ 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') {
@@ -1220,27 +1190,27 @@ class Profile extends Managed_DataObject
}
}
public function isSandboxed()
function isSandboxed()
{
return $this->hasRole(Profile_role::SANDBOXED);
}
public function isSilenced()
function isSilenced()
{
return $this->hasRole(Profile_role::SILENCED);
}
public function sandbox()
function sandbox()
{
$this->grantRole(Profile_role::SANDBOXED);
}
public function unsandbox()
function unsandbox()
{
$this->revokeRole(Profile_role::SANDBOXED);
}
public function silence()
function silence()
{
$this->grantRole(Profile_role::SILENCED);
if (common_config('notice', 'hidespam')) {
@@ -1248,7 +1218,7 @@ class Profile extends Managed_DataObject
}
}
public function silenceAs(Profile $actor)
function silenceAs(Profile $actor)
{
if (!$actor->hasRight(Right::SILENCEUSER)) {
throw new AuthorizationException(_('You cannot silence users on this site.'));
@@ -1264,7 +1234,7 @@ class Profile extends Managed_DataObject
return $this->silence();
}
public function unsilence()
function unsilence()
{
$this->revokeRole(Profile_role::SILENCED);
if (common_config('notice', 'hidespam')) {
@@ -1272,7 +1242,7 @@ class Profile extends Managed_DataObject
}
}
public function unsilenceAs(Profile $actor)
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.
@@ -1285,7 +1255,7 @@ class Profile extends Managed_DataObject
return $this->unsilence();
}
public function flushVisibility()
function flushVisibility()
{
// Get all notices
$stream = new ProfileNoticeStream($this, $this);
@@ -1331,7 +1301,8 @@ 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:
@@ -1409,7 +1380,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
public function asAtomAuthor($cur = null)
function asAtomAuthor($cur = null)
{
$xs = new XMLStringer(true);
@@ -1417,7 +1388,7 @@ class Profile extends Managed_DataObject
$xs->element('name', null, $this->nickname);
$xs->element('uri', null, $this->getUri());
if ($cur != null) {
$attrs = [];
$attrs = Array();
$attrs['following'] = $cur->isSubscribed($this) ? 'true' : 'false';
$attrs['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false';
$xs->element('statusnet:profile_info', $attrs, null);
@@ -1438,7 +1409,7 @@ class Profile extends Managed_DataObject
* @return array representation of <statusnet:profile_info> element or null
*/
public function profileInfo(Profile $scoped = null)
function profileInfo(Profile $scoped=null)
{
$profileInfoAttr = array('local_id' => $this->id);
@@ -1460,7 +1431,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
public function asActivityActor()
function asActivityActor()
{
return $this->asActivityNoun('actor');
}
@@ -1476,7 +1447,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
public function asActivityNoun($element)
function asActivityNoun($element)
{
$noun = $this->asActivityObject();
return $noun->asString('activity:' . $element);
@@ -1648,7 +1619,7 @@ class Profile extends Managed_DataObject
return $scheme ? $acct : mb_substr($acct, 5);
}
public function hasBlocked(Profile $other)
function hasBlocked(Profile $other)
{
$block = Profile_block::exists($this, $other);
return !empty($block);
@@ -1681,7 +1652,7 @@ class Profile extends Managed_DataObject
*
* @param string $uri A unique identifier for a resource (profile/group/whatever)
*/
public static function fromUri($uri)
static function fromUri($uri)
{
$profile = null;
@@ -1706,7 +1677,7 @@ class Profile extends Managed_DataObject
return $profile;
}
public function canRead(Notice $notice)
function canRead(Notice $notice)
{
if ($notice->scope & Notice::SITE_SCOPE) {
$user = $this->getUser();
@@ -1746,7 +1717,7 @@ class Profile extends Managed_DataObject
return true;
}
public static function current()
static function current()
{
$user = common_current_user();
if (empty($user)) {
@@ -1757,7 +1728,7 @@ class Profile extends Managed_DataObject
return $profile;
}
public static function ensureCurrent()
static function ensureCurrent()
{
$profile = self::current();
if (!$profile instanceof Profile) {
@@ -1776,7 +1747,7 @@ class Profile extends Managed_DataObject
* @return array of variable names to include in serialization.
*/
public function __sleep()
function __sleep()
{
$vars = parent::__sleep();
$skip = array('_user', '_group');
@@ -1831,13 +1802,11 @@ 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);
@@ -1852,8 +1821,7 @@ 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);
}
+96 -126
Ver Arquivo
@@ -1,28 +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/>.
/**
* @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
* 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/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
class Profile_list extends Managed_DataObject
{
@@ -31,7 +30,7 @@ class Profile_list extends Managed_DataObject
public $tagger; // int(4)
public $tag; // varchar(64)
public $description; // text
public $private; // bool default_false
public $private; // tinyint(1)
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
@@ -47,7 +46,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' => 'bool', 'default' => false, 'description' => 'is this tag private'),
'private' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, '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'),
@@ -59,8 +58,7 @@ class Profile_list extends Managed_DataObject
),
'primary key' => array('tagger', 'tag'),
'unique keys' => array(
'profile_list_id_key' => array('id'),
'profile_list_tag_key' => array('tag'),
'profile_list_id_key' => array('id')
),
'foreign keys' => array(
'profile_list_tagger_fkey' => array('profile', array('tagger' => 'id')),
@@ -81,7 +79,7 @@ class Profile_list extends Managed_DataObject
* @return Profile the tagger
*/
public function getTagger()
function getTagger()
{
return Profile::getByID($this->tagger);
}
@@ -93,7 +91,7 @@ class Profile_list extends Managed_DataObject
* @return String
*/
public function getBestName()
function getBestName()
{
return $this->tag;
}
@@ -104,17 +102,15 @@ class Profile_list extends Managed_DataObject
* @return String uri
*/
public function getUri()
function getUri()
{
$uri = null;
if (Event::handle('StartProfiletagGetUri', array($this, &$uri))) {
if (!empty($this->uri)) {
$uri = $this->uri;
} else {
$uri = common_local_url(
'profiletagbyid',
['id' => $this->id, 'tagger_id' => $this->tagger]
);
$uri = common_local_url('profiletagbyid',
array('id' => $this->id, 'tagger_id' => $this->tagger));
}
}
Event::handle('EndProfiletagGetUri', array($this, &$uri));
@@ -127,7 +123,7 @@ class Profile_list extends Managed_DataObject
* @return String home url
*/
public function homeUrl()
function homeUrl()
{
$url = null;
if (Event::handle('StartUserPeopletagHomeUrl', array($this, &$url))) {
@@ -135,13 +131,9 @@ class Profile_list extends Managed_DataObject
if (!empty($this->mainpage)) {
$url = $this->mainpage;
} else {
$url = common_local_url(
'showprofiletag',
[
'nickname' => $this->getTagger()->nickname,
'tag' => $this->tag,
]
);
$url = common_local_url('showprofiletag',
array('nickname' => $this->getTagger()->nickname,
'tag' => $this->tag));
}
}
Event::handle('EndUserPeopletagHomeUrl', array($this, &$url));
@@ -154,14 +146,12 @@ class Profile_list extends Managed_DataObject
* @return String permalink
*/
public function permalink()
function permalink()
{
$url = null;
if (Event::handle('StartProfiletagPermalink', array($this, &$url))) {
$url = common_local_url(
'profiletagbyid',
['id' => $this->id]
);
$url = common_local_url('profiletagbyid',
array('id' => $this->id));
}
Event::handle('EndProfiletagPermalink', array($this, &$url));
return $url;
@@ -179,7 +169,7 @@ class Profile_list extends Managed_DataObject
* @return Notice the query
*/
public function getNotices($offset, $limit, $since_id = null, $max_id = null)
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.
@@ -200,7 +190,7 @@ class Profile_list extends Managed_DataObject
* @return Profile results
*/
public function getSubscribers(int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
function getSubscribers($offset=0, $limit=null, $since=0, $upto=0)
{
$subs = new Profile();
@@ -209,15 +199,8 @@ class Profile_list extends Managed_DataObject
);
$subs->whereAdd('profile_tag_subscription.profile_tag_id = ' . $this->id);
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`");
}
$subs->selectAdd('unix_timestamp(profile_tag_subscription.' .
'created) as "cursor"');
if ($since != 0) {
$subs->whereAdd('cursor > ' . $since);
@@ -244,22 +227,24 @@ class Profile_list extends Managed_DataObject
* @return array ids of users
*/
public function getUserSubscribers()
function getUserSubscribers()
{
// XXX: cache this
$user = new User();
if(common_config('db','quote_identifiers'))
$user_table = '"user"';
else $user_table = 'user';
$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
));
$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 ';
$ids = [];
$user->query(sprintf($qry, $this->id));
$ids = array();
while ($user->fetch()) {
$ids[] = $user->id;
@@ -279,7 +264,7 @@ class Profile_list extends Managed_DataObject
* @return boolean subscription status
*/
public function hasSubscriber($id)
function hasSubscriber($id)
{
if (!is_numeric($id)) {
$id = $id->id;
@@ -303,21 +288,13 @@ class Profile_list extends Managed_DataObject
* @return Profile results
*/
public function getTagged(int $offset = 0, ?int $limit = null, int $since = 0, int $upto = 0)
function getTagged($offset=0, $limit=null, $since=0, $upto=0)
{
$tagged = new Profile();
$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`");
}
$tagged->joinAdd(array('id', 'profile_tag:tagged'));
#@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}'");
@@ -346,7 +323,7 @@ class Profile_list extends Managed_DataObject
* @return boolean success
*/
public function delete($useWhere = false)
function delete($useWhere=false)
{
// force delete one item at a time.
if (empty($this->id)) {
@@ -373,7 +350,7 @@ class Profile_list extends Managed_DataObject
* @return boolean success
*/
public function update($dataObject = false)
function update($dataObject=false)
{
if (!is_object($dataObject) && !$dataObject instanceof Profile_list) {
return parent::update($dataObject);
@@ -384,9 +361,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.'));
@@ -405,7 +382,7 @@ class Profile_list extends Managed_DataObject
* @return string atom author element
*/
public function asAtomAuthor()
function asAtomAuthor()
{
$xs = new XMLStringer(true);
@@ -427,7 +404,7 @@ class Profile_list extends Managed_DataObject
* @return string activitystreams noun
*/
public function asActivityNoun($element)
function asActivityNoun($element)
{
$noun = ActivityObject::fromPeopletag($this);
return $noun->asString('activity:' . $element);
@@ -442,13 +419,11 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
public function taggedCount($recount = false)
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);
@@ -475,16 +450,15 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
public function subscriberCount($recount = false)
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');
@@ -504,7 +478,7 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
public function blowNoticeStreamCache($all = false)
function blowNoticeStreamCache($all=false)
{
self::blow('profile_list:notice_ids:%d', $this->id);
if ($all) {
@@ -522,7 +496,7 @@ class Profile_list extends Managed_DataObject
* @return integer count
*/
public static function getByTaggerAndTag($tagger, $tag)
static function getByTaggerAndTag($tagger, $tag)
{
$ptag = Profile_list::pkeyGet(array('tagger' => $tagger, 'tag' => $tag));
return $ptag;
@@ -540,11 +514,11 @@ class Profile_list extends Managed_DataObject
* @return Profile_list the people tag object
*/
public static function ensureTag($tagger, $tag, $description = null, $private = false)
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,
@@ -570,7 +544,7 @@ class Profile_list extends Managed_DataObject
* @return integer maximum number of characters
*/
public static function maxDescription()
static function maxDescription()
{
$desclimit = common_config('peopletag', 'desclimit');
// null => use global limit (distinct from 0!)
@@ -589,7 +563,7 @@ class Profile_list extends Managed_DataObject
* @return boolean is the descripition too long?
*/
public static function descriptionTooLong($desc)
static function descriptionTooLong($desc)
{
$desclimit = self::maxDescription();
return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
@@ -604,8 +578,7 @@ class Profile_list extends Managed_DataObject
*
* @return mixed Profile_list on success, false on fail
*/
public static function saveNew(array $fields)
{
static function saveNew(array $fields) {
extract($fields);
$ptag = new Profile_list();
@@ -666,7 +639,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.'));
}
}
@@ -674,7 +647,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
@@ -714,9 +687,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.
public static function getAtCursor($fn, array $args, $cursor, $count = 20)
static function getAtCursor($fn, array $args, $cursor, $count=20)
{
$items = array();
@@ -725,12 +698,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);
}
@@ -761,14 +734,15 @@ class Profile_list extends Managed_DataObject
$next_cursor = isset($next->cursor) ?
$items[$count-1]->cursor : $items[$count-1]->id;
}
} elseif ($cursor < -1) {
} else if($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);
}
@@ -781,10 +755,7 @@ class Profile_list extends Managed_DataObject
} else {
$next_cursor = isset($items[$end]->cursor) ?
$items[$end]->cursor : $items[$end]->id;
if ($end > $count) {
// excess item
array_pop($items);
}
if ($end > $count) array_pop($items); // excess item.
// check if there are more items for next page
$fn_args = array_merge($args, array(0, 1, 0, $cursor));
@@ -800,22 +771,23 @@ class Profile_list extends Managed_DataObject
$prev_cursor = isset($prev->cursor) ?
-$items[0]->cursor : -$items[0]->id;
}
} elseif ($cursor == -1) {
} else if($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);
}
@@ -831,8 +803,7 @@ class Profile_list extends Managed_DataObject
* @return boolean success
*/
public static function setCache($ckey, &$tag, $offset = 0, $limit = null)
{
static function setCache($ckey, &$tag, $offset=0, $limit=null) {
$cache = Cache::instance();
if (empty($cache)) {
return false;
@@ -863,8 +834,8 @@ class Profile_list extends Managed_DataObject
* @return Profile_list results
*/
public static function getCached($ckey, $offset = 0, $limit = null)
{
static function getCached($ckey, $offset=0, $limit=null) {
$keys_str = self::cacheGet($ckey);
if ($keys_str === false) {
return false;
@@ -891,8 +862,7 @@ class Profile_list extends Managed_DataObject
* @return Profile_list results
*/
public static function getByKeys(array $keys)
{
static function getByKeys(array $keys) {
$cache = Cache::instance();
if (!empty($cache)) {
@@ -940,7 +910,7 @@ class Profile_list extends Managed_DataObject
}
}
public function insert()
function insert()
{
$result = parent::insert();
if ($result) {
+29 -32
Ver Arquivo
@@ -1,31 +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 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 http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*/
defined('GNUSOCIAL') || die();
class Profile_prefs extends Managed_DataObject
{
public $__table = 'profile_prefs'; // table name
@@ -57,7 +58,7 @@ class Profile_prefs extends Managed_DataObject
);
}
public static function getNamespacePrefs(Profile $profile, $namespace, array $topic = [])
static function getNamespacePrefs(Profile $profile, $namespace, array $topic=array())
{
if (empty($topic)) {
$prefs = new Profile_prefs();
@@ -75,13 +76,13 @@ class Profile_prefs extends Managed_DataObject
return $prefs;
}
public static function getNamespace(Profile $profile, $namespace, array $topic = [])
static function getNamespace(Profile $profile, $namespace, array $topic=array())
{
$prefs = self::getNamespacePrefs($profile, $namespace, $topic);
return $prefs->fetchAll();
}
public static function getAll(Profile $profile)
static function getAll(Profile $profile)
{
try {
$prefs = self::listFind('profile_id', array($profile->getID()));
@@ -99,15 +100,13 @@ class Profile_prefs extends Managed_DataObject
return $list;
}
public static function getTopic(Profile $profile, $namespace, $topic)
{
static function getTopic(Profile $profile, $namespace, $topic) {
return Profile_prefs::getByPK(array('profile_id' => $profile->getID(),
'namespace' => $namespace,
'topic' => $topic));
}
public static function getData(Profile $profile, $namespace, $topic, $def = null)
{
static function getData(Profile $profile, $namespace, $topic, $def=null) {
try {
$pref = self::getTopic($profile, $namespace, $topic);
} catch (NoResultException $e) {
@@ -121,8 +120,7 @@ class Profile_prefs extends Managed_DataObject
return $pref->data;
}
public static function getConfigData(Profile $profile, $namespace, $topic)
{
static function getConfigData(Profile $profile, $namespace, $topic) {
try {
$data = self::getData($profile, $namespace, $topic);
} catch (NoResultException $e) {
@@ -142,15 +140,14 @@ 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
*/
public static function setData(Profile $profile, $namespace, $topic, $data = null)
{
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 = DB_DataObject_Cast::blob($data);
$pref->data = $data;
$pref->update($orig);
}
return true;
@@ -164,7 +161,7 @@ class Profile_prefs extends Managed_DataObject
$pref->profile_id = $profile->getID();
$pref->namespace = $namespace;
$pref->topic = $topic;
$pref->data = DB_DataObject_Cast::blob($data);
$pref->data = $data;
$pref->created = common_sql_now();
if ($pref->insert() === false) {
+56 -87
Ver Arquivo
@@ -1,24 +1,8 @@
<?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
@@ -51,34 +35,35 @@ class Profile_tag extends Managed_DataObject
);
}
public function links()
function links()
{
return array('tagger,tag' => 'profile_list:tagger,tag');
}
public function getMeta()
function getMeta()
{
return Profile_list::pkeyGet(array('tagger' => $this->tagger, 'tag' => $this->tag));
}
public static function getSelfTagsArray(Profile $target)
static function getSelfTagsArray(Profile $target)
{
return self::getTagsArray($target->getID(), $target->getID(), $target);
}
public static function setSelfTags(Profile $target, array $newtags, array $privacy = [])
static function setSelfTags(Profile $target, array $newtags, array $privacy=array())
{
return self::setTags($target->getID(), $target->getID(), $newtags, $privacy);
}
public static function getTags($tagger, $tagged, $auth_user = null)
{
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;
}
@@ -96,7 +81,7 @@ class Profile_tag extends Managed_DataObject
$qry = sprintf($qry, $tagger, $tagged);
if (!$include_priv) {
$qry .= ' AND profile_list.private = FALSE';
$qry .= ' and profile_list.private = 0';
}
$profile_list->query($qry);
@@ -106,23 +91,20 @@ class Profile_tag extends Managed_DataObject
return $profile_list;
}
public static function getTagsArray($tagger, $tagged, Profile $scoped = null)
static function getTagsArray($tagger, $tagged, Profile $scoped=null)
{
$ptag = new Profile_tag();
$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
);
$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);
if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) {
$qry .= 'AND profile_list.private = FALSE';
$qry .= 'and profile_list.private = 0';
}
$tags = array();
@@ -136,8 +118,8 @@ class Profile_tag extends Managed_DataObject
return $tags;
}
public static function setTags($tagger, $tagged, array $newtags, array $privacy = [])
{
static function setTags($tagger, $tagged, array $newtags, array $privacy=array()) {
$newtags = array_unique($newtags);
$oldtags = self::getTagsArray($tagger, $tagged, Profile::getByID($tagger));
@@ -163,8 +145,8 @@ class Profile_tag extends Managed_DataObject
}
# set a single tag
public static function setTag($tagger, $tagged, $tag, $desc=null, $private = false)
{
static function setTag($tagger, $tagged, $tag, $desc=null, $private=false) {
$ptag = Profile_tag::pkeyGet(array('tagger' => $tagger,
'tagged' => $tagged,
'tag' => $tag));
@@ -178,6 +160,7 @@ 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.'));
@@ -189,12 +172,10 @@ 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();
@@ -204,13 +185,10 @@ 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();
@@ -243,8 +221,7 @@ class Profile_tag extends Managed_DataObject
return $newtag;
}
public static function unTag($tagger, $tagged, $tag)
{
static function unTag($tagger, $tagged, $tag) {
$ptag = Profile_tag::pkeyGet(array('tagger' => $tagger,
'tagged' => $tagged,
'tag' => $tag));
@@ -270,14 +247,13 @@ class Profile_tag extends Managed_DataObject
}
// @fixme: move this to Profile_list?
public static function cleanup($profile_list)
{
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();
@@ -290,18 +266,17 @@ class Profile_tag extends Managed_DataObject
}
// move a tag!
public static function moveTag($orig, $new)
{
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__);
@@ -310,8 +285,7 @@ class Profile_tag extends Managed_DataObject
return $result;
}
public static function blowCaches($tagger, $tagged)
{
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));
}
@@ -319,43 +293,38 @@ class Profile_tag extends Managed_DataObject
}
// Return profiles with a given tag
public static function getTagged($tagger, $tag)
{
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 = [];
'AND profile_tag.tag = "' . $profile->escape($tag) . '" ');
$tagged = array();
while ($profile->fetch()) {
$tagged[] = clone($profile);
}
return true;
}
public function insert()
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;
}
public function delete($useWhere = false)
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;
}
+48 -57
Ver Arquivo
@@ -1,25 +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/>.
/**
* @copyright 2008, 2009, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
/*
* 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/>.
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for subscription
@@ -32,8 +30,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; // bool default_true
public $sms; // bool default_true
public $jabber; // tinyint(1) default_1
public $sms; // tinyint(1) default_1
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
@@ -46,8 +44,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' => 'bool', 'default' => true, 'description' => 'deliver jabber messages'),
'sms' => array('type' => 'bool', 'default' => true, 'description' => 'deliver sms messages'),
'jabber' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'deliver jabber messages'),
'sms' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, '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'),
@@ -76,7 +74,7 @@ class Subscription extends Managed_DataObject
* @return mixed Subscription or Subscription_queue: new subscription info
*/
public static function start(Profile $subscriber, Profile $other, $force = false)
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.
@@ -119,6 +117,7 @@ class Subscription extends Managed_DataObject
$otherUser->autosubscribe &&
!self::exists($other, $subscriber) &&
!$subscriber->hasBlocked($other)) {
try {
self::start($other, $subscriber);
} catch (AlreadyFulfilledException $e) {
@@ -138,7 +137,7 @@ class Subscription extends Managed_DataObject
return $sub;
}
public static function ensureStart(Profile $subscriber, Profile $other, $force = false)
static function ensureStart(Profile $subscriber, Profile $other, $force=false)
{
try {
$sub = self::start($subscriber, $other, $force);
@@ -158,14 +157,12 @@ class Subscription extends Managed_DataObject
$sub->subscriber = $subscriber->getID();
$sub->subscribed = $other->getID();
$sub->jabber = true;
$sub->sms = true;
$sub->jabber = 1;
$sub->sms = 1;
$sub->created = common_sql_now();
$sub->uri = self::newUri(
$subscriber,
$other,
$sub->created
);
$sub->uri = self::newUri($subscriber,
$other,
$sub->created);
$result = $sub->insert();
@@ -178,7 +175,7 @@ class Subscription extends Managed_DataObject
return $sub;
}
public function notify()
function notify()
{
// XXX: add other notifications (Jabber, SMS) here
// XXX: queue this and handle it offline
@@ -187,11 +184,12 @@ class Subscription extends Managed_DataObject
$this->notifyEmail();
}
public function notifyEmail()
function notifyEmail()
{
$subscribedUser = User::getKV('id', $this->subscribed);
if ($subscribedUser instanceof User) {
$subscriber = Profile::getKV('id', $this->subscriber);
mail_subscribe_notify_profile($subscribedUser, $subscriber);
@@ -202,7 +200,7 @@ class Subscription extends Managed_DataObject
* Cancel a subscription
*
*/
public static function cancel(Profile $subscriber, Profile $other)
static function cancel(Profile $subscriber, Profile $other)
{
if (!self::exists($subscriber, $other)) {
// TRANS: Exception thrown when trying to unsibscribe without a subscription.
@@ -217,6 +215,7 @@ class Subscription extends Managed_DataObject
}
if (Event::handle('StartUnsubscribe', array($subscriber, $other))) {
$sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
'subscribed' => $other->id));
@@ -246,7 +245,7 @@ class Subscription extends Managed_DataObject
return;
}
public static function exists(Profile $subscriber, Profile $other)
static function exists(Profile $subscriber, Profile $other)
{
try {
$sub = self::getSubscription($subscriber, $other);
@@ -257,7 +256,7 @@ class Subscription extends Managed_DataObject
return true;
}
public static function getSubscription(Profile $subscriber, Profile $other)
static function getSubscription(Profile $subscriber, Profile $other)
{
// This is essentially a pkeyGet but we have an object to return in NoResultException
$sub = new Subscription();
@@ -279,7 +278,7 @@ class Subscription extends Managed_DataObject
return Profile::getByID($this->subscribed);
}
public function asActivity()
function asActivity()
{
$subscriber = $this->getSubscriber();
$subscribed = $this->getSubscribed();
@@ -294,25 +293,19 @@ 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',
[
'subscriber' => $subscriber->id,
'subscribed' => $subscribed->id,
]
);
$url = common_local_url('AtomPubShowSubscription',
array('subscriber' => $subscriber->id,
'subscribed' => $subscribed->id));
$act->selfLink = $url;
$act->editLink = $url;
@@ -363,13 +356,11 @@ 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);
}
@@ -406,7 +397,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);
@@ -435,7 +426,7 @@ class Subscription extends Managed_DataObject
*
* @return boolean success flag.
*/
public function update($dataObject = false)
function update($dataObject=false)
{
self::blow('subscription:by-subscriber:'.$this->subscriber);
self::blow('subscription:by-subscribed:'.$this->subscribed);
+126 -137
Ver Arquivo
@@ -1,20 +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/>.
/*
* 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/>.
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Table Definition for user
@@ -34,24 +37,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; // 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 $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 $language; // varchar(50)
public $timezone; // varchar(50)
public $emailpost; // bool default_true
public $emailpost; // tinyint(1) default_1
public $sms; // varchar(64) unique_key
public $carrier; // int(4)
public $smsnotify; // bool default_false
public $smsreplies; // bool default_false
public $smsnotify; // tinyint(1)
public $smsreplies; // tinyint(1)
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; // bool default_false
public $autosubscribe; // tinyint(1)
public $subscribe_policy; // tinyint(1)
public $urlshorteningservice; // varchar(50) default_ur1.ca
public $private_stream; // bool default_false
public $private_stream; // tinyint(1) default_0
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@@ -68,24 +71,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' => 'bool', 'default' => true, 'description' => 'Notify by email of subscriptions'),
'emailnotifysub' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => null, 'description' => 'Notify by email of favorites'),
'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'),
'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'),
'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
'emailpost' => array('type' => 'bool', 'default' => true, 'description' => 'Post by email'),
'emailpost' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, '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' => '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'),
'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'),
'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' => 'bool', 'default' => false, 'description' => 'automatically subscribe to users who subscribe to us'),
'autosubscribe' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, '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' => 'bool', 'default' => false, 'description' => 'whether to limit all notices to followers only'),
'private_stream' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, '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'),
),
@@ -141,7 +144,7 @@ class User extends Managed_DataObject
return $this->getProfile()->getNickname();
}
public static function getByNickname($nickname)
static function getByNickname($nickname)
{
$user = User::getKV('nickname', $nickname);
if (!$user instanceof User) {
@@ -151,12 +154,12 @@ class User extends Managed_DataObject
return $user;
}
public function isSubscribed(Profile $other)
function isSubscribed(Profile $other)
{
return $this->getProfile()->isSubscribed($other);
}
public function hasPendingSubscription(Profile $other)
function hasPendingSubscription(Profile $other)
{
return $this->getProfile()->hasPendingSubscription($other);
}
@@ -166,17 +169,17 @@ class User extends Managed_DataObject
*
* @return mixed Notice or null
*/
public function getCurrentNotice()
function getCurrentNotice()
{
return $this->getProfile()->getCurrentNotice();
}
public function getCarrier()
function getCarrier()
{
return Sms_carrier::getKV('id', $this->carrier);
}
public function hasBlocked(Profile $other)
function hasBlocked(Profile $other)
{
return $this->getProfile()->hasBlocked($other);
}
@@ -203,9 +206,10 @@ class User extends Managed_DataObject
* @return User object
* @throws Exception on failure
*/
public static function register(array $fields, $accept_email_fail = false)
{
static function register(array $fields, $accept_email_fail=false) {
// MAGICALLY put fields into current scope
extract($fields);
$profile = new Profile();
@@ -258,22 +262,23 @@ 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 = true;
$user->emailnotifynudge = true;
$user->emailnotifymsg = true;
$user->emailnotifyattn = true;
$user->emailpost = true;
$user->emailnotifysub = 1;
$user->emailnotifynudge = 1;
$user->emailnotifymsg = 1;
$user->emailnotifyattn = 1;
$user->emailpost = 1;
$user->created = common_sql_now();
if (Event::handle('StartUserRegister', array($profile))) {
$profile->query('BEGIN');
$id = $profile->insert();
@@ -286,7 +291,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;
@@ -362,11 +367,8 @@ 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());
}
@@ -392,23 +394,16 @@ 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');
}
}
@@ -423,8 +418,9 @@ class User extends Managed_DataObject
}
// Things we do when the email changes
public function emailChanged()
function emailChanged()
{
$invites = new Invitation();
$invites->address = $this->email;
$invites->address_type = 'email';
@@ -445,53 +441,48 @@ class User extends Managed_DataObject
}
}
public function mutuallySubscribed(Profile $other)
function mutuallySubscribed(Profile $other)
{
return $this->getProfile()->mutuallySubscribed($other);
}
public function mutuallySubscribedUsers()
function mutuallySubscribedUsers()
{
$user = new User();
// 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
));
$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));
return $user;
}
public function getReplies($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
{
return $this->getProfile()->getReplies($offset, $limit, $since_id, $before_id);
}
public function getTaggedNotices($tag, $offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
{
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);
}
public function getNotices($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
{
return $this->getProfile()->getNotices($offset, $limit, $since_id, $before_id);
}
public function block(Profile $other)
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,
@@ -530,7 +521,7 @@ class User extends Managed_DataObject
return true;
}
public function unblock(Profile $other)
function unblock(Profile $other)
{
// Get the block record
@@ -550,17 +541,17 @@ class User extends Managed_DataObject
return true;
}
public function isMember(User_group $group)
function isMember(User_group $group)
{
return $this->getProfile()->isMember($group);
}
public function isAdmin(User_group $group)
function isAdmin(User_group $group)
{
return $this->getProfile()->isAdmin($group);
}
public function getGroups($offset = 0, $limit = null)
function getGroups($offset=0, $limit=null)
{
return $this->getProfile()->getGroups($offset, $limit);
}
@@ -572,7 +563,7 @@ class User extends Managed_DataObject
* @param User_group $group
* @return Group_member
*/
public function joinGroup(User_group $group)
function joinGroup(User_group $group)
{
return $this->getProfile()->joinGroup($group);
}
@@ -582,37 +573,37 @@ class User extends Managed_DataObject
*
* @param User_group $group
*/
public function leaveGroup(User_group $group)
function leaveGroup(User_group $group)
{
return $this->getProfile()->leaveGroup($group);
}
public function getSubscribed($offset = 0, $limit = null)
function getSubscribed($offset=0, $limit=null)
{
return $this->getProfile()->getSubscribed($offset, $limit);
}
public function getSubscribers($offset = 0, $limit = null)
function getSubscribers($offset=0, $limit=null)
{
return $this->getProfile()->getSubscribers($offset, $limit);
}
public function getTaggedSubscribers($tag, $offset = 0, $limit = null)
function getTaggedSubscribers($tag, $offset=0, $limit=null)
{
return $this->getProfile()->getTaggedSubscribers($tag, $offset, $limit);
}
public function getTaggedSubscriptions($tag, $offset = 0, $limit = null)
function getTaggedSubscriptions($tag, $offset=0, $limit=null)
{
return $this->getProfile()->getTaggedSubscriptions($tag, $offset, $limit);
}
public function hasRight($right)
function hasRight($right)
{
return $this->getProfile()->hasRight($right);
}
public function delete($useWhere = false)
function delete($useWhere=false)
{
if (empty($this->id)) {
common_log(LOG_WARNING, "Ambiguous User->delete(); skipping related tables.");
@@ -649,14 +640,14 @@ class User extends Managed_DataObject
return parent::delete($useWhere);
}
public function _deleteTags()
function _deleteTags()
{
$tag = new Profile_tag();
$tag->tagger = $this->id;
$tag->delete();
}
public function _deleteBlocks()
function _deleteBlocks()
{
$block = new Profile_block();
$block->blocker = $this->id;
@@ -664,32 +655,32 @@ class User extends Managed_DataObject
// XXX delete group block? Reset blocker?
}
public function hasRole($name)
function hasRole($name)
{
return $this->getProfile()->hasRole($name);
}
public function grantRole($name)
function grantRole($name)
{
return $this->getProfile()->grantRole($name);
}
public function revokeRole($name)
function revokeRole($name)
{
return $this->getProfile()->revokeRole($name);
}
public function isSandboxed()
function isSandboxed()
{
return $this->getProfile()->isSandboxed();
}
public function isSilenced()
function isSilenced()
{
return $this->getProfile()->isSilenced();
}
public function receivesEmailNotifications()
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
@@ -704,7 +695,7 @@ class User extends Managed_DataObject
return true;
}
public function repeatedByMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
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.
@@ -713,7 +704,7 @@ class User extends Managed_DataObject
}
public function repeatsOfMe($offset = 0, $limit = 20, $since_id = null, $max_id = null)
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.
@@ -721,7 +712,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);
}
@@ -800,7 +791,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
*/
public static function singleUserNickname()
static function singleUserNickname()
{
try {
$user = User::singleUser();
@@ -837,7 +828,7 @@ class User extends Managed_DataObject
* Get a list of OAuth client applications that have access to this
* user's account.
*/
public function getConnectedApps($offset = 0, $limit = null)
function getConnectedApps($offset = 0, $limit = null)
{
$qry =
'SELECT u.* ' .
@@ -848,7 +839,11 @@ class User extends Managed_DataObject
'ORDER BY u.created DESC ';
if ($offset > 0) {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
if (common_config('db','type') == 'pgsql') {
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
}
}
$apps = new Oauth_application_user();
@@ -868,16 +863,16 @@ class User extends Managed_DataObject
* @return array of variable names to include in serialization.
*/
public function __sleep()
function __sleep()
{
$vars = parent::__sleep();
$skip = array('_profile');
return array_diff($vars, $skip);
}
public static function recoverPassword($nore)
static function recoverPassword($nore)
{
require_once INSTALLDIR . '/lib/util/mail.php';
require_once(INSTALLDIR . '/lib/mail.php');
// $confirm_email will be used as a fallback if our user doesn't have a confirmed email
$confirm_email = null;
@@ -948,7 +943,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 ' .
@@ -956,10 +951,8 @@ 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',
['code' => $confirm->code]
);
$body .= "\t".common_local_url('recoverpassword',
array('code' => $confirm->code));
$body .= "\n\n";
$body .= 'If not, just ignore this message.';
$body .= "\n\n";
@@ -973,7 +966,7 @@ class User extends Managed_DataObject
mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
}
public function streamModeOnly()
function streamModeOnly()
{
if (common_config('oldschool', 'enabled')) {
$osp = Old_school_prefs::getKV('user_id', $this->id);
@@ -985,7 +978,7 @@ class User extends Managed_DataObject
return false;
}
public function streamNicknames()
function streamNicknames()
{
if (common_config('oldschool', 'enabled')) {
$osp = Old_school_prefs::getKV('user_id', $this->id);
@@ -996,7 +989,7 @@ class User extends Managed_DataObject
return false;
}
public function registrationActivity()
function registrationActivity()
{
$profile = $this->getProfile();
@@ -1014,20 +1007,16 @@ 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;
}
+76 -94
Ver Arquivo
@@ -1,24 +1,8 @@
<?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;
@@ -79,7 +63,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'),
@@ -134,38 +118,40 @@ class User_group extends Managed_DataObject
return Theme::path('default-avatar-'.$sizenames[$size].'.png');
}
public function homeUrl()
function homeUrl()
{
return $this->getProfile()->getUrl();
}
public function getUri()
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', ['id' => $this->id]);
$uri = common_local_url('groupbyid',
array('id' => $this->id));
}
}
Event::handle('EndUserGroupGetUri', array($this, &$uri));
return $uri;
}
public function permalink()
function permalink()
{
$url = null;
if (Event::handle('StartUserGroupPermalink', array($this, &$url))) {
if ($this->isLocal()) {
$url = common_local_url('groupbyid', ['id' => $this->id]);
$url = common_local_url('groupbyid',
array('id' => $this->id));
}
}
Event::handle('EndUserGroupPermalink', array($this, &$url));
return $url;
}
public function getNotices($offset, $limit, $since_id = null, $max_id = null)
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.
@@ -174,26 +160,29 @@ class User_group extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
public function getMembers($offset = 0, $limit = null)
{
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);
}
public function getMemberIDs($offset = 0, $limit = null)
function getMemberIDs($offset=0, $limit=null)
{
$gm = new Group_member();
@@ -226,7 +215,7 @@ class User_group extends Managed_DataObject
* @param int $limit
* @return Profile
*/
public function getRequests($offset = 0, $limit = null)
function getRequests($offset=0, $limit=null)
{
$rq = new Group_join_queue();
$rq->group_id = $this->id;
@@ -248,7 +237,7 @@ class User_group extends Managed_DataObject
{
$block = new Group_member();
$block->group_id = $this->id;
$block->is_admin = true;
$block->is_admin = 1;
return $block->count();
}
@@ -275,7 +264,7 @@ class User_group extends Managed_DataObject
return $cnt;
}
public function getBlockedCount()
function getBlockedCount()
{
// XXX: WORM cache this
@@ -285,7 +274,7 @@ class User_group extends Managed_DataObject
return $block->count();
}
public function getQueueCount()
function getQueueCount()
{
// XXX: WORM cache this
@@ -295,12 +284,11 @@ class User_group extends Managed_DataObject
return $queue->count();
}
// offset is null because DataObject wants it, 0 would mean no results
public function getAdmins($offset = null, $limit = null)
function getAdmins($offset=null, $limit=null) // offset is null because DataObject wants it, 0 would mean no results
{
$admins = new Profile();
$admins->joinAdd(array('id', 'group_member:profile_id'));
$admins->whereAdd('group_member.group_id = ' . $this->id . ' AND group_member.is_admin = true');
$admins->whereAdd(sprintf('group_member.group_id = %u AND group_member.is_admin = 1', $this->id));
$admins->orderBy('group_member.modified ASC');
$admins->limit($offset, $limit);
$admins->find();
@@ -308,8 +296,7 @@ class User_group extends Managed_DataObject
return $admins;
}
// offset is null because DataObject wants it, 0 would mean no results
public function getBlocked($offset = null, $limit = null)
function getBlocked($offset=null, $limit=null) // offset is null because DataObject wants it, 0 would mean no results
{
$blocked = new Profile();
$blocked->joinAdd(array('id', 'group_block:blocked'));
@@ -321,7 +308,7 @@ class User_group extends Managed_DataObject
return $blocked;
}
public function setOriginal($filename)
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));
@@ -333,12 +320,8 @@ 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);
}
@@ -346,7 +329,7 @@ class User_group extends Managed_DataObject
return $this->update($orig);
}
public function getBestName()
function getBestName()
{
return ($this->fullname) ? $this->fullname : $this->nickname;
}
@@ -357,17 +340,17 @@ class User_group extends Managed_DataObject
*
* @return string
*/
public function getFancyName()
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;
}
}
public function getAliases()
function getAliases()
{
$aliases = array();
@@ -388,8 +371,8 @@ class User_group extends Managed_DataObject
return $aliases;
}
public function setAliases($newaliases)
{
function setAliases($newaliases) {
$newaliases = array_unique($newaliases);
$oldaliases = $this->getAliases();
@@ -430,7 +413,7 @@ class User_group extends Managed_DataObject
return true;
}
public static function getForNickname($nickname, Profile $profile = null)
static function getForNickname($nickname, Profile $profile=null)
{
$nickname = Nickname::normalize($nickname);
@@ -457,21 +440,24 @@ class User_group extends Managed_DataObject
return null;
}
public function getUserMembers()
function getUserMembers()
{
// XXX: cache this
$user = new User();
if(common_config('db','quote_identifiers'))
$user_table = '"user"';
else $user_table = 'user';
$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
));
$qry =
'SELECT id ' .
'FROM '. $user_table .' JOIN group_member '.
'ON '. $user_table .'.id = group_member.profile_id ' .
'WHERE group_member.group_id = %d ';
$ids = [];
$user->query(sprintf($qry, $this->id));
$ids = array();
while ($user->fetch()) {
$ids[] = $user->id;
@@ -482,7 +468,7 @@ class User_group extends Managed_DataObject
return $ids;
}
public static function maxDescription()
static function maxDescription()
{
$desclimit = common_config('group', 'desclimit');
// null => use global limit (distinct from 0!)
@@ -492,13 +478,13 @@ class User_group extends Managed_DataObject
return $desclimit;
}
public static function descriptionTooLong($desc)
static function descriptionTooLong($desc)
{
$desclimit = self::maxDescription();
return ($desclimit > 0 && !empty($desc) && (mb_strlen($desc) > $desclimit));
}
public function asAtomEntry($namespace = false, $source = false)
function asAtomEntry($namespace=false, $source=false)
{
$xs = new XMLStringer(true);
@@ -542,7 +528,7 @@ class User_group extends Managed_DataObject
return $xs->getString();
}
public function asAtomAuthor()
function asAtomAuthor()
{
$xs = new XMLStringer(true);
@@ -565,21 +551,20 @@ class User_group extends Managed_DataObject
*
* @return string
*/
public function asActivityNoun($element)
function asActivityNoun($element)
{
$noun = ActivityObject::fromGroup($this);
return $noun->asString('activity:' . $element);
}
public function getAvatar()
function getAvatar()
{
return empty($this->homepage_logo)
? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
: $this->homepage_logo;
}
public static function register($fields)
{
static function register($fields) {
if (!empty($fields['userid'])) {
$profile = Profile::getKV('id', $fields['userid']);
if ($profile && !$profile->hasRight(Right::CREATEGROUP)) {
@@ -595,20 +580,18 @@ class User_group extends Managed_DataObject
// MAGICALLY put fields into current scope
// @fixme kill extract(); it makes debugging absurdly hard
$defaults = [
'nickname' => null,
'fullname' => null,
'homepage' => null,
'description' => null,
'location' => null,
'uri' => null,
'mainpage' => null,
'aliases' => [],
'userid' => null,
];
$fields = array_merge($defaults, $fields);
$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);
extract($fields);
$group = new User_group();
@@ -662,6 +645,7 @@ class User_group extends Managed_DataObject
}
if (Event::handle('StartGroupSave', array(&$group))) {
$result = $group->insert();
if ($result === false) {
@@ -692,7 +676,7 @@ class User_group extends Managed_DataObject
$member->group_id = $group->id;
$member->profile_id = $userid;
$member->is_admin = true;
$member->is_admin = 1;
$member->created = $group->created;
$result = $member->insert();
@@ -737,7 +721,7 @@ class User_group extends Managed_DataObject
* are not de-cached in the UI, including the sidebar lists on
* GroupsAction
*/
public function delete($useWhere = false)
function delete($useWhere=false)
{
if (empty($this->id)) {
common_log(LOG_WARNING, "Ambiguous User_group->delete(); skipping related tables.");
@@ -829,7 +813,7 @@ class User_group extends Managed_DataObject
return parent::update($dataObject);
}
public function isPrivate()
function isPrivate()
{
return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
intval($this->force_scope) === 1);
@@ -841,16 +825,14 @@ class User_group extends Managed_DataObject
return ($local instanceof Local_group);
}
public static function groupsFromText($text, Profile $profile)
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;
@@ -866,7 +848,7 @@ class User_group extends Managed_DataObject
return $groups;
}
public static function idsFromText($text, Profile $profile)
static function idsFromText($text, Profile $profile)
{
$ids = array();
$groups = self::groupsFromText($text, $profile);
+27 -25
Ver Arquivo
@@ -1,31 +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 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 GNUsocial
* @package StatusNet
* @author Craig Andrews <candrews@integralblue.com>
* @copyright 2009 StatusNet Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class User_im_prefs extends Managed_DataObject
@@ -37,9 +38,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; // bool not_null default_false
public $replies; // bool not_null default_false
public $updatefrompresence; // bool not_null default_false
public $notify; // tinyint(1)
public $replies; // tinyint(1)
public $updatefrompresence; // tinyint(1)
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@@ -53,9 +54,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' => '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.'),
'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.'),
'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'),
),
@@ -68,4 +69,5 @@ class User_im_prefs extends Managed_DataObject
),
);
}
}
+22 -19
Ver Arquivo
@@ -1,27 +1,30 @@
<?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 GNUsocial
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2009 StatusNet Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
@@ -33,7 +36,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; // bool default_true
public $share_location; // tinyint(1) default_1
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@@ -45,7 +48,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' => 'bool', 'default' => true, 'description' => 'Whether to share location data'),
'share_location' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, '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'),
),
+7 -24
Ver Arquivo
@@ -1,26 +1,9 @@
<?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
@@ -40,8 +23,8 @@ class User_username extends Managed_DataObject
{
return array(
'fields' => array(
'provider_name' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'provider name'),
'username' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'username'),
'provider_name' => array('type' => 'varchar', 'length' => 191, 'description' => 'provider name'),
'username' => array('type' => 'varchar', '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'),
@@ -63,7 +46,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
*/
public static function register($user, $username, $provider_name)
static function register($user, $username, $provider_name)
{
$user_username = new User_username();
$user_username->user_id = $user->id;
@@ -71,9 +54,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;
}
}
+2 -4
Ver Arquivo
@@ -6,7 +6,6 @@
"require": {
"php": "^7.3.0",
"ext-bcmath": "*",
"ext-ctype": "*",
"ext-curl": "*",
"ext-dom": "*",
"ext-gd": "*",
@@ -17,14 +16,12 @@
"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",
@@ -37,6 +34,7 @@
"stomp-php/stomp-php": "^4.5.1"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "^2.9",
"phpunit/phpunit": "^8.2",
"psy/psysh": "^0.9.9"
},
+3294 -1402
Ver Arquivo
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
-27
Ver Arquivo
@@ -1,27 +0,0 @@
<?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();
+62 -75
Ver Arquivo
@@ -1,23 +1,13 @@
<?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
@@ -39,67 +29,64 @@
* double-check what we've been doing on postgres?
*/
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'
];
$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',
);
foreach ($classes as $cls) {
$schema[strtolower($cls)] = call_user_func([$cls, 'schemaDef']);
$schema[strtolower($cls)] = call_user_func(array($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()),
+6 -12
Ver Arquivo
@@ -49,18 +49,12 @@ class AcceptHeader extends \ArrayObject
foreach ($items as $item) {
$elems = explode(';', $item);
$mime = current($elems);
$types = explode('/', $mime);
if (!isset($types[1])) {
continue;
}
$acceptElement = [
'raw' => $mime,
'type' => trim($types[0]),
'subtype' => trim($types[1]),
];
$acceptElement = [];
$mime = current($elems);
list($type, $subtype) = explode('/', $mime);
$acceptElement['type'] = trim($type);
$acceptElement['subtype'] = trim($subtype);
$acceptElement['raw'] = $mime;
$acceptElement['params'] = [];
while (next($elems)) {
+3 -47
Ver Arquivo
@@ -1787,34 +1787,12 @@ 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_keys($array) as $i => $k) {
foreach ($array as $k => $v) {
// 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);
}
@@ -2440,7 +2418,7 @@ class DB_DataObject extends DB_DataObject_Overload
case 'pgsql':
if (!$seq) {
$seq = $DB->getSequenceName(strtolower($this->tableName() . '_' . $key));
$seq = $DB->getSequenceName(strtolower($this->tableName()));
}
$db_driver = empty($options['db_driver']) ? 'DB' : $options['db_driver'];
$method = ($db_driver == 'DB') ? 'getOne' : 'queryOne';
@@ -2971,34 +2949,12 @@ 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_keys($array) as $i => $k) {
foreach ($array as $k => $v) {
// 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);
}
+43 -22
Ver Arquivo
@@ -1,31 +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
*
* 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 GNUsocial
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
defined('GNUSOCIAL') || die();
if (!defined('GNUSOCIAL')) {
exit(1);
}
/**
* Base class for all actions
@@ -36,11 +41,14 @@ defined('GNUSOCIAL') || die();
* Actions are responsible for extracting and validating parameters; using
* model classes to read and write to the database; and doing ouput.
*
* @category Output
* @copyright 2008 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/
*
* @see HTMLOutputter
* @see HTMLOutputter
*/
class Action extends HTMLOutputter // lawsuit
{
@@ -1558,6 +1566,19 @@ 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/activitystreams/activitystreamjsondocument.php';
require_once(INSTALLDIR . '/lib/activitystreamjsondocument.php');
/**
* A noun-ish thing in the activity universe
@@ -30,7 +30,7 @@
if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/api/apiaction.php';
require_once INSTALLDIR . '/lib/apiaction.php';
/**
* Base action for API OAuth enpoints. Clean up the

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