Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Commit

Permalink
feat(deps): update to latest version of elgg-url-sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
hypeJunction committed Feb 3, 2017
1 parent a544f63 commit 782916a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"require": {
"php": ">=5.5",
"composer/installers": "~1.0",
"mrclay/elgg-url-sniffer": "~2.0"
"mrclay/elgg-url-sniffer": "~3.0"
},
"autoload": {
"psr-0": {
Expand Down
31 changes: 20 additions & 11 deletions lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace hypeJunction\Discovery;

use ElggEntity;
use ElggIcon;
use ElggUser;
use UFCOE\Elgg\Url;
use UFCOE\Elgg\SiteUrl;

/**
* Check if the entity can be discovered from a remote resource
Expand Down Expand Up @@ -237,7 +238,7 @@ function get_entity_permalink($entity, $viewtype = 'default') {
$user_hash = get_user_hash($user_guid);

$url = $entity->getVolatileData('discovery:share_url');

if (!$url) {
$title = elgg_get_friendly_title(get_discovery_title($entity));

Expand All @@ -264,21 +265,29 @@ function get_entity_permalink($entity, $viewtype = 'default') {
*/
function get_guid_from_url($url) {

$info = (new Url())->analyze($url);
$site_url = new SiteUrl(elgg_get_site_url());

if (!$info->in_site) {
$path = $site_url->getSitePath($url);
if (!$path) {
return false;
}

if ($info->guid) {
return $info->guid;
} else if ($info->username) {
$user = get_user_by_username($info->username);
$guid = $path->getGuid();
if ($guid) {
return $guid;
}

$username = $path->getUsername();
if ($username) {
$user = get_user_by_username($username);
if ($user) {
return $user->guid;
}
} else if ($info->contianer_guid) {
return $info->container_guid;
}

$container_guid = $path->getContainerGuid();
if ($container_guid) {
return $container_guid;
}

return false;
Expand Down Expand Up @@ -463,7 +472,7 @@ function get_discovery_description($entity) {
* Get discoverable icon object
*
* @param ElggEntity $entity
* @return \ElggIcon|false
* @return ElggIcon|false
*/
function get_discovery_icon($entity) {
foreach (['open_graph_image', 'cover', 'icon'] as $type) {
Expand Down

0 comments on commit 782916a

Please sign in to comment.