first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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'];
}
}

View 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);
}