Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public static function meta_boxes( $object, $box ) {
/**
* Add comment-type as column in WP-Admin
*
* @param array $column the column to implement
* @param int $comment_id the comment id
* @param array $column The column to implement.
* @param int $comment_id The comment id.
*/
public static function manage_comments_custom_column( $column, $comment_id ) {
if ( 'comment_type' !== $column ) {
Expand All @@ -74,16 +74,25 @@ public static function manage_comments_custom_column( $column, $comment_id ) {
}

/**
* Add bulk option to bulk comment handler
* Add bulk option to bulk comment handler.
*
* @param array $bulk_actions The bulk actions.
*
* @return array The bulk actions.
*/
public static function bulk_comment_actions( $bulk_actions ) {
$bulk_actions['refresh_webmention'] = __( 'Refresh Webmention', 'webmention' );
return $bulk_actions;
}

/**
* Add bulk action handler to comments
* Add bulk action handler to comments.
*
* @param string $redirect_to The redirect URL.
* @param string $doaction The action to perform.
* @param array $comment_ids The comment IDs.
*
* @return string The redirect URL.
*/
public static function bulk_comment_action_handler( $redirect_to, $doaction, $comment_ids ) {
if ( 'refresh_webmention' !== $doaction ) {
Expand All @@ -98,12 +107,12 @@ public static function bulk_comment_action_handler( $redirect_to, $doaction, $co
}

/**
* Add an action link
* Add an action link.
*
* @param array $links the settings links
* @param string $file the plugin filename
* @param array $links The settings links.
* @param string $file The plugin filename.
*
* @return array the filtered array
* @return array The filtered array.
*/
public static function plugin_action_links( $links, $file ) {
if ( stripos( $file, 'webmention' ) === false || ! function_exists( 'admin_url' ) ) {
Expand All @@ -120,12 +129,12 @@ public static function plugin_action_links( $links, $file ) {
}

/**
* Add a plugin meta link
* Add a plugin meta link.
*
* @param array $links the settings links
* @param string $file the plugin filename
* @param array $links The settings links.
* @param string $file The plugin filename.
*
* @return array the filtered array
* @return array The filtered array.
*/
public static function plugin_row_meta( $links, $file ) {
if ( stripos( $file, 'webmention' ) === false || ! function_exists( 'admin_url' ) ) {
Expand Down Expand Up @@ -175,16 +184,26 @@ public static function comment_types_dropdown( $types ) {
}

/**
* Add comment-type as column in WP-Admin
* Add comment-type as column in WP-Admin.
*
* @param array $columns The list of column names.
*
* @param array $columns the list of column names
* @return array The filtered columns.
*/
public static function comment_columns( $columns ) {
$columns['comment_type'] = esc_html__( 'Comment-Type', 'webmention' );

return $columns;
}

/**
* Add comment-type as column in WP-Admin.
*
* @param array $actions The actions.
* @param object $comment The comment object.
*
* @return array The filtered actions.
*/
public static function comment_row_actions( $actions, $comment ) {
$query = array(
'_wpnonce' => wp_create_nonce( "approve-comment_$comment->comment_ID" ),
Expand Down Expand Up @@ -213,6 +232,11 @@ public static function comment_row_actions( $actions, $comment ) {
return $actions;
}

/**
* Add a webmention approve domain.
*
* @param string $host The host.
*/
public static function add_webmention_approve_domain( $host ) {
$approvelist = get_webmention_approve_domains();
$approvelist[] = $host;
Expand All @@ -221,6 +245,11 @@ public static function add_webmention_approve_domain( $host ) {
update_option( 'webmention_approve_domains', $approvelist );
}

/**
* Transition to approve list.
*
* @param object $comment The comment object.
*/
public static function transition_to_approvelist( $comment ) {
if ( ! current_user_can( 'moderate_comments' ) ) {
return;
Expand Down Expand Up @@ -267,9 +296,7 @@ public static function admin_menu() {
* Load settings page
*/
public static function settings_page() {
require_once __DIR__ . '/class-db.php';
\Webmention\DB::update_database();
\Webmention\remove_semantic_linkbacks();
Upgrade::maybe_upgrade();

add_thickbox();
wp_enqueue_script( 'plugin-install' );
Expand Down Expand Up @@ -326,6 +353,9 @@ public static function add_help_tab() {
);
}

/**
* Register settings.
*/
public static function register_settings() {
register_setting(
'webmention',
Expand Down Expand Up @@ -450,7 +480,7 @@ public static function register_settings() {
}

/**
* Add recommended privacy content
* Add recommended privacy content.
*/
public static function add_privacy_policy_content() {
$content =
Expand Down
106 changes: 106 additions & 0 deletions includes/class-autoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Autoloader for Webmention.
*
* @package Webmention
*/

namespace Webmention;

/**
* An Autoloader that respects WordPress's filename standards.
*/
class Autoloader {

/**
* Namespace separator.
*/
const NS_SEPARATOR = '\\';

/**
* The prefix to compare classes against.
*
* @var string
* @access protected
*/
protected $prefix;

/**
* Length of the prefix string.
*
* @var int
* @access protected
*/
protected $prefix_length;

/**
* Path to the file to be loaded.
*
* @var string
* @access protected
*/
protected $path;

/**
* Constructor.
*
* @param string $prefix Namespace prefix all classes have in common.
* @param string $path Path to the files to be loaded.
*/
public function __construct( $prefix, $path ) {
$this->prefix = $prefix;
$this->prefix_length = \strlen( $prefix );
$this->path = \rtrim( $path . '/' );
}

/**
* Registers Autoloader's autoload function.
*
* @throws \Exception When autoload_function cannot be registered.
*
* @param string $prefix Namespace prefix all classes have in common.
* @param string $path Path to the files to be loaded.
*/
public static function register_path( $prefix, $path ) {
$loader = new self( $prefix, $path );
\spl_autoload_register( array( $loader, 'load' ) );
}

/**
* Loads a class if its namespace starts with `$this->prefix`.
*
* @param string $class_name The class to be loaded.
*/
public function load( $class_name ) {
if ( \strpos( $class_name, $this->prefix . self::NS_SEPARATOR ) !== 0 ) {
return;
}

// Strip prefix from the start (ala PSR-4).
$class_name = \substr( $class_name, $this->prefix_length + 1 );
$class_name = \strtolower( $class_name );
$dir = '';

$last_ns_pos = \strripos( $class_name, self::NS_SEPARATOR );
if ( false !== $last_ns_pos ) {
$namespace = \substr( $class_name, 0, $last_ns_pos );
$namespace = \str_replace( '_', '-', $namespace );
$class_name = \substr( $class_name, $last_ns_pos + 1 );
$dir = \str_replace( self::NS_SEPARATOR, DIRECTORY_SEPARATOR, $namespace ) . DIRECTORY_SEPARATOR;
}

$path = $this->path . $dir . 'class-' . \str_replace( '_', '-', $class_name ) . '.php';

if ( ! \file_exists( $path ) ) {
$path = $this->path . $dir . 'interface-' . \str_replace( '_', '-', $class_name ) . '.php';
}

if ( ! \file_exists( $path ) ) {
$path = $this->path . $dir . 'trait-' . \str_replace( '_', '-', $class_name ) . '.php';
}

if ( \file_exists( $path ) ) {
require_once $path;
}
}
}
4 changes: 1 addition & 3 deletions includes/class-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ public function generate( $args, $assoc_args ) {
* @return void
*/
public function db_migration( $args, $assoc_args ) {
require_once __DIR__ . '/class-db.php';

DB::update_database();
Upgrade::maybe_upgrade();

WP_CLI::success( __( 'DB Migration finished', 'webmention' ) );
}
Expand Down
8 changes: 7 additions & 1 deletion includes/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public static function init() {
add_filter( 'template_include', array( static::class, 'comment_template_include' ) );

add_filter( 'get_comment_link', array( static::class, 'remote_comment_link' ), 11, 2 );

// Default Comment Status.
add_filter( 'get_default_comment_status', 'webmention_get_default_comment_status', 11, 3 );

add_action( 'comment_form_after', 'webmention_comment_form', 11 );
add_action( 'comment_form_comments_closed', 'webmention_comment_form' );
}

/**
Expand Down Expand Up @@ -251,7 +257,7 @@ public static function comment_template_include( $template ) {

// replace template
if ( isset( $wp_query->query['replytocom'] ) ) {
return apply_filters( 'webmention_comment_template', __DIR__ . '/../templates/webmention-comment.php' );
return apply_filters( 'webmention_comment_template', WEBMENTION_PLUGIN_DIR . '/templates/webmention-comment.php' );
}

return $template;
Expand Down
Loading