We have moved to Github. Please open tickets there.

Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#3903 closed Defect (worksforme)

url queries result in double amps

Reported by: ismayil.khayredinov Owned by:
Priority: normal Milestone: Needs Review
Component: JavaScript Version: 1.8
Severity: minor Keywords:
Cc: brett@… Difficulty:

Description

if you pass a url with formatted query to one of the views using output/url and specify that it's an action, the query is reformatted:

Example:

        $query = http_build_query($query_array);

        $tab = array(
            'title' => 'xxx',
            'url' => "action/view?{$query}",
            'is_action' => true
        );

Resulting URL:

http://localhost/hypetest18/action/view?e=323&amp%3Bs=323&amp%3Bc=322&amp%3Bo=47&amp%3Bf=279&amp%3Bsn=9&amp%3Bcx=portfolio&__elgg_ts=1317411951&__elgg_token=6b639a22436696767843ab8915757cde

Change History (7)

comment:1 Changed 20 months ago by cash

I just did this test and it worked:

	$query_array = array('a' => 'b', 'c' => 'd');
	$query = http_build_query($query_array);

	$tab = array(
		'title' => 'xxx',
		'href' => "action/view?{$query}",
		'is_action' => true,
		'text' => 'xxx',
	);

	$content = elgg_view('output/url', $tab);

The output was:

<a title="xxx" href="http://localhost/action/view?a=b&amp;c=d&amp;__elgg_ts=1317416901&amp;__elgg_token=eabc46bbaecaafc4fdf59f2427ea3c99">xxx</a>

Are you doing anything else before passing the array to output/url?

comment:2 Changed 20 months ago by ismayil.khayredinov

Hmmm. The action goes through elgg.action js. I will do more testing. FirePHP was showing misconfigured URL before it was sent to ajax (imho). I will report back.

comment:3 Changed 20 months ago by ismayil.khayredinov

  • Component changed from Core to JavaScript

So, it seems that if the query url is sent via elgg.action it is reparsed with double amps. So must be a js issue.

comment:4 Changed 20 months ago by cash

  • Resolution set to worksforme
  • Status changed from new to closed

It works fine for me. Here is the code that I'm using:

	$query_array = array('a' => 'b', 'c' => 'd');
	$query = http_build_query($query_array);

	$tab = array(
		'title' => 'xxx',
		'href' => "action/view?{$query}",
		'is_action' => true,
		'text' => 'xxx',
		'class' => "test",
	);

	$content = elgg_view('output/url', $tab);

	$content .= <<<HTML
<script type="text/javascript">
    $(document).ready(function() {
        var url = $(".test").attr('href');
        elgg.action(url);
    });
</script>
HTML;

I'm wondering whether you have a configuration problem on your server. Check the value of arg_separator.output for PHP. It should be &

comment:5 Changed 20 months ago by ismayil.khayredinov

the setting is ok.
here are the snippets of my code:

if (!empty($segments)) {
    foreach ($segments as $segment) {
        $extract = hj_framework_extract_params_from_entity($segment, array(), $cx);
        $url = http_build_query($extract['url_params']);

        $tabs[] = array(
            'title' => $segment->title,
            'id' => "hj-ajax-tab-load-{$segment->guid}",
            'class' => "hj-ajax-tab-load",
            'url' => "action/framework/entities/view?{$url}",
            'target' => '#hj-ajax-tab-dump-portfolio',
            'is_action' => true,
            'url_class' => 'elgg-state-draggable',
            'selected' => $selected["$segment->guid"]
        );
    }
}

$ajax = <<<HTML
        <div id="hj-ajax-tab-dump-portfolio" class="hj-ajax-result hj-ajax-tabs-portfolio" style="display:none"></div>
HTML;

$module = '<div id="hj-sortable-tabs">' . elgg_view('navigation/tabs', array('tabs' => $tabs, 'id' => 'hj-sortable-tabs', 'class' => 'hj-ajax-tabs')) . '</div>';
$module .= $ajax;

$sidebar = elgg_view('hj/portfolio/userdetails', array('entity' => $user));
$title = sprintf(elgg_echo('hj:portfolio:portfolios'), $user->name);
$module = elgg_view_module('aside', $title, $module);

$content = elgg_view_layout('hj/profile', array(
    'content' => $module,
    'sidebar' => $sidebar,
        ));
$page = elgg_view_layout('one_column', array('content' => $content));

JS

elgg.provide('hj.framework.tabs');

    hj.framework.tabs.init = function() {
        $('.hj-ajax-tab-load')
        .unbind('.ajaxTabLoad')
        .bind('click.ajaxTabLoad', hj.framework.tabs.load);

        $('ul.hj-ajax-tabs li.elgg-state-selected')
        .trigger('click.ajaxTabLoad');

        
    }

    hj.framework.tabs.load = function(event) {

        var action = $(this).find('a').attr('href');
        var target = $(this).attr('target');
        var loader = '<div class="hj-ajax-loader hj-loader-circle"></div>';

        $(target).show().html(loader);
        $('li', $(this).parent('ul')).removeClass('elgg-state-selected');
        $(this).addClass('elgg-state-selected');

        elgg.action(action, {
            success : function(output) {
                $(target).html(output.data);
                elgg.trigger_hook('success', 'hj:framework:ajax');

            }
        });

        event.preventDefault();

    }

comment:6 Changed 20 months ago by cash

I guess I could try putting the links through navigation/tabs. That is the only thing that looks different between my code and yours.

comment:7 Changed 20 months ago by ismayil.khayredinov

Duh me. Sorry. Found a piece of code left from my experiments with tabs... I thought I removed all overloading files, but there was one left that was causing this drama. Thanks for your time

Note: See TracTickets for help on using tickets.