예제 #1
0
파일: start.php 프로젝트: elgg/elgg
/**
 * Redirect the requestor to the new URL
 * Checks the plugin setting to determine the course of action:
 * a) Displays an error page with the new URL
 * b) Forwards to the new URL and displays an error message
 * c) Silently forwards to the new URL
 *
 * @param string $url Relative or absolute URL
 * @return mixed
 */
function legacy_urls_redirect($url)
{
    $method = elgg_get_plugin_setting('redirect_method', 'legacy_urls');
    // we only show landing page or queue warning if html generating page
    $viewtype = elgg_get_viewtype();
    if ($viewtype != 'default' && !elgg_does_viewtype_fallback($viewtype)) {
        $method = 'immediate';
    }
    switch ($method) {
        case 'landing':
            $content = elgg_view('legacy_urls/message', array('url' => $url));
            $body = elgg_view_layout('error', array('content' => $content));
            echo elgg_view_page('', $body, 'error');
            return true;
            break;
        case 'immediate_error':
            // drop through after setting error message
            register_error(elgg_echo('changebookmark'));
        case 'immediate':
        default:
            $url = elgg_normalize_url($url);
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: {$url}");
            exit;
            break;
    }
}
예제 #2
0
파일: Cron.php 프로젝트: coldtrick/static
 /**
  * Add menu items to the filter menu
  *
  * @param string $hook         'cron'
  * @param string $type         'daily'
  * @param string $return_value optional output
  * @param array  $params       supplied params
  *
  * @return void
  */
 public static function daily($hook, $type, $return_value, $params)
 {
     if (!static_out_of_date_enabled()) {
         return;
     }
     $time = elgg_extract('time', $params, time());
     $days = (int) elgg_get_plugin_setting('out_of_date_days', 'static');
     $site = elgg_get_site_entity();
     $options = ['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'limit' => false, 'modified_time_upper' => $time - $days * 24 * 60 * 60, 'modified_time_lower' => $time - ($days + 1) * 24 * 60 * 60, 'order_by' => 'e.time_updated DESC'];
     // ignore access
     $ia = elgg_set_ignore_access(true);
     $batch = new \ElggBatch('elgg_get_entities', $options);
     $users = [];
     foreach ($batch as $entity) {
         $last_editors = $entity->getAnnotations(['annotation_name' => 'static_revision', 'limit' => 1, 'order_by' => 'n_table.time_created DESC']);
         if (empty($last_editors)) {
             continue;
         }
         $users[$last_editors[0]->getOwnerGUID()] = $last_editors[0]->getOwnerEntity();
     }
     // restore access
     elgg_set_ignore_access($ia);
     if (empty($users)) {
         return;
     }
     foreach ($users as $user) {
         $subject = elgg_echo('static:out_of_date:notification:subject');
         $message = elgg_echo('static:out_of_date:notification:message', [$user->name, elgg_normalize_url('static/out_of_date/' . $user->username)]);
         notify_user($user->getGUID(), $site->getGUID(), $subject, $message, [], 'email');
     }
 }
예제 #3
0
 /**
  * Test elgg_normalize_url()
  */
 public function testElggNormalizeURL()
 {
     $conversions = array('http://example.com' => 'http://example.com', 'https://example.com' => 'https://example.com', 'http://example-time.com' => 'http://example-time.com', '//example.com' => '//example.com', 'ftp://example.com/file' => 'ftp://example.com/file', 'mailto:brett@elgg.org' => 'mailto:brett@elgg.org', 'javascript:alert("test")' => 'javascript:alert("test")', 'app://endpoint' => 'app://endpoint', 'example.com' => 'http://example.com', 'example.com/subpage' => 'http://example.com/subpage', 'page/handler' => elgg_get_site_url() . 'page/handler', 'page/handler?p=v&p2=v2' => elgg_get_site_url() . 'page/handler?p=v&p2=v2', 'mod/plugin/file.php' => elgg_get_site_url() . 'mod/plugin/file.php', 'mod/plugin/file.php?p=v&p2=v2' => elgg_get_site_url() . 'mod/plugin/file.php?p=v&p2=v2', 'rootfile.php' => elgg_get_site_url() . 'rootfile.php', 'rootfile.php?p=v&p2=v2' => elgg_get_site_url() . 'rootfile.php?p=v&p2=v2', '/page/handler' => elgg_get_site_url() . 'page/handler', '/page/handler?p=v&p2=v2' => elgg_get_site_url() . 'page/handler?p=v&p2=v2', '/mod/plugin/file.php' => elgg_get_site_url() . 'mod/plugin/file.php', '/mod/plugin/file.php?p=v&p2=v2' => elgg_get_site_url() . 'mod/plugin/file.php?p=v&p2=v2', '/rootfile.php' => elgg_get_site_url() . 'rootfile.php', '/rootfile.php?p=v&p2=v2' => elgg_get_site_url() . 'rootfile.php?p=v&p2=v2');
     foreach ($conversions as $input => $output) {
         $this->assertIdentical($output, elgg_normalize_url($input));
     }
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function post(ParameterBag $params)
 {
     $user = elgg_get_logged_in_user_entity();
     $group = get_entity($params->guid);
     // join or request
     $join = false;
     if ($group->isPublicMembership() || $group->canEdit($user->guid)) {
         // anyone can join public groups and admins can join any group
         $join = true;
     } else {
         if (check_entity_relationship($group->guid, 'invited', $user->guid)) {
             // user has invite to closed group
             $join = true;
         }
     }
     if ($join) {
         if (groups_join_group($group, $user)) {
             $msg = elgg_echo("groups:joined");
         } else {
             throw new GraphException(elgg_echo("groups:cantjoin"));
         }
     } else {
         if (!add_entity_relationship($user->guid, 'membership_request', $group->guid)) {
             throw new GraphException(elgg_echo("groups:joinrequestnotmade"));
         }
         $owner = $group->getOwnerEntity();
         $url = elgg_normalize_url("groups/requests/{$group->guid}");
         $subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language);
         $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language);
         // Notify group owner
         notify_user($owner->guid, $user->getGUID(), $subject, $body);
         $msg = elgg_echo("groups:joinrequestmade");
     }
     return array('nodes' => array('member' => check_entity_relationship($user->guid, 'member', $group->guid), 'invited' => check_entity_relationship($group->guid, 'invited', $user->guid), 'membership_request' => check_entity_relationship($user->guid, 'membership_request', $group->guid)));
 }
