Ejemplo n.º 1
0
 /**
  * Test elgg_http_add_url_query_elements() removal of parameters
  *
  * @dataProvider providerElggHttpAddURLQueryElementsRemoveElements
  */
 public function testElggHttpAddURLQueryElementsRemoveElements($input, $params, $output)
 {
     $this->assertEquals($output, elgg_http_add_url_query_elements($input, $params));
     if ($params === array('foo' => null)) {
         $this->assertEquals($output, elgg_http_remove_url_query_element($input, 'foo'));
     }
 }
Ejemplo n.º 2
0
/**
 * Take over the groupicon page handler for fallback
 *
 * @param array $page the url elements
 *
 * @return void
 */
function group_tools_groupicon_page_handler($page)
{
    // group guid
    if (!isset($page[0])) {
        header("HTTP/1.1 400 Bad Request");
        exit;
    }
    $group_guid = $page[0];
    $group = get_entity($group_guid);
    if (empty($group) || !elgg_instanceof($group, "group")) {
        header("HTTP/1.1 400 Bad Request");
        exit;
    }
    $owner_guid = $group->getOwnerGUID();
    $icontime = (int) $group->icontime;
    if (empty($icontime)) {
        header("HTTP/1.1 404 Not Found");
        exit;
    }
    // size
    $size = "medium";
    if (isset($page[1])) {
        $icon_sizes = elgg_get_config("icon_sizes");
        if (!empty($icon_sizes) && array_key_exists($page[1], $icon_sizes)) {
            $size = $page[1];
        }
    }
    $params = array("group_guid" => $group_guid, "guid" => $owner_guid, "size" => $size, "icontime" => $icontime);
    $url = elgg_http_add_url_query_elements("mod/group_tools/pages/groups/thumbnail.php", $params);
    forward($url);
}
 /**
  * Prepares notification elements
  * @return \stdClass
  */
 public function prepare()
 {
     $object_type = $this->getObjectType();
     $object_link = elgg_view('output/url', array('text' => $this->object->getDisplayName(), 'href' => elgg_http_add_url_query_elements($this->object->getURL(), array('active_tab' => 'comments'))));
     if ($this->author->guid == $this->object->owner_guid) {
         $object_summary_title = elgg_echo('interactions:ownership:own', array($object_type), $this->language);
     } else {
         if ($this->recipient->guid == $this->object->owner_guid) {
             $object_summary_title = elgg_echo('interactions:ownership:your', array($object_type), $this->language);
         } else {
             $object_owner = $this->object->getOwnerEntity() ?: elgg_get_site_entity();
             $object_summary_title = elgg_echo('interactions:ownership:owner', array($object_owner->getDisplayName(), $object_type), $this->language);
         }
     }
     if ($this->object instanceof Comment) {
         $object_full_title = $object_summary_title;
     } else {
         $object_full_title = $object_summary_title . ' ' . $object_link;
     }
     if ($this->root->guid !== $this->object->guid) {
         $root_link = elgg_view('output/url', array('text' => $this->root->getDisplayName(), 'href' => elgg_http_add_url_query_elements($this->root->getURL(), array('active_tab' => 'comments'))));
         $object_full_title .= ' ' . elgg_echo('interactions:comment:in_thread', array($root_link));
     }
     $author_link = elgg_view('output/url', array('text' => $this->author->name, 'href' => $this->author->getURL()));
     $object_summary_link = elgg_view('output/url', array('text' => $object_summary_title, 'href' => elgg_http_add_url_query_elements($this->object->getURL(), array('active_tab' => 'comments'))));
     $action_type = $this->getActionType();
     $notification = new \stdClass();
     $notification->summary = elgg_echo('interactions:response:email:subject', array($author_link, $action_type, $object_summary_link), $this->language);
     $notification->subject = strip_tags($notification->summary);
     $notification->body = elgg_echo('interactions:response:email:body', array($author_link, $action_type, $object_full_title, $this->getComment(), $this->comment->getURL(), $this->root->getURL(), $this->author->getDisplayName(), $this->author->getURL()), $this->language);
     return $notification;
 }
Ejemplo n.º 4
0
/**
 * Register title menu items for an event
 *
 * @param Event $event
 * @return void
 */
function register_event_title_menu($event, $ts = null, $calendar = null)
{
    if (!$event instanceof Event) {
        return;
    }
    $calendar_count = 0;
    if (elgg_is_logged_in()) {
        $calendar_count = Calendar::getCalendars(elgg_get_logged_in_user_entity(), true);
    }
    if ($calendar_count) {
        // may be different than the calendar being viewed
        // make the add/remove button work for the current calendar if they own it
        // or their default calendar if they're viewing another calendar
        if ($calendar->owner_guid == elgg_get_logged_in_user_guid()) {
            $mycalendar = $calendar;
        } else {
            $mycalendar = Calendar::getPublicCalendar(elgg_get_logged_in_user_entity());
        }
        $text = elgg_echo('events:add_to_calendar:default');
        $add_remove_calendar = $mycalendar->guid;
        if ($mycalendar->hasEvent($event)) {
            $text = elgg_echo('events:remove_from_calendar:default');
            $add_remove_calendar = '';
        }
        elgg_register_menu_item('title', array('name' => 'add_to_calendar', 'href' => elgg_http_add_url_query_elements('action/calendar/add_event', array('event_guid' => $event->guid, 'calendars[]' => $add_remove_calendar)), 'is_action' => true, 'data-object-event' => true, 'data-guid' => $event->guid, 'text' => $text, 'data-calendar-count' => $calendar_count, 'link_class' => 'elgg-button elgg-button-action events-ui-event-action-addtocalendar', 'priority' => 100));
    }
    if ($event->canEdit()) {
        elgg_register_menu_item('title', array('name' => 'delete', 'text' => elgg_echo('events_ui:cancel'), 'href' => 'action/events/cancel?guid=' . $event->guid . '&ts=' . $ts, 'is_action' => true, 'link_class' => 'elgg-button elgg-button-delete elgg-requires-confirmation events-ui-event-action-cancel', 'data-object-event' => true, 'data-guid' => $event->guid, 'priority' => 300));
    }
    if ($event->canEdit() && $event->isRecurring()) {
        elgg_register_menu_item('title', array('name' => 'delete_all', 'text' => elgg_echo('events_ui:cancel:all'), 'href' => 'action/events/delete?guid=' . $event->guid, 'is_action' => true, 'link_class' => 'elgg-button elgg-button-delete elgg-requires-confirmation events-ui-event-action-cancel-all', 'rel' => elgg_echo('events_ui:cancel:all:confirm'), 'data-object-event' => true, 'data-guid' => $event->guid, 'priority' => 400));
    }
}
Ejemplo n.º 5
0
 /**
  * Add a menu item to the user hover dropdown
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current menu items
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function register($hook, $type, $return_value, $params)
 {
     static $user_dirs;
     if (!elgg_is_admin_logged_in()) {
         return;
     }
     if (empty($params) || !is_array($params)) {
         return;
     }
     $user = elgg_extract('entity', $params);
     if (!$user instanceof \ElggUser) {
         return;
     }
     if (!isset($user_dirs)) {
         $user_dirs = [];
     }
     // save in a static for performance when viewing user listings
     if (!isset($user_dirs[$user->getGUID()])) {
         $user_dirs[$user->getGUID()] = false;
         $edl = new \Elgg\EntityDirLocator($user->getGUID());
         $path = $edl->getPath();
         if (is_dir(elgg_get_data_path() . $path)) {
             $path = substr($path, 0, -1);
             $user_dirs[$user->getGUID()] = \ElggMenuItem::factory(['name' => 'dataroot-browser', 'text' => elgg_echo('dataroot_browser:menu:user_hover'), 'href' => elgg_http_add_url_query_elements('admin/administer_utilities/dataroot_browser', ['dir' => $path]), 'is_trusted' => true, 'section' => 'admin']);
         }
     }
     if (empty($user_dirs[$user->getGUID()])) {
         return;
     }
     $return_value[] = $user_dirs[$user->getGUID()];
     return $return_value;
 }
Ejemplo n.º 6
0
function home_annotation_menu_setup($hook, $type, $return, $params)
{
    $annotation = $params['annotation'];
    /* @var ElggAnnotation $annotation */
    if ($annotation->name == 'generic_comment' && $annotation->canEdit()) {
        $url = elgg_http_add_url_query_elements('action/comments/delete', array('annotation_id' => $annotation->id));
        $options = array('name' => 'delete', 'href' => $url, 'text' => elgg_echo('home:delete'), 'title' => elgg_echo('home:delete'), 'confirm' => elgg_echo('deleteconfirm'), 'encode_text' => false);
        $return[] = ElggMenuItem::factory($options);
    }
    return $return;
}
Ejemplo n.º 7
0
Archivo: Router.php Proyecto: 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);
 }
Ejemplo n.º 8
0
 /**
  * Test elgg_http_add_url_query_elements() removal of parameters
  */
 public function testElggHttpAddURLQueryElementsRemoveElements()
 {
     $tests = array(array('?foo=bar', array('foo' => ''), '?foo='), array('?foo=bar', array('foo' => 0), '?foo=0'), array('?foo=bar', array('foo' => false), '?foo=0'), array('?foo=bar', array('foo' => null), '?'), array('/?foo=bar', array('foo' => null), '/'), array('/path?foo=bar', array('foo' => null), '/path'), array('example.com', array('foo' => null), 'example.com'), array('example.com?foo=bar', array('foo' => null), 'example.com'), array('example.com/path?foo=bar', array('foo' => null), 'example.com/path'), array('http://example.com', array('foo' => null), 'http://example.com?'), array('http://example.com?foo=bar', array('foo' => null), 'http://example.com?'), array('http://example.com/?foo=bar#anchor', array('foo' => null), 'http://example.com/#anchor'), array('http://example.com/path?foo=bar', array('foo' => null), 'http://example.com/path'), array('https://example.com?foo=bar', array('foo' => null), 'https://example.com?'), array('https://example.com/path?foo=bar', array('foo' => null), 'https://example.com/path'), array('http://example-time.com?foo=bar', array('foo' => null), 'http://example-time.com?'), array('http://example-time.com/path?foo=bar', array('foo' => null), 'http://example-time.com/path'), array('ftp://example.com/?foo=bar', array('foo' => null), 'ftp://example.com/'), array('ftp://example.com/file?foo=bar', array('foo' => null), 'ftp://example.com/file'), array('app://endpoint?foo=bar', array('foo' => null), 'app://endpoint?'), array('app://endpoint/path?foo=bar', array('foo' => null), 'app://endpoint/path'), array('https://example.com?foo=123&bar=abc', array('foo' => null, 'foo2' => 'bar2'), 'https://example.com?bar=abc&foo2=bar2'), array('https://example.com/path?bar=abc&foo=123', array('foo' => null, 'foo2' => 'bar'), 'https://example.com/path?bar=abc&foo2=bar'), array('https://example.com?foo=123&bar=abc', array('foo' => null, 'foo2' => 'bar2', '123' => 456), 'https://example.com?bar=abc&foo2=bar2&123=456'), array('https://example.com/path?foo=123&bar=abc', array('foo2' => 'bar', 'foo' => null), 'https://example.com/path?bar=abc&foo2=bar'));
     foreach ($tests as $test) {
         list($input, $params, $output) = $test;
         $this->assertEquals($output, elgg_http_add_url_query_elements($input, $params));
         if ($params === array('foo' => null)) {
             $this->assertEquals($output, elgg_http_remove_url_query_element($input, 'foo'));
         }
     }
 }
Ejemplo n.º 9
0
 public function parse($url = '', array $options = array())
 {
     $meta = array('url' => $url);
     if (!$url) {
         return $meta;
     }
     $apikey = $this->config->get('embedly_key');
     $endpoint = $this->config->get('embedly_endpoint');
     $apiurl = elgg_http_add_url_query_elements($endpoint, array('key' => $apikey, 'url' => $url));
     $json = $this->httpResource->read($apiurl, $options);
     return $json ? @json_decode($json, true) : $meta;
 }
Ejemplo n.º 10
0
function relatedgroups_related_menu_setup($hook, $type, $return, $params)
{
    $group = elgg_get_page_owner_entity();
    $othergroup = $params['entity'];
    if ($group instanceof ElggGroup && $group->canEdit() && $othergroup instanceof ElggGroup && elgg_in_context('relatedgroups')) {
        // Delete all previous links
        $return = array();
        $url = elgg_http_add_url_query_elements('action/relatedgroups/remove', array('group' => $group->guid, 'othergroup' => $othergroup->guid));
        $options = array('name' => 'delete', 'href' => $url, 'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>", 'confirm' => elgg_echo('deleteconfirm'), 'text_encode' => false);
        $return[] = ElggMenuItem::factory($options);
    }
    return $return;
}
Ejemplo n.º 11
0
 /**
  * Setup API Consumer entity menu
  *
  * @param string $hook   "register"
  * @param string $type   "menu:entity"
  * @param array  $return Menu
  * @param array  $params Hook params
  * @return array
  */
 function setupEntityMenu($hook, $type, $return, $params)
 {
     $entity = elgg_extract('entity', $params);
     if (!$entity instanceof Consumer) {
         return;
     }
     if (!$entity->canEdit()) {
         return;
     }
     $return[] = ElggMenuItem::factory(array('name' => 'keygen', 'text' => elgg_echo('graph:consumers:keygen'), 'href' => elgg_http_add_url_query_elements('action/admin/graph/consumers/keygen', array('guid' => $entity->guid)), 'is_action' => true, 'priority' => 100));
     $return[] = ElggMenuItem::factory(array('name' => 'edit', 'text' => elgg_echo('edit'), 'href' => elgg_http_add_url_query_elements('admin/graph/consumers/edit', array('guid' => $entity->guid)), 'priority' => 200));
     $return[] = ElggMenuItem::factory(array('name' => 'delete', 'text' => elgg_echo('delete'), 'href' => elgg_http_add_url_query_elements('action/admin/graph/consumers/delete', array('guid' => $entity->guid)), 'is_action' => true, 'data-confirm' => elgg_echo('question:areyousure'), 'priority' => 900));
     return $return;
 }
Ejemplo n.º 12
0
 /**
  * Used to search for community plugins using title/description
  * @param array $options
  * @return array|false
  */
 static function searchPluginProjects($options = array())
 {
     // 		$mt = microtime(true);
     $query = elgg_extract('q', $options, '%');
     if (!$query) {
         $query = '%';
     }
     $url = self::getCommunityPageURL() . 'search';
     $url = elgg_http_add_url_query_elements($url, array('q' => $query, 'category' => elgg_extract('category', $options, ''), 'sort' => elgg_extract('sort', $options, 'relevance'), 'order' => elgg_extract('order', $options, 'desc'), 'entity_type' => 'object', 'entity_subtype' => 'plugin_project', 'search_type' => 'entities', 'view' => 'rss', 'limit' => elgg_extract('limit', $options, 10), 'offset' => elgg_extract('offset', $options, 0)));
     list($content, $meta) = srokap_http::getUrlWithMetadata($url);
     // 		var_dump($url);
     // 		var_dump(microtime(true) - $mt);
     return self::handlePluginProjectsRssResult($content);
 }
Ejemplo n.º 13
0
/**
 * Get publicly accessible URL for the file
 *
 * @param ElggFile $file
 * @return string
 */
function elgg_file_viewer_get_public_url($file)
{
    if (!elgg_instanceof($file, 'object', 'file')) {
        return '';
    }
    if (!elgg_is_logged_in()) {
        return $file->getURL();
    }
    $user = elgg_get_logged_in_user_entity();
    $token = create_user_token($user->username);
    $base_url = elgg_normalize_url("services/api/rest/ob");
    $params = array('method' => 'efv.download', 'guid' => $file->getGUID(), 'auth_token' => $token);
    return elgg_http_add_url_query_elements($base_url, $params);
}
Ejemplo n.º 14
0
Archivo: start.php Proyecto: elgg/elgg
/**
 * Add report user link to hover menu
 */
function reportedcontent_user_hover_menu($hook, $type, $return, $params)
{
    if (!elgg_is_logged_in()) {
        return;
    }
    $user = elgg_extract('entity', $params);
    /* @var ElggUser $user */
    if (elgg_get_logged_in_user_guid() == $user->guid) {
        return;
    }
    $href = elgg_http_add_url_query_elements('reportedcontent/add', ['address' => $user->getURL(), 'title' => $user->name]);
    $return[] = \ElggMenuItem::factory(['name' => 'reportuser', 'text' => elgg_echo('reportedcontent:user'), 'href' => $href, 'section' => 'action', 'link_class' => 'elgg-lightbox', 'deps' => 'elgg/reportedcontent']);
    return $return;
}
Ejemplo n.º 15
0
/**
 * Adds query parameters to URL for redirect
 *
 * @param string $url        The URL
 * @param array  $query_vars Additional query parameters in associate array
 * @return string
 */
function legacy_urls_prepare_url($url, array $query_vars = array())
{
    $params = array();
    // Elgg munges the request in htaccess rules so cannot use $_GET
    $query = parse_url(_elgg_services()->request->server->get('REQUEST_URI'), PHP_URL_QUERY);
    if ($query) {
        parse_str($query, $params);
    }
    $params = array_merge($params, $query_vars);
    if ($params) {
        return elgg_http_add_url_query_elements($url, $params);
    } else {
        return $url;
    }
}
Ejemplo n.º 16
0
 /**
  * Add a menu item to the follow_tag
  *
  * @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 registerFollowTag($hook, $type, $return_value, $params)
 {
     if (!elgg_is_logged_in()) {
         return;
     }
     $tag = elgg_extract('tag', $params);
     if (is_null($tag) || $tag === '') {
         return;
     }
     $encoded_tag = htmlspecialchars($tag, ENT_QUOTES, 'UTF-8', false);
     $following = tag_tools_is_user_following_tag($tag);
     $action_url = elgg_http_add_url_query_elements('action/tag_tools/follow_tag', ['tag' => $encoded_tag]);
     $return_value[] = \ElggMenuItem::factory(['name' => 'follow_tag_on', 'text' => elgg_view_icon('refresh'), 'title' => elgg_echo('tag_tools:follow_tag:menu:on'), 'href' => $action_url, 'is_action' => true, 'item_class' => $following ? 'hidden' : '']);
     $return_value[] = \ElggMenuItem::factory(['name' => 'follow_tag_off', 'text' => elgg_view_icon('refresh-hover'), 'title' => elgg_echo('tag_tools:follow_tag:menu:off'), 'href' => $action_url, 'is_action' => true, 'item_class' => $following ? '' : 'hidden']);
     return $return_value;
 }
Ejemplo n.º 17
0
function init()
{
    /**
     * Pages and URLs
     */
    elgg_register_page_handler(PAGEHANDLER, __NAMESPACE__ . '\\page_handler');
    /**
     * Actions
     */
    elgg_register_action(PLUGIN_ID . '/settings/save', __DIR__ . '/actions/settings/maps.php', 'admin');
    elgg_register_action('maps/geopositioning/update', __DIR__ . '/actions/geopositioning/update.php', 'public');
    /**
     * JS and CSS
     */
    $libs = array_filter(elgg_get_config('google_maps_libraries'));
    $gmaps_lib = elgg_http_add_url_query_elements('//maps.googleapis.com/maps/api/js', array('key' => elgg_get_plugin_setting('google_api_key', PLUGIN_ID), 'libraries' => implode(',', $libs), 'language' => get_current_language(), 'output' => 'svembed'));
    elgg_register_js('google.maps', $gmaps_lib);
    elgg_register_simplecache_view('css/framework/maps/stylesheet');
    elgg_register_css('maps', elgg_get_simplecache_url('css', 'framework/maps/stylesheet'));
    $plugin_root = __DIR__;
    if (file_exists("{$plugin_root}/vendor/autoload.php")) {
        $path = '/mod/' . PLUGIN_ID;
    } else {
        $path = '';
    }
    elgg_register_js('jquery.sticky-kit', $path . '/vendor/bower-asset/sticky-kit/jquery.sticky-kit.min.js', 'footer', 500);
    elgg_register_simplecache_view('js/framework/maps/mapbox');
    elgg_register_js('maps.mapbox', elgg_get_simplecache_url('js', 'framework/maps/mapbox'), 'footer', 550);
    // Add User Location to config
    elgg_extend_view('js/initialize_elgg', 'js/framework/maps/config');
    /**
     * Hooks
     */
    elgg_register_plugin_hook_handler('search:site', 'maps', __NAMESPACE__ . '\\setup_site_search_maps');
    // Replace a list with a map when ?list_type=mapbox
    elgg_register_plugin_hook_handler('view', 'page/components/list', __NAMESPACE__ . '\\list_type_map_view');
    elgg_register_plugin_hook_handler('view', 'page/components/gallery', __NAMESPACE__ . '\\list_type_map_view');
    // Filter out views when loading map items via ajax
    elgg_register_plugin_hook_handler('view', 'all', __NAMESPACE__ . '\\ajax_list_view');
    // Map Markers
    elgg_register_plugin_hook_handler('entity:icon:url', 'user', __NAMESPACE__ . '\\get_marker_url', 600);
    elgg_register_plugin_hook_handler('entity:icon:url', 'object', __NAMESPACE__ . '\\get_marker_url', 600);
    elgg_register_widget_type('staticmap', elgg_echo('maps:widget:staticmap'), elgg_echo('maps:widget:staticmap:desc'), array('all'), true);
}
Ejemplo n.º 18
0
function members_extended_users_setup_entity_menu($hook, $type, $return, $params)
{
    if (elgg_in_context('widgets')) {
        return $return;
    }
    $entity = $params['entity'];
    if (!elgg_instanceof($entity, 'user')) {
        return $return;
    }
    $to_remove = array('banned', 'location');
    foreach ($return as $index => $item) {
        $name = $item->getName();
        if (in_array($name, $to_remove)) {
            unset($return[$index]);
        }
    }
    if ($entity->isBanned()) {
        $banned = elgg_echo('banned');
        $options = array('name' => 'banned', 'text' => "<span>{$banned}</span>", 'href' => false, 'priority' => 0);
        $return = array(ElggMenuItem::factory($options));
    } else {
        $return = array();
        $url_params = array();
        $menu = array();
        if (isset($entity->location)) {
            $page_owner = elgg_get_page_owner_entity();
            if (elgg_instanceof($page_owner, 'group')) {
                $url_params['group_guid'] = $page_owner->guid;
            }
            $user_location = htmlspecialchars($entity->location, ENT_QUOTES, 'UTF-8', false);
            $locations = explode(",", $user_location);
            foreach ($locations as $location) {
                $q = strtolower(trim($location));
                $url_params['q'] = $q;
                $url = elgg_http_add_url_query_elements(elgg_get_site_url() . "member-locations/", $url_params);
                $menu[] = elgg_view('output/url', array('href' => $url, 'text' => $location, 'is_safe' => true));
            }
            $menu = implode(", ", $menu);
            $options = array('name' => 'location', 'text' => "<span>{$menu}</span>", 'href' => false, 'priority' => 150);
            $return[] = ElggMenuItem::factory($options);
        }
    }
    return $return;
}
Ejemplo n.º 19
0
 public function getThumbUrl($url = '', $handle = null)
 {
     $data = $this->resourceCache->get($url, $handle);
     if (!empty($data['thumb_cache'])) {
         $uid = md5($url);
         $path = "scraper_cache/thumbs/{$uid}.{$handle}.jpg";
         $dir = elgg_get_site_entity()->guid;
         $dir_tc = elgg_get_site_entity()->time_created;
         $query = serialize(array('uid' => $uid, 'path' => $path, 'd' => $dir, 'dts' => $dir_tc, 'ts' => $data['thumb_cache'], 'mac' => hash_hmac('sha256', $uid . $path, get_site_secret())));
         $icon_url = elgg_http_add_url_query_elements('/mod/hypeApps/servers/icon.php', array('q' => base64_encode($query)));
     } else {
         if (!empty($data['thumbnail_url'])) {
             $icon_url = $data['thumbnail_url'];
         } else {
             $icon_url = '/mod/hypeScraper/graphics/placeholder.png';
         }
     }
     return elgg_normalize_url($icon_url);
 }
Ejemplo n.º 20
0
 /**
  * add sorting options to the 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 array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function addSorting($hook, $type, $return_value, $params)
 {
     if (!elgg_in_context('group_sort_menu')) {
         return;
     }
     $allowed_sorting_tabs = ['all', 'yours', 'open', 'closed', 'featured'];
     $selected_tab = elgg_extract('selected', $params);
     if (!in_array($selected_tab, $allowed_sorting_tabs)) {
         return;
     }
     $base_url = current_page_url();
     // main sorting menu item
     $return_value[] = \ElggMenuItem::factory(['name' => 'sorting', 'text' => elgg_view_icon('sort'), 'title' => elgg_echo('sort'), 'href' => '#', 'priority' => -1]);
     // add sorting options
     $return_value[] = \ElggMenuItem::factory(['name' => 'newest', 'text' => elgg_view_icon('sort-amount-desc', ['class' => 'mrs']) . elgg_echo('sort:newest'), 'title' => elgg_echo('sort:newest'), 'href' => elgg_http_add_url_query_elements($base_url, ['sort' => 'newest']), 'priority' => 100, 'parent_name' => 'sorting', 'selected' => get_input('sort') === 'newest']);
     $return_value[] = \ElggMenuItem::factory(['name' => 'alpha', 'text' => elgg_view_icon('sort-alpha-asc', ['class' => 'mrs']) . elgg_echo('sort:alpha'), 'title' => elgg_echo('sort:alpha'), 'href' => elgg_http_add_url_query_elements($base_url, ['sort' => 'alpha']), 'priority' => 200, 'parent_name' => 'sorting', 'selected' => get_input('sort') === 'alpha']);
     $return_value[] = \ElggMenuItem::factory(['name' => 'popular', 'text' => elgg_view_icon('sort-numeric-desc', ['class' => 'mrs']) . elgg_echo('sort:popular'), 'title' => elgg_echo('sort:popular'), 'href' => elgg_http_add_url_query_elements($base_url, ['sort' => 'popular']), 'priority' => 300, 'parent_name' => 'sorting', 'selected' => get_input('sort') === 'popular']);
     return $return_value;
 }
Ejemplo n.º 21
0
Archivo: start.php Proyecto: elgg/elgg
/**
 * Adds query parameters to URL for redirect
 *
 * @param string $url        The URL
 * @param array  $query_vars Additional query parameters in associate array
 * @return string
 */
function legacy_urls_prepare_url($url, array $query_vars = array())
{
    $params = array();
    // Elgg munges the request in htaccess rules so cannot use $_GET
    $query = parse_url(_elgg_services()->request->server->get('REQUEST_URI'), PHP_URL_QUERY);
    if ($query) {
        parse_str($query, $params);
    }
    $params = array_merge($params, $query_vars);
    if ($params) {
        if (!empty($params['__elgg_uri'])) {
            // on multiple redirects, __elgg_uri is appended to the URL causing infinite loops #8494
            unset($params['__elgg_uri']);
        }
        return elgg_http_add_url_query_elements($url, $params);
    } else {
        return $url;
    }
}
Ejemplo n.º 22
0
/**
 * Icon URL
 *
 * @param type $hook
 * @param type $hook_type
 * @param type $return
 * @param type $params
 * @return type
 */
function elgg_media_url_handler($hook, $hook_type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    $size = elgg_extract('size', $params, 'medium');
    $type = elgg_extract('type', $params, 'icon');
    $ext = elgg_extract('ext', $params, 'jpg');
    $filename = false;
    if ($size == 'original') {
        $filename = $entity->{"{$type}_originalfilename"};
    } else {
        if (elgg_get_media_file($entity, $type, $size, $ext)) {
            $filename = "{$size}.{$ext}";
        }
    }
    if ($filename) {
        $url = elgg_normalize_url("/mod/elgg_media/media/{$entity->guid}/{$type}/{$filename}");
        // @todo: add hmac
        return elgg_http_add_url_query_elements($url, ['lastcache' => $entity->{"{$type}_time_created"}, 'hmac' => 'todo']);
    }
}
Ejemplo n.º 23
0
/**
 * Initialize the plugin
 * @return void
 */
function seo_init()
{
    elgg_register_page_handler('seo', 'seo_page_handler');
    elgg_register_action('seo/autogen', __DIR__ . '/actions/seo/autogen.php', 'admin');
    elgg_register_action('seo/edit', __DIR__ . '/actions/seo/edit.php', 'admin');
    elgg_register_event_handler('create', 'object', 'seo_update_entity');
    elgg_register_event_handler('update', 'object', 'seo_update_entity');
    elgg_register_event_handler('create', 'user', 'seo_update_entity');
    elgg_register_event_handler('update', 'user', 'seo_update_entity');
    elgg_register_event_handler('create', 'group', 'seo_update_entity');
    elgg_register_event_handler('update', 'group', 'seo_update_entity');
    elgg_register_plugin_hook_handler('view_vars', 'output/url', 'seo_sef_url_rewrite');
    elgg_register_plugin_hook_handler('route', 'all', 'seo_route', 1);
    elgg_register_plugin_hook_handler('head', 'page', 'seo_page_head_setup');
    elgg_register_plugin_hook_handler('page_owner', 'system', 'seo_page_owner_fix');
    elgg_extend_view('elgg.css', 'seo.css');
    if (elgg_is_admin_logged_in()) {
        elgg_register_menu_item('extras', array('name' => 'seo', 'text' => elgg_view_icon('search'), 'title' => elgg_echo('seo:edit'), 'href' => elgg_http_add_url_query_elements('seo/edit', array('page_uri' => current_page_url())), 'link_class' => 'elgg-lightbox'));
    }
}
Ejemplo n.º 24
0
Archivo: start.php Proyecto: elgg/elgg
/**
 * Add the embed menu item to the long text menu
 *
 * @param string $hook
 * @param string $type
 * @param array $items
 * @param array $vars
 * @return array
 */
function embed_longtext_menu($hook, $type, $items, $vars)
{
    if (elgg_get_context() == 'embed') {
        return $items;
    }
    $id = elgg_extract('id', $vars);
    if ($id === null) {
        return;
    }
    $id = elgg_extract('id', $vars);
    if ($id === null) {
        return;
    }
    $url = 'embed';
    $page_owner = elgg_get_page_owner_entity();
    if (elgg_instanceof($page_owner, 'group') && $page_owner->isMember()) {
        $url = elgg_http_add_url_query_elements($url, ['container_guid' => $page_owner->guid]);
    }
    $items[] = ElggMenuItem::factory(array('name' => 'embed', 'href' => 'javascript:', 'data-colorbox-opts' => json_encode(['href' => elgg_normalize_url($url)]), 'text' => elgg_echo('embed:media'), 'rel' => "embed-lightbox-{$id}", 'link_class' => "elgg-longtext-control elgg-lightbox embed-control embed-control-{$id} elgg-lightbox", 'deps' => ['elgg/embed'], 'priority' => 10));
    return $items;
}
Ejemplo n.º 25
0
 /**
  * Return the url for a blog icon (if any)
  *
  * @param string $hook        "entity:icon:url"
  * @param string $entity_type "object"
  * @param string $returnvalue the current icon url
  * @param array  $params      supplied params
  *
  * @return string|void
  */
 public static function blogIcon($hook, $entity_type, $returnvalue, $params)
 {
     if (empty($params) || !is_array($params)) {
         return $returnvalue;
     }
     $entity = elgg_extract("entity", $params);
     if (empty($entity) || !elgg_instanceof($entity, "object", "blog")) {
         return $returnvalue;
     }
     $iconsizes = (array) elgg_get_config("icon_sizes");
     $size = strtolower(elgg_extract("size", $params));
     if (!array_key_exists($size, $iconsizes)) {
         $size = "medium";
     }
     $icontime = (int) $entity->icontime;
     if (!$icontime) {
         return $returnvalue;
     }
     $url = elgg_http_add_url_query_elements("mod/blog_tools/pages/thumbnail.php", array("guid" => $entity->getOwnerGUID(), "blog_guid" => $entity->getGUID(), "size" => $size, "icontime" => $icontime));
     return elgg_normalize_url($url);
 }
Ejemplo n.º 26
0
 /**
  * Normalizes and signs the URL with SHA256 HMAC key
  *
  * @note Signed URLs do not offer CSRF protection and should not be used instead of action tokens.
  * 
  * @param string $url     URL to sign
  * @param string $expires Expiration time
  *                        Accepts a string suitable for strtotime()
  *                        Falsey values indicate non-expiring URL
  * @return string
  * @throws \InvalidArgumentException
  */
 public function sign($url, $expires = false)
 {
     $url = elgg_normalize_url($url);
     $parts = parse_url($url);
     if (isset($parts['query'])) {
         $query = elgg_parse_str($parts['query']);
     } else {
         $query = [];
     }
     if (isset($query[self::KEY_MAC])) {
         throw new \InvalidArgumentException('URL has already been signed');
     }
     if ($expires) {
         $query[self::KEY_EXPIRES] = strtotime($expires);
     }
     ksort($query);
     $parts['query'] = http_build_query($query);
     $url = elgg_http_build_url($parts, false);
     $token = elgg_build_hmac($url)->getToken();
     return elgg_http_add_url_query_elements($url, [self::KEY_MAC => $token]);
 }
/**
 * add in our own page in the friends/collections URI
 * 
 * @param type $hook
 * @param type $type
 * @param type $return
 * @param type $params
 * @return boolean
 */
function friend_collection_message_router($hook, $type, $return, $params)
{
    if (!($return['segments'][0] == 'collections' && $return['segments'][1] == 'message')) {
        return $return;
    }
    $id = $return['segments'][2];
    $collection = get_access_collection($id);
    $owner = get_user($collection->owner_guid);
    $can_message = elgg_trigger_plugin_hook('can_message', 'collection', array('collection_id' => $id), true);
    if (!$collection || !$owner || !$owner->canEdit() || !$can_message) {
        return $return;
    }
    $step = get_input('step', 1);
    // if we don't havea subject/message we will force step 1
    $subject = get_input('subject');
    $message = get_input('message');
    if (!$subject || !$message) {
        $step = 1;
    }
    $title = elgg_echo('friend_collection_message:title', array($collection->name));
    $collections_link = elgg_normalize_url('collections/' . $owner->username);
    elgg_push_breadcrumb(elgg_echo('friends:collections'), $collections_link);
    elgg_push_breadcrumb($title);
    switch ($step) {
        case 2:
            $action = 'action/friend_collection_message/send';
            $content = elgg_view_form('friend_collection_message/send', array('action' => $action), array('collection' => $collection));
            break;
        default:
            $action = elgg_http_remove_url_query_element(current_page_url(), 'step');
            $action = elgg_http_add_url_query_elements($action, array('step' => 2));
            $content = elgg_view_form('friend_collection_message/compose', array('action' => $action), array('collection' => $collection));
            break;
    }
    $layout = elgg_view_layout('content', array('title' => $title, 'content' => $content, 'filter' => false));
    echo elgg_view_page($title, $layout);
    return false;
}
Ejemplo n.º 28
0
/**
 * Send event data to payload URLs
 *
 * @param string $event Event name
 * @param string $type  Event type
 * @param mixed  $obj   Event object
 * @return void
 */
function webhooks_send($event, $type, $obj)
{
    $hmac_key = elgg_get_plugin_setting('hmac_key', 'hypeWebHooks');
    $payload_urls = explode(PHP_EOL, elgg_get_plugin_setting('payload_urls', 'hypeWebHooks', ''));
    if (empty($hmac_key) || empty($payload_urls)) {
        return;
    }
    $data = json_encode(array('event' => $event, 'type' => $type, 'data' => webhooks_prepare_value($obj)));
    $length = strlen($data);
    $opts = array('http' => array('method' => 'POST', 'header' => "Content-type: application/json\r\nContent-Length: {$length}\r\n", 'content' => $data, 'timeout' => 60, 'ignore_errors' => true));
    $context = stream_context_create($opts);
    foreach ($payload_urls as $url) {
        $ts = time();
        $hmac = hash_hmac('sha256', $data, $hmac_key);
        $signed_url = elgg_http_add_url_query_elements($url, array('hmac' => $hmac));
        $post = file_get_contents($signed_url, false, $context);
        if ($post) {
            error_log("Webhooks (payload sent): {$data}");
        } else {
            error_log("Webhooks (error): [{$url}] {$post}");
        }
    }
}
Ejemplo n.º 29
0
/**
 * Setup invitation request actions
 *
 * @param string $hook   "register"
 * @param string $type   "menu:invitationrequest"
 * @param array  $menu   Menu items
 * @param array  $params Hook params
 * @return array
 */
function groups_invitationrequest_menu_setup($hook, $type, $menu, $params)
{
    $group = elgg_extract('entity', $params);
    $user = elgg_extract('user', $params);
    if (!$group instanceof \ElggGroup) {
        return $menu;
    }
    if (!$user instanceof \ElggUser || !$user->canEdit()) {
        return $menu;
    }
    $accept_url = elgg_http_add_url_query_elements('action/groups/join', array('user_guid' => $user->guid, 'group_guid' => $group->guid));
    $menu[] = \ElggMenuItem::factory(array('name' => 'accept', 'href' => $accept_url, 'is_action' => true, 'text' => elgg_echo('accept'), 'link_class' => 'elgg-button elgg-button-submit', 'is_trusted' => true));
    $delete_url = elgg_http_add_url_query_elements('action/groups/killinvitation', array('user_guid' => $user->guid, 'group_guid' => $group->guid));
    $menu[] = \ElggMenuItem::factory(array('name' => 'delete', 'href' => $delete_url, 'is_action' => true, 'confirm' => elgg_echo('groups:invite:remove:check'), 'text' => elgg_echo('delete'), 'link_class' => 'elgg-button elgg-button-delete mlm'));
    return $menu;
}
Ejemplo n.º 30
0
/**
 * Add edit and delete links for forum replies
 */
function groups_annotation_menu_setup($hook, $type, $return, $params)
{
    if (elgg_in_context('widgets')) {
        return $return;
    }
    $annotation = $params['annotation'];
    if ($annotation->name != 'group_topic_post') {
        return $return;
    }
    if ($annotation->canEdit()) {
        $url = elgg_http_add_url_query_elements('action/discussion/reply/delete', array('annotation_id' => $annotation->id));
        $options = array('name' => 'delete', 'href' => $url, 'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>", 'confirm' => elgg_echo('deleteconfirm'), 'encode_text' => false);
        $return[] = ElggMenuItem::factory($options);
        $url = elgg_http_add_url_query_elements('discussion', array('annotation_id' => $annotation->id));
        $options = array('name' => 'edit', 'href' => "#edit-annotation-{$annotation->id}", 'text' => elgg_echo('edit'), 'encode_text' => false, 'rel' => 'toggle');
        $return[] = ElggMenuItem::factory($options);
    }
    return $return;
}