Commit f6d926e1 authored by profix898's avatar profix898

- Initial version of Gallery G2Image

parent d8886446
// $Id$
Installation
------------
If you install G2Image (http://g2image.steffensenfamily.com) as either a
standalone or TinyMCE plugin you will have an excellent image chooser for
Drupal/Gallery2. The configuration is automatic when you hit the 'Save
configuration' button on the G2Image settings page
(admin/settings/gallery/g2image).
; $Id$
name = "Gallery G2Image"
description = "Integrates G2Image with Gallery module"
package = "Gallery2"
dependencies[] = gallery
core = 6.x
// $Id$
function g2image_open(field) {
// Set some properties
var form = $('#'+field).parents('form').attr('id');
var url = Drupal.settings.gallery.g2image_uri+'/g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
var name = 'g2image';
var w = 600;
var h = 600;
var valLeft = (screen.width) ? (screen.width-w)/2 : 0;
var valTop = (screen.height) ? (screen.height-h)/2 : 0;
var features = 'width='+w+',height='+h+',left='+valLeft+',top='+valTop+',resizable=1,scrollbars=1';
// Open the G2Image window
window.open(url, name, features);
}
// BUEditor
function g2bueditor_open() {
if (editor.active) {
g2image_open(editor.active.textArea.id);
}
}
<?php
// $Id$
/**
* gallery_g2image.module
*/
/**
* Implementation of hook_theme().
*/
function gallery_g2image_theme() {
return array(
'gallery_g2image_textarea_link' => array(
'arguments' => array('element' => NULL, 'link' => NULL),
)
);
}
/**
* Implementation of hook_perm().
*/
function gallery_g2image_perm() {
return array('access standalone g2image');
}
/**
* Implementation of hook_menu().
*/
function gallery_g2image_menu() {
$items = array();
if (variable_get('gallery_valid', 0)) {
$items['admin/settings/gallery/g2image'] = array(
'title' => 'G2Image',
'access callback' => 'user_access',
'access arguments' => array('administer gallery settings'),
'file' => 'gallery_g2image_settings.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('_gallery_g2image_settings'),
'type' => MENU_LOCAL_TASK,
'weight' => 3
);
}
return $items;
}
/**
* Implementation of hook_elements().
*/
function gallery_g2image_elements() {
$type['textarea'] = array('#process' => array('gallery_g2image_textarea'));
return $type;
}
/**
* Function gallery_g2image_textarea().
* (add image link underneath textareas)
*/
function gallery_g2image_textarea($element) {
if (!isset($element['#disabled']) && _gallery_g2image_page_match()
&& (variable_get('gallery_g2image_mode', 'disabled') == 'standalone')
&& (user_access('access standalone g2image'))) {
gallery_g2image_add_js();
$link = theme('gallery_g2image_textarea_link', $element);
$element['#suffix'] = (isset($element['#suffix']) ? $element['#suffix'] : '') . $link;
}
return $element;
}
/**
* Function _gallery_g2image_page_match().
* (determine if g2image button should be attached to the page/textarea)
*
* @return
* TRUE if can render, FALSE if not allowed.
*/
function _gallery_g2image_page_match() {
require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
$page_match = FALSE;
$only_listed_pages = variable_get('gallery_g2image_only_listed_pages', 1);
if ($pages = variable_get('gallery_g2image_std_pages', gallery_help('admin/settings/gallery_g2image#pages'))) {
$path = drupal_get_path_alias($_GET['q']);
$regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/';
$page_match = !($only_listed_pages xor preg_match($regexp, $path));
}
return $page_match;
}
/**
* Function gallery_g2image_add_js().
*/
function gallery_g2image_add_js() {
// Ensure only sent once
static $sent = FALSE;
if (!$sent) {
if ($path = variable_get('gallery_g2image_path', FALSE)) {
drupal_add_js(array('gallery' => array('g2image_uri' => base_path() . $path)), 'setting');
drupal_add_js(drupal_get_path('module', 'gallery_g2image') .'/gallery_g2image.js');
}
$sent = TRUE;
}
}
/**
* Theme function : theme_gallery_g2image_textarea_link().
* (for adding an image link underneath textareas)
*/
function theme_gallery_g2image_textarea_link($element) {
$output = '<div class="g2image-button"><a class="g2image-link" id="g2image-link-'. $element['#id']
.'" title="'. t('Click here to add images from Gallery2 albums')
.'" href="#" onclick="g2image_open(\''. $element['#id'] .'\');">';
$output .= t('Add Gallery2 images');
$output .= '</a></div>';
return $output;
}
<?php
// $Id$
require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc');
/**
* gallery_g2image.module : gallery_g2image_settings.inc
* Settings functions
*/
/**
* Function _gallery_g2image_settings().
*/
function _gallery_g2image_settings() {
$plugin_status = gallery_plugin_status(array('imageblock'));
$plugin_status['g2image'] = _gallery_g2image_path() ? GALLERY_PLUGIN_ENABLED : GALLERY_PLUGIN_MISSING;
$desc = t('G2Image requires the Gallery2 Image Block plugin (!imageblock_status) and
the G2Image application (!g2image_status) to be installed.',
array(
'!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
'!g2image_status' => theme('gallery_plugin_status_message', $plugin_status['g2image'])
)
);
if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
$g2_uri = variable_get('gallery_embed_uri', '?q=gallery');
$g2_plugins_page = (variable_get('gallery_valid', 0)) ?
t('<a href= "@g2_plugins">Gallery2 Plugins</a>',
array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules'))
: t('Gallery2 Site Admin -> Plugins');
$desc .= t('<br />However, the Image Block plugin is unavailable. To use G2Image please go to
the !g2_plugins page and install/activate the Image Block plugin.', array(
'!g2_plugins' => $g2_plugins_page));
}
if ($plugin_status['g2image'] != GALLERY_PLUGIN_ENABLED) {
$desc .= t('<br />However, the G2Image application is unavailable. Please <a href="@g2image_url">download
G2Image</a> and install it as outlined in README.TXT.', array(
'@g2image_url' => 'http://g2image.steffensenfamily.com/index.php?title=Download'));
}
$form['g2image'] = array(
'#type' => 'fieldset',
'#title' => t('Gallery Image Assist (G2Image) settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#description' => $desc,
);
if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED && $plugin_status['g2image'] == GALLERY_PLUGIN_ENABLED) {
$form['g2image']['gallery_g2image_mode'] = array(
'#type' => 'select',
'#title' => t('Mode'),
'#default_value' => variable_get('gallery_g2image_mode', 'disabled'),
'#options' => array(
'disabled' => t('Disabled'),
'standalone' => t('Standalone'),
'tinymce' => t('TinyMCE'),
),
'#description' => t('Determines the mode of operation. For anything other than \'Disabled\' the G2Image
application has to be installed. See the README.txt instructions. In \'Standalone\'
mode a button will be visible under textfields to launch the g2image window. In
\'TinyMCE\' mode the g2image button can be used in the TinyMCE toolbar. Note that the
TinyMCE version will NOT work wih Safari - use the standalone version instead.'),
);
$form['g2image']['gallery_g2image_only_listed_pages'] = array(
'#type' => 'radios',
'#title' => t('Show g2image link on specific pages (Standalone mode only)'),
'#default_value' => variable_get('gallery_g2image_only_listed_pages', 1),
'#options' => array(
t('Show on every page except the listed pages.'),
t('Show on only the listed pages.')
)
);
require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
$form['g2image']['gallery_g2image_std_pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages (Standalone mode only)'),
'#default_value' => variable_get('gallery_g2image_std_pages', gallery_help('admin/settings/gallery_g2image#pages')),
'#description' => t('Enter one page per line as Drupal paths. The \'*\' character is a wildcard. Example paths are
\'%blog\' for the blog page and %blog-wildcard for every personal blog. %front is the front page.',
array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'))
);
$form['g2image']['gallery_g2image_sortby'] = array(
'#type' => 'select',
'#title' => t('Default Sort Order'),
'#default_value' => variable_get('gallery_g2image_sortby', 'title_asc'),
'#options' => array(
'title_asc' => t('Gallery2 Title (A-z)'),
'title_desc' => t('Gallery2 Title (z-A)'),
'name_asc' => t('Filename (A-z)'),
'name_desc' => t('Filename (z-A)'),
'mtime_desc' => t('Last Modification (newest first)'),
'mtime_asc' => t('Last Modification (oldest first)'),
),
'#description' => t('Determines the default sorting order.'),
);
$form['g2image']['gallery_g2image_images_per_page'] = array(
'#type' => 'select',
'#title' => t('Default Number of images per page'),
'#default_value' => variable_get('gallery_g2image_images_per_page', 20),
'#options' => _gallery_range_array(10, 60, 10),
'#description' => t('Choose the default number of images per page.'),
);
$form['g2image']['gallery_g2image_display_filenames'] = array(
'#type' => 'select',
'#title' => t('Default Display Options'),
'#default_value' => variable_get('gallery_g2image_display_filenames', 'thumbnails'),
'#options' => array(
'thumbnails' => t('Thumbnails only'),
'filenames' => t('Thumbnails with title and filename'),
),
'#description' => t('Choose the default display option for images.'),
);
$form['g2image']['gallery_g2image_default_action'] = array(
'#type' => 'select',
'#title' => t('Default Action'),
'#default_value' => variable_get('gallery_g2image_default_action', 'drupal_g2_filter'),
'#options' => array(
'drupal_g2_filter' => t('Gallery Filter ID'),
'thumbnail_image' => t('Thumbnail with link to image'),
'thumbnail_album' => t('Thumbnail with link to parent album'),
'thumbnail_custom_url' => t('Thumbnail with link to custom URL'),
'thumbnail_only' => t('Thumbnail only'),
'link_image' => t('Text link to image'),
'link_parent' => t('Text link to parent album'),
),
'#description' => t('Choose the default method of inserting the image info.'),
);
$form['g2image']['gallery_g2image_custom_url'] = array(
'#type' => 'textfield',
'#title' => t('Default custom url'),
'#default_value' => variable_get('gallery_g2image_custom_url', 'http://'),
'#size' => 50,
'#maxlength' => 50,
'#description' => t('The default custom url. Used with \'Thumbnail with link to custom URL\' action setting'),
);
$css_options = array(
'none' => t('None'),
'g2image_normal' => t('Normal'),
'g2image_float_left' => t('Float Left'),
'g2image_float_right' => t('Float Right'),
'g2image_centered' => t('Centered'),
);
// Merge in custom class options
$gallery_g2image_custom_class = array_filter(variable_get('gallery_g2image_custom_class', array()));
$css_options = array_merge($css_options, drupal_map_assoc($gallery_g2image_custom_class));
$form['g2image']['gallery_g2image_default_alignment'] = array(
'#type' => 'select',
'#title' => t('Default Alignment'),
'#default_value' => variable_get('gallery_g2image_default_alignment', 'none'),
'#options' => $css_options,
'#description' => t('Choose the default alignment of images.'),
);
$form['g2image']['gallery_g2image_custom_class'] = array('#tree' => TRUE);
for ($i=1; $i<=4; $i++) {
$form['g2image']['gallery_g2image_custom_class'][$i] = array(
'#type' => 'textfield',
'#title' => t('Custom Class @index', array('@index' => $i)),
'#default_value' => isset($gallery_g2image_custom_class[$i]) ? $gallery_g2image_custom_class[$i] : '',
'#size' => 20,
'#maxlength' => 50,
);
}
$form['g2image']['gallery_g2image_custom_class'][$i-1]['#description'] = t('Additional css classes to be available
for selection (must be defined in .css file).');
$form['g2image']['gallery_g2image_class_mode'] = array(
'#type' => 'select',
'#title' => t('Alignment Class Insertion Point'),
'#default_value' => variable_get('gallery_g2image_class_mode', 'img'),
'#options' => array(
'img' => t('<img class=...>'),
'div' => t('<div class=...><img ...>'),
),
'#description' => t('Determines where the alignment class will be inserted. If you choose \'&lt;div
class=...&gt;&lt;img ...&gt;\', you will have to manually delete any &lt;div&gt; tags
manually after deleting images from the TinyMCE window.'),
);
}
$form['#validate'] = array('_gallery_g2image_settings_validate');
return system_settings_form($form);
}
/**
* Function _gallery_g2image_settings_validate().
* (saves the G2Image config file)
*/
function _gallery_g2image_settings_validate($form, &$form_state) {
switch ($form_state['values']['gallery_g2image_mode']) {
case 'tinymce':
$mode = t('TinyMCE');
$path = drupal_get_path('module', 'tinymce');
$path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
break;
case 'standalone':
$mode = t('Standalone');
$path = drupal_get_path('module', 'gallery_g2image');
$path .= '/g2image';
break;
default:
return;
}
// Note that file_check_directory uses &$path and will strip the trailing '/'
$filename = $path .'/config.php';
if (is_writable($filename) == FALSE && !file_check_directory($path)) {
form_set_error('', t('G2Image does not seem to be installed for @mode mode in the required directory (@dir), or the
directory is not writable. Please see the INSTALL.txt for instructions.',
array('@mode' => $mode, '@dir' => '<drupal_path>/'. $path)));
return;
}
$cr = "\n";
$g2ic_gallery2_path = str_replace('\\', '/', variable_get('gallery_dir', './gallery2/'));
$g2ic_use_full_path = (substr($g2ic_gallery2_path, 0, 1) == '/' || substr($g2ic_gallery2_path, $_SERVER['DOCUMENT_ROOT']) !== FALSE) ? 'TRUE' : 'FALSE';
$form_state['values']['gallery_g2image_custom_url'] = check_url($form_state['values']['gallery_g2image_custom_url']);
$g2ic_display_filenames = ($form_state['values']['gallery_g2image_display_filenames'] == 'filenames') ? 'TRUE' : 'FALSE';
$g2ic_custom_class = array();
foreach ($form_state['values']['gallery_g2image_custom_class'] as $key => $value) {
$g2ic_custom_class[$key] = ($value) ? $value : 'not_used';
}
$content = '<?php'. $cr;
$content .= '/*'. $cr;
$content .= ' Gallery 2 Image Chooser'. $cr;
$content .= ' Version 3.0 - updated 16 SEP 2007'. $cr;
$content .= ' Documentation: http://g2image.steffensenfamily.com/'. $cr;
$content .= $cr;
$content .= ' Author: Kirk Steffensen with inspiration, code snippets,'. $cr;
$content .= ' and assistance as listed in CREDITS.HTML'. $cr;
$content .= $cr;
$content .= ' Released under the GPL version 2.'. $cr;
$content .= ' A copy of the license is in the root folder of this plugin.'. $cr;
$content .= $cr;
$content .= ' See README.HTML for installation info.'. $cr;
$content .= ' See CHANGELOG.HTML for a history of changes.'. $cr;
$content .= '*/'. $cr;
$content .= $cr;
$content .= '// Automatically generated by gallery.module (admin/settings/gallery/g2image).'. $cr;
$content .= '// DO NOT EDIT'. $cr;
$content .= $cr;
$content .= '$g2ic_embedded_mode = TRUE;'. $cr;
$content .= '$g2ic_gallery2_path = \''. $g2ic_gallery2_path .'\';'. $cr;
$content .= '$g2ic_use_full_path = '. $g2ic_use_full_path .';'. $cr;
$content .= '$g2ic_gallery2_uri = \''. variable_get('gallery_uri', '/gallery2/') .'\';'. $cr;
$content .= '$g2ic_embed_uri = \''. variable_get('gallery_embed_uri', '?q=gallery') .'\';'. $cr;
$content .= '$g2ic_drupal_g2_filter = TRUE;'. $cr;
$content .= '$g2ic_drupal_g2_filter_prefix = \''. variable_get('gallery_filter_prefix', 'G2') .'\';'. $cr;
$content .= '$g2ic_language = \'en\';'. $cr;
$content .= '$g2ic_images_per_page = '. $form_state['values']['gallery_g2image_images_per_page'] .';'. $cr;
$content .= '$g2ic_display_filenames = '. $g2ic_display_filenames .';'. $cr;
$content .= '$g2ic_default_alignment = \''. $form_state['values']['gallery_g2image_default_alignment'] .'\';'. $cr;
$content .= '$g2ic_custom_class_1 = \''. $g2ic_custom_class[1] .'\';'. $cr;
$content .= '$g2ic_custom_class_2 = \''. $g2ic_custom_class[2] .'\';'. $cr;
$content .= '$g2ic_custom_class_3 = \''. $g2ic_custom_class[3] .'\';'. $cr;
$content .= '$g2ic_custom_class_4 = \''. $g2ic_custom_class[4] .'\';'. $cr;
$content .= '$g2ic_class_mode = \''. $form_state['values']['gallery_g2image_class_mode'] .'\';'. $cr;
$content .= '$g2ic_default_action = \''. $form_state['values']['gallery_g2image_default_action'] .'\';'. $cr;
$content .= '$g2ic_sortby = \''. $form_state['values']['gallery_g2image_sortby'] .'\';'. $cr;
$content .= '$g2ic_custom_url = \''. $form_state['values']['gallery_g2image_custom_url'] .'\';'. $cr;
$content .= $cr;
$content .= '?>'. $cr;
$filename = $path .'/config.php';
if (is_writable($filename) == FALSE) {
form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.',
array('@filename' => $filename)));
return;
}
$handle = fopen($filename, "w");
if (fwrite($handle, $content) === FALSE) {
form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.',
array('@filename' => $filename)));
return;
}
else {
drupal_set_message(t('G2Image configuration file successfully created.'));
}
fclose($handle);
}
/**
* Function _gallery_g2image_path().
*/
function _gallery_g2image_path($path = NULL) {
if (!isset($path)) {
// Standalone G2Image folder
$path = drupal_get_path('module', 'gallery_g2image') .'/g2image';
if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
$path = NULL;
// TinyMCE folder for G2Image plugin
if (module_exists('tinymce')) {
$path = drupal_get_path('module', 'tinymce');
$path .= '/tinymce/jscripts/tiny_mce/plugins/g2image';
if (!file_exists($path .'/config.php') && !file_check_directory($path)) {
$path = NULL;
}
}
}
}
// Store location of G2Image
variable_set('gallery_g2image_path', isset($path) ? $path : FALSE);
return $path;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment