arteleku_drupal_module/arteleku.module

483 lines
16 KiB
Plaintext
Raw Normal View History

2017-12-15 01:09:28 +01:00
<?php
/**
* Implements hook_ctools_plugin_directory().
*/
function arteleku_ctools_plugin_directory($module, $plugin) {
if ($module == 'panels' && $plugin == 'layouts') {
return 'plugins/layouts';
}
if ($module == 'panels' && $plugin == 'styles') {
return 'plugins/styles';
}
}
/**
* Define information about image effects provided by a module.
*
* This hook enables modules to define image manipulation effects for use with
* an image style.
*
* @return
* An array of image effects. This array is keyed on the machine-readable
* effect name. Each effect is defined as an associative array containing the
* following items:
* - "label": The human-readable name of the effect.
* - "effect callback": The function to call to perform this image effect.
* - "dimensions passthrough": (optional) Set this item if the effect doesn't
* change the dimensions of the image.
* - "dimensions callback": (optional) The function to call to transform
* dimensions for this effect.
* - "help": (optional) A brief description of the effect that will be shown
* when adding or configuring this image effect.
* - "form callback": (optional) The name of a function that will return a
* $form array providing a configuration form for this image effect.
* - "summary theme": (optional) The name of a theme function that will output
* a summary of this image effect's configuration.
*
* @see hook_image_effect_info_alter()
*/
function arteleku_image_effect_info() {
$effects = array();
$effects['arteleku'] = array(
'label' => t('Arteleku'),
'help' => t('Cambia la saturación, el contraste y la opacidad.'),
'dimensions passthrough' => TRUE,
'effect callback' => 'arteleku_special_effect'
);
return $effects;
}
function arteleku_special_effect($image, $data = array()){
return image_toolkit_invoke('arteleku', $image, array($data));
}
function image_gd_arteleku($image, $data = array()){
// imagefilter($image->resource, IMG_FILTER_CONTRAST, 30);
//imagefilter($image->resource, IMG_FILTER_BRIGHTNESS, 75);
imagefilter($image->resource, IMG_FILTER_GRAYSCALE);
return TRUE;
}
function arteleku_views_slideshow_widget_pager_info($view) {
return array(
'arteleku_simple_pager' => array(
'name' => t('Simple counter'),
),
);
}
/**
* Implements hook_theme().
*/
function arteleku_theme($existing, $type, $theme, $path) {
return array(
'arteleku_simple_pager' => array(
'variables' => array('vss_id' => NULL, 'view' => NULL, 'settings' => array(), 'location' => NULL, 'attributes' => array()),
'template' => 'theme/views-slideshow-pager-fields',
'path' => drupal_get_path('module', 'views_slideshow'),
),
);
}
/**
* Template preprocess function for Views Slideshow simple pager.
*/
function template_preprocess_arteleku_simple_pager(&$vars) {
// Call the fields pager preprocess function.
_views_slideshow_preprocess_views_slideshow_pager_fields($vars);
// Override the (empty) rendered field items with our simple pager.
$vars['rendered_field_items'] = '';
foreach ($vars['view']->result as $count => $node) {
$vars['rendered_field_items'] .= theme('views_slideshow_pager_field_item', array('vss_id' => $vars['vss_id'], 'item' => "<span class='pager'> </span>", 'count' => $count, 'location' => $vars['location']));
}
// Clone the pager fields JavaScript object and methods.
drupal_add_js('Drupal.artelekuSimplePager = Drupal.viewsSlideshowPagerFields || {};', 'inline');
drupal_add_css(drupal_get_path('module', 'arteleku') . '/css/slideshow_pager.css');
// var_dump($vars);
}
/**
* Implements hook_block_info().
*/
function arteleku_block_info() {
$blocks = array();
$blocks['historico'] = array(
'info' => t('Histórico de años'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
$blocks['alfabeto'] = array(
'info' => t('Alfabeto'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function arteleku_block_configure($delta='') {
$form = array();
switch($delta) {
case 'historico' :
// Text field form element
$form['inicio'] = array(
'#type' => 'textfield',
'#title' => t('Fecha de inicio del listado histórico'),
'#size' => 60,
'#maxlength' => 128,
'#default_value' => variable_get('arteleku_historico_inicio', '2000'),
);
$form['vista'] = array(
'#type' => 'textfield',
'#title' => t('path de la vista'),
'#size' => 60,
'#maxlength' => 128,
'#default_value' => variable_get('arteleku_historico_vista', 'historico'),
);
break;
}
return $form;
}
/**
* Implements hook_block_save().
*/
function arteleku_block_save($delta = '', $edit = array()) {
switch($delta) {
case 'historico' :
variable_set('arteleku_historico_inicio', $edit['inicio']);
variable_set('arteleku_historico_vista', $edit['vista']);
break;
}
}
/**
* Implements hook_block_view().
*/
function arteleku_block_view($delta='') {
$block = array();
switch($delta) {
case 'historico' :
$block['content'] = _arteleku_historico_view();
break;
case 'alfabeto':
$block['content'] = _arteleku_alfabeto_view();
break;
}
return $block;
}
/**
* Implements hook_field_formatter_info().
*/
function arteleku_field_formatter_info() {
return array(
'arteleku_mime' => array(
'label' => t('Tipo de archivo'),
'field types' => array('file')
),
'arteleku_registration' => array(
'label' => t('Registration Arteleku Type'),
'field types' => array('registration')
),
'arteleku_file_tarjeta' => array(
'label' => t('Tarjeta'),
'field types' => array('file')
),
'arteleku_document' => array(
'label' => t('Link to Document'),
'field types' => array('file')
)
);
}
function arteleku_file_formatter_info(){
$formatters['arteleku_hover_image'] = array(
'label' => t('Hover'),
'file types' => array('video', 'image'),
'default settings' => array(
'image_style_back' => '',
'image_style_front' => ''
),
'view callback' => 'arteleku_hover_image_formatter_image_view',
'settings callback' => 'arteleku_hover_image_formatter_image_settings',
);
return $formatters;
}
function arteleku_hover_image_formatter_image_view($file, $display, $langcode){
$scheme = file_uri_scheme($file->uri);
$tipo = $file->type;
$current_node = arg(1);
$image_style = $display['settings']['image_style_back'];
$image_style_front = $display['settings']['image_style_front'];
$link_to_node = $display['settings']['link_to_reference'];
$valid_image_styles = image_style_options(FALSE);
$referencing_node = $file->referencing_entity->nid;
$nodeurl = '';
if ($referencing_node != $current_node){
$nodeurl = url('node/'. $referencing_node);
//Load the entity
$entity = entity_load('node', array($referencing_node));
//Get the entity type
if($entity){
$ent = $entity[$referencing_node];
$e_type = $ent->type;
$langcode_s = entity_language('node', $ent);
if ($e_type == "enlace"){
//Aquí es donde tenemos que cambiar el enlace del nodo!!!
if (isset($ent->field_enlace[$langcode][0])){
$nodeurl = url($ent->field_enlace[$langcode][0]['url']);
}elseif (isset($ent->field_enlace[$langcode_s][0])) {
$nodeurl = url($ent->field_enlace[$langcode_s][0]['url']);
}
}
}
}
$fondo="";
$frente="";
if($type = 'image'){
$alt = "";
if( isset($file->field_file_image_alt_text['und'][0]['value']) ){
$alt = $file->field_file_image_alt_text['und'][0]['value'];
}
$fondo = theme('image_style', array('path' => $file->uri, 'style_name' => $image_style, 'alt' => $alt));
$frente = theme('image_style', array('path' => $file->uri, 'style_name' => $image_style_front, 'title' => $alt));
}else{
if ($scheme == 'vimeo') {
$wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
$fondo = theme('image_style', array('path' => $wrapper->getLocalThumbnailPath(), 'style_name' => $image_style, 'title' => $file->alt));
$frente = theme('image_style', array('path' => $wrapper->getLocalThumbnailPath(), 'style_name' => $image_style_front, 'title' => $file->alt));
}
}
$marcado = "";
if($fondo != '' && $frente != ""){
$marcado = "<div class='hover-fondo-normal'>$fondo</div><div class='hover-fondo-hover'>";
if($nodeurl != ''){
$marcado .= "<a href='$nodeurl'>$frente</a></div>";
}else{
$marcado .= "$frente</div>";
}
}
$element[] = array(
'#markup' => $marcado
);
return $element;
}
function arteleku_hover_image_formatter_image_settings($form, &$form_state, $settings){
$element = array();
$element['image_style_back'] = array(
'#title' => t('Image style Back'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#default_value' => $settings['image_style_back'],
'#empty_option' => t('None (original image)'),
);
$element['image_style_front'] = array(
'#title' => t('Image style Front'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#default_value' => $settings['image_style_front'],
'#empty_option' => t('None (original image)'),
);
return $element;
}
/**
* Implements hook_field_formatter_view().
*/
function arteleku_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array(); // Initialize the var
switch ($display['type']) {
case 'arteleku_mime':
foreach ($items as $item) {
$mime = ucwords($item['type']);
$element[] = array(
'#markup' => "<div class='mime-info'>$mime</div>"
);
}
break;
case 'arteleku_file_tarjeta':
foreach ($items as $item) {
$mime = file_get_mimetype($item['uri']);
$mime = explode('/',$mime);
$mime = ucwords(array_pop($mime));
$title = field_get_items($entity_type, $entity,'title_field');
$uri = file_create_url($item['uri']);
$link = l($title[0]['value'], $uri);
if ($mime == "Vimeo"){
$uri = entity_uri($entity_type, $entity);
$link = l($title[0]['value'], $uri['path']);
}
$element[] = array(
'#markup' => "<div class='tarjeta'><div class='inside'><div class='field'><h3>$link</h3></div><div class='mini-tarjeta-abajo field'><div class='mime-info'>$mime</div></div></div></div>"
);
}
break;
case 'arteleku_registration';
list($entity_id) = entity_extract_ids($entity_type, $entity);
$settings = registration_entity_settings($entity_type, $entity_id);
//dpm($settings);
/*Fechas:
OPEN: $settings[open];
CLOSE: $settings[close];
*/
// Enable registration link if accessible.
$mostrar = FALSE;
$espacio = registration_has_room($entity_type, $entity_id);
$estado = $settings['status'];
$texto = "";
$registro = FALSE;
if (!$estado){
break;
}
if($settings['close'] && $settings['open']){
$format = "Y-m-d H:i:s";
$open = DateTime::createFromFormat($format, $settings['open']);
$close = DateTime::createFromFormat($format, $settings['close']);
$now = new DateTime();
if(($open <= $now) && ($now<=$close) && $espacio){
$mostrar = TRUE;
$formato = variable_get('date_format_corto_sin_hora', 'm/d/Y');
$desde = $open->format($formato);
$hasta = $close->format($formato);
//$texto = '<p>' . t('Abierta hasta el') . ' <span class="register-date">' . $hasta . '</span></p>';
$texto = '<p>' . t("Open until !fecha", array('!fecha' => '<span class="register-date">' . $hasta . '</span>')) .'</p>';
$registro = TRUE;
}elseif (($open <= $now) && ($now<=$close) && !$espacio){
$texto = '<p>' . t('Full event') . '</p>';
$registro = FALSE;
}else{
$texto = '<p>' . t('Closed') . '</p>';
$registro = FALSE;
}
}
if (registration_register_page_access($entity_type, $entity) && $registro) {
$uri = entity_uri($entity_type, $entity);
$element[0] = array(
'#markup' => $texto . theme('registration_link',
array(
'label' => t('Register'),
'path' => $uri['path'] . '/register',
)
)
);
}elseif($registro && !user_is_logged_in()){
$texto .= '<p>' . t('You need to be logged in for register.') . '</p>';
$current = current_path();
$element[0] = array('#markup' => $texto . l(t('Register'), "user", array( 'query'=>array('current'=>$current), 'html' => TRUE, 'attributes' => array('class'=>'register-link'))));
}elseif (!$registro){
$element[0] = array('#markup' => $texto);
}else{
$texto = '<p>' . t('You are already registered.') . '</p>';
$element[0] = array('#markup' => $texto);
}
break;
case 'arteleku_document':
//var_dump($items);
foreach ($items as $item) {
$uri = file_create_url($item['uri']);
$texto = t('Download');
$element[] = array(
'#markup' => "<a href='$uri'>$texto</a>"
);
}
break;
default:
# code...
break;
}
return $element;
}
function arteleku_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == "registration_entity_settings_form"){
$form['scheduling']['open']['#type'] = 'date_popup';
$form['scheduling']['open']['#date_format'] = 'Y-m-d';
$form['scheduling']['close']['#type'] = 'date_popup';
$form['scheduling']['close']['#date_format'] = 'Y-m-d';
$form['reminder']['reminder_settings']['reminder_date']['#type'] = 'date_popup';
$form['reminder']['reminder_settings']['reminder_date']['#date_format'] = 'Y-m-d';
}elseif ($form_id =="galleria_form_optionset_edit") {
$estilos = file_entity_view_mode_labels();
$form['image_styles']['thumb']['#options'] = $estilos;
$form['image_styles']['normal']['#options'] = $estilos;
$form['image_styles']['big']['#options'] = $estilos;
}
}
/**
* Custom function to assemble renderable array for block content.
* Returns a renderable array with the block content.
* @return
* returns a renderable array of block content.
*/
function _arteleku_historico_view() {
$block = '<ul>';
$actual = arg(1);
$inicio = variable_get('arteleku_historico_inicio', '2000');
$vista = variable_get('arteleku_historico_vista', 'historico');
$years = range(date("Y"), $inicio);
if ($actual != ''){
$actual = intval($actual);
}
foreach ($years as $key => $year) {
if ($year == $actual){
$block .= '<li class="selected-year">' . l($year, $vista . '/' . $year) . '</li>';
}else{
$block .= '<li>' . l($year, $vista . '/' . $year) . '</li>';
}
}
$block .= '</ul>';
return $block;
}
function _arteleku_alfabeto_view() {
$block = '<div class="isotope-options isotope-block"><ul class="isotope-filters option-set clearfix" data-option-key="filter">';
$block .= '<li><a href="#filter" data-option-value="*" class="selected">' . t("Todo") . '</a></li>';
$letters = range('a', 'z');
foreach ($letters as $key => $letter) {
$uc = strtoupper($letter);
$block .= "<li><a class='filterbutton' data-option-value='.$letter' href='#filter'>$uc</a></li>";
}
$block .= '</ul></div>';
return $block;
}