Skip to content

Commit

Permalink
Merge branch '1.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome committed Jul 23, 2019
2 parents df22654 + fede89b commit 50d43a4
Show file tree
Hide file tree
Showing 14 changed files with 1,389 additions and 747 deletions.
725 changes: 0 additions & 725 deletions acf-component_field.php

This file was deleted.

35 changes: 27 additions & 8 deletions acf-extensions.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/*
Plugin Name: Advanced Custom Fields Extensions
Description: Advanced Custom Fields add on. Create component, components field, hidden field and lastest post field
Version: 1.0.0
Description: Advanced Custom Fields add on. Create components, component field, hidden field and latest post field
Version: 1.1.0
Author: Metabolism
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -31,17 +31,36 @@ function acf_extensions_load_textdomain() {
*/
function include_acf_extensions_plugin() {

include_once('acf-component_field.php');
include_once('acf-hidden_field.php');
include_once('acf-latest_posts_field.php');
$required_version = '5.8.0';

acf_register_field_type( 'acf_field_component' );
acf_register_field_type( 'acf_field_hidden' );
acf_register_field_type( 'acf_field_latest_posts' );
if( !function_exists('acf') )
return;

$acf = acf();

if( is_admin() && version_compare($acf->version, $required_version, '<') ) {
add_action('admin_notices', function() use($required_version){
echo '<div class="error"><p>'.__('ACF Extensions plugin requires ACF PRO '.$required_version).'</p></div>';
});
}

include_once('fields/class-acf-field-component.php');
include_once('fields/class-acf-field-components.php');
include_once('fields/class-acf-field-hidden.php');
include_once('fields/class-acf-field-latest_posts.php');
include_once('fields/class-acf-field-better_link.php');
include_once('fields/class-acf-field-better_map.php');

include_once('rules/class-acf-rule-multisite.php');
}

add_action('acf/include_field_types', 'include_acf_extensions_plugin');

add_filter( 'mce_external_plugins', function ( $plugins ) {
$plugins['table'] = content_url() . '/plugins/acf-extensions/js/tinymce/table/plugin.min.js';
return $plugins;
});


/**
* Change acf-component status back to acf-diabled when deactivated
Expand Down
4 changes: 2 additions & 2 deletions composer.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name":"metabolism/acf-extensions",
"version": "1.0.0",
"version": "1.1.0",
"type": "wordpress-plugin",
"description": "ACF Extensions plugin with components, hidden field ans lastest posts field",
"description": "ACF Extensions plugin with component, components, hidden field ans latest posts field",
"license": "GPL-3.0-or-later",
"branch-alias": {
"dev-1.0.x": "1.0.x-dev"
Expand Down
5 changes: 2 additions & 3 deletions css/input.css
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.acf-field-hidden, .acf-field-latest-posts{
display: none;
}
.acf-field-hidden, .acf-field-latest-posts{ display: none; }
.acf-field .acf-label:empty{ display: none }
31 changes: 28 additions & 3 deletions css/thumbnail.css
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
.acf-fc-layout-handle .thumbnail{
position: relative; display: inline-block; width: 36px; margin-right: 15px; height: 15px; margin-bottom: -10px; cursor: zoom-in;
position: relative; display: inline-block; width: 44px; margin-right: 15px; height: 15px; margin-bottom: -20px; margin-left: 2px;
}

.acf-fc-layout-handle .thumbnail .small{
position: absolute; left: 0; bottom: 0; width: 100%; border: 1px solid #ddd; padding: 3px; background: #fff;
position: absolute; left: 0; bottom: 0; width: 100%; border: 1px solid #ddd; padding: 2px; background: #fff;
}

.acf-fc-layout-handle .thumbnail .large{
position: absolute; left: 0; bottom: 0; pointer-events: none; display: none; transform: translateY(50%); z-index: 999;
border: 1px solid #ddd; padding: 5px; background: #fff; max-width: 60vw; height: auto; box-shadow: 0 0 10px rgba(0,0,0,0.08);
border: 1px solid #ddd; padding: 5px; background: #fff; max-width:600px; height: auto; box-shadow: 0 0 10px rgba(0,0,0,0.08);
}

.acf-fc-layout-handle .thumbnail:hover .large{ display: block }


.acf-fc-popup [data-layout]+span{
position: absolute; right: 100%; top: 50%; transform: translateY(-50%); display: none; margin-right: 10px;
border: 1px solid #ddd; padding: 5px; background: #fff; max-width:600px; box-shadow: 0 0 10px rgba(0,0,0,0.08);
}

.acf-fc-popup [data-layout]+span:after{
width: 0; height: 0; border-style: solid; border-width: 7.5px 0 7.5px 8px; border-color: transparent transparent transparent #ffffff;
position: absolute; left: 100%; top: 50%; margin-top: -5px; content: ''; z-index: 1;
}


.acf-fc-popup [data-layout]+span:before{
width: 0; height: 0; border-style: solid; border-width: 8.5px 0 8.5px 10px; border-color: transparent transparent transparent #ddd;
position: absolute; left: 100%; top: 50%; margin-top: -5.5px; content: ''; z-index: 0;
}

.acf-fc-popup li:hover [data-layout]+span{
display: block;
}
.acf-fc-popup [data-layout]+span img{ max-width:600px; width: auto; height: auto; display: block }

.postbox{ box-shadow: none }
.postbox.closed .hndle{ border-bottom: 0 }
76 changes: 76 additions & 0 deletions fields/class-acf-field-better_link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

if( ! class_exists('acf_field_better_link') ) :

class acf_field_better_link {


/**
* Whan saving link, store post_id and boolean to know if the link title is the post title
* @param $value
* @param int $post_id
* @param array $field
* @return mixed
*/
public function updateValue($value, $post_id=0, $field=array()){

if( $field['type'] == 'link' && isset($value['url'])){

$value['post_id'] = url_to_postid($value['url']);

if( $value['post_id'] ){
$title = get_the_title($value['post_id']);
$value['is_title'] = $title == $value['title'];
}
elseif( isset($value['is_title']) ){
unset($value['is_title']);
}
}

return $value;
}

