acf_qtranslate_acf_4_file

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

Defined (1)

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

/src/acf_4/fields/file.php  
  1. class acf_qtranslate_acf_4_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. * 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_file'; 
  20. $this->label = __("File", 'acf'); 
  21. $this->category = __("qTranslate", 'acf'); 
  22. $this->defaults = array( 
  23. 'save_format' => 'object',  
  24. 'library' => 'all' 
  25. ); 
  26. $this->l10n = array( 
  27. 'select' => __("Select File", 'acf'),  
  28. 'edit' => __("Edit File", 'acf'),  
  29. 'update' => __("Update File", 'acf'),  
  30. 'uploadedTo' => __("uploaded to this post", 'acf'),  
  31. ); 
  32.  
  33. acf_field::__construct(); 
  34.  
  35. // filters 
  36. add_filter('get_media_item_args', array($this, 'get_media_item_args')); 
  37. add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3); 
  38.  
  39.  
  40. // JSON 
  41. add_action('wp_ajax_acf/fields/file/get_files', array($this, 'ajax_get_files')); 
  42. add_action('wp_ajax_nopriv_acf/fields/file/get_files', array($this, 'ajax_get_files'), 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-file">'; 
  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. 'icon' => '',  
  73. 'title' => '',  
  74. 'size' => '',  
  75. 'url' => '',  
  76. 'name' => '',  
  77. ); 
  78.  
  79. if($value && is_numeric($value)) { 
  80. $file = get_post($value); 
  81.  
  82. if($file) { 
  83. $o['class'] = 'active'; 
  84. $o['icon'] = wp_mime_type_icon( $file->ID ); 
  85. $o['title'] = $file->post_title; 
  86. $o['size'] = size_format(filesize( get_attached_file( $file->ID ) )); 
  87. $o['url'] = wp_get_attachment_url( $file->ID ); 
  88.  
  89. $explode = explode('/', $o['url']); 
  90. $o['name'] = end( $explode ); 
  91.  
  92. $field['class'] = $base_class; 
  93. if ($language === $currentLanguage) { 
  94. $field['class'] .= ' current-language'; 
  95. $o['class'] .= ' current-language'; 
  96.  
  97. $field['name'] = $base_name . '[' . $language . ']'; 
  98.  
  99. ?> 
  100. <div class="acf-file-uploader clearfix <?php echo $o['class']; ?>" data-library="<?php echo $field['library']; ?>" data-language="<?php echo $language; ?>"> 
  101. <input class="acf-file-value" type="hidden" name="<?php echo $field['name']; ?>" value="<?php echo $value; ?>" /> 
  102. <div class="has-file"> 
  103. <ul class="hl clearfix"> 
  104. <li> 
  105. <img class="acf-file-icon" src="<?php echo $o['icon']; ?>" alt=""/> 
  106. <div class="hover"> 
  107. <ul class="bl"> 
  108. <li><a href="#" class="acf-button-delete ir">Remove</a></li> 
  109. <li><a href="#" class="acf-button-edit ir">Edit</a></li> 
  110. </ul> 
  111. </div> 
  112. </li> 
  113. <li> 
  114. <p> 
  115. <strong class="acf-file-title"><?php echo $o['title']; ?></strong> 
  116. </p> 
  117. <p> 
  118. <strong><?php _e('Name', 'acf'); ?>:</strong> 
  119. <a class="acf-file-name" href="<?php echo $o['url']; ?>" target="_blank"><?php echo $o['name']; ?></a> 
  120. </p> 
  121. <p> 
  122. <strong><?php _e('Size', 'acf'); ?>:</strong> 
  123. <span class="acf-file-size"><?php echo $o['size']; ?></span> 
  124. </p> 
  125.  
  126. </li> 
  127. </ul> 
  128. </div> 
  129. <div class="no-file"> 
  130. <ul class="hl clearfix"> 
  131. <li> 
  132. <p><?php _e('No File Selected', 'acf'); ?> <a href="#" class="button add-file"><?php _e('Add File', 'acf'); ?></p></a> 
  133. </li> 
  134. </ul> 
  135. </div> 
  136. </div> 
  137. <?php endforeach; 
  138.  
  139. echo '</div>'; 
  140.  
  141. /** 
  142. * format_value 
  143. * @description: uses the basic value and allows the field type to format it 
  144. * @since: 3.6 
  145. * @created: 26/01/13 
  146. */ 
  147. function format_value($value, $post_id, $field) { 
  148. return $value; 
  149.  
  150. /** 
  151. * format_value_for_api() 
  152. * 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 
  153. * @type filter 
  154. * @since 3.6 
  155. * @date 23/01/13 
  156. * @param $value - the value which was loaded from the database 
  157. * @param $post_id - the $post_id from which the value was loaded 
  158. * @param $field - the field array holding all the field options 
  159. * @return $value - the modified value 
  160. */ 
  161. function format_value_for_api($value, $post_id, $field) { 
  162. $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value); 
  163. return parent::format_value_for_api($value, $post_id, $field); 
  164.  
  165. /** 
  166. * update_value() 
  167. * This filter is appied to the $value before it is updated in the db 
  168. * @type filter 
  169. * @since 3.6 
  170. * @date 23/01/13 
  171. * @param $value - the value which will be saved in the database 
  172. * @param $post_id - the $post_id of which the value will be saved 
  173. * @param $field - the field array holding all the field options 
  174. * @return $value - the modified value 
  175. */ 
  176. function update_value($value, $post_id, $field) { 
  177. return qtrans_join($value); 
  178.