| 1 |
<?php
|
| 2 |
// $Id: insert_view.module,v 1.15 2008/06/25 14:42:00 mlsamuelson Exp $
|
| 3 |
|
| 4 |
function insert_view_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 5 |
// The "list" operation provides the module an opportunity to declare both how
|
| 6 |
// many filters it defines and a human-readable name for each filter. Note that
|
| 7 |
// the returned name should be passed through t() for translation.
|
| 8 |
if ($op == 'list') {
|
| 9 |
return array(
|
| 10 |
0 => t('insert view filter'));
|
| 11 |
}
|
| 12 |
|
| 13 |
// All operations besides "list" provide a $delta argument so we know which
|
| 14 |
// filter they refer to. We'll switch on that argument now so that we can
|
| 15 |
// discuss each filter in turn.
|
| 16 |
switch ($op) {
|
| 17 |
case 'description':
|
| 18 |
return t('Inserts content lists into nodes using [view:myview] tags.');
|
| 19 |
case 'prepare':
|
| 20 |
return $text;
|
| 21 |
case 'process':
|
| 22 |
return _insert_view_substitute_tags($text);
|
| 23 |
case 'no cache':
|
| 24 |
return TRUE;
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
function insert_view_filter_tips($delta, $format, $long = false) {
|
| 29 |
if ($long) {
|
| 30 |
return t('
|
| 31 |
<p>The Views module allows administrators to create dynamic lists of content
|
| 32 |
for display in pages or blocks. It is possible to insert those lists into
|
| 33 |
existing node bodies and blocks, but such inclusion requires that PHP
|
| 34 |
filtering be turned on. The Insert View module allows any user to insert
|
| 35 |
view listings using tag syntax, without the need for PHP execution
|
| 36 |
permissions. The Insert View tag syntax for embedding a view is relatively
|
| 37 |
simple:</p>
|
| 38 |
|
| 39 |
<pre>[view:my_view]</pre>
|
| 40 |
|
| 41 |
<p>is replaced by the content listing corresponding to the named view. In
|
| 42 |
this case it is my_view.</p>
|
| 43 |
|
| 44 |
<pre>[view:my_view=my_display]</pre>
|
| 45 |
|
| 46 |
<p>invokes the my_view view using the my_display view display ID. If the
|
| 47 |
display slot is left empty, the view\'s "default" display is used.</p>
|
| 48 |
|
| 49 |
<pre>[view:my_view=my_display=1,2,3]</pre>
|
| 50 |
|
| 51 |
<p>uses the my_display view display, and passes a comma delimited list of
|
| 52 |
arguments (in this case 1, 2, and 3) to the view.</p>
|
| 53 |
|
| 54 |
<p>Here\'s an example you could use with the default view named "tracker"
|
| 55 |
which uses the page display and takes a user ID as an argument:</p>
|
| 56 |
|
| 57 |
<pre>[view:tracker=page=1]</pre>
|
| 58 |
|
| 59 |
<p>In short this tag says, "Insert the view named tracker, use the "page"
|
| 60 |
display, and supply the argument 1."</p>
|
| 61 |
|
| 62 |
<p>Sometimes you want to pass an argument without specifying a display ID.
|
| 63 |
You can do that by leaving the display ID slot empty, like so:</p>
|
| 64 |
|
| 65 |
<pre>[view:my_view==1]</pre>
|
| 66 |
|
| 67 |
<p>How to find a display ID: On the edit page for the view
|
| 68 |
in question, you\'ll find a list of displays at the left side of the control
|
| 69 |
area. "Defaults" will be at the top of that list. Hover your mouse
|
| 70 |
pointer over the name of the display you want to use. A URL will appear in
|
| 71 |
the status bar of your browser. This is usually at the bottom of the
|
| 72 |
window, in the chrome. Everything after #views-tab- is the display ID. For
|
| 73 |
example in http://localhost/admin/build/views/edit/tracker?destination=node%2F51#views-tab-page
|
| 74 |
the display ID would be "page".</p>
|
| 75 |
|
| 76 |
');
|
| 77 |
}
|
| 78 |
else {
|
| 79 |
return t('You may use <a href="@insert_view_help">[view:viewname] tags</a> to display listings of nodes.', array("@insert_view_help" => url("filter/tips/$format", array('fragment' => 'filter-insert_view'))));
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
function _insert_view_substitute_tags($text) {
|
| 84 |
if (preg_match_all("/\[view(_pager)?:([^=\]]+)=?([^=\]]+)?=?([^\]]*)?\]/i", $text, $match)) {
|
| 85 |
foreach ($match[3] as $key => $value) {
|
| 86 |
// view_pager syntax is deprecated in the D6 version, but leaving in for
|
| 87 |
// now so we don't break people's legacy tags
|
| 88 |
$match[1][$key] == '_pager' ? $pager = TRUE : $pager = FALSE; // not used
|
| 89 |
|
| 90 |
$viewname = $match[2][$key];
|
| 91 |
$display = ($match[3][$key] && !is_numeric($match[3][$key])) ? $match[3][$key] : 'default';
|
| 92 |
$view_args = $match[4][$key];
|
| 93 |
|
| 94 |
$view = views_get_view($viewname);
|
| 95 |
$replace = "";
|
| 96 |
|
| 97 |
if ($view_args != NULL) {
|
| 98 |
$view_args = explode(',', $view_args);
|
| 99 |
}
|
| 100 |
else {
|
| 101 |
$view_args = array();
|
| 102 |
}
|
| 103 |
|
| 104 |
if ($view) {
|
| 105 |
// render our previously gotten view, providing it with our matched
|
| 106 |
// display (or default) and matched arguments
|
| 107 |
$replace = $view->preview($display, $view_args);
|
| 108 |
|
| 109 |
$mtch[] = $match[0][$key];
|
| 110 |
$repl[] = $replace;
|
| 111 |
}
|
| 112 |
}
|
| 113 |
return str_replace($mtch, $repl, $text);
|
| 114 |
}
|
| 115 |
return $text;
|
| 116 |
}
|