From: Roland Haeder Date: Sun, 15 Feb 2015 20:47:26 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/master' X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=26703076f66f77f337559416cc02101c532d7aa8;p=quix0rs-gnu-social.git Merge remote-tracking branch 'upstream/master' Conflicts: actions/apiaccountverifycredentials.php actions/apimediaupload.php actions/apistatusesshow.php actions/apitimelinepublic.php actions/logout.php actions/public.php actions/register.php lib/inboxnoticestream.php plugins/Favorite/actions/apifavoritecreate.php plugins/OStatus/actions/pushhub.php plugins/OStatus/classes/Ostatus_profile.php plugins/OStatus/scripts/update_ostatus_profiles.php plugins/OpportunisticQM/lib/opportunisticqueuemanager.php plugins/YammerImport/lib/yammerimporter.php scripts/commandline.inc.php Signed-off-by: Roland Haeder --- 26703076f66f77f337559416cc02101c532d7aa8 diff --cc actions/apiaccountverifycredentials.php index dfa366cbb6,9b98fa6d81..12daf3e1e6 --- a/actions/apiaccountverifycredentials.php +++ b/actions/apiaccountverifycredentials.php @@@ -48,17 -48,9 +48,16 @@@ if (!defined('STATUSNET')) */ class ApiAccountVerifyCredentialsAction extends ApiAuthAction { + /** + * Handle the request + * + * Check whether the credentials are valid and output the result + * - * @param array $args $_REQUEST data (unused) + * @return void + */ - function handle(array $args=array()) + protected function handle() { - parent::handle($args); + parent::handle(); if (!in_array($this->format, array('xml', 'json'))) { // TRANS: Client error displayed when coming across a non-supported API method. diff --cc actions/apimediaupload.php index 14c26d238f,8e59fec59c..8580b209a5 --- a/actions/apimediaupload.php +++ b/actions/apimediaupload.php @@@ -48,22 -48,14 +48,11 @@@ class ApiMediaUploadAction extends ApiA * Grab the file from the 'media' param, then store, and shorten * * @todo Upload throttle! -- * -- * @param array $args $_REQUEST data (unused) -- * * @return void */ - function handle(array $args=array()) + protected function handle() { - parent::handle($args); - - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError( - // TRANS: Client error. POST is a HTTP command. It should not be translated. - _('This method requires a POST.'), - 400, $this->format - ); - } + parent::handle(); // Workaround for PHP returning empty $_POST and $_FILES when POST // length > post_max_size in php.ini diff --cc actions/logout.php index 6edbbdf293,60aec3c83a..b6d4efbf23 --- a/actions/logout.php +++ b/actions/logout.php @@@ -54,36 -52,22 +52,27 @@@ class LogoutAction extends ManagedActio return false; } + /** + * Class handler. + * - * @param array $args array of arguments - * + * @return nothing + */ - function handle(array $args=array()) + protected function doPreparation() { - parent::handle($args); if (!common_logged_in()) { - // TRANS: Error message displayed when trying to perform an action that requires a logged in user. - $this->clientError(_('Not logged in.')); - } else { - if (Event::handle('StartLogout', array($this))) { - $this->logout(); - } - Event::handle('EndLogout', array($this)); - - if (common_config('singleuser', 'enabled')) { - $user = User::singleUser(); - common_redirect(common_local_url('showstream', - array('nickname' => $user->nickname))); - } else { - common_redirect(common_local_url('public'), 303); - } + // TRANS: Error message displayed when trying to logout even though you are not logged in. + throw new AlreadyFulfilledException(_('Cannot log you out if you are not logged in.')); } + if (Event::handle('StartLogout', array($this))) { + $this->logout(); + } + Event::handle('EndLogout', array($this)); + + common_redirect(common_local_url('startpage')); } - function logout() + // Accessed through the action on events + public function logout() { common_set_user(null); common_real_login(false); // not logged in diff --cc actions/public.php index 8e5da47646,06ee75b8d1..b45bbeae7f --- a/actions/public.php +++ b/actions/public.php @@@ -53,23 -53,16 +53,23 @@@ class PublicAction extends ManagedActio var $page = null; var $notice; - var $userProfile = null; + + protected $stream = null; - function isReadOnly($args) + function isReadOnly(array $args=array()) { return true; } + /** + * Read and validate arguments + * + * @param array $args URL parameters + * + * @return boolean success value + */ - function prepare(array $args=array()) + protected function doPreparation() { - parent::prepare($args); $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; if ($this->page > MAX_PUBLIC_PAGE) { @@@ -106,20 -91,13 +98,22 @@@ return true; } + /** + * handle request + * + * Show the public stream, using recipe method showPage() + * + * @param array $args arguments, mostly unused + * + * @return void + */ - function handle(array $args=array()) + protected function streamPrepare() { - parent::handle($args); - - $this->showPage(); + if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) { + $this->stream = new PublicNoticeStream($this->scoped); + } else { + $this->stream = new ThreadingPublicNoticeStream($this->scoped); + } } /** diff --cc extlib/DB/DataObject.php index 1232d184df,684a98c92a..684a98c92a mode 100644,100755..100644 --- a/extlib/DB/DataObject.php +++ b/extlib/DB/DataObject.php diff --cc extlib/DB/DataObject/Cast.php index 59cc0af279,a31f536cd5..a31f536cd5 mode 100644,100755..100644 --- a/extlib/DB/DataObject/Cast.php +++ b/extlib/DB/DataObject/Cast.php diff --cc extlib/DB/DataObject/Generator.php index c06d6ed610,a712e6d9eb..a712e6d9eb mode 100644,100755..100644 --- a/extlib/DB/DataObject/Generator.php +++ b/extlib/DB/DataObject/Generator.php diff --cc extlib/DB/DataObject/createTables.php index ed2e738b78,1295d252b8..1295d252b8 mode 100644,100755..100644 --- a/extlib/DB/DataObject/createTables.php +++ b/extlib/DB/DataObject/createTables.php diff --cc plugins/Favorite/actions/apifavoritecreate.php index ea94958ebc,736bd7b0a1..8a27374053 --- a/plugins/Favorite/actions/apifavoritecreate.php +++ b/plugins/Favorite/actions/apifavoritecreate.php @@@ -50,22 -50,16 +50,21 @@@ class ApiFavoriteCreateAction extends A { var $notice = null; + protected $needPost = true; + + /** + * Take arguments for running + * - * @param array $args $_REQUEST args - * + * @return boolean success flag + */ - function prepare(array $args=array()) + protected function prepare(array $args=array()) { parent::prepare($args); - $this->user = $this->auth_user; $this->notice = Notice::getKV($this->arg('id')); - if ($this->notice->repeat_of != '' ) { + if (!empty($this->notice->repeat_of)) { - common_log(LOG_DEBUG, 'Trying to Fave '.$this->notice->id.', repeat of '.$this->notice->repeat_of); - common_log(LOG_DEBUG, 'Will Fave '.$this->notice->repeat_of.' instead'); + common_debug('Trying to Fave '.$this->notice->id.', repeat of '.$this->notice->repeat_of); + common_debug('Will Fave '.$this->notice->repeat_of.' instead'); $real_notice_id = $this->notice->repeat_of; $this->notice = Notice::getKV($real_notice_id); } @@@ -73,28 -67,9 +72,16 @@@ return true; } + /** + * Handle the request + * + * Check the format and show the user info + * - * @param array $args $_REQUEST data (unused) - * + * @return void + */ - function handle(array $args=array()) + protected function handle() { - parent::handle($args); - - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError( - // TRANS: Client error. POST is a HTTP command. It should not be translated. - _('This method requires a POST.'), - 400, - $this->format - ); - return; - } + parent::handle(); if (!in_array($this->format, array('xml', 'json'))) { $this->clientError( diff --cc plugins/OStatus/classes/Ostatus_profile.php index d698ba81a3,79098c6404..d5ad33a91e --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@@ -1261,12 -1259,15 +1260,15 @@@ class Ostatus_profile extends Managed_D // @todo FIXME: This should be better encapsulated // ripped from oauthstore.php (for old OMB client) - $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar'); + $temp_filename = tempnam(common_get_temp_dir(), 'listener_avatar'); try { - if (!copy($url, $temp_filename)) { - // TRANS: Server exception. %s is a URL. - throw new ServerException(sprintf(_m('Unable to fetch avatar from %s to %s.'), $url, $temp_filename)); + $imgData = HTTPClient::quickGet($url); + // Make sure it's at least an image file. ImageFile can do the rest. + if (false === getimagesizefromstring($imgData)) { + throw new UnsupportedMediaException(_('Downloaded group avatar was not an image.')); } + file_put_contents($temp_filename, $imgData); + unset($imgData); // No need to carry this in memory. if ($this->isGroup()) { $id = $this->group_id; diff --cc plugins/OStatus/scripts/gcfeeds.php index 94ead535fb,a95cd54dbc..f1db4b358f --- a/plugins/OStatus/scripts/gcfeeds.php +++ b/plugins/OStatus/scripts/gcfeeds.php @@@ -24,10 -27,15 +27,15 @@@ $helptext = <<find(); while ($feedsub->fetch()) { diff --cc plugins/YammerImport/lib/yammerimporter.php index 6af0302f77,0992882670..abd41dd99e --- a/plugins/YammerImport/lib/yammerimporter.php +++ b/plugins/YammerImport/lib/yammerimporter.php @@@ -161,9 -159,13 +161,13 @@@ class YammerImporte // Save "likes" as favorites... foreach ($data['faves'] as $nickname) { $user = User::getKV('nickname', $nickname); - - if ($user) { + if ($user instanceof User) { - Fave::addNew($user->getProfile(), $notice); + try { + Fave::addNew($user->getProfile(), $notice); + } catch (Exception $e) { + // failed, let's move to the next + common_debug('YammerImport failed favoriting a notice: '.$e->getMessage()); + } } } diff --cc scripts/commandline.inc.php index 0a5257cdd5,0000000000..1244187b87 mode 100644,000000..100644 --- a/scripts/commandline.inc.php +++ b/scripts/commandline.inc.php @@@ -1,247 -1,0 +1,248 @@@ +. + */ + +// -*- mode: php -*- + +# Abort if called from a web server + +if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { + print "This script must be run from the command line\n"; + exit(); +} + +define('GNUSOCIAL', true); +define('STATUSNET', true); //compatibility + +// Set various flags so we don't time out on long-running processes + +ini_set("max_execution_time", "0"); +ini_set("max_input_time", "0"); +set_time_limit(0); +mb_internal_encoding('UTF-8'); +error_reporting(0); ++# DEBUG: error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED); + +// Add extlib to our path so we can get Console_Getopt + +$_extra_path = array(INSTALLDIR.'/extlib/'); + +set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path()); + +require_once 'Console/Getopt.php'; + +// Note: $shortoptions and $longoptions should be pre-defined! + +$_default_shortoptions = 'qvhc:s:p:'; + +$_default_longoptions = array('quiet', 'verbose', 'help', 'conf=', 'server=', 'path='); + +if (isset($shortoptions)) { + $shortoptions .= $_default_shortoptions; +} else { + $shortoptions = $_default_shortoptions; +} + +if (isset($longoptions)) { + $longoptions = array_merge($longoptions, $_default_longoptions); +} else { + $longoptions = $_default_longoptions; +} + +$parser = new Console_Getopt(); + +$result = $parser->getopt($argv, $shortoptions, $longoptions); + +if (PEAR::isError($result)) { + print $result->getMessage()."\n"; + exit(1); +} else { + list($options, $args) = $result; +} + +function show_help() +{ + global $helptext; + + $_default_help_text = << Use as config file + -s --server= Use as server name + -p --path= Use as path name + -h --help Show this message and quit. + +END_OF_DEFAULT; + if (isset($helptext)) { + print $helptext; + } + print $_default_help_text; + exit(0); +} + +foreach ($options as $option) { + + switch ($option[0]) { + case '--server': + case 's': + $server = $option[1]; + break; + + case '--path': + case 'p': + $path = $option[1]; + break; + + case '--conf': + case 'c': + $conffile = $option[1]; + break; + + case '--help': + case 'h': + show_help(); + } +} + +require_once INSTALLDIR . '/lib/common.php'; + +set_error_handler('common_error_handler'); + +// Set up the language infrastructure so we can localize anything that +// needs to be sent out to users, such as mail notifications. +common_init_language(); + +function _make_matches($opt, $alt) +{ + $matches = array(); + + if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) { + $matches[] = '--'.$opt; + } else { + $matches[] = $opt; + } + + if (!empty($alt)) { + if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) { + $matches[] = '--'.$alt; + } else { + $matches[] = $alt; + } + } + + return $matches; +} + +function have_option($opt, $alt=null) +{ + global $options; + + $matches = _make_matches($opt, $alt); + + foreach ($options as $option) { + if (in_array($option[0], $matches)) { + return true; + } + } + + return false; +} + +function get_option_value($opt, $alt=null) +{ + global $options; + + $matches = _make_matches($opt, $alt); + + foreach ($options as $option) { + if (in_array($option[0], $matches)) { + return $option[1]; + } + } + + return null; +} + +class NoUserArgumentException extends Exception +{ +} + +function getUser() +{ + $user = null; + + if (have_option('i', 'id')) { + $id = get_option_value('i', 'id'); + $user = User::getKV('id', $id); + if (empty($user)) { + throw new Exception("Can't find user with id '$id'."); + } + } else if (have_option('n', 'nickname')) { + $nickname = get_option_value('n', 'nickname'); + $user = User::getKV('nickname', $nickname); + if (empty($user)) { + throw new Exception("Can't find user with nickname '$nickname'"); + } + } else { + throw new NoUserArgumentException("No user argument specified."); + } + + return $user; +} + +/** "Printf not quiet" */ + +function printfnq() +{ + if (have_option('q', 'quiet')) { + return null; + } + + $cargs = func_num_args(); + + if ($cargs == 0) { + return 0; + } + + $args = func_get_args(); + $format = array_shift($args); + + return vprintf($format, $args); +} + +/** "Print when verbose" */ + +function printfv() +{ + if (!have_option('v', 'verbose')) { + return null; + } + + $cargs = func_num_args(); + + if ($cargs == 0) { + return 0; + } + + $args = func_get_args(); + $format = array_shift($args); + + return vprintf($format, $args); +}