open videos on popup overlay

This commit is contained in:
2017-02-07 10:34:00 +01:00
parent cc959e62bc
commit 81f67414c8
187 changed files with 17025 additions and 28 deletions
@@ -0,0 +1,145 @@
README
------
README for the custom actions effect module.
Dependencies
------------
Hard dependencies:
- Imagecache actions.
- Image (Drupal core).
Soft dependencies/recommended modules:
- Imagemagick (preferred toolkit).
- PHP filter (Drupal core).
Which toolkit?
--------------
Personally, I prefer the imagemagick toolkit:
- It is better in anti-aliasing, try to rotate an image using both toolkits and
you will see what I mean.
- It does not execute in the PHP memory space, so is not restricted by the
memory_limit PHP setting.
- The GD toolkit will, at least on my Windows configuration, keep font files
open after a text operation, so you cannot delete, move or rename it anymore.
Installing
----------
As usual. After enabling the module you can add custom actions to images.
Custom action PHP snippets
--------------------------
Given the correct permission, the custom action effect allows you to write your
own PHP snippet that does the requested processing on the image. How it can do
so, depends on the toolkit.
For all toolkits, the snippet should return true to indicate success and false
to indicate failure.
GD
--
The GD image resource is available in $image->resource. You can call the GD
functions on this resource. This effect will query the width and height after
your processing, so you don't have to change that yourself.
Imagemagick
-----------
All real image processing is done at the end, if all effects have added their
command line arguments to the $image->ops array. So your custom action should
add the imagemagick commands and its parameters by adding new string entries to
the end of that array.
If your commands change the width or height of the resulting image, you should
record so by changing $image->info['width'] and/or $image->info['height'].
General
-------
To ease your task, this effect makes some information regarding the image being
processed available in 2 variables: $image and $image_context. These variables
are readily available in your snippet.
$image is an object containing the following properties:
- source: string, the source of the image, e.g. public://photo.jpg
- info: array, example data:
- width (int) 180
- height (int) 180
- extension (string) png
- mime_type (string) image/png
- file_size (int) 4417
- toolkit: string, imagemagick or GD
- resource: resource. The GD image resource.
- ops: array. An array of strings with the ImageMagick commands.
$image_context is an associative array containing:
- effect_data: array, the data of this image effect, example data for the custom
action effect:
- php (string)
- managed_file: object|null. A managed file object containing these properties:
- fid (string) 2
- uid (string) 1
- filename (string) photo.jpg
- uri (string) public://photo.jpg
- filemime (string) image/jpeg
- filesize (string) 445751
- status (string) 1
- timestamp (string) 1327525851
- metatags Array [0]
- rdf_mapping Array [0]
- referring_entities: array|null. A nested array with (fully loaded) entities
referring to the current image. The 1st level of entries is keyed by the field
name, the 2nd by entity type, and the 3rd by entity id. Example data:
- field_photo Array [1]
- node Array [1]
- 12 Object of: stdClass
- nid (string) 12
- vid (string) 12
- type (string) page
- author ...
- timestamp ...
- ...
- entity: object|null, the 1st entity in referring_entities. This is for easy
access to the referring entity if it may be assumed that only 1 entity is
referring to the current image.
- image_field: array|null, the 1st image field in entity that is referring to
the current image. This is for easy access to the image field data if it may
be assumed that only 1 image field is referring to the current image. Example
data:
- fid (int) 2
- alt (string) ...
- title (string) ...
- ...
Of course there are many other possible useful globals. Think of:
- base_url
- base_path
- base_root
- is_https
- user
- language
and of course $_SERVER and $_GET.
Using these information you can access entity data as follows:
Specific case (1 entity, of known entity_type, referring to the image):
<?php
$entity_type = 'node';
$field_name = 'my_field';
$entity = $image_context['entity'];
$field = field_get_items($entity_type, $entity, $field_name);
?>
Or the more general case (not knowing the referring type, or multiple entities
that may be referring to the image):
<?php
$referring_entities = $image_context['referring_entities'];
foreach ($referring_entities as $field_name => $field_referring_entities) {
foreach ($field_referring_entities as $entity_type => $entities) {
foreach ($entities as $entity_id => $entity) {
$field = field_get_items($entity_type, $entity, $field_name);
}
}
}
?>
@@ -0,0 +1,14 @@
name = Imagecache Custom Actions
description = Provides the custom and subroutine image effects.
package = Media
core = 7.x
dependencies[] = imagecache_actions
dependencies[] = image
; Information added by Drupal.org packaging script on 2016-02-19
version = "7.x-1.7"
core = "7.x"
project = "imagecache_actions"
datestamp = "1455872655"
@@ -0,0 +1,23 @@
<?php
/**
* Rename 'text' to 'php' in custom action effect data.
*/
function imagecache_customactions_update_7100(/*&$sandbox*/) {
$effects = db_select('image_effects')
->fields('image_effects')
->condition('name', 'imagecache_customactions', '=')
->execute()
->fetchAll();
foreach ($effects as $effect) {
$data = unserialize($effect->data);
if (array_key_exists('text', $data)) {
$data['php'] = $data['text'];
unset($data['text']);
$data = serialize($data);
db_update('image_effects')
->condition('ieid', $effect->ieid)
->fields(array('data' => $data))
->execute();
}
}
}
@@ -0,0 +1,290 @@
<?php
/**
* @file Allows advanced users to code their own PHP image manipulation routines
* as part of image style processing.
*
* @author Originally contributed by crea https://drupal.org/node/325103#comment-
* 1076011
*
* @author merged into imagecache_actions by dman http://coders.co.nz
*
* custom action effect:
* @todo: add description field that editors can use to define their own summary?
* @todo: add form field asking if dimensions stay the same (or if the new dimensions are known).
* subroutine effect:
* @todo: use isid to allow for image style renaming, but also use name to allow export and import (features)
*/
/**
* Implements hook_image_effect_info().
*
* Defines information about the supported effects.
*/
function imagecache_customactions_image_effect_info() {
$effects = array();
$effects['imagecache_customactions'] = array(
'label' => t('Custom action'),
'help' => t('Runs custom PHP code.'),
'effect callback' => 'imagecache_customactions_effect',
'dimensions callback' => 'imagecache_customactions_dimensions',
'form callback' => 'imagecache_customactions_form',
'summary theme' => 'imagecache_customactions_summary',
);
$effects['imagecache_subroutine'] = array(
'label' => t('Subroutine'),
'help' => t('Runs another defined preset on the image.'),
'effect callback' => 'imagecache_subroutine_effect',
'dimensions callback' => 'imagecache_subroutine_dimensions',
'form callback' => 'imagecache_subroutine_form',
'summary theme' => 'imagecache_subroutine_summary',
);
return $effects;
}
/**
* Implements hook_theme().
*
* Registers theme functions for the effect summaries.
*/
function imagecache_customactions_theme() {
return array(
'imagecache_customactions_summary' => array(
'variables' => array('data' => NULL),
),
'imagecache_subroutine_summary' => array(
'variables' => array('data' => NULL),
),
);
}
/**
* Implements hook_image_style_flush().
*
* This hook checks if the image style that is being flushed is used in a
* subroutine effect. If so, the style that contains the subroutine effect
* should be flushed as well.
*
* This may lead to recursive calls to image_style_flush() and thus to this
* hook. Without loops in styles that call each other as subroutine, this
* recursion will always end.
*
* @param array $flushed_style
* The image style that is being flushed.
*/
function imagecache_customactions_image_style_flush(/*array*/ $flushed_style) {
$styles = image_styles();
foreach ($styles as $style) {
if ($style['name'] !== $flushed_style['name']) {
foreach ($style['effects'] as $effect) {
if ($effect['name'] === 'imagecache_subroutine') {
if (isset($effect['data']['subroutine_presetname']) && $effect['data']['subroutine_presetname'] === $flushed_style['name']) {
image_style_flush($style);
}
}
}
}
}
}
/**
* Image effect form callback for the custom action effect.
*
* Note that this is not a complete form, it only contains the portion of the
* form for configuring the effect options. Therefore it does not not need to
* include metadata about the effect, nor a submit button.
*
* @param array $data
* The current configuration for this image effect.
*
* @return array
* The form definition for this effect.
*/
function imagecache_customactions_form(array $data) {
// Add defaults.
$data += array('php' => 'return TRUE;');
// Note: we also need to check for the existence of the module: admin has
// all rights, so user_acccess(...) returns TRUE even if the module is not
// enabled and the permission does not exist.
$allow_php = module_exists('php') && user_access('use PHP for settings');
$form = array(
'php' => array(
'#type' => 'textarea',
'#rows' => 12,
'#title' => t('PHP code'),
'#default_value' => $data['php'],
'#disabled' => !$allow_php,
'#description' => t("<p>A piece of PHP code that modifies the image.
It should return a boolean indicating success or failure.
You will need the '%use_php' permission, defined by the 'PHP filter' module.
See the help for an extensive explanation of the possibilities.</p>",
array('%use_php' => t('Use PHP for settings'))),
'#wysiwyg' => FALSE,
),
);
return $form;
}
/**
* Implements theme_hook() for the custom action effect summary.
*
* param array $variables
* An associative array containing:
* - data: The current configuration for this image effect.
*
* @return string
* The HTML for the summary of this image effect.
* @ingroup themeable
*/
function theme_imagecache_customactions_summary(/*array $variables*/) {
return 'Custom PHP code';
}
/**
* Image effect callback for the custom action effect.
*
* @param stdClass $image
* @param array $data
*
* @return boolean
* true on success, false otherwise.
*/
function imagecache_customactions_effect(stdClass $image, array $data) {
// Check that the PHP filter module is enabled.
$result = module_exists('php');
if ($result) {
// Get context about the image.
module_load_include('inc', 'imagecache_actions', 'utility');
$GLOBALS['image_context'] = imagecache_actions_get_image_context($image, $data);
$GLOBALS['image'] = $image;
$result = php_eval('<' . '?php global $image, $image_context; ' . $data['php'] . ' ?' . '>');
// php_eval returns '1' if the snippet returns true.
$result = $result === '1';
unset($GLOBALS['image']);
unset($GLOBALS['image_context']);
}
if ($result && $image->toolkit == 'GD') {
$image->info['width'] = imagesx($image->resource);
$image->info['height'] = imagesy($image->resource);
}
return $result;
}
/**
* Image dimensions callback for the custom action effect.
*
* @param array $dimensions
* Dimensions to be modified - an associative array containing the items
* 'width' and 'height' (in pixels).
* param array $data
* An associative array containing the effect data.
*/
function imagecache_customactions_dimensions(array &$dimensions/*, array $data*/) {
$dimensions['width'] = NULL;
$dimensions['height'] = NULL;
}
/**
* Subroutine - an imagecache action that just calls another one.
*
* Contributed by Alan D
* https://drupal.org/node/618784
*
* Reworked into customactions by dman 2010-07
*/
/**
* Image effect form callback for the subroutine effect.
*
* @param array $data
* The current configuration for this image effect.
*
* @return array
* The form definition for this effect.
*/
function imagecache_subroutine_form(array $data) {
// Add defaults.
$data += array('subroutine_presetname' => '');
// List available image styles.
// The PASS_THROUGH parameter is new as of D7.23, and is added here to prevent
// image_style_options() from double-encoding the human-readable image style
// name, since the form API will already sanitize options in a select list.
$styles = image_style_options(TRUE, PASS_THROUGH);
//@todo: unset the current style to prevent obvious recursion.
$form = array();
$form['subroutine_presetname'] = array(
'#type' => 'select',
'#title' => t('Image style to call'),
'#default_value' => $data['subroutine_presetname'],
'#options' => $styles,
'#required' => TRUE,
);
return $form;
}
/**
* Implements theme_hook() for the subroutine effect summary.
*
* @param array $variables
* An associative array containing:
* - data: The current configuration for this image effect.
*
* @return string
* The HTML for the summary of this image effect.
* @ingroup themeable
*/
function theme_imagecache_subroutine_summary(array $variables) {
$data = $variables['data'];
module_load_include('inc', 'imagecache_actions', 'utility');
$label = imagecache_actions_get_style_label($data['subroutine_presetname']);
return t('Apply image style %label', array('%label' => $label));
}
/**
* Image effect callback for the subroutine effect.
*
* @param stdClass $image
* @param array $data
*
* @return boolean
* true on success, false otherwise.
*/
function imagecache_subroutine_effect(stdClass $image, array $data) {
$result = FALSE;
if ($style = image_style_load($data['subroutine_presetname'])) {
$result = TRUE;
foreach ($style['effects'] as $effect) {
$result = $result && image_effect_apply($image, $effect);
}
}
return $result;
}
/**
* Image dimensions callback for the subroutine effect.
*
* @param array $dimensions
* Dimensions to be modified - an array with components width and height, in
* pixels.
* @param array $data
* An array with the effect options.
*/
function imagecache_subroutine_dimensions(array &$dimensions, array $data) {
// Let the subroutine transform the dimensions.
image_style_transform_dimensions($data['subroutine_presetname'], $dimensions);
}