/**
* On load, check if link and title still belong to the post_id, else update
* @param $value
* @param int $post_id
* @param array $field
* @return mixed
*/
public function loadValue($value, $post_id=0, $field=array()){

if( $field['type'] == 'link' && isset($value['post_id']) && $value['post_id']){

$url = get_permalink($value['post_id']);
$update = false;

if( isset($value['is_title']) && $value['is_title'] ) {
$value['title'] = get_the_title($value['post_id']);
$update = true;
}

if( $url != $value['url']) {
$value['url'] = $url;
$update = true;
}

if($update){
acf_update_metadata( $post_id, $field['name'], $value );
acf_update_metadata( $post_id, $field['name'], $field['key'], true );
acf_flush_value_cache( $post_id, $field['name'] );
}
}

return $value;
}

public function __construct()
{
add_filter('acf/update_value', [$this, 'updateValue'], 10, 3);
add_filter('acf/load_value', [$this, 'loadValue'], 10, 3);
}
}

new acf_field_better_link();

endif; // class_exists check
87 changes: 87 additions & 0 deletions fields/class-acf-field-better_map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

if( ! class_exists('acf_field_better_map') ) :

class acf_field_better_map {

/**
* When saving map, save also country and iso
* todo: move to js
* @param $value
* @param int $post_id
* @param array $field
* @return mixed
*/
public function updateValue($value, $post_id=0, $field=array()){

if( $field['type'] == 'google_map' && isset($value['address']) && !empty($value['address']) ){

$google_api_key = acf_get_setting('google_api_key');

$url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='.$value['lat'].','.$value['lng'].'&sensor=false&key='.$google_api_key.'&result_type=country';
$data = json_decode(file_get_contents($url), true);

if($data && isset($data['results']) && count($data['results']) ){

$result = $data['results'][0];

if( isset($result['address_components']) && count( $result['address_components'])){

$address = $result['address_components'][0];

$value['country'] = $address['long_name'];
$value['iso'] = $address['short_name'];
}
}
}

return $value;
}

/**
* On load, check if country and iso exists else get it from google
* @param $value
* @param int $post_id
* @param array $field
* @return mixed
*/
public function loadValue($value, $post_id=0, $field=array()){

if( $field['type'] == 'google_map' && isset($value['address']) && !empty($value['address']) && !isset($value['country'])){

$google_api_key = acf_get_setting('google_api_key');

$url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='.$value['lat'].','.$value['lng'].'&sensor=false&key='.$google_api_key.'&result_type=country';
$data = json_decode(file_get_contents($url), true);

if($data && isset($data['results']) && count($data['results']) ){

$result = $data['results'][0];

if( isset($result['address_components']) && count( $result['address_components'])){

$address = $result['address_components'][0];

$value['country'] = $address['long_name'];
$value['iso'] = $address['short_name'];

acf_update_metadata( $post_id, $field['name'], $value );
acf_update_metadata( $post_id, $field['name'], $field['key'], true );
acf_flush_value_cache( $post_id, $field['name'] );
}
}
}

return $value;
}

public function __construct()
{
add_filter('acf/update_value', [$this, 'updateValue'], 10, 3);
add_filter('acf/load_value', [$this, 'loadValue'], 10, 3);
}
}

new acf_field_better_map();

endif; // class_exists check
Loading

0 comments on commit 50d43a4

Please sign in to comment.