acf_qtranslate_acf_5_file

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

Defined (1)

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

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