-
Notifications
You must be signed in to change notification settings - Fork 2
/
sync-mastodon.php
113 lines (99 loc) · 2.95 KB
/
sync-mastodon.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Plugin Name: Sync Mastodon
* Description: Fetch posts from a Mastodon RSS feed and add them to a custom post type
* Author: Ross Wintle
* Author URI: https://rosswintle.uk
* Text Domain: sync-mastodon
* Domain Path: /languages
* Version: 1.3.1
* GitHub Plugin URI: https://github.com/rosswintle/sync-mastodon
*
* @package Sync_Mastodon
*/
namespace SyncMastodon;
require_once __DIR__ . '/src/class-sync-mastodon-options.php';
require_once __DIR__ . '/src/post-types/mastodon-post.php';
require_once __DIR__ . '/src/data/class-mastodon-post.php';
require_once __DIR__ . '/src/data/class-mastodon-media.php';
require_once __DIR__ . '/src/post-types/class-mastodon-post.php';
// require_once '/src/taxonomies/mastodon-tag.php';
require_once __DIR__ . '/src/class-sync-mastodon-admin.php';
require_once __DIR__ . '/src/class-sync-mastodon-meta-boxes.php';
require_once __DIR__ . '/src/class-sync-mastodon-cron.php';
require_once __DIR__ . '/src/class-sync-mastodon-wp-cli.php';
require_once __DIR__ . '/src/class-mastodon-rss-api.php';
require_once __DIR__ . '/src/class-sync-mastodon-core.php';
require_once __DIR__ . '/vendor/autoload.php';
/**
* Sync Mastodon class
*/
class Sync_Mastodon {
/**
* Constructor
*/
public function __construct() {
// Initial hooks.
add_action( 'init', [ $this, 'init_hooks' ] );
add_action( 'admin_menu', [ $this, 'admin_menu_hooks' ] );
$this->register_deactivation_hook();
}
/**
* Run any init hook actions
*
* @return void
*/
public function init_hooks() {
new Sync_Mastodon_Cron();
new Sync_Mastodon_Meta_Boxes();
new Sync_Mastodon_WPCLI();
}
/**
* Run any admin menu hook actions
*
* @return void
*/
public function admin_menu_hooks() {
new Sync_Mastodon_Admin();
}
/**
* Register a deactivation hook - this will trigger the sync_mastodon_deactivate action
* so anything that needs to be done on deactivation should be done using that hook.
*
* @return void
*/
public function register_deactivation_hook() {
register_deactivation_hook( __FILE__, [ $this, 'run_deactivation_hook' ] );
}
/**
* This actually does the sync_mastodon_deactivate hook
*/
public function run_deactivation_hook() {
do_action( 'sync_mastodon_deactivate' );
}
/**
* This takes a timestamp and turns it into local time using the gmt_offset options
*/
public static function make_time_local( $timestamp ) {
$offset_secs = ( (int) get_option( 'gmt_offset' ) ) * 60 * 60;
return $timestamp + $offset_secs;
}
/**
* This does information logging based on how the sync has been called
*/
public static function log( $message ) {
if ( class_exists( 'WP_CLI' ) ) {
\WP_CLI::log( $message );
}
return;
}
/**
* This does error logging based on how the sync has been called
*/
public static function error( $message ) {
if ( class_exists( 'WP_CLI' ) ) {
\WP_CLI::error( $message );
}
}
}
$syncmastodon_instance = new Sync_Mastodon();