class-steempress_sp-public.php 4.81 KB
Newer Older
Martin Lees's avatar
Martin Lees committed
1
2
3
4
5
6
7
8
<?php

/**
 * The public-facing functionality of the plugin.
 *
 * @link       https://steemit.com/@howo
 * @since      1.0.0
 *
Martin Lees's avatar
Martin Lees committed
9
10
 * @package    Steempress_sp
 * @subpackage Steempress_sp/public
Martin Lees's avatar
Martin Lees committed
11
12
13
14
15
16
17
18
 */

/**
 * The public-facing functionality of the plugin.
 *
 * Defines the plugin name, version, and two examples hooks for how to
 * enqueue the public-facing stylesheet and JavaScript.
 *
Martin Lees's avatar
Martin Lees committed
19
20
 * @package    Steempress_sp
 * @subpackage Steempress_sp/public
Martin Lees's avatar
Martin Lees committed
21
 */
Martin Lees's avatar
Martin Lees committed
22
class Steempress_sp_Public {
Martin Lees's avatar
Martin Lees committed
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

	/**
	 * The ID of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $plugin_name    The ID of this plugin.
	 */
	private $plugin_name;

	/**
	 * The version of this plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 * @var      string    $version    The current version of this plugin.
	 */
	private $version;

	/**
	 * Initialize the class and set its properties.
	 *
	 * @since    1.0.0
	 * @param      string    $plugin_name       The name of the plugin.
	 * @param      string    $version    The version of this plugin.
	 */
	public function __construct( $plugin_name, $version ) {

		$this->plugin_name = $plugin_name;
		$this->version = $version;

	}

	/**
	 * Register the stylesheets for the public-facing side of the site.
	 *
	 * @since    1.0.0
	 */
	public function enqueue_styles() {

		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the run() function
Martin Lees's avatar
Martin Lees committed
67
		 * defined in Steempress_sp_Loader as all of the hooks are defined
Martin Lees's avatar
Martin Lees committed
68
69
		 * in that particular class.
		 *
Martin Lees's avatar
Martin Lees committed
70
		 * The Steempress_sp_Loader will then create the relationship
Martin Lees's avatar
Martin Lees committed
71
72
73
74
		 * between the defined hooks and the functions defined in this
		 * class.
		 */

Martin Lees's avatar
Martin Lees committed
75
		wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/steempress_sp-public.css', array(), $this->version, 'all' );
Martin Lees's avatar
Martin Lees committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89

	}

	/**
	 * Register the JavaScript for the public-facing side of the site.
	 *
	 * @since    1.0.0
	 */
	public function enqueue_scripts() {

		/**
		 * This function is provided for demonstration purposes only.
		 *
		 * An instance of this class should be passed to the run() function
Martin Lees's avatar
Martin Lees committed
90
		 * defined in Steempress_sp_Loader as all of the hooks are defined
Martin Lees's avatar
Martin Lees committed
91
92
		 * in that particular class.
		 *
Martin Lees's avatar
Martin Lees committed
93
		 * The Steempress_sp_Loader will then create the relationship
Martin Lees's avatar
Martin Lees committed
94
95
96
97
		 * between the defined hooks and the functions defined in this
		 * class.
		 */

Martin Lees's avatar
Martin Lees committed
98
		wp_enqueue_script( $this->plugin_name."iframeResizer", plugin_dir_url( __FILE__ ) . 'js/iframeResizer.min.js');
99
		wp_enqueue_script( $this->plugin_name."public_js", plugin_dir_url( __FILE__ ) . 'js/steempress_sp-public.js', array( 'jquery' ), $this->version, false );
Martin Lees's avatar
Martin Lees committed
100
101
102

	}

Martin Lees's avatar
Martin Lees committed
103

104
	public function steempress_sp_comments($content)
105
106
    {

107
        $options = get_option($this->plugin_name);
108

109
110
        if (!isset($options["twoway"]))
            $options["twoway"] = "off";
111
112
        if (!isset($options["twoway-front"]))
            $options["twoway-front"] = "off";
Martin Lees's avatar
Martin Lees committed
113

114
115
        if ($options['twoway'] == "on") {
            $id = get_the_ID();
116
            
Martin Lees's avatar
Martin Lees committed
117
118
            $post = get_post($id);

119
            $permlink = get_post_meta($id, "steempress_sp_permlink", true);
120

Martin Lees's avatar
Martin Lees committed
121
122
123
124
125
126
127
128
            $author_id = $post->post_author;

            if (!isset($options["username"]))
                $options["username"] = "";


            $author = $options["username"];

129

Martin Lees's avatar
Martin Lees committed
130
131
132
133
            if (isset($options['username' . $author_id]) && $options['username' . $author_id] != "") {
                $author = $options['username' . $author_id];
            }

134
135
136
137
138
            $meta_author = get_post_meta($post->ID, 'steempress_sp_author', true);

            if ($meta_author != $author && $meta_author != "")
                $author = $meta_author;

139
140
            $steempress = "";

Martin Lees's avatar
Martin Lees committed
141
            if ($permlink != "" && $author != "") {
Martin Lees's avatar
Martin Lees committed
142
                // If it's the front page, we display a smaller iframe.
Martin Lees's avatar
Martin Lees committed
143
               $steempress = "<div id='steempress_sp_comment_feed'>";
144
                if (is_front_page())
Martin Lees's avatar
Martin Lees committed
145
                    $steempress .= "<iframe name='steempress_sp_embed'  onload=\"iFrameResize({maxHeight:800 , heightCalculationMethod:'min'})\" src=\"".steempress_sp_twoway_api_url."/?author=".$author."&permlink=".$permlink."&display_comment=false\" style=\"border: 0; width: 100%;margin-bottom: 0px !important;\"></iframe>";
146
                else
Martin Lees's avatar
Martin Lees committed
147
                    $steempress .= "<iframe name='steempress_sp_embed'  onload=\"iFrameResize({maxHeight:800, scrolling:true, heightCalculationMethod:'min'})\" src=\"".steempress_sp_twoway_api_url."/?author=".$author."&permlink=".$permlink."&display_comment=true\" style=\"border: 0; width: 100%; margin-bottom: 0px !important;\"></iframe>";
148

149
                $steempress .= "</div>";
150
            }
151
152
153
154

            if ($options["twoway-front"] === "off" && is_front_page())
                return $content;

Martin Lees's avatar
Martin Lees committed
155
            return $content .  $steempress;
156
157
158
159
        } else
            return $content;

        }
160

Martin Lees's avatar
Martin Lees committed
161

Martin Lees's avatar
Martin Lees committed
162
}