acf_qtranslate_acf_4_image

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

Defined (1)

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

/src/acf_4/fields/image.php  
  1. class acf_qtranslate_acf_4_image extends acf_field_image { 
  2.  
  3. /** 
  4. * The plugin instance. 
  5. * @var \acf_qtranslate\plugin 
  6. */ 
  7. protected $plugin; 
  8.  
  9.  
  10. /** 
  11. * __construct 
  12. * Set name / label needed for actions / filters 
  13. * @since 3.6 
  14. * @date 23/01/13 
  15. */ 
  16. function __construct($plugin) { 
  17. $this->plugin = $plugin; 
  18.  
  19. $this->name = 'qtranslate_image'; 
  20. $this->label = __("Image", 'acf'); 
  21. $this->category = __("qTranslate", 'acf'); 
  22. $this->defaults = array( 
  23. 'save_format' => 'object',  
  24. 'preview_size' => 'thumbnail',  
  25. 'library' => 'all' 
  26. ); 
  27. $this->l10n = array( 
  28. 'select' => __("Select Image", 'acf'),  
  29. 'edit' => __("Edit Image", 'acf'),  
  30. 'update' => __("Update Image", 'acf'),  
  31. 'uploadedTo' => __("uploaded to this post", 'acf'),  
  32. ); 
  33.  
  34. acf_field::__construct(); 
  35.  
  36. // filters 
  37. add_filter('get_media_item_args', array($this, 'get_media_item_args')); 
  38. add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3); 
  39.  
  40. // JSON 
  41. add_action('wp_ajax_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1); 
  42. add_action('wp_ajax_nopriv_acf/fields/image/get_images', array($this, 'ajax_get_images'), 10, 1); 
  43.  
  44. /** 
  45. * create_field() 
  46. * Create the HTML interface for your field 
  47. * @param $field - an array holding all the field's data 
  48. * @type action 
  49. * @since 3.6 
  50. * @date 23/01/13 
  51. */ 
  52. function create_field($field) { 
  53. global $q_config; 
  54. $languages = qtrans_getSortedLanguages(true); 
  55. $values = qtrans_split($field['value'], $quicktags = true); 
  56. $currentLanguage = $this->plugin->get_active_language(); 
  57.  
  58. echo '<div class="multi-language-field multi-language-field-image">'; 
  59.  
  60. foreach ($languages as $language) { 
  61. $class = 'wp-switch-editor'; 
  62. if ($language === $currentLanguage) { 
  63. $class .= ' current-language'; 
  64. echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; 
  65.  
  66. $base_class = $field['class']; 
  67. $base_name = $field['name']; 
  68. foreach ($languages as $language) : 
  69. $value = $values[$language]; 
  70. $o = array( 
  71. 'class' => '',  
  72. 'url' => '',  
  73. ); 
  74.  
  75. if ($value && is_numeric($value)) { 
  76. $url = wp_get_attachment_image_src($value, $field['preview_size']); 
  77. $o['class'] = 'active'; 
  78. $o['url'] = $url[0]; 
  79.  
  80. $field['class'] = $base_class; 
  81. if ($language === $currentLanguage) { 
  82. $field['class'] .= ' current-language'; 
  83. $o['class'] .= ' current-language'; 
  84.  
  85. $field['name'] = $base_name . '[' . $language . ']'; 
  86.  
  87. ?> 
  88. <div class="acf-image-uploader clearfix <?php echo $o['class']; ?>" data-preview_size="<?php echo $field['preview_size']; ?>" data-library="<?php echo $field['library']; ?>" data-language="<?php echo $language; ?>" > 
  89. <input class="acf-image-value" type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo $value; ?>" /> 
  90. <div class="has-image"> 
  91. <div class="hover"> 
  92. <ul class="bl"> 
  93. <li><a class="acf-button-delete ir" href="#"><?php _e("Remove", 'acf'); ?></a></li> 
  94. <li><a class="acf-button-edit ir" href="#"><?php _e("Edit", 'acf'); ?></a></li> 
  95. </ul> 
  96. </div> 
  97. <img class="acf-image-image" src="<?php echo $o['url']; ?>" alt="" /> 
  98. </div> 
  99. <div class="no-image"> 
  100. <p><?php _e('No image selected', 'acf'); ?> <input type="button" class="button add-image" value="<?php _e('Add Image', 'acf'); ?>" /> 
  101. </div> 
  102. </div> 
  103. <?php endforeach; 
  104.  
  105. echo '</div>'; 
  106.  
  107. /** 
  108. * format_value 
  109. * @description: uses the basic value and allows the field type to format it 
  110. * @since: 3.6 
  111. * @created: 26/01/13 
  112. */ 
  113. function format_value($value, $post_id, $field) { 
  114. return $value; 
  115.  
  116. /** 
  117. * format_value_for_api() 
  118. * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field 
  119. * @type filter 
  120. * @since 3.6 
  121. * @date 23/01/13 
  122. * @param $value - the value which was loaded from the database 
  123. * @param $post_id - the $post_id from which the value was loaded 
  124. * @param $field - the field array holding all the field options 
  125. * @return $value - the modified value 
  126. */ 
  127. function format_value_for_api($value, $post_id, $field) { 
  128. $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value); 
  129. return parent::format_value_for_api($value, $post_id, $field); 
  130.  
  131. /** 
  132. * update_value() 
  133. * This filter is appied to the $value before it is updated in the db 
  134. * @type filter 
  135. * @since 3.6 
  136. * @date 23/01/13 
  137. * @param $value - the value which will be saved in the database 
  138. * @param $post_id - the $post_id of which the value will be saved 
  139. * @param $field - the field array holding all the field options 
  140. * @return $value - the modified value 
  141. */ 
  142. function update_value($value, $post_id, $field) { 
  143. return qtrans_join($value); 
  144.