steempress_sp-admin-display.php 12.5 KB
Newer Older
Martin Lees's avatar
Martin Lees committed
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

/**
 * Provide a admin area view for the plugin
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @link       https://steemit.com/@howo
 * @since      1.0.0
 *
 * @package    Sp
 * @subpackage Sp/admin/partials
 */
Martin Lees's avatar
Martin Lees committed
14
15


Martin Lees's avatar
Martin Lees committed
16
17
18
19
20
?>

<div class="wrap">

    <?php
Martin Lees's avatar
Martin Lees committed
21

Martin Lees's avatar
Martin Lees committed
22
23
    //Grab all options
    $options = get_option($this->plugin_name);
24

25
26
27
28
29
30
    // avoid undefined errors when running it for the first time :
    if (!isset($options["username"]))
        $options["username"] = "";
    if (!isset($options["posting-key"]))
        $options["posting-key"] = "";
    if (!isset($options["reward"]))
Martin LEES's avatar
Martin LEES committed
31
        $options["reward"] = "50";
32
33
34
35
36
37
38
39
40
41
    if (!isset($options["tags"]))
        $options["tags"] = "";
    if (!isset($options["tags"]))
        $options["tags"] = "";
    if (!isset($options["tags"]))
        $options["tags"] = "";
    if (!isset($options["seo"]))
        $options["seo"] = "on";
    if (!isset($options["vote"]))
        $options["vote"] = "on";
42
43
    if (!isset($options["append"]))
        $options["append"] = "off";
Martin Lees's avatar
Martin Lees committed
44
45
    if (!isset($options["delay"]))
        $options["delay"] = "0";
46
47
    if (!isset($options["featured"]))
        $options["featured"] = "on";
Martin Lees's avatar
Martin Lees committed
48
49
    if (!isset($options["footer"]))
        $options["footer"] = "<br /><center><hr/><em>Posted from my blog with <a href='https://wordpress.org/plugins/steempress/'>SteemPress</a> : [%original_link%] </em><hr/></center>";
50
51
    if (!isset($options["twoway"]))
        $options["twoway"] = "off";
52
53
    if (!isset($options["update"]))
        $options["update"] = "on";
54
55
    if (!isset($options["twoway-front"]))
        $options["twoway-front"] = "off";
Martin Lees's avatar
Martin Lees committed
56
57
    if (!isset($options["wordlimit"]))
        $options["wordlimit"] = "0";
Martin Lees's avatar
Martin Lees committed
58
59


60
    $users = get_users();
Martin Lees's avatar
Martin Lees committed
61
    $categories = get_categories(array('hide_empty' => FALSE));
Martin Lees's avatar
Martin Lees committed
62
63
64
65
66
67
68
69

    for ($i = 0; $i < sizeof($users); $i++) {
        if (!isset($options['username'.$users[$i]->data->ID]))
            $options['username'.$users[$i]->data->ID] = "";
        if (!isset($options['posting-key'.$users[$i]->data->ID]))
            $options['posting-key'.$users[$i]->data->ID] = "";
    }

Martin Lees's avatar
Martin Lees committed
70
71
72
73
74
75
76

    for ($i = 0; $i < sizeof($categories); $i++)
    {
        if (!isset($options['cat'.$categories[$i]->cat_ID]))
            $options['cat'.$categories[$i]->cat_ID] = "off";
    }

Martin Lees's avatar
Martin Lees committed
77
78
79
    ?>

    <h2><?php echo esc_html(get_admin_page_title()); ?></h2>
Martin Lees's avatar
Martin Lees committed
80
81

    <p> Join us on the discord server : https://discord.gg/W2KyAbm </p>
Martin Lees's avatar
Martin Lees committed
82
83
84
    <form method="post" name="cleanup_options" action="options.php">
        <?php settings_fields($this->plugin_name); ?>
        <!-- remove some meta and generators from the <head> -->
85
86

        <p>Default steem account : </p>
Martin Lees's avatar
Martin Lees committed
87
        <p>Steem Username : </p>
Martin Lees's avatar
Martin Lees committed
88
        <input type="text" class="regular-text" maxlength="16" id="<?php echo $this->plugin_name; ?>-username" name="<?php echo $this->plugin_name; ?>[username]" value="<?php echo htmlspecialchars($options["username"], ENT_QUOTES); ?>"/>
Martin Lees's avatar
Martin Lees committed
89
        <br />
90
91
92
93
        <?php
        if ($options["posting-key"] == "" || $options['username'] == "")
            echo "Don't have a steem account ? Sign up <a href='https://steemit.com/pick_account'> here</a>"
        ?>
94
        <p>Private Posting key : </p>
Martin Lees's avatar
Martin Lees committed
95
96
        <input type="text" class="regular-text" id="<?php echo $this->plugin_name; ?>-posting-key" name="<?php echo $this->plugin_name; ?>[posting-key]" value="<?php echo htmlspecialchars($options["posting-key"], ENT_QUOTES); ?>"/>
        <br />
97

98
        <p> Reward : </p>
Martin Lees's avatar
Martin Lees committed
99
        <select name="<?php echo $this->plugin_name; ?>[reward]" id="<?php echo $this->plugin_name; ?>-reward">
Martin Lees's avatar
Martin Lees committed
100
101
            <option value="50" <?php echo ($options["reward"] == "50" ?  'selected="selected"' : '');?>>50% Steem power 50% Steem Dollars</option>
            <option value="100" <?php echo ($options["reward"] == "100" ?  'selected="selected"' : '');?>>100% Steem Power</option>
102
        </select>
Martin Lees's avatar
Martin Lees committed
103

Martin Lees's avatar
Martin Lees committed
104
105


106
        <p> Default tags : <br> separate each tag by a space, 5 max <br> Will be used if you don't specify tags when publishing. </p>
107
        <input type="text" class="regular-text" id="<?php echo $this->plugin_name; ?>-tags" name="<?php echo $this->plugin_name; ?>[tags]" value="<?php echo htmlspecialchars(($options["tags"] == "" ? "steempress blog" : $options["tags"]), ENT_QUOTES); ?>"/>
Martin Lees's avatar
Martin Lees committed
108
        <br />
109
110
        <p> Delay posts : Your posts will get published to steem x minutes after being published on your blog. A value of 0 posts your articles to steem as soon as you publish them. maximum value is 87600, 2 months. </p>
        <input type="number" max="87600" class="regular-text" id="<?php echo $this->plugin_name; ?>-delay" name="<?php echo $this->plugin_name; ?>[delay]" value="<?php echo htmlspecialchars(($options["delay"] == "" ? "0" : $options["delay"]), ENT_QUOTES); ?>"/>
Martin Lees's avatar
Martin Lees committed
111
        <br />
112
113
        <br />

114
        <input type="checkbox" id="<?php echo $this->plugin_name; ?>-append-tags" name="<?php echo $this->plugin_name; ?>[append]"  <?php echo $options['append'] == "off" ? '' : 'checked="checked"' ?>> Always add the default tags before the post tags. (For instance if the post tags are "life travel" and your default tag is "french", the tags used on the post will be "french life travel") <br/>
115
        <input type="checkbox" id="<?php echo $this->plugin_name; ?>-vote" name="<?php echo $this->plugin_name; ?>[vote]"  <?php echo $options['vote'] == "off" ? '' : 'checked="checked"' ?>> Self vote<br>
Martin Lees's avatar
Martin Lees committed
116
        <input type="checkbox" id="<?php echo $this->plugin_name; ?>-seo" name="<?php echo $this->plugin_name; ?>[seo]"  <?php echo $options['seo'] == "off" ? '' : 'checked="checked"' ?>> Add the footer text to the end of the article.<br>
117
        <input type="checkbox" id="<?php echo $this->plugin_name; ?>-featured" name="<?php echo $this->plugin_name; ?>[featured]"  <?php echo $options['featured'] == "off" ? '' : 'checked="checked"' ?>> Add featured images on top of the steem post.<br>
