| 1 |
<?php // -*-php-*-
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
function img_insert_menu($may_cache) {
|
| 5 |
$items = array();
|
| 6 |
|
| 7 |
if ($may_cache) {
|
| 8 |
$items[] = array(
|
| 9 |
'path' => 'img_insert/get_view',
|
| 10 |
'callback' => 'img_insert_get_view',
|
| 11 |
'access' => user_access('use img_insert'),
|
| 12 |
'type' => MENU_CALLBACK
|
| 13 |
);
|
| 14 |
|
| 15 |
$items[] = array(
|
| 16 |
'title' => t('Image insert'),
|
| 17 |
'path' => 'admin/settings/img_insert',
|
| 18 |
'access' => user_access('administer site configuration'),
|
| 19 |
'callback' => 'drupal_get_form',
|
| 20 |
'callback arguments' => 'img_insert_settings',
|
| 21 |
'description' => t('Configure img_insert'),
|
| 22 |
);
|
| 23 |
}
|
| 24 |
|
| 25 |
return $items;
|
| 26 |
}
|
| 27 |
|
| 28 |
function img_insert_form_alter($form_id, &$form) {
|
| 29 |
// create conten form.
|
| 30 |
if (arg(0) == 'node' && arg(1) == 'add' && substr($form_id, -9) == 'node_form') {
|
| 31 |
$form['body_filter']['image_gallery_edit'] = array(
|
| 32 |
'#type' => 'markup',
|
| 33 |
'#value' => '<iframe height="600" width="600" src="'.url('img_insert/get_view').'"></iframe>',
|
| 34 |
);
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
// menu callback.
|
| 39 |
function img_insert_get_view() {
|
| 40 |
$view = variable_get('img_insert_view', '');
|
| 41 |
|
| 42 |
if ($view == '') {
|
| 43 |
drupal_set_message(t('Please configure img_insert'), 'error');
|
| 44 |
return "";
|
| 45 |
}
|
| 46 |
|
| 47 |
$path = drupal_get_path('module', 'img_insert');
|
| 48 |
drupal_add_js($path.'/img_insert.js');
|
| 49 |
$view = views_get_view($view);
|
| 50 |
$out = views_build_view('embed', $view, NULL, $view->use_pager, $view->nodes_per_page);
|
| 51 |
|
| 52 |
// ripped from theme_page()
|
| 53 |
$output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
|
| 54 |
$output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
|
| 55 |
$output .= '<head>';
|
| 56 |
$output .= ' <title>'. (drupal_get_title() ? strip_tags(drupal_get_title()) : variable_get('site_name', 'Drupal')) .'</title>';
|
| 57 |
$output .= drupal_get_html_head();
|
| 58 |
$output .= drupal_get_css();
|
| 59 |
$output .= drupal_get_js();
|
| 60 |
|
| 61 |
$output .= $out;
|
| 62 |
$output .= ' </head>';
|
| 63 |
$output .= ' <body style="background-color: #fff; color: #000;">';
|
| 64 |
|
| 65 |
$output .= theme('closure');
|
| 66 |
$output .= '</body></html>';
|
| 67 |
|
| 68 |
echo $output;
|
| 69 |
exit();
|
| 70 |
}
|
| 71 |
|
| 72 |
function img_insert_settings() {
|
| 73 |
$form = array();
|
| 74 |
$options = array();
|
| 75 |
|
| 76 |
$result = db_query("SELECT name FROM {view_view} ORDER BY name");
|
| 77 |
while ($o = db_fetch_object($result)) {
|
| 78 |
$options[$o->name] = $o->name;
|
| 79 |
}
|
| 80 |
|
| 81 |
$form['img_insert_view'] = array(
|
| 82 |
'#type' => 'select',
|
| 83 |
'#multiple' => false,
|
| 84 |
'#options' => $options,
|
| 85 |
'#title' => t('The view to use'),
|
| 86 |
'#default_value' => variable_get('img_insert_view', ''),
|
| 87 |
);
|
| 88 |
|
| 89 |
return system_settings_form($form);
|
| 90 |
}
|
| 91 |
?>
|