/** * Test elgg_http_url_is_identical() for $ignore_params parameter handling */ public function testHttpUrlIsIdenticalIgnoreParamsHandling() { $tests = array(array('page/handler', elgg_get_site_url() . 'page/handler', array('p', 'p2'), true), array('page/handler?p=v&p2=q2', elgg_get_site_url() . 'page/handler?p=q&p2=v2', array('p', 'p2'), true), array('/rootfile.php', elgg_get_site_url() . 'rootfile.php?param=23', array('param'), true), array('/rootfile.php?p=v&p2=v2', elgg_get_site_url() . 'rootfile.php?p=v&p2=q', array('p', 'p2'), true), array('mod/plugin/file.php?other_param=123', elgg_get_site_url() . 'mod/plugin/file.php', array('q', 'p2'), false), array('/rootfile.php', elgg_get_site_url() . 'rootfile.php?param=23', array(), false)); foreach ($tests as $test) { list($url1, $url2, $ignore_params, $result) = $test; $this->assertIdentical(elgg_http_url_is_identical($url1, $url2, $ignore_params), $result, "Failed to determine URLs as " . ($result ? 'identical' : 'different') . " for: '{$url1}', '{$url2}' and ignore params set to " . print_r($ignore_params, true)); $this->assertIdentical(elgg_http_url_is_identical($url2, $url1, $ignore_params), $result, "Failed to determine URLs as " . ($result ? 'identical' : 'different') . " for: '{$url2}', '{$url1}' and ignore params set to " . print_r($ignore_params, true)); } }
<?php $url = current_page_url(); $url_split = explode('?', $url); $pieces = explode('#', array_shift($url_split)); // quick separation of query/fragment elements $current_url = $pieces[0]; $tabs = array(array('name' => 'settings', 'text' => elgg_echo('elgg_solr:settings'), 'href' => 'admin/plugin_settings/elgg_solr', 'selected' => elgg_http_url_is_identical($current_url, elgg_normalize_url('admin/plugin_settings/elgg_solr'))), array('name' => 'controls', 'text' => elgg_echo('elgg_solr:index:controls'), 'href' => 'admin/administer_utilities/solr_index', 'selected' => elgg_http_url_is_identical($current_url, elgg_normalize_url('admin/administer_utilities/solr_index')))); echo elgg_view('navigation/tabs', array('tabs' => $tabs));
/** * @dataProvider providerHttpUrlIsIdenticalIgnoreParamsHandling */ public function testHttpUrlIsIdenticalIgnoreParamsHandling($url1, $url2, $ignore_params, $result) { $this->assertSame(elgg_http_url_is_identical($url1, $url2, $ignore_params), $result, "Failed to determine URLs as " . ($result ? 'identical' : 'different') . " for: '{$url1}', '{$url2}' and ignore params set to " . print_r($ignore_params, true)); $this->assertSame(elgg_http_url_is_identical($url2, $url1, $ignore_params), $result, "Failed to determine URLs as " . ($result ? 'identical' : 'different') . " for: '{$url2}', '{$url1}' and ignore params set to " . print_r($ignore_params, true)); }
/** * Find the menu item that is currently selected * * @return \ElggMenuItem */ protected function findSelected() { // do we have a selected menu item already foreach ($this->menu as $menu_item) { if ($menu_item->getSelected()) { return $menu_item; } } // scan looking for a selected item foreach ($this->menu as $menu_item) { if ($menu_item->getHref()) { if (elgg_http_url_is_identical(current_page_url(), $menu_item->getHref())) { $menu_item->setSelected(true); return $menu_item; } } } return null; }
<?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>';