Martin Lees's avatar
Martin Lees committed
118
        <input type="checkbox" id="<?php echo $this->plugin_name; ?>-update" name="<?php echo $this->plugin_name; ?>[update]"  <?php echo $options['update'] == "off" ? '' : 'checked="checked"' ?>> Update the steem post when updating on wordpress.<br>
119

120
121
        <br/>

Martin Lees's avatar
Martin Lees committed
122
123
        <p> Footer text : <br>  the tag [%original_link%] will be replaced by the link of the article on your blog. </p>
        <br/>
124
        <textarea maxlength="30000" type="text" class="regular-text" id="<?php echo $this->plugin_name; ?>-footer" name="<?php echo $this->plugin_name; ?>[footer]"><?php echo ($options["footer"] == "" ? "<br /><center><hr/><em>Posted from my blog with <a href='https://wordpress.org/plugins/steempress/'>SteemPress</a> : [%original_link%] </em><hr/></center>" : $options["footer"]) ?> </textarea>
Martin Lees's avatar
Martin Lees committed
125
126
127
        <br />


128
129
        <button class="steempress_sp_collapsible" type="button">Define more users</button>
        <div class="steempress_sp_content">
Martin Lees's avatar
Martin Lees committed
130
131
            <br/>
            If user x publishes a post and you have set his username/private key, it will get posted on his account instead of the default one.
132
133
        <br />
        <br />
134
135
136
137
138
139
        <?php

        for ($i = 0; $i < sizeof($users); $i++)
        {
            echo "Name : ".$users[$i]->data->display_name."<br/>";
            echo "Role : ".$users[$i]->roles[0]."<br/>";
140
141
142
143

            echo '<p> Steem username :</p>';
            echo '<input type="text" class="regular-text" id="'.$this->plugin_name.'-username-'.$users[$i]->data->ID.'" name="'.$this->plugin_name.'[username'.$users[$i]->data->ID.']" value="'.htmlspecialchars($options["username".$users[$i]->data->ID], ENT_QUOTES).'"/><br />';
            echo '<p>Private Posting key : </p> <input type="text" class="regular-text" id="'.$this->plugin_name.'-posting-key-'.$users[$i]->data->ID.'" name="'.$this->plugin_name.'[posting-key'.$users[$i]->data->ID.']" value="'.htmlspecialchars($options["posting-key".$users[$i]->data->ID], ENT_QUOTES).'"/><br/><br/>';
144
145
        }

Martin Lees's avatar
Martin Lees committed
146

147
        ?>
Martin Lees's avatar
Martin Lees committed
148
        </div>
Martin Lees's avatar
Martin Lees committed
149
150
151
152
153
154
155
156
157
158
159
160
        <br/>
        Category filter : <br/>
        Check the categories that you want steempress to ignore.<br/>
        <?php

        for ($i = 0; $i < sizeof($categories); $i++)
        {
            echo "<input type='checkbox' id='".$this->plugin_name."-cat".$categories[$i]->cat_ID."' name='".$this->plugin_name."[cat".$categories[$i]->cat_ID."]' ".($options['cat'.$categories[$i]->cat_ID] == "on" ? "checked='checked'" : "").">".$categories[$i]->name."<br>";
        }

        ?>

161
        <br/>
162
163
        Two way integration (BETA) <br/>
        Displays Steem features including, upvotes, pending rewards, comments and Steem log in on the blog interface. <br/>
164
        <?php
165
166
        echo "<input type='checkbox' id='".$this->plugin_name."-twoway' name='".$this->plugin_name."[twoway]' ".($options['twoway'] == "on" ? "checked='checked'" : "")."> Activate for posts.  <br/>";
        echo "<input type='checkbox' id='".$this->plugin_name."-twoway-front' name='".$this->plugin_name."[twoway-front]' ".($options['twoway-front'] == "on" ? "checked='checked'" : "").">  Activate for front page (requires two way integration for posts to be active).";
167

Martin Lees's avatar
Martin Lees committed
168
169
170
171
172
173
174
        ?>
        <br />
        <p> Word limit : only publish the first x words to the steem blockchain, set to 0 to publish the entire article. </p>
        <input type="number" class="regular-text" id="<?php echo $this->plugin_name; ?>-wordlimit" name="<?php echo $this->plugin_name; ?>[wordlimit]" value="<?php echo htmlspecialchars(($options["wordlimit"] == "" ? "0" : $options["wordlimit"]), ENT_QUOTES); ?>"/>
        <br />
        <?php

