first import
This commit is contained in:
2
sites/all/modules/styles/contrib/file_styles/README.txt
Normal file
2
sites/all/modules/styles/contrib/file_styles/README.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
Readme for File Styles
|
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administrative page callbacks for the File: Styles module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu callback; Listing of all current File styles.
|
||||
*/
|
||||
function file_style_list() {
|
||||
$page = array();
|
||||
|
||||
$styles = file_styles();
|
||||
$page['file_style_list'] = array(
|
||||
'#markup' => theme('file_style_list', array('styles' => $styles)),
|
||||
'#attached' => array(
|
||||
'css' => array(drupal_get_path('module', 'file_styles') . '/file_styles.admin.css' => array('preprocess' => FALSE)),
|
||||
),
|
||||
);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder; Form for adding a new file style.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see file_style_add_form_submit()
|
||||
* @see file_style_name_validate()
|
||||
*/
|
||||
function file_style_add_form($form, &$form_state) {
|
||||
$form['name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#size' => '64',
|
||||
'#title' => t('Style name'),
|
||||
'#default_value' => '',
|
||||
'#description' => t('The name is used in URLs for generated file. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
|
||||
'#element_validate' => array('file_style_name_validate'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Create new style'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for adding a new file style.
|
||||
*/
|
||||
function file_style_add_form_submit($form, &$form_state) {
|
||||
$style = array('name' => $form_state['values']['name']);
|
||||
$style = file_style_save($style);
|
||||
drupal_set_message(t('Style %name was created.', array('%name' => $style['name'])));
|
||||
$form_state['redirect'] = 'admin/config/file/file-styles/edit/' . $style['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Element validate function to ensure unique, URL safe style names.
|
||||
*/
|
||||
function file_style_name_validate($element, $form_state) {
|
||||
// Check for duplicates.
|
||||
$styles = file_styles();
|
||||
if (isset($styles[$element['#value']]) && (!isset($form_state['file_style']['msid']) || $styles[$element['#value']]['msid'] != $form_state['file_style']['msid'])) {
|
||||
form_set_error($element['#name'], t('The file style name %name is already in use.', array('%name' => $element['#value'])));
|
||||
}
|
||||
|
||||
// Check for illegal characters in file style names.
|
||||
if (preg_match('/[^0-9a-z_\-]/', $element['#value'])) {
|
||||
form_set_error($element['#name'], t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Form builder; Edit a file style name and effects order.
|
||||
*
|
||||
* @param $form_state
|
||||
* An associative array containing the current state of the form.
|
||||
* @param $style
|
||||
* An file style array.
|
||||
* @ingroup forms
|
||||
* @see file_style_form_submit()
|
||||
* @see file_style_name_validate()
|
||||
*/
|
||||
function file_style_form($form, &$form_state, $file_style) {
|
||||
$title = t('Edit %name style', array('%name' => $file_style['name']));
|
||||
drupal_set_title($title, PASS_THROUGH);
|
||||
|
||||
// Adjust this form for styles that must be overridden to edit.
|
||||
$editable = (bool) ($file_style['storage'] & IMAGE_STORAGE_EDITABLE);
|
||||
|
||||
if (!$editable && empty($form_state['input'])) {
|
||||
drupal_set_message(t('This file style is currently being provided by a module. Click the "Override defaults" button to change its settings.'), 'warning');
|
||||
}
|
||||
|
||||
$form_state['file_style'] = $file_style;
|
||||
$form['#tree'] = TRUE;
|
||||
$form['#attached']['css'][drupal_get_path('module', 'file') . '/file.admin.css'] = array('preprocess' => FALSE);
|
||||
$form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array('preprocess' => FALSE);
|
||||
|
||||
// // Show the thumbnail preview.
|
||||
// $form['preview'] = array(
|
||||
// '#type' => 'item',
|
||||
// '#title' => t('Preview'),
|
||||
// '#markup' => theme('file_style_preview', array('style' => $style)),
|
||||
// );
|
||||
|
||||
// Allow the name of the style to be changed, unless this style is
|
||||
// provided by a module's hook_default_file_styles().
|
||||
if ($file_style['storage'] & IMAGE_STORAGE_MODULE) {
|
||||
$form['name'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('File style name'),
|
||||
'#markup' => $file_style['name'],
|
||||
'#description' => t('This file style is being provided by %module module and may not be renamed.', array('%module' => $style['module'])),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#size' => '64',
|
||||
'#title' => t('File style name'),
|
||||
'#default_value' => $file_style['name'],
|
||||
'#description' => t('The name is used in URLs for generated file. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
|
||||
'#element_validate' => array('file_style_name_validate'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
// Build the list of existing file effects for this file style.
|
||||
$form['effects'] = array(
|
||||
'#theme' => 'file_style_effects',
|
||||
);
|
||||
// foreach ($style['effects'] as $meid => $effect) {
|
||||
// $form['effects'][$meid]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$meid]['weight'] : NULL;
|
||||
// $form['effects'][$meid]['label'] = array(
|
||||
// '#markup' => $effect['label'],
|
||||
// );
|
||||
// $form['effects'][$meid]['summary'] = array(
|
||||
// '#markup' => isset($effect['summary theme']) ? theme($effect['summary theme'], array('data' => $effect['data'])) : '',
|
||||
// );
|
||||
// $form['effects'][$meid]['weight'] = array(
|
||||
// '#type' => 'weight',
|
||||
// '#default_value' => $effect['weight'],
|
||||
// '#access' => $editable,
|
||||
// );
|
||||
// $form['effects'][$meid]['configure'] = array(
|
||||
// '#type' => 'link',
|
||||
// '#title' => t('edit'),
|
||||
// '#href' => 'admin/config/file/file-styles/edit/' . $style['name'] . '/effects/' . $effect['meid'],
|
||||
// '#access' => $editable && isset($effect['form callback']),
|
||||
// );
|
||||
// $form['effects'][$meid]['remove'] = array(
|
||||
// '#type' => 'link',
|
||||
// '#title' => t('delete'),
|
||||
// '#href' => 'admin/config/file/file-styles/edit/' . $style['name'] . '/effects/' . $effect['meid'] . '/delete',
|
||||
// '#access' => $editable,
|
||||
// );
|
||||
// }
|
||||
|
||||
$form['effects']['tabs'] = array(
|
||||
'#type' => 'vertical_tabs',
|
||||
);
|
||||
|
||||
// Build the new file effect addition form and add it to the effect list.
|
||||
foreach (file_effect_definitions() as $definition_name => $definition) {
|
||||
$form['effects']['tabs'][$definition_name] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#title' => check_plain($definition['label']),
|
||||
'#description' => t('@label will be applied to the following:<br />Streams: %streams<br />File types: %types', array('@label' => $definition['label'], '%streams' => implode(', ', $definition['streams']), '%types' => implode(', ', $definition['mimetypes']))),
|
||||
);
|
||||
$new_effect_options = array(' ' => t('Select a file style to apply'));
|
||||
foreach ($definition['styles'] as $style_name => $style) {
|
||||
$effects = array();
|
||||
foreach ($style['effects'] as $effect) {
|
||||
$data = array();
|
||||
foreach ($effect['data'] as $type => $value) {
|
||||
$data[] = t('@type = @value', array('@type' => $type, '@value' => $value));
|
||||
}
|
||||
$effects[] = t('@effect: (@data)', array('@effect' => $effect['label'], '@data' => implode(', ', $data)));
|
||||
}
|
||||
$new_effect_options[$style_name] = t('@name - %effects', array('@name' => $style['name'], '%effects' => implode('; ', $effects))); // check_plain($style['name'] . ' ' . implode(', ', $effects));
|
||||
}
|
||||
$form['effects']['tabs'][$definition_name]['new'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Please select a style from the following options:'),
|
||||
'#options' => $new_effect_options,
|
||||
'#default_value' => isset($file_style['styles'][$definition_name]) ? $file_style['styles'][$definition_name] : ' ',
|
||||
);
|
||||
if (isset($definition['add-new-link'])) {
|
||||
$form['effects']['tabs'][$definition_name]['new']['#description'] = filter_xss($definition['add-new-link']);
|
||||
}
|
||||
if (isset($definition['preview-theme'])) {
|
||||
// theme_image_style_preview is not properly registered.
|
||||
module_load_include('inc', 'image', 'image.admin');
|
||||
// Show the thumbnail preview.
|
||||
$form['effects']['tabs'][$definition_name]['preview'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('Preview'),
|
||||
'#markup' => theme($definition['preview-theme'], array('style' => $definition['styles']['thumbnail'])),// $file_style['styles'][$definition_name])),
|
||||
);
|
||||
}
|
||||
// $form['effects']['tabs'][$definition_name]['weight'] = array(
|
||||
// '#type' => 'weight',
|
||||
// '#default_value' => count($form['effects']['tabs'][$definition_name]) - 1,
|
||||
// );
|
||||
}
|
||||
|
||||
// $new_effect_options = array('' => t('Select a new effect'));
|
||||
// foreach (file_effect_definitions() as $effect => $definition) {
|
||||
// $new_effect_options[$effect] = check_plain($definition['name']);
|
||||
// }
|
||||
// $form['effects']['new'] = array(
|
||||
// '#tree' => FALSE,
|
||||
// '#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
|
||||
// '#access' => $editable,
|
||||
// );
|
||||
// $form['effects']['new']['new'] = array(
|
||||
// '#type' => 'radios',
|
||||
// '#options' => $new_effect_options,
|
||||
// );
|
||||
|
||||
// $form['effects']['new']['add'] = array(
|
||||
// '#type' => 'submit',
|
||||
// '#value' => t('Add'),
|
||||
// '#validate' => array('file_style_form_add_validate'),
|
||||
// '#submit' => array('file_style_form_submit', 'file_style_form_add_submit'),
|
||||
// );
|
||||
|
||||
// Show the Override or Submit button for this style.
|
||||
$form['override'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Override defaults'),
|
||||
'#validate' => array(),
|
||||
'#submit' => array('file_style_form_override_submit'),
|
||||
'#access' => !$editable,
|
||||
);
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Update style'),
|
||||
'#access' => $editable,
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate handler for adding a new file effect to a file style.
|
||||
*/
|
||||
function file_style_form_add_validate($form, &$form_state) {
|
||||
if (!$form_state['values']['new']) {
|
||||
form_error($form['effects']['new']['new'], t('Select an effect to add.'));
|
||||
$form_state['rebuild'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for adding a new file effect to a file style.
|
||||
*/
|
||||
function file_style_form_add_submit($form, &$form_state) {
|
||||
$style = $form_state['file_style'];
|
||||
// Check if this field has any configuration options.
|
||||
$effect = file_effect_definition_load($form_state['values']['new']);
|
||||
|
||||
// Load the configuration form for this option.
|
||||
if (isset($effect['form callback'])) {
|
||||
$path = 'admin/config/file/file-styles/edit/' . $form_state['file_style']['name'] . '/add/' . $form_state['values']['new'];
|
||||
$form_state['redirect'] = array($path, array('query' => array('weight' => $form_state['values']['weight'])));
|
||||
}
|
||||
// If there's no form, imfiletely add the file effect.
|
||||
else {
|
||||
$effect['isid'] = $style['isid'];
|
||||
$effect['weight'] = $form_state['values']['weight'];
|
||||
file_effect_save($effect);
|
||||
drupal_set_message(t('The file effect was successfully applied.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for overriding a module-defined style.
|
||||
*/
|
||||
function file_style_form_override_submit($form, &$form_state) {
|
||||
drupal_set_message(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $form_state['file_style']['name'])));
|
||||
file_default_style_save($form_state['file_style']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for saving a file style.
|
||||
*/
|
||||
function file_style_form_submit($form, &$form_state) {
|
||||
// Update the file style name if it has changed.
|
||||
$style = $form_state['file_style'];
|
||||
if (isset($form_state['values']['name']) && $style['name'] != $form_state['values']['name']) {
|
||||
$style['name'] = $form_state['values']['name'];
|
||||
}
|
||||
|
||||
// Update file effect weights.
|
||||
if (!empty($form_state['values']['effects'])) {
|
||||
foreach ($form_state['values']['effects'] as $meid => $effect_data) {
|
||||
if (isset($style['effects'][$meid])) {
|
||||
$effect = $style['effects'][$meid];
|
||||
$effect['weight'] = $effect_data['weight'];
|
||||
file_effect_save($effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file_style_save($style);
|
||||
if ($form_state['values']['op'] == t('Update style')) {
|
||||
drupal_set_message('Changes to the style have been saved.');
|
||||
}
|
||||
$form_state['redirect'] = 'admin/config/file/file-styles/edit/' . $style['name'];
|
||||
}
|
||||
|
||||
function file_style_delete_form() {
|
||||
}
|
||||
|
||||
function file_style_revert_form() {
|
||||
}
|
||||
|
||||
function file_effect_form() {
|
||||
}
|
||||
|
||||
function file_effect_delete_form() {
|
||||
}
|
||||
|
||||
// function file_effect_form() {
|
||||
// }
|
||||
|
||||
/**
|
||||
* Display the page containing the list of file styles.
|
||||
*
|
||||
* @param $variables
|
||||
* An associative array containing:
|
||||
* - styles: An array of all the file styles returned by file_get_styles().
|
||||
*
|
||||
* @see file_get_styles()
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_file_style_list($variables) {
|
||||
$styles = $variables['styles'];
|
||||
|
||||
$header = array(t('Style name'), t('Settings'), array('data' => t('Operations'), 'colspan' => 3));
|
||||
$rows = array();
|
||||
foreach ($styles as $style) {
|
||||
$row = array();
|
||||
$row[] = l($style['name'], 'admin/config/file/file-styles/edit/' . $style['name']);
|
||||
$link_attributes = array(
|
||||
'attributes' => array(
|
||||
'class' => array('file-style-link'),
|
||||
),
|
||||
);
|
||||
if ($style['storage'] == IMAGE_STORAGE_NORMAL) {
|
||||
$row[] = t('Custom');
|
||||
$row[] = l(t('edit'), 'admin/config/file/file-styles/edit/' . $style['name'], $link_attributes);
|
||||
$row[] = l(t('delete'), 'admin/config/file/file-styles/delete/' . $style['name'], $link_attributes);
|
||||
}
|
||||
elseif ($style['storage'] == IMAGE_STORAGE_OVERRIDE) {
|
||||
$row[] = t('Overridden');
|
||||
$row[] = l(t('edit'), 'admin/config/file/file-styles/edit/' . $style['name'], $link_attributes);
|
||||
$row[] = l(t('revert'), 'admin/config/file/file-styles/revert/' . $style['name'], $link_attributes);
|
||||
}
|
||||
else {
|
||||
$row[] = t('Default');
|
||||
$row[] = l(t('edit'), 'admin/config/file/file-styles/edit/' . $style['name'], $link_attributes);
|
||||
$row[] = '';
|
||||
}
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
if (empty($rows)) {
|
||||
$rows[] = array(array(
|
||||
'colspan' => 4,
|
||||
'data' => t('There are currently no styles. <a href="!url">Add a new one</a>.', array('!url' => url('admin/config/file/file-styles/add'))),
|
||||
));
|
||||
}
|
||||
|
||||
return theme('table', array('header' => $header, 'rows' => $rows));
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Functions needed to execute image effects provided by Image module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement hook_file_effect_info().
|
||||
*/
|
||||
function file_styles_file_effect_info() {
|
||||
$effects = array(
|
||||
'file_styles_image' => array(
|
||||
'label' => t('Image styles'),
|
||||
'styles' => array(),
|
||||
'streams' => array('public://', 'private://'),
|
||||
'mimetypes' => array('image/gif', 'image/jpeg', 'image/png'),
|
||||
'module' => 'image',
|
||||
'preview-theme' => 'image_style_preview',
|
||||
'add-new-link' => l(t('Add new image style'), 'admin/config/file/image-styles/add'),
|
||||
)
|
||||
);
|
||||
|
||||
foreach (image_styles() as $style_name => $style) {
|
||||
$effects['file_styles_image']['styles'][$style_name] = $style;
|
||||
}
|
||||
|
||||
return $effects;
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
|
||||
name = File Styles
|
||||
description = Allows preset transformation of files and media for display.
|
||||
package = Styles
|
||||
core = 7.x
|
||||
files[] = file_styles.module
|
||||
files[] = file_styles.admin.inc
|
||||
files[] = includes/styles/FileStyles.inc
|
||||
dependencies[] = styles
|
||||
dependencies[] = image
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-06-01
|
||||
version = "7.x-2.0-alpha8"
|
||||
core = "7.x"
|
||||
project = "styles"
|
||||
datestamp = "1306964517"
|
||||
|
155
sites/all/modules/styles/contrib/file_styles/file_styles.install
Normal file
155
sites/all/modules/styles/contrib/file_styles/file_styles.install
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file styles/contrib/file_styles/file_styles.install
|
||||
* Install, update and uninstall functions for the file styles module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement hook_install().
|
||||
*/
|
||||
function file_styles_install() {
|
||||
// Create the styles directory and ensure it's writable.
|
||||
$path = 'temporary://file-styles';
|
||||
file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_uninstall().
|
||||
*/
|
||||
function file_styles_uninstall() {
|
||||
// Remove the styles directory and generated images.
|
||||
$path = 'temporary://file-styles';
|
||||
file_unmanaged_delete_recursive($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_schema().
|
||||
*/
|
||||
function file_styles_schema() {
|
||||
$schema = array();
|
||||
|
||||
$schema['cache_file_styles'] = drupal_get_schema_unprocessed('system', 'cache');
|
||||
$schema['cache_file_styles']['description'] = 'Cache table used to store information file manipulations that are in-progress.';
|
||||
|
||||
$schema['file_styles'] = array(
|
||||
'description' => 'Stores configuration options for file styles.',
|
||||
'fields' => array(
|
||||
'msid' => array(
|
||||
'description' => 'The primary identifier for a file style.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'The style name.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('msid'),
|
||||
'indexes' => array(
|
||||
'name' => array('name'),
|
||||
),
|
||||
);
|
||||
|
||||
$schema['file_effects'] = array(
|
||||
'description' => 'Stores configuration options for file effects.',
|
||||
'fields' => array(
|
||||
'meid' => array(
|
||||
'description' => 'The primary identifier for an file effect.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'msid' => array(
|
||||
'description' => 'The {file_styles}.isid for a file style.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'weight' => array(
|
||||
'description' => 'The weight of the effect in the style.',
|
||||
'type' => 'int',
|
||||
'unsigned' => FALSE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'The unique name of the effect to be executed.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'data' => array(
|
||||
'description' => 'The configuration data for the effect.',
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('meid'),
|
||||
'indexes' => array(
|
||||
'msid' => array('msid'),
|
||||
'weight' => array('weight'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'msid' => array('file_styles' => 'msid'),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add labels to file styles.
|
||||
*/
|
||||
function file_styles_update_7202() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild themes.
|
||||
*/
|
||||
function file_styles_update_7203() {
|
||||
drupal_theme_rebuild();
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new presets.
|
||||
*/
|
||||
function file_styles_update_7206() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix presets to use camelCase and honor links to media.
|
||||
*/
|
||||
function file_styles_update_7207() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch any image styles for use as new presets and register new hooks.
|
||||
*/
|
||||
function file_styles_update_7208() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix any broken custom image styles.
|
||||
*/
|
||||
function file_styles_update_7209() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add support for media objects.
|
||||
*/
|
||||
function file_styles_update_7210() {
|
||||
return array();
|
||||
}
|
169
sites/all/modules/styles/contrib/file_styles/file_styles.module
Normal file
169
sites/all/modules/styles/contrib/file_styles/file_styles.module
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file styles/contrib/file_styles/file_styles.module
|
||||
* File widget formatter definitions.
|
||||
*/
|
||||
|
||||
// A registry of variable_get defaults.
|
||||
include_once('includes/file_styles.variables.inc');
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_register().
|
||||
*/
|
||||
function file_styles_styles_register() {
|
||||
return array(
|
||||
'FileStyles' => array(
|
||||
'field_types' => 'file',
|
||||
'name' => t('file'),
|
||||
'description' => t('file styles'),
|
||||
'path' => drupal_get_path('module', 'file_styles') .'/includes/styles',
|
||||
'file' => 'FileStyles.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Styles filter callback.
|
||||
*
|
||||
* This will determine the correct style container corresponding to media type.
|
||||
*/
|
||||
function file_styles_styles_filter($object, $element = NULL) {
|
||||
// Ensure we're working against the fully loaded file object.
|
||||
$file = file_styles_uri_to_object($object->uri, TRUE);
|
||||
|
||||
// Allow other modules to define their own file styles.
|
||||
// In general, they'll most likely want to check against the mimetype.
|
||||
$containers = styles_default_containers('file');
|
||||
$filters = module_invoke_all('file_styles_filter', $object);
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if (isset($containers['containers'][$filter])) {
|
||||
return $filter;
|
||||
}
|
||||
}
|
||||
|
||||
// Now check the part of the mimetype before the slash.
|
||||
// Note that we can't use strstr($haystack, $needle, $before_needle)
|
||||
// < PHP 5.3, so we need a work-around.
|
||||
$filter = file_styles_strstr($object->filemime, '/', TRUE);
|
||||
if (isset($containers['containers'][$filter])) {
|
||||
return $filter;
|
||||
}
|
||||
|
||||
// Fallback to default.
|
||||
return 'default';
|
||||
}
|
||||
|
||||
/**
|
||||
* Support for strstr with $before_needle < PHP 5.3.
|
||||
*/
|
||||
function file_styles_strstr($haystack, $needle, $before_needle = FALSE){
|
||||
if ($before_needle) {
|
||||
list($var) = explode($needle, $haystack, 2);
|
||||
return $var;
|
||||
}
|
||||
return strstr($haystack, $needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path to the image for previews in Styles UI.
|
||||
*
|
||||
* If it doesn't yet exist, then copy the source to the files directory.
|
||||
*
|
||||
* @param boolean $replace
|
||||
* If TRUE, then replace the file.
|
||||
*
|
||||
* @return mixed
|
||||
* The path to the image preview file, or FALSE if unable to copy.
|
||||
*/
|
||||
function file_styles_preview_image($replace = FALSE) {
|
||||
$path = file_styles_variable_get('preview_image');
|
||||
if (!$path || $replace) {
|
||||
$dir = file_default_scheme() . '://' . file_styles_variable_get('preview_image_directory');
|
||||
if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
|
||||
$source = file_styles_variable_get('image_style_preview_image');
|
||||
if ($path = file_unmanaged_copy($source, $dir . '/' . basename($source), FILE_EXISTS_REPLACE)) {
|
||||
file_styles_variable_set('preview_image', $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme().
|
||||
*/
|
||||
function file_styles_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'file_styles_image' => array(
|
||||
'variables' => array('image_uri' => '', 'alt' => '', 'title' => '', 'attributes' => array(), 'image_style' => NULL, 'instance' => NULL),
|
||||
'file' => 'file_styles.theme.inc',
|
||||
'path' => $path . '/includes/themes',
|
||||
),
|
||||
'file_styles_image_preview' => array(
|
||||
'variables' => array('style_name' => NULL),
|
||||
'file' => 'file_styles.theme.inc',
|
||||
'path' => $path . '/includes/themes',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file object which can be passed to file_save().
|
||||
*
|
||||
* @param $uri
|
||||
* A string containing the URI, path, or filename.
|
||||
* @param $use_existing
|
||||
* (Optional) If TRUE and there's an existing file in the {file_managed}
|
||||
* table with the passed in URI, then that file object is returned.
|
||||
* Otherwise, a new file object is returned.
|
||||
* @return
|
||||
* A file object, or FALSE on error.
|
||||
*
|
||||
* @see http://drupal.org/node/685818
|
||||
*/
|
||||
function file_styles_uri_to_object($uri, $use_existing = FALSE) {
|
||||
if ($use_existing) {
|
||||
$query = db_select('file_managed', 'f')
|
||||
->fields('f', array('fid'))
|
||||
->condition('uri', $uri)
|
||||
->execute()
|
||||
->fetchCol();
|
||||
if (!empty($query)) {
|
||||
$file = file_load(array_shift($query));
|
||||
}
|
||||
}
|
||||
if (!isset($file)) {
|
||||
global $user;
|
||||
$uri = file_stream_wrapper_uri_normalize($uri);
|
||||
$wrapper = file_stream_wrapper_get_instance_by_uri($uri);
|
||||
$file = new StdClass;
|
||||
$file->uid = $user->uid;
|
||||
$file->filename = basename($uri);
|
||||
$file->uri = $uri;
|
||||
$file->filemime = file_get_mimetype($uri);
|
||||
// This is gagged because some uris will not support it.
|
||||
$file->filesize = @filesize($uri);
|
||||
$file->timestamp = REQUEST_TIME;
|
||||
$file->status = FILE_STATUS_PERMANENT;
|
||||
$file->is_new = TRUE;
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_image_style_save().
|
||||
*/
|
||||
function file_styles_image_style_save($image_style) {
|
||||
// Rebuild the styles to account for any new image styles.
|
||||
styles_style_flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_image_style_delete().
|
||||
*/
|
||||
function file_styles_image_style_delete($image_style) {
|
||||
// Rebuild the styles to account for any deleted image styles.
|
||||
styles_style_flush();
|
||||
}
|
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Theme functions for File styles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A wrapper for the image style preview.
|
||||
*/
|
||||
function theme_file_styles_image_style_preview($variables) {
|
||||
$style_name = $variables['style_name'];
|
||||
$styles = image_styles();
|
||||
if (isset($styles[$style_name])) {
|
||||
// The theme_image_style_preview function is in image.admin,
|
||||
// but not properly referenced in hook_theme.
|
||||
// @TODO: File a bug report and fix this in core.
|
||||
module_load_include('inc', 'image', 'image.admin');
|
||||
drupal_add_css(drupal_get_path('module', 'image') . '/image.admin.css');
|
||||
|
||||
// Ensure we revert the module & storage namespace for the Image module.
|
||||
if (isset($styles[$style_name]['image_module'])) {
|
||||
$styles[$style_name]['module'] = $styles[$style_name]['image_module'];
|
||||
$styles[$style_name]['storage'] = $styles[$style_name]['image_storage'];
|
||||
}
|
||||
|
||||
return theme('image_style_preview', array('style' => $styles[$style_name]));
|
||||
}
|
||||
}
|
||||
|
||||
function theme_file_styles_styles_default($variables) {
|
||||
$file = $variables['object'];
|
||||
$path = drupal_get_path('module', 'file');
|
||||
$thumbnail = theme('image',
|
||||
array(
|
||||
'path' => $path . '/images/file-unknown.png',
|
||||
'alt' => t('Thumbnail for !filename.', array('!filename' => $file->filename)),
|
||||
'attributes' => array('width' => 100, 'height' => 75, 'class' => 'file-unknown'),
|
||||
)
|
||||
);
|
||||
return $thumbnail;
|
||||
}
|
||||
|
||||
function theme_file_styles_preview_default($variables) {
|
||||
return 'default: theme_file_styles_preview_default';
|
||||
}
|
||||
|
||||
function theme_file_styles_field_formatter_styles_default($variables) {
|
||||
$file = $variables['object'];
|
||||
$file_url = file_create_url($file->uri);
|
||||
return l($file->filename, $file_url);
|
||||
}
|
||||
|
||||
function theme_file_styles_field_formatter_styles($variables) {
|
||||
// The formatter name needs to match what theme_field_formatter_image expects.
|
||||
$variables['element']['#formatter'] = '__' . $variables['style']['name'];
|
||||
|
||||
// Add Alt & Title to the element.
|
||||
$variables['element']['#item']['alt'] = $variables['element']['#item']['title'] = $variables['element']['#item']['description'];
|
||||
|
||||
// Defer to Image Styles for the rest.
|
||||
return theme('field_formatter_image', $variables);
|
||||
|
||||
}
|
||||
|
||||
function theme_file_styles_image($variables) {
|
||||
$file = $variables['object'];
|
||||
$style_name = $variables['style_name'];
|
||||
$vars = array();
|
||||
$vars['path'] = $file->uri;
|
||||
// Allow image attributes to be provided by the passed-in file object. 'alt'
|
||||
// and 'title' need to be separated out because they are treated specially by
|
||||
// theme_image().
|
||||
if (isset($file->override)) {
|
||||
$vars['attributes'] = $file->override;
|
||||
foreach (array('alt', 'title') as $attribute) {
|
||||
if (isset($vars['attributes'][$attribute])) {
|
||||
$vars[$attribute] = $vars['attributes'][$attribute];
|
||||
unset($vars['attributes'][$attribute]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add default values for 'alt' and 'title'.
|
||||
if (!isset($vars['alt'])) {
|
||||
$vars['alt'] = isset($variables['description']) ? $variables['description'] : (isset($file->description) ? $file->description : '');
|
||||
}
|
||||
if (!isset($vars['title']) || $vars['title'] === '') {
|
||||
$vars['title'] = isset($variables['title']) ? $variables['title'] : $vars['alt'];
|
||||
}
|
||||
|
||||
// Special case for 'original'.
|
||||
// @TODO Certainly can be more elegant than this.
|
||||
if ($style_name == 'original') {
|
||||
$vars['getsize'] = FALSE;
|
||||
return theme('image', $vars);
|
||||
}
|
||||
|
||||
$vars['style_name'] = $style_name;
|
||||
//@TODO: How to add fields here?
|
||||
return theme('image_style', $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support for HTML5 videos out of the box.
|
||||
*/
|
||||
function theme_file_styles_video($variables) {
|
||||
$file = $variables['object'];
|
||||
$style_name = $variables['style_name'];
|
||||
|
||||
$vars = array();
|
||||
$width = isset($variables['width']) ? $variables['width'] : NULL;
|
||||
$height = isset($variables['height']) ? $variables['height'] : NULL;
|
||||
|
||||
$path = file_create_url($file->uri);
|
||||
|
||||
$preset_name = $variables['preset_name'];
|
||||
$preset = styles_containers_available_styles('file', 'video', $preset_name);
|
||||
|
||||
// By default, we don't display as a thumbnail.
|
||||
$thumbnail = FALSE;
|
||||
|
||||
foreach ($preset['effects'] as $effect) {
|
||||
switch ($effect['name']) {
|
||||
case 'resize':
|
||||
$width = isset($effect['data']['width']) ? $effect['data']['width'] : $width;
|
||||
$height = isset($effect['data']['height']) ? $effect['data']['height'] : $height;
|
||||
break;
|
||||
case 'thumbnail':
|
||||
$thumbnail = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($variables['object']->override)) {
|
||||
$override = $variables['object']->override;
|
||||
|
||||
$width = isset($override['width']) ? $override['width'] : $width;
|
||||
$height = isset($override['height']) ? $override['height'] : $height;
|
||||
if (isset($override['wysiwyg']) && $override['wysiwyg']) {
|
||||
$thumbnail = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$vars['attributes'] = array('width' => $width, 'height' => $height);
|
||||
|
||||
if ($thumbnail) {
|
||||
return theme('image', array('path' => drupal_get_path('module', 'file_styles') . '/images/file-video.png', 'attributes' => $vars['attributes'], 'getsize' => FALSE));
|
||||
}
|
||||
|
||||
$width = isset($vars['attributes']['width']) ? ('width="' . $vars['attributes']['width'] . '"') : '';
|
||||
$height = isset($vars['attributes']['height']) ? ('height="' . $vars['attributes']['height'] . '"') : '';
|
||||
|
||||
switch($file->filemime) {
|
||||
case 'video/ogg':
|
||||
$source = "<source src='$path' type='video/ogg; codecs=\"theora, vorbis\"'>";
|
||||
break;
|
||||
case 'video/mp4':
|
||||
$source = "<source src='$path' type='video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'>";
|
||||
break;
|
||||
}
|
||||
|
||||
$output = "<video $width $height controls>$source</video>";
|
||||
|
||||
return $output;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file file_styles/includes/file_styles.variables.inc
|
||||
* Variable defaults for File Styles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define our constants.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the variable namespace, automatically prepended to module variables.
|
||||
*/
|
||||
define('FILE_STYLES_NAMESPACE', 'file_styles__');
|
||||
|
||||
/**
|
||||
* Wrapper for variable_get() using the File Styles variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to retrieve. Note that it will be namespaced by
|
||||
* pre-pending FILE_STYLES_NAMESPACE, as to avoid variable collisions
|
||||
* with other modules.
|
||||
* @param unknown $default
|
||||
* An optional default variable to return if the variable hasn't been set
|
||||
* yet. Note that within this module, all variables should already be set
|
||||
* in the file_styles_variable_default() function.
|
||||
* @return unknown
|
||||
* Returns the stored variable or its default.
|
||||
*
|
||||
* @see file_styles_variable_set()
|
||||
* @see file_styles_variable_del()
|
||||
* @see file_styles_variable_default()
|
||||
*/
|
||||
function file_styles_variable_get($name, $default = NULL) {
|
||||
// Allow for an override of the default.
|
||||
// Useful when a variable is required (like $path), but namespacing is still
|
||||
// desired.
|
||||
if (!isset($default)) {
|
||||
$default = file_styles_variable_default($name);
|
||||
}
|
||||
// Namespace all variables.
|
||||
$variable_name = FILE_STYLES_NAMESPACE . $name;
|
||||
return variable_get($variable_name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for variable_set() using the File Styles variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to set. Note that it will be namespaced by
|
||||
* pre-pending FILE_STYLES_NAMESPACE, as to avoid variable collisions with
|
||||
* other modules.
|
||||
* @param unknown $value
|
||||
* The value for which to set the variable.
|
||||
* @return unknown
|
||||
* Returns the stored variable after setting.
|
||||
*
|
||||
* @see file_styles_variable_get()
|
||||
* @see file_styles_variable_del()
|
||||
* @see file_styles_variable_default()
|
||||
*/
|
||||
function file_styles_variable_set($name, $value) {
|
||||
$variable_name = FILE_STYLES_NAMESPACE . $name;
|
||||
return variable_set($variable_name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for variable_del() using the File Styles variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to delete. Note that it will be namespaced by
|
||||
* pre-pending FILE_STYLES_NAMESPACE, as to avoid variable collisions with
|
||||
* other modules.
|
||||
*
|
||||
* @see file_styles_variable_get()
|
||||
* @see file_styles_variable_set()
|
||||
* @see file_styles_variable_default()
|
||||
*/
|
||||
function file_styles_variable_del($name) {
|
||||
$variable_name = FILE_STYLES_NAMESPACE . $name;
|
||||
variable_del($variable_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default variables within the File Styles namespace.
|
||||
*
|
||||
* @param string $name
|
||||
* Optional variable name to retrieve the default. Note that it has not yet
|
||||
* been pre-pended with the FILE_STYLES_NAMESPACE namespace at this time.
|
||||
* @return unknown
|
||||
* The default value of this variable, if it's been set, or NULL, unless
|
||||
* $name is NULL, in which case we return an array of all default values.
|
||||
*
|
||||
* @see file_styles_variable_get()
|
||||
* @see file_styles_variable_set()
|
||||
* @see file_styles_variable_del()
|
||||
*/
|
||||
function file_styles_variable_default($name = NULL) {
|
||||
static $defaults;
|
||||
|
||||
if (!isset($defaults)) {
|
||||
$defaults = array(
|
||||
'image_style_preview_image' => variable_get('image_style_preview_image', drupal_get_path('module', 'image') . '/sample.png'),
|
||||
'preview_image_directory' => 'file-styles',
|
||||
'preview_image' => '',
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset($name)) {
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
if (isset($defaults[$name])) {
|
||||
return $defaults[$name];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fully namespace variable name.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to retrieve the namespaced name.
|
||||
* @return string
|
||||
* The fully namespace variable name, prepended with
|
||||
* FILE_STYLES_NAMESPACE.
|
||||
*/
|
||||
function file_styles_variable_name($name) {
|
||||
return FILE_STYLES_NAMESPACE . $name;
|
||||
}
|
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file styles/contrib/file_styles/includes/styles/FileStyles.inc
|
||||
* Styles definitions for file styles.
|
||||
*/
|
||||
|
||||
class FileStyles extends StylesDefault {
|
||||
public $fid;
|
||||
public $uri;
|
||||
public $title;
|
||||
public $alt;
|
||||
|
||||
public $width;
|
||||
public $height;
|
||||
|
||||
public $float;
|
||||
|
||||
public $imagecachePreset = '';
|
||||
public $link;
|
||||
|
||||
public $wrapperType = 'span';
|
||||
public $classes = array('styles', 'file-styles');
|
||||
|
||||
public $streamWrapperInstance;
|
||||
|
||||
function getStreamWrapperInstance() {
|
||||
$streamWrapperInstance = $this->get('stream_wrapper_instance');
|
||||
if (!isset($streamWrapperInstance)) {
|
||||
$streamWrapperInstance = $this->setStreamWrapperInstance(file_stream_wrapper_get_instance_by_uri($this->getUri()));
|
||||
}
|
||||
return $streamWrapperInstance;
|
||||
}
|
||||
function setStreamWrapperInstance($value) {
|
||||
return $this->set('stream_wrapper_instance', $value);
|
||||
}
|
||||
|
||||
function getFid() {
|
||||
return $this->get('fid');
|
||||
}
|
||||
function setFid($value) {
|
||||
return $this->set('fid', $value);
|
||||
}
|
||||
function setObject($value) {
|
||||
$variables = $this->getVariables();
|
||||
if (!isset($value->override) && isset($variables['entity']) && isset($variables['entity']->override)) {
|
||||
$value->override = $variables['entity']->override;
|
||||
}
|
||||
return $this->set('object', $value);
|
||||
}
|
||||
function getUri() {
|
||||
$uri = $this->get('uri');
|
||||
if (isset($uri)) {
|
||||
return $uri;
|
||||
}
|
||||
// If we don't have a URI yet, then try to find it from the object.
|
||||
$object = $this->getObject();
|
||||
if (isset($object->uri)) {
|
||||
return $object->uri;
|
||||
}
|
||||
}
|
||||
function setUri($value) {
|
||||
return $this->set('uri', $value);
|
||||
}
|
||||
function getTitle() {
|
||||
return $this->override('title');
|
||||
}
|
||||
function setTitle($value) {
|
||||
// @TODO: Token support.
|
||||
return $this->set('title', $value);
|
||||
}
|
||||
function getAlt() {
|
||||
return $this->override('alt');
|
||||
}
|
||||
function setAlt($value) {
|
||||
return $this->set('alt', $value);
|
||||
}
|
||||
function getWidth() {
|
||||
return $this->override('width');
|
||||
}
|
||||
function setWidth($value) {
|
||||
return $this->set('width', $value);
|
||||
}
|
||||
function getHeight() {
|
||||
return $this->override('height');
|
||||
}
|
||||
function setHeight($value) {
|
||||
return $this->set('height', $value);
|
||||
}
|
||||
function getImageStyle() {
|
||||
return $this->get('imageStyle');
|
||||
}
|
||||
function setImageStyle($value) {
|
||||
return $this->set('imageStyle', $value);
|
||||
}
|
||||
function getLink() {
|
||||
return $this->get('link');
|
||||
}
|
||||
function setLink($value) {
|
||||
return $this->set('link', $value);
|
||||
}
|
||||
function getFloat() {
|
||||
return $this->override('float');
|
||||
}
|
||||
function setFloat($value) {
|
||||
if ($value) {
|
||||
$this->setPrefix('<span class="styles file-styles file-styles-float-'. filter_xss($value) .'">');
|
||||
}
|
||||
else {
|
||||
$this->setPrefix('<span class="styles file-styles">');
|
||||
}
|
||||
return $this->set('float', $value);
|
||||
}
|
||||
|
||||
function setImageUri($value) {
|
||||
return $this->set('imageUri', $value);
|
||||
}
|
||||
function getImageUri() {
|
||||
if ($imageUri = $this->get('imageUri')) {
|
||||
return $imageUri;
|
||||
}
|
||||
return $this->getUri();
|
||||
}
|
||||
|
||||
// Allow WYSIWYG to override the values.
|
||||
public function override($attribute) {
|
||||
$object = $this->getObject();
|
||||
if (isset($object->override) && is_array($object->override) && isset($object->override[$attribute])) {
|
||||
return $object->override[$attribute];
|
||||
}
|
||||
return $this->get($attribute);
|
||||
}
|
||||
|
||||
// Effect callbacks when rendering.
|
||||
function thumbnail($effect) {
|
||||
$attributes = array();
|
||||
$width = $this->getWidth();
|
||||
$height = $this->getHeight();
|
||||
if (isset($width)) {
|
||||
$attributes['width'] = $width;
|
||||
}
|
||||
if (isset($height)) {
|
||||
$attributes['height'] = $height;
|
||||
}
|
||||
|
||||
// We have a .media-image class for WYSIWYG.
|
||||
// We can't used ->getClass, because that's restricted.
|
||||
$class = $this->override('class');
|
||||
if (isset($class)) {
|
||||
$attributes['class'] = $class;
|
||||
}
|
||||
|
||||
// Set any WYSIWYG prescribed styles.
|
||||
$style = $this->override('style');
|
||||
$attributes['style'] = isset($style) ? ($style . ';') : '';
|
||||
foreach (array('border-width', 'border-style', 'display', 'float', 'margin', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left') as $property) {
|
||||
$value = $this->override($property);
|
||||
if (isset($value)) {
|
||||
$attributes['style'] .= $property . ':' . $value . ';';
|
||||
}
|
||||
}
|
||||
|
||||
if ($attributes['style'] == '') {
|
||||
unset($attributes['style']);
|
||||
}
|
||||
|
||||
// Set any additional prescribed attributes.
|
||||
// @todo Remove this as a hard-coded list. Note that not everything in
|
||||
// $this->getObject()->override is an HTML attribute.
|
||||
foreach (array('id', 'class', 'dir', 'lang') as $attribute) {
|
||||
$value = $this->override($attribute);
|
||||
if (!empty($value)) {
|
||||
$attributes[$attribute] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($imageUri = $this->getImageUri()) {
|
||||
$this->setOutput(theme('file_styles_image', array('image_uri' => $imageUri, 'attributes' => $attributes, 'alt' => $this->getAlt(), 'title' => $this->getTitle(), 'image_style' => $this->getImageStyle(), 'instance' => $this)));
|
||||
// Honor any applied links.
|
||||
if ($link = $this->getLink()) {
|
||||
$this->setOutput(l($this->getOutput(), $link, array('html' => TRUE)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resize($effect) {
|
||||
if (isset($effect['width'])) {
|
||||
$this->setWidth($effect['width']);
|
||||
}
|
||||
if (isset($effect['height'])) {
|
||||
$this->setHeight($effect['height']);
|
||||
}
|
||||
}
|
||||
|
||||
function float($effect) {
|
||||
$this->setFloat($effect['float']);
|
||||
}
|
||||
|
||||
function imageStyle($effect) {
|
||||
$this->setImageStyle($effect['image_style']);
|
||||
}
|
||||
|
||||
function linkToMedia($effect) {
|
||||
// If we're using the media module, then link to its media page.
|
||||
if (module_exists('media') && ($fid = $this->getFid())) {
|
||||
$link = $this->setLink('media/'. $fid);
|
||||
}
|
||||
else {
|
||||
// Link to the file's external url.
|
||||
$uri = $this->getUri();
|
||||
$stream_wrapper = file_stream_wrapper_get_instance_by_uri($uri);
|
||||
$url = $stream_wrapper->getExternalUrl();
|
||||
$link = $this->setLink($url);
|
||||
}
|
||||
if (!$this->getOutput() && ($title = $this->getTitle())) {
|
||||
$this->setOutput(l($title, $link));
|
||||
}
|
||||
}
|
||||
|
||||
function linkToPath($effect) {
|
||||
$link = $this->setLink($effect['path']);
|
||||
if (!$this->getOutput() && $link && ($title = $this->getTitle())) {
|
||||
$this->setOutput(l($title, $link));
|
||||
}
|
||||
}
|
||||
|
||||
function teaser($effect) {
|
||||
$this->set('file', file_load($this->getFid()));
|
||||
$this->setOutput(file_view($this->get('file')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the render function to always display a thumbnail in the wysiwyg.
|
||||
*/
|
||||
public function render($reset = FALSE) {
|
||||
$object = $this->getObject();
|
||||
if (isset($object->override) && is_array($object->override) && isset($object->override['wysiwyg']) && $object->override['wysiwyg']) {
|
||||
// Disregard any links pushed ahead.
|
||||
$this->pushEffect(array('name' => 'linkToPath', 'settings' => array('path' => NULL)));
|
||||
// We ensure that the thumbnail will be applied at the end.
|
||||
$this->pushEffect(array('name' => 'thumbnail', 'settings' => array()));
|
||||
}
|
||||
return parent::render($reset);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file styles/contrib/file_styles/includes/styles/file_styles.styles.inc
|
||||
* Implementations of various Styles hooks.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_default_containers().
|
||||
*/
|
||||
function file_styles_styles_default_containers() {
|
||||
$containers = array();
|
||||
foreach (array('image', 'audio', 'video', 'default') as $type) {
|
||||
$containers[$type] = array(
|
||||
'label' => t(ucfirst($type)),
|
||||
'class' => 'FileStyles',
|
||||
);
|
||||
}
|
||||
$containers['image']['preview'] = 'file_styles_image_preview';
|
||||
return array(
|
||||
'file' => array(
|
||||
'admin' => array(
|
||||
'path' => 'admin/config/media/file-styles',
|
||||
),
|
||||
'filter callback' => 'file_styles_styles_filter',
|
||||
'help' => t('Each of the following containers defines a set of styles that will be applied when a file is of the specified type. For instance, if a file field allows images and videos, a specific style might be defined for \'Thumbnail\', that will display a cropped image when a JPEG is given, or a thumbnail linking to a shadowboxed video when an MPEG is stored.'),
|
||||
'containers' => $containers,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_default_containers().
|
||||
*/
|
||||
function file_styles_styles_default_containers_alter(&$styles) {
|
||||
if (module_exists('media')) {
|
||||
$styles['media'] = $styles['file'];
|
||||
}
|
||||
unset($styles['media']['admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_default_styles().
|
||||
*/
|
||||
function file_styles_styles_default_styles() {
|
||||
return array(
|
||||
'file' => array(
|
||||
'styles' => array(
|
||||
'square_thumbnail' => array(
|
||||
'label' => 'Square thumbnail',
|
||||
'description' => 'A 120x120 square thumbnail for browsing media by an editor.',
|
||||
),
|
||||
'thumbnail' => array(
|
||||
'label' => 'Thumbnail',
|
||||
'description' => 'Small thumbnails representing the media.',
|
||||
),
|
||||
'large' => array(
|
||||
'label' => 'Large',
|
||||
'description' => 'A large format of the media.',
|
||||
),
|
||||
'medium' => array(
|
||||
'label' => 'Medium',
|
||||
'description' => 'A medium format of the media.',
|
||||
),
|
||||
'original' => array(
|
||||
'label' => 'Original',
|
||||
'description' => 'The original format of the media.',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_default_styles().
|
||||
*/
|
||||
function file_styles_styles_default_styles_alter(&$styles) {
|
||||
if (module_exists('media')) {
|
||||
$styles['media'] = $styles['file'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_default_presets().
|
||||
*/
|
||||
function file_styles_styles_default_presets() {
|
||||
$containers = array();
|
||||
|
||||
// @TODO: The real deal for video/audio/etc.
|
||||
foreach (array('image', 'audio', 'video', 'default') as $type) {
|
||||
$containers[$type] = array(
|
||||
'default preset' => 'original',
|
||||
'styles' => array(
|
||||
'thumbnail' => array(
|
||||
'default preset' => 'linked_thumbnail',
|
||||
),
|
||||
'square_thumbnail' => array(
|
||||
'default preset' => 'linked_square_thumbnail',
|
||||
),
|
||||
'large' => array(
|
||||
'default preset' => 'large',
|
||||
),
|
||||
'medium' => array(
|
||||
'default preset' => 'medium',
|
||||
),
|
||||
),
|
||||
'presets' => array(
|
||||
'original' => array(
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
)
|
||||
),
|
||||
'unlinked_thumbnail' => array(
|
||||
array(
|
||||
'name' => 'imageStyle',
|
||||
'settings' => array(
|
||||
'image_style' => 'thumbnail',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
),
|
||||
),
|
||||
'linked_thumbnail' => array(
|
||||
array(
|
||||
'name' => 'linkToMedia',
|
||||
'settings' => array(),
|
||||
),
|
||||
array(
|
||||
'name' => 'imageStyle',
|
||||
'settings' => array(
|
||||
'image_style' => 'thumbnail',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
),
|
||||
),
|
||||
'linked_square_thumbnail' => array(
|
||||
array(
|
||||
'name' => 'linkToMedia',
|
||||
'settings' => array(),
|
||||
),
|
||||
array(
|
||||
'name' => 'imageStyle',
|
||||
'settings' => array(
|
||||
'image_style' => 'square_thumbnail',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
),
|
||||
),
|
||||
'large' => array(
|
||||
array(
|
||||
'name' => 'imageStyle',
|
||||
'settings' => array(
|
||||
'image_style' => 'large',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
),
|
||||
),
|
||||
'medium' => array(
|
||||
array(
|
||||
'name' => 'imageStyle',
|
||||
'settings' => array(
|
||||
'image_style' => 'medium',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
foreach (image_styles() as $style_name => $style) {
|
||||
if (!isset($containers['image']['presets'][$style_name])) {
|
||||
$containers['image']['presets'][$style_name] = array(
|
||||
array(
|
||||
'name' => 'imageStyle',
|
||||
'settings' => array(
|
||||
'image_style' => $style_name,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'thumbnail',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return array(
|
||||
'file' => array(
|
||||
'containers' => $containers,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_default_presets().
|
||||
*/
|
||||
function file_styles_styles_default_presets_alter(&$styles) {
|
||||
if (module_exists('media')) {
|
||||
$styles['media'] = $styles['file'];
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file file_styles/includes/themes/file_styles.theme.inc
|
||||
*
|
||||
* Theme and preprocess functions for the File Styles module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Display an image according to the style presented, or raw as specified.
|
||||
*/
|
||||
function theme_file_styles_image($variables) {
|
||||
// @TODO: Check to see if the image is local as well, for getsize.
|
||||
if (isset($variables['image_style'])) {
|
||||
$output = theme('image_style', array('style_name' => $variables['image_style'], 'path' => $variables['image_uri'], 'alt' => $variables['alt'], 'title' => $variables['title'], 'getsize' => FALSE, 'attributes' => $variables['attributes']));
|
||||
}
|
||||
else {
|
||||
$output = theme('image', array('path' => $variables['image_uri'], 'alt' => $variables['alt'], 'title' => $variables['title'], 'getsize' => FALSE, 'attributes' => $variables['attributes']));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview image for Styles UI.
|
||||
*/
|
||||
function theme_file_styles_image_preview($variables) {
|
||||
// Media requires a file object.
|
||||
// Also, image_style_url() crashes if you send it a file from a module.
|
||||
// Thus, we need to copy it to the public:// directory first, for styles
|
||||
// that need to use an image style.
|
||||
// @see http://drupal.org/node/987846#comment-3949112
|
||||
$sample_image = file_styles_preview_image();
|
||||
$variables['object'] = file_styles_uri_to_object($sample_image);
|
||||
$variables['field_type'] = 'file';
|
||||
return theme('styles', $variables);
|
||||
}
|
2
sites/all/modules/styles/contrib/styles_ui/README.txt
Normal file
2
sites/all/modules/styles/contrib/styles_ui/README.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
README for Styles UI
|
354
sites/all/modules/styles/contrib/styles_ui/styles_ui.admin.inc
Normal file
354
sites/all/modules/styles/contrib/styles_ui/styles_ui.admin.inc
Normal file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administrative page callbacks for the Styles UI module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page callback for various styles overview listing pages.
|
||||
*/
|
||||
function styles_ui_containers_overview($field_type) {
|
||||
// Get the full list of styles.
|
||||
$styles = styles_default_styles();
|
||||
|
||||
// Get the containers for this field type.
|
||||
$styles_containers = styles_default_containers();
|
||||
$field_containers = $styles_containers[$field_type];
|
||||
|
||||
// Build our table listing of styles.
|
||||
$header = array(t('Styles'), array('data' => t('Operations'), 'colspan' => 2));
|
||||
$rows = array();
|
||||
|
||||
foreach ($styles[$field_type]['styles'] as $style_name => $style) {
|
||||
// What's the path to edit this style?
|
||||
$edit_path = $field_containers['admin']['path'] . '/edit/' . $style_name;
|
||||
$row = array(l(t('@style', array('@style' => $style_name)), $edit_path));
|
||||
|
||||
// Add our ops.
|
||||
if ($style['storage'] == STYLES_STORAGE_NORMAL) {
|
||||
$row[] = array('data' => l(t('edit'), $edit_path));
|
||||
$row[] = array('data' => l(t('delete'), $field_containers['admin']['path'] . '/delete/' . $style_name));
|
||||
}
|
||||
else if ($style['storage'] == STYLES_STORAGE_OVERRIDE) {
|
||||
$row[] = array('data' => l(t('edit'), $edit_path));
|
||||
$row[] = array('data' => l(t('revert'), $field_containers['admin']['path'] . '/delete/' . $style_name));
|
||||
}
|
||||
else {
|
||||
$row[] = array('data' => l(t('edit'), $edit_path), 'colspan' => 2);
|
||||
}
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
// Add a new style link to the empty table.
|
||||
// Note that the link at the top of the page is placed in hook_menu.
|
||||
$field_info = field_info_field_types($field_type);
|
||||
$field_label = $field_info['label'];
|
||||
$title = 'Add ' . $field_label . ' style';
|
||||
|
||||
$build['styles_table'] = array(
|
||||
'#theme' => 'table',
|
||||
'#header' => $header,
|
||||
'#rows' => $rows,
|
||||
'#empty' => t('No styles available. <a href="@link">@add</a>.', array('@add' => t($title), '@link' => url($field_containers['admin']['path'] . '/add'))),
|
||||
);
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback for adding a style.
|
||||
*/
|
||||
function styles_ui_style_add_form($form, $form_state, $field_type) {
|
||||
$form = array();
|
||||
$form['field_type'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $field_type,
|
||||
);
|
||||
$form['name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Style name'),
|
||||
'#description' => t('Enter the name of your desired style, which must be a unique name containing only alphanumeric characters and underscores.'),
|
||||
);
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation handler for the add style form.
|
||||
*/
|
||||
function styles_ui_style_add_form_validate($form, $form_state) {
|
||||
$field_type = $form_state['values']['field_type'];
|
||||
$style_name = $form_state['values']['name'];
|
||||
$styles = styles_default_styles();
|
||||
if (!preg_match('!^[a-z0-9_]+$!', $style_name)) {
|
||||
form_set_error('style_name', t('The machine-readable style name must contain only lowercase letters, numbers, and underscores.'));
|
||||
}
|
||||
else if (!empty($styles[$field_type]['styles'][$style_name])) {
|
||||
form_set_error('style_name', t('The machine-readable style name %style_name is already taken.', array('%style_name' => $style_name)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submission handler for the add style form.
|
||||
*/
|
||||
function styles_ui_style_add_form_submit(&$form, &$form_state) {
|
||||
$field_type = $form_state['values']['field_type'];
|
||||
$style_name = $form_state['values']['name'];
|
||||
$style = array(
|
||||
'field_type' => $field_type,
|
||||
'name' => $style_name,
|
||||
'description' => '',
|
||||
);
|
||||
// Save the new style.
|
||||
styles_style_save($style);
|
||||
|
||||
// Get the containers for this field type.
|
||||
$styles_containers = styles_default_containers();
|
||||
$field_containers = $styles_containers[$field_type];
|
||||
|
||||
// Redirect to this style's edit page.
|
||||
$form_state['redirect'] = $field_containers['admin']['path'] . '/edit/' . $style_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for the style edit form.
|
||||
*/
|
||||
function styles_ui_style_edit_form($form, $form_state, $field_type, $style_name) {
|
||||
$style = styles_style_load($field_type, $style_name);
|
||||
|
||||
$form['field_type'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $field_type,
|
||||
);
|
||||
$form['old_style_name'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $style['name'],
|
||||
);
|
||||
|
||||
$form['name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Name'),
|
||||
'#description' => t('The name of this style, which must be a unique name containing only alphanumeric characters and underscores.'),
|
||||
'#default_value' => $style['name'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['description'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Description'),
|
||||
'#description' => t('The description of the style.'),
|
||||
'#default_value' => $style['description'],
|
||||
);
|
||||
|
||||
$form['containers'] = array(
|
||||
'#type' => 'vertical_tabs',
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$containers = styles_default_containers($field_type);
|
||||
$presets = styles_default_presets($field_type);
|
||||
foreach ($containers['containers'] as $container_name => $container) {
|
||||
$style = $presets['containers'][$container_name]['styles'][$style_name];
|
||||
$container_label = isset($container['label']) ? $container['label'] : $container_name;
|
||||
$form['containers'][$container_name] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('@container', array('@container' => $container_label)),
|
||||
);
|
||||
$options = array();
|
||||
foreach ($presets['containers'][$container_name]['presets'] as $preset_name => $preset) {
|
||||
$options[$preset_name] = t('@preset', array('@preset' => $preset_name));
|
||||
}
|
||||
$default_value = isset($presets['containers'][$container_name]['styles'][$style_name]['preset']) ? $presets['containers'][$container_name]['styles'][$style_name]['preset'] : (isset($presets['containers'][$container_name]['styles'][$style_name]['default preset']) ? $presets['containers'][$container_name]['styles'][$style_name]['default preset'] : $presets['containers'][$container_name]['default preset']);
|
||||
$form['containers'][$container_name]['preset'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Preset'),
|
||||
'#options' => $options,
|
||||
'#default_value' => $default_value,
|
||||
);
|
||||
$form['containers'][$container_name]['default_preset'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('Default preset'),
|
||||
'#markup' => t('%preset', array('%preset' => $style['default preset'])),
|
||||
);
|
||||
if (isset($container['preview'])) {
|
||||
$form['containers'][$container_name]['preview'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('Preview'),
|
||||
'#markup' => theme($container['preview'], array('style_name' => $style_name)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
return $form;
|
||||
// $field_info = field_info_field_types($field_type);
|
||||
// $presets = styles_default_presets();
|
||||
// $preset = $presets[$field_type]['containers'][$preset_name];
|
||||
// $styles_containers = styles_default_containers();
|
||||
// $containers = $styles_containers[$field_type]['containers'];
|
||||
// drupal_set_title(t('Edit @field_type style preset: @preset', array('@field_type' => $field_info['label'], '@preset' => $preset_name)));
|
||||
// $form = array();
|
||||
// $form['containers'] = array(
|
||||
// '#type' => 'vertical_tabs',
|
||||
// );
|
||||
// $styles = styles_default_styles($field_type);
|
||||
// dpm($styles);
|
||||
//
|
||||
// // Begin the settings array to send to jQuery.
|
||||
// $settings = array(
|
||||
// 'stylesUI' => array(
|
||||
// 'url' => url('styles-ui/preview'),
|
||||
// 'fieldType' => check_plain($field_type),
|
||||
// ),
|
||||
// );
|
||||
// foreach ($styles['styles'] as $style_name => $style) {
|
||||
// $form['containers'][$style_name] = array(
|
||||
// '#type' => 'fieldset',
|
||||
// '#title' => $style['label'],
|
||||
// );
|
||||
// if (isset($preset['styles'][$style_name]['current preset'])) {
|
||||
// $this_preset = $preset['styles'][$style_name]['current preset'];
|
||||
// }
|
||||
// else {
|
||||
// $this_preset = $preset['styles'][$style_name]['default preset'];
|
||||
// }
|
||||
// $options = array();
|
||||
// foreach ($preset['presets'] as $preset_style_name => $effects) {
|
||||
// $options[$preset_style_name] = $preset_style_name;
|
||||
// }
|
||||
//
|
||||
// // Store the container in the 'rel' attribute for later AJAX previews.
|
||||
// $rel = check_plain($style_name);
|
||||
// $form['containers'][$style_name]['preset_' . $style_name] = array(
|
||||
// '#type' => 'radios',
|
||||
// '#title' => t('Style effects preset'),
|
||||
// '#default_value' => $this_preset,
|
||||
// '#options' => $options,
|
||||
// '#attributes' => array('class' => array('styles-ui-preset'), 'rel' => $rel),
|
||||
// );
|
||||
// // Add a preview.
|
||||
// if (isset($styles_containers[$field_type]['themes']) && isset($styles_containers[$field_type]['themes']['preview'])) {
|
||||
// $preview = '<div id="styles-ui-preview-wrapper-' . $rel . '" class="styles-ui-preview-wrapper">' . theme($styles_containers[$field_type]['themes']['preview'], array('field_type' => $field_type, 'container_name' => $style_name, 'style_name' => $this_preset)) . '</div>';
|
||||
// $form['containers'][$style_name]['preview_' . $style_name] = array(
|
||||
// '#type' => 'item',
|
||||
// '#title' => t('Style preview'),
|
||||
// '#markup' => $preview,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// // Add the javascript for live previews on radio select.
|
||||
// $form['#attached'] = array(
|
||||
// 'js' => array(drupal_get_path('module', 'styles_ui') . '/styles_ui.js'),
|
||||
// );
|
||||
// drupal_add_js($settings, array('type' => 'setting'));
|
||||
// return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation handler for the edit style form.
|
||||
*/
|
||||
function styles_ui_style_edit_form_validate($form, $form_state) {
|
||||
$field_type = $form_state['values']['field_type'];
|
||||
$style_name = $form_state['values']['name'];
|
||||
$old_style_name = $form_state['values']['old_style_name'];
|
||||
$styles = styles_default_styles();
|
||||
if (!preg_match('!^[a-z0-9_]+$!', $style_name)) {
|
||||
form_set_error('style_name', t('The machine-readable style name must contain only lowercase letters, numbers, and underscores.'));
|
||||
}
|
||||
else if (($style_name != $old_style_name) && !empty($styles[$field_type]['styles'][$style_name])) {
|
||||
form_set_error('style_name', t('The machine-readable style name %style_name is already taken.', array('%style_name' => $style_name)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submission handler for the add style form.
|
||||
*/
|
||||
function styles_ui_style_edit_form_submit(&$form, &$form_state) {
|
||||
$field_type = $form_state['values']['field_type'];
|
||||
$style_name = $form_state['values']['name'];
|
||||
$style = array(
|
||||
'field_type' => $field_type,
|
||||
'name' => $style_name,
|
||||
'description' => $form_state['values']['description'],
|
||||
);
|
||||
// Save the new style.
|
||||
styles_style_save($style);
|
||||
|
||||
// Get the containers for this field type.
|
||||
$styles = styles_default_presets($field_type);
|
||||
$containers = styles_default_containers($field_type);
|
||||
|
||||
foreach ($form_state['values']['containers'] as $container_name => $container) {
|
||||
if (is_array($container)) {
|
||||
$default_preset = isset($styles['containers'][$container_name]['styles'][$style_name]['default preset']) ? $styles['containers'][$container_name]['styles'][$style_name]['default preset'] : $styles['containers'][$container_name]['default preset'];
|
||||
$delete_only = ($default_preset == $container['preset']);
|
||||
styles_style_save_preset($field_type, $container_name, $style_name, $container['preset'], $delete_only);
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to this style's edit page.
|
||||
$form_state['redirect'] = $containers['admin']['path'] . '/edit/' . $style_name;
|
||||
}
|
||||
|
||||
function styles_ui_preview_ajax($field_type, $container_name, $preset_name) {
|
||||
$styles_containers = styles_default_containers();
|
||||
$containers = $styles_containers[$field_type]['containers'];
|
||||
drupal_json_output(array(
|
||||
'id' => '#styles-ui-preview-wrapper-' . check_plain($container_name),
|
||||
'preview' => theme($containers[$container_name]['themes']['preview'], array('field_type' => $field_type, 'container_name' => $container_name, 'style_name' => $preset_name)),
|
||||
));
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu callback; delete a style.
|
||||
*/
|
||||
function styles_ui_delete_confirm($form, &$form_state, $field_type, $style_name) {
|
||||
$form['field_type'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $field_type,
|
||||
);
|
||||
$form['style_name'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $style_name,
|
||||
);
|
||||
|
||||
$styles = styles_default_styles($field_type);
|
||||
$style = $styles['styles'][$style_name];
|
||||
if ($style['storage'] == STYLES_STORAGE_OVERRIDE) {
|
||||
$delete = 'revert';
|
||||
}
|
||||
else {
|
||||
$delete = 'delete';
|
||||
}
|
||||
|
||||
$caption = '<p>' . t('This action cannot be undone.') . '</p>';
|
||||
|
||||
$containers = styles_default_containers($field_type);
|
||||
$cancel_path = $containers['admin']['path'];
|
||||
$form['containers'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $containers,
|
||||
);
|
||||
|
||||
$message = t('Are you sure you want to @delete the %field_type style %style_name?', array('@delete' => $delete, '%field_type' => $field_type, '%style_name' => $style_name));
|
||||
|
||||
return confirm_form($form, $message, $cancel_path, $caption, t('@delete', array('@delete' => ucfirst($delete))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Process style delete confirm submissions.
|
||||
*/
|
||||
function styles_ui_delete_confirm_submit($form, &$form_state) {
|
||||
$field_type = $form_state['values']['field_type'];
|
||||
$style_name = $form_state['values']['style_name'];
|
||||
$containers = styles_default_containers($field_type);
|
||||
styles_style_delete($field_type, $style_name);
|
||||
// Redirect to this style's edit page.
|
||||
$form_state['redirect'] = $containers['admin']['path'];
|
||||
}
|
14
sites/all/modules/styles/contrib/styles_ui/styles_ui.info
Normal file
14
sites/all/modules/styles/contrib/styles_ui/styles_ui.info
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
name = Styles UI
|
||||
description = Allows administration of the Styles modules.
|
||||
package = Styles
|
||||
core = 7.x
|
||||
files[] = styles_ui.admin.inc
|
||||
dependencies[] = styles
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-06-01
|
||||
version = "7.x-2.0-alpha8"
|
||||
core = "7.x"
|
||||
project = "styles"
|
||||
datestamp = "1306964517"
|
||||
|
44
sites/all/modules/styles/contrib/styles_ui/styles_ui.install
Normal file
44
sites/all/modules/styles/contrib/styles_ui/styles_ui.install
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file styles/contrib/styles_ui/styles_ui.install
|
||||
* Install, update and uninstall functions for the Styles module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement hook_install().
|
||||
*/
|
||||
function styles_ui_install() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_uninstall().
|
||||
*/
|
||||
function styles_ui_uninstall() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild styles.
|
||||
*/
|
||||
function styles_ui_update_7200() {
|
||||
cache_clear_all('styles_', 'cache', TRUE);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change themes.
|
||||
*/
|
||||
function styles_ui_update_7201() {
|
||||
drupal_theme_rebuild();
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change menu.
|
||||
*/
|
||||
function styles_ui_update_7206() {
|
||||
menu_rebuild();
|
||||
return array();
|
||||
}
|
27
sites/all/modules/styles/contrib/styles_ui/styles_ui.js
Normal file
27
sites/all/modules/styles/contrib/styles_ui/styles_ui.js
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* jQuery attachment to Styles UI admin pages.
|
||||
*/
|
||||
(function ($) {
|
||||
|
||||
/**
|
||||
* Change the preview on radio change.
|
||||
*/
|
||||
Drupal.behaviors.stylesUI = {
|
||||
attach: function(context, settings) {
|
||||
$('.styles-ui-preset', context).once('stylesUI', function () {
|
||||
$(this).bind('change', function() {
|
||||
$preset = $(this);
|
||||
if ($preset.val()) {
|
||||
$.getJSON(Drupal.settings.stylesUI.url + '/' + Drupal.settings.stylesUI.fieldType + '/' + $preset.attr('rel') + '/' + $preset.val(), function(data){
|
||||
// @TODO: Check for errors.
|
||||
$(data.id).html(data.preview);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
// end of closure
|
||||
})(jQuery);
|
102
sites/all/modules/styles/contrib/styles_ui/styles_ui.module
Normal file
102
sites/all/modules/styles/contrib/styles_ui/styles_ui.module
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Allows administration of the Styles modules.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function styles_ui_menu() {
|
||||
// Each field type Style may choose to allow the Styles module to manage its
|
||||
// UI. To do so, they'll need to create an 'admin' array in its definition
|
||||
// at hook_styles_containers that will contain the path info:
|
||||
// 'path' => The path to the overview listing page,
|
||||
// 'title' => The title for the overview listing page,
|
||||
// 'description' => The description for the overview listing page,
|
||||
// 'access arguments' => The access arguments for the overview listing page,
|
||||
// 'add' => an optional array with the info for adding a new container:
|
||||
// 'title' => The title to add a new container for this field,
|
||||
// 'description' => The discription to add a new container for this field,
|
||||
$items = array();
|
||||
$styles_containers = styles_default_containers();
|
||||
foreach ($styles_containers as $field_type => $containers) {
|
||||
if (isset($containers['admin']) && isset($containers['admin']['path'])) {
|
||||
$field_info = field_info_field_types($field_type);
|
||||
$field_label = $field_info['label'];
|
||||
$title = $field_label . ' styles';
|
||||
$description = 'Configure ' . $field_label . ' styles.';
|
||||
$access = isset($containers['admin']['access arguments']) ? $containers['admin']['access arguments'] : array('administer styles ui');
|
||||
$items[$containers['admin']['path']] = array(
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'access arguments' => $access,
|
||||
'page callback' => 'styles_ui_containers_overview',
|
||||
'page arguments' => array($field_type),
|
||||
'file' => 'styles_ui.admin.inc',
|
||||
);
|
||||
$items[$containers['admin']['path'] . '/list'] = array(
|
||||
'title' => 'List',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -10,
|
||||
);
|
||||
$title = 'Add ' . $field_label . ' style';
|
||||
$description = '';
|
||||
$items[$containers['admin']['path'] . '/add'] = array(
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('styles_ui_style_add_form', $field_type),
|
||||
'access arguments' => $access,
|
||||
'type' => MENU_LOCAL_ACTION,
|
||||
'file' => 'styles_ui.admin.inc',
|
||||
);
|
||||
$count = substr_count($containers['admin']['path'] . '/edit/%', '/');
|
||||
$items[$containers['admin']['path'] . '/edit/%'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('styles_ui_style_edit_form', $field_type, $count),
|
||||
'access arguments' => $access,
|
||||
'file' => 'styles_ui.admin.inc',
|
||||
);
|
||||
$items[$containers['admin']['path'] . '/delete/%'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('styles_ui_delete_confirm', $field_type, $count),
|
||||
'access arguments' => $access,
|
||||
'file' => 'styles_ui.admin.inc',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$items['styles-ui/preview/%/%/%'] = array(
|
||||
'page callback' => 'styles_ui_preview_ajax',
|
||||
'page arguments' => array(2, 3, 4),
|
||||
'access arguments' => array('access content'),
|
||||
'file' => 'styles_ui.admin.inc',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement Styles module's hook_styles_style_flush().
|
||||
*/
|
||||
function styles_ui_styles_style_flush($style = NULL) {
|
||||
// Rebuild the menu so that we catch any new styles or containers.
|
||||
menu_rebuild();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_permission().
|
||||
*/
|
||||
function styles_ui_permission() {
|
||||
return array(
|
||||
'administer styles ui' => array(
|
||||
'title' => t('Administer Styles'),
|
||||
'description' => t('Configure styles settings.'),
|
||||
),
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user