Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
v2.0.0-rc1
Browse files Browse the repository at this point in the history
* Updated "oembed/oembed": "^4.0"
* Added Instagram and Facebook token settings
  • Loading branch information
leevigraham committed Feb 16, 2021
1 parent 79c693f commit 84166fb
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 64 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.0.0-rc1 - 2021.02.16

> v2.0.0 requires `"oembed/oembed": "^4.0"` which requires `"php": "^7.4|^8",`. Additionally the return data format has changed due to the updated `oembed/oembed` library. The new format can be found in the [https://github.com/newism/craft3-fields/blob/master/README.md](README.md). Existing content will still continue to work.
### Changes
- Updated dependency on `oembed/oembed` to ^v4.0

### Added
- Added new facebookToken setting
- Added new instagramToken setting

## 1.0.2 - 2021.01.19
### Fixes
- MapURL is persisted. #61 - https://github.com/newism/craft3-fields/pull/61 @thomasgoemaere
Expand Down
99 changes: 59 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
**Attention**: This plugin is under active development and will change. This is a preview release.
# A collection of custom Fields CraftCMS 3.x

# Address, telephone and email fields for CraftCMS 3.x
## Installation

Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:

```console
$ composer require newism/craft3-fields
```

Then install it…

```console
./craft plugin/install nsm-fields
```

## Configuration

* If you're using Address Autocomplete you'll need an [api key](https://developers.google.com/places/web-service/get-api-key).
* If you're embedding Instagram you'll need an [api key](https://developers.facebook.com/docs/instagram/oembed).
* If you're embedding Facebook you'll need an [api key](https://developers.facebook.com/docs/plugins/oembed).

Add the api keys to your enviroment and set in the plugin settings. See: https://craftcms.com/docs/3.x/config/#environmental-configuration

Alternatively…

Copy `src/config.php` to `CRAFT_CONFIG_PATH` and rename the file to `nsm-fields.php`.

---

# Fields

## Address

Expand Down Expand Up @@ -103,6 +132,33 @@ Given `entry.embedField` is your field…
* `{{ entry.embedField.embedData }}` outputs the returned embed object.
* `{{ entry.embedField.embedData.code | raw }}` outputs the returned embed javascript code.

Additional data:

{{ entry.embedField.embedData.authorName }} // The resource author
{{ entry.embedField.embedData.authorUrl }} // The author url
{{ entry.embedField.embedData.cms }} // The cms used
{{ entry.embedField.embedData.code.html }} // The code to embed the image, video, etc
{{ entry.embedField.embedData.code.width }} // The exact width of the embed code (if exists)
{{ entry.embedField.embedData.code.height }} // The exact height of the embed code (if exists)
{{ entry.embedField.embedData.code.aspectRatio }} // The aspect ratio (width/height)
{{ entry.embedField.embedData.description }} //The page description
{{ entry.embedField.embedData.favicon }} // The favicon of the site (an .ico file or a png with up to 32x32px)
{{ entry.embedField.embedData.feeds }} // The RSS/Atom feeds
{{ entry.embedField.embedData.icon }} // The big icon of the site
{{ entry.embedField.embedData.image }} // The thumbnail or main image
{{ entry.embedField.embedData.keywords }} // The page keywords
{{ entry.embedField.embedData.language }} // The language of the page
{{ entry.embedField.embedData.languages }} // The alternative languages
{{ entry.embedField.embedData.license }} // The license url of the resource
{{ entry.embedField.embedData.providerName }} // The provider name of the page (Youtube, Twitter, Instagram, etc)
{{ entry.embedField.embedData.providerUrl }} // The provider url
{{ entry.embedField.embedData.publishedTime }} // The published time of the resource
{{ entry.embedField.embedData.redirect }}
{{ entry.embedField.embedData.title }} //The page title
{{ entry.embedField.embedData.url }} //The canonical url
{{ entry.embedField.embedData.ombed }} // oembed data
{{ entry.embedField.embedData.linkedData }} // json-LD data

![Embed Demo](resources/img/embed-demo.gif)

## Person Name
Expand All @@ -126,52 +182,15 @@ Non-binary gender field with:

![Gender](resources/img/gender-field.png)

## Installation

### Step 1: Download the Bundle

Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:

```console
$ composer require newism/craft3-fields
```

This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.

### Step 2: Install

Install plugin in the Craft Control Panel under Settings > Plugins.

## Configuration

The plugin comes with a config.php file that defines some sensible defaults.

Copy `src/config.php` to `CRAFT_CONFIG_PATH` and rename the file to `nsm-fields.php`.

## Road Map

Some things to do, and ideas for potential features:

* Split out each field into it's own plugin. Keep this plugin as a single composer file which pulls all felds in
* Split out each field into it's own plugin. Keep this plugin as a single composer file which pulls all fields in
* Address validation / Geo-coding on submission
* Display address as text in field with option to "Edit" to reduce size of field in UI
* Update commerceguys/addressing when next stable version is released

### 1.0

* Release it

### 1.1

* Add "NSM Publish Hints" field

### 1.2

* ~~Add video field with yoututbe, vimeo previews~~ See Embed Field

## Credits

Brought to you by [Newism](http://newism.com.au)
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "newism/craft3-fields",
"description": "Address, telephone and email fields for CraftCMS 3.x",
"type": "craft-plugin",
"version": "1.0.2",
"version": "2.0.0-rc1",
"keywords": [
"craft",
"cms",
Expand All @@ -26,10 +26,11 @@
}
],
"require": {
"craftcms/cms": "^3.0",
"craftcms/cms": "^3.5",
"giggsey/libphonenumber-for-php": "^8.3",
"commerceguys/addressing": "^1.0",
"embed/embed": "^3.0"
"nyholm/psr7": "^1.2",
"embed/embed": "^4.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 9 additions & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
class Settings extends Model
{
public $googleApiKey = '';
public $facebookToken = '';
public $instagramToken = '';

public function behaviors()
{
return [
'parser' => [
'class' => EnvAttributeParserBehavior::class,
'attributes' => ['googleApiKey'],
'attributes' => [
'googleApiKey',
'facebookToken',
'instagramToken'
],
],
];
}
Expand All @@ -22,6 +28,8 @@ public function rules()
{
return [
['googleApiKey', 'string'],
['facebookToken', 'string'],
['instagramToken', 'string'],
];
}
}
45 changes: 25 additions & 20 deletions src/services/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace newism\fields\services;

use craft\base\Component;
use newism\fields\NsmFields;

/**
* Embed Service
Expand Down Expand Up @@ -42,32 +43,36 @@ class Embed extends Component
*/
public function parse($url)
{
$info = \Embed\Embed::create($url);
$pluginSettings = NsmFields::getInstance()->getSettings();
$embed = new \Embed\Embed();
$embed->setSettings([
'facebook:token' => $pluginSettings->facebookToken, //Required to embed content from Facebook
'instagram:token' => $pluginSettings->instagramToken, //Required to embed content from Instagram
]);
$info = $embed->get($url);
$result = [];
$result['title'] = $info->title;
$result['description'] = $info->description;
$result['url'] = $info->url;
$result['type'] = $info->type;
$result['tags'] = $info->tags;
$result['images'] = $info->images;
$result['image'] = $info->image;
$result['imageWidth'] = $info->imageWidth;
$result['imageHeight'] = $info->imageHeight;
$result['code'] = $info->code;
$result['source'] = $info->source;
$result['width'] = $info->width;
$result['height'] = $info->height;
$result['aspectRatio'] = $info->aspectRatio;

$result['authorName'] = $info->authorName;
$result['authorUrl'] = $info->authorUrl;
$result['cms'] = $info->cms;
$result['code'] = $info->code;
$result['description'] = $info->description;
$result['favicon'] = $info->favicon;
$result['feeds'] = $info->feeds;
$result['icon'] = $info->icon;
$result['image'] = $info->image;
$result['keywords'] = $info->keywords;
$result['language'] = $info->language;
$result['languages'] = $info->languages;
$result['license'] = $info->license;
$result['providerName'] = $info->providerName;
$result['providerUrl'] = $info->providerUrl;
$result['providerIcon'] = $info->providerIcon;
$result['providerIcons'] = $info->providerIcons;
$result['publishedDate'] = $info->publishedDate;
$result['publishedTime'] = $info->publishedTime;
$result['license'] = $info->license;
$result['linkedData'] = $info->linkedData;
$result['redirect'] = $info->redirect;
$result['title'] = $info->title;
$result['url'] = $info->url;
$result['ombed'] =$info->getOEmbed()->all();
$result['linkedData'] =$info->getLinkedData()->all();

return $result;
}
Expand Down
25 changes: 25 additions & 0 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% import "_includes/forms" as forms %}

{% set fileConfig = craft.app.config.getConfigFromFile('nsm-fields') %}

{{ forms.autoSuggestField({
first: true,
suggestEnvVars: true,
Expand All @@ -12,3 +13,27 @@
errors: settings.getErrors('googleApiKey'),
warning: (fileConfig.googleApiKey is defined) ? 'This is being overridden by the `googleApiKey` setting in `config/nsm-fields.php`.' : null,
}) }}

{{ forms.autoSuggestField({
first: true,
suggestEnvVars: true,
label: 'Instagram Token'|t('nsm-fields'),
instructions: 'Required to embed content from Instagram - See the [official documentation](https://developers.facebook.com/docs/instagram/oembed).',
id: 'instagramToken',
name: 'instagramToken',
value: settings.instagramToken,
errors: settings.getErrors('instagramToken'),
warning: (fileConfig.instagramToken is defined) ? 'This is being overridden by the `instagramToken` setting in `config/nsm-fields.php`.' : null,
}) }}

{{ forms.autoSuggestField({
first: true,
suggestEnvVars: true,
label: 'facebook Token'|t('nsm-fields'),
instructions: 'Required to embed content from Facebook - See the [official documentation](https://developers.facebook.com/docs/instagram/oembed).',
id: 'facebookToken',
name: 'facebookToken',
value: settings.facebookToken,
errors: settings.getErrors('facebookToken'),
warning: (fileConfig.facebookToken is defined) ? 'This is being overridden by the `facebookToken` setting in `config/nsm-fields.php`.' : null,
}) }}

0 comments on commit 84166fb

Please sign in to comment.