Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Tweaks #20

Merged
merged 12 commits into from
Jun 19, 2017
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
vendor
28 changes: 28 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
wp_readme_to_markdown: {
target: {
files: {
'README.md': 'readme.txt'
},
},
},
makepot: {
target: {
options: {
mainFile: 'uf2.php',
potFilename: 'languages/uf2.pot',
type: 'wp-plugin',
updateTimestamp: true
}
}
}
});

grunt.loadNpmTasks('grunt-wp-readme-to-markdown');
grunt.loadNpmTasks('grunt-wp-i18n');

// Default task(s).
grunt.registerTask('default', ['wp_readme_to_markdown']);
};
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Microformats2 #
**Contributors:** pfefferle, dshanske
**Tags:** microformats, indieweb
**Requires at least:** 4.7
**Tested up to:** 4.8
**Stable tag:** 1.0.0

Enhances your WordPress theme with microformats2 classes.

## Description ##

It is only a very basic implementation, because not every element is accessible through actions or filters. It is better to use a theme that supports [microformats2] fully.

## Frequently Asked Questions ##

### What are microformats2? ###

## Changelog ##

Project actively developed on Github at [pfefferle/wordpress-uf2](https://github.com/pfefferle/wordpress-uf2). Please file support issues there.

### 1.0.0 ###
* Initial Stable Release
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '2'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
links:
- db
ports:
- "80:80"
volumes:
- .:/var/www/html/wp-content/plugins/uf2
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DEBUG: 1
53 changes: 53 additions & 0 deletions includes/author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Enhances Author and Avatar Markup
*
*/
class UF2_Author {
/**
* Initialize plugin
*/
public function __construct() {
add_filter( 'get_avatar_data', array( $this, 'get_avatar_data' ), 10, 2 );
add_filter( 'the_author', array( $this, 'the_author' ), 99, 1 );
}

/**
* Adds microformats v2 support to the comment_author_link.
*/
public static function author_link( $link ) {
// Adds a class for microformats v2
return preg_replace( '/(class\s*=\s*[\"|\'])/i', '${1}u-url ', $link );
}

/**
* Adds microformats v2 support to the get_avatar_data() method.
*/
public static function get_avatar_data( $args, $id_or_email ) {
// Adds a class for microformats v2
if ( ! isset( $args['class'] ) ) {
$args['class'] = array();
}

if ( is_string( $args['class'] ) ) {
$args['class'] = explode( ' ', $args['class'] );
$args['class'][] = 'u-photo';
}
else {
$args['class'][] = 'u-photo';
}
return $args;
}

/**
* Adds microformats v2 support to the author.
*/
public static function the_author( $author ) {
if ( ! is_admin() ) {
return "<span class='p-author h-card'>$author</span>";
}

return $author;
}
}
45 changes: 45 additions & 0 deletions includes/comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Adds microformats2 support to your comments
*
*/
class UF2_Comment {
/**
* Initialize plugin
*/
public static function construct() {
// check if theme already supports Microformats2
if ( current_theme_supports( 'microformats2' ) ) {
return;
}

add_filter( 'comment_class', array( $this, 'comment_classes' ) );
add_filter( 'get_comment_author_link', array( $this, 'author_link' ) );
add_filter( 'comment_text', array( $this, 'comment_text' ), 99, 1 );

if ( function_exists( 'genesis_html5' ) && genesis_html5() ) {
include_once dirname( __FILE__ ) . '/genesis.php';
}
}

/**
* Adds custom classes to the array of comment classes.
*/
public static function comment_classes( $classes ) {
$classes[] = 'u-comment';
$classes[] = 'h-cite';

return $classes;
}

/**
* Adds microformats v2 support to the comment.
*/
public static function comment_text( $comment ) {
if ( ! is_admin() ) {
return "<div class='e-content p-name p-summary'>$comment</div>";
}

return $comment;
}
}
File renamed without changes.
30 changes: 30 additions & 0 deletions includes/media.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* Adds microformats2 support to media and post formats
*
*/
class UF2_Media {
/**
* Initialize plugin
*/
public function __construct() {
add_filter( 'wp_get_attachment_image_attributes', array( $this, 'wp_get_attachment_image_attributes' ), 10, 2 );
}

public static function wp_get_attachment_image_attributes( array $attr, WP_Post $attachment ) {
$parents = get_post_ancestors( $attachment );
$id = $parents[ count( $parents ) -1 ];
if ( 'image' !== get_post_format( $id ) ) {
return $attr;
}
if ( isset( $attr['class'] ) ) {
$class = explode( ' ', $attr['class'] );
$class[] = 'u-photo';
$attr['class'] = implode( ' ', array_unique( $class ) );
} else {
$attr['class'] = 'u-photo';
}
return $attr;
}
}
94 changes: 94 additions & 0 deletions includes/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* Adds microformats2 support to your posts
*
*/
class UF2_Post {
/**
* Initialize plugin
*/
public function __construct() {
add_filter( 'post_class', array( $this, 'post_classes' ) );
add_filter( 'body_class', array( $this, 'body_classes' ) );
add_filter( 'the_title', array( $this, 'the_title' ), 99, 1 );
// The priority ensures that the content and not anything added dynamically by another plugin.
add_filter( 'the_content', array( $this, 'the_post' ), -1, 1 );
add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), -1, 1 );

add_filter( 'date_i18n', array( $this, 'fix_c_time_format' ), 10, 3 );
}

