| 1 |
<?php
|
| 2 |
|
| 3 |
// Bootstrap drupal
|
| 4 |
require_once './includes/bootstrap.inc';
|
| 5 |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
|
| 6 |
|
| 7 |
if (!module_exists('fquery')) {
|
| 8 |
die ('fQuery module must be installed and enabled.');
|
| 9 |
}
|
| 10 |
|
| 11 |
// Fetch and prepare the "add story" form.
|
| 12 |
// Note: this is NOT proper use, this is just for demonstration purposes.
|
| 13 |
// Several properies added by drupal_prepare_form() will be missing. They are not relevant for these example queries.
|
| 14 |
$form = drupal_retrieve_form('story_node_form');
|
| 15 |
$form = form_builder('story_node_form', $form);
|
| 16 |
$form['author']['#attributes'] = array('class' => 'foo bar');
|
| 17 |
|
| 18 |
// Try these queries
|
| 19 |
$queries = array(
|
| 20 |
'textfield',
|
| 21 |
'textfield:not([#title=Authored on])',
|
| 22 |
'fieldset[class=foo bar]',
|
| 23 |
'[#type=fieldset] > textfield:last-child',
|
| 24 |
'fieldset + fieldset',
|
| 25 |
'checkbox#sticky, checkbox#status, checkbox#promote',
|
| 26 |
'textarea',
|
| 27 |
);
|
| 28 |
|
| 29 |
foreach ($queries as $i => $query) {
|
| 30 |
|
| 31 |
print '<h1>Query: '. check_plain($query) .'</h1>';
|
| 32 |
|
| 33 |
// Do query
|
| 34 |
timer_start($timer = 'fquery'. $i);
|
| 35 |
$query = f($query, $form);
|
| 36 |
print '<h4>Time taken: '. timer_read($timer) .'</h4>';
|
| 37 |
|
| 38 |
// Render result set
|
| 39 |
foreach ($query as $i => &$element) {
|
| 40 |
// Make sure we can render the same element multiple times if needed.
|
| 41 |
$copy = unserialize(serialize($element));
|
| 42 |
|
| 43 |
print '<h2>Element '. ($i + 1) .'</h2>';
|
| 44 |
print drupal_render_form('', $copy);
|
| 45 |
print("\n\n");
|
| 46 |
}
|
| 47 |
print '<hr />';
|
| 48 |
}
|
| 49 |
|