예제 #5
0
 /**
  * Test elgg_normalize_url()
  */
 public function testElggNormalizeURL()
 {
     $conversions = array('http://example.com' => 'http://example.com', 'https://example.com' => 'https://example.com', '//example.com' => '//example.com', 'example.com' => 'http://example.com', 'example.com/subpage' => 'http://example.com/subpage', 'page/handler' => elgg_get_site_url() . 'page/handler', 'page/handler?p=v&p2=v2' => elgg_get_site_url() . 'page/handler?p=v&p2=v2', 'mod/plugin/file.php' => elgg_get_site_url() . 'mod/plugin/file.php', 'mod/plugin/file.php?p=v&p2=v2' => elgg_get_site_url() . 'mod/plugin/file.php?p=v&p2=v2', 'rootfile.php' => elgg_get_site_url() . 'rootfile.php', 'rootfile.php?p=v&p2=v2' => elgg_get_site_url() . 'rootfile.php?p=v&p2=v2', '/page/handler' => elgg_get_site_url() . 'page/handler', '/page/handler?p=v&p2=v2' => elgg_get_site_url() . 'page/handler?p=v&p2=v2', '/mod/plugin/file.php' => elgg_get_site_url() . 'mod/plugin/file.php', '/mod/plugin/file.php?p=v&p2=v2' => elgg_get_site_url() . 'mod/plugin/file.php?p=v&p2=v2', '/rootfile.php' => elgg_get_site_url() . 'rootfile.php', '/rootfile.php?p=v&p2=v2' => elgg_get_site_url() . 'rootfile.php?p=v&p2=v2');
     foreach ($conversions as $input => $output) {
         $this->assertIdentical($output, elgg_normalize_url($input));
     }
 }
예제 #6
0
/**
 * Register items for the html head
 *
 * @param string $hook Hook name ('head')
 * @param string $type Hook type ('page')
 * @param array  $data Array of items for head
 * @return array
 */
