acf_qtranslate_acf_5_image

The Advanced Custom Fields: qTranslate acf qtranslate 5 image class.

Defined (1)

The class is defined in the following location(s).

/src/acf_5/fields/image.php  
  1. class acf_qtranslate_acf_5_image extends acf_field_image { 
  2.  
  3. /** 
  4. * The plugin instance. 
  5. * @var \acf_qtranslate_plugin 
  6. */ 
  7. protected $plugin; 
  8.  
  9. /** 
  10. * __construct 
  11. * This function will setup the field type data 
  12. * @type function 
  13. * @date 5/03/2014 
  14. * @since 5.0.0 
  15. * @param n/a 
  16. * @return n/a 
  17. */ 
  18. function __construct($plugin) { 
  19. $this->plugin = $plugin; 
  20.  
  21. $this->name = 'qtranslate_image'; 
  22. $this->label = __("Image", 'acf'); 
  23. $this->category = __("qTranslate", 'acf'); 
  24. $this->defaults = array( 
  25. 'return_format' => 'array',  
  26. 'preview_size' => 'thumbnail',  
  27. 'library' => 'all',  
  28. 'min_width' => 0,  
  29. 'min_height' => 0,  
  30. 'min_size' => 0,  
  31. 'max_width' => 0,  
  32. 'max_height' => 0,  
  33. 'max_size' => 0,  
  34. 'mime_types' => '' 
  35. ); 
  36. $this->l10n = array( 
  37. 'select' => __("Select Image", 'acf'),  
  38. 'edit' => __("Edit Image", 'acf'),  
  39. 'update' => __("Update Image", 'acf'),  
  40. 'uploadedTo' => __("Uploaded to this post", 'acf'),  
  41. 'all' => __("All images", 'acf'),  
  42. ); 
  43.  
  44.  
  45. // filters 
  46. add_filter('get_media_item_args', array($this, 'get_media_item_args')); 
  47. add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3); 
  48.  
  49. acf_field::__construct(); 
  50.  
  51. /** 
  52. * render_field() 
  53. * Create the HTML interface for your field 
  54. * @param $field - an array holding all the field's data 
  55. * @type action 
  56. * @since 3.6 
  57. * @date 23/01/13 
  58. */ 
  59. function render_field($field) { 
  60. global $q_config; 
  61. $languages = qtrans_getSortedLanguages(true); 
  62. $values = qtrans_split($field['value'], $quicktags = true); 
  63. $currentLanguage = $this->plugin->get_active_language(); 
  64.  
  65. // enqueue 
  66. acf_enqueue_uploader(); 
  67.  
  68. // vars 
  69. $div = array( 
  70. 'class' => 'acf-image-uploader acf-cf',  
  71. 'data-preview_size' => $field['preview_size'],  
  72. 'data-library' => $field['library'],  
  73. 'data-mime_types' => $field['mime_types'] 
  74. ); 
  75.  
  76. $input_atts = array( 
  77. 'type' => 'hidden',  
  78. 'name' => $field['name'],  
  79. 'value' => $field['value'],  
  80. 'data-name' => 'value-id' 
  81. ); 
  82.  
  83. $url = ''; 
  84.  
  85. echo '<div class="multi-language-field multi-language-field-image">'; 
  86.  
  87. foreach ($languages as $language) { 
  88. $class = 'wp-switch-editor'; 
  89. if ($language === $currentLanguage) { 
  90. $class .= ' current-language'; 
  91. echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; 
  92.  
  93. foreach ($languages as $language): 
  94.  
  95. $input_atts['name'] = $field['name'] . '[' . $language . ']'; 
  96. $field['value'] = $values[$language]; 
  97. $div['data-language'] = $language; 
  98. $div['class'] = 'acf-image-uploader acf-cf'; 
  99.  
  100. // has value? 
  101. if( $field['value'] && is_numeric($field['value']) ) { 
  102. $url = wp_get_attachment_image_src($field['value'], $field['preview_size']); 
  103. $url = $url[0]; 
  104.  
  105. $div['class'] .= ' has-value'; 
  106.  
  107. // basic? 
  108. $basic = !current_user_can('upload_files'); 
  109. if ($basic) { 
  110. $div['class'] .= ' basic'; 
  111.  
  112. if ($language === $currentLanguage) { 
  113. $div['class'] .= ' current-language'; 
  114.  
  115. ?> 
  116. <div <?php acf_esc_attr_e( $div ); ?>> 
  117. <div class="acf-hidden"> 
  118. <?php acf_hidden_input(array( 'name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id' )); ?> 
  119. </div> 
  120. <div class="view show-if-value acf-soh"> 
  121. <img data-name="image" src="<?php echo $url; ?>" alt=""/> 
  122. <ul class="acf-hl acf-soh-target"> 
  123. <?php if( !$basic ): ?> 
  124. <li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li> 
  125. <?php endif; ?> 
  126. <li><a class="acf-icon dark" data-name="remove" href="#"><i class="acf-sprite-delete"></i></a></li> 
  127. </ul> 
  128. </div> 
  129. <div class="view hide-if-value"> 
  130. <?php if( $basic ): ?> 
  131. <?php if( $field['value'] && !is_numeric($field['value']) ): ?> 
  132. <div class="acf-error-message"><p><?php echo $field['value']; ?></p></div> 
  133. <?php endif; ?> 
  134. <input type="file" name="<?php echo $field['name']; ?>" id="<?php echo $field['id']; ?>" /> 
  135. <?php else: ?> 
  136. <p style="margin:0;"><?php _e('No image selected', 'acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add Image', 'acf'); ?></a></p> 
  137. <?php endif; ?> 
  138. </div> 
  139. </div> 
  140.  
  141. <?php endforeach; 
  142.  
  143. echo '</div>'; 
  144.  
  145. /** 
  146. * update_value() 
  147. * This filter is appied to the $value before it is updated in the db 
  148. * @type filter 
  149. * @since 3.6 
  150. * @date 23/01/13 
  151. * @param $value - the value which will be saved in the database 
  152. * @param $post_id - the $post_id of which the value will be saved 
  153. * @param $field - the field array holding all the field options 
  154. * @return $value - the modified value 
  155. */ 
  156. function update_value($value, $post_id, $field) { 
  157. $value = parent::update_value($value, $post_id, $field); 
  158. return qtrans_join($value); 
  159.