├── acf-vimeo.php ├── README.md ├── lang └── acf-vimeo.pot ├── acf-vimeo-funcs.php ├── acf-vimeo-v4.php └── acf-vimeo-v5.php /acf-vimeo.php: -------------------------------------------------------------------------------- 1 | \n" 13 | "Language-Team: LANGUAGE \n" 14 | 15 | #: acf-vimeo-v4.php:10 acf-vimeo-v5.php:8 16 | msgid "Vimeo Video" 17 | msgstr "" 18 | 19 | #: acf-vimeo-v4.php:11 20 | msgid "Basic" 21 | msgstr "" 22 | 23 | #: acf-vimeo-v4.php:32 acf-vimeo-v5.php:37 24 | msgid "Return Value" 25 | msgstr "" 26 | 27 | #: acf-vimeo-v4.php:33 acf-vimeo-v5.php:38 28 | msgid "Type of data returned when using the_field()" 29 | msgstr "" 30 | 31 | #: acf-vimeo-v4.php:43 acf-vimeo-v5.php:46 32 | msgid "Vimeo ID" 33 | msgstr "" 34 | 35 | #: acf-vimeo-v4.php:44 acf-vimeo-v5.php:47 36 | msgid "Embed" 37 | msgstr "" 38 | 39 | #: acf-vimeo-v4.php:45 acf-vimeo-v5.php:48 40 | msgid "Video Object" 41 | msgstr "" 42 | 43 | #: acf-vimeo-v4.php:46 acf-vimeo-v5.php:49 44 | msgid "Thumbnail Object" 45 | msgstr "" 46 | #. Plugin Name of the plugin/theme 47 | msgid "Advanced Custom Fields: Vimeo Field" 48 | msgstr "" 49 | 50 | #. Plugin URI of the plugin/theme 51 | msgid "http://halgatewood.com/downloads/acf-vimeo-field" 52 | msgstr "" 53 | 54 | #. Description of the plugin/theme 55 | msgid "This premium Add-on adds a vimeo field type for the Advanced Custom Fields plugin" 56 | msgstr "" 57 | 58 | #. Author of the plugin/theme 59 | msgid "Hal Gatewood" 60 | msgstr "" 61 | 62 | #. Author URI of the plugin/theme 63 | msgid "http://halgatewood.com" 64 | msgstr "" 65 | -------------------------------------------------------------------------------- /acf-vimeo-funcs.php: -------------------------------------------------------------------------------- 1 | length = acf_vimeo_seconds_to_duration( $video->duration ); 79 | } 80 | } 81 | 82 | // DEFAULTS 83 | $video->data_source = "acf"; 84 | $video->vimeo_id = $vimeo_id; 85 | 86 | return $video; 87 | } 88 | 89 | 90 | // CONVERTS SECONDS TO UNIX TIME 91 | function acf_vimeo_seconds_to_time($time) 92 | { 93 | if(is_numeric($time)) 94 | { 95 | $value = array("years" => 0,"days" => 0,"hours" => 0,"minutes" => 0,"seconds" => 0); 96 | if($time >= 31556926){ $value["years"] = floor($time/31556926); $time = ($time%31556926); } 97 | if($time >= 86400){ $value["days"] = floor($time/86400); $time = ($time%86400); } 98 | if($time >= 3600){ $value["hours"] = floor($time/3600); $time = ($time%3600); } 99 | if($time >= 60){ $value["minutes"] = floor($time/60); $time = ($time%60); } 100 | $value["seconds"] = floor($time); 101 | return (array) $value; 102 | } 103 | else 104 | { 105 | return (bool) FALSE; 106 | } 107 | } 108 | 109 | 110 | // CONVERTS SECONDS TO A NICELY FORMATED TIME LIKE 12:34:56 111 | function acf_vimeo_seconds_to_duration($seconds) 112 | { 113 | $length_array = acf_vimeo_seconds_to_time($seconds); 114 | 115 | $length = ""; 116 | if($length_array['hours'] != "") { $length = $length_array['hours'] . ":"; } 117 | if($length_array['minutes'] < 1) $length_array['minutes'] = "0"; 118 | $length .= $length_array['minutes'] . ":"; 119 | if($length_array['seconds'] < 10) { $length_array['seconds'] = "0" . $length_array['seconds']; } 120 | $length .= $length_array['seconds']; 121 | 122 | return $length; 123 | } -------------------------------------------------------------------------------- /acf-vimeo-v4.php: -------------------------------------------------------------------------------- 1 | name = 'vimeo'; 10 | $this->label = __('Vimeo Video', 'acf-vimeo'); 11 | $this->category = apply_filters( 'acf_vimeo_category', __("Basic",'acf') ); 12 | $this->transient_time = ACF_VIMEO_TRANSIENT_TIME; 13 | $this->reg_ex = ACF_VIMEO_REG_EX; 14 | $this->defaults = array( 'return_format' => 'embed' ); 15 | 16 | parent::__construct(); // do not delete! 17 | 18 | $this->settings = array( 19 | 'path' => apply_filters('acf/helpers/get_path', __FILE__), 20 | 'dir' => apply_filters('acf/helpers/get_dir', __FILE__), 21 | 'version' => '1.0.0' 22 | ); 23 | 24 | } 25 | 26 | function create_options( $field ) 27 | { 28 | $key = $field['name']; 29 | ?> 30 | 31 | 32 | 33 |

34 | 35 | 36 | 'radio', 39 | 'name' => 'fields['.$key.'][return_format]', 40 | 'value' => $field['return_format'], 41 | 'layout' => 'horizontal', 42 | 'choices' => array( 43 | 'id' => __("Vimeo ID",'acf-vimeo'), 44 | 'embed' => __("Embed",'acf-vimeo'), 45 | 'object' => __("Video Object",'acf-vimeo'), 46 | 'thumbnail-object' => __("Thumbnail Object",'acf-vimeo') 47 | ) 48 | )); 49 | ?> 50 | 51 | 52 | '; 62 | $e .= ''; 73 | 74 | if( $field['value'] ) 75 | { 76 | $current_vimeo_id = acf_vimeo_parse_vimeo_id( $field['value'] ); 77 | if($current_vimeo_id) 78 | { 79 | $e .= ''; 80 | } 81 | } 82 | 83 | $e .= ''; 84 | 85 | $e .= " 86 | 87 | 134 | 135 | "; 136 | 137 | echo $e; 138 | } 139 | 140 | function format_value_for_api( $value, $post_id, $field ) 141 | { 142 | $vimeo_id = acf_vimeo_parse_vimeo_id( $value ); 143 | 144 | 145 | // IF NO VIDEO ID RETURN NOTHING 146 | if( !$vimeo_id ) { return false; } 147 | 148 | 149 | // RETURN EMBED 150 | if( $field['return_format'] == "embed" ) 151 | { 152 | return apply_filters('acf_vimeo_embed', '', $vimeo_id); 153 | } 154 | 155 | 156 | // RETURN THUMBNAIL 157 | if( $field['return_format'] == "thumbnail-object" ) 158 | { 159 | $thumbnails = new stdClass(); 160 | 161 | $video_object = acf_vimeo_ping_api( $vimeo_id ); 162 | 163 | if($video_object) 164 | { 165 | $thumbnails->small = $video_object->thumbnail_small; 166 | $thumbnails->medium = $video_object->thumbnail_medium; 167 | $thumbnails->large = $video_object->thumbnail_large; 168 | } 169 | 170 | return $thumbnails; 171 | } 172 | 173 | 174 | // RETURN JUST ID 175 | if( $field['return_format'] == "id" ) 176 | { 177 | return $vimeo_id; 178 | } 179 | 180 | 181 | // RETURN A VIMEO OBJECT 182 | if( $field['return_format'] == "object" ) 183 | { 184 | $value = acf_vimeo_ping_api( $vimeo_id ); 185 | } 186 | 187 | return $value; 188 | } 189 | 190 | } 191 | 192 | 193 | // CREATE FIELD 194 | new acf_field_vimeo(); 195 | ?> -------------------------------------------------------------------------------- /acf-vimeo-v5.php: -------------------------------------------------------------------------------- 1 | name = 'vimeo'; 8 | $this->label = __('Vimeo Video', 'acf-vimeo'); 9 | $this->category = 'basic'; 10 | $this->defaults = array( 'return_format' => 'embed' ); 11 | $this->l10n = array(); 12 | $this->transient_time = ACF_VIMEO_TRANSIENT_TIME; 13 | $this->reg_ex = ACF_VIMEO_REG_EX; 14 | 15 | parent::__construct(); 16 | 17 | } 18 | 19 | 20 | /* 21 | * render_field_options() 22 | * 23 | * Create extra options for your field. These are visible when editing a field. 24 | * All parameters of `acf_render_field_option` can be changed except 'prefix' 25 | * 26 | * @type action 27 | * @since 3.6 28 | * @date 23/01/13 29 | * 30 | * @param $field (array) the $field being edited 31 | * @return n/a 32 | */ 33 | 34 | function render_field_settings( $field ) 35 | { 36 | acf_render_field_setting( $field, array( 37 | 'label' => __('Return Value','acf-vimeo'), 38 | 'instructions' => __('Type of data returned when using the_field()','acf-vimeo'), 39 | 'type' => 'radio', 40 | 'name' => 'return_format', 41 | 'value' => $field['return_format'], 42 | 'prepend' => '', 43 | 'prefix' => $field['prefix'], 44 | 'layout' => 'horizontal', 45 | 'choices' => array( 46 | 'id' => __("Vimeo ID",'acf-vimeo'), 47 | 'embed' => __("Embed",'acf-vimeo'), 48 | 'object' => __("Video Object",'acf-vimeo'), 49 | 'thumbnail-object' => __("Thumbnail Object",'acf-vimeo') 50 | ) 51 | )); 52 | } 53 | 54 | 55 | 56 | /* 57 | * render_field() 58 | * 59 | * Create the HTML interface for your field 60 | * 61 | * @param $field (array) the $field being rendered 62 | * 63 | * @type action 64 | * @since 3.6 65 | * @date 23/01/13 66 | * 67 | * @param $field (array) the $field being edited 68 | * @return n/a 69 | */ 70 | 71 | function render_field( $field ) 72 | { 73 | // VARS 74 | $e = ''; 75 | $o = array( 'id', 'class', 'name', 'value' ); 76 | 77 | $e .= '
'; 78 | $e .= ''; 89 | 90 | if( $field['value'] ) 91 | { 92 | $current_vimeo_id = acf_vimeo_parse_vimeo_id( $field['value'] ); 93 | if($current_vimeo_id) 94 | { 95 | $e .= ''; 96 | } 97 | } 98 | 99 | $e .= '
'; 100 | 101 | $e .= " 102 | 103 | 150 | 151 | "; 152 | 153 | echo $e; 154 | } 155 | 156 | 157 | 158 | 159 | /* 160 | * format_value() 161 | * 162 | * This filter is applied to the $value after it is loaded from the db and before it is passed to the render_field() function 163 | * 164 | * @type filter 165 | * @since 3.6 166 | * @date 23/01/13 167 | * 168 | * @param $value (mixed) the value which was loaded from the database 169 | * @param $post_id (mixed) the $post_id from which the value was loaded 170 | * @param $field (array) the field array holding all the field options 171 | * @param $template (boolean) true if value requires formatting for front end template function 172 | * @return $value 173 | */ 174 | 175 | 176 | function format_value( $value, $post_id, $field ) 177 | { 178 | 179 | $vimeo_id = acf_vimeo_parse_vimeo_id( $value ); 180 | 181 | 182 | // IF NO VIDEO ID RETURN NOTHING 183 | if( !$vimeo_id ) { return false; } 184 | 185 | 186 | // RETURN EMBED 187 | if( $field['return_format'] == "embed" ) 188 | { 189 | return apply_filters('acf_vimeo_embed', '', $vimeo_id); 190 | } 191 | 192 | 193 | // RETURN THUMBNAIL 194 | if( $field['return_format'] == "thumbnail-object" ) 195 | { 196 | $thumbnails = new stdClass(); 197 | 198 | $video_object = acf_vimeo_ping_api( $vimeo_id ); 199 | 200 | if($video_object) 201 | { 202 | $thumbnails->small = $video_object->thumbnail_small; 203 | $thumbnails->medium = $video_object->thumbnail_medium; 204 | $thumbnails->large = $video_object->thumbnail_large; 205 | } 206 | 207 | return $thumbnails; 208 | } 209 | 210 | 211 | // RETURN JUST ID 212 | if( $field['return_format'] == "id" ) 213 | { 214 | return $vimeo_id; 215 | } 216 | 217 | 218 | // RETURN A VIMEO OBJECT 219 | if( $field['return_format'] == "object" ) 220 | { 221 | $value = acf_vimeo_ping_api( $vimeo_id ); 222 | } 223 | 224 | return $value; 225 | } 226 | } 227 | 228 | 229 | // create field 230 | new acf_field_vimeo(); 231 | 232 | ?> --------------------------------------------------------------------------------