WordPress Steemit Theme Hack

So I have to admit, waiting for the Steem token system to come out sometime in the next year, has been just to much to bare. So I wrote a set of functions to add to my word-press theme to add a bit of an information block to posts that I push to Steem, mostly for my fiction writings. (I am still messing around with the code for the Steem based banner advertisement system as well.)

The first function is just a curl cache implication, I do this to reduce the amount of loads that steemit.com ends up getting. (I’m a nice guy after all) make sure you set the correct full path to the cache folder, mine is above the public folder.

<?php

function CurlByCache($url, $cachefolder) {

$cachefile = $cachefolder.md5($url).”.curl.cache.txt” ;

// define how long we want to keep the file in seconds. I set mine to 5 hours.
$cachetime = 18000;
// Check if the cached file is still fresh. If it is, serve it up and exit.
if (file_exists($cachefile) && time() – $cachetime < filemtime($cachefile)) {
$cache = file_get_contents($cachefile);
}
// if there is either no file OR the file to too old, render the page and capture the HTML.
ob_start();

$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, $url);

//return the transfer as ain plain txt encoding
curl_setopt($ch, CURLOPT_ENCODING, “text/plain”);

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
$cache = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);

$fp = fopen($cachefile, ‘w’);
fwrite($fp, $cache);
fclose($fp);
// finally send browser output
ob_end_flush();

return $cache ;
}

?>

The second function grabs the json encoding of the post on steemit itself. You need to set the username, (without the @) and the steemit permalink (slug) for this to work, but if you are publishing to steemit via the wordpress plugin written by @recrypto then just make sure you use the wordpress $post->post_name in your themes single.php file like so:

global $post;
$steemslug = $post_slug=$post->post_name;
$steemuser = “wolfeblog” ;
$cachefolder = “/home/myuseracct/cache/” ;

SteemExtra($steemslug, $steemuser, $cachefolder) ;

Within the function below I set the class id for the division to author2 you might need to change this to fit your style.css file, mine already had an author id so I just added the author2 to it. Remember that these functions should be added to a child theme instead of the original since any updates might delete your hack.

function SteemExtra($steemslug, $steemuser, $cachefolder) {

$datalink = “https://steemit.com/curation/@”.$steemuser.”/”.$steemslug.”.json”;

$json = CurlByCache($datalink, $cachefolder) ;

$steemdata = json_decode($json,true) ;

// check status first
$status = $steemdata[‘status’] ;

if($status == 200) {

$display = “<div id=’authorbox2′>” ;
// created
$created = $steemdata[‘post’][‘created’] ;
$timestamp = strtotime($created) ;
$created = date(“F j, Y, g:i a”, strtotime($created));

// tags … [tags]
$tags = $steemdata[‘post’][‘json_metadata’][‘tags’] ;
if(!is_array($tags)) {
$tags = explode(” “, $tags);
}
$display .= “<p>This post was on published on Steemit.com <b>(“.$created.”)</b> under:</p><p>” ;
foreach($tags as $tag) {

$display .= ” <a href=’https://steemit.com/trending/”.$tag.”‘ target=’_blank’>#”.$tag.”</a>” ;
}
$display .= “</p><p>”;
// steemit.com/[url]
$url = $steemdata[‘post’][‘url’] ;

// [pending_payout_value]
$total_payout_value = $steemdata[‘post’][‘total_payout_value’] ;

// total_pending_payout_value
$total_pending_payout_value = $steemdata[‘post’][‘total_pending_payout_value’] ;

// supporters [active_votes][$n][voter]

$curator_payout_value = $steemdata[‘post’][‘curator_payout_value’] ;

$supporters = $steemdata[‘post’][‘active_votes’] ;
// sort by highest payout? done by the json already?

$display .= “Posts on steemit earn the author Steem coin, a crypto-currency. “.
SteemPayout($total_payout_value, $total_pending_payout_value, $created, $url, $curator_payout_value).”<br>” ;

$display .= “Supporters: ” ;
foreach($supporters as $voter) {
$display .= ” <a href=’http://steemit.com/@”.$voter[‘voter’].”‘ target=’_blank’>@”.$voter[‘voter’].'</a>’ ;
}

$display .= ” </p></div>”;

echo $display ;
}
}

As an added bonus you can add  a do_shortcode('') within the last $display above (google the do_shortcode('') instructions, and see the bottom of this post for a link to the steem to US dollar convertor)

Hopefully, @recrypto will steal this code and turn it into a plugin for the non geeks. 😉

– wolfe

 

Click here for reuse options!
Copyright 2017 Dan Wolfe

I am a Web Developer, Information Professional, and writer. My experiance ranges from PHP, HTML5, Java, XML and Bash scripting to Blockchain API interfaces, law library research, data indexing and programming spiders to search the dark-net. I have worked as a civil contractor for several law enforcement agencies, and security companies, providing time relative information on data breaches, and identify thief. My focus in web development is based on encryption, security, and privacy.

Topics


Archery
Barter
Comix
Crypto-currency
DIY
Food Storage
Geek
General Posts
Homesteading
Off-The-Grid
Privacy
Reviews
Self-Defense
Self-Reliance
Self-Sufficient
Steem Posts
Survivalism
WPBookList Book Post

Still Updating

I am still in the process of updating this site, and transfering all the code and posts from wolfeblog.net, please bare with me - wolfe

[currencyprice currency1="usd" currency2="btc,eth,ltc,dash,xmr,doge,zec,xrp,zec,steem" feature="all"]