#105348 and #105810 - improved INSTALL.txt.
[project/gallery.git] / gallery_g2image.inc
1 <?php
2 // $Id$
3
4 /**
5 * gallery.module : gallery_g2image.inc
6 * Support functions for g2image by capt_kirk (from http://g2image.steffensenfamily.com)
7 */
8
9 /**
10 * Add js to page
11 */
12 function gallery_g2image_add_js() {
13 // Ensure only sent once
14 static $sent = false;
15 if (!$sent) {
16 $path = drupal_get_path('module', 'gallery');
17 $g2image_uri = base_path() . $path . '/g2image/';
18
19 $output .= '<script type="text/javascript">';
20 $output .= ' var G2IMAGE_URI = "' . $g2image_uri . '";';
21 $output .= '</script>';
22
23 drupal_set_html_head($output);
24 drupal_add_js($path . '/g2image.js');
25 $sent = true;
26 }
27 }
28
29 /**
30 * Theme for adding an image link underneath textareas
31 */
32 function theme_gallery_g2image_textarea_link($element, $link) {
33 $output = '<div class="g2image-button"><a class="g2image-link" id="g2image-link-'. $element['#id']
34 . '" title="'. t('Click here to add images from Gallery2 albums')
35 . '" href="#" onclick="g2ic_open(\''.$element['#id'].'\');">';
36 $output .= t('add Gallery2 images');
37 $output .= '</a></div>';
38
39 return $output;
40 }
41
42 /**
43 * Determine if g2image button should be attached to the page/textarea.
44 * (from img_assist and tinymce code)
45 *
46 * @return
47 * TRUE if can render, FALSE if not allowed.
48 */
49 function _gallery_g2image_page_match() {
50 //if (variable_get('gallery_g2image_std_all', 1)) {
51 $page_match = FALSE;
52 $only_listed_pages = variable_get('gallery_g2image_only_listed_pages', 1);
53 $pages = variable_get('gallery_g2image_std_pages', gallery_help('admin/settings/gallery_g2image#pages'));
54 if ($pages) {
55 $path = drupal_get_path_alias($_GET['q']);
56 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/';
57 $page_match = !($only_listed_pages xor preg_match($regexp, $path));
58 }
59 return $page_match;
60 }
61
62 ?>