Make oEmbed handle our http/https setting better.
This commit is contained in:
parent
566977c136
commit
5ca2a28246
|
@ -1689,10 +1689,15 @@ function common_profile_url($nickname)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should make up a reasonable root URL
|
* Should make up a reasonable root URL
|
||||||
|
*
|
||||||
|
* @param bool $tls true or false to force TLS scheme, null to use server configuration
|
||||||
*/
|
*/
|
||||||
function common_root_url($ssl=false)
|
function common_root_url($tls=null)
|
||||||
{
|
{
|
||||||
$url = common_path('', $ssl, false);
|
if (is_null($tls)) {
|
||||||
|
$tls = GNUsocial::useHTTPS();
|
||||||
|
}
|
||||||
|
$url = common_path('', $tls, false);
|
||||||
$i = strpos($url, '?');
|
$i = strpos($url, '?');
|
||||||
if ($i !== false) {
|
if ($i !== false) {
|
||||||
$url = substr($url, 0, $i);
|
$url = substr($url, 0, $i);
|
||||||
|
|
|
@ -44,21 +44,20 @@ class OembedAction extends Action
|
||||||
parent::handle();
|
parent::handle();
|
||||||
|
|
||||||
$url = $this->trimmed('url');
|
$url = $this->trimmed('url');
|
||||||
if (substr(strtolower($url),0,strlen(common_root_url())) !== strtolower(common_root_url())) {
|
$tls = parse_url($url, PHP_URL_SCHEME) == 'https';
|
||||||
|
$root_url = common_root_url($tls);
|
||||||
|
|
||||||
|
if (substr(strtolower($url),0,mb_strlen($root_url)) !== strtolower($root_url)) {
|
||||||
// TRANS: Error message displaying attachments. %s is the site's base URL.
|
// TRANS: Error message displaying attachments. %s is the site's base URL.
|
||||||
$this->clientError(sprintf(_('oEmbed data will only be provided for %s URLs.'), common_root_url()), 400);
|
throw new ClientException(sprintf(_('oEmbed data will only be provided for %s URLs.'), $root_url));
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = substr($url,strlen(common_root_url()));
|
$path = substr($url,strlen($root_url));
|
||||||
|
|
||||||
$r = Router::get();
|
$r = Router::get();
|
||||||
|
|
||||||
|
// $r->map will throw ClientException 404 if it fails to find a mapping
|
||||||
$proxy_args = $r->map($path);
|
$proxy_args = $r->map($path);
|
||||||
if (!$proxy_args) {
|
|
||||||
// TRANS: Client error displayed in oEmbed action when path not found.
|
|
||||||
// TRANS: %s is a path.
|
|
||||||
$this->clientError(sprintf(_('"%s" not found.'),$path), 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
$oembed=array();
|
$oembed=array();
|
||||||
$oembed['version']='1.0';
|
$oembed['version']='1.0';
|
||||||
|
@ -68,18 +67,12 @@ class OembedAction extends Action
|
||||||
switch ($proxy_args['action']) {
|
switch ($proxy_args['action']) {
|
||||||
case 'shownotice':
|
case 'shownotice':
|
||||||
$oembed['type']='link';
|
$oembed['type']='link';
|
||||||
$id = $proxy_args['notice'];
|
try {
|
||||||
$notice = Notice::getKV($id);
|
$notice = Notice::getByID($proxy_args['notice']);
|
||||||
if(empty($notice)){
|
} catch (NoResultException $e) {
|
||||||
// TRANS: Client error displayed in oEmbed action when notice not found.
|
throw new ClientException($e->getMessage(), 404);
|
||||||
// TRANS: %s is a notice.
|
|
||||||
$this->clientError(sprintf(_("Notice %s not found."),$id), 404);
|
|
||||||
}
|
}
|
||||||
$profile = $notice->getProfile();
|
$profile = $notice->getProfile();
|
||||||
if (empty($profile)) {
|
|
||||||
// TRANS: Server error displayed in oEmbed action when notice has not profile.
|
|
||||||
$this->serverError(_('Notice has no profile.'), 500);
|
|
||||||
}
|
|
||||||
$authorname = $profile->getFancyName();
|
$authorname = $profile->getFancyName();
|
||||||
// TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date.
|
// TRANS: oEmbed title. %1$s is the author name, %2$s is the creation date.
|
||||||
$oembed['title'] = sprintf(_('%1$s\'s status on %2$s'),
|
$oembed['title'] = sprintf(_('%1$s\'s status on %2$s'),
|
||||||
|
@ -256,4 +249,4 @@ class OembedAction extends Action
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue