public function testCanNotValidateAlteredUrl() { $signed_url = $this->service->sign($this->url, '+1 hour'); $this->assertTrue($this->service->isValid($signed_url)); $signed_url = elgg_http_remove_url_query_element($signed_url, UrlSigner::KEY_EXPIRES); $this->assertFalse($this->service->isValid($signed_url)); }
/** * 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')); } }
/** * 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')); } } }
public static function registerPageMenu($h, $t, $v, $p) { if (!self::$add_toggle) { return; } $url = elgg_http_remove_url_query_element(current_page_url(), 'list_type'); if (get_input('list_type', 'list') == 'list') { $list_type = "gallery"; $icon = elgg_view_icon('grid'); } else { $list_type = "list"; $icon = elgg_view_icon('list'); } if (substr_count($url, '?')) { $url .= "&list_type=" . $list_type; } else { $url .= "?list_type=" . $list_type; } $item = \ElggMenuItem::factory(array('name' => 'file_list', 'text' => elgg_echo("file:list:{$list_type}") . " {$icon}", 'href' => $url, 'priority' => 1000, 'section' => 'view_toggle')); $v[] = $item; return $v; }
/** * 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; }
$type_str = elgg_echo('search:unknown_entity'); } // allow overrides for titles $search_type_str = elgg_echo("search_types:{$vars['params']['search_type']}"); if (array_key_exists('search_type', $vars['params']) && $search_type_str != "search_types:{$vars['params']['search_type']}") { $type_str = $search_type_str; } // get any more links. $more_link = ""; if (get_input("search_type") !== "entities") { $more_check = $vars['results']['count'] - ($vars['params']['offset'] + $vars['params']['limit']); $more = $more_check > 0 ? $more_check : 0; if ($more) { $title_key = $more == 1 ? 'comment' : 'comments'; $more_str = elgg_echo('search:more', array($count, $type_str)); $more_url = elgg_http_remove_url_query_element($url, 'limit'); $more_link = "<li class='elgg-item search-list-more'><a href=\"{$more_url}\">{$more_str}</a></li>"; } else { $more_link = ''; } } // @todo once elgg_view_title() supports passing a $vars array use it $body = elgg_view('page/elements/title', array('title' => $type_str, 'class' => 'search-heading-category')); $body .= '<ul class="elgg-list search-list">'; foreach ($entities as $entity) { $view_params = array("type" => $entity->type, "subtype" => $entity->getSubtype(), "search_type" => $vars['params']["search_type"]); $view = search_get_search_view($view_params, 'entity'); if ($view) { $id = "elgg-{$entity->getType()}-{$entity->getGUID()}"; $body .= "<li id=\"{$id}\" class=\"elgg-item\">"; if ($combine_search_results && get_input("search_type", "all") == "all") {
/** * Adds a toggle to extra menu for switching between list and gallery views */ function file_register_toggle() { $url = elgg_http_remove_url_query_element(current_page_url(), 'list_type'); if (get_input('list_type', 'list') == 'list') { $list_type = "gallery"; $icon = elgg_view_icon('grid'); } else { $list_type = "list"; $icon = elgg_view_icon('list'); } if (substr_count($url, '?')) { $url .= "&list_type=" . $list_type; } else { $url .= "?list_type=" . $list_type; } elgg_register_menu_item('extras', array('name' => 'file_list', 'text' => $icon, 'href' => $url, 'title' => elgg_echo("file:list:{$list_type}"), 'priority' => 1000)); }
<?php /** * Elgg list view switcher * * @package Elgg * @subpackage Core */ $baseurl = elgg_http_remove_url_query_element($vars['baseurl'], 'search_listtype'); if ($vars['listtype'] == "list") { $listtype = "gallery"; } else { $listtype = "list"; } if (substr_count($baseurl, '?')) { $baseurl .= "&search_listtype=" . $listtype; } else { $baseurl .= "?search_listtype=" . $listtype; } ?> <p class="mtm"> <?php echo elgg_echo("listtype:change"); ?> : <a href="<?php echo $baseurl; ?> "><?php echo elgg_echo("listtype:{$listtype}");
/** * Returns base URL of the list * @return string */ public function getBaseURL() { $options = $this->getOptions(); $base_url = elgg_extract('base_url', $options); $offset_key = elgg_extract('offset_key', $options, 'offset'); if (!$base_url) { $base_url = current_page_url(); } $base_url = elgg_http_remove_url_query_element($base_url, 'query'); $base_url = elgg_http_remove_url_query_element($base_url, 'sort'); $base_url = elgg_http_remove_url_query_element($base_url, 'limit'); $base_url = elgg_http_remove_url_query_element($base_url, $offset_key); return $base_url; }
* * @package Elgg.Core * * @uses $vars['title'] The title of the RSS feed * @uses $vars['body'] The items for the RSS feed as a string * @uses $vars['descrption'] The description for the RSS feed */ // Set title if (empty($vars['title'])) { $title = elgg_get_config('sitename'); } else { $title = elgg_get_config('sitename') . ": " . $vars['title']; } // Remove RSS from URL $rssurl = current_page_url(); $url = elgg_http_remove_url_query_element($rssurl, 'view'); $rssurl = htmlspecialchars($url, ENT_NOQUOTES, 'UTF-8'); $url = htmlspecialchars($url, ENT_NOQUOTES, 'UTF-8'); $body = elgg_extract('body', $vars, ''); $description = elgg_extract('description', $vars, ''); $namespaces = elgg_view('extensions/xmlns'); $extensions = elgg_view('extensions/channel'); // allow caching as required by stupid MS products for https feeds. elgg_set_http_header('Pragma: public'); elgg_set_http_header("Content-Type: text/xml;charset=utf-8"); echo "<?xml version='1.0'?>"; echo <<<END <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" {$namespaces}> <channel> \t<title><![CDATA[{$title}]]></title> \t<link>{$url}</link>
$list_class = (array) elgg_extract('list_class', $options, array()); $list_class[] = "elgg-list-groups-{$rel}"; $options['list_class'] = implode(' ', $list_class); } $query = elgg_extract('query', $vars, get_input('query')); $vars['query'] = $query; $sort = elgg_extract('sort', $vars, get_input('sort', 'alpha::asc')); $vars['sort'] = $sort; $base_url = elgg_extract('base_url', $options); if (!$base_url) { $base_url = current_page_url(); } $base_url = elgg_http_remove_url_query_element($base_url, 'query'); $base_url = elgg_http_remove_url_query_element($base_url, 'sort'); $base_url = elgg_http_remove_url_query_element($base_url, 'limit'); $base_url = elgg_http_remove_url_query_element($base_url, elgg_extract('offset_key', $options, 'offset')); $form = elgg_view_form('group/sort', array('action' => $base_url, 'method' => 'GET', 'disable_security' => true), $vars); $user = elgg_extract('user', $vars, elgg_get_page_owner_entity()); $options['user'] = $user ?: null; $options = group_sort_add_rel_options($options, $rel, $user ?: null); list($sort_field, $sort_direction) = explode('::', $sort); $options = group_sort_add_sort_options($options, $sort_field, $sort_direction); if (!empty($query) && elgg_is_active_plugin('search')) { $options['query'] = $query; if (version_compare(elgg_get_version(true), '2.1', '>=')) { // search hooks in earlier versions reset 'joins' and 'wheres' and 'order_by' $results = elgg_trigger_plugin_hook('search', 'group', $options, array()); $entities = elgg_extract('entities', $results); $list = elgg_view_entity_list($entities, $options); } else { $options = group_sort_add_search_query_options($options, $query);
$limit = get_input('limit', 5); $offset = get_input('offset', 0); if ($query) { $query = stripslashes($query); if (function_exists('mb_convert_encoding')) { $display_query = mb_convert_encoding($query, 'HTML-ENTITIES', 'UTF-8'); } else { $display_query = preg_replace("/[^-]/", "", $query); } $display_query = htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false); } $action = current_page_url(); $action = elgg_http_remove_url_query_element($action, 'query'); $action = elgg_http_remove_url_query_element($action, 'subtype'); $action = elgg_http_remove_url_query_element($action, 'limit'); $action = elgg_http_remove_url_query_element($action, 'offset'); echo elgg_view_form('embed/search_content_items', array('method' => 'get', 'disable_security' => true, 'action' => $action, 'class' => 'elgg-form-embed-search'), array('query' => $display_query, 'subtype' => $subtype)); $container_guids = array(elgg_get_logged_in_user_guid()); $page_owner = elgg_get_page_owner_entity(); if (elgg_instanceof($page_owner) && $page_owner->canWriteToContainer('object', 'file')) { $container_guids[] = $page_owner->guid; } $subtypes = elgg_get_config('registered_entities'); $object_subtypes = elgg_extract('object', $subtypes, array()); if (!in_array($subtype, $object_subtypes)) { $subtype = $object_subtypes; } $dbprefix = elgg_get_config('dbprefix'); $options = array('types' => 'object', 'subtypes' => $subtype, 'limit' => $limit, 'offset' => $offset, 'container_guids' => $container_guids, 'joins' => array(), 'wheres' => array(), 'count' => true); if ($query) { $string = sanitize_string($display_query);
<?php if (!get_input('site_menu')) { echo elgg_view('output/url', array('text' => 'Show Site Menu', 'href' => elgg_http_add_url_query_elements(current_page_url(), array('site_menu' => 1)), 'is_trusted' => true)); } else { echo elgg_view('output/url', array('text' => 'Hide Site Menu', 'href' => elgg_http_remove_url_query_element(current_page_url(), 'site_menu'), 'is_trusted' => true)); }
<?php $current_url = current_page_url(); $url_array = parse_url(current_page_url()); // remove all query strings if (isset($url_array['query'])) { $query = elgg_parse_str($url_array['query']); foreach ($query as $key => $value) { $current_url = elgg_http_remove_url_query_element($current_url, $key); } } $tabs = array(array('name' => 'settings', 'href' => 'admin/plugin_settings/trusted_users', 'text' => elgg_echo('settings'), 'selected' => elgg_http_url_is_identical($current_url, elgg_normalize_url('admin/plugin_settings/trusted_users'))), array('name' => 'users', 'href' => 'admin/users/trusted', 'text' => elgg_echo('trusted_users:trusted:users'), 'selected' => elgg_http_url_is_identical($current_url, elgg_normalize_url('admin/users/trusted')))); // lets let other plugins use the same tabs for their settings pages $tabs = elgg_trigger_plugin_hook('trusted_users', 'settings_tabs', array(), $tabs); echo elgg_view('navigation/tabs', array('tabs' => $tabs)); echo '<br><br>';
/** * Normalize base_url * * @param string $base_url Base URL * @return string */ function hypelists_prepare_base_url($base_url = null) { if (empty($base_url)) { // navigation/pagination sets this to Referrer on XHR calls // that causes trouble $base_url = current_page_url(); } // Need absolute URL (embed causes trouble) $base_url = elgg_normalize_url($base_url); $base_url = elgg_http_remove_url_query_element($base_url, 'limit'); $base_url = elgg_http_remove_url_query_element($base_url, 'offset'); return $base_url; }
foreach ($users as $user) { $form_body .= elgg_view('bulk_user_admin/user', array('entity' => $user)); } $form_body .= '</table>'; $delete_button = elgg_view('input/submit', array('value' => 'Delete checked')); $form_body .= $delete_button; $site = elgg_get_config('site'); $checked_form = elgg_view('input/form', array('action' => $site->url . 'action/bulk_user_admin/delete', 'body' => $form_body)); $domain_form = ''; if ($domain) { $delete_button = "<br /><br />" . elgg_view('input/submit', array('value' => 'Delete all in domain')); $hidden = elgg_view('input/hidden', array('name' => 'domain', 'value' => $domain)); $form_body = $delete_button . $hidden; $domain_form = elgg_view('input/form', array('action' => $site->url . 'action/bulk_user_admin/delete_by_domain', 'body' => $form_body)); } $summary = "<div>{$users_count} user(s) found</div>"; if ($domain) { $summary .= '<br />'; $summary .= elgg_view('output/url', array('href' => elgg_http_remove_url_query_element(current_page_url(), 'domain'), 'text' => elgg_echo('bulk_user_admin:all_users'))); } elgg_set_context('admin'); echo $title . $summary . $pagination . $checked_form . $domain_form . $pagination; ?> <script> $('.check-all').click(function(){ $('.elgg-form input[class!=check-all]').each(function(){ $(this).attr('checked') ? $(this).removeAttr('checked') : $(this).attr('checked', 'checked'); }); }); </script>