This patch contains the following improvements:

1. access check for views
2. much more common argument format can be used "arg1/arg2/arg3"
3. grab arguments from the url %0, %1 ... %N
4. insert_view() function to easily embed views with a PHP snippet
5. code documentation

(patched module file is also attached for users who would like to test this patch)

CommentFileSizeAuthor
insert_view.module.txt5.61 KBPasqualle
insert_view.patch11.02 KBPasqualle
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Personally , unless their is a very good reason why we should, I dont think we should replace the argument selection in "Improvement 2", but maybe add as an alternative so as not to cause extra work for websites that have implimented the existing method. I myself will have to fix the content of over 1000 pages

mlsamuelson’s picture

I like the improvements list. Haven't had a chance to test the patch yet.

Like midkemia, I think the argument format change has the danger of being very disruptive for existing sites. I'd support the change if we had legacy handling for the old argument type, but then, we're perhaps adding complexity and change without a strong need for change. Any other users want to weigh in here?

Perhaps the best course of action would be to move #2 to its own issue, where it will have an opportunity to get more attention and comments in the issue queue, and then we can proceed here with reviewing 1, 3, 4, and 5.

Pasqualle’s picture

The old argument format still works. I just added a new one..

this is the complexity of legacy handling:

if (strpos($view_args, '/') === FALSE) {
  $view_args = str_replace(',', '/', $view_args);
}

The panels module uses this argument format and quicktabs module switched to this format recently #382108: Separate view args with / rather than comma. This format is easy as it is the same what is used inside views admin interface for the preview..

The possible problem with the old format is that comma can be used to separate taxonomy terms for one argument, like arg1/term1,term2,term3/arg3/arg4, but of course this is the same as using arg1/term1+term2+term3/arg3/arg4

mlsamuelson’s picture

@Pasqualle

The complexity I was thinking of had more to do with confusion and support requests in the issue queue. :D

As long as the README.txt and the project page here on d.o are updated to reflect these changes, I don't see there being a problem with proceeding once we have a review or two of the current patch.

xtfer’s picture

I tried using the patched module, but my insert views simply stopped inserting (which is a pity, as I thought it looked like a good improvement). Not sure why they stopped working yet.

Pasqualle’s picture

maybe you do not have access for the view. can you check the access set for the view?

or can you write the Insert View tag used to display the view? do you have spaces in it, or anything special?

Pasqualle’s picture

arg1/term1,term2,term3/arg3/arg4, but of course this is the same as using arg1/term1+term2+term3/arg3/arg4

it seems like this is not true

from the issue #430596: Changing Argument Separator
the comma is used as OR
and + is used as AND

so the separator issue should be solved only in the 2.x version

Mac Clemmens’s picture

Could improvement #2 be made a configurable option? I support changing the argument separator to match views.

Pasqualle’s picture

@Digital Deployment: yes, that could be an option.. I think that's a good idea, as I do not know any other possibility how to fully support the upgrade from the old version..

Anonymous’s picture

Returning to my initial concern #1

I dont know exactly how updgrading works and what it can do, or is allowed. But the biggest issue I see stopping wholesale replacement of the old technique is identifying and making the changes which could be a big task.

So
1/is there a way of of identifying all nodes that have "Insert_view" used probably look for "[view:"

2/ if there is, is there a way of providing a scrpit that is run after update of the module, that will run through all affected nodes making the appropriate changes to the new format probably after finding "[view:" substitute the appropriate items before the next "]"

In theory this would simplify updates for all, and with a change point of 2.x, anyone using that onwards will have the new technique

Pasqualle’s picture

1. I would not run an automatic update on node content. That could really mess up things in special cases.
2. The filter can be used on various places, like it can be used in blocks, I even used the filter format in theme templates (now I am using the insert_view() function).

Anonymous’s picture

I can see the potentail risk from what you say.

An option to identify all locations where permissible, would possibly be a benefit, as i can see on a larger sites, rembering where insert view has been used could be an issue. This might also be a useful permanent feature