function community_theme_setup_head($hook, $type, $data)
{
    $data['metas'][] = array('http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge');
    $data['metas'][] = array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');
    $data['links'][] = array('rel' => 'icon', 'href' => elgg_normalize_url('mod/community_theme/graphics/favicon.ico'));
    return $data;
}
예제 #7
0
 /**
  * This functions performs actions when a wire post is created
  *
  * @param string     $event  'create'
  * @param string     $type   'object'
  * @param \ElggObject $object the ElggObject created
  *
  * @return void
  */
 public static function triggerMentionNotificationEvent($event, $type, \ElggObject $object)
 {
     if (!elgg_instanceof($object, 'object', 'thewire')) {
         return;
     }
     // @todo replace with decent Elgg 2.0 notification event handling
     //send out notification to users mentioned in a wire post
     $usernames = [];
     preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames);
     if (empty($usernames)) {
         return;
     }
     $usernames = array_unique($usernames[0]);
     $params = ['object' => $object, 'action' => 'mention'];
     foreach ($usernames as $username) {
         $username = str_ireplace('@', '', $username);
         $user = get_user_by_username($username);
         if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) {
             continue;
         }
         $setting = thewire_tools_get_notification_settings($user->getGUID());
         if (empty($setting)) {
             continue;
         }
         $subject = elgg_echo('thewire_tools:notify:mention:subject');
         $message = elgg_echo('thewire_tools:notify:mention:message', [$user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@{$user->username}")]);
         notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting);
     }
 }
예제 #8
0
 /**
  * Notify the group admins about a membership request
  *
  * @param string            $event        create
  * @param string            $type         membership_request
  * @param \ElggRelationship $relationship the created membership request relation
  *
  * @return void
  */
 public static function membershipRequest($event, $type, $relationship)
 {
     if (!$relationship instanceof \ElggRelationship) {
         return;
     }
     if ($relationship->relationship !== 'membership_request') {
         return;
     }
     // only send a message if group admins are allowed
     if (!group_tools_multiple_admin_enabled()) {
         return;
     }
     $user = get_user($relationship->guid_one);
     $group = get_entity($relationship->guid_two);
     if (empty($user) || !$group instanceof \ElggGroup) {
         return;
     }
     // Notify group admins
     $options = ['relationship' => 'group_admin', 'relationship_guid' => $group->getGUID(), 'inverse_relationship' => true, 'type' => 'user', 'limit' => false, 'wheres' => ["e.guid <> {$group->getOwnerGUID()}"]];
     $url = elgg_normalize_url("groups/requests/{$group->getGUID()}");
     $subject = elgg_echo('groups:request:subject', [$user->name, $group->name]);
     $admins = new \ElggBatch('elgg_get_entities_from_relationship', $options);
     foreach ($admins as $a) {
         $body = elgg_echo('groups:request:body', [$a->name, $user->name, $group->name, $user->getURL(), $url]);
         notify_user($a->getGUID(), $user->getGUID(), $subject, $body);
     }
 }
예제 #9
0
파일: start.php 프로젝트: lorea/Hydra-dev
/**
 * replace any http images with https urls
 * 
 * @param type $h
 * @param type $t
 * @param type $r
 * @param type $p
 * @return type
 */
