plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @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
* defined in Steempress_sp_Loader as all of the hooks are defined
* in that particular class.
*
* The Steempress_sp_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/steempress_sp-admin.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @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
* defined in Steempress_sp_Loader as all of the hooks are defined
* in that particular class.
*
* The Steempress_sp_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/steempress_sp-admin.js', array( 'jquery' ), $this->version, false );
}
/**
* Register the administration menu for this plugin into the WordPress Dashboard menu.
*
* @since 1.0.0
*/
public function add_plugin_admin_menu() {
add_options_page( 'SteemPress Options', 'SteemPress', 'manage_options', $this->plugin_name, array($this, 'display_plugin_setup_page')
);
}
/**
* Add settings action link to the plugins page.
*
* @since 1.0.0
*/
public function add_action_links( $links ) {
/*
* Documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
*/
$settings_link = array(
'' . __('Settings', $this->plugin_name) . '',
);
return array_merge( $settings_link, $links );
}
/**
* Render the settings page for this plugin.
*
* @since 1.0.0
*/
public function display_plugin_setup_page() {
include_once('partials/steempress_sp-admin-display.php');
}
public function validate($input) {
// All checkboxes inputs
$valid = array();
$valid['reward'] = (isset($input['reward']) && !empty($input['reward'] ) && ($input['reward'] == "50" || $input['reward'] == "100")) ? $input['reward'] : "50";
$valid['posting-key'] = (isset($input['posting-key']) && !empty($input['posting-key'])) ? htmlspecialchars($input['posting-key'], ENT_QUOTES) : "";
$valid['tags'] = (isset($input['tags']) && !empty($input['tags'])) ? htmlspecialchars($input['tags'], ENT_QUOTES) : "";
$valid['username'] = (isset($input['username']) && !empty($input['username'])) ? htmlspecialchars($input['username'], ENT_QUOTES) : "";
$valid['seo'] = ((isset($input['seo']) && !empty($input['seo'])) && $input['seo'] == 'on') ? 'on' : "off";
$valid['vote'] = ((isset($input['vote']) && !empty($input['vote'])) && $input['vote'] == 'on') ? 'on' : "off";
$valid['append'] = ((isset($input['append']) && !empty($input['append'])) && $input['append'] == 'on') ? 'on' : "off";
$valid['delay'] = ((isset($input['delay']) && !empty($input['delay']) && is_numeric($input['delay']) && $input['delay'] >= 0 && $input['delay'] <= 87600)) ? htmlspecialchars($input['delay'], ENT_QUOTES) : "0";
$valid['featured'] = ((isset($input['featured']) && !empty($input['featured'])) && $input['featured'] == 'on') ? 'on' : "off";
$valid['footer'] = (isset($input['footer']) && !empty($input['footer'])) ? $input['footer'] : "
Posted from my blog with SteemPress : [%original_link%]
" . $post->post_content;
}
$domain = get_site_url();
$version = steempress_sp_compte;
$pos = strrpos(steempress_sp_compte, ".");
if($pos !== false)
$version = substr_replace(steempress_sp_compte, "", $pos, strlen("."));
$version = ((float)$version)*100;
if ($options['wordlimit'] != "0") {
$limit = intval($options["wordlimit"]);
$content = TruncateHTML::truncateWords($content, $limit, '');
}
$data = array("body" => array(
"title" => $post->post_title,
"content" => $content,
"tags" => $tags,
"author" => $username,
"wif" => $posting_key,
"original_link" => $link,
"reward" => $options['reward'],
"vote"=> $options["vote"],
"delay"=> $options["delay"],
"wordpress_id"=> $id,
"domain"=> $domain,
"display_backlink" => $display_backlink,
"version" => $version,
"footer" =>$options['footer'],
));
// A few local verifications as to not overload the server with useless txs
$test = $data['body'];
// Last minute checks before sending it to the server
if ($test['tags'] != "" && $test['author'] != "" && $test['wif'] != "") {
// Post to the api who will publish it on the steem blockchain.
$result = wp_remote_post(steempress_sp_api_url, $data);
if (!isset($result->errors)) {
update_post_meta($id,'steempress_sp_permlink',$result['body']);
update_post_meta($id,'steempress_sp_author',$username);
}
}
}
public function steempress_sp_bulk_update_action($bulk_actions) {
$options = get_option($this->plugin_name);
if (!isset($options["update"]))
$options["update"] = "on";
if ($options["update"] == "on")
$bulk_actions['update_to_steem'] = __('Update to STEEM', 'update_to_steem');
return $bulk_actions;
}
public function steempress_sp_bulk_publish_action($bulk_actions) {
$bulk_actions['publish_to_steem'] = __( 'Publish to STEEM', 'publish_to_steem');
return $bulk_actions;
}
public function steempress_sp_bulk_publish_handler( $redirect_to, $doaction, $post_ids ) {
if ( $doaction !== 'publish_to_steem' ) {
return $redirect_to;
}
for ($i = sizeof($post_ids)-1; $i >= 0; $i--) {
// Perform action for each post.
$this->Steempress_sp_publish($post_ids[$i]);
}
$redirect_to = add_query_arg('published_to_steem', count( $post_ids ), $redirect_to );
return $redirect_to;
}
public function steempress_sp_bulk_update_handler( $redirect_to, $doaction, $post_ids ) {
if ( $doaction !== 'update_to_steem' ) {
return $redirect_to;
}
$updated = 0;
for ($i = sizeof($post_ids)-1; $i >= 0; $i--) {
// Perform action for each post.
if ($this->steempress_sp_update($post_ids[$i], true) == 1)
$updated++;
}
if ($updated != count($post_ids))
$redirect_to = add_query_arg('updated_to_steem_err', $updated, $redirect_to );
else
$redirect_to = add_query_arg('updated_to_steem', $updated, $redirect_to );
return $redirect_to;
}
public function steempress_sp_bulk_update_notice() {
if ( !empty( $_REQUEST['updated_to_steem']) ) {
$published_count = intval( $_REQUEST['updated_to_steem'] );
printf( '
' .
_n( 'Added %s post to be updated on STEEM. Check your posting queue on https://steempress.io to track the progress.',
'Added %s posts to be updated on STEEM. Check your posting queue on https://steempress.io to track the progress.',
$published_count,
'updated_to_steem'
) . '
' .
_n( 'Your post was not updated probably because the metadata was not correctly set. Please edit the article you wanted to update on STEEM and edit the metadata. Then resubmit it.',
'Added %s posts to be updated on STEEM. Some were not updated probably because the metadata was not correctly set. Please edit the articles you want to update to STEEM and edit the metadata. Then resubmit them.',
$published_count,
'updated_to_steem'
) . '
', $published_count );
}
}
public function steempress_sp_bulk_publish_notice() {
if ( !empty($_REQUEST['published_to_steem'])) {
$published_count = intval( $_REQUEST['published_to_steem'] );
printf( '
' .
_n( 'Added %s post to be published on STEEM. STEEM only allows one article to be published per 5 minutes so it may take a while. Check your posting queue on https://steempress.io to track the progress.',
'Added %s posts to be published on STEEM. STEEM only allows one article to be published per 5 minutes so it may take a while. check your posting queue on https://steempress.io to track the progress.',
$published_count,
'published_to_steem'
) . '
', $published_count );
}
}
public function Steempress_sp_post($new_status, $old_status, $post)
{
// New post
if ($new_status == 'publish' && $old_status != 'publish' && $post->post_type == 'post') {
if (!isset($_POST['Steempress_sp_steem_publish']) && isset($_POST['Steempress_sp_steem_do_not_publish']) )
return;
$value = get_post_meta($post->ID, 'Steempress_sp_steem_publish', true);
if ($value != "0")
$this->Steempress_sp_publish($post->ID);
// Edited post
} else if ($new_status == 'publish' && $old_status == 'publish' && $post->post_type == 'post') {
if (!isset($_POST['Steempress_sp_steem_update']) && isset($_POST['Steempress_sp_steem_do_not_update']) )
return;
$this->steempress_sp_update($post->ID);
}
return;
}
function createSteemPublishField()
{
$post_id = get_the_ID();
if (get_post_type($post_id) != 'post') {
return;
}
if (get_post_status ($post_id) == 'publish')
return;
wp_nonce_field('Steempress_sp_custom_nonce_'.$post_id, 'Steempress_sp_custom_nonce');
$value = get_post_meta($post_id, 'Steempress_sp_steem_publish', true);
if ($value == "0")
$checked = "";
else
$checked = "checked";
?>
plugin_name);
if (!isset($options["update"]))
$options["update"] = "on";
if ($options["update"] != "on")
return;
wp_nonce_field('Steempress_sp_custom_update_nonce_'.$post_id, 'Steempress_sp_custom_update_nonce');
$value = get_post_meta($post_id, 'Steempress_sp_steem_update', true);
if ($value == "0")
$checked = "";
else
$checked = "checked";
?>
These options are only for advanced users regarding steem integration
";
// Minified js to handle the "test parameters" function
$body .= "";
$body .= " ";
echo $body;
}
public function steempress_sp_add_custom_box()
{
$post_id = get_the_ID();
if (get_post_type($post_id) != 'post') {
return;
}
if (get_post_status ($post_id) != 'publish')
return;
add_meta_box(
'steempress_sp_box_id',
'SteemPress options',
array($this,'steempress_sp_custom_box_html'),
'post',
'side'
);
}
function steempress_sp_save_post_data($post_id)
{
if (array_key_exists('steempress_sp_permlink', $_POST) && array_key_exists('steempress_sp_author', $_POST)) {
update_post_meta($post_id,'steempress_sp_permlink',$_POST['steempress_sp_permlink']);
update_post_meta($post_id,'steempress_sp_author',$_POST['steempress_sp_author']);
}
}
/* Returned codes :
1 : ok
-1 : metadata is incorrect
-2 : update is not activated
-3 : Post is not in the published state
*/
function steempress_sp_update($post_id, $bulk = false)
{
$post = get_post($post_id);
if ($post->post_status == "publish") {
$options = get_option($this->plugin_name);
// Avoid undefined errors
if (!isset($options["username"]))
$options["username"] = "";
if (!isset($options["posting-key"]))
$options["posting-key"] = "";
if (!isset($options["reward"]))
$options["reward"] = "100";
if (!isset($options["tags"]))
$options["tags"] = "";
if (!isset($options["seo"]))
$options["seo"] = "on";
if (!isset($options["vote"]))
$options["vote"] = "on";
if (!isset($options["append"]))
$options["append"] = "off";
if (!isset($options["delay"]))
$options["delay"] = "0";
if (!isset($options["featured"]))
$options["featured"] = "on";
if (!isset($options["footer"]))
$options["footer"] = "
Posted from my blog with SteemPress : [%original_link%]