As an option, you can create a view of nodes to find [view: in the node body so that is an option for those using views using [view:%,

arcaic’s picture

Not sure about this as I am pretty new to Drupal but could the module support 2 tag types.

At the moment all tags begin [view:......

ie: [view:name of view=x=arg1,arg2,arg3]

What about another tag that begins [view2:....

[view2:name of view=x=arg1/arg2/arg3] (Using new argument format)

Andy

Anonymous’s picture

The way i understand it , is the intent was to bring the module into line with the argument format used by views, so ideally replacing all exisiting cases would be best.

What was being offered was a means to permit old format to remain, but if they're changed , the need to support goes away

Martin.Schwenke’s picture

Can I please suggest adding support for escaping the argument separator? There's a simple example at http://drupal.org/node/85771#comment-158116 .

Pasqualle’s picture

Re #15: The patch already has a more commonly used separator '/'. You should write the arguments same as you write them on the views admin interface at preview.

Martin.Schwenke’s picture

Doesn't this code mean that ',' are replaced by '/'?

      if (strpos($view_args, '/') === FALSE) {
        $view_args = str_replace(',', '/', $view_args);
      }

So now if your argument contains either character then it will be treated as multiple arguments? This means that adding an extra separator character makes the problem worse rather than better because you now have 2 characters that can't be used in an argument. :-)

The views preview interface seems to have a similar problem.

For example, say that my view displays nodes of a particular content type whose node title matches a single argument. If I have a node with title "A, B" then I can't currently match it using insert_view 6.x-1.0. In your proposed version I still can't use insert_view to match that node and I also can't match a node with title "X/Y".

You need a way of telling insert_view that a ',' or '/' should be treated as a character that is part of an argument instead of a character that is used to split multiple arguments. One way of doing this would be to add an escape character like the example I linked to above.

Another way would be to make the argument separator configurable per use of insert_view. The cleanest way I can think of doing this would be something like this example:

[view:@my_view=default=arg1@arg2]

That is, if you put a character that isn't allowed in a view name at the beginning of the view name, then that character is used as the argument separator. I haven't though about how this might interact with the PHP filter if you allowed it in the same input filter as the insert_view filter... but if you're allowing PHP then you probably don't need insert_view. ;-)

Pasqualle’s picture

That code snippet is wrong and should be removed.. It was meant to be a backward compatibility code, but it does not work correctly if your argument does not contain a slash..

this works correctly even with that code

arg1/val1,val2/val3+val4

but this:

arg1,arg2,arg3

does not. As the code do not know if you want to use multiple values for 1 argument or 3 arguments..

the views preview interface works, although I do not know if your example (/ inside node title) is handled correctly. The argument separator is '/' (slash), the separator for multiple values for the same argument are: ',' (comma) or '+' (plus) depending what is the relation between the values:
, equals OR
+ equal AND

we do not want to invent a new separator, we want to use the same separators as views does. That is the cleanest way.. If you find a problem with these separators you should open an issue for views..

Martin.Schwenke’s picture

The views preview interface has a similar problem but the problems are independent.

When insert_view does this

$args = $args ? explode('/', $args) : array();

it splits on every '/' in the argument(s). There is no way to include a '/' in an argument, so you can't possibly pass an argument that matches a field that has a value containing '/'. To do this you would need to be able to escape a slash. For example, arg1part1\/arg1part2/arg2.

Pasqualle’s picture

but come on Martin, that is how we use arguments in Drupal.
http://api.drupal.org/api/function/arg/6
It is not insert_view's fault that you can't use / inside arguments..

Martin.Schwenke’s picture

I partly agree. So, here's my last throw of the dice... :-)

insert_view parses the arguments into an array so it has the opportunity to decide how that parsing should be done.

If I resort to PHP and call views_embed_view() directly then I can pass arguments containing any characters, because those arguments are not parsed. So the problem is not inherent in views.

It makes sense to allow people to pass any string as an argument, even if that string contains a metacharacter. Most software allows metacharacters to be escaped.

Perhaps the real solution is to use URL encoding. In that case, perhaps views needs to decode such encoded characters in arguments before building the query? Perhaps the decoding should be optional per argument?

Pasqualle’s picture

you are right about views_embed_view(), you can put a / inside argument..

but any page or block view can not accept such arguments, so just to make it possible with embedded views we should make the arguments even more complicated. This argument handling code was based on the code in panels 2, and it is quite bulletproof.

realityloop’s picture

I've applied the patch and the module has stopped working altogether, instead outputting clear text on page view:

[view:emerg_contacts_lerp_display=page=Facilities & Services Division]

The argument type is set in my view to "Term name/synonym converted to Term ID"

Pasqualle’s picture

I know there is a problem, that the filter text is displayed when the view is empty.
Can you check that the view is not empty? Just try the preview in the view admin interface with the "Facilities & Services Division" argument ..

realityloop’s picture

Hi Pasqualle,

This is on a page that shows the view inline correctly, until I apply the patched version of the module, if I revert back the view is displaying inline correctly again.

So there are definitely records that get returned with the argument.

saurabh.bhambry’s picture

Subscribing.

I find it to be a pretty useful module however the documentation is pretty confusing and so is the example given in the read me text. All I need to do is pass on an argument using the url . However I am not able to figure out how ..

The syntax i m using : [view:tracker=page=1] works when "1" here is the value of the argument being passed. However I want to pass the argument "user ID" dynamically which ideally should be taken from the url and not supplied as value. Please help.. Any suggestions would be appreciated.

j0nathan’s picture

Priority: Normal » Critical

Hi, and thank you for the module.

Is there any updates since October 13, 2009, especially for access check for views?

I think this is an important security issue when users can insert views that have been created for admins (content list, users list, VBO).

aaront’s picture

I'm also wondering about this module's status, especially now that it is listed as an unsupported module. Just started using this module and it's doing something I haven't been able to figure out otherwise.

Martin.Schwenke’s picture

if you're currently using this module in a selected number of nodes that you edit with high privileges (e.g. site administrator) then you can replace it with the use the "PHP Code" input format and insert the view directly with PHP:

print views_embed_view("my_view", $display_id = 'default', $node->title)

Note that you do not want to allow the "PHP Code" input format on nodes that untrusted users can edit. That would allow those users to use PHP code to expose any information on your site.

I use this technique to add a view near the top of my front page via a sticky node that allows "PHP Code". One day I'll use Panels to do this instead... but that will require having the time to learn about Panels. ;-)

Pasqualle’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev

please try out the new 2.x version.
- the argument format is changed, so you need to update your nodes if you use multiple view arguments.
- and read the README.txt file

note: the 1.x version most probably remains unsupported

abaddon’s picture

is the security warning on the front page pertaining to the 2.x-dev version as well? or this one is secured?

j0nathan’s picture

Hi,
I tested one inserted view for its access by anonymous with 6.x-2.x-dev 2010-Mar-05 and it checks the access (anonymous don't see the view). Thank you for the help.

djac’s picture

Here are the steps that I followed:
Edit a view.
Under Basic Settings, there is a field called Access. I added the Admin Role only.

Results:
Users under the Admin role can see the view, but other users (ex. anonymous) cannot.

The access check appears to be working!
Thanks for the fix!

Lanae’s picture

Subscribing. Thanks for the fix!

Lanae’s picture

I just upgraded my dev site... I thought I only need to change the syntax if I use multiple arguments? Now none of my inserted views show up at all, even ones that use no arguments.

For example, this one doesn't work and I don't know what needs to change:

[view:staff=Page]

Detailed new syntax documentation to go with this new version would help.

Pasqualle’s picture

@foraker: the display name seems wrong to me. I guess it is page or page_1. In the readme.txt you can read how to find the display name.

MadOverlord’s picture

Just updated, and of course had to find all the , arguments on my site and change them to / arguments.

Whipped up a quick views filter that finds nodes that have [view: plus a second, settable argument (which you set to ",0" through ",9") and outputs a table of node titles and edit links.

Generates some false positives, of course, but it's not too much bother to use browser search to look through the edit form and see if anything needs to be tweaked.

Posting it in case anyone else might find it useful:

$view = new view;
$view->name = 'Insert_View_Finder';
$view->description = 'Insert View Finder';
$view->tag = 'Insert View Finder';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'edit_node' => array(
    'label' => 'Edit link',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'text' => '',
    'exclude' => 0,
    'id' => 'edit_node',
    'table' => 'node',
    'field' => 'edit_node',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'body' => array(
    'operator' => 'contains',
    'value' => ',0',
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'body_op',
      'identifier' => 'body',
      'label' => 'Node: Body contains this and [view:',
      'optional' => 0,
      'remember' => 0,
    ),
    'case' => 1,
    'id' => 'body',
    'table' => 'node_revisions',
    'field' => 'body',
    'relationship' => 'none',
  ),
  'body_1' => array(
    'operator' => 'contains',
    'value' => '[view:',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'case' => 1,
    'id' => 'body_1',
    'table' => 'node_revisions',
    'field' => 'body',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 20);
$handler->override_option('style_plugin', 'table');
Lanae’s picture

thanks, updated and everything's working now. I just needed to use the machine-readable display names.

dawehner’s picture

Why don't you use views_embed_view? It has access checking, too.

Pasqualle’s picture

@dereine: the insert_view() is better than views_embed_view() as it supports args from url, and the args parameter is easier to understand. And most importantly it did not have access checking at that time when this issue was created..

naero’s picture

Based on http://drupal.org/node/419880#comment-2681200, is this issue considered fixed?

Since the project page says that there is a vulnerability, where do things stand with this open issue? Has this been fixed?

GuillaumeDuveau’s picture

The project homepage has to be updated, there's still the syntax [view:name of view=name of display=arg1,arg2,arg3]

EvanDonovan’s picture

Echoing naero's comment in #41, is this committed to 2.x-dev now, and is the module secure?

Will there soon be a recommended 2.x release?

Daniel Wentsch’s picture

Subscribing.

ericm’s picture

subscribing

Pasqualle’s picture

Status: Needs review » Closed (fixed)