function view_hook($h, $t, $r, $p)
{
    $http_url = str_replace('https://', 'http://', elgg_get_site_url());
    if (preg_match_all('/<img[^>]+src\\s*=\\s*["\']?([^"\' ]+)[^>]*>/', $r, $extracted_image)) {
        foreach ($extracted_image[0] as $key => $i) {
            if (strpos($extracted_image[1][$key], elgg_get_site_url()) !== false) {
                continue;
                // already one of our links
            }
            // check if this is our url being requested over http, and rewrite to https
            if (strpos($extracted_image[1][$key], $http_url) === 0) {
                $https_image = str_replace('http://', 'https://', $extracted_image[1][$key]);
                $replacement_image = str_replace($extracted_image[1][$key], $https_image, $i);
                $r = str_replace($i, $replacement_image, $r);
                continue;
            }
            if (!is_https($extracted_image[1][$key])) {
                // replace this url
                $url = urlencode($extracted_image[1][$key]);
                if (strpos($url, 'http') === 0) {
                    $token = get_token($extracted_image[1][$key]);
                    $new_url = elgg_normalize_url('mod/image_proxy/image.php?url=' . $url . '&token=' . $token);
                    $replacement_image = str_replace($extracted_image[1][$key], $new_url, $i);
                    $r = str_replace($i, $replacement_image, $r);
                }
            }
        }
    }
    return $r;
}
예제 #10
0
 /**
  * {@inheritdoc}
  */
 protected function handle()
 {
     $uri = '/' . ltrim($this->argument('uri'), '/');
     $method = $this->argument('method') ?: 'GET';
     $add_csrf_tokens = $this->option('tokens');
     $site_url = elgg_get_site_url();
     $uri = substr(elgg_normalize_url($uri), strlen($site_url));
     $path_key = Application::GET_PATH_KEY;
     $parameters = [];
     $query = trim((string) $this->option('query'), '?');
     parse_str($query, $parameters);
     if ($add_csrf_tokens) {
         $ts = time();
         $parameters['__elgg_ts'] = $ts;
         $parameters['__elgg_token'] = _elgg_services()->actions->generateActionToken($ts);
     }
     $request = Request::create("?{$path_key}=" . urlencode($uri), $method, $parameters);
     $cookie_name = _elgg_services()->config->getCookieConfig()['session']['name'];
     $session_id = _elgg_services()->session->getId();
     $request->cookies->set($cookie_name, $session_id);
     $request->headers->set('Referer', elgg_normalize_url());
     if ($this->option('export')) {
         elgg_set_viewtype('json');
         $request->headers->set('X-Elgg-Ajax-API', '2');
     }
     _elgg_services()->setValue('request', $request);
     Application::index();
 }
예제 #11
0
/**
 * This functions performs actions when a wire post is created
 *
 * @param string     $event  'create'
 * @param string     $type   'object'
 * @param ElggObject $object the ElggObject created
 *
 * @return void
 */
function thewire_tools_create_object_event_handler($event, $type, ElggObject $object)
{
    if (empty($object) || !elgg_instanceof($object, "object", "thewire")) {
        return;
    }
    //send out notification to users mentioned in a wire post
    $usernames = array();
    preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames);
    if (empty($usernames)) {
        return;
    }
    $usernames = array_unique($usernames[0]);
    $params = array("object" => $object, "action" => "mention");
    foreach ($usernames as $username) {
        $username = str_ireplace("@", "", $username);
        $user = get_user_by_username($username);
        if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) {
            continue;
        }
        $setting = thewire_tools_get_notification_settings($user->getGUID());
        if (empty($setting)) {
            continue;
        }
        $subject = elgg_echo("thewire_tools:notify:mention:subject");
        $message = elgg_echo("thewire_tools:notify:mention:message", array($user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@" . $user->username)));
        notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting);
    }
}
예제 #12
0
/**
 * Image URL handler
 *
 * @param string $hook   "entity:url"
 * @param string $type   "object"
 * @param string $return URL
 * @param array  $params Hook params
 * @return array
 */
function images_ui_entity_url($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    if (!images()->isImage($entity)) {
        return;
    }
    return elgg_normalize_url("/images/view/{$entity->guid}");
}
예제 #13
0
/**
 * Get path location of marker icons
 * @return string
 */
function get_marker_icons_path($url = false)
{
    $path = elgg_get_plugin_setting('icons_path', PLUGIN_ID);
    if (!$path) {
        $path = PLUGIN_ID . '/graphics/icons/';
    }
    return $url ? elgg_normalize_url('mod/' . $path) : elgg_get_plugins_path() . $path;
}
예제 #14
0
/**
 * Update category icon URL
 *
 * @param string $hook		Equals 'entity:icon:url'
 * @param string $type		Equals 'object'
 * @param string $return	Current icon URL
 * @param array $params		Additional params
 * @return string			Updated icon URL
 */
