forked from danblaker/wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-moot.php
124 lines (89 loc) · 3.34 KB
/
class-moot.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
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* The new-wave commenting and forums for Wordpress
*
* @package Moot
* @author Tero Piirainen <[email protected]>
* @license MIT
* @link https://moot.it/docs/wordpress.html
* @copyright 2014 Moot Inc
*/
class Moot {
protected $version = '2.0.11';
protected $plugin_slug = 'moot';
protected static $instance = null;
protected $plugin_screen_hook_suffix = null;
private function __construct() {
add_filter('the_content', array($this, 'default_comments'));
add_action('wp_enqueue_scripts', array($this, 'moot_includes'));
add_action('wp_head', array($this, 'moot_head'));
add_action('admin_menu', array($this, 'moot_admin_menu'));
add_action('admin_init', array($this, 'moot_settings'));
add_shortcode('moot', array($this, 'moot_shortcode'));
add_shortcode('no-moot', array($this, 'moot_disable'));
}
public static function get_instance() {
if (null == self::$instance) { self::$instance = new self; }
return self::$instance;
}
public function moot_head() {
require_once(plugin_dir_path(__FILE__) . 'public.php');
}
public function moot_includes() {
if (!is_home()) {
wp_enqueue_style("moot", '//cdn.moot.it/latest/moot.css', array(), $this->version);
$lang = get_option('moot_language');
if ($lang == 'en') $lang = "";
if ($lang) $lang = "." . $lang;
wp_enqueue_script("", "//cdn.moot.it/latest/moot$lang.min.js", array('jquery'), $this->version);
}
}
public function default_comments($content) {
$forumname = get_option('moot_forum_name');
if (!is_home() && $forumname != null && get_option('moot_generate') == "true" && get_post_type() == "post") {
$page_id = sanitize_title(get_the_title());
$content .= "<a id='moot-default-comments' href='https://moot.it/i/$forumname/wordpress:$page_id'>Comments</a>";
}
return $content;
}
public function moot_settings($content) {
register_setting('moot_options', 'moot_forum_name');
register_setting('moot_options', 'moot_api_key');
register_setting('moot_options', 'moot_secret_key');
register_setting('moot_options', 'moot_language');
register_setting('moot_options', 'moot_generate');
register_setting('moot_options', 'moot_comments_under_forums');
}
// admin menu
public function moot_admin_menu() {
if (is_super_admin()) {
$this->plugin_screen_hook_suffix = add_plugins_page(
__('Moot', $this->plugin_slug),
__('Moot', $this->plugin_slug),
'read', $this->plugin_slug, array($this, 'moot_admin')
);
}
}
public function moot_admin() {
include_once('settings.php');
}
public function moot_disable() {
return "<span id='no-moot'></span>";
}
public function moot_shortcode($params) {
extract( shortcode_atts( array(
'forum' => false,
'threaded' => false,
'path' => false
), $params) );
$forumname = get_option('moot_forum_name');
if ($forumname == null) return "";
$tag = "<a id='moot' href='https://moot.it/i/$forumname";
$page_id = sanitize_title(get_the_title());
// (bool ? this : that) not working
if ($forum) return "$tag'>$forumname forums</a>";
if ($threaded) return "$tag/wordpress/$page_id'>Comments</a>";
if ($path) return "$tag/$path'>Comments are here</a>";
return "$tag/wordpress:$page_id'>Comments</a>";
}
}