175

176
177
        submit_button('Save all changes', 'primary','submit', TRUE); ?>

Martin Lees's avatar
Martin Lees committed
178

Martin Lees's avatar
Martin Lees committed
179
    </form>
180
    <p><?php
181

Martin Lees's avatar
Martin Lees committed
182
183
184
185
186
187
188
189
190
191
        $version = steempress_sp_compte;

        $pos = strrpos(steempress_sp_compte, ".");

        if($pos !== false)
            $version = substr_replace(steempress_sp_compte, "", $pos, strlen("."));

        $version = ((float)$version)*100;

        $data = array("body" => array("author" => $options['username'], "wif" => $options['posting-key'], "vote" => $options['vote'], "reward" => $options['reward'], "version" =>  $version, "footer" => $options['footer']));
192
193

        // Post to the api who will publish it on the steem blockchain.
194
        $result = wp_remote_post(steempress_sp_api_url."/test", $data);
Martin Lees's avatar
Martin Lees committed
195
196
        if (is_array($result) or ($result instanceof Traversable)) {
            echo "Connectivity to the steem server : <b style='color: darkgreen'>Ok</b> <br/>";
197
198
            $text = $result['body'];
            if ($text == "ok")
Martin Lees's avatar
Martin Lees committed
199
                      echo "Default Username/posting key  : <b style='color: red'> Wrong</b> <br/> Are you sure you used the private posting key and not the public posting key or password ?";
200
            else if ($text == "wif ok")
Martin Lees's avatar
Martin Lees committed
201
202
203
204
205
206
207
208
209
210
                echo "Default username/posting key  : <b style='color: darkgreen'>Ok</b> ";

            echo "<br/>";
            echo "<br/>";
            for ($i = 0; $i < sizeof($users); $i++)
            {
                if ($options['username'.$users[$i]->data->ID] != "" && $options['posting-key'.$users[$i]->data->ID] != "")
                {
                    echo "Name : ".$users[$i]->data->display_name."<br/>";
                    echo "Role : ".$users[$i]->roles[0]."<br/>";
Martin Lees's avatar
Martin Lees committed
211
                    $data = array("body" => array("author" => $options['username'.$users[$i]->data->ID], "wif" => $options['posting-key'.$users[$i]->data->ID], "vote" => $options['vote'], "reward" => $options['reward'], "version" =>  $version, "footer" => $options['footer']));
212
                    $result = wp_remote_post(steempress_sp_api_url."/test", $data);
Martin Lees's avatar
Martin Lees committed
213
214
215
216
217
218
219
220
221
222
223
                    $text = $result['body'];
                    if ($text == "ok")
                        echo "Username/posting key  : <b style='color: red'> Wrong</b> <br/> Are you sure you used the private posting key and not the public posting key or password ?<br/>";
                    else if ($text == "wif ok")
                        echo "username/posting key  : <b style='color: darkgreen'>Ok</b> <br/>";

                    echo "<br/>";
                }
            }

        }
Martin Lees's avatar
Martin Lees committed
224
        else
225
            echo " Connectivity to the steem server : <b style='color: red'>Connection error</b> <br /> Most likely your host isn't letting the plugin reach our steem server.";
226
        ?> </p>
Martin Lees's avatar
Martin Lees committed
227
</div>
Martin Lees's avatar
Martin Lees committed
228
229
230


<script>
231
    var coll = document.getElementsByClassName("steempress_sp_collapsible");
Martin Lees's avatar
Martin Lees committed
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    var i;

    for (i = 0; i < coll.length; i++) {
        coll[i].addEventListener("click", function() {
            this.classList.toggle("active");
            var content = this.nextElementSibling;
            if (content.style.maxHeight){
                content.style.maxHeight = null;
            } else {
                content.style.maxHeight = content.scrollHeight + "px";
            }
        });
    }
</script>