function category_icon_url($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    $size = elgg_extract('size', $params, 'medium');
    if (!elgg_instanceof($entity, 'object', HYPECATEGORIES_SUBTYPE)) {
        return $return;
    }
    return elgg_normalize_url(PAGEHANDLER . '/icon/' . $entity->guid . '/' . $size);
}
예제 #15
0
파일: Wizard.php 프로젝트: lorea/Hydra-dev
 /**
  * Get url
  *
  * @see ElggEntity::getURL()
  * @return string
  */
 public function getURL()
 {
     $friendly_title = $this->friendly_title;
     if (!empty($friendly_title)) {
         return elgg_normalize_url("wizard/{$this->friendly_title}");
     }
     // something went wrong, use fallback url
     $friendly_title = elgg_get_friendly_title($this->title);
     return elgg_normalize_url("wizard/view/{$this->getGUID()}/{$friendly_title}");
 }
 /**
  * ElggMenuItem constructor
  *
  * @param string $name Identifier of the menu item
  * @param string $text Display text of the menu item (HTML)
  * @param string $href URL of the menu item (false if not a link)
  */
 public function __construct($name, $text, $href)
 {
     $this->text = $text;
     if ($href) {
         $this->href = elgg_normalize_url($href);
     } else {
         $this->href = $href;
     }
     $this->data['name'] = $name;
 }
예제 #17
0
/**
 * Forwards the user to twitter to authenticate
 *
 * This includes the login URL as the callback
 */
function twitter_api_forward()
{
    // sanity check
    if (!twitter_api_allow_sign_on_with_twitter()) {
        forward();
    }
    $callback = elgg_normalize_url("twitter_api/login");
    $request_link = twitter_api_get_authorize_url($callback);
    forward($request_link, 'twitter_api');
}
예제 #18
0
파일: start.php 프로젝트: rasul/Elgg
/**
 * Add a reminder to set default categories.
 */
function categories_on_activate()
{
    $site = elgg_get_site_entity();
    if (!$site->categories) {
        $url = elgg_normalize_url('admin/plugin_settings/categories');
        $message = elgg_echo('categories:on_enable_reminder', array($url));
        elgg_add_admin_notice('categories_admin_notice_no_categories', $message);
    }
    return TRUE;
}
예제 #19
0
function h5p_get_core_settings()
{
    global $user, $base_url;
    $settings = array('baseUrl' => $base_url, 'postUserStatistics' => $user->uid > 0, 'ajaxPath' => elgg_normalize_url('h5p-ajax') . '/', 'ajax' => array('contentUserData' => str_replace('%3A', ':', elgg_normalize_url('h5p-ajax/content-user-data/:contentId/:dataType/:subContentId'))), 'l10n' => array('H5P' => array('fullscreen' => elgg_echo('Fullscreen'), 'disableFullscreen' => elgg_echo('Disable fullscreen'), 'download' => elgg_echo('Download'), 'copyrights' => elgg_echo('Rights of use'), 'embed' => elgg_echo('Embed'), 'size' => elgg_echo('Size'), 'showAdvanced' => elgg_echo('Show advanced'), 'hideAdvanced' => elgg_echo('Hide advanced'), 'advancedHelp' => elgg_echo('Include this script on your website if you want dynamic sizing of the embedded content:'), 'copyrightInformation' => elgg_echo('Rights of use'), 'close' => elgg_echo('Close'), 'title' => elgg_echo('Title'), 'author' => elgg_echo('Author'), 'year' => elgg_echo('Year'), 'source' => elgg_echo('Source'), 'license' => elgg_echo('License'), 'thumbnail' => elgg_echo('Thumbnail'), 'noCopyrights' => elgg_echo('No copyright information available for this content.'), 'downloadDescription' => elgg_echo('Download this content as a H5P file.'), 'copyrightsDescription' => elgg_echo('View copyright information for this content.'), 'embedDescription' => elgg_echo('View the embed code for this content.'), 'h5pDescription' => elgg_echo('Visit H5P.org to check out more cool content.'), 'contentChanged' => elgg_echo('This content has changed since you last used it.'), 'startingOver' => elgg_echo("You'll be starting over."), 'by' => elgg_echo('by'), 'showMore' => elgg_echo('Show more'), 'showLess' => elgg_echo('Show less'), 'subLevel' => elgg_echo('Sublevel'))));
    if ($user->uid) {
        $settings['user'] = array('name' => $user->name, 'mail' => $user->mail);
    } else {
        $settings['siteUrl'] = elgg_normalize_url('<front>', array('absolute' => TRUE));
    }
    return $settings;
}
예제 #20
0
파일: Shortener.php 프로젝트: n8b/VMN
 /**
  * Get a shortened URL
  * 
  * @param string $url URL
  * @return string
  */
 public static function getShortURL($url)
 {
     $hash = Hasher::getHashFromURL($url);
     if (!$hash && $this->shorten) {
         $hash = Hasher::hash($url);
     }
     if ($hash) {
         return elgg_normalize_url(implode('/', array(PAGEHANDLER, $hash)));
     }
     return $url;
 }