function fix_c_time_format( $date, $format, $timestamp ) {
if ( 'c' == $format )
$date = date_i18n( DATE_W3C, $timestamp );

return $date;
}

/**
* Adds custom classes to the array of post classes.
*/
public static function post_classes( $classes ) {
$classes = array_diff( $classes, array( 'hentry' ) );
if ( ! is_singular() ) {
if ( 'page' !== get_post_type() ) {
// Adds a class for microformats v2
$classes[] = 'h-entry';
// add hentry to the same tag as h-entry
$classes[] = 'hentry';
}
}
return $classes;
}

/**
* Adds custom classes to the array of body classes.
*/
public static function body_classes( $classes ) {
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
$classes[] = 'h-feed';
} else {
if ( 'page' !== get_post_type() ) {
$classes[] = 'hentry';
$classes[] = 'h-entry';
}
}
return array_unique( $classes );
}

/**
* Adds microformats v2 support to the post title.
*/
public static function the_title( $title ) {
if ( ! is_admin() && in_the_loop() ) {
return "<span class='p-name'>$title</span>";
}

return $title;
}

/**
* Adds microformats v2 support to the post.
*/
public static function the_post( $post ) {
if ( ! is_admin() ) {
return "<div class='e-content'>$post</div>";
}

return $post;
}

/**
* Adds microformats v2 support to the excerpt.
*/
public static function the_excerpt( $post ) {
if ( ! is_admin() ) {
return "<div class='e-content p-summary'>$post</div>";
}

return $post;
}
}
34 changes: 34 additions & 0 deletions languages/uf2.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2017 pfefferle
# This file is distributed under the same license as the uf2 package.
msgid ""
msgstr ""
"Project-Id-Version: uf2 1.0.0-dev\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/uf2\n"
"POT-Creation-Date: 2017-06-17 18:57:11+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"PO-Revision-Date: 2017-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"X-Generator: grunt-wp-i18n 0.5.4\n"

#. Plugin Name of the plugin/theme
msgid "uf2"
msgstr ""

#. Plugin URI of the plugin/theme
msgid "https://github.com/pfefferle/wordpress-uf2"
msgstr ""

#. Description of the plugin/theme
msgid "Adds microformats2 support to your WordPress theme"
msgstr ""

#. Author of the plugin/theme
msgid "pfefferle"
msgstr ""

#. Author URI of the plugin/theme
msgid "http://notizblog.org/"
msgstr ""
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "wordpress-uf2",
"description": "Microformats 2 for WordPress!",
"dependencies": {
"grunt": "^0.4.5"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-wp-deploy": "^1.0.3",
"grunt-wp-i18n": "^0.5.0",
"grunt-wp-readme-to-markdown": "^0.8.0"
},
"repository": {
"type": "git",
"url": "https://github.com/pfefferle/wordpress-uf2.git"
},
"keywords": [
"wordpress",
"mf2",
"microformats2",
"indieweb"
],
"author": "Matthias Pfefferle",
"license": "MIT",
"bugs": {
"url": "https://github.com/pfefferle/wordpress-uf2/issues"
},
"homepage": "https://github.com/pfefferle/wordpress-uf2"
}
1 change: 0 additions & 1 deletion readme.md

This file was deleted.