diff --git a/CHANGELOG.md b/CHANGELOG.md index 51013b1..9590fdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,13 @@ # Changelog +## 1.0.3 - 2017-10-06 + +### Changed +- Removed dynamic resource file from the repository + +### Added +- Added screenshots to the readme. +- Added resource links to download font packages + ## 1.0.2 - 2017-09-06 - Initial release \ No newline at end of file diff --git a/README.md b/README.md index 42c7223..198e4eb 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,14 @@ Craft plugin that provides a new field type that offers users an easy way to pick an icon from a .woff or .ttf font file. You can easily use ionicons or font awesome icons +**Note**: This plugin may become a paid add-on when the Craft Plugin store becomes available. + +## Requirements +* Craft 3.0 (beta 20)+ +* PHP 7.0+ +* PhenX PHP Font Lib +* One or more .ttf or .woff files + ## Example ### Example of the field usage in the template for a cms user @@ -80,5 +88,6 @@ Display an icon with a custom class: ### Contributors & Developers -Lucas Weijers - info@dolphiq.nl -Brought to you by [Dolphiq](Https://dolphiq.nl) +Lucas Weijers - Original developer +Johan Zandstra - Minor changes +Brought to you by [Dolphiq](Https://dolphiq.nl) info@dolphiq.nl diff --git a/composer.json b/composer.json index 4231a6a..427e207 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dolphiq/iconpicker", - "description": "Iconpicker", - "version": "1.0.2", + "description": "Craft Iconpicker plugin provides a new field type that offers users an easy way to pick an icon from a .woff or .ttf font file.", + "version": "1.0.3", "keywords": [ "craft", "cms", @@ -14,7 +14,7 @@ "type": "craft-plugin", "license": "MIT", "require": { - "craftcms/cms": "^3.0.0-beta.10", + "craftcms/cms": "^3.0.0-beta.20", "phenx/php-font-lib": "^0.5.0" }, "autoload": { @@ -32,6 +32,7 @@ "extra": { "handle": "dolphiq-iconpicker", "name": "Iconpicker", + "description": "Craft Iconpicker plugin provides a new field type that offers users an easy way to pick an icon from a .woff or .ttf font file.", "schemaVersion": "1.0.0", "developer": "Dolphiq", "developerUrl": "https://dolphiq.nl/", diff --git a/src/Plugin.php b/src/Plugin.php index 794e02c..da9374c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -18,17 +18,13 @@ class Plugin extends \craft\base\Plugin { - public function init() { parent::init(); // Register field type - Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, function(RegisterComponentTypesEvent $event) { - $event->types[] = Iconpicker::class; + Event::on(Fields::class, Fields::EVENT_REGISTER_FIELD_TYPES, function (RegisterComponentTypesEvent $event) { + $event->types[] = Iconpicker::class; }); } - } - -?> \ No newline at end of file diff --git a/src/assets/appAsset.php b/src/assets/appAsset.php index bd556c0..fd26189 100644 --- a/src/assets/appAsset.php +++ b/src/assets/appAsset.php @@ -37,4 +37,4 @@ public function init() parent::init(); } -} \ No newline at end of file +} diff --git a/src/assets/sharedAsset.php b/src/assets/sharedAsset.php index 2a74d87..9d6b0f7 100644 --- a/src/assets/sharedAsset.php +++ b/src/assets/sharedAsset.php @@ -26,4 +26,4 @@ public function init() parent::init(); } -} \ No newline at end of file +} diff --git a/src/fields/Iconpicker.php b/src/fields/Iconpicker.php index 3893c4b..f17da8d 100644 --- a/src/fields/Iconpicker.php +++ b/src/fields/Iconpicker.php @@ -20,7 +20,6 @@ use yii\db\Schema; use yii\helpers\ArrayHelper; - class Iconpicker extends Field implements PreviewableFieldInterface { // Static @@ -29,22 +28,22 @@ class Iconpicker extends Field implements PreviewableFieldInterface /** * @var string The directory where the fonts are */ - CONST FONT_DIR = '@vendor/dolphiq/iconpicker/src/resources-shared/fonts/'; + const FONT_DIR = '@vendor/dolphiq/iconpicker/src/resources-shared/fonts/'; /** * @var array All extentions that are allowed to be imported as a font */ - CONST FONT_EXT = ['*.woff', '*.ttf']; + const FONT_EXT = ['*.woff', '*.ttf']; /** * @var string Icon class */ - CONST ICON_CLASS = 'dq-icon-'; + const ICON_CLASS = 'dq-icon-'; /** * @var string Pattern to format a safe file name */ - CONST SAFE_NAME_PATTERN = '/[^A-Za-z0-9_\-]/'; + const SAFE_NAME_PATTERN = '/[^A-Za-z0-9_\-]/'; /** * @inheritdoc @@ -167,13 +166,14 @@ public function normalizeValue($value, ElementInterface $element = null) * @return array */ - private function getFonts(){ - if(empty($this->fonts)) { + private function getFonts() + { + if (empty($this->fonts)) { $files = FileHelper::findFiles(Craft::getAlias(self::FONT_DIR), ['only' => self::FONT_EXT]); $filenames = []; $fonts = []; - foreach ($files as $file){ + foreach ($files as $file) { $pathInfo = pathinfo($file); $safename = in_array($pathInfo['filename'], $filenames) ? $pathInfo['basename'] : $pathInfo['filename']; $safename = $this->safeName($safename); @@ -198,9 +198,10 @@ private function getFonts(){ * Returns a options list for the settings dropdown when defining a field * @return array */ - private function getFontOptions(){ + private function getFontOptions() + { $f = $this->getFonts(); - if(!empty($f)){ + if (!empty($f)) { return ArrayHelper::map($f, 'safename', 'basename'); } } @@ -210,11 +211,11 @@ private function getFontOptions(){ * * @return array|null */ - private function getIcons(){ - - if(!empty($this->iconFont)) { + private function getIcons() + { + if (!empty($this->iconFont)) { $fonts = $this->getFonts(); - if(!empty($fonts) && isset($fonts[$this->iconFont])) { + if (!empty($fonts) && isset($fonts[$this->iconFont])) { $font = Font::load($fonts[$this->iconFont]['path']); $font->parse(); @@ -231,10 +232,11 @@ private function getIcons(){ * @param $font \FontLib\TrueType\File|null * @return array|null */ - private function getUnicodeList($font){ - if(!empty($font)){ + private function getUnicodeList($font) + { + if (!empty($font)) { $unicodes = $font->getUnicodeCharMap(); - if(!empty($unicodes)){ + if (!empty($unicodes)) { return array_keys($unicodes); } } @@ -246,21 +248,20 @@ private function getUnicodeList($font){ /** * Generate a css file that creates font families for each font file in the font directory */ - public function getFontCss(){ - + public function getFontCss() + { $sharedAsset = new sharedAsset(); $scss = ""; - foreach ($this->getFonts() as $safeName => $pathInfo){ + foreach ($this->getFonts() as $safeName => $pathInfo) { $fontFile = $pathInfo['path']; $font = Font::load($fontFile); $font->parse(); - if(!empty($font)) { + if (!empty($font)) { $iconFontName = $safeName; if (!empty($iconFontName)) { - $scss .= " @font-face { font-family: 'dq-iconpicker-".$iconFontName."'; @@ -288,9 +289,6 @@ public function getFontCss(){ -moz-osx-font-smoothing: grayscale; }'."\n\n"; - - - } } } @@ -299,17 +297,16 @@ public function getFontCss(){ // Register the assetbundle that loads the generated css Craft::$app->view->registerAssetBundle(sharedAsset::className()); - } // Get the fontname of the currently selected font. - public function getIconFontName(){ - + public function getIconFontName() + { return $this->iconFont; - } - private function safeName($filename){ + private function safeName($filename) + { $name = preg_replace(self::SAFE_NAME_PATTERN, '-', $filename); return $name; } diff --git a/src/models/IconpickerModel.php b/src/models/IconpickerModel.php index 00abe5a..8a6aa05 100644 --- a/src/models/IconpickerModel.php +++ b/src/models/IconpickerModel.php @@ -20,10 +20,8 @@ use Craft; use craft\base\Model; - - -class IconpickerModel extends Model{ - +class IconpickerModel extends Model +{ public $icon; public $iconFont; @@ -34,24 +32,28 @@ public function rules() ]; } - public function getIconChar(){ + public function getIconChar() + { return '&#'.$this->icon.';'; } - public function getIconCharHex(){ + public function getIconCharHex() + { return '&#x'.$this->getIconHex().';'; } - public function getIconHex(){ + public function getIconHex() + { return dechex($this->icon); } - public function getIconSpan(){ + public function getIconSpan() + { return ''.$this->getIconCharHex().''; } - public function getIconClass(){ + public function getIconClass() + { return 'dq-icon-'.$this->iconFont; } - -} \ No newline at end of file +} diff --git a/src/templates/fieldSettings.twig b/src/templates/fieldSettings.twig index 2bcfbf7..6b98083 100644 --- a/src/templates/fieldSettings.twig +++ b/src/templates/fieldSettings.twig @@ -12,6 +12,11 @@ {% else %} -

You need to put at least one font in the plugins font directory. (src/resources-shared/fonts)

+

You need to put at least one font (.ttf or .woff) in the plugins font directory. (src/resources-shared/fonts)

+

Font resources:

+ {% endif %} \ No newline at end of file diff --git a/src/views/main/_field.php b/src/views/main/_field.php index 38655cc..b804372 100644 --- a/src/views/main/_field.php +++ b/src/views/main/_field.php @@ -13,8 +13,7 @@ $field->getFontCss(); -if(count($icons) > 0) { - +if (count($icons) > 0) { ?> @@ -45,8 +44,7 @@ } } else { echo 'No icons found in the selected font'; - } - ?> + } ?> @@ -61,6 +59,9 @@
- +

There is no font uploaded to the font folder of this plugin, no font selected in the field settings, or the font contains no icons

- \ No newline at end of file + \ No newline at end of file