예제 #21
0
파일: Router.php 프로젝트: n8b/VMN
 /**
  * Prefixes the URL with the page handler ID and normalizes it
  *
  * @param mixed $url   URL as string or array of segments
  * @param array $query Query params to add to the URL
  * @return string
  */
 public function normalize($url = '', $query = array())
 {
     if (is_array($url)) {
         $url = implode('/', $url);
     }
     $url = implode('/', array($this->getPageHandlerId(), $url));
     if (!empty($query)) {
         $url = elgg_http_add_url_query_elements($url, $query);
     }
     return elgg_normalize_url($url);
 }
예제 #22
0
 /**
  * Get the icon URL
  *
  * @param string $size the size of the image
  *
  * @see ElggEntity::getIconURL()
  *
  * @return string
  */
 public function getIconURL($size = "medium")
 {
     switch ($size) {
         case "tiny":
             $result = "mod/user_support/_graphics/faq/tiny.png";
             break;
         default:
             $result = "mod/user_support/_graphics/faq/small.png";
             break;
     }
     return elgg_normalize_url($result);
 }
예제 #23
0
/**
 * Get icon URL hook
 *
 * @param string $hook   Equals 'entity:icon:url'
 * @param string $type   Equals 'object'
 * @param array  $return Current URL
 * @param array  $params Additional params
 * @return array Updated URL
 * @return string
 */
function entity_icon_url($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    $size = elgg_extract('size', $params, 'medium');
    if (elgg_instanceof($entity, 'object', Place::SUBTYPE)) {
        if (!$entity->icontime) {
            return elgg_normalize_url('mod/' . PLUGIN_ID . '/graphics/icon/' . $size . '.png');
        }
        return elgg_normalize_url("places/icon/{$entity->guid}/{$size}");
    }
    return $return;
}
예제 #24
0
/**
 * Give wall posts their own URL
 *
 * @param string $hook		Equals 'entity:url'
 * @param string $type		Equals 'object'
 * @param string $return	Current URL
 * @param array $params		Additional params
 * @return string			Filtered URL
 */
function url_handler($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    if (elgg_instanceof($entity, 'object', 'hjwall')) {
        $container = $entity->getContainerEntity();
        if (elgg_instanceof($container, 'group')) {
            return elgg_normalize_url(PAGEHANDLER . '/group/' . $container->guid . '/' . $entity->guid);
        } else {
            if (elgg_instanceof($container, 'user')) {
                return elgg_normalize_url(PAGEHANDLER . '/owner/' . $container->username . '/' . $entity->guid);
            }
        }
    }
    return $return;
}
예제 #25
0
function widget_favorites_pagesetup()
{
    if (widget_favorites_has_widget()) {
        if ($favorite = widget_favorites_is_linked()) {
            $text = elgg_view_icon("star-alt");
            $href = "action/favorite/toggle?guid=" . $favorite->getGUID();
            $title = elgg_echo("widgets:favorites:menu:remove");
        } else {
            $text = elgg_view_icon("star-empty");
            $href = "action/favorite/toggle?link=" . elgg_normalize_url(current_page_url());
            $title = elgg_echo("widgets:favorites:menu:add");
        }
        elgg_register_menu_item("extras", array("name" => "widget_favorites", "title" => $title, "href" => $href, "text" => $text));
    }
}
예제 #26
0
 public function testCanSetMetadataUrl()
 {
     $owner = $this->mocks()->getUser();
     $object = $this->mocks()->getObject(['owner_guid' => $owner->guid]);
     $id = create_metadata($object->guid, 'foo', 'bar', '', $owner->guid);
     $metadata = elgg_get_metadata_from_id($id);
     _elgg_services()->hooks->backup();
     _elgg_services()->hooks->registerHandler('extender:url', 'metadata', function ($hook, $type, $return, $params) use($metadata) {
         $this->assertEquals($metadata, $params['extender']);
         if ($params['extender']->getSubtype() == 'foo') {
             return 'foo';
         }
     });
     $this->assertEquals(elgg_normalize_url('foo'), $metadata->getURL());
     _elgg_services()->hooks->restore();
 }
예제 #27
0
 /**
  * Add a menu item to the filter menu
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current return value
  * @param mixed           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function registerActivityTab($hook, $type, $return_value, $params)
 {
     if (!elgg_is_logged_in() || !elgg_in_context('activity')) {
         return;
     }
     $tags = tag_tools_get_user_following_tags();
     if (empty($tags)) {
         return;
     }
     $selected = false;
     if (strpos(current_page_url(), elgg_normalize_url('activity/tags')) === 0) {
         $selected = true;
     }
     $return_value[] = \ElggMenuItem::factory(['name' => 'tags', 'text' => elgg_echo('tags'), 'href' => 'activity/tags', 'selected' => $selected, 'priority' => 9999]);
     return $return_value;
 }
예제 #28
0
 /**
  * Handles entity URLs
  *
  * @param string $hook   "entity:url"
  * @param string $type   "object"
  * @param string $url    Current URL
  * @param array  $params Hook params
  * @return string Filtered URL
  */
 public static function urlHandler($hook, $type, $url, $params)
 {
     $entity = elgg_extract('entity', $params);
     /* @var ElggEntity $entity */
     if ($entity instanceof Comment) {
         $container = $entity->getContainerEntity();
         if ($container instanceof Comment) {
             return $container->getURL();
         }
         return elgg_normalize_url(implode('/', array('stream', 'comments', $entity->container_guid, $entity->guid))) . "#elgg-object-{$entity->guid}";
     } else {
         if ($entity instanceof RiverObject) {
             return elgg_normalize_url(implode('/', array('activity', 'view', $entity->river_id))) . "#item-river-{$entity->guid}";
         }
     }
     return $url;
 }
예제 #29
0
/**
 * Send notifications on adding a mutual crushes
 *
 * @param type $event
 * @param type $type
 * @param type $return
 * @return type
 */
function check_mutual_crushes($event, $type, $object)
{
    $mutual_crusher = get_entity($object->guid_one);
    $original_crusher = get_entity($object->guid_two);
    // mutuals!
    if (check_entity_relationship($original_crusher->getGUID(), 'crushing_on', $mutual_crusher->getGUID())) {
        $msg_url = elgg_normalize_url('messages/compose/?send_to=');
        // original
        $subject = elgg_echo('crushes:notifications:mutual_match_subject');
        $body = elgg_echo('crushes:notifications:mutual_match_body', array($original_crusher->name, $mutual_crusher->name, $mutual_crusher->getURL(), $msg_url . $mutual_crusher->guid));
        notify_user($original_crusher->getGUID(), $mutual_crusher->getGUID(), $subject, $body);
        // late comer
        $subject = elgg_echo('crushes:notifications:mutual_match_subject');
        $body = elgg_echo('crushes:notifications:mutual_match_body', array($mutual_crusher->name, $original_crusher->name, $original_crusher->getURL(), $msg_url . $original_crusher->guid));
        notify_user($mutual_crusher->getGUID(), $original_crusher->getGUID(), $subject, $body);
    }
}
예제 #30
0
 /**
  * Provide an URL for a widget title
  *
  * @param string $hook_name    'widget_url'
  * @param string $entity_type  'widget_manager'
  * @param string $return_value the current url (if any)
  * @param mixed  $params       provided params
  *
  * @return string
  */
 public static function widgetURL($hook_name, $entity_type, $return_value, $params)
 {
     if (!empty($return_value)) {
         return;
     }
     $user = elgg_get_logged_in_user_entity();
     if (empty($user)) {
         return;
     }
     $widget = elgg_extract('entity', $params);
     if (!elgg_instanceof($widget, 'object', 'widget')) {
         return;
     }
     if ($widget->handler == 'newsletter_subscribe') {
         return elgg_normalize_url("newsletter/subscriptions/{$user->username}");
     }
 }